private static PsiAnnotation[] getHierarchyAnnotations( PsiModifierListOwner listOwner, PsiModifierList modifierList) { final Set<PsiAnnotation> all = new HashSet<PsiAnnotation>() { public boolean add(PsiAnnotation o) { // don't overwrite "higher level" annotations return !contains(o) && super.add(o); } }; if (listOwner instanceof PsiMethod) { ContainerUtil.addAll(all, modifierList.getAnnotations()); SuperMethodsSearch.search((PsiMethod) listOwner, null, true, true) .forEach( new Processor<MethodSignatureBackedByPsiMethod>() { public boolean process(final MethodSignatureBackedByPsiMethod superMethod) { ContainerUtil.addAll( all, superMethod.getMethod().getModifierList().getAnnotations()); return true; } }); return all.toArray(new PsiAnnotation[all.size()]); } if (listOwner instanceof PsiParameter) { PsiParameter parameter = (PsiParameter) listOwner; PsiElement declarationScope = parameter.getDeclarationScope(); PsiParameterList parameterList; if (declarationScope instanceof PsiMethod && parameter.getParent() == (parameterList = ((PsiMethod) declarationScope).getParameterList())) { PsiMethod method = (PsiMethod) declarationScope; final int parameterIndex = parameterList.getParameterIndex(parameter); ContainerUtil.addAll(all, modifierList.getAnnotations()); SuperMethodsSearch.search(method, null, true, true) .forEach( new Processor<MethodSignatureBackedByPsiMethod>() { public boolean process(final MethodSignatureBackedByPsiMethod superMethod) { PsiParameter superParameter = superMethod.getMethod().getParameterList().getParameters()[parameterIndex]; PsiModifierList modifierList = superParameter.getModifierList(); if (modifierList != null) { ContainerUtil.addAll(all, modifierList.getAnnotations()); } return true; } }); return all.toArray(new PsiAnnotation[all.size()]); } } return modifierList.getAnnotations(); }
/** * Returns all annotations for <code>listOwner</code>, possibly walking up the method hierarchy. * * @see com.intellij.codeInsight.AnnotationUtil#isAnnotated(com.intellij.psi.PsiModifierListOwner, * java.lang.String, boolean) */ private static PsiAnnotation[] getAnnotations( @NotNull final PsiModifierListOwner listOwner, final boolean inHierarchy) { final PsiModifierList modifierList = listOwner.getModifierList(); if (modifierList == null) { return PsiAnnotation.EMPTY_ARRAY; } if (!inHierarchy) { return modifierList.getAnnotations(); } return CachedValuesManager.getCachedValue( listOwner, new CachedValueProvider<PsiAnnotation[]>() { @Nullable @Override public Result<PsiAnnotation[]> compute() { return Result.create( getHierarchyAnnotations(listOwner, modifierList), PsiModificationTracker.MODIFICATION_COUNT); } }); }