Update UAST to version 1.0.11
This commit is contained in:
@@ -16,10 +16,6 @@
|
||||
|
||||
package com.android.tools.klint.detector.api;
|
||||
|
||||
import static com.android.SdkConstants.CLASS_CONTEXT;
|
||||
import static com.android.tools.klint.client.api.JavaParser.ResolvedNode;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TypeDescriptor;
|
||||
|
||||
import com.android.annotations.NonNull;
|
||||
import com.android.annotations.Nullable;
|
||||
import com.android.tools.klint.client.api.JavaEvaluator;
|
||||
@@ -31,46 +27,19 @@ import com.google.common.collect.Iterators;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiAnonymousClass;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiEnumConstant;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiJavaCodeReferenceElement;
|
||||
import com.intellij.psi.PsiJavaFile;
|
||||
import com.intellij.psi.PsiLabeledStatement;
|
||||
import com.intellij.psi.PsiMember;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiMethodCallExpression;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import com.intellij.psi.PsiNewExpression;
|
||||
import com.intellij.psi.PsiReferenceExpression;
|
||||
import com.intellij.psi.PsiSwitchStatement;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
|
||||
import lombok.ast.*;
|
||||
import lombok.ast.Position;
|
||||
import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.psi.PsiElementBacked;
|
||||
import org.jetbrains.uast.psi.UElementWithLocation;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
|
||||
import lombok.ast.AnnotationElement;
|
||||
import lombok.ast.AnnotationMethodDeclaration;
|
||||
import lombok.ast.ClassDeclaration;
|
||||
import lombok.ast.ConstructorDeclaration;
|
||||
import lombok.ast.ConstructorInvocation;
|
||||
import lombok.ast.EnumConstant;
|
||||
import lombok.ast.Expression;
|
||||
import lombok.ast.LabelledStatement;
|
||||
import lombok.ast.MethodDeclaration;
|
||||
import lombok.ast.MethodInvocation;
|
||||
import lombok.ast.Node;
|
||||
import lombok.ast.Position;
|
||||
import lombok.ast.TypeDeclaration;
|
||||
import lombok.ast.VariableReference;
|
||||
import static com.android.SdkConstants.CLASS_CONTEXT;
|
||||
import static com.android.tools.klint.client.api.JavaParser.ResolvedNode;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TypeDescriptor;
|
||||
|
||||
/**
|
||||
* A {@link Context} used when checking Java files.
|
||||
@@ -252,8 +221,8 @@ public class JavaContext extends Context {
|
||||
UElementWithLocation segment = (UElementWithLocation) node;
|
||||
return Location.create(ioFile, file.getPsi().getText(),
|
||||
segment.getStartOffset(), segment.getEndOffset());
|
||||
} else if (node instanceof PsiElementBacked) {
|
||||
PsiElement psiElement = ((PsiElementBacked) node).getPsi();
|
||||
} else {
|
||||
PsiElement psiElement = node.getPsi();
|
||||
if (psiElement != null) {
|
||||
TextRange range = psiElement.getTextRange();
|
||||
UFile containingFile = getUFile();
|
||||
@@ -478,10 +447,7 @@ public class JavaContext extends Context {
|
||||
}
|
||||
|
||||
public boolean isSuppressedWithComment(@NonNull UElement scope, @NonNull Issue issue) {
|
||||
if (!(scope instanceof PsiElementBacked)) {
|
||||
return false;
|
||||
}
|
||||
PsiElement psi = ((PsiElementBacked) scope).getPsi();
|
||||
PsiElement psi = scope.getPsi();
|
||||
return psi != null && isSuppressedWithComment(psi, issue);
|
||||
|
||||
}
|
||||
|
||||
+6
-12
@@ -416,14 +416,12 @@ public class AnnotationDetector extends Detector implements Detector.UastScanner
|
||||
if (condition != null && PsiType.INT.equals(condition.getExpressionType())) {
|
||||
UAnnotation annotation = findIntDefAnnotation(condition);
|
||||
if (annotation != null) {
|
||||
UNamedExpression namedValue =
|
||||
UExpression value =
|
||||
annotation.findDeclaredAttributeValue(ATTR_VALUE);
|
||||
if (namedValue == null) {
|
||||
namedValue = annotation.findDeclaredAttributeValue(null);
|
||||
if (value == null) {
|
||||
value = annotation.findDeclaredAttributeValue(null);
|
||||
}
|
||||
|
||||
UExpression value = (namedValue != null) ? namedValue.getExpression() : null;
|
||||
|
||||
if (UastExpressionUtils.isArrayInitializer(value)) {
|
||||
List<UExpression> allowedValues =
|
||||
((UCallExpression) value).getValueArguments();
|
||||
@@ -514,14 +512,10 @@ public class AnnotationDetector extends Detector implements Detector.UastScanner
|
||||
}
|
||||
|
||||
private void ensureUniqueValues(@NonNull UAnnotation node) {
|
||||
UNamedExpression namedValue = node.findAttributeValue(ATTR_VALUE);
|
||||
if (namedValue == null) {
|
||||
namedValue = node.findAttributeValue(null);
|
||||
UExpression value = node.findAttributeValue(ATTR_VALUE);
|
||||
if (value == null) {
|
||||
value = node.findAttributeValue(null);
|
||||
}
|
||||
if (namedValue == null) {
|
||||
return;
|
||||
}
|
||||
UExpression value = namedValue.getExpression();
|
||||
|
||||
if (!(UastExpressionUtils.isArrayInitializer(value))) {
|
||||
return;
|
||||
|
||||
@@ -1263,34 +1263,28 @@ public class ApiDetector extends ResourceXmlDetector
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visitVariable(@NotNull UVariable node) {
|
||||
if (node instanceof ULocalVariable) {
|
||||
visitLocalVariable((ULocalVariable) node);
|
||||
}
|
||||
return super.visitVariable(node);
|
||||
}
|
||||
|
||||
private void visitLocalVariable(ULocalVariable variable) {
|
||||
public boolean visitLocalVariable(ULocalVariable variable) {
|
||||
UExpression initializer = variable.getUastInitializer();
|
||||
if (initializer == null) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
PsiType initializerType = initializer.getExpressionType();
|
||||
if (!(initializerType instanceof PsiClassType)) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
PsiType interfaceType = variable.getType();
|
||||
if (initializerType.equals(interfaceType)) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(interfaceType instanceof PsiClassType)) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
checkCast(initializer, (PsiClassType)initializerType, (PsiClassType)interfaceType);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+14
-18
@@ -16,25 +16,18 @@
|
||||
package com.android.tools.klint.checks;
|
||||
|
||||
|
||||
import static com.android.SdkConstants.ATTR_VALUE;
|
||||
import static com.android.tools.klint.checks.SupportAnnotationDetector.ATTR_ALL_OF;
|
||||
import static com.android.tools.klint.checks.SupportAnnotationDetector.ATTR_ANY_OF;
|
||||
import static com.android.tools.klint.checks.SupportAnnotationDetector.ATTR_CONDITIONAL;
|
||||
|
||||
import com.android.annotations.NonNull;
|
||||
import com.android.annotations.Nullable;
|
||||
import com.android.annotations.VisibleForTesting;
|
||||
import com.android.sdklib.AndroidVersion;
|
||||
import com.android.tools.klint.detector.api.ConstantEvaluator;
|
||||
import com.android.tools.klint.detector.api.JavaContext;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiAnnotationMemberValue;
|
||||
import com.intellij.psi.PsiArrayInitializerMemberValue;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.UAnnotation;
|
||||
import org.jetbrains.uast.UCallExpression;
|
||||
import org.jetbrains.uast.UExpression;
|
||||
import org.jetbrains.uast.util.UastExpressionUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -42,6 +35,9 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.android.SdkConstants.ATTR_VALUE;
|
||||
import static com.android.tools.klint.checks.SupportAnnotationDetector.*;
|
||||
|
||||
/**
|
||||
* A permission requirement is a boolean expression of permission names that a
|
||||
* caller must satisfy for a given Android API.
|
||||
@@ -140,7 +136,7 @@ public abstract class PermissionRequirement {
|
||||
public static Boolean getAnnotationBooleanValue(@Nullable UAnnotation annotation,
|
||||
@NonNull String name) {
|
||||
if (annotation != null) {
|
||||
UNamedExpression attributeValue = annotation.findDeclaredAttributeValue(name);
|
||||
UExpression attributeValue = annotation.findDeclaredAttributeValue(name);
|
||||
if (attributeValue == null && ATTR_VALUE.equals(name)) {
|
||||
attributeValue = annotation.findDeclaredAttributeValue(null);
|
||||
}
|
||||
@@ -160,7 +156,7 @@ public abstract class PermissionRequirement {
|
||||
public static Long getAnnotationLongValue(@Nullable UAnnotation annotation,
|
||||
@NonNull String name) {
|
||||
if (annotation != null) {
|
||||
UNamedExpression attributeValue = annotation.findDeclaredAttributeValue(name);
|
||||
UExpression attributeValue = annotation.findDeclaredAttributeValue(name);
|
||||
if (attributeValue == null && ATTR_VALUE.equals(name)) {
|
||||
attributeValue = annotation.findDeclaredAttributeValue(null);
|
||||
}
|
||||
@@ -180,7 +176,7 @@ public abstract class PermissionRequirement {
|
||||
public static Double getAnnotationDoubleValue(@Nullable UAnnotation annotation,
|
||||
@NonNull String name) {
|
||||
if (annotation != null) {
|
||||
UNamedExpression attributeValue = annotation.findDeclaredAttributeValue(name);
|
||||
UExpression attributeValue = annotation.findDeclaredAttributeValue(name);
|
||||
if (attributeValue == null && ATTR_VALUE.equals(name)) {
|
||||
attributeValue = annotation.findDeclaredAttributeValue(null);
|
||||
}
|
||||
@@ -200,7 +196,7 @@ public abstract class PermissionRequirement {
|
||||
public static String getAnnotationStringValue(@Nullable UAnnotation annotation,
|
||||
@NonNull String name) {
|
||||
if (annotation != null) {
|
||||
UNamedExpression attributeValue = annotation.findDeclaredAttributeValue(name);
|
||||
UExpression attributeValue = annotation.findDeclaredAttributeValue(name);
|
||||
if (attributeValue == null && ATTR_VALUE.equals(name)) {
|
||||
attributeValue = annotation.findDeclaredAttributeValue(null);
|
||||
}
|
||||
@@ -220,16 +216,16 @@ public abstract class PermissionRequirement {
|
||||
public static String[] getAnnotationStringValues(@Nullable UAnnotation annotation,
|
||||
@NonNull String name) {
|
||||
if (annotation != null) {
|
||||
UNamedExpression attributeValue = annotation.findDeclaredAttributeValue(name);
|
||||
UExpression attributeValue = annotation.findDeclaredAttributeValue(name);
|
||||
if (attributeValue == null && ATTR_VALUE.equals(name)) {
|
||||
attributeValue = annotation.findDeclaredAttributeValue(null);
|
||||
}
|
||||
if (attributeValue == null) {
|
||||
return null;
|
||||
}
|
||||
if (UastExpressionUtils.isArrayInitializer(attributeValue.getExpression())) {
|
||||
if (UastExpressionUtils.isArrayInitializer(attributeValue)) {
|
||||
List<UExpression> initializers =
|
||||
((UCallExpression) attributeValue.getExpression()).getValueArguments();
|
||||
((UCallExpression) attributeValue).getValueArguments();
|
||||
List<String> result = Lists.newArrayListWithCapacity(initializers.size());
|
||||
ConstantEvaluator constantEvaluator = new ConstantEvaluator(null);
|
||||
for (UExpression element : initializers) {
|
||||
@@ -245,7 +241,7 @@ public abstract class PermissionRequirement {
|
||||
}
|
||||
} else {
|
||||
// Use constant evaluator since we want to resolve field references as well
|
||||
Object o = ConstantEvaluator.evaluate(null, attributeValue.getExpression());
|
||||
Object o = ConstantEvaluator.evaluate(null, attributeValue);
|
||||
if (o instanceof String) {
|
||||
return new String[]{(String) o};
|
||||
} else if (o instanceof String[]) {
|
||||
|
||||
+12
-70
@@ -16,37 +16,6 @@
|
||||
|
||||
package com.android.tools.klint.checks;
|
||||
|
||||
import static com.android.SdkConstants.ANDROID_URI;
|
||||
import static com.android.SdkConstants.ATTR_NAME;
|
||||
import static com.android.SdkConstants.ATTR_VALUE;
|
||||
import static com.android.SdkConstants.CLASS_INTENT;
|
||||
import static com.android.SdkConstants.CLASS_VIEW;
|
||||
import static com.android.SdkConstants.INT_DEF_ANNOTATION;
|
||||
import static com.android.SdkConstants.STRING_DEF_ANNOTATION;
|
||||
import static com.android.SdkConstants.SUPPORT_ANNOTATIONS_PREFIX;
|
||||
import static com.android.SdkConstants.TAG_PERMISSION;
|
||||
import static com.android.SdkConstants.TAG_USES_PERMISSION;
|
||||
import static com.android.SdkConstants.TAG_USES_PERMISSION_SDK_23;
|
||||
import static com.android.SdkConstants.TAG_USES_PERMISSION_SDK_M;
|
||||
import static com.android.SdkConstants.TYPE_DEF_FLAG_ATTRIBUTE;
|
||||
import static com.android.resources.ResourceType.COLOR;
|
||||
import static com.android.resources.ResourceType.DIMEN;
|
||||
import static com.android.resources.ResourceType.DRAWABLE;
|
||||
import static com.android.resources.ResourceType.MIPMAP;
|
||||
import static com.android.tools.klint.checks.PermissionFinder.Operation.ACTION;
|
||||
import static com.android.tools.klint.checks.PermissionFinder.Operation.READ;
|
||||
import static com.android.tools.klint.checks.PermissionFinder.Operation.WRITE;
|
||||
import static com.android.tools.klint.checks.PermissionRequirement.ATTR_PROTECTION_LEVEL;
|
||||
import static com.android.tools.klint.checks.PermissionRequirement.VALUE_DANGEROUS;
|
||||
import static com.android.tools.klint.checks.PermissionRequirement.getAnnotationBooleanValue;
|
||||
import static com.android.tools.klint.checks.PermissionRequirement.getAnnotationDoubleValue;
|
||||
import static com.android.tools.klint.checks.PermissionRequirement.getAnnotationLongValue;
|
||||
import static com.android.tools.klint.checks.PermissionRequirement.getAnnotationStringValue;
|
||||
import static com.android.tools.klint.detector.api.ResourceEvaluator.COLOR_INT_ANNOTATION;
|
||||
import static com.android.tools.klint.detector.api.ResourceEvaluator.PX_ANNOTATION;
|
||||
import static com.android.tools.klint.detector.api.ResourceEvaluator.RES_SUFFIX;
|
||||
import static org.jetbrains.uast.UastUtils.getQualifiedParentOrThis;
|
||||
|
||||
import com.android.annotations.NonNull;
|
||||
import com.android.annotations.Nullable;
|
||||
import com.android.resources.ResourceType;
|
||||
@@ -58,35 +27,11 @@ import com.android.tools.klint.client.api.ExternalReferenceExpression;
|
||||
import com.android.tools.klint.client.api.JavaEvaluator;
|
||||
import com.android.tools.klint.client.api.LintClient;
|
||||
import com.android.tools.klint.client.api.UastLintUtils;
|
||||
import com.android.tools.klint.detector.api.Category;
|
||||
import com.android.tools.klint.detector.api.ConstantEvaluator;
|
||||
import com.android.tools.klint.detector.api.Detector;
|
||||
import com.android.tools.klint.detector.api.Implementation;
|
||||
import com.android.tools.klint.detector.api.Issue;
|
||||
import com.android.tools.klint.detector.api.JavaContext;
|
||||
import com.android.tools.klint.detector.api.Project;
|
||||
import com.android.tools.klint.detector.api.ResourceEvaluator;
|
||||
import com.android.tools.klint.detector.api.Scope;
|
||||
import com.android.tools.klint.detector.api.Severity;
|
||||
import com.android.tools.klint.detector.api.TextFormat;
|
||||
import com.android.tools.klint.detector.api.*;
|
||||
import com.android.utils.XmlUtils;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiArrayType;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiClassType;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiJavaCodeReferenceElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.PsiModifierList;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import com.intellij.psi.PsiParameterList;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.java.JavaUAnnotation;
|
||||
import org.jetbrains.uast.util.UastExpressionUtils;
|
||||
@@ -98,13 +43,14 @@ import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static com.android.SdkConstants.*;
|
||||
import static com.android.resources.ResourceType.*;
|
||||
import static com.android.tools.klint.checks.PermissionFinder.Operation.*;
|
||||
import static com.android.tools.klint.checks.PermissionRequirement.*;
|
||||
import static com.android.tools.klint.detector.api.ResourceEvaluator.*;
|
||||
import static org.jetbrains.uast.UastUtils.getQualifiedParentOrThis;
|
||||
|
||||
/**
|
||||
* Looks up annotations on method calls and enforces the various things they
|
||||
@@ -1710,15 +1656,11 @@ public class SupportAnnotationDetector extends Detector implements Detector.Uast
|
||||
|
||||
@Nullable
|
||||
private static UExpression getAnnotationValue(@NonNull UAnnotation annotation) {
|
||||
UNamedExpression value = annotation.findDeclaredAttributeValue(ATTR_VALUE);
|
||||
UExpression value = annotation.findDeclaredAttributeValue(ATTR_VALUE);
|
||||
if (value == null) {
|
||||
value = annotation.findDeclaredAttributeValue(null);
|
||||
}
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return value.getExpression();
|
||||
return value;
|
||||
}
|
||||
|
||||
private static String listAllowedValues(@NonNull UElement context,
|
||||
|
||||
+3
-6
@@ -40,7 +40,6 @@ import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.psi.PsiElementBacked;
|
||||
import org.jetbrains.uast.psi.UElementWithLocation;
|
||||
import org.jetbrains.uast.util.UastExpressionUtils;
|
||||
|
||||
@@ -116,11 +115,9 @@ public class IntellijLintUtils {
|
||||
}
|
||||
|
||||
TextRange textRange = null;
|
||||
if (element instanceof PsiElementBacked) {
|
||||
PsiElement psi = ((PsiElementBacked) element).getPsi();
|
||||
if (psi != null) {
|
||||
textRange = psi.getTextRange();
|
||||
}
|
||||
PsiElement psi = element.getPsi();
|
||||
if (psi != null) {
|
||||
textRange = psi.getTextRange();
|
||||
} else if (element instanceof UElementWithLocation) {
|
||||
UElementWithLocation elementWithLocation = (UElementWithLocation) element;
|
||||
textRange = new TextRange(
|
||||
|
||||
@@ -17,16 +17,14 @@
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.psi.KtAnnotatedExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.uast.UAnnotation
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
abstract class KotlinAbstractUElement : UElement {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this !is PsiElementBacked || other !is PsiElementBacked) {
|
||||
return this === other
|
||||
if (other !is UElement) {
|
||||
return false
|
||||
}
|
||||
|
||||
return this.psi == other.psi
|
||||
@@ -36,8 +34,7 @@ abstract class KotlinAbstractUElement : UElement {
|
||||
abstract class KotlinAbstractUExpression : KotlinAbstractUElement(), UExpression {
|
||||
override val annotations: List<UAnnotation>
|
||||
get() {
|
||||
val psi = (this as? PsiElementBacked)?.psi as? KtExpression ?: return emptyList()
|
||||
val annotatedExpression = psi.parent as? KtAnnotatedExpression ?: return emptyList()
|
||||
val annotatedExpression = psi?.parent as? KtAnnotatedExpression ?: return emptyList()
|
||||
return annotatedExpression.annotationEntries.map { KotlinUAnnotation(it, this) }
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,6 @@ import org.jetbrains.uast.kotlin.expressions.*
|
||||
import org.jetbrains.uast.kotlin.kinds.KotlinSpecialExpressionKinds
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
interface KotlinUastBindingContextProviderService {
|
||||
fun getBindingContext(element: KtElement): BindingContext
|
||||
@@ -159,7 +158,7 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin {
|
||||
return when (element) {
|
||||
is KotlinUSimpleReferenceExpression.KotlinAccessorCallExpression -> element.setterValue != null
|
||||
is KotlinAbstractUExpression -> {
|
||||
val ktElement = ((element as? PsiElementBacked)?.psi as? KtElement) ?: return false
|
||||
val ktElement = element.psi as? KtElement ?: return false
|
||||
ktElement.analyze()[BindingContext.USED_AS_EXPRESSION, ktElement] ?: false
|
||||
}
|
||||
else -> false
|
||||
@@ -227,7 +226,7 @@ internal object KotlinConverter {
|
||||
psi: KtVariableDeclaration,
|
||||
parent: UElement?
|
||||
): UDeclarationsExpression {
|
||||
val parentPsiElement = (parent as? PsiElementBacked)?.psi
|
||||
val parentPsiElement = parent?.psi
|
||||
val variable = KotlinUVariable.create(UastKotlinPsiVariable.create(psi, parentPsiElement, parent!!), parent)
|
||||
return KotlinUDeclarationsExpression(parent).apply { declarations = listOf(variable) }
|
||||
}
|
||||
|
||||
+15
-4
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
@@ -19,7 +20,7 @@ class KotlinUAnnotation(
|
||||
val context = getUastContext()
|
||||
psi.valueArguments.map { arg ->
|
||||
val name = arg.getArgumentName()?.asName?.asString() ?: ""
|
||||
UNamedExpression(name, this).apply {
|
||||
KotlinUNamedExpression(name, this).apply {
|
||||
val value = arg.getArgumentExpression()?.let { context.convertElement(it, this) } as? UExpression
|
||||
expression = value ?: UastEmptyExpression
|
||||
}
|
||||
@@ -34,7 +35,17 @@ class KotlinUAnnotation(
|
||||
//TODO
|
||||
override fun findAttributeValue(name: String?) = findDeclaredAttributeValue(name)
|
||||
|
||||
override fun findDeclaredAttributeValue(name: String?): UNamedExpression? {
|
||||
return attributeValues.firstOrNull { it.matchesName(name ?: "value") }
|
||||
override fun findDeclaredAttributeValue(name: String?): UExpression? {
|
||||
return attributeValues.firstOrNull { it.name == (name ?: "value") }?.expression
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinUNamedExpression(override val name: String, override val containingElement: UElement?) : UNamedExpression {
|
||||
override lateinit var expression: UExpression
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
|
||||
override val psi: PsiElement?
|
||||
get() = null
|
||||
}
|
||||
|
||||
@@ -69,6 +69,9 @@ class KotlinUClass private constructor(
|
||||
val containingMethod = this
|
||||
|
||||
object : UBlockExpression {
|
||||
override val psi: PsiElement?
|
||||
get() = null
|
||||
|
||||
override val containingElement: UElement?
|
||||
get() = containingMethod
|
||||
|
||||
|
||||
+1
-2
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UImportStatement
|
||||
import org.jetbrains.uast.USimpleNameReferenceExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUImportStatement(
|
||||
override val psi: KtImportDirective,
|
||||
@@ -50,7 +49,7 @@ class KotlinUImportStatement(
|
||||
override val identifier: String,
|
||||
override val containingElement: UElement?,
|
||||
private val importDirective: KtImportDirective
|
||||
) : KotlinAbstractUExpression(), USimpleNameReferenceExpression, PsiElementBacked {
|
||||
) : KotlinAbstractUExpression(), USimpleNameReferenceExpression {
|
||||
override val resolvedName: String?
|
||||
get() = identifier
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.jetbrains.uast.java.JavaUAnnotation
|
||||
import org.jetbrains.uast.java.annotations
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
abstract class AbstractKotlinUVariable : AbstractJavaUVariable() {
|
||||
override val uastInitializer: UExpression?
|
||||
@@ -179,7 +178,7 @@ open class KotlinUEnumConstant(
|
||||
private class KotlinEnumConstantClassReference(
|
||||
override val psi: PsiEnumConstant,
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), USimpleNameReferenceExpression, PsiElementBacked {
|
||||
) : JavaAbstractUExpression(), USimpleNameReferenceExpression {
|
||||
override fun resolve() = psi.containingClass
|
||||
override val resolvedName: String?
|
||||
get() = psi.containingClass?.name
|
||||
|
||||
+2
-4
@@ -3,14 +3,14 @@ package org.jetbrains.uast.kotlin.evaluation
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.uast.UBinaryExpression
|
||||
import org.jetbrains.uast.UastPostfixOperator
|
||||
import org.jetbrains.uast.evaluation.AbstractEvaluatorExtension
|
||||
import org.jetbrains.uast.evaluation.UEvaluationInfo
|
||||
import org.jetbrains.uast.evaluation.UEvaluationState
|
||||
import org.jetbrains.uast.evaluation.UEvaluatorExtension
|
||||
import org.jetbrains.uast.kotlin.KotlinBinaryOperators
|
||||
import org.jetbrains.uast.kotlin.KotlinPostfixOperators
|
||||
import org.jetbrains.uast.values.*
|
||||
|
||||
class KotlinEvaluatorExtension : UEvaluatorExtension {
|
||||
class KotlinEvaluatorExtension : AbstractEvaluatorExtension(KotlinLanguage.INSTANCE) {
|
||||
|
||||
private data class Range(val from: UValue, val to: UValue) {
|
||||
override fun toString() = "$from..$to"
|
||||
@@ -20,8 +20,6 @@ class KotlinEvaluatorExtension : UEvaluatorExtension {
|
||||
constructor(from: UValue, to: UValue, source: UBinaryExpression): this(Range(from, to), source)
|
||||
}
|
||||
|
||||
override val language: KotlinLanguage = KotlinLanguage.INSTANCE
|
||||
|
||||
override fun evaluatePostfix(
|
||||
operator: UastPostfixOperator,
|
||||
operandValue: UValue,
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||
|
||||
private fun createVariableReferenceExpression(variable: UVariable, containingElement: UElement?) =
|
||||
object : USimpleNameReferenceExpression {
|
||||
override val psi: PsiElement? = null
|
||||
override fun resolve(): PsiElement? = variable
|
||||
override val containingElement: UElement? = containingElement
|
||||
override val resolvedName: String? = variable.name
|
||||
@@ -21,6 +22,7 @@ private fun createVariableReferenceExpression(variable: UVariable, containingEle
|
||||
|
||||
private fun createNullLiteralExpression(containingElement: UElement?) =
|
||||
object : ULiteralExpression {
|
||||
override val psi: PsiElement? = null
|
||||
override val containingElement: UElement? = containingElement
|
||||
override val value: Any? = null
|
||||
override val annotations: List<UAnnotation> = emptyList()
|
||||
@@ -28,6 +30,7 @@ private fun createNullLiteralExpression(containingElement: UElement?) =
|
||||
|
||||
private fun createNotEqWithNullExpression(variable: UVariable, containingElement: UElement?) =
|
||||
object : UBinaryExpression {
|
||||
override val psi: PsiElement? = null
|
||||
override val containingElement: UElement? = containingElement
|
||||
override val leftOperand: UExpression by lz { createVariableReferenceExpression(variable, this) }
|
||||
override val rightOperand: UExpression by lz { createNullLiteralExpression(this) }
|
||||
@@ -49,6 +52,7 @@ private fun createElvisExpressions(
|
||||
declaration.declarations = listOf(tempVariable)
|
||||
|
||||
val ifExpression = object : UIfExpression {
|
||||
override val psi: PsiElement? = null
|
||||
override val containingElement: UElement? = containingElement
|
||||
override val condition: UExpression by lz { createNotEqWithNullExpression(tempVariable, this) }
|
||||
override val thenExpression: UExpression? by lz { createVariableReferenceExpression(tempVariable, this) }
|
||||
|
||||
+4
-3
@@ -17,15 +17,16 @@
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.UPolyadicExpression
|
||||
import org.jetbrains.uast.UastBinaryOperator
|
||||
|
||||
class KotlinStringTemplateUPolyadicExpression(
|
||||
override val psi: KtStringTemplateExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(),
|
||||
UPolyadicExpression,
|
||||
PsiElementBacked,
|
||||
KotlinUElementWithType,
|
||||
KotlinEvaluatableUElement {
|
||||
override val operands: List<UExpression> by lz { psi.entries.map { KotlinConverter.convert(it, this) } }
|
||||
|
||||
+1
-2
@@ -19,12 +19,11 @@ package org.jetbrains.uast.kotlin
|
||||
import org.jetbrains.kotlin.psi.KtArrayAccessExpression
|
||||
import org.jetbrains.uast.UArrayAccessExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUArrayAccessExpression(
|
||||
override val psi: KtArrayAccessExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UArrayAccessExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
) : KotlinAbstractUExpression(), UArrayAccessExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.arrayExpression, this) }
|
||||
override val indices by lz { psi.indexExpressions.map { KotlinConverter.convertOrEmpty(it, this) } }
|
||||
}
|
||||
+2
-3
@@ -25,12 +25,11 @@ import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUBinaryExpression(
|
||||
override val psi: KtBinaryExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UBinaryExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
) : KotlinAbstractUExpression(), UBinaryExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
private companion object {
|
||||
val BITWISE_OPERATORS = mapOf(
|
||||
"or" to UastBinaryOperator.BITWISE_OR,
|
||||
@@ -90,7 +89,7 @@ class KotlinUBinaryExpression(
|
||||
class KotlinCustomUBinaryExpression(
|
||||
override val psi: PsiElement,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UBinaryExpression, PsiElementBacked {
|
||||
) : KotlinAbstractUExpression(), UBinaryExpression {
|
||||
lateinit override var leftOperand: UExpression
|
||||
internal set
|
||||
|
||||
|
||||
+2
-3
@@ -21,12 +21,11 @@ import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpressionWithTypeRHS
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUBinaryExpressionWithType(
|
||||
override val psi: KtBinaryExpressionWithTypeRHS,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UBinaryExpressionWithType, PsiElementBacked,
|
||||
) : KotlinAbstractUExpression(), UBinaryExpressionWithType,
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
|
||||
override val operand by lz { KotlinConverter.convertOrEmpty(psi.left, this) }
|
||||
@@ -46,7 +45,7 @@ class KotlinUBinaryExpressionWithType(
|
||||
class KotlinCustomUBinaryExpressionWithType(
|
||||
override val psi: PsiElement,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UBinaryExpressionWithType, PsiElementBacked {
|
||||
) : KotlinAbstractUExpression(), UBinaryExpressionWithType {
|
||||
lateinit override var operand: UExpression
|
||||
internal set
|
||||
|
||||
|
||||
+1
-2
@@ -19,11 +19,10 @@ package org.jetbrains.uast.kotlin
|
||||
import org.jetbrains.kotlin.psi.KtBlockExpression
|
||||
import org.jetbrains.uast.UBlockExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUBlockExpression(
|
||||
override val psi: KtBlockExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UBlockExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
) : KotlinAbstractUExpression(), UBlockExpression, KotlinUElementWithType {
|
||||
override val expressions by lz { psi.statements.map { KotlinConverter.convertOrEmpty(it, this) } }
|
||||
}
|
||||
+1
-2
@@ -20,12 +20,11 @@ import org.jetbrains.kotlin.psi.KtBreakExpression
|
||||
import org.jetbrains.uast.UBreakExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.kotlin.KotlinAbstractUExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUBreakExpression(
|
||||
override val psi: KtBreakExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UBreakExpression, PsiElementBacked {
|
||||
) : KotlinAbstractUExpression(), UBreakExpression {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
}
|
||||
+1
-2
@@ -22,12 +22,11 @@ import org.jetbrains.kotlin.resolve.BindingContext.DOUBLE_COLON_LHS
|
||||
import org.jetbrains.uast.UCallableReferenceExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUCallableReferenceExpression(
|
||||
override val psi: KtCallableReferenceExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UCallableReferenceExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
) : KotlinAbstractUExpression(), UCallableReferenceExpression, KotlinUElementWithType {
|
||||
override val qualifierExpression: UExpression?
|
||||
get() {
|
||||
if (qualifierType != null) return null
|
||||
|
||||
@@ -22,12 +22,11 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UParameter
|
||||
import org.jetbrains.uast.UTypeReferenceExpression
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUCatchClause(
|
||||
override val psi: KtCatchClause,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUElement(), UCatchClause, PsiElementBacked {
|
||||
) : KotlinAbstractUElement(), UCatchClause {
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.catchBody, this) }
|
||||
|
||||
override val parameters by lz {
|
||||
|
||||
+1
-2
@@ -21,12 +21,11 @@ import org.jetbrains.kotlin.resolve.BindingContext.DOUBLE_COLON_LHS
|
||||
import org.jetbrains.uast.UClassLiteralExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUClassLiteralExpression(
|
||||
override val psi: KtClassLiteralExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UClassLiteralExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
) : KotlinAbstractUExpression(), UClassLiteralExpression, KotlinUElementWithType {
|
||||
override val type by lz {
|
||||
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, psi, boxed = true)
|
||||
|
||||
+1
-2
@@ -20,12 +20,11 @@ import org.jetbrains.kotlin.psi.KtContinueExpression
|
||||
import org.jetbrains.uast.UContinueExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.kotlin.KotlinAbstractUExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUContinueExpression(
|
||||
override val psi: KtContinueExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UContinueExpression, PsiElementBacked {
|
||||
) : KotlinAbstractUExpression(), UContinueExpression {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
}
|
||||
+4
@@ -15,11 +15,15 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.uast.kotlin.KotlinAbstractUExpression
|
||||
|
||||
class KotlinUDeclarationsExpression(
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UDeclarationsExpression {
|
||||
override val psi: PsiElement?
|
||||
get() = null
|
||||
|
||||
override lateinit var declarations: List<UDeclaration>
|
||||
internal set
|
||||
}
|
||||
+1
-2
@@ -20,12 +20,11 @@ import org.jetbrains.kotlin.psi.KtDoWhileExpression
|
||||
import org.jetbrains.uast.UDoWhileExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUDoWhileExpression(
|
||||
override val psi: KtDoWhileExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UDoWhileExpression, PsiElementBacked {
|
||||
) : KotlinAbstractUExpression(), UDoWhileExpression {
|
||||
override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) }
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) }
|
||||
|
||||
|
||||
@@ -21,9 +21,8 @@ import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
interface KotlinUElementWithType : UExpression, PsiElementBacked {
|
||||
interface KotlinUElementWithType : UExpression {
|
||||
override fun getExpressionType(): PsiType? {
|
||||
val ktElement = psi as? KtExpression ?: return null
|
||||
val ktType = ktElement.analyze()[BindingContext.EXPRESSION_TYPE_INFO, ktElement]?.type ?: return null
|
||||
@@ -31,7 +30,7 @@ interface KotlinUElementWithType : UExpression, PsiElementBacked {
|
||||
}
|
||||
}
|
||||
|
||||
interface KotlinEvaluatableUElement : UExpression, PsiElementBacked {
|
||||
interface KotlinEvaluatableUElement : UExpression {
|
||||
override fun evaluate(): Any? {
|
||||
val ktElement = psi as? KtExpression ?: return null
|
||||
|
||||
|
||||
+1
-2
@@ -24,13 +24,12 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.UExpressionList
|
||||
import org.jetbrains.uast.UastSpecialExpressionKind
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
open class KotlinUExpressionList(
|
||||
override val psi: PsiElement?,
|
||||
override val kind: UastSpecialExpressionKind, // original element
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UExpressionList, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
) : KotlinAbstractUExpression(), UExpressionList, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override lateinit var expressions: List<UExpression>
|
||||
internal set
|
||||
|
||||
|
||||
+1
-2
@@ -22,13 +22,12 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UForEachExpression
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import org.jetbrains.uast.psi.UastPsiParameterNotResolved
|
||||
|
||||
class KotlinUForEachExpression(
|
||||
override val psi: KtForExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UForEachExpression, PsiElementBacked {
|
||||
) : KotlinAbstractUExpression(), UForEachExpression {
|
||||
override val iteratedValue by lz { KotlinConverter.convertOrEmpty(psi.loopRange, this) }
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) }
|
||||
|
||||
|
||||
+1
-2
@@ -30,14 +30,13 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
class KotlinUFunctionCallExpression(
|
||||
override val psi: KtCallExpression,
|
||||
override val containingElement: UElement?,
|
||||
private val _resolvedCall: ResolvedCall<*>? = null
|
||||
) : KotlinAbstractUExpression(), UCallExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
) : KotlinAbstractUExpression(), UCallExpression, KotlinUElementWithType {
|
||||
companion object {
|
||||
fun resolveSource(descriptor: DeclarationDescriptor, source: PsiElement?): PsiMethod? {
|
||||
if (descriptor is ConstructorDescriptor && descriptor.isPrimary
|
||||
|
||||
+1
-2
@@ -20,12 +20,11 @@ import org.jetbrains.kotlin.psi.KtIfExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.UIfExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUIfExpression(
|
||||
override val psi: KtIfExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UIfExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
) : KotlinAbstractUExpression(), UIfExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) }
|
||||
override val thenExpression by lz { KotlinConverter.convertOrNull(psi.then, this) }
|
||||
override val elseExpression by lz { KotlinConverter.convertOrNull(psi.`else`, this) }
|
||||
|
||||
+1
-2
@@ -20,12 +20,11 @@ import org.jetbrains.kotlin.psi.KtLabeledExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.ULabeledExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinULabeledExpression(
|
||||
override val psi: KtLabeledExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), ULabeledExpression, PsiElementBacked {
|
||||
) : KotlinAbstractUExpression(), ULabeledExpression {
|
||||
override val label: String
|
||||
get() = psi.getLabelName().orAnonymous("label")
|
||||
|
||||
|
||||
+1
-2
@@ -21,13 +21,12 @@ import org.jetbrains.uast.UBlockExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.ULambdaExpression
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import org.jetbrains.uast.withMargin
|
||||
|
||||
class KotlinULambdaExpression(
|
||||
override val psi: KtLambdaExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), ULambdaExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
) : KotlinAbstractUExpression(), ULambdaExpression, KotlinUElementWithType {
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.bodyExpression, this) }
|
||||
|
||||
override val valueParameters by lz {
|
||||
|
||||
+2
-3
@@ -22,12 +22,11 @@ import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.psi.KtConstantExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.ULiteralExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinULiteralExpression(
|
||||
override val psi: KtConstantExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), ULiteralExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
) : KotlinAbstractUExpression(), ULiteralExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val isNull: Boolean
|
||||
get() = psi.unwrapBlockOrParenthesis().node?.elementType == KtNodeTypes.NULL
|
||||
|
||||
@@ -38,7 +37,7 @@ class KotlinStringULiteralExpression(
|
||||
override val psi: PsiElement,
|
||||
override val containingElement: UElement?,
|
||||
val text: String? = null
|
||||
) : KotlinAbstractUExpression(), ULiteralExpression, PsiElementBacked, KotlinUElementWithType{
|
||||
) : KotlinAbstractUExpression(), ULiteralExpression, KotlinUElementWithType{
|
||||
override val value: String
|
||||
get() = text ?: StringUtil.unescapeStringCharacters(psi.text)
|
||||
|
||||
|
||||
+2
-3
@@ -22,12 +22,11 @@ import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.psi.KtObjectLiteralExpression
|
||||
import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUObjectLiteralExpression(
|
||||
override val psi: KtObjectLiteralExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UObjectLiteralExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
) : KotlinAbstractUExpression(), UObjectLiteralExpression, KotlinUElementWithType {
|
||||
override val declaration by lz { getLanguagePlugin().convert<UClass>(psi.objectDeclaration.toLightClass()!!, this) }
|
||||
|
||||
override fun getExpressionType() = psi.objectDeclaration.toPsiType()
|
||||
@@ -59,7 +58,7 @@ class KotlinUObjectLiteralExpression(
|
||||
private class ObjectLiteralClassReference(
|
||||
override val psi: KtSuperTypeCallEntry,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUElement(), USimpleNameReferenceExpression, PsiElementBacked {
|
||||
) : KotlinAbstractUElement(), USimpleNameReferenceExpression {
|
||||
override fun resolve() = (psi.resolveCallToDeclaration(this) as? PsiMethod)?.containingClass
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
|
||||
+1
-2
@@ -19,11 +19,10 @@ package org.jetbrains.uast.kotlin
|
||||
import org.jetbrains.kotlin.psi.KtParenthesizedExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UParenthesizedExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUParenthesizedExpression(
|
||||
override val psi: KtParenthesizedExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UParenthesizedExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
) : KotlinAbstractUExpression(), UParenthesizedExpression, KotlinUElementWithType {
|
||||
override val expression by lz { KotlinConverter.convertOrEmpty(psi.expression, this) }
|
||||
}
|
||||
+1
-2
@@ -20,12 +20,11 @@ import com.intellij.psi.PsiMethod
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtPostfixExpression
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUPostfixExpression(
|
||||
override val psi: KtPostfixExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UPostfixExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement, UResolvable {
|
||||
) : KotlinAbstractUExpression(), UPostfixExpression, KotlinUElementWithType, KotlinEvaluatableUElement, UResolvable {
|
||||
override val operand by lz { KotlinConverter.convertOrEmpty(psi.baseExpression, this) }
|
||||
|
||||
override val operator = when (psi.operationToken) {
|
||||
|
||||
+1
-2
@@ -23,12 +23,11 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.UPrefixExpression
|
||||
import org.jetbrains.uast.UastPrefixOperator
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUPrefixExpression(
|
||||
override val psi: KtPrefixExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UPrefixExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
) : KotlinAbstractUExpression(), UPrefixExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val operand by lz { KotlinConverter.convertOrEmpty(psi.baseExpression, this) }
|
||||
|
||||
override val operatorIdentifier: UIdentifier?
|
||||
|
||||
+2
-3
@@ -25,13 +25,12 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.UQualifiedReferenceExpression
|
||||
import org.jetbrains.uast.UastQualifiedExpressionAccessType
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUQualifiedReferenceExpression(
|
||||
override val psi: KtDotQualifiedExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UQualifiedReferenceExpression,
|
||||
PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) }
|
||||
override val selector by lz { KotlinConverter.convertOrEmpty(psi.selectorExpression, this) }
|
||||
override val accessType = UastQualifiedExpressionAccessType.SIMPLE
|
||||
@@ -46,7 +45,7 @@ class KotlinUComponentQualifiedReferenceExpression(
|
||||
override val psi: KtDestructuringDeclarationEntry,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UQualifiedReferenceExpression,
|
||||
PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val accessType = UastQualifiedExpressionAccessType.SIMPLE
|
||||
|
||||
override lateinit var receiver: UExpression
|
||||
|
||||
+1
-2
@@ -19,11 +19,10 @@ package org.jetbrains.uast.kotlin
|
||||
import org.jetbrains.kotlin.psi.KtReturnExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UReturnExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUReturnExpression(
|
||||
override val psi: KtReturnExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UReturnExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
) : KotlinAbstractUExpression(), UReturnExpression, KotlinUElementWithType {
|
||||
override val returnExpression by lz { KotlinConverter.convertOrNull(psi.returnedExpression, this) }
|
||||
}
|
||||
+1
-2
@@ -20,13 +20,12 @@ import com.intellij.psi.PsiNamedElement
|
||||
import org.jetbrains.kotlin.psi.KtSafeQualifiedExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UQualifiedReferenceExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUSafeQualifiedExpression(
|
||||
override val psi: KtSafeQualifiedExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UQualifiedReferenceExpression,
|
||||
PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) }
|
||||
override val selector by lz { KotlinConverter.convertOrEmpty(psi.selectorExpression, this) }
|
||||
override val accessType = KotlinQualifiedExpressionAccessTypes.SAFE
|
||||
|
||||
+5
-4
@@ -31,14 +31,13 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.constant
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
open class KotlinUSimpleReferenceExpression(
|
||||
override val psi: KtSimpleNameExpression,
|
||||
override val identifier: String,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), USimpleNameReferenceExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
) : KotlinAbstractUExpression(), USimpleNameReferenceExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
private val resolvedDeclaration by lz { psi.resolveCallToDeclaration(this) }
|
||||
|
||||
override fun resolve() = resolvedDeclaration
|
||||
@@ -95,7 +94,7 @@ open class KotlinUSimpleReferenceExpression(
|
||||
private val resolvedCall: ResolvedCall<*>,
|
||||
private val accessorDescriptor: DeclarationDescriptor,
|
||||
val setterValue: KtExpression?
|
||||
) : UCallExpression, PsiElementBacked {
|
||||
) : UCallExpression {
|
||||
override val methodName: String?
|
||||
get() = accessorDescriptor.name.asString()
|
||||
|
||||
@@ -186,7 +185,7 @@ class KotlinClassViaConstructorUSimpleReferenceExpression(
|
||||
override val psi: KtCallExpression,
|
||||
override val identifier: String,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), USimpleNameReferenceExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
) : KotlinAbstractUExpression(), USimpleNameReferenceExpression, KotlinUElementWithType {
|
||||
override val resolvedName: String?
|
||||
get() = (psi.getResolvedCall(psi.analyze())?.resultingDescriptor as? ConstructorDescriptor)
|
||||
?.containingDeclaration?.name?.asString()
|
||||
@@ -203,6 +202,8 @@ class KotlinStringUSimpleReferenceExpression(
|
||||
override val identifier: String,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), USimpleNameReferenceExpression {
|
||||
override val psi: PsiElement?
|
||||
get() = null
|
||||
override fun resolve() = null
|
||||
override val resolvedName: String?
|
||||
get() = identifier
|
||||
|
||||
+1
-2
@@ -21,12 +21,11 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.USuperExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUSuperExpression(
|
||||
override val psi: KtSuperExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), USuperExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
) : KotlinAbstractUExpression(), USuperExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
|
||||
|
||||
+5
-3
@@ -16,15 +16,15 @@
|
||||
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.kotlin.kinds.KotlinSpecialExpressionKinds
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUSwitchExpression(
|
||||
override val psi: KtWhenExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), USwitchExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
) : KotlinAbstractUExpression(), USwitchExpression, KotlinUElementWithType {
|
||||
override val expression by lz { KotlinConverter.convertOrNull(psi.subjectExpression, this) }
|
||||
|
||||
override val body: UExpressionList by lz {
|
||||
@@ -49,7 +49,7 @@ class KotlinUSwitchExpression(
|
||||
class KotlinUSwitchEntry(
|
||||
override val psi: KtWhenEntry,
|
||||
override val containingElement: UExpression
|
||||
) : KotlinAbstractUExpression(), USwitchClauseExpressionWithBody, PsiElementBacked {
|
||||
) : KotlinAbstractUExpression(), USwitchClauseExpressionWithBody {
|
||||
override val caseValues by lz {
|
||||
psi.conditions.map { when (it) {
|
||||
is KtWhenConditionInRange -> KotlinCustomUBinaryExpression(it, this).apply {
|
||||
@@ -91,6 +91,8 @@ class KotlinUSwitchEntry(
|
||||
}
|
||||
containingElement
|
||||
expressions = userExpressions + object : UBreakExpression {
|
||||
override val psi: PsiElement?
|
||||
get() = null
|
||||
override val label: String?
|
||||
get() = null
|
||||
override val containingElement: UElement?
|
||||
|
||||
+1
-2
@@ -21,12 +21,11 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.UThisExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUThisExpression(
|
||||
override val psi: KtThisExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UThisExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
) : KotlinAbstractUExpression(), UThisExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
|
||||
|
||||
+1
-2
@@ -19,11 +19,10 @@ package org.jetbrains.uast.kotlin
|
||||
import org.jetbrains.kotlin.psi.KtThrowExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UThrowExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUThrowExpression(
|
||||
override val psi: KtThrowExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UThrowExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
) : KotlinAbstractUExpression(), UThrowExpression, KotlinUElementWithType {
|
||||
override val thrownExpression by lz { KotlinConverter.convertOrEmpty(psi.thrownExpression, this) }
|
||||
}
|
||||
+1
-2
@@ -21,12 +21,11 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.UTryExpression
|
||||
import org.jetbrains.uast.UVariable
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUTryExpression(
|
||||
override val psi: KtTryExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UTryExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
) : KotlinAbstractUExpression(), UTryExpression, KotlinUElementWithType {
|
||||
override val tryClause by lz { KotlinConverter.convertOrEmpty(psi.tryBlock, this) }
|
||||
override val catchClauses by lz { psi.catchClauses.map { KotlinUCatchClause(it, this) } }
|
||||
override val finallyClause by lz { psi.finallyBlock?.finalExpression?.let { KotlinConverter.convertExpression(it, this) } }
|
||||
|
||||
+1
-2
@@ -20,12 +20,11 @@ import org.jetbrains.kotlin.psi.KtIsExpression
|
||||
import org.jetbrains.uast.UBinaryExpressionWithType
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UastBinaryExpressionWithTypeKind
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUTypeCheckExpression(
|
||||
override val psi: KtIsExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UBinaryExpressionWithType, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
) : KotlinAbstractUExpression(), UBinaryExpressionWithType, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val operand by lz { KotlinConverter.convertOrEmpty(psi.leftHandSide, this) }
|
||||
|
||||
override val type by lz { psi.typeReference.toPsiType(this) }
|
||||
|
||||
+2
-3
@@ -4,19 +4,18 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UTypeReferenceExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
open class KotlinUTypeReferenceExpression(
|
||||
override val type: PsiType,
|
||||
override val psi: PsiElement?,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UTypeReferenceExpression, PsiElementBacked, KotlinUElementWithType
|
||||
) : KotlinAbstractUExpression(), UTypeReferenceExpression, KotlinUElementWithType
|
||||
|
||||
|
||||
class LazyKotlinUTypeReferenceExpression(
|
||||
override val psi: PsiElement,
|
||||
override val containingElement: UElement?,
|
||||
private val typeSupplier: () -> PsiType
|
||||
) : KotlinAbstractUExpression(), UTypeReferenceExpression, PsiElementBacked {
|
||||
) : KotlinAbstractUExpression(), UTypeReferenceExpression {
|
||||
override val type: PsiType by lz { typeSupplier() }
|
||||
}
|
||||
+1
-2
@@ -20,12 +20,11 @@ import org.jetbrains.kotlin.psi.KtWhileExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.UWhileExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUWhileExpression(
|
||||
override val psi: KtWhileExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UWhileExpression, PsiElementBacked {
|
||||
) : KotlinAbstractUExpression(), UWhileExpression {
|
||||
override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) }
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) }
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.kotlin.*
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
|
||||
private class KotlinLocalFunctionUVariable(
|
||||
@@ -29,7 +28,7 @@ private class KotlinLocalFunctionUVariable(
|
||||
private class KotlinLocalFunctionULambdaExpression(
|
||||
override val psi: KtFunction,
|
||||
override val containingElement: UElement?
|
||||
): KotlinAbstractUExpression(), ULambdaExpression, PsiElementBacked {
|
||||
): KotlinAbstractUExpression(), ULambdaExpression {
|
||||
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.bodyExpression, this) }
|
||||
|
||||
|
||||
+1
-2
@@ -19,11 +19,10 @@ package org.jetbrains.uast.kotlin
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class UnknownKotlinExpression(
|
||||
override val psi: KtExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UExpression, PsiElementBacked {
|
||||
) : KotlinAbstractUExpression(), UExpression {
|
||||
override fun asLogString() = "[!] UnknownKotlinExpression ($psi)"
|
||||
}
|
||||
@@ -9,7 +9,7 @@ UFile (package = )
|
||||
ULiteralExpression (value = 5)
|
||||
UClass (name = IntRange)
|
||||
UAnnotation (fqName = java.lang.annotation.Retention)
|
||||
UNamedExpression (name = )
|
||||
UNamedExpression (name = null)
|
||||
UQualifiedReferenceExpression
|
||||
UQualifiedReferenceExpression
|
||||
UQualifiedReferenceExpression
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.uast.test.kotlin
|
||||
|
||||
import com.intellij.mock.MockProject
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.extensions.Extensions
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
@@ -21,6 +22,12 @@ import org.jetbrains.kotlin.config.addKotlinSourceRoot
|
||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM
|
||||
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import org.jetbrains.uast.UastLanguagePlugin
|
||||
import org.jetbrains.uast.evaluation.UEvaluatorExtension
|
||||
import org.jetbrains.uast.kotlin.KotlinUastBindingContextProviderService
|
||||
import org.jetbrains.uast.kotlin.KotlinUastLanguagePlugin
|
||||
import org.jetbrains.uast.kotlin.evaluation.KotlinEvaluatorExtension
|
||||
import org.jetbrains.uast.kotlin.internal.CliKotlinUastBindingContextProviderService
|
||||
import org.jetbrains.uast.kotlin.internal.UastAnalysisHandlerExtension
|
||||
import org.jetbrains.uast.test.env.AbstractCoreEnvironment
|
||||
import org.jetbrains.uast.test.env.AbstractUastTest
|
||||
@@ -40,6 +47,8 @@ abstract class AbstractKotlinUastTest : AbstractUastTest() {
|
||||
|
||||
super.initializeEnvironment(testFile)
|
||||
|
||||
initializeKotlinEnvironment()
|
||||
|
||||
val trace = CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace()
|
||||
|
||||
val kotlinCoreEnvironment = kotlinCoreEnvironment!!
|
||||
@@ -60,6 +69,18 @@ abstract class AbstractKotlinUastTest : AbstractUastTest() {
|
||||
return vfs.findFileByPath(testFile.canonicalPath)!!
|
||||
}
|
||||
|
||||
private fun initializeKotlinEnvironment() {
|
||||
val area = Extensions.getRootArea()
|
||||
area.getExtensionPoint(UastLanguagePlugin.extensionPointName)
|
||||
.registerExtension(KotlinUastLanguagePlugin())
|
||||
area.getExtensionPoint(UEvaluatorExtension.EXTENSION_POINT_NAME)
|
||||
.registerExtension(KotlinEvaluatorExtension())
|
||||
|
||||
project.registerService(
|
||||
KotlinUastBindingContextProviderService::class.java,
|
||||
CliKotlinUastBindingContextProviderService::class.java)
|
||||
}
|
||||
|
||||
override fun createEnvironment(source: File): AbstractCoreEnvironment {
|
||||
compilerConfiguration = createKotlinCompilerConfiguration(source)
|
||||
val parentDisposable = Disposer.newDisposable()
|
||||
@@ -105,6 +126,10 @@ abstract class AbstractKotlinUastTest : AbstractUastTest() {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun addJar(root: File) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override val project: MockProject
|
||||
get() = environment.project as MockProject
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry
|
||||
import org.jetbrains.uast.UAnnotation
|
||||
import org.jetbrains.uast.UFile
|
||||
import org.jetbrains.uast.ULiteralExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import org.jetbrains.uast.test.env.findElementByText
|
||||
import org.jetbrains.uast.toUElement
|
||||
import org.junit.Assert
|
||||
@@ -18,15 +17,15 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
||||
@Test fun testAnnotationParameters() {
|
||||
doTest("AnnotationParameters") { name, file ->
|
||||
val annotation = file.findElementByText<UAnnotation>("@IntRange(from = 10, to = 0)")
|
||||
assertEquals(annotation.findAttributeValue("from")?.expression?.evaluate(), 10)
|
||||
assertEquals(annotation.findAttributeValue("to")?.expression?.evaluate(), 0)
|
||||
assertEquals(annotation.findAttributeValue("from")?.evaluate(), 10)
|
||||
assertEquals(annotation.findAttributeValue("to")?.evaluate(), 0)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun testConvertStringTemplate() {
|
||||
doTest("StringTemplateInClass") { name, file ->
|
||||
val literalExpression = file.findElementByText<ULiteralExpression>("lorem")
|
||||
val psi = (literalExpression as PsiElementBacked).psi!!
|
||||
val psi = literalExpression.psi!!
|
||||
Assert.assertTrue(psi is KtLiteralStringTemplateEntry)
|
||||
val literalExpressionAgain = psi.toUElement()
|
||||
Assert.assertTrue(literalExpressionAgain is ULiteralExpression)
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<os family="windows"/>
|
||||
</condition>
|
||||
|
||||
<property name="uast.version" value="1.0.10"/>
|
||||
<property name="uast.version" value="1.0.11"/>
|
||||
|
||||
<property name="generators" value="${basedir}/generators"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user