TypeParameterDescriptor.initialized
Internal state checks Also add a missing initialization
This commit is contained in:
+8
-3
@@ -334,6 +334,7 @@ public class JavaDescriptorResolver {
|
|||||||
typeParameterDescriptor.addUpperBound(semanticServices.getTypeTransformer().transformToType(referencedType));
|
typeParameterDescriptor.addUpperBound(semanticServices.getTypeTransformer().transformToType(referencedType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
typeParameterDescriptor.setInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeTypeParameters(PsiTypeParameterListOwner typeParameterListOwner) {
|
private void initializeTypeParameters(PsiTypeParameterListOwner typeParameterListOwner) {
|
||||||
@@ -625,7 +626,9 @@ public class JavaDescriptorResolver {
|
|||||||
if (attributeValue != null) {
|
if (attributeValue != null) {
|
||||||
String typeParametersString = (String) attributeValue.getValue();
|
String typeParametersString = (String) attributeValue.getValue();
|
||||||
if (typeParametersString != null) {
|
if (typeParametersString != null) {
|
||||||
return resolveMethodTypeParametersFromJetSignature(typeParametersString, functionDescriptorImpl);
|
List<TypeParameterDescriptor> r = resolveMethodTypeParametersFromJetSignature(typeParametersString, method, functionDescriptorImpl);
|
||||||
|
initializeTypeParameters(method);
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -637,9 +640,9 @@ public class JavaDescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #resolveClassTypeParametersFromJetSignature(String, JavaClassDescriptor)
|
* @see #resolveClassTypeParametersFromJetSignature(String, com.intellij.psi.PsiClass, JavaClassDescriptor)
|
||||||
*/
|
*/
|
||||||
private List<TypeParameterDescriptor> resolveMethodTypeParametersFromJetSignature(String jetSignature, final FunctionDescriptor functionDescriptor) {
|
private List<TypeParameterDescriptor> resolveMethodTypeParametersFromJetSignature(String jetSignature, final PsiMethod method, final FunctionDescriptor functionDescriptor) {
|
||||||
final List<TypeParameterDescriptor> r = new ArrayList<TypeParameterDescriptor>();
|
final List<TypeParameterDescriptor> r = new ArrayList<TypeParameterDescriptor>();
|
||||||
new JetSignatureReader(jetSignature).acceptFormalTypeParametersOnly(new JetSignatureExceptionsAdapter() {
|
new JetSignatureReader(jetSignature).acceptFormalTypeParametersOnly(new JetSignatureExceptionsAdapter() {
|
||||||
@Override
|
@Override
|
||||||
@@ -677,6 +680,8 @@ public class JavaDescriptorResolver {
|
|||||||
JetSignatureUtils.translateVariance(variance),
|
JetSignatureUtils.translateVariance(variance),
|
||||||
name,
|
name,
|
||||||
++index);
|
++index);
|
||||||
|
PsiTypeParameter psiTypeParameter = getPsiTypeParameterByName(method, method.getName(), name);
|
||||||
|
typeParameterDescriptorCache.put(psiTypeParameter, typeParameter);
|
||||||
r.add(typeParameter);
|
r.add(typeParameter);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+50
-1
@@ -28,6 +28,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
int index) {
|
int index) {
|
||||||
TypeParameterDescriptor typeParameterDescriptor = createForFurtherModification(containingDeclaration, annotations, reified, variance, name, index);
|
TypeParameterDescriptor typeParameterDescriptor = createForFurtherModification(containingDeclaration, annotations, reified, variance, name, index);
|
||||||
typeParameterDescriptor.addUpperBound(JetStandardClasses.getDefaultBound());
|
typeParameterDescriptor.addUpperBound(JetStandardClasses.getDefaultBound());
|
||||||
|
typeParameterDescriptor.setInitialized();
|
||||||
return typeParameterDescriptor;
|
return typeParameterDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +53,8 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
|
|
||||||
private final boolean reified;
|
private final boolean reified;
|
||||||
|
|
||||||
|
private boolean initialized = false;
|
||||||
|
|
||||||
private TypeParameterDescriptor(
|
private TypeParameterDescriptor(
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull List<AnnotationDescriptor> annotations,
|
@NotNull List<AnnotationDescriptor> annotations,
|
||||||
@@ -74,25 +77,61 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
upperBounds);
|
upperBounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setInitialized() {
|
||||||
|
if (initialized) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkInitialized() {
|
||||||
|
if (!initialized) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkUninitialized() {
|
||||||
|
if (initialized) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isReified() {
|
public boolean isReified() {
|
||||||
|
checkInitialized();
|
||||||
return reified;
|
return reified;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Variance getVariance() {
|
public Variance getVariance() {
|
||||||
|
checkInitialized();
|
||||||
return variance;
|
return variance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUpperBound(@NotNull JetType bound) {
|
public void addUpperBound(@NotNull JetType bound) {
|
||||||
|
checkUninitialized();
|
||||||
|
doAddUpperBound(bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doAddUpperBound(JetType bound) {
|
||||||
upperBounds.add(bound); // TODO : Duplicates?
|
upperBounds.add(bound); // TODO : Duplicates?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addDefaultUpperBound() {
|
||||||
|
checkUninitialized();
|
||||||
|
|
||||||
|
if (upperBounds.isEmpty()) {
|
||||||
|
doAddUpperBound(JetStandardClasses.getDefaultBound());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<JetType> getUpperBounds() {
|
public Set<JetType> getUpperBounds() {
|
||||||
|
checkInitialized();
|
||||||
return upperBounds;
|
return upperBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getUpperBoundsAsType() {
|
public JetType getUpperBoundsAsType() {
|
||||||
|
checkInitialized();
|
||||||
if (upperBoundsAsType == null) {
|
if (upperBoundsAsType == null) {
|
||||||
assert upperBounds != null : "Upper bound list is null in " + getName();
|
assert upperBounds != null : "Upper bound list is null in " + getName();
|
||||||
assert upperBounds.size() > 0 : "Upper bound list is empty in " + getName();
|
assert upperBounds.size() > 0 : "Upper bound list is empty in " + getName();
|
||||||
@@ -106,11 +145,13 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<JetType> getLowerBounds() {
|
public Set<JetType> getLowerBounds() {
|
||||||
|
//checkInitialized();
|
||||||
return Collections.singleton(JetStandardClasses.getNothingType());
|
return Collections.singleton(JetStandardClasses.getNothingType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getLowerBoundsAsType() {
|
public JetType getLowerBoundsAsType() {
|
||||||
|
checkInitialized();
|
||||||
return JetStandardClasses.getNothingType();
|
return JetStandardClasses.getNothingType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +159,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public TypeConstructor getTypeConstructor() {
|
public TypeConstructor getTypeConstructor() {
|
||||||
|
//checkInitialized();
|
||||||
return typeConstructor;
|
return typeConstructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,12 +177,14 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||||
|
checkInitialized();
|
||||||
return visitor.visitTypeParameterDescriptor(this, data);
|
return visitor.visitTypeParameterDescriptor(this, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public JetType getDefaultType() {
|
public JetType getDefaultType() {
|
||||||
|
//checkInitialized();
|
||||||
if (defaultType == null) {
|
if (defaultType == null) {
|
||||||
defaultType = new JetTypeImpl(
|
defaultType = new JetTypeImpl(
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
@@ -159,6 +203,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetType getClassObjectType() {
|
public JetType getClassObjectType() {
|
||||||
|
checkInitialized();
|
||||||
if (classObjectUpperBounds.isEmpty()) return null;
|
if (classObjectUpperBounds.isEmpty()) return null;
|
||||||
|
|
||||||
if (classObjectBoundsAsType == null) {
|
if (classObjectBoundsAsType == null) {
|
||||||
@@ -176,15 +221,19 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addClassObjectBound(@NotNull JetType bound) {
|
public void addClassObjectBound(@NotNull JetType bound) {
|
||||||
|
checkUninitialized();
|
||||||
classObjectUpperBounds.add(bound); // TODO : Duplicates?
|
classObjectUpperBounds.add(bound); // TODO : Duplicates?
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIndex() {
|
public int getIndex() {
|
||||||
|
checkInitialized();
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public TypeParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) {
|
public TypeParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) {
|
||||||
return new TypeParameterDescriptor(newOwner, Lists.newArrayList(getAnnotations()), reified, variance, getName(), index);
|
TypeParameterDescriptor copy = new TypeParameterDescriptor(newOwner, Lists.newArrayList(getAnnotations()), reified, variance, getName(), index);
|
||||||
|
copy.initialized = this.initialized;
|
||||||
|
return copy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -381,9 +381,9 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (TypeParameterDescriptor parameter : parameters) {
|
for (TypeParameterDescriptor parameter : parameters) {
|
||||||
if (parameter.getUpperBounds().isEmpty()) {
|
parameter.addDefaultUpperBound();
|
||||||
parameter.addUpperBound(JetStandardClasses.getDefaultBound());
|
|
||||||
}
|
parameter.setInitialized();
|
||||||
|
|
||||||
if (JetStandardClasses.isNothing(parameter.getUpperBoundsAsType())) {
|
if (JetStandardClasses.isNothing(parameter.getUpperBoundsAsType())) {
|
||||||
PsiElement nameIdentifier = typeParameters.get(parameter.getIndex()).getNameIdentifier();
|
PsiElement nameIdentifier = typeParameters.get(parameter.getIndex()).getNameIdentifier();
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ public class DescriptorSubstitutor {
|
|||||||
descriptor.getVariance(),
|
descriptor.getVariance(),
|
||||||
descriptor.getName(),
|
descriptor.getName(),
|
||||||
descriptor.getIndex());
|
descriptor.getIndex());
|
||||||
|
substituted.setInitialized();
|
||||||
|
|
||||||
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjection(substituted.getDefaultType()));
|
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjection(substituted.getDefaultType()));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user