Got rid of adding constant on each call site.

This commit is contained in:
Evgeny Gerashchenko
2013-03-22 19:29:06 +04:00
parent d5031e60ad
commit 288dbe70c6
4 changed files with 10 additions and 17 deletions
@@ -51,8 +51,8 @@ public final class ClassFileFactory extends GenerationStateAware {
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
} }
ClassBuilder newVisitor(String outputFilePath, PsiFile sourceFile) { ClassBuilder newVisitor(String internalClassName, PsiFile sourceFile) {
return newVisitor(outputFilePath, Collections.singletonList(sourceFile)); return newVisitor(internalClassName + ".class", Collections.singletonList(sourceFile));
} }
private ClassBuilder newVisitor(String outputFilePath, Collection<? extends PsiFile> sourceFiles) { private ClassBuilder newVisitor(String outputFilePath, Collection<? extends PsiFile> sourceFiles) {
@@ -126,16 +126,16 @@ public final class ClassFileFactory extends GenerationStateAware {
if (isPrimitive(type)) { if (isPrimitive(type)) {
throw new IllegalStateException("Codegen for primitive type is not possible: " + aClass); throw new IllegalStateException("Codegen for primitive type is not possible: " + aClass);
} }
return newVisitor(type.getInternalName() + ".class", sourceFile); return newVisitor(type.getInternalName(), sourceFile);
} }
public ClassBuilder forNamespacepart(String internalName, PsiFile sourceFile) { public ClassBuilder forNamespacepart(String internalName, PsiFile sourceFile) {
return newVisitor(internalName + ".class", sourceFile); return newVisitor(internalName, sourceFile);
} }
public ClassBuilder forTraitImplementation(ClassDescriptor aClass, GenerationState state, PsiFile sourceFile) { public ClassBuilder forTraitImplementation(ClassDescriptor aClass, GenerationState state, PsiFile sourceFile) {
return newVisitor( return newVisitor(
state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL).getInternalName() + ".class", state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL).getInternalName(),
sourceFile); sourceFile);
} }
@@ -70,7 +70,7 @@ public class ClosureCodegen extends GenerationStateAware {
public ClosureCodegen gen(JetDeclarationWithBody fun, CodegenContext context, ExpressionCodegen expressionCodegen) { public ClosureCodegen gen(JetDeclarationWithBody fun, CodegenContext context, ExpressionCodegen expressionCodegen) {
name = classNameForAnonymousClass(state.getBindingContext(), fun); name = classNameForAnonymousClass(state.getBindingContext(), fun);
ClassBuilder cv = state.getFactory().newVisitor(name.getInternalName() + ".class", fun.getContainingFile()); ClassBuilder cv = state.getFactory().newVisitor(name.getInternalName(), fun.getContainingFile());
FunctionDescriptor funDescriptor = bindingContext.get(BindingContext.FUNCTION, fun); FunctionDescriptor funDescriptor = bindingContext.get(BindingContext.FUNCTION, fun);
assert funDescriptor != null; assert funDescriptor != null;
@@ -109,11 +109,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
) { ) {
JetObjectDeclaration objectDeclaration = literal.getObjectDeclaration(); JetObjectDeclaration objectDeclaration = literal.getObjectDeclaration();
JvmClassName className = JvmClassName className = classNameForAnonymousClass(bindingContext, objectDeclaration);
classNameForAnonymousClass(bindingContext, objectDeclaration); ClassBuilder classBuilder = state.getFactory().newVisitor(className.getInternalName(), literal.getContainingFile());
ClassBuilder classBuilder = state.getFactory().newVisitor(
className.getInternalName() + ".class",
literal.getContainingFile());
ClassDescriptor classDescriptor = bindingContext.get(CLASS, objectDeclaration); ClassDescriptor classDescriptor = bindingContext.get(CLASS, objectDeclaration);
assert classDescriptor != null; assert classDescriptor != null;
@@ -278,9 +275,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
JvmClassName className = JvmClassName className =
classNameForAnonymousClass(bindingContext, declaration); classNameForAnonymousClass(bindingContext, declaration);
ClassBuilder classBuilder = state.getFactory().newVisitor( ClassBuilder classBuilder = state.getFactory().newVisitor(className.getInternalName(), declaration.getContainingFile()
className.getInternalName() + ".class",
declaration.getContainingFile()
); );
CodegenContext objectContext = context.intoAnonymousClass(descriptor, this); CodegenContext objectContext = context.intoAnonymousClass(descriptor, this);
@@ -75,9 +75,7 @@ public class ScriptCodegen extends MemberCodegen {
JvmClassName className = bindingContext.get(FQN, classDescriptorForScript); JvmClassName className = bindingContext.get(FQN, classDescriptorForScript);
assert className != null; assert className != null;
ClassBuilder classBuilder = classFileFactory.newVisitor( ClassBuilder classBuilder = classFileFactory.newVisitor(className.getInternalName(), scriptDeclaration.getContainingFile()
className.getInternalName() + ".class",
scriptDeclaration.getContainingFile()
); );
classBuilder.defineClass(scriptDeclaration, classBuilder.defineClass(scriptDeclaration,
V1_6, V1_6,