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);
}
}
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()]);
}
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);
}
Aggregations