From 3c903db4eff1aa3138f26b08cf0181b0a45f045a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Thu, 29 Apr 2021 22:19:24 +0200 Subject: [PATCH] add substitutor visitor --- .travis.yml | 7 - config/checkstyle/checkstyle.xml | 327 ------------------ config/checkstyle/suppressions.xml | 7 - cql-common/config/checkstyle/checkstyle.xml | 327 ------------------ cql-common/config/checkstyle/suppressions.xml | 7 - .../main/java/org/xbib/cql/CQLGenerator.java | 87 +++-- .../src/main/java/org/xbib/cql/Index.java | 13 +- .../java/org/xbib/cql/model/package-info.java | 4 - .../main/java/org/xbib/cql/package-info.java | 4 - .../config/checkstyle/checkstyle.xml | 327 ------------------ .../config/checkstyle/suppressions.xml | 7 - gradle.properties | 4 +- 12 files changed, 65 insertions(+), 1056 deletions(-) delete mode 100644 .travis.yml delete mode 100644 config/checkstyle/checkstyle.xml delete mode 100644 config/checkstyle/suppressions.xml delete mode 100644 cql-common/config/checkstyle/checkstyle.xml delete mode 100644 cql-common/config/checkstyle/suppressions.xml delete mode 100644 cql-common/src/main/java/org/xbib/cql/model/package-info.java delete mode 100644 cql-common/src/main/java/org/xbib/cql/package-info.java delete mode 100644 cql-elasticsearch/config/checkstyle/checkstyle.xml delete mode 100644 cql-elasticsearch/config/checkstyle/suppressions.xml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 57000f7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -sudo: false -language: java -jdk: - - oraclejdk8 -cache: - directories: - - $HOME/.m2 diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml deleted file mode 100644 index 20fd3f0..0000000 --- a/config/checkstyle/checkstyle.xml +++ /dev/null @@ -1,327 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml deleted file mode 100644 index 9b7e458..0000000 --- a/config/checkstyle/suppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/cql-common/config/checkstyle/checkstyle.xml b/cql-common/config/checkstyle/checkstyle.xml deleted file mode 100644 index 42d1e17..0000000 --- a/cql-common/config/checkstyle/checkstyle.xml +++ /dev/null @@ -1,327 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cql-common/config/checkstyle/suppressions.xml b/cql-common/config/checkstyle/suppressions.xml deleted file mode 100644 index 9b7e458..0000000 --- a/cql-common/config/checkstyle/suppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/cql-common/src/main/java/org/xbib/cql/CQLGenerator.java b/cql-common/src/main/java/org/xbib/cql/CQLGenerator.java index a6e001f..c3bfdf8 100644 --- a/cql-common/src/main/java/org/xbib/cql/CQLGenerator.java +++ b/cql-common/src/main/java/org/xbib/cql/CQLGenerator.java @@ -15,23 +15,18 @@ public final class CQLGenerator implements Visitor { */ private CQLQueryModel model; - /** - * A replacement string. - */ - private String replacementString; - - /** - * String to be replaced. - */ - private String stringToBeReplaced; + private Visitor substitutor; public CQLGenerator() { - this.replacementString = null; - this.stringToBeReplaced = null; this.model = new CQLQueryModel(); } - public CQLGenerator model(CQLQueryModel model) { + public CQLGenerator setSubstitutor(Visitor substitutor) { + this.substitutor = substitutor; + return this; + } + + public CQLGenerator setModel(CQLQueryModel model) { this.model = model; return this; } @@ -46,6 +41,9 @@ public final class CQLGenerator implements Visitor { @Override public void visit(SortedQuery node) { + if (substitutor != null) { + substitutor.visit(node); + } if (node.getSortSpec() != null) { node.getSortSpec().accept(this); } @@ -57,6 +55,9 @@ public final class CQLGenerator implements Visitor { @Override public void visit(Query node) { + if (substitutor != null) { + substitutor.visit(node); + } if (node.getPrefixAssignments() != null) { for (PrefixAssignment assignment : node.getPrefixAssignments()) { assignment.accept(this); @@ -72,6 +73,9 @@ public final class CQLGenerator implements Visitor { @Override public void visit(SortSpec node) { + if (substitutor != null) { + substitutor.visit(node); + } if (node.getSingleSpec() != null) { node.getSingleSpec().accept(this); } @@ -82,6 +86,9 @@ public final class CQLGenerator implements Visitor { @Override public void visit(SingleSpec node) { + if (substitutor != null) { + substitutor.visit(node); + } if (node.getIndex() != null) { node.getIndex().accept(this); } @@ -92,12 +99,18 @@ public final class CQLGenerator implements Visitor { @Override public void visit(PrefixAssignment node) { + if (substitutor != null) { + substitutor.visit(node); + } node.getPrefix().accept(this); node.getURI().accept(this); } @Override public void visit(ScopedClause node) { + if (substitutor != null) { + substitutor.visit(node); + } if (node.getScopedClause() != null) { node.getScopedClause().accept(this); } @@ -112,6 +125,9 @@ public final class CQLGenerator implements Visitor { @Override public void visit(BooleanGroup node) { + if (substitutor != null) { + substitutor.visit(node); + } if (node.getModifierList() != null) { node.getModifierList().accept(this); } @@ -119,6 +135,9 @@ public final class CQLGenerator implements Visitor { @Override public void visit(SearchClause node) { + if (substitutor != null) { + substitutor.visit(node); + } if (node.getQuery() != null) { node.getQuery().accept(this); } @@ -146,6 +165,9 @@ public final class CQLGenerator implements Visitor { @Override public void visit(Relation node) { + if (substitutor != null) { + substitutor.visit(node); + } if (node.getModifierList() != null) { node.getModifierList().accept(this); } @@ -153,6 +175,9 @@ public final class CQLGenerator implements Visitor { @Override public void visit(Modifier node) { + if (substitutor != null) { + substitutor.visit(node); + } if (node.getTerm() != null) { node.getTerm().accept(this); } @@ -163,48 +188,40 @@ public final class CQLGenerator implements Visitor { @Override public void visit(ModifierList node) { + if (substitutor != null) { + substitutor.visit(node); + } for (Modifier modifier : node.getModifierList()) { modifier.accept(this); } } @Override - public synchronized void visit(Term node) { - if (replacementString != null && stringToBeReplaced.equals(node.getValue())) { - node.setValue(replacementString); + public void visit(Term node) { + if (substitutor != null) { + substitutor.visit(node); } } @Override public void visit(Identifier node) { + if (substitutor != null) { + substitutor.visit(node); + } } @Override public void visit(SimpleName node) { + if (substitutor != null) { + substitutor.visit(node); + } } @Override public void visit(Index node) { - } - - /** - * Write a substitution query, for example when a term has been - * suggested to be replaced by another term. - * - * @param oldTerm the term to be replaced - * @param newTerm the replacement term - * @return the new query with the term replaced - */ - public synchronized String writeSubstitutedForm(String oldTerm, String newTerm) { - this.stringToBeReplaced = oldTerm; - this.replacementString = newTerm; - CQLParser parser = new CQLParser(model.getQuery()); - parser.parse(); - parser.getCQLQuery().accept(this); - String result = model.getQuery(); - this.stringToBeReplaced = null; - this.replacementString = null; - return result; + if (substitutor != null) { + substitutor.visit(node); + } } public String withBreadcrumbs() { diff --git a/cql-common/src/main/java/org/xbib/cql/Index.java b/cql-common/src/main/java/org/xbib/cql/Index.java index 4d60850..59c0edf 100644 --- a/cql-common/src/main/java/org/xbib/cql/Index.java +++ b/cql-common/src/main/java/org/xbib/cql/Index.java @@ -8,8 +8,13 @@ package org.xbib.cql; public class Index extends AbstractNode { private String context; + private String name; + public Index(SimpleName name) { + this(name.getName()); + } + public Index(String name) { this.name = name; int pos = name.indexOf('.'); @@ -19,8 +24,8 @@ public class Index extends AbstractNode { } } - public Index(SimpleName name) { - this(name.getName()); + public void setContext(String context) { + this.context = context; } /** @@ -30,6 +35,10 @@ public class Index extends AbstractNode { return context; } + public void setName(String name) { + this.name = name; + } + /** * Get the name of the index. * diff --git a/cql-common/src/main/java/org/xbib/cql/model/package-info.java b/cql-common/src/main/java/org/xbib/cql/model/package-info.java deleted file mode 100644 index 7723684..0000000 --- a/cql-common/src/main/java/org/xbib/cql/model/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Classes for CQL query modeling. - */ -package org.xbib.cql.model; diff --git a/cql-common/src/main/java/org/xbib/cql/package-info.java b/cql-common/src/main/java/org/xbib/cql/package-info.java deleted file mode 100644 index 30ec662..0000000 --- a/cql-common/src/main/java/org/xbib/cql/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Classes for CQL queries. - */ -package org.xbib.cql; diff --git a/cql-elasticsearch/config/checkstyle/checkstyle.xml b/cql-elasticsearch/config/checkstyle/checkstyle.xml deleted file mode 100644 index 42d1e17..0000000 --- a/cql-elasticsearch/config/checkstyle/checkstyle.xml +++ /dev/null @@ -1,327 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cql-elasticsearch/config/checkstyle/suppressions.xml b/cql-elasticsearch/config/checkstyle/suppressions.xml deleted file mode 100644 index 9b7e458..0000000 --- a/cql-elasticsearch/config/checkstyle/suppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 754af0a..4c5dcd7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ group = org.xbib name = cql -version = 3.0.4 +version = 3.0.5 gradle.wrapper.version = 6.6.1 -xbib-content.version = 2.5.1 +xbib-content.version = 2.6.4