continue work on KT-458
70b7810c30 fixed parser
this commit fixes typer
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace dollar
|
||||
|
||||
open class `$$$$$`() {
|
||||
}
|
||||
open class `$`() {
|
||||
}
|
||||
open class `$$`(`$$$$` : `$$$$$`?) : `$`() {
|
||||
val `$$$` : `$$$$$`?
|
||||
{
|
||||
$`$$$` = `$$$$`
|
||||
}
|
||||
open public fun `$$$$$$`() : `$$$$$`? {
|
||||
return `$$$`
|
||||
}
|
||||
}
|
||||
@@ -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`"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user