Revert "Bug 565752 - QuickFix is blocked by conditional expression"
This reverts commit 88c64c64b5d5d01125a7a607fbfd2f9dde45da9c.
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java
index 03ab0c0..a74fab4 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java
@@ -63,7 +63,6 @@
import org.eclipse.jdt.core.dom.PrimitiveType.Code;
import org.eclipse.jdt.core.dom.QualifiedName;
import org.eclipse.jdt.core.dom.QualifiedType;
-import org.eclipse.jdt.core.dom.ReturnStatement;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
@@ -244,22 +243,28 @@
}
break;
case ASTNode.CONDITIONAL_EXPRESSION:
- ReturnStatement parentReturnStatement= (ReturnStatement) ASTNodes.getParent(node, ASTNode.RETURN_STATEMENT);
- if (parentReturnStatement != null) {
- return getPossibleReferenceBinding(parentReturnStatement.getExpression());
- }
- VariableDeclarationStatement variableDeclarationStatement= (VariableDeclarationStatement) ASTNodes.getParent(node, ASTNode.VARIABLE_DECLARATION_STATEMENT);
- if (variableDeclarationStatement != null) {
- return variableDeclarationStatement.getType().resolveBinding();
- }
ConditionalExpression expression= (ConditionalExpression) parent;
- if (node.equals(expression.getExpression())) {
+
+ if (node.getLocationInParent() == ConditionalExpression.EXPRESSION_PROPERTY) {
return parent.getAST().resolveWellKnownType("boolean"); //$NON-NLS-1$
}
- if (node.equals(expression.getElseExpression())) {
+
+ if (node.getLocationInParent() == ConditionalExpression.THEN_EXPRESSION_PROPERTY
+ && expression.getElseExpression().resolveTypeBinding() != null) {
+ return expression.getElseExpression().resolveTypeBinding();
+ }
+
+ if (node.getLocationInParent() == ConditionalExpression.ELSE_EXPRESSION_PROPERTY
+ && expression.getThenExpression().resolveTypeBinding() != null) {
return expression.getThenExpression().resolveTypeBinding();
}
- return expression.getElseExpression().resolveTypeBinding();
+
+ if (node.getLocationInParent() == ConditionalExpression.THEN_EXPRESSION_PROPERTY
+ || node.getLocationInParent() == ConditionalExpression.ELSE_EXPRESSION_PROPERTY) {
+ return getPossibleReferenceBinding(expression);
+ }
+
+ break;
case ASTNode.POSTFIX_EXPRESSION:
return parent.getAST().resolveWellKnownType("int"); //$NON-NLS-1$
case ASTNode.PREFIX_EXPRESSION:
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java
index 63719c8..b00b38a 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java
@@ -1098,46 +1098,6 @@
}
@Test
- public void testTypeMismatchInAssignment5() throws Exception {
- // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=565752
- IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
- StringBuffer buf= new StringBuffer();
- buf.append("package test1;\n");
- buf.append("import java.util.Map;\n");
- buf.append("public class E {\n");
- buf.append(" static <K1, K2, V> V bar(K1 key1, Map<K1, Map<K2, V>> map) {\n");
- buf.append(" Map<K2, V> secondLevelMap = map.get(key1);\n");
- buf.append(" V v = secondLevelMap == null ? null : secondLevelMap.entrySet();\n");
- buf.append(" return v;\n");
- buf.append(" }\n");
- buf.append("}\n");
-
- ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
-
- CompilationUnit astRoot= getASTRoot(cu);
- ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
- assertNumberOfProposals(proposals, 2);
- assertCorrectLabels(proposals);
-
- CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0);
- String preview1= getPreviewContent(proposal);
-
- buf= new StringBuffer();
- buf.append("package test1;\n");
- buf.append("import java.util.Map;\n");
- buf.append("public class E {\n");
- buf.append(" static <K1, K2, V> V bar(K1 key1, Map<K1, Map<K2, V>> map) {\n");
- buf.append(" Map<K2, V> secondLevelMap = map.get(key1);\n");
- buf.append(" V v = (V) (secondLevelMap == null ? null : secondLevelMap.entrySet());\n");
- buf.append(" return v;\n");
- buf.append(" }\n");
- buf.append("}\n");
- String expected1= buf.toString();
-
- assertEqualStringsIgnoreOrder(new String[] { preview1 }, new String[] { expected1 });
- }
-
- @Test
public void testTypeMismatchInExpression() throws Exception {
IPackageFragment pack0= fSourceFolder.createPackageFragment("test0", false, null);