diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..0172117f
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+esql-checks/src/test/resources/FileHeaderCheck/*.esql text eol=lf
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 00000000..5065747a
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,27 @@
+language: java
+sudo: false
+
+jdk:
+ - oraclejdk8
+
+git:
+ submodules: false
+
+install: true
+script: "mvn clean install -P coverage-per-test"
+matrix:
+ fast_finish: true
+
+cache:
+ directories:
+ - '$HOME/.m2/repository'
+ - '$HOME/maven'
+
+before_cache:
+ - find $HOME/.m2 -name resolver-status.properties -exec rm {} \;
+
+notifications:
+ email: false
+
+after_success:
+ - bash <(curl -s https://codecov.io/bash) -t b5356ca9-9cef-4be3-a67e-013d18ebd73a
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 00000000..ec3290ec
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,13 @@
+# How to contribute
+
+Contributions are welcome!
+
+### 1. GitHub issue
+If you found a bug or have a feature request, you can create a [GitHub issue](https://github.com/EXXETA/sonar-esql-plugin/issues/new).
+
+### 2. Pull Request
+1. Fork it!
+2. Create your feature branch: `git checkout -b my-new-feature`
+3. Commit your changes: `git commit -am 'Add some feature'`
+4. Push to the branch: `git push origin my-new-feature`
+5. Submit a pull request
diff --git a/README.md b/README.md
index 516ea0a2..8eb33c49 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,14 @@
-sonar-esql-plugin
-=================
+# sonar-esql-plugin [![Build Status](https://travis-ci.org/EXXETA/sonar-esql-plugin.svg)](https://travis-ci.org/EXXETA/sonar-esql-plugin) [![codecov](https://codecov.io/gh/EXXETA/sonar-esql-plugin/branch/develop/graph/badge.svg)](https://codecov.io/gh/EXXETA/sonar-esql-plugin)
+
This open source plugin can be used to analyze the ESQL-sourcecode of IBM Websphere Message Broker / IBM Integration Bus projects.
+## Features
+* \>75 rules
+* Support for Broker 7, 8, 9, 10
+* Metrics (complexity, number of lines, ...)
+* Import of traces as coverage reports
+
## Installation
@@ -11,7 +17,7 @@ This open source plugin can be used to analyze the ESQL-sourcecode of IBM Websph
## Requirements
-- SonarQube 5.6
+- SonarQube 6.7
## Contributing
@@ -24,6 +30,8 @@ This open source plugin can be used to analyze the ESQL-sourcecode of IBM Websph
## History
+- 2.3.0 - Additional rules, upgrade to SonarQube 6.7, copy paste detector
+- 2.2.0 - Code coverage analysis
- 2.1.0 - A few bugfixes and a lot more checks/rules
- 2.0.0 - complete refactoring and upgrade to SonarQube 5.6
- 1.1.0 - Fix issues #7(https://github.com/EXXETA/sonar-esql-plugin/issues/7) and #8(https://github.com/EXXETA/sonar-esql-plugin/issues/8)
diff --git a/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/1.1.1/sonar-msgflow-plugin-1.1.1.jar b/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/1.1.1/sonar-msgflow-plugin-1.1.1.jar
new file mode 100644
index 00000000..c31c2716
Binary files /dev/null and b/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/1.1.1/sonar-msgflow-plugin-1.1.1.jar differ
diff --git a/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/1.1.1/sonar-msgflow-plugin-1.1.1.pom b/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/1.1.1/sonar-msgflow-plugin-1.1.1.pom
new file mode 100644
index 00000000..79db13f3
--- /dev/null
+++ b/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/1.1.1/sonar-msgflow-plugin-1.1.1.pom
@@ -0,0 +1,9 @@
+
+
+ 4.0.0
+ com.exxeta.iss
+ sonar-msgflow-plugin
+ 1.1.1
+ POM was created from install:install-file
+
diff --git a/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/com/exxeta/iss/sonar-msgflow-plugin/1.1.1/sonar-msgflow-plugin-1.1.1.jar b/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/com/exxeta/iss/sonar-msgflow-plugin/1.1.1/sonar-msgflow-plugin-1.1.1.jar
new file mode 100644
index 00000000..c31c2716
Binary files /dev/null and b/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/com/exxeta/iss/sonar-msgflow-plugin/1.1.1/sonar-msgflow-plugin-1.1.1.jar differ
diff --git a/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/com/exxeta/iss/sonar-msgflow-plugin/1.1.1/sonar-msgflow-plugin-1.1.1.pom b/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/com/exxeta/iss/sonar-msgflow-plugin/1.1.1/sonar-msgflow-plugin-1.1.1.pom
new file mode 100644
index 00000000..79db13f3
--- /dev/null
+++ b/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/com/exxeta/iss/sonar-msgflow-plugin/1.1.1/sonar-msgflow-plugin-1.1.1.pom
@@ -0,0 +1,9 @@
+
+
+ 4.0.0
+ com.exxeta.iss
+ sonar-msgflow-plugin
+ 1.1.1
+ POM was created from install:install-file
+
diff --git a/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/com/exxeta/iss/sonar-msgflow-plugin/maven-metadata-local.xml b/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/com/exxeta/iss/sonar-msgflow-plugin/maven-metadata-local.xml
new file mode 100644
index 00000000..ddd3ac74
--- /dev/null
+++ b/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/com/exxeta/iss/sonar-msgflow-plugin/maven-metadata-local.xml
@@ -0,0 +1,12 @@
+
+
+ com.exxeta.iss
+ sonar-msgflow-plugin
+
+ 1.1.1
+
+ 1.1.1
+
+ 20171228051943
+
+
diff --git a/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/maven-metadata-local.xml b/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/maven-metadata-local.xml
new file mode 100644
index 00000000..f79c4961
--- /dev/null
+++ b/dependency-repo/com/exxeta/iss/sonar-msgflow-plugin/maven-metadata-local.xml
@@ -0,0 +1,12 @@
+
+
+ com.exxeta.iss
+ sonar-msgflow-plugin
+
+ 1.1.1
+
+ 1.1.1
+
+ 20171228051927
+
+
diff --git a/esql-checks-test/pom.xml b/esql-checks-test/pom.xml
index 7af166bd..716c2d7a 100644
--- a/esql-checks-test/pom.xml
+++ b/esql-checks-test/pom.xml
@@ -3,7 +3,7 @@
com.exxeta.isssonar-esql-plugin
- 2.2.0
+ 2.3.04.0.0
diff --git a/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/EsqlCheckVerifier.java b/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/EsqlCheckVerifier.java
index e51f2b7b..638e2f6d 100644
--- a/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/EsqlCheckVerifier.java
+++ b/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/EsqlCheckVerifier.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -63,11 +63,11 @@ public static CheckMessagesVerifier issues(EsqlCheck check, File file) {
* source file where you expect an issue. For example:
*
*
- * var x = 1; -- Noncompliant {{A message for this line.}}
+ * SET x = 1; -- Noncompliant {{A message for this line.}}
*
- * function foo() { -- Noncompliant [[effortToFix=2]] [[secondary=+0,+1]]
- * -- [[sc=5;ec=6;el=+0]]
- * }
+ * function foo() BEGIN -- Noncompliant [[effortToFix=2]] [[secondary=+0,+1]]
+ * -- [[sc=5;ec=6;el=+0]]
+ * END
*
*
* How to write these comments:
diff --git a/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/ExpectedIssuesParser.java b/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/ExpectedIssuesParser.java
index 1b157cd2..1ca1e5e2 100644
--- a/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/ExpectedIssuesParser.java
+++ b/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/ExpectedIssuesParser.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,6 +17,12 @@
*/
package com.exxeta.iss.sonar.esql.checks.verifier;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.annotation.Nullable;
+
import com.exxeta.iss.sonar.esql.api.tree.Tree;
import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken;
@@ -24,10 +30,7 @@
import com.exxeta.iss.sonar.esql.api.visitors.EsqlVisitorContext;
import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitorCheck;
import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableList;
-import java.util.ArrayList;
-import java.util.List;
-import javax.annotation.Nullable;
+import com.google.common.collect.ImmutableSet;
class ExpectedIssuesParser extends SubscriptionVisitorCheck {
@@ -43,8 +46,8 @@ static List parseExpectedIssues(EsqlVisitorContext context) {
}
@Override
- public List nodesToVisit() {
- return ImmutableList.of(Kind.TOKEN);
+ public Set nodesToVisit() {
+ return ImmutableSet.of(Kind.TOKEN);
}
@Override
diff --git a/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TestIssue.java b/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TestIssue.java
index 792a98da..eee4d80b 100644
--- a/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TestIssue.java
+++ b/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TestIssue.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TestUtils.java b/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TestUtils.java
index 4b5c135e..4facd338 100644
--- a/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TestUtils.java
+++ b/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TestUtils.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,8 +17,6 @@
*/
package com.exxeta.iss.sonar.esql.checks.verifier;
-import static com.exxeta.iss.sonar.esql.compat.CompatibilityHelper.wrap;
-
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
@@ -27,8 +25,8 @@
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
+import org.sonar.api.config.internal.MapSettings;
import com.exxeta.iss.sonar.esql.api.tree.ProgramTree;
import com.exxeta.iss.sonar.esql.api.tree.Tree;
@@ -58,15 +56,16 @@ public static EsqlVisitorContext createParallelContext(InputFile file) {
private static EsqlVisitorContext createContext(InputFile file, ActionParser parser) {
try {
ProgramTree programTree = (ProgramTree) parser.parse(file.contents());
- return new EsqlVisitorContext(programTree, wrap(file), settings());
+ return new EsqlVisitorContext(programTree,file, new MapSettings().asConfig());
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
public static DefaultInputFile createTestInputFile(String baseDir, String relativePath) {
- return new DefaultInputFile("module1", relativePath).setModuleBaseDir(Paths.get(baseDir))
- .setLanguage("esql").setCharset(StandardCharsets.UTF_8).setType(InputFile.Type.MAIN);
+ return new TestInputFileBuilder("module1", relativePath).setModuleBaseDir(Paths.get(baseDir))
+ .setLanguage("esql").setCharset(StandardCharsets.UTF_8).setType(InputFile.Type.MAIN)
+ .build();
}
public static DefaultInputFile createTestInputFile(File baseDir, String relativePath) {
@@ -78,13 +77,9 @@ public static DefaultInputFile createTestInputFile(String relativePath) {
}
public static DefaultInputFile createTestInputFile(File baseDir, String relativePath, Charset charset) {
- return new DefaultInputFile(baseDir.getAbsolutePath(), relativePath)
- .setModuleBaseDir(Paths.get(baseDir.getAbsolutePath())).setLanguage("esql").setCharset(charset);
+ return new TestInputFileBuilder(baseDir.getAbsolutePath(), relativePath)
+ .setModuleBaseDir(Paths.get(baseDir.getAbsolutePath())).setLanguage("esql").setCharset(charset)
+ .build();
}
- private static Settings settings() {
- Settings settings = new MapSettings();
-
- return settings;
- }
}
diff --git a/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TreeCheckTest.java b/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TreeCheckTest.java
index 19560d10..a4c9579a 100644
--- a/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TreeCheckTest.java
+++ b/esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TreeCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks-test/src/test/java/com/exxeta/iss/sonar/esql/checks/verifier/EsqlCheckVerifierTest.java b/esql-checks-test/src/test/java/com/exxeta/iss/sonar/esql/checks/verifier/EsqlCheckVerifierTest.java
index 93ebd0a0..599914fb 100644
--- a/esql-checks-test/src/test/java/com/exxeta/iss/sonar/esql/checks/verifier/EsqlCheckVerifierTest.java
+++ b/esql-checks-test/src/test/java/com/exxeta/iss/sonar/esql/checks/verifier/EsqlCheckVerifierTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/pom.xml b/esql-checks/pom.xml
index c869b85a..fa306c02 100644
--- a/esql-checks/pom.xml
+++ b/esql-checks/pom.xml
@@ -1,48 +1,65 @@
-
- 4.0.0
+
+ 4.0.0com.exxeta.isssonar-esql-plugin
- 2.2.0
+ 2.3.0
- esql-checks
+ esql-checks
- ESQL :: Checks
+ ESQL :: Checks
+
+
+
+ org.sonarsource.sslr-squid-bridge
+ sslr-squid-bridge
+
+
+ ${project.groupId}
+ esql-frontend
+
+
+ org.sonarsource.sonarqube
+ sonar-plugin-api
+
+
+ junit
+ junit
+
+
+ org.assertj
+ assertj-core
+
+
+ org.slf4j
+ slf4j-api
+
+
+ ${project.groupId}
+ sonar-msgflow-plugin
+
+
+ ${project.groupId}
+ esql-checks-test
+ test
+
+
+ commons-io
+ commons-io
+ test
+
+
+
+
+
+ local-dependency-repo
+ file://${project.basedir}/../dependency-repo
+
+
-
-
- org.sonarsource.sslr-squid-bridge
- sslr-squid-bridge
-
-
- ${project.groupId}
- esql-frontend
-
-
- org.sonarsource.sonarqube
- sonar-plugin-api
-
-
- junit
- junit
-
-
- org.assertj
- assertj-core
-
-
- ${project.groupId}
- esql-checks-test
- test
-
-
- commons-io
- commons-io
- test
-
-
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/AbstractDoNotUseFunctinCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/AbstractDoNotUseFunctionCheck.java
similarity index 61%
rename from esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/AbstractDoNotUseFunctinCheck.java
rename to esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/AbstractDoNotUseFunctionCheck.java
index c11b9bb7..5d7d680c 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/AbstractDoNotUseFunctinCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/AbstractDoNotUseFunctionCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,22 +17,32 @@
*/
package com.exxeta.iss.sonar.esql.check;
+import java.util.List;
+
import com.exxeta.iss.sonar.esql.api.tree.expression.CallExpressionTree;
import com.exxeta.iss.sonar.esql.api.tree.expression.IdentifierTree;
import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
-public abstract class AbstractDoNotUseFunctinCheck extends DoubleDispatchVisitorCheck{
+public abstract class AbstractDoNotUseFunctionCheck extends DoubleDispatchVisitorCheck{
- public abstract String getMessage();
- public abstract String getFunctionName();
+ public abstract String getMessage(String functionName);
+ public abstract List getFunctionNames();
@Override
public void visitCallExpression(CallExpressionTree tree) {
if (tree.functionName() instanceof IdentifierTree
- && getFunctionName().equalsIgnoreCase(((IdentifierTree)tree.functionName()).name())){
- addIssue(tree.functionName(), getMessage());
+ && isDoNotUseFunction(((IdentifierTree)tree.functionName()).name())){
+ addIssue(tree.functionName(), getMessage(((IdentifierTree)tree.functionName()).name().toUpperCase()));
}
super.visitCallExpression(tree);
}
+ private boolean isDoNotUseFunction(String name) {
+ for (String functionName : getFunctionNames()){
+ if (functionName.equalsIgnoreCase(name)){
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/AbstractPassthruCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/AbstractPassthruCheck.java
new file mode 100644
index 00000000..8493476e
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/AbstractPassthruCheck.java
@@ -0,0 +1,66 @@
+package com.exxeta.iss.sonar.esql.check;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.exxeta.iss.sonar.esql.api.tree.ProgramTree;
+import com.exxeta.iss.sonar.esql.api.tree.Tree;
+import com.exxeta.iss.sonar.esql.api.tree.function.PassthruFunctionTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.PassthruStatementTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.tree.expression.LiteralTree;
+
+public abstract class AbstractPassthruCheck extends DoubleDispatchVisitorCheck{
+
+ private Map> passthruStack = new HashMap<>();
+ Tree currentPassthru = null;
+
+
+
+ @Override
+ public void visitProgram(ProgramTree tree) {
+ passthruStack.clear();
+ currentPassthru=null;
+ super.visitProgram(tree);
+ }
+
+
+ @Override
+ public void visitPassthruStatement(PassthruStatementTree tree) {
+ Tree prevPassthru = currentPassthru;
+ currentPassthru = tree;
+ passthruStack.put(tree,new ArrayList<>());
+ super.visitPassthruStatement(tree);
+ List literals = passthruStack.remove(tree);
+ checkLiterals(tree, literals);
+ currentPassthru=prevPassthru;
+ }
+
+ @Override
+ public void visitPassthruFunction(PassthruFunctionTree tree) {
+ Tree prevPassthru = currentPassthru;
+ currentPassthru = tree;
+ passthruStack.put(tree,new ArrayList<>());
+ super.visitPassthruFunction(tree);
+ List literals = passthruStack.remove(tree);
+ checkLiterals(tree, literals);
+ currentPassthru=prevPassthru;
+
+ }
+
+ protected abstract void checkLiterals(Tree tree, List literals) ;
+
+
+ @Override
+ public void visitLiteral(LiteralTree tree) {
+ if (currentPassthru!=null){
+ passthruStack.get(currentPassthru).add(tree);
+ }
+ super.visitLiteral(tree);
+ }
+
+
+
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BinaryOperatorSeparatedBySpaceCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BinaryOperatorSeparatedBySpaceCheck.java
new file mode 100644
index 00000000..2f5d85b9
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BinaryOperatorSeparatedBySpaceCheck.java
@@ -0,0 +1,96 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.Tree;
+import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
+import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken;
+import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitorCheck;
+import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * This Java class is created to implement the logic for all binary operators
+ * should be separated from their operands by spaces.
+ *
+ * @author C50679
+ *
+ */
+@Rule(key = "BinaryOperatorSeparatedBySpace")
+public class BinaryOperatorSeparatedBySpaceCheck extends SubscriptionVisitorCheck {
+
+ private static final String MESSAGE = "This binary operators should be separated from it's operands by spaces.";
+ private static final String NO_SPACE_AFTER_MESSAGE = "This token should be followed by a space.";
+ private static final List BINARY_OPERATOR = ImmutableList.of("=", ">", "<", "=<", ">=", "<>");
+ private static final List SPACE_AFTER = ImmutableList.of(",");
+
+ @Override
+ public void visitNode(Tree tree) {
+ String token =((InternalSyntaxToken)tree).text();
+ if (BINARY_OPERATOR.contains(token) || SPACE_AFTER.contains(token)) {
+ Iterator childIterator = tree.parent().childrenStream().iterator();
+ Tree prevChild = null;
+ while (childIterator.hasNext()) {
+
+ Tree child = childIterator.next();
+ if (child == tree) {
+ break;
+ }
+ prevChild = child;
+ }
+ Tree nextChild = null;
+ if (childIterator.hasNext()) {
+ nextChild = childIterator.next();
+ }
+ boolean noSpaceBefore = prevChild != null
+ && !isSpaceBetween(prevChild.lastToken(), (InternalSyntaxToken) tree);
+ boolean noSpaceAfter = nextChild != null
+ && !isSpaceBetween((InternalSyntaxToken) tree, nextChild.firstToken());
+ if (BINARY_OPERATOR.contains(token) && (noSpaceAfter || noSpaceBefore)) {
+ addIssue(tree, MESSAGE);
+ } else if (SPACE_AFTER.contains(token) && noSpaceAfter ) {
+ addIssue(tree, NO_SPACE_AFTER_MESSAGE);
+ }
+
+ }
+ super.visitNode(tree);
+ }
+
+ private boolean isSpaceBetween(SyntaxToken firstTree, SyntaxToken secondTree) {
+
+ if (firstTree.endLine() != secondTree.line()) {
+ return true;
+ }
+
+ return firstTree.endColumn() != secondTree.column();
+
+ }
+
+ @Override
+ public Set nodesToVisit() {
+ return ImmutableSet.of(Tree.Kind.TOKEN);
+ }
+
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BlankLineBeforeCommentsCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BlankLineBeforeCommentsCheck.java
new file mode 100644
index 00000000..ee7f5090
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BlankLineBeforeCommentsCheck.java
@@ -0,0 +1,58 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.util.List;
+
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.ProgramTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.EsqlFile;
+import com.exxeta.iss.sonar.esql.api.visitors.LineIssue;
+
+/**
+ * this rule checks if there is a blank line before any block or single line comment.
+ *
+ * @author Sapna Singh
+ *
+ */
+@Rule(key = "BlankLineBeforeComments")
+public class BlankLineBeforeCommentsCheck extends DoubleDispatchVisitorCheck {
+
+ private static final String MESSAGE = "Insert one blank line before this block or single-line comment.";
+
+ @Override
+ public void visitProgram(ProgramTree tree) {
+ EsqlFile file = getContext().getEsqlFile();
+ List lines = CheckUtils.readLines(file);
+
+ for (int i = 0; i < lines.size(); i++) {
+ String currentline = lines.get(i);
+
+ if ((currentline.trim().startsWith("--")) || (currentline.trim().startsWith("/*"))) {
+
+ if (i > 0 && !lines.get(i - 1).trim().isEmpty()) {
+
+ addIssue(new LineIssue(this, i + 1, MESSAGE));
+
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BooleanInversionCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BooleanInversionCheck.java
index 9ee1028a..44117ca6 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BooleanInversionCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BooleanInversionCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,8 +17,8 @@
*/
package com.exxeta.iss.sonar.esql.check;
-import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.sonar.check.Rule;
@@ -31,8 +31,8 @@
import com.exxeta.iss.sonar.esql.api.visitors.PreciseIssue;
import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitorCheck;
import com.exxeta.iss.sonar.esql.tree.SyntacticEquivalence;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
@Rule(key="BooleanInversion")
public class BooleanInversionCheck extends SubscriptionVisitorCheck {
@@ -45,8 +45,8 @@ public class BooleanInversionCheck extends SubscriptionVisitorCheck {
.build();
@Override
- public List nodesToVisit() {
- return ImmutableList.of(Tree.Kind.LOGICAL_COMPLEMENT);
+ public Set nodesToVisit() {
+ return ImmutableSet.of(Tree.Kind.LOGICAL_COMPLEMENT);
}
@Override
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BooleanLiteralCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BooleanLiteralCheck.java
index fba7e9b0..2ef0ae5c 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BooleanLiteralCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BooleanLiteralCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,7 @@
*/
package com.exxeta.iss.sonar.esql.check;
-import java.util.List;
+import java.util.Set;
import org.sonar.check.Rule;
@@ -27,13 +27,13 @@
import com.exxeta.iss.sonar.esql.api.tree.expression.UnaryExpressionTree;
import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitorCheck;
import com.exxeta.iss.sonar.esql.tree.expression.LiteralTree;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
@Rule(key="BooleanLiteral")
public class BooleanLiteralCheck extends SubscriptionVisitorCheck {
@Override
- public List nodesToVisit() {
- return ImmutableList.of(Kind.EQUAL_TO, Kind.NOT_EQUAL_TO, Kind.CONDITIONAL_AND, Kind.CONDITIONAL_OR, Kind.LOGICAL_COMPLEMENT);
+ public Set nodesToVisit() {
+ return ImmutableSet.of(Kind.EQUAL_TO, Kind.NOT_EQUAL_TO, Kind.CONDITIONAL_AND, Kind.CONDITIONAL_OR, Kind.LOGICAL_COMPLEMENT);
}
@Override
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CardinalityInLoopCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CardinalityInLoopCheck.java
index 8ba19b1d..98cbe865 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CardinalityInLoopCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CardinalityInLoopCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,8 +17,12 @@
*/
package com.exxeta.iss.sonar.esql.check;
+import java.util.ArrayList;
+import java.util.List;
+
import org.sonar.check.Rule;
+import com.exxeta.iss.sonar.esql.api.tree.ProgramTree;
import com.exxeta.iss.sonar.esql.api.tree.Tree;
import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
import com.exxeta.iss.sonar.esql.api.tree.expression.IdentifierTree;
@@ -26,13 +30,22 @@
import com.exxeta.iss.sonar.esql.api.tree.statement.RepeatStatementTree;
import com.exxeta.iss.sonar.esql.api.tree.statement.WhileStatementTree;
import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.PreciseIssue;
import com.exxeta.iss.sonar.esql.tree.impl.expression.CallExpressionTreeImpl;
@Rule(key = "CardinalityInLoop")
public class CardinalityInLoopCheck extends DoubleDispatchVisitorCheck {
private static final String MESSAGE = "Avoid using CARDINALITY in loops.";
+
+ private List reportedStatements = new ArrayList<>();
+ @Override
+ public void visitProgram(ProgramTree tree) {
+ reportedStatements.clear();
+ super.visitProgram(tree);
+ }
+
@Override
public void visitWhileStatement(WhileStatementTree tree) {
checkCardinalityInDecendants(tree);
@@ -59,4 +72,14 @@ private void checkCardinalityInDecendants(Tree tree) {
.forEach(d -> addIssue(d, MESSAGE));
}
+ @Override
+ public PreciseIssue addIssue(Tree tree, String message) {
+ if (!reportedStatements.contains(tree)){
+ reportedStatements.add(tree);
+ return super.addIssue(tree, message);
+ } else {
+ return null;
+ }
+ }
+
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CaseAtLeastThreeWhenCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CaseAtLeastThreeWhenCheck.java
index a3a7a96a..beae3796 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CaseAtLeastThreeWhenCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CaseAtLeastThreeWhenCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CaseWithTooManyWhensCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CaseWithTooManyWhensCheck.java
index ef7b259a..f0e34cbd 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CaseWithTooManyWhensCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CaseWithTooManyWhensCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CaseWithoutElseCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CaseWithoutElseCheck.java
index f9944410..0178a510 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CaseWithoutElseCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CaseWithoutElseCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -41,12 +41,8 @@ public void visitCaseFunction(CaseFunctionTree tree) {
if (tree.elseKeyword() == null) {
List whens = tree.whenClauses();
- if (whens.isEmpty()) {
- addIssue(new PreciseIssue(this, new IssueLocation(tree, MESSAGE)));
- } else {
- WhenClauseExpressionTree lastWhen = whens.get(whens.size() - 1);
- addIssue(new PreciseIssue(this, new IssueLocation(tree.caseKeyword(), lastWhen, MESSAGE)));
- }
+ WhenClauseExpressionTree lastWhen = whens.get(whens.size() - 1);
+ addIssue(new PreciseIssue(this, new IssueLocation(tree.caseKeyword(), lastWhen, MESSAGE)));
}
super.visitCaseFunction(tree);
@@ -54,15 +50,11 @@ public void visitCaseFunction(CaseFunctionTree tree) {
@Override
public void visitCaseStatement(CaseStatementTree tree) {
- if(tree.elseKeyword()==null){
- List whens = tree.whenClauses();
- if (whens.isEmpty()){
- addIssue(new PreciseIssue(this, new IssueLocation(tree, MESSAGE)));
- } else {
- WhenClauseTree lastWhen = whens.get(whens.size()-1);
- addIssue(new PreciseIssue(this, new IssueLocation(tree.caseKeyword(), lastWhen, MESSAGE)));
- }
- }
+ if (tree.elseKeyword() == null) {
+ List whens = tree.whenClauses();
+ WhenClauseTree lastWhen = whens.get(whens.size() - 1);
+ addIssue(new PreciseIssue(this, new IssueLocation(tree.caseKeyword(), lastWhen, MESSAGE)));
+ }
super.visitCaseStatement(tree);
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CheckList.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CheckList.java
index d050a036..8e4d0495 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CheckList.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CheckList.java
@@ -1,113 +1,141 @@
-/*
- * Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
- * http://www.exxeta.com
- *
- * Licensed 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 com.exxeta.iss.sonar.esql.check;
-
-import java.util.List;
-
-import com.google.common.collect.ImmutableList;
-
-public final class CheckList {
-
- public static final String REPOSITORY_KEY = "esql";
-
- public static final String REPOSITORY_NAME = "SonarAnalyzer";
-
- public static final String SONAR_WAY_PROFILE = "Sonar way";
-
- private CheckList() {
- }
-
- public static List getChecks() {
- return ImmutableList. of(
- CommentRegularExpressionCheck.class,
- ElseIfWithoutElseCheck.class,
- FileNameCheck.class,
- FunctionNameCheck.class,
- IterateStatementCheck.class,
- LineLengthCheck.class,
- ModuleNameCheck.class,
- NestedIfDepthCheck.class,
- NonReservedKeywordCheck.class,
- OneStatementPerLineCheck.class,
- ParsingErrorCheck.class,
- ProcedureNameCheck.class,
- TooManyIterateOrLeaveInLoopCheck.class,
- TooManyLinesInFileCheck.class,
- UseBrokerSchemaCheck.class,
- VariableNameCheck.class,
- PropagateToLabelCheck.class,
- ConstantNameCheck.class,
- MissingNewlineAtEndOfFileCheck.class,
- UnusedRoutineCheck.class,
- EmptyBlockCheck.class,
- EmptyFileCheck.class,
- UselessParenthesesCheck.class,
- CaseAtLeastThreeWhenCheck.class,
- FileHeaderCheck.class,
- IdenticalExpressionOnBinaryOperatorCheck.class,
- IfConditionalAlwaysTrueOrFalseCheck.class,
- DuplicateConditionIfElseAndCaseWhensCheck.class,
- BooleanInversionCheck.class,
- HardCodedCredentialsCheck.class,
- HardcodedIpCheck.class,
- HardcodedURICheck.class,
- BooleanLiteralCheck.class,
- CaseWithoutElseCheck.class,
- CardinalityInLoopCheck.class,
- LoopWithoutLeaveCheck.class,
- EmptyMainFunctionCheck.class,
- UnknownMessageDomainCheck.class,
- ParameterWithDirectionCheck.class,
- DeleteFromWithoutWhereCheck.class,
- SelectAllCheck.class,
- SleepCheck.class,
- EvalCheck.class,
- BitstreamCheck.class,
- CaseWithTooManyWhensCheck.class,
- InitializeVariablesCheck.class,
- UndocumentedModuleCheck.class,
- UndocumentedRoutineCheck.class,
- TooManyParametersCheck.class,
- VariablesSubtreeCheck.class,
- XmlnscDomainCheck.class,
- RoutineWithExcessiveReturnsCheck.class
-
- /*
-
- Backlog
-
-- Use the SOAP domain not soap in the xmlnsc domain
-
-- SOAP version should be 1.2 or 1.1
-
- IdenticalOperandOnBinaryExpressionCheck
-
-- Unreachable code after THROW or RETURN
-
-- Unused variable
-
- - Uppercase keywords
-
-- IF/ELSEIF should be CASE
-
-
- */
- );
- }
-
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+
+public final class CheckList {
+
+ public static final String REPOSITORY_KEY = "esql";
+
+ public static final String REPOSITORY_NAME = "SonarAnalyzer";
+
+ public static final String SONAR_WAY_PROFILE = "Sonar way";
+
+ private CheckList() {
+ }
+
+ public static List getChecks() {
+ return ImmutableList. of(
+ CommentRegularExpressionCheck.class,
+ ElseIfWithoutElseCheck.class,
+ FileNameCheck.class,
+ FunctionNameCheck.class,
+ IterateStatementCheck.class,
+ LineLengthCheck.class,
+ ModuleNameCheck.class,
+ NestedIfDepthCheck.class,
+ NonReservedKeywordCheck.class,
+ OneStatementPerLineCheck.class,
+ ParsingErrorCheck.class,
+ ProcedureNameCheck.class,
+ TooManyIterateOrLeaveInLoopCheck.class,
+ TooManyLinesInFileCheck.class,
+ UseBrokerSchemaCheck.class,
+ VariableNameCheck.class,
+ PropagateToLabelCheck.class,
+ ConstantNameCheck.class,
+ MissingNewlineAtEndOfFileCheck.class,
+ UnusedRoutineCheck.class,
+ EmptyBlockCheck.class,
+ EmptyFileCheck.class,
+ UselessParenthesesCheck.class,
+ CaseAtLeastThreeWhenCheck.class,
+ FileHeaderCheck.class,
+ IdenticalExpressionOnBinaryOperatorCheck.class,
+ IfConditionalAlwaysTrueOrFalseCheck.class,
+ DuplicateConditionIfElseAndCaseWhensCheck.class,
+ BooleanInversionCheck.class,
+ HardCodedCredentialsCheck.class,
+ HardcodedIpCheck.class,
+ HardcodedURICheck.class,
+ BooleanLiteralCheck.class,
+ CaseWithoutElseCheck.class,
+ CardinalityInLoopCheck.class,
+ LoopWithoutLeaveCheck.class,
+ EmptyMainFunctionCheck.class,
+ UnknownMessageDomainCheck.class,
+ ParameterWithDirectionCheck.class,
+ DeleteFromWithoutWhereCheck.class,
+ SelectAllCheck.class,
+ SleepCheck.class,
+ EvalCheck.class,
+ CaseWithTooManyWhensCheck.class,
+ InitializeVariablesCheck.class,
+ UndocumentedModuleCheck.class,
+ UndocumentedRoutineCheck.class,
+ TooManyParametersCheck.class,
+ VariablesSubtreeCheck.class,
+ XmlnscDomainCheck.class,
+ RoutineWithExcessiveReturnsCheck.class,
+ KeyWordCaseCheck.class,
+ CyclomaticComplexityCheck.class,
+ PassThruStatementCheck.class,
+ SubElementNameCheck.class,
+ FunctionProcedureLengthCheck.class,
+ FilterNodeModifyMessageCheck.class,
+ FilterNodeHaveOnlyOneReturnCheck.class,
+ NavigatingTreeCouldBeReferenceCheck.class,
+ UnusedVariableCheck.class,
+ DeprecatedMethodCheck.class,
+ ProcessInvokingItselfCheck.class,
+ InsertBlankLineBetweenFuncProcCheck.class,
+ BlankLineBeforeCommentsCheck.class,
+ RoutineCommentsCheck.class,
+ PropagateConsistencyCheck.class,
+ UnreachableCodeCheck.class,
+ CommentedCodeCheck.class,
+ SelfAssignmentCheck.class,
+ ConditionBracesCheck.class,
+ TrailingCommentsCheck.class,
+ CommentsCheck.class,
+ DeclareCombineCheck.class,
+ BinaryOperatorSeparatedBySpaceCheck.class
+
+
+
+
+
+
+
+ /*
+ The process is invoking itself. This may be a circular reference(SI)
+ Backlog
+
+- Use the SOAP domain not soap in the xmlnsc domain
+
+- SOAP version should be 1.2 or 1.1
+
+ IdenticalOperandOnBinaryExpressionCheck
+
+- Unreachable code after THROW or RETURN
+
+- Unused variable
+
+ - Uppercase keywords
+
+- IF/ELSEIF should be CASE
+
+
+ */
+ );
+ }
+
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CheckUtils.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CheckUtils.java
index 55e4daaa..26dcc87f 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CheckUtils.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CheckUtils.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,51 +19,141 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
import com.exxeta.iss.sonar.esql.api.visitors.EsqlFile;
-import com.sonar.sslr.api.AstNode;
-import com.sonar.sslr.api.Token;
public class CheckUtils {
private CheckUtils() {
}
- public static boolean equalNodes(AstNode node1, AstNode node2) {
- if (!node1.getType().equals(node2.getType()) || node1.getNumberOfChildren() != node2.getNumberOfChildren()) {
- return false;
- }
-
- List children1 = node1.getChildren();
- List children2 = node2.getChildren();
- for (int i = 0; i < children1.size(); i++) {
- if (!equalNodes(children1.get(i), children2.get(i))) {
- return false;
- }
- }
- return true;
- }
+
- public static boolean containsValue(List list, String value) {
- for (Token currentToken : list) {
- if (currentToken.getValue().equals(value)) {
- return true;
- }
- }
- return false;
- }
public static List readLines(EsqlFile file) {
try (BufferedReader reader = newBufferedReader(file)) {
return reader.lines().collect(Collectors.toList());
} catch (IOException e) {
- throw new IllegalStateException("Unable to read file " + file.relativePath(), e);
+ throw new IllegalStateException("Unable to read file " + file.toString(), e);
}
}
- private static BufferedReader newBufferedReader(EsqlFile file) {
+ private static BufferedReader newBufferedReader(EsqlFile file) throws IOException {
return new BufferedReader(new StringReader(file.contents()));
}
+
+ /* changes Strats from here (Sapna Singh) */
+
+
+
+ public static String removeQuotedContent(String s) {
+ String res = removeQuotedContentByChar(s, '\'');
+ res = removeQuotedContentByChar(res, '"');
+ return res;
+ }
+
+ public static String removeQuotedContentByChar(String s, char c) {
+ StringBuilder removeQuotedComment = new StringBuilder();
+ boolean quote = false;
+ for (int i = 0; i < s.length(); i++) {
+ if (!quote) {
+ if (s.charAt(i) == c)
+ quote = true;
+ removeQuotedComment.append(s.charAt(i));
+ continue;
+ }
+ if (s.charAt(i) == c) {
+ quote = false;
+ removeQuotedComment.append(s.charAt(i));
+ }
+ }
+
+ return removeQuotedComment.toString();
+ }
+
+ public static Set buildKeys(String lineParam)
+ {
+ String line = lineParam;
+ Set keys = new HashSet<>();
+ int startId = line.lastIndexOf('(');
+ if(startId > -1)
+ line = line.substring(startId + 1);
+ int endId = line.lastIndexOf(')');
+ if(endId > -1)
+ line = line.substring(0, endId);
+ String[] lines = line.split("\\|\\|");
+ String[] as = lines;
+ int j = as.length;
+ for(int k = 0; k < j; k++)
+ {
+ String singleLine = as[k];
+ String[] lineParts = singleLine.split(",");
+ String[] as1 = lineParts;
+ int l = as1.length;
+ for(int i1 = 0; i1 < l; i1++)
+ {
+ String thisLine = as1[i1];
+ int fromPos = thisLine.indexOf(" FROM ");
+ if(fromPos > -1)
+ thisLine = thisLine.substring(0, fromPos);
+ int asPos = thisLine.indexOf(" AS ");
+ if(asPos > -1)
+ thisLine = thisLine.substring(0, asPos);
+ String[] lineParts2 = thisLine.split(" AND ");
+ String[] as2 = lineParts2;
+ int j1 = as2.length;
+ for(int k1 = 0; k1 < j1; k1++)
+ {
+ String thisLineAfterAnd = as2[k1];
+ int cnt = 0;
+ int i = 0;
+ boolean done=false;
+ while(!done)
+ {
+ if(i >= thisLineAfterAnd.length())
+ done = true;
+ if(!done && thisLineAfterAnd.charAt(i) == '.')
+ {
+ if(cnt >= 1)
+ {
+ String newKey = thisLineAfterAnd.substring(0, i);
+ keys.add(newKey);
+ }
+ cnt++;
+ }
+ if(!done && (thisLineAfterAnd.charAt(i) == ' ' || thisLineAfterAnd.charAt(i) == '='))
+ done=true;
+ i++;
+ }
+ }
+
+ }
+
+ }
+
+ return keys;
+ }
+
+ public static Integer findLineInText(List textLines, String line)
+ {
+ int i = 0;
+ for(Iterator iterator = textLines.iterator(); iterator.hasNext();)
+ {
+ String s = iterator.next();
+ i++;
+ if(s.contains(line))
+ return i;
+ }
+
+ return null;
+ }
+
+
+
+ /* changes Ends here (sapna singh) */
}
\ No newline at end of file
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommentRegularExpressionCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommentRegularExpressionCheck.java
index 6923558e..8c9051f5 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommentRegularExpressionCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommentRegularExpressionCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +18,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
-import java.util.List;
+import java.util.Set;
import java.util.regex.Pattern;
import org.sonar.check.Rule;
@@ -32,7 +32,7 @@
import com.exxeta.iss.sonar.esql.api.visitors.LineIssue;
import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitorCheck;
import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
@Rule( key = "CommentRegularExpression" )
@RuleTemplate
@@ -92,8 +92,8 @@ public void visitNode(Tree tree) {
}
@Override
- public List nodesToVisit() {
- return ImmutableList.of(Kind.TOKEN);
+ public Set nodesToVisit() {
+ return ImmutableSet.of(Kind.TOKEN);
}
}
\ No newline at end of file
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommentedCodeCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommentedCodeCheck.java
new file mode 100644
index 00000000..23930f78
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommentedCodeCheck.java
@@ -0,0 +1,142 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.Tree;
+import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
+import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken;
+import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxTrivia;
+import com.exxeta.iss.sonar.esql.api.tree.statement.StatementsTree;
+import com.exxeta.iss.sonar.esql.api.visitors.IssueLocation;
+import com.exxeta.iss.sonar.esql.api.visitors.PreciseIssue;
+import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitorCheck;
+import com.exxeta.iss.sonar.esql.parser.EsqlParserBuilder;
+import com.exxeta.iss.sonar.esql.tree.EsqlCommentAnalyser;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.sonar.sslr.api.typed.ActionParser;
+
+@Rule(key = "CommentedCode")
+public class CommentedCodeCheck extends SubscriptionVisitorCheck {
+
+ private static final String MESSAGE = "Remove this commented out code.";
+ private static final EsqlCommentAnalyser COMMENT_ANALYSER = new EsqlCommentAnalyser();
+ private static final ActionParser PARSER = EsqlParserBuilder.createParser(Kind.STATEMENTS);
+
+ private static final List PARSING_TRY = ImmutableList.of(
+ "%s",
+ "IF TRUE THEN %s",
+ "IF TRUE THEN %s END IF;",
+ "%s END IF;",
+ "CASE A %s END CASE;",
+ "BEGIN %s",
+ "%s END;",
+ "%s;");
+
+ @Override
+ public Set nodesToVisit() {
+ return ImmutableSet.of(Kind.TOKEN);
+ }
+
+ @Override
+ public void visitNode(Tree tree) {
+ List> commentGroups = groupComments((SyntaxToken) tree);
+ commentGroups.forEach(this::checkCommentGroup);
+ }
+
+ private void checkCommentGroup(List commentGroup) {
+ String uncommentedText = uncomment(commentGroup);
+
+ boolean parseable=false;
+ for (String format : PARSING_TRY){
+ if (isParseable(String.format(format, uncommentedText))){
+ parseable=true;
+ break;
+ }
+ }
+
+ if (parseable) {
+ IssueLocation primaryLocation = new IssueLocation(commentGroup.get(0),
+ commentGroup.get(commentGroup.size() - 1), MESSAGE);
+ addIssue(new PreciseIssue(this, primaryLocation));
+ }
+ }
+
+ private boolean isParseable(String string) {
+ try{
+ StatementsTree parsedTree = (StatementsTree) PARSER.parse(string);
+ return !parsedTree.statements().isEmpty();
+ }catch (Exception e){
+ return false;
+ }
+
+ }
+
+ private static String uncomment(List triviaGroup) {
+ StringBuilder uncommentedText = new StringBuilder();
+ for (SyntaxTrivia trivia : triviaGroup) {
+ String value = COMMENT_ANALYSER.getContents(trivia.text());
+ uncommentedText.append("\n");
+ uncommentedText.append(value);
+ }
+ return uncommentedText.toString().trim();
+ }
+
+ /**
+ * Returns comments by groups which come sequentially, without empty lines
+ * between.
+ */
+ private static List> groupComments(SyntaxToken token) {
+ List> groups = new LinkedList<>();
+ List currentGroup = null;
+
+ for (SyntaxTrivia trivia : token.trivias()) {
+ if (currentGroup == null) {
+ currentGroup = initNewGroup(trivia);
+
+ } else if (isAdjacent(trivia, currentGroup)) {
+ currentGroup.add(trivia);
+
+ } else {
+ groups.add(currentGroup);
+ currentGroup = initNewGroup(trivia);
+ }
+ }
+
+ if (currentGroup != null) {
+ groups.add(currentGroup);
+ }
+ return groups;
+ }
+
+ private static List initNewGroup(SyntaxTrivia trivia) {
+ List group = new LinkedList<>();
+ group.add(trivia);
+ return group;
+ }
+
+ private static boolean isAdjacent(SyntaxTrivia trivia, List currentGroup) {
+ return currentGroup.get(currentGroup.size() - 1).line() + 1 == trivia.line();
+ }
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommentsCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommentsCheck.java
new file mode 100644
index 00000000..ef847cfd
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommentsCheck.java
@@ -0,0 +1,79 @@
+/**
+ * This java class is created to implement the logic for checking if comment is included or not,
+ * over every 20 lines of code.
+ *
+ * @author Prerana Agarkar
+ *
+ */
+package com.exxeta.iss.sonar.esql.check;
+
+import java.util.List;
+import org.sonar.check.Rule;
+import org.sonar.check.RuleProperty;
+import com.exxeta.iss.sonar.esql.api.tree.ProgramTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.EsqlFile;
+import com.exxeta.iss.sonar.esql.api.visitors.LineIssue;
+
+@Rule(key = "Comments")
+public class CommentsCheck extends DoubleDispatchVisitorCheck {
+
+ private static final String MESSAGE = "Include comment within the range of every 20 lines of code.";
+ private static final int DEFAULT_THRESHOLD = 21;
+ @RuleProperty(
+ key = "Comments",
+ description = "Include comment within the range of every 20 lines of code.",
+ defaultValue = "" + DEFAULT_THRESHOLD)
+ public int maximumThreshold = DEFAULT_THRESHOLD;
+
+
+ @Override
+ public void visitProgram(ProgramTree tree) {
+ EsqlFile file = getContext().getEsqlFile();
+ List lines = CheckUtils.readLines(file);
+
+ int linesCounter=0;
+ int commentsCount=0;
+
+
+ for(int i=0; i< lines.size();i++){
+
+ String originalLine = lines.get(i);
+
+ if(originalLine.replaceAll("\\s+","").isEmpty()){
+ continue;
+ }
+
+ if( originalLine.replaceAll("\\s+","").startsWith("--"))
+ {
+ linesCounter=0;
+ }
+
+ if(originalLine.replaceAll("\\s+","").startsWith("/*")){
+
+ commentsCount=commentsCount+1;
+ continue;
+ }
+
+ if(commentsCount >= 1 && !(originalLine.replaceAll("\\s+","").endsWith("*/"))){
+ continue;
+ }else if(commentsCount >= 1 && (originalLine.replaceAll("\\s+","").endsWith("*/"))){
+ linesCounter=0;
+ commentsCount =0;
+ }
+
+ linesCounter = linesCounter + 1;
+
+ if(linesCounter>DEFAULT_THRESHOLD)
+
+ {
+ addIssue(new LineIssue(this,i+1,MESSAGE));
+ linesCounter=0;
+ continue;
+ }
+
+ }
+
+ }
+ }
+
\ No newline at end of file
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ConditionBracesCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ConditionBracesCheck.java
new file mode 100644
index 00000000..5a843bcb
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ConditionBracesCheck.java
@@ -0,0 +1,58 @@
+/**
+ * This java class is created to implement the logic for checking if braces for conditions are used or not,
+ * if it is not used then it should be inserted.
+ *
+ *
+ * @author Prerana Agarkar
+ *
+ */
+
+package com.exxeta.iss.sonar.esql.check;
+
+import org.sonar.check.Rule;
+import com.exxeta.iss.sonar.esql.api.tree.Tree;
+import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
+import com.exxeta.iss.sonar.esql.api.tree.statement.ElseifClauseTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.IfStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.WhileStatementTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+
+@Rule(key ="ConditionBraces")
+public class ConditionBracesCheck extends DoubleDispatchVisitorCheck {
+ public static final String MESSAGE = "Use braces for conditions as it gives more readability to code.";
+
+ @Override
+ public void visitIfStatement(IfStatementTree tree)
+ {
+ checkTree(tree.condition());
+ super.visitIfStatement(tree);
+ }
+ @Override
+ public void visitElseifClause(ElseifClauseTree tree) {
+ checkTree(tree.condition());
+ super.visitElseifClause(tree);
+ }
+ @Override
+ public void visitWhileStatement(WhileStatementTree tree) {
+ checkTree(tree.condition());
+ super.visitWhileStatement(tree);
+ }
+
+ private void checkTree(Tree tree)
+ {
+ if (!(tree.is(Kind.PARENTHESISED_EXPRESSION)))
+ {
+ addIssue(tree, MESSAGE);
+ }
+ }
+}
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ConstantNameCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ConstantNameCheck.java
index 045405df..e371722e 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ConstantNameCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ConstantNameCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CyclomaticComplexityCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CyclomaticComplexityCheck.java
new file mode 100644
index 00000000..e4695594
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CyclomaticComplexityCheck.java
@@ -0,0 +1,79 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import org.sonar.check.Rule;
+import org.sonar.check.RuleProperty;
+
+import com.exxeta.iss.sonar.esql.api.tree.RoutineDeclarationTree;
+import com.exxeta.iss.sonar.esql.api.tree.Tree;
+import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateFunctionStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateProcedureStatementTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.metrics.ComplexityVisitor;
+
+/**
+ * This java class is created to implement the logic for checking cyclomatic
+ * complexity of the code. cyclomatic complexity should be less than the
+ * threshold value
+ *
+ * @author sapna singh
+ *
+ */
+@Rule(key = "CyclomaticComplexity")
+public class CyclomaticComplexityCheck extends DoubleDispatchVisitorCheck {
+
+ private static final String MESSAGE = "Refactor this %s to reduce its Cognitive Complexity from %s to the %s allowed.";
+
+ private static final int DEFAULT_COMPLEXITY_THRESHOLD = 10;
+
+ @RuleProperty(key = "maximumCyclomaticComplexity", description = "The maximum authorized cyclomatic complexity.", defaultValue = ""
+ + DEFAULT_COMPLEXITY_THRESHOLD)
+ public int maximumCyclomaticComplexity = DEFAULT_COMPLEXITY_THRESHOLD;
+
+ @Override
+ public void visitCreateFunctionStatement(CreateFunctionStatementTree tree) {
+ visitRoutine(tree);
+
+ }
+
+ @Override
+ public void visitCreateProcedureStatement(CreateProcedureStatementTree tree) {
+ visitRoutine(tree);
+ }
+
+ private void visitRoutine(RoutineDeclarationTree tree) {
+ int complexity = new ComplexityVisitor().getComplexity(tree);
+ if (complexity > maximumCyclomaticComplexity) {
+ raiseIssue(complexity, tree);
+ }
+ }
+
+ private void raiseIssue(int complexity, Tree routine) {
+ String message = String.format(MESSAGE,
+ routine instanceof CreateFunctionStatementTree ? "function" : "procedure", complexity,
+ maximumCyclomaticComplexity);
+
+ SyntaxToken primaryLocation = routine.firstToken();
+
+ addIssue(primaryLocation, message).cost(complexity - (double) maximumCyclomaticComplexity);
+
+ }
+
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DeclareCombineCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DeclareCombineCheck.java
new file mode 100644
index 00000000..9e930358
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DeclareCombineCheck.java
@@ -0,0 +1,102 @@
+/**
+ * This java class is created to implement the logic for checking if variable is initialised or not,
+ * if more than one variable of same datatype is found uninitialised then declare statement could be combined.
+ *
+ *
+ * @author Prerana Agarkar
+ *
+ */
+package com.exxeta.iss.sonar.esql.check;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.TreeMap;
+import java.util.stream.Collectors;
+
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.Tree;
+import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
+import com.exxeta.iss.sonar.esql.api.tree.statement.DeclareStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.StatementsTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.IssueLocation;
+import com.exxeta.iss.sonar.esql.api.visitors.PreciseIssue;
+
+
+
+@Rule(key ="DeclareCombine")
+public class DeclareCombineCheck extends DoubleDispatchVisitorCheck {
+ public static final String MESSAGE = "If more than one variable of same datatype is found uninitialised then declare could be combined.";
+
+
+
+ @Override
+ public void visitStatements(StatementsTree tree) {
+ Iterator declareIterator = tree.childrenStream()
+ .filter(t ->
+ t.is(Kind.DECLARE_STATEMENT)
+ && ((DeclareStatementTree)t).initialValueExpression()==null
+ )
+ .iterator();
+ Map> declares= new TreeMap<>();
+
+ while (declareIterator.hasNext()){
+ DeclareStatementTree declareStatement = (DeclareStatementTree) declareIterator.next();
+ String dataType = getDataType(declareStatement);
+
+ if ( !declares.containsKey(dataType)){
+ declares.put(dataType, new ArrayList<>());
+ }
+ declares.get(dataType).add(declareStatement);
+ }
+
+ for (Map.Entry> entry : declares.entrySet()){
+ if (entry.getValue().size()>1){
+ addIssue(entry.getValue());
+ }
+ }
+
+ super.visitStatements(tree);
+ }
+
+ private String getDataType(DeclareStatementTree declareStatement) {
+ String prefix = "";
+ if (declareStatement.sharedExt()!=null){
+ prefix+=declareStatement.sharedExt().text();
+ }
+ if (declareStatement.namespace()!=null){
+ prefix+=declareStatement.namespace().text();
+ }
+ if (declareStatement.constantKeyword()!=null){
+ prefix+=declareStatement.constantKeyword().text();
+ }
+ if (declareStatement.dataType()==null) {
+ return prefix;
+ }
+ if (declareStatement.dataType().dataType()!=null){
+ return prefix + declareStatement.dataType().dataType().text();
+ } else if (declareStatement.dataType().decimalDataType()!=null){
+ return prefix + declareStatement.dataType().decimalDataType().childrenStream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.joining(" "));
+ } else {
+ return prefix;
+ }
+ }
+
+ private void addIssue(List declareStatements) {
+
+// for (int i = 1; i < declareStatements.size(); i++) {
+// addIssue(declareStatements.get(i), MESSAGE);
+// }
+ PreciseIssue issue = addIssue(declareStatements.get(1), MESSAGE);
+
+ for (int i = 2; i < declareStatements.size(); i++) {
+ issue.secondary(new IssueLocation(declareStatements.get(i)));
+ }
+ }
+}
+
+
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DeleteFromWithoutWhereCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DeleteFromWithoutWhereCheck.java
index 4cd9f315..c4cd4ce1 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DeleteFromWithoutWhereCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DeleteFromWithoutWhereCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,19 +17,40 @@
*/
package com.exxeta.iss.sonar.esql.check;
+import java.util.List;
+
import org.sonar.check.Rule;
+import com.exxeta.iss.sonar.esql.api.tree.Tree;
import com.exxeta.iss.sonar.esql.api.tree.statement.DeleteFromStatementTree;
-import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.tree.expression.LiteralTree;
+
+@Rule(key = "DeleteFromWithoutWhere")
+public class DeleteFromWithoutWhereCheck extends AbstractPassthruCheck {
-@Rule(key="DeleteFromWithoutWhere")
-public class DeleteFromWithoutWhereCheck extends DoubleDispatchVisitorCheck {
+ private static final String MESSAGE = "Add a where caluse to this DELETE FROM statement.";
@Override
public void visitDeleteFromStatement(DeleteFromStatementTree tree) {
- if (tree.whereExpression()==null){
- addIssue(tree, "Add a where caluse to this DELETE FROM statement.");
+ if (tree.whereExpression() == null) {
+ addIssue(tree, MESSAGE);
+ }
+ }
+
+ @Override
+ protected void checkLiterals(Tree tree, List literals) {
+ if (!literals.isEmpty() && literals.get(0).value().toUpperCase().matches("'.*DELETE\\s+FROM.*")) {
+ boolean hasWhereClause = false;
+ for (LiteralTree literal : literals) {
+ if (literal.value().toUpperCase().matches(".*WHERE.*")) {
+ hasWhereClause = true;
+ }
+
+ }
+ if (!hasWhereClause) {
+ addIssue(tree, MESSAGE);
+ }
}
}
-
+
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DeprecatedMethodCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DeprecatedMethodCheck.java
new file mode 100644
index 00000000..11b2e1c1
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DeprecatedMethodCheck.java
@@ -0,0 +1,61 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.sonar.check.Rule;
+import org.sonar.check.RuleProperty;
+
+
+/**
+ * This Java class is created to implement the logic to avoid the deprecated methods.
+ * @author Sapna Singh
+ *
+ */
+@Rule(key = "DeprecatedMethod")
+public class DeprecatedMethodCheck extends AbstractDoNotUseFunctionCheck {
+ private static final String MESSAGE = "Do not use %s it is deprecated.";
+
+ private static final String DEFAULT_DEPRECATED_METHODS = "BITSTREAM";
+ @RuleProperty(
+ key = "DeprecatedMethod",
+ description = "Deprecated methods should not be used.",
+ defaultValue = DEFAULT_DEPRECATED_METHODS)
+ public String deprecatedMethods = DEFAULT_DEPRECATED_METHODS;
+
+
+
+ @Override
+ public String getMessage(String functionName) {
+ return String.format(MESSAGE, functionName);
+ }
+
+ @Override
+ public List getFunctionNames() {
+ List functionNames = new ArrayList<>();
+ for (String method : deprecatedMethods.split(",")){
+ functionNames.add(method.trim());
+ }
+ return functionNames;
+ }
+
+
+}
+
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DuplicateConditionIfElseAndCaseWhensCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DuplicateConditionIfElseAndCaseWhensCheck.java
index 81feb11a..a3f59d02 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DuplicateConditionIfElseAndCaseWhensCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/DuplicateConditionIfElseAndCaseWhensCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,12 +39,12 @@ public void visitIfStatement(IfStatementTree tree) {
for (int i = 0; i < tree.elseifClauses().size(); i++) {
if (SyntacticEquivalence.areEquivalent(condition, tree.elseifClauses().get(i).condition())) {
- addIssue(condition, tree.elseifClauses().get(i), "branch");
+ addIssue(condition, tree.elseifClauses().get(i).condition(), "branch");
}
for (int j = 0; j < i; j++) {
if (SyntacticEquivalence.areEquivalent(tree.elseifClauses().get(j).condition(),
tree.elseifClauses().get(i).condition())) {
- addIssue(tree.elseifClauses().get(j), tree.elseifClauses().get(i), "branch");
+ addIssue(tree.elseifClauses().get(j).condition(), tree.elseifClauses().get(i).condition(), "branch");
}
}
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ElseIfWithoutElseCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ElseIfWithoutElseCheck.java
index e3171bec..87222aba 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ElseIfWithoutElseCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ElseIfWithoutElseCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EmptyBlockCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EmptyBlockCheck.java
index 11ff70b3..28e012e5 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EmptyBlockCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EmptyBlockCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,18 @@
import org.sonar.check.Rule;
+import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken;
+import com.exxeta.iss.sonar.esql.api.tree.statement.BeginEndStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CaseStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.ElseClauseTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.ElseifClauseTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.ForStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.IfStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.LoopStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.RepeatStatementTree;
import com.exxeta.iss.sonar.esql.api.tree.statement.StatementsTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.WhenClauseTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.WhileStatementTree;
import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
import com.exxeta.iss.sonar.esql.api.visitors.IssueLocation;
import com.exxeta.iss.sonar.esql.api.visitors.PreciseIssue;
@@ -27,16 +38,97 @@
@Rule(key = "EmptyBlock")
public class EmptyBlockCheck extends DoubleDispatchVisitorCheck {
- private static final String MESSAGE = "Either remove or fill this block of code.";
+ private static final String MESSAGE = "Either remove or fill this block of code.";
-
+ @Override
+ public void visitBeginEndStatement(BeginEndStatementTree tree) {
+ checkBlock(tree.statements(), tree.endKeyword());
+ super.visitBeginEndStatement(tree);
+ }
-@Override
-public void visitStatements(StatementsTree tree) {
- if (tree.statements().isEmpty()){
- addIssue(new PreciseIssue(this, new IssueLocation(tree.parent() , MESSAGE)));
+ @Override
+ public void visitElseClause(ElseClauseTree tree) {
+ checkBlock(tree.statements(), ((IfStatementTree) tree.parent()).endKeyword());
+ super.visitElseClause(tree);
+ }
+
+ @Override
+ public void visitElseifClause(ElseifClauseTree tree) {
+ IfStatementTree ifStatement = (IfStatementTree) tree.parent();
+ int elseIfIndex = ifStatement.elseifClauses().indexOf(tree);
+ if (ifStatement.elseifClauses().size() > elseIfIndex + 1) {
+ // this tree is not the last elseif clause
+ checkBlock(tree.statements(), ifStatement.elseifClauses().get(elseIfIndex + 1).elseifKeyword());
+ } else if (ifStatement.elseClause() != null) {
+ checkBlock(tree.statements(), ifStatement.elseClause().elseKeyword());
+ } else {
+ checkBlock(tree.statements(), ifStatement.endKeyword());
+ }
+
+ super.visitElseifClause(tree);
+ }
+
+ @Override
+ public void visitForStatement(ForStatementTree tree) {
+ checkBlock(tree.statements(), tree.endKeyword());
+ super.visitForStatement(tree);
+ }
+
+ @Override
+ public void visitIfStatement(IfStatementTree tree) {
+ SyntaxToken endToken = null;
+ if (!tree.elseifClauses().isEmpty()) {
+ endToken = tree.elseifClauses().get(0).elseifKeyword();
+ } else if (tree.elseClause() != null) {
+ endToken = tree.elseClause().elseKeyword();
+ } else {
+ endToken = tree.endKeyword();
+ }
+ checkBlock(tree.statements(), endToken);
+ super.visitIfStatement(tree);
+ }
+
+ @Override
+ public void visitLoopStatement(LoopStatementTree tree) {
+ checkBlock(tree.statements(), tree.endKeyword());
+ super.visitLoopStatement(tree);
}
- super.visitStatements(tree);
-}
+ @Override
+ public void visitRepeatStatement(RepeatStatementTree tree) {
+ checkBlock(tree.statements(), tree.untilKeyword());
+ super.visitRepeatStatement(tree);
+ }
+
+ @Override
+ public void visitWhenClause(WhenClauseTree tree) {
+ CaseStatementTree caseStatement = (CaseStatementTree) tree.parent();
+ int whenIndex = caseStatement.whenClauses().indexOf(tree);
+ if (caseStatement.whenClauses().size()>whenIndex+1){
+ //Not the last when clause
+ checkBlock(tree.statements(), caseStatement.whenClauses().get(whenIndex+1).whenKeyword());
+ } else if (caseStatement.elseKeyword()!=null) {
+ checkBlock(tree.statements(), caseStatement.elseKeyword());
+ } else {
+ checkBlock(tree.statements(), caseStatement.endKeyword());
+ }
+ super.visitWhenClause(tree);
+ }
+
+ @Override
+ public void visitWhileStatement(WhileStatementTree tree) {
+ checkBlock(tree.statements(), tree.endKeyword());
+ super.visitWhileStatement(tree);
+ }
+
+ private void checkBlock(StatementsTree statements, SyntaxToken endToken) {
+ if (statements.statements().isEmpty() && !hasComment(endToken)) {
+ addIssue(new PreciseIssue(this, new IssueLocation(statements.parent(), MESSAGE)));
+ }
+
+ }
+
+ private static boolean hasComment(SyntaxToken endToken) {
+ return !endToken.trivias().isEmpty();
+ }
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EmptyFileCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EmptyFileCheck.java
index 220d08e2..5670ac79 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EmptyFileCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EmptyFileCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,7 @@
*/
package com.exxeta.iss.sonar.esql.check;
-import java.util.List;
+import java.util.Set;
import org.sonar.check.Rule;
@@ -26,7 +26,7 @@
import com.exxeta.iss.sonar.esql.api.visitors.FileIssue;
import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitorCheck;
import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
@Rule(key = "EmptyFile")
public class EmptyFileCheck extends SubscriptionVisitorCheck{
@@ -49,7 +49,7 @@ public void visitNode(Tree tree) {
}
@Override
- public List nodesToVisit() {
- return ImmutableList.of(Tree.Kind.TOKEN);
+ public Set nodesToVisit() {
+ return ImmutableSet.of(Tree.Kind.TOKEN);
}
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EmptyMainFunctionCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EmptyMainFunctionCheck.java
index ffbd2ac9..0c365638 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EmptyMainFunctionCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EmptyMainFunctionCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EvalCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EvalCheck.java
index f3cf28ed..95352d35 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EvalCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/EvalCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,19 +17,23 @@
*/
package com.exxeta.iss.sonar.esql.check;
+import java.util.List;
+
import org.sonar.check.Rule;
+import com.google.common.collect.ImmutableList;
+
@Rule(key="Eval")
-public class EvalCheck extends AbstractDoNotUseFunctinCheck {
+public class EvalCheck extends AbstractDoNotUseFunctionCheck {
@Override
- public String getMessage() {
+ public String getMessage(String functionName) {
return "EVAL should not be used because untested code could be injected.";
}
@Override
- public String getFunctionName() {
- return "EVAL";
+ public List getFunctionNames() {
+ return ImmutableList.of("EVAL");
}
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FileHeaderCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FileHeaderCheck.java
index f5343d17..557eca8b 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FileHeaderCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FileHeaderCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,11 +17,14 @@
*/
package com.exxeta.iss.sonar.esql.check;
+import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
@@ -45,6 +48,8 @@ public class FileHeaderCheck extends DoubleDispatchVisitorCheck {
private String[] expectedLines;
private Pattern searchPattern = null;
+ public static final Logger LOG = Loggers.get(FileHeaderCheck.class);
+
@Override
public void visitProgram(ProgramTree tree) {
@@ -74,7 +79,12 @@ private void checkRegularExpression() {
throw new IllegalArgumentException("[" + getClass().getSimpleName() + "] Unable to compile the regular expression: " + headerFormat, e);
}
}
- String fileContent = getContext().getEsqlFile().contents();
+ String fileContent = null;
+ try {
+ fileContent = getContext().getEsqlFile().contents();
+ } catch (IOException e) {
+ LOG.error("Cannot read file contents", e);
+ }
Matcher matcher = searchPattern.matcher(fileContent);
if (!matcher.find() || matcher.start() != 0) {
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FileNameCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FileNameCheck.java
index 9a23e121..c4a5dc60 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FileNameCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FileNameCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +18,7 @@
package com.exxeta.iss.sonar.esql.check;
import java.util.Collections;
-import java.util.List;
+import java.util.Set;
import java.util.regex.Pattern;
import org.sonar.check.Rule;
@@ -46,8 +46,8 @@ public FileNameCheck() {
@Override
- public List nodesToVisit() {
- return Collections.emptyList();
+ public Set nodesToVisit() {
+ return Collections.emptySet();
}
@Override
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FilterNodeHaveOnlyOneReturnCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FilterNodeHaveOnlyOneReturnCheck.java
new file mode 100644
index 00000000..d2a798ae
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FilterNodeHaveOnlyOneReturnCheck.java
@@ -0,0 +1,101 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateModuleStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.ReturnStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.ThrowStatementTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.IssueLocation;
+import com.exxeta.iss.sonar.esql.api.visitors.PreciseIssue;
+import com.exxeta.iss.sonar.esql.tree.expression.LiteralTree;
+
+/**
+ * @author Sapna Singh
+ *
+ */
+@Rule(key = "FilterNodeHaveOnlyOneReturn")
+public class FilterNodeHaveOnlyOneReturnCheck extends DoubleDispatchVisitorCheck {
+
+
+ private static final String MESSAGE = "This filter module always returns the same value";
+ private boolean insideFilterModule;
+ private int trueCount = 0;
+ private int falseCount = 0;
+ private int returnOther = 0;
+ private int throwsError = 0;
+
+
+
+ @Override
+ public void visitCreateModuleStatement(CreateModuleStatementTree tree) {
+ if ("FILTER".equalsIgnoreCase(tree.moduleType().text())) {
+ this.insideFilterModule = true;
+ falseCount = trueCount = returnOther = throwsError = 0;
+ }
+ super.visitCreateModuleStatement(tree);
+ if (this.insideFilterModule){
+ boolean returnViolation = false;
+ if (trueCount + falseCount + returnOther + throwsError == 0){ // no return or throw
+ returnViolation = true;
+ }
+ if (trueCount == 0 && returnOther == 0){ // only false or throw
+ returnViolation = true;
+ }
+ if (falseCount == 0 && returnOther == 0 && throwsError == 0){ // only true
+ returnViolation = true;
+ }
+
+ if (returnViolation) {
+
+ addIssue(new PreciseIssue(this, new IssueLocation(tree, MESSAGE)));
+ }
+
+ this.insideFilterModule=false;
+ }
+ }
+
+ @Override
+ public void visitReturnStatement(ReturnStatementTree tree) {
+ if (insideFilterModule) {
+ if (tree.expression().is(Kind.BOOLEAN_LITERAL)) {
+ LiteralTree literal = (LiteralTree) tree.expression();
+ if ("TRUE".equalsIgnoreCase(literal.value())) {
+ trueCount++;
+ } else {
+ falseCount++;
+ }
+ } else {
+ returnOther++;
+ }
+ }
+ super.visitReturnStatement(tree);
+ }
+
+ @Override
+ public void visitThrowStatement(ThrowStatementTree tree) {
+ if (insideFilterModule) {
+ throwsError++;
+ }
+ super.visitThrowStatement(tree);
+ }
+
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FilterNodeModifyMessageCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FilterNodeModifyMessageCheck.java
new file mode 100644
index 00000000..e56b1b6d
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FilterNodeModifyMessageCheck.java
@@ -0,0 +1,64 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.util.List;
+
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.FieldReferenceTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateModuleStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.SetStatementTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.LineIssue;
+import com.google.common.collect.ImmutableList;
+
+/**
+ * @author Sapna Singh
+ *
+ */
+@Rule(key = "FilterNodeModifyMessage")
+public class FilterNodeModifyMessageCheck extends DoubleDispatchVisitorCheck {
+
+ private static final String MESSAGE = "The filter node cannot modify the message";
+ private boolean insideFilterModule;
+
+ private List rootElements = ImmutableList.of("Root", "InputRoot", "OutputRoot");
+
+ @Override
+ public void visitCreateModuleStatement(CreateModuleStatementTree tree) {
+ if ("FILTER".equalsIgnoreCase(tree.moduleType().text())){
+ this.insideFilterModule=true;
+ }
+ super.visitCreateModuleStatement(tree);
+ this.insideFilterModule=false;
+ }
+
+ @Override
+ public void visitSetStatement(SetStatementTree tree) {
+ if (this.insideFilterModule && tree.variableReference() instanceof FieldReferenceTree) {
+ FieldReferenceTree fieldReference = (FieldReferenceTree) tree.variableReference();
+ if (rootElements.contains(fieldReference.pathElement().name().name().name())) {
+ addIssue(new LineIssue(this, tree, MESSAGE));
+ }
+
+ }
+
+ super.visitSetStatement(tree);
+ }
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FunctionNameCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FunctionNameCheck.java
index a0f4480e..0492b583 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FunctionNameCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FunctionNameCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FunctionProcedureLengthCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FunctionProcedureLengthCheck.java
new file mode 100644
index 00000000..7ee5cff9
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/FunctionProcedureLengthCheck.java
@@ -0,0 +1,82 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import org.sonar.check.Rule;
+import org.sonar.check.RuleProperty;
+
+import com.exxeta.iss.sonar.esql.api.tree.RoutineDeclarationTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.BeginEndStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateFunctionStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateProcedureStatementTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.IssueLocation;
+import com.exxeta.iss.sonar.esql.api.visitors.PreciseIssue;
+import com.exxeta.iss.sonar.esql.metrics.LineVisitor;
+
+/**
+ * This java class is created to implement the logic for checking the length of
+ * the function or procedure
+ *
+ * @author Sapna Singh
+ *
+ */
+@Rule(key = "FunctionProcedureLength")
+public class FunctionProcedureLengthCheck extends DoubleDispatchVisitorCheck {
+
+ private static final String MESSAGE = "This routine has %s lines, which is greater than the %s lines authorized.";
+
+ private static final int DEFAULT_LENGTH_THRESHOLD = 150;
+ @RuleProperty(
+ key = "maximumMethodProcedureLength",
+ description = "The maximum authorized method/procedure length.",
+ defaultValue = "" + DEFAULT_LENGTH_THRESHOLD)
+ public int maximumMethodProcedureLength = DEFAULT_LENGTH_THRESHOLD;
+
+
+
+ @Override
+ public void visitCreateFunctionStatement(CreateFunctionStatementTree tree) {
+ checkRoutineLength(tree);
+ super.visitCreateFunctionStatement(tree);
+ }
+
+ @Override
+ public void visitCreateProcedureStatement(CreateProcedureStatementTree tree) {
+ checkRoutineLength(tree);
+
+
+ super.visitCreateProcedureStatement(tree);
+ }
+
+ private void checkRoutineLength(RoutineDeclarationTree routineDeclarationTree) {
+ if (routineDeclarationTree.routineBody().statement() instanceof BeginEndStatementTree){
+
+ BeginEndStatementTree body = (BeginEndStatementTree) routineDeclarationTree.routineBody().statement();
+
+ int nbLines = new LineVisitor(body).getLinesOfCodeNumber();
+ if (nbLines > maximumMethodProcedureLength) {
+ String message = String.format(MESSAGE, nbLines, maximumMethodProcedureLength);
+ IssueLocation primaryLocation = new IssueLocation(routineDeclarationTree.firstToken(), message);
+ addIssue(new PreciseIssue(this, primaryLocation));
+ }
+ }
+
+ }
+
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/HardCodedCredentialsCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/HardCodedCredentialsCheck.java
index f2007ca0..fe48e243 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/HardCodedCredentialsCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/HardCodedCredentialsCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -71,7 +71,7 @@ private boolean isPasswordVariableName(FieldReferenceTree fieldReference) {
if (fieldReference==null) {
return false;
}
- return isPasswordVariableName(fieldReference.pathElement().name().name().text()) || isPasswordVariableName(fieldReference.pathElements());
+ return isPasswordVariableName(fieldReference.pathElement().name().name().name()) || isPasswordVariableName(fieldReference.pathElements());
}
private boolean isPasswordVariableName(IdentifierTree identifier) {
@@ -95,7 +95,7 @@ private boolean isPasswordVariableName(SeparatedList pathElemen
while (nameListIter.hasNext()) {
PathElementTree pathElement= nameListIter.next();
if (pathElement.name()!=null && pathElement.name().name()!=null &&
- isPasswordVariableName(pathElement.name().name().text())) {
+ isPasswordVariableName(pathElement.name().name().name())) {
return true;
}
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/HardcodedIpCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/HardcodedIpCheck.java
index 5b7efdbb..41753c4b 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/HardcodedIpCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/HardcodedIpCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/HardcodedURICheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/HardcodedURICheck.java
index e3b3336b..1995cf94 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/HardcodedURICheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/HardcodedURICheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -85,14 +85,14 @@ private boolean isFileNameFieldReference(FieldReferenceTree fieldReference) {
if (fieldReference==null){
return false;
}
- if (VARIABLE_NAME_PATTERN.matcher(fieldReference.pathElement().name().name().text()).find()) {
+ if (VARIABLE_NAME_PATTERN.matcher(fieldReference.pathElement().name().name().name()).find()) {
return true;
}
Iterator iter = fieldReference.pathElements().iterator();
while (iter.hasNext()) {
PathElementTree pathElement = iter.next();
if (pathElement.name()!=null && pathElement.name().name()!=null
- && VARIABLE_NAME_PATTERN.matcher(pathElement.name().name().text()).find()) {
+ && VARIABLE_NAME_PATTERN.matcher(pathElement.name().name().name()).find()) {
return true;
}
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/IdenticalExpressionOnBinaryOperatorCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/IdenticalExpressionOnBinaryOperatorCheck.java
index 2e3e3940..bc1ca99d 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/IdenticalExpressionOnBinaryOperatorCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/IdenticalExpressionOnBinaryOperatorCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/IfConditionalAlwaysTrueOrFalseCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/IfConditionalAlwaysTrueOrFalseCheck.java
index ae717aff..b7f43927 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/IfConditionalAlwaysTrueOrFalseCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/IfConditionalAlwaysTrueOrFalseCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/InitializeVariablesCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/InitializeVariablesCheck.java
index bdbc7471..bcfbee20 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/InitializeVariablesCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/InitializeVariablesCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/InsertBlankLineBetweenFuncProcCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/InsertBlankLineBetweenFuncProcCheck.java
new file mode 100644
index 00000000..a9857d0a
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/InsertBlankLineBetweenFuncProcCheck.java
@@ -0,0 +1,70 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.util.List;
+
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.ProgramTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.EsqlFile;
+import com.exxeta.iss.sonar.esql.api.visitors.LineIssue;
+
+/**
+ * This java class is created to implement the logic for checking there should be one blank line between procedure and function.
+ * @author C50679
+ *
+ */
+@Rule(key = "InsertBlankLineBetweenFuncProc")
+public class InsertBlankLineBetweenFuncProcCheck extends DoubleDispatchVisitorCheck{
+
+ private static final String MESSAGE = "Insert one blank line between functions and procedures.";
+
+
+ @Override
+ public void visitProgram(ProgramTree tree) {
+ EsqlFile file = getContext().getEsqlFile();
+ List lines = CheckUtils.readLines(file);
+
+ int linecounter = 0;
+ for (String line : lines) {
+
+ linecounter = linecounter + 1;
+
+
+ if(isEndStatement(line)){
+
+
+ if(linecounter nonReservedKeywords = ImmutableSet.copyOf(EsqlNonReservedKeyword.keywordValues());
+ private static final Set reservedKeywords = ImmutableSet.copyOf(EsqlReservedKeyword.keywordValues());
+ private static final String MESSAGE = "This keyword should be in uppercase.";
+
+ @Override
+ public Set nodesToVisit() {
+ return ImmutableSet.of(Tree.Kind.TOKEN);
+ }
+
+ @Override
+ public void visitNode(Tree tree) {
+ String value = ((InternalSyntaxToken) tree).text();
+ String upperCase = value.toUpperCase();
+ if (!value.equals(upperCase)
+ && (reservedKeywords.contains(upperCase) || nonReservedKeywords.contains(upperCase))
+ && !(tree.parent().parent() instanceof PathElementNameTree)
+ && !(tree.parent() instanceof IdentifierTree)
+ && !(tree.parent() instanceof SchemaNameTree)) {
+ addIssue(tree, MESSAGE);
+ }
+ super.visitNode(tree);
+ }
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/LineLengthCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/LineLengthCheck.java
index 700d08f0..fdba0d8f 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/LineLengthCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/LineLengthCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/LoopWithoutLeaveCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/LoopWithoutLeaveCheck.java
index 287e8561..509cecd3 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/LoopWithoutLeaveCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/LoopWithoutLeaveCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/MissingNewlineAtEndOfFileCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/MissingNewlineAtEndOfFileCheck.java
index 2fd66d0b..c7bb891f 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/MissingNewlineAtEndOfFileCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/MissingNewlineAtEndOfFileCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,7 +34,7 @@ public class MissingNewlineAtEndOfFileCheck extends DoubleDispatchVisitorCheck {
public void visitProgram(ProgramTree tree) {
SyntaxToken lastToken = null;
- if (tree.esqlContents() != null && tree.esqlContents().items().size()>0) {
+ if (!tree.esqlContents().items().isEmpty()) {
lastToken = ((EsqlTree) tree.esqlContents()).lastToken();
} else if (tree.semiToken()!=null){
lastToken=tree.semiToken();
@@ -45,7 +45,7 @@ public void visitProgram(ProgramTree tree) {
}
if (lastToken!=null){
int lastLine = tree.EOFToken().line();
- int lastTokenLine = ((EsqlTree) tree.esqlContents()).lastToken().endLine();
+ int lastTokenLine = lastToken.endLine();
if (lastLine == lastTokenLine) {
addIssue(new FileIssue(this, MESSAGE));
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ModuleNameCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ModuleNameCheck.java
index 382fd81e..bf4b265e 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ModuleNameCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ModuleNameCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheck.java
new file mode 100644
index 00000000..2e800e2a
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheck.java
@@ -0,0 +1,158 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.sonar.check.Rule;
+import org.sonar.check.RuleProperty;
+
+import com.exxeta.iss.sonar.esql.api.tree.ProgramTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.EsqlFile;
+import com.exxeta.iss.sonar.esql.api.visitors.LineIssue;
+
+/**
+ * This java class is created to implement the logic for reference check, Navigating message tree could be replaced by a reference.
+ * @author Sapna singh
+ *
+ */
+@Rule(key = "NavigatingTreeCouldBeReference")
+public class NavigatingTreeCouldBeReferenceCheck extends DoubleDispatchVisitorCheck{
+
+ private static final String MESSAGE = "Navigating message tree could be replaced by a reference.";
+
+ private static final int DEFAULT_THRESHOLD = 3;
+ @RuleProperty(
+ key = "NavigatingTreeCouldBeReference",
+ description = "Navigating message tree could be replaced by a reference.",
+ defaultValue = "" + DEFAULT_THRESHOLD)
+ public static int threshold = DEFAULT_THRESHOLD;
+
+
+
+ @Override
+ public void visitProgram(ProgramTree tree) {
+
+ EsqlFile file = getContext().getEsqlFile();
+ List lines = CheckUtils.readLines(file);
+
+
+
+ HashSet violatingLinesWithPossibleReference = new HashSet<>();
+ int startingLine = 0;
+
+
+ processSingleModuleForReferences( startingLine, lines, violatingLinesWithPossibleReference);
+
+
+ Set linesNumbers = new HashSet<>();
+ Iterator iterator1 = violatingLinesWithPossibleReference.iterator();
+ do
+ {
+ if(!iterator1.hasNext())
+ break;
+
+ Integer lineNumber = iterator1.next();
+ if(linesNumbers.add(lineNumber))
+ {
+ addIssue(new LineIssue(this, lineNumber, MESSAGE ));
+ }
+ } while(true);
+
+ }
+
+ private static void processSingleModuleForReferences( int startingLine, List moduleLines, HashSet violatingLinesWithPossibleReference)
+ {
+ HashMap allKeys = new HashMap<>();
+ Iterator iterator = moduleLines.iterator();
+
+ do
+ {
+ if(!iterator.hasNext())
+ break;
+ String line = iterator.next();
+
+ line = line.trim();
+ String removeQuotedComment = CheckUtils.removeQuotedContentByChar(line, '\'');
+ if(removeQuotedComment.toUpperCase().trim().startsWith("SET "))
+ {
+ removeQuotedComment = removeQuotedComment.substring(4);
+ if(removeQuotedComment.trim().endsWith(";"))
+ removeQuotedComment = removeQuotedComment.substring(0, removeQuotedComment.length() - 1);
+ int equalsPos = removeQuotedComment.indexOf('=');
+ if(equalsPos > 0) {
+ String endLine = null;
+ String startLine = removeQuotedComment.substring(0, equalsPos).trim();
+ if (!(equalsPos + 1 > removeQuotedComment.length())){
+ endLine = removeQuotedComment.substring(equalsPos + 1).trim();
+ }
+ Set keyValuesAll = new HashSet<>();
+ Set keyValuesStart = CheckUtils.buildKeys(startLine);
+ Set keyValuesEnd = new HashSet<>();
+ if (endLine!=null){
+ CheckUtils.buildKeys(endLine);
+ }
+
+ keyValuesStart.addAll(keyValuesEnd);
+ for(Iterator iterator1 = keyValuesStart.iterator(); iterator1.hasNext();) {
+ String key = iterator1.next();
+ if (!key.contains("OutputLocalEnvironment") && !key.contains("InputLocalEnvironment")) {
+ keyValuesAll.add(key);
+ }
+ }
+
+ Iterator iterator2 = keyValuesAll.iterator();
+ while(iterator2.hasNext())
+ {
+ String key = iterator2.next();
+ if(key == null || key.length() == 0)
+ throw new RuntimeException((new StringBuilder()).append("Key is empty: ").append(key).append(" for line:").append(line).toString());
+ Integer count = allKeys.get(key);
+ if(count == null)
+ allKeys.put(key, 1);
+ else
+ allKeys.put(key, count.intValue() + 1);
+ }
+ }
+ }
+ } while(true);
+ iterator = allKeys.keySet().iterator();
+
+ do
+ {
+ if(!iterator.hasNext())
+ break;
+ String key = iterator.next();
+ Integer count = allKeys.get(key);
+ if(count.intValue() > threshold )
+ {
+ Integer lineNumber = CheckUtils.findLineInText(moduleLines, key);
+ if(lineNumber == null)
+ throw new RuntimeException((new StringBuilder()).append("Cannot find line again ").append(key).toString());
+ Integer absLine = Integer.valueOf(lineNumber.intValue() + startingLine);
+ violatingLinesWithPossibleReference.add(absLine);
+ }
+ } while(true);
+ }
+ }
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NestedIfDepthCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NestedIfDepthCheck.java
index 612feade..b634d324 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NestedIfDepthCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NestedIfDepthCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NonReservedKeywordCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NonReservedKeywordCheck.java
index 0d9dd21c..95518b9b 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NonReservedKeywordCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NonReservedKeywordCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/OneStatementPerLineCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/OneStatementPerLineCheck.java
index 101915c4..bc80f2b9 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/OneStatementPerLineCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/OneStatementPerLineCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,18 +17,18 @@
*/package com.exxeta.iss.sonar.esql.check;
import java.util.List;
+import java.util.Set;
import org.sonar.check.Rule;
import com.exxeta.iss.sonar.esql.api.tree.Tree;
import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
-import com.exxeta.iss.sonar.esql.api.tree.statement.StatementTree;
import com.exxeta.iss.sonar.esql.api.visitors.IssueLocation;
import com.exxeta.iss.sonar.esql.api.visitors.PreciseIssue;
import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitorCheck;
import com.exxeta.iss.sonar.esql.tree.impl.EsqlTree;
import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ListMultimap;
@Rule(key = "OneStatementPerLine")
@@ -38,14 +38,42 @@ public class OneStatementPerLineCheck extends SubscriptionVisitorCheck {
private static final String MESSAGE = "Reformat the code to have only one statement per line.";
- private ListMultimap statementsPerLine = ArrayListMultimap.create();
+ private ListMultimap statementsPerLine = ArrayListMultimap.create();
@Override
- public List nodesToVisit() {
- return ImmutableList.of(
+ public Set nodesToVisit() {
+ return ImmutableSet.of(
Kind.IF_STATEMENT,
- Kind.BEGIN_END_STATEMENT,
- Kind.SET_STATEMENT,
+ Kind.DECLARE_STATEMENT,
+ Kind.BROKER_SCHEMA_STATEMENT,
+ Kind.CREATE_FUNCTION_STATEMENT,
+ Kind.CREATE_MODULE_STATEMENT,
+ Kind.CREATE_PROCEDURE_STATEMENT,
+ Kind.PROPAGATE_STATEMENT,
+ Kind.SET_STATEMENT,
+ Kind.ITERATE_STATEMENT,
+ Kind.CALL_STATEMENT,
+ Kind.CASE_STATEMENT,
+ Kind.LEAVE_STATEMENT,
+ Kind.LOOP_STATEMENT,
+ Kind.REPEAT_STATEMENT,
+ Kind.RETURN_STATEMENT,
+ Kind.THROW_STATEMENT,
+ Kind.WHILE_STATEMENT,
+ Kind.ATTACH_STATEMENT,
+ Kind.CREATE_STATEMENT,
+ Kind.DELETE_STATEMENT,
+ Kind.DETACH_STATEMENT,
+ Kind.RESIGNAL_STATEMENT,
+ Kind.FOR_STATEMENT,
+ Kind.MOVE_STATEMENT,
+ Kind.DELETE_FROM_STATEMENT,
+ Kind.INSERT_STATEMENT,
+ Kind.PASSTHRU_STATEMENT,
+ Kind.UPDATE_STATEMENT,
+ Kind.DECLARE_HANDLER_STATEMENT,
+ Kind.EVAL_STATEMENT,
+ Kind.LOG_STATEMENT,
Kind.PROGRAM);
}
@@ -59,7 +87,7 @@ public void visitNode(Tree tree) {
if (!tree.is(Kind.PROGRAM)){
- statementsPerLine.put(((EsqlTree) tree).getLine(), (StatementTree) tree);
+ statementsPerLine.put(((EsqlTree) tree).getLine(), tree);
}
}
@@ -69,7 +97,7 @@ public void visitNode(Tree tree) {
public void leaveNode(Tree tree) {
if (tree.is(Kind.PROGRAM)){
for (int line : statementsPerLine.keys().elementSet()) {
- List statementsAtLine = statementsPerLine.get(line);
+ List statementsAtLine = statementsPerLine.get(line);
if (statementsAtLine.size() > 1) {
addIssue(statementsAtLine);
@@ -78,7 +106,7 @@ public void leaveNode(Tree tree) {
}
}
- private void addIssue(List statementsAtLine) {
+ private void addIssue(List statementsAtLine) {
PreciseIssue issue = addIssue(statementsAtLine.get(1), MESSAGE);
for (int i = 2; i < statementsAtLine.size(); i++) {
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ParameterWithDirectionCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ParameterWithDirectionCheck.java
index 0386131d..5535c88d 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ParameterWithDirectionCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ParameterWithDirectionCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ParsingErrorCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ParsingErrorCheck.java
index 9ab420f0..b56859a0 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ParsingErrorCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ParsingErrorCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/PassThruStatementCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/PassThruStatementCheck.java
new file mode 100644
index 00000000..0e0f18ba
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/PassThruStatementCheck.java
@@ -0,0 +1,78 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.Tree;
+import com.exxeta.iss.sonar.esql.tree.expression.LiteralTree;
+
+/**
+ * This java class is created to implement the logic to check the PassThru
+ * Statement. When PASSTHRU statement is used in ESQL,Use parameter markers '?'
+ *
+ * @author Sapna Singh
+ *
+ */
+
+@Rule(key = "PassThruStatement")
+public class PassThruStatementCheck extends AbstractPassthruCheck {
+
+ private static final String MESSAGE = "Use parameter markers '?' when using the PASSTHRU statement in ESQL";
+
+ @Override
+ protected void checkLiterals(Tree tree, List literals) {
+
+ StringBuilder query =new StringBuilder();
+ for (LiteralTree literal:literals){
+ query.append(literal.value());
+ }
+
+ boolean isQueryWhereComplient = false;
+ String queryString = query.toString().toUpperCase();
+ if (queryString.trim().contains("WHERE")) {
+ String whereClause = queryString.substring(queryString.indexOf("WHERE"));
+ whereClause = CheckUtils.removeQuotedContent(whereClause);
+ whereClause = whereClause.replaceAll(" ", "");
+
+ if (whereClause.contains("GROUPBY")) {
+ whereClause = whereClause.substring(0, whereClause.indexOf("GROUPBY"));
+ } else if (whereClause.contains("ORDERBY")) {
+ whereClause = whereClause.substring(0, whereClause.indexOf("ORDERBY"));
+ }
+
+ if (StringUtils.countMatches(whereClause, "=") != StringUtils.countMatches(whereClause, "?")) {
+ isQueryWhereComplient = false;
+ } else {
+ isQueryWhereComplient = true;
+ }
+
+ } else {
+ isQueryWhereComplient = true;
+ }
+ if (!isQueryWhereComplient){
+ addIssue(tree, MESSAGE);
+ }
+
+
+ }
+
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ProcedureNameCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ProcedureNameCheck.java
index edf5c754..f1115247 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ProcedureNameCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ProcedureNameCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ProcessInvokingItselfCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ProcessInvokingItselfCheck.java
new file mode 100644
index 00000000..578d3125
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/ProcessInvokingItselfCheck.java
@@ -0,0 +1,74 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.expression.CallExpressionTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CallStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateFunctionStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateProcedureStatementTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.LineIssue;
+
+/**
+ * This Java class is created to implement the logic to check whether process is
+ * invoking itself.
+ *
+ * @author Sapna Singh
+ *
+ */
+@Rule(key = "ProcessInvokingItself")
+public class ProcessInvokingItselfCheck extends DoubleDispatchVisitorCheck {
+
+ private static final String MESSAGE = "process invoking itself.";
+ private String routineName;
+
+ @Override
+ public void visitCreateFunctionStatement(CreateFunctionStatementTree tree) {
+ routineName = tree.identifier().name();
+ super.visitCreateFunctionStatement(tree);
+ routineName=null;
+ }
+
+ @Override
+ public void visitCreateProcedureStatement(CreateProcedureStatementTree tree) {
+ routineName = tree.identifier().name();
+ super.visitCreateProcedureStatement(tree);
+ routineName=null;
+ }
+
+ @Override
+ public void visitCallExpression(CallExpressionTree tree) {
+ //TODO Check if firstToken can be replaced
+ if (routineName!=null && tree.functionName()!=null && tree.functionName().firstToken()!=null && routineName.equals(tree.functionName().firstToken().text())){
+ addIssue(new LineIssue(this, tree, MESSAGE));
+ }
+ super.visitCallExpression(tree);
+ }
+
+ @Override
+ public void visitCallStatement(CallStatementTree tree) {
+ //TODO Check if firstToken can be replaced
+ if (routineName!=null && routineName.equals(tree.routineName().firstToken().text())){
+ addIssue(new LineIssue(this, tree, MESSAGE));
+ }
+ super.visitCallStatement(tree);
+ }
+
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/PropagateConsistencyCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/PropagateConsistencyCheck.java
new file mode 100644
index 00000000..c5fc17b2
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/PropagateConsistencyCheck.java
@@ -0,0 +1,198 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.math.NumberUtils;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.Tree;
+import com.exxeta.iss.sonar.esql.api.tree.expression.ExpressionTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateFunctionStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateModuleStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateProcedureStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.PropagateStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.ReturnStatementTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.EsqlFile;
+import com.exxeta.iss.sonar.esql.tree.expression.LiteralTree;
+import com.exxeta.iss.sonar.esql.tree.impl.expression.PrefixExpressionTreeImpl;
+import com.exxeta.iss.sonar.esql.tree.impl.statement.CreateRoutineTreeImpl;
+import com.exxeta.iss.sonar.msgflow.model.MessageFlow;
+import com.exxeta.iss.sonar.msgflow.model.MessageFlowNode;
+import com.exxeta.iss.sonar.msgflow.model.MessageFlowParser;
+
+@Rule(key = "PropagateConsistency")
+public class PropagateConsistencyCheck extends DoubleDispatchVisitorCheck {
+
+ private static final String MESSAGE = "Compute node connections are inconsistent";
+ private static final Logger LOG = Loggers.get(PropagateConsistencyCheck.class);
+
+ private MessageFlowNode msgFlownode = null;
+
+ private CreateRoutineTreeImpl currentRoutine;
+
+ @Override
+ public void visitCreateModuleStatement(CreateModuleStatementTree tree) {
+ String moduleName = tree.moduleName().name();
+ EsqlFile esqlFile = getContext().getEsqlFile();
+ File projectDirectory = getProjectDirectory(esqlFile);
+
+ if (projectDirectory != null) {
+
+ msgFlowLoop: for (MessageFlow msgFlow : getMsgFlowFiles(projectDirectory)) {
+ for (MessageFlowNode node : msgFlow.getComputeNodes()) {
+ if (((String) node.getProperties().get("computeExpression")).equals(moduleName)) {
+ msgFlownode = node;
+ break msgFlowLoop;
+ }
+ }
+ }
+ }
+ super.visitCreateModuleStatement(tree);
+ msgFlownode = null;
+
+ }
+
+ private File getProjectDirectory(EsqlFile esqlFile) {
+ File projectDirectory = new File(new File(esqlFile.relativePath()).getAbsolutePath());
+ if (!projectDirectory.isDirectory()){
+ projectDirectory=projectDirectory.getParentFile();
+ }
+ while (projectDirectory != null) {
+ LOG.info("Checking "+(projectDirectory==null?"null":projectDirectory.getAbsolutePath()));
+ if (new File(projectDirectory, ".project").exists()) {
+ LOG.info("Returning "+(projectDirectory==null?"null":projectDirectory.getAbsolutePath()));
+ return projectDirectory;
+ }
+ projectDirectory = projectDirectory.getParentFile();
+ }
+ LOG.info("Nothing found.");
+ return null;
+ }
+
+ @Override
+ public void visitCreateFunctionStatement(CreateFunctionStatementTree tree) {
+ currentRoutine = (CreateRoutineTreeImpl) tree;
+ super.visitCreateFunctionStatement(tree);
+ currentRoutine = null;
+ }
+
+ @Override
+ public void visitCreateProcedureStatement(CreateProcedureStatementTree tree) {
+ currentRoutine = (CreateRoutineTreeImpl) tree;
+ super.visitCreateProcedureStatement(tree);
+ currentRoutine = null;
+ }
+
+ @Override
+ public void visitReturnStatement(ReturnStatementTree tree) {
+ if (currentRoutine instanceof CreateFunctionStatementTree // must be a function
+ && "MAIN".equalsIgnoreCase(currentRoutine.identifier().name()) // must
+ // be
+ // the
+ // main
+ // function
+ && "true".equalsIgnoreCase(tree.expression().toString())) { // must return TRUE
+ checkTerminal("OutTerminal.out", tree);
+ }
+
+ super.visitReturnStatement(tree);
+ }
+
+ private void checkTerminal(String terminalName, Tree tree) {
+ if (msgFlownode != null // msgFlow needs to be found
+ && !msgFlownode.getOutputTerminals().contains(terminalName)) {
+ addIssue(tree, MESSAGE);
+
+ }
+
+ }
+
+ @Override
+ public void visitPropagateStatement(PropagateStatementTree propagateStatement) {
+ if (propagateStatement.targetType() == null){
+ checkTerminal("OutTerminal.out", propagateStatement);
+ }else if ( "TERMINAL".equalsIgnoreCase(propagateStatement.targetType().text())) {
+ String terminalName = getTerminalName(propagateStatement.target());
+ if (terminalName!=null){
+ checkTerminal("OutTerminal." + terminalName, propagateStatement);
+ }
+ }
+
+ super.visitPropagateStatement(propagateStatement);
+ }
+
+ private static List getMsgFlowFiles(File directory) {
+ ArrayList fileList = new ArrayList<>();
+ for (File tmpFile : directory.listFiles()) {
+ if (tmpFile.isDirectory()) {
+ fileList.addAll(getMsgFlowFiles(tmpFile));
+ } else {
+ if (tmpFile.getAbsolutePath().endsWith(".msgflow")) {
+ fileList.add(new MessageFlow(tmpFile.getAbsolutePath(), new MessageFlowParser()));
+ }
+ }
+ }
+ return fileList;
+ }
+
+ private static String getTerminalName(ExpressionTree expression) {
+ String target = null;
+ if (expression instanceof LiteralTree){
+ target = ((LiteralTree)expression).value().replace("'", "");
+ }else if (expression instanceof PrefixExpressionTreeImpl){
+ PrefixExpressionTreeImpl prefixEx = (PrefixExpressionTreeImpl) expression;
+ target = prefixEx.operator().text() + prefixEx.expression().toString();
+ }
+
+ String terminal = "";
+
+
+ if (NumberUtils.isNumber(target)) {
+ int terminalNo = Integer.parseInt(target);
+ switch (terminalNo) {
+ case -2:
+ terminal = "nowhere";
+ break;
+ case -1:
+ terminal = "failure";
+ break;
+ case 0:
+ terminal = "out";
+ break;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ terminal = "out" + terminalNo;
+ break;
+ default:
+ terminal = "nowhere";
+ }
+ return terminal;
+ } else {
+ return target;
+ }
+ }
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/PropagateToLabelCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/PropagateToLabelCheck.java
index 5b99e0d4..6e5978fb 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/PropagateToLabelCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/PropagateToLabelCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/RoutineCommentsCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/RoutineCommentsCheck.java
new file mode 100644
index 00000000..134bf5b1
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/RoutineCommentsCheck.java
@@ -0,0 +1,93 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import org.apache.commons.lang.StringUtils;
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.RoutineDeclarationTree;
+import com.exxeta.iss.sonar.esql.api.tree.Tree;
+import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxTrivia;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateFunctionStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.CreateProcedureStatementTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+
+/**
+ * This Java class is created to check function or procedure header comments
+ * @author
+ *
+ */
+@Rule(key="RoutineComments")
+public class RoutineCommentsCheck extends DoubleDispatchVisitorCheck{
+
+
+ private static final String MESSAGE = "Document this %s with all parameters and return types.";
+
+
+ @Override
+ public void visitCreateFunctionStatement(CreateFunctionStatementTree tree) {
+ visitRoutine(tree, String.format(MESSAGE, "function"));
+ super.visitCreateFunctionStatement(tree);
+
+ }
+
+ @Override
+ public void visitCreateProcedureStatement(CreateProcedureStatementTree tree) {
+ visitRoutine(tree, String.format(MESSAGE, "procedure"));
+ super.visitCreateProcedureStatement(tree);
+ }
+
+ private void visitRoutine(RoutineDeclarationTree tree, String message) {
+ String comment = getComment(tree);
+
+ // check comments
+ if (isEmptyComment(comment)|| !containsAny(comment,new String[]{"Parameters:","IN:","INOUT:","OUT:","RETURNS:"})){
+ addIssue(tree.firstToken(), message);
+ }
+ }
+
+ private boolean containsAny(String haystack, String[] needles) {
+ for (String needle : needles){
+ if (haystack.contains(needle)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static String getComment(Tree tree){
+ for (SyntaxTrivia syntaxTrivia : tree.firstToken().trivias()){
+ if (syntaxTrivia.text().startsWith("/*")){
+ return syntaxTrivia.text();
+ }
+ }
+
+ return null;
+ }
+
+
+ private static boolean isEmptyComment(String comment) {
+ if (comment == null) {
+ return true;
+ }
+ // remove start and end of doc as well as stars.
+ String cleanedupJavadoc = comment.trim().substring(2).replace("*/", "").replace("*", "").trim();
+ return StringUtils.isBlank(cleanedupJavadoc);
+ }
+
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/RoutineWithExcessiveReturnsCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/RoutineWithExcessiveReturnsCheck.java
index 6914c2e6..aa394055 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/RoutineWithExcessiveReturnsCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/RoutineWithExcessiveReturnsCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SelectAllCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SelectAllCheck.java
index 916b6cd3..904a29a7 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SelectAllCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SelectAllCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,29 +25,64 @@
import com.exxeta.iss.sonar.esql.api.tree.PathElementTree;
import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
import com.exxeta.iss.sonar.esql.api.tree.function.AliasedExpressionTree;
+import com.exxeta.iss.sonar.esql.api.tree.function.PassthruFunctionTree;
import com.exxeta.iss.sonar.esql.api.tree.function.SelectFunctionTree;
import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.tree.expression.LiteralTree;
-@Rule(key="SelectAll")
-public class SelectAllCheck extends DoubleDispatchVisitorCheck{
+@Rule(key = "SelectAll")
+public class SelectAllCheck extends DoubleDispatchVisitorCheck {
+
+ private static final String MESSAGE = "Specify the needed fields.";
+ private PassthruFunctionTree passthruTree = null;
@Override
public void visitSelectFunction(SelectFunctionTree tree) {
- for (AliasedExpressionTree aliased : tree.selectClause().aliasedFieldReferenceList()){
- if (aliased.expression()!= null && aliased.expression().is(Kind.FIELD_REFERENCE)){
+ for (AliasedExpressionTree aliased : tree.selectClause().aliasedFieldReferenceList()) {
+ if (aliased.expression() != null && aliased.expression().is(Kind.FIELD_REFERENCE)) {
FieldReferenceTree fieldReference = (FieldReferenceTree) aliased.expression();
- if ("*".equals(fieldReference.pathElement().name().name().text())){
- addIssue(fieldReference, "Specify the needed fields.");
+ if (fieldReference.pathElement().name().star()!=null) {
+ addIssue(fieldReference, MESSAGE);
}
Iterator iter = fieldReference.pathElements().iterator();
- while (iter.hasNext()){
+ while (iter.hasNext()) {
PathElementTree element = iter.next();
- if ("*".equals(element.name().name().text())){
- addIssue(fieldReference, "Specify the needed fields.");
- }
+ if (element.name().star()!=null) {
+ addIssue(fieldReference, MESSAGE);
+ }
}
}
}
}
+
+ @Override
+ public void visitPassthruFunction(PassthruFunctionTree tree) {
+ this.passthruTree =tree;
+ super.visitPassthruFunction(tree);
+ this.passthruTree=null;
+ }
+ @Override
+ public void visitLiteral(LiteralTree tree) {
+ if (this.passthruTree!=null && tree.is(Kind.STRING_LITERAL)) {
+ checkSqlString(tree.value(),
+ passthruTree);
+ }
+
+ super.visitLiteral(tree);
+ }
+
+ /*
+ * Very simple implementation to check if there are any * in the sql
+ * statement.
+ */
+ private void checkSqlString(String sqlStatement, PassthruFunctionTree expression) {
+ String unqotedStatement = CheckUtils.removeQuotedContent(sqlStatement.substring(1, sqlStatement.length() - 1))
+ .trim();
+ if (unqotedStatement.startsWith("SELECT") && unqotedStatement.contains("*")) {
+ addIssue(expression, MESSAGE);
+
+ }
+ }
+
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SelfAssignmentCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SelfAssignmentCheck.java
new file mode 100644
index 00000000..a674c2f4
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SelfAssignmentCheck.java
@@ -0,0 +1,42 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.statement.SetStatementTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.tree.SyntacticEquivalence;
+
+@Rule(key = "SelfAssignment")
+public class SelfAssignmentCheck extends DoubleDispatchVisitorCheck {
+
+ private static final String MESSAGE = "Remove or correct this useless self-assignment.";
+
+ @Override
+ public void visitSetStatement(SetStatementTree tree) {
+
+ if ( SyntacticEquivalence.areEquivalent( tree.variableReference(), tree.expression())) {
+ addIssue(tree, MESSAGE);
+ }
+
+ super.visitSetStatement(tree);
+ }
+
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SleepCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SleepCheck.java
index 30936ef6..8ea839e0 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SleepCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SleepCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,19 +17,23 @@
*/
package com.exxeta.iss.sonar.esql.check;
+import java.util.List;
+
import org.sonar.check.Rule;
+import com.google.common.collect.ImmutableList;
+
@Rule(key="Sleep")
-public class SleepCheck extends AbstractDoNotUseFunctinCheck {
+public class SleepCheck extends AbstractDoNotUseFunctionCheck {
@Override
- public String getMessage() {
+ public String getMessage(String functionName) {
return "SLEEP should not be used because it blocks the executing thread.";
}
@Override
- public String getFunctionName() {
- return "SLEEP";
+ public List getFunctionNames() {
+ return ImmutableList.of("SLEEP");
}
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SubElementNameCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SubElementNameCheck.java
new file mode 100644
index 00000000..989a0fb3
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/SubElementNameCheck.java
@@ -0,0 +1,107 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.sonar.check.Rule;
+
+
+import com.exxeta.iss.sonar.esql.api.tree.ProgramTree;
+
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.EsqlFile;
+
+import com.exxeta.iss.sonar.esql.api.visitors.LineIssue;
+
+
+/**
+ * This java class is created to implement the logic to check sub-elements should be in UpperCamel-case and elements containing simple value should be in lowercase.
+ * @author sapna singh
+ *
+ */
+@Rule(key="SubElementName")
+public class SubElementNameCheck extends DoubleDispatchVisitorCheck{
+
+ private static final String MESSAGE = "sub-elements should be in UpperCamel-case and elements containing simple value should be in lowercase.";
+
+ private static final String UPPERCASE_FORMAT = "^[A-Z][a-zA-Z0-9]*$";
+ private static final String LOWERCASE_FORMAT = "^[a-z][a-zA-Z0-9]*$";
+
+
+
+ @Override
+ public void visitProgram(ProgramTree tree) {
+ EsqlFile file = getContext().getEsqlFile();
+ List lines = CheckUtils.readLines(file);
+ int i = 0;
+ for (String line : lines) {
+ i =i+1;
+
+ if(line.trim().startsWith("SET Environment")){
+
+ String[] strArr1 = line.split(Pattern.quote("="));
+
+
+ if (strArr1.length > 0){
+
+ String envSubElement = strArr1[0];
+ String envSubElement1 = null;
+ if (!(line.indexOf("Environment") + 12 > line.length())){
+ if (!(line.indexOf("Environment") + 12 > envSubElement.length())){
+ envSubElement1 = envSubElement.substring(line.indexOf("Environment")+12,line.indexOf("="));
+ }
+ String[] strArray = envSubElement1.split(Pattern.quote("."));
+
+ int strCount =0;
+ for(String str:strArray){
+ strCount++;
+
+ if(!str.matches(UPPERCASE_FORMAT) && (strCount != strArray.length)){
+
+
+ addIssue(new LineIssue(this, i, MESSAGE ));
+ }
+
+ }
+
+ String lastElement =strArray[strArray.length - 1].trim();
+ if(!lastElement.matches(LOWERCASE_FORMAT)){
+ addIssue(new LineIssue(this, i, MESSAGE ));
+ }
+
+ }
+ }
+
+
+
+ }
+ }
+
+ }
+}
+
+
+
+
+
+
+
+
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/Tags.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/Tags.java
index 1326e0c1..322aa70b 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/Tags.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/Tags.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,8 +27,17 @@ public class Tags {
public static final String CERT = "cert";
public static final String PITFALL = "pitfall";
public static final String CONFUSING = "confusing";
-
+ public static final String DATABASE = "database";
+ public static final String PERFORMANCE = "performance";
+ public static final String READABILITY = "readability";
+ public static final String STANDARDS = "standards";
+ public static final String COMPLEXITY = "complexity";
+ public static final String COMPLETNESS = "completness";
+ public static final String CORRECTNESS = "correctness";
+ public static final String DEPRICATED = "depricated";
+
+
private Tags() {
// This class only defines constants
}
-}
\ No newline at end of file
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TooManyIterateOrLeaveInLoopCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TooManyIterateOrLeaveInLoopCheck.java
index 4913d0e6..15015ae6 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TooManyIterateOrLeaveInLoopCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TooManyIterateOrLeaveInLoopCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,8 +22,6 @@
import java.util.Deque;
import java.util.List;
-import javax.annotation.Nullable;
-
import org.sonar.check.Rule;
import com.exxeta.iss.sonar.esql.api.tree.ProgramTree;
@@ -150,9 +148,9 @@ private void leaveScope() {
jumpTargets.pop();
}
- private void increaseNumberOfJumpInScopes(SyntaxToken jump, @Nullable LabelTree label) {
+ private void increaseNumberOfJumpInScopes(SyntaxToken jump, LabelTree label) {
+ String labelName = label.name().name();
for (JumpTarget jumpTarget : jumpTargets) {
- String labelName = label == null ? null : label.name().name();
jumpTarget.jumps.add(jump);
if (Objects.equal(labelName, jumpTarget.label)) {
@@ -172,26 +170,5 @@ private void leaveScopeAndCheckNumberOfJump(SyntaxToken loopKeyword) {
}
}
- /*
- *
- * @Override public void init() { subscribeTo(EsqlGrammar.beginEndStatement,
- * EsqlGrammar.whileStatement, EsqlGrammar.repeatStatement,
- * EsqlGrammar.loopStatement); }
- *
- *
- * @Override public void visitNode(AstNode astNode) { if
- * (astNode.getFirstChild(EsqlGrammar.LABEL)!=null){ String labelName =
- * astNode.getFirstChild(EsqlGrammar.LABEL).getTokenOriginalValue(); int
- * countIterate = 0; int countLeave = 0; for (AstNode statement:
- * astNode.getDescendants(EsqlGrammar.iterateStatement)){ String innerLabel
- * = statement.getFirstChild(EsqlGrammar.LABEL).getTokenOriginalValue(); if
- * (innerLabel.equals(labelName)){ countIterate++; } } for (AstNode
- * statement: astNode.getDescendants(EsqlGrammar.leaveStatement)){ String
- * innerLabel =
- * statement.getFirstChild(EsqlGrammar.LABEL).getTokenOriginalValue(); if
- * (innerLabel.equals(labelName)){ countLeave++; } } if (countIterate>1 ||
- * countLeave>1){ getContext().createLineViolation(this,
- * "Loops should not contain more than a single \"ITERATE\" or \"LEAVE\" statement."
- * , astNode); } } }
- */
+
}
\ No newline at end of file
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TooManyLinesInFileCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TooManyLinesInFileCheck.java
index 8c6c2544..f439f50e 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TooManyLinesInFileCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TooManyLinesInFileCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,7 @@
*/
package com.exxeta.iss.sonar.esql.check;
-import java.util.List;
+import java.util.Set;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
@@ -29,7 +29,7 @@
import com.exxeta.iss.sonar.esql.api.visitors.FileIssue;
import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitorCheck;
import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
@Rule(key = "TooManyLinesInFile")
@NoSqale
@@ -62,7 +62,7 @@ public void visitNode(Tree tree) {
}
@Override
- public List nodesToVisit() {
- return ImmutableList.of(Tree.Kind.TOKEN);
+ public Set nodesToVisit() {
+ return ImmutableSet.of(Tree.Kind.TOKEN);
}
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TooManyParametersCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TooManyParametersCheck.java
index d2b69e1c..1c724a0c 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TooManyParametersCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TooManyParametersCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +23,8 @@
import com.exxeta.iss.sonar.esql.api.tree.statement.CreateFunctionStatementTree;
import com.exxeta.iss.sonar.esql.api.tree.statement.CreateProcedureStatementTree;
import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.api.visitors.IssueLocation;
+import com.exxeta.iss.sonar.esql.api.visitors.PreciseIssue;
@Rule(key = "TooManyParameters")
public class TooManyParametersCheck extends DoubleDispatchVisitorCheck {
@@ -38,7 +40,7 @@ public void visitCreateFunctionStatement(CreateFunctionStatementTree tree) {
int size = tree.parameterList().size();
if (size > maximum) {
- addIssue(tree, "Function has " + size + " parameters, which is greater than " + maximum + " authorized.");
+ addIssue(new PreciseIssue(this, new IssueLocation(tree.openingParenthesis(), tree.closingParenthesis(), "Function has " + size + " parameters, which is greater than " + maximum + " authorized.")));
}
}
@@ -46,7 +48,7 @@ public void visitCreateFunctionStatement(CreateFunctionStatementTree tree) {
public void visitCreateProcedureStatement(CreateProcedureStatementTree tree) {
int size = tree.parameterList().size();
if (size > maximum) {
- addIssue(tree, "Procedure has " + size + " parameters, which is greater than " + maximum + " authorized.");
+ addIssue(new PreciseIssue(this, new IssueLocation(tree.openingParenthesis(), tree.closingParenthesis(), "Procedure has " + size + " parameters, which is greater than " + maximum + " authorized.")));
}
}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TrailingCommentsCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TrailingCommentsCheck.java
new file mode 100644
index 00000000..4cb0745d
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/TrailingCommentsCheck.java
@@ -0,0 +1,88 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.sonar.check.Rule;
+import org.sonar.check.RuleProperty;
+
+import com.exxeta.iss.sonar.esql.api.tree.Tree;
+import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken;
+import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxTrivia;
+import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitorCheck;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * This java class is created to implement the logic for checking if the line
+ * contains both code and comments, if it contains both then trailing comments
+ * should be removed.
+ *
+ *
+ * @author Prerana Agarkar
+ *
+ */
+
+@Rule(key = "TrailingComments")
+public class TrailingCommentsCheck extends SubscriptionVisitorCheck {
+
+ private static final String MESSAGE = "Move this trailing comment on the previous empty line.";
+
+ private static final String DEFAULT_LEGAL_COMMENT_PATTERN = "^--NOSONAR\\s*";
+
+ @RuleProperty(
+ key = "legalCommentPattern",
+ description = "Pattern for text of trailing comments that are allowed.",
+ defaultValue = DEFAULT_LEGAL_COMMENT_PATTERN)
+ private String legalCommentPattern = DEFAULT_LEGAL_COMMENT_PATTERN;
+
+ private Pattern pattern;
+ private int previousTokenLine;
+
+ @Override
+ public Set nodesToVisit() {
+ return ImmutableSet.of(Tree.Kind.TOKEN);
+ }
+
+ @Override
+ public void visitFile(Tree tree) {
+ previousTokenLine = -1;
+ pattern = Pattern.compile(legalCommentPattern);
+ }
+
+ @Override
+ public void visitNode(Tree tree) {
+ SyntaxToken token = (SyntaxToken) tree;
+ for (SyntaxTrivia trivia : token.trivias()) {
+ if (trivia.line() == previousTokenLine) {
+ String comment = trivia.text();
+ if (comment.startsWith("--") && !pattern.matcher(comment).matches()) {
+ addIssue(trivia, MESSAGE);
+ }
+ }
+ }
+ previousTokenLine = token.line();
+ }
+
+ public void setLegalCommentPattern(String pattern) {
+ this.legalCommentPattern = pattern;
+ }
+
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UndocumentedModuleCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UndocumentedModuleCheck.java
index 5de5e33a..a9762e0b 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UndocumentedModuleCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UndocumentedModuleCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UndocumentedRoutineCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UndocumentedRoutineCheck.java
index 0fa4e0aa..98a4594d 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UndocumentedRoutineCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UndocumentedRoutineCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UnknownMessageDomainCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UnknownMessageDomainCheck.java
index b8ebc5ea..0c7487c8 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UnknownMessageDomainCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UnknownMessageDomainCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,21 +39,21 @@ public class UnknownMessageDomainCheck extends DoubleDispatchVisitorCheck {
"MQCIH", "MQDLH", "MQIIH", "MQMD", "MQMDE", "MQPCF", "MQRFH", "MQRFH2", "MQRFH2C", "MQRMH", "MQSAPH", "MQWIH",
"EmailOutputHeader", "EmailInputHeader",
"Collection", "*",
- "DataObject", "IDOC", "SMQ_BMH", "SQL"
+ "DataObject", "IDOC", "SMQ_BMH", "SQL",
+ "ComIbmAggregateReplyBody"
));
@Override
public void visitFieldReference(FieldReferenceTree tree) {
-
- String pathElement1 = tree.pathElement().name().name().text();
- if (rootElements.contains(pathElement1)
- && !tree.pathElements().isEmpty()
- && tree.pathElements().get(0).name()!=null
- &&tree.pathElements().get(0).name().name()!=null){
- String pathElement2 = tree.pathElements().get(0).name().name().text();
- if (!domains.contains(pathElement2)){
- addIssue(tree, "Unknown domain \""+pathElement2+"\".");
+ if (tree.pathElement().name().name() != null) {
+ String pathElement1 = tree.pathElement().name().name().name();
+ if (rootElements.contains(pathElement1) && !tree.pathElements().isEmpty()
+ && tree.pathElements().get(0).name() != null && tree.pathElements().get(0).name().name() != null) {
+ String pathElement2 = tree.pathElements().get(0).name().name().name();
+ if (!domains.contains(pathElement2)) {
+ addIssue(tree, "Unknown domain \"" + pathElement2 + "\".");
+ }
}
}
super.visitFieldReference(tree);
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UnreachableCodeCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UnreachableCodeCheck.java
new file mode 100644
index 00000000..65a4b6c1
--- /dev/null
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UnreachableCodeCheck.java
@@ -0,0 +1,56 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import org.sonar.check.Rule;
+
+import com.exxeta.iss.sonar.esql.api.tree.statement.IterateStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.LeaveStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.ReturnStatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.StatementTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.StatementsTree;
+import com.exxeta.iss.sonar.esql.api.tree.statement.ThrowStatementTree;
+import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+
+@Rule(key = "UnreachableCode")
+public class UnreachableCodeCheck extends DoubleDispatchVisitorCheck{
+
+ private static final String MESSAGE = "Remove the code after this statement.";
+
+
+ @Override
+ public void visitStatements(StatementsTree tree) {
+ boolean unreachable = false;
+ for (int i=0;i usages = symbol.usages();
+ if (noUsages(usages) && symbol.isVariable() && !symbol.scope().isGlobal()) {
+ raiseIssuesOnDeclarations(symbol, String.format(MESSAGE, symbol.name()));
+ }
+ }
+ }
+
+ private void raiseIssuesOnDeclarations(Symbol symbol, String message) {
+ for (Usage usage : symbol.usages()) {
+ if (usage.isDeclaration()) {
+ addIssue(usage.identifierTree(), message);
+ }
+ }
+ }
+
+ private static boolean noUsages(Collection usages) {
+ return usages.isEmpty() || usagesAreInitializations(usages);
+ }
+
+ private static boolean usagesAreInitializations(Collection usages) {
+ for (Usage usage : usages) {
+ if (!usage.isDeclaration()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UseBrokerSchemaCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UseBrokerSchemaCheck.java
index 58de15d9..f443de14 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UseBrokerSchemaCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UseBrokerSchemaCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UselessParenthesesCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UselessParenthesesCheck.java
index e2b4a229..e4caefd1 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UselessParenthesesCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/UselessParenthesesCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/VariableNameCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/VariableNameCheck.java
index 0c31d696..905639ee 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/VariableNameCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/VariableNameCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/VariablesSubtreeCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/VariablesSubtreeCheck.java
index 9d433223..e340c346 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/VariablesSubtreeCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/VariablesSubtreeCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,12 +30,12 @@ public class VariablesSubtreeCheck extends DoubleDispatchVisitorCheck{
public void visitSetStatement(SetStatementTree tree) {
if (tree.variableReference() instanceof FieldReferenceTree){
FieldReferenceTree fieldRef = (FieldReferenceTree)tree.variableReference();
- if ("Environment".equalsIgnoreCase(fieldRef.pathElement().name().name().text()) ){
+ if ("Environment".equalsIgnoreCase(fieldRef.pathElement().name().name().name()) ){
if (fieldRef.pathElements().isEmpty()
|| fieldRef.pathElements().get(0).name()==null
|| fieldRef.pathElements().get(0).name().name()==null
- || !"Variables".equalsIgnoreCase(fieldRef.pathElements().get(0).name().name().text())){
+ || !"Variables".equalsIgnoreCase(fieldRef.pathElements().get(0).name().name().name())){
addIssue(tree, "Environment vaiables should be written to the Variables-subtree.");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/XmlnscDomainCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/XmlnscDomainCheck.java
index c8a18151..6cc831c5 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/XmlnscDomainCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/XmlnscDomainCheck.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,51 +17,64 @@
*/
package com.exxeta.iss.sonar.esql.check;
+import java.util.List;
+
import org.sonar.check.Rule;
import com.exxeta.iss.sonar.esql.api.tree.FieldReferenceTree;
-import com.exxeta.iss.sonar.esql.api.tree.Tree;
import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
import com.exxeta.iss.sonar.esql.api.tree.statement.CreateStatementTree;
import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
+import com.exxeta.iss.sonar.esql.tree.SyntacticEquivalence;
import com.exxeta.iss.sonar.esql.tree.expression.LiteralTree;
import com.google.common.collect.ImmutableList;
-@Rule(key="XmlnscDomain")
-public class XmlnscDomainCheck extends DoubleDispatchVisitorCheck{
+@Rule(key = "XmlnscDomain")
+public class XmlnscDomainCheck extends DoubleDispatchVisitorCheck {
+
+ private static final ImmutableList ROOT_ELEMENTS = ImmutableList.of("Root", "InputRoot", "OutputRoot");
+ private static final ImmutableList WRONG_DOMAINS = ImmutableList.of("XML", "XMLNS");
+ private static final String MESSAGE = "Use the XMLNSC domain instead of %s.";
- ImmutableList rootElements = ImmutableList.of("Root", "IntputRoot", "OutputRoot");
- ImmutableList wrongDomain = ImmutableList.of("XML", "XMLNS");
-
-
@Override
public void visitFieldReference(FieldReferenceTree tree) {
super.visitFieldReference(tree);
- if (rootElements.contains(tree.pathElement().name().name().text())
- && !tree.pathElements().isEmpty()
- && tree.pathElements().get(0)!=null
- && tree.pathElements().get(0).name()!=null
- && tree.pathElements().get(0).name().name()!=null){
- String domain = tree.pathElements().get(0).name().name().text();
- checkDomain(domain, tree.pathElements().get(0));
+ if (rootIs(tree, WRONG_DOMAINS)) {
+ String domain = tree.pathElement().name().name().name();
+ addIssue(tree, String.format(MESSAGE, domain));
+ } else if (rootIs(tree, ROOT_ELEMENTS) && secondElementIs(tree, WRONG_DOMAINS)) {
+ String domain = tree.pathElements().get(0).name().name().name();
+ addIssue(tree, String.format(MESSAGE, domain));
}
}
-
+
+ private boolean secondElementIs(FieldReferenceTree tree, List names) {
+ return !tree.pathElements().isEmpty()
+ && tree.pathElements().get(0).name() != null
+ && tree.pathElements().get(0).name().name() != null
+ && names.contains(tree.pathElements().get(0).name().name().name());
+ }
+
+ private boolean rootIs(FieldReferenceTree tree, List names) {
+ if (tree.pathElement().name().name()!=null){
+ return names.contains(tree.pathElement().name().name().name());
+ } else {
+ return false;
+ }
+ }
+
@Override
public void visitCreateStatement(CreateStatementTree tree) {
super.visitCreateStatement(tree);
- if (tree.domainExpression()!=null && tree.domainExpression().is(Kind.STRING_LITERAL)){
- String domain = ((LiteralTree)tree.domainExpression()).value();
- domain = domain.substring(1, domain.length()-1);
- checkDomain(domain, tree.domainExpression());
+ if (tree.domainExpression() != null
+ && SyntacticEquivalence.skipParentheses(tree.domainExpression()).is(Kind.STRING_LITERAL)) {
+ String domain = ((LiteralTree) SyntacticEquivalence.skipParentheses(tree.domainExpression())).value();
+ domain = domain.substring(1, domain.length() - 1);
+ if (WRONG_DOMAINS.contains(domain)) {
+ addIssue(tree, String.format(MESSAGE, domain));
+ }
}
}
- private void checkDomain(String domain, Tree tree) {
- if (wrongDomain.contains(domain)){
- addIssue(tree, "Use the XMLNSC domain instead of "+domain+".");
- }
- }
-
-
+
}
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql.properties b/esql-checks/src/main/resources/org/sonar/l10n/esql.properties
index 5c44e738..f84ae1cd 100644
--- a/esql-checks/src/main/resources/org/sonar/l10n/esql.properties
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql.properties
@@ -12,7 +12,7 @@ rule.esql.NestedIfDepth.param.maximumNestingLevel=Allowed nesting depth
rule.esql.NonReservedKeyword.name=ESQL keywords should not be identifiers
rule.esql.OneStatementPerLine.name=Do not use more that one statement per line
rule.esql.ParsingError.name=ESQL parser failure
-rule.esql.ProcedureName.name=Function names should comply with a naming convention
+rule.esql.ProcedureName.name=Procedure names should comply with a naming convention
rule.esql.ProcedureName.param.format=regular expression
rule.esql.TooManyIterateOrLeaveInLoop.name=Loops should not contain more than a single ITERATE or LEAVE statement.
rule.esql.TooManyLinesInFile.name=Files should not have too many lines
@@ -20,6 +20,40 @@ rule.esql.TooManyLinesInFile.param.maximum=The maximum of lines
rule.esql.UseBrokerSchema.name=Files should not be in the DEFAULT schema
rule.esql.VariableName.name=Variable names should comply with a naming convention
rule.esql.VariableName.param.format=regular expression
-rule.esql.PropagateToLabel.name=Do not use PROPGATE TO LABEL.
+rule.esql.PropagateToLabel.name=Do not use PROPAGATE TO LABEL.
rule.esql.ConstantName.name=Constant names should comply with a naming convention
rule.esql.ConstantName.param.format=regular expression
+rule.esql.SpaceAroundEqualSign.name=Space should be given around = sign
+rule.esql.KeyWordCaseCheck.name=Keywords should be in UPPERCASE
+rule.esql.CyclomaticComplexity.name=Cyclomatic Complexity is higher then the threshold
+rule.esql.CaseStatementWithSingleWhen.name=CASE statement with Single WHEN should replace by IF statement
+rule.esql.EXTERNALVariableInitialised.name=External Variable should be initialized.
+rule.esql.PassThruStatement.name=Use parameter markers '?' when using the PASSTHRU statement in ESQL.
+rule.esql.AvoidNestedIf.name=Avoid nested IF statements: use ELSEIF or CASE WHEN clauses to get quicker drop-out.
+rule.esql.MeaningfulVariable.name=Declaration of variable/counters name should be meaningful.
+rule.esql.SubElementName.name=Sub elements naming convention Check.
+rule.esql.FunctionProcedureLength.name=Function or Procedure is longer than the threshold.
+rule.esql.FilterNodeModifyMessage.name=The filter node cannot modify the message.
+rule.esql.FilterNodeHaveOnlyOneReturn.name=The filter node may only have one return value.
+rule.esql.MessageDomainNotvalid.name=The message domain may not be valid.
+rule.esql.NavigatingTreeCouldBeReference.name=Navigating message tree could be replaced by a reference.
+rule.esql.UnusedVariable.name=Remove the unused Variable.
+rule.esql.DeprecatedMethod.name=Deprecated methods should not be used.
+rule.esql.BinaryOperatorSepratedBySpace.name=All binary operators should be separated from their operands by spaces.
+rule.esql.InsertBlankLineBetweenFuncProc.name=Insert one blank line between functions and procedures.
+rule.esql.BlankLineBeforeComments.name=Insert one blank line before a block or single-line comment.
+rule.esql.BlankLineBeforeComments.name=A blank space should follow each comma in any ESQL statement that makes use of commas outside of a string literal.
+rule.esql.ProcessInvokingItself.name=Process invoking itself.
+rule.esql.FunctionComments.name=Each Function should have comments.
+rule.esql.ProcedureComments.name=Each Procedure should have comments.
+rule.esql.FileHeaderComments.name=Each ESQL file should contains header information.
+rule.esql.PropagateConsistencyCheck.name=Compute node connections should be consistent.
+rule.esql.UnreachableCode.name=Code is unreachable following RETURN or THROW statement
+rule.esql.ConditionBraces.name=Use braces for conditions as it gives more readability to code.
+rule.esql.TrailingComments.name=The line contains both code and comments. Trailing comments are discouraged.
+rule.esql.CommentedOutEsqlCode.name=Esql code has been commented out.It should be removed before code checkin.
+rule.esql.MultipleStatements.name=Multiple statements on the same line.
+rule.esql.Comments.name=Include comment within the range of every 20 lines of code.
+rule.esql.DeclareCombine.name=If more than one variable of same datatype is found uninitialised then declare could be combined.
+
+
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/BinaryOperatorSeparatedBySpace.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/BinaryOperatorSeparatedBySpace.html
new file mode 100644
index 00000000..e9027936
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/BinaryOperatorSeparatedBySpace.html
@@ -0,0 +1,11 @@
+
Binary operators should always be separated by spaces.
+
A blank space should follow each comma in any ESQL statement that makes use of commas outside of a string literal.
+
+
Noncompliant Code Example
+
+ DECLARE myInt,myInt3 INTEGER 1;
+
+
Compliant Solution
+
+ DECLARE myInt, myInt3 INTEGER 1;
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/BinaryOperatorSeparatedBySpace.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/BinaryOperatorSeparatedBySpace.json
new file mode 100644
index 00000000..5a10659f
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/BinaryOperatorSeparatedBySpace.json
@@ -0,0 +1,14 @@
+{
+ "title": "Binary operators should always be separated by spaces.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "1min"
+ },
+ "tags": [
+ "readability"
+
+ ],
+ "defaultSeverity": "Major"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Bitstream.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Bitstream.html
deleted file mode 100644
index 55a4887d..00000000
--- a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Bitstream.html
+++ /dev/null
@@ -1 +0,0 @@
-
BITSTREAM should not be used it is deprecated. Rather use ASBITSTREAM.
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/BlankLineBeforeComments.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/BlankLineBeforeComments.html
new file mode 100644
index 00000000..1a1a7b79
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/BlankLineBeforeComments.html
@@ -0,0 +1,35 @@
+
Insert one blank line before a block or single-line comment.
+
+
It is good programming practice to give blank line before block or single-line comment to increase readability .
+
Noncompliant Code Example
+
+BEGIN
+ /**
+ block comment */
+ DECLARE versionRef REFERENCE TO InputRoot.SOAP.Context.SOAP_Version;
+ CASE
+ WHEN versionRef = '1.1' THEN
+ SET Environment.Fault.faultcode = 'soapenv:Client';
+ --single line comment
+ WHEN versionRef = '1.2' THEN
+ SET Environment.Fault.faultcode = 'soapenv:Sender';
+ END CASE;
+END;
+
+
Compliant Solution
+
+ BEGIN
+
+ /**
+ block comment */
+ DECLARE versionRef REFERENCE TO InputRoot.SOAP.Context.SOAP_Version;
+ CASE
+ WHEN versionRef = '1.1' THEN
+ SET Environment.Fault.faultcode = 'soapenv:Client';
+
+ --single line comment
+ WHEN versionRef = '1.2' THEN
+ SET Environment.Fault.faultcode = 'soapenv:Sender';
+ END CASE;
+END;
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/BlankLineBeforeComments.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/BlankLineBeforeComments.json
new file mode 100644
index 00000000..963de71e
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/BlankLineBeforeComments.json
@@ -0,0 +1,14 @@
+{
+ "title": "Insert one blank line before a block or single-line comment.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "15min"
+ },
+ "tags": [
+ "readability"
+
+ ],
+ "defaultSeverity": "Major"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/CommentedCode.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/CommentedCode.html
new file mode 100644
index 00000000..fc84916c
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/CommentedCode.html
@@ -0,0 +1,10 @@
+
Programmers should not comment out code as it bloats programs and reduces readability.
+
Unused code should be deleted and can be retrieved from source control history if required.
+
See
+
+
MISRA C:2004, 2.4 - Sections of code should not be "commented out".
+
MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
+
MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
+
MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"
Include comment within the range of every 20 lines of code.
+
+
Compliant Code Example
+
+
+BROKER SCHEMA generic
+DECLARE soapenv NAMESPACE '';
+DECLARE ns NAMESPACE 'http://com/abnamro/Services/AccessFacilityAgreement/v2/' ;
+DECLARE createAccessFacilityAgreement EXTERNAL CHAR;
+DECLARE updateAccessFacilityAgreement EXTERNAL CHAR '';
+CREATE COMPUTE MODULE initialize
+CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ DECLARE bc CHARACTER;
+ DECLARE modid CHARACTER;
+ DECLARE versionRef REFERENCE TO InputRoot.SOAP.Context.SOAP_Version; SET faultRef.ExceptionElement.description = messageTextDetail;
+ DECLARE bc,verid CHARACTER;
+ THROW USER EXCEPTION CATALOG 'BIPmsgs' MESSAGE 2951 VALUES('The SQL State: ', SQLSTATE, 'The SQL Code: ', SQLCODE, 'The SQLNATIVEERROR: ', SQLNATIVEERROR, 'The SQL Error Text: ', SQLERRORTEXT ) ;
+
+ --Comment line.
+
+ CASE
+ WHEN versionRef = '1.1' THEN
+ SET Environment.Fault.faultcode = 'soapenv:Client';
+ WHEN versionRef = '1.2' THEN
+ SET Environment.Fault.faultcode = 'soapenv:Sender';
+ /* Block Comment. */
+ IF exceptionNumber >= 5000 AND exceptionNumber <= 5999 THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ ELSEIF exceptionNumber >= 5000 AND exceptionNumber <= 5999 THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ ENDIF;
+ END CASE;
+ END;
+ END MODULE;
+
+
+
Non-Compliant Code Example
+
+
+BROKER SCHEMA generic
+DECLARE soapenv NAMESPACE '';
+DECLARE ns NAMESPACE 'http://com/abnamro/Services/AccessFacilityAgreement/v2/' ;
+DECLARE createAccessFacilityAgreement EXTERNAL CHAR;
+DECLARE updateAccessFacilityAgreement EXTERNAL CHAR '';
+CREATE COMPUTE MODULE initialize
+CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ DECLARE bc CHARACTER;
+ DECLARE modid CHARACTER;
+ DECLARE versionRef REFERENCE TO InputRoot.SOAP.Context.SOAP_Version; SET faultRef.ExceptionElement.description = messageTextDetail;
+ DECLARE bc,verid CHARACTER;
+ THROW USER EXCEPTION CATALOG 'BIPmsgs' MESSAGE 2951 VALUES('The SQL State: ', SQLSTATE, 'The SQL Code: ', SQLCODE, 'The SQLNATIVEERROR: ', SQLNATIVEERROR, 'The SQL Error Text: ', SQLERRORTEXT ) ;
+ CASE
+ WHEN versionRef = '1.1' THEN
+ SET Environment.Fault.faultcode = 'soapenv:Client';
+ WHEN versionRef = '1.2' THEN
+ SET Environment.Fault.faultcode = 'soapenv:Sender';
+ IF exceptionNumber >= 5000 AND exceptionNumber <= 5999 THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+
+ -- Include comment after every 20 lines of code.
+
+ ELSEIF exceptionNumber >= 5000 AND exceptionNumber <= 5999 THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ ENDIF;
+ END CASE;
+ END;
+ END MODULE:
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Comments.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Comments.json
new file mode 100644
index 00000000..b5ea0683
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Comments.json
@@ -0,0 +1,14 @@
+{
+ "title": "Include comment within the range of every 20 lines of code.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "15min"
+ },
+ "tags": [
+ "readability"
+
+ ],
+ "defaultSeverity": "Major"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/ConditionBraces.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/ConditionBraces.html
new file mode 100644
index 00000000..6b35d7ee
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/ConditionBraces.html
@@ -0,0 +1,37 @@
+
Condition Braces Check
+
+
Compliant Code Example
+
+
+CREATE COMPUTE MODULE initialize
+CREATE FUNCTION main() RETURNS BOOLEAN
+BEGIN
+ IF (exceptionNumber >= 5000) AND (exceptionNumber <= 5999) THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ ELSEIF (exceptionNumber >= 5000) AND (exceptionNumber <= 5999) THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ ENDIF;
+ WHILE (count <= providerCount) DO
+ SET faultRef.ExceptionElement.description = messageTextDetail;
+ END WHILE;
+END;
+END MODULE;
+
+
+
Non-Compliant Code Example
+
+
+CREATE COMPUTE MODULE initialize
+CREATE FUNCTION main() RETURNS BOOLEAN
+BEGIN
+ IF exceptionNumber >= 5000 AND exceptionNumber <= 5999 THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ ELSEIF exceptionNumber >= 5000 AND exceptionNumber <= 5999 THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ ENDIF;
+ WHILE count <= providerCount DO
+ SET faultRef.ExceptionElement.description = messageTextDetail;
+ END WHILE;
+END;
+END MODULE;
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/ConditionBraces.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/ConditionBraces.json
new file mode 100644
index 00000000..296c3d60
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/ConditionBraces.json
@@ -0,0 +1,13 @@
+{
+ "title": "Use braces for conditions as it gives more readability to code.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "15min"
+ },
+ "tags": [
+ "readability"
+ ],
+ "defaultSeverity": "Major"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/CyclomaticComplexity.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/CyclomaticComplexity.html
new file mode 100644
index 00000000..9f6c8a24
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/CyclomaticComplexity.html
@@ -0,0 +1,11 @@
+
This rule applies to check Cyclomatic Complexity
+
Cyclomatic Complexity should not be higher than the given threshold value .
+
+
Noncompliant Code Example
+
+ Cyclomatic complexity should not be greater than 10
+
+
Compliant Solution
+
+ Cyclomatic complexity should be below 10
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/CyclomaticComplexity.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/CyclomaticComplexity.json
new file mode 100644
index 00000000..9a6cb57c
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/CyclomaticComplexity.json
@@ -0,0 +1,10 @@
+{
+ "title": "Cyclomatic Complexity should not be higher than the given threshold value.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "tags": [
+ "database",
+ "performance"
+ ],
+ "defaultSeverity": "Major"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/DeclareCombine.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/DeclareCombine.html
new file mode 100644
index 00000000..103a1c1f
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/DeclareCombine.html
@@ -0,0 +1,34 @@
+
If more than one variable of same datatype is found uninitialised then declare could be combined.
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/DeclareCombine.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/DeclareCombine.json
new file mode 100644
index 00000000..6ec98dc9
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/DeclareCombine.json
@@ -0,0 +1,13 @@
+{
+ "title": "If more than one variable of same datatype is found uninitialised then declare could be combined.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "15min"
+ },
+ "tags": [
+ "readability"
+ ],
+ "defaultSeverity": "Major"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/DeprecatedMethod.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/DeprecatedMethod.html
new file mode 100644
index 00000000..2c993ed8
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/DeprecatedMethod.html
@@ -0,0 +1,12 @@
+
This rule applies whenever the deprecated methods are used in the ESQL file.
+
BITSTREAM should not be used it is deprecated. Rather use ASBITSTREAM.
+
+
Deprecated methods should not be used.
+
Noncompliant Code Example
+
+ SET refEnv.operationId = BITSTREAM(Environment.LogData.serviceOperationName);
+
+
Compliant Solution
+
+ SET refEnv.operationId = ASBITSTREAMEnvironment.LogData.serviceOperationName,,1208);
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/DeprecatedMethod.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/DeprecatedMethod.json
new file mode 100644
index 00000000..7388ed8b
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/DeprecatedMethod.json
@@ -0,0 +1,16 @@
+{
+ "title": "Deprecated methods should not be used.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "240min"
+ },
+ "tags": [
+ "misra",
+ "cert",
+ "deprecated"
+
+ ],
+ "defaultSeverity": "Major"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FilterNodeHaveOnlyOneReturn.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FilterNodeHaveOnlyOneReturn.html
new file mode 100644
index 00000000..0d896dfe
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FilterNodeHaveOnlyOneReturn.html
@@ -0,0 +1,25 @@
+
Filter nodes that only have 1 return are not providing filtering to more then one available path.
+
A filter node with a single return could be either a logic error or could be redundant.
+
Noncompliant Code Example
+
+ CREATE FILTER MODULE Flow2_Filter
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ RETURN FALSE;
+ END;
+ END MODULE;
+
+
Compliant Solution
+
+ CREATE FILTER MODULE Flow2_Filter
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ RETURN FALSE;
+ END;
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ RETURN FALSE;
+ END;
+ END MODULE;
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FilterNodeHaveOnlyOneReturn.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FilterNodeHaveOnlyOneReturn.json
new file mode 100644
index 00000000..c32ad325
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FilterNodeHaveOnlyOneReturn.json
@@ -0,0 +1,15 @@
+{
+ "title": "The filter node may only have one return value",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "60min"
+ },
+ "tags": [
+
+ "correctness"
+
+ ],
+ "defaultSeverity": "Critical"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FilterNodeModifyMessage.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FilterNodeModifyMessage.html
new file mode 100644
index 00000000..456f862f
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FilterNodeModifyMessage.html
@@ -0,0 +1,20 @@
+
The filter node cannot modify the message.
+
Noncompliant Code Example
+
+ CREATE FILTER MODULE Flow2_Filter
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ RETURN FALSE;
+ END;
+ END MODULE;
+
+
Compliant Solution
+
+ CREATE FILTER MODULE Flow2_Filter
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ RETURN FALSE;
+ END;
+ END MODULE;
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FilterNodeModifyMessage.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FilterNodeModifyMessage.json
new file mode 100644
index 00000000..63adb287
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FilterNodeModifyMessage.json
@@ -0,0 +1,15 @@
+{
+ "title": "The filter node cannot modify the message",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "60min"
+ },
+ "tags": [
+
+ "correctness"
+
+ ],
+ "defaultSeverity": "Critical"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FunctionProcedureLength.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FunctionProcedureLength.html
new file mode 100644
index 00000000..7d7e428b
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FunctionProcedureLength.html
@@ -0,0 +1,11 @@
+
This rule applies to check the length of ESQL function or procedure
+
The length of the function or procedure should not be higher than the given threshold value .
+
+
Noncompliant Code Example
+
+ Function or Procedure longer than 150 code lines.
+
+
Compliant Solution
+
+ Function or Procedure shorter than 150 code lines.
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FunctionProcedureLength.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FunctionProcedureLength.json
new file mode 100644
index 00000000..8b1ffdf8
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/FunctionProcedureLength.json
@@ -0,0 +1,14 @@
+{
+ "title": "The length of the function or procedure should not be higher than the given threshold value.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "60min"
+ },
+ "tags": [
+ "complexity",
+ "readability"
+ ],
+ "defaultSeverity": "Major"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/InsertBlankLineBetweenFuncProc.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/InsertBlankLineBetweenFuncProc.html
new file mode 100644
index 00000000..b4a4e588
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/InsertBlankLineBetweenFuncProc.html
@@ -0,0 +1,33 @@
+
There should be one blank line between procedure and functions to increase readability
+
+
It is good programming practice to give space between procedures and functions.
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/InsertBlankLineBetweenFuncProc.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/InsertBlankLineBetweenFuncProc.json
new file mode 100644
index 00000000..44b13806
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/InsertBlankLineBetweenFuncProc.json
@@ -0,0 +1,14 @@
+{
+ "title": "Insert one blank line between functions and procedures.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "15min"
+ },
+ "tags": [
+ "readability"
+
+ ],
+ "defaultSeverity": "Major"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/KeyWordCaseCheck.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/KeyWordCaseCheck.html
new file mode 100644
index 00000000..85d72cdd
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/KeyWordCaseCheck.html
@@ -0,0 +1,11 @@
+
This rule applies whenever the keyword is used in the esql, it should be in the UPPERCASE.
+
+
The requirement for UPPERCASE for all the keywords in esql helps to identify the keywords hence improves readability.
+
Noncompliant Code Example
+
+ Create COMPUTE MODULE Compute1
+
+
Compliant Solution
+
+ CREATE COMPUTE MODULE Compute1
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/KeyWordCaseCheck.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/KeyWordCaseCheck.json
new file mode 100644
index 00000000..e2ba8d17
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/KeyWordCaseCheck.json
@@ -0,0 +1,14 @@
+{
+ "title": "All keywords should be in UPPER CASE.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+ "readability",
+ "standards"
+ ],
+ "defaultSeverity": "Minor"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/NavigatingTreeCouldBeReference.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/NavigatingTreeCouldBeReference.html
new file mode 100644
index 00000000..c9f4b293
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/NavigatingTreeCouldBeReference.html
@@ -0,0 +1,17 @@
+
Navigating message tree could be replaced by a reference.
+
+
+
Noncompliant Code Example
+
+
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ SET OutputRoot.XMLNSC.Response.details.person.name = 'xyz';
+ SET OutputRoot.XMLNSC.Response.details.person.lname = 'abc';
+
+
Compliant Solution
+
+ DECLARE reqRef REFERENCE TO OutputRoot.XMLNSC.Response.details.person;
+ SET reqRef.age = '20';
+ SET reqRef.name = 'xyz';
+ SET reqRef = 'abc';
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/NavigatingTreeCouldBeReference.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/NavigatingTreeCouldBeReference.json
new file mode 100644
index 00000000..2a18e92e
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/NavigatingTreeCouldBeReference.json
@@ -0,0 +1,13 @@
+{
+ "title": "Navigating message tree could be replaced by a reference.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "10min"
+ },
+ "tags": [
+ "correctness"
+ ],
+ "defaultSeverity": "Major"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/OneStatementPerLine.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/OneStatementPerLine.html
index 227c36e1..9d9f3926 100644
--- a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/OneStatementPerLine.html
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/OneStatementPerLine.html
@@ -1 +1,23 @@
For better readability, do not put more than one statement on a single line.
+
Compliant Code Example
+
+
+CREATE COMPUTE MODULE responseTransformation
+CREATE FUNCTION main() RETURNS BOOLEAN
+BEGIN
+CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+DECLARE faultRef REFERENCE TO OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+END;
+END MODULE;
+
+
+
Non-Compliant Code Example
+
+
+CREATE COMPUTE MODULE responseTransformation
+CREATE FUNCTION main() RETURNS BOOLEAN
+BEGIN
+CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException; DECLARE faultRef REFERENCE TO OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+END;
+END MODULE;
+
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/OneStatementPerLine.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/OneStatementPerLine.json
new file mode 100644
index 00000000..ccd7ab2b
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/OneStatementPerLine.json
@@ -0,0 +1,15 @@
+{
+ "title": "Statements should be on separate lines",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "1min"
+ },
+ "tags": [
+ "readability",
+ "style"
+ ],
+ "defaultSeverity": "Minor",
+ "sqKey": "OneStatementPerLine"
+}
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/PassThruStatement.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/PassThruStatement.html
new file mode 100644
index 00000000..719fce2c
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/PassThruStatement.html
@@ -0,0 +1,10 @@
+
This rule applies whenever the PASSTHRU statement is used in ESQL.
+
It is good programming practice to Use parameter markers '?' when using the PASSTHRU statement in ESQL.
+
Noncompliant Code Example
+
+ PASSTHRU 'SELECT COUNT(*) FROM Database.SHAREHOLDINGS AS S WHERE S.ACCOUNTNO = InputBody.AccountNumber' TO Database.DSN1 VALUES ();
+
+
Compliant Solution
+
+ PASSTHRU 'SELECT COUNT(*) FROM Database.SHAREHOLDINGS AS S WHERE S.ACCOUNTNO = ?' TO Database.DSN1 VALUES (InputBody.AccountNumber);
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/PassThruStatment.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/PassThruStatment.json
new file mode 100644
index 00000000..9b6afa69
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/PassThruStatment.json
@@ -0,0 +1,13 @@
+{
+ "title": "Use parameter markers '?' when using the PASSTHRU statement in ESQL.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+ "database"
+ ],
+ "defaultSeverity": "Major"
+}
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/ProcessInvokingItself.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/ProcessInvokingItself.html
new file mode 100644
index 00000000..0543b83e
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/ProcessInvokingItself.html
@@ -0,0 +1,17 @@
+
Process invoking itself.
+
+
Noncompliant Code Example
+
+ CREATE FUNCTION Main() RETURNS BOOLEAN --Noncompliant
+ BEGIN
+ DECLARE myInt INTEGER 1;
+ SET xyz = Main();
+ END;
+
+
Compliant Solution
+
+ CREATE FUNCTION Main() RETURNS BOOLEAN --Noncompliant
+ BEGIN
+ DECLARE myInt INTEGER 1;
+ END;
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/ProcessInvokingItself.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/ProcessInvokingItself.json
new file mode 100644
index 00000000..7fc23dff
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/ProcessInvokingItself.json
@@ -0,0 +1,14 @@
+{
+ "title": "Process invoking itself.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "15min"
+ },
+ "tags": [
+ "readability"
+
+ ],
+ "defaultSeverity": "Major"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/PropagateConsistency.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/PropagateConsistency.html
new file mode 100644
index 00000000..7f36dc42
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/PropagateConsistency.html
@@ -0,0 +1,2 @@
+
The compute node has the propagate statement to one or more terminals which are not connected in the message flows.
+So such terminals should be connected or such propagate statements should be removed.
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/PropagateConsistency.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/PropagateConsistency.json
new file mode 100644
index 00000000..7348e441
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/PropagateConsistency.json
@@ -0,0 +1,14 @@
+{
+ "title": "Compute node connection should be Consistent",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "15min"
+ },
+ "tags": [
+ "correctness","completeness"
+
+ ],
+ "defaultSeverity": "Major"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/RoutineComments.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/RoutineComments.html
new file mode 100644
index 00000000..c4da4b23
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/RoutineComments.html
@@ -0,0 +1,11 @@
+
Each function or procedure should have comments as below:
+/*
+ * Function description goes here.
+ * Parameters:
+ * IN: REFERENCE parameter1 - Description goes here.
+ * INOUT: INTEGER parameter2 - Description goes here.
+ * OUT: TIMESTAMP result - Description goes here.
+ * RETURNS: BOOLEAN Description goes here.
+ *
+ */
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/RoutineComments.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/RoutineComments.json
new file mode 100644
index 00000000..642c91ee
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/RoutineComments.json
@@ -0,0 +1,16 @@
+{
+ "title": "Each function or procedure should have comments",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "10min"
+ },
+ "tags": [
+ "convention"
+ ],
+ "defaultSeverity": "Major"
+}
+
+
+
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/SelfAssignment.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/SelfAssignment.html
new file mode 100644
index 00000000..a5a1ac83
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/SelfAssignment.html
@@ -0,0 +1,15 @@
+
There is no reason to re-assign a variable to itself. Either this statement is redundant and should be removed, or the re-assignment is a mistake
+and some other value or variable was intended for the assignment instead.
+
Noncompliant Code Example
+
+CREATE PROCEDURE setName(name) {
+ SET name = name;
+}
+
+
See
+
+
CERT, MSC12-C. - Detect and remove code that has no effect or is never
+ executed
This rule applies whenever elements containing sub elements .
+
+
It is good programming practice to Name elements containing sub-elements using UpperCamel-case
+ and elements containing simple value using lower-case to make the naming convention in the Environment tree
+
Noncompliant Code Example
+
+
+ SET Environment.Variables.startVar.xyz='ABC';
+ SET Environment.Variables.Abc='ABC';
+
+
+
Compliant Solution
+
+ SET Environment.Variables.StartVar.xyz='ABC';
+ SET Environment.Variables.abc='ABC';
+
+
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/SubElementName.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/SubElementName.json
new file mode 100644
index 00000000..b269134c
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/SubElementName.json
@@ -0,0 +1,14 @@
+{
+ "title": "sub-elements should be in UpperCamel-case and elements containing simple value should be in lowercase.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+
+ "standards"
+ ],
+ "defaultSeverity": "Major"
+}
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/TrailingComments.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/TrailingComments.html
new file mode 100644
index 00000000..121ad244
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/TrailingComments.html
@@ -0,0 +1,35 @@
+
The line contains both code and comments. Trailing comments are discouraged.
+
Comments are far better placed on the previous empty line of code, where they will always be visible and properly formatted.
+
+
Compliant Code Example
+
+
+CREATE COMPUTE MODULE initialize
+CREATE FUNCTION main() RETURNS BOOLEAN
+BEGIN
+
+ -- Create field statement
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ -- Create field statement
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ -- Set statement
+ SET faultRef.ExceptionElement.description = messageTextDetail;
+
+END;
+END MODULE;
+
+
+
Non-Compliant Code Example
+
+
+CREATE COMPUTE MODULE initialize
+CREATE FUNCTION main() RETURNS BOOLEAN
+BEGIN
+
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException; -- Create field statement
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException; -- Create field statement
+ SET faultRef.ExceptionElement.description = messageTextDetail;-- Set statement
+
+END;
+END MODULE;
+
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/TrailingComments.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/TrailingComments.json
new file mode 100644
index 00000000..12c60d3e
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/TrailingComments.json
@@ -0,0 +1,13 @@
+{
+ "title": "Comments should not be located at the end of lines of code",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "1min"
+ },
+ "tags": [
+ "standards"
+ ],
+ "defaultSeverity": "Minor"
+}
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/UnreachableCode.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/UnreachableCode.html
new file mode 100644
index 00000000..2d67d55c
--- /dev/null
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/UnreachableCode.html
@@ -0,0 +1,34 @@
+
Jump statements (RETURN, LEAVE and ITERATE) and THROW expressions move control flow out of the
+current code block. Typically, any statements in a block that come after a jump or THROW are simply wasted keystrokes lying in wait to
+confuse the unwary.
+
Noncompliant Code Example
+
+CREATE FUNCTION f(a INTEGER) RETURNS INTEGER
+BEGIN
+ DECLARE i INTEGER 10;
+ RETURN i + a;
+ SET i = i + 1; -- Noncompliant; this is never executed
+END;
+
+
Compliant Solution
+
+CREATE FUNCTION f(a INTEGER) RETURNS INTEGER
+BEGIN
+ DECLARE i INTEGER 10;
+ RETURN i + a;
+END;
+
+
See
+
+
MISRA C:2004, 14.1 - There shall be no unreachable code
+
MISRA C++:2008, 0-1-1 - A project shall not contain unreachable code
+
MISRA C++:2008, 0-1-9 - There shall be no dead code
+
MISRA C:2012, 2.1 - A project shall not contain unreachable code
\ No newline at end of file
diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Bitstream.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/UnusedVariable.json
similarity index 68%
rename from esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Bitstream.json
rename to esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/UnusedVariable.json
index 89ca0060..5fc23ddc 100644
--- a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Bitstream.json
+++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/UnusedVariable.json
@@ -1,14 +1,15 @@
-{
- "title": "BITSTREAM should not be used.",
- "type": "CODE_SMELL",
- "status": "ready",
- "remediation": {
- "func": "Constant\/Issue",
- "constantCost": "5min"
- },
- "tags": [
- "misra",
- "cert"
- ],
- "defaultSeverity": "Major"
+{
+ "title": "Unused Variable should be removed",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+ "misra",
+ "cert",
+ "unused"
+ ],
+ "defaultSeverity": "Major"
}
\ No newline at end of file
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BinaryOperatorSeparatedBySpaceCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BinaryOperatorSeparatedBySpaceCheckTest.java
new file mode 100644
index 00000000..ee95d6aa
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BinaryOperatorSeparatedBySpaceCheckTest.java
@@ -0,0 +1,46 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+/**
+ * @author C50679
+ *
+ */
+public class BinaryOperatorSeparatedBySpaceCheckTest {
+
+ @Test
+ public void test() {
+ EsqlCheck check = new BinaryOperatorSeparatedBySpaceCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/BinaryOperatorSpace.esql"))
+ .next().atLine(5).withMessage("This binary operators should be separated from it's operands by spaces.")
+ .next().atLine(6).withMessage("This binary operators should be separated from it's operands by spaces.")
+ .next().atLine(7).withMessage("This binary operators should be separated from it's operands by spaces.")
+ .next().atLine(8).withMessage("This binary operators should be separated from it's operands by spaces.")
+ .next().atLine(12).withMessage("This binary operators should be separated from it's operands by spaces.")
+ .next().atLine(19).withMessage("This token should be followed by a space.")
+ .noMore();
+ }
+
+}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BlankLineBeforeCommentsCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BlankLineBeforeCommentsCheckTest.java
new file mode 100644
index 00000000..25e64488
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BlankLineBeforeCommentsCheckTest.java
@@ -0,0 +1,41 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+/**
+ * @author C50679
+ *
+ */
+public class BlankLineBeforeCommentsCheckTest {
+ @Test
+ public void test() {
+ EsqlCheck check = new BlankLineBeforeCommentsCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/BlankLineBeforeComments.esql"))
+ .next().atLine(4).withMessage("Insert one blank line before this block or single-line comment.")
+ .next().atLine(16).withMessage("Insert one blank line before this block or single-line comment.")
+ .noMore();
+ }
+
+}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BooleanInversionCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BooleanInversionCheckTest.java
index 9907c230..cc40754f 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BooleanInversionCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BooleanInversionCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BooleanLiteralCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BooleanLiteralCheckTest.java
index 1d0962f1..96e76e0f 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BooleanLiteralCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BooleanLiteralCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CardinalityInLoopCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CardinalityInLoopCheckTest.java
index b687c155..02b5e50e 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CardinalityInLoopCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CardinalityInLoopCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,7 @@ public void test() {
.next().atLine(5).withMessage("Avoid using CARDINALITY in loops.")
.next().atLine(18).withMessage("Avoid using CARDINALITY in loops.")
.next().atLine(25).withMessage("Avoid using CARDINALITY in loops.")
+ .next().atLine(33).withMessage("Avoid using CARDINALITY in loops.")
.noMore();
}
}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CaseAtLeastThreeWhenCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CaseAtLeastThreeWhenCheckTest.java
index c3010010..756ca3f6 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CaseAtLeastThreeWhenCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CaseAtLeastThreeWhenCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CaseWithTooManyWhensCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CaseWithTooManyWhensCheckTest.java
index 736dc3c0..dea91f47 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CaseWithTooManyWhensCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CaseWithTooManyWhensCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CaseWithoutElseCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CaseWithoutElseCheckTest.java
index c0039fcc..b3987197 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CaseWithoutElseCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CaseWithoutElseCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CheckListTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CheckListTest.java
index 026ac466..2eda36b7 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CheckListTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CheckListTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommentRegularExpressionCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommentRegularExpressionCheckTest.java
index 49193baf..00bf1743 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommentRegularExpressionCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommentRegularExpressionCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,25 +26,49 @@
import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
public class CommentRegularExpressionCheckTest {
- @Test
- public void test() {
- CommentRegularExpressionCheck check = new CommentRegularExpressionCheck();
-
- check.setRegularExpression( "(?i).*TODO.*");
- check.message = "Avoid TODO";
-
-
- EsqlCheckVerifier.issues(check, new File("src/test/resources/empty.esql"))
- .next().atLine(1).withMessage("Avoid TODO")
- .noMore();
-
- try {
- check.setRegularExpression("[abc");
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Unable to compile regular expression: [abc");
- }
-
-
-
- }
+ @Test
+ public void test() {
+ CommentRegularExpressionCheck check = new CommentRegularExpressionCheck();
+
+ check.setRegularExpression("(?i).*TODO.*");
+ check.setMessage("Avoid TODO");
+
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/empty.esql")).next().atLine(1)
+ .withMessage("Avoid TODO").noMore();
+
+ }
+
+ @Test
+ public void exception() {
+ CommentRegularExpressionCheck check = new CommentRegularExpressionCheck();
+
+ try {
+ check.setRegularExpression("[abc");
+ } catch (IllegalStateException e) {
+ assertThat(e.getMessage()).isEqualTo("Unable to compile regular expression: [abc");
+ }
+
+ }
+
+ @Test
+ public void emptyPattern() {
+ CommentRegularExpressionCheck check = new CommentRegularExpressionCheck();
+
+ check.setRegularExpression("");
+ check.setMessage("Avoid TODO");
+
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/empty.esql")).noMore();
+
+ }
+
+ @Test
+ public void noMatch() {
+ CommentRegularExpressionCheck check = new CommentRegularExpressionCheck();
+
+ check.setRegularExpression("(?i).*FIXME.*");
+ check.setMessage("Avoid TODO");
+
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/empty.esql")).noMore();
+
+ }
}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommentedCodeCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommentedCodeCheckTest.java
new file mode 100644
index 00000000..d2ff8446
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommentedCodeCheckTest.java
@@ -0,0 +1,39 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+public class CommentedCodeCheckTest {
+ @Test
+ public void test() throws Exception {
+ CommentedCodeCheck check = new CommentedCodeCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/commentedCode.esql"))
+ .next().atLine(5).withMessage("Remove this commented out code.")
+ .next().atLine(9).withMessage("Remove this commented out code.")
+ .next().atLine(14).withMessage("Remove this commented out code.")
+ .next().atLine(18).withMessage("Remove this commented out code.")
+ .next().atLine(22).withMessage("Remove this commented out code.")
+ .next().atLine(32).withMessage("Remove this commented out code.")
+ .noMore();
+ }
+}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommentsCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommentsCheckTest.java
new file mode 100644
index 00000000..abc25aa1
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommentsCheckTest.java
@@ -0,0 +1,23 @@
+/**
+ * This java class is created to implement the logic for checking if comment is included or not,
+ * over every 20 lines of code.
+ *
+ * @author Prerana Agarkar
+ *
+ */
+package com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+import org.junit.Test;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+public class CommentsCheckTest{
+ @Test
+ public void test() {
+
+ EsqlCheckVerifier.issues(new CommentsCheck(), new File("src/test/resources/comments.esql"))
+ .next().atLine(34).withMessage("Include comment within the range of every 20 lines of code.")
+ .noMore();
+ }
+
+}
\ No newline at end of file
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ConditionBracesCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ConditionBracesCheckTest.java
new file mode 100644
index 00000000..5af22992
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ConditionBracesCheckTest.java
@@ -0,0 +1,32 @@
+/**
+ * This java class is created to implement the logic for checking if braces for conditions are used or not,
+ * if it is not used then it should be inserted.
+ *
+ *
+ * @author Prerana Agarkar
+ *
+ */
+
+package com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+public class ConditionBracesCheckTest {
+ @Test
+ public void test() {
+
+ EsqlCheckVerifier.issues(new ConditionBracesCheck(), new File("src/test/resources/conditionBraces.esql"))
+ .next().atLine(4).withMessage("Use braces for conditions as it gives more readability to code.")
+ .next().atLine(8).withMessage("Use braces for conditions as it gives more readability to code.")
+ .next().atLine(13).withMessage("Use braces for conditions as it gives more readability to code.")
+ .next().atLine(24).withMessage("Use braces for conditions as it gives more readability to code.")
+ .noMore();
+ }
+
+
+ }
+
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ConstantNameCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ConstantNameCheckTest.java
index ae2724b9..affac0d3 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ConstantNameCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ConstantNameCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CyclomaticComplexityCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CyclomaticComplexityCheckTest.java
new file mode 100644
index 00000000..80222375
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CyclomaticComplexityCheckTest.java
@@ -0,0 +1,46 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+/**
+ * This Test class is created to check the cyclomatic complexity of the code.
+ * @author sapna singh
+ *
+ */
+public class CyclomaticComplexityCheckTest {
+
+
+ @Test
+ public void test() {
+ EsqlCheck check = new CyclomaticComplexityCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/CyclomaticComplexity.esql"))
+ .next().atLine(2).withMessage("Refactor this function to reduce its Cognitive Complexity from 12 to the 10 allowed.")
+ .next().atLine(33).withMessage("Refactor this procedure to reduce its Cognitive Complexity from 33 to the 10 allowed.")
+ .noMore();
+ }
+
+}
+
+
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DeclareCombineCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DeclareCombineCheckTest.java
new file mode 100644
index 00000000..1ae465d9
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DeclareCombineCheckTest.java
@@ -0,0 +1,23 @@
+/**
+ * This java class is created to implement the logic for checking if variable is initialised or not,
+ * if more than one variable of same datatype is found uninitialised then declare statement could be combined.
+ *
+ *
+ * @author Prerana Agarkar
+ *
+ */
+
+package com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+import org.junit.Test;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+public class DeclareCombineCheckTest {
+
+ @Test
+ public void test() {
+ EsqlCheckVerifier.verify(new DeclareCombineCheck(), new File("src/test/resources/declareCombine.esql"));
+
+ }
+}
\ No newline at end of file
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DeleteFromWithoutWhereCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DeleteFromWithoutWhereCheckTest.java
index 5d5e522f..1e292ebd 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DeleteFromWithoutWhereCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DeleteFromWithoutWhereCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DeprecatedMethodCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DeprecatedMethodCheckTest.java
new file mode 100644
index 00000000..8cb66525
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DeprecatedMethodCheckTest.java
@@ -0,0 +1,46 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+/**
+ * @author C50679
+ *
+ */
+public class DeprecatedMethodCheckTest {
+ @Test
+ public void test() {
+ DeprecatedMethodCheck check = new DeprecatedMethodCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/DeprecatedMethod.esql"))
+ .next().atLine(20).withMessage("Do not use BITSTREAM it is deprecated.").noMore();
+
+ check.deprecatedMethods = "EVAL, BITSTREAM";
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/DeprecatedMethod.esql"))
+ .next().atLine(19).withMessage("Do not use EVAL it is deprecated.")
+ .next().atLine(20).withMessage("Do not use BITSTREAM it is deprecated.")
+ .noMore();
+
+ }
+
+
+}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DuplicateConditionIfElseAndCaseWhensCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DuplicateConditionIfElseAndCaseWhensCheckTest.java
index 0e73fc1e..4fc986f7 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DuplicateConditionIfElseAndCaseWhensCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/DuplicateConditionIfElseAndCaseWhensCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ElseIfWithoutElseCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ElseIfWithoutElseCheckTest.java
index 83b24c5f..644024fb 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ElseIfWithoutElseCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ElseIfWithoutElseCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EmptyBlockCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EmptyBlockCheckTest.java
index b0e7e386..b5cbc0bf 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EmptyBlockCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EmptyBlockCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,12 +26,18 @@
public class EmptyBlockCheckTest {
@Test
public void test() {
- EsqlCheckVerifier.issues(new EmptyBlockCheck(), new File("src/test/resources/ifTest.esql"))
+ EsqlCheckVerifier.issues(new EmptyBlockCheck(), new File("src/test/resources/emptyBlock.esql"))
.next().atLine(16).withMessage("Either remove or fill this block of code.")
.next().atLine(17).withMessage("Either remove or fill this block of code.")
.next().atLine(18).withMessage("Either remove or fill this block of code.")
.next().atLine(21).withMessage("Either remove or fill this block of code.")
- .next().atLine(26).withMessage("Either remove or fill this block of code.")
+ .next().atLine(23).withMessage("Either remove or fill this block of code.")
+ .next().atLine(24).withMessage("Either remove or fill this block of code.")
+ .next().atLine(25).withMessage("Either remove or fill this block of code.")
+ .next().atLine(27).withMessage("Either remove or fill this block of code.")
+ .next().atLine(31).withMessage("Either remove or fill this block of code.")
+ .next().atLine(34).withMessage("Either remove or fill this block of code.")
+ .next().atLine(55).withMessage("Either remove or fill this block of code.")
.noMore();
}
}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EmptyFileCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EmptyFileCheckTest.java
index 88d1d49f..476fc662 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EmptyFileCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EmptyFileCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EmptyMainFunctionCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EmptyMainFunctionCheckTest.java
index f3a94efa..a263cbbb 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EmptyMainFunctionCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EmptyMainFunctionCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EvalCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EvalCheckTest.java
index 862f70aa..2eb2d2ca 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EvalCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/EvalCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FileHeaderCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FileHeaderCheckTest.java
index 2fbc307e..20f2e94b 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FileHeaderCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FileHeaderCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,7 @@ public class FileHeaderCheckTest {
private final File file1 = new File("src/test/resources/FileHeaderCheck/file1.esql");
private final File file2 = new File("src/test/resources/FileHeaderCheck/file2.esql");
+ private final File file4 = new File("src/test/resources/FileHeaderCheck/file4.esql");
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -89,6 +90,9 @@ public void test_regular_expression() {
EsqlCheckVerifier.issues(checkWithRegex("-- copyright 20\\d\\d\\r-- foo"), file2)
.next().atLine(null);
+
+ EsqlCheckVerifier.issues(checkWithRegex("\\/\\*\\r?\\nChange Log\\r?\\nNo. Incident Number Jira Number Description Date Fixed Updated ESQL/Node.*\\r?\\n\\*\\/"), file4)
+ .noMore();;
}
@Test
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FileNameCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FileNameCheckTest.java
index fc70f789..762d2285 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FileNameCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FileNameCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FilterNodeHaveOnlyOneReturnCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FilterNodeHaveOnlyOneReturnCheckTest.java
new file mode 100644
index 00000000..5044c079
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FilterNodeHaveOnlyOneReturnCheckTest.java
@@ -0,0 +1,43 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+/**
+ * @author C50679
+ *
+ */
+public class FilterNodeHaveOnlyOneReturnCheckTest {
+ @Test
+ public void test() {
+ EsqlCheck check = new FilterNodeHaveOnlyOneReturnCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/FilterNodeHaveOnlyOneReturn.esql"))
+ .next().atLine(1).withMessage("This filter module always returns the same value")
+ .next().atLine(21).withMessage("This filter module always returns the same value")
+ .next().atLine(29).withMessage("This filter module always returns the same value")
+ .next().atLine(57).withMessage("This filter module always returns the same value")
+ .noMore();
+ }
+
+}
diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/AsbitstreamFunctionTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FilterNodeModifyMessageCheckTest.java
similarity index 53%
rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/AsbitstreamFunctionTest.java
rename to esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FilterNodeModifyMessageCheckTest.java
index 3db6c99e..8cd7994a 100644
--- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/AsbitstreamFunctionTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FilterNodeModifyMessageCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,21 +15,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.exxeta.iss.sonar.esql.api.tree;
+package com.exxeta.iss.sonar.esql.check;
-import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat;
+import java.io.File;
import org.junit.Test;
-import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
-
-public class AsbitstreamFunctionTest {
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+/**
+ * @author C50679
+ *
+ */
+public class FilterNodeModifyMessageCheckTest {
@Test
- public void asbitstreamFunction() {
- assertThat(Kind.ASBITSTREAM_FUNCTION)
- .matches("ASBITSTREAM(cursor OPTIONS options CCSID 1208)")
- .matches("ASBITSTREAM(Environment.Variables.MQRFH2.Data,,1208,,,,options)");
+ public void test() {
+ EsqlCheck check = new FilterNodeModifyMessageCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/FilterNodeModifyMessage.esql"))
+ .next().atLine(4).withMessage("The filter node cannot modify the message")
+ .noMore();
}
}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FunctionNameCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FunctionNameCheckTest.java
index bd97c079..e6e784f9 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FunctionNameCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FunctionNameCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FunctionProcedureLengthCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FunctionProcedureLengthCheckTest.java
new file mode 100644
index 00000000..2cf59d2d
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/FunctionProcedureLengthCheckTest.java
@@ -0,0 +1,46 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+/**
+ * This Test class is created to check the length of a function or procedure.
+ * @author Sapna Singh
+ *
+ */
+public class FunctionProcedureLengthCheckTest {
+
+
+
+ @Test
+ public void test() {
+ EsqlCheck check = new FunctionProcedureLengthCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/FunctionLength.esql"))
+ .next().atLine(362).withMessage("This routine has 152 lines, which is greater than the 150 lines authorized.")
+ .noMore();
+ }
+
+}
+
+
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/HardCodedCredentialsCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/HardCodedCredentialsCheckTest.java
index c0339170..0505c61d 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/HardCodedCredentialsCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/HardCodedCredentialsCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/HardcodedIpCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/HardcodedIpCheckTest.java
index e7e62a06..8b3d3280 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/HardcodedIpCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/HardcodedIpCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/HardcodedURICheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/HardcodedURICheckTest.java
index bafb910b..d6b0af6f 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/HardcodedURICheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/HardcodedURICheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/IdenticalExpressionOnBinaryOperatorCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/IdenticalExpressionOnBinaryOperatorCheckTest.java
index 2a51311c..84c770da 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/IdenticalExpressionOnBinaryOperatorCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/IdenticalExpressionOnBinaryOperatorCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/IfConditionalAlwaysTrueOrFalseCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/IfConditionalAlwaysTrueOrFalseCheckTest.java
index 865a9bb8..f3d56a82 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/IfConditionalAlwaysTrueOrFalseCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/IfConditionalAlwaysTrueOrFalseCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/InitializeVariablesCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/InitializeVariablesCheckTest.java
index c6db1a4b..0000c927 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/InitializeVariablesCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/InitializeVariablesCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/InsertBlankLineBetweenFuncProcCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/InsertBlankLineBetweenFuncProcCheckTest.java
new file mode 100644
index 00000000..ce374197
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/InsertBlankLineBetweenFuncProcCheckTest.java
@@ -0,0 +1,40 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+/**
+ * @author C50679
+ *
+ */
+public class InsertBlankLineBetweenFuncProcCheckTest {
+ @Test
+ public void test() {
+ EsqlCheck check = new InsertBlankLineBetweenFuncProcCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/InsertBlankLineBetweenFuncProc.esql"))
+ .next().atLine(6).withMessage("Insert one blank line between functions and procedures.")
+ .next().atLine(11).withMessage("Insert one blank line between functions and procedures.").noMore();
+ }
+
+}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/IterateStatementCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/IterateStatementCheckTest.java
index 094a38a5..75821649 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/IterateStatementCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/IterateStatementCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/KeyWordCaseCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/KeyWordCaseCheckTest.java
new file mode 100644
index 00000000..f336965c
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/KeyWordCaseCheckTest.java
@@ -0,0 +1,41 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+/**
+ * This Test Class Is created to ensure that all the keywords in esql file should be in UPPER CASE
+ * @author Sapna Singh
+ *
+ */
+public class KeyWordCaseCheckTest {
+ @Test
+ public void test() {
+ EsqlCheck check = new KeyWordCaseCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/KeyWordCaseCheck.esql"))
+ .next().atLine(7).withMessage("This keyword should be in uppercase.")
+ .next().atLine(22).withMessage("This keyword should be in uppercase.")
+ .next().atLine(32).withMessage("This keyword should be in uppercase.")
+ .noMore();
+ }
+}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/LineLengthCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/LineLengthCheckTest.java
index ea213ca0..7a19a5d2 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/LineLengthCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/LineLengthCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/LoopWithoutLeaveCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/LoopWithoutLeaveCheckTest.java
index 9428f049..3a66d9a4 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/LoopWithoutLeaveCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/LoopWithoutLeaveCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/MissingNewlineAtEndOfFileCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/MissingNewlineAtEndOfFileCheckTest.java
index b95c2119..7bb71cb6 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/MissingNewlineAtEndOfFileCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/MissingNewlineAtEndOfFileCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -52,4 +52,22 @@ public void empty() {
.noMore();
}
+ @Test
+ public void onlySchemaPathSemi() {
+ EsqlCheckVerifier.issues(check, new File(DIRECTORY, "onlySchemaPathSemi.esql"))
+ .noMore();
+ }
+
+ @Test
+ public void onlySchemaPath() {
+ EsqlCheckVerifier.issues(check, new File(DIRECTORY, "onlySchemaPath.esql"))
+ .noMore();
+ }
+
+ @Test
+ public void onlySchema() {
+ EsqlCheckVerifier.issues(check, new File(DIRECTORY, "onlySchema.esql"))
+ .noMore();
+ }
+
}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ModuleNameCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ModuleNameCheckTest.java
index 9f2aace7..c6955fbd 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ModuleNameCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ModuleNameCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheckTest.java
new file mode 100644
index 00000000..443dc989
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheckTest.java
@@ -0,0 +1,41 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+/**
+ * This java class is the test class for NavigatingTreeCouldBeReferenceCheck.java.
+ * @author Sapna. singh
+ *
+ */
+public class NavigatingTreeCouldBeReferenceCheckTest {
+
+
+ @Test
+ public void test() {
+ EsqlCheck check = new NavigatingTreeCouldBeReferenceCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/NavigatingTreeCouldBeReference.esql"))
+ .next().atLine(4).withMessage("Navigating message tree could be replaced by a reference.")
+ .noMore();
+ }
+}
+
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NestedIfDepthCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NestedIfDepthCheckTest.java
index 2f497010..720a11f3 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NestedIfDepthCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NestedIfDepthCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NonReservedKeywordCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NonReservedKeywordCheckTest.java
index 2319d22e..e5e02d54 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NonReservedKeywordCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NonReservedKeywordCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/OneStatementPerLineCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/OneStatementPerLineCheckTest.java
index 75e608ef..099d6332 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/OneStatementPerLineCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/OneStatementPerLineCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,8 +33,10 @@ public void test() {
EsqlCheckVerifier.issues(
check,
new File("src/test/resources/oneStatementPerLine.esql"))
- .next().atLine(5).withMessage("Reformat the code to have only one statement per line.")
.next().atLine(6).withMessage("Reformat the code to have only one statement per line.")
+ .next().atLine(7).withMessage("Reformat the code to have only one statement per line.")
+ .next().atLine(9).withMessage("Reformat the code to have only one statement per line.")
+ .next().atLine(12).withMessage("Reformat the code to have only one statement per line.")
.noMore();
}
}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ParameterWithDirectionCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ParameterWithDirectionCheckTest.java
index f293cf65..85b002e4 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ParameterWithDirectionCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ParameterWithDirectionCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DeleteFromStatementTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/PassThruStatementCheckTest.java
similarity index 57%
rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DeleteFromStatementTest.java
rename to esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/PassThruStatementCheckTest.java
index cc088fa6..aae4c1cf 100644
--- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DeleteFromStatementTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/PassThruStatementCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,22 +15,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.exxeta.iss.sonar.esql.api.tree.impl.statement;
+package com.exxeta.iss.sonar.esql.check;
-import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat;
+import java.io.File;
import org.junit.Test;
-import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
-
-public class DeleteFromStatementTest {
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+/**
+ * @author Sapna Singh
+ *
+ */
+public class PassThruStatementCheckTest {
+
@Test
- public void deleteFromStatement(){
- assertThat(Kind.DELETE_FROM_STATEMENT)
- .matches("DELETE FROM Database.SHAREHOLDINGS AS S WHERE S.ACCOUNTNO = InputBody.AccountNumber;");
-
+ public void test() {
+ EsqlCheck check = new PassThruStatementCheck();
+ EsqlCheckVerifier.verify(check, new File("src/test/resources/PassthruStatementCheck.esql"));
}
+
+
+
}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ProcedureNameCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ProcedureNameCheckTest.java
index a3f7b223..ff4d3cfe 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ProcedureNameCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ProcedureNameCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ProcessInvokingItselfCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ProcessInvokingItselfCheckTest.java
new file mode 100644
index 00000000..742efc64
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/ProcessInvokingItselfCheckTest.java
@@ -0,0 +1,42 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+/**
+ * @author C50679
+ *
+ */
+public class ProcessInvokingItselfCheckTest {
+
+ @Test
+ public void test() {
+ EsqlCheck check = new ProcessInvokingItselfCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/ProcessInvokingItself.esql"))
+ .next().atLine(7).withMessage("process invoking itself.")
+ .next().atLine(15).withMessage("process invoking itself.")
+ .next().atLine(23).withMessage("process invoking itself.")
+ .noMore();
+ }
+}
diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/InsertStatementTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/PropagateConsistencyCheckTest.java
similarity index 58%
rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/InsertStatementTest.java
rename to esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/PropagateConsistencyCheckTest.java
index e5e44402..f2d7596d 100644
--- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/InsertStatementTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/PropagateConsistencyCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,22 +15,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.exxeta.iss.sonar.esql.api.tree.impl.statement;
+package com.exxeta.iss.sonar.esql.check;
-import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat;
+import java.io.File;
import org.junit.Test;
-import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
-public class InsertStatementTest {
+public class PropagateConsistencyCheckTest {
+ @Test
+ public void test() {
+ PropagateConsistencyCheck check = new PropagateConsistencyCheck();
- @Test
- public void insertStatement(){
- assertThat(Kind.INSERT_STATEMENT)
- .matches("INSERT INTO Database.{Source}.{Schema}.{Table} (Name, Value) values ('Joe', 12.34);");
+ EsqlCheckVerifier.verify(check, new File("src/test/resources/testmanagement_App_v2/transform/Compute.esql"));
- }
-
-}
+ }
+
+
+}
\ No newline at end of file
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/PropagateToLabelCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/PropagateToLabelCheckTest.java
index 3d405614..319e914b 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/PropagateToLabelCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/PropagateToLabelCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/RoutineCommentsCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/RoutineCommentsCheckTest.java
new file mode 100644
index 00000000..33ae2922
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/RoutineCommentsCheckTest.java
@@ -0,0 +1,43 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+/**
+ * This Java class is a test class to check function header comments
+ * @author
+ *
+ */
+public class RoutineCommentsCheckTest {
+ @Test
+ public void test() {
+
+ EsqlCheckVerifier.issues(new RoutineCommentsCheck(), new File("src/test/resources/routineComments.esql"))
+ .next().atLine(3).withMessage("Document this function with all parameters and return types.")
+ .next().atLine(15).withMessage("Document this function with all parameters and return types.")
+ .next().atLine(42).withMessage("Document this function with all parameters and return types.")
+ .next().atLine(57).withMessage("Document this procedure with all parameters and return types.")
+ .next().atLine(66).withMessage("Document this procedure with all parameters and return types.")
+ .noMore();
+ }
+}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/RoutineWithExcessiveReturnsCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/RoutineWithExcessiveReturnsCheckTest.java
index 93717b0b..d51d1405 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/RoutineWithExcessiveReturnsCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/RoutineWithExcessiveReturnsCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SelectAllCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SelectAllCheckTest.java
index bbac0542..1d2a5e45 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SelectAllCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SelectAllCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BitstreamCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SelfAssignmentCheckTest.java
similarity index 80%
rename from esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BitstreamCheckTest.java
rename to esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SelfAssignmentCheckTest.java
index 4a3989d0..538d67ef 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/BitstreamCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SelfAssignmentCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,10 +23,9 @@
import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
-public class BitstreamCheckTest {
-
+public class SelfAssignmentCheckTest {
@Test
public void test(){
- EsqlCheckVerifier.verify(new BitstreamCheck(), new File("src/test/resources/bitstream.esql"));
+ EsqlCheckVerifier.verify(new SelfAssignmentCheck(), new File("src/test/resources/SelfAssignment.esql"));
}
}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SleepCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SleepCheckTest.java
index 17259c75..f0385bc8 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SleepCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SleepCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SubElementNameCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SubElementNameCheckTest.java
new file mode 100644
index 00000000..ecff4bae
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/SubElementNameCheckTest.java
@@ -0,0 +1,41 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+/**
+ * @author Sapna Singh
+ *
+ */
+public class SubElementNameCheckTest {
+
+ @Test
+ public void test() {
+ EsqlCheck check = new SubElementNameCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/SubElementName.esql"))
+ .next().atLine(5).withMessage("sub-elements should be in UpperCamel-case and elements containing simple value should be in lowercase.")
+ .next().atLine(6).withMessage("sub-elements should be in UpperCamel-case and elements containing simple value should be in lowercase.").noMore();
+ }
+}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TooManyIterateOrLeaveInLoopCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TooManyIterateOrLeaveInLoopCheckTest.java
index 9cd999d1..439fe900 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TooManyIterateOrLeaveInLoopCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TooManyIterateOrLeaveInLoopCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TooManyLinesInFileCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TooManyLinesInFileCheckTest.java
index a80ff3aa..365d651e 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TooManyLinesInFileCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TooManyLinesInFileCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TooManyParametersCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TooManyParametersCheckTest.java
index 0b4b27cc..d7ef5fa0 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TooManyParametersCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TooManyParametersCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TrailingCommentsCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TrailingCommentsCheckTest.java
new file mode 100644
index 00000000..8fa66f42
--- /dev/null
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/TrailingCommentsCheckTest.java
@@ -0,0 +1,48 @@
+/**
+ * This java class is created to implement the logic for checking if the line contains both code and comments,
+ * if it contains both then trailing comments should be removed.
+ *
+ *
+ * @author Prerana Agarkar
+ *
+ */
+
+package com.exxeta.iss.sonar.esql.check;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+
+public class TrailingCommentsCheckTest {
+ @Test
+ public void test() {
+
+ EsqlCheckVerifier.issues(new TrailingCommentsCheck(), new File("src/test/resources/trailingComments.esql"))
+ .next().atLine(7).withMessage("Move this trailing comment on the previous empty line.")
+ .next().atLine(12).withMessage("Move this trailing comment on the previous empty line.")
+ .next().atLine(15).withMessage("Move this trailing comment on the previous empty line.")
+ .next().atLine(16).withMessage("Move this trailing comment on the previous empty line.")
+ .noMore();
+
+ }
+
+ @Test
+ public void withoutPattern(){
+ TrailingCommentsCheck check = new TrailingCommentsCheck();
+ check.setLegalCommentPattern("");
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/trailingComments.esql"))
+ .next().atLine(7).withMessage("Move this trailing comment on the previous empty line.")
+ .next().atLine(12).withMessage("Move this trailing comment on the previous empty line.")
+ .next().atLine(14).withMessage("Move this trailing comment on the previous empty line.")
+ .next().atLine(15).withMessage("Move this trailing comment on the previous empty line.")
+ .next().atLine(16).withMessage("Move this trailing comment on the previous empty line.")
+ .noMore();
+
+
+ }
+
+
+ }
+
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UndocumentedModuleCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UndocumentedModuleCheckTest.java
index d4e0caaf..5122811c 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UndocumentedModuleCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UndocumentedModuleCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UndocumentedRoutineCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UndocumentedRoutineCheckTest.java
index ee681960..18ca945b 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UndocumentedRoutineCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UndocumentedRoutineCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnknownMessageDomainCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnknownMessageDomainCheckTest.java
index 415f91f0..84f92e05 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnknownMessageDomainCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnknownMessageDomainCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BitstreamCheck.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnreachableCodeCheckTest.java
similarity index 65%
rename from esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BitstreamCheck.java
rename to esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnreachableCodeCheckTest.java
index 710f0b36..b801f284 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/BitstreamCheck.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnreachableCodeCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,19 +17,15 @@
*/
package com.exxeta.iss.sonar.esql.check;
-import org.sonar.check.Rule;
+import java.io.File;
-@Rule(key="Bitstream")
-public class BitstreamCheck extends AbstractDoNotUseFunctinCheck {
+import org.junit.Test;
- @Override
- public String getMessage() {
- return "Do not use BITSTREAM it is deprecated.";
- }
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
- @Override
- public String getFunctionName() {
- return "BITSTREAM";
+public class UnreachableCodeCheckTest {
+ @Test
+ public void test(){
+ EsqlCheckVerifier.verify(new UnreachableCodeCheck(), new File("src/test/resources/unreachableCode.esql"));
}
-
}
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnusedRoutineCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnusedRoutineCheckTest.java
index e603e361..69e9706b 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnusedRoutineCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnusedRoutineCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/PassthruFunctionTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnusedVariableCheckTest.java
similarity index 50%
rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/PassthruFunctionTest.java
rename to esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnusedVariableCheckTest.java
index b08a7f07..32775a87 100644
--- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/PassthruFunctionTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UnusedVariableCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,24 +15,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.exxeta.iss.sonar.esql.api.tree;
+package com.exxeta.iss.sonar.esql.check;
-import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat;
+import java.io.File;
import org.junit.Test;
-import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
-
-public class PassthruFunctionTest {
+import com.exxeta.iss.sonar.esql.api.EsqlCheck;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+/**
+ * This java class is the test class.
+ * @author Sapna Singh
+ *
+ */
+public class UnusedVariableCheckTest {
@Test
- public void passthruStatement(){
- assertThat(Kind.PASSTHRU_FUNCTION)
- .matches("PASSTHRU('SELECT R.* FROM Schema1.Table1 AS R WHERE R.Name = ? OR R.Name = ? ORDER BY Name' TO Database.DSN1 VALUES ('Name1', 'Name4'))")
- .matches("PASSTHRU('aaaaa' VALUES ('aaaa'))");
-
- }
+ public void test() {
+ EsqlCheck check = new UnusedVariableCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/UnusedVariable.esql"))
+
+ .next().atLine(11).withMessage("Remove the unused Variable.")
+ .next().atLine(33).withMessage("Remove the unused Variable.")
+ .noMore();
+ }
+
}
-
\ No newline at end of file
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UseBrokerSchemaCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UseBrokerSchemaCheckTest.java
index 1b411857..3db2562f 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UseBrokerSchemaCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UseBrokerSchemaCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UselessParenthesesCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UselessParenthesesCheckTest.java
index 13a63d86..a3409deb 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UselessParenthesesCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/UselessParenthesesCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/VariableNameCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/VariableNameCheckTest.java
index 2f0f61f4..4fe0dfaf 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/VariableNameCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/VariableNameCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/VariablesSubtreeCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/VariablesSubtreeCheckTest.java
index 783430fc..9e1e4d4e 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/VariablesSubtreeCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/VariablesSubtreeCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/XmlnscDomainCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/XmlnscDomainCheckTest.java
index 2c400aab..e3243dee 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/XmlnscDomainCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/XmlnscDomainCheckTest.java
@@ -1,6 +1,6 @@
/*
* Sonar ESQL Plugin
- * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/esql-checks/src/test/resources/BinaryOperatorSpace.esql b/esql-checks/src/test/resources/BinaryOperatorSpace.esql
new file mode 100644
index 00000000..052306ae
--- /dev/null
+++ b/esql-checks/src/test/resources/BinaryOperatorSpace.esql
@@ -0,0 +1,22 @@
+CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+DECLARE versionRef REFERENCE TO InputRoot.SOAP.Context.SOAP_Version;
+ CASE
+ WHEN versionRef>= 1 THEN
+ SET Environment.Fault.faultcode='soapenv:Client';
+ WHEN versionRef<1.2 THEN
+ SET Environment.Fault.faultcode='soapenv:Sender';
+ END CASE;
+CREATE FIELD Environment.LogData;
+ DECLARE refEnv REFERENCE TO Environment.LogData;
+ SET refEnv.serviceOperationName=InputRoot.SOAP.Context.operation;
+ SET refEnv.operationId = EVAL(Environment.LogData.serviceOperationName);
+ SET refEnv.serviceName = InputRoot.SOAP.Context.service;
+ SET refEnv.interfaceId = InputRoot.SOAP.Header.ns:Info.consumerId;
+ SET refEnv.serviceVersion = SUBSTRING(SUBSTRING(SUBSTRING(InputRoot.SOAP.Context.portTypeNamespace AFTER InputRoot.SOAP.Context.service) AFTER '/')BEFORE '/');
+ SET OutputRoot =
+ InputRoot;
+ DECLARE myInt,myInt3 INTEGER 1;
+ DECLARE myInt2, myInt4 INTEGER 1;
+ RETURN TRUE;
+ END;
diff --git a/esql-checks/src/test/resources/BlankLineBeforeComments.esql b/esql-checks/src/test/resources/BlankLineBeforeComments.esql
new file mode 100644
index 00000000..d6a9a68e
--- /dev/null
+++ b/esql-checks/src/test/resources/BlankLineBeforeComments.esql
@@ -0,0 +1,27 @@
+BROKER SCHEMA generic
+DECLARE soapenv NAMESPACE 'http://schemas.xmlsoap.org/soap/envelope/';
+CREATE COMPUTE MODULE initialize
+/****************************************************************************
+* This module will initialize the service/operation related variables
+which are used to trace the message.
+*****************************************************************************/
+
+CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ DECLARE versionRef REFERENCE TO InputRoot.SOAP.Context.SOAP_Version;
+ CASE
+ WHEN versionRef = '1.1' THEN
+ SET Environment.Fault.faultcode = 'soapenv:Client';
+ END CASE;
+ --this is comment line
+ CREATE FIELD Environment.LogData;
+ DECLARE refEnv REFERENCE TO Environment.LogData;
+
+ --Another comment line
+ RETURN TRUE;
+ END;
+
+ /*
+ * And a comment block
+ */
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/CyclomaticComplexity.esql b/esql-checks/src/test/resources/CyclomaticComplexity.esql
new file mode 100644
index 00000000..4ddb7df1
--- /dev/null
+++ b/esql-checks/src/test/resources/CyclomaticComplexity.esql
@@ -0,0 +1,55 @@
+CREATE COMPUTE MODULE a
+ create FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ IF x='ANS' OR y = 'AND' THEN
+ RETURN TRUE;
+ END IF;
+ WHILE I<5 DO
+ IF x='ANS1' THEN
+ RETURN TRUE;
+ ELSEIF x='ANS1' THEN
+ RETURN FALSE;
+ ELSEIF x='AN3' THEN
+ RETURN FALSE;
+ ELSEIF x='AN4' THEN
+ RETURN FALSE;
+ ELSE
+ RETURN FALSE;
+ END IF;
+ SET I = I + 1;
+ END WHILE;
+ RETURN TRUE;
+ IF x='ANS' OR y = 'AND' AND z = 'XYZ' OR a='space' AND z = 'XYZ' OR a='space' AND z = 'XYZ' OR a='space' THEN
+ RETURN TRUE;
+ END IF;
+ END;
+ END MODULE;
+ CREATE COMPUTE MODULE b
+
+ CREATE FUNCTION Main() RETURNS CHAR
+ BEGIN
+ RETURN A<2;
+ END;
+ CREATE Procedure Main2() RETURNS BOOLEAN
+ BEGIN
+ DECLARE myInt INTEGER 1;
+ DECLARE myInt2,myInt4 INTEGER;
+ IF x='ANS' OR y = 'AND' AND z = 'XYZ' OR a='space' AND z = 'XYZ' OR a='space' AND z = 'XYZ' OR a='space' THEN
+ RETURN TRUE;
+ END IF;
+ IF x='ANS' OR y = 'AND' AND z = 'XYZ' OR a='space' AND z = 'XYZ' OR a='space' AND z = 'XYZ' OR a='space' THEN
+ RETURN TRUE;
+ END IF;
+ IF x='ANS' OR y = 'AND' AND z = 'XYZ' OR a='space' AND z = 'XYZ' OR a='space' AND z = 'XYZ' OR a='space' THEN
+ RETURN TRUE;
+ END IF;
+ IF x='ANS' OR y = 'AND' AND z = 'XYZ' OR a='space' AND z = 'XYZ' OR a='space' AND z = 'XYZ' OR a='space' THEN
+ RETURN TRUE;
+ END IF;
+ END;
+
+END MODULE;
+
+
+
+
diff --git a/esql-checks/src/test/resources/DeprecatedMethod.esql b/esql-checks/src/test/resources/DeprecatedMethod.esql
new file mode 100644
index 00000000..5856c6de
--- /dev/null
+++ b/esql-checks/src/test/resources/DeprecatedMethod.esql
@@ -0,0 +1,26 @@
+BROKER SCHEMA generic
+DECLARE soapenv NAMESPACE 'http://schemas.xmlsoap.org/soap/envelope/';
+DECLARE ns NAMESPACE 'http://com/abnamro/Services/AccessFacilityAgreement/v2/' ;
+DECLARE createAccessFacilityAgreement EXTERNAL CHAR '';
+declare updateAccessFacilityAgreement EXTERNAL CHAR '';
+CREATE COMPUTE MODULE initialize
+CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+DECLARE versionRef REFERENCE TO InputRoot.SOAP.Context.SOAP_Version;
+ CASE
+ WHEN versionRef = '1.1' THEN
+ SET Environment.Fault.faultcode = 'soapenv:Client';
+ WHEN versionRef = '1.2' THEN
+ SET Environment.Fault.faultcode = 'soapenv:Sender';
+ END CASE;
+CREATE FIELD Environment.LogData;
+ DECLARE refEnv REFERENCE TO Environment.LogData;
+ SET refEnv.serviceOperationName = InputRoot.SOAP.Context.operation;
+ SET refEnv.operationId = EVAL(Environment.LogData.serviceOperationName);
+ SET refEnv.serviceName = BITSTREAM(InputRoot.MQMD.UserIdentifier); --Noncompliant {{Do not use BITSTREAM it is deprecated.}}
+ SET refEnv.interfaceId = InputRoot.SOAP.Header.ns:Info.consumerId;
+ SET refEnv.serviceVersion = SUBSTRING(SUBSTRING(SUBSTRING(InputRoot.SOAP.Context.portTypeNamespace AFTER InputRoot.SOAP.Context.service) AFTER '/')BEFORE '/');
+ SET OutputRoot=InputRoot;
+ RETURN TRUE;
+ END;
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/FileHeaderCheck/file4.esql b/esql-checks/src/test/resources/FileHeaderCheck/file4.esql
new file mode 100644
index 00000000..8ee7e056
--- /dev/null
+++ b/esql-checks/src/test/resources/FileHeaderCheck/file4.esql
@@ -0,0 +1,7 @@
+/*
+Change Log
+No. Incident Number Jira Number Description Date Fixed Updated ESQL/Node
+1 INC0182018 DI-999 Test defect 09/01/2017 test.esql
+*/
+CREATE COMPUTE MODULE ABC
+END MODULE;
diff --git a/esql-checks/src/test/resources/FilterNodeHaveOnlyOneReturn.esql b/esql-checks/src/test/resources/FilterNodeHaveOnlyOneReturn.esql
new file mode 100644
index 00000000..df58742d
--- /dev/null
+++ b/esql-checks/src/test/resources/FilterNodeHaveOnlyOneReturn.esql
@@ -0,0 +1,63 @@
+CREATE FILTER MODULE Flow1_Filter
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ RETURN FALSE;
+ END;
+END MODULE;
+
+CREATE COMPUTE MODULE Flow2_Compute
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ IF A > B THEN
+ RETURN TRUE;
+ ELSE
+ THROW USER EXCEPTION;
+ END IF;
+ END;
+END MODULE;
+
+CREATE FILTER MODULE Flow3_Filter
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ RETURN TRUE;
+ END;
+END MODULE;
+
+CREATE FILTER MODULE Flow3_Filter
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ THROW USER EXCEPTION;
+ END;
+END MODULE;
+
+CREATE FILTER MODULE Flow4_Filter
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ IF A > B THEN
+ RETURN TRUE;
+ ELSE
+ RETURN FALSE;
+ END IF;
+ END;
+END MODULE;
+
+CREATE FILTER MODULE Flow5_Filter
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ RETURN getResult();
+ END;
+END MODULE;
+
+CREATE FILTER MODULE Flow6_Filter
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ END;
+END MODULE;
+
diff --git a/esql-checks/src/test/resources/FilterNodeModifyMessage.esql b/esql-checks/src/test/resources/FilterNodeModifyMessage.esql
new file mode 100644
index 00000000..c15435ae
--- /dev/null
+++ b/esql-checks/src/test/resources/FilterNodeModifyMessage.esql
@@ -0,0 +1,19 @@
+CREATE FILTER MODULE Flow2_Filter
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ SET a = 'a';
+ SET a.a = 'a';
+ RETURN FALSE;
+ END;
+END MODULE;
+
+CREATE COMPUTE MODULE Flow2
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ SET a = 'a';
+ SET a.a = 'a';
+ RETURN FALSE;
+ END;
+END MODULE;
diff --git a/esql-checks/src/test/resources/FunctionLength.esql b/esql-checks/src/test/resources/FunctionLength.esql
new file mode 100644
index 00000000..cbe636f6
--- /dev/null
+++ b/esql-checks/src/test/resources/FunctionLength.esql
@@ -0,0 +1,604 @@
+
+/****************************************************************************
+File Name:
+Purpose: This module performs request and response tranformation.
+Author: Ekta Patel
+Version:
+Date: 07-07-2017
+*****************************************************************************/
+/*
+* Change log goes here
+*/
+BROKER SCHEMA serviceOperations
+DECLARE soapenv NAMESPACE 'http://schemas.xmlsoap.org/soap/envelope/';
+--DECLARE nsconOper NAMESPACE 'http://api.topicus.finance/fbl/documentgenerationservice/2017/6/operations';
+--DECLARE nsconDat NAMESPACE 'http://api.topicus.finance/fbl/documentgeneration/2017/6/datatypes';
+--DECLARE nsProvider NAMESPACE 'http://com/abnamro/nl/DocumentFulfillment/v1/';
+DECLARE nsError NAMESPACE 'http://api.topicus.finance/fbl/common/2016/7/metadata';
+
+
+DECLARE ns15 NAMESPACE 'http://api.topicus.finance/fbl/documentgenerationservice/2017/8/operations';
+DECLARE ns19 NAMESPACE 'http://com/abnamro/nl/DocumentFulfillment/v1/';
+DECLARE ns31 NAMESPACE 'http://api.topicus.finance/fbl/documentgeneration/2017/8/datatypes';
+/****************************************************************************
+* A procedure that will build the request message for FR151
+* IN inRef : Reference to Soap Body
+* IN outRef : Reference to OutputRoot.
+* IN Environment: Reference to Enviroment.
+*****************************************************************************/
+CREATE PROCEDURE AdapterffCreateDocumentRequest(IN inRef REFERENCE, IN outRef REFERENCE, IN Environment REFERENCE)
+
+BEGIN
+ -- --DECLARE inRefReq REFERENCE TO inRef.SOAP.Body.nsconOper:CreateDocumentRequest;
+ -- CREATE FIELD outRef.SOAP.Body.ns19:createDocument.requestParameters;
+ -- DECLARE outRefReq REFERENCE TO outRef.SOAP.Body.ns19:createDocument.requestParameters;
+ -- DECLARE inRefReq REFERENCE TO inRef.SOAP.Body.ns15:CreateDocumentRequest.DocumentGenerationContainer;
+ -- DECLARE inRefDGC REFERENCE TO inRefReq.FTB;
+ -- DECLARE inRefFTB REFERENCE TO inRefDGC.ns31:PledgingCover;
+ -- -- CREATING REFERENCE FIELDS
+ -- CREATE LASTCHILD OF outRef DOMAIN 'SOAP';
+ -- SET outRef.SOAP.Context.Namespace.(SOAP.NamespaceDecl)xmlns:soapenv = soapenv;
+ --
+ -- CREATE FIELD outRef.SOAP.Header.ns19:Info;
+ -- DECLARE SOHeader REFERENCE TO outRef.SOAP.Header.ns19:Info;
+ --
+ -- IF EXISTS(inRef.SOAP.Header.ns15:Info.consumerId[]) THEN
+ -- IF FIELDVALUE(inRef.SOAP.Header.ns15:Info.consumerId) <> '' THEN
+ --
+ -- SET SOHeader.consumerId = inRef.SOAP.Header.ns15:Info.consumerId;
+ -- ELSE
+ -- SET SOHeader.consumerId = 'CID00004';
+ -- END IF;
+ -- ELSE
+ -- SET SOHeader.consumerId = 'CID00004';
+ -- END IF;
+ -- -- DECLARE outRef REFERENCE TO outRef.SOAP;
+ -- -- CREATE FIELD outRef.Body.nsProvider:createDocument;
+ -- -- CREATE LASTCHILD OF outReqPar.customer.party NAME 'partyTypeId';
+ -- -- CREATE LASTCHILD OF outReqPar.customer.party.partyTypeId NAME 'scheme';
+ -- -- CREATE LASTCHILD OF outReqPar.customer.party.partyTypeId NAME 'value';
+ -- -- CREATE LASTCHILD OF outReqPar.customer.party NAME 'hasName';
+ -- --
+ -- -- DECLARE outRefReq REFERENCE TO outRef.SOAP.Body.nsProvider:createDocument;
+ -- -- -- DECLARE inRefDoc REFERENCE TO inRefReq.DocumentGenerationContainer.DocumentMetadata;
+ -- -- CREATE LASTCHILD OF outRefReq NAME 'requestParameters';
+ -- -- DECLARE outReqPar REFERENCE TO outRefReq.requestParameters;
+ -- -- CREATE LASTCHILD OF outReqPar NAME 'document';
+ -- -- DECLARE docRef REFERENCE TO outReqPar.document;
+ -- -- DECLARE custRef REFERENCE TO outReqPar.customer;
+ -- -- BUILDING REQUEST MESSAGE
+ -- -- SET custRef.party.partyId.scheme = 'BusinessContactNumberNL';
+ -- -- SET custRef.party.partyId.value = inRefDoc.MainBorrowerId;
+ -- --
+ -- -- SET custRef.representativeParty.partyId.scheme = 'BusinessContactNumberNL';
+ -- -- SET custRef.representativeParty.partyId.value = inRefDoc.MainBorrowerId;
+ -- -- SET custRef.Party.PartyTypeId.Scheme = 'PartyTypeId';
+ -- -- SET custRef.Party.PartyTypeId.value = '0000';
+ -- -- SET custRef.representativePartyParty.PartyTypeId.Scheme = 'PartyTypeId';
+ -- -- SET custRef.representativePartyParty.PartyTypeId.value = '0000';
+ -- -- SET docRef.confidentialityRatingScaleId.scheme = 'ConfidentialityRatingScaleId';
+ -- -- SET docRef.confidentialityRatingScaleId.value = '1';
+ -- -- SET docRef.reference = inRefDoc.Subject;
+ -- -- SET docRef.title = inRefDoc.DocumentName;
+ -- -- SET docRef.documentTypeId.scheme = 'DocumentSubTypeId';
+ -- -- SET docRef.documentTypeId.value = '6';
+ -- -- SET docRef.documentGroupId.scheme = 'DocumentTypeId';
+ -- -- SET docRef.documentGroupId.value = '7';
+ -- -- SET outReqPar.organizationUnit.organizationUnitId.scheme = 'boNumber';
+ -- -- SET outReqPar.channelTypeId.scheme = 'OutputchannelId';
+ -- -- SET outReqPar.channelTypeId.value = 'DUM';
+ -- -- SET outReqPar.dossierId.scheme = 'DossierID';
+ -- -- SET outReqPar.dossierId.value = inRefDoc.DossierId;
+ -- -- SET outReqPar.documentPreview = 'false';
+ -- --
+ -- -- SET outReqPar.agreementId.scheme = 'AgreementIdNL';
+ -- -- SET outReqPar.agreementId.value = inRefDoc.AgreementId;
+ -- -- -- Retrieve Party
+ -- --
+ -- -- DECLARE outRefRet REFERENCE TO outRef.SOAP.Body.nsRetrieve:retrievePartyDetails;
+ -- -- DECLARE inRetResParam REFERENCE TO inRetRes.responseParameters;
+ -- -- CREATE LASTCHILD OF outRefRet NAME 'requestParameters';
+ -- -- DECLARE outRetParam REFERENCE TO outRefRet.requestParameters;
+ -- -- SET outRetParam.partyId.value = inRefDoc.MainBorrowerId;
+ -- -- SET outRetParam.selectCustomerFlag = 'true';
+ -- -- SET outReqPar.organizationUnit.organizationUnitId.value = inRetResParam.customer.managingOrganizationUnitId.value;
+ -- --
+ -- -- SET outRefReq.documentPreview = 'false';
+ -- --
+ -- --
+ -- -- SET outRetParam.partyId.value = inRefDGC.Borrower.ExternalRelationNumber;
+ -- -- SET outRetParam.selectPartyFlag = 'true';
+ -- --
+ -- -- SET outRetParam.partyId.value = inRefDGC.Borrower.ExternalRelationNumber;
+ -- -- SET outRetParam.selectResponsiblePartyFlag = 'true';
+ --
+ --
+ --
+ -- SET outRefReq.agreementId.scheme = 'AgreementIdNL';
+ -- SET outRefReq.agreementId.value = inRefReq.DocumentMetadata.AgreementId;
+ -- SET outRefReq.customer.party.partyId.scheme = 'BusinessContactNumberNL';
+ -- SET outRefReq.customer.party.partyId.value = inRefReq.DocumentMetadata.MainBorrowerId;
+ -- SET outRefReq.customer.representativeParty.partyId.scheme = 'BusinessContactNumberNL';
+ -- SET outRefReq.customer.representativeParty.partyId.value = inRefReq.DocumentMetadata.MainBorrowerId;
+ -- SET outRefReq.customer.party.partyTypeId.scheme = 'PartyTypeId';
+ -- SET outRefReq.customer.party.partyTypeId.value = '0000';
+ -- SET outRefReq.customer.representativeParty.partyTypeId.scheme = 'PartyTypeId';
+ -- SET outRefReq.customer.representativeParty.partyTypeId.value = '0000';
+ -- SET outRefReq.document.confidentialityRatingScaleId.scheme = 'ConfidentialityRatingScaleId';
+ -- SET outRefReq.document.confidentialityRatingScaleId.value = '1';
+ -- SET outRefReq.document.reference = inRefReq.DocumentMetadata.Subject;
+ -- SET outRefReq.document.title = inRefReq.DocumentMetadata.DocumentName;
+ -- SET outRefReq.document.documentTypeId.scheme = 'DocumentSubTypeId';
+ -- SET outRefReq.document.documentTypeId.value = '6';
+ -- SET outRefReq.document.documentGroupId.scheme = 'DocumentTypeId';
+ -- SET outRefReq.document.documentGroupId.value = '7';
+ -- SET outRefReq.document.documentContext.scheme = 'DocumentTypeSequenceNumber';
+ -- SET outRefReq.document.documentContext.value = 'DOCTYPE205';
+ --
+ -- SET outRefReq.document.documentContext.scheme = 'BuildingBlockID';
+ -- SET outRefReq.document.documentContext.value = '99';
+ -- SET outRefReq.document.documentContext.scheme = 'ConsumerSystem';
+ -- SET outRefReq.document.documentContext.value = 'DQO00001';
+ -- SET outRefReq.document.documentContext.scheme = 'VolgNummer';
+ -- SET outRefReq.document.documentContext.value = '205';
+ -- SET outRefReq.document.documentContext.scheme = 'DRMDocumentTitlle';
+ -- SET outRefReq.document.documentContext.value = 'Offerte_' || CURRENT_TIMESTAMP;
+ -- SET outRefReq.channelTypeId.scheme = 'OutputchannelId';
+ -- SET outRefReq.channelTypeId.value = 'DUM';
+ -- SET outRefReq.dossierId.scheme = 'DossierID';
+ -- SET outRefReq.dossierId.value = inRefReq.DocumentMetadata.DossierId;
+ -- SET outRefReq.organizationUnit.organizationUnitId.value = 'boNumber';
+ -- -- CALL GetElectronicDocument(inRef,outRef,Environment);
+ -- -- SET outReqPar.electronicDocument.content.bytes = '1';
+ -- -- DECLARE docRequest BLOB ;
+ -- --
+ -- -- SET docRequest = ASBITSTREAM(outRef.XMLNSC ENCODING inRef.Properties.Encoding CCSID inRef.Properties.CodedCharSetId);
+ -- --
+ -- -- DECLARE base64FieldType INTEGER XMLNSC.Field + XMLNSC.base64Binary;
+ -- --
+ -- -- CREATE LASTCHILD OF outReqPar.electronicDocument.content TYPE base64FieldType NAME 'base64binary' VALUE docRequest ;
+ -- --
+ -- -- SET outReqPar.electronicDocument.content.theBinLength = LENGTH(docRequest);
+ -- --
+ -- -- SET outReqPar.electronicDocument.content.theContentType.scheme = 'MIME media type';
+ -- -- SET outReqPar.electronicDocument.content.theContentType.value = 'Application/XML';
+ --
+ -- CALL GetElectronicDocument(inRef,outRef,Environment);
+ -- SET outRefReq.electronicDocument.content.bytes = '1';
+ -- DECLARE docRequest BLOB ;
+ --
+ -- SET docRequest = ASBITSTREAM(outRef.XMLNSC ENCODING inRef.Properties.Encoding CCSID inRef.Properties.CodedCharSetId);
+ --
+ -- DECLARE base64FieldType INTEGER XMLNSC.Field + XMLNSC.base64Binary;
+ --
+ -- CREATE LASTCHILD OF outRefReq.electronicDocument.content TYPE base64FieldType NAME 'base64binary' VALUE docRequest ;
+ --
+ -- SET outRefReq.electronicDocument.content.theBinLength = LENGTH(docRequest);
+ --
+ -- SET outRefReq.electronicDocument.content.theContentType.scheme = 'MIME media type';
+ -- SET outRefReq.electronicDocument.content.theContentType.value = 'Application/XML';
+ --
+ DELETE FIRSTCHILD OF outRef.SOAP;
+ CREATE FIELD outRef.SOAP.Header;
+ DECLARE hdrRef REFERENCE TO outRef.SOAP.Header;
+ SET hdrRef.ns19:Info.consumerId = 'CID00004';
+ CREATE FIELD outRef.SOAP.Body.ns19:createDocument.requestParameters;
+ DECLARE outRefReq REFERENCE TO outRef.SOAP.Body.ns19:createDocument.requestParameters;
+ DECLARE inRefReq REFERENCE TO inRef.SOAP.Body.ns15:CreateDocumentRequest.DocumentGenerationContainer;
+ DECLARE inRefDGC REFERENCE TO inRefReq.DocumentGenerationContainer.FTB;
+ DECLARE inRefFTB REFERENCE TO inRefDGC.ns31:PledgingCover;
+ CREATE FIELD outRefReq.customer;
+ DECLARE outRefCust REFERENCE TO outRefReq.customer;
+ CREATE FIELD outRefReq.agreementId;
+ DECLARE outRefAg REFERENCE TO outRefReq.agreementId;
+ CREATE FIELD outRefReq.document;
+ DECLARE outRefDoc REFERENCE TO outRefReq.document;
+ DECLARE var_date,var_date1,var_date2,i,j CHARACTER;
+
+
+ SET outRefCust.party.partyId.scheme = 'BusinessContactNumberNL';
+ SET outRefCust.party.partyId.value = inRefReq.DocumentMetadata.MainBorrowerId;
+ SET outRefCust.representativeParty.partyId.scheme = 'BusinessContactNumberNL';
+ SET outRefCust.representativeParty.partyId.value = inRefReq.DocumentMetadata.MainBorrowerId;
+ SET outRefCust.party.partyTypeId.scheme = 'PartyTypeId';
+ SET outRefCust.party.partyTypeId.value = '0000';
+ CREATE FIELD outRefCust.party.hasName;
+ DECLARE hasRef REFERENCE TO outRefCust.party.hasName;
+ CREATE LASTCHILD OF hasRef NAME 'fullName';
+ CREATE FIELD hasRef.partyNameTypeId;
+ DECLARE hasPartyRef REFERENCE TO hasRef.partyNameTypeId;
+ CREATE LASTCHILD OF hasPartyRef NAME 'scheme';
+ CREATE LASTCHILD OF hasPartyRef NAME 'value';
+
+
+ SET outRefCust.representativeParty.partyTypeId.scheme = 'PartyTypeId';
+ SET outRefCust.representativeParty.partyTypeId.value = '0000';
+ -- Has name added
+
+ SET outRefAg.scheme = 'AgreementIdNL';
+ SET outRefAg.value = inRefReq.DocumentMetadata.AgreementId;
+ SET outRefDoc.confidentialityRatingScaleId.scheme = 'ConfidentialityRatingScaleId';
+ SET outRefDoc.confidentialityRatingScaleId.value = '1';
+ SET outRefDoc.reference = inRefReq.DocumentMetadata.Subject;
+ SET outRefDoc.title = inRefReq.DocumentMetadata.DocumentName;
+
+
+ SET outRefDoc.documentTypeId.scheme = 'DocumentSubTypeId';
+ SET outRefDoc.documentTypeId.value = '6';
+ SET outRefDoc.documentGroupId.scheme = 'DocumentTypeId';
+ SET outRefDoc.documentGroupId.value = '7';
+
+
+ SET outRefDoc.documentContext[1].scheme = 'DocumentTypeSequenceNumber';
+ SET outRefDoc.documentContext[1].value = 'DOCTYPE205';
+
+ SET outRefDoc.documentContext[2].scheme = 'BuildingBlockID';
+ SET outRefDoc.documentContext[2].value = '99';
+
+ SET outRefDoc.documentContext[3].scheme = 'ConsumerSystem';
+ SET outRefDoc.documentContext[3].value = 'DQO00001';
+
+ SET outRefDoc.documentContext[4].scheme = 'VolgNummer';
+ SET outRefDoc.documentContext[4].value = '205';
+
+ SET outRefDoc.documentContext[5].scheme = 'DRMDocumentTitlle';
+ SET var_date = CAST(CURRENT_TIMESTAMP AS CHARACTER FORMAT 'YYYY-MM-DD hh:mm:ss.SSSS');
+ SET var_date1 = SUBSTRING(var_date BEFORE ' ');
+ SET var_date2 = SUBSTRING(var_date AFTER ' ');
+ SET outRefDoc.documentContext[5].value = 'Offerte_'||var_date1||'T'||var_date2;
+
+
+ SET outRefReq.channelTypeId.scheme = 'OutputchannelId';
+ SET outRefReq.channelTypeId.value = 'DUM';
+ SET outRefReq.dossierId.scheme = 'DossierID';
+ SET outRefReq.dossierId.value = inRefReq.DocumentMetadata.DossierId;
+ SET outRefReq.documentPreview = 'false';
+
+ SET outRefReq.organizationUnit.organizationUnitId.value = COALESCE(Environment.variable.retrieveParty.customer.managingOrganizationUnitId.value, '');
+ --SET outRefReq.organizationUnit.organizationUnitId.scheme = 'boNumber';
+ -- Binary to Base64
+
+ CALL GetElectronicDocument(inRef,outRef,Environment);
+ SET outRefReq.electronicDocument.content.bytes = '1';
+ DECLARE docRequest BLOB ;
+
+ SET docRequest = ASBITSTREAM(outRef.XMLNSC ENCODING inRef.Properties.Encoding CCSID inRef.Properties.CodedCharSetId);
+
+ DECLARE base64FieldType INTEGER XMLNSC.Field + XMLNSC.base64Binary;
+
+ CREATE LASTCHILD OF outRefReq.electronicDocument.content TYPE base64FieldType NAME 'base64binary' VALUE docRequest ;
+
+ SET outRefReq.electronicDocument.content.theBinLength = LENGTH(docRequest);
+
+ SET outRefReq.electronicDocument.content.theContentType.scheme = 'MIME media type';
+ SET outRefReq.electronicDocument.content.theContentType.value = 'Application/XML';
+
+END;
+/****************************************************************************
+* A procedure that will build the response message for retrieve operation
+* IN inRef : Reference to InputLocalEnvironment
+* IN outRef : Reference to Soap Body.
+* IN Environment: Reference to Enviroment.
+*****************************************************************************/
+CREATE PROCEDURE AdapterffCreateDocumentResponse(IN inRef REFERENCE, IN outRef REFERENCE, IN Environment REFERENCE)
+
+BEGIN
+ -------------------- VARIABLE DECLARATIONS -----------------------------------------------------------------
+ DECLARE inRefErr REFERENCE TO inRef.SOAP.Body;
+ -------------------- BUILDING RESPONSE MESSAGE ------------------------------------------------------
+ IF EXISTS(inRefErr.soapenv:Fault.detail.ns19:createDocumentException[]) THEN
+ SET Environment.flag = 'true';
+ DECLARE inRefErr1 REFERENCE TO inRefErr.soapenv:Fault.detail;
+ DECLARE inRefExc REFERENCE TO inRefErr1.ns19:createDocumentException;
+ CREATE FIELD Environment.LogData.providerError;
+ DECLARE envRefErr REFERENCE TO Environment.LogData.providerError;
+
+
+ SET envRefErr.code = inRefExc.code;
+ SET envRefErr.description = inRefExc.description;
+ CREATE FIELD outRef.SOAP.Body.soapenv:Fault;
+ DECLARE outFaultRef REFERENCE TO outRef.SOAP.Body.soapenv:Fault;
+ SET outFaultRef.faultcode = inRefErr.soapenv:Fault.faultcode;
+ SET outFaultRef.faultstring = 'Provider Error Occured.';
+
+ IF (inRefErr.soapenv:Fault.faultstring) IN ('SC441_DOCGEN_0700nullnull','SC441_SC441OBSERVER_ERROR_0100','100','101','201''200','202','SC441_STOREWORKFILESERVICEIMPL_ERROR_0101') THEN
+ CASE
+
+ WHEN inRefErr.soapenv:Fault.faultstring = 'SC441_DOCGEN_0700nullnull'
+ OR inRefErr.soapenv:Fault.faultstring = 'SC441_SC441OBSERVER_ERROR_0100'
+ OR inRefErr.soapenv:Fault.faultstring = 100 THEN
+ CREATE LASTCHILD OF outFaultRef NAME 'detail';
+ DECLARE detailRef REFERENCE TO outFaultRef.detail;
+ CREATE FIELD detailRef.nsError:CreateDocumentException.ExceptionElement;
+ DECLARE outRefExc REFERENCE TO detailRef.nsError:CreateDocumentException.ExceptionElement;
+ SET outRefExc.code = 102;
+ SET outRefExc.description = COALESCE(inRefExc.description,'');
+
+ SET outRefExc.status = inRefExc.status;
+
+ WHEN inRefErr.soapenv:Fault.faultstring = 101
+ OR inRefErr.soapenv:Fault.faultstring = 201
+ OR inRefErr.soapenv:Fault.faultstring = 200
+ OR inRefErr.soapenv:Fault.faultstring = 202
+ OR inRefErr.soapenv:Fault.faultstring = 'SC441_STOREWORKFILESERVICEIMPL_ERROR_0101' THEN
+
+ CREATE LASTCHILD OF outFaultRef NAME 'detail';
+ DECLARE detailRef REFERENCE TO outFaultRef.detail;
+ CREATE FIELD detailRef.nsError:CreateDocumentException.ExceptionElement;
+ DECLARE outRefExc REFERENCE TO detailRef.nsError:CreateDocumentException.ExceptionElement;
+ SET outRefExc.code = 101;
+ SET outRefExc.description = COALESCE(inRefExc.description,'');
+ SET outRefExc.status = inRefExc.status;
+ END CASE;
+ END IF;
+ ELSEIF EXISTS(inRefErr.soapenv:Fault[]) THEN
+ SET Environment.flag = 'true';
+ CREATE FIELD Environment.LogData.providerError;
+ DECLARE envRefErr REFERENCE TO Environment.LogData.providerError;
+
+ SET envRefErr.code = inRefErr.soapenv:Fault.faultcode;
+ SET envRefErr.description = inRefErr.soapenv:Fault.faultstring;
+ CREATE FIELD outRef.Body.soapenv:Fault;
+ DECLARE outFaultRef REFERENCE TO outRef.SOAP.Body.soapenv:Fault;
+ SET outFaultRef.faultcode = inRefErr.soapenv:Fault.faultcode;
+ SET outFaultRef.faultstring = 'Provider Error Occured.';
+
+ ELSE
+ DECLARE inRefReq REFERENCE TO inRefErr.ns19:createDocumentResponse.responseParameters;
+
+ CREATE FIELD outRef.SOAP.Body.ns15:CreateDocumentResponse;
+ DECLARE outRefReq REFERENCE TO outRef.SOAP.Body.ns15:CreateDocumentResponse;
+ SET outRefReq.DocumentId = inRefReq.documentResponseGroup.documentId.value;
+
+ END IF;
+
+END;
+/****************************************************************************
+* A procedure that will build the request message for FR151
+* IN inRef : Reference to Soap Body
+* IN outRef : Reference to OutputRoot.
+* IN Environment: Reference to Enviroment.
+*****************************************************************************/
+Create PROCEDURE GetElectronicDocument(IN inRef REFERENCE, IN outRef REFERENCE, IN Environment REFERENCE)
+
+BEGIN
+ CREATE LASTCHILD OF outRef DOMAIN 'XMLNSC';
+ CREATE FIELD outRef.XMLNSC.documentRequest;
+ DECLARE outDoc REFERENCE TO outRef.XMLNSC.documentRequest;
+ CREATE LASTCHILD OF outDoc NAME 'electronicDocument';
+
+ DECLARE outElecDoc REFERENCE TO outDoc.electronicDocument;
+ CREATE FIELD outElecDoc.generalAttrGroup;
+ DECLARE outGenAttr REFERENCE TO outElecDoc.generalAttrGroup;
+ DECLARE inRefReq REFERENCE TO inRef.SOAP.Body.ns15:CreateDocumentRequest.DocumentGenerationContainer;
+ DECLARE inRefDGC REFERENCE TO inRefReq.FTB;
+ DECLARE inRefFTB REFERENCE TO inRefDGC.ns31:PledgingCover;
+ DECLARE e_date, e_date1 CHARACTER;
+
+ SET outGenAttr.selectorLogo = '1';
+ --SET e_date1 = CAST(inRefDGC.ns31:Offergroup.ns31:ExpectedOfferDate AS CHARACTER FORMAT 'yyyy-MM-dd');
+ --SET outGenAttr.communicationCreationDate = e_date1; --CAST(inRefDGC.ns31:Offergroup.ns31:ExpectedOfferDate AS CHARACTER FORMAT 'yyyy-MM-dd');
+
+ SET outGenAttr.communicationCreationDate = '2017-09-27';
+ SET e_date = CAST(inRefDGC.ns31:EffectuationDate AS CHARACTER FORMAT 'yyyy-MM-dd');
+ SET outGenAttr.yearEffectiveDateDocument = SUBSTRING(e_date FROM 1 FOR 4);
+
+ SET outGenAttr.version = '1.0.0';
+ SET outGenAttr.businessLineClient = 'CMB';
+ SET outGenAttr.numberAanbiedingsbrief = '1';
+ SET outGenAttr.numberCreditAgreement = '2';
+ SET outGenAttr.numberBKR = '0';
+ SET outGenAttr.numberBegrippenlijsten = '1';
+
+
+ SET outGenAttr.numbAccountsOverview = '0';
+ SET outGenAttr.numbCreditTermsCommercial = '1';
+ SET outGenAttr.numbCreditTermsConsumer = '1';
+ --SET outGenAttr.numberPledgeLiveStock = '0';
+ -- SET outGenAttr.numberGuarantorAgreements = '2';
+ SET outGenAttr.numberGuarantorAgreements = '0';
+
+ SET outGenAttr.numbInfoBalancing = '0';
+
+ SET outGenAttr.numbClarification = '0';
+ ----------------
+
+ SET outGenAttr.numbToelichting = '0';
+ SET outGenAttr.numberBorrowers = '0';
+
+ SET outGenAttr.numberPledgers = '0';
+ SET outGenAttr.numberPledgersAkte = '0';
+ SET outGenAttr.numberPledgersWithAuction = '0';
+ SET outGenAttr.numberPledgersWithLivestock = '0';
+ SET outGenAttr.numberSaldoCompensatie = '1';
+
+ SET outGenAttr.selectorChapFinanRatio = '0';
+ SET outGenAttr.numberFacilities = '0';
+ SET outGenAttr.numberLoans = '0';
+ SET outGenAttr.numberMortgageRegisterations = '0';
+ SET outGenAttr.numberOtherCollaterals = '0';
+ SET outGenAttr.selectorBorrowerIsPledger = '0';
+
+
+
+
+ DECLARE count1, i, j, k INTEGER;
+
+
+ IF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '324' OR inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '175' OR inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '255' THEN
+ SET outGenAttr.numberPledgeAkte = '2';
+ ELSE
+ SET outGenAttr.numberPledgeAkte = '0';
+ END IF;
+
+
+
+
+
+ IF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '314' THEN
+ SET outGenAttr.numberPledgeAuction = '2';
+ ELSE
+ SET outGenAttr.numberPledgeAuction = '0';
+ END IF;
+
+
+ IF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '328' THEN
+ SET outGenAttr.numberPledgeLiveStock = '2';
+ ELSE
+ SET outGenAttr.numberPledgeLiveStock = '0';
+ END IF;
+ -- IF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '324' THEN
+ -- SET outGenAttr.numberPledgeAkte[1] = '2';
+ -- ELSE
+ -- SET outGenAttr.numberPledgeAkte[1] = '0';
+ -- END IF;
+ --
+ -- IF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '175' THEN
+ -- SET outGenAttr.numberPledgeAkte[2] = '2';
+ -- ELSE
+ -- SET outGenAttr.numberPledgeAkte[2] = '0';
+ -- END IF;
+ --
+ -- IF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '255' THEN
+ -- SET outGenAttr.numberPledgeAkte[3] = '2';
+ -- ELSE
+ -- SET outGenAttr.numberPledgeAkte[3] = '0';
+ -- END IF;
+ --
+ SET k = 1;
+ SET count1 = CARDINALITY(inRefDGC.ns31:BusinessAgreement.ns31:Facilities[]);
+
+ WHILE (k<=count1) DO
+
+ IF inRefDGC.ns31:BusinessAgreement.ns31:Facilities[k].ns31:Limit.ns31:LimitDefinitionIdentification.ns31:DefinitionCode = 'CompensatingBalanceLimit' THEN
+ SET outGenAttr.numberTermsSRC = NULL;
+ END IF;
+ IF count1>1 AND inRefDGC.ns31:BusinessAgreement.ns31:Facilities[k].ns31:Limit.ns31:LimitDefinitionIdentification.ns31:DefinitionCode = 'CompensatingBalanceLimit' THEN
+ SET outGenAttr.numberTermsSRC = '1';
+ ELSE
+ SET outGenAttr.numberTermsSRC = '0';
+ END IF;
+ SET k = k+1;
+ END WHILE;
+
+
+ SET outGenAttr.numberTerugboekformulier = '2';
+ SET outGenAttr.numberWijzAlgemeen = '0';
+
+ SET k = 1;
+ --SET count1 = CARDINALITY(inRefDGC.ns31:BusinessAgreement.ns31:Facilities[]);
+ WHILE (k<=count1) DO
+ IF inRefDGC.ns31:BusinessAgreement.ns31:Facilities[k].ns31:ProductLineDefinitionIdentification.ns31:DefinitionCode = '2' THEN
+
+ SET outGenAttr.numbProductinfoCommLoans = '1';
+ ELSE
+ SET outGenAttr.numbProductinfoCommLoans = '0';
+ END IF;
+ IF inRefDGC.ns31:BusinessAgreement.ns31:Facilities[k].ns31:ProductLineDefinitionIdentification.ns31:DefinitionCode = '158' OR inRefDGC.ns31:BusinessAgreement.ns31:Facilities[k].ns31:ProductLineDefinitionIdentification.ns31:DefinitionCode = '19' THEN
+
+ SET outGenAttr.numbProductinfoRC = '1';
+ ELSE
+ SET outGenAttr.numbProductinfoRC = '0';
+ END IF;
+ SET k = k+1;
+ END WHILE;
+
+ IF outGenAttr.numberPledgersAkte <> '0' THEN
+ SET outGenAttr.numbTermPledge = '1';
+ ELSE
+ SET outGenAttr.numbTermPledge = '0';
+ END IF;
+ --SET InputRoot.SOAP.Body.ns15:CreateDocumentRequest.DocumentGenerationContainer.FTB.ns31:BusinessAgreement.ns31:Facilities.ns31:ProductLineDefinitionIdentification
+ --REsponse which came from Retrieve party details will be mapped back
+ SET i = 1;
+ SET j = CARDINALITY(inRefDGC.ns31:Borrower.ns31:SelectedCounterpartyRoles[]);
+ WHILE (i<=j) DO
+
+ IF inRefDGC.ns31:Borrower.ns31:SelectedCounterpartyRoles[i].ns31:DefinitionCode = 'Hoofdaanvrager' THEN
+ SET outGenAttr.Involved_Parties.naamAdmKlant = Environment.variable.retrieveParty.partyAddressDetails.preferredPostalAddressContactPreference.renderedContactPreference.renderedName;
+ SET outGenAttr.Involved_Parties.naamContactpersoon = Environment.variable.retrieveParty.partyDetails.party.partyClassification.partyClassificationRelationshipClassificationId.value;
+ SET outGenAttr.Involved_Parties.straatAdmKlant = Environment.variable.retrieveParty.partyAddressDetails.preferredPostalAddressContactPreference.postalAddress.streetFullName;
+ SET outGenAttr.Involved_Parties.huisnrAdmKlant = Environment.variable.retrieveParty.partyAddressDetails.preferredPostalAddressContactPreference.postalAddress.fullHouseNumber;
+ SET outGenAttr.Involved_Parties.postcodeAdmKlant = Environment.variable.retrieveParty.partyAddressDetails.preferredPostalAddressContactPreference.postalAddress.postcodeArea;
+ SET outGenAttr.Involved_Parties.plaatsAdmKlant = Environment.variable.retrieveParty.partyAddressDetails.preferredPostalAddressContactPreference.postalAddress.cityName;
+ --SET outGenAttr.Involved_Parties.accMan = COALESCE(Environment.variable.retrieveParty.responsibleParties.responsibleParty.partyName.fullName, '');
+ SET outGenAttr.Involved_Parties.accMan = 'George';
+ SET outGenAttr.Involved_Parties.afdeling = COALESCE(Environment.variable.retrieveParty.partyAddressDetails.managingOrganizationUnit.fullName, '');
+ --SET outGenAttr.Involved_Parties.phoneAccMan = COALESCE(Environment.variable.retrieveParty.responsibleParties.responsibleParty.telephonicAddress.fullTelephoneNumber, '');
+ SET outGenAttr.Involved_Parties.phoneAccMan = '3214564569';
+ SET outGenAttr.Involved_Parties.geachteJaNee = 'J';
+ SET outGenAttr.Involved_Parties.salutationName = 'Default Salutation';
+ SET outGenAttr.numbGenTerms = Environment.variable.retrieveParty.partyDetails.party.partyRegistrationLifeCycleStatusTypeId.value;
+ END IF;
+ SET i = i+1;
+ END WHILE;
+ -----
+ IF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '402' THEN
+ SET outGenAttr.Involved_Parties.guarantors = inRefFTB;
+ ELSE
+ SET outGenAttr.Involved_Parties.guarantors = '';
+ END IF;
+ -- Ram
+ --SET outGenAttr.Involved_Parties.guarantors.nameGuarantor = Environment.variable.retrieveParty.partyDetails.preferredPostalAddressContactPreference.renderedContactPreference.renderedName;
+
+ SET outElecDoc.selectorSaldoCompensation = '1';
+ IF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '324' OR inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '255' OR inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '175' OR inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '314' OR inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '328' THEN
+ SET outElecDoc.selectReturnMoreDocs = '1';
+ ELSE
+ SET outElecDoc.selectReturnMoreDocs = '0';
+ END IF;
+ -- IF inRefFTB.ns31:Offergroup.ns31:DatePreviousSentOffer = NULL THEN
+ -- SET outElecDoc.datePreviousOffer = NULL;
+ -- ELSE
+ -- SET outElecDoc.datePreviousOffer = inRefFTB.ns31:Offergroup.ns31:DatePreviousSentOffer;
+ -- END IF;
+ SET outElecDoc.datePreviousOffer = '9999-12-31';
+ SET outElecDoc.selectorStatusCompensationAgreement = '0';
+
+ IF inRefFTB = 'Registry Property Cover Type' AND inRefDGC.ns31:ExecutionGroup.ns31:Notary <> NULL THEN
+ SET outElecDoc.selectorNewMortgageNotaryKnown = '0';
+ ELSE
+ SET outElecDoc.selectorNewMortgageNotaryKnown = '1';
+ END IF;
+
+ SET outElecDoc.numbLoanAgreementToReceive = '0';
+ SET outElecDoc.subordinations.selectSubordination = '0';
+ SET outElecDoc.subordinations.nameSubordinator = '0';
+ SET outElecDoc.subordinations.nameBorrowerSubordination = '0';
+ SET outGenAttr.numbSubordinations = '0';
+
+ IF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '324'THEN
+ SET outElecDoc.selectorPledgeCombo = '1';
+ ELSEIF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '175' THEN
+ SET outElecDoc.selectorPledgeCombo = '3';
+ ELSEIF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '255' THEN
+ SET outElecDoc.selectorPledgeCombo = '2';
+ ELSEIF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '324' AND inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '255' THEN
+ SET outElecDoc.selectorPledgeCombo = '4';
+ ELSEIF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '324' AND inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '175' THEN
+ SET outElecDoc.selectorPledgeCombo = '5';
+ ELSEIF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '255' AND inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '175' THEN
+ SET outElecDoc.selectorPledgeCombo = '6';
+ ELSEIF inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '324' AND inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '255' AND inRefFTB.ns31:CoverDefinitionIdentification.ns31:DefinitionCode = '175' THEN
+ SET outElecDoc.selectorPledgeCombo = '7';
+ ELSE
+ SET outElecDoc.selectorPledgeCombo = '0';
+ END IF;
+
+
+ SET outElecDoc.selectSRCOvk = '0';
+
+END;
+
+CREATE FUNCTION aaaa() RETURNS BOOLEAN
+BEGIN
+ RETURN TRUE;
+END;
+
+CREATE FUNCTION b() RETURNS BOOLEAN
+ RETURN TRUE;
+
+CREATE FUNCTION myProc1( IN P1 INTEGER, OUT P2 INTEGER, INOUT P3 INTEGER )
+ RETURNS INTEGER
+ LANGUAGE JAVA
+ EXTERNAL NAME "com.ibm.broker.test.MyClass.myMethod1";
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/InsertBlankLineBetweenFuncProc.esql b/esql-checks/src/test/resources/InsertBlankLineBetweenFuncProc.esql
new file mode 100644
index 00000000..bc87f170
--- /dev/null
+++ b/esql-checks/src/test/resources/InsertBlankLineBetweenFuncProc.esql
@@ -0,0 +1,12 @@
+CREATE COMPUTE MODULE Module1
+CREATE FUNCTION Main() RETURNS BOOLEAN --Noncompliant
+ BEGIN
+ DECLARE myInt INTEGER 1;
+ DECLARE myInt2 INTEGER;
+ END;
+CREATE Procedure Main2() RETURNS BOOLEAN --Noncompliant
+ BEGIN
+ DECLARE myInt INTEGER 1;
+ DECLARE myInt2 INTEGER;
+ END;
+ END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/KeyWordCaseCheck.esql b/esql-checks/src/test/resources/KeyWordCaseCheck.esql
new file mode 100644
index 00000000..ecbd7b03
--- /dev/null
+++ b/esql-checks/src/test/resources/KeyWordCaseCheck.esql
@@ -0,0 +1,33 @@
+BROKER SCHEMA country.common.esql.util --Compliant
+/****************************************************************************
+ * This module will CALL the procedures which will do the request
+ transformation for all operations in a given service.
+ *****************************************************************************/
+CREATE COMPUTE MODULE TestFlow_Compute
+ Create FUNCTION Badly_Named_Function() RETURNS BOOLEAN
+ BEGIN
+ END;
+
+ CREATE FUNCTION too_long_function_name_because_it_has_more_than_30_characters() RETURNS BOOLEAN
+ BEGIN -- begin is ok
+-- begin
+ END;
+ CREATE FUNCTION functionOk() RETURNS BOOLEAN
+ BEGIN
+ SET I = Badly_Named_Function();
+ SET OutputRoot.attach = 'AAA';
+ SET Environment.ABC = 'AAA';
+ DECLARE count INTEGER 0;
+ SET count = 15;
+ IF not condition THEN
+ END IF;
+ END;
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ CALL ABC(Environment);
+ RETURN TRUE;/*
+
+ comment ends here
+ */
+ end; --Noncompliant
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/MissingNewlineAtEndOfFileCheck/onlySchema.esql b/esql-checks/src/test/resources/MissingNewlineAtEndOfFileCheck/onlySchema.esql
new file mode 100644
index 00000000..bb07dda8
--- /dev/null
+++ b/esql-checks/src/test/resources/MissingNewlineAtEndOfFileCheck/onlySchema.esql
@@ -0,0 +1 @@
+BROKER SCHEMA A
diff --git a/esql-checks/src/test/resources/MissingNewlineAtEndOfFileCheck/onlySchemaPath.esql b/esql-checks/src/test/resources/MissingNewlineAtEndOfFileCheck/onlySchemaPath.esql
new file mode 100644
index 00000000..63ded024
--- /dev/null
+++ b/esql-checks/src/test/resources/MissingNewlineAtEndOfFileCheck/onlySchemaPath.esql
@@ -0,0 +1,2 @@
+BROKER SCHEMA A
+PATH B
diff --git a/esql-checks/src/test/resources/MissingNewlineAtEndOfFileCheck/onlySchemaPathSemi.esql b/esql-checks/src/test/resources/MissingNewlineAtEndOfFileCheck/onlySchemaPathSemi.esql
new file mode 100644
index 00000000..4ffeb5ea
--- /dev/null
+++ b/esql-checks/src/test/resources/MissingNewlineAtEndOfFileCheck/onlySchemaPathSemi.esql
@@ -0,0 +1,2 @@
+BROKER SCHEMA A
+PATH B;
diff --git a/esql-checks/src/test/resources/NavigatingTreeCouldBeReference.esql b/esql-checks/src/test/resources/NavigatingTreeCouldBeReference.esql
new file mode 100644
index 00000000..73a3e7a1
--- /dev/null
+++ b/esql-checks/src/test/resources/NavigatingTreeCouldBeReference.esql
@@ -0,0 +1,9 @@
+CREATE COMPUTE MODULE testModule
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.Response.details.person.age = '20';
+ SET OutputRoot.XMLNSC.Response.details.person.name = 'abc';
+ SET OutputRoot.XMLNSC.Response.details.person.lname = 'xyz';
+ SET OutputRoot.XMLNSC.Response.details.person.middlename = 'sdsd';
+ END;
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/PassthruStatementCheck.esql b/esql-checks/src/test/resources/PassthruStatementCheck.esql
new file mode 100644
index 00000000..c2134fd3
--- /dev/null
+++ b/esql-checks/src/test/resources/PassthruStatementCheck.esql
@@ -0,0 +1,22 @@
+CREATE COMPUTE MODULE a
+
+ CREATE PROCEDURE delete()
+ BEGIN
+ SET A = 'AAA';
+ PASSTHRU 'SELECT COUNT(*) FROM Database.SHAREHOLDINGS AS S WHERE S.ACCOUNTNO = InputBody.AccountNumber' TO Database.DSN1 VALUES (); --Noncompliant
+ PASSTHRU 'SELECT COUNT(*) FROM Database.SHAREHOLDINGS AS S WHERE S.ACCOUNTNO = ?' TO Database.DSN1 VALUES (InputBody.AccountNumber); --Compliant
+ PASSTHRU 'SELECT COUNT(*) FROM Database.SHAREHOLDINGS AS S ' TO Database.DSN1; --Compliant
+ PASSTHRU 'SELECT COUNT(*) FROM Database.SHAREHOLDINGS AS S WHERE S.ACCOUNTNO = ? GROUP BY S:ACCOUNTNO' TO Database.DSN1 VALUES (InputBody.AccountNumber); --Compliant
+ PASSTHRU 'SELECT COUNT(*) FROM Database.SHAREHOLDINGS AS S WHERE S.ACCOUNTNO = ? ORDER BY S:ACCOUNTNO' TO Database.DSN1 VALUES (InputBody.AccountNumber); --Compliant
+ PASSTHRU (STMT, param); --Compliant
+ PASSTHRU ('' || STMT, param); --Compliant
+
+ SET resultSet.rowReference[]= PASSTHRU('SELECT * FROM '||table||'.ABC A,'||table||'.BCD B,'||table|| --Noncompliant
+ '.CDE C WHERE A.IDENT = '||Ident||'
+ AND B.ID_NUMBER = '||inRef.xyz.value||'
+ AND B.ID_NUMBER = A.ID_NUMBER
+ AND C.IDENT = '||Ident||'
+ AND B.DATE_MODIFIED < C.DATE' TO Database.{DB});
+ END;
+
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/ProcessInvokingItself.esql b/esql-checks/src/test/resources/ProcessInvokingItself.esql
new file mode 100644
index 00000000..327863b5
--- /dev/null
+++ b/esql-checks/src/test/resources/ProcessInvokingItself.esql
@@ -0,0 +1,28 @@
+CREATE COMPUTE MODULE Module1
+CREATE FUNCTION Main() RETURNS BOOLEAN --Noncompliant
+ BEGIN
+ DECLARE myInt INTEGER 1;
+ DECLARE myInt2 INTEGER;
+ DECLARE xyz Boolean;
+ SET xyz = Main();
+
+ END;
+ CREATE PROCEDURE Main2() RETURNS BOOLEAN --Noncompliant
+ BEGIN
+ DECLARE myInt INTEGER 1;
+ DECLARE myInt2 INTEGER;
+ DECLARE abc Boolean;
+ SET abc = Main2();
+
+ END;
+ CREATE PROCEDURE Main3() RETURNS BOOLEAN --Noncompliant
+ BEGIN
+ DECLARE myInt INTEGER 1;
+ DECLARE myInt2 INTEGER;
+ DECLARE abc Boolean;
+ CALL Main3();
+
+ END;
+END MODULE;
+
+
diff --git a/esql-checks/src/test/resources/SelfAssignment.esql b/esql-checks/src/test/resources/SelfAssignment.esql
new file mode 100644
index 00000000..3680e48e
--- /dev/null
+++ b/esql-checks/src/test/resources/SelfAssignment.esql
@@ -0,0 +1,10 @@
+CREATE COMPUTE MODULE a
+
+ CREATE PROCEDURE set()
+ BEGIN
+ SET a = a; --Noncompliant
+ SET OutputRoot.a = OutputRoot.a; --Noncompliant
+ SET a = OutputRoot.a; --Compliant
+ END;
+
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/SubElementName.esql b/esql-checks/src/test/resources/SubElementName.esql
new file mode 100644
index 00000000..36305367
--- /dev/null
+++ b/esql-checks/src/test/resources/SubElementName.esql
@@ -0,0 +1,13 @@
+CREATE COMPUTE MODULE Module1
+
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET Environment.Variables.startVar.xyz ='ABC';
+ SET Environment.Variables.Flag ='ABC';
+ SET Environment.xyz ='true';
+ SET Environment.Fault.faultcode ='soapenv:Client';
+
+
+ END;
+
+END MODULE;
diff --git a/esql-checks/src/test/resources/UnusedVariable.esql b/esql-checks/src/test/resources/UnusedVariable.esql
new file mode 100644
index 00000000..42897db2
--- /dev/null
+++ b/esql-checks/src/test/resources/UnusedVariable.esql
@@ -0,0 +1,35 @@
+BROKER SCHEMA generic
+PATH serviceOperations;
+
+DECLARE ABC CONSTANT CHARACTER 'ABC';
+
+CrEATE COMPUTE MODULE responseTransformation
+ CReATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ DECLARE inRef REFERENCE TO InputRoot.SOAP.Body;
+ DECLARE outRef REFERENCE TO OutputRoot.SOAP.Body;
+ DECLARE envRef REFERENCE TO Environment.LogData.serviceOperationName;
+ CASE
+ WHEN abf = 'createAccessFacilityAgreement' THEN
+ DECLARE inRef REFERENCE TO InputLocalEnvironment.DFDL.BROKERMESSAGEFROMBB;
+ CALL createAccessFacilityAgreement_response(inRef,outRef,Environment);
+ WHEN abf = 'updateAccessFacilityAgreement' THEN
+ DECLARE inRef REFERENCE TO InputLocalEnvironment.DFDL.BROKERMESSAGEFROMBB;
+ CALL updateAccessFacilityAgreement_response(inRef,outRef,Environment);
+ END CASE;
+ RETURN TRUE;
+ END;
+
+ CREATE FUNCTION A() RETURNS BOOLEAN
+ BEGIN
+ DECLARE refEnv REFERENCE TO Environment.LogData;
+ SET refEnv.serviceOperationName = InputRoot.SOAP.Context.operation;
+ SET refEnv.operationId = EVAL(Environment.LogData.serviceOperationName);
+ END;
+
+ CREATE PROCEDURE B()
+ BEGIN
+ DECLARE inputRef REFERENCE TO InputRoot;
+ DECLARE inReturn REFERENCE TO inputRef.a;
+ END;
+END MOdULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/bitstream.esql b/esql-checks/src/test/resources/bitstream.esql
deleted file mode 100644
index 10d22a4f..00000000
--- a/esql-checks/src/test/resources/bitstream.esql
+++ /dev/null
@@ -1,9 +0,0 @@
-CREATE COMPUTE MODULE a
-
- CREATE PROCEDURE test()
- BEGIN
- DECLARE returnValue BOOLEAN; --Compliant
- SET returnValue = BITSTREAM('SLEEP(1000)'); --Noncompliant {{Do not use BITSTREAM it is deprecated.}}
- END;
-
-END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/cardinalityInLoopTest.esql b/esql-checks/src/test/resources/cardinalityInLoopTest.esql
index 7978c64a..2b405e50 100644
--- a/esql-checks/src/test/resources/cardinalityInLoopTest.esql
+++ b/esql-checks/src/test/resources/cardinalityInLoopTest.esql
@@ -28,7 +28,11 @@ CREATE COMPUTE MODULE CardinalityInLoop
WHILE LASTMOVE(bc) DO
SET a = CAST(b AS CHARACTER);
END WHILE;
-
+ WHILE l <= aCount DO
+ WHILE m <= eCount DO
+ DECLARE aCount1 INTEGER CARDINALITY(inRef.entity[m].association[]);
+ END WHILE;
+ END WHILE;
diff --git a/esql-checks/src/test/resources/commentedCode.esql b/esql-checks/src/test/resources/commentedCode.esql
new file mode 100644
index 00000000..dbaf598e
--- /dev/null
+++ b/esql-checks/src/test/resources/commentedCode.esql
@@ -0,0 +1,36 @@
+CREATE COMPUTE MODULE ProcessCardAccount
+
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ -- SET OutputRoot=InputRoot;
+ DECLARE end BOOLEAN TRUE;
+ IF FALSE THEN --Non compliant
+ SET OutputRoot=InputRoot;
+ --ELSE
+ -- SET OutputRoot=InputRoot;
+ END IF;
+ IF FALSE THEN --Non compliant
+ SET OutputRoot=InputRoot;
+ --ELSEIF TRUE THEN
+ -- SET OutputRoot=InputRoot;
+ END IF;
+
+ -- Move RetryCountDown to environment
+ CASE size
+ WHEN minimum + 0 THEN
+ SET description = 'small';
+ --WHEN minimum + 0 THEN
+ -- SET description = 'medium';
+ ELSE
+ SET description = 'unknown';
+ CALL handleError();
+ END CASE;
+
+ END;
+
+
+ --END;
+
+
+
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/comments.esql b/esql-checks/src/test/resources/comments.esql
new file mode 100644
index 00000000..85cef437
--- /dev/null
+++ b/esql-checks/src/test/resources/comments.esql
@@ -0,0 +1,48 @@
+BROKER SCHEMA serviceOperations
+DECLARE soapenv NAMESPACE 'http://schemas.xmlsoap.org/soap/envelope/';
+DECLARE ns NAMESPACE 'http://com/abnamro/Services/AccessFacilityAgreement/v2/' ;
+CREATE PROCEDURE createAccessFacilityAgreement_request(IN inRef REFERENCE, IN outRef REFERENCE)
+BEGIN
+-- Single Line Comment
+ SET outRef.Properties.MessageSet='A0071546_input.xsd';
+ SET outRef.Properties.MessageType='BROKERMESSAGETOBB';
+ SET outRef.Properties.CodedCharSetId = 500;
+ SET outRef.Properties.Encoding = 785;
+ /* Block Comment
+ please check
+ it.*/
+ DECLARE inputRef REFERENCE TO inRef.Body.ns:createAccessFacilityAgreement.requestParameters;
+ CREATE LASTCHILD OF outRef DOMAIN 'DFDL';
+ CREATE FIELD outRef.DFDL.BROKERMESSAGETOBB;
+ DECLARE outputRef REFERENCE TO outRef.DFDL.BROKERMESSAGETOBB;
+ SET outputRef.LL_VELD = '32154';
+ SET outputRef.ZZ_VELD = +0;
+ IF inputRef.classificationValueId = '1' THEN
+ SET outputRef.IMS_TRANSAKT_KODE ='MU360T01';
+ ELSEIF inputRef.classificationValueId = '0' THEN
+ SET outputRef.IMS_TRANSAKT_KODE ='MU326T01';
+ ELSEIF inputRef.classificationValueId = TRUE THEN
+ SET outputRef.IMS_TRANSAKT_KODE ='MU360T01';
+ ELSEIF inputRef.classificationValueId = FALSE THEN
+ SET outputRef.IMS_TRANSAKT_KODE ='MU326T01';
+ END IF;
+ SET outputRef.SERVICE_INPUT_GROUP.BS_USERID = '';
+ SET outputRef.SERVICE_INPUT_GROUP.BS_PROCESS_ID = '';
+ SET outputRef.SERVICE_INPUT_GROUP.BS_CHANNEL_ID = '';
+ SET outputRef.SERVICE_INPUT_GROUP.BS_APPLICATION_ID = '';
+ SET outputRef.SERVICE_INPUT_GROUP.BS_SESSION_ID = '';
+ SET outputRef.SERVICE_INPUT_GROUP.BS_LANGUAGE_CODE = '';
+ SET outputRef.SERVICE_INPUT_GROUP.BS_LANGUAGE_COUNTRY_CODE = '';
+ SET outputRef.SERVICE_INPUT_GROUP.BS_ISSUE_ID = '';
+ SET outputRef.SERVICE_INPUT_GROUP.BS_VIEW.BS_VIEW_NR = 0;
+ SET outputRef.SERVICE_INPUT_GROUP.BS_MPP_BMP = '';
+ SET outputRef.SERVICE_INPUT_GROUP.BS_RESERVED = '';
+ SET outputRef.BROKER_VERSIE_BERICHT_NAAR_BB = '';
+ SET outputRef.MO_BROKER_SUPPLIER_ID = '';
+ SET outputRef.MO_SERVICE_CALL_ID = '';
+ SET outputRef.MO_BROKER_PROCESS_ID ='';
+ SET outputRef.BROKER_DESTINATION_TRANSACTIE ='';
+ DECLARE bcno CHARACTER;
+ DECLARE modid CHARACTER;
+ DECLARE verid CHARACTER;
+END;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/conditionBraces.esql b/esql-checks/src/test/resources/conditionBraces.esql
new file mode 100644
index 00000000..fd18f60a
--- /dev/null
+++ b/esql-checks/src/test/resources/conditionBraces.esql
@@ -0,0 +1,31 @@
+CREATE COMPUTE MODULE responseTransformation
+CREATE FUNCTION main() RETURNS BOOLEAN
+BEGIN
+If oprName = 'createAccessFacilityAgreement' OR refIpSrvcOpName = '"http://com/abnamro/Services/AccessFacilityAgreement/v2/AccessFacilityAgreement/IAccessFacilityAgreementPort"' THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ DECLARE faultRef REFERENCE TO OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ SET faultRef.ExceptionElement.description = messageTextDetail;
+ELSEIF oprName = 'updateAccessFacilityAgreement' OR refIpSrvcOpName = '"http://com/abnamro/Services/AccessFacilityAgreement/v2/AccessFacilityAgreement/IAccessFacilityAgreementPort"' THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:updateAccessFacilityAgreementException;
+ DECLARE faultRef REFERENCE TO OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:updateAccessFacilityAgreementException;
+ SET faultRef.ExceptionElement.description = messageTextDetail;
+END IF;
+WHILE count <= providerCount DO
+ SET faultRef.ExceptionElement.description = messageTextDetail;
+END WHILE;
+/*If oprName = 'createAccessFacilityAgreement' OR refIpSrvcOpName = '"http://com/abnamro/Services/AccessFacilityAgreement/v2/AccessFacilityAgreement/IAccessFacilityAgreementPort"' THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ DECLARE faultRef REFERENCE TO OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ELSEIF oprName = 'updateAccessFacilityAgreement' OR refIpSrvcOpName = '"http://com/abnamro/Services/AccessFacilityAgreement/v2/AccessFacilityAgreement/IAccessFacilityAgreementPort"' THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:updateAccessFacilityAgreementException;
+ DECLARE faultRef REFERENCE TO OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:updateAccessFacilityAgreementException;
+ SET faultRef.ExceptionElement.description = messageTextDetail;
+END IF;*/
+If oprName = 'createAccessFacilityAgreement' OR refIpSrvcOpName = '"http://com/abnamro/Services/AccessFacilityAgreement/v2/AccessFacilityAgreement/IAccessFacilityAgreementPort"' THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+--ELSEIF oprName = 'updateAccessFacilityAgreement' OR refIpSrvcOpName = '"http://com/abnamro/Services/AccessFacilityAgreement/v2/AccessFacilityAgreement/IAccessFacilityAgreementPort"' THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:updateAccessFacilityAgreementException;
+ DECLARE faultRef REFERENCE TO OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:updateAccessFacilityAgreementException;
+END IF;
+END;
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/declareCombine.esql b/esql-checks/src/test/resources/declareCombine.esql
new file mode 100644
index 00000000..e5e0ab14
--- /dev/null
+++ b/esql-checks/src/test/resources/declareCombine.esql
@@ -0,0 +1,65 @@
+BROKER SCHEMA generic
+CREATE COMPUTE MODULE initialize
+CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ DECLARE fa EXTERNAL CHARACTER;
+ DECLARE frf1 EXTERNAL CHARACTER; --Noncompliant
+ DECLARE faultE EXTERNAL CHAR;
+ DECLARE fauE EXTERNAL CHAR;--Noncompliant
+ DECLARE faultI EXTERNAL INT;
+ DECLARE faI EXTERNAL INT;--Noncompliant
+ DECLARE faultEI EXTERNAL INTEGER;
+ DECLARE fauEI EXTERNAL INTEGER;--Noncompliant
+ DECLARE fa1 CONSTANT CHARACTER;
+ DECLARE frf2 CONSTANT CHARACTER; --Noncompliant
+ DECLARE faultE3 CONSTANT CHAR;
+ DECLARE fauE4 CONSTANT CHAR;--Noncompliant
+ DECLARE faultI5 CONSTANT INT;
+ DECLARE faI6 CONSTANT INT;--Noncompliant
+ DECLARE faultEI7 CONSTANT INTEGER;
+ DECLARE fauEI8 CONSTANT INTEGER;--Noncompliant
+ DECLARE soapenviro GMTTIMESTAMP;
+ DECLARE soapversion REFERENCE TO;
+ DECLARE faultReferen TIMESTAMP;
+ DECLARE soapenvir GMTTIMESTAMP;--Noncompliant
+ DECLARE soapenviron GMTTIME;
+ DECLARE faultRefere TIME;
+ DECLARE soapenvi GMTTIME;--Noncompliant
+ DECLARE soapver REFERENCE TO;--Noncompliant
+ DECLARE faultRf TIME;--Noncompliant
+ DECLARE faultRef TIMESTAMP;--Noncompliant
+ DECLARE providerCo INTEGER;
+ DECLARE providerCo INTEGER;--Noncompliant
+ DECLARE providerC BOOLEAN;
+ DECLARE providerCb BOOLEAN;--Noncompliant
+ DECLARE providerCF FLOAT;
+ DECLARE provider FLOAT;--Noncompliant
+ DECLARE providerCoun DATE;
+ DECLARE provid DATE;--Noncompliant
+ DECLARE soapenviroc CHAR;
+ DECLARE soapenvioc CHAR;--Noncompliant
+ DECLARE soapenvirb BLOB;
+ DECLARE s BLOB;--Noncompliant
+ DECLARE sb BIT;
+ DECLARE sv BIT;--Noncompliant
+ DECLARE faultF ROW;
+ DECLARE faultRfe ROW;--Noncompliant
+ DECLARE prov DECIMAL;
+ DECLARE prove DECIMAL;--Noncompliant
+ DECLARE provn NAMESPACE;
+ DECLARE proven NAMESPACE;--Noncompliant
+ DECLARE provN NAME;
+ DECLARE proveN NAME;--Noncompliant
+ RETURN TRUE;
+ END;
+ DECLARE myShared SHARED ROW;
+ DECLARE myShareS SHARED ROW; --Noncompliant [[secondary=+1]]
+ DECLARE myShareS2 SHARED ROW;
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ DECLARE fa EXTERNAL CHARACTER;
+ END;
+END MODULE;
+
+
+
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/deleteFrom.esql b/esql-checks/src/test/resources/deleteFrom.esql
index 5b694119..d06cf673 100644
--- a/esql-checks/src/test/resources/deleteFrom.esql
+++ b/esql-checks/src/test/resources/deleteFrom.esql
@@ -5,6 +5,18 @@ CREATE COMPUTE MODULE a
DELETE FROM Database.SHAREHOLDINGS; --Noncompliant
DELETE FROM Database.SHAREHOLDINGS AS S; --Noncompliant
DELETE FROM Database.SHAREHOLDINGS AS S WHERE S.ACCOUNTNO = InputBody.AccountNumber; --Compliant
+ PASSTHRU('DELETE FROM users'); --Noncompliant
+ PASSTHRU 'DELETE FROM users'; --Noncompliant
+ PASSTHRU(('DELETE FROM users')); --Noncompliant
+ PASSTHRU(('DELETE FROM users WHERE NAME=''name''')); --Compliant
+ PASSTHRU(STMT); --Compliant
+ PASSTHRU('SELECT * FROM dual'); --Compliant
+ PASSTHRU loadStatement(); --Compliant
+ PASSTHRU (); --Compliant
+ SET resultSet.rowReference[] = PASSTHRU('DELETE FROM ABC A' TO Database.{dsDB}); --Noncompliant
+ SET resultSet.rowReference[] = PASSTHRU('DELETE FROM '||db2_table||'.ABC A' TO Database.{dsDB}); --Noncompliant
+ PASSTHRU('DELETE FROM '||THE(PASSTHRU('SELECT MAX(tblName) from tbls WHERE empty=1'))); --Noncompliant
+ PASSTHRU('DELETE FROM '||THE(PASSTHRU('SELECT MAX(tblName) from tbls WHERE empty=1'))|| ' where a=2'); --Compliant
END;
END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/emptyBlock.esql b/esql-checks/src/test/resources/emptyBlock.esql
new file mode 100644
index 00000000..53f06082
--- /dev/null
+++ b/esql-checks/src/test/resources/emptyBlock.esql
@@ -0,0 +1,63 @@
+CREATE COMPUTE MODULE ProcessCardAccount
+
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ DECLARE end BOOLEAN TRUE;
+ IF FALSE THEN
+ IF FALSE THEN
+ IF FALSE THEN
+ IF FALSE THEN
+ SET OutputRoot=InputRoot;
+ END IF;
+ ELSEIF A = B THEN
+ IF TRUE THEN
+ SET OutputRoot=InputRoot;
+ END IF;
+ ELSEIF A = B THEN
+ ELSEIF FALSE THEN
+ ELSEIF end THEN
+ END IF;
+ END IF;
+ ELSE
+ END IF;
+ IF FALSE THEN
+ ELSEIF A = B THEN
+ ELSE
+ END IF;
+ FOR source AS Environment.SourceData.Folder[] DO END FOR;
+ FOR source AS Environment.SourceData.Folder[] DO
+ --empty is ok
+ END FOR;
+ LOOP
+
+ END LOOP;
+ REPEAT
+ UNTIL i>= 3 END REPEAT;
+ CASE
+ WHEN versionRef>= 1 THEN
+ SET Environment.Fault.faultcode='soapenv:Client';
+ WHEN versionRef<1.2 THEN
+ SET Environment.Fault.faultcode='soapenv:Sender';
+ END CASE;
+ CASE
+ WHEN versionRef>= 1 THEN
+ SET Environment.Fault.faultcode='soapenv:Client';
+ ELSE
+ SET Environment.Fault.faultcode='soapenv:Sender';
+ END CASE;
+ WHILE ( I < CARDINALITY (InputRoot.MRM.A.B.C[])) DO
+ SET I = I + 1;
+
+ END WHILE;
+ END;
+
+ CREATE FUNCTION Main2() RETURNS BOOLEAN
+ BEGIN
+ END;
+
+ CREATE FUNCTION Main3() RETURNS BOOLEAN
+ BEGIN
+ --Empty blocks with comments are ok.
+ END;
+
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/emptyMainFunction.esql b/esql-checks/src/test/resources/emptyMainFunction.esql
index cddf73c1..58fd7edb 100644
--- a/esql-checks/src/test/resources/emptyMainFunction.esql
+++ b/esql-checks/src/test/resources/emptyMainFunction.esql
@@ -16,3 +16,35 @@ CREATE COMPUTE MODULE b
END MODULE;
+CREATE COMPUTE MODULE c
+
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ RETURN A<2;
+
+ CREATE FUNCTION test() RETURNS BOOLEAN
+ BEGIN
+ END;
+
+END MODULE;
+
+CREATE COMPUTE MODULE d
+
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ SET a = 'a';
+ END;
+
+END MODULE;
+
+
+CREATE COMPUTE MODULE e
+
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ RETURN TRUE;
+ SET a = 'a';
+ END;
+
+END MODULE;
+
+
diff --git a/esql-checks/src/test/resources/functionParameter.esql b/esql-checks/src/test/resources/functionParameter.esql
new file mode 100644
index 00000000..c425f8b5
--- /dev/null
+++ b/esql-checks/src/test/resources/functionParameter.esql
@@ -0,0 +1,18 @@
+CREATE COMPUTE MODULE TestFlow_Compute
+ CREATE FUNCTION TempFunction(IN Environment REFERENCE,IN EventCode CHARACTER,IN ReplaceValue CHARACTER,
+ IN RecipientTo CHARACTER,IN Retries INTEGER,IN Name CHARACTER,IN SurName CHARACTER,IN Param1 INTEGER,
+ OUT Param2 CHARACTER, OUT Param3 CHARACTER, OUT Param4 CHARACTER) RETURNS BOOLEAN
+ BEGIN
+ END;
+ CREATE FUNCTION too_long_function_name_because_it_has_more_than_30_characters() RETURNS BOOLEAN
+ BEGIN
+ END;
+ CREATE FUNCTION functionOk() RETURNS BOOLEAN
+ BEGIN
+ SET I = Badly_Named_Function();
+ END;
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ RETURN TRUE;
+ END;
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/hardCodedCredentials.esql b/esql-checks/src/test/resources/hardCodedCredentials.esql
index 5d4155fb..541953c4 100644
--- a/esql-checks/src/test/resources/hardCodedCredentials.esql
+++ b/esql-checks/src/test/resources/hardCodedCredentials.esql
@@ -2,6 +2,10 @@ CREATE COMPUTE MODULE hardCodedCredentials
DECLARE password EXTERNAL CHAR 'defaultPwd'; --Compliant
DECLARE password2 CHAR 'myPwd'; --Noncompliant
+ DECLARE password3 CHAR ''; --Compliant
+ DECLARE password4 SHARED CHAR 'defaultPwd'; --Noncompliant
+ DECLARE text CHAR load(); --Compliant
+ DECLARE text2 CHAR 'secret'; --Compliant
CREATE PROCEDURE declareTest()
BEGIN
@@ -17,9 +21,13 @@ CREATE COMPUTE MODULE hardCodedCredentials
SET variableWithPwdInIt = 'abc'; --Noncompliant
SET varKennwort = 'geheim'; --Noncompliant
SET OutputRoot.abc.password = 'aaa'; --Noncompliant
+ SET OutputRoot.abc:*[].password = 'aaa'; --Noncompliant
SET OutputRoot.abc.password = ''; --Compliant
SET myPassword = loadPassword(); --Compliant
- SET abc='abc';
+ SET abc='abc'; --Compliant
+ SET abc.a.a.a='abc'; --Compliant
+ SET abc.a:*='abc'; --Compliant
+ SET abc.a:*[]='abc'; --Compliant
END;
CREATE PROCEDURE urlTest()
diff --git a/esql-checks/src/test/resources/leaveIterate.esql b/esql-checks/src/test/resources/leaveIterate.esql
index 9d84b90d..663e0228 100644
--- a/esql-checks/src/test/resources/leaveIterate.esql
+++ b/esql-checks/src/test/resources/leaveIterate.esql
@@ -17,7 +17,7 @@ CREATE COMPUTE MODULE ProcessCardAccount
ITERATE X;
END IF;
- -- Einige Anweisungen 2
+ -- Some statements 2
UNTIL
i >= 4
@@ -35,11 +35,32 @@ CREATE COMPUTE MODULE ProcessCardAccount
LEAVE X;
END IF;
- -- Einige Anweisungen 2
+ -- Some statements 2
UNTIL
i >= 4
END REPEAT X;
END;
+ CREATE PROCEDURE Main2()
+ B: BEGIN
+ DECLARE i INTEGER;
+ SET i = 1;
+ X : WHILE i <= 3 DO
+
+ SET i = i + 1;
+ LEAVE X;
+ END WHILE X;
+
+ SET i = 1;
+ Y : LOOP
+ IF i>= 4 THEN
+ LEAVE Y;
+ END IF;
+ SET i = i + 1;
+ END LOOP Y;
+
+
+ END B;
+
END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/oneStatementPerLine.esql b/esql-checks/src/test/resources/oneStatementPerLine.esql
index aa134acf..b99fa5f5 100644
--- a/esql-checks/src/test/resources/oneStatementPerLine.esql
+++ b/esql-checks/src/test/resources/oneStatementPerLine.esql
@@ -1,9 +1,28 @@
+BROKER SCHEMA A;
CREATE COMPUTE MODULE testModule
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
SET OutputRoot=InputRoot; SET OutputRoot=InputRoot;
SET OutputRoot=InputRoot; SET OutputRoot=InputRoot; SET OutputRoot=InputRoot;
+ IF oprName = 'createAccessFacilityAgreement' OR refIpSrvcOpName = '"http://com/abnamro/Services/AccessFacilityAgreement/v2/AccessFacilityAgreement/IAccessFacilityAgreementPort"' THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException; DECLARE faultRef REFERENCE TO OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ SET faultRef.ExceptionElement.description = messageTextDetail;
+ ELSEIF oprName = 'updateAccessFacilityAgreement' OR refIpSrvcOpName = '"http://com/abnamro/Services/AccessFacilityAgreement/v2/AccessFacilityAgreement/IAccessFacilityAgreementPort"' THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:updateAccessFacilityAgreementException; DECLARE faultRef REFERENCE TO OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:updateAccessFacilityAgreementException;
+ SET faultRef.ExceptionElement.description = messageTextDetail;
+ END IF;
+
+ END;
+
+ CREATE FUNCTION Main() RETURNS BOOLEAN BEGIN
+
+ DECLARE EXIT HANDLER FOR SQLSTATE VALUE 'U11222' BEGIN
+ SET OutputRoot.XMLNSC.Top.WHILE.mySQLCODE = SQLCODE;
+ END;
+
+ THROW USER EXCEPTION VALUES( -1, 'U11222', 42, 'error text' );
+
END;
END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/procedureParameter.esql b/esql-checks/src/test/resources/procedureParameter.esql
new file mode 100644
index 00000000..d3605914
--- /dev/null
+++ b/esql-checks/src/test/resources/procedureParameter.esql
@@ -0,0 +1,18 @@
+CREATE COMPUTE MODULE TestFlow_Compute
+ CREATE PROCEDURE ProcedureWithTooManyParams(IN Environment REFERENCE,IN EventCode CHARACTER,IN ReplaceValue CHARACTER,
+ IN RecipientTo CHARACTER,IN Retries INTEGER,IN Name CHARACTER,IN SurName CHARACTER,IN Param1 INTEGER,
+ OUT Param2 CHARACTER, OUT Param3 CHARACTER, OUT Param4 CHARACTER)
+ BEGIN
+ END;
+ CREATE FUNCTION too_long_function_name_because_it_has_more_than_30_characters() RETURNS BOOLEAN
+ BEGIN
+ END;
+ CREATE FUNCTION functionOk() RETURNS BOOLEAN
+ BEGIN
+ SET I = Badly_Named_Function();
+ END;
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ RETURN TRUE;
+ END;
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/propagateToLabel.esql b/esql-checks/src/test/resources/propagateToLabel.esql
index 8087758b..4fd342e9 100644
--- a/esql-checks/src/test/resources/propagateToLabel.esql
+++ b/esql-checks/src/test/resources/propagateToLabel.esql
@@ -3,5 +3,6 @@ CREATE COMPUTE MODULE TestFlow_Compute
BEGIN
PROPAGATE TO LABEL 'ABC';
PROPAGATE TO TERMINAL 1;
+ PROPAGATE;
END;
END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/routineComments.esql b/esql-checks/src/test/resources/routineComments.esql
new file mode 100644
index 00000000..3a575c94
--- /dev/null
+++ b/esql-checks/src/test/resources/routineComments.esql
@@ -0,0 +1,74 @@
+CREATE COMPUTE MODULE Module1
+
+ CREATE FUNCTION Main() RETURNS BOOLEAN --Noncompliant
+ BEGIN
+ DECLARE myInt INTEGER 1;
+ DECLARE myInt2 INTEGER;
+
+ END;
+
+ --This comment is irrelevant.
+ /*
+ *
+ *
+ */
+ CREATE FUNCTION Main2() RETURNS BOOLEAN --Noncompliant
+ BEGIN
+ DECLARE myInt INTEGER 1;
+ DECLARE myInt2 INTEGER;
+
+ END;
+
+ /*
+ * Function description goes here.
+ * Parameters:
+ * IN: REFERENCE parameter1 - Description goes here.
+ * INOUT: INTEGER parameter2 - Description goes here.
+ * OUT: TIMESTAMP result - Description goes here.
+ * RETURNS: BOOLEAN Description goes here.
+ *
+ */
+ CREATE FUNCTION Main3() RETURNS BOOLEAN --Compliant
+ BEGIN
+ DECLARE myInt INTEGER 1;
+ DECLARE myInt2 INTEGER;
+
+ END;
+
+ /*
+ * Function description goes here.
+ * But not the right syntax
+ */
+ CREATE FUNCTION Main4() RETURNS BOOLEAN --Noncompliant
+ BEGIN
+ DECLARE myInt INTEGER 1;
+ DECLARE myInt2 INTEGER;
+
+ END;
+
+
+
+
+
+END MODULE;
+
+CREATE COMPUTE MODULE Module1
+
+ CREATE PROCEDURE ABC() --Noncompliant
+ BEGIN
+ SET OutputRoot.XMLNSC.A.B='ABC';
+ END;
+
+
+ /*
+ * This comment explains the functionality of this procedure.
+ */
+ CREATE PROCEDURE ABC() --Compliant
+ BEGIN
+ SET OutputRoot.XMLNSC.A.B='ABC';
+ END;
+
+
+END MODULE;
+
+
diff --git a/esql-checks/src/test/resources/selectAll.esql b/esql-checks/src/test/resources/selectAll.esql
index e07ff931..8df2094a 100644
--- a/esql-checks/src/test/resources/selectAll.esql
+++ b/esql-checks/src/test/resources/selectAll.esql
@@ -7,6 +7,18 @@ CREATE COMPUTE MODULE a
SET a = SELECT COUNT(*) FROM Database.SHAREHOLDINGS AS S WHERE S.ACCOUNTNO = InputBody.AccountNumber; --Compliant
SET a = SELECT A FROM Database.SHAREHOLDINGS; --Compliant
SET a = SELECT S.A FROM Database.SHAREHOLDINGS AS S; --Compliant
+ SET a = PASSTHRU('SELECT * FROM DUAL'); --Noncompliant
+ SET a = PASSTHRU('SELECT A FROM B'); --Compliant
+ SET a = PASSTHRU('DROP SCHEMA ABC'); --Compliant
+ SET a = PASSTHRU(loadSQL()); --Compliant
+ SET resultSet.rowReference[] = PASSTHRU('SELECT * FROM '||schema||'.table1 A,' --Noncompliant
+ ||schema||'.table2 B,'
+ ||schema||'.table3 C
+ WHERE A.ID = '''||value1||'''
+ AND B.b_NUMBER = '||tree.some.value2||'
+ AND B.b_NUMBER = A.b_NUMBER
+ AND C.ID = '''||value1||'''
+ AND B.a_DATE < C.a_DATE' TO Database.{xyz});
END;
END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/testmanagement_App_v2/.project b/esql-checks/src/test/resources/testmanagement_App_v2/.project
new file mode 100644
index 00000000..d54a2237
--- /dev/null
+++ b/esql-checks/src/test/resources/testmanagement_App_v2/.project
@@ -0,0 +1 @@
+this file just needs to exist
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/testmanagement_App_v2/MF_ST.msgflow b/esql-checks/src/test/resources/testmanagement_App_v2/MF_ST.msgflow
new file mode 100644
index 00000000..c91d9664
--- /dev/null
+++ b/esql-checks/src/test/resources/testmanagement_App_v2/MF_ST.msgflow
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/esql-checks/src/test/resources/testmanagement_App_v2/transform/Compute.esql b/esql-checks/src/test/resources/testmanagement_App_v2/transform/Compute.esql
new file mode 100644
index 00000000..8fdde424
--- /dev/null
+++ b/esql-checks/src/test/resources/testmanagement_App_v2/transform/Compute.esql
@@ -0,0 +1,24 @@
+BROKER SCHEMA transform
+
+CREATE COMPUTE MODULE Compute
+ CREATE FUNCTION Main() RETURNS BOOLEAN
+ BEGIN
+ CALL CopyMessageHeaders();
+ CALL CopyEntireMessage();
+ PROPAGATE DELETE NONE; --Compliant
+ RETURN TRUE; --Compliant
+ END;
+
+ CREATE PROCEDURE CopyMessageHeaders() BEGIN
+ PROPAGATE TO TERMINAL 'out1' DELETE NONE; --Noncompliant
+ PROPAGATE TO TERMINAL 'out2' DELETE NONE; --Noncompliant
+ PROPAGATE TO LABEL 'out2' DELETE NONE; --Compliant
+ END;
+
+ CREATE PROCEDURE CopyEntireMessage() BEGIN
+ PROPAGATE TO TERMINAL 0 DELETE NONE; --Compliant
+ PROPAGATE TO TERMINAL 3 DELETE NONE; --Noncompliant
+ PROPAGATE TO TERMINAL -1 DELETE NONE; --Noncompliant
+ PROPAGATE TO TERMINAL loadTerminal() DELETE NONE; --Compliant
+ END;
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/trailingComments.esql b/esql-checks/src/test/resources/trailingComments.esql
new file mode 100644
index 00000000..3a5df724
--- /dev/null
+++ b/esql-checks/src/test/resources/trailingComments.esql
@@ -0,0 +1,19 @@
+CREATE COMPUTE MODULE responseTransformation
+CREATE FUNCTION main() RETURNS BOOLEAN
+BEGIN
+---------Begin comment---------
+/*---------Begin block comment---------*/
+IF oprName = 'createAccessFacilityAgreement' OR refIpSrvcOpName = '"http://com/abnamro/Services/AccessFacilityAgreement/v2/AccessFacilityAgreement/IAccessFacilityAgreementPort"' THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException; -- Create field statement.
+ DECLARE faultRef REFERENCE TO OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:createAccessFacilityAgreementException;
+ SET faultRef.ExceptionElement.description = messageTextDetail;
+ELSEIF oprName = 'updateAccessFacilityAgreement' OR refIpSrvcOpName = '"http://com/abnamro/Services/AccessFacilityAgreement/v2/AccessFacilityAgreement/IAccessFacilityAgreementPort"' THEN
+ CREATE FIELD OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:updateAccessFacilityAgreementException;
+ DECLARE faultRef REFERENCE TO OutputRoot.SOAP.Body.soapenv:Fault.detail.ns:updateAccessFacilityAgreementException; -- Declare statement trailing comment.
+ SET faultRef.ExceptionElement.description = messageTextDetail;
+END IF; --NOSONAR
+WHILE count <= providerCount DO--while statement.
+ SET faultRef.ExceptionElement.description = messageTextDetail; -- Set statement.
+END WHILE;
+END;
+END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/unknownMessageDomain.esql b/esql-checks/src/test/resources/unknownMessageDomain.esql
index cf57c003..8871667b 100644
--- a/esql-checks/src/test/resources/unknownMessageDomain.esql
+++ b/esql-checks/src/test/resources/unknownMessageDomain.esql
@@ -7,9 +7,15 @@ CREATE COMPUTE MODULE TestFlow_Compute
SET OutputRoot.XMLNS.test='a'; -- Compliant
SET OutputRoot.MQRFH2.test='a'; -- Compliant
SET OutputRoot.a.test='a'; -- Noncompliant
+ SET OutputRoot=InputRoot; -- Compliant
+ SET OutputRoot.[].a='a'; -- Compliant
+ SET Environment.a.b='a'; --Compliant
+ SET OutputRoot.*='a'; --Compliant
DECLARE refColl REFERENCE TO InputRoot.Collection.[>]; --Compliant
SET OutputRoot.HTTPReplyHeader."Content-Type"=contentType; --Compliant
CREATE FIELD OutputRoot.MQPCF; --Compliant
+ CREATE LASTCHILD OF OutputRoot DOMAIN ('SOAP'); --Compliant
+ SET a = SELECT * from Database;
RETURN TRUE;
END;
END MODULE;
\ No newline at end of file
diff --git a/esql-checks/src/test/resources/unreachableCode.esql b/esql-checks/src/test/resources/unreachableCode.esql
new file mode 100644
index 00000000..e969debc
--- /dev/null
+++ b/esql-checks/src/test/resources/unreachableCode.esql
@@ -0,0 +1,105 @@
+CREATE COMPUTE MODULE TestFlow_Compute
+ CREATE FUNCTION message_domain() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.test='a';
+ SET OutputRoot.MRM.test='a';
+ RETURN TRUE; --Compliant
+ END;
+ CREATE FUNCTION unreachable() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.test='a';
+ RETURN TRUE; --Noncompliant
+ RETURN TRUE;
+ SET OutputRoot.MRM.test='a';
+ END;
+ CREATE FUNCTION unreachable2() RETURNS BOOLEAN
+ BEGIN
+ SET OutputRoot.XMLNSC.test='a';
+ THROW USER EXCEPTION; --Noncompliant
+ SET OutputRoot.MRM.test='a';
+ END;
+
+
+ CREATE FUNCTION unreachableLeaveContinue () RETURNS BOOLEAN
+ BEGIN
+ DECLARE i INTEGER;
+ SET i = 0;
+ X : REPEAT
+ SET i = i + 1;
+
+ ITERATE X; --Noncompliant
+
+
+ IF i IN(2, 3) THEN
+ ITERATE X;
+ END IF;
+
+ -- Some statements 2
+
+ UNTIL
+ i >= 4
+ END REPEAT X;
+ X : REPEAT
+ SET i = i + 1;
+
+ LEAVE X; --Noncompliant
+
+ IF i IN(2, 3) THEN
+ LEAVE X;
+ END IF;
+
+ -- Some statements 2
+
+ UNTIL
+ i >= 4
+ END REPEAT X;
+ END;
+
+
+END MODULE;
+
+CREATE COMPUTE MODULE initialize
+CREATE FUNCTION main() RETURNS BOOLEAN
+ BEGIN
+
+ DECLARE VersionRef REFERENCE TO InputRoot.SOAP.Context.SOAP_Version;
+
+ CASE
+ WHEN versionRef = '1.1' THEN
+ SET Environment.soapenv:Client = 'soapenv:Client';
+
+ WHEN versionRef = '1.2' THEN
+ SET Environment.Fault.faultcode = 'soapenv:Sender';
+
+END CASE;
+IF envRefVar.inputNoOfAccounts > maxNoOfAccountsCons THEN
+ -- throw function error
+ SET envRefVar.firstFlag = 'Y';
+ SET envRefVar.flag='Y';
+ THROW USER EXCEPTION MESSAGE 5001 VALUES('Maximum account number limit of 300 exceeded'); --Noncompliant
+ DECLARE fa1 CONSTANT CHARACTER;
+ END IF;
+
+
+CREATE FIELD Environment.LogData;
+
+DECLARE refEnv REFERENCE TO Environment.LogData;
+
+SET refEnv.serviceOperationName = InputRoot.SOAP.Context.operation;
+
+SET refEnv.operationId = EVAL(Environment.LogData.serviceOperationName);
+
+SET refEnv.serviceName = InputRoot.SOAP.Context.service;
+
+SET refEnv.interfaceId = InputRoot.SOAP.Header.ns:Info.consumerId;
+
+SET refEnv.serviceVersion = SUBSTRING(SUBSTRING(SUBSTRING(InputRoot.SOAP.Context.portTypeNamespace AFTER InputRoot.SOAP.Context.service) AFTER '/')BEFORE '/');
+DECLARE VersionRef REFERENCE TO InputRoot.SOAP.Context.SOAP_Version;
+SET OutputRoot=InputRoot;
+
+RETURN TRUE;
+
+
+END;
+
+END MODULE;
diff --git a/esql-checks/src/test/resources/vaiablesSubtree.esql b/esql-checks/src/test/resources/vaiablesSubtree.esql
index 7f76a8b1..5c9fce0d 100644
--- a/esql-checks/src/test/resources/vaiablesSubtree.esql
+++ b/esql-checks/src/test/resources/vaiablesSubtree.esql
@@ -5,6 +5,9 @@ CREATE COMPUTE MODULE Module1
SET Environment.ABC='ABC'; --Noncompliant
SET Environment.{abc}='ABC'; --Noncompliant
SET Environment.Variables.abc='ABC'; --Compliant
+ SET Environment.[]='ABC'; --Noncompliant
+ SET OutputRoot.XMLNSC.abc='ABC'; --Compliant
+ SET Environment='ABC'; --Compliant
END;
diff --git a/esql-checks/src/test/resources/xmlnscDomain.esql b/esql-checks/src/test/resources/xmlnscDomain.esql
index ea601718..5e4566b4 100644
--- a/esql-checks/src/test/resources/xmlnscDomain.esql
+++ b/esql-checks/src/test/resources/xmlnscDomain.esql
@@ -3,13 +3,22 @@ CREATE COMPUTE MODULE Module1
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
- CREATE LASTCHILD OF OutputRoot DOMAIN 'XMLNS' NAME 'XMLNS'; --Noncompliant
- CREATE LASTCHILD OF OutputRoot DOMAIN 'XML' NAME 'XML'; --Noncompliant
+ CREATE LASTCHILD OF OutputRoot DOMAIN 'XMLNS' NAME 'XMLNS'; --Noncompliant {{Use the XMLNSC domain instead of XMLNS.}}
+ CREATE LASTCHILD OF OutputRoot DOMAIN 'XML' NAME 'XML'; --Noncompliant {{Use the XMLNSC domain instead of XML.}}
CREATE LASTCHILD OF OutputRoot DOMAIN 'XMLNSC' NAME 'XMLNSC'; --Compliant
-
- SET OutputRoot.XML.abc.abc='ABC'; --Noncompliant
- SET OutputRoot.XMLNS.abc.abc='ABC'; --Noncompliant
+ CREATE LASTCHILD OF OutputRoot DOMAIN ('XMLNS'); --Noncompliant {{Use the XMLNSC domain instead of XMLNS.}}
+ CREATE LASTCHILD OF OutputRoot DOMAIN (loadDomain()); --Compliant
+ CREATE LASTCHILD OF OutputRoot NAME 'XMLNS'; --Compliant
+
+ SET OutputRoot.XML.abc.abc='ABC'; --Noncompliant {{Use the XMLNSC domain instead of XML.}}
+ SET OutputRoot.XMLNS.abc.abc='ABC'; --Noncompliant {{Use the XMLNSC domain instead of XMLNS.}}
SET OutputRoot.XMLNSC.abc.abc='ABC'; --Compliant
+ SET OutputRoot.XMLNSC.abc.(XML.Attribute)abc='ABC'; --Noncompliant {{Use the XMLNSC domain instead of XML.}}
+ SET OutputRoot.*='a'; --Compliant
+ SET OutputRoot.[]='a'; --Compliant
+ SET Environment.a = InputRoot.XMLNS; --Noncompliant {{Use the XMLNSC domain instead of XMLNS.}}
+ SET OutputRoot = InputRoot; --Compliant
+ DECLARE C INTEGER SELECT COUNT(*) FROM Database.DUAL; --Compliant
END;
diff --git a/esql-code-coverage/pom.xml b/esql-code-coverage/pom.xml
index 6247f735..a770c36e 100644
--- a/esql-code-coverage/pom.xml
+++ b/esql-code-coverage/pom.xml
@@ -6,7 +6,7 @@
com.exxeta.isssonar-esql-plugin
- 2.2.0
+ 2.3.0esql-code-coverage
diff --git a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/AbstractAnalyzer.java b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/AbstractAnalyzer.java
index 3e8312f8..5ee8bc3d 100644
--- a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/AbstractAnalyzer.java
+++ b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/AbstractAnalyzer.java
@@ -1,8 +1,26 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.codecoverage;
+import static com.exxeta.iss.sonar.esql.codecoverage.CodeCoverageExtension.LOG;
+
import java.io.File;
import java.io.IOException;
-import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -14,15 +32,11 @@
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.SensorContext;
-import org.sonar.api.batch.sensor.coverage.CoverageType;
import org.sonar.api.batch.sensor.coverage.NewCoverage;
-import com.google.common.io.Files;
-import static com.exxeta.iss.sonar.esql.codecoverage.CodeCoverageExtension.LOG;
-
public abstract class AbstractAnalyzer implements ExecutionDataVisitor {
- private Pattern pathPattern = Pattern.compile("(?i)\\s*CREATE\\s+SCHEMA\\s+([\\w\\.]+)\\s+PATH");
+ private Pattern pathPattern = Pattern.compile("(?i)\\s*BROKER\\s+SCHEMA\\s+([\\w\\.]+)\\s+PATH.*");
private Pattern modulePattern = Pattern.compile("(?i)\\s*CREATE\\s+(COMPUTE|FILTER|DATABASE)\\s+MODULE\\s+(.+)");
private Pattern routinePattern = Pattern.compile("(?i)\\s*CREATE\\s+(FUNCTION|PROCEDURE)\\s+([\\w]+)\\W+.*");
private Pattern endModulePattern = Pattern.compile("(?i)\\s*END\\s+MODULE;.*");
@@ -50,18 +64,18 @@ public final void analyse(SensorContext context) {
// Create new coverages for all InputFiles
for (InputFile file : files) {
- NewCoverage coverage = context.newCoverage().onFile(file).ofType(CoverageType.UNIT);
+ NewCoverage coverage = context.newCoverage().onFile(file);
Set fileExecutableLines = executableLines.get(file);
Set fileExecutedLines = executedLines.get(file);
if (fileExecutableLines != null && fileExecutedLines == null) {
- LOG.info("File has not been executed " + file.absolutePath());
+ LOG.info("File has not been executed " + file.uri());
for (int line : fileExecutableLines) {
coverage.lineHits(line, 0);
coverage.conditions(line, 1, 0);
}
coverage.save();
} else if (fileExecutableLines == null) {
- LOG.warn("File has not been parsed " + file.absolutePath());
+ LOG.warn("File has not been parsed " + file.uri());
} else {
String lineHits = "";
for (int line : fileExecutableLines) {
@@ -74,7 +88,7 @@ public final void analyse(SensorContext context) {
coverage.conditions(line, 1, 0);
}
}
- LOG.info("Saving execution data found for " + file.absolutePath()+lineHits);
+ LOG.info("Saving execution data found for " + file.uri()+lineHits);
coverage.save();
}
}
@@ -114,7 +128,7 @@ private void fillOffsetCache(InputFile file) {
String moduleName = "";
String routineName = "";
try {
- String contents = Files.toString(file.file(), Charset.defaultCharset());
+ String contents = file.contents();
int lineNumber = 0;
for (String line : contents.split("\\r?\\n")) {
lineNumber++;
diff --git a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/CodeCoverageExtension.java b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/CodeCoverageExtension.java
index d3f8cea7..a3833dd2 100644
--- a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/CodeCoverageExtension.java
+++ b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/CodeCoverageExtension.java
@@ -1,3 +1,20 @@
+/*
+ * Sonar ESQL Plugin
+ * Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
+ * http://www.exxeta.com
+ *
+ * Licensed 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 com.exxeta.iss.sonar.esql.codecoverage;
import java.util.List;
@@ -11,8 +28,7 @@ public class CodeCoverageExtension {
public static final Logger LOG = Loggers.get(CodeCoverageExtension.class.getName());
- private CodeCoverageExtension(){
- }
+ private CodeCoverageExtension(){}
public static List