Remove dependency of "descriptors" on ImmutableSet

This commit is contained in:
Alexander Udalov
2014-08-14 15:59:51 +04:00
parent 2055d4d72c
commit 7229044a62
3 changed files with 28 additions and 27 deletions
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.types.lang; package org.jetbrains.jet.lang.types.lang;
import com.google.common.collect.ImmutableSet;
import kotlin.KotlinPackage; import kotlin.KotlinPackage;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -95,7 +94,7 @@ public class KotlinBuiltIns {
private final ModuleDescriptorImpl builtInsModule; private final ModuleDescriptorImpl builtInsModule;
private final BuiltinsPackageFragment builtinsPackageFragment; private final BuiltinsPackageFragment builtinsPackageFragment;
private volatile ImmutableSet<ClassDescriptor> nonPhysicalClasses; private final Set<ClassDescriptor> nonPhysicalClasses;
private final Map<PrimitiveType, JetType> primitiveTypeToNullableJetType; private final Map<PrimitiveType, JetType> primitiveTypeToNullableJetType;
private final Map<PrimitiveType, JetType> primitiveTypeToArrayJetType; private final Map<PrimitiveType, JetType> primitiveTypeToArrayJetType;
@@ -117,6 +116,8 @@ public class KotlinBuiltIns {
primitiveTypeToArrayJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class); primitiveTypeToArrayJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
primitiveJetTypeToJetArrayType = new HashMap<JetType, JetType>(); primitiveJetTypeToJetArrayType = new HashMap<JetType, JetType>();
jetArrayTypeToPrimitiveJetType = new HashMap<JetType, JetType>(); jetArrayTypeToPrimitiveJetType = new HashMap<JetType, JetType>();
nonPhysicalClasses = new HashSet<ClassDescriptor>();
} }
private void doInitialize() { private void doInitialize() {
@@ -124,7 +125,7 @@ public class KotlinBuiltIns {
makePrimitive(primitive); makePrimitive(primitive);
} }
nonPhysicalClasses = computeNonPhysicalClasses(); computeNonPhysicalClasses();
} }
private void makePrimitive(@NotNull PrimitiveType primitiveType) { private void makePrimitive(@NotNull PrimitiveType primitiveType) {
@@ -143,9 +144,8 @@ public class KotlinBuiltIns {
public final FqNameUnsafe cloneable = fqName("Cloneable"); public final FqNameUnsafe cloneable = fqName("Cloneable");
public final FqNameUnsafe suppress = fqName("suppress"); public final FqNameUnsafe suppress = fqName("suppress");
public final ImmutableSet<FqNameUnsafe> functionClasses = computeIndexedFqNames("Function", FUNCTION_TRAIT_COUNT); public final Set<FqNameUnsafe> functionClasses = computeIndexedFqNames("Function", FUNCTION_TRAIT_COUNT);
public final ImmutableSet<FqNameUnsafe> extensionFunctionClasses = public final Set<FqNameUnsafe> extensionFunctionClasses = computeIndexedFqNames("ExtensionFunction", FUNCTION_TRAIT_COUNT);
computeIndexedFqNames("ExtensionFunction", FUNCTION_TRAIT_COUNT);
@NotNull @NotNull
private static FqNameUnsafe fqName(@NotNull String simpleName) { private static FqNameUnsafe fqName(@NotNull String simpleName) {
@@ -153,12 +153,12 @@ public class KotlinBuiltIns {
} }
@NotNull @NotNull
private static ImmutableSet<FqNameUnsafe> computeIndexedFqNames(@NotNull String prefix, int count) { private static Set<FqNameUnsafe> computeIndexedFqNames(@NotNull String prefix, int count) {
ImmutableSet.Builder<FqNameUnsafe> builder = ImmutableSet.builder(); Set<FqNameUnsafe> result = new HashSet<FqNameUnsafe>();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
builder.add(fqName(prefix + i)); result.add(fqName(prefix + i));
} }
return builder.build(); return result;
} }
} }
@@ -260,7 +260,7 @@ public class KotlinBuiltIns {
@NotNull @NotNull
public Set<DeclarationDescriptor> getIntegralRanges() { public Set<DeclarationDescriptor> getIntegralRanges() {
return ImmutableSet.<DeclarationDescriptor>of( return KotlinPackage.<DeclarationDescriptor>setOf(
getBuiltInClassByName("ByteRange"), getBuiltInClassByName("ByteRange"),
getBuiltInClassByName("ShortRange"), getBuiltInClassByName("ShortRange"),
getBuiltInClassByName("CharRange"), getBuiltInClassByName("CharRange"),
@@ -454,13 +454,11 @@ public class KotlinBuiltIns {
*/ */
@NotNull @NotNull
public Set<ClassDescriptor> getNonPhysicalClasses() { public Set<ClassDescriptor> getNonPhysicalClasses() {
return nonPhysicalClasses; return Collections.unmodifiableSet(nonPhysicalClasses);
} }
@NotNull private void computeNonPhysicalClasses() {
private ImmutableSet<ClassDescriptor> computeNonPhysicalClasses() { nonPhysicalClasses.addAll(Arrays.asList(
ImmutableSet.Builder<ClassDescriptor> nonPhysical = ImmutableSet.builder();
nonPhysical.add(
getAny(), getAny(),
getNothing(), getNothing(),
@@ -492,14 +490,12 @@ public class KotlinBuiltIns {
getComparable(), getComparable(),
getEnum(), getEnum(),
getArray() getArray()
); ));
for (PrimitiveType primitiveType : values()) { for (PrimitiveType primitiveType : values()) {
nonPhysical.add(getPrimitiveClassDescriptor(primitiveType)); nonPhysicalClasses.add(getPrimitiveClassDescriptor(primitiveType));
nonPhysical.add(getPrimitiveArrayClassDescriptor(primitiveType)); nonPhysicalClasses.add(getPrimitiveArrayClassDescriptor(primitiveType));
} }
return nonPhysical.build();
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -761,7 +757,7 @@ public class KotlinBuiltIns {
return isTypeConstructorFqNameInSet(type, fqNames.extensionFunctionClasses); return isTypeConstructorFqNameInSet(type, fqNames.extensionFunctionClasses);
} }
private static boolean isTypeConstructorFqNameInSet(@NotNull JetType type, @NotNull ImmutableSet<FqNameUnsafe> classes) { private static boolean isTypeConstructorFqNameInSet(@NotNull JetType type, @NotNull Set<FqNameUnsafe> classes) {
ClassifierDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor(); ClassifierDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();
if (declarationDescriptor == null) return false; if (declarationDescriptor == null) return false;
@@ -16,10 +16,13 @@
package org.jetbrains.jet.lang.types.lang; package org.jetbrains.jet.lang.types.lang;
import com.google.common.collect.ImmutableSet;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
public enum PrimitiveType { public enum PrimitiveType {
BOOLEAN("Boolean"), BOOLEAN("Boolean"),
CHAR("Char"), CHAR("Char"),
@@ -31,7 +34,8 @@ public enum PrimitiveType {
DOUBLE("Double"), DOUBLE("Double"),
; ;
public static final ImmutableSet<PrimitiveType> NUMBER_TYPES = ImmutableSet.of(CHAR, BYTE, SHORT, INT, FLOAT, LONG, DOUBLE); public static final Set<PrimitiveType> NUMBER_TYPES =
Collections.unmodifiableSet(EnumSet.of(CHAR, BYTE, SHORT, INT, FLOAT, LONG, DOUBLE));
private final Name typeName; private final Name typeName;
private final Name arrayTypeName; private final Name arrayTypeName;
@@ -16,18 +16,19 @@
package org.jetbrains.jet.renderer; package org.jetbrains.jet.renderer;
import com.google.common.collect.ImmutableSet; import kotlin.KotlinPackage;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqName;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet;
import java.util.Set; import java.util.Set;
public class DescriptorRendererBuilder { public class DescriptorRendererBuilder {
private boolean shortNames = false; private boolean shortNames = false;
private boolean withDefinedIn = true; private boolean withDefinedIn = true;
private Set<DescriptorRenderer.Modifier> modifiers = ImmutableSet.copyOf(DescriptorRenderer.Modifier.values()); private Set<DescriptorRenderer.Modifier> modifiers = EnumSet.allOf(DescriptorRenderer.Modifier.class);
private boolean startFromName = false; private boolean startFromName = false;
private boolean debugMode = false; private boolean debugMode = false;
private boolean classWithPrimaryConstructor = false; private boolean classWithPrimaryConstructor = false;
@@ -77,7 +78,7 @@ public class DescriptorRendererBuilder {
@NotNull @NotNull
public DescriptorRendererBuilder setModifiers(DescriptorRenderer.Modifier... modifiers) { public DescriptorRendererBuilder setModifiers(DescriptorRenderer.Modifier... modifiers) {
return setModifiers(ImmutableSet.copyOf(modifiers)); return setModifiers(KotlinPackage.setOf(modifiers));
} }
@NotNull @NotNull