@Override
 public Void visit(ObjectCreationExpr expr, AElement elem) {
   ClassOrInterfaceType type = expr.getType();
   AClass clazz = scene.classes.vivify(type.getName());
   Expression scope = expr.getScope();
   List<Type> typeArgs = expr.getTypeArgs();
   List<Expression> args = expr.getArgs();
   List<BodyDeclaration> decls = expr.getAnonymousClassBody();
   if (scope != null) {
     scope.accept(this, elem);
   }
   if (args != null) {
     for (Expression arg : args) {
       arg.accept(this, elem);
     }
   }
   if (typeArgs != null) {
     for (Type typeArg : typeArgs) {
       typeArg.accept(this, elem);
     }
   }
   type.accept(this, clazz);
   if (decls != null) {
     for (BodyDeclaration decl : decls) {
       decl.accept(this, clazz);
     }
   }
   return null;
 }
Пример #2
0
 @Override
 public void visit(ClassOrInterfaceType n, Object arg) {
   printAnnotations(n.getAnnotations(), arg);
   if (n.getScope() != null) {
     n.getScope().accept(this, arg);
     printer.print(".");
   }
   printer.print(n.getName());
   printTypeArgs(n.getTypeArgs(), arg);
 }
 @Override
 public Void visit(MethodDeclaration decl, AElement elem) {
   Type type = decl.getType();
   List<Parameter> params = decl.getParameters();
   List<TypeParameter> typeParams = decl.getTypeParameters();
   List<AnnotationExpr> rcvrAnnos = decl.getReceiverAnnotations();
   BlockStmt body = decl.getBody();
   StringBuilder sb = new StringBuilder(decl.getName()).append('(');
   AClass clazz = (AClass) elem;
   AMethod method;
   if (params != null) {
     for (Parameter param : params) {
       Type ptype = param.getType();
       sb.append(getJVML(ptype));
     }
   }
   sb.append(')').append(getJVML(type));
   method = clazz.methods.vivify(sb.toString());
   visitDecl(decl, method);
   visitType(type, method.returnType);
   if (params != null) {
     int i = 0;
     for (Parameter param : params) {
       AField field = method.parameters.vivify(i++);
       visitType(param.getType(), field.type);
     }
   }
   if (rcvrAnnos != null) {
     for (AnnotationExpr expr : rcvrAnnos) {
       Annotation anno = extractAnnotation(expr);
       method.receiver.type.tlAnnotationsHere.add(anno);
     }
   }
   if (typeParams != null) {
     int i = 0;
     for (TypeParameter typeParam : typeParams) {
       List<ClassOrInterfaceType> bounds = typeParam.getTypeBound();
       if (bounds != null) {
         int j = 0;
         for (ClassOrInterfaceType bound : bounds) {
           BoundLocation loc = new BoundLocation(i, j);
           bound.accept(this, method.bounds.vivify(loc));
           ++j;
         }
       }
       ++i;
     }
   }
   return body == null ? null : body.accept(this, method);
 }
Пример #4
0
 @Override
 public void visit(TypeParameter n, Object arg) {
   printAnnotations(n.getAnnotations(), arg);
   printer.print(n.getName());
   if (n.getTypeBound() != null) {
     printer.print(" extends ");
     for (Iterator<ClassOrInterfaceType> i = n.getTypeBound().iterator(); i.hasNext(); ) {
       ClassOrInterfaceType c = i.next();
       c.accept(this, arg);
       if (i.hasNext()) {
         printer.print(" & ");
       }
     }
   }
 }
Пример #5
0
  @Override
  public void visit(ClassOrInterfaceDeclaration n, Object arg) {
    printJavadoc(n.getJavaDoc(), arg);
    printMemberAnnotations(n.getAnnotations(), arg);
    printModifiers(n.getModifiers());

    if (n.isInterface()) {
      printer.print("interface ");
    } else {
      printer.print("class ");
    }

    printer.print(n.getName());

    printTypeParameters(n.getTypeParameters(), arg);

    if (n.getExtends() != null) {
      printer.print(" extends ");
      for (Iterator<ClassOrInterfaceType> i = n.getExtends().iterator(); i.hasNext(); ) {
        ClassOrInterfaceType c = i.next();
        c.accept(this, arg);
        if (i.hasNext()) {
          printer.print(", ");
        }
      }
    }

    if (n.getImplements() != null) {
      printer.print(" implements ");
      for (Iterator<ClassOrInterfaceType> i = n.getImplements().iterator(); i.hasNext(); ) {
        ClassOrInterfaceType c = i.next();
        c.accept(this, arg);
        if (i.hasNext()) {
          printer.print(", ");
        }
      }
    }

    printer.printLn(" {");
    printer.indent();
    if (n.getMembers() != null) {
      printMembers(n.getMembers(), arg);
    }
    printer.unindent();
    printer.print("}");
  }
Пример #6
0
  @Override
  public void visit(EnumDeclaration n, Object arg) {
    printJavadoc(n.getJavaDoc(), arg);
    printMemberAnnotations(n.getAnnotations(), arg);
    printModifiers(n.getModifiers());

    printer.print("enum ");
    printer.print(n.getName());

    if (n.getImplements() != null) {
      printer.print(" implements ");
      for (Iterator<ClassOrInterfaceType> i = n.getImplements().iterator(); i.hasNext(); ) {
        ClassOrInterfaceType c = i.next();
        c.accept(this, arg);
        if (i.hasNext()) {
          printer.print(", ");
        }
      }
    }

    printer.printLn(" {");
    printer.indent();
    if (n.getEntries() != null) {
      printer.printLn();
      for (Iterator<EnumConstantDeclaration> i = n.getEntries().iterator(); i.hasNext(); ) {
        EnumConstantDeclaration e = i.next();
        e.accept(this, arg);
        if (i.hasNext()) {
          printer.print(", ");
        }
      }
    }
    if (n.getMembers() != null) {
      printer.printLn(";");
      printMembers(n.getMembers(), arg);
    } else {
      if (n.getEntries() != null) {
        printer.printLn();
      }
    }
    printer.unindent();
    printer.print("}");
  }