breakpoints for multi-file namespaces
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -47,6 +48,7 @@ public class ClosureAnnotator {
|
||||
private final Map<DeclarationDescriptor, ClassDescriptorImpl> classesForFunctions = new HashMap<DeclarationDescriptor, ClassDescriptorImpl>();
|
||||
private final Map<DeclarationDescriptor,ClassDescriptor> enclosing = new HashMap<DeclarationDescriptor, ClassDescriptor>();
|
||||
|
||||
private final MultiMap<FqName, JetFile> namespaceName2MultiNamespaceFiles = MultiMap.create();
|
||||
private final MultiMap<FqName, JetFile> namespaceName2Files = MultiMap.create();
|
||||
|
||||
private BindingContext bindingContext;
|
||||
@@ -165,9 +167,33 @@ public class ClosureAnnotator {
|
||||
for (JetFile jetFile : entry.getValue()) {
|
||||
jetFile.accept(visitor);
|
||||
}
|
||||
|
||||
ArrayList<JetFile> namespaceFiles = new ArrayList<JetFile>();
|
||||
for (JetFile jetFile : entry.getValue()) {
|
||||
ArrayList<JetDeclaration> fileFunctions = new ArrayList<JetDeclaration>();
|
||||
for (JetDeclaration declaration : jetFile.getDeclarations()) {
|
||||
if (declaration instanceof JetNamedFunction) {
|
||||
fileFunctions.add(declaration);
|
||||
}
|
||||
}
|
||||
|
||||
if (fileFunctions.size() > 0) {
|
||||
namespaceFiles.add(jetFile);
|
||||
}
|
||||
}
|
||||
|
||||
if(namespaceFiles.size() > 1) {
|
||||
for (JetFile namespaceFile : namespaceFiles) {
|
||||
namespaceName2MultiNamespaceFiles.putValue(entry.getKey(), namespaceFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMultiFileNamespace(FqName fqName) {
|
||||
return namespaceName2MultiNamespaceFiles.get(fqName).size() > 0;
|
||||
}
|
||||
|
||||
public JvmClassName classNameForAnonymousClass(JetElement expression) {
|
||||
if (expression instanceof JetObjectLiteralExpression) {
|
||||
JetObjectLiteralExpression jetObjectLiteralExpression = (JetObjectLiteralExpression) expression;
|
||||
|
||||
@@ -81,20 +81,7 @@ public class NamespaceCodegen {
|
||||
}
|
||||
|
||||
public void generate(CompilationErrorHandler errorHandler, final Progress progress) {
|
||||
ArrayList<Pair<JetFile, Collection<JetDeclaration>>> byFile = new ArrayList<Pair<JetFile, Collection<JetDeclaration>>>();
|
||||
|
||||
for (JetFile file : files) {
|
||||
ArrayList<JetDeclaration> fileFunctions = new ArrayList<JetDeclaration>();
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetNamedFunction) {
|
||||
fileFunctions.add(declaration);
|
||||
}
|
||||
}
|
||||
if (fileFunctions.size() > 0)
|
||||
byFile.add(new Pair<JetFile, Collection<JetDeclaration>>(file, fileFunctions));
|
||||
}
|
||||
|
||||
boolean multiFile = byFile.size() > 1;
|
||||
boolean multiFile = state.getInjector().getClosureAnnotator().isMultiFileNamespace(name);
|
||||
|
||||
for (JetFile file : files) {
|
||||
VirtualFile vFile = file.getVirtualFile();
|
||||
@@ -165,7 +152,9 @@ public class NamespaceCodegen {
|
||||
|
||||
if (k > 0) {
|
||||
PsiFile containingFile = file.getContainingFile();
|
||||
String className = name.child(Name.identifier("namespace$src$" + (nextMultiFile++))).getFqName().replace('.','/');
|
||||
String fname = containingFile.getName();
|
||||
fname = fname.substring(0,fname.lastIndexOf('.'));
|
||||
String className = name.child(Name.identifier("namespace$src$" + fname)).getFqName().replace('.','/');
|
||||
ClassBuilder builder = state.forNamespacepart(className, file);
|
||||
|
||||
builder.defineClass(containingFile, V1_6,
|
||||
|
||||
@@ -19,13 +19,20 @@
|
||||
*/
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.UserDataHolder;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class JetFilesProvider {
|
||||
@@ -33,6 +40,37 @@ public abstract class JetFilesProvider {
|
||||
return ServiceManager.getService(project, JetFilesProvider.class);
|
||||
}
|
||||
|
||||
public final Function<JetFile, List<JetFile>> allNamespaceFiles() {
|
||||
return new Function<JetFile, List<JetFile>>() {
|
||||
@Override
|
||||
public List<JetFile> fun(JetFile file) {
|
||||
return new SameJetFilePredicate(file).filter(sampleToAllFilesInModule().fun(file));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public abstract Function<JetFile, Collection<JetFile>> sampleToAllFilesInModule();
|
||||
public abstract List<JetFile> allInScope(GlobalSearchScope scope);
|
||||
|
||||
public static class SameJetFilePredicate implements Predicate<PsiFile> {
|
||||
private final FqName name;
|
||||
|
||||
public SameJetFilePredicate(JetFile file) {
|
||||
this.name = JetPsiUtil.getFQName(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(PsiFile psiFile) {
|
||||
return JetPsiUtil.getFQName((JetFile) psiFile).equals(name);
|
||||
}
|
||||
|
||||
public List<JetFile> filter(Collection<JetFile> allFiles) {
|
||||
LinkedList<JetFile> files = new LinkedList<JetFile>();
|
||||
for (JetFile aFile : allFiles) {
|
||||
if(apply(aFile))
|
||||
files.add(aFile);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ import java.util.List;
|
||||
*/
|
||||
public class AnalyzerFacadeForEverything {
|
||||
|
||||
private AnalyzerFacadeForEverything() {
|
||||
}
|
||||
|
||||
public static AnalyzeExhaust analyzeBodiesInFilesWithJavaIntegration(
|
||||
Project project, List<AnalyzerScriptParameter> scriptParameters, Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||
@NotNull BindingTrace traceContext,
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.ref.JetTypeName;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -93,6 +94,8 @@ public class CodegenTestFiles {
|
||||
for (String name : names) {
|
||||
try {
|
||||
String content = JetTestUtils.doLoadFile(JetParsingTest.getTestDataDir() + "/codegen/", name);
|
||||
int i = name.lastIndexOf(File.separatorChar);
|
||||
name = name.substring(i+1);
|
||||
JetFile file = (JetFile) JetTestUtils.createFile(name, content, project);
|
||||
files.add(file);
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user