Java Code Examples for org.eclipse.jdt.core.dom.TagElement#getTagName()

The following examples show how to use org.eclipse.jdt.core.dom.TagElement#getTagName() . 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: 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 2
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 3
Source File: JavadocContentAccess2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
CharSequence getReturnDescription() {
	if (fReturnDescription == null) {
		fReturnDescription= new StringBuffer();
		fBuf= fReturnDescription;
		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;
}
 
Example 4
Source File: JavadocContentAccess2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example 5
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 6
Source File: JavadocContentAccess2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
CharSequence getReturnDescription() {
	if (fReturnDescription == null) {
		fReturnDescription = new StringBuffer();
		fBuf = fReturnDescription;
		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;
}
 
Example 7
Source File: JavadocContentAccess2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example 8
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 9
Source File: JavadocTagsSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static void insertTag(ListRewrite rewriter, TagElement newElement, Set<String> sameKindLeadingNames, TextEditGroup groupDescription) {
	List<? extends ASTNode> tags= rewriter.getRewrittenList();

	String insertedTagName= newElement.getTagName();

	ASTNode after= null;
	int tagRanking= getTagRanking(insertedTagName);
	for (int i= tags.size() - 1; i >= 0; i--) {
		TagElement curr= (TagElement) tags.get(i);
		String tagName= curr.getTagName();
		if (tagName == null || tagRanking > getTagRanking(tagName)) {
			after= curr;
			break;
		}
		if (sameKindLeadingNames != null && isSameTag(insertedTagName, tagName)) {
			String arg= getArgument(curr);
			if (arg != null && sameKindLeadingNames.contains(arg)) {
				after= curr;
				break;
			}
		}
	}
	if (after != null) {
		rewriter.insertAfter(newElement, after, groupDescription);
	} else {
		rewriter.insertFirst(newElement, groupDescription);
	}
}
 
Example 10
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final TagElement node) {
  boolean _isNested = node.isNested();
  if (_isNested) {
    this.appendToBuffer("{");
  } else {
    this.appendLineWrapToBuffer();
    this.appendToBuffer(" * ");
  }
  boolean previousRequiresWhiteSpace = false;
  String _tagName = node.getTagName();
  boolean _tripleNotEquals = (_tagName != null);
  if (_tripleNotEquals) {
    this.appendToBuffer(node.getTagName());
    previousRequiresWhiteSpace = true;
  }
  boolean previousRequiresNewLine = false;
  for (Iterator<? extends ASTNode> it = node.fragments().iterator(); it.hasNext();) {
    {
      ASTNode e = it.next();
      boolean currentIncludesWhiteSpace = (e instanceof TextElement);
      if ((previousRequiresNewLine && currentIncludesWhiteSpace)) {
        this.appendLineWrapToBuffer();
        this.appendToBuffer(" * ");
      }
      previousRequiresNewLine = currentIncludesWhiteSpace;
      if ((previousRequiresWhiteSpace && (!currentIncludesWhiteSpace))) {
        this.appendSpaceToBuffer();
      }
      e.accept(this);
      previousRequiresWhiteSpace = ((!currentIncludesWhiteSpace) && (!(e instanceof TagElement)));
    }
  }
  boolean _isNested_1 = node.isNested();
  if (_isNested_1) {
    this.appendToBuffer("}");
  }
  return false;
}
 
Example 11
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 12
Source File: JavadocLineBreakPreparator.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private boolean isSquashRequired(TagElement node, ASTNode declaration) {
	if (declaration instanceof TypeDeclaration) {
		String tagName = node.getTagName();
		return (!node.isNested() && tagName != null && tagName.startsWith("@"));
	}
	return PARAM_TAGS.contains(node.getTagName());
}
 
Example 13
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 14
Source File: JavadocContentAccess2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void handleInlineTagElement(TagElement node) {
	String name= node.getTagName();
	
	if (TagElement.TAG_VALUE.equals(name) && handleValueTag(node))
		return;

	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--;

}
 
Example 15
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 16
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 17
Source File: JavadocTagsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void insertTag(ListRewrite rewriter, TagElement newElement, Set<String> sameKindLeadingNames, TextEditGroup groupDescription) {
	List<? extends ASTNode> tags= rewriter.getRewrittenList();

	String insertedTagName= newElement.getTagName();

	ASTNode after= null;
	int tagRanking= getTagRanking(insertedTagName);
	for (int i= tags.size() - 1; i >= 0; i--) {
		TagElement curr= (TagElement) tags.get(i);
		String tagName= curr.getTagName();
		if (tagName == null || tagRanking > getTagRanking(tagName)) {
			after= curr;
			break;
		}
		if (sameKindLeadingNames != null && isSameTag(insertedTagName, tagName)) {
			String arg= getArgument(curr);
			if (arg != null && sameKindLeadingNames.contains(arg)) {
				after= curr;
				break;
			}
		}
	}
	if (after != null) {
		rewriter.insertAfter(newElement, after, groupDescription);
	} else {
		rewriter.insertFirst(newElement, groupDescription);
	}
}
 
Example 18
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 19
Source File: JavadocContentAccess2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void handleInlineTagElement(TagElement node) {
	String name = node.getTagName();

	if (TagElement.TAG_VALUE.equals(name) && handleValueTag(node)) {
		return;
	}

	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 (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 (isCode) {
		fBuf.append("</code>"); //$NON-NLS-1$
	}
	if (isLiteral || isCode) {
		fLiteralContent--;
	}

}
 
Example 20
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;
		}
	}
}