diff options
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; + } +} |