DebuggerUtils#findSourceFileForClass() doesn't use JetFilesProvider

This commit is contained in:
Pavel V. Talanov
2014-06-24 18:21:42 +04:00
parent b2c3a7d501
commit 9f9ddbebf4
3 changed files with 18 additions and 20 deletions
@@ -22,6 +22,7 @@ import com.intellij.debugger.SourcePosition;
import com.intellij.debugger.engine.DebugProcess; import com.intellij.debugger.engine.DebugProcess;
import com.intellij.debugger.requests.ClassPrepareRequestor; import com.intellij.debugger.requests.ClassPrepareRequestor;
import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.Ref;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
@@ -108,7 +109,8 @@ public class JetPositionManager implements PositionManager {
String referenceInternalName = referenceFqName.replace('.', '/'); String referenceInternalName = referenceFqName.replace('.', '/');
JvmClassName className = JvmClassName.byInternalName(referenceInternalName); JvmClassName className = JvmClassName.byInternalName(referenceInternalName);
return DebuggerUtils.findSourceFileForClass(GlobalSearchScope.allScope(myDebugProcess.getProject()), className, sourceName); Project project = myDebugProcess.getProject();
return DebuggerUtils.findSourceFileForClass(project, GlobalSearchScope.allScope(project), className, sourceName);
} }
@NotNull @NotNull
@@ -29,7 +29,6 @@ import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.java.JvmClassName; import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils; import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.plugin.caches.resolve.IDELightClassGenerationSupport;
import org.jetbrains.jet.plugin.util.DebuggerUtils; import org.jetbrains.jet.plugin.util.DebuggerUtils;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@@ -65,7 +64,7 @@ public class JetExceptionFilter implements Filter {
String internalName = fullyQualifiedName.replace('.', '/'); String internalName = fullyQualifiedName.replace('.', '/');
JvmClassName jvmClassName = JvmClassName.byInternalName(internalName); JvmClassName jvmClassName = JvmClassName.byInternalName(internalName);
JetFile file = DebuggerUtils.findSourceFileForClass(searchScope, jvmClassName, fileName); JetFile file = DebuggerUtils.findSourceFileForClass(project, searchScope, jvmClassName, fileName);
if (file == null) return null; if (file == null) return null;
VirtualFile virtualFile = file.getVirtualFile(); VirtualFile virtualFile = file.getVirtualFile();
@@ -18,53 +18,50 @@ package org.jetbrains.jet.plugin.util;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Collections2; import com.google.common.collect.Collections2;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.codegen.binding.PsiCodegenPredictor; import org.jetbrains.jet.codegen.binding.PsiCodegenPredictor;
import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
import org.jetbrains.jet.lang.resolve.java.JvmClassName; import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage; import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import java.util.Collection; import java.util.Collection;
import static org.jetbrains.jet.plugin.stubindex.PackageIndexUtil.findFilesWithExactPackage;
public class DebuggerUtils { public class DebuggerUtils {
private DebuggerUtils() { private DebuggerUtils() {
} }
@Nullable @Nullable
public static JetFile findSourceFileForClass( public static JetFile findSourceFileForClass(
@NotNull Project project,
@NotNull GlobalSearchScope searchScope, @NotNull GlobalSearchScope searchScope,
@NotNull JvmClassName className, @NotNull JvmClassName className,
@NotNull final String fileName @NotNull final String fileName
) { ) {
JetFilesProvider filesProvider = JetFilesProvider.getInstance(searchScope.getProject());
Collection<JetFile> filesInScope = filesProvider.allInScope(searchScope);
final FqName packageFqName = getPackageFqNameForClass(className); FqName packageFqName = getPackageFqNameForClass(className);
// Only consider files with the file name from the stack trace and in the given package Collection<JetFile> filesInPackage = findFilesWithExactPackage(packageFqName, searchScope, project);
Collection<JetFile> files = Collections2.filter(filesInScope, new Predicate<JetFile>() { Collection<JetFile> filesWithExactName = Collections2.filter(filesInPackage, new Predicate<JetFile>() {
@Override @Override
public boolean apply(@Nullable JetFile file) { public boolean apply(@Nullable JetFile file) {
return file != null return file != null && file.getName().equals(fileName);
&& file.getName().equals(fileName)
&& file.getPackageFqName().equals(packageFqName);
} }
}); });
if (files.isEmpty()) return null; if (filesWithExactName.isEmpty()) return null;
JetFile anyFile = files.iterator().next(); if (filesWithExactName.size() == 1) {
if (files.size() == 1) { return filesWithExactName.iterator().next();
return anyFile;
} }
Collection<JetFile> allPackageFiles = filesProvider.allPackageFiles(anyFile); JetFile file = PsiCodegenPredictor.getFileForPackagePartName(filesWithExactName, className);
JetFile file = PsiCodegenPredictor.getFileForPackagePartName(allPackageFiles, className);
if (file != null) { if (file != null) {
return file; return file;
} }
@@ -72,10 +69,10 @@ public class DebuggerUtils {
// In the rare case that there's more than one file with this name in this package, // In the rare case that there's more than one file with this name in this package,
// we may actually need to analyze the project in order to find a file which produces this class // we may actually need to analyze the project in order to find a file which produces this class
// TODO: this code is not entirely correct, because it takes a session for only one file // TODO: this code is not entirely correct, because it takes a session for only one file
AnalyzeExhaust analyzeExhaust = ResolvePackage.getAnalysisResultsForElements(files); AnalyzeExhaust analyzeExhaust = ResolvePackage.getAnalysisResultsForElements(filesWithExactName);
return PsiCodegenPredictor.getFileForCodegenNamedClass(analyzeExhaust.getModuleDescriptor(), analyzeExhaust.getBindingContext(), return PsiCodegenPredictor.getFileForCodegenNamedClass(analyzeExhaust.getModuleDescriptor(), analyzeExhaust.getBindingContext(),
allPackageFiles, className.getInternalName()); filesWithExactName, className.getInternalName());
} }
@NotNull @NotNull