Misc refactorings in KotlinBuiltIns
- delete fields which were supposed to be used for caching, but mistakenly were never used - delete/inline unused methods and constants - delete useless logic related to root package fragment: package fragment providers are only supposed to find packages they're aware of
This commit is contained in:
@@ -52,7 +52,7 @@ import java.util.*;
|
|||||||
public class LightClassUtil {
|
public class LightClassUtil {
|
||||||
private static final Logger LOG = Logger.getInstance(LightClassUtil.class);
|
private static final Logger LOG = Logger.getInstance(LightClassUtil.class);
|
||||||
|
|
||||||
public static final File BUILT_INS_SRC_DIR = new File("core/builtins/native", KotlinBuiltIns.BUILT_INS_PACKAGE_NAME_STRING);
|
public static final File BUILT_INS_SRC_DIR = new File("core/builtins/native", KotlinBuiltIns.BUILT_INS_PACKAGE_NAME.asString());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the given file is loaded from the location where Kotlin's built-in classes are defined.
|
* Checks whether the given file is loaded from the location where Kotlin's built-in classes are defined.
|
||||||
@@ -85,7 +85,7 @@ public class LightClassUtil {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static URL getBuiltInsDirUrl() {
|
public static URL getBuiltInsDirUrl() {
|
||||||
String builtInFilePath = "/" + KotlinBuiltIns.BUILT_INS_PACKAGE_NAME_STRING + "/Library.kt";
|
String builtInFilePath = "/" + KotlinBuiltIns.BUILT_INS_PACKAGE_NAME + "/Library.kt";
|
||||||
|
|
||||||
URL url = KotlinBuiltIns.class.getResource(builtInFilePath);
|
URL url = KotlinBuiltIns.class.getResource(builtInFilePath);
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ public class CommonSupertypes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO : attributes?
|
// TODO : attributes?
|
||||||
JetScope newScope = KotlinBuiltIns.getInstance().STUB;
|
JetScope newScope = JetScope.EMPTY;
|
||||||
DeclarationDescriptor declarationDescriptor = constructor.getDeclarationDescriptor();
|
DeclarationDescriptor declarationDescriptor = constructor.getDeclarationDescriptor();
|
||||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||||
newScope = ((ClassDescriptor) declarationDescriptor).getMemberScope(newProjections);
|
newScope = ((ClassDescriptor) declarationDescriptor).getMemberScope(newProjections);
|
||||||
|
|||||||
+17
-7
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* 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.types.lang;
|
package org.jetbrains.jet.lang.types.lang;
|
||||||
|
|
||||||
import kotlin.Function0;
|
import kotlin.Function0;
|
||||||
@@ -11,7 +27,6 @@ import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor;
|
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptorImpl;
|
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptorImpl;
|
||||||
import org.jetbrains.jet.lang.descriptors.PackageFragmentProvider;
|
import org.jetbrains.jet.lang.descriptors.PackageFragmentProvider;
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.MutablePackageFragmentDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
@@ -80,15 +95,10 @@ class BuiltinsPackageFragment extends PackageFragmentDescriptorImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class BuiltinsPackageFragmentProvider implements PackageFragmentProvider {
|
private class BuiltinsPackageFragmentProvider implements PackageFragmentProvider {
|
||||||
private final PackageFragmentDescriptor rootPackage = new MutablePackageFragmentDescriptor(getContainingDeclaration(), FqName.ROOT);
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<PackageFragmentDescriptor> getPackageFragments(@NotNull FqName fqName) {
|
public List<PackageFragmentDescriptor> getPackageFragments(@NotNull FqName fqName) {
|
||||||
if (fqName.isRoot()) {
|
if (KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.equals(fqName)) {
|
||||||
return Collections.singletonList(rootPackage);
|
|
||||||
}
|
|
||||||
else if (KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.equals(fqName)) {
|
|
||||||
return Collections.<PackageFragmentDescriptor>singletonList(BuiltinsPackageFragment.this);
|
return Collections.<PackageFragmentDescriptor>singletonList(BuiltinsPackageFragment.this);
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
|||||||
@@ -38,10 +38,7 @@ import java.util.*;
|
|||||||
import static org.jetbrains.jet.lang.types.lang.PrimitiveType.*;
|
import static org.jetbrains.jet.lang.types.lang.PrimitiveType.*;
|
||||||
|
|
||||||
public class KotlinBuiltIns {
|
public class KotlinBuiltIns {
|
||||||
public static final JetScope STUB = JetScope.EMPTY;
|
public static final Name BUILT_INS_PACKAGE_NAME = Name.identifier("kotlin");
|
||||||
|
|
||||||
public static final String BUILT_INS_PACKAGE_NAME_STRING = "kotlin";
|
|
||||||
public static final Name BUILT_INS_PACKAGE_NAME = Name.identifier(BUILT_INS_PACKAGE_NAME_STRING);
|
|
||||||
public static final FqName BUILT_INS_PACKAGE_FQ_NAME = FqName.topLevel(BUILT_INS_PACKAGE_NAME);
|
public static final FqName BUILT_INS_PACKAGE_FQ_NAME = FqName.topLevel(BUILT_INS_PACKAGE_NAME);
|
||||||
|
|
||||||
public static final int FUNCTION_TRAIT_COUNT = 23;
|
public static final int FUNCTION_TRAIT_COUNT = 23;
|
||||||
@@ -99,68 +96,30 @@ public class KotlinBuiltIns {
|
|||||||
private volatile ImmutableSet<ClassDescriptor> nonPhysicalClasses;
|
private volatile ImmutableSet<ClassDescriptor> nonPhysicalClasses;
|
||||||
|
|
||||||
private final ImmutableSet<ClassDescriptor> functionClassesSet;
|
private final ImmutableSet<ClassDescriptor> functionClassesSet;
|
||||||
|
|
||||||
private final ImmutableSet<ClassDescriptor> extensionFunctionClassesSet;
|
private final ImmutableSet<ClassDescriptor> extensionFunctionClassesSet;
|
||||||
|
|
||||||
private final EnumMap<PrimitiveType, ClassDescriptor> primitiveTypeToClass;
|
private final Map<PrimitiveType, JetType> primitiveTypeToNullableJetType;
|
||||||
private final EnumMap<PrimitiveType, ClassDescriptor> primitiveTypeToArrayClass;
|
private final Map<PrimitiveType, JetType> primitiveTypeToArrayJetType;
|
||||||
private final EnumMap<PrimitiveType, JetType> primitiveTypeToJetType;
|
|
||||||
private final EnumMap<PrimitiveType, JetType> primitiveTypeToNullableJetType;
|
|
||||||
private final EnumMap<PrimitiveType, JetType> primitiveTypeToArrayJetType;
|
|
||||||
private final Map<JetType, JetType> primitiveJetTypeToJetArrayType;
|
private final Map<JetType, JetType> primitiveJetTypeToJetArrayType;
|
||||||
private final Map<JetType, JetType> jetArrayTypeToPrimitiveJetType;
|
private final Map<JetType, JetType> jetArrayTypeToPrimitiveJetType;
|
||||||
|
|
||||||
private final ClassDescriptor nothingClass;
|
|
||||||
private final ClassDescriptor arrayClass;
|
|
||||||
private final ClassDescriptor deprecatedAnnotationClass;
|
|
||||||
private final ClassDescriptor dataAnnotationClass;
|
|
||||||
private final ClassDescriptor[] functionClasses;
|
|
||||||
|
|
||||||
private volatile JetType anyType;
|
|
||||||
private volatile JetType nullableAnyType;
|
|
||||||
private volatile JetType nothingType;
|
|
||||||
private volatile JetType nullableNothingType;
|
|
||||||
private volatile JetType unitType;
|
|
||||||
private volatile JetType stringType;
|
|
||||||
private volatile JetType annotationType;
|
|
||||||
|
|
||||||
private KotlinBuiltIns() {
|
private KotlinBuiltIns() {
|
||||||
this.builtInsModule = new ModuleDescriptorImpl(Name.special("<built-ins lazy module>"),
|
builtInsModule = new ModuleDescriptorImpl(Name.special("<built-ins lazy module>"),
|
||||||
Collections.<ImportPath>emptyList(),
|
Collections.<ImportPath>emptyList(),
|
||||||
PlatformToKotlinClassMap.EMPTY);
|
PlatformToKotlinClassMap.EMPTY);
|
||||||
builtinsPackageFragment = new BuiltinsPackageFragment(new LockBasedStorageManager(), builtInsModule);
|
builtinsPackageFragment = new BuiltinsPackageFragment(new LockBasedStorageManager(), builtInsModule);
|
||||||
builtInsModule.addFragmentProvider(DependencyKind.SOURCES, builtinsPackageFragment.getProvider());
|
builtInsModule.addFragmentProvider(DependencyKind.SOURCES, builtinsPackageFragment.getProvider());
|
||||||
|
|
||||||
this.functionClassesSet = computeIndexedClasses("Function", FUNCTION_TRAIT_COUNT);
|
functionClassesSet = computeIndexedClasses("Function", FUNCTION_TRAIT_COUNT);
|
||||||
this.extensionFunctionClassesSet = computeIndexedClasses("ExtensionFunction", FUNCTION_TRAIT_COUNT);
|
extensionFunctionClassesSet = computeIndexedClasses("ExtensionFunction", FUNCTION_TRAIT_COUNT);
|
||||||
|
|
||||||
this.primitiveTypeToClass = new EnumMap<PrimitiveType, ClassDescriptor>(PrimitiveType.class);
|
primitiveTypeToNullableJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
|
||||||
this.primitiveTypeToJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
|
primitiveTypeToArrayJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
|
||||||
this.primitiveTypeToNullableJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
|
primitiveJetTypeToJetArrayType = new HashMap<JetType, JetType>();
|
||||||
this.primitiveTypeToArrayClass = new EnumMap<PrimitiveType, ClassDescriptor>(PrimitiveType.class);
|
jetArrayTypeToPrimitiveJetType = new HashMap<JetType, JetType>();
|
||||||
this.primitiveTypeToArrayJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
|
|
||||||
this.primitiveJetTypeToJetArrayType = new HashMap<JetType, JetType>();
|
|
||||||
this.jetArrayTypeToPrimitiveJetType = new HashMap<JetType, JetType>();
|
|
||||||
|
|
||||||
this.nothingClass = getBuiltInClassByName("Nothing");
|
|
||||||
this.arrayClass = getBuiltInClassByName("Array");
|
|
||||||
this.deprecatedAnnotationClass = getBuiltInClassByName("deprecated");
|
|
||||||
this.dataAnnotationClass = getBuiltInClassByName("data");
|
|
||||||
this.functionClasses = new ClassDescriptor[FUNCTION_TRAIT_COUNT];
|
|
||||||
for (int i = 0; i < functionClasses.length; i++) {
|
|
||||||
functionClasses[i] = getBuiltInClassByName("Function" + i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doInitialize() {
|
private void doInitialize() {
|
||||||
anyType = getBuiltInTypeByClassName("Any");
|
|
||||||
nullableAnyType = TypeUtils.makeNullable(anyType);
|
|
||||||
nothingType = getBuiltInTypeByClassName("Nothing");
|
|
||||||
nullableNothingType = TypeUtils.makeNullable(nothingType);
|
|
||||||
unitType = getBuiltInTypeByClassName("Unit");
|
|
||||||
stringType = getBuiltInTypeByClassName("String");
|
|
||||||
annotationType = getBuiltInTypeByClassName("Annotation");
|
|
||||||
|
|
||||||
for (PrimitiveType primitive : PrimitiveType.values()) {
|
for (PrimitiveType primitive : PrimitiveType.values()) {
|
||||||
makePrimitive(primitive);
|
makePrimitive(primitive);
|
||||||
}
|
}
|
||||||
@@ -174,10 +133,7 @@ public class KotlinBuiltIns {
|
|||||||
ClassDescriptor arrayClass = getBuiltInClassByName(primitiveType.getArrayTypeName().asString());
|
ClassDescriptor arrayClass = getBuiltInClassByName(primitiveType.getArrayTypeName().asString());
|
||||||
JetType arrayType = new JetTypeImpl(arrayClass);
|
JetType arrayType = new JetTypeImpl(arrayClass);
|
||||||
|
|
||||||
primitiveTypeToClass.put(primitiveType, theClass);
|
|
||||||
primitiveTypeToJetType.put(primitiveType, type);
|
|
||||||
primitiveTypeToNullableJetType.put(primitiveType, TypeUtils.makeNullable(type));
|
primitiveTypeToNullableJetType.put(primitiveType, TypeUtils.makeNullable(type));
|
||||||
primitiveTypeToArrayClass.put(primitiveType, arrayClass);
|
|
||||||
primitiveTypeToArrayJetType.put(primitiveType, arrayType);
|
primitiveTypeToArrayJetType.put(primitiveType, arrayType);
|
||||||
primitiveJetTypeToJetArrayType.put(type, arrayType);
|
primitiveJetTypeToJetArrayType.put(type, arrayType);
|
||||||
jetArrayTypeToPrimitiveJetType.put(arrayType, type);
|
jetArrayTypeToPrimitiveJetType.put(arrayType, type);
|
||||||
@@ -455,14 +411,14 @@ public class KotlinBuiltIns {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ClassDescriptor getMapEntry() {
|
public ClassDescriptor getMapEntry() {
|
||||||
ClassDescriptor classDescriptor = DescriptorUtils.getInnerClassByName(getBuiltInClassByName("Map"), "Entry");
|
ClassDescriptor classDescriptor = DescriptorUtils.getInnerClassByName(getMap(), "Entry");
|
||||||
assert classDescriptor != null : "Can't find Map.Entry";
|
assert classDescriptor != null : "Can't find Map.Entry";
|
||||||
return classDescriptor;
|
return classDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ClassDescriptor getMutableMapEntry() {
|
public ClassDescriptor getMutableMapEntry() {
|
||||||
ClassDescriptor classDescriptor = DescriptorUtils.getInnerClassByName(getBuiltInClassByName("MutableMap"), "MutableEntry");
|
ClassDescriptor classDescriptor = DescriptorUtils.getInnerClassByName(getMutableMap(), "MutableEntry");
|
||||||
assert classDescriptor != null : "Can't find MutableMap.MutableEntry";
|
assert classDescriptor != null : "Can't find MutableMap.MutableEntry";
|
||||||
return classDescriptor;
|
return classDescriptor;
|
||||||
}
|
}
|
||||||
@@ -696,11 +652,6 @@ public class KotlinBuiltIns {
|
|||||||
return getBuiltInTypeByClassName("Annotation");
|
return getBuiltInTypeByClassName("Annotation");
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public ClassDescriptor getPropertyMetadata() {
|
|
||||||
return getBuiltInClassByName("PropertyMetadata");
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ClassDescriptor getPropertyMetadataImpl() {
|
public ClassDescriptor getPropertyMetadataImpl() {
|
||||||
return getBuiltInClassByName("PropertyMetadataImpl");
|
return getBuiltInClassByName("PropertyMetadataImpl");
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ import java.util.Set;
|
|||||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.unwrapFakeOverride;
|
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.unwrapFakeOverride;
|
||||||
|
|
||||||
public class BuiltInsReferenceResolver extends AbstractProjectComponent {
|
public class BuiltInsReferenceResolver extends AbstractProjectComponent {
|
||||||
private static final File BUILT_INS_COMPILABLE_SRC_DIR = new File("core/builtins/src", KotlinBuiltIns.BUILT_INS_PACKAGE_NAME_STRING);
|
private static final File BUILT_INS_COMPILABLE_SRC_DIR =
|
||||||
|
new File("core/builtins/src", KotlinBuiltIns.BUILT_INS_PACKAGE_NAME.asString());
|
||||||
|
|
||||||
private volatile BindingContext bindingContext;
|
private volatile BindingContext bindingContext;
|
||||||
private volatile Set<JetFile> builtInsSources;
|
private volatile Set<JetFile> builtInsSources;
|
||||||
|
|||||||
Reference in New Issue
Block a user