Java Code Examples for org.eclipse.jdt.core.dom.Javadoc#tags()

The following examples show how to use org.eclipse.jdt.core.dom.Javadoc#tags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavadocTagsSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static TagElement findTag(Javadoc javadoc, String name, String arg) {
	List<TagElement> tags= javadoc.tags();
	int nTags= tags.size();
	for (int i= 0; i < nTags; i++) {
		TagElement curr= tags.get(i);
		if (name.equals(curr.getTagName())) {
			if (arg != null) {
				String argument= getArgument(curr);
				if (arg.equals(argument)) {
					return curr;
				}
			} else {
				return curr;
			}
		}
	}
	return null;
}
 
Example 2
Source File: UMLModelASTReader.java    From RefactoringMiner with MIT License 6 votes vote down vote up
private UMLJavadoc generateJavadoc(BodyDeclaration bodyDeclaration) {
	UMLJavadoc doc = null;
	Javadoc javaDoc = bodyDeclaration.getJavadoc();
	if(javaDoc != null) {
		doc = new UMLJavadoc();
		List<TagElement> tags = javaDoc.tags();
		for(TagElement tag : tags) {
			UMLTagElement tagElement = new UMLTagElement(tag.getTagName());
			List fragments = tag.fragments();
			for(Object docElement : fragments) {
				tagElement.addFragment(docElement.toString());
			}
			doc.addTag(tagElement);
		}
	}
	return doc;
}
 
Example 3
Source File: JavadocTagsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static TagElement findTag(Javadoc javadoc, String name, String arg) {
	List<TagElement> tags= javadoc.tags();
	int nTags= tags.size();
	for (int i= 0; i < nTags; i++) {
		TagElement curr= tags.get(i);
		if (name.equals(curr.getTagName())) {
			if (arg != null) {
				String argument= getArgument(curr);
				if (arg.equals(argument)) {
					return curr;
				}
			} else {
				return curr;
			}
		}
	}
	return null;
}
 
Example 4
Source File: MoveMethodRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
private void addParamTagElementToJavadoc(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter, String parameterToBeAdded) {
	if(newMethodDeclaration.getJavadoc() != null) {
		AST ast = newMethodDeclaration.getAST();
		Javadoc javadoc = newMethodDeclaration.getJavadoc();
		List<TagElement> tags = javadoc.tags();
		TagElement returnTagElement = null;
		for(TagElement tag : tags) {
			if(tag.getTagName() != null && tag.getTagName().equals(TagElement.TAG_RETURN)) {
				returnTagElement = tag;
				break;
			}
		}
		
		TagElement tagElement = ast.newTagElement();
		targetRewriter.set(tagElement, TagElement.TAG_NAME_PROPERTY, TagElement.TAG_PARAM, null);
		ListRewrite fragmentsRewrite = targetRewriter.getListRewrite(tagElement, TagElement.FRAGMENTS_PROPERTY);
		SimpleName paramName = ast.newSimpleName(parameterToBeAdded);
		fragmentsRewrite.insertLast(paramName, null);
		
		ListRewrite tagsRewrite = targetRewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);
		if(returnTagElement != null)
			tagsRewrite.insertBefore(tagElement, returnTagElement, null);
		else
			tagsRewrite.insertLast(tagElement, null);
	}
}
 
Example 5
Source File: MoveMethodRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
private void removeParamTagElementFromJavadoc(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter, String parameterToBeRemoved) {
	if(newMethodDeclaration.getJavadoc() != null) {
		Javadoc javadoc = newMethodDeclaration.getJavadoc();
		List<TagElement> tags = javadoc.tags();
		for(TagElement tag : tags) {
			if(tag.getTagName() != null && tag.getTagName().equals(TagElement.TAG_PARAM)) {
				List<ASTNode> tagFragments = tag.fragments();
				boolean paramFound = false;
				for(ASTNode node : tagFragments) {
					if(node instanceof SimpleName) {
						SimpleName simpleName = (SimpleName)node;
						if(simpleName.getIdentifier().equals(parameterToBeRemoved)) {
							paramFound = true;
							break;
						}
					}
				}
				if(paramFound) {
					ListRewrite tagsRewrite = targetRewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);
					tagsRewrite.remove(tag, null);
					break;
				}
			}
		}
	}
}
 
Example 6
Source File: JavadocTagsSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static TagElement findParamTag(Javadoc javadoc, String arg) {
	List<TagElement> tags= javadoc.tags();
	int nTags= tags.size();
	for (int i= 0; i < nTags; i++) {
		TagElement curr= tags.get(i);
		String currName= curr.getTagName();
		if (TagElement.TAG_PARAM.equals(currName)) {
			String argument= getArgument(curr);
			if (arg.equals(argument)) {
				return curr;
			}
		}
	}
	return null;
}
 
Example 7
Source File: JavadocTagsSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static TagElement findThrowsTag(Javadoc javadoc, String arg) {
	List<TagElement> tags= javadoc.tags();
	int nTags= tags.size();
	for (int i= 0; i < nTags; i++) {
		TagElement curr= tags.get(i);
		String currName= curr.getTagName();
		if (TagElement.TAG_THROWS.equals(currName) || TagElement.TAG_EXCEPTION.equals(currName)) {
			String argument= getArgument(curr);
			if (arg.equals(argument)) {
				return curr;
			}
		}
	}
	return null;
}
 
Example 8
Source File: AstUtils.java    From RefactoringMiner with MIT License 5 votes vote down vote up
public static boolean containsDeprecatedTag(Javadoc javadoc) {
	if (javadoc == null) {
		return false;
	}
	List<TagElement> javadocTags = (List<TagElement>) javadoc.tags();
	for (TagElement tag : javadocTags) {
		if ("@deprecated".equals(tag.getTagName())) {
			return true;
		}
	}
	return false;
}
 
Example 9
Source File: JavadocUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Decide whether to add a "param" javadoc tag or not.
 * @param methodDeclaration the method declaration
 * @return method has javadoc && (method had no parameter before || there is already an @param tag)
 */
public static boolean shouldAddParamJavadoc(MethodDeclaration methodDeclaration) {
	Javadoc javadoc= methodDeclaration.getJavadoc();
	if (javadoc == null)
		return false;
	if (methodDeclaration.parameters().size() == 0)
		return true;
	List<TagElement> tags= javadoc.tags();
	for (Iterator<TagElement> iter= tags.iterator(); iter.hasNext();) {
		TagElement element= iter.next();
		if (TagElement.TAG_PARAM.equals(element.getTagName()))
			return true;
	}
	return false;
}
 
Example 10
Source File: ExceptionOccurrencesFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(MethodDeclaration node) {
	Javadoc javadoc= node.getJavadoc();
	if (javadoc != null) {
		List<TagElement> tags= javadoc.tags();
		for (TagElement tag : tags) {
			String tagName= tag.getTagName();
			if (TagElement.TAG_EXCEPTION.equals(tagName) || TagElement.TAG_THROWS.equals(tagName)) {
				ASTNode name= (ASTNode) tag.fragments().get(0);
				if (name instanceof Name) {
					if (name != fSelectedNode && Bindings.equals(fException, ((Name) name).resolveBinding())) {
						fResult.add(new OccurrenceLocation(name.getStartPosition(), name.getLength(), 0, fDescription));
					}
				}
			}
		}
	}
	List<Type> thrownExceptionTypes= node.thrownExceptionTypes();
	for (Iterator<Type> iter= thrownExceptionTypes.iterator(); iter.hasNext(); ) {
		Type type = iter.next();
		if (type != fSelectedNode && Bindings.equals(fException, type.resolveBinding())) {
			fResult.add(new OccurrenceLocation(type.getStartPosition(), type.getLength(), 0, fDescription));
		}
	}
	Block body= node.getBody();
	if (body != null) {
		node.getBody().accept(this);
	}
	return false;
}
 
Example 11
Source File: JavadocTagsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static TagElement findParamTag(Javadoc javadoc, String arg) {
	List<TagElement> tags= javadoc.tags();
	int nTags= tags.size();
	for (int i= 0; i < nTags; i++) {
		TagElement curr= tags.get(i);
		String currName= curr.getTagName();
		if (TagElement.TAG_PARAM.equals(currName)) {
			String argument= getArgument(curr);
			if (arg.equals(argument)) {
				return curr;
			}
		}
	}
	return null;
}
 
Example 12
Source File: JavadocTagsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static TagElement findThrowsTag(Javadoc javadoc, String arg) {
	List<TagElement> tags= javadoc.tags();
	int nTags= tags.size();
	for (int i= 0; i < nTags; i++) {
		TagElement curr= tags.get(i);
		String currName= curr.getTagName();
		if (TagElement.TAG_THROWS.equals(currName) || TagElement.TAG_EXCEPTION.equals(currName)) {
			String argument= getArgument(curr);
			if (arg.equals(argument)) {
				return curr;
			}
		}
	}
	return null;
}
 
Example 13
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates the method comment for the target method declaration.
 *
 * @param rewrite
 *            the source ast rewrite
 * @param declaration
 *            the source method declaration
 * @throws JavaModelException
 *             if the argument references could not be generated
 */
protected void createMethodComment(final ASTRewrite rewrite, final MethodDeclaration declaration) throws JavaModelException {
	Assert.isNotNull(rewrite);
	Assert.isNotNull(declaration);
	final Javadoc comment= declaration.getJavadoc();
	if (comment != null) {
		final List<TagElement> tags= new LinkedList<TagElement>(comment.tags());
		final IVariableBinding[] bindings= getArgumentBindings(declaration);
		final Map<String, TagElement> elements= new HashMap<String, TagElement>(bindings.length);
		String name= null;
		List<? extends ASTNode> fragments= null;
		TagElement element= null;
		TagElement reference= null;
		IVariableBinding binding= null;
		for (int index= 0; index < bindings.length; index++) {
			binding= bindings[index];
			for (final Iterator<TagElement> iterator= comment.tags().iterator(); iterator.hasNext();) {
				element= iterator.next();
				name= element.getTagName();
				fragments= element.fragments();
				if (name != null) {
					if (name.equals(TagElement.TAG_PARAM) && !fragments.isEmpty() && fragments.get(0) instanceof SimpleName) {
						final SimpleName simple= (SimpleName) fragments.get(0);
						if (binding.getName().equals(simple.getIdentifier())) {
							elements.put(binding.getKey(), element);
							tags.remove(element);
						}
					} else if (reference == null)
						reference= element;
				}
			}
		}
		if (bindings.length == 0 && reference == null) {
			for (final Iterator<TagElement> iterator= comment.tags().iterator(); iterator.hasNext();) {
				element= iterator.next();
				name= element.getTagName();
				fragments= element.fragments();
				if (name != null && !name.equals(TagElement.TAG_PARAM))
					reference= element;
			}
		}
		final List<ASTNode> arguments= new ArrayList<ASTNode>(bindings.length + 1);
		createArgumentList(declaration, arguments, new IArgumentFactory() {

			public final ASTNode getArgumentNode(final IVariableBinding argument, final boolean last) throws JavaModelException {
				Assert.isNotNull(argument);
				if (elements.containsKey(argument.getKey()))
					return rewrite.createCopyTarget(elements.get(argument.getKey()));
				return JavadocUtil.createParamTag(argument.getName(), declaration.getAST(), fMethod.getJavaProject());
			}

			public final ASTNode getTargetNode() throws JavaModelException {
				return JavadocUtil.createParamTag(fTargetName, declaration.getAST(), fMethod.getJavaProject());
			}
		});
		final ListRewrite rewriter= rewrite.getListRewrite(comment, Javadoc.TAGS_PROPERTY);
		ASTNode tag= null;
		for (final Iterator<TagElement> iterator= comment.tags().iterator(); iterator.hasNext();) {
			tag= iterator.next();
			if (!tags.contains(tag))
				rewriter.remove(tag, null);
		}
		for (final Iterator<ASTNode> iterator= arguments.iterator(); iterator.hasNext();) {
			tag= iterator.next();
			if (reference != null)
				rewriter.insertBefore(tag, reference, null);
			else
				rewriter.insertLast(tag, null);
		}
	}
}
 
Example 14
Source File: SystemObject.java    From JDeodorant with MIT License 4 votes vote down vote up
private void inheritanceHierarchyMatchingWithStaticTypes(TypeCheckElimination typeCheckElimination,
		CompleteInheritanceDetection inheritanceDetection) {
	List<SimpleName> staticFields = typeCheckElimination.getStaticFields();
	String abstractClassType = typeCheckElimination.getAbstractClassType();
	InheritanceTree tree = null;
	if(abstractClassType != null)
		tree = inheritanceDetection.getTree(abstractClassType);
	if(tree != null) {
		DefaultMutableTreeNode rootNode = tree.getRootNode();
		DefaultMutableTreeNode leaf = rootNode.getFirstLeaf();
		List<String> inheritanceHierarchySubclassNames = new ArrayList<String>();
		while(leaf != null) {
			inheritanceHierarchySubclassNames.add((String)leaf.getUserObject());
			leaf = leaf.getNextLeaf();
		}
		int matchCounter = 0;
		for(SimpleName staticField : staticFields) {
			for(String subclassName : inheritanceHierarchySubclassNames) {
				ClassObject classObject = getClassObject(subclassName);
				AbstractTypeDeclaration abstractTypeDeclaration = classObject.getAbstractTypeDeclaration();
				if(abstractTypeDeclaration instanceof TypeDeclaration) {
					TypeDeclaration typeDeclaration = (TypeDeclaration)abstractTypeDeclaration;
					Javadoc javadoc = typeDeclaration.getJavadoc();
					if(javadoc != null) {
						List<TagElement> tagElements = javadoc.tags();
						for(TagElement tagElement : tagElements) {
							if(tagElement.getTagName() != null && tagElement.getTagName().equals(TagElement.TAG_SEE)) {
								List<ASTNode> fragments = tagElement.fragments();
								for(ASTNode fragment : fragments) {
									if(fragment instanceof MemberRef) {
										MemberRef memberRef = (MemberRef)fragment;
										IBinding staticFieldNameBinding = staticField.resolveBinding();
										ITypeBinding staticFieldNameDeclaringClass = null;
										if(staticFieldNameBinding != null && staticFieldNameBinding.getKind() == IBinding.VARIABLE) {
											IVariableBinding staticFieldNameVariableBinding = (IVariableBinding)staticFieldNameBinding;
											staticFieldNameDeclaringClass = staticFieldNameVariableBinding.getDeclaringClass();
										}
										if(staticFieldNameBinding.getName().equals(memberRef.getName().getIdentifier()) &&
												staticFieldNameDeclaringClass.getQualifiedName().equals(memberRef.getQualifier().getFullyQualifiedName())) {
											typeCheckElimination.putStaticFieldSubclassTypeMapping(staticField, subclassName);
											matchCounter++;
											break;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		if(matchCounter == staticFields.size()) {
			typeCheckElimination.setInheritanceTreeMatchingWithStaticTypes(tree);
			return;
		}
	}
}