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(),
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 {
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_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);
}
@@ -62,10 +62,6 @@ public class JetControlFlowProcessor {
private class CFPVisitor extends JetVisitorVoid {
private final boolean inCondition;
private final JetVisitorVoid conditionVisitor = new JetVisitorVoid() {
@Override
public void visitWhenConditionCall(JetWhenConditionCall condition) {
value(condition.getCallSuffixExpression(), CFPVisitor.this.inCondition); // TODO : inCondition?
}
@Override
public void visitWhenConditionInRange(JetWhenConditionInRange condition) {
@@ -419,7 +419,10 @@ public class JetExpressionParsing extends AbstractJetParsing {
}
else return false;
}
else return false;
else {
return false;
}
return true;
}
@@ -764,7 +767,6 @@ public class JetExpressionParsing extends AbstractJetParsing {
/*
* whenCondition
* : expression
* : ("." | "?." postfixExpression typeArguments? valueArguments?
* : ("in" | "!in") expression
* : ("is" | "!is") isRHS
* ;
@@ -793,21 +795,10 @@ public class JetExpressionParsing extends AbstractJetParsing {
parsePattern();
}
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 {
PsiBuilder.Marker expressionPattern = mark();
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 {
parseExpression();
}
@@ -356,10 +356,6 @@ public class JetVisitor<R, D> extends PsiElementVisitor {
return visitExpression(expression, data);
}
public R visitWhenConditionCall(JetWhenConditionCall condition, D data) {
return visitJetElement(condition, data);
}
public R visitWhenConditionIsPattern(JetWhenConditionIsPattern condition, D data) {
return visitJetElement(condition, data);
}
@@ -354,10 +354,6 @@ public class JetVisitorVoid extends PsiElementVisitor {
visitExpression(expression);
}
public void visitWhenConditionCall(JetWhenConditionCall condition) {
visitJetElement(condition);
}
public void visitWhenConditionIsPattern(JetWhenConditionIsPattern 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;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.Ref;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*;
@@ -115,19 +113,6 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
final DataFlowInfo[] newDataFlowInfo = new DataFlowInfo[]{context.dataFlowInfo};
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
public void visitWhenConditionInRange(JetWhenConditionInRange condition) {
JetExpression rangeExpression = condition.getRangeExpression();
@@ -13,16 +13,19 @@ fun foo() : Int {
1 + <!UNRESOLVED_REFERENCE!>a<!> => 1
in 1..<!UNRESOLVED_REFERENCE!>a<!> => 1
!in 1..<!UNRESOLVED_REFERENCE!>a<!> => 1
.<!UNRESOLVED_REFERENCE!>a<!> => 1
.equals(1).<!UNRESOLVED_REFERENCE!>a<!> => 1
<!UNNECESSARY_SAFE_CALL!>?.<!>equals(1) => 1
// Commented for KT-621 .<!!UNRESOLVED_REFERENCE!>a<!!> => 1
// Commented for KT-621 .equals(1).<!!UNRESOLVED_REFERENCE!>a<!!> => 1
// Commented for KT-621 <!UNNECESSARY_SAFE_CALL!!>?.<!!>equals(1) => 1
else => 1
}
return when (<!USELESS_ELVIS!>x<!>?:null) {
<!UNSAFE_CALL!>.<!>foo() => 1
.equals(1) => 1
?.equals(1).equals(2) => 1
}
// Commented for KT-621
// return when (<!!USELESS_ELVIS!>x<!!>?:null) {
// <!!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()
@@ -8,8 +8,11 @@ fun Any?.equals1(other : Any?) : Boolean = true
fun main(args: Array<String>) {
val command : Foo? = null
when (command) {
.equals(null) => 1; // must be resolved
?.equals(null) => 1 // same here
}
// Commented for KT-621
// 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 {
val c = C(true)
return when(c) {
.p => "OK"
else => "fail"
}
// Commented for KT-621
// 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) {
buffer.addLast(it)
when (it) {
.isDigit() => digits.addLast(it.int - '0'.int)
' ', '-' => {}
else => {
printAll()
digits.clear()
}
// Commented for KT-621
// when (it) {
// .isDigit() => digits.addLast(it.int - '0'.int)
// ' ', '-' => {}
// 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)
printOneDigit()
check()
+14 -4
View File
@@ -23,11 +23,21 @@ class Luhny() {
fun process(it : Char) {
buffer.addLast(it)
when (it) {
.isDigit() => digits.addLast(it.int - '0'.int)
' ', '-' => {}
else => printAll()
// Commented for KT-621
// when (it) {
// .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)
printOneDigit()
check()
+18 -7
View File
@@ -24,14 +24,25 @@ class Luhny() {
fun charIn(it : Char) {
buffer.push(it)
when (it) {
.isDigit() => digits.push(it.int - '0'.int)
' ', '-' => {}
else => {
printAll()
digits.clear()
}
// Commented for KT-621
// when (it) {
// .isDigit() => digits.push(it.int - '0'.int)
// ' ', '-' => {}
// 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)
printOneDigit()
check()
+8 -8
View File
@@ -1,13 +1,13 @@
fun foo() {
when (a) {
.foo => a
.foo() => a
.foo<T> => a
.foo<T>(a) => a
.foo<T>(a, d) => a
.{bar} => a
.{!bar} => a
.{() => !bar} => a
a.foo => a
a.foo() => a
a.foo<T> => a
a.foo<T>(a) => a
a.foo<T>(a, d) => a
a.{bar} => a
a.{!bar} => a
a.{() => !bar} => a
else => a
}
}
+143 -111
View File
@@ -22,10 +22,14 @@ JetFile: CallsInWhen.jet
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
WHEN_ENTRY
WHEN_CONDITION_CALL
PsiElement(DOT)('.')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
WHEN_CONDITION_IS_PATTERN
EXPRESSION_PATTERN
DOT_QUALIFIED_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiElement(DOT)('.')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
@@ -33,14 +37,18 @@ JetFile: CallsInWhen.jet
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ')
WHEN_ENTRY
WHEN_CONDITION_CALL
PsiElement(DOT)('.')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
WHEN_CONDITION_IS_PATTERN
EXPRESSION_PATTERN
DOT_QUALIFIED_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiElement(DOT)('.')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
@@ -48,19 +56,53 @@ JetFile: CallsInWhen.jet
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
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)('>')
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
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
PsiElement(IDENTIFIER)('a')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
@@ -68,56 +110,34 @@ JetFile: CallsInWhen.jet
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
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
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
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
PsiElement(IDENTIFIER)('a')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_ARGUMENT
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_ARGUMENT
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('d')
PsiElement(RPAR)(')')
PsiElement(IDENTIFIER)('d')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
@@ -125,15 +145,19 @@ JetFile: CallsInWhen.jet
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ')
WHEN_ENTRY
WHEN_CONDITION_CALL
PsiElement(DOT)('.')
FUNCTION_LITERAL_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
BLOCK
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
PsiElement(RBRACE)('}')
WHEN_CONDITION_IS_PATTERN
EXPRESSION_PATTERN
DOT_QUALIFIED_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiElement(DOT)('.')
FUNCTION_LITERAL_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
BLOCK
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
@@ -141,18 +165,22 @@ JetFile: CallsInWhen.jet
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ')
WHEN_ENTRY
WHEN_CONDITION_CALL
PsiElement(DOT)('.')
FUNCTION_LITERAL_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
BLOCK
PREFIX_EXPRESSION
OPERATION_REFERENCE
PsiElement(EXCL)('!')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
PsiElement(RBRACE)('}')
WHEN_CONDITION_IS_PATTERN
EXPRESSION_PATTERN
DOT_QUALIFIED_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiElement(DOT)('.')
FUNCTION_LITERAL_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
BLOCK
PREFIX_EXPRESSION
OPERATION_REFERENCE
PsiElement(EXCL)('!')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
@@ -160,24 +188,28 @@ JetFile: CallsInWhen.jet
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ')
WHEN_ENTRY
WHEN_CONDITION_CALL
PsiElement(DOT)('.')
FUNCTION_LITERAL_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
BLOCK
PREFIX_EXPRESSION
OPERATION_REFERENCE
PsiElement(EXCL)('!')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
PsiElement(RBRACE)('}')
WHEN_CONDITION_IS_PATTERN
EXPRESSION_PATTERN
DOT_QUALIFIED_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiElement(DOT)('.')
FUNCTION_LITERAL_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
BLOCK
PREFIX_EXPRESSION
OPERATION_REFERENCE
PsiElement(EXCL)('!')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
+2 -2
View File
@@ -82,7 +82,7 @@ JetFile: When_ERR.jet
WHEN_ENTRY
WHEN_CONDITION_IS_PATTERN
EXPRESSION_PATTERN
PsiErrorElement:Expecting an element, is-condition or in-condition
PsiErrorElement:Expecting an expression, is-condition or in-condition
<empty list>
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
@@ -164,7 +164,7 @@ JetFile: When_ERR.jet
WHEN_ENTRY
WHEN_CONDITION_IS_PATTERN
EXPRESSION_PATTERN
PsiErrorElement:Expecting an element, is-condition or in-condition
PsiErrorElement:Expecting an expression, is-condition or in-condition
<empty list>
PsiElement(DOUBLE_ARROW)('=>')
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")));
}
public void testCall() throws Exception {
loadText("fun foo(s: String) = when(s) { .startsWith(\"J\") => \"JetBrains\"; else => \"something\" }");
Method foo = generateFunction();
try {
assertEquals("JetBrains", foo.invoke(null, "Java"));
assertEquals("something", foo.invoke(null, "C#"));
}
catch (Throwable t) {
System.out.println(generateToText());
t.printStackTrace();
}
}
// Commented for KT-621
// public void testCall() throws Exception {
// loadText("fun foo(s: String) = when(s) { .startsWith(\"J\") => \"JetBrains\"; else => \"something\" }");
// Method foo = generateFunction();
// try {
// assertEquals("JetBrains", foo.invoke(null, "Java"));
// assertEquals("something", foo.invoke(null, "C#"));
// }
// catch (Throwable t) {
// System.out.println(generateToText());
// t.printStackTrace();
// }
// }
public void testCallProperty() throws Exception {
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.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);
}
}
+10 -7
View File
@@ -13,15 +13,18 @@ fun foo() : Int {
1 + <error>a</error> => 1
in 1..<error>a</error> => 1
!in 1..<error>a</error> => 1
.<error>a</error> => 1
.equals(1).<error>a</error> => 1
<warning>?.</warning>equals(1) => 1
// Commented for KT-621 .<!error>a</!error> => 1
// Commented for KT-621 .equals(1).<!error>a</!error> => 1
// Commented for KT-621 <!warning>?.</!warning>equals(1) => 1
else => 1
}
return when (<warning>x</warning>?:null) {
<error>.</error>foo() => 1
?.equals(1).equals(2) => 1
}
// Commented for KT-621
// 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()
@@ -1,7 +0,0 @@
// "Replace with dot call" "true"
fun foo(a: Any) {
when (a) {
<caret>?.equals(0) => true
else => false
}
}