Search in sources :

Example 1 with LocalVariableDescriptor

use of org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor in project kotlin by JetBrains.

the class CodegenAnnotatingVisitor method recordLocalVariablePropertyMetadata.

private void recordLocalVariablePropertyMetadata(LocalVariableDescriptor variableDescriptor) {
    KotlinType delegateType = JvmCodegenUtil.getPropertyDelegateType(variableDescriptor, bindingContext);
    if (delegateType == null)
        return;
    LocalVariableDescriptor delegateVariableDescriptor = new LocalVariableDescriptor(variableDescriptor.getContainingDeclaration(), Annotations.Companion.getEMPTY(), variableDescriptor.getName(), delegateType, false, false, SourceElement.NO_SOURCE);
    bindingTrace.record(LOCAL_VARIABLE_DELEGATE, variableDescriptor, delegateVariableDescriptor);
    LocalVariableDescriptor metadataVariableDescriptor = new LocalVariableDescriptor(variableDescriptor.getContainingDeclaration(), Annotations.Companion.getEMPTY(), Name.identifier(variableDescriptor.getName().asString() + "$metadata"), ReflectionTypes.Companion.createKPropertyStarType(DescriptorUtilsKt.getModule(variableDescriptor)), false, false, SourceElement.NO_SOURCE);
    bindingTrace.record(LOCAL_VARIABLE_PROPERTY_METADATA, variableDescriptor, metadataVariableDescriptor);
}
Also used : LocalVariableDescriptor(org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Example 2 with LocalVariableDescriptor

use of org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor in project kotlin by JetBrains.

the class CodegenAnnotatingVisitor method visitProperty.

@Override
public void visitProperty(@NotNull KtProperty property) {
    DeclarationDescriptor descriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, property);
    // working around a problem with shallow analysis
    if (descriptor == null)
        return;
    if (descriptor instanceof LocalVariableDescriptor) {
        recordLocalVariablePropertyMetadata((LocalVariableDescriptor) descriptor);
    }
    String nameForClassOrPackageMember = getNameForClassOrPackageMember(descriptor);
    if (nameForClassOrPackageMember != null) {
        nameStack.push(nameForClassOrPackageMember);
    } else {
        nameStack.push(peekFromStack(nameStack) + '$' + safeIdentifier(property.getNameAsSafeName()).asString());
    }
    KtPropertyDelegate delegate = property.getDelegate();
    if (delegate != null && descriptor instanceof VariableDescriptorWithAccessors) {
        VariableDescriptorWithAccessors variableDescriptor = (VariableDescriptorWithAccessors) descriptor;
        String name = inventAnonymousClassName();
        KotlinType supertype = runtimeTypes.getSupertypeForPropertyReference(variableDescriptor, variableDescriptor.isVar(), /* bound = */
        false);
        ClassDescriptor classDescriptor = recordClassForCallable(delegate, variableDescriptor, Collections.singleton(supertype), name);
        recordClosure(classDescriptor, name);
    }
    super.visitProperty(property);
    nameStack.pop();
}
Also used : LocalVariableDescriptor(org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Example 3 with LocalVariableDescriptor

use of org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor in project kotlin by JetBrains.

the class ExpressionCodegen method initializeLocalVariable.

private void initializeLocalVariable(@NotNull KtVariableDeclaration variableDeclaration, @NotNull StackValue initializer) {
    LocalVariableDescriptor variableDescriptor = (LocalVariableDescriptor) getVariableDescriptorNotNull(variableDeclaration);
    if (KtPsiUtil.isScriptDeclaration(variableDeclaration)) {
        return;
    }
    int index = lookupLocalIndex(variableDescriptor);
    if (index < 0) {
        throw new IllegalStateException("Local variable not found for " + variableDescriptor);
    }
    Type sharedVarType = typeMapper.getSharedVarType(variableDescriptor);
    Type varType = getVariableTypeNoSharing(variableDescriptor);
    StackValue storeTo = sharedVarType == null ? StackValue.local(index, varType) : StackValue.shared(index, varType);
    storeTo.putReceiver(v, false);
    initializer.put(initializer.type, v);
    markLineNumber(variableDeclaration, false);
    Type resultType = initializer.type;
    if (isDelegatedLocalVariable(variableDescriptor)) {
        StackValue metadataValue = getVariableMetadataValue(variableDescriptor);
        initializePropertyMetadata((KtProperty) variableDeclaration, variableDescriptor, metadataValue);
        ResolvedCall<FunctionDescriptor> provideDelegateResolvedCall = bindingContext.get(PROVIDE_DELEGATE_RESOLVED_CALL, variableDescriptor);
        if (provideDelegateResolvedCall != null) {
            resultType = generateProvideDelegateCallForLocalVariable(initializer, metadataValue, provideDelegateResolvedCall);
        }
    }
    storeTo.storeSelector(resultType, v);
}
Also used : LocalVariableDescriptor(org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor) IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Aggregations

LocalVariableDescriptor (org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor)3 KotlinType (org.jetbrains.kotlin.types.KotlinType)3 IElementType (com.intellij.psi.tree.IElementType)1 Type (org.jetbrains.org.objectweb.asm.Type)1