diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java index edea03308a8..03d32266d31 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java @@ -66,16 +66,25 @@ public class JetPsiUtil { @Nullable public static JetExpression deparenthesizeWithNoTypeResolution(@NotNull JetExpression expression) { - return deparenthesizeWithResolutionStrategy(expression, null); + return deparenthesizeWithNoTypeResolution(expression, true); + } + + @Nullable + public static JetExpression deparenthesizeWithNoTypeResolution( + @NotNull JetExpression expression, + boolean deparenthesizeBinaryExpressionWithTypeRHS + ) { + return deparenthesizeWithResolutionStrategy(expression, deparenthesizeBinaryExpressionWithTypeRHS, null); } @Nullable @Deprecated //Use JetPsiUtil.deparenthesizeWithNoTypeResolution() or ExpressionTypingServices.deparenthesize() public static JetExpression deparenthesizeWithResolutionStrategy( @NotNull JetExpression expression, + boolean deparenthesizeBinaryExpressionWithTypeRHS, @Nullable Function typeResolutionStrategy ) { - if (expression instanceof JetBinaryExpressionWithTypeRHS) { + if (deparenthesizeBinaryExpressionWithTypeRHS && expression instanceof JetBinaryExpressionWithTypeRHS) { JetBinaryExpressionWithTypeRHS binaryExpression = (JetBinaryExpressionWithTypeRHS) expression; JetSimpleNameExpression operationSign = binaryExpression.getOperationReference(); if (JetTokens.COLON.equals(operationSign.getReferencedNameElementType())) { @@ -87,20 +96,27 @@ public class JetPsiUtil { } } else if (expression instanceof JetPrefixExpression) { - if (JetTokens.LABELS.contains(((JetPrefixExpression) expression).getOperationReference().getReferencedNameElementType())) { - JetExpression baseExpression = ((JetPrefixExpression) expression).getBaseExpression(); - if (baseExpression != null) { - expression = baseExpression; - } + JetExpression baseExpression = getBaseExpressionIfLabeledExpression((JetPrefixExpression) expression); + if (baseExpression != null) { + expression = baseExpression; } } if (expression instanceof JetParenthesizedExpression) { JetExpression innerExpression = ((JetParenthesizedExpression) expression).getExpression(); - return innerExpression != null ? deparenthesizeWithResolutionStrategy(innerExpression, typeResolutionStrategy) : null; + return innerExpression != null ? deparenthesizeWithResolutionStrategy( + innerExpression, deparenthesizeBinaryExpressionWithTypeRHS, typeResolutionStrategy) : null; } return expression; } + @Nullable + public static JetExpression getBaseExpressionIfLabeledExpression(@NotNull JetPrefixExpression expression) { + if (JetTokens.LABELS.contains(expression.getOperationReference().getReferencedNameElementType())) { + return expression.getBaseExpression(); + } + return null; + } + @NotNull public static Name safeName(@Nullable String name) { return name == null ? NO_NAME_PROVIDED : Name.identifier(name); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java index 1e8341cc143..8d40c1d00fa 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java @@ -339,7 +339,7 @@ public class ExpressionTypingServices { public JetExpression deparenthesize( @NotNull JetExpression expression, @NotNull final ExpressionTypingContext context) { - return JetPsiUtil.deparenthesizeWithResolutionStrategy(expression, new Function() { + return JetPsiUtil.deparenthesizeWithResolutionStrategy(expression, true, new Function() { @Override public Void apply(JetTypeReference reference) { getTypeResolver().resolveType(context.scope, reference, context.trace, true);