Name imports fixed

This commit is contained in:
Andrey Breslav
2011-05-27 14:30:49 +04:00
parent b950a82fcd
commit e4df21c150
6 changed files with 78 additions and 61 deletions
@@ -99,7 +99,6 @@ public class TopDownAnalyzer {
declaration.accept(new JetVisitor() { declaration.accept(new JetVisitor() {
@Override @Override
public void visitNamespace(JetNamespace namespace) { public void visitNamespace(JetNamespace namespace) {
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
String name = namespace.getName(); String name = namespace.getName();
if (name == null) { if (name == null) {
@@ -118,9 +117,43 @@ public class TopDownAnalyzer {
} }
namespaceDescriptors.put(namespace, namespaceDescriptor); namespaceDescriptors.put(namespace, namespaceDescriptor);
WritableScope namespaceScope = new WriteThroughScope(outerScope, (WritableScope) namespaceDescriptor.getMemberScope()); WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), trace.getErrorHandler());
namespaceScopes.put(namespace, namespaceScope); namespaceScopes.put(namespace, namespaceScope);
processImports(namespace, namespaceScope, outerScope);
collectNamespacesAndClassifiers(namespaceScope, namespaceDescriptor, namespace.getDeclarations());
}
@Override
public void visitClass(JetClass klass) {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, owner, outerScope);
mutableClassDescriptor.setName(JetPsiUtil.safeName(klass.getName()));
owner.addClassifierDescriptor(mutableClassDescriptor);
classes.put(klass, mutableClassDescriptor);
declaringScopes.put(klass, outerScope);
JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution();
collectNamespacesAndClassifiers(classScope, mutableClassDescriptor, klass.getDeclarations());
}
@Override
public void visitTypedef(JetTypedef typedef) {
trace.getErrorHandler().genericError(typedef.getNode(), "Unsupported [TopDownAnalyzer]");
}
@Override
public void visitExtension(JetExtension extension) {
trace.getErrorHandler().genericError(extension.getNode(), "Unsupported [TopDownAnalyzer]");
}
});
}
}
private void processImports(@NotNull JetNamespace namespace, @NotNull WriteThroughScope namespaceScope, @NotNull JetScope outerScope) {
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
for (JetImportDirective importDirective : importDirectives) { for (JetImportDirective importDirective : importDirectives) {
if (importDirective.isAbsoluteInRootNamespace()) { if (importDirective.isAbsoluteInRootNamespace()) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
@@ -165,39 +198,10 @@ public class TopDownAnalyzer {
String aliasName = importDirective.getAliasName(); String aliasName = importDirective.getAliasName();
String importedClassifierName = aliasName != null ? aliasName : classifierDescriptor.getName(); String importedClassifierName = aliasName != null ? aliasName : classifierDescriptor.getName();
namespaceScope.addClassifierAlias(importedClassifierName, classifierDescriptor); namespaceScope.importClassifierAlias(importedClassifierName, classifierDescriptor);
} }
} }
} }
collectNamespacesAndClassifiers(namespaceScope, namespaceDescriptor, namespace.getDeclarations());
}
@Override
public void visitClass(JetClass klass) {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, owner, outerScope);
mutableClassDescriptor.setName(JetPsiUtil.safeName(klass.getName()));
owner.addClassifierDescriptor(mutableClassDescriptor);
classes.put(klass, mutableClassDescriptor);
declaringScopes.put(klass, outerScope);
JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution();
collectNamespacesAndClassifiers(classScope, mutableClassDescriptor, klass.getDeclarations());
}
@Override
public void visitTypedef(JetTypedef typedef) {
trace.getErrorHandler().genericError(typedef.getNode(), "Unsupported [TopDownAnalyzer]");
}
@Override
public void visitExtension(JetExtension extension) {
trace.getErrorHandler().genericError(extension.getNode(), "Unsupported [TopDownAnalyzer]");
}
});
}
} }
private void createTypeConstructors() { private void createTypeConstructors() {
@@ -13,8 +13,6 @@ import java.util.*;
* @author abreslav * @author abreslav
*/ */
public class WritableScopeImpl extends WritableScopeWithImports { public class WritableScopeImpl extends WritableScopeWithImports {
@NotNull
private final ErrorHandler errorHandler;
@NotNull @NotNull
private final DeclarationDescriptor ownerDeclarationDescriptor; private final DeclarationDescriptor ownerDeclarationDescriptor;
@@ -37,9 +35,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
private JetType thisType; private JetType thisType;
public WritableScopeImpl(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner, @NotNull ErrorHandler errorHandler) { public WritableScopeImpl(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner, @NotNull ErrorHandler errorHandler) {
super(scope); super(scope, errorHandler);
this.ownerDeclarationDescriptor = owner; this.ownerDeclarationDescriptor = owner;
this.errorHandler = errorHandler;
} }
@NotNull @NotNull
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor; import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionGroup; import org.jetbrains.jet.lang.descriptors.FunctionGroup;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
@@ -19,9 +20,12 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
@Nullable @Nullable
private List<JetScope> imports; private List<JetScope> imports;
private WritableScope currentIndividualImportScope;
protected final ErrorHandler errorHandler;
public WritableScopeWithImports(@NotNull JetScope scope) { public WritableScopeWithImports(@NotNull JetScope scope, @NotNull ErrorHandler errorHandler) {
super(scope); super(scope);
this.errorHandler = errorHandler;
} }
public WritableScopeWithImports setDebugName(@NotNull String debugName) { public WritableScopeWithImports setDebugName(@NotNull String debugName) {
@@ -41,6 +45,7 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
@Override @Override
public void importScope(@NotNull JetScope imported) { public void importScope(@NotNull JetScope imported) {
getImports().add(0, imported); getImports().add(0, imported);
currentIndividualImportScope = null;
} }
@Override @Override
@@ -89,8 +94,18 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
return null; return null;
} }
public void importClassifierAlias(@NotNull String importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor) {
if (currentIndividualImportScope == null) {
WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, getContainingDeclaration(), ErrorHandler.DO_NOTHING);
importScope(writableScope);
currentIndividualImportScope = writableScope;
}
currentIndividualImportScope.addClassifierAlias(importedClassifierName, classifierDescriptor);
}
@Override @Override
public String toString() { public String toString() {
return debugName + " for " + getContainingDeclaration(); return debugName + " for " + getContainingDeclaration();
} }
} }
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.*;
@@ -13,8 +14,8 @@ import java.util.Collection;
public class WriteThroughScope extends WritableScopeWithImports { public class WriteThroughScope extends WritableScopeWithImports {
private final WritableScope writableWorker; private final WritableScope writableWorker;
public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope) { public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope, @NotNull ErrorHandler errorHandler) {
super(outerScope); super(outerScope, errorHandler);
this.writableWorker = scope; this.writableWorker = scope;
} }
@@ -1407,9 +1407,9 @@ public class JetTypeInferrer {
else { else {
result = selectorReturnType; result = selectorReturnType;
} }
if (selectorExpression != null && result != null) { // if (selectorExpression != null && result != null) {
trace.recordExpressionType(selectorExpression, result); // trace.recordExpressionType(selectorExpression, result);
} // }
} }
} }
+1 -1
View File
@@ -43,7 +43,7 @@ fun test(l : java.util.List<Int>) {
c : java.lang.Comparable<Int>? c : java.lang.Comparable<Int>?
// Collections.sort<Integer>(new ArrayList<Integer>()) // Collections.sort<Integer>(new ArrayList<Integer>())
//new xxx.error>Class/error>() new xxx.<error>Class</error>()
} }