Search in sources :

Example 1 with KtSimpleNameExpression

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

the class TailRecursionCodegen method assignParameterValues.

private void assignParameterValues(CallableDescriptor fd, CallableMethod callableMethod, List<ResolvedValueArgument> valueArguments) {
    List<Type> types = callableMethod.getValueParameterTypes();
    for (ValueParameterDescriptor parameterDescriptor : Lists.reverse(fd.getValueParameters())) {
        ResolvedValueArgument arg = valueArguments.get(parameterDescriptor.getIndex());
        Type type = types.get(parameterDescriptor.getIndex());
        if (arg instanceof ExpressionValueArgument) {
            ExpressionValueArgument ev = (ExpressionValueArgument) arg;
            ValueArgument argument = ev.getValueArgument();
            KtExpression argumentExpression = argument == null ? null : argument.getArgumentExpression();
            if (argumentExpression instanceof KtSimpleNameExpression) {
                ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(argumentExpression, state.getBindingContext());
                if (resolvedCall != null && resolvedCall.getResultingDescriptor().equals(parameterDescriptor.getOriginal())) {
                    // do nothing: we shouldn't store argument to itself again
                    AsmUtil.pop(v, type);
                    continue;
                }
            }
        //assign the parameter below
        } else if (arg instanceof DefaultValueArgument) {
            AsmUtil.pop(v, type);
            DefaultParameterValueLoader.DEFAULT.genValue(parameterDescriptor, codegen).put(type, v);
        } else if (arg instanceof VarargValueArgument) {
        // assign the parameter below
        } else {
            throw new UnsupportedOperationException("Unknown argument type: " + arg + " in " + fd);
        }
        store(parameterDescriptor, type);
    }
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) ValueArgument(org.jetbrains.kotlin.psi.ValueArgument) KtExpression(org.jetbrains.kotlin.psi.KtExpression) KtSimpleNameExpression(org.jetbrains.kotlin.psi.KtSimpleNameExpression) ValueParameterDescriptor(org.jetbrains.kotlin.descriptors.ValueParameterDescriptor)

Example 2 with KtSimpleNameExpression

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

the class KotlinAndroidGotoDeclarationHandler method getGotoDeclarationTargets.

@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement sourceElement, int offset, Editor editor) {
    KtSimpleNameExpression referenceExpression = GotoResourceHelperKt.getReferenceExpression(sourceElement);
    if (referenceExpression == null) {
        return null;
    }
    AndroidFacet facet = AndroidUtilKt.getAndroidFacetForFile(referenceExpression);
    if (facet == null) {
        return null;
    }
    AndroidResourceUtil.MyReferredResourceFieldInfo info = GotoResourceHelperKt.getInfo(referenceExpression, facet);
    if (info == null)
        return null;
    String nestedClassName = info.getClassName();
    String fieldName = info.getFieldName();
    List<PsiElement> resourceList = new ArrayList<PsiElement>();
    if (info.isFromManifest()) {
        collectManifestElements(nestedClassName, fieldName, facet, resourceList);
    } else {
        ResourceManager manager = info.isSystem() ? facet.getSystemResourceManager(false) : facet.getLocalResourceManager();
        if (manager == null) {
            return null;
        }
        manager.collectLazyResourceElements(nestedClassName, fieldName, false, referenceExpression, resourceList);
        if (manager instanceof LocalResourceManager) {
            LocalResourceManager lrm = (LocalResourceManager) manager;
            if (nestedClassName.equals(ResourceType.ATTR.getName())) {
                for (Attr attr : lrm.findAttrs(fieldName)) {
                    resourceList.add(attr.getName().getXmlAttributeValue());
                }
            } else if (nestedClassName.equals(ResourceType.STYLEABLE.getName())) {
                for (DeclareStyleable styleable : lrm.findStyleables(fieldName)) {
                    resourceList.add(styleable.getName().getXmlAttributeValue());
                }
                for (Attr styleable : lrm.findStyleableAttributesByFieldName(fieldName)) {
                    resourceList.add(styleable.getName().getXmlAttributeValue());
                }
            }
        }
    }
    if (resourceList.size() > 1) {
        // Sort to ensure the output is stable, and to prefer the base folders
        Collections.sort(resourceList, AndroidResourceUtil.RESOURCE_ELEMENT_COMPARATOR);
    }
    return resourceList.toArray(new PsiElement[resourceList.size()]);
}
Also used : AndroidResourceUtil(org.jetbrains.android.util.AndroidResourceUtil) LocalResourceManager(org.jetbrains.android.resourceManagers.LocalResourceManager) ArrayList(java.util.ArrayList) KtSimpleNameExpression(org.jetbrains.kotlin.psi.KtSimpleNameExpression) ResourceManager(org.jetbrains.android.resourceManagers.ResourceManager) LocalResourceManager(org.jetbrains.android.resourceManagers.LocalResourceManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) PsiElement(com.intellij.psi.PsiElement) Attr(org.jetbrains.android.dom.resources.Attr) DeclareStyleable(org.jetbrains.android.dom.resources.DeclareStyleable)

Example 3 with KtSimpleNameExpression

use of org.jetbrains.kotlin.psi.KtSimpleNameExpression 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

KtSimpleNameExpression (org.jetbrains.kotlin.psi.KtSimpleNameExpression)3 PsiElement (com.intellij.psi.PsiElement)1 ArrayList (java.util.ArrayList)1 Attr (org.jetbrains.android.dom.resources.Attr)1 DeclareStyleable (org.jetbrains.android.dom.resources.DeclareStyleable)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 LocalResourceManager (org.jetbrains.android.resourceManagers.LocalResourceManager)1 ResourceManager (org.jetbrains.android.resourceManagers.ResourceManager)1 AndroidResourceUtil (org.jetbrains.android.util.AndroidResourceUtil)1 ValueParameterDescriptor (org.jetbrains.kotlin.descriptors.ValueParameterDescriptor)1 KtExpression (org.jetbrains.kotlin.psi.KtExpression)1 KtQualifiedExpression (org.jetbrains.kotlin.psi.KtQualifiedExpression)1 ValueArgument (org.jetbrains.kotlin.psi.ValueArgument)1 Type (org.jetbrains.org.objectweb.asm.Type)1