mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
[lombok] IDEA-289906 compare methods by equals, to support augmented elements
GitOrigin-RevId: 3117be560618625ee6750a96455e9be7e6da9d64
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ab2dd8e026
commit
60f3b284cf
@@ -263,7 +263,7 @@ public final class JavaEncapsulateFieldHelper extends EncapsulateFieldHelper {
|
||||
PsiClass aClass) throws IncorrectOperationException {
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(targetMethod.getProject());
|
||||
final PsiElement resolved = methodCall.getMethodExpression().resolve();
|
||||
if (resolved != targetMethod) {
|
||||
if (!targetMethod.equals(resolved)) {
|
||||
PsiClass containingClass;
|
||||
if (resolved instanceof PsiMethod) {
|
||||
containingClass = ((PsiMethod)resolved).getContainingClass();
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.encapsulateFields.*;
|
||||
import com.intellij.refactoring.util.DocCommentPolicy;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Assert;
|
||||
|
||||
public class EncapsulateFieldsTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
public void testAlreadyExist() {
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package de.plushnikov.intellij.plugin.refactoring;
|
||||
|
||||
import com.intellij.codeInsight.generation.GenerateMembersUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.refactoring.encapsulateFields.EncapsulateFieldsDescriptor;
|
||||
import com.intellij.refactoring.encapsulateFields.EncapsulateFieldsProcessor;
|
||||
import com.intellij.refactoring.encapsulateFields.FieldDescriptor;
|
||||
import com.intellij.refactoring.encapsulateFields.FieldDescriptorImpl;
|
||||
import com.intellij.refactoring.util.DocCommentPolicy;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import de.plushnikov.intellij.plugin.AbstractLombokLightCodeInsightTestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class LombokEncapsulateFieldsTest extends AbstractLombokLightCodeInsightTestCase {
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return super.getBasePath() + "/refactoring";
|
||||
}
|
||||
|
||||
public void testEncapsulateLombokFields() {
|
||||
doTest("EncapsulateLombokFields", "distanceFunction", "maxDistanceFunction", "qualityFunction", "uwbScoreFilter");
|
||||
}
|
||||
|
||||
public void testDataIssueEvent() {
|
||||
doTest("DataIssueEvent", "dataIssueLevel", "whereIsItComingFrom", "exceptionNullable");
|
||||
}
|
||||
|
||||
private void doTest(final String className, final String... fieldNames) {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
PsiClass aClass = myFixture.findClass(className);
|
||||
assertNotNull("Tested class not found", aClass);
|
||||
|
||||
doTest(aClass, ContainerUtil.map(fieldNames, name -> aClass.findFieldByName(name, false)));
|
||||
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.java", true);
|
||||
}
|
||||
|
||||
private static void doTest(final PsiClass aClass, final Collection<PsiField> fields) {
|
||||
final Project project = aClass.getProject();
|
||||
EncapsulateFieldsProcessor processor = new EncapsulateFieldsProcessor(project, new EncapsulateFieldsDescriptor() {
|
||||
@Override
|
||||
public FieldDescriptor[] getSelectedFields() {
|
||||
final List<FieldDescriptor> descriptors = new ArrayList<>(fields.size());
|
||||
for (PsiField field : fields) {
|
||||
descriptors.add(new FieldDescriptorImpl(
|
||||
field,
|
||||
GenerateMembersUtil.suggestGetterName(field),
|
||||
GenerateMembersUtil.suggestSetterName(field),
|
||||
GenerateMembersUtil.generateGetterPrototype(field),
|
||||
GenerateMembersUtil.generateSetterPrototype(field)
|
||||
));
|
||||
}
|
||||
return descriptors.toArray(FieldDescriptor[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToEncapsulateGet() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToEncapsulateSet() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToUseAccessorsWhenAccessible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFieldsVisibility() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessorsVisibility() {
|
||||
return PsiModifier.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getJavadocPolicy() {
|
||||
return DocCommentPolicy.MOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiClass getTargetClass() {
|
||||
return aClass;
|
||||
}
|
||||
});
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
}
|
||||
25
plugins/lombok/testData/refactoring/DataIssueEvent.java
Normal file
25
plugins/lombok/testData/refactoring/DataIssueEvent.java
Normal file
@@ -0,0 +1,25 @@
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
|
||||
@AllArgsConstructor
|
||||
public class DataIssueEvent {
|
||||
private Integer dataIssueLevel;
|
||||
private String whereIsItComingFrom;
|
||||
private String message;
|
||||
private Exception exceptionNullable;
|
||||
private String documentationNoteIdNullable;
|
||||
|
||||
public String toDisplayString() {
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(String.format("[%s][%s] %s",
|
||||
dataIssueLevel,
|
||||
whereIsItComingFrom.toLowerCase(),
|
||||
message));
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
|
||||
@AllArgsConstructor
|
||||
public class DataIssueEvent {
|
||||
private Integer dataIssueLevel;
|
||||
private String whereIsItComingFrom;
|
||||
private String message;
|
||||
private Exception exceptionNullable;
|
||||
private String documentationNoteIdNullable;
|
||||
|
||||
public String toDisplayString() {
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(String.format("[%s][%s] %s",
|
||||
getDataIssueLevel(),
|
||||
getWhereIsItComingFrom().toLowerCase(),
|
||||
message));
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
public class EncapsulateLombokFields {
|
||||
// Fields I want to replace with getter, in this class-code
|
||||
private String distanceFunction;
|
||||
@Setter
|
||||
private double maxDistanceFunction;
|
||||
private int qualityFunction;
|
||||
private Date uwbScoreFilter;
|
||||
|
||||
// Fields I want to keep unaltered
|
||||
private long obstructionTime;
|
||||
private boolean guessed;
|
||||
private double timeInterval;
|
||||
private String beyondWalls;
|
||||
|
||||
public EncapsulateLombokFields() {
|
||||
this.setUp();
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
// Field instantiates here
|
||||
distanceFunction = "xxx";
|
||||
maxDistanceFunction = 1.1;
|
||||
qualityFunction = 100;
|
||||
uwbScoreFilter = new Date();
|
||||
|
||||
obstructionTime = 0;
|
||||
guessed = true;
|
||||
timeInterval = 2.2;
|
||||
beyondWalls = "yyy";
|
||||
}
|
||||
|
||||
public boolean applyPostHeuristics() {
|
||||
// Main code of this class where fields are used without getter
|
||||
if (!distanceFunction.isEmpty()) {
|
||||
maxDistanceFunction *= 10;
|
||||
guessed = false;
|
||||
}
|
||||
if (qualityFunction < 100) {
|
||||
beyondWalls = uwbScoreFilter.toString();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
public class EncapsulateLombokFields {
|
||||
// Fields I want to replace with getter, in this class-code
|
||||
private String distanceFunction;
|
||||
@Setter
|
||||
private double maxDistanceFunction;
|
||||
private int qualityFunction;
|
||||
private Date uwbScoreFilter;
|
||||
|
||||
// Fields I want to keep unaltered
|
||||
private long obstructionTime;
|
||||
private boolean guessed;
|
||||
private double timeInterval;
|
||||
private String beyondWalls;
|
||||
|
||||
public EncapsulateLombokFields() {
|
||||
this.setUp();
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
// Field instantiates here
|
||||
setDistanceFunction("xxx");
|
||||
setMaxDistanceFunction(1.1);
|
||||
setQualityFunction(100);
|
||||
setUwbScoreFilter(new Date());
|
||||
|
||||
obstructionTime = 0;
|
||||
guessed = true;
|
||||
timeInterval = 2.2;
|
||||
beyondWalls = "yyy";
|
||||
}
|
||||
|
||||
public boolean applyPostHeuristics() {
|
||||
// Main code of this class where fields are used without getter
|
||||
if (!getDistanceFunction().isEmpty()) {
|
||||
setMaxDistanceFunction(getMaxDistanceFunction() * 10);
|
||||
guessed = false;
|
||||
}
|
||||
if (getQualityFunction() < 100) {
|
||||
beyondWalls = getUwbScoreFilter().toString();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setDistanceFunction(String distanceFunction) {
|
||||
this.distanceFunction = distanceFunction;
|
||||
}
|
||||
|
||||
public void setQualityFunction(int qualityFunction) {
|
||||
this.qualityFunction = qualityFunction;
|
||||
}
|
||||
|
||||
public void setUwbScoreFilter(Date uwbScoreFilter) {
|
||||
this.uwbScoreFilter = uwbScoreFilter;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user