Always generate getter and setter

This commit is contained in:
Mikhael Bogdanov
2013-03-18 12:47:48 +04:00
parent 83a717bafe
commit 93b860e4ad
4 changed files with 20 additions and 17 deletions
@@ -120,7 +120,8 @@ public class PropertyCodegen extends GenerationStateAware {
}
private void generateGetter(JetNamedDeclaration p, PropertyDescriptor propertyDescriptor, JetPropertyAccessor getter) {
if (getter != null && getter.getBodyExpression() != null || isExternallyAccessible(propertyDescriptor)) {
//TODO: Now it's not enough information to properly resolve property from bytecode without generated getter and setter
//if (getter != null && getter.getBodyExpression() != null || isExternallyAccessible(propertyDescriptor)) {
JvmPropertyAccessorSignature signature = typeMapper.mapGetterSignature(propertyDescriptor, kind);
PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter();
getterDescriptor = getterDescriptor != null ? getterDescriptor : DescriptorResolver.createDefaultGetter(propertyDescriptor);
@@ -129,12 +130,13 @@ public class PropertyCodegen extends GenerationStateAware {
true,
signature.getPropertyTypeKotlinSignature(),
getterDescriptor);
}
//}
}
private void generateSetter(JetNamedDeclaration p, PropertyDescriptor propertyDescriptor, JetPropertyAccessor setter) {
if (setter != null && setter.getBodyExpression() != null
|| isExternallyAccessible(propertyDescriptor) && propertyDescriptor.isVar()) {
//TODO: Now it's not enough information to properly resolve property from bytecode without generated getter and setter
if (/*setter != null && setter.getBodyExpression() != null
|| isExternallyAccessible(propertyDescriptor) &&*/ propertyDescriptor.isVar()) {
JvmPropertyAccessorSignature signature = typeMapper.mapSetterSignature(propertyDescriptor, kind);
PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter();
setterDescriptor = setterDescriptor != null ? setterDescriptor : DescriptorResolver.createDefaultSetter(propertyDescriptor);
@@ -155,7 +157,7 @@ public class PropertyCodegen extends GenerationStateAware {
@NotNull CodegenContext context) {
PropertyDescriptor propertyDescriptor = accessorDescriptor.getCorrespondingProperty();
final Type type = typeMapper.mapType(propertyDescriptor);
Type type = typeMapper.mapType(propertyDescriptor);
if (accessorDescriptor instanceof PropertyGetterDescriptor) {
if (kind != OwnerKind.NAMESPACE) {
iv.load(0, OBJECT_TYPE);
@@ -166,7 +168,8 @@ public class PropertyCodegen extends GenerationStateAware {
propertyDescriptor.getName().getName(),
type.getDescriptor());
iv.areturn(type);
} else if (accessorDescriptor instanceof PropertySetterDescriptor) {
}
else if (accessorDescriptor instanceof PropertySetterDescriptor) {
int paramCode = 0;
if (kind != OwnerKind.NAMESPACE) {
iv.load(0, OBJECT_TYPE);
@@ -184,7 +187,7 @@ public class PropertyCodegen extends GenerationStateAware {
iv.visitInsn(RETURN);
} else {
assert false;
assert false : "Unreachable state";
}
}
@@ -13,10 +13,10 @@ trait MooableTextField : InputTextField {
}
class SimpleTextField : MooableTextField {
private var text = ""
override fun getText() = text
private var text2 = ""
override fun getText() = text2
override fun setText(text: String) {
this.text = text
this.text2 = text
}
override fun moo(a: Int, b: Int, c: Int) = a + b + c
}
@@ -4,10 +4,10 @@ trait TextField {
}
class SimpleTextField : TextField {
private var text = ""
override fun getText() = text
private var text2 = ""
override fun getText() = text2
override fun setText(text: String) {
this.text = text
this.text2 = text
}
}
@@ -19,7 +19,7 @@ object State {
*/
public abstract class AbstractIterator<T>: Iterator<T> {
private var state = State.NotReady
private var next: T? = null
private var nextValue: T? = null
override fun hasNext(): Boolean {
require(state != State.Failed)
@@ -33,13 +33,13 @@ public abstract class AbstractIterator<T>: Iterator<T> {
override fun next(): T {
if (!hasNext()) throw NoSuchElementException()
state = State.NotReady
return next as T
return nextValue as T
}
/** Returns the next element in the iteration without advancing the iteration */
fun peek(): T {
if (!hasNext()) throw NoSuchElementException()
return next as T;
return nextValue as T;
}
private fun tryToComputeNext(): Boolean {
@@ -64,7 +64,7 @@ public abstract class AbstractIterator<T>: Iterator<T> {
* Sets the next value in the iteration, called from the [[computeNext()]] function
*/
protected fun setNext(value: T): Unit {
next = value
nextValue = value
state = State.Ready
}