This is an automated email from the ASF dual-hosted git repository.

neilcsmith 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 385d2c9  When printing types, print intersection types properly. 
(#1315)
385d2c9 is described below

commit 385d2c92ce020d053db1900b2f38e3a7189f0915
Author: Jan Lahoda <[email protected]>
AuthorDate: Wed Jun 26 12:16:02 2019 +0200

    When printing types, print intersection types properly. (#1315)
    
    * When printing types, print intersection types properly.
    
    * Improving appearance of the intersection types.
---
 .../src/org/netbeans/api/java/source/TypeUtilities.java    | 13 +++++++++++++
 .../org/netbeans/api/java/source/TypeUtilitiesTest.java    | 14 +++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)

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 7093b93..a2b892a 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
@@ -38,6 +38,7 @@ import javax.lang.model.type.ArrayType;
 import javax.lang.model.type.DeclaredType;
 import javax.lang.model.type.ErrorType;
 import javax.lang.model.type.ExecutableType;
+import javax.lang.model.type.IntersectionType;
 import javax.lang.model.type.TypeKind;
 import javax.lang.model.type.TypeMirror;
 import javax.lang.model.type.TypeVariable;
@@ -460,6 +461,18 @@ public final class TypeUtilities {
         }
 
         @Override
+        public StringBuilder visitIntersection(IntersectionType t, Boolean p) {
+            Iterator<? extends TypeMirror> it = t.getBounds().iterator();
+            while (it.hasNext()) {
+                visit(it.next(), p);
+                if (it.hasNext()) {
+                    DEFAULT_VALUE.append(" & ");
+                }
+            }
+            return DEFAULT_VALUE;
+        }
+
+        @Override
         public StringBuilder visitError(ErrorType t, Boolean p) {
             Element e = t.asElement();
             if (e instanceof TypeElement) {
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 79d64ae..2aa1900 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
@@ -18,6 +18,12 @@
  */
 package org.netbeans.api.java.source;
 
+import com.sun.source.tree.BlockTree;
+import com.sun.source.tree.ClassTree;
+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 java.io.File;
 import java.io.IOException;
 import java.net.URL;
@@ -125,7 +131,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 
{}");
+        TestUtilities.copyStringToFile(src, "package test; public class Test { 
{ get().run(); } private <Z extends Exception&Runnable> Z get() { return null; 
} }");
         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>() {
@@ -136,6 +142,12 @@ 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));
             }
         }, 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

Reply via email to