类org.eclipse.jdt.core.dom.Javadoc源码实例Demo

下面列出了怎么用org.eclipse.jdt.core.dom.Javadoc的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * adds a comment (if necessary) and an <code>@Override</code> annotation to the generated
 * method
 * 
 * @throws CoreException if creation failed
 */
protected void createMethodComment() throws CoreException {
	ITypeBinding object= fAst.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
	IMethodBinding[] objms= object.getDeclaredMethods();
	IMethodBinding objectMethod= null;
	for (int i= 0; i < objms.length; i++) {
		if (objms[i].getName().equals(METHODNAME_TO_STRING) && objms[i].getParameterTypes().length == 0)
			objectMethod= objms[i];
	}
	if (fContext.isCreateComments()) {
		String docString= CodeGeneration.getMethodComment(fContext.getCompilationUnit(), fContext.getTypeBinding().getQualifiedName(), toStringMethod, objectMethod, StubUtility
				.getLineDelimiterUsed(fContext.getCompilationUnit()));
		if (docString != null) {
			Javadoc javadoc= (Javadoc)fContext.getASTRewrite().createStringPlaceholder(docString, ASTNode.JAVADOC);
			toStringMethod.setJavadoc(javadoc);
		}
	}
	if (fContext.isOverrideAnnotation() && fContext.is50orHigher())
		StubUtility2.addOverrideAnnotation(fContext.getTypeBinding().getJavaElement().getJavaProject(), fContext.getASTRewrite(), toStringMethod, objectMethod);
}
 
public TypeDeclaration createBuilderClass(AST ast, TypeDeclaration originalType) {
    TypeDeclaration builderType = ast.newTypeDeclaration();
    builderType.setName(ast.newSimpleName(getBuilderName(originalType)));

    if (preferencesManager.getPreferenceValue(ADD_GENERATED_ANNOTATION)) {
        generatedAnnotationPopulator.addGeneratedAnnotation(ast, builderType);
    }
    builderType.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
    builderType.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
    builderType.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));

    if (preferencesManager.getPreferenceValue(ADD_JACKSON_DESERIALIZE_ANNOTATION)) {
        jsonPOJOBuilderAdderFragment.addJsonPOJOBuilder(ast, builderType);
    }

    if (preferencesManager.getPreferenceValue(GENERATE_JAVADOC_ON_BUILDER_CLASS)) {
        Javadoc javadoc = javadocGenerator.generateJavadoc(ast, String.format(Locale.ENGLISH, "Builder to build {@link %s}.", originalType.getName().toString()),
                Collections.emptyMap());
        builderType.setJavadoc(javadoc);
    }

    return builderType;
}
 
源代码3 项目: JDeodorant   文件: MoveMethodRefactoring.java
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;
				}
			}
		}
	}
}
 
源代码4 项目: JDeodorant   文件: MoveMethodRefactoring.java
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);
	}
}
 
源代码5 项目: eclipse.jdt.ls   文件: JavadocTagsSubProcessor.java
private void insertAllMissingTypeTags(ASTRewrite rewriter, TypeDeclaration typeDecl) {
	AST ast= typeDecl.getAST();
	Javadoc javadoc= typeDecl.getJavadoc();
	ListRewrite tagsRewriter= rewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);

	List<TypeParameter> typeParams= typeDecl.typeParameters();
	for (int i= typeParams.size() - 1; i >= 0; i--) {
		TypeParameter decl= typeParams.get(i);
		String name= '<' + decl.getName().getIdentifier() + '>';
		if (findTag(javadoc, TagElement.TAG_PARAM, name) == null) {
			TagElement newTag= ast.newTagElement();
			newTag.setTagName(TagElement.TAG_PARAM);
			TextElement text= ast.newTextElement();
			text.setText(name);
			newTag.fragments().add(text);
			insertTabStop(rewriter, newTag.fragments(), "typeParam" + i); //$NON-NLS-1$
			insertTag(tagsRewriter, newTag, getPreviousTypeParamNames(typeParams, decl));
		}
	}
}
 
源代码6 项目: xtext-xtend   文件: JavaASTFlattener.java
/**
 * Start self Converted part
 */
@Override
public boolean visit(final AnnotationTypeDeclaration node) {
  Javadoc _javadoc = node.getJavadoc();
  boolean _tripleNotEquals = (_javadoc != null);
  if (_tripleNotEquals) {
    node.getJavadoc().accept(this);
  }
  this.appendModifiers(node, node.modifiers());
  this.appendToBuffer("annotation ");
  node.getName().accept(this);
  this.appendToBuffer(" {");
  this.appendLineWrapToBuffer();
  this.visitAll(node.bodyDeclarations());
  this.appendToBuffer("}");
  return false;
}
 
源代码7 项目: xtext-xtend   文件: JavaASTFlattener.java
@Override
public boolean visit(final AnnotationTypeMemberDeclaration node) {
  Javadoc _javadoc = node.getJavadoc();
  boolean _tripleNotEquals = (_javadoc != null);
  if (_tripleNotEquals) {
    node.getJavadoc().accept(this);
  }
  this.appendModifiers(node, node.modifiers());
  node.getType().accept(this);
  this.appendSpaceToBuffer();
  node.getName().accept(this);
  Expression _default = node.getDefault();
  boolean _tripleNotEquals_1 = (_default != null);
  if (_tripleNotEquals_1) {
    this.appendToBuffer(" = ");
    node.getDefault().accept(this);
  }
  this.appendLineWrapToBuffer();
  return false;
}
 
源代码8 项目: xtext-xtend   文件: JavaASTFlattener.java
@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;
}
 
private void addEnclosingInstanceDeclaration(final AbstractTypeDeclaration declaration, final ASTRewrite rewrite) throws CoreException {
	Assert.isNotNull(declaration);
	Assert.isNotNull(rewrite);
	final AST ast= declaration.getAST();
	final VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
	fragment.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
	final FieldDeclaration newField= ast.newFieldDeclaration(fragment);
	newField.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getEnclosingInstanceAccessModifiers()));
	newField.setType(createEnclosingType(ast));
	final String comment= CodeGeneration.getFieldComment(fType.getCompilationUnit(), declaration.getName().getIdentifier(), fEnclosingInstanceFieldName, StubUtility.getLineDelimiterUsed(fType.getJavaProject()));
	if (comment != null && comment.length() > 0) {
		final Javadoc doc= (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
		newField.setJavadoc(doc);
	}
	rewrite.getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertFirst(newField, null);
}
 
private Javadoc createJavadocForStub(final String enclosingTypeName, final MethodDeclaration oldMethod, final MethodDeclaration newMethodNode, final ICompilationUnit cu, final ASTRewrite rewrite) throws CoreException {
	if (fSettings.createComments) {
		final IMethodBinding binding= oldMethod.resolveBinding();
		if (binding != null) {
			final ITypeBinding[] params= binding.getParameterTypes();
			final String fullTypeName= getDestinationType().getFullyQualifiedName('.');
			final String[] fullParamNames= new String[params.length];
			for (int i= 0; i < fullParamNames.length; i++) {
				fullParamNames[i]= Bindings.getFullyQualifiedName(params[i]);
			}
			final String comment= CodeGeneration.getMethodComment(cu, enclosingTypeName, newMethodNode, false, binding.getName(), fullTypeName, fullParamNames, StubUtility.getLineDelimiterUsed(cu));
			if (comment != null)
				return (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
		}
	}
	return null;
}
 
private void createFieldsForAccessedLocals(CompilationUnitRewrite rewrite, IVariableBinding[] varBindings, String[] fieldNames, List<BodyDeclaration> newBodyDeclarations) throws CoreException {
	final ImportRewrite importRewrite= rewrite.getImportRewrite();
	final ASTRewrite astRewrite= rewrite.getASTRewrite();
	final AST ast= astRewrite.getAST();

	for (int i= 0; i < varBindings.length; i++) {
		VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
		fragment.setInitializer(null);
		fragment.setName(ast.newSimpleName(fieldNames[i]));
		FieldDeclaration field= ast.newFieldDeclaration(fragment);
		ITypeBinding varType= varBindings[i].getType();
		field.setType(importRewrite.addImport(varType, ast));
		field.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.FINAL));
		if (doAddComments()) {
			String string= CodeGeneration.getFieldComment(rewrite.getCu(), varType.getName(), fieldNames[i], StubUtility.getLineDelimiterUsed(fCu));
			if (string != null) {
				Javadoc javadoc= (Javadoc) astRewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
				field.setJavadoc(javadoc);
			}
		}

		newBodyDeclarations.add(field);

		addLinkedPosition(KEY_FIELD_NAME_EXT + i, fragment.getName(), astRewrite, false);
	}
}
 
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;
}
 
@Override
public boolean visit(Javadoc node) {
	int commentIndex = this.tokenManager.firstIndexIn(node, TerminalTokens.TokenNameCOMMENT_JAVADOC);
	Token commentToken = this.tokenManager.get(commentIndex);
	this.commentTokenManager = new TokenManager(commentToken.getInternalStructure(), this.tokenManager);
	this.declaration = node.getParent();
	this.firstTagElement = true;
	this.hasText = false;
	return true;
}
 
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;
}
 
源代码15 项目: SparkBuilderGenerator   文件: JavadocAdder.java
public void addJavadocForBuildMethod(AST ast, MethodDeclaration buildMethod) {
    if (preferencesManager.getPreferenceValue(GENERATE_JAVADOC_ON_EACH_BUILDER_METHOD)) {
        Javadoc javadoc = javadocGenerator.generateJavadoc(ast, "Builder method of the builder.",
                Collections.singletonMap(RETURN_JAVADOC_TAG_NAME, "built class"));
        buildMethod.setJavadoc(javadoc);
    }
}
 
源代码16 项目: SparkBuilderGenerator   文件: JavadocAdder.java
public void addJavadocForStagedInterface(AST ast, String interfaceName, TypeDeclaration addedInterface) {
    if (preferencesManager.getPreferenceValue(STAGED_BUILDER_GENERATE_JAVADOC_ON_STAGE_INTERFACE)) {
        Javadoc javadoc = javadocGenerator.generateJavadoc(ast,
                String.format(Locale.ENGLISH, "Definition of a stage for staged builder."), Collections.emptyMap());
        addedInterface.setJavadoc(javadoc);
    }
}
 
private JavadocContentAccess2(IMethod method, Javadoc javadoc, String source, JavadocLookup lookup) {
	Assert.isNotNull(method);
	fElement= method;
	fMethod= method;
	fJavadoc= javadoc;
	fSource= source;
	fJavadocLookup= lookup;
}
 
源代码18 项目: eclipse.jdt.ls   文件: DelegateCreator.java
/**
 * Creates the javadoc for the delegate.
 *
 * @throws JavaModelException
 */
private void createJavadoc() throws JavaModelException {
	TagElement tag= getDelegateJavadocTag(fDeclaration);

	Javadoc comment= fDeclaration.getJavadoc();
	if (comment == null) {
		comment= getAst().newJavadoc();
		comment.tags().add(tag);
		fDelegateRewrite.getASTRewrite().set(fDeclaration, getJavaDocProperty(), comment, null);
	} else {
		fDelegateRewrite.getASTRewrite().getListRewrite(comment, Javadoc.TAGS_PROPERTY).insertLast(tag, null);
	}
}
 
@Override
public boolean visit(Javadoc node) {
	if (super.visit(node))
		return visitNode(node);
	else
		return false;
}
 
源代码20 项目: eclipse.jdt.ls   文件: ExtractMethodRefactoring.java
private MethodDeclaration createNewMethod(ASTNode[] selectedNodes, String lineDelimiter, TextEditGroup substitute) throws CoreException {
	MethodDeclaration result = createNewMethodDeclaration();
	result.setBody(createMethodBody(selectedNodes, substitute, result.getModifiers()));
	if (fGenerateJavadoc) {
		AbstractTypeDeclaration enclosingType = ASTNodes.getParent(fAnalyzer.getEnclosingBodyDeclaration(), AbstractTypeDeclaration.class);
		String string = CodeGeneration.getMethodComment(fCUnit, enclosingType.getName().getIdentifier(), result, null, lineDelimiter);
		if (string != null) {
			Javadoc javadoc = (Javadoc) fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
			result.setJavadoc(javadoc);
		}
	}
	return result;
}
 
private TagElement findThrowsTag(MethodDeclaration decl, Type exception) {
	Javadoc javadoc= decl.getJavadoc();
	if (javadoc != null) {
		String name= ASTNodes.getTypeName(exception);
		return JavadocTagsSubProcessor.findThrowsTag(javadoc, name);
	}
	return null;
}
 
private MethodDeclaration createGetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter) throws CoreException {
	FieldDeclaration field = ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class);
	Type type = field.getType();
	MethodDeclaration result = ast.newMethodDeclaration();
	result.setName(ast.newSimpleName(fGetterName));
	result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
	Type returnType = DimensionRewrite.copyTypeAndAddDimensions(type, fFieldDeclaration.extraDimensions(), rewriter);
	result.setReturnType2(returnType);

	Block block = ast.newBlock();
	result.setBody(block);

	String body = CodeGeneration.getGetterMethodBodyContent(fField.getCompilationUnit(), getTypeName(field.getParent()), fGetterName, fField.getElementName(), lineDelimiter);
	if (body != null) {
		body = body.substring(0, body.lastIndexOf(lineDelimiter));
		ASTNode getterNode = rewriter.createStringPlaceholder(body, ASTNode.BLOCK);
		block.statements().add(getterNode);
	} else {
		ReturnStatement rs = ast.newReturnStatement();
		rs.setExpression(ast.newSimpleName(fField.getElementName()));
		block.statements().add(rs);
	}
	if (fGenerateJavadoc) {
		String string = CodeGeneration.getGetterComment(fField.getCompilationUnit(), getTypeName(field.getParent()), fGetterName, fField.getElementName(), ASTNodes.asString(type), StubUtility.getBaseName(fField), lineDelimiter);
		if (string != null) {
			Javadoc javadoc = (Javadoc) fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
			result.setJavadoc(javadoc);
		}
	}
	return result;
}
 
源代码23 项目: eclipse.jdt.ls   文件: JavadocContentAccess.java
private static Javadoc getPackageJavadocNode(IJavaElement element, String cuSource) {
	CompilationUnit cu= createAST(element, cuSource);
	if (cu != null) {
		PackageDeclaration packDecl= cu.getPackage();
		if (packDecl != null) {
			return packDecl.getJavadoc();
		}
	}
	return null;
}
 
源代码24 项目: eclipse.jdt.ls   文件: JavadocContentAccess2.java
private JavadocContentAccess2(IJavaElement element, Javadoc javadoc, String source, JavadocLookup lookup) {
	Assert.isNotNull(element);
	Assert.isTrue(element instanceof IMethod || element instanceof ILocalVariable || element instanceof ITypeParameter);
	fElement = element;
	fMethod = (IMethod) ((element instanceof ILocalVariable || element instanceof ITypeParameter) ? element.getParent() : element);
	fJavadoc = javadoc;
	fSource = source;
	fJavadocLookup = lookup;
}
 
源代码25 项目: eclipse.jdt.ls   文件: JavadocContentAccess2.java
private JavadocContentAccess2(IJavaElement element, Javadoc javadoc, String source) {
	Assert.isTrue(element instanceof IMember || element instanceof IPackageFragment || element instanceof ILocalVariable || element instanceof ITypeParameter);
	fElement = element;
	fMethod = null;
	fJavadoc = javadoc;
	fSource = source;
	fJavadocLookup = JavadocLookup.NONE;
}
 
源代码26 项目: eclipse.jdt.ls   文件: JavadocContentAccess2.java
private static Javadoc getPackageJavadocNode(IJavaElement element, String cuSource) {
	CompilationUnit cu = createAST(element, cuSource);
	if (cu != null) {
		PackageDeclaration packDecl = cu.getPackage();
		if (packDecl != null) {
			return packDecl.getJavadoc();
		}
	}
	return null;
}
 
源代码27 项目: eclipse.jdt.ls   文件: JavadocContentAccess2.java
private static String getHTMLContentFromAttachedSource(IPackageFragmentRoot root, IPackageFragment packageFragment) throws CoreException {
	String filePath = packageFragment.getElementName().replace('.', '/') + '/' + JavaModelUtil.PACKAGE_INFO_JAVA;
	String contents = getFileContentFromAttachedSource(root, filePath);
	if (contents != null) {
		Javadoc packageJavadocNode = getPackageJavadocNode(packageFragment, contents);
		if (packageJavadocNode != null) {
			return new JavadocContentAccess2(packageFragment, packageJavadocNode, contents).toHTML();
		}

	}
	filePath = packageFragment.getElementName().replace('.', '/') + '/' + JavaModelUtil.PACKAGE_HTML;
	return getFileContentFromAttachedSource(root, filePath);
}
 
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;
}
 
private JavadocContentAccess2(IJavaElement element, Javadoc javadoc, String source) {
	Assert.isTrue(element instanceof IMember || element instanceof IPackageFragment);
	fElement= element;
	fMethod= null;
	fJavadoc= javadoc;
	fSource= source;
	fJavadocLookup= JavadocLookup.NONE;
}
 
源代码30 项目: eclipse.jdt.ls   文件: JavadocTagsSubProcessor.java
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;
}
 
 类所在包
 同包方法