s/Type/JetType/

This commit is contained in:
Andrey Breslav
2011-03-15 13:46:40 +03:00
parent 74190bf773
commit 0388171d88
50 changed files with 326 additions and 333 deletions
@@ -2,10 +2,7 @@ package org.jetbrains.jet.codegen;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.FunctionDescriptor;
import org.jetbrains.jet.lang.types.JetStandardClasses;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.ValueParameterDescriptor;
import org.jetbrains.jet.lang.types.*;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
@@ -38,7 +35,7 @@ public class FunctionCodegen {
Type returnType;
if (returnTypeRef == null) {
final FunctionDescriptor functionDescriptor = bindingContext.getFunctionDescriptor(f);
final org.jetbrains.jet.lang.types.Type type = functionDescriptor.getUnsubstitutedReturnType();
final JetType type = functionDescriptor.getUnsubstitutedReturnType();
if (type.equals(JetStandardClasses.getUnitType())) {
returnType = Type.VOID_TYPE;
}
@@ -73,7 +70,7 @@ public class FunctionCodegen {
private void generateReturn(MethodVisitor mv, JetExpression bodyExpression) {
if (!endsWithReturn(bodyExpression)) {
final org.jetbrains.jet.lang.types.Type expressionType = bindingContext.getExpressionType(bodyExpression);
final JetType expressionType = bindingContext.getExpressionType(bodyExpression);
if (expressionType.equals(JetStandardClasses.getUnitType())) {
mv.visitInsn(Opcodes.RETURN);
}
@@ -3,7 +3,7 @@ package org.jetbrains.jet.lang;
import com.intellij.lang.ASTNode;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.types.Type;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
@@ -22,7 +22,7 @@ public class ErrorHandler {
}
@Override
public void typeMismatch(JetExpression expression, Type expectedType, Type actualType) {
public void typeMismatch(JetExpression expression, JetType expectedType, JetType actualType) {
throw new IllegalStateException("Type mismatch: inferred type is " + actualType + " but " + expectedType + " was expected");
}
};
@@ -33,6 +33,6 @@ public class ErrorHandler {
public void structuralError(ASTNode node, String errorMessage) {
}
public void typeMismatch(JetExpression expression, Type expectedType, Type actualType) {
public void typeMismatch(JetExpression expression, JetType expectedType, JetType actualType) {
}
}
@@ -15,7 +15,7 @@ import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.Type;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
@@ -49,7 +49,7 @@ public class JetPsiChecker implements Annotator {
}
@Override
public void typeMismatch(JetExpression expression, Type expectedType, Type actualType) {
public void typeMismatch(JetExpression expression, JetType expectedType, JetType actualType) {
holder.createErrorAnnotation(expression, "Type mismatch: inferred type is " + actualType + " but " + expectedType + " was expected");
}
});
@@ -58,7 +58,7 @@ public class JetPsiChecker implements Annotator {
public void visitClass(JetClass klass) {
for (JetDelegationSpecifier specifier : klass.getDelegationSpecifiers()) {
JetTypeReference typeReference = specifier.getTypeReference();
Type type = bindingContext.resolveTypeReference(typeReference);
JetType type = bindingContext.resolveTypeReference(typeReference);
holder.createWeakWarningAnnotation(typeReference, type.toString());
}
}
@@ -16,13 +16,13 @@ public interface BindingContext {
DeclarationDescriptor getDeclarationDescriptor(JetDeclaration declaration);
Type getExpressionType(JetExpression expression);
JetType getExpressionType(JetExpression expression);
JetScope getTopLevelScope();
DeclarationDescriptor resolveReferenceExpression(JetReferenceExpression referenceExpression);
Type resolveTypeReference(JetTypeReference typeReference);
JetType resolveTypeReference(JetTypeReference typeReference);
PsiElement resolveToDeclarationPsiElement(JetReferenceExpression referenceExpression);
PsiElement getDeclarationPsiElement(DeclarationDescriptor descriptor);
}
@@ -12,9 +12,9 @@ import java.util.Map;
* @author abreslav
*/
public class BindingTraceContext extends BindingTrace implements BindingContext {
private final Map<JetExpression, Type> expressionTypes = new HashMap<JetExpression, Type>();
private final Map<JetExpression, JetType> expressionTypes = new HashMap<JetExpression, JetType>();
private final Map<JetReferenceExpression, DeclarationDescriptor> resolutionResults = new HashMap<JetReferenceExpression, DeclarationDescriptor>();
private final Map<JetTypeReference, Type> types = new HashMap<JetTypeReference, Type>();
private final Map<JetTypeReference, JetType> types = new HashMap<JetTypeReference, JetType>();
private final Map<DeclarationDescriptor, PsiElement> descriptorToDeclarations = new HashMap<DeclarationDescriptor, PsiElement>();
private final Map<PsiElement, DeclarationDescriptor> declarationsToDescriptors = new HashMap<PsiElement, DeclarationDescriptor>();
private JetScope toplevelScope;
@@ -22,7 +22,7 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public void recordExpressionType(@NotNull JetExpression expression, @NotNull Type type) {
public void recordExpressionType(@NotNull JetExpression expression, @NotNull JetType type) {
expressionTypes.put(expression, type);
}
@@ -32,7 +32,7 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
}
@Override
public void recordTypeResolution(@NotNull JetTypeReference typeReference, @NotNull Type type) {
public void recordTypeResolution(@NotNull JetTypeReference typeReference, @NotNull JetType type) {
types.put(typeReference, type);
}
@@ -79,12 +79,12 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
}
@Override
public Type resolveTypeReference(JetTypeReference typeReference) {
public JetType resolveTypeReference(JetTypeReference typeReference) {
return types.get(typeReference);
}
@Override
public Type getExpressionType(JetExpression expression) {
public JetType getExpressionType(JetExpression expression) {
return expressionTypes.get(expression);
}
@@ -38,7 +38,7 @@ public class ClassDescriptorResolver {
List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers();
// TODO : assuming that the hierarchy is acyclic
Collection<? extends Type> superclasses = delegationSpecifiers.isEmpty()
Collection<? extends JetType> superclasses = delegationSpecifiers.isEmpty()
? Collections.singleton(JetStandardClasses.getAnyType())
: resolveTypes(parameterScope, delegationSpecifiers);
boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD);
@@ -63,7 +63,7 @@ public class ClassDescriptorResolver {
List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers();
// TODO : assuming that the hierarchy is acyclic
Collection<? extends Type> superclasses = delegationSpecifiers.isEmpty()
Collection<? extends JetType> superclasses = delegationSpecifiers.isEmpty()
? Collections.singleton(JetStandardClasses.getAnyType())
: resolveTypes(parameterScope, delegationSpecifiers);
boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD);
@@ -86,7 +86,7 @@ public class ClassDescriptorResolver {
List<TypeParameterDescriptor> typeParameters,
final JetScope outerScope,
final JetScope typeParameterScope,
final Collection<? extends Type> supertypes) {
final Collection<? extends JetType> supertypes) {
final WritableScope memberDeclarations = new WritableScope(typeParameterScope, classDescriptor);
@@ -136,7 +136,7 @@ public class ClassDescriptorResolver {
List<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, parameterScope, function.getTypeParameters());
List<ValueParameterDescriptor> valueParameterDescriptors = resolveValueParameters(functionDescriptor, parameterScope, function.getValueParameters());
Type returnType;
JetType returnType;
JetTypeReference returnTypeRef = function.getReturnTypeRef();
JetExpression bodyExpression = function.getBodyExpression();
if (returnTypeRef != null) {
@@ -170,7 +170,7 @@ public class ClassDescriptorResolver {
JetParameter valueParameter = valueParameters.get(i);
JetTypeReference typeReference = valueParameter.getTypeReference();
Type type;
JetType type;
if (typeReference == null) {
semanticServices.getErrorHandler().structuralError(valueParameter.getNode(), "A type annotation is required on a value parameter " + valueParameter.getName());
type = ErrorType.createErrorType("Type annotation was missing");
@@ -212,7 +212,7 @@ public class ClassDescriptorResolver {
typeParameter.getVariance(),
typeParameter.getName(),
extendsBound == null
? Collections.<Type>singleton(JetStandardClasses.getAnyType())
? Collections.<JetType>singleton(JetStandardClasses.getAnyType())
: Collections.singleton(typeResolver.resolveType(extensibleScope, extendsBound))
);
extensibleScope.addTypeParameterDescriptor(typeParameterDescriptor);
@@ -220,18 +220,18 @@ public class ClassDescriptorResolver {
return typeParameterDescriptor;
}
public Collection<? extends Type> resolveTypes(WritableScope extensibleScope, List<JetDelegationSpecifier> delegationSpecifiers) {
public Collection<? extends JetType> resolveTypes(WritableScope extensibleScope, List<JetDelegationSpecifier> delegationSpecifiers) {
if (delegationSpecifiers.isEmpty()) {
return Collections.emptyList();
}
Collection<Type> result = new ArrayList<Type>();
Collection<JetType> result = new ArrayList<JetType>();
for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
result.add(resolveType(extensibleScope, delegationSpecifier));
}
return result;
}
private Type resolveType(JetScope scope, JetDelegationSpecifier delegationSpecifier) {
private JetType resolveType(JetScope scope, JetDelegationSpecifier delegationSpecifier) {
JetTypeReference typeReference = delegationSpecifier.getTypeReference(); // TODO : make it not null
return typeResolver.resolveType(scope, typeReference);
}
@@ -249,7 +249,7 @@ public class ClassDescriptorResolver {
// TODO : receiver?
JetTypeReference propertyTypeRef = property.getPropertyTypeRef();
Type type;
JetType type;
if (propertyTypeRef == null) {
JetExpression initializer = property.getInitializer();
if (initializer == null) {
@@ -32,7 +32,7 @@ public interface JetScope {
TypeParameterDescriptor getTypeParameter(@NotNull String name);
@NotNull
Type getThisType();
JetType getThisType();
@NotNull
FunctionGroup getFunctionGroup(@NotNull String name);
@@ -15,7 +15,7 @@ public class JetScopeAdapter implements JetScope {
@NotNull
@Override
public Type getThisType() {
public JetType getThisType() {
return scope.getThisType();
}
@@ -34,7 +34,7 @@ public abstract class JetScopeImpl implements JetScope {
@NotNull
@Override
public Type getThisType() {
public JetType getThisType() {
return JetStandardClasses.getNothingType();
}
@@ -3,7 +3,7 @@ package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.types.FunctionDescriptor;
import org.jetbrains.jet.lang.types.Type;
import org.jetbrains.jet.lang.types.JetType;
import java.util.List;
import java.util.Map;
@@ -15,13 +15,13 @@ public interface OverloadDomain {
OverloadDomain EMPTY = new OverloadDomain() {
@Nullable
@Override
public FunctionDescriptor getFunctionDescriptorForNamedArguments(@NotNull List<Type> typeArguments, @NotNull Map<String, Type> valueArgumentTypes, @Nullable Type functionLiteralArgumentType) {
public FunctionDescriptor getFunctionDescriptorForNamedArguments(@NotNull List<JetType> typeArguments, @NotNull Map<String, JetType> valueArgumentTypes, @Nullable JetType functionLiteralArgumentType) {
return null;
}
@Nullable
@Override
public FunctionDescriptor getFunctionDescriptorForPositionedArguments(@NotNull List<Type> typeArguments, @NotNull List<Type> positionedValueArgumentTypes) {
public FunctionDescriptor getFunctionDescriptorForPositionedArguments(@NotNull List<JetType> typeArguments, @NotNull List<JetType> positionedValueArgumentTypes) {
return null;
}
};
@@ -34,9 +34,9 @@ public interface OverloadDomain {
*/
@Nullable
FunctionDescriptor getFunctionDescriptorForNamedArguments(
@NotNull List<Type> typeArguments,
@NotNull Map<String, Type> valueArgumentTypes,
@Nullable Type functionLiteralArgumentType);
@NotNull List<JetType> typeArguments,
@NotNull Map<String, JetType> valueArgumentTypes,
@Nullable JetType functionLiteralArgumentType);
/**
* @param typeArguments
@@ -45,6 +45,6 @@ public interface OverloadDomain {
*/
@Nullable
FunctionDescriptor getFunctionDescriptorForPositionedArguments(
@NotNull List<Type> typeArguments,
@NotNull List<Type> positionedValueArgumentTypes);
@NotNull List<JetType> typeArguments,
@NotNull List<JetType> positionedValueArgumentTypes);
}
@@ -18,7 +18,7 @@ public class OverloadResolver {
}
@NotNull
public OverloadDomain getOverloadDomain(Type receiverType, @NotNull JetScope outerScope, @NotNull String name) {
public OverloadDomain getOverloadDomain(JetType receiverType, @NotNull JetScope outerScope, @NotNull String name) {
// TODO : extension lookup
JetScope scope = receiverType == null ? outerScope : receiverType.getMemberScope();
@@ -30,7 +30,7 @@ public class OverloadResolver {
return new OverloadDomain() {
@Override
public FunctionDescriptor getFunctionDescriptorForPositionedArguments(@NotNull final List<Type> typeArguments, @NotNull List<Type> positionedValueArgumentTypes) {
public FunctionDescriptor getFunctionDescriptorForPositionedArguments(@NotNull final List<JetType> typeArguments, @NotNull List<JetType> positionedValueArgumentTypes) {
Collection<FunctionDescriptor> possiblyApplicableFunctions = functionGroup.getPossiblyApplicableFunctions(typeArguments, positionedValueArgumentTypes);
if (possiblyApplicableFunctions.isEmpty()) {
return null;
@@ -50,8 +50,8 @@ public class OverloadResolver {
// possibly, a single value passed to a vararg
// possibly an array/list/etc passed as a whole vararg
for (int i = 0, positionedValueArgumentTypesSize = positionedValueArgumentTypes.size(); i < positionedValueArgumentTypesSize; i++) {
Type argumentType = positionedValueArgumentTypes.get(i);
Type parameterType = parameters.get(i).getType();
JetType argumentType = positionedValueArgumentTypes.get(i);
JetType parameterType = parameters.get(i).getType();
// TODO : handle vararg cases here
if (!typeChecker.isConvertibleTo(argumentType, parameterType)) {
continue descLoop;
@@ -61,15 +61,15 @@ public class OverloadResolver {
// vararg
int nonVarargs = parameters.size() - 1;
for (int i = 0; i < nonVarargs; i++) {
Type argumentType = positionedValueArgumentTypes.get(i);
Type parameterType = parameters.get(i).getType();
JetType argumentType = positionedValueArgumentTypes.get(i);
JetType parameterType = parameters.get(i).getType();
if (!typeChecker.isConvertibleTo(argumentType, parameterType)) {
continue descLoop;
}
}
Type varArgType = parameters.get(nonVarargs).getType();
JetType varArgType = parameters.get(nonVarargs).getType();
for (int i = nonVarargs, args = positionedValueArgumentTypes.size(); i < args; i++) {
Type argumentType = positionedValueArgumentTypes.get(i);
JetType argumentType = positionedValueArgumentTypes.get(i);
if (!typeChecker.isConvertibleTo(argumentType, varArgType)) {
continue descLoop;
}
@@ -105,7 +105,7 @@ public class OverloadResolver {
}
@Override
public FunctionDescriptor getFunctionDescriptorForNamedArguments(@NotNull List<Type> typeArguments, @NotNull Map<String, Type> valueArgumentTypes, @Nullable Type functionLiteralArgumentType) {
public FunctionDescriptor getFunctionDescriptorForNamedArguments(@NotNull List<JetType> typeArguments, @NotNull Map<String, JetType> valueArgumentTypes, @Nullable JetType functionLiteralArgumentType) {
throw new UnsupportedOperationException(); // TODO
}
};
@@ -118,8 +118,8 @@ public class OverloadResolver {
int fSize = fParams.size();
if (fSize != gParams.size()) return false;
for (int i = 0; i < fSize; i++) {
Type fParamType = fParams.get(i).getType();
Type gParamType = gParams.get(i).getType();
JetType fParamType = fParams.get(i).getType();
JetType gParamType = gParams.get(i).getType();
// TODO : maybe isSubtypeOf is sufficient?
if (!typeChecker.isConvertibleTo(fParamType, gParamType)) {
@@ -11,7 +11,7 @@ public class ScopeWithReceiver extends JetScopeImpl {
private final JetScope receiverTypeScope;
private final JetScope outerScope;
public ScopeWithReceiver(JetScope outerScope, Type receiverType) {
public ScopeWithReceiver(JetScope outerScope, JetType receiverType) {
this.outerScope = outerScope;
this.receiverTypeScope = receiverType.getMemberScope();
}
@@ -44,7 +44,7 @@ public class ScopeWithReceiver extends JetScopeImpl {
@NotNull
@Override
public Type getThisType() {
public JetType getThisType() {
return receiverTypeScope.getThisType();
}
@@ -53,7 +53,7 @@ public class SubstitutingScope implements JetScope {
@NotNull
@Override
public Type getThisType() {
public JetType getThisType() {
throw new UnsupportedOperationException(); // TODO
}
@@ -78,7 +78,7 @@ public class TopDownAnalyzer {
}
if (importDirective.isAllUnder()) {
JetExpression importedReference = importDirective.getImportedReference();
Type type = semanticServices.getTypeInferrer(trace).getType(namespaceScope, importedReference, false);
JetType type = semanticServices.getTypeInferrer(trace).getType(namespaceScope, importedReference, false);
if (type != null) {
namespaceScope.importScope(type.getMemberScope());
}
@@ -25,18 +25,18 @@ public class TypeResolver {
}
@NotNull
public Type resolveType(@NotNull final JetScope scope, @NotNull final JetTypeReference typeReference) {
public JetType resolveType(@NotNull final JetScope scope, @NotNull final JetTypeReference typeReference) {
final List<Attribute> attributes = AttributeResolver.INSTANCE.resolveAttributes(typeReference.getAttributes());
JetTypeElement typeElement = typeReference.getTypeElement();
Type type = resolveTypeElement(scope, attributes, typeElement, false);
JetType type = resolveTypeElement(scope, attributes, typeElement, false);
trace.recordTypeResolution(typeReference, type);
return type;
}
@NotNull
private Type resolveTypeElement(final JetScope scope, final List<Attribute> attributes, JetTypeElement typeElement, final boolean nullable) {
final Type[] result = new Type[1];
private JetType resolveTypeElement(final JetScope scope, final List<Attribute> attributes, JetTypeElement typeElement, final boolean nullable) {
final JetType[] result = new JetType[1];
if (typeElement != null) {
typeElement.accept(new JetVisitor() {
@Override
@@ -46,7 +46,7 @@ public class TypeResolver {
trace.recordReferenceResolution(type.getReferenceExpression(), classDescriptor);
TypeConstructor typeConstructor = classDescriptor.getTypeConstructor();
List<TypeProjection> arguments = resolveTypeProjections(scope, typeConstructor, type.getTypeArguments());
result[0] = new TypeImpl(
result[0] = new JetTypeImpl(
attributes,
typeConstructor,
nullable,
@@ -58,7 +58,7 @@ public class TypeResolver {
TypeParameterDescriptor typeParameterDescriptor = scope.getTypeParameter(type.getReferencedName());
if (typeParameterDescriptor != null) {
trace.recordReferenceResolution(type.getReferenceExpression(), typeParameterDescriptor);
result[0] = new TypeImpl(
result[0] = new JetTypeImpl(
attributes,
typeParameterDescriptor.getTypeConstructor(),
nullable || hasNullableBound(typeParameterDescriptor),
@@ -89,14 +89,14 @@ public class TypeResolver {
@Override
public void visitFunctionType(JetFunctionType type) {
JetTypeReference receiverTypeRef = type.getReceiverTypeRef();
Type receiverType = receiverTypeRef == null ? null : resolveType(scope, receiverTypeRef);
JetType receiverType = receiverTypeRef == null ? null : resolveType(scope, receiverTypeRef);
List<Type> parameterTypes = new ArrayList<Type>();
List<JetType> parameterTypes = new ArrayList<JetType>();
for (JetParameter parameter : type.getParameters()) {
parameterTypes.add(resolveType(scope, parameter.getTypeReference()));
}
Type returnType = resolveType(scope, type.getReturnTypeRef());
JetType returnType = resolveType(scope, type.getReturnTypeRef());
result[0] = JetStandardClasses.getFunctionType(attributes, receiverType, parameterTypes, returnType);
}
@@ -114,7 +114,7 @@ public class TypeResolver {
}
private boolean hasNullableBound(TypeParameterDescriptor typeParameterDescriptor) {
for (Type bound : typeParameterDescriptor.getUpperBounds()) {
for (JetType bound : typeParameterDescriptor.getUpperBounds()) {
if (bound.isNullable()) {
return true;
}
@@ -122,8 +122,8 @@ public class TypeResolver {
return false;
}
private List<Type> resolveTypes(JetScope scope, List<JetTypeReference> argumentElements) {
final List<Type> arguments = new ArrayList<Type>();
private List<JetType> resolveTypes(JetScope scope, List<JetTypeReference> argumentElements) {
final List<JetType> arguments = new ArrayList<JetType>();
for (JetTypeReference argumentElement : argumentElements) {
arguments.add(resolveType(scope, argumentElement));
}
@@ -137,9 +137,9 @@ public class TypeResolver {
JetTypeProjection argumentElement = argumentElements.get(i);
JetProjectionKind projectionKind = argumentElement.getProjectionKind();
Type type;
JetType type;
if (projectionKind == JetProjectionKind.STAR) {
Set<Type> upperBounds = constructor.getParameters().get(i).getUpperBounds();
Set<JetType> upperBounds = constructor.getParameters().get(i).getUpperBounds();
arguments.add(new TypeProjection(Variance.OUT_VARIANCE, TypeUtils.intersect(semanticServices.getTypeChecker(), upperBounds)));
}
else {
@@ -44,7 +44,7 @@ public class WritableFunctionGroup implements FunctionGroup {
@NotNull
@Override
public Collection<FunctionDescriptor> getPossiblyApplicableFunctions(@NotNull List<Type> typeArguments, @NotNull List<Type> positionedValueArgumentTypes) {
public Collection<FunctionDescriptor> getPossiblyApplicableFunctions(@NotNull List<JetType> typeArguments, @NotNull List<JetType> positionedValueArgumentTypes) {
int typeArgCount = typeArguments.size();
int valueArgCount = positionedValueArgumentTypes.size();
Collection<FunctionDescriptor> result = new ArrayList<FunctionDescriptor>();
@@ -24,7 +24,7 @@ public class WritableScope extends JetScopeAdapter {
@Nullable
private Map<String, NamespaceDescriptor> namespaceDescriptors;
@Nullable
private Type thisType;
private JetType thisType;
@Nullable
private List<JetScope> imports;
@@ -194,7 +194,7 @@ public class WritableScope extends JetScopeAdapter {
@NotNull
@Override
public Type getThisType() {
public JetType getThisType() {
if (thisType == null) {
return super.getThisType();
}
@@ -243,7 +243,7 @@ public class WritableScope extends JetScopeAdapter {
return super.getExtension(name); // TODO
}
public void setThisType(Type thisType) {
public void setThisType(JetType thisType) {
if (this.thisType != null) {
throw new UnsupportedOperationException("Receiver redeclared");
}
@@ -99,7 +99,7 @@ public class JavaClassMembersScope implements JetScope {
@NotNull
@Override
public Type getThisType() {
public JetType getThisType() {
return null;
}
}
@@ -77,17 +77,17 @@ public class JavaDescriptorResolver {
return classDescriptor;
}
private Collection<? extends Type> getSupertypes(PsiClass psiClass) {
List<Type> result = new ArrayList<Type>();
private Collection<? extends JetType> getSupertypes(PsiClass psiClass) {
List<JetType> result = new ArrayList<JetType>();
result.add(JetStandardClasses.getAnyType());
transformSupertypeList(result, psiClass.getExtendsListTypes());
transformSupertypeList(result, psiClass.getImplementsListTypes());
return result;
}
private void transformSupertypeList(List<Type> result, PsiClassType[] extendsListTypes) {
private void transformSupertypeList(List<JetType> result, PsiClassType[] extendsListTypes) {
for (PsiClassType type : extendsListTypes) {
Type transform = semanticServices.getTypeTransformer().transform(type);
JetType transform = semanticServices.getTypeTransformer().transform(type);
result.add(TypeUtils.makeNotNullable(transform));
}
@@ -16,7 +16,7 @@ public class JavaTypeTransformer {
private final JavaDescriptorResolver resolver;
private final JetStandardLibrary standardLibrary;
private Map<String, Type> primitiveTypesMap;
private Map<String, JetType> primitiveTypesMap;
public JavaTypeTransformer(JetStandardLibrary standardLibrary, JavaDescriptorResolver resolver) {
this.resolver = resolver;
@@ -24,10 +24,10 @@ public class JavaTypeTransformer {
}
@NotNull
public Type transform(PsiType javaType) {
return javaType.accept(new PsiTypeVisitor<Type>() {
public JetType transform(PsiType javaType) {
return javaType.accept(new PsiTypeVisitor<JetType>() {
@Override
public Type visitClassType(PsiClassType classType) {
public JetType visitClassType(PsiClassType classType) {
PsiClass psiClass = classType.resolveGenerics().getElement();
if (psiClass == null) {
return ErrorType.createErrorType("Unresolved java class: " + classType.getPresentableText());
@@ -40,7 +40,7 @@ public class JavaTypeTransformer {
ClassDescriptor descriptor = resolver.resolveClass(psiClass);
// TODO : arguments & raw types
List<TypeProjection> arguments = Collections.<TypeProjection>emptyList(); // TODO
return new TypeImpl(
return new JetTypeImpl(
Collections.<Attribute>emptyList(),
descriptor.getTypeConstructor(),
true,
@@ -49,29 +49,29 @@ public class JavaTypeTransformer {
}
@Override
public Type visitPrimitiveType(PsiPrimitiveType primitiveType) {
public JetType visitPrimitiveType(PsiPrimitiveType primitiveType) {
String canonicalText = primitiveType.getCanonicalText();
Type type = getPrimitiveTypesMap().get(canonicalText);
JetType type = getPrimitiveTypesMap().get(canonicalText);
assert type != null : canonicalText;
return type;
}
@Override
public Type visitArrayType(PsiArrayType arrayType) {
Type type = transform(arrayType.getComponentType());
public JetType visitArrayType(PsiArrayType arrayType) {
JetType type = transform(arrayType.getComponentType());
return TypeUtils.makeNullable(standardLibrary.getArrayType(type));
}
@Override
public Type visitType(PsiType type) {
public JetType visitType(PsiType type) {
throw new UnsupportedOperationException("Unsupported type: " + type.getPresentableText()); // TODO
}
});
}
public Map<String, Type> getPrimitiveTypesMap() {
public Map<String, JetType> getPrimitiveTypesMap() {
if (primitiveTypesMap == null) {
primitiveTypesMap = new HashMap<String, Type>();
primitiveTypesMap = new HashMap<String, JetType>();
primitiveTypesMap.put("byte", standardLibrary.getByteType());
primitiveTypesMap.put("short", standardLibrary.getShortType());
primitiveTypesMap.put("char", standardLibrary.getCharType());
@@ -11,7 +11,7 @@ import org.jetbrains.jet.lang.resolve.JetScope;
public class BindingTrace {
public static final BindingTrace DUMMY = new BindingTrace();
public void recordExpressionType(@NotNull JetExpression expression, @NotNull Type type) {
public void recordExpressionType(@NotNull JetExpression expression, @NotNull JetType type) {
}
public void recordReferenceResolution(@NotNull JetReferenceExpression expression, @NotNull DeclarationDescriptor descriptor) {
@@ -22,7 +22,7 @@ public class BindingTrace {
}
public void recordTypeResolution(@NotNull JetTypeReference typeReference, @NotNull Type type) {
public void recordTypeResolution(@NotNull JetTypeReference typeReference, @NotNull JetType type) {
}
@@ -32,7 +32,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
//
public final ClassDescriptorImpl initialize(boolean sealed,
List<TypeParameterDescriptor> typeParameters,
Collection<? extends Type> superclasses, JetScope memberDeclarations) {
Collection<? extends JetType> superclasses, JetScope memberDeclarations) {
this.typeConstructor = new TypeConstructor(getAttributes(), sealed, getName(), typeParameters, superclasses);
this.memberDeclarations = memberDeclarations;
return this;
@@ -5,11 +5,11 @@ package org.jetbrains.jet.lang.types;
*/
public class DfsNodeHandler<R> {
public void beforeChildren(Type current) {
public void beforeChildren(JetType current) {
}
public void afterChildren(Type current) {
public void afterChildren(JetType current) {
}
@@ -38,7 +38,7 @@ public class ErrorType {
@NotNull
@Override
public Type getThisType() {
public JetType getThisType() {
throw new UnsupportedOperationException(); // TODO
}
@@ -58,23 +58,23 @@ public class ErrorType {
private ErrorType() {}
public static Type createErrorType(String debugMessage) {
public static JetType createErrorType(String debugMessage) {
return createErrorType(debugMessage, ERROR_SCOPE);
}
private static Type createErrorType(String debugMessage, JetScope memberScope) {
return new ErrorTypeImpl(new TypeConstructor(Collections.<Attribute>emptyList(), false, "[ERROR : " + debugMessage + "]", Collections.<TypeParameterDescriptor>emptyList(), Collections.<Type>emptyList()), memberScope);
private static JetType createErrorType(String debugMessage, JetScope memberScope) {
return new ErrorTypeImpl(new TypeConstructor(Collections.<Attribute>emptyList(), false, "[ERROR : " + debugMessage + "]", Collections.<TypeParameterDescriptor>emptyList(), Collections.<JetType>emptyList()), memberScope);
}
public static Type createWrongVarianceErrorType(TypeProjection value) {
public static JetType createWrongVarianceErrorType(TypeProjection value) {
return createErrorType(value + " is not allowed here]", value.getType().getMemberScope());
}
public static boolean isErrorType(Type type) {
public static boolean isErrorType(JetType type) {
return type instanceof ErrorTypeImpl;
}
private static class ErrorTypeImpl implements Type {
private static class ErrorTypeImpl implements JetType {
private final TypeConstructor constructor;
private final JetScope memberScope;
@@ -15,7 +15,7 @@ public interface FunctionDescriptor extends DeclarationDescriptor {
List<ValueParameterDescriptor> getUnsubstitutedValueParameters();
@NotNull
Type getUnsubstitutedReturnType();
JetType getUnsubstitutedReturnType();
@NotNull
FunctionDescriptor getOriginal();
@@ -13,7 +13,7 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
private List<ValueParameterDescriptor> unsubstitutedValueParameters;
private Type unsubstitutedReturnType;
private JetType unsubstitutedReturnType;
private final FunctionDescriptor original;
public FunctionDescriptorImpl(
@@ -35,7 +35,7 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
public final void initialize(
@NotNull List<TypeParameterDescriptor> typeParameters,
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
@NotNull Type unsubstitutedReturnType) {
@NotNull JetType unsubstitutedReturnType) {
this.typeParameters = typeParameters;
this.unsubstitutedValueParameters = unsubstitutedValueParameters;
this.unsubstitutedReturnType = unsubstitutedReturnType;
@@ -55,7 +55,7 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
@Override
@NotNull
public Type getUnsubstitutedReturnType() {
public JetType getUnsubstitutedReturnType() {
return unsubstitutedReturnType;
}
@@ -38,7 +38,7 @@ public class FunctionDescriptorUtil {
}
@NotNull
public static List<ValueParameterDescriptor> getSubstitutedValueParameters(FunctionDescriptor substitutedDescriptor, @NotNull FunctionDescriptor functionDescriptor, @NotNull List<Type> typeArguments) {
public static List<ValueParameterDescriptor> getSubstitutedValueParameters(FunctionDescriptor substitutedDescriptor, @NotNull FunctionDescriptor functionDescriptor, @NotNull List<JetType> typeArguments) {
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
Map<TypeConstructor, TypeProjection> context = createSubstitutionContext(functionDescriptor, typeArguments);
List<ValueParameterDescriptor> unsubstitutedValueParameters = functionDescriptor.getUnsubstitutedValueParameters();
@@ -58,7 +58,7 @@ public class FunctionDescriptorUtil {
return result;
}
private static Map<TypeConstructor, TypeProjection> createSubstitutionContext(@NotNull FunctionDescriptor functionDescriptor, List<Type> typeArguments) {
private static Map<TypeConstructor, TypeProjection> createSubstitutionContext(@NotNull FunctionDescriptor functionDescriptor, List<JetType> typeArguments) {
Map<TypeConstructor,TypeProjection> result = new HashMap<TypeConstructor, TypeProjection>();
int typeArgumentsSize = typeArguments.size();
@@ -66,19 +66,19 @@ public class FunctionDescriptorUtil {
assert typeArgumentsSize == typeParameters.size();
for (int i = 0; i < typeArgumentsSize; i++) {
TypeParameterDescriptor typeParameterDescriptor = typeParameters.get(i);
Type typeArgument = typeArguments.get(i);
JetType typeArgument = typeArguments.get(i);
result.put(typeParameterDescriptor.getTypeConstructor(), new TypeProjection(typeArgument));
}
return result;
}
@NotNull
public static Type getSubstitutedReturnType(@NotNull FunctionDescriptor functionDescriptor, @NotNull List<Type> typeArguments) {
public static JetType getSubstitutedReturnType(@NotNull FunctionDescriptor functionDescriptor, @NotNull List<JetType> typeArguments) {
return TypeSubstitutor.INSTANCE.substitute(createSubstitutionContext(functionDescriptor, typeArguments), functionDescriptor.getUnsubstitutedReturnType(), Variance.OUT_VARIANCE);
}
@NotNull
public static FunctionDescriptor substituteFunctionDescriptor(@NotNull List<Type> typeArguments, @NotNull FunctionDescriptor functionDescriptor) {
public static FunctionDescriptor substituteFunctionDescriptor(@NotNull List<JetType> typeArguments, @NotNull FunctionDescriptor functionDescriptor) {
if (functionDescriptor.getTypeParameters().isEmpty()) {
return functionDescriptor;
}
@@ -18,7 +18,7 @@ public interface FunctionGroup extends Named {
@NotNull
@Override
public Collection<FunctionDescriptor> getPossiblyApplicableFunctions(@NotNull List<Type> typeArguments, @NotNull List<Type> positionedValueArgumentTypes) {
public Collection<FunctionDescriptor> getPossiblyApplicableFunctions(@NotNull List<JetType> typeArguments, @NotNull List<JetType> positionedValueArgumentTypes) {
return Collections.emptySet();
}
@@ -34,7 +34,7 @@ public interface FunctionGroup extends Named {
String getName();
@NotNull
Collection<FunctionDescriptor> getPossiblyApplicableFunctions(@NotNull List<Type> typeArguments, @NotNull List<Type> positionedValueArgumentTypes);
Collection<FunctionDescriptor> getPossiblyApplicableFunctions(@NotNull List<JetType> typeArguments, @NotNull List<JetType> positionedValueArgumentTypes);
boolean isEmpty();
}
@@ -27,14 +27,14 @@ public class JetStandardClasses {
"Nothing").initialize(
true,
Collections.<TypeParameterDescriptor>emptyList(),
new AbstractCollection<Type>() {
new AbstractCollection<JetType>() {
@Override
public boolean contains(Object o) {
return o instanceof Type;
return o instanceof JetType;
}
@Override
public Iterator<Type> iterator() {
public Iterator<JetType> iterator() {
throw new UnsupportedOperationException();
}
@@ -44,9 +44,9 @@ public class JetStandardClasses {
}
}, JetScope.EMPTY
);
private static final Type NOTHING_TYPE = new TypeImpl(getNothing());
private static final JetType NOTHING_TYPE = new JetTypeImpl(getNothing());
private static final Type NULLABLE_NOTHING_TYPE = new TypeImpl(
private static final JetType NULLABLE_NOTHING_TYPE = new JetTypeImpl(
Collections.<Attribute>emptyList(),
getNothing().getTypeConstructor(),
true,
@@ -61,12 +61,12 @@ public class JetStandardClasses {
"Any").initialize(
false,
Collections.<TypeParameterDescriptor>emptyList(),
Collections.<Type>emptySet(),
Collections.<JetType>emptySet(),
JetScope.EMPTY
);
private static final Type ANY_TYPE = new TypeImpl(ANY.getTypeConstructor(), JetScope.EMPTY);
private static final JetType ANY_TYPE = new JetTypeImpl(ANY.getTypeConstructor(), JetScope.EMPTY);
private static final Type NULLABLE_ANY_TYPE = TypeUtils.makeNullable(ANY_TYPE);
private static final JetType NULLABLE_ANY_TYPE = TypeUtils.makeNullable(ANY_TYPE);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -152,7 +152,7 @@ public class JetStandardClasses {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private static final Type UNIT_TYPE = new TypeImpl(getTuple(0));
private static final JetType UNIT_TYPE = new JetTypeImpl(getTuple(0));
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -198,11 +198,11 @@ public class JetStandardClasses {
}
@NotNull
public static Type getAnyType() {
public static JetType getAnyType() {
return ANY_TYPE;
}
public static Type getNullableAnyType() {
public static JetType getNullableAnyType() {
return NULLABLE_ANY_TYPE;
}
@@ -226,57 +226,57 @@ public class JetStandardClasses {
return RECEIVER_FUNCTION[parameterCount];
}
public static Type getUnitType() {
public static JetType getUnitType() {
return UNIT_TYPE;
}
public static Type getNothingType() {
public static JetType getNothingType() {
return NOTHING_TYPE;
}
public static Type getNullableNothingType() {
public static JetType getNullableNothingType() {
return NULLABLE_NOTHING_TYPE;
}
public static boolean isNothing(Type type) {
public static boolean isNothing(JetType type) {
return type.getConstructor() == NOTHING_CLASS.getTypeConstructor();
}
public static Type getTupleType(List<Attribute> attributes, List<Type> arguments) {
public static JetType getTupleType(List<Attribute> attributes, List<JetType> arguments) {
if (attributes.isEmpty() && arguments.isEmpty()) {
return getUnitType();
}
return new TypeImpl(attributes, getTuple(arguments.size()).getTypeConstructor(), false, toProjections(arguments), STUB);
return new JetTypeImpl(attributes, getTuple(arguments.size()).getTypeConstructor(), false, toProjections(arguments), STUB);
}
public static Type getTupleType(List<Type> arguments) {
public static JetType getTupleType(List<JetType> arguments) {
return getTupleType(Collections.<Attribute>emptyList(), arguments);
}
public static Type getTupleType(Type... arguments) {
public static JetType getTupleType(JetType... arguments) {
return getTupleType(Collections.<Attribute>emptyList(), Arrays.asList(arguments));
}
public static Type getLabeledTupleType(List<Attribute> attributes, List<ValueParameterDescriptor> arguments) {
public static JetType getLabeledTupleType(List<Attribute> attributes, List<ValueParameterDescriptor> arguments) {
// TODO
return getTupleType(attributes, toTypes(arguments));
}
public static Type getLabeledTupleType(List<ValueParameterDescriptor> arguments) {
public static JetType getLabeledTupleType(List<ValueParameterDescriptor> arguments) {
// TODO
return getLabeledTupleType(Collections.<Attribute>emptyList(), arguments);
}
private static List<TypeProjection> toProjections(List<Type> arguments) {
private static List<TypeProjection> toProjections(List<JetType> arguments) {
List<TypeProjection> result = new ArrayList<TypeProjection>();
for (Type argument : arguments) {
for (JetType argument : arguments) {
result.add(new TypeProjection(Variance.OUT_VARIANCE, argument));
}
return result;
}
private static List<Type> toTypes(List<ValueParameterDescriptor> labeledEntries) {
List<Type> result = new ArrayList<Type>();
private static List<JetType> toTypes(List<ValueParameterDescriptor> labeledEntries) {
List<JetType> result = new ArrayList<JetType>();
for (ValueParameterDescriptor entry : labeledEntries) {
result.add(entry.getType());
}
@@ -284,21 +284,21 @@ public class JetStandardClasses {
}
// TODO : labeled version?
public static Type getFunctionType(List<Attribute> attributes, @Nullable Type receiverType, @NotNull List<Type> parameterTypes, @NotNull Type returnType) {
public static JetType getFunctionType(List<Attribute> attributes, @Nullable JetType receiverType, @NotNull List<JetType> parameterTypes, @NotNull JetType returnType) {
List<TypeProjection> arguments = new ArrayList<TypeProjection>();
if (receiverType != null) {
arguments.add(defaultProjection(receiverType));
}
for (Type parameterType : parameterTypes) {
for (JetType parameterType : parameterTypes) {
arguments.add(defaultProjection(parameterType));
}
arguments.add(defaultProjection(returnType));
int size = parameterTypes.size();
TypeConstructor constructor = receiverType == null ? FUNCTION[size].getTypeConstructor() : RECEIVER_FUNCTION[size].getTypeConstructor();
return new TypeImpl(attributes, constructor, false, arguments, STUB);
return new JetTypeImpl(attributes, constructor, false, arguments, STUB);
}
private static TypeProjection defaultProjection(Type returnType) {
private static TypeProjection defaultProjection(JetType returnType) {
return new TypeProjection(Variance.INVARIANT, returnType);
}
}
@@ -50,15 +50,15 @@ public class JetStandardLibrary {
private final ClassDescriptor stringClass;
private final ClassDescriptor arrayClass;
private final Type byteType;
private final Type charType;
private final Type shortType;
private final Type intType;
private final Type longType;
private final Type floatType;
private final Type doubleType;
private final Type booleanType;
private final Type stringType;
private final JetType byteType;
private final JetType charType;
private final JetType shortType;
private final JetType intType;
private final JetType longType;
private final JetType floatType;
private final JetType doubleType;
private final JetType booleanType;
private final JetType stringType;
private JetStandardLibrary(@NotNull Project project) {
// TODO : review
@@ -87,15 +87,15 @@ public class JetStandardLibrary {
this.stringClass = libraryScope.getClass("String");
this.arrayClass = libraryScope.getClass("Array");
this.byteType = new TypeImpl(getByte());
this.charType = new TypeImpl(getChar());
this.shortType = new TypeImpl(getShort());
this.intType = new TypeImpl(getInt());
this.longType = new TypeImpl(getLong());
this.floatType = new TypeImpl(getFloat());
this.doubleType = new TypeImpl(getDouble());
this.booleanType = new TypeImpl(getBoolean());
this.stringType = new TypeImpl(getString());
this.byteType = new JetTypeImpl(getByte());
this.charType = new JetTypeImpl(getChar());
this.shortType = new JetTypeImpl(getShort());
this.intType = new JetTypeImpl(getInt());
this.longType = new JetTypeImpl(getLong());
this.floatType = new JetTypeImpl(getFloat());
this.doubleType = new JetTypeImpl(getDouble());
this.booleanType = new JetTypeImpl(getBoolean());
this.stringType = new JetTypeImpl(getString());
} catch (IOException e) {
throw new IllegalStateException(e);
}
@@ -156,60 +156,60 @@ public class JetStandardLibrary {
}
@NotNull
public Type getIntType() {
public JetType getIntType() {
return intType;
}
@NotNull
public Type getLongType() {
public JetType getLongType() {
return longType;
}
@NotNull
public Type getDoubleType() {
public JetType getDoubleType() {
return doubleType;
}
@NotNull
public Type getFloatType() {
public JetType getFloatType() {
return floatType;
}
@NotNull
public Type getCharType() {
public JetType getCharType() {
return charType;
}
@NotNull
public Type getBooleanType() {
public JetType getBooleanType() {
return booleanType;
}
@NotNull
public Type getStringType() {
public JetType getStringType() {
return stringType;
}
@NotNull
public Type getByteType() {
public JetType getByteType() {
return byteType;
}
@NotNull
public Type getShortType() {
public JetType getShortType() {
return shortType;
}
@NotNull
public Type getArrayType(@NotNull Type argument) {
public JetType getArrayType(@NotNull JetType argument) {
Variance variance = Variance.INVARIANT;
return getArrayType(variance, argument);
}
@NotNull
public Type getArrayType(@NotNull Variance variance, @NotNull Type argument) {
public JetType getArrayType(@NotNull Variance variance, @NotNull JetType argument) {
List<TypeProjection> types = Collections.singletonList(new TypeProjection(variance, argument));
return new TypeImpl(
return new JetTypeImpl(
Collections.<Attribute>emptyList(),
getArray().getTypeConstructor(),
false,
@@ -8,7 +8,7 @@ import java.util.List;
/**
* @author abreslav
*/
public interface Type extends Annotated {
public interface JetType extends Annotated {
@NotNull TypeConstructor getConstructor();
@NotNull List<TypeProjection> getArguments();
boolean isNullable();
@@ -63,12 +63,12 @@ public class JetTypeChecker {
conversionMap.put(actual.getTypeConstructor(), new HashSet<TypeConstructor>(Arrays.asList(constructors)));
}
public Type commonSupertype(Collection<Type> types) {
Collection<Type> typeSet = new HashSet<Type>(types);
public JetType commonSupertype(Collection<JetType> types) {
Collection<JetType> typeSet = new HashSet<JetType>(types);
assert !typeSet.isEmpty();
boolean nullable = false;
for (Iterator<Type> iterator = typeSet.iterator(); iterator.hasNext();) {
Type type = iterator.next();
for (Iterator<JetType> iterator = typeSet.iterator(); iterator.hasNext();) {
JetType type = iterator.next();
if (JetStandardClasses.isNothing(type)) {
iterator.remove();
}
@@ -84,22 +84,22 @@ public class JetTypeChecker {
return TypeUtils.makeNullableIfNeeded(typeSet.iterator().next(), nullable);
}
Map<TypeConstructor, Set<Type>> commonSupertypes = computeCommonRawSupertypes(typeSet);
Map<TypeConstructor, Set<JetType>> commonSupertypes = computeCommonRawSupertypes(typeSet);
while (commonSupertypes.size() > 1) {
HashSet<Type> merge = new HashSet<Type>();
for (Set<Type> supertypes : commonSupertypes.values()) {
HashSet<JetType> merge = new HashSet<JetType>();
for (Set<JetType> supertypes : commonSupertypes.values()) {
merge.addAll(supertypes);
}
commonSupertypes = computeCommonRawSupertypes(merge);
}
assert !commonSupertypes.isEmpty();
Map.Entry<TypeConstructor, Set<Type>> entry = commonSupertypes.entrySet().iterator().next();
Type result = computeSupertypeProjections(entry.getKey(), entry.getValue());
Map.Entry<TypeConstructor, Set<JetType>> entry = commonSupertypes.entrySet().iterator().next();
JetType result = computeSupertypeProjections(entry.getKey(), entry.getValue());
return TypeUtils.makeNullableIfNeeded(result, nullable);
}
private Type computeSupertypeProjections(TypeConstructor constructor, Set<Type> types) {
private JetType computeSupertypeProjections(TypeConstructor constructor, Set<JetType> types) {
// we assume that all the given types are applications of the same type constructor
assert !types.isEmpty();
@@ -113,19 +113,19 @@ public class JetTypeChecker {
for (int i = 0, parametersSize = parameters.size(); i < parametersSize; i++) {
TypeParameterDescriptor parameterDescriptor = parameters.get(i);
Set<TypeProjection> typeProjections = new HashSet<TypeProjection>();
for (Type type : types) {
for (JetType type : types) {
typeProjections.add(type.getArguments().get(i));
}
newProjections.add(computeSupertypeProjection(parameterDescriptor, typeProjections));
}
boolean nullable = false;
for (Type type : types) {
for (JetType type : types) {
nullable |= type.isNullable();
}
// TODO : attributes?
return new TypeImpl(Collections.<Attribute>emptyList(), constructor, nullable, newProjections, JetStandardClasses.STUB);
return new JetTypeImpl(Collections.<Attribute>emptyList(), constructor, nullable, newProjections, JetStandardClasses.STUB);
}
private TypeProjection computeSupertypeProjection(TypeParameterDescriptor parameterDescriptor, Set<TypeProjection> typeProjections) {
@@ -133,8 +133,8 @@ public class JetTypeChecker {
return typeProjections.iterator().next();
}
Set<Type> ins = new HashSet<Type>();
Set<Type> outs = new HashSet<Type>();
Set<JetType> ins = new HashSet<JetType>();
Set<JetType> outs = new HashSet<JetType>();
Variance variance = parameterDescriptor.getVariance();
switch (variance) {
@@ -170,7 +170,7 @@ public class JetTypeChecker {
if (ins != null) {
Variance projectionKind = variance == Variance.IN_VARIANCE ? Variance.INVARIANT : Variance.IN_VARIANCE;
Type intersection = TypeUtils.intersect(this, ins);
JetType intersection = TypeUtils.intersect(this, ins);
if (intersection == null) {
return new TypeProjection(Variance.OUT_VARIANCE, commonSupertype(parameterDescriptor.getUpperBounds()));
}
@@ -184,33 +184,33 @@ public class JetTypeChecker {
}
}
private Map<TypeConstructor, Set<Type>> computeCommonRawSupertypes(Collection<Type> types) {
private Map<TypeConstructor, Set<JetType>> computeCommonRawSupertypes(Collection<JetType> types) {
assert !types.isEmpty();
final Map<TypeConstructor, Set<Type>> constructorToAllInstances = new HashMap<TypeConstructor, Set<Type>>();
final Map<TypeConstructor, Set<JetType>> constructorToAllInstances = new HashMap<TypeConstructor, Set<JetType>>();
Set<TypeConstructor> commonSuperclasses = null;
List<TypeConstructor> order = null;
for (Type type : types) {
for (JetType type : types) {
Set<TypeConstructor> visited = new HashSet<TypeConstructor>();
order = dfs(type, visited, new DfsNodeHandler<List<TypeConstructor>>() {
public LinkedList<TypeConstructor> list = new LinkedList<TypeConstructor>();
@Override
public void beforeChildren(Type current) {
public void beforeChildren(JetType current) {
TypeConstructor constructor = current.getConstructor();
Set<Type> instances = constructorToAllInstances.get(constructor);
Set<JetType> instances = constructorToAllInstances.get(constructor);
if (instances == null) {
instances = new HashSet<Type>();
instances = new HashSet<JetType>();
constructorToAllInstances.put(constructor, instances);
}
instances.add(current);
}
@Override
public void afterChildren(Type current) {
public void afterChildren(JetType current) {
list.addFirst(current.getConstructor());
}
@@ -230,7 +230,7 @@ public class JetTypeChecker {
assert order != null;
Set<TypeConstructor> notSource = new HashSet<TypeConstructor>();
Map<TypeConstructor, Set<Type>> result = new HashMap<TypeConstructor, Set<Type>>();
Map<TypeConstructor, Set<JetType>> result = new HashMap<TypeConstructor, Set<JetType>>();
for (TypeConstructor superConstructor : order) {
if (!commonSuperclasses.contains(superConstructor)) {
continue;
@@ -247,38 +247,38 @@ public class JetTypeChecker {
private void markAll(TypeConstructor typeConstructor, Set<TypeConstructor> markerSet) {
markerSet.add(typeConstructor);
for (Type type : typeConstructor.getSupertypes()) {
for (JetType type : typeConstructor.getSupertypes()) {
markAll(type.getConstructor(), markerSet);
}
}
private <R> R dfs(Type current, Set<TypeConstructor> visited, DfsNodeHandler<R> handler) {
private <R> R dfs(JetType current, Set<TypeConstructor> visited, DfsNodeHandler<R> handler) {
doDfs(current, visited, handler);
return handler.result();
}
private void doDfs(Type current, Set<TypeConstructor> visited, DfsNodeHandler<?> handler) {
private void doDfs(JetType current, Set<TypeConstructor> visited, DfsNodeHandler<?> handler) {
if (!visited.add(current.getConstructor())) {
return;
}
handler.beforeChildren(current);
Map<TypeConstructor, TypeProjection> substitutionContext = TypeSubstitutor.INSTANCE.getSubstitutionContext(current);
for (Type supertype : current.getConstructor().getSupertypes()) {
for (JetType supertype : current.getConstructor().getSupertypes()) {
TypeConstructor supertypeConstructor = supertype.getConstructor();
if (visited.contains(supertypeConstructor)) {
continue;
}
Type substitutedSupertype = TypeSubstitutor.INSTANCE.substitute(substitutionContext, supertype, Variance.INVARIANT);
JetType substitutedSupertype = TypeSubstitutor.INSTANCE.substitute(substitutionContext, supertype, Variance.INVARIANT);
dfs(substitutedSupertype, visited, handler);
}
handler.afterChildren(current);
}
public boolean isConvertibleTo(JetExpression expression, Type type) {
public boolean isConvertibleTo(JetExpression expression, JetType type) {
throw new UnsupportedOperationException(); // TODO
}
public boolean isConvertibleTo(Type actual, Type expected) {
public boolean isConvertibleTo(JetType actual, JetType expected) {
if (isSubtypeOf(actual, expected)) return true;
if (expected.getConstructor() == JetStandardClasses.getTuple(0).getTypeConstructor()) {
return true;
@@ -294,14 +294,14 @@ public class JetTypeChecker {
return false;
}
public boolean isSubtypeOf(@NotNull Type subtype, @NotNull Type supertype) {
public boolean isSubtypeOf(@NotNull JetType subtype, @NotNull JetType supertype) {
if (!supertype.isNullable() && subtype.isNullable()) {
return false;
}
if (JetStandardClasses.isNothing(subtype)) {
return true;
}
@Nullable Type closestSupertype = findCorrespondingSupertype(subtype, supertype);
@Nullable JetType closestSupertype = findCorrespondingSupertype(subtype, supertype);
if (closestSupertype == null) {
return false;
}
@@ -312,13 +312,13 @@ public class JetTypeChecker {
// This method returns the supertype of the first parameter that has the same constructor
// as the second parameter, applying the substitution of type arguments to it
@Nullable
private Type findCorrespondingSupertype(Type subtype, Type supertype) {
private JetType findCorrespondingSupertype(JetType subtype, JetType supertype) {
TypeConstructor constructor = subtype.getConstructor();
if (constructor.equals(supertype.getConstructor())) {
return subtype;
}
for (Type immediateSupertype : constructor.getSupertypes()) {
Type correspondingSupertype = findCorrespondingSupertype(immediateSupertype, supertype);
for (JetType immediateSupertype : constructor.getSupertypes()) {
JetType correspondingSupertype = findCorrespondingSupertype(immediateSupertype, supertype);
if (correspondingSupertype != null) {
return TypeSubstitutor.INSTANCE.substitute(subtype, correspondingSupertype, Variance.INVARIANT);
}
@@ -326,7 +326,7 @@ public class JetTypeChecker {
return null;
}
private boolean checkSubtypeForTheSameConstructor(Type subtype, Type supertype) {
private boolean checkSubtypeForTheSameConstructor(JetType subtype, JetType supertype) {
TypeConstructor constructor = subtype.getConstructor();
assert constructor.equals(supertype.getConstructor());
@@ -338,13 +338,13 @@ public class JetTypeChecker {
TypeProjection subArgument = subArguments.get(i);
TypeProjection superArgument = superArguments.get(i);
Type subArgumentType = subArgument.getType();
Type superArgumentType = superArgument.getType();
JetType subArgumentType = subArgument.getType();
JetType superArgumentType = superArgument.getType();
switch (parameter.getVariance()) {
case INVARIANT:
switch (superArgument.getProjectionKind()) {
case INVARIANT:
if (!TypeImpl.equalTypes(subArgumentType, superArgumentType)) {
if (!JetTypeImpl.equalTypes(subArgumentType, superArgumentType)) {
return false;
}
break;
@@ -10,14 +10,14 @@ import java.util.List;
/**
* @author abreslav
*/
public final class TypeImpl extends AnnotatedImpl implements Type {
public final class JetTypeImpl extends AnnotatedImpl implements JetType {
private final TypeConstructor constructor;
private final List<TypeProjection> arguments;
private final boolean nullable;
private JetScope memberScope;
public TypeImpl(List<Attribute> attributes, TypeConstructor constructor, boolean nullable, List<TypeProjection> arguments, JetScope memberScope) {
public JetTypeImpl(List<Attribute> attributes, TypeConstructor constructor, boolean nullable, List<TypeProjection> arguments, JetScope memberScope) {
super(attributes);
this.constructor = constructor;
this.nullable = nullable;
@@ -25,11 +25,11 @@ public final class TypeImpl extends AnnotatedImpl implements Type {
this.memberScope = memberScope;
}
public TypeImpl(TypeConstructor constructor, JetScope memberScope) {
public JetTypeImpl(TypeConstructor constructor, JetScope memberScope) {
this(Collections.<Attribute>emptyList(), constructor, false, Collections.<TypeProjection>emptyList(), memberScope);
}
public TypeImpl(@NotNull ClassDescriptor classDescriptor) {
public JetTypeImpl(@NotNull ClassDescriptor classDescriptor) {
this(Collections.<Attribute>emptyList(),
classDescriptor.getTypeConstructor(),
false,
@@ -82,7 +82,7 @@ public final class TypeImpl extends AnnotatedImpl implements Type {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TypeImpl type = (TypeImpl) o;
JetTypeImpl type = (JetTypeImpl) o;
// TODO
return equalTypes(this, type);
@@ -103,7 +103,7 @@ public final class TypeImpl extends AnnotatedImpl implements Type {
}
public static boolean equalTypes(@NotNull Type type1, @NotNull Type type2) {
public static boolean equalTypes(@NotNull JetType type1, @NotNull JetType type2) {
if (type1.isNullable() != type2.isNullable()) {
return false;
}
@@ -29,8 +29,8 @@ public class JetTypeInferrer {
}
@NotNull
public Type safeGetType(@NotNull final JetScope scope, @NotNull JetExpression expression, final boolean preferBlock) {
Type type = getType(scope, expression, preferBlock);
public JetType safeGetType(@NotNull final JetScope scope, @NotNull JetExpression expression, final boolean preferBlock) {
JetType type = getType(scope, expression, preferBlock);
if (type != null) {
return type;
}
@@ -38,8 +38,8 @@ public class JetTypeInferrer {
}
@Nullable
public Type getType(@NotNull final JetScope scope, @NotNull JetExpression expression, final boolean preferBlock) {
final Type[] result = new Type[1];
public JetType getType(@NotNull final JetScope scope, @NotNull JetExpression expression, final boolean preferBlock) {
final JetType[] result = new JetType[1];
expression.accept(new JetVisitor() {
@Override
public void visitReferenceExpression(JetSimpleNameExpression expression) {
@@ -74,7 +74,7 @@ public class JetTypeInferrer {
JetTypeReference returnTypeRef = expression.getReturnTypeRef();
JetTypeReference receiverTypeRef = expression.getReceiverTypeRef();
final Type receiverType;
final JetType receiverType;
if (receiverTypeRef != null) {
receiverType = typeResolver.resolveType(scope, receiverTypeRef);
} else {
@@ -83,7 +83,7 @@ public class JetTypeInferrer {
List<JetElement> body = expression.getBody();
final Map<String, PropertyDescriptor> parameterDescriptors = new HashMap<String, PropertyDescriptor>();
List<Type> parameterTypes = new ArrayList<Type>();
List<JetType> parameterTypes = new ArrayList<JetType>();
for (JetParameter parameter : expression.getParameters()) {
JetTypeReference typeReference = parameter.getTypeReference();
if (typeReference == null) {
@@ -93,7 +93,7 @@ public class JetTypeInferrer {
parameterDescriptors.put(parameter.getName(), propertyDescriptor);
parameterTypes.add(propertyDescriptor.getType());
}
Type returnType;
JetType returnType;
if (returnTypeRef != null) {
returnType = typeResolver.resolveType(scope, returnTypeRef);
} else {
@@ -174,8 +174,8 @@ public class JetTypeInferrer {
@Override
public void visitBinaryWithTypeRHSExpression(JetBinaryExpressionWithTypeRHS expression) {
if (expression.getOperationReference().getReferencedNameElementType() == JetTokens.COLON) {
Type actualType = getType(scope, expression.getLeft(), false);
Type expectedType = typeResolver.resolveType(scope, expression.getRight());
JetType actualType = getType(scope, expression.getLeft(), false);
JetType expectedType = typeResolver.resolveType(scope, expression.getRight());
if (actualType != null && !semanticServices.getTypeChecker().isSubtypeOf(actualType, expectedType)) {
// TODO
semanticServices.getErrorHandler().typeMismatch(expression.getLeft(), expectedType, actualType);
@@ -195,8 +195,8 @@ public class JetTypeInferrer {
// TODO : type-check the branch
result[0] = JetStandardClasses.getUnitType();
} else {
Type thenType = getType(scope, expression.getThen(), true);
Type elseType = getType(scope, elseBranch, true);
JetType thenType = getType(scope, expression.getThen(), true);
JetType elseType = getType(scope, elseBranch, true);
result[0] = semanticServices.getTypeChecker().commonSupertype(Arrays.asList(thenType, elseType));
}
}
@@ -204,7 +204,7 @@ public class JetTypeInferrer {
@Override
public void visitWhenExpression(JetWhenExpression expression) {
// TODO :change scope according to the bound value in the when header
List<Type> expressions = new ArrayList<Type>();
List<JetType> expressions = new ArrayList<JetType>();
collectAllReturnTypes(expression, scope, expressions);
result[0] = semanticServices.getTypeChecker().commonSupertype(expressions);
}
@@ -214,7 +214,7 @@ public class JetTypeInferrer {
JetExpression tryBlock = expression.getTryBlock();
List<JetCatchClause> catchClauses = expression.getCatchClauses();
JetFinallySection finallyBlock = expression.getFinallyBlock();
List<Type> types = new ArrayList<Type>();
List<JetType> types = new ArrayList<JetType>();
if (finallyBlock == null) {
for (JetCatchClause catchClause : catchClauses) {
// TODO: change scope here
@@ -230,7 +230,7 @@ public class JetTypeInferrer {
@Override
public void visitTupleExpression(JetTupleExpression expression) {
List<JetExpression> entries = expression.getEntries();
List<Type> types = new ArrayList<Type>();
List<JetType> types = new ArrayList<JetType>();
for (JetExpression entry : entries) {
types.add(getType(scope, entry, false));
}
@@ -241,15 +241,15 @@ public class JetTypeInferrer {
@Override
public void visitThisExpression(JetThisExpression expression) {
// TODO : qualified this, e.g. Foo.this<Bar>
Type thisType = scope.getThisType();
JetType thisType = scope.getThisType();
JetTypeReference superTypeQualifier = expression.getSuperTypeQualifier();
if (superTypeQualifier != null) {
// This cast must be safe (assuming the PSI doesn't contain errors)
JetUserType typeElement = (JetUserType) superTypeQualifier.getTypeElement();
ClassDescriptor superclass = typeResolver.resolveClass(scope, typeElement);
Collection<? extends Type> supertypes = thisType.getConstructor().getSupertypes();
Collection<? extends JetType> supertypes = thisType.getConstructor().getSupertypes();
Map<TypeConstructor, TypeProjection> substitutionContext = TypeSubstitutor.INSTANCE.getSubstitutionContext(thisType);
for (Type declaredSupertype : supertypes) {
for (JetType declaredSupertype : supertypes) {
if (declaredSupertype.getConstructor().equals(superclass.getTypeConstructor())) {
result[0] = TypeSubstitutor.INSTANCE.substitute(substitutionContext, declaredSupertype, Variance.INVARIANT);
break;
@@ -283,7 +283,7 @@ public class JetTypeInferrer {
// TODO : functions
JetExpression receiverExpression = expression.getReceiverExpression();
JetExpression selectorExpression = expression.getSelectorExpression();
Type receiverType = getType(scope, receiverExpression, false);
JetType receiverType = getType(scope, receiverExpression, false);
if (receiverType != null) { // TODO : review
JetScope compositeScope = new ScopeWithReceiver(scope, receiverType);
result[0] = getType(compositeScope, selectorExpression, false);
@@ -322,7 +322,7 @@ public class JetTypeInferrer {
// result[0] = overloadDomain.getFunctionDescriptorForNamedArguments(typeArguments, valueArguments, functionLiteralArgument);
} else {
List<Type> types = new ArrayList<Type>();
List<JetType> types = new ArrayList<JetType>();
for (JetTypeProjection projection : typeArguments) {
// TODO : check that there's no projection
types.add(typeResolver.resolveType(scope, projection.getTypeReference()));
@@ -335,7 +335,7 @@ public class JetTypeInferrer {
positionedValueArguments.addAll(functionLiteralArguments);
List<Type> valueArgumentTypes = new ArrayList<Type>();
List<JetType> valueArgumentTypes = new ArrayList<JetType>();
for (JetExpression valueArgument : positionedValueArguments) {
valueArgumentTypes.add(getType(scope, valueArgument, false));
}
@@ -378,9 +378,9 @@ public class JetTypeInferrer {
@Override
public void visitArrayAccessExpression(JetArrayAccessExpression expression) {
JetExpression arrayExpression = expression.getArrayExpression();
Type receiverType = getType(scope, arrayExpression, false);
JetType receiverType = getType(scope, arrayExpression, false);
List<JetExpression> indexExpressions = expression.getIndexExpressions();
List<Type> argumentTypes = getTypes(scope, indexExpressions);
List<JetType> argumentTypes = getTypes(scope, indexExpressions);
if (argumentTypes == null) return;
FunctionDescriptor functionDescriptor = lookupFunction(scope, expression, "get", receiverType, argumentTypes);
@@ -390,13 +390,13 @@ public class JetTypeInferrer {
}
private void resolveArrayAccessToLValue(JetArrayAccessExpression arrayAccessExpression, JetExpression rightHandSide, JetSimpleNameExpression operationSign) {
List<Type> argumentTypes = getTypes(scope, arrayAccessExpression.getIndexExpressions());
List<JetType> argumentTypes = getTypes(scope, arrayAccessExpression.getIndexExpressions());
if (argumentTypes == null) return;
Type rhsType = getType(scope, rightHandSide, false);
JetType rhsType = getType(scope, rightHandSide, false);
if (rhsType == null) return;
argumentTypes.add(rhsType);
Type receiverType = getType(scope, arrayAccessExpression.getArrayExpression(), false);
JetType receiverType = getType(scope, arrayAccessExpression.getArrayExpression(), false);
if (receiverType == null) return;
// TODO : nasty hack: effort is duplicated
@@ -412,15 +412,15 @@ public class JetTypeInferrer {
throw new IllegalArgumentException("Unsupported element: " + elem);
}
private Type getTypeForBinaryCall(JetBinaryExpression expression, String name, JetScope scope) {
private JetType getTypeForBinaryCall(JetBinaryExpression expression, String name, JetScope scope) {
JetSimpleNameExpression operationSign = expression.getOperationReference();
JetExpression left = expression.getLeft();
Type leftType = getType(scope, left, false);
JetType leftType = getType(scope, left, false);
JetExpression right = expression.getRight();
if (right == null) {
return ErrorType.createErrorType("No right argument");
}
Type rightType = getType(scope, right, false);
JetType rightType = getType(scope, right, false);
FunctionDescriptor functionDescriptor = lookupFunction(scope, operationSign, name, leftType, Collections.singletonList(rightType));
if (functionDescriptor != null) {
return functionDescriptor.getUnsubstitutedReturnType();
@@ -443,17 +443,17 @@ public class JetTypeInferrer {
}
@Nullable
private FunctionDescriptor lookupFunction(JetScope scope, JetReferenceExpression reference, String name, Type receiverType, List<Type> argumentTypes) {
private FunctionDescriptor lookupFunction(JetScope scope, JetReferenceExpression reference, String name, JetType receiverType, List<JetType> argumentTypes) {
OverloadDomain overloadDomain = semanticServices.getOverloadResolver().getOverloadDomain(receiverType, scope, name);
overloadDomain = wrapForTracing(overloadDomain, reference);
return overloadDomain.getFunctionDescriptorForPositionedArguments(Collections.<Type>emptyList(), argumentTypes);
return overloadDomain.getFunctionDescriptorForPositionedArguments(Collections.<JetType>emptyList(), argumentTypes);
}
@Nullable
private List<Type> getTypes(JetScope scope, List<JetExpression> indexExpressions) {
List<Type> argumentTypes = new ArrayList<Type>();
private List<JetType> getTypes(JetScope scope, List<JetExpression> indexExpressions) {
List<JetType> argumentTypes = new ArrayList<JetType>();
for (JetExpression indexExpression : indexExpressions) {
Type type = getType(scope, indexExpression, false);
JetType type = getType(scope, indexExpression, false);
if (type == null) {
return null;
}
@@ -487,7 +487,7 @@ public class JetTypeInferrer {
if (selectorExpression instanceof JetSimpleNameExpression) {
JetSimpleNameExpression referenceExpression = (JetSimpleNameExpression) selectorExpression;
Type receiverType = getType(scope, expression.getReceiverExpression(), false);
JetType receiverType = getType(scope, expression.getReceiverExpression(), false);
if (receiverType != null) {
result[0] = semanticServices.getOverloadResolver().getOverloadDomain(receiverType, scope, referenceExpression.getReferencedName());
reference[0] = referenceExpression;
@@ -522,7 +522,7 @@ public class JetTypeInferrer {
if (overloadDomain == null) return OverloadDomain.EMPTY;
return new OverloadDomain() {
@Override
public FunctionDescriptor getFunctionDescriptorForNamedArguments(@NotNull List<Type> typeArguments, @NotNull Map<String, Type> valueArgumentTypes, @Nullable Type functionLiteralArgumentType) {
public FunctionDescriptor getFunctionDescriptorForNamedArguments(@NotNull List<JetType> typeArguments, @NotNull Map<String, JetType> valueArgumentTypes, @Nullable JetType functionLiteralArgumentType) {
FunctionDescriptor descriptor = overloadDomain.getFunctionDescriptorForNamedArguments(typeArguments, valueArgumentTypes, functionLiteralArgumentType);
if (descriptor != null) {
trace.recordReferenceResolution(referenceExpression, descriptor);
@@ -533,23 +533,19 @@ public class JetTypeInferrer {
}
@Override
public FunctionDescriptor getFunctionDescriptorForPositionedArguments(@NotNull List<Type> typeArguments, @NotNull List<Type> positionedValueArgumentTypes) {
public FunctionDescriptor getFunctionDescriptorForPositionedArguments(@NotNull List<JetType> typeArguments, @NotNull List<JetType> positionedValueArgumentTypes) {
FunctionDescriptor descriptor = overloadDomain.getFunctionDescriptorForPositionedArguments(typeArguments, positionedValueArgumentTypes);
if (descriptor != null) {
if (referenceExpression != null) {
trace.recordReferenceResolution(referenceExpression, descriptor);
}
trace.recordReferenceResolution(referenceExpression, descriptor);
} else {
if (referenceExpression != null) {
semanticServices.getErrorHandler().unresolvedReference(referenceExpression);
}
semanticServices.getErrorHandler().unresolvedReference(referenceExpression);
}
return descriptor;
}
};
}
private Type getBlockReturnedType(@NotNull JetScope outerScope, List<JetElement> block) {
private JetType getBlockReturnedType(@NotNull JetScope outerScope, List<JetElement> block) {
if (block.isEmpty()) {
return JetStandardClasses.getUnitType();
} else {
@@ -580,7 +576,7 @@ public class JetTypeInferrer {
}
}
private void collectAllReturnTypes(JetWhenExpression whenExpression, JetScope scope, List<Type> result) {
private void collectAllReturnTypes(JetWhenExpression whenExpression, JetScope scope, List<JetType> result) {
for (JetWhenEntry entry : whenExpression.getEntries()) {
JetWhenExpression subWhen = entry.getSubWhen();
if (subWhen != null) {
@@ -11,7 +11,7 @@ import java.util.Map;
public class LazySubstitutedPropertyDescriptorImpl implements PropertyDescriptor {
private final PropertyDescriptor propertyDescriptor;
private final Map<TypeConstructor, TypeProjection> substitutionContext;
private Type propertyType = null;
private JetType propertyType = null;
public LazySubstitutedPropertyDescriptorImpl(@NotNull PropertyDescriptor propertyDescriptor, @NotNull Map<TypeConstructor, TypeProjection> substitutionContext) {
this.propertyDescriptor = propertyDescriptor;
@@ -19,7 +19,7 @@ public class LazySubstitutedPropertyDescriptorImpl implements PropertyDescriptor
}
@Override
public Type getType() {
public JetType getType() {
if (propertyType == null) {
propertyType = TypeSubstitutor.INSTANCE.substitute(substitutionContext, propertyDescriptor.getType(), Variance.OUT_VARIANCE);
}
@@ -56,7 +56,7 @@ public class LazySubstitutingFunctionDescriptor implements FunctionDescriptor {
@NotNull
@Override
public Type getUnsubstitutedReturnType() {
public JetType getUnsubstitutedReturnType() {
return TypeSubstitutor.INSTANCE.substitute(substitutionContext, functionDescriptor.getUnsubstitutedReturnType(), Variance.OUT_VARIANCE);
}
@@ -27,7 +27,7 @@ public class LazySubstitutingFunctionGroup implements FunctionGroup {
@NotNull
@Override
public Collection<FunctionDescriptor> getPossiblyApplicableFunctions(@NotNull List<Type> typeArguments, @NotNull List<Type> positionedValueArgumentTypes) {
public Collection<FunctionDescriptor> getPossiblyApplicableFunctions(@NotNull List<JetType> typeArguments, @NotNull List<JetType> positionedValueArgumentTypes) {
Collection<FunctionDescriptor> possiblyApplicableFunctions = functionGroup.getPossiblyApplicableFunctions(typeArguments, positionedValueArgumentTypes);
Collection<FunctionDescriptor> result = new ArrayList<FunctionDescriptor>();
for (FunctionDescriptor function : possiblyApplicableFunctions) {
@@ -11,7 +11,7 @@ import java.util.List;
*
* @author abreslav
*/
public class NamespaceType implements Type {
public class NamespaceType implements JetType {
private final String name;
private final JetScope memberScope;
@@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull;
* @author abreslav
*/
public interface PropertyDescriptor extends DeclarationDescriptor {
Type getType();
JetType getType();
@Override
@NotNull
@@ -8,15 +8,15 @@ import java.util.List;
* @author abreslav
*/
public class PropertyDescriptorImpl extends DeclarationDescriptorImpl implements PropertyDescriptor {
private Type type;
private JetType type;
public PropertyDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, List<Attribute> attributes, String name, Type type) {
public PropertyDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, List<Attribute> attributes, String name, JetType type) {
super(containingDeclaration, attributes, name);
this.type = type;
}
@Override
public Type getType() {
public JetType getType() {
return type;
}
@@ -9,11 +9,11 @@ import java.util.List;
*/
public class TypeConstructor extends AnnotatedImpl {
private final List<TypeParameterDescriptor> parameters;
private final Collection<? extends Type> supertypes;
private final Collection<? extends JetType> supertypes;
private final String debugName;
private final boolean sealed;
public TypeConstructor(List<Attribute> attributes, boolean sealed, String debugName, List<TypeParameterDescriptor> parameters, Collection<? extends Type> supertypes) {
public TypeConstructor(List<Attribute> attributes, boolean sealed, String debugName, List<TypeParameterDescriptor> parameters, Collection<? extends JetType> supertypes) {
super(attributes);
this.sealed = sealed;
this.debugName = debugName;
@@ -25,7 +25,7 @@ public class TypeConstructor extends AnnotatedImpl {
return parameters;
}
public Collection<? extends Type> getSupertypes() {
public Collection<? extends JetType> getSupertypes() {
return supertypes;
}
@@ -11,10 +11,10 @@ import java.util.Set;
*/
public class TypeParameterDescriptor extends DeclarationDescriptorImpl {
private final Variance variance;
private final Set<Type> upperBounds;
private final Set<JetType> upperBounds;
private final TypeConstructor typeConstructor;
public TypeParameterDescriptor(@NotNull DeclarationDescriptor containingDeclaration, List<Attribute> attributes, Variance variance, String name, Set<Type> upperBounds) {
public TypeParameterDescriptor(@NotNull DeclarationDescriptor containingDeclaration, List<Attribute> attributes, Variance variance, String name, Set<JetType> upperBounds) {
super(containingDeclaration, attributes, name);
this.variance = variance;
this.upperBounds = upperBounds;
@@ -35,7 +35,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl {
return variance;
}
public Set<Type> getUpperBounds() {
public Set<JetType> getUpperBounds() {
return upperBounds;
}
@@ -7,14 +7,14 @@ import org.jetbrains.annotations.NotNull;
*/
public class TypeProjection {
private final Variance projection;
private final Type type;
private final JetType type;
public TypeProjection(@NotNull Variance projection, @NotNull Type type) {
public TypeProjection(@NotNull Variance projection, @NotNull JetType type) {
this.projection = projection;
this.type = type;
}
public TypeProjection(Type type) {
public TypeProjection(JetType type) {
this(Variance.INVARIANT, type);
}
@@ -22,7 +22,7 @@ public class TypeProjection {
return projection;
}
public Type getType() {
public JetType getType() {
return type;
}
@@ -12,12 +12,12 @@ public class TypeSubstitutor {
private TypeSubstitutor() {}
public Type substitute(@NotNull Type context, @NotNull Type subject, @NotNull Variance howThisTypeIsUsed) {
public JetType substitute(@NotNull JetType context, @NotNull JetType subject, @NotNull Variance howThisTypeIsUsed) {
return substitute(getSubstitutionContext(context), subject, howThisTypeIsUsed);
}
@NotNull
public Type substitute(@NotNull Map<TypeConstructor, TypeProjection> substitutionContext, @NotNull Type type, @NotNull Variance howThisTypeIsUsed) {
public JetType substitute(@NotNull Map<TypeConstructor, TypeProjection> substitutionContext, @NotNull JetType type, @NotNull Variance howThisTypeIsUsed) {
TypeProjection value = substitutionContext.get(type.getConstructor());
if (value != null) {
Variance projectionKind = value.getProjectionKind();
@@ -31,7 +31,7 @@ public class TypeSubstitutor {
return specializeType(type, substituteInArguments(substitutionContext, type));
}
public Map<TypeConstructor, TypeProjection> getSubstitutionContext(Type context) {
public Map<TypeConstructor, TypeProjection> getSubstitutionContext(JetType context) {
List<TypeParameterDescriptor> parameters = context.getConstructor().getParameters();
List<TypeProjection> contextArguments = context.getArguments();
@@ -50,7 +50,7 @@ public class TypeSubstitutor {
@NotNull
private TypeProjection substituteInProjection(Map<TypeConstructor, TypeProjection> parameterValues, TypeProjection subject) {
@NotNull Type subjectType = subject.getType();
@NotNull JetType subjectType = subject.getType();
TypeProjection value = parameterValues.get(subjectType.getConstructor());
if (value != null) {
return value;
@@ -59,7 +59,7 @@ public class TypeSubstitutor {
return new TypeProjection(subject.getProjectionKind(), specializeType(subjectType, newArguments));
}
private List<TypeProjection> substituteInArguments(Map<TypeConstructor, TypeProjection> parameterValues, Type subjectType) {
private List<TypeProjection> substituteInArguments(Map<TypeConstructor, TypeProjection> parameterValues, JetType subjectType) {
List<TypeProjection> newArguments = new ArrayList<TypeProjection>();
for (TypeProjection argument : subjectType.getArguments()) {
newArguments.add(substituteInProjection(parameterValues, argument));
@@ -67,13 +67,13 @@ public class TypeSubstitutor {
return newArguments;
}
private Type specializeType(Type type, List<TypeProjection> newArguments) {
return new TypeImpl(type.getAttributes(), type.getConstructor(), type.isNullable(), newArguments, type.getMemberScope());
private JetType specializeType(JetType type, List<TypeProjection> newArguments) {
return new JetTypeImpl(type.getAttributes(), type.getConstructor(), type.isNullable(), newArguments, type.getMemberScope());
}
public Set<Type> substituteInSet(Map<TypeConstructor, TypeProjection> substitutionContext, Set<Type> types, Variance howTheseTypesWillBeUsed) {
Set<Type> result = new HashSet<Type>();
for (Type type : types) {
public Set<JetType> substituteInSet(Map<TypeConstructor, TypeProjection> substitutionContext, Set<JetType> types, Variance howTheseTypesWillBeUsed) {
Set<JetType> result = new HashSet<JetType>();
for (JetType type : types) {
result.add(substitute(substitutionContext, type, howTheseTypesWillBeUsed));
}
return result;
@@ -11,22 +11,22 @@ import java.util.Set;
* @author abreslav
*/
public class TypeUtils {
public static Type makeNullable(Type type) {
public static JetType makeNullable(JetType type) {
if (type.isNullable()) {
return type;
}
return new TypeImpl(type.getAttributes(), type.getConstructor(), true, type.getArguments(), type.getMemberScope());
return new JetTypeImpl(type.getAttributes(), type.getConstructor(), true, type.getArguments(), type.getMemberScope());
}
public static Type makeNotNullable(Type type) {
public static JetType makeNotNullable(JetType type) {
if (!type.isNullable()) {
return type;
}
return new TypeImpl(type.getAttributes(), type.getConstructor(), false, type.getArguments(), type.getMemberScope());
return new JetTypeImpl(type.getAttributes(), type.getConstructor(), false, type.getArguments(), type.getMemberScope());
}
@Nullable
public static Type intersect(JetTypeChecker typeChecker, Set<Type> types) {
public static JetType intersect(JetTypeChecker typeChecker, Set<JetType> types) {
assert !types.isEmpty();
if (types.size() == 1) {
@@ -35,11 +35,11 @@ public class TypeUtils {
StringBuilder debugName = new StringBuilder();
boolean nullable = false;
for (Iterator<Type> iterator = types.iterator(); iterator.hasNext();) {
Type type = iterator.next();
for (Iterator<JetType> iterator = types.iterator(); iterator.hasNext();) {
JetType type = iterator.next();
if (!canHaveSubtypes(typeChecker, type)) {
for (Type other : types) {
for (JetType other : types) {
if (type != other || !typeChecker.isSubtypeOf(type, other)) {
return null;
}
@@ -57,7 +57,7 @@ public class TypeUtils {
List<Attribute> noAttributes = Collections.<Attribute>emptyList();
TypeConstructor constructor = new TypeConstructor(noAttributes, false, debugName.toString(), Collections.<TypeParameterDescriptor>emptyList(), types);
return new TypeImpl(
return new JetTypeImpl(
noAttributes,
constructor,
nullable,
@@ -65,7 +65,7 @@ public class TypeUtils {
JetStandardClasses.STUB);
}
private static boolean canHaveSubtypes(JetTypeChecker typeChecker, Type type) {
private static boolean canHaveSubtypes(JetTypeChecker typeChecker, JetType type) {
if (type.isNullable()) {
return true;
}
@@ -79,7 +79,7 @@ public class TypeUtils {
TypeParameterDescriptor parameterDescriptor = parameters.get(i);
TypeProjection typeProjection = arguments.get(i);
Variance projectionKind = typeProjection.getProjectionKind();
Type argument = typeProjection.getType();
JetType argument = typeProjection.getType();
switch (parameterDescriptor.getVariance()) {
case INVARIANT:
@@ -128,8 +128,8 @@ public class TypeUtils {
return false;
}
private static boolean lowerThanBound(JetTypeChecker typeChecker, Type argument, TypeParameterDescriptor parameterDescriptor) {
for (Type bound : parameterDescriptor.getUpperBounds()) {
private static boolean lowerThanBound(JetTypeChecker typeChecker, JetType argument, TypeParameterDescriptor parameterDescriptor) {
for (JetType bound : parameterDescriptor.getUpperBounds()) {
if (typeChecker.isSubtypeOf(argument, bound)) {
if (!argument.getConstructor().equals(bound.getConstructor())) {
return true;
@@ -139,7 +139,7 @@ public class TypeUtils {
return false;
}
public static Type makeNullableIfNeeded(Type type, boolean nullable) {
public static JetType makeNullableIfNeeded(JetType type, boolean nullable) {
if (nullable) {
return makeNullable(type);
}
@@ -12,7 +12,7 @@ public class ValueParameterDescriptorImpl extends PropertyDescriptorImpl impleme
private final boolean isVararg;
private final int index;
public ValueParameterDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, int index, List<Attribute> attributes, String name, Type type, boolean hasDefaultValue, boolean isVararg) {
public ValueParameterDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, int index, List<Attribute> attributes, String name, JetType type, boolean hasDefaultValue, boolean isVararg) {
super(containingDeclaration, attributes, name, type);
this.index = index;
this.hasDefaultValue = hasDefaultValue;
@@ -15,7 +15,7 @@ public class DescriptorUtil {
new DeclarationDescriptorVisitor<Void, StringBuilder>() {
@Override
public Void visitPropertyDescriptor(PropertyDescriptor descriptor, StringBuilder builder) {
Type type = descriptor.getType();
JetType type = descriptor.getType();
builder.append(renderName(descriptor)).append(" : ").append(type);
return super.visitPropertyDescriptor(descriptor, builder);
}
@@ -94,7 +94,7 @@ public class DescriptorUtil {
private static void renderTypeParameter(TypeParameterDescriptor descriptor, StringBuilder builder) {
builder.append(renderName(descriptor));
if (!descriptor.getUpperBounds().isEmpty()) {
Type bound = descriptor.getUpperBounds().iterator().next();
JetType bound = descriptor.getUpperBounds().iterator().next();
if (bound != JetStandardClasses.getAnyType()) {
builder.append(" : ").append(bound);
if (descriptor.getUpperBounds().size() > 1) {
@@ -126,7 +126,7 @@ public class ExpectedResolveData {
continue;
}
Type actualType = bindingContext.resolveTypeReference(typeReference);
JetType actualType = bindingContext.resolveTypeReference(typeReference);
assertNotNull("Type " + name + " not resolved for reference " + name, actualType);
ClassDescriptor expectedClass = lib.getLibraryScope().getClass(name.substring(5));
assertNotNull("Expected class not found: " + name);
@@ -156,7 +156,7 @@ public class ExpectedResolveData {
PsiElement element = file.findElementAt(position);
JetExpression expression = getAncestorOfType(JetExpression.class, element);
Type expressionType = bindingContext.getExpressionType(expression);
JetType expressionType = bindingContext.getExpressionType(expression);
TypeConstructor expectedTypeConstructor;
if (typeName.startsWith("std::")) {
ClassDescriptor expectedClass = lib.getLibraryScope().getClass(typeName.substring(5));
@@ -83,16 +83,16 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
}
@NotNull
private FunctionDescriptor standardFunction(ClassDescriptor classDescriptor, String name, Type parameterType) {
private FunctionDescriptor standardFunction(ClassDescriptor classDescriptor, String name, JetType parameterType) {
List<TypeProjection> typeArguments = Collections.emptyList();
return standardFunction(classDescriptor, typeArguments, name, parameterType);
}
@NotNull
private FunctionDescriptor standardFunction(ClassDescriptor classDescriptor, List<TypeProjection> typeArguments, String name, Type... parameterType) {
private FunctionDescriptor standardFunction(ClassDescriptor classDescriptor, List<TypeProjection> typeArguments, String name, JetType... parameterType) {
FunctionGroup functionGroup = classDescriptor.getMemberScope(typeArguments).getFunctionGroup(name);
List<Type> parameterTypeList = Arrays.asList(parameterType);
Collection<FunctionDescriptor> functions = functionGroup.getPossiblyApplicableFunctions(Collections.<Type>emptyList(), parameterTypeList);
List<JetType> parameterTypeList = Arrays.asList(parameterType);
Collection<FunctionDescriptor> functions = functionGroup.getPossiblyApplicableFunctions(Collections.<JetType>emptyList(), parameterTypeList);
for (FunctionDescriptor function : functions) {
List<ValueParameterDescriptor> unsubstitutedValueParameters = function.getUnsubstitutedValueParameters();
for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size(); i < unsubstitutedValueParametersSize; i++) {
@@ -414,17 +414,17 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
}
private void assertCommonSupertype(String expected, String... types) {
Collection<Type> subtypes = new ArrayList<Type>();
Collection<JetType> subtypes = new ArrayList<JetType>();
for (String type : types) {
subtypes.add(makeType(type));
}
Type result = semanticServices.getTypeChecker().commonSupertype(subtypes);
assertTrue(result + " != " + expected, TypeImpl.equalTypes(result, makeType(expected)));
JetType result = semanticServices.getTypeChecker().commonSupertype(subtypes);
assertTrue(result + " != " + expected, JetTypeImpl.equalTypes(result, makeType(expected)));
}
private void assertSubtypingRelation(String type1, String type2, boolean expected) {
Type typeNode1 = makeType(type1);
Type typeNode2 = makeType(type2);
JetType typeNode1 = makeType(type1);
JetType typeNode2 = makeType(type2);
boolean result = semanticServices.getTypeChecker().isSubtypeOf(
typeNode1,
typeNode2);
@@ -432,40 +432,40 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
assertTrue(typeNode1 + " is " + modifier + "a subtype of " + typeNode2, result == expected);
}
private void assertConvertibleTo(String expression, Type type) {
private void assertConvertibleTo(String expression, JetType type) {
JetExpression jetExpression = JetChangeUtil.createExpression(getProject(), expression);
assertTrue(
expression + " must be convertible to " + type,
semanticServices.getTypeChecker().isConvertibleTo(jetExpression, type));
}
private void assertNotConvertibleTo(String expression, Type type) {
private void assertNotConvertibleTo(String expression, JetType type) {
JetExpression jetExpression = JetChangeUtil.createExpression(getProject(), expression);
assertFalse(
expression + " must not be convertible to " + type,
semanticServices.getTypeChecker().isConvertibleTo(jetExpression, type));
}
private void assertType(String expression, Type expectedType) {
private void assertType(String expression, JetType expectedType) {
Project project = getProject();
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
Type type = semanticServices.getTypeInferrer(BindingTrace.DUMMY).getType(classDefinitions.BASIC_SCOPE, jetExpression, false);
assertTrue(type + " != " + expectedType, TypeImpl.equalTypes(type, expectedType));
JetType type = semanticServices.getTypeInferrer(BindingTrace.DUMMY).getType(classDefinitions.BASIC_SCOPE, jetExpression, false);
assertTrue(type + " != " + expectedType, JetTypeImpl.equalTypes(type, expectedType));
}
private void assertErrorType(String expression) {
Project project = getProject();
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
Type type = semanticServices.getTypeInferrer(BindingTrace.DUMMY).getType(classDefinitions.BASIC_SCOPE, jetExpression, false);
JetType type = semanticServices.getTypeInferrer(BindingTrace.DUMMY).getType(classDefinitions.BASIC_SCOPE, jetExpression, false);
assertTrue("Error type expected but " + type + " returned", ErrorType.isErrorType(type));
}
private void assertType(String contextType, String expression, String expectedType) {
final Type thisType = makeType(contextType);
final JetType thisType = makeType(contextType);
JetScope scope = new JetScopeAdapter(classDefinitions.BASIC_SCOPE) {
@NotNull
@Override
public Type getThisType() {
public JetType getThisType() {
return thisType;
}
};
@@ -479,16 +479,16 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
private void assertType(JetScope scope, String expression, String expectedTypeStr) {
Project project = getProject();
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
Type type = semanticServices.getTypeInferrer(BindingTrace.DUMMY).getType(scope, jetExpression, false);
Type expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
JetType type = semanticServices.getTypeInferrer(BindingTrace.DUMMY).getType(scope, jetExpression, false);
JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
assertEquals(expectedType, type);
}
private Type makeType(String typeStr) {
private JetType makeType(String typeStr) {
return makeType(classDefinitions.BASIC_SCOPE, typeStr);
}
private Type makeType(JetScope scope, String typeStr) {
private JetType makeType(JetScope scope, String typeStr) {
return new TypeResolver(BindingTrace.DUMMY, semanticServices).resolveType(scope, JetChangeUtil.createType(getProject(), typeStr));
}