diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-15 20:31:25 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-15 20:31:25 +0200 |
commit | 293a4bfaf056d11256980fb55a914d47fbbcd36c (patch) | |
tree | 6da8462ac6e052e54191accdeae47d483441533b /src/lombok/core | |
parent | 842cefb75c735d333f3c55bcedf690f3c2f0eb18 (diff) | |
download | lombok-293a4bfaf056d11256980fb55a914d47fbbcd36c.tar.gz lombok-293a4bfaf056d11256980fb55a914d47fbbcd36c.tar.bz2 lombok-293a4bfaf056d11256980fb55a914d47fbbcd36c.zip |
Renamed lombok.transformations lombok.core as the purpose of this package is to contain stuff that is useful for any lombok implementation (be it e.g. javac via apt or eclipse via agent), but not annotations and other classes that are for 'end users'.
Diffstat (limited to 'src/lombok/core')
-rw-r--r-- | src/lombok/core/TransformationsUtil.java | 18 | ||||
-rw-r--r-- | src/lombok/core/TypeLibrary.java | 39 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/lombok/core/TransformationsUtil.java b/src/lombok/core/TransformationsUtil.java new file mode 100644 index 00000000..0ce99d9f --- /dev/null +++ b/src/lombok/core/TransformationsUtil.java @@ -0,0 +1,18 @@ +package lombok.core; + +public class TransformationsUtil { + private TransformationsUtil() {} + + public static String toGetterName(CharSequence fieldName, boolean isBoolean) { + final String prefix = isBoolean ? "is" : "get"; + final String suffix; + + if ( fieldName.length() == 0 ) return prefix; + + char first = fieldName.charAt(0); + if ( Character.isLowerCase(first) ) + suffix = String.format("%s%s", Character.toTitleCase(first), fieldName.subSequence(1, fieldName.length())); + else suffix = fieldName.toString(); + return String.format("%s%s", prefix, suffix); + } +} diff --git a/src/lombok/core/TypeLibrary.java b/src/lombok/core/TypeLibrary.java new file mode 100644 index 00000000..c6789d7e --- /dev/null +++ b/src/lombok/core/TypeLibrary.java @@ -0,0 +1,39 @@ +package lombok.core; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class TypeLibrary { + private final Map<String, Set<String>> simpleToQualifiedMap = new HashMap<String, Set<String>>(); + + public void addType(String fullyQualifiedTypeName) { + 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!)"); + + final String simpleName = fullyQualifiedTypeName.substring(idx +1); + final String packageName = fullyQualifiedTypeName.substring(0, idx); + + if ( simpleToQualifiedMap.put(fullyQualifiedTypeName, Collections.singleton(fullyQualifiedTypeName)) != null ) return; + + addToMap(simpleName, fullyQualifiedTypeName); + addToMap(packageName + ".*", fullyQualifiedTypeName); + } + + private TypeLibrary addToMap(String keyName, String fullyQualifiedTypeName) { + Set<String> existing = simpleToQualifiedMap.get(keyName); + Set<String> set = (existing == null) ? new HashSet<String>() : new HashSet<String>(existing); + set.add(fullyQualifiedTypeName); + simpleToQualifiedMap.put(keyName, Collections.unmodifiableSet(set)); + return this; + } + + public Collection<String> findCompatible(String typeReference) { + Set<String> result = simpleToQualifiedMap.get(typeReference); + return result == null ? Collections.<String>emptySet() : result; + } +} |