added ExpressionTypingServices.deparenthesize()
(with type resolution)
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -52,10 +53,24 @@ public class JetPsiUtil {
|
||||
|
||||
@Nullable
|
||||
public static JetExpression deparenthesizeWithNoTypeResolution(@NotNull JetExpression expression) {
|
||||
return deparenthesizeWithResolutionStrategy(expression, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Deprecated //Use JetPsiUtil.deparenthesizeWithNoTypeResolution() or ExpressionTypingServices.deparenthesize()
|
||||
public static JetExpression deparenthesizeWithResolutionStrategy(
|
||||
@NotNull JetExpression expression,
|
||||
@Nullable Function<JetTypeReference, Void> typeResolutionStrategy
|
||||
) {
|
||||
if (expression instanceof JetBinaryExpressionWithTypeRHS) {
|
||||
JetSimpleNameExpression operationSign = ((JetBinaryExpressionWithTypeRHS) expression).getOperationSign();
|
||||
JetBinaryExpressionWithTypeRHS binaryExpression = (JetBinaryExpressionWithTypeRHS) expression;
|
||||
JetSimpleNameExpression operationSign = binaryExpression.getOperationSign();
|
||||
if (JetTokens.COLON.equals(operationSign.getReferencedNameElementType())) {
|
||||
expression = ((JetBinaryExpressionWithTypeRHS) expression).getLeft();
|
||||
expression = binaryExpression.getLeft();
|
||||
JetTypeReference typeReference = binaryExpression.getRight();
|
||||
if (typeResolutionStrategy != null && typeReference != null) {
|
||||
typeResolutionStrategy.apply(typeReference);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (expression instanceof JetPrefixExpression) {
|
||||
@@ -68,7 +83,7 @@ public class JetPsiUtil {
|
||||
}
|
||||
if (expression instanceof JetParenthesizedExpression) {
|
||||
JetExpression innerExpression = ((JetParenthesizedExpression) expression).getExpression();
|
||||
return innerExpression != null ? deparenthesizeWithNoTypeResolution(innerExpression) : null;
|
||||
return innerExpression != null ? deparenthesizeWithResolutionStrategy(innerExpression, typeResolutionStrategy) : null;
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
+14
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.lang.types.expressions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -374,4 +375,17 @@ public class ExpressionTypingServices {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetExpression deparenthesize(
|
||||
@NotNull JetExpression expression,
|
||||
@NotNull final ExpressionTypingContext context) {
|
||||
return JetPsiUtil.deparenthesizeWithResolutionStrategy(expression, new Function<JetTypeReference, Void>() {
|
||||
@Override
|
||||
public Void apply(JetTypeReference reference) {
|
||||
getTypeResolver().resolveType(context.scope, reference, context.trace, true);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -262,7 +262,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
|
||||
protected JetType visitAssignment(JetBinaryExpression expression, ExpressionTypingContext contextWithExpectedType) {
|
||||
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
|
||||
JetExpression left = JetPsiUtil.deparenthesizeWithNoTypeResolution(expression.getLeft());
|
||||
JetExpression left = context.expressionTypingServices.deparenthesize(expression.getLeft(), context);
|
||||
JetExpression right = expression.getRight();
|
||||
if (left instanceof JetArrayAccessExpression) {
|
||||
JetArrayAccessExpression arrayAccessExpression = (JetArrayAccessExpression) left;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package t
|
||||
|
||||
fun foo(array: Array<Int>) {
|
||||
(array[0] : <!DEBUG_INFO_MISSING_UNRESOLVED!>Int<!>) = 22
|
||||
(array[0] : Int) = 22
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve;
|
||||
@InnerTestClasses({JetDiagnosticsTestGenerated.Tests.class, JetDiagnosticsTestGenerated.Script.class})
|
||||
public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEagerResolve {
|
||||
@TestMetadata("compiler/testData/diagnostics/tests")
|
||||
@InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.Enum.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Library.class, Tests.NullabilityAndAutoCasts.class, Tests.NullableTypes.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Scopes.class, Tests.SenselessComparison.class, Tests.Shadowing.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.ThisAndSuper.class, Tests.Tuples.class, Tests.Varargs.class})
|
||||
@InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.Deparenthesize.class, Tests.Enum.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Library.class, Tests.NullabilityAndAutoCasts.class, Tests.NullableTypes.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Scopes.class, Tests.SenselessComparison.class, Tests.Shadowing.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.ThisAndSuper.class, Tests.Tuples.class, Tests.Varargs.class})
|
||||
public static class Tests extends AbstractDiagnosticsTestWithEagerResolve {
|
||||
@TestMetadata("Abstract.kt")
|
||||
public void testAbstract() throws Exception {
|
||||
@@ -1386,6 +1386,19 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/deparenthesize")
|
||||
public static class Deparenthesize extends AbstractDiagnosticsTestWithEagerResolve {
|
||||
public void testAllFilesPresentInDeparenthesize() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/deparenthesize"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayAccessAssignment.kt")
|
||||
public void testArrayAccessAssignment() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/deparenthesize/ArrayAccessAssignment.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/enum")
|
||||
@InnerTestClasses({Enum.Inner.class})
|
||||
public static class Enum extends AbstractDiagnosticsTestWithEagerResolve {
|
||||
@@ -3686,6 +3699,7 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
suite.addTestSuite(DataFlow.class);
|
||||
suite.addTestSuite(DataFlowInfoTraversal.class);
|
||||
suite.addTest(DeclarationChecks.innerSuite());
|
||||
suite.addTestSuite(Deparenthesize.class);
|
||||
suite.addTest(Enum.innerSuite());
|
||||
suite.addTestSuite(Extensions.class);
|
||||
suite.addTestSuite(FunctionLiterals.class);
|
||||
|
||||
Reference in New Issue
Block a user