diff options
author | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2019-08-29 16:18:27 +0200 |
---|---|---|
committer | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2019-08-29 16:19:28 +0200 |
commit | 67fccba8efbb68d8a7d3c5804b87a29abb622eaf (patch) | |
tree | 02b54b7b63ac52aed91e80260231ab93a2bba605 /src/core/lombok | |
parent | 514fd710c5fc581dc22143352101d7b191d3df0f (diff) | |
download | lombok-67fccba8efbb68d8a7d3c5804b87a29abb622eaf.tar.gz lombok-67fccba8efbb68d8a7d3c5804b87a29abb622eaf.tar.bz2 lombok-67fccba8efbb68d8a7d3c5804b87a29abb622eaf.zip |
[With] fixing the internal aliasing system
old Wither annotations were no longer being picked up.
Diffstat (limited to 'src/core/lombok')
-rw-r--r-- | src/core/lombok/core/LombokInternalAliasing.java | 21 | ||||
-rw-r--r-- | src/core/lombok/core/TypeLibrary.java | 23 | ||||
-rw-r--r-- | src/core/lombok/core/TypeResolver.java | 4 |
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; |