if (type.isPrimitive()) {
return KEYWORD.colorize(text);
}
final String packageName = type.getPackageName();
final TypeDefinition resolvedType = type.resolve();
if (StringUtilities.isNullOrEmpty(packageName)) {
if (resolvedType != null && resolvedType.isAnnotation()) {
return ATTRIBUTE.colorize(text);
}
else {
return TYPE.colorize(text);
}
}
String s = text;
char delimiter = '.';
String packagePrefix = packageName + delimiter;
int arrayDepth = 0;
while (arrayDepth < s.length() && s.charAt(arrayDepth) == '[') {
arrayDepth++;
}
if (arrayDepth > 0) {
s = s.substring(arrayDepth);
}
final boolean isSignature = s.startsWith("L") && s.endsWith(";");
if (isSignature) {
s = s.substring(1, s.length() - 1);
}
if (!StringUtilities.startsWith(s, packagePrefix)) {
delimiter = '/';
packagePrefix = packageName.replace('.', delimiter) + delimiter;
}
if (StringUtilities.startsWith(s, packagePrefix)) {
final StringBuilder sb = new StringBuilder();
final String[] packageParts = packageName.split("\\.");
for (int i = 0; i < arrayDepth; i++) {
sb.append('[');
}
if (isSignature) {
sb.append('L');
}
for (int i = 0; i < packageParts.length; i++) {
if (i != 0) {
sb.append(DELIMITER.colorize(String.valueOf(delimiter)));
}
sb.append(PACKAGE.colorize(packageParts[i]));
}
sb.append(DELIMITER.colorize(String.valueOf(delimiter)));
final String typeName = s.substring(packagePrefix.length());
final String[] typeParts = typeName.split("\\$|\\.");
final Ansi typeColor = resolvedType != null && resolvedType.isAnnotation() ? ATTRIBUTE : TYPE;
final boolean dollar = typeName.indexOf('$') >= 0;
for (int i = 0; i < typeParts.length; i++) {
if (i != 0) {
sb.append(DELIMITER.colorize(dollar ? "$" : "."));
}
sb.append(typeColor.colorize(typeParts[i]));
}
if (isSignature) {
sb.append(';');
}
return sb.toString();
}
if (resolvedType != null && resolvedType.isAnnotation()) {
return ATTRIBUTE.colorize(text);
}
else {
return TYPE.colorize(text);
}