当前位置: 首页>>代码示例>>Java>>正文


Java IBinding.getAnnotations方法代码示例

本文整理汇总了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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:NullAnnotationsRewriteOperations.java

示例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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:57,代码来源:Bindings.java

示例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;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:12,代码来源:BindingUtil.java

示例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;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:11,代码来源:BindingUtil.java

示例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;
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:12,代码来源:SharedUtils.java

示例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();
}
 
开发者ID:eclipse,项目名称:che,代码行数:43,代码来源:JavadocFinder.java


注:本文中的org.eclipse.jdt.core.dom.IBinding.getAnnotations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。