Java Code Examples for org.sonar.plugins.java.api.JavaFileScannerContext#reportIssue()
The following examples show how to use
org.sonar.plugins.java.api.JavaFileScannerContext#reportIssue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HardCodedSleepCheck.java From sonar-webdriver-plugin with MIT License | 6 votes |
@Override public void visitMethodInvocation(MethodInvocationTree tree) { JavaFileScannerContext context = getContext(); if (!tree.methodSelect().is(Tree.Kind.IDENTIFIER)) { MemberSelectExpressionTree memberSelectExpressionTree = ((MemberSelectExpressionTree) tree.methodSelect()); String methodName = memberSelectExpressionTree.identifier().name(); String fullyQualifiedNameOfExpression = memberSelectExpressionTree.expression().symbolType() .fullyQualifiedName(); if (SLEEP_METHOD_NAME.equals(methodName) && fullyQualifiedNameOfExpression.equals(THREAD)) { context.reportIssue(this, tree, "Avoid using hard coded sleeps, use explicit wait instead"); } } }
Example 2
Source File: ImplicitWaitCheck.java From sonar-webdriver-plugin with MIT License | 6 votes |
@Override public void visitMethodInvocation(MethodInvocationTree tree) { JavaFileScannerContext context = getContext(); if (!tree.methodSelect().is(Tree.Kind.IDENTIFIER)) { MemberSelectExpressionTree memberSelectExpressionTree = ((MemberSelectExpressionTree) tree.methodSelect()); String methodName = memberSelectExpressionTree.identifier().name(); String fullyQualifiedNameOfExpression = memberSelectExpressionTree.expression().symbolType() .fullyQualifiedName(); if (IMPLICITLY_WAIT_METHOD_NAME.equals(methodName) && isPartOfWebDriverPackage(fullyQualifiedNameOfExpression)) { context.reportIssue(this, tree, "Avoid using implicit wait, use explicit wait instead"); } } }
Example 3
Source File: AssertionInNonTestCheck.java From sonar-webdriver-plugin with MIT License | 5 votes |
@Override public void visitMethodInvocation(MethodInvocationTree tree) { JavaFileScannerContext context = getContext(); if (methodInvocationIsAssertion(tree)) { context.reportIssue(this, tree, "Should not use assertions in non-test classes."); } }
Example 4
Source File: BaseLocatorValueCheck.java From sonar-webdriver-plugin with MIT License | 5 votes |
private void reportLinkTextAndTagNameLocatorIssue(ExpressionTree expressionTree, String locatorKey) { JavaFileScannerContext context = getContext(); if (LOCATORS_TO_AVOID.contains(locatorKey)) { context.reportIssue(this, expressionTree, "Avoid using " + locatorKey + " locator, try using " + LOCATORS_RECOMMENDED.toString()); } }
Example 5
Source File: BaseLocatorValueCheck.java From sonar-webdriver-plugin with MIT License | 5 votes |
private void reportXpathLocatorIssue(ExpressionTree expressionTree, String locatorKey) { JavaFileScannerContext context = getContext(); if (XPATH_LOCATORS.contains(locatorKey.toLowerCase())) { context.reportIssue(this, expressionTree, "Xpath locator is not recommended, try using " + LOCATORS_RECOMMENDED.toString()); } }
Example 6
Source File: BaseLocatorValueCheck.java From sonar-webdriver-plugin with MIT License | 5 votes |
private void reportXpathIssue(ExpressionTree expressionTree, String locatorKey, String locatorValue) { JavaFileScannerContext context = getContext(); if (XPATH_LOCATORS.contains(locatorKey.toLowerCase()) && !locatorValue .matches(RECOMMENDED_XPATH_LOCATOR_REGEX)) { context.reportIssue(this, expressionTree, "Avoid using xpath locator tied to page layout"); } }
Example 7
Source File: BaseLocatorValueCheck.java From sonar-webdriver-plugin with MIT License | 5 votes |
private void reportCssIssue(ExpressionTree expressionTree, String locatorKey, String locatorValue) { JavaFileScannerContext context = getContext(); if (CSS_LOCATORS.contains(locatorKey.toLowerCase()) && locatorValue.matches(AVOID_CSS_LOCATOR_REGEX)) { context.reportIssue(this, expressionTree, "Avoid using css locator tied to page layout"); } }
Example 8
Source File: BaseLocatorValueCheck.java From sonar-webdriver-plugin with MIT License | 5 votes |
private void reportIdIssue(ExpressionTree expressionTree, String locatorKey, String locatorValue) { JavaFileScannerContext context = getContext(); if (ID_LOCATORS.contains(locatorKey.toLowerCase()) && !locatorValue.matches(VALID_ID_LOCATOR_REGEX)) { context.reportIssue(this, expressionTree, "Invalid id locator"); } }
Example 9
Source File: BaseLocatorValueCheck.java From sonar-webdriver-plugin with MIT License | 5 votes |
private void reportClassNameIssue(ExpressionTree expressionTree, String locatorKey, String locatorValue) { JavaFileScannerContext context = getContext(); if (CLASS_NAME_LOCATORS.contains(locatorKey.toLowerCase()) && locatorValue.contains(SPACE)) { context.reportIssue(this, expressionTree, "Avoid compound class names with by class name locator strategy"); } }
Example 10
Source File: ExplicitWaitInTestCheck.java From sonar-webdriver-plugin with MIT License | 5 votes |
@Override public void visitNewClass(NewClassTree tree) { JavaFileScannerContext context = getContext(); String fullyQualifiedName = tree.symbolType().fullyQualifiedName(); String identifier = tree.identifier().toString().toLowerCase(); if (identifier.contains(WAIT) && isPartOfWebDriverPackage(fullyQualifiedName)) { context.reportIssue(this, tree, "Avoid using explicit waits in Test classes."); } }
Example 11
Source File: WebDriverCommandInTestCheck.java From sonar-webdriver-plugin with MIT License | 5 votes |
@Override public void visitMethodInvocation(MethodInvocationTree tree) { JavaFileScannerContext context = getContext(); if (methodInvocationIsPartOfWebDriverPackage(tree)) { context.reportIssue(this, tree, "Should not use WebDriver commands in Test classes."); } }