namespace property initializers are written directly to backing fields

This commit is contained in:
Dmitry Jemerov
2011-07-12 13:33:33 +02:00
parent 8b823d83ef
commit b95219913a
3 changed files with 6 additions and 6 deletions
@@ -49,7 +49,7 @@ public class ClassFileFactory {
String fqName = namespace.getFQName(); String fqName = namespace.getFQName();
NamespaceCodegen codegen = ns2codegen.get(fqName); NamespaceCodegen codegen = ns2codegen.get(fqName);
if (codegen == null) { if (codegen == null) {
codegen = new NamespaceCodegen(project, newVisitor(NamespaceCodegen.getJVMClassName(fqName) + ".class"), fqName, state); codegen = new NamespaceCodegen(newVisitor(NamespaceCodegen.getJVMClassName(fqName) + ".class"), fqName, state);
ns2codegen.put(fqName, codegen); ns2codegen.put(fqName, codegen);
} }
@@ -1,6 +1,5 @@
package org.jetbrains.jet.codegen; package org.jetbrains.jet.codegen;
import com.intellij.openapi.project.Project;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassVisitor;
@@ -13,12 +12,10 @@ import org.objectweb.asm.commons.InstructionAdapter;
* @author max * @author max
*/ */
public class NamespaceCodegen { public class NamespaceCodegen {
private final Project project;
private final ClassVisitor v; private final ClassVisitor v;
private final GenerationState state; private final GenerationState state;
public NamespaceCodegen(Project project, ClassVisitor v, String fqName, GenerationState state) { public NamespaceCodegen(ClassVisitor v, String fqName, GenerationState state) {
this.project = project;
this.v = v; this.v = v;
this.state = state; this.state = state;
@@ -80,7 +77,7 @@ public class NamespaceCodegen {
if (initializer != null && !(initializer instanceof JetConstantExpression)) { if (initializer != null && !(initializer instanceof JetConstantExpression)) {
final PropertyDescriptor descriptor = (PropertyDescriptor) state.getBindingContext().getVariableDescriptor((JetProperty) declaration); final PropertyDescriptor descriptor = (PropertyDescriptor) state.getBindingContext().getVariableDescriptor((JetProperty) declaration);
codegen.genToJVMStack(initializer); codegen.genToJVMStack(initializer);
codegen.intermediateValueForProperty(descriptor, false, false).store(new InstructionAdapter(mv)); codegen.intermediateValueForProperty(descriptor, true, false).store(new InstructionAdapter(mv));
} }
} }
} }
@@ -80,6 +80,9 @@ public class PropertyGenTest extends CodegenTestCase {
final Method method = generateFunction("append"); final Method method = generateFunction("append");
method.invoke(null, "IntelliJ "); method.invoke(null, "IntelliJ ");
String value = (String) method.invoke(null, "IDEA"); String value = (String) method.invoke(null, "IDEA");
if (!value.equals("IntelliJ IDEA")) {
System.out.println(generateToText());
}
assertEquals("IntelliJ IDEA", value); assertEquals("IntelliJ IDEA", value);
} }