Remove suspicious JetTypeImpl constructors
Most of the time they were used for classes without type parameters, and getDefaultType() is supposed to be used there (additionally it may be cached)
This commit is contained in:
+4
-9
@@ -39,15 +39,11 @@ import org.jetbrains.jet.lang.resolve.calls.tasks.ResolutionCandidate;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy;
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.CALL;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
|
||||
@@ -96,11 +92,10 @@ public class ControlStructureTypingUtils {
|
||||
function, Annotations.EMPTY, false, Variance.INVARIANT,
|
||||
Name.identifierNoValidate("<TYPE-PARAMETER-FOR-" + constructionName + "-RESOLVE>"), 0);
|
||||
|
||||
JetType type = new JetTypeImpl(typeParameter.getTypeConstructor(), JetScope.EMPTY);
|
||||
JetType nullableType = new JetTypeImpl(
|
||||
Annotations.EMPTY, typeParameter.getTypeConstructor(), true, Collections.<TypeProjection>emptyList(), JetScope.EMPTY);
|
||||
JetType type = typeParameter.getDefaultType();
|
||||
JetType nullableType = TypeUtils.makeNullable(type);
|
||||
|
||||
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
|
||||
List<ValueParameterDescriptor> valueParameters = new ArrayList<ValueParameterDescriptor>(argumentNames.size());
|
||||
for (int i = 0; i < argumentNames.size(); i++) {
|
||||
JetType argumentType = isArgumentNullable.get(i) ? nullableType : type;
|
||||
ValueParameterDescriptorImpl valueParameter = new ValueParameterDescriptorImpl(
|
||||
|
||||
@@ -16,38 +16,18 @@
|
||||
|
||||
package org.jetbrains.jet.resolve.constraintSystem
|
||||
|
||||
import com.google.common.collect.ImmutableMap
|
||||
import com.google.common.collect.Maps
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.jet.ConfigurationKind
|
||||
import org.jetbrains.jet.JetLiteFixture
|
||||
import org.jetbrains.jet.JetTestUtils
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
|
||||
import org.jetbrains.jet.di.InjectorForTests
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.Renderers
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lang.resolve.*
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.jet.lang.types.Variance
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.util.Collections
|
||||
import com.intellij.openapi.project.Project
|
||||
import java.util.regex.Pattern
|
||||
import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstructor
|
||||
import org.jetbrains.jet.lang.types.JetTypeImpl
|
||||
import kotlin.test.assertNotNull
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
|
||||
|
||||
public class MyDeclarations(
|
||||
private val context: BindingContext,
|
||||
@@ -87,7 +67,7 @@ public class MyDeclarations(
|
||||
val matcher = INTEGER_VALUE_TYPE_PATTERN.matcher(name)
|
||||
if (matcher.find()) {
|
||||
val number = matcher.group(1)!!
|
||||
return JetTypeImpl(IntegerValueTypeConstructor(number.toLong()), JetScope.EMPTY)
|
||||
return JetTypeImpl(Annotations.EMPTY, IntegerValueTypeConstructor(number.toLong()), false, listOf(), JetScope.EMPTY)
|
||||
}
|
||||
return typeResolver.resolveType(
|
||||
scopeToResolveTypeParameters, JetPsiFactory.createType(project, name),
|
||||
|
||||
+10
-9
@@ -23,7 +23,6 @@ import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -201,14 +200,16 @@ public abstract class AbstractLazyTypeParameterDescriptor implements TypeParamet
|
||||
|
||||
@NotNull
|
||||
private JetType createDefaultType(@NotNull StorageManager storageManager) {
|
||||
return new JetTypeImpl(getTypeConstructor(), new LazyScopeAdapter(storageManager.createLazyValue(
|
||||
new Function0<JetScope>() {
|
||||
@Override
|
||||
public JetScope invoke() {
|
||||
return getUpperBoundsAsType().getMemberScope();
|
||||
}
|
||||
}
|
||||
)));
|
||||
return new JetTypeImpl(Annotations.EMPTY, getTypeConstructor(), false, Collections.<TypeProjection>emptyList(),
|
||||
new LazyScopeAdapter(storageManager.createLazyValue(
|
||||
new Function0<JetScope>() {
|
||||
@Override
|
||||
public JetScope invoke() {
|
||||
return getUpperBoundsAsType().getMemberScope();
|
||||
}
|
||||
}
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,11 +17,9 @@
|
||||
package org.jetbrains.jet.lang.types;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class JetTypeImpl extends AbstractJetType {
|
||||
@@ -32,7 +30,13 @@ public final class JetTypeImpl extends AbstractJetType {
|
||||
private final JetScope memberScope;
|
||||
private final Annotations annotations;
|
||||
|
||||
public JetTypeImpl(Annotations annotations, TypeConstructor constructor, boolean nullable, @NotNull List<? extends TypeProjection> arguments, JetScope memberScope) {
|
||||
public JetTypeImpl(
|
||||
@NotNull Annotations annotations,
|
||||
@NotNull TypeConstructor constructor,
|
||||
boolean nullable,
|
||||
@NotNull List<? extends TypeProjection> arguments,
|
||||
@NotNull JetScope memberScope
|
||||
) {
|
||||
this.annotations = annotations;
|
||||
|
||||
if (memberScope instanceof ErrorUtils.ErrorScope) {
|
||||
@@ -45,18 +49,6 @@ public final class JetTypeImpl extends AbstractJetType {
|
||||
this.memberScope = memberScope;
|
||||
}
|
||||
|
||||
public JetTypeImpl(TypeConstructor constructor, JetScope memberScope) {
|
||||
this(Annotations.EMPTY, constructor, false, Collections.<TypeProjection>emptyList(), memberScope);
|
||||
}
|
||||
|
||||
public JetTypeImpl(@NotNull ClassDescriptor classDescriptor) {
|
||||
this(Annotations.EMPTY,
|
||||
classDescriptor.getTypeConstructor(),
|
||||
false,
|
||||
Collections.<TypeProjection>emptyList(),
|
||||
classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Annotations getAnnotations() {
|
||||
|
||||
@@ -130,11 +130,9 @@ public class KotlinBuiltIns {
|
||||
nonPhysicalClasses = computeNonPhysicalClasses();
|
||||
}
|
||||
|
||||
private void makePrimitive(PrimitiveType primitiveType) {
|
||||
ClassDescriptor theClass = getBuiltInClassByName(primitiveType.getTypeName().asString());
|
||||
JetType type = new JetTypeImpl(theClass);
|
||||
ClassDescriptor arrayClass = getBuiltInClassByName(primitiveType.getArrayTypeName().asString());
|
||||
JetType arrayType = new JetTypeImpl(arrayClass);
|
||||
private void makePrimitive(@NotNull PrimitiveType primitiveType) {
|
||||
JetType type = getBuiltInTypeByClassName(primitiveType.getTypeName().asString());
|
||||
JetType arrayType = getBuiltInTypeByClassName(primitiveType.getArrayTypeName().asString());
|
||||
|
||||
primitiveTypeToNullableJetType.put(primitiveType, TypeUtils.makeNullable(type));
|
||||
primitiveTypeToArrayJetType.put(primitiveType, arrayType);
|
||||
@@ -491,31 +489,28 @@ public class KotlinBuiltIns {
|
||||
|
||||
@NotNull
|
||||
private JetType getBuiltInTypeByClassName(@NotNull String classSimpleName) {
|
||||
// TODO
|
||||
return new JetTypeImpl(getBuiltInClassByName(classSimpleName));
|
||||
return getBuiltInClassByName(classSimpleName).getDefaultType();
|
||||
}
|
||||
|
||||
// Special
|
||||
|
||||
@NotNull
|
||||
public JetType getNothingType() {
|
||||
return getBuiltInTypeByClassName("Nothing");
|
||||
return getNothing().getDefaultType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getNullableNothingType() {
|
||||
// TODO
|
||||
return TypeUtils.makeNullable(getNothingType());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getAnyType() {
|
||||
return getBuiltInTypeByClassName("Any");
|
||||
return getAny().getDefaultType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getNullableAnyType() {
|
||||
// TODO
|
||||
return TypeUtils.makeNullable(getAnyType());
|
||||
}
|
||||
|
||||
@@ -523,8 +518,7 @@ public class KotlinBuiltIns {
|
||||
|
||||
@NotNull
|
||||
public JetType getPrimitiveJetType(@NotNull PrimitiveType type) {
|
||||
// TODO
|
||||
return new JetTypeImpl(getPrimitiveClassDescriptor(type));
|
||||
return getPrimitiveClassDescriptor(type).getDefaultType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -576,12 +570,12 @@ public class KotlinBuiltIns {
|
||||
|
||||
@NotNull
|
||||
public JetType getUnitType() {
|
||||
return getBuiltInTypeByClassName("Unit");
|
||||
return getUnit().getDefaultType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getStringType() {
|
||||
return getBuiltInTypeByClassName("String");
|
||||
return getString().getDefaultType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -644,7 +638,7 @@ public class KotlinBuiltIns {
|
||||
|
||||
@NotNull
|
||||
public JetType getAnnotationType() {
|
||||
return getBuiltInTypeByClassName("Annotation");
|
||||
return getAnnotation().getDefaultType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user