Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Only delete getters that have the canonical form #726

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.util.PropertyUtil;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
Expand All @@ -15,11 +14,10 @@ public class LombokGetterHandler extends BaseLombokHandler {

protected void processClass(@NotNull PsiClass psiClass) {
final Map<PsiField, PsiMethod> fieldMethodMap = new HashMap<>();
for (PsiField psiField : psiClass.getFields()) {
PsiMethod propertyGetter = PropertyUtil.findPropertyGetter(psiClass, psiField.getName(), psiField.hasModifierProperty(PsiModifier.STATIC), false);

if (null != propertyGetter) {
fieldMethodMap.put(psiField, propertyGetter);
for (PsiField field : psiClass.getFields()) {
PsiMethod getter = PropertyUtil.findGetterForField(field);
if (PropertyUtil.getFieldOfGetter(getter) == field) {
fieldMethodMap.put(field, getter);
}
}

Expand Down
19 changes: 19 additions & 0 deletions testData/action/lombok/getter/afterGetterSimple.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,23 @@ class Test {
private double c;
private String d;

private int wrongReturnType;
private int wrongField;
private int fieldWithoutGetter;
private int sideEffect;
private int javadoc;
private int comment;

public long getWrongReturnType() {
return wrongReturnType;
}

public int getWrongField() {
return wrongReturnType;
}

public int getSideEffect() {
System.out.println("side-effect");
return sideEffect;
}
}
30 changes: 30 additions & 0 deletions testData/action/lombok/getter/beforeGetterSimple.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ class Test {
private double c;
private String d;

private int wrongReturnType;
private int wrongField;
private int fieldWithoutGetter;
private int sideEffect;
private int javadoc;
private int comment;

public float getB() {
return b;
}
Expand All @@ -14,4 +21,27 @@ public double getC() {
public String getD() {
return d;
}

public long getWrongReturnType() {
return wrongReturnType;
}

public int getWrongField() {
return wrongReturnType;
}

public int getSideEffect() {
System.out.println("side-effect");
return sideEffect;
}

/** Javadoc. */
public int getJavadoc() {
return javadoc;
}

public int getComment() {
// An implementation comment.
return comment;
}
}