use of org.eclipse.jdt.core.dom.TagElement in project che by eclipse.
the class JavadocContentAccess2 method getMainDescription.
CharSequence getMainDescription() {
if (fMainDescription == null) {
fMainDescription = new StringBuffer();
fBuf = fMainDescription;
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;
}
use of org.eclipse.jdt.core.dom.TagElement in project che by eclipse.
the class JavadocContentAccess2 method toHTML.
private String toHTML() {
fBuf = new StringBuffer();
fLiteralContent = 0;
// After first loop, non-null entries in the following two lists are missing and need to be inherited:
List<String> parameterNames = initParameterNames();
List<String> exceptionNames = initExceptionNames();
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>();
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)) {
parameters.add(tag);
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);
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)
// the Javadoc tool only shows the first deprecated tag
deprecatedTag = 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[] 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 || 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(parameters, parameterNames, parameterDescriptions);
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();
}
String result = fBuf.toString();
fBuf = null;
return result;
}
use of org.eclipse.jdt.core.dom.TagElement in project che by eclipse.
the class JavadocContentAccess2 method handleBlockTags.
private void handleBlockTags(String title, List<TagElement> tags) {
if (tags.isEmpty())
return;
handleBlockTagTitle(title);
for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext(); ) {
TagElement tag = iter.next();
fBuf.append(BlOCK_TAG_ENTRY_START);
if (TagElement.TAG_SEE.equals(tag.getTagName())) {
handleSeeTag(tag);
} else {
handleContentElements(tag.fragments());
}
fBuf.append(BlOCK_TAG_ENTRY_END);
}
}
use of org.eclipse.jdt.core.dom.TagElement in project che by eclipse.
the class JavadocContentAccess2 method handleContentElements.
private void handleContentElements(List<? extends ASTNode> nodes, boolean skipLeadingWhitespace) {
ASTNode previousNode = null;
for (Iterator<? extends ASTNode> iter = nodes.iterator(); iter.hasNext(); ) {
ASTNode child = iter.next();
if (previousNode != null) {
int previousEnd = previousNode.getStartPosition() + previousNode.getLength();
int childStart = child.getStartPosition();
if (previousEnd > childStart) {
// should never happen, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=304826
Exception exception = new Exception(//$NON-NLS-1$
"Illegal ASTNode positions: previousEnd=" + previousEnd + ", childStart=" + //$NON-NLS-1$
childStart + ", element=" + //$NON-NLS-1$
fElement.getHandleIdentifier() + ", Javadoc:\n" + //$NON-NLS-1$
fSource);
LOG.error(exception.getMessage(), exception);
} else if (previousEnd != childStart) {
// Need to preserve whitespace before a node that's not
// directly following the previous node (e.g. on a new line)
// due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=206518 :
String textWithStars = fSource.substring(previousEnd, childStart);
String text = removeDocLineIntros(textWithStars);
fBuf.append(text);
}
}
previousNode = child;
if (child instanceof TextElement) {
String text = ((TextElement) child).getText();
if (skipLeadingWhitespace) {
//$NON-NLS-1$ //$NON-NLS-2$
text = text.replaceFirst("^\\s+", "");
}
// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=233481 :
//$NON-NLS-1$ //$NON-NLS-2$
text = text.replaceAll("(\r\n?|\n)([ \t]*\\*)", "$1");
handleText(text);
} else if (child instanceof TagElement) {
handleInlineTagElement((TagElement) child);
} else {
// This is unexpected. Fail gracefully by just copying the source.
int start = child.getStartPosition();
String text = fSource.substring(start, start + child.getLength());
fBuf.append(removeDocLineIntros(text));
}
}
}
use of org.eclipse.jdt.core.dom.TagElement in project che by eclipse.
the class JavadocContentAccess2 method handleBlockTags.
private void handleBlockTags(List<TagElement> tags) {
for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext(); ) {
TagElement tag = iter.next();
handleBlockTagTitle(tag.getTagName());
fBuf.append(BlOCK_TAG_ENTRY_START);
handleContentElements(tag.fragments());
fBuf.append(BlOCK_TAG_ENTRY_END);
}
}
Aggregations