From 5fbf684998da293885d878c6c16a0bda6ef70935 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Thu, 10 Nov 2011 19:07:51 +0400 Subject: [PATCH] continue work on KT-458 70b7810c3059a33d6fdaa29208af02a67e87448e fixed parser this commit fixes typer --- .../jet/lang/psi/JetNamedDeclaration.java | 7 ++++- .../jetbrains/jet/lang/psi/JetPsiUtil.java | 26 ++++++++++++++++++ .../jet/lang/psi/JetSimpleNameExpression.java | 5 +--- .../checkerWithErrorTypes/quick/Dollar.jet | 15 +++++++++++ .../jet/lang/psi/JetPsiUtilTest.java | 27 +++++++++++++++++++ 5 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/checkerWithErrorTypes/quick/Dollar.jet create mode 100644 compiler/tests/org/jetbrains/jet/lang/psi/JetPsiUtilTest.java diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java index f80a390fc75..dc37a770c64 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java @@ -19,7 +19,12 @@ public abstract class JetNamedDeclaration extends JetDeclaration implements PsiN @Override public String getName() { PsiElement identifier = getNameIdentifier(); - return identifier != null ? identifier.getText() : null; + if (identifier != null) { + String text = identifier.getText(); + return text != null ? JetPsiUtil.unquoteIdentifier(text) : null; + } else { + return null; + } } @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java index 0af3fab3d14..c5f1e8c216c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java @@ -73,4 +73,30 @@ public class JetPsiUtil { } return null; } + + @NotNull + public static String unquoteIdentifier(@NotNull String quoted) { + if (quoted.indexOf('`') < 0) { + return quoted; + } + + if (quoted.startsWith("`") && quoted.endsWith("`") && quoted.length() >= 2) { + return quoted.substring(1, quoted.length() - 1); + } else { + return quoted; + } + } + + @NotNull + public static String unquoteIdentifierOrFieldReference(@NotNull String quoted) { + if (quoted.indexOf('`') < 0) { + return quoted; + } + + if (quoted.startsWith("$")) { + return "$" + unquoteIdentifier(quoted.substring(1)); + } else { + return unquoteIdentifier(quoted); + } + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetSimpleNameExpression.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetSimpleNameExpression.java index 4ef04645259..8b2d824ad3c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetSimpleNameExpression.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetSimpleNameExpression.java @@ -30,10 +30,7 @@ public class JetSimpleNameExpression extends JetReferenceExpression { return null; } String text = referencedNameElement.getNode().getText(); - if (text.startsWith("`") && text.endsWith("`") && text.length() >= 2) { - return text.substring(1, text.length()-1); - } - return text; + return text != null ? JetPsiUtil.unquoteIdentifierOrFieldReference(text) : null; } @Nullable @IfNotParsed diff --git a/compiler/testData/checkerWithErrorTypes/quick/Dollar.jet b/compiler/testData/checkerWithErrorTypes/quick/Dollar.jet new file mode 100644 index 00000000000..7966eb21ab9 --- /dev/null +++ b/compiler/testData/checkerWithErrorTypes/quick/Dollar.jet @@ -0,0 +1,15 @@ +namespace dollar + +open class `$$$$$`() { +} +open class `$`() { +} +open class `$$`(`$$$$` : `$$$$$`?) : `$`() { + val `$$$` : `$$$$$`? + { + $`$$$` = `$$$$` + } + open public fun `$$$$$$`() : `$$$$$`? { + return `$$$` + } +} diff --git a/compiler/tests/org/jetbrains/jet/lang/psi/JetPsiUtilTest.java b/compiler/tests/org/jetbrains/jet/lang/psi/JetPsiUtilTest.java new file mode 100644 index 00000000000..1036e6fdd20 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/lang/psi/JetPsiUtilTest.java @@ -0,0 +1,27 @@ +package org.jetbrains.jet.lang.psi; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * @author Stepan Koltsov + */ +public class JetPsiUtilTest extends TestCase { + + public void testUnquotedIdentifier() { + Assert.assertEquals("", JetPsiUtil.unquoteIdentifier("")); + Assert.assertEquals("a2", JetPsiUtil.unquoteIdentifier("a2")); + Assert.assertEquals("", JetPsiUtil.unquoteIdentifier("``")); + Assert.assertEquals("a2", JetPsiUtil.unquoteIdentifier("`a2`")); + } + + public void testUnquotedIdentifierOrFieldReference() { + Assert.assertEquals("", JetPsiUtil.unquoteIdentifierOrFieldReference("")); + Assert.assertEquals("a2", JetPsiUtil.unquoteIdentifierOrFieldReference("a2")); + Assert.assertEquals("", JetPsiUtil.unquoteIdentifierOrFieldReference("``")); + Assert.assertEquals("a2", JetPsiUtil.unquoteIdentifierOrFieldReference("`a2`")); + Assert.assertEquals("$a2", JetPsiUtil.unquoteIdentifierOrFieldReference("$a2")); + Assert.assertEquals("$a2", JetPsiUtil.unquoteIdentifierOrFieldReference("$`a2`")); + } + +}