Merge remote-tracking branch 'origin/master' into BETA_JAVA9
diff --git a/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/ProblemNode.java b/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/ProblemNode.java
index 5465668..e9e4246 100644
--- a/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/ProblemNode.java
+++ b/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/ProblemNode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -65,6 +65,8 @@
buf.append("E");
if (fProblem.isWarning())
buf.append("W");
+ if (fProblem.isInfo())
+ buf.append("I");
buf.append('[').append(offset).append(", ").append(length).append(']').append(' ');
buf.append(fProblem.getMessage());
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestLambda1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestLambda1.java
new file mode 100644
index 0000000..fa5feb8
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestLambda1.java
@@ -0,0 +1,12 @@
+package trycatch18_in;
+
+public class TestLambda1 {
+ private TestLambda1 log;
+ void test() {
+ Runnable r = () -> /*[*/log.info("Processing rule #{} {}", "")/*]*/;
+ }
+
+ private void info(String string, Object object) throws GridException1 {}
+}
+@SuppressWarnings("serial")
+class GridException1 extends Exception {}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestLambda2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestLambda2.java
new file mode 100644
index 0000000..db7a3a3
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestLambda2.java
@@ -0,0 +1,12 @@
+package trycatch18_in;
+
+public class TestLambda2 {
+ private TestLambda2 log;
+ void test() {
+ Runnable r = () -> /*[*/log/*]*/.info("Processing rule #{} {}", "");
+ }
+
+ private void info(String string, Object object) throws GridException1 {}
+}
+@SuppressWarnings("serial")
+class GridException1 extends Exception {}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestLambda3.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestLambda3.java
new file mode 100644
index 0000000..3a2cca2
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestLambda3.java
@@ -0,0 +1,15 @@
+package trycatch18_in;
+
+import java.io.FileNotFoundException;
+
+interface TestLambda2 {
+ int foo(int i);
+
+ default TestLambda2 method1() {
+ return x -> {
+ if (x == 0)
+ /*[*/throw new FileNotFoundException();/*]*/
+ return x;
+ };
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestLambda4.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestLambda4.java
new file mode 100644
index 0000000..4d3209c
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestLambda4.java
@@ -0,0 +1,15 @@
+package trycatch18_in;
+
+import java.io.FileNotFoundException;
+
+interface TestLambda2 {
+ int foo(int i);
+
+ default TestLambda2 method1() {
+ /*[*/return x -> {
+ if (x == 0)
+ throw new FileNotFoundException();
+ return x;
+ };/*]*/
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference1.java
new file mode 100644
index 0000000..8a0a73f
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference1.java
@@ -0,0 +1,19 @@
+package trycatch18_in;
+
+import java.io.FileNotFoundException;
+import java.util.Optional;
+
+
+public class TestMethodReference1 {
+ private static Transformer2 TRANSFORMER = new Transformer2();
+
+ public void test() {
+ /*[*/Optional.ofNullable("10").map(TRANSFORMER::transform).ifPresent(System.out::print);/*]*/
+ }
+}
+
+class Transformer2 {
+ Long transform(String number) throws FileNotFoundException {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference2.java
new file mode 100644
index 0000000..1a1ec80
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference2.java
@@ -0,0 +1,19 @@
+package trycatch18_in;
+
+import java.io.FileNotFoundException;
+import java.util.Optional;
+import java.util.function.Consumer;
+
+public class TestMethodReference2 {
+ private static Transformer TRANSFORMER = new Transformer();
+
+ public void test() {
+ /*[*/Consumer<Object> s = (a) -> Optional.ofNullable("10").map(TRANSFORMER::transform).ifPresent(System.out::print);/*]*/
+ }
+}
+
+class Transformer {
+ Long transform(String number) throws FileNotFoundException {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference3.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference3.java
new file mode 100644
index 0000000..aed59a4
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference3.java
@@ -0,0 +1,16 @@
+package trycatch18_in;
+
+import java.io.IOException;
+
+public class TestMethodReference3 {
+ {
+ FI fi = /*[*/this::test/*]*/;
+ }
+
+ private void test() throws IOException {
+ }
+
+ interface FI {
+ <T> void foo();
+ }
+}
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference4.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference4.java
new file mode 100644
index 0000000..ea01d6f
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference4.java
@@ -0,0 +1,19 @@
+package trycatch18_in;
+
+import java.io.FileNotFoundException;
+import java.util.Optional;
+
+
+public class TestMethodReference4 {
+ private static Transformer2 TRANSFORMER = new Transformer2();
+
+ public void test() {
+ Optional.ofNullable("10").map(/*[*/TRANSFORMER::transform/*]*/).ifPresent(System.out::print);
+ }
+}
+
+class Transformer2 {
+ Long transform(String number) throws FileNotFoundException {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference5.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference5.java
new file mode 100644
index 0000000..7b43969
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference5.java
@@ -0,0 +1,19 @@
+package trycatch18_in;
+
+import java.io.FileNotFoundException;
+import java.util.Optional;
+
+
+public class TestMethodReference5 {
+ private static Transformer2 TRANSFORMER = new Transformer2();
+
+ public void test() {
+ Optional.ofNullable("10").map(TRANSFORMER::/*[*/transform/*]*/).ifPresent(System.out::print);
+ }
+}
+
+class Transformer2 {
+ Long transform(String number) throws FileNotFoundException {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference6.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference6.java
new file mode 100644
index 0000000..faa7b2d
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_in/TestMethodReference6.java
@@ -0,0 +1,19 @@
+package trycatch18_in;
+
+import java.io.FileNotFoundException;
+import java.util.Optional;
+
+
+public class TestMethodReference6 {
+ private static Transformer2 TRANSFORMER = new Transformer2();
+
+ public void test() {
+ Optional.ofNullable("10").map(/*]*/TRANSFORMER::transform/*[*/).ifPresent(System.out::print);
+ }
+}
+
+class Transformer2 {
+ Long transform(String number) throws FileNotFoundException {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestLambda1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestLambda1.java
new file mode 100644
index 0000000..7315af8
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestLambda1.java
@@ -0,0 +1,17 @@
+package trycatch18_out;
+
+public class TestLambda1 {
+ private TestLambda1 log;
+ void test() {
+ Runnable r = () -> {
+ try {
+ /*[*/log.info("Processing rule #{} {}", "")/*]*/;
+ } catch (GridException1 e) {
+ }
+ };
+ }
+
+ private void info(String string, Object object) throws GridException1 {}
+}
+@SuppressWarnings("serial")
+class GridException1 extends Exception {}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestLambda3.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestLambda3.java
new file mode 100644
index 0000000..1a3aaed
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestLambda3.java
@@ -0,0 +1,18 @@
+package trycatch18_out;
+
+import java.io.FileNotFoundException;
+
+interface TestLambda2 {
+ int foo(int i);
+
+ default TestLambda2 method1() {
+ return x -> {
+ if (x == 0)
+ try {
+ /*[*/throw new FileNotFoundException();/*]*/
+ } catch (FileNotFoundException e) {
+ }
+ return x;
+ };
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestLambda4.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestLambda4.java
new file mode 100644
index 0000000..b6633cf
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestLambda4.java
@@ -0,0 +1,18 @@
+package trycatch18_in;
+
+import java.io.FileNotFoundException;
+
+interface TestLambda2 {
+ int foo(int i);
+
+ default TestLambda2 method1() {
+ try {
+ /*[*/return x -> {
+ if (x == 0)
+ throw new FileNotFoundException();
+ return x;
+ };/*]*/
+ } catch (Exception e) {
+ }
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestMethodReference1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestMethodReference1.java
new file mode 100644
index 0000000..9aaba64
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestMethodReference1.java
@@ -0,0 +1,22 @@
+package trycatch18_out;
+
+import java.io.FileNotFoundException;
+import java.util.Optional;
+
+
+public class TestMethodReference1 {
+ private static Transformer2 TRANSFORMER = new Transformer2();
+
+ public void test() {
+ try {
+ /*[*/Optional.ofNullable("10").map(TRANSFORMER::transform).ifPresent(System.out::print);/*]*/
+ } catch (Exception e) {
+ }
+ }
+}
+
+class Transformer2 {
+ Long transform(String number) throws FileNotFoundException {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestMethodReference2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestMethodReference2.java
new file mode 100644
index 0000000..7038ff3
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestMethodReference2.java
@@ -0,0 +1,22 @@
+package trycatch18_out;
+
+import java.io.FileNotFoundException;
+import java.util.Optional;
+import java.util.function.Consumer;
+
+public class TestMethodReference2 {
+ private static Transformer TRANSFORMER = new Transformer();
+
+ public void test() {
+ try {
+ /*[*/Consumer<Object> s = (a) -> Optional.ofNullable("10").map(TRANSFORMER::transform).ifPresent(System.out::print);/*]*/
+ } catch (Exception e) {
+ }
+ }
+}
+
+class Transformer {
+ Long transform(String number) throws FileNotFoundException {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestMethodReference4.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestMethodReference4.java
new file mode 100644
index 0000000..2d48b58
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestMethodReference4.java
@@ -0,0 +1,24 @@
+package trycatch18_out;
+
+import java.io.FileNotFoundException;
+import java.util.Optional;
+
+
+public class TestMethodReference4 {
+ private static Transformer2 TRANSFORMER = new Transformer2();
+
+ public void test() {
+ Optional.ofNullable("10").map(arg0 -> {
+ try {
+ return TRANSFORMER.transform/*]*/(arg0);
+ } catch (FileNotFoundException e) {
+ }
+ }).ifPresent(System.out::print);
+ }
+}
+
+class Transformer2 {
+ Long transform(String number) throws FileNotFoundException {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestMethodReference6.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestMethodReference6.java
new file mode 100644
index 0000000..7706769
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch18_out/TestMethodReference6.java
@@ -0,0 +1,24 @@
+package trycatch18_out;
+
+import java.io.FileNotFoundException;
+import java.util.Optional;
+
+
+public class TestMethodReference6 {
+ private static Transformer2 TRANSFORMER = new Transformer2();
+
+ public void test() {
+ Optional.ofNullable("10").map(/*]*/arg0 -> {
+ try {
+ return TRANSFORMER.transform(arg0);
+ } catch (FileNotFoundException e) {
+ }
+ }/*[*/).ifPresent(System.out::print);
+ }
+}
+
+class Transformer2 {
+ Long transform(String number) throws FileNotFoundException {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithTests18.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithTests18.java
index 8eb2380..5439139 100644
--- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithTests18.java
+++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithTests18.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014 IBM Corporation and others.
+ * Copyright (c) 2014, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,13 +10,13 @@
*******************************************************************************/
package org.eclipse.jdt.ui.tests.refactoring;
-import junit.framework.Test;
-
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryCatchRefactoring;
+import junit.framework.Test;
+
public class SurroundWithTests18 extends SurroundWithTests {
private static SurroundWithTestSetup18 fgTestSetup;
@@ -58,4 +58,44 @@
public void testSimple1() throws Exception {
tryCatchTest();
}
+
+ public void testLambda1() throws Exception {
+ tryCatchTest();
+ }
+
+ public void testLambda2() throws Exception {
+ tryCatchInvalidTest();
+ }
+
+ public void testLambda3() throws Exception {
+ tryCatchTest();
+ }
+
+ public void testLambda4() throws Exception {
+ tryCatchTest();
+ }
+
+ public void testMethodReference1() throws Exception {
+ tryCatchTest();
+ }
+
+ public void testMethodReference2() throws Exception {
+ tryCatchTest();
+ }
+
+ public void testMethodReference3() throws Exception {
+ tryCatchInvalidTest();
+ }
+
+ public void testMethodReference4() throws Exception {
+ tryCatchTest();
+ }
+
+ public void testMethodReference5() throws Exception {
+ tryCatchInvalidTest();
+ }
+
+ public void testMethodReference6() throws Exception {
+ tryCatchTest();
+ }
}
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest.java
index 8fc1d4d..82b2728 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest.java
@@ -447,7 +447,7 @@
boolean hasProblems= false;
for (int i= 0; i < problems.length; i++) {
IProblem prob= problems[i];
- if (prob.isWarning()) {
+ if (prob.isWarning() || prob.isInfo()) {
continue;
}
switch (prob.getID()) {
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java
index ef2e267..cf16a0e 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java
@@ -946,6 +946,74 @@
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
+ public void testConvertToLambda19() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public class C1 {\n");
+ buf.append(" Runnable r1 = new/*[1]*/ Runnable() {\n");
+ buf.append(" @Override @A @Deprecated\n");
+ buf.append(" public void run() {\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" Runnable r2 = new/*[2]*/ Runnable() {\n");
+ buf.append(" @Override @Deprecated\n");
+ buf.append(" public void run() {\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append("}\n");
+ buf.append("@interface A {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf.toString(), false, null);
+
+ int offset= buf.toString().indexOf("new/*[1]*/");
+ AssistContext context= getCorrectionContext(cu, offset, 0);
+ assertNoErrors(context);
+ List<IJavaCompletionProposal> proposals= collectAssists(context, false);
+
+ assertNumberOfProposals(proposals, 1);
+ assertCorrectLabels(proposals);
+
+ StringBuffer buf1= new StringBuffer();
+ buf1.append("package test;\n");
+ buf1.append("public class C1 {\n");
+ buf1.append(" Runnable r1 = () -> {\n");
+ buf1.append(" };\n");
+ buf1.append(" Runnable r2 = new/*[2]*/ Runnable() {\n");
+ buf1.append(" @Override @Deprecated\n");
+ buf1.append(" public void run() {\n");
+ buf1.append(" }\n");
+ buf1.append(" };\n");
+ buf1.append("}\n");
+ buf1.append("@interface A {}\n");
+ String expected= buf1.toString();
+
+ assertExpectedExistInProposals(proposals, new String[] { expected });
+
+ offset= buf.toString().indexOf("new/*[2]*/");
+ context= getCorrectionContext(cu, offset, 0);
+ assertNoErrors(context);
+ proposals= collectAssists(context, false);
+
+ assertNumberOfProposals(proposals, 1);
+ assertCorrectLabels(proposals);
+
+ buf1= new StringBuffer();
+ buf1.append("package test;\n");
+ buf1.append("public class C1 {\n");
+ buf1.append(" Runnable r1 = new/*[1]*/ Runnable() {\n");
+ buf1.append(" @Override @A @Deprecated\n");
+ buf1.append(" public void run() {\n");
+ buf1.append(" }\n");
+ buf1.append(" };\n");
+ buf1.append(" Runnable r2 = () -> {\n");
+ buf1.append(" };\n");
+ buf1.append("}\n");
+ buf1.append("@interface A {}\n");
+ expected= buf1.toString();
+
+ assertExpectedExistInProposals(proposals, new String[] { expected });
+ }
+
public void testConvertToLambdaAmbiguousOverridden() throws Exception {
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest18.java
index be59039..06e80ad 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest18.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest18.java
@@ -704,6 +704,46 @@
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 });
}
+ public void testConvertToLambdaWithMethodAnnotations() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public class C1 {\n");
+ buf.append(" Runnable r1 = new Runnable() {\n");
+ buf.append(" @Override @A @Deprecated\n");
+ buf.append(" public void run() {\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" Runnable r2 = new Runnable() {\n");
+ buf.append(" @Override @Deprecated\n");
+ buf.append(" public void run() {\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append("}\n");
+ buf.append("@interface A {}\n");
+ String original= buf.toString();
+ ICompilationUnit cu1= pack1.createCompilationUnit("C1.java", original, false, null);
+
+ enable(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES);
+ enable(CleanUpConstants.USE_LAMBDA);
+
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public class C1 {\n");
+ buf.append(" Runnable r1 = new Runnable() {\n");
+ buf.append(" @Override @A @Deprecated\n");
+ buf.append(" public void run() {\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" Runnable r2 = () -> {\n");
+ buf.append(" };\n");
+ buf.append("}\n");
+ buf.append("@interface A {}\n");
+ String expected1= buf.toString();
+
+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 });
+ }
+
public void testConvertToAnonymousWithWildcards() throws Exception {
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
StringBuffer buf= new StringBuffer();
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 2f19547..d8c08fb 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, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -214,7 +214,7 @@
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 3, 0); //quick fix on 1st problem
- assertNumberOfProposals(proposals, 3);
+ assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
@@ -272,34 +272,7 @@
buf.append("}\n");
String expected2= buf.toString();
- proposal= (CUCorrectionProposal)proposals.get(2);
- String preview3= getPreviewContent(proposal);
-
- buf= new StringBuffer();
- buf.append("package test1;\n");
- buf.append("import java.io.FileInputStream;\n");
- buf.append("import java.io.FileNotFoundException;\n");
- buf.append("import java.io.IOException;\n");
- buf.append("class MyException extends Exception {\n");
- buf.append(" static final long serialVersionUID = 1L;\n");
- buf.append("}\n");
- buf.append("public class E {\n");
- buf.append(" void bar(int n) throws IllegalArgumentException, MyException {\n");
- buf.append(" if (n == 1)\n");
- buf.append(" throw new IllegalArgumentException();\n");
- buf.append(" else\n");
- buf.append(" throw new MyException();\n");
- buf.append(" }\n");
- buf.append(" void foo(String name, boolean b) {\n");
- buf.append(" try (FileInputStream fis = new FileInputStream(name)) {\n");
- buf.append(" bar(1);\n");
- buf.append(" } catch (FileNotFoundException | IOException e) {\n");
- buf.append(" }\n");
- buf.append(" }\n");
- buf.append("}\n");
- String expected3= buf.toString();
-
- assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3 }, new String[] { expected1, expected2, expected3 });
+ assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
}
public void testUncaughtExceptionTryWithResources2() throws Exception {
@@ -329,7 +302,7 @@
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 3, 1); //quick fix on 2nd problem
- assertNumberOfProposals(proposals, 3);
+ assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
@@ -387,34 +360,7 @@
buf.append("}\n");
String expected2= buf.toString();
- proposal= (CUCorrectionProposal)proposals.get(2);
- String preview3= getPreviewContent(proposal);
-
- buf= new StringBuffer();
- buf.append("package test1;\n");
- buf.append("import java.io.FileInputStream;\n");
- buf.append("import java.io.FileNotFoundException;\n");
- buf.append("import java.io.IOException;\n");
- buf.append("class MyException extends Exception {\n");
- buf.append(" static final long serialVersionUID = 1L;\n");
- buf.append("}\n");
- buf.append("public class E {\n");
- buf.append(" void bar(int n) throws IllegalArgumentException, MyException {\n");
- buf.append(" if (n == 1)\n");
- buf.append(" throw new IllegalArgumentException();\n");
- buf.append(" else\n");
- buf.append(" throw new MyException();\n");
- buf.append(" }\n");
- buf.append(" void foo(String name, boolean b) {\n");
- buf.append(" try (FileInputStream fis = new FileInputStream(name)) {\n");
- buf.append(" bar(1);\n");
- buf.append(" } catch (FileNotFoundException | IOException e) {\n");
- buf.append(" }\n");
- buf.append(" }\n");
- buf.append("}\n");
- String expected3= buf.toString();
-
- assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3 }, new String[] { expected1, expected2, expected3 });
+ assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
}
public void testUncaughtExceptionTryWithResources3() throws Exception {
@@ -701,7 +647,7 @@
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 2, 0); //quick fix on 1st problem
- assertNumberOfProposals(proposals, 3);
+ assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
@@ -741,25 +687,181 @@
buf.append("}\n");
String expected2= buf.toString();
- proposal= (CUCorrectionProposal)proposals.get(2);
+ assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
+ }
+
+ public void testUncaughtExceptionTryWithResources6() throws Exception {
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=478714
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("\n");
+ buf.append("import java.io.ByteArrayInputStream;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.io.InputStream;\n");
+ buf.append("\n");
+ buf.append("public class E {\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" try (InputStream foo = new ByteArrayInputStream(\"foo\".getBytes(\"UTF-8\"))) {\n");
+ buf.append(" String bla = new String(ByteStreams.toByteArray(foo), \"UTF-8\");\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("\n");
+ buf.append("class ByteStreams {\n");
+ buf.append(" public static byte[] toByteArray(InputStream foo) throws IOException, ArithmeticException {\n");
+ buf.append(" return null;\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, 4, 2);
+ assertNumberOfProposals(proposals, 5);
+ assertCorrectLabels(proposals);
+
+ CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0);
+ String preview1= getPreviewContent(proposal);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("\n");
+ buf.append("import java.io.ByteArrayInputStream;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.io.InputStream;\n");
+ buf.append("import java.io.UnsupportedEncodingException;\n");
+ buf.append("\n");
+ buf.append("public class E {\n");
+ buf.append(" public static void main(String[] args) throws UnsupportedEncodingException, ArithmeticException, IOException {\n");
+ buf.append(" try (InputStream foo = new ByteArrayInputStream(\"foo\".getBytes(\"UTF-8\"))) {\n");
+ buf.append(" String bla = new String(ByteStreams.toByteArray(foo), \"UTF-8\");\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("\n");
+ buf.append("class ByteStreams {\n");
+ buf.append(" public static byte[] toByteArray(InputStream foo) throws IOException, ArithmeticException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ 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("\n");
+ buf.append("import java.io.ByteArrayInputStream;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.io.InputStream;\n");
+ buf.append("import java.io.UnsupportedEncodingException;\n");
+ buf.append("\n");
+ buf.append("public class E {\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" try (InputStream foo = new ByteArrayInputStream(\"foo\".getBytes(\"UTF-8\"))) {\n");
+ buf.append(" String bla = new String(ByteStreams.toByteArray(foo), \"UTF-8\");\n");
+ buf.append(" } catch (UnsupportedEncodingException e) {\n");
+ buf.append(" } catch (ArithmeticException e) {\n");
+ buf.append(" } catch (IOException e) {\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("\n");
+ buf.append("class ByteStreams {\n");
+ buf.append(" public static byte[] toByteArray(InputStream foo) throws IOException, ArithmeticException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ String expected2= buf.toString();
+
+ proposal= (CUCorrectionProposal) proposals.get(2);
String preview3= getPreviewContent(proposal);
buf= new StringBuffer();
buf.append("package test1;\n");
- buf.append("import java.io.FileInputStream;\n");
- buf.append("import java.io.FileNotFoundException;\n");
+ buf.append("\n");
+ buf.append("import java.io.ByteArrayInputStream;\n");
buf.append("import java.io.IOException;\n");
+ buf.append("import java.io.InputStream;\n");
+ buf.append("\n");
buf.append("public class E {\n");
- buf.append(" void foo(String name, boolean b) {\n");
- buf.append(" String e;\n");
- buf.append(" try (FileInputStream fis = new FileInputStream(name)) {\n");
- buf.append(" } catch (FileNotFoundException | IOException e1) {\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" try (InputStream foo = new ByteArrayInputStream(\"foo\".getBytes(\"UTF-8\"))) {\n");
+ buf.append(" String bla = new String(ByteStreams.toByteArray(foo), \"UTF-8\");\n");
+ buf.append(" } catch (ArithmeticException | IOException e) {\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
+ buf.append("\n");
+ buf.append("class ByteStreams {\n");
+ buf.append(" public static byte[] toByteArray(InputStream foo) throws IOException, ArithmeticException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
String expected3= buf.toString();
- assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3 }, new String[] { expected1, expected2, expected3 });
+ proposal= (CUCorrectionProposal) proposals.get(3);
+ String preview4= getPreviewContent(proposal);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("\n");
+ buf.append("import java.io.ByteArrayInputStream;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.io.InputStream;\n");
+ buf.append("\n");
+ buf.append("public class E {\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" try (InputStream foo = new ByteArrayInputStream(\"foo\".getBytes(\"UTF-8\"))) {\n");
+ buf.append(" try {\n");
+ buf.append(" String bla = new String(ByteStreams.toByteArray(foo), \"UTF-8\");\n");
+ buf.append(" } catch (ArithmeticException | IOException e) {\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("\n");
+ buf.append("class ByteStreams {\n");
+ buf.append(" public static byte[] toByteArray(InputStream foo) throws IOException, ArithmeticException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ String expected4= buf.toString();
+
+ proposal= (CUCorrectionProposal) proposals.get(4);
+ String preview5= getPreviewContent(proposal);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("\n");
+ buf.append("import java.io.ByteArrayInputStream;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.io.InputStream;\n");
+ buf.append("import java.io.UnsupportedEncodingException;\n");
+ buf.append("\n");
+ buf.append("public class E {\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" try (InputStream foo = new ByteArrayInputStream(\"foo\".getBytes(\"UTF-8\"))) {\n");
+ buf.append(" try {\n");
+ buf.append(" String bla = new String(ByteStreams.toByteArray(foo), \"UTF-8\");\n");
+ buf.append(" } catch (UnsupportedEncodingException e) {\n");
+ buf.append(" } catch (ArithmeticException e) {\n");
+ buf.append(" } catch (IOException e) {\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("\n");
+ buf.append("class ByteStreams {\n");
+ buf.append(" public static byte[] toByteArray(InputStream foo) throws IOException, ArithmeticException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ String expected5= buf.toString();
+
+ assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3, preview4, preview5 }, new String[] { expected1, expected2, expected3, expected4, expected5 });
}
public void testUnneededCaughtException1() throws Exception {
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 4625c88..9d0e29f 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
@@ -34,6 +34,7 @@
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.text.correction.CorrectionMessages;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -152,6 +153,769 @@
assertExpectedExistInProposals(proposals, new String[] { expected1, expected2 });
}
+ public void testUncaughtExceptionInLambda1() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public class C1 {\n");
+ buf.append(" Runnable r = () -> info(\"Processing rule #{} {}\", \"\");\n");
+ buf.append("\n");
+ buf.append(" private void info(String string, Object object) throws GridException1 {}\n");
+ buf.append("}\n");
+ buf.append("@SuppressWarnings(\"serial\")\n");
+ buf.append("class GridException1 extends Exception {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+ assertNumberOfProposals(proposals, 1);
+ assertCorrectLabels(proposals);
+
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public class C1 {\n");
+ buf.append(" Runnable r = () -> {\n");
+ buf.append(" try {\n");
+ buf.append(" info(\"Processing rule #{} {}\", \"\");\n");
+ buf.append(" } catch (GridException1 e) {\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append("\n");
+ buf.append(" private void info(String string, Object object) throws GridException1 {}\n");
+ buf.append("}\n");
+ buf.append("@SuppressWarnings(\"serial\")\n");
+ buf.append("class GridException1 extends Exception {}\n");
+ String expected= buf.toString();
+
+ assertExpectedExistInProposals(proposals, new String[] { expected });
+ }
+
+ public void testUncaughtExceptionInLambda2() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public class C2 {\n");
+ buf.append(" void test() {\n");
+ buf.append(" Runnable r = () -> info(\"Processing rule #{} {}\", \"\");\n");
+ buf.append(" }\n");
+ buf.append("\n");
+ buf.append(" private void info(String string, Object object) throws GridException2 {}\n");
+ buf.append("}\n");
+ buf.append("@SuppressWarnings(\"serial\")\n");
+ buf.append("class GridException2 extends Exception {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("C2.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 1);
+
+ String[] expected= new String[1];
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public class C2 {\n");
+ buf.append(" void test() {\n");
+ buf.append(" Runnable r = () -> {\n");
+ buf.append(" try {\n");
+ buf.append(" info(\"Processing rule #{} {}\", \"\");\n");
+ buf.append(" } catch (GridException2 e) {\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("\n");
+ buf.append(" private void info(String string, Object object) throws GridException2 {}\n");
+ buf.append("}\n");
+ buf.append("@SuppressWarnings(\"serial\")\n");
+ buf.append("class GridException2 extends Exception {}\n");
+ expected[0]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+
+ assertProposalDoesNotExist(proposals, CorrectionMessages.LocalCorrectionsSubProcessor_addthrows_description);
+ }
+
+ public void testUncaughtExceptionInLambda3() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.util.ArrayList;\n");
+ buf.append("public class C3 {\n");
+ buf.append(" void test(ArrayList<Integer> ruleIds) {\n");
+ buf.append(" Runnable r = () -> {\n");
+ buf.append(" for (int ruleId : ruleIds) {\n");
+ buf.append(" info(\"Processing rule #{} {}\", ruleId);\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("\n");
+ buf.append(" private void info(String string, Object object) throws GridException3 {}\n");
+ buf.append("}\n");
+ buf.append("@SuppressWarnings(\"serial\")\n");
+ buf.append("class GridException3 extends Exception {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("C3.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 1);
+
+ String[] expected= new String[1];
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.util.ArrayList;\n");
+ buf.append("public class C3 {\n");
+ buf.append(" void test(ArrayList<Integer> ruleIds) {\n");
+ buf.append(" Runnable r = () -> {\n");
+ buf.append(" for (int ruleId : ruleIds) {\n");
+ buf.append(" try {\n");
+ buf.append(" info(\"Processing rule #{} {}\", ruleId);\n");
+ buf.append(" } catch (GridException3 e) {\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("\n");
+ buf.append(" private void info(String string, Object object) throws GridException3 {}\n");
+ buf.append("}\n");
+ buf.append("@SuppressWarnings(\"serial\")\n");
+ buf.append("class GridException3 extends Exception {}\n");
+ expected[0]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+ }
+
+ public void testUncaughtExceptionInLambda4() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.File;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.util.stream.Stream;\n");
+ buf.append("public class C4 {\n");
+ buf.append(" void foo() {\n");
+ buf.append(" try {\n");
+ buf.append(" Files.walk(new File(\".\").toPath()).filter(p -> p.toString().endsWith(\".java\"))\n");
+ buf.append(" .forEach(p -> Files.lines(p).forEach(System.out::println));\n");
+ buf.append(" } catch (IOException e) {}\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("class Files {\n");
+ buf.append(" public static Stream<Object> walk(Object start) throws IOException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append(" public static Stream<String> lines(Object path) throws IOException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("C4.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 1);
+
+ String[] expected= new String[1];
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.File;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.util.stream.Stream;\n");
+ buf.append("public class C4 {\n");
+ buf.append(" void foo() {\n");
+ buf.append(" try {\n");
+ buf.append(" Files.walk(new File(\".\").toPath()).filter(p -> p.toString().endsWith(\".java\"))\n");
+ buf.append(" .forEach(p -> {\n");
+ buf.append(" try {\n");
+ buf.append(" Files.lines(p).forEach(System.out::println);\n");
+ buf.append(" } catch (IOException e) {\n");
+ buf.append(" }\n");
+ buf.append(" });\n");
+ buf.append(" } catch (IOException e) {}\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("class Files {\n");
+ buf.append(" public static Stream<Object> walk(Object start) throws IOException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append(" public static Stream<String> lines(Object path) throws IOException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ expected[0]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+ }
+
+ public void testUncaughtExceptionInLambda5() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.File;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.util.function.Consumer;\n");
+ buf.append("import java.util.stream.Stream;\n");
+ buf.append("\n");
+ buf.append("public class C5 {\n");
+ buf.append(" void foo() {\n");
+ buf.append(" Consumer<Object> s = (a) -> Files.walk(new File(\".\").toPath())\n");
+ buf.append(" .filter(p -> p.toString().endsWith(\".java\"))\n");
+ buf.append(" .forEach(p -> {\n");
+ buf.append(" try {\n");
+ buf.append(" Files.lines(p).forEach(System.out::println);\n");
+ buf.append(" } catch (IOException e) {}\n");
+ buf.append(" });\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("class Files {\n");
+ buf.append(" public static Stream<Object> walk(Object start) throws IOException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append(" public static Stream<String> lines(Object path) throws IOException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("C5.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 1);
+
+ String[] expected= new String[1];
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.File;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.util.function.Consumer;\n");
+ buf.append("import java.util.stream.Stream;\n");
+ buf.append("\n");
+ buf.append("public class C5 {\n");
+ buf.append(" void foo() {\n");
+ buf.append(" Consumer<Object> s = (a) -> {\n");
+ buf.append(" try {\n");
+ buf.append(" Files.walk(new File(\".\").toPath())\n");
+ buf.append(" .filter(p -> p.toString().endsWith(\".java\"))\n");
+ buf.append(" .forEach(p -> {\n");
+ buf.append(" try {\n");
+ buf.append(" Files.lines(p).forEach(System.out::println);\n");
+ buf.append(" } catch (IOException e) {}\n");
+ buf.append(" });\n");
+ buf.append(" } catch (IOException e) {\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("class Files {\n");
+ buf.append(" public static Stream<Object> walk(Object start) throws IOException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append(" public static Stream<String> lines(Object path) throws IOException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ expected[0]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+ }
+
+ public void testUncaughtExceptionInLambda6() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.File;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.util.function.Consumer;\n");
+ buf.append("import java.util.stream.Stream;\n");
+ buf.append("\n");
+ buf.append("public class C5 {\n");
+ buf.append(" void foo() {\n");
+ buf.append(" Consumer<Object> s = (a) -> {\n");
+ buf.append(" try {\n");
+ buf.append(" Files.walk(new File(\".\").toPath())\n");
+ buf.append(" .filter(p -> p.toString().endsWith(\".java\"))\n");
+ buf.append(" .forEach(p -> Files.lines(p).forEach(System.out::println));\n");
+ buf.append(" } catch (IOException e) {}\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("class Files {\n");
+ buf.append(" public static Stream<Object> walk(Object start) throws IOException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append(" public static Stream<String> lines(Object path) throws IOException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("C5.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 1);
+
+ String[] expected= new String[1];
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.File;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.util.function.Consumer;\n");
+ buf.append("import java.util.stream.Stream;\n");
+ buf.append("\n");
+ buf.append("public class C5 {\n");
+ buf.append(" void foo() {\n");
+ buf.append(" Consumer<Object> s = (a) -> {\n");
+ buf.append(" try {\n");
+ buf.append(" Files.walk(new File(\".\").toPath())\n");
+ buf.append(" .filter(p -> p.toString().endsWith(\".java\"))\n");
+ buf.append(" .forEach(p -> {\n");
+ buf.append(" try {\n");
+ buf.append(" Files.lines(p).forEach(System.out::println);\n");
+ buf.append(" } catch (IOException e) {\n");
+ buf.append(" }\n");
+ buf.append(" });\n");
+ buf.append(" } catch (IOException e) {}\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("class Files {\n");
+ buf.append(" public static Stream<Object> walk(Object start) throws IOException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append(" public static Stream<String> lines(Object path) throws IOException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ expected[0]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+ }
+
+ public void testUncaughtExceptionInLambda7() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer 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(" throw new FileNotFoundException();\n");
+ buf.append(" } catch (InvalidClassException e) {\n");
+ buf.append(" }\n");
+ buf.append(" return x;\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("C7.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ 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();
+
+ 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(" throw new FileNotFoundException();\n");
+ buf.append(" } catch (InvalidClassException e) {\n");
+ buf.append(" } catch (FileNotFoundException e) {\n");
+ buf.append(" }\n");
+ buf.append(" return x;\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ expected[1]= buf.toString();
+
+ 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(" throw new FileNotFoundException();\n");
+ buf.append(" } catch (InvalidClassException | FileNotFoundException e) {\n");
+ buf.append(" }\n");
+ buf.append(" return x;\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ expected[2]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+ }
+
+ public void testUncaughtExceptionInMethodReference1() throws Exception { // ExpressionMethodReference
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.FileNotFoundException;\n");
+ buf.append("import java.util.function.Consumer;\n");
+ buf.append("public class E1 {\n");
+ buf.append(" private static Transformer TRANSFORMER = new Transformer();\n");
+ buf.append(" Consumer<? super String> mapper = TRANSFORMER::transform;\n");
+ buf.append("}\n");
+ buf.append("\n");
+ buf.append("class Transformer {\n");
+ buf.append(" void transform(String number) throws FileNotFoundException {}\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E1.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 1);
+
+ String[] expected= new String[1];
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.FileNotFoundException;\n");
+ buf.append("import java.util.function.Consumer;\n");
+ buf.append("public class E1 {\n");
+ buf.append(" private static Transformer TRANSFORMER = new Transformer();\n");
+ buf.append(" Consumer<? super String> mapper = arg0 -> {\n");
+ buf.append(" try {\n");
+ buf.append(" TRANSFORMER.transform(arg0);\n");
+ buf.append(" } catch (FileNotFoundException e) {\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append("}\n");
+ buf.append("\n");
+ buf.append("class Transformer {\n");
+ buf.append(" void transform(String number) throws FileNotFoundException {}\n");
+ buf.append("}\n");
+ expected[0]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+ }
+
+ public void testUncaughtExceptionInMethodReference2() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.FileNotFoundException;\n");
+ buf.append("import java.util.Optional;\n");
+ buf.append("public class E2 {\n");
+ buf.append(" private static Transformer TRANSFORMER = new Transformer();\n");
+ buf.append(" public void test() {\n");
+ buf.append(" Optional.ofNullable(\"10\").map(TRANSFORMER::transform).ifPresent(System.out::print);\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("class Transformer {\n");
+ buf.append(" Long transform(String number) throws FileNotFoundException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E2.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 1);
+
+ String[] expected= new String[1];
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.FileNotFoundException;\n");
+ buf.append("import java.util.Optional;\n");
+ buf.append("public class E2 {\n");
+ buf.append(" private static Transformer TRANSFORMER = new Transformer();\n");
+ buf.append(" public void test() {\n");
+ buf.append(" Optional.ofNullable(\"10\").map(arg0 -> {\n");
+ buf.append(" try {\n");
+ buf.append(" return TRANSFORMER.transform(arg0);\n");
+ buf.append(" } catch (FileNotFoundException e) {\n");
+ buf.append(" }\n");
+ buf.append(" }).ifPresent(System.out::print);\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("class Transformer {\n");
+ buf.append(" Long transform(String number) throws FileNotFoundException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ expected[0]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+ }
+
+ public void testUncaughtExceptionInMethodReference3() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.FileNotFoundException;\n");
+ buf.append("import java.util.Optional;\n");
+ buf.append("import java.util.function.Consumer;\n");
+ buf.append("\n");
+ buf.append("public class E3 {\n");
+ buf.append(" private static Transformer TRANSFORMER = new Transformer();\n");
+ buf.append(" public void test() {\n");
+ buf.append(" Consumer<Object> s = (a) -> Optional.ofNullable(\"10\").map(TRANSFORMER::transform).ifPresent(System.out::print);\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("class Transformer {\n");
+ buf.append(" Long transform(String number) throws FileNotFoundException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E3.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 1);
+
+ String[] expected= new String[1];
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.FileNotFoundException;\n");
+ buf.append("import java.util.Optional;\n");
+ buf.append("import java.util.function.Consumer;\n");
+ buf.append("\n");
+ buf.append("public class E3 {\n");
+ buf.append(" private static Transformer TRANSFORMER = new Transformer();\n");
+ buf.append(" public void test() {\n");
+ buf.append(" Consumer<Object> s = (a) -> Optional.ofNullable(\"10\").map(arg0 -> {\n");
+ buf.append(" try {\n");
+ buf.append(" return TRANSFORMER.transform(arg0);\n");
+ buf.append(" } catch (FileNotFoundException e) {\n");
+ buf.append(" }\n");
+ buf.append(" }).ifPresent(System.out::print);\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("class Transformer {\n");
+ buf.append(" Long transform(String number) throws FileNotFoundException {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ expected[0]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+ }
+
+ public void testUncaughtExceptionInMethodReference4() throws Exception { // Generic lambda not allowed
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("public class E4 {\n");
+ buf.append(" {\n");
+ buf.append(" FI fi = this::test;\n");
+ buf.append(" }\n");
+ buf.append(" private void test() throws IOException {}\n");
+ buf.append(" interface FI {\n");
+ buf.append(" <T> void foo();\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E4.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 0);
+ assertProposalDoesNotExist(proposals, CorrectionMessages.LocalCorrectionsSubProcessor_surroundwith_trycatch_description);
+ }
+
+ public void testUncaughtExceptionInMethodReference5() throws Exception { // CreationReference
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.util.HashSet;\n");
+ buf.append("import java.util.function.Supplier;\n");
+ buf.append("public class E5 {\n");
+ buf.append(" void test() {\n");
+ buf.append(" Supplier<HashSet<String>> c = MyHashSet::new;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@SuppressWarnings(\"serial\")\n");
+ buf.append("class MyHashSet extends HashSet<String> {\n");
+ buf.append(" public MyHashSet() throws IOException {\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E5.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 1);
+
+ String[] expected= new String[1];
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.util.HashSet;\n");
+ buf.append("import java.util.function.Supplier;\n");
+ buf.append("public class E5 {\n");
+ buf.append(" void test() {\n");
+ buf.append(" Supplier<HashSet<String>> c = () -> {\n");
+ buf.append(" try {\n");
+ buf.append(" return new MyHashSet();\n");
+ buf.append(" } catch (IOException e) {\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@SuppressWarnings(\"serial\")\n");
+ buf.append("class MyHashSet extends HashSet<String> {\n");
+ buf.append(" public MyHashSet() throws IOException {\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ expected[0]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+ }
+
+ public void testUncaughtExceptionInMethodReference6() throws Exception { // TypeMethodReference
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.util.function.Function;\n");
+ buf.append("public class E6 {\n");
+ buf.append(" void test() {\n");
+ buf.append(" Function<Clazz<Integer>, String> c = Clazz<Integer>::searchForRefs1;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("class Clazz<E> {\n");
+ buf.append(" <F> String searchForRefs1() throws IOException {\n");
+ buf.append(" return \"\";\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E6.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 1);
+
+ String[] expected= new String[1];
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.util.function.Function;\n");
+ buf.append("public class E6 {\n");
+ buf.append(" void test() {\n");
+ buf.append(" Function<Clazz<Integer>, String> c = arg0 -> {\n");
+ buf.append(" try {\n");
+ buf.append(" return arg0.searchForRefs1();\n");
+ buf.append(" } catch (IOException e) {\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("class Clazz<E> {\n");
+ buf.append(" <F> String searchForRefs1() throws IOException {\n");
+ buf.append(" return \"\";\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ expected[0]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+ }
+
+ public void testUncaughtExceptionInMethodReference7() throws Exception { // SuperMethodReference
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.util.function.Supplier;\n");
+ buf.append("public class E7 extends Clazz<Object> {\n");
+ buf.append(" Supplier<String> c = super::searchForRefs1;\n");
+ buf.append("}\n");
+ buf.append("class Clazz<E> {\n");
+ buf.append(" <F> String searchForRefs1() throws IOException {\n");
+ buf.append(" return \"\";\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E7.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 1);
+
+ String[] expected= new String[1];
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("import java.io.IOException;\n");
+ buf.append("import java.util.function.Supplier;\n");
+ buf.append("public class E7 extends Clazz<Object> {\n");
+ buf.append(" Supplier<String> c = () -> {\n");
+ buf.append(" try {\n");
+ buf.append(" return super.searchForRefs1();\n");
+ buf.append(" } catch (IOException e) {\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append("}\n");
+ buf.append("class Clazz<E> {\n");
+ buf.append(" <F> String searchForRefs1() throws IOException {\n");
+ buf.append(" return \"\";\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ expected[0]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+ }
+
+
public void testOverrideDefaultMethod1() throws Exception {
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java
index c7c3a1f..05a73b2 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java
@@ -137,7 +137,8 @@
public static final int WARNING= 1 << 0;
public static final int ERROR= 1 << 1;
- public static final int PROBLEMS= WARNING | ERROR;
+ public static final int INFO= 1 << 2;
+ public static final int PROBLEMS= WARNING | ERROR | INFO;
private static final Message[] EMPTY_MESSAGES= new Message[0];
private static final IProblem[] EMPTY_PROBLEMS= new IProblem[0];
@@ -1200,6 +1201,8 @@
consider= problem.isWarning();
else if ((severity & ERROR) != 0)
consider= problem.isError();
+ else if ((severity & INFO) != 0)
+ consider= problem.isInfo();
if (consider) {
ASTNode temp= node;
int count= iterations;
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java
index c819a10..f9f19f8 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java
@@ -36,6 +36,7 @@
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ExpressionStatement;
+import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
@@ -89,7 +90,7 @@
@Override
public boolean visit(ClassInstanceCreation node) {
- if (isFunctionalAnonymous(node)) {
+ if (isFunctionalAnonymous(node, true)) {
fNodes.add(node);
}
return true;
@@ -519,7 +520,7 @@
if (!JavaModelUtil.is18OrHigher(root.getJavaElement().getJavaProject()))
return null;
- if (!LambdaExpressionsFix.isFunctionalAnonymous(cic))
+ if (!LambdaExpressionsFix.isFunctionalAnonymous(cic, false))
return null;
CreateLambdaOperation op= new CreateLambdaOperation(Collections.singletonList(cic));
@@ -567,7 +568,7 @@
super(name, compilationUnit, fixRewriteOperations);
}
- static boolean isFunctionalAnonymous(ClassInstanceCreation node) {
+ static boolean isFunctionalAnonymous(ClassInstanceCreation node, boolean isCleanUp) {
ITypeBinding typeBinding= node.resolveTypeBinding();
if (typeBinding == null)
return false;
@@ -598,6 +599,20 @@
if (methodBinding.isGenericMethod())
return false;
+ // Skip the Clean up if there are annotations other than @Override and @Deprecated
+ if (isCleanUp) {
+ IAnnotationBinding[] declarationAnnotations= methodBinding.getAnnotations();
+ for (IAnnotationBinding declarationAnnotation : declarationAnnotations) {
+ ITypeBinding annotationType= declarationAnnotation.getAnnotationType();
+ if (annotationType != null) {
+ String qualifiedName= annotationType.getQualifiedName();
+ if (!"java.lang.Override".equals(qualifiedName) && !"java.lang.Deprecated".equals(qualifiedName)) { //$NON-NLS-1$ //$NON-NLS-2$
+ return false;
+ }
+ }
+ }
+ }
+
// lambda cannot refer to 'this'/'super' literals
if (SuperThisReferenceFinder.hasReference(methodDecl))
return false;
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/ExceptionAnalyzer.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/ExceptionAnalyzer.java
index cfcf2f0..a9d127a 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/ExceptionAnalyzer.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/ExceptionAnalyzer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -18,27 +18,34 @@
import org.eclipse.core.runtime.Assert;
import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.ConstructorInvocation;
+import org.eclipse.jdt.core.dom.CreationReference;
+import org.eclipse.jdt.core.dom.ExpressionMethodReference;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.LambdaExpression;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.MethodReference;
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
+import org.eclipse.jdt.core.dom.SuperMethodReference;
import org.eclipse.jdt.core.dom.ThrowStatement;
import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.core.dom.TypeMethodReference;
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
import org.eclipse.jdt.internal.corext.dom.Bindings;
import org.eclipse.jdt.internal.corext.dom.Selection;
import org.eclipse.jdt.internal.corext.refactoring.util.AbstractExceptionAnalyzer;
+import org.eclipse.jdt.internal.ui.text.correction.QuickAssistProcessor;
+
public class ExceptionAnalyzer extends AbstractExceptionAnalyzer {
private Selection fSelection;
+ private static ASTNode fEnclosingNode;
private static class ExceptionComparator implements Comparator<ITypeBinding> {
@Override
@@ -61,13 +68,14 @@
}
}
- private ExceptionAnalyzer(Selection selection) {
+ private ExceptionAnalyzer(ASTNode enclosingNode, Selection selection) {
Assert.isNotNull(selection);
+ fEnclosingNode= enclosingNode;
fSelection= selection;
}
- public static ITypeBinding[] perform(BodyDeclaration enclosingNode, Selection selection) {
- ExceptionAnalyzer analyzer= new ExceptionAnalyzer(selection);
+ public static ITypeBinding[] perform(ASTNode enclosingNode, Selection selection) {
+ ExceptionAnalyzer analyzer= new ExceptionAnalyzer(enclosingNode, selection);
enclosingNode.accept(analyzer);
List<ITypeBinding> exceptions= analyzer.getCurrentExceptions();
if (enclosingNode.getNodeType() == ASTNode.METHOD_DECLARATION) {
@@ -75,10 +83,21 @@
for (Iterator<Type> thrown= thrownExceptions.iterator(); thrown.hasNext();) {
ITypeBinding thrownException= thrown.next().resolveBinding();
if (thrownException != null) {
- for (Iterator<ITypeBinding> excep= exceptions.iterator(); excep.hasNext();) {
- ITypeBinding exception= excep.next();
- if (exception.isAssignmentCompatible(thrownException))
- excep.remove();
+ updateExceptionsList(exceptions, thrownException);
+ }
+ }
+ } else {
+ ITypeBinding typeBinding= null;
+ if (enclosingNode.getLocationInParent() == LambdaExpression.BODY_PROPERTY) {
+ typeBinding= ((LambdaExpression) enclosingNode.getParent()).resolveTypeBinding();
+ } else if (enclosingNode instanceof MethodReference) {
+ typeBinding= ((MethodReference) enclosingNode).resolveTypeBinding();
+ }
+ if (typeBinding != null) {
+ IMethodBinding methodBinding= typeBinding.getFunctionalInterfaceMethod();
+ if (methodBinding != null) {
+ for (ITypeBinding thrownException : methodBinding.getExceptionTypes()) {
+ updateExceptionsList(exceptions, thrownException);
}
}
}
@@ -86,14 +105,33 @@
Collections.sort(exceptions, new ExceptionComparator());
return exceptions.toArray(new ITypeBinding[exceptions.size()]);
}
-
+
+ private static void updateExceptionsList(List<ITypeBinding> exceptions, ITypeBinding thrownException) {
+ for (Iterator<ITypeBinding> excep= exceptions.iterator(); excep.hasNext();) {
+ ITypeBinding exception= excep.next();
+ if (exception.isAssignmentCompatible(thrownException))
+ excep.remove();
+ }
+ }
+
@Override
- public boolean visit(LambdaExpression node) {
- /*
- * FIXME: Remove this method. It's just a workaround for bug 433426.
- * ExceptionAnalyzer forces clients to on the wrong enclosing node (BodyDeclaration instead of LambdaExpression's body).
- */
- return true;
+ public boolean visit(ExpressionMethodReference node) {
+ return handleMethodReference(node);
+ }
+
+ @Override
+ public boolean visit(TypeMethodReference node) {
+ return handleMethodReference(node);
+ }
+
+ @Override
+ public boolean visit(SuperMethodReference node) {
+ return handleMethodReference(node);
+ }
+
+ @Override
+ public boolean visit(CreationReference node) {
+ return handleMethodReference(node);
}
@Override
@@ -148,6 +186,21 @@
return super.visit(node);
}
+ private boolean handleMethodReference(MethodReference node) {
+ if (!isSelected(node))
+ return false;
+ if (!fEnclosingNode.equals(node))
+ return false;
+ IMethodBinding referredMethodBinding= node.resolveMethodBinding();
+ if (referredMethodBinding == null)
+ return false;
+ IMethodBinding functionalMethod= QuickAssistProcessor.getFunctionalMethodForMethodReference(node);
+ if (functionalMethod == null || functionalMethod.isGenericMethod()) { // generic lambda expressions are not allowed
+ return false;
+ }
+ return handleExceptions(referredMethodBinding, node);
+ }
+
private boolean handleExceptions(IMethodBinding binding, ASTNode node) {
if (binding == null)
return true;
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/LocalDeclarationAnalyzer.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/LocalDeclarationAnalyzer.java
index 2f7b3ad..e0d7171 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/LocalDeclarationAnalyzer.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/LocalDeclarationAnalyzer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,7 +15,6 @@
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
-import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.VariableDeclaration;
@@ -29,7 +28,7 @@
private Selection fSelection;
private List<VariableDeclaration> fAffectedLocals;
- public static VariableDeclaration[] perform(BodyDeclaration parent, Selection selection) {
+ public static VariableDeclaration[] perform(ASTNode parent, Selection selection) {
LocalDeclarationAnalyzer analyzer= new LocalDeclarationAnalyzer(selection);
parent.accept(analyzer);
return analyzer.fAffectedLocals.toArray(new VariableDeclaration[analyzer.fAffectedLocals.size()]);
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithAnalyzer.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithAnalyzer.java
index 625788d..d28dc14 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithAnalyzer.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithAnalyzer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -23,8 +23,10 @@
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ExpressionStatement;
import org.eclipse.jdt.core.dom.Initializer;
+import org.eclipse.jdt.core.dom.LambdaExpression;
import org.eclipse.jdt.core.dom.Message;
import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodReference;
import org.eclipse.jdt.core.dom.Statement;
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
import org.eclipse.jdt.core.dom.VariableDeclaration;
@@ -35,17 +37,21 @@
import org.eclipse.jdt.internal.corext.refactoring.base.JavaStatusContext;
import org.eclipse.jdt.internal.corext.refactoring.util.CodeAnalyzer;
+import org.eclipse.jdt.internal.ui.text.correction.ASTResolving;
+
public class SurroundWithAnalyzer extends CodeAnalyzer {
private VariableDeclaration[] fLocals;
+ private boolean fSurroundWithTryCatch;
- public SurroundWithAnalyzer(ICompilationUnit cunit, Selection selection) throws CoreException {
+ public SurroundWithAnalyzer(ICompilationUnit cunit, Selection selection, boolean surroundWithTryCatch) throws CoreException {
super(cunit, selection, false);
+ fSurroundWithTryCatch= surroundWithTryCatch;
}
- public Statement[] getSelectedStatements() {
+ public ASTNode[] getValidSelectedNodes() {
if (hasSelectedNodes()) {
- return internalGetSelectedNodes().toArray(new Statement[internalGetSelectedNodes().size()]);
+ return internalGetSelectedNodes().toArray(new ASTNode[internalGetSelectedNodes().size()]);
} else {
return new Statement[0];
}
@@ -70,7 +76,7 @@
@Override
public void endVisit(CompilationUnit node) {
postProcessSelectedNodes(internalGetSelectedNodes());
- BodyDeclaration enclosingNode= null;
+ ASTNode enclosingNode= null;
superCall: {
if (getStatus().hasFatalError())
break superCall;
@@ -88,12 +94,16 @@
invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotCover);
break superCall;
}
- enclosingNode= (BodyDeclaration)ASTNodes.getParent(getFirstSelectedNode(), BodyDeclaration.class);
- if (!(enclosingNode instanceof MethodDeclaration) && !(enclosingNode instanceof Initializer)) {
+ enclosingNode= getEnclosingNode(getFirstSelectedNode());
+ boolean isValidEnclosingNode= enclosingNode instanceof MethodDeclaration || enclosingNode instanceof Initializer;
+ if (fSurroundWithTryCatch) {
+ isValidEnclosingNode= isValidEnclosingNode || enclosingNode instanceof MethodReference || enclosingNode.getLocationInParent() == LambdaExpression.BODY_PROPERTY;
+ }
+ if (!isValidEnclosingNode) {
invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotContain);
break superCall;
}
- if (!onlyStatements()) {
+ if (!validSelectedNodes()) {
invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_onlyStatements);
}
fLocals= LocalDeclarationAnalyzer.perform(enclosingNode, getSelection());
@@ -129,13 +139,33 @@
}
}
- private boolean onlyStatements() {
+ private boolean validSelectedNodes() {
ASTNode[] nodes= getSelectedNodes();
for (int i= 0; i < nodes.length; i++) {
- if (!(nodes[i] instanceof Statement))
+ ASTNode node= nodes[i];
+ boolean isValidNode= node instanceof Statement;
+ if (fSurroundWithTryCatch) { // allow method reference and lambda's expression body also
+ isValidNode= isValidNode || node instanceof MethodReference || node.getLocationInParent() == LambdaExpression.BODY_PROPERTY;
+ }
+ if (!isValidNode)
return false;
}
return true;
}
+ public static ASTNode getEnclosingNode(ASTNode firstSelectedNode) {
+ ASTNode enclosingNode;
+ if (firstSelectedNode instanceof MethodReference) {
+ enclosingNode= firstSelectedNode;
+ } else {
+ enclosingNode= ASTResolving.findEnclosingLambdaExpression(firstSelectedNode);
+ if (enclosingNode != null) {
+ enclosingNode= ((LambdaExpression) enclosingNode).getBody();
+ } else {
+ enclosingNode= ASTNodes.getParent(firstSelectedNode, BodyDeclaration.class);
+ }
+ }
+ return enclosingNode;
+ }
+
}
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchAnalyzer.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchAnalyzer.java
index 97d8fa8..9ec6240 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchAnalyzer.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchAnalyzer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,18 +13,19 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.dom.BodyDeclaration;
+import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.MethodReference;
-import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.dom.Selection;
+import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
public class SurroundWithTryCatchAnalyzer extends SurroundWithAnalyzer {
private ITypeBinding[] fExceptions;
public SurroundWithTryCatchAnalyzer(ICompilationUnit unit, Selection selection) throws CoreException {
- super(unit, selection);
+ super(unit, selection, true);
}
public ITypeBinding[] getExceptions() {
@@ -33,15 +34,19 @@
@Override
public void endVisit(CompilationUnit node) {
- BodyDeclaration enclosingNode= null;
+ ASTNode enclosingNode= null;
if (!getStatus().hasFatalError() && hasSelectedNodes())
- enclosingNode= (BodyDeclaration)ASTNodes.getParent(getFirstSelectedNode(), BodyDeclaration.class);
+ enclosingNode= getEnclosingNode(getFirstSelectedNode());
super.endVisit(node);
if (enclosingNode != null && !getStatus().hasFatalError()) {
fExceptions= ExceptionAnalyzer.perform(enclosingNode, getSelection());
if (fExceptions == null || fExceptions.length == 0) {
- fExceptions= new ITypeBinding[] {node.getAST().resolveWellKnownType("java.lang.Exception")}; //$NON-NLS-1$
+ if (enclosingNode instanceof MethodReference) {
+ invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotContain);
+ } else {
+ fExceptions= new ITypeBinding[] { node.getAST().resolveWellKnownType("java.lang.Exception") }; //$NON-NLS-1$
+ }
}
}
}
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java
index 576b210..d38a917 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,6 +15,7 @@
import java.util.Iterator;
import java.util.List;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -41,7 +42,10 @@
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ExpressionStatement;
import org.eclipse.jdt.core.dom.IExtendedModifier;
+import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.LambdaExpression;
+import org.eclipse.jdt.core.dom.MethodReference;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.Statement;
@@ -71,6 +75,8 @@
import org.eclipse.jdt.internal.corext.util.Strings;
import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider;
+import org.eclipse.jdt.internal.ui.text.correction.ASTResolving;
+import org.eclipse.jdt.internal.ui.text.correction.QuickAssistProcessor;
/**
* Surround a set of statements with a try/catch block or a try/multi-catch block.
@@ -359,13 +365,37 @@
replacementNode= fRewriter.createGroupNode(result.toArray(new ASTNode[result.size()]));
}
if (fSelectedNodes.length == 1) {
+ ASTNode selectedNode= fSelectedNodes[0];
+
+ if (selectedNode instanceof MethodReference) {
+ MethodReference methodReference= (MethodReference) selectedNode;
+ IMethodBinding functionalMethod= QuickAssistProcessor.getFunctionalMethodForMethodReference(methodReference);
+ // functionalMethod is non-null and non-generic. See ExceptionAnalyzer.handleMethodReference(MethodReference node).
+ Assert.isTrue(functionalMethod != null && !functionalMethod.isGenericMethod());
+ LambdaExpression lambda= QuickAssistProcessor.convertMethodRefernceToLambda(methodReference, functionalMethod, fRootNode, fRewriter, null, true);
+ ASTNode statementInBlock= (ASTNode) ((Block) lambda.getBody()).statements().get(0);
+ fRewriter.replace(statementInBlock, replacementNode, null);
+ statements.insertLast(statementInBlock, null);
+ return;
+ }
+
+ LambdaExpression enclosingLambda= ASTResolving.findEnclosingLambdaExpression(selectedNode);
+ if (enclosingLambda != null && selectedNode.getLocationInParent() == LambdaExpression.BODY_PROPERTY && enclosingLambda.resolveMethodBinding() != null) {
+ QuickAssistProcessor.changeLambdaBodyToBlock(enclosingLambda, getAST(), fRewriter);
+ Block blockBody= (Block) fRewriter.get(enclosingLambda, LambdaExpression.BODY_PROPERTY);
+ ASTNode statementInBlock= (ASTNode) blockBody.statements().get(0);
+ fRewriter.replace(statementInBlock, replacementNode, null);
+ statements.insertLast(statementInBlock, null);
+ return;
+ }
+
if (expressionStatement != null) {
statements.insertLast(expressionStatement, null);
} else {
if (!selectedNodeRemoved)
- statements.insertLast(fRewriter.createMoveTarget(fSelectedNodes[0]), null);
+ statements.insertLast(fRewriter.createMoveTarget(selectedNode), null);
}
- fRewriter.replace(fSelectedNodes[0], replacementNode, null);
+ fRewriter.replace(selectedNode, replacementNode, null);
} else {
ListRewrite source= fRewriter.getListRewrite(
fSelectedNodes[0].getParent(),
@@ -377,7 +407,7 @@
}
}
- private List<ITypeBinding> filterSubtypeExceptions(ITypeBinding[] exceptions) {
+ public static List<ITypeBinding> filterSubtypeExceptions(ITypeBinding[] exceptions) {
List<ITypeBinding> filteredExceptions= new ArrayList<>();
filteredExceptions.addAll(Arrays.asList(exceptions));
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/RefactoringASTParser.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/RefactoringASTParser.java
index 388c683..3463d59 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/RefactoringASTParser.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/RefactoringASTParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -137,7 +137,7 @@
/**
* Returns the compiler options used for creating the refactoring AST.
* <p>
- * Turns all errors and warnings into ignore and disables task tags. The customizable set of
+ * Turns all errors, warnings and infos into ignore and disables task tags. The customizable set of
* compiler options only contains additional Eclipse options. The standard JDK compiler options
* can't be changed anyway.
*
@@ -150,7 +150,7 @@
for (Iterator<String> iter= options.keySet().iterator(); iter.hasNext();) {
String key= iter.next();
String value= options.get(key);
- if (JavaCore.ERROR.equals(value) || JavaCore.WARNING.equals(value)) {
+ if (JavaCore.ERROR.equals(value) || JavaCore.WARNING.equals(value) || JavaCore.INFO.equals(value)) {
// System.out.println("Ignoring - " + key);
options.put(key, JavaCore.IGNORE);
}
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/SelectionAwareSourceRangeComputer.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/SelectionAwareSourceRangeComputer.java
index 11d7338..053619c 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/SelectionAwareSourceRangeComputer.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/SelectionAwareSourceRangeComputer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,18 +11,23 @@
package org.eclipse.jdt.internal.corext.refactoring.util;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IBuffer;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.compiler.IScanner;
import org.eclipse.jdt.core.compiler.ITerminalSymbols;
import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.rewrite.TargetSourceRangeComputer;
import org.eclipse.jdt.core.formatter.IndentManipulation;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.dom.TokenScanner;
public class SelectionAwareSourceRangeComputer extends TargetSourceRangeComputer {
@@ -66,7 +71,10 @@
int last= fSelectedNodes.length - 1;
fRanges.put(fSelectedNodes[last], super.computeSourceRange(fSelectedNodes[last]));
- IScanner scanner= ToolFactory.createScanner(true, false, false, false);
+ IJavaProject javaProject= ((CompilationUnit) fSelectedNodes[0].getRoot()).getTypeRoot().getJavaProject();
+ String sourceLevel= javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
+ String complianceLevel= javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ IScanner scanner= ToolFactory.createScanner(true, false, false, sourceLevel, complianceLevel);
char[] source= fDocumentPortionToScan.toCharArray();
scanner.setSource(source);
fDocumentPortionToScan= null; // initializeRanges() is only called once
@@ -102,5 +110,23 @@
int newEnd= Math.max(fSelectionStart + pos, currentNode.getStartPosition() + currentNode.getLength());
range= fRanges.get(currentNode);
fRanges.put(currentNode, new SourceRange(range.getStartPosition(), newEnd - range.getStartPosition()));
+
+ // The extended source range of the last child node can end after the selection.
+ // We have to ensure that the source range of such child nodes is also capped by the selection range.
+ // Example: (/*]*/TRANSFORMER::transform/*[*/)
+ // Selection is between /*]*/ and /*[*/, but the extended range of the "transform" node actually includes /*[*/ as well.
+ while (true) {
+ List<ASTNode> children= ASTNodes.getChildren(currentNode);
+ if (!children.isEmpty()) {
+ ASTNode lastChild= children.get(children.size() - 1);
+ SourceRange extRange= super.computeSourceRange(lastChild);
+ if (extRange.getStartPosition() + extRange.getLength() > newEnd) {
+ fRanges.put(lastChild, new SourceRange(extRange.getStartPosition(), newEnd - extRange.getStartPosition()));
+ currentNode= lastChild;
+ continue;
+ }
+ }
+ break;
+ }
}
}
diff --git a/org.eclipse.jdt.ui/icons/full/obj16/quickfix_info_obj.png b/org.eclipse.jdt.ui/icons/full/obj16/quickfix_info_obj.png
new file mode 100644
index 0000000..8c82075
--- /dev/null
+++ b/org.eclipse.jdt.ui/icons/full/obj16/quickfix_info_obj.png
Binary files differ
diff --git a/org.eclipse.jdt.ui/plugin.xml b/org.eclipse.jdt.ui/plugin.xml
index e266d1a..f4b51ed 100644
--- a/org.eclipse.jdt.ui/plugin.xml
+++ b/org.eclipse.jdt.ui/plugin.xml
@@ -1065,8 +1065,23 @@
<colorDefinition
label="%DeclarationViewBackgroundColor.label"
categoryId="org.eclipse.jdt.ui.presentation"
- value="COLOR_INFO_BACKGROUND"
id="org.eclipse.jdt.ui.DeclarationView.backgroundColor">
+ <colorFactory
+ plugin="org.eclipse.ui"
+ class="org.eclipse.ui.internal.themes.RGBVisibleContrastColorFactory">
+ <parameter
+ name="foreground"
+ value="0,0,0">
+ </parameter>
+ <parameter
+ name="background"
+ value="COLOR_INFO_BACKGROUND">
+ </parameter>
+ <parameter
+ name="alternativeBackground"
+ value="COLOR_LIST_BACKGROUND">
+ </parameter>
+ </colorFactory>
<description>
%DeclarationViewBackgroundColor.description
</description>
diff --git a/org.eclipse.jdt.ui/templates/default-templates.properties b/org.eclipse.jdt.ui/templates/default-templates.properties
index 175a807..17ddf98 100644
--- a/org.eclipse.jdt.ui/templates/default-templates.properties
+++ b/org.eclipse.jdt.ui/templates/default-templates.properties
@@ -9,6 +9,7 @@
# IBM Corporation - initial API and implementation
# Benjamin Muskalla <bmuskalla@eclipsesource.com> - [templates] new SWT templates - ToolBar and ToolItem - https://bugs.eclipse.org/bugs/show_bug.cgi?id=264052
# Robert Roth <robert.roth.off@gmail.com> - [templates] 2 new code templates: finally & lock - https://bugs.eclipse.org/184222
+# Lars Vogel <Lars.Vogel@vogella.com> - [templates] Provide templates that check for 'null' - https://bugs.eclipse.org/131445
###############################################################################
Templates.for_array=iterate over array
@@ -23,6 +24,8 @@
Templates.ifelse=if else statement
Templates.elseif=else if block
Templates.else=else block
+Templates.ifnull=if statement checking for null
+Templates.ifnotnull=if statement checking for not null
Templates.try=try catch block
Templates.tryfinally=try finally block
Templates.catch=catch block
diff --git a/org.eclipse.jdt.ui/templates/default-templates.xml b/org.eclipse.jdt.ui/templates/default-templates.xml
index cd680cb..7361573 100644
--- a/org.eclipse.jdt.ui/templates/default-templates.xml
+++ b/org.eclipse.jdt.ui/templates/default-templates.xml
@@ -11,6 +11,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Robert Roth <robert.roth.off@gmail.com> - [templates] 2 new code templates: finally & lock - https://bugs.eclipse.org/184222
+ * Lars Vogel <Lars.Vogel@vogella.com> - [templates] Provide templates that check for 'null' - https://bugs.eclipse.org/131445
*******************************************************************************/
-->
@@ -75,6 +76,14 @@
${cursor}
}</template>
+<template name="ifNull" description="%Templates.ifnull" id="org.eclipse.jdt.ui.templates.ifnull" context="java-statements" enabled="true" autoinsert="false">if (${name:var} == null) {
+ ${cursor}
+}</template>
+
+<template name="ifNotNull" description="%Templates.ifnotnull" id="org.eclipse.jdt.ui.templates.ifnotnull" context="java-statements" enabled="true" autoinsert="false">if (${name:var} != null) {
+ ${cursor}
+}</template>
+
<template name="try_catch" description="%Templates.try" id="org.eclipse.jdt.ui.templates.try" context="java-statements" enabled="true" autoinsert="false">try {
${line_selection}${cursor}
} catch (${Exception} ${exception_variable_name}) {
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java
index f3e4c8b..2e69046 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java
@@ -155,6 +155,7 @@
public static final String IMG_OBJS_QUICK_FIX= NAME_PREFIX + "quickfix_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_FIXABLE_PROBLEM= NAME_PREFIX + "quickfix_warning_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_FIXABLE_ERROR= NAME_PREFIX + "quickfix_error_obj.gif"; //$NON-NLS-1$
+ public static final String IMG_OBJS_FIXABLE_INFO= NAME_PREFIX + "quickfix_info_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_ACCESSRULES_ATTRIB= NAME_PREFIX + "access_restriction_attrib.gif"; //$NON-NLS-1$
@@ -286,6 +287,7 @@
public static final ImageDescriptor DESC_OBJS_QUICK_FIX= createManagedFromKey(T_OBJ, IMG_OBJS_QUICK_FIX);
public static final ImageDescriptor DESC_OBJS_FIXABLE_PROBLEM= createManagedFromKey(T_OBJ, IMG_OBJS_FIXABLE_PROBLEM);
public static final ImageDescriptor DESC_OBJS_FIXABLE_ERROR= createManagedFromKey(T_OBJ, IMG_OBJS_FIXABLE_ERROR);
+ public static final ImageDescriptor DESC_OBJS_FIXABLE_INFO= createManagedFromKey(T_OBJ, IMG_OBJS_FIXABLE_INFO);
public static final ImageDescriptor DESC_OBJS_DEFAULT_CHANGE= createUnManaged(T_OBJ, "change.png"); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/CompilationUnitDocumentProvider.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/CompilationUnitDocumentProvider.java
index 03036fb..ca3efaa 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/CompilationUnitDocumentProvider.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/CompilationUnitDocumentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -181,8 +181,9 @@
return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
}
- private static Image fgQuickFixImage;
+ private static Image fgQuickFixWarningImage;
private static Image fgQuickFixErrorImage;
+ private static Image fgQuickFixInfoImage;
private static Image fgTaskImage;
private static Image fgInfoImage;
private static Image fgWarningImage;
@@ -239,8 +240,10 @@
if (isQuickFixable()) {
if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(getType()))
fImage= fgQuickFixErrorImage;
+ else if (JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(getType()))
+ fImage= fgQuickFixWarningImage;
else
- fImage= fgQuickFixImage;
+ fImage= fgQuickFixInfoImage;
} else {
String type= getType();
if (JavaMarkerAnnotation.TASK_ANNOTATION_TYPE.equals(type))
@@ -260,8 +263,9 @@
if (fgImagesInitialized)
return;
- fgQuickFixImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
+ fgQuickFixWarningImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
fgQuickFixErrorImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR);
+ fgQuickFixInfoImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_INFO);
ISharedImages sharedImages= PlatformUI.getWorkbench().getSharedImages();
fgTaskImage= sharedImages.getImage(SharedImages.IMG_OBJS_TASK_TSK);
@@ -318,6 +322,7 @@
String type= getType();
return JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(type) ||
JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(type) ||
+ JavaMarkerAnnotation.INFO_ANNOTATION_TYPE.equals(type) ||
SPELLING_ANNOTATION_TYPE.equals(type);
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaAnnotationImageProvider.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaAnnotationImageProvider.java
index ed95211..eefcfe2 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaAnnotationImageProvider.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaAnnotationImageProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -33,12 +33,14 @@
private final static int NO_IMAGE= 0;
private final static int GRAY_IMAGE= 1;
private final static int OVERLAY_IMAGE= 2;
- private final static int QUICKFIX_IMAGE= 3;
+ private final static int QUICKFIX_WARNING_IMAGE= 3;
private final static int QUICKFIX_ERROR_IMAGE= 4;
+ private final static int QUICKFIX_INFO_IMAGE= 5;
- private static Image fgQuickFixImage;
+ private static Image fgQuickFixWarningImage;
private static Image fgQuickFixErrorImage;
+ private static Image fgQuickFixInfoImage;
private boolean fShowQuickFixIcon;
private int fCachedImageType;
private Image fCachedImage;
@@ -84,10 +86,10 @@
return fShowQuickFixIcon && annotation.isProblem() && JavaCorrectionProcessor.hasCorrections((Annotation) annotation);
}
- private Image getQuickFixImage() {
- if (fgQuickFixImage == null)
- fgQuickFixImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
- return fgQuickFixImage;
+ private Image getQuickFixWarningImage() {
+ if (fgQuickFixWarningImage == null)
+ fgQuickFixWarningImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
+ return fgQuickFixWarningImage;
}
private Image getQuickFixErrorImage() {
@@ -96,13 +98,26 @@
return fgQuickFixErrorImage;
}
+ private Image getQuickFixInfoImage() {
+ if (fgQuickFixInfoImage == null)
+ fgQuickFixInfoImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_INFO);
+ return fgQuickFixInfoImage;
+ }
+
private int getImageType(IJavaAnnotation annotation) {
int imageType= NO_IMAGE;
if (annotation.hasOverlay())
imageType= OVERLAY_IMAGE;
else if (!annotation.isMarkedDeleted()) {
- if (showQuickFix(annotation))
- imageType= JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(annotation.getType()) ? QUICKFIX_ERROR_IMAGE : QUICKFIX_IMAGE;
+ if (showQuickFix(annotation)) {
+ if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(annotation.getType())) {
+ imageType= QUICKFIX_ERROR_IMAGE;
+ } else if (JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(annotation.getType())) {
+ imageType= QUICKFIX_WARNING_IMAGE;
+ } else {
+ imageType= QUICKFIX_INFO_IMAGE;
+ }
+ }
} else {
imageType= GRAY_IMAGE;
}
@@ -110,7 +125,7 @@
}
private Image getImage(IJavaAnnotation annotation, int imageType) {
- if ((imageType == QUICKFIX_IMAGE || imageType == QUICKFIX_ERROR_IMAGE) && fCachedImageType == imageType)
+ if ((imageType == QUICKFIX_WARNING_IMAGE || imageType == QUICKFIX_ERROR_IMAGE || imageType == QUICKFIX_INFO_IMAGE) && fCachedImageType == imageType)
return fCachedImage;
Image image= null;
@@ -120,8 +135,8 @@
image= getManagedImage((Annotation) overlay);
fCachedImageType= -1;
break;
- case QUICKFIX_IMAGE:
- image= getQuickFixImage();
+ case QUICKFIX_WARNING_IMAGE:
+ image= getQuickFixWarningImage();
fCachedImageType= imageType;
fCachedImage= image;
break;
@@ -130,6 +145,11 @@
fCachedImageType= imageType;
fCachedImage= image;
break;
+ case QUICKFIX_INFO_IMAGE:
+ image= getQuickFixInfoImage();
+ fCachedImageType= imageType;
+ fCachedImage= image;
+ break;
case GRAY_IMAGE: {
String annotationType= annotation.getType();
if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(annotationType)) {
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaMarkerAnnotation.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaMarkerAnnotation.java
index c02ffd3..aadba35 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaMarkerAnnotation.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaMarkerAnnotation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -102,7 +102,7 @@
@Override
public boolean isProblem() {
String type= getType();
- return WARNING_ANNOTATION_TYPE.equals(type) || ERROR_ANNOTATION_TYPE.equals(type);
+ return WARNING_ANNOTATION_TYPE.equals(type) || ERROR_ANNOTATION_TYPE.equals(type) || INFO_ANNOTATION_TYPE.equals(type);
}
/**
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java
index 6a034fa..f015c26 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java
@@ -130,6 +130,7 @@
private static final String ERROR= JavaCore.ERROR;
private static final String WARNING= JavaCore.WARNING;
+ private static final String INFO= JavaCore.INFO;
private static final String IGNORE= JavaCore.IGNORE;
private static final String ENABLED= JavaCore.ENABLED;
@@ -382,19 +383,20 @@
label= PreferencesMessages.ComplianceConfigurationBlock_source_compatibility_label;
addComboBox(group, label, PREF_SOURCE_COMPATIBILITY, sourceVersions, sourceLabels, indent);
- String[] errorWarningIgnore= new String[] { ERROR, WARNING, IGNORE };
+ String[] errorWarningInfoIgnore= new String[] { ERROR, WARNING, INFO, IGNORE };
- String[] errorWarningIgnoreLabels= new String[] {
+ String[] errorWarningInfoIgnoreLabels= new String[] {
PreferencesMessages.ComplianceConfigurationBlock_error,
PreferencesMessages.ComplianceConfigurationBlock_warning,
+ PreferencesMessages.ComplianceConfigurationBlock_info,
PreferencesMessages.ComplianceConfigurationBlock_ignore
};
label= PreferencesMessages.ComplianceConfigurationBlock_pb_assert_as_identifier_label;
- addComboBox(group, label, PREF_PB_ASSERT_AS_IDENTIFIER, errorWarningIgnore, errorWarningIgnoreLabels, indent);
+ addComboBox(group, label, PREF_PB_ASSERT_AS_IDENTIFIER, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, indent);
label= PreferencesMessages.ComplianceConfigurationBlock_pb_enum_as_identifier_label;
- addComboBox(group, label, PREF_PB_ENUM_AS_IDENTIFIER, errorWarningIgnore, errorWarningIgnoreLabels, indent);
+ addComboBox(group, label, PREF_PB_ENUM_AS_IDENTIFIER, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, indent);
allChildren= group.getChildren();
fComplianceChildControls.addAll(Arrays.asList(allChildren));
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaBuildConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaBuildConfigurationBlock.java
index 9b4ec87..88e6f14 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaBuildConfigurationBlock.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaBuildConfigurationBlock.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -68,6 +68,7 @@
// values
private static final String ERROR= JavaCore.ERROR;
private static final String WARNING= JavaCore.WARNING;
+ private static final String INFO= JavaCore.INFO;
private static final String IGNORE= JavaCore.IGNORE;
private static final String ABORT= JavaCore.ABORT;
@@ -136,10 +137,11 @@
PreferencesMessages.JavaBuildConfigurationBlock_warning
};
- String[] errorWarningIgnore= new String[] { ERROR, WARNING, IGNORE };
- String[] errorWarningIgnoreLabels= new String[] {
+ String[] errorWarningInfoIgnore= new String[] { ERROR, WARNING, INFO, IGNORE };
+ String[] errorWarningInfoIgnoreLabels= new String[] {
PreferencesMessages.JavaBuildConfigurationBlock_error,
PreferencesMessages.JavaBuildConfigurationBlock_warning,
+ PreferencesMessages.JavaBuildConfigurationBlock_info,
PreferencesMessages.JavaBuildConfigurationBlock_ignore
};
@@ -192,13 +194,13 @@
addComboBox(othersComposite, label, PREF_PB_CIRCULAR_BUILDPATH, errorWarning, errorWarningLabels, 0);
label= PreferencesMessages.JavaBuildConfigurationBlock_pb_check_prereq_binary_level_label;
- addComboBox(othersComposite, label, PREF_PB_INCOMPATIBLE_JDK_LEVEL, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+ addComboBox(othersComposite, label, PREF_PB_INCOMPATIBLE_JDK_LEVEL, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, 0);
label = PreferencesMessages.JavaBuildConfigurationBlock_pb_output_overlapping_with_source_label;
- addComboBox(othersComposite, label, PREF_PB_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+ addComboBox(othersComposite, label, PREF_PB_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, 0);
label= PreferencesMessages.JavaBuildConfigurationBlock_pb_strictly_compatible_jre_not_available_label;
- addComboBox(othersComposite, label, PREF_PB_STRICTLY_COMPATIBLE_JRE_NOT_AVAILABLE, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+ addComboBox(othersComposite, label, PREF_PB_STRICTLY_COMPATIBLE_JRE_NOT_AVAILABLE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, 0);
label= PreferencesMessages.JavaBuildConfigurationBlock_section_output_folder;
excomposite= createStyleSection(composite, label, nColumns);
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavadocProblemsConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavadocProblemsConfigurationBlock.java
index e0e61c1..d0a9847 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavadocProblemsConfigurationBlock.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavadocProblemsConfigurationBlock.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -61,6 +61,7 @@
// values
private static final String ERROR= JavaCore.ERROR;
private static final String WARNING= JavaCore.WARNING;
+ private static final String INFO= JavaCore.INFO;
private static final String IGNORE= JavaCore.IGNORE;
private static final String ENABLED= JavaCore.ENABLED;
@@ -116,11 +117,12 @@
}
private Composite createJavadocTabContent(Composite folder) {
- String[] errorWarningIgnore= new String[] { ERROR, WARNING, IGNORE };
+ String[] errorWarningInfoIgnore= new String[] { ERROR, WARNING, INFO, IGNORE };
- String[] errorWarningIgnoreLabels= new String[] {
+ String[] errorWarningInfoIgnoreLabels= new String[] {
PreferencesMessages.JavadocProblemsConfigurationBlock_error,
PreferencesMessages.JavadocProblemsConfigurationBlock_warning,
+ PreferencesMessages.JavadocProblemsConfigurationBlock_info,
PreferencesMessages.JavadocProblemsConfigurationBlock_ignore
};
@@ -211,7 +213,7 @@
GridDataFactory.fillDefaults().span(nColumns, 1).hint(1, 5).applyTo(spacer);
label = PreferencesMessages.JavadocProblemsConfigurationBlock_pb_invalid_javadoc_label;
- addComboBox(composite, label, PREF_PB_INVALID_JAVADOC, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+ addComboBox(composite, label, PREF_PB_INVALID_JAVADOC, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, 0);
label = PreferencesMessages.JavadocProblemsConfigurationBlock_pb_invalid_javadoc_tags_visibility_label;
addComboBox(composite, label, PREF_PB_INVALID_JAVADOC_TAGS_VISIBILITY, visibilities, visibilitiesLabels, indent);
@@ -243,7 +245,7 @@
GridDataFactory.fillDefaults().span(nColumns, 1).hint(1, 5).applyTo(spacer);
label = PreferencesMessages.JavadocProblemsConfigurationBlock_pb_missing_javadoc_label;
- addComboBox(composite, label, PREF_PB_MISSING_JAVADOC_TAGS, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+ addComboBox(composite, label, PREF_PB_MISSING_JAVADOC_TAGS, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, 0);
label = PreferencesMessages.JavadocProblemsConfigurationBlock_pb_missing_javadoc_tags_visibility_label;
addComboBox(composite, label, PREF_PB_MISSING_JAVADOC_TAGS_VISIBILITY, visibilities, visibilitiesLabels, indent);
@@ -259,7 +261,7 @@
GridDataFactory.fillDefaults().span(nColumns, 1).hint(1, 5).applyTo(spacer);
label = PreferencesMessages.JavadocProblemsConfigurationBlock_pb_missing_comments_label;
- addComboBox(composite, label, PREF_PB_MISSING_JAVADOC_COMMENTS, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+ addComboBox(composite, label, PREF_PB_MISSING_JAVADOC_COMMENTS, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, 0);
label = PreferencesMessages.JavadocProblemsConfigurationBlock_pb_missing_comments_visibility_label;
addComboBox(composite, label, PREF_PB_MISSING_JAVADOC_COMMENTS_VISIBILITY, visibilities, visibilitiesLabels, indent);
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java
index e2759f6..9519d38 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java
@@ -347,6 +347,7 @@
public static String JavaBuildConfigurationBlock_section_build_path_problems;
public static String JavaBuildConfigurationBlock_error;
public static String JavaBuildConfigurationBlock_warning;
+ public static String JavaBuildConfigurationBlock_info;
public static String JavaBuildConfigurationBlock_ignore;
public static String JavaBuildConfigurationBlock_needsbuild_title;
public static String JavaBuildConfigurationBlock_needsfullbuild_message;
@@ -373,6 +374,7 @@
public static String ProblemSeveritiesConfigurationBlock_enable_annotation_null_analysis;
public static String ProblemSeveritiesConfigurationBlock_error;
public static String ProblemSeveritiesConfigurationBlock_warning;
+ public static String ProblemSeveritiesConfigurationBlock_info;
public static String ProblemSeveritiesConfigurationBlock_ignore;
public static String ProblemSeveritiesConfigurationBlock_section_potential_programming_problems;
public static String ProblemSeveritiesConfigurationBlock_section_unnecessary_code;
@@ -457,6 +459,7 @@
public static String JavadocProblemsConfigurationBlock_private;
public static String JavadocProblemsConfigurationBlock_error;
public static String JavadocProblemsConfigurationBlock_warning;
+ public static String JavadocProblemsConfigurationBlock_info;
public static String JavadocProblemsConfigurationBlock_ignore;
public static String JavadocProblemsConfigurationBlock_note_title;
public static String JavadocProblemsConfigurationBlock_note_message;
@@ -482,6 +485,7 @@
public static String CompliancePreferencePage_title;
public static String ComplianceConfigurationBlock_error;
public static String ComplianceConfigurationBlock_warning;
+ public static String ComplianceConfigurationBlock_info;
public static String ComplianceConfigurationBlock_ignore;
public static String ComplianceConfigurationBlock_version11;
public static String ComplianceConfigurationBlock_version12;
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties
index 0b2cb42..0f60392 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties
@@ -350,6 +350,7 @@
JavaBuildConfigurationBlock_error=Error
JavaBuildConfigurationBlock_warning=Warning
+JavaBuildConfigurationBlock_info=Info
JavaBuildConfigurationBlock_ignore=Ignore
JavaBuildConfigurationBlock_needsbuild_title=Building Settings Changed
@@ -387,6 +388,7 @@
ProblemSeveritiesConfigurationBlock_enable_annotation_null_analysis=Enable annotation-based null analysis
ProblemSeveritiesConfigurationBlock_error=Error
ProblemSeveritiesConfigurationBlock_warning=Warning
+ProblemSeveritiesConfigurationBlock_info=Info
ProblemSeveritiesConfigurationBlock_ignore=Ignore
ProblemSeveritiesConfigurationBlock_section_potential_programming_problems=&Potential programming problems
@@ -502,6 +504,7 @@
JavadocProblemsConfigurationBlock_error=Error
JavadocProblemsConfigurationBlock_warning=Warning
+JavadocProblemsConfigurationBlock_info=Info
JavadocProblemsConfigurationBlock_ignore=Ignore
# The argument is replaced by the NLSed string for JavadocProblemsConfigurationBlock_note_title
@@ -534,6 +537,7 @@
ComplianceConfigurationBlock_error=Error
ComplianceConfigurationBlock_warning=Warning
+ComplianceConfigurationBlock_info=Info
ComplianceConfigurationBlock_ignore=Ignore
ComplianceConfigurationBlock_version11=1.1
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ProblemSeveritiesConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ProblemSeveritiesConfigurationBlock.java
index 73bbb31..dc83811 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ProblemSeveritiesConfigurationBlock.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ProblemSeveritiesConfigurationBlock.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -344,6 +344,7 @@
// values
private static final String ERROR= JavaCore.ERROR;
private static final String WARNING= JavaCore.WARNING;
+ private static final String INFO= JavaCore.INFO;
private static final String IGNORE= JavaCore.IGNORE;
private static final String ENABLED= JavaCore.ENABLED;
@@ -445,10 +446,11 @@
}
private Composite createStyleTabContent(Composite folder) {
- String[] errorWarningIgnore= new String[] { ERROR, WARNING, IGNORE };
- String[] errorWarningIgnoreLabels= new String[] {
+ String[] errorWarningInfoIgnore= new String[] { ERROR, WARNING, INFO, IGNORE };
+ String[] errorWarningInfoIgnoreLabels= new String[] {
PreferencesMessages.ProblemSeveritiesConfigurationBlock_error,
PreferencesMessages.ProblemSeveritiesConfigurationBlock_warning,
+ PreferencesMessages.ProblemSeveritiesConfigurationBlock_info,
PreferencesMessages.ProblemSeveritiesConfigurationBlock_ignore
};
@@ -493,39 +495,39 @@
// - expression level
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_static_access_receiver_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_STATIC_ACCESS_RECEIVER, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_STATIC_ACCESS_RECEIVER, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_indirect_access_to_static_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_INDIRECT_STATIC_ACCESS, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_INDIRECT_STATIC_ACCESS, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unqualified_field_access_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNQUALIFIED_FIELD_ACCESS, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNQUALIFIED_FIELD_ACCESS, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_synth_access_emul_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_SYNTHETIC_ACCESS_EMULATION, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_SYNTHETIC_ACCESS_EMULATION, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_parameter_assignment;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_PARAMETER_ASSIGNMENT, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_PARAMETER_ASSIGNMENT, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
// - statements level
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_non_externalized_strings_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_NON_EXTERNALIZED_STRINGS, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_NON_EXTERNALIZED_STRINGS, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_undocumented_empty_block_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNDOCUMENTED_EMPTY_BLOCK, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNDOCUMENTED_EMPTY_BLOCK, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_resource_not_managed_via_twr_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
// - member level
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_method_naming_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_METHOD_WITH_CONSTRUCTOR_NAME, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_METHOD_WITH_CONSTRUCTOR_NAME, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_missing_static_on_method_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_MISSING_STATIC_ON_METHOD, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_MISSING_STATIC_ON_METHOD, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_potentially_missing_static_on_method_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_POTENTIALLY_MISSING_STATIC_ON_METHOD, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_POTENTIALLY_MISSING_STATIC_ON_METHOD, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
// --- potential_programming_problems
@@ -538,68 +540,68 @@
// - affecting expressions
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_comparing_identical;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_COMPARING_IDENTICAL, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_COMPARING_IDENTICAL, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_no_effect_assignment_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_NO_EFFECT_ASSIGNMENT, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_NO_EFFECT_ASSIGNMENT, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_accidential_assignement_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_POSSIBLE_ACCIDENTAL_BOOLEAN_ASSIGNMENT, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_POSSIBLE_ACCIDENTAL_BOOLEAN_ASSIGNMENT, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_autoboxing_problem_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_AUTOBOXING_PROBLEM, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_AUTOBOXING_PROBLEM, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_char_array_in_concat_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_CHAR_ARRAY_IN_CONCAT, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_CHAR_ARRAY_IN_CONCAT, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
// - affecting method invocations
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_inexact_vararg_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_VARARGS_ARGUMENT_NEED_CAST, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_VARARGS_ARGUMENT_NEED_CAST, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
// - affecting single statements
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_empty_statement_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_EMPTY_STATEMENT, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_EMPTY_STATEMENT, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unused_object_allocation_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_OBJECT_ALLOCATION, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_OBJECT_ALLOCATION, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_incomplete_enum_switch_label;
- node= fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_INCOMPLETE_ENUM_SWITCH, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ node= fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_INCOMPLETE_ENUM_SWITCH, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_missing_enum_case_despite_default;
fFilteredPrefTree.addCheckBox(inner, label, PREF_15_PB_MISSING_ENUM_CASE_DESPITE_DEFAULT, enabledDisabled, extraIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_switch_missing_default_case_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_SWITCH_MISSING_DEFAULT_CASE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_SWITCH_MISSING_DEFAULT_CASE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_fall_through_case;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_FALLTHROUGH_CASE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_FALLTHROUGH_CASE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_hidden_catchblock_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_HIDDEN_CATCH_BLOCK, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_HIDDEN_CATCH_BLOCK, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_finally_block_not_completing_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_FINALLY_BLOCK_NOT_COMPLETING, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_FINALLY_BLOCK_NOT_COMPLETING, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
// - affecting code blocks
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_dead_code;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_DEAD_CODE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_DEAD_CODE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_resource_leak_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNCLOSED_CLOSEABLE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNCLOSED_CLOSEABLE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_potential_resource_leak_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
// - affecting members
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_missing_serial_version_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_MISSING_SERIAL_VERSION, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_MISSING_SERIAL_VERSION, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_missing_synchronized_on_inherited_method;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_missing_hashcode_method;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_MISSING_HASHCODE_METHOD, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_MISSING_HASHCODE_METHOD, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
// --- name_shadowing
@@ -612,22 +614,22 @@
inner= createInnerComposite(excomposite, nColumns, composite.getFont());
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_field_hiding_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_FIELD_HIDING, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_FIELD_HIDING, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_local_variable_hiding_label;
- node= fFilteredPrefTree.addComboBox(inner, label, PREF_PB_LOCAL_VARIABLE_HIDING, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ node= fFilteredPrefTree.addComboBox(inner, label, PREF_PB_LOCAL_VARIABLE_HIDING, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_special_param_hiding_label;
fFilteredPrefTree.addCheckBox(inner, label, PREF_PB_SPECIAL_PARAMETER_HIDING_FIELD, enabledDisabled, extraIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_type_parameter_hiding_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_TYPE_PARAMETER_HIDING, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_TYPE_PARAMETER_HIDING, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_overriding_pkg_dflt_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_incompatible_interface_method_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_INCOMPATIBLE_INTERFACE_METHOD, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_INCOMPATIBLE_INTERFACE_METHOD, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
// --- API access rules
@@ -639,7 +641,7 @@
inner= createInnerComposite(excomposite, nColumns, composite.getFont());
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_deprecation_label;
- node= fFilteredPrefTree.addComboBox(inner, label, PREF_PB_DEPRECATION, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ node= fFilteredPrefTree.addComboBox(inner, label, PREF_PB_DEPRECATION, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_deprecation_in_deprecation_label;
fFilteredPrefTree.addCheckBox(inner, label, PREF_PB_DEPRECATION_IN_DEPRECATED_CODE, enabledDisabled, extraIndent, node);
@@ -648,10 +650,10 @@
fFilteredPrefTree.addCheckBox(inner, label, PREF_PB_DEPRECATION_WHEN_OVERRIDING, enabledDisabled, extraIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_forbidden_reference_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_FORBIDDEN_REFERENCE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_FORBIDDEN_REFERENCE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_discourraged_reference_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_DISCOURRAGED_REFERENCE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_DISCOURRAGED_REFERENCE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
// --- unnecessary_code
@@ -664,37 +666,37 @@
inner= createInnerComposite(excomposite, nColumns, composite.getFont());
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unused_local_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_LOCAL, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_LOCAL, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unused_parameter_label;
- node= fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_PARAMETER, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ node= fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_PARAMETER, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_signal_param_in_overriding_label;
fFilteredPrefTree.addCheckBox(inner, label, PREF_PB_SIGNAL_PARAMETER_IN_OVERRIDING, disabledEnabled, extraIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unused_type_parameter;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_TYPE_PARAMETER, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_TYPE_PARAMETER, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_ignore_documented_unused_parameters;
fFilteredPrefTree.addCheckBox(inner, label, PREF_PB_UNUSED_PARAMETER_INCLUDE_DOC_COMMENT_REFERENCE, enabledDisabled, defaultIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unused_exception_parameter_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_EXCEPTION_PARAMETER, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_EXCEPTION_PARAMETER, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unused_imports_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_IMPORT, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_IMPORT, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unused_private_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_PRIVATE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_PRIVATE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unnecessary_else_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNNECESSARY_ELSE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNNECESSARY_ELSE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unnecessary_type_check_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNNECESSARY_TYPE_CHECK, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNNECESSARY_TYPE_CHECK, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unused_throwing_exception_label;
- node= fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ node= fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unused_throwing_exception_when_overriding_label;
fFilteredPrefTree.addCheckBox(inner, label, PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION_WHEN_OVERRIDING, disabledEnabled, extraIndent, node);
@@ -706,10 +708,10 @@
fFilteredPrefTree.addCheckBox(inner, label, PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION_EXEMPT_EXCEPTION_AND_THROWABLE, enabledDisabled, extraIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unused_label_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_LABEL, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_LABEL, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_redundant_super_interface_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_REDUNDANT_SUPERINTERFACE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_REDUNDANT_SUPERINTERFACE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
// --- generics
@@ -721,16 +723,16 @@
inner= createInnerComposite(excomposite, nColumns, composite.getFont());
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unsafe_type_op_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_UNCHECKED_TYPE_OPERATION, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_UNCHECKED_TYPE_OPERATION, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_raw_type_reference;
- fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_RAW_TYPE_REFERENCE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_RAW_TYPE_REFERENCE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_final_param_bound_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_FINAL_PARAM_BOUND, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_FINAL_PARAM_BOUND, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_redundant_type_arguments_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_17_PB_REDUNDANT_TYPE_ARGUMENTS, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_17_PB_REDUNDANT_TYPE_ARGUMENTS, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unavoidable_generic_type_problems;
fFilteredPrefTree.addCheckBox(inner, label, PREF_15_PB_UNAVOIDABLE_GENERIC_TYPE_PROBLEMS, disabledEnabled, defaultIndent, section);
@@ -745,25 +747,25 @@
inner= createInnerComposite(excomposite, nColumns, composite.getFont());
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_missing_override_annotation_label;
- node= fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_MISSING_OVERRIDE_ANNOTATION, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ node= fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_MISSING_OVERRIDE_ANNOTATION, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_missing_override_annotation_for_interface_method_implementations_label;
fFilteredPrefTree.addCheckBox(inner, label, PREF_16_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, enabledDisabled, extraIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_missing_deprecated_annotation_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_MISSING_DEPRECATED_ANNOTATION, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_MISSING_DEPRECATED_ANNOTATION, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_annotation_super_interface_label;
- fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_ANNOTATION_SUPER_INTERFACE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_15_PB_ANNOTATION_SUPER_INTERFACE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unhandled_surpresswarning_tokens;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNHANDLED_WARNING_TOKEN, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNHANDLED_WARNING_TOKEN, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_enable_surpresswarning_annotation;
node= fFilteredPrefTree.addCheckBox(inner, label, PREF_PB_SUPPRESS_WARNINGS, enabledDisabled, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_unused_suppresswarnings_token;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_WARNING_TOKEN, errorWarningIgnore, errorWarningIgnoreLabels, extraIndent, node);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNUSED_WARNING_TOKEN, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, extraIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_suppress_optional_errors_label;
fFilteredPrefTree.addCheckBox(inner, label, PREF_PB_SUPPRESS_OPTIONAL_ERRORS, enabledDisabled, extraIndent, node);
@@ -778,13 +780,13 @@
inner= createInnerComposite(excomposite, nColumns, composite.getFont());
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_null_reference;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_NULL_REFERENCE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_NULL_REFERENCE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_potential_null_reference;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_POTENTIAL_NULL_REFERENCE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_POTENTIAL_NULL_REFERENCE, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_redundant_null_check;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_REDUNDANT_NULL_CHECK, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent, section);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_REDUNDANT_NULL_CHECK, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_include_assert_in_null_analysis;
fFilteredPrefTree.addCheckBox(inner, label, PREF_PB_INCLUDE_ASSERTS_IN_NULL_ANALYSIS, enabledDisabled, defaultIndent, section);
@@ -798,19 +800,19 @@
fFilteredPrefTree.addComboBox(inner, label, PREF_PB_NULL_SPECIFICATION_VIOLATION, errorWarning, errorWarningLabels, extraIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_null_annotation_inference_conflict;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_POTENTIAL_NULL_ANNOTATION_INFERENCE_CONFLICT, errorWarningIgnore, errorWarningIgnoreLabels, extraIndent, node);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_POTENTIAL_NULL_ANNOTATION_INFERENCE_CONFLICT, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, extraIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_null_unchecked_conversion;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_NULL_UNCHECKED_CONVERSION, errorWarningIgnore, errorWarningIgnoreLabels, extraIndent, node);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_NULL_UNCHECKED_CONVERSION, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, extraIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_redundant_null_annotation;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_REDUNDANT_NULL_ANNOTATION, errorWarningIgnore, errorWarningIgnoreLabels, extraIndent, node);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_REDUNDANT_NULL_ANNOTATION, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, extraIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_nonnull_parameter_annotation_dropped;
- fFilteredPrefTree.addComboBox(inner, label, PREF_PB_NONNULL_PARAMETER_ANNOTATION_DROPPED, errorWarningIgnore, errorWarningIgnoreLabels, extraIndent, node);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_PB_NONNULL_PARAMETER_ANNOTATION_DROPPED, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, extraIndent, node);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_missing_nonnull_by_default_annotation;
- fFilteredPrefTree.addComboBox(inner, label, PREF_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, errorWarningIgnore, errorWarningIgnoreLabels, extraIndent, node);
+ fFilteredPrefTree.addComboBox(inner, label, PREF_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, extraIndent, node);
label= PreferencesMessages.NullAnnotationsConfigurationDialog_use_default_annotations_for_null;
fFilteredPrefTree.addCheckBoxWithLink(inner, label, INTR_DEFAULT_NULL_ANNOTATIONS, enabledDisabled, extraIndent, node, true, SWT.DEFAULT,
@@ -960,13 +962,17 @@
}
}
- private static boolean lessSevere(String errorWarningIgnore, String errorWarningIgnore2) {
- if (IGNORE.equals(errorWarningIgnore))
- return ! IGNORE.equals(errorWarningIgnore2);
- else if (WARNING.equals(errorWarningIgnore))
- return ERROR.equals(errorWarningIgnore2);
- else
- return false;
+ private static boolean lessSevere(String errorWarningInfoIgnore, String errorWarningInfoIgnore2) {
+ switch (errorWarningInfoIgnore) {
+ case IGNORE:
+ return !IGNORE.equals(errorWarningInfoIgnore2);
+ case INFO:
+ return !IGNORE.equals(errorWarningInfoIgnore2) && !INFO.equals(errorWarningInfoIgnore2);
+ case WARNING:
+ return ERROR.equals(errorWarningInfoIgnore2);
+ default:
+ return false;
+ }
}
private void updateNullAnnotationsSetting() {
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ASTResolving.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ASTResolving.java
index 78000b5..daac9c1 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ASTResolving.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ASTResolving.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -787,7 +787,7 @@
public static TryStatement findParentTryStatement(ASTNode node) {
while ((node != null) && (!(node instanceof TryStatement))) {
node= node.getParent();
- if (node instanceof BodyDeclaration) {
+ if (node instanceof BodyDeclaration || node instanceof LambdaExpression) {
return null;
}
}
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 33a9ddf..701af70 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
@@ -16,7 +16,6 @@
package org.eclipse.jdt.internal.ui.text.correction;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
@@ -77,8 +76,10 @@
import org.eclipse.jdt.core.dom.InfixExpression;
import org.eclipse.jdt.core.dom.Initializer;
import org.eclipse.jdt.core.dom.InstanceofExpression;
+import org.eclipse.jdt.core.dom.LambdaExpression;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.MethodReference;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.NameQualifiedType;
@@ -129,6 +130,7 @@
import org.eclipse.jdt.internal.corext.fix.UnusedCodeFix;
import org.eclipse.jdt.internal.corext.refactoring.code.Invocations;
import org.eclipse.jdt.internal.corext.refactoring.surround.ExceptionAnalyzer;
+import org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithAnalyzer;
import org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryCatchRefactoring;
import org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer;
import org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer;
@@ -191,7 +193,8 @@
if (selectedNode == null) {
return;
}
- while (selectedNode != null && !(selectedNode instanceof Statement) && !(selectedNode instanceof VariableDeclarationExpression)) {
+ while (selectedNode != null && !(selectedNode instanceof Statement) && !(selectedNode instanceof VariableDeclarationExpression)
+ && !(selectedNode.getLocationInParent() == LambdaExpression.BODY_PROPERTY) && !(selectedNode instanceof MethodReference)) {
selectedNode= selectedNode.getParent();
}
if (selectedNode == null) {
@@ -241,7 +244,12 @@
return;
}
- ITypeBinding[] uncaughtExceptions= ExceptionAnalyzer.perform(decl, Selection.createFromStartLength(offset, length));
+ ASTNode enclosingNode= SurroundWithAnalyzer.getEnclosingNode(selectedNode);
+ if (enclosingNode == null) {
+ return;
+ }
+
+ ITypeBinding[] uncaughtExceptions= ExceptionAnalyzer.perform(enclosingNode, Selection.createFromStartLength(offset, length));
if (uncaughtExceptions.length == 0) {
return;
}
@@ -293,7 +301,7 @@
List<CatchClause> catchClauses= surroundingTry.catchClauses();
if (catchClauses != null && catchClauses.size() == 1) {
- List<ITypeBinding> filteredExceptions= filterSubtypeExceptions(uncaughtExceptions);
+ List<ITypeBinding> filteredExceptions= SurroundWithTryCatchRefactoring.filterSubtypeExceptions(uncaughtExceptions);
String label= filteredExceptions.size() > 1
? CorrectionMessages.LocalCorrectionsSubProcessor_addexceptionstoexistingcatch_description
: CorrectionMessages.LocalCorrectionsSubProcessor_addexceptiontoexistingcatch_description;
@@ -334,55 +342,57 @@
rewrite.replace(type, newUnionType, null);
}
proposals.add(proposal);
- } else if (catchClauses != null && catchClauses.size() == 0 && uncaughtExceptions.length > 1) {
- String label= CorrectionMessages.LocalCorrectionsSubProcessor_addadditionalmulticatch_description;
- Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION);
- ASTRewrite rewrite= ASTRewrite.create(ast);
- LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.ADD_ADDITIONAL_MULTI_CATCH, image);
- ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot());
- ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports);
+ } else if (catchClauses != null && catchClauses.size() == 0) {
+ List<ITypeBinding> filteredExceptions= SurroundWithTryCatchRefactoring.filterSubtypeExceptions(uncaughtExceptions);
+ if (filteredExceptions.size() > 1) {
+ String label= CorrectionMessages.LocalCorrectionsSubProcessor_addadditionalmulticatch_description;
+ Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION);
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+ LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.ADD_ADDITIONAL_MULTI_CATCH, image);
+ ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot());
+ ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports);
- CodeScopeBuilder.Scope scope= CodeScopeBuilder.perform(decl, Selection.createFromStartLength(offset, length)).
- findScope(offset, length);
- scope.setCursor(offset);
+ CodeScopeBuilder.Scope scope= CodeScopeBuilder.perform(decl, Selection.createFromStartLength(offset, length)).findScope(offset, length);
+ scope.setCursor(offset);
- CatchClause newCatchClause= ast.newCatchClause();
- String varName= StubUtility.getExceptionVariableName(cu.getJavaProject());
- String name= scope.createName(varName, false);
- SingleVariableDeclaration var= ast.newSingleVariableDeclaration();
- var.setName(ast.newSimpleName(name));
+ CatchClause newCatchClause= ast.newCatchClause();
+ String varName= StubUtility.getExceptionVariableName(cu.getJavaProject());
+ String name= scope.createName(varName, false);
+ SingleVariableDeclaration var= ast.newSingleVariableDeclaration();
+ var.setName(ast.newSimpleName(name));
- UnionType newUnionType= ast.newUnionType();
- List<Type> types= newUnionType.types();
+ UnionType newUnionType= ast.newUnionType();
+ List<Type> types= newUnionType.types();
- for (int i= 0; i < uncaughtExceptions.length; i++) {
- ITypeBinding excBinding= uncaughtExceptions[i];
- Type type2= imports.addImport(excBinding, ast, importRewriteContext);
- types.add(type2);
+ for (int i= 0; i < filteredExceptions.size(); i++) {
+ ITypeBinding excBinding= filteredExceptions.get(i);
+ Type type2= imports.addImport(excBinding, ast, importRewriteContext);
+ types.add(type2);
- String typeKey= "type" + i; //$NON-NLS-1$
- proposal.addLinkedPosition(rewrite.track(type2), false, typeKey);
- addExceptionTypeLinkProposals(proposal, excBinding, typeKey);
+ String typeKey= "type" + i; //$NON-NLS-1$
+ proposal.addLinkedPosition(rewrite.track(type2), false, typeKey);
+ addExceptionTypeLinkProposals(proposal, excBinding, typeKey);
+ }
+ String nameKey= "name"; //$NON-NLS-1$
+ proposal.addLinkedPosition(rewrite.track(var.getName()), false, nameKey);
+ var.setType(newUnionType);
+ newCatchClause.setException(var);
+ String catchBody= StubUtility.getCatchBodyContent(cu, "Exception", name, selectedNode, String.valueOf('\n')); //$NON-NLS-1$
+ if (catchBody != null) {
+ ASTNode node= rewrite.createStringPlaceholder(catchBody, ASTNode.RETURN_STATEMENT);
+ newCatchClause.getBody().statements().add(node);
+ }
+ ListRewrite listRewrite= rewrite.getListRewrite(surroundingTry, TryStatement.CATCH_CLAUSES_PROPERTY);
+ listRewrite.insertFirst(newCatchClause, null);
+ proposals.add(proposal);
}
- String nameKey= "name"; //$NON-NLS-1$
- proposal.addLinkedPosition(rewrite.track(var.getName()), false, nameKey);
- var.setType(newUnionType);
- newCatchClause.setException(var);
- String catchBody= StubUtility.getCatchBodyContent(cu, "Exception", name, selectedNode, String.valueOf('\n')); //$NON-NLS-1$
- if (catchBody != null) {
- ASTNode node= rewrite.createStringPlaceholder(catchBody, ASTNode.RETURN_STATEMENT);
- newCatchClause.getBody().statements().add(node);
- }
- ListRewrite listRewrite= rewrite.getListRewrite(surroundingTry, TryStatement.CATCH_CLAUSES_PROPERTY);
- listRewrite.insertFirst(newCatchClause, null);
- proposals.add(proposal);
}
}
}
//Add throws declaration
- if (decl instanceof MethodDeclaration) {
- MethodDeclaration methodDecl= (MethodDeclaration) decl;
+ if (enclosingNode instanceof MethodDeclaration) {
+ MethodDeclaration methodDecl= (MethodDeclaration) enclosingNode;
IMethodBinding binding= methodDecl.resolveBinding();
boolean isApplicable= (binding != null);
if (isApplicable) {
@@ -440,23 +450,6 @@
}
}
- private static List<ITypeBinding> filterSubtypeExceptions(ITypeBinding[] exceptions) {
- List<ITypeBinding> filteredExceptions= new ArrayList<>();
- filteredExceptions.addAll(Arrays.asList(exceptions));
-
- for (Iterator<ITypeBinding> subtypeIterator= filteredExceptions.iterator(); subtypeIterator.hasNext();) {
- ITypeBinding iTypeBinding= subtypeIterator.next();
- for (Iterator<ITypeBinding> supertypeIterator= filteredExceptions.iterator(); supertypeIterator.hasNext();) {
- ITypeBinding superTypeBinding= supertypeIterator.next();
- if (!iTypeBinding.equals(superTypeBinding) && iTypeBinding.isSubTypeCompatible(superTypeBinding)) {
- subtypeIterator.remove();
- break;
- }
- }
- }
- return filteredExceptions;
- }
-
private static void addExceptionTypeLinkProposals(LinkedCorrectionProposal proposal, ITypeBinding exc, String key) {
// all super classes except Object
while (exc != null && !"java.lang.Object".equals(exc.getQualifiedName())) { //$NON-NLS-1$
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java
index 59cbf05..5a787a7 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java
@@ -623,30 +623,71 @@
return false;
}
- IMethodBinding referredMethodBinding= methodReference.resolveMethodBinding(); // too often null, see bug 440000, bug 440344, bug 333665
+ IMethodBinding functionalMethod= getFunctionalMethodForMethodReference(methodReference);
+ if (functionalMethod == null || functionalMethod.isGenericMethod()) { // generic lambda expressions are not allowed
+ return false;
+ }
+ if (resultingCollections == null)
+ return true;
+
+ ASTRewrite rewrite= ASTRewrite.create(methodReference.getAST());
+ LinkedProposalModel linkedProposalModel= new LinkedProposalModel();
+
+ LambdaExpression lambda= convertMethodRefernceToLambda(methodReference, functionalMethod, context.getASTRoot(), rewrite, linkedProposalModel, false);
+
+ // add proposal
+ String label= CorrectionMessages.QuickAssistProcessor_convert_to_lambda_expression;
+ Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
+ LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.CONVERT_METHOD_REFERENCE_TO_LAMBDA, image);
+ proposal.setLinkedProposalModel(linkedProposalModel);
+ proposal.setEndPosition(rewrite.track(lambda));
+ resultingCollections.add(proposal);
+ return true;
+ }
+
+ /**
+ * Returns the functional interface method being implemented by the given method reference.
+ *
+ * @param methodReference the method reference to get the functional method
+ * @return the functional interface method being implemented by <code>methodReference</code> or
+ * <code>null</code> if it could not be derived
+ */
+ public static IMethodBinding getFunctionalMethodForMethodReference(MethodReference methodReference) {
ITypeBinding targetTypeBinding= ASTNodes.getTargetType(methodReference);
if (targetTypeBinding == null)
- return false;
+ return null;
IMethodBinding functionalMethod= targetTypeBinding.getFunctionalInterfaceMethod();
if (functionalMethod.isSynthetic()) {
functionalMethod= Bindings.findOverriddenMethodInType(functionalMethod.getDeclaringClass(), functionalMethod);
}
- if (functionalMethod == null)
- return false;
- if (functionalMethod.isGenericMethod()) // generic lambda expressions are not allowed
- return false;
+ return functionalMethod;
+ }
- if (resultingCollections == null)
- return true;
+ /**
+ * Converts and replaces the given method reference with corresponding lambda expression in the
+ * given ASTRewrite.
+ *
+ * @param methodReference the method reference to convert
+ * @param functionalMethod the non-generic functional interface method to be implemented by the
+ * lambda expression
+ * @param astRoot the AST root
+ * @param rewrite the ASTRewrite
+ * @param linkedProposalModel to create linked proposals for lambda's parameters or
+ * <code>null</code> if linked proposals are not required
+ * @param createBlockBody <code>true</code> if lambda expression's body should be a block
+ *
+ * @return lambda expression used to replace the method reference in the given ASTRewrite
+ * @throws JavaModelException if an exception occurs while accessing the Java element
+ * corresponding to the <code>functionalMethod</code>
+ */
+ public static LambdaExpression convertMethodRefernceToLambda(MethodReference methodReference, IMethodBinding functionalMethod, CompilationUnit astRoot,
+ ASTRewrite rewrite, LinkedProposalModel linkedProposalModel, boolean createBlockBody) throws JavaModelException {
- AST ast= methodReference.getAST();
- ASTRewrite rewrite= ASTRewrite.create(ast);
- ImportRewrite importRewrite= null;
+ AST ast= astRoot.getAST();
LambdaExpression lambda= ast.newLambdaExpression();
- LinkedProposalModel linkedProposalModel= new LinkedProposalModel();
String[] lambdaParamNames= getUniqueParameterNames(methodReference, functionalMethod);
List<VariableDeclaration> lambdaParameters= lambda.parameters();
for (int i= 0; i < lambdaParamNames.length; i++) {
@@ -655,28 +696,45 @@
SimpleName name= ast.newSimpleName(paramName);
lambdaParameter.setName(name);
lambdaParameters.add(lambdaParameter);
- linkedProposalModel.getPositionGroup(name.getIdentifier(), true).addPosition(rewrite.track(name), i == 0);
+ if (linkedProposalModel != null) {
+ linkedProposalModel.getPositionGroup(name.getIdentifier(), true).addPosition(rewrite.track(name), i == 0);
+ }
}
int noOfLambdaParameters= lambdaParamNames.length;
lambda.setParentheses(noOfLambdaParameters != 1);
+ ITypeBinding returnTypeBinding= functionalMethod.getReturnType();
+ IMethodBinding referredMethodBinding= methodReference.resolveMethodBinding(); // too often null, see bug 440000, bug 440344, bug 333665
+
if (methodReference instanceof CreationReference) {
CreationReference creationRef= (CreationReference) methodReference;
Type type= creationRef.getType();
if (type instanceof ArrayType) {
ArrayCreation arrayCreation= ast.newArrayCreation();
- lambda.setBody(arrayCreation);
+ if (createBlockBody) {
+ Block blockBody= getBlockBodyForLambda(arrayCreation, returnTypeBinding, ast);
+ lambda.setBody(blockBody);
+ } else {
+ lambda.setBody(arrayCreation);
+ }
ArrayType arrayType= (ArrayType) type;
Type copiedElementType= (Type) rewrite.createCopyTarget(arrayType.getElementType());
arrayCreation.setType(ast.newArrayType(copiedElementType, arrayType.getDimensions()));
SimpleName name= ast.newSimpleName(lambdaParamNames[0]);
arrayCreation.dimensions().add(name);
- linkedProposalModel.getPositionGroup(name.getIdentifier(), false).addPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP);
+ if (linkedProposalModel != null) {
+ linkedProposalModel.getPositionGroup(name.getIdentifier(), false).addPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP);
+ }
} else {
ClassInstanceCreation cic= ast.newClassInstanceCreation();
- lambda.setBody(cic);
+ if (createBlockBody) {
+ Block blockBody= getBlockBodyForLambda(cic, returnTypeBinding, ast);
+ lambda.setBody(blockBody);
+ } else {
+ lambda.setBody(cic);
+ }
ITypeBinding typeBinding= type.resolveBinding();
if (!(type instanceof ParameterizedType) && typeBinding != null && typeBinding.getTypeDeclaration().isGenericType()) {
@@ -686,18 +744,25 @@
}
List<SimpleName> invocationArgs= getInvocationArguments(ast, 0, noOfLambdaParameters, lambdaParamNames);
cic.arguments().addAll(invocationArgs);
- for (SimpleName name : invocationArgs) {
- linkedProposalModel.getPositionGroup(name.getIdentifier(), false).addPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP);
+ if (linkedProposalModel != null) {
+ for (SimpleName name : invocationArgs) {
+ linkedProposalModel.getPositionGroup(name.getIdentifier(), false).addPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP);
+ }
}
cic.typeArguments().addAll(getCopiedTypeArguments(rewrite, methodReference.typeArguments()));
}
} else if (referredMethodBinding != null && Modifier.isStatic(referredMethodBinding.getModifiers())) {
MethodInvocation methodInvocation= ast.newMethodInvocation();
- lambda.setBody(methodInvocation);
+ if (createBlockBody) {
+ Block blockBody= getBlockBodyForLambda(methodInvocation, returnTypeBinding, ast);
+ lambda.setBody(blockBody);
+ } else {
+ lambda.setBody(methodInvocation);
+ }
Expression expr= null;
- boolean hasConflict= hasConflict(methodReference.getStartPosition(), referredMethodBinding, ScopeAnalyzer.METHODS | ScopeAnalyzer.CHECK_VISIBILITY, context.getASTRoot());
+ boolean hasConflict= hasConflict(methodReference.getStartPosition(), referredMethodBinding, ScopeAnalyzer.METHODS | ScopeAnalyzer.CHECK_VISIBILITY, astRoot);
if (hasConflict || !Bindings.isSuperType(referredMethodBinding.getDeclaringClass(), ASTNodes.getEnclosingType(methodReference)) || methodReference.typeArguments().size() != 0) {
if (methodReference instanceof ExpressionMethodReference) {
ExpressionMethodReference expressionMethodReference= (ExpressionMethodReference) methodReference;
@@ -706,7 +771,7 @@
Type type= ((TypeMethodReference) methodReference).getType();
ITypeBinding typeBinding= type.resolveBinding();
if (typeBinding != null) {
- importRewrite= StubUtility.createImportRewrite(context.getASTRoot(), true);
+ ImportRewrite importRewrite= StubUtility.createImportRewrite(astRoot, true);
expr= ast.newName(importRewrite.addImport(typeBinding));
}
}
@@ -716,14 +781,21 @@
methodInvocation.setName((SimpleName) rewrite.createCopyTarget(methodName));
List<SimpleName> invocationArgs= getInvocationArguments(ast, 0, noOfLambdaParameters, lambdaParamNames);
methodInvocation.arguments().addAll(invocationArgs);
- for (SimpleName name : invocationArgs) {
- linkedProposalModel.getPositionGroup(name.getIdentifier(), false).addPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP);
+ if (linkedProposalModel != null) {
+ for (SimpleName name : invocationArgs) {
+ linkedProposalModel.getPositionGroup(name.getIdentifier(), false).addPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP);
+ }
}
methodInvocation.typeArguments().addAll(getCopiedTypeArguments(rewrite, methodReference.typeArguments()));
} else if (methodReference instanceof SuperMethodReference) {
SuperMethodInvocation superMethodInvocation= ast.newSuperMethodInvocation();
- lambda.setBody(superMethodInvocation);
+ if (createBlockBody) {
+ Block blockBody= getBlockBodyForLambda(superMethodInvocation, returnTypeBinding, ast);
+ lambda.setBody(blockBody);
+ } else {
+ lambda.setBody(superMethodInvocation);
+ }
Name superQualifier= ((SuperMethodReference) methodReference).getQualifier();
if (superQualifier != null) {
@@ -733,20 +805,29 @@
superMethodInvocation.setName((SimpleName) rewrite.createCopyTarget(methodName));
List<SimpleName> invocationArgs= getInvocationArguments(ast, 0, noOfLambdaParameters, lambdaParamNames);
superMethodInvocation.arguments().addAll(invocationArgs);
- for (SimpleName name : invocationArgs) {
- linkedProposalModel.getPositionGroup(name.getIdentifier(), false).addPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP);
+ if (linkedProposalModel != null) {
+ for (SimpleName name : invocationArgs) {
+ linkedProposalModel.getPositionGroup(name.getIdentifier(), false).addPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP);
+ }
}
superMethodInvocation.typeArguments().addAll(getCopiedTypeArguments(rewrite, methodReference.typeArguments()));
} else {
MethodInvocation methodInvocation= ast.newMethodInvocation();
- lambda.setBody(methodInvocation);
+ if (createBlockBody) {
+ Block blockBody= getBlockBodyForLambda(methodInvocation, returnTypeBinding, ast);
+ lambda.setBody(blockBody);
+ } else {
+ lambda.setBody(methodInvocation);
+ }
boolean isTypeReference= isTypeReferenceToInstanceMethod(methodReference);
if (isTypeReference) {
SimpleName name= ast.newSimpleName(lambdaParamNames[0]);
methodInvocation.setExpression(name);
- linkedProposalModel.getPositionGroup(name.getIdentifier(), false).addPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP);
+ if (linkedProposalModel != null) {
+ linkedProposalModel.getPositionGroup(name.getIdentifier(), false).addPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP);
+ }
} else {
Expression expr= ((ExpressionMethodReference) methodReference).getExpression();
if (!(expr instanceof ThisExpression && methodReference.typeArguments().size() == 0)) {
@@ -757,25 +838,16 @@
methodInvocation.setName((SimpleName) rewrite.createCopyTarget(methodName));
List<SimpleName> invocationArgs= getInvocationArguments(ast, isTypeReference ? 1 : 0, noOfLambdaParameters, lambdaParamNames);
methodInvocation.arguments().addAll(invocationArgs);
- for (SimpleName name : invocationArgs) {
- linkedProposalModel.getPositionGroup(name.getIdentifier(), false).addPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP);
+ if (linkedProposalModel != null) {
+ for (SimpleName name : invocationArgs) {
+ linkedProposalModel.getPositionGroup(name.getIdentifier(), false).addPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP);
+ }
}
methodInvocation.typeArguments().addAll(getCopiedTypeArguments(rewrite, methodReference.typeArguments()));
}
rewrite.replace(methodReference, lambda, null);
-
- // add proposal
- String label= CorrectionMessages.QuickAssistProcessor_convert_to_lambda_expression;
- Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
- LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.CONVERT_METHOD_REFERENCE_TO_LAMBDA, image);
- proposal.setLinkedProposalModel(linkedProposalModel);
- proposal.setEndPosition(rewrite.track(lambda));
- if (importRewrite != null) {
- proposal.setImportRewrite(importRewrite);
- }
- resultingCollections.add(proposal);
- return true;
+ return lambda;
}
private static boolean hasConflict(int startPosition, IMethodBinding referredMethodBinding, int flags, CompilationUnit cu) {
@@ -884,9 +956,34 @@
AST ast= lambda.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
- Statement statementInBlockBody;
+ changeLambdaBodyToBlock(lambda, ast, rewrite);
+
+ // add proposal
+ String label= CorrectionMessages.QuickAssistProcessor_change_lambda_body_to_block;
+ Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
+ ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.CHANGE_LAMBDA_BODY_TO_BLOCK, image);
+ resultingCollections.add(proposal);
+ return true;
+ }
+
+ /**
+ * Changes the expression body of the given lambda expression to block form.
+ * {@link LambdaExpression#resolveMethodBinding()} should not be <code>null</code> for the given
+ * lambda expression.
+ *
+ * @param lambda the lambda expression to convert the body form
+ * @param ast the AST to create new nodes
+ * @param rewrite the ASTRewrite
+ */
+ public static void changeLambdaBodyToBlock(LambdaExpression lambda, AST ast, ASTRewrite rewrite) {
Expression bodyExpr= (Expression) rewrite.createMoveTarget(lambda.getBody());
- if (ast.resolveWellKnownType("void").isEqualTo(lambda.resolveMethodBinding().getReturnType())) { //$NON-NLS-1$
+ Block blockBody= getBlockBodyForLambda(bodyExpr, lambda.resolveMethodBinding().getReturnType(), ast);
+ rewrite.set(lambda, LambdaExpression.BODY_PROPERTY, blockBody, null);
+ }
+
+ private static Block getBlockBodyForLambda(Expression bodyExpr, ITypeBinding returnTypeBinding, AST ast) {
+ Statement statementInBlockBody;
+ if (ast.resolveWellKnownType("void").isEqualTo(returnTypeBinding)) { //$NON-NLS-1$
ExpressionStatement expressionStatement= ast.newExpressionStatement(bodyExpr);
statementInBlockBody= expressionStatement;
} else {
@@ -896,15 +993,7 @@
}
Block blockBody= ast.newBlock();
blockBody.statements().add(statementInBlockBody);
-
- rewrite.set(lambda, LambdaExpression.BODY_PROPERTY, blockBody, null);
-
- // add proposal
- String label= CorrectionMessages.QuickAssistProcessor_change_lambda_body_to_block;
- Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
- ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.CHANGE_LAMBDA_BODY_TO_BLOCK, image);
- resultingCollections.add(proposal);
- return true;
+ return blockBody;
}
private static boolean getChangeLambdaBodyToExpressionProposal(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) {
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickTemplateProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickTemplateProcessor.java
index 0abdca4..3205cf6 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickTemplateProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickTemplateProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -43,7 +43,7 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.Statement;
+import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.internal.corext.template.java.CompilationUnitContext;
import org.eclipse.jdt.internal.corext.template.java.CompilationUnitContextType;
@@ -186,16 +186,16 @@
IRegion region= new Region(start, end - start);
AssistContext invocationContext= new AssistContext(cu, start, end - start);
- Statement[] selectedStatements= SurroundWith.getSelectedStatements(invocationContext);
+ ASTNode[] selectedNodes= SurroundWith.getValidSelectedNodes(invocationContext);
Template[] templates= JavaPlugin.getDefault().getTemplateStore().getTemplates();
for (int i= 0; i != templates.length; i++) {
Template currentTemplate= templates[i];
if (canEvaluate(context, currentTemplate)) {
- if (selectedStatements != null) {
+ if (selectedNodes != null) {
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
- TemplateProposal proposal= new SurroundWithTemplateProposal(cu, currentTemplate, context, region, image, selectedStatements);
+ TemplateProposal proposal= new SurroundWithTemplateProposal(cu, currentTemplate, context, region, image, selectedNodes);
String[] arg= new String[] { currentTemplate.getName(), currentTemplate.getDescription() };
String decorated= Messages.format(CorrectionMessages.QuickTemplateProcessor_surround_label, arg);
proposal.setDisplayString(StyledCellLabelProvider.styleDecoratedString(decorated, StyledString.QUALIFIER_STYLER, new StyledString(currentTemplate.getName())));
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/SurroundWith.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/SurroundWith.java
index c815f53..5f23a77 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/SurroundWith.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/SurroundWith.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -157,14 +157,14 @@
}
private final CompilationUnit fRootNode;
- private final Statement[] fSelectedStatements;
+ private final ASTNode[] fSelectedNodes;
private boolean fIsNewContext;
private ITrackedNodePosition fFirstInsertedPosition;
private ITrackedNodePosition fLastInsertedPosition;
- public SurroundWith(CompilationUnit root, Statement[] selectedStatements) {
+ public SurroundWith(CompilationUnit root, ASTNode[] selectedNodes) {
fRootNode= root;
- fSelectedStatements= selectedStatements;
+ fSelectedNodes= selectedNodes;
}
@@ -175,7 +175,7 @@
return true;
Selection selection= Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength());
- SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(unit, selection);
+ SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(unit, selection, false);
context.getASTRoot().accept(analyzer);
return analyzer.getStatus().isOK() && analyzer.hasSelectedNodes();
@@ -189,15 +189,15 @@
* @return Selected nodes or null if no valid selection.
* @throws CoreException if the analyzer cannot be created
*/
- public static Statement[] getSelectedStatements(IInvocationContext context) throws CoreException {
+ public static ASTNode[] getValidSelectedNodes(IInvocationContext context) throws CoreException {
Selection selection= Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength());
- SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(context.getCompilationUnit(), selection);
+ SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(context.getCompilationUnit(), selection, false);
context.getASTRoot().accept(analyzer);
if (!analyzer.getStatus().isOK() || !analyzer.hasSelectedNodes()) {
return null;
} else {
- return analyzer.getSelectedStatements();
+ return analyzer.getValidSelectedNodes();
}
}
@@ -215,33 +215,33 @@
* @throws CoreException A core exception is thrown when the could not be created.
*/
public ASTRewrite getRewrite() throws CoreException {
- Statement[] selectedStatements= fSelectedStatements;
+ ASTNode[] selectedNodes= fSelectedNodes;
AST ast= getAst();
ASTRewrite rewrite= ASTRewrite.create(ast);
- BodyDeclaration enclosingBodyDeclaration= (BodyDeclaration)ASTNodes.getParent(selectedStatements[0], BodyDeclaration.class);
+ BodyDeclaration enclosingBodyDeclaration= (BodyDeclaration)ASTNodes.getParent(selectedNodes[0], BodyDeclaration.class);
int maxVariableId= LocalVariableIndex.perform(enclosingBodyDeclaration) + 1;
fIsNewContext= isNewContext();
- List<VariableDeclarationFragment> accessedAfter= getVariableDeclarationsAccessedAfter(selectedStatements[selectedStatements.length - 1], maxVariableId);
+ List<VariableDeclarationFragment> accessedAfter= getVariableDeclarationsAccessedAfter(selectedNodes[selectedNodes.length - 1], maxVariableId);
List<VariableDeclaration> readInside;
- readInside= getVariableDeclarationReadsInside(selectedStatements, maxVariableId);
+ readInside= getVariableDeclarationReadsInside(selectedNodes, maxVariableId);
List<ASTNode> inserted= new ArrayList<>();
- moveToBlock(selectedStatements, inserted, accessedAfter, readInside, rewrite);
+ moveToBlock(selectedNodes, inserted, accessedAfter, readInside, rewrite);
if (fIsNewContext) {
- ImportRewrite importRewrite= StubUtility.createImportRewrite((CompilationUnit)selectedStatements[0].getRoot(), false);
- ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(selectedStatements[0], importRewrite);
- for (int i= 0; i < selectedStatements.length; i++) {
- qualifyThisExpressions(selectedStatements[i], rewrite, importRewrite, importRewriteContext);
+ ImportRewrite importRewrite= StubUtility.createImportRewrite((CompilationUnit)selectedNodes[0].getRoot(), false);
+ ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(selectedNodes[0], importRewrite);
+ for (int i= 0; i < selectedNodes.length; i++) {
+ qualifyThisExpressions(selectedNodes[i], rewrite, importRewrite, importRewriteContext);
}
}
- if (selectedStatements.length == 1 && ASTNodes.isControlStatementBody(selectedStatements[0].getLocationInParent())) {
+ if (selectedNodes.length == 1 && ASTNodes.isControlStatementBody(selectedNodes[0].getLocationInParent())) {
Block wrap= ast.newBlock();
- rewrite.replace(selectedStatements[0], wrap, null);
+ rewrite.replace(selectedNodes[0], wrap, null);
ListRewrite listRewrite= rewrite.getListRewrite(wrap, Block.STATEMENTS_PROPERTY);
for (Iterator<ASTNode> iterator= inserted.iterator(); iterator.hasNext();) {
@@ -250,9 +250,9 @@
}
} else {
- ListRewrite listRewrite= getListRewrite(selectedStatements[0], rewrite);
+ ListRewrite listRewrite= getListRewrite(selectedNodes[0], rewrite);
- ASTNode current= selectedStatements[selectedStatements.length - 1];
+ ASTNode current= selectedNodes[selectedNodes.length - 1];
for (Iterator<ASTNode> iterator= inserted.iterator(); iterator.hasNext();) {
ASTNode node= iterator.next();
listRewrite.insertAfter(node, current, null);
@@ -279,7 +279,7 @@
* @param selectedNodes The selectedNodes
* @return List of VariableDeclaration
*/
- protected List<VariableDeclaration> getVariableDeclarationReadsInside(Statement[] selectedNodes, int maxVariableId) {
+ protected List<VariableDeclaration> getVariableDeclarationReadsInside(ASTNode[] selectedNodes, int maxVariableId) {
ArrayList<VariableDeclaration> result= new ArrayList<>();
if (!fIsNewContext)
return result;
@@ -364,7 +364,7 @@
}
/**
- * Moves the nodes in toMove to <code>block</block> except the VariableDeclarationFragments
+ * Moves the nodes in toMove to <code>block</code> except the VariableDeclarationFragments
* in <code>accessedAfter</code>. The initializers (if any) of variable declarations
* in <code>accessedAfter</code> are moved to the block if the variable declaration is
* part of <code>toMove</code>. VariableDeclarations in <code>accessedInside</code> are
@@ -382,7 +382,7 @@
* @param accessedInside VariableDeclaration which can be made final
* @param rewrite The rewrite to use.
*/
- private final void moveToBlock(Statement[] toMove, List<ASTNode> statements, final List<VariableDeclarationFragment> accessedAfter, final List<VariableDeclaration> accessedInside, final ASTRewrite rewrite) {
+ private final void moveToBlock(ASTNode[] toMove, List<ASTNode> statements, final List<VariableDeclarationFragment> accessedAfter, final List<VariableDeclaration> accessedInside, final ASTRewrite rewrite) {
for (int i= 0; i < toMove.length; i++) {
ASTNode node= toMove[i];
@@ -557,13 +557,9 @@
return getRootNode().getAST();
}
- protected final Statement[] getSelectedStatements() {
- return fSelectedStatements;
- }
-
private CompilationUnit getRootNode() {
- if (fSelectedStatements.length > 0)
- return (CompilationUnit)fSelectedStatements[0].getRoot();
+ if (fSelectedNodes.length > 0)
+ return (CompilationUnit)fSelectedNodes[0].getRoot();
return fRootNode;
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/spelling/CoreSpellingProblem.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/spelling/CoreSpellingProblem.java
index 3ebe95d..3842eda 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/spelling/CoreSpellingProblem.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/spelling/CoreSpellingProblem.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -165,6 +165,11 @@
return true;
}
+ @Override
+ public boolean isInfo() {
+ return false;
+ }
+
/*
* @see org.eclipse.jdt.core.compiler.IProblem#setSourceStart(int)
*/
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/SurroundWithTemplateProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/SurroundWithTemplateProposal.java
index 901ca52..716d8bd 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/SurroundWithTemplateProposal.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/SurroundWithTemplateProposal.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -45,7 +45,6 @@
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.Statement;
import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
@@ -69,14 +68,14 @@
private final IJavaProject fCurrentProject;
private ASTNode fTemplateNode;
- public SurroundWithTemplate(IInvocationContext context, Statement[] selectedNodes, Template template) {
+ public SurroundWithTemplate(IInvocationContext context, ASTNode[] selectedNodes, Template template) {
super(context.getASTRoot(), selectedNodes);
fTemplate= template;
fCurrentProject= context.getCompilationUnit().getJavaProject();
}
@Override
- protected List<VariableDeclaration> getVariableDeclarationReadsInside(Statement[] selectedNodes, int maxVariableId) {
+ protected List<VariableDeclaration> getVariableDeclarationReadsInside(ASTNode[] selectedNodes, int maxVariableId) {
if (isNewContext())
return super.getVariableDeclarationReadsInside(selectedNodes, maxVariableId);
return new ArrayList<>();
@@ -136,17 +135,17 @@
private final ICompilationUnit fCompilationUnit;
private final CompilationUnitContext fContext;
private final Template fTemplate;
- private final Statement[] fSelectedStatements;
+ private final ASTNode[] fSelectedNodes;
private TemplateProposal fProposal;
private IRegion fSelectedRegion;
- public SurroundWithTemplateProposal(ICompilationUnit compilationUnit, Template template, CompilationUnitContext context, IRegion region, Image image, Statement[] selectedStatements) {
+ public SurroundWithTemplateProposal(ICompilationUnit compilationUnit, Template template, CompilationUnitContext context, IRegion region, Image image, ASTNode[] selectedNodes) {
super(template, context, region, image);
fCompilationUnit= compilationUnit;
fTemplate= template;
fContext= context;
fRegion= region;
- fSelectedStatements= selectedStatements;
+ fSelectedNodes= selectedNodes;
}
/*
@@ -244,7 +243,7 @@
private CompilationUnitContext createNewContext(IDocument document) throws CoreException, BadLocationException {
AssistContext invocationContext= new AssistContext(fCompilationUnit, fContext.getStart(), fContext.getEnd() - fContext.getStart());
- SurroundWithTemplate surroundWith= new SurroundWithTemplate(invocationContext, fSelectedStatements, fTemplate);
+ SurroundWithTemplate surroundWith= new SurroundWithTemplate(invocationContext, fSelectedNodes, fTemplate);
Map<String, String> options= fCompilationUnit.getJavaProject().getOptions(true);
surroundWith.getRewrite().rewriteAST(document, options).apply(document);
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/preferences/TemplateContentProvider.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/preferences/TemplateContentProvider.java
deleted file mode 100644
index 4430fb8..0000000
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/preferences/TemplateContentProvider.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jdt.internal.ui.text.template.preferences;
-
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-import org.eclipse.jdt.internal.corext.template.java.TemplateSet;
-
-
-public class TemplateContentProvider implements IStructuredContentProvider {
-
- private TemplateSet fTemplateSet;
-
- /*
- * @see IStructuredContentProvider#getElements(Object)
- */
- @Override
- public Object[] getElements(Object input) {
- return fTemplateSet.getTemplates();
- }
-
- /*
- * @see IContentProvider#inputChanged(Viewer, Object, Object)
- */
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- fTemplateSet= (TemplateSet) newInput;
- }
-
- /*
- * @see IContentProvider#dispose()
- */
- @Override
- public void dispose() {
- fTemplateSet= null;
- }
-
-}
-
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java
index bfd71bd..a2a4e09 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java
@@ -745,6 +745,7 @@
public static String AccessRulesDialog_severity_info_no_link;
public static String AccessRulesDialog_severity_error;
public static String AccessRulesDialog_severity_warning;
+ public static String AccessRulesDialog_severity_info;
public static String AccessRulesDialog_severity_ignore;
public static String AccessRulesDialog_switch_dialog_title;
public static String AccessRulesDialog_switch_dialog_message;
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties
index 5fcb998..3bcc9da 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties
@@ -635,6 +635,7 @@
AccessRulesDialog_severity_info_no_link=<form><p>The problem severities as configured on the ''Error/Warning'' page currently are:</p><p>Discouraged: <b>{0}</b>, Forbidden: <b>{1}</b></p></form>
AccessRulesDialog_severity_error=Error
AccessRulesDialog_severity_warning=Warning
+AccessRulesDialog_severity_info=Info
AccessRulesDialog_severity_ignore=Ignore
AccessRulesDialog_rules_edit=Edi&t...
AccessRulesDialog_rules_down=Do&wn
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/AccessRulesDialog.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/AccessRulesDialog.java
index aae2dc7..1b77f13 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/AccessRulesDialog.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/AccessRulesDialog.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -243,6 +243,8 @@
return NewWizardMessages.AccessRulesDialog_severity_error;
} else if (JavaCore.WARNING.equals(severity)) {
return NewWizardMessages.AccessRulesDialog_severity_warning;
+ } else if (JavaCore.INFO.equals(severity)) {
+ return NewWizardMessages.AccessRulesDialog_severity_info;
} else {
return NewWizardMessages.AccessRulesDialog_severity_ignore;
}