intellij how to auto completion a class in string literal - intellij-idea

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

Related

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: custom code generation templates

How can I define custom code generation like Getters/Setters in IntelliJ. I took a look on their docs but they don't specify where I can do this. The code I would like IntelliJ to generate for me is like below:
public class Person {
private String name;
private String username;
//I want IntelliJ to propose me to generate this after Alt+Insert
public Person withName(String name){
setName(name);
return this;
}
//and this
public Person withUsername(String username){
setUsername(username);
return this;
}
}
Thanks a lot
When you press alt+insert you can click Getter and Setter. There are Getter template and Setter template drop-downs that you can select. Click the ... and you can create new templates.
It appears you're trying to follow the builder pattern. IntelliJ already has a setter template for this called "Builder". You can select it from the setter drop-down and you should be good.

intelij idea shortcut to implement interface as a new class

suppose i have a interface like this:
public interface Dumb{
String getDumbName();
}
Is there any shortcut or menu in intellij-idea to create new classes implementing the interface with dummy implement methods like this:
public class Dumber{
public String getDumbName(){
return null;
}
}
There are multiple ways to go about this.
On the interface name itself, you can hit Alt+Enter (Option+Enter on Mac), then pick 'Implement interface'. IDEA will prompt for a class name and a package to put the new class in, then generate an implementation class.
Alternatively, create the class, then add implements Dumb after the name (im<tab> Dumb). IDEA will complain that your class doesn't implement the correct methods, and offer (Alt+Enter Enter Enter) to generate them for you. Hitting Ctrl+I or clicking 'Implement methods' in the Code menu also works.

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.

struts2: select tag doesn't like beans with "parameters" property?

I have a base class ReportElement which has type property:
public abstract class ReportElement {
private ReportElementType type;
public ReportElementType getType() {
return type;
}
public void setType(ReportElementType type) {
this.type = type;
}
}
ReportElementType is just an enum with specified code and i18nKey properties for each element. I have a couple of subclasses of ReportElement, each of them introducing their own properties. One of them is Plot:
public class Plot extends ReportElement {
public Plot() {
setType(ReportElementType.PLOT);
}
private Collection<Parameter> parameters = new ArrayList<Parameter>();
public Collection<Parameter> getParameters() {
return parameters;
}
}
On some page I needed to display a collection of different ReportElement instances, so I just used struts2 select tag:
<s:select list="myElements" listKey="type.code" listValue="type.i18nKey" size="20"/>
This worked like a charm for every element except for Plot instaces. Instead of invoking getType().getCode() or getType().getI18nKey() plain toString() was invoked on every instance of Plot! After several hours of fun debugging I noticed that during tag evaluation Plot's getParameters() method is called! So it seems struts was trying to evaluate type.code and type.i18nKey using getParameters() method! Failing to do that it ignored the existence of the properties, that I have clearly specified for usage!
After renaming getParameters to a kind of odd name like getParamms the problem gone. Also the problem hasn't occured when using iterator tag together with property tag instead of select tag.
Does anyone have an idea WHY struts select tag uses parameters property of my bean, when I have clearly specified what property should be used? Is it some "cool" feature or a bug?
P.S. I use struts 2.2.3.1
The argument used in all the FreeMarker templates representing a tag's parameters is called parameters. By providing a parameters property that takes precedence, S2 was unable to get to the object on the stack containing the tag's parameters.
It's neither a cool feature nor a bug, it's just how the templates are implemented. Checking the template source may have saved the few hours of debugging.
Found corresponding issue in struts JIRA: https://issues.apache.org/jira/browse/WW-3268
2.3 is specified as fix version.