List of usage examples for org.eclipse.jdt.core.dom TagElement getParent
public final ASTNode getParent()
null if this is the root node. From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
/** * Handle {@inheritDoc}./*from ww w . j a v a2 s . co m*/ * * @param node the node * @return <code>true</code> iff the node was an {@inheritDoc} node and has been handled */ private boolean handleInheritDoc(TagElement node) { if (!TagElement.TAG_INHERITDOC.equals(node.getTagName())) return false; try { if (fMethod == null) return false; TagElement blockTag = (TagElement) node.getParent(); String blockTagName = blockTag.getTagName(); if (blockTagName == null) { CharSequence inherited = fJavadocLookup.getInheritedMainDescription(fMethod); return handleInherited(inherited); } else if (TagElement.TAG_PARAM.equals(blockTagName)) { List<? extends ASTNode> fragments = blockTag.fragments(); int size = fragments.size(); if (size > 0) { Object first = fragments.get(0); if (first instanceof SimpleName) { String name = ((SimpleName) first).getIdentifier(); String[] parameterNames = fMethod.getParameterNames(); for (int i = 0; i < parameterNames.length; i++) { if (name.equals(parameterNames[i])) { CharSequence inherited = fJavadocLookup.getInheritedParamDescription(fMethod, i); return handleInherited(inherited); } } } else if (size > 2 && first instanceof TextElement) { String firstText = ((TextElement) first).getText(); if ("<".equals(firstText)) { //$NON-NLS-1$ Object second = fragments.get(1); Object third = fragments.get(2); if (second instanceof SimpleName && third instanceof TextElement) { String thirdText = ((TextElement) third).getText(); if (">".equals(thirdText)) { //$NON-NLS-1$ String name = ((SimpleName) second).getIdentifier(); ITypeParameter[] typeParameters = fMethod.getTypeParameters(); for (int i = 0; i < typeParameters.length; i++) { ITypeParameter typeParameter = typeParameters[i]; if (name.equals(typeParameter.getElementName())) { CharSequence inherited = fJavadocLookup .getInheritedTypeParamDescription(fMethod, i); return handleInherited(inherited); } } } } } } } } else if (TagElement.TAG_RETURN.equals(blockTagName)) { CharSequence inherited = fJavadocLookup.getInheritedReturnDescription(fMethod); return handleInherited(inherited); } else if (TagElement.TAG_THROWS.equals(blockTagName) || TagElement.TAG_EXCEPTION.equals(blockTagName)) { List<? extends ASTNode> fragments = blockTag.fragments(); if (fragments.size() > 0) { Object first = fragments.get(0); if (first instanceof Name) { String name = ASTNodes.getSimpleNameIdentifier((Name) first); CharSequence inherited = fJavadocLookup.getInheritedExceptionDescription(fMethod, name); return handleInherited(inherited); } } } } catch (JavaModelException e) { //TODO e.printStackTrace(); } 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--;// w ww.j a va 2s . 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.codenvy.ide.ext.java.server.javadoc.JavadocContentAccess2.java
License:Open Source License
/** * Handle {@inheritDoc}./*from w w w . java 2s .c o m*/ * * @param node * the node * @return <code>true</code> iff the node was an {@inheritDoc} node and has been handled */ private boolean handleInheritDoc(TagElement node) { if (!TagElement.TAG_INHERITDOC.equals(node.getTagName())) return false; try { if (fMethod == null) return false; TagElement blockTag = (TagElement) node.getParent(); String blockTagName = blockTag.getTagName(); if (blockTagName == null) { CharSequence inherited = fJavadocLookup.getInheritedMainDescription(fMethod); return handleInherited(inherited); } else if (TagElement.TAG_PARAM.equals(blockTagName)) { List<? extends ASTNode> fragments = blockTag.fragments(); if (fragments.size() > 0) { Object first = fragments.get(0); if (first instanceof SimpleName) { String name = ((SimpleName) first).getIdentifier(); String[] parameterNames = fMethod.getParameterNames(); for (int i = 0; i < parameterNames.length; i++) { if (name.equals(parameterNames[i])) { CharSequence inherited = fJavadocLookup.getInheritedParamDescription(fMethod, i); return handleInherited(inherited); } } } } } else if (TagElement.TAG_RETURN.equals(blockTagName)) { CharSequence inherited = fJavadocLookup.getInheritedReturnDescription(fMethod); return handleInherited(inherited); } else if (TagElement.TAG_THROWS.equals(blockTagName) || TagElement.TAG_EXCEPTION.equals(blockTagName)) { List<? extends ASTNode> fragments = blockTag.fragments(); if (fragments.size() > 0) { Object first = fragments.get(0); if (first instanceof Name) { String name = ASTNodes.getSimpleNameIdentifier((Name) first); CharSequence inherited = fJavadocLookup.getInheritedExceptionDescription(fMethod, name); return handleInherited(inherited); } } } } catch (JavaModelException e) { LOG.error(e.getMessage(), e); } return false; }
From source file:de.akra.idocit.java.services.SimpleJavadocParser.java
License:Apache License
private String extractParentIdentifierPath(String identifier, TagElement tagElement, List<? extends Parameter> parameters, JavaMethod method) { Javadoc javadoc = (Javadoc) tagElement.getParent(); String parentParamIdentifier = readParentParamterName(javadoc, tagElement, method); if (!parentParamIdentifier.isEmpty()) { JavaParameter parentParam = findParameterByName(parameters, parentParamIdentifier); if (parentParam != null) { return parentParam.getSignatureElementPath(); } else {// w w w . j a v a2 s . c om log.info("No parent parameter found for tag element " + String.valueOf(tagElement.toString())); } } else { // jakr: if no parent is found, leave the identifier initialized with // null. In this case there must be an invalid ordering of the Javadoc // tags (@subparam without @param above). } return StringUtils.EMPTY; }
From source file:de.akra.idocit.java.services.SimpleJavadocParser.java
License:Apache License
private String extractIdentifierPath(String identifier, TagElement tagElement, List<? extends Parameter> parameters, JavaMethod method) throws ParsingException { String[] parameterNames = extractIdentifierChain(identifier); Javadoc javadoc = (Javadoc) tagElement.getParent(); String parentParamIdentifier = readParentParamterName(javadoc, tagElement, method); if (!parentParamIdentifier.isEmpty()) { JavaParameter parentParam = findParameterByName(parameters, parentParamIdentifier); if (parentParam != null) { if (parameterNames.length >= 1) { JavaParameter childParameter = findParameterByName(parentParam.getComplexType(), parameterNames[0]); int i = 1; while (i < parameterNames.length) { if (childParameter != null) { childParameter = findParameterByName(childParameter.getComplexType(), parameterNames[i]); } else { throw new ParsingException("No more subparameters to search in for the identifier " + String.valueOf(parameterNames[i]) + " in method " + String.valueOf(method.getIdentifier())); }//from w ww . jav a 2 s. c o m i++; } if (childParameter != null) { return childParameter.getSignatureElementPath(); } else { throw new ParsingException("No more subparameters to search in for the identifier " + String.valueOf(parameterNames[0]) + " in method " + String.valueOf(method.getIdentifier())); } } else { throw new ParsingException( "The docText " + String.valueOf(identifier) + " could not be splitted."); } } else { log.info("No parent parameter found for tag element " + String.valueOf(tagElement.toString())); } } else { // jakr: if no parent is found, leave the identifier initialized with // null. In this case there must be an invalid ordering of the Javadoc // tags (@subparam without @param above). } return StringUtils.EMPTY; }
From source file:org.spoofax.interpreter.adapter.ecj.ECJFactory.java
License:LGPL
private TagElement asTagElement(IStrategoTerm term) { TagElement x = ((WrappedTagElement) term).getWrappee(); return x.getParent() == null && x.getAST() == ast ? x : (TagElement) ASTNode.copySubtree(ast, x); }
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--;//w ww.j a va 2s . 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; }