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.iss sonar-esql-plugin - 2.2.0 + 2.3.0 4.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.0 com.exxeta.iss sonar-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"
  • +
+ diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/CommentedCode.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/CommentedCode.json new file mode 100644 index 00000000..aaff7875 --- /dev/null +++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/CommentedCode.json @@ -0,0 +1,16 @@ +{ + "title": "Sections of code should not be \"commented out\"", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + "misra", + "unused" + ], + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-125", + "sqKey": "CommentedCode" +} diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Comments.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Comments.html new file mode 100644 index 00000000..eb56108f --- /dev/null +++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Comments.html @@ -0,0 +1,69 @@ +

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.

+ +

Compliant Code Example

+ +
+BROKER SCHEMA generic
+CREATE COMPUTE MODULE initialize
+CREATE FUNCTION Main() RETURNS BOOLEAN
+	BEGIN
+	DECLARE soapenviron,soapenvir GMTTIMESTAMP;
+	DECLARE soapenviro,soapenvi GMTTIME;
+	DECLARE faultReferen TIME;
+	RETURN TRUE;
+	END;
+END MODULE;	 
+
+ +

Non-Compliant Code Example

+ +
+BROKER SCHEMA generic
+CREATE COMPUTE MODULE initialize
+CREATE FUNCTION Main() RETURNS BOOLEAN
+	BEGIN
+	DECLARE soapenviro GMTTIMESTAMP;
+	DECLARE soapenvi GMTTIMESTAMP;
+	DECLARE faultRefere TIMESTAMP;
+	DECLARE soapenviron GMTTIME;
+	DECLARE faultReferen TIME;
+	DECLARE soapenvir GMTTIME;
+	RETURN TRUE;
+	END;
+END MODULE;	 
+
\ 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.

+

Noncompliant Code Example

+
+	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;
+
+

Compliant Solution

+
+	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/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

+ + diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/SelfAssignment.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/SelfAssignment.json new file mode 100644 index 00000000..8e6ba2a3 --- /dev/null +++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/SelfAssignment.json @@ -0,0 +1,15 @@ +{ + "title": "Variables should not be self-assigned", + "type": "BUG", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "3min" + }, + "tags": [ + "cert" + ], + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-1656", + "sqKey": "SelfAssignment" +} diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Sonar_way_profile.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Sonar_way_profile.json index 539930d9..bb50abf4 100644 --- a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Sonar_way_profile.json +++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Sonar_way_profile.json @@ -43,12 +43,30 @@ "SelectAll", "Sleep", "Eval", - "Bitstream", "CaseWithTooManyWhens", "InitializeVariables", "TooManyParameters", "XmlnscDomain", - "RoutineWithExcessiveReturns" - ] + "RoutineWithExcessiveReturns", + "KeyWordCaseCheck", + "CyclomaticComplexity", + "PassThruStatement", + "SubElementName", + "FunctionProcedureLength", + "FilterNodeModifyMessage", + "FilterNodeHaveOnlyOneReturn", + "NavigatingTreeCouldBeReference", + "UnusedVariable", + "DeprecatedMethod", + "BinaryOperatorSeparatedBySpace", + "RoutineComments", + "PropagateConsistency", + "UnreachableCode", + "Comments", + "DeclareCombine" + + + +] } - \ No newline at end of file + diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/SubElementName.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/SubElementName.html new file mode 100644 index 00000000..13e9b8e0 --- /dev/null +++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/SubElementName.html @@ -0,0 +1,18 @@ +

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
  • +
  • MISRA C:2012, 2.2 - There shall be no dead code
  • +
  • MITRE, CWE-561 - Dead Code
  • +
  • CERT, MSC56-J. - Detect and remove superfluous code and values
  • +
  • CERT, MSC12-C. - Detect and remove code that has no effect or is never + executed
  • +
  • CERT, MSC07-CPP. - Detect and remove dead code
  • +
+ diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/UnreachableCode.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/UnreachableCode.json new file mode 100644 index 00000000..d4cc6a5c --- /dev/null +++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/UnreachableCode.json @@ -0,0 +1,19 @@ +{ + "title": "Jump statements should not be followed by other statements", + "type": "BUG", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + "cwe", + "misra", + "cert", + "unused" + ], + "standards": [ + "CWE" + ], + "defaultSeverity": "Major" +} diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/UnusedVariable.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/UnusedVariable.html new file mode 100644 index 00000000..cd6d6334 --- /dev/null +++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/UnusedVariable.html @@ -0,0 +1,18 @@ +

This rule applies whenever unused variables are used .

+ +

Unused Variable should be removed, for better performance

+ +

Noncompliant Code Example

+
+
+		DECLARE inRef REFERENCE TO InputRoot.SOAP.Body;
+		CALL createAccessFacilityAgreement_response(outRef,Environment);
+	
+
+

Compliant Solution

+
+        DECLARE inRef REFERENCE TO InputRoot.SOAP.Body;
+		CALL createAccessFacilityAgreement_response(inRef,outRef,Environment);
+	
+	
+
\ 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.iss sonar-esql-plugin - 2.2.0 + 2.3.0 esql-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 getExtensions() { ImmutableList.Builder extensions = ImmutableList.builder(); diff --git a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/CodePosition.java b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/CodePosition.java index ebc926f1..771b0bfe 100644 --- a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/CodePosition.java +++ b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/CodePosition.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 org.sonar.api.batch.fs.InputFile; diff --git a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/ExecutionDataVisitor.java b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/ExecutionDataVisitor.java index 88f60878..a6c3a50b 100644 --- a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/ExecutionDataVisitor.java +++ b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/ExecutionDataVisitor.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; public interface ExecutionDataVisitor { diff --git a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/LineExecutionData.java b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/LineExecutionData.java index de322296..2bfc481e 100644 --- a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/LineExecutionData.java +++ b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/LineExecutionData.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; public class LineExecutionData { diff --git a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/ModuleExecutionData.java b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/ModuleExecutionData.java index 5efc157a..7e95dfba 100644 --- a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/ModuleExecutionData.java +++ b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/ModuleExecutionData.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.HashSet; diff --git a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/TraceFileReader.java b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/TraceFileReader.java index 1b0cda6e..4b1ab619 100644 --- a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/TraceFileReader.java +++ b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/TraceFileReader.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 static com.exxeta.iss.sonar.esql.codecoverage.CodeCoverageExtension.LOG; diff --git a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/TraceSensor.java b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/TraceSensor.java index 5682b442..090799e4 100644 --- a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/TraceSensor.java +++ b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/codecoverage/TraceSensor.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 static com.exxeta.iss.sonar.esql.codecoverage.CodeCoverageExtension.LOG; diff --git a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/trace/InsertType.java b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/trace/InsertType.java index d1794c0f..4ca24ad9 100644 --- a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/trace/InsertType.java +++ b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/trace/InsertType.java @@ -1,4 +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.trace; import javax.xml.bind.annotation.XmlAccessType; diff --git a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/trace/UserTraceLog.java b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/trace/UserTraceLog.java index 1558b4c5..c7e94935 100644 --- a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/trace/UserTraceLog.java +++ b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/trace/UserTraceLog.java @@ -1,4 +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.trace; import java.util.ArrayList; diff --git a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/trace/UserTraceType.java b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/trace/UserTraceType.java index 1ae14996..4a97a62f 100644 --- a/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/trace/UserTraceType.java +++ b/esql-code-coverage/src/main/java/com/exxeta/iss/sonar/esql/trace/UserTraceType.java @@ -1,5 +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.trace; import java.util.ArrayList; diff --git a/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/CodeCoverageExtensionTest.java b/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/CodeCoverageExtensionTest.java index 01247a61..707ce594 100644 --- a/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/CodeCoverageExtensionTest.java +++ b/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/CodeCoverageExtensionTest.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 org.junit.Test; diff --git a/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/CodePositionTest.java b/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/CodePositionTest.java index 8a7f0397..0fabe5da 100644 --- a/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/CodePositionTest.java +++ b/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/CodePositionTest.java @@ -1,11 +1,33 @@ +/* + * 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 org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.File; import org.junit.Test; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputFile.Type; import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import com.google.common.base.Charsets; @@ -22,26 +44,28 @@ public void test(){ CodePosition cp5 = new CodePosition(null, 1); CodePosition cp6 = new CodePosition(null, 1); - assert(!cp1.equals(null)); - assert(!cp1.equals("")); - assert(cp1.equals(cp1)); - assert(!cp1.equals(cp2)); - assert(!cp1.equals(cp3)); - assert(cp1.equals(cp4)); - assert(!cp1.equals(cp5)); - assert(!cp5.equals(cp1)); - assert(cp1.hashCode()==cp4.hashCode()); - assert(cp5.equals(cp6)); + assertFalse(cp1.equals(null)); + assertFalse(cp1.equals("")); + assertTrue(cp1.equals(cp1)); + assertFalse(cp1.equals(cp2)); + assertFalse(cp1.equals(cp3)); + assertTrue(cp1.equals(cp4)); + assertFalse(cp1.equals(cp5)); + assertFalse(cp5.equals(cp1)); + assertThat(cp1.hashCode()).isEqualTo(cp4.hashCode()); + assertThat(cp5.hashCode()).isEqualTo(cp6.hashCode()); + assertTrue(cp5.equals(cp6)); } private InputFile inputFile(String relativePath){ File moduleBaseDir = new File(""); - DefaultInputFile inputFile = new DefaultInputFile("moduleKey", relativePath) + DefaultInputFile inputFile = new TestInputFileBuilder("moduleKey", relativePath) .setModuleBaseDir(moduleBaseDir.toPath()) .setLanguage("esql") .setType(Type.MAIN) - .setCharset(Charsets.UTF_8); + .setCharset(Charsets.UTF_8) + .build(); return inputFile; } } diff --git a/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/LineExecutionDataTest.java b/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/LineExecutionDataTest.java new file mode 100644 index 00000000..6c948388 --- /dev/null +++ b/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/LineExecutionDataTest.java @@ -0,0 +1,65 @@ +/* + * 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 org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class LineExecutionDataTest { + + @Test + public void equalTest(){ + + LineExecutionData a = new LineExecutionData("f", "1", "s"); + LineExecutionData b = new LineExecutionData("f", "1", "s2"); + LineExecutionData c = new LineExecutionData(null, "1", "s"); + LineExecutionData d = new LineExecutionData("f", null, "s"); + LineExecutionData e = new LineExecutionData("f", "1", null); + + assertTrue(a.equals(a)); + assertFalse(a.equals(null)); + assertFalse(a.equals(b)); + assertTrue("f".equals(a.getFunction())); + assertTrue("1".equals(a.getRelativeLine())); + assertTrue("s".equals(a.getStatement())); + assertEquals(a.hashCode(),129447); + assertEquals(new LineExecutionData(null, null, null).hashCode(), 29791); + assertFalse(a.equals("")); + assertFalse(a.equals(new LineExecutionData(null, "", ""))); + assertFalse(a.equals(new LineExecutionData("f", null, ""))); + assertFalse(a.equals(new LineExecutionData("f", "1", null))); + assertTrue(a.equals(new LineExecutionData("f", "1", "s"))); + assertFalse(c.equals(new LineExecutionData(null, "", ""))); + assertFalse(c.equals(new LineExecutionData("f", null, ""))); + assertFalse(c.equals(new LineExecutionData("f", "1", null))); + assertTrue(c.equals(new LineExecutionData(null, "1", "s"))); + assertFalse(d.equals(new LineExecutionData(null, "", ""))); + assertFalse(d.equals(new LineExecutionData("f", null, ""))); + assertFalse(d.equals(new LineExecutionData("f", "1", null))); + assertTrue(d.equals(new LineExecutionData("f", null, "s"))); + assertFalse(e.equals(new LineExecutionData("f", null, ""))); + assertTrue(e.equals(new LineExecutionData("f", "1", null))); + assertFalse(e.equals(new LineExecutionData("f", "1", "aaa"))); + + } + + +} diff --git a/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/TestUtils.java b/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/TestUtils.java deleted file mode 100644 index 1e5d0c4a..00000000 --- a/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/TestUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.exxeta.iss.sonar.esql.codecoverage; - -import java.io.File; -import java.net.URISyntaxException; -import java.net.URL; - - -import org.apache.commons.lang.StringUtils; - - -public class TestUtils { - - public static File getResource(String path) { - String resourcePath = path; - if (!resourcePath.startsWith("/")) { - resourcePath = "/" + resourcePath; - } - URL url = TestUtils.class.getResource(resourcePath); - if (url != null) { - try { - return new File(url.toURI()); - } catch (URISyntaxException e) { - return null; - } - } - return null; - } - - public static File getResource(Class baseClass, String path) { - String resourcePath = StringUtils.replaceChars(baseClass.getCanonicalName(), '.', '/'); - if (!path.startsWith("/")) { - resourcePath += "/"; - } - resourcePath += path; - return getResource(resourcePath); - } -} diff --git a/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/TraceFileReaderTest.java b/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/TraceFileReaderTest.java index 4100c321..ca4ecdeb 100644 --- a/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/TraceFileReaderTest.java +++ b/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/TraceFileReaderTest.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 org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import java.io.File; @@ -14,97 +32,104 @@ import com.exxeta.iss.sonar.esql.trace.UserTraceLog; import com.exxeta.iss.sonar.esql.trace.UserTraceType; -import static org.assertj.core.api.Assertions.assertThat; - - -import static org.hamcrest.core.Is.is; - - public class TraceFileReaderTest { - + ExecutionDataVisitor testVisitor = new ExecutionDataVisitor() { + private int moduleCount = 0; + @Override + public void visitModuleExecution(ModuleExecutionData data) { + moduleCount++; + assertNotNull(data); + assertNotNull(data.getSchemaAndModuleName()); + assertThat (moduleCount).isLessThanOrEqualTo(3); + assertThat (data.size()).isGreaterThan(0); + } + }; + @Test public void readerTest() { - - ExecutionDataVisitor visitor = new ExecutionDataVisitor() { - private int moduleCount = 0; - @Override - public void visitModuleExecution(ModuleExecutionData data) { - moduleCount++; - assertNotNull(data); - assert(moduleCount<=3); - assert(data.size()>0); - - } - }; - - TraceFileReader reader = new TraceFileReader(new File("src/test/resources/codecoverage/MessageRoutingSampleTrace.txt")).readTrace(visitor); + + + TraceFileReader reader = new TraceFileReader( + new File("src/test/resources/codecoverage/MessageRoutingSampleTrace.txt")).readTrace(testVisitor); assertEquals(3, reader.getModuleCount()); assertNotNull(reader.getModuleExecutionData("")); assertEquals(2, reader.getModuleExecutionData("").size()); assertEquals(3, reader.getModuleExecutionData(".Refresh_memory_cache_Compute").size()); assertEquals(36, reader.getModuleExecutionData(".Routing_using_memory_cache_Compute").size()); - + + reader = new TraceFileReader(null).readTrace(testVisitor); + + } + + @Test(expected=RuntimeException.class) + public void testReaderWithNotExistingFile(){ + new TraceFileReader(new File("src/test/resources/codecoverage/doesNotExist.txt")).readTrace(testVisitor); } + + @Test public void xmlReaderTest() { - + ExecutionDataVisitor visitor = new ExecutionDataVisitor() { private int moduleCount = 0; + @Override public void visitModuleExecution(ModuleExecutionData data) { moduleCount++; assertNotNull(data); - assert(moduleCount<=20); - assert(data.size()>0); - + assertThat (moduleCount).isLessThanOrEqualTo(20); + assertThat (data.size()).isGreaterThan(0); + } }; - - TraceFileReader reader = new TraceFileReader(new File("src/test/resources/codecoverage/trace.xml")).readTrace(visitor); + + TraceFileReader reader = new TraceFileReader(new File("src/test/resources/codecoverage/trace.xml")) + .readTrace(visitor); assertEquals(1, reader.getModuleCount()); assertNull(reader.getModuleExecutionData("")); assertEquals(7, reader.getModuleExecutionData(".Test_Compute").size()); - + } - + @Test(expected=RuntimeException.class) + public void xmlReaderTestCorruptFile(){ + new TraceFileReader(new File("src/test/resources/codecoverage/corruptTrace.xml")) + .readTrace(testVisitor); + } + @Test - public void jaxBTest(){ - try { - assertThat(new UserTraceLog().getUserTraceOrInformation()).isNotNull(); - UserTraceLog trace = new TraceFileReader(new File("src/test/resources/codecoverage/trace.xml")).parseTraceXml(); - assertThat(trace.getBufferSize()).isEqualTo(0); - assertThat(trace.getFileMode()).isEqualTo("safe"); - assertThat(trace.getFileSize()).isEqualTo(20480000); - assertThat(trace.getTraceFilter()).isEqualTo("none"); - assertThat(trace.getTraceLevel()).isEqualTo("none"); - assertThat(trace.getUserTraceFilter()).isEqualTo("debugTrace"); - assertThat(trace.getUuid()).isEqualTo("UserTraceLog"); - assertThat(trace.getUserTraceOrInformation()).hasSize(75); - assertThat(new UserTraceType().getInsert()).isNotNull(); - UserTraceType trace1 = trace.getUserTraceOrInformation().get(0); - assertThat(trace1.getCatalog()).isEqualTo("BIPmsgs"); - assertThat(trace1.getFile()).isEqualTo("F:\\build\\S1000_slot1\\S1000_P\\src\\DataFlowEngine\\Configuration\\ImbConfigurationManager.cpp"); - assertThat(trace1.getFunction()).isEqualTo("ImbConfigurationManager::evaluate"); - assertThat(trace1.getLabel()).isEqualTo("ConfigurationManager"); - assertThat(trace1.getLine()).isEqualTo("956"); - assertThat(trace1.getName()).isEqualTo("ConfigurationManager"); - assertThat(trace1.getNumber()).isEqualTo("4040"); - assertThat(trace1.getText()).isEqualTo("'Configuration changed successfully and committed to persistent store'"); - assertThat(trace1.getThread()).isEqualTo("9328"); - assertThat(trace1.getTimestamp()).isEqualTo("2017-09-15 04:28:04.403125"); - assertThat(trace1.getType()).isEqualTo("ComIbmConfigurationManager"); - assertThat(trace1.getInsert()).hasSize(3); - InsertType insert = trace1.getInsert().get(0); - assertThat(insert.getType()).isEqualTo("string"); - assertThat(insert.getValue()).isEqualTo("'default'"); - - } catch (JAXBException e) { - e.printStackTrace(); - assert(false); - } - + public void jaxBTest() throws JAXBException { + assertThat(new UserTraceLog().getUserTraceOrInformation()).isNotNull(); + UserTraceLog trace = new TraceFileReader(new File("src/test/resources/codecoverage/trace.xml")).parseTraceXml(); + assertThat(trace.getBufferSize()).isEqualTo(0); + assertThat(trace.getFileMode()).isEqualTo("safe"); + assertThat(trace.getFileSize()).isEqualTo(20480000); + assertThat(trace.getTraceFilter()).isEqualTo("none"); + assertThat(trace.getTraceLevel()).isEqualTo("none"); + assertThat(trace.getUserTraceFilter()).isEqualTo("debugTrace"); + assertThat(trace.getUuid()).isEqualTo("UserTraceLog"); + assertThat(trace.getUserTraceOrInformation()).hasSize(75); + assertThat(new UserTraceType().getInsert()).isNotNull(); + UserTraceType trace1 = trace.getUserTraceOrInformation().get(0); + assertThat(trace1.getCatalog()).isEqualTo("BIPmsgs"); + assertThat(trace1.getFile()).isEqualTo( + "F:\\build\\S1000_slot1\\S1000_P\\src\\DataFlowEngine\\Configuration\\ImbConfigurationManager.cpp"); + assertThat(trace1.getFunction()).isEqualTo("ImbConfigurationManager::evaluate"); + assertThat(trace1.getLabel()).isEqualTo("ConfigurationManager"); + assertThat(trace1.getLine()).isEqualTo("956"); + assertThat(trace1.getName()).isEqualTo("ConfigurationManager"); + assertThat(trace1.getNumber()).isEqualTo("4040"); + assertThat(trace1.getText()) + .isEqualTo("'Configuration changed successfully and committed to persistent store'"); + assertThat(trace1.getThread()).isEqualTo("9328"); + assertThat(trace1.getTimestamp()).isEqualTo("2017-09-15 04:28:04.403125"); + assertThat(trace1.getType()).isEqualTo("ComIbmConfigurationManager"); + assertThat(trace1.getInsert()).hasSize(3); + InsertType insert = trace1.getInsert().get(0); + assertThat(insert.getType()).isEqualTo("string"); + assertThat(insert.getValue()).isEqualTo("'default'"); + } - + } diff --git a/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/TraceSensorTest.java b/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/TraceSensorTest.java index 7c26c845..a5cf1807 100644 --- a/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/TraceSensorTest.java +++ b/esql-code-coverage/src/test/java/com/exxeta/iss/sonar/esql/codecoverage/TraceSensorTest.java @@ -15,15 +15,32 @@ import org.sonar.api.batch.fs.InputFile.Type; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.FileMetadata; +import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.internal.SensorContextTester; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import com.google.common.base.Charsets; import com.google.common.collect.ImmutableSet; +/* + * 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. + */ public class TraceSensorTest { private SensorContextTester context; - private Settings settings; + private MapSettings settings; private File moduleBaseDir = new File("src/test/resources/codecoverage/"); @@ -32,17 +49,21 @@ public class TraceSensorTest { private TraceSensor sensor; @Before - public void init() { - settings = new MapSettings(); + public void init() throws FileNotFoundException { + settings = new MapSettings(); settings.setProperty("sonar.esql.trace.reportPaths", "TraceSensorTest/trace.txt"); context = SensorContextTester.create(moduleBaseDir); context.setSettings(settings); InputFile inputFile1 = inputFile("file1.esql", Type.MAIN); + InputFile inputFile2 = inputFile("file2.esql", Type.MAIN); + InputFile inputFile3 = inputFile("file3.esql", Type.MAIN); //inputFile("tests/file1.esql", Type.TEST); linesOfCode = new HashMap<>(); linesOfCode.put(inputFile1, ImmutableSet.of(1, 2, 3, 4)); + linesOfCode.put(inputFile2, null); + linesOfCode.put(inputFile3, ImmutableSet.of(1, 2, 3, 4)); sensor = new TraceSensor(); @@ -51,18 +72,15 @@ public void init() { } - private InputFile inputFile(String relativePath, Type type) { - DefaultInputFile inputFile = new DefaultInputFile("moduleKey", relativePath) + private InputFile inputFile(String relativePath, Type type) throws FileNotFoundException { + DefaultInputFile inputFile = new TestInputFileBuilder("moduleKey", relativePath) .setModuleBaseDir(moduleBaseDir.toPath()) .setLanguage("esql") .setType(type) - .setCharset(Charsets.UTF_8); + .setCharset(Charsets.UTF_8) + .build(); - try { - inputFile.initMetadata(new FileMetadata().readMetadata(new FileReader( inputFile.file()))); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } + inputFile.setMetadata(new FileMetadata().readMetadata(new FileReader( inputFile.file()))); context.fileSystem().add(inputFile); return inputFile; @@ -75,7 +93,14 @@ public void report_not_found() throws Exception { assertThat(context.lineHits("moduleKey:file1.js", 1)).isNull(); } - + + @Test + public void folder_test() { + sensor.execute(context,linesOfCode,new String[]{"TraceSensorTest"}); + assertThat(sensor.toString()).isEqualTo("TraceSensor"); + assertThat(context.conditions("moduleKey:file1.esql", 1)).isEqualTo(1); + } + @Test public void test_overall_coverage() { sensor.execute(context,linesOfCode,new String[]{"TraceSensorTest/trace.txt"}); diff --git a/esql-code-coverage/src/test/resources/codecoverage/corruptTrace.xml b/esql-code-coverage/src/test/resources/codecoverage/corruptTrace.xml new file mode 100644 index 00000000..32a23117 --- /dev/null +++ b/esql-code-coverage/src/test/resources/codecoverage/corruptTrace.xml @@ -0,0 +1 @@ + com.exxeta.iss sonar-esql-plugin - 2.2.0 + 2.3.0 esql-frontend diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/CustomEsqlRulesDefinition.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/CustomEsqlRulesDefinition.java index ac37d35c..33f42b4a 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/CustomEsqlRulesDefinition.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/CustomEsqlRulesDefinition.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/main/java/com/exxeta/iss/sonar/esql/api/EsqlCheck.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlCheck.java index 474ee272..49a75519 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlCheck.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlCheck.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/main/java/com/exxeta/iss/sonar/esql/api/EsqlMetric.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlMetric.java index 2ad4b5cb..dc220520 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlMetric.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlMetric.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/main/java/com/exxeta/iss/sonar/esql/api/EsqlNonReservedKeyword.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlNonReservedKeyword.java index 79f340ef..4e6659a7 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlNonReservedKeyword.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlNonReservedKeyword.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/main/java/com/exxeta/iss/sonar/esql/api/EsqlTokenType.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlTokenType.java index 2b424a06..6c3e1a23 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlTokenType.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlTokenType.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/main/java/com/exxeta/iss/sonar/esql/api/symbols/Symbol.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/Symbol.java index 381cf639..4fdcacb7 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/Symbol.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/Symbol.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"); @@ -122,11 +122,11 @@ public TypeSet types() { } /** - * @return true if symbol created with var, let or const keywords or implicitly + * @return true if symbol created with CREATE */ - /* public boolean isVariable() { - return kind == Kind.LET_VARIABLE || kind == Kind.CONST_VARIABLE || kind == Kind.VARIABLE; - }*/ + public boolean isVariable() { + return kind == Kind.CONST_VARIABLE || kind == Kind.VARIABLE; + } @Override public String toString() { diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/SymbolModel.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/SymbolModel.java index 6e5d25e0..95096c13 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/SymbolModel.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/SymbolModel.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/main/java/com/exxeta/iss/sonar/esql/api/symbols/SymbolModelBuilder.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/SymbolModelBuilder.java index 69227a74..2ecde996 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/SymbolModelBuilder.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/SymbolModelBuilder.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/main/java/com/exxeta/iss/sonar/esql/api/symbols/Type.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/Type.java index 29fcce5b..a03e249a 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/Type.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/Type.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/main/java/com/exxeta/iss/sonar/esql/api/symbols/TypeSet.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/TypeSet.java index 7e0a39bd..cb37c877 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/TypeSet.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/TypeSet.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/main/java/com/exxeta/iss/sonar/esql/api/symbols/Usage.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/Usage.java index fade1de7..216aba84 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/Usage.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/symbols/Usage.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/main/java/com/exxeta/iss/sonar/esql/api/tree/AsbitstreamFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/AsbitstreamFunctionTree.java index 56f854da..75d5d310 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/AsbitstreamFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/AsbitstreamFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/BrokerSchemaStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/BrokerSchemaStatementTree.java index c1964e4b..9b17e925 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/BrokerSchemaStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/BrokerSchemaStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/DataTypeTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/DataTypeTree.java index 0b06de5d..1f1818d8 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/DataTypeTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/DataTypeTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/DecimalDataTypeTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/DecimalDataTypeTree.java index 621076fb..7eeba334 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/DecimalDataTypeTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/DecimalDataTypeTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/EsqlContentsTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/EsqlContentsTree.java index 8442d2ce..16f2cc88 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/EsqlContentsTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/EsqlContentsTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/FieldReferenceTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/FieldReferenceTree.java index ef058529..135ad744 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/FieldReferenceTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/FieldReferenceTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/IndexTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/IndexTree.java index 2e208c13..dcb7554b 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/IndexTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/IndexTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/IntervalDataTypeTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/IntervalDataTypeTree.java index 47907ec2..82b21f28 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/IntervalDataTypeTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/IntervalDataTypeTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/IntervalQualifierTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/IntervalQualifierTree.java index 6a684e33..2f82f6bf 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/IntervalQualifierTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/IntervalQualifierTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/ModuleTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/ModuleTree.java index 6189345b..467afbfd 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/ModuleTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/ModuleTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/NamespaceTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/NamespaceTree.java index 862f5998..30ebf9f1 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/NamespaceTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/NamespaceTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/PathClauseTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathClauseTree.java index 90393f1a..ed9c5473 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathClauseTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathClauseTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementNameTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementNameTree.java index 9cf495d4..eea8e492 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementNameTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementNameTree.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,13 +18,15 @@ package com.exxeta.iss.sonar.esql.api.tree; import com.exxeta.iss.sonar.esql.api.tree.expression.ExpressionTree; +import com.exxeta.iss.sonar.esql.api.tree.expression.IdentifierTree; import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken; public interface PathElementNameTree extends Tree{ SyntaxToken nameCurlyOpen(); ExpressionTree nameExpression(); SyntaxToken nameCurlyClose(); - SyntaxToken name(); + IdentifierTree name(); + SyntaxToken star(); } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementNamespaceTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementNamespaceTree.java index 2e351fae..c1a501c9 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementNamespaceTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementNamespaceTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementTree.java index 52eb65f2..651fefa5 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementTypeTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementTypeTree.java index 1633c42b..991bf810 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementTypeTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/PathElementTypeTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/ProgramTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/ProgramTree.java index 99b5ccb3..981d1bde 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/ProgramTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/ProgramTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/RoutineDeclarationTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/RoutineDeclarationTree.java index 5d6f3f7a..bd1fbf7d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/RoutineDeclarationTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/RoutineDeclarationTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/SchemaNameTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/SchemaNameTree.java index b31277d7..2d6c020e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/SchemaNameTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/SchemaNameTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/Tree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/Tree.java index 102ece07..2a879ea3 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/Tree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/Tree.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"); @@ -84,6 +84,7 @@ import com.exxeta.iss.sonar.esql.api.tree.statement.MessageSourceTree; import com.exxeta.iss.sonar.esql.api.tree.statement.MoveStatementTree; import com.exxeta.iss.sonar.esql.api.tree.statement.NameClausesTree; +import com.exxeta.iss.sonar.esql.api.tree.statement.NullableTree; import com.exxeta.iss.sonar.esql.api.tree.statement.ParameterListTree; import com.exxeta.iss.sonar.esql.api.tree.statement.ParameterTree; import com.exxeta.iss.sonar.esql.api.tree.statement.ParseClauseTree; @@ -262,7 +263,8 @@ public enum Kind implements GrammarRuleKey, Kinds { BINDING_IDENTIFIER(IdentifierTree.class), PROPERTY_IDENTIFIER(IdentifierTree.class), VARIABLE_REFERENCE(VariableReferenceTree.class), - LIST_CONSTRUCTOR_FUNCTION(ListConstructorFunctionTree.class); + LIST_CONSTRUCTOR_FUNCTION(ListConstructorFunctionTree.class), + NULLABLE(NullableTree.class); final Class associatedInterface; diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/BetweenExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/BetweenExpressionTree.java index f0be4d7c..aa8d0b51 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/BetweenExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/BetweenExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/BinaryExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/BinaryExpressionTree.java index 55a2fbf4..37844b03 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/BinaryExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/BinaryExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/CallExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/CallExpressionTree.java index bcd37a02..1a34f39d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/CallExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/CallExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/ExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/ExpressionTree.java index d42922db..d6d3ddfb 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/ExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/ExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/IdentifierTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/IdentifierTree.java index 18352bcf..87b00b50 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/IdentifierTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/IdentifierTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/InExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/InExpressionTree.java index a4422c6e..74786f20 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/InExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/InExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/IntervalExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/IntervalExpressionTree.java index bda9b4fe..2d0b5c1b 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/IntervalExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/IntervalExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/IsExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/IsExpressionTree.java index f97fe2f3..e58d8daa 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/IsExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/IsExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/LikeExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/LikeExpressionTree.java index 0943c419..3f2f4ff4 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/LikeExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/LikeExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/ParenthesisedExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/ParenthesisedExpressionTree.java index f008f883..1b567485 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/ParenthesisedExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/ParenthesisedExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/UnaryExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/UnaryExpressionTree.java index 52e8e583..e3f288db 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/UnaryExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/UnaryExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/VariableReferenceTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/VariableReferenceTree.java index 185f0584..6f904b7f 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/VariableReferenceTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/expression/VariableReferenceTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/AliasedExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/AliasedExpressionTree.java index b62ea57d..efb01797 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/AliasedExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/AliasedExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/AliasedFieldReferenceTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/AliasedFieldReferenceTree.java index 61084c5d..f884ae8d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/AliasedFieldReferenceTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/AliasedFieldReferenceTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/CaseFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/CaseFunctionTree.java index 410cca59..ffae1c49 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/CaseFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/CaseFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/CastFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/CastFunctionTree.java index 9a876e3e..ca821fe7 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/CastFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/CastFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ComplexFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ComplexFunctionTree.java index 02fe6a60..88afb352 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ComplexFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ComplexFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/DateTimeFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/DateTimeFunctionTree.java index 9be4ae68..846f7b8f 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/DateTimeFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/DateTimeFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ExtractFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ExtractFunctionTree.java index 14ac052b..b79ae7da 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ExtractFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ExtractFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/FieldFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/FieldFunctionTree.java index ba9ddd7f..c08bf7fb 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/FieldFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/FieldFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ForFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ForFunctionTree.java index ef35d4c2..89d79634 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ForFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ForFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/FromClauseExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/FromClauseExpressionTree.java index 3a9b97be..cc2456d2 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/FromClauseExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/FromClauseExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/FunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/FunctionTree.java index 84126ffc..11d551b7 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/FunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/FunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ListConstructorFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ListConstructorFunctionTree.java index d1170ac5..5d6aca2a 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ListConstructorFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ListConstructorFunctionTree.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,12 +18,12 @@ package com.exxeta.iss.sonar.esql.api.tree.function; import com.exxeta.iss.sonar.esql.api.tree.expression.ExpressionTree; +import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken; import com.exxeta.iss.sonar.esql.tree.impl.SeparatedList; -import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; public interface ListConstructorFunctionTree extends ComplexFunctionTree{ - InternalSyntaxToken listKeyword(); - InternalSyntaxToken openingCurlyBrace(); + SyntaxToken listKeyword(); + SyntaxToken openingCurlyBrace(); SeparatedList expressions(); - InternalSyntaxToken closingCurlyBrace(); + SyntaxToken closingCurlyBrace(); } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ListFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ListFunctionTree.java index 82ceb96b..43544b2a 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ListFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/ListFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/MiscellaneousFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/MiscellaneousFunctionTree.java index ceadaa9a..99c9d18e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/MiscellaneousFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/MiscellaneousFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/NumericFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/NumericFunctionTree.java index 3271b04b..c8440c9f 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/NumericFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/NumericFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/OverlayFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/OverlayFunctionTree.java index 04bb7afe..dcaedb4c 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/OverlayFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/OverlayFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/PassthruFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/PassthruFunctionTree.java index a707df4b..a786cfca 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/PassthruFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/PassthruFunctionTree.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,6 @@ package com.exxeta.iss.sonar.esql.api.tree.function; 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.expression.ExpressionTree; import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken; import com.exxeta.iss.sonar.esql.api.tree.statement.ParameterListTree; diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/PositionFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/PositionFunctionTree.java index aa7f4fa4..9385819e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/PositionFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/PositionFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/RoundFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/RoundFunctionTree.java index 624ed1ef..67e581db 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/RoundFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/RoundFunctionTree.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,9 +25,9 @@ public interface RoundFunctionTree extends NumericFunctionTree{ SyntaxToken roundKeyword(); SyntaxToken openingParenthesis(); ExpressionTree sourceNumber(); -// SyntaxToken comma(); -// ExpressionTree precision(); - /*SyntaxToken modeKeyword(); - SyntaxToken roundingMode();*/ + SyntaxToken comma(); + ExpressionTree precision(); + SyntaxToken modeKeyword(); + SyntaxToken roundingMode(); SyntaxToken closingParenthesis(); } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/RowConstructorFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/RowConstructorFunctionTree.java index 6c8bce15..0bf24078 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/RowConstructorFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/RowConstructorFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/SelectClauseTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/SelectClauseTree.java index e7b6d873..e9f863ed 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/SelectClauseTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/SelectClauseTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/SelectFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/SelectFunctionTree.java index d6f2a334..73a361e2 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/SelectFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/SelectFunctionTree.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,14 +17,11 @@ */ package com.exxeta.iss.sonar.esql.api.tree.function; -import com.exxeta.iss.sonar.esql.tree.impl.function.FromClauseExpressionTreeImpl; -import com.exxeta.iss.sonar.esql.tree.impl.function.SelectClauseTreeImpl; -import com.exxeta.iss.sonar.esql.tree.impl.function.WhereClauseTreeImpl; -import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; +import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken; public interface SelectFunctionTree extends ComplexFunctionTree{ - InternalSyntaxToken selectKeyword(); - SelectClauseTreeImpl selectClause(); - FromClauseExpressionTreeImpl fromClause(); - WhereClauseTreeImpl whereClause(); + SyntaxToken selectKeyword(); + SelectClauseTree selectClause(); + FromClauseExpressionTree fromClause(); + WhereClauseTree whereClause(); } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/StringManipulationFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/StringManipulationFunctionTree.java index d32689c8..7e58950f 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/StringManipulationFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/StringManipulationFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/SubstringFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/SubstringFunctionTree.java index f771897f..e71ce808 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/SubstringFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/SubstringFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/TheFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/TheFunctionTree.java index e6caabde..bbbb0f71 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/TheFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/TheFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/TrimFunctionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/TrimFunctionTree.java index 14851dcc..4a194369 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/TrimFunctionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/TrimFunctionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/WhenClauseExpressionTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/WhenClauseExpressionTree.java index 30d931fb..9643c88a 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/WhenClauseExpressionTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/WhenClauseExpressionTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/function/WhereClauseTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/WhereClauseTree.java index 686be7e4..93694085 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/WhereClauseTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/function/WhereClauseTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/lexical/SyntaxToken.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/lexical/SyntaxToken.java index 761fcfe4..27bc17e0 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/lexical/SyntaxToken.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/lexical/SyntaxToken.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/main/java/com/exxeta/iss/sonar/esql/api/tree/lexical/SyntaxTrivia.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/lexical/SyntaxTrivia.java index 5e3a750d..11204e6f 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/lexical/SyntaxTrivia.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/lexical/SyntaxTrivia.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/AttachStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/AttachStatementTree.java index 39731e09..416e8038 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/AttachStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/AttachStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/BeginEndStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/BeginEndStatementTree.java index 741f3b71..81141f10 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/BeginEndStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/BeginEndStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CallStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CallStatementTree.java index 205eb1f5..623ab1cc 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CallStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CallStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CaseStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CaseStatementTree.java index 5f6b742f..f0677035 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CaseStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CaseStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ControlsTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ControlsTree.java index 582b09f2..ba82532c 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ControlsTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ControlsTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateFunctionStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateFunctionStatementTree.java index 3b76099c..e969a051 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateFunctionStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateFunctionStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateModuleStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateModuleStatementTree.java index b91602a9..36b2dae8 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateModuleStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateModuleStatementTree.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.api.tree.statement; -import java.util.List; - import com.exxeta.iss.sonar.esql.api.tree.expression.IdentifierTree; import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken; @@ -32,7 +30,7 @@ public interface CreateModuleStatementTree extends StatementTree { IdentifierTree moduleName(); - List moduleStatementsList(); + StatementsTree moduleStatementsList(); SyntaxToken endKeyword(); diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateProcedureStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateProcedureStatementTree.java index 6d0f51c1..b87b569d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateProcedureStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateProcedureStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateStatementTree.java index b90951fd..67e35228 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateStatementTree.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,37 +19,32 @@ import com.exxeta.iss.sonar.esql.api.tree.FieldReferenceTree; import com.exxeta.iss.sonar.esql.api.tree.expression.ExpressionTree; -import com.exxeta.iss.sonar.esql.tree.impl.declaration.FieldReferenceTreeImpl; -import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; -import com.exxeta.iss.sonar.esql.tree.impl.statement.FromClauseTreeImpl; -import com.exxeta.iss.sonar.esql.tree.impl.statement.ParseClauseTreeImpl; -import com.exxeta.iss.sonar.esql.tree.impl.statement.RepeatClauseTreeImpl; -import com.exxeta.iss.sonar.esql.tree.impl.statement.ValuesClauseTreeImpl; +import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken; public interface CreateStatementTree extends StatementTree { - InternalSyntaxToken createKeyword(); + SyntaxToken createKeyword(); - InternalSyntaxToken qualifierName(); + SyntaxToken qualifierName(); - InternalSyntaxToken qualifierOfKeyword(); + SyntaxToken qualifierOfKeyword(); FieldReferenceTree target(); - InternalSyntaxToken asKeyword(); + SyntaxToken asKeyword(); - FieldReferenceTreeImpl aliasFieldReference(); + FieldReferenceTree aliasFieldReference(); - InternalSyntaxToken domainKeyword(); + SyntaxToken domainKeyword(); ExpressionTree domainExpression(); - RepeatClauseTreeImpl repeatClause(); + RepeatClauseTree repeatClause(); - ValuesClauseTreeImpl valuesClause(); + ValuesClauseTree valuesClause(); - FromClauseTreeImpl fromClause(); + FromClauseTree fromClause(); - ParseClauseTreeImpl parseClause(); + ParseClauseTree parseClause(); - InternalSyntaxToken semi(); + SyntaxToken semi(); } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareHandlerStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareHandlerStatementTree.java index a052993a..bee0eacd 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareHandlerStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareHandlerStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareStatementTree.java index fe377e86..d14c25fd 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareStatementTree.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,10 +17,10 @@ */ package com.exxeta.iss.sonar.esql.api.tree.statement; +import com.exxeta.iss.sonar.esql.api.tree.DataTypeTree; import com.exxeta.iss.sonar.esql.api.tree.expression.ExpressionTree; import com.exxeta.iss.sonar.esql.api.tree.expression.IdentifierTree; import com.exxeta.iss.sonar.esql.tree.impl.SeparatedList; -import com.exxeta.iss.sonar.esql.tree.impl.declaration.DataTypeTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; public interface DeclareStatementTree extends StatementTree { @@ -28,9 +28,9 @@ public interface DeclareStatementTree extends StatementTree { InternalSyntaxToken declareToken(); SeparatedList nameList(); InternalSyntaxToken sharedExt(); - InternalSyntaxToken namesapce(); + InternalSyntaxToken namespace(); InternalSyntaxToken constantKeyword(); - DataTypeTreeImpl dataType(); + DataTypeTree dataType(); ExpressionTree initialValueExpression(); InternalSyntaxToken semi(); boolean isExternal(); diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteFromStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteFromStatementTree.java index 61221b44..7c6f6e68 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteFromStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteFromStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteStatementTree.java index ce82185d..12540a65 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DetachStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DetachStatementTree.java index f6f8a167..d4230fd3 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DetachStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/DetachStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ElseClauseTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ElseClauseTree.java index cb249646..3cd087c5 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ElseClauseTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ElseClauseTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ElseifClauseTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ElseifClauseTree.java index 64840e5d..5f69350c 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ElseifClauseTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ElseifClauseTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/EvalStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/EvalStatementTree.java index fc6ddcb1..0eacf411 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/EvalStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/EvalStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ExternalRoutineBodyTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ExternalRoutineBodyTree.java index aa5dd301..c33e6d89 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ExternalRoutineBodyTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ExternalRoutineBodyTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ForStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ForStatementTree.java index 1b17d76c..5d7e0d8d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ForStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ForStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/FromClauseTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/FromClauseTree.java index 8fa4f64b..607872c1 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/FromClauseTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/FromClauseTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/IfStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/IfStatementTree.java index 09f2b294..db5c37d3 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/IfStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/IfStatementTree.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"); @@ -44,4 +44,6 @@ public interface IfStatementTree extends StatementTree { SyntaxToken semiToken(); + boolean hasElse(); + } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/InsertStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/InsertStatementTree.java index eb1ff13e..8b7cfc51 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/InsertStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/InsertStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/IterateStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/IterateStatementTree.java index ba1e32e5..749073cd 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/IterateStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/IterateStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LabelTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LabelTree.java index 72e8e8bc..59716c5c 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LabelTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LabelTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LanguageTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LanguageTree.java index 29f311fc..34d30a7a 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LanguageTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LanguageTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LeaveStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LeaveStatementTree.java index 77a9b990..7847b391 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LeaveStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LeaveStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LogStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LogStatementTree.java index 024e9406..b3157227 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LogStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LogStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LoopStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LoopStatementTree.java index fbb14924..19617848 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LoopStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/LoopStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/MessageSourceTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/MessageSourceTree.java index c3f89f73..bea4e14d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/MessageSourceTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/MessageSourceTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/MoveStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/MoveStatementTree.java index 44336428..11a70780 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/MoveStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/MoveStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/NameClausesTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/NameClausesTree.java index 841832f5..9de2e9e0 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/NameClausesTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/NameClausesTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/NullableTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/NullableTree.java new file mode 100644 index 00000000..039c0069 --- /dev/null +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/NullableTree.java @@ -0,0 +1,12 @@ +package com.exxeta.iss.sonar.esql.api.tree.statement; + +import com.exxeta.iss.sonar.esql.api.tree.Tree; +import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; + +public interface NullableTree extends Tree{ + + InternalSyntaxToken nullableKeyword(); + InternalSyntaxToken notKeyword(); + InternalSyntaxToken nullKeyword(); + +} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParameterListTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParameterListTree.java index a094a9f5..e832a65e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParameterListTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParameterListTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParameterTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParameterTree.java index ce78e94c..c4cef1ba 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParameterTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParameterTree.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"); @@ -21,6 +21,7 @@ import com.exxeta.iss.sonar.esql.api.tree.expression.IdentifierTree; import com.exxeta.iss.sonar.esql.tree.impl.declaration.DataTypeTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; +import com.exxeta.iss.sonar.esql.tree.impl.statement.NullableTreeImpl; public interface ParameterTree extends Tree { InternalSyntaxToken directionIndicator(); @@ -28,5 +29,6 @@ public interface ParameterTree extends Tree { InternalSyntaxToken constantKeyword(); InternalSyntaxToken nameOrNamesapceKeyword(); DataTypeTreeImpl dataType(); + NullableTreeImpl nullable(); } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParseClauseTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParseClauseTree.java index 8df7ba25..be9802a6 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParseClauseTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParseClauseTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/PassthruStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/PassthruStatementTree.java index 0f4b86d1..9eb9f6c9 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/PassthruStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/PassthruStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/PropagateStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/PropagateStatementTree.java index ee4684d0..f0992e45 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/PropagateStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/PropagateStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RepeatClauseTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RepeatClauseTree.java index c638a081..0c39a421 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RepeatClauseTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RepeatClauseTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RepeatStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RepeatStatementTree.java index b729f3d7..445ebe73 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RepeatStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RepeatStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ResignalStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ResignalStatementTree.java index c4c4169f..b7f01150 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ResignalStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ResignalStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ResultSetTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ResultSetTree.java index 73b0d2a9..ea562f66 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ResultSetTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ResultSetTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ReturnStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ReturnStatementTree.java index 9dc4d8d5..83db6ead 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ReturnStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ReturnStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ReturnTypeTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ReturnTypeTree.java index 700028c1..9cc2df68 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ReturnTypeTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ReturnTypeTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RoutineBodyTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RoutineBodyTree.java index 73eb52c8..a79573e6 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RoutineBodyTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RoutineBodyTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/SetColumnTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/SetColumnTree.java index 76f19b68..297eeea7 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/SetColumnTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/SetColumnTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/SetStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/SetStatementTree.java index 0cae7f96..02916ef1 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/SetStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/SetStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/SqlStateTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/SqlStateTree.java index ef4eef04..4727dea4 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/SqlStateTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/SqlStateTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/StatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/StatementTree.java index ab724b07..2548e413 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/StatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/StatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/StatementsTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/StatementsTree.java index 797ccf85..3ceefcac 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/StatementsTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/StatementsTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ThrowStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ThrowStatementTree.java index b46072ad..edf18899 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ThrowStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ThrowStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/UpdateStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/UpdateStatementTree.java index 173cf14d..df2d07e0 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/UpdateStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/UpdateStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ValuesClauseTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ValuesClauseTree.java index 73a481ff..0df86dd8 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ValuesClauseTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/ValuesClauseTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/WhenClauseTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/WhenClauseTree.java index 7bcf4412..447c954a 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/WhenClauseTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/WhenClauseTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/WhileStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/WhileStatementTree.java index c94d1058..3b662bd4 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/WhileStatementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/WhileStatementTree.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/main/java/com/exxeta/iss/sonar/esql/api/tree/symbols/type/TypableTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/symbols/type/TypableTree.java index 727ca39d..27642e99 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/symbols/type/TypableTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/symbols/type/TypableTree.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/main/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitor.java index 775fa91f..7032c85d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitor.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"); @@ -103,6 +103,7 @@ import com.exxeta.iss.sonar.esql.api.tree.statement.MessageSourceTree; import com.exxeta.iss.sonar.esql.api.tree.statement.MoveStatementTree; import com.exxeta.iss.sonar.esql.api.tree.statement.NameClausesTree; +import com.exxeta.iss.sonar.esql.api.tree.statement.NullableTree; import com.exxeta.iss.sonar.esql.api.tree.statement.ParameterListTree; import com.exxeta.iss.sonar.esql.api.tree.statement.ParameterTree; import com.exxeta.iss.sonar.esql.api.tree.statement.ParseClauseTree; @@ -594,7 +595,10 @@ public void visitPathElementName(PathElementNameTree tree) { public void visitListConstructorFunction(ListConstructorFunctionTree tree) { scanChildren(tree); - + } + + public void visitNullable(NullableTree tree) { + scanChildren(tree); } } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitorCheck.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitorCheck.java index 63666421..325de147 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitorCheck.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitorCheck.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/main/java/com/exxeta/iss/sonar/esql/api/visitors/EsqlFile.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/EsqlFile.java index a659db21..578c559c 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/EsqlFile.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/EsqlFile.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,14 @@ */ package com.exxeta.iss.sonar.esql.api.visitors; +import java.io.IOException; +import java.net.URI; + public interface EsqlFile { + /** + * @deprecated use {@link EsqlFile#fileName()} or {@link EsqlFile#uri()} + */ String relativePath(); /** @@ -26,5 +32,11 @@ public interface EsqlFile { */ String fileName(); - String contents(); + String contents() throws IOException; + + /** + * Identifier of the file. The only guarantee is that it is unique in the project. + * You should not assume it is a file:// URI. + */ + URI uri(); } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/EsqlFileImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/EsqlFileImpl.java new file mode 100644 index 00000000..bedb53e0 --- /dev/null +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/EsqlFileImpl.java @@ -0,0 +1,57 @@ +/* + * SonarQube JavaScript Plugin + * Copyright (C) 2011-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package com.exxeta.iss.sonar.esql.api.visitors; + +import java.io.IOException; +import java.net.URI; +import org.sonar.api.batch.fs.InputFile; + +public class EsqlFileImpl implements EsqlFile { + + private InputFile inputFile; + + public EsqlFileImpl(InputFile inputFile) { + this.inputFile = inputFile; + } + + @Override + public String relativePath() { + return inputFile.relativePath(); + } + + @Override + public String fileName() { + return inputFile.filename(); + } + + @Override + public String contents() throws IOException { + return inputFile.contents(); + } + + @Override + public URI uri() { + return inputFile.uri(); + } + + public InputFile inputFile() { + return inputFile; + } +} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/EsqlVisitorContext.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/EsqlVisitorContext.java index 896701da..e132c61e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/EsqlVisitorContext.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/EsqlVisitorContext.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,27 +17,25 @@ */ package com.exxeta.iss.sonar.esql.api.visitors; -import java.io.File; - -import org.sonar.api.config.Settings; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.config.Configuration; import com.exxeta.iss.sonar.esql.api.symbols.SymbolModel; import com.exxeta.iss.sonar.esql.api.tree.ProgramTree; -import com.exxeta.iss.sonar.esql.compat.CompatibleInputFile; import com.exxeta.iss.sonar.esql.tree.symbols.SymbolModelImpl; public class EsqlVisitorContext implements TreeVisitorContext { private final ProgramTree tree; - private final CompatibleInputFile compatibleInputFile; + private final EsqlFile esqlFile; private final SymbolModel symbolModel; - public EsqlVisitorContext(ProgramTree tree, CompatibleInputFile compatibleInputFile, Settings settings) { + public EsqlVisitorContext(ProgramTree tree, InputFile inputFile, Configuration configuration) { this.tree = tree; - this.compatibleInputFile = compatibleInputFile; + this.esqlFile = new EsqlFileImpl(inputFile); this.symbolModel = new SymbolModelImpl(); - SymbolModelImpl.build(this, settings); + SymbolModelImpl.build(this, configuration); } @Override @@ -47,7 +45,7 @@ public ProgramTree getTopTree() { @Override public EsqlFile getEsqlFile() { - return compatibleInputFile; + return esqlFile; } @Override @@ -55,9 +53,4 @@ public SymbolModel getSymbolModel() { return symbolModel; } - @Override - public File getFile() { - return compatibleInputFile.file(); - } - } - +} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/FileIssue.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/FileIssue.java index d9c8e711..789320c8 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/FileIssue.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/FileIssue.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/main/java/com/exxeta/iss/sonar/esql/api/visitors/Issue.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/Issue.java index 6496bbba..1e312927 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/Issue.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/Issue.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/main/java/com/exxeta/iss/sonar/esql/api/visitors/IssueLocation.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/IssueLocation.java index 1ebdea19..4d265219 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/IssueLocation.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/IssueLocation.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/main/java/com/exxeta/iss/sonar/esql/api/visitors/Issues.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/Issues.java index cdd105c3..89834766 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/Issues.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/Issues.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/main/java/com/exxeta/iss/sonar/esql/api/visitors/LineIssue.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/LineIssue.java index ec298980..ff9eeb4e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/LineIssue.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/LineIssue.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/main/java/com/exxeta/iss/sonar/esql/api/visitors/PreciseIssue.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/PreciseIssue.java index 4ec20fda..01021ee4 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/PreciseIssue.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/PreciseIssue.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/main/java/com/exxeta/iss/sonar/esql/api/visitors/SubscriptionVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/SubscriptionVisitor.java index aefe6508..3e0c9f15 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/SubscriptionVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/SubscriptionVisitor.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,7 @@ import java.util.Collection; import java.util.Iterator; -import java.util.List; +import java.util.Set; import com.exxeta.iss.sonar.esql.api.tree.Tree; import com.exxeta.iss.sonar.esql.tree.impl.EsqlTree; @@ -30,7 +30,7 @@ public abstract class SubscriptionVisitor implements TreeVisitor { private TreeVisitorContext context; private Collection nodesToVisit; - public abstract List nodesToVisit(); + public abstract Set nodesToVisit(); public void visitNode(Tree tree) { // Default behavior : do nothing. diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/SubscriptionVisitorCheck.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/SubscriptionVisitorCheck.java index cb3cf3d0..e306617d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/SubscriptionVisitorCheck.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/SubscriptionVisitorCheck.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/main/java/com/exxeta/iss/sonar/esql/api/visitors/TreeVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/TreeVisitor.java index 01b7f6f9..b0b5969c 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/TreeVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/TreeVisitor.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/main/java/com/exxeta/iss/sonar/esql/api/visitors/TreeVisitorContext.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/TreeVisitorContext.java index ad718ff2..6d9eca7b 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/TreeVisitorContext.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/TreeVisitorContext.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,9 +17,6 @@ */ package com.exxeta.iss.sonar.esql.api.visitors; -import java.io.File; - - import com.exxeta.iss.sonar.esql.api.symbols.SymbolModel; import com.exxeta.iss.sonar.esql.api.tree.ProgramTree; @@ -32,6 +29,4 @@ public interface TreeVisitorContext { SymbolModel getSymbolModel(); - File getFile(); - } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/compat/CompatibilityHelper.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/compat/CompatibilityHelper.java deleted file mode 100644 index 09436530..00000000 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/compat/CompatibilityHelper.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.compat; - -import java.util.Collection; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.sensor.SensorContext; -import org.sonar.api.utils.Version; - -public class CompatibilityHelper { - public static final Version V6_0 = Version.create(6, 0); - public static final Version V6_2 = Version.create(6, 2); - - public static CompatibleInputFile wrap(InputFile inputFile) { - return new CompatibleInputFile(inputFile); - } - - public static Collection wrap(Iterable inputFiles, SensorContext context) { - Version version = context.getSonarQubeVersion(); - if (version.isGreaterThanOrEqual(V6_2)) { - return inputFileStream(inputFiles).map(CompatibleInputFile::new).collect(Collectors.toList()); - } - if (version.isGreaterThanOrEqual(V6_0)) { - return inputFileStream(inputFiles).map(InputFileV60Compat::new).collect(Collectors.toList()); - } - return inputFileStream(inputFiles).map(f -> new InputFileV56Compat(f, context)).collect(Collectors.toList()); - } - - private static Stream inputFileStream(Iterable inputFiles) { - return StreamSupport.stream(inputFiles.spliterator(), false); - } - -} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/compat/CompatibleInputFile.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/compat/CompatibleInputFile.java deleted file mode 100644 index 98fda1e9..00000000 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/compat/CompatibleInputFile.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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.compat; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.file.Path; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.TextPointer; -import org.sonar.api.batch.fs.TextRange; - -import com.exxeta.iss.sonar.esql.api.visitors.EsqlFile; - -/** - * A compatibility wrapper for InputFile. See class hierarchy. - * - * All methods of this class simply delegate to the wrapped instance, except `wrapped`. - */ -public class CompatibleInputFile implements EsqlFile { - private final InputFile wrapped; - - CompatibleInputFile(InputFile wrapped) { - this.wrapped = wrapped; - } - - /** - * Get the original InputFile instance wrapped inside. - * - * @return original InputFile instance - */ - public InputFile wrapped() { - return wrapped; - } - - public Path path() { - return wrapped.path(); - } - - @Override - public String fileName() { - return path().getFileName().toString(); - } - - public String absolutePath() { - return wrapped.absolutePath(); - } - - @Override - public String relativePath() { - return wrapped.relativePath(); - } - - @Override - public String contents() { - try { - return wrapped.contents(); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - public File file() { - return wrapped.file(); - } - - public TextPointer newPointer(int line, int lineOffset) { - return wrapped.newPointer(line, lineOffset); - } - - public TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset) { - return wrapped.newRange(startLine, startLineOffset, endLine, endLineOffset); - } - - public TextRange selectLine(int line) { - return wrapped.selectLine(line); - } - - public Charset charset() { - return wrapped.charset(); - } - -} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/compat/InputFileV56Compat.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/compat/InputFileV56Compat.java deleted file mode 100644 index 7bea8ad1..00000000 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/compat/InputFileV56Compat.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.compat; - -import java.nio.charset.Charset; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.sensor.SensorContext; - -/** - * Makes the wrapped API 5.6+ InputFile instance compatible with API 6.0, - * by providing the charset() method. - */ -class InputFileV56Compat extends InputFileV60Compat { - - private final Charset charset; - - InputFileV56Compat(InputFile wrapped, SensorContext context) { - super(wrapped); - this.charset = context.fileSystem().encoding(); - } - - @Override - public Charset charset() { - return charset; - } -} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/compat/InputFileV60Compat.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/compat/InputFileV60Compat.java deleted file mode 100644 index 8af2de39..00000000 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/compat/InputFileV60Compat.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.compat; - -import java.io.IOException; -import java.nio.file.Files; -import org.sonar.api.batch.fs.InputFile; - -/** - * Makes the wrapped API 6.0+ InputFile instance compatible with API 6.2, - * by providing the inputStream() and contents() methods. - */ -class InputFileV60Compat extends CompatibleInputFile { - InputFileV60Compat(InputFile wrapped) { - super(wrapped); - } - - @Override - public String contents() { - try { - return new String(Files.readAllBytes(this.path()), this.charset()); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } -} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/cpd/CpdVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/cpd/CpdVisitor.java new file mode 100644 index 00000000..5fc5ae48 --- /dev/null +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/cpd/CpdVisitor.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.cpd; + +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.EsqlFileImpl; +import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitor; +import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; +import com.google.common.collect.ImmutableSet; +import java.util.Set; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.TextRange; +import org.sonar.api.batch.sensor.SensorContext; +import org.sonar.api.batch.sensor.cpd.NewCpdTokens; + +public class CpdVisitor extends SubscriptionVisitor { + + private final SensorContext sensorContext; + private InputFile inputFile; + private NewCpdTokens cpdTokens; + + public CpdVisitor(SensorContext sensorContext) { + this.sensorContext = sensorContext; + } + + @Override + public Set nodesToVisit() { + return ImmutableSet.of(Kind.TOKEN); + } + + @Override + public void visitFile(Tree scriptTree) { + inputFile = ((EsqlFileImpl) getContext().getEsqlFile()).inputFile(); + cpdTokens = sensorContext.newCpdTokens().onFile(inputFile); + super.visitFile(scriptTree); + } + + @Override + public void leaveFile(Tree scriptTree) { + super.leaveFile(scriptTree); + cpdTokens.save(); + } + + @Override + public void visitNode(Tree tree) { + if (((InternalSyntaxToken) tree).isEOF()) { + return; + } + + SyntaxToken token = (SyntaxToken) tree; + String text = token.text(); + + if ( text.startsWith("'") ) { + text = "LITERAL"; + } + + TextRange range = inputFile.newRange(token.line(), token.column(), token.endLine(), token.endColumn()); + cpdTokens.addToken(range, text); + } + +} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/highlighter/HighlightSymbolTableBuilder.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/highlighter/HighlightSymbolTableBuilder.java index f3e459f7..dc1649d1 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/highlighter/HighlightSymbolTableBuilder.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/highlighter/HighlightSymbolTableBuilder.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/main/java/com/exxeta/iss/sonar/esql/highlighter/HighlighterVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/highlighter/HighlighterVisitor.java index a432376e..4874c7ce 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/highlighter/HighlighterVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/highlighter/HighlighterVisitor.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,9 @@ */ package com.exxeta.iss.sonar.esql.highlighter; -import java.util.List; +import java.util.Set; +import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.highlighting.NewHighlighting; import org.sonar.api.batch.sensor.highlighting.TypeOfText; @@ -28,100 +29,95 @@ 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.visitors.EsqlFileImpl; import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitor; -import com.exxeta.iss.sonar.esql.compat.CompatibleInputFile; import com.exxeta.iss.sonar.esql.lexer.EsqlReservedKeyword; import com.exxeta.iss.sonar.esql.tree.impl.expression.LiteralTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; -import com.google.common.collect.ImmutableList; - -public class HighlighterVisitor extends SubscriptionVisitor{ - - private final SensorContext sensorContext; - private NewHighlighting highlighting; - - - public HighlighterVisitor(SensorContext sensorContext) { - this.sensorContext = sensorContext; - } - - @Override - public List nodesToVisit() { - return ImmutableList.builder() - .add( - Kind.NUMERIC_LITERAL, - Kind.STRING_LITERAL, - Kind.TOKEN) - .build(); - } - - @Override - public void visitFile(Tree scriptTree) { - highlighting = sensorContext.newHighlighting().onFile(((CompatibleInputFile) getContext().getEsqlFile()).wrapped()); - } - - @Override - public void leaveFile(Tree scriptTree) { - highlighting.save(); - } - - @Override - public void visitNode(Tree tree) { - SyntaxToken token = null; - TypeOfText code = null; - - if (tree.is(Kind.TOKEN)) { - highlightToken((InternalSyntaxToken) tree); - - } else if (tree.is(Kind.STRING_LITERAL)) { - token = ((LiteralTreeImpl) tree).token(); - code = TypeOfText.STRING; - - } else if (tree.is(Kind.NUMERIC_LITERAL)) { - token = ((LiteralTreeImpl) tree).token(); - code = TypeOfText.CONSTANT; - - } - - if (token != null) { - highlight(token, code); - } - } - - private void highlightToken(InternalSyntaxToken token) { - if (isKeyword(token.text())) { - highlight(token, TypeOfText.KEYWORD); - } - highlightComments(token); - } - - private void highlightComments(InternalSyntaxToken token) { - TypeOfText type; - for (SyntaxTrivia trivia : token.trivias()) { - if (trivia.text().startsWith("/**")) { - type = TypeOfText.STRUCTURED_COMMENT; - } else { - type = TypeOfText.COMMENT; - } - highlight(trivia, type); - } - } - - private void highlight(SyntaxToken token, TypeOfText type) { - highlighting.highlight(token.line(), token.column(), token.endLine(), token.endColumn(), type); - } - - private static boolean isKeyword(String text) { - for (String keyword : EsqlReservedKeyword.keywordValues()) { - if (keyword.equals(text)) { - return true; - } - } - for (String keyword : EsqlNonReservedKeyword.keywordValues()) { - if (keyword.equals(text)) { - return true; - } - } - return false; - } +import com.google.common.collect.ImmutableSet; + +public class HighlighterVisitor extends SubscriptionVisitor { + + private final SensorContext sensorContext; + private NewHighlighting highlighting; + + public HighlighterVisitor(SensorContext sensorContext) { + this.sensorContext = sensorContext; + } + + @Override + public Set nodesToVisit() { + return ImmutableSet.builder().add(Kind.NUMERIC_LITERAL, Kind.STRING_LITERAL, Kind.TOKEN).build(); + } + + @Override + public void visitFile(Tree scriptTree) { + InputFile inputFile = ((EsqlFileImpl) getContext().getEsqlFile()).inputFile(); + highlighting = sensorContext.newHighlighting().onFile(inputFile); + } + + @Override + public void leaveFile(Tree scriptTree) { + highlighting.save(); + } + + @Override + public void visitNode(Tree tree) { + SyntaxToken token = null; + TypeOfText code = null; + + if (tree.is(Kind.TOKEN)) { + highlightToken((InternalSyntaxToken) tree); + + } else if (tree.is(Kind.STRING_LITERAL)) { + token = ((LiteralTreeImpl) tree).token(); + code = TypeOfText.STRING; + + } else if (tree.is(Kind.NUMERIC_LITERAL)) { + token = ((LiteralTreeImpl) tree).token(); + code = TypeOfText.CONSTANT; + + } + + if (token != null) { + highlight(token, code); + } + } + + private void highlightToken(InternalSyntaxToken token) { + if (isKeyword(token.text())) { + highlight(token, TypeOfText.KEYWORD); + } + highlightComments(token); + } + + private void highlightComments(InternalSyntaxToken token) { + TypeOfText type; + for (SyntaxTrivia trivia : token.trivias()) { + if (trivia.text().startsWith("/**")) { + type = TypeOfText.STRUCTURED_COMMENT; + } else { + type = TypeOfText.COMMENT; + } + highlight(trivia, type); + } + } + + private void highlight(SyntaxToken token, TypeOfText type) { + highlighting.highlight(token.line(), token.column(), token.endLine(), token.endColumn(), type); + } + + private static boolean isKeyword(String text) { + for (String keyword : EsqlReservedKeyword.keywordValues()) { + if (keyword.equals(text)) { + return true; + } + } + for (String keyword : EsqlNonReservedKeyword.keywordValues()) { + if (keyword.equals(text)) { + return true; + } + } + return false; + } } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlLexer.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlLexer.java index 1598104a..ad389f2e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlLexer.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlLexer.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/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlPunctuator.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlPunctuator.java index f82b8ac1..bfe36f03 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlPunctuator.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlPunctuator.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/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlReservedKeyword.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlReservedKeyword.java index b9205ffc..62250ef2 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlReservedKeyword.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlReservedKeyword.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/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlTokenType.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlTokenType.java index 460d8cba..3a2d937a 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlTokenType.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/EsqlTokenType.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/main/java/com/exxeta/iss/sonar/esql/lexer/LexerState.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/LexerState.java index baebc65b..a48d4701 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/LexerState.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/lexer/LexerState.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/main/java/com/exxeta/iss/sonar/esql/metrics/CommentLineVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/CommentLineVisitor.java index 7f893c35..c15b35a2 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/CommentLineVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/CommentLineVisitor.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,16 +17,16 @@ */ package com.exxeta.iss.sonar.esql.metrics; +import java.util.Set; + 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.visitors.SubscriptionVisitor; import com.exxeta.iss.sonar.esql.tree.EsqlCommentAnalyser; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; -import java.util.List; -import java.util.Set; public class CommentLineVisitor extends SubscriptionVisitor { @@ -50,8 +50,8 @@ public CommentLineVisitor(Tree tree, boolean ignoreHeaderComments) { } @Override - public List nodesToVisit() { - return ImmutableList.of(Tree.Kind.TOKEN); + public Set nodesToVisit() { + return ImmutableSet.of(Tree.Kind.TOKEN); } @Override diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/ComplexityVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/ComplexityVisitor.java index 7082b2f2..9c9e9e68 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/ComplexityVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/ComplexityVisitor.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,81 +23,88 @@ 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.BinaryExpressionTree; -import com.exxeta.iss.sonar.esql.api.tree.statement.CaseStatementTree; 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.DeclareHandlerStatementTree; 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.WhenClauseTree; import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitor; - public class ComplexityVisitor extends DoubleDispatchVisitor { - private List complexityTrees; + private List complexityTrees; - public int getComplexity(Tree tree) { - return complexityTrees(tree).size(); - } + public int getComplexity(Tree tree) { + return complexityTrees(tree).size(); + } - public List complexityTrees(Tree tree) { - this.complexityTrees = new ArrayList<>(); - scan(tree); - return this.complexityTrees; - } + public List complexityTrees(Tree tree) { + this.complexityTrees = new ArrayList<>(); + scan(tree); + return this.complexityTrees; + } - @Override + @Override public void visitCreateFunctionStatement(CreateFunctionStatementTree tree) { add(tree.createKeyword()); super.visitCreateFunctionStatement(tree); } - - @Override + + @Override public void visitCreateProcedureStatement(CreateProcedureStatementTree tree) { add(tree.createKeyword()); super.visitCreateProcedureStatement(tree); } - - @Override + + @Override public void visitCreateModuleStatement(CreateModuleStatementTree tree) { add(tree.createKeyword()); super.visitCreateModuleStatement(tree); } - @Override - public void visitIfStatement(IfStatementTree tree) { - add(tree.ifKeyword()); - super.visitIfStatement(tree); - } - - @Override + @Override + public void visitIfStatement(IfStatementTree tree) { + add(tree.ifKeyword()); + super.visitIfStatement(tree); + } + + @Override public void visitRepeatStatement(RepeatStatementTree tree) { add(tree.repeatKeyword()); super.visitRepeatStatement(tree); } - @Override + + @Override public void visitLoopStatement(LoopStatementTree tree) { add(tree.loopKeyword()); super.visitLoopStatement(tree); } - @Override - public void visitCaseStatement(CaseStatementTree tree) { - add(tree.caseKeyword()); - super.visitCaseStatement(tree); + @Override + public void visitWhenClause(WhenClauseTree tree) { + add(tree.whenKeyword()); + super.visitWhenClause(tree); + } + + @Override + public void visitBinaryExpression(BinaryExpressionTree tree) { + if (tree.is(Kind.CONDITIONAL_AND, Kind.CONDITIONAL_OR)) { + add(tree.operator()); + } + super.visitBinaryExpression(tree); } - @Override - public void visitBinaryExpression(BinaryExpressionTree tree) { - if (tree.is(Kind.CONDITIONAL_AND, Kind.CONDITIONAL_OR)) { - add(tree.operator()); - } - super.visitBinaryExpression(tree); - } - - private void add(Tree tree) { - complexityTrees.add(tree); - } + @Override + public void visitDeclareHandlerStatement(DeclareHandlerStatementTree tree) { + add(tree.handlerKeyword()); + super.visitDeclareHandlerStatement(tree); + } + + private void add(Tree tree) { + complexityTrees.add(tree); + } } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/CounterVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/CounterVisitor.java index f56b61c2..b949ee26 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/CounterVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/CounterVisitor.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,9 +17,9 @@ */ package com.exxeta.iss.sonar.esql.metrics; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; +import java.util.HashSet; +import java.util.Set; import com.exxeta.iss.sonar.esql.api.tree.Tree; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; @@ -52,8 +52,9 @@ public CounterVisitor(Tree tree) { } @Override - public List nodesToVisit() { - List result = new ArrayList<>(); + public Set nodesToVisit() { + + Set result = new HashSet<>(); result.addAll(Arrays.asList(STATEMENT_NODES)); result.add(Kind.CREATE_FUNCTION_STATEMENT); result.add(Kind.CREATE_PROCEDURE_STATEMENT); diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/EsqlMetrics.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/EsqlMetrics.java index 51ae6d2b..4bc28164 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/EsqlMetrics.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/EsqlMetrics.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,8 +34,12 @@ public class EsqlMetrics implements Metrics { public static final Metric MODULES = new Metric.Builder(MODULES_KEY, "Modules", Metric.ValueType.INT) .setDescription("Modules").setDirection(Metric.DIRECTION_WORST).setQualitative(false) .setDomain(CoreMetrics.DOMAIN_SIZE).create(); + public static final String MODULE_COMPLEXITY_KEY = "moduleComplexity"; + public static final Metric MODULE_COMPLEXITY = new Metric.Builder(MODULE_COMPLEXITY_KEY, "Module Complexity", Metric.ValueType.INT) + .setDescription("Module Complexity").setDirection(Metric.DIRECTION_WORST).setQualitative(false) + .setDomain(CoreMetrics.DOMAIN_SIZE).create(); - private static final List metrics = Lists.newArrayList(PROCEDURES, MODULES); + private static final List metrics = Lists.newArrayList(PROCEDURES, MODULES, MODULE_COMPLEXITY); @Override public List getMetrics() { return metrics; diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/ExecutableLineVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/ExecutableLineVisitor.java index 5b5c5d55..be3f7130 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/ExecutableLineVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/ExecutableLineVisitor.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,6 @@ package com.exxeta.iss.sonar.esql.metrics; import java.util.HashSet; -import java.util.List; import java.util.Set; import com.exxeta.iss.sonar.esql.api.tree.Tree; @@ -27,7 +26,7 @@ import com.exxeta.iss.sonar.esql.api.tree.statement.DeclareStatementTree; import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitorCheck; import com.exxeta.iss.sonar.esql.tree.impl.EsqlTree; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; public class ExecutableLineVisitor extends SubscriptionVisitorCheck { @@ -38,9 +37,9 @@ public ExecutableLineVisitor(Tree tree) { } @Override - public List nodesToVisit() { + public Set nodesToVisit() { - return ImmutableList.of( + return ImmutableSet.of( Kind.IF_STATEMENT, Kind.DECLARE_STATEMENT, Kind.THE_FUNCTION, diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/LineVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/LineVisitor.java index 7de758fd..1fd827d2 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/LineVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/LineVisitor.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,15 +17,15 @@ */ package com.exxeta.iss.sonar.esql.metrics; +import java.util.Set; + 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.SubscriptionVisitor; import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; -import java.util.List; -import java.util.Set; /** * Visitor that computes the number of lines of code of a file. @@ -40,8 +40,8 @@ public LineVisitor(Tree tree) { } @Override - public List nodesToVisit() { - return ImmutableList.of(Kind.TOKEN); + public Set nodesToVisit() { + return ImmutableSet.of(Kind.TOKEN); } @Override diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/MetricsVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/MetricsVisitor.java index 84ac351d..335ec7fe 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/MetricsVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/MetricsVisitor.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,9 +18,7 @@ package com.exxeta.iss.sonar.esql.metrics; import java.io.Serializable; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; @@ -34,141 +32,129 @@ 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.visitors.EsqlFileImpl; import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitor; import com.exxeta.iss.sonar.esql.api.visitors.TreeVisitorContext; -import com.exxeta.iss.sonar.esql.compat.CompatibleInputFile; +import com.google.common.collect.ImmutableSet; public class MetricsVisitor extends SubscriptionVisitor { - private static final Number[] LIMITS_COMPLEXITY_FUNCTIONS = {1, 2, 4, 6, 8, 10, 12, 20, 30}; - private static final Number[] FILES_DISTRIB_BOTTOM_LIMITS = {0, 5, 10, 20, 30, 60, 90}; - - /* private static final Kind[] CLASS_NODES = { - Kind.CLASS_DECLARATION, - Kind.CLASS_EXPRESSION - };*/ - - private final SensorContext sensorContext; - private final boolean saveExecutableLines; - private InputFile inputFile; - private final Boolean ignoreHeaderComments; - private FileLinesContextFactory fileLinesContextFactory; - private Map> projectExecutableLines; - - private int moduleComplexity; - private int functionComplexity; - private RangeDistributionBuilder functionComplexityDistribution; - private RangeDistributionBuilder fileComplexityDistribution; - - public MetricsVisitor(SensorContext context, Boolean ignoreHeaderComments, FileLinesContextFactory fileLinesContextFactory, boolean saveExecutableLines) { - this.sensorContext = context; - this.ignoreHeaderComments = ignoreHeaderComments; - this.fileLinesContextFactory = fileLinesContextFactory; - this.projectExecutableLines = new HashMap<>(); - this.saveExecutableLines = saveExecutableLines; - } - - /** - * Returns executable lines of code for files in project - */ - public Map> executableLines() { - return projectExecutableLines; - } - - @Override - public List nodesToVisit() { - List result = new ArrayList<>(); - result.add(Kind.CREATE_MODULE_STATEMENT); - return result; - } - - @Override - public void leaveFile(Tree scriptTree) { - saveComplexityMetrics(getContext()); - saveCounterMetrics(getContext()); - saveLineMetrics(getContext()); - } - - @Override - public void visitNode(Tree tree) { - if (tree.is(Kind.CREATE_MODULE_STATEMENT)) { - moduleComplexity += new ComplexityVisitor().getComplexity(tree); - - } - } - - @Override - public void visitFile(Tree scriptTree) { - this.inputFile = ((CompatibleInputFile) getContext().getEsqlFile()).wrapped(); - init(); - } - - private void init() { - moduleComplexity = 0; - functionComplexityDistribution = new RangeDistributionBuilder(LIMITS_COMPLEXITY_FUNCTIONS); - fileComplexityDistribution = new RangeDistributionBuilder(FILES_DISTRIB_BOTTOM_LIMITS); - } - - private void saveCounterMetrics(TreeVisitorContext context) { - CounterVisitor counter = new CounterVisitor(context.getTopTree()); - saveMetricOnFile(CoreMetrics.FUNCTIONS, counter.getFunctionsNumber()); - saveMetricOnFile(CoreMetrics.STATEMENTS, counter.getStatementsNumber()); - saveMetricOnFile(EsqlMetrics.MODULES, counter.getModulesNumber()); - saveMetricOnFile(EsqlMetrics.PROCEDURES, counter.getProceduresNumber()); - } - - private void saveComplexityMetrics(TreeVisitorContext context) { - int fileComplexity = new ComplexityVisitor().getComplexity(context.getTopTree()); - - saveMetricOnFile(CoreMetrics.COMPLEXITY, fileComplexity); - saveMetricOnFile(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, functionComplexity); - - sensorContext.newMeasure() - .on(inputFile) - .forMetric(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION) - .withValue(functionComplexityDistribution.build()) - .save(); - - fileComplexityDistribution.add(fileComplexity); - - sensorContext.newMeasure() - .on(inputFile) - .forMetric(CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION) - .withValue(fileComplexityDistribution.build()) - .save(); - } - - private void saveLineMetrics(TreeVisitorContext context) { - LineVisitor lineVisitor = new LineVisitor(context.getTopTree()); - Set linesOfCode = lineVisitor.getLinesOfCode(); - - saveMetricOnFile(CoreMetrics.NCLOC, lineVisitor.getLinesOfCodeNumber()); - - CommentLineVisitor commentVisitor = new CommentLineVisitor(context.getTopTree(), ignoreHeaderComments); - Set commentLines = commentVisitor.getCommentLines(); - - saveMetricOnFile(CoreMetrics.COMMENT_LINES, commentVisitor.getCommentLineNumber()); - - FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(this.inputFile); - - linesOfCode.forEach(line -> fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, 1)); - commentLines.forEach(line -> fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, 1)); - - Set executableLines = new ExecutableLineVisitor(context.getTopTree()).getExecutableLines(); - projectExecutableLines.put(inputFile, executableLines); - - if (saveExecutableLines) { - executableLines.stream().forEach(line -> fileLinesContext.setIntValue(CoreMetrics.EXECUTABLE_LINES_DATA_KEY, line, 1)); - } - fileLinesContext.save(); - } - - private void saveMetricOnFile(Metric metric, T value) { - sensorContext.newMeasure() - .withValue(value) - .forMetric(metric) - .on(inputFile) - .save(); - } + private static final Number[] LIMITS_COMPLEXITY_FUNCTIONS = { 1, 2, 4, 6, 8, 10, 12, 20, 30 }; + private static final Number[] FILES_DISTRIB_BOTTOM_LIMITS = { 0, 5, 10, 20, 30, 60, 90 }; + + /* + * private static final Kind[] CLASS_NODES = { Kind.CLASS_DECLARATION, + * Kind.CLASS_EXPRESSION }; + */ + + private final SensorContext sensorContext; + private InputFile inputFile; + private final Boolean ignoreHeaderComments; + private FileLinesContextFactory fileLinesContextFactory; + private Map> projectExecutableLines; + + private int moduleComplexity; + private int functionComplexity; + private RangeDistributionBuilder functionComplexityDistribution; + private RangeDistributionBuilder fileComplexityDistribution; + + public MetricsVisitor(SensorContext context, Boolean ignoreHeaderComments, + FileLinesContextFactory fileLinesContextFactory) { + this.sensorContext = context; + this.ignoreHeaderComments = ignoreHeaderComments; + this.fileLinesContextFactory = fileLinesContextFactory; + this.projectExecutableLines = new HashMap<>(); + } + + /** + * Returns executable lines of code for files in project + */ + public Map> executableLines() { + return projectExecutableLines; + } + + @Override + public Set nodesToVisit() { + return ImmutableSet.of(Kind.CREATE_MODULE_STATEMENT); + } + + @Override + public void leaveFile(Tree scriptTree) { + saveComplexityMetrics(getContext()); + saveCounterMetrics(getContext()); + saveLineMetrics(getContext()); + } + + @Override + public void visitNode(Tree tree) { + if (tree.is(Kind.CREATE_MODULE_STATEMENT)) { + moduleComplexity += new ComplexityVisitor().getComplexity(tree); + + } + } + + @Override + public void visitFile(Tree scriptTree) { + this.inputFile = ((EsqlFileImpl) getContext().getEsqlFile()).inputFile(); + init(); + } + + private void init() { + moduleComplexity = 0; + functionComplexityDistribution = new RangeDistributionBuilder(LIMITS_COMPLEXITY_FUNCTIONS); + fileComplexityDistribution = new RangeDistributionBuilder(FILES_DISTRIB_BOTTOM_LIMITS); + } + + private void saveCounterMetrics(TreeVisitorContext context) { + CounterVisitor counter = new CounterVisitor(context.getTopTree()); + saveMetricOnFile(CoreMetrics.FUNCTIONS, counter.getFunctionsNumber()); + saveMetricOnFile(CoreMetrics.STATEMENTS, counter.getStatementsNumber()); + saveMetricOnFile(EsqlMetrics.MODULES, counter.getModulesNumber()); + saveMetricOnFile(EsqlMetrics.PROCEDURES, counter.getProceduresNumber()); + } + + private void saveComplexityMetrics(TreeVisitorContext context) { + int fileComplexity = new ComplexityVisitor().getComplexity(context.getTopTree()); + + saveMetricOnFile(CoreMetrics.COMPLEXITY, fileComplexity); + saveMetricOnFile(EsqlMetrics.MODULE_COMPLEXITY, moduleComplexity); + saveMetricOnFile(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, functionComplexity); + + sensorContext.newMeasure().on(inputFile).forMetric(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION) + .withValue(functionComplexityDistribution.build()).save(); + + fileComplexityDistribution.add(fileComplexity); + + sensorContext.newMeasure().on(inputFile).forMetric(CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION) + .withValue(fileComplexityDistribution.build()).save(); + } + + private void saveLineMetrics(TreeVisitorContext context) { + LineVisitor lineVisitor = new LineVisitor(context.getTopTree()); + Set linesOfCode = lineVisitor.getLinesOfCode(); + + saveMetricOnFile(CoreMetrics.NCLOC, lineVisitor.getLinesOfCodeNumber()); + + CommentLineVisitor commentVisitor = new CommentLineVisitor(context.getTopTree(), ignoreHeaderComments); + Set commentLines = commentVisitor.getCommentLines(); + + saveMetricOnFile(CoreMetrics.COMMENT_LINES, commentVisitor.getCommentLineNumber()); + + FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(this.inputFile); + + linesOfCode.forEach(line -> fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, 1)); + commentLines.forEach(line -> fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, 1)); + + Set executableLines = new ExecutableLineVisitor(context.getTopTree()).getExecutableLines(); + projectExecutableLines.put(inputFile, executableLines); + + executableLines.stream() + .forEach(line -> fileLinesContext.setIntValue(CoreMetrics.EXECUTABLE_LINES_DATA_KEY, line, 1)); + fileLinesContext.save(); + } + + private void saveMetricOnFile(Metric metric, T value) { + sensorContext.newMeasure().withValue(value).forMetric(metric).on(inputFile).save(); + } } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/NoSonarVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/NoSonarVisitor.java new file mode 100644 index 00000000..be72aee5 --- /dev/null +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/metrics/NoSonarVisitor.java @@ -0,0 +1,26 @@ +package com.exxeta.iss.sonar.esql.metrics; + +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.issue.NoSonarFilter; + +import com.exxeta.iss.sonar.esql.api.tree.ProgramTree; +import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitor; +import com.exxeta.iss.sonar.esql.api.visitors.EsqlFileImpl; + +public class NoSonarVisitor extends DoubleDispatchVisitor { + private final NoSonarFilter noSonarFilter; + private final boolean ignoreHeaderComments; + + public NoSonarVisitor(NoSonarFilter noSonarFilter, boolean ignoreHeaderComments) { + this.noSonarFilter = noSonarFilter; + this.ignoreHeaderComments = ignoreHeaderComments; + } + + @Override + public void visitProgram(ProgramTree tree) { + CommentLineVisitor commentVisitor = new CommentLineVisitor(tree, ignoreHeaderComments); + + InputFile inputFile = ((EsqlFileImpl) getContext().getEsqlFile()).inputFile(); + noSonarFilter.noSonarInFile(inputFile, commentVisitor.noSonarLines()); + } +} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlGrammar.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlGrammar.java index bf00833a..45557a39 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlGrammar.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlGrammar.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"); @@ -29,7 +29,6 @@ import com.exxeta.iss.sonar.esql.api.tree.ProgramTree; import com.exxeta.iss.sonar.esql.api.tree.RoutineDeclarationTree; import com.exxeta.iss.sonar.esql.api.tree.SchemaNameTree; -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.ExpressionTree; import com.exxeta.iss.sonar.esql.api.tree.expression.IdentifierTree; @@ -119,6 +118,7 @@ import com.exxeta.iss.sonar.esql.tree.impl.statement.MessageSourceTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.MoveStatementTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.NameClausesTreeImpl; +import com.exxeta.iss.sonar.esql.tree.impl.statement.NullableTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.ParameterTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.ParseClauseTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.PassthruStatementTreeImpl; @@ -224,8 +224,20 @@ public ParameterTreeImpl PARAMETER() { BINDING_IDENTIFIER(), b.optional(b.firstOf(b.token(EsqlNonReservedKeyword.NAME), b.token(EsqlNonReservedKeyword.NAMESPACE), f.newTuple8(b.optional(b.token(EsqlNonReservedKeyword.CONSTANT)), - DATA_TYPE()))))); + DATA_TYPE()))), + b.optional(NULLABLE()) + )); } + + public NullableTreeImpl NULLABLE() { + return b.nonterminal(Kind.NULLABLE).is(f.nullable( + b.firstOf( + b.token(EsqlNonReservedKeyword.NULLABLE), + f.newTuple1(b.token(EsqlNonReservedKeyword.NOT), b.token(EsqlNonReservedKeyword.NULL))) + )); + } + + public RoutineBodyTreeImpl ROUTINE_BODY() { return b.nonterminal(Kind.ROUTINE_BODY) @@ -770,11 +782,6 @@ public ExpressionTree RELATIONAL_EXPRESSION() { ), ADDITIVE_EXPRESSION())))); - /* - * b.firstOf("<", ">", "<=", ">=", b.sequence("IS", b.optional("NOT")), - * b.sequence(b.optional("NOT"), "LIKE")), b.firstOf(additiveExpression, - * subtractiveExpression)))) .skipIfOneChild(); - */ } @@ -864,7 +871,7 @@ public PathElementTreeImpl PATH_ELEMENT() { b.optional(INDEX()) ), - f.pathElement(INDEX()), + f.pathElement(b.optional(PATH_ELEMENT_TYPE()),INDEX()), f.pathElement(PATH_ELEMENT_TYPE()) ) )); @@ -887,7 +894,7 @@ public PathElementNamespaceTreeImpl PATH_ELEMENT_NAMESPACE(){ public PathElementNameTreeImpl PATH_ELEMENT_NAME(){ return b.nonterminal(Kind.PATH_ELEMENT_NAME) .is(f.pathElementName( - b.firstOf(b.token(EsqlLegacyGrammar.IDENTIFIER_NAME), + b.firstOf(IDENTIFIER_NAME(), f.newTriple3(b.token(EsqlPunctuator.LCURLYBRACE), CALL_EXPRESSION(), b.token(EsqlPunctuator.RCURLYBRACE)), b.token(EsqlPunctuator.STAR)) @@ -1192,7 +1199,7 @@ public CastFunctionTreeImpl CAST_FUNCTION(){ public CaseFunctionTreeImpl CASE_FUNCTION(){ return b.nonterminal(Kind.CASE_FUNCTION).is(f.caseFunction( - b.token(EsqlReservedKeyword.CASE), b.firstOf(b.oneOrMore(WHEN_CLAUSE_EXPRESSION()), f.newTuple111(CALL_EXPRESSION(), b.oneOrMore(WHEN_CLAUSE_EXPRESSION()))), + b.token(EsqlReservedKeyword.CASE), b.firstOf(b.oneOrMore(WHEN_CLAUSE_EXPRESSION()), f.newTuple111(EXPRESSION(), b.oneOrMore(WHEN_CLAUSE_EXPRESSION()))), b.optional(f.newTuple110(b.token(EsqlNonReservedKeyword.ELSE), EXPRESSION())), b.token(EsqlNonReservedKeyword.END) )); @@ -1263,7 +1270,7 @@ public PassthruFunctionTreeImpl PASSTHRU_FUNCTION(){ return b.nonterminal(Kind.PASSTHRU_FUNCTION).is(f.finishPassthruFunction( b.token(EsqlNonReservedKeyword.PASSTHRU), b.token(EsqlPunctuator.LPARENTHESIS), b.firstOf( - f.passthruNewSyntax(CALL_EXPRESSION(), b.optional(f.newTuple115(b.token(EsqlNonReservedKeyword.TO), FIELD_REFERENCE())), + f.passthruNewSyntax(EXPRESSION(), b.optional(f.newTuple115(b.token(EsqlNonReservedKeyword.TO), FIELD_REFERENCE())), b.optional(f.newTuple116(b.token(EsqlNonReservedKeyword.VALUES), ARGUMENT_CLAUSE()))), f.passthruOldSyntax(ARGUMENT_LIST()) ), diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlLegacyGrammar.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlLegacyGrammar.java index 2ef7c610..a0bc3526 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlLegacyGrammar.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlLegacyGrammar.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/main/java/com/exxeta/iss/sonar/esql/parser/EsqlNodeBuilder.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlNodeBuilder.java index b72ac61e..24957eab 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlNodeBuilder.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlNodeBuilder.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/main/java/com/exxeta/iss/sonar/esql/parser/EsqlParser.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlParser.java index 25df2e81..94760baf 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlParser.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlParser.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"); @@ -21,19 +21,25 @@ import java.nio.charset.Charset; import java.util.Iterator; +import org.sonar.sslr.grammar.GrammarRuleKey; + import com.exxeta.iss.sonar.esql.api.tree.Tree; import com.exxeta.iss.sonar.esql.tree.impl.EsqlTree; import com.sonar.sslr.api.typed.ActionParser; public final class EsqlParser extends ActionParser{ public EsqlParser() { + this(EsqlLegacyGrammar.PROGRAM); + } + + public EsqlParser(GrammarRuleKey rootRule) { super( Charset.defaultCharset(), EsqlLegacyGrammar.createGrammarBuilder(), EsqlGrammar.class, new TreeFactory(), new EsqlNodeBuilder(), - EsqlLegacyGrammar.PROGRAM); + rootRule); } @Override diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlParserBuilder.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlParserBuilder.java index 69926975..5a746b3d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlParserBuilder.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlParserBuilder.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,8 @@ */ package com.exxeta.iss.sonar.esql.parser; +import org.sonar.sslr.grammar.GrammarRuleKey; + import com.exxeta.iss.sonar.esql.api.tree.Tree; import com.sonar.sslr.api.typed.ActionParser; @@ -27,5 +29,9 @@ private EsqlParserBuilder() { public static ActionParser createParser() { return new EsqlParser(); } + + public static ActionParser createParser(GrammarRuleKey rootRule){ + return new EsqlParser(rootRule); + } } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/TreeFactory.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/TreeFactory.java index c81cb0b2..97c11109 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/TreeFactory.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/TreeFactory.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"); @@ -127,6 +127,7 @@ import com.exxeta.iss.sonar.esql.tree.impl.statement.MessageSourceTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.MoveStatementTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.NameClausesTreeImpl; +import com.exxeta.iss.sonar.esql.tree.impl.statement.NullableTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.ParameterTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.ParseClauseTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.PassthruStatementTreeImpl; @@ -1044,22 +1045,31 @@ public RoutineBodyTreeImpl routineBody(Tree firstOf) { } public ParameterTreeImpl parameter(Optional directionIndicator, IdentifierTree identifier, - Optional optional) { + Optional optional, Optional nullable) { if (optional.isPresent()) { if (optional.get() instanceof Tuple) { Tuple, DataTypeTreeImpl> t = (Tuple) optional.get(); return new ParameterTreeImpl(directionIndicator.isPresent() ? directionIndicator.get() : null, - identifier, t.first().isPresent() ? t.first().get() : null, t.second()); + identifier, t.first().isPresent() ? t.first().get() : null, t.second(), nullable.isPresent()?nullable.get():null); } else { return new ParameterTreeImpl(directionIndicator.isPresent() ? directionIndicator.get() : null, - identifier, (InternalSyntaxToken) optional.get()); + identifier, (InternalSyntaxToken) optional.get(), nullable.isPresent()?nullable.get():null); } } else { - return new ParameterTreeImpl(directionIndicator.isPresent() ? directionIndicator.get() : null, identifier); + return new ParameterTreeImpl(directionIndicator.isPresent() ? directionIndicator.get() : null, identifier, nullable.isPresent()?nullable.get():null); } } + public NullableTreeImpl nullable(Object object){ + if (object instanceof Tuple){ + Tuple tuple = (Tuple) object; + return new NullableTreeImpl(tuple.first(),tuple.second()); + } else { + return new NullableTreeImpl((InternalSyntaxToken) object); + } + } + public ReturnTypeTreeImpl returnType(InternalSyntaxToken returnsToken, DataTypeTreeImpl dataType, Optional nullIndicator) { @@ -1079,11 +1089,11 @@ public LanguageTreeImpl language(InternalSyntaxToken languageKeyword, InternalSy public CreateModuleStatementTreeImpl createModuleStatement(InternalSyntaxToken createKeyword, InternalSyntaxToken moduleType, InternalSyntaxToken moduleKeyword, IdentifierTree indentifier, - Optional> optional, InternalSyntaxToken endKeyword, InternalSyntaxToken moduleKeyword2, + Optional> statements, InternalSyntaxToken endKeyword, InternalSyntaxToken moduleKeyword2, InternalSyntaxToken semi) { - List moduleStatementsList = optionalList(optional); + return new CreateModuleStatementTreeImpl(createKeyword, moduleType, moduleKeyword, indentifier, - moduleStatementsList, endKeyword, moduleKeyword2); + statements(statements), endKeyword, moduleKeyword2); } public ResultSetTreeImpl resultSet(InternalSyntaxToken dynamicKeyword, InternalSyntaxToken resultKeyword, @@ -1307,8 +1317,11 @@ public PathElementTreeImpl pathElement(Optional type, O return pathElement; } - public PathElementTreeImpl pathElement(IndexTreeImpl index) { + public PathElementTreeImpl pathElement(Optional type, IndexTreeImpl index) { PathElementTreeImpl pathElement = new PathElementTreeImpl(); + if (type.isPresent()){ + pathElement.type(type.get()); + } pathElement.index(index); return pathElement; } @@ -1344,6 +1357,8 @@ public PathElementNameTreeImpl pathElementName(Object name){ if (name instanceof Triple) { Triple triple = (Triple) name; return new PathElementNameTreeImpl(triple.first(), triple.second(), triple.third()); + } else if(name instanceof IdentifierTreeImpl) { + return new PathElementNameTreeImpl((IdentifierTreeImpl)name); } else { return new PathElementNameTreeImpl((InternalSyntaxToken) name); } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/EsqlCommentAnalyser.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/EsqlCommentAnalyser.java index ccd80ad6..2d2671b2 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/EsqlCommentAnalyser.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/EsqlCommentAnalyser.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/main/java/com/exxeta/iss/sonar/esql/tree/Kinds.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/Kinds.java index 7336503b..6d978dff 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/Kinds.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/Kinds.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/main/java/com/exxeta/iss/sonar/esql/tree/SyntacticEquivalence.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/SyntacticEquivalence.java index f18cf854..7f2b3301 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/SyntacticEquivalence.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/SyntacticEquivalence.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"); @@ -101,12 +101,14 @@ protected static boolean areLeafsEquivalent(EsqlTree leftNode, EsqlTree rightNod } - public static ExpressionTree skipParentheses(ExpressionTree tree) { - if (tree.is(Tree.Kind.PARENTHESISED_EXPRESSION)) { - return skipParentheses(((ParenthesisedExpressionTree) tree).expression()); - } else { - return tree; - } - } + public static ExpressionTree skipParentheses(ExpressionTree tree) { + if (tree == null) { + return null; + } else if (tree.is(Tree.Kind.PARENTHESISED_EXPRESSION)) { + return skipParentheses(((ParenthesisedExpressionTree) tree).expression()); + } else { + return tree; + } + } } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/declaration/BindingElementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/declaration/BindingElementTree.java index bad2db03..5356122b 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/declaration/BindingElementTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/declaration/BindingElementTree.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/main/java/com/exxeta/iss/sonar/esql/tree/expression/LikeExpressionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/expression/LikeExpressionTreeImpl.java index 3d562f1d..8e7468eb 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/expression/LikeExpressionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/expression/LikeExpressionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/expression/LiteralTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/expression/LiteralTree.java index fd728682..6ba79711 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/expression/LiteralTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/expression/LiteralTree.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/EsqlTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/EsqlTree.java index 080848af..cd25accf 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/EsqlTree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/EsqlTree.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/SeparatedList.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/SeparatedList.java index 6a10d9a2..e44d8375 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/SeparatedList.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/SeparatedList.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/BrokerSchemaStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/BrokerSchemaStatementTreeImpl.java index bb1ba743..8fd4626f 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/BrokerSchemaStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/BrokerSchemaStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/DataTypeTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/DataTypeTreeImpl.java index db57a551..bf3df937 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/DataTypeTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/DataTypeTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/DecimalDataTypeTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/DecimalDataTypeTreeImpl.java index a44938a9..659869fb 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/DecimalDataTypeTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/DecimalDataTypeTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/EsqlContentsTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/EsqlContentsTreeImpl.java index 36b15dee..747bf8fe 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/EsqlContentsTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/EsqlContentsTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/FieldReferenceTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/FieldReferenceTreeImpl.java index f22ae791..0645a822 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/FieldReferenceTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/FieldReferenceTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/IndexTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/IndexTreeImpl.java index a436e500..9e8f49f2 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/IndexTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/IndexTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/IntervalDataTypeTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/IntervalDataTypeTreeImpl.java index bc0188ae..8845d7ce 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/IntervalDataTypeTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/IntervalDataTypeTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/IntervalQualifierTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/IntervalQualifierTreeImpl.java index d755bee9..39f03f88 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/IntervalQualifierTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/IntervalQualifierTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/NamespaceTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/NamespaceTreeImpl.java index cf55a881..b19b4fbb 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/NamespaceTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/NamespaceTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/ParameterListTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/ParameterListTreeImpl.java index ccbf44cf..7721e689 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/ParameterListTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/ParameterListTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathClauseTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathClauseTreeImpl.java index fbc4d056..44be88d3 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathClauseTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathClauseTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementNameTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementNameTreeImpl.java index 0fd49e4e..c56d5bac 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementNameTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementNameTreeImpl.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"); @@ -24,6 +24,7 @@ import com.exxeta.iss.sonar.esql.api.tree.expression.ExpressionTree; import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitor; import com.exxeta.iss.sonar.esql.tree.impl.EsqlTree; +import com.exxeta.iss.sonar.esql.tree.impl.expression.IdentifierTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; import com.google.common.collect.Iterators; @@ -31,7 +32,8 @@ public class PathElementNameTreeImpl extends EsqlTree implements PathElementName private InternalSyntaxToken nameCurlyOpen; private ExpressionTree nameExpression; private InternalSyntaxToken nameCurlyClose; - private InternalSyntaxToken name; + private IdentifierTreeImpl name; + private InternalSyntaxToken star; public PathElementNameTreeImpl(InternalSyntaxToken nameCurlyOpen, ExpressionTree nameExpression, InternalSyntaxToken nameCurlyClose) { @@ -41,9 +43,13 @@ public PathElementNameTreeImpl(InternalSyntaxToken nameCurlyOpen, ExpressionTree } - public PathElementNameTreeImpl(InternalSyntaxToken name) { + public PathElementNameTreeImpl(IdentifierTreeImpl name) { this.name = name; + } + public PathElementNameTreeImpl(InternalSyntaxToken star) { + this.star = star; + } @Override public InternalSyntaxToken nameCurlyOpen() { @@ -61,10 +67,15 @@ public InternalSyntaxToken nameCurlyClose() { } @Override - public InternalSyntaxToken name() { + public IdentifierTreeImpl name() { return name; } + @Override + public InternalSyntaxToken star() { + return star; + } + @Override public void accept(DoubleDispatchVisitor visitor) { visitor.visitPathElementName(this); @@ -77,7 +88,7 @@ public Kind getKind() { @Override public Iterator childrenIterator() { - return Iterators.forArray(nameCurlyOpen, nameExpression, nameCurlyClose, name); + return Iterators.forArray(nameCurlyOpen, nameExpression, nameCurlyClose, name, star); } } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementNamespaceTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementNamespaceTreeImpl.java index e7d52a18..11a21743 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementNamespaceTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementNamespaceTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementTreeImpl.java index 5c6bc31f..366eb7b3 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementTypeTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementTypeTreeImpl.java index f584f740..3d8f22dc 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementTypeTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/PathElementTypeTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/ProgramTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/ProgramTreeImpl.java index 1783f015..045f1019 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/ProgramTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/ProgramTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/SchemaNameTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/SchemaNameTreeImpl.java index 257a4894..7666076f 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/SchemaNameTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/declaration/SchemaNameTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/BetweenExpressionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/BetweenExpressionTreeImpl.java index d212ee53..2cdb580c 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/BetweenExpressionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/BetweenExpressionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/BinaryExpressionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/BinaryExpressionTreeImpl.java index baf4d2a2..04bd48c2 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/BinaryExpressionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/BinaryExpressionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/CallExpressionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/CallExpressionTreeImpl.java index 70b1bd26..902b3a5d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/CallExpressionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/CallExpressionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/IdentifierTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/IdentifierTreeImpl.java index aebbfb95..6e45a534 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/IdentifierTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/IdentifierTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/InExpressionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/InExpressionTreeImpl.java index 39c2061f..bcfaf1e3 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/InExpressionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/InExpressionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/IntervalExpressionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/IntervalExpressionTreeImpl.java index 9850da20..ef394352 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/IntervalExpressionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/IntervalExpressionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/IsExpressionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/IsExpressionTreeImpl.java index c68f590c..d4c25709 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/IsExpressionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/IsExpressionTreeImpl.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"); @@ -89,7 +89,7 @@ public void accept(DoubleDispatchVisitor visitor) { @Override public Kind getKind() { - return Kind.IN_EXPRESSION; + return Kind.IS_EXPRESSION; } @Override diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/LiteralTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/LiteralTreeImpl.java index d9b9ed6e..c6b8114e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/LiteralTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/LiteralTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/ParenthesisedExpressionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/ParenthesisedExpressionTreeImpl.java index 86c1b5dc..29bdf2ec 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/ParenthesisedExpressionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/ParenthesisedExpressionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/PrefixExpressionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/PrefixExpressionTreeImpl.java index a4241e0e..f6f5ab6b 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/PrefixExpressionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/expression/PrefixExpressionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/AliasedExpressionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/AliasedExpressionTreeImpl.java index ac79fe77..4f3f1987 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/AliasedExpressionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/AliasedExpressionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/AliasedFieldReferenceTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/AliasedFieldReferenceTreeImpl.java index 248a9f5e..725cf3a2 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/AliasedFieldReferenceTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/AliasedFieldReferenceTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/AsbitstreamFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/AsbitstreamFunctionTreeImpl.java index 667dc0fb..2619001b 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/AsbitstreamFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/AsbitstreamFunctionTreeImpl.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"); @@ -69,10 +69,8 @@ public AsbitstreamFunctionTreeImpl(InternalSyntaxToken asbitstreamKeyword, Inter if (parameters != null) { commaSeparated = parameters.get(0).first().is(EsqlPunctuator.COMMA); if (commaSeparated) { - if (parameters.size()>0){ - optionsSeparator = parameters.get(0).first(); - optionsExpression = parameters.get(0).second().isPresent()?parameters.get(0).second().get():null; - } + optionsSeparator = parameters.get(0).first(); + optionsExpression = parameters.get(0).second().isPresent()?parameters.get(0).second().get():null; if (parameters.size()>1){ encodingSeparator = parameters.get(1).first(); encodingExpression = parameters.get(1).second().isPresent()?parameters.get(1).second().get():null; diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/CaseFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/CaseFunctionTreeImpl.java index ee577dc3..f36d1ae3 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/CaseFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/CaseFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/CastFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/CastFunctionTreeImpl.java index c3674b42..5a44d301 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/CastFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/CastFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/ExtractFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/ExtractFunctionTreeImpl.java index d3b2a259..1f805193 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/ExtractFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/ExtractFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/ForFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/ForFunctionTreeImpl.java index bbe36b67..ed76df4f 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/ForFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/ForFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/FromClauseExpressionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/FromClauseExpressionTreeImpl.java index 2e84b8a3..85171431 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/FromClauseExpressionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/FromClauseExpressionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/ListConstructorFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/ListConstructorFunctionTreeImpl.java index 1e8f4bdd..e6c64af9 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/ListConstructorFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/ListConstructorFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/OverlayFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/OverlayFunctionTreeImpl.java index 890efd5a..806141a5 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/OverlayFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/OverlayFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/PassthruFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/PassthruFunctionTreeImpl.java index 35129f05..62ddc496 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/PassthruFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/PassthruFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/PositionFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/PositionFunctionTreeImpl.java index a18f0774..ef076fc7 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/PositionFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/PositionFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/RoundFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/RoundFunctionTreeImpl.java index 731cc86f..bdf9920d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/RoundFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/RoundFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/RowConstructorFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/RowConstructorFunctionTreeImpl.java index a27491b2..bb086cd9 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/RowConstructorFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/RowConstructorFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/SelectClauseTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/SelectClauseTreeImpl.java index 02b66324..f67930fa 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/SelectClauseTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/SelectClauseTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/SelectFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/SelectFunctionTreeImpl.java index ffe8a186..1c02644c 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/SelectFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/SelectFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/SubstringFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/SubstringFunctionTreeImpl.java index 9ae470dd..efa5df6f 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/SubstringFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/SubstringFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/TheFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/TheFunctionTreeImpl.java index 71d200bf..596e70b9 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/TheFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/TheFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/TrimFunctionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/TrimFunctionTreeImpl.java index ae18a4d8..91282edb 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/TrimFunctionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/TrimFunctionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/WhenClauseExpressionTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/WhenClauseExpressionTreeImpl.java index 2695cbca..744654d0 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/WhenClauseExpressionTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/WhenClauseExpressionTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/WhereClauseTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/WhereClauseTreeImpl.java index b35a98c5..106d5278 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/WhereClauseTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/function/WhereClauseTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/lexical/InternalSyntaxToken.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/lexical/InternalSyntaxToken.java index 274bca6d..a6e4a17f 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/lexical/InternalSyntaxToken.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/lexical/InternalSyntaxToken.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/lexical/InternalSyntaxTrivia.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/lexical/InternalSyntaxTrivia.java index 90dbc635..e2a61554 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/lexical/InternalSyntaxTrivia.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/lexical/InternalSyntaxTrivia.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/AttachStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/AttachStatementTreeImpl.java index 097b67eb..4eab0621 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/AttachStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/AttachStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/BeginEndStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/BeginEndStatementTreeImpl.java index a1411467..c8180b5c 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/BeginEndStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/BeginEndStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CallStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CallStatementTreeImpl.java index b3ca5c3a..798e42e0 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CallStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CallStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CaseStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CaseStatementTreeImpl.java index 0f6ba4da..858795d3 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CaseStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CaseStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ControlsTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ControlsTreeImpl.java index 6c656a72..06a6ec22 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ControlsTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ControlsTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateFunctionStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateFunctionStatementTreeImpl.java index 46328f86..d5c3daa0 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateFunctionStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateFunctionStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateModuleStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateModuleStatementTreeImpl.java index ce1e4781..b419fa5d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateModuleStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateModuleStatementTreeImpl.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,12 +18,11 @@ package com.exxeta.iss.sonar.esql.tree.impl.statement; import java.util.Iterator; -import java.util.List; import com.exxeta.iss.sonar.esql.api.tree.Tree; import com.exxeta.iss.sonar.esql.api.tree.expression.IdentifierTree; import com.exxeta.iss.sonar.esql.api.tree.statement.CreateModuleStatementTree; -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.visitors.DoubleDispatchVisitor; import com.exxeta.iss.sonar.esql.tree.impl.EsqlTree; import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; @@ -35,13 +34,13 @@ public class CreateModuleStatementTreeImpl extends EsqlTree implements CreateMod private final InternalSyntaxToken moduleType; private final InternalSyntaxToken moduleKeyword; private final IdentifierTree moduleName; - private final List moduleStatementsList; + private final StatementsTree moduleStatementsList; private final InternalSyntaxToken endKeyword; private final InternalSyntaxToken moduleKeyword2; public CreateModuleStatementTreeImpl(InternalSyntaxToken createKeyword, InternalSyntaxToken moduleType, InternalSyntaxToken moduleKeyword, IdentifierTree indentifier, - List moduleStatementsList, InternalSyntaxToken endKeyword, + StatementsTree moduleStatementsList, InternalSyntaxToken endKeyword, InternalSyntaxToken moduleKeyword2) { super(); this.createKeyword = createKeyword; @@ -74,7 +73,7 @@ public IdentifierTree moduleName() { } @Override - public List moduleStatementsList() { + public StatementsTree moduleStatementsList() { return moduleStatementsList; } @@ -95,8 +94,7 @@ public Kind getKind() { @Override public Iterator childrenIterator() { - return Iterators.concat(Iterators.forArray(createKeyword, moduleType, moduleKeyword, moduleName), - Iterators.forArray(moduleStatementsList.toArray(new StatementTree[moduleStatementsList.size()])), + return Iterators.concat(Iterators.forArray(createKeyword, moduleType, moduleKeyword, moduleName, moduleStatementsList), Iterators.forArray(endKeyword, moduleKeyword2)); } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateProcedureStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateProcedureStatementTreeImpl.java index dfa536e3..33fd6790 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateProcedureStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateProcedureStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateRoutineTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateRoutineTreeImpl.java index be8476c0..f7fd49d1 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateRoutineTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateRoutineTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateStatementTreeImpl.java index fa99ccd4..f72cb8d3 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CreateStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeclareHandlerStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeclareHandlerStatementTreeImpl.java index 772534a2..4b7af502 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeclareHandlerStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeclareHandlerStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeclareStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeclareStatementTreeImpl.java index b7eecfa3..4c790b33 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeclareStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeclareStatementTreeImpl.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"); @@ -95,7 +95,7 @@ public InternalSyntaxToken sharedExt() { @Override - public InternalSyntaxToken namesapce() { + public InternalSyntaxToken namespace() { return namesapce; } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeleteFromStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeleteFromStatementTreeImpl.java index bc93b5b9..fef0331a 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeleteFromStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeleteFromStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeleteStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeleteStatementTreeImpl.java index de7d126a..e202eb23 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeleteStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DeleteStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DetachStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DetachStatementTreeImpl.java index 8aa3b71c..71eed335 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DetachStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/DetachStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ElseClauseTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ElseClauseTreeImpl.java index 93fbb596..e091f8a6 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ElseClauseTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ElseClauseTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ElseifClauseTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ElseifClauseTreeImpl.java index 6207f8c0..a90783a5 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ElseifClauseTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ElseifClauseTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/EvalStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/EvalStatementTreeImpl.java index 6d3e8440..b88fd1a2 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/EvalStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/EvalStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ExternalRoutineBodyTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ExternalRoutineBodyTreeImpl.java index 8be45fbd..fff9518a 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ExternalRoutineBodyTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ExternalRoutineBodyTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ForStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ForStatementTreeImpl.java index ade2aa99..12851a3e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ForStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ForStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/FromClauseTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/FromClauseTreeImpl.java index 681c2633..302fbab3 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/FromClauseTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/FromClauseTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/IfStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/IfStatementTreeImpl.java index 9f622f2d..509ea478 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/IfStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/IfStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/InsertStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/InsertStatementTreeImpl.java index 8167901a..ee38482e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/InsertStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/InsertStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/IterateStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/IterateStatementTreeImpl.java index 33155b98..fa6cb3c7 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/IterateStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/IterateStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LabelTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LabelTreeImpl.java index dfcbf488..c8ff91dc 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LabelTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LabelTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LanguageTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LanguageTreeImpl.java index d971eb80..7a4b7e12 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LanguageTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LanguageTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LeaveStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LeaveStatementTreeImpl.java index 0253f153..2bf3ae80 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LeaveStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LeaveStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LogStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LogStatementTreeImpl.java index 0665ffb3..b6693d31 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LogStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LogStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LoopStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LoopStatementTreeImpl.java index 9e16b362..50e8cc65 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LoopStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/LoopStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/MessageSourceTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/MessageSourceTreeImpl.java index 9bc81772..9b4928d4 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/MessageSourceTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/MessageSourceTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/MoveStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/MoveStatementTreeImpl.java index 507b60d8..9e37f3a5 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/MoveStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/MoveStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/NameClausesTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/NameClausesTreeImpl.java index eb5c8fc7..60fb6dd4 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/NameClausesTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/NameClausesTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/NullableTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/NullableTreeImpl.java new file mode 100644 index 00000000..9ff58b08 --- /dev/null +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/NullableTreeImpl.java @@ -0,0 +1,64 @@ +package com.exxeta.iss.sonar.esql.tree.impl.statement; + +import java.util.Iterator; + +import com.exxeta.iss.sonar.esql.api.tree.Tree; +import com.exxeta.iss.sonar.esql.api.tree.statement.NullableTree; +import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitor; +import com.exxeta.iss.sonar.esql.tree.impl.EsqlTree; +import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; +import com.google.common.collect.Iterators; + +public class NullableTreeImpl extends EsqlTree implements NullableTree { + + private InternalSyntaxToken nullableKeyword; + private InternalSyntaxToken notKeyword; + private InternalSyntaxToken nullKeyword; + + + public NullableTreeImpl(InternalSyntaxToken nullableKeyword) { + this.nullableKeyword = nullableKeyword; + } + + + + public NullableTreeImpl(InternalSyntaxToken notKeyword, InternalSyntaxToken nullKeyword) { + super(); + this.notKeyword = notKeyword; + this.nullKeyword = nullKeyword; + } + + + + @Override + public void accept(DoubleDispatchVisitor visitor) { + visitor.visitNullable(this); + + } + + @Override + public InternalSyntaxToken nullableKeyword() { + return nullableKeyword; + } + + @Override + public InternalSyntaxToken notKeyword() { + return notKeyword; + } + + @Override + public InternalSyntaxToken nullKeyword() { + return nullKeyword; + } + + @Override + public Kind getKind() { + return Kind.NULLABLE; + } + + @Override + public Iterator childrenIterator() { + return Iterators.forArray(nullableKeyword, notKeyword, nullKeyword); + } + +} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ParameterTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ParameterTreeImpl.java index a2dc5ca9..17c7d152 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ParameterTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ParameterTreeImpl.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"); @@ -35,27 +35,31 @@ public class ParameterTreeImpl extends EsqlTree implements ParameterTree { private InternalSyntaxToken constantKeyword; private InternalSyntaxToken nameOrNamesapceKeyword; private DataTypeTreeImpl dataType; + private NullableTreeImpl nullable; - public ParameterTreeImpl(InternalSyntaxToken directionIndicator, IdentifierTree identifier) { + public ParameterTreeImpl(InternalSyntaxToken directionIndicator, IdentifierTree identifier, NullableTreeImpl nullable) { this.directionIndicator = directionIndicator; this.identifier = identifier; + this.nullable = nullable; } - public ParameterTreeImpl(InternalSyntaxToken directionIndicator, IdentifierTree identifier, InternalSyntaxToken nameOrNamesapceKeyword) { + public ParameterTreeImpl(InternalSyntaxToken directionIndicator, IdentifierTree identifier, InternalSyntaxToken nameOrNamesapceKeyword, NullableTreeImpl nullable) { this.directionIndicator = directionIndicator; this.identifier=identifier; this.nameOrNamesapceKeyword = nameOrNamesapceKeyword; + this.nullable = nullable; } public ParameterTreeImpl(InternalSyntaxToken directionIndicator, IdentifierTree identifier, - InternalSyntaxToken constantKeyword, DataTypeTreeImpl dataType) { + InternalSyntaxToken constantKeyword, DataTypeTreeImpl dataType, NullableTreeImpl nullable) { this.directionIndicator = directionIndicator; this.identifier = identifier; this.nameOrNamesapceKeyword = null; this.constantKeyword = constantKeyword; this.dataType = dataType; + this.nullable = nullable; } @@ -84,6 +88,11 @@ public InternalSyntaxToken nameOrNamesapceKeyword() { public DataTypeTreeImpl dataType() { return dataType; } + + @Override + public NullableTreeImpl nullable() { + return nullable; + } @Override public void accept(DoubleDispatchVisitor visitor) { @@ -98,7 +107,7 @@ public Kind getKind() { @Override public Iterator childrenIterator() { - return Iterators.forArray(directionIndicator, identifier, constantKeyword, nameOrNamesapceKeyword, dataType); + return Iterators.forArray(directionIndicator, identifier, constantKeyword, nameOrNamesapceKeyword, dataType, nullable); } } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ParseClauseTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ParseClauseTreeImpl.java index 114b04e3..2190ed70 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ParseClauseTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ParseClauseTreeImpl.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,7 @@ */ package com.exxeta.iss.sonar.esql.tree.impl.statement; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -29,7 +30,6 @@ import com.exxeta.iss.sonar.esql.parser.TreeFactory.Tuple; import com.exxeta.iss.sonar.esql.tree.impl.EsqlTree; import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; -import com.google.common.collect.Iterators; import com.sonar.sslr.api.typed.Optional; public class ParseClauseTreeImpl extends EsqlTree implements ParseClauseTree{ @@ -38,22 +38,9 @@ public class ParseClauseTreeImpl extends EsqlTree implements ParseClauseTree{ private InternalSyntaxToken openingParenthesis; private ExpressionTree expression; - private InternalSyntaxToken optionsSeparator; - private ExpressionTree optionsExpression; - private InternalSyntaxToken encodingSeparator; - private ExpressionTree encodingExpression; - private InternalSyntaxToken ccsidSeparator; - private ExpressionTree ccsidExpression; - private InternalSyntaxToken setSeparator; - private ExpressionTree setExpression; - private InternalSyntaxToken typeSeparator; - private ExpressionTree typeExpression; - private InternalSyntaxToken formatSeparator; - private ExpressionTree formatExpression; + private List>> parameters; private InternalSyntaxToken closingParenthesis; - private boolean commaSeparated; - public ParseClauseTreeImpl(InternalSyntaxToken parseKeyword, InternalSyntaxToken openingParenthesis, ExpressionTree expression, List>> parameters, InternalSyntaxToken closingParenthesis) { @@ -61,62 +48,7 @@ public ParseClauseTreeImpl(InternalSyntaxToken parseKeyword, InternalSyntaxToken this.parseKeyword = parseKeyword; this.openingParenthesis = openingParenthesis; this.expression=expression; - if (parameters != null) { - commaSeparated = parameters.get(0).first().is(EsqlPunctuator.COMMA); - if (commaSeparated) { - if (parameters.size()>0){ - optionsSeparator = parameters.get(0).first(); - optionsExpression = parameters.get(0).second().isPresent()?parameters.get(0).second().get():null; - } - if (parameters.size()>1){ - encodingSeparator = parameters.get(1).first(); - encodingExpression = parameters.get(1).second().isPresent()?parameters.get(1).second().get():null; - } - if (parameters.size()>2){ - ccsidSeparator = parameters.get(2).first(); - ccsidExpression = parameters.get(2).second().isPresent()?parameters.get(2).second().get():null; - } - if (parameters.size()>3){ - setSeparator = parameters.get(3).first(); - setExpression = parameters.get(3).second().isPresent()?parameters.get(3).second().get():null; - } - if (parameters.size()>4){ - typeSeparator = parameters.get(4).first(); - typeExpression = parameters.get(4).second().isPresent()?parameters.get(4).second().get():null; - } - if (parameters.size()>5){ - formatSeparator = parameters.get(5).first(); - formatExpression = parameters.get(5).second().isPresent()?parameters.get(5).second().get():null; - } - } else { - for (Tuple> tuple : parameters) { - if (tuple.first().is(EsqlNonReservedKeyword.OPTIONS)){ - optionsSeparator = tuple.first(); - optionsExpression = tuple.second().get(); - } - if (tuple.first().is(EsqlNonReservedKeyword.ENCODING)){ - encodingSeparator = tuple.first(); - encodingExpression = tuple.second().get(); - } - if (tuple.first().is(EsqlNonReservedKeyword.CCSID)){ - ccsidSeparator = tuple.first(); - ccsidExpression = tuple.second().get(); - } - if (tuple.first().is(EsqlNonReservedKeyword.SET)){ - setSeparator = tuple.first(); - setExpression = tuple.second().get(); - } - if (tuple.first().is(EsqlNonReservedKeyword.TYPE)){ - typeSeparator = tuple.first(); - typeExpression = tuple.second().get(); - } - if (tuple.first().is(EsqlNonReservedKeyword.FORMAT)){ - formatSeparator = tuple.first(); - formatExpression = tuple.second().get(); - } - } - } - } + this.parameters=parameters; this.closingParenthesis = closingParenthesis; } @Override @@ -134,76 +66,112 @@ public ExpressionTree expression() { @Override public InternalSyntaxToken optionsSeparator() { - return optionsSeparator; + return getSeparator(0, EsqlNonReservedKeyword.OPTIONS); } @Override public ExpressionTree optionsExpression() { - return optionsExpression; + return getExpression(0, EsqlNonReservedKeyword.OPTIONS); } @Override public InternalSyntaxToken encodingSeparator() { - return encodingSeparator; + return getSeparator(1, EsqlNonReservedKeyword.ENCODING); } @Override public ExpressionTree encodingExpression() { - return encodingExpression; + return getExpression(1, EsqlNonReservedKeyword.ENCODING); } @Override public InternalSyntaxToken ccsidSeparator() { - return ccsidSeparator; + return getSeparator(2, EsqlNonReservedKeyword.CCSID); } @Override public ExpressionTree ccsidExpression() { - return ccsidExpression; + return getExpression(2, EsqlNonReservedKeyword.CCSID); } @Override public InternalSyntaxToken setSeparator() { - return setSeparator; + return getSeparator(3, EsqlNonReservedKeyword.SET); } @Override public ExpressionTree setExpression() { - return setExpression; + return getExpression(3, EsqlNonReservedKeyword.SET); } @Override public InternalSyntaxToken typeSeparator() { - return typeSeparator; + return getSeparator(4, EsqlNonReservedKeyword.TYPE); } @Override public ExpressionTree typeExpression() { - return typeExpression; + return getExpression(4, EsqlNonReservedKeyword.TYPE); } @Override public InternalSyntaxToken formatSeparator() { - return formatSeparator; + return getSeparator(5, EsqlNonReservedKeyword.FORMAT); } @Override public ExpressionTree formatExpression() { - return formatExpression; + return getExpression(5, EsqlNonReservedKeyword.FORMAT); } + private InternalSyntaxToken getSeparator(int position, EsqlNonReservedKeyword keyword) { + if (isCommaSeparated()){ + if (parameters.size()>position){ + return parameters.get(position).first(); + } else { + return null; + } + } else { + for (Tuple> tuple : parameters){ + if (tuple.first().is(keyword)){ + return tuple.first(); + } + } + return null; + } + } + private ExpressionTree getExpression(int position, EsqlNonReservedKeyword keyword) { + if (isCommaSeparated()){ + if (parameters.size()>position){ + if (parameters.get(position).second().isPresent()){ + return parameters.get(position).second().get(); + } else { + return null; + } + } else { + return null; + } + } else { + for (Tuple> tuple : parameters){ + if (tuple.first().is(keyword) && tuple.second().isPresent()){ + return tuple.second().get(); + } + } + return null; + } + } public boolean isCommaSeparated() { - return commaSeparated; + return parameters!=null && !parameters.isEmpty() && parameters.get(0).first().is(EsqlPunctuator.COMMA); } @Override public InternalSyntaxToken closingParenthesis() { @@ -219,13 +187,20 @@ public Kind getKind() { } @Override public Iterator childrenIterator() { - return Iterators.forArray(parseKeyword, openingParenthesis, expression, - optionsSeparator, optionsExpression, - encodingSeparator, encodingExpression, - ccsidSeparator, ccsidExpression, - setSeparator, setExpression, - typeSeparator, typeExpression, - formatSeparator, formatExpression, closingParenthesis); + ArrayList children = new ArrayList<>(); + children.add(parseKeyword); + children.add(openingParenthesis); + children.add(expression); + if (parameters != null) { + for (Tuple> parameter : parameters) { + children.add(parameter.first()); + if (parameter.second().isPresent()) { + children.add(parameter.second().get()); + } + } + } + children.add(closingParenthesis); + return children.iterator(); } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/PassthruStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/PassthruStatementTreeImpl.java index 4d992ee0..1134624d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/PassthruStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/PassthruStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/PropagateStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/PropagateStatementTreeImpl.java index 70708ddf..a456db12 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/PropagateStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/PropagateStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RepeatClauseTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RepeatClauseTreeImpl.java index a56cef23..338645e8 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RepeatClauseTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RepeatClauseTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RepeatStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RepeatStatementTreeImpl.java index 0fcb7b14..6233153e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RepeatStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RepeatStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ResignalStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ResignalStatementTreeImpl.java index 09332b97..25788262 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ResignalStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ResignalStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ResultSetTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ResultSetTreeImpl.java index 4ebb02fc..5d641e07 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ResultSetTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ResultSetTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ReturnStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ReturnStatementTreeImpl.java index 55c0a8a0..5a8b6753 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ReturnStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ReturnStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ReturnTypeTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ReturnTypeTreeImpl.java index 60af17fd..146c1294 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ReturnTypeTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ReturnTypeTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RoutineBodyTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RoutineBodyTreeImpl.java index f268bfb7..77c23ed3 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RoutineBodyTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RoutineBodyTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SetColumnTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SetColumnTreeImpl.java index c23f4473..783eaeae 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SetColumnTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SetColumnTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SetStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SetStatementTreeImpl.java index be8c7564..e68c230e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SetStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SetStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SqlStateTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SqlStateTreeImpl.java index 6d52388c..028301b0 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SqlStateTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SqlStateTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/StatementsTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/StatementsTreeImpl.java index 6669d9aa..9b98ae1d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/StatementsTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/StatementsTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ThrowStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ThrowStatementTreeImpl.java index 0e585b13..4e1c3372 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ThrowStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ThrowStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/UpdateStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/UpdateStatementTreeImpl.java index ccaf03b7..f6fcb70f 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/UpdateStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/UpdateStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ValuesClauseTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ValuesClauseTreeImpl.java index 6700b2bf..c707a343 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ValuesClauseTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/ValuesClauseTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/WhenClauseTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/WhenClauseTreeImpl.java index 50e75a55..636c29d7 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/WhenClauseTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/WhenClauseTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/WhileStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/WhileStatementTreeImpl.java index dc1a6cd5..2d31b24a 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/WhileStatementTreeImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/WhileStatementTreeImpl.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/main/java/com/exxeta/iss/sonar/esql/tree/symbols/HoistedSymbolVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/HoistedSymbolVisitor.java index 2ee80f50..ebb2342e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/HoistedSymbolVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/HoistedSymbolVisitor.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/main/java/com/exxeta/iss/sonar/esql/tree/symbols/Scope.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/Scope.java index 8d1e7314..9f187c80 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/Scope.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/Scope.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/main/java/com/exxeta/iss/sonar/esql/tree/symbols/ScopeVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/ScopeVisitor.java index c899f6c7..af85e488 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/ScopeVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/ScopeVisitor.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/main/java/com/exxeta/iss/sonar/esql/tree/symbols/SymbolModelImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/SymbolModelImpl.java index de4029e5..ec00028e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/SymbolModelImpl.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/SymbolModelImpl.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"); @@ -24,7 +24,7 @@ import javax.annotation.Nullable; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import com.exxeta.iss.sonar.esql.api.symbols.Symbol; import com.exxeta.iss.sonar.esql.api.symbols.Symbol.Kind; @@ -32,7 +32,6 @@ import com.exxeta.iss.sonar.esql.api.symbols.SymbolModelBuilder; import com.exxeta.iss.sonar.esql.api.tree.Tree; import com.exxeta.iss.sonar.esql.api.visitors.TreeVisitorContext; -import com.exxeta.iss.sonar.esql.tree.symbols.SymbolVisitor; import com.exxeta.iss.sonar.esql.tree.symbols.type.TypeVisitor; public class SymbolModelImpl implements SymbolModel, SymbolModelBuilder { @@ -41,12 +40,12 @@ public class SymbolModelImpl implements SymbolModel, SymbolModelBuilder { private Set scopes = new HashSet<>(); private Scope globalScope; - public static void build(TreeVisitorContext context, @Nullable Settings settings) { + public static void build(TreeVisitorContext context, @Nullable Configuration configuration) { Map treeScopeMap = getScopes(context); new HoistedSymbolVisitor(treeScopeMap).scanTree(context); new SymbolVisitor(treeScopeMap).scanTree(context); - new TypeVisitor(settings).scanTree(context); + new TypeVisitor(configuration).scanTree(context); } private static Map getScopes(TreeVisitorContext context) { diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/SymbolVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/SymbolVisitor.java index df6efa49..d669a66d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/SymbolVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/SymbolVisitor.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,9 +34,7 @@ import com.google.common.collect.SetMultimap; /** - * This visitor creates new symbols for not hoisted variables (like class name) - * and implicitly declared variables (declared without keyword). Also it creates - * usages for all known symbols. + * This visitor creates usages for all known symbols. */ public class SymbolVisitor extends DoubleDispatchVisitor { @@ -79,15 +77,17 @@ public void visitDeclareStatement(DeclareStatementTree tree) { scan(identifier); declaredBlockScopeNames.put(currentScope, identifier.name()); } + super.visitDeclareStatement(tree); } @Override public void visitIdentifier(IdentifierTree tree) { - if (tree.is(Tree.Kind.IDENTIFIER_REFERENCE)) { + if (tree.is(Tree.Kind.IDENTIFIER_REFERENCE, Tree.Kind.PROPERTY_IDENTIFIER)) { addUsageFor(tree, Usage.Kind.READ); } + super.visitIdentifier(tree); } - + @Override public void visitBeginEndStatement(BeginEndStatementTree tree) { if (isScopeAlreadyEntered(tree)) { @@ -135,12 +135,4 @@ private boolean isScopeAlreadyEntered(BeginEndStatementTree tree) { return !treeScopeMap.containsKey(tree); } - private Scope getFunctionScope() { - Scope scope = currentScope; - while (scope.isBlock()) { - scope = scope.outer(); - } - return scope; - } - } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/Type.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/Type.java index 4a53666f..b6b166ea 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/Type.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/Type.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/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/FunctionType.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/FunctionType.java index 1f02fdd7..fc1af20f 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/FunctionType.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/FunctionType.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/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/PrimitiveOperations.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/PrimitiveOperations.java index fb5b3a70..3dc4b7cb 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/PrimitiveOperations.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/PrimitiveOperations.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/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/PrimitiveType.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/PrimitiveType.java index cb88e7b6..b2ab1c6e 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/PrimitiveType.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/PrimitiveType.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/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/ProcedureType.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/ProcedureType.java index e5699fbb..6428e5f5 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/ProcedureType.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/ProcedureType.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/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/RoutineType.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/RoutineType.java index 0cdc4fb3..4bd99c44 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/RoutineType.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/RoutineType.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/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/TypeVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/TypeVisitor.java index 5cea5e6f..4f319929 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/TypeVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/symbols/type/TypeVisitor.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,11 +18,10 @@ package com.exxeta.iss.sonar.esql.tree.symbols.type; import java.util.List; -import java.util.Optional; import javax.annotation.Nullable; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import com.exxeta.iss.sonar.esql.api.symbols.Symbol; import com.exxeta.iss.sonar.esql.api.symbols.Type; @@ -45,7 +44,7 @@ public class TypeVisitor extends DoubleDispatchVisitor { - public TypeVisitor(@Nullable Settings settings) { + public TypeVisitor( @Nullable Configuration configuration) { } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/visitors/CharsetAwareVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/visitors/CharsetAwareVisitor.java index 304a9fc1..856cd3c2 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/visitors/CharsetAwareVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/visitors/CharsetAwareVisitor.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/main/java/com/exxeta/iss/sonar/esql/utils/LiteralUtils.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/utils/LiteralUtils.java index 698a669f..41f82efc 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/utils/LiteralUtils.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/utils/LiteralUtils.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/CustomEsqlRulesDefinitionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/CustomEsqlRulesDefinitionTest.java index dd8568ef..c45860bc 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/CustomEsqlRulesDefinitionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/CustomEsqlRulesDefinitionTest.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/IssueTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/IssueTest.java index 99d89714..477e3617 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/IssueTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/IssueTest.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/TypeSetTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/TypeSetTest.java index fdd40bf4..95f8dd04 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/TypeSetTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/TypeSetTest.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/ArgumentListTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ArgumentListTest.java index 5f49ee1a..1f68aff0 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ArgumentListTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ArgumentListTest.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/CastFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CastFunctionTest.java deleted file mode 100644 index 83d4d229..00000000 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CastFunctionTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.api.tree; - -import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; - -import org.junit.Test; - -import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; - -public class CastFunctionTest { - - @Test - public void castFunction() { - assertThat(Kind.CAST_FUNCTION) - .matches("CAST(source AS DATE FORMAT pattern)") - .matches("CAST(7, 6, 5 AS DATE)") - .matches("CAST(7.4e0, 6.5e0, 5.6e0 AS DATE)") - .matches("CAST(3.1e0, 4.2e0, 5.3e0, 6.4e0, 7.5e0, 8.6789012e0 AS GMTTIMESTAMP)") - .matches("CAST ( 1 AS INTERVAL DAY )") - .matches("CAST ( 1 AS INTERVAL DAY CCSID 1208 ENCODING defaultEncoding DEFAULT 1)") - ; - } -} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CreateProcedureTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CreateProcedureTest.java index 191d17d5..a3cc3f5b 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CreateProcedureTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CreateProcedureTest.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"); @@ -53,6 +53,12 @@ public void modelTest() throws Exception{ assertEquals(tree.createKeyword().text(),"CREATE"); assertNotNull(tree.routineType()); assertNotNull(tree.identifier()); + assertNotNull(tree.identifier().name()); + assertNotNull(tree.identifier().toString()); + assertNotNull(tree.identifier().symbol()); + assertNull(tree.identifier().scope()); + + assertNotNull(tree.openingParenthesis()); assertNotNull(tree.parameterList()); assertNotNull(tree.closingParenthesis()); diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/tree/impl/CreateRoutineTreeImplTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CreateRoutineTreeImplTest.java similarity index 94% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/tree/impl/CreateRoutineTreeImplTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CreateRoutineTreeImplTest.java index 5afb3296..bf9e66a0 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/tree/impl/CreateRoutineTreeImplTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CreateRoutineTreeImplTest.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,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.exxeta.iss.sonar.esql.tree.impl; +package com.exxeta.iss.sonar.esql.api.tree; import static com.exxeta.iss.sonar.esql.utils.TestUtils.createContext; import static org.assertj.core.api.Assertions.assertThat; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/DataTypeTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/DataTypeTest.java index b0450667..dfa2b80e 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/DataTypeTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/DataTypeTest.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/FieldReferenceTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/FieldReferenceTest.java index 7b1f014d..8a2d78ed 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/FieldReferenceTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/FieldReferenceTest.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"); @@ -68,7 +68,7 @@ public void fielReference() { @Test public void model() throws Exception{ - FieldReferenceTree tree = parse("(XML.Element)NSpace1:Element1[<2].{nsexp()}:{nameexp()}.*:abc.:aaa", Kind.FIELD_REFERENCE); + FieldReferenceTree tree = parse("(XML.Element)NSpace1:Element1[<2].{nsexp()}:{nameexp()}.*:abc.:aaa.*", Kind.FIELD_REFERENCE); assertNotNull(tree); assertNotNull(tree.pathElement()); PathElementTree firstElement = tree.pathElement(); @@ -99,6 +99,7 @@ public void model() throws Exception{ assertNotNull(index.direction()); assertNotNull(index.index()); assertNotNull(index.closeBracket()); + assertNotNull(tree.pathElements().get(3).name().star()); } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/IdentifierTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/IdentifierTest.java index 09da3ca4..a3cf1b2f 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/IdentifierTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/IdentifierTest.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/KeywordTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/KeywordTest.java index 09656eb5..e7c46865 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/KeywordTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/KeywordTest.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/OverlayFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/OverlayFunctionTest.java deleted file mode 100644 index cb14e464..00000000 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/OverlayFunctionTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.api.tree; - -import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; - -import org.junit.Test; - -import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; - -public class OverlayFunctionTest { - - @Test - public void overlayFunction() { - assertThat(Kind.OVERLAY_FUNCTION) - .matches("OVERLAY ('ABCDEFGHIJ' PLACING '1234' FROM 4 FOR 3)"); - } - -} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/PositionFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/PositionFunctionTest.java deleted file mode 100644 index 76784fb0..00000000 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/PositionFunctionTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.api.tree; - -import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; - -import org.junit.Test; - -import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; - -public class PositionFunctionTest { - - @Test - public void positionFunction() { - assertThat(Kind.POSITION_FUNCTION) - .matches("POSITION('Village' IN 'Hursley Village')") - .matches("POSITION ('A' IN 'ABCABCABCABCABC' FROM 4)") - .matches("POSITION ('B' IN 'ABCABCABCABCABC' REPEAT 2)") - .matches("POSITION ('A' IN 'ABCABCABCABCABC' FROM 4 REPEAT 2)"); - } - -} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ReturnTypeTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ReturnTypeTest.java index 1c2fd354..be62c7f8 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ReturnTypeTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ReturnTypeTest.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/SpacingTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/SpacingTest.java index 39503fda..8b54ba5b 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/SpacingTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/SpacingTest.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/SubstringFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/SubstringFunctionTest.java deleted file mode 100644 index a7cecf19..00000000 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/SubstringFunctionTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.api.tree; - -import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; - -import org.junit.Test; - -import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; - -public class SubstringFunctionTest { - - @Test - public void substringFunction() { - assertThat(Kind.SUBSTRING_FUNCTION) - .matches("SUBSTRING('Hello World!' FROM 7 FOR 4)") - .matches("SUBSTRING('Hello World!' FROM 7)"); - } - -} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/SyntacticEquivalenceTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/SyntacticEquivalenceTest.java index 73b4167f..f7929db9 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/SyntacticEquivalenceTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/SyntacticEquivalenceTest.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,6 +18,7 @@ package com.exxeta.iss.sonar.esql.api.tree; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; import org.junit.Test; @@ -51,10 +52,10 @@ public void test() throws Exception { @Test public void test_equivalence_for_tree_list() throws Exception { - CallStatementTree tree1 = parse("CALL f(a, b, c) ;", Tree.Kind.CALL_STATEMENT); - CallStatementTree tree2 = parse("CALL f(a, b, c) ;", Tree.Kind.CALL_STATEMENT); - CallStatementTree tree3 = parse("CALL f(a, b) ;", Tree.Kind.CALL_STATEMENT); - CallStatementTree tree4 = parse("CALL f(a, b, b) ;", Tree.Kind.CALL_STATEMENT); + CallStatementTree tree1 = (CallStatementTree) parse("CALL f(a, b, c) ;", Tree.Kind.CALL_STATEMENT); + CallStatementTree tree2 = (CallStatementTree) parse("CALL f(a, b, c) ;", Tree.Kind.CALL_STATEMENT); + CallStatementTree tree3 = (CallStatementTree) parse("CALL f(a, b) ;", Tree.Kind.CALL_STATEMENT); + CallStatementTree tree4 = (CallStatementTree) parse("CALL f(a, b, b) ;", Tree.Kind.CALL_STATEMENT); assertThat(SyntacticEquivalence.areEquivalent(tree1.parameterList(), tree1.parameterList())).isTrue(); assertThat(SyntacticEquivalence.areEquivalent(tree1.parameterList(), tree2.parameterList())).isTrue(); @@ -65,8 +66,8 @@ public void test_equivalence_for_tree_list() throws Exception { @Test public void test_equivalence_for_empty_tree_list() throws Exception { - CallStatementTree tree1 = parse("CALL f() ;", Tree.Kind.CALL_STATEMENT); - CallStatementTree tree2 = parse("CALL f() ;", Tree.Kind.CALL_STATEMENT); + CallStatementTree tree1 = (CallStatementTree) parse("CALL f() ;", Tree.Kind.CALL_STATEMENT); + CallStatementTree tree2 = (CallStatementTree) parse("CALL f() ;", Tree.Kind.CALL_STATEMENT); assertThat(SyntacticEquivalence.areEquivalent(tree1.parameterList(), tree1.parameterList())).isFalse(); assertThat(SyntacticEquivalence.areEquivalent(tree1.parameterList(), tree2.parameterList())).isFalse(); @@ -83,10 +84,11 @@ public void test_equivalence_for_tokens() throws Exception { @Test public void test_skip_parenthesis() throws Exception { - IfStatementTree tree1 = parse("IF (TRUE) THEN END IF;", Tree.Kind.IF_STATEMENT); - IfStatementTree tree2 = parse("IF TRUE THEN END IF;", Tree.Kind.IF_STATEMENT); + IfStatementTree tree1 = (IfStatementTree) parse("IF (TRUE) THEN END IF;", Tree.Kind.IF_STATEMENT); + IfStatementTree tree2 = (IfStatementTree) parse("IF TRUE THEN END IF;", Tree.Kind.IF_STATEMENT); assertThat(SyntacticEquivalence.skipParentheses(tree1.condition()).is(Kind.BOOLEAN_LITERAL)).isTrue(); + assertNotNull(tree2); } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/BetweenExpressionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/BetweenExpressionTest.java similarity index 94% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/BetweenExpressionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/BetweenExpressionTest.java index 61fe2612..22479bff 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/BetweenExpressionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/BetweenExpressionTest.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,7 +15,7 @@ * 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.api.tree.expression; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/BinaryExpressionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/BinaryExpressionTest.java new file mode 100644 index 00000000..44fca250 --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/BinaryExpressionTest.java @@ -0,0 +1,99 @@ +package com.exxeta.iss.sonar.esql.api.tree.expression; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.sonar.sslr.grammar.GrammarRuleKey; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.parser.EsqlLegacyGrammar; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class BinaryExpressionTest extends EsqlTreeModelTest { + + @Test + public void conditional_or() throws Exception { + test_binary_expression("a OR b OR c", Kind.CONDITIONAL_OR, "OR"); + } + + @Test + public void conditional_and() throws Exception { + test_binary_expression("a AND b AND c", Kind.CONDITIONAL_AND, "AND"); + } + + @Test + public void equality_equal_to() throws Exception { + test_binary_expression("a = b = c", EsqlLegacyGrammar.equalityExpression, Kind.EQUAL_TO, "="); + } + + @Test + public void equality_not_equal_to() throws Exception { + test_binary_expression("a <> b <> c", EsqlLegacyGrammar.equalityExpression, Kind.NOT_EQUAL_TO, "<>"); + } + + @Test + public void relation_less_than() throws Exception { + test_binary_expression("a < b < c", EsqlLegacyGrammar.relationalExpression, Kind.LESS_THAN, "<"); + } + + @Test + public void relation_greater_than() throws Exception { + test_binary_expression("a > b > c", EsqlLegacyGrammar.relationalExpression, Kind.GREATER_THAN, ">"); + } + + @Test + public void relation_less_or_equal_to() throws Exception { + test_binary_expression("a <= b <= c", EsqlLegacyGrammar.relationalExpression, Kind.LESS_THAN_OR_EQUAL_TO, "<="); + } + + @Test + public void relation_greater_or_equal_to() throws Exception { + test_binary_expression("a >= b >= c", EsqlLegacyGrammar.relationalExpression, Kind.GREATER_THAN_OR_EQUAL_TO, + ">="); + } + + @Test + public void additive_plus() throws Exception { + test_binary_expression("a + b + c", EsqlLegacyGrammar.additiveExpression, Kind.PLUS, "+"); + } + + @Test + public void additive_minus() throws Exception { + test_binary_expression("a - b - c", EsqlLegacyGrammar.additiveExpression, Kind.MINUS, "-"); + } + + @Test + public void multiplicative_multiply() throws Exception { + test_binary_expression("a * b * c", EsqlLegacyGrammar.multiplicativeExpression, Kind.MULTIPLY, "*"); + } + + @Test + public void multiplicative_divide() throws Exception { + test_binary_expression("a / b / c", EsqlLegacyGrammar.multiplicativeExpression, Kind.DIVIDE, "/"); + } + + @Test + public void additive_concat() throws Exception { + test_binary_expression("a || b || c", EsqlLegacyGrammar.additiveExpression, Kind.CONCAT, "||"); + } + + private void test_binary_expression(String str, Kind kind, String operator) throws Exception { + test_binary_expression(str, kind, kind, operator); + } + + private void test_binary_expression(String str, GrammarRuleKey rule, Kind kind, String operator) throws Exception { + BinaryExpressionTree tree = parse(str, rule, kind); + + assertThat(tree.is(kind)).isTrue(); + assertThat(tree.leftOperand()).isNotNull(); + assertThat(tree.operator().text()).isEqualTo(operator); + assertThat(tree.rightOperand()).isNotNull(); + + tree = (BinaryExpressionTree) tree.leftOperand(); + + assertThat(tree.is(kind)).isTrue(); + assertThat(tree.leftOperand()).isNotNull(); + assertThat(tree.operator().text()).isEqualTo(operator); + assertThat(tree.rightOperand()).isNotNull(); + } +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/CallExpressionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/CallExpressionTest.java new file mode 100644 index 00000000..19f6b0b6 --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/CallExpressionTest.java @@ -0,0 +1,23 @@ +package com.exxeta.iss.sonar.esql.api.tree.expression; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class CallExpressionTest extends EsqlTreeModelTest { + @Test + public void test() throws Exception { + CallExpressionTree tree = parse("a(b,c,d,e)", Kind.CALL_EXPRESSION); + + assertThat(tree.is(Kind.CALL_EXPRESSION)).isTrue(); + assertThat(tree.function()).isNull(); + assertThat(tree.functionName()).isNotNull(); + assertThat(tree.parameters()).isNotNull(); + assertThat(tree.parameters().openParenthesis().text()).isEqualTo("("); + assertThat(tree.parameters().parameters().size()).isEqualTo(4); + assertThat(tree.parameters().closeParenthesis().text()).isEqualTo(")"); + } +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ExpressionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/ExpressionTest.java similarity index 89% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ExpressionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/ExpressionTest.java index 46f80cf6..66cad095 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ExpressionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/ExpressionTest.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,7 +15,7 @@ * 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.api.tree.expression; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/InExpressionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/InExpressionTest.java similarity index 94% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/InExpressionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/InExpressionTest.java index 750e4e7a..a40c1720 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/InExpressionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/InExpressionTest.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,7 +15,7 @@ * 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.api.tree.expression; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/IntervalExpressionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/IntervalExpressionTest.java new file mode 100644 index 00000000..8a4ca2fb --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/IntervalExpressionTest.java @@ -0,0 +1,23 @@ +package com.exxeta.iss.sonar.esql.api.tree.expression; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class IntervalExpressionTest extends EsqlTreeModelTest { + @Test + public void test() throws Exception { + IntervalExpressionTree tree = parse("(CURRENT_GMTTIME - InputRoot.MQMD.PutTime) MINUTE TO SECOND", Kind.INTERVAL_EXPRESSION); + + assertThat(tree.is(Kind.INTERVAL_EXPRESSION)).isTrue(); + assertThat(tree.openParenToken().text()).isEqualTo("("); + assertThat(tree.additiveExpression()).isNotNull(); + assertThat(tree.closeParenToken().text()).isEqualTo(")"); + assertThat(tree.intervalQualifier().from()).isNotNull(); + assertThat(tree.intervalQualifier().toKeyword().text()).isEqualTo("TO"); + assertThat(tree.intervalQualifier().to()).isNotNull(); + } +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/IsExpressionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/IsExpressionTest.java similarity index 60% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/IsExpressionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/IsExpressionTest.java index e90a8d58..f728b475 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/IsExpressionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/IsExpressionTest.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,15 +15,18 @@ * 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.api.tree.expression; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class IsExpressionTest { +public class IsExpressionTest extends EsqlTreeModelTest{ @Test public void expression() { @@ -36,4 +39,15 @@ public void expression() { ; } + @Test + public void modelTest() throws Exception { + IsExpressionTree tree = parse("a IS NULL", Kind.IS_EXPRESSION); + assertNotNull(tree); + assertNotNull(tree.expression()); + assertNotNull(tree.isKeyword()); + assertNull(tree.notKeyword()); + assertNull(tree.plusMinus()); + assertNotNull(tree.with()); + } + } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/LikeExpressionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/LikeExpressionTest.java similarity index 94% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/LikeExpressionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/LikeExpressionTest.java index 1c388134..7e0b12bb 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/LikeExpressionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/LikeExpressionTest.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,7 +15,7 @@ * 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.api.tree.expression; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/LiteralTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/LiteralTest.java similarity index 71% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/LiteralTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/LiteralTest.java index a7fd59a5..886e5808 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/LiteralTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/LiteralTest.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,16 +15,19 @@ * 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.api.tree.expression; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; import com.exxeta.iss.sonar.esql.parser.EsqlLegacyGrammar; +import com.exxeta.iss.sonar.esql.tree.expression.LiteralTree; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class LiteralTest { +public class LiteralTest extends EsqlTreeModelTest { @Test public void stringLiteral() { @@ -60,4 +63,14 @@ public void timestampLiteral(){ .notMatches("timestamp"); } + @Test + public void stringLiteralModelTest() throws Exception{ + LiteralTree tree = parse("'a'", Kind.STRING_LITERAL); + assertNotNull(tree); + assertNotNull(tree.token()); + assertNotNull(tree.value()); + assertNotNull(tree.toString()); + + } + } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/ParenthesisedExpressionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/ParenthesisedExpressionTest.java new file mode 100644 index 00000000..9a01899b --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/ParenthesisedExpressionTest.java @@ -0,0 +1,20 @@ +package com.exxeta.iss.sonar.esql.api.tree.expression; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class ParenthesisedExpressionTest extends EsqlTreeModelTest { + @Test + public void test() throws Exception { + ParenthesisedExpressionTree tree = parse("(a)", Kind.PARENTHESISED_EXPRESSION); + + assertThat(tree.is(Kind.PARENTHESISED_EXPRESSION)).isTrue(); + assertThat(tree.openParenthesis().text()).isEqualTo("("); + assertThat(tree.expression()).isNotNull(); + assertThat(tree.closeParenthesis().text()).isEqualTo(")"); + } +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/PrimaryExpressionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/PrimaryExpressionTest.java similarity index 89% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/PrimaryExpressionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/PrimaryExpressionTest.java index aa31be3f..fec6e4ff 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/PrimaryExpressionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/PrimaryExpressionTest.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,7 +15,7 @@ * 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.api.tree.expression; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/UnaryExpressionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/UnaryExpressionTest.java new file mode 100644 index 00000000..3f9ea9d1 --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/expression/UnaryExpressionTest.java @@ -0,0 +1,60 @@ +/* + * 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.api.tree.expression; + +import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.parser.EsqlLegacyGrammar; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class UnaryExpressionTest extends EsqlTreeModelTest{ + + @Test + public void plusPrefix() { + assertThat(EsqlLegacyGrammar.unaryExpression) + .matches("+10") + .matches("+1") + ; + } + @Test + public void minusPrefix() { + assertThat(EsqlLegacyGrammar.unaryExpression) + .matches("+10") + .matches("+1") + ; + } + @Test + public void notPrefix() { + assertThat(EsqlLegacyGrammar.unaryExpression) + .matches("NOT TRUE") + ; + } + + @Test + public void modelTest() throws Exception{ + UnaryExpressionTree tree = parse("+10", EsqlLegacyGrammar.unaryExpression, Kind.UNARY_PLUS); + assertNotNull(tree); + assertNotNull(tree.expression()); + assertNotNull(tree.operator()); + } + +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/AsbitstreamFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/AsbitstreamFunctionTest.java new file mode 100644 index 00000000..c4c0e64b --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/AsbitstreamFunctionTest.java @@ -0,0 +1,67 @@ +/* + * 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.api.tree.function; + +import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.AsbitstreamFunctionTree; +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class AsbitstreamFunctionTest extends EsqlTreeModelTest{ + + @Test + public void asbitstreamFunction() { + assertThat(Kind.ASBITSTREAM_FUNCTION) + .matches("ASBITSTREAM(cursor OPTIONS options ENCODING enc CCSID 1208 SET set TYPE type FORMAT format)") + .matches("ASBITSTREAM(cursor OPTIONS options CCSID 1208)") + .matches("ASBITSTREAM(Environment.Variables.MQRFH2.Data,,,,,,)") + .matches("ASBITSTREAM(Environment.Variables.MQRFH2.Data,,1208)") + .matches("ASBITSTREAM(Environment.Variables.MQRFH2.Data,enc,1208, set, type, format, options)") + .matches("ASBITSTREAM(Environment.Variables.MQRFH2.Data,enc)"); + } + + @Test + public void modelTest() throws Exception { + AsbitstreamFunctionTree tree = parse("ASBITSTREAM(cursor OPTIONS options CCSID 1208)", Kind.ASBITSTREAM_FUNCTION); + assertNotNull(tree.asbitstreamKeyword()); + + assertNotNull(tree.openingParenthesis()); + assertNotNull(tree.fieldReference()); + + assertNotNull(tree.optionsSeparator()); + assertNotNull(tree.optionsExpression()); + assertNull(tree.encodingSeparator()); + assertNull(tree.encodingExpression()); + assertNotNull(tree.ccsidSeparator()); + assertNotNull(tree.ccsidExpression()); + assertNull(tree.setSeparator()); + assertNull(tree.setExpression()); + assertNull(tree.typeSeparator()); + assertNull(tree.typeExpression()); + assertNull(tree.formatSeparator()); + assertNull(tree.formatExpression()); + + assertNotNull(tree.closingParenthesis()); + } + +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CaseFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/CaseFunctionTest.java similarity index 86% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CaseFunctionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/CaseFunctionTest.java index 71b726c8..35ef233d 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CaseFunctionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/CaseFunctionTest.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,7 +15,7 @@ * 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.api.tree.function; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; @@ -23,11 +23,10 @@ import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; -import com.exxeta.iss.sonar.esql.tree.impl.function.CaseFunctionTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.function.WhenClauseExpressionTreeImpl; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class CaseFunctionTest extends EsqlTreeModelTest { +public class CaseFunctionTest extends EsqlTreeModelTest { @Test public void whenClause() { @@ -43,12 +42,13 @@ public void caseStatement() { .matches("CASE " + "WHEN Month = '01' THEN 'January' " + "WHEN Month = '02' THEN 'February' " + "WHEN Month = '03' THEN 'March' " + "WHEN Month = '04' THEN 'April' " + "WHEN Month = '05' THEN 'May' " + "WHEN Month = '06' THEN 'June' " - + "ELSE 'Second half of year' " + "END"); + + "ELSE 'Second half of year' " + "END") + .matches("CASE field IN('1','2','3', '4', '5', '6') WHEN TRUE THEN REPLACE(field, '.',',') ELSE field END"); } @Test public void modelTest() throws Exception{ - CaseFunctionTreeImpl tree = parse("CASE CurrentMonth " + "WHEN '01' THEN 'January' " + "WHEN '02' THEN 'February' " + CaseFunctionTree tree = parse("CASE CurrentMonth " + "WHEN '01' THEN 'January' " + "WHEN '02' THEN 'February' " + "WHEN '03' THEN 'March' " + "WHEN '04' THEN 'April' " + "WHEN '05' THEN 'May' " + "WHEN '06' THEN 'June' " + "ELSE 'Second half of year' " + "END", Kind.CASE_FUNCTION); diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/CastFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/CastFunctionTest.java new file mode 100644 index 00000000..e230646c --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/CastFunctionTest.java @@ -0,0 +1,59 @@ +/* + * 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.api.tree.function; + +import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class CastFunctionTest extends EsqlTreeModelTest { + + @Test + public void castFunction() { + assertThat(Kind.CAST_FUNCTION).matches("CAST(source AS DATE FORMAT pattern)").matches("CAST(7, 6, 5 AS DATE)") + .matches("CAST(7.4e0, 6.5e0, 5.6e0 AS DATE)") + .matches("CAST(3.1e0, 4.2e0, 5.3e0, 6.4e0, 7.5e0, 8.6789012e0 AS GMTTIMESTAMP)") + .matches("CAST ( 1 AS INTERVAL DAY )") + .matches("CAST ( 1 AS INTERVAL DAY CCSID 1208 ENCODING defaultEncoding DEFAULT 1)"); + } + + @Test + public void modelTest() throws Exception { + CastFunctionTree tree = parse("CAST(source AS DATE FORMAT pattern)", Kind.CAST_FUNCTION); + + assertNotNull(tree.castKeyword()); + assertNotNull(tree.openingParenthesis()); + assertNotNull(tree.sourceExpressions()); + assertNotNull(tree.asKeyword()); + assertNotNull(tree.dataType()); + assertNull(tree.ccsidKeyword()); + assertNull(tree.ccsidExpression()); + assertNull(tree.encodingKeyword()); + assertNull(tree.encodingExpression()); + assertNotNull(tree.formatKeyword()); + assertNotNull(tree.formatExpression()); + assertNull(tree.defaultKeyword()); + assertNull(tree.defaultExpression()); + assertNotNull(tree.closingParenthesis()); + } +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CreateFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/CreateFunctionTest.java similarity index 95% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CreateFunctionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/CreateFunctionTest.java index 0351e5db..c1e4a946 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/CreateFunctionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/CreateFunctionTest.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,7 +15,7 @@ * 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.api.tree.function; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertEquals; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ExtractFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/ExtractFunctionTest.java similarity index 59% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ExtractFunctionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/ExtractFunctionTest.java index 033bcd8f..ad79d443 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ExtractFunctionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/ExtractFunctionTest.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,23 +15,36 @@ * 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.api.tree.function; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertTrue; import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class ExtractFunctionTest { +public class ExtractFunctionTest extends EsqlTreeModelTest{ @Test public void extractFunction(){ - //aaa assertThat(Kind.EXTRACT_FUNCTION) .matches("EXTRACT(YEAR FROM CURRENT_DATE)") .matches("EXTRACT (DAYS FROM DATE '2000-02-29')") .matches("EXTRACT (DAYOFYEAR FROM CURRENT_TIME)"); - + } + + + @Test + public void modelTest() throws Exception{ + ExtractFunctionTree tree = parse("EXTRACT(YEAR FROM CURRENT_DATE)", Kind.EXTRACT_FUNCTION); + + assertTrue(tree.extractKeyword()!=null); + assertTrue(tree.openingParenthesis()!=null); + assertTrue(tree.type()!=null); + assertTrue(tree.fromKeyword()!=null); + assertTrue(tree.sourceDate()!=null); + assertTrue(tree.closingParenthesis()!=null); } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ForFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/ForFunctionTest.java similarity index 83% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ForFunctionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/ForFunctionTest.java index 2bbba770..5af688e1 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ForFunctionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/ForFunctionTest.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,7 +15,7 @@ * 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.api.tree.function; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; @@ -23,10 +23,9 @@ import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; -import com.exxeta.iss.sonar.esql.tree.impl.function.ForFunctionTreeImpl; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class ForFunctionTest extends EsqlTreeModelTest{ +public class ForFunctionTest extends EsqlTreeModelTest{ @Test public void forFunction() { @@ -37,7 +36,7 @@ public void forFunction() { @Test public void modelTest() throws Exception{ - ForFunctionTreeImpl tree = parse("FOR ALL Body.Invoice.Purchases.\"Item\"[] AS I (I.Quantity <= 50)", Kind.FOR_FUNCTION); + ForFunctionTree tree = parse("FOR ALL Body.Invoice.Purchases.\"Item\"[] AS I (I.Quantity <= 50)", Kind.FOR_FUNCTION); assertNotNull(tree); diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ListConstructorFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/ListConstructorFunctionTest.java similarity index 93% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ListConstructorFunctionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/ListConstructorFunctionTest.java index d5c96c5c..2a81fada 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/ListConstructorFunctionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/ListConstructorFunctionTest.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,7 +15,7 @@ * 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.api.tree.function; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/OverlayFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/OverlayFunctionTest.java new file mode 100644 index 00000000..98ea2200 --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/OverlayFunctionTest.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.api.tree.function; + +import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.api.tree.function.OverlayFunctionTree; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class OverlayFunctionTest extends EsqlTreeModelTest{ + + @Test + public void overlayFunction() { + assertThat(Kind.OVERLAY_FUNCTION) + .matches("OVERLAY ('ABCDEFGHIJ' PLACING '1234' FROM 4 FOR 3)"); + } + + @Test + public void modelTest() throws Exception{ + OverlayFunctionTree tree = parse("OVERLAY ('ABCDEFGHIJ' PLACING '1234' FROM 4 FOR 3)", Kind.OVERLAY_FUNCTION); + assertNotNull(tree.overlayKeyword()); + assertNotNull(tree.openingParenthesis()); + assertNotNull(tree.sourceString()); + assertNotNull(tree.placingKeyword()); + assertNotNull(tree.sourceString2()); + assertNotNull(tree.fromKeyword()); + assertNotNull(tree.startPosition()); + assertNotNull(tree.forKeyword()); + assertNotNull(tree.stringLength()); + assertNotNull(tree.closingParenthesis()); + tree = parse("OVERLAY ('ABCDEFGHIJ' PLACING '1234' FROM 4 )", Kind.OVERLAY_FUNCTION); + assertNotNull(tree.overlayKeyword()); + assertNotNull(tree.openingParenthesis()); + assertNotNull(tree.sourceString()); + assertNotNull(tree.placingKeyword()); + assertNotNull(tree.sourceString2()); + assertNotNull(tree.fromKeyword()); + assertNotNull(tree.startPosition()); + assertNull(tree.forKeyword()); + assertNull(tree.stringLength()); + assertNotNull(tree.closingParenthesis()); + } + +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/PassthruFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/PassthruFunctionTest.java new file mode 100644 index 00000000..3b82ce69 --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/PassthruFunctionTest.java @@ -0,0 +1,67 @@ +/* + * 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.api.tree.function; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.api.tree.function.PassthruFunctionTree; +import com.exxeta.iss.sonar.esql.utils.Assertions; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class PassthruFunctionTest extends EsqlTreeModelTest{ + + + @Test + public void passthruStatement(){ + Assertions.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'))") + .matches("PASSTHRU('aaaaa' )") + .matches("PASSTHRU('a' || schema TO Database.{xyz})") + .matches(" PASSTHRU('SELECT column1,column2 FROM '||db_schema||'.table_name WHERE column3=? AND column4=?' VALUES('value1',value2))"); + + } + + @Test + public void modelTest() throws Exception{ + PassthruFunctionTree tree = parse("PASSTHRU('aaaaa' VALUES ('aaaa', 'bbbb'))", Kind.PASSTHRU_FUNCTION); + assertThat(tree.passthruKeyword()).isNotNull(); + assertThat(tree.openingParenthesis()).isNotNull(); + assertThat(tree.expression()).isNotNull(); + assertThat(tree.toKeyword()).isNull(); + assertThat(tree.databaseReference()).isNull(); + assertThat(tree.valuesKeyword()).isNotNull(); + assertThat(tree.values()).isNotNull(); + assertThat(tree.values().parameters()).isNotNull(); + assertThat(tree.values().parameters().isEmpty()).isFalse(); + assertThat(tree.values().parameters().contains(tree.values().parameters().get(0))).isTrue(); + assertThat(tree.values().parameters()).hasSize(2); + assertThat(tree.values().parameters().getSeparators()).isNotEmpty(); + assertThat(tree.values().parameters().getSeparator(0).text()).isEqualTo(","); + assertThat(tree.values().parameters().toArray()).isNotNull(); + + assertThat(tree.argumentList()).isNotNull(); + assertThat(tree.closingParenthesis()).isNotNull(); + + } + +} + \ No newline at end of file diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/PositionFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/PositionFunctionTest.java new file mode 100644 index 00000000..5bb9ac3f --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/PositionFunctionTest.java @@ -0,0 +1,54 @@ +/* + * 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.api.tree.function; + +import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class PositionFunctionTest extends EsqlTreeModelTest { + + @Test + public void positionFunction() { + assertThat(Kind.POSITION_FUNCTION).matches("POSITION('Village' IN 'Hursley Village')") + .matches("POSITION ('A' IN 'ABCABCABCABCABC' FROM 4)") + .matches("POSITION ('B' IN 'ABCABCABCABCABC' REPEAT 2)") + .matches("POSITION ('A' IN 'ABCABCABCABCABC' FROM 4 REPEAT 2)"); + } + + @Test + public void modelTest() throws Exception { + PositionFunctionTree tree = parse("POSITION ('A' IN 'ABCABCABCABCABC' FROM 4)", Kind.POSITION_FUNCTION); + assertNotNull(tree.positionKeyword()); + assertNotNull(tree.openingParenthesis()); + assertNotNull(tree.searchExpression()); + assertNotNull(tree.inKeyword()); + assertNotNull(tree.sourceExpression()); + assertNotNull(tree.fromKeyword()); + assertNotNull(tree.fromExpression()); + assertNull(tree.repeatKeyword()); + assertNull(tree.repeatExpression()); + assertNotNull(tree.closingParenthesis()); + } + +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/RoundFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/RoundFunctionTest.java similarity index 55% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/RoundFunctionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/RoundFunctionTest.java index 8c6325bd..389052b8 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/RoundFunctionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/RoundFunctionTest.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,15 +15,17 @@ * 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.api.tree.function; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class RoundFunctionTest { +public class RoundFunctionTest extends EsqlTreeModelTest{ @Test public void roundFunction() { @@ -32,5 +34,19 @@ public void roundFunction() { .matches("ROUND (1,1)") .matches("ROUND(5.5, 0 MODE ROUND_FLOOR)"); } + + @Test + public void modelTest() throws Exception{ + RoundFunctionTree tree = parse("ROUND(5.5, 0 MODE ROUND_FLOOR)", Kind.ROUND_FUNCTION); + + assertNotNull(tree.roundKeyword()); + assertNotNull(tree.openingParenthesis()); + assertNotNull(tree.sourceNumber()); + assertNotNull(tree.comma()); + assertNotNull(tree.precision()); + assertNotNull(tree.modeKeyword()); + assertNotNull(tree.roundingMode()); + assertNotNull(tree.closingParenthesis()); + } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/RowConstructorFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/RowConstructorFunctionTest.java similarity index 80% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/RowConstructorFunctionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/RowConstructorFunctionTest.java index 88d78cb8..3ad185e7 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/RowConstructorFunctionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/RowConstructorFunctionTest.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,7 +15,7 @@ * 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.api.tree.function; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; @@ -23,10 +23,9 @@ import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; -import com.exxeta.iss.sonar.esql.tree.impl.function.RowConstructorFunctionTreeImpl; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class RowConstructorFunctionTest extends EsqlTreeModelTest{ +public class RowConstructorFunctionTest extends EsqlTreeModelTest{ @Test public void rowConstructorFunction() { @@ -38,7 +37,7 @@ public void rowConstructorFunction() { @Test public void modelTest() throws Exception{ - RowConstructorFunctionTreeImpl tree = parse ("ROW('granary' AS bread, 'riesling' AS wine, 'stilton' AS cheese)", Kind.ROW_CONSTRUCTOR_FUNCTION); + RowConstructorFunctionTree tree = parse ("ROW('granary' AS bread, 'riesling' AS wine, 'stilton' AS cheese)", Kind.ROW_CONSTRUCTOR_FUNCTION); assertNotNull(tree.rowKeyword()); assertNotNull(tree.openingParenthesis()); assertNotNull(tree.aliasedExpressions()); diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/SelectFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/SelectFunctionTest.java similarity index 91% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/SelectFunctionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/SelectFunctionTest.java index 81bf62bf..1184ad99 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/SelectFunctionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/SelectFunctionTest.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,7 +15,7 @@ * 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.api.tree.function; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertEquals; @@ -24,6 +24,7 @@ import org.junit.Test; +import com.exxeta.iss.sonar.esql.api.tree.FieldReferenceTree; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; import com.exxeta.iss.sonar.esql.api.tree.function.SelectFunctionTree; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; @@ -71,12 +72,13 @@ public void whereClause(){ public void modelTest() throws Exception{ SelectFunctionTree tree = parse("SELECT * FROM Database.Datasource.SchemaName.Table As A Where A.A>10", Kind.SELECT_FUNCTION); assertNotNull(tree); + assertNotNull(tree.selectKeyword()); assertNotNull(tree.selectClause()); assertNotNull(tree.fromClause()); assertNotNull(tree.whereClause()); assertTrue(tree.selectClause().aliasedFieldReferenceList().get(0).expression().is(Kind.FIELD_REFERENCE)); FieldReferenceTree field = (FieldReferenceTree)tree.selectClause().aliasedFieldReferenceList().get(0).expression(); - assertEquals(field.pathElement().name().name().text(),"*"); + assertEquals(field.pathElement().name().star().text(),"*"); } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/SubstringFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/SubstringFunctionTest.java new file mode 100644 index 00000000..9ae053d3 --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/SubstringFunctionTest.java @@ -0,0 +1,49 @@ +/* + * 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.api.tree.function; + +import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class SubstringFunctionTest extends EsqlTreeModelTest { + + @Test + public void substringFunction() { + assertThat(Kind.SUBSTRING_FUNCTION).matches("SUBSTRING('Hello World!' FROM 7 FOR 4)") + .matches("SUBSTRING('Hello World!' FROM 7)"); + } + + @Test + public void modelTest() throws Exception { + SubstringFunctionTree tree = parse("SUBSTRING('Hello World!' FROM 7 FOR 4)", Kind.SUBSTRING_FUNCTION); + assertNotNull(tree.substringKeyword()); + assertNotNull(tree.openingParenthesis()); + assertNotNull(tree.sourceExpression()); + assertNotNull(tree.qualifier()); + assertNotNull(tree.location()); + assertNotNull(tree.forKeyword()); + assertNotNull(tree.stringLength()); + assertNotNull(tree.closingParenthesis()); + } + +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/TheFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/TheFunctionTest.java similarity index 83% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/TheFunctionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/TheFunctionTest.java index eb3ec695..b7de9a18 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/TheFunctionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/TheFunctionTest.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,7 +15,7 @@ * 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.api.tree.function; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; @@ -23,10 +23,9 @@ import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; -import com.exxeta.iss.sonar.esql.tree.impl.function.TheFunctionTreeImpl; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class TheFunctionTest extends EsqlTreeModelTest { +public class TheFunctionTest extends EsqlTreeModelTest { @Test public void theFunction() { @@ -37,7 +36,7 @@ public void theFunction() { @Test public void modelTest() throws Exception { - TheFunctionTreeImpl tree = parse("THE (getList())", Kind.THE_FUNCTION); + TheFunctionTree tree = parse("THE (getList())", Kind.THE_FUNCTION); assertNotNull(tree); assertNotNull(tree.theKeyword()); diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/TrimFunctionTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/TrimFunctionTest.java similarity index 57% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/TrimFunctionTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/TrimFunctionTest.java index 6fe54ddb..700185b2 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/TrimFunctionTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/function/TrimFunctionTest.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,15 +15,17 @@ * 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.api.tree.function; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class TrimFunctionTest { +public class TrimFunctionTest extends EsqlTreeModelTest { @Test public void trimFunction() { @@ -33,4 +35,16 @@ public void trimFunction() { .matches("TRIM(LEADING FROM ' a ')"); } + @Test + public void modelTest() throws Exception{ + TrimFunctionTree tree = parse("TRIM(TRAILING 'b' FROM 'aaabBb')", Kind.TRIM_FUNCTION); + + assertNotNull(tree.trimKeyword()); + assertNotNull(tree.openingParenthesis()); + assertNotNull(tree.qualifier()); + assertNotNull(tree.trimSingleton()); + assertNotNull(tree.fromKeyword()); + assertNotNull(tree.sourceString()); + assertNotNull(tree.closingParenthesis()); + } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/AttachStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/AttachStatementTest.java similarity index 52% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/AttachStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/AttachStatementTest.java index 7dd3161d..c0651498 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/AttachStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/AttachStatementTest.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,15 +15,18 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.api.tree.statement.AttachStatementTree; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class AttachStatementTest { +public class AttachStatementTest extends EsqlTreeModelTest { @Test public void attachStatement(){ assertThat(Kind.ATTACH_STATEMENT) @@ -31,4 +34,23 @@ public void attachStatement(){ } + @Test + public void modelTest() throws Exception { + AttachStatementTree tree = parse("ATTACH ref1 TO OutputRoot.XMLNSC.Data.Order[2] AS LASTCHILD;", Kind.ATTACH_STATEMENT); + assertNotNull(tree); + + assertNotNull(tree.attachKeyword()); + + assertNotNull(tree.dynamicReference()); + + assertNotNull(tree.toKeyword()); + + assertNotNull(tree.fieldReference()); + + assertNotNull(tree.asKeyword()); + + assertNotNull(tree.location()); + + assertNotNull(tree.semi()); + } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/BeginEndStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/BeginEndStatementTest.java similarity index 81% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/BeginEndStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/BeginEndStatementTest.java index 5c086d35..76dcb6bf 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/BeginEndStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/BeginEndStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -24,14 +24,13 @@ import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; import com.exxeta.iss.sonar.esql.api.tree.statement.BeginEndStatementTree; -import com.exxeta.iss.sonar.esql.tree.impl.statement.BeginEndStatementTreeImpl; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; public class BeginEndStatementTest extends EsqlTreeModelTest { @Test public void modelTest() throws Exception { - BeginEndStatementTreeImpl tree = parse("BEGIN CALL A(); END;", Kind.BEGIN_END_STATEMENT); + BeginEndStatementTree tree = parse("BEGIN CALL A(); END;", Kind.BEGIN_END_STATEMENT); assertNotNull(tree.beginKeyword()); assertNotNull(tree.statements()); @@ -43,7 +42,7 @@ public void modelTest() throws Exception { @Test public void modelTestWithLabel() throws Exception { - BeginEndStatementTreeImpl tree = parse("A: BEGIN CALL A(); END A;", Kind.BEGIN_END_STATEMENT); + BeginEndStatementTree tree = parse("A: BEGIN CALL A(); END A;", Kind.BEGIN_END_STATEMENT); assertNotNull(tree.labelName1()); assertNotNull(tree.colon()); diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/CallStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/CallStatementTest.java similarity index 95% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/CallStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/CallStatementTest.java index 2ca7f9d4..e9cccbf5 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/CallStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/CallStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertEquals; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/CaseStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/CaseStatementTest.java similarity index 61% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/CaseStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/CaseStatementTest.java index dc863755..6a331170 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/CaseStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/CaseStatementTest.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,15 +15,19 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.api.tree.statement.CaseStatementTree; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class CaseStatementTest { +public class CaseStatementTest extends EsqlTreeModelTest{ @Test public void whenClause() { @@ -43,4 +47,20 @@ public void caseStatement() { + " CALL handleIZeroAndPositiveJ(j);\n" + " ELSE\n" + " CALL handleAllOtherCases(j);\n" + "END CASE;"); } + + @Test + public void modelTest() throws Exception{ + CaseStatementTree tree = parse("CASE" + " WHEN i <> 0 THEN\n" + " CALL handleI(i);\n" + " WHEN j> 1 THEN\n" + + " CALL handleIZeroAndPositiveJ(j);\n" + " ELSE\n" + " CALL handleAllOtherCases(j);\n" + + "END CASE;", Kind.CASE_STATEMENT); + + assertNotNull(tree.caseKeyword()); + assertNull(tree.mainExpression()); + assertNotNull(tree.whenClauses()); + assertNotNull(tree.elseKeyword()); + assertNotNull(tree.elseSatements()); + assertNotNull(tree.endKeyword()); + assertNotNull(tree.caseKeyword2()); + assertNotNull(tree.semi()); + } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/CreateStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateStatementTest.java similarity index 80% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/CreateStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateStatementTest.java index aa64634a..c36ff2fa 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/CreateStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/CreateStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertEquals; @@ -56,6 +56,7 @@ public void createStatement(){ .matches("CREATE LASTCHILD OF OutputRoot DOMAIN('MRM') PARSE(inBitStream ENCODING inEncoding CCSID inCCSID);") .matches("CREATE LASTCHILD OF OutputRoot DOMAIN('MRM') PARSE(inBitStream SET 'abc' TYPE 'TestCase' FORMAT 'XML1');") .matches("CREATE LASTCHILD OF OutputRoot DOMAIN('MRM') PARSE(inBitStream OPTIONS options);") + .matches("CREATE LASTCHILD OF OutputRoot DOMAIN ('SOAP') PARSE (InputLocalEnvironment.Variables.Pas.Request CCSID 1208 OPTIONS RootBitStream );") ; } @@ -158,5 +159,30 @@ public void modelTest() throws Exception { assertNotNull(valuesClause.value()); } + + @Test + public void modelTest2() throws Exception { + CreateStatementTreeImpl tree = parse("CREATE LASTCHILD OF OutputRoot DOMAIN('MRM') PARSE(inBitStream ENCODING inEncoding CCSID inCCSID SET 'DP3UK14002001' TYPE 'TestCase' FORMAT 'XML1' OPTIONS options);", Kind.CREATE_STATEMENT); + ParseClauseTreeImpl parseClause = tree.parseClause(); + assertNotNull(parseClause); + assertNotNull(parseClause.parseKeyword()); + assertEquals(parseClause.parseKeyword().text(), "PARSE"); + assertNotNull(parseClause.openingParenthesis()); + assertEquals(parseClause.openingParenthesis().text(), "("); + + assertNotNull(parseClause.expression()); + assertNotNull(parseClause.optionsSeparator()); + assertNotNull(parseClause.optionsExpression()); + assertNotNull(parseClause.encodingSeparator()); + assertNotNull(parseClause.encodingExpression()); + assertNotNull(parseClause.ccsidSeparator()); + assertNotNull(parseClause.ccsidExpression()); + assertNotNull(parseClause.setSeparator()); + assertNotNull(parseClause.setExpression()); + assertNotNull(parseClause.typeSeparator()); + assertNotNull(parseClause.typeExpression()); + assertNotNull(parseClause.formatSeparator()); + assertNotNull(parseClause.formatExpression()); + } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DeclareHandlerStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareHandlerStatementTest.java similarity index 95% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DeclareHandlerStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareHandlerStatementTest.java index 053f063d..1df2ca0f 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DeclareHandlerStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareHandlerStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DeclareStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareStatementTest.java similarity index 66% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DeclareStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareStatementTest.java index a5117c17..f211e6d8 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DeclareStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeclareStatementTest.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,8 +15,9 @@ * 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.api.tree.statement; +import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -24,19 +25,28 @@ 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.tree.impl.statement.DeclareStatementTreeImpl; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; public class DeclareStatementTest extends EsqlTreeModelTest{ + @Test + public void parserTest() { + assertThat(Kind.DECLARE_STATEMENT) + .matches("DECLARE aaa NAMESPACE 'com.exxeta.test';") + .matches("DECLARE Schema1 NAME 'Joe';") + .matches("DECLARE var CHARACTER CASE field IN('1','2','3', '4', '5', '6') WHEN TRUE THEN REPLACE(field, '.',',') ELSE field END;") + .matches("DECLARE a NAMESPACE FIELDNAMESPACE(InputRoot.XMLNSC.(XML.Element)[1]);"); + + } + @Test public void modelTest() throws Exception { - DeclareStatementTreeImpl tree = parse("DECLARE deployEnvironment EXTERNAL CHARACTER 'Dev';", Kind.DECLARE_STATEMENT); + DeclareStatementTree tree = parse("DECLARE deployEnvironment EXTERNAL CHARACTER 'Dev';", Kind.DECLARE_STATEMENT); assertNotNull(tree.declareToken()); assertNotNull(tree.nameList()); assertNotNull(tree.sharedExt()); - assertNull(tree.namesapce()); + assertNull(tree.namespace()); assertNull(tree.constantKeyword()); assertNotNull(tree.dataType()); assertNotNull(tree.initialValueExpression()); diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteFromStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteFromStatementTest.java new file mode 100644 index 00000000..1f89828a --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteFromStatementTest.java @@ -0,0 +1,53 @@ +/* + * 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.api.tree.statement; + +import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.api.tree.statement.DeleteFromStatementTree; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class DeleteFromStatementTest extends EsqlTreeModelTest{ + + + @Test + public void deleteFromStatement(){ + assertThat(Kind.DELETE_FROM_STATEMENT) + .matches("DELETE FROM Database.SHAREHOLDINGS AS S WHERE S.ACCOUNTNO = InputBody.AccountNumber;"); + + } + + @Test + public void modelTest() throws Exception{ + DeleteFromStatementTree tree = parse("DELETE FROM Database.SHAREHOLDINGS AS S WHERE S.ACCOUNTNO = InputBody.AccountNumber;", Kind.DELETE_FROM_STATEMENT); + assertNotNull(tree.deleteKeyword()); + assertNotNull(tree.fromKeyword()); + assertNotNull(tree.tableReference()); + assertNotNull(tree.asKeyword()); + assertNotNull(tree.asCorrelationName()); + assertNotNull(tree.whereKeyword()); + assertNotNull(tree.whereExpression()); + assertNotNull(tree.semi()); + + } + +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DeleteStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteStatementTest.java similarity index 58% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DeleteStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteStatementTest.java index c7e16f49..170bdfe2 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DeleteStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DeleteStatementTest.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,15 +15,18 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.api.tree.statement.DeleteStatementTree; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class DeleteStatementTest { +public class DeleteStatementTest extends EsqlTreeModelTest { @Test public void deleteStatement() { @@ -32,4 +35,14 @@ public void deleteStatement() { .matches("DELETE LASTCHILD OF Cursor;"); } + @Test + public void modelTest() throws Exception{ + DeleteStatementTree tree = parse("DELETE LASTCHILD OF Cursor;", Kind.DELETE_STATEMENT); + assertNotNull(tree.deleteKeyword()); + assertNotNull(tree.qualifier()); + assertNotNull(tree.ofKeyword()); + assertNotNull(tree.fieldReference()); + assertNotNull(tree.semi()); + } + } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DetachStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DetachStatementTest.java similarity index 89% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DetachStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DetachStatementTest.java index 65359682..0c260d14 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/DetachStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/DetachStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/EvalStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/EvalStatementTest.java similarity index 56% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/EvalStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/EvalStatementTest.java index 38adf3b8..e779e485 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/EvalStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/EvalStatementTest.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,15 +15,18 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.api.tree.statement.EvalStatementTree; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class EvalStatementTest { +public class EvalStatementTest extends EsqlTreeModelTest { @Test public void evalStatement(){ assertThat(Kind.EVAL_STATEMENT) @@ -31,4 +34,14 @@ public void evalStatement(){ } + @Test + public void modelTest() throws Exception{ + EvalStatementTree tree = parse("EVAL('SET ' || scalarVar1 || ' = 2;');", Kind.EVAL_STATEMENT); + assertNotNull(tree.evalKeyword()); + assertNotNull(tree.openingParenthesis()); + assertNotNull(tree.expression()); + assertNotNull(tree.closingParenthesis()); + assertNotNull(tree.semi()); + } + } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/ForStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ForStatementTest.java similarity index 94% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/ForStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ForStatementTest.java index 760b711e..799e9eaa 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/ForStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ForStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/IfStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/IfStatementTest.java similarity index 86% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/IfStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/IfStatementTest.java index 5557828f..7c6dc1bc 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/IfStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/IfStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertFalse; @@ -26,7 +26,6 @@ import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; import com.exxeta.iss.sonar.esql.api.tree.statement.IfStatementTree; -import com.exxeta.iss.sonar.esql.tree.impl.statement.IfStatementTreeImpl; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; public class IfStatementTest extends EsqlTreeModelTest { @@ -38,7 +37,7 @@ public void ifStatement() { @Test public void modelTest() throws Exception { - IfStatementTreeImpl tree = parse("IF TRUE THEN CALL A(); ELSEIF TRUE THEN CALL B(); ELSE CALL C(); END IF;", Kind.IF_STATEMENT); + IfStatementTree tree = parse("IF TRUE THEN CALL A(); ELSEIF TRUE THEN CALL B(); ELSE CALL C(); END IF;", Kind.IF_STATEMENT); assertNotNull(tree.ifKeyword()); assertNotNull(tree.condition()); diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/InsertStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/InsertStatementTest.java new file mode 100644 index 00000000..09ee9109 --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/InsertStatementTest.java @@ -0,0 +1,63 @@ +/* + * 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.api.tree.statement; + +import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.api.tree.statement.InsertStatementTree; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class InsertStatementTest extends EsqlTreeModelTest { + + + @Test + public void insertStatement(){ + assertThat(Kind.INSERT_STATEMENT) + .matches("INSERT INTO Database.{Source}.{Schema}.{Table} (Name, Value) values ('Joe', 12.34);"); + + } + + @Test + public void modelTest() throws Exception { + InsertStatementTree tree = parse("INSERT INTO Database.{Source}.{Schema}.{Table} (Name, Value) values ('Joe', 12.34);", Kind.INSERT_STATEMENT); + assertNotNull(tree.insertKeyword()); + + assertNotNull(tree.intoKeyword()); + + assertNotNull(tree.tableReference()); + + assertNotNull(tree.columns()); + + assertNotNull(tree.valuesKeyword()); + + assertNotNull(tree.openParenthesis()); + + assertNotNull(tree.expressions()); + assertNotNull(tree.expressions().get(0)); + + assertNotNull(tree.closeParenthesis()); + + assertNotNull(tree.semi()); + + } + +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/LogStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/LogStatementTest.java similarity index 96% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/LogStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/LogStatementTest.java index be669828..0d8a1487 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/LogStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/LogStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/LoopStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/LoopStatementTest.java similarity index 93% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/LoopStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/LoopStatementTest.java index bb333e96..3be8bd26 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/LoopStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/LoopStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/MoveStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/MoveStatementTest.java similarity index 93% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/MoveStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/MoveStatementTest.java index 11b20e70..d7729477 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/MoveStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/MoveStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertEquals; @@ -25,7 +25,6 @@ import org.junit.Test; 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.tree.impl.statement.MoveStatementTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.NameClausesTreeImpl; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; @@ -40,6 +39,7 @@ public void moveStatement(){ .matches("MOVE cursor FIRSTCHILD REPEAT TYPE;") .matches("MOVE cursor FIRSTCHILD IDENTITY a;") .matches("MOVE cursor FIRSTCHILD NAMESPACE a;") + .matches("MOVE cursor PARENT;") .matches("MOVE cursor TO OutputRoot;"); } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParameterTreeTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParameterTreeTest.java new file mode 100644 index 00000000..eff21b16 --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ParameterTreeTest.java @@ -0,0 +1,51 @@ +/* + * 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.api.tree.statement; + +import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.api.tree.statement.ParameterTree; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; + +public class ParameterTreeTest extends EsqlTreeModelTest { + + @Test + public void moveStatement(){ + + assertThat(Kind.PARAMETER) + .matches("INOUT aaa") + .matches("OUT bbb CONSTANT INTEGER"); + } + + @Test + public void modelTest () throws Exception{ + ParameterTree tree = parse("IN aaa NAMESPACE", Kind.PARAMETER); + assertNotNull(tree.directionIndicator()); + assertNotNull(tree.identifier()); + assertNull(tree.constantKeyword()); + assertNotNull(tree.nameOrNamesapceKeyword()); + assertNull(tree.dataType()); + + } + +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/PassthruStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/PassthruStatementTest.java similarity index 94% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/PassthruStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/PassthruStatementTest.java index 2f437660..5d73bf44 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/PassthruStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/PassthruStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/PropagateStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/PropagateStatementTest.java similarity index 95% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/PropagateStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/PropagateStatementTest.java index 98f144a7..6a50dd2b 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/PropagateStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/PropagateStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/RepeatStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/RepeatStatementTest.java similarity index 94% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/RepeatStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/RepeatStatementTest.java index 82de3ba0..dbd8c793 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/RepeatStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/RepeatStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/ResignalStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ResignalStatementTest.java similarity index 89% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/ResignalStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ResignalStatementTest.java index 833be2c2..30e3dea2 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/ResignalStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ResignalStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/ReturnStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ReturnStatementTest.java similarity index 89% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/ReturnStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ReturnStatementTest.java index 9f5e4dac..b0409092 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/ReturnStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ReturnStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SemicolonTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/SemicolonTest.java similarity index 86% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SemicolonTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/SemicolonTest.java index 3700c110..5815f124 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/tree/impl/statement/SemicolonTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/SemicolonTest.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,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.exxeta.iss.sonar.esql.tree.impl.statement; +package com.exxeta.iss.sonar.esql.api.tree.statement; import static org.assertj.core.api.Assertions.assertThat; @@ -23,6 +23,7 @@ import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; import com.exxeta.iss.sonar.esql.api.tree.statement.SetStatementTree; +import com.exxeta.iss.sonar.esql.tree.impl.statement.SetStatementTreeImpl; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; public class SemicolonTest extends EsqlTreeModelTest { diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/SetStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/SetStatementTest.java similarity index 90% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/SetStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/SetStatementTest.java index 3e0c8da3..d07c8956 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/SetStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/SetStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/ThrowStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ThrowStatementTest.java similarity index 95% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/ThrowStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ThrowStatementTest.java index 6f72cef1..29b449fd 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/ThrowStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/ThrowStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; import static org.junit.Assert.assertNotNull; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/UpdateStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/UpdateStatementTest.java similarity index 53% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/UpdateStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/UpdateStatementTest.java index 4eff1564..0d9f46b8 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/UpdateStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/UpdateStatementTest.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,15 +15,19 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import org.junit.Test; import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.api.tree.statement.UpdateStatementTree; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; -public class UpdateStatementTest { +public class UpdateStatementTest extends EsqlTreeModelTest{ @Test @@ -34,4 +38,27 @@ public void updateStatement(){ } + @Test + public void modelTest() throws Exception{ + UpdateStatementTree tree = parse("UPDATE Database.StockPrices AS SP SET PRICE = InputBody.Message.StockPrice, B = 1;", Kind.UPDATE_STATEMENT); + + assertNotNull(tree.updateKeyword()); + + assertNotNull(tree.tableReference()); + + assertNotNull(tree.asKeyword()); + + assertNotNull(tree.alias()); + + assertNotNull(tree.setKeyword()); + + assertNotNull(tree.setColumns()); + + assertNull(tree.whereKeyword()); + + assertNull(tree.whereExpression()); + + assertNotNull(tree.semi()); + + } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/WhileStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/WhileStatementTest.java similarity index 94% rename from esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/WhileStatementTest.java rename to esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/WhileStatementTest.java index feebe1d7..d5af549b 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/impl/statement/WhileStatementTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/WhileStatementTest.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,7 +15,7 @@ * 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.api.tree.statement; import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/symbol/SymbolModelImplTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/symbol/SymbolModelImplTest.java index 6890f644..7f115622 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/symbol/SymbolModelImplTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/symbol/SymbolModelImplTest.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,25 +17,22 @@ */ package com.exxeta.iss.sonar.esql.api.tree.symbol; -import static com.exxeta.iss.sonar.esql.compat.CompatibilityHelper.wrap; import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.batch.fs.InputFile; import com.exxeta.iss.sonar.esql.api.symbols.Symbol; import com.exxeta.iss.sonar.esql.api.symbols.Symbol.Kind; import com.exxeta.iss.sonar.esql.api.tree.ProgramTree; import com.exxeta.iss.sonar.esql.api.tree.Tree; -import com.exxeta.iss.sonar.esql.compat.CompatibleInputFile; import com.exxeta.iss.sonar.esql.tree.symbols.SymbolModelImpl; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; import com.exxeta.iss.sonar.esql.utils.TestUtils; public class SymbolModelImplTest extends EsqlTreeModelTest { - private static final CompatibleInputFile INPUT_FILE = wrap(TestUtils.createTestInputFile("src/test/resources/ast/resolve/symbolModel.esql")); + private static final InputFile INPUT_FILE = TestUtils.createTestInputFile("src/test/resources/ast/resolve/symbolModel.esql"); private SymbolModelImpl SYMBOL_MODEL = symbolModel(INPUT_FILE); @Test @@ -58,7 +55,4 @@ public void override_symbol_kind() throws Exception { assertThat(func.is(Kind.FUNCTION)).isTrue(); } - private Settings settings(String environmentNames, String globalNames) { - return new MapSettings(); - } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/symbol/type/RoutineTypeTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/symbol/type/RoutineTypeTest.java index 5b8d4d23..c878be16 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/symbol/type/RoutineTypeTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/symbol/type/RoutineTypeTest.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/symbol/type/TypeTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/symbol/type/TypeTest.java index 1cc17c1e..e3e52c84 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/symbol/type/TypeTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/symbol/type/TypeTest.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,6 @@ import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; import com.exxeta.iss.sonar.esql.utils.TestUtils; -import static com.exxeta.iss.sonar.esql.compat.CompatibilityHelper.wrap; - public abstract class TypeTest extends EsqlTreeModelTest { protected ProgramTree ROOT_NODE; protected SymbolModel SYMBOL_MODEL; @@ -40,6 +38,6 @@ protected Symbol getSymbol(String name) { protected void setUp(String filename) throws Exception { InputFile file = TestUtils.createTestInputFile("src/test/resources/ast/resolve/type/", filename); ROOT_NODE = parse(file.contents()); - SYMBOL_MODEL = new EsqlVisitorContext(ROOT_NODE, wrap(file), null).getSymbolModel(); + SYMBOL_MODEL = new EsqlVisitorContext(ROOT_NODE, file, null).getSymbolModel(); } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitorTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitorTest.java index e632f92c..fb1d1323 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitorTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitorTest.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/visitors/IssueLocationTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/visitors/IssueLocationTest.java index 8fa250cb..f400caf1 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/visitors/IssueLocationTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/visitors/IssueLocationTest.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/cpd/CpdVisitorTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/cpd/CpdVisitorTest.java new file mode 100644 index 00000000..76db0733 --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/cpd/CpdVisitorTest.java @@ -0,0 +1,84 @@ +/* + * 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.cpd; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.List; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.batch.sensor.internal.SensorContextTester; +import org.sonar.duplications.internal.pmd.TokensLine; + +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.visitors.EsqlVisitorContext; +import com.exxeta.iss.sonar.esql.api.visitors.TreeVisitorContext; +import com.exxeta.iss.sonar.esql.parser.EsqlParserBuilder; +import com.exxeta.iss.sonar.esql.utils.TestUtils; +import com.google.common.base.Charsets; +import com.sonar.sslr.api.typed.ActionParser; + +public class CpdVisitorTest { + private static final Charset CHARSET = Charsets.UTF_8; + + private final ActionParser p = EsqlParserBuilder.createParser(); + + private DefaultInputFile inputFile; + private SensorContextTester sensorContext; + + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); + + @Test + public void test() throws Exception { + scan("CREATE PROCEDURE A () BEGIN\nSET x = 'a' + 1 + 'line1';\nSET y = 2;\nEND;\n"); + List cpdTokenLines = sensorContext.cpdTokens("module1:" + inputFile.relativePath()); + assertThat(cpdTokenLines).hasSize(4); + TokensLine firstTokensLine = cpdTokenLines.get(1); + assertThat(firstTokensLine.getValue()).isEqualTo("SETx=LITERAL+1+LITERAL;"); + assertThat(firstTokensLine.getStartLine()).isEqualTo(2); + assertThat(firstTokensLine.getStartUnit()).isEqualTo(7); + assertThat(firstTokensLine.getEndLine()).isEqualTo(2); + assertThat(firstTokensLine.getEndUnit()).isEqualTo(15); + + TokensLine secondTokensLine = cpdTokenLines.get(2); + assertThat(secondTokensLine.getValue()).isEqualTo("SETy=2;"); + assertThat(secondTokensLine.getStartLine()).isEqualTo(3); + assertThat(secondTokensLine.getStartUnit()).isEqualTo(16); + assertThat(secondTokensLine.getEndLine()).isEqualTo(3); + assertThat(secondTokensLine.getEndUnit()).isEqualTo(20); + } + + private void scan(String source) throws IOException { + inputFile = TestUtils.createTestInputFile(tempFolder.newFile(), source, CHARSET); + + sensorContext = SensorContextTester.create(tempFolder.getRoot().toPath()); + CpdVisitor cpdVisitor = new CpdVisitor(sensorContext); + ProgramTree tree = (ProgramTree) p.parse(source); + TreeVisitorContext visitorContext = new EsqlVisitorContext(tree, inputFile, null); + cpdVisitor.scanTree(visitorContext); + } + + +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/highlighter/HighlightSymbolTableBuilderTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/highlighter/HighlightSymbolTableBuilderTest.java index c27e9523..8e193f6d 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/highlighter/HighlightSymbolTableBuilderTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/highlighter/HighlightSymbolTableBuilderTest.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,10 +17,11 @@ */ package com.exxeta.iss.sonar.esql.highlighter; -import static com.exxeta.iss.sonar.esql.compat.CompatibilityHelper.wrap; import static org.assertj.core.api.Assertions.assertThat; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.nio.charset.StandardCharsets; import java.util.Collection; @@ -30,29 +31,29 @@ import org.sonar.api.batch.fs.internal.DefaultTextPointer; import org.sonar.api.batch.fs.internal.DefaultTextRange; import org.sonar.api.batch.fs.internal.FileMetadata; +import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.internal.SensorContextTester; import org.sonar.api.batch.sensor.symbol.NewSymbolTable; import com.exxeta.iss.sonar.esql.api.tree.Tree; -import com.exxeta.iss.sonar.esql.compat.CompatibleInputFile; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; import com.google.common.io.Files; public class HighlightSymbolTableBuilderTest extends EsqlTreeModelTest { private SensorContextTester sensorContext; - private CompatibleInputFile inputFile; + private DefaultInputFile inputFile; - private NewSymbolTable newSymbolTable(String filename) { + private NewSymbolTable newSymbolTable(String filename) throws FileNotFoundException { File moduleBaseDir = new File("src/test/resources/highlighter/"); sensorContext = SensorContextTester.create(moduleBaseDir); - DefaultInputFile defaultInputFile = new DefaultInputFile("moduleKey", filename) + inputFile = new TestInputFileBuilder("moduleKey", filename) .setModuleBaseDir(moduleBaseDir.toPath()) - .setCharset(StandardCharsets.UTF_8); - inputFile = wrap(defaultInputFile); - defaultInputFile.initMetadata(new FileMetadata().readMetadata(inputFile.file(), defaultInputFile.charset())); + .setCharset(StandardCharsets.UTF_8) + .build(); + inputFile.setMetadata(new FileMetadata().readMetadata(new FileInputStream(inputFile.file()), inputFile.charset(), inputFile.absolutePath())); - return sensorContext.newSymbolTable().onFile(defaultInputFile); + return sensorContext.newSymbolTable().onFile(inputFile); } private static DefaultTextRange textRange(int line, int startColumn, int endColumn) { diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/highlighter/HighlighterVisitorTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/highlighter/HighlighterVisitorTest.java index 9f8a20b3..3365d796 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/highlighter/HighlighterVisitorTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/highlighter/HighlighterVisitorTest.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,6 @@ */ package com.exxeta.iss.sonar.esql.highlighter; -import static com.exxeta.iss.sonar.esql.compat.CompatibilityHelper.wrap; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -36,11 +35,13 @@ import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile.Type; import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.batch.sensor.internal.SensorContextTester; 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.visitors.EsqlFileImpl; import com.exxeta.iss.sonar.esql.api.visitors.TreeVisitorContext; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; import com.google.common.base.Charsets; @@ -67,13 +68,14 @@ public void setUp() throws IOException { private void initFile(String text) throws IOException { File file = tempFolder.newFile(); - inputFile = new DefaultInputFile("moduleKey", file.getName()) + inputFile = new TestInputFileBuilder("moduleKey", file.getName()) .setLanguage("esql") .setType(Type.MAIN) .setCharset(CHARSET) - .initMetadata(text); + .initMetadata(text) + .build(); - when(visitorContext.getEsqlFile()).thenReturn(wrap(inputFile)); + when(visitorContext.getEsqlFile()).thenReturn(new EsqlFileImpl(inputFile)); } private void highlight(String string) throws Exception { diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlKeywordTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlKeywordTest.java index a2c6986e..fa7a9217 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlKeywordTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlKeywordTest.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/lexer/EsqlPunctuatorTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlPunctuatorTest.java index 3344151c..19041671 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlPunctuatorTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlPunctuatorTest.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/lexer/EsqlTokenTypeTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlTokenTypeTest.java index 001e099a..7744065a 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlTokenTypeTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlTokenTypeTest.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/metrics/MetricsTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/metrics/MetricsTest.java index f9b5aa37..d6afce92 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/metrics/MetricsTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/metrics/MetricsTest.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"); @@ -36,7 +36,7 @@ public class MetricsTest extends EsqlTreeModelTest { public void complexity() { String path = "src/test/resources/metrics/complexity.esql"; Tree tree = parse(new File(path)); - assertThat(new ComplexityVisitor().getComplexity(tree)).isEqualTo(7); + assertThat(new ComplexityVisitor().getComplexity(tree)).isEqualTo(16); } @Test diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/metrics/MetricsVisitorTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/metrics/MetricsVisitorTest.java index 477cd837..b0176cbd 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/metrics/MetricsVisitorTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/metrics/MetricsVisitorTest.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,6 @@ */ package com.exxeta.iss.sonar.esql.metrics; -import static com.exxeta.iss.sonar.esql.compat.CompatibilityHelper.wrap; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; @@ -32,11 +31,13 @@ import org.mockito.Mockito; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.internal.SensorContextTester; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.FileLinesContext; import org.sonar.api.measures.FileLinesContextFactory; +import com.exxeta.iss.sonar.esql.api.visitors.EsqlFileImpl; import com.exxeta.iss.sonar.esql.api.visitors.TreeVisitorContext; import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; @@ -44,10 +45,11 @@ public class MetricsVisitorTest extends EsqlTreeModelTest { private static final File MODULE_BASE_DIR = new File("src/test/resources/metrics/"); - private static final DefaultInputFile INPUT_FILE = new DefaultInputFile("moduleKey", "lines.esql") + private static final DefaultInputFile INPUT_FILE = new TestInputFileBuilder("moduleKey", "lines.esql") .setModuleBaseDir(MODULE_BASE_DIR.toPath()) .setLanguage("esql") - .setType(InputFile.Type.MAIN); + .setType(InputFile.Type.MAIN) + .build(); private static final String COMPONENT_KEY = "moduleKey:lines.esql"; private FileLinesContext linesContext; @@ -60,13 +62,13 @@ public void setUp() throws Exception { context.fileSystem().add(INPUT_FILE); linesContext = mock(FileLinesContext.class); treeVisitorContext = mock(TreeVisitorContext.class); - when(treeVisitorContext.getEsqlFile()).thenReturn(wrap(INPUT_FILE)); + when(treeVisitorContext.getEsqlFile()).thenReturn(new EsqlFileImpl(INPUT_FILE)); when(treeVisitorContext.getTopTree()).thenReturn(parse(INPUT_FILE.file())); } @Test public void test() { - MetricsVisitor metricsVisitor = createMetricsVisitor(false); + MetricsVisitor metricsVisitor = createMetricsVisitor(); metricsVisitor.scanTree(treeVisitorContext); assertThat(context.measure(COMPONENT_KEY, CoreMetrics.FUNCTIONS).value()).isEqualTo(0); assertThat(context.measure(COMPONENT_KEY, CoreMetrics.STATEMENTS).value()).isEqualTo(1); @@ -77,15 +79,15 @@ public void test() { @Test public void save_executable_lines() { - final MetricsVisitor metricsVisitorWithSave = createMetricsVisitor(true); + final MetricsVisitor metricsVisitorWithSave = createMetricsVisitor(); metricsVisitorWithSave.scanTree(treeVisitorContext); Mockito.verify(linesContext, atLeastOnce()).setIntValue(eq(CoreMetrics.EXECUTABLE_LINES_DATA_KEY), any(Integer.class), any(Integer.class)); } - private MetricsVisitor createMetricsVisitor(boolean saveExecutableLines) { + private MetricsVisitor createMetricsVisitor() { FileLinesContextFactory linesContextFactory = mock(FileLinesContextFactory.class); when(linesContextFactory.createFor(INPUT_FILE)).thenReturn(linesContext); - return new MetricsVisitor(context, false, linesContextFactory, saveExecutableLines); + return new MetricsVisitor(context, false, linesContextFactory); } } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/parser/ParserTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/parser/ParserTest.java index e348d3a4..f26d5260 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/parser/ParserTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/parser/ParserTest.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/utils/Assertions.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/Assertions.java index c8fa1c82..7b1eff83 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/Assertions.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/Assertions.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/utils/EsqlTreeModelTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/EsqlTreeModelTest.java index ccd3ee09..d7070d1c 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/EsqlTreeModelTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/EsqlTreeModelTest.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"); @@ -24,14 +24,14 @@ import java.nio.file.Files; import java.util.Iterator; -import org.sonar.api.config.Settings; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.config.Configuration; import org.sonar.sslr.grammar.GrammarRuleKey; 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.visitors.EsqlVisitorContext; -import com.exxeta.iss.sonar.esql.compat.CompatibleInputFile; import com.exxeta.iss.sonar.esql.parser.EsqlGrammar; import com.exxeta.iss.sonar.esql.parser.EsqlLegacyGrammar; import com.exxeta.iss.sonar.esql.parser.EsqlNodeBuilder; @@ -56,18 +56,33 @@ private ActionParser getParser(GrammarRuleKey rule){ * * @param s * the string to parse + * @param rule + * the rule used to parse the string * @param descendantToReturn * the node kind to seek in the generated tree * @return the node found for the given kind, null if not found. */ @SuppressWarnings("unchecked") - protected T parse(String s, Kind descendantToReturn) throws Exception { - Tree node = getParser(descendantToReturn).parse(s); + protected T parse(String s, GrammarRuleKey rule, Kind descendantToReturn) throws Exception { + Tree node = getParser(rule).parse(s); checkFullFidelity(node, s); return (T) getFirstDescendant((EsqlTree) node, descendantToReturn); } + + /** + * Parse the given string and return the first descendant of the given kind. + * + * @param s + * the string to parse + * @param descendantToReturn + * the node kind to seek in the generated tree + * @return the node found for the given kind, null if not found. + */ + protected T parse(String s, Kind descendantToReturn) throws Exception { + return parse(s, descendantToReturn, descendantToReturn); + } - protected SymbolModelImpl symbolModel(CompatibleInputFile file) { + protected SymbolModelImpl symbolModel(InputFile file) { try { return symbolModel(file, null); } catch (IOException e) { @@ -88,12 +103,12 @@ protected ProgramTree parse(String content) { return (ProgramTree) getParser(EsqlLegacyGrammar.PROGRAM).parse(content); } - protected SymbolModelImpl symbolModel(CompatibleInputFile file, Settings settings) throws IOException { + protected SymbolModelImpl symbolModel(InputFile file, Configuration configuration) throws IOException { ProgramTree root = (ProgramTree) getParser(EsqlLegacyGrammar.PROGRAM).parse(file.contents()); - return (SymbolModelImpl) new EsqlVisitorContext(root, file, settings).getSymbolModel(); + return (SymbolModelImpl) new EsqlVisitorContext(root, file, configuration).getSymbolModel(); } - protected EsqlVisitorContext context(CompatibleInputFile file) throws IOException { + protected EsqlVisitorContext context(InputFile file) throws IOException { ProgramTree root = (ProgramTree) getParser(EsqlLegacyGrammar.PROGRAM).parse(file.contents()); return new EsqlVisitorContext(root, file, null); } diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/LegacyParserTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/LegacyParserTest.java index f14e140b..b468536b 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/LegacyParserTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/LegacyParserTest.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/utils/SourceBuilder.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/SourceBuilder.java index 96950999..7524861f 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/SourceBuilder.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/SourceBuilder.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,13 +17,13 @@ */ package com.exxeta.iss.sonar.esql.utils; -import java.util.List; +import java.util.Set; 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.SubscriptionVisitor; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; public class SourceBuilder extends SubscriptionVisitor { @@ -38,8 +38,8 @@ public static String build(Tree tree) { } @Override - public List nodesToVisit() { - return ImmutableList.of(Tree.Kind.TOKEN); + public Set nodesToVisit() { + return ImmutableSet.of(Tree.Kind.TOKEN); } @Override diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/TestUtils.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/TestUtils.java index 7acaf7b8..d59b22ba 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/TestUtils.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/utils/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,15 +17,19 @@ */ package com.exxeta.iss.sonar.esql.utils; -import static com.exxeta.iss.sonar.esql.compat.CompatibilityHelper.wrap; - +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Paths; 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.batch.fs.internal.FileMetadata; +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.visitors.EsqlVisitorContext; @@ -38,18 +42,29 @@ public class TestUtils { public static EsqlVisitorContext createContext(InputFile file) { try { EsqlTree programTree = (EsqlTree) EsqlParserBuilder.createParser().parse(file.contents()); - return new EsqlVisitorContext((ProgramTree)programTree, wrap(file), new MapSettings()); + return new EsqlVisitorContext((ProgramTree)programTree, file, new MapSettings().asConfig()); } catch (IOException e) { throw Throwables.propagate(e); } } + public static DefaultInputFile createTestInputFile(File file, String contents, Charset encoding) { + final DefaultInputFile inputFile = new TestInputFileBuilder("module1", file.getAbsolutePath()).setCharset(encoding).build(); + try { + Files.write(file.toPath(), contents.getBytes(encoding)); + inputFile.setMetadata(new FileMetadata().readMetadata(new FileInputStream(file), encoding, file.getAbsolutePath())); + } catch (IOException e) { + throw Throwables.propagate(e); + } + return inputFile; + } public static DefaultInputFile createTestInputFile(String baseDir, String relativePath) { - final DefaultInputFile inputFile = new DefaultInputFile("module1", relativePath) + final DefaultInputFile inputFile = new TestInputFileBuilder("module1", relativePath) .setModuleBaseDir(Paths.get(baseDir)) .setLanguage("esql") .setCharset(StandardCharsets.UTF_8) - .setType(InputFile.Type.MAIN); + .setType(InputFile.Type.MAIN) + .build(); return inputFile; } diff --git a/esql-frontend/src/test/resources/metrics/complexity.esql b/esql-frontend/src/test/resources/metrics/complexity.esql index 84ce9f42..322a086e 100644 --- a/esql-frontend/src/test/resources/metrics/complexity.esql +++ b/esql-frontend/src/test/resources/metrics/complexity.esql @@ -1,24 +1,111 @@ +BROKER SCHEMA A +PATH B + CREATE COMPUTE MODULE TestFlow_Compute CREATE PROCEDURE Procedure() BEGIN PROPAGATE TO LABEL 'ABC'; PROPAGATE TO TERMINAL 1; - IF FALSE THEN - IF FALSE THEN - IF FALSE THEN - IF FALSE THEN --Non compliant + IF A is NULL THEN + IF b in (c,d,e) THEN + IF c BETWEEN 1 and 10 THEN + IF NOT FALSE THEN --Non compliant SET OutputRoot=InputRoot; END IF; - ELSEIF A = B THEN --Compliant + ELSEIF ( A = B ) THEN --Compliant IF TRUE THEN --Non compliant SET OutputRoot=InputRoot; END IF; - ELSEIF A = B THEN --Compliant + ELSEIF A = B.b[0] THEN --Compliant ELSEIF FALSE THEN --Compliant + THROW USER EXCEPTION; END IF; END IF; ELSE + SET a = (CURRENT_GMTTIME - InputRoot.MQMD.PutTime) MINUTE TO SECOND; END IF; - + SET OutputRoot.XMLNSC.abc:abc = THE ( a(b,c,d) ); + SET b = INTERVAL '1' HOUR; + SET b = CAST(StartDelyIntervalStr AS INTERVAL HOUR TO SECOND); + SET VAL = CAST('123456' AS DECIMAL(3,0)); + X : WHILE i <= 3 DO + + LEAVE X; + ITERATE X; + END WHILE X; + CALL ABC(); + 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; + + CREATE FUNCTION func() RETURNS BOOLEAN + BEGIN + DECLARE EXIT HANDLER FOR SQLSTATE VALUE 'U11222' SET a = 1; + B: LOOP + END LOOP B; + REPEAT + SET i = i + 1; + UNTIL i>= 3 END REPEAT; + RETURN TRUE; + DETACH OutputRoot.a; + ATTACH a to OutputRoot AS FIRSTCHILD; + CREATE LASTCHILD OF OutputRoot.XMLNS.TestCase.Root IDENTITY (XML.Element)NSpace1:Element1[2] VALUE 'Element 2 Value'; + CREATE NEXTSIBLING OF targetCursor AS targetCursor REPEAT; + CREATE LASTCHILD OF OutputRoot DOMAIN('MRM') PARSE(inBitStream, inEncoding, inCCSID, 'DP3UK14002001', 'TestCase', 'XML1', options); + SET a = OVERLAY ('ABCDEFGHIJ' PLACING '1234' FROM 4 FOR 3); + PASSTHRU('aaa'); + PROPAGATE DELETE NONE; + CREATE LASTCHILD OF OutputRoot From InputRoot.A; + DELETE LASTCHILD OF Cursor; + RESIGNAL; + FOR source AS Environment.SourceData.Folder[] DO END FOR; + MOVE cursor FIRSTCHILD TYPE Name NAME 'Field1'; + DELETE FROM Database.SHAREHOLDINGS AS S WHERE S.ACCOUNTNO = InputBody.AccountNumber; + INSERT INTO Database.{Source}.{Schema}.{Table} (Name, Value) values ('Joe', 12.34); + UPDATE Database.StockPrices AS SP SET PRICE = InputBody.Message.StockPrice, B = 1; + EVAL('SET ' || scalarVar1 || ' = 2;'); + LOG USER TRACE EXCEPTION VALUES(SQLSTATE, 'DivideByZero'); + SET year = EXTRACT(YEAR FROM CURRENT_DATE); + SET a = ROUND (1,1); + SET pos = POSITION ('A' IN 'ABCABCABCABCABC' FROM 4); + SET s = SUBSTRING('Hello World!' FROM 7 FOR 4); + SET t = TRIM(' a '); + SET a = ASBITSTREAM(cursor OPTIONS options CCSID 1208); + SET l = FOR ALL Body.Invoice.Purchases."Item"[] AS I (I.Quantity <= 50); + + SET m = CASE CurrentMonth WHEN '01' THEN 'January' ELSE 'Unknown' END; + + SET s = SELECT FIELDVALUE(v.a) FROM vehicle.fb:VEHICLE[] AS v WHERE v.fb:c = Environment.Variables.F; + + SET OutputRoot.XMLNS.Data = ROW('granary' AS bread, 'riesling' AS wine, 'stilton' AS cheese); + + SET p = PASSTHRU('SELECT * from aaa'); + + IF Body.Trade.Company LIKE 'I__' THEN END IF; + + SET OutputRoot.XMLNS.Data.Result[] = LIST{InputBody.Car.color, + 'green', + 'blue'}; + + END; + + CREATE PROCEDURE SwapNullable ( + IN a INTEGER NULLABLE, + OUT b INTEGER NULLABLE, + INOUT c INTEGER NULLABLE ) + LANGUAGE CLR + EXTERNAL NAME "FunctionTests.SwapStringNullable" + --ASSEMBLY "MyAssembly2" + --APPDOMAIN "MyDomain" + ; + + CREATE PROCEDURE myProc1 (IN P1 INT, OUT P2 INT) LANGUAGE DATABASE DYNAMIC RESULT SETS 2 EXTERNAL NAME "myschema.myproc1"; + END MODULE; \ No newline at end of file diff --git a/esql-plugin/pom.xml b/esql-plugin/pom.xml index 6da1546b..70a57d83 100644 --- a/esql-plugin/pom.xml +++ b/esql-plugin/pom.xml @@ -6,7 +6,7 @@ com.exxeta.iss sonar-esql-plugin - 2.2.0 + 2.3.0 esql-plugin @@ -60,6 +60,10 @@ org.assertj assertj-core + + org.mockito + mockito-all + @@ -114,8 +118,8 @@ - 2400000 - 2500000 + 3800000 + 3900000 ${project.build.directory}/${project.build.finalName}.jar diff --git a/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/CancellationException.java b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/CancellationException.java index 2a4cbad1..715bb982 100644 --- a/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/CancellationException.java +++ b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/CancellationException.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-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlChecks.java b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlChecks.java index c9a9a915..c5f249ee 100644 --- a/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlChecks.java +++ b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlChecks.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-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlLanguage.java b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlLanguage.java index 6a76484c..c1ac0dd3 100644 --- a/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlLanguage.java +++ b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlLanguage.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,23 +18,23 @@ package com.exxeta.iss.sonar.esql; import org.apache.commons.lang.StringUtils; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.resources.AbstractLanguage; public class EsqlLanguage extends AbstractLanguage { public static final String KEY = "esql"; - private Settings settings; + private Configuration configuration; - public EsqlLanguage(Settings configuration) { + public EsqlLanguage(Configuration configuration) { super(KEY, "Esql"); - this.settings = configuration; + this.configuration = configuration; } @Override public String[] getFileSuffixes() { - String[] suffixes = settings.getStringArray(EsqlPlugin.FILE_SUFFIXES_KEY); + String[] suffixes = configuration.getStringArray(EsqlPlugin.FILE_SUFFIXES_KEY); if (suffixes == null || suffixes.length == 0) { suffixes = StringUtils.split(EsqlPlugin.FILE_SUFFIXES_DEFVALUE, ","); } diff --git a/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlPlugin.java b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlPlugin.java index bceb0ddf..c97b45f1 100644 --- a/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlPlugin.java +++ b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlPlugin.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,9 +22,7 @@ import org.sonar.api.config.PropertyDefinition; import org.sonar.api.resources.Qualifiers; -import com.exxeta.iss.sonar.esql.codecoverage.CodeCoverageExtension; import com.exxeta.iss.sonar.esql.metrics.EsqlMetrics; -import com.google.common.collect.ImmutableList; public class EsqlPlugin implements Plugin { @@ -57,9 +55,10 @@ public void define(Context context) { PropertyDefinition.builder(FILE_SUFFIXES_KEY) .defaultValue(FILE_SUFFIXES_DEFVALUE) .name("File Suffixes") - .description("Comma-separated list of suffixes for files to analyze.") + .description("List of suffixes for files to analyze.") .subCategory(GENERAL) .category(ESQL_CATEGORY) + .multiValues(true) .onQualifiers(Qualifiers.PROJECT) .build(), @@ -79,6 +78,7 @@ public void define(Context context) { .name("IIB trace file") .description("Path to the IIB trace files containing coverage data. The path may be absolute or relative to the project base directory.") .onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE) + .multiValues(true) .build() ); diff --git a/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlProfile.java b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlProfile.java index ceb886bb..4be1cfe3 100644 --- a/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlProfile.java +++ b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlProfile.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-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlRulesDefinition.java b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlRulesDefinition.java index c5500744..989a42ef 100644 --- a/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlRulesDefinition.java +++ b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlRulesDefinition.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-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlSquidSensor.java b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlSquidSensor.java index 5052a471..152b5101 100644 --- a/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlSquidSensor.java +++ b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/EsqlSquidSensor.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; -import static com.exxeta.iss.sonar.esql.compat.CompatibilityHelper.wrap; - import java.io.File; import java.io.InterruptedIOException; import java.util.ArrayList; @@ -47,11 +45,10 @@ import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.batch.sensor.issue.NewIssueLocation; import org.sonar.api.batch.sensor.symbol.NewSymbolTable; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.issue.NoSonarFilter; import org.sonar.api.measures.FileLinesContextFactory; import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.Version; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.squidbridge.ProgressReport; @@ -72,10 +69,11 @@ import com.exxeta.iss.sonar.esql.check.CheckList; import com.exxeta.iss.sonar.esql.check.ParsingErrorCheck; import com.exxeta.iss.sonar.esql.codecoverage.TraceSensor; -import com.exxeta.iss.sonar.esql.compat.CompatibleInputFile; +import com.exxeta.iss.sonar.esql.cpd.CpdVisitor; import com.exxeta.iss.sonar.esql.highlighter.HighlightSymbolTableBuilder; import com.exxeta.iss.sonar.esql.highlighter.HighlighterVisitor; import com.exxeta.iss.sonar.esql.metrics.MetricsVisitor; +import com.exxeta.iss.sonar.esql.metrics.NoSonarVisitor; import com.exxeta.iss.sonar.esql.parser.EsqlParserBuilder; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; @@ -88,9 +86,6 @@ public class EsqlSquidSensor implements Sensor { private static final Logger LOG = Loggers.get(EsqlSquidSensor.class); - private static final Version V6_0 = Version.create(6, 0); - private static final Version V6_2 = Version.create(6, 2); - private final EsqlChecks checks; private final FileLinesContextFactory fileLinesContextFactory; private final FileSystem fileSystem; @@ -124,14 +119,14 @@ public EsqlSquidSensor( @VisibleForTesting protected void analyseFiles( - SensorContext context, List treeVisitors, Iterable inputFiles, + SensorContext context, List treeVisitors, Iterable inputFiles, ProductDependentExecutor executor, ProgressReport progressReport ) { boolean success = false; try { - for (CompatibleInputFile inputFile : inputFiles) { + for (InputFile inputFile : inputFiles) { // check for cancellation of the analysis (by SonarQube or SonarLint). See SONARJS-761. - if (context.getSonarQubeVersion().isGreaterThanOrEqual(V6_0) && context.isCancelled()) { + if (context.isCancelled()) { throw new CancellationException("Analysis interrupted because the SensorContext is in cancelled state"); } analyse(context, inputFile, executor, treeVisitors); @@ -154,7 +149,7 @@ private static void stopProgressReport(ProgressReport progressReport, boolean su } } - private void analyse(SensorContext sensorContext, CompatibleInputFile inputFile, ProductDependentExecutor executor, List visitors) { + private void analyse(SensorContext sensorContext, InputFile inputFile, ProductDependentExecutor executor, List visitors) { ProgramTree programTree; try { @@ -162,13 +157,13 @@ private void analyse(SensorContext sensorContext, CompatibleInputFile inputFile, scanFile(sensorContext, inputFile, executor, visitors, programTree); } catch (RecognitionException e) { checkInterrupted(e); - LOG.error("Unable to parse file: " + inputFile.absolutePath()); + LOG.error("Unable to parse file: " + inputFile.uri()); LOG.error(e.getMessage()); processRecognitionException(e, sensorContext, inputFile); } catch (Exception e) { checkInterrupted(e); processException(e, sensorContext, inputFile); - throw new AnalysisException("Unable to analyse file: " + inputFile.absolutePath(), e); + throw new AnalysisException("Unable to analyse file: " + inputFile.uri(), e); } } @@ -179,13 +174,13 @@ private static void checkInterrupted(Exception e) { } } - private void processRecognitionException(RecognitionException e, SensorContext sensorContext, CompatibleInputFile inputFile) { + private void processRecognitionException(RecognitionException e, SensorContext sensorContext, InputFile inputFile) { if (parsingErrorRuleKey != null) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(ParsingErrorCheck.MESSAGE) - .on(inputFile.wrapped()) + .on(inputFile) .at(inputFile.selectLine(e.getLine())); newIssue @@ -194,26 +189,22 @@ private void processRecognitionException(RecognitionException e, SensorContext s .save(); } - if (sensorContext.getSonarQubeVersion().isGreaterThanOrEqual(V6_0)) { - sensorContext.newAnalysisError() - .onFile(inputFile.wrapped()) - .at(inputFile.newPointer(e.getLine(), 0)) - .message(e.getMessage()) - .save(); - } + sensorContext.newAnalysisError() + .onFile(inputFile) + .at(inputFile.newPointer(e.getLine(), 0)) + .message(e.getMessage()) + .save(); } - private static void processException(Exception e, SensorContext sensorContext, CompatibleInputFile inputFile) { - if (sensorContext.getSonarQubeVersion().isGreaterThanOrEqual(V6_0)) { + private static void processException(Exception e, SensorContext sensorContext, InputFile inputFile) { sensorContext.newAnalysisError() - .onFile(inputFile.wrapped()) + .onFile(inputFile) .message(e.getMessage()) .save(); - } } - private void scanFile(SensorContext sensorContext, CompatibleInputFile inputFile, ProductDependentExecutor executor, List visitors, ProgramTree programTree) { - EsqlVisitorContext context = new EsqlVisitorContext(programTree, inputFile, sensorContext.settings()); + private void scanFile(SensorContext sensorContext, InputFile inputFile, ProductDependentExecutor executor, List visitors, ProgramTree programTree) { + EsqlVisitorContext context = new EsqlVisitorContext(programTree, inputFile, sensorContext.config()); List fileIssues = new ArrayList<>(); @@ -225,8 +216,8 @@ private void scanFile(SensorContext sensorContext, CompatibleInputFile inputFile } } - saveFileIssues(sensorContext, fileIssues, inputFile.wrapped()); - executor.highlightSymbols(inputFile.wrapped(), context); + saveFileIssues(sensorContext, fileIssues, inputFile); + executor.highlightSymbols(inputFile, context); } private void saveFileIssues(SensorContext sensorContext, List fileIssues, InputFile inputFile) { @@ -306,9 +297,9 @@ public void execute(SensorContext context) { } } - Iterable inputFiles = wrap(fileSystem.inputFiles(mainFilePredicate), context); + Iterable inputFiles = fileSystem.inputFiles(mainFilePredicate); Collection files = StreamSupport.stream(inputFiles.spliterator(), false) - .map(CompatibleInputFile::file) + .map(InputFile::file) .collect(Collectors.toList()); ProgressReport progressReport = new ProgressReport("Report about progress of ESQL analyzer", TimeUnit.SECONDS.toMillis(10)); @@ -339,14 +330,12 @@ private static class SonarQubeProductExecutor implements ProductDependentExecuto private final SensorContext context; private final NoSonarFilter noSonarFilter; private final FileLinesContextFactory fileLinesContextFactory; - private final boolean isAtLeastSq62; private MetricsVisitor metricsVisitor; SonarQubeProductExecutor(SensorContext context, NoSonarFilter noSonarFilter, FileLinesContextFactory fileLinesContextFactory) { this.context = context; this.noSonarFilter = noSonarFilter; this.fileLinesContextFactory = fileLinesContextFactory; - this.isAtLeastSq62 = context.getSonarQubeVersion().isGreaterThanOrEqual(V6_2); } @Override @@ -356,9 +345,12 @@ public List getProductDependentTreeVisitors() { metricsVisitor = new MetricsVisitor( context, ignoreHeaderComments, - fileLinesContextFactory, - isAtLeastSq62); - return Arrays.asList(metricsVisitor, new HighlighterVisitor(context)); + fileLinesContextFactory); + return Arrays.asList( + metricsVisitor, + new NoSonarVisitor(noSonarFilter, ignoreHeaderComments), + new HighlighterVisitor(context), + new CpdVisitor(context)); } @Override @@ -372,29 +364,18 @@ public void executeCoverageSensors() { if (metricsVisitor == null) { throw new IllegalStateException("Before starting coverage computation, metrics should have been calculated."); } - executeCoverageSensors(context, metricsVisitor.executableLines(), isAtLeastSq62); + executeCoverageSensors(context, metricsVisitor.executableLines()); } - private static void executeCoverageSensors(SensorContext context, Map> executableLines, boolean isAtLeastSq62) { - Settings settings = context.settings(); + private static void executeCoverageSensors(SensorContext context, Map> executableLines) { + Configuration configuration = context.config(); - String traces = settings.getString(EsqlPlugin.TRACE_PATHS_PROPERTY); + String[] traces = configuration.getStringArray(EsqlPlugin.TRACE_PATHS_PROPERTY); - if (traces != null && !traces.isEmpty()) { - (new TraceSensor()).execute(context, executableLines, traces.split(",")); - } + (new TraceSensor()).execute(context, executableLines, traces); } - - private static void logDeprecationForReportProperty(Settings settings, String propertyKey) { - String value = settings.getString(propertyKey); - if (value != null && !value.isEmpty()) { - LOG.warn("Since SonarQube 6.2 property '" + propertyKey + "' is deprecated. Use 'sonar.esql.lcov.reportPaths' instead."); - } - } - - } @VisibleForTesting @@ -417,11 +398,11 @@ public void executeCoverageSensors() { } private static boolean ignoreHeaderComments(SensorContext context) { - return context.settings().getBoolean(EsqlPlugin.IGNORE_HEADER_COMMENTS); + return context.config().getBoolean(EsqlPlugin.IGNORE_HEADER_COMMENTS).orElse(EsqlPlugin.IGNORE_HEADER_COMMENTS_DEFAULT_VALUE); } private static boolean isSonarLint(SensorContext context) { - return context.getSonarQubeVersion().isGreaterThanOrEqual(V6_0) && context.runtime().getProduct() == SonarProduct.SONARLINT; + return context.runtime().getProduct() == SonarProduct.SONARLINT; } private static void saveLineIssue(SensorContext sensorContext, InputFile inputFile, RuleKey ruleKey, LineIssue issue) { diff --git a/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/JsonProfileReader.java b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/JsonProfileReader.java index ac055f14..bcdc1209 100644 --- a/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/JsonProfileReader.java +++ b/esql-plugin/src/main/java/com/exxeta/iss/sonar/esql/JsonProfileReader.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-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlLanguageTest.java b/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlLanguageTest.java index 70a034f8..dc16bc87 100644 --- a/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlLanguageTest.java +++ b/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlLanguageTest.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"); @@ -21,17 +21,16 @@ import org.junit.Before; import org.junit.Test; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; public class EsqlLanguageTest { - private Settings settings; + private MapSettings settings; private EsqlLanguage esqlLanguage; @Before public void setUp() { settings = new MapSettings(); - esqlLanguage = new EsqlLanguage(settings); + esqlLanguage = new EsqlLanguage(settings.asConfig()); } @Test diff --git a/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlPluginTest.java b/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlPluginTest.java index c5130570..b9d41d92 100644 --- a/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlPluginTest.java +++ b/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlPluginTest.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-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlProfileTest.java b/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlProfileTest.java index e34f4f65..4af07c79 100644 --- a/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlProfileTest.java +++ b/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlProfileTest.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"); @@ -77,7 +77,7 @@ public Rule answer(InvocationOnMock invocation) { } /** - * SonarLint will inject a rule finder containing only the rules coming from the javascript repository + * SonarLint will inject a rule finder containing only the rules coming from the esql repository */ private RuleFinder sonarLintRuleFinder() { return when(mock(RuleFinder.class).findByKey(anyString(), anyString())).thenAnswer(invocation -> { diff --git a/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlSquidSensorTest.java b/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlSquidSensorTest.java index 62fff35a..6d348ea4 100644 --- a/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlSquidSensorTest.java +++ b/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/EsqlSquidSensorTest.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,6 @@ */ package com.exxeta.iss.sonar.esql; -import static com.exxeta.iss.sonar.esql.compat.CompatibilityHelper.wrap; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; @@ -25,6 +24,8 @@ import static org.mockito.Mockito.when; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.InterruptedIOException; import java.nio.charset.StandardCharsets; import java.util.Collection; @@ -41,6 +42,7 @@ import org.sonar.api.batch.fs.internal.DefaultTextPointer; import org.sonar.api.batch.fs.internal.DefaultTextRange; import org.sonar.api.batch.fs.internal.FileMetadata; +import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.CheckFactory; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; @@ -71,16 +73,11 @@ import com.exxeta.iss.sonar.esql.api.visitors.TreeVisitor; import com.exxeta.iss.sonar.esql.api.visitors.TreeVisitorContext; import com.exxeta.iss.sonar.esql.check.CheckList; -import com.exxeta.iss.sonar.esql.compat.CompatibleInputFile; import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; import com.sonar.sslr.api.RecognitionException; public class EsqlSquidSensorTest { - private static final SonarRuntime SONAR_RUNTIME_6_1 = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), - SonarQubeSide.SERVER); - private static final SonarRuntime SONAR_RUNTIME_6_2 = SonarRuntimeImpl.forSonarQube(Version.create(6, 2), - SonarQubeSide.SERVER); private static final Version SONARLINT_DETECTABLE_VERSION = Version.create(6, 0); private static final SonarRuntime SONARLINT_RUNTIME = SonarRuntimeImpl.forSonarLint(SONARLINT_DETECTABLE_VERSION); @@ -227,12 +224,16 @@ public void save_issue() throws Exception { inputFile("file.esql"); ActiveRules activeRules = (new ActiveRulesBuilder()) - .create(RuleKey.of(CheckList.REPOSITORY_KEY, "MissingNewlineAtEndOfFile")).activate().build(); + .create(RuleKey.of(CheckList.REPOSITORY_KEY, "MissingNewlineAtEndOfFile")) + .activate() + .create(RuleKey.of(CheckList.REPOSITORY_KEY, "InitializeVariables")) + .activate() + .build(); checkFactory = new CheckFactory(activeRules); createSensor().execute(context); Collection issues = context.allIssues(); - assertThat(issues).hasSize(1); + assertThat(issues).hasSize(2); } @Test @@ -248,12 +249,12 @@ public void custom_rule() throws Exception { assertThat(issue.gap()).isEqualTo(42); assertThat(issue.primaryLocation().message()).isEqualTo("Message of custom rule"); assertThat(issue.primaryLocation().textRange()) - .isEqualTo(new DefaultTextRange(new DefaultTextPointer(1, 0), new DefaultTextPointer(1, 28))); + .isEqualTo(new DefaultTextRange(new DefaultTextPointer(1, 0), new DefaultTextPointer(1, 24))); } @Test public void progress_report_should_be_stopped() throws Exception { - CompatibleInputFile inputFile = inputFile("cpd/Person.esql"); + InputFile inputFile = inputFile("cpd/Person.esql"); createSensor().analyseFiles(context, ImmutableList.of(), ImmutableList.of(inputFile), executor, progressReport); verify(progressReport).stop(); } @@ -298,7 +299,7 @@ public void cancelled_context_should_cancel_progress_report_and_return_with_no_e verify(progressReport).cancel(); } - private void analyseFileWithException(EsqlCheck check, CompatibleInputFile inputFile, + private void analyseFileWithException(EsqlCheck check,InputFile inputFile, String expectedMessageSubstring) { EsqlSquidSensor sensor = createSensor(); thrown.expect(AnalysisException.class); @@ -311,22 +312,25 @@ private void analyseFileWithException(EsqlCheck check, CompatibleInputFile input } } - - - - private CompatibleInputFile inputFile(String relativePath) { - DefaultInputFile inputFile = new DefaultInputFile("moduleKey", relativePath) + private InputFile inputFile(String relativePath) { + DefaultInputFile inputFile = new TestInputFileBuilder("moduleKey", relativePath) .setModuleBaseDir(baseDir.toPath()) .setType(Type.MAIN) .setLanguage(EsqlLanguage.KEY) - .setCharset(StandardCharsets.UTF_8); + .setCharset(StandardCharsets.UTF_8) + .build(); context.fileSystem().add(inputFile); - inputFile.initMetadata(new FileMetadata().readMetadata(inputFile.file(), Charsets.UTF_8)); - return wrap(inputFile); + try { + inputFile.setMetadata(new FileMetadata().readMetadata(new FileInputStream(inputFile.file()), Charsets.UTF_8, inputFile.absolutePath())); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return inputFile; } private final class ExceptionRaisingCheck extends DoubleDispatchVisitorCheck { diff --git a/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/rules/EsqlRulesDefinitionTest.java b/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/rules/EsqlRulesDefinitionTest.java index 69a15b87..b25f68ad 100644 --- a/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/rules/EsqlRulesDefinitionTest.java +++ b/esql-plugin/src/test/java/com/exxeta/iss/sonar/esql/rules/EsqlRulesDefinitionTest.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-plugin/src/test/resources/file.esql b/esql-plugin/src/test/resources/file.esql index 0a8d819c..7ee71fe2 100644 --- a/esql-plugin/src/test/resources/file.esql +++ b/esql-plugin/src/test/resources/file.esql @@ -1 +1 @@ -DECLARE A CONSTANT CHAR 'A'; \ No newline at end of file +DECLARE A CONSTANT CHAR; \ No newline at end of file diff --git a/pom.xml b/pom.xml index 75dbeb8c..73b12a6b 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.exxeta.iss sonar-esql-plugin - 2.2.0 + 2.3.0 pom http://exxeta.com @@ -48,7 +48,7 @@ - 5.6 + 6.7 1.17 1.8 UTF-8 @@ -62,9 +62,9 @@ 1.0.13 1.9.0 1.7.21 - 6.2 - 3.13 - 2.5.0.36 + 6.7 + 3.14.0.887 + 3.0.0.1140 1.22 2.6.1 2.6.2 @@ -73,9 +73,9 @@ 2.4 3.4 - 2.7 + 3.0.2 2.4.3 - 2.6 + 3.0.2 1.4 @@ -83,7 +83,7 @@ 3.5.1 2.9 2.8.2 - 1.4.1 + 3.0.0-M1 2.18 2.0 2.5.2 @@ -254,6 +254,11 @@ ${slf4j.version} provided + + com.exxeta.iss + sonar-msgflow-plugin + 1.1.1 + @@ -652,7 +657,7 @@ org.jacoco jacoco-maven-plugin - 0.7.5.201505241946 + 0.7.9 diff --git a/travis.sh b/travis.sh new file mode 100755 index 00000000..f3bbfe5b --- /dev/null +++ b/travis.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -euo pipefail + +function configureTravis { + mkdir -p ~/.local + curl -sSL https://github.com/SonarSource/travis-utils/tarball/v42 | tar zx --strip-components 1 -C ~/.local + source ~/.local/bin/install +} +configureTravis +. ~/.local/bin/installMaven35 + +export DEPLOY_PULL_REQUEST=true +regular_mvn_build_deploy_analyze