org.jetbrains.annotations.NotNull instead of javax.annotation.Nonnull when implement method in Intellij IDEA - intellij-idea

After recent JetBrains Intellij IDEA updates I found out that when I'm trying to implement method annotated with javax.annotation.Nonnull - IDE implements it with org.jetbrains.annotations.NotNull instead.
Example:
If you have an interface:
import javax.annotation.Nonnull;
interface User {
#Nonnull
String getName();
}
it will be implemented as:
import org.jetbrains.annotations.NotNull;
class Customer implements User {
#NotNull
#Override
public String getName() {
return null;
}
}
The question is how to configure IDE to implement methods with strict validation annotation?

Looks like a defect (https://youtrack.jetbrains.com/issue/IDEA-253324) although there is a workaround exist:
Inspections > Java > Probable bugs > Nullability problems > #NotNull/#Nullable problems > Configure Annotations. Set javax.annotation.Nullable/javax.annotation.Nonnull as defaults and restart the IDE.

To add the library with annotations to a Gradle project, add the implementation org.jetbrains:annotations:23.0.0 dependency to the build.gradle file.

Related

Why doesn't intellij suggest org.mockito.Mockito dependency when using verify()?

When creating a new test, I have issues importing mockito methods into the class.
The class looks like
#ExtendWith(SpringExtension.class)
#SpringBootTest(classes = MainSpringBootApplication.class)
class CoolServiceTest {
#Autowired
SomeService someService;
#Test
void testGetInstitutionsCache_ShouldNotSecondTime() {
assertEquals(someService.getName(), "bob");
verify(idsClientMock, times(1));
}
}
In the import menu of intellij I don't see the option to import org.mockito.Mockito which I know where the package resides.
Instead I get the option to add;
import static org.testcontainers.shaded.com.google.common.base.Verify.verify;
(obviously not what I want)
I can get around it by typing the full Mockito.verify and then adding an on-demand static import to tidy the code.
The package is definitely installed and available to use, but intellij won't pick it up automatically.

How to use #Autowire when using #ParameterizedTest in Junit5

I currently use SpringBoot1.5 and Junit5.
How do I use #autowire to dependency injection when I use the annotation #ParameterizedTest for parametric testing because I need to interact with the database.
I try to use
TestContextManager testContextManager = new TestContextManager(getClass());
testContextManager.prepareTestInstance(this);
but it will cause the #transaction to be unavailable.
this my code
#ExtendWith(MockitoExtension.class)
#RunWith(SpringRunner.class)
public abstract class AbstractUnitTest {
}
public class PatientFacadeTestParameterized extends AbstractUnitTest {
...
#Autowired
PatientFacade patientFacade;(is null)
...
#Transactional
#ParameterizedTest(name = "{index}: {0}")
#YamlFileSource(resources = {"logistics/patient_facade.yaml"})
public void testCreateAccountPhonePatienta(PatientFacadeData patientFacadeData) {
...
patientFacade.createAccountPhonePatient(patientForm1);
...
}
...
I just want to use #ParameterizedTest to manage my input.
Spring Boot 1.5.x depends on Spring Framework 4.3.x, but the latter does not provide built in support for JUnit Jupiter (a.k.a., JUnit 5).
So, if you want to use Spring Framework 4.3.x with JUnit Jupiter, the only option is to use my spring-test-junit5 project.
Once you have configured the dependency on spring-test-junit5, you will have access to the SpringExtension for JUnit Jupiter. This replaces the SpringRunner for JUnit 4.
You should then be able to rewrite your test class in a manner similar to the following. I cannot provide you an exact working example, since I do not have access to the types in your project.
#ExtendWith(SpringExtension.class)
#ExtendWith(MockitoExtension.class)
public class PatientFacadeTestParameterized {
#Autowired
PatientFacade patientFacade;
#Transactional
#ParameterizedTest(name = "{index}: {0}")
#YamlFileSource(resources = {"logistics/patient_facade.yaml"})
public void testCreateAccountPhonePatienta(PatientFacadeData patientFacadeData) {
// ...
patientFacade.createAccountPhonePatient(patientForm1);
// ...
}
What is responsible for injecting the PatientFacadeData into your test method? Does #YamlFileSource take care of that?
By the way, you should practically never need to use the TestContextManager directly in your tests. The SpringRunner and SpringExtension handle that for you.

Use Proguard 5.3 ,default type methods change to public type

I want to develop a private SDK(a jar file),some method is default permission,i want it can be called in current package only,like this:
/* package */
static String getApplicationId() {
return mApplicationId;
}
but,when use proguard to make jar later,this method change to public type,and the method name like this:
public static String c() {
return sApplicationId;
}
so i want know how to config proguard file.to make default permission method can't visiable when use this jar by proguard later,thanks
You should check your configuration, most likely you have the following setting enabled:
-allowaccessmodification
When obfuscating a library, you normally do not want this enabled, as you experience the effects as described in the question.

How to implement Java interfaces in Frege?

I have been trying out Frege and one of the first things I would like to do is implement a Java interface.
How is that done?
Here's my example in Java:
package mypkg;
import frege.repl.FregeRepl;
import frege.runtime.Concurrent;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class FregeMain implements BundleActivator {
public FregeMain() {
}
#Override
public void start( BundleContext context ) throws Exception {
System.out.println( "Frege Bundle activated" );
new Thread( () -> FregeRepl.main( new String[ 0 ] ) ).start();
}
#Override
public void stop( BundleContext context ) throws Exception {
System.out.println( "Frege stopping. Goodbye!" );
Concurrent.shutDownIfExists();
}
}
To implement this in Frege, I would need to know:
how to declare something that will be visible as a class called mypkg.FregeMain implementing BundleActivator in JVM bytecode (notice that this is important as the OSGi framework will scan the jar for classes implementing that interface, and call them automatically).
How to implement a Runnable (as a Haskell lambda, probably) and pass it on to the Thread constructor. Also same issue: implement a Java interface, but this time with an anonymous class or lambda.
I tried to understand the Calling Java from Frege post, but probably due to my lack of experience in Frege/Haskell, I just don't understand most of that.
Thanks for any input.
The simplest way to implement Java interface in Frege is possibly to use an inline module definition. Some thorough examples are in https://github.com/Frege/FregeFX/blob/master/fregefx/src/main/frege/fregefx/JavaFxUtils.fr

Which eclipse plugin implements Ctrl+PageDown or M1+PageDown

I am learning eclipse plugin development and a great deal of learning can be done by looking at the implementation of an existing builtin plugin itself.
While I was looking for a shortcut to switch between tabs I found this --> Eclipse HotKey: how to switch between tabs?
However I am not able to search the command /key binding/ Handler class that actually implements the Ctrl+PageDown key binding.
Similarly, I was able to find the key binding and the command of of M3+PAGE_DOWN (ALT+PAGE_DOWN) in plugins/org.eclipse.ui_some_version.jar (org.eclipse.ui_3.103.0.v20120705-114351.jar in my case) but not the Handler.
How can I find these out? Which plugin should I refer to?
Those commands get handled programatically inside
org.eclipse.ui.part.MultiPageEditorPart.
Good tools for analysing the origin of elements are the "Plug-In Registry" View, the "Plug-In Spy" and Google.
You can find the handler in org.eclipse.ui.workbench (see class org.eclipse.ui.part.MultiPageEditorPart)
The handler is defined programmatically and not declaratively:
public abstract class MultiPageEditorPart extends EditorPart implements IPageChangeProvider {
private static final String COMMAND_NEXT_SUB_TAB = "org.eclipse.ui.navigate.nextSubTab"; //$NON-NLS-1$
private void initializeSubTabSwitching() {
IHandlerService service = (IHandlerService) getSite().getService(IHandlerService.class);
service.activateHandler(COMMAND_NEXT_SUB_TAB, new AbstractHandler() {
// ...
}
});
}