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

Commit

Permalink
Merge branch 'backport_intellij_2017.2' into backport_intellij_2017.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mplushnikov committed Oct 3, 2019
2 parents 7010da1 + 6643537 commit cbd85af
Show file tree
Hide file tree
Showing 237 changed files with 5,175 additions and 2,195 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ 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.25) released on 01.05.2019**
**Last version (0.27) released on 03.10.2019**

Thirty version of plugin released. Contains a lot of bugfixes and some new features!
32nd version of plugin released. Contains a lot of bugfixes and long awaiting feature @SuperBuilder!

Install it automatically from IntelliJ Idea plugin repository.

Tested and supports IntelliJ versions: 2016.2, 2016.3, 2017.X, 2018.X, 2019.1
Tested and supports IntelliJ versions: 2016.2, 2016.3, 2017.X, 2018.X, 2019.1 and 2019.2

Last support for IntelliJ 15.0.6 and 2016.1 by plugin version 0.19!

Expand Down Expand Up @@ -56,8 +56,6 @@ Features / Supports

Many features of the plugin (including warnings) could be disabled through per-project settings.

__Note:__ To make use of plugin features like `@UtilityClass` and for _better_ `val` and `Value` support while using IntelliJ 14.1 - 2016.1, you need to enable "Runtime patching" in Plugin settings. This is __not__ needed with 2016.2 and higher.

Installation
------------
### Plugin Installation
Expand Down Expand Up @@ -87,7 +85,7 @@ In your `build.gradle`:
```groovy
// 'compile' can be changed to 'compileOnly' for Gradle 2.12+
// or 'provided' if using 'propdeps' plugin from SpringSource
compile "org.projectlombok:lombok:1.18.8"
compile "org.projectlombok:lombok:1.18.10"
```

##### Maven
Expand All @@ -97,7 +95,7 @@ In your `pom.xml`:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -106,7 +104,7 @@ In your `pom.xml`:
##### Ivy
In your `ivy.xml`:
```xml
<dependency org="org.projectlombok" name="lombok" rev="1.18.8" conf="build" />
<dependency org="org.projectlombok" name="lombok" rev="1.18.10" conf="build" />
```

IntelliJ and Eclipse compiler
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ dependencies {
lombok group: 'org.projectlombok', name: 'lombok', version: '1.18.10', classifier: 'sources', ext: 'jar'

testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '3.0.0'
testCompile group: 'org.mockito', name: 'mockito-core', version: '3.1.0'
}

// Tasks
Expand Down
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
ideaVersion=2017.1
#ideaVersion=2017.1.5
#
lastReleaseVersion=2019.1
#
pluginGroup=de.plushnikov.intellij.plugin
pluginName=lombok-plugin
pluginVersion=0.27
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions parts/pluginChanges.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<li>Fixed #526: StackOverflow with LombokLightParameterListBuilder.equals</li>
<li>Fixed #660: Performance problems in autocomplete/code analysis</li>
<li>Fixed #663: Method with varArgs gives an error in IntelliJ</li>
<li>Fixed #670: Non-idempotent computation issue with @Delegate usages</li>
<li>Fixed #673: Add support for @With</li>
</ol>
</li>
Expand Down
8 changes: 4 additions & 4 deletions parts/pluginDescription.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ <h1>IntelliJ Lombok plugin</h1>
<li><a href="https://projectlombok.org/features/experimental/Wither.html">@Wither</a></li>
<li><a href="https://projectlombok.org/features/With.html">@With</a></li>
<li><a href="https://projectlombok.org/features/SneakyThrows.html">@SneakyThrows</a></li>
<li><a href="https://projectlombok.org/features/val.html">from Intellij 14.1 @val</a></li>
<li><a href="https://projectlombok.org/features/var.html">from Intellij 15.0.2 @var</a></li>
<li><a href="https://projectlombok.org/features/experimental/var.html">from Intellij 14.1 @var</a></li>
<li><a href="https://projectlombok.org/features/experimental/UtilityClass.html">from Intellij 2016.2 @UtilityClass</a></li>
<li><a href="https://projectlombok.org/features/val.html">@val</a></li>
<li><a href="https://projectlombok.org/features/var.html">@var</a></li>
<li><a href="https://projectlombok.org/features/experimental/var.html">experimental @var</a></li>
<li><a href="https://projectlombok.org/features/experimental/UtilityClass.html">@UtilityClass</a></li>
<li><a href="https://projectlombok.org/features/configuration.html">Lombok config system</a></li>
<li>Code inspections</li>
<li>Refactoring actions (lombok and delombok)</li>
Expand Down
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 @@ -9,5 +9,5 @@ public interface Version {
/**
* Current version of lombok plugin
*/
String LAST_LOMBOK_VERSION = "1.18.8";
String LAST_LOMBOK_VERSION = "1.18.10";
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.intellij.codeInsight.generation.GenerationInfo;
import com.intellij.codeInsight.generation.PsiFieldMember;
import com.intellij.codeInsight.generation.PsiGenerationInfo;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiModifier;
Expand All @@ -27,7 +26,7 @@ public class LombokGenerateConstructorHandler extends GenerateConstructorHandler
protected ClassMember[] getAllOriginalMembers(PsiClass aClass) {
PsiField[] fields = aClass.getFields();
ArrayList<ClassMember> array = new ArrayList<>();
ImplicitUsageProvider[] implicitUsageProviders = Extensions.getExtensions(ImplicitUsageProvider.EP_NAME);
ImplicitUsageProvider[] implicitUsageProviders = ImplicitUsageProvider.EP_NAME.getExtensions();
fieldLoop:
for (PsiField field : fields) {
if (field.hasModifierProperty(PsiModifier.STATIC)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public PsiFile createFile(FileViewProvider viewProvider) {
return new LombokConfigFile(viewProvider);
}

@Override
public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) {
return SpaceRequirements.MAY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.PsiType;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import de.plushnikov.intellij.plugin.problem.LombokProblem;
import de.plushnikov.intellij.plugin.problem.ProblemNewBuilder;
Expand Down Expand Up @@ -63,7 +62,7 @@ public Collection<LombokProblem> verifyAnnotation(@NotNull PsiAnnotation psiAnno
PsiQuickFixFactory.createModifierListFix(lockField, PsiModifier.FINAL, true, false));
}
} else {
final PsiClassType javaLangObjectType = PsiType.getJavaLangObject(containingClass.getManager(), GlobalSearchScope.allScope(containingClass.getProject()));
final PsiClassType javaLangObjectType = PsiType.getJavaLangObject(containingClass.getManager(), containingClass.getResolveScope());

problemNewBuilder.addError(String.format("The field %s does not exist.", lockFieldName),
PsiQuickFixFactory.createNewFieldFix(containingClass, lockFieldName, javaLangObjectType, "new Object()", PsiModifier.PRIVATE, PsiModifier.FINAL));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.RecursionManager;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.TypeConversionUtil;
import de.plushnikov.intellij.plugin.problem.LombokProblem;
import de.plushnikov.intellij.plugin.settings.ProjectSettings;
Expand Down Expand Up @@ -166,7 +165,7 @@ public PsiType inferType(PsiTypeElement typeElement) {
}

if (null == psiType) {
psiType = PsiType.getJavaLangObject(typeElement.getManager(), GlobalSearchScope.allScope(typeElement.getProject()));
psiType = PsiType.getJavaLangObject(typeElement.getManager(), typeElement.getResolveScope());
}
}
return psiType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTypesUtil;
import de.plushnikov.intellij.plugin.lombokconfig.ConfigKey;
import de.plushnikov.intellij.plugin.problem.ProblemBuilder;
Expand Down Expand Up @@ -172,7 +171,7 @@ private PsiMethod createEqualsMethod(@NotNull PsiClass psiClass, @NotNull PsiAnn
.withMethodReturnType(PsiType.BOOLEAN)
.withContainingClass(psiClass)
.withNavigationElement(psiAnnotation)
.withFinalParameter("o", PsiType.getJavaLangObject(psiManager, GlobalSearchScope.allScope(psiClass.getProject())));
.withFinalParameter("o", PsiType.getJavaLangObject(psiManager, psiClass.getResolveScope()));
methodBuilder.withBody(PsiMethodUtil.createCodeBlockFromText(blockText, methodBuilder));
return methodBuilder;
}
Expand Down Expand Up @@ -201,7 +200,7 @@ private PsiMethod createCanEqualMethod(@NotNull PsiClass psiClass, @NotNull PsiA
.withMethodReturnType(PsiType.BOOLEAN)
.withContainingClass(psiClass)
.withNavigationElement(psiAnnotation)
.withFinalParameter("other", PsiType.getJavaLangObject(psiManager, GlobalSearchScope.allScope(psiClass.getProject())));
.withFinalParameter("other", PsiType.getJavaLangObject(psiManager, psiClass.getResolveScope()));
methodBuilder.withBody(PsiMethodUtil.createCodeBlockFromText(blockText, methodBuilder));
return methodBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package de.plushnikov.intellij.plugin.processor.handler;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTypesUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
Expand All @@ -20,7 +18,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;

/**
Expand Down Expand Up @@ -95,16 +93,15 @@ private Collection<PsiType> collectExcludeTypes(PsiAnnotation psiAnnotation) {
}

public <T extends PsiMember & PsiNamedElement> void generateElements(@NotNull T psiElement, @NotNull PsiType psiElementType, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target) {
final Project project = psiElement.getProject();
final PsiManager manager = psiElement.getContainingFile().getManager();

final Collection<Pair<PsiMethod, PsiSubstitutor>> includesMethods = new HashSet<>();
final Collection<Pair<PsiMethod, PsiSubstitutor>> includesMethods = new LinkedHashSet<>();

final Collection<PsiType> types = collectDelegateTypes(psiAnnotation, psiElementType);
addMethodsOfTypes(types, includesMethods);

final Collection<Pair<PsiMethod, PsiSubstitutor>> excludeMethods = new HashSet<>();
PsiClassType javaLangObjectType = PsiType.getJavaLangObject(manager, GlobalSearchScope.allScope(project));
final Collection<Pair<PsiMethod, PsiSubstitutor>> excludeMethods = new LinkedHashSet<>();
PsiClassType javaLangObjectType = PsiType.getJavaLangObject(manager, psiElement.getResolveScope());
addMethodsOfType(javaLangObjectType, excludeMethods);

final Collection<PsiType> excludes = collectExcludeTypes(psiAnnotation);
Expand All @@ -121,7 +118,6 @@ public <T extends PsiMember & PsiNamedElement> void generateElements(@NotNull T
}
}


private void addMethodsOfTypes(Collection<PsiType> types, Collection<Pair<PsiMethod, PsiSubstitutor>> includesMethods) {
for (PsiType type : types) {
addMethodsOfType(type, includesMethods);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ private boolean shouldGenerateToBuilderMethods(@NotNull PsiAnnotation psiAnnotat
return PsiAnnotationUtil.getBooleanAnnotationValue(psiAnnotation, TO_BUILDER_ANNOTATION_KEY, false);
}

private String selectNonClashingNameFor(String classGenericName, Collection<String> typeParamStrings) {
String result = classGenericName;
if (typeParamStrings.contains(classGenericName)) {
int counter = 2;
do {
result = classGenericName + counter++;
} while (typeParamStrings.contains(result));
}
return result;
}

@NotNull
public PsiClass createBuilderBaseClass(@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation) {
String builderClassName = getBuilderClassName(psiClass);
Expand All @@ -170,11 +181,13 @@ public PsiClass createBuilderBaseClass(@NotNull PsiClass psiClass, @NotNull PsiA
.withModifier(PsiModifier.STATIC)
.withModifier(PsiModifier.ABSTRACT);

final LightTypeParameterBuilder c = new LightTypeParameterBuilder("C", baseClassBuilder, 0);
final List<String> typeParamNames = Stream.of(psiClass.getTypeParameters()).map(PsiTypeParameter::getName).collect(Collectors.toList());

final LightTypeParameterBuilder c = new LightTypeParameterBuilder(selectNonClashingNameFor("C", typeParamNames), baseClassBuilder, 0);
c.getExtendsList().addReference(PsiClassUtil.getTypeWithGenerics(psiClass));
baseClassBuilder.withParameterType(c);

final LightTypeParameterBuilder b = new LightTypeParameterBuilder("B", baseClassBuilder, 1);
final LightTypeParameterBuilder b = new LightTypeParameterBuilder(selectNonClashingNameFor("B", typeParamNames), baseClassBuilder, 1);
baseClassBuilder.withParameterType(b);
b.getExtendsList().addReference(PsiClassUtil.getTypeWithGenerics(baseClassBuilder));

Expand Down Expand Up @@ -237,6 +250,7 @@ public Collection<PsiMethod> createAllMethodsOfBaseBuilder(@NotNull PsiClass psi
bTypeClass = typeParameters[typeParameters.length - 1];
cTypeClass = typeParameters[typeParameters.length - 2];
} else {
//Fallback only
bTypeClass = new LightTypeParameterBuilder("B", psiBuilderClass, 1);
cTypeClass = new LightTypeParameterBuilder("C", psiBuilderClass, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ public String renderBuildCode(@NotNull PsiVariable psiVariable, @NotNull String
final String selectedFormat;
if (collectionQualifiedName.equals(SingularCollectionClassNames.JAVA_UTIL_SORTED_MAP)) {
selectedFormat = "java.util.SortedMap<{1}, {2}> {0} = new java.util.TreeMap<{1}, {2}>();\n" +
" if ({3}.{0}$key != null) for (int $i = 0; $i < ({3}.{0}$key == null ? 0 : {3}.{0}$key.size()); $i++) {0}.put({3}.{0}$key.get($i), {3}.{0}$value.get($i));\n" +
" if ({3}.{0}$key != null) for (int $i = 0; $i < ({3}.{0}$key == null ? 0 : {3}.{0}$key.size()); $i++) {0}.put({3}.{0}$key.get($i), ({2}){3}.{0}$value.get($i));\n" +
" {0} = java.util.Collections.unmodifiableSortedMap({0});\n";
} else if (collectionQualifiedName.equals(SingularCollectionClassNames.JAVA_UTIL_NAVIGABLE_MAP)) {
selectedFormat = "java.util.NavigableMap<{1}, {2}> {0} = new java.util.TreeMap<{1}, {2}>();\n" +
" if ({3}.{0}$key != null) for (int $i = 0; $i < ({3}.{0}$key == null ? 0 : {3}.{0}$key.size()); $i++) {0}.put({3}.{0}$key.get($i), {3}.{0}$value.get($i));\n" +
" if ({3}.{0}$key != null) for (int $i = 0; $i < ({3}.{0}$key == null ? 0 : {3}.{0}$key.size()); $i++) {0}.put({3}.{0}$key.get($i), ({2}){3}.{0}$value.get($i));\n" +
" {0} = java.util.Collections.unmodifiableNavigableMap({0});\n";
} else {
selectedFormat = "java.util.Map<{1}, {2}> {0};\n" +
Expand All @@ -158,7 +158,7 @@ public String renderBuildCode(@NotNull PsiVariable psiVariable, @NotNull String
" break;\n" +
" default:\n" +
" {0} = new java.util.LinkedHashMap<{1}, {2}>({3}.{0}$key.size() < 1073741824 ? 1 + {3}.{0}$key.size() + ({3}.{0}$key.size() - 3) / 3 : java.lang.Integer.MAX_VALUE);\n" +
" for (int $i = 0; $i < {3}.{0}$key.size(); $i++) {0}.put({3}.{0}$key.get($i), {3}.{0}$value.get($i));\n" +
" for (int $i = 0; $i < {3}.{0}$key.size(); $i++) {0}.put({3}.{0}$key.get($i), ({2}){3}.{0}$value.get($i));\n" +
" {0} = java.util.Collections.unmodifiableMap({0});\n" +
" '}'\n";
}
Expand All @@ -167,7 +167,9 @@ public String renderBuildCode(@NotNull PsiVariable psiVariable, @NotNull String
}

public String renderSuperBuilderConstruction(@NotNull PsiVariable psiVariable, @NotNull String fieldName) {
return renderBuildCode(psiVariable, fieldName, "b");
final String basicCode = renderBuildCode(psiVariable, fieldName, "b");
final String assignment = "this." + psiVariable.getName() + "=" + fieldName + ";\n";
return basicCode + assignment;
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/lombokBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Fixes:<br/>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/648">#648</a>): IDEA 2019.2 highlights builder() method invocation as an error<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/660">#660</a>): Performance problems in autocomplete/code analysis<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/663">#663</a>): Method with varArgs gives an error in IntelliJ<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/670">#670</a>): 'Non-idempotent computation' issue with @Delegate usages<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/673">#673</a>): Add support for @With<br>\
<br>\
If you find my plugin helpful, donate me using <br><b>\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
package de.plushnikov.intellij.plugin;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.LanguageLevelModuleExtension;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiFile;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import com.intellij.util.PathUtil;
import junit.framework.ComparisonFailure;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.regex.Pattern;

import static com.intellij.testFramework.LightPlatformTestCase.getModule;

public abstract class AbstractLombokLightCodeInsightTestCase extends LightCodeInsightFixtureTestCase {
private static final String LOMBOK_SRC_PATH = "./generated/src/lombok";

@Override
protected String getTestDataPath() {
Expand All @@ -40,37 +29,18 @@ protected String getBasePath() {
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return new DefaultLightProjectDescriptor() {
@Override
public Sdk getSdk() {
return JavaSdk.getInstance().createJdk("java 1.8", "lib/mockJDK-1.8", false);
}

@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_8);
}
};
return LombokTestUtil.getProjectDescriptor();
}

@Override
public void setUp() throws Exception {
VfsRootAccess.allowRootAccess(new File(getTestDataPath(), getBasePath()).getCanonicalPath(),
new File(LOMBOK_SRC_PATH).getCanonicalPath());

super.setUp();
loadLombokFilesFrom(LOMBOK_SRC_PATH);
}

protected void loadLombokFilesFrom(final String srcPath) {
List<File> filesByMask = FileUtil.findFilesByMask(Pattern.compile(".*\\.java"), new File(srcPath));
filesByMask.stream().map(File::getPath).filter(this::acceptLombokFile).map(PathUtil::toSystemIndependentName).forEach(
filePath -> myFixture.copyFileToProject(filePath, filePath.substring(srcPath.lastIndexOf("/") + 1))
);
loadLombokLibrary();
}

protected boolean acceptLombokFile(String javaFilePath) {
return true;
protected void loadLombokLibrary() {
LombokTestUtil.loadLombokLibrary(myFixture, getModule());
}

protected PsiFile loadToPsiFile(String fileName) {
Expand Down
Loading

0 comments on commit cbd85af

Please sign in to comment.