This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/master by this push:
new b872793 JENA-1782: Better SHACL parse tree printing
new 2438583 Merge pull request #633 from afs/shacl-print
b872793 is described below
commit b872793dd687f3708f73f32bc2cc27b0dc52932f
Author: Andy Seaborne <[email protected]>
AuthorDate: Tue Nov 19 21:25:21 2019 +0000
JENA-1782: Better SHACL parse tree printing
---
.../shacl/engine/constraint/ConstraintOp1.java | 42 ++++++++++++++++++++
.../shacl/engine/constraint/ConstraintOpN.java | 46 ++++++++++++++++++++++
.../apache/jena/shacl/engine/constraint/ShAnd.java | 8 ++--
.../jena/shacl/engine/constraint/ShNode.java | 9 ++---
.../apache/jena/shacl/engine/constraint/ShNot.java | 7 ++--
.../apache/jena/shacl/engine/constraint/ShOr.java | 8 ++--
.../jena/shacl/engine/constraint/ShXone.java | 8 ++--
.../java/org/apache/jena/shacl/parser/Shape.java | 11 ++----
8 files changed, 108 insertions(+), 31 deletions(-)
diff --git
a/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ConstraintOp1.java
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ConstraintOp1.java
new file mode 100644
index 0000000..bafc7e8
--- /dev/null
+++
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ConstraintOp1.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.shacl.engine.constraint;
+
+import org.apache.jena.atlas.io.IndentedWriter;
+import org.apache.jena.shacl.parser.Shape;
+
+/** A constraint that operates on one other constraints */
+public abstract class ConstraintOp1 extends ConstraintOp {
+
+ protected final Shape other;
+
+ protected ConstraintOp1(Shape subShape) {
+ other = subShape;
+ }
+
+ @Override
+ public void print(IndentedWriter out) {
+ out.print(toString());
+ out.ensureStartOfLine();
+ out.incIndent();
+ other.print(out);
+ out.decIndent();
+ out.ensureStartOfLine();
+ }
+}
diff --git
a/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ConstraintOpN.java
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ConstraintOpN.java
new file mode 100644
index 0000000..48c25da
--- /dev/null
+++
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ConstraintOpN.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.shacl.engine.constraint;
+
+import java.util.List;
+
+import org.apache.jena.atlas.io.IndentedWriter;
+import org.apache.jena.shacl.parser.Shape;
+
+/** A constraint that combines N other constraints */
+public abstract class ConstraintOpN extends ConstraintOp {
+
+ protected final List<Shape> others;
+
+ protected ConstraintOpN(List<Shape> subShapes) {
+ others = subShapes;
+ }
+
+ @Override
+ public void print(IndentedWriter out) {
+ out.print(toString());
+ out.ensureStartOfLine();
+ out.incIndent();
+ for ( Shape sub: others ) {
+ sub.print(out);
+ out.ensureStartOfLine();
+ }
+ out.decIndent();
+ }
+}
diff --git
a/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShAnd.java
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShAnd.java
index 85c7047..6b9c66a 100644
---
a/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShAnd.java
+++
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShAnd.java
@@ -31,12 +31,10 @@ import org.apache.jena.shacl.validation.ValidationProc;
import org.apache.jena.shacl.vocabulary.SHACL;
/** sh:and */
-public class ShAnd extends ConstraintOp {
-
- private List<Shape> others;
+public class ShAnd extends ConstraintOpN {
public ShAnd(List<Shape> others) {
- this.others = others;
+ super(others);
}
@Override
@@ -60,6 +58,6 @@ public class ShAnd extends ConstraintOp {
@Override
public String toString() {
- return "And"+others;
+ return "And";
}
}
\ No newline at end of file
diff --git
a/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShNode.java
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShNode.java
index 40d2d45..3a6d45d 100644
---
a/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShNode.java
+++
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShNode.java
@@ -29,11 +29,10 @@ import org.apache.jena.shacl.validation.ValidationProc;
import org.apache.jena.shacl.vocabulary.SHACL;
/** sh:node */
-public class ShNode extends ConstraintOp {
- private Shape other;
-
+public class ShNode extends ConstraintOp1 {
+
public ShNode(Shape other) {
- this.other = other;
+ super(other);
}
@Override
@@ -54,6 +53,6 @@ public class ShNode extends ConstraintOp {
@Override
public String toString() {
- return "Node["+other+"]";
+ return "Node";
}
}
\ No newline at end of file
diff --git
a/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShNot.java
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShNot.java
index 7795040..86cc327 100644
---
a/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShNot.java
+++
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShNot.java
@@ -29,11 +29,10 @@ import org.apache.jena.shacl.validation.ValidationProc;
import org.apache.jena.shacl.vocabulary.SHACL;
/** sh:not */
-public class ShNot extends ConstraintOp {
- private Shape other;
+public class ShNot extends ConstraintOp1 {
public ShNot(Shape other) {
- this.other = other;
+ super(other);
}
@Override
@@ -54,6 +53,6 @@ public class ShNot extends ConstraintOp {
@Override
public String toString() {
- return "Not["+other+"]";
+ return "Not";
}
}
\ No newline at end of file
diff --git
a/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShOr.java
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShOr.java
index 144f1d1..7d6259a 100644
--- a/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShOr.java
+++ b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShOr.java
@@ -31,12 +31,10 @@ import org.apache.jena.shacl.validation.ValidationProc;
import org.apache.jena.shacl.vocabulary.SHACL;
/** sh:or */
-public class ShOr extends ConstraintOp {
-
- private List<Shape> others;
+public class ShOr extends ConstraintOpN {
public ShOr(List<Shape> others) {
- this.others = others;
+ super(others);
}
@Override
@@ -59,6 +57,6 @@ public class ShOr extends ConstraintOp {
@Override
public String toString() {
- return "Or"+others;
+ return "Or";
}
}
\ No newline at end of file
diff --git
a/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShXone.java
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShXone.java
index 8680560..11af8f9 100644
---
a/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShXone.java
+++
b/jena-shacl/src/main/java/org/apache/jena/shacl/engine/constraint/ShXone.java
@@ -31,12 +31,10 @@ import org.apache.jena.shacl.validation.ValidationProc;
import org.apache.jena.shacl.vocabulary.SHACL;
/** sh:xone */
-public class ShXone extends ConstraintOp {
-
- private List<Shape> others;
+public class ShXone extends ConstraintOpN {
public ShXone(List<Shape> others) {
- this.others = others;
+ super(others);
}
@Override
@@ -65,6 +63,6 @@ public class ShXone extends ConstraintOp {
@Override
public String toString() {
- return "Or"+others;
+ return "Xone";
}
}
\ No newline at end of file
diff --git a/jena-shacl/src/main/java/org/apache/jena/shacl/parser/Shape.java
b/jena-shacl/src/main/java/org/apache/jena/shacl/parser/Shape.java
index e1b5925..03fd149 100644
--- a/jena-shacl/src/main/java/org/apache/jena/shacl/parser/Shape.java
+++ b/jena-shacl/src/main/java/org/apache/jena/shacl/parser/Shape.java
@@ -95,12 +95,8 @@ public abstract class Shape {
if ( !(out instanceof BufferedOutputStream) )
out = new BufferedOutputStream(out, 128 * 1024);
IndentedWriter w = new IndentedWriter(out);
- try {
- print(w);
- }
- finally {
- // w.flush();
- }
+ try { print(w); }
+ finally { w.flush(); }
}
protected abstract void printHeader(IndentedWriter out);
@@ -119,7 +115,8 @@ public abstract class Shape {
try {
for ( Constraint c : constraints ) {
c.print(out);
- out.println();
+ if ( ! out.atLineStart() )
+ out.println();
}
for ( PropertyShape ps : getPropertyShapes() ) {
ps.print(out);