This is an automated email from the ASF dual-hosted git repository.
matthiasblaesing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new b2dbf811bd [3803]Fixing printing of type names for captured types with
type variables.
new a6433d1de9 Merge pull request #3877 from jlahoda/3803
b2dbf811bd is described below
commit b2dbf811bd78ddbfbcab2f6cec595917e50dcb43
Author: Jan Lahoda <[email protected]>
AuthorDate: Sun Mar 27 13:41:50 2022 +0200
[3803]Fixing printing of type names for captured types with type variables.
---
.../netbeans/modules/editor/java/AutoImport.java | 2 --
.../editor/java/JavaCodeTemplateProcessorTest.java | 22 ++++++++++++++++++++++
.../netbeans/api/java/source/TypeUtilities.java | 2 --
.../api/java/source/TypeUtilitiesTest.java | 13 ++++++++++++-
4 files changed, 34 insertions(+), 5 deletions(-)
diff --git
a/java/java.editor/src/org/netbeans/modules/editor/java/AutoImport.java
b/java/java.editor/src/org/netbeans/modules/editor/java/AutoImport.java
index e365ded940..07dd17bd49 100644
--- a/java/java.editor/src/org/netbeans/modules/editor/java/AutoImport.java
+++ b/java/java.editor/src/org/netbeans/modules/editor/java/AutoImport.java
@@ -144,8 +144,6 @@ public class AutoImport extends SimpleTypeVisitor6<Void,
Void> {
bound = type.getUpperBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
builder.append(" extends "); //NOI18N
- if (bound.getKind() == TypeKind.TYPEVAR)
- bound = ((TypeVariable)bound).getLowerBound();
visit(bound);
}
}
diff --git
a/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/JavaCodeTemplateProcessorTest.java
b/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/JavaCodeTemplateProcessorTest.java
index e4843ca98b..4313b46eb9 100644
---
a/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/JavaCodeTemplateProcessorTest.java
+++
b/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/JavaCodeTemplateProcessorTest.java
@@ -203,6 +203,28 @@ public class JavaCodeTemplateProcessorTest extends
NbTestCase {
"}");
}
+ public void testInfiteLoop() throws Exception {
+ doTestTemplateInsert("for (${IT_TYPE rightSideType
type=\"java.util.Iterator\" default=\"Iterator\" editable=false} ${IT
newVarName default=\"it\"} = ${COL instanceof=\"java.util.Collection\"
default=\"col\"}.iterator(); ${IT}.hasNext();) {\n" +
+ " ${TYPE rightSideType default=\"Object\"}
${ELEM newVarName default=\"elem\"} = ${TYPE_CAST cast default=\"\"
editable=false}${IT}.next();\n" +
+ " ${selection}${cursor}\n" +
+ "}\n",
+ "import java.util.Collection;\n" +
+ "public class Test<E> {\n" +
+ " private void t(Collection<? extends E> c)
{\n" +
+ " |\n" +
+ " }\n" +
+ "}",
+ "import java.util.Collection;\n" +
+ "public class Test<E> {\n" +
+ " private void t(Collection<? extends E> c)
{\n" +
+ " for (Iterator<? extends E> iterator| =
c.iterator(); iterator.hasNext();) {\n" +
+ " E next = iterator.next();\n" +
+ " \n" +
+ " }\n" +
+ " }\n" +
+ "}");
+ }
+
private void assertFileObjectTextMatchesRegex(String regex) throws
IOException {
String text = testFile.asText();
assertTrue("The file text must match the regular expression",
text.matches(regex));
diff --git
a/java/java.source.base/src/org/netbeans/api/java/source/TypeUtilities.java
b/java/java.source.base/src/org/netbeans/api/java/source/TypeUtilities.java
index a2b892adf5..0c8071efca 100644
--- a/java/java.source.base/src/org/netbeans/api/java/source/TypeUtilities.java
+++ b/java/java.source.base/src/org/netbeans/api/java/source/TypeUtilities.java
@@ -424,8 +424,6 @@ public final class TypeUtilities {
bound = t.getUpperBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
DEFAULT_VALUE.append(" extends "); //NOI18N
- if (bound.getKind() == TypeKind.TYPEVAR)
- bound = ((TypeVariable)bound).getLowerBound();
visit(bound, p);
}
}
diff --git
a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/TypeUtilitiesTest.java
b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/TypeUtilitiesTest.java
index 2aa1900f82..fcf99f71c0 100644
---
a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/TypeUtilitiesTest.java
+++
b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/TypeUtilitiesTest.java
@@ -24,6 +24,7 @@ import com.sun.source.tree.ExpressionStatementTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.MethodInvocationTree;
+import com.sun.source.tree.MethodTree;
import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -131,7 +132,7 @@ public class TypeUtilitiesTest extends NbTestCase {
public void testTypeName() throws Exception {
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
FileObject src = root.createData("Test.java");
- TestUtilities.copyStringToFile(src, "package test; public class Test {
{ get().run(); } private <Z extends Exception&Runnable> Z get() { return null;
} }");
+ TestUtilities.copyStringToFile(src, "package test; public class Test {
{ get().run(); } private <Z extends Exception&Runnable> Z get() { return null;
} } class C<E> { C<? extends E> get() { get(); }");
JavaSource js =
JavaSource.create(ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new
URL[0])), ClassPathSupport.createClassPath(new URL[0]),
ClassPathSupport.createClassPath(new URL[0])), src);
js.runUserActionTask(new Task<CompilationController>() {
@@ -142,12 +143,22 @@ public class TypeUtilitiesTest extends NbTestCase {
assertEquals("List<String>[]",
info.getTypeUtilities().getTypeName(info.getTreeUtilities().parseType("java.util.List<java.lang.String>[]",
context)));
assertEquals("java.util.List<java.lang.String>...",
info.getTypeUtilities().getTypeName(info.getTreeUtilities().parseType("java.util.List<java.lang.String>[]",
context), TypeUtilities.TypeNameOptions.PRINT_FQN,
TypeUtilities.TypeNameOptions.PRINT_AS_VARARG));
assertEquals("List<String>...",
info.getTypeUtilities().getTypeName(info.getTreeUtilities().parseType("java.util.List<java.lang.String>[]",
context), TypeUtilities.TypeNameOptions.PRINT_AS_VARARG));
+ {
ClassTree clazz = (ClassTree)
info.getCompilationUnit().getTypeDecls().get(0);
BlockTree init = (BlockTree) clazz.getMembers().get(1);
ExpressionStatementTree var = (ExpressionStatementTree)
init.getStatements().get(0);
ExpressionTree getInvocation = ((MemberSelectTree)
((MethodInvocationTree) var.getExpression()).getMethodSelect()).getExpression();
TypeMirror intersectionType =
info.getTrees().getTypeMirror(info.getTrees().getPath(info.getCompilationUnit(),
getInvocation));
assertEquals("Exception & Runnable",
info.getTypeUtilities().getTypeName(intersectionType));
+ }
+ {
+ ClassTree clazz = (ClassTree)
info.getCompilationUnit().getTypeDecls().get(1);
+ MethodTree mt = (MethodTree) clazz.getMembers().get(1);
+ ExpressionStatementTree var = (ExpressionStatementTree)
mt.getBody().getStatements().get(0);
+ ExpressionTree getInvocation = var.getExpression();
+ TypeMirror captureType =
info.getTrees().getTypeMirror(info.getTrees().getPath(info.getCompilationUnit(),
getInvocation));
+ assertEquals("C<? extends E>",
info.getTypeUtilities().getTypeName(captureType));
+ }
}
}, true);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists