Source files made available where "emitting" is reported
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
@@ -51,10 +52,14 @@ public final class ClassFileFactory extends GenerationStateAware {
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
ClassBuilder newVisitor(String filePath) {
|
||||
state.getProgress().log("Emitting: " + filePath);
|
||||
ClassBuilder newVisitor(String outputFilePath, PsiFile sourceFile) {
|
||||
return newVisitor(outputFilePath, Collections.singletonList(sourceFile));
|
||||
}
|
||||
|
||||
ClassBuilder newVisitor(String outputFilePath, Collection<? extends PsiFile> sourceFiles) {
|
||||
state.getProgress().log("Emitting: " + outputFilePath);
|
||||
final ClassBuilder answer = builderFactory.newClassBuilder();
|
||||
generators.put(filePath, answer);
|
||||
generators.put(outputFilePath, answer);
|
||||
return answer;
|
||||
}
|
||||
|
||||
@@ -96,7 +101,7 @@ public final class ClassFileFactory extends GenerationStateAware {
|
||||
return answer.toString();
|
||||
}
|
||||
|
||||
public NamespaceCodegen forNamespace(final FqName fqName, Collection<JetFile> files) {
|
||||
public NamespaceCodegen forNamespace(final FqName fqName, final Collection<JetFile> files) {
|
||||
assert !isDone : "Already done!";
|
||||
NamespaceCodegen codegen = ns2codegen.get(fqName);
|
||||
if (codegen == null) {
|
||||
@@ -104,7 +109,10 @@ public final class ClassFileFactory extends GenerationStateAware {
|
||||
@NotNull
|
||||
@Override
|
||||
protected ClassBuilder createClassBuilder() {
|
||||
return newVisitor(NamespaceCodegen.getJVMClassNameForKotlinNs(fqName).getInternalName() + ".class");
|
||||
return newVisitor(
|
||||
NamespaceCodegen.getJVMClassNameForKotlinNs(fqName).getInternalName() + ".class",
|
||||
files
|
||||
);
|
||||
}
|
||||
};
|
||||
codegen = new NamespaceCodegen(onDemand, fqName, state, files);
|
||||
@@ -114,20 +122,21 @@ public final class ClassFileFactory extends GenerationStateAware {
|
||||
return codegen;
|
||||
}
|
||||
|
||||
public ClassBuilder forClassImplementation(ClassDescriptor aClass) {
|
||||
public ClassBuilder forClassImplementation(ClassDescriptor aClass, PsiFile sourceFile) {
|
||||
Type type = state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.IMPL);
|
||||
if (isPrimitive(type)) {
|
||||
throw new IllegalStateException("Codegen for primitive type is not possible: " + aClass);
|
||||
}
|
||||
return newVisitor(type.getInternalName() + ".class");
|
||||
return newVisitor(type.getInternalName() + ".class", sourceFile);
|
||||
}
|
||||
|
||||
public ClassBuilder forNamespacepart(String name) {
|
||||
return newVisitor(name + ".class");
|
||||
public ClassBuilder forNamespacepart(String internalName, PsiFile sourceFile) {
|
||||
return newVisitor(internalName + ".class", sourceFile);
|
||||
}
|
||||
|
||||
public ClassBuilder forTraitImplementation(ClassDescriptor aClass, GenerationState state) {
|
||||
public ClassBuilder forTraitImplementation(ClassDescriptor aClass, GenerationState state, PsiFile sourceFile) {
|
||||
return newVisitor(
|
||||
state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL).getInternalName() + ".class");
|
||||
state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL).getInternalName() + ".class",
|
||||
sourceFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
||||
assert descriptor != null;
|
||||
|
||||
name = classNameForAnonymousClass(state.getBindingContext(), fun);
|
||||
final ClassBuilder cv = state.getFactory().newVisitor(name.getInternalName() + ".class");
|
||||
final ClassBuilder cv = state.getFactory().newVisitor(name.getInternalName() + ".class", fun.getContainingFile());
|
||||
|
||||
final FunctionDescriptor funDescriptor = bindingContext.get(BindingContext.FUNCTION, fun);
|
||||
|
||||
|
||||
@@ -112,7 +112,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
JvmClassName className =
|
||||
classNameForAnonymousClass(bindingContext, objectDeclaration);
|
||||
ClassBuilder classBuilder = state.getFactory().newVisitor(className.getInternalName() + ".class");
|
||||
ClassBuilder classBuilder = state.getFactory().newVisitor(
|
||||
className.getInternalName() + ".class",
|
||||
literal.getContainingFile());
|
||||
|
||||
final ClassDescriptor classDescriptor = bindingContext.get(CLASS, objectDeclaration);
|
||||
assert classDescriptor != null;
|
||||
@@ -271,7 +273,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
JvmClassName className =
|
||||
classNameForAnonymousClass(bindingContext, declaration);
|
||||
ClassBuilder classBuilder = state.getFactory().newVisitor(className.getInternalName() + ".class");
|
||||
ClassBuilder classBuilder = state.getFactory().newVisitor(
|
||||
className.getInternalName() + ".class",
|
||||
declaration.getContainingFile()
|
||||
);
|
||||
|
||||
final CodegenContext objectContext = context.intoAnonymousClass(descriptor, this);
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public class MemberCodegen extends GenerationStateAware {
|
||||
new ImplementationBodyCodegen(aClass, classContext, classBuilder, state).generate();
|
||||
|
||||
if (aClass instanceof JetClass && ((JetClass) aClass).isTrait()) {
|
||||
ClassBuilder traitBuilder = state.getFactory().forTraitImplementation(descriptor, state);
|
||||
ClassBuilder traitBuilder = state.getFactory().forTraitImplementation(descriptor, state, aClass.getContainingFile());
|
||||
new TraitImplBodyCodegen(aClass, context.intoClass(descriptor, OwnerKind.TRAIT_IMPL, state), traitBuilder, state)
|
||||
.generate();
|
||||
traitBuilder.done();
|
||||
@@ -123,7 +123,7 @@ public class MemberCodegen extends GenerationStateAware {
|
||||
return;
|
||||
}
|
||||
|
||||
ClassBuilder classBuilder = state.getFactory().forClassImplementation(descriptor);
|
||||
ClassBuilder classBuilder = state.getFactory().forClassImplementation(descriptor, aClass.getContainingFile());
|
||||
|
||||
final CodegenContext contextForInners = context.intoClass(descriptor, OwnerKind.IMPLEMENTATION, state);
|
||||
|
||||
|
||||
@@ -153,12 +153,11 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
}
|
||||
|
||||
if (k > 0) {
|
||||
PsiFile containingFile = file.getContainingFile();
|
||||
String namespaceInternalName = JvmClassName.byFqNameWithoutInnerClasses(name.child(Name.identifier(JvmAbi.PACKAGE_CLASS))).getInternalName();
|
||||
String className = getMultiFileNamespaceInternalName(namespaceInternalName, containingFile);
|
||||
ClassBuilder builder = state.getFactory().forNamespacepart(className);
|
||||
String className = getMultiFileNamespaceInternalName(namespaceInternalName, file);
|
||||
ClassBuilder builder = state.getFactory().forNamespacepart(className, file);
|
||||
|
||||
builder.defineClass(containingFile, V1_6,
|
||||
builder.defineClass(file, V1_6,
|
||||
ACC_PUBLIC/*|ACC_SUPER*/,
|
||||
className,
|
||||
null,
|
||||
@@ -166,7 +165,7 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
"java/lang/Object",
|
||||
new String[0]
|
||||
);
|
||||
builder.visitSource(containingFile.getName(), null);
|
||||
builder.visitSource(file.getName(), null);
|
||||
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetNamedFunction) {
|
||||
@@ -310,4 +309,4 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
String namespaceInternalName = namespaceJvmClassName.getInternalName();
|
||||
return NamespaceCodegen.getMultiFileNamespaceInternalName(namespaceInternalName, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,10 @@ public class ScriptCodegen extends MemberCodegen {
|
||||
JvmClassName className = bindingContext.get(FQN, classDescriptorForScript);
|
||||
assert className != null;
|
||||
|
||||
ClassBuilder classBuilder = classFileFactory.newVisitor(className.getInternalName() + ".class");
|
||||
ClassBuilder classBuilder = classFileFactory.newVisitor(
|
||||
className.getInternalName() + ".class",
|
||||
scriptDeclaration.getContainingFile()
|
||||
);
|
||||
classBuilder.defineClass(scriptDeclaration,
|
||||
V1_6,
|
||||
ACC_PUBLIC,
|
||||
|
||||
Reference in New Issue
Block a user