/**
  * Determines if given method exists in a given list
  *
  * @param list list of method to search through
  * @param method method to find
  * @return declaration of method from the list that has the same name and parameter types, or null
  *     if not found
  */
 protected BodyDeclaration findMethodToReplace(
     final List<BodyDeclaration> list, MethodDeclaration method) {
   for (final Iterator<BodyDeclaration> iterator = list.iterator(); iterator.hasNext(); ) {
     final BodyDeclaration bodyDecl = iterator.next();
     if (bodyDecl instanceof MethodDeclaration) {
       final MethodDeclaration method2 = (MethodDeclaration) bodyDecl;
       if (method2.getName().getIdentifier().equals(method.getName().getIdentifier())
           && method2.parameters().size() == method.parameters().size()) {
         Iterator<SingleVariableDeclaration> iterator1 = method.parameters().iterator();
         Iterator<SingleVariableDeclaration> iterator2 = method2.parameters().iterator();
         boolean ok = true;
         while (iterator1.hasNext()) {
           if (!iterator1
               .next()
               .getType()
               .subtreeMatch(new ASTMatcher(), iterator2.next().getType())) {
             ok = false;
             break;
           }
         }
         if (ok) return method2;
       }
     }
   }
   return null;
 }
Ejemplo n.º 2
0
  public static MethodDescriptor fromMethodDeclaration(
      MethodDeclaration md, BinaryNameResolver resolver) {

    MethodDescriptor desc = new MethodDescriptor();

    for (Object fragment : md.parameters()) {

      SingleVariableDeclaration parameter = (SingleVariableDeclaration) fragment;

      Type t = parameter.getType();

      if (t.isPrimitiveType()) {
        PrimitiveType type = (PrimitiveType) t;
        desc.fParameters.add(DescriptorPart.fromPrimitiveType(type));
      } else if (t.isArrayType()) {
        ArrayType type = (ArrayType) t;
        desc.fParameters.add(DescriptorPart.fromArrayType(type, resolver));
      } else if (t.isSimpleType()) {
        SimpleType type = (SimpleType) t;
        desc.fParameters.add(DescriptorPart.fromSimpleType(type, resolver));
      } else if (t.isQualifiedType()) {
        /*
        QualifiedType type = (QualifiedType) t;
        System.out.println("DESCRIPTOR QUALIFIED");
        */
      } else if (t.isNameQualifiedType()) {
        /*
        NameQualifiedType type = (NameQualifiedType) t;
        System.out.println("DESCRIPTOR NAME_QUALIFIED");
        */
      }
    }

    return desc;
  }
Ejemplo n.º 3
0
  private void assertAllBindings(CompilationUnit astRoot) {
    List<AbstractTypeDeclaration> list = astRoot.types();
    for (int i = 0; i < list.size(); i++) {
      TypeDeclaration decl = (TypeDeclaration) list.get(i);
      assertTrue(decl.resolveBinding() != null);

      if (!decl.isInterface() && decl.getSuperclassType() != null) {
        assertTrue(decl.getSuperclassType().resolveBinding() != null);
      }
      List<Type> interfaces = decl.superInterfaceTypes();
      for (int j = 0; j < interfaces.size(); j++) {
        assertTrue(interfaces.get(j).resolveBinding() != null);
      }

      MethodDeclaration[] declarations = decl.getMethods();
      for (int k = 0; k < declarations.length; k++) {
        MethodDeclaration meth = declarations[k];
        assertTrue(meth.resolveBinding() != null);
        List<SingleVariableDeclaration> params = meth.parameters();
        for (int n = 0; n < params.size(); n++) {
          SingleVariableDeclaration arg = params.get(n);
          assertTrue(arg.resolveBinding() != null);
        }
        if (!meth.isConstructor()) {
          assertTrue(meth.getReturnType2().resolveBinding() != null);
        }
      }
    }
  }
  private MethodDecl getMethodDecl(MethodDeclaration node) {
    String qualifiedTypeName = currentPackage + "." + Joiner.on(".").skipNulls().join(typesInFile);
    SimpleName nameNode = node.getName();
    String methodName = nameNode.toString();
    String returnType = "";
    if (node.getReturnType2() != null) {
      returnType = getNameOfType(node.getReturnType2());
    }

    Map<String, String> params = new HashMap<>();
    for (Object p : node.parameters()) {
      String typeName = OBJECT_TYPE;
      if (p instanceof SingleVariableDeclaration) {

        SingleVariableDeclaration svd = (SingleVariableDeclaration) p;
        String varName = svd.getName().toString();
        Type type = svd.getType();
        typeName = getNameOfType(type);

        params.put(varName, typeName);
      } else {
        System.err.println("Unxepected AST node type for param - " + p);
      }
    }
    return new MethodDecl(
        methodName, qualifiedTypeName, returnType, nameNode.getStartPosition(), params);
  }
 public boolean visit(MethodDeclaration node) {
   if (null != m_methodFilter) {
     return node.getName().getIdentifier().equals(m_methodFilter.getElementName())
         && node.parameters().size() == m_methodFilter.getNumberOfParameters();
   } else {
     return true;
   }
 }
 /*
  * @see ASTVisitor#visit(MethodDeclaration)
  */
 public boolean visit(MethodDeclaration node) {
   if (node.getJavadoc() != null) {
     node.getJavadoc().accept(this);
   }
   if (node.getAST().apiLevel() >= AST.JLS3) {
     printModifiers(node.modifiers());
     if (!node.typeParameters().isEmpty()) {
       this.fBuffer.append("<"); // $NON-NLS-1$
       for (Iterator it = node.typeParameters().iterator(); it.hasNext(); ) {
         TypeParameter t = (TypeParameter) it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(", "); // $NON-NLS-1$
         }
       }
       this.fBuffer.append("> "); // $NON-NLS-1$
     }
   }
   if (!node.isConstructor()) {
     if (node.getReturnType2() != null) {
       node.getReturnType2().accept(this);
     } else {
       // methods really ought to have a return type
       this.fBuffer.append("void"); // $NON-NLS-1$
     }
     this.fBuffer.append(" "); // $NON-NLS-1$
   }
   node.getName().accept(this);
   this.fBuffer.append("("); // $NON-NLS-1$
   for (Iterator it = node.parameters().iterator(); it.hasNext(); ) {
     SingleVariableDeclaration v = (SingleVariableDeclaration) it.next();
     v.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(", "); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(")"); // $NON-NLS-1$
   for (int i = 0; i < node.getExtraDimensions(); i++) {
     this.fBuffer.append("[]"); // $NON-NLS-1$
   }
   if (!node.thrownExceptions().isEmpty()) {
     this.fBuffer.append(" throws "); // $NON-NLS-1$
     for (Iterator it = node.thrownExceptions().iterator(); it.hasNext(); ) {
       Name n = (Name) it.next();
       n.accept(this);
       if (it.hasNext()) {
         this.fBuffer.append(", "); // $NON-NLS-1$
       }
     }
     this.fBuffer.append(" "); // $NON-NLS-1$
   }
   if (node.getBody() == null) {
     this.fBuffer.append(";"); // $NON-NLS-1$
   } else {
     node.getBody().accept(this);
   }
   return false;
 }
  private ASTRewrite doAddParam(CompilationUnit cu) {
    AST ast = cu.getAST();
    SimpleName node = fOriginalNode;

    BodyDeclaration decl = ASTResolving.findParentBodyDeclaration(node);
    if (decl instanceof MethodDeclaration) {
      MethodDeclaration methodDeclaration = (MethodDeclaration) decl;

      ASTRewrite rewrite = ASTRewrite.create(ast);

      ImportRewrite imports = createImportRewrite((CompilationUnit) decl.getRoot());
      ImportRewriteContext importRewriteContext =
          new ContextSensitiveImportRewriteContext(decl, imports);

      SingleVariableDeclaration newDecl = ast.newSingleVariableDeclaration();
      newDecl.setType(
          evaluateVariableType(
              ast, imports, importRewriteContext, methodDeclaration.resolveBinding()));
      newDecl.setName(ast.newSimpleName(node.getIdentifier()));

      ListRewrite listRewriter =
          rewrite.getListRewrite(decl, MethodDeclaration.PARAMETERS_PROPERTY);
      listRewriter.insertLast(newDecl, null);

      addLinkedPosition(rewrite.track(node), true, KEY_NAME);

      // add javadoc tag
      Javadoc javadoc = methodDeclaration.getJavadoc();
      if (javadoc != null) {
        HashSet<String> leadingNames = new HashSet<String>();
        for (Iterator<SingleVariableDeclaration> iter = methodDeclaration.parameters().iterator();
            iter.hasNext(); ) {
          SingleVariableDeclaration curr = iter.next();
          leadingNames.add(curr.getName().getIdentifier());
        }
        SimpleName newTagRef = ast.newSimpleName(node.getIdentifier());

        TagElement newTagElement = ast.newTagElement();
        newTagElement.setTagName(TagElement.TAG_PARAM);
        newTagElement.fragments().add(newTagRef);
        TextElement commentStart = ast.newTextElement();
        newTagElement.fragments().add(commentStart);

        addLinkedPosition(rewrite.track(newTagRef), false, KEY_NAME);
        addLinkedPosition(rewrite.track(commentStart), false, "comment_start"); // $NON-NLS-1$

        ListRewrite tagsRewriter = rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);
        JavadocTagsSubProcessor.insertTag(tagsRewriter, newTagElement, leadingNames);
      }

      addLinkedPosition(rewrite.track(newDecl.getType()), false, KEY_TYPE);
      addLinkedPosition(rewrite.track(newDecl.getName()), false, KEY_NAME);

      return rewrite;
    }
    return null;
  }
Ejemplo n.º 8
0
 @Override
 public boolean visit(MethodDeclaration node) {
   for (Object param : node.parameters()) {
     SingleVariableDeclaration arg = (SingleVariableDeclaration) param;
     String name = arg.getName().getFullyQualifiedName();
     String typName = arg.getType().toString();
     map.put(name, typName);
   }
   return true;
 }
Ejemplo n.º 9
0
 @Override
 public boolean visit(MethodDeclaration node) {
   methods.add(
       new OutlineMethod(
           node.getName().toString(),
           node.getReturnType2(),
           node.isConstructor(),
           node.getModifiers(),
           node.parameters(),
           clazz));
   return super.visit(node);
 }
  public GenericBuilderAdapterBuilder(LanguageGenerator generator) {
    super(generator);

    addClassDeclaration(
        generator.genericBuilderAdapterName(), GenericIdentityBuilder.class.getName());

    addBodyDeclaration(
        newFieldDeclaration(generator.specificBuilderInterfaceName(), "specificBuilder"));

    // costructors
    MethodDeclaration constructor = addConstructorDeclaration();
    constructor
        .parameters()
        .add(
            newSingleVariableDeclaration(
                generator.specificBuilderInterfaceName(), "specificBuilder"));
    addStatement(
        constructor,
        newAssignment(
            newFieldAccess(ast.newThisExpression(), "specificBuilder"),
            ast.newSimpleName("specificBuilder")));

    constructor = addConstructorDeclaration();
    constructor
        .parameters()
        .add(
            newSingleVariableDeclaration(
                generator.specificBuilderInterfaceName(), "specificBuilder"));
    constructor
        .parameters()
        .add(newSingleVariableDeclaration(IEntityContext.class.getName(), "entityContext"));
    addStatement(constructor, newConstructorInvocation(ast.newSimpleName("specificBuilder")));
    addStatement(
        constructor, newMethodInvocation("wSetEntityContext", ast.newSimpleName("entityContext")));

    // generic visit
    addBodyDeclaration(newMethodDeclaration("void", "visit"));
  }
 private String getSignature(MethodDeclaration node) {
   StringBuffer buffer = new StringBuffer();
   buffer.append(node.getName().toString());
   buffer.append('(');
   boolean first = true;
   Iterator iterator = node.parameters().iterator();
   while (iterator.hasNext()) {
     Object parameterDecl = iterator.next();
     if (parameterDecl instanceof SingleVariableDeclaration) {
       SingleVariableDeclaration svd = (SingleVariableDeclaration) parameterDecl;
       if (!first) buffer.append(", "); // $NON-NLS-1$
       buffer.append(getType(svd.getType()));
       if (svd.isVarargs()) buffer.append("..."); // $NON-NLS-1$
       first = false;
     }
   }
   buffer.append(')');
   return buffer.toString();
 }
Ejemplo n.º 12
0
  /**
   * generate checks accordingly.
   *
   * @param node
   * @param binding
   * @param declTypeBinding
   */
  private void handleInheritedAbstractMethodImplementation(
      MethodDeclaration node, IMethodBinding methodBinding, List<MethodPathItem> inhMethods) {

    // add check for method name
    checks.add(
        new MethodImplementationNameCheck(
            file, jdtTypingProvider, bridge(node), methodBinding, inhMethods));

    // add checks for parameters
    List parameterList = node.parameters();

    for (int j = 0; j < parameterList.size(); j++) {

      checks.add(
          new MethodImplementationParameterCheck(
              file,
              jdtTypingProvider,
              bridge((SingleVariableDeclaration) parameterList.get(j)),
              methodBinding,
              j,
              inhMethods));
    }

    // add checks for exceptions
    List exceptionList = node.thrownExceptions();
    Name curExcNode;
    for (int i = 0; i < exceptionList.size(); i++) {

      curExcNode = (Name) exceptionList.get(i);
      ITypeBinding curExcBinding = curExcNode.resolveTypeBinding();

      if (curExcBinding == null) continue;

      checks.add(
          new MethodImplementationExceptionCheck(
              file,
              jdtTypingProvider,
              bridge(curExcNode),
              methodBinding,
              curExcBinding.getKey(),
              inhMethods));
    }
  }
  @SuppressWarnings("unchecked")
  public boolean doesMethodTakeTypes(MethodDeclaration methodDecl, List<Type> types) {
    List parameters = methodDecl.parameters();
    if (parameters.size() == types.size()) {
      boolean typesEqual = true;

      for (int i = 0; i < parameters.size(); i++) {
        SingleVariableDeclaration param = (SingleVariableDeclaration) parameters.get(i);
        assert param != null;

        if (!param.getType().toString().equals(types.get(i).toString())) {
          typesEqual = false;
          break;
        }
      }

      if (typesEqual) return true;
    }

    return false;
  }
Ejemplo n.º 14
0
  private void handleOverridingRelationshipViolation(
      MethodDeclaration node, IMethodBinding methodBinding, List<MethodPathItem> inhMethods) {

    // get first overridden item
    MethodPathItem superItem = OverridingRelationUtils.getFirstNonAbstractItem(inhMethods);

    if (superItem == null) return;

    // add check for method name and params
    checks.add(
        new InheritedMethodCheck(
            file,
            jdtTypingProvider,
            bridge(node),
            OverridingRelationUtils.getIASTNodeList(node.parameters()),
            methodBinding.getName(),
            superItem));

    // get all keys of method exceptions in super classes which are cast
    // compatible to exceptions of "node"
    // the list should contain at least one overridden exception key
    List exceptionList = node.thrownExceptions();
    Name curExcNode;
    for (int i = 0; i < exceptionList.size(); i++) {

      curExcNode = (Name) exceptionList.get(i);
      ITypeBinding curExcBinding = curExcNode.resolveTypeBinding();

      if (curExcBinding == null) continue;

      checks.add(
          new InheritedMethodExceptionCheck(
              file,
              jdtTypingProvider,
              bridge(curExcNode),
              curExcBinding.getName(),
              superItem.getInheritedExceptionKeys(methodBinding).get(curExcBinding.getKey())));
    }
  }
Ejemplo n.º 15
0
  private static boolean gatherMethod(
      HashMap<String, ArrayList<FixTypes>> ret,
      TypeDeclaration cls,
      String name,
      String args,
      String newName) {
    if (cls == null) {
      return false;
    }
    for (MethodDeclaration mtd : cls.getMethods()) {
      if (mtd.getName().toString().equals(name)) {
        String[] pts = (args.length() > 0 ? args.split(", ") : new String[0]);
        List<SingleVariableDeclaration> pars = mtd.parameters();
        if (pars.size() == pts.length) {
          boolean same = true;
          for (int x = 0; x < pts.length; x++) {
            String clean = ClassTree.cleanType(pars.get(x).getType()).replace('/', '.');
            if (!clean.equals(pts[x])) {
              same = false;
              break;
            }
          }
          if (same) {
            Type retType = mtd.getReturnType2();

            String clsName = cls.resolveBinding().getQualifiedName().replace('.', '/');
            if (!ret.containsKey(clsName)) ret.put(clsName, new ArrayList<FixTypes>());

            ret.get(clsName)
                .add(new FixTypes.BounceMethod(cls, newName, name, pts, retType.toString()));
            return true;
          }
        }
      }
    }
    return false;
  }
  /*
   * @see ASTVisitor#visit(MethodDeclaration)
   */
  @Override
  public boolean visit(MethodDeclaration node) {
    if (!isAffected(node)) {
      return false;
    }
    doVisitNode(node.getJavadoc());

    doVisitChildren(node.modifiers());
    doVisitChildren(node.typeParameters());

    if (!node.isConstructor()) {
      doVisitNode(node.getReturnType2());
    }
    // name not visited

    int apiLevel = node.getAST().apiLevel();
    if (apiLevel >= AST.JLS8) {
      doVisitNode(node.getReceiverType());
    }
    // receiverQualifier not visited:
    //   Enclosing class names cannot be shadowed by an import (qualification is always redundant).
    doVisitChildren(node.parameters());
    if (apiLevel >= AST.JLS8) {
      doVisitChildren(node.extraDimensions());
      doVisitChildren(node.thrownExceptionTypes());
    } else {
      Iterator<Name> iter = getThrownExceptions(node).iterator();
      while (iter.hasNext()) {
        typeRefFound(iter.next());
      }
    }
    if (!fSkipMethodBodies) {
      doVisitNode(node.getBody());
    }
    return false;
  }
 /*
  * @see ASTVisitor#visit(MethodDeclaration)
  */
 @Override
 public boolean visit(MethodDeclaration node) {
   if (node.getJavadoc() != null) {
     node.getJavadoc().accept(this);
   }
   if (node.getAST().apiLevel() >= JLS3) {
     printModifiers(node.modifiers());
     if (!node.typeParameters().isEmpty()) {
       this.fBuffer.append("<"); // $NON-NLS-1$
       for (Iterator<TypeParameter> it = node.typeParameters().iterator(); it.hasNext(); ) {
         TypeParameter t = it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(", "); // $NON-NLS-1$
         }
       }
       this.fBuffer.append("> "); // $NON-NLS-1$
     }
   }
   if (!node.isConstructor()) {
     if (node.getReturnType2() != null) {
       node.getReturnType2().accept(this);
     } else {
       // methods really ought to have a return type
       this.fBuffer.append("void"); // $NON-NLS-1$
     }
     this.fBuffer.append(" "); // $NON-NLS-1$
   }
   node.getName().accept(this);
   this.fBuffer.append("("); // $NON-NLS-1$
   if (node.getAST().apiLevel() >= AST.JLS8) {
     Type receiverType = node.getReceiverType();
     if (receiverType != null) {
       receiverType.accept(this);
       this.fBuffer.append(' ');
       SimpleName qualifier = node.getReceiverQualifier();
       if (qualifier != null) {
         qualifier.accept(this);
         this.fBuffer.append('.');
       }
       this.fBuffer.append("this"); // $NON-NLS-1$
       if (node.parameters().size() > 0) {
         this.fBuffer.append(',');
       }
     }
   }
   for (Iterator<SingleVariableDeclaration> it = node.parameters().iterator(); it.hasNext(); ) {
     SingleVariableDeclaration v = it.next();
     v.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(", "); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(")"); // $NON-NLS-1$
   if (node.getAST().apiLevel() >= AST.JLS8) {
     List<Dimension> dimensions = node.extraDimensions();
     for (Iterator<Dimension> it = dimensions.iterator(); it.hasNext(); ) {
       Dimension e = it.next();
       e.accept(this);
     }
   } else {
     for (int i = 0; i < node.getExtraDimensions(); i++) {
       this.fBuffer.append("[]"); // $NON-NLS-1$
     }
   }
   List<? extends ASTNode> thrownExceptions =
       node.getAST().apiLevel() >= AST.JLS8
           ? node.thrownExceptionTypes()
           : getThrownExceptions(node);
   if (!thrownExceptions.isEmpty()) {
     this.fBuffer.append(" throws "); // $NON-NLS-1$
     for (Iterator<? extends ASTNode> it = thrownExceptions.iterator(); it.hasNext(); ) {
       ASTNode n = it.next();
       n.accept(this);
       if (it.hasNext()) {
         this.fBuffer.append(", "); // $NON-NLS-1$
       }
     }
     this.fBuffer.append(" "); // $NON-NLS-1$
   }
   if (node.getBody() == null) {
     this.fBuffer.append(";"); // $NON-NLS-1$
   } else {
     node.getBody().accept(this);
   }
   return false;
 }
Ejemplo n.º 18
0
  private List<ClassObject> parseAST(CompilationUnit compilationUnit, IFile iFile) {
    List<ClassObject> classObjects = new ArrayList<ClassObject>();
    List<AbstractTypeDeclaration> topLevelTypeDeclarations = compilationUnit.types();
    for (AbstractTypeDeclaration abstractTypeDeclaration : topLevelTypeDeclarations) {
      if (abstractTypeDeclaration instanceof TypeDeclaration) {
        TypeDeclaration topLevelTypeDeclaration = (TypeDeclaration) abstractTypeDeclaration;
        List<TypeDeclaration> typeDeclarations = new ArrayList<TypeDeclaration>();
        typeDeclarations.add(topLevelTypeDeclaration);
        typeDeclarations.addAll(getRecursivelyInnerTypes(topLevelTypeDeclaration));
        for (TypeDeclaration typeDeclaration : typeDeclarations) {
          final ClassObject classObject = new ClassObject();
          classObject.setIFile(iFile);
          classObject.setName(typeDeclaration.resolveBinding().getQualifiedName());
          classObject.setTypeDeclaration(typeDeclaration);

          if (typeDeclaration.isInterface()) {
            classObject.setInterface(true);
          }

          int modifiers = typeDeclaration.getModifiers();
          if ((modifiers & Modifier.ABSTRACT) != 0) classObject.setAbstract(true);

          if ((modifiers & Modifier.PUBLIC) != 0) classObject.setAccess(Access.PUBLIC);
          else if ((modifiers & Modifier.PROTECTED) != 0) classObject.setAccess(Access.PROTECTED);
          else if ((modifiers & Modifier.PRIVATE) != 0) classObject.setAccess(Access.PRIVATE);
          else classObject.setAccess(Access.NONE);

          if ((modifiers & Modifier.STATIC) != 0) classObject.setStatic(true);

          Type superclassType = typeDeclaration.getSuperclassType();
          if (superclassType != null) {
            ITypeBinding binding = superclassType.resolveBinding();
            String qualifiedName = binding.getQualifiedName();
            TypeObject typeObject = TypeObject.extractTypeObject(qualifiedName);
            classObject.setSuperclass(typeObject);
          }

          List<Type> superInterfaceTypes = typeDeclaration.superInterfaceTypes();
          for (Type interfaceType : superInterfaceTypes) {
            ITypeBinding binding = interfaceType.resolveBinding();
            String qualifiedName = binding.getQualifiedName();
            TypeObject typeObject = TypeObject.extractTypeObject(qualifiedName);
            classObject.addInterface(typeObject);
          }

          FieldDeclaration[] fieldDeclarations = typeDeclaration.getFields();
          for (FieldDeclaration fieldDeclaration : fieldDeclarations) {
            Type fieldType = fieldDeclaration.getType();
            ITypeBinding binding = fieldType.resolveBinding();
            List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
            for (VariableDeclarationFragment fragment : fragments) {
              String qualifiedName = binding.getQualifiedName();
              TypeObject typeObject = TypeObject.extractTypeObject(qualifiedName);
              typeObject.setArrayDimension(
                  typeObject.getArrayDimension() + fragment.getExtraDimensions());
              FieldObject fieldObject =
                  new FieldObject(typeObject, fragment.getName().getIdentifier());
              fieldObject.setClassName(classObject.getName());
              fieldObject.setVariableDeclarationFragment(fragment);

              int fieldModifiers = fieldDeclaration.getModifiers();
              if ((fieldModifiers & Modifier.PUBLIC) != 0) fieldObject.setAccess(Access.PUBLIC);
              else if ((fieldModifiers & Modifier.PROTECTED) != 0)
                fieldObject.setAccess(Access.PROTECTED);
              else if ((fieldModifiers & Modifier.PRIVATE) != 0)
                fieldObject.setAccess(Access.PRIVATE);
              else fieldObject.setAccess(Access.NONE);

              if ((fieldModifiers & Modifier.STATIC) != 0) fieldObject.setStatic(true);

              classObject.addField(fieldObject);
            }
          }

          MethodDeclaration[] methodDeclarations = typeDeclaration.getMethods();
          for (MethodDeclaration methodDeclaration : methodDeclarations) {
            String methodName = methodDeclaration.getName().getIdentifier();
            final ConstructorObject constructorObject = new ConstructorObject();
            constructorObject.setMethodDeclaration(methodDeclaration);
            constructorObject.setName(methodName);
            constructorObject.setClassName(classObject.getName());

            int methodModifiers = methodDeclaration.getModifiers();
            if ((methodModifiers & Modifier.PUBLIC) != 0)
              constructorObject.setAccess(Access.PUBLIC);
            else if ((methodModifiers & Modifier.PROTECTED) != 0)
              constructorObject.setAccess(Access.PROTECTED);
            else if ((methodModifiers & Modifier.PRIVATE) != 0)
              constructorObject.setAccess(Access.PRIVATE);
            else constructorObject.setAccess(Access.NONE);

            List<SingleVariableDeclaration> parameters = methodDeclaration.parameters();
            for (SingleVariableDeclaration parameter : parameters) {
              Type parameterType = parameter.getType();
              ITypeBinding binding = parameterType.resolveBinding();
              String qualifiedName = binding.getQualifiedName();
              TypeObject typeObject = TypeObject.extractTypeObject(qualifiedName);
              typeObject.setArrayDimension(
                  typeObject.getArrayDimension() + parameter.getExtraDimensions());
              if (parameter.isVarargs()) {
                typeObject.setArrayDimension(1);
              }
              ParameterObject parameterObject =
                  new ParameterObject(typeObject, parameter.getName().getIdentifier());
              parameterObject.setSingleVariableDeclaration(parameter);
              constructorObject.addParameter(parameterObject);
            }

            Block methodBody = methodDeclaration.getBody();
            if (methodBody != null) {
              MethodBodyObject methodBodyObject = new MethodBodyObject(methodBody);
              constructorObject.setMethodBody(methodBodyObject);
            }

            if (methodDeclaration.isConstructor()) {
              classObject.addConstructor(constructorObject);
            } else {
              MethodObject methodObject = new MethodObject(constructorObject);
              List<IExtendedModifier> extendedModifiers = methodDeclaration.modifiers();
              for (IExtendedModifier extendedModifier : extendedModifiers) {
                if (extendedModifier.isAnnotation()) {
                  Annotation annotation = (Annotation) extendedModifier;
                  if (annotation.getTypeName().getFullyQualifiedName().equals("Test")) {
                    methodObject.setTestAnnotation(true);
                    break;
                  }
                }
              }
              Type returnType = methodDeclaration.getReturnType2();
              ITypeBinding binding = returnType.resolveBinding();
              String qualifiedName = binding.getQualifiedName();
              TypeObject typeObject = TypeObject.extractTypeObject(qualifiedName);
              methodObject.setReturnType(typeObject);

              if ((methodModifiers & Modifier.ABSTRACT) != 0) methodObject.setAbstract(true);
              if ((methodModifiers & Modifier.STATIC) != 0) methodObject.setStatic(true);
              if ((methodModifiers & Modifier.SYNCHRONIZED) != 0)
                methodObject.setSynchronized(true);
              if ((methodModifiers & Modifier.NATIVE) != 0) methodObject.setNative(true);

              classObject.addMethod(methodObject);
              FieldInstructionObject fieldInstruction = methodObject.isGetter();
              if (fieldInstruction != null)
                systemObject.addGetter(methodObject.generateMethodInvocation(), fieldInstruction);
              fieldInstruction = methodObject.isSetter();
              if (fieldInstruction != null)
                systemObject.addSetter(methodObject.generateMethodInvocation(), fieldInstruction);
              fieldInstruction = methodObject.isCollectionAdder();
              if (fieldInstruction != null)
                systemObject.addCollectionAdder(
                    methodObject.generateMethodInvocation(), fieldInstruction);
              MethodInvocationObject methodInvocation = methodObject.isDelegate();
              if (methodInvocation != null)
                systemObject.addDelegate(methodObject.generateMethodInvocation(), methodInvocation);
            }
          }
          classObjects.add(classObject);
        }
      }
    }
    return classObjects;
  }
    private void insertMissingJavadocTag(
        ASTRewrite rewrite, ASTNode missingNode, BodyDeclaration bodyDecl) {
      AST ast = bodyDecl.getAST();
      Javadoc javadoc = bodyDecl.getJavadoc();
      if (javadoc == null) {
        javadoc = ast.newJavadoc();
        rewrite.set(bodyDecl, bodyDecl.getJavadocProperty(), javadoc, null);
      }

      ListRewrite tagsRewriter = rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);

      StructuralPropertyDescriptor location = missingNode.getLocationInParent();
      TagElement newTag;
      if (location == SingleVariableDeclaration.NAME_PROPERTY) {
        // normal parameter
        SingleVariableDeclaration decl = (SingleVariableDeclaration) missingNode.getParent();

        String name = ((SimpleName) missingNode).getIdentifier();
        newTag = ast.newTagElement();
        newTag.setTagName(TagElement.TAG_PARAM);
        newTag.fragments().add(ast.newSimpleName(name));

        MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDecl;
        List<SingleVariableDeclaration> params = methodDeclaration.parameters();

        Set<String> sameKindLeadingNames = getPreviousParamNames(params, decl);

        List<TypeParameter> typeParams = methodDeclaration.typeParameters();
        for (int i = 0; i < typeParams.size(); i++) {
          String curr = '<' + typeParams.get(i).getName().getIdentifier() + '>';
          sameKindLeadingNames.add(curr);
        }
        insertTag(tagsRewriter, newTag, sameKindLeadingNames);
      } else if (location == TypeParameter.NAME_PROPERTY) {
        // type parameter
        TypeParameter typeParam = (TypeParameter) missingNode.getParent();

        String name = '<' + ((SimpleName) missingNode).getIdentifier() + '>';
        newTag = ast.newTagElement();
        newTag.setTagName(TagElement.TAG_PARAM);
        TextElement text = ast.newTextElement();
        text.setText(name);
        newTag.fragments().add(text);
        List<TypeParameter> params;
        if (bodyDecl instanceof TypeDeclaration) {
          params = ((TypeDeclaration) bodyDecl).typeParameters();
        } else {
          params = ((MethodDeclaration) bodyDecl).typeParameters();
        }
        insertTag(tagsRewriter, newTag, getPreviousTypeParamNames(params, typeParam));
      } else if (location == MethodDeclaration.RETURN_TYPE2_PROPERTY) {
        newTag = ast.newTagElement();
        newTag.setTagName(TagElement.TAG_RETURN);
        insertTag(tagsRewriter, newTag, null);
      } else if (location == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
        newTag = ast.newTagElement();
        newTag.setTagName(TagElement.TAG_THROWS);
        TextElement excNode = ast.newTextElement();
        excNode.setText(ASTNodes.getQualifiedTypeName((Type) missingNode));
        newTag.fragments().add(excNode);
        List<Type> exceptions = ((MethodDeclaration) bodyDecl).thrownExceptionTypes();
        insertTag(tagsRewriter, newTag, getPreviousExceptionNames(exceptions, missingNode));
      } else {
        Assert.isTrue(
            false, "AddMissingJavadocTagProposal: unexpected node location"); // $NON-NLS-1$
        return;
      }

      TextElement textElement = ast.newTextElement();
      textElement.setText(""); // $NON-NLS-1$
      newTag.fragments().add(textElement);

      addLinkedPosition(rewrite.track(textElement), false, "comment_start"); // $NON-NLS-1$

      if (bodyDecl.getJavadoc() == null) {
        // otherwise the linked position spans over a line delimiter
        newTag.fragments().add(ast.newTextElement());
      }
    }
    private void insertAllMissingMethodTags(ASTRewrite rewriter, MethodDeclaration methodDecl) {
      AST ast = methodDecl.getAST();
      Javadoc javadoc = methodDecl.getJavadoc();
      ListRewrite tagsRewriter = rewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);

      List<TypeParameter> typeParams = methodDecl.typeParameters();
      ASTNode root = methodDecl.getRoot();
      if (root instanceof CompilationUnit) {
        ITypeRoot typeRoot = ((CompilationUnit) root).getTypeRoot();
        if (typeRoot != null
            && !StubUtility.shouldGenerateMethodTypeParameterTags(typeRoot.getJavaProject()))
          typeParams = Collections.emptyList();
      }
      List<String> typeParamNames = new ArrayList<>();
      for (int i = typeParams.size() - 1; i >= 0; i--) {
        TypeParameter decl = typeParams.get(i);
        String name = '<' + decl.getName().getIdentifier() + '>';
        if (findTag(javadoc, TagElement.TAG_PARAM, name) == null) {
          TagElement newTag = ast.newTagElement();
          newTag.setTagName(TagElement.TAG_PARAM);
          TextElement text = ast.newTextElement();
          text.setText(name);
          newTag.fragments().add(text);
          insertTabStop(rewriter, newTag.fragments(), "typeParam" + i); // $NON-NLS-1$
          insertTag(tagsRewriter, newTag, getPreviousTypeParamNames(typeParams, decl));
        }
        typeParamNames.add(name);
      }
      List<SingleVariableDeclaration> params = methodDecl.parameters();
      for (int i = params.size() - 1; i >= 0; i--) {
        SingleVariableDeclaration decl = params.get(i);
        String name = decl.getName().getIdentifier();
        if (findTag(javadoc, TagElement.TAG_PARAM, name) == null) {
          TagElement newTag = ast.newTagElement();
          newTag.setTagName(TagElement.TAG_PARAM);
          newTag.fragments().add(ast.newSimpleName(name));
          insertTabStop(rewriter, newTag.fragments(), "methParam" + i); // $NON-NLS-1$
          Set<String> sameKindLeadingNames = getPreviousParamNames(params, decl);
          sameKindLeadingNames.addAll(typeParamNames);
          insertTag(tagsRewriter, newTag, sameKindLeadingNames);
        }
      }
      if (!methodDecl.isConstructor()) {
        Type type = methodDecl.getReturnType2();
        if (!type.isPrimitiveType()
            || (((PrimitiveType) type).getPrimitiveTypeCode() != PrimitiveType.VOID)) {
          if (findTag(javadoc, TagElement.TAG_RETURN, null) == null) {
            TagElement newTag = ast.newTagElement();
            newTag.setTagName(TagElement.TAG_RETURN);
            insertTabStop(rewriter, newTag.fragments(), "return"); // $NON-NLS-1$
            insertTag(tagsRewriter, newTag, null);
          }
        }
      }
      List<Type> thrownExceptions = methodDecl.thrownExceptionTypes();
      for (int i = thrownExceptions.size() - 1; i >= 0; i--) {
        Type exception = thrownExceptions.get(i);
        ITypeBinding binding = exception.resolveBinding();
        if (binding != null) {
          String name = binding.getName();
          if (findThrowsTag(javadoc, name) == null) {
            TagElement newTag = ast.newTagElement();
            newTag.setTagName(TagElement.TAG_THROWS);
            TextElement excNode = ast.newTextElement();
            excNode.setText(ASTNodes.getQualifiedTypeName(exception));
            newTag.fragments().add(excNode);
            insertTabStop(rewriter, newTag.fragments(), "exception" + i); // $NON-NLS-1$
            insertTag(tagsRewriter, newTag, getPreviousExceptionNames(thrownExceptions, exception));
          }
        }
      }
    }