aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/lombok/core/LombokInternalAliasing.java21
-rw-r--r--src/core/lombok/core/TypeLibrary.java23
-rw-r--r--src/core/lombok/core/TypeResolver.java4
3 files changed, 39 insertions, 9 deletions
diff --git a/src/core/lombok/core/LombokInternalAliasing.java b/src/core/lombok/core/LombokInternalAliasing.java
index 0b92d3b9..68ced84f 100644
--- a/src/core/lombok/core/LombokInternalAliasing.java
+++ b/src/core/lombok/core/LombokInternalAliasing.java
@@ -21,6 +21,7 @@
*/
package lombok.core;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -30,6 +31,7 @@ public class LombokInternalAliasing {
/** 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. */
public static final Map<String, Collection<String>> IMPLIED_EXTRA_STAR_IMPORTS;
public static final Map<String, String> ALIASES;
+ public static final Map<String, Collection<String>> REVERSE_ALIASES;
/**
* Provide a fully qualified name (FQN), and the canonical version of this is returned.
@@ -53,5 +55,24 @@ public class LombokInternalAliasing {
m2.put("lombok.Delegate", "lombok.experimental.Delegate");
m2.put("lombok.experimental.Wither", "lombok.With");
ALIASES = Collections.unmodifiableMap(m2);
+
+ Map<String, Collection<String>> m3 = new HashMap<String, Collection<String>>();
+ for (Map.Entry<String, String> e : m2.entrySet()) {
+ Collection<String> c = m3.get(e.getValue());
+ if (c == null) {
+ m3.put(e.getValue(), Collections.singleton(e.getKey()));
+ } else if (c.size() == 1) {
+ Collection<String> newC = new ArrayList<String>(2);
+ newC.addAll(c);
+ m3.put(e.getValue(), c);
+ } else {
+ c.add(e.getKey());
+ }
+ }
+ for (Map.Entry<String, Collection<String>> e : m3.entrySet()) {
+ Collection<String> c = e.getValue();
+ if (c.size() > 1) e.setValue(Collections.unmodifiableList((ArrayList<String>) c));
+ }
+ REVERSE_ALIASES = Collections.unmodifiableMap(m3);
}
}
diff --git a/src/core/lombok/core/TypeLibrary.java b/src/core/lombok/core/TypeLibrary.java
index ceaf5f90..113ce67e 100644
--- a/src/core/lombok/core/TypeLibrary.java
+++ b/src/core/lombok/core/TypeLibrary.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2015 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
@@ -21,6 +21,7 @@
*/
package lombok.core;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -75,6 +76,14 @@ public class TypeLibrary {
}
public static TypeLibrary createLibraryForSingleType(String fqnSingleton) {
+ if (LombokInternalAliasing.REVERSE_ALIASES.containsKey(fqnSingleton)) {
+ // Internal aliasing is a little too complex to handle with the map-less 'efficient' implementation.
+ TypeLibrary tl = new TypeLibrary();
+ tl.addType(fqnSingleton);
+ tl.lock();
+ return tl;
+ }
+
return new TypeLibrary(fqnSingleton);
}
@@ -89,7 +98,7 @@ public class TypeLibrary {
if (locked) throw new IllegalStateException("locked");
int idx = fullyQualifiedTypeName.lastIndexOf('.');
if (idx == -1) throw new IllegalArgumentException(
- "Only fully qualified types are allowed (and stuff in the default package is not palatable to us either!)");
+ "Only fully qualified types are allowed (types in the default package cannot be added here either)");
String unqualified = fullyQualifiedTypeName.substring(idx + 1);
if (unqualifiedToQualifiedMap == null) throw new IllegalStateException("SingleType library");
@@ -97,8 +106,11 @@ public class TypeLibrary {
unqualifiedToQualifiedMap.put(unqualified, dotBased);
unqualifiedToQualifiedMap.put(fullyQualifiedTypeName, dotBased);
unqualifiedToQualifiedMap.put(dotBased, dotBased);
- for (Map.Entry<String, String> e : LombokInternalAliasing.ALIASES.entrySet()) {
- if (fullyQualifiedTypeName.equals(e.getValue())) unqualifiedToQualifiedMap.put(e.getKey(), dotBased);
+ Collection<String> oldNames = LombokInternalAliasing.REVERSE_ALIASES.get(fullyQualifiedTypeName);
+ if (oldNames != null) for (String oldName : oldNames) {
+ unqualifiedToQualifiedMap.put(oldName, dotBased);
+ int li = oldName.lastIndexOf('.');
+ if (li != -1) unqualifiedToQualifiedMap.put(oldName.substring(li + 1), dotBased);
}
int idx2 = fullyQualifiedTypeName.indexOf('$', idx + 1);
@@ -119,9 +131,6 @@ public class TypeLibrary {
public String toQualified(String typeReference) {
if (unqualifiedToQualifiedMap == null) {
if (typeReference.equals(unqualified) || typeReference.equals(qualified)) return qualified;
- for (Map.Entry<String, String> e : LombokInternalAliasing.ALIASES.entrySet()) {
- if (e.getKey().equals(typeReference)) return e.getValue();
- }
return null;
}
return unqualifiedToQualifiedMap.get(typeReference);
diff --git a/src/core/lombok/core/TypeResolver.java b/src/core/lombok/core/TypeResolver.java
index 60ac6b6a..06c91138 100644
--- a/src/core/lombok/core/TypeResolver.java
+++ b/src/core/lombok/core/TypeResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2015 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
@@ -45,7 +45,7 @@ public class TypeResolver {
public String typeRefToFullyQualifiedName(LombokNode<?, ?, ?> context, TypeLibrary library, String typeRef) {
typeRef = LombokInternalAliasing.processAliases(typeRef);
- // When asking if 'Foo' could possibly be referring to 'bar.Baz', the answer is obviously no.
+ // When asking if 'Foo' could possibly be referring to 'bar.Baz', the answer is obviously no.
String qualified = library.toQualified(typeRef);
if (qualified == null) return null;