Skip to content

Commit 67fccba

Browse files
committed
[With] fixing the internal aliasing system
old Wither annotations were no longer being picked up.
1 parent 514fd71 commit 67fccba

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

src/core/lombok/core/LombokInternalAliasing.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
package lombok.core;
2323

24+
import java.util.ArrayList;
2425
import java.util.Collection;
2526
import java.util.Collections;
2627
import java.util.HashMap;
@@ -30,6 +31,7 @@ public class LombokInternalAliasing {
3031
/** Maps a package name to a space separated list of packages. If the key package is star-imported, assume all packages in the 'value' part of the MapEntry are too. */
3132
public static final Map<String, Collection<String>> IMPLIED_EXTRA_STAR_IMPORTS;
3233
public static final Map<String, String> ALIASES;
34+
public static final Map<String, Collection<String>> REVERSE_ALIASES;
3335

3436
/**
3537
* Provide a fully qualified name (FQN), and the canonical version of this is returned.
@@ -53,5 +55,24 @@ public static String processAliases(String in) {
5355
m2.put("lombok.Delegate", "lombok.experimental.Delegate");
5456
m2.put("lombok.experimental.Wither", "lombok.With");
5557
ALIASES = Collections.unmodifiableMap(m2);
58+
59+
Map<String, Collection<String>> m3 = new HashMap<String, Collection<String>>();
60+
for (Map.Entry<String, String> e : m2.entrySet()) {
61+
Collection<String> c = m3.get(e.getValue());
62+
if (c == null) {
63+
m3.put(e.getValue(), Collections.singleton(e.getKey()));
64+
} else if (c.size() == 1) {
65+
Collection<String> newC = new ArrayList<String>(2);
66+
newC.addAll(c);
67+
m3.put(e.getValue(), c);
68+
} else {
69+
c.add(e.getKey());
70+
}
71+
}
72+
for (Map.Entry<String, Collection<String>> e : m3.entrySet()) {
73+
Collection<String> c = e.getValue();
74+
if (c.size() > 1) e.setValue(Collections.unmodifiableList((ArrayList<String>) c));
75+
}
76+
REVERSE_ALIASES = Collections.unmodifiableMap(m3);
5677
}
5778
}

src/core/lombok/core/TypeLibrary.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009-2015 The Project Lombok Authors.
2+
* Copyright (C) 2009-2019 The Project Lombok Authors.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -21,6 +21,7 @@
2121
*/
2222
package lombok.core;
2323

24+
import java.util.Collection;
2425
import java.util.HashMap;
2526
import java.util.Map;
2627

@@ -75,6 +76,14 @@ private TypeLibrary(String fqnSingleton) {
7576
}
7677

7778
public static TypeLibrary createLibraryForSingleType(String fqnSingleton) {
79+
if (LombokInternalAliasing.REVERSE_ALIASES.containsKey(fqnSingleton)) {
80+
// Internal aliasing is a little too complex to handle with the map-less 'efficient' implementation.
81+
TypeLibrary tl = new TypeLibrary();
82+
tl.addType(fqnSingleton);
83+
tl.lock();
84+
return tl;
85+
}
86+
7887
return new TypeLibrary(fqnSingleton);
7988
}
8089

@@ -89,16 +98,19 @@ public void addType(String fullyQualifiedTypeName) {
8998
if (locked) throw new IllegalStateException("locked");
9099
int idx = fullyQualifiedTypeName.lastIndexOf('.');
91100
if (idx == -1) throw new IllegalArgumentException(
92-
"Only fully qualified types are allowed (and stuff in the default package is not palatable to us either!)");
101+
"Only fully qualified types are allowed (types in the default package cannot be added here either)");
93102
String unqualified = fullyQualifiedTypeName.substring(idx + 1);
94103
if (unqualifiedToQualifiedMap == null) throw new IllegalStateException("SingleType library");
95104

96105
unqualifiedToQualifiedMap.put(unqualified.replace("$", "."), dotBased);
97106
unqualifiedToQualifiedMap.put(unqualified, dotBased);
98107
unqualifiedToQualifiedMap.put(fullyQualifiedTypeName, dotBased);
99108
unqualifiedToQualifiedMap.put(dotBased, dotBased);
100-
for (Map.Entry<String, String> e : LombokInternalAliasing.ALIASES.entrySet()) {
101-
if (fullyQualifiedTypeName.equals(e.getValue())) unqualifiedToQualifiedMap.put(e.getKey(), dotBased);
109+
Collection<String> oldNames = LombokInternalAliasing.REVERSE_ALIASES.get(fullyQualifiedTypeName);
110+
if (oldNames != null) for (String oldName : oldNames) {
111+
unqualifiedToQualifiedMap.put(oldName, dotBased);
112+
int li = oldName.lastIndexOf('.');
113+
if (li != -1) unqualifiedToQualifiedMap.put(oldName.substring(li + 1), dotBased);
102114
}
103115

104116
int idx2 = fullyQualifiedTypeName.indexOf('$', idx + 1);
@@ -119,9 +131,6 @@ public void addType(String fullyQualifiedTypeName) {
119131
public String toQualified(String typeReference) {
120132
if (unqualifiedToQualifiedMap == null) {
121133
if (typeReference.equals(unqualified) || typeReference.equals(qualified)) return qualified;
122-
for (Map.Entry<String, String> e : LombokInternalAliasing.ALIASES.entrySet()) {
123-
if (e.getKey().equals(typeReference)) return e.getValue();
124-
}
125134
return null;
126135
}
127136
return unqualifiedToQualifiedMap.get(typeReference);

src/core/lombok/core/TypeResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009-2015 The Project Lombok Authors.
2+
* Copyright (C) 2009-2019 The Project Lombok Authors.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -45,7 +45,7 @@ public boolean typeMatches(LombokNode<?, ?, ?> context, String fqn, String typeR
4545

4646
public String typeRefToFullyQualifiedName(LombokNode<?, ?, ?> context, TypeLibrary library, String typeRef) {
4747
typeRef = LombokInternalAliasing.processAliases(typeRef);
48-
// When asking if 'Foo' could possibly be referring to 'bar.Baz', the answer is obviously no.
48+
// When asking if 'Foo' could possibly be referring to 'bar.Baz', the answer is obviously no.
4949
String qualified = library.toQualified(typeRef);
5050
if (qualified == null) return null;
5151

0 commit comments

Comments
 (0)