Java Code Examples for org.sonar.plugins.java.api.tree.LiteralTree#is()

The following examples show how to use org.sonar.plugins.java.api.tree.LiteralTree#is() . 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: HardcodedIpCheck.java    From vjtools with Apache License 2.0 6 votes vote down vote up
@Override
public void visitLiteral(LiteralTree tree) {
	if (tree.is(Tree.Kind.STRING_LITERAL)) {
		String value = LiteralUtils.trimQuotes(tree.value());
		IP.reset(value);
		if (IP.matches()) {
			String ip = IP.group("ip");

			// VJ:ADD 忽略127.0.0.1
			if ("127.0.0.1".equals(ip)) {
				return;
			}
			// VJ:END
			if (areAllBelow256(Splitter.on('.').split(ip))) {
				context.reportIssue(this, tree, "Make this IP \"" + ip + "\" address configurable.");
			}
		}
	}
}
 
Example 2
Source File: HardcodedIpCheck.java    From vjtools with Apache License 2.0 6 votes vote down vote up
@Override
public void visitLiteral(LiteralTree tree) {
	if (tree.is(Tree.Kind.STRING_LITERAL)) {
		String value = LiteralUtils.trimQuotes(tree.value());
		IP.reset(value);
		if (IP.matches()) {
			String ip = IP.group("ip");

			// VJ:ADD 忽略127.0.0.1
			if ("127.0.0.1".equals(ip)) {
				return;
			}
			// VJ:END
			if (areAllBelow256(Splitter.on('.').split(ip))) {
				context.reportIssue(this, tree, "Make this IP \"" + ip + "\" address configurable.");
			}
		}
	}
}
 
Example 3
Source File: AnnotationsConstantsCheck.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Override
public void visitLiteral(LiteralTree tree) {
    if (inAnnotation && tree.is(Kind.STRING_LITERAL)) {
        String literalValue = removeQuotes(tree.value());
        if (ConstantsChecker.isAnnotationConstant(literalValue)) {
            context.reportIssue(this, tree,
                String.format("Use constant %s instead of hardcoded value.", ConstantsChecker.getAnnotationMessageForConstant(literalValue)));
        }
    }
    super.visitLiteral(tree);
}