working field read; non-working field write
This commit is contained in:
@@ -276,15 +276,16 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
PsiElement declaration = bindingContext.getDeclarationPsiElement(descriptor);
|
PsiElement declaration = bindingContext.getDeclarationPsiElement(descriptor);
|
||||||
if (declaration instanceof PsiField) {
|
if (declaration instanceof PsiField) {
|
||||||
PsiField psiField = (PsiField) declaration;
|
PsiField psiField = (PsiField) declaration;
|
||||||
|
final String owner = JetTypeMapper.jvmName(psiField.getContainingClass());
|
||||||
|
final Type fieldType = psiTypeToAsm(psiField.getType());
|
||||||
if (psiField.hasModifierProperty(PsiModifier.STATIC)) {
|
if (psiField.hasModifierProperty(PsiModifier.STATIC)) {
|
||||||
v.visitFieldInsn(Opcodes.GETSTATIC,
|
v.visitFieldInsn(Opcodes.GETSTATIC, owner, psiField.getName(), fieldType.getDescriptor());
|
||||||
JetTypeMapper.jvmName(psiField.getContainingClass()),
|
|
||||||
psiField.getName(),
|
|
||||||
psiTypeToAsm(psiField.getType()).getDescriptor());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException("don't know how to generate field reference " + descriptor);
|
ensureReceiverOnStack(expression);
|
||||||
|
v.visitFieldInsn(Opcodes.GETFIELD, owner, psiField.getName(), fieldType.getDescriptor());
|
||||||
}
|
}
|
||||||
|
myStack.push(StackValue.onStack(fieldType));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int index = myMap.getIndex(descriptor);
|
int index = myMap.getIndex(descriptor);
|
||||||
@@ -342,13 +343,7 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expression.getParent() instanceof JetDotQualifiedExpression) {
|
ensureReceiverOnStack(expression);
|
||||||
final JetDotQualifiedExpression parent = (JetDotQualifiedExpression) expression.getParent();
|
|
||||||
if (!resolvesToClassOrPackage(parent.getReceiverExpression())) {
|
|
||||||
// we have a receiver on stack
|
|
||||||
myStack.pop().put(Type.getObjectType(CLASS_OBJECT), v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PsiElement declarationPsiElement = bindingContext.getDeclarationPsiElement(funDescriptor);
|
PsiElement declarationPsiElement = bindingContext.getDeclarationPsiElement(funDescriptor);
|
||||||
Method methodDescriptor;
|
Method methodDescriptor;
|
||||||
@@ -387,6 +382,16 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ensureReceiverOnStack(JetElement expression) {
|
||||||
|
if (expression.getParent() instanceof JetDotQualifiedExpression) {
|
||||||
|
final JetDotQualifiedExpression parent = (JetDotQualifiedExpression) expression.getParent();
|
||||||
|
if (!resolvesToClassOrPackage(parent.getReceiverExpression())) {
|
||||||
|
// we have a receiver on stack
|
||||||
|
myStack.pop().put(Type.getObjectType(CLASS_OBJECT), v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void pushMethodArguments(JetCall expression, Method method) {
|
private void pushMethodArguments(JetCall expression, Method method) {
|
||||||
final Type[] argTypes = method.getArgumentTypes();
|
final Type[] argTypes = method.getArgumentTypes();
|
||||||
List<JetArgument> args = expression.getValueArguments();
|
List<JetArgument> args = expression.getValueArguments();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.codegen;
|
|||||||
|
|
||||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -272,4 +273,21 @@ public class NamespaceGenTest extends CodegenTestCase {
|
|||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
ArrayList arrayList = (ArrayList) main.invoke(null);
|
ArrayList arrayList = (ArrayList) main.invoke(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testFieldRead() throws Exception {
|
||||||
|
loadText("import java.awt.*; fun foo(c: GridBagConstraints) = c.gridx");
|
||||||
|
System.out.println(generateToText());
|
||||||
|
final Method main = generateFunction();
|
||||||
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
|
c.gridx = 239;
|
||||||
|
assertEquals(239, main.invoke(null, c));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testFieldWrite() throws Exception {
|
||||||
|
loadText("import java.awt.*; fun foo(c: GridBagConstraints) { c.gridx = 239 }");
|
||||||
|
final Method main = generateFunction();
|
||||||
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
|
main.invoke(null, c);
|
||||||
|
assertEquals(239, c.gridx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user