Blocks denoted in the BindingContext

This commit is contained in:
Andrey Breslav
2011-04-01 16:10:48 +04:00
parent 76dc0376e5
commit 7433859a51
4 changed files with 20 additions and 0 deletions
@@ -25,4 +25,6 @@ public interface BindingContext {
JetType resolveTypeReference(JetTypeReference typeReference); JetType resolveTypeReference(JetTypeReference typeReference);
PsiElement resolveToDeclarationPsiElement(JetReferenceExpression referenceExpression); PsiElement resolveToDeclarationPsiElement(JetReferenceExpression referenceExpression);
PsiElement getDeclarationPsiElement(DeclarationDescriptor descriptor); PsiElement getDeclarationPsiElement(DeclarationDescriptor descriptor);
boolean isBlock(JetFunctionLiteralExpression expression);
} }
@@ -6,7 +6,9 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* @author abreslav * @author abreslav
@@ -18,6 +20,7 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
private final Map<JetTypeReference, JetType> types = new HashMap<JetTypeReference, JetType>(); private final Map<JetTypeReference, JetType> types = new HashMap<JetTypeReference, JetType>();
private final Map<DeclarationDescriptor, PsiElement> descriptorToDeclarations = new HashMap<DeclarationDescriptor, PsiElement>(); private final Map<DeclarationDescriptor, PsiElement> descriptorToDeclarations = new HashMap<DeclarationDescriptor, PsiElement>();
private final Map<PsiElement, DeclarationDescriptor> declarationsToDescriptors = new HashMap<PsiElement, DeclarationDescriptor>(); private final Map<PsiElement, DeclarationDescriptor> declarationsToDescriptors = new HashMap<PsiElement, DeclarationDescriptor>();
private final Set<JetFunctionLiteralExpression> blocks = new HashSet<JetFunctionLiteralExpression>();
private JetScope toplevelScope; private JetScope toplevelScope;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -53,6 +56,11 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
declarationsToDescriptors.put(declaration, descriptor.getOriginal()); declarationsToDescriptors.put(declaration, descriptor.getOriginal());
} }
@Override
public void recordBlock(JetFunctionLiteralExpression expression) {
blocks.add(expression);
}
public void setToplevelScope(JetScope toplevelScope) { public void setToplevelScope(JetScope toplevelScope) {
this.toplevelScope = toplevelScope; this.toplevelScope = toplevelScope;
} }
@@ -122,4 +130,9 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
public PsiElement getDeclarationPsiElement(DeclarationDescriptor descriptor) { public PsiElement getDeclarationPsiElement(DeclarationDescriptor descriptor) {
return descriptorToDeclarations.get(descriptor.getOriginal()); return descriptorToDeclarations.get(descriptor.getOriginal());
} }
@Override
public boolean isBlock(JetFunctionLiteralExpression expression) {
return expression.hasParameterSpecification() || blocks.contains(expression);
}
} }
@@ -34,6 +34,10 @@ public class BindingTrace {
} }
public void recordBlock(JetFunctionLiteralExpression expression) {
}
public void removeReferenceResolution(@NotNull JetReferenceExpression referenceExpression) { public void removeReferenceResolution(@NotNull JetReferenceExpression referenceExpression) {
} }
@@ -378,6 +378,7 @@ public class JetTypeInferrer {
@Override @Override
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) { public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
if (preferBlock && !expression.hasParameterSpecification()) { if (preferBlock && !expression.hasParameterSpecification()) {
trace.recordBlock(expression);
result = getBlockReturnedType(scope, expression.getBody(), LabeledJumpDomain.ERROR); result = getBlockReturnedType(scope, expression.getBody(), LabeledJumpDomain.ERROR);
return; return;
} }