Java 类org.eclipse.jdt.core.dom.Javadoc 实例源码

项目:SparkBuilderGenerator    文件:EmptyBuilderClassGeneratorFragment.java   
public TypeDeclaration createBuilderClass(AST ast, TypeDeclaration originalType) {
    TypeDeclaration builderType = ast.newTypeDeclaration();
    builderType.setName(ast.newSimpleName(getBuilderName(originalType)));

    if (preferencesManager.getPreferenceValue(ADD_GENERATED_ANNOTATION)) {
        generatedAnnotationPopulator.addGeneratedAnnotation(ast, builderType);
    }
    builderType.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
    builderType.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
    builderType.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));

    if (preferencesManager.getPreferenceValue(GENERATE_JAVADOC_ON_BUILDER_CLASS)) {
        Javadoc javadoc = javadocGenerator.generateJavadoc(ast, String.format(Locale.ENGLISH, "Builder to build {@link %s}.", originalType.getName().toString()),
                Collections.emptyMap());
        builderType.setJavadoc(javadoc);
    }

    return builderType;
}
项目:eclipse.jdt.ls    文件:AbstractSerialVersionOperation.java   
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
    final ASTRewrite rewrite = cuRewrite.getASTRewrite();
    VariableDeclarationFragment fragment = null;
    for (int i = 0; i < fNodes.length; i++) {
        final ASTNode node = fNodes[i];

        final AST ast = node.getAST();

        fragment = ast.newVariableDeclarationFragment();
        fragment.setName(ast.newSimpleName(NAME_FIELD));

        final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
        declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
        declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

        if (!addInitializer(fragment, node)) {
            continue;
        }

        if (fragment.getInitializer() != null) {

            final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
            if (node instanceof AbstractTypeDeclaration) {
                rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
            } else if (node instanceof AnonymousClassDeclaration) {
                rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
            } else if (node instanceof ParameterizedType) {
                final ParameterizedType type = (ParameterizedType) node;
                final ASTNode parent = type.getParent();
                if (parent instanceof ClassInstanceCreation) {
                    final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
                    final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
                    if (anonymous != null) {
                        rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
                    }
                }
            } else {
                Assert.isTrue(false);
            }

            addLinkedPositions(rewrite, fragment, positionGroups);
        }

        final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
        if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
            final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
            declaration.setJavadoc(doc);
        }
    }
    if (fragment == null) {
        return;
    }

    positionGroups.setEndPosition(rewrite.track(fragment));
}
项目:eclipse.jdt.ls    文件:JavadocContentAccess.java   
/**
 * Gets a reader for an package fragment's Javadoc comment content from the source attachment.
 * The content does contain only the text from the comment without the Javadoc leading star characters.
 * Returns <code>null</code> if the package fragment does not contain a Javadoc comment or if no source is available.
 * @param fragment The package fragment to get the Javadoc of.
 * @return Returns a reader for the Javadoc comment content or <code>null</code> if the member
 * does not contain a Javadoc comment or if no source is available
 * @throws JavaModelException is thrown when the package fragment's javadoc can not be accessed
 * @since 3.4
 */
private static Reader internalGetContentReader(IPackageFragment fragment) throws JavaModelException {
    IPackageFragmentRoot root= (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);

    //1==> Handle the case when the documentation is present in package-info.java or package-info.class file
    boolean isBinary= root.getKind() == IPackageFragmentRoot.K_BINARY;
    ITypeRoot packageInfo;
    if (isBinary) {
        packageInfo= fragment.getClassFile(PACKAGE_INFO_CLASS);
    } else {
        packageInfo= fragment.getCompilationUnit(PACKAGE_INFO_JAVA);
    }
    if (packageInfo != null && packageInfo.exists()) {
        String source = packageInfo.getSource();
        //the source can be null for some of the class files
        if (source != null) {
            Javadoc javadocNode = getPackageJavadocNode(fragment, source);
            if (javadocNode != null) {
                int start = javadocNode.getStartPosition();
                int length = javadocNode.getLength();
                return new JavaDocCommentReader(source, start, start + length - 1);
            }
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:SimilarElementsRequestor.java   
private static ICompilationUnit createPreparedCU(ICompilationUnit cu, Javadoc comment, int wordStart) throws JavaModelException {
    int startpos= comment.getStartPosition();
    boolean isTopLevel= comment.getParent().getParent() instanceof CompilationUnit;
    char[] content= cu.getBuffer().getCharacters().clone();
    if (isTopLevel && (wordStart + 6 < content.length)) {
        content[startpos++]= 'i'; content[startpos++]= 'm'; content[startpos++]= 'p';
        content[startpos++]= 'o'; content[startpos++]= 'r'; content[startpos++]= 't';
    }
    if (wordStart < content.length) {
        for (int i= startpos; i < wordStart; i++) {
            content[i]= ' ';
        }
    }

    /*
     * Explicitly create a new non-shared working copy.
     */
    ICompilationUnit newCU= cu.getWorkingCopy(null);
    newCU.getBuffer().setContents(content);
    return newCU;
}
项目:eclipse.jdt.ls    文件:SelfEncapsulateFieldProposal.java   
private void addNewJavadoc(ASTRewrite rewrite, MethodDeclaration decl, ImportRewriteContext context) throws CoreException {
    IType parentType = fField.getDeclaringType();

    String typeName = Signature.toString(fField.getTypeSignature());
    String accessorName = StubUtility.getBaseName(fField);
    String lineDelim = "\n";

    String comment = null;
    String name = getFunctionName();
    if (isGetter) {
        comment = CodeGeneration.getGetterComment(fField.getCompilationUnit(), parentType.getTypeQualifiedName('.'), name, fField.getElementName(), typeName, accessorName, lineDelim);
    } else {
        String argname = getArgumentName();
        comment = CodeGeneration.getSetterComment(fField.getCompilationUnit(), parentType.getTypeQualifiedName('.'), name, fField.getElementName(), typeName, argname, accessorName, lineDelim);
    }
    comment = comment.substring(0, comment.lastIndexOf(lineDelim));

    if (comment != null) {
        Javadoc javadoc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
        decl.setJavadoc(javadoc);
    }
}
项目:eclipse.jdt.ls    文件:JavadocTagsSubProcessor.java   
private void insertAllMissingTypeTags(ASTRewrite rewriter, TypeDeclaration typeDecl) {
    AST ast= typeDecl.getAST();
    Javadoc javadoc= typeDecl.getJavadoc();
    ListRewrite tagsRewriter= rewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);

    List<TypeParameter> typeParams= typeDecl.typeParameters();
    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));
        }
    }
}
项目:eclipse.jdt.ls    文件:JavadocTagsSubProcessor.java   
public static TagElement findTag(Javadoc javadoc, String name, String arg) {
    List<TagElement> tags= javadoc.tags();
    int nTags= tags.size();
    for (int i= 0; i < nTags; i++) {
        TagElement curr= tags.get(i);
        if (name.equals(curr.getTagName())) {
            if (arg != null) {
                String argument= getArgument(curr);
                if (arg.equals(argument)) {
                    return curr;
                }
            } else {
                return curr;
            }
        }
    }
    return null;
}
项目:che    文件:AbstractSerialVersionOperation.java   
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups)
    throws CoreException {
  final ASTRewrite rewrite = cuRewrite.getASTRewrite();
  VariableDeclarationFragment fragment = null;
  for (int i = 0; i < fNodes.length; i++) {
    final ASTNode node = fNodes[i];

    final AST ast = node.getAST();

    fragment = ast.newVariableDeclarationFragment();
    fragment.setName(ast.newSimpleName(NAME_FIELD));

    final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
    declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
    declaration
        .modifiers()
        .addAll(
            ASTNodeFactory.newModifiers(
                ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

    if (!addInitializer(fragment, node)) continue;

    if (fragment.getInitializer() != null) {

      final TextEditGroup editGroup =
          createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
      if (node instanceof AbstractTypeDeclaration)
        rewrite
            .getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty())
            .insertAt(declaration, 0, editGroup);
      else if (node instanceof AnonymousClassDeclaration)
        rewrite
            .getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY)
            .insertAt(declaration, 0, editGroup);
      else if (node instanceof ParameterizedType) {
        final ParameterizedType type = (ParameterizedType) node;
        final ASTNode parent = type.getParent();
        if (parent instanceof ClassInstanceCreation) {
          final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
          final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
          if (anonymous != null)
            rewrite
                .getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY)
                .insertAt(declaration, 0, editGroup);
        }
      } else Assert.isTrue(false);

      addLinkedPositions(rewrite, fragment, positionGroups);
    }

    final String comment =
        CodeGeneration.getFieldComment(
            fUnit,
            declaration.getType().toString(),
            NAME_FIELD,
            StubUtility.getLineDelimiterUsed(fUnit));
    if (comment != null && comment.length() > 0) {
      final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
      declaration.setJavadoc(doc);
    }
  }
  if (fragment == null) return;

  positionGroups.setEndPosition(rewrite.track(fragment));
}
项目:che    文件:ConvertAnonymousToNestedRefactoring.java   
private void createFieldsForAccessedLocals(
    CompilationUnitRewrite rewrite,
    IVariableBinding[] varBindings,
    String[] fieldNames,
    List<BodyDeclaration> newBodyDeclarations)
    throws CoreException {
  final ImportRewrite importRewrite = rewrite.getImportRewrite();
  final ASTRewrite astRewrite = rewrite.getASTRewrite();
  final AST ast = astRewrite.getAST();

  for (int i = 0; i < varBindings.length; i++) {
    VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
    fragment.setInitializer(null);
    fragment.setName(ast.newSimpleName(fieldNames[i]));
    FieldDeclaration field = ast.newFieldDeclaration(fragment);
    ITypeBinding varType = varBindings[i].getType();
    field.setType(importRewrite.addImport(varType, ast));
    field.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.FINAL));
    if (doAddComments()) {
      String string =
          CodeGeneration.getFieldComment(
              rewrite.getCu(),
              varType.getName(),
              fieldNames[i],
              StubUtility.getLineDelimiterUsed(fCu));
      if (string != null) {
        Javadoc javadoc = (Javadoc) astRewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
        field.setJavadoc(javadoc);
      }
    }

    newBodyDeclarations.add(field);

    addLinkedPosition(KEY_FIELD_NAME_EXT + i, fragment.getName(), astRewrite, false);
  }
}
项目:che    文件:PromoteTempToFieldRefactoring.java   
private Javadoc getNewConstructorComment(ASTRewrite rewrite) throws CoreException {
  if (StubUtility.doAddComments(fCu.getJavaProject())) {
    String comment =
        CodeGeneration.getMethodComment(
            fCu,
            getEnclosingTypeName(),
            getEnclosingTypeName(),
            new String[0],
            new String[0],
            null,
            null,
            StubUtility.getLineDelimiterUsed(fCu));
    if (comment != null && comment.length() > 0) {
      return (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
    }
  }
  return null;
}
项目:che    文件:ExtractMethodRefactoring.java   
private MethodDeclaration createNewMethod(
    ASTNode[] selectedNodes, String lineDelimiter, TextEditGroup substitute)
    throws CoreException {
  MethodDeclaration result = createNewMethodDeclaration();
  result.setBody(createMethodBody(selectedNodes, substitute, result.getModifiers()));
  if (fGenerateJavadoc) {
    AbstractTypeDeclaration enclosingType =
        (AbstractTypeDeclaration)
            ASTNodes.getParent(
                fAnalyzer.getEnclosingBodyDeclaration(), AbstractTypeDeclaration.class);
    String string =
        CodeGeneration.getMethodComment(
            fCUnit, enclosingType.getName().getIdentifier(), result, null, lineDelimiter);
    if (string != null) {
      Javadoc javadoc = (Javadoc) fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
      result.setJavadoc(javadoc);
    }
  }
  return result;
}
项目:che    文件:JavadocUtil.java   
/**
 * Adds a "param" javadoc tag for a new last parameter if necessary.
 *
 * @param parameterName
 * @param methodDeclaration
 * @param astRewrite
 * @param javaProject
 * @param groupDescription
 */
public static void addParamJavadoc(
    String parameterName,
    MethodDeclaration methodDeclaration,
    ASTRewrite astRewrite,
    IJavaProject javaProject,
    TextEditGroup groupDescription) {
  if (!shouldAddParamJavadoc(methodDeclaration)) return;

  ListRewrite tagsRewrite =
      astRewrite.getListRewrite(methodDeclaration.getJavadoc(), Javadoc.TAGS_PROPERTY);
  HashSet<String> leadingNames = new HashSet<String>();
  for (Iterator<SingleVariableDeclaration> iter = methodDeclaration.parameters().iterator();
      iter.hasNext(); ) {
    SingleVariableDeclaration curr = iter.next();
    leadingNames.add(curr.getName().getIdentifier());
  }
  TagElement parameterTag = createParamTag(parameterName, astRewrite.getAST(), javaProject);
  JavadocTagsSubProcessor.insertTag(tagsRewrite, parameterTag, leadingNames, groupDescription);
}
项目:che    文件:JavadocTagsSubProcessor.java   
private void insertAllMissingTypeTags(ASTRewrite rewriter, TypeDeclaration typeDecl) {
  AST ast = typeDecl.getAST();
  Javadoc javadoc = typeDecl.getJavadoc();
  ListRewrite tagsRewriter = rewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);

  List<TypeParameter> typeParams = typeDecl.typeParameters();
  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));
    }
  }
}
项目:che    文件:JavadocTagsSubProcessor.java   
public static TagElement findTag(Javadoc javadoc, String name, String arg) {
  List<TagElement> tags = javadoc.tags();
  int nTags = tags.size();
  for (int i = 0; i < nTags; i++) {
    TagElement curr = tags.get(i);
    if (name.equals(curr.getTagName())) {
      if (arg != null) {
        String argument = getArgument(curr);
        if (arg.equals(argument)) {
          return curr;
        }
      } else {
        return curr;
      }
    }
  }
  return null;
}
项目:che    文件:SimilarElementsRequestor.java   
private static ICompilationUnit createPreparedCU(
    ICompilationUnit cu, Javadoc comment, int wordStart) throws JavaModelException {
  int startpos = comment.getStartPosition();
  boolean isTopLevel = comment.getParent().getParent() instanceof CompilationUnit;
  char[] content = cu.getBuffer().getCharacters().clone();
  if (isTopLevel && (wordStart + 6 < content.length)) {
    content[startpos++] = 'i';
    content[startpos++] = 'm';
    content[startpos++] = 'p';
    content[startpos++] = 'o';
    content[startpos++] = 'r';
    content[startpos++] = 't';
  }
  if (wordStart < content.length) {
    for (int i = startpos; i < wordStart; i++) {
      content[i] = ' ';
    }
  }

  /*
   * Explicitly create a new non-shared working copy.
   */
  ICompilationUnit newCU = cu.getWorkingCopy(null);
  newCU.getBuffer().setContents(content);
  return newCU;
}
项目:che    文件:JavadocContentAccess2.java   
private static String getHTMLContentFromAttachedSource(
    IPackageFragmentRoot root, IPackageFragment packageFragment, String urlPrefix)
    throws CoreException {
  String filePath =
      packageFragment.getElementName().replace('.', '/') + '/' + JavaModelUtil.PACKAGE_INFO_JAVA;
  String contents = getFileContentFromAttachedSource(root, filePath);
  if (contents != null) {
    Javadoc packageJavadocNode = getPackageJavadocNode(packageFragment, contents);
    if (packageJavadocNode != null)
      return new JavadocContentAccess2(packageFragment, packageJavadocNode, contents, urlPrefix)
          .toHTML();
  }
  filePath =
      packageFragment.getElementName().replace('.', '/') + '/' + JavaModelUtil.PACKAGE_HTML;
  return getFileContentFromAttachedSource(root, filePath);
}
项目:Eclipse-Postfix-Code-Completion    文件:MoveInnerToTopRefactoring.java   
private void addEnclosingInstanceDeclaration(final AbstractTypeDeclaration declaration, final ASTRewrite rewrite) throws CoreException {
    Assert.isNotNull(declaration);
    Assert.isNotNull(rewrite);
    final AST ast= declaration.getAST();
    final VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
    fragment.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
    final FieldDeclaration newField= ast.newFieldDeclaration(fragment);
    newField.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getEnclosingInstanceAccessModifiers()));
    newField.setType(createEnclosingType(ast));
    final String comment= CodeGeneration.getFieldComment(fType.getCompilationUnit(), declaration.getName().getIdentifier(), fEnclosingInstanceFieldName, StubUtility.getLineDelimiterUsed(fType.getJavaProject()));
    if (comment != null && comment.length() > 0) {
        final Javadoc doc= (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
        newField.setJavadoc(doc);
    }
    rewrite.getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertFirst(newField, null);
}
项目:Eclipse-Postfix-Code-Completion    文件:ParameterObjectFactory.java   
private FieldDeclaration createField(ParameterInfo pi, CompilationUnitRewrite cuRewrite) throws CoreException {
    AST ast= cuRewrite.getAST();
    ICompilationUnit unit= cuRewrite.getCu();

    VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
    String lineDelim= StubUtility.getLineDelimiterUsed(unit);
    SimpleName fieldName= ast.newSimpleName(pi.getNewName());
    fragment.setName(fieldName);
    FieldDeclaration declaration= ast.newFieldDeclaration(fragment);
    if (createComments(unit.getJavaProject())) {
        String comment= StubUtility.getFieldComment(unit, pi.getNewTypeName(), pi.getNewName(), lineDelim);
        if (comment != null) {
            Javadoc doc= (Javadoc) cuRewrite.getASTRewrite().createStringPlaceholder(comment, ASTNode.JAVADOC);
            declaration.setJavadoc(doc);
        }
    }
    List<Modifier> modifiers= new ArrayList<Modifier>();
    if (fCreateGetter) {
        modifiers.add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
    } else {
        modifiers.add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
    }
    declaration.modifiers().addAll(modifiers);
    declaration.setType(importBinding(pi.getNewTypeBinding(), cuRewrite));
    return declaration;
}
项目:Eclipse-Postfix-Code-Completion    文件:PullUpRefactoringProcessor.java   
private Javadoc createJavadocForStub(final String enclosingTypeName, final MethodDeclaration oldMethod, final MethodDeclaration newMethodNode, final ICompilationUnit cu, final ASTRewrite rewrite) throws CoreException {
    if (fSettings.createComments) {
        final IMethodBinding binding= oldMethod.resolveBinding();
        if (binding != null) {
            final ITypeBinding[] params= binding.getParameterTypes();
            final String fullTypeName= getDestinationType().getFullyQualifiedName('.');
            final String[] fullParamNames= new String[params.length];
            for (int i= 0; i < fullParamNames.length; i++) {
                fullParamNames[i]= Bindings.getFullyQualifiedName(params[i]);
            }
            final String comment= CodeGeneration.getMethodComment(cu, enclosingTypeName, newMethodNode, false, binding.getName(), fullTypeName, fullParamNames, StubUtility.getLineDelimiterUsed(cu));
            if (comment != null)
                return (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavadocTagsSubProcessor.java   
private void insertAllMissingTypeTags(ASTRewrite rewriter, TypeDeclaration typeDecl) {
    AST ast= typeDecl.getAST();
    Javadoc javadoc= typeDecl.getJavadoc();
    ListRewrite tagsRewriter= rewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);

    List<TypeParameter> typeParams= typeDecl.typeParameters();
    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));
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:AbstractToStringGenerator.java   
/**
 * adds a comment (if necessary) and an <code>@Override</code> annotation to the generated
 * method
 * 
 * @throws CoreException if creation failed
 */
protected void createMethodComment() throws CoreException {
    ITypeBinding object= fAst.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
    IMethodBinding[] objms= object.getDeclaredMethods();
    IMethodBinding objectMethod= null;
    for (int i= 0; i < objms.length; i++) {
        if (objms[i].getName().equals(METHODNAME_TO_STRING) && objms[i].getParameterTypes().length == 0)
            objectMethod= objms[i];
    }
    if (fContext.isCreateComments()) {
        String docString= CodeGeneration.getMethodComment(fContext.getCompilationUnit(), fContext.getTypeBinding().getQualifiedName(), toStringMethod, objectMethod, StubUtility
                .getLineDelimiterUsed(fContext.getCompilationUnit()));
        if (docString != null) {
            Javadoc javadoc= (Javadoc)fContext.getASTRewrite().createStringPlaceholder(docString, ASTNode.JAVADOC);
            toStringMethod.setJavadoc(javadoc);
        }
    }
    if (fContext.isOverrideAnnotation() && fContext.is50orHigher())
        StubUtility2.addOverrideAnnotation(fContext.getTypeBinding().getJavaElement().getJavaProject(), fContext.getASTRewrite(), toStringMethod, objectMethod);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SimilarElementsRequestor.java   
private static ICompilationUnit createPreparedCU(ICompilationUnit cu, Javadoc comment, int wordStart) throws JavaModelException {
    int startpos= comment.getStartPosition();
    boolean isTopLevel= comment.getParent().getParent() instanceof CompilationUnit;
    char[] content= cu.getBuffer().getCharacters().clone();
    if (isTopLevel && (wordStart + 6 < content.length)) {
        content[startpos++]= 'i'; content[startpos++]= 'm'; content[startpos++]= 'p';
        content[startpos++]= 'o'; content[startpos++]= 'r'; content[startpos++]= 't';
    }
    if (wordStart < content.length) {
        for (int i= startpos; i < wordStart; i++) {
            content[i]= ' ';
        }
    }

    /*
     * Explicitly create a new non-shared working copy.
     */
    ICompilationUnit newCU= cu.getWorkingCopy(null);
    newCU.getBuffer().setContents(content);
    return newCU;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavadocTagsSubProcessor.java   
private void insertAllMissingTypeTags(ASTRewrite rewriter, TypeDeclaration typeDecl) {
    AST ast= typeDecl.getAST();
    Javadoc javadoc= typeDecl.getJavadoc();
    ListRewrite tagsRewriter= rewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);

    List<TypeParameter> typeParams= typeDecl.typeParameters();
    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));
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:JavadocTagsSubProcessor.java   
public static TagElement findTag(Javadoc javadoc, String name, String arg) {
    List<TagElement> tags= javadoc.tags();
    int nTags= tags.size();
    for (int i= 0; i < nTags; i++) {
        TagElement curr= tags.get(i);
        if (name.equals(curr.getTagName())) {
            if (arg != null) {
                String argument= getArgument(curr);
                if (arg.equals(argument)) {
                    return curr;
                }
            } else {
                return curr;
            }
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavadocTagsSubProcessor.java   
public static TagElement findTag(Javadoc javadoc, String name, String arg) {
    List<TagElement> tags= javadoc.tags();
    int nTags= tags.size();
    for (int i= 0; i < nTags; i++) {
        TagElement curr= tags.get(i);
        if (name.equals(curr.getTagName())) {
            if (arg != null) {
                String argument= getArgument(curr);
                if (arg.equals(argument)) {
                    return curr;
                }
            } else {
                return curr;
            }
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:SimilarElementsRequestor.java   
private static ICompilationUnit createPreparedCU(ICompilationUnit cu, Javadoc comment, int wordStart) throws JavaModelException {
    int startpos= comment.getStartPosition();
    boolean isTopLevel= comment.getParent().getParent() instanceof CompilationUnit;
    char[] content= cu.getBuffer().getCharacters().clone();
    if (isTopLevel && (wordStart + 6 < content.length)) {
        content[startpos++]= 'i'; content[startpos++]= 'm'; content[startpos++]= 'p';
        content[startpos++]= 'o'; content[startpos++]= 'r'; content[startpos++]= 't';
    }
    if (wordStart < content.length) {
        for (int i= startpos; i < wordStart; i++) {
            content[i]= ' ';
        }
    }

    /*
     * Explicitly create a new non-shared working copy.
     */
    ICompilationUnit newCU= cu.getWorkingCopy(null);
    newCU.getBuffer().setContents(content);
    return newCU;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavadocContentAccess2.java   
private static String javadoc2HTML(IMember member, String rawJavadoc) {
    Javadoc javadoc= getJavadocNode(member, rawJavadoc);

    if (javadoc == null) {
        // fall back to JavadocContentAccess:
        try {
            Reader contentReader= JavadocContentAccess.getHTMLContentReader(member, false, false);
            if (contentReader != null)
                return getString(contentReader);
        } catch (JavaModelException e) {
            JavaPlugin.log(e);
        }
        return null;
    }

    if (canInheritJavadoc(member)) {
        IMethod method= (IMethod) member;
        return new JavadocContentAccess2(method, javadoc, rawJavadoc, new JavadocLookup(method.getDeclaringType())).toHTML();
    }
    return new JavadocContentAccess2(member, javadoc, rawJavadoc).toHTML();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:MoveInnerToTopRefactoring.java   
private void addEnclosingInstanceDeclaration(final AbstractTypeDeclaration declaration, final ASTRewrite rewrite) throws CoreException {
    Assert.isNotNull(declaration);
    Assert.isNotNull(rewrite);
    final AST ast= declaration.getAST();
    final VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
    fragment.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
    final FieldDeclaration newField= ast.newFieldDeclaration(fragment);
    newField.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getEnclosingInstanceAccessModifiers()));
    newField.setType(createEnclosingType(ast));
    final String comment= CodeGeneration.getFieldComment(fType.getCompilationUnit(), declaration.getName().getIdentifier(), fEnclosingInstanceFieldName, StubUtility.getLineDelimiterUsed(fType.getJavaProject()));
    if (comment != null && comment.length() > 0) {
        final Javadoc doc= (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
        newField.setJavadoc(doc);
    }
    rewrite.getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertFirst(newField, null);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ParameterObjectFactory.java   
private FieldDeclaration createField(ParameterInfo pi, CompilationUnitRewrite cuRewrite) throws CoreException {
    AST ast= cuRewrite.getAST();
    ICompilationUnit unit= cuRewrite.getCu();

    VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
    String lineDelim= StubUtility.getLineDelimiterUsed(unit);
    SimpleName fieldName= ast.newSimpleName(pi.getNewName());
    fragment.setName(fieldName);
    FieldDeclaration declaration= ast.newFieldDeclaration(fragment);
    if (createComments(unit.getJavaProject())) {
        String comment= StubUtility.getFieldComment(unit, pi.getNewTypeName(), pi.getNewName(), lineDelim);
        if (comment != null) {
            Javadoc doc= (Javadoc) cuRewrite.getASTRewrite().createStringPlaceholder(comment, ASTNode.JAVADOC);
            declaration.setJavadoc(doc);
        }
    }
    List<Modifier> modifiers= new ArrayList<Modifier>();
    if (fCreateGetter) {
        modifiers.add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
    } else {
        modifiers.add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
    }
    declaration.modifiers().addAll(modifiers);
    declaration.setType(importBinding(pi.getNewTypeBinding(), cuRewrite));
    return declaration;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:PullUpRefactoringProcessor.java   
private Javadoc createJavadocForStub(final String enclosingTypeName, final MethodDeclaration oldMethod, final MethodDeclaration newMethodNode, final ICompilationUnit cu, final ASTRewrite rewrite) throws CoreException {
    if (fSettings.createComments) {
        final IMethodBinding binding= oldMethod.resolveBinding();
        if (binding != null) {
            final ITypeBinding[] params= binding.getParameterTypes();
            final String fullTypeName= getDestinationType().getFullyQualifiedName('.');
            final String[] fullParamNames= new String[params.length];
            for (int i= 0; i < fullParamNames.length; i++) {
                fullParamNames[i]= Bindings.getFullyQualifiedName(params[i]);
            }
            final String comment= CodeGeneration.getMethodComment(cu, enclosingTypeName, newMethodNode, false, binding.getName(), fullTypeName, fullParamNames, StubUtility.getLineDelimiterUsed(cu));
            if (comment != null)
                return (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavadocContentAccess2.java   
private static Javadoc getJavadocNode(IMember member, String rawJavadoc) {
    //FIXME: take from SharedASTProvider if available
    //Caveat: Javadoc nodes are not available when Javadoc processing has been disabled!
    //https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207

    ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);

    IJavaProject javaProject= member.getJavaProject();
    parser.setProject(javaProject);
    Map<String, String> options= javaProject.getOptions(true);
    options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207
    parser.setCompilerOptions(options);

    String source= rawJavadoc + "class C{}"; //$NON-NLS-1$
    parser.setSource(source.toCharArray());

    CompilationUnit root= (CompilationUnit) parser.createAST(null);
    if (root == null)
        return null;
    List<AbstractTypeDeclaration> types= root.types();
    if (types.size() != 1)
        return null;
    AbstractTypeDeclaration type= types.get(0);
    return type.getJavadoc();
}
项目:clocom    文件:CommentVisitor.java   
public boolean visit(Javadoc node) {
    int startLineNumber = compilationUnit.getLineNumber(node.getStartPosition());
    int endLineNumber = compilationUnit.getLineNumber(node.getStartPosition() + node.getLength());

    //System.out.println("dd " + startLineNumber + " " + endLineNumber);
    //System.out.println("ee " + startLine + " " + endLine);

    if (startLine == startLineNumber) {

        // Build the comment char by char
        StringBuilder comment = new StringBuilder();
        for (int i = node.getStartPosition(); i < node.getStartPosition() + node.getLength(); i++) {
            comment.append(source[i]);
        }

        if (comment.capacity() > 0) {
            String str = comment.toString().replaceAll("\\n\\s+", "\n ");

            if (str != null) {
                CommentMap cMap = new CommentMap(str, startLineNumber, endLineNumber, 0);
                cMapList.add(cMap);
            }
        }
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AbstractToStringGenerator.java   
/**
 * adds a comment (if necessary) and an <code>@Override</code> annotation to the generated
 * method
 * 
 * @throws CoreException if creation failed
 */
protected void createMethodComment() throws CoreException {
    ITypeBinding object= fAst.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
    IMethodBinding[] objms= object.getDeclaredMethods();
    IMethodBinding objectMethod= null;
    for (int i= 0; i < objms.length; i++) {
        if (objms[i].getName().equals(METHODNAME_TO_STRING) && objms[i].getParameterTypes().length == 0)
            objectMethod= objms[i];
    }
    if (fContext.isCreateComments()) {
        String docString= CodeGeneration.getMethodComment(fContext.getCompilationUnit(), fContext.getTypeBinding().getQualifiedName(), toStringMethod, objectMethod, StubUtility
                .getLineDelimiterUsed(fContext.getCompilationUnit()));
        if (docString != null) {
            Javadoc javadoc= (Javadoc)fContext.getASTRewrite().createStringPlaceholder(docString, ASTNode.JAVADOC);
            toStringMethod.setJavadoc(javadoc);
        }
    }
    if (fContext.isOverrideAnnotation() && fContext.is50orHigher())
        StubUtility2.addOverrideAnnotation(fContext.getTypeBinding().getJavaElement().getJavaProject(), fContext.getASTRewrite(), toStringMethod, objectMethod);
}
项目:RefDiff    文件:AstUtils.java   
public static boolean containsDeprecatedTag(Javadoc javadoc) {
    if (javadoc == null) {
        return false;
    }
    @SuppressWarnings("unchecked")
       List<TagElement> javadocTags = (List<TagElement>) javadoc.tags();
    for (TagElement tag : javadocTags) {
        if ("@deprecated".equals(tag.getTagName())) {
            return true;
        }
    }
    return false;
}
项目:RefDiff    文件:AstUtils.java   
public static boolean containsDeprecatedTag(Javadoc javadoc) {
    if (javadoc == null) {
        return false;
    }
    @SuppressWarnings("unchecked")
       List<TagElement> javadocTags = (List<TagElement>) javadoc.tags();
    for (TagElement tag : javadocTags) {
        if ("@deprecated".equals(tag.getTagName())) {
            return true;
        }
    }
    return false;
}
项目:SparkBuilderGenerator    文件:JavadocAdder.java   
public void addJavadocForWithMethod(AST ast, String fieldName, MethodDeclaration builderMethod) {
    if (preferencesManager.getPreferenceValue(GENERATE_JAVADOC_ON_EACH_BUILDER_METHOD)) {
        Map<String, String> javadocTags = new LinkedHashMap<>();
        javadocTags.put(PARAM_JAVADOC_TAG_NAME, String.format(Locale.ENGLISH, "%s field to set", fieldName));
        javadocTags.put(RETURN_JAVADOC_TAG_NAME, "builder");
        Javadoc javadoc = javadocGenerator.generateJavadoc(ast,
                String.format(Locale.ENGLISH, "Builder method for %s parameter.", fieldName),
                javadocTags);
        builderMethod.setJavadoc(javadoc);
    }
}
项目:SparkBuilderGenerator    文件:JavadocAdder.java   
public void addJavadocForBuildMethod(AST ast, MethodDeclaration buildMethod) {
    if (preferencesManager.getPreferenceValue(GENERATE_JAVADOC_ON_EACH_BUILDER_METHOD)) {
        Javadoc javadoc = javadocGenerator.generateJavadoc(ast, "Builder method of the builder.",
                Collections.singletonMap(RETURN_JAVADOC_TAG_NAME, "built class"));
        buildMethod.setJavadoc(javadoc);
    }
}
项目:SparkBuilderGenerator    文件:JavadocAdder.java   
public void addJavadocForStagedInterface(AST ast, String interfaceName, TypeDeclaration addedInterface) {
    if (preferencesManager.getPreferenceValue(STAGED_BUILDER_GENERATE_JAVADOC_ON_STAGE_INTERFACE)) {
        Javadoc javadoc = javadocGenerator.generateJavadoc(ast,
                String.format(Locale.ENGLISH, "Definition of a stage for staged builder."), Collections.emptyMap());
        addedInterface.setJavadoc(javadoc);
    }
}
项目:SparkBuilderGenerator    文件:JavadocAdder.java   
public void addJavadocForBuilderMethod(AST ast, String typeName, MethodDeclaration builderMethod) {
    if (preferencesManager.getPreferenceValue(PluginPreferenceList.GENERATE_JAVADOC_ON_BUILDER_METHOD)) {
        Javadoc javadoc = javadocGenerator.generateJavadoc(ast, String.format(Locale.ENGLISH, "Creates builder to build {@link %s}.", typeName),
                Collections.singletonMap(RETURN_JAVADOC_TAG_NAME, "created builder"));
        builderMethod.setJavadoc(javadoc);
    }
}
项目:SparkBuilderGenerator    文件:JavadocAdder.java   
public void addJavadocForWithBuilderMethod(AST ast, String typeName, String parameterName, MethodDeclaration builderMethod) {
    if (preferencesManager.getPreferenceValue(PluginPreferenceList.GENERATE_JAVADOC_ON_BUILDER_METHOD)) {
        Javadoc javadoc = javadocGenerator.generateJavadoc(ast,
                String.format(Locale.ENGLISH, "Creates builder to build {@link %s} and setting %s parameter.", typeName, parameterName),
                Collections.singletonMap(RETURN_JAVADOC_TAG_NAME, "created builder"));
        builderMethod.setJavadoc(javadoc);
    }
}