use of kalang.FieldNotFoundException in project kalang by kasonyang.
the class AstBuilder method getImplicitInvokeExpr.
@Nullable
private ExprNode getImplicitInvokeExpr(String methodName, ExprNode[] args, ParserRuleContext ctx) {
ExprNode expr = null;
try {
ObjectType clazzType = getThisType();
InvocationExpr.MethodSelection ms = InvocationExpr.applyMethod(clazzType, methodName, args, clazzType.getMethodDescriptors(thisClazz, true, true));
if (Modifier.isStatic(ms.selectedMethod.getModifier())) {
expr = new StaticInvokeExpr(new ClassReference(thisClazz), ms.selectedMethod, ms.appliedArguments);
} else {
expr = new ObjectInvokeExpr(new ThisExpr(getThisType()), ms.selectedMethod, ms.appliedArguments);
}
} catch (MethodNotFoundException ex) {
if (args.length == 1 && (methodName.equals("print") || methodName.equals("println"))) {
try {
StaticFieldExpr fieldExpr = StaticFieldExpr.create(new ClassReference(Types.requireClassType("java.lang.System").getClassNode()), "out", null);
expr = getObjectInvokeExpr(fieldExpr, methodName, args, ctx);
} catch (FieldNotFoundException fnfEx) {
throw Exceptions.unexceptedException(fnfEx);
}
}
if (expr == null) {
this.methodNotFound(ctx.getStart(), className, methodName, args);
expr = new UnknownInvocationExpr(null, methodName, args);
}
} catch (AmbiguousMethodException ex) {
methodIsAmbiguous(ctx.start, ex);
return null;
}
mapAst(expr, ctx);
return expr;
}
use of kalang.FieldNotFoundException in project kalang by kasonyang.
the class AstBuilder method getObjectFieldExpr.
@Nullable
protected ExprNode getObjectFieldExpr(ExprNode expr, String fieldName, @Nullable ParserRuleContext rule) {
ExprNode ret;
Type type = expr.getType();
if (!(type instanceof ObjectType)) {
// AstBuilder.this.handleSyntaxError("unsupported type", rule==null ? ParserRuleContext.EMPTY : rule);
return null;
}
ObjectType exprType = (ObjectType) type;
if ((exprType instanceof ArrayType)) {
return null;
} else {
try {
ret = ObjectFieldExpr.create(expr, fieldName, exprType.getClassNode());
} catch (FieldNotFoundException ex) {
return null;
}
}
if (rule != null)
mapAst(ret, rule);
return ret;
}
use of kalang.FieldNotFoundException in project kalang by kasonyang.
the class AstBuilder method getObjectFieldLikeExpr.
protected ExprNode getObjectFieldLikeExpr(ExprNode expr, String fieldName, @Nullable ParserRuleContext rule) {
ExprNode ret;
Type type = expr.getType();
if (!(type instanceof ObjectType)) {
AstBuilder.this.handleSyntaxError("unsupported type", rule == null ? ParserRuleContext.EMPTY : rule);
return null;
}
ObjectType exprType = (ObjectType) type;
if ((exprType instanceof ArrayType) && fieldName.equals("length")) {
ret = new ArrayLengthExpr(expr);
} else {
try {
ret = ObjectFieldExpr.create(expr, fieldName, thisClazz);
} catch (FieldNotFoundException ex) {
this.diagnosisReporter.report(Diagnosis.Kind.ERROR, "field not found:" + fieldName, rule);
ret = new UnknownFieldExpr(expr, exprType.getClassNode(), fieldName);
}
}
if (rule != null)
mapAst(ret, rule);
return ret;
}
use of kalang.FieldNotFoundException in project kalang by kasonyang.
the class AstBuilder method getStaticFieldExpr.
protected AssignableExpr getStaticFieldExpr(ClassReference clazz, String fieldName, ParserRuleContext rule) {
AssignableExpr ret;
try {
ret = StaticFieldExpr.create(clazz, fieldName, thisClazz);
} catch (FieldNotFoundException ex) {
// ret = new UnknownFieldExpr(clazz, clazz.getReferencedClassNode(), fieldName);
return null;
}
mapAst(ret, rule);
return ret;
}
use of kalang.FieldNotFoundException in project kalang by kasonyang.
the class ObjectFieldExpr method create.
@Nonnull
public static FieldExpr create(@Nonnull ExprNode target, String fieldName, @Nullable ClassNode caller) throws FieldNotFoundException {
Type type = target.getType();
if (!(type instanceof ObjectType)) {
throw new UnsupportedOperationException("unsupported type:" + type);
}
ObjectType classType = (ObjectType) type;
FieldDescriptor field = getField(classType, fieldName, caller);
if (AstUtil.isStatic(field.getModifier())) {
throw new FieldNotFoundException(fieldName + " is static");
}
return new ObjectFieldExpr(target, field);
}
Aggregations