IDEA-29246 Debug with alternative JRE - JDK source is incorrect - fixes after review...
authorEgor.Ushakov <egor.ushakov@jetbrains.com>
Wed, 24 Aug 2016 14:36:17 +0000 (17:36 +0300)
committerEgor.Ushakov <egor.ushakov@jetbrains.com>
Wed, 24 Aug 2016 14:37:12 +0000 (17:37 +0300)
java/debugger/impl/src/com/intellij/debugger/DefaultDebugEnvironment.java
java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java
java/debugger/impl/src/com/intellij/debugger/impl/AlternativeJreClassFinder.java [moved from java/debugger/impl/src/com/intellij/debugger/impl/AlternativeJreIndexHelper.java with 70% similarity]
java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java
resources/src/META-INF/IdeaPlugin.xml

index e4d6499f6e42d4d28a0abe434cc0526e96a6b2bb..f6c221797251cd97ed13c8d9916700d715ed6691 100644 (file)
@@ -15,7 +15,7 @@
  */
 package com.intellij.debugger;
 
-import com.intellij.debugger.impl.AlternativeJreIndexHelper;
+import com.intellij.debugger.impl.AlternativeJreClassFinder;
 import com.intellij.debugger.impl.DebuggerManagerImpl;
 import com.intellij.debugger.settings.DebuggerSettings;
 import com.intellij.execution.ExecutionException;
@@ -94,6 +94,6 @@ public class DefaultDebugEnvironment implements DebugEnvironment {
   @Nullable
   @Override
   public Sdk getAlternativeJre() {
-    return AlternativeJreIndexHelper.getAlternativeJre(environment.getRunProfile());
+    return AlternativeJreClassFinder.getAlternativeJre(environment.getRunProfile());
   }
 }
index 25188dd36f7d94a477d8cc8ce7e54de2656ff00a..45d55ed2bfd010889b7d6d1700b08247996048a1 100644 (file)
@@ -20,14 +20,13 @@ import com.intellij.debugger.NoDataException;
 import com.intellij.debugger.PositionManager;
 import com.intellij.debugger.SourcePosition;
 import com.intellij.debugger.engine.evaluation.EvaluateException;
-import com.intellij.debugger.impl.AlternativeJreIndexHelper;
+import com.intellij.debugger.impl.AlternativeJreClassFinder;
 import com.intellij.debugger.impl.DebuggerUtilsEx;
 import com.intellij.debugger.jdi.VirtualMachineProxyImpl;
 import com.intellij.debugger.requests.ClassPrepareRequestor;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.project.IndexNotReadyException;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.util.Computable;
@@ -39,10 +38,8 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.psi.*;
 import com.intellij.psi.impl.compiled.ClsClassImpl;
-import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
 import com.intellij.psi.search.FilenameIndex;
 import com.intellij.psi.search.GlobalSearchScope;
-import com.intellij.psi.stubs.StubIndex;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.util.DocumentUtil;
 import com.intellij.util.containers.ContainerUtil;
@@ -363,34 +360,17 @@ public class PositionManagerImpl implements PositionManager, MultiRequestPositio
     // first check alternative jre if any
     Sdk alternativeJre = myDebugProcess.getSession().getAlternativeJre();
     if (alternativeJre != null) {
-      try {
-        psiClass = ContainerUtil.getFirstItem(StubIndex.getElements(JavaStubIndexKeys.CLASS_FQN,
-                                                                    originalQName.hashCode(),
-                                                                    project,
-                                                                    AlternativeJreIndexHelper.getSearchScope(alternativeJre),
-                                                                    PsiClass.class));
-
+        psiClass = findClass(project, originalQName, AlternativeJreClassFinder.getSearchScope(alternativeJre));
         if (psiClass instanceof ClsClassImpl) { //try to find sources
           PsiFile psiSource = findSourceFile((ClsClassImpl)psiClass, alternativeJre);
           if (psiSource != null) {
             return psiSource;
           }
         }
-      }
-      catch (IndexNotReadyException ignored) {
-      }
     }
 
     if (psiClass == null) {
-      GlobalSearchScope searchScope = myDebugProcess.getSearchScope();
-      psiClass = DebuggerUtils.findClass(originalQName, project, searchScope); // try to lookup original name first
-      if (psiClass == null) {
-        int dollar = originalQName.indexOf('$');
-        if (dollar > 0) {
-          final String qName = originalQName.substring(0, dollar);
-          psiClass = DebuggerUtils.findClass(qName, project, searchScope);
-        }
-      }
+      psiClass = findClass(project, originalQName, myDebugProcess.getSearchScope());
     }
 
     if (psiClass != null) {
@@ -425,13 +405,25 @@ public class PositionManagerImpl implements PositionManager, MultiRequestPositio
     return null;
   }
 
+  @Nullable
+  private static PsiClass findClass(Project project, String originalQName, GlobalSearchScope searchScope) {
+    PsiClass psiClass = DebuggerUtils.findClass(originalQName, project, searchScope); // try to lookup original name first
+    if (psiClass == null) {
+      int dollar = originalQName.indexOf('$');
+      if (dollar > 0) {
+        psiClass = DebuggerUtils.findClass(originalQName.substring(0, dollar), project, searchScope);
+      }
+    }
+    return psiClass;
+  }
+
   @Nullable
   private static PsiFile findSourceFile(ClsClassImpl psiClass, Sdk alternativeJre) {
     String sourceFileName = psiClass.getSourceFileName();
     String packageName = ((PsiClassOwner)psiClass.getContainingFile()).getPackageName();
     String relativePath = packageName.isEmpty() ? sourceFileName : packageName.replace('.', '/') + '/' + sourceFileName;
 
-    for (VirtualFile file : AlternativeJreIndexHelper.getSourceRoots(alternativeJre)) {
+    for (VirtualFile file : AlternativeJreClassFinder.getSourceRoots(alternativeJre)) {
       VirtualFile source = file.findFileByRelativePath(relativePath);
       if (source != null && source.isValid()) {
         PsiFile psiSource = psiClass.getManager().findFile(source);
similarity index 70%
rename from java/debugger/impl/src/com/intellij/debugger/impl/AlternativeJreIndexHelper.java
rename to java/debugger/impl/src/com/intellij/debugger/impl/AlternativeJreClassFinder.java
index 8428225ac9fc1d8f17eb8330aedffb883d5e6a8b..ddd097f15d004f8060c5f664fb617785450c6f30 100644 (file)
  */
 package com.intellij.debugger.impl;
 
-import com.intellij.execution.RunManager;
+import com.intellij.debugger.DebuggerManagerEx;
 import com.intellij.execution.configurations.ConfigurationWithAlternativeJre;
-import com.intellij.execution.configurations.RunConfiguration;
 import com.intellij.execution.configurations.RunProfile;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.projectRoots.ProjectJdkTable;
 import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.roots.OrderRootType;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.NonClasspathClassFinder;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.search.NonClasspathDirectoriesScope;
-import com.intellij.util.containers.SmartHashSet;
-import com.intellij.util.indexing.IndexableSetContributor;
+import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Set;
+import java.util.List;
 
 /**
  * @author egor
  */
-public class AlternativeJreIndexHelper extends IndexableSetContributor {
-  @NotNull
-  @Override
-  public Set<VirtualFile> getAdditionalRootsToIndex() {
-    return Collections.emptySet();
+public class AlternativeJreClassFinder extends NonClasspathClassFinder {
+  public AlternativeJreClassFinder(Project project, DebuggerManagerEx manager) {
+    super(project);
+    manager.addDebuggerManagerListener(new DebuggerManagerAdapter() {
+      public void sessionCreated(DebuggerSession session) {
+        clearCache();
+      }
+
+      public void sessionRemoved(DebuggerSession session) {
+        clearCache();
+      }
+    });
   }
 
-  @NotNull
   @Override
-  public Set<VirtualFile> getAdditionalProjectRootsToIndex(@NotNull Project project) {
-    SmartHashSet<VirtualFile> res = new SmartHashSet<>();
-    for (RunConfiguration configuration : RunManager.getInstance(project).getAllConfigurationsList()) {
-      Sdk jre = getAlternativeJre(configuration);
+  protected List<VirtualFile> calcClassRoots() {
+    Collection<DebuggerSession> sessions = DebuggerManagerEx.getInstanceEx(myProject).getSessions();
+    if (sessions.isEmpty()) {
+      return Collections.emptyList();
+    }
+    List<VirtualFile> res = ContainerUtil.newSmartList();
+    for (DebuggerSession session : sessions) {
+      Sdk jre = session.getAlternativeJre();
       if (jre != null) {
         res.addAll(getClassRoots(jre));
       }
index 3570bdeb3ce3c09c3c466e2ffd0609af78917dff..238c8c5550d9996ccd61fa3a6b8c4cb3f32c2f81 100644 (file)
@@ -33,9 +33,7 @@ import com.intellij.execution.runners.JavaPatchableProgramRunner;
 import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.options.SettingsEditor;
-import com.intellij.openapi.project.DumbService;
 import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.util.indexing.UnindexedFilesUpdater;
 import com.intellij.xdebugger.XDebugProcess;
 import com.intellij.xdebugger.XDebugProcessStarter;
 import com.intellij.xdebugger.XDebugSession;
@@ -118,12 +116,6 @@ public class GenericDebuggerRunner extends JavaPatchableProgramRunner<GenericDeb
     }
 
     final DebugProcessImpl debugProcess = debuggerSession.getProcess();
-
-    // index alternative jdk if needed
-    if (AlternativeJreIndexHelper.getAlternativeJre(env.getRunProfile()) != null) {
-      DumbService.getInstance(debuggerSession.getProject()).queueTask(new UnindexedFilesUpdater(debuggerSession.getProject(), false));
-    }
-
     return XDebuggerManager.getInstance(env.getProject()).startSession(env, new XDebugProcessStarter() {
       @Override
       @NotNull
index 9e7af4061bb6522454921e41a39760a3af319c70..47a26f057298445303e09508eadc66df753b5f8b 100644 (file)
     <debugger.syntheticProvider implementation="com.intellij.debugger.engine.DefaultSyntheticProvider"/>
     <debugger.sourcePositionProvider implementation="com.intellij.debugger.engine.DefaultSourcePositionProvider" order="last"/>
     <debugger.sourcePositionHighlighter implementation="com.intellij.debugger.engine.JavaSourcePositionHighlighter"/>
-    <indexedRootsProvider implementation="com.intellij.debugger.impl.AlternativeJreIndexHelper"/>
+    <java.elementFinder implementation="com.intellij.debugger.impl.AlternativeJreClassFinder" order="last"/>
 
     <debugger.nodeRenderer implementation="com.intellij.debugger.ui.tree.render.ColorObjectRenderer"/>
     <debugger.nodeRenderer implementation="com.intellij.debugger.ui.tree.render.ImageObjectRenderer"/>