List of usage examples for org.eclipse.jdt.core.dom TagElement getTagName
public String getTagName()
null if none. 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 {/*from w w w.ja v a 2 s.co 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:at.bestsolution.fxide.jdt.editor.JDTJavaDocSupport.java
License:Open Source License
public static HtmlString toHtml(IJavaElement element, String rawJavadoc) { String source = rawJavadoc + "class C{}"; //$NON-NLS-1$ CompilationUnit root = createAST(element, source); if (root == null) return null; List<AbstractTypeDeclaration> types = root.types(); if (types.size() != 1) return null; AbstractTypeDeclaration type = types.get(0); Javadoc javadoc = type.getJavadoc(); String js = ""; try (InputStream in = JDTJavaDocSupport.class.getResourceAsStream("internal/prettify.js")) { js = IOUtils.readToString(in, Charset.forName("UTF-8")); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace();//from ww w .j a v a2 s .c o m } StringBuilder b = new StringBuilder("<html><head></head><body>"); List<TagElement> l = javadoc.tags(); for (TagElement e : l) { if (e.getTagName() == null) { b.append(' '); handleContents(b, e); } // System.err.println(" ===> " + e.getTagName()); } b.append("</body></html>"); // System.err.println(b); return new HtmlString(b.toString()); // BufferedReader r = new BufferedReader(new StringReader(javaDoc)); // StringBuilder b = new StringBuilder(); // return javaDoc.replaceAll("/\\*.*\r?\n", "").replaceAll(".*\\*", ""); }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
private void parameterToHTML() { String elementName = fElement.getElementName(); List<TagElement> tags = fJavadoc.tags(); for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) { TagElement tag = iter.next(); String tagName = tag.getTagName(); if (TagElement.TAG_PARAM.equals(tagName)) { List<? extends ASTNode> fragments = tag.fragments(); int size = fragments.size(); if (size > 0) { Object first = fragments.get(0); if (first instanceof SimpleName) { String name = ((SimpleName) first).getIdentifier(); if (elementName.equals(name)) { handleContentElements(fragments.subList(1, size)); return; }/* ww w . j a v a2 s.co m*/ } else if (size > 2 && fElement instanceof ITypeParameter && 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 name = ((SimpleName) second).getIdentifier(); String thirdText = ((TextElement) third).getText(); if (elementName.equals(name) && ">".equals(thirdText)) { //$NON-NLS-1$ handleContentElements(fragments.subList(3, size)); return; } } } } } } } if (fElement instanceof ILocalVariable) { List<String> parameterNames = initParameterNames(); int i = parameterNames.indexOf(elementName); if (i != -1) { CharSequence inheritedParamDescription = fJavadocLookup.getInheritedParamDescription(fMethod, i); handleInherited(inheritedParamDescription); } } else if (fElement instanceof ITypeParameter) { List<String> typeParameterNames = initTypeParameterNames(); int i = typeParameterNames.indexOf(elementName); if (i != -1) { CharSequence inheritedTypeParamDescription = fJavadocLookup .getInheritedTypeParamDescription(fMethod, i); handleInherited(inheritedTypeParamDescription); } } }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
private void elementToHTML() { // After first loop, non-null entries in the following two lists are missing and need to be inherited: List<String> typeParameterNames = initTypeParameterNames(); List<String> parameterNames = initParameterNames(); List<String> exceptionNames = initExceptionNames(); TagElement deprecatedTag = null; TagElement start = null;//from w ww .ja v a2 s . c o m List<TagElement> typeParameters = new ArrayList<>(); List<TagElement> parameters = new ArrayList<>(); TagElement returnTag = null; List<TagElement> exceptions = new ArrayList<>(); List<TagElement> versions = new ArrayList<>(); List<TagElement> authors = new ArrayList<>(); List<TagElement> sees = new ArrayList<>(); List<TagElement> since = new ArrayList<>(); List<TagElement> rest = new ArrayList<>(); List<TagElement> tags = fJavadoc.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)) { List<? extends ASTNode> fragments = tag.fragments(); int size = fragments.size(); if (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); } parameters.add(tag); } 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 name = ((SimpleName) second).getIdentifier(); String thirdText = ((TextElement) third).getText(); if (">".equals(thirdText)) { //$NON-NLS-1$ int paramIndex = typeParameterNames.indexOf(name); if (paramIndex != -1) { typeParameterNames.set(paramIndex, null); } typeParameters.add(tag); } } } } } } else if (TagElement.TAG_RETURN.equals(tagName)) { if (returnTag == null) returnTag = tag; // the Javadoc tool only shows the first return tag } else if (TagElement.TAG_EXCEPTION.equals(tagName) || TagElement.TAG_THROWS.equals(tagName)) { exceptions.add(tag); List<? extends ASTNode> fragments = tag.fragments(); if (fragments.size() > 0) { Object first = fragments.get(0); if (first instanceof Name) { String name = ASTNodes.getSimpleNameIdentifier((Name) first); int exceptionIndex = exceptionNames.indexOf(name); if (exceptionIndex != -1) { exceptionNames.set(exceptionIndex, 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) deprecatedTag = tag; // the Javadoc tool only shows the first deprecated tag } else { rest.add(tag); } } //TODO: @Documented annotations before header if (deprecatedTag != null) handleDeprecatedTag(deprecatedTag); if (start != null) handleContentElements(start.fragments()); else if (fMethod != null) { CharSequence inherited = fJavadocLookup.getInheritedMainDescription(fMethod); // The Javadoc tool adds "Description copied from class: ..." (only for the main description). // We don't bother doing that. handleInherited(inherited); } CharSequence[] typeParameterDescriptions = new CharSequence[typeParameterNames.size()]; boolean hasInheritedTypeParameters = inheritTypeParameterDescriptions(typeParameterNames, typeParameterDescriptions); boolean hasTypeParameters = typeParameters.size() > 0 || hasInheritedTypeParameters; CharSequence[] parameterDescriptions = new CharSequence[parameterNames.size()]; boolean hasInheritedParameters = inheritParameterDescriptions(parameterNames, parameterDescriptions); boolean hasParameters = parameters.size() > 0 || hasInheritedParameters; CharSequence returnDescription = null; if (returnTag == null && needsReturnTag()) returnDescription = fJavadocLookup.getInheritedReturnDescription(fMethod); boolean hasReturnTag = returnTag != null || returnDescription != null; CharSequence[] exceptionDescriptions = new CharSequence[exceptionNames.size()]; boolean hasInheritedExceptions = inheritExceptionDescriptions(exceptionNames, exceptionDescriptions); boolean hasExceptions = exceptions.size() > 0 || hasInheritedExceptions; if (hasParameters || hasTypeParameters || hasReturnTag || hasExceptions || versions.size() > 0 || authors.size() > 0 || since.size() > 0 || sees.size() > 0 || rest.size() > 0 || (fBuf.length() > 0 && (parameterDescriptions.length > 0 || exceptionDescriptions.length > 0))) { handleSuperMethodReferences(); fBuf.append(BLOCK_TAG_START); handleParameterTags(typeParameters, typeParameterNames, typeParameterDescriptions, true); handleParameterTags(parameters, parameterNames, parameterDescriptions, false); handleReturnTag(returnTag, returnDescription); handleExceptionTags(exceptions, exceptionNames, exceptionDescriptions); handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_since_section, since); handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_version_section, versions); handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_author_section, authors); handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_see_section, sees); handleBlockTags(rest); fBuf.append(BLOCK_TAG_END); } else if (fBuf.length() > 0) { handleSuperMethodReferences(); } }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
CharSequence getMainDescription() {
if (fMainDescription == null) {
fMainDescription = new StringBuffer();
fBuf = fMainDescription;// w w w .j a v a 2 s . c o m
fLiteralContent = 0;
List<TagElement> tags = fJavadoc.tags();
for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) {
TagElement tag = iter.next();
String tagName = tag.getTagName();
if (tagName == null) {
handleContentElements(tag.fragments());
break;
}
}
fBuf = null;
}
return fMainDescription.length() > 0 ? fMainDescription : null;
}
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
CharSequence getReturnDescription() {
if (fReturnDescription == null) {
fReturnDescription = new StringBuffer();
fBuf = fReturnDescription;// ww w . ja va 2s . c o m
fLiteralContent = 0;
List<TagElement> tags = fJavadoc.tags();
for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) {
TagElement tag = iter.next();
String tagName = tag.getTagName();
if (TagElement.TAG_RETURN.equals(tagName)) {
handleContentElements(tag.fragments());
break;
}
}
fBuf = null;
}
return fReturnDescription.length() > 0 ? fReturnDescription : null;
}
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
CharSequence getInheritedTypeParamDescription(int typeParamIndex) { if (fMethod != null) { List<String> typeParameterNames = initTypeParameterNames(); if (fTypeParamDescriptions == null) { fTypeParamDescriptions = new StringBuffer[typeParameterNames.size()]; } else {/*from w w w.j a v a 2 s . c o m*/ StringBuffer description = fTypeParamDescriptions[typeParamIndex]; if (description != null) { return description.length() > 0 ? description : null; } } StringBuffer description = new StringBuffer(); fTypeParamDescriptions[typeParamIndex] = description; fBuf = description; fLiteralContent = 0; String typeParamName = typeParameterNames.get(typeParamIndex); List<TagElement> tags = fJavadoc.tags(); for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) { TagElement tag = iter.next(); String tagName = tag.getTagName(); if (TagElement.TAG_PARAM.equals(tagName)) { List<? extends ASTNode> fragments = tag.fragments(); if (fragments.size() > 2) { Object first = fragments.get(0); Object second = fragments.get(1); Object third = fragments.get(2); if (first instanceof TextElement && second instanceof SimpleName && third instanceof TextElement) { String firstText = ((TextElement) first).getText(); String thirdText = ((TextElement) third).getText(); if ("<".equals(firstText) && ">".equals(thirdText)) { //$NON-NLS-1$ //$NON-NLS-2$ String name = ((SimpleName) second).getIdentifier(); if (name.equals(typeParamName)) { handleContentElements(fragments.subList(3, fragments.size())); break; } } } } } } fBuf = null; return description.length() > 0 ? description : null; } return null; }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
CharSequence getInheritedParamDescription(int paramIndex) throws JavaModelException { if (fMethod != null) { String[] parameterNames = fMethod.getParameterNames(); if (fParamDescriptions == null) { fParamDescriptions = new StringBuffer[parameterNames.length]; } else {/*from w w w . ja v a 2s. c om*/ StringBuffer description = fParamDescriptions[paramIndex]; if (description != null) { return description.length() > 0 ? description : null; } } StringBuffer description = new StringBuffer(); fParamDescriptions[paramIndex] = description; fBuf = description; fLiteralContent = 0; String paramName = parameterNames[paramIndex]; List<TagElement> tags = fJavadoc.tags(); for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) { TagElement tag = iter.next(); String tagName = tag.getTagName(); if (TagElement.TAG_PARAM.equals(tagName)) { List<? extends ASTNode> fragments = tag.fragments(); if (fragments.size() > 0) { Object first = fragments.get(0); if (first instanceof SimpleName) { String name = ((SimpleName) first).getIdentifier(); if (name.equals(paramName)) { handleContentElements(fragments.subList(1, fragments.size())); break; } } } } } fBuf = null; return description.length() > 0 ? description : null; } return null; }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
CharSequence getExceptionDescription(String simpleName) {
if (fMethod != null) {
if (fExceptionDescriptions == null) {
fExceptionDescriptions = new HashMap<>();
} else {/*from w ww. j a va2 s . c om*/
StringBuffer description = fExceptionDescriptions.get(simpleName);
if (description != null) {
return description.length() > 0 ? description : null;
}
}
StringBuffer description = new StringBuffer();
fExceptionDescriptions.put(simpleName, description);
fBuf = description;
fLiteralContent = 0;
List<TagElement> tags = fJavadoc.tags();
for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) {
TagElement tag = iter.next();
String tagName = tag.getTagName();
if (TagElement.TAG_THROWS.equals(tagName) || TagElement.TAG_EXCEPTION.equals(tagName)) {
List<? extends ASTNode> fragments = tag.fragments();
if (fragments.size() > 0) {
Object first = fragments.get(0);
if (first instanceof Name) {
String name = ASTNodes.getSimpleNameIdentifier((Name) first);
if (name.equals(simpleName)) {
if (fragments.size() > 1)
handleContentElements(fragments.subList(1, fragments.size()));
break;
}
}
}
}
}
fBuf = null;
return description.length() > 0 ? description : null;
}
return null;
}
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 va2 s . 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--; }