本文整理汇总了Java中org.eclipse.jdt.core.dom.Annotation类的典型用法代码示例。如果您正苦于以下问题:Java Annotation类的具体用法?Java Annotation怎么用?Java Annotation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Annotation类属于org.eclipse.jdt.core.dom包,在下文中一共展示了Annotation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTopMostType
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
/**
* Returns the topmost ancestor of <code>node</code> that is a {@link Type} (but not a {@link UnionType}).
* <p>
* <b>Note:</b> The returned node often resolves to a different binding than the given <code>node</code>!
*
* @param node the starting node, can be <code>null</code>
* @return the topmost type or <code>null</code> if the node is not a descendant of a type node
* @see #getNormalizedNode(ASTNode)
*/
public static Type getTopMostType(ASTNode node) {
ASTNode result= null;
while (node instanceof Type && !(node instanceof UnionType)
|| node instanceof Name
|| node instanceof Annotation || node instanceof MemberValuePair
|| node instanceof Expression) { // Expression could maybe be reduced to expression node types that can appear in an annotation
result= node;
node= node.getParent();
}
if (result instanceof Type) {
return (Type) result;
}
return null;
}
示例2: removePureTypeAnnotations
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
/**
* Removes all {@link Annotation} whose only {@link Target} is {@link ElementType#TYPE_USE} from
* <code>node</code>'s <code>childListProperty</code>.
* <p>
* In a combination of {@link ElementType#TYPE_USE} and {@link ElementType#TYPE_PARAMETER}
* the latter is ignored, because this is implied by the former and creates no ambiguity.</p>
*
* @param node ASTNode
* @param childListProperty child list property
* @param rewrite rewrite that removes the nodes
* @param editGroup the edit group in which to collect the corresponding text edits, or null if
* ungrouped
*/
public static void removePureTypeAnnotations(ASTNode node, ChildListPropertyDescriptor childListProperty, ASTRewrite rewrite, TextEditGroup editGroup) {
CompilationUnit root= (CompilationUnit) node.getRoot();
if (!JavaModelUtil.is18OrHigher(root.getJavaElement().getJavaProject())) {
return;
}
ListRewrite listRewrite= rewrite.getListRewrite(node, childListProperty);
@SuppressWarnings("unchecked")
List<? extends ASTNode> children= (List<? extends ASTNode>) node.getStructuralProperty(childListProperty);
for (ASTNode child : children) {
if (child instanceof Annotation) {
Annotation annotation= (Annotation) child;
if (isPureTypeAnnotation(annotation)) {
listRewrite.remove(child, editGroup);
}
}
}
}
示例3: addOverrideAnnotation
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
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);
}
示例4: rewriteAST
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
/** {@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);
}
示例5: rewriteAST
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
@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
}
示例6: hasNullAnnotation
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
private static boolean hasNullAnnotation(MethodDeclaration decl) {
List<IExtendedModifier> modifiers = decl.modifiers();
String nonnull =
NullAnnotationsFix.getNonNullAnnotationName(decl.resolveBinding().getJavaElement(), false);
String nullable =
NullAnnotationsFix.getNullableAnnotationName(decl.resolveBinding().getJavaElement(), false);
for (Object mod : modifiers) {
if (mod instanceof Annotation) {
Name annotationName = ((Annotation) mod).getTypeName();
String fullyQualifiedName = annotationName.getFullyQualifiedName();
if (annotationName.isSimpleName()
? nonnull.endsWith(fullyQualifiedName)
: fullyQualifiedName.equals(nonnull)) return true;
if (annotationName.isSimpleName()
? nullable.endsWith(fullyQualifiedName)
: fullyQualifiedName.equals(nullable)) return true;
}
}
return false;
}
示例7: checkExpressionIsRValue
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
/**
* @param e
* @return int Checks.IS_RVALUE if e is an rvalue Checks.IS_RVALUE_GUESSED if e is guessed as an
* rvalue Checks.NOT_RVALUE_VOID if e is not an rvalue because its type is void
* Checks.NOT_RVALUE_MISC if e is not an rvalue for some other reason
*/
public static int checkExpressionIsRValue(Expression e) {
if (e instanceof Name) {
if (!(((Name) e).resolveBinding() instanceof IVariableBinding)) {
return NOT_RVALUE_MISC;
}
}
if (e instanceof Annotation) return NOT_RVALUE_MISC;
ITypeBinding tb = e.resolveTypeBinding();
boolean guessingRequired = false;
if (tb == null) {
guessingRequired = true;
tb = ASTResolving.guessBindingForReference(e);
}
if (tb == null) return NOT_RVALUE_MISC;
else if (tb.getName().equals("void")) // $NON-NLS-1$
return NOT_RVALUE_VOID;
return guessingRequired ? IS_RVALUE_GUESSED : IS_RVALUE;
}
示例8: checkExpression
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
private void checkExpression(RefactoringStatus status) {
ASTNode[] nodes = getSelectedNodes();
if (nodes != null && nodes.length == 1) {
ASTNode node = nodes[0];
if (node instanceof Type) {
status.addFatalError(
RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_type_reference,
JavaStatusContext.create(fCUnit, node));
} else if (node.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) {
status.addFatalError(
RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_switch_case,
JavaStatusContext.create(fCUnit, node));
} else if (node instanceof Annotation || ASTNodes.getParent(node, Annotation.class) != null) {
status.addFatalError(
RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_from_annotation,
JavaStatusContext.create(fCUnit, node));
}
}
}
示例9: removeOverrideAnnotationProposal
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
public static void removeOverrideAnnotationProposal(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals)
throws CoreException {
ICompilationUnit cu = context.getCompilationUnit();
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (!(selectedNode instanceof MethodDeclaration)) {
return;
}
MethodDeclaration methodDecl = (MethodDeclaration) selectedNode;
Annotation annot = findAnnotation("java.lang.Override", methodDecl.modifiers()); // $NON-NLS-1$
if (annot != null) {
ASTRewrite rewrite = ASTRewrite.create(annot.getAST());
rewrite.remove(annot, null);
String label = CorrectionMessages.ModifierCorrectionSubProcessor_remove_override;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label, cu, rewrite, IProposalRelevance.REMOVE_OVERRIDE, image);
proposals.add(proposal);
QuickAssistProcessor.getCreateInSuperClassProposals(context, methodDecl.getName(), proposals);
}
}
示例10: findExistingAnnotation
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
private static Annotation findExistingAnnotation(List<? extends ASTNode> modifiers) {
for (int i = 0, len = modifiers.size(); i < len; i++) {
Object curr = modifiers.get(i);
if (curr instanceof NormalAnnotation || curr instanceof SingleMemberAnnotation) {
Annotation annotation = (Annotation) curr;
ITypeBinding typeBinding = annotation.resolveTypeBinding();
if (typeBinding != null) {
if ("java.lang.SuppressWarnings"
.equals(typeBinding.getQualifiedName())) { // $NON-NLS-1$
return annotation;
}
} else {
String fullyQualifiedName = annotation.getTypeName().getFullyQualifiedName();
if ("SuppressWarnings".equals(fullyQualifiedName)
|| "java.lang.SuppressWarnings"
.equals(fullyQualifiedName)) { // $NON-NLS-1$ //$NON-NLS-2$
return annotation;
}
}
}
}
return null;
}
示例11: findAnnotation
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
/**
* Finds an annotation of the given type (as a fully-qualified name) on a
* declaration (type, method, field, etc.). If no such annotation exists,
* returns <code>null</code>.
*/
@SuppressWarnings("unchecked")
public static Annotation findAnnotation(BodyDeclaration decl,
String annotationTypeName) {
if (annotationTypeName == null) {
throw new IllegalArgumentException("annotationTypeName cannot be null");
}
List<ASTNode> modifiers = (List<ASTNode>) decl.getStructuralProperty(decl.getModifiersProperty());
for (ASTNode modifier : modifiers) {
if (modifier instanceof Annotation) {
Annotation annotation = (Annotation) modifier;
String typeName = getAnnotationTypeName(annotation);
if (annotationTypeName.equals(typeName)) {
return annotation;
}
}
}
return null;
}
示例12: validateUiHandlerFieldExistenceInUiXml
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void validateUiHandlerFieldExistenceInUiXml(
MethodDeclaration uiHandlerDecl) {
Annotation annotation = JavaASTUtils.findAnnotation(uiHandlerDecl,
UiBinderConstants.UI_HANDLER_TYPE_NAME);
if (annotation instanceof SingleMemberAnnotation) {
SingleMemberAnnotation uiHandlerAnnotation = (SingleMemberAnnotation) annotation;
Expression exp = uiHandlerAnnotation.getValue();
if (exp instanceof StringLiteral) {
validateFieldExistenceInUiXml(
(TypeDeclaration) uiHandlerDecl.getParent(), exp,
((StringLiteral) exp).getLiteralValue());
} else if (exp instanceof ArrayInitializer) {
for (Expression element : (List<Expression>) ((ArrayInitializer) exp).expressions()) {
if (element instanceof StringLiteral) {
validateFieldExistenceInUiXml(
(TypeDeclaration) uiHandlerDecl.getParent(), element,
((StringLiteral) element).getLiteralValue());
}
}
}
}
}
示例13: isSourceAnnotation
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
private static boolean isSourceAnnotation(ASTNode node) {
if (node instanceof Annotation) {
Annotation annotation = (Annotation) node;
String typeName = annotation.getTypeName().getFullyQualifiedName();
// Annotation can be used with its fully-qualified name
if (typeName.equals(ClientBundleUtilities.CLIENT_BUNDLE_SOURCE_ANNOTATION_NAME)) {
return true;
}
// Simple name is fine, too
String sourceAnnotationSimpleName =
Signature.getSimpleName(ClientBundleUtilities.CLIENT_BUNDLE_SOURCE_ANNOTATION_NAME);
if (typeName.equals(sourceAnnotationSimpleName)) {
return true;
}
}
return false;
}
示例14: validateSourceAnnotationValues
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void validateSourceAnnotationValues(Annotation annotation) throws JavaModelException {
Expression exp = JavaASTUtils.getAnnotationValue(annotation);
if (exp == null) {
return;
}
// There will usually just be one string value
if (exp instanceof StringLiteral) {
validateSourceAnnotationValue((StringLiteral) exp);
}
// But there could be multiple values; if so, check each one.
if (exp instanceof ArrayInitializer) {
ArrayInitializer array = (ArrayInitializer) exp;
for (Expression item : (List<Expression>) array.expressions()) {
if (item instanceof StringLiteral) {
validateSourceAnnotationValue((StringLiteral) item);
}
}
}
}
示例15: checkExpressionIsRValue
import org.eclipse.jdt.core.dom.Annotation; //导入依赖的package包/类
/**
* @param e
* @return int
* Checks.IS_RVALUE if e is an rvalue
* Checks.IS_RVALUE_GUESSED if e is guessed as an rvalue
* Checks.NOT_RVALUE_VOID if e is not an rvalue because its type is void
* Checks.NOT_RVALUE_MISC if e is not an rvalue for some other reason
*/
public static int checkExpressionIsRValue(Expression e) {
if (e instanceof Name) {
if(!(((Name) e).resolveBinding() instanceof IVariableBinding)) {
return NOT_RVALUE_MISC;
}
}
if (e instanceof Annotation)
return NOT_RVALUE_MISC;
ITypeBinding tb= e.resolveTypeBinding();
boolean guessingRequired= false;
if (tb == null) {
guessingRequired= true;
tb= ASTResolving.guessBindingForReference(e);
}
if (tb == null)
return NOT_RVALUE_MISC;
else if (tb.getName().equals("void")) //$NON-NLS-1$
return NOT_RVALUE_VOID;
return guessingRequired ? IS_RVALUE_GUESSED : IS_RVALUE;
}