Use safe names in codegen, for the case of light classes
This commit is contained in:
+6
-4
@@ -49,6 +49,7 @@ import java.util.*;
|
||||
import static org.jetbrains.jet.codegen.JvmCodegenUtil.peekFromStack;
|
||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.resolve.name.SpecialNames.safeIdentifier;
|
||||
import static org.jetbrains.jet.lexer.JetTokens.*;
|
||||
|
||||
class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
||||
@@ -229,8 +230,9 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
||||
|
||||
private String getName(ClassDescriptor classDescriptor) {
|
||||
String base = peekFromStack(nameStack);
|
||||
return DescriptorUtils.isTopLevelDeclaration(classDescriptor) ? base.isEmpty() ? classDescriptor.getName()
|
||||
.asString() : base + '/' + classDescriptor.getName() : base + '$' + classDescriptor.getName();
|
||||
Name descriptorName = safeIdentifier(classDescriptor.getName());
|
||||
return DescriptorUtils.isTopLevelDeclaration(classDescriptor) ? base.isEmpty() ? descriptorName
|
||||
.asString() : base + '/' + descriptorName : base + '$' + descriptorName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -344,7 +346,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
||||
nameStack.push(nameForClassOrPackageMember);
|
||||
}
|
||||
else {
|
||||
nameStack.push(peekFromStack(nameStack) + '$' + property.getName());
|
||||
nameStack.push(peekFromStack(nameStack) + '$' + safeIdentifier(property.getNameAsSafeName()).asString());
|
||||
}
|
||||
super.visitProperty(property);
|
||||
nameStack.pop();
|
||||
@@ -381,7 +383,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
|
||||
String peek = peekFromStack(nameStack);
|
||||
String name = descriptor.getName().asString();
|
||||
String name = safeIdentifier(descriptor.getName()).asString();
|
||||
if (containingDeclaration instanceof ClassDescriptor) {
|
||||
return peek + '$' + name;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
@@ -297,8 +298,9 @@ public class CodegenBinding {
|
||||
private static String getAsmTypeImpl(@NotNull BindingContext bindingContext, @NotNull ClassDescriptor klass) {
|
||||
DeclarationDescriptor container = klass.getContainingDeclaration();
|
||||
|
||||
Name name = SpecialNames.safeIdentifier(klass.getName());
|
||||
if (container instanceof PackageFragmentDescriptor) {
|
||||
String shortName = klass.getName().getIdentifier();
|
||||
String shortName = name.getIdentifier();
|
||||
FqName fqName = ((PackageFragmentDescriptor) container).getFqName();
|
||||
return fqName.isRoot() ? shortName : fqName.asString().replace('.', '/') + '/' + shortName;
|
||||
}
|
||||
@@ -312,7 +314,7 @@ public class CodegenBinding {
|
||||
case CLASS_OBJECT:
|
||||
return containerInternalName + JvmAbi.CLASS_OBJECT_SUFFIX;
|
||||
default:
|
||||
return containerInternalName + "$" + klass.getName().getIdentifier();
|
||||
return containerInternalName + "$" + name.getIdentifier();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -251,7 +251,7 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OutermostKotlinClassLightClassData getLightClassData(JetClassOrObject classOrObject) {
|
||||
public static OutermostKotlinClassLightClassData getLightClassData(@NotNull JetClassOrObject classOrObject) {
|
||||
JetClassOrObject outermostClassOrObject = getOutermostClassOrObject(classOrObject);
|
||||
return CachedValuesManager.getManager(classOrObject.getProject()).getCachedValue(
|
||||
outermostClassOrObject,
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
fun<!SYNTAX!><!> () {
|
||||
|
||||
}
|
||||
|
||||
<!REDECLARATION!>val<!SYNTAX!><!> : Int = 1<!>
|
||||
|
||||
<!REDECLARATION!>class<!SYNTAX!><!> {
|
||||
|
||||
}<!>
|
||||
|
||||
<!REDECLARATION!>object <!SYNTAX!><!>{
|
||||
|
||||
}<!>
|
||||
|
||||
<!REDECLARATION!>trait<!SYNTAX!><!> {
|
||||
|
||||
}<!>
|
||||
|
||||
<!REDECLARATION!>enum class<!SYNTAX!><!> {
|
||||
|
||||
}<!>
|
||||
|
||||
<!REDECLARATION!>annotation class<!SYNTAX!><!> <!ANNOTATION_CLASS_WITH_BODY!>{
|
||||
|
||||
}<!><!>
|
||||
|
||||
class Outer {
|
||||
fun<!SYNTAX!><!> () {
|
||||
|
||||
}
|
||||
|
||||
<!REDECLARATION!>val<!SYNTAX!><!> : Int = 1<!>
|
||||
|
||||
<!REDECLARATION!>class<!SYNTAX!><!> {
|
||||
|
||||
}<!>
|
||||
|
||||
<!REDECLARATION!>object <!SYNTAX!><!>{
|
||||
|
||||
}<!>
|
||||
|
||||
<!REDECLARATION!>trait<!SYNTAX!><!> {
|
||||
|
||||
}<!>
|
||||
|
||||
<!REDECLARATION!>enum class<!SYNTAX!><!> {
|
||||
|
||||
}<!>
|
||||
|
||||
<!REDECLARATION!>annotation class<!SYNTAX!><!> <!ANNOTATION_CLASS_WITH_BODY!>{
|
||||
|
||||
}<!><!>
|
||||
}
|
||||
@@ -2552,6 +2552,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/diagnostics/tests/duplicateJvmSignature"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("missingNames.kt")
|
||||
public void testMissingNames() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides")
|
||||
public static class AccidentalOverrides extends AbstractJetDiagnosticsTest {
|
||||
public void testAllFilesPresentInAccidentalOverrides() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user