Merge branch 'master' of git+ssh://git.labs.intellij.net/jet
This commit is contained in:
@@ -220,26 +220,29 @@ public abstract class CodegenContext {
|
|||||||
else if(descriptor instanceof PropertyDescriptor) {
|
else if(descriptor instanceof PropertyDescriptor) {
|
||||||
PropertyDescriptor pd = (PropertyDescriptor) descriptor;
|
PropertyDescriptor pd = (PropertyDescriptor) descriptor;
|
||||||
PropertyDescriptor myAccessor = new PropertyDescriptor(contextType,
|
PropertyDescriptor myAccessor = new PropertyDescriptor(contextType,
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
pd.getModality(),
|
pd.getModality(),
|
||||||
pd.getVisibility(),
|
pd.getVisibility(),
|
||||||
pd.isVar(),
|
pd.isVar(),
|
||||||
pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null,
|
pd.getExpectedThisObject(),
|
||||||
pd.getExpectedThisObject(),
|
pd.getName() + "$bridge$" + accessors.size()
|
||||||
pd.getName() + "$bridge$" + accessors.size(),
|
);
|
||||||
pd.getInType(),
|
JetType receiverType = pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null;
|
||||||
pd.getOutType());
|
myAccessor.setType(pd.getInType(), pd.getOutType(), Collections.<TypeParameterDescriptor>emptyList(), receiverType);
|
||||||
|
|
||||||
PropertyGetterDescriptor pgd = new PropertyGetterDescriptor(
|
PropertyGetterDescriptor pgd = new PropertyGetterDescriptor(
|
||||||
myAccessor, Collections.<AnnotationDescriptor>emptyList(), myAccessor.getModality(),
|
myAccessor, Collections.<AnnotationDescriptor>emptyList(), myAccessor.getModality(),
|
||||||
myAccessor.getVisibility(),
|
myAccessor.getVisibility(),
|
||||||
myAccessor.getOutType(), false, false);
|
false, false);
|
||||||
|
pgd.initialize(myAccessor.getOutType());
|
||||||
|
|
||||||
PropertySetterDescriptor psd = new PropertySetterDescriptor(
|
PropertySetterDescriptor psd = new PropertySetterDescriptor(
|
||||||
myAccessor.getModality(),
|
myAccessor.getModality(),
|
||||||
myAccessor.getVisibility(),
|
myAccessor.getVisibility(),
|
||||||
myAccessor,
|
myAccessor,
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
false, false);
|
false, false);
|
||||||
myAccessor.initialize(Collections.<TypeParameterDescriptor>emptyList(), pgd, psd);
|
myAccessor.initialize(pgd, psd);
|
||||||
accessor = myAccessor;
|
accessor = myAccessor;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public class FunctionDescriptorUtil {
|
|||||||
parameterScope.addVariableDescriptor(valueParameterDescriptor);
|
parameterScope.addVariableDescriptor(valueParameterDescriptor);
|
||||||
}
|
}
|
||||||
parameterScope.addLabeledDeclaration(descriptor);
|
parameterScope.addLabeledDeclaration(descriptor);
|
||||||
|
parameterScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
return parameterScope;
|
return parameterScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+69
-3
@@ -5,10 +5,13 @@ import com.google.common.collect.Sets;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||||
import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter;
|
import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
import org.jetbrains.jet.lang.resolve.TraceBasedRedeclarationHandler;
|
import org.jetbrains.jet.lang.resolve.TraceBasedRedeclarationHandler;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||||
@@ -34,10 +37,16 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
|||||||
private Modality modality;
|
private Modality modality;
|
||||||
private Visibility visibility;
|
private Visibility visibility;
|
||||||
private TypeConstructor typeConstructor;
|
private TypeConstructor typeConstructor;
|
||||||
|
private final RedeclarationHandler redeclarationHandler;
|
||||||
private final WritableScope scopeForMemberResolution;
|
private final WritableScope scopeForMemberResolution;
|
||||||
private final WritableScope scopeForMemberLookup;
|
private final WritableScope scopeForMemberLookup;
|
||||||
// This scope contains type parameters but does not contain inner classes
|
// This scope contains type parameters but does not contain inner classes
|
||||||
private final WritableScope scopeForSupertypeResolution;
|
private final WritableScope scopeForSupertypeResolution;
|
||||||
|
private final WritableScope scopeForAnyConstructor;
|
||||||
|
private final Map<ConstructorDescriptor, WritableScope> scopesForConstructors;
|
||||||
|
// for primary constructor and property initializers
|
||||||
|
private final WritableScope scopeForPrimaryConstructor;
|
||||||
|
|
||||||
private MutableClassDescriptor classObjectDescriptor;
|
private MutableClassDescriptor classObjectDescriptor;
|
||||||
private JetType classObjectType;
|
private JetType classObjectType;
|
||||||
private JetType defaultType;
|
private JetType defaultType;
|
||||||
@@ -48,9 +57,18 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
|||||||
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope, ClassKind kind) {
|
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope, ClassKind kind) {
|
||||||
super(containingDeclaration);
|
super(containingDeclaration);
|
||||||
TraceBasedRedeclarationHandler redeclarationHandler = new TraceBasedRedeclarationHandler(trace);
|
TraceBasedRedeclarationHandler redeclarationHandler = new TraceBasedRedeclarationHandler(trace);
|
||||||
|
this.redeclarationHandler = redeclarationHandler;
|
||||||
this.scopeForMemberLookup = new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler).setDebugName("MemberLookup");
|
this.scopeForMemberLookup = new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler).setDebugName("MemberLookup");
|
||||||
|
this.scopeForMemberLookup.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler).setDebugName("SupertypeResolution");
|
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler).setDebugName("SupertypeResolution");
|
||||||
|
this.scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, redeclarationHandler).setDebugName("MemberResolution");
|
this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, redeclarationHandler).setDebugName("MemberResolution");
|
||||||
|
this.scopeForMemberResolution.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
|
this.scopeForAnyConstructor = new WritableScopeImpl(scopeForMemberResolution, this, redeclarationHandler).setDebugName("AnyConstrutor");
|
||||||
|
this.scopeForAnyConstructor.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
|
this.scopeForPrimaryConstructor = new WritableScopeImpl(scopeForAnyConstructor, this, redeclarationHandler).setDebugName("PrimaryConstructor");
|
||||||
|
this.scopeForPrimaryConstructor.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
|
this.scopesForConstructors = new HashMap<ConstructorDescriptor, WritableScope>();
|
||||||
this.kind = kind;
|
this.kind = kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,10 +118,10 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
|||||||
return classObjectDescriptor;
|
return classObjectDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrimaryConstructor(@NotNull ConstructorDescriptor constructorDescriptor) {
|
public void setPrimaryConstructor(@NotNull ConstructorDescriptor constructorDescriptor, BindingTrace trace) {
|
||||||
assert this.primaryConstructor == null : "Primary constructor assigned twice " + this;
|
assert this.primaryConstructor == null : "Primary constructor assigned twice " + this;
|
||||||
this.primaryConstructor = constructorDescriptor;
|
this.primaryConstructor = constructorDescriptor;
|
||||||
addConstructor(constructorDescriptor);
|
addConstructor(constructorDescriptor, trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -112,7 +130,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
|||||||
return primaryConstructor;
|
return primaryConstructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addConstructor(@NotNull ConstructorDescriptor constructorDescriptor) {
|
public void addConstructor(@NotNull ConstructorDescriptor constructorDescriptor, BindingTrace trace) {
|
||||||
assert constructorDescriptor.getContainingDeclaration() == this;
|
assert constructorDescriptor.getContainingDeclaration() == this;
|
||||||
// assert constructorDescriptor.getTypeParameters().size() == getTypeConstructor().getValueParameters().size();
|
// assert constructorDescriptor.getTypeParameters().size() == getTypeConstructor().getValueParameters().size();
|
||||||
constructors.add(constructorDescriptor);
|
constructors.add(constructorDescriptor);
|
||||||
@@ -120,6 +138,26 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
|||||||
// constructorDescriptor.getTypeParameters().addAll(typeParameters);
|
// constructorDescriptor.getTypeParameters().addAll(typeParameters);
|
||||||
((ConstructorDescriptorImpl) constructorDescriptor).setReturnType(getDefaultType());
|
((ConstructorDescriptorImpl) constructorDescriptor).setReturnType(getDefaultType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WritableScope scope = constructorDescriptor.isPrimary() ?
|
||||||
|
scopeForPrimaryConstructor :
|
||||||
|
new WritableScopeImpl(scopeForAnyConstructor, this, redeclarationHandler).setDebugName("SecondaryConstructor");
|
||||||
|
|
||||||
|
WritableScope old = scopesForConstructors.put(constructorDescriptor, scope);
|
||||||
|
if (old != null) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ValueParameterDescriptor valueParameterDescriptor : constructorDescriptor.getValueParameters()) {
|
||||||
|
JetParameter parameter = (JetParameter) trace.getBindingContext().get(BindingContext.DESCRIPTOR_TO_DECLARATION, valueParameterDescriptor);
|
||||||
|
if (parameter.getValOrVarNode() == null || !constructorDescriptor.isPrimary()) {
|
||||||
|
scope.addVariableDescriptor(valueParameterDescriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scope.addLabeledDeclaration(constructorDescriptor); // TODO : Labels for constructors?!
|
||||||
|
|
||||||
|
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -128,6 +166,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
|||||||
callableMembers.add(propertyDescriptor);
|
callableMembers.add(propertyDescriptor);
|
||||||
scopeForMemberLookup.addVariableDescriptor(propertyDescriptor);
|
scopeForMemberLookup.addVariableDescriptor(propertyDescriptor);
|
||||||
scopeForMemberResolution.addVariableDescriptor(propertyDescriptor);
|
scopeForMemberResolution.addVariableDescriptor(propertyDescriptor);
|
||||||
|
scopeForAnyConstructor.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -180,6 +219,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
|||||||
this.typeParameters.add(typeParameterDescriptor);
|
this.typeParameters.add(typeParameterDescriptor);
|
||||||
scopeForSupertypeResolution.addTypeParameterDescriptor(typeParameterDescriptor);
|
scopeForSupertypeResolution.addTypeParameterDescriptor(typeParameterDescriptor);
|
||||||
}
|
}
|
||||||
|
scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -257,6 +297,16 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
|||||||
public JetScope getScopeForMemberResolution() {
|
public JetScope getScopeForMemberResolution() {
|
||||||
return scopeForMemberResolution;
|
return scopeForMemberResolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public JetScope getScopeForConstructor(@NotNull ConstructorDescriptor constructorDescriptor) {
|
||||||
|
return scopesForConstructors.get(constructorDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public JetScope getScopeForPropertyIntiailizer() {
|
||||||
|
return scopeForPrimaryConstructor;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
@@ -344,4 +394,20 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
|||||||
}
|
}
|
||||||
return implicitReceiver;
|
return implicitReceiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void lockScopes() {
|
||||||
|
scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
scopeForMemberLookup.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
scopeForMemberResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
scopeForAnyConstructor.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
scopeForPrimaryConstructor.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
for (WritableScope scope : scopesForConstructors.values()) {
|
||||||
|
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (classObjectDescriptor != null) {
|
||||||
|
classObjectDescriptor.lockScopes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.jetbrains.jet.lang.types.JetType;
|
|||||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||||
import org.jetbrains.jet.lang.types.Variance;
|
import org.jetbrains.jet.lang.types.Variance;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -24,12 +25,13 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
|||||||
private final Modality modality;
|
private final Modality modality;
|
||||||
private final Visibility visibility;
|
private final Visibility visibility;
|
||||||
private final boolean isVar;
|
private final boolean isVar;
|
||||||
private final ReceiverDescriptor receiver;
|
|
||||||
private final ReceiverDescriptor expectedThisObject;
|
private final ReceiverDescriptor expectedThisObject;
|
||||||
private final Set<PropertyDescriptor> overriddenProperties = Sets.newLinkedHashSet();
|
private final Set<PropertyDescriptor> overriddenProperties = Sets.newLinkedHashSet();
|
||||||
private final Set<PropertyDescriptor> overridingProperties = Sets.newLinkedHashSet();
|
private final Set<PropertyDescriptor> overridingProperties = Sets.newLinkedHashSet();
|
||||||
private final List<TypeParameterDescriptor> typeParemeters = Lists.newArrayListWithCapacity(0);
|
|
||||||
private final PropertyDescriptor original;
|
private final PropertyDescriptor original;
|
||||||
|
|
||||||
|
private ReceiverDescriptor receiver;
|
||||||
|
private List<TypeParameterDescriptor> typeParemeters;
|
||||||
private PropertyGetterDescriptor getter;
|
private PropertyGetterDescriptor getter;
|
||||||
private PropertySetterDescriptor setter;
|
private PropertySetterDescriptor setter;
|
||||||
|
|
||||||
@@ -40,22 +42,28 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
|||||||
@NotNull Modality modality,
|
@NotNull Modality modality,
|
||||||
@NotNull Visibility visibility,
|
@NotNull Visibility visibility,
|
||||||
boolean isVar,
|
boolean isVar,
|
||||||
@Nullable JetType receiverType,
|
|
||||||
@NotNull ReceiverDescriptor expectedThisObject,
|
@NotNull ReceiverDescriptor expectedThisObject,
|
||||||
@NotNull String name,
|
@NotNull String name) {
|
||||||
@Nullable JetType inType,
|
super(containingDeclaration, annotations, name);
|
||||||
@NotNull JetType outType) {
|
|
||||||
super(containingDeclaration, annotations, name, inType, outType);
|
|
||||||
assert !isVar || inType != null;
|
|
||||||
// assert outType != null;
|
// assert outType != null;
|
||||||
this.isVar = isVar;
|
this.isVar = isVar;
|
||||||
this.modality = modality;
|
this.modality = modality;
|
||||||
this.visibility = visibility;
|
this.visibility = visibility;
|
||||||
this.receiver = receiverType == null ? ReceiverDescriptor.NO_RECEIVER : new ExtensionReceiver(this, receiverType);
|
|
||||||
this.expectedThisObject = expectedThisObject;
|
this.expectedThisObject = expectedThisObject;
|
||||||
this.original = original == null ? this : original.getOriginal();
|
this.original = original == null ? this : original.getOriginal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PropertyDescriptor(
|
||||||
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
|
@NotNull List<AnnotationDescriptor> annotations,
|
||||||
|
@NotNull Modality modality,
|
||||||
|
@NotNull Visibility visibility,
|
||||||
|
boolean isVar,
|
||||||
|
@NotNull ReceiverDescriptor expectedThisObject,
|
||||||
|
@NotNull String name) {
|
||||||
|
this(null, containingDeclaration, annotations, modality, visibility, isVar, expectedThisObject, name);
|
||||||
|
}
|
||||||
|
|
||||||
public PropertyDescriptor(
|
public PropertyDescriptor(
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull List<AnnotationDescriptor> annotations,
|
@NotNull List<AnnotationDescriptor> annotations,
|
||||||
@@ -66,8 +74,11 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
|||||||
@NotNull ReceiverDescriptor expectedThisObject,
|
@NotNull ReceiverDescriptor expectedThisObject,
|
||||||
@NotNull String name,
|
@NotNull String name,
|
||||||
@Nullable JetType inType,
|
@Nullable JetType inType,
|
||||||
@NotNull JetType outType) {
|
@NotNull JetType outType
|
||||||
this(null, containingDeclaration, annotations, modality, visibility, isVar, receiverType, expectedThisObject, name, inType, outType);
|
)
|
||||||
|
{
|
||||||
|
this(containingDeclaration, annotations, modality, visibility, isVar, expectedThisObject, name);
|
||||||
|
setType(inType, outType, Collections.<TypeParameterDescriptor>emptyList(), receiverType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PropertyDescriptor(
|
private PropertyDescriptor(
|
||||||
@@ -75,7 +86,9 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
|||||||
@Nullable JetType receiverType,
|
@Nullable JetType receiverType,
|
||||||
@NotNull ReceiverDescriptor expectedThisObject,
|
@NotNull ReceiverDescriptor expectedThisObject,
|
||||||
@Nullable JetType inType,
|
@Nullable JetType inType,
|
||||||
@NotNull JetType outType) {
|
@NotNull JetType outType
|
||||||
|
)
|
||||||
|
{
|
||||||
this(
|
this(
|
||||||
original,
|
original,
|
||||||
original.getContainingDeclaration(),
|
original.getContainingDeclaration(),
|
||||||
@@ -83,15 +96,38 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
|||||||
original.getModality(),
|
original.getModality(),
|
||||||
original.getVisibility(),
|
original.getVisibility(),
|
||||||
original.isVar,
|
original.isVar,
|
||||||
receiverType,
|
|
||||||
expectedThisObject,
|
expectedThisObject,
|
||||||
original.getName(),
|
original.getName()
|
||||||
inType,
|
);
|
||||||
outType);
|
setType(inType, outType, Collections.<TypeParameterDescriptor>emptyList(), receiverType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(@NotNull List<TypeParameterDescriptor> typeParameters, @Nullable PropertyGetterDescriptor getter, @Nullable PropertySetterDescriptor setter) {
|
public void setType(@Nullable JetType inType, @NotNull JetType outType,
|
||||||
this.typeParemeters.addAll(typeParameters);
|
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||||
|
@Nullable JetType receiverType
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ReceiverDescriptor receiver = receiverType == null
|
||||||
|
? ReceiverDescriptor.NO_RECEIVER
|
||||||
|
: new ExtensionReceiver(this, receiverType);
|
||||||
|
setType(inType, outType, typeParameters, receiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(@Nullable JetType inType, @NotNull JetType outType,
|
||||||
|
@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull ReceiverDescriptor receiver)
|
||||||
|
{
|
||||||
|
assert !isVar || inType != null;
|
||||||
|
setInType(inType);
|
||||||
|
setOutType(outType);
|
||||||
|
|
||||||
|
this.typeParemeters = typeParameters;
|
||||||
|
|
||||||
|
this.receiver = receiver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize(
|
||||||
|
@Nullable PropertyGetterDescriptor getter, @Nullable PropertySetterDescriptor setter)
|
||||||
|
{
|
||||||
this.getter = getter;
|
this.getter = getter;
|
||||||
this.setter = setter;
|
this.setter = setter;
|
||||||
}
|
}
|
||||||
@@ -209,20 +245,24 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
|||||||
newOwner,
|
newOwner,
|
||||||
Lists.newArrayList(getAnnotations()),
|
Lists.newArrayList(getAnnotations()),
|
||||||
DescriptorUtils.convertModality(modality, makeNonAbstract), visibility, isVar,
|
DescriptorUtils.convertModality(modality, makeNonAbstract), visibility, isVar,
|
||||||
receiver.exists() ? receiver.getType() : null,
|
|
||||||
expectedThisObject,
|
expectedThisObject,
|
||||||
getName(), getInType(), getOutType());
|
getName());
|
||||||
|
|
||||||
|
propertyDescriptor.setType(getInType(), getOutType(), DescriptorUtils.copyTypeParameters(propertyDescriptor, getTypeParameters()), receiver.exists() ? receiver.getType() : null);
|
||||||
|
|
||||||
PropertyGetterDescriptor newGetter = getter == null ? null : new PropertyGetterDescriptor(
|
PropertyGetterDescriptor newGetter = getter == null ? null : new PropertyGetterDescriptor(
|
||||||
propertyDescriptor, Lists.newArrayList(getter.getAnnotations()),
|
propertyDescriptor, Lists.newArrayList(getter.getAnnotations()),
|
||||||
DescriptorUtils.convertModality(getter.getModality(), makeNonAbstract), getter.getVisibility(),
|
DescriptorUtils.convertModality(getter.getModality(), makeNonAbstract), getter.getVisibility(),
|
||||||
getter.getReturnType(),
|
|
||||||
getter.hasBody(), getter.isDefault());
|
getter.hasBody(), getter.isDefault());
|
||||||
|
if (newGetter != null) {
|
||||||
|
newGetter.initialize(getter.getReturnType());
|
||||||
|
}
|
||||||
PropertySetterDescriptor newSetter = setter == null ? null : new PropertySetterDescriptor(
|
PropertySetterDescriptor newSetter = setter == null ? null : new PropertySetterDescriptor(
|
||||||
DescriptorUtils.convertModality(setter.getModality(), makeNonAbstract), setter.getVisibility(),
|
DescriptorUtils.convertModality(setter.getModality(), makeNonAbstract), setter.getVisibility(),
|
||||||
propertyDescriptor,
|
propertyDescriptor,
|
||||||
Lists.newArrayList(setter.getAnnotations()),
|
Lists.newArrayList(setter.getAnnotations()),
|
||||||
setter.hasBody(), setter.isDefault());
|
setter.hasBody(), setter.isDefault());
|
||||||
propertyDescriptor.initialize(DescriptorUtils.copyTypeParameters(propertyDescriptor, getTypeParameters()), newGetter, newSetter);
|
propertyDescriptor.initialize(newGetter, newSetter);
|
||||||
return propertyDescriptor;
|
return propertyDescriptor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-2
@@ -17,9 +17,14 @@ import java.util.Set;
|
|||||||
public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
|
public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
|
||||||
private JetType returnType;
|
private JetType returnType;
|
||||||
|
|
||||||
public PropertyGetterDescriptor(@NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, @NotNull Modality modality, @NotNull Visibility visibility, @Nullable JetType returnType, boolean hasBody, boolean isDefault) {
|
public PropertyGetterDescriptor(@NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations,
|
||||||
|
@NotNull Modality modality, @NotNull Visibility visibility, boolean hasBody, boolean isDefault)
|
||||||
|
{
|
||||||
super(modality, visibility, correspondingProperty, annotations, "get-" + correspondingProperty.getName(), hasBody, isDefault);
|
super(modality, visibility, correspondingProperty, annotations, "get-" + correspondingProperty.getName(), hasBody, isDefault);
|
||||||
this.returnType = returnType == null ? correspondingProperty.getOutType() : returnType;
|
}
|
||||||
|
|
||||||
|
public void initialize(JetType returnType) {
|
||||||
|
this.returnType = returnType == null ? getCorrespondingProperty().getOutType() : returnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+4
-1
@@ -17,7 +17,10 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
|
|||||||
|
|
||||||
private MutableValueParameterDescriptor parameter;
|
private MutableValueParameterDescriptor parameter;
|
||||||
|
|
||||||
public PropertySetterDescriptor(@NotNull Modality modality, @NotNull Visibility visibility, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, boolean hasBody, boolean isDefault) {
|
public PropertySetterDescriptor(@NotNull Modality modality, @NotNull Visibility visibility,
|
||||||
|
@NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations,
|
||||||
|
boolean hasBody, boolean isDefault)
|
||||||
|
{
|
||||||
super(modality, visibility, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody, isDefault);
|
super(modality, visibility, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody, isDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorImpl i
|
|||||||
this.outType = outType;
|
this.outType = outType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected VariableDescriptorImpl(
|
||||||
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
|
@NotNull List<AnnotationDescriptor> annotations,
|
||||||
|
@NotNull String name
|
||||||
|
)
|
||||||
|
{
|
||||||
|
super(containingDeclaration, annotations, name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetType getOutType() {
|
public JetType getOutType() {
|
||||||
return outType;
|
return outType;
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ public class AnalyzingUtils {
|
|||||||
final WritableScope scope = new WritableScopeImpl(JetScope.EMPTY, owner, new TraceBasedRedeclarationHandler(bindingTraceContext)).setDebugName("Root scope in analyzeNamespace");
|
final WritableScope scope = new WritableScopeImpl(JetScope.EMPTY, owner, new TraceBasedRedeclarationHandler(bindingTraceContext)).setDebugName("Root scope in analyzeNamespace");
|
||||||
importingStrategy.addImports(project, semanticServices, bindingTraceContext, scope);
|
importingStrategy.addImports(project, semanticServices, bindingTraceContext, scope);
|
||||||
scope.importScope(libraryScope);
|
scope.importScope(libraryScope);
|
||||||
|
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
|
|
||||||
TopDownAnalyzer.process(semanticServices, bindingTraceContext, scope, new NamespaceLike.Adapter(owner) {
|
TopDownAnalyzer.process(semanticServices, bindingTraceContext, scope, new NamespaceLike.Adapter(owner) {
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class BodyResolver {
|
|||||||
final ConstructorDescriptor primaryConstructor = descriptor.getUnsubstitutedPrimaryConstructor();
|
final ConstructorDescriptor primaryConstructor = descriptor.getUnsubstitutedPrimaryConstructor();
|
||||||
final JetScope scopeForConstructor = primaryConstructor == null
|
final JetScope scopeForConstructor = primaryConstructor == null
|
||||||
? null
|
? null
|
||||||
: getInnerScopeForConstructor(primaryConstructor, descriptor.getScopeForMemberResolution(), true);
|
: getInnerScopeForConstructor(primaryConstructor);
|
||||||
final ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(traceForConstructors); // TODO : flow
|
final ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(traceForConstructors); // TODO : flow
|
||||||
|
|
||||||
final Map<JetTypeReference, JetType> supertypes = Maps.newLinkedHashMap();
|
final Map<JetTypeReference, JetType> supertypes = Maps.newLinkedHashMap();
|
||||||
@@ -267,7 +267,7 @@ public class BodyResolver {
|
|||||||
if (jetClassOrObject.hasPrimaryConstructor()) {
|
if (jetClassOrObject.hasPrimaryConstructor()) {
|
||||||
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||||
assert primaryConstructor != null;
|
assert primaryConstructor != null;
|
||||||
final JetScope scopeForConstructor = getInnerScopeForConstructor(primaryConstructor, classDescriptor.getScopeForMemberResolution(), true);
|
final JetScope scopeForConstructor = getInnerScopeForConstructor(primaryConstructor);
|
||||||
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(traceForConstructors);
|
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(traceForConstructors);
|
||||||
for (JetClassInitializer anonymousInitializer : anonymousInitializers) {
|
for (JetClassInitializer anonymousInitializer : anonymousInitializers) {
|
||||||
typeInferrer.getType(scopeForConstructor, anonymousInitializer.getBody(), NO_EXPECTED_TYPE);
|
typeInferrer.getType(scopeForConstructor, anonymousInitializer.getBody(), NO_EXPECTED_TYPE);
|
||||||
@@ -293,7 +293,7 @@ public class BodyResolver {
|
|||||||
|
|
||||||
private void resolveSecondaryConstructorBody(JetSecondaryConstructor declaration, final ConstructorDescriptor descriptor, final JetScope declaringScope) {
|
private void resolveSecondaryConstructorBody(JetSecondaryConstructor declaration, final ConstructorDescriptor descriptor, final JetScope declaringScope) {
|
||||||
if (!context.completeAnalysisNeeded(declaration)) return;
|
if (!context.completeAnalysisNeeded(declaration)) return;
|
||||||
final JetScope functionInnerScope = getInnerScopeForConstructor(descriptor, declaringScope, false);
|
final JetScope functionInnerScope = getInnerScopeForConstructor(descriptor);
|
||||||
|
|
||||||
final CallResolver callResolver = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY); // TODO: dataFlowInfo
|
final CallResolver callResolver = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY); // TODO: dataFlowInfo
|
||||||
|
|
||||||
@@ -366,24 +366,9 @@ public class BodyResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JetScope getInnerScopeForConstructor(@NotNull ConstructorDescriptor descriptor, @NotNull JetScope declaringScope, boolean primary) {
|
private JetScope getInnerScopeForConstructor(@NotNull ConstructorDescriptor descriptor) {
|
||||||
WritableScope constructorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Inner scope for constructor");
|
MutableClassDescriptor mutableClassDescriptor = (MutableClassDescriptor) descriptor.getContainingDeclaration();
|
||||||
for (PropertyDescriptor propertyDescriptor : ((MutableClassDescriptor) descriptor.getContainingDeclaration()).getProperties()) {
|
return mutableClassDescriptor.getScopeForConstructor(descriptor);
|
||||||
constructorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// constructorScope.setImplicitReceiver(new ClassReceiver(descriptor.getContainingDeclaration()));
|
|
||||||
|
|
||||||
for (ValueParameterDescriptor valueParameterDescriptor : descriptor.getValueParameters()) {
|
|
||||||
JetParameter parameter = (JetParameter) context.getTrace().getBindingContext().get(BindingContext.DESCRIPTOR_TO_DECLARATION, valueParameterDescriptor);
|
|
||||||
if (parameter.getValOrVarNode() == null || !primary) {
|
|
||||||
constructorScope.addVariableDescriptor(valueParameterDescriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
constructorScope.addLabeledDeclaration(descriptor); // TODO : Labels for constructors?!
|
|
||||||
|
|
||||||
return constructorScope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolvePropertyDeclarationBodies() {
|
private void resolvePropertyDeclarationBodies() {
|
||||||
@@ -399,18 +384,16 @@ public class BodyResolver {
|
|||||||
final PropertyDescriptor propertyDescriptor = this.context.getProperties().get(property);
|
final PropertyDescriptor propertyDescriptor = this.context.getProperties().get(property);
|
||||||
assert propertyDescriptor != null;
|
assert propertyDescriptor != null;
|
||||||
|
|
||||||
JetScope declaringScope = this.context.getDeclaringScopes().get(property);
|
|
||||||
|
|
||||||
JetExpression initializer = property.getInitializer();
|
JetExpression initializer = property.getInitializer();
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||||
if (primaryConstructor != null) {
|
if (primaryConstructor != null) {
|
||||||
JetScope scope = getInnerScopeForConstructor(primaryConstructor, classDescriptor.getScopeForMemberResolution(), true);
|
JetScope declaringScopeForPropertyInitializer = this.context.getDeclaringScopes().get(property);
|
||||||
resolvePropertyInitializer(property, propertyDescriptor, initializer, scope);
|
resolvePropertyInitializer(property, propertyDescriptor, initializer, declaringScopeForPropertyInitializer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resolvePropertyAccessors(property, propertyDescriptor, declaringScope);
|
resolvePropertyAccessors(property, propertyDescriptor);
|
||||||
processed.add(property);
|
processed.add(property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -429,37 +412,36 @@ public class BodyResolver {
|
|||||||
resolvePropertyInitializer(property, propertyDescriptor, initializer, declaringScope);
|
resolvePropertyInitializer(property, propertyDescriptor, initializer, declaringScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolvePropertyAccessors(property, propertyDescriptor, declaringScope);
|
resolvePropertyAccessors(property, propertyDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JetScope makeScopeForPropertyAccessor(@NotNull JetPropertyAccessor accessor, PropertyDescriptor propertyDescriptor) {
|
||||||
|
JetScope declaringScope = context.getDeclaringScopes().get(accessor);
|
||||||
|
|
||||||
private JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope, @NotNull PropertyDescriptor propertyDescriptor) {
|
JetScope propertyDeclarationInnerScope = context.getDescriptorResolver().getPropertyDeclarationInnerScope(
|
||||||
WritableScopeImpl result = new WritableScopeImpl(outerScope, propertyDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Property declaration inner scope");
|
declaringScope, propertyDescriptor, propertyDescriptor.getTypeParameters(), propertyDescriptor.getReceiverParameter());
|
||||||
for (TypeParameterDescriptor typeParameterDescriptor : propertyDescriptor.getTypeParameters()) {
|
WritableScope accessorScope = new WritableScopeImpl(propertyDeclarationInnerScope, declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Accessor scope");
|
||||||
result.addTypeParameterDescriptor(typeParameterDescriptor);
|
|
||||||
}
|
|
||||||
ReceiverDescriptor receiver = propertyDescriptor.getReceiverParameter();
|
|
||||||
if (receiver.exists()) {
|
|
||||||
result.setImplicitReceiver(receiver);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resolvePropertyAccessors(JetProperty property, PropertyDescriptor propertyDescriptor, JetScope declaringScope) {
|
|
||||||
ObservableBindingTrace fieldAccessTrackingTrace = createFieldTrackingTrace(propertyDescriptor);
|
|
||||||
|
|
||||||
WritableScope accessorScope = new WritableScopeImpl(getPropertyDeclarationInnerScope(declaringScope, propertyDescriptor), declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Accessor scope");
|
|
||||||
accessorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
|
accessorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
|
||||||
|
accessorScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
|
||||||
|
return accessorScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resolvePropertyAccessors(JetProperty property, PropertyDescriptor propertyDescriptor) {
|
||||||
|
ObservableBindingTrace fieldAccessTrackingTrace = createFieldTrackingTrace(propertyDescriptor);
|
||||||
|
|
||||||
JetPropertyAccessor getter = property.getGetter();
|
JetPropertyAccessor getter = property.getGetter();
|
||||||
PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter();
|
PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter();
|
||||||
if (getter != null && getterDescriptor != null) {
|
if (getter != null && getterDescriptor != null) {
|
||||||
|
JetScope accessorScope = makeScopeForPropertyAccessor(getter, propertyDescriptor);
|
||||||
resolveFunctionBody(fieldAccessTrackingTrace, getter, getterDescriptor, accessorScope);
|
resolveFunctionBody(fieldAccessTrackingTrace, getter, getterDescriptor, accessorScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
JetPropertyAccessor setter = property.getSetter();
|
JetPropertyAccessor setter = property.getSetter();
|
||||||
PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter();
|
PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter();
|
||||||
if (setter != null && setterDescriptor != null) {
|
if (setter != null && setterDescriptor != null) {
|
||||||
|
JetScope accessorScope = makeScopeForPropertyAccessor(setter, propertyDescriptor);
|
||||||
resolveFunctionBody(fieldAccessTrackingTrace, setter, setterDescriptor, accessorScope);
|
resolveFunctionBody(fieldAccessTrackingTrace, setter, setterDescriptor, accessorScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -485,7 +467,7 @@ public class BodyResolver {
|
|||||||
//JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(property, initializer); // TODO : flow JET-15
|
//JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(property, initializer); // TODO : flow JET-15
|
||||||
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(traceForConstructors);
|
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(traceForConstructors);
|
||||||
JetType expectedTypeForInitializer = property.getPropertyTypeRef() != null ? propertyDescriptor.getOutType() : NO_EXPECTED_TYPE;
|
JetType expectedTypeForInitializer = property.getPropertyTypeRef() != null ? propertyDescriptor.getOutType() : NO_EXPECTED_TYPE;
|
||||||
JetType type = typeInferrer.getType(getPropertyDeclarationInnerScope(scope, propertyDescriptor), initializer, expectedTypeForInitializer);
|
JetType type = typeInferrer.getType(context.getDescriptorResolver().getPropertyDeclarationInnerScope(scope, propertyDescriptor, propertyDescriptor.getTypeParameters(), propertyDescriptor.getReceiverParameter()), initializer, expectedTypeForInitializer);
|
||||||
//
|
//
|
||||||
// JetType expectedType = propertyDescriptor.getInType();
|
// JetType expectedType = propertyDescriptor.getInType();
|
||||||
// if (expectedType == null) {
|
// if (expectedType == null) {
|
||||||
|
|||||||
@@ -67,13 +67,15 @@ public class DeclarationResolver {
|
|||||||
WritableScope namespaceScope = entry.getValue();
|
WritableScope namespaceScope = entry.getValue();
|
||||||
NamespaceLike namespaceDescriptor = context.getNamespaceDescriptors().get(namespace);
|
NamespaceLike namespaceDescriptor = context.getNamespaceDescriptors().get(namespace);
|
||||||
|
|
||||||
resolveFunctionAndPropertyHeaders(namespace.getDeclarations(), namespaceScope, namespaceDescriptor);
|
resolveFunctionAndPropertyHeaders(namespace.getDeclarations(), namespaceScope, namespaceScope, namespaceScope, namespaceDescriptor);
|
||||||
}
|
}
|
||||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
||||||
JetClass jetClass = entry.getKey();
|
JetClass jetClass = entry.getKey();
|
||||||
MutableClassDescriptor classDescriptor = entry.getValue();
|
MutableClassDescriptor classDescriptor = entry.getValue();
|
||||||
|
|
||||||
resolveFunctionAndPropertyHeaders(jetClass.getDeclarations(), classDescriptor.getScopeForMemberResolution(), classDescriptor);
|
resolveFunctionAndPropertyHeaders(jetClass.getDeclarations(), classDescriptor.getScopeForMemberResolution(),
|
||||||
|
classDescriptor.getScopeForPropertyIntiailizer(), classDescriptor.getScopeForMemberResolution(),
|
||||||
|
classDescriptor);
|
||||||
// processPrimaryConstructor(classDescriptor, jetClass);
|
// processPrimaryConstructor(classDescriptor, jetClass);
|
||||||
// for (JetSecondaryConstructor jetConstructor : jetClass.getSecondaryConstructors()) {
|
// for (JetSecondaryConstructor jetConstructor : jetClass.getSecondaryConstructors()) {
|
||||||
// processSecondaryConstructor(classDescriptor, jetConstructor);
|
// processSecondaryConstructor(classDescriptor, jetConstructor);
|
||||||
@@ -83,29 +85,41 @@ public class DeclarationResolver {
|
|||||||
JetObjectDeclaration object = entry.getKey();
|
JetObjectDeclaration object = entry.getKey();
|
||||||
MutableClassDescriptor classDescriptor = entry.getValue();
|
MutableClassDescriptor classDescriptor = entry.getValue();
|
||||||
|
|
||||||
resolveFunctionAndPropertyHeaders(object.getDeclarations(), classDescriptor.getScopeForMemberResolution(), classDescriptor);
|
resolveFunctionAndPropertyHeaders(object.getDeclarations(), classDescriptor.getScopeForMemberResolution(),
|
||||||
|
classDescriptor.getScopeForPropertyIntiailizer(), classDescriptor.getScopeForMemberResolution(),
|
||||||
|
classDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : Extensions
|
// TODO : Extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolveFunctionAndPropertyHeaders(@NotNull List<JetDeclaration> declarations, final @NotNull JetScope scope, final @NotNull NamespaceLike namespaceLike) {
|
private void resolveFunctionAndPropertyHeaders(@NotNull List<JetDeclaration> declarations,
|
||||||
|
final @NotNull JetScope scopeForFunctions,
|
||||||
|
final @NotNull JetScope scopeForPropertyInitializers, final @NotNull JetScope scopeForPropertyAccessors,
|
||||||
|
final @NotNull NamespaceLike namespaceLike)
|
||||||
|
{
|
||||||
for (JetDeclaration declaration : declarations) {
|
for (JetDeclaration declaration : declarations) {
|
||||||
declaration.accept(new JetVisitorVoid() {
|
declaration.accept(new JetVisitorVoid() {
|
||||||
@Override
|
@Override
|
||||||
public void visitNamedFunction(JetNamedFunction function) {
|
public void visitNamedFunction(JetNamedFunction function) {
|
||||||
FunctionDescriptorImpl functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scope, function);
|
FunctionDescriptorImpl functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function);
|
||||||
namespaceLike.addFunctionDescriptor(functionDescriptor);
|
namespaceLike.addFunctionDescriptor(functionDescriptor);
|
||||||
context.getFunctions().put(function, functionDescriptor);
|
context.getFunctions().put(function, functionDescriptor);
|
||||||
context.getDeclaringScopes().put(function, scope);
|
context.getDeclaringScopes().put(function, scopeForFunctions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitProperty(JetProperty property) {
|
public void visitProperty(JetProperty property) {
|
||||||
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolvePropertyDescriptor(namespaceLike, scope, property);
|
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolvePropertyDescriptor(namespaceLike, scopeForPropertyInitializers, property);
|
||||||
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
||||||
context.getProperties().put(property, propertyDescriptor);
|
context.getProperties().put(property, propertyDescriptor);
|
||||||
context.getDeclaringScopes().put(property, scope);
|
context.getDeclaringScopes().put(property, scopeForPropertyInitializers);
|
||||||
|
if (property.getGetter() != null) {
|
||||||
|
context.getDeclaringScopes().put(property.getGetter(), scopeForPropertyAccessors);
|
||||||
|
}
|
||||||
|
if (property.getSetter() != null) {
|
||||||
|
context.getDeclaringScopes().put(property.getSetter(), scopeForPropertyAccessors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -150,7 +164,7 @@ public class DeclarationResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (constructorDescriptor != null) {
|
if (constructorDescriptor != null) {
|
||||||
classDescriptor.setPrimaryConstructor(constructorDescriptor);
|
classDescriptor.setPrimaryConstructor(constructorDescriptor, context.getTrace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +177,7 @@ public class DeclarationResolver {
|
|||||||
classDescriptor.getScopeForMemberResolution(),
|
classDescriptor.getScopeForMemberResolution(),
|
||||||
classDescriptor,
|
classDescriptor,
|
||||||
constructor);
|
constructor);
|
||||||
classDescriptor.addConstructor(constructorDescriptor);
|
classDescriptor.addConstructor(constructorDescriptor, context.getTrace());
|
||||||
context.getConstructors().put(constructor, constructorDescriptor);
|
context.getConstructors().put(constructor, constructorDescriptor);
|
||||||
context.getDeclaringScopes().put(constructor, classDescriptor.getScopeForMemberLookup());
|
context.getDeclaringScopes().put(constructor, classDescriptor.getScopeForMemberLookup());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import org.jetbrains.jet.lang.psi.*;
|
|||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
import org.jetbrains.jet.util.lazy.LazyValue;
|
import org.jetbrains.jet.util.lazy.LazyValue;
|
||||||
@@ -146,6 +148,7 @@ public class DescriptorResolver {
|
|||||||
innerScope.addLabeledDeclaration(functionDescriptor);
|
innerScope.addLabeledDeclaration(functionDescriptor);
|
||||||
|
|
||||||
List<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters());
|
List<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters());
|
||||||
|
innerScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
resolveGenericBounds(function, innerScope, typeParameterDescriptors);
|
resolveGenericBounds(function, innerScope, typeParameterDescriptors);
|
||||||
|
|
||||||
JetType receiverType = null;
|
JetType receiverType = null;
|
||||||
@@ -160,6 +163,8 @@ public class DescriptorResolver {
|
|||||||
|
|
||||||
List<ValueParameterDescriptor> valueParameterDescriptors = resolveValueParameters(functionDescriptor, innerScope, function.getValueParameters());
|
List<ValueParameterDescriptor> valueParameterDescriptors = resolveValueParameters(functionDescriptor, innerScope, function.getValueParameters());
|
||||||
|
|
||||||
|
innerScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
|
||||||
JetTypeReference returnTypeRef = function.getReturnTypeRef();
|
JetTypeReference returnTypeRef = function.getReturnTypeRef();
|
||||||
JetType returnType;
|
JetType returnType;
|
||||||
if (returnTypeRef != null) {
|
if (returnTypeRef != null) {
|
||||||
@@ -470,16 +475,12 @@ public class DescriptorResolver {
|
|||||||
Modality.FINAL,
|
Modality.FINAL,
|
||||||
resolveVisibilityFromModifiers(objectDeclaration.getModifierList()),
|
resolveVisibilityFromModifiers(objectDeclaration.getModifierList()),
|
||||||
false,
|
false,
|
||||||
null,
|
|
||||||
DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration),
|
DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration),
|
||||||
JetPsiUtil.safeName(objectDeclaration.getName()),
|
JetPsiUtil.safeName(objectDeclaration.getName())
|
||||||
null,
|
);
|
||||||
classDescriptor.getDefaultType());
|
|
||||||
|
|
||||||
propertyDescriptor.initialize(
|
propertyDescriptor.setType(null, classDescriptor.getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(), ReceiverDescriptor.NO_RECEIVER);
|
||||||
Collections.<TypeParameterDescriptor>emptyList(),
|
propertyDescriptor.initialize(null, null);
|
||||||
null, // TODO : is it really OK?
|
|
||||||
null);
|
|
||||||
|
|
||||||
JetObjectDeclarationName nameAsDeclaration = objectDeclaration.getNameAsDeclaration();
|
JetObjectDeclarationName nameAsDeclaration = objectDeclaration.getNameAsDeclaration();
|
||||||
if (nameAsDeclaration != null) {
|
if (nameAsDeclaration != null) {
|
||||||
@@ -488,33 +489,27 @@ public class DescriptorResolver {
|
|||||||
return propertyDescriptor;
|
return propertyDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope,
|
||||||
|
@NotNull PropertyDescriptor propertyDescriptor, List<TypeParameterDescriptor> typeParameters,
|
||||||
|
ReceiverDescriptor receiver)
|
||||||
|
{
|
||||||
|
WritableScopeImpl result = new WritableScopeImpl(outerScope, propertyDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Property declaration inner scope");
|
||||||
|
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
||||||
|
result.addTypeParameterDescriptor(typeParameterDescriptor);
|
||||||
|
}
|
||||||
|
if (receiver.exists()) {
|
||||||
|
result.setImplicitReceiver(receiver);
|
||||||
|
}
|
||||||
|
result.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public PropertyDescriptor resolvePropertyDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope scope, JetProperty property) {
|
public PropertyDescriptor resolvePropertyDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope scope, JetProperty property) {
|
||||||
JetScope scopeWithTypeParameters;
|
|
||||||
List<TypeParameterDescriptor> typeParameterDescriptors;
|
|
||||||
List<JetTypeParameter> typeParameters = property.getTypeParameters();
|
|
||||||
if (typeParameters.isEmpty()) {
|
|
||||||
scopeWithTypeParameters = scope;
|
|
||||||
typeParameterDescriptors = Collections.emptyList();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with type parameters of a property");
|
|
||||||
typeParameterDescriptors = resolveTypeParameters(containingDeclaration, writableScope, typeParameters);
|
|
||||||
resolveGenericBounds(property, writableScope, typeParameterDescriptors);
|
|
||||||
scopeWithTypeParameters = writableScope;
|
|
||||||
}
|
|
||||||
|
|
||||||
JetType receiverType = null;
|
|
||||||
JetTypeReference receiverTypeRef = property.getReceiverTypeRef();
|
|
||||||
if (receiverTypeRef != null) {
|
|
||||||
receiverType = typeResolver.resolveType(scopeWithTypeParameters, receiverTypeRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
JetModifierList modifierList = property.getModifierList();
|
JetModifierList modifierList = property.getModifierList();
|
||||||
boolean isVar = property.isVar();
|
boolean isVar = property.isVar();
|
||||||
|
|
||||||
JetType type = getVariableType(scopeWithTypeParameters, property, true);
|
|
||||||
|
|
||||||
boolean hasBody = hasBody(property);
|
boolean hasBody = hasBody(property);
|
||||||
Modality defaultModality = getDefaultModality(containingDeclaration, hasBody);
|
Modality defaultModality = getDefaultModality(containingDeclaration, hasBody);
|
||||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||||
@@ -523,16 +518,49 @@ public class DescriptorResolver {
|
|||||||
resolveModalityFromModifiers(property.getModifierList(), defaultModality),
|
resolveModalityFromModifiers(property.getModifierList(), defaultModality),
|
||||||
resolveVisibilityFromModifiers(property.getModifierList()),
|
resolveVisibilityFromModifiers(property.getModifierList()),
|
||||||
isVar,
|
isVar,
|
||||||
receiverType,
|
|
||||||
DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration),
|
DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration),
|
||||||
JetPsiUtil.safeName(property.getName()),
|
JetPsiUtil.safeName(property.getName())
|
||||||
isVar ? type : null,
|
);
|
||||||
type);
|
|
||||||
|
|
||||||
propertyDescriptor.initialize(
|
List<TypeParameterDescriptor> typeParameterDescriptors;
|
||||||
typeParameterDescriptors,
|
JetScope scopeWithTypeParameters;
|
||||||
resolvePropertyGetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor),
|
JetType receiverType = null;
|
||||||
resolvePropertySetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor));
|
|
||||||
|
{
|
||||||
|
List<JetTypeParameter> typeParameters = property.getTypeParameters();
|
||||||
|
if (typeParameters.isEmpty()) {
|
||||||
|
scopeWithTypeParameters = scope;
|
||||||
|
typeParameterDescriptors = Collections.emptyList();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with type parameters of a property");
|
||||||
|
typeParameterDescriptors = resolveTypeParameters(containingDeclaration, writableScope, typeParameters);
|
||||||
|
writableScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
resolveGenericBounds(property, writableScope, typeParameterDescriptors);
|
||||||
|
scopeWithTypeParameters = writableScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
JetTypeReference receiverTypeRef = property.getReceiverTypeRef();
|
||||||
|
if (receiverTypeRef != null) {
|
||||||
|
receiverType = typeResolver.resolveType(scopeWithTypeParameters, receiverTypeRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReceiverDescriptor receiverDescriptor = receiverType == null
|
||||||
|
? ReceiverDescriptor.NO_RECEIVER
|
||||||
|
: new ExtensionReceiver(propertyDescriptor, receiverType);
|
||||||
|
|
||||||
|
JetScope scope2 = getPropertyDeclarationInnerScope(scope, propertyDescriptor, typeParameterDescriptors, receiverDescriptor);
|
||||||
|
|
||||||
|
JetType type = getVariableType(scope2, property, true);
|
||||||
|
|
||||||
|
JetType inType = isVar ? type : null;
|
||||||
|
propertyDescriptor.setType(inType, type, typeParameterDescriptors, receiverDescriptor);
|
||||||
|
|
||||||
|
PropertyGetterDescriptor getter = resolvePropertyGetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor);
|
||||||
|
PropertySetterDescriptor setter = resolvePropertySetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor);
|
||||||
|
|
||||||
|
propertyDescriptor.initialize(getter, setter);
|
||||||
|
|
||||||
trace.record(BindingContext.VARIABLE, property, propertyDescriptor);
|
trace.record(BindingContext.VARIABLE, property, propertyDescriptor);
|
||||||
return propertyDescriptor;
|
return propertyDescriptor;
|
||||||
@@ -724,7 +752,8 @@ public class DescriptorResolver {
|
|||||||
getterDescriptor = new PropertyGetterDescriptor(
|
getterDescriptor = new PropertyGetterDescriptor(
|
||||||
propertyDescriptor, annotations, resolveModalityFromModifiers(getter.getModifierList(), propertyDescriptor.getModality()),
|
propertyDescriptor, annotations, resolveModalityFromModifiers(getter.getModifierList(), propertyDescriptor.getModality()),
|
||||||
resolveVisibilityFromModifiers(getter.getModifierList(), propertyDescriptor.getVisibility()),
|
resolveVisibilityFromModifiers(getter.getModifierList(), propertyDescriptor.getVisibility()),
|
||||||
returnType, getter.getBodyExpression() != null, false);
|
getter.getBodyExpression() != null, false);
|
||||||
|
getterDescriptor.initialize(returnType);
|
||||||
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
|
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -738,7 +767,7 @@ public class DescriptorResolver {
|
|||||||
getterDescriptor = new PropertyGetterDescriptor(
|
getterDescriptor = new PropertyGetterDescriptor(
|
||||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
||||||
propertyDescriptor.getVisibility(),
|
propertyDescriptor.getVisibility(),
|
||||||
propertyDescriptor.getOutType(), false, true);
|
false, true);
|
||||||
return getterDescriptor;
|
return getterDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -761,11 +790,13 @@ public class DescriptorResolver {
|
|||||||
isPrimary
|
isPrimary
|
||||||
);
|
);
|
||||||
trace.record(BindingContext.CONSTRUCTOR, declarationToTrace, constructorDescriptor);
|
trace.record(BindingContext.CONSTRUCTOR, declarationToTrace, constructorDescriptor);
|
||||||
|
WritableScopeImpl parameterScope = new WritableScopeImpl(scope, classDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with value parameters of a constructor");
|
||||||
|
parameterScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
return constructorDescriptor.initialize(
|
return constructorDescriptor.initialize(
|
||||||
typeParameters,
|
typeParameters,
|
||||||
resolveValueParameters(
|
resolveValueParameters(
|
||||||
constructorDescriptor,
|
constructorDescriptor,
|
||||||
new WritableScopeImpl(scope, classDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with value parameters of a constructor"),
|
parameterScope,
|
||||||
valueParameters),
|
valueParameters),
|
||||||
Modality.FINAL,
|
Modality.FINAL,
|
||||||
resolveVisibilityFromModifiers(modifierList));
|
resolveVisibilityFromModifiers(modifierList));
|
||||||
@@ -807,12 +838,17 @@ public class DescriptorResolver {
|
|||||||
resolveModalityFromModifiers(parameter.getModifierList(), Modality.FINAL),
|
resolveModalityFromModifiers(parameter.getModifierList(), Modality.FINAL),
|
||||||
resolveVisibilityFromModifiers(parameter.getModifierList()),
|
resolveVisibilityFromModifiers(parameter.getModifierList()),
|
||||||
isMutable,
|
isMutable,
|
||||||
null,
|
|
||||||
DescriptorUtils.getExpectedThisObjectIfNeeded(classDescriptor),
|
DescriptorUtils.getExpectedThisObjectIfNeeded(classDescriptor),
|
||||||
name == null ? "<no name>" : name,
|
name == null ? "<no name>" : name
|
||||||
isMutable ? type : null,
|
);
|
||||||
type);
|
PropertyGetterDescriptor getter = createDefaultGetter(propertyDescriptor);
|
||||||
propertyDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(), createDefaultGetter(propertyDescriptor), createDefaultSetter(propertyDescriptor));
|
PropertySetterDescriptor setter = createDefaultSetter(propertyDescriptor);
|
||||||
|
|
||||||
|
JetType inType = isMutable ? type : null;
|
||||||
|
propertyDescriptor.setType(inType, type, Collections.<TypeParameterDescriptor>emptyList(), ReceiverDescriptor.NO_RECEIVER);
|
||||||
|
propertyDescriptor.initialize(getter, setter);
|
||||||
|
getter.initialize(propertyDescriptor.getOutType());
|
||||||
|
|
||||||
trace.record(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter, propertyDescriptor);
|
trace.record(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter, propertyDescriptor);
|
||||||
return propertyDescriptor;
|
return propertyDescriptor;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public class TopDownAnalyzer {
|
|||||||
new TypeHierarchyResolver(context).process(outerScope, owner, declarations);
|
new TypeHierarchyResolver(context).process(outerScope, owner, declarations);
|
||||||
new DeclarationResolver(context).process();
|
new DeclarationResolver(context).process();
|
||||||
new DelegationResolver(context).process();
|
new DelegationResolver(context).process();
|
||||||
|
lockScopes(context);
|
||||||
new OverrideResolver(context).process();
|
new OverrideResolver(context).process();
|
||||||
new OverloadResolver(context).process();
|
new OverloadResolver(context).process();
|
||||||
if (!context.analyzingBootstrapLibrary()) {
|
if (!context.analyzingBootstrapLibrary()) {
|
||||||
@@ -72,6 +73,18 @@ public class TopDownAnalyzer {
|
|||||||
context.printDebugOutput(System.out);
|
context.printDebugOutput(System.out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void lockScopes(TopDownAnalysisContext context) {
|
||||||
|
for (MutableClassDescriptor mutableClassDescriptor : context.getClasses().values()) {
|
||||||
|
mutableClassDescriptor.lockScopes();
|
||||||
|
}
|
||||||
|
for (MutableClassDescriptor mutableClassDescriptor : context.getObjects().values()) {
|
||||||
|
mutableClassDescriptor.lockScopes();
|
||||||
|
}
|
||||||
|
for (WritableScope namespaceScope : context.getNamespaceScopes().values()) {
|
||||||
|
namespaceScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void processStandardLibraryNamespace(
|
public static void processStandardLibraryNamespace(
|
||||||
@NotNull JetSemanticServices semanticServices,
|
@NotNull JetSemanticServices semanticServices,
|
||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ public class TypeHierarchyResolver {
|
|||||||
context.getNamespaceDescriptors().put(namespace, namespaceDescriptor);
|
context.getNamespaceDescriptors().put(namespace, namespaceDescriptor);
|
||||||
|
|
||||||
WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), new TraceBasedRedeclarationHandler(context.getTrace()));
|
WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), new TraceBasedRedeclarationHandler(context.getTrace()));
|
||||||
|
namespaceScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
context.getNamespaceScopes().put(namespace, namespaceScope);
|
context.getNamespaceScopes().put(namespace, namespaceScope);
|
||||||
context.getDeclaringScopes().put(namespace, outerScope);
|
context.getDeclaringScopes().put(namespace, outerScope);
|
||||||
|
|
||||||
@@ -147,7 +148,7 @@ public class TypeHierarchyResolver {
|
|||||||
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
|
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
|
||||||
Modality.FINAL, Visibility.INTERNAL);//TODO check set mutableClassDescriptor.getVisibility()
|
Modality.FINAL, Visibility.INTERNAL);//TODO check set mutableClassDescriptor.getVisibility()
|
||||||
// TODO : make the constructor private?
|
// TODO : make the constructor private?
|
||||||
mutableClassDescriptor.setPrimaryConstructor(constructorDescriptor);
|
mutableClassDescriptor.setPrimaryConstructor(constructorDescriptor, context.getTrace());
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
context.getTrace().record(CONSTRUCTOR, object, constructorDescriptor);
|
context.getTrace().record(CONSTRUCTOR, object, constructorDescriptor);
|
||||||
}
|
}
|
||||||
@@ -210,7 +211,9 @@ public class TypeHierarchyResolver {
|
|||||||
Collections.<AnnotationDescriptor>emptyList(), // TODO: annotations
|
Collections.<AnnotationDescriptor>emptyList(), // TODO: annotations
|
||||||
name
|
name
|
||||||
);
|
);
|
||||||
namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Namespace member scope"));
|
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Namespace member scope");
|
||||||
|
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
|
namespaceDescriptor.initialize(scope);
|
||||||
owner.addNamespace(namespaceDescriptor);
|
owner.addNamespace(namespaceDescriptor);
|
||||||
if (namespace != null) {
|
if (namespace != null) {
|
||||||
context.getTrace().record(BindingContext.NAMESPACE, namespace, namespaceDescriptor);
|
context.getTrace().record(BindingContext.NAMESPACE, namespace, namespaceDescriptor);
|
||||||
|
|||||||
@@ -9,6 +9,14 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
|||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public interface WritableScope extends JetScope {
|
public interface WritableScope extends JetScope {
|
||||||
|
enum LockLevel {
|
||||||
|
WRITING,
|
||||||
|
BOTH,
|
||||||
|
READING,
|
||||||
|
}
|
||||||
|
|
||||||
|
void changeLockLevel(LockLevel lockLevel);
|
||||||
|
|
||||||
void addLabeledDeclaration(@NotNull DeclarationDescriptor descriptor);
|
void addLabeledDeclaration(@NotNull DeclarationDescriptor descriptor);
|
||||||
|
|
||||||
void addVariableDescriptor(@NotNull VariableDescriptor variableDescriptor);
|
void addVariableDescriptor(@NotNull VariableDescriptor variableDescriptor);
|
||||||
|
|||||||
@@ -55,17 +55,22 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void importScope(@NotNull JetScope imported) {
|
public void importScope(@NotNull JetScope imported) {
|
||||||
|
checkMayWrite();
|
||||||
super.importScope(imported);
|
super.importScope(imported);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void importClassifierAlias(@NotNull String importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor) {
|
public void importClassifierAlias(@NotNull String importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
allDescriptors.add(classifierDescriptor);
|
allDescriptors.add(classifierDescriptor);
|
||||||
super.importClassifierAlias(importedClassifierName, classifierDescriptor);
|
super.importClassifierAlias(importedClassifierName, classifierDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void importNamespaceAlias(String aliasName, NamespaceDescriptor namespaceDescriptor) {
|
public void importNamespaceAlias(String aliasName, NamespaceDescriptor namespaceDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
allDescriptors.add(namespaceDescriptor);
|
allDescriptors.add(namespaceDescriptor);
|
||||||
super.importNamespaceAlias(aliasName, namespaceDescriptor);
|
super.importNamespaceAlias(aliasName, namespaceDescriptor);
|
||||||
}
|
}
|
||||||
@@ -73,6 +78,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
if (!allDescriptorsDone) {
|
if (!allDescriptorsDone) {
|
||||||
allDescriptorsDone = true;
|
allDescriptorsDone = true;
|
||||||
allDescriptors.addAll(getWorkerScope().getAllDescriptors());
|
allDescriptors.addAll(getWorkerScope().getAllDescriptors());
|
||||||
@@ -94,6 +101,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull String labelName) {
|
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull String labelName) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
Collection<DeclarationDescriptor> superResult = super.getDeclarationsByLabel(labelName);
|
Collection<DeclarationDescriptor> superResult = super.getDeclarationsByLabel(labelName);
|
||||||
Map<String, List<DeclarationDescriptor>> labelsToDescriptors = getLabelsToDescriptors();
|
Map<String, List<DeclarationDescriptor>> labelsToDescriptors = getLabelsToDescriptors();
|
||||||
List<DeclarationDescriptor> declarationDescriptors = labelsToDescriptors.get(labelName);
|
List<DeclarationDescriptor> declarationDescriptors = labelsToDescriptors.get(labelName);
|
||||||
@@ -108,6 +117,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addLabeledDeclaration(@NotNull DeclarationDescriptor descriptor) {
|
public void addLabeledDeclaration(@NotNull DeclarationDescriptor descriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
Map<String, List<DeclarationDescriptor>> labelsToDescriptors = getLabelsToDescriptors();
|
Map<String, List<DeclarationDescriptor>> labelsToDescriptors = getLabelsToDescriptors();
|
||||||
String name = descriptor.getName();
|
String name = descriptor.getName();
|
||||||
assert name != null;
|
assert name != null;
|
||||||
@@ -137,6 +148,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addVariableDescriptor(@NotNull VariableDescriptor variableDescriptor) {
|
public void addVariableDescriptor(@NotNull VariableDescriptor variableDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||||
DeclarationDescriptor existingDescriptor = variableClassOrNamespaceDescriptors.get(variableDescriptor.getName());
|
DeclarationDescriptor existingDescriptor = variableClassOrNamespaceDescriptors.get(variableDescriptor.getName());
|
||||||
if (existingDescriptor != null) {
|
if (existingDescriptor != null) {
|
||||||
@@ -149,6 +162,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VariableDescriptor getVariable(@NotNull String name) {
|
public VariableDescriptor getVariable(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||||
DeclarationDescriptor descriptor = variableClassOrNamespaceDescriptors.get(name);
|
DeclarationDescriptor descriptor = variableClassOrNamespaceDescriptors.get(name);
|
||||||
if (descriptor instanceof VariableDescriptor) {
|
if (descriptor instanceof VariableDescriptor) {
|
||||||
@@ -172,6 +187,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
getFunctionGroups().put(functionDescriptor.getName(), functionDescriptor);
|
getFunctionGroups().put(functionDescriptor.getName(), functionDescriptor);
|
||||||
allDescriptors.add(functionDescriptor);
|
allDescriptors.add(functionDescriptor);
|
||||||
}
|
}
|
||||||
@@ -179,6 +196,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
Set<FunctionDescriptor> result = Sets.newLinkedHashSet(getFunctionGroups().get(name));
|
Set<FunctionDescriptor> result = Sets.newLinkedHashSet(getFunctionGroups().get(name));
|
||||||
|
|
||||||
result.addAll(getWorkerScope().getFunctions(name));
|
result.addAll(getWorkerScope().getFunctions(name));
|
||||||
@@ -190,17 +209,23 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTypeParameterDescriptor(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
|
public void addTypeParameterDescriptor(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
String name = typeParameterDescriptor.getName();
|
String name = typeParameterDescriptor.getName();
|
||||||
addClassifierAlias(name, typeParameterDescriptor);
|
addClassifierAlias(name, typeParameterDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addClassifierDescriptor(@NotNull ClassifierDescriptor classDescriptor) {
|
public void addClassifierDescriptor(@NotNull ClassifierDescriptor classDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
addClassifierAlias(classDescriptor.getName(), classDescriptor);
|
addClassifierAlias(classDescriptor.getName(), classDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addClassifierAlias(@NotNull String name, @NotNull ClassifierDescriptor classifierDescriptor) {
|
public void addClassifierAlias(@NotNull String name, @NotNull ClassifierDescriptor classifierDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
checkForRedeclaration(name, classifierDescriptor);
|
checkForRedeclaration(name, classifierDescriptor);
|
||||||
getVariableClassOrNamespaceDescriptors().put(name, classifierDescriptor);
|
getVariableClassOrNamespaceDescriptors().put(name, classifierDescriptor);
|
||||||
allDescriptors.add(classifierDescriptor);
|
allDescriptors.add(classifierDescriptor);
|
||||||
@@ -208,6 +233,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNamespaceAlias(@NotNull String name, @NotNull NamespaceDescriptor namespaceDescriptor) {
|
public void addNamespaceAlias(@NotNull String name, @NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
checkForRedeclaration(name, namespaceDescriptor);
|
checkForRedeclaration(name, namespaceDescriptor);
|
||||||
getNamespaceAliases().put(name, namespaceDescriptor);
|
getNamespaceAliases().put(name, namespaceDescriptor);
|
||||||
allDescriptors.add(namespaceDescriptor);
|
allDescriptors.add(namespaceDescriptor);
|
||||||
@@ -222,6 +249,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||||
DeclarationDescriptor descriptor = variableClassOrNamespaceDescriptors.get(name);
|
DeclarationDescriptor descriptor = variableClassOrNamespaceDescriptors.get(name);
|
||||||
if (descriptor instanceof ClassifierDescriptor) return (ClassifierDescriptor) descriptor;
|
if (descriptor instanceof ClassifierDescriptor) return (ClassifierDescriptor) descriptor;
|
||||||
@@ -234,6 +263,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||||
DeclarationDescriptor oldValue = variableClassOrNamespaceDescriptors.put(namespaceDescriptor.getName(), namespaceDescriptor);
|
DeclarationDescriptor oldValue = variableClassOrNamespaceDescriptors.put(namespaceDescriptor.getName(), namespaceDescriptor);
|
||||||
if (oldValue != null) {
|
if (oldValue != null) {
|
||||||
@@ -244,6 +275,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NamespaceDescriptor getDeclaredNamespace(@NotNull String name) {
|
public NamespaceDescriptor getDeclaredNamespace(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||||
DeclarationDescriptor namespaceDescriptor = variableClassOrNamespaceDescriptors.get(name);
|
DeclarationDescriptor namespaceDescriptor = variableClassOrNamespaceDescriptors.get(name);
|
||||||
if (namespaceDescriptor instanceof NamespaceDescriptor) return (NamespaceDescriptor) namespaceDescriptor;
|
if (namespaceDescriptor instanceof NamespaceDescriptor) return (NamespaceDescriptor) namespaceDescriptor;
|
||||||
@@ -252,6 +285,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
NamespaceDescriptor declaredNamespace = getDeclaredNamespace(name);
|
NamespaceDescriptor declaredNamespace = getDeclaredNamespace(name);
|
||||||
if (declaredNamespace != null) return declaredNamespace;
|
if (declaredNamespace != null) return declaredNamespace;
|
||||||
|
|
||||||
@@ -266,6 +301,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ReceiverDescriptor getImplicitReceiver() {
|
public ReceiverDescriptor getImplicitReceiver() {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
if (implicitReceiver == null) {
|
if (implicitReceiver == null) {
|
||||||
return super.getImplicitReceiver();
|
return super.getImplicitReceiver();
|
||||||
}
|
}
|
||||||
@@ -274,6 +311,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setImplicitReceiver(@NotNull ReceiverDescriptor implicitReceiver) {
|
public void setImplicitReceiver(@NotNull ReceiverDescriptor implicitReceiver) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
if (this.implicitReceiver != null) {
|
if (this.implicitReceiver != null) {
|
||||||
throw new UnsupportedOperationException("Receiver redeclared");
|
throw new UnsupportedOperationException("Receiver redeclared");
|
||||||
}
|
}
|
||||||
@@ -282,6 +321,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
|
public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
if (implicitReceiver != null && implicitReceiver.exists()) {
|
if (implicitReceiver != null && implicitReceiver.exists()) {
|
||||||
result.add(implicitReceiver);
|
result.add(implicitReceiver);
|
||||||
}
|
}
|
||||||
@@ -299,6 +340,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPropertyDescriptorByFieldName(@NotNull String fieldName, @NotNull PropertyDescriptor propertyDescriptor) {
|
public void addPropertyDescriptorByFieldName(@NotNull String fieldName, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
if (!fieldName.startsWith("$")) {
|
if (!fieldName.startsWith("$")) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
@@ -308,6 +351,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
|
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
if (!fieldName.startsWith("$")) {
|
if (!fieldName.startsWith("$")) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
@@ -318,6 +363,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<VariableDescriptor> getDeclaredVariables() {
|
public List<VariableDescriptor> getDeclaredVariables() {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
List<VariableDescriptor> result = Lists.newArrayList();
|
List<VariableDescriptor> result = Lists.newArrayList();
|
||||||
for (DeclarationDescriptor descriptor : getVariableClassOrNamespaceDescriptors().values()) {
|
for (DeclarationDescriptor descriptor : getVariableClassOrNamespaceDescriptors().values()) {
|
||||||
if (descriptor instanceof VariableDescriptor) {
|
if (descriptor instanceof VariableDescriptor) {
|
||||||
@@ -334,6 +381,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WritableScopeImpl setDebugName(@NotNull String debugName) {
|
public WritableScopeImpl setDebugName(@NotNull String debugName) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
super.setDebugName(debugName);
|
super.setDebugName(debugName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
+46
@@ -31,7 +31,36 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
|||||||
this.redeclarationHandler = redeclarationHandler;
|
this.redeclarationHandler = redeclarationHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private LockLevel lockLevel = LockLevel.WRITING;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changeLockLevel(LockLevel lockLevel) {
|
||||||
|
if (lockLevel.ordinal() < this.lockLevel.ordinal()) {
|
||||||
|
throw new IllegalStateException("cannot lower lock level from " + this.lockLevel + " to " + lockLevel);
|
||||||
|
}
|
||||||
|
this.lockLevel = lockLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void checkMayRead() {
|
||||||
|
if (lockLevel != LockLevel.READING && lockLevel != LockLevel.BOTH) {
|
||||||
|
throw new IllegalStateException("cannot read with lock level " + lockLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void checkMayWrite() {
|
||||||
|
if (lockLevel != LockLevel.WRITING && lockLevel != LockLevel.BOTH) {
|
||||||
|
throw new IllegalStateException("cannot write with lock level " + lockLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public WritableScopeWithImports setDebugName(@NotNull String debugName) {
|
public WritableScopeWithImports setDebugName(@NotNull String debugName) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
assert this.debugName == null : this.debugName;
|
assert this.debugName == null : this.debugName;
|
||||||
this.debugName = debugName;
|
this.debugName = debugName;
|
||||||
return this;
|
return this;
|
||||||
@@ -47,12 +76,16 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void importScope(@NotNull JetScope imported) {
|
public void importScope(@NotNull JetScope imported) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
getImports().add(0, imported);
|
getImports().add(0, imported);
|
||||||
currentIndividualImportScope = null;
|
currentIndividualImportScope = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
|
public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
super.getImplicitReceiversHierarchy(result);
|
super.getImplicitReceiversHierarchy(result);
|
||||||
// Imported scopes come with their receivers
|
// Imported scopes come with their receivers
|
||||||
// Example: class member resolution scope imports a scope of it's class object
|
// Example: class member resolution scope imports a scope of it's class object
|
||||||
@@ -67,6 +100,8 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VariableDescriptor getVariable(@NotNull String name) {
|
public VariableDescriptor getVariable(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
// Meaningful lookup goes here
|
// Meaningful lookup goes here
|
||||||
for (JetScope imported : getImports()) {
|
for (JetScope imported : getImports()) {
|
||||||
VariableDescriptor importedDescriptor = imported.getVariable(name);
|
VariableDescriptor importedDescriptor = imported.getVariable(name);
|
||||||
@@ -80,6 +115,8 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
if (getImports().isEmpty()) {
|
if (getImports().isEmpty()) {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
@@ -92,6 +129,8 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
for (JetScope imported : getImports()) {
|
for (JetScope imported : getImports()) {
|
||||||
ClassifierDescriptor importedClassifier = imported.getClassifier(name);
|
ClassifierDescriptor importedClassifier = imported.getClassifier(name);
|
||||||
if (importedClassifier != null) {
|
if (importedClassifier != null) {
|
||||||
@@ -103,6 +142,8 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
for (JetScope imported : getImports()) {
|
for (JetScope imported : getImports()) {
|
||||||
NamespaceDescriptor importedDescriptor = imported.getNamespace(name);
|
NamespaceDescriptor importedDescriptor = imported.getNamespace(name);
|
||||||
if (importedDescriptor != null) {
|
if (importedDescriptor != null) {
|
||||||
@@ -115,6 +156,7 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
|||||||
private WritableScope getCurrentIndividualImportScope() {
|
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");
|
||||||
|
writableScope.changeLockLevel(LockLevel.BOTH);
|
||||||
importScope(writableScope);
|
importScope(writableScope);
|
||||||
currentIndividualImportScope = writableScope;
|
currentIndividualImportScope = writableScope;
|
||||||
}
|
}
|
||||||
@@ -123,12 +165,16 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void importClassifierAlias(@NotNull String importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor) {
|
public void importClassifierAlias(@NotNull String importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
getCurrentIndividualImportScope().addClassifierAlias(importedClassifierName, classifierDescriptor);
|
getCurrentIndividualImportScope().addClassifierAlias(importedClassifierName, classifierDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void importNamespaceAlias(String aliasName, NamespaceDescriptor namespaceDescriptor) {
|
public void importNamespaceAlias(String aliasName, NamespaceDescriptor namespaceDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
getCurrentIndividualImportScope().addNamespaceAlias(aliasName, namespaceDescriptor);
|
getCurrentIndividualImportScope().addNamespaceAlias(aliasName, namespaceDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,30 +25,40 @@ public class WriteThroughScope extends WritableScopeWithImports {
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
|
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
return writableWorker.getPropertyByFieldReference(fieldName);
|
return writableWorker.getPropertyByFieldReference(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(String labelName) {
|
public Collection<DeclarationDescriptor> getDeclarationsByLabel(String labelName) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
return writableWorker.getDeclarationsByLabel(labelName);
|
return writableWorker.getDeclarationsByLabel(labelName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public DeclarationDescriptor getContainingDeclaration() {
|
public DeclarationDescriptor getContainingDeclaration() {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
return writableWorker.getContainingDeclaration();
|
return writableWorker.getContainingDeclaration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public ReceiverDescriptor getImplicitReceiver() {
|
public ReceiverDescriptor getImplicitReceiver() {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
return writableWorker.getImplicitReceiver();
|
return writableWorker.getImplicitReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
Set<FunctionDescriptor> result = Sets.newLinkedHashSet();
|
Set<FunctionDescriptor> result = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
result.addAll(writableWorker.getFunctions(name));
|
result.addAll(writableWorker.getFunctions(name));
|
||||||
@@ -63,6 +73,8 @@ public class WriteThroughScope extends WritableScopeWithImports {
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public VariableDescriptor getVariable(@NotNull String name) {
|
public VariableDescriptor getVariable(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
VariableDescriptor variable = writableWorker.getVariable(name);
|
VariableDescriptor variable = writableWorker.getVariable(name);
|
||||||
if (variable != null) return variable;
|
if (variable != null) return variable;
|
||||||
|
|
||||||
@@ -75,6 +87,8 @@ public class WriteThroughScope extends WritableScopeWithImports {
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
NamespaceDescriptor namespace = writableWorker.getNamespace(name);
|
NamespaceDescriptor namespace = writableWorker.getNamespace(name);
|
||||||
if (namespace != null) return namespace;
|
if (namespace != null) return namespace;
|
||||||
|
|
||||||
@@ -87,6 +101,8 @@ public class WriteThroughScope extends WritableScopeWithImports {
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
ClassifierDescriptor classifier = writableWorker.getClassifier(name);
|
ClassifierDescriptor classifier = writableWorker.getClassifier(name);
|
||||||
if (classifier != null) return classifier;
|
if (classifier != null) return classifier;
|
||||||
|
|
||||||
@@ -98,68 +114,94 @@ public class WriteThroughScope extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addLabeledDeclaration(@NotNull DeclarationDescriptor descriptor) {
|
public void addLabeledDeclaration(@NotNull DeclarationDescriptor descriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
writableWorker.addLabeledDeclaration(descriptor); // TODO : review
|
writableWorker.addLabeledDeclaration(descriptor); // TODO : review
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addVariableDescriptor(@NotNull VariableDescriptor variableDescriptor) {
|
public void addVariableDescriptor(@NotNull VariableDescriptor variableDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
writableWorker.addVariableDescriptor(variableDescriptor);
|
writableWorker.addVariableDescriptor(variableDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
writableWorker.addFunctionDescriptor(functionDescriptor);
|
writableWorker.addFunctionDescriptor(functionDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTypeParameterDescriptor(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
|
public void addTypeParameterDescriptor(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
writableWorker.addTypeParameterDescriptor(typeParameterDescriptor);
|
writableWorker.addTypeParameterDescriptor(typeParameterDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addClassifierDescriptor(@NotNull ClassifierDescriptor classDescriptor) {
|
public void addClassifierDescriptor(@NotNull ClassifierDescriptor classDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
writableWorker.addClassifierDescriptor(classDescriptor);
|
writableWorker.addClassifierDescriptor(classDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addClassifierAlias(@NotNull String name, @NotNull ClassifierDescriptor classifierDescriptor) {
|
public void addClassifierAlias(@NotNull String name, @NotNull ClassifierDescriptor classifierDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
writableWorker.addClassifierAlias(name, classifierDescriptor);
|
writableWorker.addClassifierAlias(name, classifierDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNamespaceAlias(@NotNull String name, @NotNull NamespaceDescriptor namespaceDescriptor) {
|
public void addNamespaceAlias(@NotNull String name, @NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
writableWorker.addNamespaceAlias(name, namespaceDescriptor);
|
writableWorker.addNamespaceAlias(name, namespaceDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
writableWorker.addNamespace(namespaceDescriptor);
|
writableWorker.addNamespace(namespaceDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public NamespaceDescriptor getDeclaredNamespace(@NotNull String name) {
|
public NamespaceDescriptor getDeclaredNamespace(@NotNull String name) {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
return writableWorker.getDeclaredNamespace(name);
|
return writableWorker.getDeclaredNamespace(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPropertyDescriptorByFieldName(@NotNull String fieldName, @NotNull PropertyDescriptor propertyDescriptor) {
|
public void addPropertyDescriptorByFieldName(@NotNull String fieldName, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
writableWorker.addPropertyDescriptorByFieldName(fieldName, propertyDescriptor);
|
writableWorker.addPropertyDescriptorByFieldName(fieldName, propertyDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void importScope(@NotNull JetScope imported) {
|
public void importScope(@NotNull JetScope imported) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
super.importScope(imported); //
|
super.importScope(imported); //
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setImplicitReceiver(@NotNull ReceiverDescriptor implicitReceiver) {
|
public void setImplicitReceiver(@NotNull ReceiverDescriptor implicitReceiver) {
|
||||||
|
checkMayWrite();
|
||||||
|
|
||||||
writableWorker.setImplicitReceiver(implicitReceiver);
|
writableWorker.setImplicitReceiver(implicitReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
if (allDescriptors == null) {
|
if (allDescriptors == null) {
|
||||||
allDescriptors = Lists.newArrayList();
|
allDescriptors = Lists.newArrayList();
|
||||||
allDescriptors.addAll(writableWorker.getAllDescriptors());
|
allDescriptors.addAll(writableWorker.getAllDescriptors());
|
||||||
@@ -170,6 +212,8 @@ public class WriteThroughScope extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetScope getOuterScope() {
|
public JetScope getOuterScope() {
|
||||||
|
checkMayRead();
|
||||||
|
|
||||||
return getWorkerScope();
|
return getWorkerScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,6 +194,8 @@ public class JetStandardClasses {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.DO_NOTHING).setDebugName("JetStandardClasses.STANDARD_CLASSES");
|
WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.DO_NOTHING).setDebugName("JetStandardClasses.STANDARD_CLASSES");
|
||||||
|
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
|
|
||||||
STANDARD_CLASSES = writableScope;
|
STANDARD_CLASSES = writableScope;
|
||||||
writableScope.addClassifierAlias("Unit", getTuple(0));
|
writableScope.addClassifierAlias("Unit", getTuple(0));
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
|||||||
import org.jetbrains.jet.lang.resolve.*;
|
import org.jetbrains.jet.lang.resolve.*;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||||
import org.jetbrains.jet.plugin.JetFileType;
|
import org.jetbrains.jet.plugin.JetFileType;
|
||||||
|
|
||||||
@@ -133,6 +134,7 @@ public class JetStandardLibrary {
|
|||||||
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this);
|
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this);
|
||||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||||
WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope");
|
WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope");
|
||||||
|
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
// this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
|
// this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
|
||||||
// bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations());
|
// bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations());
|
||||||
TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace());
|
TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace());
|
||||||
|
|||||||
+1
@@ -140,6 +140,7 @@ public class ExpressionTypingServices {
|
|||||||
|
|
||||||
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
|
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
|
||||||
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace)).setDebugName("getBlockReturnedType");
|
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace)).setDebugName("getBlockReturnedType");
|
||||||
|
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context);
|
return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -13,6 +13,7 @@ import org.jetbrains.jet.lang.psi.JetExpression;
|
|||||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.TraceBasedRedeclarationHandler;
|
import org.jetbrains.jet.lang.resolve.TraceBasedRedeclarationHandler;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||||
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
||||||
@@ -42,7 +43,9 @@ public class ExpressionTypingUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static WritableScopeImpl newWritableScopeImpl(ExpressionTypingContext context) {
|
public static WritableScopeImpl newWritableScopeImpl(ExpressionTypingContext context) {
|
||||||
return new WritableScopeImpl(context.scope, context.scope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.trace));
|
WritableScopeImpl scope = new WritableScopeImpl(context.scope, context.scope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.trace));
|
||||||
|
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isBoolean(@NotNull JetSemanticServices semanticServices, @NotNull JetType type) {
|
public static boolean isBoolean(@NotNull JetSemanticServices semanticServices, @NotNull JetType type) {
|
||||||
|
|||||||
+2
-2
@@ -243,7 +243,7 @@ class Outer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ForwardAccessToBackingField() { //kt-147
|
class ForwardAccessToBackingField() { //kt-147
|
||||||
val a = <!UNRESOLVED_REFERENCE, UNINITIALIZED_VARIABLE!>$a<!> // error
|
val a = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, UNINITIALIZED_VARIABLE!>$a<!> // error
|
||||||
val b = <!UNINITIALIZED_VARIABLE!>$c<!> // error
|
val b = <!UNINITIALIZED_VARIABLE!>$c<!> // error
|
||||||
val c = 1
|
val c = 1
|
||||||
}
|
}
|
||||||
@@ -349,4 +349,4 @@ fun test(m : M) {
|
|||||||
fun test1(m : M) {
|
fun test1(m : M) {
|
||||||
<!VAL_REASSIGNMENT!>m.x<!>++
|
<!VAL_REASSIGNMENT!>m.x<!>++
|
||||||
m.y--
|
m.y--
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
class Cyclic() {
|
class Cyclic() {
|
||||||
val a = <!UNRESOLVED_REFERENCE, UNINITIALIZED_VARIABLE!>$a<!>
|
val a = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, UNINITIALIZED_VARIABLE!>$a<!>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// http://youtrack.jetbrains.net/issue/KT-421
|
||||||
|
// KT-421 Strange 'unresolved' bug with backing fields
|
||||||
|
|
||||||
|
class A() {
|
||||||
|
val c = 1
|
||||||
|
val a = <!UNINITIALIZED_VARIABLE!>b<!>
|
||||||
|
val b = $c // '$c' is unresolved
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
|||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
WritableScopeImpl scope = new WritableScopeImpl(libraryScope, root, RedeclarationHandler.DO_NOTHING);
|
WritableScopeImpl scope = new WritableScopeImpl(libraryScope, root, RedeclarationHandler.DO_NOTHING);
|
||||||
assert classDescriptor instanceof ClassifierDescriptor;
|
assert classDescriptor instanceof ClassifierDescriptor;
|
||||||
scope.addClassifierDescriptor((ClassifierDescriptor) classDescriptor);
|
scope.addClassifierDescriptor((ClassifierDescriptor) classDescriptor);
|
||||||
|
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -545,6 +545,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(getProject(), semanticServices, JetTestUtils.DUMMY_TRACE);
|
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(getProject(), semanticServices, JetTestUtils.DUMMY_TRACE);
|
||||||
writableScope.importScope(new JavaPackageScope("", null, javaSemanticServices));
|
writableScope.importScope(new JavaPackageScope("", null, javaSemanticServices));
|
||||||
writableScope.importScope(new JavaPackageScope("java.lang", null, javaSemanticServices));
|
writableScope.importScope(new JavaPackageScope("java.lang", null, javaSemanticServices));
|
||||||
|
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
return writableScope;
|
return writableScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,6 +642,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
trace.record(BindingContext.CLASS, classElement, classDescriptor);
|
trace.record(BindingContext.CLASS, classElement, classDescriptor);
|
||||||
|
|
||||||
final WritableScope parameterScope = new WritableScopeImpl(scope, classDescriptor, new TraceBasedRedeclarationHandler(trace));
|
final WritableScope parameterScope = new WritableScopeImpl(scope, classDescriptor, new TraceBasedRedeclarationHandler(trace));
|
||||||
|
parameterScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
|
|
||||||
// This call has side-effects on the parameterScope (fills it in)
|
// This call has side-effects on the parameterScope (fills it in)
|
||||||
List<TypeParameterDescriptor> typeParameters
|
List<TypeParameterDescriptor> typeParameters
|
||||||
@@ -660,6 +662,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD);
|
boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD);
|
||||||
|
|
||||||
final WritableScope memberDeclarations = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, new TraceBasedRedeclarationHandler(trace));
|
final WritableScope memberDeclarations = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, new TraceBasedRedeclarationHandler(trace));
|
||||||
|
memberDeclarations.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
|
|
||||||
List<JetDeclaration> declarations = classElement.getDeclarations();
|
List<JetDeclaration> declarations = classElement.getDeclarations();
|
||||||
for (JetDeclaration declaration : declarations) {
|
for (JetDeclaration declaration : declarations) {
|
||||||
|
|||||||
Reference in New Issue
Block a user