KT-621 Remove .foo() pattern matching from when (Some tests were rewritten)

This commit is contained in:
Nikolay Krasko
2011-11-25 17:39:16 +04:00
parent 0b689f32a7
commit 0c758902ef
21 changed files with 256 additions and 294 deletions
@@ -2656,30 +2656,6 @@ If finally block is present, its last expression is the value of try expression.
conditionValue = generatePatternMatch(pattern, patternCondition.isNegated(), conditionValue = generatePatternMatch(pattern, patternCondition.isNegated(),
StackValue.local(subjectLocal, subjectType), nextEntry); StackValue.local(subjectLocal, subjectType), nextEntry);
} }
else if (condition instanceof JetWhenConditionCall) {
final JetExpression call = ((JetWhenConditionCall) condition).getCallSuffixExpression();
if (call instanceof JetCallExpression) {
v.load(subjectLocal, subjectType);
final DeclarationDescriptor declarationDescriptor = resolveCalleeDescriptor((JetCallExpression) call);
if (!(declarationDescriptor instanceof FunctionDescriptor)) {
throw new UnsupportedOperationException("expected function descriptor in when condition with call, found " + declarationDescriptor);
}
conditionValue = invokeFunction((JetCallExpression) call, declarationDescriptor, StackValue.onStack(subjectType));
}
else if (call instanceof JetSimpleNameExpression) {
final DeclarationDescriptor descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) call);
if (descriptor instanceof PropertyDescriptor) {
v.load(subjectLocal, subjectType);
conditionValue = intermediateValueForProperty((PropertyDescriptor) descriptor, false, null);
}
else {
throw new UnsupportedOperationException("unknown simple name resolve result: " + descriptor);
}
}
else {
throw new UnsupportedOperationException("unsupported kind of call suffix");
}
}
else { else {
throw new UnsupportedOperationException("unsupported kind of when condition"); throw new UnsupportedOperationException("unsupported kind of when condition");
} }
@@ -141,7 +141,6 @@ public interface JetNodeTypes {
JetNodeType WHEN_CONDITION_IN_RANGE = new JetNodeType("WHEN_CONDITION_IN_RANGE", JetWhenConditionInRange.class); 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_IS_PATTERN = new JetNodeType("WHEN_CONDITION_IS_PATTERN", JetWhenConditionIsPattern.class);
JetNodeType WHEN_CONDITION_CALL = new JetNodeType("WHEN_CONDITION_CALL", JetWhenConditionCall.class);
JetNodeType NAMESPACE_NAME = new JetNodeType("NAMESPACE_NAME", JetContainerNode.class); JetNodeType NAMESPACE_NAME = new JetNodeType("NAMESPACE_NAME", JetContainerNode.class);
} }
@@ -62,10 +62,6 @@ public class JetControlFlowProcessor {
private class CFPVisitor extends JetVisitorVoid { private class CFPVisitor extends JetVisitorVoid {
private final boolean inCondition; private final boolean inCondition;
private final JetVisitorVoid conditionVisitor = new JetVisitorVoid() { private final JetVisitorVoid conditionVisitor = new JetVisitorVoid() {
@Override
public void visitWhenConditionCall(JetWhenConditionCall condition) {
value(condition.getCallSuffixExpression(), CFPVisitor.this.inCondition); // TODO : inCondition?
}
@Override @Override
public void visitWhenConditionInRange(JetWhenConditionInRange condition) { public void visitWhenConditionInRange(JetWhenConditionInRange condition) {
@@ -419,7 +419,10 @@ public class JetExpressionParsing extends AbstractJetParsing {
} }
else return false; else return false;
} }
else return false; else {
return false;
}
return true; return true;
} }
@@ -764,7 +767,6 @@ public class JetExpressionParsing extends AbstractJetParsing {
/* /*
* whenCondition * whenCondition
* : expression * : expression
* : ("." | "?." postfixExpression typeArguments? valueArguments?
* : ("in" | "!in") expression * : ("in" | "!in") expression
* : ("is" | "!is") isRHS * : ("is" | "!is") isRHS
* ; * ;
@@ -793,21 +795,10 @@ public class JetExpressionParsing extends AbstractJetParsing {
parsePattern(); parsePattern();
} }
condition.done(WHEN_CONDITION_IS_PATTERN); condition.done(WHEN_CONDITION_IS_PATTERN);
} else if (at(DOT) || at(SAFE_ACCESS)) {
advance(); // DOT or SAFE_ACCESS
PsiBuilder.Marker mark = mark();
parsePostfixExpression();
if (parseCallSuffix()) {
mark.done(CALL_EXPRESSION);
}
else {
mark.drop();
}
condition.done(WHEN_CONDITION_CALL);
} else { } else {
PsiBuilder.Marker expressionPattern = mark(); PsiBuilder.Marker expressionPattern = mark();
if (atSet(WHEN_CONDITION_RECOVERY_SET_WITH_DOUBLE_ARROW)) { if (atSet(WHEN_CONDITION_RECOVERY_SET_WITH_DOUBLE_ARROW)) {
error("Expecting an element, is-condition or in-condition"); error("Expecting an expression, is-condition or in-condition");
} else { } else {
parseExpression(); parseExpression();
} }
@@ -356,10 +356,6 @@ public class JetVisitor<R, D> extends PsiElementVisitor {
return visitExpression(expression, data); return visitExpression(expression, data);
} }
public R visitWhenConditionCall(JetWhenConditionCall condition, D data) {
return visitJetElement(condition, data);
}
public R visitWhenConditionIsPattern(JetWhenConditionIsPattern condition, D data) { public R visitWhenConditionIsPattern(JetWhenConditionIsPattern condition, D data) {
return visitJetElement(condition, data); return visitJetElement(condition, data);
} }
@@ -354,10 +354,6 @@ public class JetVisitorVoid extends PsiElementVisitor {
visitExpression(expression); visitExpression(expression);
} }
public void visitWhenConditionCall(JetWhenConditionCall condition) {
visitJetElement(condition);
}
public void visitWhenConditionIsPattern(JetWhenConditionIsPattern condition) { public void visitWhenConditionIsPattern(JetWhenConditionIsPattern condition) {
visitJetElement(condition); visitJetElement(condition);
} }
@@ -1,40 +0,0 @@
package org.jetbrains.jet.lang.psi;
import com.intellij.lang.ASTNode;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lexer.JetTokens;
/**
* @author abreslav
*/
public class JetWhenConditionCall extends JetWhenCondition {
public JetWhenConditionCall(@NotNull ASTNode node) {
super(node);
}
public boolean isSafeCall() {
return getNode().findChildByType(JetTokens.SAFE_ACCESS) != null;
}
@NotNull
public ASTNode getOperationTokenNode() {
return getNode().findChildByType(TokenSet.create(JetTokens.SAFE_ACCESS, JetTokens.DOT));
}
@Nullable @IfNotParsed
public JetExpression getCallSuffixExpression() {
return findChildByClass(JetExpression.class);
}
@Override
public void accept(@NotNull JetVisitorVoid visitor) {
visitor.visitWhenConditionCall(this);
}
@Override
public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
return visitor.visitWhenConditionCall(this, data);
}
}
@@ -1,12 +1,10 @@
package org.jetbrains.jet.lang.types.expressions; package org.jetbrains.jet.lang.types.expressions;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.Ref;
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.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
@@ -115,19 +113,6 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
final DataFlowInfo[] newDataFlowInfo = new DataFlowInfo[]{context.dataFlowInfo}; final DataFlowInfo[] newDataFlowInfo = new DataFlowInfo[]{context.dataFlowInfo};
condition.accept(new JetVisitorVoid() { condition.accept(new JetVisitorVoid() {
@Override
public void visitWhenConditionCall(JetWhenConditionCall condition) {
JetExpression callSuffixExpression = condition.getCallSuffixExpression();
// JetScope compositeScope = new ScopeWithReceiver(context.scope, subjectType, semanticServices.getTypeChecker());
if (callSuffixExpression != null) {
// JetType selectorReturnType = getType(compositeScope, callSuffixExpression, false, context);
assert subjectExpression != null;
JetType selectorReturnType = facade.getSelectorReturnType(new ExpressionReceiver(subjectExpression, subjectType), condition.getOperationTokenNode(), callSuffixExpression, context);//getType(compositeScope, callSuffixExpression, false, context);
ensureBooleanResultWithCustomSubject(callSuffixExpression, selectorReturnType, "This expression", context);
// context.getServices().checkNullSafety(subjectType, condition.getOperationTokenNode(), getCalleeFunctionDescriptor(callSuffixExpression, context), condition);
}
}
@Override @Override
public void visitWhenConditionInRange(JetWhenConditionInRange condition) { public void visitWhenConditionInRange(JetWhenConditionInRange condition) {
JetExpression rangeExpression = condition.getRangeExpression(); JetExpression rangeExpression = condition.getRangeExpression();
@@ -13,16 +13,19 @@ fun foo() : Int {
1 + <!UNRESOLVED_REFERENCE!>a<!> => 1 1 + <!UNRESOLVED_REFERENCE!>a<!> => 1
in 1..<!UNRESOLVED_REFERENCE!>a<!> => 1 in 1..<!UNRESOLVED_REFERENCE!>a<!> => 1
!in 1..<!UNRESOLVED_REFERENCE!>a<!> => 1 !in 1..<!UNRESOLVED_REFERENCE!>a<!> => 1
.<!UNRESOLVED_REFERENCE!>a<!> => 1 // Commented for KT-621 .<!!UNRESOLVED_REFERENCE!>a<!!> => 1
.equals(1).<!UNRESOLVED_REFERENCE!>a<!> => 1 // Commented for KT-621 .equals(1).<!!UNRESOLVED_REFERENCE!>a<!!> => 1
<!UNNECESSARY_SAFE_CALL!>?.<!>equals(1) => 1 // Commented for KT-621 <!UNNECESSARY_SAFE_CALL!!>?.<!!>equals(1) => 1
else => 1 else => 1
} }
return when (<!USELESS_ELVIS!>x<!>?:null) {
<!UNSAFE_CALL!>.<!>foo() => 1 // Commented for KT-621
.equals(1) => 1 // return when (<!!USELESS_ELVIS!>x<!!>?:null) {
?.equals(1).equals(2) => 1 // <!!UNSAFE_CALL!!>.<!!>foo() => 1
} // .equals(1) => 1
// ?.equals(1).equals(2) => 1
// }
return 0
} }
val _type_test : Int = foo() // this is needed to ensure the inferred return type of foo() val _type_test : Int = foo() // this is needed to ensure the inferred return type of foo()
@@ -8,8 +8,11 @@ fun Any?.equals1(other : Any?) : Boolean = true
fun main(args: Array<String>) { fun main(args: Array<String>) {
val command : Foo? = null val command : Foo? = null
when (command) {
.equals(null) => 1; // must be resolved // Commented for KT-621
?.equals(null) => 1 // same here // when (command) {
} // .equals(null) => 1; // must be resolved
// ?.equals(null) => 1 // same here
// }
command.equals(null)
} }
@@ -2,8 +2,11 @@ class C(val p: Boolean) { }
fun box(): String { fun box(): String {
val c = C(true) val c = C(true)
return when(c) {
.p => "OK" // Commented for KT-621
else => "fail" // return when(c) {
} // .p => "OK"
// else => "fail"
// }
return if (c.p) "OK" else "fail"
} }
+18 -7
View File
@@ -25,14 +25,25 @@ class Luhny() {
fun charIn(it : Char) { fun charIn(it : Char) {
buffer.addLast(it) buffer.addLast(it)
when (it) {
.isDigit() => digits.addLast(it.int - '0'.int) // Commented for KT-621
' ', '-' => {} // when (it) {
else => { // .isDigit() => digits.addLast(it.int - '0'.int)
printAll() // ' ', '-' => {}
digits.clear() // else => {
} // printAll()
// digits.clear()
// }
// }
if (it.isDigit()) {
digits.addLast(it.int - '0'.int)
} else if (it == ' ' || it == '-') {
} else {
printAll()
digits.clear()
} }
if (digits.size() > 16) if (digits.size() > 16)
printOneDigit() printOneDigit()
check() check()
+14 -4
View File
@@ -23,11 +23,21 @@ class Luhny() {
fun process(it : Char) { fun process(it : Char) {
buffer.addLast(it) buffer.addLast(it)
when (it) {
.isDigit() => digits.addLast(it.int - '0'.int) // Commented for KT-621
' ', '-' => {} // when (it) {
else => printAll() // .isDigit() => digits.addLast(it.int - '0'.int)
// ' ', '-' => {}
// else => printAll()
// }
if (it.isDigit()) {
digits.addLast(it.int - '0'.int)
} else if (it == ' ' || it == '-') {
} else {
printAll()
} }
if (digits.size() > 16) if (digits.size() > 16)
printOneDigit() printOneDigit()
check() check()
+18 -7
View File
@@ -24,14 +24,25 @@ class Luhny() {
fun charIn(it : Char) { fun charIn(it : Char) {
buffer.push(it) buffer.push(it)
when (it) {
.isDigit() => digits.push(it.int - '0'.int) // Commented for KT-621
' ', '-' => {} // when (it) {
else => { // .isDigit() => digits.push(it.int - '0'.int)
printAll() // ' ', '-' => {}
digits.clear() // else => {
} // printAll()
// digits.clear()
// }
// }
if (it.isDigit()) {
digits.push(it.int - '0'.int)
} else if (it == ' ' || it == '-') {
} else {
printAll()
digits.clear()
} }
if (digits.size() > 16) if (digits.size() > 16)
printOneDigit() printOneDigit()
check() check()
+8 -8
View File
@@ -1,13 +1,13 @@
fun foo() { fun foo() {
when (a) { when (a) {
.foo => a a.foo => a
.foo() => a a.foo() => a
.foo<T> => a a.foo<T> => a
.foo<T>(a) => a a.foo<T>(a) => a
.foo<T>(a, d) => a a.foo<T>(a, d) => a
.{bar} => a a.{bar} => a
.{!bar} => a a.{!bar} => a
.{() => !bar} => a a.{() => !bar} => a
else => a else => a
} }
} }
+143 -111
View File
@@ -22,10 +22,14 @@ JetFile: CallsInWhen.jet
PsiElement(LBRACE)('{') PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ') PsiWhiteSpace('\n ')
WHEN_ENTRY WHEN_ENTRY
WHEN_CONDITION_CALL WHEN_CONDITION_IS_PATTERN
PsiElement(DOT)('.') EXPRESSION_PATTERN
REFERENCE_EXPRESSION DOT_QUALIFIED_EXPRESSION
PsiElement(IDENTIFIER)('foo') REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiElement(DOT)('.')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>') PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
@@ -33,14 +37,18 @@ JetFile: CallsInWhen.jet
PsiElement(IDENTIFIER)('a') PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ') PsiWhiteSpace('\n ')
WHEN_ENTRY WHEN_ENTRY
WHEN_CONDITION_CALL WHEN_CONDITION_IS_PATTERN
PsiElement(DOT)('.') EXPRESSION_PATTERN
CALL_EXPRESSION DOT_QUALIFIED_EXPRESSION
REFERENCE_EXPRESSION REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo') PsiElement(IDENTIFIER)('a')
VALUE_ARGUMENT_LIST PsiElement(DOT)('.')
PsiElement(LPAR)('(') CALL_EXPRESSION
PsiElement(RPAR)(')') REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>') PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
@@ -48,19 +56,53 @@ JetFile: CallsInWhen.jet
PsiElement(IDENTIFIER)('a') PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ') PsiWhiteSpace('\n ')
WHEN_ENTRY WHEN_ENTRY
WHEN_CONDITION_CALL WHEN_CONDITION_IS_PATTERN
PsiElement(DOT)('.') EXPRESSION_PATTERN
CALL_EXPRESSION DOT_QUALIFIED_EXPRESSION
REFERENCE_EXPRESSION REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo') PsiElement(IDENTIFIER)('a')
TYPE_ARGUMENT_LIST PsiElement(DOT)('.')
PsiElement(LT)('<') CALL_EXPRESSION
TYPE_PROJECTION REFERENCE_EXPRESSION
TYPE_REFERENCE PsiElement(IDENTIFIER)('foo')
USER_TYPE TYPE_ARGUMENT_LIST
PsiElement(LT)('<')
TYPE_PROJECTION
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ')
WHEN_ENTRY
WHEN_CONDITION_IS_PATTERN
EXPRESSION_PATTERN
DOT_QUALIFIED_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiElement(DOT)('.')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
TYPE_ARGUMENT_LIST
PsiElement(LT)('<')
TYPE_PROJECTION
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
REFERENCE_EXPRESSION REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T') PsiElement(IDENTIFIER)('a')
PsiElement(GT)('>') PsiElement(RPAR)(')')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>') PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
@@ -68,56 +110,34 @@ JetFile: CallsInWhen.jet
PsiElement(IDENTIFIER)('a') PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ') PsiWhiteSpace('\n ')
WHEN_ENTRY WHEN_ENTRY
WHEN_CONDITION_CALL WHEN_CONDITION_IS_PATTERN
PsiElement(DOT)('.') EXPRESSION_PATTERN
CALL_EXPRESSION DOT_QUALIFIED_EXPRESSION
REFERENCE_EXPRESSION REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo') PsiElement(IDENTIFIER)('a')
TYPE_ARGUMENT_LIST PsiElement(DOT)('.')
PsiElement(LT)('<') CALL_EXPRESSION
TYPE_PROJECTION REFERENCE_EXPRESSION
TYPE_REFERENCE PsiElement(IDENTIFIER)('foo')
USER_TYPE TYPE_ARGUMENT_LIST
PsiElement(LT)('<')
TYPE_PROJECTION
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
REFERENCE_EXPRESSION REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T') PsiElement(IDENTIFIER)('a')
PsiElement(GT)('>') PsiElement(COMMA)(',')
VALUE_ARGUMENT_LIST PsiWhiteSpace(' ')
PsiElement(LPAR)('(') VALUE_ARGUMENT
VALUE_ARGUMENT
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ')
WHEN_ENTRY
WHEN_CONDITION_CALL
PsiElement(DOT)('.')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
TYPE_ARGUMENT_LIST
PsiElement(LT)('<')
TYPE_PROJECTION
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T') PsiElement(IDENTIFIER)('d')
PsiElement(GT)('>') PsiElement(RPAR)(')')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_ARGUMENT
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('d')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>') PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
@@ -125,15 +145,19 @@ JetFile: CallsInWhen.jet
PsiElement(IDENTIFIER)('a') PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ') PsiWhiteSpace('\n ')
WHEN_ENTRY WHEN_ENTRY
WHEN_CONDITION_CALL WHEN_CONDITION_IS_PATTERN
PsiElement(DOT)('.') EXPRESSION_PATTERN
FUNCTION_LITERAL_EXPRESSION DOT_QUALIFIED_EXPRESSION
FUNCTION_LITERAL REFERENCE_EXPRESSION
PsiElement(LBRACE)('{') PsiElement(IDENTIFIER)('a')
BLOCK PsiElement(DOT)('.')
REFERENCE_EXPRESSION FUNCTION_LITERAL_EXPRESSION
PsiElement(IDENTIFIER)('bar') FUNCTION_LITERAL
PsiElement(RBRACE)('}') PsiElement(LBRACE)('{')
BLOCK
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>') PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
@@ -141,18 +165,22 @@ JetFile: CallsInWhen.jet
PsiElement(IDENTIFIER)('a') PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ') PsiWhiteSpace('\n ')
WHEN_ENTRY WHEN_ENTRY
WHEN_CONDITION_CALL WHEN_CONDITION_IS_PATTERN
PsiElement(DOT)('.') EXPRESSION_PATTERN
FUNCTION_LITERAL_EXPRESSION DOT_QUALIFIED_EXPRESSION
FUNCTION_LITERAL REFERENCE_EXPRESSION
PsiElement(LBRACE)('{') PsiElement(IDENTIFIER)('a')
BLOCK PsiElement(DOT)('.')
PREFIX_EXPRESSION FUNCTION_LITERAL_EXPRESSION
OPERATION_REFERENCE FUNCTION_LITERAL
PsiElement(EXCL)('!') PsiElement(LBRACE)('{')
REFERENCE_EXPRESSION BLOCK
PsiElement(IDENTIFIER)('bar') PREFIX_EXPRESSION
PsiElement(RBRACE)('}') OPERATION_REFERENCE
PsiElement(EXCL)('!')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>') PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
@@ -160,24 +188,28 @@ JetFile: CallsInWhen.jet
PsiElement(IDENTIFIER)('a') PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ') PsiWhiteSpace('\n ')
WHEN_ENTRY WHEN_ENTRY
WHEN_CONDITION_CALL WHEN_CONDITION_IS_PATTERN
PsiElement(DOT)('.') EXPRESSION_PATTERN
FUNCTION_LITERAL_EXPRESSION DOT_QUALIFIED_EXPRESSION
FUNCTION_LITERAL REFERENCE_EXPRESSION
PsiElement(LBRACE)('{') PsiElement(IDENTIFIER)('a')
VALUE_PARAMETER_LIST PsiElement(DOT)('.')
PsiElement(LPAR)('(') FUNCTION_LITERAL_EXPRESSION
PsiElement(RPAR)(')') FUNCTION_LITERAL
PsiWhiteSpace(' ') PsiElement(LBRACE)('{')
PsiElement(DOUBLE_ARROW)('=>') VALUE_PARAMETER_LIST
PsiWhiteSpace(' ') PsiElement(LPAR)('(')
BLOCK PsiElement(RPAR)(')')
PREFIX_EXPRESSION PsiWhiteSpace(' ')
OPERATION_REFERENCE PsiElement(DOUBLE_ARROW)('=>')
PsiElement(EXCL)('!') PsiWhiteSpace(' ')
REFERENCE_EXPRESSION BLOCK
PsiElement(IDENTIFIER)('bar') PREFIX_EXPRESSION
PsiElement(RBRACE)('}') OPERATION_REFERENCE
PsiElement(EXCL)('!')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>') PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
+2 -2
View File
@@ -82,7 +82,7 @@ JetFile: When_ERR.jet
WHEN_ENTRY WHEN_ENTRY
WHEN_CONDITION_IS_PATTERN WHEN_CONDITION_IS_PATTERN
EXPRESSION_PATTERN EXPRESSION_PATTERN
PsiErrorElement:Expecting an element, is-condition or in-condition PsiErrorElement:Expecting an expression, is-condition or in-condition
<empty list> <empty list>
PsiElement(DOUBLE_ARROW)('=>') PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
@@ -164,7 +164,7 @@ JetFile: When_ERR.jet
WHEN_ENTRY WHEN_ENTRY
WHEN_CONDITION_IS_PATTERN WHEN_CONDITION_IS_PATTERN
EXPRESSION_PATTERN EXPRESSION_PATTERN
PsiErrorElement:Expecting an element, is-condition or in-condition PsiErrorElement:Expecting an expression, is-condition or in-condition
<empty list> <empty list>
PsiElement(DOUBLE_ARROW)('=>') PsiElement(DOUBLE_ARROW)('=>')
PsiErrorElement:Expecting an element PsiErrorElement:Expecting an element
@@ -99,18 +99,19 @@ public class PatternMatchingTest extends CodegenTestCase {
assertEquals("something", foo.invoke(null, new Tuple2<String, String>(null, "not", "tuple"))); assertEquals("something", foo.invoke(null, new Tuple2<String, String>(null, "not", "tuple")));
} }
public void testCall() throws Exception { // Commented for KT-621
loadText("fun foo(s: String) = when(s) { .startsWith(\"J\") => \"JetBrains\"; else => \"something\" }"); // public void testCall() throws Exception {
Method foo = generateFunction(); // loadText("fun foo(s: String) = when(s) { .startsWith(\"J\") => \"JetBrains\"; else => \"something\" }");
try { // Method foo = generateFunction();
assertEquals("JetBrains", foo.invoke(null, "Java")); // try {
assertEquals("something", foo.invoke(null, "C#")); // assertEquals("JetBrains", foo.invoke(null, "Java"));
} // assertEquals("something", foo.invoke(null, "C#"));
catch (Throwable t) { // }
System.out.println(generateToText()); // catch (Throwable t) {
t.printStackTrace(); // System.out.println(generateToText());
} // t.printStackTrace();
} // }
// }
public void testCallProperty() throws Exception { public void testCallProperty() throws Exception {
blackBoxFile("patternMatching/callProperty.jet"); blackBoxFile("patternMatching/callProperty.jet");
@@ -40,13 +40,6 @@ public class ReplaceSafeCallWithDotCall extends JetIntentionAction<JetElement> {
CodeEditUtil.replaceChild(newElement.getNode(), newElement.getSelectorExpression().getNode(), safeQualifiedExpression.getSelectorExpression().getNode()); CodeEditUtil.replaceChild(newElement.getNode(), newElement.getSelectorExpression().getNode(), safeQualifiedExpression.getSelectorExpression().getNode());
CodeEditUtil.replaceChild(newElement.getNode(), newElement.getReceiverExpression().getNode(), safeQualifiedExpression.getReceiverExpression().getNode()); CodeEditUtil.replaceChild(newElement.getNode(), newElement.getReceiverExpression().getNode(), safeQualifiedExpression.getReceiverExpression().getNode());
element.replace(newElement);
}
else if (element instanceof JetWhenConditionCall) {
JetWhenConditionCall newElement = (JetWhenConditionCall) element;
JetDotQualifiedExpression callExpression = (JetDotQualifiedExpression) JetPsiFactory.createExpression(project, "x.foo");
CodeEditUtil.replaceChild(newElement.getNode(), newElement.getOperationTokenNode(), callExpression.getOperationTokenNode());
element.replace(newElement); element.replace(newElement);
} }
} }
+10 -7
View File
@@ -13,15 +13,18 @@ fun foo() : Int {
1 + <error>a</error> => 1 1 + <error>a</error> => 1
in 1..<error>a</error> => 1 in 1..<error>a</error> => 1
!in 1..<error>a</error> => 1 !in 1..<error>a</error> => 1
.<error>a</error> => 1 // Commented for KT-621 .<!error>a</!error> => 1
.equals(1).<error>a</error> => 1 // Commented for KT-621 .equals(1).<!error>a</!error> => 1
<warning>?.</warning>equals(1) => 1 // Commented for KT-621 <!warning>?.</!warning>equals(1) => 1
else => 1 else => 1
} }
return when (<warning>x</warning>?:null) {
<error>.</error>foo() => 1 // Commented for KT-621
?.equals(1).equals(2) => 1 // return when (<!warning>x</!warning>?:null) {
} // <!error>.</!error>foo() => 1
// ?.equals(1).equals(2) => 1
// }
return 0
} }
val _type_test : Int = foo() // this is needed to ensure the inferred return type of foo() val _type_test : Int = foo() // this is needed to ensure the inferred return type of foo()
@@ -1,7 +0,0 @@
// "Replace with dot call" "true"
fun foo(a: Any) {
when (a) {
<caret>?.equals(0) => true
else => false
}
}