use of kalang.core.NullableKind in project kalang by kasonyang.
the class JvmClassNode method getDeclaredMethodNodes.
@Override
public MethodNode[] getDeclaredMethodNodes() {
if (!this.methodsInitialized) {
this.methodsInitialized = true;
List<Executable> methods = new LinkedList();
methods.addAll(Arrays.asList(clazz.getDeclaredMethods()));
methods.addAll(Arrays.asList(clazz.getDeclaredConstructors()));
for (Executable m : methods) {
NullableKind nullable = getNullable(m.getAnnotations());
Type mType;
String mName;
int mModifier;
if (m instanceof Method) {
mType = getType(((Method) m).getGenericReturnType(), getGenericTypeMap(), ((Method) m).getReturnType(), nullable);
mName = m.getName();
mModifier = m.getModifiers();
} else if (m instanceof Constructor) {
mName = "<init>";
// getType(clz);
mType = Types.VOID_TYPE;
// | Modifier.STATIC;
mModifier = m.getModifiers();
} else {
throw Exceptions.unexceptedValue(m);
}
MethodNode methodNode = createMethodNode(mType, mName, mModifier);
for (Parameter p : m.getParameters()) {
NullableKind pnullable = getNullable(p.getAnnotations());
methodNode.createParameter(getType(p.getParameterizedType(), getGenericTypeMap(), p.getType(), pnullable), p.getName());
}
for (Class e : m.getExceptionTypes()) {
methodNode.addExceptionType(getType(e, getGenericTypeMap(), e, NullableKind.NONNULL));
}
}
}
return super.getDeclaredMethodNodes();
}
use of kalang.core.NullableKind in project kalang by kasonyang.
the class AstBuilder method getVarObjectType.
private Type getVarObjectType(VarObject p) {
Type type = this.overrideTypes.get(p);
if (type == null)
type = p.getType();
// TODO handle other object type
if (type instanceof ClassType) {
Integer ns = nullState.get(p);
NullableKind nullable;
if (ns == null) {
nullable = ((ObjectType) type).getNullable();
} else if (ns == NULLSTATE_MUST_NONNULL) {
nullable = NullableKind.NONNULL;
} else if (ns == NULLSTATE_UNKNOWN) {
nullable = NullableKind.UNKNOWN;
} else if (ns == NULLSTATE_MUST_NULL || ns == NULLSTATE_NULLABLE) {
nullable = NullableKind.NULLABLE;
} else {
throw Exceptions.unexceptedValue(ns);
}
return Types.getClassType((ClassType) type, nullable);
} else {
return type;
}
}
use of kalang.core.NullableKind in project kalang by kasonyang.
the class AstBuilder method parseClassType.
@Nullable
protected ObjectType parseClassType(KalangParser.ClassTypeContext ctx) {
NullableKind nullable = ctx.nullable == null ? NullableKind.NONNULL : NullableKind.NULLABLE;
Token rawTypeToken = ctx.rawClass;
List<String> classNameParts = new LinkedList();
for (Token p : ctx.paths) {
classNameParts.add(p.getText());
}
if (ctx.innerClass != null) {
classNameParts.add(rawTypeToken.getText() + "$" + ctx.innerClass.getText());
} else {
classNameParts.add(rawTypeToken.getText());
}
String rawType = String.join(".", classNameParts);
for (GenericType gt : thisClazz.getGenericTypes()) {
if (rawType.equals(gt.getName()))
return gt;
}
ObjectType clazzType = requireClassType(rawType, rawTypeToken);
if (clazzType == null)
return null;
ClassNode clazzNode = clazzType.getClassNode();
GenericType[] clzDeclaredGenericTypes = clazzNode.getGenericTypes();
List<KalangParser.ParameterizedElementTypeContext> parameterTypes = ctx.parameterTypes;
if (parameterTypes != null && !parameterTypes.isEmpty()) {
Type[] typeArguments = new Type[parameterTypes.size()];
if (parameterTypes != null && parameterTypes.size() > 0) {
if (clzDeclaredGenericTypes.length != parameterTypes.size()) {
diagnosisReporter.report(Diagnosis.Kind.ERROR, "wrong number of type arguments", ctx);
return null;
}
for (int i = 0; i < typeArguments.length; i++) {
typeArguments[i] = parseParameterizedElementType(parameterTypes.get(i));
// TODO should return null?
if (typeArguments[i] == null)
return null;
}
}
return Types.getClassType(clazzType.getClassNode(), typeArguments, nullable);
} else {
return Types.getClassType(clazzType.getClassNode(), nullable);
}
}
use of kalang.core.NullableKind in project kalang by kasonyang.
the class JvmClassNode method getFields.
@Override
public FieldNode[] getFields() {
if (!this.fieldsInitialized) {
this.fieldsInitialized = true;
for (Field f : clazz.getDeclaredFields()) {
NullableKind nullable = getNullable(f.getAnnotations());
FieldNode fn = createField(getType(f.getGenericType(), getGenericTypeMap(), f.getType(), nullable), f.getName(), f.getModifiers());
}
}
return super.getFields();
}
Aggregations