本文整理汇总了Java中org.eclipse.jdt.core.dom.IBinding.getAnnotations方法的典型用法代码示例。如果您正苦于以下问题:Java IBinding.getAnnotations方法的具体用法?Java IBinding.getAnnotations怎么用?Java IBinding.getAnnotations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.IBinding
的用法示例。
在下文中一共展示了IBinding.getAnnotations方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasNonNullDefault
import org.eclipse.jdt.core.dom.IBinding; //导入方法依赖的package包/类
boolean hasNonNullDefault(IBinding enclosingElement) {
if (!fRemoveIfNonNullByDefault) return false;
IAnnotationBinding[] annotations = enclosingElement.getAnnotations();
for (int i = 0; i < annotations.length; i++) {
IAnnotationBinding annot = annotations[i];
if (annot.getAnnotationType().getQualifiedName().equals(fNonNullByDefaultName)) {
IMemberValuePairBinding[] pairs = annot.getDeclaredMemberValuePairs();
if (pairs.length > 0) {
// is default cancelled by "false" or "value=false" ?
for (int j = 0; j < pairs.length; j++)
if (pairs[j].getKey() == null || pairs[j].getKey().equals("value")) // $NON-NLS-1$
return (pairs[j].getValue() != Boolean.FALSE);
}
return true;
}
}
if (enclosingElement instanceof IMethodBinding) {
return hasNonNullDefault(((IMethodBinding) enclosingElement).getDeclaringClass());
} else if (enclosingElement instanceof ITypeBinding) {
ITypeBinding typeBinding = (ITypeBinding) enclosingElement;
if (typeBinding.isLocal()) return hasNonNullDefault(typeBinding.getDeclaringMethod());
else if (typeBinding.isMember()) return hasNonNullDefault(typeBinding.getDeclaringClass());
else return hasNonNullDefault(typeBinding.getPackage());
}
return false;
}
示例2: findNullnessDefault
import org.eclipse.jdt.core.dom.IBinding; //导入方法依赖的package包/类
/**
* Answer the annotation binding representing a nullness default
* effective at the point denoted by 'contextBinding'.
* @param contextBinding method binding or type binding denoting the location of interest
* @param javaProject the containing java project, consulted for the actual name of
* the annotation used for nullness defaults (default: <code>@NonNullByDefault</code>).
* @return binding for the effective nullness default annotation
* or null if no nullness default is effective at the context location.
*/
public static IAnnotationBinding findNullnessDefault(IBinding contextBinding, IJavaProject javaProject) {
if (JavaCore.ENABLED.equals(javaProject.getOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, true))) {
String annotationName= javaProject.getOption(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, true);
while (contextBinding != null) {
for (IAnnotationBinding annotation : contextBinding.getAnnotations()) {
ITypeBinding annotationType= annotation.getAnnotationType();
if (annotationType != null && annotationType.getQualifiedName().equals(annotationName)) {
return annotation;
}
}
// travel out:
switch (contextBinding.getKind()) {
case IBinding.METHOD:
IMethodBinding methodBinding= (IMethodBinding) contextBinding;
contextBinding= methodBinding.getDeclaringMember();
if (contextBinding == null) {
contextBinding= methodBinding.getDeclaringClass();
}
break;
case IBinding.VARIABLE:
IVariableBinding variableBinding= (IVariableBinding) contextBinding;
contextBinding= variableBinding.getDeclaringMethod();
if (contextBinding == null) {
contextBinding= variableBinding.getDeclaringClass();
}
break;
case IBinding.TYPE:
ITypeBinding currentClass= (ITypeBinding) contextBinding;
contextBinding= currentClass.getDeclaringMember();
if (contextBinding == null) {
contextBinding= currentClass.getDeclaringMethod();
if (contextBinding == null) {
contextBinding= currentClass.getDeclaringClass();
if (contextBinding == null) {
contextBinding= currentClass.getPackage();
}
}
}
break;
default:
contextBinding= null;
break;
}
}
}
return null;
}
示例3: hasNamedAnnotation
import org.eclipse.jdt.core.dom.IBinding; //导入方法依赖的package包/类
/**
* Less strict version of the above where we don't care about the annotation's package.
*/
public static boolean hasNamedAnnotation(IBinding binding, String annotationName) {
for (IAnnotationBinding annotation : binding.getAnnotations()) {
if (annotation.getName().equals(annotationName)) {
return true;
}
}
return false;
}
示例4: getAnnotations
import org.eclipse.jdt.core.dom.IBinding; //导入方法依赖的package包/类
public static List<IAnnotationBinding> getAnnotations(IBinding binding, Class<?> annotationClass) {
List<IAnnotationBinding> out = Lists.newArrayList();
for (IAnnotationBinding annotation : binding.getAnnotations()) {
if (typeEqualsClass(annotation.getAnnotationType(), annotationClass)) {
out.add(annotation);
}
}
return out;
}
示例5: obtainAnnotation
import org.eclipse.jdt.core.dom.IBinding; //导入方法依赖的package包/类
/**
* @return the annotation binding if it is present on the declaration or null
*/
public static IAnnotationBinding obtainAnnotation(IBinding binding, Class<?> annotationClass) {
for (IAnnotationBinding annotation : binding.getAnnotations()) {
if (identicalAnnotations(annotation, annotationClass)) {
return annotation;
}
}
return null;
}
示例6: getAnnotations
import org.eclipse.jdt.core.dom.IBinding; //导入方法依赖的package包/类
private String getAnnotations(
IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion)
throws URISyntaxException, JavaModelException {
if (!(element instanceof IPackageFragment)) {
if (!(element instanceof IAnnotatable)) return null;
if (((IAnnotatable) element).getAnnotations().length == 0) return null;
}
IBinding binding = null;
// TODO
ASTNode node = null; // getHoveredASTNode(editorInputElement, hoverRegion);
if (node == null) {
// todo use ast ported parser,that uses our java model
// ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
// p.setProject(element.getJavaProject());
// p.setBindingsRecovery(true);
// try {
// binding = p.createBindings(new IJavaElement[]{element}, null)[0];
// } catch (OperationCanceledException e) {
// return null;
// }
} else {
binding = resolveBinding(node);
}
if (binding == null) return null;
IAnnotationBinding[] annotations = binding.getAnnotations();
if (annotations.length == 0) return null;
StringBuffer buf = new StringBuffer();
for (int i = 0; i < annotations.length; i++) {
// TODO: skip annotations that don't have an @Documented annotation?
addAnnotation(buf, element, annotations[i]);
buf.append("<br>"); // $NON-NLS-1$
}
return buf.toString();
}