simplification
[idea/community.git] / java / java-impl / src / com / intellij / codeInsight / daemon / impl / quickfix / JetBrainsAnnotationsExternalLibraryResolver.java
index e5b6a3c09e7dd442ea524a98b71e6c193d50cd60..02ce2d391cf7eb0a80ff4da6e7e51e7a160734ea 100644 (file)
@@ -18,32 +18,57 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
 import com.intellij.codeInsight.AnnotationUtil;
 import com.intellij.codeInsight.daemon.quickFix.ExternalLibraryDescriptor;
 import com.intellij.codeInsight.daemon.quickFix.ExternalLibraryResolver;
+import com.intellij.openapi.application.PathManager;
+import com.intellij.openapi.module.EffectiveLanguageLevelUtil;
 import com.intellij.openapi.module.Module;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.pom.java.LanguageLevel;
 import com.intellij.util.ThreeState;
-import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import java.io.File;
+import java.util.Collections;
 import java.util.List;
 
 /**
  * @author nik
  */
 public class JetBrainsAnnotationsExternalLibraryResolver extends ExternalLibraryResolver {
-  private static final ExternalLibraryDescriptor ANNOTATIONS = new ExternalLibraryDescriptor("com.intellij", "annotations", null) {
+  private static final ExternalLibraryDescriptor JAVA5 = new JetBrainsAnnotationsLibraryDescriptor() {
     @NotNull
     @Override
-    public List<String> locateLibraryClassesRoots(@NotNull Module contextModule) {
-      return ContainerUtil.createMaybeSingletonList(OrderEntryFix.locateAnnotationsJar(contextModule));
+    public List<String> getLibraryClassesRoots() {
+      return Collections.singletonList(FileUtil.toSystemIndependentName(new File(PathManager.getLibPath(), "annotations.jar").getAbsolutePath()));
+    }
+  };
+  private static final ExternalLibraryDescriptor JAVA8 = new JetBrainsAnnotationsLibraryDescriptor() {
+    @NotNull
+    @Override
+    public List<String> getLibraryClassesRoots() {
+      return Collections.singletonList(FileUtil.toSystemIndependentName(new File(PathManager.getHomePath(), "redist/annotations-java8.jar").getAbsolutePath()));
     }
   };
 
   @Nullable
   @Override
-  public ExternalClassResolveResult resolveClass(@NotNull String shortClassName, @NotNull ThreeState isAnnotation) {
+  public ExternalClassResolveResult resolveClass(@NotNull String shortClassName, @NotNull ThreeState isAnnotation, @NotNull Module contextModule) {
     if (AnnotationUtil.isJetbrainsAnnotation(shortClassName)) {
-      return new ExternalClassResolveResult("org.jetbrains.annotations." + shortClassName, ANNOTATIONS);
+      ExternalLibraryDescriptor libraryDescriptor = getAnnotationsLibraryDescriptor(contextModule);
+      return new ExternalClassResolveResult("org.jetbrains.annotations." + shortClassName, libraryDescriptor);
     }
     return null;
   }
+
+  @NotNull
+  public static ExternalLibraryDescriptor getAnnotationsLibraryDescriptor(@NotNull Module contextModule) {
+    boolean java8 = EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(contextModule).isAtLeast(LanguageLevel.JDK_1_8);
+    return java8 ? JAVA8 : JAVA5;
+  }
+
+  private static abstract class JetBrainsAnnotationsLibraryDescriptor extends ExternalLibraryDescriptor {
+    public JetBrainsAnnotationsLibraryDescriptor() {
+      super("com.intellij", "annotations", null);
+    }
+  }
 }