Add support of backticks in JetPsiMatcher

This commit is contained in:
Alexey Sedunov
2013-06-13 18:33:57 +04:00
parent 6629892dad
commit e13508c22b
4 changed files with 21 additions and 1 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.jet.plugin.util;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.*;
@@ -126,7 +127,7 @@ public class JetPsiMatcher {
@Override
public Boolean visitSimpleNameExpression(JetSimpleNameExpression expression, JetElement data) {
return expression.getText().equals(data.getText());
return checkIdentifierMatch(expression.getText(), data.getText());
}
@Override
@@ -254,4 +255,16 @@ public class JetPsiMatcher {
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));
}
}
@@ -0,0 +1 @@
test
@@ -0,0 +1 @@
`test`
@@ -250,6 +250,11 @@ public class JetPsiMatcherTest extends AbstractJetPsiMatcherTest {
doTestExpressions("idea/testData/jetPsiMatcher/expressions/simpleName/simpleName.kt");
}
@TestMetadata("simpleName2.kt")
public void testSimpleName2() throws Exception {
doTestExpressions("idea/testData/jetPsiMatcher/expressions/simpleName/simpleName2.kt");
}
@TestMetadata("_simpleName.kt")
public void test_simpleName() throws Exception {
doTestExpressions("idea/testData/jetPsiMatcher/expressions/simpleName/_simpleName.kt");