Search in sources :

Example 1 with KtQualifiedExpression

use of org.jetbrains.kotlin.psi.KtQualifiedExpression in project kotlin by JetBrains.

the class KotlinExpressionSurrounder method isApplicable.

@Override
public boolean isApplicable(@NotNull PsiElement[] elements) {
    if (elements.length != 1 || !(elements[0] instanceof KtExpression)) {
        return false;
    }
    KtExpression expression = (KtExpression) elements[0];
    if (expression instanceof KtCallExpression && expression.getParent() instanceof KtQualifiedExpression) {
        return false;
    }
    KotlinType type = ResolutionUtils.analyze(expression, BodyResolveMode.PARTIAL).getType(expression);
    if (type == null || isUnit(type)) {
        return false;
    }
    return isApplicable(expression);
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType) KtExpression(org.jetbrains.kotlin.psi.KtExpression) KtCallExpression(org.jetbrains.kotlin.psi.KtCallExpression) KtQualifiedExpression(org.jetbrains.kotlin.psi.KtQualifiedExpression)

Example 2 with KtQualifiedExpression

use of org.jetbrains.kotlin.psi.KtQualifiedExpression in project kotlin by JetBrains.

the class ReferenceTranslator method canBePropertyAccess.

public static boolean canBePropertyAccess(@NotNull KtExpression expression, @NotNull TranslationContext context) {
    KtSimpleNameExpression simpleNameExpression = null;
    if (expression instanceof KtQualifiedExpression) {
        simpleNameExpression = getSelectorAsSimpleName((KtQualifiedExpression) expression);
    } else if (expression instanceof KtSimpleNameExpression) {
        simpleNameExpression = (KtSimpleNameExpression) expression;
    }
    if (simpleNameExpression == null)
        return false;
    DeclarationDescriptor descriptor = getDescriptorForReferenceExpression(context.bindingContext(), simpleNameExpression);
    // Skip ValueParameterDescriptor because sometime we can miss resolved call for it, e.g. when set something to delegated property.
    return descriptor instanceof VariableDescriptor && !(descriptor instanceof ValueParameterDescriptor);
}
Also used : KtSimpleNameExpression(org.jetbrains.kotlin.psi.KtSimpleNameExpression) KtQualifiedExpression(org.jetbrains.kotlin.psi.KtQualifiedExpression)

Aggregations

KtQualifiedExpression (org.jetbrains.kotlin.psi.KtQualifiedExpression)2 KtCallExpression (org.jetbrains.kotlin.psi.KtCallExpression)1 KtExpression (org.jetbrains.kotlin.psi.KtExpression)1 KtSimpleNameExpression (org.jetbrains.kotlin.psi.KtSimpleNameExpression)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1