org.eclipse.jdt.core.dom.MarkerAnnotation Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.MarkerAnnotation. 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: MissingAnnotationAttributesProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Expression newDefaultExpression(AST ast, ITypeBinding type, ImportRewriteContext context) {
	if (type.isPrimitive()) {
		String name= type.getName();
		if ("boolean".equals(name)) { //$NON-NLS-1$
			return ast.newBooleanLiteral(false);
		} else {
			return ast.newNumberLiteral("0"); //$NON-NLS-1$
		}
	}
	if (type == ast.resolveWellKnownType("java.lang.String")) { //$NON-NLS-1$
		return ast.newStringLiteral();
	}
	if (type.isArray()) {
		ArrayInitializer initializer= ast.newArrayInitializer();
		initializer.expressions().add(newDefaultExpression(ast, type.getElementType(), context));
		return initializer;
	}
	if (type.isAnnotation()) {
		MarkerAnnotation annotation= ast.newMarkerAnnotation();
		annotation.setTypeName(ast.newName(getImportRewrite().addImport(type, context)));
		return annotation;
	}
	return ast.newNullLiteral();
}
 
Example #2
Source File: NullAnnotationsRewriteOperations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
boolean checkExisting(List<IExtendedModifier> existingModifiers, ListRewrite listRewrite, TextEditGroup editGroup) {
	for (Object mod : existingModifiers) {
		if (mod instanceof MarkerAnnotation) {
			MarkerAnnotation annotation= (MarkerAnnotation) mod;
			String existingName= annotation.getTypeName().getFullyQualifiedName();
			int lastDot= fAnnotationToRemove.lastIndexOf('.');
			if (existingName.equals(fAnnotationToRemove) || (lastDot != -1 && fAnnotationToRemove.substring(lastDot + 1).equals(existingName))) {
				if (!fAllowRemove)
					return false; // veto this change
				listRewrite.remove(annotation, editGroup);
				return true;
			}
			// paranoia: check if by accident the annotation is already present (shouldn't happen):
			lastDot= fAnnotationToAdd.lastIndexOf('.');
			if (existingName.equals(fAnnotationToAdd) || (lastDot != -1 && fAnnotationToAdd.substring(lastDot + 1).equals(existingName))) {
				return false; // already present
			}
		}
	}
	return true;
}
 
Example #3
Source File: PushDownRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private MethodDeclaration createNewMethodDeclarationNode(MemberActionInfo info, TypeVariableMaplet[] mapping, CompilationUnitRewrite rewriter, MethodDeclaration oldMethod) throws JavaModelException {
	Assert.isTrue(!info.isFieldInfo());
	IMethod method= (IMethod) info.getMember();
	ASTRewrite rewrite= rewriter.getASTRewrite();
	AST ast= rewrite.getAST();
	MethodDeclaration newMethod= ast.newMethodDeclaration();
	copyBodyOfPushedDownMethod(rewrite, method, oldMethod, newMethod, mapping);
	newMethod.setConstructor(oldMethod.isConstructor());
	copyExtraDimensions(oldMethod, newMethod);
	if (info.copyJavadocToCopiesInSubclasses())
		copyJavadocNode(rewrite, oldMethod, newMethod);
	final IJavaProject project= rewriter.getCu().getJavaProject();
	if (info.isNewMethodToBeDeclaredAbstract() && JavaModelUtil.is50OrHigher(project) && JavaPreferencesSettings.getCodeGenerationSettings(project).overrideAnnotation) {
		final MarkerAnnotation annotation= ast.newMarkerAnnotation();
		annotation.setTypeName(ast.newSimpleName("Override")); //$NON-NLS-1$
		newMethod.modifiers().add(annotation);
	}
	copyAnnotations(oldMethod, newMethod);
	newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(ast, info.getNewModifiersForCopyInSubclass(oldMethod.getModifiers())));
	newMethod.setName(ast.newSimpleName(oldMethod.getName().getIdentifier()));
	copyReturnType(rewrite, method.getCompilationUnit(), oldMethod, newMethod, mapping);
	copyParameters(rewrite, method.getCompilationUnit(), oldMethod, newMethod, mapping);
	copyThrownExceptions(oldMethod, newMethod);
	copyTypeParameters(oldMethod, newMethod);
	return newMethod;
}
 
Example #4
Source File: PullUpRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void createAbstractMethod(final IMethod sourceMethod, final CompilationUnitRewrite sourceRewriter, final CompilationUnit declaringCuNode, final AbstractTypeDeclaration destination, final TypeVariableMaplet[] mapping, final CompilationUnitRewrite targetRewrite, final Map<IMember, IncomingMemberVisibilityAdjustment> adjustments, final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException {
	final MethodDeclaration oldMethod= ASTNodeSearchUtil.getMethodDeclarationNode(sourceMethod, declaringCuNode);
	if (JavaModelUtil.is50OrHigher(sourceMethod.getJavaProject()) && (fSettings.overrideAnnotation || JavaCore.ERROR.equals(sourceMethod.getJavaProject().getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, true)))) {
		final MarkerAnnotation annotation= sourceRewriter.getAST().newMarkerAnnotation();
		annotation.setTypeName(sourceRewriter.getAST().newSimpleName("Override")); //$NON-NLS-1$
		sourceRewriter.getASTRewrite().getListRewrite(oldMethod, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(annotation, sourceRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_override_annotation, SET_PULL_UP));
	}
	final MethodDeclaration newMethod= targetRewrite.getAST().newMethodDeclaration();
	newMethod.setBody(null);
	newMethod.setConstructor(false);
	copyExtraDimensions(oldMethod, newMethod);
	newMethod.setJavadoc(null);
	int modifiers= getModifiersWithUpdatedVisibility(sourceMethod, Modifier.ABSTRACT | JdtFlags.clearFlag(Modifier.NATIVE | Modifier.FINAL, sourceMethod.getFlags()), adjustments, monitor, false, status);
	if (oldMethod.isVarargs())
		modifiers&= ~Flags.AccVarargs;
	newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(targetRewrite.getAST(), modifiers));
	newMethod.setName(((SimpleName) ASTNode.copySubtree(targetRewrite.getAST(), oldMethod.getName())));
	copyReturnType(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping);
	copyParameters(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping);
	copyThrownExceptions(oldMethod, newMethod);
	copyTypeParameters(oldMethod, newMethod);
	ImportRewriteContext context= new ContextSensitiveImportRewriteContext(destination, targetRewrite.getImportRewrite());
	ImportRewriteUtil.addImports(targetRewrite, context, oldMethod, new HashMap<Name, String>(), new HashMap<Name, String>(), false);
	targetRewrite.getASTRewrite().getListRewrite(destination, destination.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, destination.bodyDeclarations()), targetRewrite.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_abstract_method, SET_PULL_UP));
}
 
Example #5
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
private void handleModifier(IExtendedModifier extendedModifier) {
	if(extendedModifier instanceof Modifier) {
		visit((Modifier) extendedModifier);
	}
	else if(extendedModifier instanceof MarkerAnnotation) {
		visit((MarkerAnnotation) extendedModifier);
	}
	else if(extendedModifier instanceof NormalAnnotation) {
		visit((NormalAnnotation) extendedModifier);
	}
	else if(extendedModifier instanceof SingleMemberAnnotation) {
		visit((SingleMemberAnnotation) extendedModifier);
	}
}
 
Example #6
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(MarkerAnnotation annotation) {
	/*
	 * MarkerAnnotation: @ TypeName
	 */
	activateDiffStyle(annotation);
	appendAtSign();
	handleExpression(annotation.getTypeName());
	deactivateDiffStyle(annotation);
	return false;
}
 
Example #7
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final MarkerAnnotation node) {
  this.appendToBuffer("@");
  node.getTypeName().accept(this);
  this.appendSpaceToBuffer();
  return false;
}
 
Example #8
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(MarkerAnnotation node) {
	// nothing to do for marker annotations;
}
 
Example #9
Source File: DOMFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean visit(MarkerAnnotation node) {
	if (found(node, node) && this.resolveBinding)
		this.foundBinding = node.resolveAnnotationBinding();
	return true;
}
 
Example #10
Source File: ImportReferencesCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(MarkerAnnotation node) {
	typeRefFound(node.getTypeName());
	return false;
}
 
Example #11
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(MarkerAnnotation node) {
	return visitNode(node);
}
 
Example #12
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(MarkerAnnotation node) {
	endVisitNode(node);
}
 
Example #13
Source File: ConstraintCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(MarkerAnnotation node) {
	return false;
}
 
Example #14
Source File: AstMatchingNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(MarkerAnnotation node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
Example #15
Source File: ReferencedClassesParser.java    From BUILD_file_generator with Apache License 2.0 4 votes vote down vote up
@Override
public boolean visit(MarkerAnnotation node) {
  return visitAnnotation(node);
}
 
Example #16
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void endVisit(MarkerAnnotation node) {
	// nothing to do for marker annotations;
}
 
Example #17
Source File: MarkerAnnotationAttacher.java    From SparkBuilderGenerator with MIT License 4 votes vote down vote up
private MarkerAnnotation createMarkerAnnotation(AST ast, String annotation) {
    MarkerAnnotation markerAnnotation = ast.newMarkerAnnotation();
    markerAnnotation.setTypeName(ast.newSimpleName(annotation));
    return markerAnnotation;
}
 
Example #18
Source File: MarkerAnnotationAttacher.java    From SparkBuilderGenerator with MIT License 4 votes vote down vote up
public void attachAnnotation(AST ast, SingleVariableDeclaration methodParameterDeclaration, String annotationName) {
    MarkerAnnotation nonNullAnnotation = createMarkerAnnotation(ast, annotationName);
    methodParameterDeclaration.modifiers().add(0, nonNullAnnotation);
}
 
Example #19
Source File: MarkerAnnotationAttacher.java    From SparkBuilderGenerator with MIT License 4 votes vote down vote up
public void attachAnnotation(AST ast, MethodDeclaration method, String annotationName) {
    MarkerAnnotation nonNullAnnotation = createMarkerAnnotation(ast, annotationName);
    method.modifiers().add(0, nonNullAnnotation);
}
 
Example #20
Source File: JsonPOJOBuilderAdderFragment.java    From SparkBuilderGenerator with MIT License 4 votes vote down vote up
private MarkerAnnotation createEmptyJsonPojoBuilderAnnotation(AST ast) {
    return ast.newMarkerAnnotation();
}
 
Example #21
Source File: AstVisitor.java    From jdt2famix with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * handles: @ TypeName We do not use this one because we want to tie the
 * creation of annotation instances with the ensuring of bindings (e.g.,
 * {@link InJavaImporter#ensureTypeFromTypeBinding(ITypeBinding)}). Thus, we
 * prefer to call the annotation creation explicitly from the other visit
 * methods (e.g., {link {@link #visit(TypeDeclaration)}
 */
@Override
public boolean visit(MarkerAnnotation node) {
	addTypeAnnotationSourceAnchor(node);
	return true;
}