jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1476257 - /jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/FormatterElement.java
Date Fri, 26 Apr 2013 15:34:38 GMT
Author: andy
Date: Fri Apr 26 15:34:37 2013
New Revision: 1476257

URL: http://svn.apache.org/r1476257
Log:
Ensure adjacent triple/path elements have a necessary DOT.

Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/FormatterElement.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/FormatterElement.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/FormatterElement.java?rev=1476257&r1=1476256&r2=1476257&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/FormatterElement.java
(original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/FormatterElement.java
Fri Apr 26 15:34:37 2013
@@ -298,15 +298,6 @@ public class FormatterElement extends Fo
             return ;
         }
 
-//        if ( el.getElements().size() == 1 )
-//        {
-//            if ( el.getElements().get(0) instanceof ElementSubQuery )
-//            {
-//                visit((ElementSubQuery)el.getElements().get(0)) ;
-//                return ;
-//            }
-//        }
-        
         out.print("{") ;
         out.incIndent(INDENT) ;
         if ( GROUP_FIRST_ON_SAME_LINE )
@@ -316,33 +307,47 @@ public class FormatterElement extends Fo
         out.pad() ;
     
         boolean first = true ;
-        
-        for ( Iterator<Element> iter = el.getElements().listIterator() ; iter.hasNext()
;)
+        Element lastElt = null ;
+
+        for ( Element subElement : el.getElements())
         {
-            Element subElement = iter.next() ;
-           if ( ! first )
+            // Some adjacent elements need a DOT:
+            // ElementTriplesBlock, ElementPathBlock
+            if ( ! first )
             {
                 // Need to move on after the last thing printed.
-                if ( GROUP_SEP_DOT )
+                // Check for necessary DOT as separator
+                if ( GROUP_SEP_DOT || needsDotSeparator(lastElt, subElement) )
                     out.print(" . ") ;
                 out.newline() ;    
             }
             subElement.visit(this) ;
             first = false ;
+            lastElt = subElement ;
         }
         out.decIndent(INDENT) ;
-        
+
         // Where to put the closing "}"
         int row2 = out.getRow() ;
         if ( row1 != row2 )
             out.newline() ;
         else
             out.print(' ') ;
-        
+
         // Finally, close the group.
         out.print("}") ;
     }
 
+    private static boolean needsDotSeparator(Element el1, Element el2)
+    {
+        return needsDotSeparator(el1) && needsDotSeparator(el2) ;
+    }
+    
+    private static boolean needsDotSeparator(Element el)
+    {
+        return ( el instanceof ElementTriplesBlock ) || ( el instanceof ElementPathBlock
) ;
+    }
+
     @Override
     public void visit(ElementOptional el)
     {



Mime
View raw message