aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java61
-rw-r--r--src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java5
-rw-r--r--src/core/lombok/javac/apt/LombokFileObjects.java7
-rw-r--r--src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java21
-rw-r--r--src/installer/lombok/installer/eclipse/STS4LocationProvider.java44
5 files changed, 105 insertions, 33 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
index 0d0f51db..75339f7c 100644
--- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
@@ -475,47 +475,62 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
public TypeReference createTypeReference(EclipseNode type, long p, ASTNode source, boolean addWildcards) {
int pS = source.sourceStart; int pE = source.sourceEnd;
List<String> list = new ArrayList<String>();
+ List<Integer> genericsCount = addWildcards ? new ArrayList<Integer>() : null;
+
list.add(type.getName());
+ if (addWildcards) genericsCount.add(arraySizeOf(((TypeDeclaration) type.get()).typeParameters));
+ boolean staticContext = (((TypeDeclaration) type.get()).modifiers & Modifier.STATIC) != 0;
EclipseNode tNode = type.up();
+
while (tNode != null && tNode.getKind() == Kind.TYPE) {
list.add(tNode.getName());
+ if (addWildcards) genericsCount.add(staticContext ? 0 : arraySizeOf(((TypeDeclaration) tNode.get()).typeParameters));
+ if (!staticContext) staticContext = (((TypeDeclaration) tNode.get()).modifiers & Modifier.STATIC) != 0;
tNode = tNode.up();
}
Collections.reverse(list);
-
- TypeDeclaration typeDecl = (TypeDeclaration) type.get();
- int typeParamCount = typeDecl.typeParameters == null ? 0 : typeDecl.typeParameters.length;
- if (typeParamCount == 0) addWildcards = false;
- TypeReference[] typeArgs = null;
- if (addWildcards) {
- typeArgs = new TypeReference[typeParamCount];
- for (int i = 0; i < typeParamCount; i++) {
- typeArgs[i] = new Wildcard(Wildcard.UNBOUND);
- typeArgs[i].sourceStart = pS; typeArgs[i].sourceEnd = pE;
- setGeneratedBy(typeArgs[i], source);
- }
- }
+ if (addWildcards) Collections.reverse(genericsCount);
if (list.size() == 1) {
- if (addWildcards) {
- return new ParameterizedSingleTypeReference(list.get(0).toCharArray(), typeArgs, 0, p);
- } else {
+ if (!addWildcards || genericsCount.get(0) == 0) {
return new SingleTypeReference(list.get(0).toCharArray(), p);
+ } else {
+ return new ParameterizedSingleTypeReference(list.get(0).toCharArray(), wildcardify(pS, pE, source, genericsCount.get(0)), 0, p);
}
}
+
+ if (addWildcards) {
+ addWildcards = false;
+ for (int i : genericsCount) if (i > 0) addWildcards = true;
+ }
+
long[] ps = new long[list.size()];
char[][] tokens = new char[list.size()][];
for (int i = 0; i < list.size(); i++) {
ps[i] = p;
tokens[i] = list.get(i).toCharArray();
}
- if (addWildcards) {
- TypeReference[][] typeArgs2 = new TypeReference[tokens.length][];
- typeArgs2[typeArgs2.length - 1] = typeArgs;
- return new ParameterizedQualifiedTypeReference(tokens, typeArgs2, 0, ps);
- } else {
- return new QualifiedTypeReference(tokens, ps);
+
+ if (!addWildcards) return new QualifiedTypeReference(tokens, ps);
+ TypeReference[][] typeArgs2 = new TypeReference[tokens.length][];
+ for (int i = 0; i < tokens.length; i++) typeArgs2[i] = wildcardify(pS, pE, source, genericsCount.get(i));
+ return new ParameterizedQualifiedTypeReference(tokens, typeArgs2, 0, ps);
+ }
+
+ private TypeReference[] wildcardify(int pS, int pE, ASTNode source, int count) {
+ if (count == 0) return null;
+ TypeReference[] typeArgs = new TypeReference[count];
+ for (int i = 0; i < count; i++) {
+ typeArgs[i] = new Wildcard(Wildcard.UNBOUND);
+ typeArgs[i].sourceStart = pS; typeArgs[i].sourceEnd = pE;
+ setGeneratedBy(typeArgs[i], source);
}
+
+ return typeArgs;
+ }
+
+ private int arraySizeOf(Object[] arr) {
+ return arr == null ? 0 : arr.length;
}
public MethodDeclaration createEquals(EclipseNode type, Collection<EclipseNode> fields, boolean callSuper, ASTNode source, FieldAccess fieldAccess, boolean needsCanEqual, List<Annotation> onParam) {
@@ -683,7 +698,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
} else /* objects */ {
/* final java.lang.Object this$fieldName = this.fieldName; */
/* final java.lang.Object other$fieldName = other.fieldName; */
- /* if (this$fieldName == null ? other$fieldName != null : !this$fieldName.equals(other$fieldName)) return false;; */
+ /* if (this$fieldName == null ? other$fieldName != null : !this$fieldName.equals(other$fieldName)) return false; */
char[] thisDollarFieldName = ("this$" + field.getName()).toCharArray();
char[] otherDollarFieldName = ("other$" + field.getName()).toCharArray();
diff --git a/src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java b/src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java
index b42761f4..89964914 100644
--- a/src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java
+++ b/src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java
@@ -369,11 +369,6 @@ public final class SetGeneratedByVisitor extends ASTVisitor {
return super.visit(node, scope);
}
- @Override public boolean visit(ArrayInitializer node, ClassScope scope) {
- fixPositions(setGeneratedBy(node, source));
- return super.visit(node, scope);
- }
-
@Override public boolean visit(ArrayQualifiedTypeReference node, BlockScope scope) {
fixPositions(setGeneratedBy(node, source));
return super.visit(node, scope);
diff --git a/src/core/lombok/javac/apt/LombokFileObjects.java b/src/core/lombok/javac/apt/LombokFileObjects.java
index 7184629f..aba10540 100644
--- a/src/core/lombok/javac/apt/LombokFileObjects.java
+++ b/src/core/lombok/javac/apt/LombokFileObjects.java
@@ -106,7 +106,8 @@ final class LombokFileObjects {
"com.google.devtools.build.buildjar.javac.BlazeJavacMain$ClassloaderMaskingFileManager",
"com.google.devtools.build.java.turbine.javac.JavacTurbineCompiler$ClassloaderMaskingFileManager",
"org.netbeans.modules.java.source.parsing.ProxyFileManager",
- "com.sun.tools.javac.api.ClientCodeWrapper$WrappedStandardJavaFileManager"
+ "com.sun.tools.javac.api.ClientCodeWrapper$WrappedStandardJavaFileManager",
+ "com.sun.tools.javac.main.DelegatingJavaFileManager$DelegatingSJFM" // IntelliJ + JDK10
);
static Compiler getCompiler(JavaFileManager jfm) {
@@ -130,6 +131,10 @@ final class LombokFileObjects {
catch (Throwable e) {}
}
try {
+ if (Class.forName("com.sun.tools.javac.file.PathFileObject") == null) throw new NullPointerException();
+ return new Java9Compiler(jfm);
+ } catch (Throwable e) {}
+ try {
if (Class.forName("com.sun.tools.javac.file.BaseFileObject") == null) throw new NullPointerException();
return Compiler.JAVAC7;
} catch (Throwable e) {}
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
index da2db909..d8bfd154 100644
--- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
@@ -371,31 +371,44 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
public JCExpression createTypeReference(JavacNode type, boolean addWildcards) {
java.util.List<String> list = new ArrayList<String>();
+ java.util.List<Integer> genericsCount = addWildcards ? new ArrayList<Integer>() : null;
+
list.add(type.getName());
+ if (addWildcards) genericsCount.add(((JCClassDecl) type.get()).typarams.size());
+ boolean staticContext = (((JCClassDecl) type.get()).getModifiers().flags & Flags.STATIC) != 0;
JavacNode tNode = type.up();
+
while (tNode != null && tNode.getKind() == Kind.TYPE) {
list.add(tNode.getName());
+ if (addWildcards) genericsCount.add(staticContext ? 0 : ((JCClassDecl) tNode.get()).typarams.size());
+ if (!staticContext) staticContext = (((JCClassDecl) tNode.get()).getModifiers().flags & Flags.STATIC) != 0;
tNode = tNode.up();
}
Collections.reverse(list);
- JCClassDecl typeDecl = (JCClassDecl) type.get();
+ if (addWildcards) Collections.reverse(genericsCount);
JavacTreeMaker maker = type.getTreeMaker();
JCExpression chain = maker.Ident(type.toName(list.get(0)));
+ if (addWildcards) chain = wildcardify(maker, chain, genericsCount.get(0));
for (int i = 1; i < list.size(); i++) {
chain = maker.Select(chain, type.toName(list.get(i)));
+ if (addWildcards) chain = wildcardify(maker, chain, genericsCount.get(i));
}
- if (!addWildcards || typeDecl.typarams.length() == 0) return chain;
+ return chain;
+ }
+
+ private JCExpression wildcardify(JavacTreeMaker maker, JCExpression expr, int count) {
+ if (count == 0) return expr;
ListBuffer<JCExpression> wildcards = new ListBuffer<JCExpression>();
- for (int i = 0 ; i < typeDecl.typarams.length() ; i++) {
+ for (int i = 0 ; i < count ; i++) {
wildcards.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null));
}
- return maker.TypeApply(chain, wildcards.toList());
+ return maker.TypeApply(expr, wildcards.toList());
}
public JCMethodDecl createEquals(JavacNode typeNode, List<JavacNode> fields, boolean callSuper, FieldAccess fieldAccess, boolean needsCanEqual, JCTree source, List<JCAnnotation> onParam) {
diff --git a/src/installer/lombok/installer/eclipse/STS4LocationProvider.java b/src/installer/lombok/installer/eclipse/STS4LocationProvider.java
new file mode 100644
index 00000000..47a07bdd
--- /dev/null
+++ b/src/installer/lombok/installer/eclipse/STS4LocationProvider.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2018 The Project Lombok Authors.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package lombok.installer.eclipse;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import lombok.installer.IdeLocationProvider;
+
+import org.mangosdk.spi.ProviderFor;
+
+@ProviderFor(IdeLocationProvider.class)
+public class STS4LocationProvider extends EclipseProductLocationProvider {
+
+ private static final EclipseProductDescriptor STS4 = new StandardProductDescriptor("Spring Tools Suite 4",
+ "SpringToolSuite4",
+ "sts",
+ STS4LocationProvider.class.getResource("STS.png"),
+ Collections.unmodifiableList(Arrays.asList("springsource", "spring-tool-suite"))
+ );
+
+ public STS4LocationProvider() {
+ super(STS4);
+ }
+}