Unused class removed

This commit is contained in:
Andrey Breslav
2014-09-11 21:50:10 +04:00
parent d25a76e044
commit bd21e487fc
5 changed files with 1 additions and 680 deletions
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMapBuilder;
/* package */ class CollectionClassMapping extends JavaToKotlinClassMapBuilder {
public class CollectionClassMapping extends JavaToKotlinClassMapBuilder {
private static CollectionClassMapping instance = null;
@NotNull
@@ -1,131 +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.lang.resolve.java.kotlinSignature;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Lists;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
import org.jetbrains.jet.lang.resolve.java.structure.JavaSignatureFormatter;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.*;
public class JavaToKotlinMethodMap {
public static final JavaToKotlinMethodMap INSTANCE = new JavaToKotlinMethodMap();
private final JavaToKotlinMethodMapGenerated mapContainer = new JavaToKotlinMethodMapGenerated();
private JavaToKotlinMethodMap() {
}
@NotNull
public List<FunctionDescriptor> getFunctions(
@NotNull JavaMethod javaMethod,
@NotNull FqName classFqName,
@NotNull ClassDescriptor containingClass
) {
ImmutableCollection<ClassData> classDatas = mapContainer.map.get(classFqName.asString());
List<FunctionDescriptor> result = Lists.newArrayList();
Set<ClassDescriptor> allSuperClasses = new HashSet<ClassDescriptor>(DescriptorUtils.getSuperclassDescriptors(containingClass));
String serializedMethod = JavaSignatureFormatter.getInstance().formatMethod(javaMethod);
for (ClassData classData : classDatas) {
String expectedSerializedFunction = classData.method2Function.get(serializedMethod);
if (expectedSerializedFunction == null) continue;
ClassDescriptor kotlinClass = classData.kotlinClass;
if (!allSuperClasses.contains(kotlinClass)) continue;
Collection<FunctionDescriptor> functions = kotlinClass.getDefaultType().getMemberScope().getFunctions(javaMethod.getName());
for (FunctionDescriptor function : functions) {
if (expectedSerializedFunction.equals(serializeFunction(function))) {
result.add(function);
}
}
}
return result;
}
@NotNull
public static String serializeFunction(@NotNull FunctionDescriptor fun) {
return DescriptorRenderer.COMPACT.render(fun);
}
// used in generated code
static Pair<String, String> pair(String a, String b) {
return Pair.create(a, b);
}
// used in generated code
static void put(
ImmutableMultimap.Builder<String, ClassData> builder,
String javaFqName,
String kotlinQualifiedName,
Pair<String, String>... methods2Functions
) {
ImmutableMap<String, String> methods2FunctionsMap = pairs2Map(methods2Functions);
ClassDescriptor kotlinClass;
if (kotlinQualifiedName.contains(".")) { // Map.Entry and MutableMap.MutableEntry
String[] kotlinNames = kotlinQualifiedName.split("\\.");
assert kotlinNames.length == 2 : "unexpected qualified name " + kotlinQualifiedName;
ClassDescriptor outerClass = KotlinBuiltIns.getInstance().getBuiltInClassByName(Name.identifier(kotlinNames[0]));
kotlinClass = DescriptorUtils.getInnerClassByName(outerClass, kotlinNames[1]);
assert kotlinClass != null : "Class not found: " + kotlinQualifiedName;
}
else {
kotlinClass = KotlinBuiltIns.getInstance().getBuiltInClassByName(Name.identifier(kotlinQualifiedName));
}
builder.put(javaFqName, new ClassData(kotlinClass, methods2FunctionsMap));
}
private static ImmutableMap<String, String> pairs2Map(Pair<String, String>[] pairs) {
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for (Pair<String, String> pair : pairs) {
builder.put(pair.first, pair.second);
}
return builder.build();
}
static class ClassData {
@NotNull
public final ClassDescriptor kotlinClass;
@NotNull
public Map<String, String> method2Function;
public ClassData(@NotNull ClassDescriptor kotlinClass, @NotNull Map<String, String> method2Function) {
this.kotlinClass = kotlinClass;
this.method2Function = method2Function;
}
}
}
@@ -1,254 +0,0 @@
/*
* Copyright 2010-2014 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.lang.resolve.java.kotlinSignature;
import com.google.common.collect.ImmutableMultimap;
import static org.jetbrains.jet.lang.resolve.java.kotlinSignature.JavaToKotlinMethodMap.*;
/* This file is generated by org.jetbrains.jet.generators.jvm.GenerateJavaToKotlinMethodMap. DO NOT EDIT! */
@SuppressWarnings("unchecked")
class JavaToKotlinMethodMapGenerated {
final ImmutableMultimap<String, JavaToKotlinMethodMap.ClassData> map;
JavaToKotlinMethodMapGenerated() {
ImmutableMultimap.Builder<String, JavaToKotlinMethodMap.ClassData> b = ImmutableMultimap.builder();
put(b, "java.lang.Object", "Any",
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("toString()", "fun toString(): kotlin.String")
);
put(b, "java.lang.String", "String",
pair("compareTo(java.lang.String)", "fun compareTo(other: kotlin.String): kotlin.Int"),
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("toString()", "fun toString(): kotlin.String")
);
put(b, "java.lang.CharSequence", "CharSequence",
pair("toString()", "fun toString(): kotlin.String")
);
put(b, "java.lang.Throwable", "Throwable",
pair("getCause()", "fun getCause(): kotlin.Throwable?"),
pair("getMessage()", "fun getMessage(): kotlin.String?"),
pair("printStackTrace()", "fun printStackTrace(): kotlin.Unit"),
pair("toString()", "fun toString(): kotlin.String")
);
put(b, "java.lang.Comparable", "Comparable",
pair("compareTo(T)", "fun compareTo(other: T): kotlin.Int")
);
put(b, "java.lang.Enum", "Enum",
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("name()", "fun name(): kotlin.String"),
pair("ordinal()", "fun ordinal(): kotlin.Int"),
pair("toString()", "fun toString(): kotlin.String")
);
put(b, "java.lang.annotation.Annotation", "Annotation",
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("toString()", "fun toString(): kotlin.String")
);
put(b, "java.lang.Iterable", "Iterable",
pair("iterator()", "fun iterator(): kotlin.Iterator<T>")
);
put(b, "java.lang.Iterable", "MutableIterable",
pair("iterator()", "fun iterator(): kotlin.MutableIterator<T>")
);
put(b, "java.util.Iterator", "Iterator",
pair("hasNext()", "fun hasNext(): kotlin.Boolean"),
pair("next()", "fun next(): T")
);
put(b, "java.util.Iterator", "MutableIterator",
pair("hasNext()", "fun hasNext(): kotlin.Boolean"),
pair("next()", "fun next(): T"),
pair("remove()", "fun remove(): kotlin.Unit")
);
put(b, "java.util.Collection", "Collection",
pair("contains(java.lang.Object)", "fun contains(o: kotlin.Any?): kotlin.Boolean"),
pair("containsAll(java.util.Collection<?>)", "fun containsAll(c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean"),
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("isEmpty()", "fun isEmpty(): kotlin.Boolean"),
pair("iterator()", "fun iterator(): kotlin.Iterator<E>"),
pair("size()", "fun size(): kotlin.Int")
);
put(b, "java.util.Collection", "MutableCollection",
pair("add(E)", "fun add(e: E): kotlin.Boolean"),
pair("addAll(java.util.Collection<? extends E>)", "fun addAll(c: kotlin.Collection<E>): kotlin.Boolean"),
pair("clear()", "fun clear(): kotlin.Unit"),
pair("contains(java.lang.Object)", "fun contains(o: kotlin.Any?): kotlin.Boolean"),
pair("containsAll(java.util.Collection<?>)", "fun containsAll(c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean"),
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("isEmpty()", "fun isEmpty(): kotlin.Boolean"),
pair("iterator()", "fun iterator(): kotlin.MutableIterator<E>"),
pair("remove(java.lang.Object)", "fun remove(o: kotlin.Any?): kotlin.Boolean"),
pair("removeAll(java.util.Collection<?>)", "fun removeAll(c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean"),
pair("retainAll(java.util.Collection<?>)", "fun retainAll(c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean"),
pair("size()", "fun size(): kotlin.Int")
);
put(b, "java.util.List", "List",
pair("contains(java.lang.Object)", "fun contains(o: kotlin.Any?): kotlin.Boolean"),
pair("containsAll(java.util.Collection<?>)", "fun containsAll(c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean"),
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("get(int)", "fun get(index: kotlin.Int): E"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("indexOf(java.lang.Object)", "fun indexOf(o: kotlin.Any?): kotlin.Int"),
pair("isEmpty()", "fun isEmpty(): kotlin.Boolean"),
pair("iterator()", "fun iterator(): kotlin.Iterator<E>"),
pair("lastIndexOf(java.lang.Object)", "fun lastIndexOf(o: kotlin.Any?): kotlin.Int"),
pair("listIterator()", "fun listIterator(): kotlin.ListIterator<E>"),
pair("listIterator(int)", "fun listIterator(index: kotlin.Int): kotlin.ListIterator<E>"),
pair("size()", "fun size(): kotlin.Int"),
pair("subList(int, int)", "fun subList(fromIndex: kotlin.Int, toIndex: kotlin.Int): kotlin.List<E>")
);
put(b, "java.util.List", "MutableList",
pair("add(E)", "fun add(e: E): kotlin.Boolean"),
pair("add(int, E)", "fun add(index: kotlin.Int, element: E): kotlin.Unit"),
pair("addAll(int, java.util.Collection<? extends E>)", "fun addAll(index: kotlin.Int, c: kotlin.Collection<E>): kotlin.Boolean"),
pair("addAll(java.util.Collection<? extends E>)", "fun addAll(c: kotlin.Collection<E>): kotlin.Boolean"),
pair("clear()", "fun clear(): kotlin.Unit"),
pair("contains(java.lang.Object)", "fun contains(o: kotlin.Any?): kotlin.Boolean"),
pair("containsAll(java.util.Collection<?>)", "fun containsAll(c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean"),
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("get(int)", "fun get(index: kotlin.Int): E"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("indexOf(java.lang.Object)", "fun indexOf(o: kotlin.Any?): kotlin.Int"),
pair("isEmpty()", "fun isEmpty(): kotlin.Boolean"),
pair("iterator()", "fun iterator(): kotlin.MutableIterator<E>"),
pair("lastIndexOf(java.lang.Object)", "fun lastIndexOf(o: kotlin.Any?): kotlin.Int"),
pair("listIterator()", "fun listIterator(): kotlin.MutableListIterator<E>"),
pair("listIterator(int)", "fun listIterator(index: kotlin.Int): kotlin.MutableListIterator<E>"),
pair("remove(int)", "fun remove(index: kotlin.Int): E"),
pair("remove(java.lang.Object)", "fun remove(o: kotlin.Any?): kotlin.Boolean"),
pair("removeAll(java.util.Collection<?>)", "fun removeAll(c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean"),
pair("retainAll(java.util.Collection<?>)", "fun retainAll(c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean"),
pair("set(int, E)", "fun set(index: kotlin.Int, element: E): E"),
pair("size()", "fun size(): kotlin.Int"),
pair("subList(int, int)", "fun subList(fromIndex: kotlin.Int, toIndex: kotlin.Int): kotlin.MutableList<E>")
);
put(b, "java.util.Set", "Set",
pair("contains(java.lang.Object)", "fun contains(o: kotlin.Any?): kotlin.Boolean"),
pair("containsAll(java.util.Collection<?>)", "fun containsAll(c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean"),
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("isEmpty()", "fun isEmpty(): kotlin.Boolean"),
pair("iterator()", "fun iterator(): kotlin.Iterator<E>"),
pair("size()", "fun size(): kotlin.Int")
);
put(b, "java.util.Set", "MutableSet",
pair("add(E)", "fun add(e: E): kotlin.Boolean"),
pair("addAll(java.util.Collection<? extends E>)", "fun addAll(c: kotlin.Collection<E>): kotlin.Boolean"),
pair("clear()", "fun clear(): kotlin.Unit"),
pair("contains(java.lang.Object)", "fun contains(o: kotlin.Any?): kotlin.Boolean"),
pair("containsAll(java.util.Collection<?>)", "fun containsAll(c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean"),
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("isEmpty()", "fun isEmpty(): kotlin.Boolean"),
pair("iterator()", "fun iterator(): kotlin.MutableIterator<E>"),
pair("remove(java.lang.Object)", "fun remove(o: kotlin.Any?): kotlin.Boolean"),
pair("removeAll(java.util.Collection<?>)", "fun removeAll(c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean"),
pair("retainAll(java.util.Collection<?>)", "fun retainAll(c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean"),
pair("size()", "fun size(): kotlin.Int")
);
put(b, "java.util.Map", "Map",
pair("containsKey(java.lang.Object)", "fun containsKey(key: kotlin.Any?): kotlin.Boolean"),
pair("containsValue(java.lang.Object)", "fun containsValue(value: kotlin.Any?): kotlin.Boolean"),
pair("entrySet()", "fun entrySet(): kotlin.Set<kotlin.Map.Entry<K, V>>"),
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("get(java.lang.Object)", "fun get(key: kotlin.Any?): V?"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("isEmpty()", "fun isEmpty(): kotlin.Boolean"),
pair("keySet()", "fun keySet(): kotlin.Set<K>"),
pair("size()", "fun size(): kotlin.Int"),
pair("values()", "fun values(): kotlin.Collection<V>")
);
put(b, "java.util.Map", "MutableMap",
pair("clear()", "fun clear(): kotlin.Unit"),
pair("containsKey(java.lang.Object)", "fun containsKey(key: kotlin.Any?): kotlin.Boolean"),
pair("containsValue(java.lang.Object)", "fun containsValue(value: kotlin.Any?): kotlin.Boolean"),
pair("entrySet()", "fun entrySet(): kotlin.MutableSet<kotlin.MutableMap.MutableEntry<K, V>>"),
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("get(java.lang.Object)", "fun get(key: kotlin.Any?): V?"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("isEmpty()", "fun isEmpty(): kotlin.Boolean"),
pair("keySet()", "fun keySet(): kotlin.MutableSet<K>"),
pair("put(K, V)", "fun put(key: K, value: V): V?"),
pair("putAll(java.util.Map<? extends K,? extends V>)", "fun putAll(m: kotlin.Map<out K, V>): kotlin.Unit"),
pair("remove(java.lang.Object)", "fun remove(key: kotlin.Any?): V?"),
pair("size()", "fun size(): kotlin.Int"),
pair("values()", "fun values(): kotlin.MutableCollection<V>")
);
put(b, "java.util.Map.Entry", "Map.Entry",
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("getKey()", "fun getKey(): K"),
pair("getValue()", "fun getValue(): V"),
pair("hashCode()", "fun hashCode(): kotlin.Int")
);
put(b, "java.util.Map.Entry", "MutableMap.MutableEntry",
pair("equals(java.lang.Object)", "fun equals(other: kotlin.Any?): kotlin.Boolean"),
pair("getKey()", "fun getKey(): K"),
pair("getValue()", "fun getValue(): V"),
pair("hashCode()", "fun hashCode(): kotlin.Int"),
pair("setValue(V)", "fun setValue(value: V): V")
);
put(b, "java.util.ListIterator", "ListIterator",
pair("hasNext()", "fun hasNext(): kotlin.Boolean"),
pair("hasPrevious()", "fun hasPrevious(): kotlin.Boolean"),
pair("next()", "fun next(): T"),
pair("nextIndex()", "fun nextIndex(): kotlin.Int"),
pair("previous()", "fun previous(): T"),
pair("previousIndex()", "fun previousIndex(): kotlin.Int")
);
put(b, "java.util.ListIterator", "MutableListIterator",
pair("add(E)", "fun add(e: T): kotlin.Unit"),
pair("hasNext()", "fun hasNext(): kotlin.Boolean"),
pair("hasPrevious()", "fun hasPrevious(): kotlin.Boolean"),
pair("next()", "fun next(): T"),
pair("nextIndex()", "fun nextIndex(): kotlin.Int"),
pair("previous()", "fun previous(): T"),
pair("previousIndex()", "fun previousIndex(): kotlin.Int"),
pair("remove()", "fun remove(): kotlin.Unit"),
pair("set(E)", "fun set(e: T): kotlin.Unit")
);
map = b.build();
}
}