示例#1
0
 @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;
 }
示例#2
0
 private void testSuccessfulParse(String s, TreeNode tn) {
   SyntaxTree t = TestParseHelper.earleyParseBuildTree(g, s, null, diagnostics);
   assert !diagnostics.hasError()
       : "Got parser errors: " + TestParseHelper.getParseOutput(diagnostics);
   if (tn != null)
     assert tn.equals(t.getRoot()) : "Got unexpected tree: " + t.getRoot() + ", expected: " + tn;
 }
示例#3
0
 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;
 }
示例#4
0
 @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;
 }
示例#5
0
 @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;
 }
示例#6
0
 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;
 }