Imports with renaming supported for namespaces
This commit is contained in:
@@ -227,6 +227,7 @@ public class TypeHierarchyResolver {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ClassifierDescriptor classifierDescriptor = null;
|
ClassifierDescriptor classifierDescriptor = null;
|
||||||
|
NamespaceDescriptor namespaceDescriptor = null;
|
||||||
JetSimpleNameExpression referenceExpression = null;
|
JetSimpleNameExpression referenceExpression = null;
|
||||||
|
|
||||||
JetExpression importedReference = importDirective.getImportedReference();
|
JetExpression importedReference = importDirective.getImportedReference();
|
||||||
@@ -239,6 +240,7 @@ public class TypeHierarchyResolver {
|
|||||||
String referencedName = referenceExpression.getReferencedName();
|
String referencedName = referenceExpression.getReferencedName();
|
||||||
if (type != null && referencedName != null) {
|
if (type != null && referencedName != null) {
|
||||||
classifierDescriptor = type.getMemberScope().getClassifier(referencedName);
|
classifierDescriptor = type.getMemberScope().getClassifier(referencedName);
|
||||||
|
namespaceDescriptor = type.getMemberScope().getNamespace(referencedName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,15 +251,25 @@ public class TypeHierarchyResolver {
|
|||||||
String referencedName = referenceExpression.getReferencedName();
|
String referencedName = referenceExpression.getReferencedName();
|
||||||
if (referencedName != null) {
|
if (referencedName != null) {
|
||||||
classifierDescriptor = outerScope.getClassifier(referencedName);
|
classifierDescriptor = outerScope.getClassifier(referencedName);
|
||||||
|
namespaceDescriptor = outerScope.getNamespace(referencedName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String aliasName = importDirective.getAliasName();
|
||||||
if (classifierDescriptor != null) {
|
if (classifierDescriptor != null) {
|
||||||
context.getTrace().record(BindingContext.REFERENCE_TARGET, referenceExpression, classifierDescriptor);
|
context.getTrace().record(BindingContext.REFERENCE_TARGET, referenceExpression, classifierDescriptor);
|
||||||
|
|
||||||
String aliasName = importDirective.getAliasName();
|
if (aliasName != null) {
|
||||||
String importedClassifierName = aliasName != null ? aliasName : classifierDescriptor.getName();
|
namespaceScope.importClassifierAlias(aliasName, classifierDescriptor);
|
||||||
namespaceScope.importClassifierAlias(importedClassifierName, classifierDescriptor);
|
}
|
||||||
|
}
|
||||||
|
if (namespaceDescriptor != null) {
|
||||||
|
if (classifierDescriptor == null) {
|
||||||
|
context.getTrace().record(BindingContext.REFERENCE_TARGET, referenceExpression, namespaceDescriptor);
|
||||||
|
}
|
||||||
|
if (aliasName != null) {
|
||||||
|
namespaceScope.importNamespaceAlias(aliasName, namespaceDescriptor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public interface WritableScope extends JetScope {
|
|||||||
|
|
||||||
void addClassifierAlias(@NotNull String name, @NotNull ClassifierDescriptor classifierDescriptor);
|
void addClassifierAlias(@NotNull String name, @NotNull ClassifierDescriptor classifierDescriptor);
|
||||||
|
|
||||||
|
void addNamespaceAlias(@NotNull String name, @NotNull NamespaceDescriptor namespaceDescriptor);
|
||||||
|
|
||||||
void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor);
|
void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
super.importClassifierAlias(importedClassifierName, classifierDescriptor);
|
super.importClassifierAlias(importedClassifierName, classifierDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void importNamespaceAlias(String aliasName, NamespaceDescriptor namespaceDescriptor) {
|
||||||
|
allDescriptors.add(namespaceDescriptor);
|
||||||
|
super.importNamespaceAlias(aliasName, namespaceDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||||
@@ -189,13 +195,23 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addClassifierAlias(@NotNull String name, @NotNull ClassifierDescriptor classifierDescriptor) {
|
public void addClassifierAlias(@NotNull String name, @NotNull ClassifierDescriptor classifierDescriptor) {
|
||||||
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
checkForRedeclaration(name, classifierDescriptor);
|
||||||
DeclarationDescriptor originalDescriptor = variableClassOrNamespaceDescriptors.get(name);
|
getVariableClassOrNamespaceDescriptors().put(name, classifierDescriptor);
|
||||||
|
allDescriptors.add(classifierDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addNamespaceAlias(@NotNull String name, @NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||||
|
checkForRedeclaration(name, namespaceDescriptor);
|
||||||
|
getVariableClassOrNamespaceDescriptors().put(name, namespaceDescriptor);
|
||||||
|
allDescriptors.add(namespaceDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkForRedeclaration(String name, DeclarationDescriptor classifierDescriptor) {
|
||||||
|
DeclarationDescriptor originalDescriptor = getVariableClassOrNamespaceDescriptors().get(name);
|
||||||
if (originalDescriptor != null) {
|
if (originalDescriptor != null) {
|
||||||
redeclarationHandler.handleRedeclaration(originalDescriptor, classifierDescriptor);
|
redeclarationHandler.handleRedeclaration(originalDescriptor, classifierDescriptor);
|
||||||
}
|
}
|
||||||
variableClassOrNamespaceDescriptors.put(name, classifierDescriptor);
|
|
||||||
allDescriptors.add(classifierDescriptor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+11
-2
@@ -97,15 +97,24 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void importClassifierAlias(@NotNull String importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor) {
|
private WritableScope getCurrentIndividualImportScope() {
|
||||||
if (currentIndividualImportScope == null) {
|
if (currentIndividualImportScope == null) {
|
||||||
WritableScopeImpl writableScope = new WritableScopeImpl(EMPTY, getContainingDeclaration(), RedeclarationHandler.DO_NOTHING).setDebugName("Individual import scope");
|
WritableScopeImpl writableScope = new WritableScopeImpl(EMPTY, getContainingDeclaration(), RedeclarationHandler.DO_NOTHING).setDebugName("Individual import scope");
|
||||||
importScope(writableScope);
|
importScope(writableScope);
|
||||||
currentIndividualImportScope = writableScope;
|
currentIndividualImportScope = writableScope;
|
||||||
}
|
}
|
||||||
currentIndividualImportScope.addClassifierAlias(importedClassifierName, classifierDescriptor);
|
return currentIndividualImportScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void importClassifierAlias(@NotNull String importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor) {
|
||||||
|
getCurrentIndividualImportScope().addClassifierAlias(importedClassifierName, classifierDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void importNamespaceAlias(String aliasName, NamespaceDescriptor namespaceDescriptor) {
|
||||||
|
getCurrentIndividualImportScope().addNamespaceAlias(aliasName, namespaceDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getSimpleName() + "@" + Integer.toHexString(System.identityHashCode(this)) + " " + debugName + " for " + getContainingDeclaration();
|
return getClass().getSimpleName() + "@" + Integer.toHexString(System.identityHashCode(this)) + " " + debugName + " for " + getContainingDeclaration();
|
||||||
|
|||||||
@@ -126,6 +126,11 @@ public class WriteThroughScope extends WritableScopeWithImports {
|
|||||||
writableWorker.addClassifierAlias(name, classifierDescriptor);
|
writableWorker.addClassifierAlias(name, classifierDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addNamespaceAlias(@NotNull String name, @NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||||
|
writableWorker.addNamespaceAlias(name, namespaceDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||||
writableWorker.addNamespace(namespaceDescriptor);
|
writableWorker.addNamespace(namespaceDescriptor);
|
||||||
|
|||||||
Reference in New Issue
Block a user