Extract method

This commit is contained in:
Natalia.Ukhorskaya
2013-07-25 16:47:06 +04:00
parent c11bd7104c
commit 6d1e46bae0
2 changed files with 15 additions and 11 deletions
@@ -135,17 +135,7 @@ public abstract class ClassBodyCodegen extends MemberCodegen {
propertyCodegen.generatePrimaryConstructorProperty(p, propertyDescriptor);
}
else {
Type type = state.getTypeMapper().mapType(propertyDescriptor);
MethodVisitor visitor =
v.newMethod(p, ACC_PUBLIC | ACC_ABSTRACT, p.getName(), "()" + type.getDescriptor(), null, null);
JetExpression defaultValue = p.getDefaultValue();
if (defaultValue != null) {
CompileTimeConstant<?> constant =
state.getBindingContext().get(BindingContext.COMPILE_TIME_VALUE, defaultValue);
assert constant != null : "Default value for annotation parameter should be compile time value: " + defaultValue.getText();
AnnotationCodegen annotationCodegen = AnnotationCodegen.forAnnotationDefaultValue(visitor, typeMapper);
annotationCodegen.generateAnnotationDefaultValue(constant);
}
propertyCodegen.generateConstructorPropertyAsMethodForAnnotationClass(p, propertyDescriptor);
}
}
}
@@ -104,6 +104,20 @@ public class PropertyCodegen extends GenerationStateAware {
}
}
public void generateConstructorPropertyAsMethodForAnnotationClass(JetParameter p, PropertyDescriptor descriptor) {
Type type = state.getTypeMapper().mapType(descriptor);
MethodVisitor visitor =
v.newMethod(p, ACC_PUBLIC | ACC_ABSTRACT, p.getName(), "()" + type.getDescriptor(), null, null);
JetExpression defaultValue = p.getDefaultValue();
if (defaultValue != null) {
CompileTimeConstant<?> constant =
state.getBindingContext().get(BindingContext.COMPILE_TIME_VALUE, defaultValue);
assert constant != null : "Default value for annotation parameter should be compile time value: " + defaultValue.getText();
AnnotationCodegen annotationCodegen = AnnotationCodegen.forAnnotationDefaultValue(visitor, typeMapper);
annotationCodegen.generateAnnotationDefaultValue(constant);
}
}
private void generateBackingField(JetNamedDeclaration p, PropertyDescriptor propertyDescriptor) {
//noinspection ConstantConditions
boolean hasBackingField = bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor);