Example usage for org.eclipse.jdt.core.dom TagElement getLength

List of usage examples for org.eclipse.jdt.core.dom TagElement getLength

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom TagElement getLength.

Prototype

public final int getLength() 

Source Link

Document

Returns the length in characters of the original source file indicating where the source fragment corresponding to this node ends.

Usage

From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java

License:Open Source License

private void handleInlineTagElement(TagElement node) {
    String name = node.getTagName();

    if (TagElement.TAG_VALUE.equals(name) && handleValueTag(node))
        return;//from   w w w  . j  a va2s. c  om

    boolean isLink = TagElement.TAG_LINK.equals(name);
    boolean isLinkplain = TagElement.TAG_LINKPLAIN.equals(name);
    boolean isCode = TagElement.TAG_CODE.equals(name);
    boolean isLiteral = TagElement.TAG_LITERAL.equals(name);

    if (isLiteral || isCode)
        fLiteralContent++;
    if (isLink || isCode)
        fBuf.append("<code>"); //$NON-NLS-1$

    if (isLink || isLinkplain)
        handleLink(node.fragments());
    else if (isCode || isLiteral)
        handleContentElements(node.fragments(), true);
    else if (handleInheritDoc(node)) {
        // handled
    } else if (handleDocRoot(node)) {
        // handled
    } else {
        //print uninterpreted source {@tagname ...} for unknown tags
        int start = node.getStartPosition();
        String text = fSource.substring(start, start + node.getLength());
        fBuf.append(removeDocLineIntros(text));
    }

    if (isLink || isCode)
        fBuf.append("</code>"); //$NON-NLS-1$
    if (isLiteral || isCode)
        fLiteralContent--;

}

From source file:com.bsiag.eclipse.jdt.java.formatter.CommentsPreparator.java

License:Open Source License

@Override
public boolean visit(TagElement node) {
    String tagName = node.getTagName();
    if (tagName == null || tagName.length() <= 1)
        return true;

    int startIndex = tokenStartingAt(node.getStartPosition());
    int nodeEnd = node.getStartPosition() + node.getLength() - 1;
    while (ScannerHelper.isWhitespace(this.ctm.charAt(nodeEnd)))
        nodeEnd--;/*from   w  w  w  .  ja v  a2  s  . c o  m*/
    int endIndex = tokenEndingAt(nodeEnd);

    this.ctm.get(startIndex + 1).setWrapPolicy(WrapPolicy.DISABLE_WRAP);

    if (node.getParent() instanceof Javadoc) {
        assert this.ctm.toString(startIndex).startsWith(tagName);

        boolean isParamTag = PARAM_TAGS.contains(tagName);
        if (isParamTag && this.options.comment_insert_new_line_for_parameter && startIndex < endIndex) {
            Token token = this.ctm.get(startIndex + 2);
            token.breakBefore();
        }

        if (this.options.comment_indent_root_tags) {
            int indent = this.ctm.getLength(this.ctm.get(startIndex), 0) + 1;
            if (isParamTag && this.options.comment_indent_parameter_description)
                indent += this.options.indentation_size;
            for (int i = startIndex + 1; i <= endIndex; i++) {
                Token token = this.ctm.get(i);
                token.setIndent(indent);
                // indent is used temporarily, tokens that are actually first in line
                // will have this changed to align (indent is reserved for code inside <pre> tags)
            }
        }

        Token startTokeen = this.ctm.get(startIndex);
        if (startIndex > 1)
            startTokeen.breakBefore();
        int firstTagIndex;
        if (this.firstTagToken == null || (firstTagIndex = this.ctm.indexOf(this.firstTagToken)) < 0
                || startIndex < firstTagIndex)
            this.firstTagToken = startTokeen;

        handleHtml(node);
    }

    if (node.isNested()) {
        substituteWrapIfTouching(startIndex);
        substituteWrapIfTouching(endIndex + 1);
        if (IMMUTABLE_TAGS.contains(tagName) && startIndex < endIndex)
            disableFormatting(startIndex, endIndex);
        noSubstituteWrapping(node.getStartPosition(), nodeEnd);
    }
    return true;
}

From source file:com.servoy.eclipse.docgenerator.parser.JavadocExtractor.java

License:Open Source License

@Override
public void endVisit(TagElement node) {
    javadocsStack.pop();//w w  w  . j  a v  a2 s.  c  o m
    if (node.isNested()) {
        lastNodeEnd = node.getStartPosition() + node.getLength() - 1;
    }
}

From source file:org.autorefactor.refactoring.rules.CommentsRefactoring.java

License:Open Source License

private String addPeriodAtEndOfFirstLine(Javadoc node, String comment) {
    String beforeFirstTag = comment;
    String afterFirstTag = "";
    final Matcher m = FIRST_JAVADOC_TAG.matcher(comment);
    if (m.find()) {
        if (m.start() == 0) {
            return null;
        }/*from w  ww.j a  v  a  2s  .  co m*/
        beforeFirstTag = comment.substring(0, m.start());
        afterFirstTag = comment.substring(m.start());
    }
    final Matcher matcher = JAVADOC_WITHOUT_PUNCTUATION.matcher(beforeFirstTag);
    if (matcher.matches()) {
        final List<TagElement> tagElements = tags(node);
        if (tagElements.size() >= 2) {
            final TagElement firstLine = tagElements.get(0);
            final int relativeStart = firstLine.getStartPosition() - node.getStartPosition();
            final int endOfFirstLine = relativeStart + firstLine.getLength();
            return comment.substring(0, endOfFirstLine) + "." + comment.substring(endOfFirstLine);
            // TODO JNR do the replace here, not outside this method
        }
        return matcher.group(1) + "." + matcher.group(2) + afterFirstTag;
    }
    return null;
}

From source file:org.eclipse.wb.internal.core.utils.ast.AstEditor.java

License:Open Source License

private void setJavadocTagText_replaceFragments(TagElement tagElement, String tagText) throws Exception {
    List<ASTNode> fragments = DomGenerics.fragments(tagElement);
    // replace source
    int fragmentsPosition;
    if (!fragments.isEmpty()) {
        ASTNode firstFragment = fragments.get(0);
        fragmentsPosition = AstNodeUtils.getSourceBegin(firstFragment);
        int fragmentsLength = AstNodeUtils.getSourceEnd(tagElement) - fragmentsPosition;
        replaceSubstring(fragmentsPosition, fragmentsLength, tagText);
    } else {/*w  w w.jav  a2  s.  c o m*/
        fragmentsPosition = AstNodeUtils.getSourceEnd(tagElement);
        replaceSubstring(fragmentsPosition, 0, tagText);
        AstNodeUtils.setSourceLength(tagElement, tagElement.getLength() + tagText.length());
    }
    // replace fragments
    fragments.clear();
    TextElement textElement = tagElement.getAST().newTextElement();
    textElement.setSourceRange(fragmentsPosition, tagText.length());
    textElement.setText(tagText);
    fragments.add(textElement);
}

From source file:org.eclipse.xtext.xbase.ui.hover.XbaseHoverDocumentationProvider.java

License:Open Source License

protected void handleInlineTagElement(TagElement node) {
    String name = node.getTagName();
    if (TagElement.TAG_VALUE.equals(name) && handleValueTag(node))
        return;//from w w  w  .  ja va  2s .  c  o m
    boolean isLink = TagElement.TAG_LINK.equals(name);
    boolean isLinkplain = TagElement.TAG_LINKPLAIN.equals(name);
    boolean isCode = TagElement.TAG_CODE.equals(name);
    boolean isLiteral = TagElement.TAG_LITERAL.equals(name);
    if (isLiteral || isCode)
        fLiteralContent++;
    if (isLink || isCode)
        buffer.append("<code>"); //$NON-NLS-1$
    if (isLink || isLinkplain)
        handleLink(node.fragments());
    else if (isCode || isLiteral) {
        @SuppressWarnings("unchecked")
        List<ASTNode> fragments = node.fragments();
        handleContentElements(fragments, true);
    } else if (handleInheritDoc(node)) {
        // handled
    } else if (handleDocRoot(node)) {
        // handled
    } else {
        //print uninterpreted source {@tagname ...} for unknown tags
        int start = node.getStartPosition();
        String text = rawJavaDoc.substring(start, start + node.getLength());
        buffer.append(removeDocLineIntros(text));
    }
    if (isLink || isCode)
        buffer.append("</code>"); //$NON-NLS-1$
    if (isLiteral || isCode)
        fLiteralContent--;

}

From source file:org.springframework.ide.eclipse.jdt.formatter.internal.CommentsPreparator.java

License:Open Source License

@Override
public boolean visit(TagElement node) {
    String tagName = node.getTagName();
    if (tagName == null || tagName.length() <= 1)
        return true;

    int startIndex = tokenStartingAt(node.getStartPosition());
    int nodeEnd = node.getStartPosition() + node.getLength() - 1;
    while (ScannerHelper.isWhitespace(this.ctm.charAt(nodeEnd)))
        nodeEnd--;/*from   w w  w  . ja  va2s .  c om*/
    int endIndex = tokenEndingAt(nodeEnd);

    this.ctm.get(startIndex + 1).setWrapPolicy(WrapPolicy.DISABLE_WRAP);

    if (node.getParent() instanceof Javadoc) {
        assert this.ctm.toString(startIndex).startsWith(tagName);

        boolean isParamTag = PARAM_TAGS.contains(tagName);
        if (isParamTag && this.options.comment_insert_new_line_for_parameter && startIndex < endIndex) {
            Token token = this.ctm.get(startIndex + 2);
            token.breakBefore();
        }

        if (this.options.comment_indent_root_tags) {
            int indent = this.ctm.getLength(this.ctm.get(startIndex), 0) + 1;
            if (isParamTag && this.options.comment_indent_parameter_description)
                indent += this.options.indentation_size;
            for (int i = startIndex + 1; i <= endIndex; i++) {
                Token token = this.ctm.get(i);
                token.setIndent(indent);
                // indent is used temporarily, tokens that are actually first in line
                // will have this changed to align (indent is reserved for code inside <pre> tags)
            }
        }

        Token startTokeen = this.ctm.get(startIndex);
        if (startIndex > 1)
            startTokeen.breakBefore();
        int firstTagIndex;
        if (this.firstTagToken == null || (firstTagIndex = this.ctm.indexOf(this.firstTagToken)) < 0
                || startIndex < firstTagIndex)
            this.firstTagToken = startTokeen;

        handleHtml(node);
    }

    if (node.isNested() || TagElement.TAG_SEE.equals(tagName)) {
        substituteWrapIfTouching(startIndex);
        substituteWrapIfTouching(endIndex + 1);
        if (IMMUTABLE_TAGS.contains(tagName) && startIndex < endIndex)
            disableFormatting(startIndex, endIndex);
        noSubstituteWrapping(node.getStartPosition(), nodeEnd);
    }
    return true;
}

From source file:ptolemy.backtrack.eclipse.ast.ASTFormatter.java

License:Open Source License

/** Visit an ast node, and return whether its children should be further
 *  visited./*  w w  w .  jav  a2 s.c om*/
 *
 *  @param node The AST node.
 *  @return Whether its children should be further visited.
 */
public boolean visit(TagElement node) {
    if (node.isNested()) {
        // nested tags are always enclosed in braces
        _openBrace();
    } else {
        // top-level tags always begin on a new line
        _output("\n");
        _output(_indent);
        _output(" * ");
    }

    boolean previousRequiresWhiteSpace = false;

    if (node.getTagName() != null) {
        _output(node.getTagName());
        previousRequiresWhiteSpace = true;
    }

    boolean previousRequiresNewLine = false;

    for (Iterator it = node.fragments().iterator(); it.hasNext();) {
        ASTNode e = (ASTNode) it.next();

        // assume text elements include necessary leading and trailing
        // whitespace but Name, MemberRef, MethodRef, and nested
        // TagElement do not include white space
        boolean currentIncludesWhiteSpace = (e instanceof TextElement);

        if (previousRequiresNewLine && currentIncludesWhiteSpace) {
            _output("\n");
            _output(_indent);
            _output(" * ");
        }

        previousRequiresNewLine = currentIncludesWhiteSpace;

        // add space if required to separate
        if (previousRequiresWhiteSpace && !currentIncludesWhiteSpace) {
            _output(" ");
        }

        e.accept(this);
        previousRequiresWhiteSpace = !currentIncludesWhiteSpace && !(e instanceof TagElement);
    }

    if (node.isNested()) {
        _checkComments((node.getStartPosition() + node.getLength()) - 1);
        _closeBrace();
    }

    return false;
}