You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2020/12/07 13:19:37 UTC

[GitHub] [jena] fkleedorfer opened a new pull request #882: JENA-2009: Implement Visitor Pattern for SHACL Constraints

fkleedorfer opened a new pull request #882:
URL: https://github.com/apache/jena/pull/882


   Notes:
   * added `visit` method to `Constraint` interface. I experimented with providing a default implementation (calling `visitor.visit(Constraint)`) to avoid having to add an implementation to all implementing classes. This approach does not work, which I did not expect. Learned something about Java method invocation target selection there.
   * added `visit` method non-abstract subclasses of `Constraint`. The pattern suggests they should be named `accept`, but jena uses `visit` wherever I checked. I guess it's better to stick with the existing flavor.
   * Currently no unit tests as there is no logic apart from `visitor.visit(this)`. Please let me know if you feel differently. Using the PR in my client code, so I'm positive it works.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on a change in pull request #882: JENA-2009: Implement Visitor Pattern for SHACL Constraints

Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #882:
URL: https://github.com/apache/jena/pull/882#discussion_r537627200



##########
File path: jena-shacl/src/main/java/org/apache/jena/shacl/parser/ConstraintVisitor.java
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.parser;
+
+import org.apache.jena.shacl.engine.constraint.*;
+
+public interface ConstraintVisitor {
+    default void visit(ReportConstraint constraint){}

Review comment:
       That'll do fine. The validation operations are `throw new UnsupportedOperationException()` but no-op works just as well for the visitor. (I suspect that ReportConstraint shouldn't exist at all! But from memory, passing the information it carries means adding other parameters in many places which even if purer, is verbose.)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on pull request #882: JENA-2009: Implement Visitor Pattern for SHACL Constraints

Posted by GitBox <gi...@apache.org>.
afs commented on pull request #882:
URL: https://github.com/apache/jena/pull/882#issuecomment-739933773


   Please could you put the vitro in a consistent place in the constraints? Just before printCompact would be fine as many of them are there already.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs merged pull request #882: JENA-2009: Implement Visitor Pattern for SHACL Constraints

Posted by GitBox <gi...@apache.org>.
afs merged pull request #882:
URL: https://github.com/apache/jena/pull/882


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] fkleedorfer commented on a change in pull request #882: JENA-2009: Implement Visitor Pattern for SHACL Constraints

Posted by GitBox <gi...@apache.org>.
fkleedorfer commented on a change in pull request #882:
URL: https://github.com/apache/jena/pull/882#discussion_r537560555



##########
File path: jena-shacl/src/main/java/org/apache/jena/shacl/parser/ConstraintVisitor.java
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.parser;
+
+import org.apache.jena.shacl.engine.constraint.*;
+
+public interface ConstraintVisitor {
+    default void visit(ReportConstraint constraint){}

Review comment:
       We must implement `ReportConstraint.visit(ConstraintVisitor)`, though. Empty implementation for minimal friction?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on pull request #882: JENA-2009: Implement Visitor Pattern for SHACL Constraints

Posted by GitBox <gi...@apache.org>.
afs commented on pull request #882:
URL: https://github.com/apache/jena/pull/882#issuecomment-739935821


   I am unsure that default methods on the visitor are the way to go. An abstract class "ConstraintBase" has been the style up until Java8 and now can have a mixin/trait to do the same.
   
   Reason: robustness.
   
   When writing complex visitors it is good to have a way for the programmer to know they have covered all cases and be notified when a new constraint is added. Otherwise it is possible to miss a case and compile time and and it becomes a runtime problem.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org