Remove different usages of Guava and intellij-core from JDR

This commit is contained in:
Alexander Udalov
2013-08-16 21:34:06 +04:00
parent b9f96fe960
commit 28367a412a
21 changed files with 138 additions and 153 deletions
@@ -16,14 +16,14 @@
package org.jetbrains.jet.lang.resolve.java;
import com.google.common.collect.Maps;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.asm4.Type;
import java.util.HashMap;
import java.util.Map;
public class AsmTypeConstants {
private static final Map<Class<?>, Type> TYPES_MAP = Maps.newHashMap();
private static final Map<Class<?>, Type> TYPES_MAP = new HashMap<Class<?>, Type>();
public static final Type OBJECT_TYPE = getType(Object.class);
public static final Type JAVA_STRING_TYPE = getType(String.class);
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.java;
import com.google.common.collect.ImmutableSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
@@ -31,7 +30,6 @@ import java.util.*;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isEnumClassObject;
public final class DescriptorResolverUtils {
private static final ImmutableSet<String> OBJECT_METHODS = ImmutableSet.of("hashCode()", "equals(java.lang.Object)", "toString()");
private DescriptorResolverUtils() {
}
@@ -127,7 +125,9 @@ public final class DescriptorResolverUtils {
public static boolean isObjectMethod(@NotNull JavaMethod method) {
String signature = JavaSignatureFormatter.formatMethod(method);
return OBJECT_METHODS.contains(signature);
return "hashCode()".equals(signature) ||
"equals(java.lang.Object)".equals(signature) ||
"toString()".equals(signature);
}
@NotNull
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.java;
import com.google.common.collect.Lists;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.asm4.Type;
@@ -26,6 +25,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import java.util.ArrayList;
import java.util.List;
public class JvmClassName {
@@ -94,7 +94,7 @@ public class JvmClassName {
public static JvmClassName byClassDescriptor(@NotNull ClassifierDescriptor classDescriptor) {
DeclarationDescriptor descriptor = classDescriptor;
List<String> innerClassNames = Lists.newArrayList();
List<String> innerClassNames = new ArrayList<String>();
while (descriptor.getContainingDeclaration() instanceof ClassDescriptor) {
innerClassNames.add(descriptor.getName().asString());
descriptor = descriptor.getContainingDeclaration();
@@ -199,7 +199,7 @@ public class JvmClassName {
@NotNull
public List<String> getInnerClassNameList() {
List<String> innerClassList = Lists.newArrayList();
List<String> innerClassList = new ArrayList<String>();
String signatureName = getSignatureName();
int index = signatureName.indexOf('.');
while (index != -1) {
@@ -17,10 +17,7 @@
package org.jetbrains.jet.lang.resolve.java.mapping;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.intellij.psi.CommonClassNames;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
@@ -40,12 +37,11 @@ import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements PlatformToKotlinClassMap {
private static final FqName JAVA_LANG_DEPRECATED = new FqName("java.lang.Deprecated");
private static JavaToKotlinClassMap instance = null;
@NotNull
@@ -56,9 +52,9 @@ public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements
return instance;
}
private final Map<FqName, ClassDescriptor> classDescriptorMap = Maps.newHashMap();
private final Map<FqName, ClassDescriptor> classDescriptorMapForCovariantPositions = Maps.newHashMap();
private final Map<String, JetType> primitiveTypesMap = Maps.newHashMap();
private final Map<FqName, ClassDescriptor> classDescriptorMap = new HashMap<FqName, ClassDescriptor>();
private final Map<FqName, ClassDescriptor> classDescriptorMapForCovariantPositions = new HashMap<FqName, ClassDescriptor>();
private final Map<String, JetType> primitiveTypesMap = new HashMap<String, JetType>();
private final Multimap<FqName, ClassDescriptor> packagesWithMappedClasses = HashMultimap.create();
private JavaToKotlinClassMap() {
@@ -103,7 +99,7 @@ public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements
@Nullable
public AnnotationDescriptor mapToAnnotationClass(@NotNull FqName fqName) {
ClassDescriptor classDescriptor = classDescriptorMap.get(fqName);
if (classDescriptor != null && fqName.asString().equals(CommonClassNames.JAVA_LANG_DEPRECATED)) {
if (classDescriptor != null && fqName.equals(JAVA_LANG_DEPRECATED)) {
return getAnnotationDescriptorForJavaLangDeprecated(classDescriptor);
}
return null;
@@ -163,7 +159,7 @@ public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements
public Collection<ClassDescriptor> mapPlatformClass(@NotNull FqName fqName) {
ClassDescriptor kotlinAnalog = classDescriptorMap.get(fqName);
ClassDescriptor kotlinCovariantAnalog = classDescriptorMapForCovariantPositions.get(fqName);
List<ClassDescriptor> descriptors = Lists.newArrayList();
List<ClassDescriptor> descriptors = new ArrayList<ClassDescriptor>(2);
if (kotlinAnalog != null) {
descriptors.add(kotlinAnalog);
}
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.mapping;
import com.google.common.collect.Maps;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.asm4.Type;
@@ -30,6 +29,7 @@ import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
import java.util.HashMap;
import java.util.Map;
public class KotlinToJavaTypesMap extends JavaToKotlinClassMapBuilder {
@@ -43,8 +43,8 @@ public class KotlinToJavaTypesMap extends JavaToKotlinClassMapBuilder {
return instance;
}
private final Map<FqName, Type> asmTypes = Maps.newHashMap();
private final Map<FqName, Type> asmNullableTypes = Maps.newHashMap();
private final Map<FqName, Type> asmTypes = new HashMap<FqName, Type>();
private final Map<FqName, Type> asmNullableTypes = new HashMap<FqName, Type>();
private KotlinToJavaTypesMap() {
init();
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
@@ -35,6 +34,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule.INCLUDE_KOTLIN_SOURCES;
@@ -64,18 +64,24 @@ public final class JavaAnnotationResolver {
this.externalAnnotationResolver = externalAnnotationResolver;
}
private void resolveAnnotations(
@NotNull Collection<JavaAnnotation> annotations,
@NotNull PostponedTasks tasks,
@NotNull List<AnnotationDescriptor> result
) {
for (JavaAnnotation javaAnnotation : annotations) {
AnnotationDescriptor annotation = resolveAnnotation(javaAnnotation, tasks);
if (annotation != null) {
result.add(annotation);
}
}
}
@NotNull
public List<AnnotationDescriptor> resolveAnnotations(@NotNull JavaAnnotationOwner owner, @NotNull PostponedTasks tasks) {
List<AnnotationDescriptor> result = new ArrayList<AnnotationDescriptor>();
for (JavaAnnotation annotation : owner.getAnnotations()) {
ContainerUtil.addIfNotNull(result, resolveAnnotation(annotation, tasks));
}
for (JavaAnnotation annotation : externalAnnotationResolver.findExternalAnnotations(owner)) {
ContainerUtil.addIfNotNull(result, resolveAnnotation(annotation, tasks));
}
resolveAnnotations(owner.getAnnotations(), tasks, result);
resolveAnnotations(externalAnnotationResolver.findExternalAnnotations(owner), tasks, result);
return result;
}
@@ -16,14 +16,9 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import gnu.trove.THashMap;
import gnu.trove.TObjectHashingStrategy;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.descriptors.serialization.ClassId;
@@ -41,7 +36,6 @@ import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
import org.jetbrains.jet.lang.resolve.java.vfilefinder.VirtualFileFinder;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.FqNameBase;
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
@@ -62,27 +56,11 @@ import static org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule.INCLUDE_K
public final class JavaClassResolver {
private static final Logger LOG = Logger.getInstance(JavaClassResolver.class);
// NOTE: this complexity is introduced because class descriptors do not always have valid fqnames (class objects)
@NotNull
private final Map<FqNameBase, ClassDescriptor> classDescriptorCache =
new THashMap<FqNameBase, ClassDescriptor>(new TObjectHashingStrategy<FqNameBase>() {
@Override
public int computeHashCode(FqNameBase o) {
if (o instanceof FqName) {
return ((FqName) o).toUnsafe().hashCode();
}
assert o instanceof FqNameUnsafe;
return o.hashCode();
}
@Override
public boolean equals(FqNameBase n1, FqNameBase n2) {
return n1.equalsTo(n2.toString()) && n2.equalsTo(n1.toString());
}
});
private final Map<FqNameUnsafe, ClassDescriptor> classDescriptorCache = new HashMap<FqNameUnsafe, ClassDescriptor>();
@NotNull
private final Set<FqNameBase> unresolvedCache = Sets.newHashSet();
private final Set<FqNameUnsafe> unresolvedCache = new HashSet<FqNameUnsafe>();
private JavaResolverCache cache;
private JavaTypeParameterResolver typeParameterResolver;
@@ -220,7 +198,7 @@ public final class JavaClassResolver {
if (cachedDescriptor != null) {
return cachedDescriptor;
}
assert (!unresolvedCache.contains(qualifiedName))
assert !unresolvedCache.contains(qualifiedName.toUnsafe())
: "We can resolve the class, so it can't be 'unresolved' during parent resolution";
ClassId id = ClassId.fromFqNameAndContainingDeclaration(qualifiedName, containingDeclaration);
@@ -260,8 +238,8 @@ public final class JavaClassResolver {
if (cachedDescriptor != null) {
return cachedDescriptor;
}
assert (!unresolvedCache
.contains(qualifiedName)) : "We can resolve the class, so it can't be 'unresolved' during parent resolution";
assert !unresolvedCache.contains(qualifiedName.toUnsafe())
: "We can resolve the class, so it can't be 'unresolved' during parent resolution";
checkFqNamesAreConsistent(javaClass, qualifiedName);
@@ -271,11 +249,11 @@ public final class JavaClassResolver {
return doCreateClassDescriptor(qualifiedName, javaClass, tasks, containingDeclaration);
}
private void cacheNegativeValue(@NotNull FqNameBase qualifiedName) {
if (unresolvedCache.contains(qualifiedName) || classDescriptorCache.containsKey(qualifiedName)) {
throw new IllegalStateException("rewrite at " + qualifiedName);
private void cacheNegativeValue(@NotNull FqNameUnsafe fqNameUnsafe) {
if (unresolvedCache.contains(fqNameUnsafe) || classDescriptorCache.containsKey(fqNameUnsafe)) {
throw new IllegalStateException("rewrite at " + fqNameUnsafe);
}
unresolvedCache.add(qualifiedName);
unresolvedCache.add(fqNameUnsafe);
}
private static boolean isTraitImplementation(@NotNull FqName qualifiedName) {
@@ -300,7 +278,7 @@ public final class JavaClassResolver {
JavaTypeParameterResolver.Initializer typeParameterInitializer = typeParameterResolver.resolveTypeParameters(classDescriptor, javaClass);
classDescriptor.setTypeParameterDescriptors(typeParameterInitializer.getDescriptors());
List<JetType> supertypes = Lists.newArrayList();
List<JetType> supertypes = new ArrayList<JetType>();
classDescriptor.setSupertypes(supertypes);
classDescriptor.setVisibility(javaClass.getVisibility());
classDescriptor.setModality(javaClass.getModality());
@@ -363,7 +341,7 @@ public final class JavaClassResolver {
@NotNull
private static SimpleFunctionDescriptor findFunctionWithMostSpecificReturnType(@NotNull Set<JetType> supertypes) {
List<SimpleFunctionDescriptor> candidates = Lists.newArrayList();
List<SimpleFunctionDescriptor> candidates = new ArrayList<SimpleFunctionDescriptor>(supertypes.size());
for (JetType supertype : supertypes) {
List<CallableMemberDescriptor> abstractMembers = SingleAbstractMethodUtils.getAbstractMembers(supertype);
if (!abstractMembers.isEmpty()) {
@@ -385,7 +363,7 @@ public final class JavaClassResolver {
return currentMostSpecificType;
}
private void cache(@NotNull FqNameBase fqName, @Nullable ClassDescriptor classDescriptor) {
private void cache(@NotNull FqNameUnsafe fqName, @Nullable ClassDescriptor classDescriptor) {
if (classDescriptor == null) {
cacheNegativeValue(fqName);
}
@@ -437,7 +415,7 @@ public final class JavaClassResolver {
correctedSegments.add(segment);
}
}
return new FqNameUnsafe(StringUtil.join(correctedSegments, "."));
return FqNameUnsafe.fromSegments(correctedSegments);
}
private static boolean isInnerClass(@NotNull JavaClass javaClass) {
@@ -16,8 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.google.common.collect.Lists;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
@@ -34,10 +32,7 @@ import org.jetbrains.jet.lang.resolve.java.structure.JavaType;
import org.jetbrains.jet.lang.types.JetType;
import javax.inject.Inject;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import static org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils.createSamAdapterConstructor;
import static org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils.isSamAdapterNecessary;
@@ -73,7 +68,7 @@ public final class JavaConstructorResolver {
@NotNull
public Collection<ConstructorDescriptor> resolveConstructors(@NotNull JavaClass javaClass, @NotNull ClassDescriptor containingClass) {
Collection<ConstructorDescriptor> result = Lists.newArrayList();
Collection<ConstructorDescriptor> result = new ArrayList<ConstructorDescriptor>();
Collection<JavaMethod> constructors = javaClass.getConstructors();
@@ -81,13 +76,19 @@ public final class JavaConstructorResolver {
result.add(DescriptorResolver.createPrimaryConstructorForObject(containingClass));
}
else if (constructors.isEmpty()) {
ContainerUtil.addIfNotNull(result, resolveDefaultConstructor(javaClass, containingClass));
ConstructorDescriptor defaultConstructor = resolveDefaultConstructor(javaClass, containingClass);
if (defaultConstructor != null) {
result.add(defaultConstructor);
}
}
else {
for (JavaMethod constructor : constructors) {
ConstructorDescriptor descriptor = resolveConstructor(constructor, containingClass, javaClass.isStatic());
result.add(descriptor);
ContainerUtil.addIfNotNull(result, resolveSamAdapter(descriptor));
ConstructorDescriptor samAdapter = resolveSamAdapter(descriptor);
if (samAdapter != null) {
result.add(samAdapter);
}
}
}
@@ -139,10 +140,11 @@ public final class JavaConstructorResolver {
@NotNull TypeVariableResolver typeVariableResolver
) {
// A constructor for an annotation type takes all the "methods" in the @interface as parameters
List<ValueParameterDescriptor> result = Lists.newArrayList();
Collection<JavaMethod> methods = javaClass.getMethods();
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>(methods.size());
int index = 0;
for (Iterator<JavaMethod> iterator = javaClass.getMethods().iterator(); iterator.hasNext(); ) {
for (Iterator<JavaMethod> iterator = methods.iterator(); iterator.hasNext(); ) {
JavaMethod method = iterator.next();
assert method.getValueParameters().isEmpty() : "Annotation method can't have parameters: " + method;
@@ -16,8 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.google.common.collect.Sets;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
@@ -191,17 +189,23 @@ public final class JavaFunctionResolver {
public Set<FunctionDescriptor> resolveFunctionGroupForClass(@NotNull NamedMembers members, @NotNull ClassOrNamespaceDescriptor owner) {
Name methodName = members.getName();
Set<SimpleFunctionDescriptor> functionsFromCurrent = Sets.newHashSet();
Set<SimpleFunctionDescriptor> functionsFromCurrent = new HashSet<SimpleFunctionDescriptor>();
for (JavaMethod method : members.getMethods()) {
SimpleFunctionDescriptor function = resolveMethodToFunctionDescriptor(method, owner, true);
if (function != null) {
functionsFromCurrent.add(function);
ContainerUtil.addIfNotNull(functionsFromCurrent, resolveSamAdapter(function));
SimpleFunctionDescriptor samAdapter = resolveSamAdapter(function);
if (samAdapter != null) {
functionsFromCurrent.add(samAdapter);
}
}
}
if (owner instanceof NamespaceDescriptor) {
ContainerUtil.addIfNotNull(functionsFromCurrent, resolveSamConstructor((NamespaceDescriptor) owner, members));
SamConstructorDescriptor samConstructor = resolveSamConstructor((NamespaceDescriptor) owner, members);
if (samConstructor != null) {
functionsFromCurrent.add(samConstructor);
}
}
Set<FunctionDescriptor> functions = new HashSet<FunctionDescriptor>();
@@ -318,7 +322,7 @@ public final class JavaFunctionResolver {
@NotNull
private static Set<SimpleFunctionDescriptor> getFunctionsFromSupertypes(@NotNull Name name, @NotNull ClassDescriptor descriptor) {
Set<SimpleFunctionDescriptor> result = Sets.newLinkedHashSet();
Set<SimpleFunctionDescriptor> result = new LinkedHashSet<SimpleFunctionDescriptor>();
for (JetType supertype : descriptor.getTypeConstructor().getSupertypes()) {
for (FunctionDescriptor function : supertype.getMemberScope().getFunctions(name)) {
result.add((SimpleFunctionDescriptor) function);
@@ -16,8 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -54,9 +52,9 @@ public final class JavaNamespaceResolver {
JavaBridgeConfiguration.ALL_JAVA_IMPORTS,
JavaToKotlinClassMap.getInstance());
@NotNull
private final Map<FqName, JetScope> resolvedNamespaceCache = Maps.newHashMap();
private final Map<FqName, JetScope> resolvedNamespaceCache = new HashMap<FqName, JetScope>();
@NotNull
private final Set<FqName> unresolvedCache = Sets.newHashSet();
private final Set<FqName> unresolvedCache = new HashSet<FqName>();
private JavaClassFinder javaClassFinder;
private JavaResolverCache cache;
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
@@ -88,7 +87,7 @@ public final class JavaPropertyResolver {
}
}
Set<PropertyDescriptor> properties = Sets.newHashSet();
Set<PropertyDescriptor> properties = new HashSet<PropertyDescriptor>();
if (owner instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) owner;
@@ -100,7 +99,7 @@ public final class JavaPropertyResolver {
properties.addAll(propertiesFromCurrent);
return Sets.<VariableDescriptor>newHashSet(properties);
return new HashSet<VariableDescriptor>(properties);
}
@NotNull
@@ -16,8 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.intellij.openapi.diagnostic.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -136,7 +134,7 @@ public class JavaTypeTransformer {
) {
JavaTypeParameterListOwner owner = typeParameter.getOwner();
if (owner instanceof JavaMethod && ((JavaMethod) owner).isConstructor()) {
Set<JetType> supertypesJet = Sets.newHashSet();
Set<JetType> supertypesJet = new HashSet<JetType>();
for (JavaClassifierType supertype : typeParameter.getUpperBounds()) {
supertypesJet.add(transformToType(supertype, UPPER_BOUND, typeVariableResolver));
}
@@ -172,7 +170,7 @@ public class JavaTypeTransformer {
return null;
}
List<TypeProjection> arguments = Lists.newArrayList();
List<TypeProjection> arguments = new ArrayList<TypeProjection>();
List<TypeParameterDescriptor> parameters = classData.getTypeConstructor().getParameters();
if (isRaw(classifierType, !parameters.isEmpty())) {
for (TypeParameterDescriptor parameter : parameters) {
@@ -16,15 +16,15 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public final class PostponedTasks {
@NotNull
private final List<Runnable> tasks = Lists.newArrayList();
private final List<Runnable> tasks = new ArrayList<Runnable>();
public void addTask(@NotNull Runnable runnable) {
tasks.add(runnable);
@@ -16,8 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.intellij.openapi.util.Condition;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
@@ -32,19 +30,20 @@ import java.util.List;
@NotNull
private final DeclarationDescriptor owner;
public TypeVariableResolver(
@NotNull List<TypeParameterDescriptor> typeParameters,
@NotNull DeclarationDescriptor owner
) {
public TypeVariableResolver(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull DeclarationDescriptor owner) {
this.typeParameters = typeParameters;
this.owner = owner;
assert ContainerUtil.and(typeParameters, new Condition<TypeParameterDescriptor>() {
@Override
public boolean value(TypeParameterDescriptor descriptor) {
return descriptor.getContainingDeclaration() == TypeVariableResolver.this.owner;
assert parametersBelongToOwner() : "Type parameters should belong to owner: " + owner + "; " + typeParameters;
}
private boolean parametersBelongToOwner() {
for (TypeParameterDescriptor typeParameter : typeParameters) {
if (typeParameter.getContainingDeclaration() != owner) {
return false;
}
}) : "Type parameters should be parameters of owner: " + owner + "; " + typeParameters;
}
return true;
}
@NotNull
@@ -1,6 +1,5 @@
package org.jetbrains.jet.lang.resolve.java.sam;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
@@ -49,31 +48,32 @@ public class SamAdapterOverridabilityCondition implements ExternalOverridability
if (!(containingDeclaration instanceof ClassDescriptor)) {
return null;
}
Pair<SimpleFunctionDescriptor, JetType> declarationOrSynthesized =
SamAdapterInfo declarationOrSynthesized =
getNearestDeclarationOrSynthesized(callable, ((ClassDescriptor) containingDeclaration).getDefaultType());
if (declarationOrSynthesized == null) {
return null;
}
SimpleFunctionDescriptorImpl fun = (SimpleFunctionDescriptorImpl) declarationOrSynthesized.first.getOriginal();
SimpleFunctionDescriptorImpl fun = (SimpleFunctionDescriptorImpl) declarationOrSynthesized.samAdapter.getOriginal();
if (!(fun instanceof SamAdapterFunctionDescriptor)) {
return null;
}
SimpleFunctionDescriptor originalDeclarationOfSam = ((SamAdapterFunctionDescriptor) fun).getDeclaration();
return ((SimpleFunctionDescriptor) originalDeclarationOfSam.substitute(TypeSubstitutor.create(declarationOrSynthesized.second)));
return ((SimpleFunctionDescriptor) originalDeclarationOfSam.substitute(TypeSubstitutor.create(declarationOrSynthesized.ownerType)));
}
@Nullable
private static Pair<SimpleFunctionDescriptor, JetType> getNearestDeclarationOrSynthesized(
private static SamAdapterInfo getNearestDeclarationOrSynthesized(
@NotNull SimpleFunctionDescriptor samAdapter,
@NotNull JetType ownerType
) {
if (samAdapter.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
return Pair.create(samAdapter, ownerType);
return new SamAdapterInfo(samAdapter, ownerType);
}
for (CallableMemberDescriptor overridden : samAdapter.getOverriddenDescriptors()) {
ClassDescriptor containingClass = (ClassDescriptor) overridden.getContainingDeclaration();
@@ -82,15 +82,23 @@ public class SamAdapterOverridabilityCondition implements ExternalOverridability
continue;
}
Pair<SimpleFunctionDescriptor, JetType> found =
getNearestDeclarationOrSynthesized((SimpleFunctionDescriptor) overridden, immediateSupertype);
SamAdapterInfo found = getNearestDeclarationOrSynthesized((SimpleFunctionDescriptor) overridden, immediateSupertype);
if (found != null) {
return found;
}
}
}
return null;
}
private static class SamAdapterInfo {
private final SimpleFunctionDescriptor samAdapter;
private final JetType ownerType;
private SamAdapterInfo(@NotNull SimpleFunctionDescriptor samAdapter, @NotNull JetType ownerType) {
this.samAdapter = samAdapter;
this.ownerType = ownerType;
}
}
}
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.sam;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
@@ -46,7 +45,7 @@ public class SingleAbstractMethodUtils {
@NotNull
public static List<CallableMemberDescriptor> getAbstractMembers(@NotNull JetType type) {
List<CallableMemberDescriptor> abstractMembers = Lists.newArrayList();
List<CallableMemberDescriptor> abstractMembers = new ArrayList<CallableMemberDescriptor>();
for (DeclarationDescriptor member : type.getMemberScope().getAllDescriptors()) {
if (member instanceof CallableMemberDescriptor && ((CallableMemberDescriptor) member).getModality() == Modality.ABSTRACT) {
abstractMembers.add((CallableMemberDescriptor) member);
@@ -58,8 +57,9 @@ public class SingleAbstractMethodUtils {
private static JetType fixProjections(@NotNull JetType functionType) {
//removes redundant projection kinds and detects conflicts
List<TypeProjection> arguments = Lists.newArrayList();
for (TypeParameterDescriptor typeParameter : functionType.getConstructor().getParameters()) {
List<TypeParameterDescriptor> typeParameters = functionType.getConstructor().getParameters();
List<TypeProjection> arguments = new ArrayList<TypeProjection>(typeParameters.size());
for (TypeParameterDescriptor typeParameter : typeParameters) {
Variance variance = typeParameter.getVariance();
TypeProjection argument = functionType.getArguments().get(typeParameter.getIndex());
Variance kind = argument.getProjectionKind();
@@ -109,8 +109,9 @@ public class SingleAbstractMethodUtils {
public static JetType getFunctionTypeForAbstractMethod(@NotNull FunctionDescriptor function) {
JetType returnType = function.getReturnType();
assert returnType != null : "function is not initialized: " + function;
List<JetType> parameterTypes = Lists.newArrayList();
for (ValueParameterDescriptor parameter : function.getValueParameters()) {
List<ValueParameterDescriptor> valueParameters = function.getValueParameters();
List<JetType> parameterTypes = new ArrayList<JetType>(valueParameters.size());
for (ValueParameterDescriptor parameter : valueParameters) {
parameterTypes.add(parameter.getType());
}
return KotlinBuiltIns.getInstance().getFunctionType(
@@ -245,8 +246,9 @@ public class SingleAbstractMethodUtils {
", substitutor = " + typeParameters.substitutor;
}
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
for (ValueParameterDescriptor originalParam : original.getValueParameters()) {
List<ValueParameterDescriptor> originalValueParameters = original.getValueParameters();
List<ValueParameterDescriptor> valueParameters = new ArrayList<ValueParameterDescriptor>(originalValueParameters.size());
for (ValueParameterDescriptor originalParam : originalValueParameters) {
JetType originalType = originalParam.getType();
JetType functionType = getFunctionTypeForSamType(originalType);
JetType newTypeUnsubstituted = functionType != null ? functionType : originalType;
@@ -284,7 +286,7 @@ public class SingleAbstractMethodUtils {
funTypeParameter.setInitialized();
}
List<TypeParameterDescriptor> typeParameters = Lists.<TypeParameterDescriptor>newArrayList(traitToFunTypeParameters.values());
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>(traitToFunTypeParameters.values());
return new TypeParameters(typeParameters, typeParametersSubstitutor);
}
@@ -16,12 +16,7 @@
package org.jetbrains.jet.lang.resolve.java.scope;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
import com.intellij.openapi.util.Condition;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
@@ -37,9 +32,9 @@ public abstract class JavaBaseScope extends JetScopeImpl {
@NotNull
protected final MembersProvider membersProvider;
@NotNull
private final Map<Name, Set<FunctionDescriptor>> functionDescriptors = Maps.newHashMap();
private final Map<Name, Set<FunctionDescriptor>> functionDescriptors = new HashMap<Name, Set<FunctionDescriptor>>();
@NotNull
private final Map<Name, Set<VariableDescriptor>> propertyDescriptors = Maps.newHashMap();
private final Map<Name, Set<VariableDescriptor>> propertyDescriptors = new HashMap<Name, Set<VariableDescriptor>>();
@Nullable
private Collection<DeclarationDescriptor> allDescriptors = null;
@Nullable
@@ -126,7 +121,7 @@ public abstract class JavaBaseScope extends JetScopeImpl {
@NotNull
protected Collection<DeclarationDescriptor> computeAllDescriptors() {
Collection<DeclarationDescriptor> result = Sets.newHashSet();
Collection<DeclarationDescriptor> result = new HashSet<DeclarationDescriptor>();
result.addAll(computeFieldAndFunctionDescriptors());
result.addAll(filterObjects(getInnerClasses(), false));
return result;
@@ -146,7 +141,7 @@ public abstract class JavaBaseScope extends JetScopeImpl {
@NotNull
private Collection<DeclarationDescriptor> computeFieldAndFunctionDescriptors() {
Collection<DeclarationDescriptor> result = Lists.newArrayList();
Collection<DeclarationDescriptor> result = new ArrayList<DeclarationDescriptor>();
for (NamedMembers members : membersProvider.allMembers()) {
Name name = members.getName();
ProgressIndicatorProvider.checkCanceled();
@@ -165,12 +160,14 @@ public abstract class JavaBaseScope extends JetScopeImpl {
return innerClasses;
}
private static <T extends ClassDescriptor> Collection<T> filterObjects(Collection<T> classes, final boolean objects) {
return ContainerUtil.filter(classes, new Condition<T>() {
@Override
public boolean value(T classDescriptor) {
return classDescriptor.getKind().isObject() == objects;
@NotNull
private static Collection<ClassDescriptor> filterObjects(@NotNull Collection<ClassDescriptor> classes, boolean objects) {
List<ClassDescriptor> result = new ArrayList<ClassDescriptor>();
for (ClassDescriptor descriptor : classes) {
if (descriptor.getKind().isObject() == objects) {
result.add(descriptor);
}
});
}
return result;
}
}
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.scope;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
@@ -58,7 +57,10 @@ public final class JavaClassStaticMembersScope extends JavaClassMembersScope {
protected Collection<DeclarationDescriptor> computeAllDescriptors() {
Collection<DeclarationDescriptor> result = super.computeAllDescriptors();
for (JavaClass nested : javaClass.getInnerClasses()) {
ContainerUtil.addIfNotNull(result, getNamespace(nested.getName()));
NamespaceDescriptor namespace = getNamespace(nested.getName());
if (namespace != null) {
result.add(namespace);
}
}
return result;
}
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.scope;
import com.google.common.collect.Sets;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.*;
@@ -29,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import static org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule.IGNORE_KOTLIN_SOURCES;
@@ -84,7 +84,7 @@ public final class JavaPackageScope extends JavaBaseScope {
@NotNull
private Collection<DeclarationDescriptor> computeAllPackageDeclarations() {
Collection<DeclarationDescriptor> result = Sets.newHashSet();
Collection<DeclarationDescriptor> result = new HashSet<DeclarationDescriptor>();
for (JavaPackage subPackage : javaPackage.getSubPackages()) {
NamespaceDescriptor childNs = memberResolver.resolveNamespace(subPackage.getFqName(), IGNORE_KOTLIN_SOURCES);
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.scope;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
@@ -24,6 +23,7 @@ import org.jetbrains.jet.lang.resolve.java.structure.JavaField;
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.ArrayList;
import java.util.List;
public final class NamedMembers {
@@ -36,10 +36,10 @@ public final class NamedMembers {
private final Name name;
@NotNull
private final List<JavaMethod> methods = Lists.newArrayList();
private final List<JavaMethod> methods = new ArrayList<JavaMethod>();
@NotNull
private final List<JavaField> fields = Lists.newArrayList();
private final List<JavaField> fields = new ArrayList<JavaField>();
@Nullable
private JavaClass samInterface;