List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding getAnnotations
@Override
public AnnotationBinding[] getAnnotations()
From source file:com.android.tools.lint.psi.EcjPsiBinaryClass.java
License:Apache License
@SuppressWarnings("SameParameterValue") private PsiAnnotation[] findAnnotations(boolean includeSuper) { List<PsiAnnotation> all = Lists.newArrayListWithExpectedSize(4); ExternalAnnotationRepository manager = mManager.getAnnotationRepository(); if (mBinding instanceof ReferenceBinding) { ReferenceBinding cls = (ReferenceBinding) mBinding; while (cls != null) { AnnotationBinding[] annotations; try { annotations = cls.getAnnotations(); } catch (AbortCompilation e) { // ECJ will in some cases go and attempt to load the standard annotations // as part of the annotation lookup above (in // AnnotationBinding#addStandardAnnotations), but if for some reason the // class path is incorrect, this will throw an AbortCompilation. In this // case, just ignore the annotations. annotations = new AnnotationBinding[0]; }//from w ww . ja v a 2s . co m int count = annotations.length; if (count > 0) { all = Lists.newArrayListWithExpectedSize(count); for (AnnotationBinding annotation : annotations) { if (annotation != null) { all.add(new EcjPsiBinaryAnnotation(mManager, this, annotation)); } } } // Look for external annotations if (manager != null) { Collection<PsiAnnotation> external = manager.getAnnotations(cls); if (external != null) { all.addAll(external); } } if (!includeSuper) { break; } cls = cls.superclass(); } } return EcjPsiManager.ensureUnique(all); }
From source file:com.android.tools.lint.psi.EcjPsiJavaEvaluator.java
License:Apache License
@NonNull @Override//w w w .j a va2 s. c o m public PsiAnnotation[] getAllAnnotations(@NonNull PsiModifierListOwner owner, boolean inHierarchy) { if (!inHierarchy) { return getDirectAnnotations(owner); } PsiModifierList modifierList = owner.getModifierList(); if (modifierList == null) { return getDirectAnnotations(owner); } if (owner instanceof PsiMethod) { MethodBinding method; if (owner instanceof EcjPsiMethod) { EcjPsiMethod psiMethod = (EcjPsiMethod) owner; AbstractMethodDeclaration declaration = (AbstractMethodDeclaration) psiMethod.getNativeNode(); assert declaration != null; method = declaration.binding; } else if (owner instanceof EcjPsiBinaryMethod) { method = ((EcjPsiBinaryMethod) owner).getBinding(); } else { assert false : owner.getClass(); return PsiAnnotation.EMPTY_ARRAY; } List<PsiAnnotation> all = Lists.newArrayListWithExpectedSize(2); ExternalAnnotationRepository manager = mManager.getAnnotationRepository(); while (method != null) { if (method.declaringClass == null) { // for example, for unresolved problem bindings break; } AnnotationBinding[] annotations = method.getAnnotations(); int count = annotations.length; if (count > 0) { all = Lists.newArrayListWithExpectedSize(count); for (AnnotationBinding annotation : annotations) { if (annotation != null) { all.add(new EcjPsiBinaryAnnotation(mManager, modifierList, annotation)); } } } // Look for external annotations if (manager != null) { Collection<PsiAnnotation> external = manager.getAnnotations(method); if (external != null) { all.addAll(external); } } method = EcjPsiManager.findSuperMethodBinding(method, false, false); } return EcjPsiManager.ensureUnique(all); } else if (owner instanceof PsiClass) { ReferenceBinding cls; if (owner instanceof EcjPsiClass) { EcjPsiClass psiClass = (EcjPsiClass) owner; TypeDeclaration declaration = (TypeDeclaration) psiClass.getNativeNode(); assert declaration != null; cls = declaration.binding; } else if (owner instanceof EcjPsiBinaryClass) { cls = ((EcjPsiBinaryClass) owner).getTypeBinding(); } else { assert false : owner.getClass(); return PsiAnnotation.EMPTY_ARRAY; } List<PsiAnnotation> all = Lists.newArrayListWithExpectedSize(2); ExternalAnnotationRepository manager = mManager.getAnnotationRepository(); while (cls != null) { AnnotationBinding[] annotations = cls.getAnnotations(); int count = annotations.length; if (count > 0) { all = Lists.newArrayListWithExpectedSize(count); for (AnnotationBinding annotation : annotations) { if (annotation != null) { all.add(new EcjPsiBinaryAnnotation(mManager, modifierList, annotation)); } } } // Look for external annotations if (manager != null) { Collection<PsiAnnotation> external = manager.getAnnotations(cls); if (external != null) { all.addAll(external); } } try { cls = cls.superclass(); } catch (AbortCompilation ignore) { // Encountered symbol that couldn't be resolved (e.g. compiled class references // class not found on the classpath break; } } return EcjPsiManager.ensureUnique(all); } else if (owner instanceof PsiParameter) { MethodBinding method; int index; if (owner instanceof EcjPsiBinaryParameter) { EcjPsiBinaryParameter parameter = (EcjPsiBinaryParameter) owner; method = parameter.getOwnerMethod().getBinding(); index = parameter.getIndex(); } else if (owner instanceof EcjPsiParameter) { EcjPsiParameter parameter = (EcjPsiParameter) owner; if (parameter.getParent() instanceof PsiParameterList) { EcjPsiMethod psiMethod = (EcjPsiMethod) PsiTreeUtil.getParentOfType(parameter.getParent(), PsiMethod.class, true); if (psiMethod == null) { return getDirectAnnotations(owner); } index = ((PsiParameterList) parameter.getParent()).getParameterIndex(parameter); AbstractMethodDeclaration declaration = (AbstractMethodDeclaration) psiMethod.getNativeNode(); assert declaration != null; method = declaration.binding; } else { // For each block, catch block return getDirectAnnotations(owner); } } else { // Unexpected method type assert false : owner.getClass(); return getDirectAnnotations(owner); } List<PsiAnnotation> all = Lists.newArrayListWithExpectedSize(2); ExternalAnnotationRepository manager = mManager.getAnnotationRepository(); while (method != null) { if (method.declaringClass == null) { // for example, for unresolved problem bindings break; } AnnotationBinding[][] parameterAnnotations = method.getParameterAnnotations(); if (parameterAnnotations != null && index < parameterAnnotations.length) { AnnotationBinding[] annotations = parameterAnnotations[index]; int count = annotations.length; if (count > 0) { for (AnnotationBinding annotation : annotations) { if (annotation != null) { all.add(new EcjPsiBinaryAnnotation(mManager, modifierList, annotation)); } } } } // Look for external annotations if (manager != null) { Collection<PsiAnnotation> external = manager.getParameterAnnotations(method, index); if (external != null) { all.addAll(external); } } method = EcjPsiManager.findSuperMethodBinding(method, false, false); } return EcjPsiManager.ensureUnique(all); } else { // PsiField, PsiLocalVariable etc: no inheritance return getDirectAnnotations(owner); } }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.UnknownClassMirror.java
License:Open Source License
@Override public AnnotationMirror getAnnotation(String annotationType) { if (annotations == null) { doWithBindings(new ActionOnClassBinding() { @Override/* w w w. j a v a 2s.co m*/ public void doWithBinding(IType classModel, ReferenceBinding klass) { annotations = JDTUtils.getAnnotations(klass.getAnnotations()); isInnerType = getAnnotation(AbstractModelLoader.CEYLON_CONTAINER_ANNOTATION) != null || klass.isMemberType(); } }); } return annotations.get(annotationType); }
From source file:lombok.eclipse.agent.PatchVisibleForTesting.java
License:Open Source License
private static ReferenceBinding handleVisibleForTestingOnType(final Scope scope, final ReferenceBinding typeBinding) { if (typeBinding == null) return typeBinding; for (AnnotationBinding annotation : Each.elementIn(typeBinding.getAnnotations())) { if (!As.string(annotation.getAnnotationType()).contains("VisibleForTesting")) continue; ClassScope classScope = scope.outerMostClassScope(); if (classScope == null) continue; TypeDeclaration decl = classScope.referenceContext; if (As.string(decl.name).contains("Test")) continue; return new ProblemReferenceBinding(typeBinding.compoundName, typeBinding, ProblemReasons.NotVisible); }//from w w w . ja v a2 s. co m return typeBinding; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel.java
License:Open Source License
public static Lifting.InstantiationPolicy getInstantiationPolicy(ReferenceBinding roleClassBinding) { if ((roleClassBinding.getAnnotationTagBits() & TagBits.AnnotationInstantiation) != 0) { for (AnnotationBinding annotation : roleClassBinding.getAnnotations()) { if (annotation.getAnnotationType().id == IOTConstants.T_OrgObjectTeamsInstantiation) { for (ElementValuePair pair : annotation.getElementValuePairs()) { if (pair.value instanceof FieldBinding) { String name = String.valueOf(((FieldBinding) pair.value).name); try { return InstantiationPolicy.valueOf(name); } catch (IllegalArgumentException iae) { return InstantiationPolicy.ERROR; }//from w ww . j ava 2 s .co m } } } } } return InstantiationPolicy.ONDEMAND; // default }