diff --git a/idea/src/org/jetbrains/jet/lang/descriptors/NamespaceLike.java b/idea/src/org/jetbrains/jet/lang/descriptors/NamespaceLike.java new file mode 100644 index 00000000000..b5146219753 --- /dev/null +++ b/idea/src/org/jetbrains/jet/lang/descriptors/NamespaceLike.java @@ -0,0 +1,16 @@ +package org.jetbrains.jet.lang.descriptors; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author abreslav + */ +public interface NamespaceLike extends DeclarationDescriptor { + @Nullable + NamespaceDescriptor getNamespace(String name); + + void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor); + + void addClassifierDescriptor(MutableClassDescriptor classDescriptor); +} diff --git a/idea/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java b/idea/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java index b7a5ff40255..a8f44435358 100644 --- a/idea/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java +++ b/idea/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java @@ -1,5 +1,6 @@ package org.jetbrains.jet.lang.descriptors; +import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.types.*; @@ -11,22 +12,38 @@ import java.util.Set; * @author abreslav */ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implements ClassifierDescriptor { - private final Variance variance; - private final Set upperBounds; - private final TypeConstructor typeConstructor; - private final JetType boundsAsType; - private JetType type; - - public TypeParameterDescriptor( + public static TypeParameterDescriptor createWithDefaultBound( @NotNull DeclarationDescriptor containingDeclaration, @NotNull List annotations, @NotNull Variance variance, - @NotNull String name, - @NotNull Set upperBounds, - @NotNull JetType boundsAsType) { + @NotNull String name) { + TypeParameterDescriptor typeParameterDescriptor = createForFurtherModification(containingDeclaration, annotations, variance, name); + typeParameterDescriptor.addUpperBound(JetStandardClasses.getDefaultBound()); + return typeParameterDescriptor; + } + + public static TypeParameterDescriptor createForFurtherModification( + @NotNull DeclarationDescriptor containingDeclaration, + @NotNull List annotations, + @NotNull Variance variance, + @NotNull String name) { + return new TypeParameterDescriptor(containingDeclaration, annotations, variance, name); + } + + private final Variance variance; + private final Set upperBounds; + private final TypeConstructor typeConstructor; + private JetType boundsAsType; + private JetType type; + + private TypeParameterDescriptor( + @NotNull DeclarationDescriptor containingDeclaration, + @NotNull List annotations, + @NotNull Variance variance, + @NotNull String name) { super(containingDeclaration, annotations, name); this.variance = variance; - this.upperBounds = upperBounds; + this.upperBounds = Sets.newLinkedHashSet(); // TODO: Should we actually pass the annotations on to the type constructor? this.typeConstructor = new TypeConstructorImpl( this, @@ -35,27 +52,16 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement "&" + name, Collections.emptyList(), upperBounds); - this.boundsAsType = boundsAsType; - } - - public TypeParameterDescriptor( - @NotNull DeclarationDescriptor containingDeclaration, - @NotNull List annotations, - @NotNull Variance variance, - @NotNull String name) { - this( - containingDeclaration, - annotations, - variance, - name, - Collections.singleton(JetStandardClasses.getNullableAnyType()), - JetStandardClasses.getNullableAnyType()); } public Variance getVariance() { return variance; } + public void addUpperBound(@NotNull JetType bound) { + upperBounds.add(bound); + } + public Set getUpperBounds() { return upperBounds; } @@ -73,6 +79,14 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement @NotNull public JetType getBoundsAsType() { + if (boundsAsType == null) { + assert upperBounds != null; + assert upperBounds.size() > 0; + boundsAsType = upperBounds.size() == 1 ? upperBounds.iterator().next() : TypeUtils.intersect(JetTypeChecker.INSTANCE, upperBounds); + if (boundsAsType == null) { + boundsAsType = JetStandardClasses.getNothingType(); // TODO : some error message? + } + } return boundsAsType; } diff --git a/idea/src/org/jetbrains/jet/lang/resolve/BindingContext.java b/idea/src/org/jetbrains/jet/lang/resolve/BindingContext.java index 504b90a2a1a..bcd56e1b67e 100644 --- a/idea/src/org/jetbrains/jet/lang/resolve/BindingContext.java +++ b/idea/src/org/jetbrains/jet/lang/resolve/BindingContext.java @@ -29,8 +29,6 @@ public interface BindingContext { JetType getExpressionType(JetExpression expression); - JetScope getTopLevelScope(); - DeclarationDescriptor resolveReferenceExpression(JetReferenceExpression referenceExpression); JetType resolveTypeReference(JetTypeReference typeReference); diff --git a/idea/src/org/jetbrains/jet/lang/resolve/BindingTrace.java b/idea/src/org/jetbrains/jet/lang/resolve/BindingTrace.java index 31a0db736fe..5fd514f0b10 100644 --- a/idea/src/org/jetbrains/jet/lang/resolve/BindingTrace.java +++ b/idea/src/org/jetbrains/jet/lang/resolve/BindingTrace.java @@ -39,10 +39,6 @@ public interface BindingTrace { public void recordTypeResolution(@NotNull JetTypeReference typeReference, @NotNull JetType type) { } - @Override - public void setToplevelScope(JetScope toplevelScope) { - } - @Override public void recordBlock(JetFunctionLiteralExpression expression) { } @@ -82,8 +78,6 @@ public interface BindingTrace { public void recordTypeResolution(@NotNull JetTypeReference typeReference, @NotNull JetType type); - public void setToplevelScope(JetScope toplevelScope); - public void recordBlock(JetFunctionLiteralExpression expression); public void recordStatement(@NotNull JetElement statement); diff --git a/idea/src/org/jetbrains/jet/lang/resolve/BindingTraceAdapter.java b/idea/src/org/jetbrains/jet/lang/resolve/BindingTraceAdapter.java index eb99fc5ec5f..b001482f252 100644 --- a/idea/src/org/jetbrains/jet/lang/resolve/BindingTraceAdapter.java +++ b/idea/src/org/jetbrains/jet/lang/resolve/BindingTraceAdapter.java @@ -43,10 +43,6 @@ public class BindingTraceAdapter implements BindingTrace { originalTrace.recordTypeResolution(typeReference, type); } - public void setToplevelScope(JetScope toplevelScope) { - originalTrace.setToplevelScope(toplevelScope); - } - public void recordBlock(JetFunctionLiteralExpression expression) { originalTrace.recordBlock(expression); } diff --git a/idea/src/org/jetbrains/jet/lang/resolve/BindingTraceContext.java b/idea/src/org/jetbrains/jet/lang/resolve/BindingTraceContext.java index 0418737536c..029219e0659 100644 --- a/idea/src/org/jetbrains/jet/lang/resolve/BindingTraceContext.java +++ b/idea/src/org/jetbrains/jet/lang/resolve/BindingTraceContext.java @@ -60,8 +60,6 @@ public class BindingTraceContext implements BindingContext, BindingTrace { } }; - private JetScope toplevelScope; - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @NotNull @@ -149,11 +147,7 @@ public class BindingTraceContext implements BindingContext, BindingTrace { statements.remove(statement); } - public void setToplevelScope(JetScope toplevelScope) { - this.toplevelScope = toplevelScope; - } - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Override @@ -220,11 +214,6 @@ public class BindingTraceContext implements BindingContext, BindingTrace { return resolutionResults.get(referenceExpression); } - @Override - public JetScope getTopLevelScope() { - return toplevelScope; - } - @Override public PsiElement resolveToDeclarationPsiElement(JetReferenceExpression referenceExpression) { DeclarationDescriptor declarationDescriptor = resolveReferenceExpression(referenceExpression); diff --git a/idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java b/idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java index dffe9c8d500..6a2c8770302 100644 --- a/idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java +++ b/idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java @@ -1,5 +1,6 @@ package org.jetbrains.jet.lang.resolve; +import com.google.common.collect.Lists; import com.intellij.lang.ASTNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -73,6 +74,61 @@ public class ClassDescriptorResolver { ); } + public void resolveMutableClassDescriptor(@NotNull JetClass classElement, @NotNull MutableClassDescriptor descriptor) { + descriptor.setName(JetPsiUtil.safeName(classElement.getName())); + descriptor.getClassHeaderScope().addLabeledDeclaration(descriptor); + + WritableScope parameterScope = descriptor.getClassHeaderScope(); + + // TODO : Where-clause + List typeParameters = Lists.newArrayList(); + for (JetTypeParameter typeParameter : classElement.getTypeParameters()) { + TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification( + descriptor, + AnnotationResolver.INSTANCE.resolveAnnotations(typeParameter.getModifierList()), + typeParameter.getVariance(), + JetPsiUtil.safeName(typeParameter.getName()) + ); + parameterScope.addTypeParameterDescriptor(typeParameterDescriptor); + trace.recordDeclarationResolution(typeParameter, typeParameterDescriptor); + typeParameters.add(typeParameterDescriptor); + } + + boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD); + List supertypes = new ArrayList(); + TypeConstructorImpl typeConstructor = new TypeConstructorImpl( + descriptor, + AnnotationResolver.INSTANCE.resolveAnnotations(classElement.getModifierList()), + !open, + JetPsiUtil.safeName(classElement.getName()), + typeParameters, + supertypes); + descriptor.setTypeConstructor( + typeConstructor + ); + +// List delegationSpecifiers = classElement.getDelegationSpecifiers(); + // TODO : assuming that the hierarchy is acyclic +// Collection superclasses = delegationSpecifiers.isEmpty() +// ? Collections.singleton(JetStandardClasses.getAnyType()) +// : resolveDelegationSpecifiers(parameterScope, delegationSpecifiers); + + // TODO : UGLY HACK +// supertypes.addAll(superclasses); + + + // TODO : importing may be a bad idea +// for (JetType supertype : superclasses) { +// assert supertype != null : classElement.getName(); +// parameterScope.importScope(supertype.getMemberScope()); +// } + + descriptor.getClassHeaderScope().setThisType(descriptor.getDefaultType()); + + trace.recordDeclarationResolution(classElement, descriptor); + } + + public void resolveMutableClassDescriptor(@NotNull JetScope scope, @NotNull JetClass classElement, @NotNull MutableClassDescriptor descriptor) { descriptor.setName(JetPsiUtil.safeName(classElement.getName())); descriptor.getClassHeaderScope().addLabeledDeclaration(descriptor); @@ -249,14 +305,13 @@ public class ClassDescriptorResolver { JetType bound = extendsBound == null ? JetStandardClasses.getDefaultBound() : typeResolver.resolveType(extensibleScope, extendsBound); - TypeParameterDescriptor typeParameterDescriptor = new TypeParameterDescriptor( + TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification( containingDescriptor, AnnotationResolver.INSTANCE.resolveAnnotations(typeParameter.getModifierList()), typeParameter.getVariance(), - JetPsiUtil.safeName(typeParameter.getName()), - Collections.singleton(bound), - bound + JetPsiUtil.safeName(typeParameter.getName()) ); + typeParameterDescriptor.addUpperBound(bound); extensibleScope.addTypeParameterDescriptor(typeParameterDescriptor); trace.recordDeclarationResolution(typeParameter, typeParameterDescriptor); return typeParameterDescriptor; diff --git a/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java b/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java index 601db4db4b1..9011cdd33fb 100644 --- a/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java +++ b/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java @@ -24,12 +24,12 @@ import java.util.*; */ public class TopDownAnalyzer { - private final Map classes = new LinkedHashMap(); + private final Map classes = Maps.newLinkedHashMap(); private final Map namespaceScopes = new LinkedHashMap(); private final Map functions = Maps.newLinkedHashMap(); private final Map constructors = Maps.newLinkedHashMap(); private final Map properties = new LinkedHashMap(); - private final Map declaringScopes = new HashMap(); + private final Map declaringScopes = Maps.newHashMap(); private final Multimap declaringScopesToProperties = ArrayListMultimap.create(); private final Set primaryConstructorParameterProperties = Sets.newHashSet(); @@ -86,56 +86,137 @@ public class TopDownAnalyzer { process(outerScope, Collections.singletonList(declaration)); } - public void process(@NotNull JetScope outerScope, @NotNull List declarations) { - final WritableScope toplevelScope = new WritableScopeImpl(outerScope, outerScope.getContainingDeclaration(), trace.getErrorHandler(), null); // TODO ?! - trace.setToplevelScope(toplevelScope); // TODO : this is a hack - collectTypeDeclarators(toplevelScope, declarations); - resolveTypeDeclarations(); - processBehaviorDeclarators(toplevelScope, declarations); - readyToProcessExpressions = true; - resolveBehaviorDeclarationBodies(); + public void process(@NotNull WritableScope outerScope, T owner, @NotNull List declarations) { + collectNamespacesAndClassifiers(outerScope, owner, declarations); // namespaceScopes, classes + + createTypeConstructors(); // create type constructors for classes and generic parameters + resolveTypesInClassHeaders(); // Generic bounds and types in supertype lists (no expressions or constructor resolution) + checkGenericBoundsInClassHeaders(); // For the types resolved so far + + resolveFunctionAndPropertyHeaders(); // TODO : for now, fail fast if something is unknown yet (i.e. some type annotation is omitted) + resolveExecutableCode(); } -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - private void collectNamespacesAndClassifiers( + @NotNull final JetScope outerScope, + @NotNull final NamespaceLike owner, @NotNull Collection declarations) { for (JetDeclaration declaration : declarations) { declaration.accept(new JetVisitor() { @Override public void visitNamespace(JetNamespace namespace) { - super.visitNamespace(namespace); // TODO + List importDirectives = namespace.getImportDirectives(); + + String name = namespace.getName(); + if (name == null) { + name = ""; + } + NamespaceDescriptor namespaceDescriptor = owner.getNamespace(name); + if (namespaceDescriptor == null) { + namespaceDescriptor = new NamespaceDescriptor( + owner, //declaringScope.getContainingDeclaration(), + Collections.emptyList(), // TODO + name + ); + namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, trace.getErrorHandler(), null)); + owner.addNamespace(namespaceDescriptor); + trace.recordDeclarationResolution(namespace, namespaceDescriptor); + } + + WritableScope namespaceScope = new WritableScopeImpl(outerScope, owner, trace.getErrorHandler(), null); + namespaceScopes.put(namespace, namespaceScope); + + for (JetImportDirective importDirective : importDirectives) { + if (importDirective.isAbsoluteInRootNamespace()) { + throw new UnsupportedOperationException(); + } + if (importDirective.isAllUnder()) { + JetExpression importedReference = importDirective.getImportedReference(); + if (importedReference != null) { + JetType type = semanticServices.getTypeInferrer(trace, JetFlowInformationProvider.THROW_EXCEPTION).getTypeWithNamespaces(namespaceScope, importedReference, false); + if (type != null) { + namespaceScope.importScope(type.getMemberScope()); + } + } + } else { + throw new UnsupportedOperationException(); + } + } + + // TODO: !!! +// collectNamespacesAndClassifiers(namespaceScope, namespaceDescriptor, namespace.getDeclarations()); } @Override public void visitClass(JetClass klass) { - super.visitClass(klass); // TODO + MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, owner, outerScope); + mutableClassDescriptor.setName(JetPsiUtil.safeName(klass.getName())); + + owner.addClassifierDescriptor(mutableClassDescriptor); + + classes.put(klass, mutableClassDescriptor); + declaringScopes.put(klass, outerScope); + + WritableScope classScope = mutableClassDescriptor.getWritableUnsubstitutedMemberScope(); + collectTypeDeclarators(classScope, klass.getDeclarations()); } @Override public void visitTypedef(JetTypedef typedef) { - super.visitTypedef(typedef); // TODO + trace.getErrorHandler().genericError(typedef.getNode(), "Unsupported [TopDownAnalyzer]"); } @Override public void visitExtension(JetExtension extension) { - super.visitExtension(extension); // TODO + trace.getErrorHandler().genericError(extension.getNode(), "Unsupported [TopDownAnalyzer]"); } }); } } + private void createTypeConstructors() { + for (Map.Entry entry : classes.entrySet()) { + JetClass jetClass = entry.getKey(); + MutableClassDescriptor descriptor = entry.getValue(); + classDescriptorResolver.resolveMutableClassDescriptor(jetClass, descriptor); + } + } + + private void resolveTypesInClassHeaders() { + throw new UnsupportedOperationException(); // TODO + } + + private void checkGenericBoundsInClassHeaders() { + throw new UnsupportedOperationException(); // TODO + } + + private void resolveFunctionAndPropertyHeaders() { + throw new UnsupportedOperationException(); // TODO + } + + private void resolveExecutableCode() { + throw new UnsupportedOperationException(); // TODO + } + + @NotNull + public JetScope process(@NotNull JetScope outerScope, @NotNull List declarations) { + final WritableScope toplevelScope = new WritableScopeImpl(outerScope, outerScope.getContainingDeclaration(), trace.getErrorHandler(), null); // TODO ?! + + collectTypeDeclarators(toplevelScope, declarations); + resolveTypeDeclarations(); + processBehaviorDeclarators(toplevelScope, declarations); + readyToProcessExpressions = true; + resolveBehaviorDeclarationBodies(); + return toplevelScope; + } + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + private void collectTypeDeclarators( @NotNull final WritableScope declaringScope, List declarations) { for (JetDeclaration declaration : declarations) { declaration.accept(new JetVisitor() { - @Override - public void visitClass(JetClass klass) { - WritableScope classScope = processClass(declaringScope, klass); - collectTypeDeclarators(classScope, klass.getDeclarations()); - } - @Override public void visitNamespace(JetNamespace namespace) { List importDirectives = namespace.getImportDirectives(); @@ -179,9 +260,28 @@ public class TopDownAnalyzer { collectTypeDeclarators(namespaceScope, namespace.getDeclarations()); } + @Override + public void visitClass(JetClass klass) { + MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, declaringScope.getContainingDeclaration(), declaringScope); + mutableClassDescriptor.setName(JetPsiUtil.safeName(klass.getName())); + + declaringScope.addClassifierDescriptor(mutableClassDescriptor); + + classes.put(klass, mutableClassDescriptor); + declaringScopes.put(klass, declaringScope); + + WritableScope classScope = mutableClassDescriptor.getWritableUnsubstitutedMemberScope(); + collectTypeDeclarators(classScope, klass.getDeclarations()); + } + @Override public void visitTypedef(JetTypedef typedef) { - processTypeDef(typedef); + trace.getErrorHandler().genericError(typedef.getNode(), "Unsupported [TopDownAnalyzer]"); + } + + @Override + public void visitExtension(JetExtension extension) { + trace.getErrorHandler().genericError(extension.getNode(), "Unsupported [TopDownAnalyzer]"); } @Override @@ -192,27 +292,7 @@ public class TopDownAnalyzer { } } - private WritableScope processClass(@NotNull WritableScope declaringScope, JetClass klass) { - MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, declaringScope.getContainingDeclaration(), declaringScope); - mutableClassDescriptor.setName(JetPsiUtil.safeName(klass.getName())); - - declaringScope.addClassifierDescriptor(mutableClassDescriptor); - - classes.put(klass, mutableClassDescriptor); - declaringScopes.put(klass, declaringScope); - - return mutableClassDescriptor.getWritableUnsubstitutedMemberScope(); - } - - private void processExtension(JetExtension extension) { - throw new UnsupportedOperationException(extension.getText()); // TODO - } - - private void processTypeDef(@NotNull JetTypedef typedef) { - throw new UnsupportedOperationException(typedef.getText()); // TODO - } - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void resolveTypeDeclarations() { for (Map.Entry entry : classes.entrySet()) { @@ -494,7 +574,7 @@ public class TopDownAnalyzer { JetDeclaration declaration = entry.getKey(); ConstructorDescriptor descriptor = entry.getValue(); - WritableScope declaringScope = declaringScopes.get(declaration); + JetScope declaringScope = declaringScopes.get(declaration); assert declaringScope != null; resolveSecondaryConstructorBody((JetConstructor) declaration, descriptor, declaringScope); @@ -503,7 +583,7 @@ public class TopDownAnalyzer { } } - private void resolveSecondaryConstructorBody(JetConstructor declaration, final ConstructorDescriptor descriptor, final WritableScope declaringScope) { + private void resolveSecondaryConstructorBody(JetConstructor declaration, final ConstructorDescriptor descriptor, final JetScope declaringScope) { final JetScope functionInnerScope = getInnerScopeForConstructor(descriptor, declaringScope); final JetTypeInferrer typeInferrerForInitializers = semanticServices.getTypeInferrer(traceForConstructors, JetFlowInformationProvider.NONE); @@ -593,7 +673,7 @@ public class TopDownAnalyzer { final PropertyDescriptor propertyDescriptor = properties.get(property); assert propertyDescriptor != null; - WritableScope declaringScope = declaringScopes.get(property); + JetScope declaringScope = declaringScopes.get(property); JetExpression initializer = property.getInitializer(); if (initializer != null) { @@ -618,7 +698,7 @@ public class TopDownAnalyzer { if (processed.contains(property)) continue; final PropertyDescriptor propertyDescriptor = entry.getValue(); - WritableScope declaringScope = declaringScopes.get(property); + JetScope declaringScope = declaringScopes.get(property); JetExpression initializer = property.getInitializer(); if (initializer != null) { @@ -629,7 +709,7 @@ public class TopDownAnalyzer { } } - private void resolvePropertyAccessors(JetProperty property, PropertyDescriptor propertyDescriptor, WritableScope declaringScope) { + private void resolvePropertyAccessors(JetProperty property, PropertyDescriptor propertyDescriptor, JetScope declaringScope) { BindingTraceAdapter fieldAccessTrackingTrace = createFieldTrackingTrace(propertyDescriptor); WritableScope accessorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), trace.getErrorHandler(), null); @@ -698,7 +778,7 @@ public class TopDownAnalyzer { JetDeclaration declaration = entry.getKey(); FunctionDescriptor descriptor = entry.getValue(); - WritableScope declaringScope = declaringScopes.get(declaration); + JetScope declaringScope = declaringScopes.get(declaration); assert declaringScope != null; resolveFunctionBody(traceForMembers, (JetFunction) declaration, (FunctionDescriptorImpl) descriptor, declaringScope); @@ -711,7 +791,7 @@ public class TopDownAnalyzer { @NotNull BindingTrace trace, @NotNull JetDeclarationWithBody function, @NotNull MutableFunctionDescriptor functionDescriptor, - @NotNull WritableScope declaringScope) { + @NotNull JetScope declaringScope) { JetExpression bodyExpression = function.getBodyExpression(); if (bodyExpression != null) { JetFlowInformationProvider flowInformationProvider = computeFlowData(function.asElement(), bodyExpression); diff --git a/idea/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java b/idea/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java index 0e7b4a6f45c..0e3f4838546 100644 --- a/idea/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java +++ b/idea/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java @@ -2,15 +2,12 @@ package org.jetbrains.jet.lang.resolve.java; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor; -import org.jetbrains.jet.lang.descriptors.WritableFunctionGroup; import org.jetbrains.jet.lang.types.*; import java.util.*; @@ -124,32 +121,25 @@ public class JavaDescriptorResolver { } private TypeParameterDescriptor createJavaTypeParameterDescriptor(@NotNull DeclarationDescriptor owner, @NotNull PsiTypeParameter typeParameter) { - PsiClassType[] referencedTypes = typeParameter.getExtendsList().getReferencedTypes(); - Set upperBounds; - JetType boundsAsType; - if (referencedTypes.length == 0){ - boundsAsType = JetStandardClasses.getNullableAnyType(); - upperBounds = Collections.singleton(boundsAsType); - } - else if (referencedTypes.length == 1) { - boundsAsType = semanticServices.getTypeTransformer().transformToType(referencedTypes[0]); - upperBounds = Collections.singleton(boundsAsType); - } - else { - upperBounds = Sets.newLinkedHashSet(); - for (PsiClassType referencedType : referencedTypes) { - upperBounds.add(semanticServices.getTypeTransformer().transformToType(referencedType)); - } - boundsAsType = TypeUtils.safeIntersect(semanticServices.getJetSemanticServices().getTypeChecker(), upperBounds); - } - return new TypeParameterDescriptor( + TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification( owner, Collections.emptyList(), // TODO Variance.INVARIANT, - typeParameter.getName(), - upperBounds, - boundsAsType + typeParameter.getName() ); + PsiClassType[] referencedTypes = typeParameter.getExtendsList().getReferencedTypes(); + if (referencedTypes.length == 0){ + typeParameterDescriptor.addUpperBound(JetStandardClasses.getNullableAnyType()); + } + else if (referencedTypes.length == 1) { + typeParameterDescriptor.addUpperBound(semanticServices.getTypeTransformer().transformToType(referencedTypes[0])); + } + else { + for (PsiClassType referencedType : referencedTypes) { + typeParameterDescriptor.addUpperBound(semanticServices.getTypeTransformer().transformToType(referencedType)); + } + } + return typeParameterDescriptor; } @NotNull diff --git a/idea/src/org/jetbrains/jet/lang/types/JetStandardClasses.java b/idea/src/org/jetbrains/jet/lang/types/JetStandardClasses.java index cac1fdbd14e..7e9bcff771e 100644 --- a/idea/src/org/jetbrains/jet/lang/types/JetStandardClasses.java +++ b/idea/src/org/jetbrains/jet/lang/types/JetStandardClasses.java @@ -77,6 +77,10 @@ public class JetStandardClasses { private static final JetType ANY_TYPE = new JetTypeImpl(ANY.getTypeConstructor(), JetScope.EMPTY); private static final JetType NULLABLE_ANY_TYPE = TypeUtils.makeNullable(ANY_TYPE); +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + private static final JetType DEFAULT_BOUND = getNullableAnyType(); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static final JetScope STUB = JetScope.EMPTY; @@ -95,7 +99,7 @@ public class JetStandardClasses { Collections.emptyList(), "Tuple" + i); for (int j = 0; j < i; j++) { - parameters.add(new TypeParameterDescriptor( + parameters.add(TypeParameterDescriptor.createWithDefaultBound( classDescriptor, Collections.emptyList(), Variance.OUT_VARIANCE, "T" + j)); @@ -133,7 +137,7 @@ public class JetStandardClasses { Collections.emptyList(), "ReceiverFunction" + i); List parameters = createTypeParameters(i, receiverFunction); - parameters.add(0, new TypeParameterDescriptor( + parameters.add(0, TypeParameterDescriptor.createWithDefaultBound( receiverFunction, Collections.emptyList(), Variance.IN_VARIANCE, "T")); @@ -147,12 +151,12 @@ public class JetStandardClasses { private static List createTypeParameters(int parameterCount, ClassDescriptorImpl function) { List parameters = new ArrayList(); for (int j = 0; j < parameterCount; j++) { - parameters.add(new TypeParameterDescriptor( + parameters.add(TypeParameterDescriptor.createWithDefaultBound( function, Collections.emptyList(), Variance.IN_VARIANCE, "P" + j)); } - parameters.add(new TypeParameterDescriptor( + parameters.add(TypeParameterDescriptor.createWithDefaultBound( function, Collections.emptyList(), Variance.OUT_VARIANCE, "R")); @@ -199,8 +203,6 @@ public class JetStandardClasses { } } - private static final JetType DEFAULT_BOUND = getNullableAnyType(); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @NotNull diff --git a/idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java b/idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java index 35ca790b332..2cff5d852e2 100644 --- a/idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java +++ b/idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java @@ -73,9 +73,7 @@ public class JetStandardLibrary { JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this); BindingTraceContext bindingTraceContext = new BindingTraceContext(); TopDownAnalyzer bootstrappingTDA = new TopDownAnalyzer(bootstrappingSemanticServices, bindingTraceContext); - bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations()); - - this.libraryScope = bindingTraceContext.getTopLevelScope(); + this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations()); this.byteClass = (ClassDescriptor) libraryScope.getClassifier("Byte"); this.charClass = (ClassDescriptor) libraryScope.getClassifier("Char");