Changed 'deparenthesize' function to get 'a' from (a: Int) and (@l a)

This commit is contained in:
svtk
2011-11-04 18:57:55 +04:00
parent 4e159a4a4e
commit 05f1db20ce
2 changed files with 40 additions and 5 deletions
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.psi;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lexer.JetTokens;
import java.util.Collection;
import java.util.HashSet;
@@ -13,11 +14,25 @@ import java.util.Set;
public class JetPsiUtil {
@Nullable
public static JetExpression deparenthesize(@NotNull JetExpression expression) {
JetExpression result = expression;
while (result instanceof JetParenthesizedExpression) {
result = ((JetParenthesizedExpression) expression).getExpression();
if (expression instanceof JetBinaryExpressionWithTypeRHS) {
JetSimpleNameExpression operationSign = ((JetBinaryExpressionWithTypeRHS) expression).getOperationSign();
if (JetTokens.COLON.equals(operationSign.getReferencedNameElementType())) {
expression = ((JetBinaryExpressionWithTypeRHS) expression).getLeft();
}
}
return result;
else if (expression instanceof JetPrefixExpression) {
if (JetTokens.LABELS.contains(((JetPrefixExpression) expression).getOperationSign().getReferencedNameElementType())) {
JetExpression baseExpression = ((JetPrefixExpression) expression).getBaseExpression();
if (baseExpression != null) {
expression = baseExpression;
}
}
}
if (expression instanceof JetParenthesizedExpression) {
JetExpression innerExpression = ((JetParenthesizedExpression) expression).getExpression();
return innerExpression != null ? deparenthesize(innerExpression) : null;
}
return expression;
}
@NotNull
@@ -32,7 +32,27 @@ class D() {
}
}
fun cannotBe() {
fun cannotBe(var i: Int) {
<!UNRESOLVED_REFERENCE!>z<!> = 30;
<!VARIABLE_EXPECTED!>()<!> = ();
(<!VARIABLE_EXPECTED!>i <!USELESS_CAST!>as<!> Int<!>) = 34
(<!VARIABLE_EXPECTED!>i is Int<!>) = false
<!VARIABLE_EXPECTED!>A()<!> = A()
<!VARIABLE_EXPECTED!>5<!> = 34
}
fun canBe(var i: Int, val j: Int) {
(i: Int) = 36
(@label i) = 34
(<!VAL_REASSIGNMENT!>j<!>: Int) = 36
(@label <!VAL_REASSIGNMENT!>j<!>) = 34
val a = A()
(@ a.a) = 3894
}
class A() {
var a: Int = 3
}