'Add annotations to classpath' quickfix supported when IDEA is running from sources
authornik <Nikolay.Chashnikov@jetbrains.com>
Fri, 14 Aug 2015 12:33:26 +0000 (15:33 +0300)
committernik <Nikolay.Chashnikov@jetbrains.com>
Fri, 14 Aug 2015 12:39:16 +0000 (15:39 +0300)
java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/JetBrainsAnnotationsExternalLibraryResolver.java

index f377d28563bd6ab4046ef29dc8c5b63baad15cb3..28d031196eaa9355346b5a8b950eca7cb5c2a71e 100644 (file)
 package com.intellij.codeInsight.daemon.impl.quickfix;
 
 import com.intellij.codeInsight.AnnotationUtil;
-import com.intellij.openapi.roots.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.roots.ExternalLibraryDescriptor;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.pom.java.LanguageLevel;
 import com.intellij.util.ThreeState;
+import org.intellij.lang.annotations.Flow;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -39,17 +41,34 @@ public class JetBrainsAnnotationsExternalLibraryResolver extends ExternalLibrary
     @NotNull
     @Override
     public List<String> getLibraryClassesRoots() {
-      return Collections.singletonList(FileUtil.toSystemIndependentName(new File(PathManager.getLibPath(), "annotations.jar").getAbsolutePath()));
+      File annotationsJar = new File(PathManager.getLibPath(), "annotations.jar");
+      if (annotationsJar.exists()) {
+        return Collections.singletonList(FileUtil.toSystemIndependentName(annotationsJar.getAbsolutePath()));
+      }
+      return getPathsToAnnotationsDirectoriesInDevelopmentMode("annotations");
     }
   };
+
   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()));
+      File annotationsJar = new File(PathManager.getHomePath(), "redist/annotations-java8.jar");
+      if (annotationsJar.exists()) {
+        return Collections.singletonList(FileUtil.toSystemIndependentName(annotationsJar.getAbsolutePath()));
+      }
+      return getPathsToAnnotationsDirectoriesInDevelopmentMode("annotations-java8");
     }
   };
 
+  @NotNull
+  private static List<String> getPathsToAnnotationsDirectoriesInDevelopmentMode(final String moduleName) {
+    final String annotationsRoot = PathManager.getJarPathForClass(Flow.class);
+    if (annotationsRoot == null) return Collections.emptyList();
+    return Arrays.asList(annotationsRoot, FileUtil.toSystemIndependentName(new File(new File(annotationsRoot).getParentFile(),
+                                                                                    moduleName).getAbsolutePath()));
+  }
+
   @Nullable
   @Override
   public ExternalClassResolveResult resolveClass(@NotNull String shortClassName, @NotNull ThreeState isAnnotation, @NotNull Module contextModule) {