List of usage examples for org.eclipse.jdt.core.dom TagElement isNested
public boolean isNested()
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(TagElement node) { if (node.isNested()) { // nested tags are always enclosed in braces this.fBuffer.append("{");//$NON-NLS-1$ } else {// www . j a va2 s. c o m // top-level tags always begin on a new line this.fBuffer.append("\n * ");//$NON-NLS-1$ } boolean previousRequiresWhiteSpace = false; if (node.getTagName() != null) { this.fBuffer.append(node.getTagName()); previousRequiresWhiteSpace = true; } boolean previousRequiresNewLine = false; for (Iterator<? extends ASTNode> it = node.fragments().iterator(); it.hasNext();) { ASTNode e = 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) { this.fBuffer.append("\n * ");//$NON-NLS-1$ } previousRequiresNewLine = currentIncludesWhiteSpace; // add space if required to separate if (previousRequiresWhiteSpace && !currentIncludesWhiteSpace) { this.fBuffer.append(" "); //$NON-NLS-1$ } e.accept(this); previousRequiresWhiteSpace = !currentIncludesWhiteSpace && !(e instanceof TagElement); } if (node.isNested()) { this.fBuffer.append("}");//$NON-NLS-1$ } return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(TagElement node) { if (node.isNested()) { // nested tags are always enclosed in braces this.buffer.append("{");//$NON-NLS-1$ } else {/*from w w w . j a va 2 s . co m*/ // top-level tags always begin on a new line this.buffer.append("\n * ");//$NON-NLS-1$ } boolean previousRequiresWhiteSpace = false; if (node.getTagName() != null) { this.buffer.append(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) { this.buffer.append("\n * ");//$NON-NLS-1$ } previousRequiresNewLine = currentIncludesWhiteSpace; // add space if required to separate if (previousRequiresWhiteSpace && !currentIncludesWhiteSpace) { this.buffer.append(" "); //$NON-NLS-1$ } e.accept(this); previousRequiresWhiteSpace = !currentIncludesWhiteSpace && !(e instanceof TagElement); } if (node.isNested()) { this.buffer.append("}");//$NON-NLS-1$ } return false; }
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. j a v a2s .co 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 boolean visit(TagElement node) { String tagName;//from www.j a va 2s . com if (node.getTagName() == null) { tagName = JavadocMetaModel.TEXT_TAG; } else { tagName = node.getTagName(); } JavadocTagPart javadocTag = new JavadocTagPart(tagName); int prefixLen; if (node.getTagName() == null) { prefixLen = 0; } else { prefixLen = node.getTagName().length(); if (node.isNested()) { prefixLen += 1; } } storeWhitespaceIfAny(node, prefixLen); javadocsStack.peek().addPart(javadocTag); javadocsStack.push(javadocTag); 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 ava 2s . c om if (node.isNested()) { lastNodeEnd = node.getStartPosition() + node.getLength() - 1; } }
From source file:de.akra.idocit.java.utils.JavadocUtils.java
License:Apache License
/** * Extracts the plain text from the <code>fragments</code>. * //from www .j a v a 2 s . c o m * @param fragments * The fragments to read. * @param offset * The index at which should be started to read. If the fragments are e.g. * from a "@param" tag, then it is followed by the the variable name which * should be skipped. Therefore the <code>offset</code> should be 1. * @return The text from the <code>fragments</code>. */ @SuppressWarnings("unchecked") public static String readFragments(final List<ASTNode> fragments, final int offset) { final StringBuffer html = new StringBuffer(); if (fragments != null && fragments.size() >= offset) { for (final ASTNode fragment : fragments.subList(offset, fragments.size())) { final StringBuffer tempText = new StringBuffer(fragment.getLength()); switch (fragment.getNodeType()) { case ASTNode.TEXT_ELEMENT: { final TextElement textElem = (TextElement) fragment; tempText.append(textElem.getText()); break; } case ASTNode.SIMPLE_NAME: case ASTNode.QUALIFIED_NAME: { final Name name = (Name) fragment; tempText.append(name.getFullyQualifiedName()); break; } case ASTNode.METHOD_REF: { final MethodRef mRef = (MethodRef) fragment; if (mRef.getQualifier() != null) { final Name qualifier = mRef.getQualifier(); tempText.append(qualifier.getFullyQualifiedName()); } tempText.append('#'); tempText.append(mRef.getName().getIdentifier()); tempText.append('('); // write parameter list final List<MethodRefParameter> mRefParameters = (List<MethodRefParameter>) mRef.parameters(); for (final MethodRefParameter mRefParam : mRefParameters) { tempText.append(ReflectionHelper.extractIdentifierFrom(mRefParam.getType())); if (mRefParam.isVarargs()) { tempText.append("..."); } if (mRefParam.getName() != null) { tempText.append(' '); tempText.append(mRefParam.getName().getFullyQualifiedName()); } tempText.append(','); } if (!mRefParameters.isEmpty()) { // remove last comma tempText.deleteCharAt(tempText.length() - 1); } tempText.append(')'); break; } case ASTNode.MEMBER_REF: { final MemberRef mRef = (MemberRef) fragment; if (mRef.getQualifier() != null) { final Name qualifier = mRef.getQualifier(); tempText.append(qualifier.getFullyQualifiedName()); } tempText.append('#'); tempText.append(mRef.getName().getIdentifier()); break; } case ASTNode.TAG_ELEMENT: { final TagElement tagElem = (TagElement) fragment; if (tagElem.isNested()) { tempText.append('{'); } tempText.append(tagElem.getTagName()); tempText.append(' '); tempText.append(readFragments((List<ASTNode>) tagElem.fragments(), 0)); if (tagElem.isNested()) { tempText.append('}'); } break; } default: { // Do nothing! logger.info("The fragment " + String.valueOf(fragment) + " has nodetype-value " + fragment.getNodeType()); } } appendWithSpace(html, tempText); } // delete leading space, that was added by Javadoc to separate a tag // from the following text (e.g. '@param My documentation'). if (html.length() > 0 && html.charAt(0) == ' ') { html.deleteCharAt(0); } } return html.toString(); }
From source file:org.codemucker.jmutate.ast.JAstFlattener.java
License:Open Source License
public boolean visit(TagElement node) { if (node.isNested()) { // nested tags are always enclosed in braces this.buffer.append("{");//$NON-NLS-1$ } else {//w w w . j a v a 2 s . c o m // top-level tags always begin on a new line this.buffer.append("\n * ");//$NON-NLS-1$ } boolean previousRequiresWhiteSpace = false; if (node.getTagName() != null) { this.buffer.append(node.getTagName()); previousRequiresWhiteSpace = true; } boolean previousRequiresNewLine = false; for (Iterator it = node.fragments().iterator(); it.hasNext();) { ASTNode e = (ASTNode) it.next(); // Name, MemberRef, MethodRef, and nested TagElement do not include // white space. // TextElements don't always include whitespace, see // <https://bugs.eclipse.org/206518>. boolean currentIncludesWhiteSpace = false; if (e instanceof TextElement) { String text = ((TextElement) e).getText(); if (text.length() > 0 && ScannerHelper.isWhitespace(text.charAt(0))) { currentIncludesWhiteSpace = true; // workaround for // https://bugs.eclipse.org/403735 } } if (previousRequiresNewLine && currentIncludesWhiteSpace) { this.buffer.append("\n * ");//$NON-NLS-1$ } previousRequiresNewLine = currentIncludesWhiteSpace; // add space if required to separate if (previousRequiresWhiteSpace && !currentIncludesWhiteSpace) { this.buffer.append(" "); //$NON-NLS-1$ } e.accept(this); previousRequiresWhiteSpace = !currentIncludesWhiteSpace && !(e instanceof TagElement); } if (node.isNested()) { this.buffer.append("}");//$NON-NLS-1$ } return false; }
From source file:org.eclipse.xtend.core.javaconverter.JavaASTFlattener.java
License:Open Source License
@Override public boolean visit(final TagElement node) { boolean _isNested = node.isNested(); if (_isNested) { this.appendToBuffer("{"); } else {/*from w w w . j a v a2s . c o m*/ this.appendLineWrapToBuffer(); this.appendToBuffer(" * "); } boolean previousRequiresWhiteSpace = false; String _tagName = node.getTagName(); boolean _tripleNotEquals = (_tagName != null); if (_tripleNotEquals) { this.appendToBuffer(node.getTagName()); previousRequiresWhiteSpace = true; } boolean previousRequiresNewLine = false; for (Iterator<? extends ASTNode> it = node.fragments().iterator(); it.hasNext();) { { ASTNode e = it.next(); boolean currentIncludesWhiteSpace = (e instanceof TextElement); if ((previousRequiresNewLine && currentIncludesWhiteSpace)) { this.appendLineWrapToBuffer(); this.appendToBuffer(" * "); } previousRequiresNewLine = currentIncludesWhiteSpace; if ((previousRequiresWhiteSpace && (!currentIncludesWhiteSpace))) { this.appendSpaceToBuffer(); } e.accept(this); previousRequiresWhiteSpace = ((!currentIncludesWhiteSpace) && (!(e instanceof TagElement))); } } boolean _isNested_1 = node.isNested(); if (_isNested_1) { this.appendToBuffer("}"); } return false; }
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 ww .jav 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() || 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.//from w w w. ja v a 2 s . co m * * @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; }