diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/JvmClassNameTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/JvmClassNameTest.java deleted file mode 100644 index 073d95b9e91..00000000000 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/JvmClassNameTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.jvm.compiler; - -import com.google.common.collect.Lists; -import org.jetbrains.jet.lang.resolve.java.JvmClassName; -import org.junit.Test; - -import java.util.Collections; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -public class JvmClassNameTest { - @Test - public void signatureName() { - testSignatureName("jet/Map", "jet/Map", "jet.Map", "jet.Map", Collections.emptyList()); - } - - @Test - public void signatureNameOfInnerClass() { - testSignatureName("jet/Map.Entry", "jet/Map$Entry", "jet.Map.Entry", "jet.Map", Lists.newArrayList("Entry")); - } - - @Test - public void signatureNameOfDeepInnerClass() { - testSignatureName("jet/Map.Entry.AAA", "jet/Map$Entry$AAA", "jet.Map.Entry.AAA", "jet.Map", Lists.newArrayList("Entry", "AAA")); - } - - @Test - public void simpleName() { - testSignatureName("jet", "jet", "jet", "jet", Collections.emptyList()); - } - - @Test - public void incorrectSignature() { - testSignatureName("jet/Map.", "jet/Map$", "jet.Map.", "jet.Map", Lists.newArrayList("")); - - } - - private static void testSignatureName( - String className, - String innerClassName, - String fqName, - String outerClassName, - List innerClassNameList - ) { - JvmClassName mapEntryName = JvmClassName.bySignatureName(className); - assertEquals(innerClassName, mapEntryName.getInternalName()); - assertEquals(fqName, mapEntryName.getFqName().asString()); - assertEquals(outerClassName, mapEntryName.getOuterClassFqName().asString()); - assertEquals(innerClassNameList, mapEntryName.getInnerClassNameList()); - } -} diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java index 01defadf8b4..88fb99b2692 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java @@ -63,13 +63,6 @@ public class JvmClassName { return byFqNameWithoutInnerClasses(new FqName(klass.getCanonicalName())); } - @NotNull - public static JvmClassName bySignatureName(@NotNull String signatureName) { - JvmClassName className = new JvmClassName(signatureNameToInternalName(signatureName)); - className.signatureName = signatureName; - return className; - } - private static String encodeSpecialNames(String str) { String encodedObjectNames = StringUtil.replace(str, JvmAbi.CLASS_OBJECT_CLASS_NAME, CLASS_OBJECT_REPLACE_GUARD); return StringUtil.replace(encodedObjectNames, JvmAbi.TRAIT_IMPL_CLASS_NAME, TRAIT_IMPL_REPLACE_GUARD); @@ -109,39 +102,20 @@ public class JvmClassName { return fqName.asString().replace('.', '/'); } - @NotNull - private static String signatureNameToInternalName(@NotNull String signatureName) { - return signatureName.replace('.', '$'); - } - @NotNull private static String internalNameToFqName(@NotNull String name) { return decodeSpecialNames(encodeSpecialNames(name).replace('$', '.').replace('/', '.')); } - @NotNull - private static String internalNameToSignatureName(@NotNull String name) { - return decodeSpecialNames(encodeSpecialNames(name).replace('$', '.')); - } - - @NotNull - private static String signatureNameToFqName(@NotNull String name) { - return name.replace('/', '.'); - } - - private final static String CLASS_OBJECT_REPLACE_GUARD = ""; private final static String TRAIT_IMPL_REPLACE_GUARD = ""; // Internal name: jet/Map$Entry // FqName: jet.Map.Entry - // Signature name: jet/Map.Entry private final String internalName; private FqName fqName; private String descriptor; - private String signatureName; - private Type asmType; private JvmClassName(@NotNull String internalName) { @@ -151,7 +125,7 @@ public class JvmClassName { @NotNull public FqName getFqName() { if (fqName == null) { - this.fqName = new FqName(internalNameToFqName(internalName)); + fqName = new FqName(internalNameToFqName(internalName)); } return fqName; } @@ -164,11 +138,7 @@ public class JvmClassName { @NotNull public String getDescriptor() { if (descriptor == null) { - StringBuilder sb = new StringBuilder(internalName.length() + 2); - sb.append('L'); - sb.append(internalName); - sb.append(';'); - descriptor = sb.toString(); + descriptor = "L" + internalName + ';'; } return descriptor; } @@ -181,36 +151,6 @@ public class JvmClassName { return asmType; } - @NotNull - public String getSignatureName() { - if (signatureName == null) { - signatureName = internalNameToSignatureName(internalName); - } - return signatureName; - } - - @NotNull - public FqName getOuterClassFqName() { - String signatureName = getSignatureName(); - int index = signatureName.indexOf('.'); - String outerClassName = index != -1 ? signatureName.substring(0, index) : signatureName; - return new FqName(signatureNameToFqName(outerClassName)); - } - - @NotNull - public List getInnerClassNameList() { - List innerClassList = new ArrayList(); - String signatureName = getSignatureName(); - int index = signatureName.indexOf('.'); - while (index != -1) { - int nextIndex = signatureName.indexOf('.', index + 1); - String innerClassName = nextIndex != -1 ? signatureName.substring(index + 1, nextIndex) : signatureName.substring(index + 1); - innerClassList.add(innerClassName); - index = nextIndex; - } - return innerClassList; - } - @Override public String toString() { return getInternalName(); @@ -218,20 +158,13 @@ public class JvmClassName { @Override public boolean equals(Object o) { - // generated by Idea if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - - JvmClassName name = (JvmClassName) o; - - if (!internalName.equals(name.internalName)) return false; - - return true; + return internalName.equals(((JvmClassName) o).internalName); } @Override public int hashCode() { - // generated by Idea return internalName.hashCode(); } } diff --git a/idea/src/org/jetbrains/jet/plugin/util/DebuggerUtils.java b/idea/src/org/jetbrains/jet/plugin/util/DebuggerUtils.java index d47cb6cdb76..b090f2737a4 100644 --- a/idea/src/org/jetbrains/jet/plugin/util/DebuggerUtils.java +++ b/idea/src/org/jetbrains/jet/plugin/util/DebuggerUtils.java @@ -45,7 +45,7 @@ public class DebuggerUtils { JetFilesProvider filesProvider = JetFilesProvider.getInstance(searchScope.getProject()); Collection filesInScope = filesProvider.allInScope(searchScope); - final FqName packageFqName = className.getOuterClassFqName().parent(); + final FqName packageFqName = getPackageFqNameForClass(className); // Only consider files with the file name from the stack trace and in the given package Collection files = Collections2.filter(filesInScope, new Predicate() { @@ -76,4 +76,11 @@ public class DebuggerUtils { return PsiCodegenPredictor.getFileForCodegenNamedClass(analyzeExhaust.getBindingContext(), allNamespaceFiles, className); } + + @NotNull + private static FqName getPackageFqNameForClass(@NotNull JvmClassName className) { + String internalName = className.getInternalName(); + int lastSlash = internalName.lastIndexOf('/'); + return lastSlash == -1 ? FqName.ROOT : new FqName(internalName.substring(0, lastSlash).replace('/', '.')); + } }