Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKalyan Prasad Tatavarthi2019-05-16 10:49:21 +0000
committerKalyan Prasad Tatavarthi2019-05-17 05:53:13 +0000
commitd55c08dcfcdc1388c0571f8510369d5a45be1227 (patch)
tree5c67276e7636c01d56ab03ac57ede4b8c58d1b9c
parent037d8d8a9d07b4598f05bd3821eea415d2b32d4c (diff)
downloadeclipse.jdt.ui-d55c08dcfcdc1388c0571f8510369d5a45be1227.tar.gz
eclipse.jdt.ui-d55c08dcfcdc1388c0571f8510369d5a45be1227.tar.xz
eclipse.jdt.ui-d55c08dcfcdc1388c0571f8510369d5a45be1227.zip
Bug 545163 - [12][surround with try/catch] results in error with switch
expression Made changes so that the Surround with try/catch proposal is not shown on a Throw statement. Change-Id: Idd0f9c1603d5e95ace15e6c166e12d554453259d
-rw-r--r--org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java90
-rw-r--r--org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest17.java4
-rw-r--r--org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest18.java57
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java6
4 files changed, 22 insertions, 135 deletions
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java
index 9061c133e2..f615a16485 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -1195,7 +1195,7 @@ public class LocalCorrectionsQuickFixTest extends QuickFixTest {
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
- assertNumberOfProposals(proposals, 2);
+ assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
@@ -1216,27 +1216,7 @@ public class LocalCorrectionsQuickFixTest extends QuickFixTest {
buf.append("}\n");
String expected1= buf.toString();
- proposal= (CUCorrectionProposal)proposals.get(1);
- String preview2= getPreviewContent(proposal);
-
- buf= new StringBuffer();
- buf.append("package test1;\n");
- buf.append("import java.io.IOException;\n");
- buf.append("public class E {\n");
- buf.append(" void foo() {\n");
- buf.append(" try {\n");
- buf.append(" throw new IOException();\n");
- buf.append(" } catch (IOException e) {\n");
- buf.append(" try {\n");
- buf.append(" throw new IOException();\n");
- buf.append(" } catch (IOException e1) {\n");
- buf.append(" }\n");
- buf.append(" }\n");
- buf.append(" }\n");
- buf.append("}\n");
- String expected2= buf.toString();
-
- assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
+ assertEqualStringsIgnoreOrder(new String[] { preview1 }, new String[] { expected1 });
}
public void testUncaughtExceptionImportConflict() throws Exception {
@@ -1704,7 +1684,7 @@ public class LocalCorrectionsQuickFixTest extends QuickFixTest {
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
- assertNumberOfProposals(proposals, 2);
+ assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
@@ -1719,25 +1699,9 @@ public class LocalCorrectionsQuickFixTest extends QuickFixTest {
buf.append(" }\n");
buf.append("}\n");
- proposal= (CUCorrectionProposal) proposals.get(1);
- String preview2= getPreviewContent(proposal);
-
String expected1 = buf.toString();
- buf= new StringBuffer();
- buf.append("package test1;\n");
- buf.append("public class E extends A {\n");
- buf.append(" public void foo() {\n");
- buf.append(" try {\n");
- buf.append(" throw new Exception();\n");
- buf.append(" } catch (Exception e) {\n");
- buf.append(" }\n");
- buf.append(" }\n");
- buf.append("}\n");
-
- String expected2 = buf.toString();
-
- assertEqualStringsIgnoreOrder(new String[] {preview1, preview2}, new String[] {expected1, expected2});
+ assertEqualStringsIgnoreOrder(new String[] {preview1}, new String[] {expected1});
}
public void testUncaughtExceptionOnSuper5() throws Exception {
@@ -1756,7 +1720,7 @@ public class LocalCorrectionsQuickFixTest extends QuickFixTest {
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
- assertNumberOfProposals(proposals, 2);
+ assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
@@ -1775,25 +1739,7 @@ public class LocalCorrectionsQuickFixTest extends QuickFixTest {
String expected1= buf.toString();
- proposal= (CUCorrectionProposal)proposals.get(1);
- String preview2= getPreviewContent(proposal);
-
- buf= new StringBuffer();
- buf.append("package test1;\n");
- buf.append("import java.io.Closeable;\n");
- buf.append("import java.io.FileNotFoundException;\n");
- buf.append("public class A implements Closeable {\n");
- buf.append(" public void close() {\n");
- buf.append(" try {\n");
- buf.append(" throw new FileNotFoundException();\n");
- buf.append(" } catch (FileNotFoundException e) {\n");
- buf.append(" }\n");
- buf.append(" }\n");
- buf.append("}\n");
-
- String expected2= buf.toString();
-
- assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
+ assertEqualStringsIgnoreOrder(new String[] { preview1 }, new String[] { expected1 });
}
public void testUncaughtExceptionOnSuper6() throws Exception {
@@ -1811,28 +1757,8 @@ public class LocalCorrectionsQuickFixTest extends QuickFixTest {
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
- assertNumberOfProposals(proposals, 1);
+ assertNumberOfProposals(proposals, 0);
assertCorrectLabels(proposals);
-
-
- CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0);
- String preview1= getPreviewContent(proposal);
-
- buf= new StringBuffer();
- buf.append("package test1;\n");
- buf.append("import java.io.Closeable;\n");
- buf.append("public class A implements Closeable {\n");
- buf.append(" public void close() {\n");
- buf.append(" try {\n");
- buf.append(" throw new Throwable();\n");
- buf.append(" } catch (Throwable e) {\n");
- buf.append(" }\n");
- buf.append(" }\n");
- buf.append("}\n");
-
- String expected1= buf.toString();
-
- assertEqualStringsIgnoreOrder(new String[] { preview1 }, new String[] { expected1 });
}
public void testUncaughtExceptionOnThis() throws Exception {
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest17.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest17.java
index f3b6bc0efe..eedb3007fb 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest17.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest17.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -120,7 +120,7 @@ public class LocalCorrectionsQuickFixTest17 extends QuickFixTest {
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
- assertNumberOfProposals(proposals, 4);
+ assertNumberOfProposals(proposals, 3);
assertCorrectLabels(proposals);
buf= new StringBuffer();
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest18.java
index b5f52ab0bc..6578cb9da7 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest18.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest18.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2018 IBM Corporation and others.
+ * Copyright (c) 2014, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -116,7 +116,7 @@ public class LocalCorrectionsQuickFixTest18 extends QuickFixTest {
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
- assertNumberOfProposals(proposals, 2);
+ assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
buf= new StringBuffer();
@@ -135,26 +135,7 @@ public class LocalCorrectionsQuickFixTest18 extends QuickFixTest {
buf.append("@interface Marker { }\n");
String expected1= buf.toString();
- buf= new StringBuffer();
- buf.append("package test1;\n");
- buf.append("import java.io.FileNotFoundException;\n");
- buf.append("import java.lang.annotation.ElementType;\n");
- buf.append("import java.lang.annotation.Target;\n");
- buf.append("\n");
- buf.append("public class E {\n");
- buf.append(" void test(int a) {\n");
- buf.append(" try {\n");
- buf.append(" throw new @Marker FileNotFoundException();\n");
- buf.append(" } catch (@Marker FileNotFoundException e) {\n");
- buf.append(" }\n");
- buf.append(" }\n");
- buf.append("}\n");
- buf.append("\n");
- buf.append("@Target(ElementType.TYPE_USE)\n");
- buf.append("@interface Marker { }\n");
- String expected2= buf.toString();
-
- assertExpectedExistInProposals(proposals, new String[] { expected1, expected2 });
+ assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
public void testUncaughtExceptionInLambda1() throws Exception {
@@ -526,33 +507,9 @@ public class LocalCorrectionsQuickFixTest18 extends QuickFixTest {
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
assertCorrectLabels(proposals);
- assertNumberOfProposals(proposals, 3);
-
- String[] expected= new String[3];
- buf= new StringBuffer();
- buf.append("package test;\n");
- buf.append("import java.io.FileNotFoundException;\n");
- buf.append("import java.io.InvalidClassException;\n");
- buf.append("interface C7 {\n");
- buf.append(" int foo(int i);\n");
- buf.append(" default C7 method1() {\n");
- buf.append(" return x -> {\n");
- buf.append(" try {\n");
- buf.append(" if (x == -1)\n");
- buf.append(" throw new InvalidClassException(\"ex\");\n");
- buf.append(" if (x == 0)\n");
- buf.append(" try {\n");
- buf.append(" throw new FileNotFoundException();\n");
- buf.append(" } catch (FileNotFoundException e) {\n");
- buf.append(" }\n");
- buf.append(" } catch (InvalidClassException e) {\n");
- buf.append(" }\n");
- buf.append(" return x;\n");
- buf.append(" };\n");
- buf.append(" }\n");
- buf.append("}\n");
- expected[0]= buf.toString();
+ assertNumberOfProposals(proposals, 2);
+ String[] expected= new String[2];
buf= new StringBuffer();
buf.append("package test;\n");
buf.append("import java.io.FileNotFoundException;\n");
@@ -573,7 +530,7 @@ public class LocalCorrectionsQuickFixTest18 extends QuickFixTest {
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
- expected[1]= buf.toString();
+ expected[0]= buf.toString();
buf= new StringBuffer();
buf.append("package test;\n");
@@ -594,7 +551,7 @@ public class LocalCorrectionsQuickFixTest18 extends QuickFixTest {
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
- expected[2]= buf.toString();
+ expected[1]= buf.toString();
assertExpectedExistInProposals(proposals, expected);
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java
index 680f0f4cbc..00ca61448c 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java
@@ -223,6 +223,10 @@ public class LocalCorrectionsSubProcessor {
if (selectedNode == null) {
return;
}
+ boolean isSelectedNodeThrowStatement= false;
+ if (selectedNode instanceof ThrowStatement) {
+ isSelectedNodeThrowStatement = true;
+ }
int offset= selectedNode.getStartPosition();
int length= selectedNode.getLength();
@@ -254,7 +258,7 @@ public class LocalCorrectionsSubProcessor {
}
refactoring.setLeaveDirty(true);
- if (refactoring.checkActivationBasics(astRoot).isOK()) {
+ if (refactoring.checkActivationBasics(astRoot).isOK() && !isSelectedNodeThrowStatement) {
String label;
if ((vType != null) && (vName != null) && ASTNodes.isVarType(selectedNode, astRoot) && affectedLocals.contains(vName.getIdentifier())) {
label= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_surroundwith_trycatch_var_description, new Object[] { vName.getIdentifier(), vType.getName() });

Back to the top