Remove dependency of "descriptors" on Maps/Sets

This commit is contained in:
Alexander Udalov
2014-08-14 15:50:05 +04:00
parent 9bc7d27fe1
commit 2055d4d72c
19 changed files with 76 additions and 97 deletions
@@ -16,12 +16,13 @@
package org.jetbrains.jet.lang.descriptors; package org.jetbrains.jet.lang.descriptors;
import com.google.common.collect.Maps; import kotlin.KotlinPackage;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.utils.UtilsPackage;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -108,7 +109,8 @@ public class Visibilities {
} }
}; };
public static final Set<Visibility> INVISIBLE_FROM_OTHER_MODULES = Sets.newHashSet(PRIVATE, INTERNAL, LOCAL); public static final Set<Visibility> INVISIBLE_FROM_OTHER_MODULES =
Collections.unmodifiableSet(KotlinPackage.setOf(PRIVATE, INTERNAL, LOCAL));
private Visibilities() { private Visibilities() {
} }
@@ -132,13 +134,15 @@ public class Visibilities {
return null; return null;
} }
private static final Map<Visibility, Integer> ORDERED_VISIBILITIES = Maps.newHashMap(); private static final Map<Visibility, Integer> ORDERED_VISIBILITIES;
static { static {
ORDERED_VISIBILITIES.put(PRIVATE, 0); Map<Visibility, Integer> visibilities = UtilsPackage.newHashMapWithExpectedSize(4);
ORDERED_VISIBILITIES.put(INTERNAL, 1); visibilities.put(PRIVATE, 0);
ORDERED_VISIBILITIES.put(PROTECTED, 1); visibilities.put(INTERNAL, 1);
ORDERED_VISIBILITIES.put(PUBLIC, 2); visibilities.put(PROTECTED, 1);
visibilities.put(PUBLIC, 2);
ORDERED_VISIBILITIES = Collections.unmodifiableMap(visibilities);
} }
/*package*/ /*package*/
@@ -16,16 +16,12 @@
package org.jetbrains.jet.lang.descriptors.impl; package org.jetbrains.jet.lang.descriptors.impl;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor; import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor;
import org.jetbrains.jet.lang.descriptors.PackageFragmentProvider; import org.jetbrains.jet.lang.descriptors.PackageFragmentProvider;
import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqName;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.List;
import java.util.Set;
public class CompositePackageFragmentProvider implements PackageFragmentProvider { public class CompositePackageFragmentProvider implements PackageFragmentProvider {
// can be modified from outside // can be modified from outside
@@ -49,7 +45,7 @@ public class CompositePackageFragmentProvider implements PackageFragmentProvider
@NotNull @NotNull
@Override @Override
public Collection<FqName> getSubPackagesOf(@NotNull FqName fqName) { public Collection<FqName> getSubPackagesOf(@NotNull FqName fqName) {
Set<FqName> result = Sets.newHashSet(); Set<FqName> result = new HashSet<FqName>();
for (PackageFragmentProvider provider : providers) { for (PackageFragmentProvider provider : providers) {
result.addAll(provider.getSubPackagesOf(fqName)); result.addAll(provider.getSubPackagesOf(fqName));
} }
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.descriptors.impl; package org.jetbrains.jet.lang.descriptors.impl;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
@@ -30,20 +29,19 @@ import org.jetbrains.jet.lang.types.TypeSubstitutor;
import org.jetbrains.jet.lang.types.Variance; import org.jetbrains.jet.lang.types.Variance;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRootImpl implements FunctionDescriptor { public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRootImpl implements FunctionDescriptor {
private List<TypeParameterDescriptor> typeParameters;
protected List<TypeParameterDescriptor> typeParameters; private List<ValueParameterDescriptor> unsubstitutedValueParameters;
protected List<ValueParameterDescriptor> unsubstitutedValueParameters; private JetType unsubstitutedReturnType;
protected JetType unsubstitutedReturnType;
private ReceiverParameterDescriptor receiverParameter; private ReceiverParameterDescriptor receiverParameter;
protected ReceiverParameterDescriptor expectedThisObject; private ReceiverParameterDescriptor expectedThisObject;
protected Modality modality; private Modality modality;
private Visibility visibility;
protected Visibility visibility; private final Set<FunctionDescriptor> overriddenFunctions = new LinkedHashSet<FunctionDescriptor>(); // LinkedHashSet is essential here
protected final Set<FunctionDescriptor> overriddenFunctions = Sets.newLinkedHashSet(); // LinkedHashSet is essential here
private final FunctionDescriptor original; private final FunctionDescriptor original;
private final Kind kind; private final Kind kind;
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.descriptors.impl; package org.jetbrains.jet.lang.descriptors.impl;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
@@ -25,6 +24,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.TypeSubstitutor; import org.jetbrains.jet.lang.types.TypeSubstitutor;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -144,7 +144,8 @@ public abstract class PropertyAccessorDescriptorImpl extends DeclarationDescript
@NotNull @NotNull
protected Set<PropertyAccessorDescriptor> getOverriddenDescriptors(boolean isGetter) { protected Set<PropertyAccessorDescriptor> getOverriddenDescriptors(boolean isGetter) {
Set<? extends PropertyDescriptor> overriddenProperties = getCorrespondingProperty().getOverriddenDescriptors(); Set<? extends PropertyDescriptor> overriddenProperties = getCorrespondingProperty().getOverriddenDescriptors();
Set<PropertyAccessorDescriptor> overriddenAccessors = Sets.newLinkedHashSet(); // LinkedHashSet for determinism // LinkedHashSet for determinism
Set<PropertyAccessorDescriptor> overriddenAccessors = new LinkedHashSet<PropertyAccessorDescriptor>();
for (PropertyDescriptor overriddenProperty : overriddenProperties) { for (PropertyDescriptor overriddenProperty : overriddenProperties) {
PropertyAccessorDescriptor accessorDescriptor = isGetter ? overriddenProperty.getGetter() : overriddenProperty.getSetter(); PropertyAccessorDescriptor accessorDescriptor = isGetter ? overriddenProperty.getGetter() : overriddenProperty.getSetter();
if (accessorDescriptor != null) { if (accessorDescriptor != null) {
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.descriptors.impl; package org.jetbrains.jet.lang.descriptors.impl;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
@@ -30,17 +29,13 @@ import org.jetbrains.jet.lang.types.TypeSubstitutor;
import org.jetbrains.jet.lang.types.Variance; import org.jetbrains.jet.lang.types.Variance;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Set;
public class PropertyDescriptorImpl extends VariableDescriptorImpl implements PropertyDescriptor { public class PropertyDescriptorImpl extends VariableDescriptorImpl implements PropertyDescriptor {
private final Modality modality; private final Modality modality;
private Visibility visibility; private Visibility visibility;
private final boolean isVar; private final boolean isVar;
private final Set<PropertyDescriptor> overriddenProperties = Sets.newLinkedHashSet(); // LinkedHashSet is essential here private final Set<PropertyDescriptor> overriddenProperties = new LinkedHashSet<PropertyDescriptor>(); // LinkedHashSet is essential here
private final PropertyDescriptor original; private final PropertyDescriptor original;
private final Kind kind; private final Kind kind;
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.descriptors.impl; package org.jetbrains.jet.lang.descriptors.impl;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.SourceElement; import org.jetbrains.jet.lang.descriptors.SourceElement;
@@ -32,6 +31,7 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.storage.LockBasedStorageManager; import org.jetbrains.jet.storage.LockBasedStorageManager;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor { public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor {
@@ -62,7 +62,7 @@ public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor
return new TypeParameterDescriptorImpl(containingDeclaration, annotations, reified, variance, name, index, source); return new TypeParameterDescriptorImpl(containingDeclaration, annotations, reified, variance, name, index, source);
} }
private final Set<JetType> upperBounds = Sets.newLinkedHashSet(); private final Set<JetType> upperBounds = new LinkedHashSet<JetType>();
private boolean initialized = false; private boolean initialized = false;
private TypeParameterDescriptorImpl( private TypeParameterDescriptorImpl(
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.descriptors.impl; package org.jetbrains.jet.lang.descriptors.impl;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
@@ -26,17 +25,16 @@ import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeSubstitutor; import org.jetbrains.jet.lang.types.TypeSubstitutor;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
public class ValueParameterDescriptorImpl extends VariableDescriptorImpl implements ValueParameterDescriptor { public class ValueParameterDescriptorImpl extends VariableDescriptorImpl implements ValueParameterDescriptor {
private Boolean hasDefaultValue; private Boolean hasDefaultValue;
private final boolean declaresDefaultValue; private final boolean declaresDefaultValue;
private final JetType varargElementType; private final JetType varargElementType;
private final int index; private final int index;
private final ValueParameterDescriptor original; private final ValueParameterDescriptor original;
private final Set<ValueParameterDescriptor> overriddenDescriptors = new LinkedHashSet<ValueParameterDescriptor>(); // Linked is essential
private final Set<ValueParameterDescriptor> overriddenDescriptors = Sets.newLinkedHashSet(); // Linked is essential
private boolean overriddenDescriptorsLocked = false; private boolean overriddenDescriptorsLocked = false;
private final Set<? extends ValueParameterDescriptor> readOnlyOverriddenDescriptors = Collections.unmodifiableSet(overriddenDescriptors); private final Set<? extends ValueParameterDescriptor> readOnlyOverriddenDescriptors = Collections.unmodifiableSet(overriddenDescriptors);
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve; package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.Sets;
import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.ContainerUtil;
import kotlin.Function1; import kotlin.Function1;
import kotlin.KotlinPackage; import kotlin.KotlinPackage;
@@ -250,7 +249,7 @@ public class OverridingUtil {
@NotNull ClassDescriptor current, @NotNull ClassDescriptor current,
@NotNull DescriptorSink sink @NotNull DescriptorSink sink
) { ) {
Collection<CallableMemberDescriptor> notOverridden = Sets.newLinkedHashSet(membersFromSupertypes); Collection<CallableMemberDescriptor> notOverridden = new LinkedHashSet<CallableMemberDescriptor>(membersFromSupertypes);
for (CallableMemberDescriptor fromCurrent : membersFromCurrent) { for (CallableMemberDescriptor fromCurrent : membersFromCurrent) {
Collection<CallableMemberDescriptor> bound = Collection<CallableMemberDescriptor> bound =
@@ -16,13 +16,13 @@
package org.jetbrains.jet.lang.resolve.calls.inference; package org.jetbrains.jet.lang.resolve.calls.inference;
import com.google.common.collect.Maps;
import kotlin.Function1; import kotlin.Function1;
import kotlin.KotlinPackage; import kotlin.KotlinPackage;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class ConstraintPosition { public class ConstraintPosition {
@@ -31,8 +31,8 @@ public class ConstraintPosition {
public static final ConstraintPosition FROM_COMPLETER = new ConstraintPosition("FROM_COMPLETER", true); public static final ConstraintPosition FROM_COMPLETER = new ConstraintPosition("FROM_COMPLETER", true);
public static final ConstraintPosition SPECIAL = new ConstraintPosition("SPECIAL", true); public static final ConstraintPosition SPECIAL = new ConstraintPosition("SPECIAL", true);
private static final Map<Integer, ConstraintPosition> valueParameterPositions = Maps.newHashMap(); private static final Map<Integer, ConstraintPosition> valueParameterPositions = new HashMap<Integer, ConstraintPosition>();
private static final Map<Integer, ConstraintPosition> typeBoundPositions = Maps.newHashMap(); private static final Map<Integer, ConstraintPosition> typeBoundPositions = new HashMap<Integer, ConstraintPosition>();
public static ConstraintPosition getValueParameterPosition(int index) { public static ConstraintPosition getValueParameterPosition(int index) {
ConstraintPosition position = valueParameterPositions.get(index); ConstraintPosition position = valueParameterPositions.get(index);
@@ -16,8 +16,6 @@
package org.jetbrains.jet.lang.resolve.calls.inference; package org.jetbrains.jet.lang.resolve.calls.inference;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import kotlin.Function1; import kotlin.Function1;
import kotlin.KotlinPackage; import kotlin.KotlinPackage;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -30,10 +28,7 @@ import org.jetbrains.jet.lang.types.checker.TypingConstraints;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.utils.UtilsPackage; import org.jetbrains.jet.utils.UtilsPackage;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.EQUAL; import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.EQUAL;
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.SUB_TYPE; import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.SUB_TYPE;
@@ -47,8 +42,9 @@ public class ConstraintSystemImpl implements ConstraintSystem {
SUB_TYPE, EQUAL SUB_TYPE, EQUAL
} }
private final Map<TypeParameterDescriptor, TypeBoundsImpl> typeParameterBounds = Maps.newLinkedHashMap(); private final Map<TypeParameterDescriptor, TypeBoundsImpl> typeParameterBounds =
private final Set<ConstraintPosition> errorConstraintPositions = Sets.newHashSet(); new LinkedHashMap<TypeParameterDescriptor, TypeBoundsImpl>();
private final Set<ConstraintPosition> errorConstraintPositions = new HashSet<ConstraintPosition>();
private boolean hasErrorInConstrainingTypes; private boolean hasErrorInConstrainingTypes;
private final ConstraintSystemStatus constraintSystemStatus = new ConstraintSystemStatus() { private final ConstraintSystemStatus constraintSystemStatus = new ConstraintSystemStatus() {
@@ -123,7 +119,8 @@ public class ConstraintSystemImpl implements ConstraintSystem {
@NotNull Map<TypeParameterDescriptor, TypeBoundsImpl> typeParameterBounds, @NotNull Map<TypeParameterDescriptor, TypeBoundsImpl> typeParameterBounds,
@NotNull Function1<TypeParameterDescriptor, TypeProjection> getDefaultTypeProjection @NotNull Function1<TypeParameterDescriptor, TypeProjection> getDefaultTypeProjection
) { ) {
Map<TypeParameterDescriptor, TypeProjection> substitutionContext = Maps.newHashMap(); Map<TypeParameterDescriptor, TypeProjection> substitutionContext =
UtilsPackage.newHashMapWithExpectedSize(typeParameterBounds.size());
for (Map.Entry<TypeParameterDescriptor, TypeBoundsImpl> entry : typeParameterBounds.entrySet()) { for (Map.Entry<TypeParameterDescriptor, TypeBoundsImpl> entry : typeParameterBounds.entrySet()) {
TypeParameterDescriptor typeParameter = entry.getKey(); TypeParameterDescriptor typeParameter = entry.getKey();
TypeBounds typeBounds = entry.getValue(); TypeBounds typeBounds = entry.getValue();
@@ -221,12 +218,11 @@ public class ConstraintSystemImpl implements ConstraintSystem {
} }
@NotNull @NotNull
public ConstraintSystem filterConstraintsOut(@NotNull ConstraintPosition... excludePositions) { public ConstraintSystem filterConstraintsOut(@NotNull final ConstraintPosition excludePosition) {
final Set<ConstraintPosition> positions = Sets.newHashSet(excludePositions);
return filterConstraints(new Function1<ConstraintPosition, Boolean>() { return filterConstraints(new Function1<ConstraintPosition, Boolean>() {
@Override @Override
public Boolean invoke(ConstraintPosition constraintPosition) { public Boolean invoke(ConstraintPosition constraintPosition) {
return !positions.contains(constraintPosition); return !excludePosition.equals(constraintPosition);
} }
}); });
} }
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.calls.inference; package org.jetbrains.jet.lang.resolve.calls.inference;
import com.google.common.collect.Sets;
import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.ContainerUtil;
import kotlin.Function1; import kotlin.Function1;
import kotlin.KotlinPackage; import kotlin.KotlinPackage;
@@ -34,7 +33,7 @@ import static org.jetbrains.jet.lang.resolve.calls.inference.TypeBounds.BoundKin
public class TypeBoundsImpl implements TypeBounds { public class TypeBoundsImpl implements TypeBounds {
private final TypeParameterDescriptor typeVariable; private final TypeParameterDescriptor typeVariable;
private final Variance varianceOfPosition; private final Variance varianceOfPosition;
private final Set<Bound> bounds = Sets.newLinkedHashSet(); private final Set<Bound> bounds = new LinkedHashSet<Bound>();
private Collection<JetType> resultValues; private Collection<JetType> resultValues;
@@ -88,7 +87,7 @@ public class TypeBoundsImpl implements TypeBounds {
@NotNull BoundKind kind, @NotNull BoundKind kind,
@Nullable Collection<JetType> errorValues @Nullable Collection<JetType> errorValues
) { ) {
Set<JetType> result = Sets.newLinkedHashSet(); Set<JetType> result = new LinkedHashSet<JetType>();
for (Bound bound : bounds) { for (Bound bound : bounds) {
if (bound.kind == kind) { if (bound.kind == kind) {
if (!ErrorUtils.containsErrorType(bound.type)) { if (!ErrorUtils.containsErrorType(bound.type)) {
@@ -142,7 +141,7 @@ public class TypeBoundsImpl implements TypeBounds {
@NotNull @NotNull
private Collection<JetType> computeValues() { private Collection<JetType> computeValues() {
Set<JetType> values = Sets.newLinkedHashSet(); Set<JetType> values = new LinkedHashSet<JetType>();
if (bounds.isEmpty()) { if (bounds.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
@@ -16,17 +16,13 @@
package org.jetbrains.jet.lang.resolve.scopes; package org.jetbrains.jet.lang.resolve.scopes;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly; import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer; import org.jetbrains.jet.utils.Printer;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import static org.jetbrains.jet.lang.resolve.scopes.JetScopeSelectorUtil.*; import static org.jetbrains.jet.lang.resolve.scopes.JetScopeSelectorUtil.*;
@@ -106,7 +102,7 @@ public class ChainedScope implements JetScope {
@Override @Override
public Collection<DeclarationDescriptor> getAllDescriptors() { public Collection<DeclarationDescriptor> getAllDescriptors() {
if (allDescriptors == null) { if (allDescriptors == null) {
allDescriptors = Sets.newHashSet(); allDescriptors = new HashSet<DeclarationDescriptor>();
for (JetScope scope : scopeChain) { for (JetScope scope : scopeChain) {
allDescriptors.addAll(scope.getAllDescriptors()); allDescriptors.addAll(scope.getAllDescriptors());
} }
@@ -16,15 +16,12 @@
package org.jetbrains.jet.lang.resolve.scopes; package org.jetbrains.jet.lang.resolve.scopes;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collection; import java.util.*;
import java.util.Collections;
import java.util.Set;
public class JetScopeSelectorUtil { public class JetScopeSelectorUtil {
private JetScopeSelectorUtil() { private JetScopeSelectorUtil() {
@@ -47,7 +44,7 @@ public class JetScopeSelectorUtil {
@NotNull @NotNull
public static <D extends DeclarationDescriptor> Collection<D> collect(Collection<JetScope> scopes, ScopeByNameMultiSelector<D> selector, Name name) { public static <D extends DeclarationDescriptor> Collection<D> collect(Collection<JetScope> scopes, ScopeByNameMultiSelector<D> selector, Name name) {
Set<D> descriptors = Sets.newHashSet(); Set<D> descriptors = new HashSet<D>();
for (JetScope scope : scopes) { for (JetScope scope : scopes) {
descriptors.addAll(selector.get(scope, name)); descriptors.addAll(selector.get(scope, name));
@@ -58,7 +55,7 @@ public class JetScopeSelectorUtil {
@NotNull @NotNull
public static <D extends DeclarationDescriptor> Collection<D> collect(Collection<JetScope> scopes, ScopeDescriptorSelector<D> selector) { public static <D extends DeclarationDescriptor> Collection<D> collect(Collection<JetScope> scopes, ScopeDescriptorSelector<D> selector) {
Set<D> descriptors = Sets.newHashSet(); Set<D> descriptors = new HashSet<D>();
for (JetScope scope : scopes) { for (JetScope scope : scopes) {
descriptors.addAll(selector.get(scope)); descriptors.addAll(selector.get(scope));
@@ -146,8 +143,7 @@ public class JetScopeSelectorUtil {
) { ) {
if (scopes.length == 0) return Collections.emptySet(); if (scopes.length == 0) return Collections.emptySet();
Set<D> descriptors = Sets.newLinkedHashSet(); Set<D> descriptors = new LinkedHashSet<D>();
for (JetScope jetScope : scopes) { for (JetScope jetScope : scopes) {
descriptors.addAll(descriptorsSelector.get(jetScope, name)); descriptors.addAll(descriptorsSelector.get(jetScope, name));
} }
@@ -16,8 +16,6 @@
package org.jetbrains.jet.lang.resolve.scopes; package org.jetbrains.jet.lang.resolve.scopes;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly; import org.jetbrains.annotations.TestOnly;
@@ -25,11 +23,9 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.TypeSubstitutor; import org.jetbrains.jet.lang.types.TypeSubstitutor;
import org.jetbrains.jet.utils.Printer; import org.jetbrains.jet.utils.Printer;
import org.jetbrains.jet.utils.UtilsPackage;
import java.util.Collection; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class SubstitutingScope implements JetScope { public class SubstitutingScope implements JetScope {
@@ -50,7 +46,7 @@ public class SubstitutingScope implements JetScope {
if (substitutor.isEmpty()) return descriptor; if (substitutor.isEmpty()) return descriptor;
if (substitutedDescriptors == null) { if (substitutedDescriptors == null) {
substitutedDescriptors = Maps.newHashMap(); substitutedDescriptors = new HashMap<DeclarationDescriptor, DeclarationDescriptor>();
} }
DeclarationDescriptor substituted = substitutedDescriptors.get(descriptor); DeclarationDescriptor substituted = substitutedDescriptors.get(descriptor);
@@ -70,7 +66,7 @@ public class SubstitutingScope implements JetScope {
if (substitutor.isEmpty()) return descriptors; if (substitutor.isEmpty()) return descriptors;
if (descriptors.isEmpty()) return descriptors; if (descriptors.isEmpty()) return descriptors;
Set<D> result = Sets.newHashSetWithExpectedSize(descriptors.size()); Set<D> result = UtilsPackage.newHashSetWithExpectedSize(descriptors.size());
for (D descriptor : descriptors) { for (D descriptor : descriptors) {
D substitute = substitute(descriptor); D substitute = substitute(descriptor);
if (substitute != null) { if (substitute != null) {
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.types; package org.jetbrains.jet.lang.types;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
@@ -107,7 +106,7 @@ public class CommonSupertypes {
List<TypeConstructor> order = null; List<TypeConstructor> order = null;
for (JetType type : types) { for (JetType type : types) {
Set<TypeConstructor> visited = Sets.newHashSet(); Set<TypeConstructor> visited = new HashSet<TypeConstructor>();
order = topologicallySortSuperclassesAndRecordAllInstances(type, constructorToAllInstances, visited); order = topologicallySortSuperclassesAndRecordAllInstances(type, constructorToAllInstances, visited);
if (commonSuperclasses == null) { if (commonSuperclasses == null) {
@@ -16,8 +16,6 @@
package org.jetbrains.jet.lang.types; package org.jetbrains.jet.lang.types;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor; import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
@@ -32,7 +30,7 @@ public class IntersectionTypeConstructor extends AnnotatedImpl implements TypeCo
public IntersectionTypeConstructor(Annotations annotations, Collection<JetType> typesToIntersect) { public IntersectionTypeConstructor(Annotations annotations, Collection<JetType> typesToIntersect) {
super(annotations); super(annotations);
this.intersectedTypes = Sets.newLinkedHashSet(typesToIntersect); this.intersectedTypes = new LinkedHashSet<JetType>(typesToIntersect);
this.hashCode = intersectedTypes.hashCode(); this.hashCode = intersectedTypes.hashCode();
} }
@@ -16,8 +16,6 @@
package org.jetbrains.jet.lang.types; package org.jetbrains.jet.lang.types;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import kotlin.Function1; import kotlin.Function1;
import kotlin.KotlinPackage; import kotlin.KotlinPackage;
import kotlin.Unit; import kotlin.Unit;
@@ -36,6 +34,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.utils.DFS; import org.jetbrains.jet.utils.DFS;
import org.jetbrains.jet.utils.UtilsPackage;
import java.util.*; import java.util.*;
@@ -138,7 +137,7 @@ public class TypeUtils {
} }
public static boolean isIntersectionEmpty(@NotNull JetType typeA, @NotNull JetType typeB) { public static boolean isIntersectionEmpty(@NotNull JetType typeA, @NotNull JetType typeB) {
return intersect(JetTypeChecker.DEFAULT, Sets.newLinkedHashSet(Arrays.asList(typeA, typeB))) == null; return intersect(JetTypeChecker.DEFAULT, new LinkedHashSet<JetType>(Arrays.asList(typeA, typeB))) == null;
} }
@Nullable @Nullable
@@ -237,7 +236,7 @@ public class TypeUtils {
private static boolean unify(JetType withParameters, JetType expected) { private static boolean unify(JetType withParameters, JetType expected) {
// T -> how T is used // T -> how T is used
final Map<TypeParameterDescriptor, Variance> parameters = Maps.newHashMap(); final Map<TypeParameterDescriptor, Variance> parameters = new HashMap<TypeParameterDescriptor, Variance>();
Function1<TypeParameterUsage, Unit> processor = new Function1<TypeParameterUsage, Unit>() { Function1<TypeParameterUsage, Unit> processor = new Function1<TypeParameterUsage, Unit>() {
@Override @Override
public Unit invoke(TypeParameterUsage parameterUsage) { public Unit invoke(TypeParameterUsage parameterUsage) {
@@ -469,7 +468,7 @@ public class TypeUtils {
throw new IllegalArgumentException("type parameter counts do not match: " + clazz + ", " + projections); throw new IllegalArgumentException("type parameter counts do not match: " + clazz + ", " + projections);
} }
Map<TypeConstructor, TypeProjection> substitutions = Maps.newHashMap(); Map<TypeConstructor, TypeProjection> substitutions = UtilsPackage.newHashMapWithExpectedSize(clazzTypeParameters.size());
for (int i = 0; i < clazzTypeParameters.size(); ++i) { for (int i = 0; i < clazzTypeParameters.size(); ++i) {
TypeConstructor typeConstructor = clazzTypeParameters.get(i).getTypeConstructor(); TypeConstructor typeConstructor = clazzTypeParameters.get(i).getTypeConstructor();
@@ -547,7 +546,7 @@ public class TypeUtils {
@NotNull @NotNull
private static Set<JetType> getIntersectionOfSupertypes(@NotNull Collection<JetType> types) { private static Set<JetType> getIntersectionOfSupertypes(@NotNull Collection<JetType> types) {
Set<JetType> upperBounds = Sets.newHashSet(); Set<JetType> upperBounds = new HashSet<JetType>();
for (JetType type : types) { for (JetType type : types) {
Collection<JetType> supertypes = type.getConstructor().getSupertypes(); Collection<JetType> supertypes = type.getConstructor().getSupertypes();
if (upperBounds.isEmpty()) { if (upperBounds.isEmpty()) {
@@ -654,7 +653,7 @@ public class TypeUtils {
} }
public static TypeSubstitutor makeConstantSubstitutor(Collection<TypeParameterDescriptor> typeParameterDescriptors, JetType type) { public static TypeSubstitutor makeConstantSubstitutor(Collection<TypeParameterDescriptor> typeParameterDescriptors, JetType type) {
final Set<TypeConstructor> constructors = Sets.newHashSet(); final Set<TypeConstructor> constructors = UtilsPackage.newHashSetWithExpectedSize(typeParameterDescriptors.size());
for (TypeParameterDescriptor typeParameterDescriptor : typeParameterDescriptors) { for (TypeParameterDescriptor typeParameterDescriptor : typeParameterDescriptors) {
constructors.add(typeParameterDescriptor.getTypeConstructor()); constructors.add(typeParameterDescriptor.getTypeConstructor());
} }
@@ -16,7 +16,6 @@
package org.jetbrains.jet.renderer; package org.jetbrains.jet.renderer;
import com.google.common.collect.Sets;
import kotlin.Function1; import kotlin.Function1;
import kotlin.KotlinPackage; import kotlin.KotlinPackage;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -114,7 +113,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
this.debugMode = debugMode; this.debugMode = debugMode;
this.textFormat = textFormat; this.textFormat = textFormat;
this.includePropertyConstant = includePropertyConstant; this.includePropertyConstant = includePropertyConstant;
this.excludedAnnotationClasses = Sets.newHashSet(excludedAnnotationClasses); this.excludedAnnotationClasses = new HashSet<FqName>(excludedAnnotationClasses);
this.prettyFunctionTypes = prettyFunctionTypes; this.prettyFunctionTypes = prettyFunctionTypes;
this.uninferredTypeParameterAsName = uninferredTypeParameterAsName; this.uninferredTypeParameterAsName = uninferredTypeParameterAsName;
this.includeSynthesizedParameterNames = includeSynthesizedParameterNames; this.includeSynthesizedParameterNames = includeSynthesizedParameterNames;
@@ -18,6 +18,8 @@ package org.jetbrains.jet.utils
import java.util.LinkedHashMap import java.util.LinkedHashMap
import java.util.ArrayList import java.util.ArrayList
import java.util.HashMap
import java.util.HashSet
public fun <K, V> Stream<V>.valuesToMap(key: (V) -> K): Map<K, V> { public fun <K, V> Stream<V>.valuesToMap(key: (V) -> K): Map<K, V> {
val map = LinkedHashMap<K, V>() val map = LinkedHashMap<K, V>()
@@ -83,4 +85,12 @@ public fun <T: Any> emptyOrSingletonList(item: T?): List<T> = if (item == null)
public fun <T: Any> MutableCollection<T>.addIfNotNull(t: T?) { public fun <T: Any> MutableCollection<T>.addIfNotNull(t: T?) {
if (t != null) add(t) if (t != null) add(t)
} }
public fun <K, V> newHashMapWithExpectedSize(expectedSize: Int): HashMap<K, V> {
return HashMap(if (expectedSize < 3) 3 else expectedSize + expectedSize / 3 + 1)
}
public fun <E> newHashSetWithExpectedSize(expectedSize: Int): HashSet<E> {
return HashSet(if (expectedSize < 3) 3 else expectedSize + expectedSize / 3 + 1)
}