Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2016-05-24 11:42:16 +0000
committerSasikanth Bharadwaj2017-04-12 10:49:56 +0000
commit30b8634488c2a308787d6f4bc05e881c37e80405 (patch)
tree87b8eeb77d97cf76b43a12dfcc1e7265ec921695
parent8e7f77d85abf81407daed23fef4b3a32a6ec4955 (diff)
downloadeclipse.jdt.core-30b8634488c2a308787d6f4bc05e881c37e80405.tar.gz
eclipse.jdt.core-30b8634488c2a308787d6f4bc05e881c37e80405.tar.xz
eclipse.jdt.core-30b8634488c2a308787d6f4bc05e881c37e80405.zip
org.eclipse.jdt.internal.compiler.ast.LambdaExpression$CopyFailureException Change-Id: I7bc73c15ae3754f3c32d1d4ae3faf59ad063ba53
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java92
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java9
2 files changed, 94 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java
index dbb558c8a0..68b596566c 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java
@@ -11,6 +11,7 @@
package org.eclipse.jdt.core.tests.model;
+import java.util.HashMap;
import java.util.Map;
import junit.framework.Test;
@@ -1532,13 +1533,18 @@ public void test430441() throws JavaModelException {
IJavaProject javaProject = getJavaProject("Completion");
Map<String, String> options = javaProject.getOptions(true);
- options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED);
- options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED);
- javaProject.setOptions(options);
+ try {
+ Map<String, String> customOptions = new HashMap<String, String>(options);
+ customOptions.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED);
+ customOptions.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED);
+ javaProject.setOptions(customOptions);
- IEvaluationContext context = javaProject.newEvaluationContext();
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- context.codeComplete(str, cursorLocation, requestor);
+ IEvaluationContext context = javaProject.newEvaluationContext();
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ context.codeComplete(str, cursorLocation, requestor);
+ } finally {
+ javaProject.setOptions(options);
+ }
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430656, [1.8][content assist] Content assist does not work for method reference argument
public void test430656() throws JavaModelException {
@@ -2864,4 +2870,78 @@ public void _test492947d() throws JavaModelException {
"StringBuilder[TYPE_REF]{StringBuilder, java.lang, Ljava.lang.StringBuilder;, null, null, null, null, [139, 148], " + relevance + "}"
, requestor.getResults());
}
+public void testBug493705() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/HelloWorld.java",
+ "package b493705;\n" +
+ "\n" +
+ "import java.util.function.BiFunction;\n" +
+ "\n" +
+ "class Control { }\n" +
+ "class Composite extends Control { }\n" +
+ "class Label extends Control {\n" +
+ " public Label(Composite p, int i) {}\n" +
+ "}\n" +
+ "\n" +
+ "class Viewer { }\n" +
+ "interface ViewerSupplier {\n" +
+ " ViewerUI<? extends Viewer> getViewerUI();\n" +
+ "}\n" +
+ "class ViewerUI<V extends Viewer> extends SwtUI<Control>{\n" +
+ "\n" +
+ "}\n" +
+ "interface ControlSupplier {\n" +
+ " SwtUI<? extends Control> getControlUI();\n" +
+ "}\n" +
+ "class SwtUI<T> {\n" +
+ " public SwtUI<T> child(ControlSupplier supplier) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " public SwtUI<T> child(ViewerSupplier supplier) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " public static <T extends Control> SwtUI<T> create(BiFunction<Composite, Integer, T> ctor) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " public SwtUI<T> text(String text) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ "public class HelloWorld {\n" +
+ " void test(SwtUI<Composite> root) {\n" +
+ " root.child(() -> SwtUI.create(Label::new)\n" +
+ " .text(\"Selection\").\n" +
+ " );\n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, true, true, false);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = ".text(\"Selection\").";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ // TODO: compute relevances
+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED;
+ int relevance2 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED + R_NON_STATIC;
+ assertResults(
+ "create[METHOD_REF]{create(), LSwtUI<LLabel;>;, <T:LControl;>(Ljava.util.function.BiFunction<LComposite;Ljava.lang.Integer;TT;>;)LSwtUI<TT;>;, null, null, create, (ctor), [853, 853], "+relevance1+"}\n" +
+ "new[KEYWORD]{new, null, null, null, null, new, null, [853, 853], "+relevance1+"}\n" +
+ "child[METHOD_REF]{child(), LSwtUI<LLabel;>;, (LControlSupplier;)LSwtUI<LLabel;>;, null, null, child, (supplier), [853, 853], "+relevance2+"}\n" +
+ "child[METHOD_REF]{child(), LSwtUI<LLabel;>;, (LViewerSupplier;)LSwtUI<LLabel;>;, null, null, child, (supplier), [853, 853], "+relevance2+"}\n" +
+ "clone[METHOD_REF]{clone(), Ljava.lang.Object;, ()Ljava.lang.Object;, null, null, clone, null, [853, 853], "+relevance2+"}\n" +
+ "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, null, null, equals, (obj), [853, 853], "+relevance2+"}\n" +
+ "finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, null, null, finalize, null, [853, 853], "+relevance2+"}\n" +
+ "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class<*>;, null, null, getClass, null, [853, 853], "+relevance2+"}\n" +
+ "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, null, null, hashCode, null, [853, 853], "+relevance2+"}\n" +
+ "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, null, null, notify, null, [853, 853], "+relevance2+"}\n" +
+ "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, null, null, notifyAll, null, [853, 853], "+relevance2+"}\n" +
+ "text[METHOD_REF]{text(), LSwtUI<LLabel;>;, (Ljava.lang.String;)LSwtUI<LLabel;>;, null, null, text, (text), [853, 853], "+relevance2+"}\n" +
+ "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, null, null, toString, null, [853, 853], "+relevance2+"}\n" +
+ "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, null, null, wait, null, [853, 853], "+relevance2+"}\n" +
+ "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, null, null, wait, (millis), [853, 853], "+relevance2+"}\n" +
+ "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, null, null, wait, (millis, nanos), [853, 853], "+relevance2+"}"
+ , requestor.getResults());
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
index 2c4620c0b5..63e2c2ca84 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
@@ -944,7 +944,14 @@ public class LambdaExpression extends FunctionalExpression implements IPolyExpre
if (r1.isCompatibleWith(r2, skope))
return true;
- LambdaExpression copy = cachedResolvedCopy(s, true /* any resolved copy is good */, false, null); // we expect a cached copy - otherwise control won't reach here.
+ LambdaExpression copy;
+ try {
+ copy = cachedResolvedCopy(s, true /* any resolved copy is good */, false, null); // we expect a cached copy - otherwise control won't reach here.
+ } catch (CopyFailureException cfe) {
+ if (this.assistNode)
+ return false;
+ throw cfe;
+ }
Expression [] returnExpressions = copy.resultExpressions;
int returnExpressionsLength = returnExpressions == null ? 0 : returnExpressions.length;
if (returnExpressionsLength > 0) {

Back to the top