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

The following examples show how to use org.eclipse.jdt.core.dom.TagElement#fragments() . 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: XbaseHoverDocumentationProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected 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();
		buffer.append(BlOCK_TAG_ENTRY_START);
		if (TagElement.TAG_SEE.equals(tag.getTagName())) {
			handleSeeTag(tag);
		} else {
			@SuppressWarnings("unchecked")
			List<ASTNode> fragments = tag.fragments();
			handleContentElements(fragments);
		}
		buffer.append(BlOCK_TAG_ENTRY_END);
	}
}
 
Example 2
Source File: JavadocTagsSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static String getArgument(TagElement curr) {
	List<? extends ASTNode> fragments= curr.fragments();
	if (!fragments.isEmpty()) {
		Object first= fragments.get(0);
		if (first instanceof Name) {
			return ASTNodes.getSimpleNameIdentifier((Name) first);
		} else if (first instanceof TextElement && TagElement.TAG_PARAM.equals(curr.getTagName())) {
			String text= ((TextElement) first).getText();
			if ("<".equals(text) && fragments.size() >= 3) { //$NON-NLS-1$
				Object second= fragments.get(1);
				Object third= fragments.get(2);
				if (second instanceof Name && third instanceof TextElement && ">".equals(((TextElement) third).getText())) { //$NON-NLS-1$
					return '<' + ASTNodes.getSimpleNameIdentifier((Name) second) + '>';
				}
			} else if (text.startsWith(String.valueOf('<')) && text.endsWith(String.valueOf('>')) && text.length() > 2) {
				return text.substring(1, text.length() - 1);
			}
		}
	}
	return null;
}
 
Example 3
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 4
Source File: ImportReferencesCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean visit(TagElement node) {
	String tagName= node.getTagName();
	List<? extends ASTNode> list= node.fragments();
	int idx= 0;
	if (tagName != null && !list.isEmpty()) {
		Object first= list.get(0);
		if (first instanceof Name) {
			if ("@throws".equals(tagName) || "@exception".equals(tagName)) {  //$NON-NLS-1$//$NON-NLS-2$
				typeRefFound((Name) first);
			} else if ("@see".equals(tagName) || "@link".equals(tagName) || "@linkplain".equals(tagName)) {  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
				Name name= (Name) first;
				possibleTypeRefFound(name);
			}
			idx++;
		}
	}
	for (int i= idx; i < list.size(); i++) {
		doVisitNode(list.get(i));
	}
	return false;
}
 
Example 5
Source File: JavadocTagsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static String getArgument(TagElement curr) {
	List<? extends ASTNode> fragments= curr.fragments();
	if (!fragments.isEmpty()) {
		Object first= fragments.get(0);
		if (first instanceof Name) {
			return ASTNodes.getSimpleNameIdentifier((Name) first);
		} else if (first instanceof TextElement && TagElement.TAG_PARAM.equals(curr.getTagName())) {
			String text= ((TextElement) first).getText();
			if ("<".equals(text) && fragments.size() >= 3) { //$NON-NLS-1$
				Object second= fragments.get(1);
				Object third= fragments.get(2);
				if (second instanceof Name && third instanceof TextElement && ">".equals(((TextElement) third).getText())) { //$NON-NLS-1$
					return '<' + ASTNodes.getSimpleNameIdentifier((Name) second) + '>';
				}
			} else if (text.startsWith(String.valueOf('<')) && text.endsWith(String.valueOf('>')) && text.length() > 2) {
				return text.substring(1, text.length() - 1);
			}
		}
	}
	return null;
}
 
Example 6
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 7
Source File: XbaseHoverDocumentationProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void handleBlockTags(List<TagElement> tags) {
	for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) {
		TagElement tag = iter.next();
		handleBlockTagTitle(tag.getTagName());
		buffer.append(BlOCK_TAG_ENTRY_START);
		@SuppressWarnings("unchecked")
		List<ASTNode> fragments = tag.fragments();
		handleContentElements(fragments);
		buffer.append(BlOCK_TAG_ENTRY_END);
	}
}
 
Example 8
Source File: XbaseHoverDocumentationProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void handleThrowsTag(TagElement tag) {
	@SuppressWarnings("unchecked")
	List<? extends ASTNode> fragments = tag.fragments();
	int size = fragments.size();
	if (size > 0) {
		handleLink(fragments.subList(0, 1));
		if (size > 1) {
			buffer.append(JavaElementLabels.CONCAT_STRING);
			handleContentElements(fragments.subList(1, size));
		}
	}
}
 
Example 9
Source File: XbaseHoverDocumentationProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void handleDeprecatedTag(TagElement tag) {
	buffer.append("<p><b>"); //$NON-NLS-1$
	//TODO: Messages out of properties like in JDT?
	buffer.append("Deprecated.");
	buffer.append("</b> <i>"); //$NON-NLS-1$
	@SuppressWarnings("unchecked")
	List<ASTNode> fragments = tag.fragments();
	handleContentElements(fragments);
	buffer.append("</i></p>"); //$NON-NLS-1$
}
 
Example 10
Source File: XbaseHoverDocumentationProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void handleReturnTag(TagElement tag) {
	if (tag == null)
		return;
	handleBlockTagTitle("Returns:");
	buffer.append(BlOCK_TAG_ENTRY_START);
	@SuppressWarnings("unchecked")
	List<ASTNode> fragments = tag.fragments();
	handleContentElements(fragments);
	buffer.append(BlOCK_TAG_ENTRY_END);
}
 
Example 11
Source File: JavadocContentAccess2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void handleBlockTags(List<TagElement> tags) {
	for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) {
		TagElement tag = iter.next();
		handleBlockTagTitle(tag.getTagName());
		List fragments = tag.fragments();
		if (!fragments.isEmpty()) {
			fBuf.append(BLOCK_TAG_START);
			fBuf.append(BlOCK_TAG_ENTRY_START);
			handleContentElements(fragments);
			fBuf.append(BlOCK_TAG_ENTRY_END);
			fBuf.append(BLOCK_TAG_END);
		}
		fBuf.append(BlOCK_TAG_ENTRY_END);
	}
}
 
Example 12
Source File: JavadocContentAccess2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void handleThrowsTag(TagElement tag) {
	List<? extends ASTNode> fragments = tag.fragments();
	int size = fragments.size();
	if (size > 0) {
		handleLink(fragments.subList(0, 1));
		if (size > 1) {
			fBuf.append(JavaElementLabels.CONCAT_STRING);
			handleContentElements(fragments.subList(1, size));
		}
	}
}
 
Example 13
Source File: JavadocContentAccess2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void handleThrowsTag(TagElement tag) {
	List<? extends ASTNode> fragments= tag.fragments();
	int size= fragments.size();
	if (size > 0) {
		handleLink(fragments.subList(0, 1));
		if (size > 1) {
			fBuf.append(JavaElementLabels.CONCAT_STRING);
			handleContentElements(fragments.subList(1, size));
		}
	}
}
 
Example 14
Source File: SService.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private String extractFullText(TagElement tagElement) {
	StringBuilder builder = new StringBuilder();
	for (Object fragment : tagElement.fragments()) {
		if (fragment instanceof TextElement) {
			TextElement textElement = (TextElement) fragment;
			builder.append(textElement.getText() + " ");
		}
	}
	return builder.toString().trim();
}
 
Example 15
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 16
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;
		}
	}
}