Qualified this resolved correctly
This commit is contained in:
@@ -30,10 +30,9 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
|
||||
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope) {
|
||||
super(containingDeclaration);
|
||||
this.scopeForMemberLookup = new WritableScopeImpl(JetScope.EMPTY, this, trace.getErrorHandler());
|
||||
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, trace.getErrorHandler());
|
||||
this.scopeForMemberResolution = new WritableScopeImpl(scopeForMemberLookup, this, trace.getErrorHandler());
|
||||
scopeForMemberResolution.importScope(scopeForSupertypeResolution);
|
||||
this.scopeForMemberLookup = new WritableScopeImpl(JetScope.EMPTY, this, trace.getErrorHandler()).setDebugName("MemberLookup");
|
||||
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, trace.getErrorHandler()).setDebugName("SupertypeResolution");
|
||||
this.scopeForMemberResolution = new WritableScopeImpl(new ChainedScope(this, scopeForMemberLookup, scopeForSupertypeResolution), this, trace.getErrorHandler()).setDebugName("MemberResolution");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class ChainedScope implements JetScope {
|
||||
private final DeclarationDescriptor containingDeclaration;
|
||||
private final JetScope[] scopeChain;
|
||||
|
||||
public ChainedScope(DeclarationDescriptor containingDeclaration, JetScope... scopes) {
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
scopeChain = scopes.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||
for (JetScope scope : scopeChain) {
|
||||
ClassifierDescriptor classifier = scope.getClassifier(name);
|
||||
if (classifier != null) return classifier;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||
for (JetScope jetScope : scopeChain) {
|
||||
NamespaceDescriptor namespace = jetScope.getNamespace(name);
|
||||
if (namespace != null) {
|
||||
return namespace;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VariableDescriptor getVariable(@NotNull String name) {
|
||||
for (JetScope jetScope : scopeChain) {
|
||||
VariableDescriptor variable = jetScope.getVariable(name);
|
||||
if (variable != null) {
|
||||
return variable;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
for (JetScope jetScope : scopeChain) {
|
||||
FunctionGroup functionGroup = jetScope.getFunctionGroup(name);
|
||||
if (!functionGroup.isEmpty()) return functionGroup;
|
||||
}
|
||||
return FunctionGroup.EMPTY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return containingDeclaration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(String labelName) {
|
||||
for (JetScope jetScope : scopeChain) {
|
||||
Collection<DeclarationDescriptor> declarationsByLabel = jetScope.getDeclarationsByLabel(labelName);
|
||||
if (!declarationsByLabel.isEmpty()) return declarationsByLabel; // TODO : merge?
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
|
||||
for (JetScope jetScope : scopeChain) {
|
||||
PropertyDescriptor propertyByFieldReference = jetScope.getPropertyByFieldReference(fieldName);
|
||||
if (propertyByFieldReference != null) {
|
||||
return propertyByFieldReference;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -59,8 +59,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull String labelName) {
|
||||
Map<String, List<DeclarationDescriptor>> labelsToDescriptors = getLabelsToDescriptors();
|
||||
Collection<DeclarationDescriptor> superResult = super.getDeclarationsByLabel(labelName);
|
||||
Map<String, List<DeclarationDescriptor>> labelsToDescriptors = getLabelsToDescriptors();
|
||||
List<DeclarationDescriptor> declarationDescriptors = labelsToDescriptors.get(labelName);
|
||||
if (declarationDescriptors == null) {
|
||||
return superResult;
|
||||
|
||||
@@ -15,6 +15,8 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class WritableScopeWithImports extends JetScopeAdapter implements WritableScope {
|
||||
|
||||
private String debugName;
|
||||
|
||||
@Nullable
|
||||
private List<JetScope> imports;
|
||||
|
||||
@@ -22,6 +24,12 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
||||
super(scope);
|
||||
}
|
||||
|
||||
public WritableScopeWithImports setDebugName(@NotNull String debugName) {
|
||||
assert this.debugName == null : this.debugName;
|
||||
this.debugName = debugName;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected final List<JetScope> getImports() {
|
||||
if (imports == null) {
|
||||
@@ -80,4 +88,9 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return debugName + " for " + getContainingDeclaration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -938,6 +938,7 @@ public class JetTypeInferrer {
|
||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
|
||||
thisType = classDescriptor.getDefaultType();
|
||||
trace.recordReferenceResolution(expression.getTargetLabel(), classDescriptor);
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
|
||||
@@ -26,7 +26,6 @@ fun test(l : java.util.List<Int>) {
|
||||
|
||||
<error>new List<Int></error>
|
||||
|
||||
// Collections.sort<Integer>(new ArrayList<Integer>())
|
||||
|
||||
val o = "sdf" <warning>as</warning> Object
|
||||
|
||||
@@ -42,4 +41,12 @@ fun test(l : java.util.List<Int>) {
|
||||
val c : Com<Int>? = null
|
||||
|
||||
c : java.lang.Comparable<Int>?
|
||||
|
||||
// Collections.sort<Integer>(new ArrayList<Integer>())
|
||||
//new xxx.error>Class/error>()
|
||||
}
|
||||
|
||||
|
||||
namespace xxx {
|
||||
import java.lang.Class;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
namespace qualified_this {
|
||||
~qtA~class A(val a:Int) {
|
||||
|
||||
~qtB~class B() {
|
||||
val x = this`qtB`@B
|
||||
val y = this`qtA`@A
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class A<~T~T, ~E~E> {
|
||||
val a : `T`T
|
||||
val x : A<`T`T, `E`E>
|
||||
@@ -8,4 +19,5 @@ class A<~T~T, ~E~E> {
|
||||
|
||||
~X.E~class E {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user