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()));
|
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) {
|
private static String encodeSpecialNames(String str) {
|
||||||
String encodedObjectNames = StringUtil.replace(str, JvmAbi.CLASS_OBJECT_CLASS_NAME, CLASS_OBJECT_REPLACE_GUARD);
|
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);
|
return StringUtil.replace(encodedObjectNames, JvmAbi.TRAIT_IMPL_CLASS_NAME, TRAIT_IMPL_REPLACE_GUARD);
|
||||||
@@ -109,39 +102,20 @@ public class JvmClassName {
|
|||||||
return fqName.asString().replace('.', '/');
|
return fqName.asString().replace('.', '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static String signatureNameToInternalName(@NotNull String signatureName) {
|
|
||||||
return signatureName.replace('.', '$');
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static String internalNameToFqName(@NotNull String name) {
|
private static String internalNameToFqName(@NotNull String name) {
|
||||||
return decodeSpecialNames(encodeSpecialNames(name).replace('$', '.').replace('/', '.'));
|
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 CLASS_OBJECT_REPLACE_GUARD = "<class_object>";
|
||||||
private final static String TRAIT_IMPL_REPLACE_GUARD = "<trait_impl>";
|
private final static String TRAIT_IMPL_REPLACE_GUARD = "<trait_impl>";
|
||||||
|
|
||||||
// Internal name: jet/Map$Entry
|
// Internal name: jet/Map$Entry
|
||||||
// FqName: jet.Map.Entry
|
// FqName: jet.Map.Entry
|
||||||
// Signature name: jet/Map.Entry
|
|
||||||
|
|
||||||
private final String internalName;
|
private final String internalName;
|
||||||
private FqName fqName;
|
private FqName fqName;
|
||||||
private String descriptor;
|
private String descriptor;
|
||||||
private String signatureName;
|
|
||||||
|
|
||||||
private Type asmType;
|
private Type asmType;
|
||||||
|
|
||||||
private JvmClassName(@NotNull String internalName) {
|
private JvmClassName(@NotNull String internalName) {
|
||||||
@@ -151,7 +125,7 @@ public class JvmClassName {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public FqName getFqName() {
|
public FqName getFqName() {
|
||||||
if (fqName == null) {
|
if (fqName == null) {
|
||||||
this.fqName = new FqName(internalNameToFqName(internalName));
|
fqName = new FqName(internalNameToFqName(internalName));
|
||||||
}
|
}
|
||||||
return fqName;
|
return fqName;
|
||||||
}
|
}
|
||||||
@@ -164,11 +138,7 @@ public class JvmClassName {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public String getDescriptor() {
|
public String getDescriptor() {
|
||||||
if (descriptor == null) {
|
if (descriptor == null) {
|
||||||
StringBuilder sb = new StringBuilder(internalName.length() + 2);
|
descriptor = "L" + internalName + ';';
|
||||||
sb.append('L');
|
|
||||||
sb.append(internalName);
|
|
||||||
sb.append(';');
|
|
||||||
descriptor = sb.toString();
|
|
||||||
}
|
}
|
||||||
return descriptor;
|
return descriptor;
|
||||||
}
|
}
|
||||||
@@ -181,36 +151,6 @@ public class JvmClassName {
|
|||||||
return asmType;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getInternalName();
|
return getInternalName();
|
||||||
@@ -218,20 +158,13 @@ public class JvmClassName {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
// generated by Idea
|
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
return internalName.equals(((JvmClassName) o).internalName);
|
||||||
JvmClassName name = (JvmClassName) o;
|
|
||||||
|
|
||||||
if (!internalName.equals(name.internalName)) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
// generated by Idea
|
|
||||||
return internalName.hashCode();
|
return internalName.hashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class DebuggerUtils {
|
|||||||
JetFilesProvider filesProvider = JetFilesProvider.getInstance(searchScope.getProject());
|
JetFilesProvider filesProvider = JetFilesProvider.getInstance(searchScope.getProject());
|
||||||
Collection<JetFile> filesInScope = filesProvider.allInScope(searchScope);
|
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
|
// 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>() {
|
Collection<JetFile> files = Collections2.filter(filesInScope, new Predicate<JetFile>() {
|
||||||
@@ -76,4 +76,11 @@ public class DebuggerUtils {
|
|||||||
|
|
||||||
return PsiCodegenPredictor.getFileForCodegenNamedClass(analyzeExhaust.getBindingContext(), allNamespaceFiles, className);
|
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