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 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 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 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");
|
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 {
|
public static class ImportResolver {
|
||||||
private BindingTrace trace;
|
private final BindingTrace trace;
|
||||||
private boolean firstPhase;
|
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) {
|
public ImportResolver(BindingTrace trace, boolean firstPhase) {
|
||||||
this.trace = trace;
|
this.trace = trace;
|
||||||
this.firstPhase = firstPhase;
|
this.firstPhase = firstPhase;
|
||||||
|
this.importMembersFromObjectsAndVars = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processImportReference(JetImportDirective importDirective, WritableScope namespaceScope, JetScope outerScope) {
|
public void processImportReference(JetImportDirective importDirective, WritableScope namespaceScope, JetScope outerScope) {
|
||||||
@@ -77,6 +80,7 @@ public class ImportsResolver {
|
|||||||
JetScope scope = importDirective.isAllUnder() ? namespaceScope : outerScope;
|
JetScope scope = importDirective.isAllUnder() ? namespaceScope : outerScope;
|
||||||
descriptors = lookupDescriptorsForSimpleNameReference((JetSimpleNameExpression) importedReference, scope);
|
descriptors = lookupDescriptorsForSimpleNameReference((JetSimpleNameExpression) importedReference, scope);
|
||||||
}
|
}
|
||||||
|
JetSimpleNameExpression referenceExpression = getLastReference(importedReference);
|
||||||
if (importDirective.isAllUnder()) {
|
if (importDirective.isAllUnder()) {
|
||||||
for (DeclarationDescriptor descriptor : descriptors) {
|
for (DeclarationDescriptor descriptor : descriptors) {
|
||||||
if (firstPhase) {
|
if (firstPhase) {
|
||||||
@@ -85,18 +89,25 @@ public class ImportsResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof VariableDescriptor) {
|
else if (descriptor instanceof VariableDescriptor) {
|
||||||
|
if (!importMembersFromObjectsAndVars) {
|
||||||
|
trace.report(CANNOT_IMPORT_OBJECT_MEMBERS.on(referenceExpression != null ? referenceExpression : importedReference));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
JetType type = ((VariableDescriptor) descriptor).getOutType();
|
JetType type = ((VariableDescriptor) descriptor).getOutType();
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
namespaceScope.importScope(ScopeBoundToReceiver.create(descriptor, type.getMemberScope()));
|
namespaceScope.importScope(ScopeBoundToReceiver.create(descriptor, type.getMemberScope()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof ClassDescriptor) {
|
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()));
|
namespaceScope.importScope(ScopeBoundToReceiver.create(descriptor, ((ClassDescriptor) descriptor).getDefaultType().getMemberScope()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JetSimpleNameExpression referenceExpression = getLastReference(importedReference);
|
|
||||||
|
|
||||||
String aliasName = importDirective.getAliasName();
|
String aliasName = importDirective.getAliasName();
|
||||||
if (aliasName == null) {
|
if (aliasName == null) {
|
||||||
@@ -149,10 +160,10 @@ public class ImportsResolver {
|
|||||||
assert receiverExpression instanceof JetSimpleNameExpression;
|
assert receiverExpression instanceof JetSimpleNameExpression;
|
||||||
declarationDescriptors = lookupDescriptorsForSimpleNameReference((JetSimpleNameExpression) receiverExpression, outerScope);
|
declarationDescriptors = lookupDescriptorsForSimpleNameReference((JetSimpleNameExpression) receiverExpression, outerScope);
|
||||||
}
|
}
|
||||||
|
JetExpression selectorExpression = importedReference.getSelectorExpression();
|
||||||
|
assert selectorExpression instanceof JetSimpleNameExpression;
|
||||||
|
JetSimpleNameExpression selector = (JetSimpleNameExpression) selectorExpression;
|
||||||
for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
|
for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
|
||||||
JetExpression selectorExpression = importedReference.getSelectorExpression();
|
|
||||||
assert selectorExpression instanceof JetSimpleNameExpression;
|
|
||||||
JetSimpleNameExpression selector = (JetSimpleNameExpression) selectorExpression;
|
|
||||||
if (declarationDescriptor instanceof NamespaceDescriptor) {
|
if (declarationDescriptor instanceof NamespaceDescriptor) {
|
||||||
return lookupDescriptorsForSimpleNameReference(selector, ((NamespaceDescriptor) declarationDescriptor).getMemberScope());
|
return lookupDescriptorsForSimpleNameReference(selector, ((NamespaceDescriptor) declarationDescriptor).getMemberScope());
|
||||||
}
|
}
|
||||||
@@ -177,7 +188,12 @@ public class ImportsResolver {
|
|||||||
trace.report(NO_CLASS_OBJECT.on(classReference, classDescriptor));
|
trace.report(NO_CLASS_OBJECT.on(classReference, classDescriptor));
|
||||||
return Collections.emptyList();
|
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
|
@NotNull
|
||||||
@@ -186,7 +202,12 @@ public class ImportsResolver {
|
|||||||
|
|
||||||
JetType variableType = variableDescriptor.getReturnType();
|
JetType variableType = variableDescriptor.getReturnType();
|
||||||
if (variableType == null) return Collections.emptyList();
|
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
|
@NotNull
|
||||||
|
|||||||
@@ -5,22 +5,23 @@ import b.B //class
|
|||||||
import b.foo //function
|
import b.foo //function
|
||||||
import b.ext //extension function
|
import b.ext //extension function
|
||||||
import b.value //property
|
import b.value //property
|
||||||
import b.C.bar //function from class object
|
import b.C.<!CANNOT_IMPORT_OBJECT_MEMBERS!>bar<!> //function from class object
|
||||||
import b.C.cValue //property from class object
|
import b.C.<!CANNOT_IMPORT_OBJECT_MEMBERS!>cValue<!> //property from class object
|
||||||
import b.constant.fff //function from val
|
import b.constant.<!CANNOT_IMPORT_VARIABLE_MEMBERS!>fff<!> //function from val
|
||||||
import b.constant.dValue //property from val
|
import b.constant.<!CANNOT_IMPORT_VARIABLE_MEMBERS!>dValue<!> //property from val
|
||||||
import b.E.f //val from class object
|
import b.E.<!CANNOT_IMPORT_OBJECT_MEMBERS!>f<!> //val from class object
|
||||||
|
import <!UNRESOLVED_REFERENCE!>smth<!>.illegal
|
||||||
|
|
||||||
fun test(arg: B) {
|
fun test(arg: B) {
|
||||||
foo(value)
|
foo(value)
|
||||||
arg.ext()
|
arg.ext()
|
||||||
|
|
||||||
bar()
|
<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||||
foo(cValue)
|
foo(<!UNRESOLVED_REFERENCE!>cValue<!>)
|
||||||
|
|
||||||
fff(dValue)
|
<!UNRESOLVED_REFERENCE!>fff<!>(<!UNRESOLVED_REFERENCE!>dValue<!>)
|
||||||
|
|
||||||
f.f()
|
<!UNRESOLVED_REFERENCE!>f<!>.f()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FILE:b.kt
|
// FILE:b.kt
|
||||||
@@ -61,14 +62,14 @@ class F() {
|
|||||||
//FILE:c.kt
|
//FILE:c.kt
|
||||||
package c
|
package c
|
||||||
|
|
||||||
import C.*
|
import <!CANNOT_IMPORT_OBJECT_MEMBERS!>C<!>.*
|
||||||
|
|
||||||
object C {
|
object C {
|
||||||
fun a() {
|
fun f() {
|
||||||
}
|
}
|
||||||
val b = 3
|
val i = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
fun foo() {
|
fun foo() {
|
||||||
if (b == 3) a()
|
if (<!UNRESOLVED_REFERENCE!>i<!> == 3) <!UNRESOLVED_REFERENCE!>f<!>()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user