Skip to content

Commit

Permalink
[fixes projectlombok#2369] types nested in enums/interfaces not marke…
Browse files Browse the repository at this point in the history
…d static no longer cause issues in ecj.
  • Loading branch information
rzwitserloot authored and Febell committed Mar 1, 2020
1 parent c02e77a commit 7142194
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/changelog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Lombok Changelog
* FEATURE: Similar to `@Builder`, you can now configure a `@SuperBuilder`'s 'setter' prefixes via `@SuperBuilder(setterPrefix = "set")` for example. We still discourage doing this. [Pull Request #2357](https://github.com/rzwitserloot/lombok/pull/2357).
* FEATURE: If using `@Synchronized("lockVar")`, if `lockVar` is referring to a static field, the code lombok generates no longer causes a warning about accessing a static entity incorrectly. [Issue #678](https://github.com/rzwitserloot/lombok/issues/678)
* BUGFIX: Using `@SuperBuilder` on a class that has some fairly convoluted generics usage would fail with 'Wrong number of type arguments'. [Issue #2359](https://github.com/rzwitserloot/lombok/issues/2359) [Pull Request #2362](https://github.com/rzwitserloot/lombok/pull/2362)
* BUGFIX: Various lombok annotations on classes nested inside enums or interfaces would cause errors in eclipse. [Issue #2369](https://github.com/rzwitserloot/lombok/issues/2369)

### v1.18.12 (February 1st, 2020)
* PLATFORM: Support for JDK13 (including `yield` in switch expressions, as well as delombok having a nicer style for arrow-style switch blocks, and text blocks).
Expand Down
18 changes: 13 additions & 5 deletions src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public static void removeTypeUseAnnotations(TypeReference from) {

public static TypeReference namePlusTypeParamsToTypeReference(EclipseNode type, TypeParameter[] params, long p) {
TypeDeclaration td = (TypeDeclaration) type.get();
boolean instance = (td.modifiers & ClassFileConstants.AccStatic) == 0;
boolean instance = (td.modifiers & MODIFIERS_INDICATING_STATIC) == 0;
return namePlusTypeParamsToTypeReference(type.up(), td.name, instance, params, p);
}

Expand Down Expand Up @@ -891,7 +891,7 @@ public static TypeReference generateParameterizedTypeReference(EclipseNode type,
for (int i = 0; i < tnLen; i++) ps[i] = p;
TypeReference[][] rr = new TypeReference[tnLen][];
rr[tnLen - 1] = typeParams;
boolean instance = (td.modifiers & ClassFileConstants.AccStatic) == 0;
boolean instance = (td.modifiers & MODIFIERS_INDICATING_STATIC) == 0;
if (instance) fillOuterTypeParams(rr, tnLen - 2, type.up(), p);
return new ParameterizedQualifiedTypeReference(tn, rr, 0, ps);
}
Expand All @@ -908,6 +908,8 @@ public static TypeReference generateParameterizedTypeReference(EclipseNode paren
return new ParameterizedQualifiedTypeReference(tn, rr, 0, ps);
}

private static final int MODIFIERS_INDICATING_STATIC = ClassFileConstants.AccInterface | ClassFileConstants.AccStatic | ClassFileConstants.AccEnum;

/**
* This class will add type params to fully qualified chain of type references for inner types, such as {@code GrandParent.Parent.Child}; this is needed only as long as the chain does not involve static.
*
Expand All @@ -917,6 +919,10 @@ private static boolean fillOuterTypeParams(TypeReference[][] rr, int idx, Eclips
if (idx < 0 || node == null || !(node.get() instanceof TypeDeclaration)) return false;
boolean filled = false;
TypeDeclaration td = (TypeDeclaration) node.get();
if (0 != (td.modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccEnum))) {
// any class defs inside an enum or interface are static, even if not marked as such.
return false;
}
TypeParameter[] tps = td.typeParameters;
if (tps != null && tps.length > 0) {
TypeReference[] trs = new TypeReference[tps.length];
Expand All @@ -926,7 +932,8 @@ private static boolean fillOuterTypeParams(TypeReference[][] rr, int idx, Eclips
rr[idx] = trs;
filled = true;
}
if ((td.modifiers & ClassFileConstants.AccStatic) != 0) return filled; // Once we hit a static class, no further typeparams needed.

if ((td.modifiers & MODIFIERS_INDICATING_STATIC) != 0) return filled; // Once we hit a static class, no further typeparams needed.
boolean f2 = fillOuterTypeParams(rr, idx - 1, node.up(), p);
return f2 || filled;
}
Expand Down Expand Up @@ -961,7 +968,8 @@ public static TypeReference generateTypeReference(EclipseNode type, long p) {
long[] ps = new long[tnLen];
for (int i = 0; i < tnLen; i++) ps[i] = p;

boolean instance = (td.modifiers & ClassFileConstants.AccStatic) == 0 && type.up() != null && type.up().get() instanceof TypeDeclaration;

boolean instance = (td.modifiers & MODIFIERS_INDICATING_STATIC) == 0 && type.up() != null && type.up().get() instanceof TypeDeclaration;
if (instance) {
TypeReference[][] trs = new TypeReference[tn.length][];
boolean filled = fillOuterTypeParams(trs, trs.length - 2, type.up(), p);
Expand Down Expand Up @@ -2103,7 +2111,7 @@ public static List<Integer> createListOfNonExistentFields(List<String> list, Ecl
if (list.isEmpty()) break;
if (child.getKind() != Kind.FIELD) continue;
if (excludeStandard) {
if ((((FieldDeclaration)child.get()).modifiers & ClassFileConstants.AccStatic) != 0) continue;
if ((((FieldDeclaration) child.get()).modifiers & ClassFileConstants.AccStatic) != 0) continue;
if (child.getName().startsWith("$")) continue;
}
if (excludeTransient && (((FieldDeclaration)child.get()).modifiers & ClassFileConstants.AccTransient) != 0) continue;
Expand Down

0 comments on commit 7142194

Please sign in to comment.