use of org.sonar.java.reporting.InternalJavaIssueBuilder in project sonar-java by SonarSource.
the class AssertJChainSimplificationCheck method createIssueBuilder.
private InternalJavaIssueBuilder createIssueBuilder(MethodInvocationTree predicate, AssertJChainSimplificationIndex.Simplification simplification) {
InternalJavaIssueBuilder builder = QuickFixHelper.newIssue(context).forRule(this).onTree(ExpressionUtils.methodName(predicate)).withMessage(ISSUE_MESSAGE_FORMAT_STRING, simplification.getReplacement());
simplification.getQuickFix().ifPresent(builder::withQuickFixes);
return builder;
}
use of org.sonar.java.reporting.InternalJavaIssueBuilder in project sonar-java by SonarSource.
the class BigDecimalDoubleConstructorCheck method visitNode.
@Override
public void visitNode(Tree tree) {
NewClassTree newClassTree = (NewClassTree) tree;
if (BIG_DECIMAL_DOUBLE_FLOAT.matches(newClassTree)) {
InternalJavaIssueBuilder builder = ((InternalJavaIssueBuilder) ((DefaultJavaFileScannerContext) context).newIssue()).forRule(this).onTree(tree);
Arguments arguments = newClassTree.arguments();
if (arguments.size() == 1) {
builder.withMessage("Use \"BigDecimal.valueOf\" instead.");
builder.withQuickFix(() -> valueOfQuickFix(newClassTree));
} else {
builder.withMessage("Use \"new BigDecimal(String, MathContext)\" instead.");
ExpressionTree firstArgument = arguments.get(0);
if (firstArgument instanceof LiteralTree) {
builder.withQuickFix(() -> stringConstructorQuickFix((LiteralTree) firstArgument));
}
}
builder.report();
}
}
use of org.sonar.java.reporting.InternalJavaIssueBuilder in project sonar-java by SonarSource.
the class CompareToResultTestCheck method reportIssue.
private void reportIssue(BinaryExpressionTree binaryExpression, long operandValue, boolean compareToIsLeft) {
InternalJavaIssueBuilder builder = QuickFixHelper.newIssue(context).forRule(this).onTree(binaryExpression.operatorToken()).withMessage("Only the sign of the result should be examined.");
if (binaryExpression.is(Kind.EQUAL_TO)) {
// For !=, even if we could in theory replace by <=/>= 0, we do not suggest quick fixes and let the user figure out what was his intent
builder.withQuickFix(() -> getQuickFix(binaryExpression, operandValue, compareToIsLeft));
}
builder.report();
}
use of org.sonar.java.reporting.InternalJavaIssueBuilder in project sonar-java by SonarSource.
the class DateFormatWeekYearCheck method inspectPattern.
private void inspectPattern(ExpressionTree argument) {
Optional<String> literal = argument.asConstant(String.class);
if (!literal.isPresent()) {
return;
}
String datePattern = literal.get();
if (StringUtils.contains(datePattern, 'w')) {
return;
}
int start = datePattern.indexOf('Y');
if (start > -1) {
int end = getEndIndexOfYearSequence(datePattern, start);
String firstYSeq = datePattern.substring(start, end);
String replacement = firstYSeq.toLowerCase(Locale.ENGLISH);
String message = String.format(RECOMMENDATION_YEAR_MESSAGE, firstYSeq, replacement);
InternalJavaIssueBuilder issueBuilder = QuickFixHelper.newIssue(context).forRule(this).onTree(argument).withMessage(message);
if (argument.is(Tree.Kind.STRING_LITERAL)) {
issueBuilder.withQuickFix(() -> computeQuickFix(argument, start, end, replacement));
}
issueBuilder.report();
}
}
Aggregations