List of usage examples for org.eclipse.jdt.core.dom TagElement toString
@Override public final String toString()
From source file:chibi.gumtreediff.gen.jdt.JdtVisitor.java
License:Open Source License
@Override public boolean visit(TagElement e) { e.toString(); return true; }
From source file:com.t3.doccreator.MethodDefinition.java
License:Open Source License
private void parseDoc(Javadoc javadoc) { javadoc.accept(new ASTVisitor(true) { @Override/*from w w w. j a v a2s .c o m*/ public boolean visit(TagElement node) { List<?> f = node.fragments(); if (node.getTagName() == null) for (Object o : f) { if (o instanceof TextElement) doc += ((TextElement) o).getText(); else if (o instanceof TagElement) { TagElement te = (TagElement) o; if (te.getTagName().equals("@link")) { if (te.fragments().size() == 2) doc += te.fragments().get(1).toString(); else if (te.fragments().size() == 1) doc += te.fragments().get(0).toString().substring(1); else throw new Error(); } else throw new Error(); } else throw new Error(); } else if (f.size() >= 2 && node.getTagName().equals("@param")) try { parameters.get(((SimpleName) f.get(0)).toString()).setComment(f.subList(1, f.size()) .stream().map(Object::toString).collect(Collectors.joining())); } catch (NullPointerException npe) { System.err.println("NPE for " + getName() + " -> " + ((SimpleName) f.get(0)).toString()); } else if (node.getTagName().equals("@return")) returnComment = f.stream().map(Object::toString).collect(Collectors.joining("\n")); else if (f.size() == 2 && node.getTagName().equals("@throws")) errorComment = ((TextElement) f.get(1)).getText(); else if (node.getTagName().equals("@author")) ; else if (node.getTagName().equals("@see")) ; else throw new Error(node.toString()); return false; } }); String[] lines = doc.split("\n"); doc = ""; for (String l : lines) { l = l.trim(); if (l.startsWith("*")) l = l.substring(1); if (l.startsWith("/**")) l = l.substring(3); if (l.startsWith("**/")) l = l.substring(3); if (l.endsWith("/")) l = l.substring(0, l.length() - 1); doc += l.trim() + "\n"; } }
From source file:com.tsc9526.monalisa.plugin.eclipse.tools.PluginHelper.java
License:Open Source License
public static String getJavadocField(Javadoc doc, String property) { String value = null;/*from w ww .j av a 2 s .c o m*/ if (doc != null && doc.isDocComment()) { for (Object o : doc.tags()) { TagElement tag = (TagElement) o; String tn = tag.getTagName(); if (property.equals(tn)) { value = tag.toString(); int p = value.indexOf(property); value = value.substring(p + property.length()).trim(); break; } } } return value; }
From source file:ctrus.pa.bow.java.token.ClassTokens.java
License:Apache License
@SuppressWarnings("unchecked") private void addTokensFromJavaDoc(Javadoc jd) { if (jd != null) { List<TagElement> jDocComments = (List<TagElement>) jd.tags(); for (TagElement jDocComment : jDocComments) { addCommentToken(jDocComment.toString()); }//w w w .java2 s .c o m } }
From source file:ctrus.pa.bow.java.token.MethodTokens.java
License:Apache License
@Override @SuppressWarnings("unchecked") public void addTokens(ASTNode node) { // Check if the node is a MethodDeclaration if (!(node instanceof MethodDeclaration)) throw new IllegalArgumentException( "Expecting method declaration but found " + node.getClass().getName()); MethodDeclaration mth = (MethodDeclaration) node; // Add method name String methodName = mth.getName().getFullyQualifiedName(); addInterfaceToken(methodName);// w w w . j av a 2s . c o m // Add method declaration parameters and create unique method name String uniqueMethodName = ""; uniqueMethodName = methodName; for (SingleVariableDeclaration param : (List<SingleVariableDeclaration>) mth.parameters()) { if (!_stateAnalysis) { addInterfaceToken(param.getName().getIdentifier()); addInterfaceToken(param.getType().toString()); } uniqueMethodName = uniqueMethodName + " " + param.getType().toString(); } // Set the identifier of this token-set setIdentifier(uniqueMethodName); // Add return type if (!mth.isConstructor()) { boolean skipReturn = false; Type mthReturn = mth.getReturnType2(); if (mthReturn == null) { skipReturn = true; } else if (mthReturn.isPrimitiveType()) { if (PrimitiveType.VOID.equals(((PrimitiveType) mthReturn).getPrimitiveTypeCode())) skipReturn = true; } if (!skipReturn) addInterfaceToken(mthReturn.toString()); } // update method identifier position in the Java source text updateIdentifierPosition(mth); // Add exceptions thrown by method if (!_stateAnalysis) { for (Object exception : mth.thrownExceptionTypes()) { addInterfaceToken(((SimpleType) exception).getName().getFullyQualifiedName()); } } // Visit the method body to collect terms Block block = mth.getBody(); if (_hasBody && block != null) { // Found method body block.accept(new ASTVisitor() { public boolean visit(StringLiteral node) { if (!_stateAnalysis) { addToken(node.toString()); } return true; } public boolean visit(SimpleName node) { addToken(node.toString()); return true; } }); } // Add java doc comment found for the method if (!_ignoreComments && !_stateAnalysis && mth.getJavadoc() != null) { List<TagElement> jDocComments = (List<TagElement>) mth.getJavadoc().tags(); for (TagElement jDocComment : jDocComments) { addCommentToken(jDocComment.toString()); } } }
From source file:de.akra.idocit.java.services.AbsJavadocParser.java
License:Apache License
/** * Converts the Javdoc to a list of {@link Documentation}s. The * {@link Documentation#getSignatureElementIdentifier()} is set to a simple path of * the Javadoc tag, so that the {@link Documentation}s can be assigned to right * {@link SignatureElement}s later.//from w w w.jav a 2s . c o m * <p> * Example:<br /> * <ul> * <li>General description => <code>signatureElementIdentifier = null</code></li> * <li>@param paramName => * <code>signatureElementIdentifier = {@link #CONVERTED_JAVADOC_TAG_PARAM} + {@link JavaParser#delimiters}.pathDelimiter + paramName</code> * <li>@return => * <code>signatureElementIdentifier = {@link #CONVERTED_JAVADOC_TAG_RETURN}</code> * <li>@throws exceptionName => * <code>signatureElementIdentifier = {@link #CONVERTED_JAVADOC_TAG_THROWS} + {@link JavaParser#delimiters}.pathDelimiter + exceptionName</code> * </li> * </ul> * </p> * * @param javadoc * The Javadoc to convert to {@link Documentation}s. * @return a list of {@link Documentation}s. * @since 0.0.2 */ @SuppressWarnings("unchecked") public List<Documentation> convertExistingJavadoc(Javadoc javadoc) { List<Documentation> foundDocs = Collections.emptyList(); if (javadoc != null) { foundDocs = new ArrayList<Documentation>(javadoc.tags().size()); // TODO make the used addressee adjustable via the Preference Pages final Addressee developer = DescribedItemUtils.findAddressee("Developer"); for (final TagElement tag : (List<TagElement>) javadoc.tags()) { final Documentation doc = new Documentation(); String comment = null; if (tag.getTagName() == null) { comment = JavadocUtils.readFragments((List<ASTNode>) tag.fragments(), 0); } else if (tag.getTagName().matches(JAVADOC_TAG_RETURN)) { comment = JavadocUtils.readFragments((List<ASTNode>) tag.fragments(), 0).trim(); doc.setSignatureElementIdentifier(CONVERTED_JAVADOC_TAG_RETURN); } else if (tag.getTagName().matches(JAVADOC_TAG_PARAM) || tag.getTagName().matches(JAVADOC_TAG_THROWS)) { comment = JavadocUtils.readFragments((List<ASTNode>) tag.fragments(), 1); final ASTNode paramName = (ASTNode) tag.fragments().get(0); if (ASTNode.SIMPLE_NAME == paramName.getNodeType()) { final SimpleName name = (SimpleName) paramName; String identifier = null; if (tag.getTagName().matches(JAVADOC_TAG_PARAM)) { identifier = CONVERTED_JAVADOC_TAG_PARAM + JavaParser.delimiters.getPathDelimiter() + name.getIdentifier(); } else { identifier = CONVERTED_JAVADOC_TAG_THROWS + JavaParser.delimiters.getPathDelimiter() + name.getIdentifier(); } doc.setSignatureElementIdentifier(identifier); } else { log.warning("Javadoc Parameter name is not available: " + tag.toString()); } } else { log.log(Level.FINE, "Javadoc tag is not converted: " + tag); } if (comment != null) { doc.getDocumentation().put(developer, comment); doc.getAddresseeSequence().add(developer); foundDocs.add(doc); } } } return foundDocs; }
From source file:de.akra.idocit.java.services.SimpleJavadocParser.java
License:Apache License
private String extractParentIdentifierPath(String identifier, TagElement tagElement, List<? extends Parameter> parameters, JavaMethod method) { Javadoc javadoc = (Javadoc) tagElement.getParent(); String parentParamIdentifier = readParentParamterName(javadoc, tagElement, method); if (!parentParamIdentifier.isEmpty()) { JavaParameter parentParam = findParameterByName(parameters, parentParamIdentifier); if (parentParam != null) { return parentParam.getSignatureElementPath(); } else {/* w ww. ja v a 2 s . co m*/ log.info("No parent parameter found for tag element " + String.valueOf(tagElement.toString())); } } else { // jakr: if no parent is found, leave the identifier initialized with // null. In this case there must be an invalid ordering of the Javadoc // tags (@subparam without @param above). } return StringUtils.EMPTY; }
From source file:de.akra.idocit.java.services.SimpleJavadocParser.java
License:Apache License
private String extractIdentifierPath(String identifier, TagElement tagElement, List<? extends Parameter> parameters, JavaMethod method) throws ParsingException { String[] parameterNames = extractIdentifierChain(identifier); Javadoc javadoc = (Javadoc) tagElement.getParent(); String parentParamIdentifier = readParentParamterName(javadoc, tagElement, method); if (!parentParamIdentifier.isEmpty()) { JavaParameter parentParam = findParameterByName(parameters, parentParamIdentifier); if (parentParam != null) { if (parameterNames.length >= 1) { JavaParameter childParameter = findParameterByName(parentParam.getComplexType(), parameterNames[0]); int i = 1; while (i < parameterNames.length) { if (childParameter != null) { childParameter = findParameterByName(childParameter.getComplexType(), parameterNames[i]); } else { throw new ParsingException("No more subparameters to search in for the identifier " + String.valueOf(parameterNames[i]) + " in method " + String.valueOf(method.getIdentifier())); }/*w ww.jav a2 s.c om*/ i++; } if (childParameter != null) { return childParameter.getSignatureElementPath(); } else { throw new ParsingException("No more subparameters to search in for the identifier " + String.valueOf(parameterNames[0]) + " in method " + String.valueOf(method.getIdentifier())); } } else { throw new ParsingException( "The docText " + String.valueOf(identifier) + " could not be splitted."); } } else { log.info("No parent parameter found for tag element " + String.valueOf(tagElement.toString())); } } else { // jakr: if no parent is found, leave the identifier initialized with // null. In this case there must be an invalid ordering of the Javadoc // tags (@subparam without @param above). } return StringUtils.EMPTY; }
From source file:in.cypal.studio.gwt.core.builder.GwtBuilder.java
License:Apache License
private void updateAsyncFiles(IProgressMonitor monitor) throws CoreException, BadLocationException { monitor = Util.getNonNullMonitor(monitor); try {//from w w w . j av a 2 s . c om IResourceDelta delta = getDelta(getProject()); List remoteServices = gwtProject.getRemoteServices(delta); monitor.beginTask("Updating Async files...", remoteServices.size()); for (Iterator i = remoteServices.iterator(); i.hasNext();) { IFile aRemoteServiceFile = (IFile) i.next(); IPackageFragment clientPackage = (IPackageFragment) JavaCore.create(aRemoteServiceFile.getParent()); ICompilationUnit asyncContents = (ICompilationUnit) JavaCore.create(aRemoteServiceFile); String source = asyncContents.getBuffer().getContents(); Document document = new Document(source); ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(asyncContents); CompilationUnit astRoot = (CompilationUnit) parser.createAST(null); AST ast = astRoot.getAST(); astRoot.recordModifications(); // Modify imports (+AsyncCallback, -RemoteService, -*Exception) List imports = astRoot.imports(); List importsToBeRemoved = new ArrayList(); for (Iterator j = imports.iterator(); j.hasNext();) { ImportDeclaration anImportDecl = (ImportDeclaration) j.next(); String importName = anImportDecl.getName().getFullyQualifiedName(); if (importName.endsWith("Exception") || //$NON-NLS-1$ importName.equals("com.google.gwt.core.client.GWT") || //$NON-NLS-1$ importName.equals("com.google.gwt.user.client.rpc.ServiceDefTarget") || //$NON-NLS-1$ importName.equals("com.google.gwt.user.client.rpc.RemoteService")//$NON-NLS-1$ ) importsToBeRemoved.add(anImportDecl); } imports.removeAll(importsToBeRemoved); ImportDeclaration importDecl = ast.newImportDeclaration(); importDecl.setName(ast.newName("com.google.gwt.user.client.rpc.AsyncCallback")); //$NON-NLS-1$ astRoot.imports().add(importDecl); // Add Async to the name TypeDeclaration aRemoteService = (TypeDeclaration) astRoot.types().get(0); String remoteServiceAsyncName = aRemoteService.getName().getFullyQualifiedName() + "Async"; //$NON-NLS-1$ aRemoteService.setName(astRoot.getAST().newSimpleName(remoteServiceAsyncName)); // Remote all interfaces aRemoteService.superInterfaceTypes().clear(); // Change methods, fields and inner classes List bodyDeclarations = aRemoteService.bodyDeclarations(); List declarationsToDelete = new ArrayList(); for (Iterator k = bodyDeclarations.iterator(); k.hasNext();) { Object currDeclaration = k.next(); if (currDeclaration instanceof MethodDeclaration) { // Make return type void MethodDeclaration aMethod = (MethodDeclaration) currDeclaration; aMethod.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID)); // Add AsyncCallback parameter SingleVariableDeclaration asyncCallbackParam = ast.newSingleVariableDeclaration(); asyncCallbackParam.setName(ast.newSimpleName("callback")); //$NON-NLS-1$ asyncCallbackParam.setType(ast.newSimpleType(ast.newName("AsyncCallback"))); //$NON-NLS-1$ aMethod.parameters().add(asyncCallbackParam); // Remove throws aMethod.thrownExceptions().clear(); // Remove @gwt tags Javadoc jdoc = aMethod.getJavadoc(); if (jdoc != null) { List tags = jdoc.tags(); List tagsToRemove = new ArrayList(); for (Iterator itTags = tags.iterator(); itTags.hasNext();) { TagElement tag = (TagElement) itTags.next(); if (tag.toString().contains("@gwt")) { tagsToRemove.add(tag); } } tags.removeAll(tagsToRemove); } } else if (currDeclaration instanceof FieldDeclaration || currDeclaration instanceof TypeDeclaration) { // Remove the fields and inner classes declarationsToDelete.add(currDeclaration); } } bodyDeclarations.removeAll(declarationsToDelete); // computation of the text edits TextEdit edits = astRoot.rewrite(document, asyncContents.getJavaProject().getOptions(true)); // computation of the new source code edits.apply(document); String newSource = document.get(); // update of the compilation unit clientPackage.createCompilationUnit(remoteServiceAsyncName + ".java", newSource, true, monitor); //$NON-NLS-1$ monitor.worked(1); } } finally { monitor.done(); } }
From source file:org.eclipse.xtext.xbase.ui.hover.XbaseHoverDocumentationProvider.java
License:Open Source License
protected boolean handleValueTag(TagElement node) { // Not handled explicit for Xbase for now handleText(node.toString()); return true;//from w w w . jav a 2 s . c o m }