Search in sources :

Example 66 with Javadoc

use of org.eclipse.jdt.core.dom.Javadoc in project xtext-xtend by eclipse.

the class JavaASTFlattener method visit.

@Override
public boolean visit(final EnumConstantDeclaration node) {
    Javadoc _javadoc = node.getJavadoc();
    boolean _tripleNotEquals = (_javadoc != null);
    if (_tripleNotEquals) {
        node.getJavadoc().accept(this);
    }
    this.appendModifiers(node, node.modifiers());
    node.getName().accept(this);
    boolean _isEmpty = node.arguments().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        this.addProblem(node, "Enum constant cannot have any arguments");
        this.appendToBuffer("(");
        this.visitAllSeparatedByComma(node.arguments());
        this.appendToBuffer(")");
    }
    AnonymousClassDeclaration _anonymousClassDeclaration = node.getAnonymousClassDeclaration();
    boolean _tripleNotEquals_1 = (_anonymousClassDeclaration != null);
    if (_tripleNotEquals_1) {
        this.addProblem(node, "Enum constant cannot have any anonymous class declarations");
        node.getAnonymousClassDeclaration().accept(this);
    }
    return false;
}
Also used : AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) Javadoc(org.eclipse.jdt.core.dom.Javadoc)

Example 67 with Javadoc

use of org.eclipse.jdt.core.dom.Javadoc in project xtext-eclipse by eclipse.

the class XbaseHoverDocumentationProvider method computeDocumentation.

public String computeDocumentation(EObject object) {
    buffer = new StringBuffer();
    context = object;
    fLiteralContent = 0;
    List<String> parameterNames = initParameterNames();
    Map<String, URI> exceptionNamesToURI = initExceptionNamesToURI();
    addAnnotations(object);
    getDocumentationWithPrefix(object);
    Javadoc javadoc = getJavaDoc();
    if (javadoc == null)
        return buffer.toString();
    TagElement deprecatedTag = null;
    TagElement start = null;
    List<TagElement> parameters = new ArrayList<TagElement>();
    TagElement returnTag = null;
    List<TagElement> exceptions = new ArrayList<TagElement>();
    List<TagElement> versions = new ArrayList<TagElement>();
    List<TagElement> authors = new ArrayList<TagElement>();
    List<TagElement> sees = new ArrayList<TagElement>();
    List<TagElement> since = new ArrayList<TagElement>();
    List<TagElement> rest = new ArrayList<TagElement>();
    @SuppressWarnings("unchecked") List<TagElement> tags = javadoc.tags();
    for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext(); ) {
        TagElement tag = iter.next();
        String tagName = tag.getTagName();
        if (tagName == null) {
            start = tag;
        } else if (TagElement.TAG_PARAM.equals(tagName)) {
            parameters.add(tag);
            @SuppressWarnings("unchecked") List<? extends ASTNode> fragments = tag.fragments();
            if (fragments.size() > 0) {
                Object first = fragments.get(0);
                if (first instanceof SimpleName) {
                    String name = ((SimpleName) first).getIdentifier();
                    int paramIndex = parameterNames.indexOf(name);
                    if (paramIndex != -1) {
                        parameterNames.set(paramIndex, null);
                    }
                }
            }
        } else if (TagElement.TAG_RETURN.equals(tagName)) {
            if (returnTag == null)
                // the Javadoc tool only shows the first return tag
                returnTag = tag;
        } else if (TagElement.TAG_EXCEPTION.equals(tagName) || TagElement.TAG_THROWS.equals(tagName)) {
            exceptions.add(tag);
            @SuppressWarnings("unchecked") List<? extends ASTNode> fragments = tag.fragments();
            if (fragments.size() > 0) {
                Object first = fragments.get(0);
                if (first instanceof Name) {
                    @SuppressWarnings("restriction") String name = org.eclipse.jdt.internal.corext.dom.ASTNodes.getSimpleNameIdentifier((Name) first);
                    if (exceptionNamesToURI.containsKey(name)) {
                        exceptionNamesToURI.put(name, null);
                    }
                }
            }
        } else if (TagElement.TAG_SINCE.equals(tagName)) {
            since.add(tag);
        } else if (TagElement.TAG_VERSION.equals(tagName)) {
            versions.add(tag);
        } else if (TagElement.TAG_AUTHOR.equals(tagName)) {
            authors.add(tag);
        } else if (TagElement.TAG_SEE.equals(tagName)) {
            sees.add(tag);
        } else if (TagElement.TAG_DEPRECATED.equals(tagName)) {
            if (deprecatedTag == null)
                // the Javadoc tool only shows the first deprecated tag
                deprecatedTag = tag;
        } else {
            rest.add(tag);
        }
    }
    boolean hasParameters = parameters.size() > 0;
    boolean hasReturnTag = returnTag != null;
    boolean hasExceptions = exceptions.size() > 0;
    if (deprecatedTag != null)
        handleDeprecatedTag(deprecatedTag);
    if (start != null) {
        @SuppressWarnings("unchecked") List<ASTNode> fragments = start.fragments();
        handleContentElements(fragments);
    }
    if (hasParameters || hasReturnTag || hasExceptions || versions.size() > 0 || authors.size() > 0 || since.size() > 0 || sees.size() > 0 || rest.size() > 0 || (buffer.length() > 0) && (parameterNames.size() > 0 || exceptionNamesToURI.size() > 0)) {
        handleSuperMethodReferences(object);
        buffer.append(BLOCK_TAG_START);
        handleParameters(object, parameters, parameterNames);
        handleReturnTag(returnTag);
        handleExceptionTags(exceptions, exceptionNamesToURI);
        handleBlockTags("Since:", since);
        handleBlockTags("Version:", versions);
        handleBlockTags("Author:", authors);
        handleBlockTags("See Also:", sees);
        handleBlockTags(rest);
        buffer.append(BLOCK_TAG_END);
    } else if (buffer.length() > 0) {
        handleSuperMethodReferences(object);
    }
    String result = buffer.toString();
    buffer = null;
    rawJavaDoc = null;
    context = null;
    return result;
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) ArrayList(java.util.ArrayList) Javadoc(org.eclipse.jdt.core.dom.Javadoc) URI(org.eclipse.emf.common.util.URI) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Name(org.eclipse.jdt.core.dom.Name) ASTNode(org.eclipse.jdt.core.dom.ASTNode) TagElement(org.eclipse.jdt.core.dom.TagElement) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject)

Example 68 with Javadoc

use of org.eclipse.jdt.core.dom.Javadoc in project eclipse-cs by checkstyle.

the class MethodLimitQuickfix method handleGetCorrectingASTVisitor.

/**
 * {@inheritDoc}
 */
protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartOffset) {
    return new ASTVisitor() {

        @SuppressWarnings("unchecked")
        public boolean visit(MethodDeclaration node) {
            Javadoc doc = node.getJavadoc();
            if (doc == null) {
                doc = node.getAST().newJavadoc();
                node.setJavadoc(doc);
            }
            TagElement newTag = node.getAST().newTagElement();
            newTag.setTagName("TODO Added by MethodLimit Sample quickfix");
            doc.tags().add(0, newTag);
            return true;
        }
    };
}
Also used : MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) Javadoc(org.eclipse.jdt.core.dom.Javadoc) TagElement(org.eclipse.jdt.core.dom.TagElement) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor)

Aggregations

Javadoc (org.eclipse.jdt.core.dom.Javadoc)68 AST (org.eclipse.jdt.core.dom.AST)33 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)31 ASTNode (org.eclipse.jdt.core.dom.ASTNode)30 TagElement (org.eclipse.jdt.core.dom.TagElement)25 Type (org.eclipse.jdt.core.dom.Type)25 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)20 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)17 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)16 ImportRewriteContext (org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext)16 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)15 Block (org.eclipse.jdt.core.dom.Block)15 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)14 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)14 ImportRewrite (org.eclipse.jdt.core.dom.rewrite.ImportRewrite)14 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)14 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)12 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)12 ReturnStatement (org.eclipse.jdt.core.dom.ReturnStatement)12 TextElement (org.eclipse.jdt.core.dom.TextElement)11