Skip to content

Commit

Permalink
Merge branch 'backport_intellij_2019.2' into backport_intellij_2019.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
  • Loading branch information
mplushnikov committed Sep 24, 2020
2 parents 52f479a + d9384af commit 384d43a
Show file tree
Hide file tree
Showing 30 changed files with 313 additions and 152 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ideaVersion=2018.1
#
pluginGroup=de.plushnikov.intellij.plugin
pluginName=lombok-plugin
pluginVersion=0.31
pluginVersion=0.32
#
javaVersion=1.8
sources=true
Expand Down
8 changes: 8 additions & 0 deletions parts/pluginChanges.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<ul>
<li>0.32
<ol>
<li>Fixed #761: EqualsAndHashCode: Wrong warning 'A method with one of those names already exists'</li>
<li>Fixed #826: Error if using @FieldNameConstants in switch case</li>
<li>Fixed #858: Delombok produces duplicate @NonNull annotations on setters/getters</li>
<li>Fixed #933: Enable annotation processing warning showing everytime project is opened</li>
</ol>
</li>
<li>0.31
<ol>
<li>Fixed #923: ArrayIndexOutOfBoundsException in ReplaceExplicitTypeWithVariableIntention</li>
Expand Down
14 changes: 13 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
rootProject.name = 'lombok-plugin'
pluginManagement {
repositories {
maven {
url 'https://jetbrains.bintray.com/intellij-plugin-service'
}
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
}
}

rootProject.name = 'lombok-plugin'
2 changes: 1 addition & 1 deletion src/main/java/de/plushnikov/intellij/plugin/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
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;

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\\[\\]'");

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PsiMethod> 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) {
Expand All @@ -145,7 +144,7 @@ protected Collection<PsiMethod> createEqualAndHashCode(@NotNull PsiClass psiClas
result.add(createEqualsMethod(psiClass, psiAnnotation, shouldGenerateCanEqual, memberInfos));

final Collection<PsiMethod> 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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<PsiMethod> 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<PsiMethod> 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) {
Expand All @@ -93,8 +92,7 @@ protected void generatePsiElements(@NotNull PsiClass psiClass, @NotNull PsiAnnot

@NotNull
Collection<PsiMethod> createToStringMethod(@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation) {
final Collection<PsiMethod> classMethods = PsiClassUtil.collectClassMethodsIntern(psiClass);
if (PsiMethodUtil.hasMethodByName(classMethods, METHOD_NAME)) {
if (hasToStringMethodDefined(psiClass)) {
return Collections.emptyList();
}

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 384d43a

Please sign in to comment.