use of org.eclipse.jdt.core.dom.Javadoc in project xtext-xtend by eclipse.
the class JavaASTFlattener method visit.
@Override
public boolean visit(final EnumConstantDeclaration node) {
Javadoc _javadoc = node.getJavadoc();
boolean _tripleNotEquals = (_javadoc != null);
if (_tripleNotEquals) {
node.getJavadoc().accept(this);
}
this.appendModifiers(node, node.modifiers());
node.getName().accept(this);
boolean _isEmpty = node.arguments().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
this.addProblem(node, "Enum constant cannot have any arguments");
this.appendToBuffer("(");
this.visitAllSeparatedByComma(node.arguments());
this.appendToBuffer(")");
}
AnonymousClassDeclaration _anonymousClassDeclaration = node.getAnonymousClassDeclaration();
boolean _tripleNotEquals_1 = (_anonymousClassDeclaration != null);
if (_tripleNotEquals_1) {
this.addProblem(node, "Enum constant cannot have any anonymous class declarations");
node.getAnonymousClassDeclaration().accept(this);
}
return false;
}
use of org.eclipse.jdt.core.dom.Javadoc in project xtext-eclipse by eclipse.
the class XbaseHoverDocumentationProvider method computeDocumentation.
public String computeDocumentation(EObject object) {
buffer = new StringBuffer();
context = object;
fLiteralContent = 0;
List<String> parameterNames = initParameterNames();
Map<String, URI> exceptionNamesToURI = initExceptionNamesToURI();
addAnnotations(object);
getDocumentationWithPrefix(object);
Javadoc javadoc = getJavaDoc();
if (javadoc == null)
return buffer.toString();
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>();
@SuppressWarnings("unchecked") List<TagElement> tags = javadoc.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);
@SuppressWarnings("unchecked") 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);
@SuppressWarnings("unchecked") List<? extends ASTNode> fragments = tag.fragments();
if (fragments.size() > 0) {
Object first = fragments.get(0);
if (first instanceof Name) {
@SuppressWarnings("restriction") String name = org.eclipse.jdt.internal.corext.dom.ASTNodes.getSimpleNameIdentifier((Name) first);
if (exceptionNamesToURI.containsKey(name)) {
exceptionNamesToURI.put(name, 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);
}
}
boolean hasParameters = parameters.size() > 0;
boolean hasReturnTag = returnTag != null;
boolean hasExceptions = exceptions.size() > 0;
if (deprecatedTag != null)
handleDeprecatedTag(deprecatedTag);
if (start != null) {
@SuppressWarnings("unchecked") List<ASTNode> fragments = start.fragments();
handleContentElements(fragments);
}
if (hasParameters || hasReturnTag || hasExceptions || versions.size() > 0 || authors.size() > 0 || since.size() > 0 || sees.size() > 0 || rest.size() > 0 || (buffer.length() > 0) && (parameterNames.size() > 0 || exceptionNamesToURI.size() > 0)) {
handleSuperMethodReferences(object);
buffer.append(BLOCK_TAG_START);
handleParameters(object, parameters, parameterNames);
handleReturnTag(returnTag);
handleExceptionTags(exceptions, exceptionNamesToURI);
handleBlockTags("Since:", since);
handleBlockTags("Version:", versions);
handleBlockTags("Author:", authors);
handleBlockTags("See Also:", sees);
handleBlockTags(rest);
buffer.append(BLOCK_TAG_END);
} else if (buffer.length() > 0) {
handleSuperMethodReferences(object);
}
String result = buffer.toString();
buffer = null;
rawJavaDoc = null;
context = null;
return result;
}
use of org.eclipse.jdt.core.dom.Javadoc in project eclipse-cs by checkstyle.
the class MethodLimitQuickfix method handleGetCorrectingASTVisitor.
/**
* {@inheritDoc}
*/
protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartOffset) {
return new ASTVisitor() {
@SuppressWarnings("unchecked")
public boolean visit(MethodDeclaration node) {
Javadoc doc = node.getJavadoc();
if (doc == null) {
doc = node.getAST().newJavadoc();
node.setJavadoc(doc);
}
TagElement newTag = node.getAST().newTagElement();
newTag.setTagName("TODO Added by MethodLimit Sample quickfix");
doc.tags().add(0, newTag);
return true;
}
};
}
use of org.eclipse.jdt.core.dom.Javadoc in project eclipse.jdt.ls by eclipse.
the class SelectionRangeHandler method selectionRange.
public List<SelectionRange> selectionRange(SelectionRangeParams params, IProgressMonitor monitor) {
if (params.getPositions() == null || params.getPositions().isEmpty()) {
return Collections.emptyList();
}
ITypeRoot root = JDTUtils.resolveTypeRoot(params.getTextDocument().getUri());
if (root == null) {
return Collections.emptyList();
}
CompilationUnit ast = CoreASTProvider.getInstance().getAST(root, CoreASTProvider.WAIT_YES, monitor);
// extra logic to check within the line comments and block comments, which are not parts of the AST
@SuppressWarnings("unchecked") List<Comment> comments = new ArrayList<Comment>(ast.getCommentList());
comments.removeIf(comment -> {
// Javadoc nodes are already in the AST
return (comment instanceof Javadoc);
});
List<SelectionRange> $ = new ArrayList<>();
for (Position pos : params.getPositions()) {
try {
int offset = JsonRpcHelpers.toOffset(root.getBuffer(), pos.getLine(), pos.getCharacter());
ASTNode node = NodeFinder.perform(ast, offset, 0);
if (node == null) {
continue;
}
// find all the ancestors
List<ASTNode> nodes = new ArrayList<>();
while (node != null) {
nodes.add(node);
node = node.getParent();
}
// find all the ranges corresponding to the parent nodes
SelectionRange selectionRange = null;
ListIterator<ASTNode> iterator = nodes.listIterator(nodes.size());
while (iterator.hasPrevious()) {
node = iterator.previous();
Range range = JDTUtils.toRange(root, node.getStartPosition(), node.getLength());
selectionRange = new SelectionRange(range, selectionRange);
}
// find in comments
ASTNode containingComment = containingComment(comments, offset);
if (containingComment != null) {
Range range = JDTUtils.toRange(root, containingComment.getStartPosition(), containingComment.getLength());
selectionRange = new SelectionRange(range, selectionRange);
}
if (selectionRange != null) {
$.add(selectionRange);
}
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException("Failed to calculate selection range", e);
}
}
return $;
}
use of org.eclipse.jdt.core.dom.Javadoc in project eclipse.jdt.ls by eclipse.
the class JavadocContentAccess method internalGetContentReader.
/**
* Gets a reader for an package fragment's Javadoc comment content from the source attachment.
* The content does contain only the text from the comment without the Javadoc leading star characters.
* Returns <code>null</code> if the package fragment does not contain a Javadoc comment or if no source is available.
* @param fragment The package fragment to get the Javadoc of.
* @return Returns a reader for the Javadoc comment content or <code>null</code> if the member
* does not contain a Javadoc comment or if no source is available
* @throws JavaModelException is thrown when the package fragment's javadoc can not be accessed
* @since 3.4
*/
private static Reader internalGetContentReader(IPackageFragment fragment) throws JavaModelException {
IPackageFragmentRoot root = (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
// 1==> Handle the case when the documentation is present in package-info.java or package-info.class file
boolean isBinary = root.getKind() == IPackageFragmentRoot.K_BINARY;
ITypeRoot packageInfo;
if (isBinary) {
packageInfo = fragment.getClassFile(PACKAGE_INFO_CLASS);
} else {
packageInfo = fragment.getCompilationUnit(PACKAGE_INFO_JAVA);
}
if (packageInfo != null && packageInfo.exists()) {
String source = packageInfo.getSource();
// the source can be null for some of the class files
if (source != null) {
Javadoc javadocNode = getPackageJavadocNode(fragment, source);
if (javadocNode != null) {
int start = javadocNode.getStartPosition();
int length = javadocNode.getLength();
return new JavaDocCommentReader(source, start, start + length - 1);
}
}
}
return null;
}
Aggregations