Refactoring of the TopDownAnalyzer in progress
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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<JetType> upperBounds;
|
||||
private final TypeConstructor typeConstructor;
|
||||
private final JetType boundsAsType;
|
||||
private JetType type;
|
||||
|
||||
public TypeParameterDescriptor(
|
||||
public static TypeParameterDescriptor createWithDefaultBound(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<Annotation> annotations,
|
||||
@NotNull Variance variance,
|
||||
@NotNull String name,
|
||||
@NotNull Set<JetType> 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<Annotation> annotations,
|
||||
@NotNull Variance variance,
|
||||
@NotNull String name) {
|
||||
return new TypeParameterDescriptor(containingDeclaration, annotations, variance, name);
|
||||
}
|
||||
|
||||
private final Variance variance;
|
||||
private final Set<JetType> upperBounds;
|
||||
private final TypeConstructor typeConstructor;
|
||||
private JetType boundsAsType;
|
||||
private JetType type;
|
||||
|
||||
private TypeParameterDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<Annotation> 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.<TypeParameterDescriptor>emptyList(),
|
||||
upperBounds);
|
||||
this.boundsAsType = boundsAsType;
|
||||
}
|
||||
|
||||
public TypeParameterDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<Annotation> 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<JetType> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,6 @@ public interface BindingContext {
|
||||
|
||||
JetType getExpressionType(JetExpression expression);
|
||||
|
||||
JetScope getTopLevelScope();
|
||||
|
||||
DeclarationDescriptor resolveReferenceExpression(JetReferenceExpression referenceExpression);
|
||||
|
||||
JetType resolveTypeReference(JetTypeReference typeReference);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<TypeParameterDescriptor> 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<JetType> supertypes = new ArrayList<JetType>();
|
||||
TypeConstructorImpl typeConstructor = new TypeConstructorImpl(
|
||||
descriptor,
|
||||
AnnotationResolver.INSTANCE.resolveAnnotations(classElement.getModifierList()),
|
||||
!open,
|
||||
JetPsiUtil.safeName(classElement.getName()),
|
||||
typeParameters,
|
||||
supertypes);
|
||||
descriptor.setTypeConstructor(
|
||||
typeConstructor
|
||||
);
|
||||
|
||||
// List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers();
|
||||
// TODO : assuming that the hierarchy is acyclic
|
||||
// Collection<? extends JetType> 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;
|
||||
|
||||
@@ -24,12 +24,12 @@ import java.util.*;
|
||||
*/
|
||||
public class TopDownAnalyzer {
|
||||
|
||||
private final Map<JetClass, MutableClassDescriptor> classes = new LinkedHashMap<JetClass, MutableClassDescriptor>();
|
||||
private final Map<JetClass, MutableClassDescriptor> classes = Maps.newLinkedHashMap();
|
||||
private final Map<JetNamespace, WritableScope> namespaceScopes = new LinkedHashMap<JetNamespace, WritableScope>();
|
||||
private final Map<JetDeclaration, FunctionDescriptorImpl> functions = Maps.newLinkedHashMap();
|
||||
private final Map<JetDeclaration, ConstructorDescriptor> constructors = Maps.newLinkedHashMap();
|
||||
private final Map<JetProperty, PropertyDescriptor> properties = new LinkedHashMap<JetProperty, PropertyDescriptor>();
|
||||
private final Map<JetDeclaration, WritableScope> declaringScopes = new HashMap<JetDeclaration, WritableScope>();
|
||||
private final Map<JetDeclaration, JetScope> declaringScopes = Maps.newHashMap();
|
||||
private final Multimap<DeclarationDescriptor, PropertyDescriptor> declaringScopesToProperties = ArrayListMultimap.create();
|
||||
private final Set<PropertyDescriptor> primaryConstructorParameterProperties = Sets.newHashSet();
|
||||
|
||||
@@ -86,56 +86,137 @@ public class TopDownAnalyzer {
|
||||
process(outerScope, Collections.singletonList(declaration));
|
||||
}
|
||||
|
||||
public void process(@NotNull JetScope outerScope, @NotNull List<JetDeclaration> 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 <T extends NamespaceDescriptor & NamespaceLike> void process(@NotNull WritableScope outerScope, T owner, @NotNull List<JetDeclaration> 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<JetDeclaration> declarations) {
|
||||
for (JetDeclaration declaration : declarations) {
|
||||
declaration.accept(new JetVisitor() {
|
||||
@Override
|
||||
public void visitNamespace(JetNamespace namespace) {
|
||||
super.visitNamespace(namespace); // TODO
|
||||
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
|
||||
|
||||
String name = namespace.getName();
|
||||
if (name == null) {
|
||||
name = "<no name provided>";
|
||||
}
|
||||
NamespaceDescriptor namespaceDescriptor = owner.getNamespace(name);
|
||||
if (namespaceDescriptor == null) {
|
||||
namespaceDescriptor = new NamespaceDescriptor(
|
||||
owner, //declaringScope.getContainingDeclaration(),
|
||||
Collections.<Annotation>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<JetClass, MutableClassDescriptor> 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<JetDeclaration> 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<JetDeclaration> 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<JetImportDirective> 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<JetClass, MutableClassDescriptor> 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);
|
||||
|
||||
@@ -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<JetType> 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.<Annotation>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
|
||||
|
||||
@@ -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.<Annotation>emptyList(),
|
||||
"Tuple" + i);
|
||||
for (int j = 0; j < i; j++) {
|
||||
parameters.add(new TypeParameterDescriptor(
|
||||
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
|
||||
classDescriptor,
|
||||
Collections.<Annotation>emptyList(),
|
||||
Variance.OUT_VARIANCE, "T" + j));
|
||||
@@ -133,7 +137,7 @@ public class JetStandardClasses {
|
||||
Collections.<Annotation>emptyList(),
|
||||
"ReceiverFunction" + i);
|
||||
List<TypeParameterDescriptor> parameters = createTypeParameters(i, receiverFunction);
|
||||
parameters.add(0, new TypeParameterDescriptor(
|
||||
parameters.add(0, TypeParameterDescriptor.createWithDefaultBound(
|
||||
receiverFunction,
|
||||
Collections.<Annotation>emptyList(),
|
||||
Variance.IN_VARIANCE, "T"));
|
||||
@@ -147,12 +151,12 @@ public class JetStandardClasses {
|
||||
private static List<TypeParameterDescriptor> createTypeParameters(int parameterCount, ClassDescriptorImpl function) {
|
||||
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>();
|
||||
for (int j = 0; j < parameterCount; j++) {
|
||||
parameters.add(new TypeParameterDescriptor(
|
||||
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
|
||||
function,
|
||||
Collections.<Annotation>emptyList(),
|
||||
Variance.IN_VARIANCE, "P" + j));
|
||||
}
|
||||
parameters.add(new TypeParameterDescriptor(
|
||||
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
|
||||
function,
|
||||
Collections.<Annotation>emptyList(),
|
||||
Variance.OUT_VARIANCE, "R"));
|
||||
@@ -199,8 +203,6 @@ public class JetStandardClasses {
|
||||
}
|
||||
}
|
||||
|
||||
private static final JetType DEFAULT_BOUND = getNullableAnyType();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user