예제 #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);
 }
예제 #2
0
 @Override
 public void setTypeVariables(List<TypeVariable> typeVariables) {
   declaration.setTypeParameters(
       typeVariables
           .stream()
           .map(getContext()::unresolveTypeVariable)
           .collect(Collectors.toList()));
 }
예제 #3
0
 @Override
 public List<TypeVariable> getTypeVariables() {
   return declaration
       .getTypeParameters()
       .stream()
       .map(getContext()::resolveTypeVariable)
       .collect(Collectors.toList());
 }
예제 #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);
  }
예제 #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());
 }
예제 #6
0
 @Override
 public List<Annotation> getAnnotations() {
   return SourceInfo.this.getAnnotationsInternal(declaration.getAnnotations());
 }
예제 #7
0
 @Override
 public void setAccessFlags(AccessFlags accessFlags) {
   declaration.setModifiers(accessFlags.access);
 }
예제 #8
0
 @Override
 public AccessFlags getAccessFlags() {
   return new AccessFlags(declaration.getModifiers());
 }
예제 #9
0
 @Override
 public void setName(String name) {
   declaration.setName(name);
 }
예제 #10
0
 @Override
 public String getName() {
   return declaration.getName();
 }
예제 #11
0
 @Override
 public void setReturnType(Type type) {
   declaration.setType(setType(type, declaration.getType()));
 }
예제 #12
0
 @Override
 public Type getReturnType() {
   return getContext().resolve(declaration.getType());
 }