Java Code Examples for org.eclipse.jdt.core.dom.Annotation#setTypeName()

The following examples show how to use org.eclipse.jdt.core.dom.Annotation#setTypeName() . 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: JsonPOJOBuilderAdderFragment.java    From SparkBuilderGenerator with MIT License 5 votes vote down vote up
private Optional<Annotation> createJsonPojoBuilderAnnotation(AST ast) {
    String buildMethodName = getBuilderMethodName();
    String withMethodPrefix = getWithMethodPrefix();

    if (!buildMethodName.equals(DEFAULT_BUILDER_METHOD_NAME_ATTRIBUTE_VALUE) || !withMethodPrefix.equals(DEFAULT_WITH_METHOD_ATTRIBUTE_VALUE)) {
        Annotation result = createJsonPojoBuilderAnnotationWithAttributes(ast, buildMethodName, withMethodPrefix);
        result.setTypeName(ast.newSimpleName(JSON_POJO_BUILDER_CLASS_NAME));
        return Optional.of(result);
    }

    return Optional.empty();
}
 
Example 2
Source File: StubUtility2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void addOverrideAnnotation(IJavaProject project, ASTRewrite rewrite, MethodDeclaration decl, IMethodBinding binding) {
	if (binding.getDeclaringClass().isInterface()) {
		String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
		if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6))
			return; // not allowed in 1.5
		if (JavaCore.DISABLED.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, true)))
			return; // user doesn't want to use 1.6 style
	}
	
	Annotation marker= rewrite.getAST().newMarkerAnnotation();
	marker.setTypeName(rewrite.getAST().newSimpleName("Override")); //$NON-NLS-1$
	rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
}
 
Example 3
Source File: Java50Fix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
	AST ast= cuRewrite.getRoot().getAST();
	ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(fBodyDeclaration, fBodyDeclaration.getModifiersProperty());
	Annotation newAnnotation= ast.newMarkerAnnotation();
	newAnnotation.setTypeName(ast.newSimpleName(fAnnotation));
	TextEditGroup group= createTextEditGroup(Messages.format(FixMessages.Java50Fix_AddMissingAnnotation_description, BasicElementLabels.getJavaElementName(fAnnotation)), cuRewrite);
	listRewrite.insertFirst(newAnnotation, group);
}
 
Example 4
Source File: NullAnnotationsRewriteOperations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
	AST ast= cuRewrite.getRoot().getAST();
	ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(fBodyDeclaration, fBodyDeclaration.getModifiersProperty());
	TextEditGroup group= createTextEditGroup(fMessage, cuRewrite);
	if (!checkExisting(fBodyDeclaration.modifiers(), listRewrite, group))
		return;
	if (hasNonNullDefault(fBodyDeclaration.resolveBinding()))
		return; // should be safe, as in this case checkExisting() should've already produced a change (remove existing annotation).
	Annotation newAnnotation= ast.newMarkerAnnotation();
	ImportRewrite importRewrite= cuRewrite.getImportRewrite();
	String resolvableName= importRewrite.addImport(fAnnotationToAdd);
	newAnnotation.setTypeName(ast.newName(resolvableName));
	listRewrite.insertLast(newAnnotation, group); // null annotation is last modifier, directly preceding the return type
}
 
Example 5
Source File: NullAnnotationsRewriteOperations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel linkedModel) throws CoreException {
	AST ast= cuRewrite.getRoot().getAST();
	ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(fArgument, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
	TextEditGroup group= createTextEditGroup(fMessage, cuRewrite);
	if (!checkExisting(fArgument.modifiers(), listRewrite, group))
		return;
	Annotation newAnnotation= ast.newMarkerAnnotation();
	ImportRewrite importRewrite= cuRewrite.getImportRewrite();
	String resolvableName= importRewrite.addImport(fAnnotationToAdd);
	newAnnotation.setTypeName(ast.newName(resolvableName));
	listRewrite.insertLast(newAnnotation, group); // null annotation is last modifier, directly preceding the type
}
 
Example 6
Source File: ModifierCorrectionSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void addOverridingDeprecatedMethodProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {

		ICompilationUnit cu= context.getCompilationUnit();

		ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
		if (!(selectedNode instanceof MethodDeclaration)) {
			return;
		}
		boolean is50OrHigher= JavaModelUtil.is50OrHigher(cu.getJavaProject());
		MethodDeclaration methodDecl= (MethodDeclaration) selectedNode;
		AST ast= methodDecl.getAST();
		ASTRewrite rewrite= ASTRewrite.create(ast);
		if (is50OrHigher) {
			Annotation annot= ast.newMarkerAnnotation();
			annot.setTypeName(ast.newName("Deprecated")); //$NON-NLS-1$
			rewrite.getListRewrite(methodDecl, methodDecl.getModifiersProperty()).insertFirst(annot, null);
		}
		Javadoc javadoc= methodDecl.getJavadoc();
		if (javadoc != null || !is50OrHigher) {
			if (!is50OrHigher) {
				javadoc= ast.newJavadoc();
				rewrite.set(methodDecl, MethodDeclaration.JAVADOC_PROPERTY, javadoc, null);
			}
			TagElement newTag= ast.newTagElement();
			newTag.setTagName(TagElement.TAG_DEPRECATED);
			JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null);
		}

		String label= CorrectionMessages.ModifierCorrectionSubProcessor_overrides_deprecated_description;
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
		ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.OVERRIDES_DEPRECATED, image);
		proposals.add(proposal);
	}