private boolean shouldInitializeProperty(@NotNull JetProperty property) { JetExpression initializer = property.getDelegateExpressionOrInitializer(); if (initializer == null) return false; PropertyDescriptor propertyDescriptor = (PropertyDescriptor) bindingContext.get(VARIABLE, property); assert propertyDescriptor != null; CompileTimeConstant<?> compileTimeValue = propertyDescriptor.getCompileTimeInitializer(); if (compileTimeValue == null) return true; // TODO: OPTIMIZATION: don't initialize static final fields Object value = compileTimeValue.getValue(); JetType jetType = getPropertyOrDelegateType(property, propertyDescriptor); Type type = typeMapper.mapType(jetType); return !skipDefaultValue(propertyDescriptor, value, type); }
@Nullable private static String getMessageFromAnnotationDescriptor( @NotNull AnnotationDescriptor descriptor) { ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(descriptor.getType()); if (classDescriptor != null) { ValueParameterDescriptor parameter = DescriptorResolverUtils.getAnnotationParameterByName( DEFAULT_ANNOTATION_MEMBER_NAME, classDescriptor); if (parameter != null) { CompileTimeConstant<?> valueArgument = descriptor.getValueArgument(parameter); if (valueArgument != null) { Object value = valueArgument.getValue(); if (value instanceof String) { return String.valueOf(value); } } } } return null; }
private void generateBackingField(JetProperty p, PropertyDescriptor propertyDescriptor) { if (state.getBindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor)) { DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration(); if (CodegenUtil.isInterface(containingDeclaration)) return; Object value = null; final JetExpression initializer = p.getInitializer(); if (initializer != null) { if (initializer instanceof JetConstantExpression) { CompileTimeConstant<?> compileTimeValue = state.getBindingContext().get(BindingContext.COMPILE_TIME_VALUE, initializer); value = compileTimeValue != null ? compileTimeValue.getValue() : null; } } int modifiers; if (kind == OwnerKind.NAMESPACE) { int access = JetTypeMapper.getAccessModifiers(propertyDescriptor, 0); modifiers = access | Opcodes.ACC_STATIC; } else { modifiers = JetTypeMapper.getAccessModifiers(propertyDescriptor, 0); } if (!propertyDescriptor.isVar()) { modifiers |= Opcodes.ACC_FINAL; } if (state.getInjector().getJetStandardLibrary().isVolatile(propertyDescriptor)) { modifiers |= Opcodes.ACC_VOLATILE; } Type type = state .getInjector() .getJetTypeMapper() .mapType(propertyDescriptor.getType(), MapTypeMode.VALUE); FieldVisitor fieldVisitor = v.newField(p, modifiers, p.getName(), type.getDescriptor(), null, value); AnnotationCodegen.forField(fieldVisitor, state.getInjector().getJetTypeMapper()) .genAnnotations(propertyDescriptor); } }