示例#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());
 }