List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodBinding getParameterAnnotations
public AnnotationBinding[][] getParameterAnnotations()
From source file:com.android.tools.lint.psi.EcjPsiJavaEvaluator.java
License:Apache License
@NonNull @Override/*from ww w .j a v a 2s .co 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.codenvy.ide.ext.java.server.TypeBindingConvector.java
License:Open Source License
private static JsonElement toJsonParameterAnnotations(MethodBinding method) { AnnotationBinding[][] parameterAnnotations = method.getParameterAnnotations(); if (parameterAnnotations == null) return JsonNull.INSTANCE; JsonArray array = new JsonArray(); for (AnnotationBinding[] parameterAnnotation : parameterAnnotations) { array.add(toJsonAnnotations(parameterAnnotation)); }//from w w w . j a v a 2 s. c o m return array; }