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.tasks.TracingStrategy;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||||
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.receivers.ReceiverValue;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.CALL;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.CALL;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
|
||||||
@@ -96,11 +92,10 @@ public class ControlStructureTypingUtils {
|
|||||||
function, Annotations.EMPTY, false, Variance.INVARIANT,
|
function, Annotations.EMPTY, false, Variance.INVARIANT,
|
||||||
Name.identifierNoValidate("<TYPE-PARAMETER-FOR-" + constructionName + "-RESOLVE>"), 0);
|
Name.identifierNoValidate("<TYPE-PARAMETER-FOR-" + constructionName + "-RESOLVE>"), 0);
|
||||||
|
|
||||||
JetType type = new JetTypeImpl(typeParameter.getTypeConstructor(), JetScope.EMPTY);
|
JetType type = typeParameter.getDefaultType();
|
||||||
JetType nullableType = new JetTypeImpl(
|
JetType nullableType = TypeUtils.makeNullable(type);
|
||||||
Annotations.EMPTY, typeParameter.getTypeConstructor(), true, Collections.<TypeProjection>emptyList(), JetScope.EMPTY);
|
|
||||||
|
|
||||||
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
|
List<ValueParameterDescriptor> valueParameters = new ArrayList<ValueParameterDescriptor>(argumentNames.size());
|
||||||
for (int i = 0; i < argumentNames.size(); i++) {
|
for (int i = 0; i < argumentNames.size(); i++) {
|
||||||
JetType argumentType = isArgumentNullable.get(i) ? nullableType : type;
|
JetType argumentType = isArgumentNullable.get(i) ? nullableType : type;
|
||||||
ValueParameterDescriptorImpl valueParameter = new ValueParameterDescriptorImpl(
|
ValueParameterDescriptorImpl valueParameter = new ValueParameterDescriptorImpl(
|
||||||
|
|||||||
@@ -16,38 +16,18 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.resolve.constraintSystem
|
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.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.FunctionDescriptor
|
||||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor
|
|
||||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
|
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.psi.*
|
||||||
import org.jetbrains.jet.lang.resolve.*
|
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.resolve.scopes.JetScope
|
||||||
import org.jetbrains.jet.lang.types.JetType
|
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 com.intellij.openapi.project.Project
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstructor
|
import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstructor
|
||||||
import org.jetbrains.jet.lang.types.JetTypeImpl
|
import org.jetbrains.jet.lang.types.JetTypeImpl
|
||||||
import kotlin.test.assertNotNull
|
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
|
||||||
|
|
||||||
public class MyDeclarations(
|
public class MyDeclarations(
|
||||||
private val context: BindingContext,
|
private val context: BindingContext,
|
||||||
@@ -87,7 +67,7 @@ public class MyDeclarations(
|
|||||||
val matcher = INTEGER_VALUE_TYPE_PATTERN.matcher(name)
|
val matcher = INTEGER_VALUE_TYPE_PATTERN.matcher(name)
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
val number = matcher.group(1)!!
|
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(
|
return typeResolver.resolveType(
|
||||||
scopeToResolveTypeParameters, JetPsiFactory.createType(project, name),
|
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.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
|
||||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
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.descriptors.annotations.Annotations;
|
||||||
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;
|
||||||
@@ -201,14 +200,16 @@ public abstract class AbstractLazyTypeParameterDescriptor implements TypeParamet
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JetType createDefaultType(@NotNull StorageManager storageManager) {
|
private JetType createDefaultType(@NotNull StorageManager storageManager) {
|
||||||
return new JetTypeImpl(getTypeConstructor(), new LazyScopeAdapter(storageManager.createLazyValue(
|
return new JetTypeImpl(Annotations.EMPTY, getTypeConstructor(), false, Collections.<TypeProjection>emptyList(),
|
||||||
new Function0<JetScope>() {
|
new LazyScopeAdapter(storageManager.createLazyValue(
|
||||||
@Override
|
new Function0<JetScope>() {
|
||||||
public JetScope invoke() {
|
@Override
|
||||||
return getUpperBoundsAsType().getMemberScope();
|
public JetScope invoke() {
|
||||||
}
|
return getUpperBoundsAsType().getMemberScope();
|
||||||
}
|
}
|
||||||
)));
|
}
|
||||||
|
))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,11 +17,9 @@
|
|||||||
package org.jetbrains.jet.lang.types;
|
package org.jetbrains.jet.lang.types;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
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.descriptors.annotations.Annotations;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class JetTypeImpl extends AbstractJetType {
|
public final class JetTypeImpl extends AbstractJetType {
|
||||||
@@ -32,7 +30,13 @@ public final class JetTypeImpl extends AbstractJetType {
|
|||||||
private final JetScope memberScope;
|
private final JetScope memberScope;
|
||||||
private final Annotations annotations;
|
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;
|
this.annotations = annotations;
|
||||||
|
|
||||||
if (memberScope instanceof ErrorUtils.ErrorScope) {
|
if (memberScope instanceof ErrorUtils.ErrorScope) {
|
||||||
@@ -45,18 +49,6 @@ public final class JetTypeImpl extends AbstractJetType {
|
|||||||
this.memberScope = memberScope;
|
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
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Annotations getAnnotations() {
|
public Annotations getAnnotations() {
|
||||||
|
|||||||
@@ -130,11 +130,9 @@ public class KotlinBuiltIns {
|
|||||||
nonPhysicalClasses = computeNonPhysicalClasses();
|
nonPhysicalClasses = computeNonPhysicalClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makePrimitive(PrimitiveType primitiveType) {
|
private void makePrimitive(@NotNull PrimitiveType primitiveType) {
|
||||||
ClassDescriptor theClass = getBuiltInClassByName(primitiveType.getTypeName().asString());
|
JetType type = getBuiltInTypeByClassName(primitiveType.getTypeName().asString());
|
||||||
JetType type = new JetTypeImpl(theClass);
|
JetType arrayType = getBuiltInTypeByClassName(primitiveType.getArrayTypeName().asString());
|
||||||
ClassDescriptor arrayClass = getBuiltInClassByName(primitiveType.getArrayTypeName().asString());
|
|
||||||
JetType arrayType = new JetTypeImpl(arrayClass);
|
|
||||||
|
|
||||||
primitiveTypeToNullableJetType.put(primitiveType, TypeUtils.makeNullable(type));
|
primitiveTypeToNullableJetType.put(primitiveType, TypeUtils.makeNullable(type));
|
||||||
primitiveTypeToArrayJetType.put(primitiveType, arrayType);
|
primitiveTypeToArrayJetType.put(primitiveType, arrayType);
|
||||||
@@ -491,31 +489,28 @@ public class KotlinBuiltIns {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JetType getBuiltInTypeByClassName(@NotNull String classSimpleName) {
|
private JetType getBuiltInTypeByClassName(@NotNull String classSimpleName) {
|
||||||
// TODO
|
return getBuiltInClassByName(classSimpleName).getDefaultType();
|
||||||
return new JetTypeImpl(getBuiltInClassByName(classSimpleName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special
|
// Special
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getNothingType() {
|
public JetType getNothingType() {
|
||||||
return getBuiltInTypeByClassName("Nothing");
|
return getNothing().getDefaultType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getNullableNothingType() {
|
public JetType getNullableNothingType() {
|
||||||
// TODO
|
|
||||||
return TypeUtils.makeNullable(getNothingType());
|
return TypeUtils.makeNullable(getNothingType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getAnyType() {
|
public JetType getAnyType() {
|
||||||
return getBuiltInTypeByClassName("Any");
|
return getAny().getDefaultType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getNullableAnyType() {
|
public JetType getNullableAnyType() {
|
||||||
// TODO
|
|
||||||
return TypeUtils.makeNullable(getAnyType());
|
return TypeUtils.makeNullable(getAnyType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,8 +518,7 @@ public class KotlinBuiltIns {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getPrimitiveJetType(@NotNull PrimitiveType type) {
|
public JetType getPrimitiveJetType(@NotNull PrimitiveType type) {
|
||||||
// TODO
|
return getPrimitiveClassDescriptor(type).getDefaultType();
|
||||||
return new JetTypeImpl(getPrimitiveClassDescriptor(type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -576,12 +570,12 @@ public class KotlinBuiltIns {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getUnitType() {
|
public JetType getUnitType() {
|
||||||
return getBuiltInTypeByClassName("Unit");
|
return getUnit().getDefaultType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getStringType() {
|
public JetType getStringType() {
|
||||||
return getBuiltInTypeByClassName("String");
|
return getString().getDefaultType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -644,7 +638,7 @@ public class KotlinBuiltIns {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getAnnotationType() {
|
public JetType getAnnotationType() {
|
||||||
return getBuiltInTypeByClassName("Annotation");
|
return getAnnotation().getDefaultType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user