diff --git a/README.md b/README.md
index 96a8ce59c..b2a3bdb89 100644
--- a/README.md
+++ b/README.md
@@ -13,20 +13,28 @@ lombok-intellij-plugin [![Donate](https://www.paypal.com/en_US/i/btn/btn_donateC
Provides support for lombok annotations to write great Java code with IntelliJ IDEA.
-**Last version (0.30) released on 05.09.2020**
+**Last version (0.31) released on 06.09.2020**
---
-## Unfortunately the current IntelliJ 2020.2 version has a bug and lombok plugin can't be used normally.
-## Use previous IntelliJ version 2020.1 or update to IntelliJ IDEA 2020.2.1
+:collision: **Unfortunately the current IntelliJ 2020.2 version has a bug and lombok plugin can't be used normally.** :collision:
+
+:hammer_and_wrench: Use previous IntelliJ version 2020.1 or update to IntelliJ IDEA 2020.2.1
+---
+
+:collision: **The latest IntelliJ IDEA versions still contains a BUG :beetle: for several plugins (including plugin for Lombok) were shown as incompatible with the updated version of the IDE.** :collision:
+
+You can find the issue with a detailed explanation here: https://youtrack.jetbrains.com/issue/IDEA-237113 and https://youtrack.jetbrains.com/issue/IDEA-246822
+
+:hammer_and_wrench: As of now, the workaround is to re-install the plugin in the IDE settings.
---
35th version of plugin released.
Install it automatically from IntelliJ Idea plugin repository.
-Tested and supports IntelliJ versions: 2016.2, 2016.3, 2017.X, 2018.X, 2019.1, 2019.2, 2019.3, 2020.1 and 2020.2.1
+Tested and supports IntelliJ versions: 2017.X, 2018.X, 2019.X, 2020.1 and 2020.2.1
-Last support for IntelliJ 2016.2 and 2016.3 by plugin version 0.30!
+Last support for IntelliJ 2016.2 and 2016.3 by plugin version 0.31!
Last support for IntelliJ 15.0.6 and 2016.1 by plugin version 0.19!
diff --git a/build.gradle b/build.gradle
index 83dc2b4e6..4420cad01 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,5 +1,5 @@
plugins {
- id "org.jetbrains.intellij" version "0.4.22"
+ id "org.jetbrains.intellij" version "0.4.26"
id "org.jetbrains.grammarkit" version "2018.3"
id "com.github.ManifestClasspath" version "0.1.0-RELEASE"
}
@@ -81,8 +81,8 @@ dependencies {
lombok group: 'org.projectlombok', name: 'lombok', version: '1.18.12', classifier: 'sources', ext: 'jar'
testImplementation("junit:junit:4.13")
- testImplementation("org.mockito:mockito-core:3.5.10")
- testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.6.2")
+ testImplementation("org.mockito:mockito-core:3.5.11")
+ testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.7.0")
}
// Tasks
diff --git a/gradle.properties b/gradle.properties
index 651a9b276..8118b3772 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -7,7 +7,7 @@ ideaVersion=2017.1
#
pluginGroup=de.plushnikov.intellij.plugin
pluginName=lombok-plugin
-pluginVersion=0.31
+pluginVersion=0.32
#
javaVersion=1.8
sources=true
diff --git a/parts/pluginChanges.html b/parts/pluginChanges.html
index a607978be..2c0cf3452 100644
--- a/parts/pluginChanges.html
+++ b/parts/pluginChanges.html
@@ -1,4 +1,12 @@
+ - 0.32
+
+ - Fixed #761: EqualsAndHashCode: Wrong warning 'A method with one of those names already exists'
+ - Fixed #826: Error if using @FieldNameConstants in switch case
+ - Fixed #858: Delombok produces duplicate @NonNull annotations on setters/getters
+ - Fixed #933: Enable annotation processing warning showing everytime project is opened
+
+
- 0.31
- Fixed #923: ArrayIndexOutOfBoundsException in ReplaceExplicitTypeWithVariableIntention
diff --git a/settings.gradle b/settings.gradle
index f1e90982a..934d131ab 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1 +1,13 @@
-rootProject.name = 'lombok-plugin'
\ No newline at end of file
+pluginManagement {
+ repositories {
+ maven {
+ url 'https://jetbrains.bintray.com/intellij-plugin-service'
+ }
+ maven {
+ url "https://plugins.gradle.org/m2/"
+ }
+ mavenCentral()
+ }
+}
+
+rootProject.name = 'lombok-plugin'
diff --git a/src/main/java/de/plushnikov/intellij/plugin/Version.java b/src/main/java/de/plushnikov/intellij/plugin/Version.java
index 5f11b21b8..d2bc66589 100644
--- a/src/main/java/de/plushnikov/intellij/plugin/Version.java
+++ b/src/main/java/de/plushnikov/intellij/plugin/Version.java
@@ -5,7 +5,7 @@ public interface Version {
/**
* Current plugin version.
*/
- String PLUGIN_VERSION = "0.31";
+ String PLUGIN_VERSION = "0.32";
/**
* Current version of lombok plugin
*/
diff --git a/src/main/java/de/plushnikov/intellij/plugin/action/delombok/DelombokHandler.java b/src/main/java/de/plushnikov/intellij/plugin/action/delombok/DelombokHandler.java
index e3174c5e7..6ab6f4fb7 100644
--- a/src/main/java/de/plushnikov/intellij/plugin/action/delombok/DelombokHandler.java
+++ b/src/main/java/de/plushnikov/intellij/plugin/action/delombok/DelombokHandler.java
@@ -236,31 +236,21 @@ private PsiMethod rebuildMethod(@NotNull Project project, @NotNull PsiMethod fro
resultMethod.getThrowsList().replace(elementFactory.createReferenceList(refs));
}
- for (PsiParameter parameter : fromMethod.getParameterList().getParameters()) {
- PsiParameter param = elementFactory.createParameter(parameter.getName(), parameter.getType());
- final PsiModifierList parameterModifierList = parameter.getModifierList();
- if (parameterModifierList != null) {
- PsiModifierList modifierList = param.getModifierList();
- for (PsiAnnotation originalAnnotation : parameterModifierList.getAnnotations()) {
- final PsiAnnotation annotation = modifierList.addAnnotation(originalAnnotation.getQualifiedName());
- for (PsiNameValuePair nameValuePair : originalAnnotation.getParameterList().getAttributes()) {
- annotation.setDeclaredAttributeValue(nameValuePair.getName(), nameValuePair.getValue());
- }
- }
- modifierList.setModifierProperty(PsiModifier.FINAL, parameterModifierList.hasModifierProperty(PsiModifier.FINAL));
+ for (PsiParameter fromParameter : fromMethod.getParameterList().getParameters()) {
+ PsiParameter toParameter = elementFactory.createParameter(fromParameter.getName(), fromParameter.getType());
+ final PsiModifierList fromParameterModifierList = fromParameter.getModifierList();
+ if (fromParameterModifierList != null) {
+ final PsiModifierList toParameterModifierList = toParameter.getModifierList();
+ copyAnnotations(fromParameterModifierList, toParameterModifierList);
+ toParameterModifierList.setModifierProperty(PsiModifier.FINAL, fromParameterModifierList.hasModifierProperty(PsiModifier.FINAL));
}
- resultMethod.getParameterList().add(param);
+ resultMethod.getParameterList().add(toParameter);
}
final PsiModifierList fromMethodModifierList = fromMethod.getModifierList();
final PsiModifierList resultMethodModifierList = resultMethod.getModifierList();
copyModifiers(fromMethodModifierList, resultMethodModifierList);
- for (PsiAnnotation psiAnnotation : fromMethodModifierList.getAnnotations()) {
- final PsiAnnotation annotation = resultMethodModifierList.addAnnotation(psiAnnotation.getQualifiedName());
- for (PsiNameValuePair nameValuePair : psiAnnotation.getParameterList().getAttributes()) {
- annotation.setDeclaredAttributeValue(nameValuePair.getName(), nameValuePair.getValue());
- }
- }
+ copyAnnotations(fromMethodModifierList, resultMethodModifierList);
PsiCodeBlock body = fromMethod.getBody();
if (null != body) {
@@ -272,6 +262,21 @@ private PsiMethod rebuildMethod(@NotNull Project project, @NotNull PsiMethod fro
return (PsiMethod) CodeStyleManager.getInstance(project).reformat(resultMethod);
}
+ private void copyAnnotations(@NotNull PsiModifierList fromModifierList, @NotNull PsiModifierList toModifierList) {
+ final Set existedAnnotation = Stream.of(toModifierList.getAnnotations())
+ .map(PsiAnnotation::getQualifiedName)
+ .collect(Collectors.toSet());
+ for (PsiAnnotation originalAnnotation : fromModifierList.getAnnotations()) {
+ final String qualifiedName = StringUtil.notNullize(originalAnnotation.getQualifiedName());
+ if (!existedAnnotation.contains(qualifiedName)) {
+ final PsiAnnotation annotation = toModifierList.addAnnotation(qualifiedName);
+ for (PsiNameValuePair nameValuePair : originalAnnotation.getParameterList().getAttributes()) {
+ annotation.setDeclaredAttributeValue(nameValuePair.getName(), nameValuePair.getValue());
+ }
+ }
+ }
+ }
+
private void rebuildTypeParameter(@NotNull PsiTypeParameterListOwner listOwner, @NotNull PsiTypeParameterListOwner resultOwner) {
final PsiTypeParameterList resultOwnerTypeParameterList = resultOwner.getTypeParameterList();
if (null != resultOwnerTypeParameterList) {
diff --git a/src/main/java/de/plushnikov/intellij/plugin/activity/LombokProjectValidatorActivity.java b/src/main/java/de/plushnikov/intellij/plugin/activity/LombokProjectValidatorActivity.java
index c07082607..9a97e9886 100644
--- a/src/main/java/de/plushnikov/intellij/plugin/activity/LombokProjectValidatorActivity.java
+++ b/src/main/java/de/plushnikov/intellij/plugin/activity/LombokProjectValidatorActivity.java
@@ -5,7 +5,6 @@
import com.intellij.notification.*;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
-import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootManager;
@@ -121,9 +120,9 @@ private CompilerConfigurationImpl getCompilerConfiguration(Project project) {
}
private boolean hasAnnotationProcessorsEnabled(Project project) {
- CompilerConfigurationImpl compilerConfiguration = getCompilerConfiguration(project);
+ final CompilerConfigurationImpl compilerConfiguration = getCompilerConfiguration(project);
return compilerConfiguration.getDefaultProcessorProfile().isEnabled() &&
- compilerConfiguration.getModuleProcessorProfiles().stream().anyMatch(AnnotationProcessingConfiguration::isEnabled);
+ compilerConfiguration.getModuleProcessorProfiles().stream().allMatch(AnnotationProcessingConfiguration::isEnabled);
}
private boolean hasLombokLibrary(Project project) {
@@ -179,26 +178,4 @@ int compareVersionString(@NotNull String firstVersionOne, @NotNull String second
}
return 0;
}
-
- /**
- * Simple {@link NotificationListener.Adapter} that opens Settings Page for correct dialog.
- */
- private static class SettingsOpeningListener extends NotificationListener.Adapter {
-
- private final Project project;
- private final String nameToSelect;
-
- SettingsOpeningListener(Project project, String nameToSelect) {
- this.project = project;
- this.nameToSelect = nameToSelect;
- }
-
- @Override
- protected void hyperlinkActivated(@NotNull final Notification notification, @NotNull final HyperlinkEvent e) {
-
- if (!project.isDisposed()) {
- ShowSettingsUtil.getInstance().showSettingsDialog(project, nameToSelect);
- }
- }
- }
}
diff --git a/src/main/java/de/plushnikov/intellij/plugin/extension/LombokHighlightErrorFilter.java b/src/main/java/de/plushnikov/intellij/plugin/extension/LombokHighlightErrorFilter.java
index 792bdf42c..e24970c2c 100644
--- a/src/main/java/de/plushnikov/intellij/plugin/extension/LombokHighlightErrorFilter.java
+++ b/src/main/java/de/plushnikov/intellij/plugin/extension/LombokHighlightErrorFilter.java
@@ -8,10 +8,7 @@
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
-import de.plushnikov.intellij.plugin.handler.BuilderHandler;
-import de.plushnikov.intellij.plugin.handler.EqualsAndHashCodeCallSuperHandler;
-import de.plushnikov.intellij.plugin.handler.LazyGetterHandler;
-import de.plushnikov.intellij.plugin.handler.OnXAnnotationHandler;
+import de.plushnikov.intellij.plugin.handler.*;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -19,7 +16,6 @@
import java.util.*;
import java.util.regex.Pattern;
-
public class LombokHighlightErrorFilter implements HighlightInfoFilter {
private static final Pattern LOMBOK_ANY_ANNOTATION_REQUIRED = Pattern.compile("Incompatible types\\. Found: '__*', required: 'lombok.*AnyAnnotation\\[\\]'");
@@ -143,6 +139,19 @@ public boolean accept(@NotNull PsiElement highlightedElement) {
}
},
+ CONSTANT_EXPRESSION_REQUIRED(HighlightSeverity.ERROR, CodeInsightColors.ERRORS_ATTRIBUTES) {
+ @Override
+ public boolean descriptionCheck(@Nullable String description) {
+// message("constant.expression.required")
+ return "Constant expression required".equals(description);
+ }
+
+ @Override
+ public boolean accept(@NotNull PsiElement highlightedElement) {
+ return !FieldNameConstantsHandler.isFiledNameConstants(highlightedElement);
+ }
+ },
+
// WARNINGS HANDLERS
VARIABLE_INITIALIZER_IS_REDUNDANT(HighlightSeverity.WARNING, CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES) {
diff --git a/src/main/java/de/plushnikov/intellij/plugin/handler/FieldNameConstantsHandler.java b/src/main/java/de/plushnikov/intellij/plugin/handler/FieldNameConstantsHandler.java
new file mode 100644
index 000000000..272999925
--- /dev/null
+++ b/src/main/java/de/plushnikov/intellij/plugin/handler/FieldNameConstantsHandler.java
@@ -0,0 +1,25 @@
+package de.plushnikov.intellij.plugin.handler;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiModifierListOwner;
+import com.intellij.psi.PsiReferenceExpression;
+import com.intellij.psi.util.PsiTreeUtil;
+import de.plushnikov.intellij.plugin.util.PsiAnnotationSearchUtil;
+import lombok.experimental.FieldNameConstants;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public class FieldNameConstantsHandler {
+
+ public static boolean isFiledNameConstants(@NotNull PsiElement element) {
+ @Nullable PsiReferenceExpression psiReferenceExpression = PsiTreeUtil.getParentOfType(element, PsiReferenceExpression.class);
+ if (psiReferenceExpression == null) {
+ return false;
+ }
+ PsiElement psiElement = psiReferenceExpression.resolve();
+ if (!(psiElement instanceof PsiModifierListOwner)) {
+ return false;
+ }
+ return PsiAnnotationSearchUtil.isAnnotatedWith((PsiModifierListOwner) psiElement, FieldNameConstants.class);
+ }
+}
diff --git a/src/main/java/de/plushnikov/intellij/plugin/processor/ValProcessor.java b/src/main/java/de/plushnikov/intellij/plugin/processor/ValProcessor.java
index c1db99791..2f00f7aeb 100644
--- a/src/main/java/de/plushnikov/intellij/plugin/processor/ValProcessor.java
+++ b/src/main/java/de/plushnikov/intellij/plugin/processor/ValProcessor.java
@@ -183,14 +183,18 @@ public void verifyParameter(@NotNull final PsiParameter psiParameter, @NotNull f
}
}
+ private boolean canInferType(@NotNull PsiTypeElement typeElement) {
+ final PsiElement parent = typeElement.getParent();
+ return (parent instanceof PsiLocalVariable && isValOrVar((PsiLocalVariable) parent)) ||
+ (parent instanceof PsiParameter && isValOrVarForEach((PsiParameter) parent));
+ }
+
@Nullable
public PsiType inferType(PsiTypeElement typeElement) {
PsiType psiType = null;
- final PsiElement parent = typeElement.getParent();
- if ((parent instanceof PsiLocalVariable && isValOrVar((PsiLocalVariable) parent)) ||
- (parent instanceof PsiParameter && isValOrVarForEach((PsiParameter) parent))) {
-
+ if (canInferType(typeElement)) {
+ final PsiElement parent = typeElement.getParent();
if (parent instanceof PsiLocalVariable) {
psiType = processLocalVariableInitializer(((PsiLocalVariable) parent).getInitializer());
} else {
diff --git a/src/main/java/de/plushnikov/intellij/plugin/processor/clazz/EqualsAndHashCodeProcessor.java b/src/main/java/de/plushnikov/intellij/plugin/processor/clazz/EqualsAndHashCodeProcessor.java
index 2c2aa4398..a484df867 100644
--- a/src/main/java/de/plushnikov/intellij/plugin/processor/clazz/EqualsAndHashCodeProcessor.java
+++ b/src/main/java/de/plushnikov/intellij/plugin/processor/clazz/EqualsAndHashCodeProcessor.java
@@ -114,17 +114,16 @@ private boolean validateAnnotationOnRightType(@NotNull PsiClass psiClass, @NotNu
return result;
}
- private boolean validateExistingMethods(@NotNull PsiClass psiClass, @NotNull ProblemBuilder builder) {
+ private void validateExistingMethods(@NotNull PsiClass psiClass, @NotNull ProblemBuilder builder) {
if (hasOneOfMethodsDefined(psiClass)) {
builder.addWarning("Not generating equals and hashCode: A method with one of those names already exists. (Either both or none of these methods will be generated).");
- return false;
}
- return true;
}
private boolean hasOneOfMethodsDefined(@NotNull PsiClass psiClass) {
final Collection classMethodsIntern = PsiClassUtil.collectClassMethodsIntern(psiClass);
- return PsiMethodUtil.hasMethodByName(classMethodsIntern, EQUALS_METHOD_NAME, HASH_CODE_METHOD_NAME);
+ return PsiMethodUtil.hasMethodByName(classMethodsIntern, EQUALS_METHOD_NAME, 1) ||
+ PsiMethodUtil.hasMethodByName(classMethodsIntern, HASH_CODE_METHOD_NAME, 0);
}
protected void generatePsiElements(@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation, @NotNull List super PsiElement> target) {
@@ -145,7 +144,7 @@ protected Collection createEqualAndHashCode(@NotNull PsiClass psiClas
result.add(createEqualsMethod(psiClass, psiAnnotation, shouldGenerateCanEqual, memberInfos));
final Collection classMethods = PsiClassUtil.collectClassMethodsIntern(psiClass);
- if (shouldGenerateCanEqual && !PsiMethodUtil.hasMethodByName(classMethods, CAN_EQUAL_METHOD_NAME)) {
+ if (shouldGenerateCanEqual && !PsiMethodUtil.hasMethodByName(classMethods, CAN_EQUAL_METHOD_NAME, 1)) {
result.add(createCanEqualMethod(psiClass, psiAnnotation));
}
diff --git a/src/main/java/de/plushnikov/intellij/plugin/processor/clazz/ToStringProcessor.java b/src/main/java/de/plushnikov/intellij/plugin/processor/clazz/ToStringProcessor.java
index d67d879c4..a7c654407 100644
--- a/src/main/java/de/plushnikov/intellij/plugin/processor/clazz/ToStringProcessor.java
+++ b/src/main/java/de/plushnikov/intellij/plugin/processor/clazz/ToStringProcessor.java
@@ -29,7 +29,7 @@
*/
public class ToStringProcessor extends AbstractClassProcessor {
- public static final String METHOD_NAME = "toString";
+ public static final String TO_STRING_METHOD_NAME = "toString";
private static final String INCLUDE_ANNOTATION_METHOD = "name";
private static final String INCLUDE_ANNOTATION_RANK = "rank";
@@ -75,16 +75,15 @@ private boolean validateAnnotationOnRigthType(@NotNull PsiClass psiClass, @NotNu
return result;
}
- private boolean validateExistingMethods(@NotNull PsiClass psiClass, @NotNull ProblemBuilder builder) {
- boolean result = true;
-
- final Collection classMethods = PsiClassUtil.collectClassMethodsIntern(psiClass);
- if (PsiMethodUtil.hasMethodByName(classMethods, METHOD_NAME)) {
- builder.addWarning("Not generated '%s'(): A method with same name already exists", METHOD_NAME);
- result = false;
+ private void validateExistingMethods(@NotNull PsiClass psiClass, @NotNull ProblemBuilder builder) {
+ if (hasToStringMethodDefined(psiClass)) {
+ builder.addWarning("Not generated '%s'(): A method with same name already exists", TO_STRING_METHOD_NAME);
}
+ }
- return result;
+ private boolean hasToStringMethodDefined(@NotNull PsiClass psiClass) {
+ final Collection classMethods = PsiClassUtil.collectClassMethodsIntern(psiClass);
+ return PsiMethodUtil.hasMethodByName(classMethods, TO_STRING_METHOD_NAME, 0);
}
protected void generatePsiElements(@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation, @NotNull List super PsiElement> target) {
@@ -93,8 +92,7 @@ protected void generatePsiElements(@NotNull PsiClass psiClass, @NotNull PsiAnnot
@NotNull
Collection createToStringMethod(@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation) {
- final Collection classMethods = PsiClassUtil.collectClassMethodsIntern(psiClass);
- if (PsiMethodUtil.hasMethodByName(classMethods, METHOD_NAME)) {
+ if (hasToStringMethodDefined(psiClass)) {
return Collections.emptyList();
}
@@ -110,7 +108,7 @@ public PsiMethod createToStringMethod(@NotNull PsiClass psiClass, @NotNull Colle
final String paramString = createParamString(psiClass, memberInfos, psiAnnotation, forceCallSuper);
final String blockText = String.format("return \"%s(%s)\";", getSimpleClassName(psiClass), paramString);
- final LombokLightMethodBuilder methodBuilder = new LombokLightMethodBuilder(psiManager, METHOD_NAME)
+ final LombokLightMethodBuilder methodBuilder = new LombokLightMethodBuilder(psiManager, TO_STRING_METHOD_NAME)
.withMethodReturnType(PsiType.getJavaLangString(psiManager, GlobalSearchScope.allScope(psiClass.getProject())))
.withContainingClass(psiClass)
.withNavigationElement(psiAnnotation)
diff --git a/src/main/java/de/plushnikov/intellij/plugin/processor/clazz/builder/BuilderPreDefinedInnerClassMethodProcessor.java b/src/main/java/de/plushnikov/intellij/plugin/processor/clazz/builder/BuilderPreDefinedInnerClassMethodProcessor.java
index 4e22f03c5..3b297b89a 100644
--- a/src/main/java/de/plushnikov/intellij/plugin/processor/clazz/builder/BuilderPreDefinedInnerClassMethodProcessor.java
+++ b/src/main/java/de/plushnikov/intellij/plugin/processor/clazz/builder/BuilderPreDefinedInnerClassMethodProcessor.java
@@ -61,7 +61,7 @@ protected Collection extends PsiElement> generatePsiElements(@NotNull PsiClass
}
// create 'toString' method
- if (!existedMethodNames.contains(ToStringProcessor.METHOD_NAME)) {
+ if (!existedMethodNames.contains(ToStringProcessor.TO_STRING_METHOD_NAME)) {
result.add(builderHandler.createToStringMethod(psiAnnotation, psiBuilderClass));
}
diff --git a/src/main/java/de/plushnikov/intellij/plugin/processor/handler/EqualsAndHashCodeToStringHandler.java b/src/main/java/de/plushnikov/intellij/plugin/processor/handler/EqualsAndHashCodeToStringHandler.java
index e853a4a5f..c2bd5644c 100644
--- a/src/main/java/de/plushnikov/intellij/plugin/processor/handler/EqualsAndHashCodeToStringHandler.java
+++ b/src/main/java/de/plushnikov/intellij/plugin/processor/handler/EqualsAndHashCodeToStringHandler.java
@@ -211,7 +211,7 @@ private String buildAttributeNameString(boolean doNotUseGetters, @NotNull PsiFie
final PsiAnnotation getterLombokAnnotation = PsiAnnotationSearchUtil.findAnnotation(psiClass, Getter.class);
hasGetter = null == getterLombokAnnotation || null != LombokProcessorUtil.getMethodModifier(getterLombokAnnotation);
} else {
- hasGetter = PsiMethodUtil.hasMethodByName(PsiClassUtil.collectClassMethodsIntern(psiClass), getterName);
+ hasGetter = PsiMethodUtil.hasMethodByName(PsiClassUtil.collectClassMethodsIntern(psiClass), getterName, 0);
}
return hasGetter ? getterName + "()" : fieldName;
diff --git a/src/main/java/de/plushnikov/intellij/plugin/processor/handler/SuperBuilderHandler.java b/src/main/java/de/plushnikov/intellij/plugin/processor/handler/SuperBuilderHandler.java
index 4cbe10e2c..02d55a675 100644
--- a/src/main/java/de/plushnikov/intellij/plugin/processor/handler/SuperBuilderHandler.java
+++ b/src/main/java/de/plushnikov/intellij/plugin/processor/handler/SuperBuilderHandler.java
@@ -343,7 +343,7 @@ private Collection addAllMethodsForBaseBuilderClass(@NotNull PsiClass
result.add(buildMethod);
}
- if (!existedMethodNames.contains(ToStringProcessor.METHOD_NAME)) {
+ if (!existedMethodNames.contains(ToStringProcessor.TO_STRING_METHOD_NAME)) {
// create 'toString' method
result.add(createToStringMethod(psiAnnotation, baseClassBuilder, forceCallSuper));
}
diff --git a/src/main/java/de/plushnikov/intellij/plugin/util/LombokRuntimeVersion.java b/src/main/java/de/plushnikov/intellij/plugin/util/LombokRuntimeVersion.java
deleted file mode 100644
index 5b42551ea..000000000
--- a/src/main/java/de/plushnikov/intellij/plugin/util/LombokRuntimeVersion.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package de.plushnikov.intellij.plugin.util;
-
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.ProjectRootManager;
-import com.intellij.openapi.vfs.VirtualFile;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Objects;
-import java.util.stream.Collectors;
-
-public class LombokRuntimeVersion {
- public String findCurrentLombokVersion() {
- //"1.18.4" -> @FieldNameConstants redesigned
- //"1.18.2" -> @SuperBuilder added
- //"1.18.0" -> @Flogger added
- //"1.16.22" -> lombok.experimental.Builder and lombok.experimental.Value were removed
- //"1.16.16" -> @Builder.Default added
- //"1.16.12" -> @var added
- //"1.16.10" -> JBoss logger added
- //"1.16.6" -> @Helper added
-
- return "";
- }
-
- public Collection getLombokJarsInProject(@NotNull Project project) {
- List pathsFiles = ProjectRootManager.getInstance(project).orderEntries().withoutSdk().librariesOnly().getPathsList().getVirtualFiles();
- return pathsFiles.stream()
- .filter(file -> Objects.equals(file.getExtension(), "jar"))
- .filter(file -> file.getNameWithoutExtension().contains("lombok-"))
- .map(VirtualFile::getNameWithoutExtension)
- .collect(Collectors.toSet());
- }
-}
diff --git a/src/main/java/de/plushnikov/intellij/plugin/util/PsiMethodUtil.java b/src/main/java/de/plushnikov/intellij/plugin/util/PsiMethodUtil.java
index bcd3a1781..ff3826e8a 100644
--- a/src/main/java/de/plushnikov/intellij/plugin/util/PsiMethodUtil.java
+++ b/src/main/java/de/plushnikov/intellij/plugin/util/PsiMethodUtil.java
@@ -3,9 +3,7 @@
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.List;
/**
* @author Plushnikov Michail
@@ -17,35 +15,25 @@ public static PsiCodeBlock createCodeBlockFromText(@NotNull String blockText, @N
return elementFactory.createCodeBlockFromText("{" + blockText + "}", psiElement);
}
- public static boolean hasMethodByName(@NotNull Collection classMethods, @NotNull String methodName) {
- return classMethods.stream().map(PsiMethod::getName).anyMatch(methodName::equals);
+ public static boolean hasMethodByName(@NotNull Collection classMethods, @NotNull String methodName, int paramCount) {
+ return classMethods.stream()
+ .filter(m -> methodName.equals(m.getName()))
+ .anyMatch(m -> acceptedParameterCount(m, paramCount));
}
- public static boolean hasMethodByName(@NotNull Collection classMethods, String... methodNames) {
- final List searchedMethodNames = Arrays.asList(methodNames);
- return classMethods.stream().map(PsiMethod::getName).anyMatch(searchedMethodNames::contains);
+ public static boolean hasSimilarMethod(@NotNull Collection classMethods, @NotNull String methodName, int paramCount) {
+ return classMethods.stream()
+ .filter(m -> methodName.equalsIgnoreCase(m.getName()))
+ .anyMatch(m -> acceptedParameterCount(m, paramCount));
}
- public static boolean hasSimilarMethod(@NotNull Collection classMethods, @NotNull String methodName, int methodArgCount) {
- for (PsiMethod classMethod : classMethods) {
- if (isSimilarMethod(classMethod, methodName, methodArgCount)) {
- return true;
- }
+ private static boolean acceptedParameterCount(@NotNull PsiMethod classMethod, int methodArgCount) {
+ int minArgs = classMethod.getParameterList().getParametersCount();
+ int maxArgs = minArgs;
+ if (classMethod.isVarArgs()) {
+ minArgs--;
+ maxArgs = Integer.MAX_VALUE;
}
- return false;
- }
-
- private static boolean isSimilarMethod(@NotNull PsiMethod classMethod, @NotNull String methodName, int methodArgCount) {
- boolean equalNames = methodName.equalsIgnoreCase(classMethod.getName());
- if (equalNames) {
- int minArgs = classMethod.getParameterList().getParametersCount();
- int maxArgs = minArgs;
- if (classMethod.isVarArgs()) {
- minArgs--;
- maxArgs = Integer.MAX_VALUE;
- }
- return !(methodArgCount < minArgs || methodArgCount > maxArgs);
- }
- return false;
+ return !(methodArgCount < minArgs || methodArgCount > maxArgs);
}
}
diff --git a/src/main/resources/messages/lombokBundle.properties b/src/main/resources/messages/lombokBundle.properties
index c11d31863..25af7570f 100644
--- a/src/main/resources/messages/lombokBundle.properties
+++ b/src/main/resources/messages/lombokBundle.properties
@@ -20,7 +20,10 @@ daemon.donate.title=Lombok support plugin updated to v{0}
daemon.donate.content=
\
Helpful? Donate with PayPal
\
Fixes:
\
-- Fixed (#923): ArrayIndexOutOfBoundsException in ReplaceExplicitTypeWithVariableIntention
\
+- Fixed (#761): EqualsAndHashCode: Wrong warning 'A method with one of those names already exists'
\
+- Fixed (#826): Error if using @FieldNameConstants in switch case
\
+- Fixed (#858): Delombok produces duplicate @NonNull annotations on setters/getters
\
+- Fixed (#933): Enable annotation processing warning showing everytime project is opened
\
\
If you find my plugin helpful, donate me using
\
PayPal\
diff --git a/src/test/java/de/plushnikov/RequiredApiVersion.java b/src/test/java/de/plushnikov/RequiredApiVersion.java
index 9e3a85e21..361b4cf99 100644
--- a/src/test/java/de/plushnikov/RequiredApiVersion.java
+++ b/src/test/java/de/plushnikov/RequiredApiVersion.java
@@ -1,10 +1,6 @@
package de.plushnikov;
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
+import java.lang.annotation.*;
/**
* Defines that a test class may only run if the current API version is at least the given value.
diff --git a/src/test/java/de/plushnikov/intellij/plugin/action/delombok/DelombokDataActionTest.java b/src/test/java/de/plushnikov/intellij/plugin/action/delombok/DelombokDataActionTest.java
index 59ed36471..139c71bf3 100644
--- a/src/test/java/de/plushnikov/intellij/plugin/action/delombok/DelombokDataActionTest.java
+++ b/src/test/java/de/plushnikov/intellij/plugin/action/delombok/DelombokDataActionTest.java
@@ -18,4 +18,7 @@ public void testDataSimple() throws Exception {
doTest();
}
+ public void testDataWithAnnotations() throws Exception {
+ doTest();
+ }
}
diff --git a/src/test/java/de/plushnikov/intellij/plugin/processor/EqualsAndHashCodeTest.java b/src/test/java/de/plushnikov/intellij/plugin/processor/EqualsAndHashCodeTest.java
index f9dcddf97..bfe23cc2e 100644
--- a/src/test/java/de/plushnikov/intellij/plugin/processor/EqualsAndHashCodeTest.java
+++ b/src/test/java/de/plushnikov/intellij/plugin/processor/EqualsAndHashCodeTest.java
@@ -59,4 +59,7 @@ public class EqualsAndHashCodeTest extends AbstractLombokParsingTestCase {
doTest(true);
}
+ public void testEqualsandhashcode$EqualsAndHashCodeWithNamedExistingMethods() {
+ doTest(true);
+ }
}
diff --git a/src/test/java/de/plushnikov/intellij/plugin/processor/ToStringTest.java b/src/test/java/de/plushnikov/intellij/plugin/processor/ToStringTest.java
index 671f95c2b..808a80ade 100644
--- a/src/test/java/de/plushnikov/intellij/plugin/processor/ToStringTest.java
+++ b/src/test/java/de/plushnikov/intellij/plugin/processor/ToStringTest.java
@@ -38,4 +38,8 @@ public class ToStringTest extends AbstractLombokParsingTestCase {
public void testTostring$ToStringSimpleClassName() {
doTest(true);
}
+
+ public void testTostring$ToStringWithNamedExistingMethods() {
+ doTest(true);
+ }
}
diff --git a/test-manual/src/main/java/de/plushnikov/val/Issue802.java b/test-manual/src/main/java/de/plushnikov/val/Issue802.java
new file mode 100644
index 000000000..7f6e928ea
--- /dev/null
+++ b/test-manual/src/main/java/de/plushnikov/val/Issue802.java
@@ -0,0 +1,13 @@
+package de.plushnikov.val;
+
+import lombok.val;
+import java.util.Optional;
+public class Issue802 {
+ public static void main(String... args) {
+ val strOpt = Optional.of("1");
+ val intOptInferredLambda = strOpt.map(str -> Integer.valueOf(str));
+ val intOptInferredMethodRef = strOpt.map(Integer::valueOf);
+ Optional intOptExplicit = intOptInferredMethodRef;
+ intOptExplicit = intOptInferredLambda;
+ }
+}
diff --git a/testData/action/delombok/data/afterDataWithAnnotations.java b/testData/action/delombok/data/afterDataWithAnnotations.java
new file mode 100644
index 000000000..1dbdbb148
--- /dev/null
+++ b/testData/action/delombok/data/afterDataWithAnnotations.java
@@ -0,0 +1,50 @@
+import lombok.NonNull;
+
+public class DataWithAnnotations {
+ @NonNull
+ @Deprecated
+ @SuppressWarnings("any")
+ private Integer someParentInteger;
+
+ public DataWithAnnotations(@NonNull Integer someParentInteger) {
+ this.someParentInteger = someParentInteger;
+ }
+
+ @Deprecated
+ public @NonNull Integer getSomeParentInteger() {
+ return this.someParentInteger;
+ }
+
+ @Deprecated
+ public void setSomeParentInteger(@NonNull Integer someParentInteger) {
+ this.someParentInteger = someParentInteger;
+ }
+
+ public boolean equals(final Object o) {
+ if (o == this) return true;
+ if (!(o instanceof DataWithAnnotations)) return false;
+ final DataWithAnnotations other = (DataWithAnnotations) o;
+ if (!other.canEqual((Object) this)) return false;
+ final Object this$someParentInteger = this.getSomeParentInteger();
+ final Object other$someParentInteger = other.getSomeParentInteger();
+ if (this$someParentInteger == null ? other$someParentInteger != null : !this$someParentInteger.equals(other$someParentInteger))
+ return false;
+ return true;
+ }
+
+ protected boolean canEqual(final Object other) {
+ return other instanceof DataWithAnnotations;
+ }
+
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final Object $someParentInteger = this.getSomeParentInteger();
+ result = result * PRIME + ($someParentInteger == null ? 43 : $someParentInteger.hashCode());
+ return result;
+ }
+
+ public String toString() {
+ return "DataWithAnnotations(someParentInteger=" + this.getSomeParentInteger() + ")";
+ }
+}
diff --git a/testData/action/delombok/data/beforeDataWithAnnotations.java b/testData/action/delombok/data/beforeDataWithAnnotations.java
new file mode 100644
index 000000000..c3b17eb28
--- /dev/null
+++ b/testData/action/delombok/data/beforeDataWithAnnotations.java
@@ -0,0 +1,11 @@
+import lombok.Data;
+import lombok.NonNull;
+
+@Data
+public class DataWithAnnotations {
+
+ @NonNull
+ @Deprecated
+ @SuppressWarnings("any")
+ private Integer someParentInteger;
+}
diff --git a/testData/after/equalsandhashcode/EqualsAndHashCodeWithNamedExistingMethods.java b/testData/after/equalsandhashcode/EqualsAndHashCodeWithNamedExistingMethods.java
new file mode 100644
index 000000000..dd30756bf
--- /dev/null
+++ b/testData/after/equalsandhashcode/EqualsAndHashCodeWithNamedExistingMethods.java
@@ -0,0 +1,40 @@
+import java.util.Objects;
+
+public class EqualsAndHashCodeWithNamedExistingMethods {
+ private int someInt;
+ private Integer someInteger;
+
+ public boolean equals(Object o, Object o2) {
+ return o.equals(o2);
+ }
+
+ public int hashCode(Float someFloat) {
+ return Objects.hash(someFloat);
+ }
+
+ public boolean equals(final Object o) {
+ if (o == this) return true;
+ if (!(o instanceof EqualsAndHashCodeWithNamedExistingMethods)) return false;
+ final EqualsAndHashCodeWithNamedExistingMethods other = (EqualsAndHashCodeWithNamedExistingMethods) o;
+ if (!other.canEqual((Object) this)) return false;
+ if (this.someInt != other.someInt) return false;
+ final Object this$someInteger = this.someInteger;
+ final Object other$someInteger = other.someInteger;
+ if (this$someInteger == null ? other$someInteger != null : !this$someInteger.equals(other$someInteger))
+ return false;
+ return true;
+ }
+
+ protected boolean canEqual(final Object other) {
+ return other instanceof EqualsAndHashCodeWithNamedExistingMethods;
+ }
+
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ result = result * PRIME + this.someInt;
+ final Object $someInteger = this.someInteger;
+ result = result * PRIME + ($someInteger == null ? 43 : $someInteger.hashCode());
+ return result;
+ }
+}
diff --git a/testData/after/tostring/ToStringWithNamedExistingMethods.java b/testData/after/tostring/ToStringWithNamedExistingMethods.java
new file mode 100644
index 000000000..cb26269b8
--- /dev/null
+++ b/testData/after/tostring/ToStringWithNamedExistingMethods.java
@@ -0,0 +1,11 @@
+public class ToStringWithNamedExistingMethods {
+ private int someInt;
+
+ public String toString(String string) {
+ return string;
+ }
+
+ public String toString() {
+ return "ToStringWithNamedExistingMethods(someInt=" + this.someInt + ")";
+ }
+}
diff --git a/testData/before/equalsandhashcode/EqualsAndHashCodeWithNamedExistingMethods.java b/testData/before/equalsandhashcode/EqualsAndHashCodeWithNamedExistingMethods.java
new file mode 100644
index 000000000..a08067c33
--- /dev/null
+++ b/testData/before/equalsandhashcode/EqualsAndHashCodeWithNamedExistingMethods.java
@@ -0,0 +1,18 @@
+import lombok.EqualsAndHashCode;
+
+import java.util.Objects;
+
+@EqualsAndHashCode
+public class EqualsAndHashCodeWithNamedExistingMethods {
+
+ private int someInt;
+ private Integer someInteger;
+
+ public boolean equals(Object o, Object o2) {
+ return o.equals(o2);
+ }
+
+ public int hashCode(Float someFloat) {
+ return Objects.hash(someFloat);
+ }
+}
diff --git a/testData/before/tostring/ToStringWithNamedExistingMethods.java b/testData/before/tostring/ToStringWithNamedExistingMethods.java
new file mode 100644
index 000000000..325c72b0e
--- /dev/null
+++ b/testData/before/tostring/ToStringWithNamedExistingMethods.java
@@ -0,0 +1,11 @@
+import lombok.ToString;
+
+@ToString
+public class ToStringWithNamedExistingMethods {
+
+ private int someInt;
+
+ public String toString(String string) {
+ return string;
+ }
+}