added deparenthesizeBinaryExpressionWithTypeRHS
param to deparenthesize
This commit is contained in:
@@ -66,16 +66,25 @@ public class JetPsiUtil {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static JetExpression deparenthesizeWithNoTypeResolution(@NotNull JetExpression expression) {
|
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
|
@Nullable
|
||||||
@Deprecated //Use JetPsiUtil.deparenthesizeWithNoTypeResolution() or ExpressionTypingServices.deparenthesize()
|
@Deprecated //Use JetPsiUtil.deparenthesizeWithNoTypeResolution() or ExpressionTypingServices.deparenthesize()
|
||||||
public static JetExpression deparenthesizeWithResolutionStrategy(
|
public static JetExpression deparenthesizeWithResolutionStrategy(
|
||||||
@NotNull JetExpression expression,
|
@NotNull JetExpression expression,
|
||||||
|
boolean deparenthesizeBinaryExpressionWithTypeRHS,
|
||||||
@Nullable Function<JetTypeReference, Void> typeResolutionStrategy
|
@Nullable Function<JetTypeReference, Void> typeResolutionStrategy
|
||||||
) {
|
) {
|
||||||
if (expression instanceof JetBinaryExpressionWithTypeRHS) {
|
if (deparenthesizeBinaryExpressionWithTypeRHS && expression instanceof JetBinaryExpressionWithTypeRHS) {
|
||||||
JetBinaryExpressionWithTypeRHS binaryExpression = (JetBinaryExpressionWithTypeRHS) expression;
|
JetBinaryExpressionWithTypeRHS binaryExpression = (JetBinaryExpressionWithTypeRHS) expression;
|
||||||
JetSimpleNameExpression operationSign = binaryExpression.getOperationReference();
|
JetSimpleNameExpression operationSign = binaryExpression.getOperationReference();
|
||||||
if (JetTokens.COLON.equals(operationSign.getReferencedNameElementType())) {
|
if (JetTokens.COLON.equals(operationSign.getReferencedNameElementType())) {
|
||||||
@@ -87,20 +96,27 @@ public class JetPsiUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (expression instanceof JetPrefixExpression) {
|
else if (expression instanceof JetPrefixExpression) {
|
||||||
if (JetTokens.LABELS.contains(((JetPrefixExpression) expression).getOperationReference().getReferencedNameElementType())) {
|
JetExpression baseExpression = getBaseExpressionIfLabeledExpression((JetPrefixExpression) expression);
|
||||||
JetExpression baseExpression = ((JetPrefixExpression) expression).getBaseExpression();
|
if (baseExpression != null) {
|
||||||
if (baseExpression != null) {
|
expression = baseExpression;
|
||||||
expression = baseExpression;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (expression instanceof JetParenthesizedExpression) {
|
if (expression instanceof JetParenthesizedExpression) {
|
||||||
JetExpression innerExpression = ((JetParenthesizedExpression) expression).getExpression();
|
JetExpression innerExpression = ((JetParenthesizedExpression) expression).getExpression();
|
||||||
return innerExpression != null ? deparenthesizeWithResolutionStrategy(innerExpression, typeResolutionStrategy) : null;
|
return innerExpression != null ? deparenthesizeWithResolutionStrategy(
|
||||||
|
innerExpression, deparenthesizeBinaryExpressionWithTypeRHS, typeResolutionStrategy) : null;
|
||||||
}
|
}
|
||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static JetExpression getBaseExpressionIfLabeledExpression(@NotNull JetPrefixExpression expression) {
|
||||||
|
if (JetTokens.LABELS.contains(expression.getOperationReference().getReferencedNameElementType())) {
|
||||||
|
return expression.getBaseExpression();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Name safeName(@Nullable String name) {
|
public static Name safeName(@Nullable String name) {
|
||||||
return name == null ? NO_NAME_PROVIDED : Name.identifier(name);
|
return name == null ? NO_NAME_PROVIDED : Name.identifier(name);
|
||||||
|
|||||||
+1
-1
@@ -339,7 +339,7 @@ public class ExpressionTypingServices {
|
|||||||
public JetExpression deparenthesize(
|
public JetExpression deparenthesize(
|
||||||
@NotNull JetExpression expression,
|
@NotNull JetExpression expression,
|
||||||
@NotNull final ExpressionTypingContext context) {
|
@NotNull final ExpressionTypingContext context) {
|
||||||
return JetPsiUtil.deparenthesizeWithResolutionStrategy(expression, new Function<JetTypeReference, Void>() {
|
return JetPsiUtil.deparenthesizeWithResolutionStrategy(expression, true, new Function<JetTypeReference, Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void apply(JetTypeReference reference) {
|
public Void apply(JetTypeReference reference) {
|
||||||
getTypeResolver().resolveType(context.scope, reference, context.trace, true);
|
getTypeResolver().resolveType(context.scope, reference, context.trace, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user