mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
generate equals/hashCode: ensure one @Override is inserted; extensions could also provide their annotations on equals/hashCode override;
tests: language level is 1.5 though jdk is mockJdk14 without @Override as expected -> fqns in test data
This commit is contained in:
@@ -145,9 +145,6 @@ public class GenerateEqualsHelper implements Runnable {
|
||||
private PsiMethod createEquals() throws IncorrectOperationException {
|
||||
@NonNls StringBuilder buffer = new StringBuilder();
|
||||
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(myProject);
|
||||
if (shouldAddOverrideAnnotation(myClass)) {
|
||||
buffer.append("@Override\n");
|
||||
}
|
||||
ArrayList<PsiField> equalsFields = new ArrayList<PsiField>();
|
||||
ContainerUtil.addAll(equalsFields, myEqualsFields);
|
||||
Collections.sort(equalsFields, EqualsFieldsComparator.INSTANCE);
|
||||
@@ -165,7 +162,8 @@ public class GenerateEqualsHelper implements Runnable {
|
||||
nameSuggestions = codeStyleManager.suggestVariableName(VariableKind.PARAMETER, null, null, objectType).names;
|
||||
final String objectBaseName = nameSuggestions.length > 0 ? nameSuggestions[0] : "object";
|
||||
contextMap.put("baseParamName", objectBaseName);
|
||||
contextMap.put("superHasEquals", superMethodExists(getEqualsSignature(myProject, myClass.getResolveScope())));
|
||||
final MethodSignature equalsSignature = getEqualsSignature(myProject, myClass.getResolveScope());
|
||||
contextMap.put("superHasEquals", superMethodExists(equalsSignature));
|
||||
contextMap.put("checkParameterWithInstanceof", myCheckParameterWithInstanceof);
|
||||
|
||||
final String methodText = GenerationUtil
|
||||
@@ -185,6 +183,10 @@ public class GenerateEqualsHelper implements Runnable {
|
||||
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, styleSettings.GENERATE_FINAL_PARAMETERS);
|
||||
|
||||
PsiMethod method = (PsiMethod)myCodeStyleManager.reformat(result);
|
||||
final PsiMethod superEquals = MethodSignatureUtil.findMethodBySignature(myClass, equalsSignature, true);
|
||||
if (superEquals != null) {
|
||||
OverrideImplementUtil.annotateOnOverrideImplement(method, myClass, superEquals);
|
||||
}
|
||||
method = (PsiMethod)myJavaCodeStyleManager.shortenClassReferences(method);
|
||||
return method;
|
||||
}
|
||||
@@ -200,10 +202,6 @@ public class GenerateEqualsHelper implements Runnable {
|
||||
private PsiMethod createHashCode() throws IncorrectOperationException {
|
||||
@NonNls StringBuilder buffer = new StringBuilder();
|
||||
|
||||
if (shouldAddOverrideAnnotation(myClass)) {
|
||||
buffer.append("@Override\n");
|
||||
}
|
||||
|
||||
final HashMap<String, Object> contextMap = new HashMap<String, Object>();
|
||||
contextMap.put("superHasHashCode", mySuperHasHashCode);
|
||||
|
||||
@@ -218,6 +216,10 @@ public class GenerateEqualsHelper implements Runnable {
|
||||
catch (IncorrectOperationException e) {
|
||||
return null;
|
||||
}
|
||||
final PsiMethod superHashCode = MethodSignatureUtil.findMethodBySignature(myClass, getHashCodeSignature(), true);
|
||||
if (superHashCode != null) {
|
||||
OverrideImplementUtil.annotateOnOverrideImplement(hashCode, myClass, superHashCode);
|
||||
}
|
||||
hashCode = (PsiMethod)myJavaCodeStyleManager.shortenClassReferences(hashCode);
|
||||
return (PsiMethod)myCodeStyleManager.reformat(hashCode);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Arrays {
|
||||
int[] i;
|
||||
|
||||
@Override
|
||||
@java.lang.Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
@@ -13,7 +13,7 @@ class Arrays {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@java.lang.Override
|
||||
public int hashCode() {
|
||||
return i != null ? i.hashCode() : 0;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Test {
|
||||
int i;
|
||||
|
||||
@Override
|
||||
@java.lang.Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
@@ -13,7 +13,7 @@ class Test {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@java.lang.Override
|
||||
public int hashCode() {
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Integer {
|
||||
int i;
|
||||
|
||||
@Override
|
||||
@java.lang.Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
@@ -13,7 +13,7 @@ class Integer {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@java.lang.Override
|
||||
public int hashCode() {
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ class Test {
|
||||
class Integer {
|
||||
int i;
|
||||
|
||||
@Override
|
||||
@java.lang.Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
@@ -15,7 +15,7 @@ class Test {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@java.lang.Override
|
||||
public int hashCode() {
|
||||
return i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user