Esempio 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);
 }
Esempio n. 2
0
 @Override
 public void setTypeVariables(List<TypeVariable> typeVariables) {
   declaration.setTypeParameters(
       typeVariables
           .stream()
           .map(getContext()::unresolveTypeVariable)
           .collect(Collectors.toList()));
 }
Esempio n. 3
0
 @Override
 public List<TypeVariable> getTypeVariables() {
   return declaration
       .getTypeParameters()
       .stream()
       .map(getContext()::resolveTypeVariable)
       .collect(Collectors.toList());
 }
Esempio n. 4
0
  @Override
  public void add(MethodInfo method) {
    MethodDeclaration methodDeclaration;

    if (method instanceof MethodDeclarationWrapper) {
      val wrapper = (MethodDeclarationWrapper) method;
      methodDeclaration = (MethodDeclaration) wrapper.declaration.clone();
      methodDeclaration.setAnnotations(Collections.emptyList());
      wrapper
          .getClassInfo()
          .changeTypeContext(wrapper.getContext(), getContext(), methodDeclaration);
    } else {
      methodDeclaration = new MethodDeclaration();
      new MethodDeclarationWrapper(methodDeclaration).setAll(method);
    }

    addMember(methodDeclaration);
  }
Esempio n. 5
0
 @Override
 public List<Parameter> getParameters() {
   return declaration
       .getParameters()
       .stream()
       .map(
           (parameter) ->
               new Parameter(
                   getContext().resolve(parameter.getType()), parameter.getId().getName()))
       .collect(Collectors.toList());
 }
Esempio n. 6
0
 @Override
 public List<Annotation> getAnnotations() {
   return SourceInfo.this.getAnnotationsInternal(declaration.getAnnotations());
 }
Esempio n. 7
0
 @Override
 public void setAccessFlags(AccessFlags accessFlags) {
   declaration.setModifiers(accessFlags.access);
 }
Esempio n. 8
0
 @Override
 public AccessFlags getAccessFlags() {
   return new AccessFlags(declaration.getModifiers());
 }
Esempio n. 9
0
 @Override
 public void setName(String name) {
   declaration.setName(name);
 }
Esempio n. 10
0
 @Override
 public String getName() {
   return declaration.getName();
 }
Esempio n. 11
0
 @Override
 public void setReturnType(Type type) {
   declaration.setType(setType(type, declaration.getType()));
 }
Esempio n. 12
0
 @Override
 public Type getReturnType() {
   return getContext().resolve(declaration.getType());
 }