Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
8705656
Honor SuppressWarnings of unused on the first type for unused imports
antonioaversa Dec 4, 2026
7ccb007
Report no unused import in a unit with an unresolved name
antonioaversa Dec 4, 2026
29dee07
Keep every owner of a statically imported name and bind a call to the…
antonioaversa Dec 4, 2026
1b0346b
Scan the annotations of a type parameter for the imports they use
antonioaversa Dec 4, 2026
a6a8113
Count a used own-package single-type import as used
antonioaversa Dec 4, 2026
a92bd55
Count a statically imported nested type as used by its constructor calls
antonioaversa Dec 4, 2026
7903c2e
Read the annotations written on an enum constant
antonioaversa Dec 4, 2026
f1d4df9
Infer Object for the open type variables of a generic call that no ty…
antonioaversa Dec 4, 2026
cd694f0
Replay the unused import, deprecated enum constant and generic cast o…
antonioaversa Dec 4, 2026
f21dae2
Revert "Count a used own-package single-type import as used"
antonioaversa Dec 4, 2026
41874c5
Report no unused import for a type the unit declares, instead of gati…
antonioaversa Dec 4, 2026
1062113
Keep the type arguments of a supertype written in a class header for …
antonioaversa Dec 5, 2026
849e49f
Do not treat a cast to a bounded wildcard argument as a widening unle…
antonioaversa Dec 5, 2026
3a3c04a
Ignore JDK deprecations newer than the configured language level
antonioaversa Dec 5, 2026
fc1735d
Mark the generic methods read from compiled classes as parametrized
antonioaversa Dec 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.sonar.java.model.ExpressionUtils;
import org.sonar.java.model.JavaTree;
import org.sonar.java.model.expression.IdentifierTreeImpl;
import org.sonar.plugins.java.api.diagnostics.ProblemKind;
import org.sonar.plugins.java.api.semantic.Symbol;
import org.sonar.plugins.java.api.semantic.Type;
import org.sonar.plugins.java.api.tree.AnnotationTree;
import org.sonar.plugins.java.api.tree.AssignmentExpressionTree;
import org.sonar.plugins.java.api.tree.BaseTreeVisitor;
import org.sonar.plugins.java.api.tree.BinaryExpressionTree;
Expand All @@ -44,15 +46,18 @@
import org.sonar.plugins.java.api.tree.IdentifierTree;
import org.sonar.plugins.java.api.tree.ImportClauseTree;
import org.sonar.plugins.java.api.tree.ImportTree;
import org.sonar.plugins.java.api.tree.LiteralTree;
import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree;
import org.sonar.plugins.java.api.tree.MethodReferenceTree;
import org.sonar.plugins.java.api.tree.MethodTree;
import org.sonar.plugins.java.api.tree.ModuleDeclarationTree;
import org.sonar.plugins.java.api.tree.NewArrayTree;
import org.sonar.plugins.java.api.tree.PackageDeclarationTree;
import org.sonar.plugins.java.api.tree.SyntaxToken;
import org.sonar.plugins.java.api.tree.SyntaxTrivia;
import org.sonar.plugins.java.api.tree.Tree;
import org.sonar.plugins.java.api.tree.TryStatementTree;
import org.sonar.plugins.java.api.tree.TypeParameterTree;
import org.sonar.plugins.java.api.tree.TypeTree;
import org.sonar.plugins.java.api.tree.UnionTypeTree;
import org.sonar.plugins.java.api.tree.VariableTree;
Expand Down Expand Up @@ -151,6 +156,12 @@
scan(tree.method().annotations());
}

@Override
public void visitTypeParameter(TypeParameterTree tree) {
scan(tree.identifier().annotations());
super.visitTypeParameter(tree);
}

@Override
public void visitTypeCast(org.sonar.plugins.java.api.tree.TypeCastTree tree) {
Type cast = tree.type().symbolType();
Expand Down Expand Up @@ -206,14 +217,17 @@

/** Flow analysis is not done for a unit that has unresolved names. */
private void reportUnreachableCatches(JavaTree.CompilationUnitTreeImpl unit) {
String currentPackage = unit.packageDeclaration() == null ? "" : dotted(unit.packageDeclaration().packageName());
boolean unresolved = identifiers.stream().anyMatch(identifier -> identifier.symbol().isUnknown() && !isUnnamed(identifier))
|| unit.imports().stream().anyMatch(clause -> clause instanceof ImportTree tree && !isResolvable(tree, dotted(tree.qualifiedIdentifier()), currentPackage));
if (!unresolved) {
if (!hasUnresolvedNames(unit)) {
tries.forEach(this::reportUnreachableCatches);
}
}

private boolean hasUnresolvedNames(JavaTree.CompilationUnitTreeImpl unit) {
String currentPackage = unit.packageDeclaration() == null ? "" : dotted(unit.packageDeclaration().packageName());
return identifiers.stream().anyMatch(identifier -> identifier.symbol().isUnknown() && !isUnnamed(identifier))
|| unit.imports().stream().anyMatch(clause -> clause instanceof ImportTree tree && !isResolvable(tree, dotted(tree.qualifiedIdentifier()), currentPackage));
}
Comment thread
gitar-bot[bot] marked this conversation as resolved.
Resolved

private static boolean isUnnamed(IdentifierTree identifier) {
return identifier instanceof IdentifierTreeImpl impl && impl.isUnnamedVariable();
}
Expand Down Expand Up @@ -362,12 +376,16 @@
return text.length();
}

private void reportUnusedImports(JavaTree.CompilationUnitTreeImpl unit) {

Check failure on line 379 in java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CompilerWarnings.java

View check run for this annotation

SonarQube-Next / SonarQube Code Analysis

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.

[S3776] Cognitive Complexity of methods should not be too high See more on https://next.sonarqube.com/sonarqube/project/issues?id=org.sonarsource.java%3Ajava&pullRequest=6620&issues=26f6cb29-bf6d-4686-84e8-1a9b00654279&open=26f6cb29-bf6d-4686-84e8-1a9b00654279
if (unit.moduleDeclaration() != null) {
// The compiler reports no unused import in a module declaration unit.
return;
}
if (suppressesUnused(unit)) {
return;
}
Set<String> seen = new HashSet<>();
Set<String> declared = declaredTypeNames(unit);
String currentPackage = unit.packageDeclaration() == null ? "" : dotted(unit.packageDeclaration().packageName());
loadImportedTypes(unit);
List<IdentifierTree> outOfScope = identifiers.stream().filter(identifier -> !isInFileScope(identifier)).toList();
Expand All @@ -378,12 +396,38 @@
String name = dotted(importTree.qualifiedIdentifier());
String key = (importTree.isStatic() ? "static " : "") + name;
boolean duplicate = !seen.add(key);
Comment on lines 384 to 398

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Quality: PR description still claims unresolved-name units report no unused import

This commit removes the hasUnresolvedNames(unit) check from reportUnusedImports, and adds the ownType check in its place. A unit with an unresolved name now gets unused-import warnings again. The PR description table still has the row "a unit with an unresolved name reports no unused import" (S1128, 2 → 0). The row "a used single-type import of the unit's own package counts as used" is also still there, even though commit f21dae2 reverted that behaviour: isOwnPackage applies to single-type imports again. Please update both rows to say that imports of a type the unit itself declares are skipped, and give the before/after numbers measured for that case.

Was this helpful? React with 👍 / 👎

if (isResolvable(importTree, name, currentPackage) && (duplicate || isOwnPackage(importTree, name, currentPackage) || !isUsed(importTree, name, outOfScope))) {
boolean ownType = !importTree.isStatic() && importTree.qualifiedIdentifier() instanceof MemberSelectExpressionTree select && declared.contains(select.identifier().name());
if (!ownType && isResolvable(importTree, name, currentPackage) && (duplicate || isOwnPackage(importTree, name, currentPackage) || !isUsed(importTree, name, outOfScope))) {
add(ProblemKind.UNUSED_IMPORT, "The import " + (name.endsWith(".*") ? name.substring(0, name.length() - 2) : name) + " is never used", importTree);
}
}
}

/** The compiler honours a suppression of unused code on the first type declaration of the unit for its imports too. */
private static boolean suppressesUnused(JavaTree.CompilationUnitTreeImpl unit) {
return unit.types().stream().filter(ClassTree.class::isInstance).map(ClassTree.class::cast).findFirst()
.map(first -> first.modifiers().annotations().stream().anyMatch(CompilerWarnings::suppressesUnused)).orElse(false);
}

/** The compiler never reports a single-type import of a type the unit itself declares. */
private static Set<String> declaredTypeNames(JavaTree.CompilationUnitTreeImpl unit) {
return unit.types().stream().filter(ClassTree.class::isInstance).map(ClassTree.class::cast)
.map(type -> type.simpleName() == null ? "" : type.simpleName().name()).collect(Collectors.toSet());
}

private static boolean suppressesUnused(AnnotationTree annotation) {
String name = dotted(annotation.annotationType());
if (!"SuppressWarnings".equals(name) && !"java.lang.SuppressWarnings".equals(name)) {
return false;
}
return annotation.arguments().stream().anyMatch(argument -> {
ExpressionTree value = argument instanceof AssignmentExpressionTree assignment ? assignment.expression() : (ExpressionTree) argument;
List<? extends Tree> literals = value instanceof NewArrayTree array ? array.initializers() : List.of(value);
return literals.stream().anyMatch(literal -> literal instanceof LiteralTree string && string.is(Tree.Kind.STRING_LITERAL)
&& Set.of("\"unused\"", "\"all\"").contains(string.value()));
});
}

/** Loads the imported types first, so that an on-demand import of their package is known to exist. */
private void loadImportedTypes(JavaTree.CompilationUnitTreeImpl unit) {
for (ImportClauseTree clause : unit.imports()) {
Expand Down Expand Up @@ -470,7 +514,7 @@
if (!importTree.isStatic()) {
return denotesType(symbol, dotted, identifier);
}
return isMemberOf(symbol, qualifier.replace('$', '.')) || (symbol.isTypeSymbol() && dottedType(symbol).equals(dotted));
return isMemberOf(symbol, qualifier.replace('$', '.')) || denotesType(symbol, dotted, identifier);
}

/** A static import also brings in the members the named type inherits. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.List;
import javax.annotation.Nullable;
import org.sonar.java.ast.parser.QualifiedIdentifierListTreeImpl;
import org.sonar.java.ast.parser.ArgumentListTreeImpl;
import org.sonar.java.ast.parser.FormalParametersListTreeImpl;
import org.sonar.java.ast.parser.TypeParameterListTreeImpl;
Expand Down Expand Up @@ -83,12 +84,16 @@
Tree.Kind kind = declarationKind(node);
CstNode body = requiredField(node, "body", null);
CstNode name = requiredField(node, "name", null);
state.types.push(sema.resolveTypeSymbol(name.decl()));
// translated before the members so that the bounds of the type parameters are known inside the bodies
Symbol.TypeSymbol declaredSymbol = sema.resolveTypeSymbol(name.decl());
state.types.push(declaredSymbol);
// translated before the members so that the bounds of the type parameters and the supertypes are known inside the bodies
CstNode typeParameters = field(node, "type_parameters");
TypeParameterListTreeImpl typeParameterList = typeParameters == null ? null : typeTrees().typeParameters(typeParameters);
List<Tree> members;
Hierarchy hierarchy;
try {
hierarchy = hierarchy(node);
bindSupertypes(declaredSymbol, hierarchy.superType(), hierarchy.interfaceTypes(), kind);
members = membersOf(body);
} finally {
state.types.pop();
Expand All @@ -114,9 +119,9 @@
state.scopes.removeFirst();
}
}
completeHierarchy(tree, node);
completeHierarchy(tree, node, hierarchy);
bindDeclaration(tree, name, identifier);
bindSupertypes(tree, kind);
bindRecordComponents(tree, kind);
return tree;
}

Expand All @@ -140,25 +145,33 @@
};
}

private void completeHierarchy(ClassTreeImpl tree, CstNode node) {
private record Hierarchy(@Nullable CstNode superclass, @Nullable TypeTree superType, @Nullable CstNode interfaces, @Nullable QualifiedIdentifierListTreeImpl interfaceTypes) {
}

private Hierarchy hierarchy(CstNode node) {
CstNode superclass = childKind(node, "superclass");
if (superclass != null) {
tree.completeSuperclass(token(required(superclass, "extends")), typeTrees().type(firstType(superclass)));
}
CstNode interfaces = childKind(node, "super_interfaces");
if (interfaces == null) {
interfaces = childKind(node, "extends_interfaces");
}
if (interfaces != null) {
tree.completeInterfaces(firstKeyword(interfaces), typeTrees().separatedTypes(interfaces));
return new Hierarchy(superclass, superclass == null ? null : typeTrees().type(firstType(superclass)), interfaces,
interfaces == null ? null : typeTrees().separatedTypes(interfaces));
}

private void completeHierarchy(ClassTreeImpl tree, CstNode node, Hierarchy hierarchy) {
if (hierarchy.superclass() != null) {
tree.completeSuperclass(token(required(hierarchy.superclass(), "extends")), hierarchy.superType());
}
if (hierarchy.interfaces() != null) {
tree.completeInterfaces(firstKeyword(hierarchy.interfaces()), hierarchy.interfaceTypes());
}
CstNode permits = childKind(node, "permits");
if (permits != null) {
tree.completePermittedTypes(token(required(permits, "permits")), typeTrees().separatedTypes(permits));
}
}

private static void bindSupertypes(ClassTreeImpl tree, Tree.Kind kind) {
private static void bindRecordComponents(ClassTreeImpl tree, Tree.Kind kind) {
if (kind == Tree.Kind.RECORD && tree.symbol() instanceof JTypeSymbol recordSymbol) {
// the components of a record belong to the record, not to its canonical constructor
tree.recordComponents().stream()
Expand All @@ -167,17 +180,19 @@
.map(JVariableSymbol.class::cast)
.forEach(component -> component.owner(recordSymbol));
}
if (tree.symbol() instanceof JTypeSymbol declared) {
if (tree.superClass() != null
&& tree.superClass().symbolType().symbol() instanceof JTypeSymbol parent && parent.id != null && !parent.isUnknown() && !parent.equals(declared)) {
}

private static void bindSupertypes(Symbol.TypeSymbol symbol, @Nullable TypeTree superType, @Nullable QualifiedIdentifierListTreeImpl interfaces, Tree.Kind kind) {
if (symbol instanceof JTypeSymbol declared) {
if (superType != null
&& superType.symbolType().symbol() instanceof JTypeSymbol parent && parent.id != null && !parent.isUnknown() && !parent.equals(declared)) {
declared.superName(parent.id);
} else if (kind == Tree.Kind.RECORD) {
declared.superName("java.lang.Record");
} else if (kind == Tree.Kind.ENUM) {
declared.superName("java.lang.Enum");
}
declared.declaredSupertypes(tree.superClass() == null ? null : tree.superClass().symbolType(),
tree.superInterfaces().stream().map(TypeTree::symbolType).toList());
declared.declaredSupertypes(superType == null ? null : superType.symbolType(), (interfaces == null ? List.<TypeTree>of() : interfaces).stream().map(TypeTree::symbolType).toList());

Check warning on line 195 in java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/DeclarationTranslator.java

View check run for this annotation

SonarQube-Next / SonarQube Code Analysis

Split this 186 characters long line (which is greater than 180 authorized).

[S103] Lines should not be too long See more on https://next.sonarqube.com/sonarqube/project/issues?id=org.sonarsource.java%3Ajava&pullRequest=6620&issues=66034e93-e43e-4dd6-908e-7e873a2c9e53&open=66034e93-e43e-4dd6-908e-7e873a2c9e53
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.annotation.Nullable;
import org.sonar.java.ast.parser.ArgumentListTreeImpl;
import org.sonar.java.ast.parser.QualifiedIdentifierListTreeImpl;
import org.sonar.java.model.ExpressionUtils;
import org.sonar.java.model.InternalSyntaxToken;
import org.sonar.java.model.JavaTree;
import org.sonar.java.model.LiteralUtils;
Expand Down Expand Up @@ -168,6 +169,19 @@ private void ascribeGenericCall(ExpressionTree expression, Type target) {
}
}

/** A generic call that nothing types, such as a cast operand, infers {@code Object} for the type variables its arguments leave open. */
private void defaultOpenTypeVariables(ExpressionTree expression) {
if (ExpressionUtils.skipParentheses(expression) instanceof MethodInvocationTreeImpl call
&& call.methodSymbol() instanceof JMethodSymbol generic
&& !generic.isUnknown()
&& !capturesAnArgument(call.symbolType())) {
Type inferred = sema.inference().defaultedReturn(generic, call.symbolType());
if (inferred != null) {
retargetInvocation(call, generic, inferred);
}
}
}

private static boolean capturesAnArgument(Type type) {
return type.typeArguments().stream().anyMatch(argument -> argument instanceof JType captured && captured.isCapture());
}
Expand Down Expand Up @@ -452,6 +466,7 @@ private TypeCastExpressionTreeImpl cast(CstNode node) {
}
}
ExpressionTree value = expression(requiredField(node, "value", lastNamed(node)));
defaultOpenTypeVariables(value);
InternalSyntaxToken andToken = bounds.isEmpty() ? null : token(ands.get(0));
TypeCastExpressionTreeImpl tree = new TypeCastExpressionTreeImpl(token(required(node, "(")), type, andToken, bounds, token(required(node, ")")), value);
if (bounds.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
final class FileImports {
final Map<String, String> singleImports = new HashMap<>();
final List<String> onDemandImports = new ArrayList<>();
final Map<String, String> staticImports = new HashMap<>();
/** Every owner a name is statically imported from, in import order: the names of several owners overload each other. */
final Map<String, List<String>> staticImports = new HashMap<>();
final List<String> staticOnDemandImports = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.sonar.plugins.java.api.semantic.Type;
import org.sonar.plugins.java.api.tree.MethodTree;

import static org.sonar.java.semsitter.SemaFacts.strings;
import static org.sonar.java.semsitter.SemaFacts.text;
Expand Down Expand Up @@ -244,6 +246,51 @@
return substitution;
}

/**
* The type {@code method} returns when its call has no target type, which leaves the type variables that the
* arguments do not fix to {@code Object}, or null when none stays open.
*/
@Nullable
Type defaultedReturn(JMethodSymbol method, Type current) {

Check failure on line 254 in java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/Inference.java

View check run for this annotation

SonarQube-Next / SonarQube Code Analysis

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.

[S3776] Cognitive Complexity of methods should not be too high See more on https://next.sonarqube.com/sonarqube/project/issues?id=org.sonarsource.java%3Ajava&pullRequest=6620&issues=bfc665e9-086e-4660-bb4a-0befe9646c69&open=bfc665e9-086e-4660-bb4a-0befe9646c69
if (method.declaration() instanceof MethodTree declaration && !declaration.typeParameters().isEmpty()) {
if (current.isTypeVar() || declaration.typeParameters().stream().anyMatch(parameter -> !parameter.bounds().isEmpty())) {
return null;
}
Set<String> own = declaration.typeParameters().stream().map(parameter -> parameter.identifier().name()).collect(Collectors.toSet());
Type replaced = withObjectFor(own, current);
return replaced == current ? null : replaced;
}
JsonObject member = sema.substitution().lookupGenericMember(method);
JsonObject declared = sema.substitution().declaredReturn(method);
if (member == null || declared == null || !(member.get(TYPE_VARS) instanceof JsonArray names) || names.isEmpty()) {
return null;
}
if (isTypeVariable(declared) || (method.id != null && method.id.matches(".*#[^(]*<[^>(]*:.*"))) {

Check warning on line 268 in java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/Inference.java

View check run for this annotation

SonarQube-Next / SonarQube Code Analysis

Simplify this regular expression to reduce its runtime, as it has super-linear performance due to backtracking.

[S8786] Regular expressions should not cause non-linear backtracking See more on https://next.sonarqube.com/sonarqube/project/issues?id=org.sonarsource.java%3Ajava&pullRequest=6620&issues=379f0356-f3d2-4e8a-a560-f7364a922643&open=379f0356-f3d2-4e8a-a560-f7364a922643
return null;
}
String descriptor = text(member, "desc");
boolean open = descriptor == null ? Substitution.mentionsTypeVariable(current) : current.equals(sema.factTypes().returnTypeOf(descriptor));
if (!open) {
return null;
}
Type object = sema.getClassType(SemaFacts.OBJECT_TYPE);
Map<String, Type> bound = new HashMap<>();
names.forEach(name -> bound.put(name.getAsString(), object));
JType result = sema.factTypes().typeFromFact(declared, bound);
return result.isUnknown() || Substitution.mentionsTypeVariable(result) ? null : result;
}

private Type withObjectFor(Set<String> variables, Type type) {
if (type instanceof JType variable && variable.isTypeVar() && variables.contains(variable.name())) {
return sema.getClassType(SemaFacts.OBJECT_TYPE);
}
if (type instanceof JType parameterized && parameterized.isParameterized()) {
List<JType> arguments = parameterized.args.stream().map(argument -> sema.asJType(withObjectFor(variables, argument))).toList();
return arguments.equals(parameterized.args) ? type : JType.named(sema, parameterized.erasure().fullyQualifiedName(), arguments);
}
return type;
}

/**
* The type {@code method} returns when the type its call is passed as fixes the type variables of the
* method, or null when they stay open or were already inferred from arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -113,7 +114,10 @@ private void bindStaticImport(IdentifierTreeImpl identifier, @Nullable Expressio
boolean declaredHere = state.types.stream().filter(type -> !type.isUnknown())
.anyMatch(type -> sema.lookup().declaredMethod(type.type().fullyQualifiedName(), identifier.name(), arguments) != null);
if (!declaredHere) {
Symbol.MethodSymbol imported = sema.lookup().declaredMethod(state.imports.staticImports.get(identifier.name()), identifier.name(), arguments);
List<String> owners = state.imports.staticImports.get(identifier.name());
Symbol.MethodSymbol imported = owners.stream().map(owner -> sema.lookup().applicableMethod(owner, identifier.name(), arguments))
.filter(Objects::nonNull).findFirst()
.orElseGet(() -> owners.stream().map(owner -> sema.lookup().declaredMethod(owner, identifier.name(), arguments)).filter(Objects::nonNull).findFirst().orElse(null));
if (imported != null) {
rebindMethod(identifier, imported, initialTarget);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private static final class Caches {
private Function<String, PackagePresence> packageLoader = name -> PackagePresence.UNKNOWN;
private int typeRevision;
private boolean noLibraries;
private int release;
private boolean typesLoaded;
}

Expand Down Expand Up @@ -319,6 +320,15 @@ void moveUse(@Nullable String from, @Nullable String to, IdentifierTree use) {
}

/** Without any library, a method of a type nothing declares is unknown instead of named after its written owner. */
void release(int release) {
caches.release = release;
}

/** The configured language level, or 0 when the project sets none. */
int release() {
return caches.release;
}

void noLibraries(boolean noLibraries) {
caches.noLibraries = noLibraries;
}
Comment on lines 322 to 334

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Quality: JSema release(): javadoc moved off noLibraries and wrong default

The new release(int) setter went in between the existing noLibraries javadoc and noLibraries(boolean). That comment ("Without any library, a method of a type nothing declares is unknown…") now documents release(int), and noLibraries has no doc. The getter's doc is also wrong. It says the level is "0 when the project sets none", but SemSitterParser passes Integer.MAX_VALUE when javaVersion.isNotSet(). Behaviour is the same either way: neither 0 nor Integer.MAX_VALUE drops a deprecation. Still, a reader who trusts the doc will misread the release <= 8 guard in SemaAnnotations.deprecatedAfterRelease. The fix is to move the comment back onto noLibraries and describe the unset case correctly.

Move the noLibraries javadoc back and document the unset value accurately:

/** Sets the configured language level. */
void release(int release) {
  caches.release = release;
}

/** The configured language level, or Integer.MAX_VALUE when the project sets none. */
int release() {
  return caches.release;
}

/** Without any library, a method of a type nothing declares is unknown instead of named after its written owner. */
void noLibraries(boolean noLibraries) {
  caches.noLibraries = noLibraries;
}
  • Apply fix

Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎

Expand Down
Loading