Ejemplo n.º 1
0
 void changeTypeContext(ResolutionContext old, ResolutionContext new_, MethodDeclaration m) {
   m.setType(changeTypeContext(old, new_, m.getType()));
   m.setBody(
       new BlockStmt(
           Collections.singletonList(
               new ThrowStmt(
                   new ObjectCreationExpr(
                       null,
                       new ClassOrInterfaceType("UnsupportedOperationException"),
                       Collections.emptyList())))));
   NodeUtil.forChildren(
       m,
       node -> {
         Expression scope = node.getScope();
         // TODO: Currently guesses that it's a type name if first character is uppercase.
         // Should check for fields/variables which match instead
         if (scope instanceof NameExpr
             && Character.isUpperCase(((NameExpr) scope).getName().charAt(0))) {
           String name = ((NameExpr) scope).getName();
           node.setScope(ASTHelper.createNameExpr(new_.typeToString(old.resolve(name))));
         }
       },
       MethodCallExpr.class);
   NodeUtil.forChildren(
       m,
       node -> node.setType(changeTypeContext(old, new_, node.getType())),
       VariableDeclarationExpr.class);
   NodeUtil.forChildren(
       m, node -> node.setType(changeTypeContext(old, new_, node.getType())), TypeExpr.class);
   NodeUtil.forChildren(
       m,
       node -> node.setType(changeTypeContext(old, new_, node.getType())),
       com.github.javaparser.ast.body.Parameter.class);
 }
Ejemplo n.º 2
0
 static com.github.javaparser.ast.type.Type changeTypeContext(
     ResolutionContext old, ResolutionContext new_, com.github.javaparser.ast.type.Type t) {
   Type current = old.resolve(t);
   if (current.isClassType()) {
     return ResolutionContext.typeToJavaParserType(
         current.remapClassNames(new_::typeToJavaParserType));
   }
   return t;
 }
Ejemplo n.º 3
0
 private ResolutionContext getContextInternal() {
   return ResolutionContext.of(type.get());
 }
Ejemplo n.º 4
0
 private ResolutionContext getContext() {
   if (context != null) return context;
   return context = ResolutionContext.of(declaration);
 }