IntelliJ IDEA: Unnecessary space after reformatting - intellij-idea

I'm new to IntelliJ and need some help for some issue when I'm reformatting the code.
For example, let's say I have this code which is ,at first, written in other IDE(Eclipse).
#Service
public class TestService {
private Logger logger = LoggerFactory.getLogger(getClass());
//...
}
If I reformat code(cmd+option+L)...
#Service
public class TestService {
____private Logger logger = LoggerFactory.getLogger(getClass());
//...
}
IntelliJ somehow generates some silly empty spaces that make git to think something changed.
I'm currently using the most recent version of IntellJ on M1 Mac. I also did import Eclipse code style into IntelliJ. Is there any configuration to resolve this problem?

Probably your tab characters were auto-replaced by space characters because that is IntelliJ defaults.
Go to "Preferences | Editor | Code Style | Java" and click "Use tab character" to keep your tabs.

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.

org.jetbrains.annotations.NotNull instead of javax.annotation.Nonnull when implement method in 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.

Intellij - Private final string somehow null

I have the following line in my class:
public class myClass {
private final String MY_VAR = "PY-PP";
...
}
But somehow whenever I inspect my code in debug, that variable is null, it is not being used anywhere except in 1 place to read, any ideas?
I have tried invalidating caches, rebuilding whole project and redeploying the server with no luck, this is a brand new intellij install as well.

intellij how to auto completion a class in string literal

I have defined a method like below:
public void mehtod(String clazz) {
...
}
clazz parameter is a FQDN name as: com.example.Hello, and I want intellij to autocomplete when i type "com.example.Hello".
Do I need to make some custom config in Intellij?
You can use "Class Name Completion" for this.
Ctrl-Option-Space on Mac, Ctrl-Alt-SPace on Windows
I agree with "JB Nizet", though: Use Hello.class.getName() is more reliable

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() {
// ...
}
});
}