Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2019-10-03 18:28:05 +0000
committerStephan Herrmann2019-10-03 18:28:05 +0000
commit5ca2ca232f8cb29b05a8a4d67dda881f1f0670a1 (patch)
treecb015f13aee9f8f3aef1367618d5b2752a5c0f37
parent5e4867d6d2b1eaa5536a27398d8170e9a2332730 (diff)
downloadeclipse.jdt.core-5ca2ca232f8cb29b05a8a4d67dda881f1f0670a1.tar.gz
eclipse.jdt.core-5ca2ca232f8cb29b05a8a4d67dda881f1f0670a1.tar.xz
eclipse.jdt.core-5ca2ca232f8cb29b05a8a4d67dda881f1f0670a1.zip
Bug 495475 - [quick fix][dom] Create local variable quickfix fails with
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java34
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java16
2 files changed, 47 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
index 568caf7cb1..995812c7fc 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
@@ -5424,5 +5424,39 @@ public void testLambdaSynthetic() throws JavaModelException {
assertEquals("val$outerArg",synVars[0].getName());
assertEquals("val$outerLocal",synVars[1].getName());
}
+public void testCaptureBinding18() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter18/src/xyz/X.java", true/* resolve */);
+ StringBuilder buf= new StringBuilder();
+ buf.append("package xyz;\n");
+ buf.append("\n");
+ buf.append("import java.util.List;\n");
+ buf.append("\n");
+ buf.append("public class X {\n");
+ buf.append("\n");
+ buf.append(" protected <E extends Comparable<E>> List<E> createEmptySet() {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append("\n");
+ buf.append(" public void emptySet() {\n");
+ buf.append(" s = createEmptySet();\n");
+ buf.append(" }\n");
+ buf.append("\n");
+ buf.append("}");
+ String content= buf.toString();
+ CompilationUnit cu = (CompilationUnit) buildAST(content, this.workingCopy, false /*i.e. ignore errors*/);
+ MethodDeclaration method= ((TypeDeclaration)cu.types().get(0)).getMethods()[1];
+ Assignment assignment= (Assignment) ((ExpressionStatement) method.getBody().statements().get(0)).getExpression();
+ ITypeBinding binding = assignment.getRightHandSide().resolveTypeBinding();
+ assertTrue("main type is parameterized", binding.isParameterizedType());
+ binding = binding.getTypeArguments()[0];
+ assertTrue("treat as wildcard", binding.isWildcardType());
+ assertFalse("don't treat as capture", binding.isCapture());
+ assertTrue("has upper bound", binding.isUpperbound());
+ ITypeBinding[] typeBounds = binding.getTypeBounds();
+ assertEquals("number of bounds", 1, typeBounds.length);
+ ITypeBinding bound = typeBounds[0];
+ assertTrue("bound is parameterized", bound.isParameterizedType());
+ assertEquals("bound's type argument is the original type argument", binding, bound.getTypeArguments()[0]);
+}
}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java
index 6c15ad9293..fd364c11e2 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -27,6 +27,7 @@ import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.CaptureBinding;
+import org.eclipse.jdt.internal.compiler.lookup.CaptureBinding18;
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
import org.eclipse.jdt.internal.compiler.lookup.IntersectionTypeBinding18;
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
@@ -1047,7 +1048,7 @@ class TypeBinding implements ITypeBinding {
@Override
public boolean isCapture() {
- return this.binding.isCapture();
+ return this.binding.isCapture() && !(this.binding instanceof CaptureBinding18);
}
@Override
@@ -1272,13 +1273,22 @@ class TypeBinding implements ITypeBinding {
return ((WildcardBinding) this.binding).boundKind == Wildcard.EXTENDS;
case Binding.INTERSECTION_TYPE :
return true;
+ case Binding.TYPE_PARAMETER:
+ if (this.binding instanceof CaptureBinding18) {
+ CaptureBinding18 captureBinding18 = (CaptureBinding18) this.binding;
+ org.eclipse.jdt.internal.compiler.lookup.TypeBinding upperBound = captureBinding18.upperBound();
+ if (upperBound != null && upperBound.id != TypeIds.T_JavaLangObject) {
+ return true;
+ }
+ }
+ return false;
}
return false;
}
@Override
public boolean isWildcardType() {
- return this.binding.isWildcard();
+ return this.binding.isWildcard() || this.binding instanceof CaptureBinding18;
}
/*

Back to the top