@Override public boolean visit(ClassInstanceCreationExpression c) { ExpressionType clzType; if (c.hasBody()) { clzType = new ExpressionType(cip.getFullName(c.getBody())); } else { clzType = c.getId().getExpressionType(); } if (hasMethods(clzType, c)) { String fqn = clzType.getClassName(); ArgumentList al = c.getArgumentList(); try { MethodInformation mi = findMatchingConstructor(fqn, al); if (mi == null) { diagnostics.report( SourceDiagnostics.error( tree.getOrigin(), c.getParsePosition(), "No matching constructor found")); } else { c.setMethodInformation(mi); } } catch (IOException e) { diagnostics.report( SourceDiagnostics.error( tree.getOrigin(), c.getParsePosition(), "Failed to read class: " + e)); } } return true; }
private boolean hasMethods(ExpressionType clzType, TreeNode m) { if (clzType.isPrimitiveType()) { diagnostics.report( SourceDiagnostics.error( tree.getOrigin(), m.getParsePosition(), "Primitives have no methods")); return false; } else if (clzType == ExpressionType.VOID) { diagnostics.report( SourceDiagnostics.error(tree.getOrigin(), m.getParsePosition(), "Void has no methods")); return false; } else if (clzType == ExpressionType.NULL) { diagnostics.report( SourceDiagnostics.error(tree.getOrigin(), m.getParsePosition(), "null has no methods")); return false; } return true; }
@Override public boolean visit(FieldAccess f) { ExpressionType retType = cip.getFieldType(f.getFrom().getExpressionType().getClassName(), f.getFieldId()); if (retType == null) { diagnostics.report( SourceDiagnostics.error( tree.getOrigin(), f.getParsePosition(), "Cannot find symbol: %s", f.getFieldId())); } else { f.setReturnType(retType); } return true; }
@Override public boolean visit(MethodInvocation m) { ExpressionType clzType = getOnType(m.getOn()); if (hasMethods(clzType, m)) { String fqn = clzType.getClassName(); String name = m.getId(); ArgumentList al = m.getArgumentList(); try { MethodInformation mi = findMatchingMethod(fqn, name, al); if (mi == null) { diagnostics.report( SourceDiagnostics.error( tree.getOrigin(), m.getParsePosition(), "No matching method found")); } else { m.setMethodInformation(mi); } } catch (IOException e) { diagnostics.report( SourceDiagnostics.error( tree.getOrigin(), m.getParsePosition(), "Failed to read class: " + e)); } } return false; }
private ExpressionType lub(TreeNode tn, ExpressionType et1, ExpressionType et2) { if (et1.isPrimitiveType()) { if (!et2.isPrimitiveType()) { diagnostics.report( SourceDiagnostics.error( tree.getOrigin(), tn.getParsePosition(), "Unable to find common parent type of %s and %s", et1, et2)); return null; } return ExpressionType.bigger(et1, et2); } return et1; }