diff --git a/java/java-psi-api/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java b/java/java-psi-api/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java index 89b476970f20..ef03545de723 100644 --- a/java/java-psi-api/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java +++ b/java/java-psi-api/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java @@ -200,28 +200,36 @@ public abstract class BaseExternalAnnotationsManager extends ExternalAnnotations String externalName = getExternalName(listOwner, false); String oldExternalName = getNormalizedExternalName(listOwner); + final PsiElementFactory factory = JavaPsiFacade.getInstance(myPsiManager.getProject()).getElementFactory(); for (PsiFile file : files) { if (!file.isValid()) continue; if (onlyWritable && !file.isWritable()) continue; - MultiMap fileData = getDataFromFile(file); - for (AnnotationData annotationData : ContainerUtil.concat(fileData.get(externalName), fileData.get(oldExternalName))) { - // don't add annotation, if there already is one with this FQ name - if (result.containsKey(annotationData.annotationClassFqName)) continue; - - try { - PsiElementFactory factory = JavaPsiFacade.getInstance(myPsiManager.getProject()).getElementFactory(); - PsiAnnotation annotation = factory.createAnnotationFromText(annotationData.annotationText, null); - result.put(annotationData.annotationClassFqName, annotation); - } - catch (IncorrectOperationException e) { - LOG.error(e); - } - } + final MultiMap fileData = getDataFromFile(file); + + collectAnnotations(result, fileData.get(externalName), factory); + collectAnnotations(result, fileData.get(oldExternalName), factory); } return result; } + private static void collectAnnotations(Map result, + Collection dataCollection, + PsiElementFactory factory) { + for (AnnotationData annotationData : dataCollection) { + // don't add annotation, if there already is one with this FQ name + if (result.containsKey(annotationData.annotationClassFqName)) continue; + + try { + PsiAnnotation annotation = factory.createAnnotationFromText(annotationData.annotationText, null); + result.put(annotationData.annotationClassFqName, annotation); + } + catch (IncorrectOperationException e) { + LOG.error(e); + } + } + } + @NotNull protected abstract List getExternalAnnotationsRoots(@NotNull VirtualFile libraryFile);