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.requests.ClassPrepareRequestor;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
@@ -108,7 +109,8 @@ public class JetPositionManager implements PositionManager {
String referenceInternalName = referenceFqName.replace('.', '/');
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
@@ -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.PackageClassUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.plugin.caches.resolve.IDELightClassGenerationSupport;
import org.jetbrains.jet.plugin.util.DebuggerUtils;
import java.util.regex.Matcher;
@@ -65,7 +64,7 @@ public class JetExceptionFilter implements Filter {
String internalName = fullyQualifiedName.replace('.', '/');
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;
VirtualFile virtualFile = file.getVirtualFile();
@@ -18,53 +18,50 @@ package org.jetbrains.jet.plugin.util;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.codegen.binding.PsiCodegenPredictor;
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.name.FqName;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import java.util.Collection;
import static org.jetbrains.jet.plugin.stubindex.PackageIndexUtil.findFilesWithExactPackage;
public class DebuggerUtils {
private DebuggerUtils() {
}
@Nullable
public static JetFile findSourceFileForClass(
@NotNull Project project,
@NotNull GlobalSearchScope searchScope,
@NotNull JvmClassName className,
@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> files = Collections2.filter(filesInScope, new Predicate<JetFile>() {
Collection<JetFile> filesInPackage = findFilesWithExactPackage(packageFqName, searchScope, project);
Collection<JetFile> filesWithExactName = Collections2.filter(filesInPackage, new Predicate<JetFile>() {
@Override
public boolean apply(@Nullable JetFile file) {
return file != null
&& file.getName().equals(fileName)
&& file.getPackageFqName().equals(packageFqName);
return file != null && file.getName().equals(fileName);
}
});
if (files.isEmpty()) return null;
if (filesWithExactName.isEmpty()) return null;
JetFile anyFile = files.iterator().next();
if (files.size() == 1) {
return anyFile;
if (filesWithExactName.size() == 1) {
return filesWithExactName.iterator().next();
}
Collection<JetFile> allPackageFiles = filesProvider.allPackageFiles(anyFile);
JetFile file = PsiCodegenPredictor.getFileForPackagePartName(allPackageFiles, className);
JetFile file = PsiCodegenPredictor.getFileForPackagePartName(filesWithExactName, className);
if (file != null) {
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,
// 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
AnalyzeExhaust analyzeExhaust = ResolvePackage.getAnalysisResultsForElements(files);
AnalyzeExhaust analyzeExhaust = ResolvePackage.getAnalysisResultsForElements(filesWithExactName);
return PsiCodegenPredictor.getFileForCodegenNamedClass(analyzeExhaust.getModuleDescriptor(), analyzeExhaust.getBindingContext(),
allPackageFiles, className.getInternalName());
filesWithExactName, className.getInternalName());
}
@NotNull