objects or variables members import resolve functionality rollback
This commit is contained in:
@@ -83,6 +83,9 @@ public interface Errors {
|
||||
SimpleDiagnosticFactory LABEL_NAME_CLASH = SimpleDiagnosticFactory.create(WARNING, "There is more than one label with such a name in this scope");
|
||||
SimpleDiagnosticFactory EXPRESSION_EXPECTED_NAMESPACE_FOUND = SimpleDiagnosticFactory.create(ERROR, "Expression expected, but a namespace name found");
|
||||
|
||||
SimpleDiagnosticFactory CANNOT_IMPORT_OBJECT_MEMBERS = SimpleDiagnosticFactory.create(ERROR, "Cannot import members of object separately, use full paths or try to move members to namespace level");
|
||||
SimpleDiagnosticFactory CANNOT_IMPORT_VARIABLE_MEMBERS = SimpleDiagnosticFactory.create(ERROR, "Cannot import members of variable separately, use full paths");
|
||||
|
||||
SimpleDiagnosticFactory CANNOT_INFER_PARAMETER_TYPE = SimpleDiagnosticFactory.create(ERROR, "Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) => ...} notation");
|
||||
|
||||
SimpleDiagnosticFactory NO_BACKING_FIELD_ABSTRACT_PROPERTY = SimpleDiagnosticFactory.create(ERROR, "This property doesn't have a backing field, because it's abstract");
|
||||
|
||||
@@ -53,12 +53,15 @@ public class ImportsResolver {
|
||||
}
|
||||
|
||||
public static class ImportResolver {
|
||||
private BindingTrace trace;
|
||||
private boolean firstPhase;
|
||||
private final BindingTrace trace;
|
||||
private final boolean firstPhase;
|
||||
// flag is used not to invoke code that resolves members from objects and variables; functionality is under discuss so far, see KT-876
|
||||
private final boolean importMembersFromObjectsAndVars;
|
||||
|
||||
public ImportResolver(BindingTrace trace, boolean firstPhase) {
|
||||
this.trace = trace;
|
||||
this.firstPhase = firstPhase;
|
||||
this.importMembersFromObjectsAndVars = false;
|
||||
}
|
||||
|
||||
public void processImportReference(JetImportDirective importDirective, WritableScope namespaceScope, JetScope outerScope) {
|
||||
@@ -77,6 +80,7 @@ public class ImportsResolver {
|
||||
JetScope scope = importDirective.isAllUnder() ? namespaceScope : outerScope;
|
||||
descriptors = lookupDescriptorsForSimpleNameReference((JetSimpleNameExpression) importedReference, scope);
|
||||
}
|
||||
JetSimpleNameExpression referenceExpression = getLastReference(importedReference);
|
||||
if (importDirective.isAllUnder()) {
|
||||
for (DeclarationDescriptor descriptor : descriptors) {
|
||||
if (firstPhase) {
|
||||
@@ -85,18 +89,25 @@ public class ImportsResolver {
|
||||
}
|
||||
}
|
||||
else if (descriptor instanceof VariableDescriptor) {
|
||||
if (!importMembersFromObjectsAndVars) {
|
||||
trace.report(CANNOT_IMPORT_OBJECT_MEMBERS.on(referenceExpression != null ? referenceExpression : importedReference));
|
||||
continue;
|
||||
}
|
||||
JetType type = ((VariableDescriptor) descriptor).getOutType();
|
||||
if (type != null) {
|
||||
namespaceScope.importScope(ScopeBoundToReceiver.create(descriptor, type.getMemberScope()));
|
||||
}
|
||||
}
|
||||
else if (descriptor instanceof ClassDescriptor) {
|
||||
if (!importMembersFromObjectsAndVars) {
|
||||
trace.report(CANNOT_IMPORT_VARIABLE_MEMBERS.on(referenceExpression != null ? referenceExpression : importedReference));
|
||||
continue;
|
||||
}
|
||||
namespaceScope.importScope(ScopeBoundToReceiver.create(descriptor, ((ClassDescriptor) descriptor).getDefaultType().getMemberScope()));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
JetSimpleNameExpression referenceExpression = getLastReference(importedReference);
|
||||
|
||||
String aliasName = importDirective.getAliasName();
|
||||
if (aliasName == null) {
|
||||
@@ -149,10 +160,10 @@ public class ImportsResolver {
|
||||
assert receiverExpression instanceof JetSimpleNameExpression;
|
||||
declarationDescriptors = lookupDescriptorsForSimpleNameReference((JetSimpleNameExpression) receiverExpression, outerScope);
|
||||
}
|
||||
JetExpression selectorExpression = importedReference.getSelectorExpression();
|
||||
assert selectorExpression instanceof JetSimpleNameExpression;
|
||||
JetSimpleNameExpression selector = (JetSimpleNameExpression) selectorExpression;
|
||||
for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
|
||||
JetExpression selectorExpression = importedReference.getSelectorExpression();
|
||||
assert selectorExpression instanceof JetSimpleNameExpression;
|
||||
JetSimpleNameExpression selector = (JetSimpleNameExpression) selectorExpression;
|
||||
if (declarationDescriptor instanceof NamespaceDescriptor) {
|
||||
return lookupDescriptorsForSimpleNameReference(selector, ((NamespaceDescriptor) declarationDescriptor).getMemberScope());
|
||||
}
|
||||
@@ -177,7 +188,12 @@ public class ImportsResolver {
|
||||
trace.report(NO_CLASS_OBJECT.on(classReference, classDescriptor));
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return addBoundToReceiver(lookupDescriptorsForSimpleNameReference(memberReference, classObjectType.getMemberScope()), classDescriptor);
|
||||
Collection<DeclarationDescriptor> members = lookupDescriptorsForSimpleNameReference(memberReference, classObjectType.getMemberScope());
|
||||
if (!importMembersFromObjectsAndVars) {
|
||||
trace.report(CANNOT_IMPORT_OBJECT_MEMBERS.on(memberReference));
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return addBoundToReceiver(members, classDescriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -186,7 +202,12 @@ public class ImportsResolver {
|
||||
|
||||
JetType variableType = variableDescriptor.getReturnType();
|
||||
if (variableType == null) return Collections.emptyList();
|
||||
return addBoundToReceiver(lookupDescriptorsForSimpleNameReference(memberReference, variableType.getMemberScope()), variableDescriptor);
|
||||
Collection<DeclarationDescriptor> members = lookupDescriptorsForSimpleNameReference(memberReference, variableType.getMemberScope());
|
||||
if (!importMembersFromObjectsAndVars) {
|
||||
trace.report(CANNOT_IMPORT_VARIABLE_MEMBERS.on(memberReference));
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return addBoundToReceiver(members, variableDescriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -5,22 +5,23 @@ import b.B //class
|
||||
import b.foo //function
|
||||
import b.ext //extension function
|
||||
import b.value //property
|
||||
import b.C.bar //function from class object
|
||||
import b.C.cValue //property from class object
|
||||
import b.constant.fff //function from val
|
||||
import b.constant.dValue //property from val
|
||||
import b.E.f //val from class object
|
||||
import b.C.<!CANNOT_IMPORT_OBJECT_MEMBERS!>bar<!> //function from class object
|
||||
import b.C.<!CANNOT_IMPORT_OBJECT_MEMBERS!>cValue<!> //property from class object
|
||||
import b.constant.<!CANNOT_IMPORT_VARIABLE_MEMBERS!>fff<!> //function from val
|
||||
import b.constant.<!CANNOT_IMPORT_VARIABLE_MEMBERS!>dValue<!> //property from val
|
||||
import b.E.<!CANNOT_IMPORT_OBJECT_MEMBERS!>f<!> //val from class object
|
||||
import <!UNRESOLVED_REFERENCE!>smth<!>.illegal
|
||||
|
||||
fun test(arg: B) {
|
||||
foo(value)
|
||||
arg.ext()
|
||||
|
||||
bar()
|
||||
foo(cValue)
|
||||
<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||
foo(<!UNRESOLVED_REFERENCE!>cValue<!>)
|
||||
|
||||
fff(dValue)
|
||||
<!UNRESOLVED_REFERENCE!>fff<!>(<!UNRESOLVED_REFERENCE!>dValue<!>)
|
||||
|
||||
f.f()
|
||||
<!UNRESOLVED_REFERENCE!>f<!>.f()
|
||||
}
|
||||
|
||||
// FILE:b.kt
|
||||
@@ -61,14 +62,14 @@ class F() {
|
||||
//FILE:c.kt
|
||||
package c
|
||||
|
||||
import C.*
|
||||
import <!CANNOT_IMPORT_OBJECT_MEMBERS!>C<!>.*
|
||||
|
||||
object C {
|
||||
fun a() {
|
||||
fun f() {
|
||||
}
|
||||
val b = 3
|
||||
val i = 3
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
if (b == 3) a()
|
||||
if (<!UNRESOLVED_REFERENCE!>i<!> == 3) <!UNRESOLVED_REFERENCE!>f<!>()
|
||||
}
|
||||
Reference in New Issue
Block a user