Extract interface: TypeParameterDescriptor
A lot of code relied on these descriptors being mutable. In most cases I managed to work around this, but there're still are casts to raw List necessary in one or two places
This commit is contained in:
@@ -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.<TypeParameterDescriptor>emptyList(), pd.getExpectedThisObject(), receiverType);
|
||||
myAccessor.setType(pd.getType(), Collections.<TypeParameterDescriptorImpl>emptyList(), pd.getExpectedThisObject(), receiverType);
|
||||
|
||||
PropertyGetterDescriptor pgd = new PropertyGetterDescriptor(
|
||||
myAccessor, Collections.<AnnotationDescriptor>emptyList(), myAccessor.getModality(),
|
||||
|
||||
@@ -54,7 +54,7 @@ public class CodegenUtil {
|
||||
|
||||
invokeDescriptor.initialize(fd.getReceiverParameter().exists() ? fd.getReceiverParameter().getType() : null,
|
||||
fd.getExpectedThisObject(),
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<TypeParameterDescriptorImpl>emptyList(),
|
||||
fd.getValueParameters(),
|
||||
fd.getReturnType(),
|
||||
Modality.FINAL,
|
||||
|
||||
@@ -1093,7 +1093,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -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))
|
||||
|
||||
+8
-8
@@ -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<JetType> upperBoundsForKotlin;
|
||||
@Nullable
|
||||
private final List<JetType> 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<JetType> upperBoundsForKotlin, List<JetType> 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.<AnnotationDescriptor>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.<AnnotationDescriptor>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){
|
||||
|
||||
-1
@@ -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;
|
||||
|
||||
+1
-6
@@ -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;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
}
|
||||
|
||||
public final ClassDescriptorImpl initialize(boolean sealed,
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@NotNull Collection<JetType> supertypes,
|
||||
@NotNull JetScope memberDeclarations,
|
||||
@NotNull Set<ConstructorDescriptor> constructors,
|
||||
@@ -57,7 +57,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
}
|
||||
|
||||
public final ClassDescriptorImpl initialize(boolean sealed,
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@NotNull Collection<JetType> supertypes,
|
||||
@NotNull JetScope memberDeclarations,
|
||||
@NotNull Set<ConstructorDescriptor> constructors,
|
||||
|
||||
+2
-2
@@ -77,12 +77,12 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
||||
protected FunctionDescriptorImpl initialize(
|
||||
@Nullable JetType receiverType,
|
||||
@NotNull ReceiverDescriptor expectedThisObject,
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<ValueParameterDescriptor> 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;
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ public class FunctionDescriptorUtil {
|
||||
assert JetStandardClasses.isFunctionType(functionType);
|
||||
functionDescriptor.initialize(JetStandardClasses.getReceiverType(functionType),
|
||||
expectedThisObject,
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<TypeParameterDescriptorImpl>emptyList(),
|
||||
JetStandardClasses.getValueParameters(functionDescriptor, functionType),
|
||||
JetStandardClasses.getReturnTypeFromFunctionType(functionType),
|
||||
modality,
|
||||
|
||||
@@ -112,17 +112,17 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
setType(outType, Collections.<TypeParameterDescriptor>emptyList(), expectedThisObject, receiverType);
|
||||
}
|
||||
|
||||
public void setType(@NotNull JetType outType, @NotNull List<TypeParameterDescriptor> typeParameters, @NotNull ReceiverDescriptor expectedThisObject, @Nullable JetType receiverType) {
|
||||
public void setType(@NotNull JetType outType, @NotNull List<? extends TypeParameterDescriptor> 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<TypeParameterDescriptor> typeParameters, @NotNull ReceiverDescriptor expectedThisObject, @NotNull ReceiverDescriptor receiver) {
|
||||
public void setType(@NotNull JetType outType, @NotNull List<? extends TypeParameterDescriptor> typeParameters, @NotNull ReceiverDescriptor expectedThisObject, @NotNull ReceiverDescriptor receiver) {
|
||||
setOutType(outType);
|
||||
|
||||
this.typeParameters = typeParameters;
|
||||
this.typeParameters = Lists.newArrayList(typeParameters);
|
||||
|
||||
this.receiver = receiver;
|
||||
this.expectedThisObject = expectedThisObject;
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
||||
public SimpleFunctionDescriptorImpl initialize(
|
||||
@Nullable JetType receiverType,
|
||||
@NotNull ReceiverDescriptor expectedThisObject,
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
||||
@Nullable JetType unsubstitutedReturnType,
|
||||
@Nullable Modality modality,
|
||||
|
||||
+16
-222
@@ -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<AnnotationDescriptor> 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<AnnotationDescriptor> 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<JetType> upperBounds;
|
||||
private JetType upperBoundsAsType;
|
||||
private final TypeConstructor typeConstructor;
|
||||
private JetType defaultType;
|
||||
private final Set<JetType> classObjectUpperBounds = Sets.newLinkedHashSet();
|
||||
private JetType classObjectBoundsAsType;
|
||||
|
||||
private final boolean reified;
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private TypeParameterDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> 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.<TypeParameterDescriptor>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 ? "<no owner>" : 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<JetType> getUpperBounds() {
|
||||
checkInitialized();
|
||||
return upperBounds;
|
||||
}
|
||||
Set<JetType> 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<JetType> getLowerBounds() {
|
||||
//checkInitialized();
|
||||
return Collections.singleton(JetStandardClasses.getNothingType());
|
||||
}
|
||||
Set<JetType> 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, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
checkInitialized();
|
||||
return visitor.visitTypeParameterDescriptor(this, data);
|
||||
}
|
||||
int getIndex();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getDefaultType() {
|
||||
//checkInitialized();
|
||||
if (defaultType == null) {
|
||||
defaultType = new JetTypeImpl(
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
getTypeConstructor(),
|
||||
TypeUtils.hasNullableLowerBound(this),
|
||||
Collections.<TypeProjection>emptyList(),
|
||||
new LazyScopeAdapter(new LazyValue<JetScope>() {
|
||||
@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);
|
||||
}
|
||||
|
||||
+275
@@ -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<AnnotationDescriptor> 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<AnnotationDescriptor> 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<JetType> upperBounds;
|
||||
private JetType upperBoundsAsType;
|
||||
private final TypeConstructor typeConstructor;
|
||||
private JetType defaultType;
|
||||
private final Set<JetType> classObjectUpperBounds = Sets.newLinkedHashSet();
|
||||
private JetType classObjectBoundsAsType;
|
||||
|
||||
private final boolean reified;
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private TypeParameterDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> 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.<TypeParameterDescriptor>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 ? "<no owner>" : 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<JetType> 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<JetType> 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, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
checkInitialized();
|
||||
return visitor.visitTypeParameterDescriptor(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getDefaultType() {
|
||||
//checkInitialized();
|
||||
if (defaultType == null) {
|
||||
defaultType = new JetTypeImpl(
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
getTypeConstructor(),
|
||||
TypeUtils.hasNullableLowerBound(this),
|
||||
Collections.<TypeProjection>emptyList(),
|
||||
new LazyScopeAdapter(new LazyValue<JetScope>() {
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class DescriptorResolver {
|
||||
List<TypeParameterDescriptor> 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<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters(), trace);
|
||||
List<TypeParameterDescriptorImpl> 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<TypeParameterDescriptor> resolveTypeParameters(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, List<JetTypeParameter> typeParameters, BindingTrace trace) {
|
||||
List<TypeParameterDescriptor> result = new ArrayList<TypeParameterDescriptor>();
|
||||
public List<TypeParameterDescriptorImpl> resolveTypeParameters(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, List<JetTypeParameter> typeParameters, BindingTrace trace) {
|
||||
List<TypeParameterDescriptorImpl> result = new ArrayList<TypeParameterDescriptorImpl>();
|
||||
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<TypeParameterDescriptor> parameters, BindingTrace trace) {
|
||||
|
||||
public void resolveGenericBounds(@NotNull JetTypeParameterListOwner declaration, JetScope scope, List<TypeParameterDescriptorImpl> parameters, BindingTrace trace) {
|
||||
List<UpperBoundCheckerTask> deferredUpperBoundCheckerTasks = Lists.newArrayList();
|
||||
|
||||
List<JetTypeParameter> typeParameters = declaration.getTypeParameters();
|
||||
Map<Name, TypeParameterDescriptor> parameterByName = Maps.newHashMap();
|
||||
Map<Name, TypeParameterDescriptorImpl> 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<TypeParameterDescriptor> typeParameters,
|
||||
public JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope, @NotNull List<? extends TypeParameterDescriptor> 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<TypeParameterDescriptor> typeParameterDescriptors;
|
||||
List<TypeParameterDescriptorImpl> typeParameterDescriptors;
|
||||
JetScope scopeWithTypeParameters;
|
||||
JetType receiverType = null;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<JetObjectDeclaration, MutableClassDescriptor> 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
|
||||
|
||||
@@ -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);
|
||||
|
||||
+3
-2
@@ -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;
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -170,7 +170,7 @@ public class ErrorUtils {
|
||||
function.initialize(
|
||||
null,
|
||||
ReceiverDescriptor.NO_RECEIVER,
|
||||
Collections.<TypeParameterDescriptor>emptyList(), // TODO
|
||||
Collections.<TypeParameterDescriptorImpl>emptyList(), // TODO
|
||||
Collections.<ValueParameterDescriptor>emptyList(), // TODO
|
||||
createErrorType("<ERROR FUNCTION RETURN TYPE>"),
|
||||
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.<AnnotationDescriptor>emptyList(), false, debugName, Collections.<TypeParameterDescriptor>emptyList(), Collections.singleton(JetStandardClasses.getAnyType())), memberScope);
|
||||
return new ErrorTypeImpl(new TypeConstructorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), false, debugName, Collections.<TypeParameterDescriptorImpl>emptyList(), Collections.singleton(JetStandardClasses.getAnyType())), memberScope);
|
||||
}
|
||||
|
||||
public static JetType createWrongVarianceErrorType(TypeProjection value) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class TypeConstructorImpl extends AnnotatedImpl implements TypeConstructo
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
boolean sealed,
|
||||
@NotNull String debugName,
|
||||
@NotNull List<TypeParameterDescriptor> parameters,
|
||||
@NotNull List<? extends TypeParameterDescriptor> parameters,
|
||||
@NotNull Collection<JetType> supertypes) {
|
||||
super(annotations);
|
||||
this.classifierDescriptor = classifierDescriptor;
|
||||
|
||||
@@ -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<TypeParameterUsage> 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()) {
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
functionDescriptor.initialize(effectiveReceiverType,
|
||||
NO_RECEIVER,
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<TypeParameterDescriptorImpl>emptyList(),
|
||||
valueParameterDescriptors,
|
||||
/*unsubstitutedReturnType = */ null,
|
||||
Modality.FINAL,
|
||||
|
||||
@@ -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.<AnnotationDescriptor>emptyList(),
|
||||
true, Variance.OUT_VARIANCE, Name.identifier("T" + (j + 1)), j);
|
||||
parameters.add(typeParameterDescriptor);
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(classDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.PUBLIC, false, false, Name.identifier("_" + (j + 1)), CallableMemberDescriptor.Kind.DECLARATION);
|
||||
propertyDescriptor.setType(typeParameterDescriptor.getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(), classDescriptor.getImplicitReceiver(), ReceiverDescriptor.NO_RECEIVER);
|
||||
propertyDescriptor.setType(typeParameterDescriptor.getDefaultType(), Collections.<TypeParameterDescriptorImpl>emptyList(), classDescriptor.getImplicitReceiver(), ReceiverDescriptor.NO_RECEIVER);
|
||||
PropertyGetterDescriptor getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, Collections.<AnnotationDescriptor>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.<AnnotationDescriptor>emptyList(), Name.identifier("invoke"), CallableMemberDescriptor.Kind.DECLARATION);
|
||||
WritableScope scopeForInvokeWithReceiver = createScopeForInvokeFunction(receiverFunction, invokeWithReceiver);
|
||||
List<TypeParameterDescriptor> parameters = createTypeParameters(i, receiverFunction);
|
||||
parameters.add(0, TypeParameterDescriptor.createWithDefaultBound(
|
||||
parameters.add(0, TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
receiverFunction,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
true, Variance.IN_VARIANCE, Name.identifier("T"), 0));
|
||||
@@ -238,12 +238,12 @@ public class JetStandardClasses {
|
||||
private static List<TypeParameterDescriptor> createTypeParameters(int parameterCount, ClassDescriptorImpl function) {
|
||||
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>();
|
||||
for (int j = 1; j <= parameterCount; j++) {
|
||||
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
|
||||
parameters.add(TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
function,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
true, Variance.IN_VARIANCE, Name.identifier("P" + j), j));
|
||||
}
|
||||
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
|
||||
parameters.add(TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
function,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
true, Variance.OUT_VARIANCE, Name.identifier("R"), parameterCount + 1));
|
||||
|
||||
@@ -146,7 +146,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
||||
|
||||
Object typeNameObject;
|
||||
|
||||
if (cd == null || cd instanceof TypeParameterDescriptor) {
|
||||
if (cd == null || cd instanceof TypeParameterDescriptorImpl) {
|
||||
typeNameObject = type.getConstructor();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -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<TypeParameterDescriptor> typeParameters
|
||||
List<TypeParameterDescriptorImpl> typeParameters
|
||||
= descriptorResolver.resolveTypeParameters(classDescriptor, parameterScope, classElement.getTypeParameters(), JetTestUtils.DUMMY_TRACE);
|
||||
descriptorResolver.resolveGenericBounds(classElement, parameterScope, typeParameters, JetTestUtils.DUMMY_TRACE);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user