$fieldName resolved

This commit is contained in:
Andrey Breslav
2011-04-18 22:54:32 +04:00
parent 78f3eac62a
commit d9c08e38da
10 changed files with 92 additions and 19 deletions
@@ -38,4 +38,11 @@ public interface JetScope {
@NotNull
Collection<DeclarationDescriptor> getDeclarationsByLabel(String labelName);
/**
* @param fieldName includes the "$"
* @return the property declaring this field, if any
*/
@Nullable
PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName);
}
@@ -54,4 +54,9 @@ public class JetScopeAdapter implements JetScope {
public Collection<DeclarationDescriptor> getDeclarationsByLabel(String labelName) {
return scope.getDeclarationsByLabel(labelName);
}
@Override
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
return scope.getPropertyByFieldReference(fieldName);
}
}
@@ -42,4 +42,9 @@ public abstract class JetScopeImpl implements JetScope {
public Collection<DeclarationDescriptor> getDeclarationsByLabel(String labelName) {
return Collections.emptyList();
}
@Override
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
return null;
}
}
@@ -73,4 +73,9 @@ public class SubstitutingScope implements JetScope {
public Collection<DeclarationDescriptor> getDeclarationsByLabel(String labelName) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
throw new UnsupportedOperationException(); // TODO
}
}
@@ -243,6 +243,7 @@ public class TopDownAnalyzer {
declaringScopes.put(property, declaringScope);
PropertyDescriptor descriptor = classDescriptorResolver.resolvePropertyDescriptor(declaringScope.getContainingDeclaration(), declaringScope, property);
declaringScope.addVariableDescriptor(descriptor);
declaringScope.addPropertyDescriptorByFieldName("$" + descriptor.getName(), descriptor);
properties.put(property, descriptor);
}
@@ -17,6 +17,10 @@ public class WritableScope extends JetScopeAdapter {
@NotNull
private final DeclarationDescriptor ownerDeclarationDescriptor;
// FieldNames include "$"
@Nullable
private Map<String, PropertyDescriptor> propertyDescriptorsByFieldNames;
@Nullable
private Map<String, VariableDescriptor> variableDescriptors;
@Nullable
@@ -270,4 +274,24 @@ public class WritableScope extends JetScopeAdapter {
}
this.thisType = thisType;
}
@SuppressWarnings({"NullableProblems"})
@NotNull
private Map<String, PropertyDescriptor> getPropertyDescriptorsByFieldNames() {
if (propertyDescriptorsByFieldNames == null) {
propertyDescriptorsByFieldNames = new HashMap<String, PropertyDescriptor>();
}
return propertyDescriptorsByFieldNames;
}
public void addPropertyDescriptorByFieldName(@NotNull String fieldName, PropertyDescriptor propertyDescriptor) {
getPropertyDescriptorsByFieldNames().put(fieldName, propertyDescriptor);
}
@Override
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
PropertyDescriptor descriptor = getPropertyDescriptorsByFieldNames().get(fieldName);
if (descriptor != null) return descriptor;
return super.getPropertyByFieldReference(fieldName);
}
}
@@ -37,6 +37,11 @@ public class JavaClassMembersScope implements JetScope {
throw new UnsupportedOperationException(); // TODO
}
@Override
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
return null;
}
@Override
public ClassifierDescriptor getClassifier(@NotNull String name) {
for (PsiClass innerClass : psiClass.getAllInnerClasses()) {
@@ -53,6 +53,11 @@ public class ErrorUtils {
return Collections.emptyList();
}
@Override
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
return null; // TODO : review
}
};
private static final FunctionGroup ERROR_FUNCTION_GROUP = new FunctionGroup() {
@@ -440,25 +440,38 @@ public class JetTypeInferrer {
public void visitSimpleNameExpression(JetSimpleNameExpression expression) {
// TODO : other members
// TODO : type substitutions???
String referencedName = expression.getReferencedName();
if (referencedName != null) {
VariableDescriptor variable = scope.getVariable(referencedName);
if (variable != null) {
trace.recordReferenceResolution(expression, variable);
result = variable.getOutType();
if (result == null) {
semanticServices.getErrorHandler().genericError(expression.getNode(), "This variable is not readable in this context");
}
return;
} else {
NamespaceDescriptor namespace = scope.getNamespace(referencedName);
if (namespace != null) {
trace.recordReferenceResolution(expression, namespace);
result = namespace.getNamespaceType();
return;
}
if (expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
PropertyDescriptor property = scope.getPropertyByFieldReference(expression.getReferencedName());
if (property == null) {
semanticServices.getErrorHandler().unresolvedReference(expression);
}
else {
trace.recordReferenceResolution(expression, property);
result = property.getOutType();
}
}
else {
assert expression.getReferencedNameElementType() == JetTokens.IDENTIFIER;
String referencedName = expression.getReferencedName();
if (referencedName != null) {
VariableDescriptor variable = scope.getVariable(referencedName);
if (variable != null) {
trace.recordReferenceResolution(expression, variable);
result = variable.getOutType();
if (result == null) {
semanticServices.getErrorHandler().genericError(expression.getNode(), "This variable is not readable in this context");
}
return;
} else {
NamespaceDescriptor namespace = scope.getNamespace(referencedName);
if (namespace != null) {
trace.recordReferenceResolution(expression, namespace);
result = namespace.getNamespaceType();
return;
}
}
semanticServices.getErrorHandler().unresolvedReference(expression);
}
semanticServices.getErrorHandler().unresolvedReference(expression);
}
}
+4 -1
View File
@@ -1,6 +1,9 @@
var x : Int = 1 + x
get() : Int = 1
set(<error>ref</error> value : <error>Long</error>) {$x = value}
set(<error>ref</error> value : <error>Long</error>) {
$x = value.int
$x = <error>1.lng</error>
}
val xx : Int = 1 + x
get() : Int = 1