use of kalang.AstNotFoundException in project kalang by kasonyang.
the class JvmClassNode method transType.
// TODO why transType could be null?
@Nullable
private Type transType(java.lang.reflect.Type t, Map<TypeVariable, GenericType> genericTypes) {
if (t instanceof TypeVariable) {
GenericType vt = genericTypes.get((TypeVariable) t);
// FIXME it may be null if TypeVariable comes from method
if (vt != null) {
return vt;
}
return null;
} else if (t instanceof java.lang.reflect.ParameterizedType) {
java.lang.reflect.ParameterizedType pt = (java.lang.reflect.ParameterizedType) t;
Type rawType = transType(pt.getRawType(), genericTypes);
if (!(rawType instanceof ObjectType)) {
return null;
}
java.lang.reflect.Type[] typeArgs = pt.getActualTypeArguments();
Type[] gTypes = transType(typeArgs, genericTypes);
if (gTypes == null) {
return null;
}
return Types.getClassType(((ObjectType) rawType).getClassNode(), gTypes);
} else if (t instanceof java.lang.reflect.WildcardType) {
java.lang.reflect.WildcardType wt = (java.lang.reflect.WildcardType) t;
Type[] upperBounds = transType(wt.getUpperBounds(), genericTypes);
if (upperBounds == null) {
return null;
}
Type[] lowerBounds = transType(wt.getLowerBounds(), genericTypes);
if (lowerBounds == null) {
return null;
}
return new WildcardType(upperBounds, lowerBounds);
} else if (t instanceof GenericArrayType) {
GenericArrayType gt = (GenericArrayType) t;
Type ct = transType(gt.getGenericComponentType(), genericTypes);
if (ct == null) {
return null;
}
return Types.getArrayType(ct, NullableKind.NONNULL);
} else if (t instanceof Class) {
Class type = (Class) t;
if (type.isPrimitive()) {
return Types.getPrimitiveType(type.getTypeName());
} else if (type.isArray()) {
Type ct = transType(type.getComponentType(), genericTypes);
if (ct == null) {
return null;
}
return Types.getArrayType(ct);
} else {
try {
return Types.getClassType(this.astLoader.findAst(type));
} catch (AstNotFoundException ex) {
throw new RuntimeException(ex);
}
}
} else {
return null;
}
}
use of kalang.AstNotFoundException in project kalang by kasonyang.
the class AstLoader method loadAst.
@Nonnull
public ClassNode loadAst(@Nonnull String className) throws AstNotFoundException {
ClassNode ast = cachedAsts.get(className);
if (ast != null)
return ast;
if (parent != null) {
try {
return parent.loadAst(className);
} catch (AstNotFoundException ex) {
}
}
if (className.endsWith("[]")) {
String name = className;
name = name.substring(0, name.length() - 2);
ast = AstUtil.createArrayAst(loadAst(name).name);
} else {
ast = findAst(className);
if (ast == null)
throw new AstNotFoundException(className);
}
cachedAsts.put(className, ast);
return ast;
}
Aggregations