Name imports fixed
This commit is contained in:
@@ -99,7 +99,6 @@ public class TopDownAnalyzer {
|
||||
declaration.accept(new JetVisitor() {
|
||||
@Override
|
||||
public void visitNamespace(JetNamespace namespace) {
|
||||
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
|
||||
|
||||
String name = namespace.getName();
|
||||
if (name == null) {
|
||||
@@ -118,57 +117,10 @@ public class TopDownAnalyzer {
|
||||
}
|
||||
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);
|
||||
|
||||
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 {
|
||||
ClassifierDescriptor classifierDescriptor = null;
|
||||
JetSimpleNameExpression referenceExpression = null;
|
||||
|
||||
JetExpression importedReference = importDirective.getImportedReference();
|
||||
if (importedReference instanceof JetDotQualifiedExpression) {
|
||||
JetDotQualifiedExpression reference = (JetDotQualifiedExpression) importedReference;
|
||||
JetType type = semanticServices.getTypeInferrer(trace, JetFlowInformationProvider.THROW_EXCEPTION).getTypeWithNamespaces(namespaceScope, reference.getReceiverExpression(), false);
|
||||
JetExpression selectorExpression = reference.getSelectorExpression();
|
||||
if (selectorExpression != null) {
|
||||
referenceExpression = (JetSimpleNameExpression) selectorExpression;
|
||||
String referencedName = referenceExpression.getReferencedName();
|
||||
if (type != null && referencedName != null) {
|
||||
classifierDescriptor = type.getMemberScope().getClassifier(referencedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
assert importedReference instanceof JetSimpleNameExpression;
|
||||
referenceExpression = (JetSimpleNameExpression) importedReference;
|
||||
|
||||
String referencedName = referenceExpression.getReferencedName();
|
||||
if (referencedName != null) {
|
||||
classifierDescriptor = outerScope.getClassifier(referencedName);
|
||||
}
|
||||
}
|
||||
|
||||
if (classifierDescriptor != null) {
|
||||
trace.recordReferenceResolution(referenceExpression, classifierDescriptor);
|
||||
|
||||
String aliasName = importDirective.getAliasName();
|
||||
String importedClassifierName = aliasName != null ? aliasName : classifierDescriptor.getName();
|
||||
namespaceScope.addClassifierAlias(importedClassifierName, classifierDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
processImports(namespace, namespaceScope, outerScope);
|
||||
|
||||
collectNamespacesAndClassifiers(namespaceScope, namespaceDescriptor, namespace.getDeclarations());
|
||||
}
|
||||
@@ -200,6 +152,58 @@ public class TopDownAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
private void processImports(@NotNull JetNamespace namespace, @NotNull WriteThroughScope namespaceScope, @NotNull JetScope outerScope) {
|
||||
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
|
||||
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 {
|
||||
ClassifierDescriptor classifierDescriptor = null;
|
||||
JetSimpleNameExpression referenceExpression = null;
|
||||
|
||||
JetExpression importedReference = importDirective.getImportedReference();
|
||||
if (importedReference instanceof JetDotQualifiedExpression) {
|
||||
JetDotQualifiedExpression reference = (JetDotQualifiedExpression) importedReference;
|
||||
JetType type = semanticServices.getTypeInferrer(trace, JetFlowInformationProvider.THROW_EXCEPTION).getTypeWithNamespaces(namespaceScope, reference.getReceiverExpression(), false);
|
||||
JetExpression selectorExpression = reference.getSelectorExpression();
|
||||
if (selectorExpression != null) {
|
||||
referenceExpression = (JetSimpleNameExpression) selectorExpression;
|
||||
String referencedName = referenceExpression.getReferencedName();
|
||||
if (type != null && referencedName != null) {
|
||||
classifierDescriptor = type.getMemberScope().getClassifier(referencedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
assert importedReference instanceof JetSimpleNameExpression;
|
||||
referenceExpression = (JetSimpleNameExpression) importedReference;
|
||||
|
||||
String referencedName = referenceExpression.getReferencedName();
|
||||
if (referencedName != null) {
|
||||
classifierDescriptor = outerScope.getClassifier(referencedName);
|
||||
}
|
||||
}
|
||||
|
||||
if (classifierDescriptor != null) {
|
||||
trace.recordReferenceResolution(referenceExpression, classifierDescriptor);
|
||||
|
||||
String aliasName = importDirective.getAliasName();
|
||||
String importedClassifierName = aliasName != null ? aliasName : classifierDescriptor.getName();
|
||||
namespaceScope.importClassifierAlias(importedClassifierName, classifierDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createTypeConstructors() {
|
||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : classes.entrySet()) {
|
||||
JetClass jetClass = entry.getKey();
|
||||
|
||||
@@ -13,8 +13,6 @@ import java.util.*;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
@NotNull
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@NotNull
|
||||
private final DeclarationDescriptor ownerDeclarationDescriptor;
|
||||
@@ -37,9 +35,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
private JetType thisType;
|
||||
|
||||
public WritableScopeImpl(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner, @NotNull ErrorHandler errorHandler) {
|
||||
super(scope);
|
||||
super(scope, errorHandler);
|
||||
this.ownerDeclarationDescriptor = owner;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionGroup;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
@@ -19,9 +20,12 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
||||
|
||||
@Nullable
|
||||
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);
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
public WritableScopeWithImports setDebugName(@NotNull String debugName) {
|
||||
@@ -41,6 +45,7 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
||||
@Override
|
||||
public void importScope(@NotNull JetScope imported) {
|
||||
getImports().add(0, imported);
|
||||
currentIndividualImportScope = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,8 +94,18 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
||||
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
|
||||
public String toString() {
|
||||
return debugName + " for " + getContainingDeclaration();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
|
||||
@@ -13,8 +14,8 @@ import java.util.Collection;
|
||||
public class WriteThroughScope extends WritableScopeWithImports {
|
||||
private final WritableScope writableWorker;
|
||||
|
||||
public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope) {
|
||||
super(outerScope);
|
||||
public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope, @NotNull ErrorHandler errorHandler) {
|
||||
super(outerScope, errorHandler);
|
||||
this.writableWorker = scope;
|
||||
}
|
||||
|
||||
|
||||
@@ -1407,9 +1407,9 @@ public class JetTypeInferrer {
|
||||
else {
|
||||
result = selectorReturnType;
|
||||
}
|
||||
if (selectorExpression != null && result != null) {
|
||||
trace.recordExpressionType(selectorExpression, result);
|
||||
}
|
||||
// if (selectorExpression != null && result != null) {
|
||||
// trace.recordExpressionType(selectorExpression, result);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ fun test(l : java.util.List<Int>) {
|
||||
c : java.lang.Comparable<Int>?
|
||||
|
||||
// Collections.sort<Integer>(new ArrayList<Integer>())
|
||||
//new xxx.error>Class/error>()
|
||||
new xxx.<error>Class</error>()
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user