I'm using Lombok to generate accessor methods. I have my lombok.config file in module/src/main/java directory. The config file looks like this.
lombok.accessors.prefix += m
config.stopBubbling = true
I have the following in my code.
#Setter String mRoute;
This seems to generate the function getMRoute() instead of getRoute().
I've tried changing the location of the lombok.config file, and even installed the Lombok Plugin for IntelliJ.
Adding #Accessors(prefix = "m") before the class declaration fixes the issue.
#Accessors(prefix = "m")
public class MyClass {
#Getter private int mNum;
}
will generate getNum() instead of getMNum()
I think Android Studio is based on IntelliJ IDEA, and does not yet support lombok.config files.
Related
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.
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.
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.
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.
Im using IntelliJ IDEA 12. Can I customise code that is generated using "Refactor" functional?
For example I want to change the template of setting generation(Encapsulate fields) from:
public void setField(String field) {
this.field = field;
}
to
public MyClass setField(String field) {
this.field = field;
return this;
}
As far as I know, you can't do what you're suggesting in Intellij. There are plugins, however, that can help with the generation of fluent interfaces.
Some things you can change the template for. The setters and getters is not one of them. You can vote for the feature request IDEA-28206 Allow customization of generated getter/setter. Engineer Dollery is correct that there are some plugins for inserting customer setters & getters. But I do not believe there are any that will override the template used by the refactoring.