$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 @NotNull
Collection<DeclarationDescriptor> getDeclarationsByLabel(String labelName); 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) { public Collection<DeclarationDescriptor> getDeclarationsByLabel(String labelName) {
return scope.getDeclarationsByLabel(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) { public Collection<DeclarationDescriptor> getDeclarationsByLabel(String labelName) {
return Collections.emptyList(); 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) { public Collection<DeclarationDescriptor> getDeclarationsByLabel(String labelName) {
throw new UnsupportedOperationException(); // TODO 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); declaringScopes.put(property, declaringScope);
PropertyDescriptor descriptor = classDescriptorResolver.resolvePropertyDescriptor(declaringScope.getContainingDeclaration(), declaringScope, property); PropertyDescriptor descriptor = classDescriptorResolver.resolvePropertyDescriptor(declaringScope.getContainingDeclaration(), declaringScope, property);
declaringScope.addVariableDescriptor(descriptor); declaringScope.addVariableDescriptor(descriptor);
declaringScope.addPropertyDescriptorByFieldName("$" + descriptor.getName(), descriptor);
properties.put(property, descriptor); properties.put(property, descriptor);
} }
@@ -17,6 +17,10 @@ public class WritableScope extends JetScopeAdapter {
@NotNull @NotNull
private final DeclarationDescriptor ownerDeclarationDescriptor; private final DeclarationDescriptor ownerDeclarationDescriptor;
// FieldNames include "$"
@Nullable
private Map<String, PropertyDescriptor> propertyDescriptorsByFieldNames;
@Nullable @Nullable
private Map<String, VariableDescriptor> variableDescriptors; private Map<String, VariableDescriptor> variableDescriptors;
@Nullable @Nullable
@@ -270,4 +274,24 @@ public class WritableScope extends JetScopeAdapter {
} }
this.thisType = thisType; 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 throw new UnsupportedOperationException(); // TODO
} }
@Override
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
return null;
}
@Override @Override
public ClassifierDescriptor getClassifier(@NotNull String name) { public ClassifierDescriptor getClassifier(@NotNull String name) {
for (PsiClass innerClass : psiClass.getAllInnerClasses()) { for (PsiClass innerClass : psiClass.getAllInnerClasses()) {
@@ -53,6 +53,11 @@ public class ErrorUtils {
return Collections.emptyList(); return Collections.emptyList();
} }
@Override
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
return null; // TODO : review
}
}; };
private static final FunctionGroup ERROR_FUNCTION_GROUP = new FunctionGroup() { private static final FunctionGroup ERROR_FUNCTION_GROUP = new FunctionGroup() {
@@ -440,6 +440,18 @@ public class JetTypeInferrer {
public void visitSimpleNameExpression(JetSimpleNameExpression expression) { public void visitSimpleNameExpression(JetSimpleNameExpression expression) {
// TODO : other members // TODO : other members
// TODO : type substitutions??? // TODO : type substitutions???
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(); String referencedName = expression.getReferencedName();
if (referencedName != null) { if (referencedName != null) {
VariableDescriptor variable = scope.getVariable(referencedName); VariableDescriptor variable = scope.getVariable(referencedName);
@@ -461,6 +473,7 @@ public class JetTypeInferrer {
semanticServices.getErrorHandler().unresolvedReference(expression); semanticServices.getErrorHandler().unresolvedReference(expression);
} }
} }
}
@Override @Override
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) { public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
+4 -1
View File
@@ -1,6 +1,9 @@
var x : Int = 1 + x var x : Int = 1 + x
get() : Int = 1 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 val xx : Int = 1 + x
get() : Int = 1 get() : Int = 1