Negations supported

This commit is contained in:
Andrey Breslav
2011-06-10 19:21:39 +04:00
parent 49b60c3af8
commit c3854c939c
4 changed files with 63 additions and 4 deletions
@@ -3,7 +3,7 @@ package org.jetbrains.jet.lang.psi;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetNodeTypes;
import org.jetbrains.annotations.Nullable;
/**
* @author max
@@ -18,13 +18,12 @@ public class JetPrefixExpression extends JetUnaryExpression {
visitor.visitPrefixExpression(this);
}
@NotNull
@Nullable @IfNotParsed
public JetExpression getBaseExpression() {
PsiElement expression = getOperationSign().getNextSibling();
while (expression != null && false == expression instanceof JetExpression) {
expression = expression.getNextSibling();
}
assert expression != null;
return (JetExpression) expression;
}
}
@@ -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;
import org.jetbrains.jet.JetNodeTypes;
/**
@@ -12,7 +13,6 @@ public abstract class JetUnaryExpression extends JetExpression {
super(node);
}
@NotNull
public abstract JetExpression getBaseExpression();
@NotNull
@@ -1403,6 +1403,25 @@ public class JetTypeInferrer {
}
}
}
@Override
public void visitUnaryExpression(JetUnaryExpression expression) {
IElementType operationTokenType = expression.getOperationSign().getReferencedNameElementType();
if (operationTokenType == JetTokens.EXCL) {
JetExpression baseExpression = expression.getBaseExpression();
if (baseExpression != null) {
result[0] = extractDataFlowInfoFromCondition(baseExpression, !conditionValue);
}
}
}
@Override
public void visitParenthesizedExpression(JetParenthesizedExpression expression) {
JetExpression body = expression.getExpression();
if (body != null) {
body.accept(this);
}
}
});
return result[0];
}
+41
View File
@@ -214,3 +214,44 @@ fun f6(s : String?) {
} while (s == null)
s.get(0)
}
fun f7(s : String?, t : String?) {
s?.get(0)
if (!(s == null)) {
s.get(0)
}
s?.get(0)
if (!(s != null)) {
s?.get(0)
}
else {
s.get(0)
}
s?.get(0)
if (!!(s != null)) {
s.get(0)
}
else {
s?.get(0)
}
s?.get(0)
t?.get(0)
if (!(s == null || t == null)) {
s.get(0)
t.get(0)
}
else {
s?.get(0)
t?.get(0)
}
s?.get(0)
t?.get(0)
if (!(s == null && s == null)) {
s.get(0)
t?.get(0)
}
else {
s?.get(0)
t?.get(0)
}
}