Skip to content

Commit

Permalink
[fixes #2169] Eclipse 2019-06 + JDK12 + @Singular caused a cavalcad…
Browse files Browse the repository at this point in the history
…e of error popups
  • Loading branch information
rzwitserloot committed Jul 15, 2019
1 parent 206e306 commit b3824c9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions doc/changelog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Lombok Changelog
* ENHANCEMENT: If you mix up eclipse's non-null support, such as `@NonNullByDefault`, with lombok's `@NonNull`, you get a bunch of warnings about dead code that are inappropriate. These warnings are now suppressed, thanks to a contribution from Till Brychcy! [Pull Request #2155](https://github.com/rzwitserloot/lombok/pull/2155)
* BUGFIX: Delombok would turn something like `List<byte[]>...` in a method parameter to `List<byte...>...` [Issue #2140](https://github.com/rzwitserloot/lombok/issues/2140)
* BUGFIX: Javac would generate the wrong equals and hashCode if a type-use annotation was put on an array type field [Issue #2165](https://github.com/rzwitserloot/lombok/issues/2165)
* BUGFIX: Eclipse 2019-06 + JDK-12 compatibility + an `@Singular` builder entry would produce a cascade of error dialogs. [Issue #2169](https://github.com/rzwitserloot/lombok/issues/2169)
* IMPROBABLE BREAKING CHANGE: Stricter validation of configuration keys dealing with identifiers and types (`lombok.log.fieldName`, `lombok.fieldNameConstants.innerTypeName`, `lombok.copyableAnnotations`).
>>>>>>> customlog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
import org.eclipse.jdt.internal.compiler.ast.Assignment;
import org.eclipse.jdt.internal.compiler.ast.BreakStatement;
import org.eclipse.jdt.internal.compiler.ast.CaseStatement;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.FieldReference;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
Expand Down Expand Up @@ -74,7 +73,7 @@ public class EclipseJavaUtilListSingularizer extends EclipseJavaUtilListSetSingu
List<Statement> switchContents = new ArrayList<Statement>();

/* case 0: (empty) break; */ {
switchContents.add(new CaseStatement(makeIntLiteral(new char[] {'0'}, null), 0, 0));
switchContents.add(Eclipse.createCaseStatement(makeIntLiteral(new char[] {'0'}, null)));
MessageSend invoke = new MessageSend();
invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0);
invoke.selector = "emptyList".toCharArray();
Expand All @@ -83,7 +82,7 @@ public class EclipseJavaUtilListSingularizer extends EclipseJavaUtilListSetSingu
}

/* case 1: (singleton) break; */ {
switchContents.add(new CaseStatement(makeIntLiteral(new char[] {'1'}, null), 0, 0));
switchContents.add(Eclipse.createCaseStatement(makeIntLiteral(new char[] {'1'}, null)));
FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
thisDotField.receiver = getBuilderReference(builderVariable);
MessageSend thisDotFieldGet0 = new MessageSend();
Expand All @@ -101,7 +100,7 @@ public class EclipseJavaUtilListSingularizer extends EclipseJavaUtilListSetSingu
}

/* default: Create by passing builder field to constructor. */ {
switchContents.add(new CaseStatement(null, 0, 0));
switchContents.add(Eclipse.createCaseStatement(null));

Expression argToUnmodifiable;
/* new j.u.ArrayList<Generics>(this.pluralName); */ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.eclipse.jdt.internal.compiler.ast.BinaryExpression;
import org.eclipse.jdt.internal.compiler.ast.Block;
import org.eclipse.jdt.internal.compiler.ast.BreakStatement;
import org.eclipse.jdt.internal.compiler.ast.CaseStatement;
import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression;
import org.eclipse.jdt.internal.compiler.ast.EqualExpression;
import org.eclipse.jdt.internal.compiler.ast.Expression;
Expand All @@ -58,6 +57,7 @@
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;

import lombok.ConfigurationKeys;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseNode;
import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer;
import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData;
Expand Down Expand Up @@ -95,7 +95,7 @@ protected List<Statement> createJavaUtilSetMapInitialCapacitySwitchStatements(Si
char[] keyName = mapMode ? (new String(data.getPluralName()) + "$key").toCharArray() : data.getPluralName();

if (emptyCollectionMethod != null) { // case 0: (empty); break;
switchContents.add(new CaseStatement(makeIntLiteral(new char[] {'0'}, null), 0, 0));
switchContents.add(Eclipse.createCaseStatement(makeIntLiteral(new char[] {'0'}, null)));

/* pluralName = java.util.Collections.emptyCollectionMethod(); */ {
MessageSend invoke = new MessageSend();
Expand All @@ -108,7 +108,7 @@ protected List<Statement> createJavaUtilSetMapInitialCapacitySwitchStatements(Si
}

if (singletonCollectionMethod != null) { // case 1: (singleton); break;
switchContents.add(new CaseStatement(makeIntLiteral(new char[] {'1'}, null), 0, 0));
switchContents.add(Eclipse.createCaseStatement(makeIntLiteral(new char[] {'1'}, null)));
/* !mapMode: pluralName = java.util.Collections.singletonCollectionMethod(this.pluralName.get(0));
mapMode: pluralName = java.util.Collections.singletonCollectionMethod(this.pluralName$key.get(0), this.pluralName$value.get(0)); */ {
FieldReference thisDotKey = new FieldReference(keyName, 0L);
Expand Down Expand Up @@ -142,7 +142,7 @@ protected List<Statement> createJavaUtilSetMapInitialCapacitySwitchStatements(Si
}

{ // default:
switchContents.add(new CaseStatement(null, 0, 0));
switchContents.add(Eclipse.createCaseStatement(null));
switchContents.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, mapMode, false, true, emptyCollectionMethod == null, targetType, builderVariable));
}

Expand Down
24 changes: 23 additions & 1 deletion src/utils/lombok/eclipse/Eclipse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2013 The Project Lombok Authors.
* Copyright (C) 2009-2019 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
Expand Down Expand Up @@ -29,10 +29,13 @@

import lombok.core.ClassLiteral;
import lombok.core.FieldSelect;
import lombok.permit.Permit;

import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.CaseStatement;
import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess;
import org.eclipse.jdt.internal.compiler.ast.Clinit;
import org.eclipse.jdt.internal.compiler.ast.Expression;
Expand Down Expand Up @@ -262,4 +265,23 @@ private static boolean ecjSupportsJava7Features() {
return false;
}
}

private static boolean caseStatementInit = false;
private static Field caseStatementConstantExpressions = null;
public static CaseStatement createCaseStatement(Expression expr) {
CaseStatement stat = new CaseStatement(expr, 0, 0);
if (expr == null) return stat;
if (!caseStatementInit) {
try {
caseStatementConstantExpressions = Permit.getField(CaseStatement.class, "constantExpressions");
caseStatementConstantExpressions.setAccessible(true);
} catch (NoSuchFieldException ignore) {}
caseStatementInit = true;
}
if (caseStatementConstantExpressions != null) try {
caseStatementConstantExpressions.set(stat, new Expression[] {expr});
} catch (IllegalArgumentException ignore) {
} catch (IllegalAccessException ignore) {}
return stat;
}
}

0 comments on commit b3824c9

Please sign in to comment.