Drop JetWhenConditionWithExpression, replaced with JetWhenConditionIsPattern with JetExpressionPattern inside
This commit is contained in:
@@ -136,7 +136,6 @@ public interface JetNodeTypes {
|
||||
JetNodeType WHEN_CONDITION_IN_RANGE = new JetNodeType("WHEN_CONDITION_IN_RANGE", JetWhenConditionInRange.class);
|
||||
JetNodeType WHEN_CONDITION_IS_PATTERN = new JetNodeType("WHEN_CONDITION_IS_PATTERN", JetWhenConditionIsPattern.class);
|
||||
JetNodeType WHEN_CONDITION_CALL = new JetNodeType("WHEN_CONDITION_CALL", JetWhenConditionCall.class);
|
||||
JetNodeType WHEN_CONDITION_EXPRESSION = new JetNodeType("WHEN_CONDITION_EXPRESSION", JetWhenConditionWithExpression.class);
|
||||
|
||||
JetNodeType NAMESPACE_NAME = new JetNodeType("NAMESPACE_NAME", JetContainerNode.class);
|
||||
}
|
||||
|
||||
@@ -1837,15 +1837,16 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
private StackValue generateWhenCondition(Type subjectType, int subjectLocal, JetWhenCondition condition,
|
||||
@Nullable Label nextEntry) {
|
||||
StackValue conditionValue;
|
||||
if (condition instanceof JetWhenConditionWithExpression) {
|
||||
v.load(subjectLocal, subjectType);
|
||||
JetExpression condExpression = ((JetWhenConditionWithExpression) condition).getExpression();
|
||||
Type condType = isNumberPrimitive(subjectType) ? expressionType(condExpression) : OBJECT_TYPE;
|
||||
gen(condExpression, condType);
|
||||
generateEqualsForExpressionsOnStack(JetTokens.EQEQ, subjectType, condType);
|
||||
conditionValue = myStack.pop();
|
||||
}
|
||||
else if (condition instanceof JetWhenConditionInRange) {
|
||||
// if (condition instanceof JetWhenConditionWithExpression) {
|
||||
// v.load(subjectLocal, subjectType);
|
||||
// JetExpression condExpression = ((JetWhenConditionWithExpression) condition).getExpression();
|
||||
// Type condType = isNumberPrimitive(subjectType) ? expressionType(condExpression) : OBJECT_TYPE;
|
||||
// gen(condExpression, condType);
|
||||
// generateEqualsForExpressionsOnStack(JetTokens.EQEQ, subjectType, condType);
|
||||
// conditionValue = myStack.pop();
|
||||
// }
|
||||
// else
|
||||
if (condition instanceof JetWhenConditionInRange) {
|
||||
JetExpression range = ((JetWhenConditionInRange) condition).getRangeExpression();
|
||||
gen(range, RANGE_TYPE);
|
||||
new StackValue.Local(subjectLocal, subjectType).put(INTEGER_TYPE, v);
|
||||
|
||||
@@ -648,11 +648,6 @@ public class JetControlFlowProcessor {
|
||||
condition.accept(new JetVisitor() {
|
||||
private final JetVisitor conditionVisitor = this;
|
||||
|
||||
@Override
|
||||
public void visitWhenConditionWithExpression(JetWhenConditionWithExpression condition) {
|
||||
value(condition.getExpression(), false, inCondition); // TODO : inCondition?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitWhenConditionCall(JetWhenConditionCall condition) {
|
||||
value(condition.getCallSuffixExpression(), false, inCondition); // TODO : inCondition?
|
||||
|
||||
@@ -758,18 +758,16 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
else {
|
||||
mark.drop();
|
||||
}
|
||||
// myJetParsing.parseTypeArgumentList();
|
||||
// if (at(LPAR)) {
|
||||
// parseValueArgumentList();
|
||||
// }
|
||||
condition.done(WHEN_CONDITION_CALL);
|
||||
} else {
|
||||
PsiBuilder.Marker expressionPattern = mark();
|
||||
if (atSet(WHEN_CONDITION_RECOVERY_SET_WITH_DOUBLE_ARROW)) {
|
||||
error("Expecting an element, is-condition or in-condition");
|
||||
} else {
|
||||
parseExpression();
|
||||
}
|
||||
condition.done(WHEN_CONDITION_EXPRESSION);
|
||||
expressionPattern.done(EXPRESSION_PATTERN);
|
||||
condition.done(WHEN_CONDITION_IS_PATTERN);
|
||||
}
|
||||
myBuilder.restoreNewlinesState();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -11,7 +12,7 @@ public class JetExpressionPattern extends JetPattern {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable @IfNotParsed
|
||||
public JetExpression getExpression() {
|
||||
return findChildByClass(JetExpression.class);
|
||||
}
|
||||
|
||||
@@ -354,10 +354,6 @@ public class JetVisitor extends PsiElementVisitor {
|
||||
visitExpression(expression);
|
||||
}
|
||||
|
||||
public void visitWhenConditionWithExpression(JetWhenConditionWithExpression condition) {
|
||||
visitJetElement(condition);
|
||||
}
|
||||
|
||||
public void visitWhenConditionCall(JetWhenConditionCall condition) {
|
||||
visitJetElement(condition);
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetWhenConditionWithExpression extends JetWhenCondition {
|
||||
public JetWhenConditionWithExpression(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@IfNotParsed
|
||||
public JetExpression getExpression() {
|
||||
return findChildByClass(JetExpression.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull JetVisitor visitor) {
|
||||
visitor.visitWhenConditionWithExpression(this);
|
||||
}
|
||||
}
|
||||
@@ -1345,18 +1345,6 @@ public class JetTypeInferrer {
|
||||
private DataFlowInfo checkWhenCondition(@Nullable final JetExpression subjectExpression, final JetType subjectType, JetWhenCondition condition, final WritableScope scopeToExtend, final VariableDescriptor... subjectVariables) {
|
||||
final DataFlowInfo[] newDataFlowInfo = new DataFlowInfo[]{context.dataFlowInfo};
|
||||
condition.accept(new JetVisitor() {
|
||||
@Override
|
||||
public void visitWhenConditionWithExpression(JetWhenConditionWithExpression condition) {
|
||||
JetExpression conditionExpression = condition.getExpression();
|
||||
if (conditionExpression != null) {
|
||||
JetType type = getType(context.scope, conditionExpression, false);
|
||||
if (type != null && subjectType != null) {
|
||||
if (TypeUtils.intersect(semanticServices.getTypeChecker(), Sets.newHashSet(subjectType, type)) == null) {
|
||||
context.trace.getErrorHandler().genericError(conditionExpression.getNode(), "This condition can never hold");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitWhenConditionCall(JetWhenConditionCall condition) {
|
||||
|
||||
@@ -310,14 +310,15 @@ JetFile: NewlinesInParentheses.jet
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
CALL_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('f')
|
||||
PsiWhiteSpace('\n ')
|
||||
VALUE_ARGUMENT_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
CALL_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('f')
|
||||
PsiWhiteSpace('\n ')
|
||||
VALUE_ARGUMENT_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
|
||||
+28
-24
@@ -1146,35 +1146,39 @@ JetFile: When.jet
|
||||
PsiElement(IDENTIFIER)('c')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
INTEGER_CONSTANT
|
||||
PsiElement(INTEGER_LITERAL)('1')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
INTEGER_CONSTANT
|
||||
PsiElement(INTEGER_LITERAL)('1')
|
||||
PsiElement(COMMA)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
CALL_EXPRESSION
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
CALL_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
VALUE_ARGUMENT_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiElement(COMMA)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
VALUE_ARGUMENT_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiElement(IDENTIFIER)('bar')
|
||||
PsiElement(COMMA)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('bar')
|
||||
PsiElement(COMMA)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
BINARY_EXPRESSION
|
||||
INTEGER_CONSTANT
|
||||
PsiElement(INTEGER_LITERAL)('2')
|
||||
PsiWhiteSpace(' ')
|
||||
OPERATION_REFERENCE
|
||||
PsiElement(PLUS)('+')
|
||||
PsiWhiteSpace(' ')
|
||||
INTEGER_CONSTANT
|
||||
PsiElement(INTEGER_LITERAL)('3')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
BINARY_EXPRESSION
|
||||
INTEGER_CONSTANT
|
||||
PsiElement(INTEGER_LITERAL)('2')
|
||||
PsiWhiteSpace(' ')
|
||||
OPERATION_REFERENCE
|
||||
PsiElement(PLUS)('+')
|
||||
PsiWhiteSpace(' ')
|
||||
INTEGER_CONSTANT
|
||||
PsiElement(INTEGER_LITERAL)('3')
|
||||
PsiElement(COMMA)(',')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
|
||||
@@ -80,9 +80,10 @@ JetFile: When_ERR.jet
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
PsiErrorElement:Expecting an element, is-condition or in-condition
|
||||
<empty list>
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
PsiErrorElement:Expecting an element, is-condition or in-condition
|
||||
<empty list>
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
@@ -161,9 +162,10 @@ JetFile: When_ERR.jet
|
||||
PsiElement(SEMICOLON)(';')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
PsiErrorElement:Expecting an element, is-condition or in-condition
|
||||
<empty list>
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
PsiErrorElement:Expecting an element, is-condition or in-condition
|
||||
<empty list>
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiErrorElement:Expecting an element
|
||||
<empty list>
|
||||
|
||||
@@ -431,9 +431,10 @@ JetFile: BinaryTree.jet
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('EQ')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('EQ')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
@@ -441,9 +442,10 @@ JetFile: BinaryTree.jet
|
||||
PsiElement(true)('true')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('LS')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('LS')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
@@ -467,9 +469,10 @@ JetFile: BinaryTree.jet
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('GT')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('GT')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
@@ -707,9 +710,10 @@ JetFile: BinaryTree.jet
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('EQ')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('EQ')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
@@ -717,9 +721,10 @@ JetFile: BinaryTree.jet
|
||||
PsiElement(false)('false')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('LS')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('LS')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
@@ -745,9 +750,10 @@ JetFile: BinaryTree.jet
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('GT')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('GT')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
@@ -884,9 +890,10 @@ JetFile: BinaryTree.jet
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('EQ')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('EQ')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
@@ -897,9 +904,10 @@ JetFile: BinaryTree.jet
|
||||
PsiElement(false)('false')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('LS')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('LS')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace('\n ')
|
||||
@@ -984,9 +992,10 @@ JetFile: BinaryTree.jet
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('GT')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('GT')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace('\n ')
|
||||
@@ -1256,9 +1265,10 @@ JetFile: BinaryTree.jet
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('EQ')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('EQ')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
@@ -1266,9 +1276,10 @@ JetFile: BinaryTree.jet
|
||||
PsiElement(IDENTIFIER)('node')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('LS')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('LS')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
@@ -1287,9 +1298,10 @@ JetFile: BinaryTree.jet
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace('\n ')
|
||||
WHEN_ENTRY
|
||||
WHEN_CONDITION_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('GT')
|
||||
WHEN_CONDITION_IS_PATTERN
|
||||
EXPRESSION_PATTERN
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('GT')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
|
||||
Reference in New Issue
Block a user