Drop JetPsiMatcher class and use JetPsiUnifier instead. Drop AbstractJetPsiMatcherTest
This commit is contained in:
@@ -42,7 +42,6 @@ import org.jetbrains.jet.jvm.compiler.AbstractWriteSignatureTest
|
|||||||
import org.jetbrains.jet.cli.AbstractKotlincExecutableTest
|
import org.jetbrains.jet.cli.AbstractKotlincExecutableTest
|
||||||
import org.jetbrains.jet.repl.AbstractReplInterpreterTest
|
import org.jetbrains.jet.repl.AbstractReplInterpreterTest
|
||||||
import org.jetbrains.jet.cfg.AbstractControlFlowTest
|
import org.jetbrains.jet.cfg.AbstractControlFlowTest
|
||||||
import org.jetbrains.jet.psi.AbstractJetPsiMatcherTest
|
|
||||||
import org.jetbrains.jet.checkers.AbstractJetPsiCheckerTest
|
import org.jetbrains.jet.checkers.AbstractJetPsiCheckerTest
|
||||||
import org.jetbrains.jet.checkers.AbstractJetJsCheckerTest
|
import org.jetbrains.jet.checkers.AbstractJetJsCheckerTest
|
||||||
import org.jetbrains.jet.plugin.quickfix.AbstractQuickFixTest
|
import org.jetbrains.jet.plugin.quickfix.AbstractQuickFixTest
|
||||||
@@ -296,11 +295,6 @@ fun main(args: Array<String>) {
|
|||||||
model("resolve/additionalLazyResolve")
|
model("resolve/additionalLazyResolve")
|
||||||
}
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractJetPsiMatcherTest>()) {
|
|
||||||
model("jetPsiMatcher/expressions", testMethod = "doTestExpressions")
|
|
||||||
model("jetPsiMatcher/types", testMethod = "doTestTypes")
|
|
||||||
}
|
|
||||||
|
|
||||||
testClass(javaClass<AbstractJetPsiCheckerTest>()) {
|
testClass(javaClass<AbstractJetPsiCheckerTest>()) {
|
||||||
model("checker", recursive = false)
|
model("checker", recursive = false)
|
||||||
model("checker/regression")
|
model("checker/regression")
|
||||||
|
|||||||
+32
-17
@@ -23,9 +23,11 @@ import org.jetbrains.jet.lang.psi.JetPsiFactory
|
|||||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||||
import org.jetbrains.jet.plugin.util.JetPsiMatcher
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||||
|
import org.jetbrains.jet.plugin.util.psi.patternMatching.JetPsiUnifier
|
||||||
|
import org.jetbrains.jet.plugin.util.psi.patternMatching.UnificationResult
|
||||||
|
import org.jetbrains.jet.plugin.util.psi.patternMatching.matches
|
||||||
|
|
||||||
public class ReplaceWithOperatorAssignIntention : JetSelfTargetingIntention<JetBinaryExpression>("replace.with.operator.assign.intention", javaClass()) {
|
public class ReplaceWithOperatorAssignIntention : JetSelfTargetingIntention<JetBinaryExpression>("replace.with.operator.assign.intention", javaClass()) {
|
||||||
|
|
||||||
@@ -46,33 +48,38 @@ public class ReplaceWithOperatorAssignIntention : JetSelfTargetingIntention<JetB
|
|||||||
val descriptor = context[BindingContext.REFERENCE_TARGET, expression.getOperationReference()]?.getContainingDeclaration()
|
val descriptor = context[BindingContext.REFERENCE_TARGET, expression.getOperationReference()]?.getContainingDeclaration()
|
||||||
val isPrimitiveOperation = descriptor is ClassDescriptor && KotlinBuiltIns.getInstance().isPrimitiveType(descriptor.getDefaultType())
|
val isPrimitiveOperation = descriptor is ClassDescriptor && KotlinBuiltIns.getInstance().isPrimitiveType(descriptor.getDefaultType())
|
||||||
|
|
||||||
when {
|
return when {
|
||||||
JetPsiMatcher.checkElementMatch(variableExpression, expression.getLeft()) -> {
|
variableExpression.matches(expression.getLeft()) -> {
|
||||||
val validity = expression.getOperationToken() == JetTokens.PLUS ||
|
val validity = expression.getOperationToken() == JetTokens.PLUS ||
|
||||||
expression.getOperationToken() == JetTokens.MINUS ||
|
expression.getOperationToken() == JetTokens.MINUS ||
|
||||||
expression.getOperationToken() == JetTokens.MUL ||
|
expression.getOperationToken() == JetTokens.MUL ||
|
||||||
expression.getOperationToken() == JetTokens.DIV ||
|
expression.getOperationToken() == JetTokens.DIV ||
|
||||||
expression.getOperationToken() == JetTokens.PERC
|
expression.getOperationToken() == JetTokens.PERC
|
||||||
|
|
||||||
if (validity) {
|
if (validity) {
|
||||||
setText("Replace with ${expression.getOperationReference().getText()}= Expression")
|
setText("Replace with ${expression.getOperationReference().getText()}= Expression")
|
||||||
}
|
}
|
||||||
|
|
||||||
return validity
|
validity
|
||||||
}
|
}
|
||||||
JetPsiMatcher.checkElementMatch(variableExpression, expression.getRight()) -> {
|
|
||||||
|
variableExpression.matches(expression.getRight()) -> {
|
||||||
val validity = (expression.getOperationToken() == JetTokens.PLUS ||
|
val validity = (expression.getOperationToken() == JetTokens.PLUS ||
|
||||||
expression.getOperationToken() == JetTokens.MUL) &&
|
expression.getOperationToken() == JetTokens.MUL) &&
|
||||||
isPrimitiveOperation
|
isPrimitiveOperation
|
||||||
|
|
||||||
if (validity) {
|
if (validity) {
|
||||||
setText("Replace with ${expression.getOperationReference().getText()}= Expression")
|
setText("Replace with ${expression.getOperationReference().getText()}= Expression")
|
||||||
}
|
}
|
||||||
|
|
||||||
return validity
|
validity
|
||||||
}
|
}
|
||||||
expression.getLeft() is JetBinaryExpression -> return isPrimitiveOperation && checkExpressionRepeat(variableExpression, expression.getLeft() as JetBinaryExpression)
|
|
||||||
else -> return false
|
expression.getLeft() is JetBinaryExpression ->
|
||||||
|
isPrimitiveOperation && checkExpressionRepeat(variableExpression, expression.getLeft() as JetBinaryExpression)
|
||||||
|
|
||||||
|
else ->
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,21 +94,29 @@ public class ReplaceWithOperatorAssignIntention : JetSelfTargetingIntention<JetB
|
|||||||
[tailRecursive]
|
[tailRecursive]
|
||||||
fun buildReplacement(variableExpression: JetSimpleNameExpression, expression: JetBinaryExpression, replacementBuilder: StringBuilder): String {
|
fun buildReplacement(variableExpression: JetSimpleNameExpression, expression: JetBinaryExpression, replacementBuilder: StringBuilder): String {
|
||||||
when {
|
when {
|
||||||
JetPsiMatcher.checkElementMatch(variableExpression, expression.getLeft()) -> {
|
variableExpression.matches(expression.getLeft()) -> {
|
||||||
return "${variableExpression.getText()} ${expression.getOperationReference().getText()}= ${expression.getRight()!!.getText()} ${replacementBuilder.toString()}"
|
return "${variableExpression.getText()} ${expression.getOperationReference().getText()}= ${expression.getRight()!!.getText()} ${replacementBuilder.toString()}"
|
||||||
}
|
}
|
||||||
JetPsiMatcher.checkElementMatch(variableExpression, expression.getRight()) -> {
|
|
||||||
|
variableExpression.matches(expression.getRight()) -> {
|
||||||
return "${variableExpression.getText()} ${expression.getOperationReference().getText()}= ${expression.getLeft()!!.getText()} ${replacementBuilder.toString()}"
|
return "${variableExpression.getText()} ${expression.getOperationReference().getText()}= ${expression.getLeft()!!.getText()} ${replacementBuilder.toString()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
expression.getLeft() is JetBinaryExpression -> {
|
expression.getLeft() is JetBinaryExpression -> {
|
||||||
return buildReplacement(variableExpression, expression.getLeft() as JetBinaryExpression, StringBuilder("${expression.getOperationReference().getText()} ${expression.getRight()!!.getText()} ${replacementBuilder.toString()}"))
|
return buildReplacement(variableExpression, expression.getLeft() as JetBinaryExpression, StringBuilder("${expression.getOperationReference().getText()} ${expression.getRight()!!.getText()} ${replacementBuilder.toString()}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
return replacementBuilder.toString()
|
return replacementBuilder.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
element.replace(JetPsiFactory(element).createExpression(buildReplacement(element.getLeft() as JetSimpleNameExpression, element.getRight() as JetBinaryExpression, StringBuilder())))
|
val replacement = buildReplacement(
|
||||||
|
(element.getLeft() as JetSimpleNameExpression),
|
||||||
|
element.getRight() as JetBinaryExpression,
|
||||||
|
StringBuilder()
|
||||||
|
)
|
||||||
|
element.replace(JetPsiFactory(element).createExpression(replacement))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+11
-21
@@ -18,7 +18,6 @@ package org.jetbrains.jet.plugin.intentions.branchedTransformations
|
|||||||
|
|
||||||
import org.jetbrains.jet.lang.psi.*
|
import org.jetbrains.jet.lang.psi.*
|
||||||
import org.jetbrains.jet.lexer.JetTokens
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
import org.jetbrains.jet.plugin.util.JetPsiMatcher
|
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUnparsingUtils.*
|
import org.jetbrains.jet.lang.psi.JetPsiUnparsingUtils.*
|
||||||
import org.jetbrains.jet.lang.psi.psiUtil.*
|
import org.jetbrains.jet.lang.psi.psiUtil.*
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
@@ -26,6 +25,11 @@ import com.intellij.psi.util.PsiTreeUtil
|
|||||||
import com.intellij.psi.PsiWhiteSpace
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import com.intellij.util.containers.ContainerUtil
|
import com.intellij.util.containers.ContainerUtil
|
||||||
|
import org.jetbrains.jet.plugin.util.psi.patternMatching.JetPsiUnifier
|
||||||
|
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||||
|
import org.jetbrains.jet.plugin.util.psi.patternMatching.toRange
|
||||||
|
import org.jetbrains.jet.plugin.util.psi.patternMatching.UnificationResult
|
||||||
|
import org.jetbrains.jet.plugin.util.psi.patternMatching.matches
|
||||||
|
|
||||||
public val TRANSFORM_WITHOUT_CHECK: String = "Expression must be checked before applying transformation"
|
public val TRANSFORM_WITHOUT_CHECK: String = "Expression must be checked before applying transformation"
|
||||||
|
|
||||||
@@ -70,8 +74,7 @@ public fun JetWhenExpression.canFlatten(): Boolean {
|
|||||||
val elseBranch = getElseExpression()
|
val elseBranch = getElseExpression()
|
||||||
if (elseBranch !is JetWhenExpression) return false
|
if (elseBranch !is JetWhenExpression) return false
|
||||||
|
|
||||||
return JetPsiUtil.checkWhenExpressionHasSingleElse(elseBranch) &&
|
return JetPsiUtil.checkWhenExpressionHasSingleElse(elseBranch) && subject.matches(elseBranch.getSubjectExpression())
|
||||||
JetPsiMatcher.checkElementMatch(subject, elseBranch.getSubjectExpression())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun JetWhenExpression.getSubjectCandidate(): JetExpression? {
|
fun JetWhenExpression.getSubjectCandidate(): JetExpression? {
|
||||||
@@ -113,7 +116,7 @@ fun JetWhenExpression.getSubjectCandidate(): JetExpression? {
|
|||||||
if (lastCandidate == null) {
|
if (lastCandidate == null) {
|
||||||
lastCandidate = currCandidate
|
lastCandidate = currCandidate
|
||||||
}
|
}
|
||||||
else if (!JetPsiMatcher.checkElementMatch(lastCandidate, currCandidate)) return null
|
else if (!lastCandidate.matches(currCandidate)) return null
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,14 +182,7 @@ public fun JetWhenExpression.introduceSubject(): JetWhenExpression {
|
|||||||
when (op) {
|
when (op) {
|
||||||
JetTokens.IN_KEYWORD -> builder.range(rhs, false)
|
JetTokens.IN_KEYWORD -> builder.range(rhs, false)
|
||||||
JetTokens.NOT_IN -> builder.range(rhs, true)
|
JetTokens.NOT_IN -> builder.range(rhs, true)
|
||||||
JetTokens.EQEQ -> {
|
JetTokens.EQEQ -> builder.condition(if (subject.matches(lhs)) rhs else lhs)
|
||||||
if (JetPsiMatcher.checkElementMatch(subject, lhs)) {
|
|
||||||
builder.condition(rhs)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
builder.condition(lhs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> assert(false, TRANSFORM_WITHOUT_CHECK)
|
else -> assert(false, TRANSFORM_WITHOUT_CHECK)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,14 +317,8 @@ public fun JetWhenExpression.transformToIf() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fun JetWhenExpression.canMergeWithNext(): Boolean {
|
public fun JetWhenExpression.canMergeWithNext(): Boolean {
|
||||||
fun checkConditions(e1: JetWhenEntry, e2: JetWhenEntry): Boolean {
|
fun checkConditions(e1: JetWhenEntry, e2: JetWhenEntry): Boolean =
|
||||||
if (e1.isElse() != e2.isElse()) return false
|
e1.getConditions().toList().toRange().matches(e2.getConditions().toList().toRange())
|
||||||
|
|
||||||
val conditions1 = e1.getConditions().toList()
|
|
||||||
val conditions2 = e2.getConditions().toList()
|
|
||||||
return conditions1.size == conditions2.size &&
|
|
||||||
(conditions1 zip conditions2).all { pair -> JetPsiMatcher.checkElementMatch(pair.first, pair.second)}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun JetWhenEntry.declarationNames(): Set<String> =
|
fun JetWhenEntry.declarationNames(): Set<String> =
|
||||||
getExpression()?.blockExpressionsOrSingle()
|
getExpression()?.blockExpressionsOrSingle()
|
||||||
@@ -348,7 +338,7 @@ public fun JetWhenExpression.canMergeWithNext(): Boolean {
|
|||||||
val sibling = PsiTreeUtil.skipSiblingsForward(this, javaClass<PsiWhiteSpace>())
|
val sibling = PsiTreeUtil.skipSiblingsForward(this, javaClass<PsiWhiteSpace>())
|
||||||
|
|
||||||
if (sibling !is JetWhenExpression) return false
|
if (sibling !is JetWhenExpression) return false
|
||||||
if (!JetPsiMatcher.checkElementMatch(getSubjectExpression(), sibling.getSubjectExpression())) return false
|
if (!getSubjectExpression().matches(sibling.getSubjectExpression())) return false
|
||||||
|
|
||||||
val entries1 = getEntries()
|
val entries1 = getEntries()
|
||||||
val entries2 = sibling.getEntries()
|
val entries2 = sibling.getEntries()
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.jet.plugin.intentions.declarations;
|
package org.jetbrains.jet.plugin.intentions.declarations;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.psi.PsiComment;
|
import com.intellij.psi.PsiComment;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
@@ -30,7 +29,6 @@ import org.jetbrains.jet.lang.types.JetType;
|
|||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
|
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
|
||||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||||
import org.jetbrains.jet.plugin.util.JetPsiMatcher;
|
|
||||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||||
@@ -77,8 +75,7 @@ public class DeclarationUtils {
|
|||||||
|
|
||||||
if (!(assignment.getLeft() instanceof JetSimpleNameExpression)) return null;
|
if (!(assignment.getLeft() instanceof JetSimpleNameExpression)) return null;
|
||||||
if (assignment.getRight() == null) return null;
|
if (assignment.getRight() == null) return null;
|
||||||
//noinspection ConstantConditions
|
if (!JetPsiUtil.unquoteIdentifier(assignment.getLeft().getText()).equals(property.getName())) return null;
|
||||||
if (!JetPsiMatcher.checkIdentifierMatch(property.getNameIdentifier().getText(), assignment.getLeft().getText())) return null;
|
|
||||||
|
|
||||||
return new Pair<JetProperty, JetBinaryExpression>(property, assignment);
|
return new Pair<JetProperty, JetBinaryExpression>(property, assignment);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,288 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2013 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.jet.plugin.util;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class JetPsiMatcher {
|
|
||||||
private JetPsiMatcher() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean checkTypeReferenceMatch(JetTypeReference t1, JetTypeReference t2) {
|
|
||||||
return (t1 == t2) || (t1 != null && t2 != null && t1.getText().equals(t2.getText()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private interface Predicate2<A, B> {
|
|
||||||
boolean apply(A a, B b);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Predicate2<JetElement, JetElement> DEFAULT_CHECKER = new Predicate2<JetElement, JetElement>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(JetElement element1, JetElement element2) {
|
|
||||||
return checkElementMatch(element1, element2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static final Predicate2<ValueArgument, ValueArgument> VALUE_ARGUMENT_CHECKER = new Predicate2<ValueArgument, ValueArgument>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(ValueArgument a1, ValueArgument a2) {
|
|
||||||
if (a1 == a2) return true;
|
|
||||||
if (a1 == null || a2 == null) return false;
|
|
||||||
|
|
||||||
if (a1.getClass() != a2.getClass()) return false;
|
|
||||||
|
|
||||||
if (a1.isNamed() != a2.isNamed()) return false;
|
|
||||||
|
|
||||||
if (!checkElementMatch(a1.getArgumentExpression(), a2.getArgumentExpression())) return false;
|
|
||||||
|
|
||||||
if (a1.isNamed()) {
|
|
||||||
return checkElementMatch(a1.getArgumentName(), a2.getArgumentName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static final Predicate2<JetParameter, JetParameter> PARAMETER_TYPE_CHECKER = new Predicate2<JetParameter, JetParameter>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(JetParameter param1, JetParameter param2) {
|
|
||||||
return checkElementMatch(param1.getTypeReference(), param2.getTypeReference());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static <T> boolean checkListMatch(List<? extends T> list1, List<? extends T> list2, Predicate2<T, T> checker) {
|
|
||||||
int n = list1.size();
|
|
||||||
if (list2.size() != n) return false;
|
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
if (!checker.apply(list1.get(i), list2.get(i))) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T extends JetElement> boolean checkListMatch(List<? extends T> list1, List<? extends T> list2) {
|
|
||||||
return checkListMatch(list1, list2, DEFAULT_CHECKER);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final JetVisitor<Boolean, JetElement> VISITOR = new JetVisitor<Boolean, JetElement>() {
|
|
||||||
@Override
|
|
||||||
public Boolean visitJetElement(@NotNull JetElement element, JetElement data) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitArrayAccessExpression(@NotNull JetArrayAccessExpression aae1, JetElement data) {
|
|
||||||
JetArrayAccessExpression aae2 = (JetArrayAccessExpression) data;
|
|
||||||
|
|
||||||
return checkElementMatch(aae1.getArrayExpression(), aae2.getArrayExpression()) &&
|
|
||||||
checkListMatch(aae1.getIndexExpressions(), aae2.getIndexExpressions());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitBinaryExpression(@NotNull JetBinaryExpression be1, JetElement data) {
|
|
||||||
JetBinaryExpression be2 = (JetBinaryExpression) data;
|
|
||||||
|
|
||||||
return be1.getOperationToken() == be2.getOperationToken() &&
|
|
||||||
checkElementMatch(be1.getLeft(), be2.getLeft()) &&
|
|
||||||
checkElementMatch(be1.getRight(), be2.getRight());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitBinaryWithTypeRHSExpression(@NotNull JetBinaryExpressionWithTypeRHS bet1, JetElement data) {
|
|
||||||
JetBinaryExpressionWithTypeRHS bet2 = (JetBinaryExpressionWithTypeRHS) data;
|
|
||||||
|
|
||||||
return checkElementMatch(bet1.getLeft(), bet2.getLeft()) &&
|
|
||||||
checkTypeReferenceMatch(bet1.getRight(), bet2.getRight());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitCallExpression(@NotNull JetCallExpression call1, JetElement data) {
|
|
||||||
JetCallExpression call2 = (JetCallExpression) data;
|
|
||||||
|
|
||||||
if (!checkElementMatch(call1.getCalleeExpression(), call2.getCalleeExpression())) return false;
|
|
||||||
|
|
||||||
return checkListMatch(call1.getValueArguments(), call2.getValueArguments(), VALUE_ARGUMENT_CHECKER);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression, JetElement data) {
|
|
||||||
return checkIdentifierMatch(expression.getText(), data.getText());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitConstantExpression(@NotNull JetConstantExpression expression, JetElement data) {
|
|
||||||
return expression.getText().equals(data.getText());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitIsExpression(@NotNull JetIsExpression is1, JetElement data) {
|
|
||||||
JetIsExpression is2 = (JetIsExpression) data;
|
|
||||||
|
|
||||||
return checkElementMatch(is1.getLeftHandSide(), is2.getLeftHandSide()) &&
|
|
||||||
checkTypeReferenceMatch(is1.getTypeRef(), is2.getTypeRef()) &&
|
|
||||||
is1.isNegated() == is2.isNegated();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitQualifiedExpression(@NotNull JetQualifiedExpression qe1, JetElement data) {
|
|
||||||
JetQualifiedExpression qe2 = (JetQualifiedExpression) data;
|
|
||||||
|
|
||||||
return qe1.getOperationSign() == qe2.getOperationSign() &&
|
|
||||||
checkElementMatch(qe1.getReceiverExpression(), qe2.getReceiverExpression()) &&
|
|
||||||
checkElementMatch(qe1.getSelectorExpression(), qe2.getSelectorExpression());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitStringTemplateExpression(@NotNull JetStringTemplateExpression expression, JetElement data) {
|
|
||||||
return checkListMatch(
|
|
||||||
Arrays.asList(expression.getEntries()),
|
|
||||||
Arrays.asList(((JetStringTemplateExpression) data).getEntries())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitStringTemplateEntryWithExpression(@NotNull JetStringTemplateEntryWithExpression entry, JetElement data) {
|
|
||||||
return checkElementMatch(entry.getExpression(), ((JetStringTemplateEntryWithExpression) data).getExpression());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitLiteralStringTemplateEntry(@NotNull JetLiteralStringTemplateEntry entry, JetElement data) {
|
|
||||||
return entry.getText().equals(data.getText());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitEscapeStringTemplateEntry(@NotNull JetEscapeStringTemplateEntry entry, JetElement data) {
|
|
||||||
return entry.getText().equals(data.getText());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitSuperExpression(@NotNull JetSuperExpression super1, JetElement data) {
|
|
||||||
JetSuperExpression super2 = (JetSuperExpression) data;
|
|
||||||
|
|
||||||
return checkTypeReferenceMatch(super1.getSuperTypeQualifier(), super2.getSuperTypeQualifier()) &&
|
|
||||||
checkElementMatch(super1.getInstanceReference(), super2.getInstanceReference()) &&
|
|
||||||
checkElementMatch(super1.getTargetLabel(), super2.getTargetLabel());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitThrowExpression(@NotNull JetThrowExpression expression, JetElement data) {
|
|
||||||
return checkElementMatch(expression.getThrownExpression(), ((JetThrowExpression) data).getThrownExpression());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitThisExpression(@NotNull JetThisExpression this1, JetElement data) {
|
|
||||||
return checkElementMatch(this1.getTargetLabel(), ((JetThisExpression) data).getTargetLabel());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitUnaryExpression(@NotNull JetUnaryExpression ue1, JetElement data) {
|
|
||||||
JetUnaryExpression ue2 = (JetUnaryExpression) data;
|
|
||||||
|
|
||||||
return checkElementMatch(ue1.getBaseExpression(), ue2.getBaseExpression()) &&
|
|
||||||
checkElementMatch(ue1.getOperationReference(), ue2.getOperationReference());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitTypeReference(@NotNull JetTypeReference typeReference, JetElement data) {
|
|
||||||
return checkElementMatch(typeReference.getTypeElement(), ((JetTypeReference) data).getTypeElement());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitFunctionType(@NotNull JetFunctionType type1, JetElement data) {
|
|
||||||
JetFunctionType type2 = (JetFunctionType) data;
|
|
||||||
|
|
||||||
return checkElementMatch(type1.getReceiverTypeRef(), type2.getReceiverTypeRef()) &&
|
|
||||||
checkElementMatch(type1.getReturnTypeRef(), type2.getReturnTypeRef()) &&
|
|
||||||
checkListMatch(type1.getParameters(), type2.getParameters(), PARAMETER_TYPE_CHECKER);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitUserType(@NotNull JetUserType type1, JetElement data) {
|
|
||||||
JetUserType type2 = (JetUserType) data;
|
|
||||||
|
|
||||||
return checkElementMatch(type1.getReferenceExpression(), type2.getReferenceExpression()) &&
|
|
||||||
checkElementMatch(type1.getQualifier(), type2.getQualifier()) &&
|
|
||||||
checkListMatch(type1.getTypeArgumentsAsTypes(), type2.getTypeArgumentsAsTypes());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitSelfType(@NotNull JetSelfType type, JetElement data) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitNullableType(@NotNull JetNullableType nullableType, JetElement data) {
|
|
||||||
return checkElementMatch(nullableType.getInnerType(), ((JetNullableType) data).getInnerType());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitWhenConditionWithExpression(@NotNull JetWhenConditionWithExpression condition, JetElement data) {
|
|
||||||
return checkElementMatch(condition.getExpression(), ((JetWhenConditionWithExpression) data).getExpression());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitWhenConditionInRange(@NotNull JetWhenConditionInRange condition, JetElement data) {
|
|
||||||
JetWhenConditionInRange other = (JetWhenConditionInRange) data;
|
|
||||||
return condition.isNegated() == other.isNegated() &&
|
|
||||||
checkElementMatch(condition.getRangeExpression(), other.getRangeExpression());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitWhenConditionIsPattern(@NotNull JetWhenConditionIsPattern condition, JetElement data) {
|
|
||||||
JetWhenConditionIsPattern other = (JetWhenConditionIsPattern) data;
|
|
||||||
return condition.isNegated() == other.isNegated() &&
|
|
||||||
checkElementMatch(condition.getTypeRef(), other.getTypeRef());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static JetElement unwrap(JetElement e) {
|
|
||||||
if (e instanceof JetExpression) {
|
|
||||||
return JetPsiUtil.deparenthesize((JetExpression) e);
|
|
||||||
}
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkElementMatch(@Nullable JetElement e1, @Nullable JetElement e2) {
|
|
||||||
e1 = unwrap(e1);
|
|
||||||
e2 = unwrap(e2);
|
|
||||||
|
|
||||||
if (e1 == e2) return true;
|
|
||||||
if (e1 == null || e2 == null) return false;
|
|
||||||
|
|
||||||
if (e1.getClass() != e2.getClass()) return false;
|
|
||||||
|
|
||||||
return e1.accept(VISITOR, e2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static String unquote(@NotNull String s) {
|
|
||||||
return (s.startsWith("`") && s.endsWith("`")) ? s.substring(1, s.length() - 1) : s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkIdentifierMatch(@Nullable String s1, @Nullable String s2) {
|
|
||||||
if (s1 == s2) return true;
|
|
||||||
if (s1 == null || s2 == null) return false;
|
|
||||||
|
|
||||||
return unquote(s1).equals(unquote(s2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
a[0]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
b[0]
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
a[0]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a[2]
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
a[0]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a[n]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a[0]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a[0]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a[n]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a[n]
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
1 + 2
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
2 + 1
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
1 + 2
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
1 - 2
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
a + 2
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
b + 2
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
a + b
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
c/d
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
a is String
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a as String
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
a !is String
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a is String
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
1 + 2
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
1 + 2
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a + b
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a + b
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a*10
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a*10
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a is String
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a is String
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a !is String
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a !is String
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
f()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
f(0)
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
f()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
g()
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
f(a, b)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a.f(b)
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
x.f(a, b)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
y.f(c, z)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
f()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
f()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
f(a)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
f(a)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
f(a, 1)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
f(a, 1)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
x.f(a, 1)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
x.f(a, 1)
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
123
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
345
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
123
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
123
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
(a + b*x.f(n - 1))
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
(a + b)*x.f(n - 1)
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
(a.foo((n + 2)*(m - 1))[k[i]] is MyClass?) || (b.foo(n - 2)[i + 1] !is YourClass)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a.foo((n + 2*m - 1))[k[i]] is MyClass? || b.foo[n - 2](i + 1) !is YourClass
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
a > b[n] && (a < foo(x.bar(n + 2)) || a == n) && b[n - 1] != foo(a + 2)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a > b[n] && a < foo(x.bar(n + 2)) || (a == n) && (b[n - 1] != foo(a + 2))
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
(a + b*x.f(n - 1))
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
(a) + b*x.f(n - 1)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
(a.foo((n + 2)*(m - 1))[k[i]] is MyClass?) || (b.foo(n - 2)[i + 1] !is YourClass)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a.foo((n + 2)*(m - 1))[k[i]] is MyClass? || b.foo(n - 2)[i + 1] !is YourClass
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a > b[n] && (a < foo(x.bar(n + 2)) || a == n) && b[n - 1] != foo(a + 2)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a > b[n] && (a < foo(x.bar(n + 2)) || (a == n)) && (b[n - 1] != foo(a + 2))
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
test
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
abcd
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
test
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
test
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
test
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
`test`
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
super.foo()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
super.bar()
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
super<String>.foo()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
super<Int>.foo()
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
super<>.foo()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
super.foo()
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
super<A>@B.foo()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
super<B>@A.foo()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
super.foo()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
super.foo()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
super<Int>.foo()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
super<Int>.foo()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
super<>.foo()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
super<>.foo()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
super<Int>@label.foo()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
super<Int>@label.foo()
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
throw X()
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
throw Z()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
throw X()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
throw X()
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
!false
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
!true
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
!a
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
++a
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// NOT_EQUAL
|
|
||||||
!a
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user