diff --git a/compiler/testData/cli/jvm/signatureClash.out b/compiler/testData/cli/jvm/signatureClash.out index 26d449d589e..12ffca2e30f 100644 --- a/compiler/testData/cli/jvm/signatureClash.out +++ b/compiler/testData/cli/jvm/signatureClash.out @@ -21,9 +21,9 @@ ERROR: compiler/testData/cli/jvm/signatureClash.kt: (20, 5) Platform declaration fun (): kotlin.Int fun getTr(): kotlin.Int ERROR: compiler/testData/cli/jvm/signatureClash.kt: (24, 7) Platform declaration clash: The following declarations have the same JVM signature (f$b$0(LC;)V): - fun f$b$0(c: C): kotlin.Unit + fun `f$b$0`(c: C): kotlin.Unit fun f(): kotlin.Unit ERROR: compiler/testData/cli/jvm/signatureClash.kt: (26, 5) Platform declaration clash: The following declarations have the same JVM signature (f$b$0(LC;)V): - fun f$b$0(c: C): kotlin.Unit + fun `f$b$0`(c: C): kotlin.Unit fun f(): kotlin.Unit COMPILATION_ERROR \ No newline at end of file diff --git a/compiler/testData/cli/jvm/syntheticAccessorSignatureClash.out b/compiler/testData/cli/jvm/syntheticAccessorSignatureClash.out index a8e100f1cfe..417347ffb81 100644 --- a/compiler/testData/cli/jvm/syntheticAccessorSignatureClash.out +++ b/compiler/testData/cli/jvm/syntheticAccessorSignatureClash.out @@ -1,20 +1,20 @@ WARNING: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (34, 17) Variable 's' is never used ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (15, 5) Accidental override: The following declarations have the same JVM signature (foo$b$0(LDerived;)V): - fun foo$b$0(d: Derived): kotlin.Unit + fun `foo$b$0`(d: Derived): kotlin.Unit fun foo(): kotlin.Unit ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (18, 9) Accidental override: The following declarations have the same JVM signature (getBar$b$1(LDerived;)I): - fun getBar$b$1(d: Derived): kotlin.Int + fun `getBar$b$1`(d: Derived): kotlin.Int fun (): kotlin.Int ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (19, 9) Accidental override: The following declarations have the same JVM signature (setBar$b$1(LDerived;I)V): - fun setBar$b$1(d: Derived, i: kotlin.Int): kotlin.Unit + fun `setBar$b$1`(d: Derived, i: kotlin.Int): kotlin.Unit fun (: kotlin.Int): kotlin.Unit ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (21, 5) Accidental override: The following declarations have the same JVM signature (getBaz$b$2(LDerived;)I): - fun getBaz$b$2(d: Derived): kotlin.Int + fun `getBaz$b$2`(d: Derived): kotlin.Int fun (): kotlin.Int ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (23, 5) Accidental override: The following declarations have the same JVM signature (getBoo$b$3(LDerived;)I): - fun getBoo$b$3(d: Derived): kotlin.Int + fun `getBoo$b$3`(d: Derived): kotlin.Int fun (): kotlin.Int ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (27, 9) Accidental override: The following declarations have the same JVM signature (setBar1$b$4(LDerived;I)V): - fun setBar1$b$4(d: Derived, i: kotlin.Int): kotlin.Unit + fun `setBar1$b$4`(d: Derived, i: kotlin.Int): kotlin.Unit fun (: kotlin.Int): kotlin.Unit COMPILATION_ERROR \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/classes/DollarsInAnnotationName.txt b/compiler/testData/loadJava/compiledKotlin/annotations/classes/DollarsInAnnotationName.txt index b09753e01c4..92194a689e2 100644 --- a/compiler/testData/loadJava/compiledKotlin/annotations/classes/DollarsInAnnotationName.txt +++ b/compiler/testData/loadJava/compiledKotlin/annotations/classes/DollarsInAnnotationName.txt @@ -1,17 +1,17 @@ package test -internal final annotation class $$$$$$ : kotlin.Annotation { - /*primary*/ public constructor $$$$$$() +internal final annotation class `$$$$$$` : kotlin.Annotation { + /*primary*/ public constructor `$$$$$$`() } -test.$$$$$$() internal final class A { +test.`$$$$$$`() internal final class A { /*primary*/ public constructor A() } -internal final annotation class Anno$tation : kotlin.Annotation { - /*primary*/ public constructor Anno$tation() +internal final annotation class `Anno$tation` : kotlin.Annotation { + /*primary*/ public constructor `Anno$tation`() } -test.Anno$tation() internal final class Cla$s { - /*primary*/ public constructor Cla$s() +test.`Anno$tation`() internal final class `Cla$s` { + /*primary*/ public constructor `Cla$s`() } diff --git a/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java b/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java index 04ce2c97e1d..d41fd1ea4bb 100644 --- a/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java +++ b/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java @@ -201,8 +201,23 @@ public class DescriptorRendererImpl implements DescriptorRenderer { @Override @NotNull public String renderName(@NotNull Name identifier) { - String asString = identifier.toString(); - return escape(KeywordStringsGenerated.KEYWORDS.contains(asString) ? '`' + asString + '`' : asString); + String asString = identifier.asString(); + return escape(nameShouldBeEscaped(identifier) ? '`' + asString + '`' : asString); + } + + private static boolean nameShouldBeEscaped(@NotNull Name identifier) { + if (identifier.isSpecial()) return false; + + String name = identifier.asString(); + + if (KeywordStringsGenerated.KEYWORDS.contains(name)) return true; + + for (int i = 0; i < name.length(); i++) { + char c = name.charAt(i); + if (!Character.isLetterOrDigit(c) && c != '_') return true; + } + + return false; } private void renderName(@NotNull DeclarationDescriptor descriptor, @NotNull StringBuilder builder) { diff --git a/idea/testData/completion/basic/common/NameWithDollars.kt b/idea/testData/completion/basic/common/NameWithDollars.kt new file mode 100644 index 00000000000..c4305ae1c07 --- /dev/null +++ b/idea/testData/completion/basic/common/NameWithDollars.kt @@ -0,0 +1,8 @@ +fun `$$$$`() {} + +fun foo() { + +} + +// EXIST: $$$$ +// INVOCATION_COUNT: 2 diff --git a/idea/tests/org/jetbrains/jet/completion/JSBasicCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JSBasicCompletionTestGenerated.java index 922aca61652..d99b35f7405 100644 --- a/idea/tests/org/jetbrains/jet/completion/JSBasicCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/JSBasicCompletionTestGenerated.java @@ -390,6 +390,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes doTest(fileName); } + @TestMetadata("NameWithDollars.kt") + public void testNameWithDollars() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NameWithDollars.kt"); + doTest(fileName); + } + @TestMetadata("NamedObject.kt") public void testNamedObject() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NamedObject.kt"); diff --git a/idea/tests/org/jetbrains/jet/completion/JvmBasicCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JvmBasicCompletionTestGenerated.java index 71771926e03..4b9f6f16785 100644 --- a/idea/tests/org/jetbrains/jet/completion/JvmBasicCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/JvmBasicCompletionTestGenerated.java @@ -390,6 +390,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT doTest(fileName); } + @TestMetadata("NameWithDollars.kt") + public void testNameWithDollars() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NameWithDollars.kt"); + doTest(fileName); + } + @TestMetadata("NamedObject.kt") public void testNamedObject() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NamedObject.kt");