提交 67ca0496 编写于 作者: S Stepan Koltsov

TypeParameterDescriptor.initialized

Internal state checks

Also add a missing initialization
上级 dfdd5959
......@@ -334,6 +334,7 @@ public class JavaDescriptorResolver {
typeParameterDescriptor.addUpperBound(semanticServices.getTypeTransformer().transformToType(referencedType));
}
}
typeParameterDescriptor.setInitialized();
}
private void initializeTypeParameters(PsiTypeParameterListOwner typeParameterListOwner) {
......@@ -625,7 +626,9 @@ public class JavaDescriptorResolver {
if (attributeValue != null) {
String typeParametersString = (String) attributeValue.getValue();
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>();
new JetSignatureReader(jetSignature).acceptFormalTypeParametersOnly(new JetSignatureExceptionsAdapter() {
@Override
......@@ -677,6 +680,8 @@ public class JavaDescriptorResolver {
JetSignatureUtils.translateVariance(variance),
name,
++index);
PsiTypeParameter psiTypeParameter = getPsiTypeParameterByName(method, method.getName(), name);
typeParameterDescriptorCache.put(psiTypeParameter, typeParameter);
r.add(typeParameter);
}
};
......
......@@ -28,6 +28,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
int index) {
TypeParameterDescriptor typeParameterDescriptor = createForFurtherModification(containingDeclaration, annotations, reified, variance, name, index);
typeParameterDescriptor.addUpperBound(JetStandardClasses.getDefaultBound());
typeParameterDescriptor.setInitialized();
return typeParameterDescriptor;
}
......@@ -52,6 +53,8 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
private final boolean reified;
private boolean initialized = false;
private TypeParameterDescriptor(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<AnnotationDescriptor> annotations,
......@@ -74,25 +77,61 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
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() {
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());
}
}
@NotNull
public Set<JetType> getUpperBounds() {
checkInitialized();
return upperBounds;
}
@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();
......@@ -106,11 +145,13 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
@NotNull
public Set<JetType> getLowerBounds() {
//checkInitialized();
return Collections.singleton(JetStandardClasses.getNothingType());
}
@NotNull
public JetType getLowerBoundsAsType() {
checkInitialized();
return JetStandardClasses.getNothingType();
}
......@@ -118,6 +159,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
@NotNull
@Override
public TypeConstructor getTypeConstructor() {
//checkInitialized();
return typeConstructor;
}
......@@ -135,12 +177,14 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
@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(),
......@@ -159,6 +203,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
@Override
public JetType getClassObjectType() {
checkInitialized();
if (classObjectUpperBounds.isEmpty()) return null;
if (classObjectBoundsAsType == null) {
......@@ -176,15 +221,19 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
}
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) {
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) {
if (parameter.getUpperBounds().isEmpty()) {
parameter.addUpperBound(JetStandardClasses.getDefaultBound());
}
parameter.addDefaultUpperBound();
parameter.setInitialized();
if (JetStandardClasses.isNothing(parameter.getUpperBoundsAsType())) {
PsiElement nameIdentifier = typeParameters.get(parameter.getIndex()).getNameIdentifier();
......
......@@ -44,6 +44,7 @@ public class DescriptorSubstitutor {
descriptor.getVariance(),
descriptor.getName(),
descriptor.getIndex());
substituted.setInitialized();
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjection(substituted.getDefaultType()));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册