Delete signature name from JvmClassName
This commit is contained in:
@@ -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.<String>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.<String>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<String> innerClassNameList
|
||||
) {
|
||||
JvmClassName mapEntryName = JvmClassName.bySignatureName(className);
|
||||
assertEquals(innerClassName, mapEntryName.getInternalName());
|
||||
assertEquals(fqName, mapEntryName.getFqName().asString());
|
||||
assertEquals(outerClassName, mapEntryName.getOuterClassFqName().asString());
|
||||
assertEquals(innerClassNameList, mapEntryName.getInnerClassNameList());
|
||||
}
|
||||
}
|
||||
+3
-70
@@ -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 = "<class_object>";
|
||||
private final static String TRAIT_IMPL_REPLACE_GUARD = "<trait_impl>";
|
||||
|
||||
// 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<String> getInnerClassNameList() {
|
||||
List<String> innerClassList = new ArrayList<String>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class DebuggerUtils {
|
||||
JetFilesProvider filesProvider = JetFilesProvider.getInstance(searchScope.getProject());
|
||||
Collection<JetFile> 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<JetFile> files = Collections2.filter(filesInScope, new Predicate<JetFile>() {
|
||||
@@ -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('/', '.'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user