added deparenthesizeBinaryExpressionWithTypeRHS

param to deparenthesize
This commit is contained in:
Svetlana Isakova
2013-08-09 18:23:44 +04:00
parent c0f7a82b15
commit 46b099c858
2 changed files with 25 additions and 9 deletions
@@ -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<JetTypeReference, Void> 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);
@@ -339,7 +339,7 @@ public class ExpressionTypingServices {
public JetExpression deparenthesize(
@NotNull JetExpression expression,
@NotNull final ExpressionTypingContext context) {
return JetPsiUtil.deparenthesizeWithResolutionStrategy(expression, new Function<JetTypeReference, Void>() {
return JetPsiUtil.deparenthesizeWithResolutionStrategy(expression, true, new Function<JetTypeReference, Void>() {
@Override
public Void apply(JetTypeReference reference) {
getTypeResolver().resolveType(context.scope, reference, context.trace, true);