diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContext.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContext.java index 683f687e1e7..11969ba40d7 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContext.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContext.java @@ -223,7 +223,7 @@ public abstract class CodegenContext { CallableMemberDescriptor.Kind.DECLARATION ); JetType receiverType = pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null; - myAccessor.setType(pd.getType(), Collections.emptyList(), pd.getExpectedThisObject(), receiverType); + myAccessor.setType(pd.getType(), Collections.emptyList(), pd.getExpectedThisObject(), receiverType); PropertyGetterDescriptor pgd = new PropertyGetterDescriptor( myAccessor, Collections.emptyList(), myAccessor.getModality(), diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java index caaf653c39b..be95711e65a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java @@ -54,7 +54,7 @@ public class CodegenUtil { invokeDescriptor.initialize(fd.getReceiverParameter().exists() ? fd.getReceiverParameter().getType() : null, fd.getExpectedThisObject(), - Collections.emptyList(), + Collections.emptyList(), fd.getValueParameters(), fd.getReturnType(), Modality.FINAL, diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 3f82f7db800..9890c1183de 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -1093,7 +1093,7 @@ public class ExpressionCodegen extends JetVisitor { } } - if (descriptor instanceof TypeParameterDescriptor) { + if (descriptor instanceof TypeParameterDescriptorImpl) { TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) descriptor; v.invokevirtual("jet/TypeInfo", "getClassObject", "()Ljava/lang/Object;"); v.checkcast(asmType(typeParameterDescriptor.getClassObjectType())); @@ -2614,7 +2614,7 @@ If finally block is present, its last expression is the value of try expression. JetExpression left = expression.getLeft(); JetType leftType = bindingContext.get(BindingContext.EXPRESSION_TYPE, left); DeclarationDescriptor descriptor = rightType.getConstructor().getDeclarationDescriptor(); - if (descriptor instanceof ClassDescriptor || descriptor instanceof TypeParameterDescriptor) { + if (descriptor instanceof ClassDescriptor || descriptor instanceof TypeParameterDescriptorImpl) { StackValue value = genQualified(receiver, left); value.put(JetTypeMapper.boxType(value.type), v); assert leftType != null; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java index d1b3807da64..71bc4f14ec5 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java @@ -463,7 +463,7 @@ public class JetTypeMapper { return asmType; } - if (descriptor instanceof TypeParameterDescriptor) { + if (descriptor instanceof TypeParameterDescriptorImpl) { Type type = mapType(((TypeParameterDescriptor) descriptor).getUpperBoundsAsType(), kind); if (signatureVisitor != null) { @@ -722,7 +722,7 @@ public class JetTypeMapper { signatureVisitor.writeInterfaceBoundEnd(); } } - if (jetType.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) { + if (jetType.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptorImpl) { signatureVisitor.writeInterfaceBound(); mapType(jetType, signatureVisitor, MapTypeMode.TYPE_PARAMETER); signatureVisitor.writeInterfaceBoundEnd(); @@ -966,7 +966,7 @@ public class JetTypeMapper { public boolean isGenericsArray(JetType type) { DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor(); - if(declarationDescriptor instanceof TypeParameterDescriptor) + if(declarationDescriptor instanceof TypeParameterDescriptorImpl) return true; if(standardLibrary.getArray().equals(declarationDescriptor)) diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java index 05ab28ca5d2..506ce076cac 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java @@ -107,14 +107,14 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes @NotNull private final TypeParameterDescriptorOrigin origin; @NotNull - final TypeParameterDescriptor descriptor; + final TypeParameterDescriptorImpl descriptor; final PsiTypeParameter psiTypeParameter; @Nullable private final List upperBoundsForKotlin; @Nullable private final List lowerBoundsForKotlin; - private TypeParameterDescriptorInitialization(@NotNull TypeParameterDescriptor descriptor, @NotNull PsiTypeParameter psiTypeParameter) { + private TypeParameterDescriptorInitialization(@NotNull TypeParameterDescriptorImpl descriptor, @NotNull PsiTypeParameter psiTypeParameter) { this.origin = TypeParameterDescriptorOrigin.JAVA; this.descriptor = descriptor; this.psiTypeParameter = psiTypeParameter; @@ -122,7 +122,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes this.lowerBoundsForKotlin = null; } - private TypeParameterDescriptorInitialization(@NotNull TypeParameterDescriptor descriptor, @NotNull PsiTypeParameter psiTypeParameter, + private TypeParameterDescriptorInitialization(@NotNull TypeParameterDescriptorImpl descriptor, @NotNull PsiTypeParameter psiTypeParameter, List upperBoundsForKotlin, List lowerBoundsForKotlin) { this.origin = TypeParameterDescriptorOrigin.KOTLIN; this.descriptor = descriptor; @@ -608,10 +608,10 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes @NotNull private final TypeVariableResolver typeVariableResolver; @NotNull - private final TypeParameterDescriptor typeParameterDescriptor; + private final TypeParameterDescriptorImpl typeParameterDescriptor; protected JetSignatureTypeParameterVisitor(PsiTypeParameterListOwner psiOwner, - String name, TypeVariableResolver typeVariableResolver, TypeParameterDescriptor typeParameterDescriptor) + String name, TypeVariableResolver typeVariableResolver, TypeParameterDescriptorImpl typeParameterDescriptor) { if (name.isEmpty()) { throw new IllegalStateException(); @@ -687,7 +687,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes @Override public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance, boolean reified) { - TypeParameterDescriptor typeParameter = TypeParameterDescriptor.createForFurtherModification( + TypeParameterDescriptorImpl typeParameter = TypeParameterDescriptorImpl.createForFurtherModification( containingDeclaration, Collections.emptyList(), // TODO: wrong reified, @@ -762,7 +762,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes @NotNull private TypeParameterDescriptorInitialization makeUninitializedTypeParameter(@NotNull DeclarationDescriptor containingDeclaration, @NotNull PsiTypeParameter psiTypeParameter) { - TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification( + TypeParameterDescriptorImpl typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification( containingDeclaration, Collections.emptyList(), // TODO false, @@ -774,7 +774,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes } private void initializeTypeParameter(TypeParameterDescriptorInitialization typeParameter, TypeVariableResolver typeVariableByPsiResolver) { - TypeParameterDescriptor typeParameterDescriptor = typeParameter.descriptor; + TypeParameterDescriptorImpl typeParameterDescriptor = typeParameter.descriptor; if (typeParameter.origin == TypeParameterDescriptorOrigin.KOTLIN) { List upperBounds = typeParameter.upperBoundsForKotlin; if (upperBounds.size() == 0){ diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/TypeVariableResolverFromTypeDescriptors.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/TypeVariableResolverFromTypeDescriptors.java index ed1f6235fff..aedd1e8bef1 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/TypeVariableResolverFromTypeDescriptors.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/TypeVariableResolverFromTypeDescriptors.java @@ -17,7 +17,6 @@ package org.jetbrains.jet.lang.resolve.java; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.ClassOrNamespaceDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/TypeVariableResolvers.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/TypeVariableResolvers.java index 3a63089762c..858625e4c93 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/TypeVariableResolvers.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/TypeVariableResolvers.java @@ -17,12 +17,7 @@ package org.jetbrains.jet.lang.resolve.java; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.descriptors.ClassDescriptor; -import org.jetbrains.jet.lang.descriptors.ClassOrNamespaceDescriptor; -import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; -import org.jetbrains.jet.lang.descriptors.ModuleDescriptor; -import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; -import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; +import org.jetbrains.jet.lang.descriptors.*; import java.util.ArrayList; import java.util.List; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java index b3a0d6974ee..0dde08e8498 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java @@ -48,7 +48,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl } public final ClassDescriptorImpl initialize(boolean sealed, - @NotNull List typeParameters, + @NotNull List typeParameters, @NotNull Collection supertypes, @NotNull JetScope memberDeclarations, @NotNull Set constructors, @@ -57,7 +57,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl } public final ClassDescriptorImpl initialize(boolean sealed, - @NotNull List typeParameters, + @NotNull List typeParameters, @NotNull Collection supertypes, @NotNull JetScope memberDeclarations, @NotNull Set constructors, diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java index 69216fca3f0..fcc486e9d3e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java @@ -77,12 +77,12 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i protected FunctionDescriptorImpl initialize( @Nullable JetType receiverType, @NotNull ReceiverDescriptor expectedThisObject, - @NotNull List typeParameters, + @NotNull List typeParameters, @NotNull List unsubstitutedValueParameters, @Nullable JetType unsubstitutedReturnType, @Nullable Modality modality, @NotNull Visibility visibility) { - this.typeParameters = typeParameters; + this.typeParameters = Lists.newArrayList(typeParameters); this.unsubstitutedValueParameters = unsubstitutedValueParameters; this.unsubstitutedReturnType = unsubstitutedReturnType; this.modality = modality; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java index e9e543a1fe5..8044d6b2dde 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java @@ -126,7 +126,7 @@ public class FunctionDescriptorUtil { assert JetStandardClasses.isFunctionType(functionType); functionDescriptor.initialize(JetStandardClasses.getReceiverType(functionType), expectedThisObject, - Collections.emptyList(), + Collections.emptyList(), JetStandardClasses.getValueParameters(functionDescriptor, functionType), JetStandardClasses.getReturnTypeFromFunctionType(functionType), modality, diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java index 4a535c807c0..88058260e6e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java @@ -112,17 +112,17 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab setType(outType, Collections.emptyList(), expectedThisObject, receiverType); } - public void setType(@NotNull JetType outType, @NotNull List typeParameters, @NotNull ReceiverDescriptor expectedThisObject, @Nullable JetType receiverType) { + public void setType(@NotNull JetType outType, @NotNull List typeParameters, @NotNull ReceiverDescriptor expectedThisObject, @Nullable JetType receiverType) { ReceiverDescriptor receiver = receiverType == null ? NO_RECEIVER : new ExtensionReceiver(this, receiverType); setType(outType, typeParameters, expectedThisObject, receiver); } - public void setType(@NotNull JetType outType, @NotNull List typeParameters, @NotNull ReceiverDescriptor expectedThisObject, @NotNull ReceiverDescriptor receiver) { + public void setType(@NotNull JetType outType, @NotNull List typeParameters, @NotNull ReceiverDescriptor expectedThisObject, @NotNull ReceiverDescriptor receiver) { setOutType(outType); - this.typeParameters = typeParameters; + this.typeParameters = Lists.newArrayList(typeParameters); this.receiver = receiver; this.expectedThisObject = expectedThisObject; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/SimpleFunctionDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/SimpleFunctionDescriptorImpl.java index 57d84e60de1..7c2cda46d0c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/SimpleFunctionDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/SimpleFunctionDescriptorImpl.java @@ -54,7 +54,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme public SimpleFunctionDescriptorImpl initialize( @Nullable JetType receiverType, @NotNull ReceiverDescriptor expectedThisObject, - @NotNull List typeParameters, + @NotNull List typeParameters, @NotNull List unsubstitutedValueParameters, @Nullable JetType unsubstitutedReturnType, @Nullable Modality modality, diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java index 66b588e80a7..07afc2a3866 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java @@ -16,251 +16,45 @@ package org.jetbrains.jet.lang.descriptors; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; -import org.jetbrains.jet.lang.resolve.name.Name; -import org.jetbrains.jet.lang.resolve.scopes.JetScope; -import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter; -import org.jetbrains.jet.lang.types.*; -import org.jetbrains.jet.lang.types.checker.JetTypeChecker; -import org.jetbrains.jet.lang.types.lang.JetStandardClasses; -import org.jetbrains.jet.resolve.DescriptorRenderer; -import org.jetbrains.jet.util.lazy.LazyValue; +import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.lang.types.TypeConstructor; +import org.jetbrains.jet.lang.types.TypeSubstitutor; +import org.jetbrains.jet.lang.types.Variance; -import java.util.Collections; -import java.util.List; import java.util.Set; /** * @author abreslav */ -public class TypeParameterDescriptor extends DeclarationDescriptorImpl implements ClassifierDescriptor { - public static TypeParameterDescriptor createWithDefaultBound( - @NotNull DeclarationDescriptor containingDeclaration, - @NotNull List annotations, - boolean reified, - @NotNull Variance variance, - @NotNull Name name, - int index) { - TypeParameterDescriptor typeParameterDescriptor = createForFurtherModification(containingDeclaration, annotations, reified, variance, name, index); - typeParameterDescriptor.addUpperBound(JetStandardClasses.getDefaultBound()); - typeParameterDescriptor.setInitialized(); - return typeParameterDescriptor; - } +public interface TypeParameterDescriptor extends ClassifierDescriptor { + boolean isReified(); - public static TypeParameterDescriptor createForFurtherModification( - @NotNull DeclarationDescriptor containingDeclaration, - @NotNull List annotations, - boolean reified, - @NotNull Variance variance, - @NotNull Name name, - int index) { - return new TypeParameterDescriptor(containingDeclaration, annotations, reified, variance, name, index); - } - - // 0-based - private final int index; - private final Variance variance; - private final Set upperBounds; - private JetType upperBoundsAsType; - private final TypeConstructor typeConstructor; - private JetType defaultType; - private final Set classObjectUpperBounds = Sets.newLinkedHashSet(); - private JetType classObjectBoundsAsType; - - private final boolean reified; - - private boolean initialized = false; - - private TypeParameterDescriptor( - @NotNull DeclarationDescriptor containingDeclaration, - @NotNull List annotations, - boolean reified, - @NotNull Variance variance, - @NotNull Name name, - int index) { - super(containingDeclaration, annotations, name); - this.index = index; - this.variance = variance; - this.upperBounds = Sets.newLinkedHashSet(); - this.reified = reified; - // TODO: Should we actually pass the annotations on to the type constructor? - this.typeConstructor = new TypeConstructorImpl( - this, - annotations, - false, - name.getName(), - Collections.emptyList(), - upperBounds); - } - - private void checkInitialized() { - if (!initialized) { - throw new IllegalStateException("Type parameter descriptor in not initialized: " + nameForAssertions()); - } - } - - private void checkUninitialized() { - if (initialized) { - throw new IllegalStateException("Type parameter descriptor is already initialized: " + nameForAssertions()); - } - } - - private String nameForAssertions() { - DeclarationDescriptor owner = getContainingDeclaration(); - return getName() + " declared in " + (owner == null ? "" : owner.getName()); - } - - public void setInitialized() { - checkUninitialized(); - initialized = true; - } - - public boolean isReified() { - checkInitialized(); - return reified; - } - - public Variance getVariance() { - checkInitialized(); - return variance; - } - - public void addUpperBound(@NotNull JetType bound) { - checkUninitialized(); - doAddUpperBound(bound); - } - - private void doAddUpperBound(JetType bound) { - upperBounds.add(bound); // TODO : Duplicates? - } - - public void addDefaultUpperBound() { - checkUninitialized(); - - if (upperBounds.isEmpty()) { - doAddUpperBound(JetStandardClasses.getDefaultBound()); - } - } + Variance getVariance(); @NotNull - public Set getUpperBounds() { - checkInitialized(); - return upperBounds; - } + Set getUpperBounds(); @NotNull - public JetType getUpperBoundsAsType() { - checkInitialized(); - if (upperBoundsAsType == null) { - assert upperBounds != null : "Upper bound list is null in " + getName(); - assert upperBounds.size() > 0 : "Upper bound list is empty in " + getName(); - upperBoundsAsType = TypeUtils.intersect(JetTypeChecker.INSTANCE, upperBounds); - if (upperBoundsAsType == null) { - upperBoundsAsType = JetStandardClasses.getNothingType(); - } - } - return upperBoundsAsType; - } + JetType getUpperBoundsAsType(); @NotNull - public Set getLowerBounds() { - //checkInitialized(); - return Collections.singleton(JetStandardClasses.getNothingType()); - } + Set getLowerBounds(); @NotNull - public JetType getLowerBoundsAsType() { - checkInitialized(); - return JetStandardClasses.getNothingType(); - } - - + JetType getLowerBoundsAsType(); + @NotNull @Override - public TypeConstructor getTypeConstructor() { - //checkInitialized(); - return typeConstructor; - } - - @Override - public String toString() { - try { - return DescriptorRenderer.TEXT.render(this); - } catch (Exception e) { - return this.getClass().getName() + "@" + System.identityHashCode(this); - } - } + TypeConstructor getTypeConstructor(); @NotNull @Override @Deprecated // Use the static method TypeParameterDescriptor.substitute() - public TypeParameterDescriptor substitute(TypeSubstitutor substitutor) { - throw new UnsupportedOperationException(); - } + TypeParameterDescriptor substitute(TypeSubstitutor substitutor); - @Override - public R accept(DeclarationDescriptorVisitor visitor, D data) { - checkInitialized(); - return visitor.visitTypeParameterDescriptor(this, data); - } + int getIndex(); @NotNull - @Override - public JetType getDefaultType() { - //checkInitialized(); - if (defaultType == null) { - defaultType = new JetTypeImpl( - Collections.emptyList(), - getTypeConstructor(), - TypeUtils.hasNullableLowerBound(this), - Collections.emptyList(), - new LazyScopeAdapter(new LazyValue() { - @Override - protected JetScope compute() { - return getUpperBoundsAsType().getMemberScope(); - } - })); - } - return defaultType; - } - - @Override - public JetType getClassObjectType() { - checkInitialized(); - if (classObjectUpperBounds.isEmpty()) return null; - - if (classObjectBoundsAsType == null) { - classObjectBoundsAsType = TypeUtils.intersect(JetTypeChecker.INSTANCE, classObjectUpperBounds); - if (classObjectBoundsAsType == null) { - classObjectBoundsAsType = JetStandardClasses.getNothingType(); - } - } - return classObjectBoundsAsType; - } - - @Override - public boolean isClassObjectAValue() { - return true; - } - - public void addClassObjectBound(@NotNull JetType bound) { - checkUninitialized(); - classObjectUpperBounds.add(bound); // TODO : Duplicates? - } - - public int getIndex() { - checkInitialized(); - return index; - } - - @NotNull - public TypeParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) { - TypeParameterDescriptor copy = new TypeParameterDescriptor(newOwner, Lists.newArrayList(getAnnotations()), reified, variance, getName(), index); - copy.upperBounds.addAll(this.upperBounds); - copy.initialized = this.initialized; - return copy; - } + TypeParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptorImpl.java new file mode 100644 index 00000000000..1ccd4ff68ee --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptorImpl.java @@ -0,0 +1,275 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.descriptors; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.resolve.name.Name; +import org.jetbrains.jet.lang.resolve.scopes.JetScope; +import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter; +import org.jetbrains.jet.lang.types.*; +import org.jetbrains.jet.lang.types.checker.JetTypeChecker; +import org.jetbrains.jet.lang.types.lang.JetStandardClasses; +import org.jetbrains.jet.resolve.DescriptorRenderer; +import org.jetbrains.jet.util.lazy.LazyValue; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +/** + * @author abreslav + */ +public class TypeParameterDescriptorImpl extends DeclarationDescriptorImpl implements TypeParameterDescriptor { + public static TypeParameterDescriptor createWithDefaultBound( + @NotNull DeclarationDescriptor containingDeclaration, + @NotNull List annotations, + boolean reified, + @NotNull Variance variance, + @NotNull Name name, + int index) { + TypeParameterDescriptorImpl typeParameterDescriptor = createForFurtherModification(containingDeclaration, annotations, reified, variance, name, index); + typeParameterDescriptor.addUpperBound(JetStandardClasses.getDefaultBound()); + typeParameterDescriptor.setInitialized(); + return typeParameterDescriptor; + } + + public static TypeParameterDescriptorImpl createForFurtherModification( + @NotNull DeclarationDescriptor containingDeclaration, + @NotNull List annotations, + boolean reified, + @NotNull Variance variance, + @NotNull Name name, + int index) { + return new TypeParameterDescriptorImpl(containingDeclaration, annotations, reified, variance, name, index); + } + + // 0-based + private final int index; + private final Variance variance; + private final Set upperBounds; + private JetType upperBoundsAsType; + private final TypeConstructor typeConstructor; + private JetType defaultType; + private final Set classObjectUpperBounds = Sets.newLinkedHashSet(); + private JetType classObjectBoundsAsType; + + private final boolean reified; + + private boolean initialized = false; + + private TypeParameterDescriptorImpl( + @NotNull DeclarationDescriptor containingDeclaration, + @NotNull List annotations, + boolean reified, + @NotNull Variance variance, + @NotNull Name name, + int index) { + super(containingDeclaration, annotations, name); + this.index = index; + this.variance = variance; + this.upperBounds = Sets.newLinkedHashSet(); + this.reified = reified; + // TODO: Should we actually pass the annotations on to the type constructor? + this.typeConstructor = new TypeConstructorImpl( + this, + annotations, + false, + name.getName(), + Collections.emptyList(), + upperBounds); + } + + private void checkInitialized() { + if (!initialized) { + throw new IllegalStateException("Type parameter descriptor in not initialized: " + nameForAssertions()); + } + } + + private void checkUninitialized() { + if (initialized) { + throw new IllegalStateException("Type parameter descriptor is already initialized: " + nameForAssertions()); + } + } + + private String nameForAssertions() { + DeclarationDescriptor owner = getContainingDeclaration(); + return getName() + " declared in " + (owner == null ? "" : owner.getName()); + } + + public void setInitialized() { + checkUninitialized(); + initialized = true; + } + + @Override + public boolean isReified() { + checkInitialized(); + return reified; + } + + @Override + public Variance getVariance() { + checkInitialized(); + return variance; + } + + public void addUpperBound(@NotNull JetType bound) { + checkUninitialized(); + doAddUpperBound(bound); + } + + private void doAddUpperBound(JetType bound) { + upperBounds.add(bound); // TODO : Duplicates? + } + + public void addDefaultUpperBound() { + checkUninitialized(); + + if (upperBounds.isEmpty()) { + doAddUpperBound(JetStandardClasses.getDefaultBound()); + } + } + + @Override + @NotNull + public Set getUpperBounds() { + checkInitialized(); + return upperBounds; + } + + @Override + @NotNull + public JetType getUpperBoundsAsType() { + checkInitialized(); + if (upperBoundsAsType == null) { + assert upperBounds != null : "Upper bound list is null in " + getName(); + assert upperBounds.size() > 0 : "Upper bound list is empty in " + getName(); + upperBoundsAsType = TypeUtils.intersect(JetTypeChecker.INSTANCE, upperBounds); + if (upperBoundsAsType == null) { + upperBoundsAsType = JetStandardClasses.getNothingType(); + } + } + return upperBoundsAsType; + } + + @Override + @NotNull + public Set getLowerBounds() { + //checkInitialized(); + return Collections.singleton(JetStandardClasses.getNothingType()); + } + + @Override + @NotNull + public JetType getLowerBoundsAsType() { + checkInitialized(); + return JetStandardClasses.getNothingType(); + } + + + @NotNull + @Override + public TypeConstructor getTypeConstructor() { + //checkInitialized(); + return typeConstructor; + } + + @Override + public String toString() { + try { + return DescriptorRenderer.TEXT.render(this); + } catch (Exception e) { + return this.getClass().getName() + "@" + System.identityHashCode(this); + } + } + + @NotNull + @Override + @Deprecated // Use the static method TypeParameterDescriptor.substitute() + public TypeParameterDescriptor substitute(TypeSubstitutor substitutor) { + throw new UnsupportedOperationException(); + } + + @Override + public R accept(DeclarationDescriptorVisitor visitor, D data) { + checkInitialized(); + return visitor.visitTypeParameterDescriptor(this, data); + } + + @NotNull + @Override + public JetType getDefaultType() { + //checkInitialized(); + if (defaultType == null) { + defaultType = new JetTypeImpl( + Collections.emptyList(), + getTypeConstructor(), + TypeUtils.hasNullableLowerBound(this), + Collections.emptyList(), + new LazyScopeAdapter(new LazyValue() { + @Override + protected JetScope compute() { + return getUpperBoundsAsType().getMemberScope(); + } + })); + } + return defaultType; + } + + @Override + public JetType getClassObjectType() { + checkInitialized(); + if (classObjectUpperBounds.isEmpty()) return null; + + if (classObjectBoundsAsType == null) { + classObjectBoundsAsType = TypeUtils.intersect(JetTypeChecker.INSTANCE, classObjectUpperBounds); + if (classObjectBoundsAsType == null) { + classObjectBoundsAsType = JetStandardClasses.getNothingType(); + } + } + return classObjectBoundsAsType; + } + + @Override + public boolean isClassObjectAValue() { + return true; + } + + public void addClassObjectBound(@NotNull JetType bound) { + checkUninitialized(); + classObjectUpperBounds.add(bound); // TODO : Duplicates? + } + + @Override + public int getIndex() { + checkInitialized(); + return index; + } + + @Override + @NotNull + public TypeParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) { + TypeParameterDescriptorImpl + copy = new TypeParameterDescriptorImpl(newOwner, Lists.newArrayList(getAnnotations()), reified, variance, getName(), index); + copy.upperBounds.addAll(this.upperBounds); + copy.initialized = this.initialized; + return copy; + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java index 73d69e2a067..0c4ed63ac33 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java @@ -79,7 +79,7 @@ public class DescriptorResolver { List typeParameters = Lists.newArrayList(); int index = 0; for (JetTypeParameter typeParameter : classElement.getTypeParameters()) { - TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification( + TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification( descriptor, annotationResolver.createAnnotationStubs(typeParameter.getModifierList(), trace), !typeParameter.hasModifier(JetTokens.ERASED_KEYWORD), @@ -175,7 +175,7 @@ public class DescriptorResolver { WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Function descriptor header scope"); innerScope.addLabeledDeclaration(functionDescriptor); - List typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters(), trace); + List typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters(), trace); innerScope.changeLockLevel(WritableScope.LockLevel.BOTH); resolveGenericBounds(function, innerScope, typeParameterDescriptors, trace); @@ -307,8 +307,8 @@ public class DescriptorResolver { } } - public List resolveTypeParameters(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, List typeParameters, BindingTrace trace) { - List result = new ArrayList(); + public List resolveTypeParameters(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, List typeParameters, BindingTrace trace) { + List result = new ArrayList(); for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) { JetTypeParameter typeParameter = typeParameters.get(i); result.add(resolveTypeParameter(containingDescriptor, extensibleScope, typeParameter, i, trace)); @@ -316,12 +316,12 @@ public class DescriptorResolver { return result; } - private TypeParameterDescriptor resolveTypeParameter(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, JetTypeParameter typeParameter, int index, BindingTrace trace) { + private TypeParameterDescriptorImpl resolveTypeParameter(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, JetTypeParameter typeParameter, int index, BindingTrace trace) { // JetTypeReference extendsBound = typeParameter.getExtendsBound(); // JetType bound = extendsBound == null // ? JetStandardClasses.getDefaultBound() // : typeResolver.resolveType(extensibleScope, extendsBound); - TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification( + TypeParameterDescriptorImpl typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification( containingDescriptor, annotationResolver.createAnnotationStubs(typeParameter.getModifierList(), trace), !typeParameter.hasModifier(JetTokens.ERASED_KEYWORD), @@ -346,14 +346,15 @@ public class DescriptorResolver { isClassObjectConstraint = classObjectConstraint; } } - public void resolveGenericBounds(@NotNull JetTypeParameterListOwner declaration, JetScope scope, List parameters, BindingTrace trace) { + + public void resolveGenericBounds(@NotNull JetTypeParameterListOwner declaration, JetScope scope, List parameters, BindingTrace trace) { List deferredUpperBoundCheckerTasks = Lists.newArrayList(); List typeParameters = declaration.getTypeParameters(); - Map parameterByName = Maps.newHashMap(); + Map parameterByName = Maps.newHashMap(); for (int i = 0; i < typeParameters.size(); i++) { JetTypeParameter jetTypeParameter = typeParameters.get(i); - TypeParameterDescriptor typeParameterDescriptor = parameters.get(i); + TypeParameterDescriptorImpl typeParameterDescriptor = parameters.get(i); parameterByName.put(typeParameterDescriptor.getName(), typeParameterDescriptor); @@ -373,7 +374,7 @@ public class DescriptorResolver { if (referencedName == null) { continue; } - TypeParameterDescriptor typeParameterDescriptor = parameterByName.get(referencedName); + TypeParameterDescriptorImpl typeParameterDescriptor = parameterByName.get(referencedName); JetTypeReference boundTypeReference = constraint.getBoundTypeReference(); JetType bound = null; if (boundTypeReference != null) { @@ -405,7 +406,7 @@ public class DescriptorResolver { } } - for (TypeParameterDescriptor parameter : parameters) { + for (TypeParameterDescriptorImpl parameter : parameters) { parameter.addDefaultUpperBound(); parameter.setInitialized(); @@ -551,7 +552,7 @@ public class DescriptorResolver { return variableDescriptor; } - public JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope, @NotNull List typeParameters, + public JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope, @NotNull List typeParameters, @NotNull ReceiverDescriptor receiver, BindingTrace trace) { WritableScopeImpl result = new WritableScopeImpl(outerScope, outerScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(trace)).setDebugName("Property declaration inner scope"); for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) { @@ -583,7 +584,7 @@ public class DescriptorResolver { CallableMemberDescriptor.Kind.DECLARATION ); - List typeParameterDescriptors; + List typeParameterDescriptors; JetScope scopeWithTypeParameters; JetType receiverType = null; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java index 40ba883128e..ce8f0bbea4a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java @@ -275,7 +275,7 @@ public class DescriptorUtils { ClassDescriptor clazz = (ClassDescriptor) classifier; return clazz.getKind() == ClassKind.OBJECT || clazz.getKind() == ClassKind.ENUM_ENTRY; } - else if (classifier instanceof TypeParameterDescriptor) { + else if (classifier instanceof TypeParameterDescriptorImpl) { return false; } else { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java index 8c7fe2bbe18..2ecf21fd46e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java @@ -212,7 +212,7 @@ public class OverridingUtil { if (type.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor) { return type; } - else if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) { + else if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptorImpl) { return ((TypeParameterDescriptor) type.getConstructor().getDeclarationDescriptor()).getUpperBoundsAsType(); } else { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java index b5d65c3bcef..b0e53273c38 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java @@ -395,7 +395,7 @@ public class TypeHierarchyResolver { JetClass jetClass = entry.getKey(); MutableClassDescriptor descriptor = entry.getValue(); descriptorResolver.resolveGenericBounds(jetClass, descriptor.getScopeForSupertypeResolution(), - descriptor.getTypeConstructor().getParameters(), trace); + (List) descriptor.getTypeConstructor().getParameters(), trace); descriptorResolver.resolveSupertypes(jetClass, descriptor, trace); } for (Map.Entry entry : context.getObjects().entrySet()) { @@ -528,7 +528,7 @@ public class TypeHierarchyResolver { if (projections.size() > 1) { TypeConstructor typeConstructor = entry.getKey(); DeclarationDescriptor declarationDescriptor = typeConstructor.getDeclarationDescriptor(); - assert declarationDescriptor instanceof TypeParameterDescriptor : declarationDescriptor; + assert declarationDescriptor instanceof TypeParameterDescriptorImpl : declarationDescriptor; TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) declarationDescriptor; // Immediate arguments of supertypes cannot be projected diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java index ab54ab52fe4..a189b882c66 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java @@ -95,7 +95,7 @@ public class TypeResolver { return; } - if (classifierDescriptor instanceof TypeParameterDescriptor) { + if (classifierDescriptor instanceof TypeParameterDescriptorImpl) { TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) classifierDescriptor; trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, typeParameterDescriptor); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemWithPriorities.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemWithPriorities.java index 022b909c68f..65a2ee84422 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemWithPriorities.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemWithPriorities.java @@ -21,6 +21,7 @@ import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; +import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptorImpl; import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.checker.TypeCheckingProcedure; @@ -88,7 +89,7 @@ public class ConstraintSystemWithPriorities implements ConstraintSystem { @NotNull private TypeValue getTypeValueFor(@NotNull JetType type) { DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor(); - if (declarationDescriptor instanceof TypeParameterDescriptor) { + if (declarationDescriptor instanceof TypeParameterDescriptorImpl) { TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) declarationDescriptor; // Checking that this is not a T?, but exactly T if (typeParameterDescriptor.getDefaultType().isNullable() == type.isNullable()) { @@ -488,7 +489,7 @@ public class ConstraintSystemWithPriorities implements ConstraintSystem { @Override public TypeProjection get(TypeConstructor key) { DeclarationDescriptor declarationDescriptor = key.getDeclarationDescriptor(); - if (declarationDescriptor instanceof TypeParameterDescriptor) { + if (declarationDescriptor instanceof TypeParameterDescriptorImpl) { TypeParameterDescriptor descriptor = (TypeParameterDescriptor) declarationDescriptor; if (!unknownTypes.containsKey(descriptor)) return null; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/DescriptorSubstitutor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/DescriptorSubstitutor.java index eada1237fb8..132f75ede6e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/DescriptorSubstitutor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/DescriptorSubstitutor.java @@ -20,6 +20,7 @@ import com.google.common.collect.Maps; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; +import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptorImpl; import java.util.List; import java.util.Map; @@ -58,7 +59,7 @@ public class DescriptorSubstitutor { }); for (TypeParameterDescriptor descriptor : typeParameters) { - TypeParameterDescriptor substituted = TypeParameterDescriptor.createForFurtherModification( + TypeParameterDescriptorImpl substituted = TypeParameterDescriptorImpl.createForFurtherModification( newContainingDeclaration, descriptor.getAnnotations(), descriptor.isReified(), diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java index e3fcb857a03..5f24e97621f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java @@ -170,7 +170,7 @@ public class ErrorUtils { function.initialize( null, ReceiverDescriptor.NO_RECEIVER, - Collections.emptyList(), // TODO + Collections.emptyList(), // TODO Collections.emptyList(), // TODO createErrorType(""), Modality.OPEN, @@ -223,7 +223,7 @@ public class ErrorUtils { } private static JetType createErrorTypeWithCustomDebugName(JetScope memberScope, String debugName) { - return new ErrorTypeImpl(new TypeConstructorImpl(ERROR_CLASS, Collections.emptyList(), false, debugName, Collections.emptyList(), Collections.singleton(JetStandardClasses.getAnyType())), memberScope); + return new ErrorTypeImpl(new TypeConstructorImpl(ERROR_CLASS, Collections.emptyList(), false, debugName, Collections.emptyList(), Collections.singleton(JetStandardClasses.getAnyType())), memberScope); } public static JetType createWrongVarianceErrorType(TypeProjection value) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java index 6fe27a072e6..2c62f5d51fe 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java @@ -21,6 +21,7 @@ import com.google.common.collect.Multimap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; +import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptorImpl; import org.jetbrains.jet.lang.types.lang.JetStandardClasses; import org.jetbrains.jet.util.CommonSuppliers; @@ -111,7 +112,7 @@ public class SubstitutionUtils { } public static boolean hasUnsubstitutedTypeParameters(JetType type) { - if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) { + if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptorImpl) { return true; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeConstructorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeConstructorImpl.java index 1d1eceb5ef8..16216bc779c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeConstructorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeConstructorImpl.java @@ -45,7 +45,7 @@ public class TypeConstructorImpl extends AnnotatedImpl implements TypeConstructo @NotNull List annotations, boolean sealed, @NotNull String debugName, - @NotNull List parameters, + @NotNull List parameters, @NotNull Collection supertypes) { super(annotations); this.classifierDescriptor = classifierDescriptor; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java index e3ae251dbef..7bf184d015f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java @@ -22,10 +22,7 @@ import com.google.common.collect.Sets; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.descriptors.ClassDescriptor; -import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor; -import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; -import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; +import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintResolutionListener; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemSolution; @@ -222,7 +219,7 @@ public class TypeUtils { private static void processAllTypeParameters(JetType type, Variance howThiTypeIsUsed, Processor result) { ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); - if (descriptor instanceof TypeParameterDescriptor) { + if (descriptor instanceof TypeParameterDescriptorImpl) { result.process(new TypeParameterUsage((TypeParameterDescriptor)descriptor, howThiTypeIsUsed)); } for (TypeProjection projection : type.getArguments()) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java index 8a4ea7ea3c0..6f2c5e6f2a3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java @@ -149,7 +149,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor { } functionDescriptor.initialize(effectiveReceiverType, NO_RECEIVER, - Collections.emptyList(), + Collections.emptyList(), valueParameterDescriptors, /*unsubstitutedReturnType = */ null, Modality.FINAL, diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java index dbec3286f6f..ee62cc2f842 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java @@ -157,13 +157,13 @@ public class JetStandardClasses { Name.identifier("Tuple" + i)); WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, RedeclarationHandler.THROW_EXCEPTION); for (int j = 0; j < i; j++) { - TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createWithDefaultBound( + TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptorImpl.createWithDefaultBound( classDescriptor, Collections.emptyList(), true, Variance.OUT_VARIANCE, Name.identifier("T" + (j + 1)), j); parameters.add(typeParameterDescriptor); PropertyDescriptor propertyDescriptor = new PropertyDescriptor(classDescriptor, Collections.emptyList(), Modality.FINAL, Visibilities.PUBLIC, false, false, Name.identifier("_" + (j + 1)), CallableMemberDescriptor.Kind.DECLARATION); - propertyDescriptor.setType(typeParameterDescriptor.getDefaultType(), Collections.emptyList(), classDescriptor.getImplicitReceiver(), ReceiverDescriptor.NO_RECEIVER); + propertyDescriptor.setType(typeParameterDescriptor.getDefaultType(), Collections.emptyList(), classDescriptor.getImplicitReceiver(), ReceiverDescriptor.NO_RECEIVER); PropertyGetterDescriptor getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, Collections.emptyList(), Modality.FINAL, Visibilities.PUBLIC, false, true, CallableMemberDescriptor.Kind.DECLARATION); getterDescriptor.initialize(typeParameterDescriptor.getDefaultType()); propertyDescriptor.initialize(getterDescriptor, null); @@ -215,7 +215,7 @@ public class JetStandardClasses { SimpleFunctionDescriptorImpl invokeWithReceiver = new SimpleFunctionDescriptorImpl(receiverFunction, Collections.emptyList(), Name.identifier("invoke"), CallableMemberDescriptor.Kind.DECLARATION); WritableScope scopeForInvokeWithReceiver = createScopeForInvokeFunction(receiverFunction, invokeWithReceiver); List parameters = createTypeParameters(i, receiverFunction); - parameters.add(0, TypeParameterDescriptor.createWithDefaultBound( + parameters.add(0, TypeParameterDescriptorImpl.createWithDefaultBound( receiverFunction, Collections.emptyList(), true, Variance.IN_VARIANCE, Name.identifier("T"), 0)); @@ -238,12 +238,12 @@ public class JetStandardClasses { private static List createTypeParameters(int parameterCount, ClassDescriptorImpl function) { List parameters = new ArrayList(); for (int j = 1; j <= parameterCount; j++) { - parameters.add(TypeParameterDescriptor.createWithDefaultBound( + parameters.add(TypeParameterDescriptorImpl.createWithDefaultBound( function, Collections.emptyList(), true, Variance.IN_VARIANCE, Name.identifier("P" + j), j)); } - parameters.add(TypeParameterDescriptor.createWithDefaultBound( + parameters.add(TypeParameterDescriptorImpl.createWithDefaultBound( function, Collections.emptyList(), true, Variance.OUT_VARIANCE, Name.identifier("R"), parameterCount + 1)); diff --git a/compiler/frontend/src/org/jetbrains/jet/resolve/DescriptorRenderer.java b/compiler/frontend/src/org/jetbrains/jet/resolve/DescriptorRenderer.java index ec2517a0856..d38cba2cb79 100644 --- a/compiler/frontend/src/org/jetbrains/jet/resolve/DescriptorRenderer.java +++ b/compiler/frontend/src/org/jetbrains/jet/resolve/DescriptorRenderer.java @@ -146,7 +146,7 @@ public class DescriptorRenderer implements Renderer { Object typeNameObject; - if (cd == null || cd instanceof TypeParameterDescriptor) { + if (cd == null || cd instanceof TypeParameterDescriptorImpl) { typeNameObject = type.getConstructor(); } else { diff --git a/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java b/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java index 671abc34e72..e27e075ff51 100644 --- a/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java +++ b/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java @@ -698,7 +698,7 @@ public class JetTypeCheckerTest extends JetLiteFixture { parameterScope.changeLockLevel(WritableScope.LockLevel.BOTH); // This call has side-effects on the parameterScope (fills it in) - List typeParameters + List typeParameters = descriptorResolver.resolveTypeParameters(classDescriptor, parameterScope, classElement.getTypeParameters(), JetTestUtils.DUMMY_TRACE); descriptorResolver.resolveGenericBounds(classElement, parameterScope, typeParameters, JetTestUtils.DUMMY_TRACE); diff --git a/idea/src/org/jetbrains/jet/plugin/JetDescriptorIconProvider.java b/idea/src/org/jetbrains/jet/plugin/JetDescriptorIconProvider.java index 862eea63b29..e2a8270280f 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetDescriptorIconProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/JetDescriptorIconProvider.java @@ -110,7 +110,7 @@ public final class JetDescriptorIconProvider { return ((PropertyDescriptor)descriptor).isVar() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL; } - if (descriptor instanceof TypeParameterDescriptor) { + if (descriptor instanceof TypeParameterDescriptorImpl) { return PlatformIcons.CLASS_ICON; } diff --git a/idea/src/org/jetbrains/jet/plugin/completion/JetCompletionContributor.java b/idea/src/org/jetbrains/jet/plugin/completion/JetCompletionContributor.java index 0298a6a83b9..a4321a5cb06 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/JetCompletionContributor.java +++ b/idea/src/org/jetbrains/jet/plugin/completion/JetCompletionContributor.java @@ -183,7 +183,7 @@ public class JetCompletionContributor extends CompletionContributor { DeclarationDescriptor descriptor = ((JetLookupObject)object).getDescriptor(); return (descriptor instanceof ClassDescriptor) || (descriptor instanceof NamespaceDescriptor) || - (descriptor instanceof TypeParameterDescriptor); + (descriptor instanceof TypeParameterDescriptorImpl); } }