Update to UAST 0.12
This commit is contained in:
+1
-1
@@ -102,7 +102,7 @@ class ResourceFoldingBuilder : FoldingBuilderEx() {
|
||||
|
||||
val element = getOutermostQualified() ?: this
|
||||
|
||||
(element.containingElement as? UCallExpression)?.run {
|
||||
(element.uastParent as? UCallExpression)?.run {
|
||||
if (isFoldableGetResourceValueCall()) {
|
||||
return getOutermostQualified()?.createFoldingDescriptor() ?: createFoldingDescriptor()
|
||||
}
|
||||
|
||||
@@ -2622,7 +2622,7 @@ public class LintDriver {
|
||||
return true;
|
||||
}
|
||||
|
||||
scope = scope.getContainingElement();
|
||||
scope = scope.getUastParent();
|
||||
if (scope instanceof PsiFile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ public class UElementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
cls = cls.getUastSuperClass();
|
||||
cls = cls.getSuperClass();
|
||||
depth++;
|
||||
if (depth == 500) {
|
||||
// Shouldn't happen in practice; this prevents the IDE from
|
||||
|
||||
@@ -16,41 +16,6 @@
|
||||
|
||||
package com.android.tools.klint.detector.api;
|
||||
|
||||
import static com.android.SdkConstants.ANDROID_MANIFEST_XML;
|
||||
import static com.android.SdkConstants.ANDROID_PREFIX;
|
||||
import static com.android.SdkConstants.ANDROID_URI;
|
||||
import static com.android.SdkConstants.ATTR_LOCALE;
|
||||
import static com.android.SdkConstants.BIN_FOLDER;
|
||||
import static com.android.SdkConstants.DOT_GIF;
|
||||
import static com.android.SdkConstants.DOT_JPEG;
|
||||
import static com.android.SdkConstants.DOT_JPG;
|
||||
import static com.android.SdkConstants.DOT_PNG;
|
||||
import static com.android.SdkConstants.DOT_WEBP;
|
||||
import static com.android.SdkConstants.DOT_XML;
|
||||
import static com.android.SdkConstants.FN_BUILD_GRADLE;
|
||||
import static com.android.SdkConstants.ID_PREFIX;
|
||||
import static com.android.SdkConstants.NEW_ID_PREFIX;
|
||||
import static com.android.SdkConstants.TOOLS_URI;
|
||||
import static com.android.SdkConstants.UTF_8;
|
||||
import static com.android.ide.common.resources.configuration.FolderConfiguration.QUALIFIER_SPLITTER;
|
||||
import static com.android.ide.common.resources.configuration.LocaleQualifier.BCP_47_PREFIX;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_BOOLEAN;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_BOOLEAN_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_BYTE;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_BYTE_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_CHAR;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_CHARACTER_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_DOUBLE;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_DOUBLE_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_FLOAT;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_FLOAT_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_INT;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_INTEGER_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_LONG;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_LONG_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_SHORT;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_SHORT_WRAPPER;
|
||||
|
||||
import com.android.annotations.NonNull;
|
||||
import com.android.annotations.Nullable;
|
||||
import com.android.builder.model.AndroidProject;
|
||||
@@ -78,21 +43,14 @@ import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.PsiClassType;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiImportStatement;
|
||||
import com.intellij.psi.PsiLiteral;
|
||||
import com.intellij.psi.PsiParenthesizedExpression;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
|
||||
import org.jetbrains.uast.UElement;
|
||||
import org.jetbrains.uast.UParenthesizedExpression;
|
||||
import com.intellij.psi.*;
|
||||
import lombok.ast.ImportDeclaration;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.jetbrains.org.objectweb.asm.tree.ClassNode;
|
||||
import org.jetbrains.org.objectweb.asm.tree.FieldNode;
|
||||
import org.jetbrains.uast.UElement;
|
||||
import org.jetbrains.uast.UParenthesizedExpression;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
@@ -100,17 +58,15 @@ import org.w3c.dom.NodeList;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import lombok.ast.ImportDeclaration;
|
||||
import static com.android.SdkConstants.*;
|
||||
import static com.android.ide.common.resources.configuration.FolderConfiguration.QUALIFIER_SPLITTER;
|
||||
import static com.android.ide.common.resources.configuration.LocaleQualifier.BCP_47_PREFIX;
|
||||
import static com.android.tools.klint.client.api.JavaParser.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -1299,7 +1255,7 @@ public class LintUtils {
|
||||
@Nullable
|
||||
public static UElement skipParentheses(@Nullable UElement element) {
|
||||
while (element instanceof UParenthesizedExpression) {
|
||||
element = element.getContainingElement();
|
||||
element = element.getUastParent();
|
||||
}
|
||||
|
||||
return element;
|
||||
|
||||
@@ -179,7 +179,7 @@ public class AnnotationDetector extends Detector implements Detector.UastScanner
|
||||
}
|
||||
|
||||
if (FQCN_SUPPRESS_LINT.equals(type)) {
|
||||
UElement parent = annotation.getContainingElement();
|
||||
UElement parent = annotation.getUastParent();
|
||||
if (parent == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -218,8 +218,8 @@ public class AnnotationDetector extends Detector implements Detector.UastScanner
|
||||
} else if (type.startsWith(SUPPORT_ANNOTATIONS_PREFIX)) {
|
||||
if (CHECK_RESULT_ANNOTATION.equals(type)) {
|
||||
// Check that the return type of this method is not void!
|
||||
if (annotation.getContainingElement() instanceof UMethod) {
|
||||
UMethod method = (UMethod) annotation.getContainingElement();
|
||||
if (annotation.getUastParent() instanceof UMethod) {
|
||||
UMethod method = (UMethod) annotation.getUastParent();
|
||||
if (!method.isConstructor()
|
||||
&& PsiType.VOID.equals(method.getReturnType())) {
|
||||
mContext.report(ANNOTATION_USAGE, annotation.getPsi(),
|
||||
@@ -284,7 +284,7 @@ public class AnnotationDetector extends Detector implements Detector.UastScanner
|
||||
PERMISSION_ANNOTATION_WRITE.equals(type)) {
|
||||
// Check that if there are no arguments, this is specified on a parameter,
|
||||
// and conversely, on methods and fields there is a valid argument.
|
||||
if (annotation.getContainingElement() instanceof UMethod) {
|
||||
if (annotation.getUastParent() instanceof UMethod) {
|
||||
String value = PermissionRequirement.getAnnotationStringValue(annotation, ATTR_VALUE);
|
||||
String[] anyOf = PermissionRequirement.getAnnotationStringValues(annotation, ATTR_ANY_OF);
|
||||
String[] allOf = PermissionRequirement.getAnnotationStringValues(annotation, ATTR_ALL_OF);
|
||||
@@ -342,7 +342,7 @@ public class AnnotationDetector extends Detector implements Detector.UastScanner
|
||||
|
||||
private void checkTargetType(@NonNull UAnnotation node, @NonNull String type1,
|
||||
@Nullable String type2, boolean allowCollection) {
|
||||
UElement parent = node.getContainingElement();
|
||||
UElement parent = node.getUastParent();
|
||||
PsiType type;
|
||||
|
||||
if (parent instanceof UDeclarationsExpression) {
|
||||
|
||||
@@ -851,7 +851,7 @@ public class ApiDetector extends ResourceXmlDetector
|
||||
|
||||
// It's okay to reference the constant as a case constant (since that
|
||||
// code path won't be taken) or in a condition of an if statement
|
||||
UElement curr = node.getContainingElement();
|
||||
UElement curr = node.getUastParent();
|
||||
while (curr != null) {
|
||||
if (curr instanceof USwitchClauseExpression) {
|
||||
List<UExpression> caseValues = ((USwitchClauseExpression) curr).getCaseValues();
|
||||
@@ -869,7 +869,7 @@ public class ApiDetector extends ResourceXmlDetector
|
||||
} else if (curr instanceof UMethod || curr instanceof UClass) {
|
||||
break;
|
||||
}
|
||||
curr = curr.getContainingElement();
|
||||
curr = curr.getUastParent();
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -1536,7 +1536,7 @@ public class ApiDetector extends ResourceXmlDetector
|
||||
return targetApi;
|
||||
}
|
||||
}
|
||||
scope = scope.getContainingElement();
|
||||
scope = scope.getUastParent();
|
||||
if (scope instanceof PsiFile) {
|
||||
break;
|
||||
}
|
||||
@@ -1730,7 +1730,7 @@ public class ApiDetector extends ResourceXmlDetector
|
||||
int api,
|
||||
JavaContext context
|
||||
) {
|
||||
UElement current = element.getContainingElement();
|
||||
UElement current = element.getUastParent();
|
||||
UElement prev = element;
|
||||
while (current != null) {
|
||||
if (current instanceof UIfExpression) {
|
||||
@@ -1747,7 +1747,7 @@ public class ApiDetector extends ResourceXmlDetector
|
||||
return false;
|
||||
}
|
||||
prev = current;
|
||||
current = current.getContainingElement();
|
||||
current = current.getUastParent();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -16,36 +16,28 @@
|
||||
|
||||
package com.android.tools.klint.checks;
|
||||
|
||||
import static com.android.SdkConstants.CLASS_VIEW;
|
||||
import static com.android.SdkConstants.SUPPORT_ANNOTATIONS_PREFIX;
|
||||
import static com.android.tools.klint.checks.SupportAnnotationDetector.filterRelevantAnnotations;
|
||||
import static com.android.tools.klint.detector.api.LintUtils.skipParentheses;
|
||||
|
||||
import com.android.annotations.NonNull;
|
||||
import com.android.annotations.Nullable;
|
||||
import com.android.tools.klint.client.api.JavaEvaluator;
|
||||
import com.android.tools.klint.detector.api.Category;
|
||||
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.Location;
|
||||
import com.android.tools.klint.detector.api.Scope;
|
||||
import com.android.tools.klint.detector.api.Severity;
|
||||
import com.android.tools.klint.detector.api.*;
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
|
||||
import org.jetbrains.uast.UElement;
|
||||
import org.jetbrains.uast.UMethod;
|
||||
import org.jetbrains.uast.USuperExpression;
|
||||
import org.jetbrains.uast.UReferenceExpression;
|
||||
import org.jetbrains.uast.USuperExpression;
|
||||
import org.jetbrains.uast.visitor.AbstractUastVisitor;
|
||||
import org.jetbrains.uast.visitor.UastVisitor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.android.SdkConstants.CLASS_VIEW;
|
||||
import static com.android.SdkConstants.SUPPORT_ANNOTATIONS_PREFIX;
|
||||
import static com.android.tools.klint.checks.SupportAnnotationDetector.filterRelevantAnnotations;
|
||||
import static com.android.tools.klint.detector.api.LintUtils.skipParentheses;
|
||||
|
||||
/**
|
||||
* Makes sure that methods call super when overriding methods.
|
||||
*/
|
||||
@@ -185,7 +177,7 @@ public class CallSuperDetector extends Detector implements Detector.UastScanner
|
||||
|
||||
@Override
|
||||
public boolean visitSuperExpression(USuperExpression node) {
|
||||
UElement parent = skipParentheses(node.getContainingElement());
|
||||
UElement parent = skipParentheses(node.getUastParent());
|
||||
if (parent instanceof UReferenceExpression) {
|
||||
PsiElement resolved = ((UReferenceExpression) parent).resolve();
|
||||
if (mMethod.equals(resolved)) {
|
||||
|
||||
@@ -16,54 +16,16 @@
|
||||
|
||||
package com.android.tools.klint.checks;
|
||||
|
||||
import static com.android.SdkConstants.CLASS_CONTENTPROVIDER;
|
||||
import static com.android.SdkConstants.CLASS_CONTEXT;
|
||||
import static com.android.tools.klint.detector.api.LintUtils.skipParentheses;
|
||||
import static org.jetbrains.uast.UastUtils.getOutermostQualified;
|
||||
import static org.jetbrains.uast.UastUtils.getParentOfType;
|
||||
import static org.jetbrains.uast.UastUtils.getQualifiedChain;
|
||||
|
||||
import com.android.SdkConstants;
|
||||
import com.android.annotations.NonNull;
|
||||
import com.android.annotations.Nullable;
|
||||
import com.android.tools.klint.client.api.JavaEvaluator;
|
||||
import com.android.tools.klint.detector.api.Category;
|
||||
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.Location;
|
||||
import com.android.tools.klint.detector.api.Scope;
|
||||
import com.android.tools.klint.detector.api.Severity;
|
||||
import com.android.tools.klint.detector.api.*;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiClassType;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiLocalVariable;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.util.containers.Predicate;
|
||||
import org.jetbrains.uast.UBinaryExpression;
|
||||
import org.jetbrains.uast.UCallExpression;
|
||||
import org.jetbrains.uast.UDoWhileExpression;
|
||||
import org.jetbrains.uast.UElement;
|
||||
import org.jetbrains.uast.UExpression;
|
||||
import org.jetbrains.uast.UField;
|
||||
import org.jetbrains.uast.UIfExpression;
|
||||
import org.jetbrains.uast.ULocalVariable;
|
||||
import org.jetbrains.uast.UMethod;
|
||||
import org.jetbrains.uast.UQualifiedReferenceExpression;
|
||||
import org.jetbrains.uast.UReturnExpression;
|
||||
import org.jetbrains.uast.UUnaryExpression;
|
||||
import org.jetbrains.uast.UVariable;
|
||||
import org.jetbrains.uast.UWhileExpression;
|
||||
import org.jetbrains.uast.UastCallKind;
|
||||
import org.jetbrains.uast.UastUtils;
|
||||
import org.jetbrains.uast.UReferenceExpression;
|
||||
import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.util.UastExpressionUtils;
|
||||
import org.jetbrains.uast.visitor.AbstractUastVisitor;
|
||||
import org.jetbrains.uast.visitor.UastVisitor;
|
||||
@@ -71,6 +33,11 @@ import org.jetbrains.uast.visitor.UastVisitor;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.android.SdkConstants.CLASS_CONTENTPROVIDER;
|
||||
import static com.android.SdkConstants.CLASS_CONTEXT;
|
||||
import static com.android.tools.klint.detector.api.LintUtils.skipParentheses;
|
||||
import static org.jetbrains.uast.UastUtils.*;
|
||||
|
||||
/**
|
||||
* Checks for missing {@code recycle} calls on resources that encourage it, and
|
||||
* for missing {@code commit} calls on FragmentTransactions, etc.
|
||||
@@ -718,10 +685,10 @@ public class CleanupDetector extends Detector implements Detector.UastScanner {
|
||||
// apply if the return value is not considered
|
||||
|
||||
UElement qualifiedNode = node;
|
||||
UElement parent = skipParentheses(node.getContainingElement());
|
||||
UElement parent = skipParentheses(node.getUastParent());
|
||||
while (parent instanceof UReferenceExpression) {
|
||||
qualifiedNode = parent;
|
||||
parent = skipParentheses(parent.getContainingElement());
|
||||
parent = skipParentheses(parent.getUastParent());
|
||||
}
|
||||
boolean returnValueIgnored = true;
|
||||
|
||||
@@ -761,7 +728,7 @@ public class CleanupDetector extends Detector implements Detector.UastScanner {
|
||||
public static PsiVariable getVariableElement(@NonNull UCallExpression rhs,
|
||||
boolean allowChainedCalls) {
|
||||
UElement parent = skipParentheses(
|
||||
UastUtils.getQualifiedParentOrThis(rhs).getContainingElement());
|
||||
UastUtils.getQualifiedParentOrThis(rhs).getUastParent());
|
||||
|
||||
// Handle some types of chained calls; e.g. you might have
|
||||
// var = prefs.edit().put(key,value)
|
||||
@@ -769,9 +736,9 @@ public class CleanupDetector extends Detector implements Detector.UastScanner {
|
||||
if (allowChainedCalls) {
|
||||
while (true) {
|
||||
if ((parent instanceof UQualifiedReferenceExpression)) {
|
||||
UElement parentParent = skipParentheses(parent.getContainingElement());
|
||||
UElement parentParent = skipParentheses(parent.getUastParent());
|
||||
if ((parentParent instanceof UQualifiedReferenceExpression)) {
|
||||
parent = skipParentheses(parentParent.getContainingElement());
|
||||
parent = skipParentheses(parentParent.getUastParent());
|
||||
} else if (parentParent instanceof UVariable
|
||||
|| parentParent instanceof UBinaryExpression) {
|
||||
parent = parentParent;
|
||||
|
||||
+6
-21
@@ -16,36 +16,21 @@
|
||||
|
||||
package com.android.tools.klint.checks;
|
||||
|
||||
import static com.android.SdkConstants.CLASS_CONTEXT;
|
||||
import static com.android.SdkConstants.CLASS_VIEW;
|
||||
import static com.android.SdkConstants.CLASS_VIEWGROUP;
|
||||
import static com.android.SdkConstants.DOT_LAYOUT_PARAMS;
|
||||
import static com.android.SdkConstants.R_STYLEABLE_PREFIX;
|
||||
import static com.android.tools.klint.detector.api.LintUtils.skipParentheses;
|
||||
|
||||
import com.android.annotations.NonNull;
|
||||
import com.android.annotations.Nullable;
|
||||
import com.android.tools.klint.detector.api.Category;
|
||||
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.Scope;
|
||||
import com.android.tools.klint.detector.api.Severity;
|
||||
import com.android.tools.klint.detector.api.*;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
|
||||
import org.jetbrains.uast.UCallExpression;
|
||||
import org.jetbrains.uast.UClass;
|
||||
import org.jetbrains.uast.UExpression;
|
||||
import org.jetbrains.uast.UMethod;
|
||||
import org.jetbrains.uast.UastUtils;
|
||||
import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.visitor.UastVisitor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.android.SdkConstants.*;
|
||||
import static com.android.tools.klint.detector.api.LintUtils.skipParentheses;
|
||||
|
||||
/**
|
||||
* Makes sure that custom views use a declare styleable that matches
|
||||
* the name of the custom view
|
||||
@@ -89,7 +74,7 @@ public class CustomViewDetector extends Detector implements Detector.UastScanner
|
||||
@Override
|
||||
public void visitMethod(@NonNull JavaContext context, @Nullable UastVisitor visitor,
|
||||
@NonNull UCallExpression node, @NonNull UMethod method) {
|
||||
if (skipParentheses(node.getContainingElement()) instanceof UExpression) {
|
||||
if (skipParentheses(node.getUastParent()) instanceof UExpression) {
|
||||
if (!context.getEvaluator().isMemberInSubClassOf(method, CLASS_CONTEXT, false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public class CutPasteDetector extends Detector implements Detector.UastScanner {
|
||||
|
||||
@Nullable
|
||||
private static String getLhs(@NonNull UCallExpression call) {
|
||||
UElement parent = call.getContainingElement();
|
||||
UElement parent = call.getUastParent();
|
||||
while (parent != null && !(parent instanceof UBlockExpression)) {
|
||||
if (parent instanceof ULocalVariable) {
|
||||
return ((ULocalVariable) parent).getName();
|
||||
@@ -152,7 +152,7 @@ public class CutPasteDetector extends Detector implements Detector.UastScanner {
|
||||
return aa.getReceiver().asSourceString();
|
||||
}
|
||||
}
|
||||
parent = parent.getContainingElement();
|
||||
parent = parent.getUastParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -291,7 +291,7 @@ public class CutPasteDetector extends Detector implements Detector.UastScanner {
|
||||
}
|
||||
|
||||
private static UExpression getBreakedExpression(UBreakExpression node) {
|
||||
UElement parent = node.getContainingElement();
|
||||
UElement parent = node.getUastParent();
|
||||
String label = node.getLabel();
|
||||
while (parent != null) {
|
||||
if (label != null) {
|
||||
@@ -306,13 +306,13 @@ public class CutPasteDetector extends Detector implements Detector.UastScanner {
|
||||
return (UExpression) parent;
|
||||
}
|
||||
}
|
||||
parent = parent.getContainingElement();
|
||||
parent = parent.getUastParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static UExpression getContinuedExpression(UContinueExpression node) {
|
||||
UElement parent = node.getContainingElement();
|
||||
UElement parent = node.getUastParent();
|
||||
String label = node.getLabel();
|
||||
while (parent != null) {
|
||||
if (label != null) {
|
||||
@@ -327,7 +327,7 @@ public class CutPasteDetector extends Detector implements Detector.UastScanner {
|
||||
return (UExpression) parent;
|
||||
}
|
||||
}
|
||||
parent = parent.getContainingElement();
|
||||
parent = parent.getUastParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+9
-39
@@ -16,51 +16,17 @@
|
||||
|
||||
package com.android.tools.klint.checks;
|
||||
|
||||
import static com.android.SdkConstants.SUPPORT_LIB_ARTIFACT;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_BOOLEAN;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_BOOLEAN_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_BYTE_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_CHARACTER_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_DOUBLE_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_FLOAT_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_INT;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_INTEGER_WRAPPER;
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_LONG_WRAPPER;
|
||||
import static com.android.tools.klint.detector.api.LintUtils.skipParentheses;
|
||||
|
||||
import com.android.annotations.NonNull;
|
||||
import com.android.annotations.Nullable;
|
||||
import com.android.tools.klint.client.api.JavaEvaluator;
|
||||
import com.android.tools.klint.detector.api.Category;
|
||||
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.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.google.common.collect.Sets;
|
||||
import com.google.common.collect.Sets.SetView;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiType;
|
||||
|
||||
import org.jetbrains.uast.UBinaryExpression;
|
||||
import org.jetbrains.uast.UCallExpression;
|
||||
import org.jetbrains.uast.UElement;
|
||||
import org.jetbrains.uast.UExpression;
|
||||
import org.jetbrains.uast.UIfExpression;
|
||||
import org.jetbrains.uast.UMethod;
|
||||
import org.jetbrains.uast.UParenthesizedExpression;
|
||||
import org.jetbrains.uast.UPrefixExpression;
|
||||
import org.jetbrains.uast.UQualifiedReferenceExpression;
|
||||
import org.jetbrains.uast.USimpleNameReferenceExpression;
|
||||
import org.jetbrains.uast.USuperExpression;
|
||||
import org.jetbrains.uast.UThisExpression;
|
||||
import org.jetbrains.uast.UThrowExpression;
|
||||
import org.jetbrains.uast.UastUtils;
|
||||
import org.jetbrains.uast.UReferenceExpression;
|
||||
import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.util.UastExpressionUtils;
|
||||
import org.jetbrains.uast.visitor.AbstractUastVisitor;
|
||||
import org.jetbrains.uast.visitor.UastVisitor;
|
||||
@@ -70,6 +36,10 @@ import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static com.android.SdkConstants.SUPPORT_LIB_ARTIFACT;
|
||||
import static com.android.tools.klint.client.api.JavaParser.*;
|
||||
import static com.android.tools.klint.detector.api.LintUtils.skipParentheses;
|
||||
|
||||
/**
|
||||
* Looks for performance issues in Java files, such as memory allocations during
|
||||
* drawing operations and using HashMap instead of SparseArray.
|
||||
@@ -237,7 +207,7 @@ public class JavaPerformanceDetector extends Detector implements Detector.UastSc
|
||||
}
|
||||
|
||||
if (mFlagAllocations
|
||||
&& !(skipParentheses(node.getContainingElement()) instanceof UThrowExpression)
|
||||
&& !(skipParentheses(node.getUastParent()) instanceof UThrowExpression)
|
||||
&& mCheckAllocations) {
|
||||
// Make sure we're still inside the method declaration that marked
|
||||
// mInDraw as true, in case we've left it and we're in a static
|
||||
@@ -316,7 +286,7 @@ public class JavaPerformanceDetector extends Detector implements Detector.UastSc
|
||||
* </pre>
|
||||
*/
|
||||
private static boolean isLazilyInitialized(UElement node) {
|
||||
UElement curr = node.getContainingElement();
|
||||
UElement curr = node.getUastParent();
|
||||
while (curr != null) {
|
||||
if (curr instanceof UMethod) {
|
||||
return false;
|
||||
@@ -347,7 +317,7 @@ public class JavaPerformanceDetector extends Detector implements Detector.UastSc
|
||||
return false;
|
||||
|
||||
}
|
||||
curr = curr.getContainingElement();
|
||||
curr = curr.getUastParent();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -16,36 +16,18 @@
|
||||
|
||||
package com.android.tools.klint.checks;
|
||||
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_STRING;
|
||||
|
||||
import com.android.annotations.NonNull;
|
||||
import com.android.annotations.Nullable;
|
||||
import com.android.tools.klint.client.api.JavaEvaluator;
|
||||
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.Location;
|
||||
import com.android.tools.klint.detector.api.Scope;
|
||||
import com.android.tools.klint.detector.api.Severity;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.psi.PsiParameterList;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
|
||||
import com.android.tools.klint.detector.api.*;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.visitor.UastVisitor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static com.android.tools.klint.client.api.JavaParser.TYPE_STRING;
|
||||
|
||||
/**
|
||||
* Detector for finding inefficiencies and errors in logging calls.
|
||||
@@ -142,7 +124,7 @@ public class LogDetector extends Detector implements Detector.UastScanner {
|
||||
|
||||
String name = method.getName();
|
||||
boolean withinConditional = IS_LOGGABLE.equals(name) ||
|
||||
checkWithinConditional(context, node.getContainingElement(), node);
|
||||
checkWithinConditional(context, node.getUastParent(), node);
|
||||
|
||||
// See if it's surrounded by an if statement (and it's one of the non-error, spammy
|
||||
// log methods (info, verbose, etc))
|
||||
@@ -249,7 +231,7 @@ public class LogDetector extends Detector implements Detector.UastScanner {
|
||||
|| curr instanceof UClass) { // static block
|
||||
break;
|
||||
}
|
||||
curr = curr.getContainingElement();
|
||||
curr = curr.getUastParent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+5
-18
@@ -17,28 +17,13 @@
|
||||
package com.android.tools.klint.checks;
|
||||
|
||||
|
||||
import static com.android.tools.klint.checks.CutPasteDetector.isReachableFrom;
|
||||
|
||||
import com.android.annotations.NonNull;
|
||||
import com.android.annotations.Nullable;
|
||||
import com.android.tools.klint.client.api.JavaEvaluator;
|
||||
import com.android.tools.klint.detector.api.Category;
|
||||
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.Scope;
|
||||
import com.android.tools.klint.detector.api.Severity;
|
||||
import com.android.tools.klint.detector.api.*;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiLocalVariable;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.util.UastExpressionUtils;
|
||||
import org.jetbrains.uast.visitor.AbstractUastVisitor;
|
||||
@@ -47,6 +32,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.android.tools.klint.checks.CutPasteDetector.isReachableFrom;
|
||||
|
||||
/**
|
||||
* Checks related to RecyclerView usage.
|
||||
*/
|
||||
@@ -171,7 +158,7 @@ public class RecyclerViewDetector extends Detector implements Detector.UastScann
|
||||
// want
|
||||
UExpression statement = UastUtils.getParentOfType(reference, UExpression.class, true);
|
||||
if (statement != null) {
|
||||
parentToChildren.put(statement.getContainingElement(), reference);
|
||||
parentToChildren.put(statement.getUastParent(), reference);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ public class ServiceCastDetector extends Detector implements Detector.UastScanne
|
||||
public void visitMethod(@NonNull JavaContext context, @Nullable UastVisitor visitor,
|
||||
@NonNull UCallExpression call, @NonNull UMethod method) {
|
||||
UElement parent = LintUtils.skipParentheses(
|
||||
UastUtils.getQualifiedParentOrThis(call).getContainingElement());
|
||||
UastUtils.getQualifiedParentOrThis(call).getUastParent());
|
||||
if (UastExpressionUtils.isTypeCast(parent)) {
|
||||
UBinaryExpressionWithType cast = (UBinaryExpressionWithType) parent;
|
||||
|
||||
|
||||
+1
-1
@@ -734,7 +734,7 @@ public class SupportAnnotationDetector extends Detector implements Detector.Uast
|
||||
}
|
||||
|
||||
private static boolean isExpressionValueUnused(UExpression expression) {
|
||||
return getQualifiedParentOrThis(expression).getContainingElement()
|
||||
return getQualifiedParentOrThis(expression).getUastParent()
|
||||
instanceof UBlockExpression;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,6 @@
|
||||
|
||||
package com.android.tools.klint.checks;
|
||||
|
||||
import static com.android.SdkConstants.ANDROID_URI;
|
||||
import static com.android.SdkConstants.ATTR_CLASS;
|
||||
import static com.android.SdkConstants.ATTR_ID;
|
||||
import static com.android.SdkConstants.DOT_XML;
|
||||
import static com.android.SdkConstants.ID_PREFIX;
|
||||
import static com.android.SdkConstants.NEW_ID_PREFIX;
|
||||
import static com.android.SdkConstants.VIEW_TAG;
|
||||
|
||||
import com.android.annotations.NonNull;
|
||||
import com.android.annotations.Nullable;
|
||||
import com.android.ide.common.res2.AbstractResourceRepository;
|
||||
@@ -33,51 +25,20 @@ import com.android.ide.common.resources.ResourceUrl;
|
||||
import com.android.resources.ResourceFolderType;
|
||||
import com.android.resources.ResourceType;
|
||||
import com.android.tools.klint.client.api.LintClient;
|
||||
import com.android.tools.klint.detector.api.Category;
|
||||
import com.android.tools.klint.detector.api.Context;
|
||||
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.LintUtils;
|
||||
import com.android.tools.klint.detector.api.ResourceEvaluator;
|
||||
import com.android.tools.klint.detector.api.ResourceXmlDetector;
|
||||
import com.android.tools.klint.detector.api.Scope;
|
||||
import com.android.tools.klint.detector.api.Severity;
|
||||
import com.android.tools.klint.detector.api.Speed;
|
||||
import com.android.tools.klint.detector.api.XmlContext;
|
||||
import com.android.tools.klint.detector.api.*;
|
||||
import com.android.utils.XmlUtils;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.*;
|
||||
import com.intellij.psi.PsiClassType;
|
||||
import com.intellij.psi.PsiType;
|
||||
|
||||
import org.jetbrains.uast.UBinaryExpressionWithType;
|
||||
import org.jetbrains.uast.UCallExpression;
|
||||
import org.jetbrains.uast.UElement;
|
||||
import org.jetbrains.uast.UExpression;
|
||||
import org.jetbrains.uast.UMethod;
|
||||
import org.jetbrains.uast.UParenthesizedExpression;
|
||||
import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.visitor.UastVisitor;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static com.android.SdkConstants.*;
|
||||
|
||||
/** Detector for finding inconsistent usage of views and casts
|
||||
* <p>
|
||||
@@ -189,11 +150,11 @@ public class ViewTypeDetector extends ResourceXmlDetector implements Detector.Ua
|
||||
}
|
||||
assert method.getName().equals("findViewById");
|
||||
UElement node = LintUtils.skipParentheses(call);
|
||||
while (node != null && node.getContainingElement() instanceof UParenthesizedExpression) {
|
||||
node = node.getContainingElement();
|
||||
while (node != null && node.getUastParent() instanceof UParenthesizedExpression) {
|
||||
node = node.getUastParent();
|
||||
}
|
||||
if (node.getContainingElement() instanceof UBinaryExpressionWithType) {
|
||||
UBinaryExpressionWithType cast = (UBinaryExpressionWithType) node.getContainingElement();
|
||||
if (node.getUastParent() instanceof UBinaryExpressionWithType) {
|
||||
UBinaryExpressionWithType cast = (UBinaryExpressionWithType) node.getUastParent();
|
||||
PsiType type = cast.getType();
|
||||
String castType = null;
|
||||
if (type instanceof PsiClassType) {
|
||||
|
||||
+1
-1
@@ -261,7 +261,7 @@ public class IntellijLintUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
element = element.getContainingElement();
|
||||
element = element.getUastParent();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.jetbrains.uast.*
|
||||
|
||||
class KotlinUAnnotation(
|
||||
override val psi: KtAnnotationEntry,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : UAnnotation {
|
||||
private val resolvedAnnotation by lz { psi.analyze()[BindingContext.ANNOTATION, psi] }
|
||||
|
||||
@@ -40,7 +40,7 @@ class KotlinUAnnotation(
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinUNamedExpression(override val name: String, override val containingElement: UElement?) : UNamedExpression {
|
||||
class KotlinUNamedExpression(override val name: String, override val uastParent: UElement?) : UNamedExpression {
|
||||
override lateinit var expression: UExpression
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUMethod
|
||||
|
||||
class KotlinUClass private constructor(
|
||||
psi: KtLightClass,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : AbstractJavaUClass(), PsiClass by psi {
|
||||
|
||||
val ktClass = psi.kotlinOrigin
|
||||
@@ -49,17 +49,21 @@ class KotlinUClass private constructor(
|
||||
override val uastAnchor: UElement
|
||||
get() = UIdentifier(psi.nameIdentifier, this)
|
||||
|
||||
override val uastNestedClasses: List<UClass> by lz {
|
||||
override fun getInnerClasses(): Array<UClass> {
|
||||
// filter DefaultImpls to avoid processing same methods from original interface multiple times
|
||||
// filter Enum entry classes to avoid duplication with PsiEnumConstant initializer class
|
||||
psi.innerClasses.filter {
|
||||
return psi.innerClasses.filter {
|
||||
it.name != JvmAbi.DEFAULT_IMPLS_CLASS_NAME && !it.isEnumEntryLightClass()
|
||||
}.map {
|
||||
getLanguagePlugin().convert<UClass>(it, this)
|
||||
}
|
||||
}.toTypedArray()
|
||||
}
|
||||
|
||||
override val uastMethods: List<UMethod> by lz {
|
||||
override fun getSuperClass(): UClass? = super.getSuperClass()
|
||||
override fun getFields(): Array<UField> = super.getFields()
|
||||
override fun getInitializers(): Array<UClassInitializer> = super.getInitializers()
|
||||
|
||||
override fun getMethods(): Array<UMethod> {
|
||||
val primaryConstructor = ktClass?.getPrimaryConstructor()?.toLightMethods()?.firstOrNull()
|
||||
val initBlocks = ktClass?.getAnonymousInitializers() ?: emptyList()
|
||||
|
||||
@@ -75,7 +79,7 @@ class KotlinUClass private constructor(
|
||||
override val psi: PsiElement?
|
||||
get() = null
|
||||
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
get() = containingMethod
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
@@ -96,10 +100,11 @@ class KotlinUClass private constructor(
|
||||
|
||||
fun isDelegatedMethod(psiMethod: PsiMethod) = psiMethod is KtLightMethod && psiMethod.isDelegated
|
||||
|
||||
psi.methods.asSequence()
|
||||
return psi.methods.asSequence()
|
||||
.filterNot(::isDelegatedMethod)
|
||||
.map(::createUMethod)
|
||||
.toList()
|
||||
.toTypedArray()
|
||||
}
|
||||
|
||||
private fun PsiClass.isEnumEntryLightClass() = (this as? KtLightClass)?.kotlinOrigin is KtEnumEntry
|
||||
@@ -116,7 +121,7 @@ class KotlinUClass private constructor(
|
||||
|
||||
class KotlinUAnonymousClass(
|
||||
psi: PsiAnonymousClass,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : AbstractJavaUClass(), UAnonymousClass, PsiAnonymousClass by psi {
|
||||
|
||||
override val psi: PsiAnonymousClass = unwrap<UAnonymousClass, PsiAnonymousClass>(psi)
|
||||
@@ -125,6 +130,12 @@ class KotlinUAnonymousClass(
|
||||
return super<AbstractJavaUClass>.getOriginalElement()
|
||||
}
|
||||
|
||||
override fun getSuperClass(): UClass? = super<AbstractJavaUClass>.getSuperClass()
|
||||
override fun getFields(): Array<UField> = super<AbstractJavaUClass>.getFields()
|
||||
override fun getMethods(): Array<UMethod> = super<AbstractJavaUClass>.getMethods()
|
||||
override fun getInitializers(): Array<UClassInitializer> = super<AbstractJavaUClass>.getInitializers()
|
||||
override fun getInnerClasses(): Array<UClass> = super<AbstractJavaUClass>.getInnerClasses()
|
||||
|
||||
override val uastAnchor: UElement?
|
||||
get() {
|
||||
val ktClassOrObject = (psi.originalElement as? KtLightClass)?.kotlinOrigin as? KtObjectDeclaration ?: return null
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ import org.jetbrains.uast.USimpleNameReferenceExpression
|
||||
|
||||
class KotlinUImportStatement(
|
||||
override val psi: KtImportDirective,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : UImportStatement {
|
||||
override val isOnDemand: Boolean
|
||||
get() = psi.isAllUnder
|
||||
@@ -47,7 +47,7 @@ class KotlinUImportStatement(
|
||||
private class ImportReference(
|
||||
override val psi: KtExpression,
|
||||
override val identifier: String,
|
||||
override val containingElement: UElement?,
|
||||
override val uastParent: UElement?,
|
||||
private val importDirective: KtImportDirective
|
||||
) : KotlinAbstractUExpression(), USimpleNameReferenceExpression {
|
||||
override val resolvedName: String?
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.jetbrains.uast.kotlin.*
|
||||
|
||||
open class KotlinUMethod(
|
||||
psi: KtLightMethod,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : UMethod, JavaUElementWithComments, PsiMethod by psi {
|
||||
override val psi: KtLightMethod = unwrap<UMethod, KtLightMethod>(psi)
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ abstract class AbstractKotlinUVariable : AbstractJavaUVariable() {
|
||||
|
||||
class KotlinUVariable(
|
||||
psi: PsiVariable,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : AbstractKotlinUVariable(), UVariable, PsiVariable by psi {
|
||||
override val psi = unwrap<UVariable, PsiVariable>(psi)
|
||||
|
||||
@@ -81,7 +81,7 @@ class KotlinUVariable(
|
||||
|
||||
open class KotlinUParameter(
|
||||
psi: PsiParameter,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : AbstractKotlinUVariable(), UParameter, PsiParameter by psi {
|
||||
|
||||
override val psi = unwrap<UParameter, PsiParameter>(psi)
|
||||
@@ -97,7 +97,7 @@ open class KotlinUParameter(
|
||||
|
||||
open class KotlinUField(
|
||||
psi: PsiField,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : AbstractKotlinUVariable(), UField, PsiField by psi {
|
||||
|
||||
override val psi = unwrap<UField, PsiField>(psi)
|
||||
@@ -113,7 +113,7 @@ open class KotlinUField(
|
||||
|
||||
open class KotlinULocalVariable(
|
||||
psi: PsiLocalVariable,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : AbstractKotlinUVariable(), ULocalVariable, PsiLocalVariable by psi {
|
||||
|
||||
override val psi = unwrap<ULocalVariable, PsiLocalVariable>(psi)
|
||||
@@ -130,7 +130,7 @@ open class KotlinULocalVariable(
|
||||
|
||||
open class KotlinUEnumConstant(
|
||||
psi: PsiEnumConstant,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : AbstractKotlinUVariable(), UEnumConstant, PsiEnumConstant by psi {
|
||||
override val initializingClass: UClass? by lz { getLanguagePlugin().convertOpt<UClass>(psi.initializingClass, this) }
|
||||
|
||||
@@ -177,7 +177,7 @@ open class KotlinUEnumConstant(
|
||||
|
||||
private class KotlinEnumConstantClassReference(
|
||||
override val psi: PsiEnumConstant,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : JavaAbstractUExpression(), USimpleNameReferenceExpression {
|
||||
override fun resolve() = psi.containingClass
|
||||
override val resolvedName: String?
|
||||
|
||||
@@ -14,7 +14,7 @@ private fun createVariableReferenceExpression(variable: UVariable, containingEle
|
||||
object : USimpleNameReferenceExpression {
|
||||
override val psi: PsiElement? = null
|
||||
override fun resolve(): PsiElement? = variable
|
||||
override val containingElement: UElement? = containingElement
|
||||
override val uastParent: UElement? = containingElement
|
||||
override val resolvedName: String? = variable.name
|
||||
override val annotations: List<UAnnotation> = emptyList()
|
||||
override val identifier: String = variable.name.orAnonymous()
|
||||
@@ -23,7 +23,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 uastParent: UElement? = containingElement
|
||||
override val value: Any? = null
|
||||
override val annotations: List<UAnnotation> = emptyList()
|
||||
}
|
||||
@@ -31,7 +31,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 uastParent: UElement? = containingElement
|
||||
override val leftOperand: UExpression by lz { createVariableReferenceExpression(variable, this) }
|
||||
override val rightOperand: UExpression by lz { createNullLiteralExpression(this) }
|
||||
override val operator: UastBinaryOperator = UastBinaryOperator.NOT_EQUALS
|
||||
@@ -53,7 +53,7 @@ private fun createElvisExpressions(
|
||||
|
||||
val ifExpression = object : UIfExpression {
|
||||
override val psi: PsiElement? = null
|
||||
override val containingElement: UElement? = containingElement
|
||||
override val uastParent: UElement? = containingElement
|
||||
override val condition: UExpression by lz { createNotEqWithNullExpression(tempVariable, this) }
|
||||
override val thenExpression: UExpression? by lz { createVariableReferenceExpression(tempVariable, this) }
|
||||
override val elseExpression: UExpression? by lz { KotlinConverter.convertExpression(right, this) }
|
||||
@@ -73,7 +73,7 @@ fun createElvisExpression(elvisExpression: KtBinaryExpression, containingElement
|
||||
return object : UExpressionList, KotlinEvaluatableUElement, KotlinUElementWithType {
|
||||
override val psi: PsiElement? = elvisExpression
|
||||
override val kind = KotlinSpecialExpressionKinds.ELVIS
|
||||
override val containingElement: UElement? = containingElement
|
||||
override val uastParent: UElement? = containingElement
|
||||
override val annotations: List<UAnnotation> = emptyList()
|
||||
override val expressions: List<UExpression> by lz {
|
||||
createElvisExpressions(left, right, this, elvisExpression.parent)
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.jetbrains.uast.UastBinaryOperator
|
||||
|
||||
class KotlinStringTemplateUPolyadicExpression(
|
||||
override val psi: KtStringTemplateExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(),
|
||||
UPolyadicExpression,
|
||||
KotlinUElementWithType,
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.uast.UElement
|
||||
|
||||
class KotlinUArrayAccessExpression(
|
||||
override val psi: KtArrayAccessExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : 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
-2
@@ -28,7 +28,7 @@ import org.jetbrains.uast.*
|
||||
|
||||
class KotlinUBinaryExpression(
|
||||
override val psi: KtBinaryExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UBinaryExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
private companion object {
|
||||
val BITWISE_OPERATORS = mapOf(
|
||||
@@ -88,7 +88,7 @@ class KotlinUBinaryExpression(
|
||||
|
||||
class KotlinCustomUBinaryExpression(
|
||||
override val psi: PsiElement,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UBinaryExpression {
|
||||
lateinit override var leftOperand: UExpression
|
||||
internal set
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ import org.jetbrains.uast.*
|
||||
|
||||
class KotlinUBinaryExpressionWithType(
|
||||
override val psi: KtBinaryExpressionWithTypeRHS,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UBinaryExpressionWithType,
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
|
||||
@@ -44,7 +44,7 @@ class KotlinUBinaryExpressionWithType(
|
||||
|
||||
class KotlinCustomUBinaryExpressionWithType(
|
||||
override val psi: PsiElement,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UBinaryExpressionWithType {
|
||||
lateinit override var operand: UExpression
|
||||
internal set
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.uast.UElement
|
||||
|
||||
class KotlinUBlockExpression(
|
||||
override val psi: KtBlockExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UBlockExpression, KotlinUElementWithType {
|
||||
override val expressions by lz { psi.statements.map { KotlinConverter.convertOrEmpty(it, this) } }
|
||||
}
|
||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.uast.kotlin.KotlinAbstractUExpression
|
||||
|
||||
class KotlinUBreakExpression(
|
||||
override val psi: KtBreakExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UBreakExpression {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ import org.jetbrains.uast.UExpression
|
||||
|
||||
class KotlinUCallableReferenceExpression(
|
||||
override val psi: KtCallableReferenceExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UCallableReferenceExpression, KotlinUElementWithType {
|
||||
override val qualifierExpression: UExpression?
|
||||
get() {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
|
||||
class KotlinUCatchClause(
|
||||
override val psi: KtCatchClause,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUElement(), UCatchClause {
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.catchBody, this) }
|
||||
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.jetbrains.uast.UExpression
|
||||
|
||||
class KotlinUClassLiteralExpression(
|
||||
override val psi: KtClassLiteralExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UClassLiteralExpression, KotlinUElementWithType {
|
||||
override val type by lz {
|
||||
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.uast.kotlin.KotlinAbstractUExpression
|
||||
|
||||
class KotlinUContinueExpression(
|
||||
override val psi: KtContinueExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UContinueExpression {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.uast.kotlin.KotlinAbstractUExpression
|
||||
|
||||
class KotlinUDeclarationsExpression(
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UDeclarationsExpression {
|
||||
override val psi: PsiElement?
|
||||
get() = null
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.uast.UIdentifier
|
||||
|
||||
class KotlinUDoWhileExpression(
|
||||
override val psi: KtDoWhileExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UDoWhileExpression {
|
||||
override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) }
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) }
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import org.jetbrains.uast.UastSpecialExpressionKind
|
||||
open class KotlinUExpressionList(
|
||||
override val psi: PsiElement?,
|
||||
override val kind: UastSpecialExpressionKind, // original element
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UExpressionList, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override lateinit var expressions: List<UExpression>
|
||||
internal set
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import org.jetbrains.uast.psi.UastPsiParameterNotResolved
|
||||
|
||||
class KotlinUForEachExpression(
|
||||
override val psi: KtForExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UForEachExpression {
|
||||
override val iteratedValue by lz { KotlinConverter.convertOrEmpty(psi.loopRange, this) }
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) }
|
||||
|
||||
+3
-3
@@ -34,7 +34,7 @@ import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
class KotlinUFunctionCallExpression(
|
||||
override val psi: KtCallExpression,
|
||||
override val containingElement: UElement?,
|
||||
override val uastParent: UElement?,
|
||||
private val _resolvedCall: ResolvedCall<*>? = null
|
||||
) : KotlinAbstractUExpression(), UCallExpression, KotlinUElementWithType {
|
||||
companion object {
|
||||
@@ -96,8 +96,8 @@ class KotlinUFunctionCallExpression(
|
||||
|
||||
override val receiver: UExpression?
|
||||
get() {
|
||||
return if (containingElement is UQualifiedReferenceExpression && containingElement.selector == this)
|
||||
containingElement.receiver
|
||||
return if (uastParent is UQualifiedReferenceExpression && uastParent.selector == this)
|
||||
uastParent.receiver
|
||||
else
|
||||
null
|
||||
}
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.uast.UIfExpression
|
||||
|
||||
class KotlinUIfExpression(
|
||||
override val psi: KtIfExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UIfExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) }
|
||||
override val thenExpression by lz { KotlinConverter.convertOrNull(psi.then, this) }
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.uast.ULabeledExpression
|
||||
|
||||
class KotlinULabeledExpression(
|
||||
override val psi: KtLabeledExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), ULabeledExpression {
|
||||
override val label: String
|
||||
get() = psi.getLabelName().orAnonymous("label")
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ import org.jetbrains.uast.withMargin
|
||||
|
||||
class KotlinULambdaExpression(
|
||||
override val psi: KtLambdaExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), ULambdaExpression, KotlinUElementWithType {
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.bodyExpression, this) }
|
||||
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ import org.jetbrains.uast.ULiteralExpression
|
||||
|
||||
class KotlinULiteralExpression(
|
||||
override val psi: KtConstantExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), ULiteralExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val isNull: Boolean
|
||||
get() = psi.unwrapBlockOrParenthesis().node?.elementType == KtNodeTypes.NULL
|
||||
@@ -35,7 +35,7 @@ class KotlinULiteralExpression(
|
||||
|
||||
class KotlinStringULiteralExpression(
|
||||
override val psi: PsiElement,
|
||||
override val containingElement: UElement?,
|
||||
override val uastParent: UElement?,
|
||||
val text: String? = null
|
||||
) : KotlinAbstractUExpression(), ULiteralExpression, KotlinUElementWithType{
|
||||
override val value: String
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ import org.jetbrains.uast.*
|
||||
|
||||
class KotlinUObjectLiteralExpression(
|
||||
override val psi: KtObjectLiteralExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UObjectLiteralExpression, KotlinUElementWithType {
|
||||
override val declaration by lz { getLanguagePlugin().convert<UClass>(psi.objectDeclaration.toLightClass()!!, this) }
|
||||
|
||||
@@ -57,7 +57,7 @@ class KotlinUObjectLiteralExpression(
|
||||
|
||||
private class ObjectLiteralClassReference(
|
||||
override val psi: KtSuperTypeCallEntry,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUElement(), USimpleNameReferenceExpression {
|
||||
override fun resolve() = (psi.resolveCallToDeclaration(this) as? PsiMethod)?.containingClass
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.uast.UParenthesizedExpression
|
||||
|
||||
class KotlinUParenthesizedExpression(
|
||||
override val psi: KtParenthesizedExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UParenthesizedExpression, KotlinUElementWithType {
|
||||
override val expression by lz { KotlinConverter.convertOrEmpty(psi.expression, this) }
|
||||
}
|
||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.uast.*
|
||||
|
||||
class KotlinUPostfixExpression(
|
||||
override val psi: KtPostfixExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UPostfixExpression, KotlinUElementWithType, KotlinEvaluatableUElement, UResolvable {
|
||||
override val operand by lz { KotlinConverter.convertOrEmpty(psi.baseExpression, this) }
|
||||
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import org.jetbrains.uast.UastPrefixOperator
|
||||
|
||||
class KotlinUPrefixExpression(
|
||||
override val psi: KtPrefixExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UPrefixExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val operand by lz { KotlinConverter.convertOrEmpty(psi.baseExpression, this) }
|
||||
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ import org.jetbrains.uast.UastQualifiedExpressionAccessType
|
||||
|
||||
class KotlinUQualifiedReferenceExpression(
|
||||
override val psi: KtDotQualifiedExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UQualifiedReferenceExpression,
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) }
|
||||
@@ -43,7 +43,7 @@ class KotlinUQualifiedReferenceExpression(
|
||||
|
||||
class KotlinUComponentQualifiedReferenceExpression(
|
||||
override val psi: KtDestructuringDeclarationEntry,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UQualifiedReferenceExpression,
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val accessType = UastQualifiedExpressionAccessType.SIMPLE
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.uast.UReturnExpression
|
||||
|
||||
class KotlinUReturnExpression(
|
||||
override val psi: KtReturnExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UReturnExpression, KotlinUElementWithType {
|
||||
override val returnExpression by lz { KotlinConverter.convertOrNull(psi.returnedExpression, this) }
|
||||
}
|
||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.uast.UQualifiedReferenceExpression
|
||||
|
||||
class KotlinUSafeQualifiedExpression(
|
||||
override val psi: KtSafeQualifiedExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UQualifiedReferenceExpression,
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) }
|
||||
|
||||
+6
-6
@@ -36,7 +36,7 @@ import org.jetbrains.uast.visitor.UastVisitor
|
||||
open class KotlinUSimpleReferenceExpression(
|
||||
override val psi: KtSimpleNameExpression,
|
||||
override val identifier: String,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), USimpleNameReferenceExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
private val resolvedDeclaration by lz { psi.resolveCallToDeclaration(this) }
|
||||
|
||||
@@ -90,7 +90,7 @@ open class KotlinUSimpleReferenceExpression(
|
||||
|
||||
class KotlinAccessorCallExpression(
|
||||
override val psi: KtElement,
|
||||
override val containingElement: KotlinUSimpleReferenceExpression,
|
||||
override val uastParent: KotlinUSimpleReferenceExpression,
|
||||
private val resolvedCall: ResolvedCall<*>,
|
||||
private val accessorDescriptor: DeclarationDescriptor,
|
||||
val setterValue: KtExpression?
|
||||
@@ -100,7 +100,7 @@ open class KotlinUSimpleReferenceExpression(
|
||||
|
||||
override val receiver: UExpression?
|
||||
get() {
|
||||
val containingElement = containingElement.containingElement
|
||||
val containingElement = uastParent.uastParent
|
||||
return if (containingElement is UQualifiedReferenceExpression && containingElement.selector == this)
|
||||
containingElement.receiver
|
||||
else
|
||||
@@ -116,7 +116,7 @@ open class KotlinUSimpleReferenceExpression(
|
||||
}
|
||||
|
||||
override val methodIdentifier: UIdentifier?
|
||||
get() = UIdentifier(containingElement.psi, this)
|
||||
get() = UIdentifier(uastParent.psi, this)
|
||||
|
||||
override val classReference: UReferenceExpression?
|
||||
get() = null
|
||||
@@ -184,7 +184,7 @@ open class KotlinUSimpleReferenceExpression(
|
||||
class KotlinClassViaConstructorUSimpleReferenceExpression(
|
||||
override val psi: KtCallExpression,
|
||||
override val identifier: String,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), USimpleNameReferenceExpression, KotlinUElementWithType {
|
||||
override val resolvedName: String?
|
||||
get() = (psi.getResolvedCall(psi.analyze())?.resultingDescriptor as? ConstructorDescriptor)
|
||||
@@ -200,7 +200,7 @@ class KotlinClassViaConstructorUSimpleReferenceExpression(
|
||||
|
||||
class KotlinStringUSimpleReferenceExpression(
|
||||
override val identifier: String,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), USimpleNameReferenceExpression {
|
||||
override val psi: PsiElement?
|
||||
get() = null
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.jetbrains.uast.USuperExpression
|
||||
|
||||
class KotlinUSuperExpression(
|
||||
override val psi: KtSuperExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), USuperExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
|
||||
+3
-4
@@ -23,7 +23,7 @@ import org.jetbrains.uast.kotlin.kinds.KotlinSpecialExpressionKinds
|
||||
|
||||
class KotlinUSwitchExpression(
|
||||
override val psi: KtWhenExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), USwitchExpression, KotlinUElementWithType {
|
||||
override val expression by lz { KotlinConverter.convertOrNull(psi.subjectExpression, this) }
|
||||
|
||||
@@ -48,7 +48,7 @@ class KotlinUSwitchExpression(
|
||||
|
||||
class KotlinUSwitchEntry(
|
||||
override val psi: KtWhenEntry,
|
||||
override val containingElement: UExpression
|
||||
override val uastParent: UExpression
|
||||
) : KotlinAbstractUExpression(), USwitchClauseExpressionWithBody {
|
||||
override val caseValues by lz {
|
||||
psi.conditions.map { when (it) {
|
||||
@@ -89,13 +89,12 @@ class KotlinUSwitchEntry(
|
||||
is KtBlockExpression -> exprPsi.statements.map { KotlinConverter.convertOrEmpty(it, this) }
|
||||
else -> listOf(KotlinConverter.convertOrEmpty(exprPsi, this))
|
||||
}
|
||||
containingElement
|
||||
expressions = userExpressions + object : UBreakExpression {
|
||||
override val psi: PsiElement?
|
||||
get() = null
|
||||
override val label: String?
|
||||
get() = null
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
get() = this@KotlinUSwitchEntry
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.jetbrains.uast.UThisExpression
|
||||
|
||||
class KotlinUThisExpression(
|
||||
override val psi: KtThisExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UThisExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.uast.UThrowExpression
|
||||
|
||||
class KotlinUThrowExpression(
|
||||
override val psi: KtThrowExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UThrowExpression, KotlinUElementWithType {
|
||||
override val thrownExpression by lz { KotlinConverter.convertOrEmpty(psi.thrownExpression, this) }
|
||||
}
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.jetbrains.uast.UVariable
|
||||
|
||||
class KotlinUTryExpression(
|
||||
override val psi: KtTryExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UTryExpression, KotlinUElementWithType {
|
||||
override val tryClause by lz { KotlinConverter.convertOrEmpty(psi.tryBlock, this) }
|
||||
override val catchClauses by lz { psi.catchClauses.map { KotlinUCatchClause(it, this) } }
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.uast.UastBinaryExpressionWithTypeKind
|
||||
|
||||
class KotlinUTypeCheckExpression(
|
||||
override val psi: KtIsExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UBinaryExpressionWithType, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val operand by lz { KotlinConverter.convertOrEmpty(psi.leftHandSide, this) }
|
||||
|
||||
|
||||
+2
-2
@@ -8,13 +8,13 @@ import org.jetbrains.uast.UTypeReferenceExpression
|
||||
open class KotlinUTypeReferenceExpression(
|
||||
override val type: PsiType,
|
||||
override val psi: PsiElement?,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UTypeReferenceExpression, KotlinUElementWithType
|
||||
|
||||
|
||||
class LazyKotlinUTypeReferenceExpression(
|
||||
override val psi: PsiElement,
|
||||
override val containingElement: UElement?,
|
||||
override val uastParent: UElement?,
|
||||
private val typeSupplier: () -> PsiType
|
||||
) : KotlinAbstractUExpression(), UTypeReferenceExpression {
|
||||
override val type: PsiType by lz { typeSupplier() }
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.uast.UWhileExpression
|
||||
|
||||
class KotlinUWhileExpression(
|
||||
override val psi: KtWhileExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UWhileExpression {
|
||||
override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) }
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) }
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||
private class KotlinLocalFunctionUVariable(
|
||||
val function: KtFunction,
|
||||
override val psi: PsiVariable,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : UVariable, PsiVariable by psi {
|
||||
override val uastInitializer: UExpression? by lz {
|
||||
createLocalFunctionLambdaExpression(function, this)
|
||||
@@ -27,7 +27,7 @@ private class KotlinLocalFunctionUVariable(
|
||||
|
||||
private class KotlinLocalFunctionULambdaExpression(
|
||||
override val psi: KtFunction,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
): KotlinAbstractUExpression(), ULambdaExpression {
|
||||
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.bodyExpression, this) }
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.uast.UExpression
|
||||
|
||||
class UnknownKotlinExpression(
|
||||
override val psi: KtExpression,
|
||||
override val containingElement: UElement?
|
||||
override val uastParent: UElement?
|
||||
) : KotlinAbstractUExpression(), UExpression {
|
||||
override fun asLogString() = "[!] UnknownKotlinExpression ($psi)"
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
<os family="windows"/>
|
||||
</condition>
|
||||
|
||||
<property name="uast.version" value="1.0.11"/>
|
||||
<property name="uast.version" value="1.0.12"/>
|
||||
|
||||
<property name="generators" value="${basedir}/generators"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user