Skip to content

Commit 696015c

Browse files
committed
All java7/8 compatible checks executed when source version is not set
1 parent 05c0394 commit 696015c

33 files changed

Lines changed: 488 additions & 57 deletions

java-checks/src/main/java/org/sonar/java/checks/AbstractClassNoFieldShouldBeInterfaceCheck.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class AbstractClassNoFieldShouldBeInterfaceCheck extends IssuableSubscrip
5050

5151
@Override
5252
public boolean isCompatibleWithJavaVersion(Integer version) {
53-
return JavaVersionHelper.java8Guaranteed(version);
53+
return JavaVersionHelper.java8Compatible(version);
5454
}
5555

5656
@Override
@@ -62,7 +62,9 @@ public List<Tree.Kind> nodesToVisit() {
6262
public void visitNode(Tree tree) {
6363
ClassTree classTree = (ClassTree) tree;
6464
if (classTree.superClass() == null && classIsAbstract(classTree) && classHasNoFieldAndProtectedMethod(classTree)) {
65-
addIssue(classTree, "Convert the abstract class \"" + classTree.simpleName().name() + "\" into an interface.");
65+
addIssue(
66+
classTree,
67+
"Convert the abstract class \"" + classTree.simpleName().name() + "\" into an interface." + JavaVersionHelper.java8CompatibilityMessage(context.getJavaVersion()));
6668
}
6769
}
6870

java-checks/src/main/java/org/sonar/java/checks/AnonymousClassShouldBeLambdaCheck.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.sonar.squidbridge.annotations.SqaleSubCharacteristic;
4242

4343
import javax.annotation.Nullable;
44+
4445
import java.util.List;
4546

4647
@Rule(
@@ -58,7 +59,7 @@ public class AnonymousClassShouldBeLambdaCheck extends BaseTreeVisitor implement
5859

5960
@Override
6061
public boolean isCompatibleWithJavaVersion(@Nullable Integer version) {
61-
return JavaVersionHelper.java8Guaranteed(version);
62+
return JavaVersionHelper.java8Compatible(version);
6263
}
6364

6465
@Override
@@ -82,7 +83,7 @@ public void visitNewClass(NewClassTree tree) {
8283
if (classBody != null) {
8384
TypeTree identifier = tree.identifier();
8485
if (!useThisIdentifier(classBody) && !enumConstants.contains(identifier) && hasOnlyOneMethod(classBody.members())) {
85-
context.addIssue(identifier, this, "Make this anonymous inner class a lambda");
86+
context.addIssue(identifier, this, "Make this anonymous inner class a lambda" + JavaVersionHelper.java8CompatibilityMessage(context.getJavaVersion()));
8687
}
8788
}
8889
}

java-checks/src/main/java/org/sonar/java/checks/DateUtilsTruncateCheck.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.sonar.squidbridge.annotations.SqaleSubCharacteristic;
3535

3636
import javax.annotation.Nullable;
37+
3738
import java.util.List;
3839

3940
@Rule(
@@ -48,7 +49,7 @@ public class DateUtilsTruncateCheck extends AbstractMethodDetection implements J
4849

4950
@Override
5051
public boolean isCompatibleWithJavaVersion(@Nullable Integer version) {
51-
return JavaVersionHelper.java8Guaranteed(version);
52+
return JavaVersionHelper.java8Compatible(version);
5253
}
5354

5455
@Override
@@ -61,7 +62,7 @@ protected List<MethodMatcher> getMethodInvocationMatchers() {
6162

6263
@Override
6364
protected void onMethodInvocationFound(MethodInvocationTree mit) {
64-
addIssue(mit, "Use \"Instant.truncatedTo\" instead.");
65+
addIssue(mit, "Use \"Instant.truncatedTo\" instead." + JavaVersionHelper.java8CompatibilityMessage(context.getJavaVersion()));
6566
}
6667

6768
private static MethodMatcher truncateMethodMatcher(String firstParameterType) {

java-checks/src/main/java/org/sonar/java/checks/DiamondOperatorCheck.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class DiamondOperatorCheck extends SubscriptionBaseVisitor implements Jav
6262

6363
@Override
6464
public boolean isCompatibleWithJavaVersion(Integer version) {
65-
return JavaVersionHelper.java7Guaranteed(version);
65+
return JavaVersionHelper.java7Compatible(version);
6666
}
6767

6868
@Override
@@ -77,7 +77,10 @@ public void visitNode(Tree tree) {
7777
if (newClassTree.classBody() == null && isParameterizedType(newTypeTree)) {
7878
TypeTree type = getTypeFromExpression(tree.parent());
7979
if (type != null && isParameterizedType(type)) {
80-
reportIssue(((ParameterizedTypeTree) newTypeTree).typeArguments(), "Replace the type specification in this constructor call.");
80+
reportIssue(
81+
((ParameterizedTypeTree) newTypeTree).typeArguments(),
82+
"Replace the type specification in this constructor call with the diamond operator (\"<>\")." +
83+
JavaVersionHelper.java7CompatibilityMessage(context.getJavaVersion()));
8184
}
8285
}
8386
}

java-checks/src/main/java/org/sonar/java/checks/FileCreateTempFileCheck.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ public void visitMethodInvocation(MethodInvocationTree mit) {
129129
if (FILE_DELETE.matches(mit)) {
130130
checkAndAdvanceState(mit, State.CREATE_TMP_FILE, State.DELETE);
131131
} else if (FILE_MKDIR.matches(mit) && State.MKDIR.equals(checkAndAdvanceState(mit, State.DELETE, State.MKDIR))) {
132-
context.addIssue(mit, this, "Use \"Files.createTempDirectory\" or a library function to create this directory instead.");
132+
context.addIssue(
133+
mit,
134+
this,
135+
"Use \"Files.createTempDirectory\" or a library function to create this directory instead." +
136+
JavaVersionHelper.java7CompatibilityMessage(context.getJavaVersion()));
133137
}
134138
}
135139

java-checks/src/main/java/org/sonar/java/checks/LambdaOptionalParenthesisCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void visitNode(Tree tree) {
6363
VariableTree param = let.parameters().get(0);
6464
String ident = param.simpleName().name();
6565
if(param.type().is(Tree.Kind.INFERED_TYPE)) {
66-
addIssue(param, "Remove the parentheses around the \"" + ident + "\" parameter");
66+
addIssue(param, "Remove the parentheses around the \"" + ident + "\" parameter" + JavaVersionHelper.java8CompatibilityMessage(context.getJavaVersion()));
6767
}
6868
}
6969
}

java-checks/src/main/java/org/sonar/java/checks/LambdaSingleExpressionCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void visitNode(Tree tree) {
6767
if (singleStatementIsReturn(lambdaExpressionTree)) {
6868
message += " and then remove useless return keyword";
6969
}
70-
addIssue(lambdaExpressionTree.body(), message);
70+
addIssue(lambdaExpressionTree.body(), message + JavaVersionHelper.java8CompatibilityMessage(context.getJavaVersion()));
7171
}
7272
}
7373

java-checks/src/main/java/org/sonar/java/checks/RepeatAnnotationCheck.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.sonar.squidbridge.annotations.SqaleSubCharacteristic;
4040

4141
import javax.annotation.Nullable;
42+
4243
import java.util.List;
4344

4445
@Rule(
@@ -55,7 +56,7 @@ public class RepeatAnnotationCheck extends BaseTreeVisitor implements JavaFileSc
5556

5657
@Override
5758
public boolean isCompatibleWithJavaVersion(@Nullable Integer version) {
58-
return JavaVersionHelper.java8Guaranteed(version);
59+
return JavaVersionHelper.java8Compatible(version);
5960
}
6061

6162
@Override
@@ -69,7 +70,10 @@ public void visitAnnotation(AnnotationTree annotationTree) {
6970
if (isArrayInitialized(annotationTree)) {
7071
NewArrayTree arrayTree = (NewArrayTree) annotationTree.arguments().get(0);
7172
if (isAllSameAnnotation(arrayTree.initializers()) && isAnnotationRepeatable(arrayTree.initializers().get(0))) {
72-
context.addIssue(annotationTree, this, "Remove the '" + getAnnotationName(annotationTree) + "' wrapper from this annotation group");
73+
context.addIssue(
74+
annotationTree,
75+
this,
76+
"Remove the '" + getAnnotationName(annotationTree) + "' wrapper from this annotation group" + JavaVersionHelper.java8CompatibilityMessage(context.getJavaVersion()));
7377
}
7478
}
7579
super.visitAnnotation(annotationTree);

java-checks/src/main/java/org/sonar/java/checks/ReplaceLambdaByMethodRefCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void scanFile(JavaFileScannerContext context) {
7171
@Override
7272
public void visitLambdaExpression(LambdaExpressionTree tree) {
7373
if (isSingleMethodInvocationUsingLambdaParamAsArg(tree) || isBlockInvokingMethod(tree.body())) {
74-
context.addIssue(tree, this, "Replace this lambda with a method reference.");
74+
context.addIssue(tree, this, "Replace this lambda with a method reference." + JavaVersionHelper.java8CompatibilityMessage(context.getJavaVersion()));
7575
}
7676
super.visitLambdaExpression(tree);
7777
}

java-checks/src/main/java/org/sonar/java/checks/SAMAnnotatedCheck.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@
5858
public class SAMAnnotatedCheck extends IssuableSubscriptionVisitor implements JavaVersionAwareVisitor {
5959

6060
private static final ImmutableMultimap<String, List<String>> OBJECT_METHODS = new ImmutableMultimap.Builder<String, List<String>>().
61-
put("equals", ImmutableList.of("Object")).
62-
put("getClass", ImmutableList.<String>of()).
63-
put("hashcode", ImmutableList.<String>of()).
64-
put("notify", ImmutableList.<String>of()).
65-
put("notifyAll", ImmutableList.<String>of()).
66-
put("toString", ImmutableList.<String>of()).
67-
put("wait", ImmutableList.<String>of()).
68-
put("wait", ImmutableList.of("long")).
69-
put("wait", ImmutableList.of("long", "int")).
70-
build();
61+
put("equals", ImmutableList.of("Object")).
62+
put("getClass", ImmutableList.<String>of()).
63+
put("hashcode", ImmutableList.<String>of()).
64+
put("notify", ImmutableList.<String>of()).
65+
put("notifyAll", ImmutableList.<String>of()).
66+
put("toString", ImmutableList.<String>of()).
67+
put("wait", ImmutableList.<String>of()).
68+
put("wait", ImmutableList.of("long")).
69+
put("wait", ImmutableList.of("long", "int")).
70+
build();
7171

7272
@Override
7373
public boolean isCompatibleWithJavaVersion(Integer version) {
74-
return JavaVersionHelper.java8Guaranteed(version);
74+
return JavaVersionHelper.java8Compatible(version);
7575
}
7676

7777
@Override
@@ -83,7 +83,10 @@ public List<Tree.Kind> nodesToVisit() {
8383
public void visitNode(Tree tree) {
8484
ClassTree classTree = (ClassTree) tree;
8585
if (hasOneAbstractMethod(classTree) && !isAnnotated(classTree)) {
86-
addIssue(tree, "Annotate the \"" + classTree.simpleName().name() + "\" interface with the @FunctionInterface annotation");
86+
addIssue(
87+
tree,
88+
"Annotate the \"" + classTree.simpleName().name() + "\" interface with the @FunctionInterface annotation" +
89+
JavaVersionHelper.java8CompatibilityMessage(context.getJavaVersion()));
8790
}
8891
}
8992

0 commit comments

Comments
 (0)