diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/Bindings.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/Bindings.java new file mode 100644 index 00000000000..9e2a0bec209 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/Bindings.java @@ -0,0 +1,286 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.Nullable; +import org.sonar.java.model.AbstractTypedTree; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.declaration.VariableTreeImpl; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.java.model.expression.LiteralTreeImpl; +import org.sonar.java.model.expression.MethodInvocationTreeImpl; +import org.sonar.java.model.statement.SwitchExpressionTreeImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.CaseGroupTree; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.LambdaExpressionTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.ParameterizedTypeTree; +import org.sonar.plugins.java.api.tree.SwitchExpressionTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.VariableTree; +import org.sonar.plugins.java.api.tree.YieldStatementTree; + +/** Stateless helpers that bind symbols and types to trees. */ +final class Bindings { + + private static final String BOOLEAN = "boolean"; + private static final String JAVA_LANG_STRING = "java.lang.String"; + private static final Set BOOLEAN_OPERATORS = Set.of("&&", "||", "==", "!=", "<", ">", "<=", ">=", "instanceof"); + + private Bindings() { + } + + static Type switchResultType(SwitchExpressionTreeImpl tree) { + List results = new ArrayList<>(); + for (CaseGroupTree group : tree.cases()) { + group.body().forEach(statement -> statement.accept(new BaseTreeVisitor() { + @Override + public void visitYieldStatement(YieldStatementTree yieldStatement) { + results.add(yieldStatement.expression().symbolType()); + } + + @Override + public void visitSwitchExpression(SwitchExpressionTree nested) { + // nested switch expressions yield their own results + } + + @Override + public void visitLambdaExpression(LambdaExpressionTree lambda) { + // lambdas cannot yield to the enclosing switch + } + + @Override + public void visitClass(ClassTree type) { + // classes cannot yield to the enclosing switch + } + })); + } + if (results.isEmpty() || results.stream().anyMatch(Type::isUnknown) || results.stream().distinct().count() != 1) { + return Type.UNKNOWN; + } + return results.get(0); + } + + static Set functionArguments(List arguments) { + Set functions = new HashSet<>(); + for (int i = 0; i < arguments.size(); i++) { + if (arguments.get(i).is(Tree.Kind.LAMBDA_EXPRESSION, Tree.Kind.METHOD_REFERENCE)) { + functions.add(i); + } + } + return functions; + } + + static List argumentTypes(List arguments) { + return arguments.stream().map(ExpressionTree::symbolType).toList(); + } + + static LiteralTreeImpl literal(Tree.Kind kind, InternalSyntaxToken token, Type type) { + LiteralTreeImpl tree = new LiteralTreeImpl(kind, token); + ascribe(tree, type); + return tree; + } + + static boolean namesType(Tree expression) { + if (expression instanceof IdentifierTree identifier) { + return identifier.symbol().isTypeSymbol(); + } + return (expression instanceof MemberSelectExpressionTree select) ? select.identifier().symbol().isTypeSymbol() : (expression instanceof ParameterizedTypeTree); + } + + private static boolean isTypeVariable(Type type) { + Type base = type; + while (base.isArray()) { + base = ((Type.ArrayType) base).elementType(); + } + return base.isTypeVar(); + } + + /** Whether a declared type, or the element type of a declared array, spells type arguments. */ + static boolean keepsArguments(Type type) { + return type.isParameterized() || (type.isArray() && keepsArguments(((Type.ArrayType) type).elementType())); + } + + static boolean sameErasure(Type left, Type right) { + return left.erasure().fullyQualifiedName().equals(right.erasure().fullyQualifiedName()); + } + + /** The scan records erased parameter types, while the declared parameters keep their type arguments. */ + static void declaredParameterTypes(JMethodSymbol method, List parameters) { + List erased = method.parameterTypes(); + if (erased.size() != parameters.size()) { + return; + } + List declared = new ArrayList<>(); + for (int i = 0; i < parameters.size(); i++) { + Type type = parameters.get(i).type().symbolType(); + if (type.isUnknown() || !(isTypeVariable(type) || sameErasure(type, erased.get(i)))) { + return; + } + declared.add(type); + } + method.parameterTypes(declared); + } + + /** A field is not hidden by a local variable of an enclosing method: a local class declares its own members. */ + static boolean isField(Symbol variable) { + return variable.owner().isTypeSymbol(); + } + + /** Usages are stored under the symbol's own id, which can differ from the fact key that resolved it. */ + static String usageId(Symbol symbol, String target) { + if (symbol instanceof JSymbol jSymbol && !jSymbol.isUnknown() && !jSymbol.toString().equals(jSymbol.name())) { + return jSymbol.toString(); + } + return target; + } + + static Type binaryType(String operator, Type left, Type right) { + if (BOOLEAN_OPERATORS.contains(operator)) { + return left instanceof JType j ? j.sema.getClassType(BOOLEAN) : Type.UNKNOWN; + } + if ("+".equals(operator) && (left.is(JAVA_LANG_STRING) || right.is(JAVA_LANG_STRING))) { + return left instanceof JType j ? j.sema.getClassType(JAVA_LANG_STRING) : Type.UNKNOWN; + } + Type promoted = promotedBinaryType(operator, unboxed(left), unboxed(right)); + if (promoted != null) { + return promoted; + } + if (left.isUnknown()) { + return right; + } + return left; + } + + static Type unboxed(Type type) { + return type.isPrimitiveWrapper() ? type.primitiveType() : type; + } + + /** The type JLS 5.6 gives an arithmetic, bitwise or shift operation, or null when an operand is not a primitive. */ + @Nullable + private static Type promotedBinaryType(String operator, Type left, Type right) { + if (!(left instanceof JType j) || !left.isPrimitive() || !right.isPrimitive()) { + return null; + } + boolean bitwise = "&".equals(operator) || "|".equals(operator) || "^".equals(operator); + if (left.is(BOOLEAN) || right.is(BOOLEAN)) { + return bitwise && left.is(BOOLEAN) && right.is(BOOLEAN) ? left : null; + } + if ("<<".equals(operator) || ">>".equals(operator) || ">>>".equals(operator)) { + return j.sema.getClassType(left.is("long") ? "long" : "int"); + } + return j.sema.getClassType(widestNumericName(left, right)); + } + + private static String widestNumericName(Type left, Type right) { + for (String name : List.of("double", "float", "long")) { + if (left.is(name) || right.is(name)) { + return name; + } + } + return "int"; + } + + static Tree.Kind binaryKind(String operator) { + return switch (operator) { + case "+" -> Tree.Kind.PLUS; + case "-" -> Tree.Kind.MINUS; + case "*" -> Tree.Kind.MULTIPLY; + case "/" -> Tree.Kind.DIVIDE; + case "%" -> Tree.Kind.REMAINDER; + case "<<" -> Tree.Kind.LEFT_SHIFT; + case ">>" -> Tree.Kind.RIGHT_SHIFT; + case ">>>" -> Tree.Kind.UNSIGNED_RIGHT_SHIFT; + case "<" -> Tree.Kind.LESS_THAN; + case ">" -> Tree.Kind.GREATER_THAN; + case "<=" -> Tree.Kind.LESS_THAN_OR_EQUAL_TO; + case ">=" -> Tree.Kind.GREATER_THAN_OR_EQUAL_TO; + case "==" -> Tree.Kind.EQUAL_TO; + case "!=" -> Tree.Kind.NOT_EQUAL_TO; + case "&" -> Tree.Kind.AND; + case "|" -> Tree.Kind.OR; + case "^" -> Tree.Kind.XOR; + case "&&" -> Tree.Kind.CONDITIONAL_AND; + case "||" -> Tree.Kind.CONDITIONAL_OR; + default -> Tree.Kind.PLUS; + }; + } + + static Tree.Kind assignmentKind(String operator) { + return switch (operator) { + case "+=" -> Tree.Kind.PLUS_ASSIGNMENT; + case "-=" -> Tree.Kind.MINUS_ASSIGNMENT; + case "*=" -> Tree.Kind.MULTIPLY_ASSIGNMENT; + case "/=" -> Tree.Kind.DIVIDE_ASSIGNMENT; + case "%=" -> Tree.Kind.REMAINDER_ASSIGNMENT; + case "&=" -> Tree.Kind.AND_ASSIGNMENT; + case "|=" -> Tree.Kind.OR_ASSIGNMENT; + case "^=" -> Tree.Kind.XOR_ASSIGNMENT; + case "<<=" -> Tree.Kind.LEFT_SHIFT_ASSIGNMENT; + case ">>=" -> Tree.Kind.RIGHT_SHIFT_ASSIGNMENT; + case ">>>=" -> Tree.Kind.UNSIGNED_RIGHT_SHIFT_ASSIGNMENT; + default -> Tree.Kind.ASSIGNMENT; + }; + } + + static Tree.Kind unaryKind(String operator, boolean prefix) { + return switch (operator) { + case "++" -> prefix ? Tree.Kind.PREFIX_INCREMENT : Tree.Kind.POSTFIX_INCREMENT; + case "--" -> prefix ? Tree.Kind.PREFIX_DECREMENT : Tree.Kind.POSTFIX_DECREMENT; + case "-" -> Tree.Kind.UNARY_MINUS; + case "+" -> Tree.Kind.UNARY_PLUS; + case "~" -> Tree.Kind.BITWISE_COMPLEMENT; + default -> Tree.Kind.LOGICAL_COMPLEMENT; + }; + } + + static Type identifierType(Symbol symbol) { + return symbol instanceof Symbol.MethodSymbol method && !method.isUnknown() ? method.returnType().type() : symbol.type(); + } + + /** A resolved type, or an unresolved one that still carries its written name. */ + static boolean isKnownOrRecovered(Type type) { + return !type.isUnknown() || !"!Unknown!".equals(type.fullyQualifiedName()); + } + + static Type variableType(VariableTreeImpl variable) { + return variable.symbol().type().isUnknown() ? variable.type().symbolType() : variable.symbol().type(); + } + + static void ascribe(Tree tree, @Nullable Type type) { + if (tree instanceof AbstractTypedTree typed && type != null) { + typed.setSymbolType(type); + } + } + + static void bind(IdentifierTreeImpl identifier, @Nullable Symbol symbol) { + identifier.setSymbol(symbol == null ? Symbol.UNKNOWN_SYMBOL : symbol); + } + + static void bindMethod(MethodInvocationTreeImpl invocation, @Nullable Symbol.MethodSymbol method) { + invocation.setMethodSymbol(method == null ? Symbol.MethodSymbol.UNKNOWN_METHOD : method); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/BundledServer.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/BundledServer.java new file mode 100644 index 00000000000..43f3085703d --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/BundledServer.java @@ -0,0 +1,135 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.Locale; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; +import javax.annotation.Nullable; +import org.sonar.api.SonarEdition; +import org.sonar.api.SonarRuntime; + +/** + * The SemSitter servers shipped inside this plugin, one per Linux architecture, for the runners that have no server + * installed: the performance-validation benchmark and SonarQube Cloud, whose analysis service runs on arm64. A server is + * used only there. Every other analysis keeps the default frontend unless an executable is configured. + * + *

Where a server is expected, it must be usable: a host that is not Linux amd64 or arm64, or a server that cannot be + * extracted, fails the analysis instead of silently leaving it to the default frontend. + */ +final class BundledServer { + + static final String RESOURCE_X86_64 = "udg-java-server-x86_64-unknown-linux-musl"; + static final String RESOURCE_AARCH64 = "udg-java-server-aarch64-unknown-linux-musl"; + static final String PERFORMANCE_VALIDATION_CONTEXT = "sonar.java.context"; + private static final AtomicReference COPY = new AtomicReference<>(); + + private BundledServer() { + } + + static Optional extract(SonarRuntime runtime) { + if (!performanceValidation() && runtime.getEdition() != SonarEdition.SONARCLOUD) { + return Optional.empty(); + } + return Optional.of(copyOnce(resourceFor(System.getProperty("os.name", ""), System.getProperty("os.arch", "")))); + } + + /** The server that runs on the given host, or a failure for a host none of them runs on. */ + static String resourceFor(String osName, String architecture) { + if (!osName.toLowerCase(Locale.ROOT).contains("linux")) { + throw new IllegalStateException("The bundled SemSitter server only runs on Linux, not on " + osName); + } + return switch (architecture.toLowerCase(Locale.ROOT)) { + case "amd64", "x86_64" -> RESOURCE_X86_64; + case "aarch64", "arm64" -> RESOURCE_AARCH64; + default -> throw new IllegalStateException("No SemSitter server is bundled for the architecture " + architecture); + }; + } + + /** + * Copies the server once per JVM, to a file of the user that no concurrent analysis on the same host writes to. A + * server that cannot be extracted fails the analysis, so that a performance validation never silently runs ECJ. + */ + private static synchronized Path copyOnce(String resource) { + Path copy = COPY.get(); + if (copy != null) { + return copy; + } + try (InputStream in = BundledServer.class.getResourceAsStream(resource)) { + copy = install(in, resource, installDirectory(System.getProperty("user.home", ""), System.getProperty("java.io.tmpdir"))); + COPY.set(copy); + return copy; + } catch (IOException failure) { + throw new IllegalStateException("The bundled SemSitter server could not be extracted: " + failure.getMessage(), failure); + } + } + + /** The directory of the user's home for the server, or else the temporary directory when the home does not exist or cannot be written, as in a container. */ + static Path installDirectory(String home, String temporaryDirectory) throws IOException { + Path homeDirectory = Path.of(home, ".sonar", "semsitter"); + return isUsable(homeDirectory) ? homeDirectory : Files.createDirectories(Path.of(temporaryDirectory)); + } + + private static boolean isUsable(Path directory) { + try { + Files.createDirectories(directory); + return Files.isWritable(directory); + } catch (IOException | RuntimeException failure) { + return false; + } + } + + /** Writes the server to a new executable file of {@code directory}, deleted when the JVM exits or right away if the copy fails. */ + static Path install(@Nullable InputStream in, String resource, Path directory) throws IOException { + if (in == null) { + throw new IllegalStateException("The SemSitter server is not bundled in this plugin."); + } + Path destination = Files.createTempFile(directory, resource, ""); + if (!copyTo(in, destination)) { + delete(destination); + throw new IllegalStateException("The bundled SemSitter server could not be copied to " + destination); + } + Runtime.getRuntime().addShutdownHook(new Thread(() -> delete(destination))); + return destination; + } + + private static boolean copyTo(InputStream in, Path destination) { + try { + Files.copy(in, destination, StandardCopyOption.REPLACE_EXISTING); + return destination.toFile().setExecutable(true); + } catch (IOException failure) { + return false; + } + } + + private static boolean delete(Path path) { + try { + return Files.deleteIfExists(path); + } catch (IOException failure) { + return false; + } + } + + private static boolean performanceValidation() { + return PERFORMANCE_VALIDATION_CONTEXT.equals(System.getProperty("sensor.context.key")); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CastChecks.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CastChecks.java new file mode 100644 index 00000000000..0c951b85b98 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CastChecks.java @@ -0,0 +1,316 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import javax.annotation.CheckForNull; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.Arguments; +import org.sonar.plugins.java.api.tree.ArrayAccessExpressionTree; +import org.sonar.plugins.java.api.tree.AssignmentExpressionTree; +import org.sonar.plugins.java.api.tree.BlockTree; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.LambdaExpressionTree; +import org.sonar.plugins.java.api.tree.MethodInvocationTree; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.NewClassTree; +import org.sonar.plugins.java.api.tree.ParenthesizedTree; +import org.sonar.plugins.java.api.tree.ReturnStatementTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeCastTree; +import org.sonar.plugins.java.api.tree.VarTypeTree; +import org.sonar.plugins.java.api.tree.VariableTree; + +/** Static checks behind the redundant cast warning: widening, promotion and the casts that change overload or target typing. */ +final class CastChecks { + + private static final Pattern LEADING_DIGITS = Pattern.compile("^\\d++"); + + private static final Map NUMERIC_RANK = Map.of("byte", 0, "short", 1, "char", 1, "int", 2, "long", 3, "float", 4, "double", 5); + + private CastChecks() { + } + + /** Whether the cast is the result of a lambda passed as an argument: it can fix the type the call infers. */ + static boolean isResultOfArgumentLambda(TypeCastTree cast) { + Tree parent = cast.parent(); + while (parent instanceof ParenthesizedTree || parent instanceof ReturnStatementTree) { + parent = parent.parent(); + } + if (parent instanceof BlockTree) { + parent = parent.parent(); + } + return parent instanceof LambdaExpressionTree lambda && lambda.parent() instanceof Arguments; + } + + /** The innermost element type of an array type; the type itself otherwise. */ + static Type elementType(Type type) { + Type element = type; + while (element.isArray()) { + element = ((Type.ArrayType) element).elementType(); + } + return element; + } + + /** Whether the cast is the array an element is read from. */ + static boolean isIndexedArray(TypeCastTree cast) { + Tree child = cast; + Tree parent = cast.parent(); + while (parent instanceof ParenthesizedTree) { + child = parent; + parent = parent.parent(); + } + return parent instanceof ArrayAccessExpressionTree access && access.expression() == child; + } + + /** The type of the parameter {@code argument} is passed to, when no other method of the owner or its supertypes could take the call instead. */ + private static java.util.Optional soleParameterType(Arguments arguments, Tree argument) { + Symbol.MethodSymbol method = calledMethod(arguments); + int index = arguments.indexOf(argument); + if (method == null || method.isUnknown() || index >= method.parameterTypes().size() || method.isVarArgsMethod() || !(method.owner() instanceof JTypeSymbol owner)) { + return java.util.Optional.empty(); + } + long sameArity = java.util.stream.Stream.concat(java.util.stream.Stream.of(owner.type()), owner.superTypes().stream()) + .map(Type::symbol) + .filter(JTypeSymbol.class::isInstance) + .flatMap(type -> ((JTypeSymbol) type).membersNamed(method.name()).stream()) + .filter(member -> member.isMethodSymbol() && ((Symbol.MethodSymbol) member).parameterTypes().size() == arguments.size()) + .map(member -> ((Symbol.MethodSymbol) member).parameterTypes().stream().map(parameter -> parameter.erasure().fullyQualifiedName()).toList()) + .distinct() + .count(); + return sameArity == 1 ? java.util.Optional.of(method.parameterTypes().get(index)) : java.util.Optional.empty(); + } + + /** The declared return type of the method a return statement belongs to; none inside a lambda. */ + private static java.util.Optional returnedAs(Tree statement) { + Tree enclosing = statement.parent(); + while (!(enclosing instanceof MethodTree) && !(enclosing instanceof LambdaExpressionTree) + && !(enclosing instanceof ClassTree)) { + enclosing = enclosing.parent(); + } + if (enclosing instanceof MethodTree method && method.returnType() != null) { + return java.util.Optional.of(method.returnType().symbolType()); + } + return java.util.Optional.empty(); + } + + /** The result type of an expression lambda whose target type does not depend on inferring the call it is passed to. */ + private static java.util.Optional lambdaResult(LambdaExpressionTree lambda) { + Symbol.MethodSymbol method = lambda.symbol(); + if (method == null || method.isUnknown()) { + return java.util.Optional.empty(); + } + if (lambda.parent() instanceof Arguments arguments + && (isGenericCall(arguments) || soleParameterType(arguments, lambda).isEmpty())) { + return java.util.Optional.empty(); + } + return java.util.Optional.of(method.returnType().type()); + } + + private static boolean isGenericCall(Arguments arguments) { + Symbol.MethodSymbol method = calledMethod(arguments); + return method == null || method.isParametrizedMethod() || method.owner().type().isParameterized(); + } + + @CheckForNull + private static Symbol.MethodSymbol calledMethod(Arguments arguments) { + if (arguments.parent() instanceof MethodInvocationTree call) { + return call.methodSymbol(); + } + return arguments.parent() instanceof NewClassTree creation ? creation.methodSymbol() : null; + } + + /** A primitive cast changes the value unless it is an identity or widening conversion of the operand; a reference cast never does. */ + static boolean castKeepsValue(Type operand, Type cast, Substitution substitution) { + return !cast.isPrimitive() || isAssignable(operand, cast, substitution); + } + + /** Whether a value of type {@code from} is assignable to {@code to} without a cast, boxing and unboxing included. */ + static boolean isAssignable(Type from, Type to, Substitution substitution) { + if (from.isPrimitive() && to.isPrimitive()) { + String fromName = from.fullyQualifiedName(); + String toName = to.fullyQualifiedName(); + return fromName.equals(toName) || (NUMERIC_RANK.containsKey(fromName) && NUMERIC_RANK.containsKey(toName) && isWidening(fromName, toName)); + } + if (from.isPrimitive()) { + Type boxed = from.primitiveWrapperType(); + return boxed != null && boxed.isSubtypeOf(to); + } + if (to.isPrimitive()) { + Type unboxed = from.primitiveType(); + return unboxed != null && isAssignable(unboxed, to, substitution); + } + return from.isSubtypeOf(to) && substitution.preservesArguments(from, to); + } + + /** The type as the compiler prints it: type arguments included, without spaces between them. */ + static String displayName(Type type) { + if (type.isNullType()) { + return "null"; + } + if (type.isArray()) { + return displayName(((Type.ArrayType) type).elementType()) + "[]"; + } + if (type.isParameterized()) { + return memberName(type.erasure()) + type.typeArguments().stream().map(CastChecks::displayName).collect(java.util.stream.Collectors.joining(",", "<", ">")); + } + return memberName(type); + } + + /** + * The bounds of an intersection type in the order the compiler keeps them: as written when the first one is a class, + * otherwise sorted by qualified name. + */ + static String intersectionName(List bounds) { + List ordered = new ArrayList<>(bounds); + if (!isClassType(ordered.get(0))) { + ordered.sort(java.util.Comparator.comparing(CastChecks::readableName)); + } + return ordered.stream().map(CastChecks::displayName).collect(java.util.stream.Collectors.joining(" & ")); + } + + private static boolean isClassType(Type type) { + return type.isClass() && !type.symbol().isInterface(); + } + + private static String readableName(Type type) { + if (type.isParameterized()) { + return readableName(type.erasure()) + type.typeArguments().stream().map(CastChecks::readableName).collect(java.util.stream.Collectors.joining(",", "<", ">")); + } + return type.isTypeVar() ? type.name() : type.fullyQualifiedName().replace('$', '.'); + } + + /** + * A member type is spelled with its enclosing types, as the compiler does in its messages. A local type starts its own + * spelling, and an anonymous one has none. + */ + private static String memberName(Type type) { + String fqn = type.fullyQualifiedName(); + if (fqn.indexOf('$') < 0 || type.isTypeVar() || (type instanceof JType jType && jType.isWildcard())) { + return type.name(); + } + List names = new ArrayList<>(); + for (String segment : fqn.substring(fqn.lastIndexOf('.') + 1).split("\\$")) { + String name = LEADING_DIGITS.matcher(segment).replaceFirst(""); + if (name.length() != segment.length()) { + names.clear(); + } + names.add(name); + } + return String.join(".", names); + } + + /** Whether the cast is the operand of another cast that the operand's own type cannot reach without it. */ + static boolean changesTypeFor(TypeCastTree cast, Type operand, Substitution substitution) { + Tree parent = cast.parent(); + while (parent instanceof ParenthesizedTree) { + parent = parent.parent(); + } + if (!(parent instanceof TypeCastTree outer)) { + return false; + } + Type target = outer.type().symbolType(); + return target.isParameterized() && operand.isParameterized() + && !substitution.preservesArguments(operand, target) && !substitution.preservesArguments(target, operand); + } + + /** The extra bounds of an intersection cast also have to hold for the operand. */ + static boolean satisfiesBounds(TypeCastTree cast, Type operand) { + return cast.bounds().stream().allMatch(bound -> !bound.symbolType().isUnknown() && operand.isSubtypeOf(bound.symbolType())); + } + + /** The declared type of the variable the cast initializes or is assigned to. */ + static java.util.Optional assignedTo(TypeCastTree cast) { + Tree child = cast; + Tree parent = cast.parent(); + while (parent instanceof ParenthesizedTree) { + child = parent; + parent = parent.parent(); + } + if (parent instanceof VariableTree variable && variable.initializer() == child + && !(variable.type() instanceof VarTypeTree)) { + return java.util.Optional.of(variable.type().symbolType()); + } + if (parent instanceof AssignmentExpressionTree assignment && assignment.is(Tree.Kind.ASSIGNMENT) && assignment.expression() == child) { + return java.util.Optional.of(assignment.variable().symbolType()); + } + if (parent instanceof Arguments arguments) { + return soleParameterType(arguments, child); + } + if (parent instanceof ReturnStatementTree) { + return returnedAs(parent); + } + if (parent instanceof LambdaExpressionTree lambda && lambda.body() == child) { + return lambdaResult(lambda); + } + return java.util.Optional.empty(); + } + + static String castMessage(ExpressionTree cast) { + return "Unnecessary cast from " + displayName(((TypeCastTree) cast).expression().symbolType()) + " to " + displayName(cast.symbolType()); + } + + static boolean isWideningPrimitiveCast(ExpressionTree tree) { + if (!(tree instanceof TypeCastTree cast)) { + return false; + } + String from = cast.expression().symbolType().fullyQualifiedName(); + String to = cast.type().symbolType().fullyQualifiedName(); + return NUMERIC_RANK.containsKey(from) && NUMERIC_RANK.containsKey(to) && (from.equals(to) || isWidening(from, to)); + } + + private static boolean isWidening(String from, String to) { + if ("char".equals(to)) { + return false; + } + if ("char".equals(from)) { + return NUMERIC_RANK.get(to) >= NUMERIC_RANK.get("int"); + } + return NUMERIC_RANK.get(from) < NUMERIC_RANK.get(to); + } + + /** The type the operand has once its cast is dropped, or null when the operand is not a numeric primitive. */ + static String promotionInput(ExpressionTree operand, boolean dropCast) { + Type type = dropCast ? ((TypeCastTree) operand).expression().symbolType() : operand.symbolType(); + String name = type.fullyQualifiedName(); + return NUMERIC_RANK.containsKey(name) ? name : null; + } + + static boolean sameOperandTypes(Tree.Kind kind, String leftWithout, String rightWithout, ExpressionTree left, ExpressionTree right) { + String leftWith = left.symbolType().fullyQualifiedName(); + String rightWith = right.symbolType().fullyQualifiedName(); + if (kind == Tree.Kind.LEFT_SHIFT || kind == Tree.Kind.RIGHT_SHIFT || kind == Tree.Kind.UNSIGNED_RIGHT_SHIFT) { + return unaryPromoted(leftWith).equals(unaryPromoted(leftWithout)) && unaryPromoted(rightWith).equals(unaryPromoted(rightWithout)); + } + return binaryPromoted(leftWith, rightWith).equals(binaryPromoted(leftWithout, rightWithout)); + } + + private static String unaryPromoted(String type) { + return NUMERIC_RANK.get(type) < NUMERIC_RANK.get("int") ? "int" : type; + } + + private static String binaryPromoted(String left, String right) { + String a = unaryPromoted(left); + String b = unaryPromoted(right); + return NUMERIC_RANK.get(a) >= NUMERIC_RANK.get(b) ? a : b; + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CompilerWarnings.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CompilerWarnings.java new file mode 100644 index 00000000000..da36fd38247 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CompilerWarnings.java @@ -0,0 +1,487 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +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.AssignmentExpressionTree; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.BinaryExpressionTree; +import org.sonar.plugins.java.api.tree.CatchTree; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.CompilationUnitTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +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.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.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.TypeTree; +import org.sonar.plugins.java.api.tree.UnionTypeTree; +import org.sonar.plugins.java.api.tree.VariableTree; + +import static org.sonar.java.semsitter.CastChecks.assignedTo; +import static org.sonar.java.semsitter.CastChecks.castMessage; +import static org.sonar.java.semsitter.CastChecks.elementType; +import static org.sonar.java.semsitter.CastChecks.isIndexedArray; +import static org.sonar.java.semsitter.CastChecks.isResultOfArgumentLambda; +import static org.sonar.java.semsitter.CastChecks.isWideningPrimitiveCast; +import static org.sonar.java.semsitter.CastChecks.promotionInput; +import static org.sonar.java.semsitter.CastChecks.sameOperandTypes; +import static org.sonar.java.semsitter.ImportScopes.declaredIn; +import static org.sonar.java.semsitter.ImportScopes.denotesType; +import static org.sonar.java.semsitter.ImportScopes.dotted; +import static org.sonar.java.semsitter.ImportScopes.dottedType; +import static org.sonar.java.semsitter.ImportScopes.isInScope; +import static org.sonar.java.semsitter.ImportScopes.isOwnPackage; + +/** + * The compiler diagnostics the checks read from the compilation unit, derived from the tree and its symbols: + * unused imports and assignments without effect. + */ +final class CompilerWarnings extends BaseTreeVisitor { + private static final Pattern JAVADOC_REFERENCE = Pattern.compile("\\{@(?:link|linkplain|value)\\s++([^}]*)\\}|@(?:see|throws|exception)\\s++([^\\r\\n]*)"); + + private static final Pattern CONTINUATION_STARS = Pattern.compile("(\\R)\\h*+\\*++(?!/)"); + + private static final Pattern MARKDOWN_LINK = Pattern.compile("\\[([^\\]\\r\\n]*)\\]"); + + private static final Pattern JAVA_NAME = Pattern.compile("[\\p{L}_$][\\p{L}\\p{N}_$]*"); + + static final Set SUPPORTED_KINDS = Collections.unmodifiableSet( + EnumSet.of(ProblemKind.UNUSED_IMPORT, ProblemKind.REDUNDANT_CAST, ProblemKind.ASSIGNMENT_HAS_NO_EFFECT, ProblemKind.MASKED_CATCH)); + + private final Map> warnings = new EnumMap<>(ProblemKind.class); + + private final List identifiers = new ArrayList<>(); + + private final Set javadocNames = new HashSet<>(); + + private final List tries = new ArrayList<>(); + + private final JSema sema; + + private CompilerWarnings(JSema sema) { + this.sema = sema; + SUPPORTED_KINDS.forEach(kind -> warnings.put(kind, new LinkedHashSet<>())); + } + + static void addTo(JavaTree.CompilationUnitTreeImpl unit) { + CompilerWarnings visitor = new CompilerWarnings((JSema) unit.sema); + visitor.scan(unit.packageDeclaration()); + visitor.scan(unit.types()); + unit.imports().forEach(visitor::scan); + visitor.collectJavadocNames(unit); + visitor.reportUnusedImports(unit); + visitor.reportUnreachableCatches(unit); + unit.addWarnings(visitor.warnings); + } + + private void add(ProblemKind type, String message, Tree tree) { + warnings.computeIfAbsent(type, key -> new LinkedHashSet<>()).add(new JWarning(message, type, tree)); + } + + @Override + public void visitImport(ImportTree tree) { + // names inside an import are not uses + } + + @Override + public void visitIdentifier(IdentifierTree tree) { + identifiers.add(tree); + super.visitIdentifier(tree); + } + + @Override + public void visitArrayType(org.sonar.plugins.java.api.tree.ArrayTypeTree tree) { + scan(tree.annotations()); + super.visitArrayType(tree); + } + + /** Only simple names use an import: the member of a qualified name is not one. */ + @Override + public void visitMemberSelectExpression(MemberSelectExpressionTree tree) { + scan(tree.annotations()); + scan(tree.expression()); + scan(tree.identifier().annotations()); + } + + /** The method a method reference names is found through its qualifier, not through an import. */ + @Override + public void visitMethodReference(MethodReferenceTree tree) { + scan(tree.expression()); + scan(tree.typeArguments()); + scan(tree.method().annotations()); + } + + @Override + public void visitTypeCast(org.sonar.plugins.java.api.tree.TypeCastTree tree) { + Type cast = tree.type().symbolType(); + Type operand = tree.expression().symbolType(); + boolean widening = !cast.isUnknown() && !operand.isUnknown() && operand.isSubtypeOf(cast) && CastChecks.satisfiesBounds(tree, operand) + && sema.substitution().preservesArguments(operand, cast) && !CastChecks.changesTypeFor(tree, operand, sema.substitution()) + && !isResultOfArgumentLambda(tree); + boolean identity = widening && cast.erasure().fullyQualifiedName().equals(operand.erasure().fullyQualifiedName()) + && elementType(cast).typeArguments().isEmpty() == elementType(operand).typeArguments().isEmpty(); + boolean acceptedAsIs = !cast.isUnknown() && !operand.isUnknown() && !CastChecks.changesTypeFor(tree, operand, sema.substitution()) + && CastChecks.castKeepsValue(operand, cast, sema.substitution()) + && assignedTo(tree).filter(target -> !target.isUnknown() && (!cast.isPrimitive() || target.isPrimitive()) + && CastChecks.isAssignable(operand, target, sema.substitution())).isPresent(); + if (identity || acceptedAsIs || (widening && cast.isArray() && isIndexedArray(tree))) { + String target = CastChecks.intersectionName(java.util.stream.Stream.concat(java.util.stream.Stream.of(tree.type()), tree.bounds().stream()) + .map(TypeTree::symbolType).toList()); + add(ProblemKind.REDUNDANT_CAST, "Unnecessary cast from " + CastChecks.displayName(operand) + " to " + target, tree); + } + super.visitTypeCast(tree); + scan(tree.bounds()); + } + + /** + * A widening primitive cast on an operand is unnecessary when the operator promotes the operands to the same types without it + * (all casts of the expression are removed together). + */ + @Override + public void visitBinaryExpression(BinaryExpressionTree tree) { + ExpressionTree left = ExpressionUtils.skipParentheses(tree.leftOperand()); + ExpressionTree right = ExpressionUtils.skipParentheses(tree.rightOperand()); + boolean leftCast = isWideningPrimitiveCast(left); + boolean rightCast = isWideningPrimitiveCast(right); + if (leftCast || rightCast) { + String leftType = promotionInput(left, leftCast); + String rightType = promotionInput(right, rightCast); + if (leftType != null && rightType != null && sameOperandTypes(tree.kind(), leftType, rightType, left, right)) { + if (leftCast) { + add(ProblemKind.REDUNDANT_CAST, castMessage(left), left); + } + if (rightCast) { + add(ProblemKind.REDUNDANT_CAST, castMessage(right), right); + } + } + } + super.visitBinaryExpression(tree); + } + + @Override + public void visitTryStatement(TryStatementTree tree) { + tries.add(tree); + super.visitTryStatement(tree); + } + + /** 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) { + tries.forEach(this::reportUnreachableCatches); + } + } + + private static boolean isUnnamed(IdentifierTree identifier) { + return identifier instanceof IdentifierTreeImpl impl && impl.isUnnamedVariable(); + } + + /** A catch of a checked exception that nothing left over by the previous catches can reach. */ + private void reportUnreachableCatches(TryStatementTree tree) { + ThrownTypes body = new ThrownTypes(); + body.scanTry(tree.resourceList(), tree.block()); + if (body.unknown) { + return; + } + List remaining = new ArrayList<>(body.thrown); + for (CatchTree catchTree : tree.catches()) { + TypeTree parameterType = catchTree.parameter().type(); + List alternatives = parameterType instanceof UnionTypeTree union ? union.typeAlternatives() : List.of(parameterType); + List handled = new ArrayList<>(); + for (TypeTree alternative : alternatives) { + Type type = alternative.symbolType(); + if (type.isUnknown()) { + return; + } + handled.add(type); + if (isCheckedException(type) && remaining.stream().noneMatch(thrown -> thrown.isSubtypeOf(type) || type.isSubtypeOf(thrown))) { + String message = "Unreachable catch block for " + type.name() + + ". Only more specific exceptions are thrown and they are handled by previous catch block(s)."; + add(ProblemKind.MASKED_CATCH, message, alternative); + } + } + remaining.removeIf(thrown -> handled.stream().anyMatch(thrown::isSubtypeOf)); + } + } + + /** Neither unchecked nor a supertype of the unchecked ones. */ + private static boolean isCheckedException(Type type) { + return type.isClass() && type.isSubtypeOf("java.lang.Throwable") && !type.isSubtypeOf("java.lang.RuntimeException") && !type.isSubtypeOf("java.lang.Error") + && !type.is("java.lang.Exception") && !type.is("java.lang.Throwable"); + } + + @Override + public void visitAssignmentExpression(AssignmentExpressionTree tree) { + if (hasNoEffect(tree)) { + add(ProblemKind.ASSIGNMENT_HAS_NO_EFFECT, "The assignment to variable " + assignedVariable(tree.variable()).name() + " has no effect", tree); + } + super.visitAssignmentExpression(tree); + } + + /** A plain assignment of a variable to itself, unless the variable is volatile: writing it then still publishes the value. */ + static boolean hasNoEffect(AssignmentExpressionTree tree) { + Symbol target = tree.is(Tree.Kind.ASSIGNMENT) ? assignedVariable(tree.variable()) : null; + return target != null && !target.isVolatile() && target.equals(assignedVariable(tree.expression())); + } + + /** The variable a simple name, {@code this.name} or {@code Type.name} designates. */ + private static Symbol assignedVariable(ExpressionTree tree) { + ExpressionTree expression = ExpressionUtils.skipParentheses(tree); + IdentifierTree name = null; + if (expression instanceof IdentifierTree identifier) { + name = identifier; + } else if (expression instanceof MemberSelectExpressionTree select) { + ExpressionTree qualifier = select.expression(); + if (qualifier instanceof IdentifierTree owner && ("this".equals(owner.name()) || owner.symbol().isTypeSymbol())) { + name = select.identifier(); + } + } + if (name == null || !name.symbol().isVariableSymbol() || name.symbol().isUnknown()) { + return null; + } + return name.symbol(); + } + + /** + * The names a Javadoc reference tag ({@code @link}, {@code @value}, {@code @see}, {@code @throws}) spells, as the compiler + * reads them: only the comments documenting a declaration are resolved. + */ + private void collectJavadocNames(Tree tree) { + SyntaxToken first = isDocumentedDeclaration(tree) ? tree.firstToken() : null; + if (first != null) { + for (SyntaxTrivia trivia : first.trivias()) { + if (trivia.comment().startsWith("/**") || trivia.comment().startsWith("///")) { + javadocNames.addAll(javadocReferenceNames(trivia.comment())); + } + } + } + if (tree instanceof JavaTree javaTree && !javaTree.isLeaf()) { + javaTree.getChildren().forEach(this::collectJavadocNames); + } + } + + static boolean isDocumentedDeclaration(Tree tree) { + return tree instanceof ClassTree || tree instanceof MethodTree || tree instanceof ModuleDeclarationTree + || (tree instanceof PackageDeclarationTree && tree.parent() instanceof CompilationUnitTree unit && unit.types().isEmpty()) + || (tree instanceof VariableTree && tree.parent() instanceof ClassTree); + } + + /** The names the references of a Javadoc comment spell, a reference wrapped onto a continuation line included. */ + static List javadocReferenceNames(String comment) { + List names = new ArrayList<>(); + Matcher matcher = JAVADOC_REFERENCE.matcher(CONTINUATION_STARS.matcher(comment).replaceAll("$1")); + while (matcher.find()) { + names.addAll(referenceNames(matcher.group(matcher.group(1) != null ? 1 : 2))); + } + if (comment.startsWith("///")) { + Matcher link = MARKDOWN_LINK.matcher(comment); + while (link.find()) { + names.addAll(referenceNames(link.group(1))); + } + } + return names; + } + + /** + * The simple names a Javadoc reference spells: its first name and the first name of each parameter type of a method + * reference, since a qualified type does not go through an import. The reference ends at the first whitespace outside + * its parameter list, so the description that follows names nothing. + */ + static List referenceNames(String text) { + String reference = text.substring(0, referenceEnd(text)); + int open = reference.indexOf('('); + List names = new ArrayList<>(); + firstName(open < 0 ? reference : reference.substring(0, open)).ifPresent(names::add); + if (open >= 0) { + for (String parameter : reference.substring(open + 1).split(",")) { + firstName(parameter).ifPresent(names::add); + } + } + return names; + } + + private static Optional firstName(String text) { + Matcher word = JAVA_NAME.matcher(text); + return word.find() ? Optional.of(word.group()) : Optional.empty(); + } + + private static int referenceEnd(String text) { + int depth = 0; + for (int i = 0; i < text.length(); i++) { + char c = text.charAt(i); + if (c == '(') { + depth++; + } else if (c == ')') { + depth = Math.max(0, depth - 1); + } else if (depth == 0 && Character.isWhitespace(c)) { + return i; + } + } + return text.length(); + } + + private void reportUnusedImports(JavaTree.CompilationUnitTreeImpl unit) { + if (unit.moduleDeclaration() != null) { + // The compiler reports no unused import in a module declaration unit. + return; + } + Set seen = new HashSet<>(); + String currentPackage = unit.packageDeclaration() == null ? "" : dotted(unit.packageDeclaration().packageName()); + loadImportedTypes(unit); + List outOfScope = identifiers.stream().filter(identifier -> !isInFileScope(identifier)).toList(); + for (ImportClauseTree clause : unit.imports()) { + if (!(clause instanceof ImportTree importTree)) { + continue; + } + String name = dotted(importTree.qualifiedIdentifier()); + String key = (importTree.isStatic() ? "static " : "") + name; + boolean duplicate = !seen.add(key); + if (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); + } + } + } + + /** 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()) { + if (clause instanceof ImportTree importTree && !importTree.isStatic() && !dotted(importTree.qualifiedIdentifier()).endsWith(".*")) { + declaresImported(dotted(importTree.qualifiedIdentifier())); + } + } + } + + private void declaresImported(String name) { + binaryName(name); + } + + /** Like the compiler, only an import that resolves can be reported as unused. */ + private boolean isResolvable(ImportTree importTree, String name, String currentPackage) { + if (importTree instanceof JavaTree.ImportTreeImpl impl && impl.isModule()) { + return true; + } + boolean onDemand = name.endsWith(".*"); + String qualifier = onDemand ? name.substring(0, name.length() - 2) : name; + if (onDemand && !importTree.isStatic() && (qualifier.equals(currentPackage) || sema.knowsPackage(qualifier))) { + return true; + } + return resolvesType(importTree.isStatic() && !onDemand ? qualifier.substring(0, Math.max(0, qualifier.lastIndexOf('.'))) : qualifier); + } + + private boolean resolvesType(String dotted) { + return binaryName(dotted) != null; + } + + /** The binary name of the type a dotted name denotes, trying each dot as a nesting boundary. */ + private String binaryName(String dotted) { + String candidate = dotted; + while (!candidate.isEmpty()) { + if (sema.declaresType(candidate)) { + return candidate; + } + int dot = candidate.lastIndexOf('.'); + if (dot < 0) { + return null; + } + candidate = candidate.substring(0, dot) + "$" + candidate.substring(dot + 1); + } + return null; + } + + private static boolean isInFileScope(IdentifierTree identifier) { + Symbol symbol = identifier.symbol(); + return !symbol.isUnknown() && symbol.declaration() != null && isInScope(symbol, identifier); + } + + private boolean isUsed(ImportTree importTree, String name, List outOfScope) { + if (importTree instanceof JavaTree.ImportTreeImpl impl && impl.isModule()) { + return true; + } + boolean onDemand = name.endsWith(".*"); + String qualifier = onDemand ? name.substring(0, name.length() - 2) : name.substring(0, Math.max(0, name.lastIndexOf('.'))); + return usedInJavadoc(importTree, name, qualifier) || outOfScope.stream().anyMatch(identifier -> uses(importTree, name, qualifier, identifier)); + } + + /** A Javadoc reference uses a single-type import of its name, and an on-demand import of a package declaring it. */ + private boolean usedInJavadoc(ImportTree importTree, String name, String qualifier) { + if (!name.endsWith(".*")) { + return javadocNames.contains(name.substring(name.lastIndexOf('.') + 1)); + } + return !importTree.isStatic() && javadocNames.stream().anyMatch(javadocName -> resolvesType(qualifier + "." + javadocName)); + } + + private boolean uses(ImportTree importTree, String name, String qualifier, IdentifierTree identifier) { + Symbol symbol = identifier.symbol(); + if (name.endsWith(".*")) { + String owner = qualifier.replace('$', '.'); + return declaredIn(symbol, owner, importTree.isStatic()) + || (importTree.isStatic() && !symbol.isUnknown() && !symbol.isTypeSymbol() && isMemberOf(symbol, owner)); + } + if (!identifier.name().equals(name.substring(name.lastIndexOf('.') + 1))) { + return false; + } + if (symbol.isUnknown()) { + return true; + } + // a class named with a dollar sign is a top-level class, as written in the import, not a nested one + String dotted = name.replace('$', '.'); + if (!importTree.isStatic()) { + return denotesType(symbol, dotted, identifier); + } + return isMemberOf(symbol, qualifier.replace('$', '.')) || (symbol.isTypeSymbol() && dottedType(symbol).equals(dotted)); + } + + /** A static import also brings in the members the named type inherits. */ + private boolean isMemberOf(Symbol symbol, String qualifier) { + if (!(symbol.owner() instanceof Symbol.TypeSymbol owner)) { + return false; + } + if (dottedType(owner).equals(qualifier)) { + return true; + } + String binary = binaryName(qualifier); + return binary != null && sema.getClassType(binary).isSubtypeOf(owner.type()); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CstNode.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CstNode.java new file mode 100644 index 00000000000..a2eb938d635 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CstNode.java @@ -0,0 +1,121 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nullable; +import org.sonarsource.semsitter.wire.Ref; + +import static org.sonar.java.semsitter.CstNodes.isComment; + +final class CstNode { + + private static final String BOUND = "bound"; + + final org.sonarsource.semsitter.wire.Node proto; + + CstNode(org.sonarsource.semsitter.wire.Node proto) { + this.proto = proto; + } + + String k() { + return proto.getKind(); + } + + String f() { + return proto.getField(); + } + + String text() { + return proto.getText(); + } + + boolean missing() { + return proto.getMissing(); + } + + int line() { + return proto.getStartLine(); + } + + int col() { + return proto.getStartCol(); + } + + List children() { + List children = new ArrayList<>(); + for (CstNode child : allChildren()) { + if (!isComment(child)) { + children.add(child); + } + } + return children; + } + + List allChildren() { + return proto.getChildrenList().stream().map(CstNode::new).toList(); + } + + @Nullable + String decl() { + return proto.getDeclsCount() == 0 ? null : proto.getDecls(0); + } + + List decls() { + return proto.getDeclsList(); + } + + boolean unresolved() { + if (proto.getRefsCount() == 0) { + return "type_identifier".equals(k()); + } + for (Ref ref : proto.getRefsList()) { + if (BOUND.equals(ref.getOutcome())) { + return false; + } + } + return true; + } + + @Nullable + String valueTarget() { + return target(true); + } + + @Nullable + String typeTarget() { + return target(false); + } + + @Nullable + String target(boolean value) { + String fallback = null; + for (Ref ref : proto.getRefsList()) { + if (ref.getTarget().isEmpty() || !BOUND.equals(ref.getOutcome())) { + continue; + } + String access = ref.getAccess(); + boolean isValue = "r".equals(access) || "w".equals(access) || "rw".equals(access); + if (isValue == value) { + return ref.getTarget(); + } + fallback = ref.getTarget(); + } + return value ? null : fallback; + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CstNodes.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CstNodes.java new file mode 100644 index 00000000000..560cdd2831c --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/CstNodes.java @@ -0,0 +1,291 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.List; +import javax.annotation.Nullable; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.JavaTree; +import org.sonar.java.model.KeywordSuper; +import org.sonar.java.model.KeywordThis; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.Modifier; +import org.sonar.plugins.java.api.tree.Tree; + +/** Navigation helpers over SemSitter CST nodes. */ +final class CstNodes { + + private static final String IDENTIFIER = "identifier"; + private static final String TYPE_IDENTIFIER = "type_identifier"; + + private CstNodes() { + } + + @Nullable + static CstNode firstProblem(CstNode node) { + if ("ERROR".equals(node.k()) || node.missing()) { + return node; + } + for (org.sonarsource.semsitter.wire.Node child : node.proto.getChildrenList()) { + CstNode problem = firstProblem(new CstNode(child)); + if (problem != null) { + return problem; + } + } + return null; + } + + static void collectLeaves(CstNode node, List leaves) { + if (isComment(node) || node.allChildren().isEmpty() || isLiteral(node.k())) { + if (!node.text().isEmpty()) { + leaves.add(node); + } + return; + } + for (CstNode child : node.allChildren()) { + collectLeaves(child, leaves); + } + } + + /** Tree-sitter splits {@code Record throws Ex} into a field named {@code throws} and a compact constructor named {@code Ex}. */ + @Nullable + static CstNode enumSeparator(List siblings, int index) { + CstNode next = siblings.get(index + 1); + if (",".equals(next.text())) { + return next; + } + if ("enum_body_declarations".equals(next.k())) { + return next.children().get(0); + } + return null; + } + + static boolean nextIsGroup(List siblings, int index) { + return "switch_block_statement_group".equals(siblings.get(index + 1).k()); + } + + static String dottedName(ExpressionTree tree) { + if (tree instanceof MemberSelectExpressionTree select) { + String qualifier = dottedName(select.expression()); + return qualifier.isEmpty() ? "" : (qualifier + "." + select.identifier().name()); + } + return tree instanceof IdentifierTree identifier ? identifier.name() : ""; + } + + /** The {@code this} or {@code super} written after a qualifier is a keyword, not a name. */ + static IdentifierTreeImpl receiverKeyword(IdentifierTreeImpl identifier) { + return switch (identifier.name()) { + case "this" -> new KeywordThis((InternalSyntaxToken) identifier.identifierToken(), Symbol.UNKNOWN_SYMBOL); + case "super" -> new KeywordSuper((InternalSyntaxToken) identifier.identifierToken(), Symbol.UNKNOWN_SYMBOL); + default -> identifier; + }; + } + + static boolean compoundName(CstNode node) { + return switch (node.k()) { + case "scoped_type_identifier", "scoped_identifier", "generic_type", "field_access" -> true; + default -> false; + }; + } + + static Modifier modifierKeyword(String text) { + return switch (text) { + case "public" -> Modifier.PUBLIC; + case "protected" -> Modifier.PROTECTED; + case "private" -> Modifier.PRIVATE; + case "static" -> Modifier.STATIC; + case "abstract" -> Modifier.ABSTRACT; + case "final" -> Modifier.FINAL; + case "native" -> Modifier.NATIVE; + case "synchronized" -> Modifier.SYNCHRONIZED; + case "transient" -> Modifier.TRANSIENT; + case "volatile" -> Modifier.VOLATILE; + case "strictfp" -> Modifier.STRICTFP; + case "default" -> Modifier.DEFAULT; + case "sealed" -> Modifier.SEALED; + case "non-sealed" -> Modifier.NON_SEALED; + default -> throw new IllegalArgumentException("Not a modifier: " + text); + }; + } + + static boolean isTypeKind(String kind) { + return switch (kind) { + case TYPE_IDENTIFIER, IDENTIFIER, "scoped_identifier", "scoped_type_identifier", "generic_type", "array_type", "integral_type", "floating_point_type", "boolean_type", + "void_type", "wildcard", "annotated_type" -> true; + default -> false; + }; + } + + private static boolean isLiteral(String kind) { + return switch (kind) { + case "string_literal", "character_literal", "text_block", "decimal_integer_literal", "hex_integer_literal", "octal_integer_literal", "binary_integer_literal", + "decimal_floating_point_literal", "hex_floating_point_literal" -> true; + default -> false; + }; + } + + static boolean isComment(CstNode node) { + return "line_comment".equals(node.k()) || "block_comment".equals(node.k()); + } + + static InternalSyntaxToken closingAngle(CstNode node) { + CstNode close = lastKeyword(node, ">"); + return new InternalSyntaxToken(close.line(), close.col(), ">", List.of(), false); + } + + @Nullable + static CstNode keyword(CstNode node, String text) { + for (CstNode child : node.children()) { + if (text.equals(child.text()) || text.equals(child.k())) { + return child; + } + } + return null; + } + + static CstNode lastKeyword(CstNode node, String text) { + List children = node.children(); + for (int i = children.size() - 1; i >= 0; i--) { + if (text.equals(children.get(i).text())) { + return children.get(i); + } + } + return node; + } + + static boolean same(@Nullable CstNode left, @Nullable CstNode right) { + return left != null && right != null && left.proto == right.proto; + } + + static CstNode required(CstNode node, String text) { + CstNode found = keyword(node, text); + return found == null ? node : found; + } + + @Nullable + static CstNode field(CstNode node, String name) { + for (CstNode child : node.children()) { + if (name.equals(child.f())) { + return child; + } + } + return null; + } + + static CstNode requiredField(CstNode node, String name, @Nullable CstNode fallback) { + CstNode found = field(node, name); + if (found != null) { + return found; + } + return fallback == null ? node : fallback; + } + + @Nullable + static CstNode childKind(CstNode node, String kind) { + for (CstNode child : node.children()) { + if (kind.equals(child.k())) { + return child; + } + } + return null; + } + + @Nullable + static CstNode firstOf(CstNode node, String... kinds) { + for (CstNode child : node.children()) { + for (String kind : kinds) { + if (kind.equals(child.k())) { + return child; + } + } + } + return null; + } + + @Nullable + static CstNode lastOf(CstNode node, String kind) { + CstNode found = null; + for (CstNode child : node.children()) { + if (kind.equals(child.k())) { + found = child; + } + } + return found; + } + + @Nullable + static CstNode nameNode(CstNode node) { + CstNode named = field(node, "name"); + return named != null ? named : firstOf(node, IDENTIFIER, TYPE_IDENTIFIER); + } + + @Nullable + static CstNode firstNamed(CstNode node) { + for (CstNode child : node.children()) { + if ((!child.text().equals(child.k()) || child.k().contains("_")) + && (!child.children().isEmpty() || child.k().contains("_") || IDENTIFIER.equals(child.k()) || TYPE_IDENTIFIER.equals(child.k()))) { + return child; + } + } + return node.children().isEmpty() ? node : node.children().get(0); + } + + static boolean isAnnotation(CstNode node) { + return "annotation".equals(node.k()) || "marker_annotation".equals(node.k()); + } + + static CstNode lastNamed(CstNode node) { + List children = node.children(); + for (int i = children.size() - 1; i >= 0; i--) { + CstNode child = children.get(i); + if (child.k().contains("_") || IDENTIFIER.equals(child.k())) { + return child; + } + } + return node; + } + + @Nullable + static CstNode firstType(CstNode node) { + for (CstNode child : node.children()) { + if (isTypeKind(child.k())) { + return child; + } + } + return null; + } + + static InternalSyntaxToken firstKeyword(CstNode node) { + CstNode keyword = node.children().get(0); + return new InternalSyntaxToken(keyword.line(), keyword.col(), keyword.text(), List.of(), false); + } + + static void setParents(Tree node) { + if (node instanceof JavaTree javaTree && node.kind() != Tree.Kind.INFERED_TYPE && node.kind() != Tree.Kind.TOKEN) { + for (Tree child : javaTree.getChildren()) { + if (child instanceof JavaTree javaChild) { + javaChild.setParent(node); + setParents(child); + } + } + } + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/DeclarationTranslator.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/DeclarationTranslator.java new file mode 100644 index 00000000000..f992fc3e2a9 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/DeclarationTranslator.java @@ -0,0 +1,290 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import javax.annotation.Nullable; +import org.sonar.java.ast.parser.ArgumentListTreeImpl; +import org.sonar.java.ast.parser.FormalParametersListTreeImpl; +import org.sonar.java.ast.parser.TypeParameterListTreeImpl; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.declaration.ClassTreeImpl; +import org.sonar.java.model.declaration.EnumConstantTreeImpl; +import org.sonar.java.model.declaration.MethodTreeImpl; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.java.model.expression.NewClassTreeImpl; +import org.sonar.java.model.statement.EmptyStatementTreeImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeTree; +import org.sonar.plugins.java.api.tree.VariableTree; + +import static org.sonar.java.semsitter.Bindings.argumentTypes; +import static org.sonar.java.semsitter.Bindings.ascribe; +import static org.sonar.java.semsitter.Bindings.bind; +import static org.sonar.java.semsitter.CstNodes.childKind; +import static org.sonar.java.semsitter.CstNodes.enumSeparator; +import static org.sonar.java.semsitter.CstNodes.field; +import static org.sonar.java.semsitter.CstNodes.firstKeyword; +import static org.sonar.java.semsitter.CstNodes.firstOf; +import static org.sonar.java.semsitter.CstNodes.firstType; +import static org.sonar.java.semsitter.CstNodes.nameNode; +import static org.sonar.java.semsitter.CstNodes.required; +import static org.sonar.java.semsitter.CstNodes.requiredField; + +/** Translates class, interface, enum, record and annotation type declarations. */ +final class DeclarationTranslator extends TranslatorPart { + + private static final String INTERFACE_DECLARATION = "interface_declaration"; + private static final String ENUM_DECLARATION = "enum_declaration"; + private static final String RECORD_DECLARATION = "record_declaration"; + private static final String ANNOTATION_TYPE_DECLARATION = "annotation_type_declaration"; + + DeclarationTranslator(TranslationState state) { + super(state); + } + + void addMember(List members, CstNode node) { + switch (node.k()) { + case "field_declaration", "constant_declaration", "local_variable_declaration" -> members.addAll(members().variables(node)); + case "method_declaration", "constructor_declaration", "compact_constructor_declaration" -> members.add(members().method(node)); + case "annotation_type_element_declaration" -> members.add(annotationElement(node)); + case "class_declaration", INTERFACE_DECLARATION, ENUM_DECLARATION, RECORD_DECLARATION, ANNOTATION_TYPE_DECLARATION -> members.add(typeDeclaration(node)); + case "static_initializer" -> members.add(members().staticInitializer(node)); + case "block" -> members.add(members().initializer(node)); + case ";" -> members.add(new EmptyStatementTreeImpl(token(node))); + case "{", "}" -> { + // punctuation of the body + } + default -> { + // skipped construct + } + } + } + + ClassTreeImpl typeDeclaration(CstNode node) { + 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 + CstNode typeParameters = field(node, "type_parameters"); + TypeParameterListTreeImpl typeParameterList = typeParameters == null ? null : typeTrees().typeParameters(typeParameters); + List members; + try { + members = membersOf(body); + } finally { + state.types.pop(); + } + ClassTreeImpl tree = new ClassTreeImpl(kind, token(required(body, "{")), members, token(required(body, "}"))); + IdentifierTreeImpl identifier = names().identifier(name); + InternalSyntaxToken keywordToken = token(required(node, declarationKeyword(node))); + if (kind == Tree.Kind.ANNOTATION_TYPE) { + tree.completeAtToken(new InternalSyntaxToken(keywordToken.line(), keywordToken.column(), "@", keywordToken.trivias(), false)); + keywordToken = new InternalSyntaxToken(keywordToken.line(), keywordToken.column() + 1, "interface", List.of(), false); + } + tree.complete(members().modifiers(node), keywordToken, identifier); + if (typeParameterList != null) { + tree.completeTypeParameters(typeParameterList); + } + if (kind == Tree.Kind.RECORD) { + CstNode parameters = requiredField(node, "parameters", null); + // the components must not shadow same-named variables of the enclosing method after the record + state.scopes.addFirst(new HashMap<>()); + try { + tree.completeRecordComponents(token(required(parameters, "(")), members().parameters(parameters), token(required(parameters, ")"))); + } finally { + state.scopes.removeFirst(); + } + } + completeHierarchy(tree, node); + bindDeclaration(tree, name, identifier); + bindSupertypes(tree, kind); + return tree; + } + + private Tree.Kind declarationKind(CstNode node) { + return switch (node.k()) { + case INTERFACE_DECLARATION -> Tree.Kind.INTERFACE; + case ENUM_DECLARATION -> Tree.Kind.ENUM; + case RECORD_DECLARATION -> state.records ? Tree.Kind.RECORD : Tree.Kind.CLASS; + case ANNOTATION_TYPE_DECLARATION -> Tree.Kind.ANNOTATION_TYPE; + default -> Tree.Kind.CLASS; + }; + } + + private static String declarationKeyword(CstNode node) { + return switch (node.k()) { + case INTERFACE_DECLARATION -> "interface"; + case ANNOTATION_TYPE_DECLARATION -> "@interface"; + case ENUM_DECLARATION -> "enum"; + case RECORD_DECLARATION -> "record"; + default -> "class"; + }; + } + + private void completeHierarchy(ClassTreeImpl tree, 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)); + } + 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) { + 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() + .map(VariableTree::symbol) + .filter(JVariableSymbol.class::isInstance) + .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)) { + 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()); + } + } + + List membersOf(CstNode body) { + List members = new ArrayList<>(); + List children = body.children(); + for (int i = 0; i < children.size(); i++) { + CstNode child = children.get(i); + if ("enum_constant".equals(child.k())) { + members.add(enumConstant(child, enumSeparator(children, i))); + } else if ("enum_body_declarations".equals(child.k())) { + List declarations = child.children(); + int j = 0; + while (childKind(body, "enum_constant") != null && j < declarations.size() && ";".equals(declarations.get(j).text())) { + j++; + } + for (; j < declarations.size(); j++) { + addMember(members, declarations.get(j)); + } + } else { + addMember(members, child); + } + } + return members; + } + + private EnumConstantTreeImpl enumConstant(CstNode node, @Nullable CstNode separatorNode) { + IdentifierTreeImpl name = names().identifier(requiredField(node, "name", firstOf(node, "identifier"))); + CstNode arguments = field(node, "arguments"); + ArgumentListTreeImpl args = arguments == null ? ArgumentListTreeImpl.emptyList() : expressions().arguments(arguments); + CstNode body = field(node, "body"); + ClassTreeImpl classBody = null; + if (body != null) { + classBody = new ClassTreeImpl(Tree.Kind.CLASS, token(required(body, "{")), membersOf(body), token(required(body, "}"))); + bindType(classBody, node); + } + InternalSyntaxToken separator = separatorNode == null ? null : token(separatorNode); + EnumConstantTreeImpl tree = new EnumConstantTreeImpl(members().modifiers(node), name, new NewClassTreeImpl(name, args, classBody), separator); + bindDeclaration(tree, nameNode(node), name); + Symbol.TypeSymbol enumType = state.types.element(); + if (classBody != null && enumType instanceof JSymbol enumSymbol) { + // An enum with a constant body is not final. + enumSymbol.removeModifier("final"); + } + boolean knownEnum = !enumType.isUnknown(); + bindEnumConstructor(name, args, knownEnum ? enumType : null); + if (knownEnum) { + ascribe(name, enumType.type()); + if (tree.symbol() instanceof JSymbol field && field.type().isUnknown()) { + field.type(enumType.type()); + } + } + return tree; + } + + /** The name of an enum constant is also its constructor call: it names the constructor of {@code enumType}, or nothing. */ + private void bindEnumConstructor(IdentifierTreeImpl name, ArgumentListTreeImpl args, @Nullable Symbol.TypeSymbol enumType) { + Symbol constructor = null; + if (enumType != null) { + String owner = enumType.type().fullyQualifiedName(); + Symbol.MethodSymbol declared = sema.lookup().declaredMethod(owner, "", argumentTypes(args)); + constructor = declared != null || !args.isEmpty() ? declared : sema.resolve(owner + "#()"); + } + bind(name, constructor instanceof Symbol.MethodSymbol ? constructor : null); + if (name.symbol() instanceof Symbol.MethodSymbol method && !method.isUnknown()) { + recordUse(method, name); + } + } + + private MethodTreeImpl annotationElement(CstNode node) { + FormalParametersListTreeImpl formals = new FormalParametersListTreeImpl(token(required(node, "(")), token(required(node, ")"))); + CstNode value = field(node, "value"); + IdentifierTreeImpl name = names().identifier(requiredField(node, "name", firstOf(node, "identifier"))); + MethodTreeImpl tree = new MethodTreeImpl(formals, value == null ? null : token(required(node, "default")), value == null ? null : expressions().expression(value)) + .complete(typeTrees().arrayType(typeTrees().type(requiredField(node, "type", firstType(node))), field(node, "dimensions")), name, token(required(node, ";"))) + .completeWithModifiers(members().modifiers(node)); + bindDeclaration(tree, nameNode(node), name); + return tree; + } + + void bindImplicitClass(ClassTreeImpl tree, List members) { + JTypeSymbol implicitClass = firstKnownOwner(members); + if (implicitClass == null && !state.implicitClassName.isEmpty() && sema.resolve(state.implicitClassName) instanceof JTypeSymbol named) { + implicitClass = named; + } + if (implicitClass == null) { + return; + } + tree.setSymbol(implicitClass); + sema.declare(implicitClass.id, tree); + adoptOrphanMethods(members, implicitClass); + } + + private static JTypeSymbol firstKnownOwner(List members) { + for (Tree member : members) { + if (member instanceof MethodTree method && method.symbol().owner() instanceof JTypeSymbol owner && !owner.isUnknown()) { + return owner; + } + } + return null; + } + + private static void adoptOrphanMethods(List members, JTypeSymbol implicitClass) { + for (Tree member : members) { + if (member instanceof MethodTree method && method.symbol() instanceof JMethodSymbol symbol && (symbol.owner() == null || symbol.owner().isUnknown())) { + symbol.owner(implicitClass); + } + } + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/EffectivelyFinalVariables.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/EffectivelyFinalVariables.java new file mode 100644 index 00000000000..f469c42938f --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/EffectivelyFinalVariables.java @@ -0,0 +1,152 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; +import org.sonar.java.model.ExpressionUtils; +import org.sonar.java.model.JavaTree; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.tree.AssignmentExpressionTree; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.CaseGroupTree; +import org.sonar.plugins.java.api.tree.CaseLabelTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.IfStatementTree; +import org.sonar.plugins.java.api.tree.SwitchTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.UnaryExpressionTree; +import org.sonar.plugins.java.api.tree.VariableTree; + +/** + * Marks the local variables and parameters that are never reassigned (JLS 4.12.4), as the compiler does. + * A local declared without a value stays effectively final when each plain assignment to it happens while it is + * definitely unassigned, approximated as: no assignment repeats in a loop of its scope, and any two assignments sit + * in exclusive branches, the two arms of an {@code if} or two arrow cases of a {@code switch}. + */ +final class EffectivelyFinalVariables extends BaseTreeVisitor { + + private final Map> plainAssignments = new IdentityHashMap<>(); + private final Set updated = Collections.newSetFromMap(new IdentityHashMap<>()); + private final List variables = new ArrayList<>(); + + private EffectivelyFinalVariables() { + } + + static void mark(JavaTree.CompilationUnitTreeImpl unit) { + EffectivelyFinalVariables visitor = new EffectivelyFinalVariables(); + visitor.scan(unit); + for (VariableTree variable : visitor.variables) { + JVariableSymbol symbol = (JVariableSymbol) variable.symbol(); + List assignments = visitor.plainAssignments.getOrDefault(symbol, List.of()); + boolean unassigned = variable.initializer() == null && isLocalDeclaration(variable); + boolean effectivelyFinal = !visitor.updated.contains(symbol) && (assignments.isEmpty() || (unassigned && assignedOnce(variable, assignments))); + symbol.effectivelyFinal(effectivelyFinal); + } + } + + static boolean isLocalDeclaration(VariableTree variable) { + Tree parent = variable.parent(); + return parent.is(Tree.Kind.BLOCK, Tree.Kind.CASE_GROUP, Tree.Kind.STATIC_INITIALIZER, Tree.Kind.INITIALIZER) + || (parent.is(Tree.Kind.LIST) && parent.parent() != null && parent.parent().is(Tree.Kind.FOR_STATEMENT)); + } + + static boolean assignedOnce(VariableTree variable, List assignments) { + if (assignments.stream().anyMatch(assignment -> repeatsInLoop(assignment, variable.parent()))) { + return false; + } + for (int i = 0; i < assignments.size(); i++) { + for (int j = i + 1; j < assignments.size(); j++) { + if (!exclusive(assignments.get(i), assignments.get(j))) { + return false; + } + } + } + return true; + } + + private static boolean repeatsInLoop(Tree assignment, Tree scope) { + for (Tree current = assignment.parent(); current != null && current != scope; current = current.parent()) { + if (current.is(Tree.Kind.FOR_STATEMENT, Tree.Kind.FOR_EACH_STATEMENT, Tree.Kind.WHILE_STATEMENT, Tree.Kind.DO_STATEMENT)) { + return true; + } + } + return false; + } + + /** Whether at most one of {@code first} and {@code second} runs: they sit in two arms of one branching. */ + private static boolean exclusive(Tree first, Tree second) { + Map firstPath = new IdentityHashMap<>(); + for (Tree child = first, current = first.parent(); current != null; child = current, current = current.parent()) { + firstPath.put(current, child); + } + Tree child = second; + Tree common = second.parent(); + while (common != null && !firstPath.containsKey(common)) { + child = common; + common = common.parent(); + } + if (common instanceof IfStatementTree branch) { + Tree other = firstPath.get(common); + return child != other && branch.elseStatement() != null && Set.of(branch.thenStatement(), branch.elseStatement()).equals(Set.of(child, other)); + } + return common instanceof SwitchTree && isArrowCase(child) && isArrowCase(firstPath.get(common)) && child != firstPath.get(common); + } + + private static boolean isArrowCase(Tree tree) { + return tree instanceof CaseGroupTree group && group.labels().stream().noneMatch(CaseLabelTree::isFallThrough); + } + + @Override + public void visitVariable(VariableTree tree) { + if (tree.symbol() instanceof JVariableSymbol symbol && (symbol.isLocalVariable() || symbol.isParameter())) { + variables.add(tree); + } + super.visitVariable(tree); + } + + @Override + public void visitAssignmentExpression(AssignmentExpressionTree tree) { + Symbol target = assigned(tree.variable()); + if (target != null && tree.is(Tree.Kind.ASSIGNMENT)) { + plainAssignments.computeIfAbsent(target, key -> new ArrayList<>()).add(tree); + } else if (target != null) { + updated.add(target); + } + super.visitAssignmentExpression(tree); + } + + @Override + public void visitUnaryExpression(UnaryExpressionTree tree) { + Symbol target = assigned(tree.expression()); + if (target != null && tree.is(Tree.Kind.PREFIX_INCREMENT, Tree.Kind.PREFIX_DECREMENT, Tree.Kind.POSTFIX_INCREMENT, Tree.Kind.POSTFIX_DECREMENT)) { + updated.add(target); + } + super.visitUnaryExpression(tree); + } + + @Nullable + private static Symbol assigned(ExpressionTree target) { + return ExpressionUtils.skipParentheses(target) instanceof IdentifierTree identifier ? identifier.symbol() : null; + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/ExpressionTranslator.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/ExpressionTranslator.java new file mode 100644 index 00000000000..4e795707944 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/ExpressionTranslator.java @@ -0,0 +1,478 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nullable; +import org.sonar.java.ast.parser.ArgumentListTreeImpl; +import org.sonar.java.ast.parser.QualifiedIdentifierListTreeImpl; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.JavaTree; +import org.sonar.java.model.LiteralUtils; +import org.sonar.java.model.declaration.VariableTreeImpl; +import org.sonar.java.model.expression.AssignmentExpressionTreeImpl; +import org.sonar.java.model.expression.BinaryExpressionTreeImpl; +import org.sonar.java.model.expression.ConditionalExpressionTreeImpl; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.java.model.expression.InstanceOfTreeImpl; +import org.sonar.java.model.expression.InternalPostfixUnaryExpression; +import org.sonar.java.model.expression.InternalPrefixUnaryExpression; +import org.sonar.java.model.expression.LambdaExpressionTreeImpl; +import org.sonar.java.model.expression.MethodInvocationTreeImpl; +import org.sonar.java.model.expression.NewArrayTreeImpl; +import org.sonar.java.model.expression.NewClassTreeImpl; +import org.sonar.java.model.expression.ParenthesizedTreeImpl; +import org.sonar.java.model.expression.TypeCastExpressionTreeImpl; +import org.sonar.java.model.pattern.TypePatternTreeImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.ConditionalExpressionTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeTree; + +import static org.sonar.java.semsitter.Bindings.argumentTypes; +import static org.sonar.java.semsitter.Bindings.ascribe; +import static org.sonar.java.semsitter.Bindings.assignmentKind; +import static org.sonar.java.semsitter.Bindings.binaryKind; +import static org.sonar.java.semsitter.Bindings.binaryType; +import static org.sonar.java.semsitter.Bindings.bind; +import static org.sonar.java.semsitter.Bindings.keepsArguments; +import static org.sonar.java.semsitter.Bindings.literal; +import static org.sonar.java.semsitter.Bindings.sameErasure; +import static org.sonar.java.semsitter.Bindings.unaryKind; +import static org.sonar.java.semsitter.Bindings.unboxed; +import static org.sonar.java.semsitter.Bindings.variableType; +import static org.sonar.java.semsitter.CstNodes.field; +import static org.sonar.java.semsitter.CstNodes.firstNamed; +import static org.sonar.java.semsitter.CstNodes.lastNamed; +import static org.sonar.java.semsitter.CstNodes.required; +import static org.sonar.java.semsitter.CstNodes.requiredField; + +/** Translates expressions and operators, and ascribes target types. */ +final class ExpressionTranslator extends TranslatorPart { + + private static final String OPERATOR = "operator"; + private static final String RIGHT = "right"; + private static final String BOOLEAN = "boolean"; + private static final String SHORT = "short"; + private static final String INSTANCEOF = "instanceof"; + + ExpressionTranslator(TranslationState state) { + super(state); + } + + ExpressionTree expression(CstNode node) { + return switch (node.k()) { + case "decimal_integer_literal", "hex_integer_literal", "octal_integer_literal", "binary_integer_literal" -> names().integerLiteral(node); + case "decimal_floating_point_literal", "hex_floating_point_literal" -> names().floatingLiteral(node); + case "string_literal", "string_fragment" -> + literal(node.text().startsWith("\"\"\"") ? Tree.Kind.TEXT_BLOCK : Tree.Kind.STRING_LITERAL, token(node), sema.getClassType("java.lang.String")); + case "character_literal" -> literal(Tree.Kind.CHAR_LITERAL, token(node), sema.getClassType("char")); + case "scoped_identifier", "scoped_type_identifier", "field_access" -> names().memberSelect(node); + case "method_invocation" -> invocations().invocation(node); + case "object_creation_expression" -> invocations().creation(node); + case "array_creation_expression" -> invocations().arrayCreation(node); + case "array_initializer", "element_value_array_initializer" -> invocations().arrayInitializer(node); + case "element_value_pair" -> members().elementValuePair(node); + case "class_literal" -> invocations().classLiteral(node); + case "annotation", "marker_annotation" -> members().annotation(node); + case "array_access" -> invocations().arrayAccess(node); + case "assignment_expression" -> assignment(node); + case "binary_expression" -> binary(node); + case "unary_expression" -> unary(node); + case "update_expression" -> update(node); + case "parenthesized_expression" -> parenthesized(node); + case "ternary_expression" -> ternary(node); + case "cast_expression" -> cast(node); + case "instanceof_expression" -> instanceOf(node); + case "lambda_expression" -> lambdas().lambda(node); + case "method_reference" -> lambdas().methodReference(node); + case "switch_expression" -> switches().switchExpression(node); + case "generic_type", "array_type", "integral_type", "floating_point_type", "boolean_type", "void_type", "wildcard", "annotated_type" -> invocations().typeExpression(node); + default -> names().primary(node); + }; + } + + /** Types a lambda, a method reference or an array initializer from the type its context expects. */ + void ascribeTarget(ExpressionTree expression, Type target) { + ascribeTargetTyped(expression, target); + ascribeArrayElements(expression, target); + if (expression instanceof NewClassTreeImpl newClass) { + inferDiamond(newClass, target); + } + ascribePolyExpression(expression, target); + ascribeGenericCall(expression, target); + ascribeCollectorCall(expression, target); + if (expression instanceof LambdaExpressionTreeImpl lambda) { + lambdas().bindLambdaParameterOwner(lambda, lambda.symbolType()); + } + } + + private void ascribeTargetTyped(ExpressionTree expression, Type target) { + boolean targetTyped = expression.is(Tree.Kind.LAMBDA_EXPRESSION, Tree.Kind.METHOD_REFERENCE) || (expression instanceof NewArrayTreeImpl array && array.type() == null); + // an erased type variable (Object) is not a functional interface: wait for the inferred parameter + if (targetTyped && expression.symbolType().isUnknown() && !target.isUnknown() && !target.is("java.lang.Object")) { + ascribe(expression, expression instanceof NewArrayTreeImpl ? target : sema.inference().groundType(target)); + } + } + + private void ascribeArrayElements(ExpressionTree expression, Type target) { + if (expression instanceof NewArrayTreeImpl array && array.type() == null && target instanceof Type.ArrayType arrayType) { + array.initializers().forEach(element -> ascribeTarget(element, arrayType.elementType())); + } + } + + private static void ascribePolyExpression(ExpressionTree expression, Type target) { + // a switch expression is a poly expression: in an assignment context it has the target type + if (expression.is(Tree.Kind.SWITCH_EXPRESSION) && !target.isUnknown() && !target.isPrimitive() && !expression.symbolType().isPrimitive()) { + ascribe(expression, target); + } + // a reference conditional is a poly expression: in an assignment context it has the target type + if (expression instanceof ConditionalExpressionTree && keepsArguments(target) && sameErasure(target, expression.symbolType())) { + ascribe(expression, target); + } + } + + private void ascribeGenericCall(ExpressionTree expression, Type target) { + if (expression instanceof MethodInvocationTreeImpl call + && call.methodSymbol() instanceof JMethodSymbol generic + && !generic.isUnknown() + && (!call.symbolType().isParameterized() || capturesAnArgument(call.symbolType()))) { + Type inferred = sema.inference().targetedReturn(generic, target); + if (inferred != null) { + ascribe(call, inferred); + List parameters = sema.functionalInference().targetedParameters(generic, target); + if (parameters != null && parameters.size() == generic.parameterTypes().size()) { + ascribeArguments(generic, parameters, call.arguments()); + } + } + } + } + + private static boolean capturesAnArgument(Type type) { + return type.typeArguments().stream().anyMatch(argument -> argument instanceof JType captured && captured.isCapture()); + } + + private void ascribeCollectorCall(ExpressionTree expression, Type target) { + if (expression instanceof MethodInvocationTreeImpl call + && call.methodSymbol() instanceof JMethodSymbol generic + && !generic.isUnknown() + && call.symbolType().isParameterized() + && target.isParameterized() + && call.arguments().stream().anyMatch(argument -> argument.is(Tree.Kind.METHOD_INVOCATION) && argument.symbolType().is("java.util.stream.Collector"))) { + Type retargeted = sema.inference().retargetedElement(generic, generic.owner().type(), call.symbolType(), target); + if (retargeted != null) { + ascribe(call, retargeted); + } + } + } + + /** A diamond takes the type arguments its target gives the created class, and its constructor is seen from that type. */ + void inferDiamond(NewClassTreeImpl tree, Type target) { + if (!(tree.identifier() instanceof JavaTree.ParameterizedTypeTreeImpl generic) || !generic.typeArguments().isEmpty() || !target.isParameterized()) { + return; + } + boolean anonymous = tree.classBody() != null && tree.classBody().symbol() instanceof JTypeSymbol body && !body.isUnknown(); + // an anonymous class keeps its own type; the diamond parameterizes the supertype it names + Type inferred = sema.inference().inferDiamond(anonymous ? generic.symbolType() : tree.symbolType(), sema.inference().groundType(target)); + if (!inferred.isParameterized()) { + return; + } + ascribe(generic, inferred); + if (anonymous) { + ((JTypeSymbol) tree.classBody().symbol()).declaredSupertype(inferred); + return; + } + ascribe(tree, inferred); + IdentifierTreeImpl identifier = (IdentifierTreeImpl) tree.getConstructorIdentifier(); + ascribe(identifier, inferred); + if (identifier.symbol() instanceof JMethodSymbol constructor && !constructor.isUnknown()) { + List parameters = sema.substitution().invocationParameters(constructor, inferred, argumentTypes(tree.arguments())); + bind(identifier, sema.substitution().invocationView(constructor, inferred, parameters, constructor.returnType().type())); + } + } + + void ascribeArguments(Symbol.MethodSymbol method, List arguments) { + ascribeArguments(method, method.parameterTypes(), arguments); + } + + /** Types the arguments from the declared parameters, substituted for the receiver's type arguments when the call is generic. */ + void ascribeArguments(Symbol.MethodSymbol method, List parameters, List arguments) { + for (int i = 0; i < arguments.size() && !parameters.isEmpty(); i++) { + Type parameter = parameters.get(Math.min(i, parameters.size() - 1)); + if (method.isVarArgsMethod() && i >= parameters.size() - 1 && parameter.isArray() + && (arguments.size() != parameters.size() || arguments.get(i).is(Tree.Kind.LAMBDA_EXPRESSION, Tree.Kind.METHOD_REFERENCE))) { + parameter = ((Type.ArrayType) parameter).elementType(); + } + if (i < parameters.size() || method.isVarArgsMethod()) { + ascribeTarget(arguments.get(i), parameter); + } + } + } + + private AssignmentExpressionTreeImpl assignment(CstNode node) { + CstNode operator = requiredField(node, OPERATOR, null); + AssignmentExpressionTreeImpl tree = new AssignmentExpressionTreeImpl( + assignmentKind(operator.text()), + expression(requiredField(node, "left", firstNamed(node))), + token(operator), + expression(requiredField(node, RIGHT, lastNamed(node)))); + ascribe(tree, tree.variable().symbolType()); + if (tree.is(Tree.Kind.ASSIGNMENT)) { + ascribeTarget(tree.expression(), tree.variable().symbolType()); + } + return tree; + } + + private BinaryExpressionTreeImpl binary(CstNode node) { + CstNode operator = requiredField(node, OPERATOR, null); + String text = operator.text(); + ExpressionTree left = expression(requiredField(node, "left", firstNamed(node))); + ExpressionTree right = expression(requiredField(node, RIGHT, lastNamed(node))); + BinaryExpressionTreeImpl tree = new BinaryExpressionTreeImpl(binaryKind(text), left, token(operator), right); + ascribe(tree, binaryType(text, left.symbolType(), right.symbolType())); + return tree; + } + + private ExpressionTree unary(CstNode node) { + CstNode operator = requiredField(node, OPERATOR, null); + String text = operator.text(); + ExpressionTree value = expression(requiredField(node, "operand", firstNamed(node))); + InternalPrefixUnaryExpression tree = new InternalPrefixUnaryExpression(unaryKind(text, true), token(operator), value); + ascribe(tree, "!".equals(text) ? sema.getClassType(BOOLEAN) : unaryPromoted(value.symbolType())); + return tree; + } + + /** {@code +}, {@code -} and {@code ~} promote a byte, short or char operand to int. */ + private Type unaryPromoted(Type operand) { + Type primitive = unboxed(operand); + if (!primitive.isPrimitive()) { + return operand; + } + boolean narrow = primitive.is("byte") || primitive.is(SHORT) || primitive.is("char"); + return narrow ? sema.getClassType("int") : primitive; + } + + private ExpressionTree update(CstNode node) { + List children = node.children(); + CstNode first = children.get(0); + boolean prefix = "++".equals(first.text()) || "--".equals(first.text()); + CstNode operator = prefix ? first : children.get(children.size() - 1); + ExpressionTree operand = expression(firstNamed(node)); + String text = operator.text(); + InternalSyntaxToken token = token(operator); + ExpressionTree tree = prefix + ? new InternalPrefixUnaryExpression(unaryKind(text, true), token, operand) + : new InternalPostfixUnaryExpression(unaryKind(text, false), operand, token); + ascribe(tree, operand.symbolType()); + return tree; + } + + private ParenthesizedTreeImpl parenthesized(CstNode node) { + Parens parens = parens(node); + ParenthesizedTreeImpl tree = new ParenthesizedTreeImpl(parens.open(), parens.expr(), parens.close()); + ascribe(tree, parens.expr().symbolType()); + return tree; + } + + private ConditionalExpressionTreeImpl ternary(CstNode node) { + ExpressionTree condition = expression(requiredField(node, "condition", firstNamed(node))); + ExpressionTree then = expression(requiredField(node, "consequence", firstNamed(node))); + ExpressionTree otherwise = expression(requiredField(node, "alternative", lastNamed(node))); + ConditionalExpressionTreeImpl tree = new ConditionalExpressionTreeImpl(condition, token(required(node, "?")), then, token(required(node, ":")), otherwise); + ascribe(tree, conditionalType(then, otherwise)); + return tree; + } + + /** The type of a conditional: operands of numeric or boolean types are unboxed and promoted, others keep the more general operand type. */ + private Type conditionalType(ExpressionTree then, ExpressionTree otherwise) { + Type first = then.symbolType(); + Type second = otherwise.symbolType(); + if (first.isUnknown() || second.isUnknown()) { + return first.isUnknown() ? second : first; + } + if (first.equals(second)) { + return first; + } + Type left = primitiveOperand(first); + Type right = primitiveOperand(second); + if (isUnboxedConditional(first, second, left, right)) { + return unboxedConditionalType(first, left, right, then, otherwise); + } + if (first.isNullType() || second.isNullType()) { + return nullConditionalType(first, second); + } + // a type variable is compared by its bound: erasing it would make the variable look like its own bound + if ((first.isTypeVar() || second.isTypeVar()) && !first.isPrimitive() && !second.isPrimitive()) { + return typeVariableConditionalType(first, second); + } + return referenceConditionalType(first, second); + } + + private static Type primitiveOperand(Type operand) { + return operand.isPrimitive() ? operand : operand.primitiveType(); + } + + private static boolean isUnboxedConditional(Type first, Type second, @Nullable Type left, @Nullable Type right) { + boolean oneIsPrimitive = first.isPrimitive() || second.isPrimitive(); + return left != null && right != null && (oneIsPrimitive || (first.isPrimitiveWrapper() && second.isPrimitiveWrapper() && !left.equals(right))); + } + + private Type unboxedConditionalType(Type first, Type left, Type right, ExpressionTree then, ExpressionTree otherwise) { + if (left.equals(right)) { + return left; + } + if (left.is(BOOLEAN) || right.is(BOOLEAN)) { + return first; + } + return numericPromotion(left, right, then, otherwise); + } + + private static Type nullConditionalType(Type first, Type second) { + if (first.isNullType()) { + return second.isPrimitive() ? second.primitiveWrapperType() : second; + } + return first.isPrimitive() ? first.primitiveWrapperType() : first; + } + + private Type typeVariableConditionalType(Type first, Type second) { + if (second.isSubtypeOf(first)) { + return first; + } + if (first.isSubtypeOf(second)) { + return second; + } + Type firstBound = typeVariableBound(first); + Type secondBound = typeVariableBound(second); + return !secondBound.isSubtypeOf(firstBound.erasure()) && firstBound.isSubtypeOf(secondBound.erasure()) ? secondBound : firstBound; + } + + private Type typeVariableBound(Type type) { + return type instanceof JType variable && variable.isTypeVar() ? sema.memberFactory().typeVariableBound(variable.typeVarId) : type; + } + + private static Type referenceConditionalType(Type first, Type second) { + if (!first.isPrimitive() && !second.isPrimitive()) { + if (second.isSubtypeOf(first.erasure())) { + return first; + } + if (first.isSubtypeOf(second.erasure())) { + return second; + } + } + return first; + } + + private Type numericPromotion(Type left, Type right, ExpressionTree then, ExpressionTree otherwise) { + List order = List.of("byte", SHORT, "char", "int", "long", "float", "double"); + int a = order.indexOf(left.fullyQualifiedName()); + int b = order.indexOf(right.fullyQualifiedName()); + boolean byteAndShort = (a == 0 && b == 1) || (a == 1 && b == 0); + if (byteAndShort) { + return sema.getClassType(SHORT); + } + // a constant int that fits the narrower operand keeps that type + if (a < 3 && right.is("int") && fitsIn(otherwise, left)) { + return left; + } + if (b < 3 && left.is("int") && fitsIn(then, right)) { + return right; + } + return sema.getClassType(order.get(Math.max(3, Math.max(a, b)))); + } + + static boolean fitsIn(ExpressionTree constant, Type narrow) { + Integer value = LiteralUtils.intLiteralValue(constant); + if (value == null) { + return false; + } + return switch (narrow.fullyQualifiedName()) { + case "byte" -> value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE; + case SHORT -> value >= Short.MIN_VALUE && value <= Short.MAX_VALUE; + default -> value >= Character.MIN_VALUE && value <= Character.MAX_VALUE; + }; + } + + private TypeCastExpressionTreeImpl cast(CstNode node) { + List typeNodes = node.children().stream().filter(child -> "type".equals(child.f())).toList(); + TypeTree type = typeTrees().type(typeNodes.get(0)); + List ands = node.children().stream().filter(child -> "&".equals(child.k())).toList(); + QualifiedIdentifierListTreeImpl bounds = QualifiedIdentifierListTreeImpl.emptyList(); + for (int i = 1; i < typeNodes.size(); i++) { + bounds.add(typeTrees().type(typeNodes.get(i))); + if (i < ands.size()) { + bounds.separators().add(token(ands.get(i))); + } + } + ExpressionTree value = expression(requiredField(node, "value", lastNamed(node))); + 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()) { + ascribe(tree, type.symbolType()); + // The cast type is the target of a lambda operand (JLS 15.16). Only its parameters are rebound: typing the lambda itself would make the cast look redundant. + // The rebinding mirrors the ECJ-based analysis, which suppresses S1117 for a lambda parameter whose target is a nested, implicitly static interface. + if (value instanceof LambdaExpressionTreeImpl lambda && !type.symbolType().isUnknown()) { + lambdas().bindLambdaParameterOwner(lambda, sema.inference().groundType(type.symbolType())); + } + } else { + List parts = new ArrayList<>(); + parts.add(sema.asJType(type.symbolType())); + bounds.forEach(bound -> parts.add(sema.asJType(bound.symbolType()))); + ascribe(tree, JType.intersection(sema, parts)); + } + return tree; + } + + private InstanceOfTreeImpl instanceOf(CstNode node) { + ExpressionTree left = expression(requiredField(node, "left", firstNamed(node))); + CstNode name = field(node, "name"); + CstNode patternNode = field(node, "pattern"); + InstanceOfTreeImpl tree; + if (patternNode != null) { + tree = new InstanceOfTreeImpl(left, token(required(node, INSTANCEOF)), lambdas().pattern(patternNode)); + } else if (name != null) { + VariableTreeImpl variable = new VariableTreeImpl(members().modifiers(node), typeTrees().type(requiredField(node, RIGHT, null)), names().identifier(name)); + bindDeclaration(variable, name, (IdentifierTreeImpl) variable.simpleName()); + TypePatternTreeImpl pattern = new TypePatternTreeImpl(variable, variableType(variable)); + tree = new InstanceOfTreeImpl(left, token(required(node, INSTANCEOF)), pattern); + } else { + tree = new InstanceOfTreeImpl(left, token(required(node, INSTANCEOF)), typeTrees().type(requiredField(node, RIGHT, null))); + } + ascribe(tree, sema.getClassType(BOOLEAN)); + return tree; + } + + ArgumentListTreeImpl arguments(CstNode node) { + ArgumentListTreeImpl list = ArgumentListTreeImpl.emptyList(); + InternalSyntaxToken open = null; + InternalSyntaxToken close = null; + for (CstNode child : node.children()) { + if ("(".equals(child.text())) { + open = token(child); + } else if (")".equals(child.text())) { + close = token(child); + } else if (",".equals(child.text())) { + list.separators().add(token(child)); + } else { + list.add(expression(child)); + } + } + return list.complete(open, close); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FactAnnotation.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FactAnnotation.java new file mode 100644 index 00000000000..ec438755e85 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FactAnnotation.java @@ -0,0 +1,45 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.List; +import org.sonar.java.model.AnnotationValueImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.SymbolMetadata.AnnotationInstance; +import org.sonar.plugins.java.api.semantic.SymbolMetadata.AnnotationValue; + +final class FactAnnotation implements AnnotationInstance { + + private final Symbol symbol; + private final List values; + + FactAnnotation(JSema sema, String fqn, List values, boolean valuesKnown) { + this.symbol = sema.typeSymbol(fqn); + // An annotation known by name only keeps one unknown value, so a consumer that reads a value never meets an empty list. + this.values = valuesKnown ? values : List.of(new AnnotationValueImpl("value", null)); + } + + @Override + public Symbol symbol() { + return symbol; + } + + @Override + public List values() { + return values; + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FactTypes.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FactTypes.java index 19f7f932863..5f197384719 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FactTypes.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FactTypes.java @@ -37,6 +37,8 @@ final class FactTypes { private static final String OBJECT = "java.lang.Object"; + private static final String TERM = "java::"; + private static final String HASHED_TERM = TERM + "{"; private final JSema sema; private final Map placeholders = new HashMap<>(); @@ -247,7 +249,18 @@ private static String variablePrefix(String key, String owner) { return key.startsWith(erased + "<") ? erased : null; } - Type typeFromName(String name) { + /** + * The type a fact names: a class, a primitive, a type variable item or an array of those. An array term is spelled + * {@code java::byte[]} over its element; a hashed term, {@code java::{...}}, spells no element and stays unknown. + */ + Type typeFromName(String id) { + if (id.startsWith(HASHED_TERM)) { + return JType.unknown(sema); + } + String name = id.startsWith(TERM) ? id.substring(TERM.length()) : id; + if (name.endsWith("[]")) { + return JType.array(sema, sema.asJType(typeFromName(name.substring(0, name.length() - 2)))); + } JTypeSymbol variable = typeParameterItem(name); if (variable != null) { return variable.type(); @@ -256,9 +269,6 @@ Type typeFromName(String name) { if (JSema.PRIMITIVES.contains(erased)) { return sema.primitiveType(erased); } - if (erased.endsWith("[]")) { - return JType.array(sema, sema.asJType(typeFromName(erased.substring(0, erased.length() - 2)))); - } return sema.getClassType(erased); } diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FileImports.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FileImports.java new file mode 100644 index 00000000000..47f2c945708 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FileImports.java @@ -0,0 +1,30 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** The imports of the translated file: single-type ones by simple name, on-demand ones by package or type. */ +final class FileImports { + final Map singleImports = new HashMap<>(); + final List onDemandImports = new ArrayList<>(); + final Map staticImports = new HashMap<>(); + final List staticOnDemandImports = new ArrayList<>(); +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FullGenStats.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FullGenStats.java new file mode 100644 index 00000000000..8a1a9071eb5 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FullGenStats.java @@ -0,0 +1,30 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import javax.annotation.Nullable; + +/** + * What the server answers to {@code full-gen}: how many files it scanned and, when it reports them, how long the scan took + * on its side, how many files it failed to scan, and its peak resident memory. A measure the server does not report is null. + */ +public record FullGenStats(int files, @Nullable Long elapsedMs, @Nullable Long failures, @Nullable Long peakRssKb) { + + static FullGenStats of(int files) { + return new FullGenStats(files, null, null, null); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FunctionalInference.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FunctionalInference.java index 8f6b2bad63d..84138eaac68 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FunctionalInference.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/FunctionalInference.java @@ -16,36 +16,190 @@ */ package org.sonar.java.semsitter; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; import javax.annotation.Nullable; import org.sonar.plugins.java.api.semantic.Type; -/** Parameter and result types of lambdas and method references, unknown until inference from their target lands. */ -class FunctionalInference { +import static org.sonar.java.semsitter.SemaFacts.erase; +import static org.sonar.java.semsitter.SemaFacts.text; - /** The functional interface {@code parameter} as a function producing {@code produced}, or null when unknown. */ - @Nullable - Type functionProducing(Type parameter, Type produced) { - return null; +/** Parameter and result types of lambdas and method references, inferred from their functional target. */ +final class FunctionalInference { + + private final JSema sema; + + FunctionalInference(JSema sema) { + this.sema = sema; } /** - * Whether {@code method} returns a type variable. - * @param method method to inspect, used once inference lands + * The functional interface {@code parameter} with only the type argument its method returns known, as the type a + * function that produces {@code produced} has there, or null when {@code parameter} is not such an interface. */ + @Nullable + Type functionProducing(Type parameter, Type produced) { + if (!(parameter instanceof JType declared) || !declared.isParameterized() || produced.isUnknown() || produced.isTypeVar() || Substitution.mentionsTypeVariable(produced)) { + return null; + } + JMethodSymbol functional = sema.lookup().functionalMethod(declared); + Integer position = functional == null ? null : sema.substitution().returnedClassVariable(functional, declared); + if (position == null || position >= declared.args.size()) { + return null; + } + JType boxed = sema.asJType(produced.isPrimitive() ? produced.primitiveWrapperType() : produced); + List arguments = new ArrayList<>(); + for (int i = 0; i < declared.args.size(); i++) { + arguments.add(i == position ? boxed : JType.unknown(sema)); + } + return JType.inferred(sema, declared.erasure().fullyQualifiedName(), arguments); + } + + /** Whether {@code method} returns a type variable, as the descriptor erases it or as its source declares it. */ boolean returnsClassVariable(JMethodSymbol method) { - return false; + JsonObject returned = sema.substitution().declaredReturn(method); + Type declared = method.returnType().type(); + if (returned == null) { + return declared != null && declared.isTypeVar(); + } + return "typevar".equals(text(returned, "kind")); } - /** The result of an unbound method reference to {@code method} implementing {@code function}, or null when unknown. */ + /** + * What {@code Type::method} yields when the method returns a class type variable, read from the first + * parameter of {@code function}, the receiver it is applied to; null when that is not known. + */ @Nullable Type unboundReferenceResult(JMethodSymbol method, Type function) { - return null; + JMethodSymbol functional = sema.lookup().functionalMethod(function); + if (method.isStatic() || functional == null || sema.inference().declaresTypeVariables(method, false)) { + return null; + } + List parameters = sema.substitution().invocationParameters(functional, sema.inference().groundType(function), List.of()); + if (parameters.isEmpty() || method.owner().type() == null) { + return null; + } + Type receiver = sema.inference().groundType(parameters.get(0)); + Type declaring = receiver.isUnknown() ? null : sema.substitution().asSuperType(receiver, method.owner().type().erasure().fullyQualifiedName(), new HashSet<>()); + if (declaring == null || !declaring.isParameterized()) { + return null; + } + Type result = sema.inference().invocationReturn(method, declaring, List.of()); + return result.isUnknown() || result.isTypeVar() ? null : result; } - /** The parameter types of {@code method} fixed by {@code target}, or null when unknown. */ + /** + * The parameter types of {@code method} when the type its call is passed as fixes the type variables of the + * method, or null when they stay open. + */ @Nullable List targetedParameters(JMethodSymbol method, Type target) { - return null; + JsonObject member = sema.substitution().lookupGenericMember(method); + JsonObject declared = sema.substitution().declaredReturn(method); + if (member == null || declared == null || !(member.get("typeVars") instanceof JsonArray names) || names.isEmpty()) { + return null; + } + Set own = new HashSet<>(); + names.forEach(name -> own.add(name.getAsString())); + Map bound = new HashMap<>(); + bindReturnToTarget(declared, target, own, bound); + List parameters = sema.substitution().declaredParameters(method); + if (bound.isEmpty() || parameters.isEmpty()) { + return null; + } + List result = new ArrayList<>(); + for (JsonObject parameter : parameters) { + JType type = sema.factTypes().typeFromFact(parameter, bound); + result.add(type.isUnknown() || Substitution.mentionsTypeVariable(type) ? Type.UNKNOWN : type); + } + return result; + } + + /** + * Binds the type variables a declared return type names from the type the call is passed as. The target may be a + * supertype of the declared type: its arguments are read through the supertype of the declared type it names. + */ + void bindReturnToTarget(JsonObject declared, Type target, Set variables, Map bound) { + bindFromType(declared, target, variables, bound); + if (!bound.isEmpty() || !(target instanceof JType expected) || !expected.isParameterized() || declared.get("args") == null) { + return; + } + JType written = sema.factTypes().typeFromFact(declared); + Type aligned = written.isParameterized() ? sema.substitution().asSuperType(written, expected.erasure().fullyQualifiedName(), new HashSet<>()) : null; + if (aligned == null || !aligned.isParameterized() || aligned.typeArguments().size() != expected.args.size()) { + return; + } + for (int i = 0; i < expected.args.size(); i++) { + Type argument = aligned.typeArguments().get(i); + JType given = expected.args.get(i); + if (argument.isTypeVar() && variables.contains(argument.name()) && !given.isWildcard() && !given.isUnknown()) { + bound.putIfAbsent(argument.name(), given); + } + } + } + + /** + * Binds the type variables of {@code variables} that the declared type {@code declared} names to the types + * {@code actual} gives them at the same position. Open type variables and unbounded wildcards bind nothing. + */ + void bindFromType(JsonObject declared, Type actual, Set variables, Map bound) { + Type known = groundOf(actual); + if (known.isUnknown() || known.isNullType() || known.isTypeVar() || (actual != known && known.is("java.lang.Object"))) { + return; + } + String kind = text(declared, "kind"); + if ("typevar".equals(kind)) { + bindVariable(text(declared, "id"), known, variables, bound); + } else if (JSema.WILDCARD.equals(kind)) { + JsonObject limit = wildcardLimit(declared); + if (limit != null) { + bindFromType(limit, known, variables, bound); + } + } else if (JSema.ARRAY.equals(kind) && declared.get("elem") instanceof JsonObject element && known instanceof Type.ArrayType array) { + bindFromType(element, array.elementType(), variables, bound); + } else if (declared.get("args") instanceof JsonArray arguments && !arguments.isEmpty() && text(declared, "id") != null) { + bindArguments(text(declared, "id"), arguments, known, variables, bound); + } + } + + private static void bindVariable(@Nullable String id, Type known, Set variables, Map bound) { + if (variables.contains(id)) { + bound.putIfAbsent(id, known.isPrimitive() ? known.primitiveWrapperType() : known); + } + } + + private Type groundOf(Type actual) { + Type known = actual; + while (known instanceof JType wildcard && wildcard.isWildcard()) { + JType ground = wildcard.groundType(); + known = ground == wildcard.element && !ground.is("java.lang.Object") ? JType.capture(sema, ground) : ground; + } + return known; + } + + @Nullable + private static JsonObject wildcardLimit(JsonObject declared) { + if (declared.get("super") instanceof JsonObject lower) { + return lower; + } + return declared.get("extends") instanceof JsonObject upper ? upper : null; + } + + private void bindArguments(String id, JsonArray arguments, Type known, Set variables, Map bound) { + Type aligned = sema.substitution().asSuperType(known, erase(id), new HashSet<>()); + if (aligned == null || !aligned.isParameterized() || aligned.typeArguments().size() != arguments.size()) { + return; + } + for (int i = 0; i < arguments.size(); i++) { + if (arguments.get(i) instanceof JsonObject argument) { + bindFromType(argument, aligned.typeArguments().get(i), variables, bound); + } + } } } diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/ImportScopes.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/ImportScopes.java new file mode 100644 index 00000000000..a0a71b1b141 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/ImportScopes.java @@ -0,0 +1,110 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.ImportTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.Tree; + +/** Static checks behind the unused import warning: scopes, own package and the names a type is reachable by. */ +final class ImportScopes { + + private ImportScopes() { + } + + /** The package's own types are imported implicitly, so such an import is never counted as used. */ + static boolean isOwnPackage(ImportTree importTree, String name, String currentPackage) { + if (importTree.isStatic() || currentPackage.isEmpty()) { + return false; + } + String qualifier = name.endsWith(".*") ? name.substring(0, name.length() - 2) : name.substring(0, Math.max(0, name.lastIndexOf('.'))); + return qualifier.equals(currentPackage); + } + + /** + * A member of another type of the same file is in scope only through an import, one of an enclosing or inherited type is not. + * The annotations of a class are outside its scope, and a method looked up through an incomplete hierarchy may still come from an import. + */ + static boolean isInScope(Symbol symbol, IdentifierTree identifier) { + if (!(symbol.owner() instanceof Symbol.TypeSymbol owner) || owner.isUnknown()) { + return true; + } + boolean incompleteHierarchy = false; + boolean inScope = false; + Tree previous = identifier; + for (Tree tree = identifier.parent(); tree != null; previous = tree, tree = tree.parent()) { + if (tree instanceof org.sonar.plugins.java.api.tree.ClassTree declared) { + incompleteHierarchy |= declared.superClass() != null && declared.superClass().symbolType().isUnknown(); + Symbol.TypeSymbol enclosing = declared.symbol(); + if (!isOutsideBody(declared, previous) && (enclosing.equals(owner) || enclosing.type().isSubtypeOf(owner.type().erasure()))) { + inScope = true; + } + } + } + return inScope && !(symbol.isMethodSymbol() && incompleteHierarchy); + } + + /** The annotations, type parameters and supertypes of a class are not part of its body, where its members are in scope. */ + private static boolean isOutsideBody(org.sonar.plugins.java.api.tree.ClassTree declared, Tree child) { + return child == declared.modifiers() || child == declared.typeParameters() || child == declared.superClass() + || child == declared.superInterfaces(); + } + + static boolean denotesType(Symbol symbol, String name, IdentifierTree identifier) { + if (symbol.isTypeSymbol()) { + return dottedType(symbol).equals(name); + } + if (!(symbol.isMethodSymbol() && "".equals(symbol.name()))) { + return false; + } + if (symbol.owner() instanceof Symbol.TypeSymbol owner && dottedType(owner).equals(name)) { + return true; + } + Type written = identifier.symbolType(); + return written != null && !written.isUnknown() && written.erasure().fullyQualifiedName().replace('$', '.').equals(name); + } + + static boolean declaredIn(Symbol symbol, String qualifier, boolean isStatic) { + if (symbol.isUnknown()) { + return false; + } + if (isStatic && !symbol.isTypeSymbol()) { + return symbol.owner() instanceof Symbol.TypeSymbol owner && dottedType(owner).equals(qualifier); + } + Symbol type = !isStatic && "".equals(symbol.name()) ? symbol.owner() : symbol; + return type.isTypeSymbol() && !type.isUnknown() && directlyIn(dottedType(type), qualifier); + } + + /** An on-demand import brings the types declared directly in its package or type, not those of a subpackage. */ + private static boolean directlyIn(String type, String qualifier) { + return type.startsWith(qualifier + ".") && type.indexOf('.', qualifier.length() + 1) < 0; + } + + static String dottedType(Symbol symbol) { + return symbol.type().fullyQualifiedName().replace('$', '.'); + } + + static String dotted(Tree tree) { + if (tree instanceof MemberSelectExpressionTree select) { + return dotted(select.expression()) + "." + select.identifier().name(); + } + return ((IdentifierTree) tree).name(); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/Inference.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/Inference.java index 62713dd17a4..411e5872a44 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/Inference.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/Inference.java @@ -16,80 +16,408 @@ */ package org.sonar.java.semsitter; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; import javax.annotation.Nullable; import org.sonar.plugins.java.api.semantic.Type; -/** Return and thrown types of invocations and diamonds, as declared until inference from arguments and targets lands. */ -class Inference { +import static org.sonar.java.semsitter.SemaFacts.strings; +import static org.sonar.java.semsitter.SemaFacts.text; + +/** Return and thrown types of invocations and diamonds, inferred from the arguments and the target type. */ +final class Inference { + + private static final String TYPE_VARS = "typeVars"; + + private final JSema sema; + + Inference(JSema sema) { + this.sema = sema; + } /** - * The type an invocation of {@code method} evaluates to: its declared return type. - * @param receiver type of the receiver, used once inference lands - * @param arguments types of the arguments, used once inference lands + * The type an invocation of {@code method} evaluates to. A self-typed method returns the receiver, or a + * capture of it when the receiver leaves its own type argument as a wildcard. */ Type invocationReturn(JMethodSymbol method, @Nullable Type receiver, List arguments) { + if (receiver != null && receiver.isArray() && "clone".equals(method.name())) { + return receiver; + } + Type result = invocationReturnType(method, receiver, arguments); + return withEnclosingArguments(method, receiver, result); + } + + /** The inner class a member of a parameterized class returns keeps the arguments of its enclosing class; a static member type has none. */ + private Type withEnclosingArguments(JMethodSymbol method, @Nullable Type receiver, Type result) { + if (receiver == null || method.isStatic() || !(result instanceof JType inner) || !inner.isClass() || inner.isParameterized() || method.owner().type() == null) { + return result; + } + String ownerFqn = method.owner().type().erasure().fullyQualifiedName(); + if ((!inner.fullyQualifiedName().startsWith(ownerFqn + "$") && !inner.fullyQualifiedName().startsWith(ownerFqn + ".")) + || inner.symbol().isStatic() || inner.symbol().isInterface() || inner.symbol().isEnum()) { + return result; + } + Type declaring = sema.substitution().asSuperType(receiver, ownerFqn, new HashSet<>()); + return declaring instanceof JType enclosing && enclosing.isParameterized() ? inner.withOuter(enclosing) : result; + } + + private Type invocationReturnType(JMethodSymbol method, @Nullable Type receiver, List arguments) { + Type fromReceiver = receiverReturn(method, receiver, arguments); + return fromReceiver != null ? fromReceiver : declaredReturnType(method, receiver, arguments); + } + + @Nullable + private Type receiverReturn(JMethodSymbol method, @Nullable Type receiver, List arguments) { + if (method.returnsSelf() && receiver instanceof JType returned && returned.isCapture()) { + return returned; + } + if (receiver instanceof JType captured && captured.isCapture() && captured.element.isClass() && !method.isStatic()) { + // a member of a capture is a member of its bound + return invocationReturnType(method, captured.element, arguments); + } + Type argument = returnedTypeArgument(method, receiver); + if (argument != null) { + if (method.returnsSelf() && argument instanceof JType captured && captured.isCapture() && receiver instanceof JType self && self.isClass()) { + return JType.capture(sema, self); + } + if (!argument.isTypeVar()) { + return argument; + } + } + if (method.returnsSelf() && receiver instanceof JType returned && returned.isClass()) { + boolean wildcard = returned.typeArguments().stream().anyMatch(typeArgument -> typeArgument instanceof JType type && type.isCapture()); + return wildcard ? JType.capture(sema, returned) : returned; + } + return null; + } + + @Nullable + private Type returnedTypeArgument(JMethodSymbol method, @Nullable Type receiver) { + Integer index = method.returnTypeParameter(); + Type declaring = index == null || receiver == null ? null : sema.substitution().declaringType(method, receiver); + return declaring != null && declaring.isParameterized() && declaring.typeArguments().size() > index ? declaring.typeArguments().get(index) : null; + } + + private Type declaredReturnType(JMethodSymbol method, @Nullable Type receiver, List arguments) { + JsonObject declaredReturn = sema.substitution().declaredReturn(method); + if (declaredReturn != null) { + Type substituted = substitutedReturn(method, receiver, arguments, declaredReturn); + Type known = substituted != null ? substituted : libraryReturn(method, declaredReturn); + if (known != null) { + return known; + } + } Type declared = method.returnType().type(); + if ((declared == null || declared.isUnknown()) && declaredReturn != null) { + // the declaration comes later in the file than this call + JType plain = sema.factTypes().typeFromFact(declaredReturn, Map.of(), true); + if (!plain.isUnknown() && !mentionsMethodTypeVariable(method, plain)) { + return plain; + } + } return declared == null ? Type.UNKNOWN : declared; } - /** The erased return type of a call on a raw receiver, or null when it does not apply. */ + /** The method's own type variables shadow the class ones of the same name, even when the call leaves them unbound. */ + private Map invocationSubstitution(JMethodSymbol method, Map classSubstitution, List arguments) { + Map substitution = new HashMap<>(classSubstitution); + JsonObject member = classSubstitution.isEmpty() ? null : sema.substitution().lookupGenericMember(method); + if (member != null) { + strings(member, TYPE_VARS).forEach(substitution::remove); + } + substitution.putAll(methodSubstitution(method, arguments)); + return substitution; + } + + @Nullable + private Type substitutedReturn(JMethodSymbol method, @Nullable Type receiver, List arguments, JsonObject declaredReturn) { + Map classSubstitution = receiver == null ? Map.of() : sema.substitution().classSubstitution(method, receiver); + Map substitution = invocationSubstitution(method, classSubstitution, arguments); + if (substitution.isEmpty() && !method.isStatic()) { + return null; + } + JType substituted = sema.factTypes().typeFromFact(declaredReturn, substitution, true); + boolean leaks = classSubstitution.isEmpty() ? Substitution.mentionsTypeVariable(substituted) : mentionsMethodTypeVariable(method, substituted); + return substituted.isUnknown() || leaks ? null : substituted; + } + + /** A library method with no type variables in play still returns the type arguments its signature spells out. */ + @Nullable + private JType libraryReturn(JMethodSymbol method, JsonObject declaredReturn) { + if (method.isStatic() || method.declaration() != null) { + return null; + } + JType plain = sema.factTypes().typeFromFact(declaredReturn, Map.of(), true); + boolean spelledOut = !plain.isUnknown() && plain.isParameterized() && !Substitution.mentionsTypeVariable(plain); + return spelledOut && plain.args.stream().noneMatch(JType::isCapture) ? plain : null; + } + + /** The erased return type of an instance method of a generic class called on a raw receiver, or null when it does not apply. */ @Nullable Type rawReturn(JMethodSymbol method) { - return null; + JsonObject declaredReturn = sema.substitution().declaredReturn(method); + if (declaredReturn == null || method.isStatic() || !hasClassTypeVariables(method)) { + return null; + } + JType plain = sema.factTypes().typeFromFact(declaredReturn, Map.of(), true); + if (plain.isTypeVar() && !method.returnType().type().isUnknown()) { + // the descriptor erases a type variable to its bound + return method.returnType().type(); + } + return plain.isUnknown() ? null : plain.erasure(); + } + + private boolean hasClassTypeVariables(JMethodSymbol method) { + JsonObject info = sema.typeInfos.get(sema.sourceName(method.owner().type().erasure().fullyQualifiedName())); + return info != null && !strings(info, TYPE_VARS).isEmpty(); } - /** The thrown types of a call inferred from its arguments, or null when the erased thrown types stand. */ + /** + * The thrown types of a call when the method throws a type variable, taken from the arguments the variable is + * inferred from, or null when the erased thrown types stand. + */ @Nullable List invocationThrown(JMethodSymbol method, @Nullable Type receiver, List arguments) { - return null; + JsonObject member = method.isUnknown() ? null : sema.substitution().lookupGenericMember(method); + if (member == null || !(member.get("throwsTypes") instanceof JsonArray facts) || facts.isEmpty()) { + return null; + } + Map substitution = invocationSubstitution(method, receiver == null ? Map.of() : sema.substitution().classSubstitution(method, receiver), arguments); + List erased = method.thrownTypes(); + List result = new ArrayList<>(); + boolean changed = false; + for (int i = 0; i < facts.size(); i++) { + JsonObject fact = facts.get(i) instanceof JsonObject object ? object : null; + Type inferred = inferredThrown(fact, substitution); + if (inferred == null) { + result.add(i < erased.size() ? erased.get(i) : declaredThrown(fact)); + } else { + result.add(inferred); + changed = true; + } + } + return changed ? result : null; } - /** The type {@code method} returns when its target fixes its type variables, or null when they stay open. */ + @Nullable + private Type inferredThrown(@Nullable JsonObject fact, Map substitution) { + if (fact == null || !isTypeVariable(fact)) { + return null; + } + Type inferred = sema.factTypes().typeFromFact(fact, substitution, true); + return inferred.isUnknown() || Substitution.mentionsTypeVariable(inferred) ? null : inferred; + } + + private Type declaredThrown(@Nullable JsonObject fact) { + return fact == null || isTypeVariable(fact) ? Type.UNKNOWN : sema.factTypes().typeFromFact(fact, Map.of(), true); + } + + private static boolean isTypeVariable(JsonObject fact) { + return "typevar".equals(text(fact, "kind")); + } + + /** Maps the type variables of {@code method} itself to the arguments they are inferred from. */ + private Map methodSubstitution(JMethodSymbol method, List arguments) { + JsonObject member = arguments.isEmpty() && sema.explicitTypeArguments.isEmpty() ? null : sema.substitution().lookupGenericMember(method); + if (member == null || !(member.get(TYPE_VARS) instanceof JsonArray names)) { + return Map.of(); + } + List variables = sema.substitution().parameterVariables(method); + Map substitution = new HashMap<>(); + for (int i = 0; i < names.size(); i++) { + Type inferred = sema.substitution().methodArgument(variables, "m" + i, arguments); + if (inferred != null && !inferred.isUnknown()) { + substitution.put(names.get(i).getAsString(), inferred); + } + } + Set own = new HashSet<>(); + names.forEach(name -> own.add(name.getAsString())); + List declared = sema.substitution().declaredParameters(method); + for (int i = 0; i < declared.size() && i < arguments.size(); i++) { + sema.functionalInference().bindFromType(declared.get(i), arguments.get(i), own, substitution); + } + return substitution; + } + + /** + * 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. + */ @Nullable Type targetedReturn(JMethodSymbol method, Type target) { - return null; + 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; + } + Set own = new HashSet<>(); + names.forEach(name -> own.add(name.getAsString())); + Map bound = new HashMap<>(); + sema.functionalInference().bindReturnToTarget(declared, target, own, bound); + if (bound.isEmpty()) { + return null; + } + JType result = sema.factTypes().typeFromFact(declared, bound); + return result.isUnknown() || Substitution.mentionsTypeVariable(result) ? null : result; } - /** The result of a call retargeted to a supertype of its element, or null when the result stands. */ + /** + * The result of a call that returns a bare method type variable, such as {@code Stream.collect(collector)}, when + * the type it is passed as takes a supertype of the element where the result carries it: a collector factory leaves + * its element free, so {@code Collection} fixes the result of a stream of {@code String} to + * {@code List}. Null when the result stands. + */ @Nullable Type retargetedElement(JMethodSymbol method, Type receiver, Type returned, Type target) { + JsonObject declared = sema.substitution().declaredReturn(method); + JsonObject member = method.isUnknown() ? null : sema.substitution().lookupGenericMember(method); + if (declared == null || member == null || !"typevar".equals(text(declared, "kind")) + || !(receiver instanceof JType owner) || owner.args.isEmpty() + || !(returned instanceof JType result) || !result.isParameterized() || !(target instanceof JType wantedType) || !wantedType.isParameterized()) { + return null; + } + JType element = owner.args.get(0); + if (element.isWildcard() || element.isUnknown() || element.isParameterized() || !element.isClass()) { + return null; + } + int open = onlyPosition(result.args, element); + Type aligned = open < 0 ? null : sema.substitution().asSuperType(result, wantedType.erasure().fullyQualifiedName(), new HashSet<>()); + if (aligned == null || !aligned.isParameterized() || aligned.typeArguments().size() != wantedType.args.size()) { + return null; + } + for (int k = 0; k < wantedType.args.size(); k++) { + JType wanted = wantedType.args.get(k); + if (aligned.typeArguments().get(k).fullyQualifiedName().equals(element.fullyQualifiedName()) + && !wanted.isWildcard() && !wanted.isUnknown() && !wanted.isParameterized() && wanted.isClass() + && !wanted.fullyQualifiedName().equals(element.fullyQualifiedName()) && element.isSubtypeOf(wanted)) { + List arguments = new ArrayList<>(result.args); + arguments.set(open, wanted); + return JType.named(sema, result.erasure().fullyQualifiedName(), arguments); + } + } return null; } + /** The single position of {@code element} among {@code arguments}, or -1 when it appears there zero or several times. */ + private static int onlyPosition(List arguments, JType element) { + int position = -1; + for (int i = 0; i < arguments.size(); i++) { + if (arguments.get(i).fullyQualifiedName().equals(element.fullyQualifiedName())) { + if (position >= 0) { + return -1; + } + position = i; + } + } + return position; + } + + private boolean mentionsMethodTypeVariable(JMethodSymbol method, Type type) { + JsonObject member = sema.substitution().lookupGenericMember(method); + if (member == null || !(member.get(TYPE_VARS) instanceof JsonArray names) || names.isEmpty()) { + return false; + } + Set own = new HashSet<>(); + names.forEach(name -> own.add(name.getAsString())); + return Substitution.mentionsTypeVariable(type, own::contains); + } + /** - * The parameterization of {@code created} a diamond infers from {@code target}. - * @param target type the diamond is assigned to, used once inference lands + * The parameterization of {@code created} a diamond infers from {@code target}: each type parameter of the created + * class takes the target argument it is passed to through the supertype matching the target. */ Type inferDiamond(Type created, Type target) { - return created; + if (!(created.erasure() instanceof JType raw) || raw.isUnknown() || !(target instanceof JType expected) || !expected.isParameterized()) { + return created; + } + String targetFqn = expected.erasure().fullyQualifiedName(); + if (raw.fullyQualifiedName().equals(targetFqn)) { + return JType.named(sema, raw.fullyQualifiedName(), expected.args); + } + Type generic = raw.declaringType(); + Type declared = generic.isParameterized() ? sema.substitution().asSuperType(generic, targetFqn, new HashSet<>()) : null; + if (declared == null || declared.typeArguments().size() != expected.args.size()) { + return created; + } + Map inferred = new HashMap<>(); + for (int i = 0; i < expected.args.size(); i++) { + if (declared.typeArguments().get(i).isTypeVar()) { + inferred.put(declared.typeArguments().get(i).fullyQualifiedName(), expected.args.get(i)); + } + } + List arguments = new ArrayList<>(); + for (Type variable : generic.typeArguments()) { + JType argument = inferred.get(variable.fullyQualifiedName()); + if (argument == null) { + return created; + } + arguments.add(argument); + } + return JType.named(sema, raw.fullyQualifiedName(), arguments); } /** - * The parameterization of {@code created} a diamond infers from the arguments of its constructor. - * @param constructor constructor the diamond calls, used once inference lands - * @param arguments types of the arguments, used once inference lands + * The parameterization of {@code created} a diamond infers from the arguments of its constructor: each type + * parameter of the class takes the argument type it is passed as, or {@code created} when one stays open. */ Type inferDiamondFromArguments(JMethodSymbol constructor, Type created, List arguments) { - return created; + if (!(created.erasure() instanceof JType raw) || raw.isUnknown() || created.isParameterized()) { + return created; + } + JsonObject info = sema.typeInfos.get(sema.sourceName(raw.fullyQualifiedName())); + List names = info == null ? List.of() : strings(info, TYPE_VARS); + List declared = names.isEmpty() ? List.of() : sema.substitution().declaredParameters(constructor); + if (declared.isEmpty() || declared.size() != arguments.size()) { + return created; + } + Set own = new HashSet<>(names); + Map bound = new HashMap<>(); + for (int i = 0; i < declared.size(); i++) { + sema.functionalInference().bindFromType(declared.get(i), arguments.get(i), own, bound); + } + List inferred = new ArrayList<>(); + for (String name : names) { + Type argument = bound.get(name); + if (argument == null || argument.isUnknown()) { + return created; + } + inferred.add(sema.asJType(argument)); + } + return JType.named(sema, raw.fullyQualifiedName(), inferred); } - /** The type a lambda or method reference implements for a wildcard-parameterized target. */ + /** The type a lambda or method reference implements for a wildcard-parameterized target (JLS 9.9). */ Type groundType(Type target) { - return target; + if (!(target instanceof JType type) || !type.isParameterized() || type.args.stream().noneMatch(JType::isWildcard)) { + return target; + } + return JType.named(sema, type.fullyQualifiedName(), type.args.stream().map(JType::groundType).toList()); } - /** Capture conversion of the receiver's wildcard arguments. */ + /** Capture conversion: a member is accessed through captures of the receiver's wildcard arguments. */ Type captureWildcards(Type receiver) { - return receiver; + if (!(receiver instanceof JType type) || !type.isParameterized() || type.args.stream().noneMatch(JType::isWildcard)) { + return receiver; + } + List captured = type.args.stream().map(argument -> argument.isWildcard() ? JType.capture(sema, argument.element) : argument).toList(); + return JType.named(sema, type.fullyQualifiedName(), captured); } /** - * Whether {@code method} declares type variables of its own. - * @param method method to inspect, used once inference lands - * @param substituted whether its signature is already substituted, used once inference lands + * Whether {@code method} declares type variables of its own. A constructor, whose diamond infers them, and a + * method whose declaration is unknown count when their types are substituted. */ boolean declaresTypeVariables(JMethodSymbol method, boolean substituted) { - return false; + JsonObject member = "".equals(method.name()) ? null : sema.substitution().lookupGenericMember(method); + if (member == null) { + return substituted; + } + return member.get(TYPE_VARS) instanceof JsonArray names && !names.isEmpty(); } } diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/InvocationTranslator.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/InvocationTranslator.java new file mode 100644 index 00000000000..3ba5ca26b1b --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/InvocationTranslator.java @@ -0,0 +1,397 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.regex.Pattern; +import javax.annotation.Nullable; +import org.sonar.java.ast.parser.ArgumentListTreeImpl; +import org.sonar.java.ast.parser.InitializerListTreeImpl; +import org.sonar.java.model.ArrayDimensionTreeImpl; +import org.sonar.java.model.JavaTree; +import org.sonar.java.model.declaration.ClassTreeImpl; +import org.sonar.java.model.expression.ArrayAccessExpressionTreeImpl; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.java.model.expression.LambdaExpressionTreeImpl; +import org.sonar.java.model.expression.MemberSelectExpressionTreeImpl; +import org.sonar.java.model.expression.MethodInvocationTreeImpl; +import org.sonar.java.model.expression.MethodReferenceTreeImpl; +import org.sonar.java.model.expression.NewArrayTreeImpl; +import org.sonar.java.model.expression.NewClassTreeImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.ArrayDimensionTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.ParameterizedTypeTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeTree; +import org.sonar.plugins.java.api.tree.VariableTree; + +import static org.sonar.java.semsitter.Bindings.argumentTypes; +import static org.sonar.java.semsitter.Bindings.ascribe; +import static org.sonar.java.semsitter.Bindings.bind; +import static org.sonar.java.semsitter.Bindings.bindMethod; +import static org.sonar.java.semsitter.Bindings.functionArguments; +import static org.sonar.java.semsitter.CstNodes.childKind; +import static org.sonar.java.semsitter.CstNodes.field; +import static org.sonar.java.semsitter.CstNodes.firstNamed; +import static org.sonar.java.semsitter.CstNodes.firstType; +import static org.sonar.java.semsitter.CstNodes.lastKeyword; +import static org.sonar.java.semsitter.CstNodes.lastNamed; +import static org.sonar.java.semsitter.CstNodes.required; +import static org.sonar.java.semsitter.CstNodes.requiredField; + +/** Translates method invocations, instance and array creations, and array accesses. */ +final class InvocationTranslator extends TranslatorPart { + + private static final String JAVA_LANG_OBJECT = "java.lang.Object"; + private static final Pattern ARITY_ONLY = Pattern.compile("[^#]+#[^#(]+\\(\\d+\\)"); + + InvocationTranslator(TranslationState state) { + super(state); + } + + MethodInvocationTreeImpl invocation(CstNode node) { + CstNode name = requiredField(node, "name", null); + CstNode object = field(node, "object"); + IdentifierTreeImpl identifier = names().identifier(name); + bindUse(identifier, name, object != null); + ExpressionTree select; + ExpressionTree qualifier = null; + if (object == null) { + select = identifier; + } else { + qualifier = names().superQualifier(node, object); + select = new MemberSelectExpressionTreeImpl(qualifier, token(lastKeyword(node, ".")), identifier); + } + CstNode typeArguments = field(node, "type_arguments"); + MethodInvocationTreeImpl tree = new MethodInvocationTreeImpl( + select, + typeArguments == null ? null : typeTrees().typeArguments(typeArguments), + expressions().arguments(requiredField(node, "arguments", childKind(node, "argument_list")))); + Type receiver = qualifier == null ? typeTrees().currentType() : qualifier.symbolType(); + String target = name.valueTarget(); + boolean arityOnly = target != null && ARITY_ONLY.matcher(target).matches(); + List arguments = argumentTypes(tree.arguments()); + bindStaticImport(identifier, qualifier, arguments); + bindLibraryOrOverload(tree, identifier, qualifier, arityOnly ? target : null, arguments); + refineMethodBinding(identifier, qualifier, receiver, arguments); + if (identifier.symbol() instanceof JMethodSymbol method) { + bindResolvedInvocation(tree, identifier, method, qualifier, receiver, arguments); + } else if (tree.methodSymbol().isUnknown()) { + // An unresolved call keeps its written name, as a recovered binding does. + JMethodSymbol unresolved = new JMethodSymbol(sema, null, identifier.name()); + unresolved.unknown(true); + bindMethod(tree, unresolved); + } + return tree; + } + + /** An unqualified call to a statically imported name binds the imported method unless an enclosing type declares it. */ + private void bindStaticImport(IdentifierTreeImpl identifier, @Nullable ExpressionTree qualifier, List arguments) { + if (qualifier == null && state.imports.staticImports.containsKey(identifier.name())) { + 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); + if (imported != null) { + bind(identifier, imported); + } + } + } + } + + /** An unresolved or arity-only call is looked up, a bound one prefers its best overload. */ + private void bindLibraryOrOverload(MethodInvocationTreeImpl tree, IdentifierTreeImpl identifier, @Nullable ExpressionTree qualifier, + @Nullable String arityTarget, List arguments) { + if (identifier.symbol().isUnknown() || arityTarget != null) { + Symbol.MethodSymbol method = arityTarget != null + ? sema.lookup().declaredMethod(SemaFacts.erase(arityTarget.substring(0, arityTarget.indexOf('#'))), identifier.name(), arguments) + : names().libraryMethod(qualifier, identifier.name(), arguments, functionArguments(tree.arguments())); + if (method != null) { + bind(identifier, method); + } + } else if (identifier.symbol() instanceof Symbol.MethodSymbol bound) { + Set functions = functionArguments(tree.arguments()); + Symbol.MethodSymbol preferred = sema.overloads().preferOverload(bound, names().libraryMethod(qualifier, identifier.name(), arguments, functions), arguments, functions); + if (preferred != bound && bound instanceof JSymbol from && preferred instanceof JSymbol to) { + sema.moveUse(from.id, to.id, identifier); + } + bind(identifier, preferred); + } + } + + /** A method whose arity does not fit is dropped, a varargs one becomes its most specific form. */ + private void refineMethodBinding(IdentifierTreeImpl identifier, @Nullable ExpressionTree qualifier, Type receiver, List arguments) { + if (identifier.symbol() instanceof JMethodSymbol method && !method.isUnknown() && !MemberLookup.arityMatches(method, arguments.size())) { + bind(identifier, Symbol.MethodSymbol.UNKNOWN_METHOD); + } + if (identifier.symbol() instanceof JMethodSymbol chosen) { + JMethodSymbol specific = OverloadRanking.mostSpecificVarArgs(chosen, arguments); + if (specific != chosen) { + sema.moveUse(chosen.id, specific.id, identifier); + bind(identifier, specific); + } + } + if (qualifier != null && receiver.isUnknown() && !receiver.symbol().isUnknown()) { + // a member of a parameterization with an undeclared argument is not bound + bind(identifier, Symbol.MethodSymbol.UNKNOWN_METHOD); + } + } + + /** Binds and types an invocation whose method is resolved. */ + private void bindResolvedInvocation(MethodInvocationTreeImpl tree, IdentifierTreeImpl identifier, JMethodSymbol method, @Nullable ExpressionTree qualifier, + Type receiver, List arguments) { + List explicit = tree.typeArguments() == null ? List.of() : tree.typeArguments().stream().map(TypeTree::symbolType).toList(); + List parameters = sema.substitution().withExplicitTypeArguments(explicit, () -> sema.substitution().invocationParameters(method, receiver, arguments)); + expressions().ascribeArguments(method, parameters, tree.arguments()); + List typed = typedArguments(tree, arguments, parameters); + Type returned = sema.substitution().withExplicitTypeArguments(explicit, () -> sema.inference().invocationReturn(method, receiver, typed)); + Type erased = qualifier != null && receiver.isRawType() && isWrittenRaw(qualifier) ? sema.inference().rawReturn(method) : null; + if (erased != null) { + // a member of a raw type has the erasure of its declared type + returned = erased; + state.rawResults.add(tree); + } + if ("getClass".equals(method.name()) && arguments.isEmpty() && method.owner().type().is(JAVA_LANG_OBJECT) + && !receiver.isUnknown() && receiver.erasure() instanceof JType erasedReceiver) { + // the static type of the call is Class where T is the static type of the receiver + returned = JType.named(sema, "java.lang.Class", List.of(JType.wildcard(sema, erasedReceiver))); + } + List thrownArguments = withCreatedTypes(tree.arguments(), typed); + List thrown = sema.substitution().withExplicitTypeArguments(explicit, () -> sema.inference().invocationThrown(method, receiver, thrownArguments)); + JMethodSymbol view = sema.substitution().invocationView(method, receiver, parameters, returned, thrown); + bindMethod(tree, view); + bind(identifier, view); + ascribe(identifier, returned); + ascribe(tree, returned); + } + + /** The argument types, with nested calls, method references and expression lambdas typed by their result. */ + private List typedArguments(MethodInvocationTreeImpl tree, List arguments, List parameters) { + List typed = new ArrayList<>(arguments); + for (int i = 0; i < typed.size(); i++) { + if (tree.arguments().get(i).is(Tree.Kind.METHOD_INVOCATION)) { + typed.set(i, tree.arguments().get(i).symbolType()); + } else if (tree.arguments().get(i) instanceof MethodReferenceTreeImpl reference && i < parameters.size() + && lambdas().referenceResult(reference, parameters.get(i)) instanceof Type produced) { + Type function = sema.functionalInference().functionProducing(parameters.get(i), produced); + if (function != null) { + typed.set(i, function); + } + } else if (tree.arguments().get(i) instanceof LambdaExpressionTreeImpl lambda && lambda.body() instanceof ExpressionTree value && i < parameters.size()) { + Type function = sema.functionalInference().functionProducing(parameters.get(i), value.symbolType()); + if (function != null) { + typed.set(i, function); + } + } + } + return typed; + } + + /** + * The argument types with each supplier of a created object, {@code Type::new} or {@code () -> new Type(..)}, + * typed as {@code Supplier}: the type a generic throws clause is inferred from. + */ + private List withCreatedTypes(List expressions, List types) { + List result = new ArrayList<>(types); + for (int i = 0; i < result.size(); i++) { + Type created = null; + ExpressionTree argument = expressions.get(i); + if (argument instanceof MethodReferenceTreeImpl reference && "new".equals(reference.method().name()) && reference.expression() instanceof TypeTree qualifier) { + created = qualifier.symbolType(); + } else if (argument instanceof LambdaExpressionTreeImpl lambda && lambda.parameters().isEmpty() && lambda.body() instanceof NewClassTreeImpl creation) { + created = creation.symbolType(); + } + if (created != null && !created.isUnknown() && created.isClass()) { + result.set(i, JType.named(sema, "java.util.function.Supplier", List.of(sema.asJType(created)))); + } + } + return result; + } + + ExpressionTree typeExpression(CstNode node) { + return (ExpressionTree) typeTrees().type(node); + } + + NewClassTreeImpl creation(CstNode node) { + CstNode typeNode = requiredField(node, "type", null); + TypeTree type = typeTrees().annotate(names().recoverQualifiedType(typeTrees().type(typeNode)), node); + ArgumentListTreeImpl args = expressions().arguments(requiredField(node, "arguments", null)); + CstNode body = childKind(node, "class_body"); + ClassTreeImpl classBody = null; + if (body != null) { + classBody = new ClassTreeImpl(Tree.Kind.CLASS, token(required(body, "{")), declarations().membersOf(body), token(required(body, "}"))); + // An anonymous class is declared at its creation expression, whatever its members. + bindType(classBody, node); + } + NewClassTreeImpl tree = new NewClassTreeImpl(type, args, classBody).completeWithNewKeyword(token(required(node, "new"))); + CstNode enclosing = node.children().get(0); + if (!"new".equals(enclosing.text())) { + tree.completeWithEnclosingExpression(expressions().expression(enclosing)); + tree.completeWithDotToken(token(required(node, "."))); + } + CstNode typeArguments = field(node, "type_arguments"); + if (typeArguments != null) { + tree.completeWithTypeArguments(typeTrees().typeArguments(typeArguments)); + } + bindConstructor(tree, typeNode); + ascribe(tree, classBody != null && !classBody.symbol().isUnknown() ? classBody.symbol().type() : type.symbolType()); + return tree; + } + + private void bindConstructor(NewClassTreeImpl tree, CstNode typeNode) { + IdentifierTreeImpl identifier = (IdentifierTreeImpl) tree.getConstructorIdentifier(); + TypeTree written = tree.identifier() instanceof ParameterizedTypeTree parameterized ? parameterized.type() : tree.identifier(); + String imported = written instanceof MemberSelectExpressionTree ? null : state.imports.singleImports.get(identifier.name()); + String constructor = typeNode.valueTarget(); + if (constructor != null && bindResolvedConstructor(tree, identifier, imported, constructor)) { + return; + } + Type type = tree.identifier().symbolType().erasure(); + if (imported != null && sema.declaresType(imported) && !imported.equals(type.fullyQualifiedName())) { + type = sema.getClassType(imported); + bindType(identifier, imported); + } + String owner = tree.classBody() != null && type.symbol().isInterface() ? JAVA_LANG_OBJECT : type.fullyQualifiedName(); + Symbol.MethodSymbol declared = type.isClass() ? sema.lookup().declaredMethod(owner, "", argumentTypes(tree.arguments()), functionArguments(tree.arguments())) : null; + if (declared != null && MemberLookup.arityMatches(declared, tree.arguments().size())) { + bind(identifier, declared); + recordUse(declared, identifier); + expressions().ascribeArguments(declared, tree.arguments()); + viewWithInferredParameters(tree, identifier); + } else if (!(identifier.symbol() instanceof Symbol.MethodSymbol)) { + bind(identifier, Symbol.MethodSymbol.UNKNOWN_METHOD); + } + } + + /** Binds the constructor SemSitter resolved unless another import declares the type; whether it did. */ + private boolean bindResolvedConstructor(NewClassTreeImpl tree, IdentifierTreeImpl identifier, @Nullable String imported, String constructor) { + Symbol resolved = sema.resolve(constructor); + String owner = resolved.owner() == null || resolved.owner().type() == null ? "" : resolved.owner().type().erasure().fullyQualifiedName(); + boolean importedElsewhere = imported != null && sema.declaresType(imported) && !imported.equals(owner); + if (resolved instanceof Symbol.MethodSymbol method && !importedElsewhere && MemberLookup.arityMatches(method, tree.arguments().size())) { + bind(identifier, resolved); + recordUse(resolved, identifier); + expressions().ascribeArguments(method, tree.arguments()); + viewWithInferredParameters(tree, identifier); + return true; + } + return false; + } + + /** A diamond without a target takes the class arguments its constructor arguments fix. */ + private void inferDiamondFromArguments(NewClassTreeImpl tree, JMethodSymbol constructor) { + if (!(tree.identifier() instanceof JavaTree.ParameterizedTypeTreeImpl generic) || !generic.typeArguments().isEmpty()) { + return; + } + Type inferred = sema.inference().inferDiamondFromArguments(constructor, generic.symbolType(), argumentTypes(tree.arguments())); + if (inferred.isParameterized()) { + ascribe(generic, inferred); + } + } + + /** A generic constructor is seen with the type arguments its call infers for the parameters. */ + private void viewWithInferredParameters(NewClassTreeImpl tree, IdentifierTreeImpl identifier) { + if (!(identifier.symbol() instanceof JMethodSymbol constructor) || constructor.isUnknown()) { + return; + } + inferDiamondFromArguments(tree, constructor); + List parameters = sema.substitution().invocationParameters(constructor, tree.identifier().symbolType(), argumentTypes(tree.arguments())); + if (!parameters.equals(constructor.parameterTypes())) { + JMethodSymbol view = sema.substitution().invocationView(constructor, tree.identifier().symbolType(), parameters, constructor.returnType().type()); + if (view != constructor && !constructor.isParametrizedMethod()) { + // the class arguments written at the call do not make the constructor generic + view.parametrized(false); + } + bind(identifier, view); + } + } + + /** Whether a receiver is raw because of what is written: a variable declared with a raw type, or the erased result of such a call. */ + private boolean isWrittenRaw(ExpressionTree qualifier) { + if (state.rawResults.contains(qualifier)) { + return true; + } + Symbol symbol = qualifier instanceof IdentifierTree identifier ? identifier.symbol() : Symbol.UNKNOWN_SYMBOL; + return symbol.isVariableSymbol() && symbol.declaration() instanceof VariableTree variable + && variable.type() instanceof IdentifierTree variableType && !"var".equals(variableType.name()); + } + + NewArrayTreeImpl arrayCreation(CstNode node) { + CstNode initializer = field(node, "value"); + List dims = new ArrayList<>(); + for (CstNode child : node.children()) { + // sized dimensions, then unsized ones: new byte[n][] + if ("dimensions_expr".equals(child.k()) || "dimensions".equals(child.k())) { + dims.addAll(typeTrees().dimensions(child)); + } + } + InitializerListTreeImpl initializers = initializer == null ? InitializerListTreeImpl.emptyList() : initializers(initializer); + NewArrayTreeImpl tree = new NewArrayTreeImpl(dims, initializers) + .complete(typeTrees().annotate(typeTrees().type(requiredField(node, "type", firstType(node))), node)) + .completeWithNewKeyword(token(required(node, "new"))); + if (initializer != null) { + tree.completeWithCurlyBraces(token(required(initializer, "{")), token(required(initializer, "}"))); + } + ascribe(tree, typeTrees().arrayTypeOf(tree.type(), dims.size())); + return tree; + } + + NewArrayTreeImpl arrayInitializer(CstNode node) { + return new NewArrayTreeImpl(List.of(), initializers(node)).completeWithCurlyBraces(token(required(node, "{")), token(required(node, "}"))); + } + + MemberSelectExpressionTreeImpl classLiteral(CstNode node) { + ExpressionTree type = (ExpressionTree) names().recoverQualifiedType(typeTrees().type(firstNamed(node))); + IdentifierTreeImpl className = new IdentifierTreeImpl(token(required(node, "class"))); + MemberSelectExpressionTreeImpl tree = new MemberSelectExpressionTreeImpl(type, token(required(node, ".")), className); + Type literal = type.symbolType().isPrimitive() ? type.symbolType().primitiveWrapperType() : type.symbolType(); + JType argument = literal instanceof JType jType ? jType : JType.unknown(sema); + ascribe(tree, JType.inferred(sema, "java.lang.Class", List.of(argument))); + return tree; + } + + private InitializerListTreeImpl initializers(CstNode node) { + InitializerListTreeImpl list = InitializerListTreeImpl.emptyList(); + for (CstNode child : node.children()) { + if ("{".equals(child.text()) || "}".equals(child.text())) { + continue; + } + if (",".equals(child.text())) { + list.separators().add(token(child)); + } else { + list.add(expressions().expression(child)); + } + } + return list; + } + + ArrayAccessExpressionTreeImpl arrayAccess(CstNode node) { + ExpressionTree array = expressions().expression(requiredField(node, "array", firstNamed(node))); + ExpressionTree index = expressions().expression(requiredField(node, "index", lastNamed(node))); + ArrayDimensionTreeImpl dimension = new ArrayDimensionTreeImpl(token(required(node, "[")), index, token(required(node, "]"))); + ArrayAccessExpressionTreeImpl tree = new ArrayAccessExpressionTreeImpl(array, dimension); + Type arrayType = array.symbolType(); + ascribe(tree, arrayType.isArray() ? ((Type.ArrayType) arrayType).elementType() : Type.UNKNOWN); + return tree; + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JInitializerBlockSymbol.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JInitializerBlockSymbol.java new file mode 100644 index 00000000000..1575d6452eb --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JInitializerBlockSymbol.java @@ -0,0 +1,216 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.Collections; +import java.util.List; +import org.sonar.java.model.Symbols; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.SymbolMetadata; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.MethodTree; + +/** + * Symbol type to represent initializer blocks. It's a type of method symbol and was introduced, so that variables + * defined inside an initializer block can have an owner other than the containing class. This is necessary to properly + * detect them as local variables. + */ +final class JInitializerBlockSymbol implements Symbol.MethodSymbol { + private final TypeSymbol owner; + private final boolean isStatic; + + public JInitializerBlockSymbol(TypeSymbol owner, boolean isStatic) { + this.owner = owner; + this.isStatic = isStatic; + } + + @Override + public MethodTree declaration() { + return null; + } + + @Override + public List parameterTypes() { + return Collections.emptyList(); + } + + @Override + public List declarationParameters() { + return Collections.emptyList(); + } + + @Override + public Symbol.TypeSymbol returnType() { + return TypeSymbol.UNKNOWN_TYPE; + } + + @Override + public List thrownTypes() { + return Collections.emptyList(); + } + + @Override + public List overriddenSymbols() { + return Collections.emptyList(); + } + + @Override + public Symbol owner() { + return owner; + } + + @Override + public Type type() { + return Type.UNKNOWN; + } + + @Override + public boolean isVariableSymbol() { + return false; + } + + @Override + public boolean isTypeSymbol() { + return false; + } + + @Override + public boolean isMethodSymbol() { + return true; + } + + @Override + public boolean isPackageSymbol() { + return false; + } + + @Override + public boolean isStatic() { + return isStatic; + } + + @Override + public boolean isFinal() { + return false; + } + + @Override + public boolean isEnum() { + return false; + } + + @Override + public boolean isInterface() { + return false; + } + + @Override + public boolean isAbstract() { + return false; + } + + @Override + public boolean isPublic() { + return false; + } + + @Override + public boolean isPrivate() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isPackageVisibility() { + return false; + } + + @Override + public boolean isDeprecated() { + return false; + } + + @Override + public boolean isVolatile() { + return false; + } + + @Override + public boolean isUnknown() { + return false; + } + + @Override + public SymbolMetadata metadata() { + return Symbols.EMPTY_METADATA; + } + + @Override + public TypeSymbol enclosingClass() { + return owner; + } + + @Override + public List usages() { + return Collections.emptyList(); + } + + @Override + public String name() { + return isStatic ? " (initializer block)" : " (initializer block)"; + } + + @Override + public String signature() { + return owner.name() + "." + name(); + } + + @Override + public boolean isOverridable() { + return false; + } + + @Override + public boolean isParametrizedMethod() { + return false; + } + + @Override + public boolean isDefaultMethod() { + return false; + } + + @Override + public boolean isSynchronizedMethod() { + return false; + } + + @Override + public boolean isVarArgsMethod() { + return false; + } + + @Override + public boolean isNativeMethod() { + return false; + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JSymbol.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JSymbol.java index 37cc5e94ffe..ef6ff0a3fb5 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JSymbol.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JSymbol.java @@ -23,7 +23,6 @@ import java.util.Objects; import java.util.Set; import javax.annotation.Nullable; -import org.sonar.java.model.Symbols; import org.sonar.plugins.java.api.semantic.Symbol; import org.sonar.plugins.java.api.semantic.SymbolMetadata; import org.sonar.plugins.java.api.semantic.Type; @@ -57,6 +56,7 @@ enum Kind { private boolean deprecated; private static final String PRIVATE = "private"; private final Set modifiers = new HashSet<>(); + private SymbolMetadata metadata; private int hash; JSymbol(JSema sema, Kind kind, @Nullable String id, String name) { @@ -286,7 +286,10 @@ public boolean isUnknown() { @Override public final SymbolMetadata metadata() { - return Symbols.EMPTY_METADATA; + if (metadata == null) { + metadata = new JSymbolMetadata(this); + } + return metadata; } @Nullable diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JSymbolMetadata.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JSymbolMetadata.java new file mode 100644 index 00000000000..f573f8408fb --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JSymbolMetadata.java @@ -0,0 +1,423 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Stream; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import org.sonar.java.model.JNullabilityData; +import org.sonar.java.model.JSymbolMetadataNullabilityHelper; +import org.sonar.java.model.ModifiersUtils; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.SymbolMetadata; +import org.sonar.plugins.java.api.tree.AnnotationTree; +import org.sonar.plugins.java.api.tree.ArrayTypeTree; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.ParameterizedTypeTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeTree; +import org.sonar.plugins.java.api.tree.VariableTree; + +/** + * Annotations of one symbol, taken from its declaration tree when the file contains it and from + * the graph fact otherwise. Nullability walks those annotations and then overridden methods. + */ +final class JSymbolMetadata implements SymbolMetadata { + + private final JSymbol symbol; + + private List annotations; + + private final Map nullabilityCache = new EnumMap<>(NullabilityTarget.class); + + JSymbolMetadata(JSymbol symbol) { + this.symbol = symbol; + } + + public static NullabilityData noNullabilityAnnotationAt(NullabilityLevel level) { + return JNullabilityData.noNullabilityAnnotationAt(level); + } + + public static NullabilityData unknownNullabilityAt(NullabilityLevel level) { + return JNullabilityData.unknownNullabilityAt(level); + } + + @Override + public List annotations() { + if (annotations == null) { + annotations = loadAnnotations(); + } + return annotations; + } + + @Override + public List symbolAnnotations() { + return annotations(); + } + + private List loadAnnotations() { + Tree declaration = symbol.declaration(); + if (declaration != null) { + List fromTree = new ArrayList<>(); + TypeTree written = declaredType(declaration); + boolean array = written instanceof ArrayTypeTree; + for (AnnotationTree annotation : ModifiersUtils.getAnnotations(declaration)) { + // an annotation only a type can carry, written before an array type, is on its elements + if (!(array && isTypeUseOnly(annotation)) && !namesDeclaredNonAnnotation(annotation)) { + fromTree.add(new TreeAnnotation(symbol.sema, annotation)); + } + } + if (written != null) { + for (AnnotationTree annotation : outermostTypeAnnotations(written)) { + fromTree.add(new TreeAnnotation(symbol.sema, annotation)); + } + } + return fromTree; + } + List fromFacts = new ArrayList<>(); + List declared = symbol instanceof JPackageSymbol + ? symbol.sema.annotationFacts().packageAnnotations(symbol.name()) + : symbol.sema.annotationFacts().declaredAnnotations(symbol.id); + for (DeclaredAnnotation annotation : declared) { + fromFacts.add(new FactAnnotation(symbol.sema, SemaFacts.erase(annotation.name()), annotation.values(), annotation.valuesKnown())); + } + return fromFacts; + } + + /** A class or interface declared in the sources is not an annotation, whatever the code writes after the {@code @}. */ + private static boolean namesDeclaredNonAnnotation(AnnotationTree annotation) { + return annotation.annotationType().symbolType().symbol().declaration() instanceof ClassTree declared && !declared.is(Tree.Kind.ANNOTATION_TYPE); + } + + @Nullable + private static TypeTree declaredType(Tree declaration) { + if (declaration instanceof MethodTree method) { + return method.returnType(); + } + return declaration instanceof VariableTree variable ? variable.type() : null; + } + + /** The annotations written on the type itself: on an array type those of its first dimension. */ + private static List outermostTypeAnnotations(TypeTree type) { + TypeTree current = type; + while (current instanceof ArrayTypeTree array && array.type() instanceof ArrayTypeTree inner) { + current = inner; + } + if (current instanceof ArrayTypeTree array) { + return array.annotations(); + } + if (current instanceof IdentifierTree identifier) { + return identifier.annotations(); + } + if (current instanceof MemberSelectExpressionTree select) { + return select.identifier().annotations(); + } + return current instanceof ParameterizedTypeTree parameterized ? outermostTypeAnnotations(parameterized.type()) : List.of(); + } + + private static boolean isTypeUseOnly(AnnotationTree annotation) { + List targets = annotation.annotationType().symbolType().symbol().metadata().valuesForAnnotation("java.lang.annotation.Target"); + if (targets == null) { + return false; + } + Set names = new HashSet<>(); + for (AnnotationValue target : targets) { + collectTargets(target.value(), names); + } + return names.contains("TYPE_USE") && Stream.of("METHOD", "FIELD", "PARAMETER", "LOCAL_VARIABLE").noneMatch(names::contains); + } + + private static void collectTargets(@Nullable Object value, Set names) { + if (value instanceof Object[] values) { + for (Object item : values) { + collectTargets(item, names); + } + } else if (value instanceof Symbol symbol) { + names.add(symbol.name()); + } + } + + @Override + public boolean isAnnotatedWith(String fullyQualifiedName) { + for (AnnotationInstance annotation : annotations()) { + if (annotation.symbol().type().is(fullyQualifiedName)) { + return true; + } + } + return false; + } + + @Nullable + @Override + public List valuesForAnnotation(String fullyQualifiedNameOfAnnotation) { + for (AnnotationInstance annotation : annotations()) { + if (annotation.symbol().type().is(fullyQualifiedNameOfAnnotation)) { + return annotation.values(); + } + } + return null; + } + + @Override + public NullabilityData nullabilityData() { + NullabilityTarget target = target(symbol); + if (target == null) { + return unknownNullabilityAt(NullabilityLevel.UNKNOWN); + } + return nullabilityData(target); + } + + @Override + public NullabilityData nullabilityData(NullabilityTarget target) { + return nullabilityCache.computeIfAbsent(target, this::resolveNullability); + } + + @Nullable + @Override + public AnnotationTree findAnnotationTree(AnnotationInstance annotationInstance) { + Tree declaration = symbol.declaration(); + if (declaration == null) { + return null; + } + for (AnnotationTree annotation : ModifiersUtils.getAnnotations(declaration)) { + if (annotation.annotationType().symbolType().symbol().equals(annotationInstance.symbol()) + && annotation.arguments().size() == annotationInstance.values().size()) { + return annotation; + } + } + return null; + } + + @Override + public SymbolMetadata[] parametersMetadata() { + Tree declaration = symbol.declaration(); + return declaration == null ? new SymbolMetadata[0] : typeArgumentsMetadata(symbol.sema, declaredType(declaration)); + } + + private static SymbolMetadata[] typeArgumentsMetadata(JSema sema, @Nullable TypeTree written) { + if (!(written instanceof ParameterizedTypeTree parameterized)) { + return new SymbolMetadata[0]; + } + return parameterized.typeArguments().stream() + .map(argument -> new TypeTreeMetadata(sema, argument)) + .toArray(SymbolMetadata[]::new); + } + + static boolean isAnnotatedType(TypeTree type) { + return !outermostTypeAnnotations(type).isEmpty(); + } + + static SymbolMetadata ofTypeTree(JSema sema, TypeTree type) { + return new TypeTreeMetadata(sema, type); + } + + static SymbolMetadata ofDeclared(JSema sema, List declared) { + return new DeclaredTypeMetadata(sema, declared); + } + + /** The annotations written on a type, such as an argument of a parameterized type. */ + private abstract static class AnnotatedType implements SymbolMetadata { + + private List annotations; + + abstract List loadAnnotations(); + + @Override + public List annotations() { + if (annotations == null) { + annotations = loadAnnotations(); + } + return annotations; + } + + @Override + public List symbolAnnotations() { + return annotations(); + } + + @Override + public boolean isAnnotatedWith(String fullyQualifiedName) { + return annotations().stream().anyMatch(annotation -> annotation.symbol().type().is(fullyQualifiedName)); + } + + @Nullable + @Override + public List valuesForAnnotation(String fullyQualifiedNameOfAnnotation) { + return annotations().stream() + .filter(annotation -> annotation.symbol().type().is(fullyQualifiedNameOfAnnotation)) + .map(AnnotationInstance::values) + .findFirst() + .orElse(null); + } + + @Override + public NullabilityData nullabilityData() { + return nullabilityData(NullabilityTarget.PARAMETER); + } + + @Override + public NullabilityData nullabilityData(NullabilityTarget target) { + return JSymbolMetadataNullabilityHelper.getNullabilityDataAtLevel(this, target, NullabilityLevel.VARIABLE); + } + } + + private static final class TypeTreeMetadata extends AnnotatedType { + + private final JSema sema; + private final TypeTree type; + + private TypeTreeMetadata(JSema sema, TypeTree type) { + this.sema = sema; + this.type = type; + } + + @Override + List loadAnnotations() { + return outermostTypeAnnotations(type).stream().map(annotation -> new TreeAnnotation(sema, annotation)).toList(); + } + + @Nullable + @Override + public AnnotationTree findAnnotationTree(AnnotationInstance annotationInstance) { + return outermostTypeAnnotations(type).stream() + .filter(annotation -> annotation.annotationType().symbolType().symbol().equals(annotationInstance.symbol())) + .findFirst() + .orElse(null); + } + + @Override + public SymbolMetadata[] parametersMetadata() { + return typeArgumentsMetadata(sema, type); + } + } + + /** The annotations of a type a server answer states, such as a type argument of a supertype. */ + private static final class DeclaredTypeMetadata extends AnnotatedType { + + private final JSema sema; + private final List declared; + + private DeclaredTypeMetadata(JSema sema, List declared) { + this.sema = sema; + this.declared = declared; + } + + @Override + List loadAnnotations() { + return declared.stream() + .map(annotation -> new FactAnnotation(sema, SemaFacts.erase(annotation.name()), annotation.values(), annotation.valuesKnown())) + .toList(); + } + + @Nullable + @Override + public AnnotationTree findAnnotationTree(AnnotationInstance annotationInstance) { + return null; + } + + @Override + public SymbolMetadata[] parametersMetadata() { + return new SymbolMetadata[0]; + } + } + + private NullabilityData resolveNullability(NullabilityTarget target) { + NullabilityLevel level = level(symbol); + NullabilityData atLevel = JSymbolMetadataNullabilityHelper.getNullabilityDataAtLevel(this, target, level); + if (atLevel.type() != NullabilityType.NO_ANNOTATION) { + return atLevel; + } + if (symbol.isMethodSymbol()) { + NullabilityData inherited = inheritedNullability((Symbol.MethodSymbol) symbol, target); + if (inherited.type() != NullabilityType.NO_ANNOTATION) { + return inherited; + } + } + if (symbol.isPackageSymbol()) { + return noNullabilityAnnotationAt(level); + } + Symbol owner = symbol.owner(); + // a local or anonymous class is declared in a method or initializer; the contract of that member is not its own + while (symbol.isTypeSymbol() && owner != null && (owner.isMethodSymbol() || owner.isVariableSymbol())) { + owner = owner.owner(); + } + if (owner == Symbol.ROOT_PACKAGE) { + return noNullabilityAnnotationAt(NullabilityLevel.PACKAGE); + } + if (owner == null || owner.isUnknown()) { + return unknownNullabilityAt(level); + } + return owner.metadata().nullabilityData(target); + } + + private static NullabilityData inheritedNullability(Symbol.MethodSymbol method, NullabilityTarget target) { + for (Symbol.MethodSymbol overridden : method.overriddenSymbols()) { + NullabilityData data = JSymbolMetadataNullabilityHelper.getNullabilityDataAtLevel(overridden.metadata(), target, NullabilityLevel.METHOD); + if (data.type() != NullabilityType.NO_ANNOTATION && !data.equals(unknownNullabilityAt(NullabilityLevel.METHOD))) { + return data; + } + } + return noNullabilityAnnotationAt(NullabilityLevel.METHOD); + } + + static NullabilityLevel level(Symbol symbol) { + if (symbol.isVariableSymbol()) { + return NullabilityLevel.VARIABLE; + } + if (symbol.isMethodSymbol()) { + return NullabilityLevel.METHOD; + } + if (symbol.isTypeSymbol()) { + return NullabilityLevel.CLASS; + } + if (symbol.isPackageSymbol()) { + return NullabilityLevel.PACKAGE; + } + return NullabilityLevel.UNKNOWN; + } + + @CheckForNull + private static NullabilityTarget target(Symbol symbol) { + if (symbol.isMethodSymbol()) { + return NullabilityTarget.METHOD; + } + if (!symbol.isVariableSymbol()) { + return null; + } + Symbol owner = symbol.owner(); + if (owner != null && owner.isTypeSymbol()) { + return NullabilityTarget.FIELD; + } + Tree declaration = symbol.declaration(); + if (declaration == null || declaration.parent() == null || declaration.parent() instanceof MethodTree) { + return NullabilityTarget.PARAMETER; + } + if (declaration.parent().is(Tree.Kind.LAMBDA_EXPRESSION)) { + return null; + } + return NullabilityTarget.LOCAL_VARIABLE; + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JTypeSymbol.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JTypeSymbol.java index 157bc1a3f05..ff90570dfd0 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JTypeSymbol.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JTypeSymbol.java @@ -376,7 +376,7 @@ List membersNamed(String name) { return generic.membersNamed(name); } List found = new ArrayList<>(); - if (members != null || id == null || sema.inDocument(id) || declaration() != null) { + if (members != null || id == null || isDeclaredInDocument()) { // The implicit members of a type this file declares depend on all of its members. for (Symbol member : memberSymbols()) { if (name.equals(member.name())) { @@ -396,6 +396,11 @@ List membersNamed(String name) { return found; } + /** True for a type the analyzed file declares, even before its declaration tree is attached. */ + boolean isDeclaredInDocument() { + return (id != null && sema.inDocument(id)) || declaration() != null; + } + /** False only when the fact surely names another member: by its written name, or by the name its id gives. */ private static boolean mayBeNamed(JsonObject member, String name) { if (member.get("id") instanceof JsonPrimitive memberId) { diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JVariableSymbol.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JVariableSymbol.java index 42a1846d5db..cd0bbfd4361 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JVariableSymbol.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JVariableSymbol.java @@ -26,6 +26,7 @@ import org.sonar.plugins.java.api.semantic.Symbol; import org.sonar.plugins.java.api.semantic.SymbolMetadata; import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.AnnotationTree; import org.sonar.plugins.java.api.tree.ExpressionTree; import org.sonar.plugins.java.api.tree.IdentifierTree; import org.sonar.plugins.java.api.tree.LiteralTree; @@ -201,7 +202,7 @@ public boolean isParameter() { @Override public SymbolMetadata metadata() { - return Symbols.EMPTY_METADATA; + return new PlaceholderMetadata(owner); } @Override @@ -214,4 +215,54 @@ public boolean isFinal() { return false; } } + /** A parameter no source declares carries no annotation of its own: its nullability is the default its method, class or package sets. */ + private static final class PlaceholderMetadata implements SymbolMetadata { + private final Symbol owner; + + PlaceholderMetadata(Symbol owner) { + this.owner = owner; + } + + @Override + public boolean isAnnotatedWith(String fullyQualifiedName) { + return false; + } + + @Nullable + @Override + public List valuesForAnnotation(String fullyQualifiedNameOfAnnotation) { + return null; + } + + @Override + public List annotations() { + return Collections.emptyList(); + } + + @Override + public List symbolAnnotations() { + return Collections.emptyList(); + } + + @Override + public NullabilityData nullabilityData() { + return nullabilityData(NullabilityTarget.PARAMETER); + } + + @Override + public NullabilityData nullabilityData(NullabilityTarget target) { + return owner.isUnknown() ? JSymbolMetadata.unknownNullabilityAt(NullabilityLevel.VARIABLE) : owner.metadata().nullabilityData(target); + } + + @Nullable + @Override + public AnnotationTree findAnnotationTree(AnnotationInstance annotationInstance) { + return null; + } + + @Override + public SymbolMetadata[] parametersMetadata() { + return new SymbolMetadata[0]; + } + } } diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JWarning.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JWarning.java new file mode 100644 index 00000000000..6192cf82698 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/JWarning.java @@ -0,0 +1,48 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.Objects; +import org.sonar.plugins.java.api.diagnostics.ProblemKind; +import org.sonar.plugins.java.api.diagnostics.Warning; +import org.sonar.plugins.java.api.tree.Tree; + +public final class JWarning extends JProblem implements Warning { + + private final Tree syntaxTree; + + JWarning(String message, ProblemKind type, Tree syntaxTree) { + super(message, type); + this.syntaxTree = syntaxTree; + } + + @Override + public Tree syntaxTree() { + return syntaxTree; + } + + @Override + public boolean equals(Object o) { + return super.equals(o) && syntaxTree == ((JWarning) o).syntaxTree; + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), System.identityHashCode(syntaxTree)); + } + +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/LambdaTranslator.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/LambdaTranslator.java new file mode 100644 index 00000000000..32094a0ad26 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/LambdaTranslator.java @@ -0,0 +1,338 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.Nullable; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.declaration.VariableTreeImpl; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.java.model.expression.LambdaExpressionTreeImpl; +import org.sonar.java.model.expression.MethodReferenceTreeImpl; +import org.sonar.java.model.pattern.RecordPatternTreeImpl; +import org.sonar.java.model.pattern.TypePatternTreeImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.InferedTypeTree; +import org.sonar.plugins.java.api.tree.LambdaExpressionTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.PatternTree; +import org.sonar.plugins.java.api.tree.ReturnStatementTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeTree; +import org.sonar.plugins.java.api.tree.VariableTree; + +import static org.sonar.java.semsitter.Bindings.ascribe; +import static org.sonar.java.semsitter.Bindings.bind; +import static org.sonar.java.semsitter.Bindings.namesType; +import static org.sonar.java.semsitter.Bindings.variableType; +import static org.sonar.java.semsitter.CstNodes.firstOf; +import static org.sonar.java.semsitter.CstNodes.firstType; +import static org.sonar.java.semsitter.CstNodes.lastNamed; +import static org.sonar.java.semsitter.CstNodes.lastOf; +import static org.sonar.java.semsitter.CstNodes.required; +import static org.sonar.java.semsitter.CstNodes.requiredField; + +/** Translates lambdas, method references and patterns. */ +final class LambdaTranslator extends TranslatorPart { + private static final String RECORD_PATTERN = "record_pattern"; + + LambdaTranslator(TranslationState state) { + super(state); + } + + void bindLambdaParameterOwner(LambdaExpressionTreeImpl lambda, Type target) { + JMethodSymbol functional = sema.lookup().functionalMethod(target); + if (functional == null || functional.parameterTypes().size() != lambda.parameters().size()) { + return; + } + List substituted = sema.substitution().invocationParameters(functional, target, List.of()); + List types = lambdaParameterTypes(lambda, functional, substituted); + JMethodSymbol shared = sema.substitution().invocationView(functional, target, types, sema.inference().invocationReturn(functional, target, List.of())); + var arrow = lambda.arrowToken().range().start(); + JMethodSymbol view = shared.lambdaView(functional.id + "$lambda$" + arrow.line() + ":" + arrow.column() + "()"); + lambda.setSymbol(view); + for (VariableTree parameter : lambda.parameters()) { + if (parameter.symbol() instanceof JVariableSymbol symbol) { + symbol.owner(view); + } + } + ascribeLambdaResults(lambda, view.returnType().type()); + ownLambdaVariables(lambda, view); + } + + /** Types the untyped lambda parameters from the functional method and returns the type each parameter ends up with. */ + private static List lambdaParameterTypes(LambdaExpressionTreeImpl lambda, JMethodSymbol functional, List substituted) { + List types = new ArrayList<>(); + for (int i = 0; i < lambda.parameters().size(); i++) { + VariableTree parameter = lambda.parameters().get(i); + Type type = parameter.symbol().type(); + if ((type == null || type.isUnknown()) && parameter.symbol() instanceof JVariableSymbol symbol && !substituted.get(i).isUnknown()) { + type = substituted.get(i); + symbol.type(type); + ascribe(parameter.simpleName(), type); + } + if (parameter.type() instanceof InferedTypeTree inferred && inferred.symbolType().isUnknown() && type != null && !type.isUnknown()) { + ascribe(inferred, type); + } + types.add(type == null || type.isUnknown() ? functional.parameterTypes().get(i) : type); + } + return types; + } + + private static void ownLambdaVariables(LambdaExpressionTreeImpl lambda, JMethodSymbol view) { + lambda.body().accept(new BaseTreeVisitor() { + @Override + public void visitVariable(VariableTree tree) { + if (tree.symbol() instanceof JVariableSymbol symbol && symbol.owner() instanceof JSymbol owner && owner.id != null && owner.id.contains("$lambda$")) { + symbol.owner(view); + } + super.visitVariable(tree); + } + + @Override + public void visitIdentifier(IdentifierTree tree) { + if (tree instanceof IdentifierTreeImpl use && use.symbolType().isUnknown() && use.symbol() instanceof JVariableSymbol variable + && lambda.parameters().stream().anyMatch(parameter -> parameter.symbol().equals(variable)) && variable.type() != null && !variable.type().isUnknown()) { + ascribe(use, variable.type()); + } + } + + @Override + public void visitLambdaExpression(LambdaExpressionTree tree) { + // nested lambdas own their variables + } + + @Override + public void visitClass(ClassTree tree) { + // local and anonymous classes own their variables + } + }); + } + + /** The values a lambda returns take the return type of the functional method as their target. */ + private void ascribeLambdaResults(LambdaExpressionTreeImpl lambda, Type returned) { + if (returned.isUnknown() || returned.isVoid()) { + return; + } + if (lambda.body() instanceof ExpressionTree value) { + expressions().ascribeTarget(value, returned); + return; + } + lambda.body().accept(new BaseTreeVisitor() { + @Override + public void visitReturnStatement(ReturnStatementTree tree) { + if (tree.expression() != null) { + expressions().ascribeTarget(tree.expression(), returned); + } + } + + @Override + public void visitLambdaExpression(LambdaExpressionTree tree) { + // nested lambdas have their own results + } + + @Override + public void visitClass(ClassTree tree) { + // local and anonymous classes have their own methods + } + }); + } + + /** + * The type a method reference yields, or null when it is a constructor reference or the method is generic or unknown. + * An unbound {@code Type::method} returning a class type variable takes it from the function's first parameter. + */ + @Nullable + Type referenceResult(MethodReferenceTreeImpl reference, Type function) { + if (!(reference.method().symbol() instanceof JMethodSymbol method) || method.isUnknown() || "new".equals(method.name()) || "".equals(method.name())) { + return null; + } + Type returned = method.returnType().type(); + if (sema.functionalInference().returnsClassVariable(method) && namesType(reference.expression())) { + return sema.functionalInference().unboundReferenceResult(method, function); + } + return returned == null || returned.isUnknown() || returned.isTypeVar() || returned.isVoid() ? null : returned; + } + + PatternTree pattern(CstNode node) { + if (RECORD_PATTERN.equals(node.k())) { + return recordPattern(node); + } + CstNode nested = firstOf(node, RECORD_PATTERN, "type_pattern", "pattern", "underscore_pattern"); + if (nested != null) { + return pattern(nested); + } + if ("underscore_pattern".equals(node.k())) { + return new TypePatternTreeImpl(new VariableTreeImpl(new IdentifierTreeImpl(token(node), true)), Type.UNKNOWN); + } + CstNode name = lastOf(node, "identifier"); + VariableTreeImpl variable = new VariableTreeImpl(members().modifiers(node), typeTrees().type(firstType(node)), names().identifier(name == null ? node : name)); + bindDeclaration(variable, name, (IdentifierTreeImpl) variable.simpleName()); + if (variable.symbol().type() != null && !variable.symbol().type().isUnknown()) { + ascribe(variable.type(), variable.symbol().type()); + } + return new TypePatternTreeImpl(variable, variableType(variable)); + } + + private RecordPatternTreeImpl recordPattern(CstNode node) { + CstNode body = required(node, "record_pattern_body"); + List patterns = new ArrayList<>(); + for (CstNode child : body.children()) { + if ("record_pattern_component".equals(child.k()) || RECORD_PATTERN.equals(child.k())) { + patterns.add(pattern(child)); + } + } + TypeTree recordType = typeTrees().type(firstType(node)); + state.deferred.add(() -> { + if (recordType.symbolType().symbol().declaration() instanceof ClassTree recordClass && recordClass.recordComponents().size() == patterns.size()) { + for (int i = 0; i < patterns.size(); i++) { + if (patterns.get(i) instanceof TypePatternTreeImpl unnamed && unnamed.patternVariable().symbol().isUnknown() + && unnamed.patternVariable() instanceof VariableTreeImpl variable) { + patterns.set(i, typeUnnamedPattern(variable, recordClass.recordComponents().get(i).type().symbolType())); + } + } + } + }); + return new RecordPatternTreeImpl(recordType, token(required(body, "(")), patterns, token(required(body, ")"))); + } + + /** An unnamed pattern variable has the type of the record component it stands for. */ + private TypePatternTreeImpl typeUnnamedPattern(VariableTreeImpl variable, Type type) { + var start = ((IdentifierTreeImpl) variable.simpleName()).identifierToken().range().start(); + JVariableSymbol symbol = new JVariableSymbol(sema, "_@" + start.line() + ":" + start.column(), "_", "local"); + symbol.type(type); + sema.declare(symbol.id, variable); + variable.setSymbol(symbol); + ascribe(variable.type(), type); + return new TypePatternTreeImpl(variable, type); + } + + LambdaExpressionTreeImpl lambda(CstNode node) { + state.scopes.addFirst(new HashMap<>()); + state.returnTargets.push(Type.UNKNOWN); + try { + return lambdaInScope(node); + } finally { + state.scopes.removeFirst(); + state.returnTargets.pop(); + } + } + + private LambdaExpressionTreeImpl lambdaInScope(CstNode node) { + List parameters = new ArrayList<>(); + CstNode formals = requiredField(node, "parameters", null); + InternalSyntaxToken open = null; + InternalSyntaxToken close = null; + if ("formal_parameters".equals(formals.k()) || "inferred_parameters".equals(formals.k())) { + open = optionalToken(formals, "("); + close = optionalToken(formals, ")"); + if ("formal_parameters".equals(formals.k())) { + parameters.addAll(members().parameters(formals)); + } else { + parameters.addAll(inferredParameters(formals)); + } + } else { + parameters.add(untypedParameter(formals)); + } + CstNode body = requiredField(node, "body", lastNamed(node)); + Tree lambdaBody = "block".equals(body.k()) ? statements().block(body) : expressions().expression(body); + LambdaExpressionTreeImpl tree = new LambdaExpressionTreeImpl(open, parameters, close, token(required(node, "->")), lambdaBody); + state.deferred.add(() -> parameters.forEach(parameter -> { + if (parameter.type() instanceof InferedTypeTree inferred && inferred.symbolType().isUnknown() && !parameter.symbol().type().isUnknown()) { + ascribe(inferred, parameter.symbol().type()); + } + })); + state.deferred.add(() -> unbindUntypedParameters(tree)); + for (VariableTree parameter : parameters) { + if (parameter.symbol().owner() instanceof JMethodSymbol method) { + method.lambda(true); + tree.setSymbol(method); + break; + } + } + return tree; + } + + private List inferredParameters(CstNode formals) { + List inferred = new ArrayList<>(); + for (CstNode child : formals.children()) { + if ("identifier".equals(child.k())) { + inferred.add(untypedParameter(child)); + } else if (",".equals(child.text())) { + inferred.get(inferred.size() - 1).setEndToken(token(child)); + } + } + return inferred; + } + + private VariableTreeImpl untypedParameter(CstNode node) { + IdentifierTreeImpl name = names().identifier(node); + VariableTreeImpl parameter = new VariableTreeImpl(name); + bindDeclaration(parameter, node, name); + return parameter; + } + + /** The compiler leaves the receivers of a lambda without a target unresolved: its inferred parameters are not bound where they qualify a member. */ + private static void unbindUntypedParameters(LambdaExpressionTreeImpl lambda) { + if (!lambda.symbolType().isUnknown()) { + return; + } + Set untyped = new HashSet<>(); + for (VariableTree parameter : lambda.parameters()) { + if (parameter.type() instanceof InferedTypeTree && parameter.symbol().type().isUnknown()) { + untyped.add(parameter.symbol()); + } + } + if (untyped.isEmpty()) { + return; + } + lambda.body().accept(new BaseTreeVisitor() { + @Override + public void visitMemberSelectExpression(MemberSelectExpressionTree select) { + if (select.expression() instanceof IdentifierTreeImpl use && untyped.contains(use.symbol())) { + use.symbol().usages().remove(use); + bind(use, Symbol.UNKNOWN_SYMBOL); + } + super.visitMemberSelectExpression(select); + } + }); + } + + MethodReferenceTreeImpl methodReference(CstNode node) { + List children = node.children(); + ExpressionTree qualifier = expressions().expression(children.get(0)); + CstNode nameNode = children.get(children.size() - 1); + IdentifierTreeImpl name = names().identifier(nameNode); + if (!"new".equals(name.name()) || !qualifier.is(Tree.Kind.ARRAY_TYPE)) { + bindUse(name, nameNode, true); + } + MethodReferenceTreeImpl tree = new MethodReferenceTreeImpl(qualifier, token(required(node, "::"))); + CstNode typeArguments = firstOf(node, "type_arguments"); + tree.complete(typeArguments == null ? null : typeTrees().typeArguments(typeArguments), name); + ascribe(tree, Type.UNKNOWN); + return tree; + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/MemberFactory.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/MemberFactory.java index 6a765ac8767..e07386d4d3a 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/MemberFactory.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/MemberFactory.java @@ -19,8 +19,10 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Set; import javax.annotation.Nullable; @@ -49,6 +51,8 @@ final class MemberFactory { private final JSema sema; final Set creating = new HashSet<>(); + private final Map initializerBlockSymbols = new HashMap<>(); + private final Map staticInitializerBlockSymbols = new HashMap<>(); MemberFactory(JSema sema) { this.sema = sema; @@ -352,6 +356,14 @@ void applyTypeInfo(JTypeSymbol symbol, JsonObject info) { symbol.unknown(false); } + JInitializerBlockSymbol initializerBlockSymbol(JTypeSymbol owner) { + return initializerBlockSymbols.computeIfAbsent(owner, k -> new JInitializerBlockSymbol(k, false)); + } + + JInitializerBlockSymbol staticInitializerBlockSymbol(JTypeSymbol owner) { + return staticInitializerBlockSymbols.computeIfAbsent(owner, k -> new JInitializerBlockSymbol(k, true)); + } + /** The unknown type a written name stands for when nothing declares it. */ JTypeSymbol recoveredType(String name) { JTypeSymbol recovered = sema.typeSymbol(name); diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/MemberTranslator.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/MemberTranslator.java new file mode 100644 index 00000000000..05668caa75c --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/MemberTranslator.java @@ -0,0 +1,353 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; +import javax.annotation.Nullable; +import org.sonar.java.ast.parser.ArgumentListTreeImpl; +import org.sonar.java.ast.parser.FormalParametersListTreeImpl; +import org.sonar.java.ast.parser.QualifiedIdentifierListTreeImpl; +import org.sonar.java.ast.parser.TypeParameterListTreeImpl; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.JavaTree; +import org.sonar.java.model.declaration.AnnotationTreeImpl; +import org.sonar.java.model.declaration.MethodTreeImpl; +import org.sonar.java.model.declaration.ModifierKeywordTreeImpl; +import org.sonar.java.model.declaration.ModifiersTreeImpl; +import org.sonar.java.model.declaration.VariableTreeImpl; +import org.sonar.java.model.expression.AssignmentExpressionTreeImpl; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.java.model.expression.MemberSelectExpressionTreeImpl; +import org.sonar.java.model.expression.NewArrayTreeImpl; +import org.sonar.java.model.expression.VarTypeTreeImpl; +import org.sonar.java.model.statement.BlockTreeImpl; +import org.sonar.java.model.statement.StaticInitializerTreeImpl; +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.ArrayTypeTree; +import org.sonar.plugins.java.api.tree.AssignmentExpressionTree; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.LambdaExpressionTree; +import org.sonar.plugins.java.api.tree.ModifierTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeTree; +import org.sonar.plugins.java.api.tree.VariableTree; + +import static org.sonar.java.semsitter.Bindings.ascribe; +import static org.sonar.java.semsitter.Bindings.bind; +import static org.sonar.java.semsitter.Bindings.keepsArguments; +import static org.sonar.java.semsitter.CstNodes.childKind; +import static org.sonar.java.semsitter.CstNodes.field; +import static org.sonar.java.semsitter.CstNodes.firstNamed; +import static org.sonar.java.semsitter.CstNodes.firstOf; +import static org.sonar.java.semsitter.CstNodes.firstType; +import static org.sonar.java.semsitter.CstNodes.isAnnotation; +import static org.sonar.java.semsitter.CstNodes.lastNamed; +import static org.sonar.java.semsitter.CstNodes.modifierKeyword; +import static org.sonar.java.semsitter.CstNodes.nameNode; +import static org.sonar.java.semsitter.CstNodes.required; +import static org.sonar.java.semsitter.CstNodes.requiredField; + +/** Translates methods, fields, variables, initializers, modifiers and annotations. */ +final class MemberTranslator extends TranslatorPart { + + private static final String DIMENSIONS = "dimensions"; + private static final String SPREAD_PARAMETER = "spread_parameter"; + private static final String VALUE = "value"; + + MemberTranslator(TranslationState state) { + super(state); + } + + MethodTreeImpl method(CstNode node) { + state.scopes.addFirst(new HashMap<>()); + CstNode typeNode = field(node, "type"); + state.returnTargets.push(typeNode == null || field(node, DIMENSIONS) != null ? Type.UNKNOWN : syntacticType(typeNode)); + try { + return methodInScope(node); + } finally { + state.scopes.removeFirst(); + state.returnTargets.pop(); + } + } + + private MethodTreeImpl methodInScope(CstNode node) { + // translated before the parameters and the body so that the bounds of the type parameters are known there + CstNode typeParameters = field(node, "type_parameters"); + TypeParameterListTreeImpl typeParameterList = typeParameters == null ? null : typeTrees().typeParameters(typeParameters); + FormalParametersListTreeImpl formals = formalParameters(field(node, "parameters")); + CstNode body = field(node, "body"); + BlockTreeImpl block = body == null ? null : statements().block(body); + CstNode typeNode = field(node, "type"); + TypeTree returnType = typeNode == null ? null : returnType(node, typeNode); + IdentifierTreeImpl name = names().identifier(requiredField(node, "name", firstOf(node, "identifier"))); + CstNode thrown = childKind(node, "throws"); + MethodTreeImpl tree = new MethodTreeImpl( + returnType, + name, + formals, + thrown == null ? null : token(required(thrown, "throws")), + thrown == null ? QualifiedIdentifierListTreeImpl.emptyList() : typeTrees().separatedTypes(thrown), + block, + body == null ? token(required(node, ";")) : null) + .completeWithModifiers(modifiers(node)); + if (typeParameterList != null) { + tree.completeWithTypeParameters(typeParameterList); + } + bindDeclaration(tree, nameNode(node), name); + return tree; + } + + private FormalParametersListTreeImpl formalParameters(@Nullable CstNode parameters) { + FormalParametersListTreeImpl formals = new FormalParametersListTreeImpl( + parameters == null ? null : token(required(parameters, "(")), + parameters == null ? null : token(required(parameters, ")"))); + if (parameters != null) { + for (CstNode child : parameters.children()) { + if ("formal_parameter".equals(child.k()) || SPREAD_PARAMETER.equals(child.k()) || "receiver_parameter".equals(child.k())) { + formals.add(variable(child)); + } else if (",".equals(child.text())) { + formals.get(formals.size() - 1).setEndToken(token(child)); + } + } + } + return formals; + } + + private TypeTree returnType(CstNode node, CstNode typeNode) { + TypeTree written = names().recoverQualifiedType(typeTrees().type(typeNode)); + List afterTypeParameters = node.children().stream().filter(CstNodes::isAnnotation).map(this::annotation).toList(); + TypeTree element = written; + while (element instanceof ArrayTypeTree array) { + element = array.type(); + } + TypeTranslator.annotateLeftmost(element, afterTypeParameters); + return typeTrees().arrayType(written, field(node, DIMENSIONS)); + } + + List parameters(CstNode parameters) { + List trees = new ArrayList<>(); + for (CstNode child : parameters.children()) { + if ("formal_parameter".equals(child.k()) || SPREAD_PARAMETER.equals(child.k())) { + trees.add(variable(child)); + } else if (",".equals(child.text())) { + trees.get(trees.size() - 1).setEndToken(token(child)); + } + } + return new ArrayList<>(trees); + } + + List variables(CstNode declaration) { + ModifiersTreeImpl modifiers = modifiers(declaration); + CstNode typeNode = field(declaration, "type"); + TypeTree type; + if (typeNode != null) { + type = typeTrees().type(typeNode); + if ("field_declaration".equals(declaration.k()) || "constant_declaration".equals(declaration.k())) { + type = names().recoverQualifiedType(type); + } else if (type instanceof MemberSelectExpressionTreeImpl select && select.symbolType().isUnknown()) { + // an unresolved qualified name of a local or a parameter is not typed by what is written + ascribe(select, JType.unknown(sema)); + } + } else if (SPREAD_PARAMETER.equals(declaration.k())) { + type = spreadType(declaration); + } else { + type = typeTrees().catchType(required(declaration, "catch_type")); + } + List trees = new ArrayList<>(); + for (CstNode child : declaration.children()) { + if ("variable_declarator".equals(child.k())) { + trees.add(declarator(child, modifiers, type)); + } else if (",".equals(child.text()) || ";".equals(child.text())) { + trees.get(trees.size() - 1).setEndToken(token(child)); + } + } + if (trees.isEmpty()) { + trees.add(declarator(declaration, modifiers, type)); + } + return trees; + } + + private TypeTree spreadType(CstNode node) { + TypeTree element = typeTrees().type(firstType(node)); + List annotations = node.children().stream().filter(CstNodes::isAnnotation).map(this::annotation).toList(); + JavaTree.ArrayTypeTreeImpl array = new JavaTree.ArrayTypeTreeImpl(element, annotations, token(required(node, "..."))); + ascribe(array, JType.array(sema, element.symbolType() instanceof JType elementType ? elementType : JType.unknown(sema))); + return array; + } + + VariableTreeImpl variable(CstNode parameter) { + return variables(parameter).get(0); + } + + private VariableTreeImpl declarator(CstNode node, ModifiersTreeImpl modifiers, TypeTree type) { + IdentifierTreeImpl name = names().identifier(requiredField(node, "name", firstOf(node, "identifier"))); + VariableTreeImpl tree = new VariableTreeImpl(name).completeModifiersAndType(modifiers, applyDimensions(type, node)); + CstNode value = field(node, VALUE); + if (value != null) { + ExpressionTree initializer = expressions().expression(value); + expressions().ascribeTarget(initializer, tree.type().symbolType()); + tree.completeTypeAndInitializer(tree.type(), token(required(node, "=")), initializer); + } + bindDeclaration(tree, nameNode(node), name); + Type declared = tree.type().symbolType(); + if (tree.type() instanceof VarTypeTreeImpl && tree.initializer() != null && tree.initializer().symbolType().isIntersectionType() && tree.symbol() instanceof JSymbol symbol) { + symbol.type(tree.initializer().symbolType()); + ascribe(tree.type(), tree.initializer().symbolType()); + } else if (keepsArguments(declared) && tree.symbol() instanceof JSymbol symbol) { + symbol.type(declared); + } else if (tree.symbol().type() != null && !tree.symbol().type().isUnknown()) { + ascribe(tree.type(), tree.symbol().type()); + } + return tree; + } + + private TypeTree applyDimensions(TypeTree type, CstNode node) { + CstNode dimensions = field(node, DIMENSIONS); + if (dimensions == null) { + return type; + } + return typeTrees().arrayType(type, dimensions); + } + + BlockTreeImpl staticInitializer(CstNode node) { + BlockTreeImpl block = statements().block(node); + ownInitializerVariables(block, true); + return new StaticInitializerTreeImpl(token(required(node, "static")), + (InternalSyntaxToken) block.openBraceToken(), block.body(), (InternalSyntaxToken) block.closeBraceToken()); + } + + /** Variables declared in an initializer block belong to the block, not to the class. */ + private void ownInitializerVariables(BlockTreeImpl block, boolean isStatic) { + Symbol.TypeSymbol enclosing = state.types.peek(); + if (!(enclosing instanceof JTypeSymbol enclosingType)) { + return; + } + JInitializerBlockSymbol owner = isStatic ? sema.memberFactory().staticInitializerBlockSymbol(enclosingType) : sema.memberFactory().initializerBlockSymbol(enclosingType); + block.accept(new BaseTreeVisitor() { + @Override + public void visitVariable(VariableTree tree) { + if (tree.symbol() instanceof JVariableSymbol variable && enclosing.equals(variable.owner())) { + variable.owner(owner); + } + super.visitVariable(tree); + } + + @Override + public void visitClass(ClassTree tree) { + // members of local and anonymous classes keep their own owner + } + + @Override + public void visitLambdaExpression(LambdaExpressionTree tree) { + // lambda variables belong to the lambda + } + }); + } + + BlockTreeImpl initializer(CstNode node) { + BlockTreeImpl block = statements().block(node); + ownInitializerVariables(block, false); + return new BlockTreeImpl(Tree.Kind.INITIALIZER, (InternalSyntaxToken) block.openBraceToken(), block.body(), (InternalSyntaxToken) block.closeBraceToken()); + } + + AssignmentExpressionTreeImpl elementValuePair(CstNode node) { + CstNode key = requiredField(node, "key", firstNamed(node)); + IdentifierTreeImpl name = names().identifier(key); + // An element name is never a local variable or a parameter of the same name. + bindUse(name, key, true); + ExpressionTree value = expressions().expression(requiredField(node, VALUE, lastNamed(node))); + AssignmentExpressionTreeImpl tree = new AssignmentExpressionTreeImpl(Tree.Kind.ASSIGNMENT, name, token(required(node, "=")), value); + ascribe(tree, value.symbolType()); + return tree; + } + + ModifiersTreeImpl modifiers(CstNode node) { + CstNode modifiers = childKind(node, "modifiers"); + List trees = new ArrayList<>(); + if (modifiers != null) { + for (CstNode child : modifiers.children()) { + trees.add(isAnnotation(child) ? annotation(child) : new ModifierKeywordTreeImpl(modifierKeyword(child.text()), token(child))); + } + } + return new ModifiersTreeImpl(trees); + } + + AnnotationTreeImpl annotation(CstNode node) { + TypeTree type = (TypeTree) expressions().expression(requiredField(node, "name", null)); + if (type instanceof IdentifierTreeImpl identifier) { + names().recoverType(identifier); + } + ArgumentListTreeImpl arguments = ArgumentListTreeImpl.emptyList(); + CstNode args = field(node, "arguments"); + if (args != null) { + arguments = expressions().arguments(args); + } + AnnotationTreeImpl tree = new AnnotationTreeImpl(token(required(node, "@")), type, arguments); + ascribe(tree, names().annotationType(type)); + if (type instanceof MemberSelectExpressionTreeImpl select && select.symbolType().isUnknown()) { + // the written qualified name is the annotation's type; the name tree itself stays unresolved + ascribe(select, JType.unknown(sema)); + } + for (ExpressionTree argument : arguments) { + if (argument instanceof AssignmentExpressionTree assignment && assignment.variable() instanceof IdentifierTreeImpl element && element.symbol().isUnknown() + && type.symbolType().isClass()) { + Symbol.MethodSymbol method = sema.lookup().declaredMethod(type.symbolType().fullyQualifiedName(), element.name(), List.of()); + if (method != null) { + bind(element, method); + ascribe(element, method.returnType().type()); + } + } + } + typeArrayValues(type, arguments); + return tree; + } + + /** An array value of an annotation, {@code @A({x, y})}, has the type of the element it is given to. */ + private void typeArrayValues(TypeTree type, ArgumentListTreeImpl arguments) { + if (!type.symbolType().isClass()) { + return; + } + for (ExpressionTree argument : arguments) { + String element = VALUE; + ExpressionTree value = argument; + if (argument instanceof AssignmentExpressionTreeImpl assignment && assignment.variable() instanceof IdentifierTreeImpl name) { + element = name.name(); + value = assignment.expression(); + } + Symbol.MethodSymbol method = value instanceof NewArrayTreeImpl array && array.type() == null + ? sema.lookup().declaredMethod(type.symbolType().fullyQualifiedName(), element, List.of()) + : null; + if (method != null && method.returnType() != null) { + expressions().ascribeTarget(value, method.returnType().type()); + if (argument instanceof AssignmentExpressionTreeImpl assignment) { + ascribe(assignment, value.symbolType()); + } + } + } + } + + List annotations(CstNode node) { + return node.children().stream().filter(CstNodes::isAnnotation).map(this::annotation).collect(Collectors.toCollection(ArrayList::new)); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/NameTranslator.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/NameTranslator.java new file mode 100644 index 00000000000..8bf098e429a --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/NameTranslator.java @@ -0,0 +1,385 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Stream; +import javax.annotation.Nullable; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.KeywordSuper; +import org.sonar.java.model.KeywordThis; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.java.model.expression.LiteralTreeImpl; +import org.sonar.java.model.expression.MemberSelectExpressionTreeImpl; +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.ExpressionTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeTree; + +import static org.sonar.java.semsitter.Bindings.ascribe; +import static org.sonar.java.semsitter.Bindings.bind; +import static org.sonar.java.semsitter.Bindings.literal; +import static org.sonar.java.semsitter.CstNodes.compoundName; +import static org.sonar.java.semsitter.CstNodes.dottedName; +import static org.sonar.java.semsitter.CstNodes.field; +import static org.sonar.java.semsitter.CstNodes.firstNamed; +import static org.sonar.java.semsitter.CstNodes.keyword; +import static org.sonar.java.semsitter.CstNodes.lastKeyword; +import static org.sonar.java.semsitter.CstNodes.lastNamed; +import static org.sonar.java.semsitter.CstNodes.receiverKeyword; +import static org.sonar.java.semsitter.CstNodes.required; +import static org.sonar.java.semsitter.CstNodes.same; +/** Translates and resolves identifiers, qualified names, member selects and literals. */ +final class NameTranslator extends TranslatorPart { + + private static final String SUPER = "super"; + private static final String JAVA_LANG_OBJECT = "java.lang.Object"; + + NameTranslator(TranslationState state) { + super(state); + } + + ExpressionTree primary(CstNode node) { + if ("this".equals(node.k())) { + return thisKeyword(node); + } + if (SUPER.equals(node.k())) { + return superKeyword(node); + } + if ("true".equals(node.k()) || "false".equals(node.k())) { + return literal(Tree.Kind.BOOLEAN_LITERAL, token(node), sema.getClassType("boolean")); + } + if ("null_literal".equals(node.k())) { + return literal(Tree.Kind.NULL_LITERAL, token(node), JType.nullType(sema)); + } + IdentifierTreeImpl identifier = identifier(node); + bindUse(identifier, node); + if (!state.naming && identifier.symbol().isUnknown() && node.unresolved()) { + String type = importedType(identifier.name()); + if (type != null) { + bindType(identifier, type); + } + } + if (!state.naming && identifier.symbol().isUnknown() && node.unresolved() && !"type_identifier".equals(node.k())) { + unresolvedField(identifier); + } + if (!state.naming && "type_identifier".equals(node.k())) { + preferSingleImport(identifier); + recoverType(identifier); + } + return identifier; + } + + private KeywordThis thisKeyword(CstNode node) { + KeywordThis keyword = new KeywordThis(token(node), Symbol.UNKNOWN_SYMBOL); + Symbol.TypeSymbol enclosing = state.types.peek(); + if (enclosing != null) { + bind(keyword, sema.lookup().receiverSymbol(enclosing, "this", enclosing.type())); + ascribe(keyword, enclosing.type()); + } + return keyword; + } + + private KeywordSuper superKeyword(CstNode node) { + KeywordSuper keyword = new KeywordSuper(token(node), Symbol.UNKNOWN_SYMBOL); + Symbol.TypeSymbol enclosing = state.types.peek(); + if (enclosing != null) { + Type superType = enclosing.superClass() == null ? Type.UNKNOWN : enclosing.superClass(); + bind(keyword, sema.lookup().receiverSymbol(enclosing, SUPER, superType)); + ascribe(keyword, superType); + } + return keyword; + } + + /** An unresolved qualified type name keeps its written name where the compiler's recovery does. */ + TypeTree recoverQualifiedType(TypeTree type) { + if (type instanceof MemberSelectExpressionTreeImpl select && select.symbolType().isUnknown() && select.identifier().symbol().isUnknown()) { + IdentifierTreeImpl identifier = (IdentifierTreeImpl) select.identifier(); + JTypeSymbol recovered = sema.memberFactory().recoveredType(dottedName(select)); + bind(identifier, recovered); + ascribe(identifier, recovered.type()); + ascribe(select, recovered.type()); + } + return type; + } + + /** The type of an annotation: an unresolved one keeps its written, possibly qualified, name. */ + Type annotationType(TypeTree type) { + if (type.symbolType().isUnknown()) { + return sema.memberFactory().recoveredType(dottedName((ExpressionTree) type)).type(); + } + return type.symbolType(); + } + + /** An unresolved type name keeps its written name, as a recovered binding does, so checks can match on the simple name. */ + void recoverType(IdentifierTreeImpl identifier) { + if (identifier.symbol().isUnknown()) { + JTypeSymbol recovered = sema.memberFactory().recoveredType(identifier.name()); + bind(identifier, recovered); + ascribe(identifier, recovered.type()); + } + } + + /** A duplicate single-type import is an error; recovery keeps the first, which is the type this simple name denotes. */ + private void preferSingleImport(IdentifierTreeImpl identifier) { + String imported = state.imports.singleImports.get(identifier.name()); + if (imported == null || !sema.declaresType(imported)) { + return; + } + Symbol symbol = identifier.symbol(); + boolean constructor = symbol.isMethodSymbol() && "".equals(symbol.name()); + if (!symbol.isTypeSymbol() && !symbol.isUnknown() && !constructor) { + return; + } + String resolved = identifier.symbolType().erasure().fullyQualifiedName(); + if (!imported.equals(resolved)) { + bindType(identifier, imported); + } + } + + /** The type a simple name stands for when SemSitter left it unresolved: imported, in the package, or in java.lang. */ + @Nullable + private String importedType(String name) { + List candidates = new ArrayList<>(); + if (state.imports.singleImports.containsKey(name)) { + candidates.add(state.imports.singleImports.get(name)); + } + candidates.add(state.packageName.isEmpty() ? name : (state.packageName + "." + name)); + state.imports.onDemandImports.forEach(prefix -> candidates.add(prefix + "." + name)); + candidates.add("java.lang." + name); + return candidates.stream().filter(sema::declaresType).findFirst().orElse(null); + } + + /** + * A name SemSitter left unresolved, looked up as a field of the enclosing types first, since a declared or inherited + * field shadows a static import, then as a static field a static import, single or on demand, brings in. + */ + private void unresolvedField(IdentifierTreeImpl identifier) { + String name = identifier.name(); + List imported = new ArrayList<>(); + String single = state.imports.staticImports.get(name); + if (single != null) { + imported.add(single); + } + imported.addAll(state.imports.staticOnDemandImports); + Stream members = state.types.stream().filter(type -> !type.isUnknown()) + .map(type -> sema.lookup().declaredField(type.type().fullyQualifiedName(), name)); + Stream imports = imported.stream().map(owner -> sema.lookup().declaredField(owner, name)) + .filter(field -> field != null && field.isStatic()); + Stream.concat(members, imports).filter(Objects::nonNull).findFirst().ifPresent(field -> { + bind(identifier, field); + ascribe(identifier, field.type()); + }); + } + + private void resolveQualifiedType(ExpressionTree qualifier, IdentifierTreeImpl identifier) { + Symbol owner = qualifierSymbol(qualifier); + String candidate; + if (owner.isTypeSymbol() && !owner.isUnknown()) { + candidate = owner.type().fullyQualifiedName() + "$" + identifier.name(); + } else if (owner.isUnknown() || owner.isPackageSymbol()) { + String prefix = dottedName(qualifier); + candidate = prefix.isEmpty() ? null : (prefix + "." + identifier.name()); + } else { + candidate = null; + } + if (candidate != null && sema.declaresType(candidate)) { + bindType(identifier, candidate); + } + } + + private static Symbol qualifierSymbol(ExpressionTree qualifier) { + if (qualifier instanceof MemberSelectExpressionTree select) { + return select.identifier().symbol(); + } + if (qualifier instanceof IdentifierTree name) { + return name.symbol(); + } + return Symbol.UNKNOWN_SYMBOL; + } + + @Nullable + private String fieldOwner(ExpressionTree qualifier) { + Type receiver = qualifier.symbolType().erasure(); + if (receiver.isClass()) { + return receiver.fullyQualifiedName(); + } + return qualifier instanceof IdentifierTree name ? importedType(name.name()) : null; + } + + /** The method SemSitter left unresolved, looked up in the receiver type, or in the enclosing types and static imports of an unqualified call. */ + @Nullable + Symbol.MethodSymbol libraryMethod(@Nullable ExpressionTree qualifier, String name, List arguments, Set functions) { + List owners = new ArrayList<>(); + if (qualifier != null) { + Type receiver = qualifier.symbolType().erasure(); + if (receiver.isClass()) { + owners.add(receiver.fullyQualifiedName()); + } else if (receiver.isArray()) { + owners.add(JAVA_LANG_OBJECT); + } else if (qualifier instanceof IdentifierTree typeName) { + String imported = importedType(typeName.name()); + if (imported != null) { + owners.add(imported); + } + } + } else { + state.types.stream().filter(type -> !type.isUnknown()).forEach(type -> owners.add(type.type().fullyQualifiedName())); + if (state.imports.staticImports.containsKey(name)) { + owners.add(state.imports.staticImports.get(name)); + } + owners.addAll(state.imports.staticOnDemandImports); + } + Symbol.MethodSymbol found = owners.stream().map(owner -> sema.lookup().declaredMethod(owner, name, arguments, functions)).filter(Objects::nonNull).findFirst().orElse(null); + if (found == null && qualifier != null && !qualifier.symbolType().isUnknown() && !owners.contains(JAVA_LANG_OBJECT)) { + found = sema.lookup().declaredMethod(JAVA_LANG_OBJECT, name, arguments, functions); + } + return found; + } + + private void bindQualifierPackages(ExpressionTree qualifier, IdentifierTree identifier) { + if (identifier.symbol() instanceof Symbol.TypeSymbol type && !type.isUnknown()) { + Symbol owner = type.owner(); + while (owner != null && !owner.isPackageSymbol()) { + owner = owner.owner(); + } + if (owner != null && dottedName(qualifier).equals(owner.name())) { + bindPackage(qualifier, owner.name()); + } + } + } + + void bindPackage(ExpressionTree tree, String name) { + ExpressionTree last = tree; + if (tree instanceof MemberSelectExpressionTree select) { + int dot = name.lastIndexOf('.'); + if (dot < 0) { + return; + } + bindPackage(select.expression(), name.substring(0, dot)); + last = select.identifier(); + } + if (last instanceof IdentifierTreeImpl identifier && identifier.symbol().isUnknown()) { + bind(identifier, sema.packageSymbol(name)); + } + } + + IdentifierTreeImpl identifier(CstNode node) { + String text = node.text().isEmpty() ? node.k() : node.text(); + InternalSyntaxToken token = state.tokens.getOrDefault(node.proto, new InternalSyntaxToken(node.line(), node.col(), text, List.of(), false)); + return new IdentifierTreeImpl(token, state.unnamedVariables && "_".equals(text)); + } + + LiteralTreeImpl integerLiteral(CstNode node) { + String text = node.text(); + boolean isLong = text.endsWith("l") || text.endsWith("L"); + return literal(isLong ? Tree.Kind.LONG_LITERAL : Tree.Kind.INT_LITERAL, token(node), sema.getClassType(isLong ? "long" : "int")); + } + + LiteralTreeImpl floatingLiteral(CstNode node) { + String text = node.text(); + boolean isFloat = text.endsWith("f") || text.endsWith("F"); + return literal(isFloat ? Tree.Kind.FLOAT_LITERAL : Tree.Kind.DOUBLE_LITERAL, token(node), sema.getClassType(isFloat ? "float" : "double")); + } + + MemberSelectExpressionTreeImpl memberSelect(CstNode node) { + CstNode object = field(node, "object"); + if (object == null) { + object = field(node, "scope"); + } + CstNode name = field(node, "name"); + if (name == null) { + name = field(node, "field"); + } + CstNode scope = object == null ? firstNamed(node) : object; + ExpressionTree qualifier = memberSelectQualifier(node, object, scope); + CstNode nameNode = name == null ? lastNamed(node) : name; + IdentifierTreeImpl identifier = receiverKeyword(identifier(nameNode)); + bindUse(identifier, name != null || nameNode.proto.getRefsCount() > 0 ? nameNode : node, true); + if (!state.naming) { + resolveMemberSelect(qualifier, identifier); + } + List annotations = node.children().stream().filter(CstNodes::isAnnotation).map(members()::annotation).toList(); + if (!annotations.isEmpty()) { + identifier.complete(annotations); + } + MemberSelectExpressionTreeImpl tree = new MemberSelectExpressionTreeImpl(qualifier, token(lastKeyword(node, ".")), identifier); + ascribe(tree, identifier.symbolType()); + return tree; + } + + private ExpressionTree memberSelectQualifier(CstNode node, @Nullable CstNode object, CstNode scope) { + if (object != null) { + return superQualifier(node, object); + } + return compoundName(scope) ? invocations().typeExpression(scope) : primary(scope); + } + + /** Resolves an identifier left unknown by SemSitter as a member of the qualifier: a nested type, a field, or a package. */ + private void resolveMemberSelect(ExpressionTree qualifier, IdentifierTreeImpl identifier) { + bindQualifiedReceiver(qualifier, identifier); + if (identifier.symbol().isUnknown()) { + resolveQualifiedType(qualifier, identifier); + } + if (identifier.symbol().isUnknown()) { + String owner = fieldOwner(qualifier); + Symbol.VariableSymbol field = owner == null ? null : sema.lookup().declaredField(owner, identifier.name()); + if (field != null) { + bind(identifier, field); + ascribe(identifier, field.type()); + } + } + bindQualifierPackages(qualifier, identifier); + if (identifier.symbol() instanceof JVariableSymbol field && !field.isUnknown() && field.type() != null) { + Type read = sema.substitution().fieldTypeOn(field, qualifier.symbolType()); + if (read != field.type()) { + ascribe(identifier, read); + } + } + } + + ExpressionTree superQualifier(CstNode node, CstNode object) { + ExpressionTree qualifier = expressions().expression(object); + CstNode superNode = keyword(node, SUPER); + if (superNode == null || same(superNode, object)) { + return qualifier; + } + IdentifierTreeImpl identifier = new KeywordSuper(token(superNode), Symbol.UNKNOWN_SYMBOL); + bindQualifiedReceiver(qualifier, identifier); + MemberSelectExpressionTreeImpl select = new MemberSelectExpressionTreeImpl(qualifier, token(required(node, ".")), identifier); + ascribe(select, identifier.symbolType()); + return select; + } + + private void bindQualifiedReceiver(ExpressionTree qualifier, IdentifierTreeImpl identifier) { + boolean isThis = "this".equals(identifier.name()); + if (!identifier.symbol().isUnknown() || (!isThis && !SUPER.equals(identifier.name())) + || !(qualifier.symbolType().symbol() instanceof Symbol.TypeSymbol owner) || owner.isUnknown()) { + return; + } + Type type = isThis || owner.isInterface() || owner.superClass() == null ? owner.type() : owner.superClass(); + bind(identifier, sema.lookup().receiverSymbol(owner, identifier.name(), type)); + ascribe(identifier, type); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/OverloadRanking.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/OverloadRanking.java index 483db9f1c5c..e2f8cfe308a 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/OverloadRanking.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/OverloadRanking.java @@ -16,6 +16,7 @@ */ package org.sonar.java.semsitter; +import java.util.ArrayList; import java.util.List; import java.util.Set; import javax.annotation.Nullable; @@ -23,26 +24,79 @@ import org.sonar.plugins.java.api.semantic.Type; /** Ranks applicable overloads to pick the most specific one. */ -class OverloadRanking { +final class OverloadRanking { - /** - * The overload that matches {@code arguments} when {@code candidate} is more specific than {@code current}. - * @param candidate overload to compare, used once ranking lands - * @param arguments types of the arguments, used once ranking lands - * @param functions positions of the lambda and method reference arguments, used once ranking lands - */ + private final JSema sema; + + OverloadRanking(JSema sema) { + this.sema = sema; + } + + /** The overload that matches {@code arguments} when {@code candidate} is more specific than {@code current}. */ Symbol.MethodSymbol preferOverload(Symbol.MethodSymbol current, @Nullable Symbol.MethodSymbol candidate, List arguments, Set functions) { + if (candidate == null || candidate == current || candidate.isUnknown() || !MemberLookup.arityMatches(candidate, arguments.size())) { + return current; + } + if (!functions.isEmpty() && sema.lookup().takesNoFunction(candidate, functions)) { + return current; + } + if (!functions.isEmpty() && sema.lookup().takesNoFunction(current, functions)) { + return candidate; + } + return byPhase(current, candidate, arguments); + } + + private static Symbol.MethodSymbol byPhase(Symbol.MethodSymbol current, Symbol.MethodSymbol candidate, List arguments) { + for (int phase = 0; phase < 3; phase++) { + boolean currentOk = applicable(current, arguments, phase); + boolean candidateOk = applicable(candidate, arguments, phase); + if (currentOk && !candidateOk) { + return current; + } + if (candidateOk && !currentOk) { + return candidate; + } + if (currentOk) { + return moreSpecific(candidate, current) && !moreSpecific(current, candidate) ? candidate : current; + } + } return current; } - /** - * The most specific variable-arity overload of {@code chosen} applicable to the arguments. - * @param arguments types of the arguments, used once ranking lands - */ - JMethodSymbol mostSpecificVarArgs(JMethodSymbol chosen, List arguments) { + /** The most specific variable-arity overload of {@code chosen} applicable to the arguments, when no earlier phase applies to {@code chosen}. */ + static JMethodSymbol mostSpecificVarArgs(JMethodSymbol chosen, List arguments) { + if (chosen.isUnknown() || !chosen.isVarArgsMethod() || !(chosen.owner() instanceof JTypeSymbol owner) || owner.isDeclaredInDocument() + || applicable(chosen, arguments, 0) || applicable(chosen, arguments, 1) || arguments.stream().anyMatch(Type::isUnknown)) { + return chosen; + } + List candidates = new ArrayList<>(); + for (Symbol member : owner.lookupSymbols(chosen.name())) { + if (member instanceof JMethodSymbol method && !method.isUnknown() && method.isVarArgsMethod() && method.isStatic() == chosen.isStatic() && applicable(method, arguments, 2)) { + candidates.add(method); + } + } + for (JMethodSymbol candidate : candidates) { + if (candidates.stream().allMatch(other -> other == candidate || moreSpecificVarArgs(candidate, other, arguments.size()))) { + return candidate; + } + } return chosen; } + private static boolean moreSpecificVarArgs(Symbol.MethodSymbol method, Symbol.MethodSymbol other, int count) { + for (int i = 0; i < Math.max(count, Math.max(method.parameterTypes().size(), other.parameterTypes().size())); i++) { + if (!expanded(method, i).erasure().isSubtypeOf(expanded(other, i).erasure())) { + return false; + } + } + return true; + } + + private static Type expanded(Symbol.MethodSymbol method, int index) { + List parameters = method.parameterTypes(); + return index < parameters.size() - 1 ? parameters.get(index) : ((Type.ArrayType) parameters.get(parameters.size() - 1)).elementType(); + } + static boolean applicable(Symbol.MethodSymbol method, List arguments, int phase) { List parameters = method.parameterTypes(); int count = parameters.size(); diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/OverriddenMethods.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/OverriddenMethods.java index c83ea797c62..0bf019e05d6 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/OverriddenMethods.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/OverriddenMethods.java @@ -16,6 +16,8 @@ */ package org.sonar.java.semsitter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -23,7 +25,13 @@ import javax.annotation.Nullable; import org.sonar.plugins.java.api.semantic.Symbol; import org.sonar.plugins.java.api.semantic.Symbol.MethodSymbol; +import org.sonar.plugins.java.api.semantic.SymbolMetadata; import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.ParameterizedTypeTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.TypeTree; /** Finds the methods a method overrides, walking the supertypes of its class. */ final class OverriddenMethods { @@ -69,12 +77,81 @@ private void walk(List found, Set visited, @Nullable Type private void match(List found, JTypeSymbol parent, @Nullable Type declaring) { for (Symbol member : parent.membersNamed(symbol.name())) { if (member instanceof JMethodSymbol method && !method.isStatic() && !method.isPrivate() && sameSignature(method, declaring)) { - found.add(method); + found.add(withWrittenTypeArgument(method, declaring)); return; } } } + /** + * A method returning a class type variable, seen through a supertype written with an annotated type argument + * ({@code Converter}), carries that annotation as the nullability of its result. + */ + private MethodSymbol withWrittenTypeArgument(JMethodSymbol library, @Nullable Type declaring) { + if (declaring == null) { + return library; + } + Integer position = returnedClassVariable(library, declaring); + SymbolMetadata metadata = position == null ? null : writtenArgumentMetadata(declaring, position); + if (metadata == null) { + return library; + } + return (MethodSymbol) Proxy.newProxyInstance(MethodSymbol.class.getClassLoader(), new Class[] {MethodSymbol.class}, (proxy, method, arguments) -> { + if ("metadata".equals(method.getName()) && method.getParameterCount() == 0) { + return metadata; + } + if ("equals".equals(method.getName()) && method.getParameterCount() == 1) { + return proxy == arguments[0] || library.equals(arguments[0]); + } + try { + return method.invoke(library, arguments); + } catch (InvocationTargetException e) { + throw e.getCause(); + } + }); + } + + /** The annotations of the type argument at {@code position} of {@code declaring}: as written in this class, or as a supertype states it. */ + @Nullable + private SymbolMetadata writtenArgumentMetadata(Type declaring, int position) { + JTypeSymbol owner = (JTypeSymbol) symbol.owner(); + if (owner.declaration() instanceof ClassTree classTree) { + List supertypes = new ArrayList<>(classTree.superInterfaces()); + if (classTree.superClass() != null) { + supertypes.add(classTree.superClass()); + } + for (TypeTree supertype : supertypes) { + if (supertype instanceof ParameterizedTypeTree parameterized && parameterized.symbolType().erasure().fullyQualifiedName().equals(declaring.erasure().fullyQualifiedName()) + && position < parameterized.typeArguments().size() + && JSymbolMetadata.isAnnotatedType(parameterized.typeArguments().get(position))) { + return JSymbolMetadata.ofTypeTree(sema, parameterized.typeArguments().get(position)); + } + } + } + List declared = sema.annotationFacts().supertypeArgumentAnnotations(owner.type(), declaring, position); + return declared.isEmpty() ? null : JSymbolMetadata.ofDeclared(sema, declared); + } + + /** The position, among the type variables of its class, of the one the method returns. */ + @Nullable + private Integer returnedClassVariable(JMethodSymbol method, Type declaring) { + if (method.returnTypeParameter() != null) { + return method.returnTypeParameter(); + } + if (method.declaration() == null) { + return sema.substitution().returnedClassVariable(method, declaring); + } + if (method.declaration() instanceof MethodTree tree && tree.returnType() instanceof IdentifierTree returned + && method.owner().declaration() instanceof ClassTree parentClass) { + for (int i = 0; i < parentClass.typeParameters().size(); i++) { + if (parentClass.typeParameters().get(i).identifier().name().equals(returned.name())) { + return i; + } + } + } + return null; + } + private boolean viaClassVariable(JMethodSymbol library, int index, Type declaring, String mine) { Type argument = sema.substitution().classVariableArgument(library, index, declaring); return argument != null && mine.equals(argument.erasure().fullyQualifiedName()); diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterApi.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterApi.java index cebd73d1696..a33a132e78a 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterApi.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterApi.java @@ -29,7 +29,7 @@ public interface SemSitterApi extends AutoCloseable { void setSettings(Map> settings) throws IOException; - int fullGen(Collection files) throws IOException; + FullGenStats fullGen(Collection files) throws IOException; Document getFile(String path, int ahead) throws IOException; diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterClient.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterClient.java index 92e01cffdb9..a680c00f6e9 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterClient.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterClient.java @@ -34,6 +34,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; import org.sonarsource.semsitter.wire.Document; /** @@ -102,17 +103,25 @@ public void setSettings(Map> settings) throws IOException { /** * Scans {@code files}, or the source roots when empty. - * @return how many files the server scanned + * @return how many files the server scanned, with the measures it reports */ @Override - public int fullGen(Collection files) throws IOException { + public FullGenStats fullGen(Collection files) throws IOException { JsonObject request = request("full-gen"); if (!files.isEmpty()) { JsonArray array = new JsonArray(); files.forEach(array::add); request.add("files", array); } - return send(request).get("files").getAsInt(); + JsonObject header = send(request); + return new FullGenStats(header.get("files").getAsInt(), longOrNull(header, "elapsed_ms"), longOrNull(header, "failures"), + longOrNull(header, "peak_rss_kb")); + } + + @Nullable + private static Long longOrNull(JsonObject header, String name) { + JsonElement value = header.get(name); + return value == null || value.isJsonNull() ? null : value.getAsLong(); } @Override diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterFlag.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterFlag.java new file mode 100644 index 00000000000..ff006da5537 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterFlag.java @@ -0,0 +1,39 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import org.sonar.api.config.Configuration; + +/** + * The switch that turns the SemSitter frontend on for an analysis. The feature flag itself lives in SonarQube Cloud, which + * sends its value to the analyzer as the context property {@value #ENABLED_PROPERTY}. The analyzer never evaluates a flag and + * never reaches out to a flag service: an absent property means {@link #DEFAULT}. + * + *

{@value #ENABLED_PROPERTY} is a contract with SonarQube Cloud. Renaming it requires the same change there. + */ +public final class SemSitterFlag { + + public static final String ENABLED_PROPERTY = "sonar.java.internal.semsitter.enabled"; + static final boolean DEFAULT = false; + + private SemSitterFlag() { + } + + public static boolean isEnabled(Configuration configuration) { + return configuration.getBoolean(ENABLED_PROPERTY).orElse(DEFAULT); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterFullSources.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterFullSources.java new file mode 100644 index 00000000000..c3a456551ad --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterFullSources.java @@ -0,0 +1,85 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Stream; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.config.Configuration; + +/** + * The files and directories that hold the full sources of a project, for an analysis that reports on fewer files, typically a + * single one chosen with {@code sonar.sources} or {@code sonar.tests}. The SemSitter server builds its graph from them, so + * the types of the analyzed files resolve against the whole project. Only the SemSitter frontend can use them. + * + *

The property name is a contract with the callers that send it. It is defined here only. + */ +public final class SemSitterFullSources { + + public static final String PROPERTY = "sonar.java.internal.semsitter.fullSources"; + + private SemSitterFullSources() { + } + + /** The non-blank entries of {@value #PROPERTY}, as written: comma-separated, absolute or relative to the module base directory. */ + public static List entries(Configuration configuration) { + return Arrays.stream(configuration.getStringArray(PROPERTY)).filter(entry -> !entry.isBlank()).toList(); + } + + /** + * @return the Java files of the entries: a file stands for itself, a directory for the {@code .java} files below it + * @throws IllegalStateException when an entry does not exist + */ + static Set javaFiles(List entries, Path moduleBaseDirectory) { + Set files = new LinkedHashSet<>(); + for (String entry : entries) { + Path path = moduleBaseDirectory.resolve(entry).toAbsolutePath().normalize(); + if (Files.isDirectory(path)) { + files.addAll(javaFilesBelow(path)); + } else if (Files.isRegularFile(path)) { + files.add(path); + } else { + throw new IllegalStateException(PROPERTY + " names " + path + ", which does not exist."); + } + } + return files; + } + + private static List javaFilesBelow(Path directory) { + try (Stream paths = Files.walk(directory)) { + return paths.filter(path -> Files.isRegularFile(path) && path.getFileName().toString().endsWith(".java")).toList(); + } catch (IOException failure) { + throw new UncheckedIOException("Cannot list the sources below " + directory, failure); + } + } + + /** The directory that {@code sonar.sources} is relative to, found by removing the relative path of the file from its path. */ + static Path moduleBaseDirectory(InputFile file) { + Path base = file.path(); + for (int depth = Path.of(file.relativePath()).getNameCount(); depth > 0; depth--) { + base = base.getParent(); + } + return base; + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java index c102822859a..029dcbaa40b 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java @@ -29,9 +29,11 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Comparator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.concurrent.CancellationException; +import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; import java.util.function.BooleanSupplier; import javax.annotation.Nullable; @@ -47,9 +49,10 @@ /** * The {@link JParser} backed by a SemSitter server. One server serves one call of {@link #parse}: it is started on the - * common directory of the files, scans them all, and answers one document per file, which the {@link DocumentTranslator} - * turns into the tree the checks run on. This frontend never hands files to another one: a server that cannot start - * fails the analysis, and a file the translator does not support yet is reported as a parse error. + * common directory of the files and of the {@link SemSitterFullSources full sources}, builds its graph from them all, and + * answers one document per analyzed file, which the {@link DocumentTranslator} turns into the tree the checks run on. Without + * full sources, the graph is built from the analyzed files only. This frontend never hands files to another one: a server + * that cannot start fails the analysis, and a file the translator does not support yet is reported as a parse error. */ public final class SemSitterParser implements JParser { @@ -69,18 +72,30 @@ public interface Launcher { private final Launcher launcher; private final DocumentTranslator translator; private final Path javaHome; + private final List fullSources; public SemSitterParser(Mode mode, JavaVersion javaVersion, List classpath, Launcher launcher, DocumentTranslator translator) { - this(mode, javaVersion, classpath, launcher, translator, Path.of(System.getProperty("java.home"))); + this(mode, javaVersion, classpath, launcher, translator, List.of()); + } + + public SemSitterParser(Mode mode, JavaVersion javaVersion, List classpath, Launcher launcher, DocumentTranslator translator, + List fullSources) { + this(mode, javaVersion, classpath, launcher, translator, Path.of(System.getProperty("java.home")), fullSources); } SemSitterParser(Mode mode, JavaVersion javaVersion, List classpath, Launcher launcher, DocumentTranslator translator, Path javaHome) { + this(mode, javaVersion, classpath, launcher, translator, javaHome, List.of()); + } + + SemSitterParser(Mode mode, JavaVersion javaVersion, List classpath, Launcher launcher, DocumentTranslator translator, Path javaHome, + List fullSources) { this.mode = mode; this.javaVersion = javaVersion; this.classpath = classpath; this.launcher = launcher; this.translator = translator; this.javaHome = javaHome; + this.fullSources = fullSources; } @Override @@ -90,10 +105,14 @@ public void parse(Iterable inputFiles, BooleanSupplier isCanceled, An if (files.isEmpty()) { return; } - Path root = ProjectRoot.commonAncestor(files.stream().map(InputFile::path).toList()) + long walkStart = System.nanoTime(); + Set graphFiles = new LinkedHashSet<>(files.stream().map(file -> file.path().toAbsolutePath().normalize()).toList()); + graphFiles.addAll(SemSitterFullSources.javaFiles(fullSources, SemSitterFullSources.moduleBaseDirectory(files.getFirst()))); + long walkMs = millisSince(walkStart); + Path root = ProjectRoot.commonAncestor(graphFiles) .orElseThrow(() -> new IllegalStateException("The files share no directory to start the SemSitter server on.")); files.sort(Comparator.comparing(file -> ProjectRoot.relative(root, file.path()))); - scan(open(root, files), files, isCanceled, analysisProgress, action); + scan(open(root, graphFiles, walkMs), files, isCanceled, analysisProgress, action); } private void scan(Session session, List files, BooleanSupplier isCanceled, AnalysisProgress analysisProgress, @@ -135,12 +154,25 @@ private static JParseResult translate(Session session, InputFile file) { } } - private Session open(Path root, List files) { + /** + * Starts the server and builds its graph, then logs how long each step took: {@code walkMs} is the time spent listing + * the files of the graph, measured by the caller. + */ + private Session open(Path root, Set graphFiles, long walkMs) { SemSitterApi api = null; try { + long startNanos = System.nanoTime(); api = launcher.start(root); + long settingsNanos = System.nanoTime(); api.setSettings(SemSitterSettings.of(javaVersion, classpath, javaHome)); - api.fullGen(files.stream().map(file -> ProjectRoot.relative(root, file.path())).toList()); + long fullGenNanos = System.nanoTime(); + FullGenStats stats = api.fullGen(graphFiles.stream().map(file -> ProjectRoot.relative(root, file)).sorted().toList()); + long endNanos = System.nanoTime(); + LOG.info("SemSitter graph of {} files built in {} ms (walk {} ms, server start {} ms, settings {} ms, full-gen {} ms; " + + "server-reported {} ms, {} failures, peak RSS {} MB)", + stats.files(), walkMs + toMillis(endNanos - startNanos), walkMs, toMillis(settingsNanos - startNanos), + toMillis(fullGenNanos - settingsNanos), toMillis(endNanos - fullGenNanos), + orUnknown(stats.elapsedMs()), orUnknown(stats.failures()), orUnknown(megabytes(stats.peakRssKb()))); return new Session(api, root, javaVersion.isNotSet() ? Integer.MAX_VALUE : javaVersion.asInt(), classpath.isEmpty(), translator); } catch (IOException | RuntimeException e) { if (api != null) { @@ -150,6 +182,23 @@ private Session open(Path root, List files) { } } + private static long millisSince(long startNanos) { + return toMillis(System.nanoTime() - startNanos); + } + + private static long toMillis(long nanos) { + return TimeUnit.NANOSECONDS.toMillis(nanos); + } + + @Nullable + private static Long megabytes(@Nullable Long kilobytes) { + return kilobytes == null ? null : (kilobytes / 1024); + } + + private static Object orUnknown(@Nullable Long value) { + return value == null ? "n/a" : value; + } + /** The open server and what parsing one file against it needs. */ private static final class Session implements AutoCloseable, DocumentTranslator.ServerLoaders { private final SemSitterApi api; diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParserProvider.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParserProvider.java new file mode 100644 index 00000000000..79308799eb0 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParserProvider.java @@ -0,0 +1,126 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.io.File; +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; +import java.util.function.UnaryOperator; +import javax.annotation.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonar.api.SonarRuntime; +import org.sonar.api.config.Configuration; +import org.sonar.java.model.JParser; +import org.sonar.java.model.JParserProvider; +import org.sonar.plugins.java.api.JavaVersion; + +/** + * Offers the SemSitter frontend when {@link SemSitterFlag} is on, that is when SonarQube Cloud sent + * {@value SemSitterFlag#ENABLED_PROPERTY}, or when the analysis runs where a {@link BundledServer} is expected: the + * performance validation and SonarQube Cloud, where the frontend is always on. An analysis that asks for the SemSitter frontend + * gets it or fails: it fails when no SemSitter executable is known, and never falls back to another frontend. So does + * {@value SemSitterFullSources#PROPERTY} when the frontend is not in use. Once chosen, the SemSitter frontend never hands files + * to another frontend. + */ +public final class SemSitterParserProvider implements JParserProvider { + + public static final String EXECUTABLE_PROPERTY = "sonar.java.semsitter.executable"; + public static final String EXECUTABLE_ENVIRONMENT = "SEMSITTER_ANALYZER"; + + private static final Logger LOG = LoggerFactory.getLogger(SemSitterParserProvider.class); + + private final UnaryOperator environment; + private final DocumentTranslator translator; + private final Function> bundledServer; + private volatile boolean enabled; + private final AtomicReference> fullSources = new AtomicReference<>(List.of()); + private final AtomicReference executable = new AtomicReference<>(); + + public SemSitterParserProvider() { + this(System::getenv, SemSitterTranslator::translate, BundledServer::extract); + } + + SemSitterParserProvider(UnaryOperator environment, DocumentTranslator translator, Function> bundledServer) { + this.environment = environment; + this.translator = translator; + this.bundledServer = bundledServer; + } + + @Override + public void configure(Configuration configuration) { + start(configuration, null); + } + + @Override + public void configure(Configuration configuration, SonarRuntime runtime) { + start(configuration, runtime); + } + + /** A configured executable is used as is. The bundled server is the one of a runtime where it is expected, and is used even if the flag is off. */ + private void start(Configuration configuration, @Nullable SonarRuntime runtime) { + enabled = false; + executable.set(null); + fullSources.set(List.of()); + List entries = SemSitterFullSources.entries(configuration); + Optional configured = configuredExecutable(configuration).map(Path::of); + Optional bundled = configured.isPresent() || runtime == null ? Optional.empty() : bundledServer.apply(runtime); + if (bundled.isEmpty() && !SemSitterFlag.isEnabled(configuration)) { + rejectFullSources(entries); + return; + } + Path server = configured.or(() -> bundled).orElseThrow(() -> new IllegalStateException( + "The SemSitter frontend is turned on by " + SemSitterFlag.ENABLED_PROPERTY + " but no SemSitter executable is known: set " + + EXECUTABLE_PROPERTY + " or the environment variable " + EXECUTABLE_ENVIRONMENT)); + executable.set(server); + fullSources.set(entries); + enabled = true; + LOG.info("The Java analyzer will use the SemSitter frontend with the {} server {}.", bundled.isPresent() ? "bundled" : "configured", server); + } + + List fullSources() { + return fullSources.get(); + } + + private static void rejectFullSources(List entries) { + if (!entries.isEmpty()) { + throw new IllegalStateException(SemSitterFullSources.PROPERTY + " is set but the SemSitter frontend is not in use: only the SemSitter frontend " + + "can build its graph from sources other than the analyzed files."); + } + } + + /** The non-blank {@value #EXECUTABLE_PROPERTY}, or else the non-blank environment variable {@value #EXECUTABLE_ENVIRONMENT}. */ + private Optional configuredExecutable(Configuration configuration) { + Optional fromVariable = Optional.ofNullable(environment.apply(EXECUTABLE_ENVIRONMENT)).filter(value -> !value.isBlank()); + return configuration.get(EXECUTABLE_PROPERTY).filter(value -> !value.isBlank()).or(() -> fromVariable); + } + + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public JParser create(JParser.Mode mode, JavaVersion javaVersion, List classpath, boolean shouldIgnoreUnnamedModuleForSplitPackage, + boolean shouldUseJdkReleaseOption) { + Path server = executable.get(); + return new SemSitterParser(mode, javaVersion, classpath, root -> SemSitterClient.start(server, root), translator, fullSources.get()); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterTranslator.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterTranslator.java new file mode 100644 index 00000000000..2a4addbc64a --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterTranslator.java @@ -0,0 +1,354 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import com.google.gson.JsonObject; +import com.sonar.sslr.api.RecognitionException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.function.Function; +import javax.annotation.Nullable; +import org.sonar.java.ast.parser.ModuleNameListTreeImpl; +import org.sonar.java.ast.parser.ModuleNameTreeImpl; +import org.sonar.java.ast.parser.QualifiedIdentifierListTreeImpl; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.InternalSyntaxTrivia; +import org.sonar.java.model.JParseResult; +import org.sonar.java.model.JavaTree; +import org.sonar.java.model.declaration.ClassTreeImpl; +import org.sonar.java.model.declaration.ExportsDirectiveTreeImpl; +import org.sonar.java.model.declaration.ModifierKeywordTreeImpl; +import org.sonar.java.model.declaration.ModifiersTreeImpl; +import org.sonar.java.model.declaration.ModuleDeclarationTreeImpl; +import org.sonar.java.model.declaration.OpensDirectiveTreeImpl; +import org.sonar.java.model.declaration.ProvidesDirectiveTreeImpl; +import org.sonar.java.model.declaration.RequiresDirectiveTreeImpl; +import org.sonar.java.model.declaration.UsesDirectiveTreeImpl; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.java.model.expression.MemberSelectExpressionTreeImpl; +import org.sonar.java.model.statement.EmptyStatementTreeImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.tree.AnnotationTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.ImportClauseTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.Modifier; +import org.sonar.plugins.java.api.tree.ModifierTree; +import org.sonar.plugins.java.api.tree.ModuleDeclarationTree; +import org.sonar.plugins.java.api.tree.ModuleDirectiveTree; +import org.sonar.plugins.java.api.tree.SyntaxTrivia; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeTree; +import org.sonarsource.semsitter.wire.Document; + +import static org.sonar.java.semsitter.CstNodes.childKind; +import static org.sonar.java.semsitter.CstNodes.collectLeaves; +import static org.sonar.java.semsitter.CstNodes.dottedName; +import static org.sonar.java.semsitter.CstNodes.firstNamed; +import static org.sonar.java.semsitter.CstNodes.firstOf; +import static org.sonar.java.semsitter.CstNodes.firstProblem; +import static org.sonar.java.semsitter.CstNodes.isComment; +import static org.sonar.java.semsitter.CstNodes.keyword; +import static org.sonar.java.semsitter.CstNodes.lastKeyword; +import static org.sonar.java.semsitter.CstNodes.lastNamed; +import static org.sonar.java.semsitter.CstNodes.required; +import static org.sonar.java.semsitter.CstNodes.requiredField; +import static org.sonar.java.semsitter.CstNodes.setParents; + +/** + * Builds the SonarJava AST from one SemSitter CST document. + * Positions come from the CST. Symbols and types come from {@link JSema}. + */ +final class SemSitterTranslator extends TranslatorPart { + private static final String MODULE = "module"; + private static final String PACKAGE = "package"; + + private SemSitterTranslator(JSema sema) { + super(new TranslationState(sema)); + } + + static JParseResult translate(Document document, DocumentTranslator.ServerLoaders loaders, boolean noLibraries, int javaVersion) { + return translate(document, loaders::types, loaders::hasPackage, noLibraries, javaVersion); + } + + static JParseResult translate(Document document, Function, JsonObject> types, Function packages, boolean noLibraries, + int javaVersion) { + JSema sema = new JSema(); + sema.noLibraries(noLibraries); + sema.ingestDocument(document); + sema.loadTypes(types); + sema.loadPackages(packages); + return JParseResult.success(translate(sema, document, javaVersion)); + } + + private static JavaTree.CompilationUnitTreeImpl translate(JSema sema, Document document, int javaVersion) { + boolean broken = document.getHasError(); + SemSitterTranslator translator = new SemSitterTranslator(sema); + translator.state.unnamedVariables = javaVersion >= 22; + translator.state.records = javaVersion >= 16; + translator.state.markdownComments = javaVersion >= 23; + if (!document.getPath().isEmpty()) { + String fileName = Path.of(document.getPath()).getFileName().toString(); + translator.state.implicitClassName = fileName.endsWith(".java") ? fileName.substring(0, fileName.length() - 5) : fileName; + } + CstNode root = new CstNode(document.getTree()); + if (broken) { + CstNode problem = firstProblem(root); + int line = problem == null ? 1 : problem.line(); + int column = problem == null ? 1 : (problem.col() + 1); + throw new RecognitionException(line, String.format("Parse error at line %d column %d: Syntax error", line, column)); + } + translator.indexTokens(root); + translator.declareGenericReturns(root); + JavaTree.CompilationUnitTreeImpl unit = translator.compilationUnit(root); + translator.state.deferred.forEach(Runnable::run); + unit.setSemanticModel(sema, sema.undefinedTypes(), sema.getEnvironmentCleaner()); + setParents(unit); + CompilerWarnings.addTo(unit); + EffectivelyFinalVariables.mark(unit); + return unit; + } + + private void indexTokens(CstNode root) { + List leaves = new ArrayList<>(); + collectLeaves(root, leaves); + List pending = new ArrayList<>(); + for (CstNode leaf : leaves) { + if (isComment(leaf)) { + SyntaxTrivia previous = pending.isEmpty() ? null : pending.get(pending.size() - 1); + if (state.markdownComments && previous != null && previous.isComment(SyntaxTrivia.CommentKind.MARKDOWN) && leaf.text().startsWith("///") + && previous.range().end().line() + 1 == leaf.line()) { + pending.set(pending.size() - 1, new InternalSyntaxTrivia(SyntaxTrivia.CommentKind.MARKDOWN, + previous.comment() + "\n" + " ".repeat(leaf.col()) + trivia(leaf).comment(), previous.range().start().line(), previous.range().start().columnOffset())); + } else { + pending.add(trivia(leaf)); + } + } else { + state.tokens.put(leaf.proto, new InternalSyntaxToken(leaf.line(), leaf.col(), leaf.text(), pending, false)); + pending = new ArrayList<>(); + } + } + state.eof = new InternalSyntaxToken(root.proto.getEndLine(), root.proto.getEndCol(), "", pending, true); + } + + private JavaTree.CompilationUnitTreeImpl compilationUnit(CstNode program) { + JavaTree.PackageDeclarationTreeImpl packageDeclaration = null; + List imports = new ArrayList<>(); + List types = new ArrayList<>(); + List compactMembers = new ArrayList<>(); + ModuleDeclarationTree module = null; + boolean[] compact = {false}; + for (CstNode child : program.children()) { + TopLevel collected = addTopLevel(child, imports, types, compactMembers, compact[0]); + packageDeclaration = collected.packageDeclaration == null ? packageDeclaration : collected.packageDeclaration; + module = collected.module == null ? module : collected.module; + compact[0] = collected.compact; + } + if (compact[0]) { + ClassTreeImpl implicitClass = new ClassTreeImpl(Tree.Kind.IMPLICIT_CLASS, null, compactMembers, null); + declarations().bindImplicitClass(implicitClass, compactMembers); + types.add(implicitClass); + } + return new JavaTree.CompilationUnitTreeImpl(packageDeclaration, imports, types, module, state.eof); + } + + /** One top-level construct. */ + private TopLevel addTopLevel(CstNode child, List imports, List types, List compactMembers, boolean compact) { + return switch (child.k()) { + case "package_declaration" -> new TopLevel(packageDeclaration(child), null, compact); + case "module_declaration" -> new TopLevel(null, moduleDeclaration(child), compact); + case "import_declaration" -> { + imports.add(importDeclaration(child)); + yield new TopLevel(null, null, compact); + } + case ";" -> { + EmptyStatementTreeImpl empty = new EmptyStatementTreeImpl(token(child)); + if (compact) { + compactMembers.add(empty); + } else if (types.isEmpty()) { + imports.add(empty); + } else { + types.add(empty); + } + yield new TopLevel(null, null, compact); + } + case "class_declaration", "interface_declaration", "enum_declaration", "record_declaration", "annotation_type_declaration" -> { + declarations().addMember(compact ? compactMembers : types, child); + yield new TopLevel(null, null, compact); + } + case "method_declaration", "constructor_declaration", "field_declaration", "constant_declaration", "local_variable_declaration", "static_initializer", "block" -> { + if (!compact) { + compact = true; + compactMembers.addAll(types); + types.clear(); + } + declarations().addMember(compactMembers, child); + yield new TopLevel(null, null, compact); + } + default -> new TopLevel(null, null, compact); + }; + } + + private record TopLevel(@Nullable JavaTree.PackageDeclarationTreeImpl packageDeclaration, @Nullable ModuleDeclarationTree module, boolean compact) { + } + + private ModuleDeclarationTreeImpl moduleDeclaration(CstNode node) { + CstNode body = requiredField(node, "body", childKind(node, "module_body")); + List directives = new ArrayList<>(); + for (CstNode child : body.children()) { + if (child.k().endsWith("_module_directive")) { + directives.add(moduleDirective(child)); + } + } + return new ModuleDeclarationTreeImpl( + node.children().stream().filter(CstNodes::isAnnotation).map(members()::annotation).toList(), + optionalToken(node, "open"), + token(required(node, MODULE)), + moduleName(requiredField(node, "name", firstNamed(node))), + token(required(body, "{")), + directives, + token(required(body, "}"))); + } + + private ModuleDirectiveTree moduleDirective(CstNode node) { + InternalSyntaxToken keyword = token(node.children().get(0)); + InternalSyntaxToken semicolon = token(required(node, ";")); + return switch (node.k()) { + case "requires_module_directive" -> + new RequiresDirectiveTreeImpl(keyword, requiresModifiers(node), moduleName(requiredField(node, MODULE, lastNamed(node))), semicolon); + case "exports_module_directive" -> new ExportsDirectiveTreeImpl(keyword, directivePackage(node), optionalToken(node, "to"), moduleNames(node), semicolon); + case "opens_module_directive" -> new OpensDirectiveTreeImpl(keyword, directivePackage(node), optionalToken(node, "to"), moduleNames(node), semicolon); + case "uses_module_directive" -> new UsesDirectiveTreeImpl(keyword, (TypeTree) expressions().expression(requiredField(node, "type", firstNamed(node))), semicolon); + default -> new ProvidesDirectiveTreeImpl(keyword, (TypeTree) expressions().expression(requiredField(node, "provided", firstNamed(node))), + token(required(node, "with")), providers(node), semicolon); + }; + } + + private ExpressionTree directivePackage(CstNode node) { + return expressions().expression(requiredField(node, PACKAGE, firstNamed(node))); + } + + private ModifiersTreeImpl requiresModifiers(CstNode node) { + List modifiers = new ArrayList<>(); + for (CstNode child : node.children()) { + if ("requires_modifier".equals(child.k())) { + CstNode keyword = child.children().get(0); + modifiers.add(new ModifierKeywordTreeImpl("static".equals(keyword.text()) ? Modifier.STATIC : Modifier.TRANSITIVE, token(keyword))); + } + } + return new ModifiersTreeImpl(modifiers); + } + + private ModuleNameListTreeImpl moduleNames(CstNode node) { + ModuleNameListTreeImpl names = ModuleNameListTreeImpl.emptyList(); + for (CstNode child : node.children()) { + if ("modules".equals(child.f())) { + names.add(moduleName(child)); + } else if (",".equals(child.text())) { + names.separators().add(token(child)); + } + } + return names; + } + + private QualifiedIdentifierListTreeImpl providers(CstNode node) { + QualifiedIdentifierListTreeImpl providers = QualifiedIdentifierListTreeImpl.emptyList(); + boolean afterWith = false; + for (CstNode child : node.children()) { + if ("with".equals(child.text())) { + afterWith = true; + } else if (",".equals(child.text())) { + providers.separators().add(token(child)); + } else if (afterWith && !";".equals(child.text())) { + providers.add((TypeTree) expressions().expression(child)); + } + } + return providers; + } + + private ModuleNameTreeImpl moduleName(CstNode node) { + ModuleNameTreeImpl name = ModuleNameTreeImpl.emptyList(); + addModuleName(name, node); + return name; + } + + private void addModuleName(ModuleNameTreeImpl name, CstNode node) { + if ("scoped_identifier".equals(node.k())) { + addModuleName(name, requiredField(node, "scope", firstNamed(node))); + name.add(new IdentifierTreeImpl(token(requiredField(node, "name", lastNamed(node))))); + } else { + name.add(new IdentifierTreeImpl(token(node))); + } + } + + private JavaTree.PackageDeclarationTreeImpl packageDeclaration(CstNode node) { + state.naming = true; + ExpressionTree name = expressions().expression(requiredField(node, "name", firstOf(node, "scoped_identifier", "identifier"))); + state.naming = false; + state.packageName = dottedName(name); + names().bindPackage(name, state.packageName); + return new JavaTree.PackageDeclarationTreeImpl(members().annotations(node), token(required(node, PACKAGE)), name, token(required(node, ";"))); + } + + private JavaTree.ImportTreeImpl importDeclaration(CstNode node) { + InternalSyntaxToken staticToken = optionalToken(node, "static"); + state.naming = true; + ExpressionTree name = expressions().expression(requiredField(node, "name", firstNamed(node))); + state.naming = false; + CstNode star = keyword(node, "asterisk"); + if (star != null) { + (staticToken == null ? state.imports.onDemandImports : state.imports.staticOnDemandImports).add(dottedName(name)); + name = new MemberSelectExpressionTreeImpl(name, token(lastKeyword(node, ".")), new IdentifierTreeImpl(token(star))); + } else if (name instanceof MemberSelectExpressionTree select) { + if (staticToken == null) { + state.imports.singleImports.putIfAbsent(select.identifier().name(), dottedName(name)); + } else { + state.imports.staticImports.putIfAbsent(select.identifier().name(), dottedName(select.expression())); + } + } + JavaTree.ImportTreeImpl imported = new JavaTree.ImportTreeImpl(token(required(node, "import")), staticToken, optionalToken(node, MODULE), name, token(required(node, ";"))); + if (staticToken == null && name instanceof MemberSelectExpressionTree select && !"*".equals(select.identifier().name())) { + String fqn = dottedName(name); + if (sema.declaresType(fqn) && sema.resolve(fqn) instanceof Symbol.TypeSymbol type) { + imported.setSymbol(type); + } else if (!imported.isModule()) { + imported.setSymbol(Symbol.TypeSymbol.UNKNOWN_TYPE); + } + } + return imported; + } + + private SyntaxTrivia trivia(CstNode node) { + String text = node.text(); + if (text.startsWith("//") && text.endsWith("\r")) { + text = text.substring(0, text.length() - 1); + } + SyntaxTrivia.CommentKind kind; + if (state.markdownComments && text.startsWith("///")) { + kind = SyntaxTrivia.CommentKind.MARKDOWN; + } else if (text.startsWith("/**") && !"/**/".equals(text)) { + kind = SyntaxTrivia.CommentKind.JAVADOC; + } else if (text.startsWith("//")) { + kind = SyntaxTrivia.CommentKind.LINE; + } else { + kind = SyntaxTrivia.CommentKind.BLOCK; + } + return new InternalSyntaxTrivia(kind, text, node.line(), node.col()); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemaParts.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemaParts.java index 7b405d81369..447c067af78 100644 --- a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemaParts.java +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemaParts.java @@ -30,13 +30,13 @@ final class SemaParts { SemaParts(JSema sema) { annotationFacts = new SemaAnnotations(sema); - inference = new Inference(); - functionalInference = new FunctionalInference(); + inference = new Inference(sema); + functionalInference = new FunctionalInference(sema); substitution = new Substitution(sema); libraryMembers = new LibraryMembers(sema); memberFactory = new MemberFactory(sema); lookup = new MemberLookup(sema); - overloads = new OverloadRanking(); + overloads = new OverloadRanking(sema); factTypes = new FactTypes(sema); } } diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/StatementTranslator.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/StatementTranslator.java new file mode 100644 index 00000000000..f78bef49e42 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/StatementTranslator.java @@ -0,0 +1,424 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Objects; +import javax.annotation.Nullable; +import org.sonar.java.ast.parser.StatementListTreeImpl; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.JLabelSymbol; +import org.sonar.java.model.declaration.VariableTreeImpl; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.java.model.expression.MemberSelectExpressionTreeImpl; +import org.sonar.java.model.expression.MethodInvocationTreeImpl; +import org.sonar.java.model.expression.NewClassTreeImpl; +import org.sonar.java.model.statement.AssertStatementTreeImpl; +import org.sonar.java.model.statement.BlockTreeImpl; +import org.sonar.java.model.statement.BreakStatementTreeImpl; +import org.sonar.java.model.statement.ContinueStatementTreeImpl; +import org.sonar.java.model.statement.DoWhileStatementTreeImpl; +import org.sonar.java.model.statement.EmptyStatementTreeImpl; +import org.sonar.java.model.statement.ExpressionStatementTreeImpl; +import org.sonar.java.model.statement.ForEachStatementImpl; +import org.sonar.java.model.statement.ForStatementTreeImpl; +import org.sonar.java.model.statement.IfStatementTreeImpl; +import org.sonar.java.model.statement.LabeledStatementTreeImpl; +import org.sonar.java.model.statement.ReturnStatementTreeImpl; +import org.sonar.java.model.statement.SynchronizedStatementTreeImpl; +import org.sonar.java.model.statement.ThrowStatementTreeImpl; +import org.sonar.java.model.statement.WhileStatementTreeImpl; +import org.sonar.java.model.statement.YieldStatementTreeImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.StatementTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeTree; + +import static org.sonar.java.semsitter.Bindings.ascribe; +import static org.sonar.java.semsitter.Bindings.bindMethod; +import static org.sonar.java.semsitter.CstNodes.childKind; +import static org.sonar.java.semsitter.CstNodes.field; +import static org.sonar.java.semsitter.CstNodes.firstNamed; +import static org.sonar.java.semsitter.CstNodes.firstOf; +import static org.sonar.java.semsitter.CstNodes.firstType; +import static org.sonar.java.semsitter.CstNodes.lastKeyword; +import static org.sonar.java.semsitter.CstNodes.lastNamed; +import static org.sonar.java.semsitter.CstNodes.nameNode; +import static org.sonar.java.semsitter.CstNodes.required; +import static org.sonar.java.semsitter.CstNodes.requiredField; + +/** Translates blocks and statements. */ +final class StatementTranslator extends TranslatorPart { + + private static final String BLOCK = "block"; + private static final String LOCAL_VARIABLE_DECLARATION = "local_variable_declaration"; + private static final String PARENTHESIZED_EXPRESSION = "parenthesized_expression"; + private static final String CONDITION = "condition"; + + StatementTranslator(TranslationState state) { + super(state); + } + + BlockTreeImpl block(CstNode node) { + state.scopes.addFirst(new HashMap<>()); + try { + return blockInScope(node); + } finally { + state.scopes.removeFirst(); + } + } + + private BlockTreeImpl blockInScope(CstNode node) { + if (!BLOCK.equals(node.k())) { + CstNode nested = childKind(node, BLOCK); + if (nested != null) { + node = nested; + } + } + InternalSyntaxToken open = token(required(node, "{")); + InternalSyntaxToken close = token(required(node, "}")); + List statements = new ArrayList<>(); + for (CstNode child : node.children()) { + if ("{".equals(child.text()) || "}".equals(child.text())) { + continue; + } + addStatement(statements, child); + } + return new BlockTreeImpl(open, statements, close); + } + + void addStatement(List statements, CstNode node) { + if (LOCAL_VARIABLE_DECLARATION.equals(node.k())) { + statements.addAll(members().variables(node)); + return; + } + if (";".equals(node.text())) { + statements.add(new EmptyStatementTreeImpl(token(node))); + return; + } + CstNode switchNode = childKind(node, "switch_expression"); + if ("expression_statement".equals(node.k()) && switchNode != null) { + statements.add(switches().switchStatement(switchNode)); + statements.add(new EmptyStatementTreeImpl(token(required(node, ";")))); + return; + } + statements.add(statement(node)); + } + + private StatementTree statement(CstNode node) { + return switch (node.k()) { + case BLOCK -> block(node); + case "expression_statement" -> expressionStatement(node); + case "explicit_constructor_invocation" -> constructorInvocation(node); + case "if_statement" -> ifStatement(node); + case "while_statement" -> whileStatement(node); + case "do_statement" -> doStatement(node); + case "for_statement" -> forStatement(node); + case "enhanced_for_statement" -> forEach(node); + case "break_statement" -> breakStatement(node); + case "continue_statement" -> continueStatement(node); + case "return_statement" -> returnStatement(node); + case "yield_statement" -> yieldStatement(node); + case "throw_statement" -> throwStatement(node); + case "assert_statement" -> assertStatement(node); + case "labeled_statement" -> labeled(node); + case "try_statement", "try_with_resources_statement" -> switches().tryStatement(node); + case "synchronized_statement" -> synchronizedStatement(node); + case "switch_statement", "switch_expression" -> switches().switchStatement(node); + case LOCAL_VARIABLE_DECLARATION -> members().variables(node).get(0); + case "class_declaration", "interface_declaration", "enum_declaration", "record_declaration" -> declarations().typeDeclaration(node); + default -> new EmptyStatementTreeImpl(";".equals(node.text()) ? token(node) : token(required(node, ";"))); + }; + } + + ExpressionStatementTreeImpl expressionStatement(CstNode node) { + return new ExpressionStatementTreeImpl(expressions().expression(node.children().get(0)), optionalToken(node, ";")); + } + + private ExpressionStatementTreeImpl constructorInvocation(CstNode node) { + CstNode constructor = requiredField(node, "constructor", firstOf(node, "super", "this")); + IdentifierTreeImpl identifier = names().identifier(constructor); + bindUse(identifier, constructor); + CstNode object = field(node, "object"); + ExpressionTree select = object == null + ? identifier + : new MemberSelectExpressionTreeImpl(expressions().expression(object), token(required(node, ".")), identifier); + CstNode typeArguments = field(node, "type_arguments"); + MethodInvocationTreeImpl invocation = new MethodInvocationTreeImpl(select, typeArguments == null ? null : typeTrees().typeArguments(typeArguments), + expressions().arguments(requiredField(node, "arguments", childKind(node, "argument_list")))); + if (identifier.symbol() instanceof Symbol.MethodSymbol method) { + bindMethod(invocation, method); + ascribe(invocation, method.owner().type()); + ascribe(identifier, Type.UNKNOWN); + } + Symbol.TypeSymbol enclosing = state.types.peek(); + if (invocation.symbolType().isUnknown() && enclosing != null) { + Type constructed = "this".equals(identifier.name()) ? enclosing.type() : enclosing.superClass(); + ascribe(invocation, constructed == null ? Type.UNKNOWN : constructed); + } + return new ExpressionStatementTreeImpl(invocation, token(required(node, ";"))); + } + + private IfStatementTreeImpl ifStatement(CstNode node) { + Parens condition = parens(requiredField(node, CONDITION, childKind(node, PARENTHESIZED_EXPRESSION))); + CstNode alternative = field(node, "alternative"); + return new IfStatementTreeImpl( + token(required(node, "if")), + condition.open(), + condition.expr(), + condition.close(), + statement(requiredField(node, "consequence", lastNamed(node))), + alternative == null ? null : token(required(node, "else")), + alternative == null ? null : statement(alternative)); + } + + private WhileStatementTreeImpl whileStatement(CstNode node) { + Parens condition = parens(requiredField(node, CONDITION, childKind(node, PARENTHESIZED_EXPRESSION))); + return new WhileStatementTreeImpl( + token(required(node, "while")), + condition.open(), + condition.expr(), + condition.close(), + statement(requiredField(node, "body", lastNamed(node)))); + } + + private DoWhileStatementTreeImpl doStatement(CstNode node) { + Parens condition = parens(requiredField(node, CONDITION, childKind(node, PARENTHESIZED_EXPRESSION))); + return new DoWhileStatementTreeImpl( + token(required(node, "do")), + statement(requiredField(node, "body", firstNamed(node))), + token(required(node, "while")), + condition.open(), + condition.expr(), + condition.close(), + token(lastKeyword(node, ";"))); + } + + private ForStatementTreeImpl forStatement(CstNode node) { + state.scopes.addFirst(new HashMap<>()); + try { + return forStatementInScope(node); + } finally { + state.scopes.removeFirst(); + } + } + + private ForStatementTreeImpl forStatementInScope(CstNode node) { + ForClauses clauses = new ForClauses(); + for (CstNode child : node.children()) { + if (")".equals(child.text())) { + break; + } + clauses.add(child); + } + return new ForStatementTreeImpl( + token(required(node, "for")), + token(required(node, "(")), + clauses.init, + Objects.requireNonNull(clauses.firstSemicolon), + clauses.condition, + Objects.requireNonNull(clauses.secondSemicolon), + clauses.update, + token(required(node, ")")), + statement(requiredField(node, "body", lastNamed(node)))); + } + + /** Accumulates the init, condition and update clauses of a for statement while its children are visited. */ + private final class ForClauses { + private final StatementListTreeImpl init = StatementListTreeImpl.emptyList(); + private final StatementListTreeImpl update = StatementListTreeImpl.emptyList(); + @Nullable + private InternalSyntaxToken firstSemicolon = null; + @Nullable + private InternalSyntaxToken secondSemicolon = null; + @Nullable + private ExpressionTree condition = null; + private int semicolons = 0; + + void add(CstNode child) { + String text = child.text(); + if ("for".equals(text) || "(".equals(text)) { + return; + } + if (";".equals(text)) { + addSemicolon(child); + } else if (",".equals(text)) { + (semicolons == 0 ? init : update).separators().add(token(child)); + } else if (LOCAL_VARIABLE_DECLARATION.equals(child.k())) { + addDeclaration(child); + } else { + addExpression(child); + } + } + + private void addSemicolon(CstNode child) { + semicolons++; + if (semicolons == 1) { + firstSemicolon = token(child); + } else { + secondSemicolon = token(child); + } + } + + private void addDeclaration(CstNode child) { + List declared = members().variables(child); + init.addAll(declared); + declared.get(declared.size() - 1).setEndToken(null); + firstSemicolon = token(required(child, ";")); + semicolons = 1; + } + + private void addExpression(CstNode child) { + switch (semicolons) { + case 0 -> init.add(new ExpressionStatementTreeImpl(expressions().expression(child), null)); + case 1 -> condition = expressions().expression(child); + default -> update.add(new ExpressionStatementTreeImpl(expressions().expression(child), null)); + } + } + } + + private ForEachStatementImpl forEach(CstNode node) { + state.scopes.addFirst(new HashMap<>()); + try { + return forEachInScope(node); + } finally { + state.scopes.removeFirst(); + } + } + + private ForEachStatementImpl forEachInScope(CstNode node) { + TypeTree type = typeTrees().arrayType(typeTrees().type(requiredField(node, "type", firstType(node))), field(node, "dimensions")); + IdentifierTreeImpl name = names().identifier(requiredField(node, "name", firstOf(node, "identifier"))); + VariableTreeImpl variable = new VariableTreeImpl(members().modifiers(node), type, name); + bindDeclaration(variable, requiredField(node, "name", nameNode(node)), name); + return new ForEachStatementImpl( + token(required(node, "for")), + token(required(node, "(")), + variable, + token(required(node, ":")), + expressions().expression(requiredField(node, "value", firstNamed(node))), + token(required(node, ")")), + statement(requiredField(node, "body", lastNamed(node)))); + } + + private BreakStatementTreeImpl breakStatement(CstNode node) { + IdentifierTreeImpl label = labelUse(node); + return new BreakStatementTreeImpl(token(required(node, "break")), label, token(required(node, ";"))); + } + + private ContinueStatementTreeImpl continueStatement(CstNode node) { + return new ContinueStatementTreeImpl(token(required(node, "continue")), labelUse(node), token(required(node, ";"))); + } + + private ReturnStatementTreeImpl returnStatement(CstNode node) { + ExpressionTree expression = null; + for (CstNode child : node.children()) { + if (!"return".equals(child.text()) && !";".equals(child.text())) { + expression = expressions().expression(child); + } + } + if (expression instanceof NewClassTreeImpl newClass && !state.returnTargets.isEmpty()) { + expressions().inferDiamond(newClass, state.returnTargets.peek()); + } + if (expression != null + && expression.is(Tree.Kind.LAMBDA_EXPRESSION, Tree.Kind.METHOD_REFERENCE, Tree.Kind.METHOD_INVOCATION) + && !state.returnTargets.isEmpty() + && !state.returnTargets.peek().isUnknown()) { + expressions().ascribeTarget(expression, state.returnTargets.peek()); + } + return new ReturnStatementTreeImpl(token(required(node, "return")), expression, token(required(node, ";"))); + } + + private YieldStatementTreeImpl yieldStatement(CstNode node) { + ExpressionTree expression = null; + for (CstNode child : node.children()) { + if (!"yield".equals(child.text()) && !";".equals(child.text())) { + expression = expressions().expression(child); + } + } + return new YieldStatementTreeImpl(token(required(node, "yield")), Objects.requireNonNull(expression), token(required(node, ";"))); + } + + private ThrowStatementTreeImpl throwStatement(CstNode node) { + return new ThrowStatementTreeImpl(token(required(node, "throw")), expressions().expression(firstNamed(node)), token(required(node, ";"))); + } + + private AssertStatementTreeImpl assertStatement(CstNode node) { + List expressions = new ArrayList<>(); + InternalSyntaxToken colon = null; + for (CstNode child : node.children()) { + if (":".equals(child.text())) { + colon = token(child); + } else if (!"assert".equals(child.text()) && !";".equals(child.text())) { + expressions.add(expressions().expression(child)); + } + } + AssertStatementTreeImpl tree = new AssertStatementTreeImpl(token(required(node, "assert")), expressions.get(0), token(required(node, ";"))); + if (colon != null) { + tree.complete(colon, expressions.get(1)); + } + return tree; + } + + private LabeledStatementTreeImpl labeled(CstNode node) { + CstNode label = node.children().get(0); + IdentifierTreeImpl name = names().identifier(label); + JLabelSymbol symbol = new JLabelSymbol(name.name()); + state.labels.push(symbol); + List children = node.children(); + LabeledStatementTreeImpl tree = new LabeledStatementTreeImpl(name, token(required(node, ":")), statement(children.get(children.size() - 1))); + state.labels.pop(); + symbol.setDeclaration(tree); + tree.labelSymbol = symbol; + String id = label.decl(); + if (id != null) { + sema.declare(id, tree); + } + return tree; + } + + private SynchronizedStatementTreeImpl synchronizedStatement(CstNode node) { + Parens parens = parens(requiredField(node, CONDITION, childKind(node, PARENTHESIZED_EXPRESSION))); + return new SynchronizedStatementTreeImpl( + token(required(node, "synchronized")), + parens.open(), + parens.expr(), + parens.close(), + block(requiredField(node, "body", childKind(node, BLOCK)))); + } + + @Nullable + private IdentifierTreeImpl labelUse(CstNode node) { + CstNode name = firstOf(node, "identifier"); + if (name == null) { + return null; + } + IdentifierTreeImpl identifier = names().identifier(name); + for (JLabelSymbol label : state.labels) { + if (label.name().equals(identifier.name())) { + label.addUsage(identifier); + identifier.labelSymbol = label; + break; + } + } + return identifier; + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SwitchTranslator.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SwitchTranslator.java new file mode 100644 index 00000000000..e00876ac400 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SwitchTranslator.java @@ -0,0 +1,216 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; +import org.sonar.java.ast.parser.ResourceListTreeImpl; +import org.sonar.java.ast.parser.StatementListTreeImpl; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.declaration.VariableTreeImpl; +import org.sonar.java.model.expression.LiteralTreeImpl; +import org.sonar.java.model.pattern.DefaultPatternTreeImpl; +import org.sonar.java.model.pattern.GuardedPatternTreeImpl; +import org.sonar.java.model.pattern.NullPatternTreeImpl; +import org.sonar.java.model.statement.CaseGroupTreeImpl; +import org.sonar.java.model.statement.CaseLabelTreeImpl; +import org.sonar.java.model.statement.CatchTreeImpl; +import org.sonar.java.model.statement.ExpressionStatementTreeImpl; +import org.sonar.java.model.statement.SwitchExpressionTreeImpl; +import org.sonar.java.model.statement.SwitchStatementTreeImpl; +import org.sonar.java.model.statement.TryStatementTreeImpl; +import org.sonar.java.model.statement.YieldStatementTreeImpl; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.PatternTree; + +import static org.sonar.java.semsitter.Bindings.ascribe; +import static org.sonar.java.semsitter.Bindings.switchResultType; +import static org.sonar.java.semsitter.CstNodes.childKind; +import static org.sonar.java.semsitter.CstNodes.field; +import static org.sonar.java.semsitter.CstNodes.firstNamed; +import static org.sonar.java.semsitter.CstNodes.keyword; +import static org.sonar.java.semsitter.CstNodes.nextIsGroup; +import static org.sonar.java.semsitter.CstNodes.required; +import static org.sonar.java.semsitter.CstNodes.requiredField; + +/** Translates try statements, switch statements and switch expressions. */ +final class SwitchTranslator extends TranslatorPart { + + SwitchTranslator(TranslationState state) { + super(state); + } + + TryStatementTreeImpl tryStatement(CstNode node) { + ResourceListTreeImpl resources = ResourceListTreeImpl.emptyList(); + CstNode resourceNode = field(node, "resources"); + if (resourceNode != null) { + addResources(resources, resourceNode); + } + List catches = catches(node); + CstNode finallyBlock = childKind(node, "finally_clause"); + return new TryStatementTreeImpl( + token(required(node, "try")), + resources.isEmpty() ? null : token(required(resourceNode, "(")), + resources, + resources.isEmpty() ? null : token(required(resourceNode, ")")), + statements().block(requiredField(node, "body", node)), + catches, + finallyBlock == null ? null : token(required(finallyBlock, "finally")), + finallyBlock == null ? null : statements().block(finallyBlock)); + } + + private void addResources(ResourceListTreeImpl resources, CstNode resourceNode) { + for (CstNode child : resourceNode.children()) { + if ("resource".equals(child.k()) && field(child, "name") == null) { + resources.add(expressions().expression(firstNamed(child))); + } else if ("resource".equals(child.k())) { + VariableTreeImpl resource = members().variable(child); + // A resource variable is implicitly final. + if (resource.symbol() instanceof JSymbol symbol) { + symbol.addModifiers(FINAL_MODIFIER); + } + resources.add(resource); + } else if (";".equals(child.text())) { + resources.separators().add(token(child)); + } + } + } + + private List catches(CstNode node) { + List catches = new ArrayList<>(); + for (CstNode child : node.children()) { + if ("catch_clause".equals(child.k())) { + state.scopes.addFirst(new HashMap<>()); + try { + VariableTreeImpl variable = members().variable(required(child, "catch_formal_parameter")); + catches.add(new CatchTreeImpl( + token(required(child, "catch")), + token(required(child, "(")), + variable, + token(required(child, ")")), + statements().block(requiredField(child, "body", childKind(child, "block"))))); + } finally { + state.scopes.removeFirst(); + } + } + } + return catches; + } + + SwitchStatementTreeImpl switchStatement(CstNode node) { + Parens parens = parens(requiredField(node, "condition", childKind(node, "parenthesized_expression"))); + CstNode body = requiredField(node, "body", node); + return new SwitchStatementTreeImpl( + token(required(node, "switch")), + parens.open(), + parens.expr(), + parens.close(), + token(required(body, "{")), + switchGroups(body), + token(required(body, "}"))); + } + + SwitchExpressionTreeImpl switchExpression(CstNode node) { + boolean previous = state.switchExpression; + state.switchExpression = true; + Parens parens = parens(requiredField(node, "condition", childKind(node, "parenthesized_expression"))); + CstNode body = requiredField(node, "body", node); + SwitchExpressionTreeImpl tree = new SwitchExpressionTreeImpl( + token(required(node, "switch")), + parens.open(), + parens.expr(), + parens.close(), + token(required(body, "{")), + switchGroups(body), + token(required(body, "}"))); + state.switchExpression = previous; + ascribe(tree, switchResultType(tree)); + return tree; + } + + private List switchGroups(CstNode body) { + List groups = new ArrayList<>(); + List carried = new ArrayList<>(); + List children = body.children(); + for (int i = 0; i < children.size(); i++) { + CstNode child = children.get(i); + if ("switch_rule".equals(child.k()) || "switch_block_statement_group".equals(child.k())) { + CaseGroupTreeImpl group = switchArm(child, carried); + if (group.body().isEmpty() && "switch_block_statement_group".equals(child.k()) && nextIsGroup(children, i)) { + carried = group.labels().stream().map(CaseLabelTreeImpl.class::cast).collect(Collectors.toCollection(ArrayList::new)); + } else { + groups.add(group); + carried = new ArrayList<>(); + } + } + } + return groups; + } + + private CaseGroupTreeImpl switchArm(CstNode node, List carried) { + List labels = new ArrayList<>(carried); + StatementListTreeImpl body = StatementListTreeImpl.emptyList(); + List children = node.children(); + int i = 0; + while (i < children.size()) { + CstNode child = children.get(i); + if ("switch_label".equals(child.k())) { + i++; + labels.add(caseLabel(child, token(children.get(i)))); + } else if ("expression_statement".equals(child.k()) && "switch_rule".equals(node.k())) { + ExpressionStatementTreeImpl statement = statements().expressionStatement(child); + body.add(new YieldStatementTreeImpl(null, statement.expression(), (InternalSyntaxToken) statement.semicolonToken())); + } else { + statements().addStatement(body, child); + } + i++; + } + return new CaseGroupTreeImpl(labels, body); + } + + private CaseLabelTreeImpl caseLabel(CstNode node, InternalSyntaxToken separator) { + InternalSyntaxToken keyword = keyword(node, "case") != null ? token(keyword(node, "case")) : token(required(node, "default")); + List expressions = new ArrayList<>(); + boolean caseLabel = keyword(node, "case") != null; + for (CstNode child : node.children()) { + if (!"case".equals(child.text()) && !",".equals(child.text())) { + addLabelElement(expressions, child, caseLabel); + } + } + return new CaseLabelTreeImpl(keyword, expressions, separator); + } + + private void addLabelElement(List expressions, CstNode child, boolean caseLabel) { + if ("default".equals(child.text())) { + if (caseLabel) { + expressions.add(new DefaultPatternTreeImpl(token(child), Type.UNKNOWN)); + } + } else if ("pattern".equals(child.k()) || "record_pattern".equals(child.k()) || "type_pattern".equals(child.k())) { + expressions.add(lambdas().pattern(child)); + } else if ("guard".equals(child.k()) && !expressions.isEmpty() && expressions.get(expressions.size() - 1) instanceof PatternTree guarded) { + GuardedPatternTreeImpl pattern = new GuardedPatternTreeImpl(guarded, token(required(child, "when")), expressions().expression(firstNamed(child)), guarded.symbolType()); + expressions.set(expressions.size() - 1, pattern); + } else if ("null_literal".equals(child.k())) { + expressions.add(new NullPatternTreeImpl((LiteralTreeImpl) expressions().expression(child))); + } else { + expressions.add(expressions().expression(child)); + } + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/ThrownTypes.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/ThrownTypes.java new file mode 100644 index 00000000000..cf324c0a6e6 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/ThrownTypes.java @@ -0,0 +1,125 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.List; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TryStatementTree; +import org.sonar.plugins.java.api.tree.TypeTree; +import org.sonar.plugins.java.api.tree.UnionTypeTree; + +/** The exception types the statements of a try body can throw, not looking inside lambdas and nested classes. */ +final class ThrownTypes extends BaseTreeVisitor { + final List thrown = new ArrayList<>(); + boolean unknown; + + void scanTry(List resources, Tree block) { + for (Tree resource : resources) { + scan(resource); + addClose(resource instanceof org.sonar.plugins.java.api.tree.VariableTree variable ? variable.type().symbolType() : ((ExpressionTree) resource).symbolType()); + } + scan(block); + } + + private void addClose(Type type) { + if (type.isUnknown()) { + unknown = true; + return; + } + List candidates = new ArrayList<>(List.of(type)); + type.symbol().superTypes().forEach(candidates::add); + for (Type candidate : candidates) { + for (Symbol member : candidate.symbol().memberSymbols()) { + if (member instanceof Symbol.MethodSymbol method && "close".equals(method.name()) && method.parameterTypes().isEmpty()) { + addAll(method); + return; + } + } + } + unknown = true; + } + + private void addAll(Symbol.MethodSymbol method) { + if (method.isUnknown()) { + unknown = true; + return; + } + method.thrownTypes().forEach(this::add); + } + + private void add(Type type) { + if (type.isUnknown() || !type.isClass()) { + unknown = true; + } else { + thrown.add(type); + } + } + + @Override + public void visitMethodInvocation(org.sonar.plugins.java.api.tree.MethodInvocationTree tree) { + super.visitMethodInvocation(tree); + addAll(tree.methodSymbol()); + } + + @Override + public void visitNewClass(org.sonar.plugins.java.api.tree.NewClassTree tree) { + scan(tree.enclosingExpression()); + scan(tree.arguments()); + addAll(tree.methodSymbol()); + } + + @Override + public void visitThrowStatement(org.sonar.plugins.java.api.tree.ThrowStatementTree tree) { + super.visitThrowStatement(tree); + add(tree.expression().symbolType()); + } + + @Override + public void visitTryStatement(TryStatementTree tree) { + ThrownTypes inner = new ThrownTypes(); + inner.scanTry(tree.resourceList(), tree.block()); + unknown |= inner.unknown; + List caught = new ArrayList<>(); + tree.catches().forEach(catchTree -> { + TypeTree parameterType = catchTree.parameter().type(); + (parameterType instanceof UnionTypeTree union ? union.typeAlternatives() : List.of(parameterType)).forEach(alternative -> caught.add(alternative.symbolType())); + scan(catchTree.block()); + }); + inner.thrown.stream().filter(type -> caught.stream().noneMatch(type::isSubtypeOf)).forEach(thrown::add); + scan(tree.finallyBlock()); + } + + @Override + public void visitLambdaExpression(org.sonar.plugins.java.api.tree.LambdaExpressionTree tree) { + // not thrown by the enclosing statements + } + + @Override + public void visitMethodReference(org.sonar.plugins.java.api.tree.MethodReferenceTree tree) { + scan(tree.expression()); + } + + @Override + public void visitClass(org.sonar.plugins.java.api.tree.ClassTree tree) { + // a nested class has its own callables + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/TranslationState.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/TranslationState.java new file mode 100644 index 00000000000..77b16bcb149 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/TranslationState.java @@ -0,0 +1,67 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.HashSet; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.JLabelSymbol; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.Tree; + +/** State shared by the parts that translate one document. */ +final class TranslationState { + + final JSema sema; + final Map tokens = new IdentityHashMap<>(); + final Deque labels = new ArrayDeque<>(); + final Deque types = new ArrayDeque<>(); + InternalSyntaxToken eof = new InternalSyntaxToken(1, 0, "", List.of(), true); + boolean switchExpression; + String implicitClassName = ""; + String packageName = ""; + boolean naming; + final FileImports imports = new FileImports(); + final Deque> scopes = new ArrayDeque<>(); + final Deque returnTargets = new ArrayDeque<>(); + final Set rawResults = new HashSet<>(); + + /** Whether {@code _} declares an unnamed variable (Java 22 and later) instead of a plain name. */ + boolean unnamedVariables = true; + + boolean records = true; + + /** Whether consecutive {@code ///} lines form one Markdown comment (Java 23 and later). */ + boolean markdownComments = true; + + /** Work that needs declarations met later in the file. */ + final List deferred = new ArrayList<>(); + + final TranslatorParts parts; + + TranslationState(JSema sema) { + this.sema = sema; + parts = new TranslatorParts(this); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/TranslatorPart.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/TranslatorPart.java new file mode 100644 index 00000000000..6e14ab26a78 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/TranslatorPart.java @@ -0,0 +1,342 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import javax.annotation.Nullable; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.ModifiersUtils; +import org.sonar.java.model.declaration.ClassTreeImpl; +import org.sonar.java.model.declaration.MethodTreeImpl; +import org.sonar.java.model.declaration.VariableTreeImpl; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.Modifier; +import org.sonar.plugins.java.api.tree.Tree; +import static org.sonar.java.semsitter.Bindings.ascribe; +import static org.sonar.java.semsitter.Bindings.bind; +import static org.sonar.java.semsitter.Bindings.declaredParameterTypes; +import static org.sonar.java.semsitter.Bindings.identifierType; +import static org.sonar.java.semsitter.Bindings.isField; +import static org.sonar.java.semsitter.Bindings.isKnownOrRecovered; +import static org.sonar.java.semsitter.Bindings.keepsArguments; +import static org.sonar.java.semsitter.Bindings.sameErasure; +import static org.sonar.java.semsitter.Bindings.usageId; +import static org.sonar.java.semsitter.CstNodes.field; +import static org.sonar.java.semsitter.CstNodes.firstType; +import static org.sonar.java.semsitter.CstNodes.isComment; +import static org.sonar.java.semsitter.CstNodes.isTypeKind; +import static org.sonar.java.semsitter.CstNodes.keyword; +import static org.sonar.java.semsitter.CstNodes.required; +import static org.sonar.java.semsitter.CstNodes.requiredField; + +/** Base of the translator parts: shared state, token lookup, and declaration and use bindings. */ +class TranslatorPart { + + final JSema sema; + final TranslationState state; + + static final List FINAL_MODIFIER = List.of("final"); + + TranslatorPart(TranslationState state) { + this.state = state; + this.sema = state.sema; + } + + DeclarationTranslator declarations() { + return state.parts.declarations; + } + + MemberTranslator members() { + return state.parts.members; + } + + StatementTranslator statements() { + return state.parts.statements; + } + + SwitchTranslator switches() { + return state.parts.switches; + } + + NameTranslator names() { + return state.parts.names; + } + + ExpressionTranslator expressions() { + return state.parts.expressions; + } + + InvocationTranslator invocations() { + return state.parts.invocations; + } + + LambdaTranslator lambdas() { + return state.parts.lambdas; + } + + TypeTranslator typeTrees() { + return state.parts.typeTrees; + } + + void bindType(IdentifierTreeImpl identifier, String fqn) { + Symbol symbol = sema.resolve(fqn); + bind(identifier, symbol); + ascribe(identifier, symbol.type()); + sema.use(fqn, identifier); + } + + void bindDeclaration(Tree tree, @Nullable CstNode name, IdentifierTreeImpl identifier) { + if (name == null) { + return; + } + String id = name.decl(); + if (id == null) { + if (tree instanceof VariableTreeImpl variable && "_".equals(identifier.name())) { + bindUnnamedVariable(variable, identifier); + } + return; + } + if (id.contains("#(")) { + id = name.decls().stream().filter(extra -> !extra.contains("(")).findFirst().orElse(id); + } + Symbol symbol = sema.resolve(id); + sema.declare(id, tree); + for (String extra : name.decls()) { + if (!extra.equals(id)) { + sema.declare(extra, tree); + } + } + completeVariableSymbol(tree, symbol); + completeMethodReturnType(tree, symbol); + bind(identifier, symbol); + ascribe(identifier, identifierType(symbol)); + if (!state.scopes.isEmpty() && symbol.isVariableSymbol() && symbol.owner() != null && symbol.owner().isMethodSymbol()) { + state.scopes.peekFirst().put(symbol.name(), symbol); + } + setDeclaredSymbol(tree, symbol); + } + + private static void completeVariableSymbol(Tree tree, Symbol symbol) { + // The scan records no modifiers for locals and parameters. + if (tree instanceof VariableTreeImpl declared && symbol instanceof JSymbol declaredSymbol && symbol.isVariableSymbol() + && ModifiersUtils.hasModifier(declared.modifiers(), Modifier.FINAL)) { + declaredSymbol.addModifiers(FINAL_MODIFIER); + } + if (tree instanceof VariableTreeImpl variable && symbol instanceof JSymbol variableSymbol && symbol.isVariableSymbol() && variable.type() != null) { + Type declared = variable.type().symbolType(); + if (symbol.type().isUnknown() ? isKnownOrRecovered(declared) : (keepsArguments(declared) && sameErasure(declared, symbol.type()))) { + variableSymbol.type(declared); + } + } + } + + private static void completeMethodReturnType(Tree tree, Symbol symbol) { + if (tree instanceof MethodTreeImpl method && symbol instanceof JMethodSymbol methodSymbol && method.returnType() != null + && methodSymbol.returnType().type().isUnknown() && isKnownOrRecovered(method.returnType().symbolType())) { + methodSymbol.returnTypeSymbol(method.returnType().symbolType().symbol()); + } else if (tree instanceof MethodTreeImpl method && symbol instanceof JMethodSymbol methodSymbol && method.returnType() != null + && method.returnType().symbolType().isParameterized() && !methodSymbol.returnType().type().isParameterized() + && sameErasure(method.returnType().symbolType(), methodSymbol.returnType().type())) { + methodSymbol.returnTypeSymbol(method.returnType().symbolType().symbol()); + } + } + + private static void setDeclaredSymbol(Tree tree, Symbol symbol) { + if (tree instanceof ClassTreeImpl classTree && symbol instanceof Symbol.TypeSymbol typeSymbol) { + classTree.setSymbol(typeSymbol); + if (symbol instanceof JSymbol nested && ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.STATIC) && !nested.isStatic()) { + nested.addModifiers(List.of("static")); + } + } else if (tree instanceof MethodTreeImpl method && symbol instanceof Symbol.MethodSymbol methodSymbol) { + method.setSymbol(methodSymbol); + if (methodSymbol instanceof JMethodSymbol declared) { + declaredParameterTypes(declared, method.parameters()); + } + } else if (tree instanceof VariableTreeImpl variable && symbol instanceof Symbol.VariableSymbol variableSymbol) { + variable.setSymbol(variableSymbol); + } + } + + /** An unnamed variable declares nothing the scan records, so it gets a local symbol of its own. */ + private void bindUnnamedVariable(VariableTreeImpl variable, IdentifierTreeImpl identifier) { + var start = identifier.identifierToken().range().start(); + JVariableSymbol symbol = new JVariableSymbol(sema, "_@" + start.line() + ":" + start.column(), "_", "local"); + Type declared = variable.type() == null ? Type.UNKNOWN : variable.type().symbolType(); + if (isKnownOrRecovered(declared)) { + symbol.type(declared); + } + sema.declare(symbol.id, variable); + variable.setSymbol(symbol); + } + + /** + * The scan records erased return types, so the type arguments of each declared return type are read from the + * syntax before any body is translated: invocations may precede the declaration they call. + */ + void declareGenericReturns(CstNode node) { + if ("method_declaration".equals(node.k()) && field(node, "dimensions") == null + && sema.resolve(requiredField(node, "name", null).decl()) instanceof JMethodSymbol method) { + Type declared = syntacticType(requiredField(node, "type", null)); + if (declared.isParameterized() && sameErasure(declared, method.returnType().type())) { + method.returnTypeSymbol(declared.symbol()); + } + } + for (CstNode child : node.children()) { + declareGenericReturns(child); + } + } + + /** The type a type node denotes, from the references the scan bound, without translating it. */ + Type syntacticType(CstNode node) { + switch (node.k()) { + case "type_identifier", "scoped_type_identifier" -> { + String target = node.typeTarget(); + return target != null && sema.resolve(target) instanceof Symbol.TypeSymbol type && !type.isUnknown() ? type.type() : Type.UNKNOWN; + } + case "generic_type" -> { + return genericSyntacticType(node); + } + case "wildcard" -> { + return wildcardSyntacticType(node); + } + default -> { + return Type.UNKNOWN; + } + } + } + + private Type genericSyntacticType(CstNode node) { + Type raw = syntacticType(node.children().get(0)); + if (raw.isUnknown()) { + return raw; + } + List types = new ArrayList<>(); + for (CstNode argument : required(node, "type_arguments").children()) { + if (isTypeKind(argument.k())) { + types.add(syntacticType(argument) instanceof JType type ? type : JType.unknown(sema)); + } + } + return JType.named(sema, raw.erasure().fullyQualifiedName(), types); + } + + private Type wildcardSyntacticType(CstNode node) { + CstNode bound = firstType(node); + if (bound == null) { + return JType.wildcard(sema, (JType) sema.getClassType("java.lang.Object")); + } + JType type = syntacticType(bound) instanceof JType known ? known : JType.unknown(sema); + return keyword(node, "super") != null ? JType.superWildcard(sema, type) : JType.wildcard(sema, type); + } + + void bindType(ClassTreeImpl tree, CstNode node) { + String id = node.decl(); + if (id != null && sema.resolve(id) instanceof Symbol.TypeSymbol typeSymbol) { + tree.setSymbol(typeSymbol); + sema.declare(id, tree); + } + } + + void bindUse(IdentifierTreeImpl identifier, CstNode node) { + bindUse(identifier, node, false); + } + + void bindUse(IdentifierTreeImpl identifier, CstNode node, boolean qualified) { + String target = node.valueTarget(); + if (target == null) { + target = node.typeTarget(); + } + if (target == null) { + return; + } + Symbol symbol = sema.resolve(target); + String typeTarget = node.typeTarget(); + if (symbol.isMethodSymbol() && "".equals(symbol.name()) && typeTarget != null && !typeTarget.equals(target)) { + target = typeTarget; + symbol = sema.resolve(target); + } + if (symbol.isMethodSymbol() && symbol.isUnknown()) { + symbol = Symbol.MethodSymbol.UNKNOWN_METHOD; + } + if (!qualified && (symbol.isUnknown() || (symbol.isVariableSymbol() && !isField(symbol)))) { + Symbol local = scopedVariable(identifier.name()); + if (local != null) { + symbol = local; + } + } + bind(identifier, symbol); + ascribe(identifier, identifierType(symbol)); + sema.use(usageId(symbol, target), identifier); + } + + @Nullable + private Symbol scopedVariable(String name) { + for (Map scope : state.scopes) { + Symbol found = scope.get(name); + if (found != null) { + return found; + } + } + return null; + } + + void recordUse(Symbol symbol, IdentifierTree identifier) { + String id = usageId(symbol, ""); + if (!id.isEmpty()) { + sema.use(id, identifier); + } + } + + Parens parens(CstNode node) { + InternalSyntaxToken open = token(required(node, "(")); + InternalSyntaxToken close = token(required(node, ")")); + return new Parens(open, expressions().expression(node.children().get(1)), close); + } + + InternalSyntaxToken token(CstNode node) { + InternalSyntaxToken found = state.tokens.get(node.proto); + if (found != null) { + return found; + } + if (!node.children().isEmpty()) { + for (CstNode child : node.children()) { + if (child.children().isEmpty() && !child.text().isEmpty() && !isComment(child)) { + return token(child); + } + } + } + String text = node.text().isEmpty() ? node.k() : node.text(); + if (text.indexOf('_') >= 0) { + text = ""; + } + return new InternalSyntaxToken(node.line(), node.col(), text, List.of(), false); + } + + @Nullable + InternalSyntaxToken optionalToken(CstNode node, String text) { + CstNode found = keyword(node, text); + return found == null ? null : token(found); + } + + record Parens(InternalSyntaxToken open, ExpressionTree expr, InternalSyntaxToken close) { + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/TranslatorParts.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/TranslatorParts.java new file mode 100644 index 00000000000..e6ff1cd06ac --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/TranslatorParts.java @@ -0,0 +1,42 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +/** The parts that translate one document, each created once and sharing one {@link TranslationState}. */ +final class TranslatorParts { + final DeclarationTranslator declarations; + final MemberTranslator members; + final StatementTranslator statements; + final SwitchTranslator switches; + final NameTranslator names; + final ExpressionTranslator expressions; + final InvocationTranslator invocations; + final LambdaTranslator lambdas; + final TypeTranslator typeTrees; + + TranslatorParts(TranslationState state) { + declarations = new DeclarationTranslator(state); + members = new MemberTranslator(state); + statements = new StatementTranslator(state); + switches = new SwitchTranslator(state); + names = new NameTranslator(state); + expressions = new ExpressionTranslator(state); + invocations = new InvocationTranslator(state); + lambdas = new LambdaTranslator(state); + typeTrees = new TypeTranslator(state); + } +} diff --git a/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/TypeTranslator.java b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/TypeTranslator.java new file mode 100644 index 00000000000..295a852cbd9 --- /dev/null +++ b/java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/TypeTranslator.java @@ -0,0 +1,340 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import javax.annotation.Nullable; +import org.sonar.java.ast.parser.QualifiedIdentifierListTreeImpl; +import org.sonar.java.ast.parser.TypeParameterListTreeImpl; +import org.sonar.java.model.AbstractTypedTree; +import org.sonar.java.model.ArrayDimensionTreeImpl; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.JavaTree; +import org.sonar.java.model.TypeParameterTreeImpl; +import org.sonar.java.model.declaration.AnnotationTreeImpl; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.java.model.expression.TypeArgumentListTreeImpl; +import org.sonar.java.model.expression.VarTypeTreeImpl; +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.ArrayDimensionTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.ParameterizedTypeTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeParameterTree; +import org.sonar.plugins.java.api.tree.TypeTree; +import org.sonar.plugins.java.api.tree.WildcardTree; + +import static org.sonar.java.semsitter.Bindings.ascribe; +import static org.sonar.java.semsitter.Bindings.bind; +import static org.sonar.java.semsitter.CstNodes.childKind; +import static org.sonar.java.semsitter.CstNodes.closingAngle; +import static org.sonar.java.semsitter.CstNodes.field; +import static org.sonar.java.semsitter.CstNodes.firstOf; +import static org.sonar.java.semsitter.CstNodes.firstType; +import static org.sonar.java.semsitter.CstNodes.isAnnotation; +import static org.sonar.java.semsitter.CstNodes.isTypeKind; +import static org.sonar.java.semsitter.CstNodes.keyword; +import static org.sonar.java.semsitter.CstNodes.required; +import static org.sonar.java.semsitter.CstNodes.requiredField; + +/** Translates type syntax: primitive, array, generic, wildcard and union types, and type parameters. */ +final class TypeTranslator extends TranslatorPart { + + private static final String EXTENDS = "extends"; + + TypeTranslator(TranslationState state) { + super(state); + } + + TypeTree type(CstNode node) { + return switch (node.k()) { + case "integral_type", "floating_point_type", "boolean_type", "void_type" -> primitive(node); + case "generic_type" -> generic(node); + case "array_type" -> arrayType(type(requiredField(node, "element", firstType(node))), field(node, "dimensions")); + case "scoped_identifier", "scoped_type_identifier", "field_access" -> names().memberSelect(node); + case "wildcard" -> wildcard(node); + case "annotated_type" -> annotatedType(node); + case "type_identifier" -> "var".equals(node.text()) ? new VarTypeTreeImpl(token(node)) : (TypeTree) names().primary(node); + default -> (TypeTree) ("identifier".equals(node.k()) ? names().primary(node) : expressions().expression(node)); + }; + } + + private TypeTree annotatedType(CstNode node) { + return annotate(type(firstType(node)), node); + } + + TypeTree annotate(TypeTree type, CstNode node) { + annotateLeftmost(type, node.children().stream().filter(CstNodes::isAnnotation).map(members()::annotation).toList()); + return type; + } + + /** Like ECJ, the annotations written before a qualified or parameterized type go on its leftmost name. */ + static void annotateLeftmost(TypeTree type, List annotations) { + TypeTree target = type; + while (true) { + TypeTree next = switch (target) { + case ParameterizedTypeTree parameterized -> parameterized.type(); + case MemberSelectExpressionTree select when select.expression() instanceof TypeTree outer -> outer; + default -> null; + }; + if (next == null) { + break; + } + target = next; + } + if (!annotations.isEmpty() && target instanceof JavaTree.AnnotatedTypeTree annotated) { + annotated.complete(annotations); + } + } + + private JavaTree.PrimitiveTypeTreeImpl primitive(CstNode node) { + CstNode keyword = node.children().isEmpty() ? node : node.children().get(0); + JavaTree.PrimitiveTypeTreeImpl tree = new JavaTree.PrimitiveTypeTreeImpl(token(keyword)); + tree.complete(List.of()); + ascribe(tree, sema.getClassType(keyword.text())); + return tree; + } + + private JavaTree.ParameterizedTypeTreeImpl generic(CstNode node) { + TypeTree raw = type(firstType(node)); + JavaTree.ParameterizedTypeTreeImpl tree = new JavaTree.ParameterizedTypeTreeImpl(raw, typeArguments(required(node, "type_arguments"))); + List args = new ArrayList<>(); + for (TypeTree argument : tree.typeArguments()) { + if (argument instanceof WildcardTree wildcard) { + Type wildcardType = wildcardType(wildcard); + ascribe(argument, wildcardType); + args.add(wildcardType); + } else { + args.add(argument.symbolType()); + } + } + if (raw.symbolType() instanceof JType) { + List typeArguments = new ArrayList<>(); + for (Type argument : args) { + typeArguments.add(argument instanceof JType jType ? jType : JType.unknown(sema)); + } + JType parameterized = JType.named(sema, raw.symbolType().erasure().fullyQualifiedName(), typeArguments); + ascribe(tree, parameterized); + if (raw instanceof AbstractTypedTree typed) { + ascribe(typed, parameterized); + } + if (raw instanceof IdentifierTreeImpl identifier) { + bind(identifier, parameterized.symbol()); + } + } + return tree; + } + + TypeTree arrayType(TypeTree element, @Nullable CstNode dimensions) { + if (dimensions == null) { + return element; + } + TypeTree current = element; + List annotations = new ArrayList<>(); + List children = dimensions.children(); + for (int i = 0; i < children.size(); i++) { + if ("[".equals(children.get(i).text())) { + InternalSyntaxToken close = token(children.get(i + 1)); + JType component = current.symbolType() instanceof JType jType ? jType : JType.unknown(sema); + current = new JavaTree.ArrayTypeTreeImpl(current, annotations, token(children.get(i)), close); + annotations = new ArrayList<>(); + ascribe(current, JType.array(sema, component)); + } else if (isAnnotation(children.get(i))) { + annotations.add(members().annotation(children.get(i))); + } + } + return current; + } + + private Type wildcardType(WildcardTree wildcard) { + if (wildcard.is(Tree.Kind.SUPER_WILDCARD) && wildcard.bound() != null && wildcard.bound().symbolType() instanceof JType lower) { + return JType.superWildcard(sema, lower); + } + Type upper = wildcard.is(Tree.Kind.EXTENDS_WILDCARD) && wildcard.bound() != null ? wildcard.bound().symbolType() : sema.getClassType("java.lang.Object"); + return upper instanceof JType bound ? JType.wildcard(sema, bound) : Type.UNKNOWN; + } + + private JavaTree.WildcardTreeImpl wildcard(CstNode node) { + CstNode bound = firstType(node); + List annotations = node.children().stream().filter(CstNodes::isAnnotation).map(members()::annotation).toList(); + if (bound == null) { + JavaTree.WildcardTreeImpl tree = new JavaTree.WildcardTreeImpl(token(required(node, "?"))); + tree.complete(annotations); + return tree; + } + boolean upper = keyword(node, EXTENDS) != null; + JavaTree.WildcardTreeImpl tree = new JavaTree.WildcardTreeImpl( + upper ? Tree.Kind.EXTENDS_WILDCARD : Tree.Kind.SUPER_WILDCARD, + token(required(node, upper ? EXTENDS : "super")), + type(bound)).complete(token(required(node, "?"))); + tree.complete(annotations); + return tree; + } + + TypeArgumentListTreeImpl typeArguments(CstNode node) { + TypeArgumentListTreeImpl list = new TypeArgumentListTreeImpl(token(required(node, "<")), closingAngle(node)); + for (CstNode child : node.children()) { + if ("<".equals(child.text()) || ">".equals(child.text())) { + continue; + } + if (",".equals(child.text())) { + list.separators().add(token(child)); + } else { + list.add(type(child)); + } + } + return list; + } + + TypeParameterListTreeImpl typeParameters(CstNode node) { + TypeParameterListTreeImpl list = new TypeParameterListTreeImpl(token(required(node, "<")), closingAngle(node)); + for (CstNode child : node.children()) { + if ("<".equals(child.text()) || ">".equals(child.text())) { + continue; + } + if (",".equals(child.text())) { + list.separators().add(token(child)); + } else { + list.add(typeParameter(child)); + } + } + return list; + } + + private TypeParameterTree typeParameter(CstNode node) { + CstNode nameNode = firstOf(node, "type_identifier", "identifier"); + IdentifierTreeImpl name = names().identifier(nameNode); + bindUse(name, nameNode); + CstNode bound = childKind(node, "type_bound"); + TypeParameterTreeImpl tree; + if (bound == null) { + tree = new TypeParameterTreeImpl(name); + } else { + tree = new TypeParameterTreeImpl(name, token(required(bound, EXTENDS)), separatedTypes(bound)); + } + if (name.symbol().isUnknown()) { + bindDeclaration(tree, nameNode, name); + } + if (name.symbol() instanceof Symbol.TypeSymbol typeSymbol) { + tree.setSymbol(typeSymbol); + } + if (bound != null && name.symbol() instanceof JTypeSymbol parameter && parameter.isTypeParameter()) { + parameter.boundTrees(tree.bounds()); + } + return tree; + } + + TypeTree catchType(CstNode node) { + int alternatives = 0; + for (CstNode child : node.children()) { + if (isTypeKind(child.k())) { + alternatives++; + } + } + if (alternatives <= 1) { + return type(firstType(node)); + } + QualifiedIdentifierListTreeImpl list = QualifiedIdentifierListTreeImpl.emptyList(); + for (CstNode child : node.children()) { + if (isTypeKind(child.k())) { + list.add(type(child)); + } else { + list.separators().add(token(child)); + } + } + JavaTree.UnionTypeTreeImpl union = new JavaTree.UnionTypeTreeImpl(list); + ascribe(union, leastUpperBound(list.stream().map(TypeTree::symbolType).toList())); + return union; + } + + /** The closest class every alternative of a multi-catch descends from. */ + private Type leastUpperBound(List alternatives) { + if (alternatives.stream().anyMatch(Type::isUnknown)) { + return Type.UNKNOWN; + } + Type candidate = alternatives.get(0); + while (candidate != null && !candidate.isUnknown()) { + Type current = candidate; + if (alternatives.stream().allMatch(alternative -> alternative.isSubtypeOf(current))) { + return current; + } + candidate = current.symbol().superClass(); + } + return sema.getClassType("java.lang.Object"); + } + + QualifiedIdentifierListTreeImpl separatedTypes(CstNode node) { + QualifiedIdentifierListTreeImpl list = QualifiedIdentifierListTreeImpl.emptyList(); + addSeparatedTypes(list, node); + return list; + } + + private void addSeparatedTypes(QualifiedIdentifierListTreeImpl list, CstNode node) { + for (CstNode child : node.children()) { + if ("type_list".equals(child.k())) { + addSeparatedTypes(list, child); + } else if (isTypeKind(child.k())) { + list.add(type(child)); + } else if (",".equals(child.text()) || "&".equals(child.text())) { + list.separators().add(token(child)); + } + } + } + + List dimensions(CstNode node) { + List dims = new ArrayList<>(); + List annotations = new ArrayList<>(); + ExpressionTree index = null; + InternalSyntaxToken open = null; + for (CstNode child : node.children()) { + if ("[".equals(child.text())) { + open = token(child); + index = null; + } else if ("]".equals(child.text())) { + dims.add(new ArrayDimensionTreeImpl(Objects.requireNonNull(open), index, token(child)).completeAnnotations(annotations)); + annotations = new ArrayList<>(); + open = null; + } else if (open != null) { + index = expressions().expression(child); + } else if (isAnnotation(child)) { + annotations.add(members().annotation(child)); + } + } + return dims; + } + + Type currentType() { + Symbol.TypeSymbol enclosing = state.types.peek(); + return enclosing == null ? Type.UNKNOWN : enclosing.type(); + } + + Type arrayTypeOf(TypeTree element, int dimensions) { + Type type = element.symbolType(); + if (!(type instanceof JType jType)) { + return Type.UNKNOWN; + } + for (int i = 0; i < Math.max(dimensions, 1); i++) { + jType = JType.array(sema, jType); + } + return jType; + } +} diff --git a/java-frontend-semsitter/src/main/resources/META-INF/services/org.sonar.java.model.JParserProvider b/java-frontend-semsitter/src/main/resources/META-INF/services/org.sonar.java.model.JParserProvider new file mode 100644 index 00000000000..af4b455c6fb --- /dev/null +++ b/java-frontend-semsitter/src/main/resources/META-INF/services/org.sonar.java.model.JParserProvider @@ -0,0 +1 @@ +org.sonar.java.semsitter.SemSitterParserProvider diff --git a/java-frontend-semsitter/src/main/resources/org/sonar/java/semsitter/udg-java-server-aarch64-unknown-linux-musl b/java-frontend-semsitter/src/main/resources/org/sonar/java/semsitter/udg-java-server-aarch64-unknown-linux-musl new file mode 100644 index 00000000000..f87617d568d Binary files /dev/null and b/java-frontend-semsitter/src/main/resources/org/sonar/java/semsitter/udg-java-server-aarch64-unknown-linux-musl differ diff --git a/java-frontend-semsitter/src/main/resources/org/sonar/java/semsitter/udg-java-server-x86_64-unknown-linux-musl b/java-frontend-semsitter/src/main/resources/org/sonar/java/semsitter/udg-java-server-x86_64-unknown-linux-musl new file mode 100644 index 00000000000..ae23cfdb534 Binary files /dev/null and b/java-frontend-semsitter/src/main/resources/org/sonar/java/semsitter/udg-java-server-x86_64-unknown-linux-musl differ diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/BindingsTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/BindingsTest.java new file mode 100644 index 00000000000..8639f7601cd --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/BindingsTest.java @@ -0,0 +1,201 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.sonar.java.model.statement.SwitchExpressionTreeImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.CompilationUnitTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.MethodInvocationTree; +import org.sonar.plugins.java.api.tree.MethodReferenceTree; +import org.sonar.plugins.java.api.tree.SwitchExpressionTree; +import org.sonar.plugins.java.api.tree.Tree; + +import static org.assertj.core.api.Assertions.assertThat; + +class BindingsTest { + + private final JSema sema = new JSema(); + + @TempDir + Path baseDir; + + @Test + void comparisons_and_logical_operators_are_boolean() { + Type result = Bindings.binaryType("<=", type("int"), type("long")); + + assertThat(result.is("boolean")).isTrue(); + assertThat(Bindings.binaryType("instanceof", Type.UNKNOWN, type("int")).isUnknown()).isTrue(); + } + + @Test + void a_string_operand_makes_a_concatenation() { + assertThat(Bindings.binaryType("+", type("int"), sema.getClassType("java.lang.String")).is("java.lang.String")).isTrue(); + assertThat(Bindings.binaryType("+", Type.UNKNOWN, sema.getClassType("java.lang.String")).isUnknown()).isTrue(); + } + + @Test + void arithmetic_operands_are_promoted() { + assertThat(Bindings.binaryType("*", type("byte"), type("short")).is("int")).isTrue(); + assertThat(Bindings.binaryType("-", type("int"), type("double")).is("double")).isTrue(); + assertThat(Bindings.binaryType("+", type("float"), type("long")).is("float")).isTrue(); + assertThat(Bindings.binaryType("%", type("long"), type("int")).is("long")).isTrue(); + assertThat(Bindings.binaryType("<<", type("long"), type("int")).is("long")).isTrue(); + assertThat(Bindings.binaryType(">>>", type("byte"), type("long")).is("int")).isTrue(); + } + + @Test + void bitwise_operators_on_booleans_stay_boolean() { + assertThat(Bindings.binaryType("&", type("boolean"), type("boolean")).is("boolean")).isTrue(); + assertThat(Bindings.binaryType("+", type("boolean"), type("int")).is("boolean")).isTrue(); + assertThat(Bindings.binaryType("^", type("int"), type("boolean")).is("int")).isTrue(); + } + + @Test + void a_non_primitive_operand_keeps_the_known_side() { + Type list = sema.getClassType("java.util.List"); + + assertThat(Bindings.binaryType("-", Type.UNKNOWN, type("int")).is("int")).isTrue(); + assertThat(Bindings.binaryType("-", list, type("int"))).isSameAs(list); + assertThat(Bindings.binaryType("-", type("int"), list)).isSameAs(type("int")); + } + + @Test + void unknown_operators_get_the_default_kinds() { + assertThat(Bindings.binaryKind("??")).isEqualTo(Tree.Kind.PLUS); + assertThat(Bindings.binaryKind("^")).isEqualTo(Tree.Kind.XOR); + assertThat(Bindings.assignmentKind("=")).isEqualTo(Tree.Kind.ASSIGNMENT); + assertThat(Bindings.unaryKind("!", true)).isEqualTo(Tree.Kind.LOGICAL_COMPLEMENT); + assertThat(Bindings.unaryKind("--", false)).isEqualTo(Tree.Kind.POSTFIX_DECREMENT); + } + + @Test + void an_unknown_method_names_its_own_type() { + JMethodSymbol unknown = new JMethodSymbol(sema, null, "m"); + unknown.unknown(true); + + assertThat(Bindings.identifierType(unknown)).isSameAs(unknown.type()); + assertThat(Bindings.identifierType(Symbol.UNKNOWN_SYMBOL).isUnknown()).isTrue(); + } + + @Test + void arrays_keep_the_arguments_of_their_elements() { + assertThat(Bindings.keepsArguments(type("int[]"))).isFalse(); + assertThat(Bindings.keepsArguments(Type.UNKNOWN)).isFalse(); + assertThat(Bindings.isKnownOrRecovered(Type.UNKNOWN)).isFalse(); + assertThat(Bindings.isKnownOrRecovered(type("int"))).isTrue(); + } + + @Test + void a_switch_expression_has_the_type_all_its_yields_share() throws Exception { + List switches = switches(""" + class S { + Object f(int i) { + return switch (i) { + case 1 -> "a"; + case 2 -> { + Runnable r = () -> {}; + Object o = new Object() { int g() { return switch (i) { default -> { yield 1; } }; } }; + yield "b"; + } + default -> { + int k = switch (i) { default -> 3; }; + yield "c"; + } + }; + } + Object g(int i) { + return switch (i) { case 1 -> "a"; default -> 2; }; + } + Object h(int i) { + return switch (i) { default -> throw new IllegalStateException(); }; + } + Object u(int i) { + return switch (i) { default -> unknown(); }; + } + } + """); + + assertThat(Bindings.switchResultType((SwitchExpressionTreeImpl) switches.get(0)).is("java.lang.String")).isTrue(); + assertThat(Bindings.switchResultType((SwitchExpressionTreeImpl) switches.get(3)).isUnknown()).isTrue(); + assertThat(Bindings.switchResultType((SwitchExpressionTreeImpl) switches.get(4)).isUnknown()).isTrue(); + assertThat(Bindings.switchResultType((SwitchExpressionTreeImpl) switches.get(5)).isUnknown()).isTrue(); + } + + @Test + void type_names_are_identifiers_selections_or_parameterized_types_of_types() throws Exception { + CompilationUnitTree unit = parse(""" + import java.util.List; + class N { + Object f(String s, List l) { + String.valueOf(1); + s.trim(); + java.lang.String.valueOf(2); + l.get(0).trim(); + java.util.function.Function, Integer> size = List::size; + return size; + } + } + """); + List receivers = new ArrayList<>(); + unit.accept(new BaseTreeVisitor() { + @Override + public void visitMethodInvocation(MethodInvocationTree tree) { + if (tree.methodSelect() instanceof org.sonar.plugins.java.api.tree.MemberSelectExpressionTree select && tree.arguments().size() <= 1 + && !"get".equals(select.identifier().name())) { + receivers.add(select.expression()); + } + super.visitMethodInvocation(tree); + } + + @Override + public void visitMethodReference(MethodReferenceTree tree) { + receivers.add((ExpressionTree) tree.expression()); + super.visitMethodReference(tree); + } + }); + + assertThat(receivers).extracting(Bindings::namesType).containsExactly(true, false, true, false, true); + } + + private Type type(String name) { + return sema.getClassType(name); + } + + private List switches(String source) throws Exception { + List found = new ArrayList<>(); + parse(source).accept(new BaseTreeVisitor() { + @Override + public void visitSwitchExpression(SwitchExpressionTree tree) { + found.add(tree); + super.visitSwitchExpression(tree); + } + }); + return found; + } + + private CompilationUnitTree parse(String source) throws Exception { + return Replays.parseWithEcj(baseDir, "BindingsSample", source).get(); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/BundledServerTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/BundledServerTest.java new file mode 100644 index 00000000000..08bf4a122fb --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/BundledServerTest.java @@ -0,0 +1,141 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import com.sonarsource.scanner.engine.sensor.test.fixtures.TestSonarRuntime; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Locale; +import java.util.Optional; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.sonar.api.SonarEdition; +import org.sonar.api.SonarQubeSide; +import org.sonar.api.SonarRuntime; +import org.sonar.api.utils.Version; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +class BundledServerTest { + + @TempDir + Path project; + + @Test + void bundled_server_stays_unused_outside_performance_validation_and_sonarqube_cloud() { + System.clearProperty("sensor.context.key"); + + assertThat(BundledServer.extract(runtime(SonarEdition.COMMUNITY))).isEmpty(); + assertThat(BundledServer.extract(runtime(SonarEdition.ENTERPRISE))).isEmpty(); + } + + @Test + void the_server_follows_the_architecture_of_the_linux_host() { + assertThat(BundledServer.resourceFor("Linux", "amd64")).isEqualTo(BundledServer.RESOURCE_X86_64); + assertThat(BundledServer.resourceFor("Linux", "x86_64")).isEqualTo(BundledServer.RESOURCE_X86_64); + assertThat(BundledServer.resourceFor("Linux", "aarch64")).isEqualTo(BundledServer.RESOURCE_AARCH64); + assertThat(BundledServer.resourceFor("Linux", "arm64")).isEqualTo(BundledServer.RESOURCE_AARCH64); + } + + @Test + void a_host_without_a_bundled_server_fails() { + assertThatThrownBy(() -> BundledServer.resourceFor("Mac OS X", "aarch64")).isInstanceOf(IllegalStateException.class).hasMessageContaining("only runs on Linux"); + assertThatThrownBy(() -> BundledServer.resourceFor("Linux", "riscv64")).isInstanceOf(IllegalStateException.class).hasMessageContaining("riscv64"); + } + + @Test + void both_linux_servers_are_bundled() throws Exception { + for (String resource : new String[] {BundledServer.RESOURCE_X86_64, BundledServer.RESOURCE_AARCH64}) { + try (InputStream in = BundledServer.class.getResourceAsStream(resource)) { + assertThat(in).isNotNull(); + assertThat(in.readNBytes(4)).containsExactly(0x7f, 'E', 'L', 'F'); + } + } + } + + @Test + void the_installed_copy_is_executable() throws Exception { + Path copy = BundledServer.install(new ByteArrayInputStream(new byte[] {1, 2, 3}), "server", project); + + assertThat(Files.isExecutable(copy)).isTrue(); + assertThat(Files.readAllBytes(copy)).containsExactly(1, 2, 3); + } + + @Test + void a_failed_copy_fails_and_leaves_no_file_behind() throws Exception { + InputStream broken = new InputStream() { + @Override + public int read() throws IOException { + throw new IOException("broken"); + } + }; + + assertThatThrownBy(() -> BundledServer.install(broken, "server", project)).isInstanceOf(IllegalStateException.class).hasMessageContaining("could not be copied"); + try (var files = Files.list(project)) { + assertThat(files).isEmpty(); + } + } + + @Test + void the_server_goes_to_the_home_of_the_user() throws Exception { + Path directory = BundledServer.installDirectory(project.toString(), project.resolve("tmp").toString()); + + assertThat(directory).isEqualTo(project.resolve(".sonar").resolve("semsitter")); + } + + @Test + void the_server_goes_to_the_temporary_directory_when_the_home_is_unusable() throws Exception { + Path notADirectory = Files.writeString(project.resolve("home"), "file"); + Path temporary = project.resolve("tmp"); + + assertThat(BundledServer.installDirectory(notADirectory.toString(), temporary.toString())).isEqualTo(temporary); + } + + @Test + void a_missing_bundled_server_fails() { + assertThatThrownBy(() -> BundledServer.install(null, "server", project)).hasMessage("The SemSitter server is not bundled in this plugin."); + } + + @Test + void bundled_linux_server_speaks_the_protocol() throws Exception { + String os = System.getProperty("os.name", "").toLowerCase(Locale.ROOT); + String architecture = System.getProperty("os.arch", ""); + assumeTrue(os.contains("linux") && List.of("amd64", "x86_64", "aarch64", "arm64").contains(architecture)); + System.setProperty("sensor.context.key", BundledServer.PERFORMANCE_VALIDATION_CONTEXT); + try { + Optional server = BundledServer.extract(runtime(SonarEdition.COMMUNITY)); + assertThat(server).isPresent(); + + try (SemSitterClient client = SemSitterClient.start(server.get(), project)) { + assertThat(client).isNotNull(); + } + assertThat(Files.isExecutable(server.get())).isTrue(); + } finally { + System.clearProperty("sensor.context.key"); + } + } + + private static SonarRuntime runtime(SonarEdition edition) { + return TestSonarRuntime.forSonarQube(Version.create(10, 0), SonarQubeSide.SCANNER, edition); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/CastChecksTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/CastChecksTest.java new file mode 100644 index 00000000000..b12bece262b --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/CastChecksTest.java @@ -0,0 +1,248 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.sonar.java.model.ExpressionUtils; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.Arguments; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.BinaryExpressionTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.MethodInvocationTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeCastTree; + +import static org.assertj.core.api.Assertions.assertThat; + +class CastChecksTest { + + private static final String TYPES = """ + { + "java.lang.Object": {"origin": "classpath", "kind": "class", "modifiers": ["public"], "interfaces": [], "typeParameters": 0, "typeVars": [], "members": []}, + "java.lang.Integer": {"origin": "classpath", "kind": "class", "modifiers": ["public", "final"], "super": "java.lang.Number", "interfaces": [], "typeParameters": 0, "typeVars": [], "members": []}, + "java.lang.Number": {"origin": "classpath", "kind": "class", "modifiers": ["public", "abstract"], "super": "java.lang.Object", "interfaces": [], "typeParameters": 0, "typeVars": [], "members": []}, + "java.lang.String": {"origin": "classpath", "kind": "class", "modifiers": ["public", "final"], "super": "java.lang.Object", "interfaces": [], "typeParameters": 0, "typeVars": [], "members": []} + } + """; + + private static final String SOURCE = """ + import java.util.List; + import java.util.function.Supplier; + + class C { + Object field; + + void casts(Object o, int i, long l, byte b) { + var inferred = (String) o; + String declared = (String) o; + field = (String) o; + i += (int) l; + int element = ((int[]) o)[0]; + int length = ((Object[]) o).length; + Supplier expression = () -> (String) o; + Supplier block = () -> { return (String) o; }; + take((String) o); + take(() -> (String) o); + take(() -> { return ((String) o); }); + long shifted = (long) i << 2; + int promoted = (int) b << 2; + long sum = (long) i + l; + double mixed = (double) i * 2; + } + + Object returned(Object o) { + return (String) o; + } + + void take(Object o) { + } + } + """; + + @TempDir + Path baseDir; + + private final JSema sema = new JSema(); + private final List casts = new ArrayList<>(); + private final List binaries = new ArrayList<>(); + + @BeforeEach + void setUp() throws Exception { + sema.loadPackages(name -> null); + sema.loadTypes(names -> new JsonObject()); + sema.ingestTypes(JsonParser.parseString(TYPES).getAsJsonObject()); + Replays.parseWithEcj(baseDir, "CastChecksSample", SOURCE).get().accept(new BaseTreeVisitor() { + @Override + public void visitTypeCast(TypeCastTree tree) { + casts.add(tree); + super.visitTypeCast(tree); + } + + @Override + public void visitBinaryExpression(BinaryExpressionTree tree) { + binaries.add(tree); + super.visitBinaryExpression(tree); + } + }); + } + + @Test + void primitive_assignability_follows_widening() { + assertThat(assignable("int", "long")).isTrue(); + assertThat(assignable("int", "int")).isTrue(); + assertThat(assignable("char", "int")).isTrue(); + assertThat(assignable("char", "short")).isFalse(); + assertThat(assignable("byte", "char")).isFalse(); + assertThat(assignable("long", "int")).isFalse(); + assertThat(assignable("boolean", "int")).isFalse(); + assertThat(assignable("int", "boolean")).isFalse(); + } + + @Test + void only_a_narrowing_primitive_cast_changes_the_value() { + assertThat(castKeepsValue("int", "byte")).isFalse(); + assertThat(castKeepsValue("long", "int")).isFalse(); + assertThat(castKeepsValue("int", "long")).isTrue(); + assertThat(castKeepsValue("int", "int")).isTrue(); + assertThat(castKeepsValue("java.lang.Object", "java.lang.String")).isTrue(); + } + + @Test + void boxing_and_unboxing_are_assignments() { + assertThat(assignable("int", "java.lang.Integer")).isTrue(); + assertThat(assignable("int", "java.lang.Number")).isTrue(); + assertThat(assignable("int", "java.lang.String")).isFalse(); + assertThat(assignable("java.lang.Integer", "long")).isTrue(); + assertThat(assignable("java.lang.String", "int")).isFalse(); + assertThat(assignable("java.lang.String", "java.lang.Object")).isTrue(); + assertThat(assignable("java.lang.Object", "java.lang.String")).isFalse(); + } + + @Test + void display_names_spell_arrays_and_type_arguments() { + Type list = JType.named(sema, "java.util.List", List.of((JType) sema.getClassType("java.lang.String"))); + Type array = sema.getClassType("int[][]"); + + assertThat(CastChecks.displayName(list)).isEqualTo("List"); + assertThat(CastChecks.displayName(array)).isEqualTo("int[][]"); + assertThat(CastChecks.displayName(JType.nullType(sema))).isEqualTo("null"); + assertThat(CastChecks.elementType(array).fullyQualifiedName()).isEqualTo("int"); + } + + @Test + void display_names_spell_member_types_with_their_enclosing_types() { + Type entry = JType.named(sema, "java.util.Map$Entry", List.of((JType) sema.getClassType("java.lang.String"), (JType) sema.getClassType("java.lang.Integer"))); + + assertThat(CastChecks.displayName(sema.getClassType("java.util.Map$Entry"))).isEqualTo("Map.Entry"); + assertThat(CastChecks.displayName(entry)).isEqualTo("Map.Entry"); + assertThat(CastChecks.displayName(JType.named(sema, "a.Outer$1Local", List.of()))).isEqualTo("Local"); + assertThat(CastChecks.displayName(JType.named(sema, "a.Outer$1Local$Inner", List.of()))).isEqualTo("Local.Inner"); + } + + @Test + void the_assigned_type_is_the_declared_type_of_the_target() { + assertThat(assignedTo(0)).isEmpty(); + assertThat(assignedTo(1)).hasValueSatisfying(type -> assertThat(type.is("java.lang.String")).isTrue()); + assertThat(assignedTo(2)).hasValueSatisfying(type -> assertThat(type.is("java.lang.Object")).isTrue()); + assertThat(assignedTo(3)).isEmpty(); + assertThat(assignedTo(6)).hasValueSatisfying(type -> assertThat(type.is("java.lang.Object")).isTrue()); + assertThat(assignedTo(7)).isEmpty(); + assertThat(assignedTo(8)).isEmpty(); + assertThat(assignedTo(9)).isEmpty(); + assertThat(assignedTo(casts.size() - 1)).hasValueSatisfying(type -> assertThat(type.is("java.lang.Object")).isTrue()); + } + + @Test + void an_argument_has_the_parameter_type_only_when_no_overload_of_the_owner_or_its_supertypes_could_take_it() throws Exception { + ReplayTest.loadRecordings(); + List arguments = new ArrayList<>(); + ReplayTest.translate("CastContexts").get().accept(new BaseTreeVisitor() { + @Override + public void visitTypeCast(TypeCastTree tree) { + if (tree.parent() instanceof Arguments && tree.parent().parent() instanceof MethodInvocationTree) { + arguments.add(tree); + } + super.visitTypeCast(tree); + } + }); + + assertThat(CastChecks.assignedTo(castPassedTo(arguments, "take"))).hasValueSatisfying(type -> assertThat(type.is("java.lang.Object")).isTrue()); + assertThat(CastChecks.assignedTo(castPassedTo(arguments, "overloaded"))).isEmpty(); + assertThat(CastChecks.assignedTo(castPassedTo(arguments, "varargs"))).isEmpty(); + } + + private static TypeCastTree castPassedTo(List casts, String method) { + return casts.stream() + .filter(cast -> ((MethodInvocationTree) cast.parent().parent()).methodSymbol().name().equals(method)) + .findFirst() + .orElseThrow(); + } + + @Test + void an_indexed_array_is_the_expression_of_an_array_access() { + assertThat(CastChecks.isIndexedArray(casts.get(4))).isTrue(); + assertThat(CastChecks.isIndexedArray(casts.get(5))).isFalse(); + assertThat(CastChecks.isIndexedArray(casts.get(1))).isFalse(); + } + + @Test + void the_result_of_a_lambda_argument_can_fix_the_inferred_call() { + assertThat(CastChecks.isResultOfArgumentLambda(casts.get(9))).isTrue(); + assertThat(CastChecks.isResultOfArgumentLambda(casts.get(10))).isTrue(); + assertThat(CastChecks.isResultOfArgumentLambda(casts.get(6))).isFalse(); + assertThat(CastChecks.isResultOfArgumentLambda(casts.get(7))).isFalse(); + assertThat(CastChecks.isResultOfArgumentLambda(casts.get(1))).isFalse(); + } + + @Test + void a_widening_cast_is_redundant_when_the_promotion_gives_the_same_types() { + assertThat(sameOperandTypes(binaries.get(0))).isFalse(); + assertThat(sameOperandTypes(binaries.get(1))).isTrue(); + assertThat(sameOperandTypes(binaries.get(2))).isTrue(); + assertThat(sameOperandTypes(binaries.get(3))).isFalse(); + assertThat(CastChecks.isWideningPrimitiveCast(binaries.get(0))).isFalse(); + assertThat(CastChecks.castMessage(casts.get(11))).isEqualTo("Unnecessary cast from int to long"); + } + + private boolean sameOperandTypes(BinaryExpressionTree binary) { + ExpressionTree left = ExpressionUtils.skipParentheses(binary.leftOperand()); + ExpressionTree right = ExpressionUtils.skipParentheses(binary.rightOperand()); + Tree.Kind kind = binary.kind(); + return CastChecks.sameOperandTypes(kind, CastChecks.promotionInput(left, true), CastChecks.promotionInput(right, false), left, right); + } + + private Optional assignedTo(int index) { + return CastChecks.assignedTo(casts.get(index)); + } + + private boolean castKeepsValue(String operand, String cast) { + return CastChecks.castKeepsValue(sema.getClassType(operand), sema.getClassType(cast), sema.substitution()); + } + + private boolean assignable(String from, String to) { + return CastChecks.isAssignable(sema.getClassType(from), sema.getClassType(to), sema.substitution()); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/CompilerWarningsTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/CompilerWarningsTest.java new file mode 100644 index 00000000000..d69da700110 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/CompilerWarningsTest.java @@ -0,0 +1,118 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.sonar.plugins.java.api.tree.AssignmentExpressionTree; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.VariableTree; + +import static org.assertj.core.api.Assertions.assertThat; + +class CompilerWarningsTest { + + private static final String SOURCE = """ + class A { + int plain; + volatile int shared; + void m(int local) { + int inner = 0; + plain = plain; + shared = shared; + local += local; + inner = local; + } + } + """; + + @TempDir + Path baseDir; + + @Test + void a_reference_names_its_type_and_the_parameter_types_of_a_method() { + assertThat(CompilerWarnings.referenceNames("Foo#bar(List, Map) the label")).containsExactly("Foo", "List", "Map"); + assertThat(CompilerWarnings.referenceNames("#m(A)")).containsExactly("m", "A"); + } + + @Test + void a_qualified_parameter_type_names_only_its_first_segment() { + assertThat(CompilerWarnings.referenceNames("#m(java.util.List, Map)")).containsExactly("m", "java", "Map"); + } + + @Test + void a_reference_wrapped_onto_a_continuation_line_is_read_without_its_star() { + assertThat(CompilerWarnings.javadocReferenceNames("/**\n * {@link\n * Foo}\n * @see\n * Bar\n */")).containsExactly("Foo", "Bar"); + assertThat(CompilerWarnings.javadocReferenceNames("/// [Baz]")).containsExactly("Baz"); + } + + @Test + void the_description_after_a_reference_names_nothing() { + assertThat(CompilerWarnings.referenceNames("IllegalStateException if the cache (Set by init) is stale")).containsExactly("IllegalStateException"); + assertThat(CompilerWarnings.referenceNames("#m(A)) label (B)")).containsExactly("m", "A"); + } + + @Test + void only_a_plain_self_assignment_of_a_non_volatile_variable_has_no_effect() throws Exception { + List assignments = new ArrayList<>(); + parse().accept(new BaseTreeVisitor() { + @Override + public void visitAssignmentExpression(AssignmentExpressionTree tree) { + assignments.add(tree); + super.visitAssignmentExpression(tree); + } + }); + + assertThat(assignments).extracting(CompilerWarnings::hasNoEffect).containsExactly(true, false, false, false); + } + + @Test + void only_the_comments_of_members_and_types_document_a_declaration() throws Exception { + List declarations = new ArrayList<>(); + parse().accept(new BaseTreeVisitor() { + @Override + public void visitClass(ClassTree tree) { + declarations.add(tree); + super.visitClass(tree); + } + + @Override + public void visitMethod(MethodTree tree) { + declarations.add(tree); + super.visitMethod(tree); + } + + @Override + public void visitVariable(VariableTree tree) { + declarations.add(tree); + super.visitVariable(tree); + } + }); + + assertThat(declarations).extracting(CompilerWarnings::isDocumentedDeclaration).containsExactly(true, true, true, true, false, false); + } + + private Tree parse() throws Exception { + return Replays.parseWithEcj(baseDir, "A", SOURCE).get(); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/CstNodesTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/CstNodesTest.java new file mode 100644 index 00000000000..2ce33707590 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/CstNodesTest.java @@ -0,0 +1,143 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.sonar.java.ast.parser.ArgumentListTreeImpl; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.KeywordSuper; +import org.sonar.java.model.KeywordThis; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.java.model.expression.MemberSelectExpressionTreeImpl; +import org.sonar.java.model.expression.MethodInvocationTreeImpl; +import org.sonar.plugins.java.api.tree.Modifier; +import org.sonarsource.semsitter.wire.Node; +import org.sonarsource.semsitter.wire.Ref; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.sonar.java.semsitter.TranslationStateFixtures.inner; +import static org.sonar.java.semsitter.TranslationStateFixtures.leaf; + +class CstNodesTest { + + @Test + void first_problem_is_an_error_or_a_missing_node() { + Node missing = leaf(";", "", 2, 4).toBuilder().setMissing(true).build(); + + assertThat(CstNodes.firstProblem(node(inner("program", leaf("x", "x", 1, 0), missing)))).extracting(CstNode::line).isEqualTo(2); + assertThat(CstNodes.firstProblem(node(inner("ERROR")))).extracting(CstNode::k).isEqualTo("ERROR"); + assertThat(CstNodes.firstProblem(node(inner("program", leaf("x", "x", 1, 0))))).isNull(); + } + + @Test + void enum_separator_is_a_comma_or_starts_the_body_declarations() { + Node comma = leaf(",", ",", 1, 1); + Node semicolon = leaf(";", ";", 1, 3); + List siblings = node(inner("enum_body", leaf("A", "A", 1, 0), comma, leaf("B", "B", 1, 2), inner("enum_body_declarations", semicolon), leaf("}", "}", 1, 4))).children(); + + assertThat(CstNodes.enumSeparator(siblings, 0).proto).isSameAs(comma); + assertThat(CstNodes.enumSeparator(siblings, 2).proto).isSameAs(semicolon); + assertThat(CstNodes.enumSeparator(siblings, 3)).isNull(); + } + + @Test + void dotted_name_of_a_qualified_name() { + IdentifierTreeImpl java = identifier("java"); + MemberSelectExpressionTreeImpl javaUtil = new MemberSelectExpressionTreeImpl(java, token("."), identifier("util")); + MethodInvocationTreeImpl call = new MethodInvocationTreeImpl(identifier("call"), null, ArgumentListTreeImpl.emptyList()); + + assertThat(CstNodes.dottedName(javaUtil)).isEqualTo("java.util"); + assertThat(CstNodes.dottedName(new MemberSelectExpressionTreeImpl(call, token("."), identifier("x")))).isEmpty(); + assertThat(CstNodes.dottedName(call)).isEmpty(); + } + + @Test + void receiver_keywords_are_this_and_super() { + IdentifierTreeImpl name = identifier("name"); + + assertThat(CstNodes.receiverKeyword(identifier("this"))).isInstanceOf(KeywordThis.class); + assertThat(CstNodes.receiverKeyword(identifier("super"))).isInstanceOf(KeywordSuper.class); + assertThat(CstNodes.receiverKeyword(name)).isSameAs(name); + } + + @Test + void modifier_keywords() { + assertThat(CstNodes.modifierKeyword("strictfp")).isEqualTo(Modifier.STRICTFP); + assertThat(CstNodes.modifierKeyword("non-sealed")).isEqualTo(Modifier.NON_SEALED); + assertThatThrownBy(() -> CstNodes.modifierKeyword("transitive")).isInstanceOf(IllegalArgumentException.class).hasMessage("Not a modifier: transitive"); + } + + @Test + void keyword_lookups_fall_back_to_the_node() { + CstNode node = node(inner("block", leaf("{", "{", 1, 0), leaf("}", "}", 1, 1))); + + assertThat(CstNodes.lastKeyword(node, ";")).isSameAs(node); + assertThat(CstNodes.required(node, ";")).isSameAs(node); + assertThat(CstNodes.requiredField(node, "body", null)).isSameAs(node); + assertThat(CstNodes.requiredField(node, "body", node.children().get(0)).text()).isEqualTo("{"); + assertThat(CstNodes.nameNode(node)).isNull(); + assertThat(CstNodes.closingAngle(node(inner("type_arguments", leaf("<", "<", 3, 1), leaf(">", ">", 3, 5))))) + .extracting(InternalSyntaxToken::text, InternalSyntaxToken::line, InternalSyntaxToken::column).containsExactly(">", 3, 5); + } + + @Test + void same_needs_two_nodes_of_one_proto() { + Node proto = leaf("x", "x", 1, 0); + + assertThat(CstNodes.same(node(proto), node(proto))).isTrue(); + assertThat(CstNodes.same(node(proto), node(leaf("x", "x", 1, 0)))).isFalse(); + assertThat(CstNodes.same(null, node(proto))).isFalse(); + assertThat(CstNodes.same(node(proto), null)).isFalse(); + } + + @Test + void first_named_skips_punctuation() { + Node identifier = leaf("identifier", "a", 1, 1); + Node keyword = leaf("int", "int", 1, 0); + + assertThat(CstNodes.firstNamed(node(inner("x", leaf("(", "(", 1, 0), identifier))).proto).isSameAs(identifier); + assertThat(CstNodes.firstNamed(node(inner("x", keyword))).proto).isSameAs(keyword); + assertThat(CstNodes.firstNamed(node(inner("x", leaf("+", "-", 1, 0), leaf("type_identifier", "T", 1, 1)))).text()).isEqualTo("T"); + CstNode empty = node(inner("x")); + assertThat(CstNodes.firstNamed(empty)).isSameAs(empty); + } + + @Test + void only_bound_references_with_a_target_are_targets() { + Node.Builder name = leaf("identifier", "a", 1, 0).toBuilder() + .addRefs(Ref.newBuilder().setAccess("r").setOutcome("bound")) + .addRefs(Ref.newBuilder().setAccess("r").setOutcome("ambiguous").setTarget("A#a")) + .addRefs(Ref.newBuilder().setAccess("ref").setOutcome("bound").setTarget("A")); + + assertThat(node(name.build()).valueTarget()).isNull(); + assertThat(node(name.build()).typeTarget()).isEqualTo("A"); + } + + private static CstNode node(Node proto) { + return new CstNode(proto); + } + + private static IdentifierTreeImpl identifier(String name) { + return new IdentifierTreeImpl(token(name)); + } + + private static InternalSyntaxToken token(String text) { + return new InternalSyntaxToken(1, 0, text, List.of(), false); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/EffectivelyFinalVariablesTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/EffectivelyFinalVariablesTest.java new file mode 100644 index 00000000000..8d1eb62d507 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/EffectivelyFinalVariablesTest.java @@ -0,0 +1,104 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.sonar.plugins.java.api.tree.AssignmentExpressionTree; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.CompilationUnitTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.VariableTree; + +import static org.assertj.core.api.Assertions.assertThat; + +class EffectivelyFinalVariablesTest { + + private static final String SOURCE = """ + class A { + void m(boolean c, int k) { + int ifElse; if (c) ifElse = 1; else ifElse = 2; + int sequence; sequence = 1; sequence = 2; + int loop; while (c) { loop = 1; } + int arrows; switch (k) { case 1 -> arrows = 1; default -> arrows = 2; } + int colons; switch (k) { case 1: colons = 1; default: colons = 2; } + int sameArm; if (c) { sameArm = 1; sameArm = 2; } + int noElse; if (c) noElse = 1; noElse = 2; + for (int init; c;) { init = 1; } + boolean nested; if (nested = (nested = c)) { } else { } + } + } + """; + + @TempDir + Path baseDir; + + private final Map variables = new HashMap<>(); + private final Map> assignments = new HashMap<>(); + + @BeforeEach + void parse() throws Exception { + CompilationUnitTree unit = (CompilationUnitTree) Replays.parseWithEcj(baseDir, "A", SOURCE).get(); + unit.accept(new BaseTreeVisitor() { + @Override + public void visitVariable(VariableTree tree) { + variables.put(tree.simpleName().name(), tree); + super.visitVariable(tree); + } + + @Override + public void visitAssignmentExpression(AssignmentExpressionTree tree) { + assignments.computeIfAbsent(((IdentifierTree) tree.variable()).name(), name -> new ArrayList<>()).add(tree); + super.visitAssignmentExpression(tree); + } + }); + } + + @Test + void assignments_in_exclusive_branches_count_once() { + assertThat(assignedOnce("ifElse")).isTrue(); + assertThat(assignedOnce("arrows")).isTrue(); + } + + @Test + void repeated_or_sequential_assignments_do_not() { + assertThat(assignedOnce("sequence")).isFalse(); + assertThat(assignedOnce("loop")).isFalse(); + assertThat(assignedOnce("colons")).isFalse(); + assertThat(assignedOnce("sameArm")).isFalse(); + assertThat(assignedOnce("noElse")).isFalse(); + assertThat(assignedOnce("init")).isFalse(); + assertThat(assignedOnce("nested")).isFalse(); + } + + @Test + void a_for_initializer_declares_a_local() { + assertThat(EffectivelyFinalVariables.isLocalDeclaration(variables.get("init"))).isTrue(); + assertThat(EffectivelyFinalVariables.isLocalDeclaration(variables.get("k"))).isFalse(); + } + + private boolean assignedOnce(String name) { + return EffectivelyFinalVariables.assignedOnce(variables.get(name), assignments.get(name)); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ExpressionTranslatorTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ExpressionTranslatorTest.java new file mode 100644 index 00000000000..99951e5c77c --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ExpressionTranslatorTest.java @@ -0,0 +1,130 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.nio.file.Path; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.AnnotationTree; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.CompilationUnitTree; +import org.sonar.plugins.java.api.tree.ConditionalExpressionTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.NewArrayTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeCastTree; +import org.sonar.plugins.java.api.tree.UnaryExpressionTree; +import org.sonar.plugins.java.api.tree.VariableTree; +import org.sonarsource.semsitter.wire.Node; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.java.semsitter.TranslationStateFixtures.all; +import static org.sonar.java.semsitter.TranslationStateFixtures.inner; +import static org.sonar.java.semsitter.TranslationStateFixtures.kind; +import static org.sonar.java.semsitter.TranslationStateFixtures.leaf; +import static org.sonar.java.semsitter.TranslationStateFixtures.mutate; +import static org.sonar.java.semsitter.TranslationStateFixtures.recorded; +import static org.sonar.java.semsitter.TranslationStateFixtures.text; +import static org.sonar.java.semsitter.TranslationStateFixtures.translate; +import static org.sonar.java.semsitter.TranslationStateFixtures.unresolved; +import static org.sonar.java.semsitter.TranslationStateFixtures.where; + +class ExpressionTranslatorTest { + + @Test + void an_annotation_is_an_element_value() { + Node nested = inner("marker_annotation", leaf("@", "@", 32, 10), leaf("identifier", "Nested", 32, 11).toBuilder().setField("name").build()); + CompilationUnitTree unit = translate(mutate(recorded("Annotations"), where(text("\"single\""), node -> nested)), 21); + + AnnotationTree config = all(unit, AnnotationTree.class).stream() + .filter(annotation -> annotation.arguments().size() == 1 && annotation.arguments().get(0) instanceof AnnotationTree) + .findFirst().orElseThrow(); + + assertThat(((AnnotationTree) config.arguments().get(0)).annotationType().symbolType().name()).isEqualTo("Nested"); + } + + @Test + void an_intersection_cast_separates_each_bound() { + CompilationUnitTree unit = translate(mutate(recorded("Unresolved"), where(kind("cast_expression"), ExpressionTranslatorTest::withTwoMoreBounds)), 21); + + TypeCastTree cast = all(unit, TypeCastTree.class).get(0); + + assertThat(cast.andToken()).isNotNull(); + assertThat(cast.bounds()).hasSize(2); + assertThat(cast.bounds().separators()).hasSize(1); + } + + @Test + void a_conditional_of_a_boolean_and_a_number_has_the_type_of_its_first_operand() { + CompilationUnitTree unit = translate(mutate(recorded("Imports"), where(kind("decimal_integer_literal").and(text("1")).and(node -> node.getStartLine() == 65), + node -> node.toBuilder().setKind("true").setText("true").build())), 21); + + ConditionalExpressionTree conditional = all(unit, ConditionalExpressionTree.class).get(0); + + assertThat(conditional.trueExpression().is(Tree.Kind.BOOLEAN_LITERAL)).isTrue(); + assertThat(conditional.symbolType().is("boolean")).isTrue(); + } + + @Test + void a_conditional_of_a_type_variable_and_an_unrelated_type_has_the_bound_of_the_variable() { + CompilationUnitTree unit = translate(mutate(recorded("Generics"), where(node -> node.getStartLine() == 43 && "alternative".equals(node.getField()), + node -> leaf("string_literal", "\"x\"", 43, node.getStartCol()).toBuilder().setField("alternative").build())), 21); + + ConditionalExpressionTree conditional = all(unit, ConditionalExpressionTree.class).get(0); + + assertThat(conditional.falseExpression().is(Tree.Kind.STRING_LITERAL)).isTrue(); + assertThat(conditional.symbolType().erasure().is("java.lang.Comparable")).isTrue(); + } + + @Test + void a_negated_unknown_operand_stays_unknown() { + CompilationUnitTree unit = translate(mutate(recorded("Imports"), where(text("value").and(node -> node.getStartLine() == 27 && node.getRefsCount() > 0), + node -> unresolved(node.toBuilder().setText("ghost").build()))), 21); + + UnaryExpressionTree negation = all(unit, UnaryExpressionTree.class).stream().filter(tree -> tree.is(Tree.Kind.UNARY_MINUS)).findFirst().orElseThrow(); + + assertThat(negation.expression().symbolType().isUnknown()).isTrue(); + assertThat(negation.symbolType().isUnknown()).isTrue(); + } + + private static Node withTwoMoreBounds(Node cast) { + return cast.toBuilder() + .addChildren(2, leaf("&", "&", 35, 30)) + .addChildren(3, leaf("type_identifier", "First", 35, 32).toBuilder().setField("type").build()) + .addChildren(4, leaf("&", "&", 35, 38)) + .addChildren(5, leaf("type_identifier", "Second", 35, 40).toBuilder().setField("type").build()) + .build(); + } + + @Test + void an_int_constant_narrows_a_conditional_only_when_it_fits(@TempDir Path baseDir) throws Exception { + CompilationUnitTree unit = (CompilationUnitTree) Replays.parseWithEcj(baseDir, "B", "class B { int x; int[] v = {127, 128, -128, -129, 32767, 32768, 65535, -1, x}; }").get(); + List values = ((NewArrayTree) ((VariableTree) ((ClassTree) unit.types().get(0)).members().get(1)).initializer()).initializers(); + JSema sema = new JSema(); + Type byteType = sema.primitiveType("byte"); + Type shortType = sema.primitiveType("short"); + Type charType = sema.primitiveType("char"); + + assertThat(values.subList(0, 4)).extracting(value -> ExpressionTranslator.fitsIn(value, byteType)).containsExactly(true, false, true, false); + assertThat(values.subList(4, 6)).extracting(value -> ExpressionTranslator.fitsIn(value, shortType)).containsExactly(true, false); + assertThat(values.subList(6, 8)).extracting(value -> ExpressionTranslator.fitsIn(value, charType)).containsExactly(true, false); + assertThat(ExpressionTranslator.fitsIn(values.get(8), byteType)).isFalse(); + } + +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/FactTypesTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/FactTypesTest.java index 3738ab411d9..156dcc2f899 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/FactTypesTest.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/FactTypesTest.java @@ -156,6 +156,20 @@ void type_parameter_items_name_the_variables_of_classes_and_callables_by_positio assertThat(types.typeFromName("p.A::`").isTypeVar()).isFalse(); assertThat(types.typeFromName("p.A::`x").isTypeVar()).isFalse(); assertThat(types.typeFromName("int[]").fullyQualifiedName()).isEqualTo("int[]"); + assertThat(types.typeFromName("java::p.G`1::`0[]")).satisfies(array -> { + assertThat(array.isArray()).isTrue(); + assertThat(((Type.ArrayType) array).elementType().name()).isEqualTo("E"); + }); + } + + @Test + void array_terms_are_the_arrays_of_their_element() { + assertThat(types.typeFromName("java::byte[]").fullyQualifiedName()).isEqualTo("byte[]"); + assertThat(types.typeFromName("java::int[][]").fullyQualifiedName()).isEqualTo("int[][]"); + assertThat(types.typeFromName("java::java.lang.String[]").fullyQualifiedName()).isEqualTo("java.lang.String[]"); + assertThat(types.typeFromName("java::java.util.List`1[]").fullyQualifiedName()).isEqualTo("java.util.List[]"); + assertThat(types.typeFromName("java::byte[]")).isEqualTo(types.typeFromName("byte[]")); + assertThat(types.typeFromName("java::{a1b2}").isUnknown()).isTrue(); } @Test diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/FakeServer.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/FakeServer.java index c49b4495348..e284d73f87c 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/FakeServer.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/FakeServer.java @@ -88,7 +88,16 @@ private static void serve(List args, InputStream in, OutputStream out) t private static byte[] answer(JsonObject request, JsonObject header) { switch (request.get("cmd").getAsString()) { case "set-settings" -> header.add("settings", request.get("settings")); - case "full-gen" -> header.addProperty("files", request.has("files") ? request.getAsJsonArray("files").size() : 0); + case "full-gen" -> { + if (request.has("files")) { + header.addProperty("files", request.getAsJsonArray("files").size()); + header.addProperty("elapsed_ms", 42); + header.addProperty("failures", 1); + header.addProperty("peak_rss_kb", 2048); + } else { + header.addProperty("files", 0); + } + } case "get-file" -> { String path = request.get("path").getAsString(); if (path.endsWith("Nope.java")) { diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/FunctionalInferenceTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/FunctionalInferenceTest.java index 80db4e62ec4..fc88f56bf3e 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/FunctionalInferenceTest.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/FunctionalInferenceTest.java @@ -16,23 +16,175 @@ */ package org.sonar.java.semsitter; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; import org.junit.jupiter.api.Test; +import org.sonar.plugins.java.api.semantic.Type; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.java.semsitter.JTypeFixtures.json; class FunctionalInferenceTest { + private static final String FUNCTION = "java.util.function.Function"; + private static final String SUPPLIER = "java.util.function.Supplier"; + private static final String OPTIONAL = "java.util.Optional"; + private static final String LIST = "java.util.List"; + private static final String COLLECTIONS = "java.util.Collections"; + private static final String T = "{\"id\": \"T\", \"kind\": \"typevar\"}"; + private static final String LIST_OF_T = "{\"id\": \"java.util.List\", \"args\": [" + T + "]}"; + private final JTypeFixtures fixtures = new JTypeFixtures(); - private final FunctionalInference functional = fixtures.sema.functionalInference(); + private final FunctionalInference inference = fixtures.sema.functionalInference(); + + @Test + void function_producing_a_value_knows_only_its_result() { + Type function = inference.functionProducing(fixtures.type(FUNCTION, fixtures.string(), fixtures.object()), fixtures.primitive("int")); + + assertThat(function.erasure()).isEqualTo(fixtures.type(FUNCTION)); + assertThat(function.typeArguments().get(0).isUnknown()).isTrue(); + assertThat(function.typeArguments().get(1)).isEqualTo(fixtures.integer()); + assertThat(inference.functionProducing(fixtures.type(SUPPLIER, fixtures.object()), fixtures.string()).typeArguments()).containsExactly(fixtures.string()); + } + + @Test + void function_producing_needs_a_parameterized_functional_interface_and_a_known_value() { + JType function = fixtures.type(FUNCTION, fixtures.string(), fixtures.object()); + JType variable = JType.typeVar(fixtures.sema, "E", "lib.Other`1"); + + assertThat(inference.functionProducing(fixtures.type(FUNCTION), fixtures.string())).isNull(); + assertThat(inference.functionProducing(Type.UNKNOWN, fixtures.string())).isNull(); + assertThat(inference.functionProducing(function, Type.UNKNOWN)).isNull(); + assertThat(inference.functionProducing(function, variable)).isNull(); + assertThat(inference.functionProducing(function, fixtures.type(LIST, variable))).isNull(); + assertThat(inference.functionProducing(fixtures.type(LIST, fixtures.string()), fixtures.string())).isNull(); + assertThat(inference.functionProducing(fixtures.type("java.util.function.Consumer", fixtures.string()), fixtures.string())).isNull(); + assertThat(inference.functionProducing(fixtures.type(FUNCTION, fixtures.string()), fixtures.string())).isNull(); + } + + @Test + void methods_returning_a_type_variable_are_recognized() { + assertThat(inference.returnsClassVariable(fixtures.method(OPTIONAL, "get"))).isTrue(); + assertThat(inference.returnsClassVariable(fixtures.method("java.lang.String", "length"))).isFalse(); + assertThat(inference.returnsClassVariable(fixtures.method("java.lang.Object", "clone"))).isFalse(); + JMethodSymbol source = new JMethodSymbol(fixtures.sema, null, "get"); + source.returnTypeSymbol(fixtures.sema.memberFactory().typeParameter("lib.Box`1").type().symbol()); + assertThat(inference.returnsClassVariable(source)).isTrue(); + } + + @Test + void unbound_reference_takes_its_result_from_the_receiver_the_function_applies_to() { + JMethodSymbol get = fixtures.method(OPTIONAL, "get"); + + assertThat(inference.unboundReferenceResult(get, fixtures.type(FUNCTION, fixtures.type(OPTIONAL, fixtures.string()), fixtures.object()))) + .isEqualTo(fixtures.string()); + assertThat(inference.unboundReferenceResult(get, fixtures.type(FUNCTION, JType.superWildcard(fixtures.sema, fixtures.type(OPTIONAL, fixtures.string())), + fixtures.object()))).isEqualTo(fixtures.string()); + } + + @Test + void unbound_reference_result_is_unknown_without_a_known_receiver() { + JMethodSymbol get = fixtures.method(OPTIONAL, "get"); + JType variable = JType.typeVar(fixtures.sema, "E", "lib.Other`1"); + + assertThat(inference.unboundReferenceResult(get, fixtures.type(FUNCTION, fixtures.type(OPTIONAL), fixtures.object()))).isNull(); + assertThat(inference.unboundReferenceResult(get, fixtures.type(FUNCTION, fixtures.string(), fixtures.object()))).isNull(); + assertThat(inference.unboundReferenceResult(get, fixtures.type(FUNCTION, JType.unknown(fixtures.sema), fixtures.object()))).isNull(); + assertThat(inference.unboundReferenceResult(get, fixtures.type(FUNCTION, fixtures.type(OPTIONAL, variable), fixtures.object()))).isNull(); + assertThat(inference.unboundReferenceResult(get, fixtures.type(SUPPLIER, fixtures.string()))).isNull(); + assertThat(inference.unboundReferenceResult(get, fixtures.string())).isNull(); + } + + @Test + void unbound_reference_result_is_unknown_for_static_or_generic_methods() { + JType function = fixtures.type(FUNCTION, fixtures.type("java.util.stream.Stream", fixtures.string()), fixtures.object()); + + assertThat(inference.unboundReferenceResult(fixtures.method("java.util.stream.Stream", "collect", "java.util.stream.Collector"), function)).isNull(); + assertThat(inference.unboundReferenceResult(fixtures.method(COLLECTIONS, "singletonList", "java.lang.Object"), function)).isNull(); + } @Test - void functional_types_are_unknown_until_inference_lands() { - JMethodSymbol valueOf = fixtures.method("java.lang.String", "valueOf", "java.lang.Object"); - JType string = fixtures.string(); + void target_fixes_the_parameters_of_a_generic_method() { + JMethodSymbol singletonList = fixtures.method(COLLECTIONS, "singletonList", "java.lang.Object"); + JMethodSymbol entry = fixtures.method("java.util.Map", "entry", "java.lang.Object", "java.lang.Object"); + + assertThat(inference.targetedParameters(singletonList, fixtures.type(LIST, fixtures.string()))).containsExactly(fixtures.string()); + assertThat(inference.targetedParameters(singletonList, fixtures.type("java.util.Collection", fixtures.string()))).containsExactly(fixtures.string()); + assertThat(inference.targetedParameters(entry, fixtures.type("java.util.Map$Entry", fixtures.string(), fixtures.extending(fixtures.object())))) + .containsExactly(fixtures.string(), Type.UNKNOWN); + } + + @Test + void target_fixes_nothing_for_other_methods() { + JMethodSymbol singletonList = fixtures.method(COLLECTIONS, "singletonList", "java.lang.Object"); + + assertThat(inference.targetedParameters(singletonList, fixtures.string())).isNull(); + assertThat(inference.targetedParameters(singletonList, fixtures.type("java.util.Map", fixtures.string(), fixtures.string()))).isNull(); + assertThat(inference.targetedParameters(fixtures.method(COLLECTIONS, "emptyList"), fixtures.type(LIST, fixtures.string()))).isNull(); + assertThat(inference.targetedParameters(fixtures.method(OPTIONAL, "get"), fixtures.string())).isNull(); + assertThat(inference.targetedParameters(fixtures.method("java.lang.Object", "clone"), fixtures.string())).isNull(); + assertThat(inference.targetedParameters(fixtures.method("java.util.ArrayList", "", "java.util.Collection"), fixtures.string())).isNull(); + assertThat(inference.targetedParameters(singletonList, Type.UNKNOWN)).isNull(); + assertThat(inference.targetedParameters(fixtures.method("java.util.Objects", "requireNonNull", "java.lang.Object"), fixtures.type(LIST, fixtures.type("lib.Missing")))) + .isNull(); + } + + @Test + void target_binds_only_the_variables_its_supertype_arguments_name() { + JType collection = fixtures.type("java.util.Collection", fixtures.string()); + + assertThat(bindReturn(LIST_OF_T, fixtures.type("java.util.Collection", fixtures.extending(fixtures.string())), Set.of("T"))).isEmpty(); + assertThat(bindReturn(LIST_OF_T, collection, Set.of("U"))).isEmpty(); + assertThat(bindReturn("{\"id\": \"java.util.List\", \"args\": [{\"id\": \"java.lang.String\"}]}", collection, Set.of("T"))).isEmpty(); + assertThat(bindReturn(LIST_OF_T, collection, Set.of("T"))).containsEntry("T", fixtures.string()); + } + + @Test + void binds_type_variables_through_wildcards_arrays_and_supertypes() { + assertThat(bind("{\"kind\": \"wildcard\", \"super\": " + T + "}", fixtures.string())).containsEntry("T", fixtures.string()); + assertThat(bind("{\"kind\": \"wildcard\", \"extends\": " + T + "}", fixtures.string())).containsEntry("T", fixtures.string()); + assertThat(bind("{\"kind\": \"wildcard\"}", fixtures.string())).isEmpty(); + assertThat(bind("{\"kind\": \"array\", \"elem\": " + T + "}", JType.array(fixtures.sema, fixtures.primitive("int")))).containsEntry("T", fixtures.integer()); + assertThat(bind("{\"kind\": \"array\", \"elem\": " + T + "}", fixtures.string())).isEmpty(); + assertThat(bind(LIST_OF_T, fixtures.type("java.util.ArrayList", fixtures.string()))).containsEntry("T", fixtures.string()); + assertThat(bind(LIST_OF_T, fixtures.type("java.util.ArrayList"))).isEmpty(); + assertThat(bind(LIST_OF_T, fixtures.string())).isEmpty(); + assertThat(bind("{\"id\": \"java.util.List\", \"args\": [\"T\"]}", fixtures.type(LIST, fixtures.string()))).isEmpty(); + assertThat(bind("{\"id\": \"java.util.List\", \"args\": []}", fixtures.type(LIST, fixtures.string()))).isEmpty(); + assertThat(bind("{\"args\": [" + T + "]}", fixtures.type(LIST, fixtures.string()))).isEmpty(); + assertThat(bind("{\"id\": \"U\", \"kind\": \"typevar\"}", fixtures.string())).isEmpty(); + } + + @Test + void binds_nothing_from_open_or_unknown_types() { + JType variable = JType.typeVar(fixtures.sema, "E", "lib.Other`1"); + + assertThat(bind(T, Type.UNKNOWN)).isEmpty(); + assertThat(bind(T, JType.nullType(fixtures.sema))).isEmpty(); + assertThat(bind(T, variable)).isEmpty(); + assertThat(bind(T, fixtures.extending(fixtures.object()))).isEmpty(); + assertThat(bind(T, fixtures.object())).containsEntry("T", fixtures.object()); + } + + @Test + void bound_of_a_wildcard_binds_as_a_capture() { + Type bound = bind(T, fixtures.extending(fixtures.string())).get("T"); + + assertThat(((JType) bound).isCapture()).isTrue(); + assertThat(bound.erasure()).isEqualTo(fixtures.string()); + assertThat(bind(T, JType.superWildcard(fixtures.sema, fixtures.string()))).containsEntry("T", fixtures.string()); + } + + private Map bindReturn(String declared, Type target, Set variables) { + Map bound = new HashMap<>(); + inference.bindReturnToTarget(json(declared), target, variables, bound); + return bound; + } - assertThat(functional.functionProducing(string, string)).isNull(); - assertThat(functional.returnsClassVariable(valueOf)).isFalse(); - assertThat(functional.unboundReferenceResult(valueOf, string)).isNull(); - assertThat(functional.targetedParameters(valueOf, string)).isNull(); + private Map bind(String declared, Type actual) { + Map bound = new HashMap<>(); + inference.bindFromType(json(declared), actual, Set.of("T"), bound); + return bound; } } diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ImportScopesTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ImportScopesTest.java new file mode 100644 index 00000000000..d44793b9b32 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ImportScopesTest.java @@ -0,0 +1,212 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.CompilationUnitTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.ImportTree; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.NewClassTree; + +import static org.assertj.core.api.Assertions.assertThat; + +class ImportScopesTest { + + private static final String SOURCE = """ + package p; + + import p.A; + import p.*; + import static p.A.x; + import q.B; + + @Ann(A.K) + class A extends Missing { + static final int K = 1; + static int x; + void m() { + int local = 0; + local++; + x++; + foo(); + new Other(); + new Other.Inner.Deep(); + unresolved++; + } + void foo() { + } + } + + class Other { + static int y; + static class Inner { + static class Deep { + } + } + void n() { + y++; + A.x++; + } + } + + class Sub extends Other { + void k() { + y++; + } + } + + @interface Ann { + int value(); + } + """; + + @TempDir + Path baseDir; + + private CompilationUnitTree unit; + + @BeforeEach + void parse() throws Exception { + unit = (CompilationUnitTree) Replays.parseWithEcj(baseDir, "p/A", SOURCE).get(); + } + + @Test + void own_package_imports_are_the_single_type_and_on_demand_ones_of_the_package() { + List imports = unit.imports().stream().map(ImportTree.class::cast).toList(); + + assertThat(ImportScopes.isOwnPackage(imports.get(0), "p.A", "p")).isTrue(); + assertThat(ImportScopes.isOwnPackage(imports.get(1), "p.*", "p")).isTrue(); + assertThat(ImportScopes.isOwnPackage(imports.get(2), "p.A.x", "p")).isFalse(); + assertThat(ImportScopes.isOwnPackage(imports.get(3), "q.B", "p")).isFalse(); + assertThat(ImportScopes.isOwnPackage(imports.get(0), "p.A", "")).isFalse(); + assertThat(ImportScopes.dotted(imports.get(1).qualifiedIdentifier())).isEqualTo("p.*"); + assertThat(ImportScopes.dotted(unit.packageDeclaration().packageName())).isEqualTo("p"); + } + + @Test + void members_of_enclosing_and_inherited_types_are_in_scope() { + assertThat(inScope("local", 0)).isTrue(); + assertThat(inScope("x", 1)).isTrue(); + assertThat(inScope("y", 0)).isTrue(); + assertThat(inScope("y", 1)).isTrue(); + assertThat(inScope("unresolved", 0)).isTrue(); + } + + @Test + void members_of_other_types_annotations_and_methods_of_incomplete_hierarchies_are_not_in_scope() { + assertThat(inScope("x", 3)).isFalse(); + assertThat(inScope("K", 0)).isFalse(); + assertThat(inScope("foo", 0)).isFalse(); + } + + @Test + void a_type_is_denoted_by_its_symbol_or_by_the_class_its_constructor_creates() { + Symbol.TypeSymbol other = classSymbol("Other"); + List creations = creations(); + Symbol constructor = creations.get(0).methodSymbol(); + IdentifierTree deep = identifiers("Deep").get(0); + + assertThat(ImportScopes.denotesType(other, "p.Other", identifiers("Other").get(0))).isTrue(); + assertThat(ImportScopes.denotesType(method("foo"), "p.A.foo", identifiers("foo").get(0))).isFalse(); + assertThat(ImportScopes.denotesType(constructor, "p.Other", identifiers("Other").get(0))).isTrue(); + assertThat(ImportScopes.denotesType(constructor, "p.Other.Inner.Deep", deep)).isTrue(); + assertThat(ImportScopes.denotesType(constructor, "q.B", deep)).isFalse(); + assertThat(ImportScopes.denotesType(constructor, "q.B", identifiers("unresolved").get(0))).isFalse(); + } + + @Test + void on_demand_imports_bring_the_types_of_a_package_or_the_members_of_a_type() { + Symbol.TypeSymbol inner = classSymbol("Inner"); + Symbol.TypeSymbol deep = classSymbol("Deep"); + Symbol constructor = creations().get(0).methodSymbol(); + + assertThat(ImportScopes.declaredIn(identifiers("unresolved").get(0).symbol(), "p", false)).isFalse(); + assertThat(ImportScopes.declaredIn(inner, "p.Other", true)).isTrue(); + assertThat(ImportScopes.declaredIn(deep, "p.Other", true)).isFalse(); + assertThat(ImportScopes.declaredIn(identifiers("y").get(0).symbol(), "p.Other", true)).isTrue(); + assertThat(ImportScopes.declaredIn(constructor, "p", false)).isTrue(); + assertThat(ImportScopes.declaredIn(inner, "q", false)).isFalse(); + assertThat(ImportScopes.declaredIn(inner, "p.Other", false)).isTrue(); + assertThat(ImportScopes.declaredIn(inner, "p", false)).isFalse(); + assertThat(ImportScopes.declaredIn(method("foo"), "p", false)).isFalse(); + } + + private boolean inScope(String name, int index) { + IdentifierTree identifier = identifiers(name).get(index); + return ImportScopes.isInScope(identifier.symbol(), identifier); + } + + private List identifiers(String name) { + List found = new ArrayList<>(); + unit.accept(new BaseTreeVisitor() { + @Override + public void visitIdentifier(IdentifierTree tree) { + if (name.equals(tree.name())) { + found.add(tree); + } + } + }); + return found; + } + + private List creations() { + List found = new ArrayList<>(); + unit.accept(new BaseTreeVisitor() { + @Override + public void visitNewClass(NewClassTree tree) { + found.add(tree); + } + }); + return found; + } + + private Symbol.TypeSymbol classSymbol(String name) { + List found = new ArrayList<>(); + unit.accept(new BaseTreeVisitor() { + @Override + public void visitClass(ClassTree tree) { + if (tree.simpleName() != null && name.equals(tree.simpleName().name())) { + found.add(tree.symbol()); + } + super.visitClass(tree); + } + }); + return found.get(0); + } + + private Symbol method(String name) { + List found = new ArrayList<>(); + unit.accept(new BaseTreeVisitor() { + @Override + public void visitMethod(MethodTree tree) { + if (name.equals(tree.simpleName().name())) { + found.add(tree.symbol()); + } + } + }); + return found.get(0); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/InferenceDiamondTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/InferenceDiamondTest.java new file mode 100644 index 00000000000..643fcc06a6d --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/InferenceDiamondTest.java @@ -0,0 +1,200 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.sonar.plugins.java.api.semantic.Type; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.java.semsitter.JTypeFixtures.library; +import static org.sonar.java.semsitter.JTypeFixtures.member; + +class InferenceDiamondTest { + + private static final String STREAM = "java.util.stream.Stream"; + private static final String COLLECTOR = "java.util.stream.Collector"; + private static final String LIST = "java.util.List"; + private static final String MAP = "java.util.Map"; + private static final String COLLECTION = "java.util.Collection"; + private static final String ARRAY_LIST = "java.util.ArrayList"; + private static final String CHAR_SEQUENCE = "java.lang.CharSequence"; + private static final String KEYED = "lib.Keyed"; + private static final String K = "{\"id\": \"K\", \"kind\": \"typevar\"}"; + private static final String V = "{\"id\": \"V\", \"kind\": \"typevar\"}"; + + private final JTypeFixtures fixtures = new JTypeFixtures( + library(KEYED, "\"typeParameters\": 2, \"typeVars\": [\"K\", \"V\"], \"interfaces\": [\"java.lang.Iterable\", \"java.lang.Comparable\"]," + + "\"interfaceTypes\": [{\"id\": \"java.lang.Iterable\", \"args\": [" + V + "]}, {\"id\": \"java.lang.Comparable\", \"args\": [{\"id\": \"java.lang.String\"}]}]", + member("", "(Ljava/lang/Object;Ljava/lang/Object;)V", "\"paramVars\": [\"c0\", \"c1\"], \"paramTypes\": [" + K + ", " + V + "]"), + member("", "(Ljava/lang/Object;)V", "\"paramVars\": [\"c0\"], \"paramTypes\": [" + K + "]"))); + private final Inference inference = fixtures.sema.inference(); + private final JMethodSymbol collect = fixtures.method(STREAM, "collect", COLLECTOR); + + @Test + void collected_result_takes_the_supertype_its_target_asks_for() { + Type result = retarget(fixtures.string(), fixtures.type(LIST, fixtures.string()), fixtures.type(COLLECTION, fixtures.type(CHAR_SEQUENCE))); + + assertThat(result).isEqualTo(fixtures.type(LIST, fixtures.type(CHAR_SEQUENCE))); + } + + @Test + void collected_result_stands_when_the_target_does_not_widen_its_element() { + JType strings = fixtures.type(LIST, fixtures.string()); + + assertThat(retarget(fixtures.string(), strings, fixtures.type(COLLECTION, fixtures.string()))).isNull(); + assertThat(retarget(fixtures.string(), strings, fixtures.type(COLLECTION, fixtures.integer()))).isNull(); + assertThat(retarget(fixtures.string(), strings, fixtures.type(COLLECTION, fixtures.extending(fixtures.type(CHAR_SEQUENCE))))).isNull(); + assertThat(retarget(fixtures.string(), strings, fixtures.type(COLLECTION, fixtures.type(LIST, fixtures.string())))).isNull(); + assertThat(retarget(fixtures.string(), strings, fixtures.type(COLLECTION, JType.array(fixtures.sema, fixtures.string())))).isNull(); + assertThat(retarget(fixtures.string(), strings, fixtures.type(MAP, fixtures.string(), fixtures.string()))).isNull(); + assertThat(retarget(fixtures.string(), strings, fixtures.type(COLLECTION))).isNull(); + assertThat(retarget(fixtures.string(), strings, fixtures.type("java.lang.Iterable", fixtures.type(CHAR_SEQUENCE)))).isEqualTo(fixtures.type(LIST, fixtures.type(CHAR_SEQUENCE))); + } + + @Test + void collected_result_stands_when_its_element_is_not_a_plain_class() { + JType strings = fixtures.type(LIST, fixtures.string()); + JType target = fixtures.type(COLLECTION, fixtures.type(CHAR_SEQUENCE)); + + assertThat(retarget(fixtures.extending(fixtures.string()), strings, target)).isNull(); + assertThat(retarget(JType.unknown(fixtures.sema), strings, target)).isNull(); + assertThat(retarget(fixtures.type(LIST, fixtures.string()), strings, target)).isNull(); + assertThat(retarget(JType.array(fixtures.sema, fixtures.string()), strings, target)).isNull(); + assertThat(retarget(fixtures.string(), fixtures.type(MAP, fixtures.string(), fixtures.string()), fixtures.type(MAP, fixtures.type(CHAR_SEQUENCE), fixtures.string()))) + .isNull(); + assertThat(retarget(fixtures.string(), fixtures.type(LIST, fixtures.integer()), target)).isNull(); + } + + @Test + void collected_result_stands_for_other_calls() { + JType strings = fixtures.type(LIST, fixtures.string()); + JType target = fixtures.type(COLLECTION, fixtures.type(CHAR_SEQUENCE)); + JType stream = fixtures.type(STREAM, fixtures.string()); + + assertThat(inference.retargetedElement(fixtures.method(STREAM, "count"), stream, strings, target)).isNull(); + assertThat(inference.retargetedElement(fixtures.method("java.lang.Object", "clone"), stream, strings, target)).isNull(); + assertThat(inference.retargetedElement(fixtures.method("java.util.ArrayList", "", COLLECTION), stream, strings, target)).isNull(); + assertThat(inference.retargetedElement(collect, fixtures.type(STREAM), strings, target)).isNull(); + assertThat(inference.retargetedElement(collect, stream, fixtures.string(), target)).isNull(); + assertThat(inference.retargetedElement(collect, stream, strings, fixtures.string())).isNull(); + assertThat(inference.retargetedElement(collect, Type.UNKNOWN, strings, target)).isNull(); + assertThat(inference.retargetedElement(collect, stream, Type.UNKNOWN, target)).isNull(); + assertThat(inference.retargetedElement(collect, stream, strings, Type.UNKNOWN)).isNull(); + JMethodSymbol unknown = new JMethodSymbol(fixtures.sema, null, "collect"); + unknown.unknown(true); + assertThat(inference.retargetedElement(unknown, stream, strings, target)).isNull(); + } + + @Test + void collected_result_widens_only_the_argument_carrying_the_element() { + JType counts = fixtures.type(MAP, fixtures.string(), fixtures.integer()); + + assertThat(retarget(fixtures.string(), counts, fixtures.type(MAP, fixtures.string(), fixtures.integer()))).isNull(); + assertThat(retarget(fixtures.string(), counts, fixtures.type(MAP, fixtures.type(CHAR_SEQUENCE), fixtures.integer()))) + .isEqualTo(fixtures.type(MAP, fixtures.type(CHAR_SEQUENCE), fixtures.integer())); + } + + @Test + void diamond_takes_the_target_arguments() { + assertThat(inference.inferDiamond(fixtures.type(ARRAY_LIST), fixtures.type(LIST, fixtures.string()))).isEqualTo(fixtures.type(ARRAY_LIST, fixtures.string())); + assertThat(inference.inferDiamond(fixtures.type(ARRAY_LIST), fixtures.type(ARRAY_LIST, fixtures.string()))).isEqualTo(fixtures.type(ARRAY_LIST, fixtures.string())); + } + + @Test + void diamond_stands_when_the_target_leaves_a_type_parameter_open() { + JType keyed = fixtures.type(KEYED); + + assertThat(inference.inferDiamond(keyed, fixtures.type("java.lang.Iterable", fixtures.string()))).isSameAs(keyed); + assertThat(inference.inferDiamond(keyed, fixtures.type("java.lang.Comparable", fixtures.string()))).isSameAs(keyed); + assertThat(inference.inferDiamond(keyed, fixtures.type(LIST, fixtures.string()))).isSameAs(keyed); + assertThat(inference.inferDiamond(fixtures.string(), fixtures.type("java.lang.Comparable", fixtures.string()))).isSameAs(fixtures.string()); + assertThat(inference.inferDiamond(keyed, fixtures.type("java.lang.Iterable"))).isSameAs(keyed); + assertThat(inference.inferDiamond(keyed, Type.UNKNOWN)).isSameAs(keyed); + JType unknown = JType.unknown(fixtures.sema); + assertThat(inference.inferDiamond(unknown, fixtures.type(LIST, fixtures.string()))).isSameAs(unknown); + assertThat(inference.inferDiamond(Type.UNKNOWN, fixtures.type(LIST, fixtures.string()))).isSameAs(Type.UNKNOWN); + } + + @Test + void diamond_takes_the_constructor_arguments() { + JMethodSymbol copy = fixtures.method(ARRAY_LIST, "", COLLECTION); + JMethodSymbol pair = fixtures.method(KEYED, "", "java.lang.Object", "java.lang.Object"); + + assertThat(inference.inferDiamondFromArguments(copy, fixtures.type(ARRAY_LIST), List.of(fixtures.type(LIST, fixtures.string())))) + .isEqualTo(fixtures.type(ARRAY_LIST, fixtures.string())); + assertThat(inference.inferDiamondFromArguments(pair, fixtures.type(KEYED), List.of(fixtures.string(), fixtures.primitive("int")))) + .isEqualTo(fixtures.type(KEYED, fixtures.string(), fixtures.integer())); + } + + @Test + void diamond_stands_when_the_constructor_arguments_leave_a_type_parameter_open() { + JType keyed = fixtures.type(KEYED); + JType arrayList = fixtures.type(ARRAY_LIST); + JMethodSymbol single = fixtures.method(KEYED, "", "java.lang.Object"); + JMethodSymbol copy = fixtures.method(ARRAY_LIST, "", COLLECTION); + + assertThat(inference.inferDiamondFromArguments(single, keyed, List.of(fixtures.string()))).isSameAs(keyed); + assertThat(inference.inferDiamondFromArguments(copy, arrayList, List.of())).isSameAs(arrayList); + assertThat(inference.inferDiamondFromArguments(copy, arrayList, List.of(Type.UNKNOWN))).isSameAs(arrayList); + assertThat(inference.inferDiamondFromArguments(fixtures.method(ARRAY_LIST, ""), arrayList, List.of())).isSameAs(arrayList); + assertThat(inference.inferDiamondFromArguments(fixtures.method("java.lang.String", ""), fixtures.string(), List.of())).isSameAs(fixtures.string()); + JType parameterized = fixtures.type(ARRAY_LIST, fixtures.string()); + assertThat(inference.inferDiamondFromArguments(copy, parameterized, List.of(fixtures.type(LIST, fixtures.integer())))).isSameAs(parameterized); + JType unknown = JType.unknown(fixtures.sema); + assertThat(inference.inferDiamondFromArguments(copy, unknown, List.of())).isSameAs(unknown); + assertThat(inference.inferDiamondFromArguments(copy, Type.UNKNOWN, List.of())).isSameAs(Type.UNKNOWN); + } + + @Test + void ground_type_replaces_wildcards_by_their_bounds() { + JType function = fixtures.type("java.util.function.Function", JType.superWildcard(fixtures.sema, fixtures.string()), fixtures.extending(fixtures.integer())); + JType strings = fixtures.type(LIST, fixtures.string()); + + assertThat(inference.groundType(function)).isEqualTo(fixtures.type("java.util.function.Function", fixtures.string(), fixtures.integer())); + assertThat(inference.groundType(strings)).isSameAs(strings); + assertThat(inference.groundType(fixtures.string())).isSameAs(fixtures.string()); + assertThat(inference.groundType(Type.UNKNOWN)).isSameAs(Type.UNKNOWN); + } + + @Test + void capture_conversion_captures_wildcard_arguments() { + JType numbers = fixtures.type(MAP, fixtures.string(), fixtures.extending(fixtures.type("java.lang.Number"))); + JType strings = fixtures.type(LIST, fixtures.string()); + + Type captured = inference.captureWildcards(numbers); + + assertThat(captured.typeArguments().get(0)).isSameAs(fixtures.string()); + assertThat(((JType) captured.typeArguments().get(1)).isCapture()).isTrue(); + assertThat(captured.typeArguments().get(1).erasure()).isEqualTo(fixtures.type("java.lang.Number")); + assertThat(inference.captureWildcards(strings)).isSameAs(strings); + assertThat(inference.captureWildcards(fixtures.string())).isSameAs(fixtures.string()); + assertThat(inference.captureWildcards(Type.UNKNOWN)).isSameAs(Type.UNKNOWN); + } + + @Test + void declared_type_variables_are_the_method_own() { + assertThat(inference.declaresTypeVariables(fixtures.method("java.util.Collections", "emptyList"), false)).isTrue(); + assertThat(inference.declaresTypeVariables(fixtures.method("java.util.Optional", "get"), true)).isFalse(); + assertThat(inference.declaresTypeVariables(fixtures.method(ARRAY_LIST, "", COLLECTION), true)).isTrue(); + assertThat(inference.declaresTypeVariables(fixtures.method("java.lang.Object", "clone"), false)).isFalse(); + } + + private Type retarget(JType element, JType returned, JType target) { + return inference.retargetedElement(collect, fixtures.type(STREAM, element), returned, target); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/InferenceTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/InferenceTest.java index b428d057aed..2fd089a954a 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/InferenceTest.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/InferenceTest.java @@ -18,28 +18,274 @@ import java.util.List; import org.junit.jupiter.api.Test; +import org.sonar.plugins.java.api.semantic.Type; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.java.semsitter.JTypeFixtures.library; +import static org.sonar.java.semsitter.JTypeFixtures.member; class InferenceTest { - private final JTypeFixtures fixtures = new JTypeFixtures(); + private static final String BOX = "lib.Box"; + private static final String T = "{\"id\": \"T\", \"kind\": \"typevar\"}"; + private static final String X = "{\"id\": \"X\", \"kind\": \"typevar\"}"; + private static final String BOX_OF_T = "{\"id\": \"lib.Box\", \"args\": [" + T + "]}"; + private static final String INNER_FACT = "{\"id\": \"lib.Box$Inner\"}"; + private static final String MISSING = "()Llib/Missing;"; + private static final String COLLECTIONS = "java.util.Collections"; + private static final String OPTIONAL = "java.util.Optional"; + private static final String LIST = "java.util.List"; + private static final String SUPPLIER = "java.util.function.Supplier"; + + private final JTypeFixtures fixtures = new JTypeFixtures( + library(BOX, "\"typeParameters\": 1, \"typeVars\": [\"T\"], \"typeVarBounds\": [[{\"id\": \"java.lang.Object\", \"args\": []}]]", + member("self", "()Llib/Box;", "\"retSelf\": true, \"retType\": " + BOX_OF_T), + member("get", "()Ljava/lang/Object;", "\"retParam\": 0, \"retType\": " + T), + member("inner", "()Llib/Box$Inner;", "\"retType\": " + INNER_FACT), + member("make", "()Llib/Box$Inner;", "\"static\": true, \"retType\": " + INNER_FACT), + member("nested", "()Llib/Box$Nested;", "\"retType\": {\"id\": \"lib.Box$Nested\"}"), + member("name", "()Ljava/lang/String;", "\"retType\": {\"id\": \"java.lang.String\"}"), + member("late", MISSING, "\"retType\": {\"id\": \"java.lang.String\"}"), + member("absent", MISSING, "\"retType\": {\"id\": \"lib.Missing\"}"), + member("lost", MISSING, "\"typeVars\": [\"E\"], \"retType\": {\"id\": \"E\", \"kind\": \"typevar\"}"), + member("held", "()Llib/Missing;", "\"retType\": " + T), + member("count", "()I", "\"retType\": {\"id\": \"int\"}"), + member("deep", "()Llib/Box.Deep;", "\"retType\": {\"id\": \"lib.Box.Deep\"}"), + member("silent", "()V", "\"throwsTypes\": []"), + member("rethrow", "()V", "\"throwsTypes\": [" + T + "]"), + member("pair", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/util/List;", "\"static\": true, \"varargs\": true, \"typeVars\": [\"E\"]," + + "\"paramVars\": [\"m0\", \"m0[]\"], \"paramTypes\": [{\"id\": \"E\", \"kind\": \"typevar\"}, {\"kind\": \"array\", \"elem\": {\"id\": \"E\", \"kind\": \"typevar\"}}]," + + "\"retType\": {\"id\": \"java.util.List\", \"args\": [{\"id\": \"E\", \"kind\": \"typevar\"}]}"), + member("listed", "()Ljava/util/List;", "\"retType\": {\"id\": \"java.util.List\", \"args\": [{\"id\": \"java.lang.String\"}]}"), + member("fail", "(Ljava/util/function/Supplier;)V", "\"typeVars\": [\"X\"], \"paramVars\": [\"\"], \"throwsTypes\": [{\"id\": \"java.io.IOException\"}, " + X + "]," + + "\"paramTypes\": [{\"id\": \"java.util.function.Supplier\", \"args\": [{\"kind\": \"wildcard\", \"extends\": " + X + "}]}]"), + member("id", "(Ljava/lang/Object;)Ljava/lang/Object;", "\"typeVars\": [\"T\"], \"paramVars\": [\"m0\"], \"paramTypes\": [" + T + "], \"retType\": " + T), + member("untyped", "(Ljava/lang/Object;)Ljava/lang/Object;", "\"static\": true, \"typeVars\": null, \"paramVars\": [\"m0\"], \"paramTypes\": [" + T + "], \"retType\": " + T)), + library("lib.Box$Inner", ""), + library("lib.Box$Nested", "\"modifiers\": [\"public\", \"static\"]"), + library("lib.Box.Deep", "")); private final Inference inference = fixtures.sema.inference(); @Test - void declared_types_stand_until_inference_lands() { - JMethodSymbol valueOf = fixtures.method("java.lang.String", "valueOf", "java.lang.Object"); - JType string = fixtures.string(); - - assertThat(inference.invocationReturn(valueOf, null, List.of(string))).isSameAs(valueOf.returnType().type()); - assertThat(inference.rawReturn(valueOf)).isNull(); - assertThat(inference.invocationThrown(valueOf, null, List.of(string))).isNull(); - assertThat(inference.targetedReturn(valueOf, string)).isNull(); - assertThat(inference.retargetedElement(valueOf, string, string, string)).isNull(); - assertThat(inference.inferDiamond(string, string)).isSameAs(string); - assertThat(inference.inferDiamondFromArguments(valueOf, string, List.of(string))).isSameAs(string); - assertThat(inference.groundType(string)).isSameAs(string); - assertThat(inference.captureWildcards(string)).isSameAs(string); - assertThat(inference.declaresTypeVariables(valueOf, true)).isFalse(); + void clone_of_an_array_is_the_array_type() { + JType strings = JType.array(fixtures.sema, fixtures.string()); + JMethodSymbol clone = fixtures.method("java.lang.Object", "clone"); + + assertThat(inference.invocationReturn(clone, strings, List.of())).isSameAs(strings); + assertThat(inference.invocationReturn(clone, fixtures.string(), List.of())).isEqualTo(fixtures.object()); + } + + @Test + void inner_class_returned_by_a_member_keeps_the_receiver_arguments() { + JType boxed = box(fixtures.string()); + + Type inner = inference.invocationReturn(boxMethod("inner"), boxed, List.of()); + + assertThat(inner.fullyQualifiedName()).isEqualTo("lib.Box$Inner"); + assertThat(((JType) inner).outer()).isEqualTo(boxed); + assertThat(((JType) inference.invocationReturn(boxMethod("inner"), fixtures.type(BOX), List.of())).outer()).isNull(); + assertThat(((JType) inference.invocationReturn(boxMethod("make"), boxed, List.of())).outer()).isNull(); + assertThat(((JType) inference.invocationReturn(boxMethod("inner"), null, List.of())).outer()).isNull(); + } + + @Test + void a_static_member_type_has_no_enclosing_arguments() { + assertThat(((JType) inference.invocationReturn(boxMethod("nested"), box(fixtures.string()), List.of())).outer()).isNull(); + } + + @Test + void other_members_of_a_parameterized_receiver_keep_their_return() { + JType boxed = box(fixtures.string()); + + assertThat(((JType) inference.invocationReturn(boxMethod("deep"), boxed, List.of())).outer()).isEqualTo(boxed); + assertThat(inference.invocationReturn(boxMethod("count"), boxed, List.of())).isEqualTo(fixtures.primitive("int")); + assertThat(inference.invocationReturn(boxMethod("listed"), boxed, List.of())).isEqualTo(fixtures.type(LIST, fixtures.string())); + assertThat(inference.invocationReturn(boxMethod("absent"), boxed, List.of()).isUnknown()).isTrue(); + assertThat(inference.invocationReturn(fixtures.method("java.lang.Object", "toString"), JType.array(fixtures.sema, fixtures.string()), List.of())) + .isEqualTo(fixtures.string()); + } + + @Test + void member_of_a_capture_that_is_no_class_is_the_declared_one() { + JType capturedArray = fixtures.capture(JType.array(fixtures.sema, fixtures.string())); + + assertThat(inference.invocationReturn(boxMethod("get"), capturedArray, List.of())).isEqualTo(fixtures.object()); + assertThat(inference.invocationReturn(boxMethod("make"), fixtures.capture(box(fixtures.string())), List.of()).fullyQualifiedName()).isEqualTo("lib.Box$Inner"); + } + + @Test + void type_argument_still_open_is_not_the_return() { + JType open = JType.typeVar(fixtures.sema, "E", "lib.Other`1"); + + assertThat(inference.invocationReturn(fixtures.method(OPTIONAL, "get"), fixtures.type(OPTIONAL, open), List.of())).isEqualTo(open); + assertThat(inference.invocationReturn(fixtures.method(OPTIONAL, "get"), fixtures.type(OPTIONAL), List.of())).isEqualTo(fixtures.object()); + assertThat(inference.invocationReturn(fixtures.method(OPTIONAL, "get"), null, List.of())).isEqualTo(fixtures.object()); + } + + @Test + void self_typed_method_without_receiver_returns_its_declaration() { + assertThat(inference.invocationReturn(boxMethod("self"), null, List.of()).erasure()).isEqualTo(fixtures.type(BOX)); + assertThat(inference.invocationReturn(boxMethod("self"), Type.UNKNOWN, List.of()).erasure()).isEqualTo(fixtures.type(BOX)); + assertThat(inference.invocationReturn(fixtures.method("java.lang.Object", "getClass"), null, List.of())).isEqualTo(fixtures.type("java.lang.Class")); + } + + @Test + void variable_arity_type_variable_is_inferred_from_the_leading_argument() { + JMethodSymbol pair = boxMethod("pair", "java.lang.Object", "java.lang.Object[]"); + + assertThat(inference.invocationReturn(pair, null, List.of(fixtures.string()))).isEqualTo(fixtures.type(LIST, fixtures.string())); + } + + @Test + void self_typed_method_returns_its_receiver() { + JType boxed = box(fixtures.string()); + JType captured = fixtures.capture(boxed); + + assertThat(inference.invocationReturn(boxMethod("self"), boxed, List.of())).isSameAs(boxed); + assertThat(inference.invocationReturn(boxMethod("self"), captured, List.of())).isSameAs(captured); + } + + @Test + void self_typed_method_of_a_receiver_with_captured_arguments_returns_a_capture() { + Type result = inference.invocationReturn(boxMethod("self"), box(fixtures.capture(fixtures.string())), List.of()); + + assertThat(((JType) result).isCapture()).isTrue(); + assertThat(result.erasure()).isEqualTo(fixtures.type(BOX)); + } + + @Test + void self_typed_method_whose_self_argument_is_captured_returns_a_capture_of_the_receiver() { + JMethodSymbol sequential = fixtures.method("java.util.stream.BaseStream", "sequential"); + JType stream = fixtures.type("java.util.stream.Stream", fixtures.string()); + JType receiver = fixtures.type("java.util.stream.BaseStream", fixtures.string(), fixtures.capture(stream)); + + Type result = inference.invocationReturn(sequential, receiver, List.of()); + + assertThat(((JType) result).isCapture()).isTrue(); + assertThat(result.erasure()).isEqualTo(fixtures.type("java.util.stream.BaseStream")); + } + + @Test + void member_of_a_capture_is_the_member_of_its_bound() { + Type result = inference.invocationReturn(boxMethod("get"), fixtures.capture(box(fixtures.string())), List.of()); + + assertThat(result).isEqualTo(fixtures.string()); + } + + @Test + void declared_return_stands_for_a_return_type_the_descriptor_cannot_name() { + assertThat(inference.invocationReturn(boxMethod("late"), box(fixtures.string()), List.of())).isEqualTo(fixtures.string()); + assertThat(inference.invocationReturn(boxMethod("late"), null, List.of())).isEqualTo(fixtures.string()); + assertThat(inference.invocationReturn(boxMethod("absent"), null, List.of()).isUnknown()).isTrue(); + assertThat(inference.invocationReturn(boxMethod("lost"), null, List.of()).isUnknown()).isTrue(); + } + + @Test + void library_method_returns_the_parameterization_its_signature_spells() { + assertThat(inference.invocationReturn(boxMethod("listed"), fixtures.type(BOX), List.of())).isEqualTo(fixtures.type(LIST, fixtures.string())); + } + + @Test + void static_method_type_variable_is_inferred_from_explicit_type_arguments() { + JMethodSymbol emptyList = fixtures.method(COLLECTIONS, "emptyList"); + + Type result = fixtures.sema.substitution().withExplicitTypeArguments(List.of(fixtures.string()), () -> inference.invocationReturn(emptyList, null, List.of())); + + assertThat(result).isEqualTo(fixtures.type(LIST, fixtures.string())); + } + + @Test + void static_method_type_variable_is_inferred_from_arguments() { + JMethodSymbol singletonList = fixtures.method(COLLECTIONS, "singletonList", "java.lang.Object"); + + assertThat(inference.invocationReturn(singletonList, null, List.of(fixtures.primitive("int")))).isEqualTo(fixtures.type(LIST, fixtures.integer())); + assertThat(inference.invocationReturn(singletonList, null, List.of(Type.UNKNOWN))).isEqualTo(fixtures.type(LIST)); + } + + @Test + void a_method_type_variable_shadows_the_class_one_of_the_same_name() { + JType integer = fixtures.type("java.lang.Integer"); + + assertThat(inference.invocationReturn(boxMethod("id", "java.lang.Object"), box(fixtures.string()), List.of(integer))).isEqualTo(integer); + } + + @Test + void an_unbound_method_type_variable_does_not_take_the_class_argument_of_the_same_name() { + assertThat(inference.invocationReturn(boxMethod("id", "java.lang.Object"), box(fixtures.string()), List.of(Type.UNKNOWN))).isEqualTo(fixtures.object()); + } + + @Test + void method_without_type_variables_infers_nothing_from_its_arguments() { + assertThat(inference.invocationReturn(boxMethod("untyped", "java.lang.Object"), null, List.of(fixtures.string()))).isEqualTo(fixtures.object()); + } + + @Test + void raw_return_erases_the_declared_return() { + assertThat(inference.rawReturn(fixtures.method(OPTIONAL, "get"))).isEqualTo(fixtures.object()); + assertThat(inference.rawReturn(fixtures.method(OPTIONAL, "map", "java.util.function.Function"))).isEqualTo(fixtures.type(OPTIONAL)); + assertThat(inference.rawReturn(boxMethod("absent"))).isNull(); + assertThat(inference.rawReturn(fixtures.method(OPTIONAL, "of", "java.lang.Object"))).isNull(); + assertThat(inference.rawReturn(fixtures.method("java.lang.String", "length"))).isNull(); + assertThat(inference.rawReturn(fixtures.method("java.lang.Object", "clone"))).isNull(); + assertThat(inference.rawReturn(boxMethod("held"))).isEqualTo(fixtures.object()); + } + + @Test + void thrown_type_variable_is_inferred_from_the_argument() { + JMethodSymbol orElseThrow = fixtures.method(OPTIONAL, "orElseThrow", SUPPLIER); + JType supplier = fixtures.type(SUPPLIER, fixtures.type("java.lang.IllegalStateException")); + + assertThat(inference.invocationThrown(orElseThrow, fixtures.type(OPTIONAL, fixtures.string()), List.of(supplier))) + .containsExactly(fixtures.type("java.lang.IllegalStateException")); + assertThat(inference.invocationThrown(orElseThrow, null, List.of(supplier))).containsExactly(fixtures.type("java.lang.IllegalStateException")); + assertThat(inference.invocationThrown(orElseThrow, null, List.of(Type.UNKNOWN))).isNull(); + } + + @Test + void thrown_types_that_are_no_type_variable_keep_their_declared_type() { + JType supplier = fixtures.type(SUPPLIER, fixtures.type("java.lang.IllegalStateException")); + + assertThat(inference.invocationThrown(boxMethod("fail", SUPPLIER), null, List.of(supplier))) + .containsExactly(fixtures.type("java.io.IOException"), fixtures.type("java.lang.IllegalStateException")); + assertThat(inference.invocationThrown(boxMethod("get"), null, List.of())).isNull(); + assertThat(inference.invocationThrown(fixtures.method("java.lang.Object", "clone"), null, List.of())).isNull(); + assertThat(inference.invocationThrown(boxMethod("silent"), null, List.of())).isNull(); + assertThat(inference.invocationThrown(unknown(), null, List.of())).isNull(); + assertThat(inference.invocationThrown(boxMethod("rethrow"), box(fixtures.type("lib.Missing")), List.of())).isNull(); + assertThat(inference.invocationThrown(boxMethod("rethrow"), box(fixtures.type("java.io.IOException")), List.of())) + .containsExactly(fixtures.type("java.io.IOException")); + } + + @Test + void target_fixes_the_type_variables_of_the_result() { + JMethodSymbol emptyList = fixtures.method(COLLECTIONS, "emptyList"); + JMethodSymbol emptyMap = fixtures.method(COLLECTIONS, "emptyMap"); + + assertThat(inference.targetedReturn(emptyList, fixtures.type(LIST, fixtures.string()))).isEqualTo(fixtures.type(LIST, fixtures.string())); + assertThat(inference.targetedReturn(emptyList, fixtures.string())).isNull(); + assertThat(inference.targetedReturn(emptyMap, fixtures.type("java.util.Map", fixtures.string(), fixtures.extending(fixtures.object())))).isNull(); + assertThat(inference.targetedReturn(boxMethod("get"), fixtures.string())).isNull(); + assertThat(inference.targetedReturn(fixtures.method("java.lang.Object", "clone"), fixtures.string())).isNull(); + assertThat(inference.targetedReturn(boxMethod("fail", SUPPLIER), fixtures.string())).isNull(); + assertThat(inference.targetedReturn(boxMethod("untyped", "java.lang.Object"), fixtures.string())).isNull(); + } + + @Test + void method_without_type_variable_list_declares_none() { + assertThat(inference.declaresTypeVariables(boxMethod("untyped", "java.lang.Object"), true)).isFalse(); + } + + private JMethodSymbol unknown() { + JMethodSymbol unknown = new JMethodSymbol(fixtures.sema, null, "get"); + unknown.unknown(true); + return unknown; + } + + private JType box(JType argument) { + return fixtures.type(BOX, argument); + } + + private JMethodSymbol boxMethod(String name, String... parameters) { + return fixtures.method(BOX, name, parameters); } } diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/InvocationTranslatorTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/InvocationTranslatorTest.java new file mode 100644 index 00000000000..faf9c6e017f --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/InvocationTranslatorTest.java @@ -0,0 +1,88 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.sonar.plugins.java.api.tree.CompilationUnitTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.LambdaExpressionTree; +import org.sonar.plugins.java.api.tree.MethodInvocationTree; +import org.sonar.plugins.java.api.tree.NewClassTree; +import org.sonar.plugins.java.api.tree.TypeTree; +import org.sonarsource.semsitter.wire.Node; +import org.sonarsource.semsitter.wire.Ref; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.java.semsitter.TranslationStateFixtures.all; +import static org.sonar.java.semsitter.TranslationStateFixtures.inner; +import static org.sonar.java.semsitter.TranslationStateFixtures.kind; +import static org.sonar.java.semsitter.TranslationStateFixtures.leaf; +import static org.sonar.java.semsitter.TranslationStateFixtures.mutate; +import static org.sonar.java.semsitter.TranslationStateFixtures.recorded; +import static org.sonar.java.semsitter.TranslationStateFixtures.translate; +import static org.sonar.java.semsitter.TranslationStateFixtures.where; + +class InvocationTranslatorTest { + + @Test + void a_bound_method_of_another_arity_is_unknown() { + CompilationUnitTree unit = translate(mutate(recorded("Imports"), where(node -> node.getRefsList().stream().anyMatch(ref -> ref.getTarget().equals("java.lang.Math#abs(int)")), + node -> node.toBuilder().setText("max").clearRefs().addRefs(Ref.newBuilder().setAccess("r").setOutcome("bound").setTarget("java.lang.Math#max(int,int)")).build())), 21); + + List calls = all(unit, MethodInvocationTree.class).stream() + .filter(call -> call.methodSelect() instanceof IdentifierTree name && name.name().equals("max")) + .toList(); + + assertThat(calls).isNotEmpty().allSatisfy(call -> { + assertThat(call.methodSymbol().isUnknown()).isTrue(); + assertThat(call.methodSymbol().name()).isEqualTo("max"); + }); + } + + @Test + void a_lambda_argument_creating_an_object_is_translated() { + Node creation = inner("object_creation_expression", leaf("new", "new", 20, 20), + leaf("type_identifier", "Object", 20, 24).toBuilder().setField("type").addRefs(Ref.newBuilder().setAccess("ref").setOutcome("bound").setTarget("java.lang.Object")).build(), + inner("argument_list", leaf("(", "(", 20, 30), leaf(")", ")", 20, 31)).toBuilder().setField("arguments").build()).toBuilder().setField("body").build(); + CompilationUnitTree unit = translate(mutate(recorded("Initializers"), where(kind("lambda_expression").and(node -> node.getStartLine() == 20), + node -> replaceBody(node, creation))), 21); + + LambdaExpressionTree lambda = all(unit, LambdaExpressionTree.class).get(0); + + assertThat(lambda.body()).isInstanceOfSatisfying(NewClassTree.class, created -> assertThat(created.symbolType().is("java.lang.Object")).isTrue()); + assertThat(((MethodInvocationTree) lambda.parent().parent()).methodSymbol().name()).isEqualTo("add"); + } + + @Test + void a_creation_keeps_its_constructor_type_arguments() { + Node typeArguments = inner("type_arguments", leaf("<", "<", 14, 25), leaf("type_identifier", "Other", 14, 26), leaf(">", ">", 14, 31)).toBuilder().setField("type_arguments").build(); + CompilationUnitTree unit = translate(mutate(recorded("Unresolved"), where(kind("object_creation_expression").and(node -> node.getStartLine() == 14), + node -> node.toBuilder().addChildren(1, typeArguments).build())), 21); + + NewClassTree creation = all(unit, NewClassTree.class).get(0); + + assertThat(creation.typeArguments()).hasSize(1); + assertThat(((TypeTree) creation.typeArguments().get(0)).symbolType().name()).isEqualTo("Other"); + } + + private static Node replaceBody(Node lambda, Node body) { + Node.Builder builder = lambda.toBuilder().clearChildren(); + lambda.getChildrenList().forEach(child -> builder.addChildren("body".equals(child.getField()) ? body : child)); + return builder.build(); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/JVariableSymbolTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/JVariableSymbolTest.java index 631d431bf60..93f52c5d98a 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/JVariableSymbolTest.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/JVariableSymbolTest.java @@ -128,10 +128,21 @@ void parameter_placeholder_of_an_undeclared_method_carries_nothing_but_its_type( assertThat(metadata.symbolAnnotations()).isEmpty(); assertThat(metadata.nullabilityData().isNonNull(SymbolMetadata.NullabilityLevel.PACKAGE, false, false)).isFalse(); assertThat(metadata.nullabilityData(SymbolMetadata.NullabilityTarget.PARAMETER).isNullable(SymbolMetadata.NullabilityLevel.PACKAGE, false, false)).isFalse(); + assertThat(metadata.nullabilityData()).isEqualTo(method.metadata().nullabilityData(SymbolMetadata.NullabilityTarget.PARAMETER)); assertThat(metadata.findAnnotationTree(null)).isNull(); assertThat(metadata.parametersMetadata()).isEmpty(); } + @Test + void parameter_placeholder_of_an_unknown_method_has_unknown_nullability() { + JSema sema = new JSema(); + JMethodSymbol method = new JMethodSymbol(sema, null, "m"); + method.unknown(true); + Symbol.VariableSymbol placeholder = (Symbol.VariableSymbol) sema.factTypes().parameterPlaceholder(method, 0, sema.primitiveType("int")); + + assertThat(placeholder.metadata().nullabilityData()).isEqualTo(JSymbolMetadata.unknownNullabilityAt(SymbolMetadata.NullabilityLevel.VARIABLE)); + } + private Optional constant(JSema sema, List fields, String name, String... modifiers) { JVariableSymbol field = new JVariableSymbol(sema, "C#" + name, name, "field"); field.addModifiers(List.of(modifiers)); diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/JWarningTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/JWarningTest.java new file mode 100644 index 00000000000..c64f81f28ee --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/JWarningTest.java @@ -0,0 +1,44 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.plugins.java.api.diagnostics.ProblemKind; +import org.sonar.plugins.java.api.tree.Tree; + +import static org.assertj.core.api.Assertions.assertThat; + +class JWarningTest { + + private static final Tree TREE = new InternalSyntaxToken(1, 0, "x", List.of(), false); + private static final Tree OTHER_TREE = new InternalSyntaxToken(1, 0, "x", List.of(), false); + + @Test + void warnings_are_equal_only_on_the_same_tree() { + JWarning warning = new JWarning("m", ProblemKind.UNUSED_IMPORT, TREE); + + assertThat(warning.syntaxTree()).isSameAs(TREE); + assertThat(warning) + .isEqualTo(new JWarning("m", ProblemKind.UNUSED_IMPORT, TREE)) + .hasSameHashCodeAs(new JWarning("m", ProblemKind.UNUSED_IMPORT, TREE)) + .isNotEqualTo(new JWarning("m", ProblemKind.UNUSED_IMPORT, OTHER_TREE)) + .isNotEqualTo(new JWarning("other", ProblemKind.UNUSED_IMPORT, TREE)) + .isNotEqualTo(new JProblem("m", ProblemKind.UNUSED_IMPORT)); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/LambdaTranslatorTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/LambdaTranslatorTest.java new file mode 100644 index 00000000000..9d31ae87dc4 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/LambdaTranslatorTest.java @@ -0,0 +1,113 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import org.junit.jupiter.api.Test; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.tree.BlockTree; +import org.sonar.plugins.java.api.tree.CompilationUnitTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.LambdaExpressionTree; +import org.sonar.plugins.java.api.tree.MethodReferenceTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TypeTree; +import org.sonarsource.semsitter.wire.Node; +import org.sonarsource.semsitter.wire.Ref; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.java.semsitter.TranslationStateFixtures.all; +import static org.sonar.java.semsitter.TranslationStateFixtures.inner; +import static org.sonar.java.semsitter.TranslationStateFixtures.kind; +import static org.sonar.java.semsitter.TranslationStateFixtures.leaf; +import static org.sonar.java.semsitter.TranslationStateFixtures.mutate; +import static org.sonar.java.semsitter.TranslationStateFixtures.recorded; +import static org.sonar.java.semsitter.TranslationStateFixtures.translate; +import static org.sonar.java.semsitter.TranslationStateFixtures.where; + +class LambdaTranslatorTest { + + @Test + void a_method_reference_keeps_its_explicit_type_arguments() { + Node typeArguments = inner("type_arguments", leaf("<", "<", 25, 45), leaf("type_identifier", "Missing", 25, 46), leaf(">", ">", 25, 53)); + CompilationUnitTree unit = translate(mutate(recorded("Lambdas"), where(kind("method_reference").and(node -> node.getStartLine() == 25), + node -> node.toBuilder().addChildren(2, typeArguments).build())), 21); + + MethodReferenceTree reference = all(unit, MethodReferenceTree.class).stream().filter(tree -> tree.method().name().equals("toString")).findFirst().orElseThrow(); + + assertThat(reference.typeArguments()).hasSize(1); + assertThat(((TypeTree) reference.typeArguments().get(0)).symbolType().name()).isEqualTo("Missing"); + } + + @Test + void an_unbound_reference_to_a_method_returning_a_class_variable_is_translated() { + CompilationUnitTree unit = translate(mutate(recorded("Lambdas"), where(node -> node.getStartLine() == 37 && node.getRefsCount() > 0, LambdaTranslatorTest::optionalGet)), 21); + + MethodReferenceTree reference = all(unit, MethodReferenceTree.class).stream().filter(tree -> tree.method().name().equals("get")).findFirst().orElseThrow(); + + assertThat(reference.method().symbol().owner().name()).isEqualTo("Optional"); + assertThat(((ExpressionTree) reference.expression()).symbolType().is("java.util.Optional")).isTrue(); + } + + @Test + void classes_and_lambdas_nested_in_a_lambda_body_own_their_declarations() { + Node local = inner("class_declaration", leaf("class", "class", 21, 4), field(leaf("identifier", "Local", 21, 10), "name"), + field(inner("class_body", leaf("{", "{", 21, 16), leaf("}", "}", 21, 17)), "body")); + Node nested = inner("expression_statement", inner("lambda_expression", + field(inner("formal_parameters", leaf("(", "(", 21, 19), leaf(")", ")", 21, 20)), "parameters"), leaf("->", "->", 21, 22), + field(inner("block", leaf("{", "{", 21, 25), leaf("}", "}", 21, 26)), "body")), leaf(";", ";", 21, 27)); + CompilationUnitTree unit = translate(mutate(recorded("Lambdas"), where(kind("block").and(node -> node.getStartLine() == 20), + node -> node.toBuilder().addChildren(1, local).addChildren(2, nested).build())), 21); + + LambdaExpressionTree typed = all(unit, LambdaExpressionTree.class).stream().filter(lambda -> lambda.parameters().size() == 2 && lambda.body().is(Tree.Kind.BLOCK)).findFirst().orElseThrow(); + + assertThat(((BlockTree) typed.body()).body()).extracting(Tree::kind).containsExactly(Tree.Kind.CLASS, Tree.Kind.EXPRESSION_STATEMENT, Tree.Kind.RETURN_STATEMENT); + assertThat(typed.symbolType().is("java.util.function.BiFunction")).isTrue(); + } + + @Test + void a_lambda_with_fewer_parameters_than_its_target_keeps_its_parameter_owners() { + CompilationUnitTree unit = translate(mutate(recorded("Lambdas"), where(kind("inferred_parameters").and(node -> node.getStartLine() == 19), LambdaTranslatorTest::firstParameterOnly)), 21); + + LambdaExpressionTree sum = all(unit, LambdaExpressionTree.class).stream().filter(lambda -> lambda.arrowToken().range().start().line() == 19).findFirst().orElseThrow(); + + assertThat(sum.parameters()).hasSize(1); + Symbol owner = sum.parameters().get(0).symbol().owner(); + assertThat(owner instanceof JMethodSymbol method && method.id != null && method.id.contains("$lambda$")).isFalse(); + } + + private static Node firstParameterOnly(Node parameters) { + Node.Builder builder = parameters.toBuilder().clearChildren(); + parameters.getChildrenList().stream().filter(child -> !",".equals(child.getText()) && !"y".equals(child.getText())).forEach(builder::addChildren); + return builder.build(); + } + + private static Node optionalGet(Node node) { + return switch (node.getText()) { + case "String" -> retarget(node.toBuilder().setText("Optional").build(), "ref", "java.util.Optional`1"); + case "toUpperCase" -> retarget(node.toBuilder().setText("get").build(), "r", "java.util.Optional#get()"); + default -> node; + }; + } + + private static Node retarget(Node node, String access, String target) { + return node.toBuilder().clearRefs().addRefs(Ref.newBuilder().setAccess(access).setOutcome("bound").setTarget(target)).build(); + } + + private static Node field(Node node, String name) { + return node.toBuilder().setField(name).build(); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/LibraryAnnotationsTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/LibraryAnnotationsTest.java new file mode 100644 index 00000000000..c77436ff501 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/LibraryAnnotationsTest.java @@ -0,0 +1,154 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.SymbolMetadata; + +import static org.assertj.core.api.Assertions.assertThat; + +class LibraryAnnotationsTest { + + private static final String LIBRARY = """ + { + "lib.Annotated": { + "origin": "classpath", "kind": "class", "modifiers": ["public"], "super": "java.lang.Object", "interfaces": [], + "typeParameters": 0, "typeVars": [], + "annotations": ["lib.Marker"], + "members": [ + { + "k": "m", "name": "configure", "desc": "(Ljava/lang/String;I)V", "vis": "public", "abstract": false, "final": false, "static": false, + "synchronized": false, "varargs": false, "retSelf": false, "throws": [], + "annotations": [ + {"name": "java.lang.Deprecated", "values": [{"kind": "string", "name": "since", "value": "2"}, {"kind": "boolean", "name": "forRemoval", "value": true}]}, + {"name": "lib.Limits", "values": [ + {"kind": "byte", "name": "b", "value": 1}, + {"kind": "short", "name": "s", "value": 2}, + {"kind": "int", "value": 3}, + {"kind": "long", "name": "l", "value": 4}, + {"kind": "float", "name": "f", "value": 1.5}, + {"kind": "double", "name": "d", "value": 2.5}, + {"kind": "char", "name": "c", "value": 65}, + {"kind": "class", "name": "type", "value": "java.lang.String"}, + {"kind": "annotation", "name": "nested", "value": {"name": "lib.Marker"}}, + {"kind": "array", "name": "all", "value": [{"kind": "int", "value": 7}, "bare", {"kind": "string", "value": "x"}]}, + {"kind": "array", "name": "none", "value": 3}, + {"kind": "long", "name": "missing"}, + {"kind": "mystery", "name": "unknown", "value": 1}, + {"name": "untyped", "value": 1}, + "ignored" + ]}, + {"values": []} + ], + "parameterAnnotations": [[{"name": "lib.NonNull", "values": []}], []], + "typeAnnotations": [ + {"on": "type", "path": [], "name": "lib.Nullable", "values": []}, + {"on": "type", "path": [], "name": "lib.Limits", "values": []}, + {"on": "type", "path": [{"kind": "array"}], "name": "lib.Deep", "values": []}, + {"on": "param", "path": [], "name": "lib.Other", "values": []} + ] + } + ] + } + } + """; + + private JSema sema; + + @BeforeEach + void setUp() { + sema = new JSema(); + sema.loadPackages(name -> null); + sema.loadTypes(names -> new JsonObject()); + sema.ingestTypes(JsonParser.parseString(LIBRARY).getAsJsonObject()); + } + + @Test + void library_member_annotations_keep_values_of_every_kind() { + Symbol.MethodSymbol method = configure(); + + Map limits = method.metadata().valuesForAnnotation("lib.Limits").stream() + .collect(Collectors.toMap(SymbolMetadata.AnnotationValue::name, value -> describe(value.value()))); + + assertThat(limits) + .containsEntry("b", (byte) 1) + .containsEntry("s", (short) 2) + .containsEntry("value", 3) + .containsEntry("l", 4L) + .containsEntry("f", 1.5f) + .containsEntry("d", 2.5) + .containsEntry("c", 'A') + .containsEntry("type", "java.lang.String") + .containsEntry("nested", "lib.Marker") + .containsEntry("all", "[7, null, x]") + .containsEntry("none", "[]") + .containsEntry("missing", "null") + .containsEntry("unknown", "null") + .containsEntry("untyped", "null") + .hasSize(14); + } + + @Test + void library_member_annotations_include_outermost_type_annotations_once() { + List names = configure().metadata().annotations().stream().map(annotation -> annotation.symbol().type().fullyQualifiedName()).toList(); + + assertThat(names).containsExactly("java.lang.Deprecated", "lib.Limits", "lib.Nullable"); + } + + @Test + void deprecated_library_member_is_deprecated() { + assertThat(configure().isDeprecated()).isTrue(); + } + + @Test + void library_parameter_annotations_belong_to_their_parameter() { + List parameters = configure().declarationParameters(); + + assertThat(parameters).hasSize(2); + assertThat(parameters.get(0).metadata().isAnnotatedWith("lib.NonNull")).isTrue(); + assertThat(parameters.get(1).metadata().annotations()).isEmpty(); + } + + @Test + void annotation_names_given_as_strings_are_read() { + Symbol.TypeSymbol type = sema.getClassType("lib.Annotated").symbol(); + + assertThat(type.metadata().isAnnotatedWith("lib.Marker")).isTrue(); + } + + private Symbol.MethodSymbol configure() { + return (Symbol.MethodSymbol) sema.getClassType("lib.Annotated").symbol().lookupSymbols("configure").iterator().next(); + } + + private static Object describe(Object value) { + if (value instanceof Object[] array) { + return Arrays.stream(array).map(LibraryAnnotationsTest::describe).map(String::valueOf).collect(Collectors.joining(", ", "[", "]")); + } + if (value instanceof Symbol symbol) { + return symbol.type().fullyQualifiedName(); + } + return value == null ? "null" : value; + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/MemberTranslatorTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/MemberTranslatorTest.java new file mode 100644 index 00000000000..55dac2d860a --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/MemberTranslatorTest.java @@ -0,0 +1,87 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.List; +import java.util.function.Predicate; +import org.junit.jupiter.api.Test; +import org.sonar.plugins.java.api.tree.AnnotationTree; +import org.sonar.plugins.java.api.tree.AssignmentExpressionTree; +import org.sonar.plugins.java.api.tree.BlockTree; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.CompilationUnitTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonarsource.semsitter.wire.Node; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.java.semsitter.TranslationStateFixtures.all; +import static org.sonar.java.semsitter.TranslationStateFixtures.inner; +import static org.sonar.java.semsitter.TranslationStateFixtures.kind; +import static org.sonar.java.semsitter.TranslationStateFixtures.leaf; +import static org.sonar.java.semsitter.TranslationStateFixtures.mutate; +import static org.sonar.java.semsitter.TranslationStateFixtures.recorded; +import static org.sonar.java.semsitter.TranslationStateFixtures.text; +import static org.sonar.java.semsitter.TranslationStateFixtures.translate; +import static org.sonar.java.semsitter.TranslationStateFixtures.unresolved; +import static org.sonar.java.semsitter.TranslationStateFixtures.where; + +class MemberTranslatorTest { + + @Test + void unresolved_element_names_are_the_methods_of_the_annotation_type() { + Predicate elements = text("since").or(text("forRemoval")); + CompilationUnitTree unit = translate(mutate(recorded("Annotations"), where(elements, TranslationStateFixtures::unresolved)), 21); + + List names = all(unit, AssignmentExpressionTree.class).stream() + .map(AssignmentExpressionTree::variable).filter(IdentifierTree.class::isInstance).map(IdentifierTree.class::cast) + .filter(name -> name.name().equals("since") || name.name().equals("forRemoval")) + .toList(); + + assertThat(names).extracting(name -> name.symbol().owner().name() + "#" + name.symbol().name() + " " + name.symbolType().fullyQualifiedName()) + .containsExactly("Deprecated#since java.lang.String", "Deprecated#forRemoval boolean"); + } + + @Test + void an_unresolved_qualified_annotation_keeps_its_written_name() { + Node qualified = inner("scoped_identifier", + field(inner("scoped_identifier", field(unresolved(leaf("identifier", "com", 50, 3)), "scope"), leaf(".", ".", 50, 6), field(unresolved(leaf("identifier", "example", 50, 7)), "name")), "scope"), + leaf(".", ".", 50, 14), + field(unresolved(leaf("identifier", "Missing", 50, 15)), "name")); + CompilationUnitTree unit = translate(mutate(recorded("Annotations"), where(text("Override"), node -> field(qualified, "name"))), 21); + + AnnotationTree annotation = all(unit, AnnotationTree.class).stream().filter(tree -> tree.annotationType() instanceof MemberSelectExpressionTree).findFirst().orElseThrow(); + + assertThat(annotation.symbolType().fullyQualifiedName()).isEqualTo("com.example.Missing"); + assertThat(annotation.annotationType().symbolType().isUnknown()).isTrue(); + } + + @Test + void initializers_of_an_undeclared_class_are_translated() { + CompilationUnitTree unit = translate(mutate(recorded("Initializers"), where(kind("identifier").and(text("Initializers")), node -> node.toBuilder().clearDecls().build())), 21); + + List initializers = all(unit, BlockTree.class).stream().filter(block -> block.is(Tree.Kind.INITIALIZER, Tree.Kind.STATIC_INITIALIZER)).toList(); + + assertThat(((ClassTree) unit.types().get(0)).symbol().isUnknown()).isTrue(); + assertThat(initializers).extracting(Tree::kind).containsExactly(Tree.Kind.STATIC_INITIALIZER, Tree.Kind.INITIALIZER, Tree.Kind.INITIALIZER); + } + + private static Node field(Node node, String name) { + return node.toBuilder().setField(name).build(); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/NameTranslatorTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/NameTranslatorTest.java new file mode 100644 index 00000000000..786b28fb807 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/NameTranslatorTest.java @@ -0,0 +1,82 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.List; +import java.util.function.Predicate; +import org.junit.jupiter.api.Test; +import org.sonar.plugins.java.api.tree.CompilationUnitTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonarsource.semsitter.wire.Node; +import org.sonarsource.semsitter.wire.Ref; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.java.semsitter.TranslationStateFixtures.all; +import static org.sonar.java.semsitter.TranslationStateFixtures.mutate; +import static org.sonar.java.semsitter.TranslationStateFixtures.recorded; +import static org.sonar.java.semsitter.TranslationStateFixtures.text; +import static org.sonar.java.semsitter.TranslationStateFixtures.translate; +import static org.sonar.java.semsitter.TranslationStateFixtures.unresolved; +import static org.sonar.java.semsitter.TranslationStateFixtures.where; + +class NameTranslatorTest { + + private static final Predicate REFERENCE = node -> node.getRefsCount() > 0; + + @Test + void a_static_import_of_a_missing_type_brings_in_nothing() { + Predicate argument = REFERENCE.and(text("argument")); + CompilationUnitTree unit = translate(mutate(recorded("Unresolved"), where(argument, node -> unresolved(node.toBuilder().setText("help").build()))), 21); + + assertThat(describe(unit, "help")).isNotEmpty().containsOnly(".!unknown! !Unknown!"); + } + + @Test + void a_type_name_denotes_its_single_type_import() { + Predicate list = REFERENCE.and(text("List")); + CompilationUnitTree unit = translate(mutate(recorded("Imports"), where(list, node -> node.toBuilder().clearRefs() + .addRefs(Ref.newBuilder().setAccess("ref").setOutcome("bound").setTarget("java.util.Collection`1")).build())), 21); + + assertThat(describe(unit, "List")).isNotEmpty().allMatch(description -> description.endsWith(" java.util.List")); + } + + @Test + void an_unresolved_name_is_the_field_a_static_import_brings_in() { + Predicate imported = REFERENCE.and(text("PI").or(text("E")).or(text("SECONDS")).or(text("radius"))); + CompilationUnitTree unit = translate(mutate(recorded("StaticImports"), where(imported, TranslationStateFixtures::unresolved)), 21); + + assertThat(describe(unit, "PI")).isNotEmpty().containsOnly("Math.PI double"); + assertThat(describe(unit, "E")).isNotEmpty().containsOnly("Math.E double"); + assertThat(describe(unit, "SECONDS")).isNotEmpty().containsOnly("TimeUnit.SECONDS java.util.concurrent.TimeUnit"); + assertThat(describe(unit, "radius")).contains(".!unknown! !Unknown!"); + } + + @Test + void an_unresolved_name_is_the_field_of_its_enclosing_type_first() { + Predicate count = REFERENCE.and(text("count")); + CompilationUnitTree unit = translate(mutate(recorded("corpus/IteratorNextExceptionCheckSample"), where(count, TranslationStateFixtures::unresolved)), 21); + + assertThat(describe(unit, "count")).hasSize(3).containsOnly("IteratorNextExceptionCheckSampleO.count int"); + } + + private static List describe(CompilationUnitTree unit, String name) { + return all(unit, IdentifierTree.class).stream() + .filter(identifier -> name.equals(identifier.name()) && identifier.identifierToken().range().start().line() > 4) + .map(identifier -> (identifier.symbol().owner() == null ? "" : identifier.symbol().owner().name()) + "." + identifier.symbol().name() + " " + identifier.symbolType().fullyQualifiedName()) + .toList(); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/OverloadRankingTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/OverloadRankingTest.java index 27240e16b53..0c1fb1c81cd 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/OverloadRankingTest.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/OverloadRankingTest.java @@ -36,23 +36,125 @@ class OverloadRankingTest { "origin": "classpath", "kind": "class", "modifiers": ["public"], "super": "java.lang.Object", "interfaces": [], "typeParameters": 0, "typeVars": [], "members": [ - %s, %s, %s, %s, %s, %s, %s + %s, %s, %s, %s, %s, %s, %s, %s, %s ] } } """.formatted(member("(Ljava/lang/Long;)V", false, true), member("([Ljava/lang/Object;)V", true, true), member("([Ljava/lang/String;)V", true, true), member("([Ljava/lang/Integer;)V", true, true), member("(I[Ljava/lang/String;)V", true, false), - member("(Ljava/lang/String;[Ljava/lang/Object;)V", true, true), member("take", "(Llib/Missing;)V", false, true)); + member("(Ljava/lang/String;[Ljava/lang/Object;)V", true, true), member("take", "(Llib/Missing;)V", false, true), + member("run", "(Ljava/lang/Runnable;)V", false, true), member("run", "(Ljava/lang/Thread;)V", false, true)); private final JTypeFixtures fixtures = new JTypeFixtures(VARARGS_TYPE); + private final OverloadRanking ranking = fixtures.sema.overloads(); @Test - void instance_ranking_keeps_the_given_choice() { - OverloadRanking ranking = fixtures.sema.overloads(); - JMethodSymbol objects = varargs(OBJECT + "[]"); + void keeps_current_when_candidate_cannot_compete() { + JMethodSymbol current = valueOf(OBJECT); + List arguments = List.of(fixtures.primitive("int")); + + assertThat(ranking.preferOverload(current, null, arguments, Set.of())).isSameAs(current); + assertThat(ranking.preferOverload(current, current, arguments, Set.of())).isSameAs(current); + assertThat(ranking.preferOverload(current, valueOf("char[]", "int", "int"), arguments, Set.of())).isSameAs(current); + assertThat(ranking.preferOverload(current, unknown(), arguments, Set.of())).isSameAs(current); + } + + @Test + void keeps_current_when_neither_overload_takes_the_function() { + JMethodSymbol message = fixtures.method("java.util.Objects", "requireNonNull", OBJECT, STRING); + JMethodSymbol fallback = fixtures.method("java.util.Objects", "toString", OBJECT, STRING); + List arguments = List.of(fixtures.object(), fixtures.string()); + + assertThat(ranking.preferOverload(message, fallback, arguments, Set.of(1))).isSameAs(message); + } + + @Test + void keeps_current_when_both_overloads_are_as_specific() { + JMethodSymbol current = valueOf(OBJECT); + + assertThat(ranking.preferOverload(current, fixtures.method("java.util.Objects", "toString", OBJECT), List.of(fixtures.string()), Set.of())) + .isSameAs(current); + } + + @Test + void prefers_candidate_taking_the_function_an_argument_is() { + JMethodSymbol message = fixtures.method("java.util.Objects", "requireNonNull", OBJECT, STRING); + JMethodSymbol supplier = fixtures.method("java.util.Objects", "requireNonNull", OBJECT, "java.util.function.Supplier"); + List arguments = List.of(fixtures.object(), Type.UNKNOWN); + + assertThat(ranking.preferOverload(message, supplier, arguments, Set.of(1))).isSameAs(supplier); + assertThat(ranking.preferOverload(supplier, message, arguments, Set.of(1))).isSameAs(supplier); + } + + @Test + void keeps_current_when_the_candidate_cannot_take_the_function() { + JMethodSymbol runnable = fixtures.method(VARARGS, "run", "java.lang.Runnable"); + JMethodSymbol thread = fixtures.method(VARARGS, "run", "java.lang.Thread"); + + assertThat(ranking.preferOverload(runnable, thread, List.of(Type.UNKNOWN), Set.of(0))).isSameAs(runnable); + } + + @Test + void prefers_overload_applicable_in_an_earlier_phase() { + JMethodSymbol object = valueOf(OBJECT); + JMethodSymbol primitive = valueOf("int"); + + assertThat(ranking.preferOverload(object, primitive, List.of(fixtures.primitive("int")), Set.of())).isSameAs(primitive); + assertThat(ranking.preferOverload(primitive, object, List.of(fixtures.integer()), Set.of())).isSameAs(object); + assertThat(ranking.preferOverload(object, primitive, List.of(fixtures.integer()), Set.of())).isSameAs(object); + assertThat(ranking.preferOverload(valueOf("char[]"), primitive, List.of(fixtures.integer()), Set.of())).isSameAs(primitive); + } + + @Test + void prefers_more_specific_of_two_applicable_overloads() { + JMethodSymbol object = valueOf(OBJECT); + JMethodSymbol chars = valueOf("char[]"); + List arguments = List.of(JType.array(fixtures.sema, fixtures.primitive("char"))); - assertThat(ranking.preferOverload(objects, valueOf("int"), List.of(fixtures.string()), Set.of())).isSameAs(objects); - assertThat(ranking.mostSpecificVarArgs(objects, List.of(fixtures.string()))).isSameAs(objects); + assertThat(ranking.preferOverload(object, chars, arguments, Set.of())).isSameAs(chars); + assertThat(ranking.preferOverload(chars, object, arguments, Set.of())).isSameAs(chars); + } + + @Test + void keeps_current_when_no_overload_applies() { + JMethodSymbol primitive = valueOf("int"); + + assertThat(ranking.preferOverload(primitive, valueOf("char[]"), List.of(fixtures.string()), Set.of())).isSameAs(primitive); + } + + @Test + void picks_most_specific_variable_arity_overload() { + JMethodSymbol objects = varargs("java.lang.Object[]"); + List strings = List.of(fixtures.string(), fixtures.string()); + + assertThat(OverloadRanking.mostSpecificVarArgs(objects, strings)).isSameAs(varargs("java.lang.String[]")); + } + + @Test + void keeps_variable_arity_choice_when_no_overload_is_most_specific() { + JMethodSymbol strings = varargs("java.lang.String[]"); + JType nullType = JType.nullType(fixtures.sema); + + assertThat(OverloadRanking.mostSpecificVarArgs(strings, List.of(nullType, nullType))).isSameAs(strings); + } + + @Test + void keeps_choice_that_needs_no_variable_arity() { + JMethodSymbol objects = varargs("java.lang.Object[]"); + JMethodSymbol fixed = valueOf(OBJECT); + + assertThat(OverloadRanking.mostSpecificVarArgs(objects, List.of(JType.array(fixtures.sema, fixtures.string())))).isSameAs(objects); + assertThat(OverloadRanking.mostSpecificVarArgs(objects, List.of(fixtures.string(), Type.UNKNOWN))).isSameAs(objects); + assertThat(OverloadRanking.mostSpecificVarArgs(fixed, List.of(fixtures.string(), fixtures.string()))).isSameAs(fixed); + JMethodSymbol unknown = unknown(); + assertThat(OverloadRanking.mostSpecificVarArgs(unknown, List.of(fixtures.string()))).isSameAs(unknown); + } + + @Test + void keeps_variable_arity_choice_applicable_by_boxing() { + JMethodSymbol counted = varargs("int", "java.lang.String[]"); + + assertThat(OverloadRanking.mostSpecificVarArgs(counted, List.of(fixtures.integer(), JType.array(fixtures.sema, fixtures.string())))).isSameAs(counted); } @Test @@ -92,6 +194,12 @@ private JMethodSymbol valueOf(String... parameters) { return fixtures.method(STRING, VALUE_OF, parameters); } + private JMethodSymbol unknown() { + JMethodSymbol unknown = new JMethodSymbol(fixtures.sema, null, "of"); + unknown.unknown(true); + return unknown; + } + private JMethodSymbol varargs(String... parameters) { return fixtures.method(VARARGS, "of", parameters); } diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/OverriddenMethodsTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/OverriddenMethodsTest.java index 760ad1f1c34..2c0602835bd 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/OverriddenMethodsTest.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/OverriddenMethodsTest.java @@ -22,6 +22,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.SymbolMetadata; import static org.assertj.core.api.Assertions.assertThat; @@ -102,6 +103,42 @@ void a_method_overrides_the_method_of_its_parameterized_interface() { assertThat(overridden.get(0).owner().name()).isEqualTo("Converter"); } + @Test + void the_annotated_type_argument_of_the_supertype_is_the_result_annotation_of_the_overridden_method() { + Symbol.MethodSymbol library = method("lib.Converter", "convert"); + Symbol.MethodSymbol overridden = method("lib.Impl", "convert").overriddenSymbols().get(0); + + SymbolMetadata metadata = overridden.metadata(); + assertThat(metadata.isAnnotatedWith("javax.annotation.Nullable")).isTrue(); + assertThat(metadata.isAnnotatedWith("lib.NonNull")).isFalse(); + assertThat(metadata.valuesForAnnotation("javax.annotation.Nullable")).isEmpty(); + assertThat(metadata.valuesForAnnotation("lib.NonNull")).isNull(); + assertThat(metadata.symbolAnnotations()).hasSize(1); + assertThat(metadata.findAnnotationTree(metadata.annotations().get(0))).isNull(); + assertThat(metadata.parametersMetadata()).isEmpty(); + assertThat(metadata.nullabilityData().type()).isEqualTo(SymbolMetadata.NullabilityType.WEAK_NULLABLE); + assertThat(metadata.nullabilityData(SymbolMetadata.NullabilityTarget.FIELD).type()).isEqualTo(SymbolMetadata.NullabilityType.WEAK_NULLABLE); + assertThat(overridden.name()).isEqualTo("convert"); + assertThat(overridden).isEqualTo(library).isEqualTo(overridden); + } + + @Test + void the_overriding_method_inherits_the_nullability_of_the_written_type_argument() { + SymbolMetadata.NullabilityData nullability = method("lib.Impl", "convert").metadata().nullabilityData(); + + assertThat(nullability.type()).isEqualTo(SymbolMetadata.NullabilityType.WEAK_NULLABLE); + assertThat(nullability.level()).isEqualTo(SymbolMetadata.NullabilityLevel.METHOD); + } + + @Test + void a_type_argument_annotation_is_found_through_a_supertype() { + List overridden = method("lib.Sub", "convert", "java.lang.String").overriddenSymbols(); + + assertThat(overridden).extracting(method -> method.owner().name()).containsExactly("Impl", "Converter"); + assertThat(overridden.get(0).metadata().annotations()).isEmpty(); + assertThat(overridden.get(1).metadata().isAnnotatedWith("javax.annotation.Nullable")).isTrue(); + } + @Test void a_method_without_a_type_variable_result_keeps_its_own_metadata() { List overridden = method("lib.Impl", "reset").overriddenSymbols(); diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ReplayRecorderTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ReplayRecorderTest.java new file mode 100644 index 00000000000..07b786b2b96 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ReplayRecorderTest.java @@ -0,0 +1,120 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.protobuf.TextFormat; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.List; +import java.util.stream.Stream; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.api.io.TempDir; +import org.sonar.java.model.JParseResult; +import org.sonar.java.model.JavaVersionImpl; +import org.sonarsource.semsitter.wire.Document; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Records what a real SemSitter server answers for every replay sample. Run it after adding a sample or when the server + * output changes, with {@code -Dsemsitter.executable= -Dsemsitter.record=true}. + */ +@EnabledIfSystemProperty(named = "semsitter.record", matches = "true") +@EnabledIfSystemProperty(named = "semsitter.executable", matches = ".+") +class ReplayRecorderTest { + + @TempDir + Path project; + + @Test + void record_every_sample() throws Exception { + JsonObject types = new JsonObject(); + JsonObject packages = new JsonObject(); + List samples = Replays.samples(); + for (String sample : samples) { + recordSample(sample, types, packages); + } + Replays.writeSorted(Replays.TYPES, types); + Replays.writeSorted(Replays.PACKAGES, packages); + assertThat(samples).isNotEmpty(); + } + + private void recordSample(String sample, JsonObject types, JsonObject packages) throws Exception { + Path directory; + String fileName; + List analyzed; + if (Replays.isProjectFile(sample)) { + directory = Replays.PROJECT.toAbsolutePath().normalize(); + fileName = Replays.projectPath(sample); + analyzed = projectFiles(directory); + Files.copy(directory.resolve(fileName), Replays.DIRECTORY.resolve(sample + ".java"), StandardCopyOption.REPLACE_EXISTING); + } else { + directory = Files.createDirectories(project.resolve(sample)); + fileName = Path.of(sample).getFileName() + ".java"; + Files.writeString(directory.resolve(fileName), Replays.source(sample), StandardCharsets.UTF_8); + analyzed = List.of(fileName); + } + try (SemSitterClient client = SemSitterClient.start(Path.of(System.getProperty("semsitter.executable")), directory)) { + client.setSettings(SemSitterSettings.of(new JavaVersionImpl(Replays.javaVersion(sample)), List.of(), Path.of(System.getProperty("java.home")))); + client.fullGen(analyzed); + Document document = client.getFile(fileName, 0); + Replays.write(Replays.recording(sample), TextFormat.printer().printToString(document)); + if (document.getHasError()) { + return; + } + JParseResult result = SemSitterTranslator.translate(document, names -> { + JsonObject answer = JsonParser.parseString(new String(answer(client, names), StandardCharsets.UTF_8)).getAsJsonObject(); + answer.entrySet().forEach(entry -> types.add(entry.getKey(), entry.getValue())); + return answer; + }, name -> { + Boolean exists = hasPackage(client, name); + packages.addProperty(name, exists); + return exists; + }, true, Replays.javaVersion(sample)); + TreeDescription.describe(result.get()); + } + } + + private static List projectFiles(Path root) throws IOException { + try (Stream files = Files.walk(root)) { + return files.filter(file -> file.toString().endsWith(".java")).map(file -> root.relativize(file).toString().replace('\\', '/')).sorted().toList(); + } + } + + private static byte[] answer(SemSitterClient client, java.util.Set names) { + try { + return client.getTypes(names); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + private static Boolean hasPackage(SemSitterClient client, String name) { + try { + return client.hasPackage(List.of(name)).get(name); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ReplayTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ReplayTest.java new file mode 100644 index 00000000000..bf1f244b6a1 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ReplayTest.java @@ -0,0 +1,126 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import com.google.gson.JsonObject; +import com.sonar.sslr.api.RecognitionException; +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.sonar.java.model.JParseResult; +import org.sonar.plugins.java.api.tree.CompilationUnitTree; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Translates every recorded replay sample. The tree must have the shape ECJ gives for the same source, and the semantic + * information must be the approved one in {@code replay/X.expected.txt}. Run with {@code -Dsemsitter.approve=true} + * to approve the current translation. + */ +class ReplayTest { + + private static final Set NOT_COMPILING = Set.of("Unresolved"); + + private static JsonObject types; + private static JsonObject packages; + + @TempDir + Path baseDir; + + @BeforeAll + static void loadRecordings() throws IOException { + types = Replays.readJson(Replays.TYPES); + packages = Replays.readJson(Replays.PACKAGES); + } + + static List samples() throws IOException { + return Replays.samples(); + } + + @ParameterizedTest + @MethodSource("samples") + void same_tree_shape_as_ecj(String sample) throws Exception { + String source = Replays.source(sample); + JParseResult ecj = Replays.parseWithEcj(baseDir, sample, source); + JParseResult semSitter = translate(sample); + + if (Replays.document(sample).getHasError()) { + assertThatThrownBy(ecj::get).isInstanceOf(RecognitionException.class); + assertThatThrownBy(semSitter::get).isInstanceOf(RecognitionException.class); + } else { + assertThat(TreeDescription.shape(semSitter.get())).containsExactlyElementsOf(TreeDescription.shape(ecj.get())); + } + } + + @ParameterizedTest + @MethodSource("samples") + void same_warnings_as_ecj(String sample) throws Exception { + JParseResult semSitter = translate(sample); + if (!Replays.document(sample).getHasError() && !NOT_COMPILING.contains(sample) && !Replays.isCorpus(sample)) { + List expected = TreeDescription.warnings(Replays.parseWithEcj(baseDir, sample, Replays.source(sample)).get()); + + assertThat(TreeDescription.warnings(semSitter.get())).containsExactlyInAnyOrderElementsOf(expected); + assertThat(((CompilationUnitTree) semSitter.get()).supportedWarningKinds()).containsExactlyInAnyOrderElementsOf(CompilerWarnings.SUPPORTED_KINDS); + } + } + + @ParameterizedTest + @MethodSource("samples") + void approved_semantics(String sample) throws Exception { + List actual = describe(translate(sample)); + + Path approved = Replays.approved(sample); + if (Boolean.getBoolean("semsitter.approve")) { + Replays.write(approved, String.join("\n", actual) + "\n"); + } + assertThat(actual).containsExactlyElementsOf(Replays.read(approved).lines().toList()); + } + + private static List describe(JParseResult result) { + try { + return TreeDescription.describe(result.get()); + } catch (Exception failure) { + return List.of("FAILURE " + failure.getMessage()); + } + } + + static JParseResult translate(String sample) throws IOException { + SessionTypes session = new SessionTypes(names -> { + JsonObject answer = new JsonObject(); + names.stream().filter(types::has).forEach(name -> answer.add(name, types.get(name))); + return answer; + }); + try { + return SemSitterTranslator.translate(Replays.document(sample), session::get, ReplayTest::hasPackage, true, Replays.javaVersion(sample)); + } catch (RecognitionException syntaxError) { + return JParseResult.failure(syntaxError); + } + } + + private static Boolean hasPackage(String name) { + if (!packages.has(name) || packages.get(name).isJsonNull()) { + return null; + } + return packages.get(name).getAsBoolean(); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/Replays.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/Replays.java index ab1f19a3339..313ab48d84c 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/Replays.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/Replays.java @@ -16,43 +16,114 @@ */ package org.sonar.java.semsitter; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.google.protobuf.TextFormat; import com.sonarsource.scanner.engine.sensor.test.fixtures.TestInputFileBuilder; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Stream; import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; import org.sonar.api.batch.fs.InputFile; import org.sonar.java.AnalysisProgress; import org.sonar.java.jdt.JDTParser; import org.sonar.java.model.JParseResult; import org.sonar.java.model.JParser; import org.sonar.java.model.JavaVersionImpl; +import org.sonarsource.semsitter.wire.Document; /** - * The JDK type declarations a SemSitter server answered, recorded in {@code replay/types.json.gz}, and ECJ parsing of - * test sources. + * Recorded SemSitter server answers. Each sample {@code replay/X.java} has the document the server answered for it in + * {@code replay/X.textproto.gz}. The type declarations and package answers of all samples are shared in + * {@code replay/types.json.gz} and {@code replay/packages.json}. */ final class Replays { private static final int JAVA_VERSION = 21; + private static final Pattern VERSIONED = Pattern.compile("java(\\d+)/.*"); static final Path DIRECTORY = Path.of("src", "test", "resources", "org", "sonar", "java", "semsitter", "replay"); static final Path TYPES = DIRECTORY.resolve("types.json.gz"); + static final Path PACKAGES = DIRECTORY.resolve("packages.json"); + static final Path PROJECT = Path.of("..", "java-frontend", "src", "main", "java"); + + private static final String PROJECT_PREFIX = "project/"; + + private static final Gson GSON = new GsonBuilder().disableHtmlEscaping().create(); private Replays() { } + /** The samples written for the replay, then the ones of {@code replay/corpus/}, taken from the check test sources. */ + static List samples() throws IOException { + try (Stream files = Files.walk(DIRECTORY)) { + return files.map(file -> DIRECTORY.relativize(file).toString().replace('\\', '/')).filter(name -> name.endsWith(".java")) + .map(name -> name.substring(0, name.length() - 5)).sorted().toList(); + } + } + + static boolean isCorpus(String sample) { + return sample.startsWith("corpus/") || isProjectFile(sample); + } + + /** A sample of {@code replay/project/}: a file of {@link #PROJECT}, recorded with the whole project around it. */ + static boolean isProjectFile(String sample) { + return sample.startsWith(PROJECT_PREFIX); + } + + /** The language level of a sample: the one of its {@code replay/javaNN/} directory, 21 elsewhere. */ + static int javaVersion(String sample) { + Matcher versioned = VERSIONED.matcher(sample); + return versioned.matches() ? Integer.parseInt(versioned.group(1)) : JAVA_VERSION; + } + + static String projectPath(String sample) { + return sample.substring(PROJECT_PREFIX.length()) + ".java"; + } + + static String source(String sample) throws IOException { + return Files.readString(DIRECTORY.resolve(sample + ".java"), StandardCharsets.UTF_8); + } + + static Document document(String sample) throws IOException { + Document.Builder document = Document.newBuilder(); + TextFormat.merge(read(recording(sample)), document); + return document.build(); + } + + static Path recording(String sample) { + return DIRECTORY.resolve(sample + ".textproto.gz"); + } + + static Path approved(String sample) { + return DIRECTORY.resolve(sample + (isCorpus(sample) ? ".expected.txt.gz" : ".expected.txt")); + } + static String read(Path file) throws IOException { try (InputStream in = Files.newInputStream(file)) { return new String(isGzip(file) ? new GZIPInputStream(in).readAllBytes() : in.readAllBytes(), StandardCharsets.UTF_8); } } + static void write(Path file, String content) throws IOException { + try (OutputStream out = isGzip(file) ? new GZIPOutputStream(Files.newOutputStream(file)) : Files.newOutputStream(file)) { + out.write(content.getBytes(StandardCharsets.UTF_8)); + } + } + private static boolean isGzip(Path file) { return file.getFileName().toString().endsWith(".gz"); } @@ -64,6 +135,18 @@ static JsonObject readJson(Path file) throws IOException { return JsonParser.parseString(read(file)).getAsJsonObject(); } + static void writeSorted(Path file, JsonObject json) throws IOException { + Map sorted = new TreeMap<>(json.asMap()); + StringBuilder out = new StringBuilder("{\n"); + int index = 0; + for (Map.Entry entry : sorted.entrySet()) { + out.append(GSON.toJson(entry.getKey())).append(": ").append(GSON.toJson(entry.getValue())); + out.append(++index < sorted.size() ? ",\n" : "\n"); + } + out.append("}\n"); + write(file, out.toString()); + } + static InputFile inputFile(Path baseDir, String relativePath, String source) { return new TestInputFileBuilder("module", relativePath) .setModuleBaseDir(baseDir) @@ -75,7 +158,7 @@ static InputFile inputFile(Path baseDir, String relativePath, String source) { static JParseResult parseWithEcj(Path baseDir, String sample, String source) { List results = new ArrayList<>(); - JDTParser.create(JParser.Mode.BATCH, new JavaVersionImpl(JAVA_VERSION), List.of(), false, true) + JDTParser.create(JParser.Mode.BATCH, new JavaVersionImpl(javaVersion(sample)), List.of(), false, true) .parse(List.of(inputFile(baseDir, sample + ".java", source)), () -> false, new AnalysisProgress(1), (file, result) -> results.add(result)); return results.get(0); } diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ScriptedServer.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ScriptedServer.java index 979095fa883..fe63d7e919a 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ScriptedServer.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ScriptedServer.java @@ -50,6 +50,7 @@ final class ScriptedServer implements SemSitterApi { boolean closed; IOException settingsFailure; IOException loaderFailure; + FullGenStats fullGenStats; static Document emptyFile(String path) { return Document.newBuilder().setPath(path).setSemantic(true).setTree(Node.newBuilder().setKind("program")).build(); @@ -65,10 +66,10 @@ public void setSettings(Map> settings) throws IOException { } @Override - public int fullGen(Collection files) { + public FullGenStats fullGen(Collection files) { requests.add("full-gen"); scanned.addAll(files); - return files.size(); + return fullGenStats != null ? fullGenStats : FullGenStats.of(files.size()); } @Override diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterClientE2ETest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterClientE2ETest.java index a910ef183cf..96125d66a02 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterClientE2ETest.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterClientE2ETest.java @@ -48,7 +48,7 @@ void serves_files_and_types_of_a_project() throws IOException { try (SemSitterClient client = SemSitterClient.start(Path.of(System.getProperty("semsitter.executable")), project)) { client.setSettings(Map.of("jvm.java_version", List.of("17"))); - assertThat(client.fullGen(List.of())).isEqualTo(2); + assertThat(client.fullGen(List.of()).files()).isEqualTo(2); Document document = client.getFile("p/A.java", 0); assertThat(document.getPath()).isEqualTo("p/A.java"); diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterClientTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterClientTest.java index ed4af20bcf8..5b0fcccd321 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterClientTest.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterClientTest.java @@ -51,7 +51,7 @@ void start_takes_the_executable_path() { void requests_are_answered_in_order() throws IOException { try (SemSitterClient client = fakeServer()) { client.setSettings(Map.of("jvm.libraries", List.of("a.jar", "b.jar"))); - assertThat(client.fullGen(List.of("p/A.java", "p/B.java"))).isEqualTo(2); + assertThat(client.fullGen(List.of("p/A.java", "p/B.java"))).isEqualTo(new FullGenStats(2, 42L, 1L, 2048L)); assertThat(client.getFile("p/A.java", 1).getPath()).isEqualTo("p/A.java"); assertThat(JsonParser.parseString(new String(client.getTypes(List.of("java.lang.String")), StandardCharsets.UTF_8)).getAsJsonObject() .getAsJsonObject("java.lang.String").get("kind").getAsString()).isEqualTo("class"); @@ -59,6 +59,13 @@ void requests_are_answered_in_order() throws IOException { } } + @Test + void full_gen_measures_the_server_does_not_report_are_null() throws IOException { + try (SemSitterClient client = fakeServer()) { + assertThat(client.fullGen(List.of())).isEqualTo(FullGenStats.of(0)); + } + } + @Test void server_error_fails_the_request_only() throws IOException { try (SemSitterClient client = fakeServer()) { diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterFlagTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterFlagTest.java new file mode 100644 index 00000000000..61df06cd5df --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterFlagTest.java @@ -0,0 +1,53 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.sonar.api.config.Configuration; +import org.sonar.scanner.plugin.api.impl.config.MapSettings; + +import static org.assertj.core.api.Assertions.assertThat; + +class SemSitterFlagTest { + + @Test + void property_name_is_the_contract_with_sonarqube_cloud() { + assertThat(SemSitterFlag.ENABLED_PROPERTY).isEqualTo("sonar.java.internal.semsitter.enabled"); + } + + @Test + void absent_property_keeps_the_default_frontend() { + assertThat(SemSitterFlag.isEnabled(configuration(Map.of()))).isEqualTo(SemSitterFlag.DEFAULT).isFalse(); + } + + @Test + void property_true_enables() { + assertThat(SemSitterFlag.isEnabled(configuration(Map.of(SemSitterFlag.ENABLED_PROPERTY, "true")))).isTrue(); + } + + @Test + void property_false_disables() { + assertThat(SemSitterFlag.isEnabled(configuration(Map.of(SemSitterFlag.ENABLED_PROPERTY, "false")))).isFalse(); + } + + private static Configuration configuration(Map properties) { + MapSettings settings = new MapSettings(); + properties.forEach(settings::setProperty); + return settings.asConfig(); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterFullSourcesTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterFullSourcesTest.java new file mode 100644 index 00000000000..2c761bb1755 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterFullSourcesTest.java @@ -0,0 +1,102 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import com.sonarsource.scanner.engine.sensor.test.fixtures.TestInputFileBuilder; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.config.Configuration; +import org.sonar.scanner.plugin.api.impl.config.MapSettings; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class SemSitterFullSourcesTest { + + @TempDir + Path module; + + @Test + void property_name_is_the_contract_with_the_callers() { + assertThat(SemSitterFullSources.PROPERTY).isEqualTo("sonar.java.internal.semsitter.fullSources"); + } + + @Test + void entries_are_the_trimmed_non_blank_values() { + assertThat(SemSitterFullSources.entries(settings(Map.of()))).isEmpty(); + assertThat(SemSitterFullSources.entries(settings(Map.of(SemSitterFullSources.PROPERTY, "src/main/java, src/gen/java ,")))).containsExactly("src/main/java", "src/gen/java"); + } + + @Test + void a_directory_stands_for_its_java_files_below_it() throws Exception { + Path a = java("src/p/A.java"); + Path b = java("src/p/q/B.java"); + Files.writeString(module.resolve("src/p/readme.txt"), "text"); + + assertThat(SemSitterFullSources.javaFiles(List.of("src"), module)).containsExactlyInAnyOrder(a, b); + } + + @Test + void a_file_stands_for_itself_and_entries_may_be_absolute() throws Exception { + Path a = java("src/p/A.java"); + Path b = java("other/B.java"); + + assertThat(SemSitterFullSources.javaFiles(List.of("src/p/A.java", b.toString()), module)).containsExactlyInAnyOrder(a, b); + } + + @Test + void a_file_listed_twice_counts_once() throws Exception { + Path a = java("src/A.java"); + + assertThat(SemSitterFullSources.javaFiles(List.of("src", "src/A.java", "./src/../src/A.java"), module)).containsExactly(a); + } + + @Test + void a_missing_entry_fails() { + List entries = List.of("nowhere"); + + assertThatThrownBy(() -> SemSitterFullSources.javaFiles(entries, module)) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining(SemSitterFullSources.PROPERTY) + .hasMessageContaining("does not exist"); + } + + @Test + void module_base_directory_is_the_path_without_the_relative_path() throws Exception { + InputFile file = new TestInputFileBuilder("module", "src/main/java/p/A.java").setModuleBaseDir(module).setCharset(StandardCharsets.UTF_8).setLanguage("java").build(); + + assertThat(SemSitterFullSources.moduleBaseDirectory(file).toRealPath()).isEqualTo(module.toRealPath()); + } + + private Path java(String relativePath) throws Exception { + Path path = module.resolve(relativePath).toAbsolutePath().normalize(); + Files.createDirectories(path.getParent()); + return Files.writeString(path, "class A {}"); + } + + private static Configuration settings(Map properties) { + MapSettings settings = new MapSettings(); + properties.forEach(settings::setProperty); + return settings.asConfig(); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterParityTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterParityTest.java new file mode 100644 index 00000000000..3f18e029ab8 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterParityTest.java @@ -0,0 +1,247 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import com.sonarsource.scanner.engine.sensor.test.fixtures.TestInputFileBuilder; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.java.AnalysisProgress; +import org.sonar.java.jdt.JDTParser; +import org.sonar.java.model.JParseResult; +import org.sonar.java.model.JParser; +import org.sonar.java.model.JavaTree; +import org.sonar.java.model.JavaVersionImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.MethodInvocationTree; +import org.sonar.plugins.java.api.tree.SyntaxToken; +import org.sonar.plugins.java.api.tree.Tree; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Parses the same sources with the default frontend and with a real SemSitter server, and expects the same trees and + * the same semantic information. It runs only when {@value #EXECUTABLE} names a SemSitter server executable. + */ +class SemSitterParityTest { + + private static final String EXECUTABLE = "semsitter.executable"; + + @TempDir + Path project; + + @BeforeAll + static void locateServer() { + String path = System.getProperty(EXECUTABLE); + Assumptions.assumeTrue(path != null && !path.isBlank(), EXECUTABLE + " is not set"); + } + + @Test + void class_with_fields_and_methods() throws Exception { + assertSameTree(""" + package p; + + import java.util.List; + + public class A { + private final int count = 3; + private List names; + + public int twice(int value) { + return value * 2 + count; + } + + String first() { + return names.get(0); + } + } + """); + } + + @Test + void generics_lambdas_and_streams() throws Exception { + assertSameTree(""" + import java.util.List; + import java.util.stream.Collectors; + + class A { + List lengths(List words) { + return words.stream().map(w -> w.length()).filter(n -> n > 2).collect(Collectors.toList()); + } + } + """); + } + + @Test + void lambda_result_types_the_generic_call() throws Exception { + assertSameTree(""" + import java.util.List; + import java.util.stream.Collectors; + + class A { + List lengths(List words) { + return words.stream().map(w -> w.length()).collect(Collectors.toList()); + } + } + """); + } + + @Test + void array_length_has_an_unknown_owner() throws Exception { + assertSameTree(""" + class A { + int size(int[] values) { + return values.length; + } + } + """); + } + + @Test + void enums_records_and_interfaces() throws Exception { + assertSameTree(""" + interface Shape { double area(); } + + record Circle(double radius) implements Shape { + public double area() { return Math.PI * radius * radius; } + } + + enum Color { RED, GREEN; Color next() { return values()[(ordinal() + 1) % values().length]; } } + """); + } + + @Test + void control_flow_and_exceptions() throws Exception { + assertSameTree(""" + class A { + int run(String s) { + try { + for (int i = 0; i < s.length(); i++) { + if (s.charAt(i) == 'x') { + return i; + } + } + switch (s) { + case "a": return 1; + default: break; + } + } catch (IllegalStateException | IllegalArgumentException e) { + throw new RuntimeException(e); + } finally { + System.out.println("done"); + } + return -1; + } + } + """); + } + + @Test + void syntax_error_is_reported_as_a_parse_failure() throws IOException { + InputFile broken = file("Broken.java", "class Broken { int x = ; }"); + + JParseResult result = parseAll(semSitter(), broken).get(0); + + assertThatThrownBy(result::get).isInstanceOf(com.sonar.sslr.api.RecognitionException.class); + } + + private void assertSameTree(String source) throws Exception { + InputFile input = file("A.java", source); + + List expected = describe(parseAll(JDTParser.create(JParser.Mode.BATCH, new JavaVersionImpl(21), List.of(), false, true), input).get(0)); + List actual = describe(parseAll(semSitter(), input).get(0)); + + int common = Math.min(expected.size(), actual.size()); + int mismatch = 0; + while (mismatch < common && expected.get(mismatch).equals(actual.get(mismatch))) { + mismatch++; + } + assertThat(actual.subList(Math.max(0, mismatch - 2), Math.min(actual.size(), mismatch + 4))) + .as("first difference at node %d of %d", mismatch, expected.size()) + .containsExactlyElementsOf(expected.subList(Math.max(0, mismatch - 2), Math.min(expected.size(), mismatch + 4))); + assertThat(actual).hasSameSizeAs(expected); + } + + private JParser semSitter() { + return new SemSitterParser(JParser.Mode.BATCH, new JavaVersionImpl(21), List.of(), root -> SemSitterClient.start(Path.of(System.getProperty(EXECUTABLE)), root), + SemSitterTranslator::translate); + } + + private static List parseAll(JParser parser, InputFile input) { + List results = new ArrayList<>(); + parser.parse(List.of(input), () -> false, new AnalysisProgress(1), (file, result) -> results.add(result)); + return results; + } + + private InputFile file(String name, String source) throws IOException { + Files.writeString(project.resolve(name), source, StandardCharsets.UTF_8); + return new TestInputFileBuilder("module", name) + .setModuleBaseDir(project) + .setCharset(StandardCharsets.UTF_8) + .setLanguage("java") + .setContents(source) + .build(); + } + + private static List describe(JParseResult result) throws Exception { + List lines = new ArrayList<>(); + describe((Tree) result.get(), lines); + return lines; + } + + private static void describe(Tree tree, List lines) { + StringBuilder line = new StringBuilder(tree.kind().name()); + SyntaxToken first = tree.firstToken(); + if (first != null) { + line.append(" @").append(first.range().start().line()).append(':').append(first.range().start().column()); + } + if (tree instanceof IdentifierTree identifier) { + line.append(" id ").append(identifier.name()).append(" : ").append(identifier.symbolType().fullyQualifiedName()).append(' ').append(symbol(identifier.symbol())); + } else if (tree instanceof MethodInvocationTree invocation) { + line.append(" call ").append(symbol(invocation.methodSymbol())).append(" : ").append(invocation.symbolType().fullyQualifiedName()); + } + lines.add(line.toString()); + JavaTree javaTree = (JavaTree) tree; + if (javaTree.isLeaf()) { + return; + } + for (Tree child : javaTree.getChildren()) { + if (child != null) { + describe(child, lines); + } + } + } + + private static String symbol(Symbol symbol) { + if (symbol.isUnknown()) { + return "unknown"; + } + String owner = symbol.owner() == null ? "" : symbol.owner().name() + "."; + String kinds = String.valueOf(symbol.isMethodSymbol()) + symbol.isVariableSymbol() + symbol.isTypeSymbol(); + return owner + symbol.name() + " " + kinds; + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterParserProviderTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterParserProviderTest.java new file mode 100644 index 00000000000..72c673dd841 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterParserProviderTest.java @@ -0,0 +1,275 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import com.sonarsource.scanner.engine.sensor.test.fixtures.TestSonarRuntime; +import java.io.File; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.UnaryOperator; +import org.junit.jupiter.api.Test; +import org.sonar.api.SonarEdition; +import org.sonar.api.SonarQubeSide; +import org.sonar.api.SonarRuntime; +import org.sonar.api.config.Configuration; +import org.sonar.api.utils.Version; +import org.sonar.java.model.JParser; +import org.sonar.java.model.JavaVersionImpl; +import org.sonar.scanner.plugin.api.impl.config.MapSettings; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class SemSitterParserProviderTest { + + private static final String ENABLED = SemSitterFlag.ENABLED_PROPERTY; + private static final String EXECUTABLE = SemSitterParserProvider.EXECUTABLE_PROPERTY; + private static final String FULL_SOURCES = SemSitterFullSources.PROPERTY; + + private final DocumentTranslator translator = (document, loaders, noLibraries, javaVersion) -> { + throw new UnsupportedOperationException(); + }; + + @Test + void provider_is_disabled_until_configured() { + assertThat(provider(Map.of()).isEnabled()).isFalse(); + } + + @Test + void provider_is_disabled_without_property_nor_executable() { + SemSitterParserProvider provider = provider(Map.of()); + + provider.configure(settings(Map.of())); + + assertThat(provider.isEnabled()).isFalse(); + } + + @Test + void flag_on_without_executable_fails_instead_of_leaving_the_analysis_to_another_frontend() { + SemSitterParserProvider provider = provider(Map.of()); + Configuration configuration = settings(Map.of(ENABLED, "true")); + + assertThatThrownBy(() -> provider.configure(configuration)) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining(ENABLED) + .hasMessageContaining(EXECUTABLE) + .hasMessageContaining(SemSitterParserProvider.EXECUTABLE_ENVIRONMENT); + assertThat(provider.isEnabled()).isFalse(); + } + + @Test + void blank_executable_counts_as_no_executable() { + SemSitterParserProvider provider = provider(Map.of(SemSitterParserProvider.EXECUTABLE_ENVIRONMENT, " ")); + Configuration configuration = settings(Map.of(EXECUTABLE, " ", ENABLED, "true")); + + assertThatThrownBy(() -> provider.configure(configuration)).isInstanceOf(IllegalStateException.class); + } + + @Test + void executable_without_flag_keeps_the_default_frontend() { + SemSitterParserProvider provider = provider(Map.of()); + + provider.configure(settings(Map.of(EXECUTABLE, "/bin/semsitter"))); + + assertThat(provider.isEnabled()).isEqualTo(SemSitterFlag.DEFAULT); + } + + @Test + void property_enables_with_an_executable() { + SemSitterParserProvider provider = provider(Map.of()); + + provider.configure(settings(Map.of(EXECUTABLE, "/bin/semsitter", ENABLED, "true"))); + + assertThat(provider.isEnabled()).isTrue(); + } + + @Test + void property_false_keeps_the_default_frontend() { + SemSitterParserProvider provider = provider(Map.of()); + + provider.configure(settings(Map.of(EXECUTABLE, "/bin/semsitter", ENABLED, "false"))); + + assertThat(provider.isEnabled()).isFalse(); + } + + @Test + void executable_can_come_from_the_environment() { + SemSitterParserProvider provider = provider(Map.of(SemSitterParserProvider.EXECUTABLE_ENVIRONMENT, "/bin/semsitter")); + + provider.configure(settings(Map.of(ENABLED, "true"))); + + assertThat(provider.isEnabled()).isTrue(); + } + + @Test + void configuring_again_forgets_the_previous_analysis() { + SemSitterParserProvider provider = provider(Map.of()); + provider.configure(settings(Map.of(EXECUTABLE, "/bin/semsitter", ENABLED, "true"))); + assertThat(provider.isEnabled()).isTrue(); + + provider.configure(settings(Map.of())); + + assertThat(provider.isEnabled()).isFalse(); + } + + @Test + void full_sources_without_the_semsitter_frontend_fail_the_analysis() { + SemSitterParserProvider provider = provider(Map.of()); + Configuration offByDefault = settings(Map.of(FULL_SOURCES, "src/main/java")); + Configuration explicitlyOff = settings(Map.of(FULL_SOURCES, "src/main/java", ENABLED, "false", EXECUTABLE, "/bin/semsitter")); + + assertThatThrownBy(() -> provider.configure(offByDefault)).isInstanceOf(IllegalStateException.class).hasMessageContaining(FULL_SOURCES); + assertThatThrownBy(() -> provider.configure(explicitlyOff)).isInstanceOf(IllegalStateException.class).hasMessageContaining(FULL_SOURCES); + assertThat(provider.isEnabled()).isFalse(); + } + + @Test + void full_sources_with_the_semsitter_frontend_are_accepted() { + SemSitterParserProvider provider = provider(Map.of()); + + provider.configure(settings(Map.of(FULL_SOURCES, "src/main/java, src/test/java", EXECUTABLE, "/bin/semsitter", ENABLED, "true"))); + + assertThat(provider.isEnabled()).isTrue(); + } + + @Test + void configuring_again_forgets_the_full_sources() { + SemSitterParserProvider provider = provider(Map.of()); + provider.configure(settings(Map.of(FULL_SOURCES, "src", EXECUTABLE, "/bin/semsitter", ENABLED, "true"))); + assertThat(provider.fullSources()).containsExactly("src"); + + provider.configure(settings(Map.of(EXECUTABLE, "/bin/semsitter", ENABLED, "true"))); + + assertThat(provider.isEnabled()).isTrue(); + assertThat(provider.fullSources()).isEmpty(); + } + + @Test + void created_parser_is_the_semsitter_parser() { + SemSitterParserProvider provider = provider(Map.of()); + provider.configure(settings(Map.of(EXECUTABLE, Path.of("semsitter").toString(), ENABLED, "true"))); + + JParser parser = provider.create(JParser.Mode.BATCH, new JavaVersionImpl(17), List.of(new File("a.jar")), false, true); + + assertThat(parser).isInstanceOf(SemSitterParser.class); + } + + @Test + void bundled_server_turns_the_frontend_on_even_without_the_flag() { + SemSitterParserProvider provider = provider(Map.of(), Optional.of(Path.of("bundled"))); + + provider.configure(settings(Map.of()), runtime(SonarEdition.SONARCLOUD)); + + assertThat(provider.isEnabled()).isTrue(); + } + + @Test + void bundled_server_ignores_the_flag_turned_off() { + SemSitterParserProvider provider = provider(Map.of(), Optional.of(Path.of("bundled"))); + + provider.configure(settings(Map.of(ENABLED, "false")), runtime(SonarEdition.SONARCLOUD)); + + assertThat(provider.isEnabled()).isTrue(); + } + + @Test + void full_sources_are_accepted_where_the_bundled_server_turns_the_frontend_on() { + SemSitterParserProvider provider = provider(Map.of(), Optional.of(Path.of("bundled"))); + + provider.configure(settings(Map.of(FULL_SOURCES, "src/main/java")), runtime(SonarEdition.SONARCLOUD)); + + assertThat(provider.isEnabled()).isTrue(); + } + + @Test + void full_sources_fail_when_the_runtime_has_no_bundled_server_and_the_flag_is_off() { + SemSitterParserProvider provider = provider(Map.of(), Optional.empty()); + Configuration configuration = settings(Map.of(FULL_SOURCES, "src/main/java")); + SonarRuntime runtime = runtime(SonarEdition.COMMUNITY); + + assertThatThrownBy(() -> provider.configure(configuration, runtime)).isInstanceOf(IllegalStateException.class).hasMessageContaining(FULL_SOURCES); + } + + @Test + void configured_executable_wins_over_the_bundled_server() { + SemSitterParserProvider provider = provider(Map.of(), Optional.of(Path.of("bundled"))); + provider.configure(settings(Map.of(EXECUTABLE, "/bin/semsitter", ENABLED, "true")), runtime(SonarEdition.SONARCLOUD)); + + assertThat(provider.isEnabled()).isTrue(); + provider.configure(settings(Map.of(EXECUTABLE, "/bin/semsitter", ENABLED, "false")), runtime(SonarEdition.SONARCLOUD)); + assertThat(provider.isEnabled()).isFalse(); + } + + @Test + void no_bundled_server_and_no_flag_keeps_the_default_frontend() { + SemSitterParserProvider provider = provider(Map.of(), Optional.empty()); + + provider.configure(settings(Map.of()), runtime(SonarEdition.COMMUNITY)); + + assertThat(provider.isEnabled()).isFalse(); + } + + @Test + void no_bundled_server_and_flag_on_fails() { + SemSitterParserProvider provider = provider(Map.of(), Optional.empty()); + Configuration configuration = settings(Map.of(ENABLED, "true")); + SonarRuntime runtime = runtime(SonarEdition.COMMUNITY); + + assertThatThrownBy(() -> provider.configure(configuration, runtime)).isInstanceOf(IllegalStateException.class); + } + + @Test + void a_runtime_that_cannot_extract_the_bundled_server_fails_the_analysis() { + SemSitterParserProvider provider = new SemSitterParserProvider(key -> null, translator, runtime -> { + throw new IllegalStateException("no server for this host"); + }); + Configuration configuration = settings(Map.of()); + SonarRuntime runtime = runtime(SonarEdition.SONARCLOUD); + + assertThatThrownBy(() -> provider.configure(configuration, runtime)).hasMessage("no server for this host"); + } + + @Test + void bundled_server_is_not_asked_without_a_runtime() { + SemSitterParserProvider provider = provider(Map.of(), Optional.of(Path.of("bundled"))); + + provider.configure(settings(Map.of())); + + assertThat(provider.isEnabled()).isFalse(); + } + + private SemSitterParserProvider provider(Map environment) { + return provider(environment, Optional.empty()); + } + + private SemSitterParserProvider provider(Map environment, Optional bundled) { + UnaryOperator lookup = environment::get; + return new SemSitterParserProvider(lookup, translator, runtime -> bundled); + } + + private static SonarRuntime runtime(SonarEdition edition) { + return TestSonarRuntime.forSonarQube(Version.create(10, 0), SonarQubeSide.SCANNER, edition); + } + + private static Configuration settings(Map properties) { + MapSettings settings = new MapSettings(); + properties.forEach(settings::setProperty); + return settings.asConfig(); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterParserTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterParserTest.java index eb9f3e6269b..5f98c5b1904 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterParserTest.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterParserTest.java @@ -88,6 +88,60 @@ void every_file_is_parsed_against_one_server_started_on_the_common_directory() t } } + @Test + void full_sources_feed_the_server_graph_while_only_the_analyzed_file_is_parsed() throws Exception { + InputFile analyzed = file("src/p/A.java"); + Files.createDirectories(project.resolve("src/p")); + Files.createDirectories(project.resolve("src/q")); + Files.writeString(project.resolve("src/p/B.java"), "class B {}"); + Files.writeString(project.resolve("src/q/C.java"), "class C {}"); + Files.writeString(project.resolve("src/q/notes.txt"), "text"); + Path[] startedOn = new Path[1]; + + new SemSitterParser(JParser.Mode.BATCH, new JavaVersionImpl(17), List.of(), root -> { + startedOn[0] = root; + return server; + }, this::translate, project.resolve("no-jdk"), List.of("src")) + .parse(List.of(analyzed), () -> false, new AnalysisProgress(1), this::collect); + + assertThat(realPath(startedOn[0])).isEqualTo(realPath(project.resolve("src"))); + assertThat(server.scanned).containsExactly("p/A.java", "p/B.java", "q/C.java"); + assertThat(server.requests).containsExactly("set-settings", "full-gen", "get-file p/A.java"); + assertThat(results.keySet()).containsExactly("A.java"); + } + + @Test + void full_sources_above_the_analyzed_file_move_the_server_root_up() throws Exception { + InputFile analyzed = file("src/main/java/p/A.java"); + Files.createDirectories(project.resolve("src/test/java")); + Files.writeString(project.resolve("src/test/java/ATest.java"), "class ATest {}"); + Path[] startedOn = new Path[1]; + + new SemSitterParser(JParser.Mode.BATCH, new JavaVersionImpl(17), List.of(), root -> { + startedOn[0] = root; + return server; + }, this::translate, project.resolve("no-jdk"), List.of("src/test/java")) + .parse(List.of(analyzed), () -> false, new AnalysisProgress(1), this::collect); + + assertThat(realPath(startedOn[0])).isEqualTo(realPath(project.resolve("src"))); + assertThat(server.scanned).containsExactly("main/java/p/A.java", "test/java/ATest.java"); + assertThat(server.requests).containsOnlyOnce("get-file main/java/p/A.java"); + } + + @Test + void a_missing_full_sources_entry_fails_before_any_server_starts() { + AtomicInteger starts = new AtomicInteger(); + SemSitterParser parser = new SemSitterParser(JParser.Mode.BATCH, new JavaVersionImpl(17), List.of(), root -> { + starts.incrementAndGet(); + return server; + }, this::translate, project.resolve("no-jdk"), List.of("missing")); + List files = List.of(file("A.java")); + AnalysisProgress progress = new AnalysisProgress(1); + + assertThatThrownBy(() -> parser.parse(files, () -> false, progress, this::collect)).isInstanceOf(IllegalStateException.class).hasMessageContaining("missing"); + assertThat(starts).hasValue(0); + } + @Test void files_are_parsed_in_the_order_the_server_scans_them() { InputFile z = file("Z.java"); @@ -262,6 +316,27 @@ void batches_log_the_progress_of_the_whole_analysis() { .containsSubsequence("Starting batch processing.", "100% analyzed", "Batch processing: Done."); } + @Test + void opening_the_server_logs_how_long_each_step_of_the_graph_build_took() { + server.fullGenStats = new FullGenStats(2, 1234L, 1L, 3L * 1024 * 1024); + + parser(JParser.Mode.BATCH, new JavaVersionImpl(), List.of(), root -> server) + .parse(List.of(file("A.java"), file("B.java")), () -> false, new AnalysisProgress(2), this::collect); + + assertThat(logTester.logs(Level.INFO)).anyMatch(log -> log.matches( + "SemSitter graph of 2 files built in \\d+ ms \\(walk \\d+ ms, server start \\d+ ms, settings \\d+ ms, full-gen \\d+ ms; " + + "server-reported 1234 ms, 1 failures, peak RSS 3072 MB\\)")); + } + + @Test + void graph_build_log_shows_the_measures_the_server_does_not_report_as_unknown() { + parser(JParser.Mode.FILE_BY_FILE, new JavaVersionImpl(), List.of(), root -> server) + .parse(List.of(file("A.java")), () -> false, new AnalysisProgress(1), this::collect); + + assertThat(logTester.logs(Level.INFO)).anyMatch(log -> log.startsWith("SemSitter graph of 1 files built in ") + && log.endsWith("; server-reported n/a ms, n/a failures, peak RSS n/a MB)")); + } + @Test void batch_logs_the_share_of_the_analysis_done_once_a_period_has_passed() { AnalysisProgress analysisProgress = new AnalysisProgress(4); diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterTranslatorTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterTranslatorTest.java new file mode 100644 index 00000000000..8d6ca1dd4aa --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterTranslatorTest.java @@ -0,0 +1,217 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.protobuf.TextFormat; +import com.sonar.sslr.api.RecognitionException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.SymbolMetadata; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.CompilationUnitTree; +import org.sonar.plugins.java.api.tree.EnumConstantTree; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.SyntaxTrivia; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.VariableTree; +import org.sonarsource.semsitter.wire.Document; +import org.sonarsource.semsitter.wire.Node; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.sonar.java.semsitter.TranslationStateFixtures.all; +import static org.sonar.java.semsitter.TranslationStateFixtures.kind; +import static org.sonar.java.semsitter.TranslationStateFixtures.leaf; +import static org.sonar.java.semsitter.TranslationStateFixtures.mutate; +import static org.sonar.java.semsitter.TranslationStateFixtures.recorded; +import static org.sonar.java.semsitter.TranslationStateFixtures.text; +import static org.sonar.java.semsitter.TranslationStateFixtures.where; + +/** + * Translates documents a real SemSitter server answered for the sources next to them in the test resources, with the + * type declarations it answered for them. + */ +class SemSitterTranslatorTest { + + private static final Function, JsonObject> TYPES_ALREADY_SENT = names -> new JsonObject(); + + @Test + void enum_constant_calls_the_enum_constructor() throws Exception { + List constants = enumConstants(translate("Outer", recordedTypes("Outer"))); + + assertThat(constants).extracting(constant -> constant.initializer().methodSymbol().name()).containsExactly("", ""); + assertThat(constants).allSatisfy(constant -> assertThat(((VariableTree) constant).symbol().isVariableSymbol()).isTrue()); + } + + @Test + void enum_constant_of_an_unknown_enum_calls_an_unknown_constructor() throws Exception { + List constants = enumConstants(translate("Outer", TYPES_ALREADY_SENT)); + + assertThat(constants).extracting(constant -> constant.initializer().methodSymbol()).containsOnly(Symbol.MethodSymbol.UNKNOWN_METHOD); + assertThat(constants).allSatisfy(constant -> assertThat(((VariableTree) constant).symbol().isVariableSymbol()).isTrue()); + } + + @Test + void an_unresolved_method_is_owned_by_the_unknown_type() { + JMethodSymbol method = new JMethodSymbol(new JSema(), null, "log"); + method.unknown(true); + + assertThat(method.owner()).isSameAs(Symbol.TypeSymbol.UNKNOWN_TYPE); + assertThat(((Symbol.TypeSymbol) method.owner()).memberSymbols()).isEmpty(); + } + + @Test + void annotation_values_are_constants_enum_constants_or_unknown() throws Exception { + Map values = annotationValues(translate("Routes", recordedTypes("Routes"))); + + assertThat(values) + .containsEntry("knownConstant", List.of("/local")) + .containsEntry("unknownConstant", Collections.singletonList(null)); + assertThat(values.get("enumConstant")).isInstanceOfSatisfying(Symbol.VariableSymbol.class, constant -> assertThat(constant.name()).isEqualTo("A")); + } + + @Test + void a_broken_document_is_rejected_at_its_first_missing_node() { + Document missingSemicolon = mutate(recorded("Imports"), where(kind(";"), node -> node.toBuilder().setMissing(true).build())).toBuilder().setHasError(true).build(); + Document noProblemNode = recorded("Imports").toBuilder().setHasError(true).build(); + + assertThatThrownBy(() -> TranslationStateFixtures.translate(missingSemicolon, 21)).isInstanceOf(RecognitionException.class) + .hasMessage("Parse error at line 1 column 25: Syntax error"); + assertThatThrownBy(() -> TranslationStateFixtures.translate(noProblemNode, 21)).isInstanceOf(RecognitionException.class) + .hasMessage("Parse error at line 1 column 1: Syntax error"); + } + + @Test + void top_level_semicolons_are_empty_statements() { + Document imports = recorded("Imports"); + Node program = imports.getTree().toBuilder() + .addChildren(12, leaf(";", ";", 13, 0)) + .addChildren(leaf(";", ";", 200, 0)) + .build(); + Node implicitProgram = recorded("java25/ImplicitClass").getTree().toBuilder().addChildren(leaf(";", ";", 19, 0)).build(); + + CompilationUnitTree unit = TranslationStateFixtures.translate(imports.toBuilder().setTree(program).build(), 21); + CompilationUnitTree implicit = TranslationStateFixtures.translate(recorded("java25/ImplicitClass").toBuilder().setTree(implicitProgram).build(), 25); + + assertThat(unit.imports()).hasSize(13).last().matches(tree -> tree.is(Tree.Kind.EMPTY_STATEMENT)); + assertThat(unit.types()).extracting(Tree::kind).containsExactly(Tree.Kind.CLASS, Tree.Kind.EMPTY_STATEMENT); + assertThat(((ClassTree) implicit.types().get(0)).members()).last().matches(tree -> tree.is(Tree.Kind.EMPTY_STATEMENT)); + } + + @Test + void records_are_classes_before_java_16() { + CompilationUnitTree before = TranslationStateFixtures.translate(recorded("Declarations"), 15); + CompilationUnitTree after = TranslationStateFixtures.translate(recorded("Declarations"), 16); + + assertThat(all(before, ClassTree.class)).noneMatch(tree -> tree.is(Tree.Kind.RECORD)); + assertThat(all(after, ClassTree.class)).anyMatch(tree -> tree.is(Tree.Kind.RECORD)); + } + + @Test + void the_implicit_class_is_the_one_the_scan_declared_whatever_the_path() { + Document document = recorded("java25/ImplicitClass"); + + assertThat(implicitClass(document.toBuilder().setPath("dir/ImplicitClass").build()).symbol().name()).isEqualTo("ImplicitClass"); + assertThat(implicitClass(document).symbol().name()).isEqualTo("ImplicitClass"); + assertThat(implicitClass(document.toBuilder().clearPath().build()).symbol().name()).isEqualTo("ImplicitClass"); + } + + @Test + void a_line_comment_ending_with_a_carriage_return_drops_it() { + Document document = mutate(recorded("java25/ImplicitClass"), where(text("/// Greets `name`."), node -> node.toBuilder().setText("/// Greets `name`.\r").build())); + + MethodTree greet = (MethodTree) implicitClass(document).members().get(2); + + assertThat(greet.firstToken().trivias()).extracting(SyntaxTrivia::comment).containsExactly("/// Greets `name`."); + } + + private static ClassTree implicitClass(Document document) { + return (ClassTree) TranslationStateFixtures.translate(document, 25).types().get(0); + } + + private static CompilationUnitTree translate(String name, Function, JsonObject> types) throws Exception { + Document.Builder document = Document.newBuilder(); + try (InputStream input = resource(name + ".textproto")) { + TextFormat.merge(new InputStreamReader(input, StandardCharsets.UTF_8), document); + } + return SemSitterTranslator.translate(document.build(), types, pkg -> null, true, 17).get(); + } + + private static Function, JsonObject> recordedTypes(String name) throws IOException { + JsonObject recorded; + try (InputStream input = resource(name + ".types.json")) { + recorded = JsonParser.parseReader(new InputStreamReader(input, StandardCharsets.UTF_8)).getAsJsonObject(); + } + return new SessionTypes(names -> { + JsonObject answer = new JsonObject(); + names.stream().filter(recorded::has).forEach(type -> answer.add(type, recorded.get(type))); + return answer; + })::get; + } + + private static InputStream resource(String name) { + return Objects.requireNonNull(SemSitterTranslatorTest.class.getResourceAsStream("translator/" + name), name); + } + + private static List enumConstants(CompilationUnitTree unit) { + List constants = new ArrayList<>(); + unit.accept(new BaseTreeVisitor() { + @Override + public void visitEnumConstant(EnumConstantTree tree) { + constants.add(tree); + super.visitEnumConstant(tree); + } + }); + return constants; + } + + private static Map annotationValues(CompilationUnitTree unit) { + List methods = new ArrayList<>(); + unit.accept(new BaseTreeVisitor() { + @Override + public void visitMethod(MethodTree tree) { + methods.add(tree); + super.visitMethod(tree); + } + }); + return methods.stream() + .filter(method -> !method.symbol().metadata().annotations().isEmpty()) + .collect(Collectors.toMap(method -> method.simpleName().name(), SemSitterTranslatorTest::firstValue)); + } + + private static Object firstValue(MethodTree method) { + SymbolMetadata.AnnotationInstance annotation = method.symbol().metadata().annotations().get(0); + Object value = annotation.values().get(0).value(); + return value instanceof Object[] array ? Arrays.asList(array) : value; + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemaAnnotationsTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemaAnnotationsTest.java index 58eff9c998a..7f3e5be3a8d 100644 --- a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemaAnnotationsTest.java +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemaAnnotationsTest.java @@ -98,6 +98,9 @@ void declared_annotations_of_a_graph_fact_keep_no_values() { assertThat(names(declared)).containsExactly("lib.Marker"); assertThat(declared.get(0).valuesKnown()).isFalse(); + FactAnnotation instance = new FactAnnotation(sema, "lib.Marker", declared.get(0).values(), false); + assertThat(instance.symbol().name()).isEqualTo("Marker"); + assertThat(instance.values()).extracting(AnnotationValue::name, AnnotationValue::value).containsExactly(tuple("value", null)); assertThat(annotations.declaredAnnotations("p.Other")).isEmpty(); assertThat(annotations.declaredAnnotations(null)).isEmpty(); } diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SymbolDetails.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SymbolDetails.java new file mode 100644 index 00000000000..e748e62c4c6 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SymbolDetails.java @@ -0,0 +1,160 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.SymbolMetadata; +import org.sonar.plugins.java.api.semantic.Type; + +/** + * What the checks most often ask of a symbol beyond its name and type: annotation values, nullability, overridden + * methods, members and subtyping. + */ +final class SymbolDetails { + + private static final List SUPERTYPES = List.of("java.lang.Object", "java.io.Serializable", "java.lang.Comparable", "java.lang.Number", + "java.lang.Runnable", "java.util.Collection", "java.lang.Throwable", "java.lang.annotation.Annotation"); + + private SymbolDetails() { + } + + static String of(Symbol symbol) { + StringBuilder out = new StringBuilder("details"); + out.append(" declared ").append(symbol.declaration() != null).append(" usages ").append(symbol.usages().size()); + out.append(" metadata ").append(metadata(symbol.metadata())); + out.append(" typeArguments ").append(Arrays.stream(symbol.metadata().parametersMetadata()).map(SymbolDetails::lookups).toList()); + out.append(" enclosing ").append(name(symbol.enclosingClass())); + out.append(" flags ").append(flags(symbol)); + if (symbol instanceof Symbol.MethodSymbol method) { + out.append(method(method)); + } else if (symbol instanceof Symbol.TypeSymbol type) { + out.append(type(type)); + } else if (symbol instanceof Symbol.VariableSymbol variable) { + out.append(" local ").append(variable.isLocalVariable()).append(" parameter ").append(variable.isParameter()) + .append(" effectivelyFinal ").append(variable.isEffectivelyFinal()).append(" constant ").append(variable.constantValue().orElse(null)); + if (variable.isLocalVariable() && variable.owner() instanceof Symbol.MethodSymbol owner) { + out.append(" owner ").append(owner(owner)); + } + } + return out.toString(); + } + + private static List flags(Symbol symbol) { + List flags = new java.util.ArrayList<>(); + addIf(flags, symbol.isStatic(), "static"); + addIf(flags, symbol.isFinal(), "final"); + addIf(flags, symbol.isAbstract(), "abstract"); + addIf(flags, symbol.isPublic(), "public"); + addIf(flags, symbol.isPrivate(), "private"); + addIf(flags, symbol.isProtected(), "protected"); + addIf(flags, symbol.isPackageVisibility(), "package"); + addIf(flags, symbol.isDeprecated(), "deprecated"); + addIf(flags, symbol.isVolatile(), "volatile"); + addIf(flags, symbol.isEnum(), "enum"); + addIf(flags, symbol.isInterface(), "interface"); + addIf(flags, symbol.isUnknown(), "unknown"); + return flags; + } + + private static void addIf(List flags, boolean condition, String flag) { + if (condition) { + flags.add(flag); + } + } + + private static String owner(Symbol.MethodSymbol owner) { + return owner.name() + " " + owner.signature() + " " + flags(owner) + " returns " + TreeDescription.type(owner.returnType().type()) + + " parameters " + owner.parameterTypes().size() + " thrown " + owner.thrownTypes().size() + " overridden " + owner.overriddenSymbols().size() + + " declared " + (owner.declaration() != null) + " usages " + owner.usages().size() + " metadata " + owner.metadata().annotations().size() + + " enclosing " + name(owner.enclosingClass()) + " type " + owner.type().isUnknown() + " kinds " + owner.isMethodSymbol() + owner.isTypeSymbol() + owner.isVariableSymbol() + + " other " + owner.isDefaultMethod() + owner.isSynchronizedMethod() + owner.isVarArgsMethod() + owner.isNativeMethod() + owner.isOverridable() + + owner.isParametrizedMethod() + owner.declarationParameters().size() + owner.isLocalVariable() + owner.isParameter(); + } + + private static String method(Symbol.MethodSymbol method) { + return " overridden " + method.overriddenSymbols().stream().map(overridden -> qualified(overridden) + lookups(overridden.metadata())).toList() + + " overridable " + method.isOverridable() + " generic " + method.isParametrizedMethod() + " default " + method.isDefaultMethod() + + " synchronized " + method.isSynchronizedMethod() + " varargs " + method.isVarArgsMethod() + " native " + method.isNativeMethod() + + " parameters " + method.declarationParameters().stream().map(Symbol::name).toList() + + " parameterMetadata " + Arrays.stream(method.metadata().parametersMetadata()).map(SymbolDetails::metadata).toList(); + } + + private static String type(Symbol.TypeSymbol type) { + Type self = type.type(); + return " members " + type.memberSymbols().stream().map(Symbol::name).sorted().toList() + + " lookupToString " + type.lookupSymbols("toString").size() + + " outermost " + name(type.outermostClass()) + + " annotation " + type.isAnnotation() + + " subtypeOf " + SUPERTYPES.stream().filter(self::isSubtypeOf).toList() + + " superTypes " + type.superTypes().stream().map(TreeDescription::type).sorted().toList() + + " numerical " + self.isNumerical() + " wrapper " + self.isPrimitiveWrapper() + " raw " + self.isRawType() + + " declaring " + name(self.declaringType().symbol()); + } + + private static String metadata(SymbolMetadata metadata) { + String annotations = metadata.annotations().stream() + .map(annotation -> annotation.symbol().type().fullyQualifiedName() + annotation.values().stream() + .map(value -> value.name() + "=" + value(value.value())).collect(Collectors.joining(",", "(", ")"))) + .sorted().collect(Collectors.joining(" ")); + SymbolMetadata.NullabilityData nullability = metadata.nullabilityData(); + return "[" + annotations + "] nullability " + nullability.type() + "/" + nullability.level() + + " nonNull " + nullability.isNonNull(SymbolMetadata.NullabilityLevel.PACKAGE, false, false) + + " nullable " + nullability.isNullable(SymbolMetadata.NullabilityLevel.PACKAGE, false, false) + + " strongNullable " + nullability.isStrongNullable(SymbolMetadata.NullabilityLevel.PACKAGE, false, false) + + " strict " + nullability.isNonNull(SymbolMetadata.NullabilityLevel.VARIABLE, true, true) + + nullability.isNullable(SymbolMetadata.NullabilityLevel.VARIABLE, true, true) + + nullability.isStrongNullable(SymbolMetadata.NullabilityLevel.VARIABLE, true, true) + + " meta " + nullability.metaAnnotation() + + " source " + (nullability.annotation() == null ? null : nullability.annotation().symbol().name()) + + " tree " + (nullability.declaration() != null) + + " lookups " + lookups(metadata); + } + + /** How each annotation is found again: its tree, its values by name, and whether the symbol counts as annotated with it. */ + private static String lookups(SymbolMetadata metadata) { + return metadata.annotations().stream() + .map(annotation -> { + String name = annotation.symbol().type().fullyQualifiedName(); + List values = metadata.valuesForAnnotation(name); + return name + " tree " + (metadata.findAnnotationTree(annotation) != null) + " values " + (values == null ? null : values.size()) + + " annotated " + metadata.isAnnotatedWith(name); + }) + .sorted().collect(Collectors.joining(", ", "[", "]")); + } + + private static String value(Object value) { + if (value instanceof Object[] array) { + return Arrays.stream(array).map(SymbolDetails::value).collect(Collectors.joining(",", "{", "}")); + } + if (value instanceof Symbol symbol) { + return qualified(symbol); + } + return String.valueOf(value); + } + + private static String qualified(Symbol symbol) { + return name(symbol.owner()) + "." + symbol.name(); + } + + private static String name(Symbol symbol) { + return symbol == null ? "null" : Objects.toString(symbol.name()); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ThrownTypesTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ThrownTypesTest.java new file mode 100644 index 00000000000..6b8ba147d30 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/ThrownTypesTest.java @@ -0,0 +1,170 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.TryStatementTree; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Collects thrown types on trees the ECJ frontend gives, as those of the SemSitter frontend have the same shape. */ +class ThrownTypesTest { + + private static final String SOURCE = """ + import java.io.FileReader; + import java.io.IOException; + import java.util.function.Supplier; + + class T { + void resource(String name) throws IOException { + try (FileReader reader = new FileReader(name)) { + } + } + + void existingResource(FileReader reader) throws IOException { + try (reader) { + } + } + + void notCloseable() { + try (Object object = new Object()) { + } + } + + void unknownResource() { + try (Missing missing = new Missing()) { + } + } + + void typeVariable(E e) throws E { + try { + throw e; + } finally { + } + } + + void nested() throws Exception { + try { + try { + throw new IOException(); + } catch (IllegalStateException | IllegalArgumentException caught) { + } + Supplier lazy = this::toString; + Runnable run = () -> { throw new RuntimeException(); }; + Object local = new Object() { + void inner() throws Exception { + throw new Exception(); + } + }; + } finally { + } + } + + void caughtByNested() { + try { + try { + throw new IOException(); + } catch (IOException caught) { + } + } finally { + } + } + + void unknownCall() { + try { + missing(); + } finally { + } + } + } + """; + + @TempDir + Path baseDir; + + private final Map tries = new HashMap<>(); + + @BeforeEach + void parse() throws Exception { + Replays.parseWithEcj(baseDir, "ThrownTypesSample", SOURCE).get().accept(new BaseTreeVisitor() { + private String method; + + @Override + public void visitMethod(MethodTree tree) { + method = tree.simpleName().name(); + super.visitMethod(tree); + } + + @Override + public void visitTryStatement(TryStatementTree tree) { + tries.putIfAbsent(method, tree); + super.visitTryStatement(tree); + } + }); + } + + @Test + void closing_a_resource_throws_what_its_close_method_declares() { + assertThat(thrown("resource").thrown).extracting(Type::fullyQualifiedName).contains("java.io.IOException"); + assertThat(thrown("resource").unknown).isFalse(); + assertThat(thrown("existingResource").thrown).extracting(Type::fullyQualifiedName).containsExactly("java.io.IOException"); + } + + @Test + void a_resource_without_close_or_type_is_unknown() { + assertThat(thrown("notCloseable").unknown).isTrue(); + assertThat(thrown("unknownResource").unknown).isTrue(); + } + + @Test + void a_thrown_type_variable_is_unknown() { + assertThat(thrown("typeVariable").unknown).isTrue(); + } + + @Test + void lambdas_and_nested_classes_throw_nothing_to_the_enclosing_body() { + ThrownTypes thrown = thrown("nested"); + + assertThat(thrown.unknown).isFalse(); + assertThat(thrown.thrown).extracting(Type::fullyQualifiedName).containsExactly("java.io.IOException"); + } + + @Test + void an_exception_caught_by_a_nested_try_is_not_thrown() { + assertThat(thrown("caughtByNested").thrown).isEmpty(); + } + + @Test + void an_unknown_call_is_unknown() { + assertThat(thrown("unknownCall").unknown).isTrue(); + } + + private ThrownTypes thrown(String method) { + TryStatementTree tree = tries.get(method); + ThrownTypes thrown = new ThrownTypes(); + thrown.scanTry(tree.resourceList(), tree.block()); + return thrown; + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/TranslationStateFixtures.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/TranslationStateFixtures.java new file mode 100644 index 00000000000..b8f8427a2d8 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/TranslationStateFixtures.java @@ -0,0 +1,151 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import com.google.gson.JsonObject; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; +import org.sonar.java.model.JParseResult; +import org.sonar.java.model.JavaTree; +import org.sonar.plugins.java.api.tree.CompilationUnitTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonarsource.semsitter.wire.Document; +import org.sonarsource.semsitter.wire.Node; +import org.sonarsource.semsitter.wire.Ref; + +/** Recorded replay documents, changed in place to reach the shapes and answers the recordings do not have. */ +final class TranslationStateFixtures { + + private static JsonObject types; + private static JsonObject packages; + + private TranslationStateFixtures() { + } + + static Document recorded(String sample) { + try { + return Replays.document(sample); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + static CompilationUnitTree translate(String sample) { + return translate(recorded(sample), Replays.javaVersion(sample)); + } + + /** Translates a document with the type declarations and package answers recorded for all the replay samples. */ + static CompilationUnitTree translate(Document document, int javaVersion) { + loadRecordings(); + SessionTypes session = new SessionTypes(names -> { + JsonObject answer = new JsonObject(); + names.stream().filter(types::has).forEach(name -> answer.add(name, types.get(name))); + return answer; + }); + JParseResult result = SemSitterTranslator.translate(document, session::get, TranslationStateFixtures::hasPackage, true, javaVersion); + try { + return result.get(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** The document with {@code change} applied to every node of its tree, children first. */ + static Document mutate(Document document, UnaryOperator change) { + return document.toBuilder().setTree(mutate(document.getTree(), change)).build(); + } + + private static Node mutate(Node node, UnaryOperator change) { + Node.Builder builder = node.toBuilder().clearChildren(); + node.getChildrenList().forEach(child -> builder.addChildren(mutate(child, change))); + return change.apply(builder.build()); + } + + /** Applies {@code change} to the nodes {@code selected} picks, and leaves the other nodes as they are. */ + static UnaryOperator where(Predicate selected, UnaryOperator change) { + return node -> selected.test(node) ? change.apply(node) : node; + } + + static Predicate text(String text) { + return node -> text.equals(node.getText()); + } + + static Predicate kind(String kind) { + return node -> kind.equals(node.getKind()); + } + + /** The node as SemSitter answers a name it could not resolve. */ + static Node unresolved(Node node) { + return node.toBuilder().clearRefs().addRefs(Ref.newBuilder().setAccess("r").setOutcome("unresolved")).build(); + } + + static Node leaf(String kind, String text, int line, int col) { + return Node.newBuilder().setKind(kind).setText(text).setStartLine(line).setStartCol(col).setEndLine(line).setEndCol(col + text.length()).build(); + } + + static Node inner(String kind, Node... children) { + Node.Builder builder = Node.newBuilder().setKind(kind).setNamed(true); + for (Node child : children) { + builder.addChildren(child); + } + if (children.length > 0) { + builder.setStartLine(children[0].getStartLine()).setStartCol(children[0].getStartCol()); + } + return builder.build(); + } + + static List all(Tree root, Class type) { + List found = new ArrayList<>(); + collect(root, type, found); + return found; + } + + private static void collect(Tree tree, Class type, List found) { + if (type.isInstance(tree)) { + found.add(type.cast(tree)); + } + if (tree instanceof JavaTree javaTree && !javaTree.isLeaf()) { + for (Tree child : javaTree.getChildren()) { + if (child != null) { + collect(child, type, found); + } + } + } + } + + private static synchronized void loadRecordings() { + if (types == null) { + try { + types = Replays.readJson(Replays.TYPES); + packages = Replays.readJson(Replays.PACKAGES); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + } + + private static Boolean hasPackage(String name) { + if (!packages.has(name) || packages.get(name).isJsonNull()) { + return null; + } + return packages.get(name).getAsBoolean(); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/TranslatorPartTest.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/TranslatorPartTest.java new file mode 100644 index 00000000000..d2b8cec756c --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/TranslatorPartTest.java @@ -0,0 +1,63 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.sonar.java.model.InternalSyntaxToken; +import org.sonar.java.model.expression.IdentifierTreeImpl; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonarsource.semsitter.wire.Node; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.java.semsitter.TranslationStateFixtures.inner; +import static org.sonar.java.semsitter.TranslationStateFixtures.leaf; + +class TranslatorPartTest { + + private final TranslationState state = new TranslationState(new JSema()); + private final TranslatorPart part = state.parts.names; + + @Test + void token_of_an_unindexed_node_is_its_first_leaf_or_its_text() { + Node semicolon = leaf(";", ";", 1, 9); + state.tokens.put(semicolon, new InternalSyntaxToken(1, 9, ";", List.of(), false)); + + assertThat(part.token(new CstNode(inner("statement", inner("x", leaf("y", "", 1, 0)), semicolon))).text()).isEqualTo(";"); + assertThat(part.token(new CstNode(inner("x", inner("y")))).text()).isEqualTo("x"); + assertThat(part.token(new CstNode(leaf("word", "word", 2, 3)))).extracting(InternalSyntaxToken::text, InternalSyntaxToken::line, InternalSyntaxToken::column) + .containsExactly("word", 2, 3); + assertThat(part.token(new CstNode(inner("null_literal"))).text()).isEmpty(); + } + + @Test + void syntactic_type_of_a_type_the_scan_did_not_bind_is_unknown() { + assertThat(part.syntacticType(new CstNode(leaf("integral_type", "int", 1, 0)))).isSameAs(Type.UNKNOWN); + assertThat(part.syntacticType(new CstNode(leaf("type_identifier", "Missing", 1, 0)))).isSameAs(Type.UNKNOWN); + assertThat(part.syntacticType(new CstNode(inner("generic_type", leaf("type_identifier", "Missing", 1, 0), inner("type_arguments"))))).isSameAs(Type.UNKNOWN); + } + + @Test + void a_declaration_without_a_name_binds_nothing() { + IdentifierTreeImpl identifier = new IdentifierTreeImpl(new InternalSyntaxToken(1, 0, "x", List.of(), false)); + + part.bindDeclaration(identifier, null, identifier); + + assertThat(identifier.symbol()).isSameAs(Symbol.UNKNOWN_SYMBOL); + } +} diff --git a/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/TreeDescription.java b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/TreeDescription.java new file mode 100644 index 00000000000..20f8e3df601 --- /dev/null +++ b/java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/TreeDescription.java @@ -0,0 +1,201 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.semsitter; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import javax.annotation.Nullable; +import org.sonar.java.model.JavaTree; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.MethodInvocationTree; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.NewClassTree; +import org.sonar.plugins.java.api.tree.SyntaxToken; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.VariableTree; + +/** + * One line per tree node with its kind, its position and what the semantic model says about it, so that two frontends + * can be compared node by node. + */ +final class TreeDescription { + + private TreeDescription() { + } + + static List describe(Tree tree) { + List lines = new ArrayList<>(); + describe(tree, lines, true); + lines.addAll(warnings(tree)); + return lines; + } + + static List warnings(Tree tree) { + List lines = new ArrayList<>(); + if (tree instanceof JavaTree.CompilationUnitTreeImpl unit) { + unit.supportedWarningKinds().stream().sorted().forEach(kind -> unit.warnings(kind).forEach(warning -> lines.add("WARNING " + kind + " " + + warning.syntaxTree().kind() + position(warning.syntaxTree()) + " " + warning.message()))); + } + return lines; + } + + private static String position(Tree tree) { + SyntaxToken first = tree.firstToken(); + return first == null ? "" : " @" + first.range().start().line() + ":" + first.range().start().column(); + } + + /** Only the kind and the position of each node. */ + static List shape(Tree tree) { + List lines = new ArrayList<>(); + describe(tree, lines, false); + return lines; + } + + private static void describe(Tree tree, List lines, boolean semantics) { + StringBuilder line = new StringBuilder(tree.kind().name()); + SyntaxToken first = tree.firstToken(); + if (first != null) { + line.append(" @").append(first.range().start().line()).append(':').append(first.range().start().column()); + } + if (semantics) { + describeSemantics(tree, line); + } + lines.add(line.toString()); + if (semantics) { + Symbol declared = declaredOrCalled(tree); + if (declared != null && !declared.isUnknown()) { + lines.add(" " + SymbolDetails.of(declared)); + } + } + JavaTree javaTree = (JavaTree) tree; + if (javaTree.isLeaf()) { + return; + } + for (Tree child : javaTree.getChildren()) { + if (child != null) { + describe(child, lines, semantics); + } + } + } + + @Nullable + private static Symbol declaredOrCalled(Tree tree) { + if (tree instanceof ClassTree type) { + return type.symbol(); + } else if (tree instanceof MethodTree method) { + return method.symbol(); + } else if (tree instanceof VariableTree variable) { + return variable.symbol(); + } else if (tree instanceof MethodInvocationTree invocation) { + return invocation.methodSymbol(); + } else if (tree instanceof NewClassTree creation) { + return creation.methodSymbol(); + } + return null; + } + + private static void describeSemantics(Tree tree, StringBuilder line) { + if (tree instanceof IdentifierTree identifier) { + line.append(" id ").append(identifier.name()).append(" ").append(symbol(identifier.symbol())); + } else if (tree instanceof MethodInvocationTree invocation) { + line.append(" call ").append(symbol(invocation.methodSymbol())); + } else if (tree instanceof NewClassTree creation) { + line.append(" new ").append(symbol(creation.methodSymbol())); + } else if (tree instanceof VariableTree variable) { + line.append(" var ").append(symbol(variable.symbol())); + } else if (tree instanceof MethodTree method) { + line.append(" method ").append(symbol(method.symbol())).append(" overrides ").append(method.isOverriding()); + } else if (tree instanceof ClassTree type && type.symbol() != null) { + line.append(" class ").append(symbol(type.symbol())).append(" super ").append(type(type.symbol().superClass())) + .append(" interfaces ").append(type.symbol().interfaces().stream().map(TreeDescription::type).toList()); + } + if (tree instanceof ExpressionTree expression) { + line.append(" : ").append(type(expression.symbolType())); + expression.asConstant().ifPresent(constant -> line.append(" = ").append(constant.toString().replace("\n", "\\n"))); + } + } + + private static String symbol(Symbol symbol) { + if (symbol.isUnknown()) { + return "unknown"; + } + StringBuilder out = new StringBuilder(); + Symbol owner = symbol.owner(); + out.append(owner == null ? "" : owner.name() + ".").append(symbol.name()); + out.append(" [").append(flags(symbol)).append("]"); + out.append(" : ").append(type(symbol.type())); + String annotations = symbol.metadata().annotations().stream().map(annotation -> annotation.symbol().type().fullyQualifiedName()).sorted().collect(Collectors.joining(",")); + if (!annotations.isEmpty()) { + out.append(" @").append(annotations); + } + if (symbol instanceof Symbol.MethodSymbol method) { + out.append(" (").append(method.parameterTypes().stream().map(TreeDescription::type).collect(Collectors.joining(","))).append(")"); + out.append(" returns ").append(method.returnType() == null ? "-" : type(method.returnType().type())); + out.append(" throws ").append(method.thrownTypes().stream().map(TreeDescription::type).toList()); + out.append(" sig ").append(method.signature()); + } + return out.toString(); + } + + private static String flags(Symbol symbol) { + StringBuilder flags = new StringBuilder(); + append(flags, symbol.isMethodSymbol(), "m"); + append(flags, symbol.isVariableSymbol(), "v"); + append(flags, symbol.isTypeSymbol(), "t"); + append(flags, symbol.isPackageSymbol(), "p"); + append(flags, symbol.isStatic(), "static"); + append(flags, symbol.isFinal(), "final"); + append(flags, symbol.isAbstract(), "abstract"); + append(flags, symbol.isPublic(), "public"); + append(flags, symbol.isPrivate(), "private"); + append(flags, symbol.isProtected(), "protected"); + append(flags, symbol.isPackageVisibility(), "package"); + append(flags, symbol.isEnum(), "enum"); + append(flags, symbol.isInterface(), "interface"); + append(flags, symbol.isDeprecated(), "deprecated"); + append(flags, symbol.isVolatile(), "volatile"); + return flags.toString(); + } + + private static void append(StringBuilder flags, boolean set, String name) { + if (set) { + flags.append(flags.isEmpty() ? "" : " ").append(name); + } + } + + static String type(Type type) { + if (type == null) { + return "null"; + } + if (type.isUnknown()) { + return "?"; + } + StringBuilder out = new StringBuilder(type.fullyQualifiedName()); + if (type.isParameterized()) { + out.append(type.typeArguments().stream().map(TreeDescription::type).collect(Collectors.joining(",", "<", ">"))); + } + if (!type.erasure().fullyQualifiedName().equals(type.fullyQualifiedName())) { + out.append(" erasure ").append(type.erasure().fullyQualifiedName()); + } + return out.toString(); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Annotations.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Annotations.expected.txt new file mode 100644 index 00000000000..443efd4b7c3 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Annotations.expected.txt @@ -0,0 +1,571 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id lang unknown : ? +TOKEN @1:13 +TOKEN @1:17 +IDENTIFIER @1:18 id annotation unknown : ? +TOKEN @1:18 +TOKEN @1:28 +IDENTIFIER @1:29 id Documented unknown : ? +TOKEN @1:29 +TOKEN @1:39 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id lang unknown : ? +TOKEN @2:13 +TOKEN @2:17 +IDENTIFIER @2:18 id annotation unknown : ? +TOKEN @2:18 +TOKEN @2:28 +IDENTIFIER @2:29 id ElementType unknown : ? +TOKEN @2:29 +TOKEN @2:40 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id lang unknown : ? +TOKEN @3:13 +TOKEN @3:17 +IDENTIFIER @3:18 id annotation unknown : ? +TOKEN @3:18 +TOKEN @3:28 +IDENTIFIER @3:29 id Retention unknown : ? +TOKEN @3:29 +TOKEN @3:38 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id lang unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id annotation unknown : ? +TOKEN @4:18 +TOKEN @4:28 +IDENTIFIER @4:29 id RetentionPolicy unknown : ? +TOKEN @4:29 +TOKEN @4:44 +IMPORT @5:1 +TOKEN @5:1 +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +IDENTIFIER @5:8 id java unknown : ? +TOKEN @5:8 +TOKEN @5:12 +IDENTIFIER @5:13 id lang unknown : ? +TOKEN @5:13 +TOKEN @5:17 +IDENTIFIER @5:18 id annotation unknown : ? +TOKEN @5:18 +TOKEN @5:28 +IDENTIFIER @5:29 id Target unknown : ? +TOKEN @5:29 +TOKEN @5:35 +IMPORT @6:1 +TOKEN @6:1 +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +IDENTIFIER @6:8 id java unknown : ? +TOKEN @6:8 +TOKEN @6:12 +IDENTIFIER @6:13 id util unknown : ? +TOKEN @6:13 +TOKEN @6:17 +IDENTIFIER @6:18 id List unknown : ? +TOKEN @6:18 +TOKEN @6:22 +CLASS @8:1 class .Annotations [t package] : Annotations @java.lang.SuppressWarnings super java.lang.Object interfaces [] + details declared true usages 0 metadata [java.lang.SuppressWarnings(value={unchecked,rawtypes})] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [java.lang.SuppressWarnings tree true values 1 annotated true] typeArguments [] enclosing Annotations flags [package] members [, Callback, Config, Mode, PATH, configured, removed, safe, single, toString, unused] lookupToString 1 outermost Annotations annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Annotations +MODIFIERS @8:1 +ANNOTATION @8:1 : java.lang.SuppressWarnings +TOKEN @8:1 +IDENTIFIER @8:2 id SuppressWarnings java.lang.SuppressWarnings [t public interface] : java.lang.SuppressWarnings @java.lang.annotation.Retention : java.lang.SuppressWarnings +TOKEN @8:2 +ARGUMENTS @8:18 +TOKEN @8:18 +NEW_ARRAY @8:19 : java.lang.String[] +TOKEN @8:19 +LIST @8:20 +STRING_LITERAL @8:20 : java.lang.String = unchecked +TOKEN @8:20 +TOKEN @8:31 +STRING_LITERAL @8:33 : java.lang.String = rawtypes +TOKEN @8:33 +TOKEN @8:43 +TOKEN @8:44 +TOKEN @9:1 +IDENTIFIER @9:7 id Annotations .Annotations [t package] : Annotations @java.lang.SuppressWarnings : Annotations +TOKEN @9:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @9:19 +VARIABLE @11:3 var Annotations.PATH [v static final package] : java.lang.String + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Annotations flags [static, final, package] local false parameter false effectivelyFinal true constant /root +MODIFIERS @11:3 +TOKEN @11:3 +TOKEN @11:10 +IDENTIFIER @11:16 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @11:16 +IDENTIFIER @11:23 id PATH Annotations.PATH [v static final package] : java.lang.String : java.lang.String = /root +TOKEN @11:23 +TOKEN @11:28 +STRING_LITERAL @11:30 : java.lang.String = /root +TOKEN @11:30 +TOKEN @11:37 +ENUM @13:3 class Annotations.Mode [t static final package enum] : Annotations$Mode super java.lang.Enum interfaces [] + details declared true usages 3 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Annotations flags [static, final, package, enum] members [, A, B, valueOf, values] lookupToString 0 outermost Annotations annotation false subtypeOf [java.lang.Object, java.io.Serializable, java.lang.Comparable] superTypes [java.io.Serializable, java.lang.Comparable, java.lang.Enum, java.lang.Object, java.lang.constant.Constable] numerical false wrapper false raw false declaring Mode +MODIFIERS +TOKEN @13:3 +IDENTIFIER @13:8 id Mode Annotations.Mode [t static final package enum] : Annotations$Mode : Annotations$Mode +TOKEN @13:8 +TYPE_PARAMETERS +LIST +LIST +TOKEN @13:13 +ENUM_CONSTANT @14:5 var Mode.A [v static final public enum] : Annotations$Mode + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Mode flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @14:5 new Mode. [m private] : ? () returns void throws [] sig Annotations$Mode#(Ljava/lang/String;I)V : ? + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Mode flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @14:5 id A Mode. [m private] : ? () returns void throws [] sig Annotations$Mode#(Ljava/lang/String;I)V : Annotations$Mode +TOKEN @14:5 +ARGUMENTS +TOKEN @14:6 +ENUM_CONSTANT @14:8 var Mode.B [v static final public enum] : Annotations$Mode + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Mode flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @14:8 new Mode. [m private] : ? () returns void throws [] sig Annotations$Mode#(Ljava/lang/String;I)V : ? + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Mode flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @14:8 id B Mode. [m private] : ? () returns void throws [] sig Annotations$Mode#(Ljava/lang/String;I)V : Annotations$Mode +TOKEN @14:8 +ARGUMENTS +TOKEN @15:3 +ANNOTATION_TYPE @17:3 class Annotations.Config [t static package interface] : Annotations$Config @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target super java.lang.Object interfaces [java.lang.annotation.Annotation] + details declared true usages 3 metadata [java.lang.annotation.Documented() java.lang.annotation.Retention(value=RetentionPolicy.RUNTIME) java.lang.annotation.Target(value={ElementType.METHOD,ElementType.FIELD,ElementType.PARAMETER,ElementType.TYPE})] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [java.lang.annotation.Documented tree true values 0 annotated true, java.lang.annotation.Retention tree true values 1 annotated true, java.lang.annotation.Target tree true values 1 annotated true] typeArguments [] enclosing Annotations flags [static, package, interface] members [mode, paths, priority, type, value] lookupToString 0 outermost Annotations annotation true subtypeOf [java.lang.Object, java.lang.annotation.Annotation] superTypes [java.lang.Object, java.lang.annotation.Annotation] numerical false wrapper false raw false declaring Config +MODIFIERS @17:3 +ANNOTATION @17:3 : java.lang.annotation.Documented +TOKEN @17:3 +IDENTIFIER @17:4 id Documented java.lang.annotation.Documented [t public interface] : java.lang.annotation.Documented @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.annotation.Documented +TOKEN @17:4 +ARGUMENTS +ANNOTATION @18:3 : java.lang.annotation.Retention +TOKEN @18:3 +IDENTIFIER @18:4 id Retention java.lang.annotation.Retention [t public interface] : java.lang.annotation.Retention @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.annotation.Retention +TOKEN @18:4 +ARGUMENTS @18:13 +TOKEN @18:13 +MEMBER_SELECT @18:14 : java.lang.annotation.RetentionPolicy +IDENTIFIER @18:14 id RetentionPolicy java.lang.annotation.RetentionPolicy [t final public enum] : java.lang.annotation.RetentionPolicy : java.lang.annotation.RetentionPolicy +TOKEN @18:14 +TOKEN @18:29 +IDENTIFIER @18:30 id RUNTIME RetentionPolicy.RUNTIME [v static final public enum] : java.lang.annotation.RetentionPolicy : java.lang.annotation.RetentionPolicy +TOKEN @18:30 +TOKEN @18:37 +ANNOTATION @19:3 : java.lang.annotation.Target +TOKEN @19:3 +IDENTIFIER @19:4 id Target java.lang.annotation.Target [t public interface] : java.lang.annotation.Target @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.annotation.Target +TOKEN @19:4 +ARGUMENTS @19:10 +TOKEN @19:10 +NEW_ARRAY @19:11 : java.lang.annotation.ElementType[] +TOKEN @19:11 +LIST @19:12 +MEMBER_SELECT @19:12 : java.lang.annotation.ElementType +IDENTIFIER @19:12 id ElementType java.lang.annotation.ElementType [t final public enum] : java.lang.annotation.ElementType : java.lang.annotation.ElementType +TOKEN @19:12 +TOKEN @19:23 +IDENTIFIER @19:24 id METHOD ElementType.METHOD [v static final public enum] : java.lang.annotation.ElementType : java.lang.annotation.ElementType +TOKEN @19:24 +TOKEN @19:30 +MEMBER_SELECT @19:32 : java.lang.annotation.ElementType +IDENTIFIER @19:32 id ElementType java.lang.annotation.ElementType [t final public enum] : java.lang.annotation.ElementType : java.lang.annotation.ElementType +TOKEN @19:32 +TOKEN @19:43 +IDENTIFIER @19:44 id FIELD ElementType.FIELD [v static final public enum] : java.lang.annotation.ElementType : java.lang.annotation.ElementType +TOKEN @19:44 +TOKEN @19:49 +MEMBER_SELECT @19:51 : java.lang.annotation.ElementType +IDENTIFIER @19:51 id ElementType java.lang.annotation.ElementType [t final public enum] : java.lang.annotation.ElementType : java.lang.annotation.ElementType +TOKEN @19:51 +TOKEN @19:62 +IDENTIFIER @19:63 id PARAMETER ElementType.PARAMETER [v static final public enum] : java.lang.annotation.ElementType : java.lang.annotation.ElementType +TOKEN @19:63 +TOKEN @19:72 +MEMBER_SELECT @19:74 : java.lang.annotation.ElementType +IDENTIFIER @19:74 id ElementType java.lang.annotation.ElementType [t final public enum] : java.lang.annotation.ElementType : java.lang.annotation.ElementType +TOKEN @19:74 +TOKEN @19:85 +IDENTIFIER @19:86 id TYPE ElementType.TYPE [v static final public enum] : java.lang.annotation.ElementType : java.lang.annotation.ElementType +TOKEN @19:86 +TOKEN @19:90 +TOKEN @19:91 +TOKEN @20:3 +TOKEN @20:4 +IDENTIFIER @20:14 id Config Annotations.Config [t static package interface] : Annotations$Config @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : Annotations$Config +TOKEN @20:14 +TYPE_PARAMETERS +LIST +LIST +TOKEN @20:21 +METHOD @21:5 method Config.value [m abstract public] : ? () returns java.lang.String throws [] sig Annotations$Config#value()Ljava/lang/String; overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Config flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @21:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @21:5 +IDENTIFIER @21:12 id value Config.value [m abstract public] : ? () returns java.lang.String throws [] sig Annotations$Config#value()Ljava/lang/String; : java.lang.String +TOKEN @21:12 +TOKEN @21:17 +TOKEN @21:18 +TOKEN @21:20 +STRING_LITERAL @21:28 : java.lang.String = +TOKEN @21:28 +TOKEN @21:30 +METHOD @23:5 method Config.paths [m abstract public] : ? () returns java.lang.String[] throws [] sig Annotations$Config#paths()[Ljava/lang/String; overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Config flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +ARRAY_TYPE @23:5 : java.lang.String[] +IDENTIFIER @23:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @23:5 +TOKEN @23:11 +TOKEN @23:12 +IDENTIFIER @23:14 id paths Config.paths [m abstract public] : ? () returns java.lang.String[] throws [] sig Annotations$Config#paths()[Ljava/lang/String; : java.lang.String[] +TOKEN @23:14 +TOKEN @23:19 +TOKEN @23:20 +TOKEN @23:22 +NEW_ARRAY @23:30 : ? +TOKEN @23:30 +LIST +TOKEN @23:31 +TOKEN @23:32 +METHOD @25:5 method Config.mode [m abstract public] : ? () returns Annotations$Mode throws [] sig Annotations$Config#mode()LAnnotations$Mode; overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Config flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @25:5 id Mode Annotations.Mode [t static final package enum] : Annotations$Mode : Annotations$Mode +TOKEN @25:5 +IDENTIFIER @25:10 id mode Config.mode [m abstract public] : ? () returns Annotations$Mode throws [] sig Annotations$Config#mode()LAnnotations$Mode; : Annotations$Mode +TOKEN @25:10 +TOKEN @25:14 +TOKEN @25:15 +TOKEN @25:17 +MEMBER_SELECT @25:25 : Annotations$Mode +IDENTIFIER @25:25 id Mode Annotations.Mode [t static final package enum] : Annotations$Mode : Annotations$Mode +TOKEN @25:25 +TOKEN @25:29 +IDENTIFIER @25:30 id A Mode.A [v static final public enum] : Annotations$Mode : Annotations$Mode +TOKEN @25:30 +TOKEN @25:31 +METHOD @27:5 method Config.priority [m abstract public] : ? () returns int throws [] sig Annotations$Config#priority()I overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Config flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @27:5 : int +TOKEN @27:5 +IDENTIFIER @27:9 id priority Config.priority [m abstract public] : ? () returns int throws [] sig Annotations$Config#priority()I : int +TOKEN @27:9 +TOKEN @27:17 +TOKEN @27:18 +TOKEN @27:20 +INT_LITERAL @27:28 : int = 1 +TOKEN @27:28 +TOKEN @27:29 +METHOD @29:5 method Config.type [m abstract public] : ? () returns java.lang.Class throws [] sig Annotations$Config#type()Ljava/lang/Class; overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Config flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS +TYPE_PARAMETERS +PARAMETERIZED_TYPE @29:5 : java.lang.Class +IDENTIFIER @29:5 id Class java.lang.Class [t final public] : java.lang.Class : java.lang.Class +TOKEN @29:5 +TYPE_ARGUMENTS @29:10 +TOKEN @29:10 +UNBOUNDED_WILDCARD @29:11 +TOKEN @29:11 +TOKEN @29:12 +IDENTIFIER @29:14 id type Config.type [m abstract public] : ? () returns java.lang.Class throws [] sig Annotations$Config#type()Ljava/lang/Class; : java.lang.Class +TOKEN @29:14 +TOKEN @29:18 +TOKEN @29:19 +TOKEN @29:21 +MEMBER_SELECT @29:29 : java.lang.Class +IDENTIFIER @29:29 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @29:29 +TOKEN @29:35 +IDENTIFIER @29:36 id class unknown : ? +TOKEN @29:36 +TOKEN @29:41 +TOKEN @30:3 +VARIABLE @32:3 var Annotations.single [v package] : int @Annotations$Config + details declared true usages 0 metadata [Annotations$Config(value=single)] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [Annotations$Config tree true values 1 annotated true] typeArguments [] enclosing Annotations flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS @32:3 +ANNOTATION @32:3 : Annotations$Config +TOKEN @32:3 +IDENTIFIER @32:4 id Config Annotations.Config [t static package interface] : Annotations$Config @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : Annotations$Config +TOKEN @32:4 +ARGUMENTS @32:10 +TOKEN @32:10 +STRING_LITERAL @32:11 : java.lang.String = single +TOKEN @32:11 +TOKEN @32:19 +PRIMITIVE_TYPE @33:3 : int +TOKEN @33:3 +IDENTIFIER @33:7 id single Annotations.single [v package] : int @Annotations$Config : int +TOKEN @33:7 +TOKEN @33:13 +METHOD @35:3 method Annotations.configured [m package] : ? @Annotations$Config (java.lang.String) returns void throws [] sig Annotations#configured(Ljava/lang/String;)V overrides false + details declared true usages 0 metadata [Annotations$Config(value=/root,paths={/root/a,/b},mode=Mode.B,priority=5,type=java.lang.String)] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [Annotations$Config tree true values 5 annotated true] typeArguments [] enclosing Annotations flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [parameter] parameterMetadata [] +MODIFIERS @35:3 +ANNOTATION @35:3 : Annotations$Config +TOKEN @35:3 +IDENTIFIER @35:4 id Config Annotations.Config [t static package interface] : Annotations$Config @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : Annotations$Config +TOKEN @35:4 +ARGUMENTS @35:10 +TOKEN @35:10 +ASSIGNMENT @35:11 : java.lang.String +IDENTIFIER @35:11 id value Config.value [m abstract public] : ? () returns java.lang.String throws [] sig Annotations$Config#value()Ljava/lang/String; : java.lang.String +TOKEN @35:11 +TOKEN @35:17 +IDENTIFIER @35:19 id PATH Annotations.PATH [v static final package] : java.lang.String : java.lang.String = /root +TOKEN @35:19 +TOKEN @35:23 +ASSIGNMENT @35:25 : java.lang.String[] +IDENTIFIER @35:25 id paths Config.paths [m abstract public] : ? () returns java.lang.String[] throws [] sig Annotations$Config#paths()[Ljava/lang/String; : java.lang.String[] +TOKEN @35:25 +TOKEN @35:31 +NEW_ARRAY @35:33 : java.lang.String[] +TOKEN @35:33 +LIST @35:34 +PLUS @35:34 : java.lang.String = /root/a +IDENTIFIER @35:34 id PATH Annotations.PATH [v static final package] : java.lang.String : java.lang.String = /root +TOKEN @35:34 +TOKEN @35:39 +STRING_LITERAL @35:41 : java.lang.String = /a +TOKEN @35:41 +TOKEN @35:45 +STRING_LITERAL @35:47 : java.lang.String = /b +TOKEN @35:47 +TOKEN @35:51 +TOKEN @35:52 +ASSIGNMENT @35:54 : Annotations$Mode +IDENTIFIER @35:54 id mode Config.mode [m abstract public] : ? () returns Annotations$Mode throws [] sig Annotations$Config#mode()LAnnotations$Mode; : Annotations$Mode +TOKEN @35:54 +TOKEN @35:59 +MEMBER_SELECT @35:61 : Annotations$Mode +IDENTIFIER @35:61 id Mode Annotations.Mode [t static final package enum] : Annotations$Mode : Annotations$Mode +TOKEN @35:61 +TOKEN @35:65 +IDENTIFIER @35:66 id B Mode.B [v static final public enum] : Annotations$Mode : Annotations$Mode +TOKEN @35:66 +TOKEN @35:67 +ASSIGNMENT @35:69 : int +IDENTIFIER @35:69 id priority Config.priority [m abstract public] : ? () returns int throws [] sig Annotations$Config#priority()I : int +TOKEN @35:69 +TOKEN @35:78 +PLUS @35:80 : int = 5 +INT_LITERAL @35:80 : int = 2 +TOKEN @35:80 +TOKEN @35:82 +INT_LITERAL @35:84 : int = 3 +TOKEN @35:84 +TOKEN @35:85 +ASSIGNMENT @35:87 : java.lang.Class +IDENTIFIER @35:87 id type Config.type [m abstract public] : ? () returns java.lang.Class throws [] sig Annotations$Config#type()Ljava/lang/Class; : java.lang.Class +TOKEN @35:87 +TOKEN @35:92 +MEMBER_SELECT @35:94 : java.lang.Class +IDENTIFIER @35:94 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @35:94 +TOKEN @35:100 +IDENTIFIER @35:101 id class unknown : ? +TOKEN @35:101 +TOKEN @35:106 +TYPE_PARAMETERS +PRIMITIVE_TYPE @36:3 : void +TOKEN @36:3 +IDENTIFIER @36:8 id configured Annotations.configured [m package] : ? @Annotations$Config (java.lang.String) returns void throws [] sig Annotations#configured(Ljava/lang/String;)V : void +TOKEN @36:8 +TOKEN @36:18 +VARIABLE @36:19 var configured.parameter [v package] : java.lang.String @Annotations$Config + details declared true usages 0 metadata [Annotations$Config(value=param)] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [Annotations$Config tree true values 1 annotated true] typeArguments [] enclosing Annotations flags [package] local true parameter true effectivelyFinal true constant null owner configured Annotations#configured(Ljava/lang/String;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Annotations type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS @36:19 +ANNOTATION @36:19 : Annotations$Config +TOKEN @36:19 +IDENTIFIER @36:20 id Config Annotations.Config [t static package interface] : Annotations$Config @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : Annotations$Config +TOKEN @36:20 +ARGUMENTS @36:26 +TOKEN @36:26 +STRING_LITERAL @36:27 : java.lang.String = param +TOKEN @36:27 +TOKEN @36:34 +IDENTIFIER @36:36 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @36:36 +IDENTIFIER @36:43 id parameter configured.parameter [v package] : java.lang.String @Annotations$Config : java.lang.String +TOKEN @36:43 +TOKEN @36:52 +BLOCK @36:54 +TOKEN @36:54 +TOKEN @37:3 +METHOD @39:3 method Annotations.removed [m package deprecated] : ? @java.lang.Deprecated () returns void throws [] sig Annotations#removed()V overrides false + details declared true usages 0 metadata [java.lang.Deprecated(since=1.0,forRemoval=true)] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Deprecated tree true values 2 annotated true] typeArguments [] enclosing Annotations flags [package, deprecated] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @39:3 +ANNOTATION @39:3 : java.lang.Deprecated +TOKEN @39:3 +IDENTIFIER @39:4 id Deprecated java.lang.Deprecated [t public interface] : java.lang.Deprecated @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Deprecated +TOKEN @39:4 +ARGUMENTS @39:14 +TOKEN @39:14 +ASSIGNMENT @39:15 : java.lang.String +IDENTIFIER @39:15 id since Deprecated.since [m abstract public] : ? () returns java.lang.String throws [] sig java.lang.Deprecated#since()Ljava/lang/String; : java.lang.String +TOKEN @39:15 +TOKEN @39:21 +STRING_LITERAL @39:23 : java.lang.String = 1.0 +TOKEN @39:23 +TOKEN @39:28 +ASSIGNMENT @39:30 : boolean +IDENTIFIER @39:30 id forRemoval Deprecated.forRemoval [m abstract public] : ? () returns boolean throws [] sig java.lang.Deprecated#forRemoval()Z : boolean +TOKEN @39:30 +TOKEN @39:41 +BOOLEAN_LITERAL @39:43 : boolean = true +TOKEN @39:43 +TOKEN @39:47 +TYPE_PARAMETERS +PRIMITIVE_TYPE @40:3 : void +TOKEN @40:3 +IDENTIFIER @40:8 id removed Annotations.removed [m package deprecated] : ? @java.lang.Deprecated () returns void throws [] sig Annotations#removed()V : void +TOKEN @40:8 +TOKEN @40:15 +TOKEN @40:16 +BLOCK @40:18 +TOKEN @40:18 +TOKEN @41:3 +METHOD @43:3 method Annotations.safe [m final package] : ? @java.lang.SafeVarargs (java.util.List[]) returns void throws [] sig Annotations#safe([Ljava/util/List;)V overrides false + details declared true usages 0 metadata [java.lang.SafeVarargs()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.SafeVarargs tree true values 0 annotated true] typeArguments [] enclosing Annotations flags [final, package] overridden [] overridable false generic false default false synchronized false varargs true native false parameters [lists] parameterMetadata [] +MODIFIERS @43:3 +ANNOTATION @43:3 : java.lang.SafeVarargs +TOKEN @43:3 +IDENTIFIER @43:4 id SafeVarargs java.lang.SafeVarargs [t public interface] : java.lang.SafeVarargs @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.SafeVarargs +TOKEN @43:4 +ARGUMENTS +TOKEN @44:3 +TYPE_PARAMETERS +PRIMITIVE_TYPE @44:9 : void +TOKEN @44:9 +IDENTIFIER @44:14 id safe Annotations.safe [m final package] : ? @java.lang.SafeVarargs (java.util.List[]) returns void throws [] sig Annotations#safe([Ljava/util/List;)V : void +TOKEN @44:14 +TOKEN @44:18 +VARIABLE @44:19 var safe.lists [v package] : java.util.List[] + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Annotations flags [package] local true parameter true effectivelyFinal true constant null owner safe Annotations#safe([Ljava/util/List;)V [final, package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Annotations type true kinds truefalsefalse other falsefalsetruefalsefalsefalse1falsefalse +MODIFIERS +ARRAY_TYPE @44:19 : java.util.List[] +PARAMETERIZED_TYPE @44:19 : java.util.List +IDENTIFIER @44:19 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @44:19 +TYPE_ARGUMENTS @44:23 +TOKEN @44:23 +IDENTIFIER @44:24 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @44:24 +TOKEN @44:30 +TOKEN @44:31 +IDENTIFIER @44:35 id lists safe.lists [v package] : java.util.List[] : java.util.List[] +TOKEN @44:35 +TOKEN @44:40 +BLOCK @44:42 +TOKEN @44:42 +TOKEN @45:3 +INTERFACE @47:3 class Annotations.Callback [t static package interface] : Annotations$Callback @java.lang.FunctionalInterface super java.lang.Object interfaces [] + details declared true usages 0 metadata [java.lang.FunctionalInterface()] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [java.lang.FunctionalInterface tree true values 0 annotated true] typeArguments [] enclosing Annotations flags [static, package, interface] members [call] lookupToString 0 outermost Annotations annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Callback +MODIFIERS @47:3 +ANNOTATION @47:3 : java.lang.FunctionalInterface +TOKEN @47:3 +IDENTIFIER @47:4 id FunctionalInterface java.lang.FunctionalInterface [t public interface] : java.lang.FunctionalInterface @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.FunctionalInterface +TOKEN @47:4 +ARGUMENTS +TOKEN @48:3 +IDENTIFIER @48:13 id Callback Annotations.Callback [t static package interface] : Annotations$Callback @java.lang.FunctionalInterface : Annotations$Callback +TOKEN @48:13 +TYPE_PARAMETERS +LIST +LIST +TOKEN @48:22 +METHOD @49:5 method Callback.call [m abstract public] : ? () returns void throws [] sig Annotations$Callback#call()V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Callback flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @49:5 : void +TOKEN @49:5 +IDENTIFIER @49:10 id call Callback.call [m abstract public] : ? () returns void throws [] sig Annotations$Callback#call()V : void +TOKEN @49:10 +TOKEN @49:14 +TOKEN @49:15 +TOKEN @49:16 +TOKEN @50:3 +METHOD @52:3 method Annotations.toString [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Annotations#toString()Ljava/lang/String; overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Annotations flags [public] overridden [Object.toString[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @52:3 +ANNOTATION @52:3 : java.lang.Override +TOKEN @52:3 +IDENTIFIER @52:4 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @52:4 +ARGUMENTS +TOKEN @53:3 +TYPE_PARAMETERS +IDENTIFIER @53:10 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @53:10 +IDENTIFIER @53:17 id toString Annotations.toString [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Annotations#toString()Ljava/lang/String; : java.lang.String +TOKEN @53:17 +TOKEN @53:25 +TOKEN @53:26 +BLOCK @53:28 +TOKEN @53:28 +RETURN_STATEMENT @54:5 +TOKEN @54:5 +STRING_LITERAL @54:12 : java.lang.String = annotations +TOKEN @54:12 +TOKEN @54:25 +TOKEN @55:3 +VARIABLE @57:3 var Annotations.unused [v private] : int @java.lang.SuppressWarnings + details declared true usages 0 metadata [java.lang.SuppressWarnings(value={unused})] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.SuppressWarnings tree true values 1 annotated true] typeArguments [] enclosing Annotations flags [private] local false parameter false effectivelyFinal false constant null +MODIFIERS @57:3 +ANNOTATION @57:3 : java.lang.SuppressWarnings +TOKEN @57:3 +IDENTIFIER @57:4 id SuppressWarnings java.lang.SuppressWarnings [t public interface] : java.lang.SuppressWarnings @java.lang.annotation.Retention : java.lang.SuppressWarnings +TOKEN @57:4 +ARGUMENTS @57:20 +TOKEN @57:20 +STRING_LITERAL @57:21 : java.lang.String = unused +TOKEN @57:21 +TOKEN @57:29 +TOKEN @58:3 +PRIMITIVE_TYPE @58:11 : int +TOKEN @58:11 +IDENTIFIER @58:15 id unused Annotations.unused [v private] : int @java.lang.SuppressWarnings : int +TOKEN @58:15 +TOKEN @58:21 +TOKEN @59:1 +TOKEN @60:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Annotations.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Annotations.java new file mode 100644 index 00000000000..ee486751150 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Annotations.java @@ -0,0 +1,59 @@ +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.List; + +@SuppressWarnings({"unchecked", "rawtypes"}) +class Annotations { + + static final String PATH = "/root"; + + enum Mode { + A, B + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) + @interface Config { + String value() default ""; + + String[] paths() default {}; + + Mode mode() default Mode.A; + + int priority() default 1; + + Class type() default Object.class; + } + + @Config("single") + int single; + + @Config(value = PATH, paths = {PATH + "/a", "/b"}, mode = Mode.B, priority = 2 + 3, type = String.class) + void configured(@Config("param") String parameter) { + } + + @Deprecated(since = "1.0", forRemoval = true) + void removed() { + } + + @SafeVarargs + final void safe(List... lists) { + } + + @FunctionalInterface + interface Callback { + void call(); + } + + @Override + public String toString() { + return "annotations"; + } + + @SuppressWarnings("unused") + private int unused; +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Annotations.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Annotations.textproto.gz new file mode 100644 index 00000000000..819a33e3519 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Annotations.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/CastContexts.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/CastContexts.expected.txt new file mode 100644 index 00000000000..4bce6c3eb3b --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/CastContexts.expected.txt @@ -0,0 +1,1406 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id io unknown : ? +TOKEN @1:13 +TOKEN @1:15 +IDENTIFIER @1:16 id Closeable unknown : ? +TOKEN @1:16 +TOKEN @1:25 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id io unknown : ? +TOKEN @2:13 +TOKEN @2:15 +IDENTIFIER @2:16 id FileNotFoundException unknown : ? +TOKEN @2:16 +TOKEN @2:37 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id io unknown : ? +TOKEN @3:13 +TOKEN @3:15 +IDENTIFIER @3:16 id FileReader unknown : ? +TOKEN @3:16 +TOKEN @3:26 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id io unknown : ? +TOKEN @4:13 +TOKEN @4:15 +IDENTIFIER @4:16 id IOException unknown : ? +TOKEN @4:16 +TOKEN @4:27 +IMPORT @5:1 +TOKEN @5:1 +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +IDENTIFIER @5:8 id java unknown : ? +TOKEN @5:8 +TOKEN @5:12 +IDENTIFIER @5:13 id io unknown : ? +TOKEN @5:13 +TOKEN @5:15 +IDENTIFIER @5:16 id Reader unknown : ? +TOKEN @5:16 +TOKEN @5:22 +IMPORT @6:1 +TOKEN @6:1 +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +IDENTIFIER @6:8 id java unknown : ? +TOKEN @6:8 +TOKEN @6:12 +IDENTIFIER @6:13 id util unknown : ? +TOKEN @6:13 +TOKEN @6:17 +IDENTIFIER @6:18 id List unknown : ? +TOKEN @6:18 +TOKEN @6:22 +IMPORT @7:1 +TOKEN @7:1 +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +IDENTIFIER @7:8 id java unknown : ? +TOKEN @7:8 +TOKEN @7:12 +IDENTIFIER @7:13 id util unknown : ? +TOKEN @7:13 +TOKEN @7:17 +IDENTIFIER @7:18 id function unknown : ? +TOKEN @7:18 +TOKEN @7:26 +IDENTIFIER @7:27 id Function unknown : ? +TOKEN @7:27 +TOKEN @7:35 +IMPORT @8:1 +TOKEN @8:1 +MEMBER_SELECT @8:8 : ? +MEMBER_SELECT @8:8 : ? +MEMBER_SELECT @8:8 : ? +IDENTIFIER @8:8 id java unknown : ? +TOKEN @8:8 +TOKEN @8:12 +IDENTIFIER @8:13 id util unknown : ? +TOKEN @8:13 +TOKEN @8:17 +IDENTIFIER @8:18 id function unknown : ? +TOKEN @8:18 +TOKEN @8:26 +IDENTIFIER @8:27 id Supplier unknown : ? +TOKEN @8:27 +TOKEN @8:35 +CLASS @10:1 class .CastContexts [t package] : CastContexts super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] members [, , Holder, LIMIT, arguments, assigned, masked, overloaded, overloaded, returned, returnedParenthesized, run, take, target, varargs] lookupToString 0 outermost CastContexts annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring CastContexts +MODIFIERS +TOKEN @10:1 +IDENTIFIER @10:7 id CastContexts .CastContexts [t package] : CastContexts : CastContexts +TOKEN @10:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @10:20 +VARIABLE @12:3 var CastContexts.LIMIT [v static final package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [static, final, package] local false parameter false effectivelyFinal true constant null +MODIFIERS @12:3 +TOKEN @12:3 +TOKEN @12:10 +PRIMITIVE_TYPE @12:16 : int +TOKEN @12:16 +IDENTIFIER @12:20 id LIMIT CastContexts.LIMIT [v static final package] : int : int +TOKEN @12:20 +TOKEN @12:25 +VARIABLE @13:3 var CastContexts.target [v package] : java.lang.Object + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @13:3 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @13:3 +IDENTIFIER @13:10 id target CastContexts.target [v package] : java.lang.Object : java.lang.Object +TOKEN @13:10 +TOKEN @13:16 +STATIC_INITIALIZER @15:3 +TOKEN @15:3 +TOKEN @15:10 +VARIABLE @16:5 var (initializer block).seed [v package] : int + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner (initializer block) CastContexts. (initializer block) [static] returns ? parameters 0 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsefalsefalse0falsefalse +MODIFIERS +PRIMITIVE_TYPE @16:5 : int +TOKEN @16:5 +IDENTIFIER @16:9 id seed (initializer block).seed [v package] : int : int +TOKEN @16:9 +TOKEN @16:14 +INT_LITERAL @16:16 : int = 3 +TOKEN @16:16 +TOKEN @16:17 +EXPRESSION_STATEMENT @17:5 +ASSIGNMENT @17:5 : int +IDENTIFIER @17:5 id LIMIT CastContexts.LIMIT [v static final package] : int : int +TOKEN @17:5 +TOKEN @17:11 +MULTIPLY @17:13 : int +IDENTIFIER @17:13 id seed (initializer block).seed [v package] : int : int +TOKEN @17:13 +TOKEN @17:18 +INT_LITERAL @17:20 : int = 2 +TOKEN @17:20 +TOKEN @17:21 +TOKEN @18:3 +INITIALIZER @20:3 +TOKEN @20:3 +VARIABLE @21:5 var (initializer block).label [v package] : java.lang.String + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner (initializer block) CastContexts. (initializer block) [] returns ? parameters 0 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsefalsefalse0falsefalse +MODIFIERS +IDENTIFIER @21:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @21:5 +IDENTIFIER @21:12 id label (initializer block).label [v package] : java.lang.String : java.lang.String +TOKEN @21:12 +TOKEN @21:18 +STRING_LITERAL @21:20 : java.lang.String = x +TOKEN @21:20 +TOKEN @21:23 +EXPRESSION_STATEMENT @22:5 +ASSIGNMENT @22:5 : java.lang.Object +IDENTIFIER @22:5 id target CastContexts.target [v package] : java.lang.Object : java.lang.Object +TOKEN @22:5 +TOKEN @22:12 +IDENTIFIER @22:14 id label (initializer block).label [v package] : java.lang.String : java.lang.String +TOKEN @22:14 +TOKEN @22:19 +TOKEN @23:3 +METHOD @25:3 method CastContexts.returned [m package] : ? (java.lang.String) returns java.lang.Object throws [] sig CastContexts#returned(Ljava/lang/String;)Ljava/lang/Object; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [s] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @25:3 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @25:3 +IDENTIFIER @25:10 id returned CastContexts.returned [m package] : ? (java.lang.String) returns java.lang.Object throws [] sig CastContexts#returned(Ljava/lang/String;)Ljava/lang/Object; : java.lang.Object +TOKEN @25:10 +TOKEN @25:18 +VARIABLE @25:19 var returned.s [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner returned CastContexts#returned(Ljava/lang/String;)Ljava/lang/Object; [package] returns java.lang.Object parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @25:19 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @25:19 +IDENTIFIER @25:26 id s returned.s [v package] : java.lang.String : java.lang.String +TOKEN @25:26 +TOKEN @25:27 +BLOCK @25:29 +TOKEN @25:29 +RETURN_STATEMENT @26:5 +TOKEN @26:5 +TYPE_CAST @26:12 : java.lang.Object +TOKEN @26:12 +IDENTIFIER @26:13 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @26:13 +LIST +TOKEN @26:19 +IDENTIFIER @26:21 id s returned.s [v package] : java.lang.String : java.lang.String +TOKEN @26:21 +TOKEN @26:22 +TOKEN @27:3 +METHOD @29:3 method CastContexts.returnedParenthesized [m package] : ? (java.lang.String) returns java.lang.Object throws [] sig CastContexts#returnedParenthesized(Ljava/lang/String;)Ljava/lang/Object; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [s] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @29:3 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @29:3 +IDENTIFIER @29:10 id returnedParenthesized CastContexts.returnedParenthesized [m package] : ? (java.lang.String) returns java.lang.Object throws [] sig CastContexts#returnedParenthesized(Ljava/lang/String;)Ljava/lang/Object; : java.lang.Object +TOKEN @29:10 +TOKEN @29:31 +VARIABLE @29:32 var returnedParenthesized.s [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner returnedParenthesized CastContexts#returnedParenthesized(Ljava/lang/String;)Ljava/lang/Object; [package] returns java.lang.Object parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @29:32 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @29:32 +IDENTIFIER @29:39 id s returnedParenthesized.s [v package] : java.lang.String : java.lang.String +TOKEN @29:39 +TOKEN @29:40 +BLOCK @29:42 +TOKEN @29:42 +RETURN_STATEMENT @30:5 +TOKEN @30:5 +PARENTHESIZED_EXPRESSION @30:12 : java.lang.Object +TOKEN @30:12 +TYPE_CAST @30:13 : java.lang.Object +TOKEN @30:13 +IDENTIFIER @30:14 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @30:14 +LIST +TOKEN @30:20 +IDENTIFIER @30:22 id s returnedParenthesized.s [v package] : java.lang.String : java.lang.String +TOKEN @30:22 +TOKEN @30:23 +TOKEN @30:24 +TOKEN @31:3 +METHOD @33:3 method CastContexts.assigned [m package] : ? (java.lang.String,char,byte,short,int,long) returns void throws [] sig CastContexts#assigned(Ljava/lang/String;CBSIJ)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [s, c, b, sh, i, l] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @33:3 : void +TOKEN @33:3 +IDENTIFIER @33:8 id assigned CastContexts.assigned [m package] : ? (java.lang.String,char,byte,short,int,long) returns void throws [] sig CastContexts#assigned(Ljava/lang/String;CBSIJ)V : void +TOKEN @33:8 +TOKEN @33:16 +VARIABLE @33:17 var assigned.s [v package] : java.lang.String + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +IDENTIFIER @33:17 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @33:17 +IDENTIFIER @33:24 id s assigned.s [v package] : java.lang.String : java.lang.String +TOKEN @33:24 +TOKEN @33:25 +VARIABLE @33:27 var assigned.c [v package] : char + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +PRIMITIVE_TYPE @33:27 : char +TOKEN @33:27 +IDENTIFIER @33:32 id c assigned.c [v package] : char : char +TOKEN @33:32 +TOKEN @33:33 +VARIABLE @33:35 var assigned.b [v package] : byte + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +PRIMITIVE_TYPE @33:35 : byte +TOKEN @33:35 +IDENTIFIER @33:40 id b assigned.b [v package] : byte : byte +TOKEN @33:40 +TOKEN @33:41 +VARIABLE @33:43 var assigned.sh [v package] : short + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +PRIMITIVE_TYPE @33:43 : short +TOKEN @33:43 +IDENTIFIER @33:49 id sh assigned.sh [v package] : short : short +TOKEN @33:49 +TOKEN @33:51 +VARIABLE @33:53 var assigned.i [v package] : int + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +PRIMITIVE_TYPE @33:53 : int +TOKEN @33:53 +IDENTIFIER @33:57 id i assigned.i [v package] : int : int +TOKEN @33:57 +TOKEN @33:58 +VARIABLE @33:60 var assigned.l [v package] : long + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +PRIMITIVE_TYPE @33:60 : long +TOKEN @33:60 +IDENTIFIER @33:65 id l assigned.l [v package] : long : long +TOKEN @33:65 +TOKEN @33:66 +BLOCK @33:68 +TOKEN @33:68 +EXPRESSION_STATEMENT @34:5 +ASSIGNMENT @34:5 : java.lang.Object +IDENTIFIER @34:5 id target CastContexts.target [v package] : java.lang.Object : java.lang.Object +TOKEN @34:5 +TOKEN @34:12 +TYPE_CAST @34:14 : java.lang.Object +TOKEN @34:14 +IDENTIFIER @34:15 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @34:15 +LIST +TOKEN @34:21 +IDENTIFIER @34:23 id s assigned.s [v package] : java.lang.String : java.lang.String +TOKEN @34:23 +TOKEN @34:24 +EXPRESSION_STATEMENT @35:5 +ASSIGNMENT @35:5 : java.lang.Object +IDENTIFIER @35:5 id target CastContexts.target [v package] : java.lang.Object : java.lang.Object +TOKEN @35:5 +TOKEN @35:12 +PARENTHESIZED_EXPRESSION @35:14 : java.lang.Object +TOKEN @35:14 +TYPE_CAST @35:15 : java.lang.Object +TOKEN @35:15 +IDENTIFIER @35:16 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @35:16 +LIST +TOKEN @35:22 +IDENTIFIER @35:24 id s assigned.s [v package] : java.lang.String : java.lang.String +TOKEN @35:24 +TOKEN @35:25 +TOKEN @35:26 +VARIABLE @36:5 var assigned.fromChar [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +PRIMITIVE_TYPE @36:5 : int +TOKEN @36:5 +IDENTIFIER @36:9 id fromChar assigned.fromChar [v package] : int : int +TOKEN @36:9 +TOKEN @36:18 +TYPE_CAST @36:20 : int +TOKEN @36:20 +PRIMITIVE_TYPE @36:21 : int +TOKEN @36:21 +LIST +TOKEN @36:24 +IDENTIFIER @36:26 id c assigned.c [v package] : char : char +TOKEN @36:26 +TOKEN @36:27 +VARIABLE @37:5 var assigned.toChar [v package] : char + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +PRIMITIVE_TYPE @37:5 : char +TOKEN @37:5 +IDENTIFIER @37:10 id toChar assigned.toChar [v package] : char : char +TOKEN @37:10 +TOKEN @37:17 +TYPE_CAST @37:19 : char +TOKEN @37:19 +PRIMITIVE_TYPE @37:20 : char +TOKEN @37:20 +LIST +TOKEN @37:24 +IDENTIFIER @37:26 id i assigned.i [v package] : int : int +TOKEN @37:26 +TOKEN @37:27 +VARIABLE @38:5 var assigned.shifted [v package] : long + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +PRIMITIVE_TYPE @38:5 : long +TOKEN @38:5 +IDENTIFIER @38:10 id shifted assigned.shifted [v package] : long : long +TOKEN @38:10 +TOKEN @38:18 +LEFT_SHIFT @38:20 : long +TYPE_CAST @38:20 : long +TOKEN @38:20 +PRIMITIVE_TYPE @38:21 : long +TOKEN @38:21 +LIST +TOKEN @38:25 +IDENTIFIER @38:27 id i assigned.i [v package] : int : int +TOKEN @38:27 +TOKEN @38:29 +INT_LITERAL @38:32 : int = 2 +TOKEN @38:32 +TOKEN @38:33 +VARIABLE @39:5 var assigned.shiftedInt [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +PRIMITIVE_TYPE @39:5 : int +TOKEN @39:5 +IDENTIFIER @39:9 id shiftedInt assigned.shiftedInt [v package] : int : int +TOKEN @39:9 +TOKEN @39:20 +LEFT_SHIFT @39:22 : int +TYPE_CAST @39:22 : int +TOKEN @39:22 +PRIMITIVE_TYPE @39:23 : int +TOKEN @39:23 +LIST +TOKEN @39:26 +IDENTIFIER @39:28 id b assigned.b [v package] : byte : byte +TOKEN @39:28 +TOKEN @39:30 +IDENTIFIER @39:33 id sh assigned.sh [v package] : short : short +TOKEN @39:33 +TOKEN @39:35 +VARIABLE @40:5 var assigned.sum [v package] : long + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +PRIMITIVE_TYPE @40:5 : long +TOKEN @40:5 +IDENTIFIER @40:10 id sum assigned.sum [v package] : long : long +TOKEN @40:10 +TOKEN @40:14 +PLUS @40:16 : long +TYPE_CAST @40:16 : long +TOKEN @40:16 +PRIMITIVE_TYPE @40:17 : long +TOKEN @40:17 +LIST +TOKEN @40:21 +IDENTIFIER @40:23 id i assigned.i [v package] : int : int +TOKEN @40:23 +TOKEN @40:25 +IDENTIFIER @40:27 id l assigned.l [v package] : long : long +TOKEN @40:27 +TOKEN @40:28 +VARIABLE @41:5 var assigned.bytes [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +PRIMITIVE_TYPE @41:5 : int +TOKEN @41:5 +IDENTIFIER @41:9 id bytes assigned.bytes [v package] : int : int +TOKEN @41:9 +TOKEN @41:15 +PLUS @41:17 : int +TYPE_CAST @41:17 : int +TOKEN @41:17 +PRIMITIVE_TYPE @41:18 : int +TOKEN @41:18 +LIST +TOKEN @41:21 +IDENTIFIER @41:23 id b assigned.b [v package] : byte : byte +TOKEN @41:23 +TOKEN @41:25 +TYPE_CAST @41:27 : int +TOKEN @41:27 +PRIMITIVE_TYPE @41:28 : int +TOKEN @41:28 +LIST +TOKEN @41:31 +IDENTIFIER @41:33 id sh assigned.sh [v package] : short : short +TOKEN @41:33 +TOKEN @41:35 +VARIABLE @42:5 var assigned.fraction [v package] : double + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +PRIMITIVE_TYPE @42:5 : double +TOKEN @42:5 +IDENTIFIER @42:12 id fraction assigned.fraction [v package] : double : double +TOKEN @42:12 +TOKEN @42:21 +DIVIDE @42:23 : double +TYPE_CAST @42:23 : double +TOKEN @42:23 +PRIMITIVE_TYPE @42:24 : double +TOKEN @42:24 +LIST +TOKEN @42:30 +IDENTIFIER @42:32 id i assigned.i [v package] : int : int +TOKEN @42:32 +TOKEN @42:34 +IDENTIFIER @42:36 id l assigned.l [v package] : long : long +TOKEN @42:36 +TOKEN @42:37 +VARIABLE @43:5 var assigned.elements [v package] : java.lang.Object[] + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +ARRAY_TYPE @43:5 : java.lang.Object[] +IDENTIFIER @43:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @43:5 +TOKEN @43:11 +TOKEN @43:12 +IDENTIFIER @43:14 id elements assigned.elements [v package] : java.lang.Object[] : java.lang.Object[] +TOKEN @43:14 +TOKEN @43:23 +NEW_ARRAY @43:25 : java.lang.Object[] +TOKEN @43:25 +IDENTIFIER @43:29 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @43:29 +ARRAY_DIMENSION @43:35 +TOKEN @43:35 +INT_LITERAL @43:36 : int = 1 +TOKEN @43:36 +TOKEN @43:37 +LIST +TOKEN @43:38 +VARIABLE @44:5 var assigned.first [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +IDENTIFIER @44:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @44:5 +IDENTIFIER @44:12 id first assigned.first [v package] : java.lang.String : java.lang.String +TOKEN @44:12 +TOKEN @44:18 +ARRAY_ACCESS_EXPRESSION @44:20 : java.lang.String +PARENTHESIZED_EXPRESSION @44:20 : java.lang.String[] +TOKEN @44:20 +TYPE_CAST @44:21 : java.lang.String[] +TOKEN @44:21 +ARRAY_TYPE @44:22 : java.lang.String[] +IDENTIFIER @44:22 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @44:22 +TOKEN @44:28 +TOKEN @44:29 +LIST +TOKEN @44:30 +IDENTIFIER @44:32 id elements assigned.elements [v package] : java.lang.Object[] : java.lang.Object[] +TOKEN @44:32 +TOKEN @44:40 +ARRAY_DIMENSION @44:41 +TOKEN @44:41 +INT_LITERAL @44:42 : int = 0 +TOKEN @44:42 +TOKEN @44:43 +TOKEN @44:44 +VARIABLE @45:5 var assigned.direct [v package] : java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +IDENTIFIER @45:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @45:5 +IDENTIFIER @45:12 id direct assigned.direct [v package] : java.lang.Object : java.lang.Object +TOKEN @45:12 +TOKEN @45:19 +ARRAY_ACCESS_EXPRESSION @45:21 : java.lang.Object +PARENTHESIZED_EXPRESSION @45:21 : java.lang.Object[] +TOKEN @45:21 +TYPE_CAST @45:22 : java.lang.Object[] +TOKEN @45:22 +ARRAY_TYPE @45:23 : java.lang.Object[] +IDENTIFIER @45:23 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @45:23 +TOKEN @45:29 +TOKEN @45:30 +LIST +TOKEN @45:31 +IDENTIFIER @45:33 id elements assigned.elements [v package] : java.lang.Object[] : java.lang.Object[] +TOKEN @45:33 +TOKEN @45:41 +ARRAY_DIMENSION @45:42 +TOKEN @45:42 +INT_LITERAL @45:43 : int = 0 +TOKEN @45:43 +TOKEN @45:44 +TOKEN @45:45 +VARIABLE @46:5 var assigned.boxed [v package] : java.lang.Integer + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner assigned CastContexts#assigned(Ljava/lang/String;CBSIJ)V [package] returns void parameters 6 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse6falsefalse +MODIFIERS +IDENTIFIER @46:5 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @46:5 +IDENTIFIER @46:13 id boxed assigned.boxed [v package] : java.lang.Integer : java.lang.Integer +TOKEN @46:13 +TOKEN @46:19 +TYPE_CAST @46:21 : int +TOKEN @46:21 +PRIMITIVE_TYPE @46:22 : int +TOKEN @46:22 +LIST +TOKEN @46:25 +IDENTIFIER @46:27 id b assigned.b [v package] : byte : byte +TOKEN @46:27 +TOKEN @46:28 +TOKEN @47:3 +METHOD @49:3 method CastContexts.arguments [m package] : ? (java.lang.String,java.util.List) returns void throws [] sig CastContexts#arguments(Ljava/lang/String;Ljava/util/List;)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [s, list] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @49:3 : void +TOKEN @49:3 +IDENTIFIER @49:8 id arguments CastContexts.arguments [m package] : ? (java.lang.String,java.util.List) returns void throws [] sig CastContexts#arguments(Ljava/lang/String;Ljava/util/List;)V : void +TOKEN @49:8 +TOKEN @49:17 +VARIABLE @49:18 var arguments.s [v package] : java.lang.String + details declared true usages 7 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner arguments CastContexts#arguments(Ljava/lang/String;Ljava/util/List;)V [package] returns void parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @49:18 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @49:18 +IDENTIFIER @49:25 id s arguments.s [v package] : java.lang.String : java.lang.String +TOKEN @49:25 +TOKEN @49:26 +VARIABLE @49:28 var arguments.list [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner arguments CastContexts#arguments(Ljava/lang/String;Ljava/util/List;)V [package] returns void parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PARAMETERIZED_TYPE @49:28 : java.util.List +IDENTIFIER @49:28 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @49:28 +TYPE_ARGUMENTS @49:32 +TOKEN @49:32 +IDENTIFIER @49:33 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @49:33 +TOKEN @49:39 +IDENTIFIER @49:41 id list arguments.list [v package] : java.util.List : java.util.List +TOKEN @49:41 +TOKEN @49:45 +BLOCK @49:47 +TOKEN @49:47 +EXPRESSION_STATEMENT @50:5 +METHOD_INVOCATION @50:5 call List.add [m abstract public] : ? (java.lang.Object) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.add[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @50:5 : ? +IDENTIFIER @50:5 id list arguments.list [v package] : java.util.List : java.util.List +TOKEN @50:5 +TOKEN @50:9 +IDENTIFIER @50:10 id add List.add [m abstract public] : ? (java.lang.Object) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean +TOKEN @50:10 +ARGUMENTS @50:13 +TOKEN @50:13 +TYPE_CAST @50:14 : java.lang.Object +TOKEN @50:14 +IDENTIFIER @50:15 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @50:15 +LIST +TOKEN @50:21 +IDENTIFIER @50:23 id s arguments.s [v package] : java.lang.String : java.lang.String +TOKEN @50:23 +TOKEN @50:24 +TOKEN @50:25 +EXPRESSION_STATEMENT @51:5 +METHOD_INVOCATION @51:5 call CastContexts.take [m package] : ? (java.lang.Object) returns void throws [] sig CastContexts#take(Ljava/lang/Object;)V : void + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [o] parameterMetadata [] +IDENTIFIER @51:5 id take CastContexts.take [m package] : ? (java.lang.Object) returns void throws [] sig CastContexts#take(Ljava/lang/Object;)V : void +TOKEN @51:5 +ARGUMENTS @51:9 +TOKEN @51:9 +TYPE_CAST @51:10 : java.lang.Object +TOKEN @51:10 +IDENTIFIER @51:11 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @51:11 +LIST +TOKEN @51:17 +IDENTIFIER @51:19 id s arguments.s [v package] : java.lang.String : java.lang.String +TOKEN @51:19 +TOKEN @51:20 +TOKEN @51:21 +EXPRESSION_STATEMENT @52:5 +METHOD_INVOCATION @52:5 call CastContexts.overloaded [m package] : ? (java.lang.Object) returns void throws [] sig CastContexts#overloaded(Ljava/lang/Object;)V : void + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [o] parameterMetadata [] +IDENTIFIER @52:5 id overloaded CastContexts.overloaded [m package] : ? (java.lang.Object) returns void throws [] sig CastContexts#overloaded(Ljava/lang/Object;)V : void +TOKEN @52:5 +ARGUMENTS @52:15 +TOKEN @52:15 +TYPE_CAST @52:16 : java.lang.Object +TOKEN @52:16 +IDENTIFIER @52:17 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @52:17 +LIST +TOKEN @52:23 +IDENTIFIER @52:25 id s arguments.s [v package] : java.lang.String : java.lang.String +TOKEN @52:25 +TOKEN @52:26 +TOKEN @52:27 +EXPRESSION_STATEMENT @53:5 +METHOD_INVOCATION @53:5 call CastContexts.varargs [m package] : ? (java.lang.Object[]) returns void throws [] sig CastContexts#varargs([Ljava/lang/Object;)V : void + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs true native false parameters [values] parameterMetadata [] +IDENTIFIER @53:5 id varargs CastContexts.varargs [m package] : ? (java.lang.Object[]) returns void throws [] sig CastContexts#varargs([Ljava/lang/Object;)V : void +TOKEN @53:5 +ARGUMENTS @53:12 +TOKEN @53:12 +TYPE_CAST @53:13 : java.lang.Object +TOKEN @53:13 +IDENTIFIER @53:14 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @53:14 +LIST +TOKEN @53:20 +IDENTIFIER @53:22 id s arguments.s [v package] : java.lang.String : java.lang.String +TOKEN @53:22 +TOKEN @53:23 +TOKEN @53:24 +EXPRESSION_STATEMENT @54:5 +NEW_CLASS @54:5 new Holder. [m package] : ? (java.lang.Object) returns void throws [] sig CastContexts$Holder#(Ljava/lang/Object;)V : CastContexts$Holder + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Holder flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [o] parameterMetadata [] +TOKEN @54:5 +IDENTIFIER @54:9 id Holder Holder. [m package] : ? (java.lang.Object) returns void throws [] sig CastContexts$Holder#(Ljava/lang/Object;)V : CastContexts$Holder +TOKEN @54:9 +ARGUMENTS @54:15 +TOKEN @54:15 +TYPE_CAST @54:16 : java.lang.Object +TOKEN @54:16 +IDENTIFIER @54:17 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @54:17 +LIST +TOKEN @54:23 +IDENTIFIER @54:25 id s arguments.s [v package] : java.lang.String : java.lang.String +TOKEN @54:25 +TOKEN @54:26 +TOKEN @54:27 +VARIABLE @55:5 var arguments.supplier [v package] : java.util.function.Supplier + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner arguments CastContexts#arguments(Ljava/lang/String;Ljava/util/List;)V [package] returns void parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PARAMETERIZED_TYPE @55:5 : java.util.function.Supplier +IDENTIFIER @55:5 id Supplier java.util.function.Supplier [t public interface] : java.util.function.Supplier @java.lang.FunctionalInterface : java.util.function.Supplier +TOKEN @55:5 +TYPE_ARGUMENTS @55:13 +TOKEN @55:13 +IDENTIFIER @55:14 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @55:14 +TOKEN @55:20 +IDENTIFIER @55:22 id supplier arguments.supplier [v package] : java.util.function.Supplier : java.util.function.Supplier +TOKEN @55:22 +TOKEN @55:31 +LAMBDA_EXPRESSION @55:33 : java.util.function.Supplier +TOKEN @55:33 +TOKEN @55:34 +TOKEN @55:36 +TYPE_CAST @55:39 : java.lang.Object +TOKEN @55:39 +IDENTIFIER @55:40 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @55:40 +LIST +TOKEN @55:46 +IDENTIFIER @55:48 id s arguments.s [v package] : java.lang.String : java.lang.String +TOKEN @55:48 +TOKEN @55:49 +VARIABLE @56:5 var arguments.function [v package] : java.util.function.Function + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner arguments CastContexts#arguments(Ljava/lang/String;Ljava/util/List;)V [package] returns void parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PARAMETERIZED_TYPE @56:5 : java.util.function.Function +IDENTIFIER @56:5 id Function java.util.function.Function [t public interface] : java.util.function.Function @java.lang.FunctionalInterface : java.util.function.Function +TOKEN @56:5 +TYPE_ARGUMENTS @56:13 +TOKEN @56:13 +IDENTIFIER @56:14 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @56:14 +TOKEN @56:20 +IDENTIFIER @56:22 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @56:22 +TOKEN @56:28 +IDENTIFIER @56:30 id function arguments.function [v package] : java.util.function.Function : java.util.function.Function +TOKEN @56:30 +TOKEN @56:39 +LAMBDA_EXPRESSION @56:41 : java.util.function.Function +VARIABLE @56:41 var apply.value [v package] : java.lang.String + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Function flags [package] local true parameter true effectivelyFinal true constant null owner apply java.util.function.Function#apply(Ljava/lang/Object;)Ljava/lang/Object; [abstract, public] returns java.lang.Object parameters 1 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing Function type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @56:41 id value apply.value [v package] : java.lang.String : java.lang.String +TOKEN @56:41 +TOKEN @56:47 +BLOCK @56:50 +TOKEN @56:50 +RETURN_STATEMENT @57:7 +TOKEN @57:7 +TYPE_CAST @57:14 : java.lang.Object +TOKEN @57:14 +IDENTIFIER @57:15 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @57:15 +LIST +TOKEN @57:21 +IDENTIFIER @57:23 id value apply.value [v package] : java.lang.String : java.lang.String +TOKEN @57:23 +TOKEN @57:28 +TOKEN @58:5 +TOKEN @58:6 +EXPRESSION_STATEMENT @59:5 +METHOD_INVOCATION @59:5 call CastContexts.run [m package] : ? (java.util.function.Supplier) returns void throws [] sig CastContexts#run(Ljava/util/function/Supplier;)V : void + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [supplier] parameterMetadata [] +IDENTIFIER @59:5 id run CastContexts.run [m package] : ? (java.util.function.Supplier) returns void throws [] sig CastContexts#run(Ljava/util/function/Supplier;)V : void +TOKEN @59:5 +ARGUMENTS @59:8 +TOKEN @59:8 +LAMBDA_EXPRESSION @59:9 : java.util.function.Supplier +TOKEN @59:9 +TOKEN @59:10 +TOKEN @59:12 +TYPE_CAST @59:15 : java.lang.Object +TOKEN @59:15 +IDENTIFIER @59:16 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @59:16 +LIST +TOKEN @59:22 +IDENTIFIER @59:24 id s arguments.s [v package] : java.lang.String : java.lang.String +TOKEN @59:24 +TOKEN @59:25 +TOKEN @59:26 +TOKEN @60:3 +METHOD @62:3 method CastContexts.take [m package] : ? (java.lang.Object) returns void throws [] sig CastContexts#take(Ljava/lang/Object;)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [o] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @62:3 : void +TOKEN @62:3 +IDENTIFIER @62:8 id take CastContexts.take [m package] : ? (java.lang.Object) returns void throws [] sig CastContexts#take(Ljava/lang/Object;)V : void +TOKEN @62:8 +TOKEN @62:12 +VARIABLE @62:13 var take.o [v package] : java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner take CastContexts#take(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @62:13 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @62:13 +IDENTIFIER @62:20 id o take.o [v package] : java.lang.Object : java.lang.Object +TOKEN @62:20 +TOKEN @62:21 +BLOCK @62:23 +TOKEN @62:23 +TOKEN @63:3 +METHOD @65:3 method CastContexts.overloaded [m package] : ? (java.lang.Object) returns void throws [] sig CastContexts#overloaded(Ljava/lang/Object;)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [o] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @65:3 : void +TOKEN @65:3 +IDENTIFIER @65:8 id overloaded CastContexts.overloaded [m package] : ? (java.lang.Object) returns void throws [] sig CastContexts#overloaded(Ljava/lang/Object;)V : void +TOKEN @65:8 +TOKEN @65:18 +VARIABLE @65:19 var overloaded.o [v package] : java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner overloaded CastContexts#overloaded(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @65:19 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @65:19 +IDENTIFIER @65:26 id o overloaded.o [v package] : java.lang.Object : java.lang.Object +TOKEN @65:26 +TOKEN @65:27 +BLOCK @65:29 +TOKEN @65:29 +TOKEN @66:3 +METHOD @68:3 method CastContexts.overloaded [m package] : ? (java.lang.String) returns void throws [] sig CastContexts#overloaded(Ljava/lang/String;)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [s] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @68:3 : void +TOKEN @68:3 +IDENTIFIER @68:8 id overloaded CastContexts.overloaded [m package] : ? (java.lang.String) returns void throws [] sig CastContexts#overloaded(Ljava/lang/String;)V : void +TOKEN @68:8 +TOKEN @68:18 +VARIABLE @68:19 var overloaded.s [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner overloaded CastContexts#overloaded(Ljava/lang/String;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @68:19 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @68:19 +IDENTIFIER @68:26 id s overloaded.s [v package] : java.lang.String : java.lang.String +TOKEN @68:26 +TOKEN @68:27 +BLOCK @68:29 +TOKEN @68:29 +TOKEN @69:3 +METHOD @71:3 method CastContexts.varargs [m package] : ? (java.lang.Object[]) returns void throws [] sig CastContexts#varargs([Ljava/lang/Object;)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs true native false parameters [values] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @71:3 : void +TOKEN @71:3 +IDENTIFIER @71:8 id varargs CastContexts.varargs [m package] : ? (java.lang.Object[]) returns void throws [] sig CastContexts#varargs([Ljava/lang/Object;)V : void +TOKEN @71:8 +TOKEN @71:15 +VARIABLE @71:16 var varargs.values [v package] : java.lang.Object[] + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner varargs CastContexts#varargs([Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsetruefalsetruefalse1falsefalse +MODIFIERS +ARRAY_TYPE @71:16 : java.lang.Object[] +IDENTIFIER @71:16 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @71:16 +TOKEN @71:22 +IDENTIFIER @71:26 id values varargs.values [v package] : java.lang.Object[] : java.lang.Object[] +TOKEN @71:26 +TOKEN @71:32 +BLOCK @71:34 +TOKEN @71:34 +TOKEN @72:3 +METHOD @74:3 method CastContexts.run [m package] : ? (java.util.function.Supplier) returns void throws [] sig CastContexts#run(Ljava/util/function/Supplier;)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [supplier] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @74:3 : void +TOKEN @74:3 +IDENTIFIER @74:8 id run CastContexts.run [m package] : ? (java.util.function.Supplier) returns void throws [] sig CastContexts#run(Ljava/util/function/Supplier;)V : void +TOKEN @74:8 +TOKEN @74:11 +VARIABLE @74:12 var run.supplier [v package] : java.util.function.Supplier + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing CastContexts flags [package] local true parameter true effectivelyFinal true constant null owner run CastContexts#run(Ljava/util/function/Supplier;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @74:12 : java.util.function.Supplier +IDENTIFIER @74:12 id Supplier java.util.function.Supplier [t public interface] : java.util.function.Supplier @java.lang.FunctionalInterface : java.util.function.Supplier +TOKEN @74:12 +TYPE_ARGUMENTS @74:20 +TOKEN @74:20 +IDENTIFIER @74:21 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @74:21 +TOKEN @74:27 +IDENTIFIER @74:29 id supplier run.supplier [v package] : java.util.function.Supplier : java.util.function.Supplier +TOKEN @74:29 +TOKEN @74:37 +BLOCK @74:39 +TOKEN @74:39 +TOKEN @75:3 +CLASS @77:3 class CastContexts.Holder [t static package] : CastContexts$Holder super java.lang.Object interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [static, package] members [] lookupToString 0 outermost CastContexts annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Holder +MODIFIERS @77:3 +TOKEN @77:3 +TOKEN @77:10 +IDENTIFIER @77:16 id Holder CastContexts.Holder [t static package] : CastContexts$Holder : CastContexts$Holder +TOKEN @77:16 +TYPE_PARAMETERS +LIST +LIST +TOKEN @77:23 +CONSTRUCTOR @78:5 method Holder. [m package] : ? (java.lang.Object) returns void throws [] sig CastContexts$Holder#(Ljava/lang/Object;)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Holder flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [o] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @78:5 id Holder Holder. [m package] : ? (java.lang.Object) returns void throws [] sig CastContexts$Holder#(Ljava/lang/Object;)V : void +TOKEN @78:5 +TOKEN @78:11 +VARIABLE @78:12 var .o [v package] : java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Holder flags [package] local true parameter true effectivelyFinal true constant null owner CastContexts$Holder#(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Holder type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @78:12 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @78:12 +IDENTIFIER @78:19 id o .o [v package] : java.lang.Object : java.lang.Object +TOKEN @78:19 +TOKEN @78:20 +BLOCK @78:22 +TOKEN @78:22 +TOKEN @79:5 +TOKEN @80:3 +METHOD @82:3 method CastContexts.masked [m package] : ? () returns void throws [java.io.IOException] sig CastContexts#masked()V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @82:3 : void +TOKEN @82:3 +IDENTIFIER @82:8 id masked CastContexts.masked [m package] : ? () returns void throws [java.io.IOException] sig CastContexts#masked()V : void +TOKEN @82:8 +TOKEN @82:14 +TOKEN @82:15 +TOKEN @82:17 +LIST @82:24 +IDENTIFIER @82:24 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @82:24 +BLOCK @82:36 +TOKEN @82:36 +TRY_STATEMENT @83:5 +TOKEN @83:5 +BLOCK @83:9 +TOKEN @83:9 +THROW_STATEMENT @84:7 +TOKEN @84:7 +NEW_CLASS @84:13 new FileNotFoundException. [m public] : ? () returns void throws [] sig java.io.FileNotFoundException#()V : java.io.FileNotFoundException + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing FileNotFoundException flags [public] overridden [IOException.[], Exception.[], Throwable.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @84:13 +IDENTIFIER @84:17 id FileNotFoundException FileNotFoundException. [m public] : ? () returns void throws [] sig java.io.FileNotFoundException#()V : java.io.FileNotFoundException +TOKEN @84:17 +ARGUMENTS @84:38 +TOKEN @84:38 +TOKEN @84:39 +TOKEN @84:40 +TOKEN @85:5 +CATCH @85:7 +TOKEN @85:7 +TOKEN @85:13 +VARIABLE @85:14 var masked.e [v package] : java.io.FileNotFoundException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner masked CastContexts#masked()V [package] returns void parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @85:14 id FileNotFoundException java.io.FileNotFoundException [t public] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @85:14 +IDENTIFIER @85:36 id e masked.e [v package] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @85:36 +TOKEN @85:37 +BLOCK @85:39 +TOKEN @85:39 +EXPRESSION_STATEMENT @86:7 +METHOD_INVOCATION @86:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 8 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @86:7 : ? +IDENTIFIER @86:7 id e masked.e [v package] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @86:7 +TOKEN @86:8 +IDENTIFIER @86:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @86:9 +ARGUMENTS @86:24 +TOKEN @86:24 +TOKEN @86:25 +TOKEN @86:26 +TOKEN @87:5 +CATCH @87:7 +TOKEN @87:7 +TOKEN @87:13 +VARIABLE @87:14 var masked.e [v package] : java.io.IOException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner masked CastContexts#masked()V [package] returns void parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @87:14 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @87:14 +IDENTIFIER @87:26 id e masked.e [v package] : java.io.IOException : java.io.IOException +TOKEN @87:26 +TOKEN @87:27 +BLOCK @87:29 +TOKEN @87:29 +EXPRESSION_STATEMENT @88:7 +METHOD_INVOCATION @88:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 8 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @88:7 : ? +IDENTIFIER @88:7 id e masked.e [v package] : java.io.IOException : java.io.IOException +TOKEN @88:7 +TOKEN @88:8 +IDENTIFIER @88:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @88:9 +ARGUMENTS @88:24 +TOKEN @88:24 +TOKEN @88:25 +TOKEN @88:26 +TOKEN @89:5 +TRY_STATEMENT @90:5 +TOKEN @90:5 +TOKEN @90:9 +LIST @90:10 +VARIABLE @90:10 var masked.reader [v final package] : java.io.Reader + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [final, package] local true parameter false effectivelyFinal true constant null owner masked CastContexts#masked()V [package] returns void parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @90:10 id Reader java.io.Reader [t abstract public] : java.io.Reader : java.io.Reader +TOKEN @90:10 +IDENTIFIER @90:17 id reader masked.reader [v final package] : java.io.Reader : java.io.Reader +TOKEN @90:17 +TOKEN @90:24 +NEW_CLASS @90:26 new FileReader. [m public] : ? (java.lang.String) returns void throws [java.io.FileNotFoundException] sig java.io.FileReader#(Ljava/lang/String;)V : java.io.FileReader + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing FileReader flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @90:26 +IDENTIFIER @90:30 id FileReader FileReader. [m public] : ? (java.lang.String) returns void throws [java.io.FileNotFoundException] sig java.io.FileReader#(Ljava/lang/String;)V : java.io.FileReader +TOKEN @90:30 +ARGUMENTS @90:40 +TOKEN @90:40 +STRING_LITERAL @90:41 : java.lang.String = f +TOKEN @90:41 +TOKEN @90:44 +TOKEN @90:45 +BLOCK @90:47 +TOKEN @90:47 +EXPRESSION_STATEMENT @91:7 +METHOD_INVOCATION @91:7 call Reader.read [m public] : ? () returns int throws [java.io.IOException] sig java.io.Reader#read()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Reader flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @91:7 : ? +IDENTIFIER @91:7 id reader masked.reader [v final package] : java.io.Reader : java.io.Reader +TOKEN @91:7 +TOKEN @91:13 +IDENTIFIER @91:14 id read Reader.read [m public] : ? () returns int throws [java.io.IOException] sig java.io.Reader#read()I : int +TOKEN @91:14 +ARGUMENTS @91:18 +TOKEN @91:18 +TOKEN @91:19 +TOKEN @91:20 +TOKEN @92:5 +CATCH @92:7 +TOKEN @92:7 +TOKEN @92:13 +VARIABLE @92:14 var masked.e [v package] : java.io.FileNotFoundException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner masked CastContexts#masked()V [package] returns void parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @92:14 id FileNotFoundException java.io.FileNotFoundException [t public] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @92:14 +IDENTIFIER @92:36 id e masked.e [v package] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @92:36 +TOKEN @92:37 +BLOCK @92:39 +TOKEN @92:39 +EXPRESSION_STATEMENT @93:7 +METHOD_INVOCATION @93:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 8 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @93:7 : ? +IDENTIFIER @93:7 id e masked.e [v package] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @93:7 +TOKEN @93:8 +IDENTIFIER @93:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @93:9 +ARGUMENTS @93:24 +TOKEN @93:24 +TOKEN @93:25 +TOKEN @93:26 +TOKEN @94:5 +CATCH @94:7 +TOKEN @94:7 +TOKEN @94:13 +VARIABLE @94:14 var masked.e [v package] : java.io.IOException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner masked CastContexts#masked()V [package] returns void parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @94:14 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @94:14 +IDENTIFIER @94:26 id e masked.e [v package] : java.io.IOException : java.io.IOException +TOKEN @94:26 +TOKEN @94:27 +BLOCK @94:29 +TOKEN @94:29 +EXPRESSION_STATEMENT @95:7 +METHOD_INVOCATION @95:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 8 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @95:7 : ? +IDENTIFIER @95:7 id e masked.e [v package] : java.io.IOException : java.io.IOException +TOKEN @95:7 +TOKEN @95:8 +IDENTIFIER @95:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @95:9 +ARGUMENTS @95:24 +TOKEN @95:24 +TOKEN @95:25 +TOKEN @95:26 +TOKEN @96:5 +TRY_STATEMENT @97:5 +TOKEN @97:5 +TOKEN @97:9 +LIST @97:10 +VARIABLE @97:10 var masked.closeable [v final package] : java.io.Closeable + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [final, package] local true parameter false effectivelyFinal true constant null owner masked CastContexts#masked()V [package] returns void parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @97:10 id Closeable java.io.Closeable [t public interface] : java.io.Closeable : java.io.Closeable +TOKEN @97:10 +IDENTIFIER @97:20 id closeable masked.closeable [v final package] : java.io.Closeable : java.io.Closeable +TOKEN @97:20 +TOKEN @97:30 +LAMBDA_EXPRESSION @97:32 : java.io.Closeable +TOKEN @97:32 +TOKEN @97:33 +TOKEN @97:35 +BLOCK @97:38 +TOKEN @97:38 +TOKEN @98:5 +TOKEN @98:6 +BLOCK @98:8 +TOKEN @98:8 +EXPRESSION_STATEMENT @99:7 +METHOD_INVOCATION @99:7 call Closeable.close [m abstract public] : ? () returns void throws [java.io.IOException] sig java.io.Closeable#close()V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Closeable flags [abstract, public] overridden [AutoCloseable.close[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @99:7 : ? +IDENTIFIER @99:7 id closeable masked.closeable [v final package] : java.io.Closeable : java.io.Closeable +TOKEN @99:7 +TOKEN @99:16 +IDENTIFIER @99:17 id close Closeable.close [m abstract public] : ? () returns void throws [java.io.IOException] sig java.io.Closeable#close()V : void +TOKEN @99:17 +ARGUMENTS @99:22 +TOKEN @99:22 +TOKEN @99:23 +TOKEN @99:24 +TOKEN @100:5 +CATCH @100:7 +TOKEN @100:7 +TOKEN @100:13 +VARIABLE @100:14 var masked.e [v package] : java.io.IOException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner masked CastContexts#masked()V [package] returns void parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @100:14 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @100:14 +IDENTIFIER @100:26 id e masked.e [v package] : java.io.IOException : java.io.IOException +TOKEN @100:26 +TOKEN @100:27 +BLOCK @100:29 +TOKEN @100:29 +EXPRESSION_STATEMENT @101:7 +METHOD_INVOCATION @101:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 8 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @101:7 : ? +IDENTIFIER @101:7 id e masked.e [v package] : java.io.IOException : java.io.IOException +TOKEN @101:7 +TOKEN @101:8 +IDENTIFIER @101:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @101:9 +ARGUMENTS @101:24 +TOKEN @101:24 +TOKEN @101:25 +TOKEN @101:26 +TOKEN @102:5 +TRY_STATEMENT @103:5 +TOKEN @103:5 +BLOCK @103:9 +TOKEN @103:9 +TRY_STATEMENT @104:7 +TOKEN @104:7 +BLOCK @104:11 +TOKEN @104:11 +THROW_STATEMENT @105:9 +TOKEN @105:9 +NEW_CLASS @105:15 new FileNotFoundException. [m public] : ? () returns void throws [] sig java.io.FileNotFoundException#()V : java.io.FileNotFoundException + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing FileNotFoundException flags [public] overridden [IOException.[], Exception.[], Throwable.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @105:15 +IDENTIFIER @105:19 id FileNotFoundException FileNotFoundException. [m public] : ? () returns void throws [] sig java.io.FileNotFoundException#()V : java.io.FileNotFoundException +TOKEN @105:19 +ARGUMENTS @105:40 +TOKEN @105:40 +TOKEN @105:41 +TOKEN @105:42 +TOKEN @106:7 +TOKEN @106:9 +BLOCK @106:17 +TOKEN @106:17 +EXPRESSION_STATEMENT @107:9 +ASSIGNMENT @107:9 : java.lang.Object +IDENTIFIER @107:9 id target CastContexts.target [v package] : java.lang.Object : java.lang.Object +TOKEN @107:9 +TOKEN @107:16 +NULL_LITERAL @107:18 : +TOKEN @107:18 +TOKEN @107:22 +TOKEN @108:7 +TOKEN @109:5 +CATCH @109:7 +TOKEN @109:7 +TOKEN @109:13 +VARIABLE @109:14 var masked.e [v final package] : java.lang.Exception + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [final, package] local true parameter false effectivelyFinal true constant null owner masked CastContexts#masked()V [package] returns void parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +UNION_TYPE @109:14 +LIST @109:14 +IDENTIFIER @109:14 id FileNotFoundException java.io.FileNotFoundException [t public] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @109:14 +TOKEN @109:36 +IDENTIFIER @109:38 id IllegalStateException java.lang.IllegalStateException [t public] : java.lang.IllegalStateException : java.lang.IllegalStateException +TOKEN @109:38 +IDENTIFIER @109:60 id e masked.e [v final package] : java.lang.Exception : java.lang.Exception +TOKEN @109:60 +TOKEN @109:61 +BLOCK @109:63 +TOKEN @109:63 +EXPRESSION_STATEMENT @110:7 +METHOD_INVOCATION @110:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 8 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @110:7 : ? +IDENTIFIER @110:7 id e masked.e [v final package] : java.lang.Exception : java.lang.Exception +TOKEN @110:7 +TOKEN @110:8 +IDENTIFIER @110:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @110:9 +ARGUMENTS @110:24 +TOKEN @110:24 +TOKEN @110:25 +TOKEN @110:26 +TOKEN @111:5 +CATCH @111:7 +TOKEN @111:7 +TOKEN @111:13 +VARIABLE @111:14 var masked.e [v package] : java.io.IOException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner masked CastContexts#masked()V [package] returns void parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @111:14 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @111:14 +IDENTIFIER @111:26 id e masked.e [v package] : java.io.IOException : java.io.IOException +TOKEN @111:26 +TOKEN @111:27 +BLOCK @111:29 +TOKEN @111:29 +EXPRESSION_STATEMENT @112:7 +METHOD_INVOCATION @112:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 8 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @112:7 : ? +IDENTIFIER @112:7 id e masked.e [v package] : java.io.IOException : java.io.IOException +TOKEN @112:7 +TOKEN @112:8 +IDENTIFIER @112:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @112:9 +ARGUMENTS @112:24 +TOKEN @112:24 +TOKEN @112:25 +TOKEN @112:26 +TOKEN @113:5 +VARIABLE @114:5 var masked.shared [v package] : java.io.Reader + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner masked CastContexts#masked()V [package] returns void parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @114:5 id Reader java.io.Reader [t abstract public] : java.io.Reader : java.io.Reader +TOKEN @114:5 +IDENTIFIER @114:12 id shared masked.shared [v package] : java.io.Reader : java.io.Reader +TOKEN @114:12 +TOKEN @114:19 +NEW_CLASS @114:21 new FileReader. [m public] : ? (java.lang.String) returns void throws [java.io.FileNotFoundException] sig java.io.FileReader#(Ljava/lang/String;)V : java.io.FileReader + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing FileReader flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @114:21 +IDENTIFIER @114:25 id FileReader FileReader. [m public] : ? (java.lang.String) returns void throws [java.io.FileNotFoundException] sig java.io.FileReader#(Ljava/lang/String;)V : java.io.FileReader +TOKEN @114:25 +ARGUMENTS @114:35 +TOKEN @114:35 +STRING_LITERAL @114:36 : java.lang.String = g +TOKEN @114:36 +TOKEN @114:39 +TOKEN @114:40 +TRY_STATEMENT @115:5 +TOKEN @115:5 +TOKEN @115:9 +LIST @115:10 +IDENTIFIER @115:10 id shared masked.shared [v package] : java.io.Reader : java.io.Reader +TOKEN @115:10 +TOKEN @115:16 +BLOCK @115:18 +TOKEN @115:18 +EXPRESSION_STATEMENT @116:7 +METHOD_INVOCATION @116:7 call Reader.read [m public] : ? () returns int throws [java.io.IOException] sig java.io.Reader#read()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Reader flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @116:7 : ? +IDENTIFIER @116:7 id shared masked.shared [v package] : java.io.Reader : java.io.Reader +TOKEN @116:7 +TOKEN @116:13 +IDENTIFIER @116:14 id read Reader.read [m public] : ? () returns int throws [java.io.IOException] sig java.io.Reader#read()I : int +TOKEN @116:14 +ARGUMENTS @116:18 +TOKEN @116:18 +TOKEN @116:19 +TOKEN @116:20 +TOKEN @117:5 +TRY_STATEMENT @118:5 +TOKEN @118:5 +BLOCK @118:9 +TOKEN @118:9 +SYNCHRONIZED_STATEMENT @119:7 +TOKEN @119:7 +TOKEN @119:20 +IDENTIFIER @119:21 id this CastContexts.this [v final] : CastContexts : CastContexts +TOKEN @119:21 +TOKEN @119:25 +BLOCK @119:27 +TOKEN @119:27 +THROW_STATEMENT @120:9 +TOKEN @120:9 +NEW_CLASS @120:15 new FileNotFoundException. [m public] : ? () returns void throws [] sig java.io.FileNotFoundException#()V : java.io.FileNotFoundException + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing FileNotFoundException flags [public] overridden [IOException.[], Exception.[], Throwable.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @120:15 +IDENTIFIER @120:19 id FileNotFoundException FileNotFoundException. [m public] : ? () returns void throws [] sig java.io.FileNotFoundException#()V : java.io.FileNotFoundException +TOKEN @120:19 +ARGUMENTS @120:40 +TOKEN @120:40 +TOKEN @120:41 +TOKEN @120:42 +TOKEN @121:7 +TOKEN @122:5 +CATCH @122:7 +TOKEN @122:7 +TOKEN @122:13 +VARIABLE @122:14 var masked.e [v package] : java.io.FileNotFoundException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner masked CastContexts#masked()V [package] returns void parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @122:14 id FileNotFoundException java.io.FileNotFoundException [t public] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @122:14 +IDENTIFIER @122:36 id e masked.e [v package] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @122:36 +TOKEN @122:37 +BLOCK @122:39 +TOKEN @122:39 +THROW_STATEMENT @123:7 +TOKEN @123:7 +IDENTIFIER @123:13 id e masked.e [v package] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @123:13 +TOKEN @123:14 +TOKEN @124:5 +CATCH @124:7 +TOKEN @124:7 +TOKEN @124:13 +VARIABLE @124:14 var masked.e [v package] : java.io.IOException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing CastContexts flags [package] local true parameter false effectivelyFinal true constant null owner masked CastContexts#masked()V [package] returns void parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing CastContexts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @124:14 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @124:14 +IDENTIFIER @124:26 id e masked.e [v package] : java.io.IOException : java.io.IOException +TOKEN @124:26 +TOKEN @124:27 +BLOCK @124:29 +TOKEN @124:29 +EXPRESSION_STATEMENT @125:7 +METHOD_INVOCATION @125:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 8 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @125:7 : ? +IDENTIFIER @125:7 id e masked.e [v package] : java.io.IOException : java.io.IOException +TOKEN @125:7 +TOKEN @125:8 +IDENTIFIER @125:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @125:9 +ARGUMENTS @125:24 +TOKEN @125:24 +TOKEN @125:25 +TOKEN @125:26 +TOKEN @126:5 +TOKEN @127:3 +TOKEN @128:1 +TOKEN @129:1 +WARNING REDUNDANT_CAST TYPE_CAST @26:12 Unnecessary cast from String to Object +WARNING REDUNDANT_CAST TYPE_CAST @30:13 Unnecessary cast from String to Object +WARNING REDUNDANT_CAST TYPE_CAST @34:14 Unnecessary cast from String to Object +WARNING REDUNDANT_CAST TYPE_CAST @35:15 Unnecessary cast from String to Object +WARNING REDUNDANT_CAST TYPE_CAST @36:20 Unnecessary cast from char to int +WARNING REDUNDANT_CAST TYPE_CAST @39:22 Unnecessary cast from byte to int +WARNING REDUNDANT_CAST TYPE_CAST @40:16 Unnecessary cast from int to long +WARNING REDUNDANT_CAST TYPE_CAST @41:17 Unnecessary cast from byte to int +WARNING REDUNDANT_CAST TYPE_CAST @41:27 Unnecessary cast from short to int +WARNING REDUNDANT_CAST TYPE_CAST @45:22 Unnecessary cast from Object[] to Object[] +WARNING REDUNDANT_CAST TYPE_CAST @50:14 Unnecessary cast from String to Object +WARNING REDUNDANT_CAST TYPE_CAST @51:10 Unnecessary cast from String to Object +WARNING REDUNDANT_CAST TYPE_CAST @54:16 Unnecessary cast from String to Object +WARNING REDUNDANT_CAST TYPE_CAST @55:39 Unnecessary cast from String to Object +WARNING REDUNDANT_CAST TYPE_CAST @59:15 Unnecessary cast from String to Object +WARNING MASKED_CATCH IDENTIFIER @87:14 Unreachable catch block for IOException. Only more specific exceptions are thrown and they are handled by previous catch block(s). +WARNING MASKED_CATCH IDENTIFIER @111:14 Unreachable catch block for IOException. Only more specific exceptions are thrown and they are handled by previous catch block(s). +WARNING MASKED_CATCH IDENTIFIER @124:14 Unreachable catch block for IOException. Only more specific exceptions are thrown and they are handled by previous catch block(s). diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/CastContexts.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/CastContexts.java new file mode 100644 index 00000000000..5d69d69b349 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/CastContexts.java @@ -0,0 +1,128 @@ +import java.io.Closeable; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.util.List; +import java.util.function.Function; +import java.util.function.Supplier; + +class CastContexts { + + static final int LIMIT; + Object target; + + static { + int seed = 3; + LIMIT = seed * 2; + } + + { + String label = "x"; + target = label; + } + + Object returned(String s) { + return (Object) s; + } + + Object returnedParenthesized(String s) { + return ((Object) s); + } + + void assigned(String s, char c, byte b, short sh, int i, long l) { + target = (Object) s; + target = ((Object) s); + int fromChar = (int) c; + char toChar = (char) i; + long shifted = (long) i << 2; + int shiftedInt = (int) b << sh; + long sum = (long) i + l; + int bytes = (int) b + (int) sh; + double fraction = (double) i / l; + Object[] elements = new Object[1]; + String first = ((String[]) elements)[0]; + Object direct = ((Object[]) elements)[0]; + Integer boxed = (int) b; + } + + void arguments(String s, List list) { + list.add((Object) s); + take((Object) s); + overloaded((Object) s); + varargs((Object) s); + new Holder((Object) s); + Supplier supplier = () -> (Object) s; + Function function = value -> { + return (Object) value; + }; + run(() -> (Object) s); + } + + void take(Object o) { + } + + void overloaded(Object o) { + } + + void overloaded(String s) { + } + + void varargs(Object... values) { + } + + void run(Supplier supplier) { + } + + static class Holder { + Holder(Object o) { + } + } + + void masked() throws IOException { + try { + throw new FileNotFoundException(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + try (Reader reader = new FileReader("f")) { + reader.read(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + try (Closeable closeable = () -> { + }) { + closeable.close(); + } catch (IOException e) { + e.printStackTrace(); + } + try { + try { + throw new FileNotFoundException(); + } finally { + target = null; + } + } catch (FileNotFoundException | IllegalStateException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + Reader shared = new FileReader("g"); + try (shared) { + shared.read(); + } + try { + synchronized (this) { + throw new FileNotFoundException(); + } + } catch (FileNotFoundException e) { + throw e; + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/CastContexts.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/CastContexts.textproto.gz new file mode 100644 index 00000000000..778e3ca264d Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/CastContexts.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Conditionals.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Conditionals.expected.txt new file mode 100644 index 00000000000..0b610d8aa42 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Conditionals.expected.txt @@ -0,0 +1,1328 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id io unknown : ? +TOKEN @1:13 +TOKEN @1:15 +IDENTIFIER @1:16 id Serializable unknown : ? +TOKEN @1:16 +TOKEN @1:28 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id util unknown : ? +TOKEN @2:13 +TOKEN @2:17 +IDENTIFIER @2:18 id ArrayList unknown : ? +TOKEN @2:18 +TOKEN @2:27 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id util unknown : ? +TOKEN @3:13 +TOKEN @3:17 +IDENTIFIER @3:18 id Collection unknown : ? +TOKEN @3:18 +TOKEN @3:28 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id util unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id Comparator unknown : ? +TOKEN @4:18 +TOKEN @4:28 +IMPORT @5:1 +TOKEN @5:1 +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +IDENTIFIER @5:8 id java unknown : ? +TOKEN @5:8 +TOKEN @5:12 +IDENTIFIER @5:13 id util unknown : ? +TOKEN @5:13 +TOKEN @5:17 +IDENTIFIER @5:18 id LinkedList unknown : ? +TOKEN @5:18 +TOKEN @5:28 +IMPORT @6:1 +TOKEN @6:1 +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +IDENTIFIER @6:8 id java unknown : ? +TOKEN @6:8 +TOKEN @6:12 +IDENTIFIER @6:13 id util unknown : ? +TOKEN @6:13 +TOKEN @6:17 +IDENTIFIER @6:18 id List unknown : ? +TOKEN @6:18 +TOKEN @6:22 +IMPORT @7:1 +TOKEN @7:1 +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +IDENTIFIER @7:8 id java unknown : ? +TOKEN @7:8 +TOKEN @7:12 +IDENTIFIER @7:13 id util unknown : ? +TOKEN @7:13 +TOKEN @7:17 +IDENTIFIER @7:18 id function unknown : ? +TOKEN @7:18 +TOKEN @7:26 +IDENTIFIER @7:27 id Supplier unknown : ? +TOKEN @7:27 +TOKEN @7:35 +CLASS @9:1 class .Conditionals [t package] : Conditionals super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] members [, casts, mix, switchTarget, unary, value] lookupToString 0 outermost Conditionals annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw true declaring Conditionals +MODIFIERS +TOKEN @9:1 +IDENTIFIER @9:7 id Conditionals .Conditionals [t package] : Conditionals : Conditionals +TOKEN @9:7 +TYPE_PARAMETERS @9:19 +TOKEN @9:19 +TYPE_PARAMETER @9:20 +IDENTIFIER @9:20 id T Conditionals.T [t package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @9:20 +TOKEN @9:22 +LIST @9:30 +IDENTIFIER @9:30 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @9:30 +TOKEN @9:36 +LIST +LIST +TOKEN @9:38 +VARIABLE @11:3 var Conditionals.value [v package] : T erasure java.lang.Number + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @11:3 id T Conditionals.T [t package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @11:3 +IDENTIFIER @11:5 id value Conditionals.value [v package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @11:5 +TOKEN @11:10 +METHOD @13:3 method Conditionals.mix [m package] : ? (boolean,int,long,java.lang.Integer,java.lang.Long,byte,short,char,double,java.lang.String,T erasure java.lang.Number,java.lang.Number,java.util.ArrayList,java.util.LinkedList) returns java.lang.Object throws [] sig Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [flag, i, l, boxed, boxedLong, b, s, c, d, text, t, n, arrayList, linkedList] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @13:3 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @13:3 +IDENTIFIER @13:10 id mix Conditionals.mix [m package] : ? (boolean,int,long,java.lang.Integer,java.lang.Long,byte,short,char,double,java.lang.String,T erasure java.lang.Number,java.lang.Number,java.util.ArrayList,java.util.LinkedList) returns java.lang.Object throws [] sig Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; : java.lang.Object +TOKEN @13:10 +TOKEN @13:13 +VARIABLE @13:14 var mix.flag [v package] : boolean + details declared true usages 25 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @13:14 : boolean +TOKEN @13:14 +IDENTIFIER @13:22 id flag mix.flag [v package] : boolean : boolean +TOKEN @13:22 +TOKEN @13:26 +VARIABLE @13:28 var mix.i [v package] : int + details declared true usages 6 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @13:28 : int +TOKEN @13:28 +IDENTIFIER @13:32 id i mix.i [v package] : int : int +TOKEN @13:32 +TOKEN @13:33 +VARIABLE @13:35 var mix.l [v package] : long + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @13:35 : long +TOKEN @13:35 +IDENTIFIER @13:40 id l mix.l [v package] : long : long +TOKEN @13:40 +TOKEN @13:41 +VARIABLE @13:43 var mix.boxed [v package] : java.lang.Integer + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @13:43 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @13:43 +IDENTIFIER @13:51 id boxed mix.boxed [v package] : java.lang.Integer : java.lang.Integer +TOKEN @13:51 +TOKEN @13:56 +VARIABLE @13:58 var mix.boxedLong [v package] : java.lang.Long + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @13:58 id Long java.lang.Long [t final public] : java.lang.Long @jdk.internal.ValueBased : java.lang.Long +TOKEN @13:58 +IDENTIFIER @13:63 id boxedLong mix.boxedLong [v package] : java.lang.Long : java.lang.Long +TOKEN @13:63 +TOKEN @13:72 +VARIABLE @13:74 var mix.b [v package] : byte + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @13:74 : byte +TOKEN @13:74 +IDENTIFIER @13:79 id b mix.b [v package] : byte : byte +TOKEN @13:79 +TOKEN @13:80 +VARIABLE @13:82 var mix.s [v package] : short + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @13:82 : short +TOKEN @13:82 +IDENTIFIER @13:88 id s mix.s [v package] : short : short +TOKEN @13:88 +TOKEN @13:89 +VARIABLE @13:91 var mix.c [v package] : char + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @13:91 : char +TOKEN @13:91 +IDENTIFIER @13:96 id c mix.c [v package] : char : char +TOKEN @13:96 +TOKEN @13:97 +VARIABLE @13:99 var mix.d [v package] : double + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @13:99 : double +TOKEN @13:99 +IDENTIFIER @13:106 id d mix.d [v package] : double : double +TOKEN @13:106 +TOKEN @13:107 +VARIABLE @13:109 var mix.text [v package] : java.lang.String + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @13:109 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @13:109 +IDENTIFIER @13:116 id text mix.text [v package] : java.lang.String : java.lang.String +TOKEN @13:116 +TOKEN @13:120 +VARIABLE @13:122 var mix.t [v package] : T erasure java.lang.Number + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @13:122 id T Conditionals.T [t package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @13:122 +IDENTIFIER @13:124 id t mix.t [v package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @13:124 +TOKEN @13:125 +VARIABLE @13:127 var mix.n [v package] : java.lang.Number + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @13:127 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @13:127 +IDENTIFIER @13:134 id n mix.n [v package] : java.lang.Number : java.lang.Number +TOKEN @13:134 +TOKEN @13:135 +VARIABLE @14:5 var mix.arrayList [v package] : java.util.ArrayList + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PARAMETERIZED_TYPE @14:5 : java.util.ArrayList +IDENTIFIER @14:5 id ArrayList java.util.ArrayList [t public] : java.util.ArrayList : java.util.ArrayList +TOKEN @14:5 +TYPE_ARGUMENTS @14:14 +TOKEN @14:14 +IDENTIFIER @14:15 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @14:15 +TOKEN @14:21 +IDENTIFIER @14:23 id arrayList mix.arrayList [v package] : java.util.ArrayList : java.util.ArrayList +TOKEN @14:23 +TOKEN @14:32 +VARIABLE @14:34 var mix.linkedList [v package] : java.util.LinkedList + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PARAMETERIZED_TYPE @14:34 : java.util.LinkedList +IDENTIFIER @14:34 id LinkedList java.util.LinkedList [t public] : java.util.LinkedList : java.util.LinkedList +TOKEN @14:34 +TYPE_ARGUMENTS @14:44 +TOKEN @14:44 +IDENTIFIER @14:45 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @14:45 +TOKEN @14:51 +IDENTIFIER @14:53 id linkedList mix.linkedList [v package] : java.util.LinkedList : java.util.LinkedList +TOKEN @14:53 +TOKEN @14:63 +BLOCK @14:65 +TOKEN @14:65 +VARIABLE @15:5 var mix.a1 [v package] : long + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @15:5 : long +TOKEN @15:5 +IDENTIFIER @15:10 id a1 mix.a1 [v package] : long : long +TOKEN @15:10 +TOKEN @15:13 +CONDITIONAL_EXPRESSION @15:15 : long +IDENTIFIER @15:15 id flag mix.flag [v package] : boolean : boolean +TOKEN @15:15 +TOKEN @15:20 +IDENTIFIER @15:22 id i mix.i [v package] : int : int +TOKEN @15:22 +TOKEN @15:24 +IDENTIFIER @15:26 id l mix.l [v package] : long : long +TOKEN @15:26 +TOKEN @15:27 +VARIABLE @16:5 var mix.a2 [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @16:5 : int +TOKEN @16:5 +IDENTIFIER @16:9 id a2 mix.a2 [v package] : int : int +TOKEN @16:9 +TOKEN @16:12 +CONDITIONAL_EXPRESSION @16:14 : int +IDENTIFIER @16:14 id flag mix.flag [v package] : boolean : boolean +TOKEN @16:14 +TOKEN @16:19 +IDENTIFIER @16:21 id i mix.i [v package] : int : int +TOKEN @16:21 +TOKEN @16:23 +IDENTIFIER @16:25 id boxed mix.boxed [v package] : java.lang.Integer : java.lang.Integer +TOKEN @16:25 +TOKEN @16:30 +VARIABLE @17:5 var mix.a3 [v package] : java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @17:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @17:5 +IDENTIFIER @17:12 id a3 mix.a3 [v package] : java.lang.Object : java.lang.Object +TOKEN @17:12 +TOKEN @17:15 +CONDITIONAL_EXPRESSION @17:17 : long +IDENTIFIER @17:17 id flag mix.flag [v package] : boolean : boolean +TOKEN @17:17 +TOKEN @17:22 +IDENTIFIER @17:24 id boxed mix.boxed [v package] : java.lang.Integer : java.lang.Integer +TOKEN @17:24 +TOKEN @17:30 +IDENTIFIER @17:32 id boxedLong mix.boxedLong [v package] : java.lang.Long : java.lang.Long +TOKEN @17:32 +TOKEN @17:41 +VARIABLE @18:5 var mix.a4 [v package] : short + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @18:5 : short +TOKEN @18:5 +IDENTIFIER @18:11 id a4 mix.a4 [v package] : short : short +TOKEN @18:11 +TOKEN @18:14 +CONDITIONAL_EXPRESSION @18:16 : short +IDENTIFIER @18:16 id flag mix.flag [v package] : boolean : boolean +TOKEN @18:16 +TOKEN @18:21 +IDENTIFIER @18:23 id b mix.b [v package] : byte : byte +TOKEN @18:23 +TOKEN @18:25 +IDENTIFIER @18:27 id s mix.s [v package] : short : short +TOKEN @18:27 +TOKEN @18:28 +VARIABLE @19:5 var mix.a5 [v package] : char + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @19:5 : char +TOKEN @19:5 +IDENTIFIER @19:10 id a5 mix.a5 [v package] : char : char +TOKEN @19:10 +TOKEN @19:13 +CONDITIONAL_EXPRESSION @19:15 : char +IDENTIFIER @19:15 id flag mix.flag [v package] : boolean : boolean +TOKEN @19:15 +TOKEN @19:20 +IDENTIFIER @19:22 id c mix.c [v package] : char : char +TOKEN @19:22 +TOKEN @19:24 +INT_LITERAL @19:26 : int = 1 +TOKEN @19:26 +TOKEN @19:27 +VARIABLE @20:5 var mix.a6 [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @20:5 : int +TOKEN @20:5 +IDENTIFIER @20:9 id a6 mix.a6 [v package] : int : int +TOKEN @20:9 +TOKEN @20:12 +CONDITIONAL_EXPRESSION @20:14 : char +IDENTIFIER @20:14 id flag mix.flag [v package] : boolean : boolean +TOKEN @20:14 +TOKEN @20:19 +INT_LITERAL @20:21 : int = 1 +TOKEN @20:21 +TOKEN @20:23 +IDENTIFIER @20:25 id c mix.c [v package] : char : char +TOKEN @20:25 +TOKEN @20:26 +VARIABLE @21:5 var mix.a7 [v package] : double + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @21:5 : double +TOKEN @21:5 +IDENTIFIER @21:12 id a7 mix.a7 [v package] : double : double +TOKEN @21:12 +TOKEN @21:15 +CONDITIONAL_EXPRESSION @21:17 : double +IDENTIFIER @21:17 id flag mix.flag [v package] : boolean : boolean +TOKEN @21:17 +TOKEN @21:22 +IDENTIFIER @21:24 id d mix.d [v package] : double : double +TOKEN @21:24 +TOKEN @21:26 +IDENTIFIER @21:28 id i mix.i [v package] : int : int +TOKEN @21:28 +TOKEN @21:29 +VARIABLE @22:5 var mix.a8 [v package] : java.lang.Integer + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @22:5 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @22:5 +IDENTIFIER @22:13 id a8 mix.a8 [v package] : java.lang.Integer : java.lang.Integer +TOKEN @22:13 +TOKEN @22:16 +CONDITIONAL_EXPRESSION @22:18 : java.lang.Integer +IDENTIFIER @22:18 id flag mix.flag [v package] : boolean : boolean +TOKEN @22:18 +TOKEN @22:23 +NULL_LITERAL @22:25 : +TOKEN @22:25 +TOKEN @22:30 +IDENTIFIER @22:32 id i mix.i [v package] : int : int +TOKEN @22:32 +TOKEN @22:33 +VARIABLE @23:5 var mix.a9 [v package] : java.lang.Integer + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @23:5 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @23:5 +IDENTIFIER @23:13 id a9 mix.a9 [v package] : java.lang.Integer : java.lang.Integer +TOKEN @23:13 +TOKEN @23:16 +CONDITIONAL_EXPRESSION @23:18 : java.lang.Integer +IDENTIFIER @23:18 id flag mix.flag [v package] : boolean : boolean +TOKEN @23:18 +TOKEN @23:23 +IDENTIFIER @23:25 id i mix.i [v package] : int : int +TOKEN @23:25 +TOKEN @23:27 +NULL_LITERAL @23:29 : +TOKEN @23:29 +TOKEN @23:33 +VARIABLE @24:5 var mix.a10 [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @24:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @24:5 +IDENTIFIER @24:12 id a10 mix.a10 [v package] : java.lang.String : java.lang.String +TOKEN @24:12 +TOKEN @24:16 +CONDITIONAL_EXPRESSION @24:18 : java.lang.String +IDENTIFIER @24:18 id flag mix.flag [v package] : boolean : boolean +TOKEN @24:18 +TOKEN @24:23 +NULL_LITERAL @24:25 : +TOKEN @24:25 +TOKEN @24:30 +IDENTIFIER @24:32 id text mix.text [v package] : java.lang.String : java.lang.String +TOKEN @24:32 +TOKEN @24:36 +VARIABLE @25:5 var mix.a11 [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @25:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @25:5 +IDENTIFIER @25:12 id a11 mix.a11 [v package] : java.lang.String : java.lang.String +TOKEN @25:12 +TOKEN @25:16 +CONDITIONAL_EXPRESSION @25:18 : java.lang.String +IDENTIFIER @25:18 id flag mix.flag [v package] : boolean : boolean +TOKEN @25:18 +TOKEN @25:23 +IDENTIFIER @25:25 id text mix.text [v package] : java.lang.String : java.lang.String +TOKEN @25:25 +TOKEN @25:30 +NULL_LITERAL @25:32 : +TOKEN @25:32 +TOKEN @25:36 +VARIABLE @26:5 var mix.a12 [v package] : java.lang.Number + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @26:5 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @26:5 +IDENTIFIER @26:12 id a12 mix.a12 [v package] : java.lang.Number : java.lang.Number +TOKEN @26:12 +TOKEN @26:16 +CONDITIONAL_EXPRESSION @26:18 : java.lang.Number +IDENTIFIER @26:18 id flag mix.flag [v package] : boolean : boolean +TOKEN @26:18 +TOKEN @26:23 +IDENTIFIER @26:25 id t mix.t [v package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @26:25 +TOKEN @26:27 +IDENTIFIER @26:29 id n mix.n [v package] : java.lang.Number : java.lang.Number +TOKEN @26:29 +TOKEN @26:30 +VARIABLE @27:5 var mix.a13 [v package] : java.lang.Number + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @27:5 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @27:5 +IDENTIFIER @27:12 id a13 mix.a13 [v package] : java.lang.Number : java.lang.Number +TOKEN @27:12 +TOKEN @27:16 +CONDITIONAL_EXPRESSION @27:18 : java.lang.Number +IDENTIFIER @27:18 id flag mix.flag [v package] : boolean : boolean +TOKEN @27:18 +TOKEN @27:23 +IDENTIFIER @27:25 id n mix.n [v package] : java.lang.Number : java.lang.Number +TOKEN @27:25 +TOKEN @27:27 +IDENTIFIER @27:29 id t mix.t [v package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @27:29 +TOKEN @27:30 +VARIABLE @28:5 var mix.a14 [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PARAMETERIZED_TYPE @28:5 : java.util.List +IDENTIFIER @28:5 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @28:5 +TYPE_ARGUMENTS @28:9 +TOKEN @28:9 +IDENTIFIER @28:10 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @28:10 +TOKEN @28:16 +IDENTIFIER @28:18 id a14 mix.a14 [v package] : java.util.List : java.util.List +TOKEN @28:18 +TOKEN @28:22 +CONDITIONAL_EXPRESSION @28:24 : java.util.ArrayList +IDENTIFIER @28:24 id flag mix.flag [v package] : boolean : boolean +TOKEN @28:24 +TOKEN @28:29 +IDENTIFIER @28:31 id arrayList mix.arrayList [v package] : java.util.ArrayList : java.util.ArrayList +TOKEN @28:31 +TOKEN @28:41 +IDENTIFIER @28:43 id linkedList mix.linkedList [v package] : java.util.LinkedList : java.util.LinkedList +TOKEN @28:43 +TOKEN @28:53 +VARIABLE @29:5 var mix.a15 [v package] : java.util.Collection + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PARAMETERIZED_TYPE @29:5 : java.util.Collection +IDENTIFIER @29:5 id Collection java.util.Collection [t public interface] : java.util.Collection : java.util.Collection +TOKEN @29:5 +TYPE_ARGUMENTS @29:15 +TOKEN @29:15 +IDENTIFIER @29:16 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @29:16 +TOKEN @29:22 +IDENTIFIER @29:24 id a15 mix.a15 [v package] : java.util.Collection : java.util.Collection +TOKEN @29:24 +TOKEN @29:28 +CONDITIONAL_EXPRESSION @29:30 : java.util.List +IDENTIFIER @29:30 id flag mix.flag [v package] : boolean : boolean +TOKEN @29:30 +TOKEN @29:35 +IDENTIFIER @29:37 id arrayList mix.arrayList [v package] : java.util.ArrayList : java.util.ArrayList +TOKEN @29:37 +TOKEN @29:47 +METHOD_INVOCATION @29:49 call List.of [m static public] : ? () returns java.util.List throws [] sig java.util.List#of()Ljava/util/List; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @29:49 : ? +IDENTIFIER @29:49 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @29:49 +TOKEN @29:53 +IDENTIFIER @29:54 id of List.of [m static public] : ? () returns java.util.List throws [] sig java.util.List#of()Ljava/util/List; : java.util.List +TOKEN @29:54 +ARGUMENTS @29:56 +TOKEN @29:56 +TOKEN @29:57 +TOKEN @29:58 +VARIABLE @30:5 var mix.a16 [v package] : java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @30:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @30:5 +IDENTIFIER @30:12 id a16 mix.a16 [v package] : java.lang.Object : java.lang.Object +TOKEN @30:12 +TOKEN @30:16 +CONDITIONAL_EXPRESSION @30:18 : java.lang.String +IDENTIFIER @30:18 id flag mix.flag [v package] : boolean : boolean +TOKEN @30:18 +TOKEN @30:23 +IDENTIFIER @30:25 id text mix.text [v package] : java.lang.String : java.lang.String +TOKEN @30:25 +TOKEN @30:30 +IDENTIFIER @30:32 id i mix.i [v package] : int : int +TOKEN @30:32 +TOKEN @30:33 +VARIABLE @31:5 var mix.a17 [v package] : boolean + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PRIMITIVE_TYPE @31:5 : boolean +TOKEN @31:5 +IDENTIFIER @31:13 id a17 mix.a17 [v package] : boolean : boolean +TOKEN @31:13 +TOKEN @31:17 +CONDITIONAL_EXPRESSION @31:19 : boolean +IDENTIFIER @31:19 id flag mix.flag [v package] : boolean : boolean +TOKEN @31:19 +TOKEN @31:24 +IDENTIFIER @31:26 id flag mix.flag [v package] : boolean : boolean +TOKEN @31:26 +TOKEN @31:31 +LOGICAL_COMPLEMENT @31:33 : boolean +TOKEN @31:33 +IDENTIFIER @31:34 id flag mix.flag [v package] : boolean : boolean +TOKEN @31:34 +TOKEN @31:38 +VARIABLE @32:5 var mix.a18 [v package] : java.lang.Boolean + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @32:5 id Boolean java.lang.Boolean [t final public] : java.lang.Boolean @jdk.internal.ValueBased : java.lang.Boolean +TOKEN @32:5 +IDENTIFIER @32:13 id a18 mix.a18 [v package] : java.lang.Boolean : java.lang.Boolean +TOKEN @32:13 +TOKEN @32:17 +CONDITIONAL_EXPRESSION @32:19 : boolean +IDENTIFIER @32:19 id flag mix.flag [v package] : boolean : boolean +TOKEN @32:19 +TOKEN @32:24 +MEMBER_SELECT @32:26 : java.lang.Boolean = true +IDENTIFIER @32:26 id Boolean java.lang.Boolean [t final public] : java.lang.Boolean @jdk.internal.ValueBased : java.lang.Boolean +TOKEN @32:26 +TOKEN @32:33 +IDENTIFIER @32:34 id TRUE Boolean.TRUE [v static final public] : java.lang.Boolean : java.lang.Boolean = true +TOKEN @32:34 +TOKEN @32:39 +IDENTIFIER @32:41 id flag mix.flag [v package] : boolean : boolean +TOKEN @32:41 +TOKEN @32:45 +VARIABLE @33:5 var mix.a19 [v package] : java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @33:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @33:5 +IDENTIFIER @33:12 id a19 mix.a19 [v package] : java.lang.Object : java.lang.Object +TOKEN @33:12 +TOKEN @33:16 +CONDITIONAL_EXPRESSION @33:18 : int +IDENTIFIER @33:18 id flag mix.flag [v package] : boolean : boolean +TOKEN @33:18 +TOKEN @33:23 +IDENTIFIER @33:25 id b mix.b [v package] : byte : byte +TOKEN @33:25 +TOKEN @33:27 +IDENTIFIER @33:29 id c mix.c [v package] : char : char +TOKEN @33:29 +TOKEN @33:30 +VARIABLE @34:5 var mix.a20 [v package] : T erasure java.lang.Number + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +IDENTIFIER @34:5 id T Conditionals.T [t package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @34:5 +IDENTIFIER @34:7 id a20 mix.a20 [v package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @34:7 +TOKEN @34:11 +CONDITIONAL_EXPRESSION @34:13 : T erasure java.lang.Number +IDENTIFIER @34:13 id flag mix.flag [v package] : boolean : boolean +TOKEN @34:13 +TOKEN @34:18 +IDENTIFIER @34:20 id t mix.t [v package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @34:20 +TOKEN @34:22 +IDENTIFIER @34:24 id value Conditionals.value [v package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @34:24 +TOKEN @34:29 +VARIABLE @35:5 var mix.a21 [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PARAMETERIZED_TYPE @35:5 : java.util.List +IDENTIFIER @35:5 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @35:5 +TYPE_ARGUMENTS @35:9 +TOKEN @35:9 +IDENTIFIER @35:10 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @35:10 +TOKEN @35:16 +IDENTIFIER @35:18 id a21 mix.a21 [v package] : java.util.List : java.util.List +TOKEN @35:18 +TOKEN @35:22 +CONDITIONAL_EXPRESSION @35:24 : java.util.ArrayList +IDENTIFIER @35:24 id flag mix.flag [v package] : boolean : boolean +TOKEN @35:24 +TOKEN @35:29 +NEW_CLASS @35:31 new ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ArrayList flags [public] overridden [AbstractList.[], AbstractCollection.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @35:31 +PARAMETERIZED_TYPE @35:35 : java.util.ArrayList +IDENTIFIER @35:35 id ArrayList ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList +TOKEN @35:35 +TYPE_ARGUMENTS @35:44 +TOKEN @35:44 +TOKEN @35:45 +ARGUMENTS @35:46 +TOKEN @35:46 +TOKEN @35:47 +TOKEN @35:49 +NEW_CLASS @35:51 new LinkedList. [m public] : ? () returns void throws [] sig java.util.LinkedList#()V : java.util.LinkedList + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing LinkedList flags [public] overridden [AbstractSequentialList.[], AbstractList.[], AbstractCollection.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @35:51 +PARAMETERIZED_TYPE @35:55 : java.util.LinkedList +IDENTIFIER @35:55 id LinkedList LinkedList. [m public] : ? () returns void throws [] sig java.util.LinkedList#()V : java.util.LinkedList +TOKEN @35:55 +TYPE_ARGUMENTS @35:65 +TOKEN @35:65 +TOKEN @35:66 +ARGUMENTS @35:67 +TOKEN @35:67 +TOKEN @35:68 +TOKEN @35:69 +VARIABLE @36:5 var mix.a22 [v package] : java.util.function.Supplier + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner mix Conditionals#mix(ZIJLjava/lang/Integer;Ljava/lang/Long;BSCDLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/util/ArrayList;Ljava/util/LinkedList;)Ljava/lang/Object; [package] returns java.lang.Object parameters 14 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse14falsefalse +MODIFIERS +PARAMETERIZED_TYPE @36:5 : java.util.function.Supplier +IDENTIFIER @36:5 id Supplier java.util.function.Supplier [t public interface] : java.util.function.Supplier @java.lang.FunctionalInterface : java.util.function.Supplier +TOKEN @36:5 +TYPE_ARGUMENTS @36:13 +TOKEN @36:13 +IDENTIFIER @36:14 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @36:14 +TOKEN @36:20 +IDENTIFIER @36:22 id a22 mix.a22 [v package] : java.util.function.Supplier : java.util.function.Supplier +TOKEN @36:22 +TOKEN @36:26 +CONDITIONAL_EXPRESSION @36:28 : ? +IDENTIFIER @36:28 id flag mix.flag [v package] : boolean : boolean +TOKEN @36:28 +TOKEN @36:33 +LAMBDA_EXPRESSION @36:35 : ? +TOKEN @36:35 +TOKEN @36:36 +TOKEN @36:38 +STRING_LITERAL @36:41 : java.lang.String = a +TOKEN @36:41 +TOKEN @36:45 +METHOD_REFERENCE @36:47 : ? +IDENTIFIER @36:47 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @36:47 +TOKEN @36:53 +IDENTIFIER @36:55 id new unknown : ? +TOKEN @36:55 +TOKEN @36:58 +RETURN_STATEMENT @37:5 +TOKEN @37:5 +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : java.lang.String +PLUS @37:12 : long +IDENTIFIER @37:12 id a1 mix.a1 [v package] : long : long +TOKEN @37:12 +TOKEN @37:15 +IDENTIFIER @37:17 id a2 mix.a2 [v package] : int : int +TOKEN @37:17 +TOKEN @37:20 +METHOD_INVOCATION @37:22 call String.valueOf [m static public] : ? (java.lang.Object) returns java.lang.String throws [] sig java.lang.String#valueOf(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @37:22 : ? +IDENTIFIER @37:22 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @37:22 +TOKEN @37:28 +IDENTIFIER @37:29 id valueOf String.valueOf [m static public] : ? (java.lang.Object) returns java.lang.String throws [] sig java.lang.String#valueOf(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String +TOKEN @37:29 +ARGUMENTS @37:36 +TOKEN @37:36 +IDENTIFIER @37:37 id a3 mix.a3 [v package] : java.lang.Object : java.lang.Object +TOKEN @37:37 +TOKEN @37:39 +TOKEN @37:41 +IDENTIFIER @37:43 id a4 mix.a4 [v package] : short : short +TOKEN @37:43 +TOKEN @37:46 +IDENTIFIER @37:48 id a5 mix.a5 [v package] : char : char +TOKEN @37:48 +TOKEN @37:51 +IDENTIFIER @37:53 id a6 mix.a6 [v package] : int : int +TOKEN @37:53 +TOKEN @37:56 +IDENTIFIER @37:58 id a7 mix.a7 [v package] : double : double +TOKEN @37:58 +TOKEN @37:61 +IDENTIFIER @37:63 id a8 mix.a8 [v package] : java.lang.Integer : java.lang.Integer +TOKEN @37:63 +TOKEN @37:66 +IDENTIFIER @37:68 id a9 mix.a9 [v package] : java.lang.Integer : java.lang.Integer +TOKEN @37:68 +TOKEN @37:71 +IDENTIFIER @37:73 id a10 mix.a10 [v package] : java.lang.String : java.lang.String +TOKEN @37:73 +TOKEN @37:77 +IDENTIFIER @37:79 id a11 mix.a11 [v package] : java.lang.String : java.lang.String +TOKEN @37:79 +TOKEN @37:83 +IDENTIFIER @37:85 id a12 mix.a12 [v package] : java.lang.Number : java.lang.Number +TOKEN @37:85 +TOKEN @37:89 +IDENTIFIER @37:91 id a13 mix.a13 [v package] : java.lang.Number : java.lang.Number +TOKEN @37:91 +TOKEN @37:95 +IDENTIFIER @37:97 id a14 mix.a14 [v package] : java.util.List : java.util.List +TOKEN @37:97 +TOKEN @37:101 +IDENTIFIER @37:103 id a15 mix.a15 [v package] : java.util.Collection : java.util.Collection +TOKEN @37:103 +TOKEN @37:107 +IDENTIFIER @37:109 id a16 mix.a16 [v package] : java.lang.Object : java.lang.Object +TOKEN @37:109 +TOKEN @37:113 +IDENTIFIER @37:115 id a17 mix.a17 [v package] : boolean : boolean +TOKEN @37:115 +TOKEN @37:119 +IDENTIFIER @37:121 id a18 mix.a18 [v package] : java.lang.Boolean : java.lang.Boolean +TOKEN @37:121 +TOKEN @37:125 +IDENTIFIER @37:127 id a19 mix.a19 [v package] : java.lang.Object : java.lang.Object +TOKEN @37:127 +TOKEN @37:131 +IDENTIFIER @37:133 id a20 mix.a20 [v package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @37:133 +TOKEN @37:137 +IDENTIFIER @37:139 id a21 mix.a21 [v package] : java.util.List : java.util.List +TOKEN @37:139 +TOKEN @37:143 +IDENTIFIER @37:145 id a22 mix.a22 [v package] : java.util.function.Supplier : java.util.function.Supplier +TOKEN @37:145 +TOKEN @37:148 +TOKEN @38:3 +METHOD @40:3 method Conditionals.casts [m package] : ? (java.lang.Object) returns java.lang.Object throws [] sig Conditionals#casts(Ljava/lang/Object;)Ljava/lang/Object; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [o] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @40:3 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @40:3 +IDENTIFIER @40:10 id casts Conditionals.casts [m package] : ? (java.lang.Object) returns java.lang.Object throws [] sig Conditionals#casts(Ljava/lang/Object;)Ljava/lang/Object; : java.lang.Object +TOKEN @40:10 +TOKEN @40:15 +VARIABLE @40:16 var casts.o [v package] : java.lang.Object + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner casts Conditionals#casts(Ljava/lang/Object;)Ljava/lang/Object; [package] returns java.lang.Object parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @40:16 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @40:16 +IDENTIFIER @40:23 id o casts.o [v package] : java.lang.Object : java.lang.Object +TOKEN @40:23 +TOKEN @40:24 +BLOCK @40:26 +TOKEN @40:26 +VARIABLE @41:5 var casts.task [v package] : java.lang.Runnable + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner casts Conditionals#casts(Ljava/lang/Object;)Ljava/lang/Object; [package] returns java.lang.Object parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @41:5 id Runnable java.lang.Runnable [t public interface] : java.lang.Runnable @java.lang.FunctionalInterface : java.lang.Runnable +TOKEN @41:5 +IDENTIFIER @41:14 id task casts.task [v package] : java.lang.Runnable : java.lang.Runnable +TOKEN @41:14 +TOKEN @41:19 +TYPE_CAST @41:21 : java.io.Serializable & java.lang.Runnable +TOKEN @41:21 +IDENTIFIER @41:22 id Runnable java.lang.Runnable [t public interface] : java.lang.Runnable @java.lang.FunctionalInterface : java.lang.Runnable +TOKEN @41:22 +TOKEN @41:31 +LIST @41:33 +IDENTIFIER @41:33 id Serializable java.io.Serializable [t public interface] : java.io.Serializable : java.io.Serializable +TOKEN @41:33 +TOKEN @41:45 +LAMBDA_EXPRESSION @41:47 : ? +TOKEN @41:47 +TOKEN @41:48 +TOKEN @41:50 +METHOD_INVOCATION @41:53 call PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing PrintStream flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @41:53 : ? +MEMBER_SELECT @41:53 : java.io.PrintStream +IDENTIFIER @41:53 id System java.lang.System [t final public] : java.lang.System : java.lang.System +TOKEN @41:53 +TOKEN @41:59 +IDENTIFIER @41:60 id out System.out [v static final public] : java.io.PrintStream : java.io.PrintStream +TOKEN @41:60 +TOKEN @41:63 +IDENTIFIER @41:64 id println PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void +TOKEN @41:64 +ARGUMENTS @41:71 +TOKEN @41:71 +STRING_LITERAL @41:72 : java.lang.String = task +TOKEN @41:72 +TOKEN @41:78 +TOKEN @41:79 +VARIABLE @42:5 var casts.comparator [v package] : java.util.Comparator + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner casts Conditionals#casts(Ljava/lang/Object;)Ljava/lang/Object; [package] returns java.lang.Object parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @42:5 : java.util.Comparator +IDENTIFIER @42:5 id Comparator java.util.Comparator [t public interface] : java.util.Comparator @java.lang.FunctionalInterface : java.util.Comparator +TOKEN @42:5 +TYPE_ARGUMENTS @42:15 +TOKEN @42:15 +IDENTIFIER @42:16 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @42:16 +TOKEN @42:22 +IDENTIFIER @42:24 id comparator casts.comparator [v package] : java.util.Comparator : java.util.Comparator +TOKEN @42:24 +TOKEN @42:35 +TYPE_CAST @42:37 : java.io.Serializable & java.util.Comparator +TOKEN @42:37 +PARAMETERIZED_TYPE @42:38 : java.util.Comparator +IDENTIFIER @42:38 id Comparator java.util.Comparator [t public interface] : java.util.Comparator @java.lang.FunctionalInterface : java.util.Comparator +TOKEN @42:38 +TYPE_ARGUMENTS @42:48 +TOKEN @42:48 +IDENTIFIER @42:49 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @42:49 +TOKEN @42:55 +TOKEN @42:57 +LIST @42:59 +IDENTIFIER @42:59 id Serializable java.io.Serializable [t public interface] : java.io.Serializable : java.io.Serializable +TOKEN @42:59 +TOKEN @42:71 +LAMBDA_EXPRESSION @42:73 : ? +TOKEN @42:73 +VARIABLE @42:74 var casts(java.lang.Object)$lambda$42:72.x [v package] : java.lang.String + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner casts(java.lang.Object)$lambda$42:72 Conditionals#casts(java.lang.Object)$lambda$42:72()Ljava/lang/Object; [package] returns ? parameters 0 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @42:74 id x casts(java.lang.Object)$lambda$42:72.x [v package] : java.lang.String : java.lang.String +TOKEN @42:74 +TOKEN @42:75 +VARIABLE @42:77 var casts(java.lang.Object)$lambda$42:72.y [v package] : java.lang.String + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner casts(java.lang.Object)$lambda$42:72 Conditionals#casts(java.lang.Object)$lambda$42:72()Ljava/lang/Object; [package] returns ? parameters 0 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @42:77 id y casts(java.lang.Object)$lambda$42:72.y [v package] : java.lang.String : java.lang.String +TOKEN @42:77 +TOKEN @42:78 +TOKEN @42:80 +MINUS @42:83 : int +METHOD_INVOCATION @42:83 call String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [CharSequence.length[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @42:83 : ? +IDENTIFIER @42:83 id x casts(java.lang.Object)$lambda$42:72.x [v package] : java.lang.String : java.lang.String +TOKEN @42:83 +TOKEN @42:84 +IDENTIFIER @42:85 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @42:85 +ARGUMENTS @42:91 +TOKEN @42:91 +TOKEN @42:92 +TOKEN @42:94 +METHOD_INVOCATION @42:96 call String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [CharSequence.length[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @42:96 : ? +IDENTIFIER @42:96 id y casts(java.lang.Object)$lambda$42:72.y [v package] : java.lang.String : java.lang.String +TOKEN @42:96 +TOKEN @42:97 +IDENTIFIER @42:98 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @42:98 +ARGUMENTS @42:104 +TOKEN @42:104 +TOKEN @42:105 +TOKEN @42:106 +VARIABLE @43:5 var casts.intersection [v package] : java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner casts Conditionals#casts(Ljava/lang/Object;)Ljava/lang/Object; [package] returns java.lang.Object parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @43:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @43:5 +IDENTIFIER @43:12 id intersection casts.intersection [v package] : java.lang.Object : java.lang.Object +TOKEN @43:12 +TOKEN @43:25 +TYPE_CAST @43:27 : java.io.Serializable & java.lang.Comparable +TOKEN @43:27 +IDENTIFIER @43:28 id Serializable java.io.Serializable [t public interface] : java.io.Serializable : java.io.Serializable +TOKEN @43:28 +TOKEN @43:41 +LIST @43:43 +PARAMETERIZED_TYPE @43:43 : java.lang.Comparable +IDENTIFIER @43:43 id Comparable java.lang.Comparable [t public interface] : java.lang.Comparable : java.lang.Comparable +TOKEN @43:43 +TYPE_ARGUMENTS @43:53 +TOKEN @43:53 +IDENTIFIER @43:54 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @43:54 +TOKEN @43:60 +TOKEN @43:61 +IDENTIFIER @43:63 id o casts.o [v package] : java.lang.Object : java.lang.Object +TOKEN @43:63 +TOKEN @43:64 +RETURN_STATEMENT @44:5 +TOKEN @44:5 +SWITCH_EXPRESSION @44:12 : ? +TOKEN @44:12 +TOKEN @44:19 +METHOD_INVOCATION @44:20 call Object.hashCode [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns int throws [] sig java.lang.Object#hashCode()I : int + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @44:20 : ? +IDENTIFIER @44:20 id o casts.o [v package] : java.lang.Object : java.lang.Object +TOKEN @44:20 +TOKEN @44:21 +IDENTIFIER @44:22 id hashCode Object.hashCode [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns int throws [] sig java.lang.Object#hashCode()I : int +TOKEN @44:22 +ARGUMENTS @44:30 +TOKEN @44:30 +TOKEN @44:31 +TOKEN @44:32 +TOKEN @44:34 +CASE_GROUP @45:7 +CASE_LABEL @45:7 +TOKEN @45:7 +INT_LITERAL @45:12 : int = 0 +TOKEN @45:12 +TOKEN @45:14 +YIELD_STATEMENT @45:17 +IDENTIFIER @45:17 id task casts.task [v package] : java.lang.Runnable : java.lang.Runnable +TOKEN @45:17 +TOKEN @45:21 +CASE_GROUP @46:7 +CASE_LABEL @46:7 +TOKEN @46:7 +INT_LITERAL @46:12 : int = 1 +TOKEN @46:12 +TOKEN @46:14 +YIELD_STATEMENT @46:17 +IDENTIFIER @46:17 id comparator casts.comparator [v package] : java.util.Comparator : java.util.Comparator +TOKEN @46:17 +TOKEN @46:27 +CASE_GROUP @47:7 +CASE_LABEL @47:7 +TOKEN @47:7 +TOKEN @47:15 +YIELD_STATEMENT @47:18 +IDENTIFIER @47:18 id intersection casts.intersection [v package] : java.lang.Object : java.lang.Object +TOKEN @47:18 +TOKEN @47:30 +TOKEN @48:5 +TOKEN @48:6 +TOKEN @49:3 +METHOD @51:3 method Conditionals.switchTarget [m package] : ? (int,T erasure java.lang.Number) returns java.lang.Number throws [] sig Conditionals#switchTarget(ILjava/lang/Number;)Ljava/lang/Number; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [k, t] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @51:3 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @51:3 +IDENTIFIER @51:10 id switchTarget Conditionals.switchTarget [m package] : ? (int,T erasure java.lang.Number) returns java.lang.Number throws [] sig Conditionals#switchTarget(ILjava/lang/Number;)Ljava/lang/Number; : java.lang.Number +TOKEN @51:10 +TOKEN @51:22 +VARIABLE @51:23 var switchTarget.k [v package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner switchTarget Conditionals#switchTarget(ILjava/lang/Number;)Ljava/lang/Number; [package] returns java.lang.Number parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @51:23 : int +TOKEN @51:23 +IDENTIFIER @51:27 id k switchTarget.k [v package] : int : int +TOKEN @51:27 +TOKEN @51:28 +VARIABLE @51:30 var switchTarget.t [v package] : T erasure java.lang.Number + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner switchTarget Conditionals#switchTarget(ILjava/lang/Number;)Ljava/lang/Number; [package] returns java.lang.Number parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @51:30 id T Conditionals.T [t package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @51:30 +IDENTIFIER @51:32 id t switchTarget.t [v package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @51:32 +TOKEN @51:33 +BLOCK @51:35 +TOKEN @51:35 +VARIABLE @52:5 var switchTarget.result [v package] : java.lang.Number + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner switchTarget Conditionals#switchTarget(ILjava/lang/Number;)Ljava/lang/Number; [package] returns java.lang.Number parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @52:5 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @52:5 +IDENTIFIER @52:12 id result switchTarget.result [v package] : java.lang.Number : java.lang.Number +TOKEN @52:12 +TOKEN @52:19 +SWITCH_EXPRESSION @52:21 : java.lang.Number +TOKEN @52:21 +TOKEN @52:28 +IDENTIFIER @52:29 id k switchTarget.k [v package] : int : int +TOKEN @52:29 +TOKEN @52:30 +TOKEN @52:32 +CASE_GROUP @53:7 +CASE_LABEL @53:7 +TOKEN @53:7 +INT_LITERAL @53:12 : int = 0 +TOKEN @53:12 +TOKEN @53:14 +YIELD_STATEMENT @53:17 +INT_LITERAL @53:17 : int = 1 +TOKEN @53:17 +TOKEN @53:18 +CASE_GROUP @54:7 +CASE_LABEL @54:7 +TOKEN @54:7 +INT_LITERAL @54:12 : int = 1 +TOKEN @54:12 +TOKEN @54:14 +YIELD_STATEMENT @54:17 +LONG_LITERAL @54:17 : long = 2 +TOKEN @54:17 +TOKEN @54:19 +CASE_GROUP @55:7 +CASE_LABEL @55:7 +TOKEN @55:7 +TOKEN @55:15 +YIELD_STATEMENT @55:18 +IDENTIFIER @55:18 id t switchTarget.t [v package] : T erasure java.lang.Number : T erasure java.lang.Number +TOKEN @55:18 +TOKEN @55:19 +TOKEN @56:5 +TOKEN @56:6 +VARIABLE @57:5 var switchTarget.numbers [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner switchTarget Conditionals#switchTarget(ILjava/lang/Number;)Ljava/lang/Number; [package] returns java.lang.Number parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PARAMETERIZED_TYPE @57:5 : java.util.List +IDENTIFIER @57:5 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @57:5 +TYPE_ARGUMENTS @57:9 +TOKEN @57:9 +EXTENDS_WILDCARD @57:10 +TOKEN @57:10 +TOKEN @57:12 +IDENTIFIER @57:20 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @57:20 +TOKEN @57:26 +IDENTIFIER @57:28 id numbers switchTarget.numbers [v package] : java.util.List : java.util.List +TOKEN @57:28 +TOKEN @57:36 +SWITCH_EXPRESSION @57:38 : java.util.List +TOKEN @57:38 +TOKEN @57:45 +IDENTIFIER @57:46 id k switchTarget.k [v package] : int : int +TOKEN @57:46 +TOKEN @57:47 +TOKEN @57:49 +CASE_GROUP @58:7 +CASE_LABEL @58:7 +TOKEN @58:7 +INT_LITERAL @58:12 : int = 0 +TOKEN @58:12 +TOKEN @58:14 +YIELD_STATEMENT @58:17 +METHOD_INVOCATION @58:17 call List.of [m static public] : ? (java.lang.Integer) returns java.util.List throws [] sig java.util.List#of(Ljava/lang/Object;)Ljava/util/List; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @58:17 : ? +IDENTIFIER @58:17 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @58:17 +TOKEN @58:21 +IDENTIFIER @58:22 id of List.of [m static public] : ? (java.lang.Integer) returns java.util.List throws [] sig java.util.List#of(Ljava/lang/Object;)Ljava/util/List; : java.util.List +TOKEN @58:22 +ARGUMENTS @58:24 +TOKEN @58:24 +INT_LITERAL @58:25 : int = 1 +TOKEN @58:25 +TOKEN @58:26 +TOKEN @58:27 +CASE_GROUP @59:7 +CASE_LABEL @59:7 +TOKEN @59:7 +TOKEN @59:15 +YIELD_STATEMENT @59:18 +NEW_CLASS @59:18 new ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ArrayList flags [public] overridden [AbstractList.[], AbstractCollection.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @59:18 +PARAMETERIZED_TYPE @59:22 : java.util.ArrayList +IDENTIFIER @59:22 id ArrayList ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList +TOKEN @59:22 +TYPE_ARGUMENTS @59:31 +TOKEN @59:31 +IDENTIFIER @59:32 id Double java.lang.Double [t final public] : java.lang.Double @jdk.internal.ValueBased : java.lang.Double +TOKEN @59:32 +TOKEN @59:38 +ARGUMENTS @59:39 +TOKEN @59:39 +TOKEN @59:40 +TOKEN @59:41 +TOKEN @60:5 +TOKEN @60:6 +RETURN_STATEMENT @61:5 +TOKEN @61:5 +PLUS @61:12 : int +METHOD_INVOCATION @61:12 call Number.intValue [m abstract public] : ? () returns int throws [] sig java.lang.Number#intValue()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Number flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @61:12 : ? +IDENTIFIER @61:12 id result switchTarget.result [v package] : java.lang.Number : java.lang.Number +TOKEN @61:12 +TOKEN @61:18 +IDENTIFIER @61:19 id intValue Number.intValue [m abstract public] : ? () returns int throws [] sig java.lang.Number#intValue()I : int +TOKEN @61:19 +ARGUMENTS @61:27 +TOKEN @61:27 +TOKEN @61:28 +TOKEN @61:30 +METHOD_INVOCATION @61:32 call List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.size[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @61:32 : ? +IDENTIFIER @61:32 id numbers switchTarget.numbers [v package] : java.util.List : java.util.List +TOKEN @61:32 +TOKEN @61:39 +IDENTIFIER @61:40 id size List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int +TOKEN @61:40 +ARGUMENTS @61:44 +TOKEN @61:44 +TOKEN @61:45 +TOKEN @61:46 +TOKEN @62:3 +METHOD @64:3 method Conditionals.unary [m package] : ? (byte,short,char,java.lang.Integer) returns int throws [] sig Conditionals#unary(BSCLjava/lang/Integer;)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [b, s, c, boxed] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @64:3 : int +TOKEN @64:3 +IDENTIFIER @64:7 id unary Conditionals.unary [m package] : ? (byte,short,char,java.lang.Integer) returns int throws [] sig Conditionals#unary(BSCLjava/lang/Integer;)I : int +TOKEN @64:7 +TOKEN @64:12 +VARIABLE @64:13 var unary.b [v package] : byte + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal false constant null owner unary Conditionals#unary(BSCLjava/lang/Integer;)I [package] returns int parameters 4 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PRIMITIVE_TYPE @64:13 : byte +TOKEN @64:13 +IDENTIFIER @64:18 id b unary.b [v package] : byte : byte +TOKEN @64:18 +TOKEN @64:19 +VARIABLE @64:21 var unary.s [v package] : short + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal false constant null owner unary Conditionals#unary(BSCLjava/lang/Integer;)I [package] returns int parameters 4 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PRIMITIVE_TYPE @64:21 : short +TOKEN @64:21 +IDENTIFIER @64:27 id s unary.s [v package] : short : short +TOKEN @64:27 +TOKEN @64:28 +VARIABLE @64:30 var unary.c [v package] : char + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner unary Conditionals#unary(BSCLjava/lang/Integer;)I [package] returns int parameters 4 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PRIMITIVE_TYPE @64:30 : char +TOKEN @64:30 +IDENTIFIER @64:35 id c unary.c [v package] : char : char +TOKEN @64:35 +TOKEN @64:36 +VARIABLE @64:38 var unary.boxed [v package] : java.lang.Integer + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter true effectivelyFinal true constant null owner unary Conditionals#unary(BSCLjava/lang/Integer;)I [package] returns int parameters 4 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @64:38 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @64:38 +IDENTIFIER @64:46 id boxed unary.boxed [v package] : java.lang.Integer : java.lang.Integer +TOKEN @64:46 +TOKEN @64:51 +BLOCK @64:53 +TOKEN @64:53 +VARIABLE @65:5 var unary.x [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner unary Conditionals#unary(BSCLjava/lang/Integer;)I [package] returns int parameters 4 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PRIMITIVE_TYPE @65:5 : int +TOKEN @65:5 +IDENTIFIER @65:9 id x unary.x [v package] : int : int +TOKEN @65:9 +TOKEN @65:11 +PLUS @65:13 : int +PLUS @65:13 : int +UNARY_MINUS @65:13 : int +TOKEN @65:13 +IDENTIFIER @65:14 id b unary.b [v package] : byte : byte +TOKEN @65:14 +TOKEN @65:16 +BITWISE_COMPLEMENT @65:18 : int +TOKEN @65:18 +IDENTIFIER @65:19 id s unary.s [v package] : short : short +TOKEN @65:19 +TOKEN @65:21 +UNARY_PLUS @65:23 : int +TOKEN @65:23 +IDENTIFIER @65:24 id c unary.c [v package] : char : char +TOKEN @65:24 +TOKEN @65:25 +VARIABLE @66:5 var unary.y [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner unary Conditionals#unary(BSCLjava/lang/Integer;)I [package] returns int parameters 4 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PRIMITIVE_TYPE @66:5 : int +TOKEN @66:5 +IDENTIFIER @66:9 id y unary.y [v package] : int : int +TOKEN @66:9 +TOKEN @66:11 +UNARY_MINUS @66:13 : int +TOKEN @66:13 +IDENTIFIER @66:14 id boxed unary.boxed [v package] : java.lang.Integer : java.lang.Integer +TOKEN @66:14 +TOKEN @66:19 +VARIABLE @67:5 var unary.z [v package] : long + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Conditionals flags [package] local true parameter false effectivelyFinal true constant null owner unary Conditionals#unary(BSCLjava/lang/Integer;)I [package] returns int parameters 4 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Conditionals type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PRIMITIVE_TYPE @67:5 : long +TOKEN @67:5 +IDENTIFIER @67:10 id z unary.z [v package] : long : long +TOKEN @67:10 +TOKEN @67:12 +UNARY_MINUS @67:14 : long = -1 +TOKEN @67:14 +LONG_LITERAL @67:15 : long = 1 +TOKEN @67:15 +TOKEN @67:17 +RETURN_STATEMENT @68:5 +TOKEN @68:5 +PLUS @68:12 : int +PLUS @68:12 : int +PLUS @68:12 : int +PLUS @68:12 : int +IDENTIFIER @68:12 id x unary.x [v package] : int : int +TOKEN @68:12 +TOKEN @68:14 +IDENTIFIER @68:16 id y unary.y [v package] : int : int +TOKEN @68:16 +TOKEN @68:18 +TYPE_CAST @68:20 : int +TOKEN @68:20 +PRIMITIVE_TYPE @68:21 : int +TOKEN @68:21 +LIST +TOKEN @68:24 +IDENTIFIER @68:26 id z unary.z [v package] : long : long +TOKEN @68:26 +TOKEN @68:28 +PARENTHESIZED_EXPRESSION @68:30 : byte +TOKEN @68:30 +POSTFIX_INCREMENT @68:31 : byte +IDENTIFIER @68:31 id b unary.b [v package] : byte : byte +TOKEN @68:31 +TOKEN @68:32 +TOKEN @68:34 +TOKEN @68:36 +PARENTHESIZED_EXPRESSION @68:38 : short +TOKEN @68:38 +PREFIX_DECREMENT @68:39 : short +TOKEN @68:39 +IDENTIFIER @68:41 id s unary.s [v package] : short : short +TOKEN @68:41 +TOKEN @68:42 +TOKEN @68:43 +TOKEN @69:3 +TOKEN @70:1 +TOKEN @71:1 +WARNING REDUNDANT_CAST TYPE_CAST @43:27 Unnecessary cast from Object to Serializable & Comparable diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Conditionals.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Conditionals.java new file mode 100644 index 00000000000..cfae1972333 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Conditionals.java @@ -0,0 +1,70 @@ +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import java.util.function.Supplier; + +class Conditionals { + + T value; + + Object mix(boolean flag, int i, long l, Integer boxed, Long boxedLong, byte b, short s, char c, double d, String text, T t, Number n, + ArrayList arrayList, LinkedList linkedList) { + long a1 = flag ? i : l; + int a2 = flag ? i : boxed; + Object a3 = flag ? boxed : boxedLong; + short a4 = flag ? b : s; + char a5 = flag ? c : 1; + int a6 = flag ? 1 : c; + double a7 = flag ? d : i; + Integer a8 = flag ? null : i; + Integer a9 = flag ? i : null; + String a10 = flag ? null : text; + String a11 = flag ? text : null; + Number a12 = flag ? t : n; + Number a13 = flag ? n : t; + List a14 = flag ? arrayList : linkedList; + Collection a15 = flag ? arrayList : List.of(); + Object a16 = flag ? text : i; + boolean a17 = flag ? flag : !flag; + Boolean a18 = flag ? Boolean.TRUE : flag; + Object a19 = flag ? b : c; + T a20 = flag ? t : value; + List a21 = flag ? new ArrayList<>() : new LinkedList<>(); + Supplier a22 = flag ? () -> "a" : String::new; + return a1 + a2 + String.valueOf(a3) + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + a14 + a15 + a16 + a17 + a18 + a19 + a20 + a21 + a22; + } + + Object casts(Object o) { + Runnable task = (Runnable & Serializable) () -> System.out.println("task"); + Comparator comparator = (Comparator & Serializable) (x, y) -> x.length() - y.length(); + Object intersection = (Serializable & Comparable) o; + return switch (o.hashCode()) { + case 0 -> task; + case 1 -> comparator; + default -> intersection; + }; + } + + Number switchTarget(int k, T t) { + Number result = switch (k) { + case 0 -> 1; + case 1 -> 2L; + default -> t; + }; + List numbers = switch (k) { + case 0 -> List.of(1); + default -> new ArrayList(); + }; + return result.intValue() + numbers.size(); + } + + int unary(byte b, short s, char c, Integer boxed) { + int x = -b + ~s + +c; + int y = -boxed; + long z = -1L; + return x + y + (int) z + (b++) + (--s); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Conditionals.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Conditionals.textproto.gz new file mode 100644 index 00000000000..027d71e19c5 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Conditionals.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Declarations.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Declarations.expected.txt new file mode 100644 index 00000000000..716a0c2f521 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Declarations.expected.txt @@ -0,0 +1,693 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id io unknown : ? +TOKEN @1:13 +TOKEN @1:15 +IDENTIFIER @1:16 id Serializable unknown : ? +TOKEN @1:16 +TOKEN @1:28 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id util unknown : ? +TOKEN @2:13 +TOKEN @2:17 +IDENTIFIER @2:18 id List unknown : ? +TOKEN @2:18 +TOKEN @2:22 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id util unknown : ? +TOKEN @3:13 +TOKEN @3:17 +IDENTIFIER @3:18 id Map unknown : ? +TOKEN @3:18 +TOKEN @3:21 +IMPORT @4:1 +TOKEN @4:1 +TOKEN @4:8 +MEMBER_SELECT @4:15 : ? +MEMBER_SELECT @4:15 : ? +MEMBER_SELECT @4:15 : ? +IDENTIFIER @4:15 id java unknown : ? +TOKEN @4:15 +TOKEN @4:19 +IDENTIFIER @4:20 id util unknown : ? +TOKEN @4:20 +TOKEN @4:24 +IDENTIFIER @4:25 id Collections unknown : ? +TOKEN @4:25 +TOKEN @4:36 +IDENTIFIER @4:37 id emptyList unknown : ? +TOKEN @4:37 +TOKEN @4:46 +CLASS @6:1 class .Declarations [t abstract public] : Declarations super java.lang.Object interfaces [java.io.Serializable, java.lang.Comparable>] + details declared true usages 3 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [abstract, public] members [, , Circle, Level, Listener, Marker, Nested, Point, Shape, Square, compareTo, convert, counter, current, grid, index, legacy, names, nativeCall, run, serialVersionUID, values] lookupToString 0 outermost Declarations annotation false subtypeOf [java.lang.Object, java.io.Serializable, java.lang.Comparable] superTypes [java.io.Serializable, java.lang.Comparable>, java.lang.Object] numerical false wrapper false raw true declaring Declarations +MODIFIERS @6:1 +TOKEN @6:1 +TOKEN @6:8 +TOKEN @6:17 +IDENTIFIER @6:23 id Declarations .Declarations [t abstract public] : Declarations : Declarations +TOKEN @6:23 +TYPE_PARAMETERS @6:35 +TOKEN @6:35 +TYPE_PARAMETER @6:36 +IDENTIFIER @6:36 id T Declarations.T [t package] : T erasure java.lang.Comparable : T erasure java.lang.Comparable +TOKEN @6:36 +TOKEN @6:38 +LIST @6:46 +PARAMETERIZED_TYPE @6:46 : java.lang.Comparable +IDENTIFIER @6:46 id Comparable java.lang.Comparable [t public interface] : java.lang.Comparable : java.lang.Comparable +TOKEN @6:46 +TYPE_ARGUMENTS @6:56 +TOKEN @6:56 +IDENTIFIER @6:57 id T Declarations.T [t package] : T erasure java.lang.Comparable : T erasure java.lang.Comparable +TOKEN @6:57 +TOKEN @6:58 +TOKEN @6:59 +TOKEN @6:61 +LIST @6:72 +IDENTIFIER @6:72 id Serializable java.io.Serializable [t public interface] : java.io.Serializable : java.io.Serializable +TOKEN @6:72 +TOKEN @6:84 +PARAMETERIZED_TYPE @6:86 : java.lang.Comparable +IDENTIFIER @6:86 id Comparable java.lang.Comparable [t public interface] : java.lang.Comparable : java.lang.Comparable +TOKEN @6:86 +TYPE_ARGUMENTS @6:96 +TOKEN @6:96 +PARAMETERIZED_TYPE @6:97 : Declarations +IDENTIFIER @6:97 id Declarations .Declarations [t abstract public] : Declarations : Declarations +TOKEN @6:97 +TYPE_ARGUMENTS @6:109 +TOKEN @6:109 +IDENTIFIER @6:110 id T Declarations.T [t package] : T erasure java.lang.Comparable : T erasure java.lang.Comparable +TOKEN @6:110 +TOKEN @6:111 +TOKEN @6:112 +LIST +TOKEN @6:114 +VARIABLE @8:3 var Declarations.serialVersionUID [v static final private] : long + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [static, final, private] local false parameter false effectivelyFinal true constant 1 +MODIFIERS @8:3 +TOKEN @8:3 +TOKEN @8:11 +TOKEN @8:18 +PRIMITIVE_TYPE @8:24 : long +TOKEN @8:24 +IDENTIFIER @8:29 id serialVersionUID Declarations.serialVersionUID [v static final private] : long : long = 1 +TOKEN @8:29 +TOKEN @8:46 +LONG_LITERAL @8:48 : long = 1 +TOKEN @8:48 +TOKEN @8:50 +VARIABLE @9:3 var Declarations.counter [v protected volatile] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [protected, volatile] local false parameter false effectivelyFinal false constant null +MODIFIERS @9:3 +TOKEN @9:3 +TOKEN @9:13 +TOKEN @9:23 +PRIMITIVE_TYPE @9:32 : int +TOKEN @9:32 +IDENTIFIER @9:36 id counter Declarations.counter [v protected volatile] : int : int +TOKEN @9:36 +TOKEN @9:43 +VARIABLE @10:3 var Declarations.names [v package] : java.util.List + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Declarations flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @10:3 : java.util.List +IDENTIFIER @10:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @10:3 +TYPE_ARGUMENTS @10:7 +TOKEN @10:7 +IDENTIFIER @10:8 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @10:8 +TOKEN @10:14 +IDENTIFIER @10:16 id names Declarations.names [v package] : java.util.List : java.util.List +TOKEN @10:16 +TOKEN @10:21 +VARIABLE @11:3 var Declarations.index [v package] : java.util.Map> + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Declarations flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @11:3 : java.util.Map> +IDENTIFIER @11:3 id Map java.util.Map [t public interface] : java.util.Map> : java.util.Map> +TOKEN @11:3 +TYPE_ARGUMENTS @11:6 +TOKEN @11:6 +IDENTIFIER @11:7 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @11:7 +TOKEN @11:13 +PARAMETERIZED_TYPE @11:15 : java.util.List +IDENTIFIER @11:15 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @11:15 +TYPE_ARGUMENTS @11:19 +TOKEN @11:19 +IDENTIFIER @11:20 id T Declarations.T [t package] : T erasure java.lang.Comparable : T erasure java.lang.Comparable +TOKEN @11:20 +TOKEN @11:21 +TOKEN @11:22 +IDENTIFIER @11:24 id index Declarations.index [v package] : java.util.Map> : java.util.Map> +TOKEN @11:24 +TOKEN @11:29 +VARIABLE @12:3 var Declarations.values [v package] : int[] + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +ARRAY_TYPE @12:3 : int[] +PRIMITIVE_TYPE @12:3 : int +TOKEN @12:3 +TOKEN @12:6 +TOKEN @12:7 +IDENTIFIER @12:9 id values Declarations.values [v package] : int[] : int[] +TOKEN @12:9 +TOKEN @12:15 +VARIABLE @13:3 var Declarations.grid [v package] : java.lang.String[][] + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +ARRAY_TYPE @13:3 : java.lang.String[][] +ARRAY_TYPE @13:3 : java.lang.String[] +IDENTIFIER @13:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @13:3 +TOKEN @13:9 +TOKEN @13:10 +TOKEN @13:11 +TOKEN @13:12 +IDENTIFIER @13:14 id grid Declarations.grid [v package] : java.lang.String[][] : java.lang.String[][] +TOKEN @13:14 +TOKEN @13:18 +VARIABLE @14:3 var Declarations.current [v package] : T erasure java.lang.Comparable + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @14:3 id T Declarations.T [t package] : T erasure java.lang.Comparable : T erasure java.lang.Comparable +TOKEN @14:3 +IDENTIFIER @14:5 id current Declarations.current [v package] : T erasure java.lang.Comparable : T erasure java.lang.Comparable +TOKEN @14:5 +TOKEN @14:12 +CONSTRUCTOR @16:3 method Declarations. [m public] : ? () returns void throws [] sig Declarations#()V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @16:3 +TOKEN @16:3 +TYPE_PARAMETERS +IDENTIFIER @16:10 id Declarations Declarations. [m public] : ? () returns void throws [] sig Declarations#()V : void +TOKEN @16:10 +TOKEN @16:22 +TOKEN @16:23 +BLOCK @16:25 +TOKEN @16:25 +TOKEN @17:3 +CONSTRUCTOR @19:3 method Declarations. [m protected] : ? (T erasure java.lang.Comparable) returns void throws [] sig Declarations#(Ljava/lang/Comparable;)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [protected] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [first] parameterMetadata [] +MODIFIERS @19:3 +TOKEN @19:3 +TYPE_PARAMETERS +IDENTIFIER @19:13 id Declarations Declarations. [m protected] : ? (T erasure java.lang.Comparable) returns void throws [] sig Declarations#(Ljava/lang/Comparable;)V : void +TOKEN @19:13 +TOKEN @19:25 +VARIABLE @19:26 var .first [v package] : T erasure java.lang.Comparable + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [package] local true parameter true effectivelyFinal true constant null owner Declarations#(Ljava/lang/Comparable;)V [protected] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Declarations type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @19:26 id T Declarations.T [t package] : T erasure java.lang.Comparable : T erasure java.lang.Comparable +TOKEN @19:26 +IDENTIFIER @19:28 id first .first [v package] : T erasure java.lang.Comparable : T erasure java.lang.Comparable +TOKEN @19:28 +TOKEN @19:33 +BLOCK @19:35 +TOKEN @19:35 +TOKEN @20:3 +METHOD @22:3 method Declarations.run [m abstract public] : ? () returns void throws [java.lang.Exception] sig Declarations#run()V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @22:3 +TOKEN @22:3 +TOKEN @22:10 +TYPE_PARAMETERS +PRIMITIVE_TYPE @22:19 : void +TOKEN @22:19 +IDENTIFIER @22:24 id run Declarations.run [m abstract public] : ? () returns void throws [java.lang.Exception] sig Declarations#run()V : void +TOKEN @22:24 +TOKEN @22:27 +TOKEN @22:28 +TOKEN @22:30 +LIST @22:37 +IDENTIFIER @22:37 id Exception java.lang.Exception [t public] : java.lang.Exception : java.lang.Exception +TOKEN @22:37 +TOKEN @22:46 +METHOD @24:3 method Declarations.convert [m final public] : ? (T erasure java.lang.Comparable,java.lang.Class) returns R erasure java.lang.Object throws [] sig Declarations#convert(Ljava/lang/Comparable;Ljava/lang/Class;)Ljava/lang/Object; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [final, public] overridden [] overridable false generic true default false synchronized true varargs false native false parameters [input, target] parameterMetadata [] +MODIFIERS @24:3 +TOKEN @24:3 +TOKEN @24:10 +TOKEN @24:16 +TYPE_PARAMETERS @24:29 +TOKEN @24:29 +TYPE_PARAMETER @24:30 +IDENTIFIER @24:30 id R convert.R [t package] : R erasure java.lang.Object : R erasure java.lang.Object +TOKEN @24:30 +TOKEN @24:31 +IDENTIFIER @24:33 id R convert.R [t package] : R erasure java.lang.Object : R erasure java.lang.Object +TOKEN @24:33 +IDENTIFIER @24:35 id convert Declarations.convert [m final public] : ? (T erasure java.lang.Comparable,java.lang.Class) returns R erasure java.lang.Object throws [] sig Declarations#convert(Ljava/lang/Comparable;Ljava/lang/Class;)Ljava/lang/Object; : R erasure java.lang.Object +TOKEN @24:35 +TOKEN @24:42 +VARIABLE @24:43 var convert.input [v package] : T erasure java.lang.Comparable + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [package] local true parameter true effectivelyFinal true constant null owner convert Declarations#convert(Ljava/lang/Comparable;Ljava/lang/Class;)Ljava/lang/Object; [final, public] returns R erasure java.lang.Object parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Declarations type true kinds truefalsefalse other falsetruefalsefalsefalsetrue2falsefalse +MODIFIERS +IDENTIFIER @24:43 id T Declarations.T [t package] : T erasure java.lang.Comparable : T erasure java.lang.Comparable +TOKEN @24:43 +IDENTIFIER @24:45 id input convert.input [v package] : T erasure java.lang.Comparable : T erasure java.lang.Comparable +TOKEN @24:45 +TOKEN @24:50 +VARIABLE @24:52 var convert.target [v package] : java.lang.Class + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Declarations flags [package] local true parameter true effectivelyFinal true constant null owner convert Declarations#convert(Ljava/lang/Comparable;Ljava/lang/Class;)Ljava/lang/Object; [final, public] returns R erasure java.lang.Object parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Declarations type true kinds truefalsefalse other falsetruefalsefalsefalsetrue2falsefalse +MODIFIERS +PARAMETERIZED_TYPE @24:52 : java.lang.Class +IDENTIFIER @24:52 id Class java.lang.Class [t final public] : java.lang.Class : java.lang.Class +TOKEN @24:52 +TYPE_ARGUMENTS @24:57 +TOKEN @24:57 +IDENTIFIER @24:58 id R convert.R [t package] : R erasure java.lang.Object : R erasure java.lang.Object +TOKEN @24:58 +TOKEN @24:59 +IDENTIFIER @24:61 id target convert.target [v package] : java.lang.Class : java.lang.Class +TOKEN @24:61 +TOKEN @24:67 +BLOCK @24:69 +TOKEN @24:69 +RETURN_STATEMENT @25:5 +TOKEN @25:5 +NULL_LITERAL @25:12 : +TOKEN @25:12 +TOKEN @25:16 +TOKEN @26:3 +METHOD @28:3 method Declarations.nativeCall [m static package] : ? () returns void throws [] sig Declarations#nativeCall()V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [static, package] overridden [] overridable false generic false default false synchronized false varargs false native true parameters [] parameterMetadata [] +MODIFIERS @28:3 +TOKEN @28:3 +TOKEN @28:10 +TYPE_PARAMETERS +PRIMITIVE_TYPE @28:17 : void +TOKEN @28:17 +IDENTIFIER @28:22 id nativeCall Declarations.nativeCall [m static package] : ? () returns void throws [] sig Declarations#nativeCall()V : void +TOKEN @28:22 +TOKEN @28:32 +TOKEN @28:33 +TOKEN @28:34 +METHOD @30:3 method Declarations.legacy [m package deprecated] : ? @java.lang.Deprecated (java.lang.String[]) returns void throws [] sig Declarations#legacy([Ljava/lang/String;)V overrides false + details declared true usages 0 metadata [java.lang.Deprecated()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Deprecated tree true values 0 annotated true] typeArguments [] enclosing Declarations flags [package, deprecated] overridden [] overridable true generic false default false synchronized false varargs true native false parameters [args] parameterMetadata [] +MODIFIERS @30:3 +ANNOTATION @30:3 : java.lang.Deprecated +TOKEN @30:3 +IDENTIFIER @30:4 id Deprecated java.lang.Deprecated [t public interface] : java.lang.Deprecated @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Deprecated +TOKEN @30:4 +ARGUMENTS +TYPE_PARAMETERS +PRIMITIVE_TYPE @31:3 : void +TOKEN @31:3 +IDENTIFIER @31:8 id legacy Declarations.legacy [m package deprecated] : ? @java.lang.Deprecated (java.lang.String[]) returns void throws [] sig Declarations#legacy([Ljava/lang/String;)V : void +TOKEN @31:8 +TOKEN @31:14 +VARIABLE @31:15 var legacy.args [v package] : java.lang.String[] + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [package] local true parameter true effectivelyFinal true constant null owner legacy Declarations#legacy([Ljava/lang/String;)V [package, deprecated] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Declarations type true kinds truefalsefalse other falsefalsetruefalsetruefalse1falsefalse +MODIFIERS +ARRAY_TYPE @31:15 : java.lang.String[] +IDENTIFIER @31:15 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @31:15 +TOKEN @31:21 +IDENTIFIER @31:25 id args legacy.args [v package] : java.lang.String[] : java.lang.String[] +TOKEN @31:25 +TOKEN @31:29 +BLOCK @31:31 +TOKEN @31:31 +TOKEN @32:3 +METHOD @34:3 method Declarations.compareTo [m public] : ? @java.lang.Override (Declarations) returns int throws [] sig Declarations#compareTo(LDeclarations;)I overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Declarations flags [public] overridden [Comparable.compareTo[]] overridable true generic false default false synchronized false varargs false native false parameters [other] parameterMetadata [] +MODIFIERS @34:3 +ANNOTATION @34:3 : java.lang.Override +TOKEN @34:3 +IDENTIFIER @34:4 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @34:4 +ARGUMENTS +TOKEN @35:3 +TYPE_PARAMETERS +PRIMITIVE_TYPE @35:10 : int +TOKEN @35:10 +IDENTIFIER @35:14 id compareTo Declarations.compareTo [m public] : ? @java.lang.Override (Declarations) returns int throws [] sig Declarations#compareTo(LDeclarations;)I : int +TOKEN @35:14 +TOKEN @35:23 +VARIABLE @35:24 var compareTo.other [v package] : Declarations + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Declarations flags [package] local true parameter true effectivelyFinal true constant null owner compareTo Declarations#compareTo(LDeclarations;)I [public] returns int parameters 1 thrown 0 overridden 1 declared true usages 0 metadata 1 enclosing Declarations type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @35:24 : Declarations +IDENTIFIER @35:24 id Declarations .Declarations [t abstract public] : Declarations : Declarations +TOKEN @35:24 +TYPE_ARGUMENTS @35:36 +TOKEN @35:36 +IDENTIFIER @35:37 id T Declarations.T [t package] : T erasure java.lang.Comparable : T erasure java.lang.Comparable +TOKEN @35:37 +TOKEN @35:38 +IDENTIFIER @35:40 id other compareTo.other [v package] : Declarations : Declarations +TOKEN @35:40 +TOKEN @35:45 +BLOCK @35:47 +TOKEN @35:47 +RETURN_STATEMENT @36:5 +TOKEN @36:5 +INT_LITERAL @36:12 : int = 0 +TOKEN @36:12 +TOKEN @36:13 +TOKEN @37:3 +INTERFACE @39:3 class Declarations.Listener [t static package interface] : Declarations$Listener super java.lang.Object interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [static, package, interface] members [close, none, onEvent] lookupToString 0 outermost Declarations annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Listener +MODIFIERS +TOKEN @39:3 +IDENTIFIER @39:13 id Listener Declarations.Listener [t static package interface] : Declarations$Listener : Declarations$Listener +TOKEN @39:13 +TYPE_PARAMETERS +LIST +LIST +TOKEN @39:22 +METHOD @40:5 method Listener.onEvent [m abstract public] : ? (java.lang.String) returns void throws [] sig Declarations$Listener#onEvent(Ljava/lang/String;)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Listener flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [event] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @40:5 : void +TOKEN @40:5 +IDENTIFIER @40:10 id onEvent Listener.onEvent [m abstract public] : ? (java.lang.String) returns void throws [] sig Declarations$Listener#onEvent(Ljava/lang/String;)V : void +TOKEN @40:10 +TOKEN @40:17 +VARIABLE @40:18 var onEvent.event [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Listener flags [package] local true parameter true effectivelyFinal true constant null owner onEvent Declarations$Listener#onEvent(Ljava/lang/String;)V [abstract, public] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Listener type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @40:18 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @40:18 +IDENTIFIER @40:25 id event onEvent.event [v package] : java.lang.String : java.lang.String +TOKEN @40:25 +TOKEN @40:30 +TOKEN @40:31 +METHOD @42:5 method Listener.close [m public] : ? () returns void throws [] sig Declarations$Listener#close()V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Listener flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @42:5 +TOKEN @42:5 +TYPE_PARAMETERS +PRIMITIVE_TYPE @42:13 : void +TOKEN @42:13 +IDENTIFIER @42:18 id close Listener.close [m public] : ? () returns void throws [] sig Declarations$Listener#close()V : void +TOKEN @42:18 +TOKEN @42:23 +TOKEN @42:24 +BLOCK @42:26 +TOKEN @42:26 +TOKEN @43:5 +METHOD @45:5 method Listener.none [m static public] : ? () returns Declarations$Listener throws [] sig Declarations$Listener#none()LDeclarations$Listener; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Listener flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @45:5 +TOKEN @45:5 +TYPE_PARAMETERS +IDENTIFIER @45:12 id Listener Declarations.Listener [t static package interface] : Declarations$Listener : Declarations$Listener +TOKEN @45:12 +IDENTIFIER @45:21 id none Listener.none [m static public] : ? () returns Declarations$Listener throws [] sig Declarations$Listener#none()LDeclarations$Listener; : Declarations$Listener +TOKEN @45:21 +TOKEN @45:25 +TOKEN @45:26 +BLOCK @45:28 +TOKEN @45:28 +RETURN_STATEMENT @46:7 +TOKEN @46:7 +NULL_LITERAL @46:14 : +TOKEN @46:14 +TOKEN @46:18 +TOKEN @47:5 +TOKEN @48:3 +ENUM @50:3 class Declarations.Level [t static final package enum] : Declarations$Level super java.lang.Enum interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [static, final, package, enum] members [, HIGH, LOW, MEDIUM, next, valueOf, values] lookupToString 0 outermost Declarations annotation false subtypeOf [java.lang.Object, java.io.Serializable, java.lang.Comparable] superTypes [java.io.Serializable, java.lang.Comparable, java.lang.Enum, java.lang.Object, java.lang.constant.Constable] numerical false wrapper false raw false declaring Level +MODIFIERS +TOKEN @50:3 +IDENTIFIER @50:8 id Level Declarations.Level [t static final package enum] : Declarations$Level : Declarations$Level +TOKEN @50:8 +TYPE_PARAMETERS +LIST +LIST +TOKEN @50:14 +ENUM_CONSTANT @51:5 var Level.LOW [v static final public enum] : Declarations$Level + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Level flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @51:5 new Level. [m private] : ? () returns void throws [] sig Declarations$Level#(Ljava/lang/String;I)V : ? + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Level flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @51:5 id LOW Level. [m private] : ? () returns void throws [] sig Declarations$Level#(Ljava/lang/String;I)V : Declarations$Level +TOKEN @51:5 +ARGUMENTS +TOKEN @51:8 +ENUM_CONSTANT @51:10 var Level.MEDIUM [v static final public enum] : Declarations$Level + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Level flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @51:10 new Level. [m private] : ? () returns void throws [] sig Declarations$Level#(Ljava/lang/String;I)V : ? + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Level flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @51:10 id MEDIUM Level. [m private] : ? () returns void throws [] sig Declarations$Level#(Ljava/lang/String;I)V : Declarations$Level +TOKEN @51:10 +ARGUMENTS +TOKEN @51:16 +ENUM_CONSTANT @51:18 var Level.HIGH [v static final public enum] : Declarations$Level + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Level flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @51:18 new Level. [m private] : ? () returns void throws [] sig Declarations$Level#(Ljava/lang/String;I)V : ? + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Level flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @51:18 id HIGH Level. [m private] : ? () returns void throws [] sig Declarations$Level#(Ljava/lang/String;I)V : Declarations$Level +TOKEN @51:18 +ARGUMENTS +TOKEN @51:22 +METHOD @53:5 method Level.next [m package] : ? () returns Declarations$Level throws [] sig Declarations$Level#next()LDeclarations$Level; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Level flags [package] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @53:5 id Level Declarations.Level [t static final package enum] : Declarations$Level : Declarations$Level +TOKEN @53:5 +IDENTIFIER @53:11 id next Level.next [m package] : ? () returns Declarations$Level throws [] sig Declarations$Level#next()LDeclarations$Level; : Declarations$Level +TOKEN @53:11 +TOKEN @53:15 +TOKEN @53:16 +BLOCK @53:18 +TOKEN @53:18 +RETURN_STATEMENT @54:7 +TOKEN @54:7 +NULL_LITERAL @54:14 : +TOKEN @54:14 +TOKEN @54:18 +TOKEN @55:5 +TOKEN @56:3 +RECORD @58:3 class Declarations.Point [t static final package] : Declarations$Point super java.lang.Record interfaces [java.io.Serializable] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [static, final, package] members [, origin, x, x, y, y] lookupToString 0 outermost Declarations annotation false subtypeOf [java.lang.Object, java.io.Serializable] superTypes [java.io.Serializable, java.lang.Object, java.lang.Record] numerical false wrapper false raw false declaring Point +MODIFIERS +TOKEN @58:3 +IDENTIFIER @58:10 id Point Declarations.Point [t static final package] : Declarations$Point : Declarations$Point +TOKEN @58:10 +TYPE_PARAMETERS +TOKEN @58:15 +VARIABLE @58:16 var Point.x [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Point flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @58:16 : int +TOKEN @58:16 +IDENTIFIER @58:20 id x Point.x [v package] : int : int +TOKEN @58:20 +TOKEN @58:21 +VARIABLE @58:23 var Point.y [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Point flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @58:23 : int +TOKEN @58:23 +IDENTIFIER @58:27 id y Point.y [v package] : int : int +TOKEN @58:27 +TOKEN @58:28 +TOKEN @58:30 +LIST @58:41 +IDENTIFIER @58:41 id Serializable java.io.Serializable [t public interface] : java.io.Serializable : java.io.Serializable +TOKEN @58:41 +LIST +TOKEN @58:54 +CONSTRUCTOR @59:5 method Point. [m package] : ? (int,int) returns void throws [] sig Declarations$Point#(II)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Point flags [package] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @59:5 id Point Point. [m package] : ? (int,int) returns void throws [] sig Declarations$Point#(II)V : void +TOKEN @59:5 +BLOCK @59:11 +TOKEN @59:11 +TOKEN @60:5 +METHOD @62:5 method Point.origin [m static package] : ? () returns Declarations$Point throws [] sig Declarations$Point#origin()LDeclarations$Point; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Point flags [static, package] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @62:5 +TOKEN @62:5 +TYPE_PARAMETERS +IDENTIFIER @62:12 id Point Declarations.Point [t static final package] : Declarations$Point : Declarations$Point +TOKEN @62:12 +IDENTIFIER @62:18 id origin Point.origin [m static package] : ? () returns Declarations$Point throws [] sig Declarations$Point#origin()LDeclarations$Point; : Declarations$Point +TOKEN @62:18 +TOKEN @62:24 +TOKEN @62:25 +BLOCK @62:27 +TOKEN @62:27 +RETURN_STATEMENT @63:7 +TOKEN @63:7 +NULL_LITERAL @63:14 : +TOKEN @63:14 +TOKEN @63:18 +TOKEN @64:5 +TOKEN @65:3 +ANNOTATION_TYPE @67:3 class Declarations.Marker [t static package interface] : Declarations$Marker super java.lang.Object interfaces [java.lang.annotation.Annotation] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [static, package, interface] members [priority, value] lookupToString 0 outermost Declarations annotation true subtypeOf [java.lang.Object, java.lang.annotation.Annotation] superTypes [java.lang.Object, java.lang.annotation.Annotation] numerical false wrapper false raw false declaring Marker +MODIFIERS +TOKEN @67:3 +TOKEN @67:4 +IDENTIFIER @67:14 id Marker Declarations.Marker [t static package interface] : Declarations$Marker : Declarations$Marker +TOKEN @67:14 +TYPE_PARAMETERS +LIST +LIST +TOKEN @67:21 +METHOD @68:5 method Marker.value [m abstract public] : ? () returns java.lang.String throws [] sig Declarations$Marker#value()Ljava/lang/String; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Marker flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @68:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @68:5 +IDENTIFIER @68:12 id value Marker.value [m abstract public] : ? () returns java.lang.String throws [] sig Declarations$Marker#value()Ljava/lang/String; : java.lang.String +TOKEN @68:12 +TOKEN @68:17 +TOKEN @68:18 +TOKEN @68:20 +STRING_LITERAL @68:28 : java.lang.String = +TOKEN @68:28 +TOKEN @68:30 +METHOD @70:5 method Marker.priority [m abstract public] : ? () returns int throws [] sig Declarations$Marker#priority()I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Marker flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @70:5 : int +TOKEN @70:5 +IDENTIFIER @70:9 id priority Marker.priority [m abstract public] : ? () returns int throws [] sig Declarations$Marker#priority()I : int +TOKEN @70:9 +TOKEN @70:17 +TOKEN @70:18 +TOKEN @70:20 +INT_LITERAL @70:28 : int = 0 +TOKEN @70:28 +TOKEN @70:29 +TOKEN @71:3 +CLASS @73:3 class Declarations.Nested [t static package] : Declarations$Nested super Declarations interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [static, package] members [, , run] lookupToString 0 outermost Declarations annotation false subtypeOf [java.lang.Object, java.io.Serializable, java.lang.Comparable] superTypes [Declarations, java.io.Serializable, java.lang.Comparable>, java.lang.Object] numerical false wrapper false raw false declaring Nested +MODIFIERS @73:3 +TOKEN @73:3 +TOKEN @73:10 +IDENTIFIER @73:16 id Nested Declarations.Nested [t static package] : Declarations$Nested : Declarations$Nested +TOKEN @73:16 +TYPE_PARAMETERS +TOKEN @73:23 +PARAMETERIZED_TYPE @73:31 : Declarations +IDENTIFIER @73:31 id Declarations .Declarations [t abstract public] : Declarations : Declarations +TOKEN @73:31 +TYPE_ARGUMENTS @73:43 +TOKEN @73:43 +IDENTIFIER @73:44 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @73:44 +TOKEN @73:50 +LIST +LIST +TOKEN @73:52 +STATIC_INITIALIZER @74:5 +TOKEN @74:5 +TOKEN @74:12 +TOKEN @75:5 +INITIALIZER @77:5 +TOKEN @77:5 +TOKEN @78:5 +METHOD @80:5 method Nested.run [m public] : ? @java.lang.Override () returns void throws [] sig Declarations$Nested#run()V overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Nested flags [public] overridden [Declarations.run[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @80:5 +ANNOTATION @80:5 : java.lang.Override +TOKEN @80:5 +IDENTIFIER @80:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @80:6 +ARGUMENTS +TOKEN @81:5 +TYPE_PARAMETERS +PRIMITIVE_TYPE @81:12 : void +TOKEN @81:12 +IDENTIFIER @81:17 id run Nested.run [m public] : ? @java.lang.Override () returns void throws [] sig Declarations$Nested#run()V : void +TOKEN @81:17 +TOKEN @81:20 +TOKEN @81:21 +BLOCK @81:23 +TOKEN @81:23 +TOKEN @82:5 +TOKEN @83:3 +INTERFACE @85:3 class Declarations.Shape [t static package interface] : Declarations$Shape super java.lang.Object interfaces [] + details declared true usages 2 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [static, package, interface] members [] lookupToString 0 outermost Declarations annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Shape +MODIFIERS @85:3 +TOKEN @85:3 +TOKEN @85:10 +IDENTIFIER @85:20 id Shape Declarations.Shape [t static package interface] : Declarations$Shape : Declarations$Shape +TOKEN @85:20 +TYPE_PARAMETERS +LIST +LIST @85:34 +IDENTIFIER @85:34 id Circle Declarations.Circle [t static final package] : Declarations$Circle : Declarations$Circle +TOKEN @85:34 +TOKEN @85:40 +IDENTIFIER @85:42 id Square Declarations.Square [t static final package] : Declarations$Square : Declarations$Square +TOKEN @85:42 +TOKEN @85:49 +TOKEN @86:3 +RECORD @88:3 class Declarations.Circle [t static final package] : Declarations$Circle super java.lang.Record interfaces [Declarations$Shape] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [static, final, package] members [, radius, radius] lookupToString 0 outermost Declarations annotation false subtypeOf [java.lang.Object] superTypes [Declarations$Shape, java.lang.Object, java.lang.Record] numerical false wrapper false raw false declaring Circle +MODIFIERS +TOKEN @88:3 +IDENTIFIER @88:10 id Circle Declarations.Circle [t static final package] : Declarations$Circle : Declarations$Circle +TOKEN @88:10 +TYPE_PARAMETERS +TOKEN @88:16 +VARIABLE @88:17 var Circle.radius [v package] : double + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Circle flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @88:17 : double +TOKEN @88:17 +IDENTIFIER @88:24 id radius Circle.radius [v package] : double : double +TOKEN @88:24 +TOKEN @88:30 +TOKEN @88:32 +LIST @88:43 +IDENTIFIER @88:43 id Shape Declarations.Shape [t static package interface] : Declarations$Shape : Declarations$Shape +TOKEN @88:43 +LIST +TOKEN @88:49 +TOKEN @89:3 +CLASS @91:3 class Declarations.Square [t static final package] : Declarations$Square super java.lang.Object interfaces [Declarations$Shape] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Declarations flags [static, final, package] members [] lookupToString 0 outermost Declarations annotation false subtypeOf [java.lang.Object] superTypes [Declarations$Shape, java.lang.Object] numerical false wrapper false raw false declaring Square +MODIFIERS @91:3 +TOKEN @91:3 +TOKEN @91:10 +TOKEN @91:16 +IDENTIFIER @91:22 id Square Declarations.Square [t static final package] : Declarations$Square : Declarations$Square +TOKEN @91:22 +TYPE_PARAMETERS +TOKEN @91:29 +LIST @91:40 +IDENTIFIER @91:40 id Shape Declarations.Shape [t static package interface] : Declarations$Shape : Declarations$Shape +TOKEN @91:40 +LIST +TOKEN @91:46 +TOKEN @92:3 +TOKEN @93:1 +TOKEN @94:1 +WARNING UNUSED_IMPORT IMPORT @4:1 The import java.util.Collections.emptyList is never used diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Declarations.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Declarations.java new file mode 100644 index 00000000000..bc3323ec6a3 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Declarations.java @@ -0,0 +1,93 @@ +import java.io.Serializable; +import java.util.List; +import java.util.Map; +import static java.util.Collections.emptyList; + +public abstract class Declarations> implements Serializable, Comparable> { + + private static final long serialVersionUID = 1L; + protected transient volatile int counter; + List names; + Map> index; + int[] values; + String[][] grid; + T current; + + public Declarations() { + } + + protected Declarations(T first) { + } + + public abstract void run() throws Exception; + + public final synchronized R convert(T input, Class target) { + return null; + } + + static native void nativeCall(); + + @Deprecated + void legacy(String... args) { + } + + @Override + public int compareTo(Declarations other) { + return 0; + } + + interface Listener { + void onEvent(String event); + + default void close() { + } + + static Listener none() { + return null; + } + } + + enum Level { + LOW, MEDIUM, HIGH; + + Level next() { + return null; + } + } + + record Point(int x, int y) implements Serializable { + Point { + } + + static Point origin() { + return null; + } + } + + @interface Marker { + String value() default ""; + + int priority() default 0; + } + + static class Nested extends Declarations { + static { + } + + { + } + + @Override + public void run() { + } + } + + sealed interface Shape permits Circle, Square { + } + + record Circle(double radius) implements Shape { + } + + static final class Square implements Shape { + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Declarations.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Declarations.textproto.gz new file mode 100644 index 00000000000..2cfb5393913 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Declarations.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Enums.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Enums.expected.txt new file mode 100644 index 00000000000..e424ee78e0b --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Enums.expected.txt @@ -0,0 +1,748 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id util unknown : ? +TOKEN @1:13 +TOKEN @1:17 +IDENTIFIER @1:18 id EnumMap unknown : ? +TOKEN @1:18 +TOKEN @1:25 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id util unknown : ? +TOKEN @2:13 +TOKEN @2:17 +IDENTIFIER @2:18 id EnumSet unknown : ? +TOKEN @2:18 +TOKEN @2:25 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id util unknown : ? +TOKEN @3:13 +TOKEN @3:17 +IDENTIFIER @3:18 id Map unknown : ? +TOKEN @3:18 +TOKEN @3:21 +ENUM @5:1 class .Enums [t package enum] : Enums super java.lang.Enum interfaces [java.lang.Comparable, java.lang.Runnable] + details declared true usages 7 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package, enum] members [, , , , , MINUS, PLUS, TIMES, apply, compute, parse, priority, run, symbol, table, valueOf, values] lookupToString 0 outermost Enums annotation false subtypeOf [java.lang.Object, java.io.Serializable, java.lang.Comparable, java.lang.Runnable] superTypes [java.io.Serializable, java.lang.Comparable, java.lang.Enum, java.lang.Object, java.lang.Runnable, java.lang.constant.Constable] numerical false wrapper false raw false declaring Enums +MODIFIERS +TOKEN @5:1 +IDENTIFIER @5:6 id Enums .Enums [t package enum] : Enums : Enums +TOKEN @5:6 +TYPE_PARAMETERS +TOKEN @5:12 +LIST @5:23 +PARAMETERIZED_TYPE @5:23 : java.lang.Comparable +IDENTIFIER @5:23 id Comparable java.lang.Comparable [t public interface] : java.lang.Comparable : java.lang.Comparable +TOKEN @5:23 +TYPE_ARGUMENTS @5:33 +TOKEN @5:33 +IDENTIFIER @5:34 id Enums .Enums [t package enum] : Enums : Enums +TOKEN @5:34 +TOKEN @5:39 +TOKEN @5:40 +IDENTIFIER @5:42 id Runnable java.lang.Runnable [t public interface] : java.lang.Runnable @java.lang.FunctionalInterface : java.lang.Runnable +TOKEN @5:42 +LIST +TOKEN @5:51 +ENUM_CONSTANT @6:3 var Enums.PLUS [v static final public enum] : Enums + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @6:3 new Enums. [m private] : ? (java.lang.String,int) returns void throws [] sig Enums#(Ljava/lang/String;ILjava/lang/String;I)V : ? + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [symbol, priority] parameterMetadata [] +IDENTIFIER @6:3 id PLUS Enums. [m private] : ? (java.lang.String,int) returns void throws [] sig Enums#(Ljava/lang/String;ILjava/lang/String;I)V : Enums +TOKEN @6:3 +ARGUMENTS @6:7 +TOKEN @6:7 +STRING_LITERAL @6:8 : java.lang.String = + +TOKEN @6:8 +TOKEN @6:11 +INT_LITERAL @6:13 : int = 1 +TOKEN @6:13 +TOKEN @6:14 +CLASS @6:16 class Enums. [t package] : Enums$1 super Enums interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] members [, apply] lookupToString 0 outermost Enums annotation false subtypeOf [java.lang.Object, java.io.Serializable, java.lang.Comparable, java.lang.Runnable] superTypes [Enums, java.io.Serializable, java.lang.Comparable, java.lang.Enum, java.lang.Object, java.lang.Runnable, java.lang.constant.Constable] numerical false wrapper false raw false declaring +MODIFIERS +TYPE_PARAMETERS +LIST +LIST +TOKEN @6:16 +METHOD @7:5 method .apply [m package] : ? @java.lang.Override (int,int) returns int throws [] sig Enums$1#apply(II)I overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing flags [package] overridden [Enums.apply[]] overridable true generic false default false synchronized false varargs false native false parameters [a, b] parameterMetadata [] +MODIFIERS @7:5 +ANNOTATION @7:5 : java.lang.Override +TOKEN @7:5 +IDENTIFIER @7:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @7:6 +ARGUMENTS +TYPE_PARAMETERS +PRIMITIVE_TYPE @8:5 : int +TOKEN @8:5 +IDENTIFIER @8:9 id apply .apply [m package] : ? @java.lang.Override (int,int) returns int throws [] sig Enums$1#apply(II)I : int +TOKEN @8:9 +TOKEN @8:14 +VARIABLE @8:15 var apply.a [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing flags [package] local true parameter true effectivelyFinal true constant null owner apply Enums$1#apply(II)I [package] returns int parameters 2 thrown 0 overridden 1 declared true usages 0 metadata 1 enclosing type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @8:15 : int +TOKEN @8:15 +IDENTIFIER @8:19 id a apply.a [v package] : int : int +TOKEN @8:19 +TOKEN @8:20 +VARIABLE @8:22 var apply.b [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing flags [package] local true parameter true effectivelyFinal true constant null owner apply Enums$1#apply(II)I [package] returns int parameters 2 thrown 0 overridden 1 declared true usages 0 metadata 1 enclosing type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @8:22 : int +TOKEN @8:22 +IDENTIFIER @8:26 id b apply.b [v package] : int : int +TOKEN @8:26 +TOKEN @8:27 +BLOCK @8:29 +TOKEN @8:29 +RETURN_STATEMENT @9:7 +TOKEN @9:7 +PLUS @9:14 : int +IDENTIFIER @9:14 id a apply.a [v package] : int : int +TOKEN @9:14 +TOKEN @9:16 +IDENTIFIER @9:18 id b apply.b [v package] : int : int +TOKEN @9:18 +TOKEN @9:19 +TOKEN @10:5 +TOKEN @11:3 +TOKEN @11:4 +ENUM_CONSTANT @12:3 var Enums.MINUS [v static final public enum] : Enums + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @12:3 new Enums. [m private] : ? (java.lang.String,int) returns void throws [] sig Enums#(Ljava/lang/String;ILjava/lang/String;I)V : ? + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [symbol, priority] parameterMetadata [] +IDENTIFIER @12:3 id MINUS Enums. [m private] : ? (java.lang.String,int) returns void throws [] sig Enums#(Ljava/lang/String;ILjava/lang/String;I)V : Enums +TOKEN @12:3 +ARGUMENTS @12:8 +TOKEN @12:8 +STRING_LITERAL @12:9 : java.lang.String = - +TOKEN @12:9 +TOKEN @12:12 +INT_LITERAL @12:14 : int = 1 +TOKEN @12:14 +TOKEN @12:15 +CLASS @12:17 class Enums. [t package] : Enums$2 super Enums interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] members [, apply] lookupToString 0 outermost Enums annotation false subtypeOf [java.lang.Object, java.io.Serializable, java.lang.Comparable, java.lang.Runnable] superTypes [Enums, java.io.Serializable, java.lang.Comparable, java.lang.Enum, java.lang.Object, java.lang.Runnable, java.lang.constant.Constable] numerical false wrapper false raw false declaring +MODIFIERS +TYPE_PARAMETERS +LIST +LIST +TOKEN @12:17 +METHOD @13:5 method .apply [m package] : ? @java.lang.Override (int,int) returns int throws [] sig Enums$2#apply(II)I overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing flags [package] overridden [Enums.apply[]] overridable true generic false default false synchronized false varargs false native false parameters [a, b] parameterMetadata [] +MODIFIERS @13:5 +ANNOTATION @13:5 : java.lang.Override +TOKEN @13:5 +IDENTIFIER @13:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @13:6 +ARGUMENTS +TYPE_PARAMETERS +PRIMITIVE_TYPE @14:5 : int +TOKEN @14:5 +IDENTIFIER @14:9 id apply .apply [m package] : ? @java.lang.Override (int,int) returns int throws [] sig Enums$2#apply(II)I : int +TOKEN @14:9 +TOKEN @14:14 +VARIABLE @14:15 var apply.a [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing flags [package] local true parameter true effectivelyFinal true constant null owner apply Enums$2#apply(II)I [package] returns int parameters 2 thrown 0 overridden 1 declared true usages 0 metadata 1 enclosing type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @14:15 : int +TOKEN @14:15 +IDENTIFIER @14:19 id a apply.a [v package] : int : int +TOKEN @14:19 +TOKEN @14:20 +VARIABLE @14:22 var apply.b [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing flags [package] local true parameter true effectivelyFinal true constant null owner apply Enums$2#apply(II)I [package] returns int parameters 2 thrown 0 overridden 1 declared true usages 0 metadata 1 enclosing type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @14:22 : int +TOKEN @14:22 +IDENTIFIER @14:26 id b apply.b [v package] : int : int +TOKEN @14:26 +TOKEN @14:27 +BLOCK @14:29 +TOKEN @14:29 +RETURN_STATEMENT @15:7 +TOKEN @15:7 +MINUS @15:14 : int +IDENTIFIER @15:14 id a apply.a [v package] : int : int +TOKEN @15:14 +TOKEN @15:16 +IDENTIFIER @15:18 id b apply.b [v package] : int : int +TOKEN @15:18 +TOKEN @15:19 +TOKEN @16:5 +TOKEN @17:3 +TOKEN @17:4 +ENUM_CONSTANT @18:3 var Enums.TIMES [v static final public enum] : Enums + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @18:3 new Enums. [m private] : ? (java.lang.String) returns void throws [] sig Enums#(Ljava/lang/String;ILjava/lang/String;)V : ? + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [symbol] parameterMetadata [] +IDENTIFIER @18:3 id TIMES Enums. [m private] : ? (java.lang.String) returns void throws [] sig Enums#(Ljava/lang/String;ILjava/lang/String;)V : Enums +TOKEN @18:3 +ARGUMENTS @18:8 +TOKEN @18:8 +STRING_LITERAL @18:9 : java.lang.String = * +TOKEN @18:9 +TOKEN @18:12 +CLASS @18:14 class Enums. [t package] : Enums$3 super Enums interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] members [, apply] lookupToString 0 outermost Enums annotation false subtypeOf [java.lang.Object, java.io.Serializable, java.lang.Comparable, java.lang.Runnable] superTypes [Enums, java.io.Serializable, java.lang.Comparable, java.lang.Enum, java.lang.Object, java.lang.Runnable, java.lang.constant.Constable] numerical false wrapper false raw false declaring +MODIFIERS +TYPE_PARAMETERS +LIST +LIST +TOKEN @18:14 +METHOD @19:5 method .apply [m package] : ? @java.lang.Override (int,int) returns int throws [] sig Enums$3#apply(II)I overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing flags [package] overridden [Enums.apply[]] overridable true generic false default false synchronized false varargs false native false parameters [a, b] parameterMetadata [] +MODIFIERS @19:5 +ANNOTATION @19:5 : java.lang.Override +TOKEN @19:5 +IDENTIFIER @19:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @19:6 +ARGUMENTS +TYPE_PARAMETERS +PRIMITIVE_TYPE @20:5 : int +TOKEN @20:5 +IDENTIFIER @20:9 id apply .apply [m package] : ? @java.lang.Override (int,int) returns int throws [] sig Enums$3#apply(II)I : int +TOKEN @20:9 +TOKEN @20:14 +VARIABLE @20:15 var apply.a [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing flags [package] local true parameter true effectivelyFinal true constant null owner apply Enums$3#apply(II)I [package] returns int parameters 2 thrown 0 overridden 1 declared true usages 0 metadata 1 enclosing type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @20:15 : int +TOKEN @20:15 +IDENTIFIER @20:19 id a apply.a [v package] : int : int +TOKEN @20:19 +TOKEN @20:20 +VARIABLE @20:22 var apply.b [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing flags [package] local true parameter true effectivelyFinal true constant null owner apply Enums$3#apply(II)I [package] returns int parameters 2 thrown 0 overridden 1 declared true usages 0 metadata 1 enclosing type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @20:22 : int +TOKEN @20:22 +IDENTIFIER @20:26 id b apply.b [v package] : int : int +TOKEN @20:26 +TOKEN @20:27 +BLOCK @20:29 +TOKEN @20:29 +RETURN_STATEMENT @21:7 +TOKEN @21:7 +MULTIPLY @21:14 : int +IDENTIFIER @21:14 id a apply.a [v package] : int : int +TOKEN @21:14 +TOKEN @21:16 +IDENTIFIER @21:18 id b apply.b [v package] : int : int +TOKEN @21:18 +TOKEN @21:19 +TOKEN @22:5 +TOKEN @23:3 +TOKEN @23:4 +VARIABLE @25:3 var Enums.symbol [v final private] : java.lang.String + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [final, private] local false parameter false effectivelyFinal true constant null +MODIFIERS @25:3 +TOKEN @25:3 +TOKEN @25:11 +IDENTIFIER @25:17 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @25:17 +IDENTIFIER @25:24 id symbol Enums.symbol [v final private] : java.lang.String : java.lang.String +TOKEN @25:24 +TOKEN @25:30 +VARIABLE @26:3 var Enums.priority [v final private] : int + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [final, private] local false parameter false effectivelyFinal true constant null +MODIFIERS @26:3 +TOKEN @26:3 +TOKEN @26:11 +PRIMITIVE_TYPE @26:17 : int +TOKEN @26:17 +IDENTIFIER @26:21 id priority Enums.priority [v final private] : int : int +TOKEN @26:21 +TOKEN @26:29 +CONSTRUCTOR @28:3 method Enums. [m private] : ? (java.lang.String) returns void throws [] sig Enums#(Ljava/lang/String;ILjava/lang/String;)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [symbol] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @28:3 id Enums Enums. [m private] : ? (java.lang.String) returns void throws [] sig Enums#(Ljava/lang/String;ILjava/lang/String;)V : void +TOKEN @28:3 +TOKEN @28:8 +VARIABLE @28:9 var .symbol [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] local true parameter true effectivelyFinal true constant null owner Enums#(Ljava/lang/String;ILjava/lang/String;)V [private] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Enums type true kinds truefalsefalse other falsefalsefalsefalsefalsefalse1falsefalse +MODIFIERS +IDENTIFIER @28:9 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @28:9 +IDENTIFIER @28:16 id symbol .symbol [v package] : java.lang.String : java.lang.String +TOKEN @28:16 +TOKEN @28:22 +BLOCK @28:24 +TOKEN @28:24 +EXPRESSION_STATEMENT @29:5 +METHOD_INVOCATION @29:5 call Enums. [m private] : ? (java.lang.String,int) returns void throws [] sig Enums#(Ljava/lang/String;ILjava/lang/String;I)V : Enums + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [symbol, priority] parameterMetadata [] +IDENTIFIER @29:5 id this Enums. [m private] : ? (java.lang.String,int) returns void throws [] sig Enums#(Ljava/lang/String;ILjava/lang/String;I)V : ? +TOKEN @29:5 +ARGUMENTS @29:9 +TOKEN @29:9 +IDENTIFIER @29:10 id symbol .symbol [v package] : java.lang.String : java.lang.String +TOKEN @29:10 +TOKEN @29:16 +INT_LITERAL @29:18 : int = 2 +TOKEN @29:18 +TOKEN @29:19 +TOKEN @29:20 +TOKEN @30:3 +CONSTRUCTOR @32:3 method Enums. [m private] : ? (java.lang.String,int) returns void throws [] sig Enums#(Ljava/lang/String;ILjava/lang/String;I)V overrides false + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [symbol, priority] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @32:3 id Enums Enums. [m private] : ? (java.lang.String,int) returns void throws [] sig Enums#(Ljava/lang/String;ILjava/lang/String;I)V : void +TOKEN @32:3 +TOKEN @32:8 +VARIABLE @32:9 var .symbol [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] local true parameter true effectivelyFinal true constant null owner Enums#(Ljava/lang/String;ILjava/lang/String;I)V [private] returns void parameters 2 thrown 0 overridden 0 declared true usages 3 metadata 0 enclosing Enums type true kinds truefalsefalse other falsefalsefalsefalsefalsefalse2falsefalse +MODIFIERS +IDENTIFIER @32:9 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @32:9 +IDENTIFIER @32:16 id symbol .symbol [v package] : java.lang.String : java.lang.String +TOKEN @32:16 +TOKEN @32:22 +VARIABLE @32:24 var .priority [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] local true parameter true effectivelyFinal true constant null owner Enums#(Ljava/lang/String;ILjava/lang/String;I)V [private] returns void parameters 2 thrown 0 overridden 0 declared true usages 3 metadata 0 enclosing Enums type true kinds truefalsefalse other falsefalsefalsefalsefalsefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @32:24 : int +TOKEN @32:24 +IDENTIFIER @32:28 id priority .priority [v package] : int : int +TOKEN @32:28 +TOKEN @32:36 +BLOCK @32:38 +TOKEN @32:38 +EXPRESSION_STATEMENT @33:5 +ASSIGNMENT @33:5 : java.lang.String +MEMBER_SELECT @33:5 : java.lang.String +IDENTIFIER @33:5 id this Enums.this [v final] : Enums : Enums +TOKEN @33:5 +TOKEN @33:9 +IDENTIFIER @33:10 id symbol Enums.symbol [v final private] : java.lang.String : java.lang.String +TOKEN @33:10 +TOKEN @33:17 +IDENTIFIER @33:19 id symbol .symbol [v package] : java.lang.String : java.lang.String +TOKEN @33:19 +TOKEN @33:25 +EXPRESSION_STATEMENT @34:5 +ASSIGNMENT @34:5 : int +MEMBER_SELECT @34:5 : int +IDENTIFIER @34:5 id this Enums.this [v final] : Enums : Enums +TOKEN @34:5 +TOKEN @34:9 +IDENTIFIER @34:10 id priority Enums.priority [v final private] : int : int +TOKEN @34:10 +TOKEN @34:19 +IDENTIFIER @34:21 id priority .priority [v package] : int : int +TOKEN @34:21 +TOKEN @34:29 +TOKEN @35:3 +METHOD @37:3 method Enums.apply [m abstract package] : ? (int,int) returns int throws [] sig Enums#apply(II)I overrides false + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [abstract, package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [a, b] parameterMetadata [] +MODIFIERS @37:3 +TOKEN @37:3 +TYPE_PARAMETERS +PRIMITIVE_TYPE @37:12 : int +TOKEN @37:12 +IDENTIFIER @37:16 id apply Enums.apply [m abstract package] : ? (int,int) returns int throws [] sig Enums#apply(II)I : int +TOKEN @37:16 +TOKEN @37:21 +VARIABLE @37:22 var apply.a [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] local true parameter true effectivelyFinal true constant null owner apply Enums#apply(II)I [abstract, package] returns int parameters 2 thrown 0 overridden 0 declared true usages 2 metadata 0 enclosing Enums type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @37:22 : int +TOKEN @37:22 +IDENTIFIER @37:26 id a apply.a [v package] : int : int +TOKEN @37:26 +TOKEN @37:27 +VARIABLE @37:29 var apply.b [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] local true parameter true effectivelyFinal true constant null owner apply Enums#apply(II)I [abstract, package] returns int parameters 2 thrown 0 overridden 0 declared true usages 2 metadata 0 enclosing Enums type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @37:29 : int +TOKEN @37:29 +IDENTIFIER @37:33 id b apply.b [v package] : int : int +TOKEN @37:33 +TOKEN @37:34 +TOKEN @37:35 +METHOD @39:3 method Enums.run [m public] : ? @java.lang.Override () returns void throws [] sig Enums#run()V overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Enums flags [public] overridden [Runnable.run[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @39:3 +ANNOTATION @39:3 : java.lang.Override +TOKEN @39:3 +IDENTIFIER @39:4 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @39:4 +ARGUMENTS +TOKEN @40:3 +TYPE_PARAMETERS +PRIMITIVE_TYPE @40:10 : void +TOKEN @40:10 +IDENTIFIER @40:15 id run Enums.run [m public] : ? @java.lang.Override () returns void throws [] sig Enums#run()V : void +TOKEN @40:15 +TOKEN @40:18 +TOKEN @40:19 +BLOCK @40:21 +TOKEN @40:21 +EXPRESSION_STATEMENT @41:5 +METHOD_INVOCATION @41:5 call PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing PrintStream flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @41:5 : ? +MEMBER_SELECT @41:5 : java.io.PrintStream +IDENTIFIER @41:5 id System java.lang.System [t final public] : java.lang.System : java.lang.System +TOKEN @41:5 +TOKEN @41:11 +IDENTIFIER @41:12 id out System.out [v static final public] : java.io.PrintStream : java.io.PrintStream +TOKEN @41:12 +TOKEN @41:15 +IDENTIFIER @41:16 id println PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void +TOKEN @41:16 +ARGUMENTS @41:23 +TOKEN @41:23 +PLUS @41:24 : java.lang.String +IDENTIFIER @41:24 id symbol Enums.symbol [v final private] : java.lang.String : java.lang.String +TOKEN @41:24 +TOKEN @41:31 +IDENTIFIER @41:33 id priority Enums.priority [v final private] : int : int +TOKEN @41:33 +TOKEN @41:41 +TOKEN @41:42 +TOKEN @42:3 +METHOD @44:3 method Enums.parse [m static package] : ? (java.lang.String) returns Enums throws [] sig Enums#parse(Ljava/lang/String;)LEnums; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [static, package] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [text] parameterMetadata [] +MODIFIERS @44:3 +TOKEN @44:3 +TYPE_PARAMETERS +IDENTIFIER @44:10 id Enums .Enums [t package enum] : Enums : Enums +TOKEN @44:10 +IDENTIFIER @44:16 id parse Enums.parse [m static package] : ? (java.lang.String) returns Enums throws [] sig Enums#parse(Ljava/lang/String;)LEnums; : Enums +TOKEN @44:16 +TOKEN @44:21 +VARIABLE @44:22 var parse.text [v package] : java.lang.String + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] local true parameter true effectivelyFinal true constant null owner parse Enums#parse(Ljava/lang/String;)LEnums; [static, package] returns Enums parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Enums type true kinds truefalsefalse other falsefalsefalsefalsefalsefalse1falsefalse +MODIFIERS +IDENTIFIER @44:22 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @44:22 +IDENTIFIER @44:29 id text parse.text [v package] : java.lang.String : java.lang.String +TOKEN @44:29 +TOKEN @44:33 +BLOCK @44:35 +TOKEN @44:35 +FOR_EACH_STATEMENT @45:5 +TOKEN @45:5 +TOKEN @45:9 +VARIABLE @45:10 var parse.value [v package] : Enums + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] local true parameter false effectivelyFinal true constant null owner parse Enums#parse(Ljava/lang/String;)LEnums; [static, package] returns Enums parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Enums type true kinds truefalsefalse other falsefalsefalsefalsefalsefalse1falsefalse +MODIFIERS +IDENTIFIER @45:10 id Enums .Enums [t package enum] : Enums : Enums +TOKEN @45:10 +IDENTIFIER @45:16 id value parse.value [v package] : Enums : Enums +TOKEN @45:16 +TOKEN @45:22 +METHOD_INVOCATION @45:24 call Enums.values [m static public] : ? () returns Enums[] throws [] sig Enums#values()[LEnums; : Enums[] + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @45:24 id values Enums.values [m static public] : ? () returns Enums[] throws [] sig Enums#values()[LEnums; : Enums[] +TOKEN @45:24 +ARGUMENTS @45:30 +TOKEN @45:30 +TOKEN @45:31 +TOKEN @45:32 +BLOCK @45:34 +TOKEN @45:34 +IF_STATEMENT @46:7 +TOKEN @46:7 +TOKEN @46:10 +METHOD_INVOCATION @46:11 call String.equals [m public] : ? (java.lang.Object) returns boolean throws [] sig java.lang.String#equals(Ljava/lang/Object;)Z : boolean + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [Object.equals[]] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @46:11 : ? +MEMBER_SELECT @46:11 : java.lang.String +IDENTIFIER @46:11 id value parse.value [v package] : Enums : Enums +TOKEN @46:11 +TOKEN @46:16 +IDENTIFIER @46:17 id symbol Enums.symbol [v final private] : java.lang.String : java.lang.String +TOKEN @46:17 +TOKEN @46:23 +IDENTIFIER @46:24 id equals String.equals [m public] : ? (java.lang.Object) returns boolean throws [] sig java.lang.String#equals(Ljava/lang/Object;)Z : boolean +TOKEN @46:24 +ARGUMENTS @46:30 +TOKEN @46:30 +IDENTIFIER @46:31 id text parse.text [v package] : java.lang.String : java.lang.String +TOKEN @46:31 +TOKEN @46:35 +TOKEN @46:36 +BLOCK @46:38 +TOKEN @46:38 +RETURN_STATEMENT @47:9 +TOKEN @47:9 +IDENTIFIER @47:16 id value parse.value [v package] : Enums : Enums +TOKEN @47:16 +TOKEN @47:21 +TOKEN @48:7 +TOKEN @49:5 +RETURN_STATEMENT @50:5 +TOKEN @50:5 +METHOD_INVOCATION @50:12 call Enums.valueOf [m static public] : ? (java.lang.String) returns Enums throws [] sig Enums#valueOf(Ljava/lang/String;)LEnums; : Enums + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +IDENTIFIER @50:12 id valueOf Enums.valueOf [m static public] : ? (java.lang.String) returns Enums throws [] sig Enums#valueOf(Ljava/lang/String;)LEnums; : Enums +TOKEN @50:12 +ARGUMENTS @50:19 +TOKEN @50:19 +IDENTIFIER @50:20 id text parse.text [v package] : java.lang.String : java.lang.String +TOKEN @50:20 +TOKEN @50:24 +TOKEN @50:25 +TOKEN @51:3 +METHOD @53:3 method Enums.compute [m package] : ? (int,int) returns int throws [] sig Enums#compute(II)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [a, b] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @53:3 : int +TOKEN @53:3 +IDENTIFIER @53:7 id compute Enums.compute [m package] : ? (int,int) returns int throws [] sig Enums#compute(II)I : int +TOKEN @53:7 +TOKEN @53:14 +VARIABLE @53:15 var compute.a [v package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] local true parameter true effectivelyFinal true constant null owner compute Enums#compute(II)I [package] returns int parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Enums type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @53:15 : int +TOKEN @53:15 +IDENTIFIER @53:19 id a compute.a [v package] : int : int +TOKEN @53:19 +TOKEN @53:20 +VARIABLE @53:22 var compute.b [v package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [package] local true parameter true effectivelyFinal true constant null owner compute Enums#compute(II)I [package] returns int parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Enums type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @53:22 : int +TOKEN @53:22 +IDENTIFIER @53:26 id b compute.b [v package] : int : int +TOKEN @53:26 +TOKEN @53:27 +BLOCK @53:29 +TOKEN @53:29 +SWITCH_STATEMENT @54:5 : ? +TOKEN @54:5 +TOKEN @54:12 +IDENTIFIER @54:13 id this Enums.this [v final] : Enums : Enums +TOKEN @54:13 +TOKEN @54:17 +TOKEN @54:19 +CASE_GROUP @55:7 +CASE_LABEL @55:7 +TOKEN @55:7 +IDENTIFIER @55:12 id PLUS Enums.PLUS [v static final public enum] : Enums : Enums +TOKEN @55:12 +TOKEN @55:16 +RETURN_STATEMENT @56:9 +TOKEN @56:9 +METHOD_INVOCATION @56:16 call Enums.apply [m abstract package] : ? (int,int) returns int throws [] sig Enums#apply(II)I : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [abstract, package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [a, b] parameterMetadata [] +MEMBER_SELECT @56:16 : ? +IDENTIFIER @56:16 id PLUS Enums.PLUS [v static final public enum] : Enums : Enums +TOKEN @56:16 +TOKEN @56:20 +IDENTIFIER @56:21 id apply Enums.apply [m abstract package] : ? (int,int) returns int throws [] sig Enums#apply(II)I : int +TOKEN @56:21 +ARGUMENTS @56:26 +TOKEN @56:26 +IDENTIFIER @56:27 id a compute.a [v package] : int : int +TOKEN @56:27 +TOKEN @56:28 +IDENTIFIER @56:30 id b compute.b [v package] : int : int +TOKEN @56:30 +TOKEN @56:31 +TOKEN @56:32 +CASE_GROUP @57:7 +CASE_LABEL @57:7 +TOKEN @57:7 +IDENTIFIER @57:12 id MINUS Enums.MINUS [v static final public enum] : Enums : Enums +TOKEN @57:12 +TOKEN @57:17 +RETURN_STATEMENT @58:9 +TOKEN @58:9 +METHOD_INVOCATION @58:16 call Enums.apply [m abstract package] : ? (int,int) returns int throws [] sig Enums#apply(II)I : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enums flags [abstract, package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [a, b] parameterMetadata [] +IDENTIFIER @58:16 id apply Enums.apply [m abstract package] : ? (int,int) returns int throws [] sig Enums#apply(II)I : int +TOKEN @58:16 +ARGUMENTS @58:21 +TOKEN @58:21 +IDENTIFIER @58:22 id a compute.a [v package] : int : int +TOKEN @58:22 +TOKEN @58:23 +IDENTIFIER @58:25 id b compute.b [v package] : int : int +TOKEN @58:25 +TOKEN @58:26 +TOKEN @58:27 +CASE_GROUP @59:7 +CASE_LABEL @59:7 +TOKEN @59:7 +TOKEN @59:14 +RETURN_STATEMENT @60:9 +TOKEN @60:9 +PLUS @60:16 : int +METHOD_INVOCATION @60:16 call String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [CharSequence.length[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @60:16 : ? +METHOD_INVOCATION @60:16 call Enum.name [m final public] : ? () returns java.lang.String throws [] sig java.lang.Enum#name()Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enum flags [final, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @60:16 id name Enum.name [m final public] : ? () returns java.lang.String throws [] sig java.lang.Enum#name()Ljava/lang/String; : java.lang.String +TOKEN @60:16 +ARGUMENTS @60:20 +TOKEN @60:20 +TOKEN @60:21 +TOKEN @60:22 +IDENTIFIER @60:23 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @60:23 +ARGUMENTS @60:29 +TOKEN @60:29 +TOKEN @60:30 +TOKEN @60:32 +METHOD_INVOCATION @60:34 call Enum.ordinal [m final public] : ? () returns int throws [] sig java.lang.Enum#ordinal()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enum flags [final, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @60:34 id ordinal Enum.ordinal [m final public] : ? () returns int throws [] sig java.lang.Enum#ordinal()I : int +TOKEN @60:34 +ARGUMENTS @60:41 +TOKEN @60:41 +TOKEN @60:42 +TOKEN @60:43 +TOKEN @61:5 +TOKEN @62:3 +METHOD @64:3 method Enums.table [m static package] : ? () returns java.util.Map throws [] sig Enums#table()Ljava/util/Map; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Enums flags [static, package] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [], [] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS @64:3 +TOKEN @64:3 +TYPE_PARAMETERS +PARAMETERIZED_TYPE @64:10 : java.util.Map +IDENTIFIER @64:10 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @64:10 +TYPE_ARGUMENTS @64:13 +TOKEN @64:13 +IDENTIFIER @64:14 id Enums .Enums [t package enum] : Enums : Enums +TOKEN @64:14 +TOKEN @64:19 +IDENTIFIER @64:21 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @64:21 +TOKEN @64:28 +IDENTIFIER @64:30 id table Enums.table [m static package] : ? () returns java.util.Map throws [] sig Enums#table()Ljava/util/Map; : java.util.Map +TOKEN @64:30 +TOKEN @64:35 +TOKEN @64:36 +BLOCK @64:38 +TOKEN @64:38 +VARIABLE @65:5 var table.table [v package] : java.util.Map + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Enums flags [package] local true parameter false effectivelyFinal true constant null owner table Enums#table()Ljava/util/Map; [static, package] returns java.util.Map parameters 0 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Enums type true kinds truefalsefalse other falsefalsefalsefalsefalsefalse0falsefalse +MODIFIERS +PARAMETERIZED_TYPE @65:5 : java.util.Map +IDENTIFIER @65:5 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @65:5 +TYPE_ARGUMENTS @65:8 +TOKEN @65:8 +IDENTIFIER @65:9 id Enums .Enums [t package enum] : Enums : Enums +TOKEN @65:9 +TOKEN @65:14 +IDENTIFIER @65:16 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @65:16 +TOKEN @65:23 +IDENTIFIER @65:25 id table table.table [v package] : java.util.Map : java.util.Map +TOKEN @65:25 +TOKEN @65:31 +NEW_CLASS @65:33 new EnumMap. [m public] : ? (java.lang.Class) returns void throws [] sig java.util.EnumMap#(Ljava/lang/Class;)V : java.util.EnumMap + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing EnumMap flags [public] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @65:33 +PARAMETERIZED_TYPE @65:37 : java.util.EnumMap +IDENTIFIER @65:37 id EnumMap EnumMap. [m public] : ? (java.lang.Class) returns void throws [] sig java.util.EnumMap#(Ljava/lang/Class;)V : java.util.EnumMap +TOKEN @65:37 +TYPE_ARGUMENTS @65:44 +TOKEN @65:44 +TOKEN @65:45 +ARGUMENTS @65:46 +TOKEN @65:46 +MEMBER_SELECT @65:47 : java.lang.Class +IDENTIFIER @65:47 id Enums .Enums [t package enum] : Enums : Enums +TOKEN @65:47 +TOKEN @65:52 +IDENTIFIER @65:53 id class unknown : ? +TOKEN @65:53 +TOKEN @65:58 +TOKEN @65:59 +EXPRESSION_STATEMENT @66:5 +METHOD_INVOCATION @66:5 call Iterable.forEach [m public] : ? (java.util.function.Consumer) returns void throws [] sig java.lang.Iterable#forEach(Ljava/util/function/Consumer;)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Iterable flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @66:5 : ? +METHOD_INVOCATION @66:5 call EnumSet.allOf [m static public] : ? (java.lang.Class) returns java.util.EnumSet throws [] sig java.util.EnumSet#allOf(Ljava/lang/Class;)Ljava/util/EnumSet; : java.util.EnumSet + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing EnumSet flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @66:5 : ? +IDENTIFIER @66:5 id EnumSet java.util.EnumSet [t abstract public] : java.util.EnumSet : java.util.EnumSet +TOKEN @66:5 +TOKEN @66:12 +IDENTIFIER @66:13 id allOf EnumSet.allOf [m static public] : ? (java.lang.Class) returns java.util.EnumSet throws [] sig java.util.EnumSet#allOf(Ljava/lang/Class;)Ljava/util/EnumSet; : java.util.EnumSet +TOKEN @66:13 +ARGUMENTS @66:18 +TOKEN @66:18 +MEMBER_SELECT @66:19 : java.lang.Class +IDENTIFIER @66:19 id Enums .Enums [t package enum] : Enums : Enums +TOKEN @66:19 +TOKEN @66:24 +IDENTIFIER @66:25 id class unknown : ? +TOKEN @66:25 +TOKEN @66:30 +TOKEN @66:31 +IDENTIFIER @66:32 id forEach Iterable.forEach [m public] : ? (java.util.function.Consumer) returns void throws [] sig java.lang.Iterable#forEach(Ljava/util/function/Consumer;)V : void +TOKEN @66:32 +ARGUMENTS @66:39 +TOKEN @66:39 +LAMBDA_EXPRESSION @66:40 : java.util.function.Consumer +VARIABLE @66:40 var accept.value [v package] : Enums + details declared true usages 2 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Consumer flags [package] local true parameter true effectivelyFinal true constant null owner accept java.util.function.Consumer#accept(Ljava/lang/Object;)V [abstract, public] returns void parameters 1 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing Consumer type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @66:40 id value accept.value [v package] : Enums : Enums +TOKEN @66:40 +TOKEN @66:46 +METHOD_INVOCATION @66:49 call Map.put [m abstract public] : ? (Enums,java.lang.Integer) returns java.lang.Integer throws [] sig java.util.Map#put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; : java.lang.Integer + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Map flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +MEMBER_SELECT @66:49 : ? +IDENTIFIER @66:49 id table table.table [v package] : java.util.Map : java.util.Map +TOKEN @66:49 +TOKEN @66:54 +IDENTIFIER @66:55 id put Map.put [m abstract public] : ? (Enums,java.lang.Integer) returns java.lang.Integer throws [] sig java.util.Map#put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; : java.lang.Integer +TOKEN @66:55 +ARGUMENTS @66:58 +TOKEN @66:58 +IDENTIFIER @66:59 id value accept.value [v package] : Enums : Enums +TOKEN @66:59 +TOKEN @66:64 +MEMBER_SELECT @66:66 : int +IDENTIFIER @66:66 id value accept.value [v package] : Enums : Enums +TOKEN @66:66 +TOKEN @66:71 +IDENTIFIER @66:72 id priority Enums.priority [v final private] : int : int +TOKEN @66:72 +TOKEN @66:80 +TOKEN @66:81 +TOKEN @66:82 +RETURN_STATEMENT @67:5 +TOKEN @67:5 +IDENTIFIER @67:12 id table table.table [v package] : java.util.Map : java.util.Map +TOKEN @67:12 +TOKEN @67:17 +TOKEN @68:3 +TOKEN @69:1 +TOKEN @70:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Enums.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Enums.java new file mode 100644 index 00000000000..5033c6837b2 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Enums.java @@ -0,0 +1,69 @@ +import java.util.EnumMap; +import java.util.EnumSet; +import java.util.Map; + +enum Enums implements Comparable, Runnable { + PLUS("+", 1) { + @Override + int apply(int a, int b) { + return a + b; + } + }, + MINUS("-", 1) { + @Override + int apply(int a, int b) { + return a - b; + } + }, + TIMES("*") { + @Override + int apply(int a, int b) { + return a * b; + } + }; + + private final String symbol; + private final int priority; + + Enums(String symbol) { + this(symbol, 2); + } + + Enums(String symbol, int priority) { + this.symbol = symbol; + this.priority = priority; + } + + abstract int apply(int a, int b); + + @Override + public void run() { + System.out.println(symbol + priority); + } + + static Enums parse(String text) { + for (Enums value : values()) { + if (value.symbol.equals(text)) { + return value; + } + } + return valueOf(text); + } + + int compute(int a, int b) { + switch (this) { + case PLUS: + return PLUS.apply(a, b); + case MINUS: + return apply(a, b); + default: + return name().length() + ordinal(); + } + } + + static Map table() { + Map table = new EnumMap<>(Enums.class); + EnumSet.allOf(Enums.class).forEach(value -> table.put(value, value.priority)); + return table; + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Enums.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Enums.textproto.gz new file mode 100644 index 00000000000..8c3c3a3ce21 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Enums.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Expressions.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Expressions.expected.txt new file mode 100644 index 00000000000..3d51d7f9b32 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Expressions.expected.txt @@ -0,0 +1,1119 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id util unknown : ? +TOKEN @1:13 +TOKEN @1:17 +IDENTIFIER @1:18 id ArrayList unknown : ? +TOKEN @1:18 +TOKEN @1:27 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id util unknown : ? +TOKEN @2:13 +TOKEN @2:17 +IDENTIFIER @2:18 id List unknown : ? +TOKEN @2:18 +TOKEN @2:22 +CLASS @4:1 class .Expressions [t package] : Expressions super java.lang.Object interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] members [, , BIG, FLAG, HEX, Inner, LETTER, NAME, RATIO, SIZE, SMALL, a, array, arrayType, assign, b, boxed, c, concat, created, d, deep, e, empty, first, init, inner, innerValue, isString, length, list, matrix, negated, nextLetter, o, qualified, s, self, shift, shortValue, size, small, superCall, text, type, unboxed] lookupToString 0 outermost Expressions annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Expressions +MODIFIERS +TOKEN @4:1 +IDENTIFIER @4:7 id Expressions .Expressions [t package] : Expressions : Expressions +TOKEN @4:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @4:19 +VARIABLE @6:3 var Expressions.SIZE [v static final package] : int + details declared true usages 5 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [static, final, package] local false parameter false effectivelyFinal true constant 4 +MODIFIERS @6:3 +TOKEN @6:3 +TOKEN @6:10 +PRIMITIVE_TYPE @6:16 : int +TOKEN @6:16 +IDENTIFIER @6:20 id SIZE Expressions.SIZE [v static final package] : int : int = 4 +TOKEN @6:20 +TOKEN @6:25 +INT_LITERAL @6:27 : int = 4 +TOKEN @6:27 +TOKEN @6:28 +VARIABLE @7:3 var Expressions.NAME [v static final package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [static, final, package] local false parameter false effectivelyFinal true constant expr4 +MODIFIERS @7:3 +TOKEN @7:3 +TOKEN @7:10 +IDENTIFIER @7:16 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @7:16 +IDENTIFIER @7:23 id NAME Expressions.NAME [v static final package] : java.lang.String : java.lang.String = expr4 +TOKEN @7:23 +TOKEN @7:28 +PLUS @7:30 : java.lang.String = expr4 +STRING_LITERAL @7:30 : java.lang.String = expr +TOKEN @7:30 +TOKEN @7:37 +IDENTIFIER @7:39 id SIZE Expressions.SIZE [v static final package] : int : int = 4 +TOKEN @7:39 +TOKEN @7:43 +VARIABLE @8:3 var Expressions.BIG [v static final package] : long + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [static, final, package] local false parameter false effectivelyFinal true constant 1099511627776 +MODIFIERS @8:3 +TOKEN @8:3 +TOKEN @8:10 +PRIMITIVE_TYPE @8:16 : long +TOKEN @8:16 +IDENTIFIER @8:21 id BIG Expressions.BIG [v static final package] : long : long = 1099511627776 +TOKEN @8:21 +TOKEN @8:25 +LEFT_SHIFT @8:27 : long +LONG_LITERAL @8:27 : long = 1 +TOKEN @8:27 +TOKEN @8:30 +INT_LITERAL @8:33 : int = 40 +TOKEN @8:33 +TOKEN @8:35 +VARIABLE @9:3 var Expressions.LETTER [v static final package] : char + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [static, final, package] local false parameter false effectivelyFinal true constant 97 +MODIFIERS @9:3 +TOKEN @9:3 +TOKEN @9:10 +PRIMITIVE_TYPE @9:16 : char +TOKEN @9:16 +IDENTIFIER @9:21 id LETTER Expressions.LETTER [v static final package] : char : char = 97 +TOKEN @9:21 +TOKEN @9:28 +CHAR_LITERAL @9:30 : char = 97 +TOKEN @9:30 +TOKEN @9:33 +VARIABLE @10:3 var Expressions.RATIO [v static final package] : double + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [static, final, package] local false parameter false effectivelyFinal true constant 1500.0 +MODIFIERS @10:3 +TOKEN @10:3 +TOKEN @10:10 +PRIMITIVE_TYPE @10:16 : double +TOKEN @10:16 +IDENTIFIER @10:23 id RATIO Expressions.RATIO [v static final package] : double : double = 1500.0 +TOKEN @10:23 +TOKEN @10:29 +DOUBLE_LITERAL @10:31 : double +TOKEN @10:31 +TOKEN @10:36 +VARIABLE @11:3 var Expressions.SMALL [v static final package] : float + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [static, final, package] local false parameter false effectivelyFinal true constant 2.5 +MODIFIERS @11:3 +TOKEN @11:3 +TOKEN @11:10 +PRIMITIVE_TYPE @11:16 : float +TOKEN @11:16 +IDENTIFIER @11:22 id SMALL Expressions.SMALL [v static final package] : float : float = 2.5 +TOKEN @11:22 +TOKEN @11:28 +FLOAT_LITERAL @11:30 : float +TOKEN @11:30 +TOKEN @11:34 +VARIABLE @12:3 var Expressions.FLAG [v static final package] : boolean + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [static, final, package] local false parameter false effectivelyFinal true constant true +MODIFIERS @12:3 +TOKEN @12:3 +TOKEN @12:10 +PRIMITIVE_TYPE @12:16 : boolean +TOKEN @12:16 +IDENTIFIER @12:24 id FLAG Expressions.FLAG [v static final package] : boolean : boolean = true +TOKEN @12:24 +TOKEN @12:29 +CONDITIONAL_AND @12:31 : boolean +LOGICAL_COMPLEMENT @12:31 : boolean = true +TOKEN @12:31 +BOOLEAN_LITERAL @12:32 : boolean = false +TOKEN @12:32 +TOKEN @12:38 +PARENTHESIZED_EXPRESSION @12:41 : boolean +TOKEN @12:41 +CONDITIONAL_OR @12:42 : boolean +GREATER_THAN @12:42 : boolean +IDENTIFIER @12:42 id SIZE Expressions.SIZE [v static final package] : int : int = 4 +TOKEN @12:42 +TOKEN @12:47 +INT_LITERAL @12:49 : int = 2 +TOKEN @12:49 +TOKEN @12:51 +LESS_THAN_OR_EQUAL_TO @12:54 : boolean +IDENTIFIER @12:54 id SIZE Expressions.SIZE [v static final package] : int : int = 4 +TOKEN @12:54 +TOKEN @12:59 +INT_LITERAL @12:62 : int = 1 +TOKEN @12:62 +TOKEN @12:63 +TOKEN @12:64 +VARIABLE @13:3 var Expressions.HEX [v static final package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [static, final, package] local false parameter false effectivelyFinal true constant -5 +MODIFIERS @13:3 +TOKEN @13:3 +TOKEN @13:10 +PRIMITIVE_TYPE @13:16 : int +TOKEN @13:16 +IDENTIFIER @13:20 id HEX Expressions.HEX [v static final package] : int : int = -5 +TOKEN @13:20 +TOKEN @13:24 +OR @13:26 : int +AND @13:26 : int +INT_LITERAL @13:26 : int = 255 +TOKEN @13:26 +TOKEN @13:31 +INT_LITERAL @13:33 : int = 10 +TOKEN @13:33 +TOKEN @13:40 +XOR @13:42 : int +INT_LITERAL @13:42 : int = 15 +TOKEN @13:42 +TOKEN @13:46 +BITWISE_COMPLEMENT @13:48 : int = -4 +TOKEN @13:48 +INT_LITERAL @13:49 : int = 3 +TOKEN @13:49 +TOKEN @13:50 +VARIABLE @15:3 var Expressions.a [v package] : int + details declared true usages 7 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @15:3 : int +TOKEN @15:3 +IDENTIFIER @15:7 id a Expressions.a [v package] : int : int +TOKEN @15:7 +TOKEN @15:9 +INT_LITERAL @15:11 : int = 1 +TOKEN @15:11 +TOKEN @15:12 +VARIABLE @16:3 var Expressions.b [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @16:3 : int +TOKEN @16:3 +IDENTIFIER @16:7 id b Expressions.b [v package] : int : int +TOKEN @16:7 +TOKEN @16:9 +MINUS @16:11 : int +PLUS @16:11 : int +IDENTIFIER @16:11 id a Expressions.a [v package] : int : int +TOKEN @16:11 +TOKEN @16:13 +MULTIPLY @16:15 : int = 6 +INT_LITERAL @16:15 : int = 2 +TOKEN @16:15 +TOKEN @16:17 +INT_LITERAL @16:19 : int = 3 +TOKEN @16:19 +TOKEN @16:21 +REMAINDER @16:23 : int = 2 +DIVIDE @16:23 : int = 2 +INT_LITERAL @16:23 : int = 4 +TOKEN @16:23 +TOKEN @16:25 +INT_LITERAL @16:27 : int = 2 +TOKEN @16:27 +TOKEN @16:29 +INT_LITERAL @16:31 : int = 3 +TOKEN @16:31 +TOKEN @16:32 +VARIABLE @17:3 var Expressions.c [v package] : long + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @17:3 : long +TOKEN @17:3 +IDENTIFIER @17:8 id c Expressions.c [v package] : long : long +TOKEN @17:8 +TOKEN @17:10 +PLUS @17:12 : long +IDENTIFIER @17:12 id a Expressions.a [v package] : int : int +TOKEN @17:12 +TOKEN @17:14 +LONG_LITERAL @17:16 : long = 1 +TOKEN @17:16 +TOKEN @17:18 +VARIABLE @18:3 var Expressions.d [v package] : double + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @18:3 : double +TOKEN @18:3 +IDENTIFIER @18:10 id d Expressions.d [v package] : double : double +TOKEN @18:10 +TOKEN @18:12 +DIVIDE @18:14 : double +IDENTIFIER @18:14 id a Expressions.a [v package] : int : int +TOKEN @18:14 +TOKEN @18:16 +DOUBLE_LITERAL @18:18 : double +TOKEN @18:18 +TOKEN @18:21 +VARIABLE @19:3 var Expressions.e [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @19:3 : int +TOKEN @19:3 +IDENTIFIER @19:7 id e Expressions.e [v package] : int : int +TOKEN @19:7 +TOKEN @19:9 +TYPE_CAST @19:11 : int +TOKEN @19:11 +PRIMITIVE_TYPE @19:12 : int +TOKEN @19:12 +LIST +TOKEN @19:15 +IDENTIFIER @19:17 id d Expressions.d [v package] : double : double +TOKEN @19:17 +TOKEN @19:18 +VARIABLE @20:3 var Expressions.o [v package] : java.lang.Object + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @20:3 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @20:3 +IDENTIFIER @20:10 id o Expressions.o [v package] : java.lang.Object : java.lang.Object +TOKEN @20:10 +TOKEN @20:12 +STRING_LITERAL @20:14 : java.lang.String = text +TOKEN @20:14 +TOKEN @20:20 +VARIABLE @21:3 var Expressions.isString [v package] : boolean + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @21:3 : boolean +TOKEN @21:3 +IDENTIFIER @21:11 id isString Expressions.isString [v package] : boolean : boolean +TOKEN @21:11 +TOKEN @21:20 +INSTANCE_OF @21:22 : boolean +IDENTIFIER @21:22 id o Expressions.o [v package] : java.lang.Object : java.lang.Object +TOKEN @21:22 +TOKEN @21:24 +IDENTIFIER @21:35 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @21:35 +TOKEN @21:41 +VARIABLE @22:3 var Expressions.s [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @22:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @22:3 +IDENTIFIER @22:10 id s Expressions.s [v package] : java.lang.String : java.lang.String +TOKEN @22:10 +TOKEN @22:12 +CONDITIONAL_EXPRESSION @22:14 : java.lang.String +IDENTIFIER @22:14 id isString Expressions.isString [v package] : boolean : boolean +TOKEN @22:14 +TOKEN @22:23 +TYPE_CAST @22:25 : java.lang.String +TOKEN @22:25 +IDENTIFIER @22:26 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @22:26 +LIST +TOKEN @22:32 +IDENTIFIER @22:34 id o Expressions.o [v package] : java.lang.Object : java.lang.Object +TOKEN @22:34 +TOKEN @22:36 +NULL_LITERAL @22:38 : +TOKEN @22:38 +TOKEN @22:42 +VARIABLE @23:3 var Expressions.array [v package] : int[] + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +ARRAY_TYPE @23:3 : int[] +PRIMITIVE_TYPE @23:3 : int +TOKEN @23:3 +TOKEN @23:6 +TOKEN @23:7 +IDENTIFIER @23:9 id array Expressions.array [v package] : int[] : int[] +TOKEN @23:9 +TOKEN @23:15 +NEW_ARRAY @23:17 : int[] +TOKEN @23:17 +PRIMITIVE_TYPE @23:21 : int +TOKEN @23:21 +ARRAY_DIMENSION @23:24 +TOKEN @23:24 +IDENTIFIER @23:25 id SIZE Expressions.SIZE [v static final package] : int : int = 4 +TOKEN @23:25 +TOKEN @23:29 +LIST +TOKEN @23:30 +VARIABLE @24:3 var Expressions.matrix [v package] : int[][] + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +ARRAY_TYPE @24:3 : int[][] +ARRAY_TYPE @24:3 : int[] +PRIMITIVE_TYPE @24:3 : int +TOKEN @24:3 +TOKEN @24:6 +TOKEN @24:7 +TOKEN @24:8 +TOKEN @24:9 +IDENTIFIER @24:11 id matrix Expressions.matrix [v package] : int[][] : int[][] +TOKEN @24:11 +TOKEN @24:18 +NEW_ARRAY @24:20 : int[][] +TOKEN @24:20 +LIST @24:21 +NEW_ARRAY @24:21 : int[] +TOKEN @24:21 +LIST @24:22 +INT_LITERAL @24:22 : int = 1 +TOKEN @24:22 +TOKEN @24:23 +INT_LITERAL @24:25 : int = 2 +TOKEN @24:25 +TOKEN @24:26 +TOKEN @24:27 +NEW_ARRAY @24:29 : int[] +TOKEN @24:29 +LIST @24:30 +INT_LITERAL @24:30 : int = 3 +TOKEN @24:30 +TOKEN @24:31 +TOKEN @24:32 +TOKEN @24:33 +VARIABLE @25:3 var Expressions.init [v package] : int[] + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +ARRAY_TYPE @25:3 : int[] +PRIMITIVE_TYPE @25:3 : int +TOKEN @25:3 +TOKEN @25:6 +TOKEN @25:7 +IDENTIFIER @25:9 id init Expressions.init [v package] : int[] : int[] +TOKEN @25:9 +TOKEN @25:14 +NEW_ARRAY @25:16 : int[] +TOKEN @25:16 +PRIMITIVE_TYPE @25:20 : int +TOKEN @25:20 +ARRAY_DIMENSION @25:23 +TOKEN @25:23 +TOKEN @25:24 +TOKEN @25:26 +LIST @25:27 +INT_LITERAL @25:27 : int = 1 +TOKEN @25:27 +TOKEN @25:28 +INT_LITERAL @25:30 : int = 2 +TOKEN @25:30 +TOKEN @25:31 +INT_LITERAL @25:33 : int = 3 +TOKEN @25:33 +TOKEN @25:34 +TOKEN @25:35 +VARIABLE @26:3 var Expressions.first [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @26:3 : int +TOKEN @26:3 +IDENTIFIER @26:7 id first Expressions.first [v package] : int : int +TOKEN @26:7 +TOKEN @26:13 +ARRAY_ACCESS_EXPRESSION @26:15 : int +IDENTIFIER @26:15 id init Expressions.init [v package] : int[] : int[] +TOKEN @26:15 +ARRAY_DIMENSION @26:19 +TOKEN @26:19 +INT_LITERAL @26:20 : int = 0 +TOKEN @26:20 +TOKEN @26:21 +TOKEN @26:22 +VARIABLE @27:3 var Expressions.length [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @27:3 : int +TOKEN @27:3 +IDENTIFIER @27:7 id length Expressions.length [v package] : int : int +TOKEN @27:7 +TOKEN @27:14 +MEMBER_SELECT @27:16 : int +IDENTIFIER @27:16 id init Expressions.init [v package] : int[] : int[] +TOKEN @27:16 +TOKEN @27:20 +IDENTIFIER @27:21 id length !unknown!.length [v final public] : int : int +TOKEN @27:21 +TOKEN @27:27 +VARIABLE @28:3 var Expressions.list [v package] : java.util.List + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @28:3 : java.util.List +IDENTIFIER @28:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @28:3 +TYPE_ARGUMENTS @28:7 +TOKEN @28:7 +IDENTIFIER @28:8 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @28:8 +TOKEN @28:14 +IDENTIFIER @28:16 id list Expressions.list [v package] : java.util.List : java.util.List +TOKEN @28:16 +TOKEN @28:21 +NEW_CLASS @28:23 new ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ArrayList flags [public] overridden [AbstractList.[], AbstractCollection.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @28:23 +PARAMETERIZED_TYPE @28:27 : java.util.ArrayList +IDENTIFIER @28:27 id ArrayList ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList +TOKEN @28:27 +TYPE_ARGUMENTS @28:36 +TOKEN @28:36 +TOKEN @28:37 +ARGUMENTS @28:38 +TOKEN @28:38 +TOKEN @28:39 +TOKEN @28:40 +VARIABLE @29:3 var Expressions.type [v package] : java.lang.Class + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @29:3 : java.lang.Class +IDENTIFIER @29:3 id Class java.lang.Class [t final public] : java.lang.Class : java.lang.Class +TOKEN @29:3 +TYPE_ARGUMENTS @29:8 +TOKEN @29:8 +UNBOUNDED_WILDCARD @29:9 +TOKEN @29:9 +TOKEN @29:10 +IDENTIFIER @29:12 id type Expressions.type [v package] : java.lang.Class : java.lang.Class +TOKEN @29:12 +TOKEN @29:17 +MEMBER_SELECT @29:19 : java.lang.Class +IDENTIFIER @29:19 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @29:19 +TOKEN @29:25 +IDENTIFIER @29:26 id class unknown : ? +TOKEN @29:26 +TOKEN @29:31 +VARIABLE @30:3 var Expressions.arrayType [v package] : java.lang.Class + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @30:3 : java.lang.Class +IDENTIFIER @30:3 id Class java.lang.Class [t final public] : java.lang.Class : java.lang.Class +TOKEN @30:3 +TYPE_ARGUMENTS @30:8 +TOKEN @30:8 +UNBOUNDED_WILDCARD @30:9 +TOKEN @30:9 +TOKEN @30:10 +IDENTIFIER @30:12 id arrayType Expressions.arrayType [v package] : java.lang.Class : java.lang.Class +TOKEN @30:12 +TOKEN @30:22 +MEMBER_SELECT @30:24 : java.lang.Class +ARRAY_TYPE @30:24 : int[] +PRIMITIVE_TYPE @30:24 : int +TOKEN @30:24 +TOKEN @30:27 +TOKEN @30:28 +TOKEN @30:29 +IDENTIFIER @30:30 id class unknown : ? +TOKEN @30:30 +TOKEN @30:35 +VARIABLE @31:3 var Expressions.concat [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @31:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @31:3 +IDENTIFIER @31:10 id concat Expressions.concat [v package] : java.lang.String : java.lang.String +TOKEN @31:10 +TOKEN @31:17 +PLUS @31:19 : java.lang.String +PLUS @31:19 : java.lang.String +PLUS @31:19 : java.lang.String +PLUS @31:19 : java.lang.String = a1c +PLUS @31:19 : java.lang.String = a1 +STRING_LITERAL @31:19 : java.lang.String = a +TOKEN @31:19 +TOKEN @31:23 +INT_LITERAL @31:25 : int = 1 +TOKEN @31:25 +TOKEN @31:27 +CHAR_LITERAL @31:29 : char = 99 +TOKEN @31:29 +TOKEN @31:33 +DOUBLE_LITERAL @31:35 : double +TOKEN @31:35 +TOKEN @31:39 +BOOLEAN_LITERAL @31:41 : boolean = true +TOKEN @31:41 +TOKEN @31:46 +NULL_LITERAL @31:48 : +TOKEN @31:48 +TOKEN @31:52 +VARIABLE @32:3 var Expressions.self [v package] : java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @32:3 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @32:3 +IDENTIFIER @32:10 id self Expressions.self [v package] : java.lang.Object : java.lang.Object +TOKEN @32:10 +TOKEN @32:15 +IDENTIFIER @32:17 id this Expressions.this [v final] : Expressions : Expressions +TOKEN @32:17 +TOKEN @32:21 +VARIABLE @33:3 var Expressions.shift [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @33:3 : int +TOKEN @33:3 +IDENTIFIER @33:7 id shift Expressions.shift [v package] : int : int +TOKEN @33:7 +TOKEN @33:13 +UNSIGNED_RIGHT_SHIFT @33:15 : int +RIGHT_SHIFT @33:15 : int +IDENTIFIER @33:15 id a Expressions.a [v package] : int : int +TOKEN @33:15 +TOKEN @33:17 +INT_LITERAL @33:20 : int = 1 +TOKEN @33:20 +TOKEN @33:22 +INT_LITERAL @33:26 : int = 2 +TOKEN @33:26 +TOKEN @33:27 +VARIABLE @34:3 var Expressions.negated [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @34:3 : int +TOKEN @34:3 +IDENTIFIER @34:7 id negated Expressions.negated [v package] : int : int +TOKEN @34:7 +TOKEN @34:15 +PLUS @34:17 : int +UNARY_MINUS @34:17 : int +TOKEN @34:17 +IDENTIFIER @34:18 id a Expressions.a [v package] : int : int +TOKEN @34:18 +TOKEN @34:20 +UNARY_PLUS @34:22 : int +TOKEN @34:22 +IDENTIFIER @34:23 id b Expressions.b [v package] : int : int +TOKEN @34:23 +TOKEN @34:24 +VARIABLE @35:3 var Expressions.nextLetter [v package] : char + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @35:3 : char +TOKEN @35:3 +IDENTIFIER @35:8 id nextLetter Expressions.nextLetter [v package] : char : char +TOKEN @35:8 +TOKEN @35:19 +TYPE_CAST @35:21 : char +TOKEN @35:21 +PRIMITIVE_TYPE @35:22 : char +TOKEN @35:22 +LIST +TOKEN @35:26 +PARENTHESIZED_EXPRESSION @35:28 : int = 98 +TOKEN @35:28 +PLUS @35:29 : int = 98 +IDENTIFIER @35:29 id LETTER Expressions.LETTER [v static final package] : char : char = 97 +TOKEN @35:29 +TOKEN @35:36 +INT_LITERAL @35:38 : int = 1 +TOKEN @35:38 +TOKEN @35:39 +TOKEN @35:40 +VARIABLE @36:3 var Expressions.small [v package] : byte + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @36:3 : byte +TOKEN @36:3 +IDENTIFIER @36:8 id small Expressions.small [v package] : byte : byte +TOKEN @36:8 +TOKEN @36:14 +TYPE_CAST @36:16 : byte +TOKEN @36:16 +PRIMITIVE_TYPE @36:17 : byte +TOKEN @36:17 +LIST +TOKEN @36:21 +INT_LITERAL @36:23 : int = 200 +TOKEN @36:23 +TOKEN @36:26 +VARIABLE @37:3 var Expressions.shortValue [v package] : short + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @37:3 : short +TOKEN @37:3 +IDENTIFIER @37:9 id shortValue Expressions.shortValue [v package] : short : short +TOKEN @37:9 +TOKEN @37:20 +INT_LITERAL @37:22 : int = 10 +TOKEN @37:22 +TOKEN @37:24 +VARIABLE @38:3 var Expressions.boxed [v package] : java.lang.Integer + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @38:3 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @38:3 +IDENTIFIER @38:11 id boxed Expressions.boxed [v package] : java.lang.Integer : java.lang.Integer +TOKEN @38:11 +TOKEN @38:17 +IDENTIFIER @38:19 id a Expressions.a [v package] : int : int +TOKEN @38:19 +TOKEN @38:20 +VARIABLE @39:3 var Expressions.unboxed [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @39:3 : int +TOKEN @39:3 +IDENTIFIER @39:7 id unboxed Expressions.unboxed [v package] : int : int +TOKEN @39:7 +TOKEN @39:15 +IDENTIFIER @39:17 id boxed Expressions.boxed [v package] : java.lang.Integer : java.lang.Integer +TOKEN @39:17 +TOKEN @39:22 +VARIABLE @40:3 var Expressions.text [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @40:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @40:3 +IDENTIFIER @40:10 id text Expressions.text [v package] : java.lang.String : java.lang.String +TOKEN @40:10 +TOKEN @40:15 +METHOD_INVOCATION @40:17 call String.toUpperCase [m public] : ? () returns java.lang.String throws [] sig java.lang.String#toUpperCase()Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @40:17 : ? +METHOD_INVOCATION @40:17 call String.trim [m public] : ? () returns java.lang.String throws [] sig java.lang.String#trim()Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @40:17 : ? +METHOD_INVOCATION @40:17 call String.valueOf [m static public] : ? (int) returns java.lang.String throws [] sig java.lang.String#valueOf(I)Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @40:17 : ? +IDENTIFIER @40:17 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @40:17 +TOKEN @40:23 +IDENTIFIER @40:24 id valueOf String.valueOf [m static public] : ? (int) returns java.lang.String throws [] sig java.lang.String#valueOf(I)Ljava/lang/String; : java.lang.String +TOKEN @40:24 +ARGUMENTS @40:31 +TOKEN @40:31 +IDENTIFIER @40:32 id a Expressions.a [v package] : int : int +TOKEN @40:32 +TOKEN @40:33 +TOKEN @40:34 +IDENTIFIER @40:35 id trim String.trim [m public] : ? () returns java.lang.String throws [] sig java.lang.String#trim()Ljava/lang/String; : java.lang.String +TOKEN @40:35 +ARGUMENTS @40:39 +TOKEN @40:39 +TOKEN @40:40 +TOKEN @40:41 +IDENTIFIER @40:42 id toUpperCase String.toUpperCase [m public] : ? () returns java.lang.String throws [] sig java.lang.String#toUpperCase()Ljava/lang/String; : java.lang.String +TOKEN @40:42 +ARGUMENTS @40:53 +TOKEN @40:53 +TOKEN @40:54 +TOKEN @40:55 +VARIABLE @41:3 var Expressions.size [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @41:3 : int +TOKEN @41:3 +IDENTIFIER @41:7 id size Expressions.size [v package] : int : int +TOKEN @41:7 +TOKEN @41:12 +METHOD_INVOCATION @41:14 call List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.size[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @41:14 : ? +IDENTIFIER @41:14 id list Expressions.list [v package] : java.util.List : java.util.List +TOKEN @41:14 +TOKEN @41:18 +IDENTIFIER @41:19 id size List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int +TOKEN @41:19 +ARGUMENTS @41:23 +TOKEN @41:23 +TOKEN @41:24 +TOKEN @41:25 +VARIABLE @42:3 var Expressions.empty [v package] : boolean + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @42:3 : boolean +TOKEN @42:3 +IDENTIFIER @42:11 id empty Expressions.empty [v package] : boolean : boolean +TOKEN @42:11 +TOKEN @42:17 +CONDITIONAL_AND @42:19 : boolean +METHOD_INVOCATION @42:19 call List.isEmpty [m abstract public] : ? () returns boolean throws [] sig java.util.List#isEmpty()Z : boolean + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.isEmpty[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @42:19 : ? +IDENTIFIER @42:19 id list Expressions.list [v package] : java.util.List : java.util.List +TOKEN @42:19 +TOKEN @42:23 +IDENTIFIER @42:24 id isEmpty List.isEmpty [m abstract public] : ? () returns boolean throws [] sig java.util.List#isEmpty()Z : boolean +TOKEN @42:24 +ARGUMENTS @42:31 +TOKEN @42:31 +TOKEN @42:32 +TOKEN @42:34 +METHOD_INVOCATION @42:37 call List.contains [m abstract public] : ? (java.lang.Object) returns boolean throws [] sig java.util.List#contains(Ljava/lang/Object;)Z : boolean + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.contains[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @42:37 : ? +IDENTIFIER @42:37 id list Expressions.list [v package] : java.util.List : java.util.List +TOKEN @42:37 +TOKEN @42:41 +IDENTIFIER @42:42 id contains List.contains [m abstract public] : ? (java.lang.Object) returns boolean throws [] sig java.util.List#contains(Ljava/lang/Object;)Z : boolean +TOKEN @42:42 +ARGUMENTS @42:50 +TOKEN @42:50 +STRING_LITERAL @42:51 : java.lang.String = x +TOKEN @42:51 +TOKEN @42:54 +TOKEN @42:55 +VARIABLE @43:3 var Expressions.created [v package] : java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @43:3 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @43:3 +IDENTIFIER @43:10 id created Expressions.created [v package] : java.lang.Object : java.lang.Object +TOKEN @43:10 +TOKEN @43:18 +NEW_CLASS @43:20 new Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : Expressions$1 + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @43:20 +IDENTIFIER @43:24 id Object Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : java.lang.Object +TOKEN @43:24 +ARGUMENTS @43:30 +TOKEN @43:30 +TOKEN @43:31 +CLASS @43:33 class Expressions. [t package] : Expressions$1 super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] members [, toString] lookupToString 1 outermost Expressions annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring +MODIFIERS +TYPE_PARAMETERS +LIST +LIST +TOKEN @43:33 +METHOD @44:5 method .toString [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Expressions$1#toString()Ljava/lang/String; overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing flags [public] overridden [Object.toString[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @44:5 +ANNOTATION @44:5 : java.lang.Override +TOKEN @44:5 +IDENTIFIER @44:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @44:6 +ARGUMENTS +TOKEN @45:5 +TYPE_PARAMETERS +IDENTIFIER @45:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @45:12 +IDENTIFIER @45:19 id toString .toString [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Expressions$1#toString()Ljava/lang/String; : java.lang.String +TOKEN @45:19 +TOKEN @45:27 +TOKEN @45:28 +BLOCK @45:30 +TOKEN @45:30 +RETURN_STATEMENT @46:7 +TOKEN @46:7 +STRING_LITERAL @46:14 : java.lang.String = anonymous +TOKEN @46:14 +TOKEN @46:25 +TOKEN @47:5 +TOKEN @48:3 +TOKEN @48:4 +VARIABLE @49:3 var Expressions.inner [v package] : Expressions$Inner + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @49:3 id Inner Expressions.Inner [t package] : Expressions$Inner : Expressions$Inner +TOKEN @49:3 +IDENTIFIER @49:9 id inner Expressions.inner [v package] : Expressions$Inner : Expressions$Inner +TOKEN @49:9 +TOKEN @49:15 +NEW_CLASS @49:17 new Inner. [m package] : ? () returns void throws [] sig Expressions$Inner#(LExpressions;)V : Expressions$Inner + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Inner flags [package] overridden [Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @49:17 +IDENTIFIER @49:21 id Inner Inner. [m package] : ? () returns void throws [] sig Expressions$Inner#(LExpressions;)V : Expressions$Inner +TOKEN @49:21 +ARGUMENTS @49:26 +TOKEN @49:26 +TOKEN @49:27 +TOKEN @49:28 +VARIABLE @50:3 var Expressions.deep [v package] : Expressions$Inner$Deep + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +MEMBER_SELECT @50:3 : Expressions$Inner$Deep +IDENTIFIER @50:3 id Inner Expressions.Inner [t package] : Expressions$Inner : Expressions$Inner +TOKEN @50:3 +TOKEN @50:8 +IDENTIFIER @50:9 id Deep Inner.Deep [t package] : Expressions$Inner$Deep : Expressions$Inner$Deep +TOKEN @50:9 +IDENTIFIER @50:14 id deep Expressions.deep [v package] : Expressions$Inner$Deep : Expressions$Inner$Deep +TOKEN @50:14 +TOKEN @50:19 +NEW_CLASS @50:21 new unknown : ? +IDENTIFIER @50:21 id inner Expressions.inner [v package] : Expressions$Inner : Expressions$Inner +TOKEN @50:21 +TOKEN @50:26 +TOKEN @50:27 +IDENTIFIER @50:31 id Deep unknown : ? +TOKEN @50:31 +ARGUMENTS @50:35 +TOKEN @50:35 +TOKEN @50:36 +TOKEN @50:37 +VARIABLE @51:3 var Expressions.innerValue [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @51:3 : int +TOKEN @51:3 +IDENTIFIER @51:7 id innerValue Expressions.innerValue [v package] : int : int +TOKEN @51:7 +TOKEN @51:18 +MEMBER_SELECT @51:20 : int +IDENTIFIER @51:20 id inner Expressions.inner [v package] : Expressions$Inner : Expressions$Inner +TOKEN @51:20 +TOKEN @51:25 +IDENTIFIER @51:26 id value Inner.value [v package] : int : int +TOKEN @51:26 +TOKEN @51:31 +VARIABLE @52:3 var Expressions.qualified [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @52:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @52:3 +IDENTIFIER @52:10 id qualified Expressions.qualified [v package] : java.lang.String : java.lang.String +TOKEN @52:10 +TOKEN @52:20 +METHOD_INVOCATION @52:22 call Locale.toString [m final public] : ? () returns java.lang.String throws [] sig java.util.Locale#toString()Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Locale flags [final, public] overridden [Object.toString[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @52:22 : ? +MEMBER_SELECT @52:22 : java.util.Locale +MEMBER_SELECT @52:22 : java.util.Locale +MEMBER_SELECT @52:22 : ? +IDENTIFIER @52:22 id java .java [p package] : ? : ? +TOKEN @52:22 +TOKEN @52:26 +IDENTIFIER @52:27 id util .java.util [p package] : ? : ? +TOKEN @52:27 +TOKEN @52:31 +IDENTIFIER @52:32 id Locale java.util.Locale [t final public] : java.util.Locale : java.util.Locale +TOKEN @52:32 +TOKEN @52:38 +IDENTIFIER @52:39 id ROOT Locale.ROOT [v static final public] : java.util.Locale : java.util.Locale +TOKEN @52:39 +TOKEN @52:43 +IDENTIFIER @52:44 id toString Locale.toString [m final public] : ? () returns java.lang.String throws [] sig java.util.Locale#toString()Ljava/lang/String; : java.lang.String +TOKEN @52:44 +ARGUMENTS @52:52 +TOKEN @52:52 +TOKEN @52:53 +TOKEN @52:54 +METHOD @54:3 method Expressions.assign [m package] : ? () returns int throws [] sig Expressions#assign()I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @54:3 : int +TOKEN @54:3 +IDENTIFIER @54:7 id assign Expressions.assign [m package] : ? () returns int throws [] sig Expressions#assign()I : int +TOKEN @54:7 +TOKEN @54:13 +TOKEN @54:14 +BLOCK @54:16 +TOKEN @54:16 +VARIABLE @55:5 var assign.x [v package] : int + details declared true usages 16 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] local true parameter false effectivelyFinal false constant null owner assign Expressions#assign()I [package] returns int parameters 0 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Expressions type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +PRIMITIVE_TYPE @55:5 : int +TOKEN @55:5 +IDENTIFIER @55:9 id x assign.x [v package] : int : int +TOKEN @55:9 +TOKEN @55:11 +INT_LITERAL @55:13 : int = 0 +TOKEN @55:13 +TOKEN @55:14 +EXPRESSION_STATEMENT @56:5 +PLUS_ASSIGNMENT @56:5 : int +IDENTIFIER @56:5 id x assign.x [v package] : int : int +TOKEN @56:5 +TOKEN @56:7 +INT_LITERAL @56:10 : int = 1 +TOKEN @56:10 +TOKEN @56:11 +EXPRESSION_STATEMENT @57:5 +MINUS_ASSIGNMENT @57:5 : int +IDENTIFIER @57:5 id x assign.x [v package] : int : int +TOKEN @57:5 +TOKEN @57:7 +INT_LITERAL @57:10 : int = 2 +TOKEN @57:10 +TOKEN @57:11 +EXPRESSION_STATEMENT @58:5 +MULTIPLY_ASSIGNMENT @58:5 : int +IDENTIFIER @58:5 id x assign.x [v package] : int : int +TOKEN @58:5 +TOKEN @58:7 +INT_LITERAL @58:10 : int = 3 +TOKEN @58:10 +TOKEN @58:11 +EXPRESSION_STATEMENT @59:5 +DIVIDE_ASSIGNMENT @59:5 : int +IDENTIFIER @59:5 id x assign.x [v package] : int : int +TOKEN @59:5 +TOKEN @59:7 +INT_LITERAL @59:10 : int = 4 +TOKEN @59:10 +TOKEN @59:11 +EXPRESSION_STATEMENT @60:5 +REMAINDER_ASSIGNMENT @60:5 : int +IDENTIFIER @60:5 id x assign.x [v package] : int : int +TOKEN @60:5 +TOKEN @60:7 +INT_LITERAL @60:10 : int = 5 +TOKEN @60:10 +TOKEN @60:11 +EXPRESSION_STATEMENT @61:5 +LEFT_SHIFT_ASSIGNMENT @61:5 : int +IDENTIFIER @61:5 id x assign.x [v package] : int : int +TOKEN @61:5 +TOKEN @61:7 +INT_LITERAL @61:11 : int = 1 +TOKEN @61:11 +TOKEN @61:12 +EXPRESSION_STATEMENT @62:5 +RIGHT_SHIFT_ASSIGNMENT @62:5 : int +IDENTIFIER @62:5 id x assign.x [v package] : int : int +TOKEN @62:5 +TOKEN @62:7 +INT_LITERAL @62:11 : int = 1 +TOKEN @62:11 +TOKEN @62:12 +EXPRESSION_STATEMENT @63:5 +UNSIGNED_RIGHT_SHIFT_ASSIGNMENT @63:5 : int +IDENTIFIER @63:5 id x assign.x [v package] : int : int +TOKEN @63:5 +TOKEN @63:7 +INT_LITERAL @63:12 : int = 1 +TOKEN @63:12 +TOKEN @63:13 +EXPRESSION_STATEMENT @64:5 +AND_ASSIGNMENT @64:5 : int +IDENTIFIER @64:5 id x assign.x [v package] : int : int +TOKEN @64:5 +TOKEN @64:7 +INT_LITERAL @64:10 : int = 7 +TOKEN @64:10 +TOKEN @64:11 +EXPRESSION_STATEMENT @65:5 +OR_ASSIGNMENT @65:5 : int +IDENTIFIER @65:5 id x assign.x [v package] : int : int +TOKEN @65:5 +TOKEN @65:7 +INT_LITERAL @65:10 : int = 8 +TOKEN @65:10 +TOKEN @65:11 +EXPRESSION_STATEMENT @66:5 +XOR_ASSIGNMENT @66:5 : int +IDENTIFIER @66:5 id x assign.x [v package] : int : int +TOKEN @66:5 +TOKEN @66:7 +INT_LITERAL @66:10 : int = 9 +TOKEN @66:10 +TOKEN @66:11 +EXPRESSION_STATEMENT @67:5 +POSTFIX_INCREMENT @67:5 : int +IDENTIFIER @67:5 id x assign.x [v package] : int : int +TOKEN @67:5 +TOKEN @67:6 +TOKEN @67:8 +EXPRESSION_STATEMENT @68:5 +POSTFIX_DECREMENT @68:5 : int +IDENTIFIER @68:5 id x assign.x [v package] : int : int +TOKEN @68:5 +TOKEN @68:6 +TOKEN @68:8 +EXPRESSION_STATEMENT @69:5 +PREFIX_INCREMENT @69:5 : int +TOKEN @69:5 +IDENTIFIER @69:7 id x assign.x [v package] : int : int +TOKEN @69:7 +TOKEN @69:8 +EXPRESSION_STATEMENT @70:5 +PREFIX_DECREMENT @70:5 : int +TOKEN @70:5 +IDENTIFIER @70:7 id x assign.x [v package] : int : int +TOKEN @70:7 +TOKEN @70:8 +RETURN_STATEMENT @71:5 +TOKEN @71:5 +IDENTIFIER @71:12 id x assign.x [v package] : int : int +TOKEN @71:12 +TOKEN @71:13 +TOKEN @72:3 +METHOD @74:3 method Expressions.superCall [m package] : ? () returns java.lang.String throws [] sig Expressions#superCall()Ljava/lang/String; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @74:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @74:3 +IDENTIFIER @74:10 id superCall Expressions.superCall [m package] : ? () returns java.lang.String throws [] sig Expressions#superCall()Ljava/lang/String; : java.lang.String +TOKEN @74:10 +TOKEN @74:19 +TOKEN @74:20 +BLOCK @74:22 +TOKEN @74:22 +RETURN_STATEMENT @75:5 +TOKEN @75:5 +PLUS @75:12 : java.lang.String +METHOD_INVOCATION @75:12 call Object.toString [m public] : ? () returns java.lang.String throws [] sig java.lang.Object#toString()Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @75:12 : ? +IDENTIFIER @75:12 id super Expressions.super [v final] : java.lang.Object : java.lang.Object +TOKEN @75:12 +TOKEN @75:17 +IDENTIFIER @75:18 id toString Object.toString [m public] : ? () returns java.lang.String throws [] sig java.lang.Object#toString()Ljava/lang/String; : java.lang.String +TOKEN @75:18 +ARGUMENTS @75:26 +TOKEN @75:26 +TOKEN @75:27 +TOKEN @75:29 +METHOD_INVOCATION @75:31 call Object.hashCode [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns int throws [] sig java.lang.Object#hashCode()I : int + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @75:31 : ? +MEMBER_SELECT @75:31 : Expressions +IDENTIFIER @75:31 id Expressions .Expressions [t package] : Expressions : Expressions +TOKEN @75:31 +TOKEN @75:42 +IDENTIFIER @75:43 id this Expressions.this [v final] : Expressions : Expressions +TOKEN @75:43 +TOKEN @75:47 +IDENTIFIER @75:48 id hashCode Object.hashCode [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns int throws [] sig java.lang.Object#hashCode()I : int +TOKEN @75:48 +ARGUMENTS @75:56 +TOKEN @75:56 +TOKEN @75:57 +TOKEN @75:58 +TOKEN @76:3 +CLASS @78:3 class Expressions.Inner [t package] : Expressions$Inner super java.lang.Object interfaces [] + details declared true usages 3 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Expressions flags [package] members [, Deep, value] lookupToString 0 outermost Expressions annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Inner +MODIFIERS +TOKEN @78:3 +IDENTIFIER @78:9 id Inner Expressions.Inner [t package] : Expressions$Inner : Expressions$Inner +TOKEN @78:9 +TYPE_PARAMETERS +LIST +LIST +TOKEN @78:15 +VARIABLE @79:5 var Inner.value [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Inner flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @79:5 : int +TOKEN @79:5 +IDENTIFIER @79:9 id value Inner.value [v package] : int : int +TOKEN @79:9 +TOKEN @79:15 +IDENTIFIER @79:17 id SIZE Expressions.SIZE [v static final package] : int : int = 4 +TOKEN @79:17 +TOKEN @79:21 +CLASS @81:5 class Inner.Deep [t package] : Expressions$Inner$Deep super java.lang.Object interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Inner flags [package] members [] lookupToString 0 outermost Expressions annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Deep +MODIFIERS +TOKEN @81:5 +IDENTIFIER @81:11 id Deep Inner.Deep [t package] : Expressions$Inner$Deep : Expressions$Inner$Deep +TOKEN @81:11 +TYPE_PARAMETERS +LIST +LIST +TOKEN @81:16 +TOKEN @82:5 +TOKEN @83:3 +TOKEN @84:1 +TOKEN @85:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Expressions.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Expressions.java new file mode 100644 index 00000000000..0a68ff21883 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Expressions.java @@ -0,0 +1,84 @@ +import java.util.ArrayList; +import java.util.List; + +class Expressions { + + static final int SIZE = 4; + static final String NAME = "expr" + SIZE; + static final long BIG = 1L << 40; + static final char LETTER = 'a'; + static final double RATIO = 1.5e3; + static final float SMALL = 2.5f; + static final boolean FLAG = !false && (SIZE > 2 || SIZE <= 1); + static final int HEX = 0xFF & 0b1010 | 017 ^ ~3; + + int a = 1; + int b = a + 2 * 3 - 4 / 2 % 3; + long c = a + 1L; + double d = a / 2.0; + int e = (int) d; + Object o = "text"; + boolean isString = o instanceof String; + String s = isString ? (String) o : null; + int[] array = new int[SIZE]; + int[][] matrix = {{1, 2}, {3}}; + int[] init = new int[] {1, 2, 3}; + int first = init[0]; + int length = init.length; + List list = new ArrayList<>(); + Class type = String.class; + Class arrayType = int[].class; + String concat = "a" + 1 + 'c' + 2.0 + true + null; + Object self = this; + int shift = a >> 1 >>> 2; + int negated = -a + +b; + char nextLetter = (char) (LETTER + 1); + byte small = (byte) 200; + short shortValue = 10; + Integer boxed = a; + int unboxed = boxed; + String text = String.valueOf(a).trim().toUpperCase(); + int size = list.size(); + boolean empty = list.isEmpty() && list.contains("x"); + Object created = new Object() { + @Override + public String toString() { + return "anonymous"; + } + }; + Inner inner = new Inner(); + Inner.Deep deep = inner.new Deep(); + int innerValue = inner.value; + String qualified = java.util.Locale.ROOT.toString(); + + int assign() { + int x = 0; + x += 1; + x -= 2; + x *= 3; + x /= 4; + x %= 5; + x <<= 1; + x >>= 1; + x >>>= 1; + x &= 7; + x |= 8; + x ^= 9; + x++; + x--; + ++x; + --x; + return x; + } + + String superCall() { + return super.toString() + Expressions.this.hashCode(); + } + + class Inner { + int value = SIZE; + + class Deep { + } + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Expressions.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Expressions.textproto.gz new file mode 100644 index 00000000000..10fb7e72050 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Expressions.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/GenericEdges.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/GenericEdges.expected.txt new file mode 100644 index 00000000000..0c6f76aecfa --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/GenericEdges.expected.txt @@ -0,0 +1,1813 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id io unknown : ? +TOKEN @1:13 +TOKEN @1:15 +IDENTIFIER @1:16 id IOException unknown : ? +TOKEN @1:16 +TOKEN @1:27 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id util unknown : ? +TOKEN @2:13 +TOKEN @2:17 +IDENTIFIER @2:18 id ArrayList unknown : ? +TOKEN @2:18 +TOKEN @2:27 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id util unknown : ? +TOKEN @3:13 +TOKEN @3:17 +IDENTIFIER @3:18 id Collection unknown : ? +TOKEN @3:18 +TOKEN @3:28 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id util unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id Comparator unknown : ? +TOKEN @4:18 +TOKEN @4:28 +IMPORT @5:1 +TOKEN @5:1 +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +IDENTIFIER @5:8 id java unknown : ? +TOKEN @5:8 +TOKEN @5:12 +IDENTIFIER @5:13 id util unknown : ? +TOKEN @5:13 +TOKEN @5:17 +IDENTIFIER @5:18 id HashMap unknown : ? +TOKEN @5:18 +TOKEN @5:25 +IMPORT @6:1 +TOKEN @6:1 +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +IDENTIFIER @6:8 id java unknown : ? +TOKEN @6:8 +TOKEN @6:12 +IDENTIFIER @6:13 id util unknown : ? +TOKEN @6:13 +TOKEN @6:17 +IDENTIFIER @6:18 id Iterator unknown : ? +TOKEN @6:18 +TOKEN @6:26 +IMPORT @7:1 +TOKEN @7:1 +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +IDENTIFIER @7:8 id java unknown : ? +TOKEN @7:8 +TOKEN @7:12 +IDENTIFIER @7:13 id util unknown : ? +TOKEN @7:13 +TOKEN @7:17 +IDENTIFIER @7:18 id List unknown : ? +TOKEN @7:18 +TOKEN @7:22 +IMPORT @8:1 +TOKEN @8:1 +MEMBER_SELECT @8:8 : ? +MEMBER_SELECT @8:8 : ? +IDENTIFIER @8:8 id java unknown : ? +TOKEN @8:8 +TOKEN @8:12 +IDENTIFIER @8:13 id util unknown : ? +TOKEN @8:13 +TOKEN @8:17 +IDENTIFIER @8:18 id Map unknown : ? +TOKEN @8:18 +TOKEN @8:21 +IMPORT @9:1 +TOKEN @9:1 +MEMBER_SELECT @9:8 : ? +MEMBER_SELECT @9:8 : ? +IDENTIFIER @9:8 id java unknown : ? +TOKEN @9:8 +TOKEN @9:12 +IDENTIFIER @9:13 id util unknown : ? +TOKEN @9:13 +TOKEN @9:17 +IDENTIFIER @9:18 id Optional unknown : ? +TOKEN @9:18 +TOKEN @9:26 +IMPORT @10:1 +TOKEN @10:1 +MEMBER_SELECT @10:8 : ? +MEMBER_SELECT @10:8 : ? +MEMBER_SELECT @10:8 : ? +IDENTIFIER @10:8 id java unknown : ? +TOKEN @10:8 +TOKEN @10:12 +IDENTIFIER @10:13 id util unknown : ? +TOKEN @10:13 +TOKEN @10:17 +IDENTIFIER @10:18 id concurrent unknown : ? +TOKEN @10:18 +TOKEN @10:28 +IDENTIFIER @10:29 id Callable unknown : ? +TOKEN @10:29 +TOKEN @10:37 +IMPORT @11:1 +TOKEN @11:1 +MEMBER_SELECT @11:8 : ? +MEMBER_SELECT @11:8 : ? +MEMBER_SELECT @11:8 : ? +IDENTIFIER @11:8 id java unknown : ? +TOKEN @11:8 +TOKEN @11:12 +IDENTIFIER @11:13 id util unknown : ? +TOKEN @11:13 +TOKEN @11:17 +IDENTIFIER @11:18 id function unknown : ? +TOKEN @11:18 +TOKEN @11:26 +IDENTIFIER @11:27 id BiFunction unknown : ? +TOKEN @11:27 +TOKEN @11:37 +IMPORT @12:1 +TOKEN @12:1 +MEMBER_SELECT @12:8 : ? +MEMBER_SELECT @12:8 : ? +MEMBER_SELECT @12:8 : ? +IDENTIFIER @12:8 id java unknown : ? +TOKEN @12:8 +TOKEN @12:12 +IDENTIFIER @12:13 id util unknown : ? +TOKEN @12:13 +TOKEN @12:17 +IDENTIFIER @12:18 id function unknown : ? +TOKEN @12:18 +TOKEN @12:26 +IDENTIFIER @12:27 id Function unknown : ? +TOKEN @12:27 +TOKEN @12:35 +IMPORT @13:1 +TOKEN @13:1 +MEMBER_SELECT @13:8 : ? +MEMBER_SELECT @13:8 : ? +MEMBER_SELECT @13:8 : ? +IDENTIFIER @13:8 id java unknown : ? +TOKEN @13:8 +TOKEN @13:12 +IDENTIFIER @13:13 id util unknown : ? +TOKEN @13:13 +TOKEN @13:17 +IDENTIFIER @13:18 id function unknown : ? +TOKEN @13:18 +TOKEN @13:26 +IDENTIFIER @13:27 id Supplier unknown : ? +TOKEN @13:27 +TOKEN @13:35 +IMPORT @14:1 +TOKEN @14:1 +MEMBER_SELECT @14:8 : ? +MEMBER_SELECT @14:8 : ? +MEMBER_SELECT @14:8 : ? +IDENTIFIER @14:8 id java unknown : ? +TOKEN @14:8 +TOKEN @14:12 +IDENTIFIER @14:13 id util unknown : ? +TOKEN @14:13 +TOKEN @14:17 +IDENTIFIER @14:18 id stream unknown : ? +TOKEN @14:18 +TOKEN @14:24 +IDENTIFIER @14:25 id Collectors unknown : ? +TOKEN @14:25 +TOKEN @14:35 +IMPORT @15:1 +TOKEN @15:1 +MEMBER_SELECT @15:8 : ? +MEMBER_SELECT @15:8 : ? +MEMBER_SELECT @15:8 : ? +IDENTIFIER @15:8 id java unknown : ? +TOKEN @15:8 +TOKEN @15:12 +IDENTIFIER @15:13 id util unknown : ? +TOKEN @15:13 +TOKEN @15:17 +IDENTIFIER @15:18 id stream unknown : ? +TOKEN @15:18 +TOKEN @15:24 +IDENTIFIER @15:25 id Stream unknown : ? +TOKEN @15:25 +TOKEN @15:31 +CLASS @17:1 class .GenericEdges [t package] : GenericEdges super java.lang.Object interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] members [, Node, Outer, Thrower, call, edges, mapAll, nodes] lookupToString 0 outermost GenericEdges annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw true declaring GenericEdges +MODIFIERS +TOKEN @17:1 +IDENTIFIER @17:7 id GenericEdges .GenericEdges [t package] : GenericEdges : GenericEdges +TOKEN @17:7 +TYPE_PARAMETERS @17:19 +TOKEN @17:19 +TYPE_PARAMETER @17:20 +IDENTIFIER @17:20 id K GenericEdges.K [t package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @17:20 +TOKEN @17:21 +TYPE_PARAMETER @17:23 +IDENTIFIER @17:23 id V GenericEdges.V [t package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @17:23 +TOKEN @17:24 +LIST +LIST +TOKEN @17:26 +CLASS @19:3 class GenericEdges.Node [t package] : GenericEdges$Node super java.lang.Object interfaces [] + details declared true usages 2 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] members [, get, key, value] lookupToString 0 outermost GenericEdges annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Node +MODIFIERS +TOKEN @19:3 +IDENTIFIER @19:9 id Node GenericEdges.Node [t package] : GenericEdges$Node : GenericEdges$Node +TOKEN @19:9 +TYPE_PARAMETERS +LIST +LIST +TOKEN @19:14 +VARIABLE @20:5 var Node.key [v package] : K erasure java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Node flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @20:5 id K GenericEdges.K [t package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @20:5 +IDENTIFIER @20:7 id key Node.key [v package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @20:7 +TOKEN @20:10 +VARIABLE @21:5 var Node.value [v package] : V erasure java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Node flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @21:5 id V GenericEdges.V [t package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @21:5 +IDENTIFIER @21:7 id value Node.value [v package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @21:7 +TOKEN @21:12 +METHOD @23:5 method Node.get [m package] : ? () returns V erasure java.lang.Object throws [] sig GenericEdges$Node#get()Ljava/lang/Object; overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Node flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @23:5 id V GenericEdges.V [t package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @23:5 +IDENTIFIER @23:7 id get Node.get [m package] : ? () returns V erasure java.lang.Object throws [] sig GenericEdges$Node#get()Ljava/lang/Object; : V erasure java.lang.Object +TOKEN @23:7 +TOKEN @23:10 +TOKEN @23:11 +BLOCK @23:13 +TOKEN @23:13 +RETURN_STATEMENT @24:7 +TOKEN @24:7 +IDENTIFIER @24:14 id value Node.value [v package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @24:14 +TOKEN @24:19 +TOKEN @25:5 +TOKEN @26:3 +CLASS @28:3 class GenericEdges.Outer [t static package] : GenericEdges$Outer super java.lang.Object interfaces [] + details declared true usages 4 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [static, package] members [, Inner, make] lookupToString 0 outermost GenericEdges annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw true declaring Outer +MODIFIERS @28:3 +TOKEN @28:3 +TOKEN @28:10 +IDENTIFIER @28:16 id Outer GenericEdges.Outer [t static package] : GenericEdges$Outer : GenericEdges$Outer +TOKEN @28:16 +TYPE_PARAMETERS @28:21 +TOKEN @28:21 +TYPE_PARAMETER @28:22 +IDENTIFIER @28:22 id T Outer.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @28:22 +TOKEN @28:23 +LIST +LIST +TOKEN @28:25 +CLASS @29:5 class Outer.Inner [t package] : GenericEdges$Outer$Inner super java.lang.Object interfaces [] + details declared true usages 4 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Outer flags [package] members [, held, held] lookupToString 0 outermost GenericEdges annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Inner +MODIFIERS +TOKEN @29:5 +IDENTIFIER @29:11 id Inner Outer.Inner [t package] : GenericEdges$Outer$Inner : GenericEdges$Outer$Inner +TOKEN @29:11 +TYPE_PARAMETERS +LIST +LIST +TOKEN @29:17 +VARIABLE @30:7 var Inner.held [v package] : T erasure java.lang.Object + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Inner flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @30:7 id T Outer.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @30:7 +IDENTIFIER @30:9 id held Inner.held [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @30:9 +TOKEN @30:13 +METHOD @32:7 method Inner.held [m package] : ? () returns T erasure java.lang.Object throws [] sig GenericEdges$Outer$Inner#held()Ljava/lang/Object; overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Inner flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @32:7 id T Outer.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @32:7 +IDENTIFIER @32:9 id held Inner.held [m package] : ? () returns T erasure java.lang.Object throws [] sig GenericEdges$Outer$Inner#held()Ljava/lang/Object; : T erasure java.lang.Object +TOKEN @32:9 +TOKEN @32:13 +TOKEN @32:14 +BLOCK @32:16 +TOKEN @32:16 +RETURN_STATEMENT @33:9 +TOKEN @33:9 +IDENTIFIER @33:16 id held Inner.held [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @33:16 +TOKEN @33:20 +TOKEN @34:7 +TOKEN @35:5 +METHOD @37:5 method Outer.make [m package] : ? () returns GenericEdges$Outer$Inner throws [] sig GenericEdges$Outer#make()LGenericEdges$Outer$Inner; overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Outer flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @37:5 id Inner Outer.Inner [t package] : GenericEdges$Outer$Inner : GenericEdges$Outer$Inner +TOKEN @37:5 +IDENTIFIER @37:11 id make Outer.make [m package] : ? () returns GenericEdges$Outer$Inner throws [] sig GenericEdges$Outer#make()LGenericEdges$Outer$Inner; : GenericEdges$Outer$Inner +TOKEN @37:11 +TOKEN @37:15 +TOKEN @37:16 +BLOCK @37:18 +TOKEN @37:18 +RETURN_STATEMENT @38:7 +TOKEN @38:7 +NEW_CLASS @38:14 new Inner. [m package] : ? () returns void throws [] sig GenericEdges$Outer$Inner#(LGenericEdges$Outer;)V : GenericEdges$Outer$Inner + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Inner flags [package] overridden [Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @38:14 +IDENTIFIER @38:18 id Inner Inner. [m package] : ? () returns void throws [] sig GenericEdges$Outer$Inner#(LGenericEdges$Outer;)V : GenericEdges$Outer$Inner +TOKEN @38:18 +ARGUMENTS @38:23 +TOKEN @38:23 +TOKEN @38:24 +TOKEN @38:25 +TOKEN @39:5 +TOKEN @40:3 +INTERFACE @42:3 class GenericEdges.Thrower [t static package interface] : GenericEdges$Thrower super java.lang.Object interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [static, package, interface] members [run] lookupToString 0 outermost GenericEdges annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw true declaring Thrower +MODIFIERS +TOKEN @42:3 +IDENTIFIER @42:13 id Thrower GenericEdges.Thrower [t static package interface] : GenericEdges$Thrower : GenericEdges$Thrower +TOKEN @42:13 +TYPE_PARAMETERS @42:20 +TOKEN @42:20 +TYPE_PARAMETER @42:21 +IDENTIFIER @42:21 id E Thrower.E [t package] : E erasure java.lang.Exception : E erasure java.lang.Exception +TOKEN @42:21 +TOKEN @42:23 +LIST @42:31 +IDENTIFIER @42:31 id Exception java.lang.Exception [t public] : java.lang.Exception : java.lang.Exception +TOKEN @42:31 +TOKEN @42:40 +LIST +LIST +TOKEN @42:42 +METHOD @43:5 method Thrower.run [m abstract public] : ? () returns void throws [E erasure java.lang.Exception] sig GenericEdges$Thrower#run()V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Thrower flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @43:5 : void +TOKEN @43:5 +IDENTIFIER @43:10 id run Thrower.run [m abstract public] : ? () returns void throws [E erasure java.lang.Exception] sig GenericEdges$Thrower#run()V : void +TOKEN @43:10 +TOKEN @43:13 +TOKEN @43:14 +TOKEN @43:16 +LIST @43:23 +IDENTIFIER @43:23 id E Thrower.E [t package] : E erasure java.lang.Exception : E erasure java.lang.Exception +TOKEN @43:23 +TOKEN @43:24 +TOKEN @44:3 +METHOD @46:3 method GenericEdges.call [m static package] : ? (GenericEdges$Thrower) returns void throws [E erasure java.lang.Exception] sig GenericEdges#call(LGenericEdges$Thrower;)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [static, package] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [thrower] parameterMetadata [] +MODIFIERS @46:3 +TOKEN @46:3 +TYPE_PARAMETERS @46:10 +TOKEN @46:10 +TYPE_PARAMETER @46:11 +IDENTIFIER @46:11 id E call.E [t package] : E erasure java.lang.Exception : E erasure java.lang.Exception +TOKEN @46:11 +TOKEN @46:13 +LIST @46:21 +IDENTIFIER @46:21 id Exception java.lang.Exception [t public] : java.lang.Exception : java.lang.Exception +TOKEN @46:21 +TOKEN @46:30 +PRIMITIVE_TYPE @46:32 : void +TOKEN @46:32 +IDENTIFIER @46:37 id call GenericEdges.call [m static package] : ? (GenericEdges$Thrower) returns void throws [E erasure java.lang.Exception] sig GenericEdges#call(LGenericEdges$Thrower;)V : void +TOKEN @46:37 +TOKEN @46:41 +VARIABLE @46:42 var call.thrower [v package] : GenericEdges$Thrower + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter true effectivelyFinal true constant null owner call GenericEdges#call(LGenericEdges$Thrower;)V [static, package] returns void parameters 1 thrown 1 overridden 0 declared true usages 1 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsefalsetrue1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @46:42 : GenericEdges$Thrower +IDENTIFIER @46:42 id Thrower GenericEdges.Thrower [t static package interface] : GenericEdges$Thrower : GenericEdges$Thrower +TOKEN @46:42 +TYPE_ARGUMENTS @46:49 +TOKEN @46:49 +IDENTIFIER @46:50 id E call.E [t package] : E erasure java.lang.Exception : E erasure java.lang.Exception +TOKEN @46:50 +TOKEN @46:51 +IDENTIFIER @46:53 id thrower call.thrower [v package] : GenericEdges$Thrower : GenericEdges$Thrower +TOKEN @46:53 +TOKEN @46:60 +TOKEN @46:62 +LIST @46:69 +IDENTIFIER @46:69 id E call.E [t package] : E erasure java.lang.Exception : E erasure java.lang.Exception +TOKEN @46:69 +BLOCK @46:71 +TOKEN @46:71 +EXPRESSION_STATEMENT @47:5 +METHOD_INVOCATION @47:5 call Thrower.run [m abstract public] : ? () returns void throws [E erasure java.lang.Exception] sig GenericEdges$Thrower#run()V : void + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Thrower flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @47:5 : ? +IDENTIFIER @47:5 id thrower call.thrower [v package] : GenericEdges$Thrower : GenericEdges$Thrower +TOKEN @47:5 +TOKEN @47:12 +IDENTIFIER @47:13 id run Thrower.run [m abstract public] : ? () returns void throws [E erasure java.lang.Exception] sig GenericEdges$Thrower#run()V : void +TOKEN @47:13 +ARGUMENTS @47:16 +TOKEN @47:16 +TOKEN @47:17 +TOKEN @47:18 +TOKEN @48:3 +METHOD @50:3 method GenericEdges.mapAll [m static package] : ? (java.util.Collection,java.util.function.Function) returns java.util.List throws [] sig GenericEdges#mapAll(Ljava/util/Collection;Ljava/util/function/Function;)Ljava/util/List; overrides false + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [static, package] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [input, mapper] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS @50:3 +TOKEN @50:3 +TYPE_PARAMETERS @50:10 +TOKEN @50:10 +TYPE_PARAMETER @50:11 +IDENTIFIER @50:11 id T mapAll.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @50:11 +TOKEN @50:12 +TYPE_PARAMETER @50:14 +IDENTIFIER @50:14 id R mapAll.R [t package] : R erasure java.lang.Object : R erasure java.lang.Object +TOKEN @50:14 +TOKEN @50:15 +PARAMETERIZED_TYPE @50:17 : java.util.List +IDENTIFIER @50:17 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @50:17 +TYPE_ARGUMENTS @50:21 +TOKEN @50:21 +IDENTIFIER @50:22 id R mapAll.R [t package] : R erasure java.lang.Object : R erasure java.lang.Object +TOKEN @50:22 +TOKEN @50:23 +IDENTIFIER @50:25 id mapAll GenericEdges.mapAll [m static package] : ? (java.util.Collection,java.util.function.Function) returns java.util.List throws [] sig GenericEdges#mapAll(Ljava/util/Collection;Ljava/util/function/Function;)Ljava/util/List; : java.util.List +TOKEN @50:25 +TOKEN @50:31 +VARIABLE @50:32 var mapAll.input [v package] : java.util.Collection + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter true effectivelyFinal true constant null owner mapAll GenericEdges#mapAll(Ljava/util/Collection;Ljava/util/function/Function;)Ljava/util/List; [static, package] returns java.util.List parameters 2 thrown 0 overridden 0 declared true usages 2 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsefalsetrue2falsefalse +MODIFIERS +PARAMETERIZED_TYPE @50:32 : java.util.Collection +IDENTIFIER @50:32 id Collection java.util.Collection [t public interface] : java.util.Collection : java.util.Collection +TOKEN @50:32 +TYPE_ARGUMENTS @50:42 +TOKEN @50:42 +EXTENDS_WILDCARD @50:43 +TOKEN @50:43 +TOKEN @50:45 +IDENTIFIER @50:53 id T mapAll.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @50:53 +TOKEN @50:54 +IDENTIFIER @50:56 id input mapAll.input [v package] : java.util.Collection : java.util.Collection +TOKEN @50:56 +TOKEN @50:61 +VARIABLE @50:63 var mapAll.mapper [v package] : java.util.function.Function + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing GenericEdges flags [package] local true parameter true effectivelyFinal true constant null owner mapAll GenericEdges#mapAll(Ljava/util/Collection;Ljava/util/function/Function;)Ljava/util/List; [static, package] returns java.util.List parameters 2 thrown 0 overridden 0 declared true usages 2 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsefalsetrue2falsefalse +MODIFIERS +PARAMETERIZED_TYPE @50:63 : java.util.function.Function +IDENTIFIER @50:63 id Function java.util.function.Function [t public interface] : java.util.function.Function @java.lang.FunctionalInterface : java.util.function.Function +TOKEN @50:63 +TYPE_ARGUMENTS @50:71 +TOKEN @50:71 +SUPER_WILDCARD @50:72 +TOKEN @50:72 +TOKEN @50:74 +IDENTIFIER @50:80 id T mapAll.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @50:80 +TOKEN @50:81 +EXTENDS_WILDCARD @50:83 +TOKEN @50:83 +TOKEN @50:85 +IDENTIFIER @50:93 id R mapAll.R [t package] : R erasure java.lang.Object : R erasure java.lang.Object +TOKEN @50:93 +TOKEN @50:94 +IDENTIFIER @50:96 id mapper mapAll.mapper [v package] : java.util.function.Function : java.util.function.Function +TOKEN @50:96 +TOKEN @50:102 +BLOCK @50:104 +TOKEN @50:104 +VARIABLE @51:5 var mapAll.result [v package] : java.util.List + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner mapAll GenericEdges#mapAll(Ljava/util/Collection;Ljava/util/function/Function;)Ljava/util/List; [static, package] returns java.util.List parameters 2 thrown 0 overridden 0 declared true usages 2 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsefalsetrue2falsefalse +MODIFIERS +PARAMETERIZED_TYPE @51:5 : java.util.List +IDENTIFIER @51:5 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @51:5 +TYPE_ARGUMENTS @51:9 +TOKEN @51:9 +IDENTIFIER @51:10 id R mapAll.R [t package] : R erasure java.lang.Object : R erasure java.lang.Object +TOKEN @51:10 +TOKEN @51:11 +IDENTIFIER @51:13 id result mapAll.result [v package] : java.util.List : java.util.List +TOKEN @51:13 +TOKEN @51:20 +NEW_CLASS @51:22 new ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ArrayList flags [public] overridden [AbstractList.[], AbstractCollection.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @51:22 +PARAMETERIZED_TYPE @51:26 : java.util.ArrayList +IDENTIFIER @51:26 id ArrayList ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList +TOKEN @51:26 +TYPE_ARGUMENTS @51:35 +TOKEN @51:35 +TOKEN @51:36 +ARGUMENTS @51:37 +TOKEN @51:37 +TOKEN @51:38 +TOKEN @51:39 +FOR_EACH_STATEMENT @52:5 +TOKEN @52:5 +TOKEN @52:9 +VARIABLE @52:10 var mapAll.item [v package] : T erasure java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner mapAll GenericEdges#mapAll(Ljava/util/Collection;Ljava/util/function/Function;)Ljava/util/List; [static, package] returns java.util.List parameters 2 thrown 0 overridden 0 declared true usages 2 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsefalsetrue2falsefalse +MODIFIERS +IDENTIFIER @52:10 id T mapAll.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @52:10 +IDENTIFIER @52:12 id item mapAll.item [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @52:12 +TOKEN @52:17 +IDENTIFIER @52:19 id input mapAll.input [v package] : java.util.Collection : java.util.Collection +TOKEN @52:19 +TOKEN @52:24 +BLOCK @52:26 +TOKEN @52:26 +EXPRESSION_STATEMENT @53:7 +METHOD_INVOCATION @53:7 call List.add [m abstract public] : ? (R erasure java.lang.Object) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.add[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @53:7 : ? +IDENTIFIER @53:7 id result mapAll.result [v package] : java.util.List : java.util.List +TOKEN @53:7 +TOKEN @53:13 +IDENTIFIER @53:14 id add List.add [m abstract public] : ? (R erasure java.lang.Object) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean +TOKEN @53:14 +ARGUMENTS @53:17 +TOKEN @53:17 +METHOD_INVOCATION @53:18 call Function.apply [m abstract public] : ? (java.lang.Object) returns R erasure java.lang.Object throws [] sig java.util.function.Function#apply(Ljava/lang/Object;)Ljava/lang/Object; : java.lang.Object + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Function flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @53:18 : ? +IDENTIFIER @53:18 id mapper mapAll.mapper [v package] : java.util.function.Function : java.util.function.Function +TOKEN @53:18 +TOKEN @53:24 +IDENTIFIER @53:25 id apply Function.apply [m abstract public] : ? (java.lang.Object) returns R erasure java.lang.Object throws [] sig java.util.function.Function#apply(Ljava/lang/Object;)Ljava/lang/Object; : java.lang.Object +TOKEN @53:25 +ARGUMENTS @53:30 +TOKEN @53:30 +IDENTIFIER @53:31 id item mapAll.item [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @53:31 +TOKEN @53:35 +TOKEN @53:36 +TOKEN @53:37 +TOKEN @54:5 +RETURN_STATEMENT @55:5 +TOKEN @55:5 +IDENTIFIER @55:12 id result mapAll.result [v package] : java.util.List : java.util.List +TOKEN @55:12 +TOKEN @55:18 +TOKEN @56:3 +VARIABLE @58:3 var GenericEdges.nodes [v package] : java.util.Map + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing GenericEdges flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @58:3 : java.util.Map +IDENTIFIER @58:3 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @58:3 +TYPE_ARGUMENTS @58:6 +TOKEN @58:6 +IDENTIFIER @58:7 id K GenericEdges.K [t package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @58:7 +TOKEN @58:8 +IDENTIFIER @58:10 id Node GenericEdges.Node [t package] : GenericEdges$Node : GenericEdges$Node +TOKEN @58:10 +TOKEN @58:14 +IDENTIFIER @58:16 id nodes GenericEdges.nodes [v package] : java.util.Map : java.util.Map +TOKEN @58:16 +TOKEN @58:22 +NEW_CLASS @58:24 new HashMap. [m public] : ? () returns void throws [] sig java.util.HashMap#()V : java.util.HashMap + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing HashMap flags [public] overridden [AbstractMap.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @58:24 +PARAMETERIZED_TYPE @58:28 : java.util.HashMap +IDENTIFIER @58:28 id HashMap HashMap. [m public] : ? () returns void throws [] sig java.util.HashMap#()V : java.util.HashMap +TOKEN @58:28 +TYPE_ARGUMENTS @58:35 +TOKEN @58:35 +TOKEN @58:36 +ARGUMENTS @58:37 +TOKEN @58:37 +TOKEN @58:38 +TOKEN @58:39 +METHOD @60:3 method GenericEdges.edges [m package] : ? (java.util.List,java.util.List,java.util.Map,java.util.Optional) returns void throws [java.io.IOException] sig GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [numbers, sink, nested, maybe] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @60:3 : void +TOKEN @60:3 +IDENTIFIER @60:8 id edges GenericEdges.edges [m package] : ? (java.util.List,java.util.List,java.util.Map,java.util.Optional) returns void throws [java.io.IOException] sig GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V : void +TOKEN @60:8 +TOKEN @60:13 +VARIABLE @60:14 var edges.numbers [v package] : java.util.List + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter true effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @60:14 : java.util.List +IDENTIFIER @60:14 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @60:14 +TYPE_ARGUMENTS @60:18 +TOKEN @60:18 +EXTENDS_WILDCARD @60:19 +TOKEN @60:19 +TOKEN @60:21 +IDENTIFIER @60:29 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @60:29 +TOKEN @60:35 +IDENTIFIER @60:37 id numbers edges.numbers [v package] : java.util.List : java.util.List +TOKEN @60:37 +TOKEN @60:44 +VARIABLE @60:46 var edges.sink [v package] : java.util.List + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter true effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @60:46 : java.util.List +IDENTIFIER @60:46 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @60:46 +TYPE_ARGUMENTS @60:50 +TOKEN @60:50 +SUPER_WILDCARD @60:51 +TOKEN @60:51 +TOKEN @60:53 +IDENTIFIER @60:59 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @60:59 +TOKEN @60:66 +IDENTIFIER @60:68 id sink edges.sink [v package] : java.util.List : java.util.List +TOKEN @60:68 +TOKEN @60:72 +VARIABLE @60:74 var edges.nested [v package] : java.util.Map + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing GenericEdges flags [package] local true parameter true effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @60:74 : java.util.Map +IDENTIFIER @60:74 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @60:74 +TYPE_ARGUMENTS @60:77 +TOKEN @60:77 +IDENTIFIER @60:78 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @60:78 +TOKEN @60:84 +EXTENDS_WILDCARD @60:86 +TOKEN @60:86 +TOKEN @60:88 +PARAMETERIZED_TYPE @60:96 : java.util.List +IDENTIFIER @60:96 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @60:96 +TYPE_ARGUMENTS @60:100 +TOKEN @60:100 +IDENTIFIER @60:101 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @60:101 +TOKEN @60:107 +TOKEN @60:108 +IDENTIFIER @60:110 id nested edges.nested [v package] : java.util.Map : java.util.Map +TOKEN @60:110 +TOKEN @60:116 +VARIABLE @60:118 var edges.maybe [v package] : java.util.Optional + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter true effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @60:118 : java.util.Optional +IDENTIFIER @60:118 id Optional java.util.Optional [t final public] : java.util.Optional @jdk.internal.ValueBased : java.util.Optional +TOKEN @60:118 +TYPE_ARGUMENTS @60:126 +TOKEN @60:126 +IDENTIFIER @60:127 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @60:127 +TOKEN @60:133 +IDENTIFIER @60:135 id maybe edges.maybe [v package] : java.util.Optional : java.util.Optional +TOKEN @60:135 +TOKEN @60:140 +TOKEN @61:5 +LIST @61:12 +IDENTIFIER @61:12 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @61:12 +BLOCK @61:24 +TOKEN @61:24 +VARIABLE @62:5 var edges.first [v package] : java.lang.Number + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @62:5 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @62:5 +IDENTIFIER @62:12 id first edges.first [v package] : java.lang.Number : java.lang.Number +TOKEN @62:12 +TOKEN @62:18 +METHOD_INVOCATION @62:20 call List.get [m abstract public] : ? (int) returns java.lang.Number throws [] sig java.util.List#get(I)Ljava/lang/Object; : java.lang.Number + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @62:20 : ? +IDENTIFIER @62:20 id numbers edges.numbers [v package] : java.util.List : java.util.List +TOKEN @62:20 +TOKEN @62:27 +IDENTIFIER @62:28 id get List.get [m abstract public] : ? (int) returns java.lang.Number throws [] sig java.util.List#get(I)Ljava/lang/Object; : java.lang.Number +TOKEN @62:28 +ARGUMENTS @62:31 +TOKEN @62:31 +INT_LITERAL @62:32 : int = 0 +TOKEN @62:32 +TOKEN @62:33 +TOKEN @62:34 +EXPRESSION_STATEMENT @63:5 +METHOD_INVOCATION @63:5 call List.add [m abstract public] : ? (java.lang.Object) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.add[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @63:5 : ? +IDENTIFIER @63:5 id sink edges.sink [v package] : java.util.List : java.util.List +TOKEN @63:5 +TOKEN @63:9 +IDENTIFIER @63:10 id add List.add [m abstract public] : ? (java.lang.Object) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean +TOKEN @63:10 +ARGUMENTS @63:13 +TOKEN @63:13 +INT_LITERAL @63:14 : int = 1 +TOKEN @63:14 +TOKEN @63:15 +TOKEN @63:16 +VARIABLE @64:5 var edges.fromSink [v package] : java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @64:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @64:5 +IDENTIFIER @64:12 id fromSink edges.fromSink [v package] : java.lang.Object : java.lang.Object +TOKEN @64:12 +TOKEN @64:21 +METHOD_INVOCATION @64:23 call List.get [m abstract public] : ? (int) returns java.lang.Object throws [] sig java.util.List#get(I)Ljava/lang/Object; : java.lang.Object + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @64:23 : ? +IDENTIFIER @64:23 id sink edges.sink [v package] : java.util.List : java.util.List +TOKEN @64:23 +TOKEN @64:27 +IDENTIFIER @64:28 id get List.get [m abstract public] : ? (int) returns java.lang.Object throws [] sig java.util.List#get(I)Ljava/lang/Object; : java.lang.Object +TOKEN @64:28 +ARGUMENTS @64:31 +TOKEN @64:31 +INT_LITERAL @64:32 : int = 0 +TOKEN @64:32 +TOKEN @64:33 +TOKEN @64:34 +VARIABLE @65:5 var edges.size [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PRIMITIVE_TYPE @65:5 : int +TOKEN @65:5 +IDENTIFIER @65:9 id size edges.size [v package] : int : int +TOKEN @65:9 +TOKEN @65:14 +METHOD_INVOCATION @65:16 call List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.size[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @65:16 : ? +METHOD_INVOCATION @65:16 call Map.get [m abstract public] : ? (java.lang.Object) returns java.util.List throws [] sig java.util.Map#get(Ljava/lang/Object;)Ljava/lang/Object; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Map flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @65:16 : ? +IDENTIFIER @65:16 id nested edges.nested [v package] : java.util.Map : java.util.Map +TOKEN @65:16 +TOKEN @65:22 +IDENTIFIER @65:23 id get Map.get [m abstract public] : ? (java.lang.Object) returns java.util.List throws [] sig java.util.Map#get(Ljava/lang/Object;)Ljava/lang/Object; : java.util.List +TOKEN @65:23 +ARGUMENTS @65:26 +TOKEN @65:26 +STRING_LITERAL @65:27 : java.lang.String = k +TOKEN @65:27 +TOKEN @65:30 +TOKEN @65:31 +IDENTIFIER @65:32 id size List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int +TOKEN @65:32 +ARGUMENTS @65:36 +TOKEN @65:36 +TOKEN @65:37 +TOKEN @65:38 +VARIABLE @66:5 var edges.type [v package] : java.lang.Class + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @66:5 : java.lang.Class +IDENTIFIER @66:5 id Class java.lang.Class [t final public] : java.lang.Class : java.lang.Class +TOKEN @66:5 +TYPE_ARGUMENTS @66:10 +TOKEN @66:10 +UNBOUNDED_WILDCARD @66:11 +TOKEN @66:11 +TOKEN @66:12 +IDENTIFIER @66:14 id type edges.type [v package] : java.lang.Class : java.lang.Class +TOKEN @66:14 +TOKEN @66:19 +METHOD_INVOCATION @66:21 call Object.getClass [m final public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns java.lang.Class throws [] sig java.lang.Object#getClass()Ljava/lang/Class; : java.lang.Class + details declared false usages 2 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [final, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @66:21 : ? +IDENTIFIER @66:21 id first edges.first [v package] : java.lang.Number : java.lang.Number +TOKEN @66:21 +TOKEN @66:26 +IDENTIFIER @66:27 id getClass Object.getClass [m final public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns java.lang.Class throws [] sig java.lang.Object#getClass()Ljava/lang/Class; : java.lang.Class +TOKEN @66:27 +ARGUMENTS @66:35 +TOKEN @66:35 +TOKEN @66:36 +TOKEN @66:37 +VARIABLE @67:5 var edges.typed [v package] : java.lang.Class + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @67:5 : java.lang.Class +IDENTIFIER @67:5 id Class java.lang.Class [t final public] : java.lang.Class : java.lang.Class +TOKEN @67:5 +TYPE_ARGUMENTS @67:10 +TOKEN @67:10 +EXTENDS_WILDCARD @67:11 +TOKEN @67:11 +TOKEN @67:13 +IDENTIFIER @67:21 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @67:21 +TOKEN @67:27 +IDENTIFIER @67:29 id typed edges.typed [v package] : java.lang.Class : java.lang.Class +TOKEN @67:29 +TOKEN @67:35 +METHOD_INVOCATION @67:37 call Object.getClass [m final public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns java.lang.Class throws [] sig java.lang.Object#getClass()Ljava/lang/Class; : java.lang.Class + details declared false usages 2 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [final, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @67:37 : ? +IDENTIFIER @67:37 id first edges.first [v package] : java.lang.Number : java.lang.Number +TOKEN @67:37 +TOKEN @67:42 +IDENTIFIER @67:43 id getClass Object.getClass [m final public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns java.lang.Class throws [] sig java.lang.Object#getClass()Ljava/lang/Class; : java.lang.Class +TOKEN @67:43 +ARGUMENTS @67:51 +TOKEN @67:51 +TOKEN @67:52 +TOKEN @67:53 +VARIABLE @68:5 var edges.value [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @68:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @68:5 +IDENTIFIER @68:12 id value edges.value [v package] : java.lang.String : java.lang.String +TOKEN @68:12 +TOKEN @68:18 +METHOD_INVOCATION @68:20 call Optional.orElseThrow [m public] : ? (java.util.function.Supplier) returns java.lang.String throws [java.lang.IllegalStateException] sig java.util.Optional#orElseThrow(Ljava/util/function/Supplier;)Ljava/lang/Object; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Optional flags [public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @68:20 : ? +IDENTIFIER @68:20 id maybe edges.maybe [v package] : java.util.Optional : java.util.Optional +TOKEN @68:20 +TOKEN @68:25 +IDENTIFIER @68:26 id orElseThrow Optional.orElseThrow [m public] : ? (java.util.function.Supplier) returns java.lang.String throws [java.lang.IllegalStateException] sig java.util.Optional#orElseThrow(Ljava/util/function/Supplier;)Ljava/lang/Object; : java.lang.String +TOKEN @68:26 +ARGUMENTS @68:37 +TOKEN @68:37 +METHOD_REFERENCE @68:38 : java.util.function.Supplier +IDENTIFIER @68:38 id IllegalStateException java.lang.IllegalStateException [t public] : java.lang.IllegalStateException : java.lang.IllegalStateException +TOKEN @68:38 +TOKEN @68:59 +IDENTIFIER @68:61 id new IllegalStateException. [m public] : ? () returns void throws [] sig java.lang.IllegalStateException#()V : void +TOKEN @68:61 +TOKEN @68:64 +TOKEN @68:65 +VARIABLE @69:5 var edges.other [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @69:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @69:5 +IDENTIFIER @69:12 id other edges.other [v package] : java.lang.String : java.lang.String +TOKEN @69:12 +TOKEN @69:18 +METHOD_INVOCATION @69:20 call Optional.orElseGet [m public] : ? (java.util.function.Supplier) returns java.lang.String throws [] sig java.util.Optional#orElseGet(Ljava/util/function/Supplier;)Ljava/lang/Object; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Optional flags [public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @69:20 : ? +IDENTIFIER @69:20 id maybe edges.maybe [v package] : java.util.Optional : java.util.Optional +TOKEN @69:20 +TOKEN @69:25 +IDENTIFIER @69:26 id orElseGet Optional.orElseGet [m public] : ? (java.util.function.Supplier) returns java.lang.String throws [] sig java.util.Optional#orElseGet(Ljava/util/function/Supplier;)Ljava/lang/Object; : java.lang.String +TOKEN @69:26 +ARGUMENTS @69:35 +TOKEN @69:35 +LAMBDA_EXPRESSION @69:36 : java.util.function.Supplier +TOKEN @69:36 +TOKEN @69:37 +TOKEN @69:39 +STRING_LITERAL @69:42 : java.lang.String = x +TOKEN @69:42 +TOKEN @69:45 +TOKEN @69:46 +EXPRESSION_STATEMENT @70:5 +METHOD_INVOCATION @70:5 call GenericEdges.call [m static package] : ? (GenericEdges$Thrower) returns void throws [E erasure java.lang.Exception] sig GenericEdges#call(LGenericEdges$Thrower;)V : void + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [static, package] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [thrower] parameterMetadata [] +IDENTIFIER @70:5 id call GenericEdges.call [m static package] : ? (GenericEdges$Thrower) returns void throws [E erasure java.lang.Exception] sig GenericEdges#call(LGenericEdges$Thrower;)V : void +TOKEN @70:5 +ARGUMENTS @70:9 +TOKEN @70:9 +LAMBDA_EXPRESSION @70:10 : GenericEdges$Thrower +TOKEN @70:10 +TOKEN @70:11 +TOKEN @70:13 +BLOCK @70:16 +TOKEN @70:16 +THROW_STATEMENT @71:7 +TOKEN @71:7 +NEW_CLASS @71:13 new IOException. [m public] : ? (java.lang.String) returns void throws [] sig java.io.IOException#(Ljava/lang/String;)V : java.io.IOException + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing IOException flags [public] overridden [Exception.[], Throwable.[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @71:13 +IDENTIFIER @71:17 id IOException IOException. [m public] : ? (java.lang.String) returns void throws [] sig java.io.IOException#(Ljava/lang/String;)V : java.io.IOException +TOKEN @71:17 +ARGUMENTS @71:28 +TOKEN @71:28 +STRING_LITERAL @71:29 : java.lang.String = io +TOKEN @71:29 +TOKEN @71:33 +TOKEN @71:34 +TOKEN @72:5 +TOKEN @72:6 +TOKEN @72:7 +VARIABLE @73:5 var edges.outer [v package] : GenericEdges$Outer + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @73:5 : GenericEdges$Outer +IDENTIFIER @73:5 id Outer GenericEdges.Outer [t static package] : GenericEdges$Outer : GenericEdges$Outer +TOKEN @73:5 +TYPE_ARGUMENTS @73:10 +TOKEN @73:10 +IDENTIFIER @73:11 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @73:11 +TOKEN @73:17 +IDENTIFIER @73:19 id outer edges.outer [v package] : GenericEdges$Outer : GenericEdges$Outer +TOKEN @73:19 +TOKEN @73:25 +NEW_CLASS @73:27 new Outer. [m package] : ? () returns void throws [] sig GenericEdges$Outer#()V : GenericEdges$Outer + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Outer flags [package] overridden [Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @73:27 +PARAMETERIZED_TYPE @73:31 : GenericEdges$Outer +IDENTIFIER @73:31 id Outer Outer. [m package] : ? () returns void throws [] sig GenericEdges$Outer#()V : GenericEdges$Outer +TOKEN @73:31 +TYPE_ARGUMENTS @73:36 +TOKEN @73:36 +TOKEN @73:37 +ARGUMENTS @73:38 +TOKEN @73:38 +TOKEN @73:39 +TOKEN @73:40 +VARIABLE @74:5 var edges.inner [v package] : GenericEdges$Outer$Inner + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +MEMBER_SELECT @74:5 : GenericEdges$Outer$Inner +PARAMETERIZED_TYPE @74:5 : GenericEdges$Outer +IDENTIFIER @74:5 id Outer GenericEdges.Outer [t static package] : GenericEdges$Outer : GenericEdges$Outer +TOKEN @74:5 +TYPE_ARGUMENTS @74:10 +TOKEN @74:10 +IDENTIFIER @74:11 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @74:11 +TOKEN @74:17 +TOKEN @74:18 +IDENTIFIER @74:19 id Inner Outer.Inner [t package] : GenericEdges$Outer$Inner : GenericEdges$Outer$Inner +TOKEN @74:19 +IDENTIFIER @74:25 id inner edges.inner [v package] : GenericEdges$Outer$Inner : GenericEdges$Outer$Inner +TOKEN @74:25 +TOKEN @74:31 +METHOD_INVOCATION @74:33 call Outer.make [m package] : ? () returns GenericEdges$Outer$Inner throws [] sig GenericEdges$Outer#make()LGenericEdges$Outer$Inner; : GenericEdges$Outer$Inner + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Outer flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @74:33 : ? +IDENTIFIER @74:33 id outer edges.outer [v package] : GenericEdges$Outer : GenericEdges$Outer +TOKEN @74:33 +TOKEN @74:38 +IDENTIFIER @74:39 id make Outer.make [m package] : ? () returns GenericEdges$Outer$Inner throws [] sig GenericEdges$Outer#make()LGenericEdges$Outer$Inner; : GenericEdges$Outer$Inner +TOKEN @74:39 +ARGUMENTS @74:43 +TOKEN @74:43 +TOKEN @74:44 +TOKEN @74:45 +VARIABLE @75:5 var edges.held [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @75:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @75:5 +IDENTIFIER @75:12 id held edges.held [v package] : java.lang.String : java.lang.String +TOKEN @75:12 +TOKEN @75:17 +METHOD_INVOCATION @75:19 call Inner.held [m package] : ? () returns T erasure java.lang.Object throws [] sig GenericEdges$Outer$Inner#held()Ljava/lang/Object; : T erasure java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Inner flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @75:19 : ? +IDENTIFIER @75:19 id inner edges.inner [v package] : GenericEdges$Outer$Inner : GenericEdges$Outer$Inner +TOKEN @75:19 +TOKEN @75:24 +IDENTIFIER @75:25 id held Inner.held [m package] : ? () returns T erasure java.lang.Object throws [] sig GenericEdges$Outer$Inner#held()Ljava/lang/Object; : T erasure java.lang.Object +TOKEN @75:25 +ARGUMENTS @75:29 +TOKEN @75:29 +TOKEN @75:30 +TOKEN @75:31 +VARIABLE @76:5 var edges.explicit [v package] : GenericEdges$Outer$Inner + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +MEMBER_SELECT @76:5 : GenericEdges$Outer$Inner +PARAMETERIZED_TYPE @76:5 : GenericEdges$Outer +IDENTIFIER @76:5 id Outer GenericEdges.Outer [t static package] : GenericEdges$Outer : GenericEdges$Outer +TOKEN @76:5 +TYPE_ARGUMENTS @76:10 +TOKEN @76:10 +IDENTIFIER @76:11 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @76:11 +TOKEN @76:17 +TOKEN @76:18 +IDENTIFIER @76:19 id Inner Outer.Inner [t package] : GenericEdges$Outer$Inner : GenericEdges$Outer$Inner +TOKEN @76:19 +IDENTIFIER @76:25 id explicit edges.explicit [v package] : GenericEdges$Outer$Inner : GenericEdges$Outer$Inner +TOKEN @76:25 +TOKEN @76:34 +NEW_CLASS @76:36 new unknown : ? +IDENTIFIER @76:36 id outer edges.outer [v package] : GenericEdges$Outer : GenericEdges$Outer +TOKEN @76:36 +TOKEN @76:41 +TOKEN @76:42 +IDENTIFIER @76:46 id Inner unknown : ? +TOKEN @76:46 +ARGUMENTS @76:51 +TOKEN @76:51 +TOKEN @76:52 +TOKEN @76:53 +VARIABLE @77:5 var edges.explicitHeld [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @77:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @77:5 +IDENTIFIER @77:12 id explicitHeld edges.explicitHeld [v package] : java.lang.String : java.lang.String +TOKEN @77:12 +TOKEN @77:25 +MEMBER_SELECT @77:27 : T erasure java.lang.Object +IDENTIFIER @77:27 id explicit edges.explicit [v package] : GenericEdges$Outer$Inner : GenericEdges$Outer$Inner +TOKEN @77:27 +TOKEN @77:35 +IDENTIFIER @77:36 id held Inner.held [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @77:36 +TOKEN @77:40 +VARIABLE @78:5 var edges.node [v package] : GenericEdges$Node + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @78:5 id Node GenericEdges.Node [t package] : GenericEdges$Node : GenericEdges$Node +TOKEN @78:5 +IDENTIFIER @78:10 id node edges.node [v package] : GenericEdges$Node : GenericEdges$Node +TOKEN @78:10 +TOKEN @78:15 +METHOD_INVOCATION @78:17 call Iterator.next [m abstract public] : ? () returns GenericEdges$Node throws [] sig java.util.Iterator#next()Ljava/lang/Object; : GenericEdges$Node + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Iterator flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @78:17 : ? +METHOD_INVOCATION @78:17 call Collection.iterator [m abstract public] : ? () returns java.util.Iterator throws [] sig java.util.Collection#iterator()Ljava/util/Iterator; : java.util.Iterator + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collection flags [abstract, public] overridden [Iterable.iterator[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @78:17 : ? +METHOD_INVOCATION @78:17 call Map.values [m abstract public] : ? () returns java.util.Collection throws [] sig java.util.Map#values()Ljava/util/Collection; : java.util.Collection + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Map flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @78:17 : ? +IDENTIFIER @78:17 id nodes GenericEdges.nodes [v package] : java.util.Map : java.util.Map +TOKEN @78:17 +TOKEN @78:22 +IDENTIFIER @78:23 id values Map.values [m abstract public] : ? () returns java.util.Collection throws [] sig java.util.Map#values()Ljava/util/Collection; : java.util.Collection +TOKEN @78:23 +ARGUMENTS @78:29 +TOKEN @78:29 +TOKEN @78:30 +TOKEN @78:31 +IDENTIFIER @78:32 id iterator Collection.iterator [m abstract public] : ? () returns java.util.Iterator throws [] sig java.util.Collection#iterator()Ljava/util/Iterator; : java.util.Iterator +TOKEN @78:32 +ARGUMENTS @78:40 +TOKEN @78:40 +TOKEN @78:41 +TOKEN @78:42 +IDENTIFIER @78:43 id next Iterator.next [m abstract public] : ? () returns GenericEdges$Node throws [] sig java.util.Iterator#next()Ljava/lang/Object; : GenericEdges$Node +TOKEN @78:43 +ARGUMENTS @78:47 +TOKEN @78:47 +TOKEN @78:48 +TOKEN @78:49 +VARIABLE @79:5 var edges.got [v package] : V erasure java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @79:5 id V GenericEdges.V [t package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @79:5 +IDENTIFIER @79:7 id got edges.got [v package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @79:7 +TOKEN @79:11 +METHOD_INVOCATION @79:13 call Node.get [m package] : ? () returns V erasure java.lang.Object throws [] sig GenericEdges$Node#get()Ljava/lang/Object; : V erasure java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Node flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @79:13 : ? +IDENTIFIER @79:13 id node edges.node [v package] : GenericEdges$Node : GenericEdges$Node +TOKEN @79:13 +TOKEN @79:17 +IDENTIFIER @79:18 id get Node.get [m package] : ? () returns V erasure java.lang.Object throws [] sig GenericEdges$Node#get()Ljava/lang/Object; : V erasure java.lang.Object +TOKEN @79:18 +ARGUMENTS @79:21 +TOKEN @79:21 +TOKEN @79:22 +TOKEN @79:23 +VARIABLE @80:5 var edges.key [v package] : K erasure java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @80:5 id K GenericEdges.K [t package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @80:5 +IDENTIFIER @80:7 id key edges.key [v package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @80:7 +TOKEN @80:11 +MEMBER_SELECT @80:13 : K erasure java.lang.Object +IDENTIFIER @80:13 id node edges.node [v package] : GenericEdges$Node : GenericEdges$Node +TOKEN @80:13 +TOKEN @80:17 +IDENTIFIER @80:18 id key Node.key [v package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @80:18 +TOKEN @80:21 +VARIABLE @81:5 var edges.lengths [v package] : java.util.List + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @81:5 : java.util.List +IDENTIFIER @81:5 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @81:5 +TYPE_ARGUMENTS @81:9 +TOKEN @81:9 +IDENTIFIER @81:10 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @81:10 +TOKEN @81:17 +IDENTIFIER @81:19 id lengths edges.lengths [v package] : java.util.List : java.util.List +TOKEN @81:19 +TOKEN @81:27 +METHOD_INVOCATION @81:29 call GenericEdges.mapAll [m static package] : ? (java.util.Collection,java.util.function.Function) returns java.util.List throws [] sig GenericEdges#mapAll(Ljava/util/Collection;Ljava/util/function/Function;)Ljava/util/List; : java.util.List + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [static, package] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [input, mapper] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +IDENTIFIER @81:29 id mapAll GenericEdges.mapAll [m static package] : ? (java.util.Collection,java.util.function.Function) returns java.util.List throws [] sig GenericEdges#mapAll(Ljava/util/Collection;Ljava/util/function/Function;)Ljava/util/List; : java.util.List +TOKEN @81:29 +ARGUMENTS @81:35 +TOKEN @81:35 +METHOD_INVOCATION @81:36 call List.of [m static public] : ? (java.lang.String,java.lang.String) returns java.util.List throws [] sig java.util.List#of(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/List; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +MEMBER_SELECT @81:36 : ? +IDENTIFIER @81:36 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @81:36 +TOKEN @81:40 +IDENTIFIER @81:41 id of List.of [m static public] : ? (java.lang.String,java.lang.String) returns java.util.List throws [] sig java.util.List#of(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/List; : java.util.List +TOKEN @81:41 +ARGUMENTS @81:43 +TOKEN @81:43 +STRING_LITERAL @81:44 : java.lang.String = a +TOKEN @81:44 +TOKEN @81:47 +STRING_LITERAL @81:49 : java.lang.String = bb +TOKEN @81:49 +TOKEN @81:53 +TOKEN @81:54 +METHOD_REFERENCE @81:56 : java.util.function.Function +IDENTIFIER @81:56 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @81:56 +TOKEN @81:62 +IDENTIFIER @81:64 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @81:64 +TOKEN @81:70 +TOKEN @81:71 +VARIABLE @82:5 var edges.strings [v package] : java.util.List + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @82:5 : java.util.List +IDENTIFIER @82:5 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @82:5 +TYPE_ARGUMENTS @82:9 +TOKEN @82:9 +IDENTIFIER @82:10 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @82:10 +TOKEN @82:16 +IDENTIFIER @82:18 id strings edges.strings [v package] : java.util.List : java.util.List +TOKEN @82:18 +TOKEN @82:26 +METHOD_INVOCATION @82:28 call GenericEdges.mapAll [m static package] : ? (java.util.Collection,java.util.function.Function) returns java.util.List throws [] sig GenericEdges#mapAll(Ljava/util/Collection;Ljava/util/function/Function;)Ljava/util/List; : java.util.List + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [static, package] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [input, mapper] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +TYPE_ARGUMENTS @82:41 +TOKEN @82:41 +IDENTIFIER @82:42 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @82:42 +TOKEN @82:49 +IDENTIFIER @82:51 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @82:51 +TOKEN @82:57 +MEMBER_SELECT @82:28 : ? +IDENTIFIER @82:28 id GenericEdges .GenericEdges [t package] : GenericEdges : GenericEdges +TOKEN @82:28 +TOKEN @82:40 +IDENTIFIER @82:58 id mapAll GenericEdges.mapAll [m static package] : ? (java.util.Collection,java.util.function.Function) returns java.util.List throws [] sig GenericEdges#mapAll(Ljava/util/Collection;Ljava/util/function/Function;)Ljava/util/List; : java.util.List +TOKEN @82:58 +ARGUMENTS @82:64 +TOKEN @82:64 +IDENTIFIER @82:65 id lengths edges.lengths [v package] : java.util.List : java.util.List +TOKEN @82:65 +TOKEN @82:72 +METHOD_REFERENCE @82:74 : java.util.function.Function +IDENTIFIER @82:74 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @82:74 +TOKEN @82:80 +IDENTIFIER @82:82 id valueOf String.valueOf [m static public] : ? (java.lang.Object) returns java.lang.String throws [] sig java.lang.String#valueOf(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String +TOKEN @82:82 +TOKEN @82:89 +TOKEN @82:90 +VARIABLE @83:5 var edges.parts [v package] : java.util.Map> + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @83:5 : java.util.Map> +IDENTIFIER @83:5 id Map java.util.Map [t public interface] : java.util.Map> : java.util.Map> +TOKEN @83:5 +TYPE_ARGUMENTS @83:8 +TOKEN @83:8 +IDENTIFIER @83:9 id Boolean java.lang.Boolean [t final public] : java.lang.Boolean @jdk.internal.ValueBased : java.lang.Boolean +TOKEN @83:9 +TOKEN @83:16 +PARAMETERIZED_TYPE @83:18 : java.util.List +IDENTIFIER @83:18 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @83:18 +TYPE_ARGUMENTS @83:22 +TOKEN @83:22 +IDENTIFIER @83:23 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @83:23 +TOKEN @83:29 +TOKEN @83:30 +IDENTIFIER @83:32 id parts edges.parts [v package] : java.util.Map> : java.util.Map> +TOKEN @83:32 +TOKEN @83:38 +METHOD_INVOCATION @83:40 call Stream.collect [m abstract public] : ? (java.util.stream.Collector) returns java.util.Map> throws [] sig java.util.stream.Stream#collect(Ljava/util/stream/Collector;)Ljava/lang/Object; : java.util.Map> + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @83:40 : ? +METHOD_INVOCATION @83:40 call Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream + details declared false usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collection flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @83:40 : ? +IDENTIFIER @83:40 id strings edges.strings [v package] : java.util.List : java.util.List +TOKEN @83:40 +TOKEN @83:47 +IDENTIFIER @83:48 id stream Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @83:48 +ARGUMENTS @83:54 +TOKEN @83:54 +TOKEN @83:55 +TOKEN @83:56 +IDENTIFIER @83:57 id collect Stream.collect [m abstract public] : ? (java.util.stream.Collector) returns java.util.Map> throws [] sig java.util.stream.Stream#collect(Ljava/util/stream/Collector;)Ljava/lang/Object; : java.util.Map> +TOKEN @83:57 +ARGUMENTS @83:64 +TOKEN @83:64 +METHOD_INVOCATION @83:65 call Collectors.partitioningBy [m static public] : ? (java.util.function.Predicate) returns java.util.stream.Collector throws [] sig java.util.stream.Collectors#partitioningBy(Ljava/util/function/Predicate;)Ljava/util/stream/Collector; : java.util.stream.Collector>> + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collectors flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @83:65 : ? +IDENTIFIER @83:65 id Collectors java.util.stream.Collectors [t final public] : java.util.stream.Collectors : java.util.stream.Collectors +TOKEN @83:65 +TOKEN @83:75 +IDENTIFIER @83:76 id partitioningBy Collectors.partitioningBy [m static public] : ? (java.util.function.Predicate) returns java.util.stream.Collector throws [] sig java.util.stream.Collectors#partitioningBy(Ljava/util/function/Predicate;)Ljava/util/stream/Collector; : java.util.stream.Collector +TOKEN @83:76 +ARGUMENTS @83:90 +TOKEN @83:90 +LAMBDA_EXPRESSION @83:91 : java.util.function.Predicate +VARIABLE @83:91 var test.s [v package] : java.lang.String + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Predicate flags [package] local true parameter true effectivelyFinal true constant null owner test java.util.function.Predicate#test(Ljava/lang/Object;)Z [abstract, public] returns boolean parameters 1 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing Predicate type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @83:91 id s test.s [v package] : java.lang.String : java.lang.String +TOKEN @83:91 +TOKEN @83:93 +METHOD_INVOCATION @83:96 call String.isEmpty [m public] : ? () returns boolean throws [] sig java.lang.String#isEmpty()Z : boolean + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [CharSequence.isEmpty[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @83:96 : ? +IDENTIFIER @83:96 id s test.s [v package] : java.lang.String : java.lang.String +TOKEN @83:96 +TOKEN @83:97 +IDENTIFIER @83:98 id isEmpty String.isEmpty [m public] : ? () returns boolean throws [] sig java.lang.String#isEmpty()Z : boolean +TOKEN @83:98 +ARGUMENTS @83:105 +TOKEN @83:105 +TOKEN @83:106 +TOKEN @83:107 +TOKEN @83:108 +TOKEN @83:109 +VARIABLE @84:5 var edges.counts [v package] : java.util.Map + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @84:5 : java.util.Map +IDENTIFIER @84:5 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @84:5 +TYPE_ARGUMENTS @84:8 +TOKEN @84:8 +IDENTIFIER @84:9 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @84:9 +TOKEN @84:15 +IDENTIFIER @84:17 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @84:17 +TOKEN @84:24 +IDENTIFIER @84:26 id counts edges.counts [v package] : java.util.Map : java.util.Map +TOKEN @84:26 +TOKEN @84:33 +METHOD_INVOCATION @84:35 call Stream.collect [m abstract public] : ? (java.util.stream.Collector) returns java.util.Map throws [] sig java.util.stream.Stream#collect(Ljava/util/stream/Collector;)Ljava/lang/Object; : java.util.Map + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @84:35 : ? +METHOD_INVOCATION @84:35 call Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream + details declared false usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collection flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @84:35 : ? +IDENTIFIER @84:35 id strings edges.strings [v package] : java.util.List : java.util.List +TOKEN @84:35 +TOKEN @84:42 +IDENTIFIER @84:43 id stream Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @84:43 +ARGUMENTS @84:49 +TOKEN @84:49 +TOKEN @84:50 +TOKEN @84:51 +IDENTIFIER @84:52 id collect Stream.collect [m abstract public] : ? (java.util.stream.Collector) returns java.util.Map throws [] sig java.util.stream.Stream#collect(Ljava/util/stream/Collector;)Ljava/lang/Object; : java.util.Map +TOKEN @84:52 +ARGUMENTS @84:59 +TOKEN @84:59 +METHOD_INVOCATION @84:60 call Collectors.toMap [m static public] : ? (java.util.function.Function,java.util.function.Function,java.util.function.BinaryOperator) returns java.util.stream.Collector> throws [] sig java.util.stream.Collectors#toMap(Ljava/util/function/Function;Ljava/util/function/Function;Ljava/util/function/BinaryOperator;)Ljava/util/stream/Collector; : java.util.stream.Collector> + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collectors flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0, arg1, arg2] parameterMetadata [] +MEMBER_SELECT @84:60 : ? +IDENTIFIER @84:60 id Collectors java.util.stream.Collectors [t final public] : java.util.stream.Collectors : java.util.stream.Collectors +TOKEN @84:60 +TOKEN @84:70 +IDENTIFIER @84:71 id toMap Collectors.toMap [m static public] : ? (java.util.function.Function,java.util.function.Function,java.util.function.BinaryOperator) returns java.util.stream.Collector> throws [] sig java.util.stream.Collectors#toMap(Ljava/util/function/Function;Ljava/util/function/Function;Ljava/util/function/BinaryOperator;)Ljava/util/stream/Collector; : java.util.stream.Collector> +TOKEN @84:71 +ARGUMENTS @84:76 +TOKEN @84:76 +METHOD_INVOCATION @84:77 call Function.identity [m static public] : ? () returns java.util.function.Function throws [] sig java.util.function.Function#identity()Ljava/util/function/Function; : java.util.function.Function + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Function flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @84:77 : ? +IDENTIFIER @84:77 id Function java.util.function.Function [t public interface] : java.util.function.Function @java.lang.FunctionalInterface : java.util.function.Function +TOKEN @84:77 +TOKEN @84:85 +IDENTIFIER @84:86 id identity Function.identity [m static public] : ? () returns java.util.function.Function throws [] sig java.util.function.Function#identity()Ljava/util/function/Function; : java.util.function.Function +TOKEN @84:86 +ARGUMENTS @84:94 +TOKEN @84:94 +TOKEN @84:95 +TOKEN @84:96 +METHOD_REFERENCE @84:98 : java.util.function.Function +IDENTIFIER @84:98 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @84:98 +TOKEN @84:104 +IDENTIFIER @84:106 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @84:106 +TOKEN @84:112 +METHOD_REFERENCE @84:114 : java.util.function.BinaryOperator +IDENTIFIER @84:114 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @84:114 +TOKEN @84:121 +IDENTIFIER @84:123 id sum Integer.sum [m static public] : ? (int,int) returns int throws [] sig java.lang.Integer#sum(II)I : int +TOKEN @84:123 +TOKEN @84:126 +TOKEN @84:127 +TOKEN @84:128 +VARIABLE @85:5 var edges.longest [v package] : java.util.Optional + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @85:5 : java.util.Optional +IDENTIFIER @85:5 id Optional java.util.Optional [t final public] : java.util.Optional @jdk.internal.ValueBased : java.util.Optional +TOKEN @85:5 +TYPE_ARGUMENTS @85:13 +TOKEN @85:13 +IDENTIFIER @85:14 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @85:14 +TOKEN @85:21 +IDENTIFIER @85:23 id longest edges.longest [v package] : java.util.Optional : java.util.Optional +TOKEN @85:23 +TOKEN @85:31 +METHOD_INVOCATION @85:33 call Stream.max [m abstract public] : ? (java.util.Comparator) returns java.util.Optional throws [] sig java.util.stream.Stream#max(Ljava/util/Comparator;)Ljava/util/Optional; : java.util.Optional + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @85:33 : ? +METHOD_INVOCATION @85:33 call Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream + details declared false usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collection flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @85:33 : ? +IDENTIFIER @85:33 id lengths edges.lengths [v package] : java.util.List : java.util.List +TOKEN @85:33 +TOKEN @85:40 +IDENTIFIER @85:41 id stream Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @85:41 +ARGUMENTS @85:47 +TOKEN @85:47 +TOKEN @85:48 +TOKEN @85:49 +IDENTIFIER @85:50 id max Stream.max [m abstract public] : ? (java.util.Comparator) returns java.util.Optional throws [] sig java.util.stream.Stream#max(Ljava/util/Comparator;)Ljava/util/Optional; : java.util.Optional +TOKEN @85:50 +ARGUMENTS @85:53 +TOKEN @85:53 +METHOD_INVOCATION @85:54 call Comparator.naturalOrder [m static public] : ? () returns java.util.Comparator throws [] sig java.util.Comparator#naturalOrder()Ljava/util/Comparator; : java.util.Comparator + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Comparator flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @85:54 : ? +IDENTIFIER @85:54 id Comparator java.util.Comparator [t public interface] : java.util.Comparator @java.lang.FunctionalInterface : java.util.Comparator +TOKEN @85:54 +TOKEN @85:64 +IDENTIFIER @85:65 id naturalOrder Comparator.naturalOrder [m static public] : ? () returns java.util.Comparator throws [] sig java.util.Comparator#naturalOrder()Ljava/util/Comparator; : java.util.Comparator +TOKEN @85:65 +ARGUMENTS @85:77 +TOKEN @85:77 +TOKEN @85:78 +TOKEN @85:79 +TOKEN @85:80 +VARIABLE @86:5 var edges.chunks [v package] : java.util.stream.Stream> + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @86:5 : java.util.stream.Stream> +IDENTIFIER @86:5 id Stream java.util.stream.Stream [t public interface] : java.util.stream.Stream> : java.util.stream.Stream> +TOKEN @86:5 +TYPE_ARGUMENTS @86:11 +TOKEN @86:11 +PARAMETERIZED_TYPE @86:12 : java.util.List +IDENTIFIER @86:12 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @86:12 +TYPE_ARGUMENTS @86:16 +TOKEN @86:16 +IDENTIFIER @86:17 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @86:17 +TOKEN @86:23 +TOKEN @86:24 +IDENTIFIER @86:26 id chunks edges.chunks [v package] : java.util.stream.Stream> : java.util.stream.Stream> +TOKEN @86:26 +TOKEN @86:33 +METHOD_INVOCATION @86:35 call Stream.of [m static public] : ? @java.lang.SafeVarargs (java.util.List[]) returns java.util.stream.Stream> throws [] sig java.util.stream.Stream#of([Ljava/lang/Object;)Ljava/util/stream/Stream; : java.util.stream.Stream> + details declared false usages 1 metadata [java.lang.SafeVarargs()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.SafeVarargs tree false values 0 annotated true] typeArguments [] enclosing Stream flags [static, public] overridden [] overridable false generic true default false synchronized false varargs true native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @86:35 : ? +IDENTIFIER @86:35 id Stream java.util.stream.Stream [t public interface] : java.util.stream.Stream : java.util.stream.Stream +TOKEN @86:35 +TOKEN @86:41 +IDENTIFIER @86:42 id of Stream.of [m static public] : ? @java.lang.SafeVarargs (java.util.List[]) returns java.util.stream.Stream> throws [] sig java.util.stream.Stream#of([Ljava/lang/Object;)Ljava/util/stream/Stream; : java.util.stream.Stream> +TOKEN @86:42 +ARGUMENTS @86:44 +TOKEN @86:44 +IDENTIFIER @86:45 id strings edges.strings [v package] : java.util.List : java.util.List +TOKEN @86:45 +TOKEN @86:52 +IDENTIFIER @86:54 id strings edges.strings [v package] : java.util.List : java.util.List +TOKEN @86:54 +TOKEN @86:61 +TOKEN @86:62 +VARIABLE @87:5 var edges.flat [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @87:5 : java.util.List +IDENTIFIER @87:5 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @87:5 +TYPE_ARGUMENTS @87:9 +TOKEN @87:9 +IDENTIFIER @87:10 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @87:10 +TOKEN @87:16 +IDENTIFIER @87:18 id flat edges.flat [v package] : java.util.List : java.util.List +TOKEN @87:18 +TOKEN @87:23 +METHOD_INVOCATION @87:25 call Stream.collect [m abstract public] : ? (java.util.stream.Collector) returns java.lang.Object throws [] sig java.util.stream.Stream#collect(Ljava/util/stream/Collector;)Ljava/lang/Object; : java.util.List + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @87:25 : ? +METHOD_INVOCATION @87:25 call Stream.flatMap [m abstract public] : ? (java.util.function.Function) returns java.util.stream.Stream throws [] sig java.util.stream.Stream#flatMap(Ljava/util/function/Function;)Ljava/util/stream/Stream; : java.util.stream.Stream + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @87:25 : ? +IDENTIFIER @87:25 id chunks edges.chunks [v package] : java.util.stream.Stream> : java.util.stream.Stream> +TOKEN @87:25 +TOKEN @87:31 +IDENTIFIER @87:32 id flatMap Stream.flatMap [m abstract public] : ? (java.util.function.Function) returns java.util.stream.Stream throws [] sig java.util.stream.Stream#flatMap(Ljava/util/function/Function;)Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @87:32 +ARGUMENTS @87:39 +TOKEN @87:39 +METHOD_REFERENCE @87:40 : java.util.function.Function,java.util.stream.Stream> +IDENTIFIER @87:40 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @87:40 +TOKEN @87:44 +IDENTIFIER @87:46 id stream Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @87:46 +TOKEN @87:52 +TOKEN @87:53 +IDENTIFIER @87:54 id collect Stream.collect [m abstract public] : ? (java.util.stream.Collector) returns java.lang.Object throws [] sig java.util.stream.Stream#collect(Ljava/util/stream/Collector;)Ljava/lang/Object; : java.lang.Object +TOKEN @87:54 +ARGUMENTS @87:61 +TOKEN @87:61 +METHOD_INVOCATION @87:62 call Collectors.toList [m static public] : ? () returns java.util.stream.Collector throws [] sig java.util.stream.Collectors#toList()Ljava/util/stream/Collector; : java.util.stream.Collector + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collectors flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @87:62 : ? +IDENTIFIER @87:62 id Collectors java.util.stream.Collectors [t final public] : java.util.stream.Collectors : java.util.stream.Collectors +TOKEN @87:62 +TOKEN @87:72 +IDENTIFIER @87:73 id toList Collectors.toList [m static public] : ? () returns java.util.stream.Collector throws [] sig java.util.stream.Collectors#toList()Ljava/util/stream/Collector; : java.util.stream.Collector +TOKEN @87:73 +ARGUMENTS @87:79 +TOKEN @87:79 +TOKEN @87:80 +TOKEN @87:81 +TOKEN @87:82 +VARIABLE @88:5 var edges.repeat [v package] : java.util.function.BiFunction + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], [], []] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @88:5 : java.util.function.BiFunction +IDENTIFIER @88:5 id BiFunction java.util.function.BiFunction [t public interface] : java.util.function.BiFunction @java.lang.FunctionalInterface : java.util.function.BiFunction +TOKEN @88:5 +TYPE_ARGUMENTS @88:15 +TOKEN @88:15 +IDENTIFIER @88:16 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @88:16 +TOKEN @88:22 +IDENTIFIER @88:24 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @88:24 +TOKEN @88:31 +IDENTIFIER @88:33 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @88:33 +TOKEN @88:39 +IDENTIFIER @88:41 id repeat edges.repeat [v package] : java.util.function.BiFunction : java.util.function.BiFunction +TOKEN @88:41 +TOKEN @88:48 +METHOD_REFERENCE @88:50 : java.util.function.BiFunction +IDENTIFIER @88:50 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @88:50 +TOKEN @88:56 +IDENTIFIER @88:58 id repeat String.repeat [m public] : ? (int) returns java.lang.String throws [] sig java.lang.String#repeat(I)Ljava/lang/String; : java.lang.String +TOKEN @88:58 +TOKEN @88:64 +VARIABLE @89:5 var edges.factory [v package] : java.util.function.Supplier> + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @89:5 : java.util.function.Supplier> +IDENTIFIER @89:5 id Supplier java.util.function.Supplier [t public interface] : java.util.function.Supplier> @java.lang.FunctionalInterface : java.util.function.Supplier> +TOKEN @89:5 +TYPE_ARGUMENTS @89:13 +TOKEN @89:13 +PARAMETERIZED_TYPE @89:14 : java.util.List +IDENTIFIER @89:14 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @89:14 +TYPE_ARGUMENTS @89:18 +TOKEN @89:18 +IDENTIFIER @89:19 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @89:19 +TOKEN @89:25 +TOKEN @89:26 +IDENTIFIER @89:28 id factory edges.factory [v package] : java.util.function.Supplier> : java.util.function.Supplier> +TOKEN @89:28 +TOKEN @89:36 +METHOD_REFERENCE @89:38 : java.util.function.Supplier> +IDENTIFIER @89:38 id ArrayList java.util.ArrayList [t public] : java.util.ArrayList : java.util.ArrayList +TOKEN @89:38 +TOKEN @89:47 +IDENTIFIER @89:49 id new ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : void +TOKEN @89:49 +TOKEN @89:52 +VARIABLE @90:5 var edges.callable [v package] : java.util.concurrent.Callable + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @90:5 : java.util.concurrent.Callable +IDENTIFIER @90:5 id Callable java.util.concurrent.Callable [t public interface] : java.util.concurrent.Callable @java.lang.FunctionalInterface : java.util.concurrent.Callable +TOKEN @90:5 +TYPE_ARGUMENTS @90:13 +TOKEN @90:13 +IDENTIFIER @90:14 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @90:14 +TOKEN @90:21 +IDENTIFIER @90:23 id callable edges.callable [v package] : java.util.concurrent.Callable : java.util.concurrent.Callable +TOKEN @90:23 +TOKEN @90:32 +METHOD_REFERENCE @90:34 : java.util.concurrent.Callable +IDENTIFIER @90:34 id lengths edges.lengths [v package] : java.util.List : java.util.List +TOKEN @90:34 +TOKEN @90:41 +IDENTIFIER @90:43 id size List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int +TOKEN @90:43 +TOKEN @90:47 +VARIABLE @91:5 var edges.iterator [v package] : java.util.Iterator + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @91:5 : java.util.Iterator +IDENTIFIER @91:5 id Iterator java.util.Iterator [t public interface] : java.util.Iterator : java.util.Iterator +TOKEN @91:5 +TYPE_ARGUMENTS @91:13 +TOKEN @91:13 +EXTENDS_WILDCARD @91:14 +TOKEN @91:14 +TOKEN @91:16 +IDENTIFIER @91:24 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @91:24 +TOKEN @91:30 +IDENTIFIER @91:32 id iterator edges.iterator [v package] : java.util.Iterator : java.util.Iterator +TOKEN @91:32 +TOKEN @91:41 +METHOD_INVOCATION @91:43 call List.iterator [m abstract public] : ? () returns java.util.Iterator throws [] sig java.util.List#iterator()Ljava/util/Iterator; : java.util.Iterator + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.iterator[], Iterable.iterator[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @91:43 : ? +IDENTIFIER @91:43 id numbers edges.numbers [v package] : java.util.List : java.util.List +TOKEN @91:43 +TOKEN @91:50 +IDENTIFIER @91:51 id iterator List.iterator [m abstract public] : ? () returns java.util.Iterator throws [] sig java.util.List#iterator()Ljava/util/Iterator; : java.util.Iterator +TOKEN @91:51 +ARGUMENTS @91:59 +TOKEN @91:59 +TOKEN @91:60 +TOKEN @91:61 +VARIABLE @92:5 var edges.anonymous [v package] : java.util.Comparator + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @92:5 : java.util.Comparator +IDENTIFIER @92:5 id Comparator java.util.Comparator [t public interface] : java.util.Comparator @java.lang.FunctionalInterface : java.util.Comparator +TOKEN @92:5 +TYPE_ARGUMENTS @92:15 +TOKEN @92:15 +IDENTIFIER @92:16 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @92:16 +TOKEN @92:22 +IDENTIFIER @92:24 id anonymous edges.anonymous [v package] : java.util.Comparator : java.util.Comparator +TOKEN @92:24 +TOKEN @92:34 +NEW_CLASS @92:36 new Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : GenericEdges$1 + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @92:36 +PARAMETERIZED_TYPE @92:40 : java.util.Comparator +IDENTIFIER @92:40 id Comparator Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : java.util.Comparator +TOKEN @92:40 +TYPE_ARGUMENTS @92:50 +TOKEN @92:50 +TOKEN @92:51 +ARGUMENTS @92:52 +TOKEN @92:52 +TOKEN @92:53 +CLASS @92:55 class edges. [t package] : GenericEdges$1 super java.lang.Object interfaces [java.util.Comparator] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing GenericEdges flags [package] members [, compare] lookupToString 0 outermost GenericEdges annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object, java.util.Comparator] numerical false wrapper false raw false declaring +MODIFIERS +TYPE_PARAMETERS +LIST +LIST +TOKEN @92:55 +METHOD @93:7 method .compare [m public] : ? @java.lang.Override (java.lang.String,java.lang.String) returns int throws [] sig GenericEdges$1#compare(Ljava/lang/String;Ljava/lang/String;)I overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing flags [public] overridden [Comparator.compare[]] overridable true generic false default false synchronized false varargs false native false parameters [left, right] parameterMetadata [] +MODIFIERS @93:7 +ANNOTATION @93:7 : java.lang.Override +TOKEN @93:7 +IDENTIFIER @93:8 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @93:8 +ARGUMENTS +TOKEN @94:7 +TYPE_PARAMETERS +PRIMITIVE_TYPE @94:14 : int +TOKEN @94:14 +IDENTIFIER @94:18 id compare .compare [m public] : ? @java.lang.Override (java.lang.String,java.lang.String) returns int throws [] sig GenericEdges$1#compare(Ljava/lang/String;Ljava/lang/String;)I : int +TOKEN @94:18 +TOKEN @94:25 +VARIABLE @94:26 var compare.left [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing flags [package] local true parameter true effectivelyFinal true constant null owner compare GenericEdges$1#compare(Ljava/lang/String;Ljava/lang/String;)I [public] returns int parameters 2 thrown 0 overridden 1 declared true usages 0 metadata 1 enclosing type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @94:26 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @94:26 +IDENTIFIER @94:33 id left compare.left [v package] : java.lang.String : java.lang.String +TOKEN @94:33 +TOKEN @94:37 +VARIABLE @94:39 var compare.right [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing flags [package] local true parameter true effectivelyFinal true constant null owner compare GenericEdges$1#compare(Ljava/lang/String;Ljava/lang/String;)I [public] returns int parameters 2 thrown 0 overridden 1 declared true usages 0 metadata 1 enclosing type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @94:39 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @94:39 +IDENTIFIER @94:46 id right compare.right [v package] : java.lang.String : java.lang.String +TOKEN @94:46 +TOKEN @94:51 +BLOCK @94:53 +TOKEN @94:53 +RETURN_STATEMENT @95:9 +TOKEN @95:9 +METHOD_INVOCATION @95:16 call String.compareTo [m public] : ? (java.lang.String) returns int throws [] sig java.lang.String#compareTo(Ljava/lang/String;)I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [Comparable.compareTo[]] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @95:16 : ? +IDENTIFIER @95:16 id left compare.left [v package] : java.lang.String : java.lang.String +TOKEN @95:16 +TOKEN @95:20 +IDENTIFIER @95:21 id compareTo String.compareTo [m public] : ? (java.lang.String) returns int throws [] sig java.lang.String#compareTo(Ljava/lang/String;)I : int +TOKEN @95:21 +ARGUMENTS @95:30 +TOKEN @95:30 +IDENTIFIER @95:31 id right compare.right [v package] : java.lang.String : java.lang.String +TOKEN @95:31 +TOKEN @95:36 +TOKEN @95:37 +TOKEN @96:7 +TOKEN @97:5 +TOKEN @97:6 +VARIABLE @98:5 var edges.raw [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing GenericEdges flags [package] local true parameter false effectivelyFinal true constant null owner edges GenericEdges#edges(Ljava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/util/Optional;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing GenericEdges type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @98:5 : java.util.List +IDENTIFIER @98:5 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @98:5 +TYPE_ARGUMENTS @98:9 +TOKEN @98:9 +IDENTIFIER @98:10 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @98:10 +TOKEN @98:16 +IDENTIFIER @98:18 id raw edges.raw [v package] : java.util.List : java.util.List +TOKEN @98:18 +TOKEN @98:22 +NEW_CLASS @98:24 new ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ArrayList flags [public] overridden [AbstractList.[], AbstractCollection.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @98:24 +IDENTIFIER @98:28 id ArrayList ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList +TOKEN @98:28 +ARGUMENTS @98:37 +TOKEN @98:37 +TOKEN @98:38 +TOKEN @98:39 +EXPRESSION_STATEMENT @99:5 +METHOD_INVOCATION @99:5 call PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing PrintStream flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @99:5 : ? +MEMBER_SELECT @99:5 : java.io.PrintStream +IDENTIFIER @99:5 id System java.lang.System [t final public] : java.lang.System : java.lang.System +TOKEN @99:5 +TOKEN @99:11 +IDENTIFIER @99:12 id out System.out [v static final public] : java.io.PrintStream : java.io.PrintStream +TOKEN @99:12 +TOKEN @99:15 +IDENTIFIER @99:16 id println PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void +TOKEN @99:16 +ARGUMENTS @99:23 +TOKEN @99:23 +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +PLUS @99:24 : java.lang.String +IDENTIFIER @99:24 id size edges.size [v package] : int : int +TOKEN @99:24 +TOKEN @99:29 +IDENTIFIER @99:31 id value edges.value [v package] : java.lang.String : java.lang.String +TOKEN @99:31 +TOKEN @99:37 +IDENTIFIER @99:39 id other edges.other [v package] : java.lang.String : java.lang.String +TOKEN @99:39 +TOKEN @99:45 +IDENTIFIER @99:47 id held edges.held [v package] : java.lang.String : java.lang.String +TOKEN @99:47 +TOKEN @99:52 +IDENTIFIER @99:54 id explicitHeld edges.explicitHeld [v package] : java.lang.String : java.lang.String +TOKEN @99:54 +TOKEN @99:67 +IDENTIFIER @99:69 id got edges.got [v package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @99:69 +TOKEN @99:73 +IDENTIFIER @99:75 id key edges.key [v package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @99:75 +TOKEN @99:79 +IDENTIFIER @99:81 id parts edges.parts [v package] : java.util.Map> : java.util.Map> +TOKEN @99:81 +TOKEN @99:87 +IDENTIFIER @99:89 id counts edges.counts [v package] : java.util.Map : java.util.Map +TOKEN @99:89 +TOKEN @99:96 +IDENTIFIER @99:98 id longest edges.longest [v package] : java.util.Optional : java.util.Optional +TOKEN @99:98 +TOKEN @99:106 +IDENTIFIER @99:108 id flat edges.flat [v package] : java.util.List : java.util.List +TOKEN @99:108 +TOKEN @99:113 +IDENTIFIER @99:115 id repeat edges.repeat [v package] : java.util.function.BiFunction : java.util.function.BiFunction +TOKEN @99:115 +TOKEN @99:122 +IDENTIFIER @99:124 id factory edges.factory [v package] : java.util.function.Supplier> : java.util.function.Supplier> +TOKEN @99:124 +TOKEN @99:132 +IDENTIFIER @99:134 id callable edges.callable [v package] : java.util.concurrent.Callable : java.util.concurrent.Callable +TOKEN @99:134 +TOKEN @100:7 +IDENTIFIER @100:9 id iterator edges.iterator [v package] : java.util.Iterator : java.util.Iterator +TOKEN @100:9 +TOKEN @100:18 +IDENTIFIER @100:20 id anonymous edges.anonymous [v package] : java.util.Comparator : java.util.Comparator +TOKEN @100:20 +TOKEN @100:30 +IDENTIFIER @100:32 id raw edges.raw [v package] : java.util.List : java.util.List +TOKEN @100:32 +TOKEN @100:36 +IDENTIFIER @100:38 id type edges.type [v package] : java.lang.Class : java.lang.Class +TOKEN @100:38 +TOKEN @100:43 +IDENTIFIER @100:45 id typed edges.typed [v package] : java.lang.Class : java.lang.Class +TOKEN @100:45 +TOKEN @100:51 +IDENTIFIER @100:53 id fromSink edges.fromSink [v package] : java.lang.Object : java.lang.Object +TOKEN @100:53 +TOKEN @100:61 +TOKEN @100:62 +TOKEN @101:3 +TOKEN @102:1 +TOKEN @103:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/GenericEdges.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/GenericEdges.java new file mode 100644 index 00000000000..cb697e480a3 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/GenericEdges.java @@ -0,0 +1,102 @@ +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.Callable; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +class GenericEdges { + + class Node { + K key; + V value; + + V get() { + return value; + } + } + + static class Outer { + class Inner { + T held; + + T held() { + return held; + } + } + + Inner make() { + return new Inner(); + } + } + + interface Thrower { + void run() throws E; + } + + static void call(Thrower thrower) throws E { + thrower.run(); + } + + static List mapAll(Collection input, Function mapper) { + List result = new ArrayList<>(); + for (T item : input) { + result.add(mapper.apply(item)); + } + return result; + } + + Map nodes = new HashMap<>(); + + void edges(List numbers, List sink, Map> nested, Optional maybe) + throws IOException { + Number first = numbers.get(0); + sink.add(1); + Object fromSink = sink.get(0); + int size = nested.get("k").size(); + Class type = first.getClass(); + Class typed = first.getClass(); + String value = maybe.orElseThrow(IllegalStateException::new); + String other = maybe.orElseGet(() -> "x"); + call(() -> { + throw new IOException("io"); + }); + Outer outer = new Outer<>(); + Outer.Inner inner = outer.make(); + String held = inner.held(); + Outer.Inner explicit = outer.new Inner(); + String explicitHeld = explicit.held; + Node node = nodes.values().iterator().next(); + V got = node.get(); + K key = node.key; + List lengths = mapAll(List.of("a", "bb"), String::length); + List strings = GenericEdges.mapAll(lengths, String::valueOf); + Map> parts = strings.stream().collect(Collectors.partitioningBy(s -> s.isEmpty())); + Map counts = strings.stream().collect(Collectors.toMap(Function.identity(), String::length, Integer::sum)); + Optional longest = lengths.stream().max(Comparator.naturalOrder()); + Stream> chunks = Stream.of(strings, strings); + List flat = chunks.flatMap(List::stream).collect(Collectors.toList()); + BiFunction repeat = String::repeat; + Supplier> factory = ArrayList::new; + Callable callable = lengths::size; + Iterator iterator = numbers.iterator(); + Comparator anonymous = new Comparator<>() { + @Override + public int compare(String left, String right) { + return left.compareTo(right); + } + }; + List raw = new ArrayList(); + System.out.println(size + value + other + held + explicitHeld + got + key + parts + counts + longest + flat + repeat + factory + callable + + iterator + anonymous + raw + type + typed + fromSink); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/GenericEdges.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/GenericEdges.textproto.gz new file mode 100644 index 00000000000..ca96a5e44e6 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/GenericEdges.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Generics.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Generics.expected.txt new file mode 100644 index 00000000000..bb2028f37e0 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Generics.expected.txt @@ -0,0 +1,1047 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id util unknown : ? +TOKEN @1:13 +TOKEN @1:17 +IDENTIFIER @1:18 id ArrayList unknown : ? +TOKEN @1:18 +TOKEN @1:27 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id util unknown : ? +TOKEN @2:13 +TOKEN @2:17 +IDENTIFIER @2:18 id Arrays unknown : ? +TOKEN @2:18 +TOKEN @2:24 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id util unknown : ? +TOKEN @3:13 +TOKEN @3:17 +IDENTIFIER @3:18 id Collections unknown : ? +TOKEN @3:18 +TOKEN @3:29 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id util unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id HashMap unknown : ? +TOKEN @4:18 +TOKEN @4:25 +IMPORT @5:1 +TOKEN @5:1 +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +IDENTIFIER @5:8 id java unknown : ? +TOKEN @5:8 +TOKEN @5:12 +IDENTIFIER @5:13 id util unknown : ? +TOKEN @5:13 +TOKEN @5:17 +IDENTIFIER @5:18 id List unknown : ? +TOKEN @5:18 +TOKEN @5:22 +IMPORT @6:1 +TOKEN @6:1 +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +IDENTIFIER @6:8 id java unknown : ? +TOKEN @6:8 +TOKEN @6:12 +IDENTIFIER @6:13 id util unknown : ? +TOKEN @6:13 +TOKEN @6:17 +IDENTIFIER @6:18 id Map unknown : ? +TOKEN @6:18 +TOKEN @6:21 +IMPORT @7:1 +TOKEN @7:1 +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +IDENTIFIER @7:8 id java unknown : ? +TOKEN @7:8 +TOKEN @7:12 +IDENTIFIER @7:13 id util unknown : ? +TOKEN @7:13 +TOKEN @7:17 +IDENTIFIER @7:18 id Optional unknown : ? +TOKEN @7:18 +TOKEN @7:26 +IMPORT @8:1 +TOKEN @8:1 +MEMBER_SELECT @8:8 : ? +MEMBER_SELECT @8:8 : ? +MEMBER_SELECT @8:8 : ? +IDENTIFIER @8:8 id java unknown : ? +TOKEN @8:8 +TOKEN @8:12 +IDENTIFIER @8:13 id util unknown : ? +TOKEN @8:13 +TOKEN @8:17 +IDENTIFIER @8:18 id function unknown : ? +TOKEN @8:18 +TOKEN @8:26 +IDENTIFIER @8:27 id Function unknown : ? +TOKEN @8:27 +TOKEN @8:35 +CLASS @10:1 class .Generics [t package] : Generics super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [package] members [37:48, , Box, box, copied, empty, entry, field, firstItem, firstNumber, fixed, invert, inverted, items, map, mapped, max, maxInt, maxString, maybe, numbers, orElse, size, unboxed, values] lookupToString 0 outermost Generics annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw true declaring Generics +MODIFIERS +TOKEN @10:1 +IDENTIFIER @10:7 id Generics .Generics [t package] : Generics : Generics +TOKEN @10:7 +TYPE_PARAMETERS @10:15 +TOKEN @10:15 +TYPE_PARAMETER @10:16 +IDENTIFIER @10:16 id T Generics.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @10:16 +TOKEN @10:17 +LIST +LIST +TOKEN @10:19 +CLASS @12:3 class Generics.Box [t static package] : Generics$Box super java.lang.Object interfaces [] + details declared true usages 5 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [static, package] members [, get, map, value] lookupToString 0 outermost Generics annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw true declaring Box +MODIFIERS @12:3 +TOKEN @12:3 +TOKEN @12:10 +IDENTIFIER @12:16 id Box Generics.Box [t static package] : Generics$Box : Generics$Box +TOKEN @12:16 +TYPE_PARAMETERS @12:19 +TOKEN @12:19 +TYPE_PARAMETER @12:20 +IDENTIFIER @12:20 id E Box.E [t package] : E erasure java.lang.Object : E erasure java.lang.Object +TOKEN @12:20 +TOKEN @12:21 +LIST +LIST +TOKEN @12:23 +VARIABLE @13:5 var Box.value [v package] : E erasure java.lang.Object + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Box flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @13:5 id E Box.E [t package] : E erasure java.lang.Object : E erasure java.lang.Object +TOKEN @13:5 +IDENTIFIER @13:7 id value Box.value [v package] : E erasure java.lang.Object : E erasure java.lang.Object +TOKEN @13:7 +TOKEN @13:12 +CONSTRUCTOR @15:5 method Box. [m package] : ? (E erasure java.lang.Object) returns void throws [] sig Generics$Box#(Ljava/lang/Object;)V overrides false + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Box flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @15:5 id Box Box. [m package] : ? (E erasure java.lang.Object) returns void throws [] sig Generics$Box#(Ljava/lang/Object;)V : void +TOKEN @15:5 +TOKEN @15:8 +VARIABLE @15:9 var .value [v package] : E erasure java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Box flags [package] local true parameter true effectivelyFinal true constant null owner Generics$Box#(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 2 metadata 0 enclosing Box type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @15:9 id E Box.E [t package] : E erasure java.lang.Object : E erasure java.lang.Object +TOKEN @15:9 +IDENTIFIER @15:11 id value .value [v package] : E erasure java.lang.Object : E erasure java.lang.Object +TOKEN @15:11 +TOKEN @15:16 +BLOCK @15:18 +TOKEN @15:18 +EXPRESSION_STATEMENT @16:7 +ASSIGNMENT @16:7 : E erasure java.lang.Object +MEMBER_SELECT @16:7 : E erasure java.lang.Object +IDENTIFIER @16:7 id this Box.this [v final] : Generics$Box : Generics$Box +TOKEN @16:7 +TOKEN @16:11 +IDENTIFIER @16:12 id value Box.value [v package] : E erasure java.lang.Object : E erasure java.lang.Object +TOKEN @16:12 +TOKEN @16:18 +IDENTIFIER @16:20 id value .value [v package] : E erasure java.lang.Object : E erasure java.lang.Object +TOKEN @16:20 +TOKEN @16:25 +TOKEN @17:5 +METHOD @19:5 method Box.get [m package] : ? () returns E erasure java.lang.Object throws [] sig Generics$Box#get()Ljava/lang/Object; overrides false + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Box flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @19:5 id E Box.E [t package] : E erasure java.lang.Object : E erasure java.lang.Object +TOKEN @19:5 +IDENTIFIER @19:7 id get Box.get [m package] : ? () returns E erasure java.lang.Object throws [] sig Generics$Box#get()Ljava/lang/Object; : E erasure java.lang.Object +TOKEN @19:7 +TOKEN @19:10 +TOKEN @19:11 +BLOCK @19:13 +TOKEN @19:13 +RETURN_STATEMENT @20:7 +TOKEN @20:7 +IDENTIFIER @20:14 id value Box.value [v package] : E erasure java.lang.Object : E erasure java.lang.Object +TOKEN @20:14 +TOKEN @20:19 +TOKEN @21:5 +METHOD @23:5 method Box.map [m package] : ? (java.util.function.Function) returns Generics$Box throws [] sig Generics$Box#map(Ljava/util/function/Function;)LGenerics$Box; overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Box flags [package] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [mapper] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS +TYPE_PARAMETERS @23:5 +TOKEN @23:5 +TYPE_PARAMETER @23:6 +IDENTIFIER @23:6 id R map.R [t package] : R erasure java.lang.Object : R erasure java.lang.Object +TOKEN @23:6 +TOKEN @23:7 +PARAMETERIZED_TYPE @23:9 : Generics$Box +IDENTIFIER @23:9 id Box Generics.Box [t static package] : Generics$Box : Generics$Box +TOKEN @23:9 +TYPE_ARGUMENTS @23:12 +TOKEN @23:12 +IDENTIFIER @23:13 id R map.R [t package] : R erasure java.lang.Object : R erasure java.lang.Object +TOKEN @23:13 +TOKEN @23:14 +IDENTIFIER @23:16 id map Box.map [m package] : ? (java.util.function.Function) returns Generics$Box throws [] sig Generics$Box#map(Ljava/util/function/Function;)LGenerics$Box; : Generics$Box +TOKEN @23:16 +TOKEN @23:19 +VARIABLE @23:20 var map.mapper [v package] : java.util.function.Function + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Box flags [package] local true parameter true effectivelyFinal true constant null owner map Generics$Box#map(Ljava/util/function/Function;)LGenerics$Box; [package] returns Generics$Box parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Box type true kinds truefalsefalse other falsefalsefalsefalsetruetrue1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @23:20 : java.util.function.Function +IDENTIFIER @23:20 id Function java.util.function.Function [t public interface] : java.util.function.Function @java.lang.FunctionalInterface : java.util.function.Function +TOKEN @23:20 +TYPE_ARGUMENTS @23:28 +TOKEN @23:28 +SUPER_WILDCARD @23:29 +TOKEN @23:29 +TOKEN @23:31 +IDENTIFIER @23:37 id E Box.E [t package] : E erasure java.lang.Object : E erasure java.lang.Object +TOKEN @23:37 +TOKEN @23:38 +EXTENDS_WILDCARD @23:40 +TOKEN @23:40 +TOKEN @23:42 +IDENTIFIER @23:50 id R map.R [t package] : R erasure java.lang.Object : R erasure java.lang.Object +TOKEN @23:50 +TOKEN @23:51 +IDENTIFIER @23:53 id mapper map.mapper [v package] : java.util.function.Function : java.util.function.Function +TOKEN @23:53 +TOKEN @23:59 +BLOCK @23:61 +TOKEN @23:61 +RETURN_STATEMENT @24:7 +TOKEN @24:7 +NEW_CLASS @24:14 new Box. [m package] : ? (R erasure java.lang.Object) returns void throws [] sig Generics$Box#(Ljava/lang/Object;)V : Generics$Box + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Box flags [package] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [value] parameterMetadata [] +TOKEN @24:14 +PARAMETERIZED_TYPE @24:18 : Generics$Box +IDENTIFIER @24:18 id Box Box. [m package] : ? (R erasure java.lang.Object) returns void throws [] sig Generics$Box#(Ljava/lang/Object;)V : Generics$Box +TOKEN @24:18 +TYPE_ARGUMENTS @24:21 +TOKEN @24:21 +TOKEN @24:22 +ARGUMENTS @24:23 +TOKEN @24:23 +METHOD_INVOCATION @24:24 call Function.apply [m abstract public] : ? (java.lang.Object) returns R erasure java.lang.Object throws [] sig java.util.function.Function#apply(Ljava/lang/Object;)Ljava/lang/Object; : java.lang.Object + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Function flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @24:24 : ? +IDENTIFIER @24:24 id mapper map.mapper [v package] : java.util.function.Function : java.util.function.Function +TOKEN @24:24 +TOKEN @24:30 +IDENTIFIER @24:31 id apply Function.apply [m abstract public] : ? (java.lang.Object) returns R erasure java.lang.Object throws [] sig java.util.function.Function#apply(Ljava/lang/Object;)Ljava/lang/Object; : java.lang.Object +TOKEN @24:31 +ARGUMENTS @24:36 +TOKEN @24:36 +IDENTIFIER @24:37 id value Box.value [v package] : E erasure java.lang.Object : E erasure java.lang.Object +TOKEN @24:37 +TOKEN @24:42 +TOKEN @24:43 +TOKEN @24:44 +TOKEN @25:5 +TOKEN @26:3 +VARIABLE @28:3 var Generics.field [v package] : T erasure java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @28:3 id T Generics.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @28:3 +IDENTIFIER @28:5 id field Generics.field [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @28:5 +TOKEN @28:10 +VARIABLE @29:3 var Generics.items [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @29:3 : java.util.List +IDENTIFIER @29:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @29:3 +TYPE_ARGUMENTS @29:7 +TOKEN @29:7 +IDENTIFIER @29:8 id T Generics.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @29:8 +TOKEN @29:9 +IDENTIFIER @29:11 id items Generics.items [v package] : java.util.List : java.util.List +TOKEN @29:11 +TOKEN @29:17 +NEW_CLASS @29:19 new ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ArrayList flags [public] overridden [AbstractList.[], AbstractCollection.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @29:19 +PARAMETERIZED_TYPE @29:23 : java.util.ArrayList +IDENTIFIER @29:23 id ArrayList ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList +TOKEN @29:23 +TYPE_ARGUMENTS @29:32 +TOKEN @29:32 +TOKEN @29:33 +ARGUMENTS @29:34 +TOKEN @29:34 +TOKEN @29:35 +TOKEN @29:36 +VARIABLE @30:3 var Generics.map [v package] : java.util.Map> + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @30:3 : java.util.Map> +IDENTIFIER @30:3 id Map java.util.Map [t public interface] : java.util.Map> : java.util.Map> +TOKEN @30:3 +TYPE_ARGUMENTS @30:6 +TOKEN @30:6 +IDENTIFIER @30:7 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @30:7 +TOKEN @30:13 +PARAMETERIZED_TYPE @30:15 : java.util.List +IDENTIFIER @30:15 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @30:15 +TYPE_ARGUMENTS @30:19 +TOKEN @30:19 +IDENTIFIER @30:20 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @30:20 +TOKEN @30:27 +TOKEN @30:28 +IDENTIFIER @30:30 id map Generics.map [v package] : java.util.Map> : java.util.Map> +TOKEN @30:30 +TOKEN @30:34 +NEW_CLASS @30:36 new HashMap. [m public] : ? () returns void throws [] sig java.util.HashMap#()V : java.util.HashMap> + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing HashMap flags [public] overridden [AbstractMap.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @30:36 +PARAMETERIZED_TYPE @30:40 : java.util.HashMap> +IDENTIFIER @30:40 id HashMap HashMap. [m public] : ? () returns void throws [] sig java.util.HashMap#()V : java.util.HashMap> +TOKEN @30:40 +TYPE_ARGUMENTS @30:47 +TOKEN @30:47 +TOKEN @30:48 +ARGUMENTS @30:49 +TOKEN @30:49 +TOKEN @30:50 +TOKEN @30:51 +VARIABLE @31:3 var Generics.box [v package] : Generics$Box + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @31:3 : Generics$Box +IDENTIFIER @31:3 id Box Generics.Box [t static package] : Generics$Box : Generics$Box +TOKEN @31:3 +TYPE_ARGUMENTS @31:6 +TOKEN @31:6 +IDENTIFIER @31:7 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @31:7 +TOKEN @31:13 +IDENTIFIER @31:15 id box Generics.box [v package] : Generics$Box : Generics$Box +TOKEN @31:15 +TOKEN @31:19 +NEW_CLASS @31:21 new Box. [m package] : ? (java.lang.String) returns void throws [] sig Generics$Box#(Ljava/lang/Object;)V : Generics$Box + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Box flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +TOKEN @31:21 +PARAMETERIZED_TYPE @31:25 : Generics$Box +IDENTIFIER @31:25 id Box Box. [m package] : ? (java.lang.String) returns void throws [] sig Generics$Box#(Ljava/lang/Object;)V : Generics$Box +TOKEN @31:25 +TYPE_ARGUMENTS @31:28 +TOKEN @31:28 +TOKEN @31:29 +ARGUMENTS @31:30 +TOKEN @31:30 +STRING_LITERAL @31:31 : java.lang.String = text +TOKEN @31:31 +TOKEN @31:37 +TOKEN @31:38 +VARIABLE @32:3 var Generics.mapped [v package] : Generics$Box + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @32:3 : Generics$Box +IDENTIFIER @32:3 id Box Generics.Box [t static package] : Generics$Box : Generics$Box +TOKEN @32:3 +TYPE_ARGUMENTS @32:6 +TOKEN @32:6 +IDENTIFIER @32:7 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @32:7 +TOKEN @32:14 +IDENTIFIER @32:16 id mapped Generics.mapped [v package] : Generics$Box : Generics$Box +TOKEN @32:16 +TOKEN @32:23 +METHOD_INVOCATION @32:25 call Box.map [m package] : ? (java.util.function.Function) returns Generics$Box throws [] sig Generics$Box#map(Ljava/util/function/Function;)LGenerics$Box; : Generics$Box + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Box flags [package] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [mapper] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MEMBER_SELECT @32:25 : ? +IDENTIFIER @32:25 id box Generics.box [v package] : Generics$Box : Generics$Box +TOKEN @32:25 +TOKEN @32:28 +IDENTIFIER @32:29 id map Box.map [m package] : ? (java.util.function.Function) returns Generics$Box throws [] sig Generics$Box#map(Ljava/util/function/Function;)LGenerics$Box; : Generics$Box +TOKEN @32:29 +ARGUMENTS @32:32 +TOKEN @32:32 +METHOD_REFERENCE @32:33 : java.util.function.Function +IDENTIFIER @32:33 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @32:33 +TOKEN @32:39 +IDENTIFIER @32:41 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @32:41 +TOKEN @32:47 +TOKEN @32:48 +VARIABLE @33:3 var Generics.unboxed [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @33:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @33:3 +IDENTIFIER @33:10 id unboxed Generics.unboxed [v package] : java.lang.String : java.lang.String +TOKEN @33:10 +TOKEN @33:18 +METHOD_INVOCATION @33:20 call Box.get [m package] : ? () returns java.lang.String throws [] sig Generics$Box#get()Ljava/lang/Object; : java.lang.String + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Box flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @33:20 : ? +IDENTIFIER @33:20 id box Generics.box [v package] : Generics$Box : Generics$Box +TOKEN @33:20 +TOKEN @33:23 +IDENTIFIER @33:24 id get Box.get [m package] : ? () returns java.lang.String throws [] sig Generics$Box#get()Ljava/lang/Object; : java.lang.String +TOKEN @33:24 +ARGUMENTS @33:27 +TOKEN @33:27 +TOKEN @33:28 +TOKEN @33:29 +VARIABLE @34:3 var Generics.size [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @34:3 : int +TOKEN @34:3 +IDENTIFIER @34:7 id size Generics.size [v package] : int : int +TOKEN @34:7 +TOKEN @34:12 +METHOD_INVOCATION @34:14 call Box.get [m package] : ? () returns java.lang.Integer throws [] sig Generics$Box#get()Ljava/lang/Object; : java.lang.Integer + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Box flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @34:14 : ? +IDENTIFIER @34:14 id mapped Generics.mapped [v package] : Generics$Box : Generics$Box +TOKEN @34:14 +TOKEN @34:20 +IDENTIFIER @34:21 id get Box.get [m package] : ? () returns java.lang.Integer throws [] sig Generics$Box#get()Ljava/lang/Object; : java.lang.Integer +TOKEN @34:21 +ARGUMENTS @34:24 +TOKEN @34:24 +TOKEN @34:25 +TOKEN @34:26 +VARIABLE @35:3 var Generics.fixed [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @35:3 : java.util.List +IDENTIFIER @35:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @35:3 +TYPE_ARGUMENTS @35:7 +TOKEN @35:7 +IDENTIFIER @35:8 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @35:8 +TOKEN @35:14 +IDENTIFIER @35:16 id fixed Generics.fixed [v package] : java.util.List : java.util.List +TOKEN @35:16 +TOKEN @35:22 +METHOD_INVOCATION @35:24 call Arrays.asList [m static public] : ? @java.lang.SafeVarargs (java.lang.String[]) returns java.util.List throws [] sig java.util.Arrays#asList([Ljava/lang/Object;)Ljava/util/List; : java.util.List + details declared false usages 1 metadata [java.lang.SafeVarargs()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.SafeVarargs tree false values 0 annotated true] typeArguments [] enclosing Arrays flags [static, public] overridden [] overridable false generic true default false synchronized false varargs true native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @35:24 : ? +IDENTIFIER @35:24 id Arrays java.util.Arrays [t final public] : java.util.Arrays : java.util.Arrays +TOKEN @35:24 +TOKEN @35:30 +IDENTIFIER @35:31 id asList Arrays.asList [m static public] : ? @java.lang.SafeVarargs (java.lang.String[]) returns java.util.List throws [] sig java.util.Arrays#asList([Ljava/lang/Object;)Ljava/util/List; : java.util.List +TOKEN @35:31 +ARGUMENTS @35:37 +TOKEN @35:37 +STRING_LITERAL @35:38 : java.lang.String = a +TOKEN @35:38 +TOKEN @35:41 +STRING_LITERAL @35:43 : java.lang.String = b +TOKEN @35:43 +TOKEN @35:46 +TOKEN @35:47 +VARIABLE @36:3 var Generics.empty [v package] : java.util.List + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @36:3 : java.util.List +IDENTIFIER @36:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @36:3 +TYPE_ARGUMENTS @36:7 +TOKEN @36:7 +IDENTIFIER @36:8 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @36:8 +TOKEN @36:15 +IDENTIFIER @36:17 id empty Generics.empty [v package] : java.util.List : java.util.List +TOKEN @36:17 +TOKEN @36:23 +METHOD_INVOCATION @36:25 call Collections.emptyList [m static final public] : ? () returns java.util.List throws [] sig java.util.Collections#emptyList()Ljava/util/List; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collections flags [static, final, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @36:25 : ? +IDENTIFIER @36:25 id Collections java.util.Collections [t public] : java.util.Collections : java.util.Collections +TOKEN @36:25 +TOKEN @36:36 +IDENTIFIER @36:37 id emptyList Collections.emptyList [m static final public] : ? () returns java.util.List throws [] sig java.util.Collections#emptyList()Ljava/util/List; : java.util.List +TOKEN @36:37 +ARGUMENTS @36:46 +TOKEN @36:46 +TOKEN @36:47 +TOKEN @36:48 +VARIABLE @37:3 var Generics.maybe [v package] : java.util.Optional + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @37:3 : java.util.Optional +IDENTIFIER @37:3 id Optional java.util.Optional [t final public] : java.util.Optional @jdk.internal.ValueBased : java.util.Optional +TOKEN @37:3 +TYPE_ARGUMENTS @37:11 +TOKEN @37:11 +IDENTIFIER @37:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @37:12 +TOKEN @37:18 +IDENTIFIER @37:20 id maybe Generics.maybe [v package] : java.util.Optional : java.util.Optional +TOKEN @37:20 +TOKEN @37:26 +METHOD_INVOCATION @37:28 call Optional.map [m public] : ? (java.util.function.Function) returns java.util.Optional throws [] sig java.util.Optional#map(Ljava/util/function/Function;)Ljava/util/Optional; : java.util.Optional + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Optional flags [public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @37:28 : ? +METHOD_INVOCATION @37:28 call Optional.of [m static public] : ? (java.lang.String) returns java.util.Optional throws [] sig java.util.Optional#of(Ljava/lang/Object;)Ljava/util/Optional; : java.util.Optional + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Optional flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @37:28 : ? +IDENTIFIER @37:28 id Optional java.util.Optional [t final public] : java.util.Optional @jdk.internal.ValueBased : java.util.Optional +TOKEN @37:28 +TOKEN @37:36 +IDENTIFIER @37:37 id of Optional.of [m static public] : ? (java.lang.String) returns java.util.Optional throws [] sig java.util.Optional#of(Ljava/lang/Object;)Ljava/util/Optional; : java.util.Optional +TOKEN @37:37 +ARGUMENTS @37:39 +TOKEN @37:39 +STRING_LITERAL @37:40 : java.lang.String = x +TOKEN @37:40 +TOKEN @37:43 +TOKEN @37:44 +IDENTIFIER @37:45 id map Optional.map [m public] : ? (java.util.function.Function) returns java.util.Optional throws [] sig java.util.Optional#map(Ljava/util/function/Function;)Ljava/util/Optional; : java.util.Optional +TOKEN @37:45 +ARGUMENTS @37:48 +TOKEN @37:48 +LAMBDA_EXPRESSION @37:49 : java.util.function.Function +VARIABLE @37:49 var apply.s [v package] : java.lang.String + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Function flags [package] local true parameter true effectivelyFinal true constant null owner apply java.util.function.Function#apply(Ljava/lang/Object;)Ljava/lang/Object; [abstract, public] returns ? parameters 1 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing Function type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @37:49 id s apply.s [v package] : java.lang.String : java.lang.String +TOKEN @37:49 +TOKEN @37:51 +PLUS @37:54 : java.lang.String +IDENTIFIER @37:54 id s apply.s [v package] : java.lang.String : java.lang.String +TOKEN @37:54 +TOKEN @37:56 +STRING_LITERAL @37:58 : java.lang.String = y +TOKEN @37:58 +TOKEN @37:61 +TOKEN @37:62 +VARIABLE @38:3 var Generics.orElse [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @38:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @38:3 +IDENTIFIER @38:10 id orElse Generics.orElse [v package] : java.lang.String : java.lang.String +TOKEN @38:10 +TOKEN @38:17 +METHOD_INVOCATION @38:19 call Optional.orElse [m public] : ? (java.lang.String) returns java.lang.String throws [] sig java.util.Optional#orElse(Ljava/lang/Object;)Ljava/lang/Object; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Optional flags [public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @38:19 : ? +IDENTIFIER @38:19 id maybe Generics.maybe [v package] : java.util.Optional : java.util.Optional +TOKEN @38:19 +TOKEN @38:24 +IDENTIFIER @38:25 id orElse Optional.orElse [m public] : ? (java.lang.String) returns java.lang.String throws [] sig java.util.Optional#orElse(Ljava/lang/Object;)Ljava/lang/Object; : java.lang.String +TOKEN @38:25 +ARGUMENTS @38:31 +TOKEN @38:31 +STRING_LITERAL @38:32 : java.lang.String = none +TOKEN @38:32 +TOKEN @38:38 +TOKEN @38:39 +VARIABLE @39:3 var Generics.numbers [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @39:3 : java.util.List +IDENTIFIER @39:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @39:3 +TYPE_ARGUMENTS @39:7 +TOKEN @39:7 +EXTENDS_WILDCARD @39:8 +TOKEN @39:8 +TOKEN @39:10 +IDENTIFIER @39:18 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @39:18 +TOKEN @39:24 +IDENTIFIER @39:26 id numbers Generics.numbers [v package] : java.util.List : java.util.List +TOKEN @39:26 +TOKEN @39:34 +METHOD_INVOCATION @39:36 call List.of [m static public] : ? (java.lang.Integer,java.lang.Integer) returns java.util.List throws [] sig java.util.List#of(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/List; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +MEMBER_SELECT @39:36 : ? +IDENTIFIER @39:36 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @39:36 +TOKEN @39:40 +IDENTIFIER @39:41 id of List.of [m static public] : ? (java.lang.Integer,java.lang.Integer) returns java.util.List throws [] sig java.util.List#of(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/List; : java.util.List +TOKEN @39:41 +ARGUMENTS @39:43 +TOKEN @39:43 +INT_LITERAL @39:44 : int = 1 +TOKEN @39:44 +TOKEN @39:45 +DOUBLE_LITERAL @39:47 : double +TOKEN @39:47 +TOKEN @39:50 +TOKEN @39:51 +VARIABLE @40:3 var Generics.firstNumber [v package] : java.lang.Number + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @40:3 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @40:3 +IDENTIFIER @40:10 id firstNumber Generics.firstNumber [v package] : java.lang.Number : java.lang.Number +TOKEN @40:10 +TOKEN @40:22 +METHOD_INVOCATION @40:24 call List.get [m abstract public] : ? (int) returns java.lang.Number throws [] sig java.util.List#get(I)Ljava/lang/Object; : java.lang.Number + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @40:24 : ? +IDENTIFIER @40:24 id numbers Generics.numbers [v package] : java.util.List : java.util.List +TOKEN @40:24 +TOKEN @40:31 +IDENTIFIER @40:32 id get List.get [m abstract public] : ? (int) returns java.lang.Number throws [] sig java.util.List#get(I)Ljava/lang/Object; : java.lang.Number +TOKEN @40:32 +ARGUMENTS @40:35 +TOKEN @40:35 +INT_LITERAL @40:36 : int = 0 +TOKEN @40:36 +TOKEN @40:37 +TOKEN @40:38 +METHOD @42:3 method Generics.max [m static package] : ? (A erasure java.lang.Comparable,A erasure java.lang.Comparable) returns Generics#max<:java.lang.Comparable<>>( throws [] sig Generics#max(Ljava/lang/Comparable;Ljava/lang/Comparable;)LGenerics#max<:java/lang/Comparable<>>(; overrides false + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [static, package] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [left, right] parameterMetadata [] +MODIFIERS @42:3 +TOKEN @42:3 +TYPE_PARAMETERS @42:10 +TOKEN @42:10 +TYPE_PARAMETER @42:11 +IDENTIFIER @42:11 id A max.A [t package] : A erasure java.lang.Comparable : A erasure java.lang.Comparable +TOKEN @42:11 +TOKEN @42:13 +LIST @42:21 +PARAMETERIZED_TYPE @42:21 : java.lang.Comparable +IDENTIFIER @42:21 id Comparable java.lang.Comparable [t public interface] : java.lang.Comparable : java.lang.Comparable +TOKEN @42:21 +TYPE_ARGUMENTS @42:31 +TOKEN @42:31 +IDENTIFIER @42:32 id A max.A [t package] : A erasure java.lang.Comparable : A erasure java.lang.Comparable +TOKEN @42:32 +TOKEN @42:33 +TOKEN @42:34 +IDENTIFIER @42:36 id A max.A [t package] : A erasure java.lang.Comparable : A erasure java.lang.Comparable +TOKEN @42:36 +IDENTIFIER @42:38 id max Generics.max [m static package] : ? (A erasure java.lang.Comparable,A erasure java.lang.Comparable) returns Generics#max<:java.lang.Comparable<>>( throws [] sig Generics#max(Ljava/lang/Comparable;Ljava/lang/Comparable;)LGenerics#max<:java/lang/Comparable<>>(; : Generics#max<:java.lang.Comparable<>>( +TOKEN @42:38 +TOKEN @42:41 +VARIABLE @42:42 var max.left [v package] : A erasure java.lang.Comparable + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [package] local true parameter true effectivelyFinal true constant null owner max Generics#max(Ljava/lang/Comparable;Ljava/lang/Comparable;)LGenerics#max<:java/lang/Comparable<>>(; [static, package] returns Generics#max<:java.lang.Comparable<>>( parameters 2 thrown 0 overridden 0 declared true usages 2 metadata 0 enclosing Generics type true kinds truefalsefalse other falsefalsefalsefalsefalsetrue2falsefalse +MODIFIERS +IDENTIFIER @42:42 id A max.A [t package] : A erasure java.lang.Comparable : A erasure java.lang.Comparable +TOKEN @42:42 +IDENTIFIER @42:44 id left max.left [v package] : A erasure java.lang.Comparable : A erasure java.lang.Comparable +TOKEN @42:44 +TOKEN @42:48 +VARIABLE @42:50 var max.right [v package] : A erasure java.lang.Comparable + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [package] local true parameter true effectivelyFinal true constant null owner max Generics#max(Ljava/lang/Comparable;Ljava/lang/Comparable;)LGenerics#max<:java/lang/Comparable<>>(; [static, package] returns Generics#max<:java.lang.Comparable<>>( parameters 2 thrown 0 overridden 0 declared true usages 2 metadata 0 enclosing Generics type true kinds truefalsefalse other falsefalsefalsefalsefalsetrue2falsefalse +MODIFIERS +IDENTIFIER @42:50 id A max.A [t package] : A erasure java.lang.Comparable : A erasure java.lang.Comparable +TOKEN @42:50 +IDENTIFIER @42:52 id right max.right [v package] : A erasure java.lang.Comparable : A erasure java.lang.Comparable +TOKEN @42:52 +TOKEN @42:57 +BLOCK @42:59 +TOKEN @42:59 +RETURN_STATEMENT @43:5 +TOKEN @43:5 +CONDITIONAL_EXPRESSION @43:12 : A erasure java.lang.Comparable +GREATER_THAN @43:12 : boolean +METHOD_INVOCATION @43:12 call Comparable.compareTo [m abstract public] : ? (java.lang.Object) returns int throws [] sig java.lang.Comparable#compareTo(Ljava/lang/Object;)I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Comparable flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @43:12 : ? +IDENTIFIER @43:12 id left max.left [v package] : A erasure java.lang.Comparable : A erasure java.lang.Comparable +TOKEN @43:12 +TOKEN @43:16 +IDENTIFIER @43:17 id compareTo Comparable.compareTo [m abstract public] : ? (java.lang.Object) returns int throws [] sig java.lang.Comparable#compareTo(Ljava/lang/Object;)I : int +TOKEN @43:17 +ARGUMENTS @43:26 +TOKEN @43:26 +IDENTIFIER @43:27 id right max.right [v package] : A erasure java.lang.Comparable : A erasure java.lang.Comparable +TOKEN @43:27 +TOKEN @43:32 +TOKEN @43:34 +INT_LITERAL @43:36 : int = 0 +TOKEN @43:36 +TOKEN @43:38 +IDENTIFIER @43:40 id left max.left [v package] : A erasure java.lang.Comparable : A erasure java.lang.Comparable +TOKEN @43:40 +TOKEN @43:45 +IDENTIFIER @43:47 id right max.right [v package] : A erasure java.lang.Comparable : A erasure java.lang.Comparable +TOKEN @43:47 +TOKEN @43:52 +TOKEN @44:3 +VARIABLE @46:3 var Generics.maxInt [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @46:3 : int +TOKEN @46:3 +IDENTIFIER @46:7 id maxInt Generics.maxInt [v package] : int : int +TOKEN @46:7 +TOKEN @46:14 +METHOD_INVOCATION @46:16 call Generics.max [m static package] : ? (java.lang.Integer,java.lang.Integer) returns java.lang.Integer throws [] sig Generics#max(Ljava/lang/Comparable;Ljava/lang/Comparable;)LGenerics#max<:java/lang/Comparable<>>(; : java.lang.Integer + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [static, package] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [left, right] parameterMetadata [] +IDENTIFIER @46:16 id max Generics.max [m static package] : ? (java.lang.Integer,java.lang.Integer) returns java.lang.Integer throws [] sig Generics#max(Ljava/lang/Comparable;Ljava/lang/Comparable;)LGenerics#max<:java/lang/Comparable<>>(; : java.lang.Integer +TOKEN @46:16 +ARGUMENTS @46:19 +TOKEN @46:19 +INT_LITERAL @46:20 : int = 1 +TOKEN @46:20 +TOKEN @46:21 +INT_LITERAL @46:23 : int = 2 +TOKEN @46:23 +TOKEN @46:24 +TOKEN @46:25 +VARIABLE @47:3 var Generics.maxString [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @47:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @47:3 +IDENTIFIER @47:10 id maxString Generics.maxString [v package] : java.lang.String : java.lang.String +TOKEN @47:10 +TOKEN @47:20 +METHOD_INVOCATION @47:22 call Generics.max [m static package] : ? (java.lang.String,java.lang.String) returns java.lang.String throws [] sig Generics#max(Ljava/lang/Comparable;Ljava/lang/Comparable;)LGenerics#max<:java/lang/Comparable<>>(; : java.lang.String + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [static, package] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [left, right] parameterMetadata [] +IDENTIFIER @47:22 id max Generics.max [m static package] : ? (java.lang.String,java.lang.String) returns java.lang.String throws [] sig Generics#max(Ljava/lang/Comparable;Ljava/lang/Comparable;)LGenerics#max<:java/lang/Comparable<>>(; : java.lang.String +TOKEN @47:22 +ARGUMENTS @47:25 +TOKEN @47:25 +STRING_LITERAL @47:26 : java.lang.String = a +TOKEN @47:26 +TOKEN @47:29 +STRING_LITERAL @47:31 : java.lang.String = b +TOKEN @47:31 +TOKEN @47:34 +TOKEN @47:35 +VARIABLE @48:3 var Generics.firstItem [v package] : T erasure java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @48:3 id T Generics.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @48:3 +IDENTIFIER @48:5 id firstItem Generics.firstItem [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @48:5 +TOKEN @48:15 +METHOD_INVOCATION @48:17 call List.get [m abstract public] : ? (int) returns T erasure java.lang.Object throws [] sig java.util.List#get(I)Ljava/lang/Object; : T erasure java.lang.Object + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @48:17 : ? +IDENTIFIER @48:17 id items Generics.items [v package] : java.util.List : java.util.List +TOKEN @48:17 +TOKEN @48:22 +IDENTIFIER @48:23 id get List.get [m abstract public] : ? (int) returns T erasure java.lang.Object throws [] sig java.util.List#get(I)Ljava/lang/Object; : T erasure java.lang.Object +TOKEN @48:23 +ARGUMENTS @48:26 +TOKEN @48:26 +INT_LITERAL @48:27 : int = 0 +TOKEN @48:27 +TOKEN @48:28 +TOKEN @48:29 +VARIABLE @49:3 var Generics.copied [v package] : java.util.List + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @49:3 : java.util.List +IDENTIFIER @49:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @49:3 +TYPE_ARGUMENTS @49:7 +TOKEN @49:7 +IDENTIFIER @49:8 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @49:8 +TOKEN @49:14 +IDENTIFIER @49:16 id copied Generics.copied [v package] : java.util.List : java.util.List +TOKEN @49:16 +TOKEN @49:23 +NEW_CLASS @49:25 new ArrayList. [m public] : ? (java.util.Collection) returns void throws [] sig java.util.ArrayList#(Ljava/util/Collection;)V : java.util.ArrayList + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ArrayList flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @49:25 +PARAMETERIZED_TYPE @49:29 : java.util.ArrayList +IDENTIFIER @49:29 id ArrayList ArrayList. [m public] : ? (java.util.Collection) returns void throws [] sig java.util.ArrayList#(Ljava/util/Collection;)V : java.util.ArrayList +TOKEN @49:29 +TYPE_ARGUMENTS @49:38 +TOKEN @49:38 +TOKEN @49:39 +ARGUMENTS @49:40 +TOKEN @49:40 +IDENTIFIER @49:41 id fixed Generics.fixed [v package] : java.util.List : java.util.List +TOKEN @49:41 +TOKEN @49:46 +TOKEN @49:47 +VARIABLE @50:3 var Generics.entry [v package] : java.util.Map$Entry> + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @50:3 : java.util.Map$Entry> +MEMBER_SELECT @50:3 : java.util.Map$Entry> +IDENTIFIER @50:3 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @50:3 +TOKEN @50:6 +IDENTIFIER @50:7 id Entry java.util.Entry [t static public interface] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @50:7 +TYPE_ARGUMENTS @50:12 +TOKEN @50:12 +IDENTIFIER @50:13 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @50:13 +TOKEN @50:19 +PARAMETERIZED_TYPE @50:21 : java.util.List +IDENTIFIER @50:21 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @50:21 +TYPE_ARGUMENTS @50:25 +TOKEN @50:25 +IDENTIFIER @50:26 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @50:26 +TOKEN @50:33 +TOKEN @50:34 +IDENTIFIER @50:36 id entry Generics.entry [v package] : java.util.Map$Entry> : java.util.Map$Entry> +TOKEN @50:36 +TOKEN @50:42 +METHOD_INVOCATION @50:44 call Iterator.next [m abstract public] : ? () returns java.util.Map$Entry> throws [] sig java.util.Iterator#next()Ljava/lang/Object; : java.util.Map$Entry> + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Iterator flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @50:44 : ? +METHOD_INVOCATION @50:44 call Set.iterator [m abstract public] : ? () returns java.util.Iterator>> throws [] sig java.util.Set#iterator()Ljava/util/Iterator; : java.util.Iterator>> + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Set flags [abstract, public] overridden [Collection.iterator[], Iterable.iterator[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @50:44 : ? +METHOD_INVOCATION @50:44 call Map.entrySet [m abstract public] : ? () returns java.util.Set>> throws [] sig java.util.Map#entrySet()Ljava/util/Set; : java.util.Set>> + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Map flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @50:44 : ? +IDENTIFIER @50:44 id map Generics.map [v package] : java.util.Map> : java.util.Map> +TOKEN @50:44 +TOKEN @50:47 +IDENTIFIER @50:48 id entrySet Map.entrySet [m abstract public] : ? () returns java.util.Set>> throws [] sig java.util.Map#entrySet()Ljava/util/Set; : java.util.Set>> +TOKEN @50:48 +ARGUMENTS @50:56 +TOKEN @50:56 +TOKEN @50:57 +TOKEN @50:58 +IDENTIFIER @50:59 id iterator Set.iterator [m abstract public] : ? () returns java.util.Iterator>> throws [] sig java.util.Set#iterator()Ljava/util/Iterator; : java.util.Iterator>> +TOKEN @50:59 +ARGUMENTS @50:67 +TOKEN @50:67 +TOKEN @50:68 +TOKEN @50:69 +IDENTIFIER @50:70 id next Iterator.next [m abstract public] : ? () returns java.util.Map$Entry> throws [] sig java.util.Iterator#next()Ljava/lang/Object; : java.util.Map$Entry> +TOKEN @50:70 +ARGUMENTS @50:74 +TOKEN @50:74 +TOKEN @50:75 +TOKEN @50:76 +VARIABLE @51:3 var Generics.values [v package] : java.util.List + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @51:3 : java.util.List +IDENTIFIER @51:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @51:3 +TYPE_ARGUMENTS @51:7 +TOKEN @51:7 +IDENTIFIER @51:8 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @51:8 +TOKEN @51:15 +IDENTIFIER @51:17 id values Generics.values [v package] : java.util.List : java.util.List +TOKEN @51:17 +TOKEN @51:24 +METHOD_INVOCATION @51:26 call Entry.getValue [m abstract public] : ? () returns java.util.List throws [] sig java.util.Map$Entry#getValue()Ljava/lang/Object; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Entry flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @51:26 : ? +IDENTIFIER @51:26 id entry Generics.entry [v package] : java.util.Map$Entry> : java.util.Map$Entry> +TOKEN @51:26 +TOKEN @51:31 +IDENTIFIER @51:32 id getValue Entry.getValue [m abstract public] : ? () returns java.util.List throws [] sig java.util.Map$Entry#getValue()Ljava/lang/Object; : java.util.List +TOKEN @51:32 +ARGUMENTS @51:40 +TOKEN @51:40 +TOKEN @51:41 +TOKEN @51:42 +METHOD @53:3 method Generics.invert [m package] : ? (java.util.Map) returns java.util.Map throws [] sig Generics#invert(Ljava/util/Map;)Ljava/util/Map; overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Generics flags [package] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [source] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [], [] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS +TYPE_PARAMETERS @53:3 +TOKEN @53:3 +TYPE_PARAMETER @53:4 +IDENTIFIER @53:4 id K invert.K [t package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @53:4 +TOKEN @53:5 +TYPE_PARAMETER @53:7 +IDENTIFIER @53:7 id V invert.V [t package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @53:7 +TOKEN @53:8 +PARAMETERIZED_TYPE @53:10 : java.util.Map +IDENTIFIER @53:10 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @53:10 +TYPE_ARGUMENTS @53:13 +TOKEN @53:13 +IDENTIFIER @53:14 id V invert.V [t package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @53:14 +TOKEN @53:15 +IDENTIFIER @53:17 id K invert.K [t package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @53:17 +TOKEN @53:18 +IDENTIFIER @53:20 id invert Generics.invert [m package] : ? (java.util.Map) returns java.util.Map throws [] sig Generics#invert(Ljava/util/Map;)Ljava/util/Map; : java.util.Map +TOKEN @53:20 +TOKEN @53:26 +VARIABLE @53:27 var invert.source [v package] : java.util.Map + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Generics flags [package] local true parameter true effectivelyFinal true constant null owner invert Generics#invert(Ljava/util/Map;)Ljava/util/Map; [package] returns java.util.Map parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Generics type true kinds truefalsefalse other falsefalsefalsefalsetruetrue1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @53:27 : java.util.Map +IDENTIFIER @53:27 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @53:27 +TYPE_ARGUMENTS @53:30 +TOKEN @53:30 +IDENTIFIER @53:31 id K invert.K [t package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @53:31 +TOKEN @53:32 +IDENTIFIER @53:34 id V invert.V [t package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @53:34 +TOKEN @53:35 +IDENTIFIER @53:37 id source invert.source [v package] : java.util.Map : java.util.Map +TOKEN @53:37 +TOKEN @53:43 +BLOCK @53:45 +TOKEN @53:45 +VARIABLE @54:5 var invert.result [v package] : java.util.Map + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Generics flags [package] local true parameter false effectivelyFinal true constant null owner invert Generics#invert(Ljava/util/Map;)Ljava/util/Map; [package] returns java.util.Map parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Generics type true kinds truefalsefalse other falsefalsefalsefalsetruetrue1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @54:5 : java.util.Map +IDENTIFIER @54:5 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @54:5 +TYPE_ARGUMENTS @54:8 +TOKEN @54:8 +IDENTIFIER @54:9 id V invert.V [t package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @54:9 +TOKEN @54:10 +IDENTIFIER @54:12 id K invert.K [t package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @54:12 +TOKEN @54:13 +IDENTIFIER @54:15 id result invert.result [v package] : java.util.Map : java.util.Map +TOKEN @54:15 +TOKEN @54:22 +NEW_CLASS @54:24 new HashMap. [m public] : ? () returns void throws [] sig java.util.HashMap#()V : java.util.HashMap + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing HashMap flags [public] overridden [AbstractMap.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @54:24 +PARAMETERIZED_TYPE @54:28 : java.util.HashMap +IDENTIFIER @54:28 id HashMap HashMap. [m public] : ? () returns void throws [] sig java.util.HashMap#()V : java.util.HashMap +TOKEN @54:28 +TYPE_ARGUMENTS @54:35 +TOKEN @54:35 +TOKEN @54:36 +ARGUMENTS @54:37 +TOKEN @54:37 +TOKEN @54:38 +TOKEN @54:39 +EXPRESSION_STATEMENT @55:5 +METHOD_INVOCATION @55:5 call Map.forEach [m public] : ? (java.util.function.BiConsumer) returns void throws [] sig java.util.Map#forEach(Ljava/util/function/BiConsumer;)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Map flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @55:5 : ? +IDENTIFIER @55:5 id source invert.source [v package] : java.util.Map : java.util.Map +TOKEN @55:5 +TOKEN @55:11 +IDENTIFIER @55:12 id forEach Map.forEach [m public] : ? (java.util.function.BiConsumer) returns void throws [] sig java.util.Map#forEach(Ljava/util/function/BiConsumer;)V : void +TOKEN @55:12 +ARGUMENTS @55:19 +TOKEN @55:19 +LAMBDA_EXPRESSION @55:20 : java.util.function.BiConsumer +TOKEN @55:20 +VARIABLE @55:21 var accept.k [v package] : K erasure java.lang.Object + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing BiConsumer flags [package] local true parameter true effectivelyFinal true constant null owner accept java.util.function.BiConsumer#accept(Ljava/lang/Object;Ljava/lang/Object;)V [abstract, public] returns void parameters 2 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing BiConsumer type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @55:21 id k accept.k [v package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @55:21 +TOKEN @55:22 +VARIABLE @55:24 var accept.v [v package] : V erasure java.lang.Object + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing BiConsumer flags [package] local true parameter true effectivelyFinal true constant null owner accept java.util.function.BiConsumer#accept(Ljava/lang/Object;Ljava/lang/Object;)V [abstract, public] returns void parameters 2 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing BiConsumer type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @55:24 id v accept.v [v package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @55:24 +TOKEN @55:25 +TOKEN @55:27 +METHOD_INVOCATION @55:30 call Map.put [m abstract public] : ? (V erasure java.lang.Object,K erasure java.lang.Object) returns K erasure java.lang.Object throws [] sig java.util.Map#put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; : K erasure java.lang.Object + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Map flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +MEMBER_SELECT @55:30 : ? +IDENTIFIER @55:30 id result invert.result [v package] : java.util.Map : java.util.Map +TOKEN @55:30 +TOKEN @55:36 +IDENTIFIER @55:37 id put Map.put [m abstract public] : ? (V erasure java.lang.Object,K erasure java.lang.Object) returns K erasure java.lang.Object throws [] sig java.util.Map#put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; : K erasure java.lang.Object +TOKEN @55:37 +ARGUMENTS @55:40 +TOKEN @55:40 +IDENTIFIER @55:41 id v accept.v [v package] : V erasure java.lang.Object : V erasure java.lang.Object +TOKEN @55:41 +TOKEN @55:42 +IDENTIFIER @55:44 id k accept.k [v package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @55:44 +TOKEN @55:45 +TOKEN @55:46 +TOKEN @55:47 +RETURN_STATEMENT @56:5 +TOKEN @56:5 +IDENTIFIER @56:12 id result invert.result [v package] : java.util.Map : java.util.Map +TOKEN @56:12 +TOKEN @56:18 +TOKEN @57:3 +VARIABLE @59:3 var Generics.inverted [v package] : java.util.Map + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Generics flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @59:3 : java.util.Map +IDENTIFIER @59:3 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @59:3 +TYPE_ARGUMENTS @59:6 +TOKEN @59:6 +IDENTIFIER @59:7 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @59:7 +TOKEN @59:14 +IDENTIFIER @59:16 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @59:16 +TOKEN @59:22 +IDENTIFIER @59:24 id inverted Generics.inverted [v package] : java.util.Map : java.util.Map +TOKEN @59:24 +TOKEN @59:33 +METHOD_INVOCATION @59:35 call Generics.invert [m package] : ? (java.util.Map) returns java.util.Map throws [] sig Generics#invert(Ljava/util/Map;)Ljava/util/Map; : java.util.Map + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Generics flags [package] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [source] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [], [] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +IDENTIFIER @59:35 id invert Generics.invert [m package] : ? (java.util.Map) returns java.util.Map throws [] sig Generics#invert(Ljava/util/Map;)Ljava/util/Map; : java.util.Map +TOKEN @59:35 +ARGUMENTS @59:41 +TOKEN @59:41 +METHOD_INVOCATION @59:42 call Map.of [m static public] : ? (java.lang.String,java.lang.Integer) returns java.util.Map throws [] sig java.util.Map#of(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map; : java.util.Map + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Map flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +MEMBER_SELECT @59:42 : ? +IDENTIFIER @59:42 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @59:42 +TOKEN @59:45 +IDENTIFIER @59:46 id of Map.of [m static public] : ? (java.lang.String,java.lang.Integer) returns java.util.Map throws [] sig java.util.Map#of(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map; : java.util.Map +TOKEN @59:46 +ARGUMENTS @59:48 +TOKEN @59:48 +STRING_LITERAL @59:49 : java.lang.String = a +TOKEN @59:49 +TOKEN @59:52 +INT_LITERAL @59:54 : int = 1 +TOKEN @59:54 +TOKEN @59:55 +TOKEN @59:56 +TOKEN @59:57 +TOKEN @60:1 +TOKEN @61:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Generics.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Generics.java new file mode 100644 index 00000000000..d8d0a357f1b --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Generics.java @@ -0,0 +1,60 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; + +class Generics { + + static class Box { + E value; + + Box(E value) { + this.value = value; + } + + E get() { + return value; + } + + Box map(Function mapper) { + return new Box<>(mapper.apply(value)); + } + } + + T field; + List items = new ArrayList<>(); + Map> map = new HashMap<>(); + Box box = new Box<>("text"); + Box mapped = box.map(String::length); + String unboxed = box.get(); + int size = mapped.get(); + List fixed = Arrays.asList("a", "b"); + List empty = Collections.emptyList(); + Optional maybe = Optional.of("x").map(s -> s + "y"); + String orElse = maybe.orElse("none"); + List numbers = List.of(1, 2.0); + Number firstNumber = numbers.get(0); + + static > A max(A left, A right) { + return left.compareTo(right) > 0 ? left : right; + } + + int maxInt = max(1, 2); + String maxString = max("a", "b"); + T firstItem = items.get(0); + List copied = new ArrayList<>(fixed); + Map.Entry> entry = map.entrySet().iterator().next(); + List values = entry.getValue(); + + Map invert(Map source) { + Map result = new HashMap<>(); + source.forEach((k, v) -> result.put(v, k)); + return result; + } + + Map inverted = invert(Map.of("a", 1)); +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Generics.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Generics.textproto.gz new file mode 100644 index 00000000000..c2ff8e12a2b Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Generics.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Imports.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Imports.expected.txt new file mode 100644 index 00000000000..eefc5189811 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Imports.expected.txt @@ -0,0 +1,1043 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id util unknown : ? +TOKEN @1:13 +TOKEN @1:17 +IDENTIFIER @1:18 id HashMap unknown : ? +TOKEN @1:18 +TOKEN @1:25 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id util unknown : ? +TOKEN @2:13 +TOKEN @2:17 +IDENTIFIER @2:18 id List unknown : ? +TOKEN @2:18 +TOKEN @2:22 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id util unknown : ? +TOKEN @3:13 +TOKEN @3:17 +IDENTIFIER @3:18 id Map unknown : ? +TOKEN @3:18 +TOKEN @3:21 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id util unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id Map unknown : ? +TOKEN @4:18 +TOKEN @4:21 +IDENTIFIER @4:22 id Entry unknown : ? +TOKEN @4:22 +TOKEN @4:27 +IMPORT @5:1 +TOKEN @5:1 +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +IDENTIFIER @5:8 id java unknown : ? +TOKEN @5:8 +TOKEN @5:12 +IDENTIFIER @5:13 id util unknown : ? +TOKEN @5:13 +TOKEN @5:17 +IDENTIFIER @5:18 id concurrent unknown : ? +TOKEN @5:18 +TOKEN @5:28 +IDENTIFIER @5:29 id TimeUnit unknown : ? +TOKEN @5:29 +TOKEN @5:37 +IMPORT @6:1 +TOKEN @6:1 +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +IDENTIFIER @6:8 id java unknown : ? +TOKEN @6:8 +TOKEN @6:12 +IDENTIFIER @6:13 id util unknown : ? +TOKEN @6:13 +TOKEN @6:17 +IDENTIFIER @6:18 id * unknown : ? +TOKEN @6:18 +TOKEN @6:19 +IMPORT @7:1 +TOKEN @7:1 +TOKEN @7:8 +MEMBER_SELECT @7:15 : ? +MEMBER_SELECT @7:15 : ? +MEMBER_SELECT @7:15 : ? +IDENTIFIER @7:15 id java unknown : ? +TOKEN @7:15 +TOKEN @7:19 +IDENTIFIER @7:20 id lang unknown : ? +TOKEN @7:20 +TOKEN @7:24 +IDENTIFIER @7:25 id Math unknown : ? +TOKEN @7:25 +TOKEN @7:29 +IDENTIFIER @7:30 id PI unknown : ? +TOKEN @7:30 +TOKEN @7:32 +IMPORT @8:1 +TOKEN @8:1 +TOKEN @8:8 +MEMBER_SELECT @8:15 : ? +MEMBER_SELECT @8:15 : ? +MEMBER_SELECT @8:15 : ? +IDENTIFIER @8:15 id java unknown : ? +TOKEN @8:15 +TOKEN @8:19 +IDENTIFIER @8:20 id lang unknown : ? +TOKEN @8:20 +TOKEN @8:24 +IDENTIFIER @8:25 id Math unknown : ? +TOKEN @8:25 +TOKEN @8:29 +IDENTIFIER @8:30 id abs unknown : ? +TOKEN @8:30 +TOKEN @8:33 +IMPORT @9:1 +TOKEN @9:1 +TOKEN @9:8 +MEMBER_SELECT @9:15 : ? +MEMBER_SELECT @9:15 : ? +MEMBER_SELECT @9:15 : ? +IDENTIFIER @9:15 id java unknown : ? +TOKEN @9:15 +TOKEN @9:19 +IDENTIFIER @9:20 id lang unknown : ? +TOKEN @9:20 +TOKEN @9:24 +IDENTIFIER @9:25 id Integer unknown : ? +TOKEN @9:25 +TOKEN @9:32 +IDENTIFIER @9:33 id MAX_VALUE unknown : ? +TOKEN @9:33 +TOKEN @9:42 +IMPORT @10:1 +TOKEN @10:1 +TOKEN @10:8 +MEMBER_SELECT @10:15 : ? +MEMBER_SELECT @10:15 : ? +MEMBER_SELECT @10:15 : ? +MEMBER_SELECT @10:15 : ? +IDENTIFIER @10:15 id java unknown : ? +TOKEN @10:15 +TOKEN @10:19 +IDENTIFIER @10:20 id util unknown : ? +TOKEN @10:20 +TOKEN @10:24 +IDENTIFIER @10:25 id concurrent unknown : ? +TOKEN @10:25 +TOKEN @10:35 +IDENTIFIER @10:36 id TimeUnit unknown : ? +TOKEN @10:36 +TOKEN @10:44 +IDENTIFIER @10:45 id SECONDS unknown : ? +TOKEN @10:45 +TOKEN @10:52 +IMPORT @11:1 +TOKEN @11:1 +TOKEN @11:8 +MEMBER_SELECT @11:15 : ? +MEMBER_SELECT @11:15 : ? +MEMBER_SELECT @11:15 : ? +IDENTIFIER @11:15 id java unknown : ? +TOKEN @11:15 +TOKEN @11:19 +IDENTIFIER @11:20 id util unknown : ? +TOKEN @11:20 +TOKEN @11:24 +IDENTIFIER @11:25 id Collections unknown : ? +TOKEN @11:25 +TOKEN @11:36 +IDENTIFIER @11:37 id * unknown : ? +TOKEN @11:37 +TOKEN @11:38 +IMPORT @12:1 +TOKEN @12:1 +TOKEN @12:8 +MEMBER_SELECT @12:15 : ? +MEMBER_SELECT @12:15 : ? +MEMBER_SELECT @12:15 : ? +IDENTIFIER @12:15 id java unknown : ? +TOKEN @12:15 +TOKEN @12:19 +IDENTIFIER @12:20 id util unknown : ? +TOKEN @12:20 +TOKEN @12:24 +IDENTIFIER @12:25 id Map unknown : ? +TOKEN @12:25 +TOKEN @12:28 +IDENTIFIER @12:29 id entry unknown : ? +TOKEN @12:29 +TOKEN @12:34 +CLASS @14:1 class .Imports [t package] : Imports super java.lang.Object interfaces [java.lang.Comparable] + details declared true usages 6 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [package] members [, Child, Greeter, Holder, Polite, absolute, circle, compareTo, constant, entries, fromStar, fullyQualified, maximum, optional, pair, qualifiedPair, sorted, unit] lookupToString 0 outermost Imports annotation false subtypeOf [java.lang.Object, java.lang.Comparable] superTypes [java.lang.Comparable, java.lang.Object] numerical false wrapper false raw false declaring Imports +MODIFIERS +TOKEN @14:1 +IDENTIFIER @14:7 id Imports .Imports [t package] : Imports : Imports +TOKEN @14:7 +TYPE_PARAMETERS +TOKEN @14:15 +LIST @14:26 +PARAMETERIZED_TYPE @14:26 : java.lang.Comparable +IDENTIFIER @14:26 id Comparable java.lang.Comparable [t public interface] : java.lang.Comparable : java.lang.Comparable +TOKEN @14:26 +TYPE_ARGUMENTS @14:36 +TOKEN @14:36 +IDENTIFIER @14:37 id Imports .Imports [t package] : Imports : Imports +TOKEN @14:37 +TOKEN @14:44 +LIST +TOKEN @14:46 +VARIABLE @16:3 var Imports.circle [v package] : double + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @16:3 : double +TOKEN @16:3 +IDENTIFIER @16:10 id circle Imports.circle [v package] : double : double +TOKEN @16:10 +TOKEN @16:17 +MULTIPLY @16:19 : double +INT_LITERAL @16:19 : int = 2 +TOKEN @16:19 +TOKEN @16:21 +IDENTIFIER @16:23 id PI Math.PI [v static final public] : double : double = 3.141592653589793 +TOKEN @16:23 +TOKEN @16:25 +VARIABLE @17:3 var Imports.maximum [v package] : int + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @17:3 : int +TOKEN @17:3 +IDENTIFIER @17:7 id maximum Imports.maximum [v package] : int : int +TOKEN @17:7 +TOKEN @17:15 +IDENTIFIER @17:17 id MAX_VALUE Integer.MAX_VALUE [v static final public] : int : int = 2147483647 +TOKEN @17:17 +TOKEN @17:26 +VARIABLE @18:3 var Imports.unit [v package] : java.util.concurrent.TimeUnit + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @18:3 id TimeUnit java.util.concurrent.TimeUnit [t final public enum] : java.util.concurrent.TimeUnit : java.util.concurrent.TimeUnit +TOKEN @18:3 +IDENTIFIER @18:12 id unit Imports.unit [v package] : java.util.concurrent.TimeUnit : java.util.concurrent.TimeUnit +TOKEN @18:12 +TOKEN @18:17 +IDENTIFIER @18:19 id SECONDS TimeUnit.SECONDS [v static final public enum] : java.util.concurrent.TimeUnit : java.util.concurrent.TimeUnit +TOKEN @18:19 +TOKEN @18:26 +VARIABLE @19:3 var Imports.pair [v package] : java.util.Map$Entry + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Imports flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @19:3 : java.util.Map$Entry +IDENTIFIER @19:3 id Entry java.util.Entry [t static public interface] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @19:3 +TYPE_ARGUMENTS @19:8 +TOKEN @19:8 +IDENTIFIER @19:9 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @19:9 +TOKEN @19:15 +IDENTIFIER @19:17 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @19:17 +TOKEN @19:24 +IDENTIFIER @19:26 id pair Imports.pair [v package] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @19:26 +TOKEN @19:31 +METHOD_INVOCATION @19:33 call Map.entry [m static public] : ? (java.lang.String,java.lang.Integer) returns java.util.Map$Entry throws [] sig java.util.Map#entry(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map$Entry; : java.util.Map$Entry + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Map flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +IDENTIFIER @19:33 id entry Map.entry [m static public] : ? (java.lang.String,java.lang.Integer) returns java.util.Map$Entry throws [] sig java.util.Map#entry(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map$Entry; : java.util.Map$Entry +TOKEN @19:33 +ARGUMENTS @19:38 +TOKEN @19:38 +STRING_LITERAL @19:39 : java.lang.String = a +TOKEN @19:39 +TOKEN @19:42 +INT_LITERAL @19:44 : int = 1 +TOKEN @19:44 +TOKEN @19:45 +TOKEN @19:46 +VARIABLE @20:3 var Imports.qualifiedPair [v package] : java.util.Map$Entry + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Imports flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @20:3 : java.util.Map$Entry +MEMBER_SELECT @20:3 : java.util.Map$Entry +IDENTIFIER @20:3 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @20:3 +TOKEN @20:6 +IDENTIFIER @20:7 id Entry java.util.Entry [t static public interface] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @20:7 +TYPE_ARGUMENTS @20:12 +TOKEN @20:12 +IDENTIFIER @20:13 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @20:13 +TOKEN @20:19 +IDENTIFIER @20:21 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @20:21 +TOKEN @20:28 +IDENTIFIER @20:30 id qualifiedPair Imports.qualifiedPair [v package] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @20:30 +TOKEN @20:44 +METHOD_INVOCATION @20:46 call Map.entry [m static public] : ? (java.lang.String,java.lang.Integer) returns java.util.Map$Entry throws [] sig java.util.Map#entry(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map$Entry; : java.util.Map$Entry + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Map flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +MEMBER_SELECT @20:46 : ? +IDENTIFIER @20:46 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @20:46 +TOKEN @20:49 +IDENTIFIER @20:50 id entry Map.entry [m static public] : ? (java.lang.String,java.lang.Integer) returns java.util.Map$Entry throws [] sig java.util.Map#entry(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map$Entry; : java.util.Map$Entry +TOKEN @20:50 +ARGUMENTS @20:55 +TOKEN @20:55 +STRING_LITERAL @20:56 : java.lang.String = b +TOKEN @20:56 +TOKEN @20:59 +INT_LITERAL @20:61 : int = 2 +TOKEN @20:61 +TOKEN @20:62 +TOKEN @20:63 +VARIABLE @21:3 var Imports.fullyQualified [v package] : java.util.Map$Entry + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Imports flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @21:3 : java.util.Map$Entry +MEMBER_SELECT @21:3 : java.util.Map$Entry +MEMBER_SELECT @21:3 : java.util.Map +MEMBER_SELECT @21:3 : ? +IDENTIFIER @21:3 id java .java [p package] : ? : ? +TOKEN @21:3 +TOKEN @21:7 +IDENTIFIER @21:8 id util .java.util [p package] : ? : ? +TOKEN @21:8 +TOKEN @21:12 +IDENTIFIER @21:13 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @21:13 +TOKEN @21:16 +IDENTIFIER @21:17 id Entry java.util.Entry [t static public interface] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @21:17 +TYPE_ARGUMENTS @21:22 +TOKEN @21:22 +IDENTIFIER @21:23 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @21:23 +TOKEN @21:29 +IDENTIFIER @21:31 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @21:31 +TOKEN @21:38 +IDENTIFIER @21:40 id fullyQualified Imports.fullyQualified [v package] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @21:40 +TOKEN @21:55 +IDENTIFIER @21:57 id pair Imports.pair [v package] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @21:57 +TOKEN @21:61 +VARIABLE @22:3 var Imports.sorted [v package] : java.util.List + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Imports flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @22:3 : java.util.List +IDENTIFIER @22:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @22:3 +TYPE_ARGUMENTS @22:7 +TOKEN @22:7 +IDENTIFIER @22:8 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @22:8 +TOKEN @22:14 +IDENTIFIER @22:16 id sorted Imports.sorted [v package] : java.util.List : java.util.List +TOKEN @22:16 +TOKEN @22:23 +METHOD_INVOCATION @22:25 call Collections.emptyList [m static final public] : ? () returns java.util.List throws [] sig java.util.Collections#emptyList()Ljava/util/List; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collections flags [static, final, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @22:25 id emptyList Collections.emptyList [m static final public] : ? () returns java.util.List throws [] sig java.util.Collections#emptyList()Ljava/util/List; : java.util.List +TOKEN @22:25 +ARGUMENTS @22:34 +TOKEN @22:34 +TOKEN @22:35 +TOKEN @22:36 +VARIABLE @23:3 var Imports.fromStar [v package] : java.util.Set + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Imports flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @23:3 : java.util.Set +IDENTIFIER @23:3 id Set java.util.Set [t public interface] : java.util.Set : java.util.Set +TOKEN @23:3 +TYPE_ARGUMENTS @23:6 +TOKEN @23:6 +IDENTIFIER @23:7 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @23:7 +TOKEN @23:13 +IDENTIFIER @23:15 id fromStar Imports.fromStar [v package] : java.util.Set : java.util.Set +TOKEN @23:15 +TOKEN @23:24 +NEW_CLASS @23:26 new HashSet. [m public] : ? () returns void throws [] sig java.util.HashSet#()V : java.util.HashSet + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing HashSet flags [public] overridden [AbstractSet.[], AbstractCollection.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @23:26 +PARAMETERIZED_TYPE @23:30 : java.util.HashSet +IDENTIFIER @23:30 id HashSet HashSet. [m public] : ? () returns void throws [] sig java.util.HashSet#()V : java.util.HashSet +TOKEN @23:30 +TYPE_ARGUMENTS @23:37 +TOKEN @23:37 +TOKEN @23:38 +ARGUMENTS @23:39 +TOKEN @23:39 +TOKEN @23:40 +TOKEN @23:41 +VARIABLE @24:3 var Imports.optional [v package] : java.util.Optional + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Imports flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @24:3 : java.util.Optional +IDENTIFIER @24:3 id Optional java.util.Optional [t final public] : java.util.Optional @jdk.internal.ValueBased : java.util.Optional +TOKEN @24:3 +TYPE_ARGUMENTS @24:11 +TOKEN @24:11 +IDENTIFIER @24:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @24:12 +TOKEN @24:18 +IDENTIFIER @24:20 id optional Imports.optional [v package] : java.util.Optional : java.util.Optional +TOKEN @24:20 +TOKEN @24:29 +METHOD_INVOCATION @24:31 call Optional.empty [m static public] : ? () returns java.util.Optional throws [] sig java.util.Optional#empty()Ljava/util/Optional; : java.util.Optional + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Optional flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @24:31 : ? +IDENTIFIER @24:31 id Optional java.util.Optional [t final public] : java.util.Optional @jdk.internal.ValueBased : java.util.Optional +TOKEN @24:31 +TOKEN @24:39 +IDENTIFIER @24:40 id empty Optional.empty [m static public] : ? () returns java.util.Optional throws [] sig java.util.Optional#empty()Ljava/util/Optional; : java.util.Optional +TOKEN @24:40 +ARGUMENTS @24:45 +TOKEN @24:45 +TOKEN @24:46 +TOKEN @24:47 +METHOD @26:3 method Imports.absolute [m package] : ? (int) returns int throws [] sig Imports#absolute(I)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @26:3 : int +TOKEN @26:3 +IDENTIFIER @26:7 id absolute Imports.absolute [m package] : ? (int) returns int throws [] sig Imports#absolute(I)I : int +TOKEN @26:7 +TOKEN @26:15 +VARIABLE @26:16 var absolute.value [v package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [package] local true parameter true effectivelyFinal true constant null owner absolute Imports#absolute(I)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Imports type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @26:16 : int +TOKEN @26:16 +IDENTIFIER @26:20 id value absolute.value [v package] : int : int +TOKEN @26:20 +TOKEN @26:25 +BLOCK @26:27 +TOKEN @26:27 +RETURN_STATEMENT @27:5 +TOKEN @27:5 +PLUS @27:12 : int +METHOD_INVOCATION @27:12 call Math.abs [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int) returns int throws [] sig java.lang.Math#abs(I)I : int + details declared false usages 2 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Math flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +IDENTIFIER @27:12 id abs Math.abs [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int) returns int throws [] sig java.lang.Math#abs(I)I : int +TOKEN @27:12 +ARGUMENTS @27:15 +TOKEN @27:15 +IDENTIFIER @27:16 id value absolute.value [v package] : int : int +TOKEN @27:16 +TOKEN @27:21 +TOKEN @27:23 +METHOD_INVOCATION @27:25 call Math.abs [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int) returns int throws [] sig java.lang.Math#abs(I)I : int + details declared false usages 2 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Math flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @27:25 : ? +IDENTIFIER @27:25 id Math java.lang.Math [t final public] : java.lang.Math : java.lang.Math +TOKEN @27:25 +TOKEN @27:29 +IDENTIFIER @27:30 id abs Math.abs [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int) returns int throws [] sig java.lang.Math#abs(I)I : int +TOKEN @27:30 +ARGUMENTS @27:33 +TOKEN @27:33 +UNARY_MINUS @27:34 : int +TOKEN @27:34 +IDENTIFIER @27:35 id value absolute.value [v package] : int : int +TOKEN @27:35 +TOKEN @27:40 +TOKEN @27:41 +TOKEN @28:3 +METHOD @30:3 method Imports.entries [m package] : ? (java.util.Map>) returns void throws [] sig Imports#entries(Ljava/util/Map;)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [map] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @30:3 : void +TOKEN @30:3 +IDENTIFIER @30:8 id entries Imports.entries [m package] : ? (java.util.Map>) returns void throws [] sig Imports#entries(Ljava/util/Map;)V : void +TOKEN @30:8 +TOKEN @30:15 +VARIABLE @30:16 var entries.map [v package] : java.util.Map> + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Imports flags [package] local true parameter true effectivelyFinal true constant null owner entries Imports#entries(Ljava/util/Map;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Imports type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @30:16 : java.util.Map> +IDENTIFIER @30:16 id Map java.util.Map [t public interface] : java.util.Map> : java.util.Map> +TOKEN @30:16 +TYPE_ARGUMENTS @30:19 +TOKEN @30:19 +IDENTIFIER @30:20 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @30:20 +TOKEN @30:26 +PARAMETERIZED_TYPE @30:28 : java.util.List +IDENTIFIER @30:28 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @30:28 +TYPE_ARGUMENTS @30:32 +TOKEN @30:32 +IDENTIFIER @30:33 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @30:33 +TOKEN @30:40 +TOKEN @30:41 +IDENTIFIER @30:43 id map entries.map [v package] : java.util.Map> : java.util.Map> +TOKEN @30:43 +TOKEN @30:46 +BLOCK @30:48 +TOKEN @30:48 +FOR_EACH_STATEMENT @31:5 +TOKEN @31:5 +TOKEN @31:9 +VARIABLE @31:10 var entries.entry [v package] : java.util.Map$Entry> + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Imports flags [package] local true parameter false effectivelyFinal true constant null owner entries Imports#entries(Ljava/util/Map;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Imports type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @31:10 : java.util.Map$Entry> +IDENTIFIER @31:10 id Entry java.util.Entry [t static public interface] : java.util.Map$Entry> : java.util.Map$Entry> +TOKEN @31:10 +TYPE_ARGUMENTS @31:15 +TOKEN @31:15 +IDENTIFIER @31:16 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @31:16 +TOKEN @31:22 +PARAMETERIZED_TYPE @31:24 : java.util.List +IDENTIFIER @31:24 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @31:24 +TYPE_ARGUMENTS @31:28 +TOKEN @31:28 +IDENTIFIER @31:29 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @31:29 +TOKEN @31:36 +TOKEN @31:37 +IDENTIFIER @31:39 id entry entries.entry [v package] : java.util.Map$Entry> : java.util.Map$Entry> +TOKEN @31:39 +TOKEN @31:45 +METHOD_INVOCATION @31:47 call Map.entrySet [m abstract public] : ? () returns java.util.Set>> throws [] sig java.util.Map#entrySet()Ljava/util/Set; : java.util.Set>> + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Map flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @31:47 : ? +IDENTIFIER @31:47 id map entries.map [v package] : java.util.Map> : java.util.Map> +TOKEN @31:47 +TOKEN @31:50 +IDENTIFIER @31:51 id entrySet Map.entrySet [m abstract public] : ? () returns java.util.Set>> throws [] sig java.util.Map#entrySet()Ljava/util/Set; : java.util.Set>> +TOKEN @31:51 +ARGUMENTS @31:59 +TOKEN @31:59 +TOKEN @31:60 +TOKEN @31:61 +BLOCK @31:63 +TOKEN @31:63 +EXPRESSION_STATEMENT @32:7 +METHOD_INVOCATION @32:7 call String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [CharSequence.length[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @32:7 : ? +METHOD_INVOCATION @32:7 call Entry.getKey [m abstract public] : ? () returns java.lang.String throws [] sig java.util.Map$Entry#getKey()Ljava/lang/Object; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Entry flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @32:7 : ? +IDENTIFIER @32:7 id entry entries.entry [v package] : java.util.Map$Entry> : java.util.Map$Entry> +TOKEN @32:7 +TOKEN @32:12 +IDENTIFIER @32:13 id getKey Entry.getKey [m abstract public] : ? () returns java.lang.String throws [] sig java.util.Map$Entry#getKey()Ljava/lang/Object; : java.lang.String +TOKEN @32:13 +ARGUMENTS @32:19 +TOKEN @32:19 +TOKEN @32:20 +TOKEN @32:21 +IDENTIFIER @32:22 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @32:22 +ARGUMENTS @32:28 +TOKEN @32:28 +TOKEN @32:29 +TOKEN @32:30 +EXPRESSION_STATEMENT @33:7 +METHOD_INVOCATION @33:7 call List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.size[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @33:7 : ? +METHOD_INVOCATION @33:7 call Entry.getValue [m abstract public] : ? () returns java.util.List throws [] sig java.util.Map$Entry#getValue()Ljava/lang/Object; : java.util.List + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Entry flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @33:7 : ? +IDENTIFIER @33:7 id entry entries.entry [v package] : java.util.Map$Entry> : java.util.Map$Entry> +TOKEN @33:7 +TOKEN @33:12 +IDENTIFIER @33:13 id getValue Entry.getValue [m abstract public] : ? () returns java.util.List throws [] sig java.util.Map$Entry#getValue()Ljava/lang/Object; : java.util.List +TOKEN @33:13 +ARGUMENTS @33:21 +TOKEN @33:21 +TOKEN @33:22 +TOKEN @33:23 +IDENTIFIER @33:24 id size List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int +TOKEN @33:24 +ARGUMENTS @33:28 +TOKEN @33:28 +TOKEN @33:29 +TOKEN @33:30 +TOKEN @34:5 +FOR_EACH_STATEMENT @35:5 +TOKEN @35:5 +TOKEN @35:9 +VARIABLE @35:10 var entries.entry [v package] : java.util.Map$Entry> + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Imports flags [package] local true parameter false effectivelyFinal true constant null owner entries Imports#entries(Ljava/util/Map;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Imports type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @35:10 : java.util.Map$Entry> +MEMBER_SELECT @35:10 : java.util.Map$Entry> +IDENTIFIER @35:10 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @35:10 +TOKEN @35:13 +IDENTIFIER @35:14 id Entry java.util.Entry [t static public interface] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @35:14 +TYPE_ARGUMENTS @35:19 +TOKEN @35:19 +IDENTIFIER @35:20 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @35:20 +TOKEN @35:26 +PARAMETERIZED_TYPE @35:28 : java.util.List +IDENTIFIER @35:28 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @35:28 +TYPE_ARGUMENTS @35:32 +TOKEN @35:32 +IDENTIFIER @35:33 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @35:33 +TOKEN @35:40 +TOKEN @35:41 +IDENTIFIER @35:43 id entry entries.entry [v package] : java.util.Map$Entry> : java.util.Map$Entry> +TOKEN @35:43 +TOKEN @35:49 +METHOD_INVOCATION @35:51 call HashMap.entrySet [m public] : ? () returns java.util.Set>> throws [] sig java.util.HashMap#entrySet()Ljava/util/Set; : java.util.Set>> + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing HashMap flags [public] overridden [AbstractMap.entrySet[], Map.entrySet[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @35:51 : ? +NEW_CLASS @35:51 new HashMap. [m public] : ? (java.util.Map) returns void throws [] sig java.util.HashMap#(Ljava/util/Map;)V : java.util.HashMap> + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing HashMap flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @35:51 +PARAMETERIZED_TYPE @35:55 : java.util.HashMap> +IDENTIFIER @35:55 id HashMap HashMap. [m public] : ? (java.util.Map) returns void throws [] sig java.util.HashMap#(Ljava/util/Map;)V : java.util.HashMap +TOKEN @35:55 +TYPE_ARGUMENTS @35:62 +TOKEN @35:62 +TOKEN @35:63 +ARGUMENTS @35:64 +TOKEN @35:64 +IDENTIFIER @35:65 id map entries.map [v package] : java.util.Map> : java.util.Map> +TOKEN @35:65 +TOKEN @35:68 +TOKEN @35:69 +IDENTIFIER @35:70 id entrySet HashMap.entrySet [m public] : ? () returns java.util.Set>> throws [] sig java.util.HashMap#entrySet()Ljava/util/Set; : java.util.Set>> +TOKEN @35:70 +ARGUMENTS @35:78 +TOKEN @35:78 +TOKEN @35:79 +TOKEN @35:80 +BLOCK @35:82 +TOKEN @35:82 +EXPRESSION_STATEMENT @36:7 +METHOD_INVOCATION @36:7 call Entry.setValue [m abstract public] : ? (java.util.List) returns java.util.List throws [] sig java.util.Map$Entry#setValue(Ljava/lang/Object;)Ljava/lang/Object; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Entry flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @36:7 : ? +IDENTIFIER @36:7 id entry entries.entry [v package] : java.util.Map$Entry> : java.util.Map$Entry> +TOKEN @36:7 +TOKEN @36:12 +IDENTIFIER @36:13 id setValue Entry.setValue [m abstract public] : ? (java.util.List) returns java.util.List throws [] sig java.util.Map$Entry#setValue(Ljava/lang/Object;)Ljava/lang/Object; : java.util.List +TOKEN @36:13 +ARGUMENTS @36:21 +TOKEN @36:21 +METHOD_INVOCATION @36:22 call Collections.unmodifiableList [m static public] : ? (java.util.List) returns java.util.List throws [] sig java.util.Collections#unmodifiableList(Ljava/util/List;)Ljava/util/List; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collections flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +IDENTIFIER @36:22 id unmodifiableList Collections.unmodifiableList [m static public] : ? (java.util.List) returns java.util.List throws [] sig java.util.Collections#unmodifiableList(Ljava/util/List;)Ljava/util/List; : java.util.List +TOKEN @36:22 +ARGUMENTS @36:38 +TOKEN @36:38 +METHOD_INVOCATION @36:39 call Entry.getValue [m abstract public] : ? () returns java.util.List throws [] sig java.util.Map$Entry#getValue()Ljava/lang/Object; : java.util.List + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Entry flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @36:39 : ? +IDENTIFIER @36:39 id entry entries.entry [v package] : java.util.Map$Entry> : java.util.Map$Entry> +TOKEN @36:39 +TOKEN @36:44 +IDENTIFIER @36:45 id getValue Entry.getValue [m abstract public] : ? () returns java.util.List throws [] sig java.util.Map$Entry#getValue()Ljava/lang/Object; : java.util.List +TOKEN @36:45 +ARGUMENTS @36:53 +TOKEN @36:53 +TOKEN @36:54 +TOKEN @36:55 +TOKEN @36:56 +TOKEN @36:57 +TOKEN @37:5 +TOKEN @38:3 +METHOD @40:3 method Imports.compareTo [m public] : ? @java.lang.Override (Imports) returns int throws [] sig Imports#compareTo(LImports;)I overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Imports flags [public] overridden [Comparable.compareTo[]] overridable true generic false default false synchronized false varargs false native false parameters [other] parameterMetadata [] +MODIFIERS @40:3 +ANNOTATION @40:3 : java.lang.Override +TOKEN @40:3 +IDENTIFIER @40:4 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @40:4 +ARGUMENTS +TOKEN @41:3 +TYPE_PARAMETERS +PRIMITIVE_TYPE @41:10 : int +TOKEN @41:10 +IDENTIFIER @41:14 id compareTo Imports.compareTo [m public] : ? @java.lang.Override (Imports) returns int throws [] sig Imports#compareTo(LImports;)I : int +TOKEN @41:14 +TOKEN @41:23 +VARIABLE @41:24 var compareTo.other [v package] : Imports + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [package] local true parameter true effectivelyFinal true constant null owner compareTo Imports#compareTo(LImports;)I [public] returns int parameters 1 thrown 0 overridden 1 declared true usages 0 metadata 1 enclosing Imports type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @41:24 id Imports .Imports [t package] : Imports : Imports +TOKEN @41:24 +IDENTIFIER @41:32 id other compareTo.other [v package] : Imports : Imports +TOKEN @41:32 +TOKEN @41:37 +BLOCK @41:39 +TOKEN @41:39 +RETURN_STATEMENT @42:5 +TOKEN @42:5 +METHOD_INVOCATION @42:12 call Integer.compare [m static public] : ? (int,int) returns int throws [] sig java.lang.Integer#compare(II)I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Integer flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +MEMBER_SELECT @42:12 : ? +IDENTIFIER @42:12 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @42:12 +TOKEN @42:19 +IDENTIFIER @42:20 id compare Integer.compare [m static public] : ? (int,int) returns int throws [] sig java.lang.Integer#compare(II)I : int +TOKEN @42:20 +ARGUMENTS @42:27 +TOKEN @42:27 +IDENTIFIER @42:28 id maximum Imports.maximum [v package] : int : int +TOKEN @42:28 +TOKEN @42:35 +MEMBER_SELECT @42:37 : int +IDENTIFIER @42:37 id other compareTo.other [v package] : Imports : Imports +TOKEN @42:37 +TOKEN @42:42 +IDENTIFIER @42:43 id maximum Imports.maximum [v package] : int : int +TOKEN @42:43 +TOKEN @42:50 +TOKEN @42:51 +TOKEN @43:3 +INTERFACE @45:3 class Imports.Greeter [t static package interface] : Imports$Greeter super java.lang.Object interfaces [] + details declared true usages 2 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [static, package, interface] members [greet] lookupToString 0 outermost Imports annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Greeter +MODIFIERS +TOKEN @45:3 +IDENTIFIER @45:13 id Greeter Imports.Greeter [t static package interface] : Imports$Greeter : Imports$Greeter +TOKEN @45:13 +TYPE_PARAMETERS +LIST +LIST +TOKEN @45:21 +METHOD @46:5 method Greeter.greet [m public] : ? () returns java.lang.String throws [] sig Imports$Greeter#greet()Ljava/lang/String; overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Greeter flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @46:5 +TOKEN @46:5 +TYPE_PARAMETERS +IDENTIFIER @46:13 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @46:13 +IDENTIFIER @46:20 id greet Greeter.greet [m public] : ? () returns java.lang.String throws [] sig Imports$Greeter#greet()Ljava/lang/String; : java.lang.String +TOKEN @46:20 +TOKEN @46:25 +TOKEN @46:26 +BLOCK @46:28 +TOKEN @46:28 +RETURN_STATEMENT @47:7 +TOKEN @47:7 +STRING_LITERAL @47:14 : java.lang.String = hello +TOKEN @47:14 +TOKEN @47:21 +TOKEN @48:5 +TOKEN @49:3 +INTERFACE @51:3 class Imports.Polite [t static package interface] : Imports$Polite super java.lang.Object interfaces [Imports$Greeter] + details declared true usages 2 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [static, package, interface] members [greet] lookupToString 0 outermost Imports annotation false subtypeOf [java.lang.Object] superTypes [Imports$Greeter, java.lang.Object] numerical false wrapper false raw false declaring Polite +MODIFIERS +TOKEN @51:3 +IDENTIFIER @51:13 id Polite Imports.Polite [t static package interface] : Imports$Polite : Imports$Polite +TOKEN @51:13 +TYPE_PARAMETERS +TOKEN @51:20 +LIST @51:28 +IDENTIFIER @51:28 id Greeter Imports.Greeter [t static package interface] : Imports$Greeter : Imports$Greeter +TOKEN @51:28 +LIST +TOKEN @51:36 +METHOD @52:5 method Polite.greet [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Imports$Polite#greet()Ljava/lang/String; overrides true + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Polite flags [public] overridden [Greeter.greet[]] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @52:5 +ANNOTATION @52:5 : java.lang.Override +TOKEN @52:5 +IDENTIFIER @52:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @52:6 +ARGUMENTS +TOKEN @53:5 +TYPE_PARAMETERS +IDENTIFIER @53:13 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @53:13 +IDENTIFIER @53:20 id greet Polite.greet [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Imports$Polite#greet()Ljava/lang/String; : java.lang.String +TOKEN @53:20 +TOKEN @53:25 +TOKEN @53:26 +BLOCK @53:28 +TOKEN @53:28 +RETURN_STATEMENT @54:7 +TOKEN @54:7 +PLUS @54:14 : java.lang.String +STRING_LITERAL @54:14 : java.lang.String = please +TOKEN @54:14 +TOKEN @54:24 +METHOD_INVOCATION @54:26 call Greeter.greet [m public] : ? () returns java.lang.String throws [] sig Imports$Greeter#greet()Ljava/lang/String; : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Greeter flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @54:26 : ? +MEMBER_SELECT @54:26 : Imports$Greeter +IDENTIFIER @54:26 id Greeter Imports.Greeter [t static package interface] : Imports$Greeter : Imports$Greeter +TOKEN @54:26 +TOKEN @54:33 +IDENTIFIER @54:34 id super Greeter.super [v static final public] : Imports$Greeter : Imports$Greeter +TOKEN @54:34 +TOKEN @54:39 +IDENTIFIER @54:40 id greet Greeter.greet [m public] : ? () returns java.lang.String throws [] sig Imports$Greeter#greet()Ljava/lang/String; : java.lang.String +TOKEN @54:40 +ARGUMENTS @54:45 +TOKEN @54:45 +TOKEN @54:46 +TOKEN @54:47 +TOKEN @55:5 +TOKEN @56:3 +CLASS @58:3 class Imports.Child [t package] : Imports$Child super Imports interfaces [Imports$Polite] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [package] members [, greet, parentMaximum] lookupToString 0 outermost Imports annotation false subtypeOf [java.lang.Object, java.lang.Comparable] superTypes [Imports, Imports$Greeter, Imports$Polite, java.lang.Comparable, java.lang.Object] numerical false wrapper false raw false declaring Child +MODIFIERS +TOKEN @58:3 +IDENTIFIER @58:9 id Child Imports.Child [t package] : Imports$Child : Imports$Child +TOKEN @58:9 +TYPE_PARAMETERS +TOKEN @58:15 +IDENTIFIER @58:23 id Imports .Imports [t package] : Imports : Imports +TOKEN @58:23 +TOKEN @58:31 +LIST @58:42 +IDENTIFIER @58:42 id Polite Imports.Polite [t static package interface] : Imports$Polite : Imports$Polite +TOKEN @58:42 +LIST +TOKEN @58:49 +METHOD @59:5 method Child.greet [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Imports$Child#greet()Ljava/lang/String; overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Child flags [public] overridden [Polite.greet[java.lang.Override tree true values 0 annotated true], Greeter.greet[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @59:5 +ANNOTATION @59:5 : java.lang.Override +TOKEN @59:5 +IDENTIFIER @59:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @59:6 +ARGUMENTS +TOKEN @60:5 +TYPE_PARAMETERS +IDENTIFIER @60:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @60:12 +IDENTIFIER @60:19 id greet Child.greet [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Imports$Child#greet()Ljava/lang/String; : java.lang.String +TOKEN @60:19 +TOKEN @60:24 +TOKEN @60:25 +BLOCK @60:27 +TOKEN @60:27 +RETURN_STATEMENT @61:7 +TOKEN @61:7 +PLUS @61:14 : java.lang.String +PLUS @61:14 : java.lang.String +METHOD_INVOCATION @61:14 call Polite.greet [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Imports$Polite#greet()Ljava/lang/String; : java.lang.String + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Polite flags [public] overridden [Greeter.greet[]] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @61:14 : ? +MEMBER_SELECT @61:14 : Imports$Polite +IDENTIFIER @61:14 id Polite Imports.Polite [t static package interface] : Imports$Polite : Imports$Polite +TOKEN @61:14 +TOKEN @61:20 +IDENTIFIER @61:21 id super Polite.super [v static final public] : Imports$Polite : Imports$Polite +TOKEN @61:21 +TOKEN @61:26 +IDENTIFIER @61:27 id greet Polite.greet [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Imports$Polite#greet()Ljava/lang/String; : java.lang.String +TOKEN @61:27 +ARGUMENTS @61:32 +TOKEN @61:32 +TOKEN @61:33 +TOKEN @61:35 +MEMBER_SELECT @61:37 : int +MEMBER_SELECT @61:37 : Imports +IDENTIFIER @61:37 id Imports .Imports [t package] : Imports : Imports +TOKEN @61:37 +TOKEN @61:44 +IDENTIFIER @61:45 id this Imports.this [v final] : Imports : Imports +TOKEN @61:45 +TOKEN @61:49 +IDENTIFIER @61:50 id maximum Imports.maximum [v package] : int : int +TOKEN @61:50 +TOKEN @61:58 +METHOD_INVOCATION @61:60 call Object.toString [m public] : ? () returns java.lang.String throws [] sig java.lang.Object#toString()Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @61:60 : ? +MEMBER_SELECT @61:60 : Imports +IDENTIFIER @61:60 id Child Imports.Child [t package] : Imports$Child : Imports$Child +TOKEN @61:60 +TOKEN @61:65 +IDENTIFIER @61:66 id super Child.super [v final] : Imports : Imports +TOKEN @61:66 +TOKEN @61:71 +IDENTIFIER @61:72 id toString Object.toString [m public] : ? () returns java.lang.String throws [] sig java.lang.Object#toString()Ljava/lang/String; : java.lang.String +TOKEN @61:72 +ARGUMENTS @61:80 +TOKEN @61:80 +TOKEN @61:81 +TOKEN @61:82 +TOKEN @62:5 +METHOD @64:5 method Child.parentMaximum [m package] : ? () returns int throws [] sig Imports$Child#parentMaximum()I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Child flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @64:5 : int +TOKEN @64:5 +IDENTIFIER @64:9 id parentMaximum Child.parentMaximum [m package] : ? () returns int throws [] sig Imports$Child#parentMaximum()I : int +TOKEN @64:9 +TOKEN @64:22 +TOKEN @64:23 +BLOCK @64:25 +TOKEN @64:25 +RETURN_STATEMENT @65:7 +TOKEN @65:7 +CONDITIONAL_EXPRESSION @65:14 : int +GREATER_THAN @65:14 : boolean +PLUS @65:14 : double +MEMBER_SELECT @65:14 : int +IDENTIFIER @65:14 id super Child.super [v final] : Imports : Imports +TOKEN @65:14 +TOKEN @65:19 +IDENTIFIER @65:20 id maximum Imports.maximum [v package] : int : int +TOKEN @65:20 +TOKEN @65:28 +MEMBER_SELECT @65:30 : double +MEMBER_SELECT @65:30 : Imports +IDENTIFIER @65:30 id Imports .Imports [t package] : Imports : Imports +TOKEN @65:30 +TOKEN @65:37 +IDENTIFIER @65:38 id this Imports.this [v final] : Imports : Imports +TOKEN @65:38 +TOKEN @65:42 +IDENTIFIER @65:43 id circle Imports.circle [v package] : double : double +TOKEN @65:43 +TOKEN @65:50 +INT_LITERAL @65:52 : int = 0 +TOKEN @65:52 +TOKEN @65:54 +INT_LITERAL @65:56 : int = 1 +TOKEN @65:56 +TOKEN @65:58 +INT_LITERAL @65:60 : int = 0 +TOKEN @65:60 +TOKEN @65:61 +TOKEN @66:5 +TOKEN @67:3 +CLASS @69:3 class Imports.Holder [t static package] : Imports$Holder super java.lang.Object interfaces [] + details declared true usages 3 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [static, package] members [, CONSTANT, Deep] lookupToString 0 outermost Imports annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Holder +MODIFIERS @69:3 +TOKEN @69:3 +TOKEN @69:10 +IDENTIFIER @69:16 id Holder Imports.Holder [t static package] : Imports$Holder : Imports$Holder +TOKEN @69:16 +TYPE_PARAMETERS +LIST +LIST +TOKEN @69:23 +VARIABLE @70:5 var Holder.CONSTANT [v static final package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Holder flags [static, final, package] local false parameter false effectivelyFinal true constant c +MODIFIERS @70:5 +TOKEN @70:5 +TOKEN @70:12 +IDENTIFIER @70:18 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @70:18 +IDENTIFIER @70:25 id CONSTANT Holder.CONSTANT [v static final package] : java.lang.String : java.lang.String = c +TOKEN @70:25 +TOKEN @70:34 +STRING_LITERAL @70:36 : java.lang.String = c +TOKEN @70:36 +TOKEN @70:39 +CLASS @72:5 class Holder.Deep [t static package] : Imports$Holder$Deep super java.lang.Object interfaces [] + details declared true usages 2 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Holder flags [static, package] members [, depth] lookupToString 0 outermost Imports annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Deep +MODIFIERS @72:5 +TOKEN @72:5 +TOKEN @72:12 +IDENTIFIER @72:18 id Deep Holder.Deep [t static package] : Imports$Holder$Deep : Imports$Holder$Deep +TOKEN @72:18 +TYPE_PARAMETERS +LIST +LIST +TOKEN @72:23 +VARIABLE @73:7 var Deep.depth [v static package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Deep flags [static, package] local false parameter false effectivelyFinal false constant null +MODIFIERS @73:7 +TOKEN @73:7 +PRIMITIVE_TYPE @73:14 : int +TOKEN @73:14 +IDENTIFIER @73:18 id depth Deep.depth [v static package] : int : int +TOKEN @73:18 +TOKEN @73:24 +INT_LITERAL @73:26 : int = 2 +TOKEN @73:26 +TOKEN @73:27 +TOKEN @74:5 +TOKEN @75:3 +VARIABLE @77:3 var Imports.constant [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Imports flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @77:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @77:3 +IDENTIFIER @77:10 id constant Imports.constant [v package] : java.lang.String : java.lang.String +TOKEN @77:10 +TOKEN @77:19 +PLUS @77:21 : java.lang.String +PLUS @77:21 : java.lang.String +MEMBER_SELECT @77:21 : java.lang.String = c +IDENTIFIER @77:21 id Holder Imports.Holder [t static package] : Imports$Holder : Imports$Holder +TOKEN @77:21 +TOKEN @77:27 +IDENTIFIER @77:28 id CONSTANT Holder.CONSTANT [v static final package] : java.lang.String : java.lang.String = c +TOKEN @77:28 +TOKEN @77:37 +MEMBER_SELECT @77:39 : int +MEMBER_SELECT @77:39 : Imports$Holder$Deep +IDENTIFIER @77:39 id Holder Imports.Holder [t static package] : Imports$Holder : Imports$Holder +TOKEN @77:39 +TOKEN @77:45 +IDENTIFIER @77:46 id Deep Holder.Deep [t static package] : Imports$Holder$Deep : Imports$Holder$Deep +TOKEN @77:46 +TOKEN @77:50 +IDENTIFIER @77:51 id depth Deep.depth [v static package] : int : int +TOKEN @77:51 +TOKEN @77:57 +MEMBER_SELECT @77:59 : int +MEMBER_SELECT @77:59 : Imports$Holder$Deep +MEMBER_SELECT @77:59 : Imports$Holder +IDENTIFIER @77:59 id Imports .Imports [t package] : Imports : Imports +TOKEN @77:59 +TOKEN @77:66 +IDENTIFIER @77:67 id Holder Imports.Holder [t static package] : Imports$Holder : Imports$Holder +TOKEN @77:67 +TOKEN @77:73 +IDENTIFIER @77:74 id Deep Holder.Deep [t static package] : Imports$Holder$Deep : Imports$Holder$Deep +TOKEN @77:74 +TOKEN @77:78 +IDENTIFIER @77:79 id depth Deep.depth [v static package] : int : int +TOKEN @77:79 +TOKEN @77:84 +TOKEN @78:1 +TOKEN @79:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Imports.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Imports.java new file mode 100644 index 00000000000..2d7da0efc2a --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Imports.java @@ -0,0 +1,78 @@ +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; +import java.util.*; +import static java.lang.Math.PI; +import static java.lang.Math.abs; +import static java.lang.Integer.MAX_VALUE; +import static java.util.concurrent.TimeUnit.SECONDS; +import static java.util.Collections.*; +import static java.util.Map.entry; + +class Imports implements Comparable { + + double circle = 2 * PI; + int maximum = MAX_VALUE; + TimeUnit unit = SECONDS; + Entry pair = entry("a", 1); + Map.Entry qualifiedPair = Map.entry("b", 2); + java.util.Map.Entry fullyQualified = pair; + List sorted = emptyList(); + Set fromStar = new HashSet<>(); + Optional optional = Optional.empty(); + + int absolute(int value) { + return abs(value) + Math.abs(-value); + } + + void entries(Map> map) { + for (Entry> entry : map.entrySet()) { + entry.getKey().length(); + entry.getValue().size(); + } + for (Map.Entry> entry : new HashMap<>(map).entrySet()) { + entry.setValue(unmodifiableList(entry.getValue())); + } + } + + @Override + public int compareTo(Imports other) { + return Integer.compare(maximum, other.maximum); + } + + interface Greeter { + default String greet() { + return "hello"; + } + } + + interface Polite extends Greeter { + @Override + default String greet() { + return "please " + Greeter.super.greet(); + } + } + + class Child extends Imports implements Polite { + @Override + public String greet() { + return Polite.super.greet() + Imports.this.maximum + Child.super.toString(); + } + + int parentMaximum() { + return super.maximum + Imports.this.circle > 0 ? 1 : 0; + } + } + + static class Holder { + static final String CONSTANT = "c"; + + static class Deep { + static int depth = 2; + } + } + + String constant = Holder.CONSTANT + Holder.Deep.depth + Imports.Holder.Deep.depth; +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Imports.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Imports.textproto.gz new file mode 100644 index 00000000000..eac27e52181 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Imports.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Inheritance.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Inheritance.expected.txt new file mode 100644 index 00000000000..97a3becf537 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Inheritance.expected.txt @@ -0,0 +1,1095 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id io unknown : ? +TOKEN @1:13 +TOKEN @1:15 +IDENTIFIER @1:16 id Closeable unknown : ? +TOKEN @1:16 +TOKEN @1:25 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id io unknown : ? +TOKEN @2:13 +TOKEN @2:15 +IDENTIFIER @2:16 id IOException unknown : ? +TOKEN @2:16 +TOKEN @2:27 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id util unknown : ? +TOKEN @3:13 +TOKEN @3:17 +IDENTIFIER @3:18 id AbstractList unknown : ? +TOKEN @3:18 +TOKEN @3:30 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id util unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id Comparator unknown : ? +TOKEN @4:18 +TOKEN @4:28 +IMPORT @5:1 +TOKEN @5:1 +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +IDENTIFIER @5:8 id java unknown : ? +TOKEN @5:8 +TOKEN @5:12 +IDENTIFIER @5:13 id util unknown : ? +TOKEN @5:13 +TOKEN @5:17 +IDENTIFIER @5:18 id Iterator unknown : ? +TOKEN @5:18 +TOKEN @5:26 +IMPORT @6:1 +TOKEN @6:1 +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +IDENTIFIER @6:8 id java unknown : ? +TOKEN @6:8 +TOKEN @6:12 +IDENTIFIER @6:13 id util unknown : ? +TOKEN @6:13 +TOKEN @6:17 +IDENTIFIER @6:18 id List unknown : ? +TOKEN @6:18 +TOKEN @6:22 +IMPORT @7:1 +TOKEN @7:1 +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +IDENTIFIER @7:8 id java unknown : ? +TOKEN @7:8 +TOKEN @7:12 +IDENTIFIER @7:13 id util unknown : ? +TOKEN @7:13 +TOKEN @7:17 +IDENTIFIER @7:18 id function unknown : ? +TOKEN @7:18 +TOKEN @7:26 +IDENTIFIER @7:27 id Function unknown : ? +TOKEN @7:27 +TOKEN @7:35 +CLASS @9:1 class .Inheritance [t package] : Inheritance super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Inheritance flags [package] members [, Animal, Base, Dog, Mapper, Names, Puppy, use] lookupToString 0 outermost Inheritance annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Inheritance +MODIFIERS +TOKEN @9:1 +IDENTIFIER @9:7 id Inheritance .Inheritance [t package] : Inheritance : Inheritance +TOKEN @9:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @9:19 +INTERFACE @11:3 class Inheritance.Animal [t static package interface] : Inheritance$Animal super java.lang.Object interfaces [java.lang.Comparable] + details declared true usages 4 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Inheritance flags [static, package, interface] members [compareTo, greet, name] lookupToString 0 outermost Inheritance annotation false subtypeOf [java.lang.Object, java.lang.Comparable] superTypes [java.lang.Comparable, java.lang.Object] numerical false wrapper false raw false declaring Animal +MODIFIERS +TOKEN @11:3 +IDENTIFIER @11:13 id Animal Inheritance.Animal [t static package interface] : Inheritance$Animal : Inheritance$Animal +TOKEN @11:13 +TYPE_PARAMETERS +TOKEN @11:20 +LIST @11:28 +PARAMETERIZED_TYPE @11:28 : java.lang.Comparable +IDENTIFIER @11:28 id Comparable java.lang.Comparable [t public interface] : java.lang.Comparable : java.lang.Comparable +TOKEN @11:28 +TYPE_ARGUMENTS @11:38 +TOKEN @11:38 +IDENTIFIER @11:39 id Animal Inheritance.Animal [t static package interface] : Inheritance$Animal : Inheritance$Animal +TOKEN @11:39 +TOKEN @11:45 +LIST +TOKEN @11:47 +METHOD @12:5 method Animal.name [m abstract public] : ? () returns java.lang.String throws [] sig Inheritance$Animal#name()Ljava/lang/String; overrides false + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Animal flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @12:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @12:5 +IDENTIFIER @12:12 id name Animal.name [m abstract public] : ? () returns java.lang.String throws [] sig Inheritance$Animal#name()Ljava/lang/String; : java.lang.String +TOKEN @12:12 +TOKEN @12:16 +TOKEN @12:17 +TOKEN @12:18 +METHOD @14:5 method Animal.greet [m public] : ? () returns java.lang.String throws [] sig Inheritance$Animal#greet()Ljava/lang/String; overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Animal flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @14:5 +TOKEN @14:5 +TYPE_PARAMETERS +IDENTIFIER @14:13 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @14:13 +IDENTIFIER @14:20 id greet Animal.greet [m public] : ? () returns java.lang.String throws [] sig Inheritance$Animal#greet()Ljava/lang/String; : java.lang.String +TOKEN @14:20 +TOKEN @14:25 +TOKEN @14:26 +BLOCK @14:28 +TOKEN @14:28 +RETURN_STATEMENT @15:7 +TOKEN @15:7 +PLUS @15:14 : java.lang.String +STRING_LITERAL @15:14 : java.lang.String = I am +TOKEN @15:14 +TOKEN @15:22 +METHOD_INVOCATION @15:24 call Animal.name [m abstract public] : ? () returns java.lang.String throws [] sig Inheritance$Animal#name()Ljava/lang/String; : java.lang.String + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Animal flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @15:24 id name Animal.name [m abstract public] : ? () returns java.lang.String throws [] sig Inheritance$Animal#name()Ljava/lang/String; : java.lang.String +TOKEN @15:24 +ARGUMENTS @15:28 +TOKEN @15:28 +TOKEN @15:29 +TOKEN @15:30 +TOKEN @16:5 +METHOD @18:5 method Animal.compareTo [m public] : ? @java.lang.Override (Inheritance$Animal) returns int throws [] sig Inheritance$Animal#compareTo(LInheritance$Animal;)I overrides true + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Animal flags [public] overridden [Comparable.compareTo[]] overridable true generic false default true synchronized false varargs false native false parameters [other] parameterMetadata [] +MODIFIERS @18:5 +ANNOTATION @18:5 : java.lang.Override +TOKEN @18:5 +IDENTIFIER @18:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @18:6 +ARGUMENTS +TOKEN @19:5 +TYPE_PARAMETERS +PRIMITIVE_TYPE @19:13 : int +TOKEN @19:13 +IDENTIFIER @19:17 id compareTo Animal.compareTo [m public] : ? @java.lang.Override (Inheritance$Animal) returns int throws [] sig Inheritance$Animal#compareTo(LInheritance$Animal;)I : int +TOKEN @19:17 +TOKEN @19:26 +VARIABLE @19:27 var compareTo.other [v package] : Inheritance$Animal + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Animal flags [package] local true parameter true effectivelyFinal true constant null owner compareTo Inheritance$Animal#compareTo(LInheritance$Animal;)I [public] returns int parameters 1 thrown 0 overridden 1 declared true usages 1 metadata 1 enclosing Animal type true kinds truefalsefalse other truefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @19:27 id Animal Inheritance.Animal [t static package interface] : Inheritance$Animal : Inheritance$Animal +TOKEN @19:27 +IDENTIFIER @19:34 id other compareTo.other [v package] : Inheritance$Animal : Inheritance$Animal +TOKEN @19:34 +TOKEN @19:39 +BLOCK @19:41 +TOKEN @19:41 +RETURN_STATEMENT @20:7 +TOKEN @20:7 +METHOD_INVOCATION @20:14 call String.compareTo [m public] : ? (java.lang.String) returns int throws [] sig java.lang.String#compareTo(Ljava/lang/String;)I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [Comparable.compareTo[]] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @20:14 : ? +METHOD_INVOCATION @20:14 call Animal.name [m abstract public] : ? () returns java.lang.String throws [] sig Inheritance$Animal#name()Ljava/lang/String; : java.lang.String + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Animal flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @20:14 id name Animal.name [m abstract public] : ? () returns java.lang.String throws [] sig Inheritance$Animal#name()Ljava/lang/String; : java.lang.String +TOKEN @20:14 +ARGUMENTS @20:18 +TOKEN @20:18 +TOKEN @20:19 +TOKEN @20:20 +IDENTIFIER @20:21 id compareTo String.compareTo [m public] : ? (java.lang.String) returns int throws [] sig java.lang.String#compareTo(Ljava/lang/String;)I : int +TOKEN @20:21 +ARGUMENTS @20:30 +TOKEN @20:30 +METHOD_INVOCATION @20:31 call Animal.name [m abstract public] : ? () returns java.lang.String throws [] sig Inheritance$Animal#name()Ljava/lang/String; : java.lang.String + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Animal flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @20:31 : ? +IDENTIFIER @20:31 id other compareTo.other [v package] : Inheritance$Animal : Inheritance$Animal +TOKEN @20:31 +TOKEN @20:36 +IDENTIFIER @20:37 id name Animal.name [m abstract public] : ? () returns java.lang.String throws [] sig Inheritance$Animal#name()Ljava/lang/String; : java.lang.String +TOKEN @20:37 +ARGUMENTS @20:41 +TOKEN @20:41 +TOKEN @20:42 +TOKEN @20:43 +TOKEN @20:44 +TOKEN @21:5 +TOKEN @22:3 +CLASS @24:3 class Inheritance.Base [t static abstract package] : Inheritance$Base super java.lang.Object interfaces [Inheritance$Animal, java.io.Closeable] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Inheritance flags [static, abstract, package] members [, close, equals, hashCode, legs, move, name] lookupToString 0 outermost Inheritance annotation false subtypeOf [java.lang.Object, java.lang.Comparable] superTypes [Inheritance$Animal, java.io.Closeable, java.lang.AutoCloseable, java.lang.Comparable, java.lang.Object] numerical false wrapper false raw false declaring Base +MODIFIERS @24:3 +TOKEN @24:3 +TOKEN @24:12 +TOKEN @24:19 +IDENTIFIER @24:25 id Base Inheritance.Base [t static abstract package] : Inheritance$Base : Inheritance$Base +TOKEN @24:25 +TYPE_PARAMETERS +TOKEN @24:30 +LIST @24:41 +IDENTIFIER @24:41 id Animal Inheritance.Animal [t static package interface] : Inheritance$Animal : Inheritance$Animal +TOKEN @24:41 +TOKEN @24:47 +IDENTIFIER @24:49 id Closeable java.io.Closeable [t public interface] : java.io.Closeable : java.io.Closeable +TOKEN @24:49 +LIST +TOKEN @24:59 +VARIABLE @25:5 var Base.legs [v protected] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Base flags [protected] local false parameter false effectivelyFinal false constant null +MODIFIERS @25:5 +TOKEN @25:5 +PRIMITIVE_TYPE @25:15 : int +TOKEN @25:15 +IDENTIFIER @25:19 id legs Base.legs [v protected] : int : int +TOKEN @25:19 +TOKEN @25:23 +METHOD @27:5 method Base.move [m abstract protected] : ? () returns void throws [] sig Inheritance$Base#move()V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Base flags [abstract, protected] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @27:5 +TOKEN @27:5 +TOKEN @27:15 +TYPE_PARAMETERS +PRIMITIVE_TYPE @27:24 : void +TOKEN @27:24 +IDENTIFIER @27:29 id move Base.move [m abstract protected] : ? () returns void throws [] sig Inheritance$Base#move()V : void +TOKEN @27:29 +TOKEN @27:33 +TOKEN @27:34 +TOKEN @27:35 +METHOD @29:5 method Base.name [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Inheritance$Base#name()Ljava/lang/String; overrides true + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Base flags [public] overridden [Animal.name[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @29:5 +ANNOTATION @29:5 : java.lang.Override +TOKEN @29:5 +IDENTIFIER @29:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @29:6 +ARGUMENTS +TOKEN @30:5 +TYPE_PARAMETERS +IDENTIFIER @30:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @30:12 +IDENTIFIER @30:19 id name Base.name [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Inheritance$Base#name()Ljava/lang/String; : java.lang.String +TOKEN @30:19 +TOKEN @30:23 +TOKEN @30:24 +BLOCK @30:26 +TOKEN @30:26 +RETURN_STATEMENT @31:7 +TOKEN @31:7 +METHOD_INVOCATION @31:14 call Class.getSimpleName [m public] : ? () returns java.lang.String throws [] sig java.lang.Class#getSimpleName()Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Class flags [public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @31:14 : ? +METHOD_INVOCATION @31:14 call Object.getClass [m final public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns java.lang.Class throws [] sig java.lang.Object#getClass()Ljava/lang/Class; : java.lang.Class + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [final, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @31:14 id getClass Object.getClass [m final public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns java.lang.Class throws [] sig java.lang.Object#getClass()Ljava/lang/Class; : java.lang.Class +TOKEN @31:14 +ARGUMENTS @31:22 +TOKEN @31:22 +TOKEN @31:23 +TOKEN @31:24 +IDENTIFIER @31:25 id getSimpleName Class.getSimpleName [m public] : ? () returns java.lang.String throws [] sig java.lang.Class#getSimpleName()Ljava/lang/String; : java.lang.String +TOKEN @31:25 +ARGUMENTS @31:38 +TOKEN @31:38 +TOKEN @31:39 +TOKEN @31:40 +TOKEN @32:5 +METHOD @34:5 method Base.close [m public] : ? @java.lang.Override () returns void throws [java.io.IOException] sig Inheritance$Base#close()V overrides true + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Base flags [public] overridden [Closeable.close[], AutoCloseable.close[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @34:5 +ANNOTATION @34:5 : java.lang.Override +TOKEN @34:5 +IDENTIFIER @34:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @34:6 +ARGUMENTS +TOKEN @35:5 +TYPE_PARAMETERS +PRIMITIVE_TYPE @35:12 : void +TOKEN @35:12 +IDENTIFIER @35:17 id close Base.close [m public] : ? @java.lang.Override () returns void throws [java.io.IOException] sig Inheritance$Base#close()V : void +TOKEN @35:17 +TOKEN @35:22 +TOKEN @35:23 +TOKEN @35:25 +LIST @35:32 +IDENTIFIER @35:32 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @35:32 +BLOCK @35:44 +TOKEN @35:44 +TOKEN @36:5 +METHOD @38:5 method Base.equals [m public] : ? @java.lang.Override (java.lang.Object) returns boolean throws [] sig Inheritance$Base#equals(Ljava/lang/Object;)Z overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Base flags [public] overridden [Object.equals[]] overridable true generic false default false synchronized false varargs false native false parameters [other] parameterMetadata [] +MODIFIERS @38:5 +ANNOTATION @38:5 : java.lang.Override +TOKEN @38:5 +IDENTIFIER @38:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @38:6 +ARGUMENTS +TOKEN @39:5 +TYPE_PARAMETERS +PRIMITIVE_TYPE @39:12 : boolean +TOKEN @39:12 +IDENTIFIER @39:20 id equals Base.equals [m public] : ? @java.lang.Override (java.lang.Object) returns boolean throws [] sig Inheritance$Base#equals(Ljava/lang/Object;)Z : boolean +TOKEN @39:20 +TOKEN @39:26 +VARIABLE @39:27 var equals.other [v package] : java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Base flags [package] local true parameter true effectivelyFinal true constant null owner equals Inheritance$Base#equals(Ljava/lang/Object;)Z [public] returns boolean parameters 1 thrown 0 overridden 1 declared true usages 0 metadata 1 enclosing Base type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @39:27 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @39:27 +IDENTIFIER @39:34 id other equals.other [v package] : java.lang.Object : java.lang.Object +TOKEN @39:34 +TOKEN @39:39 +BLOCK @39:41 +TOKEN @39:41 +RETURN_STATEMENT @40:7 +TOKEN @40:7 +METHOD_INVOCATION @40:14 call Object.equals [m public] : ? (java.lang.Object) returns boolean throws [] sig java.lang.Object#equals(Ljava/lang/Object;)Z : boolean + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @40:14 : ? +IDENTIFIER @40:14 id super Base.super [v final] : java.lang.Object : java.lang.Object +TOKEN @40:14 +TOKEN @40:19 +IDENTIFIER @40:20 id equals Object.equals [m public] : ? (java.lang.Object) returns boolean throws [] sig java.lang.Object#equals(Ljava/lang/Object;)Z : boolean +TOKEN @40:20 +ARGUMENTS @40:26 +TOKEN @40:26 +IDENTIFIER @40:27 id other equals.other [v package] : java.lang.Object : java.lang.Object +TOKEN @40:27 +TOKEN @40:32 +TOKEN @40:33 +TOKEN @41:5 +METHOD @43:5 method Base.hashCode [m public] : ? @java.lang.Override () returns int throws [] sig Inheritance$Base#hashCode()I overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Base flags [public] overridden [Object.hashCode[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @43:5 +ANNOTATION @43:5 : java.lang.Override +TOKEN @43:5 +IDENTIFIER @43:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @43:6 +ARGUMENTS +TOKEN @44:5 +TYPE_PARAMETERS +PRIMITIVE_TYPE @44:12 : int +TOKEN @44:12 +IDENTIFIER @44:16 id hashCode Base.hashCode [m public] : ? @java.lang.Override () returns int throws [] sig Inheritance$Base#hashCode()I : int +TOKEN @44:16 +TOKEN @44:24 +TOKEN @44:25 +BLOCK @44:27 +TOKEN @44:27 +RETURN_STATEMENT @45:7 +TOKEN @45:7 +IDENTIFIER @45:14 id legs Base.legs [v protected] : int : int +TOKEN @45:14 +TOKEN @45:18 +TOKEN @46:5 +TOKEN @47:3 +CLASS @49:3 class Inheritance.Dog [t static package] : Inheritance$Dog super Inheritance$Base interfaces [] + details declared true usages 2 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Inheritance flags [static, package] members [, greet, move, toString] lookupToString 1 outermost Inheritance annotation false subtypeOf [java.lang.Object, java.lang.Comparable] superTypes [Inheritance$Animal, Inheritance$Base, java.io.Closeable, java.lang.AutoCloseable, java.lang.Comparable, java.lang.Object] numerical false wrapper false raw false declaring Dog +MODIFIERS @49:3 +TOKEN @49:3 +TOKEN @49:10 +IDENTIFIER @49:16 id Dog Inheritance.Dog [t static package] : Inheritance$Dog : Inheritance$Dog +TOKEN @49:16 +TYPE_PARAMETERS +TOKEN @49:20 +IDENTIFIER @49:28 id Base Inheritance.Base [t static abstract package] : Inheritance$Base : Inheritance$Base +TOKEN @49:28 +LIST +LIST +TOKEN @49:33 +METHOD @50:5 method Dog.move [m protected] : ? @java.lang.Override () returns void throws [] sig Inheritance$Dog#move()V overrides true + details declared true usages 2 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Dog flags [protected] overridden [Base.move[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @50:5 +ANNOTATION @50:5 : java.lang.Override +TOKEN @50:5 +IDENTIFIER @50:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @50:6 +ARGUMENTS +TOKEN @51:5 +TYPE_PARAMETERS +PRIMITIVE_TYPE @51:15 : void +TOKEN @51:15 +IDENTIFIER @51:20 id move Dog.move [m protected] : ? @java.lang.Override () returns void throws [] sig Inheritance$Dog#move()V : void +TOKEN @51:20 +TOKEN @51:24 +TOKEN @51:25 +BLOCK @51:27 +TOKEN @51:27 +EXPRESSION_STATEMENT @52:7 +ASSIGNMENT @52:7 : int +IDENTIFIER @52:7 id legs Base.legs [v protected] : int : int +TOKEN @52:7 +TOKEN @52:12 +INT_LITERAL @52:14 : int = 4 +TOKEN @52:14 +TOKEN @52:15 +TOKEN @53:5 +METHOD @55:5 method Dog.greet [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Inheritance$Dog#greet()Ljava/lang/String; overrides true + details declared true usages 2 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Dog flags [public] overridden [Animal.greet[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @55:5 +ANNOTATION @55:5 : java.lang.Override +TOKEN @55:5 +IDENTIFIER @55:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @55:6 +ARGUMENTS +TOKEN @56:5 +TYPE_PARAMETERS +IDENTIFIER @56:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @56:12 +IDENTIFIER @56:19 id greet Dog.greet [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Inheritance$Dog#greet()Ljava/lang/String; : java.lang.String +TOKEN @56:19 +TOKEN @56:24 +TOKEN @56:25 +BLOCK @56:27 +TOKEN @56:27 +RETURN_STATEMENT @57:7 +TOKEN @57:7 +PLUS @57:14 : java.lang.String +STRING_LITERAL @57:14 : java.lang.String = Woof +TOKEN @57:14 +TOKEN @57:22 +METHOD_INVOCATION @57:24 call Animal.greet [m public] : ? () returns java.lang.String throws [] sig Inheritance$Animal#greet()Ljava/lang/String; : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Animal flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @57:24 : ? +IDENTIFIER @57:24 id super Dog.super [v final] : Inheritance$Base : Inheritance$Base +TOKEN @57:24 +TOKEN @57:29 +IDENTIFIER @57:30 id greet Animal.greet [m public] : ? () returns java.lang.String throws [] sig Inheritance$Animal#greet()Ljava/lang/String; : java.lang.String +TOKEN @57:30 +ARGUMENTS @57:35 +TOKEN @57:35 +TOKEN @57:36 +TOKEN @57:37 +TOKEN @58:5 +METHOD @60:5 method Dog.toString [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Inheritance$Dog#toString()Ljava/lang/String; overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Dog flags [public] overridden [Object.toString[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @60:5 +ANNOTATION @60:5 : java.lang.Override +TOKEN @60:5 +IDENTIFIER @60:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @60:6 +ARGUMENTS +TOKEN @61:5 +TYPE_PARAMETERS +IDENTIFIER @61:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @61:12 +IDENTIFIER @61:19 id toString Dog.toString [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Inheritance$Dog#toString()Ljava/lang/String; : java.lang.String +TOKEN @61:19 +TOKEN @61:27 +TOKEN @61:28 +BLOCK @61:30 +TOKEN @61:30 +RETURN_STATEMENT @62:7 +TOKEN @62:7 +METHOD_INVOCATION @62:14 call Base.name [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Inheritance$Base#name()Ljava/lang/String; : java.lang.String + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Base flags [public] overridden [Animal.name[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @62:14 id name Base.name [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Inheritance$Base#name()Ljava/lang/String; : java.lang.String +TOKEN @62:14 +ARGUMENTS @62:18 +TOKEN @62:18 +TOKEN @62:19 +TOKEN @62:20 +TOKEN @63:5 +TOKEN @64:3 +CLASS @66:3 class Inheritance.Puppy [t static final package] : Inheritance$Puppy super Inheritance$Dog interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Inheritance flags [static, final, package] members [, move] lookupToString 0 outermost Inheritance annotation false subtypeOf [java.lang.Object, java.lang.Comparable] superTypes [Inheritance$Animal, Inheritance$Base, Inheritance$Dog, java.io.Closeable, java.lang.AutoCloseable, java.lang.Comparable, java.lang.Object] numerical false wrapper false raw false declaring Puppy +MODIFIERS @66:3 +TOKEN @66:3 +TOKEN @66:10 +TOKEN @66:16 +IDENTIFIER @66:22 id Puppy Inheritance.Puppy [t static final package] : Inheritance$Puppy : Inheritance$Puppy +TOKEN @66:22 +TYPE_PARAMETERS +TOKEN @66:28 +IDENTIFIER @66:36 id Dog Inheritance.Dog [t static package] : Inheritance$Dog : Inheritance$Dog +TOKEN @66:36 +LIST +LIST +TOKEN @66:40 +METHOD @67:5 method Puppy.move [m protected] : ? @java.lang.Override () returns void throws [] sig Inheritance$Puppy#move()V overrides true + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Puppy flags [protected] overridden [Dog.move[java.lang.Override tree true values 0 annotated true], Base.move[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @67:5 +ANNOTATION @67:5 : java.lang.Override +TOKEN @67:5 +IDENTIFIER @67:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @67:6 +ARGUMENTS +TOKEN @68:5 +TYPE_PARAMETERS +PRIMITIVE_TYPE @68:15 : void +TOKEN @68:15 +IDENTIFIER @68:20 id move Puppy.move [m protected] : ? @java.lang.Override () returns void throws [] sig Inheritance$Puppy#move()V : void +TOKEN @68:20 +TOKEN @68:24 +TOKEN @68:25 +BLOCK @68:27 +TOKEN @68:27 +EXPRESSION_STATEMENT @69:7 +METHOD_INVOCATION @69:7 call Dog.move [m protected] : ? @java.lang.Override () returns void throws [] sig Inheritance$Dog#move()V : void + details declared true usages 2 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Dog flags [protected] overridden [Base.move[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @69:7 : ? +IDENTIFIER @69:7 id super Puppy.super [v final] : Inheritance$Dog : Inheritance$Dog +TOKEN @69:7 +TOKEN @69:12 +IDENTIFIER @69:13 id move Dog.move [m protected] : ? @java.lang.Override () returns void throws [] sig Inheritance$Dog#move()V : void +TOKEN @69:13 +ARGUMENTS @69:17 +TOKEN @69:17 +TOKEN @69:18 +TOKEN @69:19 +TOKEN @70:5 +TOKEN @71:3 +CLASS @73:3 class Inheritance.Names [t static package] : Inheritance$Names super java.util.AbstractList interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Inheritance flags [static, package] members [, get, iterator, size] lookupToString 0 outermost Inheritance annotation false subtypeOf [java.lang.Object, java.util.Collection] superTypes [java.lang.Iterable, java.lang.Object, java.util.AbstractCollection, java.util.AbstractList, java.util.Collection, java.util.List, java.util.SequencedCollection] numerical false wrapper false raw false declaring Names +MODIFIERS @73:3 +TOKEN @73:3 +TOKEN @73:10 +IDENTIFIER @73:16 id Names Inheritance.Names [t static package] : Inheritance$Names : Inheritance$Names +TOKEN @73:16 +TYPE_PARAMETERS +TOKEN @73:22 +PARAMETERIZED_TYPE @73:30 : java.util.AbstractList +IDENTIFIER @73:30 id AbstractList java.util.AbstractList [t abstract public] : java.util.AbstractList : java.util.AbstractList +TOKEN @73:30 +TYPE_ARGUMENTS @73:42 +TOKEN @73:42 +IDENTIFIER @73:43 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @73:43 +TOKEN @73:49 +LIST +LIST +TOKEN @73:51 +METHOD @74:5 method Names.get [m public] : ? @java.lang.Override (int) returns java.lang.String throws [] sig Inheritance$Names#get(I)Ljava/lang/String; overrides true + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Names flags [public] overridden [AbstractList.get[], List.get[]] overridable true generic false default false synchronized false varargs false native false parameters [index] parameterMetadata [] +MODIFIERS @74:5 +ANNOTATION @74:5 : java.lang.Override +TOKEN @74:5 +IDENTIFIER @74:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @74:6 +ARGUMENTS +TOKEN @75:5 +TYPE_PARAMETERS +IDENTIFIER @75:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @75:12 +IDENTIFIER @75:19 id get Names.get [m public] : ? @java.lang.Override (int) returns java.lang.String throws [] sig Inheritance$Names#get(I)Ljava/lang/String; : java.lang.String +TOKEN @75:19 +TOKEN @75:22 +VARIABLE @75:23 var get.index [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Names flags [package] local true parameter true effectivelyFinal true constant null owner get Inheritance$Names#get(I)Ljava/lang/String; [public] returns java.lang.String parameters 1 thrown 0 overridden 2 declared true usages 1 metadata 1 enclosing Names type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @75:23 : int +TOKEN @75:23 +IDENTIFIER @75:27 id index get.index [v package] : int : int +TOKEN @75:27 +TOKEN @75:32 +BLOCK @75:34 +TOKEN @75:34 +RETURN_STATEMENT @76:7 +TOKEN @76:7 +PLUS @76:14 : java.lang.String +STRING_LITERAL @76:14 : java.lang.String = n +TOKEN @76:14 +TOKEN @76:18 +IDENTIFIER @76:20 id index get.index [v package] : int : int +TOKEN @76:20 +TOKEN @76:25 +TOKEN @77:5 +METHOD @79:5 method Names.size [m public] : ? @java.lang.Override () returns int throws [] sig Inheritance$Names#size()I overrides true + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Names flags [public] overridden [AbstractCollection.size[], Collection.size[], List.size[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @79:5 +ANNOTATION @79:5 : java.lang.Override +TOKEN @79:5 +IDENTIFIER @79:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @79:6 +ARGUMENTS +TOKEN @80:5 +TYPE_PARAMETERS +PRIMITIVE_TYPE @80:12 : int +TOKEN @80:12 +IDENTIFIER @80:16 id size Names.size [m public] : ? @java.lang.Override () returns int throws [] sig Inheritance$Names#size()I : int +TOKEN @80:16 +TOKEN @80:20 +TOKEN @80:21 +BLOCK @80:23 +TOKEN @80:23 +RETURN_STATEMENT @81:7 +TOKEN @81:7 +INT_LITERAL @81:14 : int = 3 +TOKEN @81:14 +TOKEN @81:15 +TOKEN @82:5 +METHOD @84:5 method Names.iterator [m public] : ? @java.lang.Override () returns java.util.Iterator throws [] sig Inheritance$Names#iterator()Ljava/util/Iterator; overrides true + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [[]] enclosing Names flags [public] overridden [AbstractList.iterator[], AbstractCollection.iterator[], Collection.iterator[], Iterable.iterator[], List.iterator[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS @84:5 +ANNOTATION @84:5 : java.lang.Override +TOKEN @84:5 +IDENTIFIER @84:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @84:6 +ARGUMENTS +TOKEN @85:5 +TYPE_PARAMETERS +PARAMETERIZED_TYPE @85:12 : java.util.Iterator +IDENTIFIER @85:12 id Iterator java.util.Iterator [t public interface] : java.util.Iterator : java.util.Iterator +TOKEN @85:12 +TYPE_ARGUMENTS @85:20 +TOKEN @85:20 +IDENTIFIER @85:21 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @85:21 +TOKEN @85:27 +IDENTIFIER @85:29 id iterator Names.iterator [m public] : ? @java.lang.Override () returns java.util.Iterator throws [] sig Inheritance$Names#iterator()Ljava/util/Iterator; : java.util.Iterator +TOKEN @85:29 +TOKEN @85:37 +TOKEN @85:38 +BLOCK @85:40 +TOKEN @85:40 +RETURN_STATEMENT @86:7 +TOKEN @86:7 +METHOD_INVOCATION @86:14 call AbstractList.iterator [m public] : ? () returns java.util.Iterator throws [] sig java.util.AbstractList#iterator()Ljava/util/Iterator; : java.util.Iterator + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing AbstractList flags [public] overridden [AbstractCollection.iterator[], Collection.iterator[], Iterable.iterator[], List.iterator[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @86:14 : ? +IDENTIFIER @86:14 id super Names.super [v final] : java.util.AbstractList : java.util.AbstractList +TOKEN @86:14 +TOKEN @86:19 +IDENTIFIER @86:20 id iterator AbstractList.iterator [m public] : ? () returns java.util.Iterator throws [] sig java.util.AbstractList#iterator()Ljava/util/Iterator; : java.util.Iterator +TOKEN @86:20 +ARGUMENTS @86:28 +TOKEN @86:28 +TOKEN @86:29 +TOKEN @86:30 +TOKEN @87:5 +TOKEN @88:3 +CLASS @90:3 class Inheritance.Mapper [t static package] : Inheritance$Mapper super java.lang.Object interfaces [java.util.function.Function, java.util.Comparator] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Inheritance flags [static, package] members [, apply, compare] lookupToString 0 outermost Inheritance annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object, java.util.Comparator, java.util.function.Function] numerical false wrapper false raw true declaring Mapper +MODIFIERS @90:3 +TOKEN @90:3 +TOKEN @90:10 +IDENTIFIER @90:16 id Mapper Inheritance.Mapper [t static package] : Inheritance$Mapper : Inheritance$Mapper +TOKEN @90:16 +TYPE_PARAMETERS @90:22 +TOKEN @90:22 +TYPE_PARAMETER @90:23 +IDENTIFIER @90:23 id T Mapper.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @90:23 +TOKEN @90:24 +TOKEN @90:26 +LIST @90:37 +PARAMETERIZED_TYPE @90:37 : java.util.function.Function +IDENTIFIER @90:37 id Function java.util.function.Function [t public interface] : java.util.function.Function @java.lang.FunctionalInterface : java.util.function.Function +TOKEN @90:37 +TYPE_ARGUMENTS @90:45 +TOKEN @90:45 +IDENTIFIER @90:46 id T Mapper.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @90:46 +TOKEN @90:47 +IDENTIFIER @90:49 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @90:49 +TOKEN @90:55 +TOKEN @90:56 +PARAMETERIZED_TYPE @90:58 : java.util.Comparator +IDENTIFIER @90:58 id Comparator java.util.Comparator [t public interface] : java.util.Comparator @java.lang.FunctionalInterface : java.util.Comparator +TOKEN @90:58 +TYPE_ARGUMENTS @90:68 +TOKEN @90:68 +IDENTIFIER @90:69 id T Mapper.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @90:69 +TOKEN @90:70 +LIST +TOKEN @90:72 +METHOD @91:5 method Mapper.apply [m public] : ? @java.lang.Override (T erasure java.lang.Object) returns java.lang.String throws [] sig Inheritance$Mapper#apply(Ljava/lang/Object;)Ljava/lang/String; overrides true + details declared true usages 3 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Mapper flags [public] overridden [Function.apply[]] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MODIFIERS @91:5 +ANNOTATION @91:5 : java.lang.Override +TOKEN @91:5 +IDENTIFIER @91:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @91:6 +ARGUMENTS +TOKEN @92:5 +TYPE_PARAMETERS +IDENTIFIER @92:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @92:12 +IDENTIFIER @92:19 id apply Mapper.apply [m public] : ? @java.lang.Override (T erasure java.lang.Object) returns java.lang.String throws [] sig Inheritance$Mapper#apply(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String +TOKEN @92:19 +TOKEN @92:24 +VARIABLE @92:25 var apply.value [v package] : T erasure java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Mapper flags [package] local true parameter true effectivelyFinal true constant null owner apply Inheritance$Mapper#apply(Ljava/lang/Object;)Ljava/lang/String; [public] returns java.lang.String parameters 1 thrown 0 overridden 1 declared true usages 3 metadata 1 enclosing Mapper type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @92:25 id T Mapper.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @92:25 +IDENTIFIER @92:27 id value apply.value [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @92:27 +TOKEN @92:32 +BLOCK @92:34 +TOKEN @92:34 +RETURN_STATEMENT @93:7 +TOKEN @93:7 +METHOD_INVOCATION @93:14 call String.valueOf [m static public] : ? (java.lang.Object) returns java.lang.String throws [] sig java.lang.String#valueOf(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @93:14 : ? +IDENTIFIER @93:14 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @93:14 +TOKEN @93:20 +IDENTIFIER @93:21 id valueOf String.valueOf [m static public] : ? (java.lang.Object) returns java.lang.String throws [] sig java.lang.String#valueOf(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String +TOKEN @93:21 +ARGUMENTS @93:28 +TOKEN @93:28 +IDENTIFIER @93:29 id value apply.value [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @93:29 +TOKEN @93:34 +TOKEN @93:35 +TOKEN @94:5 +METHOD @96:5 method Mapper.compare [m public] : ? @java.lang.Override (T erasure java.lang.Object,T erasure java.lang.Object) returns int throws [] sig Inheritance$Mapper#compare(Ljava/lang/Object;Ljava/lang/Object;)I overrides true + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Mapper flags [public] overridden [Comparator.compare[]] overridable true generic false default false synchronized false varargs false native false parameters [left, right] parameterMetadata [] +MODIFIERS @96:5 +ANNOTATION @96:5 : java.lang.Override +TOKEN @96:5 +IDENTIFIER @96:6 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @96:6 +ARGUMENTS +TOKEN @97:5 +TYPE_PARAMETERS +PRIMITIVE_TYPE @97:12 : int +TOKEN @97:12 +IDENTIFIER @97:16 id compare Mapper.compare [m public] : ? @java.lang.Override (T erasure java.lang.Object,T erasure java.lang.Object) returns int throws [] sig Inheritance$Mapper#compare(Ljava/lang/Object;Ljava/lang/Object;)I : int +TOKEN @97:16 +TOKEN @97:23 +VARIABLE @97:24 var compare.left [v package] : T erasure java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Mapper flags [package] local true parameter true effectivelyFinal true constant null owner compare Inheritance$Mapper#compare(Ljava/lang/Object;Ljava/lang/Object;)I [public] returns int parameters 2 thrown 0 overridden 1 declared true usages 1 metadata 1 enclosing Mapper type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @97:24 id T Mapper.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @97:24 +IDENTIFIER @97:26 id left compare.left [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @97:26 +TOKEN @97:30 +VARIABLE @97:32 var compare.right [v package] : T erasure java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Mapper flags [package] local true parameter true effectivelyFinal true constant null owner compare Inheritance$Mapper#compare(Ljava/lang/Object;Ljava/lang/Object;)I [public] returns int parameters 2 thrown 0 overridden 1 declared true usages 1 metadata 1 enclosing Mapper type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @97:32 id T Mapper.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @97:32 +IDENTIFIER @97:34 id right compare.right [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @97:34 +TOKEN @97:39 +BLOCK @97:41 +TOKEN @97:41 +RETURN_STATEMENT @98:7 +TOKEN @98:7 +METHOD_INVOCATION @98:14 call String.compareTo [m public] : ? (java.lang.String) returns int throws [] sig java.lang.String#compareTo(Ljava/lang/String;)I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [Comparable.compareTo[]] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @98:14 : ? +METHOD_INVOCATION @98:14 call Mapper.apply [m public] : ? @java.lang.Override (T erasure java.lang.Object) returns java.lang.String throws [] sig Inheritance$Mapper#apply(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String + details declared true usages 3 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Mapper flags [public] overridden [Function.apply[]] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @98:14 id apply Mapper.apply [m public] : ? @java.lang.Override (T erasure java.lang.Object) returns java.lang.String throws [] sig Inheritance$Mapper#apply(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String +TOKEN @98:14 +ARGUMENTS @98:19 +TOKEN @98:19 +IDENTIFIER @98:20 id left compare.left [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @98:20 +TOKEN @98:24 +TOKEN @98:25 +IDENTIFIER @98:26 id compareTo String.compareTo [m public] : ? (java.lang.String) returns int throws [] sig java.lang.String#compareTo(Ljava/lang/String;)I : int +TOKEN @98:26 +ARGUMENTS @98:35 +TOKEN @98:35 +METHOD_INVOCATION @98:36 call Mapper.apply [m public] : ? @java.lang.Override (T erasure java.lang.Object) returns java.lang.String throws [] sig Inheritance$Mapper#apply(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String + details declared true usages 3 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Mapper flags [public] overridden [Function.apply[]] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @98:36 id apply Mapper.apply [m public] : ? @java.lang.Override (T erasure java.lang.Object) returns java.lang.String throws [] sig Inheritance$Mapper#apply(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String +TOKEN @98:36 +ARGUMENTS @98:41 +TOKEN @98:41 +IDENTIFIER @98:42 id right compare.right [v package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @98:42 +TOKEN @98:47 +TOKEN @98:48 +TOKEN @98:49 +TOKEN @99:5 +TOKEN @100:3 +METHOD @102:3 method Inheritance.use [m package] : ? (Inheritance$Dog,Inheritance$Puppy,Inheritance$Names,Inheritance$Mapper) returns void throws [java.io.IOException] sig Inheritance#use(LInheritance$Dog;LInheritance$Puppy;LInheritance$Names;LInheritance$Mapper;)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Inheritance flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [dog, puppy, names, mapper] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @102:3 : void +TOKEN @102:3 +IDENTIFIER @102:8 id use Inheritance.use [m package] : ? (Inheritance$Dog,Inheritance$Puppy,Inheritance$Names,Inheritance$Mapper) returns void throws [java.io.IOException] sig Inheritance#use(LInheritance$Dog;LInheritance$Puppy;LInheritance$Names;LInheritance$Mapper;)V : void +TOKEN @102:8 +TOKEN @102:11 +VARIABLE @102:12 var use.dog [v package] : Inheritance$Dog + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Inheritance flags [package] local true parameter true effectivelyFinal true constant null owner use Inheritance#use(LInheritance$Dog;LInheritance$Puppy;LInheritance$Names;LInheritance$Mapper;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Inheritance type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @102:12 id Dog Inheritance.Dog [t static package] : Inheritance$Dog : Inheritance$Dog +TOKEN @102:12 +IDENTIFIER @102:16 id dog use.dog [v package] : Inheritance$Dog : Inheritance$Dog +TOKEN @102:16 +TOKEN @102:19 +VARIABLE @102:21 var use.puppy [v package] : Inheritance$Puppy + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Inheritance flags [package] local true parameter true effectivelyFinal true constant null owner use Inheritance#use(LInheritance$Dog;LInheritance$Puppy;LInheritance$Names;LInheritance$Mapper;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Inheritance type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @102:21 id Puppy Inheritance.Puppy [t static final package] : Inheritance$Puppy : Inheritance$Puppy +TOKEN @102:21 +IDENTIFIER @102:27 id puppy use.puppy [v package] : Inheritance$Puppy : Inheritance$Puppy +TOKEN @102:27 +TOKEN @102:32 +VARIABLE @102:34 var use.names [v package] : Inheritance$Names + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Inheritance flags [package] local true parameter true effectivelyFinal true constant null owner use Inheritance#use(LInheritance$Dog;LInheritance$Puppy;LInheritance$Names;LInheritance$Mapper;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Inheritance type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @102:34 id Names Inheritance.Names [t static package] : Inheritance$Names : Inheritance$Names +TOKEN @102:34 +IDENTIFIER @102:40 id names use.names [v package] : Inheritance$Names : Inheritance$Names +TOKEN @102:40 +TOKEN @102:45 +VARIABLE @102:47 var use.mapper [v package] : Inheritance$Mapper + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Inheritance flags [package] local true parameter true effectivelyFinal true constant null owner use Inheritance#use(LInheritance$Dog;LInheritance$Puppy;LInheritance$Names;LInheritance$Mapper;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Inheritance type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @102:47 : Inheritance$Mapper +IDENTIFIER @102:47 id Mapper Inheritance.Mapper [t static package] : Inheritance$Mapper : Inheritance$Mapper +TOKEN @102:47 +TYPE_ARGUMENTS @102:53 +TOKEN @102:53 +IDENTIFIER @102:54 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @102:54 +TOKEN @102:61 +IDENTIFIER @102:63 id mapper use.mapper [v package] : Inheritance$Mapper : Inheritance$Mapper +TOKEN @102:63 +TOKEN @102:69 +TOKEN @102:71 +LIST @102:78 +IDENTIFIER @102:78 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @102:78 +BLOCK @102:90 +TOKEN @102:90 +EXPRESSION_STATEMENT @103:5 +METHOD_INVOCATION @103:5 call Dog.move [m protected] : ? @java.lang.Override () returns void throws [] sig Inheritance$Dog#move()V : void + details declared true usages 2 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Dog flags [protected] overridden [Base.move[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @103:5 : ? +IDENTIFIER @103:5 id dog use.dog [v package] : Inheritance$Dog : Inheritance$Dog +TOKEN @103:5 +TOKEN @103:8 +IDENTIFIER @103:9 id move Dog.move [m protected] : ? @java.lang.Override () returns void throws [] sig Inheritance$Dog#move()V : void +TOKEN @103:9 +ARGUMENTS @103:13 +TOKEN @103:13 +TOKEN @103:14 +TOKEN @103:15 +EXPRESSION_STATEMENT @104:5 +METHOD_INVOCATION @104:5 call Puppy.move [m protected] : ? @java.lang.Override () returns void throws [] sig Inheritance$Puppy#move()V : void + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Puppy flags [protected] overridden [Dog.move[java.lang.Override tree true values 0 annotated true], Base.move[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @104:5 : ? +IDENTIFIER @104:5 id puppy use.puppy [v package] : Inheritance$Puppy : Inheritance$Puppy +TOKEN @104:5 +TOKEN @104:10 +IDENTIFIER @104:11 id move Puppy.move [m protected] : ? @java.lang.Override () returns void throws [] sig Inheritance$Puppy#move()V : void +TOKEN @104:11 +ARGUMENTS @104:15 +TOKEN @104:15 +TOKEN @104:16 +TOKEN @104:17 +EXPRESSION_STATEMENT @105:5 +METHOD_INVOCATION @105:5 call Dog.greet [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Inheritance$Dog#greet()Ljava/lang/String; : java.lang.String + details declared true usages 2 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Dog flags [public] overridden [Animal.greet[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @105:5 : ? +IDENTIFIER @105:5 id dog use.dog [v package] : Inheritance$Dog : Inheritance$Dog +TOKEN @105:5 +TOKEN @105:8 +IDENTIFIER @105:9 id greet Dog.greet [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Inheritance$Dog#greet()Ljava/lang/String; : java.lang.String +TOKEN @105:9 +ARGUMENTS @105:14 +TOKEN @105:14 +TOKEN @105:15 +TOKEN @105:16 +EXPRESSION_STATEMENT @106:5 +METHOD_INVOCATION @106:5 call Dog.greet [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Inheritance$Dog#greet()Ljava/lang/String; : java.lang.String + details declared true usages 2 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Dog flags [public] overridden [Animal.greet[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @106:5 : ? +IDENTIFIER @106:5 id puppy use.puppy [v package] : Inheritance$Puppy : Inheritance$Puppy +TOKEN @106:5 +TOKEN @106:10 +IDENTIFIER @106:11 id greet Dog.greet [m public] : ? @java.lang.Override () returns java.lang.String throws [] sig Inheritance$Dog#greet()Ljava/lang/String; : java.lang.String +TOKEN @106:11 +ARGUMENTS @106:16 +TOKEN @106:16 +TOKEN @106:17 +TOKEN @106:18 +EXPRESSION_STATEMENT @107:5 +METHOD_INVOCATION @107:5 call Base.close [m public] : ? @java.lang.Override () returns void throws [java.io.IOException] sig Inheritance$Base#close()V : void + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Base flags [public] overridden [Closeable.close[], AutoCloseable.close[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @107:5 : ? +IDENTIFIER @107:5 id dog use.dog [v package] : Inheritance$Dog : Inheritance$Dog +TOKEN @107:5 +TOKEN @107:8 +IDENTIFIER @107:9 id close Base.close [m public] : ? @java.lang.Override () returns void throws [java.io.IOException] sig Inheritance$Base#close()V : void +TOKEN @107:9 +ARGUMENTS @107:14 +TOKEN @107:14 +TOKEN @107:15 +TOKEN @107:16 +EXPRESSION_STATEMENT @108:5 +METHOD_INVOCATION @108:5 call Names.get [m public] : ? @java.lang.Override (int) returns java.lang.String throws [] sig Inheritance$Names#get(I)Ljava/lang/String; : java.lang.String + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Names flags [public] overridden [AbstractList.get[], List.get[]] overridable true generic false default false synchronized false varargs false native false parameters [index] parameterMetadata [] +MEMBER_SELECT @108:5 : ? +IDENTIFIER @108:5 id names use.names [v package] : Inheritance$Names : Inheritance$Names +TOKEN @108:5 +TOKEN @108:10 +IDENTIFIER @108:11 id get Names.get [m public] : ? @java.lang.Override (int) returns java.lang.String throws [] sig Inheritance$Names#get(I)Ljava/lang/String; : java.lang.String +TOKEN @108:11 +ARGUMENTS @108:14 +TOKEN @108:14 +INT_LITERAL @108:15 : int = 0 +TOKEN @108:15 +TOKEN @108:16 +TOKEN @108:17 +EXPRESSION_STATEMENT @109:5 +METHOD_INVOCATION @109:5 call Names.size [m public] : ? @java.lang.Override () returns int throws [] sig Inheritance$Names#size()I : int + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Names flags [public] overridden [AbstractCollection.size[], Collection.size[], List.size[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @109:5 : ? +IDENTIFIER @109:5 id names use.names [v package] : Inheritance$Names : Inheritance$Names +TOKEN @109:5 +TOKEN @109:10 +IDENTIFIER @109:11 id size Names.size [m public] : ? @java.lang.Override () returns int throws [] sig Inheritance$Names#size()I : int +TOKEN @109:11 +ARGUMENTS @109:15 +TOKEN @109:15 +TOKEN @109:16 +TOKEN @109:17 +EXPRESSION_STATEMENT @110:5 +METHOD_INVOCATION @110:5 call Iterator.next [m abstract public] : ? () returns java.lang.String throws [] sig java.util.Iterator#next()Ljava/lang/Object; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Iterator flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @110:5 : ? +METHOD_INVOCATION @110:5 call Names.iterator [m public] : ? @java.lang.Override () returns java.util.Iterator throws [] sig Inheritance$Names#iterator()Ljava/util/Iterator; : java.util.Iterator + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [[]] enclosing Names flags [public] overridden [AbstractList.iterator[], AbstractCollection.iterator[], Collection.iterator[], Iterable.iterator[], List.iterator[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MEMBER_SELECT @110:5 : ? +IDENTIFIER @110:5 id names use.names [v package] : Inheritance$Names : Inheritance$Names +TOKEN @110:5 +TOKEN @110:10 +IDENTIFIER @110:11 id iterator Names.iterator [m public] : ? @java.lang.Override () returns java.util.Iterator throws [] sig Inheritance$Names#iterator()Ljava/util/Iterator; : java.util.Iterator +TOKEN @110:11 +ARGUMENTS @110:19 +TOKEN @110:19 +TOKEN @110:20 +TOKEN @110:21 +IDENTIFIER @110:22 id next Iterator.next [m abstract public] : ? () returns java.lang.String throws [] sig java.util.Iterator#next()Ljava/lang/Object; : java.lang.String +TOKEN @110:22 +ARGUMENTS @110:26 +TOKEN @110:26 +TOKEN @110:27 +TOKEN @110:28 +EXPRESSION_STATEMENT @111:5 +METHOD_INVOCATION @111:5 call Mapper.apply [m public] : ? @java.lang.Override (java.lang.Integer) returns java.lang.String throws [] sig Inheritance$Mapper#apply(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String + details declared true usages 3 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Mapper flags [public] overridden [Function.apply[]] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MEMBER_SELECT @111:5 : ? +IDENTIFIER @111:5 id mapper use.mapper [v package] : Inheritance$Mapper : Inheritance$Mapper +TOKEN @111:5 +TOKEN @111:11 +IDENTIFIER @111:12 id apply Mapper.apply [m public] : ? @java.lang.Override (java.lang.Integer) returns java.lang.String throws [] sig Inheritance$Mapper#apply(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String +TOKEN @111:12 +ARGUMENTS @111:17 +TOKEN @111:17 +INT_LITERAL @111:18 : int = 1 +TOKEN @111:18 +TOKEN @111:19 +TOKEN @111:20 +EXPRESSION_STATEMENT @112:5 +METHOD_INVOCATION @112:5 call Mapper.compare [m public] : ? @java.lang.Override (java.lang.Integer,java.lang.Integer) returns int throws [] sig Inheritance$Mapper#compare(Ljava/lang/Object;Ljava/lang/Object;)I : int + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Mapper flags [public] overridden [Comparator.compare[]] overridable true generic false default false synchronized false varargs false native false parameters [left, right] parameterMetadata [] +MEMBER_SELECT @112:5 : ? +IDENTIFIER @112:5 id mapper use.mapper [v package] : Inheritance$Mapper : Inheritance$Mapper +TOKEN @112:5 +TOKEN @112:11 +IDENTIFIER @112:12 id compare Mapper.compare [m public] : ? @java.lang.Override (java.lang.Integer,java.lang.Integer) returns int throws [] sig Inheritance$Mapper#compare(Ljava/lang/Object;Ljava/lang/Object;)I : int +TOKEN @112:12 +ARGUMENTS @112:19 +TOKEN @112:19 +INT_LITERAL @112:20 : int = 1 +TOKEN @112:20 +TOKEN @112:21 +INT_LITERAL @112:23 : int = 2 +TOKEN @112:23 +TOKEN @112:24 +TOKEN @112:25 +EXPRESSION_STATEMENT @113:5 +METHOD_INVOCATION @113:5 call Comparator.reversed [m public] : ? () returns java.util.Comparator throws [] sig java.util.Comparator#reversed()Ljava/util/Comparator; : java.util.Comparator + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Comparator flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @113:5 : ? +IDENTIFIER @113:5 id mapper use.mapper [v package] : Inheritance$Mapper : Inheritance$Mapper +TOKEN @113:5 +TOKEN @113:11 +IDENTIFIER @113:12 id reversed Comparator.reversed [m public] : ? () returns java.util.Comparator throws [] sig java.util.Comparator#reversed()Ljava/util/Comparator; : java.util.Comparator +TOKEN @113:12 +ARGUMENTS @113:20 +TOKEN @113:20 +TOKEN @113:21 +TOKEN @113:22 +VARIABLE @114:5 var use.view [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Inheritance flags [package] local true parameter false effectivelyFinal true constant null owner use Inheritance#use(LInheritance$Dog;LInheritance$Puppy;LInheritance$Names;LInheritance$Mapper;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Inheritance type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +PARAMETERIZED_TYPE @114:5 : java.util.List +IDENTIFIER @114:5 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @114:5 +TYPE_ARGUMENTS @114:9 +TOKEN @114:9 +IDENTIFIER @114:10 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @114:10 +TOKEN @114:16 +IDENTIFIER @114:18 id view use.view [v package] : java.util.List : java.util.List +TOKEN @114:18 +TOKEN @114:23 +METHOD_INVOCATION @114:25 call AbstractList.subList [m public] : ? (int,int) returns java.util.List throws [] sig java.util.AbstractList#subList(II)Ljava/util/List; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing AbstractList flags [public] overridden [List.subList[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +MEMBER_SELECT @114:25 : ? +IDENTIFIER @114:25 id names use.names [v package] : Inheritance$Names : Inheritance$Names +TOKEN @114:25 +TOKEN @114:30 +IDENTIFIER @114:31 id subList AbstractList.subList [m public] : ? (int,int) returns java.util.List throws [] sig java.util.AbstractList#subList(II)Ljava/util/List; : java.util.List +TOKEN @114:31 +ARGUMENTS @114:38 +TOKEN @114:38 +INT_LITERAL @114:39 : int = 0 +TOKEN @114:39 +TOKEN @114:40 +INT_LITERAL @114:42 : int = 1 +TOKEN @114:42 +TOKEN @114:43 +TOKEN @114:44 +EXPRESSION_STATEMENT @115:5 +METHOD_INVOCATION @115:5 call List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.size[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @115:5 : ? +IDENTIFIER @115:5 id view use.view [v package] : java.util.List : java.util.List +TOKEN @115:5 +TOKEN @115:9 +IDENTIFIER @115:10 id size List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int +TOKEN @115:10 +ARGUMENTS @115:14 +TOKEN @115:14 +TOKEN @115:15 +TOKEN @115:16 +VARIABLE @116:5 var use.animal [v package] : Inheritance$Animal + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Inheritance flags [package] local true parameter false effectivelyFinal true constant null owner use Inheritance#use(LInheritance$Dog;LInheritance$Puppy;LInheritance$Names;LInheritance$Mapper;)V [package] returns void parameters 4 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Inheritance type true kinds truefalsefalse other falsefalsefalsefalsetruefalse4falsefalse +MODIFIERS +IDENTIFIER @116:5 id Animal Inheritance.Animal [t static package interface] : Inheritance$Animal : Inheritance$Animal +TOKEN @116:5 +IDENTIFIER @116:12 id animal use.animal [v package] : Inheritance$Animal : Inheritance$Animal +TOKEN @116:12 +TOKEN @116:19 +IDENTIFIER @116:21 id dog use.dog [v package] : Inheritance$Dog : Inheritance$Dog +TOKEN @116:21 +TOKEN @116:24 +EXPRESSION_STATEMENT @117:5 +METHOD_INVOCATION @117:5 call Animal.compareTo [m public] : ? @java.lang.Override (Inheritance$Animal) returns int throws [] sig Inheritance$Animal#compareTo(LInheritance$Animal;)I : int + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Animal flags [public] overridden [Comparable.compareTo[]] overridable true generic false default true synchronized false varargs false native false parameters [other] parameterMetadata [] +MEMBER_SELECT @117:5 : ? +IDENTIFIER @117:5 id animal use.animal [v package] : Inheritance$Animal : Inheritance$Animal +TOKEN @117:5 +TOKEN @117:11 +IDENTIFIER @117:12 id compareTo Animal.compareTo [m public] : ? @java.lang.Override (Inheritance$Animal) returns int throws [] sig Inheritance$Animal#compareTo(LInheritance$Animal;)I : int +TOKEN @117:12 +ARGUMENTS @117:21 +TOKEN @117:21 +IDENTIFIER @117:22 id puppy use.puppy [v package] : Inheritance$Puppy : Inheritance$Puppy +TOKEN @117:22 +TOKEN @117:27 +TOKEN @117:28 +TOKEN @118:3 +TOKEN @119:1 +TOKEN @120:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Inheritance.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Inheritance.java new file mode 100644 index 00000000000..b5be0beca0e --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Inheritance.java @@ -0,0 +1,119 @@ +import java.io.Closeable; +import java.io.IOException; +import java.util.AbstractList; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.function.Function; + +class Inheritance { + + interface Animal extends Comparable { + String name(); + + default String greet() { + return "I am " + name(); + } + + @Override + default int compareTo(Animal other) { + return name().compareTo(other.name()); + } + } + + abstract static class Base implements Animal, Closeable { + protected int legs; + + protected abstract void move(); + + @Override + public String name() { + return getClass().getSimpleName(); + } + + @Override + public void close() throws IOException { + } + + @Override + public boolean equals(Object other) { + return super.equals(other); + } + + @Override + public int hashCode() { + return legs; + } + } + + static class Dog extends Base { + @Override + protected void move() { + legs = 4; + } + + @Override + public String greet() { + return "Woof " + super.greet(); + } + + @Override + public String toString() { + return name(); + } + } + + static final class Puppy extends Dog { + @Override + protected void move() { + super.move(); + } + } + + static class Names extends AbstractList { + @Override + public String get(int index) { + return "n" + index; + } + + @Override + public int size() { + return 3; + } + + @Override + public Iterator iterator() { + return super.iterator(); + } + } + + static class Mapper implements Function, Comparator { + @Override + public String apply(T value) { + return String.valueOf(value); + } + + @Override + public int compare(T left, T right) { + return apply(left).compareTo(apply(right)); + } + } + + void use(Dog dog, Puppy puppy, Names names, Mapper mapper) throws IOException { + dog.move(); + puppy.move(); + dog.greet(); + puppy.greet(); + dog.close(); + names.get(0); + names.size(); + names.iterator().next(); + mapper.apply(1); + mapper.compare(1, 2); + mapper.reversed(); + List view = names.subList(0, 1); + view.size(); + Animal animal = dog; + animal.compareTo(puppy); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Inheritance.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Inheritance.textproto.gz new file mode 100644 index 00000000000..e689ac027cc Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Inheritance.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/InheritedStaticImports.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/InheritedStaticImports.expected.txt new file mode 100644 index 00000000000..5e0cb2a40cf --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/InheritedStaticImports.expected.txt @@ -0,0 +1,112 @@ +COMPILATION_UNIT @1:1 +PACKAGE @1:1 +TOKEN @1:1 +IDENTIFIER @1:9 id inherited .inherited [p package] : ? : ? +TOKEN @1:9 +TOKEN @1:18 +IMPORT @3:1 +TOKEN @3:1 +TOKEN @3:8 +MEMBER_SELECT @3:15 : ? +MEMBER_SELECT @3:15 : ? +IDENTIFIER @3:15 id inherited unknown : ? +TOKEN @3:15 +TOKEN @3:24 +IDENTIFIER @3:25 id Child unknown : ? +TOKEN @3:25 +TOKEN @3:30 +IDENTIFIER @3:31 id * unknown : ? +TOKEN @3:31 +TOKEN @3:32 +CLASS @5:1 class inherited.Parent [t package] : inherited.Parent super java.lang.Object interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Parent flags [package] members [, twice] lookupToString 0 outermost Parent annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Parent +MODIFIERS +TOKEN @5:1 +IDENTIFIER @5:7 id Parent inherited.Parent [t package] : inherited.Parent : inherited.Parent +TOKEN @5:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @5:14 +METHOD @6:3 method Parent.twice [m static package] : ? (int) returns int throws [] sig inherited.Parent#twice(I)I overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Parent flags [static, package] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MODIFIERS @6:3 +TOKEN @6:3 +TYPE_PARAMETERS +PRIMITIVE_TYPE @6:10 : int +TOKEN @6:10 +IDENTIFIER @6:14 id twice Parent.twice [m static package] : ? (int) returns int throws [] sig inherited.Parent#twice(I)I : int +TOKEN @6:14 +TOKEN @6:19 +VARIABLE @6:20 var twice.value [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Parent flags [package] local true parameter true effectivelyFinal true constant null owner twice inherited.Parent#twice(I)I [static, package] returns int parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Parent type true kinds truefalsefalse other falsefalsefalsefalsefalsefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @6:20 : int +TOKEN @6:20 +IDENTIFIER @6:24 id value twice.value [v package] : int : int +TOKEN @6:24 +TOKEN @6:29 +BLOCK @6:31 +TOKEN @6:31 +RETURN_STATEMENT @7:5 +TOKEN @7:5 +MULTIPLY @7:12 : int +IDENTIFIER @7:12 id value twice.value [v package] : int : int +TOKEN @7:12 +TOKEN @7:18 +INT_LITERAL @7:20 : int = 2 +TOKEN @7:20 +TOKEN @7:21 +TOKEN @8:3 +TOKEN @9:1 +CLASS @11:1 class inherited.Child [t package] : inherited.Child super inherited.Parent interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Child flags [package] members [] lookupToString 0 outermost Child annotation false subtypeOf [java.lang.Object] superTypes [inherited.Parent, java.lang.Object] numerical false wrapper false raw false declaring Child +MODIFIERS +TOKEN @11:1 +IDENTIFIER @11:7 id Child inherited.Child [t package] : inherited.Child : inherited.Child +TOKEN @11:7 +TYPE_PARAMETERS +TOKEN @11:13 +IDENTIFIER @11:21 id Parent inherited.Parent [t package] : inherited.Parent : inherited.Parent +TOKEN @11:21 +LIST +LIST +TOKEN @11:28 +TOKEN @12:1 +CLASS @14:1 class inherited.InheritedStaticImports [t package] : inherited.InheritedStaticImports super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing InheritedStaticImports flags [package] members [, four] lookupToString 0 outermost InheritedStaticImports annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring InheritedStaticImports +MODIFIERS +TOKEN @14:1 +IDENTIFIER @14:7 id InheritedStaticImports inherited.InheritedStaticImports [t package] : inherited.InheritedStaticImports : inherited.InheritedStaticImports +TOKEN @14:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @14:30 +METHOD @15:3 method InheritedStaticImports.four [m package] : ? () returns int throws [] sig inherited.InheritedStaticImports#four()I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing InheritedStaticImports flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @15:3 : int +TOKEN @15:3 +IDENTIFIER @15:7 id four InheritedStaticImports.four [m package] : ? () returns int throws [] sig inherited.InheritedStaticImports#four()I : int +TOKEN @15:7 +TOKEN @15:11 +TOKEN @15:12 +BLOCK @15:14 +TOKEN @15:14 +RETURN_STATEMENT @16:5 +TOKEN @16:5 +METHOD_INVOCATION @16:12 call Parent.twice [m static package] : ? (int) returns int throws [] sig inherited.Parent#twice(I)I : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Parent flags [static, package] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @16:12 id twice Parent.twice [m static package] : ? (int) returns int throws [] sig inherited.Parent#twice(I)I : int +TOKEN @16:12 +ARGUMENTS @16:17 +TOKEN @16:17 +INT_LITERAL @16:18 : int = 2 +TOKEN @16:18 +TOKEN @16:19 +TOKEN @16:20 +TOKEN @17:3 +TOKEN @18:1 +TOKEN @19:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/InheritedStaticImports.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/InheritedStaticImports.java new file mode 100644 index 00000000000..a6aee670b55 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/InheritedStaticImports.java @@ -0,0 +1,18 @@ +package inherited; + +import static inherited.Child.*; + +class Parent { + static int twice(int value) { + return value * 2; + } +} + +class Child extends Parent { +} + +class InheritedStaticImports { + int four() { + return twice(2); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/InheritedStaticImports.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/InheritedStaticImports.textproto.gz new file mode 100644 index 00000000000..2f432894022 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/InheritedStaticImports.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Initializers.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Initializers.expected.txt new file mode 100644 index 00000000000..adef47d455e --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Initializers.expected.txt @@ -0,0 +1,747 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id util unknown : ? +TOKEN @1:13 +TOKEN @1:17 +IDENTIFIER @1:18 id ArrayList unknown : ? +TOKEN @1:18 +TOKEN @1:27 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id util unknown : ? +TOKEN @2:13 +TOKEN @2:17 +IDENTIFIER @2:18 id List unknown : ? +TOKEN @2:18 +TOKEN @2:22 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id util unknown : ? +TOKEN @3:13 +TOKEN @3:17 +IDENTIFIER @3:18 id concurrent unknown : ? +TOKEN @3:18 +TOKEN @3:28 +IDENTIFIER @3:29 id Callable unknown : ? +TOKEN @3:29 +TOKEN @3:37 +CLASS @5:1 class .Initializers [t package] : Initializers super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [package] members [20:14, , , , NAMES, anonymousGeneric, counter, id, local, tasks] lookupToString 0 outermost Initializers annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Initializers +MODIFIERS +TOKEN @5:1 +IDENTIFIER @5:7 id Initializers .Initializers [t package] : Initializers : Initializers +TOKEN @5:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @5:20 +VARIABLE @7:3 var Initializers.NAMES [v static final package] : java.util.List + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Initializers flags [static, final, package] local false parameter false effectivelyFinal true constant null +MODIFIERS @7:3 +TOKEN @7:3 +TOKEN @7:10 +PARAMETERIZED_TYPE @7:16 : java.util.List +IDENTIFIER @7:16 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @7:16 +TYPE_ARGUMENTS @7:20 +TOKEN @7:20 +IDENTIFIER @7:21 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @7:21 +TOKEN @7:27 +IDENTIFIER @7:29 id NAMES Initializers.NAMES [v static final package] : java.util.List : java.util.List +TOKEN @7:29 +TOKEN @7:34 +VARIABLE @8:3 var Initializers.counter [v static package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [static, package] local false parameter false effectivelyFinal false constant null +MODIFIERS @8:3 +TOKEN @8:3 +PRIMITIVE_TYPE @8:10 : int +TOKEN @8:10 +IDENTIFIER @8:14 id counter Initializers.counter [v static package] : int : int +TOKEN @8:14 +TOKEN @8:21 +VARIABLE @9:3 var Initializers.id [v final package] : int + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [final, package] local false parameter false effectivelyFinal true constant null +MODIFIERS @9:3 +TOKEN @9:3 +PRIMITIVE_TYPE @9:9 : int +TOKEN @9:9 +IDENTIFIER @9:13 id id Initializers.id [v final package] : int : int +TOKEN @9:13 +TOKEN @9:15 +VARIABLE @10:3 var Initializers.tasks [v final package] : java.util.List + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Initializers flags [final, package] local false parameter false effectivelyFinal true constant null +MODIFIERS @10:3 +TOKEN @10:3 +PARAMETERIZED_TYPE @10:9 : java.util.List +IDENTIFIER @10:9 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @10:9 +TYPE_ARGUMENTS @10:13 +TOKEN @10:13 +IDENTIFIER @10:14 id Runnable java.lang.Runnable [t public interface] : java.lang.Runnable @java.lang.FunctionalInterface : java.lang.Runnable +TOKEN @10:14 +TOKEN @10:22 +IDENTIFIER @10:24 id tasks Initializers.tasks [v final package] : java.util.List : java.util.List +TOKEN @10:24 +TOKEN @10:30 +NEW_CLASS @10:32 new ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ArrayList flags [public] overridden [AbstractList.[], AbstractCollection.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @10:32 +PARAMETERIZED_TYPE @10:36 : java.util.ArrayList +IDENTIFIER @10:36 id ArrayList ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList +TOKEN @10:36 +TYPE_ARGUMENTS @10:45 +TOKEN @10:45 +TOKEN @10:46 +ARGUMENTS @10:47 +TOKEN @10:47 +TOKEN @10:48 +TOKEN @10:49 +STATIC_INITIALIZER @12:3 +TOKEN @12:3 +TOKEN @12:10 +EXPRESSION_STATEMENT @13:5 +ASSIGNMENT @13:5 : java.util.List +IDENTIFIER @13:5 id NAMES Initializers.NAMES [v static final package] : java.util.List : java.util.List +TOKEN @13:5 +TOKEN @13:11 +NEW_CLASS @13:13 new ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ArrayList flags [public] overridden [AbstractList.[], AbstractCollection.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @13:13 +PARAMETERIZED_TYPE @13:17 : java.util.ArrayList +IDENTIFIER @13:17 id ArrayList ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList +TOKEN @13:17 +TYPE_ARGUMENTS @13:26 +TOKEN @13:26 +TOKEN @13:27 +ARGUMENTS @13:28 +TOKEN @13:28 +TOKEN @13:29 +TOKEN @13:30 +EXPRESSION_STATEMENT @14:5 +METHOD_INVOCATION @14:5 call List.add [m abstract public] : ? (java.lang.String) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.add[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @14:5 : ? +IDENTIFIER @14:5 id NAMES Initializers.NAMES [v static final package] : java.util.List : java.util.List +TOKEN @14:5 +TOKEN @14:10 +IDENTIFIER @14:11 id add List.add [m abstract public] : ? (java.lang.String) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean +TOKEN @14:11 +ARGUMENTS @14:14 +TOKEN @14:14 +STRING_LITERAL @14:15 : java.lang.String = a +TOKEN @14:15 +TOKEN @14:18 +TOKEN @14:19 +EXPRESSION_STATEMENT @15:5 +ASSIGNMENT @15:5 : int +IDENTIFIER @15:5 id counter Initializers.counter [v static package] : int : int +TOKEN @15:5 +TOKEN @15:13 +METHOD_INVOCATION @15:15 call List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.size[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @15:15 : ? +IDENTIFIER @15:15 id NAMES Initializers.NAMES [v static final package] : java.util.List : java.util.List +TOKEN @15:15 +TOKEN @15:20 +IDENTIFIER @15:21 id size List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int +TOKEN @15:21 +ARGUMENTS @15:25 +TOKEN @15:25 +TOKEN @15:26 +TOKEN @15:27 +TOKEN @16:3 +INITIALIZER @18:3 +TOKEN @18:3 +EXPRESSION_STATEMENT @19:5 +ASSIGNMENT @19:5 : int +IDENTIFIER @19:5 id id Initializers.id [v final package] : int : int +TOKEN @19:5 +TOKEN @19:8 +PREFIX_INCREMENT @19:10 : int +TOKEN @19:10 +IDENTIFIER @19:12 id counter Initializers.counter [v static package] : int : int +TOKEN @19:12 +TOKEN @19:19 +EXPRESSION_STATEMENT @20:5 +METHOD_INVOCATION @20:5 call List.add [m abstract public] : ? (java.lang.Runnable) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.add[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @20:5 : ? +IDENTIFIER @20:5 id tasks Initializers.tasks [v final package] : java.util.List : java.util.List +TOKEN @20:5 +TOKEN @20:10 +IDENTIFIER @20:11 id add List.add [m abstract public] : ? (java.lang.Runnable) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean +TOKEN @20:11 +ARGUMENTS @20:14 +TOKEN @20:14 +LAMBDA_EXPRESSION @20:15 : java.lang.Runnable +TOKEN @20:15 +TOKEN @20:16 +TOKEN @20:18 +METHOD_INVOCATION @20:21 call PrintStream.println [m public] : ? (int) returns void throws [] sig java.io.PrintStream#println(I)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing PrintStream flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @20:21 : ? +MEMBER_SELECT @20:21 : java.io.PrintStream +IDENTIFIER @20:21 id System java.lang.System [t final public] : java.lang.System : java.lang.System +TOKEN @20:21 +TOKEN @20:27 +IDENTIFIER @20:28 id out System.out [v static final public] : java.io.PrintStream : java.io.PrintStream +TOKEN @20:28 +TOKEN @20:31 +IDENTIFIER @20:32 id println PrintStream.println [m public] : ? (int) returns void throws [] sig java.io.PrintStream#println(I)V : void +TOKEN @20:32 +ARGUMENTS @20:39 +TOKEN @20:39 +IDENTIFIER @20:40 id id Initializers.id [v final package] : int : int +TOKEN @20:40 +TOKEN @20:42 +TOKEN @20:43 +TOKEN @20:44 +TOKEN @21:3 +CONSTRUCTOR @23:3 method Initializers. [m package] : ? () returns void throws [] sig Initializers#()V overrides true + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [package] overridden [Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @23:3 id Initializers Initializers. [m package] : ? () returns void throws [] sig Initializers#()V : void +TOKEN @23:3 +TOKEN @23:15 +TOKEN @23:16 +BLOCK @23:18 +TOKEN @23:18 +EXPRESSION_STATEMENT @24:5 +METHOD_INVOCATION @24:5 call Initializers. [m package] : ? (int) returns void throws [] sig Initializers#(I)V : Initializers + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [extra] parameterMetadata [] +IDENTIFIER @24:5 id this Initializers. [m package] : ? (int) returns void throws [] sig Initializers#(I)V : ? +TOKEN @24:5 +ARGUMENTS @24:9 +TOKEN @24:9 +INT_LITERAL @24:10 : int = 0 +TOKEN @24:10 +TOKEN @24:11 +TOKEN @24:12 +TOKEN @25:3 +CONSTRUCTOR @27:3 method Initializers. [m package] : ? (int) returns void throws [] sig Initializers#(I)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [extra] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @27:3 id Initializers Initializers. [m package] : ? (int) returns void throws [] sig Initializers#(I)V : void +TOKEN @27:3 +TOKEN @27:15 +VARIABLE @27:16 var .extra [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [package] local true parameter true effectivelyFinal true constant null owner Initializers#(I)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Initializers type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @27:16 : int +TOKEN @27:16 +IDENTIFIER @27:20 id extra .extra [v package] : int : int +TOKEN @27:20 +TOKEN @27:25 +BLOCK @27:27 +TOKEN @27:27 +EXPRESSION_STATEMENT @28:5 +METHOD_INVOCATION @28:5 call Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : java.lang.Object + details declared false usages 2 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @28:5 id super Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : ? +TOKEN @28:5 +ARGUMENTS @28:10 +TOKEN @28:10 +TOKEN @28:11 +TOKEN @28:12 +EXPRESSION_STATEMENT @29:5 +METHOD_INVOCATION @29:5 call List.add [m abstract public] : ? (java.lang.Runnable) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.add[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @29:5 : ? +IDENTIFIER @29:5 id tasks Initializers.tasks [v final package] : java.util.List : java.util.List +TOKEN @29:5 +TOKEN @29:10 +IDENTIFIER @29:11 id add List.add [m abstract public] : ? (java.lang.Runnable) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean +TOKEN @29:11 +ARGUMENTS @29:14 +TOKEN @29:14 +NEW_CLASS @29:15 new Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : Initializers$1 + details declared false usages 2 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @29:15 +IDENTIFIER @29:19 id Runnable Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : java.lang.Runnable +TOKEN @29:19 +ARGUMENTS @29:27 +TOKEN @29:27 +TOKEN @29:28 +CLASS @29:30 class . [t package] : Initializers$1 super java.lang.Object interfaces [java.lang.Runnable] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [package] members [, run, runs] lookupToString 0 outermost Initializers annotation false subtypeOf [java.lang.Object, java.lang.Runnable] superTypes [java.lang.Object, java.lang.Runnable] numerical false wrapper false raw false declaring +MODIFIERS +TYPE_PARAMETERS +LIST +LIST +TOKEN @29:30 +VARIABLE @30:7 var .runs [v private] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing flags [private] local false parameter false effectivelyFinal false constant null +MODIFIERS @30:7 +TOKEN @30:7 +PRIMITIVE_TYPE @30:15 : int +TOKEN @30:15 +IDENTIFIER @30:19 id runs .runs [v private] : int : int +TOKEN @30:19 +TOKEN @30:23 +METHOD @32:7 method .run [m public] : ? @java.lang.Override () returns void throws [] sig Initializers$1#run()V overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing flags [public] overridden [Runnable.run[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @32:7 +ANNOTATION @32:7 : java.lang.Override +TOKEN @32:7 +IDENTIFIER @32:8 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @32:8 +ARGUMENTS +TOKEN @33:7 +TYPE_PARAMETERS +PRIMITIVE_TYPE @33:14 : void +TOKEN @33:14 +IDENTIFIER @33:19 id run .run [m public] : ? @java.lang.Override () returns void throws [] sig Initializers$1#run()V : void +TOKEN @33:19 +TOKEN @33:22 +TOKEN @33:23 +BLOCK @33:25 +TOKEN @33:25 +EXPRESSION_STATEMENT @34:9 +PLUS_ASSIGNMENT @34:9 : int +IDENTIFIER @34:9 id runs .runs [v private] : int : int +TOKEN @34:9 +TOKEN @34:14 +IDENTIFIER @34:17 id extra .extra [v package] : int : int +TOKEN @34:17 +TOKEN @34:22 +TOKEN @35:7 +TOKEN @36:5 +TOKEN @36:6 +TOKEN @36:7 +TOKEN @37:3 +METHOD @39:3 method Initializers.local [m package] : ? (int) returns java.util.concurrent.Callable throws [] sig Initializers#local(I)Ljava/util/concurrent/Callable; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Initializers flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [base] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS +TYPE_PARAMETERS +PARAMETERIZED_TYPE @39:3 : java.util.concurrent.Callable +IDENTIFIER @39:3 id Callable java.util.concurrent.Callable [t public interface] : java.util.concurrent.Callable @java.lang.FunctionalInterface : java.util.concurrent.Callable +TOKEN @39:3 +TYPE_ARGUMENTS @39:11 +TOKEN @39:11 +IDENTIFIER @39:12 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @39:12 +TOKEN @39:19 +IDENTIFIER @39:21 id local Initializers.local [m package] : ? (int) returns java.util.concurrent.Callable throws [] sig Initializers#local(I)Ljava/util/concurrent/Callable; : java.util.concurrent.Callable +TOKEN @39:21 +TOKEN @39:26 +VARIABLE @39:27 var local.base [v package] : int + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [package] local true parameter true effectivelyFinal true constant null owner local Initializers#local(I)Ljava/util/concurrent/Callable; [package] returns java.util.concurrent.Callable parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Initializers type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @39:27 : int +TOKEN @39:27 +IDENTIFIER @39:31 id base local.base [v package] : int : int +TOKEN @39:31 +TOKEN @39:35 +BLOCK @39:37 +TOKEN @39:37 +CLASS @40:5 class local.Adder [t package] : Initializers$1Adder super java.lang.Object interfaces [java.util.concurrent.Callable] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [package] members [call, delta, local(int)$Adder#] lookupToString 0 outermost Initializers annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object, java.util.concurrent.Callable] numerical false wrapper false raw false declaring Adder +MODIFIERS +TOKEN @40:5 +IDENTIFIER @40:11 id Adder local.Adder [t package] : Initializers$1Adder : Initializers$1Adder +TOKEN @40:11 +TYPE_PARAMETERS +TOKEN @40:17 +LIST @40:28 +PARAMETERIZED_TYPE @40:28 : java.util.concurrent.Callable +IDENTIFIER @40:28 id Callable java.util.concurrent.Callable [t public interface] : java.util.concurrent.Callable @java.lang.FunctionalInterface : java.util.concurrent.Callable +TOKEN @40:28 +TYPE_ARGUMENTS @40:36 +TOKEN @40:36 +IDENTIFIER @40:37 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @40:37 +TOKEN @40:44 +LIST +TOKEN @40:46 +VARIABLE @41:7 var Adder.delta [v final private] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Adder flags [final, private] local false parameter false effectivelyFinal true constant null +MODIFIERS @41:7 +TOKEN @41:7 +TOKEN @41:15 +PRIMITIVE_TYPE @41:21 : int +TOKEN @41:21 +IDENTIFIER @41:25 id delta Adder.delta [v final private] : int : int +TOKEN @41:25 +TOKEN @41:30 +CONSTRUCTOR @43:7 method Adder. [m package] : ? (int) returns void throws [] sig Initializers$1Adder#(I)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Adder flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [delta] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @43:7 id Adder Adder. [m package] : ? (int) returns void throws [] sig Initializers$1Adder#(I)V : void +TOKEN @43:7 +TOKEN @43:12 +VARIABLE @43:13 var .delta [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Adder flags [package] local true parameter true effectivelyFinal true constant null owner Initializers$1Adder#(I)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Adder type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @43:13 : int +TOKEN @43:13 +IDENTIFIER @43:17 id delta .delta [v package] : int : int +TOKEN @43:17 +TOKEN @43:22 +BLOCK @43:24 +TOKEN @43:24 +EXPRESSION_STATEMENT @44:9 +ASSIGNMENT @44:9 : int +MEMBER_SELECT @44:9 : int +IDENTIFIER @44:9 id this Adder.this [v final] : Initializers$1Adder : Initializers$1Adder +TOKEN @44:9 +TOKEN @44:13 +IDENTIFIER @44:14 id delta Adder.delta [v final private] : int : int +TOKEN @44:14 +TOKEN @44:20 +IDENTIFIER @44:22 id delta .delta [v package] : int : int +TOKEN @44:22 +TOKEN @44:27 +TOKEN @45:7 +METHOD @47:7 method Adder.call [m public] : ? @java.lang.Override () returns java.lang.Integer throws [] sig Initializers$1Adder#call()Ljava/lang/Integer; overrides true + details declared true usages 0 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing Adder flags [public] overridden [Callable.call[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @47:7 +ANNOTATION @47:7 : java.lang.Override +TOKEN @47:7 +IDENTIFIER @47:8 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @47:8 +ARGUMENTS +TOKEN @48:7 +TYPE_PARAMETERS +IDENTIFIER @48:14 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @48:14 +IDENTIFIER @48:22 id call Adder.call [m public] : ? @java.lang.Override () returns java.lang.Integer throws [] sig Initializers$1Adder#call()Ljava/lang/Integer; : java.lang.Integer +TOKEN @48:22 +TOKEN @48:26 +TOKEN @48:27 +BLOCK @48:29 +TOKEN @48:29 +RETURN_STATEMENT @49:9 +TOKEN @49:9 +PLUS @49:16 : int +PLUS @49:16 : int +IDENTIFIER @49:16 id base local.base [v package] : int : int +TOKEN @49:16 +TOKEN @49:21 +IDENTIFIER @49:23 id delta Adder.delta [v final private] : int : int +TOKEN @49:23 +TOKEN @49:29 +IDENTIFIER @49:31 id id Initializers.id [v final package] : int : int +TOKEN @49:31 +TOKEN @49:33 +TOKEN @50:7 +TOKEN @51:5 +RECORD @52:5 class local.Pair [t static final package] : Initializers$1Pair super java.lang.Record interfaces [] + details declared true usages 2 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [static, final, package] members [left, local(int)$Pair#, right, sum] lookupToString 0 outermost Initializers annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object, java.lang.Record] numerical false wrapper false raw false declaring Pair +MODIFIERS +TOKEN @52:5 +IDENTIFIER @52:12 id Pair local.Pair [t static final package] : Initializers$1Pair : Initializers$1Pair +TOKEN @52:12 +TYPE_PARAMETERS +TOKEN @52:16 +VARIABLE @52:17 var Pair.left [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Pair flags [package] local false parameter true effectivelyFinal true constant null +MODIFIERS +PRIMITIVE_TYPE @52:17 : int +TOKEN @52:17 +IDENTIFIER @52:21 id left Pair.left [v package] : int : int +TOKEN @52:21 +TOKEN @52:25 +VARIABLE @52:27 var Pair.right [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Pair flags [package] local false parameter true effectivelyFinal true constant null +MODIFIERS +PRIMITIVE_TYPE @52:27 : int +TOKEN @52:27 +IDENTIFIER @52:31 id right Pair.right [v package] : int : int +TOKEN @52:31 +TOKEN @52:36 +LIST +LIST +TOKEN @52:38 +METHOD @53:7 method Pair.sum [m package] : ? () returns int throws [] sig Initializers$1Pair#sum()I overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Pair flags [package] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @53:7 : int +TOKEN @53:7 +IDENTIFIER @53:11 id sum Pair.sum [m package] : ? () returns int throws [] sig Initializers$1Pair#sum()I : int +TOKEN @53:11 +TOKEN @53:14 +TOKEN @53:15 +BLOCK @53:17 +TOKEN @53:17 +RETURN_STATEMENT @54:9 +TOKEN @54:9 +PLUS @54:16 : int +IDENTIFIER @54:16 id left Pair.left [v package] : int : int +TOKEN @54:16 +TOKEN @54:21 +IDENTIFIER @54:23 id right Pair.right [v package] : int : int +TOKEN @54:23 +TOKEN @54:28 +TOKEN @55:7 +TOKEN @56:5 +ENUM @57:5 class local.Kind [t static package] : Initializers$1Kind super java.lang.Enum interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [static, package] members [, ONE, TWO] lookupToString 0 outermost Initializers annotation false subtypeOf [java.lang.Object, java.io.Serializable, java.lang.Comparable] superTypes [java.io.Serializable, java.lang.Comparable, java.lang.Enum, java.lang.Object, java.lang.constant.Constable] numerical false wrapper false raw false declaring Kind +MODIFIERS +TOKEN @57:5 +IDENTIFIER @57:10 id Kind local.Kind [t static package] : Initializers$1Kind : Initializers$1Kind +TOKEN @57:10 +TYPE_PARAMETERS +LIST +LIST +TOKEN @57:15 +ENUM_CONSTANT @58:7 var Kind.ONE [v static final public enum] : Initializers$1Kind + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Kind flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @58:7 new unknown : ? +IDENTIFIER @58:7 id ONE unknown : Initializers$1Kind +TOKEN @58:7 +ARGUMENTS +TOKEN @58:10 +ENUM_CONSTANT @58:12 var Kind.TWO [v static final public enum] : Initializers$1Kind + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Kind flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @58:12 new unknown : ? +IDENTIFIER @58:12 id TWO unknown : Initializers$1Kind +TOKEN @58:12 +ARGUMENTS +TOKEN @59:5 +INTERFACE @60:5 class local.Shape [t static package] : Initializers$1Shape super java.lang.Object interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [static, package] members [area, local(int)$Shape#] lookupToString 0 outermost Initializers annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Shape +MODIFIERS +TOKEN @60:5 +IDENTIFIER @60:15 id Shape local.Shape [t static package] : Initializers$1Shape : Initializers$1Shape +TOKEN @60:15 +TYPE_PARAMETERS +LIST +LIST +TOKEN @60:21 +METHOD @61:7 method Shape.area [m package] : ? () returns double throws [] sig Initializers$1Shape#area()D overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Shape flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @61:7 : double +TOKEN @61:7 +IDENTIFIER @61:14 id area Shape.area [m package] : ? () returns double throws [] sig Initializers$1Shape#area()D : double +TOKEN @61:14 +TOKEN @61:18 +TOKEN @61:19 +TOKEN @61:20 +TOKEN @62:5 +VARIABLE @63:5 var local.square [v package] : Initializers#local(int)$Shape + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [package] local true parameter false effectivelyFinal true constant null owner local Initializers#local(I)Ljava/util/concurrent/Callable; [package] returns java.util.concurrent.Callable parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Initializers type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @63:5 id Shape local.Shape [t static package] : Initializers$1Shape : Initializers#local(int)$Shape +TOKEN @63:5 +IDENTIFIER @63:11 id square local.square [v package] : Initializers#local(int)$Shape : Initializers#local(int)$Shape +TOKEN @63:11 +TOKEN @63:18 +LAMBDA_EXPRESSION @63:20 : Initializers$1Shape +TOKEN @63:20 +TOKEN @63:21 +TOKEN @63:23 +MULTIPLY @63:26 : int +IDENTIFIER @63:26 id base local.base [v package] : int : int +TOKEN @63:26 +TOKEN @63:31 +IDENTIFIER @63:33 id base local.base [v package] : int : int +TOKEN @63:33 +TOKEN @63:37 +VARIABLE @64:5 var local.pair [v package] : Initializers#local(int)$Pair + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [package] local true parameter false effectivelyFinal true constant null owner local Initializers#local(I)Ljava/util/concurrent/Callable; [package] returns java.util.concurrent.Callable parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Initializers type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @64:5 id Pair local.Pair [t static final package] : Initializers$1Pair : Initializers#local(int)$Pair +TOKEN @64:5 +IDENTIFIER @64:10 id pair local.pair [v package] : Initializers#local(int)$Pair : Initializers#local(int)$Pair +TOKEN @64:10 +TOKEN @64:15 +NEW_CLASS @64:17 new Pair. [m package] : ? (int,int) returns void throws [] sig Initializers$1Pair#(II)V : Initializers$1Pair + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Pair flags [package] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +TOKEN @64:17 +IDENTIFIER @64:21 id Pair Pair. [m package] : ? (int,int) returns void throws [] sig Initializers$1Pair#(II)V : Initializers$1Pair +TOKEN @64:21 +ARGUMENTS @64:25 +TOKEN @64:25 +IDENTIFIER @64:26 id base local.base [v package] : int : int +TOKEN @64:26 +TOKEN @64:30 +METHOD_INVOCATION @64:32 call Enum.ordinal [m final public] : ? () returns int throws [] sig java.lang.Enum#ordinal()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enum flags [final, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @64:32 : ? +MEMBER_SELECT @64:32 : Initializers$1Kind +IDENTIFIER @64:32 id Kind local.Kind [t static package] : Initializers$1Kind : Initializers$1Kind +TOKEN @64:32 +TOKEN @64:36 +IDENTIFIER @64:37 id TWO Kind.TWO [v static final public enum] : Initializers$1Kind : Initializers$1Kind +TOKEN @64:37 +TOKEN @64:40 +IDENTIFIER @64:41 id ordinal Enum.ordinal [m final public] : ? () returns int throws [] sig java.lang.Enum#ordinal()I : int +TOKEN @64:41 +ARGUMENTS @64:48 +TOKEN @64:48 +TOKEN @64:49 +TOKEN @64:50 +TOKEN @64:51 +RETURN_STATEMENT @65:5 +TOKEN @65:5 +NEW_CLASS @65:12 new Adder. [m package] : ? (int) returns void throws [] sig Initializers$1Adder#(I)V : Initializers$1Adder + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Adder flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [delta] parameterMetadata [] +TOKEN @65:12 +IDENTIFIER @65:16 id Adder Adder. [m package] : ? (int) returns void throws [] sig Initializers$1Adder#(I)V : Initializers$1Adder +TOKEN @65:16 +ARGUMENTS @65:21 +TOKEN @65:21 +PLUS @65:22 : int +METHOD_INVOCATION @65:22 call Pair.sum [m package] : ? () returns int throws [] sig Initializers$1Pair#sum()I : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Pair flags [package] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @65:22 : ? +IDENTIFIER @65:22 id pair local.pair [v package] : Initializers#local(int)$Pair : Initializers#local(int)$Pair +TOKEN @65:22 +TOKEN @65:26 +IDENTIFIER @65:27 id sum Pair.sum [m package] : ? () returns int throws [] sig Initializers$1Pair#sum()I : int +TOKEN @65:27 +ARGUMENTS @65:30 +TOKEN @65:30 +TOKEN @65:31 +TOKEN @65:33 +TYPE_CAST @65:35 : int +TOKEN @65:35 +PRIMITIVE_TYPE @65:36 : int +TOKEN @65:36 +LIST +TOKEN @65:39 +METHOD_INVOCATION @65:41 call Shape.area [m package] : ? () returns double throws [] sig Initializers$1Shape#area()D : double + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Shape flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @65:41 : ? +IDENTIFIER @65:41 id square local.square [v package] : Initializers#local(int)$Shape : Initializers#local(int)$Shape +TOKEN @65:41 +TOKEN @65:47 +IDENTIFIER @65:48 id area Shape.area [m package] : ? () returns double throws [] sig Initializers$1Shape#area()D : double +TOKEN @65:48 +ARGUMENTS @65:52 +TOKEN @65:52 +TOKEN @65:53 +TOKEN @65:54 +TOKEN @65:55 +TOKEN @66:3 +METHOD @68:3 method Initializers.anonymousGeneric [m package] : ? () returns java.lang.Object throws [] sig Initializers#anonymousGeneric()Ljava/lang/Object; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @68:3 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @68:3 +IDENTIFIER @68:10 id anonymousGeneric Initializers.anonymousGeneric [m package] : ? () returns java.lang.Object throws [] sig Initializers#anonymousGeneric()Ljava/lang/Object; : java.lang.Object +TOKEN @68:10 +TOKEN @68:26 +TOKEN @68:27 +BLOCK @68:29 +TOKEN @68:29 +RETURN_STATEMENT @69:5 +TOKEN @69:5 +NEW_CLASS @69:12 new ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : Initializers$2 + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ArrayList flags [public] overridden [AbstractList.[], AbstractCollection.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @69:12 +PARAMETERIZED_TYPE @69:16 : java.util.ArrayList +IDENTIFIER @69:16 id ArrayList ArrayList. [m public] : ? () returns void throws [] sig java.util.ArrayList#()V : java.util.ArrayList +TOKEN @69:16 +TYPE_ARGUMENTS @69:25 +TOKEN @69:25 +IDENTIFIER @69:26 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @69:26 +TOKEN @69:32 +ARGUMENTS @69:33 +TOKEN @69:33 +TOKEN @69:34 +CLASS @69:36 class anonymousGeneric. [t package] : Initializers$2 super java.util.ArrayList interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Initializers flags [package] members [, add] lookupToString 0 outermost Initializers annotation false subtypeOf [java.lang.Object, java.io.Serializable, java.util.Collection] superTypes [java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.lang.Object, java.util.AbstractCollection, java.util.AbstractList, java.util.ArrayList, java.util.Collection, java.util.List, java.util.RandomAccess, java.util.SequencedCollection] numerical false wrapper false raw false declaring +MODIFIERS +TYPE_PARAMETERS +LIST +LIST +TOKEN @69:36 +INITIALIZER @70:7 +TOKEN @70:7 +EXPRESSION_STATEMENT @71:9 +METHOD_INVOCATION @71:9 call .add [m public] : ? @java.lang.Override (java.lang.String) returns boolean throws [] sig Initializers$2#add(Ljava/lang/String;)Z : boolean + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing flags [public] overridden [ArrayList.add[]] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @71:9 id add .add [m public] : ? @java.lang.Override (java.lang.String) returns boolean throws [] sig Initializers$2#add(Ljava/lang/String;)Z : boolean +TOKEN @71:9 +ARGUMENTS @71:12 +TOKEN @71:12 +STRING_LITERAL @71:13 : java.lang.String = first +TOKEN @71:13 +TOKEN @71:20 +TOKEN @71:21 +TOKEN @72:7 +METHOD @74:7 method .add [m public] : ? @java.lang.Override (java.lang.String) returns boolean throws [] sig Initializers$2#add(Ljava/lang/String;)Z overrides true + details declared true usages 1 metadata [java.lang.Override()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [java.lang.Override tree true values 0 annotated true] typeArguments [] enclosing flags [public] overridden [ArrayList.add[]] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MODIFIERS @74:7 +ANNOTATION @74:7 : java.lang.Override +TOKEN @74:7 +IDENTIFIER @74:8 id Override java.lang.Override [t public interface] : java.lang.Override @java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Override +TOKEN @74:8 +ARGUMENTS +TOKEN @75:7 +TYPE_PARAMETERS +PRIMITIVE_TYPE @75:14 : boolean +TOKEN @75:14 +IDENTIFIER @75:22 id add .add [m public] : ? @java.lang.Override (java.lang.String) returns boolean throws [] sig Initializers$2#add(Ljava/lang/String;)Z : boolean +TOKEN @75:22 +TOKEN @75:25 +VARIABLE @75:26 var add.value [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing flags [package] local true parameter true effectivelyFinal true constant null owner add Initializers$2#add(Ljava/lang/String;)Z [public] returns boolean parameters 1 thrown 0 overridden 1 declared true usages 1 metadata 1 enclosing type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @75:26 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @75:26 +IDENTIFIER @75:33 id value add.value [v package] : java.lang.String : java.lang.String +TOKEN @75:33 +TOKEN @75:38 +BLOCK @75:40 +TOKEN @75:40 +RETURN_STATEMENT @76:9 +TOKEN @76:9 +METHOD_INVOCATION @76:16 call ArrayList.add [m public] : ? (java.lang.Object) returns boolean throws [] sig java.util.ArrayList#add(Ljava/lang/Object;)Z : boolean + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ArrayList flags [public] overridden [AbstractList.add[], AbstractCollection.add[], Collection.add[], List.add[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @76:16 : ? +IDENTIFIER @76:16 id super Initializers.super [v final] : java.lang.Object : java.lang.Object +TOKEN @76:16 +TOKEN @76:21 +IDENTIFIER @76:22 id add ArrayList.add [m public] : ? (java.lang.Object) returns boolean throws [] sig java.util.ArrayList#add(Ljava/lang/Object;)Z : boolean +TOKEN @76:22 +ARGUMENTS @76:25 +TOKEN @76:25 +METHOD_INVOCATION @76:26 call String.trim [m public] : ? () returns java.lang.String throws [] sig java.lang.String#trim()Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @76:26 : ? +IDENTIFIER @76:26 id value add.value [v package] : java.lang.String : java.lang.String +TOKEN @76:26 +TOKEN @76:31 +IDENTIFIER @76:32 id trim String.trim [m public] : ? () returns java.lang.String throws [] sig java.lang.String#trim()Ljava/lang/String; : java.lang.String +TOKEN @76:32 +ARGUMENTS @76:36 +TOKEN @76:36 +TOKEN @76:37 +TOKEN @76:38 +TOKEN @76:39 +TOKEN @77:7 +TOKEN @78:5 +TOKEN @78:6 +TOKEN @79:3 +TOKEN @80:1 +TOKEN @81:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Initializers.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Initializers.java new file mode 100644 index 00000000000..058163ddecb --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Initializers.java @@ -0,0 +1,80 @@ +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + +class Initializers { + + static final List NAMES; + static int counter; + final int id; + final List tasks = new ArrayList<>(); + + static { + NAMES = new ArrayList<>(); + NAMES.add("a"); + counter = NAMES.size(); + } + + { + id = ++counter; + tasks.add(() -> System.out.println(id)); + } + + Initializers() { + this(0); + } + + Initializers(int extra) { + super(); + tasks.add(new Runnable() { + private int runs; + + @Override + public void run() { + runs += extra; + } + }); + } + + Callable local(int base) { + class Adder implements Callable { + private final int delta; + + Adder(int delta) { + this.delta = delta; + } + + @Override + public Integer call() { + return base + delta + id; + } + } + record Pair(int left, int right) { + int sum() { + return left + right; + } + } + enum Kind { + ONE, TWO + } + interface Shape { + double area(); + } + Shape square = () -> base * base; + Pair pair = new Pair(base, Kind.TWO.ordinal()); + return new Adder(pair.sum() + (int) square.area()); + } + + Object anonymousGeneric() { + return new ArrayList() { + { + add("first"); + } + + @Override + public boolean add(String value) { + return super.add(value.trim()); + } + }; + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Initializers.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Initializers.textproto.gz new file mode 100644 index 00000000000..79e374064a0 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Initializers.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/IntersectionCasts.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/IntersectionCasts.expected.txt new file mode 100644 index 00000000000..22bc8cf1b1f --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/IntersectionCasts.expected.txt @@ -0,0 +1,135 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id io unknown : ? +TOKEN @1:13 +TOKEN @1:15 +IDENTIFIER @1:16 id Serializable unknown : ? +TOKEN @1:16 +TOKEN @1:28 +CLASS @3:1 class .IntersectionCasts [t package] : IntersectionCasts super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing IntersectionCasts flags [package] members [, keep, redundant] lookupToString 0 outermost IntersectionCasts annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring IntersectionCasts +MODIFIERS +TOKEN @3:1 +IDENTIFIER @3:7 id IntersectionCasts .IntersectionCasts [t package] : IntersectionCasts : IntersectionCasts +TOKEN @3:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @3:25 +METHOD @4:3 method IntersectionCasts.keep [m package] : ? (java.lang.Comparable) returns java.io.Serializable throws [] sig IntersectionCasts#keep(Ljava/lang/Comparable;)Ljava/io/Serializable; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing IntersectionCasts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [comparable] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @4:3 id Serializable java.io.Serializable [t public interface] : java.io.Serializable : java.io.Serializable +TOKEN @4:3 +IDENTIFIER @4:16 id keep IntersectionCasts.keep [m package] : ? (java.lang.Comparable) returns java.io.Serializable throws [] sig IntersectionCasts#keep(Ljava/lang/Comparable;)Ljava/io/Serializable; : java.io.Serializable +TOKEN @4:16 +TOKEN @4:20 +VARIABLE @4:21 var keep.comparable [v package] : java.lang.Comparable + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing IntersectionCasts flags [package] local true parameter true effectivelyFinal true constant null owner keep IntersectionCasts#keep(Ljava/lang/Comparable;)Ljava/io/Serializable; [package] returns java.io.Serializable parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing IntersectionCasts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @4:21 : java.lang.Comparable +IDENTIFIER @4:21 id Comparable java.lang.Comparable [t public interface] : java.lang.Comparable : java.lang.Comparable +TOKEN @4:21 +TYPE_ARGUMENTS @4:31 +TOKEN @4:31 +IDENTIFIER @4:32 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @4:32 +TOKEN @4:38 +IDENTIFIER @4:40 id comparable keep.comparable [v package] : java.lang.Comparable : java.lang.Comparable +TOKEN @4:40 +TOKEN @4:50 +BLOCK @4:52 +TOKEN @4:52 +VARIABLE @5:5 var keep.serializable [v package] : java.io.Serializable + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing IntersectionCasts flags [package] local true parameter false effectivelyFinal true constant null owner keep IntersectionCasts#keep(Ljava/lang/Comparable;)Ljava/io/Serializable; [package] returns java.io.Serializable parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing IntersectionCasts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @5:5 id Serializable java.io.Serializable [t public interface] : java.io.Serializable : java.io.Serializable +TOKEN @5:5 +IDENTIFIER @5:18 id serializable keep.serializable [v package] : java.io.Serializable : java.io.Serializable +TOKEN @5:18 +TOKEN @5:31 +TYPE_CAST @5:33 : java.io.Serializable & java.lang.Comparable +TOKEN @5:33 +PARAMETERIZED_TYPE @5:34 : java.lang.Comparable +IDENTIFIER @5:34 id Comparable java.lang.Comparable [t public interface] : java.lang.Comparable : java.lang.Comparable +TOKEN @5:34 +TYPE_ARGUMENTS @5:44 +TOKEN @5:44 +IDENTIFIER @5:45 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @5:45 +TOKEN @5:51 +TOKEN @5:53 +LIST @5:55 +IDENTIFIER @5:55 id Serializable java.io.Serializable [t public interface] : java.io.Serializable : java.io.Serializable +TOKEN @5:55 +TOKEN @5:67 +IDENTIFIER @5:69 id comparable keep.comparable [v package] : java.lang.Comparable : java.lang.Comparable +TOKEN @5:69 +TOKEN @5:79 +RETURN_STATEMENT @6:5 +TOKEN @6:5 +IDENTIFIER @6:12 id serializable keep.serializable [v package] : java.io.Serializable : java.io.Serializable +TOKEN @6:12 +TOKEN @6:24 +TOKEN @7:3 +METHOD @9:3 method IntersectionCasts.redundant [m package] : ? (java.lang.String) returns java.lang.Object throws [] sig IntersectionCasts#redundant(Ljava/lang/String;)Ljava/lang/Object; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing IntersectionCasts flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [text] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @9:3 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @9:3 +IDENTIFIER @9:10 id redundant IntersectionCasts.redundant [m package] : ? (java.lang.String) returns java.lang.Object throws [] sig IntersectionCasts#redundant(Ljava/lang/String;)Ljava/lang/Object; : java.lang.Object +TOKEN @9:10 +TOKEN @9:19 +VARIABLE @9:20 var redundant.text [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing IntersectionCasts flags [package] local true parameter true effectivelyFinal true constant null owner redundant IntersectionCasts#redundant(Ljava/lang/String;)Ljava/lang/Object; [package] returns java.lang.Object parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing IntersectionCasts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @9:20 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @9:20 +IDENTIFIER @9:27 id text redundant.text [v package] : java.lang.String : java.lang.String +TOKEN @9:27 +TOKEN @9:31 +BLOCK @9:33 +TOKEN @9:33 +VARIABLE @10:5 var redundant.widened [v package] : java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing IntersectionCasts flags [package] local true parameter false effectivelyFinal true constant null owner redundant IntersectionCasts#redundant(Ljava/lang/String;)Ljava/lang/Object; [package] returns java.lang.Object parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing IntersectionCasts type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @10:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @10:5 +IDENTIFIER @10:12 id widened redundant.widened [v package] : java.lang.Object : java.lang.Object +TOKEN @10:12 +TOKEN @10:20 +TYPE_CAST @10:22 : java.io.Serializable & java.lang.Comparable +TOKEN @10:22 +PARAMETERIZED_TYPE @10:23 : java.lang.Comparable +IDENTIFIER @10:23 id Comparable java.lang.Comparable [t public interface] : java.lang.Comparable : java.lang.Comparable +TOKEN @10:23 +TYPE_ARGUMENTS @10:33 +TOKEN @10:33 +IDENTIFIER @10:34 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @10:34 +TOKEN @10:40 +TOKEN @10:42 +LIST @10:44 +IDENTIFIER @10:44 id Serializable java.io.Serializable [t public interface] : java.io.Serializable : java.io.Serializable +TOKEN @10:44 +TOKEN @10:56 +IDENTIFIER @10:58 id text redundant.text [v package] : java.lang.String : java.lang.String +TOKEN @10:58 +TOKEN @10:62 +RETURN_STATEMENT @11:5 +TOKEN @11:5 +IDENTIFIER @11:12 id widened redundant.widened [v package] : java.lang.Object : java.lang.Object +TOKEN @11:12 +TOKEN @11:19 +TOKEN @12:3 +TOKEN @13:1 +TOKEN @14:1 +WARNING REDUNDANT_CAST TYPE_CAST @10:22 Unnecessary cast from String to Serializable & Comparable diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/IntersectionCasts.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/IntersectionCasts.java new file mode 100644 index 00000000000..66f11005802 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/IntersectionCasts.java @@ -0,0 +1,13 @@ +import java.io.Serializable; + +class IntersectionCasts { + Serializable keep(Comparable comparable) { + Serializable serializable = (Comparable & Serializable) comparable; + return serializable; + } + + Object redundant(String text) { + Object widened = (Comparable & Serializable) text; + return widened; + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/IntersectionCasts.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/IntersectionCasts.textproto.gz new file mode 100644 index 00000000000..4c52adda6eb Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/IntersectionCasts.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/JavadocImports.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/JavadocImports.expected.txt new file mode 100644 index 00000000000..5843d66fa53 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/JavadocImports.expected.txt @@ -0,0 +1,63 @@ +COMPILATION_UNIT @2:1 +PACKAGE @2:1 +TOKEN @2:1 +IDENTIFIER @2:9 id javadoc .javadoc [p package] : ? : ? +TOKEN @2:9 +TOKEN @2:16 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id io unknown : ? +TOKEN @4:13 +TOKEN @4:15 +IDENTIFIER @4:16 id File unknown : ? +TOKEN @4:16 +TOKEN @4:20 +IMPORT @5:1 +TOKEN @5:1 +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +IDENTIFIER @5:8 id java unknown : ? +TOKEN @5:8 +TOKEN @5:12 +IDENTIFIER @5:13 id util unknown : ? +TOKEN @5:13 +TOKEN @5:17 +IDENTIFIER @5:18 id * unknown : ? +TOKEN @5:18 +TOKEN @5:19 +IMPORT @6:1 +TOKEN @6:1 +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +IDENTIFIER @6:8 id java unknown : ? +TOKEN @6:8 +TOKEN @6:12 +IDENTIFIER @6:13 id util unknown : ? +TOKEN @6:13 +TOKEN @6:17 +IDENTIFIER @6:18 id concurrent unknown : ? +TOKEN @6:18 +TOKEN @6:28 +IDENTIFIER @6:29 id * unknown : ? +TOKEN @6:29 +TOKEN @6:30 +CLASS @9:1 class javadoc.JavadocImports [t package] : javadoc.JavadocImports super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing JavadocImports flags [package] members [] lookupToString 0 outermost JavadocImports annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring JavadocImports +MODIFIERS +TOKEN @9:1 +IDENTIFIER @9:7 id JavadocImports javadoc.JavadocImports [t package] : javadoc.JavadocImports : javadoc.JavadocImports +TOKEN @9:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @9:22 +TOKEN @10:1 +TOKEN @11:1 +WARNING UNUSED_IMPORT IMPORT @4:1 The import java.io.File is never used +WARNING UNUSED_IMPORT IMPORT @6:1 The import java.util.concurrent is never used diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/JavadocImports.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/JavadocImports.java new file mode 100644 index 00000000000..ac1fd3f296e --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/JavadocImports.java @@ -0,0 +1,10 @@ +/** {@link File} */ +package javadoc; + +import java.io.File; +import java.util.*; +import java.util.concurrent.*; + +/** {@link List} */ +class JavadocImports { +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/JavadocImports.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/JavadocImports.textproto.gz new file mode 100644 index 00000000000..822097fcef0 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/JavadocImports.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Lambdas.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Lambdas.expected.txt new file mode 100644 index 00000000000..d32f2d3f680 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Lambdas.expected.txt @@ -0,0 +1,982 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id util unknown : ? +TOKEN @1:13 +TOKEN @1:17 +IDENTIFIER @1:18 id Comparator unknown : ? +TOKEN @1:18 +TOKEN @1:28 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id util unknown : ? +TOKEN @2:13 +TOKEN @2:17 +IDENTIFIER @2:18 id List unknown : ? +TOKEN @2:18 +TOKEN @2:22 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id util unknown : ? +TOKEN @3:13 +TOKEN @3:17 +IDENTIFIER @3:18 id Map unknown : ? +TOKEN @3:18 +TOKEN @3:21 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id util unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id Optional unknown : ? +TOKEN @4:18 +TOKEN @4:26 +IMPORT @5:1 +TOKEN @5:1 +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +IDENTIFIER @5:8 id java unknown : ? +TOKEN @5:8 +TOKEN @5:12 +IDENTIFIER @5:13 id util unknown : ? +TOKEN @5:13 +TOKEN @5:17 +IDENTIFIER @5:18 id function unknown : ? +TOKEN @5:18 +TOKEN @5:26 +IDENTIFIER @5:27 id BiFunction unknown : ? +TOKEN @5:27 +TOKEN @5:37 +IMPORT @6:1 +TOKEN @6:1 +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +IDENTIFIER @6:8 id java unknown : ? +TOKEN @6:8 +TOKEN @6:12 +IDENTIFIER @6:13 id util unknown : ? +TOKEN @6:13 +TOKEN @6:17 +IDENTIFIER @6:18 id function unknown : ? +TOKEN @6:18 +TOKEN @6:26 +IDENTIFIER @6:27 id Function unknown : ? +TOKEN @6:27 +TOKEN @6:35 +IMPORT @7:1 +TOKEN @7:1 +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +IDENTIFIER @7:8 id java unknown : ? +TOKEN @7:8 +TOKEN @7:12 +IDENTIFIER @7:13 id util unknown : ? +TOKEN @7:13 +TOKEN @7:17 +IDENTIFIER @7:18 id function unknown : ? +TOKEN @7:18 +TOKEN @7:26 +IDENTIFIER @7:27 id Predicate unknown : ? +TOKEN @7:27 +TOKEN @7:36 +IMPORT @8:1 +TOKEN @8:1 +MEMBER_SELECT @8:8 : ? +MEMBER_SELECT @8:8 : ? +MEMBER_SELECT @8:8 : ? +IDENTIFIER @8:8 id java unknown : ? +TOKEN @8:8 +TOKEN @8:12 +IDENTIFIER @8:13 id util unknown : ? +TOKEN @8:13 +TOKEN @8:17 +IDENTIFIER @8:18 id function unknown : ? +TOKEN @8:18 +TOKEN @8:26 +IDENTIFIER @8:27 id Supplier unknown : ? +TOKEN @8:27 +TOKEN @8:35 +IMPORT @9:1 +TOKEN @9:1 +MEMBER_SELECT @9:8 : ? +MEMBER_SELECT @9:8 : ? +MEMBER_SELECT @9:8 : ? +IDENTIFIER @9:8 id java unknown : ? +TOKEN @9:8 +TOKEN @9:12 +IDENTIFIER @9:13 id util unknown : ? +TOKEN @9:13 +TOKEN @9:17 +IDENTIFIER @9:18 id stream unknown : ? +TOKEN @9:18 +TOKEN @9:24 +IDENTIFIER @9:25 id Collectors unknown : ? +TOKEN @9:25 +TOKEN @9:35 +CLASS @11:1 class .Lambdas [t package] : Lambdas super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Lambdas flags [package] members [13:22, 15:30, 19:46, 20:48, , arrays, builder, byLength, capture, empty, firstUpper, grouped, length, lengths, notEmpty, printer, runnable, sort, sum, supplier, total, typed] lookupToString 0 outermost Lambdas annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Lambdas +MODIFIERS +TOKEN @11:1 +IDENTIFIER @11:7 id Lambdas .Lambdas [t package] : Lambdas : Lambdas +TOKEN @11:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @11:15 +VARIABLE @13:3 var Lambdas.runnable [v package] : java.lang.Runnable + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Lambdas flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @13:3 id Runnable java.lang.Runnable [t public interface] : java.lang.Runnable @java.lang.FunctionalInterface : java.lang.Runnable +TOKEN @13:3 +IDENTIFIER @13:12 id runnable Lambdas.runnable [v package] : java.lang.Runnable : java.lang.Runnable +TOKEN @13:12 +TOKEN @13:21 +LAMBDA_EXPRESSION @13:23 : java.lang.Runnable +TOKEN @13:23 +TOKEN @13:24 +TOKEN @13:26 +BLOCK @13:29 +TOKEN @13:29 +TOKEN @14:3 +TOKEN @14:4 +VARIABLE @15:3 var Lambdas.supplier [v package] : java.util.function.Supplier + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @15:3 : java.util.function.Supplier +IDENTIFIER @15:3 id Supplier java.util.function.Supplier [t public interface] : java.util.function.Supplier @java.lang.FunctionalInterface : java.util.function.Supplier +TOKEN @15:3 +TYPE_ARGUMENTS @15:11 +TOKEN @15:11 +IDENTIFIER @15:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @15:12 +TOKEN @15:18 +IDENTIFIER @15:20 id supplier Lambdas.supplier [v package] : java.util.function.Supplier : java.util.function.Supplier +TOKEN @15:20 +TOKEN @15:29 +LAMBDA_EXPRESSION @15:31 : java.util.function.Supplier +TOKEN @15:31 +TOKEN @15:32 +TOKEN @15:34 +STRING_LITERAL @15:37 : java.lang.String = value +TOKEN @15:37 +TOKEN @15:44 +VARIABLE @16:3 var Lambdas.length [v package] : java.util.function.Function + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Lambdas flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @16:3 : java.util.function.Function +IDENTIFIER @16:3 id Function java.util.function.Function [t public interface] : java.util.function.Function @java.lang.FunctionalInterface : java.util.function.Function +TOKEN @16:3 +TYPE_ARGUMENTS @16:11 +TOKEN @16:11 +IDENTIFIER @16:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @16:12 +TOKEN @16:18 +IDENTIFIER @16:20 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @16:20 +TOKEN @16:27 +IDENTIFIER @16:29 id length Lambdas.length [v package] : java.util.function.Function : java.util.function.Function +TOKEN @16:29 +TOKEN @16:36 +METHOD_REFERENCE @16:38 : java.util.function.Function +IDENTIFIER @16:38 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @16:38 +TOKEN @16:44 +IDENTIFIER @16:46 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @16:46 +TOKEN @16:52 +VARIABLE @17:3 var Lambdas.arrays [v package] : java.util.function.Function + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Lambdas flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @17:3 : java.util.function.Function +IDENTIFIER @17:3 id Function java.util.function.Function [t public interface] : java.util.function.Function @java.lang.FunctionalInterface : java.util.function.Function +TOKEN @17:3 +TYPE_ARGUMENTS @17:11 +TOKEN @17:11 +IDENTIFIER @17:12 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @17:12 +TOKEN @17:19 +ARRAY_TYPE @17:21 : int[] +PRIMITIVE_TYPE @17:21 : int +TOKEN @17:21 +TOKEN @17:24 +TOKEN @17:25 +TOKEN @17:26 +IDENTIFIER @17:28 id arrays Lambdas.arrays [v package] : java.util.function.Function : java.util.function.Function +TOKEN @17:28 +TOKEN @17:35 +METHOD_REFERENCE @17:37 : java.util.function.Function +ARRAY_TYPE @17:37 : int[] +PRIMITIVE_TYPE @17:37 : int +TOKEN @17:37 +TOKEN @17:40 +TOKEN @17:41 +TOKEN @17:42 +IDENTIFIER @17:44 id new unknown : ? +TOKEN @17:44 +TOKEN @17:47 +VARIABLE @18:3 var Lambdas.builder [v package] : java.util.function.Supplier + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @18:3 : java.util.function.Supplier +IDENTIFIER @18:3 id Supplier java.util.function.Supplier [t public interface] : java.util.function.Supplier @java.lang.FunctionalInterface : java.util.function.Supplier +TOKEN @18:3 +TYPE_ARGUMENTS @18:11 +TOKEN @18:11 +IDENTIFIER @18:12 id StringBuilder java.lang.StringBuilder [t final public] : java.lang.StringBuilder : java.lang.StringBuilder +TOKEN @18:12 +TOKEN @18:25 +IDENTIFIER @18:27 id builder Lambdas.builder [v package] : java.util.function.Supplier : java.util.function.Supplier +TOKEN @18:27 +TOKEN @18:35 +METHOD_REFERENCE @18:37 : java.util.function.Supplier +IDENTIFIER @18:37 id StringBuilder java.lang.StringBuilder [t final public] : java.lang.StringBuilder : java.lang.StringBuilder +TOKEN @18:37 +TOKEN @18:50 +IDENTIFIER @18:52 id new StringBuilder. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.StringBuilder#()V : void +TOKEN @18:52 +TOKEN @18:55 +VARIABLE @19:3 var Lambdas.sum [v package] : java.util.function.BiFunction + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], [], []] enclosing Lambdas flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @19:3 : java.util.function.BiFunction +IDENTIFIER @19:3 id BiFunction java.util.function.BiFunction [t public interface] : java.util.function.BiFunction @java.lang.FunctionalInterface : java.util.function.BiFunction +TOKEN @19:3 +TYPE_ARGUMENTS @19:13 +TOKEN @19:13 +IDENTIFIER @19:14 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @19:14 +TOKEN @19:21 +IDENTIFIER @19:23 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @19:23 +TOKEN @19:30 +IDENTIFIER @19:32 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @19:32 +TOKEN @19:39 +IDENTIFIER @19:41 id sum Lambdas.sum [v package] : java.util.function.BiFunction : java.util.function.BiFunction +TOKEN @19:41 +TOKEN @19:45 +LAMBDA_EXPRESSION @19:47 : java.util.function.BiFunction +TOKEN @19:47 +VARIABLE @19:48 var apply.x [v package] : java.lang.Integer + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing BiFunction flags [package] local true parameter true effectivelyFinal true constant null owner apply java.util.function.BiFunction#apply(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; [abstract, public] returns java.lang.Integer parameters 2 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing BiFunction type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @19:48 id x apply.x [v package] : java.lang.Integer : java.lang.Integer +TOKEN @19:48 +TOKEN @19:49 +VARIABLE @19:51 var apply.y [v package] : java.lang.Integer + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing BiFunction flags [package] local true parameter true effectivelyFinal true constant null owner apply java.util.function.BiFunction#apply(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; [abstract, public] returns java.lang.Integer parameters 2 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing BiFunction type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @19:51 id y apply.y [v package] : java.lang.Integer : java.lang.Integer +TOKEN @19:51 +TOKEN @19:52 +TOKEN @19:54 +PLUS @19:57 : int +IDENTIFIER @19:57 id x apply.x [v package] : java.lang.Integer : java.lang.Integer +TOKEN @19:57 +TOKEN @19:59 +IDENTIFIER @19:61 id y apply.y [v package] : java.lang.Integer : java.lang.Integer +TOKEN @19:61 +TOKEN @19:62 +VARIABLE @20:3 var Lambdas.typed [v package] : java.util.function.BiFunction + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], [], []] enclosing Lambdas flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @20:3 : java.util.function.BiFunction +IDENTIFIER @20:3 id BiFunction java.util.function.BiFunction [t public interface] : java.util.function.BiFunction @java.lang.FunctionalInterface : java.util.function.BiFunction +TOKEN @20:3 +TYPE_ARGUMENTS @20:13 +TOKEN @20:13 +IDENTIFIER @20:14 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @20:14 +TOKEN @20:21 +IDENTIFIER @20:23 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @20:23 +TOKEN @20:30 +IDENTIFIER @20:32 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @20:32 +TOKEN @20:39 +IDENTIFIER @20:41 id typed Lambdas.typed [v package] : java.util.function.BiFunction : java.util.function.BiFunction +TOKEN @20:41 +TOKEN @20:47 +LAMBDA_EXPRESSION @20:49 : java.util.function.BiFunction +TOKEN @20:49 +VARIABLE @20:50 var apply.x [v package] : java.lang.Integer + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing BiFunction flags [package] local true parameter true effectivelyFinal true constant null owner apply java.util.function.BiFunction#apply(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; [abstract, public] returns java.lang.Integer parameters 2 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing BiFunction type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @20:50 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @20:50 +IDENTIFIER @20:58 id x apply.x [v package] : java.lang.Integer : java.lang.Integer +TOKEN @20:58 +TOKEN @20:59 +VARIABLE @20:61 var apply.y [v package] : java.lang.Integer + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing BiFunction flags [package] local true parameter true effectivelyFinal true constant null owner apply java.util.function.BiFunction#apply(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; [abstract, public] returns java.lang.Integer parameters 2 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing BiFunction type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @20:61 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @20:61 +IDENTIFIER @20:69 id y apply.y [v package] : java.lang.Integer : java.lang.Integer +TOKEN @20:69 +TOKEN @20:70 +TOKEN @20:72 +BLOCK @20:75 +TOKEN @20:75 +RETURN_STATEMENT @21:5 +TOKEN @21:5 +MULTIPLY @21:12 : int +IDENTIFIER @21:12 id x apply.x [v package] : java.lang.Integer : java.lang.Integer +TOKEN @21:12 +TOKEN @21:14 +IDENTIFIER @21:16 id y apply.y [v package] : java.lang.Integer : java.lang.Integer +TOKEN @21:16 +TOKEN @21:17 +TOKEN @22:3 +TOKEN @22:4 +VARIABLE @23:3 var Lambdas.empty [v package] : java.util.function.Predicate + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @23:3 : java.util.function.Predicate +IDENTIFIER @23:3 id Predicate java.util.function.Predicate [t public interface] : java.util.function.Predicate @java.lang.FunctionalInterface : java.util.function.Predicate +TOKEN @23:3 +TYPE_ARGUMENTS @23:12 +TOKEN @23:12 +IDENTIFIER @23:13 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @23:13 +TOKEN @23:19 +IDENTIFIER @23:21 id empty Lambdas.empty [v package] : java.util.function.Predicate : java.util.function.Predicate +TOKEN @23:21 +TOKEN @23:27 +METHOD_REFERENCE @23:29 : java.util.function.Predicate +IDENTIFIER @23:29 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @23:29 +TOKEN @23:35 +IDENTIFIER @23:37 id isEmpty String.isEmpty [m public] : ? () returns boolean throws [] sig java.lang.String#isEmpty()Z : boolean +TOKEN @23:37 +TOKEN @23:44 +VARIABLE @24:3 var Lambdas.notEmpty [v package] : java.util.function.Predicate + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @24:3 : java.util.function.Predicate +IDENTIFIER @24:3 id Predicate java.util.function.Predicate [t public interface] : java.util.function.Predicate @java.lang.FunctionalInterface : java.util.function.Predicate +TOKEN @24:3 +TYPE_ARGUMENTS @24:12 +TOKEN @24:12 +IDENTIFIER @24:13 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @24:13 +TOKEN @24:19 +IDENTIFIER @24:21 id notEmpty Lambdas.notEmpty [v package] : java.util.function.Predicate : java.util.function.Predicate +TOKEN @24:21 +TOKEN @24:30 +METHOD_INVOCATION @24:32 call Predicate.negate [m public] : ? () returns java.util.function.Predicate throws [] sig java.util.function.Predicate#negate()Ljava/util/function/Predicate; : java.util.function.Predicate + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Predicate flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @24:32 : ? +IDENTIFIER @24:32 id empty Lambdas.empty [v package] : java.util.function.Predicate : java.util.function.Predicate +TOKEN @24:32 +TOKEN @24:37 +IDENTIFIER @24:38 id negate Predicate.negate [m public] : ? () returns java.util.function.Predicate throws [] sig java.util.function.Predicate#negate()Ljava/util/function/Predicate; : java.util.function.Predicate +TOKEN @24:38 +ARGUMENTS @24:44 +TOKEN @24:44 +TOKEN @24:45 +TOKEN @24:46 +VARIABLE @25:3 var Lambdas.printer [v package] : java.util.function.Function + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Lambdas flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @25:3 : java.util.function.Function +IDENTIFIER @25:3 id Function java.util.function.Function [t public interface] : java.util.function.Function @java.lang.FunctionalInterface : java.util.function.Function +TOKEN @25:3 +TYPE_ARGUMENTS @25:11 +TOKEN @25:11 +IDENTIFIER @25:12 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @25:12 +TOKEN @25:18 +IDENTIFIER @25:20 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @25:20 +TOKEN @25:26 +IDENTIFIER @25:28 id printer Lambdas.printer [v package] : java.util.function.Function : java.util.function.Function +TOKEN @25:28 +TOKEN @25:36 +METHOD_REFERENCE @25:38 : java.util.function.Function +IDENTIFIER @25:38 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @25:38 +TOKEN @25:44 +IDENTIFIER @25:46 id toString Object.toString [m public] : ? () returns java.lang.String throws [] sig java.lang.Object#toString()Ljava/lang/String; : java.lang.String +TOKEN @25:46 +TOKEN @25:54 +VARIABLE @26:3 var Lambdas.byLength [v package] : java.util.Comparator + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @26:3 : java.util.Comparator +IDENTIFIER @26:3 id Comparator java.util.Comparator [t public interface] : java.util.Comparator @java.lang.FunctionalInterface : java.util.Comparator +TOKEN @26:3 +TYPE_ARGUMENTS @26:13 +TOKEN @26:13 +IDENTIFIER @26:14 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @26:14 +TOKEN @26:20 +IDENTIFIER @26:22 id byLength Lambdas.byLength [v package] : java.util.Comparator : java.util.Comparator +TOKEN @26:22 +TOKEN @26:31 +METHOD_INVOCATION @26:33 call Comparator.comparing [m static public] : ? (java.util.function.Function) returns java.util.Comparator throws [] sig java.util.Comparator#comparing(Ljava/util/function/Function;)Ljava/util/Comparator; : java.util.Comparator + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Comparator flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @26:33 : ? +IDENTIFIER @26:33 id Comparator java.util.Comparator [t public interface] : java.util.Comparator @java.lang.FunctionalInterface : java.util.Comparator +TOKEN @26:33 +TOKEN @26:43 +IDENTIFIER @26:44 id comparing Comparator.comparing [m static public] : ? (java.util.function.Function) returns java.util.Comparator throws [] sig java.util.Comparator#comparing(Ljava/util/function/Function;)Ljava/util/Comparator; : java.util.Comparator +TOKEN @26:44 +ARGUMENTS @26:53 +TOKEN @26:53 +METHOD_REFERENCE @26:54 : java.util.function.Function +IDENTIFIER @26:54 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @26:54 +TOKEN @26:60 +IDENTIFIER @26:62 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @26:62 +TOKEN @26:68 +TOKEN @26:69 +METHOD @28:3 method Lambdas.lengths [m package] : ? (java.util.List) returns java.util.List throws [] sig Lambdas#lengths(Ljava/util/List;)Ljava/util/List; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [words] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS +TYPE_PARAMETERS +PARAMETERIZED_TYPE @28:3 : java.util.List +IDENTIFIER @28:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @28:3 +TYPE_ARGUMENTS @28:7 +TOKEN @28:7 +IDENTIFIER @28:8 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @28:8 +TOKEN @28:15 +IDENTIFIER @28:17 id lengths Lambdas.lengths [m package] : ? (java.util.List) returns java.util.List throws [] sig Lambdas#lengths(Ljava/util/List;)Ljava/util/List; : java.util.List +TOKEN @28:17 +TOKEN @28:24 +VARIABLE @28:25 var lengths.words [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] local true parameter true effectivelyFinal true constant null owner lengths Lambdas#lengths(Ljava/util/List;)Ljava/util/List; [package] returns java.util.List parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Lambdas type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @28:25 : java.util.List +IDENTIFIER @28:25 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @28:25 +TYPE_ARGUMENTS @28:29 +TOKEN @28:29 +IDENTIFIER @28:30 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @28:30 +TOKEN @28:36 +IDENTIFIER @28:38 id words lengths.words [v package] : java.util.List : java.util.List +TOKEN @28:38 +TOKEN @28:43 +BLOCK @28:45 +TOKEN @28:45 +RETURN_STATEMENT @29:5 +TOKEN @29:5 +METHOD_INVOCATION @29:12 call Stream.collect [m abstract public] : ? (java.util.stream.Collector) returns java.util.List throws [] sig java.util.stream.Stream#collect(Ljava/util/stream/Collector;)Ljava/lang/Object; : java.util.List + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @29:12 : ? +METHOD_INVOCATION @29:12 call Stream.filter [m abstract public] : ? (java.util.function.Predicate) returns java.util.stream.Stream throws [] sig java.util.stream.Stream#filter(Ljava/util/function/Predicate;)Ljava/util/stream/Stream; : java.util.stream.Stream + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @29:12 : ? +METHOD_INVOCATION @29:12 call Stream.map [m abstract public] : ? (java.util.function.Function) returns java.util.stream.Stream throws [] sig java.util.stream.Stream#map(Ljava/util/function/Function;)Ljava/util/stream/Stream; : java.util.stream.Stream + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @29:12 : ? +METHOD_INVOCATION @29:12 call Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream + details declared false usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collection flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @29:12 : ? +IDENTIFIER @29:12 id words lengths.words [v package] : java.util.List : java.util.List +TOKEN @29:12 +TOKEN @29:17 +IDENTIFIER @29:18 id stream Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @29:18 +ARGUMENTS @29:24 +TOKEN @29:24 +TOKEN @29:25 +TOKEN @29:26 +IDENTIFIER @29:27 id map Stream.map [m abstract public] : ? (java.util.function.Function) returns java.util.stream.Stream throws [] sig java.util.stream.Stream#map(Ljava/util/function/Function;)Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @29:27 +ARGUMENTS @29:30 +TOKEN @29:30 +LAMBDA_EXPRESSION @29:31 : java.util.function.Function +VARIABLE @29:31 var apply.w [v package] : java.lang.String + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Function flags [package] local true parameter true effectivelyFinal true constant null owner apply java.util.function.Function#apply(Ljava/lang/Object;)Ljava/lang/Object; [abstract, public] returns ? parameters 1 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing Function type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @29:31 id w apply.w [v package] : java.lang.String : java.lang.String +TOKEN @29:31 +TOKEN @29:33 +METHOD_INVOCATION @29:36 call String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int + details declared false usages 5 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [CharSequence.length[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @29:36 : ? +IDENTIFIER @29:36 id w apply.w [v package] : java.lang.String : java.lang.String +TOKEN @29:36 +TOKEN @29:37 +IDENTIFIER @29:38 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @29:38 +ARGUMENTS @29:44 +TOKEN @29:44 +TOKEN @29:45 +TOKEN @29:46 +TOKEN @29:47 +IDENTIFIER @29:48 id filter Stream.filter [m abstract public] : ? (java.util.function.Predicate) returns java.util.stream.Stream throws [] sig java.util.stream.Stream#filter(Ljava/util/function/Predicate;)Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @29:48 +ARGUMENTS @29:54 +TOKEN @29:54 +LAMBDA_EXPRESSION @29:55 : java.util.function.Predicate +VARIABLE @29:55 var test.n [v package] : java.lang.Integer + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Predicate flags [package] local true parameter true effectivelyFinal true constant null owner test java.util.function.Predicate#test(Ljava/lang/Object;)Z [abstract, public] returns boolean parameters 1 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing Predicate type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @29:55 id n test.n [v package] : java.lang.Integer : java.lang.Integer +TOKEN @29:55 +TOKEN @29:57 +GREATER_THAN @29:60 : boolean +IDENTIFIER @29:60 id n test.n [v package] : java.lang.Integer : java.lang.Integer +TOKEN @29:60 +TOKEN @29:62 +INT_LITERAL @29:64 : int = 2 +TOKEN @29:64 +TOKEN @29:65 +TOKEN @29:66 +IDENTIFIER @29:67 id collect Stream.collect [m abstract public] : ? (java.util.stream.Collector) returns java.util.List throws [] sig java.util.stream.Stream#collect(Ljava/util/stream/Collector;)Ljava/lang/Object; : java.util.List +TOKEN @29:67 +ARGUMENTS @29:74 +TOKEN @29:74 +METHOD_INVOCATION @29:75 call Collectors.toList [m static public] : ? () returns java.util.stream.Collector throws [] sig java.util.stream.Collectors#toList()Ljava/util/stream/Collector; : java.util.stream.Collector> + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collectors flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @29:75 : ? +IDENTIFIER @29:75 id Collectors java.util.stream.Collectors [t final public] : java.util.stream.Collectors : java.util.stream.Collectors +TOKEN @29:75 +TOKEN @29:85 +IDENTIFIER @29:86 id toList Collectors.toList [m static public] : ? () returns java.util.stream.Collector throws [] sig java.util.stream.Collectors#toList()Ljava/util/stream/Collector; : java.util.stream.Collector +TOKEN @29:86 +ARGUMENTS @29:92 +TOKEN @29:92 +TOKEN @29:93 +TOKEN @29:94 +TOKEN @29:95 +TOKEN @30:3 +METHOD @32:3 method Lambdas.grouped [m package] : ? (java.util.List) returns java.util.Map> throws [] sig Lambdas#grouped(Ljava/util/List;)Ljava/util/Map; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Lambdas flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [words] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [], [] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS +TYPE_PARAMETERS +PARAMETERIZED_TYPE @32:3 : java.util.Map> +IDENTIFIER @32:3 id Map java.util.Map [t public interface] : java.util.Map> : java.util.Map> +TOKEN @32:3 +TYPE_ARGUMENTS @32:6 +TOKEN @32:6 +IDENTIFIER @32:7 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @32:7 +TOKEN @32:14 +PARAMETERIZED_TYPE @32:16 : java.util.List +IDENTIFIER @32:16 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @32:16 +TYPE_ARGUMENTS @32:20 +TOKEN @32:20 +IDENTIFIER @32:21 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @32:21 +TOKEN @32:27 +TOKEN @32:28 +IDENTIFIER @32:30 id grouped Lambdas.grouped [m package] : ? (java.util.List) returns java.util.Map> throws [] sig Lambdas#grouped(Ljava/util/List;)Ljava/util/Map; : java.util.Map> +TOKEN @32:30 +TOKEN @32:37 +VARIABLE @32:38 var grouped.words [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] local true parameter true effectivelyFinal true constant null owner grouped Lambdas#grouped(Ljava/util/List;)Ljava/util/Map; [package] returns java.util.Map> parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Lambdas type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @32:38 : java.util.List +IDENTIFIER @32:38 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @32:38 +TYPE_ARGUMENTS @32:42 +TOKEN @32:42 +IDENTIFIER @32:43 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @32:43 +TOKEN @32:49 +IDENTIFIER @32:51 id words grouped.words [v package] : java.util.List : java.util.List +TOKEN @32:51 +TOKEN @32:56 +BLOCK @32:58 +TOKEN @32:58 +RETURN_STATEMENT @33:5 +TOKEN @33:5 +METHOD_INVOCATION @33:12 call Stream.collect [m abstract public] : ? (java.util.stream.Collector) returns java.lang.Object throws [] sig java.util.stream.Stream#collect(Ljava/util/stream/Collector;)Ljava/lang/Object; : java.util.Map> + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @33:12 : ? +METHOD_INVOCATION @33:12 call Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream + details declared false usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collection flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @33:12 : ? +IDENTIFIER @33:12 id words grouped.words [v package] : java.util.List : java.util.List +TOKEN @33:12 +TOKEN @33:17 +IDENTIFIER @33:18 id stream Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @33:18 +ARGUMENTS @33:24 +TOKEN @33:24 +TOKEN @33:25 +TOKEN @33:26 +IDENTIFIER @33:27 id collect Stream.collect [m abstract public] : ? (java.util.stream.Collector) returns java.lang.Object throws [] sig java.util.stream.Stream#collect(Ljava/util/stream/Collector;)Ljava/lang/Object; : java.lang.Object +TOKEN @33:27 +ARGUMENTS @33:34 +TOKEN @33:34 +METHOD_INVOCATION @33:35 call Collectors.groupingBy [m static public] : ? (java.util.function.Function) returns java.util.stream.Collector throws [] sig java.util.stream.Collectors#groupingBy(Ljava/util/function/Function;)Ljava/util/stream/Collector; : java.util.stream.Collector + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collectors flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @33:35 : ? +IDENTIFIER @33:35 id Collectors java.util.stream.Collectors [t final public] : java.util.stream.Collectors : java.util.stream.Collectors +TOKEN @33:35 +TOKEN @33:45 +IDENTIFIER @33:46 id groupingBy Collectors.groupingBy [m static public] : ? (java.util.function.Function) returns java.util.stream.Collector throws [] sig java.util.stream.Collectors#groupingBy(Ljava/util/function/Function;)Ljava/util/stream/Collector; : java.util.stream.Collector +TOKEN @33:46 +ARGUMENTS @33:56 +TOKEN @33:56 +METHOD_REFERENCE @33:57 : java.util.function.Function +IDENTIFIER @33:57 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @33:57 +TOKEN @33:63 +IDENTIFIER @33:65 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @33:65 +TOKEN @33:71 +TOKEN @33:72 +TOKEN @33:73 +TOKEN @34:3 +METHOD @36:3 method Lambdas.firstUpper [m package] : ? (java.util.List) returns java.util.Optional throws [] sig Lambdas#firstUpper(Ljava/util/List;)Ljava/util/Optional; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [words] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS +TYPE_PARAMETERS +PARAMETERIZED_TYPE @36:3 : java.util.Optional +IDENTIFIER @36:3 id Optional java.util.Optional [t final public] : java.util.Optional @jdk.internal.ValueBased : java.util.Optional +TOKEN @36:3 +TYPE_ARGUMENTS @36:11 +TOKEN @36:11 +IDENTIFIER @36:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @36:12 +TOKEN @36:18 +IDENTIFIER @36:20 id firstUpper Lambdas.firstUpper [m package] : ? (java.util.List) returns java.util.Optional throws [] sig Lambdas#firstUpper(Ljava/util/List;)Ljava/util/Optional; : java.util.Optional +TOKEN @36:20 +TOKEN @36:30 +VARIABLE @36:31 var firstUpper.words [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] local true parameter true effectivelyFinal true constant null owner firstUpper Lambdas#firstUpper(Ljava/util/List;)Ljava/util/Optional; [package] returns java.util.Optional parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Lambdas type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @36:31 : java.util.List +IDENTIFIER @36:31 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @36:31 +TYPE_ARGUMENTS @36:35 +TOKEN @36:35 +IDENTIFIER @36:36 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @36:36 +TOKEN @36:42 +IDENTIFIER @36:44 id words firstUpper.words [v package] : java.util.List : java.util.List +TOKEN @36:44 +TOKEN @36:49 +BLOCK @36:51 +TOKEN @36:51 +RETURN_STATEMENT @37:5 +TOKEN @37:5 +METHOD_INVOCATION @37:12 call Stream.findFirst [m abstract public] : ? () returns java.util.Optional throws [] sig java.util.stream.Stream#findFirst()Ljava/util/Optional; : java.util.Optional + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @37:12 : ? +METHOD_INVOCATION @37:12 call Stream.map [m abstract public] : ? (java.util.function.Function) returns java.util.stream.Stream throws [] sig java.util.stream.Stream#map(Ljava/util/function/Function;)Ljava/util/stream/Stream; : java.util.stream.Stream + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @37:12 : ? +METHOD_INVOCATION @37:12 call Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream + details declared false usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collection flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @37:12 : ? +IDENTIFIER @37:12 id words firstUpper.words [v package] : java.util.List : java.util.List +TOKEN @37:12 +TOKEN @37:17 +IDENTIFIER @37:18 id stream Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @37:18 +ARGUMENTS @37:24 +TOKEN @37:24 +TOKEN @37:25 +TOKEN @37:26 +IDENTIFIER @37:27 id map Stream.map [m abstract public] : ? (java.util.function.Function) returns java.util.stream.Stream throws [] sig java.util.stream.Stream#map(Ljava/util/function/Function;)Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @37:27 +ARGUMENTS @37:30 +TOKEN @37:30 +METHOD_REFERENCE @37:31 : java.util.function.Function +IDENTIFIER @37:31 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @37:31 +TOKEN @37:37 +IDENTIFIER @37:39 id toUpperCase String.toUpperCase [m public] : ? () returns java.lang.String throws [] sig java.lang.String#toUpperCase()Ljava/lang/String; : java.lang.String +TOKEN @37:39 +TOKEN @37:50 +TOKEN @37:51 +IDENTIFIER @37:52 id findFirst Stream.findFirst [m abstract public] : ? () returns java.util.Optional throws [] sig java.util.stream.Stream#findFirst()Ljava/util/Optional; : java.util.Optional +TOKEN @37:52 +ARGUMENTS @37:61 +TOKEN @37:61 +TOKEN @37:62 +TOKEN @37:63 +TOKEN @38:3 +METHOD @40:3 method Lambdas.total [m package] : ? (java.util.List) returns int throws [] sig Lambdas#total(Ljava/util/List;)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Lambdas flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [words] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @40:3 : int +TOKEN @40:3 +IDENTIFIER @40:7 id total Lambdas.total [m package] : ? (java.util.List) returns int throws [] sig Lambdas#total(Ljava/util/List;)I : int +TOKEN @40:7 +TOKEN @40:12 +VARIABLE @40:13 var total.words [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] local true parameter true effectivelyFinal true constant null owner total Lambdas#total(Ljava/util/List;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Lambdas type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @40:13 : java.util.List +IDENTIFIER @40:13 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @40:13 +TYPE_ARGUMENTS @40:17 +TOKEN @40:17 +IDENTIFIER @40:18 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @40:18 +TOKEN @40:24 +IDENTIFIER @40:26 id words total.words [v package] : java.util.List : java.util.List +TOKEN @40:26 +TOKEN @40:31 +BLOCK @40:33 +TOKEN @40:33 +RETURN_STATEMENT @41:5 +TOKEN @41:5 +METHOD_INVOCATION @41:12 call IntStream.sum [m abstract public] : ? () returns int throws [] sig java.util.stream.IntStream#sum()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing IntStream flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @41:12 : ? +METHOD_INVOCATION @41:12 call Stream.mapToInt [m abstract public] : ? (java.util.function.ToIntFunction) returns java.util.stream.IntStream throws [] sig java.util.stream.Stream#mapToInt(Ljava/util/function/ToIntFunction;)Ljava/util/stream/IntStream; : java.util.stream.IntStream + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @41:12 : ? +METHOD_INVOCATION @41:12 call Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream + details declared false usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collection flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @41:12 : ? +IDENTIFIER @41:12 id words total.words [v package] : java.util.List : java.util.List +TOKEN @41:12 +TOKEN @41:17 +IDENTIFIER @41:18 id stream Collection.stream [m public] : ? () returns java.util.stream.Stream throws [] sig java.util.Collection#stream()Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @41:18 +ARGUMENTS @41:24 +TOKEN @41:24 +TOKEN @41:25 +TOKEN @41:26 +IDENTIFIER @41:27 id mapToInt Stream.mapToInt [m abstract public] : ? (java.util.function.ToIntFunction) returns java.util.stream.IntStream throws [] sig java.util.stream.Stream#mapToInt(Ljava/util/function/ToIntFunction;)Ljava/util/stream/IntStream; : java.util.stream.IntStream +TOKEN @41:27 +ARGUMENTS @41:35 +TOKEN @41:35 +METHOD_REFERENCE @41:36 : java.util.function.ToIntFunction +IDENTIFIER @41:36 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @41:36 +TOKEN @41:42 +IDENTIFIER @41:44 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @41:44 +TOKEN @41:50 +TOKEN @41:51 +IDENTIFIER @41:52 id sum IntStream.sum [m abstract public] : ? () returns int throws [] sig java.util.stream.IntStream#sum()I : int +TOKEN @41:52 +ARGUMENTS @41:55 +TOKEN @41:55 +TOKEN @41:56 +TOKEN @41:57 +TOKEN @42:3 +METHOD @44:3 method Lambdas.capture [m package] : ? (java.lang.String) returns java.util.function.Supplier throws [] sig Lambdas#capture(Ljava/lang/String;)Ljava/util/function/Supplier; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [prefix] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS +TYPE_PARAMETERS +PARAMETERIZED_TYPE @44:3 : java.util.function.Supplier +IDENTIFIER @44:3 id Supplier java.util.function.Supplier [t public interface] : java.util.function.Supplier @java.lang.FunctionalInterface : java.util.function.Supplier +TOKEN @44:3 +TYPE_ARGUMENTS @44:11 +TOKEN @44:11 +IDENTIFIER @44:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @44:12 +TOKEN @44:18 +IDENTIFIER @44:20 id capture Lambdas.capture [m package] : ? (java.lang.String) returns java.util.function.Supplier throws [] sig Lambdas#capture(Ljava/lang/String;)Ljava/util/function/Supplier; : java.util.function.Supplier +TOKEN @44:20 +TOKEN @44:27 +VARIABLE @44:28 var capture.prefix [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Lambdas flags [package] local true parameter true effectivelyFinal true constant null owner capture Lambdas#capture(Ljava/lang/String;)Ljava/util/function/Supplier; [package] returns java.util.function.Supplier parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Lambdas type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @44:28 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @44:28 +IDENTIFIER @44:35 id prefix capture.prefix [v package] : java.lang.String : java.lang.String +TOKEN @44:35 +TOKEN @44:41 +BLOCK @44:43 +TOKEN @44:43 +VARIABLE @45:5 var capture.count [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Lambdas flags [package] local true parameter false effectivelyFinal true constant null owner capture Lambdas#capture(Ljava/lang/String;)Ljava/util/function/Supplier; [package] returns java.util.function.Supplier parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Lambdas type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @45:5 : int +TOKEN @45:5 +IDENTIFIER @45:9 id count capture.count [v package] : int : int +TOKEN @45:9 +TOKEN @45:15 +INT_LITERAL @45:17 : int = 3 +TOKEN @45:17 +TOKEN @45:18 +RETURN_STATEMENT @46:5 +TOKEN @46:5 +LAMBDA_EXPRESSION @46:12 : java.util.function.Supplier +TOKEN @46:12 +TOKEN @46:13 +TOKEN @46:15 +PLUS @46:18 : java.lang.String +PLUS @46:18 : java.lang.String +IDENTIFIER @46:18 id prefix capture.prefix [v package] : java.lang.String : java.lang.String +TOKEN @46:18 +TOKEN @46:25 +IDENTIFIER @46:27 id count capture.count [v package] : int : int +TOKEN @46:27 +TOKEN @46:33 +METHOD_INVOCATION @46:35 call Object.hashCode [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns int throws [] sig java.lang.Object#hashCode()I : int + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @46:35 : ? +IDENTIFIER @46:35 id this Lambdas.this [v final] : Lambdas : Lambdas +TOKEN @46:35 +TOKEN @46:39 +IDENTIFIER @46:40 id hashCode Object.hashCode [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns int throws [] sig java.lang.Object#hashCode()I : int +TOKEN @46:40 +ARGUMENTS @46:48 +TOKEN @46:48 +TOKEN @46:49 +TOKEN @46:50 +TOKEN @47:3 +METHOD @49:3 method Lambdas.sort [m package] : ? (java.util.List) returns void throws [] sig Lambdas#sort(Ljava/util/List;)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Lambdas flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [words] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @49:3 : void +TOKEN @49:3 +IDENTIFIER @49:8 id sort Lambdas.sort [m package] : ? (java.util.List) returns void throws [] sig Lambdas#sort(Ljava/util/List;)V : void +TOKEN @49:8 +TOKEN @49:12 +VARIABLE @49:13 var sort.words [v package] : java.util.List + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Lambdas flags [package] local true parameter true effectivelyFinal true constant null owner sort Lambdas#sort(Ljava/util/List;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Lambdas type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @49:13 : java.util.List +IDENTIFIER @49:13 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @49:13 +TYPE_ARGUMENTS @49:17 +TOKEN @49:17 +IDENTIFIER @49:18 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @49:18 +TOKEN @49:24 +IDENTIFIER @49:26 id words sort.words [v package] : java.util.List : java.util.List +TOKEN @49:26 +TOKEN @49:31 +BLOCK @49:33 +TOKEN @49:33 +EXPRESSION_STATEMENT @50:5 +METHOD_INVOCATION @50:5 call List.sort [m public] : ? (java.util.Comparator) returns void throws [] sig java.util.List#sort(Ljava/util/Comparator;)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @50:5 : ? +IDENTIFIER @50:5 id words sort.words [v package] : java.util.List : java.util.List +TOKEN @50:5 +TOKEN @50:10 +IDENTIFIER @50:11 id sort List.sort [m public] : ? (java.util.Comparator) returns void throws [] sig java.util.List#sort(Ljava/util/Comparator;)V : void +TOKEN @50:11 +ARGUMENTS @50:15 +TOKEN @50:15 +LAMBDA_EXPRESSION @50:16 : java.util.Comparator +TOKEN @50:16 +VARIABLE @50:17 var compare.a [v package] : java.lang.String + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Comparator flags [package] local true parameter true effectivelyFinal true constant null owner compare java.util.Comparator#compare(Ljava/lang/Object;Ljava/lang/Object;)I [abstract, public] returns int parameters 2 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing Comparator type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @50:17 id a compare.a [v package] : java.lang.String : java.lang.String +TOKEN @50:17 +TOKEN @50:18 +VARIABLE @50:20 var compare.b [v package] : java.lang.String + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Comparator flags [package] local true parameter true effectivelyFinal true constant null owner compare java.util.Comparator#compare(Ljava/lang/Object;Ljava/lang/Object;)I [abstract, public] returns int parameters 2 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing Comparator type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @50:20 id b compare.b [v package] : java.lang.String : java.lang.String +TOKEN @50:20 +TOKEN @50:21 +TOKEN @50:23 +METHOD_INVOCATION @50:26 call String.compareToIgnoreCase [m public] : ? (java.lang.String) returns int throws [] sig java.lang.String#compareToIgnoreCase(Ljava/lang/String;)I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @50:26 : ? +IDENTIFIER @50:26 id a compare.a [v package] : java.lang.String : java.lang.String +TOKEN @50:26 +TOKEN @50:27 +IDENTIFIER @50:28 id compareToIgnoreCase String.compareToIgnoreCase [m public] : ? (java.lang.String) returns int throws [] sig java.lang.String#compareToIgnoreCase(Ljava/lang/String;)I : int +TOKEN @50:28 +ARGUMENTS @50:47 +TOKEN @50:47 +IDENTIFIER @50:48 id b compare.b [v package] : java.lang.String : java.lang.String +TOKEN @50:48 +TOKEN @50:49 +TOKEN @50:50 +TOKEN @50:51 +EXPRESSION_STATEMENT @51:5 +METHOD_INVOCATION @51:5 call Iterable.forEach [m public] : ? (java.util.function.Consumer) returns void throws [] sig java.lang.Iterable#forEach(Ljava/util/function/Consumer;)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Iterable flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @51:5 : ? +IDENTIFIER @51:5 id words sort.words [v package] : java.util.List : java.util.List +TOKEN @51:5 +TOKEN @51:10 +IDENTIFIER @51:11 id forEach Iterable.forEach [m public] : ? (java.util.function.Consumer) returns void throws [] sig java.lang.Iterable#forEach(Ljava/util/function/Consumer;)V : void +TOKEN @51:11 +ARGUMENTS @51:18 +TOKEN @51:18 +METHOD_REFERENCE @51:19 : java.util.function.Consumer +MEMBER_SELECT @51:19 : java.io.PrintStream +IDENTIFIER @51:19 id System java.lang.System [t final public] : java.lang.System : java.lang.System +TOKEN @51:19 +TOKEN @51:25 +IDENTIFIER @51:26 id out System.out [v static final public] : java.io.PrintStream : java.io.PrintStream +TOKEN @51:26 +TOKEN @51:29 +IDENTIFIER @51:31 id println PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void +TOKEN @51:31 +TOKEN @51:38 +TOKEN @51:39 +EXPRESSION_STATEMENT @52:5 +METHOD_INVOCATION @52:5 call Collection.removeIf [m public] : ? (java.util.function.Predicate) returns boolean throws [] sig java.util.Collection#removeIf(Ljava/util/function/Predicate;)Z : boolean + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Collection flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @52:5 : ? +IDENTIFIER @52:5 id words sort.words [v package] : java.util.List : java.util.List +TOKEN @52:5 +TOKEN @52:10 +IDENTIFIER @52:11 id removeIf Collection.removeIf [m public] : ? (java.util.function.Predicate) returns boolean throws [] sig java.util.Collection#removeIf(Ljava/util/function/Predicate;)Z : boolean +TOKEN @52:11 +ARGUMENTS @52:19 +TOKEN @52:19 +LAMBDA_EXPRESSION @52:20 : java.util.function.Predicate +VARIABLE @52:20 var test.word [v package] : java.lang.String + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Predicate flags [package] local true parameter true effectivelyFinal true constant null owner test java.util.function.Predicate#test(Ljava/lang/Object;)Z [abstract, public] returns boolean parameters 1 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing Predicate type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @52:20 id word test.word [v package] : java.lang.String : java.lang.String +TOKEN @52:20 +TOKEN @52:25 +METHOD_INVOCATION @52:28 call String.startsWith [m public] : ? (java.lang.String) returns boolean throws [] sig java.lang.String#startsWith(Ljava/lang/String;)Z : boolean + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @52:28 : ? +IDENTIFIER @52:28 id word test.word [v package] : java.lang.String : java.lang.String +TOKEN @52:28 +TOKEN @52:32 +IDENTIFIER @52:33 id startsWith String.startsWith [m public] : ? (java.lang.String) returns boolean throws [] sig java.lang.String#startsWith(Ljava/lang/String;)Z : boolean +TOKEN @52:33 +ARGUMENTS @52:43 +TOKEN @52:43 +STRING_LITERAL @52:44 : java.lang.String = x +TOKEN @52:44 +TOKEN @52:47 +TOKEN @52:48 +TOKEN @52:49 +TOKEN @53:3 +TOKEN @54:1 +TOKEN @55:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Lambdas.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Lambdas.java new file mode 100644 index 00000000000..5841ef01c30 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Lambdas.java @@ -0,0 +1,54 @@ +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +class Lambdas { + + Runnable runnable = () -> { + }; + Supplier supplier = () -> "value"; + Function length = String::length; + Function arrays = int[]::new; + Supplier builder = StringBuilder::new; + BiFunction sum = (x, y) -> x + y; + BiFunction typed = (Integer x, Integer y) -> { + return x * y; + }; + Predicate empty = String::isEmpty; + Predicate notEmpty = empty.negate(); + Function printer = Object::toString; + Comparator byLength = Comparator.comparing(String::length); + + List lengths(List words) { + return words.stream().map(w -> w.length()).filter(n -> n > 2).collect(Collectors.toList()); + } + + Map> grouped(List words) { + return words.stream().collect(Collectors.groupingBy(String::length)); + } + + Optional firstUpper(List words) { + return words.stream().map(String::toUpperCase).findFirst(); + } + + int total(List words) { + return words.stream().mapToInt(String::length).sum(); + } + + Supplier capture(String prefix) { + int count = 3; + return () -> prefix + count + this.hashCode(); + } + + void sort(List words) { + words.sort((a, b) -> a.compareToIgnoreCase(b)); + words.forEach(System.out::println); + words.removeIf(word -> word.startsWith("x")); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Lambdas.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Lambdas.textproto.gz new file mode 100644 index 00000000000..b27b6d1879e Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Lambdas.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Overloads.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Overloads.expected.txt new file mode 100644 index 00000000000..d7912163092 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Overloads.expected.txt @@ -0,0 +1,687 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id util unknown : ? +TOKEN @1:13 +TOKEN @1:17 +IDENTIFIER @1:18 id List unknown : ? +TOKEN @1:18 +TOKEN @1:22 +CLASS @3:1 class .Overloads [t package] : Overloads super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] members [, call, call, call, call, call, call, call, call, call, calls] lookupToString 0 outermost Overloads annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Overloads +MODIFIERS +TOKEN @3:1 +IDENTIFIER @3:7 id Overloads .Overloads [t package] : Overloads : Overloads +TOKEN @3:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @3:17 +METHOD @5:3 method Overloads.call [m package] : ? (int) returns void throws [] sig Overloads#call(I)V overrides false + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @5:3 : void +TOKEN @5:3 +IDENTIFIER @5:8 id call Overloads.call [m package] : ? (int) returns void throws [] sig Overloads#call(I)V : void +TOKEN @5:8 +TOKEN @5:12 +VARIABLE @5:13 var call.value [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] local true parameter true effectivelyFinal true constant null owner call Overloads#call(I)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 3 metadata 0 enclosing Overloads type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @5:13 : int +TOKEN @5:13 +IDENTIFIER @5:17 id value call.value [v package] : int : int +TOKEN @5:17 +TOKEN @5:22 +BLOCK @5:24 +TOKEN @5:24 +TOKEN @6:3 +METHOD @8:3 method Overloads.call [m package] : ? (long) returns void throws [] sig Overloads#call(J)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @8:3 : void +TOKEN @8:3 +IDENTIFIER @8:8 id call Overloads.call [m package] : ? (long) returns void throws [] sig Overloads#call(J)V : void +TOKEN @8:8 +TOKEN @8:12 +VARIABLE @8:13 var call.value [v package] : long + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] local true parameter true effectivelyFinal true constant null owner call Overloads#call(J)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Overloads type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @8:13 : long +TOKEN @8:13 +IDENTIFIER @8:18 id value call.value [v package] : long : long +TOKEN @8:18 +TOKEN @8:23 +BLOCK @8:25 +TOKEN @8:25 +TOKEN @9:3 +METHOD @11:3 method Overloads.call [m package] : ? (double) returns void throws [] sig Overloads#call(D)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @11:3 : void +TOKEN @11:3 +IDENTIFIER @11:8 id call Overloads.call [m package] : ? (double) returns void throws [] sig Overloads#call(D)V : void +TOKEN @11:8 +TOKEN @11:12 +VARIABLE @11:13 var call.value [v package] : double + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] local true parameter true effectivelyFinal true constant null owner call Overloads#call(D)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Overloads type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @11:13 : double +TOKEN @11:13 +IDENTIFIER @11:20 id value call.value [v package] : double : double +TOKEN @11:20 +TOKEN @11:25 +BLOCK @11:27 +TOKEN @11:27 +TOKEN @12:3 +METHOD @14:3 method Overloads.call [m package] : ? (java.lang.Integer) returns void throws [] sig Overloads#call(Ljava/lang/Integer;)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @14:3 : void +TOKEN @14:3 +IDENTIFIER @14:8 id call Overloads.call [m package] : ? (java.lang.Integer) returns void throws [] sig Overloads#call(Ljava/lang/Integer;)V : void +TOKEN @14:8 +TOKEN @14:12 +VARIABLE @14:13 var call.value [v package] : java.lang.Integer + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] local true parameter true effectivelyFinal true constant null owner call Overloads#call(Ljava/lang/Integer;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Overloads type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @14:13 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @14:13 +IDENTIFIER @14:21 id value call.value [v package] : java.lang.Integer : java.lang.Integer +TOKEN @14:21 +TOKEN @14:26 +BLOCK @14:28 +TOKEN @14:28 +TOKEN @15:3 +METHOD @17:3 method Overloads.call [m package] : ? (java.lang.Object) returns void throws [] sig Overloads#call(Ljava/lang/Object;)V overrides false + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @17:3 : void +TOKEN @17:3 +IDENTIFIER @17:8 id call Overloads.call [m package] : ? (java.lang.Object) returns void throws [] sig Overloads#call(Ljava/lang/Object;)V : void +TOKEN @17:8 +TOKEN @17:12 +VARIABLE @17:13 var call.value [v package] : java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] local true parameter true effectivelyFinal true constant null owner call Overloads#call(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 2 metadata 0 enclosing Overloads type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @17:13 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @17:13 +IDENTIFIER @17:20 id value call.value [v package] : java.lang.Object : java.lang.Object +TOKEN @17:20 +TOKEN @17:25 +BLOCK @17:27 +TOKEN @17:27 +TOKEN @18:3 +METHOD @20:3 method Overloads.call [m package] : ? (java.lang.String) returns void throws [] sig Overloads#call(Ljava/lang/String;)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @20:3 : void +TOKEN @20:3 +IDENTIFIER @20:8 id call Overloads.call [m package] : ? (java.lang.String) returns void throws [] sig Overloads#call(Ljava/lang/String;)V : void +TOKEN @20:8 +TOKEN @20:12 +VARIABLE @20:13 var call.value [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] local true parameter true effectivelyFinal true constant null owner call Overloads#call(Ljava/lang/String;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Overloads type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @20:13 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @20:13 +IDENTIFIER @20:20 id value call.value [v package] : java.lang.String : java.lang.String +TOKEN @20:20 +TOKEN @20:25 +BLOCK @20:27 +TOKEN @20:27 +TOKEN @21:3 +METHOD @23:3 method Overloads.call [m package] : ? (java.lang.String,java.lang.Object[]) returns void throws [] sig Overloads#call(Ljava/lang/String;[Ljava/lang/Object;)V overrides false + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs true native false parameters [first, rest] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @23:3 : void +TOKEN @23:3 +IDENTIFIER @23:8 id call Overloads.call [m package] : ? (java.lang.String,java.lang.Object[]) returns void throws [] sig Overloads#call(Ljava/lang/String;[Ljava/lang/Object;)V : void +TOKEN @23:8 +TOKEN @23:12 +VARIABLE @23:13 var call.first [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] local true parameter true effectivelyFinal true constant null owner call Overloads#call(Ljava/lang/String;[Ljava/lang/Object;)V [package] returns void parameters 2 thrown 0 overridden 0 declared true usages 3 metadata 0 enclosing Overloads type true kinds truefalsefalse other falsefalsetruefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @23:13 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @23:13 +IDENTIFIER @23:20 id first call.first [v package] : java.lang.String : java.lang.String +TOKEN @23:20 +TOKEN @23:25 +VARIABLE @23:27 var call.rest [v package] : java.lang.Object[] + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] local true parameter true effectivelyFinal true constant null owner call Overloads#call(Ljava/lang/String;[Ljava/lang/Object;)V [package] returns void parameters 2 thrown 0 overridden 0 declared true usages 3 metadata 0 enclosing Overloads type true kinds truefalsefalse other falsefalsetruefalsetruefalse2falsefalse +MODIFIERS +ARRAY_TYPE @23:27 : java.lang.Object[] +IDENTIFIER @23:27 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @23:27 +TOKEN @23:33 +IDENTIFIER @23:37 id rest call.rest [v package] : java.lang.Object[] : java.lang.Object[] +TOKEN @23:37 +TOKEN @23:41 +BLOCK @23:43 +TOKEN @23:43 +TOKEN @24:3 +METHOD @26:3 method Overloads.call [m package] : ? (int,int) returns void throws [] sig Overloads#call(II)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [first, second] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @26:3 : void +TOKEN @26:3 +IDENTIFIER @26:8 id call Overloads.call [m package] : ? (int,int) returns void throws [] sig Overloads#call(II)V : void +TOKEN @26:8 +TOKEN @26:12 +VARIABLE @26:13 var call.first [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] local true parameter true effectivelyFinal true constant null owner call Overloads#call(II)V [package] returns void parameters 2 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Overloads type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @26:13 : int +TOKEN @26:13 +IDENTIFIER @26:17 id first call.first [v package] : int : int +TOKEN @26:17 +TOKEN @26:22 +VARIABLE @26:24 var call.second [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] local true parameter true effectivelyFinal true constant null owner call Overloads#call(II)V [package] returns void parameters 2 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Overloads type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @26:24 : int +TOKEN @26:24 +IDENTIFIER @26:28 id second call.second [v package] : int : int +TOKEN @26:28 +TOKEN @26:34 +BLOCK @26:36 +TOKEN @26:36 +TOKEN @27:3 +METHOD @29:3 method Overloads.call [m package] : ? (java.util.List) returns void throws [] sig Overloads#call(Ljava/util/List;)V overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [values] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @29:3 : void +TOKEN @29:3 +IDENTIFIER @29:8 id call Overloads.call [m package] : ? (java.util.List) returns void throws [] sig Overloads#call(Ljava/util/List;)V : void +TOKEN @29:8 +TOKEN @29:12 +VARIABLE @29:13 var call.values [v package] : java.util.List + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Overloads flags [package] local true parameter true effectivelyFinal true constant null owner call Overloads#call(Ljava/util/List;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing Overloads type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @29:13 : java.util.List +IDENTIFIER @29:13 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @29:13 +TYPE_ARGUMENTS @29:17 +TOKEN @29:17 +IDENTIFIER @29:18 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @29:18 +TOKEN @29:24 +IDENTIFIER @29:26 id values call.values [v package] : java.util.List : java.util.List +TOKEN @29:26 +TOKEN @29:32 +BLOCK @29:34 +TOKEN @29:34 +TOKEN @30:3 +METHOD @32:3 method Overloads.calls [m package] : ? () returns void throws [] sig Overloads#calls()V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @32:3 : void +TOKEN @32:3 +IDENTIFIER @32:8 id calls Overloads.calls [m package] : ? () returns void throws [] sig Overloads#calls()V : void +TOKEN @32:8 +TOKEN @32:13 +TOKEN @32:14 +BLOCK @32:16 +TOKEN @32:16 +EXPRESSION_STATEMENT @33:5 +METHOD_INVOCATION @33:5 call Overloads.call [m package] : ? (int) returns void throws [] sig Overloads#call(I)V : void + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @33:5 id call Overloads.call [m package] : ? (int) returns void throws [] sig Overloads#call(I)V : void +TOKEN @33:5 +ARGUMENTS @33:9 +TOKEN @33:9 +INT_LITERAL @33:10 : int = 1 +TOKEN @33:10 +TOKEN @33:11 +TOKEN @33:12 +EXPRESSION_STATEMENT @34:5 +METHOD_INVOCATION @34:5 call Overloads.call [m package] : ? (long) returns void throws [] sig Overloads#call(J)V : void + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @34:5 id call Overloads.call [m package] : ? (long) returns void throws [] sig Overloads#call(J)V : void +TOKEN @34:5 +ARGUMENTS @34:9 +TOKEN @34:9 +LONG_LITERAL @34:10 : long = 1 +TOKEN @34:10 +TOKEN @34:12 +TOKEN @34:13 +EXPRESSION_STATEMENT @35:5 +METHOD_INVOCATION @35:5 call Overloads.call [m package] : ? (double) returns void throws [] sig Overloads#call(D)V : void + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @35:5 id call Overloads.call [m package] : ? (double) returns void throws [] sig Overloads#call(D)V : void +TOKEN @35:5 +ARGUMENTS @35:9 +TOKEN @35:9 +FLOAT_LITERAL @35:10 : float +TOKEN @35:10 +TOKEN @35:14 +TOKEN @35:15 +EXPRESSION_STATEMENT @36:5 +METHOD_INVOCATION @36:5 call Overloads.call [m package] : ? (int) returns void throws [] sig Overloads#call(I)V : void + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @36:5 id call Overloads.call [m package] : ? (int) returns void throws [] sig Overloads#call(I)V : void +TOKEN @36:5 +ARGUMENTS @36:9 +TOKEN @36:9 +CHAR_LITERAL @36:10 : char = 99 +TOKEN @36:10 +TOKEN @36:13 +TOKEN @36:14 +EXPRESSION_STATEMENT @37:5 +METHOD_INVOCATION @37:5 call Overloads.call [m package] : ? (int) returns void throws [] sig Overloads#call(I)V : void + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @37:5 id call Overloads.call [m package] : ? (int) returns void throws [] sig Overloads#call(I)V : void +TOKEN @37:5 +ARGUMENTS @37:9 +TOKEN @37:9 +TYPE_CAST @37:10 : short +TOKEN @37:10 +PRIMITIVE_TYPE @37:11 : short +TOKEN @37:11 +LIST +TOKEN @37:16 +INT_LITERAL @37:18 : int = 2 +TOKEN @37:18 +TOKEN @37:19 +TOKEN @37:20 +EXPRESSION_STATEMENT @38:5 +METHOD_INVOCATION @38:5 call Overloads.call [m package] : ? (java.lang.Integer) returns void throws [] sig Overloads#call(Ljava/lang/Integer;)V : void + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @38:5 id call Overloads.call [m package] : ? (java.lang.Integer) returns void throws [] sig Overloads#call(Ljava/lang/Integer;)V : void +TOKEN @38:5 +ARGUMENTS @38:9 +TOKEN @38:9 +METHOD_INVOCATION @38:10 call Integer.valueOf [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int) returns java.lang.Integer throws [] sig java.lang.Integer#valueOf(I)Ljava/lang/Integer; : java.lang.Integer + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Integer flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @38:10 : ? +IDENTIFIER @38:10 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @38:10 +TOKEN @38:17 +IDENTIFIER @38:18 id valueOf Integer.valueOf [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int) returns java.lang.Integer throws [] sig java.lang.Integer#valueOf(I)Ljava/lang/Integer; : java.lang.Integer +TOKEN @38:18 +ARGUMENTS @38:25 +TOKEN @38:25 +INT_LITERAL @38:26 : int = 3 +TOKEN @38:26 +TOKEN @38:27 +TOKEN @38:28 +TOKEN @38:29 +EXPRESSION_STATEMENT @39:5 +METHOD_INVOCATION @39:5 call Overloads.call [m package] : ? (java.lang.String) returns void throws [] sig Overloads#call(Ljava/lang/String;)V : void + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @39:5 id call Overloads.call [m package] : ? (java.lang.String) returns void throws [] sig Overloads#call(Ljava/lang/String;)V : void +TOKEN @39:5 +ARGUMENTS @39:9 +TOKEN @39:9 +STRING_LITERAL @39:10 : java.lang.String = text +TOKEN @39:10 +TOKEN @39:16 +TOKEN @39:17 +EXPRESSION_STATEMENT @40:5 +METHOD_INVOCATION @40:5 call Overloads.call [m package] : ? (java.lang.Object) returns void throws [] sig Overloads#call(Ljava/lang/Object;)V : void + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @40:5 id call Overloads.call [m package] : ? (java.lang.Object) returns void throws [] sig Overloads#call(Ljava/lang/Object;)V : void +TOKEN @40:5 +ARGUMENTS @40:9 +TOKEN @40:9 +NEW_CLASS @40:10 new Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : java.lang.Object + details declared false usages 2 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @40:10 +IDENTIFIER @40:14 id Object Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : java.lang.Object +TOKEN @40:14 +ARGUMENTS @40:20 +TOKEN @40:20 +TOKEN @40:21 +TOKEN @40:22 +TOKEN @40:23 +EXPRESSION_STATEMENT @41:5 +METHOD_INVOCATION @41:5 call Overloads.call [m package] : ? (java.lang.String,java.lang.Object[]) returns void throws [] sig Overloads#call(Ljava/lang/String;[Ljava/lang/Object;)V : void + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs true native false parameters [first, rest] parameterMetadata [] +IDENTIFIER @41:5 id call Overloads.call [m package] : ? (java.lang.String,java.lang.Object[]) returns void throws [] sig Overloads#call(Ljava/lang/String;[Ljava/lang/Object;)V : void +TOKEN @41:5 +ARGUMENTS @41:9 +TOKEN @41:9 +STRING_LITERAL @41:10 : java.lang.String = a +TOKEN @41:10 +TOKEN @41:13 +INT_LITERAL @41:15 : int = 1 +TOKEN @41:15 +TOKEN @41:16 +INT_LITERAL @41:18 : int = 2 +TOKEN @41:18 +TOKEN @41:19 +TOKEN @41:20 +EXPRESSION_STATEMENT @42:5 +METHOD_INVOCATION @42:5 call Overloads.call [m package] : ? (java.lang.String,java.lang.Object[]) returns void throws [] sig Overloads#call(Ljava/lang/String;[Ljava/lang/Object;)V : void + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs true native false parameters [first, rest] parameterMetadata [] +IDENTIFIER @42:5 id call Overloads.call [m package] : ? (java.lang.String,java.lang.Object[]) returns void throws [] sig Overloads#call(Ljava/lang/String;[Ljava/lang/Object;)V : void +TOKEN @42:5 +ARGUMENTS @42:9 +TOKEN @42:9 +STRING_LITERAL @42:10 : java.lang.String = a +TOKEN @42:10 +TOKEN @42:13 +STRING_LITERAL @42:15 : java.lang.String = b +TOKEN @42:15 +TOKEN @42:18 +TOKEN @42:19 +EXPRESSION_STATEMENT @43:5 +METHOD_INVOCATION @43:5 call Overloads.call [m package] : ? (int,int) returns void throws [] sig Overloads#call(II)V : void + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [first, second] parameterMetadata [] +IDENTIFIER @43:5 id call Overloads.call [m package] : ? (int,int) returns void throws [] sig Overloads#call(II)V : void +TOKEN @43:5 +ARGUMENTS @43:9 +TOKEN @43:9 +INT_LITERAL @43:10 : int = 1 +TOKEN @43:10 +TOKEN @43:11 +INT_LITERAL @43:13 : int = 2 +TOKEN @43:13 +TOKEN @43:14 +TOKEN @43:15 +EXPRESSION_STATEMENT @44:5 +METHOD_INVOCATION @44:5 call Overloads.call [m package] : ? (java.util.List) returns void throws [] sig Overloads#call(Ljava/util/List;)V : void + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [values] parameterMetadata [] +IDENTIFIER @44:5 id call Overloads.call [m package] : ? (java.util.List) returns void throws [] sig Overloads#call(Ljava/util/List;)V : void +TOKEN @44:5 +ARGUMENTS @44:9 +TOKEN @44:9 +METHOD_INVOCATION @44:10 call List.of [m static public] : ? (java.lang.String) returns java.util.List throws [] sig java.util.List#of(Ljava/lang/Object;)Ljava/util/List; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @44:10 : ? +IDENTIFIER @44:10 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @44:10 +TOKEN @44:14 +IDENTIFIER @44:15 id of List.of [m static public] : ? (java.lang.String) returns java.util.List throws [] sig java.util.List#of(Ljava/lang/Object;)Ljava/util/List; : java.util.List +TOKEN @44:15 +ARGUMENTS @44:17 +TOKEN @44:17 +STRING_LITERAL @44:18 : java.lang.String = x +TOKEN @44:18 +TOKEN @44:21 +TOKEN @44:22 +TOKEN @44:23 +EXPRESSION_STATEMENT @45:5 +METHOD_INVOCATION @45:5 call Overloads.call [m package] : ? (java.lang.Object) returns void throws [] sig Overloads#call(Ljava/lang/Object;)V : void + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +IDENTIFIER @45:5 id call Overloads.call [m package] : ? (java.lang.Object) returns void throws [] sig Overloads#call(Ljava/lang/Object;)V : void +TOKEN @45:5 +ARGUMENTS @45:9 +TOKEN @45:9 +TYPE_CAST @45:10 : java.lang.Object +TOKEN @45:10 +IDENTIFIER @45:11 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @45:11 +LIST +TOKEN @45:17 +STRING_LITERAL @45:19 : java.lang.String = cast +TOKEN @45:19 +TOKEN @45:25 +TOKEN @45:26 +EXPRESSION_STATEMENT @46:5 +METHOD_INVOCATION @46:5 call Overloads.call [m package] : ? (java.lang.String,java.lang.Object[]) returns void throws [] sig Overloads#call(Ljava/lang/String;[Ljava/lang/Object;)V : void + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] overridden [] overridable true generic false default false synchronized false varargs true native false parameters [first, rest] parameterMetadata [] +IDENTIFIER @46:5 id call Overloads.call [m package] : ? (java.lang.String,java.lang.Object[]) returns void throws [] sig Overloads#call(Ljava/lang/String;[Ljava/lang/Object;)V : void +TOKEN @46:5 +ARGUMENTS @46:9 +TOKEN @46:9 +NULL_LITERAL @46:10 : +TOKEN @46:10 +TOKEN @46:14 +NULL_LITERAL @46:16 : +TOKEN @46:16 +TOKEN @46:20 +TOKEN @46:21 +VARIABLE @47:5 var calls.builder [v package] : java.lang.StringBuilder + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Overloads flags [package] local true parameter false effectivelyFinal true constant null owner calls Overloads#calls()V [package] returns void parameters 0 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Overloads type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @47:5 id StringBuilder java.lang.StringBuilder [t final public] : java.lang.StringBuilder : java.lang.StringBuilder +TOKEN @47:5 +IDENTIFIER @47:19 id builder calls.builder [v package] : java.lang.StringBuilder : java.lang.StringBuilder +TOKEN @47:19 +TOKEN @47:27 +NEW_CLASS @47:29 new StringBuilder. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.StringBuilder#()V : java.lang.StringBuilder + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing StringBuilder flags [public] overridden [AbstractStringBuilder.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @47:29 +IDENTIFIER @47:33 id StringBuilder StringBuilder. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.StringBuilder#()V : java.lang.StringBuilder +TOKEN @47:33 +ARGUMENTS @47:46 +TOKEN @47:46 +TOKEN @47:47 +TOKEN @47:48 +EXPRESSION_STATEMENT @48:5 +METHOD_INVOCATION @48:5 call StringBuilder.append [m public] : ? (char[]) returns java.lang.StringBuilder throws [] sig java.lang.StringBuilder#append([C)Ljava/lang/StringBuilder; : java.lang.StringBuilder + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StringBuilder flags [public] overridden [AbstractStringBuilder.append[]] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @48:5 : ? +METHOD_INVOCATION @48:5 call StringBuilder.append [m public] : ? (boolean) returns java.lang.StringBuilder throws [] sig java.lang.StringBuilder#append(Z)Ljava/lang/StringBuilder; : java.lang.StringBuilder + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StringBuilder flags [public] overridden [AbstractStringBuilder.append[]] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @48:5 : ? +METHOD_INVOCATION @48:5 call StringBuilder.append [m public] : ? (double) returns java.lang.StringBuilder throws [] sig java.lang.StringBuilder#append(D)Ljava/lang/StringBuilder; : java.lang.StringBuilder + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StringBuilder flags [public] overridden [AbstractStringBuilder.append[]] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @48:5 : ? +METHOD_INVOCATION @48:5 call StringBuilder.append [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (java.lang.String) returns java.lang.StringBuilder throws [] sig java.lang.StringBuilder#append(Ljava/lang/String;)Ljava/lang/StringBuilder; : java.lang.StringBuilder + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing StringBuilder flags [public] overridden [AbstractStringBuilder.append[]] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @48:5 : ? +METHOD_INVOCATION @48:5 call StringBuilder.append [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (char) returns java.lang.StringBuilder throws [] sig java.lang.StringBuilder#append(C)Ljava/lang/StringBuilder; : java.lang.StringBuilder + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing StringBuilder flags [public] overridden [AbstractStringBuilder.append[], Appendable.append[]] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @48:5 : ? +METHOD_INVOCATION @48:5 call StringBuilder.append [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int) returns java.lang.StringBuilder throws [] sig java.lang.StringBuilder#append(I)Ljava/lang/StringBuilder; : java.lang.StringBuilder + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing StringBuilder flags [public] overridden [AbstractStringBuilder.append[]] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @48:5 : ? +IDENTIFIER @48:5 id builder calls.builder [v package] : java.lang.StringBuilder : java.lang.StringBuilder +TOKEN @48:5 +TOKEN @48:12 +IDENTIFIER @48:13 id append StringBuilder.append [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int) returns java.lang.StringBuilder throws [] sig java.lang.StringBuilder#append(I)Ljava/lang/StringBuilder; : java.lang.StringBuilder +TOKEN @48:13 +ARGUMENTS @48:19 +TOKEN @48:19 +INT_LITERAL @48:20 : int = 1 +TOKEN @48:20 +TOKEN @48:21 +TOKEN @48:22 +IDENTIFIER @48:23 id append StringBuilder.append [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (char) returns java.lang.StringBuilder throws [] sig java.lang.StringBuilder#append(C)Ljava/lang/StringBuilder; : java.lang.StringBuilder +TOKEN @48:23 +ARGUMENTS @48:29 +TOKEN @48:29 +CHAR_LITERAL @48:30 : char = 99 +TOKEN @48:30 +TOKEN @48:33 +TOKEN @48:34 +IDENTIFIER @48:35 id append StringBuilder.append [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (java.lang.String) returns java.lang.StringBuilder throws [] sig java.lang.StringBuilder#append(Ljava/lang/String;)Ljava/lang/StringBuilder; : java.lang.StringBuilder +TOKEN @48:35 +ARGUMENTS @48:41 +TOKEN @48:41 +STRING_LITERAL @48:42 : java.lang.String = s +TOKEN @48:42 +TOKEN @48:45 +TOKEN @48:46 +IDENTIFIER @48:47 id append StringBuilder.append [m public] : ? (double) returns java.lang.StringBuilder throws [] sig java.lang.StringBuilder#append(D)Ljava/lang/StringBuilder; : java.lang.StringBuilder +TOKEN @48:47 +ARGUMENTS @48:53 +TOKEN @48:53 +DOUBLE_LITERAL @48:54 : double +TOKEN @48:54 +TOKEN @48:57 +TOKEN @48:58 +IDENTIFIER @48:59 id append StringBuilder.append [m public] : ? (boolean) returns java.lang.StringBuilder throws [] sig java.lang.StringBuilder#append(Z)Ljava/lang/StringBuilder; : java.lang.StringBuilder +TOKEN @48:59 +ARGUMENTS @48:65 +TOKEN @48:65 +BOOLEAN_LITERAL @48:66 : boolean = true +TOKEN @48:66 +TOKEN @48:70 +TOKEN @48:71 +IDENTIFIER @48:72 id append StringBuilder.append [m public] : ? (char[]) returns java.lang.StringBuilder throws [] sig java.lang.StringBuilder#append([C)Ljava/lang/StringBuilder; : java.lang.StringBuilder +TOKEN @48:72 +ARGUMENTS @48:78 +TOKEN @48:78 +NEW_ARRAY @48:79 : char[] +TOKEN @48:79 +PRIMITIVE_TYPE @48:83 : char +TOKEN @48:83 +ARRAY_DIMENSION @48:87 +TOKEN @48:87 +TOKEN @48:88 +TOKEN @48:90 +LIST @48:91 +CHAR_LITERAL @48:91 : char = 97 +TOKEN @48:91 +TOKEN @48:94 +TOKEN @48:95 +TOKEN @48:96 +EXPRESSION_STATEMENT @49:5 +METHOD_INVOCATION @49:5 call PrintStream.println [m public] : ? (int) returns void throws [] sig java.io.PrintStream#println(I)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing PrintStream flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @49:5 : ? +MEMBER_SELECT @49:5 : java.io.PrintStream +IDENTIFIER @49:5 id System java.lang.System [t final public] : java.lang.System : java.lang.System +TOKEN @49:5 +TOKEN @49:11 +IDENTIFIER @49:12 id out System.out [v static final public] : java.io.PrintStream : java.io.PrintStream +TOKEN @49:12 +TOKEN @49:15 +IDENTIFIER @49:16 id println PrintStream.println [m public] : ? (int) returns void throws [] sig java.io.PrintStream#println(I)V : void +TOKEN @49:16 +ARGUMENTS @49:23 +TOKEN @49:23 +INT_LITERAL @49:24 : int = 1 +TOKEN @49:24 +TOKEN @49:25 +TOKEN @49:26 +EXPRESSION_STATEMENT @50:5 +METHOD_INVOCATION @50:5 call PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing PrintStream flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @50:5 : ? +MEMBER_SELECT @50:5 : java.io.PrintStream +IDENTIFIER @50:5 id System java.lang.System [t final public] : java.lang.System : java.lang.System +TOKEN @50:5 +TOKEN @50:11 +IDENTIFIER @50:12 id out System.out [v static final public] : java.io.PrintStream : java.io.PrintStream +TOKEN @50:12 +TOKEN @50:15 +IDENTIFIER @50:16 id println PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void +TOKEN @50:16 +ARGUMENTS @50:23 +TOKEN @50:23 +STRING_LITERAL @50:24 : java.lang.String = text +TOKEN @50:24 +TOKEN @50:30 +TOKEN @50:31 +EXPRESSION_STATEMENT @51:5 +METHOD_INVOCATION @51:5 call PrintStream.println [m public] : ? (char) returns void throws [] sig java.io.PrintStream#println(C)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing PrintStream flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @51:5 : ? +MEMBER_SELECT @51:5 : java.io.PrintStream +IDENTIFIER @51:5 id System java.lang.System [t final public] : java.lang.System : java.lang.System +TOKEN @51:5 +TOKEN @51:11 +IDENTIFIER @51:12 id out System.out [v static final public] : java.io.PrintStream : java.io.PrintStream +TOKEN @51:12 +TOKEN @51:15 +IDENTIFIER @51:16 id println PrintStream.println [m public] : ? (char) returns void throws [] sig java.io.PrintStream#println(C)V : void +TOKEN @51:16 +ARGUMENTS @51:23 +TOKEN @51:23 +CHAR_LITERAL @51:24 : char = 99 +TOKEN @51:24 +TOKEN @51:27 +TOKEN @51:28 +EXPRESSION_STATEMENT @52:5 +METHOD_INVOCATION @52:5 call PrintStream.println [m public] : ? (java.lang.Object) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/Object;)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing PrintStream flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @52:5 : ? +MEMBER_SELECT @52:5 : java.io.PrintStream +IDENTIFIER @52:5 id System java.lang.System [t final public] : java.lang.System : java.lang.System +TOKEN @52:5 +TOKEN @52:11 +IDENTIFIER @52:12 id out System.out [v static final public] : java.io.PrintStream : java.io.PrintStream +TOKEN @52:12 +TOKEN @52:15 +IDENTIFIER @52:16 id println PrintStream.println [m public] : ? (java.lang.Object) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/Object;)V : void +TOKEN @52:16 +ARGUMENTS @52:23 +TOKEN @52:23 +NEW_CLASS @52:24 new Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : java.lang.Object + details declared false usages 2 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @52:24 +IDENTIFIER @52:28 id Object Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : java.lang.Object +TOKEN @52:28 +ARGUMENTS @52:34 +TOKEN @52:34 +TOKEN @52:35 +TOKEN @52:36 +TOKEN @52:37 +EXPRESSION_STATEMENT @53:5 +METHOD_INVOCATION @53:5 call String.format [m static public] : ? (java.lang.String,java.lang.Object[]) returns java.lang.String throws [] sig java.lang.String#format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [static, public] overridden [] overridable false generic false default false synchronized false varargs true native false parameters [arg0, arg1] parameterMetadata [] +MEMBER_SELECT @53:5 : ? +IDENTIFIER @53:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @53:5 +TOKEN @53:11 +IDENTIFIER @53:12 id format String.format [m static public] : ? (java.lang.String,java.lang.Object[]) returns java.lang.String throws [] sig java.lang.String#format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String; : java.lang.String +TOKEN @53:12 +ARGUMENTS @53:18 +TOKEN @53:18 +STRING_LITERAL @53:19 : java.lang.String = %s %d +TOKEN @53:19 +TOKEN @53:26 +STRING_LITERAL @53:28 : java.lang.String = a +TOKEN @53:28 +TOKEN @53:31 +INT_LITERAL @53:33 : int = 1 +TOKEN @53:33 +TOKEN @53:34 +TOKEN @53:35 +EXPRESSION_STATEMENT @54:5 +METHOD_INVOCATION @54:5 call Math.max [m static public] : ? (long,long) returns long throws [] sig java.lang.Math#max(JJ)J : long + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Math flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +MEMBER_SELECT @54:5 : ? +IDENTIFIER @54:5 id Math java.lang.Math [t final public] : java.lang.Math : java.lang.Math +TOKEN @54:5 +TOKEN @54:9 +IDENTIFIER @54:10 id max Math.max [m static public] : ? (long,long) returns long throws [] sig java.lang.Math#max(JJ)J : long +TOKEN @54:10 +ARGUMENTS @54:13 +TOKEN @54:13 +INT_LITERAL @54:14 : int = 1 +TOKEN @54:14 +TOKEN @54:15 +LONG_LITERAL @54:17 : long = 2 +TOKEN @54:17 +TOKEN @54:19 +TOKEN @54:20 +EXPRESSION_STATEMENT @55:5 +METHOD_INVOCATION @55:5 call Math.abs [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (double) returns double throws [] sig java.lang.Math#abs(D)D : double + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Math flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @55:5 : ? +IDENTIFIER @55:5 id Math java.lang.Math [t final public] : java.lang.Math : java.lang.Math +TOKEN @55:5 +TOKEN @55:9 +IDENTIFIER @55:10 id abs Math.abs [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (double) returns double throws [] sig java.lang.Math#abs(D)D : double +TOKEN @55:10 +ARGUMENTS @55:13 +TOKEN @55:13 +UNARY_MINUS @55:14 : double +TOKEN @55:14 +DOUBLE_LITERAL @55:15 : double +TOKEN @55:15 +TOKEN @55:18 +TOKEN @55:19 +TOKEN @56:3 +TOKEN @57:1 +TOKEN @58:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Overloads.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Overloads.java new file mode 100644 index 00000000000..3eb87f77ae2 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Overloads.java @@ -0,0 +1,57 @@ +import java.util.List; + +class Overloads { + + void call(int value) { + } + + void call(long value) { + } + + void call(double value) { + } + + void call(Integer value) { + } + + void call(Object value) { + } + + void call(String value) { + } + + void call(String first, Object... rest) { + } + + void call(int first, int second) { + } + + void call(List values) { + } + + void calls() { + call(1); + call(1L); + call(1.5f); + call('c'); + call((short) 2); + call(Integer.valueOf(3)); + call("text"); + call(new Object()); + call("a", 1, 2); + call("a", "b"); + call(1, 2); + call(List.of("x")); + call((Object) "cast"); + call(null, null); + StringBuilder builder = new StringBuilder(); + builder.append(1).append('c').append("s").append(2.0).append(true).append(new char[] {'a'}); + System.out.println(1); + System.out.println("text"); + System.out.println('c'); + System.out.println(new Object()); + String.format("%s %d", "a", 1); + Math.max(1, 2L); + Math.abs(-1.5); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Overloads.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Overloads.textproto.gz new file mode 100644 index 00000000000..44b370403ad Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Overloads.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Patterns.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Patterns.expected.txt new file mode 100644 index 00000000000..31da5135173 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Patterns.expected.txt @@ -0,0 +1,604 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id util unknown : ? +TOKEN @1:13 +TOKEN @1:17 +IDENTIFIER @1:18 id List unknown : ? +TOKEN @1:18 +TOKEN @1:22 +CLASS @3:1 class .Patterns [t package] : Patterns super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] members [, Circle, Color, Rect, Shape, area, code, describe, text] lookupToString 0 outermost Patterns annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Patterns +MODIFIERS +TOKEN @3:1 +IDENTIFIER @3:7 id Patterns .Patterns [t package] : Patterns : Patterns +TOKEN @3:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @3:16 +INTERFACE @5:3 class Patterns.Shape [t static package interface] : Patterns$Shape super java.lang.Object interfaces [] + details declared true usages 3 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [static, package, interface] members [] lookupToString 0 outermost Patterns annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Shape +MODIFIERS @5:3 +TOKEN @5:3 +TOKEN @5:10 +IDENTIFIER @5:20 id Shape Patterns.Shape [t static package interface] : Patterns$Shape : Patterns$Shape +TOKEN @5:20 +TYPE_PARAMETERS +LIST +LIST @5:34 +IDENTIFIER @5:34 id Circle Patterns.Circle [t static final package] : Patterns$Circle : Patterns$Circle +TOKEN @5:34 +TOKEN @5:40 +IDENTIFIER @5:42 id Rect Patterns.Rect [t static final package] : Patterns$Rect : Patterns$Rect +TOKEN @5:42 +TOKEN @5:47 +TOKEN @6:3 +RECORD @8:3 class Patterns.Circle [t static final package] : Patterns$Circle super java.lang.Record interfaces [Patterns$Shape] + details declared true usages 2 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [static, final, package] members [, radius, radius] lookupToString 0 outermost Patterns annotation false subtypeOf [java.lang.Object] superTypes [Patterns$Shape, java.lang.Object, java.lang.Record] numerical false wrapper false raw false declaring Circle +MODIFIERS +TOKEN @8:3 +IDENTIFIER @8:10 id Circle Patterns.Circle [t static final package] : Patterns$Circle : Patterns$Circle +TOKEN @8:10 +TYPE_PARAMETERS +TOKEN @8:16 +VARIABLE @8:17 var Circle.radius [v package] : double + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Circle flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @8:17 : double +TOKEN @8:17 +IDENTIFIER @8:24 id radius Circle.radius [v package] : double : double +TOKEN @8:24 +TOKEN @8:30 +TOKEN @8:32 +LIST @8:43 +IDENTIFIER @8:43 id Shape Patterns.Shape [t static package interface] : Patterns$Shape : Patterns$Shape +TOKEN @8:43 +LIST +TOKEN @8:49 +TOKEN @9:3 +RECORD @11:3 class Patterns.Rect [t static final package] : Patterns$Rect super java.lang.Record interfaces [Patterns$Shape] + details declared true usages 3 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [static, final, package] members [, height, height, width, width] lookupToString 0 outermost Patterns annotation false subtypeOf [java.lang.Object] superTypes [Patterns$Shape, java.lang.Object, java.lang.Record] numerical false wrapper false raw false declaring Rect +MODIFIERS +TOKEN @11:3 +IDENTIFIER @11:10 id Rect Patterns.Rect [t static final package] : Patterns$Rect : Patterns$Rect +TOKEN @11:10 +TYPE_PARAMETERS +TOKEN @11:14 +VARIABLE @11:15 var Rect.width [v package] : double + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Rect flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @11:15 : double +TOKEN @11:15 +IDENTIFIER @11:22 id width Rect.width [v package] : double : double +TOKEN @11:22 +TOKEN @11:27 +VARIABLE @11:29 var Rect.height [v package] : double + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Rect flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @11:29 : double +TOKEN @11:29 +IDENTIFIER @11:36 id height Rect.height [v package] : double : double +TOKEN @11:36 +TOKEN @11:42 +TOKEN @11:44 +LIST @11:55 +IDENTIFIER @11:55 id Shape Patterns.Shape [t static package interface] : Patterns$Shape : Patterns$Shape +TOKEN @11:55 +LIST +TOKEN @11:61 +TOKEN @12:3 +ENUM @14:3 class Patterns.Color [t static final package enum] : Patterns$Color super java.lang.Enum interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [static, final, package, enum] members [, BLUE, GREEN, RED, valueOf, values] lookupToString 0 outermost Patterns annotation false subtypeOf [java.lang.Object, java.io.Serializable, java.lang.Comparable] superTypes [java.io.Serializable, java.lang.Comparable, java.lang.Enum, java.lang.Object, java.lang.constant.Constable] numerical false wrapper false raw false declaring Color +MODIFIERS +TOKEN @14:3 +IDENTIFIER @14:8 id Color Patterns.Color [t static final package enum] : Patterns$Color : Patterns$Color +TOKEN @14:8 +TYPE_PARAMETERS +LIST +LIST +TOKEN @14:14 +ENUM_CONSTANT @15:5 var Color.RED [v static final public enum] : Patterns$Color + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Color flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @15:5 new Color. [m private] : ? () returns void throws [] sig Patterns$Color#(Ljava/lang/String;I)V : ? + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Color flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @15:5 id RED Color. [m private] : ? () returns void throws [] sig Patterns$Color#(Ljava/lang/String;I)V : Patterns$Color +TOKEN @15:5 +ARGUMENTS +TOKEN @15:8 +ENUM_CONSTANT @15:10 var Color.GREEN [v static final public enum] : Patterns$Color + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Color flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @15:10 new Color. [m private] : ? () returns void throws [] sig Patterns$Color#(Ljava/lang/String;I)V : ? + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Color flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @15:10 id GREEN Color. [m private] : ? () returns void throws [] sig Patterns$Color#(Ljava/lang/String;I)V : Patterns$Color +TOKEN @15:10 +ARGUMENTS +TOKEN @15:15 +ENUM_CONSTANT @15:17 var Color.BLUE [v static final public enum] : Patterns$Color + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Color flags [static, final, public, enum] local false parameter false effectivelyFinal true constant null +MODIFIERS +NEW_CLASS @15:17 new Color. [m private] : ? () returns void throws [] sig Patterns$Color#(Ljava/lang/String;I)V : ? + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Color flags [private] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +IDENTIFIER @15:17 id BLUE Color. [m private] : ? () returns void throws [] sig Patterns$Color#(Ljava/lang/String;I)V : Patterns$Color +TOKEN @15:17 +ARGUMENTS +TOKEN @16:3 +METHOD @18:3 method Patterns.area [m package] : ? (Patterns$Shape) returns double throws [] sig Patterns#area(LPatterns$Shape;)D overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [shape] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @18:3 : double +TOKEN @18:3 +IDENTIFIER @18:10 id area Patterns.area [m package] : ? (Patterns$Shape) returns double throws [] sig Patterns#area(LPatterns$Shape;)D : double +TOKEN @18:10 +TOKEN @18:14 +VARIABLE @18:15 var area.shape [v package] : Patterns$Shape + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter true effectivelyFinal true constant null owner area Patterns#area(LPatterns$Shape;)D [package] returns double parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @18:15 id Shape Patterns.Shape [t static package interface] : Patterns$Shape : Patterns$Shape +TOKEN @18:15 +IDENTIFIER @18:21 id shape area.shape [v package] : Patterns$Shape : Patterns$Shape +TOKEN @18:21 +TOKEN @18:26 +BLOCK @18:28 +TOKEN @18:28 +RETURN_STATEMENT @19:5 +TOKEN @19:5 +SWITCH_EXPRESSION @19:12 : double +TOKEN @19:12 +TOKEN @19:19 +IDENTIFIER @19:20 id shape area.shape [v package] : Patterns$Shape : Patterns$Shape +TOKEN @19:20 +TOKEN @19:25 +TOKEN @19:27 +CASE_GROUP @20:7 +CASE_LABEL @20:7 +TOKEN @20:7 +TYPE_PATTERN @20:12 : Patterns$Circle +VARIABLE @20:12 var area.c [v package] : Patterns$Circle + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter false effectivelyFinal true constant null owner area Patterns#area(LPatterns$Shape;)D [package] returns double parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @20:12 id Circle Patterns.Circle [t static final package] : Patterns$Circle : Patterns$Circle +TOKEN @20:12 +IDENTIFIER @20:19 id c area.c [v package] : Patterns$Circle : Patterns$Circle +TOKEN @20:19 +TOKEN @20:21 +YIELD_STATEMENT @20:24 +MULTIPLY @20:24 : double +MULTIPLY @20:24 : double +MEMBER_SELECT @20:24 : double = 3.141592653589793 +IDENTIFIER @20:24 id Math java.lang.Math [t final public] : java.lang.Math : java.lang.Math +TOKEN @20:24 +TOKEN @20:28 +IDENTIFIER @20:29 id PI Math.PI [v static final public] : double : double = 3.141592653589793 +TOKEN @20:29 +TOKEN @20:32 +METHOD_INVOCATION @20:34 call Circle.radius [m public] : ? () returns double throws [] sig Patterns$Circle#radius()D : double + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Circle flags [public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @20:34 : ? +IDENTIFIER @20:34 id c area.c [v package] : Patterns$Circle : Patterns$Circle +TOKEN @20:34 +TOKEN @20:35 +IDENTIFIER @20:36 id radius Circle.radius [m public] : ? () returns double throws [] sig Patterns$Circle#radius()D : double +TOKEN @20:36 +ARGUMENTS @20:42 +TOKEN @20:42 +TOKEN @20:43 +TOKEN @20:45 +METHOD_INVOCATION @20:47 call Circle.radius [m public] : ? () returns double throws [] sig Patterns$Circle#radius()D : double + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Circle flags [public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @20:47 : ? +IDENTIFIER @20:47 id c area.c [v package] : Patterns$Circle : Patterns$Circle +TOKEN @20:47 +TOKEN @20:48 +IDENTIFIER @20:49 id radius Circle.radius [m public] : ? () returns double throws [] sig Patterns$Circle#radius()D : double +TOKEN @20:49 +ARGUMENTS @20:55 +TOKEN @20:55 +TOKEN @20:56 +TOKEN @20:57 +CASE_GROUP @21:7 +CASE_LABEL @21:7 +TOKEN @21:7 +RECORD_PATTERN @21:12 : Patterns$Rect +IDENTIFIER @21:12 id Rect Patterns.Rect [t static final package] : Patterns$Rect : Patterns$Rect +TOKEN @21:12 +TOKEN @21:16 +TYPE_PATTERN @21:17 : double +VARIABLE @21:17 var area.w [v package] : double + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter false effectivelyFinal true constant null owner area Patterns#area(LPatterns$Shape;)D [package] returns double parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @21:17 : double +TOKEN @21:17 +IDENTIFIER @21:24 id w area.w [v package] : double : double +TOKEN @21:24 +TYPE_PATTERN @21:27 : double +VARIABLE @21:27 var area.h [v package] : double + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter false effectivelyFinal true constant null owner area Patterns#area(LPatterns$Shape;)D [package] returns double parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @21:27 : double +TOKEN @21:27 +IDENTIFIER @21:34 id h area.h [v package] : double : double +TOKEN @21:34 +TOKEN @21:35 +TOKEN @21:37 +YIELD_STATEMENT @21:40 +MULTIPLY @21:40 : double +IDENTIFIER @21:40 id w area.w [v package] : double : double +TOKEN @21:40 +TOKEN @21:42 +IDENTIFIER @21:44 id h area.h [v package] : double : double +TOKEN @21:44 +TOKEN @21:45 +TOKEN @22:5 +TOKEN @22:6 +TOKEN @23:3 +METHOD @25:3 method Patterns.describe [m package] : ? (java.lang.Object) returns java.lang.String throws [] sig Patterns#describe(Ljava/lang/Object;)Ljava/lang/String; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [o] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @25:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @25:3 +IDENTIFIER @25:10 id describe Patterns.describe [m package] : ? (java.lang.Object) returns java.lang.String throws [] sig Patterns#describe(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String +TOKEN @25:10 +TOKEN @25:18 +VARIABLE @25:19 var describe.o [v package] : java.lang.Object + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter true effectivelyFinal true constant null owner describe Patterns#describe(Ljava/lang/Object;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @25:19 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @25:19 +IDENTIFIER @25:26 id o describe.o [v package] : java.lang.Object : java.lang.Object +TOKEN @25:26 +TOKEN @25:27 +BLOCK @25:29 +TOKEN @25:29 +IF_STATEMENT @26:5 +TOKEN @26:5 +TOKEN @26:8 +CONDITIONAL_AND @26:9 : boolean +PATTERN_INSTANCE_OF @26:9 : boolean +IDENTIFIER @26:9 id o describe.o [v package] : java.lang.Object : java.lang.Object +TOKEN @26:9 +TOKEN @26:11 +TYPE_PATTERN @26:22 : java.lang.String +VARIABLE @26:22 var describe.s [v package] : java.lang.String + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter false effectivelyFinal true constant null owner describe Patterns#describe(Ljava/lang/Object;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @26:22 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @26:22 +IDENTIFIER @26:29 id s describe.s [v package] : java.lang.String : java.lang.String +TOKEN @26:29 +TOKEN @26:31 +LOGICAL_COMPLEMENT @26:34 : boolean +TOKEN @26:34 +METHOD_INVOCATION @26:35 call String.isEmpty [m public] : ? () returns boolean throws [] sig java.lang.String#isEmpty()Z : boolean + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [CharSequence.isEmpty[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @26:35 : ? +IDENTIFIER @26:35 id s describe.s [v package] : java.lang.String : java.lang.String +TOKEN @26:35 +TOKEN @26:36 +IDENTIFIER @26:37 id isEmpty String.isEmpty [m public] : ? () returns boolean throws [] sig java.lang.String#isEmpty()Z : boolean +TOKEN @26:37 +ARGUMENTS @26:44 +TOKEN @26:44 +TOKEN @26:45 +TOKEN @26:46 +BLOCK @26:48 +TOKEN @26:48 +RETURN_STATEMENT @27:7 +TOKEN @27:7 +IDENTIFIER @27:14 id s describe.s [v package] : java.lang.String : java.lang.String +TOKEN @27:14 +TOKEN @27:15 +TOKEN @28:5 +IF_STATEMENT @29:5 +TOKEN @29:5 +TOKEN @29:8 +PATTERN_INSTANCE_OF @29:9 : boolean +IDENTIFIER @29:9 id o describe.o [v package] : java.lang.Object : java.lang.Object +TOKEN @29:9 +TOKEN @29:11 +RECORD_PATTERN @29:22 : Patterns$Rect +IDENTIFIER @29:22 id Rect Patterns.Rect [t static final package] : Patterns$Rect : Patterns$Rect +TOKEN @29:22 +TOKEN @29:26 +TYPE_PATTERN @29:27 : double +VARIABLE @29:27 var describe.w [v package] : double + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter false effectivelyFinal true constant null owner describe Patterns#describe(Ljava/lang/Object;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +VAR_TYPE @29:27 +TOKEN @29:27 +IDENTIFIER @29:31 id w describe.w [v package] : double : double +TOKEN @29:31 +TYPE_PATTERN @29:34 : double +VARIABLE @29:34 var describe.h [v package] : double + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter false effectivelyFinal true constant null owner describe Patterns#describe(Ljava/lang/Object;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +VAR_TYPE @29:34 +TOKEN @29:34 +IDENTIFIER @29:38 id h describe.h [v package] : double : double +TOKEN @29:38 +TOKEN @29:39 +TOKEN @29:40 +BLOCK @29:42 +TOKEN @29:42 +RETURN_STATEMENT @30:7 +TOKEN @30:7 +PLUS @30:14 : java.lang.String +PLUS @30:14 : java.lang.String +IDENTIFIER @30:14 id w describe.w [v package] : double : double +TOKEN @30:14 +TOKEN @30:16 +STRING_LITERAL @30:18 : java.lang.String = x +TOKEN @30:18 +TOKEN @30:22 +IDENTIFIER @30:24 id h describe.h [v package] : double : double +TOKEN @30:24 +TOKEN @30:25 +TOKEN @31:5 +RETURN_STATEMENT @32:5 +TOKEN @32:5 +SWITCH_EXPRESSION @32:12 : java.lang.String +TOKEN @32:12 +TOKEN @32:19 +IDENTIFIER @32:20 id o describe.o [v package] : java.lang.Object : java.lang.Object +TOKEN @32:20 +TOKEN @32:21 +TOKEN @32:23 +CASE_GROUP @33:7 +CASE_LABEL @33:7 +TOKEN @33:7 +NULL_PATTERN @33:12 : +NULL_LITERAL @33:12 : +TOKEN @33:12 +TOKEN @33:17 +YIELD_STATEMENT @33:20 +STRING_LITERAL @33:20 : java.lang.String = null +TOKEN @33:20 +TOKEN @33:26 +CASE_GROUP @34:7 +CASE_LABEL @34:7 +TOKEN @34:7 +GUARDED_PATTERN @34:12 : java.lang.Integer +TYPE_PATTERN @34:12 : java.lang.Integer +VARIABLE @34:12 var describe.i [v package] : java.lang.Integer + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter false effectivelyFinal true constant null owner describe Patterns#describe(Ljava/lang/Object;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @34:12 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @34:12 +IDENTIFIER @34:20 id i describe.i [v package] : java.lang.Integer : java.lang.Integer +TOKEN @34:20 +TOKEN @34:22 +GREATER_THAN @34:27 : boolean +IDENTIFIER @34:27 id i describe.i [v package] : java.lang.Integer : java.lang.Integer +TOKEN @34:27 +TOKEN @34:29 +INT_LITERAL @34:31 : int = 10 +TOKEN @34:31 +TOKEN @34:34 +YIELD_STATEMENT @34:37 +STRING_LITERAL @34:37 : java.lang.String = big +TOKEN @34:37 +TOKEN @34:42 +CASE_GROUP @35:7 +CASE_LABEL @35:7 +TOKEN @35:7 +TYPE_PATTERN @35:12 : java.lang.Integer +VARIABLE @35:12 var describe.i [v package] : java.lang.Integer + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter false effectivelyFinal true constant null owner describe Patterns#describe(Ljava/lang/Object;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @35:12 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @35:12 +IDENTIFIER @35:20 id i describe.i [v package] : java.lang.Integer : java.lang.Integer +TOKEN @35:20 +TOKEN @35:22 +YIELD_STATEMENT @35:25 +PLUS @35:25 : java.lang.String +STRING_LITERAL @35:25 : java.lang.String = int +TOKEN @35:25 +TOKEN @35:32 +IDENTIFIER @35:34 id i describe.i [v package] : java.lang.Integer : java.lang.Integer +TOKEN @35:34 +TOKEN @35:35 +CASE_GROUP @36:7 +CASE_LABEL @36:7 +TOKEN @36:7 +TYPE_PATTERN @36:12 : java.util.List +VARIABLE @36:12 var describe.list [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Patterns flags [package] local true parameter false effectivelyFinal true constant null owner describe Patterns#describe(Ljava/lang/Object;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @36:12 : java.util.List +IDENTIFIER @36:12 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @36:12 +TYPE_ARGUMENTS @36:16 +TOKEN @36:16 +UNBOUNDED_WILDCARD @36:17 +TOKEN @36:17 +TOKEN @36:18 +IDENTIFIER @36:20 id list describe.list [v package] : java.util.List : java.util.List +TOKEN @36:20 +TOKEN @36:25 +YIELD_STATEMENT @36:28 +PLUS @36:28 : java.lang.String +STRING_LITERAL @36:28 : java.lang.String = list +TOKEN @36:28 +TOKEN @36:36 +METHOD_INVOCATION @36:38 call List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.size[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @36:38 : ? +IDENTIFIER @36:38 id list describe.list [v package] : java.util.List : java.util.List +TOKEN @36:38 +TOKEN @36:42 +IDENTIFIER @36:43 id size List.size [m abstract public] : ? () returns int throws [] sig java.util.List#size()I : int +TOKEN @36:43 +ARGUMENTS @36:47 +TOKEN @36:47 +TOKEN @36:48 +TOKEN @36:49 +CASE_GROUP @37:7 +CASE_LABEL @37:7 +TOKEN @37:7 +TOKEN @37:15 +YIELD_STATEMENT @37:18 +METHOD_INVOCATION @37:18 call Object.toString [m public] : ? () returns java.lang.String throws [] sig java.lang.Object#toString()Ljava/lang/String; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @37:18 : ? +IDENTIFIER @37:18 id o describe.o [v package] : java.lang.Object : java.lang.Object +TOKEN @37:18 +TOKEN @37:19 +IDENTIFIER @37:20 id toString Object.toString [m public] : ? () returns java.lang.String throws [] sig java.lang.Object#toString()Ljava/lang/String; : java.lang.String +TOKEN @37:20 +ARGUMENTS @37:28 +TOKEN @37:28 +TOKEN @37:29 +TOKEN @37:30 +TOKEN @38:5 +TOKEN @38:6 +TOKEN @39:3 +METHOD @41:3 method Patterns.code [m package] : ? (Patterns$Color) returns int throws [] sig Patterns#code(LPatterns$Color;)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [color] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @41:3 : int +TOKEN @41:3 +IDENTIFIER @41:7 id code Patterns.code [m package] : ? (Patterns$Color) returns int throws [] sig Patterns#code(LPatterns$Color;)I : int +TOKEN @41:7 +TOKEN @41:11 +VARIABLE @41:12 var code.color [v package] : Patterns$Color + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter true effectivelyFinal true constant null owner code Patterns#code(LPatterns$Color;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @41:12 id Color Patterns.Color [t static final package enum] : Patterns$Color : Patterns$Color +TOKEN @41:12 +IDENTIFIER @41:18 id color code.color [v package] : Patterns$Color : Patterns$Color +TOKEN @41:18 +TOKEN @41:23 +BLOCK @41:25 +TOKEN @41:25 +RETURN_STATEMENT @42:5 +TOKEN @42:5 +SWITCH_EXPRESSION @42:12 : int +TOKEN @42:12 +TOKEN @42:19 +IDENTIFIER @42:20 id color code.color [v package] : Patterns$Color : Patterns$Color +TOKEN @42:20 +TOKEN @42:25 +TOKEN @42:27 +CASE_GROUP @43:7 +CASE_LABEL @43:7 +TOKEN @43:7 +IDENTIFIER @43:12 id RED Color.RED [v static final public enum] : Patterns$Color : Patterns$Color +TOKEN @43:12 +TOKEN @43:16 +YIELD_STATEMENT @43:19 +INT_LITERAL @43:19 : int = 1 +TOKEN @43:19 +TOKEN @43:20 +CASE_GROUP @44:7 +CASE_LABEL @44:7 +TOKEN @44:7 +IDENTIFIER @44:12 id GREEN Color.GREEN [v static final public enum] : Patterns$Color : Patterns$Color +TOKEN @44:12 +TOKEN @44:18 +YIELD_STATEMENT @44:21 +INT_LITERAL @44:21 : int = 2 +TOKEN @44:21 +TOKEN @44:22 +CASE_GROUP @45:7 +CASE_LABEL @45:7 +TOKEN @45:7 +IDENTIFIER @45:12 id BLUE Color.BLUE [v static final public enum] : Patterns$Color : Patterns$Color +TOKEN @45:12 +TOKEN @45:17 +BLOCK @45:20 +TOKEN @45:20 +VARIABLE @46:9 var code.base [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter false effectivelyFinal true constant null owner code Patterns#code(LPatterns$Color;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @46:9 : int +TOKEN @46:9 +IDENTIFIER @46:13 id base code.base [v package] : int : int +TOKEN @46:13 +TOKEN @46:18 +INT_LITERAL @46:20 : int = 3 +TOKEN @46:20 +TOKEN @46:21 +YIELD_STATEMENT @47:9 +TOKEN @47:9 +IDENTIFIER @47:15 id base code.base [v package] : int : int +TOKEN @47:15 +TOKEN @47:19 +TOKEN @48:7 +TOKEN @49:5 +TOKEN @49:6 +TOKEN @50:3 +METHOD @52:3 method Patterns.text [m package] : ? (java.lang.String) returns java.lang.String throws [] sig Patterns#text(Ljava/lang/String;)Ljava/lang/String; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [s] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @52:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @52:3 +IDENTIFIER @52:10 id text Patterns.text [m package] : ? (java.lang.String) returns java.lang.String throws [] sig Patterns#text(Ljava/lang/String;)Ljava/lang/String; : java.lang.String +TOKEN @52:10 +TOKEN @52:14 +VARIABLE @52:15 var text.s [v package] : java.lang.String + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter true effectivelyFinal true constant null owner text Patterns#text(Ljava/lang/String;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @52:15 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @52:15 +IDENTIFIER @52:22 id s text.s [v package] : java.lang.String : java.lang.String +TOKEN @52:22 +TOKEN @52:23 +BLOCK @52:25 +TOKEN @52:25 +VARIABLE @53:5 var text.block [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Patterns flags [package] local true parameter false effectivelyFinal true constant null owner text Patterns#text(Ljava/lang/String;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Patterns type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @53:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @53:5 +IDENTIFIER @53:12 id block text.block [v package] : java.lang.String : java.lang.String +TOKEN @53:12 +TOKEN @53:18 +TEXT_BLOCK @53:20 : java.lang.String = block\ntext\n +TOKEN @53:20 +TOKEN @56:10 +RETURN_STATEMENT @57:5 +TOKEN @57:5 +SWITCH_EXPRESSION @57:12 : java.lang.String +TOKEN @57:12 +TOKEN @57:19 +IDENTIFIER @57:20 id s text.s [v package] : java.lang.String : java.lang.String +TOKEN @57:20 +TOKEN @57:21 +TOKEN @57:23 +CASE_GROUP @58:7 +CASE_LABEL @58:7 +TOKEN @58:7 +STRING_LITERAL @58:12 : java.lang.String = a +TOKEN @58:12 +STRING_LITERAL @58:17 : java.lang.String = b +TOKEN @58:17 +TOKEN @58:21 +YIELD_STATEMENT @58:24 +IDENTIFIER @58:24 id block text.block [v package] : java.lang.String : java.lang.String +TOKEN @58:24 +TOKEN @58:29 +CASE_GROUP @59:7 +CASE_LABEL @59:7 +TOKEN @59:7 +TOKEN @59:15 +YIELD_STATEMENT @59:18 +IDENTIFIER @59:18 id s text.s [v package] : java.lang.String : java.lang.String +TOKEN @59:18 +TOKEN @59:19 +TOKEN @60:5 +TOKEN @60:6 +TOKEN @61:3 +TOKEN @62:1 +TOKEN @63:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Patterns.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Patterns.java new file mode 100644 index 00000000000..ae3cb01a55a --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Patterns.java @@ -0,0 +1,62 @@ +import java.util.List; + +class Patterns { + + sealed interface Shape permits Circle, Rect { + } + + record Circle(double radius) implements Shape { + } + + record Rect(double width, double height) implements Shape { + } + + enum Color { + RED, GREEN, BLUE + } + + double area(Shape shape) { + return switch (shape) { + case Circle c -> Math.PI * c.radius() * c.radius(); + case Rect(double w, double h) -> w * h; + }; + } + + String describe(Object o) { + if (o instanceof String s && !s.isEmpty()) { + return s; + } + if (o instanceof Rect(var w, var h)) { + return w + "x" + h; + } + return switch (o) { + case null -> "null"; + case Integer i when i > 10 -> "big"; + case Integer i -> "int " + i; + case List list -> "list " + list.size(); + default -> o.toString(); + }; + } + + int code(Color color) { + return switch (color) { + case RED -> 1; + case GREEN -> 2; + case BLUE -> { + int base = 3; + yield base; + } + }; + } + + String text(String s) { + String block = """ + block + text + """; + return switch (s) { + case "a", "b" -> block; + default -> s; + }; + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Patterns.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Patterns.textproto.gz new file mode 100644 index 00000000000..d16427a6597 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Patterns.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/QualifiedTypeAnnotations.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/QualifiedTypeAnnotations.expected.txt new file mode 100644 index 00000000000..e8814162408 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/QualifiedTypeAnnotations.expected.txt @@ -0,0 +1,139 @@ +COMPILATION_UNIT @1:1 +PACKAGE @1:1 +TOKEN @1:1 +IDENTIFIER @1:9 id annotated .annotated [p package] : ? : ? +TOKEN @1:9 +TOKEN @1:18 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id annotated unknown : ? +TOKEN @3:8 +TOKEN @3:17 +IDENTIFIER @3:18 id Tags unknown : ? +TOKEN @3:18 +TOKEN @3:22 +IDENTIFIER @3:23 id Tag unknown : ? +TOKEN @3:23 +TOKEN @3:26 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id lang unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id annotation unknown : ? +TOKEN @4:18 +TOKEN @4:28 +IDENTIFIER @4:29 id ElementType unknown : ? +TOKEN @4:29 +TOKEN @4:40 +IMPORT @5:1 +TOKEN @5:1 +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +IDENTIFIER @5:8 id java unknown : ? +TOKEN @5:8 +TOKEN @5:12 +IDENTIFIER @5:13 id lang unknown : ? +TOKEN @5:13 +TOKEN @5:17 +IDENTIFIER @5:18 id annotation unknown : ? +TOKEN @5:18 +TOKEN @5:28 +IDENTIFIER @5:29 id Target unknown : ? +TOKEN @5:29 +TOKEN @5:35 +CLASS @7:1 class annotated.Tags [t package] : annotated.Tags super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Tags flags [package] members [, Tag] lookupToString 0 outermost Tags annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Tags +MODIFIERS +TOKEN @7:1 +IDENTIFIER @7:7 id Tags annotated.Tags [t package] : annotated.Tags : annotated.Tags +TOKEN @7:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @7:12 +ANNOTATION_TYPE @8:3 class Tags.Tag [t static package interface] : annotated.Tags$Tag @java.lang.annotation.Target super java.lang.Object interfaces [java.lang.annotation.Annotation] + details declared true usages 1 metadata [java.lang.annotation.Target(value={ElementType.TYPE_USE})] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [java.lang.annotation.Target tree true values 1 annotated true] typeArguments [] enclosing Tags flags [static, package, interface] members [] lookupToString 0 outermost Tags annotation true subtypeOf [java.lang.Object, java.lang.annotation.Annotation] superTypes [java.lang.Object, java.lang.annotation.Annotation] numerical false wrapper false raw false declaring Tag +MODIFIERS @8:3 +ANNOTATION @8:3 : java.lang.annotation.Target +TOKEN @8:3 +IDENTIFIER @8:4 id Target java.lang.annotation.Target [t public interface] : java.lang.annotation.Target @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.annotation.Target +TOKEN @8:4 +ARGUMENTS @8:10 +TOKEN @8:10 +MEMBER_SELECT @8:11 : java.lang.annotation.ElementType +IDENTIFIER @8:11 id ElementType java.lang.annotation.ElementType [t final public enum] : java.lang.annotation.ElementType : java.lang.annotation.ElementType +TOKEN @8:11 +TOKEN @8:22 +IDENTIFIER @8:23 id TYPE_USE ElementType.TYPE_USE [v static final public enum] : java.lang.annotation.ElementType : java.lang.annotation.ElementType +TOKEN @8:23 +TOKEN @8:31 +TOKEN @9:3 +TOKEN @9:4 +IDENTIFIER @9:14 id Tag Tags.Tag [t static package interface] : annotated.Tags$Tag @java.lang.annotation.Target : annotated.Tags$Tag +TOKEN @9:14 +TYPE_PARAMETERS +LIST +LIST +TOKEN @9:18 +TOKEN @10:3 +TOKEN @11:1 +CLASS @13:1 class annotated.QualifiedTypeAnnotations [t abstract package] : annotated.QualifiedTypeAnnotations super java.lang.Object interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing QualifiedTypeAnnotations flags [abstract, package] members [, Inner, m] lookupToString 0 outermost QualifiedTypeAnnotations annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring QualifiedTypeAnnotations +MODIFIERS @13:1 +TOKEN @13:1 +TOKEN @13:10 +IDENTIFIER @13:16 id QualifiedTypeAnnotations annotated.QualifiedTypeAnnotations [t abstract package] : annotated.QualifiedTypeAnnotations : annotated.QualifiedTypeAnnotations +TOKEN @13:16 +TYPE_PARAMETERS +LIST +LIST +TOKEN @13:41 +CLASS @14:3 class QualifiedTypeAnnotations.Inner [t package] : annotated.QualifiedTypeAnnotations$Inner super java.lang.Object interfaces [] + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing QualifiedTypeAnnotations flags [package] members [] lookupToString 0 outermost QualifiedTypeAnnotations annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Inner +MODIFIERS +TOKEN @14:3 +IDENTIFIER @14:9 id Inner QualifiedTypeAnnotations.Inner [t package] : annotated.QualifiedTypeAnnotations$Inner : annotated.QualifiedTypeAnnotations$Inner +TOKEN @14:9 +TYPE_PARAMETERS +LIST +LIST +TOKEN @14:15 +TOKEN @15:3 +METHOD @17:3 method QualifiedTypeAnnotations.m [m abstract package] : ? () returns annotated.QualifiedTypeAnnotations$Inner throws [] sig annotated.QualifiedTypeAnnotations#m()Lannotated/QualifiedTypeAnnotations$Inner; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing QualifiedTypeAnnotations flags [abstract, package] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS @17:3 +TOKEN @17:3 +TYPE_PARAMETERS @17:12 +TOKEN @17:12 +TYPE_PARAMETER @17:13 +IDENTIFIER @17:13 id T m.T [t package] : T erasure java.lang.Object : T erasure java.lang.Object +TOKEN @17:13 +TOKEN @17:14 +MEMBER_SELECT @17:16 : annotated.QualifiedTypeAnnotations$Inner +IDENTIFIER @17:16 id QualifiedTypeAnnotations annotated.QualifiedTypeAnnotations [t abstract package] : annotated.QualifiedTypeAnnotations : annotated.QualifiedTypeAnnotations +ANNOTATION @17:16 : annotated.Tags$Tag +TOKEN @17:16 +IDENTIFIER @17:17 id Tag Tags.Tag [t static package interface] : annotated.Tags$Tag @java.lang.annotation.Target : annotated.Tags$Tag +TOKEN @17:17 +ARGUMENTS +TOKEN @17:21 +TOKEN @17:45 +IDENTIFIER @17:46 id Inner QualifiedTypeAnnotations.Inner [t package] : annotated.QualifiedTypeAnnotations$Inner : annotated.QualifiedTypeAnnotations$Inner +TOKEN @17:46 +IDENTIFIER @17:52 id m QualifiedTypeAnnotations.m [m abstract package] : ? () returns annotated.QualifiedTypeAnnotations$Inner throws [] sig annotated.QualifiedTypeAnnotations#m()Lannotated/QualifiedTypeAnnotations$Inner; : annotated.QualifiedTypeAnnotations$Inner +TOKEN @17:52 +TOKEN @17:53 +TOKEN @17:54 +TOKEN @17:55 +TOKEN @18:1 +TOKEN @19:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/QualifiedTypeAnnotations.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/QualifiedTypeAnnotations.java new file mode 100644 index 00000000000..572928ea29d --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/QualifiedTypeAnnotations.java @@ -0,0 +1,18 @@ +package annotated; + +import annotated.Tags.Tag; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +class Tags { + @Target(ElementType.TYPE_USE) + @interface Tag { + } +} + +abstract class QualifiedTypeAnnotations { + class Inner { + } + + abstract @Tag QualifiedTypeAnnotations.Inner m(); +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/QualifiedTypeAnnotations.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/QualifiedTypeAnnotations.textproto.gz new file mode 100644 index 00000000000..47b1f35216c Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/QualifiedTypeAnnotations.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Statements.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Statements.expected.txt new file mode 100644 index 00000000000..7e4b54c565b --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Statements.expected.txt @@ -0,0 +1,897 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id io unknown : ? +TOKEN @1:13 +TOKEN @1:15 +IDENTIFIER @1:16 id FileReader unknown : ? +TOKEN @1:16 +TOKEN @1:26 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id io unknown : ? +TOKEN @2:13 +TOKEN @2:15 +IDENTIFIER @2:16 id IOException unknown : ? +TOKEN @2:16 +TOKEN @2:27 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id io unknown : ? +TOKEN @3:13 +TOKEN @3:15 +IDENTIFIER @3:16 id Reader unknown : ? +TOKEN @3:16 +TOKEN @3:22 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id util unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id List unknown : ? +TOKEN @4:18 +TOKEN @4:22 +CLASS @6:1 class .Statements [t package] : Statements super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] members [, lock, nothing, run, yields] lookupToString 0 outermost Statements annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Statements +MODIFIERS +TOKEN @6:1 +IDENTIFIER @6:7 id Statements .Statements [t package] : Statements : Statements +TOKEN @6:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @6:18 +VARIABLE @8:3 var Statements.lock [v final private] : java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [final, private] local false parameter false effectivelyFinal true constant null +MODIFIERS @8:3 +TOKEN @8:3 +TOKEN @8:11 +IDENTIFIER @8:17 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @8:17 +IDENTIFIER @8:24 id lock Statements.lock [v final private] : java.lang.Object : java.lang.Object +TOKEN @8:24 +TOKEN @8:29 +NEW_CLASS @8:31 new Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : java.lang.Object + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Object flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @8:31 +IDENTIFIER @8:35 id Object Object. [m public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate () returns void throws [] sig java.lang.Object#()V : java.lang.Object +TOKEN @8:35 +ARGUMENTS @8:41 +TOKEN @8:41 +TOKEN @8:42 +TOKEN @8:43 +METHOD @10:3 method Statements.run [m package] : ? (java.lang.String,java.util.List) returns int throws [java.io.IOException] sig Statements#run(Ljava/lang/String;Ljava/util/List;)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [s, items] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @10:3 : int +TOKEN @10:3 +IDENTIFIER @10:7 id run Statements.run [m package] : ? (java.lang.String,java.util.List) returns int throws [java.io.IOException] sig Statements#run(Ljava/lang/String;Ljava/util/List;)I : int +TOKEN @10:7 +TOKEN @10:10 +VARIABLE @10:11 var run.s [v package] : java.lang.String + details declared true usages 5 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] local true parameter true effectivelyFinal true constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @10:11 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @10:11 +IDENTIFIER @10:18 id s run.s [v package] : java.lang.String : java.lang.String +TOKEN @10:18 +TOKEN @10:19 +VARIABLE @10:21 var run.items [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Statements flags [package] local true parameter true effectivelyFinal true constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PARAMETERIZED_TYPE @10:21 : java.util.List +IDENTIFIER @10:21 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @10:21 +TYPE_ARGUMENTS @10:25 +TOKEN @10:25 +IDENTIFIER @10:26 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @10:26 +TOKEN @10:32 +IDENTIFIER @10:34 id items run.items [v package] : java.util.List : java.util.List +TOKEN @10:34 +TOKEN @10:39 +TOKEN @10:41 +LIST @10:48 +IDENTIFIER @10:48 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @10:48 +BLOCK @10:60 +TOKEN @10:60 +VARIABLE @11:5 var run.total [v package] : int + details declared true usages 19 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] local true parameter false effectivelyFinal false constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @11:5 : int +TOKEN @11:5 +IDENTIFIER @11:9 id total run.total [v package] : int : int +TOKEN @11:9 +TOKEN @11:15 +INT_LITERAL @11:17 : int = 0 +TOKEN @11:17 +TOKEN @11:18 +VARIABLE @12:5 var run.limit [v final package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [final, package] local true parameter false effectivelyFinal true constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS @12:5 +TOKEN @12:5 +PRIMITIVE_TYPE @12:11 : int +TOKEN @12:11 +IDENTIFIER @12:15 id limit run.limit [v final package] : int : int +TOKEN @12:15 +TOKEN @12:21 +INT_LITERAL @12:23 : int = 10 +TOKEN @12:23 +TOKEN @12:25 +VARIABLE @13:5 var run.inferred [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] local true parameter false effectivelyFinal true constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +VAR_TYPE @13:5 +TOKEN @13:5 +IDENTIFIER @13:9 id inferred run.inferred [v package] : java.lang.String : java.lang.String +TOKEN @13:9 +TOKEN @13:18 +STRING_LITERAL @13:20 : java.lang.String = local +TOKEN @13:20 +TOKEN @13:27 +FOR_STATEMENT @14:5 +TOKEN @14:5 +TOKEN @14:9 +LIST @14:10 +VARIABLE @14:10 var run.i [v package] : int + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] local true parameter false effectivelyFinal false constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @14:10 : int +TOKEN @14:10 +IDENTIFIER @14:14 id i run.i [v package] : int : int +TOKEN @14:14 +TOKEN @14:16 +INT_LITERAL @14:18 : int = 0 +TOKEN @14:18 +TOKEN @14:19 +VARIABLE @14:10 var run.j [v package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] local true parameter false effectivelyFinal false constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @14:10 : int +TOKEN @14:10 +IDENTIFIER @14:21 id j run.j [v package] : int : int +TOKEN @14:21 +TOKEN @14:23 +INT_LITERAL @14:25 : int = 1 +TOKEN @14:25 +TOKEN @14:26 +LESS_THAN @14:28 : boolean +IDENTIFIER @14:28 id i run.i [v package] : int : int +TOKEN @14:28 +TOKEN @14:30 +METHOD_INVOCATION @14:32 call String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [CharSequence.length[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @14:32 : ? +IDENTIFIER @14:32 id s run.s [v package] : java.lang.String : java.lang.String +TOKEN @14:32 +TOKEN @14:33 +IDENTIFIER @14:34 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @14:34 +ARGUMENTS @14:40 +TOKEN @14:40 +TOKEN @14:41 +TOKEN @14:42 +LIST @14:44 +EXPRESSION_STATEMENT @14:44 +POSTFIX_INCREMENT @14:44 : int +IDENTIFIER @14:44 id i run.i [v package] : int : int +TOKEN @14:44 +TOKEN @14:45 +TOKEN @14:47 +EXPRESSION_STATEMENT @14:49 +POSTFIX_INCREMENT @14:49 : int +IDENTIFIER @14:49 id j run.j [v package] : int : int +TOKEN @14:49 +TOKEN @14:50 +TOKEN @14:52 +BLOCK @14:54 +TOKEN @14:54 +IF_STATEMENT @15:7 +TOKEN @15:7 +TOKEN @15:10 +EQUAL_TO @15:11 : boolean +METHOD_INVOCATION @15:11 call String.charAt [m public] : ? (int) returns char throws [] sig java.lang.String#charAt(I)C : char + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [CharSequence.charAt[]] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @15:11 : ? +IDENTIFIER @15:11 id s run.s [v package] : java.lang.String : java.lang.String +TOKEN @15:11 +TOKEN @15:12 +IDENTIFIER @15:13 id charAt String.charAt [m public] : ? (int) returns char throws [] sig java.lang.String#charAt(I)C : char +TOKEN @15:13 +ARGUMENTS @15:19 +TOKEN @15:19 +IDENTIFIER @15:20 id i run.i [v package] : int : int +TOKEN @15:20 +TOKEN @15:21 +TOKEN @15:23 +CHAR_LITERAL @15:26 : char = 120 +TOKEN @15:26 +TOKEN @15:29 +BLOCK @15:31 +TOKEN @15:31 +CONTINUE_STATEMENT @16:9 +TOKEN @16:9 +TOKEN @16:17 +TOKEN @17:7 +TOKEN @17:9 +IF_STATEMENT @17:14 +TOKEN @17:14 +TOKEN @17:17 +EQUAL_TO @17:18 : boolean +METHOD_INVOCATION @17:18 call String.charAt [m public] : ? (int) returns char throws [] sig java.lang.String#charAt(I)C : char + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [CharSequence.charAt[]] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @17:18 : ? +IDENTIFIER @17:18 id s run.s [v package] : java.lang.String : java.lang.String +TOKEN @17:18 +TOKEN @17:19 +IDENTIFIER @17:20 id charAt String.charAt [m public] : ? (int) returns char throws [] sig java.lang.String#charAt(I)C : char +TOKEN @17:20 +ARGUMENTS @17:26 +TOKEN @17:26 +IDENTIFIER @17:27 id i run.i [v package] : int : int +TOKEN @17:27 +TOKEN @17:28 +TOKEN @17:30 +CHAR_LITERAL @17:33 : char = 121 +TOKEN @17:33 +TOKEN @17:36 +BLOCK @17:38 +TOKEN @17:38 +BREAK_STATEMENT @18:9 +TOKEN @18:9 +TOKEN @18:14 +TOKEN @19:7 +TOKEN @19:9 +BLOCK @19:14 +TOKEN @19:14 +EXPRESSION_STATEMENT @20:9 +PLUS_ASSIGNMENT @20:9 : int +IDENTIFIER @20:9 id total run.total [v package] : int : int +TOKEN @20:9 +TOKEN @20:15 +IDENTIFIER @20:18 id j run.j [v package] : int : int +TOKEN @20:18 +TOKEN @20:19 +TOKEN @21:7 +TOKEN @22:5 +FOR_EACH_STATEMENT @23:5 +TOKEN @23:5 +TOKEN @23:9 +VARIABLE @23:10 var run.item [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] local true parameter false effectivelyFinal true constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @23:10 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @23:10 +IDENTIFIER @23:17 id item run.item [v package] : java.lang.String : java.lang.String +TOKEN @23:17 +TOKEN @23:22 +IDENTIFIER @23:24 id items run.items [v package] : java.util.List : java.util.List +TOKEN @23:24 +TOKEN @23:29 +BLOCK @23:31 +TOKEN @23:31 +EXPRESSION_STATEMENT @24:7 +PLUS_ASSIGNMENT @24:7 : int +IDENTIFIER @24:7 id total run.total [v package] : int : int +TOKEN @24:7 +TOKEN @24:13 +METHOD_INVOCATION @24:16 call String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [CharSequence.length[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @24:16 : ? +IDENTIFIER @24:16 id item run.item [v package] : java.lang.String : java.lang.String +TOKEN @24:16 +TOKEN @24:20 +IDENTIFIER @24:21 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @24:21 +ARGUMENTS @24:27 +TOKEN @24:27 +TOKEN @24:28 +TOKEN @24:29 +TOKEN @25:5 +FOR_STATEMENT @26:5 +TOKEN @26:5 +TOKEN @26:9 +LIST +TOKEN @26:10 +TOKEN @26:11 +LIST +TOKEN @26:12 +BLOCK @26:14 +TOKEN @26:14 +BREAK_STATEMENT @27:7 +TOKEN @27:7 +TOKEN @27:12 +TOKEN @28:5 +WHILE_STATEMENT @29:5 +TOKEN @29:5 +TOKEN @29:11 +GREATER_THAN @29:12 : boolean +IDENTIFIER @29:12 id total run.total [v package] : int : int +TOKEN @29:12 +TOKEN @29:18 +IDENTIFIER @29:20 id limit run.limit [v final package] : int : int +TOKEN @29:20 +TOKEN @29:25 +BLOCK @29:27 +TOKEN @29:27 +EXPRESSION_STATEMENT @30:7 +POSTFIX_DECREMENT @30:7 : int +IDENTIFIER @30:7 id total run.total [v package] : int : int +TOKEN @30:7 +TOKEN @30:12 +TOKEN @30:14 +TOKEN @31:5 +DO_STATEMENT @32:5 +TOKEN @32:5 +BLOCK @32:8 +TOKEN @32:8 +EXPRESSION_STATEMENT @33:7 +POSTFIX_INCREMENT @33:7 : int +IDENTIFIER @33:7 id total run.total [v package] : int : int +TOKEN @33:7 +TOKEN @33:12 +TOKEN @33:14 +TOKEN @34:5 +TOKEN @34:7 +TOKEN @34:13 +LESS_THAN @34:14 : boolean +IDENTIFIER @34:14 id total run.total [v package] : int : int +TOKEN @34:14 +TOKEN @34:20 +INT_LITERAL @34:22 : int = 3 +TOKEN @34:22 +TOKEN @34:23 +TOKEN @34:24 +LABELED_STATEMENT @35:5 +IDENTIFIER @35:5 id outer unknown : ? +TOKEN @35:5 +TOKEN @35:10 +FOR_STATEMENT @36:5 +TOKEN @36:5 +TOKEN @36:9 +LIST @36:10 +VARIABLE @36:10 var run.i [v package] : int + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] local true parameter false effectivelyFinal false constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @36:10 : int +TOKEN @36:10 +IDENTIFIER @36:14 id i run.i [v package] : int : int +TOKEN @36:14 +TOKEN @36:16 +INT_LITERAL @36:18 : int = 0 +TOKEN @36:18 +TOKEN @36:19 +LESS_THAN @36:21 : boolean +IDENTIFIER @36:21 id i run.i [v package] : int : int +TOKEN @36:21 +TOKEN @36:23 +INT_LITERAL @36:25 : int = 3 +TOKEN @36:25 +TOKEN @36:26 +LIST @36:28 +EXPRESSION_STATEMENT @36:28 +POSTFIX_INCREMENT @36:28 : int +IDENTIFIER @36:28 id i run.i [v package] : int : int +TOKEN @36:28 +TOKEN @36:29 +TOKEN @36:31 +BLOCK @36:33 +TOKEN @36:33 +FOR_STATEMENT @37:7 +TOKEN @37:7 +TOKEN @37:11 +LIST @37:12 +VARIABLE @37:12 var run.j [v package] : int + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] local true parameter false effectivelyFinal false constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @37:12 : int +TOKEN @37:12 +IDENTIFIER @37:16 id j run.j [v package] : int : int +TOKEN @37:16 +TOKEN @37:18 +INT_LITERAL @37:20 : int = 0 +TOKEN @37:20 +TOKEN @37:21 +LESS_THAN @37:23 : boolean +IDENTIFIER @37:23 id j run.j [v package] : int : int +TOKEN @37:23 +TOKEN @37:25 +INT_LITERAL @37:27 : int = 3 +TOKEN @37:27 +TOKEN @37:28 +LIST @37:30 +EXPRESSION_STATEMENT @37:30 +POSTFIX_INCREMENT @37:30 : int +IDENTIFIER @37:30 id j run.j [v package] : int : int +TOKEN @37:30 +TOKEN @37:31 +TOKEN @37:33 +BLOCK @37:35 +TOKEN @37:35 +IF_STATEMENT @38:9 +TOKEN @38:9 +TOKEN @38:12 +EQUAL_TO @38:13 : boolean +IDENTIFIER @38:13 id i run.i [v package] : int : int +TOKEN @38:13 +TOKEN @38:15 +IDENTIFIER @38:18 id j run.j [v package] : int : int +TOKEN @38:18 +TOKEN @38:19 +BLOCK @38:21 +TOKEN @38:21 +CONTINUE_STATEMENT @39:11 +TOKEN @39:11 +IDENTIFIER @39:20 id outer outer [] : ? : ? +TOKEN @39:20 +TOKEN @39:25 +TOKEN @40:9 +IF_STATEMENT @41:9 +TOKEN @41:9 +TOKEN @41:12 +GREATER_THAN @41:13 : boolean +IDENTIFIER @41:13 id i run.i [v package] : int : int +TOKEN @41:13 +TOKEN @41:15 +IDENTIFIER @41:17 id j run.j [v package] : int : int +TOKEN @41:17 +TOKEN @41:18 +BLOCK @41:20 +TOKEN @41:20 +BREAK_STATEMENT @42:11 +TOKEN @42:11 +IDENTIFIER @42:17 id outer outer [] : ? : ? +TOKEN @42:17 +TOKEN @42:22 +TOKEN @43:9 +TOKEN @44:7 +TOKEN @45:5 +SWITCH_STATEMENT @46:5 : ? +TOKEN @46:5 +TOKEN @46:12 +IDENTIFIER @46:13 id s run.s [v package] : java.lang.String : java.lang.String +TOKEN @46:13 +TOKEN @46:14 +TOKEN @46:16 +CASE_GROUP @47:7 +CASE_LABEL @47:7 +TOKEN @47:7 +STRING_LITERAL @47:12 : java.lang.String = a +TOKEN @47:12 +TOKEN @47:15 +CASE_LABEL @48:7 +TOKEN @48:7 +STRING_LITERAL @48:12 : java.lang.String = b +TOKEN @48:12 +TOKEN @48:15 +EXPRESSION_STATEMENT @49:9 +ASSIGNMENT @49:9 : int +IDENTIFIER @49:9 id total run.total [v package] : int : int +TOKEN @49:9 +TOKEN @49:15 +INT_LITERAL @49:17 : int = 1 +TOKEN @49:17 +TOKEN @49:18 +BREAK_STATEMENT @50:9 +TOKEN @50:9 +TOKEN @50:14 +CASE_GROUP @51:7 +CASE_LABEL @51:7 +TOKEN @51:7 +STRING_LITERAL @51:12 : java.lang.String = c +TOKEN @51:12 +TOKEN @51:15 +EXPRESSION_STATEMENT @52:9 +ASSIGNMENT @52:9 : int +IDENTIFIER @52:9 id total run.total [v package] : int : int +TOKEN @52:9 +TOKEN @52:15 +INT_LITERAL @52:17 : int = 2 +TOKEN @52:17 +TOKEN @52:18 +CASE_GROUP @53:7 +CASE_LABEL @53:7 +TOKEN @53:7 +TOKEN @53:14 +EXPRESSION_STATEMENT @54:9 +ASSIGNMENT @54:9 : int +IDENTIFIER @54:9 id total run.total [v package] : int : int +TOKEN @54:9 +TOKEN @54:15 +INT_LITERAL @54:17 : int = 3 +TOKEN @54:17 +TOKEN @54:18 +TOKEN @55:5 +SWITCH_STATEMENT @56:5 : ? +TOKEN @56:5 +TOKEN @56:12 +IDENTIFIER @56:13 id total run.total [v package] : int : int +TOKEN @56:13 +TOKEN @56:18 +TOKEN @56:20 +CASE_GROUP @57:7 +CASE_LABEL @57:7 +TOKEN @57:7 +INT_LITERAL @57:12 : int = 1 +TOKEN @57:12 +TOKEN @57:14 +YIELD_STATEMENT @57:17 +ASSIGNMENT @57:17 : int +IDENTIFIER @57:17 id total run.total [v package] : int : int +TOKEN @57:17 +TOKEN @57:23 +INT_LITERAL @57:25 : int = 10 +TOKEN @57:25 +TOKEN @57:27 +CASE_GROUP @58:7 +CASE_LABEL @58:7 +TOKEN @58:7 +INT_LITERAL @58:12 : int = 2 +TOKEN @58:12 +INT_LITERAL @58:15 : int = 3 +TOKEN @58:15 +TOKEN @58:17 +BLOCK @58:20 +TOKEN @58:20 +EXPRESSION_STATEMENT @59:9 +ASSIGNMENT @59:9 : int +IDENTIFIER @59:9 id total run.total [v package] : int : int +TOKEN @59:9 +TOKEN @59:15 +INT_LITERAL @59:17 : int = 20 +TOKEN @59:17 +TOKEN @59:19 +TOKEN @60:7 +CASE_GROUP @61:7 +CASE_LABEL @61:7 +TOKEN @61:7 +TOKEN @61:15 +THROW_STATEMENT @61:18 +TOKEN @61:18 +NEW_CLASS @61:24 new IllegalStateException. [m public] : ? () returns void throws [] sig java.lang.IllegalStateException#()V : java.lang.IllegalStateException + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing IllegalStateException flags [public] overridden [RuntimeException.[], Exception.[], Throwable.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @61:24 +IDENTIFIER @61:28 id IllegalStateException IllegalStateException. [m public] : ? () returns void throws [] sig java.lang.IllegalStateException#()V : java.lang.IllegalStateException +TOKEN @61:28 +ARGUMENTS @61:49 +TOKEN @61:49 +TOKEN @61:50 +TOKEN @61:51 +TOKEN @62:5 +TRY_STATEMENT @63:5 +TOKEN @63:5 +TOKEN @63:9 +LIST @63:10 +VARIABLE @63:10 var run.reader [v final package] : java.io.Reader + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [final, package] local true parameter false effectivelyFinal true constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @63:10 id Reader java.io.Reader [t abstract public] : java.io.Reader : java.io.Reader +TOKEN @63:10 +IDENTIFIER @63:17 id reader run.reader [v final package] : java.io.Reader : java.io.Reader +TOKEN @63:17 +TOKEN @63:24 +NEW_CLASS @63:26 new FileReader. [m public] : ? (java.lang.String) returns void throws [java.io.FileNotFoundException] sig java.io.FileReader#(Ljava/lang/String;)V : java.io.FileReader + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing FileReader flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @63:26 +IDENTIFIER @63:30 id FileReader FileReader. [m public] : ? (java.lang.String) returns void throws [java.io.FileNotFoundException] sig java.io.FileReader#(Ljava/lang/String;)V : java.io.FileReader +TOKEN @63:30 +ARGUMENTS @63:40 +TOKEN @63:40 +IDENTIFIER @63:41 id s run.s [v package] : java.lang.String : java.lang.String +TOKEN @63:41 +TOKEN @63:42 +TOKEN @63:43 +VARIABLE @63:45 var run.other [v final package] : java.io.Reader + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [final, package] local true parameter false effectivelyFinal true constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @63:45 id Reader java.io.Reader [t abstract public] : java.io.Reader : java.io.Reader +TOKEN @63:45 +IDENTIFIER @63:52 id other run.other [v final package] : java.io.Reader : java.io.Reader +TOKEN @63:52 +TOKEN @63:58 +NEW_CLASS @63:60 new FileReader. [m public] : ? (java.lang.String) returns void throws [java.io.FileNotFoundException] sig java.io.FileReader#(Ljava/lang/String;)V : java.io.FileReader + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing FileReader flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @63:60 +IDENTIFIER @63:64 id FileReader FileReader. [m public] : ? (java.lang.String) returns void throws [java.io.FileNotFoundException] sig java.io.FileReader#(Ljava/lang/String;)V : java.io.FileReader +TOKEN @63:64 +ARGUMENTS @63:74 +TOKEN @63:74 +IDENTIFIER @63:75 id inferred run.inferred [v package] : java.lang.String : java.lang.String +TOKEN @63:75 +TOKEN @63:83 +TOKEN @63:84 +BLOCK @63:86 +TOKEN @63:86 +EXPRESSION_STATEMENT @64:7 +PLUS_ASSIGNMENT @64:7 : int +IDENTIFIER @64:7 id total run.total [v package] : int : int +TOKEN @64:7 +TOKEN @64:13 +PLUS @64:16 : int +METHOD_INVOCATION @64:16 call Reader.read [m public] : ? () returns int throws [java.io.IOException] sig java.io.Reader#read()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Reader flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @64:16 : ? +IDENTIFIER @64:16 id reader run.reader [v final package] : java.io.Reader : java.io.Reader +TOKEN @64:16 +TOKEN @64:22 +IDENTIFIER @64:23 id read Reader.read [m public] : ? () returns int throws [java.io.IOException] sig java.io.Reader#read()I : int +TOKEN @64:23 +ARGUMENTS @64:27 +TOKEN @64:27 +TOKEN @64:28 +TOKEN @64:30 +METHOD_INVOCATION @64:32 call Reader.read [m public] : ? () returns int throws [java.io.IOException] sig java.io.Reader#read()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Reader flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @64:32 : ? +IDENTIFIER @64:32 id other run.other [v final package] : java.io.Reader : java.io.Reader +TOKEN @64:32 +TOKEN @64:37 +IDENTIFIER @64:38 id read Reader.read [m public] : ? () returns int throws [java.io.IOException] sig java.io.Reader#read()I : int +TOKEN @64:38 +ARGUMENTS @64:42 +TOKEN @64:42 +TOKEN @64:43 +TOKEN @64:44 +TOKEN @65:5 +CATCH @65:7 +TOKEN @65:7 +TOKEN @65:13 +VARIABLE @65:14 var run.e [v final package] : java.lang.RuntimeException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [final, package] local true parameter false effectivelyFinal true constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +UNION_TYPE @65:14 +LIST @65:14 +IDENTIFIER @65:14 id IllegalStateException java.lang.IllegalStateException [t public] : java.lang.IllegalStateException : java.lang.IllegalStateException +TOKEN @65:14 +TOKEN @65:36 +IDENTIFIER @65:38 id IllegalArgumentException java.lang.IllegalArgumentException [t public] : java.lang.IllegalArgumentException : java.lang.IllegalArgumentException +TOKEN @65:38 +IDENTIFIER @65:63 id e run.e [v final package] : java.lang.RuntimeException : java.lang.RuntimeException +TOKEN @65:63 +TOKEN @65:64 +BLOCK @65:66 +TOKEN @65:66 +THROW_STATEMENT @66:7 +TOKEN @66:7 +NEW_CLASS @66:13 new RuntimeException. [m public] : ? (java.lang.Throwable) returns void throws [] sig java.lang.RuntimeException#(Ljava/lang/Throwable;)V : java.lang.RuntimeException + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing RuntimeException flags [public] overridden [Exception.[], Throwable.[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @66:13 +IDENTIFIER @66:17 id RuntimeException RuntimeException. [m public] : ? (java.lang.Throwable) returns void throws [] sig java.lang.RuntimeException#(Ljava/lang/Throwable;)V : java.lang.RuntimeException +TOKEN @66:17 +ARGUMENTS @66:33 +TOKEN @66:33 +IDENTIFIER @66:34 id e run.e [v final package] : java.lang.RuntimeException : java.lang.RuntimeException +TOKEN @66:34 +TOKEN @66:35 +TOKEN @66:36 +TOKEN @67:5 +CATCH @67:7 +TOKEN @67:7 +TOKEN @67:13 +VARIABLE @67:14 var run.e [v package] : java.io.IOException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] local true parameter false effectivelyFinal true constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +IDENTIFIER @67:14 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @67:14 +IDENTIFIER @67:26 id e run.e [v package] : java.io.IOException : java.io.IOException +TOKEN @67:26 +TOKEN @67:27 +BLOCK @67:29 +TOKEN @67:29 +THROW_STATEMENT @68:7 +TOKEN @68:7 +IDENTIFIER @68:13 id e run.e [v package] : java.io.IOException : java.io.IOException +TOKEN @68:13 +TOKEN @68:14 +TOKEN @69:5 +TOKEN @69:7 +BLOCK @69:15 +TOKEN @69:15 +EXPRESSION_STATEMENT @70:7 +ASSIGNMENT @70:7 : int +IDENTIFIER @70:7 id total run.total [v package] : int : int +TOKEN @70:7 +TOKEN @70:13 +INT_LITERAL @70:15 : int = 0 +TOKEN @70:15 +TOKEN @70:16 +TOKEN @71:5 +SYNCHRONIZED_STATEMENT @72:5 +TOKEN @72:5 +TOKEN @72:18 +IDENTIFIER @72:19 id lock Statements.lock [v final private] : java.lang.Object : java.lang.Object +TOKEN @72:19 +TOKEN @72:23 +BLOCK @72:25 +TOKEN @72:25 +EXPRESSION_STATEMENT @73:7 +POSTFIX_INCREMENT @73:7 : int +IDENTIFIER @73:7 id total run.total [v package] : int : int +TOKEN @73:7 +TOKEN @73:12 +TOKEN @73:14 +TOKEN @74:5 +ASSERT_STATEMENT @75:5 +TOKEN @75:5 +GREATER_THAN_OR_EQUAL_TO @75:12 : boolean +IDENTIFIER @75:12 id total run.total [v package] : int : int +TOKEN @75:12 +TOKEN @75:18 +INT_LITERAL @75:21 : int = 0 +TOKEN @75:21 +TOKEN @75:23 +STRING_LITERAL @75:25 : java.lang.String = negative +TOKEN @75:25 +TOKEN @75:35 +EMPTY_STATEMENT @76:5 +TOKEN @76:5 +BLOCK @77:5 +TOKEN @77:5 +VARIABLE @78:7 var run.scoped [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] local true parameter false effectivelyFinal true constant null owner run Statements#run(Ljava/lang/String;Ljava/util/List;)I [package] returns int parameters 2 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +PRIMITIVE_TYPE @78:7 : int +TOKEN @78:7 +IDENTIFIER @78:11 id scoped run.scoped [v package] : int : int +TOKEN @78:11 +TOKEN @78:18 +INT_LITERAL @78:20 : int = 1 +TOKEN @78:20 +TOKEN @78:21 +EXPRESSION_STATEMENT @79:7 +PLUS_ASSIGNMENT @79:7 : int +IDENTIFIER @79:7 id total run.total [v package] : int : int +TOKEN @79:7 +TOKEN @79:13 +IDENTIFIER @79:16 id scoped run.scoped [v package] : int : int +TOKEN @79:16 +TOKEN @79:22 +TOKEN @80:5 +CLASS @81:5 class unknown super java.lang.Object interfaces [] +MODIFIERS +TOKEN @81:5 +IDENTIFIER @81:11 id Local unknown : ? +TOKEN @81:11 +TYPE_PARAMETERS +LIST +LIST +TOKEN @81:17 +METHOD @82:7 method Local.value [m package] : ? () returns int throws [] sig Statements$1Local#value()I overrides null + details declared true usages 1 metadata [] nullability UNKNOWN/METHOD nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Local flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @82:7 : int +TOKEN @82:7 +IDENTIFIER @82:11 id value Local.value [m package] : ? () returns int throws [] sig Statements$1Local#value()I : int +TOKEN @82:11 +TOKEN @82:16 +TOKEN @82:17 +BLOCK @82:19 +TOKEN @82:19 +RETURN_STATEMENT @83:9 +TOKEN @83:9 +IDENTIFIER @83:16 id limit run.limit [v final package] : int : int +TOKEN @83:16 +TOKEN @83:21 +TOKEN @84:7 +TOKEN @85:5 +EXPRESSION_STATEMENT @86:5 +PLUS_ASSIGNMENT @86:5 : int +IDENTIFIER @86:5 id total run.total [v package] : int : int +TOKEN @86:5 +TOKEN @86:11 +METHOD_INVOCATION @86:14 call Local.value [m package] : ? () returns int throws [] sig Statements$1Local#value()I : int + details declared true usages 1 metadata [] nullability UNKNOWN/METHOD nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Local flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @86:14 : ? +NEW_CLASS @86:14 new Local. [m package] : ? () returns void throws [] sig Statements$1Local#()V : ? + details declared false usages 1 metadata [] nullability UNKNOWN/METHOD nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Local flags [package] overridden [Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @86:14 +IDENTIFIER @86:18 id Local Local. [m package] : ? () returns void throws [] sig Statements$1Local#()V : ? +TOKEN @86:18 +ARGUMENTS @86:23 +TOKEN @86:23 +TOKEN @86:24 +TOKEN @86:25 +IDENTIFIER @86:26 id value Local.value [m package] : ? () returns int throws [] sig Statements$1Local#value()I : int +TOKEN @86:26 +ARGUMENTS @86:31 +TOKEN @86:31 +TOKEN @86:32 +TOKEN @86:33 +RETURN_STATEMENT @87:5 +TOKEN @87:5 +IDENTIFIER @87:12 id total run.total [v package] : int : int +TOKEN @87:12 +TOKEN @87:17 +TOKEN @88:3 +METHOD @90:3 method Statements.nothing [m package] : ? () returns void throws [] sig Statements#nothing()V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @90:3 : void +TOKEN @90:3 +IDENTIFIER @90:8 id nothing Statements.nothing [m package] : ? () returns void throws [] sig Statements#nothing()V : void +TOKEN @90:8 +TOKEN @90:15 +TOKEN @90:16 +BLOCK @90:18 +TOKEN @90:18 +RETURN_STATEMENT @91:5 +TOKEN @91:5 +TOKEN @91:11 +TOKEN @92:3 +METHOD @94:3 method Statements.yields [m package] : ? (int) returns int throws [] sig Statements#yields(I)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [k] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @94:3 : int +TOKEN @94:3 +IDENTIFIER @94:7 id yields Statements.yields [m package] : ? (int) returns int throws [] sig Statements#yields(I)I : int +TOKEN @94:7 +TOKEN @94:13 +VARIABLE @94:14 var yields.k [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Statements flags [package] local true parameter true effectivelyFinal true constant null owner yields Statements#yields(I)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Statements type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @94:14 : int +TOKEN @94:14 +IDENTIFIER @94:18 id k yields.k [v package] : int : int +TOKEN @94:18 +TOKEN @94:19 +BLOCK @94:21 +TOKEN @94:21 +RETURN_STATEMENT @95:5 +TOKEN @95:5 +SWITCH_EXPRESSION @95:12 : int +TOKEN @95:12 +TOKEN @95:19 +IDENTIFIER @95:20 id k yields.k [v package] : int : int +TOKEN @95:20 +TOKEN @95:21 +TOKEN @95:23 +CASE_GROUP @96:7 +CASE_LABEL @96:7 +TOKEN @96:7 +INT_LITERAL @96:12 : int = 1 +TOKEN @96:12 +TOKEN @96:13 +YIELD_STATEMENT @97:9 +TOKEN @97:9 +INT_LITERAL @97:15 : int = 10 +TOKEN @97:15 +TOKEN @97:17 +CASE_GROUP @98:7 +CASE_LABEL @98:7 +TOKEN @98:7 +TOKEN @98:14 +YIELD_STATEMENT @99:9 +TOKEN @99:9 +INT_LITERAL @99:15 : int = 0 +TOKEN @99:15 +TOKEN @99:16 +TOKEN @100:5 +TOKEN @100:6 +TOKEN @101:3 +TOKEN @102:1 +TOKEN @103:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Statements.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Statements.java new file mode 100644 index 00000000000..d774cadb365 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Statements.java @@ -0,0 +1,102 @@ +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.util.List; + +class Statements { + + private final Object lock = new Object(); + + int run(String s, List items) throws IOException { + int total = 0; + final int limit = 10; + var inferred = "local"; + for (int i = 0, j = 1; i < s.length(); i++, j++) { + if (s.charAt(i) == 'x') { + continue; + } else if (s.charAt(i) == 'y') { + break; + } else { + total += j; + } + } + for (String item : items) { + total += item.length(); + } + for (;;) { + break; + } + while (total > limit) { + total--; + } + do { + total++; + } while (total < 3); + outer: + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (i == j) { + continue outer; + } + if (i > j) { + break outer; + } + } + } + switch (s) { + case "a": + case "b": + total = 1; + break; + case "c": + total = 2; + default: + total = 3; + } + switch (total) { + case 1 -> total = 10; + case 2, 3 -> { + total = 20; + } + default -> throw new IllegalStateException(); + } + try (Reader reader = new FileReader(s); Reader other = new FileReader(inferred)) { + total += reader.read() + other.read(); + } catch (IllegalStateException | IllegalArgumentException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw e; + } finally { + total = 0; + } + synchronized (lock) { + total++; + } + assert total >= 0 : "negative"; + ; + { + int scoped = 1; + total += scoped; + } + class Local { + int value() { + return limit; + } + } + total += new Local().value(); + return total; + } + + void nothing() { + return; + } + + int yields(int k) { + return switch (k) { + case 1: + yield 10; + default: + yield 0; + }; + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Statements.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Statements.textproto.gz new file mode 100644 index 00000000000..e3bcf5f0b93 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Statements.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/StaticImports.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/StaticImports.expected.txt new file mode 100644 index 00000000000..ff59071f3b0 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/StaticImports.expected.txt @@ -0,0 +1,413 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +TOKEN @1:8 +MEMBER_SELECT @1:15 : ? +MEMBER_SELECT @1:15 : ? +MEMBER_SELECT @1:15 : ? +IDENTIFIER @1:15 id java unknown : ? +TOKEN @1:15 +TOKEN @1:19 +IDENTIFIER @1:20 id lang unknown : ? +TOKEN @1:20 +TOKEN @1:24 +IDENTIFIER @1:25 id Math unknown : ? +TOKEN @1:25 +TOKEN @1:29 +IDENTIFIER @1:30 id * unknown : ? +TOKEN @1:30 +TOKEN @1:31 +IMPORT @2:1 +TOKEN @2:1 +TOKEN @2:8 +MEMBER_SELECT @2:15 : ? +MEMBER_SELECT @2:15 : ? +MEMBER_SELECT @2:15 : ? +IDENTIFIER @2:15 id java unknown : ? +TOKEN @2:15 +TOKEN @2:19 +IDENTIFIER @2:20 id util unknown : ? +TOKEN @2:20 +TOKEN @2:24 +IDENTIFIER @2:25 id Map unknown : ? +TOKEN @2:25 +TOKEN @2:28 +IDENTIFIER @2:29 id Entry unknown : ? +TOKEN @2:29 +TOKEN @2:34 +IMPORT @3:1 +TOKEN @3:1 +TOKEN @3:8 +MEMBER_SELECT @3:15 : ? +MEMBER_SELECT @3:15 : ? +MEMBER_SELECT @3:15 : ? +MEMBER_SELECT @3:15 : ? +IDENTIFIER @3:15 id java unknown : ? +TOKEN @3:15 +TOKEN @3:19 +IDENTIFIER @3:20 id util unknown : ? +TOKEN @3:20 +TOKEN @3:24 +IDENTIFIER @3:25 id concurrent unknown : ? +TOKEN @3:25 +TOKEN @3:35 +IDENTIFIER @3:36 id TimeUnit unknown : ? +TOKEN @3:36 +TOKEN @3:44 +IDENTIFIER @3:45 id SECONDS unknown : ? +TOKEN @3:45 +TOKEN @3:52 +IMPORT @4:1 +TOKEN @4:1 +TOKEN @4:8 +MEMBER_SELECT @4:15 : ? +MEMBER_SELECT @4:15 : ? +MEMBER_SELECT @4:15 : ? +MEMBER_SELECT @4:15 : ? +IDENTIFIER @4:15 id java unknown : ? +TOKEN @4:15 +TOKEN @4:19 +IDENTIFIER @4:20 id util unknown : ? +TOKEN @4:20 +TOKEN @4:24 +IDENTIFIER @4:25 id Locale unknown : ? +TOKEN @4:25 +TOKEN @4:31 +IDENTIFIER @4:32 id Category unknown : ? +TOKEN @4:32 +TOKEN @4:40 +IDENTIFIER @4:41 id FORMAT unknown : ? +TOKEN @4:41 +TOKEN @4:47 +IMPORT @6:1 +TOKEN @6:1 +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +IDENTIFIER @6:8 id java unknown : ? +TOKEN @6:8 +TOKEN @6:12 +IDENTIFIER @6:13 id util unknown : ? +TOKEN @6:13 +TOKEN @6:17 +IDENTIFIER @6:18 id Locale unknown : ? +TOKEN @6:18 +TOKEN @6:24 +IMPORT @7:1 +TOKEN @7:1 +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +IDENTIFIER @7:8 id java unknown : ? +TOKEN @7:8 +TOKEN @7:12 +IDENTIFIER @7:13 id util unknown : ? +TOKEN @7:13 +TOKEN @7:17 +IDENTIFIER @7:18 id Map unknown : ? +TOKEN @7:18 +TOKEN @7:21 +IMPORT @8:1 +TOKEN @8:1 +MEMBER_SELECT @8:8 : ? +MEMBER_SELECT @8:8 : ? +MEMBER_SELECT @8:8 : ? +IDENTIFIER @8:8 id java unknown : ? +TOKEN @8:8 +TOKEN @8:12 +IDENTIFIER @8:13 id util unknown : ? +TOKEN @8:13 +TOKEN @8:17 +IDENTIFIER @8:18 id concurrent unknown : ? +TOKEN @8:18 +TOKEN @8:28 +IDENTIFIER @8:29 id TimeUnit unknown : ? +TOKEN @8:29 +TOKEN @8:37 +CLASS @10:1 class .StaticImports [t package] : StaticImports super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing StaticImports flags [package] members [, area, category, key, sum, timeout] lookupToString 0 outermost StaticImports annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring StaticImports +MODIFIERS +TOKEN @10:1 +IDENTIFIER @10:7 id StaticImports .StaticImports [t package] : StaticImports : StaticImports +TOKEN @10:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @10:21 +METHOD @11:3 method StaticImports.area [m package] : ? (double) returns double throws [] sig StaticImports#area(D)D overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StaticImports flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [radius] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @11:3 : double +TOKEN @11:3 +IDENTIFIER @11:10 id area StaticImports.area [m package] : ? (double) returns double throws [] sig StaticImports#area(D)D : double +TOKEN @11:10 +TOKEN @11:14 +VARIABLE @11:15 var area.radius [v package] : double + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StaticImports flags [package] local true parameter true effectivelyFinal true constant null owner area StaticImports#area(D)D [package] returns double parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing StaticImports type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @11:15 : double +TOKEN @11:15 +IDENTIFIER @11:22 id radius area.radius [v package] : double : double +TOKEN @11:22 +TOKEN @11:28 +BLOCK @11:30 +TOKEN @11:30 +RETURN_STATEMENT @12:5 +TOKEN @12:5 +MULTIPLY @12:12 : double +IDENTIFIER @12:12 id PI Math.PI [v static final public] : double : double = 3.141592653589793 +TOKEN @12:12 +TOKEN @12:15 +METHOD_INVOCATION @12:17 call Math.pow [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (double,double) returns double throws [] sig java.lang.Math#pow(DD)D : double + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Math flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +IDENTIFIER @12:17 id pow Math.pow [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (double,double) returns double throws [] sig java.lang.Math#pow(DD)D : double +TOKEN @12:17 +ARGUMENTS @12:20 +TOKEN @12:20 +IDENTIFIER @12:21 id radius area.radius [v package] : double : double +TOKEN @12:21 +TOKEN @12:27 +INT_LITERAL @12:29 : int = 2 +TOKEN @12:29 +TOKEN @12:30 +TOKEN @12:31 +TOKEN @13:3 +METHOD @15:3 method StaticImports.timeout [m package] : ? () returns long throws [] sig StaticImports#timeout()J overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StaticImports flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @15:3 : long +TOKEN @15:3 +IDENTIFIER @15:8 id timeout StaticImports.timeout [m package] : ? () returns long throws [] sig StaticImports#timeout()J : long +TOKEN @15:8 +TOKEN @15:15 +TOKEN @15:16 +BLOCK @15:18 +TOKEN @15:18 +VARIABLE @16:5 var timeout.unit [v package] : java.util.concurrent.TimeUnit + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StaticImports flags [package] local true parameter false effectivelyFinal true constant null owner timeout StaticImports#timeout()J [package] returns long parameters 0 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing StaticImports type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @16:5 id TimeUnit java.util.concurrent.TimeUnit [t final public enum] : java.util.concurrent.TimeUnit : java.util.concurrent.TimeUnit +TOKEN @16:5 +IDENTIFIER @16:14 id unit timeout.unit [v package] : java.util.concurrent.TimeUnit : java.util.concurrent.TimeUnit +TOKEN @16:14 +TOKEN @16:19 +IDENTIFIER @16:21 id SECONDS TimeUnit.SECONDS [v static final public enum] : java.util.concurrent.TimeUnit : java.util.concurrent.TimeUnit +TOKEN @16:21 +TOKEN @16:28 +RETURN_STATEMENT @17:5 +TOKEN @17:5 +METHOD_INVOCATION @17:12 call TimeUnit.toMillis [m public] : ? (long) returns long throws [] sig java.util.concurrent.TimeUnit#toMillis(J)J : long + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing TimeUnit flags [public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @17:12 : ? +IDENTIFIER @17:12 id unit timeout.unit [v package] : java.util.concurrent.TimeUnit : java.util.concurrent.TimeUnit +TOKEN @17:12 +TOKEN @17:16 +IDENTIFIER @17:17 id toMillis TimeUnit.toMillis [m public] : ? (long) returns long throws [] sig java.util.concurrent.TimeUnit#toMillis(J)J : long +TOKEN @17:17 +ARGUMENTS @17:25 +TOKEN @17:25 +METHOD_INVOCATION @17:26 call Math.max [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int,int) returns int throws [] sig java.lang.Math#max(II)I : int + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Math flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +IDENTIFIER @17:26 id max Math.max [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int,int) returns int throws [] sig java.lang.Math#max(II)I : int +TOKEN @17:26 +ARGUMENTS @17:29 +TOKEN @17:29 +INT_LITERAL @17:30 : int = 1 +TOKEN @17:30 +TOKEN @17:31 +METHOD_INVOCATION @17:33 call Math.abs [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int) returns int throws [] sig java.lang.Math#abs(I)I : int + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Math flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +IDENTIFIER @17:33 id abs Math.abs [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int) returns int throws [] sig java.lang.Math#abs(I)I : int +TOKEN @17:33 +ARGUMENTS @17:36 +TOKEN @17:36 +UNARY_MINUS @17:37 : int = -3 +TOKEN @17:37 +INT_LITERAL @17:38 : int = 3 +TOKEN @17:38 +TOKEN @17:39 +TOKEN @17:40 +TOKEN @17:41 +TOKEN @17:42 +TOKEN @18:3 +METHOD @20:3 method StaticImports.key [m package] : ? (java.util.Map$Entry) returns java.lang.String throws [] sig StaticImports#key(Ljava/util/Map$Entry;)Ljava/lang/String; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StaticImports flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [entry] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @20:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @20:3 +IDENTIFIER @20:10 id key StaticImports.key [m package] : ? (java.util.Map$Entry) returns java.lang.String throws [] sig StaticImports#key(Ljava/util/Map$Entry;)Ljava/lang/String; : java.lang.String +TOKEN @20:10 +TOKEN @20:13 +VARIABLE @20:14 var key.entry [v package] : java.util.Map$Entry + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing StaticImports flags [package] local true parameter true effectivelyFinal true constant null owner key StaticImports#key(Ljava/util/Map$Entry;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing StaticImports type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @20:14 : java.util.Map$Entry +IDENTIFIER @20:14 id Entry java.util.Entry [t static public interface] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @20:14 +TYPE_ARGUMENTS @20:19 +TOKEN @20:19 +IDENTIFIER @20:20 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @20:20 +TOKEN @20:26 +IDENTIFIER @20:28 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @20:28 +TOKEN @20:35 +IDENTIFIER @20:37 id entry key.entry [v package] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @20:37 +TOKEN @20:42 +BLOCK @20:44 +TOKEN @20:44 +RETURN_STATEMENT @21:5 +TOKEN @21:5 +PLUS @21:12 : java.lang.String +METHOD_INVOCATION @21:12 call Entry.getKey [m abstract public] : ? () returns java.lang.String throws [] sig java.util.Map$Entry#getKey()Ljava/lang/Object; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Entry flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @21:12 : ? +IDENTIFIER @21:12 id entry key.entry [v package] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @21:12 +TOKEN @21:17 +IDENTIFIER @21:18 id getKey Entry.getKey [m abstract public] : ? () returns java.lang.String throws [] sig java.util.Map$Entry#getKey()Ljava/lang/Object; : java.lang.String +TOKEN @21:18 +ARGUMENTS @21:24 +TOKEN @21:24 +TOKEN @21:25 +TOKEN @21:27 +IDENTIFIER @21:29 id E Math.E [v static final public] : double : double = 2.718281828459045 +TOKEN @21:29 +TOKEN @21:30 +TOKEN @22:3 +METHOD @24:3 method StaticImports.category [m package] : ? () returns java.util.Locale$Category throws [] sig StaticImports#category()Ljava/util/Locale$Category; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StaticImports flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +MEMBER_SELECT @24:3 : java.util.Locale$Category +IDENTIFIER @24:3 id Locale java.util.Locale [t final public] : java.util.Locale : java.util.Locale +TOKEN @24:3 +TOKEN @24:9 +IDENTIFIER @24:10 id Category java.util.Category [t static final public enum] : java.util.Locale$Category : java.util.Locale$Category +TOKEN @24:10 +IDENTIFIER @24:19 id category StaticImports.category [m package] : ? () returns java.util.Locale$Category throws [] sig StaticImports#category()Ljava/util/Locale$Category; : java.util.Locale$Category +TOKEN @24:19 +TOKEN @24:27 +TOKEN @24:28 +BLOCK @24:30 +TOKEN @24:30 +RETURN_STATEMENT @25:5 +TOKEN @25:5 +IDENTIFIER @25:12 id FORMAT Category.FORMAT [v static final public enum] : java.util.Locale$Category : java.util.Locale$Category +TOKEN @25:12 +TOKEN @25:18 +TOKEN @26:3 +METHOD @28:3 method StaticImports.sum [m package] : ? (java.util.Map) returns int throws [] sig StaticImports#sum(Ljava/util/Map;)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StaticImports flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [map] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @28:3 : int +TOKEN @28:3 +IDENTIFIER @28:7 id sum StaticImports.sum [m package] : ? (java.util.Map) returns int throws [] sig StaticImports#sum(Ljava/util/Map;)I : int +TOKEN @28:7 +TOKEN @28:10 +VARIABLE @28:11 var sum.map [v package] : java.util.Map + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing StaticImports flags [package] local true parameter true effectivelyFinal true constant null owner sum StaticImports#sum(Ljava/util/Map;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing StaticImports type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @28:11 : java.util.Map +IDENTIFIER @28:11 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @28:11 +TYPE_ARGUMENTS @28:14 +TOKEN @28:14 +IDENTIFIER @28:15 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @28:15 +TOKEN @28:21 +IDENTIFIER @28:23 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @28:23 +TOKEN @28:30 +IDENTIFIER @28:32 id map sum.map [v package] : java.util.Map : java.util.Map +TOKEN @28:32 +TOKEN @28:35 +BLOCK @28:37 +TOKEN @28:37 +VARIABLE @29:5 var sum.total [v package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StaticImports flags [package] local true parameter false effectivelyFinal false constant null owner sum StaticImports#sum(Ljava/util/Map;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing StaticImports type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @29:5 : int +TOKEN @29:5 +IDENTIFIER @29:9 id total sum.total [v package] : int : int +TOKEN @29:9 +TOKEN @29:15 +INT_LITERAL @29:17 : int = 0 +TOKEN @29:17 +TOKEN @29:18 +FOR_EACH_STATEMENT @30:5 +TOKEN @30:5 +TOKEN @30:9 +VARIABLE @30:10 var sum.entry [v package] : java.util.Map$Entry + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing StaticImports flags [package] local true parameter false effectivelyFinal true constant null owner sum StaticImports#sum(Ljava/util/Map;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing StaticImports type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @30:10 : java.util.Map$Entry +IDENTIFIER @30:10 id Entry java.util.Entry [t static public interface] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @30:10 +TYPE_ARGUMENTS @30:15 +TOKEN @30:15 +IDENTIFIER @30:16 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @30:16 +TOKEN @30:22 +IDENTIFIER @30:24 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @30:24 +TOKEN @30:31 +IDENTIFIER @30:33 id entry sum.entry [v package] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @30:33 +TOKEN @30:39 +METHOD_INVOCATION @30:41 call Map.entrySet [m abstract public] : ? () returns java.util.Set> throws [] sig java.util.Map#entrySet()Ljava/util/Set; : java.util.Set> + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Map flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @30:41 : ? +IDENTIFIER @30:41 id map sum.map [v package] : java.util.Map : java.util.Map +TOKEN @30:41 +TOKEN @30:44 +IDENTIFIER @30:45 id entrySet Map.entrySet [m abstract public] : ? () returns java.util.Set> throws [] sig java.util.Map#entrySet()Ljava/util/Set; : java.util.Set> +TOKEN @30:45 +ARGUMENTS @30:53 +TOKEN @30:53 +TOKEN @30:54 +TOKEN @30:55 +BLOCK @30:57 +TOKEN @30:57 +EXPRESSION_STATEMENT @31:7 +PLUS_ASSIGNMENT @31:7 : int +IDENTIFIER @31:7 id total sum.total [v package] : int : int +TOKEN @31:7 +TOKEN @31:13 +METHOD_INVOCATION @31:16 call Entry.getValue [m abstract public] : ? () returns java.lang.Integer throws [] sig java.util.Map$Entry#getValue()Ljava/lang/Object; : java.lang.Integer + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Entry flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @31:16 : ? +IDENTIFIER @31:16 id entry sum.entry [v package] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @31:16 +TOKEN @31:21 +IDENTIFIER @31:22 id getValue Entry.getValue [m abstract public] : ? () returns java.lang.Integer throws [] sig java.util.Map$Entry#getValue()Ljava/lang/Object; : java.lang.Integer +TOKEN @31:22 +ARGUMENTS @31:30 +TOKEN @31:30 +TOKEN @31:31 +TOKEN @31:32 +TOKEN @32:5 +RETURN_STATEMENT @33:5 +TOKEN @33:5 +PLUS @33:12 : int +IDENTIFIER @33:12 id total sum.total [v package] : int : int +TOKEN @33:12 +TOKEN @33:18 +METHOD_INVOCATION @33:20 call Enum.ordinal [m final public] : ? () returns int throws [] sig java.lang.Enum#ordinal()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Enum flags [final, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @33:20 : ? +IDENTIFIER @33:20 id SECONDS TimeUnit.SECONDS [v static final public enum] : java.util.concurrent.TimeUnit : java.util.concurrent.TimeUnit +TOKEN @33:20 +TOKEN @33:27 +IDENTIFIER @33:28 id ordinal Enum.ordinal [m final public] : ? () returns int throws [] sig java.lang.Enum#ordinal()I : int +TOKEN @33:28 +ARGUMENTS @33:35 +TOKEN @33:35 +TOKEN @33:36 +TOKEN @33:37 +TOKEN @34:3 +TOKEN @35:1 +TOKEN @36:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/StaticImports.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/StaticImports.java new file mode 100644 index 00000000000..c6d648f585f --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/StaticImports.java @@ -0,0 +1,35 @@ +import static java.lang.Math.*; +import static java.util.Map.Entry; +import static java.util.concurrent.TimeUnit.SECONDS; +import static java.util.Locale.Category.FORMAT; + +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +class StaticImports { + double area(double radius) { + return PI * pow(radius, 2); + } + + long timeout() { + TimeUnit unit = SECONDS; + return unit.toMillis(max(1, abs(-3))); + } + + String key(Entry entry) { + return entry.getKey() + E; + } + + Locale.Category category() { + return FORMAT; + } + + int sum(Map map) { + int total = 0; + for (Entry entry : map.entrySet()) { + total += entry.getValue(); + } + return total + SECONDS.ordinal(); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/StaticImports.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/StaticImports.textproto.gz new file mode 100644 index 00000000000..c554f2355f6 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/StaticImports.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SwitchShapes.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SwitchShapes.expected.txt new file mode 100644 index 00000000000..662466505f8 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SwitchShapes.expected.txt @@ -0,0 +1,324 @@ +COMPILATION_UNIT @1:1 +CLASS @1:1 class .SwitchShapes [t package] : SwitchShapes super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] members [, colonExpression, nullDefault, ruleValues, trailingLabel] lookupToString 0 outermost SwitchShapes annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring SwitchShapes +MODIFIERS +TOKEN @1:1 +IDENTIFIER @1:7 id SwitchShapes .SwitchShapes [t package] : SwitchShapes : SwitchShapes +TOKEN @1:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @1:20 +METHOD @2:3 method SwitchShapes.trailingLabel [m package] : ? (int) returns int throws [] sig SwitchShapes#trailingLabel(I)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [x] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @2:3 : int +TOKEN @2:3 +IDENTIFIER @2:7 id trailingLabel SwitchShapes.trailingLabel [m package] : ? (int) returns int throws [] sig SwitchShapes#trailingLabel(I)I : int +TOKEN @2:7 +TOKEN @2:20 +VARIABLE @2:21 var trailingLabel.x [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] local true parameter true effectivelyFinal true constant null owner trailingLabel SwitchShapes#trailingLabel(I)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing SwitchShapes type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @2:21 : int +TOKEN @2:21 +IDENTIFIER @2:25 id x trailingLabel.x [v package] : int : int +TOKEN @2:25 +TOKEN @2:26 +BLOCK @2:28 +TOKEN @2:28 +VARIABLE @3:5 var trailingLabel.result [v package] : int + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] local true parameter false effectivelyFinal false constant null owner trailingLabel SwitchShapes#trailingLabel(I)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing SwitchShapes type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @3:5 : int +TOKEN @3:5 +IDENTIFIER @3:9 id result trailingLabel.result [v package] : int : int +TOKEN @3:9 +TOKEN @3:16 +INT_LITERAL @3:18 : int = 0 +TOKEN @3:18 +TOKEN @3:19 +SWITCH_STATEMENT @4:5 : ? +TOKEN @4:5 +TOKEN @4:12 +IDENTIFIER @4:13 id x trailingLabel.x [v package] : int : int +TOKEN @4:13 +TOKEN @4:14 +TOKEN @4:16 +CASE_GROUP @5:7 +CASE_LABEL @5:7 +TOKEN @5:7 +INT_LITERAL @5:12 : int = 1 +TOKEN @5:12 +TOKEN @5:13 +EXPRESSION_STATEMENT @6:9 +ASSIGNMENT @6:9 : int +IDENTIFIER @6:9 id result trailingLabel.result [v package] : int : int +TOKEN @6:9 +TOKEN @6:16 +INT_LITERAL @6:18 : int = 10 +TOKEN @6:18 +TOKEN @6:20 +CASE_GROUP @7:7 +CASE_LABEL @7:7 +TOKEN @7:7 +INT_LITERAL @7:12 : int = 2 +TOKEN @7:12 +TOKEN @7:13 +CASE_LABEL @8:7 +TOKEN @8:7 +INT_LITERAL @8:12 : int = 3 +TOKEN @8:12 +TOKEN @8:13 +EXPRESSION_STATEMENT @9:9 +POSTFIX_INCREMENT @9:9 : int +IDENTIFIER @9:9 id result trailingLabel.result [v package] : int : int +TOKEN @9:9 +TOKEN @9:15 +TOKEN @9:17 +BREAK_STATEMENT @10:9 +TOKEN @10:9 +TOKEN @10:14 +CASE_GROUP @11:7 +CASE_LABEL @11:7 +TOKEN @11:7 +INT_LITERAL @11:12 : int = 4 +TOKEN @11:12 +TOKEN @11:13 +TOKEN @12:5 +RETURN_STATEMENT @13:5 +TOKEN @13:5 +IDENTIFIER @13:12 id result trailingLabel.result [v package] : int : int +TOKEN @13:12 +TOKEN @13:18 +TOKEN @14:3 +METHOD @16:3 method SwitchShapes.nullDefault [m package] : ? (java.lang.Object) returns java.lang.String throws [] sig SwitchShapes#nullDefault(Ljava/lang/Object;)Ljava/lang/String; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [o] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @16:3 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @16:3 +IDENTIFIER @16:10 id nullDefault SwitchShapes.nullDefault [m package] : ? (java.lang.Object) returns java.lang.String throws [] sig SwitchShapes#nullDefault(Ljava/lang/Object;)Ljava/lang/String; : java.lang.String +TOKEN @16:10 +TOKEN @16:21 +VARIABLE @16:22 var nullDefault.o [v package] : java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] local true parameter true effectivelyFinal true constant null owner nullDefault SwitchShapes#nullDefault(Ljava/lang/Object;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing SwitchShapes type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @16:22 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @16:22 +IDENTIFIER @16:29 id o nullDefault.o [v package] : java.lang.Object : java.lang.Object +TOKEN @16:29 +TOKEN @16:30 +BLOCK @16:32 +TOKEN @16:32 +RETURN_STATEMENT @17:5 +TOKEN @17:5 +SWITCH_EXPRESSION @17:12 : java.lang.String +TOKEN @17:12 +TOKEN @17:19 +IDENTIFIER @17:20 id o nullDefault.o [v package] : java.lang.Object : java.lang.Object +TOKEN @17:20 +TOKEN @17:21 +TOKEN @17:23 +CASE_GROUP @18:7 +CASE_LABEL @18:7 +TOKEN @18:7 +TYPE_PATTERN @18:12 : java.lang.String +VARIABLE @18:12 var nullDefault.s [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] local true parameter false effectivelyFinal true constant null owner nullDefault SwitchShapes#nullDefault(Ljava/lang/Object;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing SwitchShapes type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @18:12 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @18:12 +IDENTIFIER @18:19 id s nullDefault.s [v package] : java.lang.String : java.lang.String +TOKEN @18:19 +TOKEN @18:21 +YIELD_STATEMENT @18:24 +IDENTIFIER @18:24 id s nullDefault.s [v package] : java.lang.String : java.lang.String +TOKEN @18:24 +TOKEN @18:25 +CASE_GROUP @19:7 +CASE_LABEL @19:7 +TOKEN @19:7 +NULL_PATTERN @19:12 : +NULL_LITERAL @19:12 : +TOKEN @19:12 +DEFAULT_PATTERN @19:18 : ? +TOKEN @19:18 +TOKEN @19:26 +YIELD_STATEMENT @19:29 +STRING_LITERAL @19:29 : java.lang.String = other +TOKEN @19:29 +TOKEN @19:36 +TOKEN @20:5 +TOKEN @20:6 +TOKEN @21:3 +METHOD @23:3 method SwitchShapes.colonExpression [m package] : ? (java.lang.String) returns int throws [] sig SwitchShapes#colonExpression(Ljava/lang/String;)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [day] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @23:3 : int +TOKEN @23:3 +IDENTIFIER @23:7 id colonExpression SwitchShapes.colonExpression [m package] : ? (java.lang.String) returns int throws [] sig SwitchShapes#colonExpression(Ljava/lang/String;)I : int +TOKEN @23:7 +TOKEN @23:22 +VARIABLE @23:23 var colonExpression.day [v package] : java.lang.String + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] local true parameter true effectivelyFinal true constant null owner colonExpression SwitchShapes#colonExpression(Ljava/lang/String;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing SwitchShapes type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @23:23 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @23:23 +IDENTIFIER @23:30 id day colonExpression.day [v package] : java.lang.String : java.lang.String +TOKEN @23:30 +TOKEN @23:33 +BLOCK @23:35 +TOKEN @23:35 +RETURN_STATEMENT @24:5 +TOKEN @24:5 +SWITCH_EXPRESSION @24:12 : int +TOKEN @24:12 +TOKEN @24:19 +IDENTIFIER @24:20 id day colonExpression.day [v package] : java.lang.String : java.lang.String +TOKEN @24:20 +TOKEN @24:23 +TOKEN @24:25 +CASE_GROUP @25:7 +CASE_LABEL @25:7 +TOKEN @25:7 +STRING_LITERAL @25:12 : java.lang.String = MON +TOKEN @25:12 +TOKEN @25:17 +CASE_LABEL @26:7 +TOKEN @26:7 +STRING_LITERAL @26:12 : java.lang.String = TUE +TOKEN @26:12 +TOKEN @26:17 +YIELD_STATEMENT @27:9 +TOKEN @27:9 +INT_LITERAL @27:15 : int = 1 +TOKEN @27:15 +TOKEN @27:16 +CASE_GROUP @28:7 +CASE_LABEL @28:7 +TOKEN @28:7 +TOKEN @28:14 +VARIABLE @29:9 var colonExpression.length [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] local true parameter false effectivelyFinal true constant null owner colonExpression SwitchShapes#colonExpression(Ljava/lang/String;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing SwitchShapes type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @29:9 : int +TOKEN @29:9 +IDENTIFIER @29:13 id length colonExpression.length [v package] : int : int +TOKEN @29:13 +TOKEN @29:20 +METHOD_INVOCATION @29:22 call String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing String flags [public] overridden [CharSequence.length[]] overridable false generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @29:22 : ? +IDENTIFIER @29:22 id day colonExpression.day [v package] : java.lang.String : java.lang.String +TOKEN @29:22 +TOKEN @29:25 +IDENTIFIER @29:26 id length String.length [m public] : ? () returns int throws [] sig java.lang.String#length()I : int +TOKEN @29:26 +ARGUMENTS @29:32 +TOKEN @29:32 +TOKEN @29:33 +TOKEN @29:34 +YIELD_STATEMENT @30:9 +TOKEN @30:9 +IDENTIFIER @30:15 id length colonExpression.length [v package] : int : int +TOKEN @30:15 +TOKEN @30:21 +TOKEN @31:5 +TOKEN @31:6 +TOKEN @32:3 +METHOD @34:3 method SwitchShapes.ruleValues [m package] : ? (int) returns int throws [] sig SwitchShapes#ruleValues(I)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [x] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @34:3 : int +TOKEN @34:3 +IDENTIFIER @34:7 id ruleValues SwitchShapes.ruleValues [m package] : ? (int) returns int throws [] sig SwitchShapes#ruleValues(I)I : int +TOKEN @34:7 +TOKEN @34:17 +VARIABLE @34:18 var ruleValues.x [v package] : int + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] local true parameter true effectivelyFinal true constant null owner ruleValues SwitchShapes#ruleValues(I)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing SwitchShapes type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @34:18 : int +TOKEN @34:18 +IDENTIFIER @34:22 id x ruleValues.x [v package] : int : int +TOKEN @34:22 +TOKEN @34:23 +BLOCK @34:25 +TOKEN @34:25 +RETURN_STATEMENT @35:5 +TOKEN @35:5 +SWITCH_EXPRESSION @35:12 : int +TOKEN @35:12 +TOKEN @35:19 +IDENTIFIER @35:20 id x ruleValues.x [v package] : int : int +TOKEN @35:20 +TOKEN @35:21 +TOKEN @35:23 +CASE_GROUP @36:7 +CASE_LABEL @36:7 +TOKEN @36:7 +INT_LITERAL @36:12 : int = 1 +TOKEN @36:12 +INT_LITERAL @36:15 : int = 2 +TOKEN @36:15 +TOKEN @36:17 +YIELD_STATEMENT @36:20 +MULTIPLY @36:20 : int +IDENTIFIER @36:20 id x ruleValues.x [v package] : int : int +TOKEN @36:20 +TOKEN @36:22 +INT_LITERAL @36:24 : int = 2 +TOKEN @36:24 +TOKEN @36:25 +CASE_GROUP @37:7 +CASE_LABEL @37:7 +TOKEN @37:7 +INT_LITERAL @37:12 : int = 3 +TOKEN @37:12 +TOKEN @37:14 +BLOCK @37:17 +TOKEN @37:17 +VARIABLE @38:9 var ruleValues.y [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing SwitchShapes flags [package] local true parameter false effectivelyFinal true constant null owner ruleValues SwitchShapes#ruleValues(I)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing SwitchShapes type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @38:9 : int +TOKEN @38:9 +IDENTIFIER @38:13 id y ruleValues.y [v package] : int : int +TOKEN @38:13 +TOKEN @38:15 +PLUS @38:17 : int +IDENTIFIER @38:17 id x ruleValues.x [v package] : int : int +TOKEN @38:17 +TOKEN @38:19 +INT_LITERAL @38:21 : int = 1 +TOKEN @38:21 +TOKEN @38:22 +YIELD_STATEMENT @39:9 +TOKEN @39:9 +IDENTIFIER @39:15 id y ruleValues.y [v package] : int : int +TOKEN @39:15 +TOKEN @39:16 +TOKEN @40:7 +CASE_GROUP @41:7 +CASE_LABEL @41:7 +TOKEN @41:7 +TOKEN @41:15 +THROW_STATEMENT @41:18 +TOKEN @41:18 +NEW_CLASS @41:24 new IllegalArgumentException. [m public] : ? () returns void throws [] sig java.lang.IllegalArgumentException#()V : java.lang.IllegalArgumentException + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing IllegalArgumentException flags [public] overridden [RuntimeException.[], Exception.[], Throwable.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @41:24 +IDENTIFIER @41:28 id IllegalArgumentException IllegalArgumentException. [m public] : ? () returns void throws [] sig java.lang.IllegalArgumentException#()V : java.lang.IllegalArgumentException +TOKEN @41:28 +ARGUMENTS @41:52 +TOKEN @41:52 +TOKEN @41:53 +TOKEN @41:54 +TOKEN @42:5 +TOKEN @42:6 +TOKEN @43:3 +TOKEN @44:1 +TOKEN @45:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SwitchShapes.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SwitchShapes.java new file mode 100644 index 00000000000..f9c581227c6 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SwitchShapes.java @@ -0,0 +1,44 @@ +class SwitchShapes { + int trailingLabel(int x) { + int result = 0; + switch (x) { + case 1: + result = 10; + case 2: + case 3: + result++; + break; + case 4: + } + return result; + } + + String nullDefault(Object o) { + return switch (o) { + case String s -> s; + case null, default -> "other"; + }; + } + + int colonExpression(String day) { + return switch (day) { + case "MON": + case "TUE": + yield 1; + default: + int length = day.length(); + yield length; + }; + } + + int ruleValues(int x) { + return switch (x) { + case 1, 2 -> x * 2; + case 3 -> { + int y = x + 1; + yield y; + } + default -> throw new IllegalArgumentException(); + }; + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SwitchShapes.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SwitchShapes.textproto.gz new file mode 100644 index 00000000000..3a7a550622d Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SwitchShapes.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SyntaxError.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SyntaxError.expected.txt new file mode 100644 index 00000000000..e6d39bf6489 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SyntaxError.expected.txt @@ -0,0 +1 @@ +FAILURE Parse error at line 3 column 1: Syntax error diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SyntaxError.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SyntaxError.java new file mode 100644 index 00000000000..26d6f9f5398 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SyntaxError.java @@ -0,0 +1,11 @@ +import java.util.List; + +class SyntaxError { + + int valid = 1; + + void broken(List items) { + int x = ; + items.add("x" + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SyntaxError.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SyntaxError.textproto.gz new file mode 100644 index 00000000000..57559acd7d5 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/SyntaxError.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/TypeSyntax.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/TypeSyntax.expected.txt new file mode 100644 index 00000000000..e27047712e8 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/TypeSyntax.expected.txt @@ -0,0 +1,543 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id io unknown : ? +TOKEN @1:13 +TOKEN @1:15 +IDENTIFIER @1:16 id IOException unknown : ? +TOKEN @1:16 +TOKEN @1:27 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id io unknown : ? +TOKEN @2:13 +TOKEN @2:15 +IDENTIFIER @2:16 id Serializable unknown : ? +TOKEN @2:16 +TOKEN @2:28 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id lang unknown : ? +TOKEN @3:13 +TOKEN @3:17 +IDENTIFIER @3:18 id annotation unknown : ? +TOKEN @3:18 +TOKEN @3:28 +IDENTIFIER @3:29 id ElementType unknown : ? +TOKEN @3:29 +TOKEN @3:40 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id lang unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id annotation unknown : ? +TOKEN @4:18 +TOKEN @4:28 +IDENTIFIER @4:29 id Target unknown : ? +TOKEN @4:29 +TOKEN @4:35 +IMPORT @5:1 +TOKEN @5:1 +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +IDENTIFIER @5:8 id java unknown : ? +TOKEN @5:8 +TOKEN @5:12 +IDENTIFIER @5:13 id util unknown : ? +TOKEN @5:13 +TOKEN @5:17 +IDENTIFIER @5:18 id Collection unknown : ? +TOKEN @5:18 +TOKEN @5:28 +IMPORT @6:1 +TOKEN @6:1 +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +IDENTIFIER @6:8 id java unknown : ? +TOKEN @6:8 +TOKEN @6:12 +IDENTIFIER @6:13 id util unknown : ? +TOKEN @6:13 +TOKEN @6:17 +IDENTIFIER @6:18 id List unknown : ? +TOKEN @6:18 +TOKEN @6:22 +IMPORT @7:1 +TOKEN @7:1 +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +IDENTIFIER @7:8 id java unknown : ? +TOKEN @7:8 +TOKEN @7:12 +IDENTIFIER @7:13 id util unknown : ? +TOKEN @7:13 +TOKEN @7:17 +IDENTIFIER @7:18 id Map unknown : ? +TOKEN @7:18 +TOKEN @7:21 +CLASS @9:1 class .TypeSyntax [t package] : TypeSyntax super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing TypeSyntax flags [package] members [, Tagged, annotated, annotatedArgument, arrayOfLists, arrayReturn, bounded, entry, lower, multiCatch, nested, pair, qualified, unbounded, upper, varargs] lookupToString 0 outermost TypeSyntax annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw true declaring TypeSyntax +MODIFIERS +TOKEN @9:1 +IDENTIFIER @9:7 id TypeSyntax .TypeSyntax [t package] : TypeSyntax : TypeSyntax +TOKEN @9:7 +TYPE_PARAMETERS @9:17 +TOKEN @9:17 +TYPE_PARAMETER @9:18 +IDENTIFIER @9:18 id K TypeSyntax.K [t package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @9:18 +TOKEN @9:19 +TYPE_PARAMETER @9:21 +IDENTIFIER @9:21 id V TypeSyntax.V [t package] : V erasure java.lang.Number : V erasure java.lang.Number +TOKEN @9:21 +TOKEN @9:23 +LIST @9:31 +IDENTIFIER @9:31 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @9:31 +TOKEN @9:38 +PARAMETERIZED_TYPE @9:40 : java.lang.Comparable +IDENTIFIER @9:40 id Comparable java.lang.Comparable [t public interface] : java.lang.Comparable : java.lang.Comparable +TOKEN @9:40 +TYPE_ARGUMENTS @9:50 +TOKEN @9:50 +IDENTIFIER @9:51 id V TypeSyntax.V [t package] : V erasure java.lang.Number : V erasure java.lang.Number +TOKEN @9:51 +TOKEN @9:52 +TOKEN @9:53 +LIST +LIST +TOKEN @9:55 +ANNOTATION_TYPE @11:3 class TypeSyntax.Tagged [t static package interface] : TypeSyntax$Tagged @java.lang.annotation.Target super java.lang.Object interfaces [java.lang.annotation.Annotation] + details declared true usages 2 metadata [java.lang.annotation.Target(value={ElementType.TYPE_USE})] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [java.lang.annotation.Target tree true values 1 annotated true] typeArguments [] enclosing TypeSyntax flags [static, package, interface] members [] lookupToString 0 outermost TypeSyntax annotation true subtypeOf [java.lang.Object, java.lang.annotation.Annotation] superTypes [java.lang.Object, java.lang.annotation.Annotation] numerical false wrapper false raw false declaring Tagged +MODIFIERS @11:3 +ANNOTATION @11:3 : java.lang.annotation.Target +TOKEN @11:3 +IDENTIFIER @11:4 id Target java.lang.annotation.Target [t public interface] : java.lang.annotation.Target @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.annotation.Target +TOKEN @11:4 +ARGUMENTS @11:10 +TOKEN @11:10 +MEMBER_SELECT @11:11 : java.lang.annotation.ElementType +IDENTIFIER @11:11 id ElementType java.lang.annotation.ElementType [t final public enum] : java.lang.annotation.ElementType : java.lang.annotation.ElementType +TOKEN @11:11 +TOKEN @11:22 +IDENTIFIER @11:23 id TYPE_USE ElementType.TYPE_USE [v static final public enum] : java.lang.annotation.ElementType : java.lang.annotation.ElementType +TOKEN @11:23 +TOKEN @11:31 +TOKEN @12:3 +TOKEN @12:4 +IDENTIFIER @12:14 id Tagged TypeSyntax.Tagged [t static package interface] : TypeSyntax$Tagged @java.lang.annotation.Target : TypeSyntax$Tagged +TOKEN @12:14 +TYPE_PARAMETERS +LIST +LIST +TOKEN @12:21 +TOKEN @13:3 +VARIABLE @15:3 var TypeSyntax.upper [v package] : java.util.List + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing TypeSyntax flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @15:3 : java.util.List +IDENTIFIER @15:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @15:3 +TYPE_ARGUMENTS @15:7 +TOKEN @15:7 +EXTENDS_WILDCARD @15:8 +TOKEN @15:8 +TOKEN @15:10 +IDENTIFIER @15:18 id Number java.lang.Number [t abstract public] : java.lang.Number : java.lang.Number +TOKEN @15:18 +TOKEN @15:24 +IDENTIFIER @15:26 id upper TypeSyntax.upper [v package] : java.util.List : java.util.List +TOKEN @15:26 +TOKEN @15:31 +VARIABLE @16:3 var TypeSyntax.lower [v package] : java.util.List + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing TypeSyntax flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @16:3 : java.util.List +IDENTIFIER @16:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @16:3 +TYPE_ARGUMENTS @16:7 +TOKEN @16:7 +SUPER_WILDCARD @16:8 +TOKEN @16:8 +TOKEN @16:10 +IDENTIFIER @16:16 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @16:16 +TOKEN @16:23 +IDENTIFIER @16:25 id lower TypeSyntax.lower [v package] : java.util.List : java.util.List +TOKEN @16:25 +TOKEN @16:30 +VARIABLE @17:3 var TypeSyntax.unbounded [v package] : java.util.List + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing TypeSyntax flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @17:3 : java.util.List +IDENTIFIER @17:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @17:3 +TYPE_ARGUMENTS @17:7 +TOKEN @17:7 +UNBOUNDED_WILDCARD @17:8 +TOKEN @17:8 +TOKEN @17:9 +IDENTIFIER @17:11 id unbounded TypeSyntax.unbounded [v package] : java.util.List : java.util.List +TOKEN @17:11 +TOKEN @17:20 +VARIABLE @18:3 var TypeSyntax.nested [v package] : java.util.Map> + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing TypeSyntax flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @18:3 : java.util.Map> +IDENTIFIER @18:3 id Map java.util.Map [t public interface] : java.util.Map> : java.util.Map> +TOKEN @18:3 +TYPE_ARGUMENTS @18:6 +TOKEN @18:6 +IDENTIFIER @18:7 id K TypeSyntax.K [t package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @18:7 +TOKEN @18:8 +PARAMETERIZED_TYPE @18:10 : java.util.List +IDENTIFIER @18:10 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @18:10 +TYPE_ARGUMENTS @18:14 +TOKEN @18:14 +IDENTIFIER @18:15 id V TypeSyntax.V [t package] : V erasure java.lang.Number : V erasure java.lang.Number +TOKEN @18:15 +TOKEN @18:16 +TOKEN @18:17 +IDENTIFIER @18:19 id nested TypeSyntax.nested [v package] : java.util.Map> : java.util.Map> +TOKEN @18:19 +TOKEN @18:25 +VARIABLE @19:3 var TypeSyntax.arrayOfLists [v package] : java.util.List[] + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing TypeSyntax flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +ARRAY_TYPE @19:3 : java.util.List[] +PARAMETERIZED_TYPE @19:3 : java.util.List +IDENTIFIER @19:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @19:3 +TYPE_ARGUMENTS @19:7 +TOKEN @19:7 +IDENTIFIER @19:8 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @19:8 +TOKEN @19:14 +TOKEN @19:15 +TOKEN @19:16 +IDENTIFIER @19:18 id arrayOfLists TypeSyntax.arrayOfLists [v package] : java.util.List[] : java.util.List[] +TOKEN @19:18 +TOKEN @19:30 +VARIABLE @20:3 var TypeSyntax.qualified [v package] : java.util.Set + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing TypeSyntax flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @20:3 : java.util.Set +MEMBER_SELECT @20:3 : java.util.Set +MEMBER_SELECT @20:3 : ? +IDENTIFIER @20:3 id java .java [p package] : ? : ? +TOKEN @20:3 +TOKEN @20:7 +IDENTIFIER @20:8 id util .java.util [p package] : ? : ? +TOKEN @20:8 +TOKEN @20:12 +IDENTIFIER @20:13 id Set java.util.Set [t public interface] : java.util.Set : java.util.Set +TOKEN @20:13 +TYPE_ARGUMENTS @20:16 +TOKEN @20:16 +MEMBER_SELECT @20:17 : java.lang.String +MEMBER_SELECT @20:17 : ? +IDENTIFIER @20:17 id java .java [p package] : ? : ? +TOKEN @20:17 +TOKEN @20:21 +IDENTIFIER @20:22 id lang .java.lang [p package] : ? : ? +TOKEN @20:22 +TOKEN @20:26 +IDENTIFIER @20:27 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @20:27 +TOKEN @20:33 +IDENTIFIER @20:35 id qualified TypeSyntax.qualified [v package] : java.util.Set : java.util.Set +TOKEN @20:35 +TOKEN @20:44 +VARIABLE @21:3 var TypeSyntax.annotated [v package] : java.lang.String @TypeSyntax$Tagged + details declared true usages 0 metadata [TypeSyntax$Tagged()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [TypeSyntax$Tagged tree true values 0 annotated true] typeArguments [] enclosing TypeSyntax flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS @21:3 +ANNOTATION @21:3 : TypeSyntax$Tagged +TOKEN @21:3 +IDENTIFIER @21:4 id Tagged TypeSyntax.Tagged [t static package interface] : TypeSyntax$Tagged @java.lang.annotation.Target : TypeSyntax$Tagged +TOKEN @21:4 +ARGUMENTS +IDENTIFIER @21:11 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @21:11 +IDENTIFIER @21:18 id annotated TypeSyntax.annotated [v package] : java.lang.String @TypeSyntax$Tagged : java.lang.String +TOKEN @21:18 +TOKEN @21:27 +VARIABLE @22:3 var TypeSyntax.annotatedArgument [v package] : java.util.List + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[TypeSyntax$Tagged tree true values 0 annotated true]] enclosing TypeSyntax flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @22:3 : java.util.List +IDENTIFIER @22:3 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @22:3 +TYPE_ARGUMENTS @22:7 +TOKEN @22:7 +IDENTIFIER @22:8 id String java.lang.String [t final public] : java.lang.String : java.lang.String +ANNOTATION @22:8 : TypeSyntax$Tagged +TOKEN @22:8 +IDENTIFIER @22:9 id Tagged TypeSyntax.Tagged [t static package interface] : TypeSyntax$Tagged @java.lang.annotation.Target : TypeSyntax$Tagged +TOKEN @22:9 +ARGUMENTS +TOKEN @22:16 +TOKEN @22:22 +IDENTIFIER @22:24 id annotatedArgument TypeSyntax.annotatedArgument [v package] : java.util.List : java.util.List +TOKEN @22:24 +TOKEN @22:41 +VARIABLE @23:3 var TypeSyntax.entry [v package] : java.util.Map$Entry + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing TypeSyntax flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @23:3 : java.util.Map$Entry +MEMBER_SELECT @23:3 : java.util.Map$Entry +IDENTIFIER @23:3 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @23:3 +TOKEN @23:6 +IDENTIFIER @23:7 id Entry java.util.Entry [t static public interface] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @23:7 +TYPE_ARGUMENTS @23:12 +TOKEN @23:12 +IDENTIFIER @23:13 id K TypeSyntax.K [t package] : K erasure java.lang.Object : K erasure java.lang.Object +TOKEN @23:13 +TOKEN @23:14 +IDENTIFIER @23:16 id V TypeSyntax.V [t package] : V erasure java.lang.Number : V erasure java.lang.Number +TOKEN @23:16 +TOKEN @23:17 +IDENTIFIER @23:19 id entry TypeSyntax.entry [v package] : java.util.Map$Entry : java.util.Map$Entry +TOKEN @23:19 +TOKEN @23:24 +METHOD @25:3 method TypeSyntax.bounded [m package] : ? (T erasure java.util.Collection) returns T erasure java.util.Collection throws [] sig TypeSyntax#bounded(Ljava/util/Collection;)Ljava/util/Collection; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing TypeSyntax flags [package] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [input] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS @25:3 +TOKEN @25:3 +TYPE_PARAMETER @25:4 +IDENTIFIER @25:4 id T bounded.T [t package] : T erasure java.util.Collection : T erasure java.util.Collection +TOKEN @25:4 +TOKEN @25:6 +LIST @25:14 +PARAMETERIZED_TYPE @25:14 : java.util.Collection +IDENTIFIER @25:14 id Collection java.util.Collection [t public interface] : java.util.Collection : java.util.Collection +TOKEN @25:14 +TYPE_ARGUMENTS @25:24 +TOKEN @25:24 +SUPER_WILDCARD @25:25 +TOKEN @25:25 +TOKEN @25:27 +IDENTIFIER @25:33 id V TypeSyntax.V [t package] : V erasure java.lang.Number : V erasure java.lang.Number +TOKEN @25:33 +TOKEN @25:34 +TOKEN @25:36 +IDENTIFIER @25:38 id Serializable java.io.Serializable [t public interface] : java.io.Serializable : java.io.Serializable +TOKEN @25:38 +TOKEN @25:50 +IDENTIFIER @25:52 id T bounded.T [t package] : T erasure java.util.Collection : T erasure java.util.Collection +TOKEN @25:52 +IDENTIFIER @25:54 id bounded TypeSyntax.bounded [m package] : ? (T erasure java.util.Collection) returns T erasure java.util.Collection throws [] sig TypeSyntax#bounded(Ljava/util/Collection;)Ljava/util/Collection; : T erasure java.util.Collection +TOKEN @25:54 +TOKEN @25:61 +VARIABLE @25:62 var bounded.input [v package] : T erasure java.util.Collection + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing TypeSyntax flags [package] local true parameter true effectivelyFinal true constant null owner bounded TypeSyntax#bounded(Ljava/util/Collection;)Ljava/util/Collection; [package] returns T erasure java.util.Collection parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing TypeSyntax type true kinds truefalsefalse other falsefalsefalsefalsetruetrue1falsefalse +MODIFIERS +IDENTIFIER @25:62 id T bounded.T [t package] : T erasure java.util.Collection : T erasure java.util.Collection +TOKEN @25:62 +IDENTIFIER @25:64 id input bounded.input [v package] : T erasure java.util.Collection : T erasure java.util.Collection +TOKEN @25:64 +TOKEN @25:69 +BLOCK @25:71 +TOKEN @25:71 +RETURN_STATEMENT @26:5 +TOKEN @26:5 +IDENTIFIER @26:12 id input bounded.input [v package] : T erasure java.util.Collection : T erasure java.util.Collection +TOKEN @26:12 +TOKEN @26:17 +TOKEN @27:3 +METHOD @29:3 method TypeSyntax.pair [m package] : ? (A erasure java.lang.Object,B erasure java.lang.Object) returns java.util.Map throws [] sig TypeSyntax#pair(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing TypeSyntax flags [package] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [a, b] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [], [] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS +TYPE_PARAMETERS @29:3 +TOKEN @29:3 +TYPE_PARAMETER @29:4 +IDENTIFIER @29:4 id A pair.A [t package] : A erasure java.lang.Object : A erasure java.lang.Object +TOKEN @29:4 +TOKEN @29:5 +TYPE_PARAMETER @29:7 +IDENTIFIER @29:7 id B pair.B [t package] : B erasure java.lang.Object : B erasure java.lang.Object +TOKEN @29:7 +TOKEN @29:8 +PARAMETERIZED_TYPE @29:10 : java.util.Map +IDENTIFIER @29:10 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @29:10 +TYPE_ARGUMENTS @29:13 +TOKEN @29:13 +IDENTIFIER @29:14 id A pair.A [t package] : A erasure java.lang.Object : A erasure java.lang.Object +TOKEN @29:14 +TOKEN @29:15 +IDENTIFIER @29:17 id B pair.B [t package] : B erasure java.lang.Object : B erasure java.lang.Object +TOKEN @29:17 +TOKEN @29:18 +IDENTIFIER @29:20 id pair TypeSyntax.pair [m package] : ? (A erasure java.lang.Object,B erasure java.lang.Object) returns java.util.Map throws [] sig TypeSyntax#pair(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map; : java.util.Map +TOKEN @29:20 +TOKEN @29:24 +VARIABLE @29:25 var pair.a [v package] : A erasure java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing TypeSyntax flags [package] local true parameter true effectivelyFinal true constant null owner pair TypeSyntax#pair(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map; [package] returns java.util.Map parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing TypeSyntax type true kinds truefalsefalse other falsefalsefalsefalsetruetrue2falsefalse +MODIFIERS +IDENTIFIER @29:25 id A pair.A [t package] : A erasure java.lang.Object : A erasure java.lang.Object +TOKEN @29:25 +IDENTIFIER @29:27 id a pair.a [v package] : A erasure java.lang.Object : A erasure java.lang.Object +TOKEN @29:27 +TOKEN @29:28 +VARIABLE @29:30 var pair.b [v package] : B erasure java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing TypeSyntax flags [package] local true parameter true effectivelyFinal true constant null owner pair TypeSyntax#pair(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map; [package] returns java.util.Map parameters 2 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing TypeSyntax type true kinds truefalsefalse other falsefalsefalsefalsetruetrue2falsefalse +MODIFIERS +IDENTIFIER @29:30 id B pair.B [t package] : B erasure java.lang.Object : B erasure java.lang.Object +TOKEN @29:30 +IDENTIFIER @29:32 id b pair.b [v package] : B erasure java.lang.Object : B erasure java.lang.Object +TOKEN @29:32 +TOKEN @29:33 +BLOCK @29:35 +TOKEN @29:35 +RETURN_STATEMENT @30:5 +TOKEN @30:5 +NULL_LITERAL @30:12 : +TOKEN @30:12 +TOKEN @30:16 +TOKEN @31:3 +METHOD @33:3 method TypeSyntax.multiCatch [m package] : ? () returns void throws [] sig TypeSyntax#multiCatch()V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing TypeSyntax flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @33:3 : void +TOKEN @33:3 +IDENTIFIER @33:8 id multiCatch TypeSyntax.multiCatch [m package] : ? () returns void throws [] sig TypeSyntax#multiCatch()V : void +TOKEN @33:8 +TOKEN @33:18 +TOKEN @33:19 +BLOCK @33:21 +TOKEN @33:21 +TRY_STATEMENT @34:5 +TOKEN @34:5 +BLOCK @34:9 +TOKEN @34:9 +THROW_STATEMENT @35:7 +TOKEN @35:7 +NEW_CLASS @35:13 new IOException. [m public] : ? () returns void throws [] sig java.io.IOException#()V : java.io.IOException + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing IOException flags [public] overridden [Exception.[], Throwable.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @35:13 +IDENTIFIER @35:17 id IOException IOException. [m public] : ? () returns void throws [] sig java.io.IOException#()V : java.io.IOException +TOKEN @35:17 +ARGUMENTS @35:28 +TOKEN @35:28 +TOKEN @35:29 +TOKEN @35:30 +TOKEN @36:5 +CATCH @36:7 +TOKEN @36:7 +TOKEN @36:13 +VARIABLE @36:14 var multiCatch.e [v final package] : java.lang.Exception + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing TypeSyntax flags [final, package] local true parameter false effectivelyFinal true constant null owner multiCatch TypeSyntax#multiCatch()V [package] returns void parameters 0 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing TypeSyntax type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +UNION_TYPE @36:14 +LIST @36:14 +IDENTIFIER @36:14 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @36:14 +TOKEN @36:26 +IDENTIFIER @36:28 id RuntimeException java.lang.RuntimeException [t public] : java.lang.RuntimeException : java.lang.RuntimeException +TOKEN @36:28 +IDENTIFIER @36:45 id e multiCatch.e [v final package] : java.lang.Exception : java.lang.Exception +TOKEN @36:45 +TOKEN @36:46 +BLOCK @36:48 +TOKEN @36:48 +EXPRESSION_STATEMENT @37:7 +METHOD_INVOCATION @37:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @37:7 : ? +IDENTIFIER @37:7 id e multiCatch.e [v final package] : java.lang.Exception : java.lang.Exception +TOKEN @37:7 +TOKEN @37:8 +IDENTIFIER @37:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @37:9 +ARGUMENTS @37:24 +TOKEN @37:24 +TOKEN @37:25 +TOKEN @37:26 +TOKEN @38:5 +TOKEN @39:3 +METHOD @41:3 method TypeSyntax.arrayReturn [m package] : ? () returns int[] throws [] sig TypeSyntax#arrayReturn()[I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing TypeSyntax flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +ARRAY_TYPE @41:3 : int[][] +ARRAY_TYPE @41:3 : int[] +PRIMITIVE_TYPE @41:3 : int +TOKEN @41:3 +TOKEN @41:6 +TOKEN @41:7 +TOKEN @41:22 +TOKEN @41:23 +IDENTIFIER @41:9 id arrayReturn TypeSyntax.arrayReturn [m package] : ? () returns int[] throws [] sig TypeSyntax#arrayReturn()[I : int[] +TOKEN @41:9 +TOKEN @41:20 +TOKEN @41:21 +BLOCK @41:25 +TOKEN @41:25 +RETURN_STATEMENT @42:5 +TOKEN @42:5 +NULL_LITERAL @42:12 : +TOKEN @42:12 +TOKEN @42:16 +TOKEN @43:3 +METHOD @45:3 method TypeSyntax.varargs [m package] : ? (java.util.List[]) returns void throws [] sig TypeSyntax#varargs([Ljava/util/List;)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing TypeSyntax flags [package] overridden [] overridable true generic false default false synchronized false varargs true native false parameters [lists] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @45:3 : void +TOKEN @45:3 +IDENTIFIER @45:8 id varargs TypeSyntax.varargs [m package] : ? (java.util.List[]) returns void throws [] sig TypeSyntax#varargs([Ljava/util/List;)V : void +TOKEN @45:8 +TOKEN @45:15 +VARIABLE @45:16 var varargs.lists [v package] : java.util.List[] + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing TypeSyntax flags [package] local true parameter true effectivelyFinal true constant null owner varargs TypeSyntax#varargs([Ljava/util/List;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing TypeSyntax type true kinds truefalsefalse other falsefalsetruefalsetruefalse1falsefalse +MODIFIERS +ARRAY_TYPE @45:16 : java.util.List[] +PARAMETERIZED_TYPE @45:16 : java.util.List +IDENTIFIER @45:16 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @45:16 +TYPE_ARGUMENTS @45:20 +TOKEN @45:20 +EXTENDS_WILDCARD @45:21 +TOKEN @45:21 +TOKEN @45:23 +IDENTIFIER @45:31 id V TypeSyntax.V [t package] : V erasure java.lang.Number : V erasure java.lang.Number +TOKEN @45:31 +TOKEN @45:32 +TOKEN @45:33 +IDENTIFIER @45:37 id lists varargs.lists [v package] : java.util.List[] : java.util.List[] +TOKEN @45:37 +TOKEN @45:42 +BLOCK @45:44 +TOKEN @45:44 +TOKEN @46:3 +TOKEN @47:1 +TOKEN @48:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/TypeSyntax.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/TypeSyntax.java new file mode 100644 index 00000000000..9a762483e89 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/TypeSyntax.java @@ -0,0 +1,47 @@ +import java.io.IOException; +import java.io.Serializable; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +class TypeSyntax> { + + @Target(ElementType.TYPE_USE) + @interface Tagged { + } + + List upper; + List lower; + List unbounded; + Map> nested; + List[] arrayOfLists; + java.util.Set qualified; + @Tagged String annotated; + List<@Tagged String> annotatedArgument; + Map.Entry entry; + + & Serializable> T bounded(T input) { + return input; + } + + Map pair(A a, B b) { + return null; + } + + void multiCatch() { + try { + throw new IOException(); + } catch (IOException | RuntimeException e) { + e.printStackTrace(); + } + } + + int[] arrayReturn()[] { + return null; + } + + void varargs(List... lists) { + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/TypeSyntax.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/TypeSyntax.textproto.gz new file mode 100644 index 00000000000..ca10d972f67 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/TypeSyntax.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Unresolved.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Unresolved.expected.txt new file mode 100644 index 00000000000..5285ac4c507 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Unresolved.expected.txt @@ -0,0 +1,525 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id com unknown : ? +TOKEN @1:8 +TOKEN @1:11 +IDENTIFIER @1:12 id example unknown : ? +TOKEN @1:12 +TOKEN @1:19 +IDENTIFIER @1:20 id missing unknown : ? +TOKEN @1:20 +TOKEN @1:27 +IDENTIFIER @1:28 id Service unknown : ? +TOKEN @1:28 +TOKEN @1:35 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id com unknown : ? +TOKEN @2:8 +TOKEN @2:11 +IDENTIFIER @2:12 id example unknown : ? +TOKEN @2:12 +TOKEN @2:19 +IDENTIFIER @2:20 id missing unknown : ? +TOKEN @2:20 +TOKEN @2:27 +IDENTIFIER @2:28 id * unknown : ? +TOKEN @2:28 +TOKEN @2:29 +IMPORT @3:1 +TOKEN @3:1 +TOKEN @3:8 +MEMBER_SELECT @3:15 : ? +MEMBER_SELECT @3:15 : ? +MEMBER_SELECT @3:15 : ? +MEMBER_SELECT @3:15 : ? +IDENTIFIER @3:15 id com unknown : ? +TOKEN @3:15 +TOKEN @3:18 +IDENTIFIER @3:19 id example unknown : ? +TOKEN @3:19 +TOKEN @3:26 +IDENTIFIER @3:27 id missing unknown : ? +TOKEN @3:27 +TOKEN @3:34 +IDENTIFIER @3:35 id Helpers unknown : ? +TOKEN @3:35 +TOKEN @3:42 +IDENTIFIER @3:43 id help unknown : ? +TOKEN @3:43 +TOKEN @3:47 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id util unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id List unknown : ? +TOKEN @4:18 +TOKEN @4:22 +CLASS @6:1 class .Unresolved [t package] : Unresolved super ? interfaces [?] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] members [, items, nested, run, service] lookupToString 0 outermost Unresolved annotation false subtypeOf [] superTypes [?, ?] numerical false wrapper false raw false declaring Unresolved +MODIFIERS +TOKEN @6:1 +IDENTIFIER @6:7 id Unresolved .Unresolved [t package] : Unresolved : Unresolved +TOKEN @6:7 +TYPE_PARAMETERS +TOKEN @6:18 +IDENTIFIER @6:26 id MissingBase unknown : ? +TOKEN @6:26 +TOKEN @6:38 +LIST @6:49 +IDENTIFIER @6:49 id MissingInterface unknown : ? +TOKEN @6:49 +LIST +TOKEN @6:66 +VARIABLE @8:3 var Unresolved.service [v package] : ? + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +IDENTIFIER @8:3 id Service unknown : ? +TOKEN @8:3 +IDENTIFIER @8:11 id service Unresolved.service [v package] : ? : ? +TOKEN @8:11 +TOKEN @8:18 +VARIABLE @9:3 var Unresolved.items [v package] : ? + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Unresolved flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PARAMETERIZED_TYPE @9:3 : ? +IDENTIFIER @9:3 id List java.util.List [t public interface] : ? : ? +TOKEN @9:3 +TYPE_ARGUMENTS @9:7 +TOKEN @9:7 +IDENTIFIER @9:8 id Missing unknown : ? +TOKEN @9:8 +TOKEN @9:15 +IDENTIFIER @9:17 id items Unresolved.items [v package] : ? : ? +TOKEN @9:17 +TOKEN @9:22 +VARIABLE @10:3 var Unresolved.nested [v package] : ? + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +MEMBER_SELECT @10:3 : ? +IDENTIFIER @10:3 id Missing unknown : ? +TOKEN @10:3 +TOKEN @10:10 +IDENTIFIER @10:11 id Nested unknown : ? +TOKEN @10:11 +IDENTIFIER @10:18 id nested Unresolved.nested [v package] : ? : ? +TOKEN @10:18 +TOKEN @10:24 +METHOD @12:3 method Unresolved.run [m package] : ? @MissingAnnotation (?) returns void throws [] sig Unresolved#run(Ljava/lang/Object;)V overrides null + details declared true usages 0 metadata [MissingAnnotation()] nullability UNKNOWN/METHOD nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [MissingAnnotation tree false values 0 annotated true] typeArguments [] enclosing Unresolved flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [argument] parameterMetadata [] +MODIFIERS @12:3 +ANNOTATION @12:3 : ? +TOKEN @12:3 +IDENTIFIER @12:4 id MissingAnnotation unknown : ? +TOKEN @12:4 +ARGUMENTS @12:21 +TOKEN @12:21 +ASSIGNMENT @12:22 : java.lang.String +IDENTIFIER @12:22 id value unknown : ? +TOKEN @12:22 +TOKEN @12:28 +STRING_LITERAL @12:30 : java.lang.String = x +TOKEN @12:30 +TOKEN @12:33 +ASSIGNMENT @12:35 : int +IDENTIFIER @12:35 id count unknown : ? +TOKEN @12:35 +TOKEN @12:41 +INT_LITERAL @12:43 : int = 2 +TOKEN @12:43 +TOKEN @12:44 +TYPE_PARAMETERS +PRIMITIVE_TYPE @13:3 : void +TOKEN @13:3 +IDENTIFIER @13:8 id run Unresolved.run [m package] : ? @MissingAnnotation (?) returns void throws [] sig Unresolved#run(Ljava/lang/Object;)V : void +TOKEN @13:8 +TOKEN @13:11 +VARIABLE @13:12 var run.argument [v package] : ? + details declared true usages 2 metadata [] nullability UNKNOWN/METHOD nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local true parameter true effectivelyFinal true constant null owner run Unresolved#run(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Unresolved type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @13:12 id Missing unknown : ? +TOKEN @13:12 +IDENTIFIER @13:20 id argument run.argument [v package] : ? : ? +TOKEN @13:20 +TOKEN @13:28 +BLOCK @13:30 +TOKEN @13:30 +VARIABLE @14:5 var run.local [v package] : ? + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local true parameter false effectivelyFinal true constant null owner run Unresolved#run(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Unresolved type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @14:5 id Missing unknown : ? +TOKEN @14:5 +IDENTIFIER @14:13 id local run.local [v package] : ? : ? +TOKEN @14:13 +TOKEN @14:19 +NEW_CLASS @14:21 new unknown : ? +TOKEN @14:21 +IDENTIFIER @14:25 id Missing unknown : ? +TOKEN @14:25 +ARGUMENTS @14:32 +TOKEN @14:32 +IDENTIFIER @14:33 id argument run.argument [v package] : ? : ? +TOKEN @14:33 +TOKEN @14:41 +TOKEN @14:42 +EXPRESSION_STATEMENT @15:5 +METHOD_INVOCATION @15:5 call unknown : ? +MEMBER_SELECT @15:5 : ? +IDENTIFIER @15:5 id local run.local [v package] : ? : ? +TOKEN @15:5 +TOKEN @15:10 +IDENTIFIER @15:11 id doSomething unknown : ? +TOKEN @15:11 +ARGUMENTS @15:22 +TOKEN @15:22 +INT_LITERAL @15:23 : int = 1 +TOKEN @15:23 +TOKEN @15:24 +STRING_LITERAL @15:26 : java.lang.String = two +TOKEN @15:26 +TOKEN @15:31 +TOKEN @15:32 +EXPRESSION_STATEMENT @16:5 +METHOD_INVOCATION @16:5 call unknown : ? +MEMBER_SELECT @16:5 : ? +METHOD_INVOCATION @16:5 call unknown : ? +MEMBER_SELECT @16:5 : ? +METHOD_INVOCATION @16:5 call unknown : ? +MEMBER_SELECT @16:5 : ? +IDENTIFIER @16:5 id service Unresolved.service [v package] : ? : ? +TOKEN @16:5 +TOKEN @16:12 +IDENTIFIER @16:13 id call unknown : ? +TOKEN @16:13 +ARGUMENTS @16:17 +TOKEN @16:17 +TOKEN @16:18 +TOKEN @16:19 +IDENTIFIER @16:20 id chain unknown : ? +TOKEN @16:20 +ARGUMENTS @16:25 +TOKEN @16:25 +TOKEN @16:26 +TOKEN @16:27 +IDENTIFIER @16:28 id end unknown : ? +TOKEN @16:28 +ARGUMENTS @16:31 +TOKEN @16:31 +TOKEN @16:32 +TOKEN @16:33 +EXPRESSION_STATEMENT @17:5 +METHOD_INVOCATION @17:5 call unknown : ? +IDENTIFIER @17:5 id help unknown : ? +TOKEN @17:5 +ARGUMENTS @17:9 +TOKEN @17:9 +IDENTIFIER @17:10 id local run.local [v package] : ? : ? +TOKEN @17:10 +TOKEN @17:15 +TOKEN @17:16 +EXPRESSION_STATEMENT @18:5 +METHOD_INVOCATION @18:5 call unknown : ? +IDENTIFIER @18:5 id unknownMethod unknown : ? +TOKEN @18:5 +ARGUMENTS @18:18 +TOKEN @18:18 +TOKEN @18:19 +TOKEN @18:20 +VARIABLE @19:5 var run.length [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local true parameter false effectivelyFinal true constant null owner run Unresolved#run(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Unresolved type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @19:5 : int +TOKEN @19:5 +IDENTIFIER @19:9 id length run.length [v package] : int : int +TOKEN @19:9 +TOKEN @19:16 +PLUS @19:18 : ? +METHOD_INVOCATION @19:18 call unknown : ? +MEMBER_SELECT @19:18 : ? +IDENTIFIER @19:18 id local run.local [v package] : ? : ? +TOKEN @19:18 +TOKEN @19:23 +IDENTIFIER @19:24 id size unknown : ? +TOKEN @19:24 +ARGUMENTS @19:28 +TOKEN @19:28 +TOKEN @19:29 +TOKEN @19:31 +METHOD_INVOCATION @19:33 call unknown : ? +MEMBER_SELECT @19:33 : ? +IDENTIFIER @19:33 id items Unresolved.items [v package] : ? : ? +TOKEN @19:33 +TOKEN @19:38 +IDENTIFIER @19:39 id size unknown : int +TOKEN @19:39 +ARGUMENTS @19:43 +TOKEN @19:43 +TOKEN @19:44 +TOKEN @19:45 +VARIABLE @20:5 var run.text [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local true parameter false effectivelyFinal true constant null owner run Unresolved#run(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Unresolved type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @20:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @20:5 +IDENTIFIER @20:12 id text run.text [v package] : java.lang.String : java.lang.String +TOKEN @20:12 +TOKEN @20:17 +MEMBER_SELECT @20:19 : ? +IDENTIFIER @20:19 id argument run.argument [v package] : ? : ? +TOKEN @20:19 +TOKEN @20:27 +IDENTIFIER @20:28 id name unknown : ? +TOKEN @20:28 +TOKEN @20:32 +VARIABLE @21:5 var run.created [v package] : java.lang.Object + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local true parameter false effectivelyFinal true constant null owner run Unresolved#run(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Unresolved type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @21:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @21:5 +IDENTIFIER @21:12 id created run.created [v package] : java.lang.Object : java.lang.Object +TOKEN @21:12 +TOKEN @21:20 +NEW_CLASS @21:22 new unknown : Unresolved$1 +TOKEN @21:22 +PARAMETERIZED_TYPE @21:26 : ? +IDENTIFIER @21:26 id Unknown unknown : ? +TOKEN @21:26 +TYPE_ARGUMENTS @21:33 +TOKEN @21:33 +IDENTIFIER @21:34 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @21:34 +TOKEN @21:40 +ARGUMENTS @21:41 +TOKEN @21:41 +TOKEN @21:42 +CLASS @21:44 class run. [t package] : Unresolved$1 super ? interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] members [, inner] lookupToString 0 outermost Unresolved annotation false subtypeOf [] superTypes [?] numerical false wrapper false raw false declaring +MODIFIERS +TYPE_PARAMETERS +LIST +LIST +TOKEN @21:44 +METHOD @22:7 method .inner [m package] : ? () returns void throws [] sig Unresolved$1#inner()V overrides null + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @22:7 : void +TOKEN @22:7 +IDENTIFIER @22:12 id inner .inner [m package] : ? () returns void throws [] sig Unresolved$1#inner()V : void +TOKEN @22:12 +TOKEN @22:17 +TOKEN @22:18 +BLOCK @22:20 +TOKEN @22:20 +TOKEN @23:7 +TOKEN @24:5 +TOKEN @24:6 +VARIABLE @25:5 var run.names [v package] : java.util.List + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Unresolved flags [package] local true parameter false effectivelyFinal true constant null owner run Unresolved#run(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Unresolved type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @25:5 : java.util.List +IDENTIFIER @25:5 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @25:5 +TYPE_ARGUMENTS @25:9 +TOKEN @25:9 +IDENTIFIER @25:10 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @25:10 +TOKEN @25:16 +IDENTIFIER @25:18 id names run.names [v package] : java.util.List : java.util.List +TOKEN @25:18 +TOKEN @25:24 +METHOD_INVOCATION @25:26 call Stream.toList [m public] : ? () returns java.util.List throws [] sig java.util.stream.Stream#toList()Ljava/util/List; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [public] overridden [] overridable true generic false default true synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @25:26 : ? +METHOD_INVOCATION @25:26 call Stream.map [m abstract public] : ? (java.util.function.Function) returns java.util.stream.Stream throws [] sig java.util.stream.Stream#map(Ljava/util/function/Function;)Ljava/util/stream/Stream; : java.util.stream.Stream + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Stream flags [abstract, public] overridden [] overridable true generic true default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @25:26 : ? +METHOD_INVOCATION @25:26 call unknown : ? +MEMBER_SELECT @25:26 : ? +IDENTIFIER @25:26 id items Unresolved.items [v package] : ? : ? +TOKEN @25:26 +TOKEN @25:31 +IDENTIFIER @25:32 id stream unknown : java.util.stream.Stream +TOKEN @25:32 +ARGUMENTS @25:38 +TOKEN @25:38 +TOKEN @25:39 +TOKEN @25:40 +IDENTIFIER @25:41 id map Stream.map [m abstract public] : ? (java.util.function.Function) returns java.util.stream.Stream throws [] sig java.util.stream.Stream#map(Ljava/util/function/Function;)Ljava/util/stream/Stream; : java.util.stream.Stream +TOKEN @25:41 +ARGUMENTS @25:44 +TOKEN @25:44 +METHOD_REFERENCE @25:45 : java.util.function.Function +IDENTIFIER @25:45 id Missing unknown : ? +TOKEN @25:45 +TOKEN @25:52 +IDENTIFIER @25:54 id name unknown : ? +TOKEN @25:54 +TOKEN @25:58 +TOKEN @25:59 +IDENTIFIER @25:60 id toList Stream.toList [m public] : ? () returns java.util.List throws [] sig java.util.stream.Stream#toList()Ljava/util/List; : java.util.List +TOKEN @25:60 +ARGUMENTS @25:66 +TOKEN @25:66 +TOKEN @25:67 +TOKEN @25:68 +FOR_EACH_STATEMENT @26:5 +TOKEN @26:5 +TOKEN @26:9 +VARIABLE @26:10 var run.item [v package] : ? + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local true parameter false effectivelyFinal true constant null owner run Unresolved#run(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Unresolved type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @26:10 id Missing unknown : ? +TOKEN @26:10 +IDENTIFIER @26:18 id item run.item [v package] : ? : ? +TOKEN @26:18 +TOKEN @26:23 +IDENTIFIER @26:25 id items Unresolved.items [v package] : ? : ? +TOKEN @26:25 +TOKEN @26:30 +BLOCK @26:32 +TOKEN @26:32 +EXPRESSION_STATEMENT @27:7 +METHOD_INVOCATION @27:7 call unknown : ? +MEMBER_SELECT @27:7 : ? +IDENTIFIER @27:7 id item run.item [v package] : ? : ? +TOKEN @27:7 +TOKEN @27:11 +IDENTIFIER @27:12 id process unknown : ? +TOKEN @27:12 +ARGUMENTS @27:19 +TOKEN @27:19 +TOKEN @27:20 +TOKEN @27:21 +TOKEN @28:5 +TRY_STATEMENT @29:5 +TOKEN @29:5 +BLOCK @29:9 +TOKEN @29:9 +EXPRESSION_STATEMENT @30:7 +METHOD_INVOCATION @30:7 call unknown : ? +MEMBER_SELECT @30:7 : ? +IDENTIFIER @30:7 id local run.local [v package] : ? : ? +TOKEN @30:7 +TOKEN @30:12 +IDENTIFIER @30:13 id risky unknown : ? +TOKEN @30:13 +ARGUMENTS @30:18 +TOKEN @30:18 +TOKEN @30:19 +TOKEN @30:20 +TOKEN @31:5 +CATCH @31:7 +TOKEN @31:7 +TOKEN @31:13 +VARIABLE @31:14 var run.e [v package] : ? + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local true parameter false effectivelyFinal true constant null owner run Unresolved#run(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Unresolved type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @31:14 id MissingException unknown : ? +TOKEN @31:14 +IDENTIFIER @31:31 id e run.e [v package] : ? : ? +TOKEN @31:31 +TOKEN @31:32 +BLOCK @31:34 +TOKEN @31:34 +EXPRESSION_STATEMENT @32:7 +METHOD_INVOCATION @32:7 call unknown : ? +MEMBER_SELECT @32:7 : ? +IDENTIFIER @32:7 id e run.e [v package] : ? : ? +TOKEN @32:7 +TOKEN @32:8 +IDENTIFIER @32:9 id handle unknown : ? +TOKEN @32:9 +ARGUMENTS @32:15 +TOKEN @32:15 +TOKEN @32:16 +TOKEN @32:17 +TOKEN @33:5 +VARIABLE @34:5 var run.array [v package] : ? + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local true parameter false effectivelyFinal true constant null owner run Unresolved#run(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Unresolved type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +ARRAY_TYPE @34:5 : ? +IDENTIFIER @34:5 id Missing unknown : ? +TOKEN @34:5 +TOKEN @34:12 +TOKEN @34:13 +IDENTIFIER @34:15 id array run.array [v package] : ? : ? +TOKEN @34:15 +TOKEN @34:21 +NEW_ARRAY @34:23 : ? +TOKEN @34:23 +IDENTIFIER @34:27 id Missing unknown : ? +TOKEN @34:27 +ARRAY_DIMENSION @34:34 +TOKEN @34:34 +IDENTIFIER @34:35 id length run.length [v package] : int : int +TOKEN @34:35 +TOKEN @34:41 +LIST +TOKEN @34:42 +VARIABLE @35:5 var run.cast [v package] : java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local true parameter false effectivelyFinal true constant null owner run Unresolved#run(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Unresolved type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @35:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @35:5 +IDENTIFIER @35:12 id cast run.cast [v package] : java.lang.Object : java.lang.Object +TOKEN @35:12 +TOKEN @35:17 +TYPE_CAST @35:19 : ? +TOKEN @35:19 +IDENTIFIER @35:20 id Missing unknown : ? +TOKEN @35:20 +LIST +TOKEN @35:27 +IDENTIFIER @35:29 id created run.created [v package] : java.lang.Object : java.lang.Object +TOKEN @35:29 +TOKEN @35:36 +VARIABLE @36:5 var run.test [v package] : boolean + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local true parameter false effectivelyFinal true constant null owner run Unresolved#run(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Unresolved type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @36:5 : boolean +TOKEN @36:5 +IDENTIFIER @36:13 id test run.test [v package] : boolean : boolean +TOKEN @36:13 +TOKEN @36:18 +CONDITIONAL_AND @36:20 : boolean +PATTERN_INSTANCE_OF @36:20 : boolean +IDENTIFIER @36:20 id created run.created [v package] : java.lang.Object : java.lang.Object +TOKEN @36:20 +TOKEN @36:28 +TYPE_PATTERN @36:39 : ? +VARIABLE @36:39 var run.missing [v package] : ? + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unresolved flags [package] local true parameter false effectivelyFinal true constant null owner run Unresolved#run(Ljava/lang/Object;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 1 enclosing Unresolved type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @36:39 id Missing unknown : ? +TOKEN @36:39 +IDENTIFIER @36:47 id missing run.missing [v package] : ? : ? +TOKEN @36:47 +TOKEN @36:55 +METHOD_INVOCATION @36:58 call unknown : ? +MEMBER_SELECT @36:58 : ? +IDENTIFIER @36:58 id missing run.missing [v package] : ? : ? +TOKEN @36:58 +TOKEN @36:65 +IDENTIFIER @36:66 id valid unknown : ? +TOKEN @36:66 +ARGUMENTS @36:71 +TOKEN @36:71 +TOKEN @36:72 +TOKEN @36:73 +TOKEN @37:3 +TOKEN @38:1 +TOKEN @39:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Unresolved.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Unresolved.java new file mode 100644 index 00000000000..ac4453aabf1 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Unresolved.java @@ -0,0 +1,38 @@ +import com.example.missing.Service; +import com.example.missing.*; +import static com.example.missing.Helpers.help; +import java.util.List; + +class Unresolved extends MissingBase implements MissingInterface { + + Service service; + List items; + Missing.Nested nested; + + @MissingAnnotation(value = "x", count = 2) + void run(Missing argument) { + Missing local = new Missing(argument); + local.doSomething(1, "two"); + service.call().chain().end(); + help(local); + unknownMethod(); + int length = local.size() + items.size(); + String text = argument.name; + Object created = new Unknown() { + void inner() { + } + }; + List names = items.stream().map(Missing::name).toList(); + for (Missing item : items) { + item.process(); + } + try { + local.risky(); + } catch (MissingException e) { + e.handle(); + } + Missing[] array = new Missing[length]; + Object cast = (Missing) created; + boolean test = created instanceof Missing missing && missing.valid(); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Unresolved.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Unresolved.textproto.gz new file mode 100644 index 00000000000..54ba921026e Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Unresolved.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Warnings.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Warnings.expected.txt new file mode 100644 index 00000000000..3ee7287c81c --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Warnings.expected.txt @@ -0,0 +1,1084 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id io unknown : ? +TOKEN @1:13 +TOKEN @1:15 +IDENTIFIER @1:16 id FileNotFoundException unknown : ? +TOKEN @1:16 +TOKEN @1:37 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id io unknown : ? +TOKEN @2:13 +TOKEN @2:15 +IDENTIFIER @2:16 id IOException unknown : ? +TOKEN @2:16 +TOKEN @2:27 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id io unknown : ? +TOKEN @3:13 +TOKEN @3:15 +IDENTIFIER @3:16 id InputStream unknown : ? +TOKEN @3:16 +TOKEN @3:27 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id util unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id ArrayList unknown : ? +TOKEN @4:18 +TOKEN @4:27 +IMPORT @5:1 +TOKEN @5:1 +MEMBER_SELECT @5:8 : ? +MEMBER_SELECT @5:8 : ? +IDENTIFIER @5:8 id java unknown : ? +TOKEN @5:8 +TOKEN @5:12 +IDENTIFIER @5:13 id util unknown : ? +TOKEN @5:13 +TOKEN @5:17 +IDENTIFIER @5:18 id HashMap unknown : ? +TOKEN @5:18 +TOKEN @5:25 +IMPORT @6:1 +TOKEN @6:1 +MEMBER_SELECT @6:8 : ? +MEMBER_SELECT @6:8 : ? +IDENTIFIER @6:8 id java unknown : ? +TOKEN @6:8 +TOKEN @6:12 +IDENTIFIER @6:13 id util unknown : ? +TOKEN @6:13 +TOKEN @6:17 +IDENTIFIER @6:18 id List unknown : ? +TOKEN @6:18 +TOKEN @6:22 +IMPORT @7:1 +TOKEN @7:1 +MEMBER_SELECT @7:8 : ? +MEMBER_SELECT @7:8 : ? +IDENTIFIER @7:8 id java unknown : ? +TOKEN @7:8 +TOKEN @7:12 +IDENTIFIER @7:13 id util unknown : ? +TOKEN @7:13 +TOKEN @7:17 +IDENTIFIER @7:18 id Map unknown : ? +TOKEN @7:18 +TOKEN @7:21 +IMPORT @8:1 +TOKEN @8:1 +MEMBER_SELECT @8:8 : ? +MEMBER_SELECT @8:8 : ? +IDENTIFIER @8:8 id java unknown : ? +TOKEN @8:8 +TOKEN @8:12 +IDENTIFIER @8:13 id util unknown : ? +TOKEN @8:13 +TOKEN @8:17 +IDENTIFIER @8:18 id Set unknown : ? +TOKEN @8:18 +TOKEN @8:21 +IMPORT @9:1 +TOKEN @9:1 +MEMBER_SELECT @9:8 : ? +MEMBER_SELECT @9:8 : ? +MEMBER_SELECT @9:8 : ? +IDENTIFIER @9:8 id java unknown : ? +TOKEN @9:8 +TOKEN @9:12 +IDENTIFIER @9:13 id util unknown : ? +TOKEN @9:13 +TOKEN @9:17 +IDENTIFIER @9:18 id concurrent unknown : ? +TOKEN @9:18 +TOKEN @9:28 +IDENTIFIER @9:29 id Callable unknown : ? +TOKEN @9:29 +TOKEN @9:37 +IMPORT @10:1 +TOKEN @10:1 +TOKEN @10:8 +MEMBER_SELECT @10:15 : ? +MEMBER_SELECT @10:15 : ? +MEMBER_SELECT @10:15 : ? +IDENTIFIER @10:15 id java unknown : ? +TOKEN @10:15 +TOKEN @10:19 +IDENTIFIER @10:20 id lang unknown : ? +TOKEN @10:20 +TOKEN @10:24 +IDENTIFIER @10:25 id Math unknown : ? +TOKEN @10:25 +TOKEN @10:29 +IDENTIFIER @10:30 id max unknown : ? +TOKEN @10:30 +TOKEN @10:33 +IMPORT @11:1 +TOKEN @11:1 +TOKEN @11:8 +MEMBER_SELECT @11:15 : ? +MEMBER_SELECT @11:15 : ? +MEMBER_SELECT @11:15 : ? +IDENTIFIER @11:15 id java unknown : ? +TOKEN @11:15 +TOKEN @11:19 +IDENTIFIER @11:20 id lang unknown : ? +TOKEN @11:20 +TOKEN @11:24 +IDENTIFIER @11:25 id Math unknown : ? +TOKEN @11:25 +TOKEN @11:29 +IDENTIFIER @11:30 id min unknown : ? +TOKEN @11:30 +TOKEN @11:33 +IMPORT @12:1 +TOKEN @12:1 +TOKEN @12:8 +MEMBER_SELECT @12:15 : ? +MEMBER_SELECT @12:15 : ? +MEMBER_SELECT @12:15 : ? +IDENTIFIER @12:15 id java unknown : ? +TOKEN @12:15 +TOKEN @12:19 +IDENTIFIER @12:20 id util unknown : ? +TOKEN @12:20 +TOKEN @12:24 +IDENTIFIER @12:25 id Collections unknown : ? +TOKEN @12:25 +TOKEN @12:36 +IDENTIFIER @12:37 id * unknown : ? +TOKEN @12:37 +TOKEN @12:38 +CLASS @14:1 class .Warnings [t package] : Warnings super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] members [, assignments, casts, catches, effectivelyFinal, field] lookupToString 0 outermost Warnings annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Warnings +MODIFIERS +TOKEN @14:1 +IDENTIFIER @14:7 id Warnings .Warnings [t package] : Warnings : Warnings +TOKEN @14:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @14:16 +VARIABLE @16:3 var Warnings.field [v package] : int + details declared true usages 4 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @16:3 : int +TOKEN @16:3 +IDENTIFIER @16:7 id field Warnings.field [v package] : int : int +TOKEN @16:7 +TOKEN @16:12 +METHOD @18:3 method Warnings.casts [m package] : ? (java.lang.Object,java.lang.String,int,long,java.util.List) returns void throws [] sig Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [o, s, i, l, list] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @18:3 : void +TOKEN @18:3 +IDENTIFIER @18:8 id casts Warnings.casts [m package] : ? (java.lang.Object,java.lang.String,int,long,java.util.List) returns void throws [] sig Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V : void +TOKEN @18:8 +TOKEN @18:13 +VARIABLE @18:14 var casts.o [v package] : java.lang.Object + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter true effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +IDENTIFIER @18:14 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @18:14 +IDENTIFIER @18:21 id o casts.o [v package] : java.lang.Object : java.lang.Object +TOKEN @18:21 +TOKEN @18:22 +VARIABLE @18:24 var casts.s [v package] : java.lang.String + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter true effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +IDENTIFIER @18:24 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @18:24 +IDENTIFIER @18:31 id s casts.s [v package] : java.lang.String : java.lang.String +TOKEN @18:31 +TOKEN @18:32 +VARIABLE @18:34 var casts.i [v package] : int + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter true effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +PRIMITIVE_TYPE @18:34 : int +TOKEN @18:34 +IDENTIFIER @18:38 id i casts.i [v package] : int : int +TOKEN @18:38 +TOKEN @18:39 +VARIABLE @18:41 var casts.l [v package] : long + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter true effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +PRIMITIVE_TYPE @18:41 : long +TOKEN @18:41 +IDENTIFIER @18:46 id l casts.l [v package] : long : long +TOKEN @18:46 +TOKEN @18:47 +VARIABLE @18:49 var casts.list [v package] : java.util.List + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Warnings flags [package] local true parameter true effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +PARAMETERIZED_TYPE @18:49 : java.util.List +IDENTIFIER @18:49 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @18:49 +TYPE_ARGUMENTS @18:53 +TOKEN @18:53 +IDENTIFIER @18:54 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @18:54 +TOKEN @18:60 +IDENTIFIER @18:62 id list casts.list [v package] : java.util.List : java.util.List +TOKEN @18:62 +TOKEN @18:66 +BLOCK @18:68 +TOKEN @18:68 +VARIABLE @19:5 var casts.same [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +IDENTIFIER @19:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @19:5 +IDENTIFIER @19:12 id same casts.same [v package] : java.lang.String : java.lang.String +TOKEN @19:12 +TOKEN @19:17 +TYPE_CAST @19:19 : java.lang.String +TOKEN @19:19 +IDENTIFIER @19:20 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @19:20 +LIST +TOKEN @19:26 +IDENTIFIER @19:28 id s casts.s [v package] : java.lang.String : java.lang.String +TOKEN @19:28 +TOKEN @19:29 +VARIABLE @20:5 var casts.widened [v package] : java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +IDENTIFIER @20:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @20:5 +IDENTIFIER @20:12 id widened casts.widened [v package] : java.lang.Object : java.lang.Object +TOKEN @20:12 +TOKEN @20:20 +TYPE_CAST @20:22 : java.lang.Object +TOKEN @20:22 +IDENTIFIER @20:23 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @20:23 +LIST +TOKEN @20:29 +IDENTIFIER @20:31 id s casts.s [v package] : java.lang.String : java.lang.String +TOKEN @20:31 +TOKEN @20:32 +VARIABLE @21:5 var casts.promoted [v package] : long + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +PRIMITIVE_TYPE @21:5 : long +TOKEN @21:5 +IDENTIFIER @21:10 id promoted casts.promoted [v package] : long : long +TOKEN @21:10 +TOKEN @21:19 +TYPE_CAST @21:21 : long +TOKEN @21:21 +PRIMITIVE_TYPE @21:22 : long +TOKEN @21:22 +LIST +TOKEN @21:26 +IDENTIFIER @21:28 id i casts.i [v package] : int : int +TOKEN @21:28 +TOKEN @21:29 +VARIABLE @22:5 var casts.narrowed [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +PRIMITIVE_TYPE @22:5 : int +TOKEN @22:5 +IDENTIFIER @22:9 id narrowed casts.narrowed [v package] : int : int +TOKEN @22:9 +TOKEN @22:18 +TYPE_CAST @22:20 : int +TOKEN @22:20 +PRIMITIVE_TYPE @22:21 : int +TOKEN @22:21 +LIST +TOKEN @22:24 +IDENTIFIER @22:26 id l casts.l [v package] : long : long +TOKEN @22:26 +TOKEN @22:27 +VARIABLE @23:5 var casts.mixed [v package] : double + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +PRIMITIVE_TYPE @23:5 : double +TOKEN @23:5 +IDENTIFIER @23:12 id mixed casts.mixed [v package] : double : double +TOKEN @23:12 +TOKEN @23:18 +DIVIDE @23:20 : double +TYPE_CAST @23:20 : double +TOKEN @23:20 +PRIMITIVE_TYPE @23:21 : double +TOKEN @23:21 +LIST +TOKEN @23:27 +IDENTIFIER @23:29 id i casts.i [v package] : int : int +TOKEN @23:29 +TOKEN @23:31 +INT_LITERAL @23:33 : int = 2 +TOKEN @23:33 +TOKEN @23:34 +VARIABLE @24:5 var casts.downcast [v package] : java.lang.String + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +IDENTIFIER @24:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @24:5 +IDENTIFIER @24:12 id downcast casts.downcast [v package] : java.lang.String : java.lang.String +TOKEN @24:12 +TOKEN @24:21 +TYPE_CAST @24:23 : java.lang.String +TOKEN @24:23 +IDENTIFIER @24:24 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @24:24 +LIST +TOKEN @24:30 +IDENTIFIER @24:32 id o casts.o [v package] : java.lang.Object : java.lang.Object +TOKEN @24:32 +TOKEN @24:33 +VARIABLE @25:5 var casts.fromList [v package] : java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +IDENTIFIER @25:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @25:5 +IDENTIFIER @25:12 id fromList casts.fromList [v package] : java.lang.Object : java.lang.Object +TOKEN @25:12 +TOKEN @25:21 +TYPE_CAST @25:23 : java.lang.Object +TOKEN @25:23 +IDENTIFIER @25:24 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @25:24 +LIST +TOKEN @25:30 +METHOD_INVOCATION @25:32 call List.get [m abstract public] : ? (int) returns java.lang.String throws [] sig java.util.List#get(I)Ljava/lang/Object; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @25:32 : ? +IDENTIFIER @25:32 id list casts.list [v package] : java.util.List : java.util.List +TOKEN @25:32 +TOKEN @25:36 +IDENTIFIER @25:37 id get List.get [m abstract public] : ? (int) returns java.lang.String throws [] sig java.util.List#get(I)Ljava/lang/Object; : java.lang.String +TOKEN @25:37 +ARGUMENTS @25:40 +TOKEN @25:40 +INT_LITERAL @25:41 : int = 0 +TOKEN @25:41 +TOKEN @25:42 +TOKEN @25:43 +VARIABLE @26:5 var casts.boxed [v package] : java.lang.Integer + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +IDENTIFIER @26:5 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @26:5 +IDENTIFIER @26:13 id boxed casts.boxed [v package] : java.lang.Integer : java.lang.Integer +TOKEN @26:13 +TOKEN @26:19 +TYPE_CAST @26:21 : java.lang.Integer +TOKEN @26:21 +IDENTIFIER @26:22 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @26:22 +LIST +TOKEN @26:29 +IDENTIFIER @26:31 id i casts.i [v package] : int : int +TOKEN @26:31 +TOKEN @26:32 +VARIABLE @27:5 var casts.unboxed [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +PRIMITIVE_TYPE @27:5 : int +TOKEN @27:5 +IDENTIFIER @27:9 id unboxed casts.unboxed [v package] : int : int +TOKEN @27:9 +TOKEN @27:17 +TYPE_CAST @27:19 : int +TOKEN @27:19 +PRIMITIVE_TYPE @27:20 : int +TOKEN @27:20 +LIST +TOKEN @27:23 +IDENTIFIER @27:25 id boxed casts.boxed [v package] : java.lang.Integer : java.lang.Integer +TOKEN @27:25 +TOKEN @27:30 +VARIABLE @28:5 var casts.lambda [v package] : java.lang.Runnable + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +IDENTIFIER @28:5 id Runnable java.lang.Runnable [t public interface] : java.lang.Runnable @java.lang.FunctionalInterface : java.lang.Runnable +TOKEN @28:5 +IDENTIFIER @28:14 id lambda casts.lambda [v package] : java.lang.Runnable : java.lang.Runnable +TOKEN @28:14 +TOKEN @28:21 +TYPE_CAST @28:23 : java.lang.Runnable +TOKEN @28:23 +IDENTIFIER @28:24 id Runnable java.lang.Runnable [t public interface] : java.lang.Runnable @java.lang.FunctionalInterface : java.lang.Runnable +TOKEN @28:24 +LIST +TOKEN @28:32 +LAMBDA_EXPRESSION @28:34 : ? +TOKEN @28:34 +TOKEN @28:35 +TOKEN @28:37 +BLOCK @28:40 +TOKEN @28:40 +TOKEN @29:5 +TOKEN @29:6 +VARIABLE @30:5 var casts.generic [v package] : java.util.List + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +PARAMETERIZED_TYPE @30:5 : java.util.List +IDENTIFIER @30:5 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @30:5 +TYPE_ARGUMENTS @30:9 +TOKEN @30:9 +IDENTIFIER @30:10 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @30:10 +TOKEN @30:16 +IDENTIFIER @30:18 id generic casts.generic [v package] : java.util.List : java.util.List +TOKEN @30:18 +TOKEN @30:26 +TYPE_CAST @30:28 : java.util.List +TOKEN @30:28 +PARAMETERIZED_TYPE @30:29 : java.util.List +IDENTIFIER @30:29 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @30:29 +TYPE_ARGUMENTS @30:33 +TOKEN @30:33 +IDENTIFIER @30:34 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @30:34 +TOKEN @30:40 +LIST +TOKEN @30:41 +IDENTIFIER @30:43 id list casts.list [v package] : java.util.List : java.util.List +TOKEN @30:43 +TOKEN @30:47 +VARIABLE @31:5 var casts.array [v package] : java.lang.Object + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +IDENTIFIER @31:5 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @31:5 +IDENTIFIER @31:12 id array casts.array [v package] : java.lang.Object : java.lang.Object +TOKEN @31:12 +TOKEN @31:18 +TYPE_CAST @31:20 : java.lang.Object[] +TOKEN @31:20 +ARRAY_TYPE @31:21 : java.lang.Object[] +IDENTIFIER @31:21 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @31:21 +TOKEN @31:27 +TOKEN @31:28 +LIST +TOKEN @31:29 +NEW_ARRAY @31:31 : java.lang.String[] +TOKEN @31:31 +IDENTIFIER @31:35 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @31:35 +ARRAY_DIMENSION @31:41 +TOKEN @31:41 +INT_LITERAL @31:42 : int = 0 +TOKEN @31:42 +TOKEN @31:43 +LIST +TOKEN @31:44 +VARIABLE @32:5 var casts.letter [v package] : char + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner casts Warnings#casts(Ljava/lang/Object;Ljava/lang/String;IJLjava/util/List;)V [package] returns void parameters 5 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse5falsefalse +MODIFIERS +PRIMITIVE_TYPE @32:5 : char +TOKEN @32:5 +IDENTIFIER @32:10 id letter casts.letter [v package] : char : char +TOKEN @32:10 +TOKEN @32:17 +TYPE_CAST @32:19 : char +TOKEN @32:19 +PRIMITIVE_TYPE @32:20 : char +TOKEN @32:20 +LIST +TOKEN @32:24 +INT_LITERAL @32:26 : int = 65 +TOKEN @32:26 +TOKEN @32:28 +TOKEN @33:3 +METHOD @35:3 method Warnings.assignments [m package] : ? (int) returns void throws [] sig Warnings#assignments(I)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [value] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @35:3 : void +TOKEN @35:3 +IDENTIFIER @35:8 id assignments Warnings.assignments [m package] : ? (int) returns void throws [] sig Warnings#assignments(I)V : void +TOKEN @35:8 +TOKEN @35:19 +VARIABLE @35:20 var assignments.value [v package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter true effectivelyFinal false constant null owner assignments Warnings#assignments(I)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @35:20 : int +TOKEN @35:20 +IDENTIFIER @35:24 id value assignments.value [v package] : int : int +TOKEN @35:24 +TOKEN @35:29 +BLOCK @35:31 +TOKEN @35:31 +VARIABLE @36:5 var assignments.local [v package] : int + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal false constant null owner assignments Warnings#assignments(I)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @36:5 : int +TOKEN @36:5 +IDENTIFIER @36:9 id local assignments.local [v package] : int : int +TOKEN @36:9 +TOKEN @36:15 +INT_LITERAL @36:17 : int = 1 +TOKEN @36:17 +TOKEN @36:18 +EXPRESSION_STATEMENT @37:5 +ASSIGNMENT @37:5 : int +IDENTIFIER @37:5 id local assignments.local [v package] : int : int +TOKEN @37:5 +TOKEN @37:11 +IDENTIFIER @37:13 id local assignments.local [v package] : int : int +TOKEN @37:13 +TOKEN @37:18 +EXPRESSION_STATEMENT @38:5 +ASSIGNMENT @38:5 : int +MEMBER_SELECT @38:5 : int +IDENTIFIER @38:5 id this Warnings.this [v final] : Warnings : Warnings +TOKEN @38:5 +TOKEN @38:9 +IDENTIFIER @38:10 id field Warnings.field [v package] : int : int +TOKEN @38:10 +TOKEN @38:16 +MEMBER_SELECT @38:18 : int +IDENTIFIER @38:18 id this Warnings.this [v final] : Warnings : Warnings +TOKEN @38:18 +TOKEN @38:22 +IDENTIFIER @38:23 id field Warnings.field [v package] : int : int +TOKEN @38:23 +TOKEN @38:28 +EXPRESSION_STATEMENT @39:5 +ASSIGNMENT @39:5 : int +IDENTIFIER @39:5 id field Warnings.field [v package] : int : int +TOKEN @39:5 +TOKEN @39:11 +IDENTIFIER @39:13 id field Warnings.field [v package] : int : int +TOKEN @39:13 +TOKEN @39:18 +EXPRESSION_STATEMENT @40:5 +ASSIGNMENT @40:5 : int +IDENTIFIER @40:5 id value assignments.value [v package] : int : int +TOKEN @40:5 +TOKEN @40:11 +IDENTIFIER @40:13 id value assignments.value [v package] : int : int +TOKEN @40:13 +TOKEN @40:18 +VARIABLE @41:5 var assignments.other [v package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal false constant null owner assignments Warnings#assignments(I)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @41:5 : int +TOKEN @41:5 +IDENTIFIER @41:9 id other assignments.other [v package] : int : int +TOKEN @41:9 +TOKEN @41:15 +IDENTIFIER @41:17 id local assignments.local [v package] : int : int +TOKEN @41:17 +TOKEN @41:22 +EXPRESSION_STATEMENT @42:5 +ASSIGNMENT @42:5 : int +IDENTIFIER @42:5 id other assignments.other [v package] : int : int +TOKEN @42:5 +TOKEN @42:11 +METHOD_INVOCATION @42:13 call Math.max [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int,int) returns int throws [] sig java.lang.Math#max(II)I : int + details declared false usages 1 metadata [jdk.internal.vm.annotation.IntrinsicCandidate()] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true] typeArguments [] enclosing Math flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +IDENTIFIER @42:13 id max Math.max [m static public] : ? @jdk.internal.vm.annotation.IntrinsicCandidate (int,int) returns int throws [] sig java.lang.Math#max(II)I : int +TOKEN @42:13 +ARGUMENTS @42:16 +TOKEN @42:16 +IDENTIFIER @42:17 id other assignments.other [v package] : int : int +TOKEN @42:17 +TOKEN @42:22 +INT_LITERAL @42:24 : int = 2 +TOKEN @42:24 +TOKEN @42:25 +TOKEN @42:26 +TOKEN @43:3 +METHOD @45:3 method Warnings.catches [m package] : ? (java.io.InputStream) returns void throws [] sig Warnings#catches(Ljava/io/InputStream;)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [in] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @45:3 : void +TOKEN @45:3 +IDENTIFIER @45:8 id catches Warnings.catches [m package] : ? (java.io.InputStream) returns void throws [] sig Warnings#catches(Ljava/io/InputStream;)V : void +TOKEN @45:8 +TOKEN @45:15 +VARIABLE @45:16 var catches.in [v package] : java.io.InputStream + details declared true usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter true effectivelyFinal true constant null owner catches Warnings#catches(Ljava/io/InputStream;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @45:16 id InputStream java.io.InputStream [t abstract public] : java.io.InputStream : java.io.InputStream +TOKEN @45:16 +IDENTIFIER @45:28 id in catches.in [v package] : java.io.InputStream : java.io.InputStream +TOKEN @45:28 +TOKEN @45:30 +BLOCK @45:32 +TOKEN @45:32 +TRY_STATEMENT @46:5 +TOKEN @46:5 +BLOCK @46:9 +TOKEN @46:9 +EXPRESSION_STATEMENT @47:7 +METHOD_INVOCATION @47:7 call InputStream.read [m abstract public] : ? () returns int throws [java.io.IOException] sig java.io.InputStream#read()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing InputStream flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @47:7 : ? +IDENTIFIER @47:7 id in catches.in [v package] : java.io.InputStream : java.io.InputStream +TOKEN @47:7 +TOKEN @47:9 +IDENTIFIER @47:10 id read InputStream.read [m abstract public] : ? () returns int throws [java.io.IOException] sig java.io.InputStream#read()I : int +TOKEN @47:10 +ARGUMENTS @47:14 +TOKEN @47:14 +TOKEN @47:15 +TOKEN @47:16 +TOKEN @48:5 +CATCH @48:7 +TOKEN @48:7 +TOKEN @48:13 +VARIABLE @48:14 var catches.e [v package] : java.io.IOException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner catches Warnings#catches(Ljava/io/InputStream;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @48:14 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @48:14 +IDENTIFIER @48:26 id e catches.e [v package] : java.io.IOException : java.io.IOException +TOKEN @48:26 +TOKEN @48:27 +BLOCK @48:29 +TOKEN @48:29 +THROW_STATEMENT @49:7 +TOKEN @49:7 +NEW_CLASS @49:13 new IllegalStateException. [m public] : ? (java.lang.Throwable) returns void throws [] sig java.lang.IllegalStateException#(Ljava/lang/Throwable;)V : java.lang.IllegalStateException + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing IllegalStateException flags [public] overridden [RuntimeException.[], Exception.[], Throwable.[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @49:13 +IDENTIFIER @49:17 id IllegalStateException IllegalStateException. [m public] : ? (java.lang.Throwable) returns void throws [] sig java.lang.IllegalStateException#(Ljava/lang/Throwable;)V : java.lang.IllegalStateException +TOKEN @49:17 +ARGUMENTS @49:38 +TOKEN @49:38 +IDENTIFIER @49:39 id e catches.e [v package] : java.io.IOException : java.io.IOException +TOKEN @49:39 +TOKEN @49:40 +TOKEN @49:41 +TOKEN @50:5 +CATCH @50:7 +TOKEN @50:7 +TOKEN @50:13 +VARIABLE @50:14 var catches.e [v package] : java.lang.RuntimeException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner catches Warnings#catches(Ljava/io/InputStream;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @50:14 id RuntimeException java.lang.RuntimeException [t public] : java.lang.RuntimeException : java.lang.RuntimeException +TOKEN @50:14 +IDENTIFIER @50:31 id e catches.e [v package] : java.lang.RuntimeException : java.lang.RuntimeException +TOKEN @50:31 +TOKEN @50:32 +BLOCK @50:34 +TOKEN @50:34 +THROW_STATEMENT @51:7 +TOKEN @51:7 +IDENTIFIER @51:13 id e catches.e [v package] : java.lang.RuntimeException : java.lang.RuntimeException +TOKEN @51:13 +TOKEN @51:14 +TOKEN @52:5 +TRY_STATEMENT @53:5 +TOKEN @53:5 +BLOCK @53:9 +TOKEN @53:9 +EXPRESSION_STATEMENT @54:7 +METHOD_INVOCATION @54:7 call InputStream.read [m abstract public] : ? () returns int throws [java.io.IOException] sig java.io.InputStream#read()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing InputStream flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @54:7 : ? +IDENTIFIER @54:7 id in catches.in [v package] : java.io.InputStream : java.io.InputStream +TOKEN @54:7 +TOKEN @54:9 +IDENTIFIER @54:10 id read InputStream.read [m abstract public] : ? () returns int throws [java.io.IOException] sig java.io.InputStream#read()I : int +TOKEN @54:10 +ARGUMENTS @54:14 +TOKEN @54:14 +TOKEN @54:15 +TOKEN @54:16 +TOKEN @55:5 +CATCH @55:7 +TOKEN @55:7 +TOKEN @55:13 +VARIABLE @55:14 var catches.e [v package] : java.io.FileNotFoundException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner catches Warnings#catches(Ljava/io/InputStream;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @55:14 id FileNotFoundException java.io.FileNotFoundException [t public] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @55:14 +IDENTIFIER @55:36 id e catches.e [v package] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @55:36 +TOKEN @55:37 +BLOCK @55:39 +TOKEN @55:39 +EXPRESSION_STATEMENT @56:7 +METHOD_INVOCATION @56:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @56:7 : ? +IDENTIFIER @56:7 id e catches.e [v package] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @56:7 +TOKEN @56:8 +IDENTIFIER @56:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @56:9 +ARGUMENTS @56:24 +TOKEN @56:24 +TOKEN @56:25 +TOKEN @56:26 +TOKEN @57:5 +CATCH @57:7 +TOKEN @57:7 +TOKEN @57:13 +VARIABLE @57:14 var catches.e [v package] : java.io.IOException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner catches Warnings#catches(Ljava/io/InputStream;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @57:14 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @57:14 +IDENTIFIER @57:26 id e catches.e [v package] : java.io.IOException : java.io.IOException +TOKEN @57:26 +TOKEN @57:27 +BLOCK @57:29 +TOKEN @57:29 +EXPRESSION_STATEMENT @58:7 +METHOD_INVOCATION @58:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @58:7 : ? +IDENTIFIER @58:7 id e catches.e [v package] : java.io.IOException : java.io.IOException +TOKEN @58:7 +TOKEN @58:8 +IDENTIFIER @58:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @58:9 +ARGUMENTS @58:24 +TOKEN @58:24 +TOKEN @58:25 +TOKEN @58:26 +TOKEN @59:5 +TRY_STATEMENT @60:5 +TOKEN @60:5 +BLOCK @60:9 +TOKEN @60:9 +EXPRESSION_STATEMENT @61:7 +METHOD_INVOCATION @61:7 call InputStream.close [m public] : ? () returns void throws [java.io.IOException] sig java.io.InputStream#close()V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing InputStream flags [public] overridden [Closeable.close[], AutoCloseable.close[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @61:7 : ? +IDENTIFIER @61:7 id in catches.in [v package] : java.io.InputStream : java.io.InputStream +TOKEN @61:7 +TOKEN @61:9 +IDENTIFIER @61:10 id close InputStream.close [m public] : ? () returns void throws [java.io.IOException] sig java.io.InputStream#close()V : void +TOKEN @61:10 +ARGUMENTS @61:15 +TOKEN @61:15 +TOKEN @61:16 +TOKEN @61:17 +TOKEN @62:5 +CATCH @62:7 +TOKEN @62:7 +TOKEN @62:13 +VARIABLE @62:14 var catches.e [v package] : java.lang.Exception + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner catches Warnings#catches(Ljava/io/InputStream;)V [package] returns void parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @62:14 id Exception java.lang.Exception [t public] : java.lang.Exception : java.lang.Exception +TOKEN @62:14 +IDENTIFIER @62:24 id e catches.e [v package] : java.lang.Exception : java.lang.Exception +TOKEN @62:24 +TOKEN @62:25 +BLOCK @62:27 +TOKEN @62:27 +EXPRESSION_STATEMENT @63:7 +METHOD_INVOCATION @63:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 3 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @63:7 : ? +IDENTIFIER @63:7 id e catches.e [v package] : java.lang.Exception : java.lang.Exception +TOKEN @63:7 +TOKEN @63:8 +IDENTIFIER @63:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @63:9 +ARGUMENTS @63:24 +TOKEN @63:24 +TOKEN @63:25 +TOKEN @63:26 +TOKEN @64:5 +TOKEN @65:3 +METHOD @67:3 method Warnings.effectivelyFinal [m package] : ? (java.util.List) returns void throws [java.lang.Exception] sig Warnings#effectivelyFinal(Ljava/util/List;)V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [items] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @67:3 : void +TOKEN @67:3 +IDENTIFIER @67:8 id effectivelyFinal Warnings.effectivelyFinal [m package] : ? (java.util.List) returns void throws [java.lang.Exception] sig Warnings#effectivelyFinal(Ljava/util/List;)V : void +TOKEN @67:8 +TOKEN @67:24 +VARIABLE @67:25 var effectivelyFinal.items [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Warnings flags [package] local true parameter true effectivelyFinal true constant null owner effectivelyFinal Warnings#effectivelyFinal(Ljava/util/List;)V [package] returns void parameters 1 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @67:25 : java.util.List +IDENTIFIER @67:25 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @67:25 +TYPE_ARGUMENTS @67:29 +TOKEN @67:29 +IDENTIFIER @67:30 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @67:30 +TOKEN @67:36 +IDENTIFIER @67:38 id items effectivelyFinal.items [v package] : java.util.List : java.util.List +TOKEN @67:38 +TOKEN @67:43 +TOKEN @67:45 +LIST @67:52 +IDENTIFIER @67:52 id Exception java.lang.Exception [t public] : java.lang.Exception : java.lang.Exception +TOKEN @67:52 +BLOCK @67:62 +TOKEN @67:62 +VARIABLE @68:5 var effectivelyFinal.notFinal [v package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal false constant null owner effectivelyFinal Warnings#effectivelyFinal(Ljava/util/List;)V [package] returns void parameters 1 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @68:5 : int +TOKEN @68:5 +IDENTIFIER @68:9 id notFinal effectivelyFinal.notFinal [v package] : int : int +TOKEN @68:9 +TOKEN @68:18 +INT_LITERAL @68:20 : int = 0 +TOKEN @68:20 +TOKEN @68:21 +EXPRESSION_STATEMENT @69:5 +POSTFIX_INCREMENT @69:5 : int +IDENTIFIER @69:5 id notFinal effectivelyFinal.notFinal [v package] : int : int +TOKEN @69:5 +TOKEN @69:13 +TOKEN @69:15 +VARIABLE @70:5 var effectivelyFinal.captured [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner effectivelyFinal Warnings#effectivelyFinal(Ljava/util/List;)V [package] returns void parameters 1 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @70:5 : int +TOKEN @70:5 +IDENTIFIER @70:9 id captured effectivelyFinal.captured [v package] : int : int +TOKEN @70:9 +TOKEN @70:18 +INT_LITERAL @70:20 : int = 1 +TOKEN @70:20 +TOKEN @70:21 +VARIABLE @71:5 var effectivelyFinal.name [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner effectivelyFinal Warnings#effectivelyFinal(Ljava/util/List;)V [package] returns void parameters 1 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @71:5 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @71:5 +IDENTIFIER @71:12 id name effectivelyFinal.name [v package] : java.lang.String : java.lang.String +TOKEN @71:12 +TOKEN @71:17 +STRING_LITERAL @71:19 : java.lang.String = n +TOKEN @71:19 +TOKEN @71:22 +VARIABLE @72:5 var effectivelyFinal.callable [v package] : java.util.concurrent.Callable + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner effectivelyFinal Warnings#effectivelyFinal(Ljava/util/List;)V [package] returns void parameters 1 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @72:5 : java.util.concurrent.Callable +IDENTIFIER @72:5 id Callable java.util.concurrent.Callable [t public interface] : java.util.concurrent.Callable @java.lang.FunctionalInterface : java.util.concurrent.Callable +TOKEN @72:5 +TYPE_ARGUMENTS @72:13 +TOKEN @72:13 +IDENTIFIER @72:14 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @72:14 +TOKEN @72:20 +IDENTIFIER @72:22 id callable effectivelyFinal.callable [v package] : java.util.concurrent.Callable : java.util.concurrent.Callable +TOKEN @72:22 +TOKEN @72:31 +LAMBDA_EXPRESSION @72:33 : java.util.concurrent.Callable +TOKEN @72:33 +TOKEN @72:34 +TOKEN @72:36 +PLUS @72:39 : java.lang.String +IDENTIFIER @72:39 id name effectivelyFinal.name [v package] : java.lang.String : java.lang.String +TOKEN @72:39 +TOKEN @72:44 +IDENTIFIER @72:46 id captured effectivelyFinal.captured [v package] : int : int +TOKEN @72:46 +TOKEN @72:54 +FOR_EACH_STATEMENT @73:5 +TOKEN @73:5 +TOKEN @73:9 +VARIABLE @73:10 var effectivelyFinal.item [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner effectivelyFinal Warnings#effectivelyFinal(Ljava/util/List;)V [package] returns void parameters 1 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @73:10 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @73:10 +IDENTIFIER @73:17 id item effectivelyFinal.item [v package] : java.lang.String : java.lang.String +TOKEN @73:17 +TOKEN @73:22 +IDENTIFIER @73:24 id items effectivelyFinal.items [v package] : java.util.List : java.util.List +TOKEN @73:24 +TOKEN @73:29 +BLOCK @73:31 +TOKEN @73:31 +VARIABLE @74:7 var effectivelyFinal.r [v package] : java.lang.Runnable + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner effectivelyFinal Warnings#effectivelyFinal(Ljava/util/List;)V [package] returns void parameters 1 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @74:7 id Runnable java.lang.Runnable [t public interface] : java.lang.Runnable @java.lang.FunctionalInterface : java.lang.Runnable +TOKEN @74:7 +IDENTIFIER @74:16 id r effectivelyFinal.r [v package] : java.lang.Runnable : java.lang.Runnable +TOKEN @74:16 +TOKEN @74:18 +LAMBDA_EXPRESSION @74:20 : java.lang.Runnable +TOKEN @74:20 +TOKEN @74:21 +TOKEN @74:23 +METHOD_INVOCATION @74:26 call PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing PrintStream flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @74:26 : ? +MEMBER_SELECT @74:26 : java.io.PrintStream +IDENTIFIER @74:26 id System java.lang.System [t final public] : java.lang.System : java.lang.System +TOKEN @74:26 +TOKEN @74:32 +IDENTIFIER @74:33 id out System.out [v static final public] : java.io.PrintStream : java.io.PrintStream +TOKEN @74:33 +TOKEN @74:36 +IDENTIFIER @74:37 id println PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void +TOKEN @74:37 +ARGUMENTS @74:44 +TOKEN @74:44 +IDENTIFIER @74:45 id item effectivelyFinal.item [v package] : java.lang.String : java.lang.String +TOKEN @74:45 +TOKEN @74:49 +TOKEN @74:50 +EXPRESSION_STATEMENT @75:7 +METHOD_INVOCATION @75:7 call Runnable.run [m abstract public] : ? () returns void throws [] sig java.lang.Runnable#run()V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Runnable flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @75:7 : ? +IDENTIFIER @75:7 id r effectivelyFinal.r [v package] : java.lang.Runnable : java.lang.Runnable +TOKEN @75:7 +TOKEN @75:8 +IDENTIFIER @75:9 id run Runnable.run [m abstract public] : ? () returns void throws [] sig java.lang.Runnable#run()V : void +TOKEN @75:9 +ARGUMENTS @75:12 +TOKEN @75:12 +TOKEN @75:13 +TOKEN @75:14 +TOKEN @76:5 +EXPRESSION_STATEMENT @77:5 +METHOD_INVOCATION @77:5 call Callable.call [m abstract public] : ? () returns java.lang.String throws [java.lang.Exception] sig java.util.concurrent.Callable#call()Ljava/lang/Object; : java.lang.String + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Callable flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @77:5 : ? +IDENTIFIER @77:5 id callable effectivelyFinal.callable [v package] : java.util.concurrent.Callable : java.util.concurrent.Callable +TOKEN @77:5 +TOKEN @77:13 +IDENTIFIER @77:14 id call Callable.call [m abstract public] : ? () returns java.lang.String throws [java.lang.Exception] sig java.util.concurrent.Callable#call()Ljava/lang/Object; : java.lang.String +TOKEN @77:14 +ARGUMENTS @77:18 +TOKEN @77:18 +TOKEN @77:19 +TOKEN @77:20 +VARIABLE @78:5 var effectivelyFinal.counts [v package] : java.util.Map + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], []] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner effectivelyFinal Warnings#effectivelyFinal(Ljava/util/List;)V [package] returns void parameters 1 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @78:5 : java.util.Map +IDENTIFIER @78:5 id Map java.util.Map [t public interface] : java.util.Map : java.util.Map +TOKEN @78:5 +TYPE_ARGUMENTS @78:8 +TOKEN @78:8 +IDENTIFIER @78:9 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @78:9 +TOKEN @78:15 +IDENTIFIER @78:17 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @78:17 +TOKEN @78:24 +IDENTIFIER @78:26 id counts effectivelyFinal.counts [v package] : java.util.Map : java.util.Map +TOKEN @78:26 +TOKEN @78:33 +NEW_CLASS @78:35 new HashMap. [m public] : ? () returns void throws [] sig java.util.HashMap#()V : java.util.HashMap + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing HashMap flags [public] overridden [AbstractMap.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @78:35 +PARAMETERIZED_TYPE @78:39 : java.util.HashMap +IDENTIFIER @78:39 id HashMap HashMap. [m public] : ? () returns void throws [] sig java.util.HashMap#()V : java.util.HashMap +TOKEN @78:39 +TYPE_ARGUMENTS @78:46 +TOKEN @78:46 +TOKEN @78:47 +ARGUMENTS @78:48 +TOKEN @78:48 +TOKEN @78:49 +TOKEN @78:50 +VARIABLE @79:5 var effectivelyFinal.values [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Warnings flags [package] local true parameter false effectivelyFinal true constant null owner effectivelyFinal Warnings#effectivelyFinal(Ljava/util/List;)V [package] returns void parameters 1 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Warnings type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @79:5 : java.util.List +IDENTIFIER @79:5 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @79:5 +TYPE_ARGUMENTS @79:9 +TOKEN @79:9 +IDENTIFIER @79:10 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @79:10 +TOKEN @79:17 +IDENTIFIER @79:19 id values effectivelyFinal.values [v package] : java.util.List : java.util.List +TOKEN @79:19 +TOKEN @79:26 +NEW_CLASS @79:28 new ArrayList. [m public] : ? (java.util.Collection) returns void throws [] sig java.util.ArrayList#(Ljava/util/Collection;)V : java.util.ArrayList + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ArrayList flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @79:28 +PARAMETERIZED_TYPE @79:32 : java.util.ArrayList +IDENTIFIER @79:32 id ArrayList ArrayList. [m public] : ? (java.util.Collection) returns void throws [] sig java.util.ArrayList#(Ljava/util/Collection;)V : java.util.ArrayList +TOKEN @79:32 +TYPE_ARGUMENTS @79:41 +TOKEN @79:41 +TOKEN @79:42 +ARGUMENTS @79:43 +TOKEN @79:43 +METHOD_INVOCATION @79:44 call Map.values [m abstract public] : ? () returns java.util.Collection throws [] sig java.util.Map#values()Ljava/util/Collection; : java.util.Collection + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Map flags [abstract, public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @79:44 : ? +IDENTIFIER @79:44 id counts effectivelyFinal.counts [v package] : java.util.Map : java.util.Map +TOKEN @79:44 +TOKEN @79:50 +IDENTIFIER @79:51 id values Map.values [m abstract public] : ? () returns java.util.Collection throws [] sig java.util.Map#values()Ljava/util/Collection; : java.util.Collection +TOKEN @79:51 +ARGUMENTS @79:57 +TOKEN @79:57 +TOKEN @79:58 +TOKEN @79:59 +TOKEN @79:60 +EXPRESSION_STATEMENT @80:5 +METHOD_INVOCATION @80:5 call List.add [m abstract public] : ? (java.lang.Integer) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [abstract, public] overridden [Collection.add[]] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @80:5 : ? +IDENTIFIER @80:5 id values effectivelyFinal.values [v package] : java.util.List : java.util.List +TOKEN @80:5 +TOKEN @80:11 +IDENTIFIER @80:12 id add List.add [m abstract public] : ? (java.lang.Integer) returns boolean throws [] sig java.util.List#add(Ljava/lang/Object;)Z : boolean +TOKEN @80:12 +ARGUMENTS @80:15 +TOKEN @80:15 +IDENTIFIER @80:16 id notFinal effectivelyFinal.notFinal [v package] : int : int +TOKEN @80:16 +TOKEN @80:24 +TOKEN @80:25 +TOKEN @81:3 +TOKEN @82:1 +TOKEN @83:1 +WARNING UNUSED_IMPORT IMPORT @8:1 The import java.util.Set is never used +WARNING UNUSED_IMPORT IMPORT @11:1 The import java.lang.Math.min is never used +WARNING UNUSED_IMPORT IMPORT @12:1 The import java.util.Collections is never used +WARNING REDUNDANT_CAST TYPE_CAST @19:19 Unnecessary cast from String to String +WARNING REDUNDANT_CAST TYPE_CAST @20:22 Unnecessary cast from String to Object +WARNING REDUNDANT_CAST TYPE_CAST @21:21 Unnecessary cast from int to long +WARNING REDUNDANT_CAST TYPE_CAST @25:23 Unnecessary cast from String to Object +WARNING REDUNDANT_CAST TYPE_CAST @26:21 Unnecessary cast from int to Integer +WARNING REDUNDANT_CAST TYPE_CAST @27:19 Unnecessary cast from Integer to int +WARNING REDUNDANT_CAST TYPE_CAST @30:28 Unnecessary cast from List to List +WARNING REDUNDANT_CAST TYPE_CAST @31:20 Unnecessary cast from String[] to Object[] +WARNING ASSIGNMENT_HAS_NO_EFFECT ASSIGNMENT @37:5 The assignment to variable local has no effect +WARNING ASSIGNMENT_HAS_NO_EFFECT ASSIGNMENT @38:5 The assignment to variable field has no effect +WARNING ASSIGNMENT_HAS_NO_EFFECT ASSIGNMENT @39:5 The assignment to variable field has no effect +WARNING ASSIGNMENT_HAS_NO_EFFECT ASSIGNMENT @40:5 The assignment to variable value has no effect diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Warnings.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Warnings.java new file mode 100644 index 00000000000..31c97172c95 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Warnings.java @@ -0,0 +1,82 @@ +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Callable; +import static java.lang.Math.max; +import static java.lang.Math.min; +import static java.util.Collections.*; + +class Warnings { + + int field; + + void casts(Object o, String s, int i, long l, List list) { + String same = (String) s; + Object widened = (Object) s; + long promoted = (long) i; + int narrowed = (int) l; + double mixed = (double) i / 2; + String downcast = (String) o; + Object fromList = (Object) list.get(0); + Integer boxed = (Integer) i; + int unboxed = (int) boxed; + Runnable lambda = (Runnable) () -> { + }; + List generic = (List) list; + Object array = (Object[]) new String[0]; + char letter = (char) 65; + } + + void assignments(int value) { + int local = 1; + local = local; + this.field = this.field; + field = field; + value = value; + int other = local; + other = max(other, 2); + } + + void catches(InputStream in) { + try { + in.read(); + } catch (IOException e) { + throw new IllegalStateException(e); + } catch (RuntimeException e) { + throw e; + } + try { + in.read(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + try { + in.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + void effectivelyFinal(List items) throws Exception { + int notFinal = 0; + notFinal++; + int captured = 1; + String name = "n"; + Callable callable = () -> name + captured; + for (String item : items) { + Runnable r = () -> System.out.println(item); + r.run(); + } + callable.call(); + Map counts = new HashMap<>(); + List values = new ArrayList<>(counts.values()); + values.add(notFinal); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Warnings.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Warnings.textproto.gz new file mode 100644 index 00000000000..689855b99a7 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/Warnings.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ArrayCopyLoopCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ArrayCopyLoopCheckSample.expected.txt.gz new file mode 100644 index 00000000000..0929d1d1668 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ArrayCopyLoopCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ArrayCopyLoopCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ArrayCopyLoopCheckSample.java new file mode 100644 index 00000000000..b02f1dea34c --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ArrayCopyLoopCheckSample.java @@ -0,0 +1,649 @@ +package checks; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; + +abstract class ArrayCopyLoopCheckSample implements Collection { + + // test where src and dst are not primitives but compatible + public void coverageEdgeCase(Long[] arrWE) { + Number[] result = new Number[arrWE.length]; + for (int i = 0; i < arrWE.length; i++) { + result[i] = arrWE[i]; // Noncompliant {{Use "Arrays.copyOf", "Arrays.asList", "Collections.addAll" or "System.arraycopy" instead.}} + } + } + + public Integer[] classToClass(Long[] arrWE) { + Integer[] result = new Integer[arrWE.length]; + for (int i = 0; i < arrWE.length; i++) { + result[i] = /* using auto boxing */ Integer.parseInt(String.valueOf(arrWE[i])); // Compliant + } + return result; + } + + public Long[] classToClassLong(Integer[] arr) { + Long[] result = new Long[arr.length]; + for (int i = 0; i < arr.length; i++) { + result[i] = /* using auto boxing */ Long.parseLong(String.valueOf(arr[i])); // Compliant + } + return result; + } + + public Integer[] boxed(int[] arr) { + Integer[] result = new Integer[arr.length]; + for (int i = 0; i < arr.length; i++) { + result[i] = /* using auto boxing */ arr[i]; // Compliant + } + return result; + } + + public int[] unboxed(Integer[] arr) { + int[] result = new int[arr.length]; + for (int i = 0; i < arr.length; i++) { + result[i] = /* using auto unboxing */ arr[i]; // Compliant + } + return result; + } + + public Long[] boxed(long[] arr) { + Long[] result = new Long[arr.length]; + for (int i = 0; i < arr.length; i++) { + result[i] = /* using auto boxing */ arr[i]; // Compliant + } + return result; + } + + public long[] unboxed(Long[] arr) { + long[] result = new long[arr.length]; + for (int i = 0; i < arr.length; i++) { + result[i] = /* using auto unboxing */ arr[i]; // Compliant + } + return result; + } + + public Float[] boxed(float[] arr) { + Float[] result = new Float[arr.length]; + for (int i = 0; i < arr.length; i++) { + result[i] = /* using auto boxing */ arr[i]; // Compliant + } + return result; + } + + public float[] unboxed(Float[] arr) { + float[] result = new float[arr.length]; + for (int i = 0; i < arr.length; i++) { + result[i] = /* using auto unboxing */ arr[i]; // Compliant + } + return result; + } + + public Double[] boxed(double[] arr) { + Double[] result = new Double[arr.length]; + for (int i = 0; i < arr.length; i++) { + result[i] = /* using auto boxing */ arr[i]; // Compliant + } + return result; + } + + public double[] unboxed(Double[] arr) { + double[] result = new double[arr.length]; + for (int i = 0; i < arr.length; i++) { + result[i] = /* using auto unboxing */ arr[i]; // Compliant + } + return result; + } + + public Character[] boxed(char[] arr) { + Character[] result = new Character[arr.length]; + for (int i = 0; i < arr.length; i++) { + result[i] = /* using auto boxing */ arr[i]; // Compliant + } + return result; + } + + public char[] unboxed(Character[] arr) { + char[] result = new char[arr.length]; + for (int i = 0; i < arr.length; i++) { + result[i] = /* using auto unboxing */ arr[i]; // Compliant + } + return result; + } + + int x; + + void f() throws InterruptedException { + int i = 0, from = 0, to = 0; + char c = 0; + byte b = 0; + Integer[] src = new Integer[] {1, 2, 3, 4, 5}; + Integer[] dst = new Integer[src.length]; + List list = new ArrayList<>(); + + for (int j = 0; j < src.length; ++j) { + dst[j] = src[j]; // Noncompliant {{Use "Arrays.copyOf", "Arrays.asList", "Collections.addAll" or "System.arraycopy" instead.}} + } + + for (int j = 0; j < src.length; ++j) { + list.add(src[j]); // Noncompliant + } + + while (i < src.length) { + dst[i] = src[i]; // Noncompliant + ++i; + } + + while (i < src.length) { + list.add(src[i]); // Noncompliant + ++i; + } + + for (Integer n : src) { + list.add(n); // Noncompliant + } + + for (Integer n : src) + list.add(n); // Noncompliant + + for (Integer n : new Integer[]{1, 2, 3, 4, 5}) { + list.add(n); // Noncompliant + } + + for (; from < to; ++from) { + dst[from] = src[from]; // Noncompliant + } + + for (; from < to; ++from) { + list.add(src[from]); // Noncompliant + } + + while (from < to) { + list.add(src[from]); // Noncompliant + ++from; + } + + for (int j = 0; j < 5; ++j) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; j < 5 + 3; ++j) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; j < src.length; j++) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; j < src.length; j += 1) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; j < src.length; j = j + 1) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; j < src.length; j = 1 + j) { + dst[j] = src[j]; // Noncompliant + } + + while (i < src.length) { + list.add(src[i]); // Noncompliant + i++; + } + + while (i < src.length) { + list.add(src[i]); // Noncompliant + i += 1; + } + + while (i < src.length) { + list.add(src[i]); // Noncompliant + i = i + 1; + } + + while (i < src.length) { + list.add(src[i]); // Noncompliant + i = 1 + i; + } + + do { + dst[i] = src[i]; // Noncompliant + i++; + } while (i < src.length); + + do { + list.add(src[i]); // Noncompliant + i++; + } while (i < src.length); + + do { + list.add(src[i]); // Noncompliant + i += 1; + } while (i < src.length); + + do { + list.add(src[i]); // Noncompliant + i = i + 1; + } while (i < src.length); + + do { + list.add(src[i]); // Noncompliant + i = 1 + i; + } while (i < src.length); + + for (int j = 0; j != src.length; ++j) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; j <= src.length - 1; ++j) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; src.length > j; ++j) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; src.length - 1 >= j; ++j) { + dst[j] = src[j]; // Noncompliant + } + + for (;;) break; + + for (int j = 0; j < src.length; ++j); + + for (int j = 0; j < src.length; ++j) {} + + for (int j = 0; j < src.length; ++j) { + System.out.println(src[i]); + } + + for (int j = 0, k = 0; src.length - j != 0; ++j, ++k) { + dst[j] = src[k]; + } + + for (int j = 0, k = 0; i < src.length; ++j, ++k) { + dst[j] = src[k]; + } + + for (int j = 0; j < src.length;) { + dst[j] = src[j]; + ++j; + } + + for (int j = src.length - 1; j >= 0; j = j - 1) { + dst[j] = src[j]; + } + + for (int j = 0; j < src.length; ++c) { + dst[j] = src[j]; + } + + for (int j = 0; j < src.length; c += 1) { + dst[j] = src[j]; + } + + for (int j = 0; j < src.length; c = (char)(c + 1)) { + dst[j] = src[j]; + } + + for (int j = 0; j < src.length; j = j + one()) { + dst[j] = src[j]; + } + + for (int j = 0; j < src.length; j = one() + j) { + dst[j] = src[j]; + } + + for (int j = 0; j < src.length; ++j) { + array()[i] = src[j]; + } + + for (int j = 0; j < src.length; ++j) { + dst[j] = array()[i]; + } + + for (int j = 0; j < src.length; ++j) { + list().add(src[j]); + } + + for (int j = 0; j < src.length; ++j) { + list.add(array()[j]); + } + + for (int j = 0; src.length - j != 0; ++j) { + dst[j] = src[j]; + } + + for (int j = 0; j < src.length; ++j) { + dst[j] = j; + } + + for (int j = 0; j < src.length; ++j) { + i = src[j]; + } + + for (int j = 0; j < src.length; ++j) { + i = j; + } + + for (int n : new ArrayList()) { + list.add(n); + } + + for (int j = 0; j < src.length; ++j) { + dst.wait(src[j]); + } + + for (int j = 0; j < src.length; ++j) { + list.add(j); + } + + for (int j = 0; j < src.length; ++j) { + ; + } + + for (int j = 0; j < src.length; ++j) { + list(); + } + + for (int j = 0; j < src.length; j = j + 2) { + dst[j] = src[j]; + } + + for (int j = 0; j < src.length; j = 2 + j) { + dst[j] = src[j]; + } + + for (int j = 0; j < src.length; j = i + 2) { + dst[j] = src[j]; + } + + for (int j = 0; j < src.length; j = 2 + i) { + dst[j] = src[j]; + } + + i = 0; + for (int n : src) { + dst[i++] = n; + } + + for (int j = 0; j < src.length; j += 2) { + dst[j] = src[j]; + } + + for (int j = 0; j < j; ++j) { + dst[j] = src[j]; + } + + for (this.x = 0; this.x < src.length; this.x += 1) { + dst[this.x] = src[this.x]; + } + + for (this.x = 0; this.x < src.length; ++this.x) { + dst[this.x] = src[this.x]; + } + + for (int j = 0; j < src.length; ++j) { + add(src[j]); + } + + while (i < src.length) { + list.add(src[i++]); + } + + while (i < src.length) + list.add(src[i++]); + + while (i < src.length) { + list.add(array()[i]); + ++i; + } + + while (i < src.length) { + list().add(src[i]); + ++i; + } + + while (i < src.length) { + list.contains(src[i]); + ++i; + } + + i = -1; + while (i < src.length - 1) { + ++i; + list.add(src[i]); + } + + while (i < src.length) { + list.add(src[i++]); + System.out.println(i); + } + + while (c < b) { + list.add(src[from]); + ++from; + } + + while (from < from) { + list.add(src[from]); + ++from; + } + + while (from < to) { + list.add(src[from++]); + } + + while (to - from != 0) { + list.add(src[from]); + ++from; + } + + while (from < to) { + list.add(src[from++]); + ; + } + + for (int n : src) { + list.contains(n); + } + + for (int n : src) { + list.add(n); + ; + } + + for (int n : src) { + list(); + } + + for (int n : src) { + dst.hashCode(); + } + + for (int n : src) { + list.add(i); + } + + for (int n : src) { + list.add(1); + } + + for (int n : src); + + for (int n : src) { + add(n); + } + + for (int n : src) { + list().add(n); + } + + for (int j = 0; !false; ++j) { + dst[j] = src[j]; + } + } + + void arraysOfPrimitives() { + int i = 0, from = 0, to = 0; + char c = 0; + byte b = 0; + int[] src = new int[]{1, 2, 3, 4, 5}; + int[] dst = new int[src.length]; + List list = new ArrayList<>(); + + for (int j = 0; j < src.length; ++j) { + dst[j] = src[j]; // Noncompliant {{Use "Arrays.copyOf", "Arrays.asList", "Collections.addAll" or "System.arraycopy" instead.}} + } + + for (int j = 0; j < src.length; ++j) { + list.add(src[j]); // Compliant, no helper can copy an array of primitive into a collection + // Collections.addAll(list, src); does not compile + // Arrays.asList(src) will return a List + } + + do { + dst[i] = src[i]; // Noncompliant + ++i; + } while (i < src.length); + + while (i < src.length) { + dst[i] = src[i]; // Noncompliant + ++i; + } + + while (i < src.length) { + list.add(src[i]); // Compliant, no helper can copy an array of primitive into a collection + ++i; + } + + for (int n : src) { + list.add(n); // Compliant, no helper can copy an array of primitive into a collection + } + + for (int n : src) + list.add(n); // Compliant, no helper can copy an array of primitive into a collection + + for (int n : new int[]{1, 2, 3, 4, 5}) { + list.add(n); // Compliant, no helper can copy an array of primitive into a collection + } + + for (int n : new Integer[]{1, 2, 3, 4, 5}) { + list.add(n); // Compliant, acceptable FN to avoid noise + } + + for (; from < to; ++from) { + dst[from] = src[from]; // Noncompliant + } + + for (; from < to; ++from) { + list.add(src[from]); // Compliant, no helper can copy an array of primitive into a collection + } + + while (from < to) { + list.add(src[from]); // Compliant, no helper can copy an array of primitive into a collection + ++from; + } + + for (int j = 0; j < 5; ++j) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; j < 5 + 3; ++j) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; j < src.length; j++) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; j < src.length; j += 1) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; j < src.length; j = j + 1) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; j < src.length; j = 1 + j) { + dst[j] = src[j]; // Noncompliant + } + + while (i < src.length) { + list.add(src[i]); // Compliant, no helper can copy an array of primitive into a collection + i++; + } + + while (i < src.length) { + list.add(src[i]); // Compliant, no helper can copy an array of primitive into a collection + i += 1; + } + + while (i < src.length) { + list.add(src[i]); // Compliant, no helper can copy an array of primitive into a collection + i = i + 1; + } + + while (i < src.length) { + list.add(src[i]); // Compliant, no helper can copy an array of primitive into a collection + i = 1 + i; + } + + for (int j = 0; j != src.length; ++j) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; j <= src.length - 1; ++j) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; src.length > j; ++j) { + dst[j] = src[j]; // Noncompliant + } + + for (int j = 0; src.length - 1 >= j; ++j) { + dst[j] = src[j]; // Noncompliant + } + } + + public void copy(Collection target, int[] source) { + for (int s : source) { + target.add(s); // FP: S3012. Collection.addAll does not accept int[] as an argument. + } + } + + private static void copyToSet(long[] array, Set set) { + for (long labelId : array) { + set.add(labelId); // Compliant + } + } + + private static void copyToNonCollection(int[] array) { + class NonCollection { + void add(Integer i) {} + } + + NonCollection nonCollection = new NonCollection(); + for (Integer i : array) { + nonCollection.add(i); // Compliant + } + } + + List list() { + return new ArrayList<>(); + } + + int[] array() { + return new int[]{}; + } + + int one() { + return 1; + } + + @Override + public boolean add(Integer n) { + return true; + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ArrayCopyLoopCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ArrayCopyLoopCheckSample.textproto.gz new file mode 100644 index 00000000000..dc990574347 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ArrayCopyLoopCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/BooleanLiteralCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/BooleanLiteralCheckSample.expected.txt.gz new file mode 100644 index 00000000000..0741f72167a Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/BooleanLiteralCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/BooleanLiteralCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/BooleanLiteralCheckSample.java new file mode 100644 index 00000000000..92d6dfb9868 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/BooleanLiteralCheckSample.java @@ -0,0 +1,319 @@ +package checks; + +class BooleanLiteralCheckSample { + + public void f(boolean var, boolean foo) { + boolean[] tests = { + var == false, // Noncompliant {{Remove the unnecessary boolean literal.}} +// ^^^^^ + var == true, // Noncompliant {{Remove the unnecessary boolean literal.}} + var != false, // Noncompliant + var != true, // Noncompliant + false == var, // Noncompliant + true == var, // Noncompliant + false != var, // Noncompliant + true != var, // Noncompliant + !true, // Noncompliant [[quickfixes=qf_negation_true]] +// ^^^^ + // fix@qf_negation_true {{Simplify the expression}} + // edit@qf_negation_true [[sc=5;ec=10]] {{false}} + !false, // Noncompliant [[quickfixes=qf_negation_false]] +// ^^^^^ + // fix@qf_negation_false {{Simplify the expression}} + // edit@qf_negation_false [[sc=5;ec=11]] {{true}} + false && foo(), // Noncompliant + foo() || true, // Noncompliant + true || false, // Noncompliant {{Remove the unnecessary boolean literals.}} +// ^^^^ ^^^^^< + + var == foo(true), // Compliant + !foo, // Compliant + foo() && bar() // Compliant + }; + + boolean exp = foo(); + var = foo() ? true : // Noncompliant {{Remove the unnecessary boolean literals.}} [[quickfixes=qf_cond1]] +// ^^^^ + false; +// ^^^^^< + // fix@qf_cond1 {{Simplify the expression}} + // edit@qf_cond1 [[sc=16;el=+2;ec=12]] {{}} + var = foo() ? false : true; // Noncompliant [[quickfixes=qf_cond2]] +// ^^^^^ + // fix@qf_cond2 {{Simplify the expression}} + // edit@qf_cond2 [[sc=16;ec=31]] {{}} + // edit@qf_cond2 [[sc=11;ec=11]] {{!}} + var = foo() ? true : exp; // Noncompliant [[quickfixes=qf_cond3]] +// ^^^^ + // fix@qf_cond3 {{Simplify the expression}} + // edit@qf_cond3 [[sc=17;ec=25]] {{||}} + var = foo() ? false : exp; // Noncompliant [[quickfixes=qf_cond4]] +// ^^^^^ + // fix@qf_cond4 {{Simplify the expression}} + // edit@qf_cond4 [[sc=17;ec=26]] {{&&}} + // edit@qf_cond4 [[sc=11;ec=11]] {{!}} + var = foo() ? exp : true; // Noncompliant [[quickfixes=qf_cond5]] +// ^^^^ + // fix@qf_cond5 {{Simplify the expression}} + // edit@qf_cond5 [[sc=22;ec=29]] {{}} + // edit@qf_cond5 [[sc=11;ec=11]] {{!}} + // edit@qf_cond5 [[sc=17;ec=18]] {{||}} + var = foo() ? exp : false; // Noncompliant [[quickfixes=qf_cond6]] +// ^^^^^ + // fix@qf_cond6 {{Simplify the expression}} + // edit@qf_cond6 [[sc=22;ec=30]] {{}} + // edit@qf_cond6 [[sc=17;ec=18]] {{&&}} + + // The following are reported but we do not suggest a quick fix as it looks more like a bug (see S3923) + var = foo() ? true : true; // Noncompliant [[quickfixes=!]] +// ^^^^ + var = foo() ? false : false; // Noncompliant [[quickfixes=!]] +// ^^^^^ + + Boolean b1 = foo() ? true : null; // Compliant + Boolean b2 = foo() ? exp : null; // Compliant + Boolean b3 = foo() ? null : false; // Compliant + Boolean b4 = foo() ? null : exp; // Compliant + + var = foo(); + var = foo() || exp; + var = !foo() && exp; + var = !foo() || exp; + var = foo() && exp; + } + + void quickFixForEquality(boolean var) { + boolean b; + b = var == false; // Noncompliant [[quickfixes=qf_equal1]] +// ^^^^^ + // fix@qf_equal1 {{Simplify the expression}} + // edit@qf_equal1 [[sc=9;ec=9]] {{!}} + // edit@qf_equal1 [[sc=12;ec=21]] {{}} + b = var == true; // Noncompliant [[quickfixes=qf_equal2]] +// ^^^^ + // fix@qf_equal2 {{Simplify the expression}} + // edit@qf_equal2 [[sc=12;ec=20]] {{}} + b = var != false; // Noncompliant [[quickfixes=qf_equal3]] +// ^^^^^ + // fix@qf_equal3 {{Simplify the expression}} + // edit@qf_equal3 [[sc=12;ec=21]] {{}} + b = var != true; // Noncompliant [[quickfixes=qf_equal4]] +// ^^^^ + // fix@qf_equal4 {{Simplify the expression}} + // edit@qf_equal4 [[sc=9;ec=9]] {{!}} + // edit@qf_equal4 [[sc=12;ec=20]] {{}} + + b = false == var; // Noncompliant [[quickfixes=qf_equal5]] +// ^^^^^ + // fix@qf_equal5 {{Simplify the expression}} + // edit@qf_equal5 [[sc=9;ec=18]] {{!}} + b = true == var; // Noncompliant [[quickfixes=qf_equal6]] +// ^^^^ + // fix@qf_equal6 {{Simplify the expression}} + // edit@qf_equal6 [[sc=9;ec=17]] {{}} + b = false != var; // Noncompliant [[quickfixes=qf_equal7]] +// ^^^^^ + // fix@qf_equal7 {{Simplify the expression}} + // edit@qf_equal7 [[sc=9;ec=18]] {{}} + b = true != var; // Noncompliant [[quickfixes=qf_equal8]] +// ^^^^ + // fix@qf_equal8 {{Simplify the expression}} + // edit@qf_equal8 [[sc=9;ec=17]] {{!}} + + b = true == true; // Noncompliant [[quickfixes=qf_equal9]] +// ^^^^ + // fix@qf_equal9 {{Simplify the expression}} + // edit@qf_equal9 [[sc=9;ec=21]] {{true}} + b = false == false; // Noncompliant [[quickfixes=qf_equal10]] +// ^^^^^ + // fix@qf_equal10 {{Simplify the expression}} + // edit@qf_equal10 [[sc=9;ec=23]] {{true}} + b = false == true; // Noncompliant [[quickfixes=qf_equal11]] +// ^^^^^ + // fix@qf_equal11 {{Simplify the expression}} + // edit@qf_equal11 [[sc=9;ec=22]] {{false}} + b = true == false; // Noncompliant [[quickfixes=qf_equal12]] +// ^^^^ + // fix@qf_equal12 {{Simplify the expression}} + // edit@qf_equal12 [[sc=9;ec=22]] {{false}} + + b = true != true; // Noncompliant [[quickfixes=qf_equal13]] +// ^^^^ + // fix@qf_equal13 {{Simplify the expression}} + // edit@qf_equal13 [[sc=9;ec=21]] {{false}} + b = false != false; // Noncompliant [[quickfixes=qf_equal14]] +// ^^^^^ + // fix@qf_equal14 {{Simplify the expression}} + // edit@qf_equal14 [[sc=9;ec=23]] {{false}} + b = false != true; // Noncompliant [[quickfixes=qf_equal15]] +// ^^^^^ + // fix@qf_equal15 {{Simplify the expression}} + // edit@qf_equal15 [[sc=9;ec=22]] {{true}} + b = true != false; // Noncompliant [[quickfixes=qf_equal16]] +// ^^^^ + // fix@qf_equal16 {{Simplify the expression}} + // edit@qf_equal16 [[sc=9;ec=22]] {{true}} + } + + void quickFixForAndAndOr(boolean var, boolean var2) { + boolean b; + b = f() || false; // Noncompliant [[quickfixes=qf_and_or1]] +// ^^^^^ + // fix@qf_and_or1 {{Simplify the expression}} + // edit@qf_and_or1 [[sc=12;ec=21]] {{}} + b = f() && true; // Noncompliant [[quickfixes=qf_and_or2]] +// ^^^^ + // fix@qf_and_or2 {{Simplify the expression}} + // edit@qf_and_or2 [[sc=12;ec=20]] {{}} + + // When the expression can have side effects, it is not always possible to simply fix the issue. + // We are not suggesting a quick fix when it would require to extract the side effects. + b = f() || true; // Noncompliant [[quickfixes=!]] +// ^^^^ + b = f() && false; // Noncompliant [[quickfixes=!]] +// ^^^^^ + // However, the same expression without side effect can be replaced safely + b = var || true; // Noncompliant [[quickfixes=qf_and_or3]] +// ^^^^ + // fix@qf_and_or3 {{Simplify the expression}} + // edit@qf_and_or3 [[sc=9;ec=16]] {{}} + b = var && false; // Noncompliant [[quickfixes=qf_and_or4]] +// ^^^^^ + // fix@qf_and_or4 {{Simplify the expression}} + // edit@qf_and_or4 [[sc=9;ec=16]] {{}} + + b = true || f(); // Noncompliant [[quickfixes=qf_and_or5]] +// ^^^^ + // fix@qf_and_or5 {{Simplify the expression}} + // edit@qf_and_or5 [[sc=13;ec=20]] {{}} + b = false || f(); // Noncompliant [[quickfixes=qf_and_or6]] +// ^^^^^ + // fix@qf_and_or6 {{Simplify the expression}} + // edit@qf_and_or6 [[sc=9;ec=18]] {{}} + b = true && f(); // Noncompliant [[quickfixes=qf_and_or7]] +// ^^^^ + // fix@qf_and_or7 {{Simplify the expression}} + // edit@qf_and_or7 [[sc=9;ec=17]] {{}} + b = false && f(); // Noncompliant [[quickfixes=qf_and_or8]] +// ^^^^^ + // fix@qf_and_or8 {{Simplify the expression}} + // edit@qf_and_or8 [[sc=14;ec=21]] {{}} + + b = true || true; // Noncompliant [[quickfixes=qf_and_or9]] +// ^^^^ + // fix@qf_and_or9 {{Simplify the expression}} + // edit@qf_and_or9 [[sc=9;ec=21]] {{true}} + b = false || true; // Noncompliant [[quickfixes=qf_and_or10]] +// ^^^^^ + // fix@qf_and_or10 {{Simplify the expression}} + // edit@qf_and_or10 [[sc=9;ec=22]] {{true}} + b = true || false; // Noncompliant [[quickfixes=qf_and_or11]] +// ^^^^ + // fix@qf_and_or11 {{Simplify the expression}} + // edit@qf_and_or11 [[sc=9;ec=22]] {{true}} + b = false || false; // Noncompliant [[quickfixes=qf_and_or12]] +// ^^^^^ + // fix@qf_and_or12 {{Simplify the expression}} + // edit@qf_and_or12 [[sc=9;ec=23]] {{false}} + + b = true && true; // Noncompliant [[quickfixes=qf_and_or13]] +// ^^^^ + // fix@qf_and_or13 {{Simplify the expression}} + // edit@qf_and_or13 [[sc=9;ec=21]] {{true}} + b = false && true; // Noncompliant [[quickfixes=qf_and_or14]] +// ^^^^^ + // fix@qf_and_or14 {{Simplify the expression}} + // edit@qf_and_or14 [[sc=9;ec=22]] {{false}} + b = true && false; // Noncompliant [[quickfixes=qf_and_or15]] +// ^^^^ + // fix@qf_and_or15 {{Simplify the expression}} + // edit@qf_and_or15 [[sc=9;ec=22]] {{false}} + b = false && false; // Noncompliant [[quickfixes=qf_and_or16]] +// ^^^^^ + // fix@qf_and_or16 {{Simplify the expression}} + // edit@qf_and_or16 [[sc=9;ec=23]] {{false}} + + // Side effect can be nested into a more complex expression + b = (b ? var : bar()) || true; // Noncompliant [[quickfixes=!]] +// ^^^^ + b = (b ? var : var2) || true; // Noncompliant [[quickfixes=qf_side_effect]] +// ^^^^ + // fix@qf_side_effect {{Simplify the expression}} + // edit@qf_side_effect [[sc=9;ec=29]] {{}} + + } + + boolean isNotNull(Object s, boolean exp) { + boolean result; + result = s == null ? false : exp; // Noncompliant [[quickfixes=qf_proper_fix]] +// ^^^^^ + // result = s != null && exp; + // fix@qf_proper_fix {{Simplify the expression}} + // edit@qf_proper_fix [[sc=24;ec=33]]{{&&}} + // edit@qf_proper_fix [[sc=16;ec=18]]{{!=}} + return result; + } + + boolean externalConditionisFalse(boolean externalCondition, boolean exp) { + boolean result; + result = externalCondition ? false : exp; // Noncompliant [[quickfixes=regular_fix]] +// ^^^^^ + // result = !externalCondition && exp; + // fix@regular_fix {{Simplify the expression}} + // edit@regular_fix [[sc=32;ec=41]]{{&&}} + // edit@regular_fix [[sc=14;ec=14]]{{!}} + return result; + } + + boolean doesNotStartWithA(String s, boolean exp) { + return (s != null) && s.startsWith("a") ? false : exp; // Noncompliant [[quickfixes=complex_fix]] +// ^^^^^ + // return ((s == null) || !s.startsWith("a")) && exp; + // fix@complex_fix {{Simplify the expression}} + // edit@complex_fix [[sc=45;ec=54]]{{&&}} + // edit@complex_fix [[sc=44;ec=44]]{{)}} + // edit@complex_fix [[sc=27;ec=27]]{{!}} + // edit@complex_fix [[sc=24;ec=26]]{{||}} + // edit@complex_fix [[sc=15;ec=17]]{{==}} + // edit@complex_fix [[sc=12;ec=12]]{{(}} + } + + boolean isNotADuck(String s, boolean exp) { + return s != null && s.startsWith("d") && s.endsWith("uck") ? false : exp; // Noncompliant [[quickfixes=duck_fix]] +// ^^^^^ + // return (s == null || !s.startsWith("d") || !s.endsWith("uck")) && exp; + // fix@duck_fix {{Simplify the expression}} + // edit@duck_fix [[sc=64;ec=73]]{{&&}} + // edit@duck_fix [[sc=63;ec=63]]{{)}} + // edit@duck_fix [[sc=46;ec=46]]{{!}} + // edit@duck_fix [[sc=43;ec=45]]{{||}} + // edit@duck_fix [[sc=25;ec=25]]{{!}} + // edit@duck_fix [[sc=22;ec=24]]{{||}} + // edit@duck_fix [[sc=14;ec=16]]{{==}} + // edit@duck_fix [[sc=12;ec=12]]{{(}} + } + + boolean isADuck(String s, boolean exp) { + return !isNotADuck(s, exp); + } + + boolean doesNotHaveWings(String s, boolean isMammal, boolean exp) { + return isADuck(s, exp) || (isMammal && s != null && s.equals("bat")) ? false : exp; // Noncompliant [[quickfixes=wings_qf]] +// ^^^^^ + // return !isADuck(s, exp) && (!isMammal || s == null || !s.equals("bat")) && exp; + // fix@wings_qf {{Simplify the expression}} + // edit@wings_qf [[sc=74;ec=83]]{{&&}} + // edit@wings_qf [[sc=57;ec=57]]{{!}} + // edit@wings_qf [[sc=54;ec=56]]{{||}} + // edit@wings_qf [[sc=46;ec=48]]{{==}} + // edit@wings_qf [[sc=41;ec=43]]{{||}} + // edit@wings_qf [[sc=32;ec=32]]{{!}} + // edit@wings_qf [[sc=28;ec=30]]{{&&}} + // edit@wings_qf [[sc=12;ec=12]]{{!}} + } + + boolean foo() { return true; } + boolean foo(boolean b) { return b; } + boolean bar() { return true; } + boolean f() { return true; } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/BooleanLiteralCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/BooleanLiteralCheckSample.textproto.gz new file mode 100644 index 00000000000..b9958e51248 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/BooleanLiteralCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ConstructorsShouldNotAccessUninitializedValuesCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ConstructorsShouldNotAccessUninitializedValuesCheckSample.expected.txt.gz new file mode 100644 index 00000000000..ce32d48bf57 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ConstructorsShouldNotAccessUninitializedValuesCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ConstructorsShouldNotAccessUninitializedValuesCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ConstructorsShouldNotAccessUninitializedValuesCheckSample.java new file mode 100644 index 00000000000..9094b8ea75e --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ConstructorsShouldNotAccessUninitializedValuesCheckSample.java @@ -0,0 +1,290 @@ +package checks; + +import java.util.List; +import java.util.Locale; +import java.util.Objects; +import java.util.function.Supplier; + +public class ConstructorsShouldNotAccessUninitializedValuesCheckSample { + + record SimpleUser(String name) { + SimpleUser { + if (name().isBlank()) { // Noncompliant {{Replace this call to "name()" with the "name" parameter; the field is not assigned yet.}} +// ^^^^ + throw new IllegalArgumentException(); + } + } + } + + record ThisAccess(String name) { + ThisAccess { + if (this.name().isBlank()) { // Noncompliant {{Replace this call to "name()" with the "name" parameter; the field is not assigned yet.}} +// ^^^^ + throw new IllegalArgumentException(); + } + } + } + + record QualifiedThisAccess(String name) { + QualifiedThisAccess { + if (QualifiedThisAccess.this.name().isBlank()) { // Noncompliant {{Replace this call to "name()" with the "name" parameter; the field is not assigned yet.}} +// ^^^^ + throw new IllegalArgumentException(); + } + } + } + + record MultipleComponents(String first, String last, int age) { + MultipleComponents { + if (first().isEmpty()) { // Noncompliant {{Replace this call to "first()" with the "first" parameter; the field is not assigned yet.}} +// ^^^^^ + throw new IllegalArgumentException(); + } + if (this.last().isEmpty()) { // Noncompliant {{Replace this call to "last()" with the "last" parameter; the field is not assigned yet.}} +// ^^^^ + throw new IllegalArgumentException(); + } + if (age() < 0) { // Noncompliant {{Replace this call to "age()" with the "age" parameter; the field is not assigned yet.}} +// ^^^ + throw new IllegalArgumentException(); + } + } + } + + record CompliantDirectAccess(String name, int age) { + CompliantDirectAccess { + if (name.isBlank() || age < 0) { // Compliant + throw new IllegalArgumentException(); + } + } + } + + record ExplicitAccessor(List items) { + ExplicitAccessor { + if (items().isEmpty()) { // Noncompliant {{Replace this call to "items()" with the "items" parameter; the field is not assigned yet.}} +// ^^^^^ + throw new IllegalArgumentException(); + } + } + + @Override + public List items() { + return List.copyOf(items); + } + } + + record CanonicalConstructor(String name) { + CanonicalConstructor(String name) { + if (name().isBlank()) { // Noncompliant {{Replace this call to "name()" with the "name" parameter; the field is not assigned yet.}} +// ^^^^ + throw new IllegalArgumentException(); + } + this.name = name; + if (name().isBlank()) { // Compliant, the field is assigned + throw new IllegalArgumentException(); + } + } + } + + record CanonicalMultipleComponents(String name, int age) { + CanonicalMultipleComponents(String name, int age) { + this.name = name.toLowerCase(Locale.ROOT); + if (name().isBlank() || age() < 0) { // Noncompliant {{Replace this call to "age()" with the "age" parameter; the field is not assigned yet.}} +// ^^^ + throw new IllegalArgumentException(); + } + this.age = age; + if (age() > 150) { // Compliant + throw new IllegalArgumentException(); + } + } + } + + record CanonicalAccessorInAssignment(String name) { + CanonicalAccessorInAssignment(String name) { + this.name = name().trim(); // Noncompliant {{Replace this call to "name()" with the "name" parameter; the field is not assigned yet.}} +// ^^^^ + } + } + + record CanonicalParenthesizedAssignment(String name) { + CanonicalParenthesizedAssignment(String name) { + (this).name = name; + if (name().isBlank()) { // Compliant + throw new IllegalArgumentException(); + } + } + } + + record CanonicalBranches(String name) { + CanonicalBranches(String name) { + if (name == null) { + this.name = ""; + } else { + this.name = name.trim(); + } + if (name().isEmpty()) { // Compliant + throw new IllegalArgumentException(); + } + } + } + + static class Holder { + String value; + } + + record CanonicalOtherAssignments(String name) { + CanonicalOtherAssignments(String name) { + String trimmed; + trimmed = name.trim(); + Holder holder = new Holder(); + holder.value = trimmed; + if (name().isEmpty()) { // Noncompliant {{Replace this call to "name()" with the "name" parameter; the field is not assigned yet.}} +// ^^^^ + throw new IllegalArgumentException(); + } + this.name = trimmed; + } + } + + record CanonicalLocalClassAssignment(String name) { + CanonicalLocalClassAssignment(String name) { + class Temporary { + String name; + + Temporary() { + this.name = "temporary"; + } + } + Runnable lambda = () -> new Temporary(); + if (name().isEmpty()) { // Noncompliant {{Replace this call to "name()" with the "name" parameter; the field is not assigned yet.}} +// ^^^^ + throw new IllegalArgumentException(); + } + this.name = name; + } + } + + record FlexibleConstructorBody(String name) { + FlexibleConstructorBody(String name, int ignored) { + Objects.requireNonNull(name); + this(name); + if (name().isBlank()) { // Compliant, the canonical constructor already ran + throw new IllegalArgumentException(); + } + } + } + + record GenericRecord(T value) { + GenericRecord { + if (value() == null) { // Noncompliant {{Replace this call to "value()" with the "value" parameter; the field is not assigned yet.}} +// ^^^^^ + throw new IllegalArgumentException(); + } + } + } + + record CanonicalBranchAssignment(String name) { + CanonicalBranchAssignment(String name) { + if (name == null) { + this.name = ""; + } else { + String copy = name(); // FN, the textually first assignment of "name" is in the other branch + this.name = name.trim(); + } + } + } + + record DelegatingConstructor(String name) { + DelegatingConstructor(String name, boolean flag) { + this(name); + if (name().isBlank()) { // Compliant, the canonical constructor already ran + throw new IllegalArgumentException(); + } + } + } + + record OtherMethodCall(String name) { + OtherMethodCall { + helper(); // Compliant + validate(name); // Compliant + name("suffix"); // Compliant, not the accessor + } + + void helper() { + } + + String name(String suffix) { + return name + suffix; + } + + static void validate(String s) { + } + } + + record AccessOnOtherInstance(String name) { + AccessOnOtherInstance { + AccessOnOtherInstance other = new AccessOnOtherInstance("other"); + if (other.name().isBlank()) { // Compliant + throw new IllegalArgumentException(); + } + } + } + + record OuterRecord(String outerName) { + OuterRecord { + if (outerName().isBlank()) { // Noncompliant {{Replace this call to "outerName()" with the "outerName" parameter; the field is not assigned yet.}} +// ^^^^^^^^^ + throw new IllegalArgumentException(); + } + } + + record InnerRecord(String innerName) { + InnerRecord { + if (innerName().isBlank()) { // Noncompliant {{Replace this call to "innerName()" with the "innerName" parameter; the field is not assigned yet.}} +// ^^^^^^^^^ + throw new IllegalArgumentException(); + } + } + } + } + + record DeferredCalls(String name) { + DeferredCalls { + class LocalClass { + void localMethod() { + name(); // Compliant + } + } + Runnable lambda = () -> name(); // Compliant + Object anonymous = new Object() { + String value() { + return name(); // Compliant + } + }; + Supplier reference = this::name; // Compliant + } + } + + record WithCastAndParens(String name) { + WithCastAndParens { + if (((WithCastAndParens) (this)).name().isBlank()) { // Noncompliant {{Replace this call to "name()" with the "name" parameter; the field is not assigned yet.}} +// ^^^^ + throw new IllegalArgumentException(); + } + } + } + + record InNewClassArgument(String name) { + InNewClassArgument { + throw new IllegalArgumentException("bad name: " + name()); // Noncompliant {{Replace this call to "name()" with the "name" parameter; the field is not assigned yet.}} +// ^^^^ + } + } + + record NoComponents() { + NoComponents { + // Compliant + } + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ConstructorsShouldNotAccessUninitializedValuesCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ConstructorsShouldNotAccessUninitializedValuesCheckSample.textproto.gz new file mode 100644 index 00000000000..1c78e49b7cb Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ConstructorsShouldNotAccessUninitializedValuesCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/CopyConstructorMissesFieldCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/CopyConstructorMissesFieldCheckSample.expected.txt.gz new file mode 100644 index 00000000000..7e3f927295d Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/CopyConstructorMissesFieldCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/CopyConstructorMissesFieldCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/CopyConstructorMissesFieldCheckSample.java new file mode 100644 index 00000000000..cd951db520b --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/CopyConstructorMissesFieldCheckSample.java @@ -0,0 +1,386 @@ +package checks; + +class CopyConstructorMissesFieldCheckSample { + + static class Basic { + private static int instances; + private transient Object cache; + private Object initialized = new Object(); + private final String name; + private String note; + private int retries; + private boolean enabled; + + Basic(Basic other) { // Noncompliant {{This copy constructor leaves eligible fields uninitialized; initialize them explicitly to distinguish omissions from intentional resets.}} [[secondary=10,11,12]] + name = other.name; + } + } + + static class ExplicitDefaults { + private String text; + private int number; + private boolean flag; + + ExplicitDefaults(ExplicitDefaults other) { + this.text = null; + number = 0; + this.flag = false; + } + } + + static class ConstructorsThatAreNotCopies { + private String value; + + ConstructorsThatAreNotCopies() { + } + + ConstructorsThatAreNotCopies(String value) { + } + + ConstructorsThatAreNotCopies(ConstructorsThatAreNotCopies other, int ignored) { + } + } + + static class Generic { + private T first; + private T second; + + Generic(Generic other) { // Noncompliant [[secondary=46]] + first = other.first; + } + } + + static class ForeignAssignments { + private int value; + + ForeignAssignments(ForeignAssignments other) { // Noncompliant [[secondary=54]] + other.value = 1; + } + } + + static class ShadowedField { + private int value; + + ShadowedField(ShadowedField other) { // Noncompliant [[secondary=62]] + int value = other.value; + value = 1; + } + } + + static class CompoundAssignment { + private int value; + + CompoundAssignment(CompoundAssignment other) { + value += other.value; + } + } + + static class IncrementAndDecrement { + private int postfixIncrement, prefixIncrement, postfixDecrement, prefixDecrement; + + IncrementAndDecrement(IncrementAndDecrement other) { + postfixIncrement++; ++prefixIncrement; postfixDecrement--; --prefixDecrement; + } + } + + static class Delegation { + private String name; + private int count; + + Delegation(Delegation other) { + this(other.name, other.count); + } + + Delegation(String name, int count) { + this.name = name; + this.count = count; + } + } + + static class IncompleteDelegation { + private String name; + private int count; + + IncompleteDelegation(IncompleteDelegation other) { // Noncompliant [[secondary=102]] + this(other.name); + } + + IncompleteDelegation(String name) { + this.name = name; + } + } + + static class Helpers { + private String name; + private int count; + + Helpers(Helpers other) { + copyName(other); + this.copyCount(other); + } + + private void copyName(Helpers other) { + name = other.name; + } + + private void copyCount(Helpers other) { + finishCount(other); + } + + private void finishCount(Helpers other) { + count = other.count; + } + } + + static class IncompleteHelper { + private String name; + private int count; + + IncompleteHelper(IncompleteHelper other) { // Noncompliant [[secondary=137]] + setName(other); + } + + private void setName(IncompleteHelper other) { + name = other.name; + } + } + + static class CallsOnOtherDoNotCount { + private int value; + + CallsOnOtherDoNotCount(CallsOnOtherDoNotCount other) { // Noncompliant [[secondary=149]] + other.initialize(); + } + + private void initialize() { + value = 1; + } + } + + static class StaticHelperDoesNotCount { + private int value; + + StaticHelperDoesNotCount(StaticHelperDoesNotCount other) { // Noncompliant [[secondary=161]] + initialize(other); + } + + private static void initialize(StaticHelperDoesNotCount target) { + target.value = 1; + } + } + + static class ConditionalAssignment { + private int value; + + ConditionalAssignment(ConditionalAssignment other) { + if (other.value > 0) { + value = other.value; + } + } + } + + static class DeferredAssignments { + private int lambdaValue; + private int localClassValue; + private int anonymousClassValue; + + DeferredAssignments(DeferredAssignments other) { // Noncompliant [[secondary=183,184,185]] + Runnable lambda = () -> lambdaValue = other.lambdaValue; + class Local { + void set() { + localClassValue = other.localClassValue; + } + } + Runnable anonymous = new Runnable() { + @Override + public void run() { + anonymousClassValue = other.anonymousClassValue; + } + }; + } + } + + static class SelfTypedField { + private SelfTypedField parent; + private String label; + + SelfTypedField(SelfTypedField other) { // Noncompliant [[secondary=205]] + parent = other.parent; + } + } + + record Point(int x, int y) { + Point(Point other) { + this(other.x, other.y); + } + } + + static class MultipleCopyConstructors { + private int first; + private int second; + + MultipleCopyConstructors(MultipleCopyConstructors other) { // Noncompliant [[secondary=220]] + first = other.first; + } + + MultipleCopyConstructors(MultipleCopyConstructors other, boolean marker) { + second = other.second; + } + } + + static class ParenthesizedThis { + private int value; + + ParenthesizedThis(ParenthesizedThis other) { + (this).value = other.value; + } + } + + static class EligibilityExclusions { + private static int staticValue; + private transient int transientValue; + private int initializedValue = 1; + private final int initializedFinal = 2; + + EligibilityExclusions(EligibilityExclusions other) { + } + } + + static class DifferentTypeParameter { + private int value; + + DifferentTypeParameter(Basic other) { + } + } + + static class ParentType { + } + + static class ChildType extends ParentType { + private int value; + + ChildType(ParentType other) { + } + } + + static class RecursiveHelper { + private int value; + + RecursiveHelper(RecursiveHelper other) { + initialize(other); + } + + private void initialize(RecursiveHelper other) { + initialize(other); + } + } + + static class DelegationChain { + private String name; + private int value; + + DelegationChain(DelegationChain other) { + this(other.name); + } + + DelegationChain(String name) { + this(name, 0); + } + + DelegationChain(String name, int value) { + this.name = name; + this.value = value; + } + } + + static class QualifiedDirectAssignment { + private int value; + + QualifiedDirectAssignment(QualifiedDirectAssignment other) { + QualifiedDirectAssignment.this.value = other.value; + } + } + + static class QualifiedHelperCall { + private int value; + + QualifiedHelperCall(QualifiedHelperCall other) { + QualifiedHelperCall.this.initialize(other); + } + + private void initialize(QualifiedHelperCall other) { + value = other.value; + } + } + + static class InstanceInitializerAssignments { + private final int direct; + private int throughHelper; + + { + direct = 1; + initialize(); + } + + InstanceInitializerAssignments(InstanceInitializerAssignments other) { + } + + private void initialize() { + throughHelper = 1; + } + } + + static class GenericHelper { + private T value; + + GenericHelper(GenericHelper other) { + initialize(other); + } + + private void initialize(GenericHelper other) { + value = other.value; + } + } + + static class QualifiedOuterThis { + private int outerValue; + + class Inner { + private int innerValue; + + Inner(Inner other) { // Noncompliant [[secondary=349]] + QualifiedOuterThis.this.outerValue = other.innerValue; + } + } + } + + static class NestedReceiverIsNotThis { + private int value; + private NestedReceiverIsNotThis delegate = this; + + NestedReceiverIsNotThis(NestedReceiverIsNotThis other) { // Noncompliant [[secondary=358]] + other.delegate.value = 1; + } + } + + static class CastReceiver { + private int value; + + CastReceiver(CastReceiver other) { + ((CastReceiver) this).initialize(other); + } + + private void initialize(CastReceiver other) { + value = other.value; + } + } + + static class RejectedUnaryWrites { + private int value; + + RejectedUnaryWrites(RejectedUnaryWrites other) { // Noncompliant [[secondary=379]] + int ignored = -other.value; + other.value++; + } + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/CopyConstructorMissesFieldCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/CopyConstructorMissesFieldCheckSample.textproto.gz new file mode 100644 index 00000000000..c2b0017466c Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/CopyConstructorMissesFieldCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/DoubleCheckedLockingCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/DoubleCheckedLockingCheckSample.expected.txt.gz new file mode 100644 index 00000000000..ea3d54a85c3 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/DoubleCheckedLockingCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/DoubleCheckedLockingCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/DoubleCheckedLockingCheckSample.java new file mode 100644 index 00000000000..bd221c5aa6f --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/DoubleCheckedLockingCheckSample.java @@ -0,0 +1,312 @@ +package checks; +class DoubleCheckedLockingCheckSample { + private Helper helper = null; + + public Helper classicCase() { + if (helper == null) +// ^^^^^^^^^^^^^^> + synchronized (this) { // Noncompliant {{Remove this dangerous instance of double-checked locking.}} +// ^^^^^^^^^^^^ + if (helper == null) +// ^^^^^^^^^^^^^^< + helper = new Helper(); + } + return helper; + } + + public Helper classicCaseNegated() { + if (!(helper != null)) +// ^^^^^^^^^^^^^^^^^> + synchronized (this) { // Noncompliant {{Remove this dangerous instance of double-checked locking.}} +// ^^^^^^^^^^^^ + if (helper == null) +// ^^^^^^^^^^^^^^< + helper = new Helper(); + } + return helper; + } + + public Helper classicCaseInnerNegated() { + if (helper == null) +// ^^^^^^^^^^^^^^> + synchronized (this) { // Noncompliant {{Remove this dangerous instance of double-checked locking.}} +// ^^^^^^^^^^^^ + if (!(helper != null)) +// ^^^^^^^^^^^^^^^^^< + helper = new Helper(); + } + return helper; + } + + public Helper classicCaseRepeatedNegations() { + if (((!!(helper == null)))) +// ^^^^^^^^^^^^^^^^^^^^^^> + synchronized (this) { // Noncompliant {{Remove this dangerous instance of double-checked locking.}} +// ^^^^^^^^^^^^ + if (!(!(!(helper != null)))) +// ^^^^^^^^^^^^^^^^^^^^^^^< + helper = new Helper(); + } + return helper; + } + + public Helper fieldIsNotActuallyInitializedHere() { + if (helper == null) + synchronized (this) { // Compliant - field is not initialized in this method actually + if (helper == null) { + System.out.println("haha!"); // Nelson + } + } + return helper; + } + + public Helper memberSelectCondition() { + if (this.helper == null) +// ^^^^^^^^^^^^^^^^^^^> + synchronized (this) { // Noncompliant {{Remove this dangerous instance of double-checked locking.}} +// ^^^^^^^^^^^^ + if (helper == null) +// ^^^^^^^^^^^^^^< + this.helper = new Helper(); + } + return helper; + } + + public Helper memberSelectCondition2() { + if (helper == null) +// ^^^^^^^^^^^^^^> + synchronized (this) { // Noncompliant {{Remove this dangerous instance of double-checked locking.}} +// ^^^^^^^^^^^^ + if (this.helper == null) +// ^^^^^^^^^^^^^^^^^^^< + this.helper = new Helper(); + } + return helper; + } + + public Helper memberSelectCondition3() { + if (this.helper == null) +// ^^^^^^^^^^^^^^^^^^^> + synchronized (this) { // Noncompliant {{Remove this dangerous instance of double-checked locking.}} +// ^^^^^^^^^^^^ + if (this.helper == null) +// ^^^^^^^^^^^^^^^^^^^< + this.helper = new Helper(); + } + return helper; + } + + public Helper invertedConditions() { + if (null == this.helper) +// ^^^^^^^^^^^^^^^^^^^> + synchronized (this) { // Noncompliant {{Remove this dangerous instance of double-checked locking.}} +// ^^^^^^^^^^^^ + if (null == helper) +// ^^^^^^^^^^^^^^< + this.helper = new Helper(); + } + return helper; + } + + public Helper intializationViaMemberSelect2() { + if (helper == null) +// ^^^^^^^^^^^^^^> + synchronized (this) { // Noncompliant {{Remove this dangerous instance of double-checked locking.}} +// ^^^^^^^^^^^^ + if (helper == null) +// ^^^^^^^^^^^^^^< + this.helper = new Helper(); + } + return helper; + } + + private AbstractHelper abstractHelper; + private HelperInterface helperInterface; + + public HelperInterface interfaceHelper() { + if (helperInterface == null) +// ^^^^^^^^^^^^^^^^^^^^^^^> + synchronized (this) { // Noncompliant {{Remove this dangerous instance of double-checked locking.}} +// ^^^^^^^^^^^^ + if (helperInterface == null) +// ^^^^^^^^^^^^^^^^^^^^^^^< + this.helperInterface = new Helper(); + } + return helperInterface; + } + + public AbstractHelper abstractHelper() { + if (abstractHelper == null) +// ^^^^^^^^^^^^^^^^^^^^^^> + synchronized (this) { // Noncompliant {{Remove this dangerous instance of double-checked locking.}} +// ^^^^^^^^^^^^ + if (abstractHelper == null) +// ^^^^^^^^^^^^^^^^^^^^^^< + this.abstractHelper = new Helper(); + } + return abstractHelper; + } + + static class Helper extends AbstractHelper implements HelperInterface { int field; } + abstract static class AbstractHelper { int field; } + interface HelperInterface { } +} + +// after java 5 volatile keyword will guarantee correct read/write ordering with memory barriers +class DoubleCheckedLockingCheckSampleVolatile { + private volatile Helper helper = null; + + public Helper classicCase() { + if (helper == null) + synchronized (this) { // Compliant because field is volatile + if (helper == null) + helper = new Helper(); + } + return helper; + } + + static class Helper { } +} + +class DoubleCheckedLockingCheckSampleNestedIfs { + private Helper helper = null; + private boolean sunIsUp, sunIsDown; + + public Helper unrelatedNestedIfs() { + if (null == helper) { +// ^^^^^^^^^^^^^^> + if (sunIsUp) { + doSomething(); + } + synchronized (this) { // Noncompliant {{Remove this dangerous instance of double-checked locking.}} +// ^^^^^^^^^^^^ + if (sunIsDown) { + doSomethingElse(); + if (null == helper) +// ^^^^^^^^^^^^^^< + helper = new Helper(); + } + } + } + return helper; + } + + static class Helper { + int field; + } + + void doSomething() { } + void doSomethingElse() { } +} + +class DoubleCheckedLockingCheckSampleCompliant { + + private Helper helper = null; + private int primitiveField = 0; + private Integer field; + private boolean sunIsUp; + + public void notTheSameTest() { + if (sunIsUp) { + synchronized (this) { // Compliant + if (helper == null) + helper = new Helper(); + } + } + } + + public void notTheField() { + Helper helper = null; + if (helper == null) { + synchronized (this) { // Compliant + if (helper == null) { + helper = new Helper(); + } + } + } + } + + public void notTheField2() { + Helper helper = null; + if (null == null) { + synchronized (this) { // Compliant + if (helper == helper) { + helper = new Helper(); + } + } + } + } + + + public void otherField() { + if (helper == null) { + synchronized (this) { // Compliant + if (field == null) { + field = 42; + } + } + } + } + + public void otherField2() { + if (helper == null) { + synchronized (this) { + if (helper == null) { + primitiveField = 42; // Compliant + } + } + } + } + + public Helper synchronizedWithTwoIfs() { + synchronized (this) { // Compliant + if (helper == null) + if (helper == null) + helper = new Helper(); + } + return helper; + } + + public void notAVariable() { + if (MyClass.class == null) { + synchronized (this) { // Compliant + if (MyClass.class == null) { + + } + } + } + } + + public synchronized Helper synchronizedClassicCase() { + if (helper == null) + synchronized (this) { // Compliant + if (helper == null) + helper = new Helper(); + } + return helper; + } + + public Helper negatedNullEqualityOuter() { + if (!(helper == null)) + synchronized (this) { // Compliant + if (helper == null) + helper = new Helper(); + } + return helper; + } + + public Helper doubleNegatedNotEqualInner() { + if (helper == null) + synchronized (this) { + if (!!(helper != null)) + helper = new Helper(); + } + return helper; + } + + static class Helper { } +} + +class DoubleCheckedLockingCheckSampleStringResource { + final String field = ""; +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/DoubleCheckedLockingCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/DoubleCheckedLockingCheckSample.textproto.gz new file mode 100644 index 00000000000..d527480cf2b Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/DoubleCheckedLockingCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/EqualsMismatchedMembersCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/EqualsMismatchedMembersCheckSample.expected.txt.gz new file mode 100644 index 00000000000..76955bb7176 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/EqualsMismatchedMembersCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/EqualsMismatchedMembersCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/EqualsMismatchedMembersCheckSample.java new file mode 100644 index 00000000000..06df481f31e --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/EqualsMismatchedMembersCheckSample.java @@ -0,0 +1,576 @@ +package checks; + +import java.util.Arrays; + +class EqualsMismatchedMembersCheckSample { + + static class User { + private String firstName; + private String lastName; + + @Override + public boolean equals(Object obj) { + if (obj instanceof User other) { + return java.util.Objects.equals(this.firstName, other.firstName) + && java.util.Objects.equals(this.lastName, other.firstName); // Noncompliant {{This equals() implementation compares mismatched members; pairing "lastName" with "firstName" breaks the equality contract.}} + } + return false; + } + } + + static class CompliantUser { + private String firstName; + private String lastName; + + @Override + public boolean equals(Object obj) { + if (obj instanceof CompliantUser other) { + return java.util.Objects.equals(this.firstName, other.firstName) + && java.util.Objects.equals(this.lastName, other.lastName); + } + return false; + } + } + + static class Point { + private int x; + private int y; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Point that)) { + return false; + } + return x == that.x && y == that.x; // Noncompliant {{This equals() implementation compares mismatched members; pairing "y" with "x" breaks the equality contract.}} + } + } + + static class CompliantPoint { + private int x; + private int y; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof CompliantPoint that)) { + return false; + } + return x == that.x && y == that.y; + } + } + + static class NotEqual { + private int x; + private int y; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof NotEqual that)) { + return false; + } + return x != that.y; // Noncompliant {{This equals() implementation compares mismatched members; pairing "x" with "y" breaks the equality contract.}} + } + } + + static class Box { + private Object key; + private Object value; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Box that)) { + return false; + } + return key.equals(that.key) && value.equals(that.key); // Noncompliant {{This equals() implementation compares mismatched members; pairing "value" with "key" breaks the equality contract.}} + } + } + + static class CompliantBox { + private Object key; + private Object value; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof CompliantBox that)) { + return false; + } + return key.equals(that.key) && value.equals(that.value); + } + } + + static class Person { + private String firstName; + private String lastName; + + String getFirstName() { + return firstName; + } + + String getLastName() { + return lastName; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Person that)) { + return false; + } + return getFirstName().equals(that.getFirstName()) + && getLastName().equals(that.getFirstName()); // Noncompliant {{This equals() implementation compares mismatched members; pairing "getLastName()" with "getFirstName()" breaks the equality contract.}} + } + } + + static class CompliantPerson { + private String firstName; + private String lastName; + + String getFirstName() { + return firstName; + } + + String getLastName() { + return lastName; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof CompliantPerson that)) { + return false; + } + return getFirstName().equals(that.getFirstName()) + && getLastName().equals(that.getLastName()); + } + } + + static class PrimitiveGetters { + private int a; + private int b; + + int getA() { + return a; + } + + int getB() { + return b; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof PrimitiveGetters that)) { + return false; + } + return getA() == that.getB() && getB() == that.getB(); // Noncompliant {{This equals() implementation compares mismatched members; pairing "getA()" with "getB()" breaks the equality contract.}} + } + } + + record NamedPoint(int x, int y) { + @Override + public boolean equals(Object obj) { + if (!(obj instanceof NamedPoint that)) { + return false; + } + return this.x() == that.y(); // Noncompliant {{This equals() implementation compares mismatched members; pairing "x()" with "y()" breaks the equality contract.}} + } + } + + static class ArraysHolder { + private int[] left; + private int[] right; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ArraysHolder that)) { + return false; + } + return Arrays.equals(this.left, that.right); // Noncompliant {{This equals() implementation compares mismatched members; pairing "left" with "right" breaks the equality contract.}} + } + } + + static class ArraysRangeHolder { + private int[] left; + private int[] right; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ArraysRangeHolder that)) { + return false; + } + return Arrays.equals(this.left, 0, 1, that.right, 0, 1); // Noncompliant {{This equals() implementation compares mismatched members; pairing "left" with "right" breaks the equality contract.}} + } + } + + static class GuavaHolder { + private Object a; + private Object b; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof GuavaHolder that)) { + return false; + } + return com.google.common.base.Objects.equal(a, that.b) && com.google.common.base.Objects.equal(b, that.b); // Noncompliant {{This equals() implementation compares mismatched members; pairing "a" with "b" breaks the equality contract.}} + } + } + + static class MultipleMismatches { + private int a; + private int b; + private int c; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof MultipleMismatches that)) { + return false; + } + return a == that.b // Noncompliant {{This equals() implementation compares mismatched members; pairing "a" with "b" breaks the equality contract.}} + && b == that.c; // Noncompliant {{This equals() implementation compares mismatched members; pairing "b" with "c" breaks the equality contract.}} + } + } + + static class UnorderedPair { + private int a; + private int b; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof UnorderedPair that)) { + return false; + } + return (a == that.a && b == that.b) || (a == that.b && b == that.a); + } + } + + static class MixedFieldAndGetter { + private String name; + + String getName() { + return name; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof MixedFieldAndGetter that)) { + return false; + } + return this.name.equals(that.getName()); + } + } + + static class Parent { + int inherited; + } + + static class Child extends Parent { + int own; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Child that)) { + return false; + } + return this.inherited == that.own; + } + } + + static class Statics { + static int DEFAULT; + int value; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Statics that)) { + return false; + } + return this.value == DEFAULT && this.value == that.value; + } + } + + static class SuperCall { + int a; + int b; + + @Override + public boolean equals(Object obj) { + return super.equals(obj); + } + } + + static class NotEqualsMethod { + int a; + int b; + + public boolean equals(NotEqualsMethod other) { + return a == other.b; + } + + public int compareTo(Object other) { + return a == ((NotEqualsMethod) other).b ? 0 : 1; + } + } + + static class Locals { + int a; + int b; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Locals that)) { + return false; + } + int temp = that.a; + return this.a == temp && this.b == that.b; + } + } + + static class Parentheses { + int a; + int b; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Parentheses that)) { + return false; + } + return (a) == (that.b); // Noncompliant {{This equals() implementation compares mismatched members; pairing "a" with "b" breaks the equality contract.}} + } + } + + static class SameObjectFields { + int start; + int end; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof SameObjectFields that)) { + return false; + } + if (this.start == this.end && that.start == that.end) { + return true; + } + return this.start == that.start && this.end == that.end; + } + } + + static class OtherFirst { + int a; + int b; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof OtherFirst that)) { + return false; + } + return that.a == this.b; // Noncompliant {{This equals() implementation compares mismatched members; pairing "b" with "a" breaks the equality contract.}} + } + } + + static class Holder { + private T left; + private T right; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Holder that)) { + return false; + } + return java.util.Objects.equals(this.left, that.right); // Noncompliant {{This equals() implementation compares mismatched members; pairing "left" with "right" breaks the equality contract.}} + } + } + + static class GenericSameMember { + private T left; + private T right; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof GenericSameMember that)) { + return false; + } + return java.util.Objects.equals(this.left, that.left) + && java.util.Objects.equals(this.right, that.right); + } + } + + static class GenericUnordered { + private T a; + private T b; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof GenericUnordered that)) { + return false; + } + return (java.util.Objects.equals(a, that.a) && java.util.Objects.equals(b, that.b)) + || (java.util.Objects.equals(a, that.b) && java.util.Objects.equals(b, that.a)); + } + } + + static class StaticSingleton { + static final StaticSingleton EMPTY = new StaticSingleton(); + int a; + int b; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof StaticSingleton that)) { + return false; + } + return this.a == EMPTY.b && this.a == that.a && this.b == that.b; + } + } + + static class DistinctStatements { + int a; + int b; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof DistinctStatements that)) { + return false; + } + if (a == that.b) { // Noncompliant {{This equals() implementation compares mismatched members; pairing "a" with "b" breaks the equality contract.}} + return true; + } + return b == that.a; // Noncompliant {{This equals() implementation compares mismatched members; pairing "b" with "a" breaks the equality contract.}} + } + } + + static class NestedTypeInEquals { + int a; + int b; + + @Override + public boolean equals(Object obj) { + class Local { + } + if (!(obj instanceof NestedTypeInEquals that)) { + return false; + } + return a == that.a && b == that.b; + } + } + + static class NonMemberOperand { + int a; + int b; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof NonMemberOperand that)) { + return false; + } + return a == (that.b + 0) && a == that.a; + } + } + + static class UnqualifiedEquals { + Object a; + Object b; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof UnqualifiedEquals that)) { + return false; + } + return equals(that.a) && a.equals(that.a); + } + } + + static class NestedReceiver { + int a; + NestedReceiver child; + + NestedReceiver child() { + return child; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof NestedReceiver that)) { + return false; + } + return this.a == that.child().a && this.a == that.a; + } + } + + static class CustomEqualHelper { + Object a; + Object b; + + static boolean equal(Object x, Object y) { + return x == y; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof CustomEqualHelper that)) { + return false; + } + return equal(a, that.b); // Noncompliant {{This equals() implementation compares mismatched members; pairing "a" with "b" breaks the equality contract.}} + } + } + + static class NonBooleanEqualHelper { + int a; + int b; + + static void equal(Object x, Object y) { + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof NonBooleanEqualHelper that)) { + return false; + } + equal(a, that.b); + return a == that.a; + } + } + + static class StaticGetter { + int a; + int b; + + static int getA() { + return 0; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof StaticGetter that)) { + return false; + } + return getA() == that.b && a == that.a; + } + } + + static class FieldReceiver { + int a; + int b; + FieldReceiver other; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof FieldReceiver that)) { + return false; + } + return this.a == other.b && this.a == that.a; + } + } + + static class GetterWithArgument { + int a; + int b; + + int value(int ignored) { + return a; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof GetterWithArgument that)) { + return false; + } + return value(0) == that.b && a == that.a; + } + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/EqualsMismatchedMembersCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/EqualsMismatchedMembersCheckSample.textproto.gz new file mode 100644 index 00000000000..2f2da75c924 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/EqualsMismatchedMembersCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FinalizerAttackCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FinalizerAttackCheckSample.expected.txt.gz new file mode 100644 index 00000000000..8020809967b Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FinalizerAttackCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FinalizerAttackCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FinalizerAttackCheckSample.java new file mode 100644 index 00000000000..e8d04ffd200 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FinalizerAttackCheckSample.java @@ -0,0 +1,742 @@ +package checks; + +class FinalizerAttackCheckSample { + + // --- Noncompliant: non-final class with throwing constructor --- + + static class SecurityService { // Secondary {{Non-final class}} + private final String token; + + public SecurityService(String token) throws IllegalArgumentException { // Noncompliant {{Make this class "final" or make this throwing constructor "private".}} + if (token == null) { + throw new IllegalArgumentException("Invalid token"); + } + this.token = token; + } + } + + static class AuthProvider { // Secondary {{Non-final class}} + public AuthProvider(String credentials) throws Exception { // Noncompliant + if (credentials.isEmpty()) { + throw new Exception("Bad credentials"); + } + } + } + + static class ResourceLoader { // Secondary {{Non-final class}} + ResourceLoader(String path) { // Noncompliant + if (path == null) { + throw new NullPointerException(); + } + } + } + + static class MultiConstructorService { // Secondary {{Non-final class}} + MultiConstructorService(int id) throws Exception { // Noncompliant + if (id < 0) { + throw new Exception("Negative id"); + } + } + + MultiConstructorService(String name) { + } + } + + static class ProtectedConstructorService { // Secondary {{Non-final class}} + protected ProtectedConstructorService(String data) throws Exception { // Noncompliant + if (data == null) { + throw new Exception("Null data"); + } + } + } + + static class ThrowsClauseOnly { // Secondary {{Non-final class}} + public ThrowsClauseOnly() throws Exception { // Noncompliant + } + } + + // --- Compliant: final class --- + + static final class SecureService { + public SecureService(String token) throws IllegalArgumentException { + if (token == null) { + throw new IllegalArgumentException("Invalid token"); + } + } + } + + // --- Compliant: all constructors private (factory pattern) --- + + static class FactoryService { + private FactoryService(String data) { + } + + public static FactoryService create(String data) throws Exception { + if (data == null) { + throw new Exception("Null"); + } + return new FactoryService(data); + } + } + + // --- Compliant: no throwing constructor --- + + static class SafeService { + public SafeService(String data) { + // no throw + } + } + + static class NoConstructor { + void doSomething() { + } + } + + // --- Noncompliant: abstract class with throwing constructor (attacker can subclass) --- + + static abstract class AbstractService { // Secondary {{Non-final class}} + public AbstractService(String data) throws Exception { // Noncompliant + if (data == null) { + throw new Exception("Null"); + } + } + } + + // --- Compliant: private throwing constructor, public non-throwing constructor --- + + static class MixedConstructors { + private MixedConstructors(String data) throws Exception { + if (data == null) { + throw new Exception("Null"); + } + } + + public MixedConstructors(int id) { + } + } + + // --- Compliant: enum (implicitly final) --- + + enum Status { + ACTIVE, INACTIVE; + + Status() { + } + } + + // --- Compliant: record (implicitly final) --- + + record Credential(String value) { + Credential { + if (value == null) { + throw new IllegalArgumentException("Null value"); + } + } + } + + // --- Compliant: sealed class whose permitted subclasses are all final/sealed --- + + static sealed class SealedServiceAllFinal permits AllowedSubclass { + public SealedServiceAllFinal(String data) throws Exception { + if (data == null) { + throw new Exception("Null"); + } + } + } + + static final class AllowedSubclass extends SealedServiceAllFinal { + public AllowedSubclass(String data) throws Exception { + super(data); + } + } + + // --- Noncompliant: sealed class with a non-sealed permitted subclass --- + + static sealed class SealedServiceWithNonSealed permits OpenSubclass { // Secondary {{Non-final class}} + public SealedServiceWithNonSealed(String data) throws Exception { // Noncompliant + if (data == null) { + throw new Exception("Null"); + } + } + } + + static non-sealed class OpenSubclass extends SealedServiceWithNonSealed { // Secondary {{Non-final class}} + public OpenSubclass(String data) throws Exception { // Noncompliant + super(data); + } + } + + // --- Compliant: inner interface (no constructors) --- + + interface Service { + void execute(); + } + + // --- Noncompliant: throw in constructor body without throws clause --- + + static class ConfigLoader { // Secondary {{Non-final class}} + public ConfigLoader(String config) { // Noncompliant + if (config == null) { + throw new IllegalStateException("Missing config"); + } + } + } + + // --- Compliant: throw in a method, not in constructor --- + + static class Processor { + public Processor() { + } + + public void process() { + throw new UnsupportedOperationException(); + } + } + + // --- Noncompliant: nested throw in try block within constructor --- + + static class DatabaseConnection { // Secondary {{Non-final class}} + public DatabaseConnection(String url) { // Noncompliant + try { + if (url == null) { + throw new RuntimeException("Null URL"); + } + } catch (Exception e) { + throw new RuntimeException("Connection failed", e); + } + } + } + + // --- Compliant: all throwing constructors are private --- + + static class PrivateOnlyThrowers { + private PrivateOnlyThrowers(String s) throws Exception { + throw new Exception(); + } + + private PrivateOnlyThrowers(int i) { + throw new IllegalArgumentException(); + } + } + + // --- Compliant: class declares final finalize() method --- + + static class ProtectedByFinalizer { + public ProtectedByFinalizer(String data) throws Exception { + if (data == null) { + throw new Exception("Null"); + } + } + + @Override + protected final void finalize() { + // prevents finalizer attack + } + } + + // --- Noncompliant: instance initializer throws, no explicit constructor --- + + static class InitializerThrower { // Noncompliant {{Make this class "final" or add a private constructor, because initializers can throw.}} + { // Secondary {{Throwing initializer}} + if (System.currentTimeMillis() == 0) { + throw new RuntimeException("init"); + } + } + } + + // --- Compliant: field initializer calls a method that throws unchecked exception (no throws clause) --- + + static class FieldInitializerMethodCall { + private final Object value = computeValue(); + + private static Object computeValue() { + throw new UnsupportedOperationException(); + } + } + + + // --- Compliant: instance initializer throws but has explicit private constructor --- + + static class InitializerWithPrivateConstructor { + { + if (System.currentTimeMillis() == 0) { + throw new RuntimeException("init"); + } + } + + private InitializerWithPrivateConstructor() { + } + } + + // --- Compliant: local class (cannot be subclassed from outside) --- + + void someMethod() { + class LocalClass { + LocalClass() throws Exception { + throw new Exception("local"); + } + } + } + + // --- Compliant: field initializer calls a method, no direct throw in initializer expression --- + + static class FieldInitializerIndirectThrow { + private final Object data = check(null); + + private static Object check(Object o) { + if (o == null) { + throw new IllegalArgumentException(); + } + return o; + } + } + + // --- Noncompliant: non-final finalize() does not protect --- + + static class NonFinalFinalize { // Secondary {{Non-final class}} + public NonFinalFinalize(String data) throws Exception { // Noncompliant + if (data == null) { + throw new Exception("Null"); + } + } + + @Override + protected void finalize() { + // non-final finalize does NOT protect + } + } + + // --- Compliant: throw only inside lambda in constructor --- + + static class ThrowInLambda { + public ThrowInLambda() { + Runnable r = () -> { + throw new RuntimeException("in lambda"); + }; + } + } + + // --- Compliant: throw only inside anonymous class in constructor --- + + static class ThrowInAnonymousClass { + public ThrowInAnonymousClass() { + Runnable r = new Runnable() { + @Override + public void run() { + throw new RuntimeException("in anon"); + } + }; + } + } + + // --- Noncompliant: multiple throwing instance initializers, no explicit constructor --- + + static class MultipleThrowingInitializers { // Noncompliant {{Make this class "final" or add a private constructor, because initializers can throw.}} + { // Secondary {{Throwing initializer}} + if (System.currentTimeMillis() == 0) { + throw new RuntimeException("init block 1"); + } + } + { // Secondary {{Throwing initializer}} + if (System.currentTimeMillis() == 1) { + throw new RuntimeException("init block 2"); + } + } + } + + // --- Compliant: local class inside a constructor --- + + static class EnclosingWithLocalInConstructor { + EnclosingWithLocalInConstructor() { + class InnerLocal { + InnerLocal() throws Exception { + throw new Exception("local in ctor"); + } + } + } + } + + // --- Compliant: field initializer without throw --- + + static class FieldInitializerNoThrow { + private final String data = "hello"; + } + + // --- Compliant: field without initializer --- + + static class FieldNoInitializer { + private String data; + } + + // --- Noncompliant: explicit non-private constructor AND throwing initializer --- + + static class ConstructorAndThrowingInitializer { // Secondary {{Non-final class}} + { + if (System.currentTimeMillis() == 0) { + throw new RuntimeException("init"); + } + } + + public ConstructorAndThrowingInitializer(String data) throws Exception { // Noncompliant + if (data == null) { + throw new Exception("Null"); + } + } + } + + // --- Noncompliant: explicit non-throwing constructor AND throwing initializer (constructor is still a vector) --- + + static class NonThrowingConstructorWithThrowingInit { // Secondary {{Non-final class}} + { + if (System.currentTimeMillis() == 0) { + throw new RuntimeException("init"); + } + } + + public NonThrowingConstructorWithThrowingInit() { // Noncompliant + // non-throwing, but the initializer block throws during construction + } + } + + // --- Noncompliant: abstract class with throwing initializer, no constructor --- + + static abstract class AbstractWithThrowingInitializer { // Noncompliant {{Make this class "final" or add a private constructor, because initializers can throw.}} + { // Secondary {{Throwing initializer}} + if (System.currentTimeMillis() == 0) { + throw new RuntimeException("abstract init"); + } + } + } + + // --- Compliant: sealed class with all final + sealed subclasses (deep hierarchy) --- + + static sealed class DeepSealedParent permits DeepSealedChild { + public DeepSealedParent(String data) throws Exception { + if (data == null) { + throw new Exception("Null"); + } + } + } + + static sealed class DeepSealedChild extends DeepSealedParent permits DeepSealedGrandchild { + public DeepSealedChild(String data) throws Exception { + super(data); + } + } + + static final class DeepSealedGrandchild extends DeepSealedChild { + public DeepSealedGrandchild(String data) throws Exception { + super(data); + } + } + + // --- Noncompliant: sealed class with deep hierarchy ending in non-sealed --- + + static sealed class DeepSealedNonSealedBottom permits DeepSealedMid { // Secondary {{Non-final class}} + public DeepSealedNonSealedBottom(String data) throws Exception { // Noncompliant + if (data == null) { + throw new Exception("Null"); + } + } + } + + static sealed class DeepSealedMid extends DeepSealedNonSealedBottom permits DeepSealedOpen { // Secondary {{Non-final class}} + public DeepSealedMid(String data) throws Exception { // Noncompliant + super(data); + } + } + + static non-sealed class DeepSealedOpen extends DeepSealedMid { // Secondary {{Non-final class}} + public DeepSealedOpen(String data) throws Exception { // Noncompliant + super(data); + } + } + + // --- Compliant: class with final finalize() and throwing initializer --- + + static class FinalFinalizerWithThrowingInit { + { + if (System.currentTimeMillis() == 0) { + throw new RuntimeException("init"); + } + } + + @Override + protected final void finalize() { + // prevents finalizer attack + } + } + + // --- Compliant: class with only static initializer that throws --- + + static class StaticInitializerThrower { + static { + if (System.getenv("MISSING") == null) { + throw new RuntimeException("static init"); + } + } + } + + // --- Compliant: field initializer calls method (no direct throw in initializer) --- + + static class FieldInitializerIndirectThrow2 { + private final Object value = throwingInit(); + + private static Object throwingInit() { + throw new UnsupportedOperationException(); + } + } + + // --- Compliant: field initializer is a method call (no direct throw in initializer expression) --- + + static class FieldInitWithExplicitConstructor { + private final Object data = initField(); + + public FieldInitWithExplicitConstructor() { + } + + private Object initField() { + throw new UnsupportedOperationException(); + } + } + + // --- Compliant: abstract class with non-throwing constructor and no initializers --- + + static abstract class AbstractNoThrow { + public AbstractNoThrow() { + } + } + + // --- Compliant: sealed class with only sealed/final subclasses (resolved via symbolType) --- + + static sealed class SealedResolved permits ResolvedFinalChild { + public SealedResolved(String s) throws Exception { + if (s == null) throw new Exception(); + } + } + + static final class ResolvedFinalChild extends SealedResolved { + ResolvedFinalChild(String s) throws Exception { + super(s); + } + } + + // --- Noncompliant: class with multiple constructors, some throwing --- + + static class PartiallyVulnerable { // Secondary {{Non-final class}} + PartiallyVulnerable(int x) throws Exception { // Noncompliant + if (x < 0) throw new Exception(); + } + + private PartiallyVulnerable(String s) throws Exception { + if (s == null) throw new Exception(); + } + + PartiallyVulnerable(double d) { + // compliant: non-throwing + } + } + + // --- Compliant: abstract class with no throwing constructor and no throwing initializer --- + + static abstract class AbstractSafeClass { + public AbstractSafeClass(String data) { + // no throw + } + + abstract void doWork(); + } + + // --- Noncompliant: abstract class with constructor that has throws clause only --- + + static abstract class AbstractThrowsClause { // Secondary {{Non-final class}} + protected AbstractThrowsClause() throws Exception { // Noncompliant + } + } + + // --- Compliant: sealed class with sealed child (not non-sealed) --- + + static sealed class SealedWithSealedChild permits SealedChild { + public SealedWithSealedChild(String s) throws Exception { + if (s == null) throw new Exception(); + } + } + + static sealed class SealedChild extends SealedWithSealedChild permits FinalGrandchild { + public SealedChild(String s) throws Exception { + super(s); + } + } + + static final class FinalGrandchild extends SealedChild { + public FinalGrandchild(String s) throws Exception { + super(s); + } + } + + // --- Compliant: abstract class with only abstract methods --- + + static abstract class AbstractMethodOnly { + abstract void compute(); + } + + // --- Compliant: field initializer without direct throw --- + + static class FieldInitializerSafe { + private final String value = String.valueOf(42); + + public FieldInitializerSafe() { + } + } + + // --- Compliant: field initializer is anonymous class with throw (skipped by visitor) --- + + static class FieldInitAnonymousThrow { + private final Runnable action = new Runnable() { + @Override + public void run() { + throw new RuntimeException("in anon in field init"); + } + }; + } + + // --- Noncompliant: non-final, non-private constructors where one has throw and one has throws clause --- + + static class BothThrowAndThrowsClause { // Secondary {{Non-final class}} + public BothThrowAndThrowsClause(int x) { // Noncompliant + if (x < 0) { + throw new IllegalArgumentException(); + } + } + + protected BothThrowAndThrowsClause(String s) throws Exception { // Noncompliant + } + } + + // --- Noncompliant: finalize(Object) is not zero-arg finalize, does not protect --- + + static class WrongFinalizeSignature { // Secondary {{Non-final class}} + public WrongFinalizeSignature(String s) throws Exception { // Noncompliant + if (s == null) throw new Exception(); + } + + protected final void finalize(Object obj) { + // wrong signature, does not protect + } + } + + // --- Noncompliant: class with field without initializer but throwing constructor --- + + static class FieldWithoutInitializer { // Secondary {{Non-final class}} + private Object data; + + public FieldWithoutInitializer() throws Exception { // Noncompliant + throw new Exception(); + } + } + + // --- Compliant: sealed class with all sealed children (no non-sealed in hierarchy) --- + + static sealed class SealedAllSealed permits SealedChildA { + public SealedAllSealed(String s) throws Exception { + if (s == null) throw new Exception(); + } + } + + static final class SealedChildA extends SealedAllSealed { + SealedChildA(String s) throws Exception { + super(s); + } + } + + // --- Compliant: field initializer calls method (no direct throw in expression) --- + + static class FieldInitMethodCallOnly { + private final Object value = initOrThrow(); + + private static Object initOrThrow() { + throw new UnsupportedOperationException(); + } + } + + // --- Compliant: abstract class with private constructor and throwing initializer --- + + static abstract class AbstractPrivateCtorThrowingInit { + { + if (System.currentTimeMillis() == 0) { + throw new RuntimeException("init"); + } + } + + private AbstractPrivateCtorThrowingInit() { + } + } + + // --- Noncompliant: class with multiple constructors, one private one public, throwing initializer --- + + static class MixedCtorsThrowingInit { // Secondary {{Non-final class}} + { + if (System.currentTimeMillis() == 0) { + throw new RuntimeException("init"); + } + } + + private MixedCtorsThrowingInit(int x) { + } + + public MixedCtorsThrowingInit(String s) { // Noncompliant + } + } + + // --- Compliant: class with final empty finalize() and throwing field initializer calls method --- + + static class FinalFinalizerFieldInit { + private final Object value = computeValue(); + + private static Object computeValue() { + throw new UnsupportedOperationException(); + } + + @Override + protected final void finalize() { + } + } + + // --- Noncompliant: class with final finalize() but non-empty body (can still resurrect object) --- + + static class FinalFinalizerNonEmpty { // Secondary {{Non-final class}} + public FinalFinalizerNonEmpty(String data) throws Exception { // Noncompliant + if (data == null) { + throw new Exception("Null"); + } + } + + @Override + protected final void finalize() { + System.out.println("leaked"); + } + } + + // --- Compliant: class with only private constructor, throwing initializer, no default ctor --- + + static class PrivateCtorOnlyThrowInit { + { + if (System.currentTimeMillis() == 0) { + throw new RuntimeException("init"); + } + } + + private PrivateCtorOnlyThrowInit(String s) { + } + } + + // --- Noncompliant: nested inner class with throwing constructor --- + + static class OuterClass { + static class InnerVulnerable { // Secondary {{Non-final class}} + public InnerVulnerable(String s) throws Exception { // Noncompliant + if (s == null) throw new Exception(); + } + } + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FinalizerAttackCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FinalizerAttackCheckSample.textproto.gz new file mode 100644 index 00000000000..50035d37b81 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FinalizerAttackCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FloatingPointComparisonCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FloatingPointComparisonCheckSample.expected.txt.gz new file mode 100644 index 00000000000..3c717287523 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FloatingPointComparisonCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FloatingPointComparisonCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FloatingPointComparisonCheckSample.java new file mode 100644 index 00000000000..d38c77394b3 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FloatingPointComparisonCheckSample.java @@ -0,0 +1,564 @@ +package checks; + +import java.util.Comparator; +import java.util.List; +import java.util.function.DoubleSupplier; + +class FloatingPointComparisonCheckSample { + + // === Noncompliant: subtraction in compareTo with double === + + static class PositionBySubtraction implements Comparable { + private double latitude; + private double longitude; + + @Override + public int compareTo(PositionBySubtraction other) { + int latComparison = (int) (this.latitude - other.latitude); // Noncompliant {{Use "Double.compare" or "Float.compare" to compare floating-point values.}} +// ^ + if (latComparison != 0) { + return latComparison; + } + return (int) (this.longitude - other.longitude); // Noncompliant + } + } + + // === Noncompliant: subtraction in compareTo with float === + + static class FloatHolder implements Comparable { + private float value; + + @Override + public int compareTo(FloatHolder other) { + return (int) (this.value - other.value); // Noncompliant + } + } + + // === Noncompliant: subtraction in Comparator.compare === + + static class DoubleComparator implements Comparator { + @Override + public int compare(double[] a, double[] b) { + return (int) (a[0] - b[0]); // Noncompliant + } + } + + // === Noncompliant: subtraction in lambda Comparator === + + void lambdaSubtraction() { + List list = null; + list.sort((a, b) -> (int) (a[0] - b[0])); // Noncompliant + } + + // === Noncompliant: relational operators in compareTo === + + static class RelationalCompareTo implements Comparable { + private double value; + + @Override + public int compareTo(RelationalCompareTo other) { + if (this.value < other.value) { // Noncompliant + return -1; + } + if (this.value > other.value) { // Noncompliant + return 1; + } + return 0; + } + } + + // === Noncompliant: relational operators in Comparator.compare === + + static class RelationalComparator implements Comparator { + @Override + public int compare(Float a, Float b) { + float x = a; + float y = b; + if (x <= y) { // Noncompliant + return x >= y ? 0 : -1; // Noncompliant + } + return 1; + } + } + + // === Noncompliant: relational operators in lambda === + + void lambdaRelational() { + List list = null; + list.sort((a, b) -> { + double x = a; + double y = b; + if (x > y) return 1; // Noncompliant + if (x < y) return -1; // Noncompliant + return 0; + }); + } + + // === Compliant: using Double.compare in compareTo === + + static class CorrectCompareTo implements Comparable { + private double value; + + @Override + public int compareTo(CorrectCompareTo other) { + return Double.compare(this.value, other.value); // Compliant + } + } + + // === Compliant: using Float.compare in compareTo === + + static class CorrectFloatCompareTo implements Comparable { + private float value; + + @Override + public int compareTo(CorrectFloatCompareTo other) { + return Float.compare(this.value, other.value); // Compliant + } + } + + // === Compliant: using Double.compare in Comparator === + + static class CorrectComparator implements Comparator { + @Override + public int compare(double[] a, double[] b) { + return Double.compare(a[0], b[0]); // Compliant + } + } + + // === Compliant: using Double.compare in lambda === + + void lambdaCorrect() { + List list = null; + list.sort((a, b) -> Double.compare(a[0], b[0])); // Compliant + } + + // === Compliant: integer subtraction in compareTo === + + static class IntegerCompareTo implements Comparable { + private int value; + + @Override + public int compareTo(IntegerCompareTo other) { + return this.value - other.value; // Compliant - not floating-point + } + } + + // === Compliant: integer relational in compareTo === + + static class IntegerRelational implements Comparable { + private int value; + + @Override + public int compareTo(IntegerRelational other) { + if (this.value < other.value) { // Compliant - not floating-point + return -1; + } + return this.value > other.value ? 1 : 0; // Compliant + } + } + + // === Compliant: floating-point subtraction outside compareTo/compare === + + double subtract(double a, double b) { + return a - b; // Compliant - not in a comparison method + } + + boolean isGreater(double a, double b) { + return a > b; // Compliant - not in a comparison method + } + + // === Compliant: inner class has its own compareTo === + + static class OuterWithInner implements Comparable { + private double value; + + @Override + public int compareTo(OuterWithInner other) { + return Double.compare(this.value, other.value); // Compliant + + // Inner class should be checked independently + } + + static class InnerNotComparable { + double compute(double a, double b) { + return a - b; // Compliant - not in a comparison method + } + } + } + + // === Compliant: long subtraction in Comparator === + + static class LongComparator implements Comparator { + @Override + public int compare(long[] a, long[] b) { + return (int) (a[0] - b[0]); // Compliant - not floating-point + } + } + + // === Compliant: abstract compareTo method (no body) === + + interface CustomComparable { + int compareTo(T other); // Compliant - abstract method, no body + } + + // === Compliant: abstract compare method in Comparator (no body) === + + abstract static class AbstractDoubleComparator implements Comparator { + @Override + public abstract int compare(Double a, Double b); // Compliant - abstract method, no body + } + + // === Compliant: compare method not in a Comparator === + + static class DoubleUtils { + int compare(double a, double b) { + return (int) (a - b); // Compliant - not in a Comparator + } + } + + // === Noncompliant: only one operand is floating-point === + + static class MixedOperands implements Comparable { + private double value; + + @Override + public int compareTo(MixedOperands other) { + if (0 < other.value) { // Noncompliant + return -1; + } + return Double.compare(this.value, other.value); // Compliant + } + } + + // === Compliant: lambda which is not a Comparator, nested in compareTo === + + static class NonComparatorLambda implements Comparable { + private double value; + + @Override + public int compareTo(NonComparatorLambda other) { + DoubleSupplier difference = () -> this.value - other.value; // Compliant - not a Comparator + return Double.compare(difference.getAsDouble(), 0.0); // Compliant + } + } + + // === Compliant: local class nested in compareTo is checked independently === + + static class LocalClassInCompareTo implements Comparable { + private double value; + + @Override + public int compareTo(LocalClassInCompareTo other) { + class Difference { + double between(double a, double b) { + return a - b; // Compliant - not in a comparison method + } + } + return Double.compare(new Difference().between(this.value, other.value), 0.0); // Compliant + } + } + + // === Compliant: subtraction used with Float.compare/Double.compare === + + static class DifferenceWithFloatCompare implements Comparable { + private float a; + private float b; + + @Override + public int compareTo(DifferenceWithFloatCompare other) { + float d1 = this.a - this.b; // Compliant - result flows into Float.compare + float d2 = other.a - other.b; + return Float.compare(d1, d2); + } + } + + static class DifferenceWithDoubleCompare implements Comparable { + private double x; + private double y; + + @Override + public int compareTo(DifferenceWithDoubleCompare other) { + double d1 = this.x - this.y; // Compliant - result flows into Double.compare + double d2 = other.x - other.y; + return Double.compare(d1, d2); + } + } + + // === Noncompliant: subtraction with Float.compare but also relational operators === + + static class MixedSubtractionAndRelational implements Comparable { + private float a; + private float b; + + @Override + public int compareTo(MixedSubtractionAndRelational other) { + float d1 = this.a - this.b; // Noncompliant +// ^ + float d2 = other.a - other.b; // Noncompliant +// ^ + if (d1 > d2) { // Noncompliant +// ^ + return 1; + } + return Float.compare(d1, d2); + } + } + + // === Compliant: subtraction in Comparator lambda with Double.compare === + + void lambdaSubtractionWithCompare() { + List list = null; + list.sort((a, b) -> { + double diff1 = a[0] - a[1]; // Compliant - result flows into Double.compare + double diff2 = b[0] - b[1]; + return Double.compare(diff1, diff2); + }); + } + + // === Noncompliant: Float.compare used for one field, raw subtraction for another === + + static class PartialCompare implements Comparable { + private float a; + private float x; + + @Override + public int compareTo(PartialCompare other) { + int c = Float.compare(this.a, other.a); + if (c != 0) return c; + return (int) (this.x - other.x); // Noncompliant + } + } + + // === Noncompliant: Double.compare called conditionally, subtraction returned directly === + + static class ConditionalCompare implements Comparable { + private double a; + private double b; + + @Override + public int compareTo(ConditionalCompare other) { + if (this.a != other.a) { + return Double.compare(this.a, other.a); + } + return (int) (this.b - other.b); // Noncompliant + } + } + + // === Noncompliant: subtraction in ternary, compare call elsewhere === + + static class TernaryWithCompare implements Comparable { + private double x; + private double y; + + @Override + public int compareTo(TernaryWithCompare other) { + double diff = this.x - other.x; // Noncompliant +// ^ + return diff != 0 ? (int) diff : Double.compare(this.y, other.y); + } + } + + // === Compliant: subtraction used as direct argument to Float.compare === + + static class DirectSubtractionArgument implements Comparable { + private float a; + private float b; + + @Override + public int compareTo(DirectSubtractionArgument other) { + return Float.compare(this.a - this.b, other.a - other.b); // Compliant + } + } + + // === Compliant: methods which only look like comparison methods === + + static class LookAlikeMethods { + double compareTo(Object other) { + return other.hashCode() - 1.0; // Compliant - does not return an int + } + + int compareTo(Object a, Object b) { + return (int) (a.hashCode() - b.hashCode() - 0.5); // Compliant - compareTo takes exactly one parameter + } + + int compareTo(double a) { + return (int) (a - 1.0); // Compliant - the parameter is primitive + } + + int compare(Double a) { + return (int) (a - 1.0); // Compliant - compare takes exactly two parameters + } + + double compare(Double a, Double b) { + return a - b; // Compliant - does not return an int + } + } + + // === Compliant: parenthesized subtraction in Float.compare === + + static class ParenthesizedSubtractionInCompare implements Comparable { + private float a; + private float b; + + @Override + public int compareTo(ParenthesizedSubtractionInCompare other) { + return Float.compare((this.a - this.b), (other.a - other.b)); // Compliant + } + } + + // === Compliant: cast subtraction in Double.compare === + + static class CastSubtractionInCompare implements Comparable { + private float x; + private float y; + + @Override + public int compareTo(CastSubtractionInCompare other) { + return Double.compare((double) (this.x - this.y), (double) (other.x - other.y)); // Compliant + } + } + + // === Compliant: chained subtraction in Double.compare === + + static class ChainedSubtractionInCompare implements Comparable { + private double a; + private double b; + private double c; + + @Override + public int compareTo(ChainedSubtractionInCompare other) { + return Double.compare(this.a - this.b - this.c, other.a - other.b - other.c); // Compliant + } + } + + // === Compliant: parenthesized initializer variable in Float.compare === + + static class ParenthesizedInitializerInCompare implements Comparable { + private float a; + private float b; + + @Override + public int compareTo(ParenthesizedInitializerInCompare other) { + float d1 = (this.a - this.b); // Compliant - result flows into Float.compare + float d2 = (other.a - other.b); + return Float.compare(d1, d2); + } + } + + // === Noncompliant: variable used in compare AND truncated === + + static class VariableUsedOutsideCompare implements Comparable { + private double x; + + @Override + public int compareTo(VariableUsedOutsideCompare other) { + double d = this.x - other.x; // Noncompliant +// ^ + if (Double.compare(d, 0) == 0) return 0; + return (int) d; + } + } + + // === Noncompliant: subtraction compared against constant in Double.compare === + + static class SubtractionAgainstConstant implements Comparable { + private double x; + + @Override + public int compareTo(SubtractionAgainstConstant other) { + return Double.compare(this.x - other.x, 0); // Noncompliant +// ^ + } + } + + static class SubtractionAgainstZeroFloat implements Comparable { + private float a; + + @Override + public int compareTo(SubtractionAgainstZeroFloat other) { + return Float.compare(this.a - other.a, 0f); // Noncompliant +// ^ + } + } + + // === Compliant: parenthesized variable usage in compare === + + static class ParenthesizedVariableUsage implements Comparable { + private double x; + private double y; + + @Override + public int compareTo(ParenthesizedVariableUsage other) { + double a = this.x - this.y; // Compliant - flows into Double.compare + double b = other.x - other.y; + return Double.compare((a), (b)); + } + } + + // === Compliant: cast variable usage in compare === + + static class CastVariableUsage implements Comparable { + private float x; + private float y; + + @Override + public int compareTo(CastVariableUsage other) { + float a = this.x - this.y; // Compliant - flows into Double.compare via cast + float b = other.x - other.y; + return Double.compare((double) a, (double) b); + } + } + + // === Compliant: subtraction nested in method call inside Double.compare === + + static class MathHypotInCompare implements Comparable { + private double x; + private double y; + + @Override + public int compareTo(MathHypotInCompare other) { + return Double.compare(Math.hypot(this.x - 1, this.y - 1), Math.hypot(other.x - 1, other.y - 1)); // Compliant + } + } + + // === Compliant: Math.abs of subtraction stored in variable passed to Double.compare === + + static class AbsSubtractionInCompare implements Comparable { + private double x; + private double y; + + @Override + public int compareTo(AbsSubtractionInCompare other) { + double d1 = Math.abs(this.x - this.y); // Compliant - flows into Double.compare + double d2 = Math.abs(other.x - other.y); + return Double.compare(d1, d2); + } + } + + // === Compliant: subtraction in addition inside Float.compare === + + static class AdditionWithSubtractionInCompare implements Comparable { + private float a; + private float b; + private float c; + + @Override + public int compareTo(AdditionWithSubtractionInCompare other) { + return Float.compare(this.a - this.b + this.c, other.a - other.b + other.c); // Compliant + } + } + + // === Compliant: squared delta in Double.compare === + + static class SquaredDeltaInCompare implements Comparable { + private double a; + private double b; + + @Override + public int compareTo(SquaredDeltaInCompare other) { + double d1 = (this.a - this.b) * (this.a - this.b); // Compliant - flows into Double.compare + double d2 = (other.a - other.b) * (other.a - other.b); + return Double.compare(d1, d2); + } + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FloatingPointComparisonCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FloatingPointComparisonCheckSample.textproto.gz new file mode 100644 index 00000000000..77e25e2a8d2 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/FloatingPointComparisonCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ForLoopStreamSuggestionCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ForLoopStreamSuggestionCheckSample.expected.txt.gz new file mode 100644 index 00000000000..e4a042a4cb4 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ForLoopStreamSuggestionCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ForLoopStreamSuggestionCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ForLoopStreamSuggestionCheckSample.java new file mode 100644 index 00000000000..dc2295ece9a --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ForLoopStreamSuggestionCheckSample.java @@ -0,0 +1,379 @@ +package checks; + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Set; +import java.util.concurrent.LinkedBlockingQueue; + +class ForLoopStreamSuggestionCheckSample { + + private List items = new ArrayList<>(); + + void simpleCollect() { + List result = new ArrayList<>(); + for (String item : items) { // Noncompliant {{Use a stream instead of this loop.}} +// ^^^ + result.add(item); + } + } + + void filterCollect() { + List result = new ArrayList<>(); + for (String item : items) { // Noncompliant +// ^^^ + if (item != null) { + result.add(item); + } + } + } + + void filterCollectUnbraced() { + List result = new ArrayList<>(); + for (String item : items) { // Noncompliant +// ^^^ + if (item.length() > 3) + result.add(item); + } + } + + void simpleCollectUnbraced() { + List result = new ArrayList<>(); + for (String item : items) // Noncompliant +// ^^^ + result.add(item); + } + + void collectToSet() { + Set result = new HashSet<>(); + for (String item : items) { // Noncompliant +// ^^^ + result.add(item); + } + } + + void collectToLinkedList() { + LinkedList result = new LinkedList<>(); + for (String item : items) { // Noncompliant +// ^^^ + result.add(item); + } + } + + void addLastMethod() { + LinkedList result = new LinkedList<>(); + for (String item : items) { // Noncompliant +// ^^^ + result.addLast(item); + } + } + + void offerLastMethod() { + LinkedList result = new LinkedList<>(); + for (String item : items) { // Noncompliant +// ^^^ + result.offerLast(item); + } + } + + void offerSingleArg() { + LinkedList result = new LinkedList<>(); + for (String item : items) { // Noncompliant +// ^^^ + result.offer(item); + } + } + + // === Compliant cases === + + void addFirstMethod() { + LinkedList result = new LinkedList<>(); + for (String item : items) { // compliant - addFirst reverses order, not equivalent to stream + result.addFirst(item); + } + } + + void offerFirstMethod() { + LinkedList result = new LinkedList<>(); + for (String item : items) { // compliant - offerFirst reverses order, not equivalent to stream + result.offerFirst(item); + } + } + + void variableWithoutInitializer() { + List result; + result = new ArrayList<>(); + for (String item : items) { // compliant - variable has no initializer at declaration + result.add(item); + } + } + + void multipleStatementsInLoop() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - multiple statements + System.out.println(item); + result.add(item); + } + } + + void ifWithNonExpressionBody() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - if body is a return statement, not expression + if (item != null) + return; + } + } + + void ifElseBranch() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - else branch present + if (item != null) { + result.add(item); + } else { + result.add("default"); + } + } + } + + void breakInLoop() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - multi-statement with break + if (item == null) break; + result.add(item); + } + } + + void continueInLoop() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - multi-statement with continue + if (item == null) continue; + result.add(item); + } + } + + void returnInLoop() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - multi-statement with return + if (item == null) return; + result.add(item); + } + } + + void nestedLoopBody() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - nested loop + for (char c : item.toCharArray()) { + result.add(String.valueOf(c)); + } + } + } + + void localCollectionInLoop() { + for (String item : items) { // compliant - collection declared inside loop + List temp = new ArrayList<>(); + temp.add(item); + } + } + + void noCollectionDeclared() { + for (String item : items) { // compliant - no collection variable before loop + System.out.println(item); + } + } + + void emptyLoop() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - empty body + } + } + + void traditionalForLoop() { + List result = new ArrayList<>(); + for (int i = 0; i < 10; i++) { // compliant - traditional for loop, not for-each + result.add(String.valueOf(i)); + } + } + + void nonCollectionTarget() { + StringBuilder sb = new StringBuilder(); + for (String item : items) { // compliant - StringBuilder is not a Collection + sb.append(item); + } + } + + void methodCallNotAdd() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - not an add method + result.remove(item); + } + } + + void noCollectionBeforeLoop(List result) { + for (String item : items) { // compliant - result is a parameter, not declared in the block + result.add(item); + } + } + + void filterCollectPositionalAdd() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - add(int, E) inside filter has no stream equivalent + if (item != null) { + result.add(0, item); + } + } + } + + void positionalAdd() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - add(int, E) is positional insert, no stream equivalent + result.add(0, item); + } + } + + void offerWithTimeout() throws InterruptedException { + LinkedBlockingQueue result = new LinkedBlockingQueue<>(); + for (String item : items) { // compliant - offer(e, timeout, unit) has 3 args + result.offer(item, 1, java.util.concurrent.TimeUnit.SECONDS); + } + } + + void addWithoutMemberSelect() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - add is a plain method call, not member select + add(item); + } + } + + private void add(String item) { } + + void assignmentNotAdd() { + int[] arr = new int[10]; + int i = 0; + for (String item : items) { // compliant - array assignment, not collection add + arr[i++] = item.length(); + } + } + + void collectFromExistingCollection() { + List result = items; + for (String item : items) { // compliant - result is not a fresh collection + result.add(item); + } + } + + void collectFromCopiedCollection() { + List result = new ArrayList<>(items); + for (String item : items) { // compliant - result is pre-populated, not empty + result.add(item); + } + } + + void selfModifyingLoop() { + List result = new ArrayList<>(); + result.add("seed"); + for (String item : result) { // compliant - source and target are the same collection + result.add(item); + } + } + + void preLoopMutation() { + List result = new ArrayList<>(); + result.add("seed"); + for (String item : items) { // compliant - collection is mutated before the loop + result.add(item); + } + } + + void offerToQueueInterface() { + Queue result = new LinkedList<>(); + for (String item : items) { // Noncompliant +// ^^^ + result.offer(item); + } + } + + void addLastToDequeInterface() { + Deque result = new ArrayDeque<>(); + for (String item : items) { // Noncompliant +// ^^^ + result.addLast(item); + } + } + + void offerLastToDequeInterface() { + Deque result = new ArrayDeque<>(); + for (String item : items) { // Noncompliant +// ^^^ + result.offerLast(item); + } + } + + interface CustomCollectionLike { + void add(int metric); + } + + void unrelatedAddOverload(CustomCollectionLike tracker) { + List result = new ArrayList<>(); + for (String item : items) { // compliant - tracker.add(int) is not Collection.add + tracker.add(item.length()); + } + } + + static class Metrics extends ArrayList { + void add(int metric) { } + } + + void nonCollectionAddOverload() { + Metrics result = new Metrics(); + for (String item : items) { // compliant - add(int) is Metrics' own overload, not Collection.add(E) + result.add(item.length()); + } + } + + void newCollectionWithInitialCapacity() { + List result = new ArrayList<>(16); + for (String item : items) { // Noncompliant +// ^^^ + result.add(item); + } + } + + void assignmentBeforeLoop() { + List result = new ArrayList<>(); + int x = 0; + x = 42; + for (String item : items) { // Noncompliant +// ^^^ + result.add(item); + } + } + + void chainedMethodTarget() { + List result = new ArrayList<>(); + for (String item : items) { // compliant - target is method call return, not a tracked variable + getList().add(item); + } + } + + private List getList() { return items; } + + void staticMethodCallBeforeLoop() { + List result = new ArrayList<>(); + System.out.println("start"); + for (String item : items) { // Noncompliant +// ^^^ + result.add(item); + } + } + + void fieldTargetNotTracked() { + for (String item : items) { // compliant - this.items is a field, not a local fresh collection + this.items.add(item); + } + } + +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ForLoopStreamSuggestionCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ForLoopStreamSuggestionCheckSample.textproto.gz new file mode 100644 index 00000000000..b732530be04 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ForLoopStreamSuggestionCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/GetInstanceReturningNewInstanceCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/GetInstanceReturningNewInstanceCheckSample.expected.txt.gz new file mode 100644 index 00000000000..0c0ffeb4c71 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/GetInstanceReturningNewInstanceCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/GetInstanceReturningNewInstanceCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/GetInstanceReturningNewInstanceCheckSample.java new file mode 100644 index 00000000000..20b02af339c --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/GetInstanceReturningNewInstanceCheckSample.java @@ -0,0 +1,211 @@ +package checks; + +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +class GetInstanceReturningNewInstanceCheckSample { + + static class NoCache { + + private final Map flags = new HashMap<>(); + + public static NoCache getInstance() { +// ^^^^^^^^^^^> + return new NoCache(); // Noncompliant {{Rename this method, as "getInstance" is conventionally reserved for singletons, or make it return a cached instance instead of a new one.}} +// ^^^^^^^^^^^^^ + } + + void enable(String name) { + flags.put(name, true); + } + } + + static class NoCacheWithArguments { + + private NoCacheWithArguments(String name) { + } + + static NoCacheWithArguments getInstance() { +// ^^^^^^^^^^^> + return new NoCacheWithArguments("default"); // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + } + } + + static class GenericNoCache { + + static GenericNoCache getInstance() { +// ^^^^^^^^^^^> + return new GenericNoCache<>(); // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^^ + } + } + + static class RawNoCache { + + static RawNoCache getInstance() { +// ^^^^^^^^^^^> + return new RawNoCache(); // Noncompliant +// ^^^^^^^^^^^^^^^^ + } + } + + static class EagerlyCached { + + private static final EagerlyCached INSTANCE = new EagerlyCached(); + + private EagerlyCached() { + } + + static EagerlyCached getInstance() { + return INSTANCE; + } + } + + static class LazilyCached { + + private static LazilyCached instance; + + private LazilyCached() { + } + + static LazilyCached getInstance() { + if (instance == null) { + instance = new LazilyCached(); + } + return instance; + } + } + + static class SynchronizedLazilyCached { + + private static SynchronizedLazilyCached instance; + + static synchronized SynchronizedLazilyCached getInstance() { + if (instance == null) { + instance = new SynchronizedLazilyCached(); + } + return instance; + } + } + + static class HolderCached { + + private static class Holder { + private static final HolderCached INSTANCE = new HolderCached(); + } + + static HolderCached getInstance() { + return Holder.INSTANCE; + } + } + + static class NotStatic { + + NotStatic getInstance() { + return new NotStatic(); + } + } + + static class ParameterizedFactory { + + static ParameterizedFactory getInstance(Locale locale) { + return new ParameterizedFactory(); + } + + static ParameterizedFactory getInstance(Locale locale, String variant) { + return new ParameterizedFactory(); + } + } + + static class DifferentlyNamedFactories { + + static DifferentlyNamedFactories newInstance() { + return new DifferentlyNamedFactories(); + } + + static DifferentlyNamedFactories create() { + return new DifferentlyNamedFactories(); + } + + static DifferentlyNamedFactories of() { + return new DifferentlyNamedFactories(); + } + + static DifferentlyNamedFactories valueOf() { + return new DifferentlyNamedFactories(); + } + } + + static class ReturnsAnotherType { + + static Map getInstance() { + return new HashMap<>(); + } + } + + static class ReturnsAnonymousSubclass { + + static ReturnsAnonymousSubclass getInstance() { + return new ReturnsAnonymousSubclass() { + }; + } + } + + static class DoesMoreThanCreate { + + private static int calls; + + static DoesMoreThanCreate getInstance() { + calls++; + return new DoesMoreThanCreate(); + } + } + + static class ReturnsNull { + + static ReturnsNull getInstance() { + return null; + } + } + + static class NativeAccessor { + + static native NativeAccessor getInstance(); + } + + static class Throwing { + + static Throwing getInstance() { + throw new UnsupportedOperationException(); + } + } + + static class ReturnsNothing { + + static void getInstance() { + return; + } + } + + interface WithoutBody { + + static WithoutBody getInstance() { + return null; + } + } + + static abstract class AbstractGetInstance { + + abstract AbstractGetInstance getInstance(); + } + + enum EnumSingleton { + INSTANCE; + + static EnumSingleton getInstance() { + return INSTANCE; + } + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/GetInstanceReturningNewInstanceCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/GetInstanceReturningNewInstanceCheckSample.textproto.gz new file mode 100644 index 00000000000..9ba35ddc06a Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/GetInstanceReturningNewInstanceCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IdenticalCasesInSwitchCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IdenticalCasesInSwitchCheckSample.expected.txt.gz new file mode 100644 index 00000000000..e7c196a1be7 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IdenticalCasesInSwitchCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IdenticalCasesInSwitchCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IdenticalCasesInSwitchCheckSample.java new file mode 100644 index 00000000000..adcd8f02b1e --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IdenticalCasesInSwitchCheckSample.java @@ -0,0 +1,250 @@ +package checks; + +class IdenticalCasesInSwitchCheckSample { + void foo(){ + switch (1) { + case 1: +// ^[el=+4;ec=14]> + System.out.println("plop"); + System.out.println("plop"); + break; + case 2: + System.out.println("bar"); //Compliant + break; + case 3: // Noncompliant {{This case's code block is the same as the block for the case on line 6.}} +// ^[el=+5;ec=14] 1 + case 4: + System.out.println("plop"); + System.out.println("plop"); + break; + case 5: // Noncompliant {{This case's code block is the same as the block for the case on line 6.}} +// ^[el=+4;ec=14] + System.out.println("plop"); + System.out.println("plop"); + break; + } + + switch (1) { + case 1: + f(1); + break; + case 2: + f(2); + break; + } + + switch (1) { + case 1: +// ^[el=+2;ec=18]> + trivial(); + case 2: // Noncompliant + //^[el=+2;ec=18] 1 + trivial(); + } + + switch (1) { + case 1: +// ^[el=+3;ec=14]> + trivial(); + break; + case 2: // Noncompliant + //^[el=+3;ec=14] 1 + trivial(); + break; + case 3: // Noncompliant + trivial(); + break; + } + + switch (1) { + case 1: + trivial(); + case 2: + trivial(); + case 3: + default: + } + + switch (1) { + case 1: + trivial(); + break; + case 2: + trivial(); + break; + case 3: + default: + } + + switch (1) { + case 1: + f(); + nonTrivial(); + case 2: // Noncompliant + f(); + nonTrivial(); + case 3: + } + + switch (1) { + case 1: + f(1); + break; + } + + switch (1) { + case 1: + f(1); + System.out.println(1); + break; + case 2: // Noncompliant + f(1); + System.out.println(1); + break; + } + + switch (1) { + case 1: + f(1); + System.out.println(1); + break; + case 2: // Noncompliant + f(1); + System.out.println(1); + break; + case 3: + break; + } + + switch (1) { + case 1: + trivial(); + break; + case 2: // Compliant - this case is covered by RSPEC-3923 + trivial(); + break; + default: // Compliant - this case is covered by RSPEC-3923 + trivial(); + break; + } + } + + void ifStatement() { + if (true) { + System.out.println("foo"); + } else if (true) { + // skip empty blocks + } else if (true) { + // skip empty blocks + } else if (true) { + System.out.println("bar"); + } else if (true) { // Compliant - trivial + System.out.println("foo"); + } else { // Compliant - trivial + System.out.println("foo"); + } + + if (true) { + //^[el=+4;ec=5]> {{Original}} + System.out.println("foo"); + System.out.println("foo"); + } else if (true) { + // skip empty blocks + } else if (true) { + // skip empty blocks + } else if (true) { + System.out.println("bar"); + } else if (true) { // Noncompliant {{This branch's code block is the same as the block for the branch on line 147.}} +// ^[el=+4;ec=5] 1 + System.out.println("foo"); + System.out.println("foo"); + } else { // Noncompliant {{This branch's code block is the same as the block for the branch on line 147.}} +// ^[ec=5;el=+4] + System.out.println("foo"); + System.out.println("foo"); + } + if (true) { + f(); + } + + if (true) f(); + else if (true) f(); + else g(); + + if (true) f(); + else f(); + + if (true) f(); +// ^^^^> + else if (true) f(); // Noncompliant +// ^^^^ + if (true) { +// ^[el=+4;ec=5]> + f(); + f(); + } + else if (true) { // Noncompliant + // ^[el=+4;ec=5] 1 + f(); + f(); + } + else if (true) { +// ^[el=+4;ec=5]> + g(); + g(); + } + else if (true) { // Noncompliant + // ^[el=+4;ec=5] + g(); + g(); + } + else ; + } + + private void g() { + } + + private void nonTrivial() { + } + + private void trivial() { + } + + private void f() { + } + + private void f(int i) { + } + + static class Parent {}; + static class A extends Parent {}; + static class B extends Parent {}; + + // Edge case involving variables introduced with `instanceof`. + // See: https://community.sonarsource.com/t/fp-java-s1871-branch-code-block-is-the-same/130645 + void variablesBoundInInstanceOf() { + Parent p1 = new A(); + Parent p2 = new B(); + if(Math.random() < 0.5) { + p1 = new B(); + p2 = new A(); + } + + // No problem when `a` refers to different variables. + Parent p = null; + if (p1 instanceof A a) { + p = a; + } + else if (p2 instanceof A a) { + p = a; + } + + // Variables have different names and identities. + if (p1 instanceof A a1) { + p = a1; + } + else if (p2 instanceof A a2) { + p = a2; + } + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IdenticalCasesInSwitchCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IdenticalCasesInSwitchCheckSample.textproto.gz new file mode 100644 index 00000000000..9ca5929d6fa Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IdenticalCasesInSwitchCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IncompatibleBitMaskCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IncompatibleBitMaskCheckSample.expected.txt.gz new file mode 100644 index 00000000000..5278006ffc8 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IncompatibleBitMaskCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IncompatibleBitMaskCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IncompatibleBitMaskCheckSample.java new file mode 100644 index 00000000000..235b2ecbc3c --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IncompatibleBitMaskCheckSample.java @@ -0,0 +1,256 @@ +package checks; + +class IncompatibleBitMaskCheckSample { + + void bitwiseAndNoncompliant(int x, long status) { + // AND mask 1 (0b01) cannot produce 2 (0b10) + if ((x & 1) == 2) {} // Noncompliant {{This comparison is always false.}} + // ^^ + + // AND mask 0x0F cannot produce 0x10 + if ((x & 0x0F) == 0x10) {} // Noncompliant {{This comparison is always false.}} + + // AND mask 3 (0b11) cannot produce 4 (0b100) + if ((x & 3) == 4) {} // Noncompliant {{This comparison is always false.}} + + // != with incompatible values is always true + if ((x & 1) != 2) {} // Noncompliant {{This comparison is always true.}} + + // Long variant: AND mask 0xFF cannot produce 0x100 + if ((status & 0xFFL) == 0x100L) {} // Noncompliant {{This comparison is always false.}} + } + + void bitwiseOrNoncompliant(int x, long data) { + // OR with 1 always sets bit 0, result can never be 0 + if ((x | 1) == 0) {} // Noncompliant {{This comparison is always false.}} + + // OR with 3 always sets bits 0 and 1, result can never be 2 (missing bit 0) + if ((x | 3) == 2) {} // Noncompliant {{This comparison is always false.}} + + // != with incompatible OR is always true + if ((x | 2) != 1) {} // Noncompliant {{This comparison is always true.}} + + // Long variant: OR with 0xFF always sets low 8 bits + if ((data | 0xFFL) == 0L) {} // Noncompliant {{This comparison is always false.}} + } + + void bitwiseAndCompliant(int x, long status) { + // Mask 2 can produce 2 + if ((x & 2) == 2) {} // Compliant + + // 0x04 is within mask 0x0F + if ((x & 0x0F) == 0x04) {} // Compliant + + // Comparing AND result to 0 is always valid + if ((x & 1) == 0) {} // Compliant + + // 3 is within mask 7 + if ((x & 7) == 3) {} // Compliant + + // 2 is reachable by AND with 3 + if ((x & 3) != 2) {} // Compliant + + // Long: 0x80 is within mask 0xFF + if ((status & 0xFFL) == 0x80L) {} // Compliant + } + + void bitwiseOrCompliant(int x, long data) { + // 1 includes all mask bits + if ((x | 1) == 1) {} // Compliant + + // 3 includes all mask bits + if ((x | 3) == 3) {} // Compliant + + // 0xFF includes all mask bits 0x0F + if ((x | 0x0F) == 0xFF) {} // Compliant + + // 3 includes mask bit 2, comparison is meaningful + if ((x | 2) != 3) {} // Compliant + + // Value includes all mask bits + if ((data | 0xFFL) == 0xFFL) {} // Compliant + } + + void maskOnLeftSide(int x) { + // Mask on left side of bitwise operation + if ((1 & x) == 2) {} // Noncompliant {{This comparison is always false.}} + + if ((1 & x) == 0) {} // Compliant + } + + void constantOnLeftSideOfComparison(int x) { + // Constant on left side of comparison + if (2 == (x & 1)) {} // Noncompliant {{This comparison is always false.}} + + if (0 == (x & 1)) {} // Compliant + } + + void hexAndBinaryLiterals(int x) { + // Hex literals + if ((x & 0xFF) == 0x100) {} // Noncompliant {{This comparison is always false.}} + + // Binary literals + if ((x & 0b1111) == 0b10000) {} // Noncompliant {{This comparison is always false.}} + + if ((x & 0b1111) == 0b1010) {} // Compliant + } + + void edgeCases(int x) { + // Mask of 0: AND with 0 always produces 0 + if ((x & 0) == 1) {} // Noncompliant {{This comparison is always false.}} + if ((x & 0) == 0) {} // Compliant + + // OR with 0: result is x, any comparison is meaningful + if ((x | 0) == 5) {} // Compliant + } + + void noConstantOperands(int x, int y, int z) { + // No constant mask - no issue + if ((x & y) == 2) {} // Compliant + + // No constant comparison value - no issue + if ((x & 1) == y) {} // Compliant + + // No constant at all + if ((x & y) == z) {} // Compliant + } + + void notBitwiseOperations(int x) { + // XOR is not covered + if ((x ^ 1) == 2) {} // Compliant + + // Regular comparison without bitwise + if (x == 2) {} // Compliant + + // Addition, not bitwise + if ((x + 1) == 2) {} // Compliant + } + + void parenthesizedExpressions(int x) { + // Extra parentheses around bitwise operation + if (((x & 1)) == 2) {} // Noncompliant {{This comparison is always false.}} + + if (((x & 2)) == 2) {} // Compliant + } + + void bitwiseOrNotEqual(int x, long data) { + // != with OR where mask bits are not all present in value: always true + if ((x | 3) != 0) {} // Noncompliant {{This comparison is always true.}} + + // Long variant: OR with != always true when mask bits missing + if ((data | 0xFFL) != 0L) {} // Noncompliant {{This comparison is always true.}} + + // Constant on left side with != and OR + if (0 != (x | 1)) {} // Noncompliant {{This comparison is always true.}} + + // Compliant: value includes mask bits + if ((x | 1) != 1) {} // Compliant + } + + void longLiteralMaskOnLeft(long x) { + // Long literal as left operand of bitwise AND + if ((0xFFL & x) == 0x100L) {} // Noncompliant {{This comparison is always false.}} + + // Long literal as left operand of bitwise OR + if ((0xFFL | x) == 0L) {} // Noncompliant {{This comparison is always false.}} + + // != with long literal mask on left + if ((0xFFL & x) != 0x100L) {} // Noncompliant {{This comparison is always true.}} + + // Compliant long literal mask on left + if ((0xFFL & x) == 0x80L) {} // Compliant + } + + void longLiteralOnRightOfBitwiseOp(long x) { + // Long literal on right side of bitwise AND + if ((x & 0xFFL) == 0x100L) {} // Noncompliant {{This comparison is always false.}} + + // Long literal on left side of bitwise AND (exercises left-operand path in hasLongLiteral) + if ((0xFFL & x) == 0x80L) {} // Compliant + } + + void intWidthHighBitMasks(int x) { + // 0xFFFFFFFF as int is -1, so (x & 0xFFFFFFFF) == -1 is valid when x == -1 + if ((x & 0xFFFFFFFF) == -1) {} // Compliant + + // 0xFFFFFFFF as int is -1, AND with -1 is identity, so comparing to 0 is valid + if ((x & 0xFFFFFFFF) == 0) {} // Compliant + + // 0x80000000 as int is Integer.MIN_VALUE (-2147483648), valid comparison + if ((x & 0x80000000) == -2147483648) {} // Compliant + + // High-bit hex mask with matching hex value + if ((x & 0xF0000000) == 0xF0000000) {} // Compliant + + // AND with 3 cannot produce -1 (only bits 0 and 1 can be set) + if ((x & 3) == -1) {} // Noncompliant {{This comparison is always false.}} + + // != with int-width high-bit mask + if ((x & 3) != -1) {} // Noncompliant {{This comparison is always true.}} + } + + void comparisonValueOnLeftWithLong(long x) { + // Long constant on left side of comparison, bitwise on right + if (0x100L == (x & 0xFFL)) {} // Noncompliant {{This comparison is always false.}} + + if (0x80L == (x & 0xFFL)) {} // Compliant + } + + void intHexMaskSignExtensionInLongContext(long longX) { + // Int literal 0xFFFFFFFF sign-extends to -1L in long context, so (longX & -1L) == longX + // This comparison is valid when longX == -1 + if ((longX & 0xFFFFFFFF) == -1L) {} // Compliant + + // 0xFFFFFFFF sign-extends to -1L, AND with -1L is identity, so any value is reachable + if ((longX & 0xFFFFFFFF) == 4294967295L) {} // Compliant + + // 0x80000000 as int is MIN_VALUE, sign-extends to 0xFFFFFFFF_80000000L + // AND with that mask can produce 0x80000000L (the low 32 bits match) + if ((longX & 0x80000000) == 0x80000000L) {} // Compliant + + // Int mask 0x0F does not sign-extend (no high bit set), stays 0x0F + // AND with 0x0F cannot produce 0x100L + if ((longX & 0x0F) == 0x100L) {} // Noncompliant {{This comparison is always false.}} + } + + void longBitwiseOpsWithLongLiterals(long x) { + // OR with 0xFFL always sets low 8 bits; result must include those bits + // 0x10000000000L does not include any of the low 8 bits + if ((x | 0xFFL) == 0x10000000000L) {} // Noncompliant {{This comparison is always false.}} + + // Long AND mask: 0xFFL cannot produce value beyond 0xFF + if ((x & 0xFFL) == 0x10000000000L) {} // Noncompliant {{This comparison is always false.}} + } + + void parenthesizedLiterals(int x) { + // Parenthesized mask literal + if ((x & (1)) == 2) {} // Noncompliant {{This comparison is always false.}} + + // Parenthesized comparison value + if ((x & 1) == (2)) {} // Noncompliant {{This comparison is always false.}} + + // Parenthesized hex mask and value + if ((x & (0xFF)) == (0x1FF)) {} // Noncompliant {{This comparison is always false.}} + + // Compliant with parenthesized literals + if ((x & (3)) == (2)) {} // Compliant + } + + void intOperationWithLongComparisonValue(int intVar) { + // int bitwise result is promoted to long for comparison with long literal + // (intVar & 0xFFFFFFFF) is int -1, promoted to long -1L, which != 0xFFFFFFFFL (4294967295) + if ((intVar & 0xFFFFFFFF) == 0xFFFFFFFFL) {} // Noncompliant {{This comparison is always false.}} + + // != variant + if ((intVar & 0xFFFFFFFF) != 0xFFFFFFFFL) {} // Noncompliant {{This comparison is always true.}} + } + + void unsignedHighBitLongMasks(long flags) { + // 0xFFFF_FFFF_FFFF_FFFEL has all bits set except LSB + // AND with that mask clears bit 0 only, so result can never be -1L (all bits set) + if ((flags & 0xFFFF_FFFF_FFFF_FFFEL) == -1L) {} // Noncompliant {{This comparison is always false.}} + + // 0x8000_0000_0000_0000L is Long.MIN_VALUE, AND with it can produce 0L + if ((flags & 0x8000_0000_0000_0000L) == 0L) {} // Compliant + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IncompatibleBitMaskCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IncompatibleBitMaskCheckSample.textproto.gz new file mode 100644 index 00000000000..3887aa74edf Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IncompatibleBitMaskCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerClassInInterfaceCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerClassInInterfaceCheckSample.expected.txt.gz new file mode 100644 index 00000000000..6b9128c741b Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerClassInInterfaceCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerClassInInterfaceCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerClassInInterfaceCheckSample.java new file mode 100644 index 00000000000..a4914516fe4 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerClassInInterfaceCheckSample.java @@ -0,0 +1,254 @@ +package checks; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +interface InnerClassInInterfaceCheckSample { + + void doSomething(); + + class DefaultImpl implements InnerClassInInterfaceCheckSample { // Noncompliant {{Move this class out of this interface.}} +// ^^^^^^^^^^^ + @Override + public void doSomething() { + } + } + + class Empty {} // Noncompliant +// ^^^^^ + + static class ExplicitlyStatic {} // Noncompliant +// ^^^^^^^^^^^^^^^^ + + abstract class AbstractHelper {} // Compliant - abstract classes are contract-like + + interface NestedContract { // Compliant - nested interface + void process(); + } + + enum Status { // Compliant - enums for contract constants + ACTIVE, INACTIVE + } + + record Payload(String data, int size) {} // Compliant - record as data carrier + + @interface Marker {} // Compliant - annotation type + + interface InnerInterface { + class InnerInNested {} // Noncompliant +// ^^^^^^^^^^^^^ + } +} + +interface ExtendedInterface extends Comparable { + class Helper { // Noncompliant +// ^^^^^^ + public int compare(ExtendedInterface a, ExtendedInterface b) { + return 0; + } + } + + class First {} // Noncompliant +// ^^^^^ + class Second {} // Noncompliant +// ^^^^^^ +} + +interface WithHelperTypes { + + Result compute(Request request) throws ComputationException; + + Optional wrapped(); + + void consume(List> elements); + + void consumeQualified(WithHelperTypes.Qualified qualified); + + default Defaulted defaulted() { + return new Defaulted(); + } + + static Created create() { + return new Created(); + } + + class Result {} // Compliant - return type of an interface method + + class Request {} // Compliant - parameter type of an interface method + + class ComputationException extends Exception {} // Compliant - exception thrown by an interface method + + class Wrapped {} // Compliant - type argument of a return type + + class Element {} // Compliant - nested type argument of a parameter type + + class Qualified {} // Compliant - qualified parameter type + + class Defaulted {} // Compliant - return type of a default method + + class Created {} // Compliant - return type of a static method + + class Unused {} // Noncompliant +// ^^^^^^ + + class UsedInBodyOnly {} // Noncompliant +// ^^^^^^^^^^^^^^ + default void useInBody() { + UsedInBodyOnly local = new UsedInBodyOnly(); + } + + class ParameterName {} // Noncompliant +// ^^^^^^^^^^^^^ + void named(String ParameterName); +} + +interface WithNameCollisionsInSignatures { + + java.util.Optional qualifiedForeignType(); + + Element typeParameter(); + + class Optional {} // Noncompliant +// ^^^^^^^^ + + class Element {} // Noncompliant +// ^^^^^^^ +} + +interface WithImplementationsUsedInSignatures { + + WithImplementationsUsedInSignatures copy(Nested other); + + Generic generic(); + + Qualified qualified(); + + class Nested implements WithImplementationsUsedInSignatures { // Noncompliant +// ^^^^^^ + @Override + public WithImplementationsUsedInSignatures copy(Nested other) { + return this; + } + @Override + public Generic generic() { + return null; + } + @Override + public Qualified qualified() { + return null; + } + } + + class Generic implements WithImplementationsUsedInSignatures, Comparable> { // Noncompliant +// ^^^^^^^ + @Override + public WithImplementationsUsedInSignatures copy(Nested other) { + return this; + } + @Override + public Generic generic() { + return null; + } + @Override + public Qualified qualified() { + return null; + } + @Override + public int compareTo(Generic o) { + return 0; + } + } + + class Qualified implements checks.WithImplementationsUsedInSignatures { // Noncompliant +// ^^^^^^^^^ + @Override + public WithImplementationsUsedInSignatures copy(Nested other) { + return this; + } + @Override + public Generic generic() { + return null; + } + @Override + public Qualified qualified() { + return null; + } + } +} + +interface ComparableUser { + + Helper helper(); + + class Helper implements Comparable { // Compliant - helper type, does not implement the enclosing interface + @Override + public int compareTo(ComparableUser o) { + return 0; + } + } +} + +interface WithBuilder { + + String name(); + + class Builder { // Compliant - builder pattern + private String name; + + public Builder name(String name) { + this.name = name; + return this; + } + } + + class WithBuilderBuilder {} // Compliant - builder pattern +} + +class TopLevelClass { // Compliant - not inside an interface + class InnerClass {} // Compliant - class inside class + + interface InnerInterface {} // Compliant - interface inside class +} + +enum TopLevelEnum { + VALUE; + class Helper {} // Compliant - class inside enum +} + +interface WithDefaultMethod { + default Runnable createAction() { + return new Runnable() { // Compliant - anonymous class + @Override + public void run() { + } + }; + } +} + +@interface AnnotationWithClass { + class Helper {} // Compliant - annotation types are not interfaces +} + +interface WithNestedClassHierarchy { + class Outer { // Noncompliant +// ^^^^^ + class Inner {} // Compliant - parent is a class, not an interface + } +} + +interface WithGenericHelperTypes { + + GenericResult compute(GenericRequest request); + + void consume(List> elements); + + class GenericResult {} // Compliant - generic return type of an interface method + + class GenericRequest {} // Compliant - generic parameter type of an interface method + + class GenericElement {} // Compliant - generic type argument of a parameter type + + class GenericUnused {} // Noncompliant +// ^^^^^^^^^^^^^ +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerClassInInterfaceCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerClassInInterfaceCheckSample.textproto.gz new file mode 100644 index 00000000000..67ff259ce43 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerClassInInterfaceCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerStaticClassesCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerStaticClassesCheckSample.expected.txt.gz new file mode 100644 index 00000000000..f65dc2c9f07 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerStaticClassesCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerStaticClassesCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerStaticClassesCheckSample.java new file mode 100644 index 00000000000..7a78af4e2e5 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerStaticClassesCheckSample.java @@ -0,0 +1,281 @@ +package checks.InnerStaticClassesCheck; + +class Fruit { + private int value; + + public class Seed { // Noncompliant {{Make this a "static" inner class.}} +// ^^^^ + int germinationDays = 0; + public Seed(int germinationDays) { + this.germinationDays = germinationDays; + } + public int getGerminationDays() { + return germinationDays; + } + public class SeedI { // Compliant, inner classes cannot be static + int germinationDays = 0; + public SeedI(int germinationDays) { + this.germinationDays = germinationDays; + } + public int getGerminationDays() { + return germinationDays; + } + } + } + + public static class StaticSeed { + int germinationDays = 0; + public StaticSeed(int germinationDays) { + this.germinationDays = germinationDays; + } + public int getGerminationDays() { + return germinationDays; + } + public static class StaticSeedI { + int germinationDays = 0; + public StaticSeedI(int germinationDays) { + this.germinationDays = germinationDays; + } + public int getGerminationDays() { + return germinationDays; + } + } + public class StaticSeedI2 { // Noncompliant {{Make this a "static" inner class.}} + + } + } + + public class Referencing { + public Referencing() { + value = 5; + } + public class ReferencingI { + public ReferencingI() { + value = 5; + } + } + } + + public class Referencing2 { + public Referencing2() { + Fruit.this.value = 6; + } + public class Referencing2I { + public Referencing2I() { + Fruit.this.value = 6; + } + } + } + + public class Referencing3 { + public void method() { + instance.toString(); // coverage + new Referencing2(); // Referencing2 accesses instance + } + } + + private void fun() { + foo: + for (int i = 0; i < value; i++) { + continue foo; + } + Fruit fruit = new Fruit() { // compliant, we ignore anonymous classes + }; + } + + private static final Fruit.StaticSeed instance = new Fruit.StaticSeed(5){ + }; + + public interface Interface { + } + + public void noncompliant() { + class Seed implements Interface { // Noncompliant {{Extract this local class into a "static" inner class.}} + public void foo() { + return; + } + } + + Interface inter = new Interface() { // compliant, we ignore anonymous classes + public void foo() { + return; + } + }; + } + +} +class Bar { + public int plop() {return 1;} +} + +class A { + private int fielda; + + class B { // Compliant inner class refers to field. + Bar foo() { + return new Bar() { + public String toString() { return ""+fielda;} + }; + } + } + class C { // Noncompliant + Object foo() { + return new Object(); + } + } + + class SubB extends B { // Compliant since super class is not static + Bar foo() { + return new Bar(); + } + } + + class SubSubB extends SubB { // Compliant since super class is not static + Bar foo() { + return new Bar(); + } + } + + class InnerObject extends Object { // Noncompliant + + } + + class InnerArrayList extends java.util.ArrayList { // Noncompliant + + } + +} + +class Extendable { + protected int field; +} + +class Foo extends Extendable { + + class Inner { // Compliant field is refered. + void plop(){ + System.out.println(field); + } + } +} +class A1 { + private int field; + + class B { // Noncompliant + int foo; + class C { + Bar foo() { + return new Bar() { + public String toString() { + return "" + foo; + } + }; + } + } + } + + void usedInAnonymousClass() { + final String myString = ""; + method(new toImplement() { // Compliant my String is used. + public void fun(String s) { + myString.length(); + } + }); + } + interface toImplement { + void fun(String s); + } + void method(Object j) {} + +} + +class A2 extends A3 { + A2(Object o){} +} + +class A3 { + class Inner extends A2 { + public Inner() { + super(A3.this); + } + } +} +class A4 { + public void m(int a) { + class B { // compliant cannot be made static + int foo() { + return a; + } + } + } +} + +class Parent { + static class Generic { + abstract class A implements java.util.List { } // Compliant + abstract class B extends A { } // Compliant + class C extends Generic { } // Compliant + class C2 extends Other.Generic { } // Compliant + abstract class D implements java.util.List { } // Noncompliant + } +} +class Other { + static class Generic {} +} + +class Foo2 { + private String string; + + public Foo2() { + class Bar { // Noncompliant {{Extract this local class into a "static" inner class.}} + } + } + + public void method() { + class Baz { // Noncompliant {{Extract this local class into a "static" inner class.}} + } + } + + record InnerFoo2Record() { // Compliant + } + + enum InnerEnum { // Compliant + A, B, C; + } + + @interface InnerAnnotation { // Compliant + } +} + +record FooRecord() { + public FooRecord() { + class InnerBar { // Noncompliant {{Extract this local class into a "static" inner class.}} + } + } + + public void method() { + class InnerBaz { // Noncompliant {{Extract this local class into a "static" inner class.}} + } + } + + class InnerFoo { // Noncompliant + } + + record InnerFooRecord() { // Compliant + } + + enum InnerEnum { // Compliant + A, B, C; + } + + @interface InnerAnnotation { // Compliant + } +} + +@interface FooAnnotation { + class InnerFoo { // Compliant + } + + record InnerFooRecord() { // Compliant + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerStaticClassesCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerStaticClassesCheckSample.textproto.gz new file mode 100644 index 00000000000..5740e96c658 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InnerStaticClassesCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InstanceOfPatternMatching.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InstanceOfPatternMatching.expected.txt.gz new file mode 100644 index 00000000000..c5103dc815b Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InstanceOfPatternMatching.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InstanceOfPatternMatching.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InstanceOfPatternMatching.java new file mode 100644 index 00000000000..94823b8028f --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InstanceOfPatternMatching.java @@ -0,0 +1,297 @@ +package checks; + +import java.util.Map; + +public abstract class InstanceOfPatternMatching { + + private static String booleanArray(Object o){ + if(o instanceof boolean[]){ // Noncompliant {{Replace this instanceof check and cast with 'instanceof boolean[] booleanArray'}} + return Boolean.toString(((boolean[])o)[0]); + } + return "not a boolean array"; + } + + private static String booleanArray2(Object o){ + if(o instanceof boolean[][]){ // Noncompliant {{Replace this instanceof check and cast with 'instanceof boolean[][] booleanArrayArray'}} + return Boolean.toString(((boolean[][])o)[0][0]); + } + return "not a boolean array"; + } + + int if1(Object o) { + if (o instanceof String) { // Noncompliant {{Replace this instanceof check and cast with 'instanceof String str'}} +// ^^^^^^^^^^^^^^^^^^^ + String str = (String) o; +// ^^^^^^^^^^< + return str.length(); + } + return 0; + } + + int if1Compliant(Object o) { + if (o instanceof String string) { // Compliant + return string.length(); + } + return 0; + } + + int if2(Object o) { + if (1 > 2 && o instanceof String && 3 > 4) { // Noncompliant {{Replace this instanceof check and cast with 'instanceof String str'}} +// ^^^^^^^^^^^^^^^^^^^ + System.out.println("holla"); + String str = (String) o; +// ^^^^^^^^^^< + return str.length(); + } + return 0; + } + + int if3(Object o) { + if (o instanceof String) { // Noncompliant {{Replace this instanceof check and cast with 'instanceof String str'}} +// ^^^^^^^^^^^^^^^^^^^ + if (23 < 42) { + String str = (String) o; +// ^^^^^^^^^^< + return str.length(); + } + } + return 0; + } + + Object o; + int if4() { + if (o instanceof String) { // Noncompliant {{Replace this instanceof check and cast with 'instanceof String str'}} +// ^^^^^^^^^^^^^^^^^^^ + String str = (String) o; +// ^^^^^^^^^^< + return str.length(); + } + return 0; + } + + int if4Compliant() { + if (o instanceof String) { + Object o = "shadow"; + String str = (String) o; // Compliant because we're casting a different o than the one we instanceofed + return str.length(); + } + return 0; + } + + int if5(Map map) { + if (map.get("hello") instanceof String) { // Noncompliant {{Replace this instanceof check and cast with 'instanceof String str'}} +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + String str = (String) map.get("hello"); +// ^^^^^^^^^^^^^^^^^^^^^^^^^< + return str.length(); + } + return 0; + } + + int if5Compliant(Map map) { + if (map.get("hello") instanceof String) { + String str = (String) map.get("goodbye"); // Compliant because we're getting a different key than we instanceofed + return str.length(); + } + return 0; + } + + int if16(Object o) { + // Since the assignment of the cast happens separately from the variable declaration, we don't use the variable name + // in the error message + if (o instanceof String) { // Noncompliant {{Replace this instanceof check and cast with 'instanceof String string'}} +// ^^^^^^^^^^^^^^^^^^^ + String str; + str = (String) o; +// ^^^^^^^^^^< + return str.length(); + } + return 0; + } + + int if7(Object o) { + if (o instanceof Integer) { // Compliant because different types are used for the cast + String str = (String) o; + return str.length(); + } + return 0; + } + + int if8(Object o1, Object o2) { + if (o1 instanceof String) { // Compliant because we're instanceoffing a different object than we cast + String str = (String) o2; + return str.length(); + } + return 0; + } + + int if9(Object o) { + if (1 > 2 || o instanceof String || 3 > 4) { // Compliant because the instanceof doesn't dominate the cast (would be nice to have an invalid cast SE rule to catch this as a bug) + System.out.println("holla"); + String str = (String) o; + return str.length(); + } + return 0; + } + + int if10(Object o) { + if (!(o instanceof String)) { // Compliant because the instanceof doesn't dominate the cast (would be nice to have an invalid cast SE rule to catch this as a bug) + System.out.println("holla"); + String str = (String) o; + return str.length(); + } + return 0; + } + + + int ifElse1(Object o) { + if (!(o instanceof String)) { // Noncompliant {{Replace this instanceof check and cast with 'instanceof String str'}} +// ^^^^^^^^^^^^^^^^^^^ + } else { + String str = (String) o; +// ^^^^^^^^^^< + return str.length(); + } + return 0; + } + + int ifElse2(Object o) { + if (o instanceof String) { // Compliant because the condition isn't active in the else clause (would be nice to have an invalid cast SE rule to catch this as a bug) + } else { + String str = (String) o; + return str.length(); + } + return 0; + } + + int ifElse3(Object o) { + if (!(o instanceof String || 1 < 2)) { // Noncompliant {{Replace this instanceof check and cast with 'instanceof String str'}} +// ^^^^^^^^^^^^^^^^^^^ + } else { + String str = (String) o; +// ^^^^^^^^^^< + return str.length(); + } + return 0; + } + + int ifElse4(Object o) { + if (!(o instanceof String && 1 < 2)) { // Compliant because the instanceof doesn't dominate the else + } else { + String str = (String) o; + return str.length(); + } + return 0; + } + + int ifElse5(Object o) { + if (!!(o instanceof String)) { // Compliant because the condition isn't active in the else clause (would be nice to have an invalid cast SE rule to catch this as a bug) + } else { + String str = (String) o; + return str.length(); + } + return 0; + } + + int ifElse6(Object o) { + if (!!!(o instanceof String)) { // Noncompliant {{Replace this instanceof check and cast with 'instanceof String str'}} +// ^^^^^^^^^^^^^^^^^^^ + } else { + String str = (String) o; +// ^^^^^^^^^^< + return str.length(); + } + return 0; + } + + boolean and1(Object o) { + return (o instanceof String && ((String) o).length() > 0); // Noncompliant {{Replace this instanceof check and cast with 'instanceof String string'}} +// ^^^^^^^^^^^^^^^^^^^ +// ^^^^^^^^^^@-1< + } + + boolean and1Compliant(Object o) { + return (o instanceof String s && s.length() > 0); // Compliant + } + + boolean and2(Object o) { + return (1 < 4 && o instanceof String && ((String) o).length() > 0 && 23 < 42); // Noncompliant {{Replace this instanceof check and cast with 'instanceof String string'}} +// ^^^^^^^^^^^^^^^^^^^ +// ^^^^^^^^^^@-1< + } + + boolean and3(Object o) { + return (!(o instanceof String) && ((String) o).length() > 0); // Compliant because the instanceof isn't in effect for the right operand + } + + boolean or1(Object o) { + return (!(o instanceof String) || ((String) o).length() > 0); // Noncompliant {{Replace this instanceof check and cast with 'instanceof String string'}} +// ^^^^^^^^^^^^^^^^^^^ +// ^^^^^^^^^^@-1< + } + + boolean or2(Object o) { + return (o instanceof String || ((String) o).length() > 0); // Compliant because the instanceof isn't in effect for the right operand + } + + + int ternary(Object o) { + return (o instanceof String) ? ((String) o).length() : 0; // Noncompliant {{Replace this instanceof check and cast with 'instanceof String string'}} +// ^^^^^^^^^^^^^^^^^^^ +// ^^^^^^^^^^@-1< + } + + int ternaryCompliant(Object o) { + return (o instanceof String s) ? s.length() : 0; // Compliant + } + + abstract Object getNext(); + + void whileLoop1() { + Object o = getNext(); + while (o instanceof String) { // Noncompliant {{Replace this instanceof check and cast with 'instanceof String str'}} +// ^^^^^^^^^^^^^^^^^^^ + String str = (String) o; +// ^^^^^^^^^^< + o = getNext(); + } + } + + void whileLoop2() { + Object o = getNext(); + while (!(o instanceof String)) { // Compliant because instanceof not active inside loop + String str = (String) o; + o = getNext(); + } + } + + void whileLoop3() { + Object o = getNext(); + while (!(o instanceof String)) { // FN because we don't detect casts that come after the loop + o = getNext(); + } + String str = (String) o; + } + + void forLoop1() { + for (Object o = getNext(); o instanceof String; o = getNext()) { // Noncompliant {{Replace this instanceof check and cast with 'instanceof String str'}} +// ^^^^^^^^^^^^^^^^^^^ + String str = (String) o; +// ^^^^^^^^^^< + } + } + + void forLoop2() { + for (Object o = getNext(); !(o instanceof String); o = getNext()) { // Compliant because instanceof not active inside loop + String str = (String) getNext(); + } + } + + void forLoop3() { + for (Object o = getNext(); ; o = getNext()) { // Test that we don't throw for empty conditions + String str = (String) getNext(); + } + } + + +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InstanceOfPatternMatching.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InstanceOfPatternMatching.textproto.gz new file mode 100644 index 00000000000..84bd8914332 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InstanceOfPatternMatching.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerOverflowCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerOverflowCheckSample.expected.txt.gz new file mode 100644 index 00000000000..e81b1fe9d47 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerOverflowCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerOverflowCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerOverflowCheckSample.java new file mode 100644 index 00000000000..fc55fe1198b --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerOverflowCheckSample.java @@ -0,0 +1,241 @@ +package checks; + +import java.time.Instant; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.function.IntBinaryOperator; +import java.util.function.IntSupplier; + +class IntegerOverflowCheckSample { + + int intAddition = Integer.MAX_VALUE + 1; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + int intSubtraction = Integer.MIN_VALUE - 1; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + int intMultiplication = 1_000_000 * 10_000; // Noncompliant +// ^^^^^^^^^^^^^^^^^^ + long longAddition = Long.MAX_VALUE + 1L; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^ + long longSubtraction = Long.MIN_VALUE - 1L; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^ + long longMultiplication = 4_000_000_000L * 4_000_000_000L; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + int nested = Integer.MAX_VALUE + 1; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + int wrappedExact = (Integer.MAX_VALUE + 1) + Integer.MAX_VALUE; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + long wrappedLongExact = (Long.MAX_VALUE + 1L) + Long.MAX_VALUE; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^ + int nestedWithoutOverflow = (1 + 2) + 3; + + int exactIntMaximum = Integer.MAX_VALUE - 1; + int exactIntMinimum = Integer.MIN_VALUE + 1; + long exactLongMaximum = Long.MAX_VALUE - 1L; + long widenedBefore = (long) Integer.MAX_VALUE + 1; + long ownedByS2184 = Integer.MAX_VALUE + 1; + Object explicitResultCast = (long) (Integer.MAX_VALUE + 1); // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + double ownedLongToDouble = Long.MAX_VALUE + 1L; + float ownedLongToFloat = Long.MAX_VALUE + 1L; + double assignedDouble; + + long ownedReturn() { + return Integer.MAX_VALUE + 1; + } + + void widenedArguments() { + consume(Integer.MAX_VALUE + 1); + new LongHolder(Integer.MAX_VALUE + 1); + consumeTwo(0L, Integer.MAX_VALUE + 1); + new Date((long) (Integer.MAX_VALUE + 1)); + Instant.ofEpochSecond((long) (Integer.MAX_VALUE + 1), 0L); + Instant.ofEpochSecond(0L, (long) (Integer.MAX_VALUE + 1)); // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + Instant.ofEpochSecond((long) (Long.MAX_VALUE + 1L), 0L); // Noncompliant +// ^^^^^^^^^^^^^^^^^^^ + consumeObject((long) (Integer.MAX_VALUE + 1)); // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + } + + void consume(long value) { + } + + void consumeTwo(long first, long second) { + } + + void consumeObject(Object value) { + } + + void widenedAssignment() { + assignedDouble = Long.MAX_VALUE + 1L; + } + + int unknown(int left, int right) { + int arbitrary = left + right; + long member = new LongHolder(0L).value + 1; + return arbitrary; + } + + int midpoint(int low, int high) { + int result = (low + high) / 2; // Noncompliant +// ^^^^^^^^^^ + double doubleResult = (low + high) / 2.0; // Noncompliant +// ^^^^^^^^^^ + float floatResult = (low + high) / 2f; // Noncompliant +// ^^^^^^^^^^ + int safe = low + (high - low) / 2; + int shifted = (low + high) >>> 1; + long widenedAverage = ((long) low + high) / 2; + int knownAverage = (1 + 2) / 2; + int ceilingHalf = (low + 1) / 2; + return result + safe + shifted + (int) doubleResult + (int) floatResult + knownAverage + ceilingHalf; + } + + int boundedMidpoints(int low, String text, List values) { + int boundedAverage = (text.length() + values.size()) / 2; + int mixedAverage = (low + values.size()) / 2; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^ + return boundedAverage + mixedAverage; + } + + long longAverage(long low, long high) { + return (low + high) / 2; + } + + int narrowAverages(short shortLow, short shortHigh, byte byteLow, byte byteHigh, char charLow, char charHigh, int intLow) { + int shortMidpoint = (shortLow + shortHigh) / 2; + int byteMidpoint = (byteLow + byteHigh) / 2; + int charMidpoint = (charLow + charHigh) / 2; + int mixedMidpoint = (intLow + shortHigh) / 2; + return shortMidpoint + byteMidpoint + charMidpoint + mixedMidpoint; + } + + int bounded(String text, List values, Map map, Day day, int[] array) { + int safe = text.length(); + int twoBounded = text.length() + values.size(); + int lengthPlusOne = array.length + 1; + int possibleOverflow = array.length * Integer.MAX_VALUE; + int wrappedUnknown = (text.length() + values.size()) + Integer.MAX_VALUE; + int mask = (hashCode() & 255) * 1_000_000; + int reverseMask = (255 & hashCode()) * 1_000_000; + int invalidMask = (hashCode() & -1) + 1; + int mapAndOrdinal = map.size() + day.ordinal(); + int bitCount = Integer.bitCount(hashCode()) * Integer.MAX_VALUE; + int alwaysAbove = (Integer.bitCount(hashCode()) + 2) * Integer.MAX_VALUE; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + int alwaysBelow = Integer.MIN_VALUE - (Integer.bitCount(hashCode()) + 1); // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + long longBitCount = (Long.bitCount(System.nanoTime()) + 2L) * Long.MAX_VALUE; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + long unsignedLow = System.nanoTime() & 0xFFFFFFFFL; + long unsignedSquare = unsignedLow * unsignedLow; + return safe + twoBounded + lengthPlusOne + possibleOverflow + wrappedUnknown + mask + reverseMask + invalidMask + mapAndOrdinal + bitCount + + alwaysAbove + alwaysBelow + (int) longBitCount + (int) unsignedSquare; + } + + int effectivelyFinal() { + int value = Integer.MAX_VALUE; + return value + 1; // Noncompliant +// ^^^^^^^^^ + } + + int reassigned() { + int value = Integer.MAX_VALUE; + value = 0; + return value + 1; + } + + int unknownNegation(int value) { + return -value; + } + + long literalNegation() { + int minimumLiteral = -2147483648; + long minimumLongLiteral = -9223372036854775808L; + int belowMinimumLiteral = -2147483648 - 1; // Noncompliant +// ^^^^^^^^^^^^^^^ + return minimumLiteral + minimumLongLiteral + belowMinimumLiteral; + } + + long parenthesizedSinks() { + long parenthesized = (Integer.MAX_VALUE + 1); // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + consume((Integer.MAX_VALUE + 1)); // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + return (Integer.MAX_VALUE + 1); // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + } + + long lambdaReturn() { + IntSupplier supplier = () -> { + return Integer.MAX_VALUE + 1; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + }; + return supplier.getAsInt(); + } + + int ordinaryReturn() { + return Integer.MIN_VALUE - 1; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + } + + Comparator comparator = (left, right) -> left - right; + Comparator constantComparator = (left, right) -> Integer.MIN_VALUE - 1; + Comparator castComparator = (left, right) -> (int) (Integer.MIN_VALUE - 1); + IntBinaryOperator nonComparator = (left, right) -> Integer.MIN_VALUE - 1; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + + Comparator blockComparator = (left, right) -> { + return Integer.MIN_VALUE - 1; + }; + + Comparator comparatorWithIntermediate = (left, right) -> { + int overflow = Integer.MIN_VALUE - 1; // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^^ + if (overflow == 0) { + return 0; + } + return left - right; + }; + + int minimumNegation = -Integer.MIN_VALUE; + long minimumLongNegation = -Long.MIN_VALUE; + final int minimumAlias = Integer.MIN_VALUE; + int minimumAliasNegation = -minimumAlias; // Noncompliant +// ^^^^^^^^^^^^^ + int parenthesizedMinimumNegation = -(Integer.MIN_VALUE); // Noncompliant +// ^^^^^^^^^^^^^^^^^^^^ + long widenedMinimumAliasNegation = -minimumAlias; // Noncompliant +// ^^^^^^^^^^^^^ + Date minimumAliasTimestamp = new Date(-minimumAlias); + Instant minimumAliasInstant = Instant.ofEpochMilli((long) -minimumAlias); + + int exactMethods() { + return Math.addExact(Integer.MAX_VALUE, 1) + + Math.subtractExact(Integer.MIN_VALUE, 1) + + Math.multiplyExact(Integer.MAX_VALUE, 2) + + Math.negateExact(Integer.MIN_VALUE); + } + + static class LongHolder { + long value; + + LongHolder(long value) { + this.value = value; + } + } + + static class ComparatorImplementation implements Comparator { + @Override + public int compare(Integer left, Integer right) { + return Integer.MIN_VALUE - 1; + } + } + + enum Day { + MONDAY + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerOverflowCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerOverflowCheckSample.textproto.gz new file mode 100644 index 00000000000..babc315ae3f Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerOverflowCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerSubtractionInComparisonCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerSubtractionInComparisonCheckSample.expected.txt.gz new file mode 100644 index 00000000000..ac5cc2be3e0 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerSubtractionInComparisonCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerSubtractionInComparisonCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerSubtractionInComparisonCheckSample.java new file mode 100644 index 00000000000..6988bd98726 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerSubtractionInComparisonCheckSample.java @@ -0,0 +1,483 @@ +package checks; + +import java.io.File; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.function.IntSupplier; + +class IntegerSubtractionInComparisonCheckSample { + + static class TimestampedEvent implements Comparable { + private long timestamp; + + @Override + public int compareTo(TimestampedEvent other) { + return (int) (this.timestamp - other.timestamp); // Noncompliant {{Subtracting numeric values in compareTo can overflow; use Long.compare instead.}} +// ^ + } + } + + static class IntHolder implements Comparable { + private int value; + + @Override + public int compareTo(IntHolder other) { + return this.value - other.value; // Noncompliant {{Subtracting numeric values in compareTo can overflow; use Integer.compare instead.}} + } + } + + static class BoxedIntHolder implements Comparable { + private Integer value; + + @Override + public int compareTo(BoxedIntHolder other) { + return this.value - other.value; // Noncompliant {{Subtracting numeric values in compareTo can overflow; use Integer.compare instead.}} + } + } + + static class BoxedLongHolder implements Comparable { + private Long value; + + @Override + public int compareTo(BoxedLongHolder other) { + return (int) (this.value - other.value); // Noncompliant {{Subtracting numeric values in compareTo can overflow; use Long.compare instead.}} + } + } + + static class MixedOperands implements Comparable { + private long longValue; + private int intValue; + + @Override + public int compareTo(MixedOperands other) { + return (int) (this.longValue - other.intValue); // Noncompliant {{Subtracting numeric values in compareTo can overflow; use Long.compare instead.}} + } + } + + static class IndexArithmetic implements Comparable { + private int[] parts; + + @Override + public int compareTo(IndexArithmetic other) { + for (int i = 0; i < parts.length - 1; i++) { // Compliant - subtraction is not the comparison result + int cmp = Integer.compare(this.parts[i], other.parts[i]); + if (cmp != 0) { + return cmp; + } + } + return 0; + } + } + + static class IntermediateDiff implements Comparable { + private int age; + + @Override + public int compareTo(IntermediateDiff other) { + int diff = this.age - other.age; // Compliant - only a returned subtraction is reported + if (diff != 0) { + return Integer.compare(this.age, other.age); + } + return 0; + } + } + + static class HashCodeCompare implements Comparable { + @Override + public int compareTo(HashCodeCompare other) { + return this.hashCode() - other.hashCode(); // Noncompliant {{Subtracting numeric values in compareTo can overflow; use Integer.compare instead.}} + } + } + + static class NonIntCastCompareTo implements Comparable { + private int value; + + @Override + public int compareTo(NonIntCastCompareTo other) { + return (int) (short) (this.value - other.value); // Compliant - the subtraction is wrapped in a non-int cast + } + } + + static class AgeComparator implements Comparator { + @Override + public int compare(IntHolder left, IntHolder right) { + return left.value - right.value; // Noncompliant {{Subtracting numeric values in compare can overflow; use Integer.compare instead.}} + } + } + + static class LongArrayComparator implements Comparator { + @Override + public int compare(long[] a, long[] b) { + return (int) (a[0] - b[0]); // Noncompliant {{Subtracting numeric values in compare can overflow; use Long.compare instead.}} + } + } + + static final Comparator COMPARATOR_UNBOXED_INT_CAST = new Comparator() { + @Override + public int compare(Number n1, Number n2) { + return (int) (n1.longValue() - n2.longValue()); // Noncompliant {{Subtracting numeric values in compare can overflow; use Long.compare instead.}} + } + }; + + static final Comparator COMPARATOR_BOXED_INT_CAST = new Comparator() { + @Override + public int compare(Long n1, Long n2) { + return (int) (n1 - n2); // Noncompliant {{Subtracting numeric values in compare can overflow; use Long.compare instead.}} + } + }; + + static final Comparator COMPARATOR_FILE_INT_CAST = new Comparator() { + @Override + public int compare(File lhs, File rhs) { + return (int) (rhs.lastModified() - lhs.lastModified()); // Noncompliant {{Subtracting numeric values in compare can overflow; use Long.compare instead.}} + } + }; + + void lambdaSubtraction(List list, List events) { + list.sort((a, b) -> a.value - b.value); // Noncompliant {{Subtracting numeric values in compare can overflow; use Integer.compare instead.}} + events.sort((left, right) -> (int) (left.timestamp - right.timestamp)); // Noncompliant {{Subtracting numeric values in compare can overflow; use Long.compare instead.}} + list.sort((a, b) -> { + return a.value - b.value; // Noncompliant {{Subtracting numeric values in compare can overflow; use Integer.compare instead.}} + }); + } + + static class CorrectLongCompareTo implements Comparable { + private long timestamp; + + @Override + public int compareTo(CorrectLongCompareTo other) { + return Long.compare(this.timestamp, other.timestamp); // Compliant + } + } + + static class CorrectIntCompareTo implements Comparable { + private int value; + + @Override + public int compareTo(CorrectIntCompareTo other) { + return Integer.compare(this.value, other.value); // Compliant + } + } + + static class CorrectBoxedLongCompareTo implements Comparable { + private Long value; + + @Override + public int compareTo(CorrectBoxedLongCompareTo other) { + return value.compareTo(other.value); // Compliant + } + } + + static class IntegerRelational implements Comparable { + private int value; + + @Override + public int compareTo(IntegerRelational other) { + if (this.value < other.value) { // Compliant + return -1; + } + return this.value > other.value ? 1 : 0; // Compliant + } + } + + static class FloatingPointCompareTo implements Comparable { + private double latitude; + + @Override + public int compareTo(FloatingPointCompareTo other) { + return (int) (this.latitude - other.latitude); // Compliant - handled by S9148 + } + } + + static class ByteCompareTo implements Comparable { + private byte value; + + @Override + public int compareTo(ByteCompareTo other) { + return this.value - other.value; // Compliant - difference fits in int + } + } + + static class ShortCompareTo implements Comparable { + private short value; + + @Override + public int compareTo(ShortCompareTo other) { + return this.value - other.value; // Compliant - difference fits in int + } + } + + static class CharCompareTo implements Comparable { + private char value; + + @Override + public int compareTo(CharCompareTo other) { + return this.value - other.value; // Compliant - difference fits in int + } + } + + static class BoxedShortCompareTo implements Comparable { + private Short value; + + @Override + public int compareTo(BoxedShortCompareTo other) { + return this.value - other.value; // Compliant - difference fits in int + } + } + + static class ArrayLengthComparator implements Comparator { + @Override + public int compare(int[] left, int[] right) { + return left.length - right.length; // Compliant - both operands are array lengths, bounded in [0, Integer.MAX_VALUE] + } + } + + static class StringLengthComparator implements Comparator { + @Override + public int compare(String left, String right) { + return left.length() - right.length(); // Compliant - both operands are String.length(), bounded in [0, Integer.MAX_VALUE] + } + } + + static class CollectionSizeComparator implements Comparator> { + @Override + public int compare(List left, List right) { + return left.size() - right.size(); // Compliant - both operands are Collection.size(), bounded in [0, Integer.MAX_VALUE] + } + } + + static class MapSizeComparator implements Comparator> { + @Override + public int compare(Map left, Map right) { + return left.size() - right.size(); // Compliant - both operands are Map.size(), bounded in [0, Integer.MAX_VALUE] + } + } + + enum Suit { + CLUBS, DIAMONDS, HEARTS, SPADES + } + + static class OrdinalComparator implements Comparator { + @Override + public int compare(Suit left, Suit right) { + return left.ordinal() - right.ordinal(); // Compliant - both operands are Enum.ordinal(), bounded in [0, Integer.MAX_VALUE] + } + } + + static class BitCountComparator implements Comparator { + @Override + public int compare(Integer left, Integer right) { + return Integer.bitCount(left) - Integer.bitCount(right); // Compliant - both operands are bounded in [0, 32] + } + } + + static class LongBitCountComparator implements Comparator { + @Override + public int compare(Long left, Long right) { + return Long.bitCount(left) - Long.bitCount(right); // Compliant - both operands are bounded in [0, 64] + } + } + + static class MaskedByteComparator implements Comparator { + @Override + public int compare(byte[] left, byte[] right) { + int a = left[0] & 0xff; + int b = right[0] & 0xff; + return a - b; // Compliant - both operands are masked to [0, 255] + } + } + + static class DirectMaskedByteComparator implements Comparator { + @Override + public int compare(byte[] left, byte[] right) { + return (left[0] & 0xff) - (right[0] & 0xff); // Compliant - both operands are masked to [0, 255] + } + } + + static class IndirectLengthComparator implements Comparator { + @Override + public int compare(String left, String right) { + int len1 = left.length(); + int len2 = right.length(); + return len1 - len2; // Compliant - len1 and len2 are single-write locals holding String.length() + } + } + + static class LiteralConstantComparator implements Comparator { + @Override + public int compare(Object left, Object right) { + return 0 - 1; // Compliant - both operands are compile-time constants + } + } + + static class MixedBoundedAndUnboundedComparator implements Comparable { + private int value; + + @Override + public int compareTo(MixedBoundedAndUnboundedComparator other) { + // Noncompliant@+1 {{Subtracting numeric values in compareTo can overflow; use Integer.compare instead.}} + return this.value - other.getClass().getName().length(); + } + } + + static class MixedUnboundedAndBoundedComparator implements Comparator { + @Override + public int compare(String left, String right) { + // Noncompliant@+1 {{Subtracting numeric values in compare can overflow; use Integer.compare instead.}} + return left.length() - right.hashCode(); + } + } + + static class BoundedButUnsafeComparator implements Comparator { + @Override + public int compare(byte[] left, byte[] right) { + int a = left[0] & 0xff; + // Noncompliant@+1 {{Subtracting numeric values in compare can overflow; use Integer.compare instead.}} + return a - Integer.MIN_VALUE; + } + } + + static class SignBitLiteralComparator implements Comparator { + @Override + public int compare(String left, String right) { + // 0x80000000 is the int literal for Integer.MIN_VALUE; left.length() is bounded but this still overflows. + // Noncompliant@+1 {{Subtracting numeric values in compare can overflow; use Integer.compare instead.}} + return left.length() - 0x80000000; + } + } + + static class MaskedByUnresolvedMaskComparator implements Comparator { + @Override + public int compare(Integer left, Integer right) { + int mask = computeMask(left); + // mask does not resolve to a constant, so the mask range - and therefore this subtraction - is unknown. + // Noncompliant@+1 {{Subtracting numeric values in compare can overflow; use Integer.compare instead.}} + return (left & mask) - 0; + } + + private static int computeMask(int seed) { + return seed > 0 ? 0xff : 0x0f; + } + } + + static class DeeplyChainedLocalsComparator implements Comparator { + @Override + public int compare(String left, String right) { + int a = left.length(); + int b = a; + int c = b; + int d = c; + int e = d; + int f = e; + int g = f; + int h = g; + // The single-write resolution depth cap keeps this conservative: h is not traced all the way back to + // left.length(), so it is treated as unbounded even though it provably isn't. + // Noncompliant@+1 {{Subtracting numeric values in compare can overflow; use Integer.compare instead.}} + return h - right.length(); + } + } + + static class IncrementedCounterComparator implements Comparator { + @Override + public int compare(String[] left, String[] right) { + int leftCount = 0; + for (String s : left) { + leftCount++; + } + int rightCount = 0; + for (String s : right) { + rightCount++; + } + // leftCount and rightCount are mutated with ++, not a single assignment, so they are not resolved to a + // bounded range even though both loops only ever increment their counter. + // Noncompliant@+1 {{Subtracting numeric values in compare can overflow; use Integer.compare instead.}} + return leftCount - rightCount; + } + } + + static class UnknownRangeComparator implements Comparable { + @Override + public int compareTo(UnknownRangeComparator other) { + return this.hashCode() - other.hashCode(); // Noncompliant {{Subtracting numeric values in compareTo can overflow; use Integer.compare instead.}} + } + } + + int subtract(int a, int b) { + return a - b; // Compliant - not in a comparison method + } + + static class DoubleUtils { + int compare(int a, int b) { + return a - b; // Compliant - not in a Comparator + } + } + + static class NonComparableTest { + private final long value = 0; + + public int compareTo(NonComparableTest other) { + return (int) (this.value - other.value); // Compliant - class is not Comparable + } + } + + static final Object COMPARATOR_LIKE_INT_CAST = new Object() { + public int compare(Long n1, Long n2) { + return (int) (n1 - n2); // Compliant - not a Comparator + } + }; + + static class LookAlikeMethods { + double compareTo(Object other) { + return other.hashCode() - 1; // Compliant - does not return an int + } + + int compareTo(Object a, Object b) { + return a.hashCode() - b.hashCode(); // Compliant - compareTo takes exactly one parameter + } + + int compare(IntHolder a) { + return a.value - 1; // Compliant - compare takes exactly two parameters + } + } + + static class NestedLambda implements Comparable { + private int value; + + @Override + public int compareTo(NestedLambda other) { + IntSupplier difference = () -> this.value - other.value; // Compliant - not a Comparator + return Integer.compare(difference.getAsInt(), 0); // Compliant + } + } + + static class LocalClassInCompareTo implements Comparable { + private int value; + + @Override + public int compareTo(LocalClassInCompareTo other) { + class Difference { + int between(int a, int b) { + return a - b; // Compliant - not in a comparison method + } + } + return Integer.compare(new Difference().between(this.value, other.value), 0); // Compliant + } + } + + interface CustomComparable { + int compareTo(T other); // Compliant - abstract method, no body + } + + abstract static class AbstractIntComparator implements Comparator { + @Override + public abstract int compare(Integer a, Integer b); // Compliant - abstract method, no body + } + + void lambdaCorrect(List list, List events) { + list.sort((a, b) -> Integer.compare(a.value, b.value)); // Compliant + events.sort((left, right) -> Long.compare(left.timestamp, right.timestamp)); // Compliant + } + +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerSubtractionInComparisonCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerSubtractionInComparisonCheckSample.textproto.gz new file mode 100644 index 00000000000..6d5386f6dc0 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IntegerSubtractionInComparisonCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InterruptedExceptionCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InterruptedExceptionCheckSample.expected.txt.gz new file mode 100644 index 00000000000..4df9af852c6 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InterruptedExceptionCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InterruptedExceptionCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InterruptedExceptionCheckSample.java new file mode 100644 index 00000000000..d264419b1c0 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InterruptedExceptionCheckSample.java @@ -0,0 +1,540 @@ +package checks; + +import java.io.IOException; +import java.util.Set; +import java.util.concurrent.BlockingQueue; +import java.util.function.LongSupplier; + +enum Level { + WARN; +} +interface Log { + void log(Level level, String s, Throwable e); +} + +public class InterruptedExceptionCheckSample { + static final Log LOGGER = null; + + public void run1 () { + try { + while (true) { + if (LOGGER != null) throw new IOException(""); + throw new InterruptedException(""); + + } + }catch (java.io.IOException e) { + LOGGER.log(Level.WARN, "Interrupted!", e); + }catch (InterruptedException e) { // Noncompliant {{Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.}} +// ^^^^^^^^^^^^^^^^^^^^^^ + LOGGER.log(Level.WARN, "Interrupted!", e); + } + } + + public void runUnknownSymbol () { + try { + while (true) { + if (LOGGER != null) throw new IOException(""); + throw new InterruptedException(""); + } + }catch (java.io.IOException e) { + LOGGER.log(Level.WARN, "Interrupted!", e); + }catch (InterruptedException e) { // Noncompliant + LOGGER.log(Level.WARN, "Interrupted!", e); + } + } + + public void catchUnionType () { + try { + while (true) { + if (LOGGER != null) throw new IOException(""); + throw new InterruptedException(""); + } + } catch (InterruptedException | java.io.IOException e) { // Noncompliant {{Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.}} +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + LOGGER.log(Level.WARN, "Interrupted!", e); + } + } + + public void runInterrupted() { + try { + throw new InterruptedException(); + } catch (InterruptedException e) { + LOGGER.log(Level.WARN, "Interrupted!", e); + // clean up state... + Thread.currentThread().interrupt(); + } + try { + while (true) { + throw new InterruptedException(); + // do stuff + } + } catch (InterruptedException e) { // Noncompliant {{Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.}} + LOGGER.log(Level.WARN, "Interrupted!", e); + // clean up state... + new Interruptable().interrupt(); + } + } + + public Object getNextTask(BlockingQueue queue) { + boolean interrupted = false; + try { + while (true) { + try { + return queue.take(); + } catch (InterruptedException e) { + interrupted = true; + // fall through and retry + } + } + } finally { + if (interrupted) + Thread.currentThread().interrupt(); + } + } + +} + +class Interruptable { + static final Log LOGGER = null; + + void interrupt() { + + } + + private static void waitForNextExecution(Set running, LongSupplier waitTimeoutMillis) { + try { + Thread.sleep(waitTimeoutMillis.getAsLong()); + } catch (InterruptedException e) { //Compliant + cancelAllSubTasksAndInterrupt(running); + } + } + + private static void cancelAllSubTasksAndInterrupt(Set subTasks) { + for (Runnable task : subTasks) { + System.out.println("--- waitForNextExecution: Service interrupted. Cancel execution of task {}."); + } + Thread.currentThread().interrupt(); + } + + private static void waitForNextExecution1(Set running, LongSupplier waitTimeoutMillis) { + try { + Thread.sleep(waitTimeoutMillis.getAsLong()); + } catch (InterruptedException e) { // Noncompliant + cancelAllSubTasksAndInterrupt1(running); + } + } + + private static void cancelAllSubTasksAndInterrupt1(Set subTasks) { + cancelAllSubTasksAndInterrupt2(subTasks); + } + + private static void cancelAllSubTasksAndInterrupt2(Set subTasks) { + cancelAllSubTasksAndInterrupt3(subTasks); + } + + private static void cancelAllSubTasksAndInterrupt3(Set subTasks) { + cancelAllSubTasksAndInterrupt4(subTasks); + if (LOGGER != null )throw new RuntimeException(); + } + + private static void cancelAllSubTasksAndInterrupt4(Set subTasks) { + for (Runnable task : subTasks) { + System.out.println("--- waitForNextExecution: Service interrupted. Cancel execution of task {}."); + } + Thread.currentThread().interrupt(); + } + + public void catchGenericException() throws InterruptedException { + try { + throwsInterruptedException(); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^> + } catch (Exception e) { // Noncompliant {{Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.}} +// ^^^^^^^^^^^ + LOGGER.log(Level.WARN, "Interrupted!", e); + } + + try { + throwsInterruptedException(); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^> + throwsException(); + } catch (Exception e) { // Noncompliant +// ^^^^^^^^^^^ + LOGGER.log(Level.WARN, "Interrupted!", e); + } + + try { + throwsInterruptedException(); + } catch (Throwable e) { // Noncompliant {{Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.}} + LOGGER.log(Level.WARN, "Interrupted!", e); + } + + try { + throwsInterruptedException(); + } catch (Exception e) { // Compliant, correct handling + Thread.currentThread().interrupt(); + } + + try { + throwsInterruptedException(); + } catch (IllegalArgumentException e) { // Compliant, InterruptedException not caught + LOGGER.log(Level.WARN, "Interrupted!", e); + } + + try { + throwsException(); + } catch (Exception e) { // Compliant + LOGGER.log(Level.WARN, "Interrupted!", e); + } + } + + public void catchMultiplesException() throws InterruptedException { + try { + throwsInterruptedException(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } catch (Exception e) { // Compliant, correctly handled in the previous catch + LOGGER.log(Level.WARN, "Something else!", e); + } + + try { + throwsInterruptedException(); + } catch (Exception e) { + Thread.currentThread().interrupt(); + } catch (Throwable e) { // Compliant, correctly handled in the previous catch + LOGGER.log(Level.WARN, "Something else!", e); + } + + try { + throwsInterruptedException(); + } catch (Exception e) { // Noncompliant + LOGGER.log(Level.WARN, "Something else!", e); + } catch (Throwable e) { + Thread.currentThread().interrupt(); + } + } + + public void throwNewInterruptedExceptionFromCatch() throws InterruptedException { + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Compliant + throw new InterruptedException(); + } + + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Compliant + throw new CustomizedInterruptedException(); + } + + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Noncompliant + throw new RuntimeException(); + } + } + + public void catchSubtypeOfInterruptedException() throws InterruptedException { + try { + throwsInterruptedException(); + } catch (CustomizedInterruptedException e) { // Compliant + throw new InterruptedException(); + } + + try { + throwsInterruptedException(); + } catch (CustomizedInterruptedException e) { // Compliant + throw new CustomizedInterruptedException(); + } + + try { + throwsInterruptedException(); + } catch (CustomizedInterruptedException e) { // Noncompliant + throw new RuntimeException(); + } + } + + public void throwNewInterruptedExceptionFromFunction() throws InterruptedException { + + try { + throwsInterruptedException(); + } catch (CustomizedInterruptedException e) { // Compliant + interruptByThrowingInterruptedExceptionL4(); + } + + try { + throwsInterruptedException(); + } catch (CustomizedInterruptedException e) { // Compliant + interruptByThrowingInterruptedExceptionL3(); + } + + try { + throwsInterruptedException(); + } catch (CustomizedInterruptedException e) { // Compliant + interruptByThrowingInterruptedExceptionL2(); + } + + try { + throwsInterruptedException(); + } catch (CustomizedInterruptedException e) { // Noncompliant + interruptByThrowingInterruptedExceptionL1(); + } + } + + public void throwNewCustomizedInterruptedExceptionFromFunction() throws InterruptedException { + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Compliant + interruptByThrowingCustomizedInterruptedExceptionL4(); + } + + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Compliant + interruptByThrowingCustomizedInterruptedExceptionL3(); + } + + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Compliant + interruptByThrowingCustomizedInterruptedExceptionL2(); + } + + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Noncompliant + interruptByThrowingCustomizedInterruptedExceptionL1(); + } + } + + public void rethrowSameException() throws InterruptedException { + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Compliant + doSomething(); + throw e; + } + + RuntimeException re = new RuntimeException(); + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Noncompliant + doSomething(); + throw re; + } + + InterruptedException ie = new InterruptedException(); + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Compliant + throw ie; + } + + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Noncompliant + doSomething(); + throw getRuntimeException(); + } + + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Compliant + throw getInterruptedException(); + } + } + + public void cutControlFlow() throws InterruptedException { + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Noncompliant + + Object instance = new Object() { + void foo() { + Thread.currentThread().interrupt(); + } + + void bar() throws InterruptedException { + throw new InterruptedException(); + } + }; + } + + try { + throwsInterruptedException(); + } catch (InterruptedException e) { // Noncompliant + Runnable foo = () -> Thread.currentThread().interrupt(); + Action bar = () -> { + throw new InterruptedException(); + }; + } + } + + public void throwExceptionInTryDirectly() throws InterruptedException { + try { + throw new RuntimeException(); + } catch (Exception e) { // Compliant + } + + try { + throw new InterruptedException(); + } catch (Exception e) { // Noncompliant + } + + try { + InterruptedException ie = new InterruptedException(); + throw ie; + } catch (Exception e) { // Noncompliant + } + + try { + throw getInterruptedException(); + } catch (Exception e) { // Noncompliant + } + } + + void falsePositivesSonarjava4406() { + try { + try { + throwsInterruptedException(); + } catch (InterruptedException ie) { // Noncompliant + } + } catch (Exception e) { // Compliant, because inner try does not throw an InterruptedException + } + + try { + try { + throwsInterruptedException(); + } catch (InterruptedException ie) { // Compliant + Thread.currentThread().interrupt(); + } + } catch (Exception e) { // Compliant, because inner try does not throw an InterruptedException + } + + try { + try { + throwsInterruptedException(); + } catch (InterruptedException ie) { // Compliant + throw new InterruptedException(); + } + } catch (Exception e) { // Noncompliant + } + + try { + try { + throwsInterruptedException(); + } catch (InterruptedException ie) { // Compliant + throw new InterruptedException(); + } + } catch (InterruptedException e) { // Noncompliant + } + + try { + try { + throwsInterruptedException(); + } catch (RuntimeException ie) { // Compliant + } + } catch (Exception e) { // Noncompliant + } + + } + + public void throwInterruptedExceptionFromResourceList() throws InterruptedException { + try { + try(AutoCloseable autocloseable = getAutoCloseableThrowsInterruptedException()) { + doSomething(); + } catch (IOException ie) { + doSomething(); + } + } catch (Exception e) { // Noncompliant + } + } + + public void throwInterruptedExceptionWithinThrowStatement() throws InterruptedException { + try { + throw getRuntimeExceptionThrowsInterruptedException(); + } catch (Exception e) { // Noncompliant + } + } + + + public void catchUnionType1() throws IOException, InterruptedException { + try { + getRuntimeExceptionThrowsInterruptedException(); + getRuntimeExceptionThrowsIOException(); + } catch (InterruptedException | IOException e) { // Compliant - FP from SONARJAVA-4497 + doSomething(); + throw e; + } + } + + private AutoCloseable getAutoCloseableThrowsInterruptedException() throws InterruptedException { + throw getInterruptedException(); + } + + private RuntimeException getRuntimeExceptionThrowsInterruptedException() throws InterruptedException { + throw getInterruptedException(); + } + private RuntimeException getRuntimeExceptionThrowsIOException() throws IOException { + throw new IOException(); + } + + @FunctionalInterface + public interface Action { + void action() throws InterruptedException; + } + + private static RuntimeException getRuntimeException() { + return new RuntimeException(); + } + + private static InterruptedException getInterruptedException() { + return new InterruptedException(); + } + + private static void doSomething() { + } + + private static void interruptByThrowingInterruptedExceptionL1() throws InterruptedException { + interruptByThrowingInterruptedExceptionL2(); + } + + private static void interruptByThrowingInterruptedExceptionL2() throws InterruptedException { + interruptByThrowingInterruptedExceptionL3(); + } + + private static void interruptByThrowingInterruptedExceptionL3() throws InterruptedException { + interruptByThrowingInterruptedExceptionL4(); + } + + private static void interruptByThrowingInterruptedExceptionL4() throws InterruptedException { + throw new InterruptedException(); + } + + private static void interruptByThrowingCustomizedInterruptedExceptionL1() throws InterruptedException { + interruptByThrowingCustomizedInterruptedExceptionL2(); + } + + private static void interruptByThrowingCustomizedInterruptedExceptionL2() throws InterruptedException { + interruptByThrowingCustomizedInterruptedExceptionL3(); + } + + private static void interruptByThrowingCustomizedInterruptedExceptionL3() throws InterruptedException { + interruptByThrowingCustomizedInterruptedExceptionL4(); + } + + private static void interruptByThrowingCustomizedInterruptedExceptionL4() throws InterruptedException { + throw new CustomizedInterruptedException(); + } + + public static void throwsException() throws Exception { + throw new Exception(); + } + + public static void throwsInterruptedException() throws InterruptedException { + throw new InterruptedException(); + } + + private static class CustomizedInterruptedException extends InterruptedException { + } + +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InterruptedExceptionCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InterruptedExceptionCheckSample.textproto.gz new file mode 100644 index 00000000000..2fffca1e527 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/InterruptedExceptionCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IteratorNextExceptionCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IteratorNextExceptionCheckSample.expected.txt.gz new file mode 100644 index 00000000000..6a3e91a49b5 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IteratorNextExceptionCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IteratorNextExceptionCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IteratorNextExceptionCheckSample.java new file mode 100644 index 00000000000..d9a235e1f50 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IteratorNextExceptionCheckSample.java @@ -0,0 +1,352 @@ +package checks; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.ListIterator; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.PrimitiveIterator; + +class IteratorNextExceptionCheckSampleA implements Iterator { + + public String next() { // Noncompliant {{Add a "NoSuchElementException" for iteration beyond the end of the collection.}} +// ^^^^ + if (!hasNext()){ + return null; + } + return "x"; + } + @Override + public boolean hasNext() { + return false; + } +} + +class IteratorNextExceptionCheckSampleB implements Iterator { + + public String next() { // Noncompliant + if (!hasNext()){ + throw new IllegalStateException(); + } + return "x"; + } + @Override + public boolean hasNext() { + return false; + } +} + +class IteratorNextExceptionCheckSampleC implements Iterator { + + public String next() { + if (!hasNext()){ + throw new NoSuchElementException(); + } + return "x"; + } + + public String next(String argument) { + return "x"; + } + + public String notNext() { + return "x"; + } + + @Override + public boolean hasNext() { + return false; + } + +} + +class IteratorNextExceptionCheckSampleD implements Iterator { + + public String next() { // Noncompliant + if (!hasNext()){ + RuntimeException e = new RuntimeException(); + throw e; + } + return "x"; + } + + @Override + public boolean hasNext() { + return false; + } + +} + +class IteratorNextExceptionCheckSampleE { // Not an iterator + + public String next() { + if (!hasNext()){ + return null; + } + return "x"; + } + + public boolean hasNext() { + return false; + } + +} + +abstract class IteratorNextExceptionCheckSampleF implements Iterator{ + public abstract String next(); +} + +class IteratorNextExceptionCheckSampleG implements Iterator { + + private Iterator iter; + + public String next() { + return iter.next(); + } + + @Override + public boolean hasNext() { + return false; + } + +} + +class IteratorNextExceptionCheckSampleI implements Iterator { + + public String next() { // Noncompliant + return throwsIndexOutOfBoundsException(); + } + + public String throwsIndexOutOfBoundsException() throws IndexOutOfBoundsException { + throw new IndexOutOfBoundsException(); + } + + @Override + public boolean hasNext() { + return false; + } + +} + +class IteratorNextExceptionCheckSampleJ implements Iterator { + public String next() { + if (!hasNext()){ + throw new NoSuchElementException(); + } + return "x"; + } + @Override + public boolean hasNext() { + return false; + } +} +class IteratorNextExceptionCheckSampleK implements Iterator { + IteratorNextExceptionCheckSampleJ a; + public String next() { + return a.next(); // Compliant + } + @Override + public boolean hasNext() { + return false; + } +} + +abstract class IteratorNextExceptionCheckSampleL implements Iterator { + @Override + public String next() { // Compliant + return getOptional().orElseThrow(NoSuchElementException::new); + } + + Optional getOptional() { + return Optional.empty(); + } +} + +class IteratorNextExceptionCheckSampleM implements Iterator { + ListIterator a; + public String next() { + return a.previous(); // Compliant + } + @Override + public boolean hasNext() { + return a.hasPrevious(); + } +} + +class IteratorNextExceptionCheckSampleM2 implements PrimitiveIterator.OfInt { + Iterator iterator; + @Override + public int nextInt() { + return iterator.next().hashCode(); // Compliant + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } +} + +/** + * FALSE POSITIVE below. We currently are not able to tell which methods outside of this file (like `removeFirst`) + * can throw `NoSuchElementException`. The case below is actually compliant. + */ +class IteratorNextExceptionCheckSampleM3 implements Iterator { + LinkedList list; + @Override + public String next() { // Noncompliant + return list.removeFirst(); + } + + @Override + public boolean hasNext() { + return list.isEmpty(); + } +} + +class IteratorNextExceptionCheckSampleN implements Iterator { + PrimitiveIterator.OfDouble a; + public Double next() { + return a.nextDouble(); // Compliant + } + @Override + public boolean hasNext() { + return a.hasNext(); + } +} + +class IteratorNextExceptionCheckSampleO implements Iterator { + private int count = 10; + + public String next() { // Compliant + return getNext(); + } + + private String getNext() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + return "hello"; + } + + public static void justThrow() { + throw new NoSuchElementException(); + } + + @Override + public boolean hasNext() { + count--; + return count > 0; + } + +} + +class IteratorNextExceptionCheckSampleP implements Iterator { + private T elem; + + public T next() { // Compliant + if (!hasNext()) { + IteratorNextExceptionCheckSampleO.justThrow(); + } + return elem; + } + + @Override + public boolean hasNext() { + return false; + } + +} + +class IteratorNextExceptionCheckSampleQ implements Iterator { + private T elem; + + public T next() { // Compliant + if (!hasNext()) { + class Foo extends NoSuchElementException {} + throw new Foo(); + } + return elem; + } + + @Override + public boolean hasNext() { + return false; + } + +} + +class IteratorNextExceptionCheckSampleR implements Iterator { + public T next() { // Noncompliant + return recurseA(); + } + + public T recurseA() { + return recurseB(); + } + + public T recurseB() { + return recurseA(); + } + + @Override + public boolean hasNext() { + return false; + } + +} + +class IteratorNextExceptionCheckSampleS implements Iterator { + private T elem; + + public T next() { // Compliant + return a(); + } + + private T a() { + return b(); + } + + private T b() { + return false ? c() : d(); + } + + private T c() { + return elem; + } + + private T d() { + throw new NoSuchElementException(); + } + + @Override + public boolean hasNext() { + return false; + } + +} + +/** + * FALSE NEGATIVE below. We currently do not handle try-catch statements. In the example below, the expected exception + * is caught when it should not be. The example is actually non-compliant + */ +class IteratorNextExceptionCheckSampleT implements Iterator { + private T elem; + + public T next() { // Compliant, FN + try { + return getNext(); + } catch (NoSuchElementException e) { + return elem; + } + } + + private T getNext() { + throw new NoSuchElementException(); + } + + @Override + public boolean hasNext() { + return false; + } + +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IteratorNextExceptionCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IteratorNextExceptionCheckSample.textproto.gz new file mode 100644 index 00000000000..65c1c7eb1ca Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/IteratorNextExceptionCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/MembersDifferOnlyByCapitalizationCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/MembersDifferOnlyByCapitalizationCheckSample.expected.txt.gz new file mode 100644 index 00000000000..1009265eb83 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/MembersDifferOnlyByCapitalizationCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/MembersDifferOnlyByCapitalizationCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/MembersDifferOnlyByCapitalizationCheckSample.java new file mode 100644 index 00000000000..6ee21215aef --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/MembersDifferOnlyByCapitalizationCheckSample.java @@ -0,0 +1,208 @@ +package checks; + +class MembersDifferOnlyByCapitalizationCheckSample { + +abstract class A implements MyInterface { + private static final long var1 = -9215047833775013803L; // Compliant + public long var2 = 0L; + + public void equAls(Object obj) {} // Noncompliant {{Rename method "equAls" to prevent any misunderstanding/clash with method "equals" defined in superclass "java.lang.Object".}} + + protected void finaliZe() {} // Noncompliant {{Rename method "finaliZe" to prevent any misunderstanding/clash with method "finalize" defined in superclass "java.lang.Object".}} + + public void myMethod() {} + + public Object stuff; +// ^^^^^> + public void stuff() {} // Noncompliant {{Rename method "stuff" to prevent any misunderstanding/clash with field "stuff".}} + // ^^^^^ + public void stuff(int i) {} // Noncompliant {{Rename method "stuff" to prevent any misunderstanding/clash with field "stuff".}} + + public void foo(int i) {} // Compliant + public void foo(boolean i) {} // Compliant + + public void myOtherMethoD() {} // Noncompliant {{Rename method "myOtherMethoD" to prevent any misunderstanding/clash with method "myOtherMethod" defined in interface "checks.MembersDifferOnlyByCapitalizationCheckSample$MyInterface".}} +// ^^^^^^^^^^^^^ + private static void gUl() {} // Noncompliant {{Rename method "gUl" to prevent any misunderstanding/clash with method "gul".}} + //^^^ + public void gul() {} // Compliant +// ^^^< + + private boolean qix; + + public Object myField; // Noncompliant + @Override public void myField() {} // Compliant, as it overrides the parent interface method + + public A() {} + class MyInnerClass {} + ; + + public void SUPER() {} // Compliant + public void tHiS() {} // Compliant + +} + +interface MyInterface { + public boolean myOtherMethod(); + public void gul(); + public void myField(); +} + +abstract class B extends A { + private static final long var1 = -9215047833775013803L; // Compliant + public void var2() {}; // Noncompliant +// ^^^^> + public void vAr2() {}; // Noncompliant + //^^^^ + + public void myMethoD() {} // Noncompliant {{Rename method "myMethoD" to prevent any misunderstanding/clash with method "myMethod" defined in superclass "checks.MembersDifferOnlyByCapitalizationCheckSample$A".}} + + public Object qix; // Compliant + + public void fOo(int i) {} // Noncompliant +} + +class Visibility { + public int tmp0; +// ^^^^> + private void tmp0() {} + public void tmp0(int i) {} // Noncompliant {{Rename method "tmp0" to prevent any misunderstanding/clash with field "tmp0".}} + // ^^^^ + protected void tmp0(long l) {} + void tmp0(short s) {} + + private int tmp1; + private void tmp1() {} // Compliant - private members having same name are ignored + public void tmp1(int i) {} + protected void tmp1(long l) {} + void tmp1(short s) {} + + int tmp2; +// ^^^^> + private void tmp2() {} + public void tmp2(int i) {} + protected void tmp2(long l) {} + void tmp2(short s) {} // Noncompliant {{Rename method "tmp2" to prevent any misunderstanding/clash with field "tmp2".}} + // ^^^^ + + protected int tmp3; +// ^^^^> + private void tmp3() {} + public void tmp3(int i) {} + protected void tmp3(long l) {} // Noncompliant {{Rename method "tmp3" to prevent any misunderstanding/clash with field "tmp3".}} + // ^^^^ + void tmp3(short s) {} +} + +public enum MyEnum { + FOO; + + public void foo() {} // Compliant + public static MyEnum valueof(int i) { return FOO; } // Noncompliant {{Rename method "valueof" to prevent any misunderstanding/clash with method "valueOf".}} +} + +class ABuilder { + String name; + String wrong; +// ^^^^^> + String value; + + ABuilder name(String name) { // Compliant - exception for builder pattern + this.name = name; + return this; + } + + ABuilder WRONG(String wrong) { // Noncompliant + // ^^^^^ + this.wrong = value; + return this; + } +} + + +class SameName { + Object m; + Object f1, f2, f3; + Object flambda; + Object fAnon; + + Object m() { // Compliant + return m; + } + + Object M() { // Noncompliant + return m; + } + + Object f1() { // Noncompliant + return new Object(); + } + + void f2() { // Noncompliant + return; + } + + Object flambda() { // Compliant + call(f -> { + return new Object(); + }); + return flambda; + } + + void call(java.util.function.Function o) {} + + Object fAnon() { // Compliant + Object o = new Object() { + public String toString() { + return ""; + } + }; + return fAnon; + } + + Object foo; + void foo() { // Noncompliant + SameName sn = new SameName() { + Object bar() { + return foo; + } + }; + } + + boolean cond; + + Object f3() { // Noncompliant + if (cond) { + return new Object(); + } + return f3; + } +} + + record MyRecord(int intComponent, boolean bool) { + + public static final boolean BooL = false; // Noncompliant {{Rename field "BooL" to prevent any misunderstanding/clash with field "bool".}} + + @Override public boolean bool() { + return bool; + } + + public int intCOMPONENT() { // Noncompliant {{Rename method "intCOMPONENT" to prevent any misunderstanding/clash with method "intComponent".}} + return intComponent; + } + } + + Object subClass; // Compliant + class subClass { } + + class NoDuplications { + void Abcde(){ } +// ^^^^^> + void aBcde(){ } // Noncompliant {{Rename method "aBcde" to prevent any misunderstanding/clash with method "Abcde".}} + // ^^^^^ + void abCde(){ } // Noncompliant {{Rename method "abCde" to prevent any misunderstanding/clash with method "Abcde".}} + void abcDe(){ } // Noncompliant {{Rename method "abcDe" to prevent any misunderstanding/clash with method "Abcde".}} + void abcdE(){ } // Noncompliant {{Rename method "abcdE" to prevent any misunderstanding/clash with method "Abcde".}} + } + +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/MembersDifferOnlyByCapitalizationCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/MembersDifferOnlyByCapitalizationCheckSample.textproto.gz new file mode 100644 index 00000000000..c0bcbb738c1 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/MembersDifferOnlyByCapitalizationCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/PrintfFailCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/PrintfFailCheckSample.expected.txt.gz new file mode 100644 index 00000000000..fec92de20d1 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/PrintfFailCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/PrintfFailCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/PrintfFailCheckSample.java new file mode 100644 index 00000000000..69b66002aff --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/PrintfFailCheckSample.java @@ -0,0 +1,301 @@ +package checks; + +import java.io.PrintStream; +import java.io.PrintWriter; +import java.text.FieldPosition; +import java.text.MessageFormat; +import java.util.Calendar; +import java.util.Formatter; +import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.stream.IntStream; + +public class PrintfFailCheckSample { + void foo(Calendar c) throws java.io.IOException { + Object myObject = new Object(); + Object[] objs = new Object[]{14}; + Locale loc = Locale.US; + // String format =================================================================================================== + double value = 1.0; + String.format("The value of my integer is %d", "Hello World"); // Noncompliant {{An 'int' is expected rather than a String.}} + String.format("First {0} and then {1}", "foo", "bar"); + String.format("Duke's Birthday year is %tX", 12l); // Noncompliant {{X is not a supported time conversion character}} + String.format("Display %3$d and then %d", 1, 2, 3); + String.format("Too many arguments %d and %d", 1, 2, 3); + String.format("Not enough arguments %d and %d", 1); // Noncompliant {{Not enough arguments.}} + String.format("%1$d %2$d %9$-3.3s", 1, 2, "hello"); // Noncompliant {{Not enough arguments to feed formater at index 9: '%9$'.}} + String.format("%12$s", 1, 2, "hello"); // Noncompliant {{Not enough arguments to feed formater at index 12: '%12$'.}} + String.format("First Line\n %d", 1); + String.format("First Line"); + String.format("First Line%%"); + String.format("First Line%n"); // Compliant + String.format("%< is equals to %d", 2); // Noncompliant {{The argument index '<' refers to the previous format specifier but there isn't one.}} + String.format("Is myObject null ? %b", myObject); + String.format("value is " + value); // Compliant + String.format("string without arguments"); + String.format("%d %d", new Object[]{1,2}); // Compliant + String.format("%d %d", new Object[]{1,2,3}); // Compliant, too many arguments but no errors, reported by S3457 + String.format("%d %d", new Object[]{1}); // Noncompliant {{Not enough arguments.}} + String.format("%d %d", objs); // Compliant, not initialized inside the call + String.format("%d %d", new Object[42]); // Compliant + String.format("%d%d", IntStream.range(0, 2).mapToObj(Integer::valueOf).toArray()); // Compliant + String.format("%d%d", IntStream.range(0, 1).mapToObj(Integer::valueOf).toArray()); // FN, acceptable to avoid noise + String.format("%d%d", IntStream.range(0, 2).mapToObj(Integer::valueOf).toArray(Object[]::new)); // Compliant + String.format("Result %s %s",new Exception(),new Exception(),new Exception()); // Compliant, reported by S3457 + String.format("Result %s %s",new Object[] {new Exception(),new Exception(),new Exception()}); // Compliant, reported by S3457 + String.format("Result %s %s",new Exception(),new Exception()); // Compliant + String.format("Result %s %s",new Object[] {new Exception(),new Exception()}); // Compliant + String.format("Result %s %s",new Exception()); // Noncompliant {{Not enough arguments.}} + String.format("Result %s %s",new Object[] {new Exception()}); // Noncompliant {{Not enough arguments.}} + String.format("%s " + value, new Exception()); // Compliant, reported by S3457 + String.format("%s " + value); // Compliant, reported by S3457 + + String.format("Too many arguments %d and %d and %d", 1, 2, 3, 4); + String.format("normal %d%% ", 1); //Compliant + String.format("Duke's Birthday year is %t", 12l); // Noncompliant {{Time conversion requires a second character.}} + String.format("Duke's Birthday year is %tH", 12l); // Compliant + String.format("Duke's Birthday year is %tH", Long.valueOf(12L)); // Compliant + String.format("Duke's Birthday year is %tH", loc); // Noncompliant {{Time argument is expected (long, Long, Calendar, Date and TemporalAccessor).}} + String.format("%08d%n", 1); + GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance(); + String.format("Duke's Birthday year is %tH", gc); + // Noncompliant@+1 + String.format("Duke's Birthday year is %t", loc); // Noncompliant + String.format("Accessed before %tF%n", java.time.LocalDate.now()); // Compliant + System.out.printf("%1$ty_%1$tm_%1$td_%1$tH_%1$tM_%1$tS", java.time.LocalDateTime.now()); // Compliant + + String.format("Dude's Birthday: %1$tm % "Result " + value); // Compliant + + // slf4jLog ======================================================================================================== + // slf4jLog is a facade, various logging frameworks can be used under it. It implies that we will only report issues when + // there are obvious mistakes, not when it depends on the underlying framework (even if it works correctly with the common one). + org.slf4j.Logger slf4jLog = org.slf4j.LoggerFactory.getLogger(""); + org.slf4j.Marker marker = org.slf4j.MarkerFactory.getMarker(""); + + slf4jLog.debug(marker, "message {}"); // Compliant, wrong string formatting but no error: will be reported by S3457 + slf4jLog.debug(marker, "message ", 1); + slf4jLog.debug(marker, "message {}", 1); + slf4jLog.debug(marker, "message {} - {}", 1, 2); + slf4jLog.debug(marker, "message {}", 1, 2); + slf4jLog.debug(marker, "message {} {} {}", 1, 2, 3); + slf4jLog.debug(marker, "message {} {}", 1, 2, 3); + slf4jLog.debug(marker, "message {} {}", new Object[]{1, 2, 3}); + slf4jLog.debug(marker, "message {} {} {}", new Object[]{1, 2, 3}); + slf4jLog.debug(marker, "message {} {} {}", new Object[]{1, 2}); // Compliant, wrong string formatting but no error: will be reported by S3457 + slf4jLog.debug(marker, "message ", new Exception()); + slf4jLog.debug(marker, "message {}", new Exception()); // Compliant, wrong string formatting but no error: will be reported by S3457 + slf4jLog.debug(marker, "message {}", new Exception().toString()); + + + slf4jLog.debug("message {}"); // Compliant, wrong string formatting but no error: will be reported by S3457 + slf4jLog.debug("message ", 1); + slf4jLog.debug("message {}", 1); + slf4jLog.debug("message {} - {}", 1, 2); + slf4jLog.debug("message {}", 1, 2); + slf4jLog.debug("message {} {} {}", 1, 2, 3); + slf4jLog.debug("message {} {}", 1, 2, 3); + slf4jLog.debug("message {} {}", new Object[]{1, 2, 3}); + slf4jLog.debug("message {} {} {}", new Object[]{1, 2, 3}); + slf4jLog.debug("message ", new Exception()); + slf4jLog.debug("message {}", new Exception()); // Compliant, wrong string formatting but no error: will be reported by S3457 + slf4jLog.debug("message {}", new Exception().toString()); + + slf4jLog.error("message {}"); // Compliant, wrong string formatting but no error: will be reported by S3457 + slf4jLog.error("message {}", new Exception()); // Compliant, wrong string formatting but no error: will be reported by S3457 + slf4jLog.error("message {}", new Exception().toString()); + slf4jLog.error("message ", 1); + slf4jLog.error("message {}", 1); + slf4jLog.error("message {} {}", 1); // Compliant, wrong string formatting but no error: will be reported by S3457 + slf4jLog.error("message {} {}", 1, new Exception()); // Compliant, wrong string formatting but no error: will be reported by S3457 + slf4jLog.error("message {} {}", 1, new Exception().toString()); + slf4jLog.info("message {} - {}", 1, 2); + slf4jLog.info("message {}", 1, 2); + slf4jLog.info("message {} {} {}", 1, 2, 3); + slf4jLog.info("message {}", new Exception()); // Compliant, wrong string formatting but no error: will be reported by S3457 + slf4jLog.trace("message {} {}", 1, 2, 3); + slf4jLog.trace("message {} {}", new Object[]{1, 2, 3}); + slf4jLog.trace("message {} {} {}", new Object[]{1, 2, 3}); + slf4jLog.trace("message ", new Exception()); + slf4jLog.trace("message {}", new Exception()); // Compliant, wrong string formatting but no error: will be reported by S3457 + slf4jLog.warn("message {}"); // Compliant, wrong string formatting but no error: will be reported by S3457 + slf4jLog.warn("message ", 1); + slf4jLog.warn("message {}", 1); + slf4jLog.warn("Output on the error channel detected: this is probably due to a problem on pylint's side."); + slf4jLog.warn("message {}", new Exception()); // Compliant, wrong string formatting but no error: will be reported by S3457 + String fileKey = "key"; + slf4jLog.warn("The resource for '{}' is not found, drilling down to the details of this test won't be possible", fileKey); + slf4jLog.warn("The resource for is not found, drilling down to the details of this test won't be possible"); + + slf4jLog.error("message: " + value); // Compliant, reported by S3457 + slf4jLog.error("message: {}" + value, value); // Compliant, reported by S3457 + slf4jLog.error("message:" + value, new Exception()); // Compliant + slf4jLog.error("message: {}", value, new Exception()); // Compliant + + // log4j =========================================================================================================== + org.apache.logging.log4j.Logger log4j = org.apache.logging.log4j.LogManager.getLogger(); + log4j.log(org.apache.logging.log4j.Level.DEBUG, "message"); // Compliant + log4j.log(org.apache.logging.log4j.Level.DEBUG, "message {}"); // Compliant, wrong string formatting but no error: will be reported by S3457 + log4j.log(org.apache.logging.log4j.Level.DEBUG, "message {}", new Exception()); // Compliant, wrong string formatting but no error: will be reported by S3457 + log4j.log(org.apache.logging.log4j.Level.DEBUG, "message {}", 1); // Compliant + log4j.log(org.apache.logging.log4j.Level.DEBUG, "message {} {}", 1); // Compliant, wrong string formatting but no error: will be reported by S3457 + log4j.log(org.apache.logging.log4j.Level.DEBUG, "message %d", 1); // Compliant + log4j.log(org.apache.logging.log4j.Level.DEBUG, "message %d %s", 1, "hello"); // Compliant + + log4j.debug("message"); // Compliant + log4j.debug("message {} {}", 1); // Compliant, wrong string formatting but no error: will be reported by S3457 + log4j.error("message {}", new Exception()); // Compliant, wrong string formatting but no error: will be reported by S3457 + log4j.error("message {} {}", 1, new Exception()); // Compliant, wrong string formatting but no error: will be reported by S3457 + log4j.error("message {} {}", 1, new Exception().toString()); + log4j.error("message {} {}", 1, 2, 3); // Compliant, detected by S3457 "3rd argument is not used." + log4j.error("message {} {}", 1, 2, new Exception().toString()); // Compliant, detected by S3457 "3rd argument is not used." + log4j.error("message ", () -> 1); // Compliant, detected by S3457 "String contains no format specifiers." + log4j.error("message {}", () -> 1); + log4j.error("message {} {}", () -> 1); // Compliant, wrong string formatting but no error: will be reported by S3457 + String param1 = "abc"; + log4j.error(() -> "message " + param1); + log4j.error(() -> "message " + param1, new Exception()); + + log4j.fatal("message {} {}", 1); // Compliant, wrong string formatting but no error: will be reported by S3457 + log4j.info("message {} {}", 1); // Compliant, wrong string formatting but no error: will be reported by S3457 + log4j.trace("message {} {}", 1); // Compliant, wrong string formatting but no error: will be reported by S3457 + log4j.warn("message {} {}", 1); // Compliant, wrong string formatting but no error: will be reported by S3457 + log4j.warn("message {} {} {}", 1, 2); // Compliant, wrong string formatting but no error: will be reported by S3457 + + log4j.debug(() -> "hello"); // Compliant + log4j.debug("message {}", 1); // Compliant + log4j.debug("message {}", () -> 1); // Compliant + log4j.debug("message %s message %d", "hello", "world"); // Compliant, wrong string formatting but no error: will be reported by S3457 + log4j.debug("message %s message %d %s", "hello", 42); // Compliant, wrong string formatting but no error: will be reported by S3457 + + log4j.printf(org.apache.logging.log4j.Level.DEBUG, "message %s %d", "hello", 42); // Compliant - Java formatters + + log4j.error("message: " + value); // Compliant, reported by S3457 + log4j.error("message: {}" + value, value); // Compliant, reported by S3457 + log4j.error("message:" + value, new Exception()); // Compliant, reported by S3457 + log4j.error("message: {}", value, new Exception()); // Compliant + + String.format("%2147483648$g", 42.0); // Noncompliant {{Not enough arguments to feed formater at index 2147483647: '%2147483648$'.}} + String.format("%2147483648g", 42.0); // Compliant + String.format("%.2147483648g", 42.0); // Compliant + String.format("%1000000000000$g", 42.0); // Noncompliant {{Not enough arguments to feed formater at index 2147483647: '%1000000000000$'.}} + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/PrintfFailCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/PrintfFailCheckSample.textproto.gz new file mode 100644 index 00000000000..69bdc4a2a72 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/PrintfFailCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantThrowsDeclarationCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantThrowsDeclarationCheckSample.expected.txt.gz new file mode 100644 index 00000000000..d84e4656f2b Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantThrowsDeclarationCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantThrowsDeclarationCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantThrowsDeclarationCheckSample.java new file mode 100644 index 00000000000..5245cffe9e8 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantThrowsDeclarationCheckSample.java @@ -0,0 +1,435 @@ +package checks; + +import java.io.IOException; +import java.text.ParseException; + +public class RedundantThrowsDeclarationCheckSample { + + public void foo1() { + } + + public void foo2() throws Throwable { + } + + public void foo3() throws Error { + } + + public void foo4() throws MyException { + } + + public void foo5() throws RuntimeException { // Compliant + } + + public void foo6() throws IllegalArgumentException { // Compliant + } + + public void foo7() throws MyRuntimeException { // Compliant + } + + public void foo8() throws MyException, Exception { // Noncompliant {{Remove the declaration of thrown exception 'checks.RedundantThrowsDeclarationCheckSample$MyException' which is a subclass of 'java.lang.Exception'.}} [[quickfixes=qf_first]] +// ^^^^^^^^^^^ + // fix@qf_first {{Remove "MyException"}} + // edit@qf_first [[sc=29;ec=42]] {{}} + } + + public void foo9() throws Error, Throwable { // Noncompliant {{Remove the declaration of thrown exception 'java.lang.Error' which is a subclass of 'java.lang.Throwable'.}} + } + + public void foo11() throws MyException, MyException { // Noncompliant {{Remove the redundant 'checks.RedundantThrowsDeclarationCheckSample$MyException' thrown exception declaration(s).}} + } + + public void foo12() throws MyException, MyException, Throwable { // Noncompliant {{Remove the declaration of thrown exception 'checks.RedundantThrowsDeclarationCheckSample$MyException' which is a subclass of 'java.lang.Throwable'.}} + } + + public void foo13() throws MyRuntimeException, MyRuntimeException { // Noncompliant {{Remove the redundant 'checks.RedundantThrowsDeclarationCheckSample$MyRuntimeException' thrown exception declaration(s).}} + } + + public void foo14() throws MyRuntimeException, Throwable { // Compliant - being explicit with the runtime + } + + public void foo15() throws Exception, Error { + } + + public class MyException extends Exception { + } + + public class MyRuntimeException extends RuntimeException { + } + + interface MyInterface { + T plop() throws IllegalStateException; // Compliant + } + + static class MyClass implements MyInterface { + @Override + public String plop() { + return ""; + } + } +} + +abstract class MySuperClass { + abstract void foo() throws MyException; +} + +abstract class ThrownCheckedExceptions extends MySuperClass { + public ThrownCheckedExceptions(String s) throws MyException { // Noncompliant {{Remove the declaration of thrown exception 'checks.MyException', as it cannot be thrown from constructor's body.}} [[quickfixes=qf_all_throws]] +// ^^^^^^^^^^^ + // fix@qf_all_throws {{Remove "MyException"}} + // edit@qf_all_throws [[sc=43;ec=62]] {{}} + bar(); + } + + @Override + void foo() throws MyException { //Compliant - Override + bar(); + } + + void foo0() throws MyException { // Noncompliant {{Remove the declaration of thrown exception 'checks.MyException', as it cannot be thrown from method's body.}} + bar(); + } + + void foo3() throws MyException { // Noncompliant {{Remove the declaration of thrown exception 'checks.MyException', as it cannot be thrown from method's body.}} + new MyClass() { + void foo() throws MyException { + throw new MyException(); + } + }; + } + + void foo4() throws MyException { // Noncompliant + gul(o -> { throw new RuntimeException(); }); + } + + void foo5() throws MyException { // Compliant + bar(); + mok(); + } + + void foo6() { // Compliant + puf(); + kal(); + } + + void foo7() throws MyException { // Compliant - False-Negative - studying control flow is not done + try { + mok(); + } catch(MyException e) { + // do nothing + } + } + + void foo8(Throwable t) throws java.io.IOException { // Compliant + throwIfException(t, java.io.IOException.class); + } + + void foo9(int i) throws MyException { + new MyOtherClass(i); + } + + protected Object readResolve() throws java.io.ObjectStreamException { // Compliant - Serializable contract + return null; + } + + int foo9() throws MyException { // Compliant - designed for extension + return 0; + } + + public int foo10() throws MyException { // Compliant - designed for extension + throw new UnsupportedOperationException(); + } + + private int foo11() throws MyException { // Noncompliant + return 0; + } + + Object foo12() throws MyException { // Noncompliant + return new Object(); + } + + void foo13() throws MyException { // Compliant - designed for extension + return; + } + + void foo14(java.io.File file) throws java.io.IOException { // Compliant - Closeable.close() throws IOException + try (java.io.FileInputStream fis = new java.io.FileInputStream(file)) { + // do something + } + } + + void foo15(java.io.File file) throws Exception { // Compliant - AutoCloseable.close() throws Exception + try (AutoCloseable ac = getAutoCloseableWithoutExceptionPlease(file)) { + // do something + } + } + + void foo16(java.io.File file) throws MyException { // Noncompliant {{Remove the declaration of thrown exception 'checks.MyException', as it cannot be thrown from method's body.}} + try (MyAutoCloseable mac = getAutoCloseableWithoutExceptionPlease(file)) { + // do something + } + } + + void foo17(java.io.File file) throws java.io.IOException { // Compliant MyCloseable inherits from Closeable + try (MyCloseable mac = getMyCloseable(file)) { + // do something + } + } + + void foo18(java.io.File file) throws IOException, ParseException { // Noncompliant {{Remove the declaration of thrown exception 'java.text.ParseException', as it cannot be thrown from method's body.}} [[quickfixes=qf_last]] +// ^^^^^^^^^^^^^^ + // fix@qf_last {{Remove "ParseException"}} + // edit@qf_last [[sc=51;ec=67]] {{}} + try (MyCloseable mac = getMyCloseable(file)) { + // do something + } + } + + void foo20(java.io.File file) throws ParseException { // Compliant - AutoCloseableParserInterface.close() throws ParseException + try (AutoCloseableParserInterface mac = getAutoCloseableInterfaceWithParseException(file)) { + // do something + } + } + + void foo21(java.io.File file) throws ParseException { // Compliant - AutoCloseableParserClass.close() throws ParseException + try (AutoCloseableParserClass mac = getAutoCloseableClassWithParseException(file)) { + // do something + } + } + + abstract void bar(); + abstract void gul(java.util.function.Function s); + abstract void mok() throws MyException; + abstract void puf() throws MyError; + abstract void kal() throws MyRuntimeException; // Compliant + abstract void throwIfException(Throwable t, Class declaredType) throws X; + static class MyClass { } + static class MyOtherClass { + public MyOtherClass(int i) throws MyException { } + } + + abstract MyAutoCloseable getAutoCloseableWithoutExceptionPlease(java.io.File file); + abstract MyCloseable getMyCloseable(java.io.File file); + abstract AutoCloseableParserInterface getAutoCloseableInterfaceWithParseException(java.io.File file); + abstract AutoCloseableParserClass getAutoCloseableClassWithParseException(java.io.File file); + interface MyAutoCloseable extends AutoCloseable { + @Override + void close(); // override which does not throw 'java.lang.Exception' + } + interface MyCloseable extends java.io.Closeable { + } + interface AutoCloseableParserInterface extends AutoCloseable { + @Override + void close() throws ParseException; + } + static class AutoCloseableParserClass implements AutoCloseable { + int close = 2; + public void close(int i) { + } + @Override + public void close() throws ParseException { + throw new ParseException("", 0); + } + } + + interface MyOtherInterface { + Object foo(Object o) throws MyException; // Compliant + + default Object bar(Object o) throws MyException { // Compliant - default method are also defining a contract + return o; + } + + default Object qix(Object o) throws MyException, MyException { // Noncompliant + return o; + } + } +} + +class MyException extends Exception {} +class MyError extends Error {} +class MyRuntimeException extends RuntimeException {} +class MyException2 extends Exception {} + +abstract class NonThrownExceptionClass { + abstract void bar(); + + static void qix() { + } + + final class FinalClass { + + /** + * @throws MyException proper javadoc description + */ + void nonOverrideableMethod() throws MyException { // Noncompliant {{Remove the declaration of thrown exception 'checks.MyException', as it cannot be thrown from method's body.}} + bar(); + } + } + + static class NormalClass { + + void bar() {} + + /** + * @exception MyException proper javadoc description + */ + private void nonOverrideableMethod1() throws MyException { // Noncompliant {{Remove the declaration of thrown exception 'checks.MyException', as it cannot be thrown from method's body.}} + bar(); + } + + /** + * @throws MyException proper javadoc description + */ + static void nonOverrideableMethod2() throws MyException { // Noncompliant {{Remove the declaration of thrown exception 'checks.MyException', as it cannot be thrown from method's body.}} + qix(); + } + + /** + * @throws MyException proper javadoc description + */ + final void nonOverrideableMethod3() throws MyException { // Noncompliant {{Remove the declaration of thrown exception 'checks.MyException', as it cannot be thrown from method's body.}} + bar(); + } + + /** + * @throws MyException proper javadoc description + */ + void overrideableMethod1() throws MyException { // Compliant : can be overridden and has javadoc associated + bar(); + } + + /** + * @throws MyException proper javadoc description + */ + protected void overrideableMethod2() throws MyException { // Compliant : can be overridden and has javadoc associated + bar(); + } + + /** + * @exception MyException proper javadoc description + */ + public void overrideableMethod3() throws MyException { // Compliant : can be overridden and has javadoc associated + bar(); + } + + /** + * Overridable method but javadoc for exception is missing proper description + * @exception MyException + */ + public void overrideableMethod4() throws MyException { // Noncompliant + bar(); + } + + /** + * @exception MyException proper javadoc description + * @throws MyException2 proper javadoc description + */ + public void missingJavadocForException() throws MyException, java.io.IOException, MyException2 { // Noncompliant {{Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body.}} [[quickfixes=qf_middle]] +// ^^^^^^^^^^^^^^^^^^^ + // fix@qf_middle {{Remove "IOException"}} + // edit@qf_middle [[sc=66;ec=87]] {{}} + bar(); + } + } +} + +class RedundantThrowsDeclarationParent { + public RedundantThrowsDeclarationParent() throws IllegalAccessException { // Compliant + throw new IllegalAccessException(); + } + + public RedundantThrowsDeclarationParent(String a) { + } + + public RedundantThrowsDeclarationParent(String a, String b) throws IllegalAccessException { // Compliant + foo(); + } + + private void foo() throws IllegalAccessException { + throw new IllegalAccessException(); + } +} + +class RedundantThrowsDeclarationChild extends RedundantThrowsDeclarationParent { + + public RedundantThrowsDeclarationChild(Integer a) throws IllegalAccessException { // Compliant, implicit call can throw IllegalAccessException + // implicit call to parent constructor + System.out.println("a:" + a); + } + + public RedundantThrowsDeclarationChild(Long a) throws IllegalAccessException { // Compliant, equivalent to "Child(Integer a)" + super(); + System.out.println("a:" + a); + } + + public RedundantThrowsDeclarationChild(Float a) throws IllegalAccessException { // Noncompliant + this(4.2, 4.2); + System.out.println("a:" + a); + } + + public RedundantThrowsDeclarationChild(Double a) throws IllegalAccessException { // Noncompliant + super("a:" + a); + System.out.println("a:" + a); + } + + public RedundantThrowsDeclarationChild(Integer a, Integer b) throws IllegalAccessException { // Compliant, call to Parent that calls foo, that thows IllegalAccessException + super("a:" + a, " b:" + a); + System.out.println("a:" + a); + } + + public RedundantThrowsDeclarationChild(Double d1, Double d2) { + super("a"); + } +} + +class RedundantThrowsDeclarationA { + class Parent1 { + public Parent1() throws IllegalAccessException { // Compliant + throw new IllegalAccessException(); + } + public Parent1(String a) { // Compliant + } + } + + class Child1 extends Parent1 { + public Child1(Long a) throws IllegalAccessException { // Noncompliant + RedundantThrowsDeclarationA.this.super("a:" + + a); + } + } +} + +class RedundantThrowsDeclarationB { + class Parent2{ + public Parent2() throws IllegalAccessException { // Compliant + throw new IllegalAccessException(); + } + public Parent2(String a) { // Compliant + } + } + + class Child2 extends Parent2 { + public Child2(Long a) throws IllegalAccessException { // Compliant + //implicit call to Parent2. Parent2() will have an implicit parameter A + System.out.println("a:" + a); + } + } +} + +class StrangeException { + T t; + + private void foo() throws T { // Compliant + throw t; + } + + void bar() throws IOException { + new StrangeException().foo(); + } +} + +enum RedundantThrowsDeclarationMyEnum { + AAA(7), BBB(2); + + RedundantThrowsDeclarationMyEnum(int i) throws RuntimeException { + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantThrowsDeclarationCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantThrowsDeclarationCheckSample.textproto.gz new file mode 100644 index 00000000000..85e7a73ae39 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantThrowsDeclarationCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantTypeCastCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantTypeCastCheckSample.expected.txt.gz new file mode 100644 index 00000000000..ebc76552a73 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantTypeCastCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantTypeCastCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantTypeCastCheckSample.java new file mode 100644 index 00000000000..9cf199d59e4 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantTypeCastCheckSample.java @@ -0,0 +1,512 @@ +package checks; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.function.Predicate; + +class Outer { + class Nested { + } + class ExtendedNested extends Nested { } + List list; + List foo() { + Object obj = null; + Object o1 = (List) foo(); // Noncompliant {{Remove this unnecessary cast to "List".}} [[quickfixes=qf1]] +// ^^^^^^^^^^^^^^ + // fix@qf1 {{Remove the cast to "List"}} + // edit@qf1 [[sc=17;ec=32]] {{}} + Object o2 = (List) foo(); // Noncompliant {{Remove this unnecessary cast to "List".}} + Object o3 = (List) foo(); // Noncompliant {{Remove this unnecessary cast to "List".}} + String s1 = (String) obj; // Compliant + String s2 = (String) s1; // Noncompliant {{Remove this unnecessary cast to "String".}} + Nested a = (Nested) new ExtendedNested(); // Noncompliant {{Remove this unnecessary cast to "Nested".}} + Nested[][] as = (Nested[][]) new ExtendedNested[1][1]; // Noncompliant {{Remove this unnecessary cast to "Nested[][]".}} + ExtendedNested b = null; + fun(b); + + fun((ExtendedNested) b); // Noncompliant + fun(((ExtendedNested) b)); // Noncompliant + fun((((ExtendedNested) b))); // Noncompliant + fun((Nested) a, (ExtendedNested) a); // Noncompliant +// ^^^^^^^^ + fun((Nested) b); // Compliant - exception to distinguish the method to call + List bees = new java.util.ArrayList(); + List aaas = (List) bees; + C c = new C((Nested) null); // Compliant - exception to distinguish the constructor to call + foo((List>) (List) foo2()); // compliant + + String[] stringList = (String[]) list.toArray(new String[0]); // Compliant + return null; + } + + List foo2() { + + int a = 1; + int b = 2; + double d = (double) a / (double) b; + int c = (int)a; // Noncompliant {{Remove this unnecessary cast to "int".}} + int e = (int) d; + return null; + } + + void lossyWideningCasts(int intVar, long longVar) { + float f1 = (float) intVar; // Compliant: documents potential precision loss, required by S9395 + float f2 = (float) longVar; // Compliant + double d1 = (double) longVar; // Compliant + float f3 = (float) (intVar); // Compliant + double d2 = (double) intVar; // Noncompliant {{Remove this unnecessary cast to "double".}} + float f4 = (float) 42; // Noncompliant {{Remove this unnecessary cast to "float".}} + double d3 = (double) 42L; // Noncompliant {{Remove this unnecessary cast to "double".}} + float f5 = (float) (intVar * intVar); // Noncompliant {{Remove this unnecessary cast to "float".}} + float f6 = (float) (intVar + intVar); // Noncompliant + double d4 = (double) (longVar / longVar); // Noncompliant + float f7 = (float) intVar * intVar; // Compliant + } + + private static int charConversion(char c) { + return (char) ((c | 0x20) - 'a'); // Compliant + } + + void foo(List> a) {} + + void castInArguments(List p) { + Collection v1 = Collections.emptyList(); + List v2 = Collections.emptyList(); + castInArguments((List) v1); // Compliant - cast needed + castInArguments((List) v2); // Noncompliant + } + + List> foo3() { + return null; + } + void fun(Nested a) { + } + + void fun(Nested a, ExtendedNested b) { + } + + void fun(ExtendedNested b) { + } + + void funBParameter(ExtendedNested b) { + } + + class C { + C(Nested a) {} + C(ExtendedNested a) throws Exception { + Object o = (Object) fun().newInstance(); // Noncompliant {{Remove this unnecessary cast to "Object".}} + } + Class fun() { return null;} + public T[] toArray(T[] a) { + Object[] elementData = new Object[0]; + // Make a new array of a's runtime type, but my contents: + return (T[]) Arrays.copyOf(elementData, 12, a.getClass()); // Compliant - The cast is mandatory! + } + String[] fun2(){ + return (String[]) null; // Noncompliant {{Remove this unnecessary cast to "String[]".}} + } + } +} + +class RedundantTypeCastCheckSample_D { + List genericCast() { + List objectList = null; + return (List) objectList; + } +} + +class RedundantTypeCastCheckSample_E { + Map> secondTypeChangeCast(Map multimap) { + return (Map>) (Map) multimap; // Compliant + } + RedundantTypeCastCheckSample_E> typeChangeCast(RedundantTypeCastCheckSample_E> list) { + return (RedundantTypeCastCheckSample_E>) (RedundantTypeCastCheckSample_E) list; // Compliant + } +} +interface Dto {} +interface Index, KEY extends java.io.Serializable> {} +class CastToRawType { + void fun() { + Object o1 = (Object) Object[].class; // Noncompliant + Class o2 = (Class) Object[].class; // Noncompliant + } + private final Map, Index> indexComponents = null; + public K get(Class clazz){ + return (K) this.indexComponents.get(clazz); + } + +} + +class RedundantTypeCastCheckSample_F { + class Inner { + J fun(T t) { + return (J) t; + } + } + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) + a = (T[])java.lang.reflect.Array + .newInstance(a.getClass().getComponentType(), size); + java.util.Iterator> it = iterator(); + for (int i = 0; i < size; i++) + a[i] = (T) new java.util.AbstractMap.SimpleEntry(it.next()); + if (a.length > size) + a[size] = null; + return a; + } + public int size() { + return 42; + } + public java.util.Iterator> iterator() { + return null; + } +} +class RedundantTypeCastCheckSample_G { + + private RedundantTypeCastCheckSample_G resolveSupertype() { + return null; + } + + void foo() { + RedundantTypeCastCheckSample_G plop = (RedundantTypeCastCheckSample_G) resolveSupertype(); // this works but there is an issue in the returned type of resolveSupertype which returns raw type RedundantTypeCastCheckSample_G instead of RedundantTypeCastCheckSample_G + } + + private int unsafeCompare(Object k1, Object k2) { + Comparator comparator = null; + if (comparator == null) { + return ((Comparable) k1).compareTo(k2); + } else { + return ((Comparator) comparator).compare(k1, k2); + } + } + + String foo(Object a) { + return a == null ? (String) null : a.toString(); // Noncompliant + } + + static class H { + java.util.concurrent.Callable c0 = () -> { + return (H) getValue(); + }; + + private Object getValue() { + return null; + } + + public T getInstance(Runtime runtime, Object o, Class clazz) throws Exception { + String name = clazz.getName(); + Class c = (Class) Class.forName(name, true, o.getClass().getClassLoader()); + return null; + } + + public String supportSpecificTypeReturnedByGetClass(Object obj) { + // "getClass()" does not respect its method signature, instead of returning "Class", it returns "Class" + Class cls1 = ((String) obj).getClass(); // Compliant, without the "(String)" cast, the code does not compile + Class cls3 = ((Object) obj).getClass(); // false-negative, limitation of the rule which is more permissive there is a ".getClass()" method invocation + + // coverage + Class cls2 = ((H) obj).getClass((String) obj); // not an "Object#getClass()" method invocation + class CornerCase{ + int getClass; + } + ((CornerCase) obj).getClass = 42; // not a method invocation but a field + return cls1.getName(); + } + + public Class getClass(T obj) { + return (Class) obj.getClass(); + } + + public static Number choose(Integer i, Float f, boolean takeFirst) { + return takeFirst ? (Number) i : f; + } + + public static Number choose2(Integer i, Float f, boolean takeFirst) { + return takeFirst ? (int) i : f; + } + + public static float choose3(int i, double f, boolean takeFirst) { + return takeFirst ? i : (float)f; + } + } + + class I { + K getValue(K s) { + return s; + } + String foo() { + // FN introduced due to ECJ 3.44 + return (String) getValue(""); // Compliant + } + } + + void fun() { + Object test = new Object[]{"1"}; + String[] test2 = new String[]{"1"}; + Object[] test3 = new String[]{"1"}; + System.out.println(((Object[])test)[0]); // compliant : target type is array access + System.out.println(((Object[])test2)[0]); // Noncompliant + System.out.println(((String[])test3)[0]); // compliant + } +} + +interface RedundantTypeCastCheckSample_J { + default void foo() { } + default void bar() { } + + interface K extends RedundantTypeCastCheckSample_J { + void foo(); + } + + interface L extends RedundantTypeCastCheckSample_J { + void foobar(); + } + + static void test() { + RedundantTypeCastCheckSample_J j1 = (K) () -> { }; // compliant : cast is needed for it to be used as a lambda expression + RedundantTypeCastCheckSample_J j2 = (L) () -> { }; // compliant : cast is needed for it to be used as a lambda expression + } +} + +interface RedundantTypeCastCheckSample_M { + default void foo() { } + default void bar() { } + void foobar(); + + interface N extends RedundantTypeCastCheckSample_M { + default void foobar() { } + void foo(); + } + + interface O extends RedundantTypeCastCheckSample_M { } + + interface P extends RedundantTypeCastCheckSample_M { + void foobar(); + } + + interface Q extends RedundantTypeCastCheckSample_M { + default void foo() { } + } + + static void test() { + RedundantTypeCastCheckSample_M m1 = () -> { }; + RedundantTypeCastCheckSample_M m2 = (RedundantTypeCastCheckSample_M) () -> { }; // FN because we now allow all casts on lambdas to avoid FPs + RedundantTypeCastCheckSample_M m3 = (N) () -> { }; // compliant : cast changes method associated to lambda expression + RedundantTypeCastCheckSample_M m6 = (Q) () -> { }; // compliant : cast changes default definition of method foo + } +} + +class RedundantTypeCastCheckSample_T { + Predicate methodReferenceCastNeeded() { + return ((Predicate) Objects::nonNull).negate(); // Compliant : cannot call Predicate#negate() without casting it first + } + + Comparator methodReferenceCastNeeded2() { + return (((Comparator) Integer::compare)).reversed(); // Compliant : cannot call Comparator#reversed() without casting it first + } + + Predicate methodReferenceCastNotNeeded() { + return (((Predicate) Objects::nonNull)); // FN because we now allow all casts on method references to avoid FPs + } + + Comparator methodReferenceCastNotNeeded2() { + return (Comparator) Integer::compare; // FN because we now allow all casts on method references to avoid FPs + } +} + +abstract class MyClass { + public String field; + abstract U foo(); + + String qix() { + return ((MyOtherClass) foo()).field; // Compliant - FN + } + + String qix0() { + return ((MyOtherClass) foo()).otherField; // Compliant + } + + String qix1() { + return ((MyOtherClass) foo()).bar(); // Compliant + } + + MyClass qix3() { + return ((MyOtherClass) foo()); // Noncompliant + } +} +abstract class MyOtherClass extends MyClass { + public String otherField; + abstract String bar(); +} + +class AWT { + private static java.awt.event.AWTEventListener deProxyAWTEventListener(java.awt.event.AWTEventListener l) { + java.awt.event.AWTEventListener localL = l; + + if (localL == null) { + return null; + } + if (l instanceof java.awt.event.AWTEventListenerProxy) { + localL = (java.awt.event.AWTEventListener) // Noncompliant + ((java.awt.event.AWTEventListenerProxy) l).getListener(); // Compliant + } + return localL; + } + + void foo() { + byte a = 42; + a = (byte) -a; // Compliant - cast is required + } +} + +class CastIntersectionType { + public static final Comparator UNIQUE_ID_COMPARATOR = (Comparator & java.io.Serializable) (o1, o2) -> o1.toString().compareTo(o2.toString()); +} + +abstract class Discuss { + + abstract M getMeta(); + + void foo() { + int i = ((String) getMeta()).length(); // Compliant - generic method correctly handled + } +} + +class ClassWithAnnotation { + @MyAnnotation((int) (0L + 42)) + Object field; + + @interface MyAnnotation { + int value() default 42; + } +} + +class ClassWithVariadicFunction { + public ClassWithVariadicFunction(int i) { + + } + + void variadicFunction(int ... p) {} + void fun() { + variadicFunction(1, 2, (int) 3.4); + variadicFunction(1, 2, ((int) 3.4)); + variadicFunction((int) 1, 2, 3); // Noncompliant + variadicFunction(((int) 1), 2, 3); // Noncompliant + variadicFunction(1, 2, 3, (int) 4); // Noncompliant + + ClassWithVariadicFunction c = new ClassWithVariadicFunction((int) 3.4); // recovered constructor + } +} + +class GenericClass { + private GenericClass type() { + return null; + } + + void foo() { + GenericClass g = (GenericClass) type(); // type of the method invocation is well-handled + } +} + +class CastRawType { + public static void paramsErrorMessage(Class clazz) { + Outer.Nested r = (Outer.Nested) clazz.getAnnotation(Outer.Nested.class); // Handle cast of raw types + } +} + +class PrecisionLossCasts { + static final int SMALL_INT = 42; + static final long SMALL_LONG = 42L; + + PrecisionLossCasts(float first, float second, double third) {} + + void conversions(int intValue, long longValue) { + float fromInt = (float) intValue; + float fromLong = (float) longValue; + double doubleFromLong = (double) longValue; + + fromInt = (float) intValue; + fromLong = (float) longValue; + doubleFromLong = (double) longValue; + + fromInt += (float) intValue; + fromLong += (float) longValue; + doubleFromLong += (double) longValue; + + takeFloat((float) intValue); + takeFloat((float) longValue); + takeDouble((double) longValue); + new PrecisionLossCasts((float) intValue, (float) longValue, (double) longValue); + + takeFloat(((float) (intValue))); + takeFloat(((float) (longValue))); + takeDouble(((double) (longValue))); + } + + float returnInt(int value) { + return (float) value; + } + + float returnLong(long value) { + return (float) value; + } + + double returnLongAsDouble(long value) { + return (double) value; + } + + void safeConstants() { + float zero = (float) 0; // Noncompliant + float fromInt = (float) 1; // Noncompliant + float fromLong = (float) 1L; // Noncompliant + double doubleFromLong = (double) 1L; // Noncompliant + + float namedInt = (float) SMALL_INT; // Noncompliant + float namedLong = (float) SMALL_LONG; // Noncompliant + double namedDouble = (double) SMALL_LONG; // Noncompliant + float folded = (float) (20 + 22); // Noncompliant + + float intUpperBound = (float) 16_777_216; // Noncompliant + float intLowerBound = (float) -16_777_216; // Noncompliant + float longUpperBound = (float) 16_777_216L; // Noncompliant + float longLowerBound = (float) -16_777_216L; // Noncompliant + double doubleUpperBound = (double) 9_007_199_254_740_992L; // Noncompliant + double doubleLowerBound = (double) -9_007_199_254_740_992L; // Noncompliant + + takeFloat(((float) (1))); // Noncompliant + takeFloat((float) 1L); // Noncompliant + takeDouble((double) 1L); // Noncompliant + new PrecisionLossCasts((float) 1, (float) 1L, (double) 1L); // Noncompliant 3 + } + + void lossyConstants() { + float fromInt = (float) 16_777_217; + float negativeInt = (float) -16_777_217; + float fromLong = (float) 16_777_217L; + float negativeLong = (float) -16_777_217L; + double doubleFromLong = (double) 9_007_199_254_740_993L; + double negativeDouble = (double) -9_007_199_254_740_993L; + } + + void redundantCasts(int intValue, long longValue, float floatValue, byte byteValue, short shortValue, char charValue) { + int sameInt = (int) intValue; // Noncompliant + long sameLong = (long) longValue; // Noncompliant + float sameFloat = (float) floatValue; // Noncompliant + long widerInteger = (long) intValue; // Noncompliant + double fromInt = (double) intValue; // Noncompliant + double fromFloat = (double) floatValue; // Noncompliant + float fromByte = (float) byteValue; // Noncompliant + float fromShort = (float) shortValue; // Noncompliant + float fromChar = (float) charValue; // Noncompliant + } + + void takeFloat(float value) {} + void takeDouble(double value) {} +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantTypeCastCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantTypeCastCheckSample.textproto.gz new file mode 100644 index 00000000000..f382c89e049 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/RedundantTypeCastCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ReplaceLambdaByMethodRefCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ReplaceLambdaByMethodRefCheckSample.expected.txt.gz new file mode 100644 index 00000000000..f7c01f210f0 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ReplaceLambdaByMethodRefCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ReplaceLambdaByMethodRefCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ReplaceLambdaByMethodRefCheckSample.java new file mode 100644 index 00000000000..9d5f0d8ae6a --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ReplaceLambdaByMethodRefCheckSample.java @@ -0,0 +1,577 @@ +package checks; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +class LambdaA { + void fun() { + String strings = "test"; + Runnable run = () -> System.out.println(strings); + run.run(); + IntStream.range(1, 5) + .map((x) -> x * x) + .map(x -> square(x)) // Noncompliant {{Replace this lambda with method reference 'this::square'.}} +// ^^ + .map(x -> { // Noncompliant + return square(x); + }) + .map(this::square) //Compliant + .forEach(System.out::println); + IntStream.range(1, 5).forEach(x -> System.out.println(x)); // Noncompliant + IntStream.range(1, 5).forEach(x -> { // Noncompliant + System.out.println(x); + }); + IntStream.range(1, 5).forEach(x -> {return;}); // Compliant + + Arrays.asList("bar").stream().filter(string -> string.startsWith("b")); // Compliant + Arrays.asList(new LambdaA()).stream().filter(a -> a.coolerThan(0, a)); // Compliant + + biConsumer((x, y) -> { ; }); + biConsumer((x, y) -> { ;; }); + } + + void generics() { + Stream.of(Integer.valueOf(42)).forEach(x -> new java.util.ArrayList(x)); // false-negative, generics are not supported + Stream.of(Integer.valueOf(42)).forEach(x -> new java.util.ArrayList<>(x)); // false-negative, generics are not supported + Stream.of(Integer.valueOf(42)).forEach(java.util.ArrayList::new); // Compliant + Stream.of(Integer.valueOf(42)).forEach(java.util.ArrayList::new); // Compliant + } + + void biConsumer(BiConsumer consumer) { + } + + void runnable(Runnable runnable) { + } + + void foo(List list, String a) { + list.stream().map(String::toLowerCase).close(); + + list.stream().map(s -> s.toLowerCase()).close(); // Noncompliant + list.stream().map(s -> { return s.toLowerCase(); }).close(); // Noncompliant + + list.stream().map(s -> new String()).close(); // Compliant + list.stream().map(s -> a.toLowerCase()).close(); // Compliant + list.stream().map(s -> s.toLowerCase().toUpperCase()).close(); // Compliant + list.stream().forEach(s -> fun()); // Compliant + list.stream().reduce((x, y) -> x.toLowerCase()); // Compliant + } + + int square(int x) { + return x * x; + } + + boolean coolerThan(int i, LambdaA a) { + return true; + } + + Collection values = transform( + input -> getValueProvider().apply(input).getValue() //cannot be replaced by a method reference. + ); + + Collection values2 = transform2((input, input2) -> getValueProvider().apply(input)); //cannot be replaced by a method reference. + + LambdaA getValueProvider() { + return null; + } + LambdaA getValue() { + return null; + } + LambdaA apply(LambdaA a) { + return a; + } + + Collection transform(F f) {return null;} + Collection transform2(F2 f) {return null;} + interface F2 { + LambdaA apply(LambdaA a1, LambdaA a2); + } + interface F { + LambdaA apply(LambdaA a1); + } + + static class Nested { + void doSomething() {} + + int method() { + return 1; + } + + void multiline() { + Optional.empty().map(x -> { + doSomething(); + return method(); + }); + } + } + + void nullChecks(List strings, String s2) { + strings.stream().filter(s1 -> s1 != null); // Noncompliant {{Replace this lambda with method reference 'Objects::nonNull'.}} + strings.stream().filter(string -> string != null); // Noncompliant {{Replace this lambda with method reference 'Objects::nonNull'.}} + strings.stream().filter(s -> { return s != null; }); // Noncompliant {{Replace this lambda with method reference 'Objects::nonNull'.}} + strings.stream().filter(string -> (string) == null); // Noncompliant {{Replace this lambda with method reference 'Objects::isNull'.}} + strings.stream().filter(string -> null == string); // Noncompliant {{Replace this lambda with method reference 'Objects::isNull'.}} + strings.stream().filter(s -> (((s == null)))); // Noncompliant {{Replace this lambda with method reference 'Objects::isNull'.}} + + strings.stream().filter(Objects::nonNull); // Compliant + strings.stream().filter(Objects::isNull); // Compliant + + strings.stream().filter(s -> s != null); // Compliant, shorter + strings.stream().filter(s -> s == null); // Compliant, shorter + + strings.stream().filter(s -> (((s == s2)))); // Compliant + strings.stream().filter(s -> (((s2 == s)))); // Compliant + strings.stream().filter(s -> (((s2 == null)))); // Compliant + strings.stream().filter(s -> (((null == null)))); // Compliant + } + + void append(StringBuilder sb, List list) { + list.forEach(item -> sb.append("\n").append(item)); + } +} + +class LambdaD { + + LambdaD(Object o) { /* ... */ } + String foo() { return ""; } + void bar(java.util.function.Supplier supplier) { /* ... */ } + + void test(Object param) { + bar(() -> new LambdaD(param).foo()); // Compliant - this is not equivalent to the next line + bar(new LambdaD(param)::foo); + } +} + +class TestA { + +} + + +class CastCheck { + + void bar(java.util.function.Function function) { /* ... */ } + void bar2(java.util.function.BiFunction function) { /* ... */ } + void bar3(java.util.function.Function> function) { /* ... */ } + void bar4(java.util.function.Function function) { /* ... */ } + void bar5(java.util.function.Function function) { /* ... */ } + void bar6(java.util.function.Function function) { /* ... */ } + void bar7(java.util.function.Function> function) { /* ... */ } + void bar8(java.util.function.Function[]> function) { /* ... */ } + void bar9(java.util.function.Function f) { /* ... */ } + + void barbar(java.util.function.Predicate function) { /* ... */ } + void barbar2(java.util.function.BiPredicate function) { /* ... */ } + void barbar3(java.util.function.Predicate> function) { /* ... */ } + void barbar4(java.util.function.Predicate function) { /* ... */ } + void barbar5(java.util.function.Predicate function) { /* ... */ } + void barbar6(java.util.function.Predicate function) { /* ... */ } + void barbar7(java.util.function.Predicate> function) { /* ... */ } + void barbar8(java.util.function.Predicate[]> function) { /* ... */ } + void barbar9(java.util.function.Predicate f) { /* ... */ } + + void testInstanceOf(Object param) { + barbar((o) -> o instanceof String); // Noncompliant {{Replace this lambda with method reference 'String.class::isInstance'.}} + barbar(String.class::isInstance); // Compliant + + barbar4((o) -> o instanceof TestA); // Noncompliant {{Replace this lambda with method reference 'TestA.class::isInstance'.}} + barbar4(TestA.class::isInstance); //Compliant + + barbar3(List.class::isInstance); //Compliant + barbar3((o) -> o instanceof List); // Noncompliant {{Replace this lambda with method reference 'List.class::isInstance'.}} + + barbar5(TestA[].class::isInstance); //Compliant + barbar5((o) -> o instanceof TestA[]); // Noncompliant {{Replace this lambda with method reference 'TestA[].class::isInstance'.}} + + barbar6(TestA[][].class::isInstance); //Compliant + barbar6((o) -> o instanceof TestA[][]); // Noncompliant {{Replace this lambda with method reference 'TestA[][].class::isInstance'.}} + + barbar7(List.class::isInstance); //Compliant + barbar7((o) -> o instanceof List ); // Noncompliant {{Replace this lambda with method reference 'List.class::isInstance'.}} + + barbar8(List[].class::isInstance); //Compliant + barbar8((o) -> o instanceof List[] ); // Noncompliant {{Replace this lambda with method reference 'List[].class::isInstance'.}} + + barbar9(char.class::isInstance); //Compliant + barbar9(Character.class::isInstance); //Compliant + barbar9((o) -> o instanceof Character); // Noncompliant {{Replace this lambda with method reference 'Character.class::isInstance'.}} + } + + void testInstanceOf2(Object param) { + barbar((o) -> { // Noncompliant {{Replace this lambda with method reference 'String.class::isInstance'.}} + return o instanceof String; + }); + } + + void testInstanceOf3(Object param) { + barbar2((a, b) -> { // Compliant + return a instanceof String; + }); + } + + void testInstanceOf4(Object param) { + barbar(o -> { // Compliant + return o instanceof String && true; + }); + } + + void testInstanceOf5(Object param) { + Object o2 = new Object(); + barbar(o -> { // Compliant + return o2 instanceof String; + }); + } + + void testCasts(Object param) { + bar((object) -> (String) object); // Noncompliant {{Replace this lambda with method reference 'String.class::cast'.}} + bar((o) -> (String) o); // Compliant, shorter + bar(String.class::cast); // Compliant + + bar4((object) -> (TestA) object); // Noncompliant {{Replace this lambda with method reference 'TestA.class::cast'.}} + bar4((o) -> (TestA) o); // Compliant, shorter + bar4(TestA.class::cast); + + bar3(List.class::cast); //Compliant + bar3((o) -> (List) o); // Compliant, there is no 'List.class::cast' + + bar5(TestA[].class::cast); //Compliant + bar5((o) -> (TestA[]) o); // Compliant, shorter + bar5((object) -> (TestA[]) object); // Noncompliant {{Replace this lambda with method reference 'TestA[].class::cast'.}} + + bar6(TestA[][].class::cast); //Compliant + bar6((o) -> (TestA[][]) o); // Compliant, shorter + bar6((object) -> (TestA[][]) object); // Noncompliant {{Replace this lambda with method reference 'TestA[][].class::cast'.}} + + bar7(List.class::cast); //Compliant + bar7((o) -> (List) o); // Compliant, there is no 'List.class::cast' + + bar8(List[].class::cast); //Compliant + bar8((o) -> (List[]) o); // Compliant, there is no 'List[].class::cast' + + bar9(char.class::cast); //Compliant + bar9(Character.class::cast); //Compliant + bar9((object) -> (char) object); // Noncompliant {{Replace this lambda with method reference 'char.class::cast'.}} + bar9((object) -> (Character) object); // Noncompliant {{Replace this lambda with method reference 'Character.class::cast'.}} + + "abc".chars().mapToObj(i -> (char) i); // Compliant, char::cast takes an Object as its argument causing i to be implicitly converted to Integer, + "abc".chars().mapToObj(char.class::cast); // since casting Integer to char is invalid, this change would turn a valid cast into an invalid one + } + + void testCasts2(Object param) { + bar((o) -> { // Noncompliant {{Replace this lambda with method reference 'String.class::cast'.}} + return (String)o; + }); + } + + void testCasts3(Object param) { + bar2((a, b) -> { // Compliant + return (String)a; + }); + } + + void testCasts4(Object param) { + bar(o -> { // Compliant + return (String)o.getClass().getCanonicalName(); + }); + } + + void testCasts5(Object param) { + Object o2 = new Object(); + bar(o -> { // Compliant + return (String)o2; + }); + } + + void quickFixes(List strings) { + IntStream.range(1, 5).forEach(x -> staticMethod(x)); // Compliant, shorter + IntStream.range(1, 5).forEach(x -> CastCheck.staticMethod(x)); // Noncompliant {{Replace this lambda with method reference 'CastCheck::staticMethod'.}} [[quickfixes=qf1]] +// ^^ + // fix@qf1 {{Replace with "CastCheck::staticMethod"}} + // edit@qf1 [[sc=35;ec=65]] {{CastCheck::staticMethod}} + IntStream.range(1, 5).forEach(param -> staticMethod(param)); // Noncompliant {{Replace this lambda with method reference 'CastCheck::staticMethod'.}} [[quickfixes=qf2]] +// ^^ + // fix@qf2 {{Replace with "CastCheck::staticMethod"}} + // edit@qf2 [[sc=35;ec=63]] {{CastCheck::staticMethod}} + IntStream.range(1, 5).forEach(x -> notStatic(x)); // Noncompliant {{Replace this lambda with method reference 'this::notStatic'.}} [[quickfixes=qf3]] +// ^^ + // fix@qf3 {{Replace with "this::notStatic"}} + // edit@qf3 [[sc=35;ec=52]] {{this::notStatic}} + Nested n = new Nested(1); + IntStream.range(1, 5).forEach(x -> n.takeInt(x)); // Noncompliant {{Replace this lambda with method reference 'n::takeInt'.}} [[quickfixes=qf4]] +// ^^ + // fix@qf4 {{Replace with "n::takeInt"}} + // edit@qf4 [[sc=35;ec=52]] {{n::takeInt}} + IntStream.range(1, 5).forEach(x -> NestedStatic.takeIntStatic(x)); // FN, do not report an issue because NestedStatic is not final + + IntStream.range(1, 5).forEach(x -> new Nested(x)); // Noncompliant {{Replace this lambda with method reference 'Nested::new'.}} [[quickfixes=qf_new_class]] +// ^^ + // fix@qf_new_class {{Replace with "Nested::new"}} + // edit@qf_new_class [[sc=35;ec=53]] {{Nested::new}} + IntStream.range(1, 5).forEach(x -> new CastCheck.Nested(x)); // Noncompliant {{Replace this lambda with method reference 'CastCheck.Nested::new'.}} [[quickfixes=qf_new_class2]] +// ^^ + // fix@qf_new_class2 {{Replace with "CastCheck.Nested::new"}} + // edit@qf_new_class2 [[sc=35;ec=63]] {{CastCheck.Nested::new}} + + IntStream.range(1, 5).forEach(x -> new NestedStatic.NestedInNested(x)); // Noncompliant {{Replace this lambda with method reference 'NestedStatic.NestedInNested::new'.}} [[quickfixes=qf_new_class3]] +// ^^ + // fix@qf_new_class3 {{Replace with "NestedStatic.NestedInNested::new"}} + // edit@qf_new_class3 [[sc=35;ec=74]] {{NestedStatic.NestedInNested::new}} + + strings.stream() + .map(s -> s.toLowerCase()) // Noncompliant {{Replace this lambda with method reference 'String::toLowerCase'.}} [[quickfixes=qf5]] +// ^^ + // fix@qf5 {{Replace with "String::toLowerCase"}} + // edit@qf5 [[sc=12;ec=32]] {{String::toLowerCase}} + .map(s -> { // Noncompliant [[quickfixes=qf6]] +// ^^ + return s.toLowerCase(); + }) + // fix@qf6 {{Replace with "String::toLowerCase"}} + // edit@qf6 [[sc=12;el=+3;ec=8]] {{String::toLowerCase}} + .forEach(x -> System.out.println(x)); // Noncompliant {{Replace this lambda with method reference 'System.out::println'.}} [[quickfixes=qf7]] +// ^^ + // fix@qf7 {{Replace with "System.out::println"}} + // edit@qf7 [[sc=16;ec=42]] {{System.out::println}} + + strings.stream().filter(string -> string != null); // Noncompliant [[quickfixes=qf_null1]] +// ^^ + // fix@qf_null1 {{Replace with "Objects::nonNull"}} + // edit@qf_null1 [[sc=29;ec=53]] {{Objects::nonNull}} + strings.stream().filter(s -> (s) == null); // Noncompliant [[quickfixes=qf_null2]] +// ^^ + // fix@qf_null2 {{Replace with "Objects::isNull"}} + // edit@qf_null2 [[sc=29;ec=45]] {{Objects::isNull}} + barbar((o) -> o instanceof String); // Noncompliant [[quickfixes=qf_instance_of]] +// ^^ + // fix@qf_instance_of {{Replace with "String.class::isInstance"}} + // edit@qf_instance_of [[sc=12;ec=38]] {{String.class::isInstance}} + bar((object) -> (String) object); // Noncompliant [[quickfixes=qf_cast1]] +// ^^ + // fix@qf_cast1 {{Replace with "String.class::cast"}} + // edit@qf_cast1 [[sc=9;ec=36]] {{String.class::cast}} + bar6((object) -> (TestA[][]) object); // Noncompliant [[quickfixes=qf_cast2]] +// ^^ + // fix@qf_cast2 {{Replace with "TestA[][].class::cast"}} + // edit@qf_cast2 [[sc=10;ec=40]] {{TestA[][].class::cast}} + + strings.stream().allMatch(it -> "x1".equals(it)); // Noncompliant {{Replace this lambda with method reference '"x1"::equals'.}} [[quickfixes=qf_str_lit]] +// ^^ + // fix@qf_str_lit {{Replace with ""x1"::equals"}} + // edit@qf_str_lit [[sc=31;ec=52]] {{"x1"::equals}} + } + + int notStatic(int x) { + return x * x; + } + + static int staticMethod(int x) { + return x * x * x; + } + + class Nested { + { + IntStream.range(1, 5).forEach(parameter -> takeInt(parameter)); // Noncompliant {{Replace this lambda with method reference 'Nested.this::takeInt'.}} [[quickfixes=qf_init]] +// ^^ + // Could be simpler: "this::takeInt", but add the class name since we can not get the enclosing method + // fix@qf_init {{Replace with "Nested.this::takeInt"}} + // edit@qf_init [[sc=37;ec=68]] {{Nested.this::takeInt}} + + IntStream.range(1, 5).forEach(parameter -> notStatic(parameter)); // Noncompliant {{Replace this lambda with method reference 'CastCheck.this::notStatic'.}} [[quickfixes=qf_init2]] +// ^^ + // fix@qf_init2 {{Replace with "CastCheck.this::notStatic"}} + // edit@qf_init2 [[sc=37;ec=70]] {{CastCheck.this::notStatic}} + } + + Nested(int x) { + + } + + void quickFixInNestedClass() { + IntStream.range(1, 5).forEach(parameter -> notStatic(parameter)); // Noncompliant {{Replace this lambda with method reference 'CastCheck.this::notStatic'.}} [[quickfixes=qf_this]] +// ^^ + // fix@qf_this {{Replace with "CastCheck.this::notStatic"}} + // edit@qf_this [[sc=37;ec=70]] {{CastCheck.this::notStatic}} + + IntStream.range(1, 5).forEach(parameter -> staticMethod(parameter)); // Noncompliant {{Replace this lambda with method reference 'CastCheck::staticMethod'.}} [[quickfixes=qf_this2]] +// ^^ + // fix@qf_this2 {{Replace with "CastCheck::staticMethod"}} + // edit@qf_this2 [[sc=37;ec=73]] {{CastCheck::staticMethod}} + } + + class NestedDeeper { + void quickFixInNestedClass() { + IntStream.range(1, 5).forEach(parameter -> notStatic(parameter)); // Noncompliant {{Replace this lambda with method reference 'CastCheck.this::notStatic'.}} [[quickfixes=qf_this3]] +// ^^ + // fix@qf_this3 {{Replace with "CastCheck.this::notStatic"}} + // edit@qf_this3 [[sc=39;ec=72]] {{CastCheck.this::notStatic}} + } + } + + public int takeInt(int x) { + return 1 + x; + } + + public int doSomething() { + return 1; + } + } + + void quickFixInNestedClass() { + Stream.of(new NestedExtend()).forEach(x -> x.doSomething()); // Noncompliant [[quickfixes=qf_method_override]] +// ^^ + // fix@qf_method_override {{Replace with "Nested::doSomething"}} + // edit@qf_method_override [[sc=43;ec=63]] {{Nested::doSomething}} + + Stream.of(new NestedExtendOverrideTakeInt()).forEach(x -> x.doSomething()); // Noncompliant [[quickfixes=qf_method_override3]] +// ^^ + // fix@qf_method_override3 {{Replace with "Nested::doSomething"}} + // edit@qf_method_override3 [[sc=58;ec=78]] {{Nested::doSomething}} + Stream.of(new NestedExtendOverrideTakeInt()).forEach(parameterWithLongName -> parameterWithLongName.doSomething()); // Noncompliant [[quickfixes=qf_method_override2]] +// ^^ + // fix@qf_method_override2 {{Replace with "Nested::doSomething"}} + // edit@qf_method_override2 [[sc=58;ec=118]] {{Nested::doSomething}} + } + + class NestedExtend extends Nested { + NestedExtend() { + super(1); + } + } + + class NestedExtendOverrideTakeInt extends Nested { + NestedExtendOverrideTakeInt() { + super(1); + } + + public int doSomething() { + return 1; + } + } + + static class NestedStatic { + public static int takeIntStatic(int x) { + return 1 + x; + } + + static class NestedInNested { + NestedInNested(int x) { + + } + } + } +} + +class LambdaB { + void intToString() { + apply((i, r) -> Integer.toString(i, r)); // Noncompliant [[quickfixes=qf_int_to_str2]] +// ^^ + // fix@qf_int_to_str2 {{Replace with "Integer::toString"}} + // edit@qf_int_to_str2 [[sc=11;ec=43]] {{Integer::toString}} + } + + String apply(BiFunction f) { + return f.apply(10, 16); + } +} + +class MultiArityTest { + void test() { + BiFunction test = (mat, i) -> foo(mat, i); // Compliant, both methods have the same reference and cannot be disambiguated + } + String foo(int x) { return Integer.toString(x); } + static String foo(MultiArityTest mat, int x) { return Integer.toString(x); } +} + +class TestObject { + String foo() { + return null; + } + + int spam() { + return 0; + } + + static int spam(TestObject to) { + return to.hashCode(); + } + + int eggs() throws Exception { + throw new UnsupportedOperationException(); + } +} + +class TestNumber extends TestObject { + static String foo(TestNumber tn) { + return null; + } + String foo() { + return "Number here"; + } + + void test() { + Optional.of(new TestNumber()).map(testNumber -> testNumber.foo()); // Noncompliant [[quickfixes=qf_supertype]] +// ^^ + // fix@qf_supertype {{Replace with "TestObject::foo"}} + // edit@qf_supertype [[sc=39;ec=69]] {{TestObject::foo}} + } +} +class TestInteger extends TestNumber { + String foo() { + return "Integer here"; + } + + int eggs() { + return 42; + } + + static int eggs(TestInteger ti) { + return ti.hashCode(); + } + + String bar(String s) { + return s; + } + + static String bar(TestInteger i, String s, String t) { + return eggs(i) == 0 ? s : t; + } + + static void consumeBoth(BiConsumer bc) { + bc.accept(null, null); + } + + void test() { + Optional.of(new TestInteger()).map(testInteger -> testInteger.foo()); // Noncompliant [[quickfixes=qf_supertype2]] +// ^^ + // fix@qf_supertype2 {{Replace with "TestObject::foo"}} + // edit@qf_supertype2 [[sc=40;ec=72]] {{TestObject::foo}} + Optional.of(new TestInteger()).map(testInteger -> TestNumber.foo(testInteger)); // Compliant, method reference is ambiguous + Optional.of(new TestInteger()).map(testInteger -> testInteger.spam()); // Compliant, method reference is ambiguous + Optional.of(new TestInteger()).map(testInteger -> (foo().length() % 23 == 0 ? testInteger : (TestObject) null).spam(testInteger)); // Compliant, method reference is ambiguous + Optional.of(new TestInteger()).map(testInteger -> testInteger.eggs()); // Compliant, method reference is ambiguous + consumeBoth((testInteger, s) -> testInteger.bar(s)); // Noncompliant [[quickfixes=qf_2args]] +// ^^ + // fix@qf_2args {{Replace with "TestInteger::bar"}} + // edit@qf_2args [[sc=17;ec=55]] {{TestInteger::bar}} + consumeBoth((testInteger, s) -> testInteger.bar("test")); // Compliant + } +} + +class UnambiguousDueToParameterType { + static int foo(String s) { + return 1; + } + + int foo() { + return 2; + } + + void test() { + Optional.of(this).map(x -> x.foo()); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ReplaceLambdaByMethodRefCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ReplaceLambdaByMethodRefCheckSample.textproto.gz new file mode 100644 index 00000000000..92b78d9e2f6 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/ReplaceLambdaByMethodRefCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/SpecializedFunctionalInterfacesCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/SpecializedFunctionalInterfacesCheckSample.expected.txt.gz new file mode 100644 index 00000000000..2a1012608ed Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/SpecializedFunctionalInterfacesCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/SpecializedFunctionalInterfacesCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/SpecializedFunctionalInterfacesCheckSample.java new file mode 100644 index 00000000000..0e2f5b6e23b --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/SpecializedFunctionalInterfacesCheckSample.java @@ -0,0 +1,453 @@ +package checks; + +import java.util.LinkedHashMap; +import java.util.Map.Entry; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.BinaryOperator; +import java.util.function.Consumer; +import java.util.function.DoubleBinaryOperator; +import java.util.function.DoublePredicate; +import java.util.function.Function; +import java.util.function.IntFunction; +import java.util.function.IntSupplier; +import java.util.function.LongSupplier; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class SpecializedFunctionalInterfacesCheckSample { + + static class A implements Supplier { // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'IntSupplier'}} +// ^ + @Override + public Integer get() { + return null; + } + + static class AA implements Consumer { // Noncompliant + + Consumer a1 = new Consumer() { // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'IntConsumer'}} +// ^^^^^^^^^^^^^^^^^ + @Override + public void accept(Integer t) { + } + }; + Consumer a2 = new Consumer() { // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'DoubleConsumer'}} +// ^^^^^^^^^^^^^^^^ + @Override + public void accept(Double t) { + } + }; + Consumer a3 = new Consumer() { // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'LongConsumer'}} + @Override + public void accept(Long t) { + } + }; + Supplier a = () -> 1; // Noncompliant + Supplier a6 = () -> 1.0; // Noncompliant + Supplier a7 = () -> new Long(1); // Noncompliant + Predicate a4 = (int1) -> true; // Noncompliant + Predicate a8 = (double1) -> true; // Noncompliant + Predicate a9 = (long1) -> true; // Noncompliant + UnaryOperator a5 = (int1) -> int1; // Noncompliant + UnaryOperator a10 = (double1) -> double1; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'DoubleUnaryOperator'}} +// ^^^^^^^^^^^^^^^^^^^^^ + UnaryOperator a11 = long1 -> long1; // Noncompliant + BiConsumer a12 = (aaa, int1) -> {}; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'ObjIntConsumer'}} +// ^^^^^^^^^^^^^^^^^^^^^^ + BiConsumer a13 = (aaa, long1) -> {}; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'ObjLongConsumer'}} + BiConsumer a14 = (aaa, double1) -> {}; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'ObjDoubleConsumer'}} + BiConsumer compl1 = (a, aa) -> {}; // Compliant + Function a15 = (aaa) -> 1; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'ToIntFunction'}} + Function a16 = (aaa) -> new Long(1); // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'ToLongFunction'}} + Function a17 = new Function() { // Compliant, a17 is referenced bellow + @Override + public Double apply(A aaa) { + return 1.0; + } + }; + Function a17_2 = a17; // Compliant + Function a18 = (int1) -> new A(); // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'IntFunction'}} + Function a19 = (long1) -> new A(); // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'LongFunction'}} + Function a20 = (double1) -> new A2(); // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'DoubleFunction'}} + + Function a21 = (double1) -> 1; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'DoubleToIntFunction'}} + Function a22 = (double1) -> new Long(1); // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'DoubleToLongFunction'}} + Function a23 = (long1) -> 1.0; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'LongToDoubleFunction'}} + Function a24 = (long1) -> 1; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'LongToIntFunction'}} + + Function a25 = (aaa) -> new A(); // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'UnaryOperator'}} + Function lambda = value -> value * 2; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'IntUnaryOperator'}} + BiFunction a40 = (x, y) -> 2.0; // Compliant + BiFunction a42 = (x, y) -> 1; // Compliant + BiFunction a43 = (x, y) -> 2.0; // Compliant + + BiFunction bi = (x, y) -> { // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'BinaryOperator'}} + return x + y; + }; + + Function a39; // Compliant -- compliant no initialization + Function a30 = new Function() { // Compliant + @Override + public Object apply(Object t) { + return null; + } + }; + Function, ? extends A> a32 = new Function() { // Compliant + @Override + public Object apply(Object t) { + return null; + } + }; + DoublePredicate a31; + Supplier a34 = () -> new A(); // Compliant + IntSupplier a45 = new IntSupplier() { + @Override + public int getAsInt() { + return 0; + } + }; + Consumer a35 = new Consumer() { // Compliant + @Override + public void accept(A t) { + } + }; + DoubleBinaryOperator d = (x, y) -> x * y; // Compliant + IntFunction a33 = (x) -> new A(); // Compliant + Predicate a36 = (aaa) -> true; // Compliant + UnaryOperator a37 = (aaa) -> new A(); // Compliant + BinaryOperator a38 = new BinaryOperator() { // Compliant + @Override + public A apply(A t, A t1) { + return null; + } + }; + + @Override + public void accept(Long t) { + } + + Function a41 = new Function() { // Compliant because we don't apply the rule when wildcards are used + @Override + public Object apply(Object t) { + return null; + } + }; + + private static class A3 { + } + + Function foo1 = a3 -> new A3(); // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'UnaryOperator'}} + } + + Function foo1 = aaaaaa -> new AA(); // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'UnaryOperator'}} + } + + static class A2 implements BinaryOperator {// Noncompliant {{Refactor this code to use the more specialised Functional Interface 'IntBinaryOperator'}} + @Override + public Integer apply(Integer t, Integer u) { + return null; + } + } + + static class A3 { + void foo() { + Supplier a = () -> true; // Noncompliant + BinaryOperator var1 = new BinaryOperator() {// Noncompliant + @Override + public Double apply(Double t, Double u) { + return null; + } + }; + BinaryOperator var2 = new BinaryOperator() { // Noncompliant + @Override + public Long apply(Long t, Long u) { + return null; + } + }; + } + + private static class A4 implements Function>, Entry>> { // Noncompliant +// ^^ + @Override + public Entry> apply(Entry> t) { + return null; + } + + private static String getDetails(Function function, Integer... inT) { // Compliant because we don't apply the rule when wildcards are used + + Function a; // Compliant + Function foo1 = new Function() { // Compliant because we don't apply the rule when wildcards are used + @Override + public Object apply(Object t) { + return null; + } + }; + Function foo2 = new Function() { // Compliant because we don't apply the rule when wildcards are used + @Override + public Object apply(Object t) { + return null; + } + }; + Function, ? extends A> foo3 = new Function() { // Compliant + @Override + public Object apply(Object t) { + return null; + } + }; + return null; + } + } + + } + + static class MySupplier implements Supplier { // Noncompliant +// ^^^^^^^^^^ +// ^^^^^^^^^^^^^^^^^@-1< + Supplier mySupplier = new MySupplier(); // Compliant + + @Override + public Integer get() { + return null; + } + } + + static class MySupplier1 implements Supplier, Runnable { // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'IntSupplier'}} +// ^^^^^^^^^^^ +// ^^^^^^^^^^^^^^^^^@-1< + Supplier mySupplier = new MySupplier1(); // Compliant + + @Override + public Integer get() { + return null; + } + + @Override + public void run() { + } + } + + static class MySupplier2 implements Supplier, Consumer { // Noncompliant {{Refactor this code to use the more specialised Functional Interfaces 'IntSupplier', 'DoubleConsumer'}} +// ^^^^^^^^^^^ +// ^^^^^^^^^^^^^^^^^@-1< +// ^^^^^^^^^^^^^^^^@-2< + Supplier mySupplier = new MySupplier2(); // Compliant + + @Override + public Integer get() { + return null; + } + + @Override + public void accept(Double t) { + } + } + + static class MySupplier3 implements Supplier, Runnable, Consumer { // Noncompliant {{Refactor this code to use the more specialised Functional Interfaces 'IntSupplier', 'DoubleConsumer'}} +// ^^^^^^^^^^^ +// ^^^^^^^^^^^^^^^^^@-1< +// ^^^^^^^^^^^^^^^^@-2< + Supplier mySupplier = new MySupplier2(); // Compliant + + @Override + public Integer get() { + return null; + } + + @Override + public void accept(Double t) { + } + + @Override + public void run() { + } + + void foo4() { + BiFunction myBiFunc = new BiFunction() { // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'BinaryOperator'}} + @Override + public Integer[][][] apply(Integer[][][] t, Integer[][][] u) { + return null; + } + }; + + com.google.common.base.Function ff = new com.google.common.base.Function() { // Compliant + @Override + public String apply(Integer a) { + return null; + } + }; + } + } + + static class BooleanFunctions implements Supplier, Consumer { // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'BooleanSupplier'}} + + @Override + public Boolean get() { + return null; + } + + @Override + public void accept(Boolean t) { + } + + Function a1 = (x) -> true; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'UnaryOperator'}} + Function a2 = (x) -> true; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'Predicate'}} + Function a3 = (x) -> null; + Function a4 = (x) -> null; + + BiFunction b1 = (x, y) -> true; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'BiPredicate'}} + BiFunction b2 = (x, y) -> true; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'BinaryOperator'}} + + Supplier a = () -> true; // Noncompliant + BiConsumer b3 = (aaa, bool1) -> {}; // Compliant - there is no ObjBooleanConsumer functional interface + Consumer b4 = (bool1) -> {}; // Compliant - there is no BooleanConsumer functional interface + Predicate b5 = (bool1) -> true; // Compliant - there is no BooleanPredicate functional interface + UnaryOperator b6 = (bool1) -> true; // Compliant - there is no BooleanUnaryOperator functional interface + BinaryOperator b7 = (bool1, bool2) -> true; // Compliant - there is no BooleanBinaryOperator functional interface + } + + static class MethodParams { + void call(Function function) { // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'IntUnaryOperator'}} + } + } + + static class InferedTypeTree { + java.util.Optional> fun() { + return null; + } + + boolean test(String str) { + return fun().map(f -> consume(f, str)).isPresent(); + } + + boolean test2(String str) { + return fun().map((Function f) -> consume(f, str)).isPresent(); + } + + java.util.Optional> consume(Function f, String str) { // Compliant because we don't apply the rule when wildcards are used + return null; + } + } + + static int noIssueWhenUsedAsMethodReference(Stream objectStream, Object object) { + // The usage of "keyMapperFunction1" it does not allow to replace its type with ToIntFunction, + // it would not be assignable to "keyMapperFunction2" + Function keyMapperFunction1 = Object::hashCode; + + // The usage of "keyMapperFunction2" it does not allow to replace its type with ToIntFunction, + // it would not be compatible with the bellow "Collectors.toMap" + Function keyMapperFunction2 = keyMapperFunction1; + objectStream.collect(Collectors.toMap(keyMapperFunction2, Function.identity())); + + // "keyMapperFunction3" is not used as a reference, so it's OK to replace it with ToIntFunction + Function keyMapperFunction3 = Object::hashCode; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'ToIntFunction'}} + int value = keyMapperFunction3.apply(object); + value = value + keyMapperFunction3.apply(value) + Math.abs(keyMapperFunction3.apply(value)); + value += keyMapperFunction3.apply(value); + if (value > 0) { + return keyMapperFunction3.apply(value); + } + + BiConsumer m1_1 = (a, b) -> System.setProperty(a, String.valueOf(b)); // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'ObjIntConsumer'}} + m1_1.accept("", 2); + m1_1.accept("", 3); + BiConsumer m1_2 = (a, b) -> System.setProperty(a, String.valueOf(b)); + m1_2.accept("", 2); + foo(m1_2); + Consumer m2_1 = (a) -> System.setProperty("x", String.valueOf(a)); // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'IntConsumer'}} + m2_1.accept(2); + Consumer m2_2 = (a) -> System.setProperty("x", String.valueOf(a)); + foo(m2_2); + Supplier m3_1 = () -> 42; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'IntSupplier'}} + foo(m3_1.get()); + Supplier m3_2 = () -> 42; + foo(m3_2); + Function m4_1 = (a) -> a + 1; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'IntUnaryOperator'}} + int x4_1 = m4_1.apply(3) + 2; + Function m4_2 = (a) -> a + 1; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'UnaryOperator'}} + Stream.of(1, 2, 3).map(m4_2).forEach(x -> foo(x)); + Function m5_1 = (a) -> "true".equals(a); // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'Predicate'}} + foo(m5_1.apply("") ? 1 : 2); + Function m5_2 = (a) -> "true".equals(a); + foo(m5_2); + Function m6_1 = Long::valueOf; // Noncompliant {{Refactor this code to use the more specialised Functional Interface 'IntToLongFunction'}} + LongSupplier s = () -> m6_1.apply(12); + Function m6_2 = Long::valueOf; + foo(m6_2); + return m4_1.apply(7); + } + + static void foo(Object object) { + + } + + void functionsWithDefaultMethods() { + Function myFunctionLB = l -> l > 42L; // Compliant, uses compose/andThen + myFunctionLB.andThen(s -> s && true); + myFunctionLB.compose((Object o) -> o.hashCode() + 42L); + + Function myFunctionIB = i -> i > 42; // Compliant, uses compose/andThen + myFunctionIB.andThen(s -> s && true); + myFunctionIB.compose((Object o) -> o.hashCode() + 42); + + Function myFunctionDB = i -> i > 42.5; // Compliant, uses compose/andThen + myFunctionDB.andThen(s -> s && true); + myFunctionDB.compose((Object o) -> (double)o.hashCode() + 42.8); + + Function myFunctionLS = l -> l > 42L ? "big" : "small"; // Compliant, uses compose/andThen + myFunctionLS.andThen(s -> s.length() + 42); + myFunctionLS.compose((Object o) -> o.hashCode() + 42L); + + Function myFunctionLI = l -> l > 42L ? l.compareTo(100L) : l.compareTo(1000L); // Compliant, uses compose/andThen + myFunctionLI.andThen(s -> s + 42); + myFunctionLI.compose((Object o) -> o.hashCode() + 42L); + + Function myFunctionSD = s -> s.length() > 42 ? 100.01 : 10.002; // Compliant, uses compose/andThen + myFunctionSD.andThen(s -> s + 42); + myFunctionSD.compose((Object o) -> o.hashCode() + "42L"); + } + + void biFunctionsWithDefaultMethods() { + BiFunction myFunctionLB = (s, l) -> l > 42L; // Compliant, uses andThen + myFunctionLB.andThen(s -> s && true); + + BiFunction myFunctionIB = (s, i) -> i > 42; // Compliant, uses andThen + myFunctionIB.andThen(s -> s && true); + + BiFunction myFunctionDB = (s, d) -> d > 42.5; // Compliant, uses andThen + myFunctionDB.andThen(s -> s && true); + } + + void biConsumersWithDefaultMethods() { + BiConsumer myConsumerLB = (s, l) -> System.out.println(s + l); // Compliant, uses andThen + myConsumerLB.andThen((s, l) -> System.out.println("After" + s + l)); + + BiConsumer myConsumerIB = (s, i) -> System.out.println(s + i); // Compliant, uses andThen + myConsumerIB.andThen((s, l) -> System.out.println("After" + s + l)); + + BiConsumer myConsumerDB = (s, d) -> System.out.println(s + d); // Compliant, uses andThen + myConsumerDB.andThen((s, l) -> System.out.println("After" + s + l)); + } + + void biConsumersWithWrappers() { + BiConsumer myConsumerII = (s, l) -> System.out.println(s + l); // Compliant + BiConsumer myConsumerIL = (s, l) -> System.out.println(s + l); // Compliant + BiConsumer myConsumerID = (s, l) -> System.out.println(s + l); // Compliant + + BiConsumer myConsumerLI = (s, l) -> System.out.println(s + l); // Compliant + BiConsumer myConsumerLL = (s, l) -> System.out.println(s + l); // Compliant + BiConsumer myConsumerLD = (s, l) -> System.out.println(s + l); // Compliant + + BiConsumer myConsumerDI = (s, l) -> System.out.println(s + l); // Compliant + BiConsumer myConsumerDL = (s, l) -> System.out.println(s + l); // Compliant + BiConsumer myConsumerDD = (s, l) -> System.out.println(s + l); // Compliant + + BiConsumer myConsumerCD = (s, l) -> System.out.println(s + l); // Compliant + BiConsumer myConsumerFL = (s, l) -> System.out.println(s + l); // Compliant + BiConsumer myConsumerBI = (s, l) -> System.out.println(s + l); // Compliant + BiConsumer myConsumerSI = (s, l) -> System.out.println(s + l); // Compliant + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/SpecializedFunctionalInterfacesCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/SpecializedFunctionalInterfacesCheckSample.textproto.gz new file mode 100644 index 00000000000..9b48c28e3cd Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/SpecializedFunctionalInterfacesCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/StringFormatCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/StringFormatCheckSample.expected.txt.gz new file mode 100644 index 00000000000..2a20df72a19 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/StringFormatCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/StringFormatCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/StringFormatCheckSample.java new file mode 100644 index 00000000000..f4c7fca3c51 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/StringFormatCheckSample.java @@ -0,0 +1,223 @@ +package checks; + +import java.util.Formattable; +import java.util.Locale; + +class StringFormatCheckSample { + + String simple(Object value) { + return String.format("%s", value); // Noncompliant {{Use String.valueOf() instead of String.format().}} + } + + String path(String directory, String filename) { + return String.format("%s/%s", directory, filename); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String label(String key, Object value) { + return String.format("%s: %s", key, value); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String wrapped(String value) { + return String.format("prefix-%s-suffix", value); // compliant: format string is too long (>= 15 chars) + } + + String localized(Object value) { + return String.format(Locale.ROOT, "%s", value); // Noncompliant {{Use String.valueOf() instead of String.format().}} + } + + String escapedPercent(String value) { + return String.format("100%%: %s", value); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String numeric(double amount) { + return String.format("%.2f", amount); // compliant + } + + String padded(int value) { + return String.format("0x%08X", value); // compliant + } + + String aligned(String name) { + return String.format("%-20s", name); // compliant + } + + String date(long timestamp) { + return String.format("%tF", timestamp); // compliant + } + + String dynamic(String format, Object value) { + return String.format(format, value); // compliant + } + + String composed(String prefix, Object value) { + return String.format(prefix + "%s", value); // compliant + } + + String extra(Object value, Object unused) { + return String.format("%s", value, unused); // compliant + } + + String missing() { + return String.format("%s"); // compliant + } + + String indexed(Object value) { + return String.format("%1$s", value); // compliant + } + + String literalPercent() { + return String.format("100%%"); // compliant + } + + String array(Object[] values) { + return String.format("%s", values); // compliant + } + + String stringArray(String[] values) { + return String.format("%s", values); // compliant + } + + String charArray(char[] values) { + return String.format("%s", values); // compliant + } + + String intArray(int[] values) { + return String.format("%s", values); // compliant + } + + String emptyFormat() { + return String.format(""); // compliant + } + + String noPlaceholders() { + return String.format("hello"); // compliant + } + + String trailingPercent() { + return String.format("value%"); // compliant + } + + String localizedConcat(String a, String b) { + return String.format(Locale.ROOT, "%s/%s", a, b); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String multipleEscapedPercents(String value) { + return String.format("%%:%s:%%", value); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String threeArguments(String a, String b, String c) { + return String.format("%s-%s-%s", a, b, c); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String localizedNoArgs() { + return String.format(Locale.ROOT, "hello"); // compliant + } + + String localizedArray(Object[] values) { + return String.format(Locale.ROOT, "%s", values); // compliant + } + + String localizedMissing() { + return String.format(Locale.ROOT, "%s"); // compliant + } + + String localizedExtra(Object value, Object unused) { + return String.format(Locale.ROOT, "%s", value, unused); // compliant + } + + String localizedNumeric(double value) { + return String.format(Locale.ROOT, "%.2f", value); // compliant + } + + String localizedTrailingPercent() { + return String.format(Locale.ROOT, "value%"); // compliant + } + + String localizedFormattable(Formattable value) { + return String.format(Locale.ROOT, "%s", value); // compliant + } + + String localizedFormattableConcat(String prefix, Formattable value) { + return String.format(Locale.ROOT, "%s/%s", prefix, value); // compliant + } + + String nonLocalizedFormattable(Formattable value) { + return String.format("%s", value); // compliant + } + + String nonLocalizedFormattableConcat(String prefix, Formattable value) { + return String.format("%s/%s", prefix, value); // compliant + } + + String escapeSequenceInFormat(int value) { + return String.format("\045s", value); // compliant + } + + String longFormatString(String a, String b) { + return String.format("long prefix %s/%s", a, b); // compliant: format string is too long (>= 15 chars) + } + + String inBraces(String value) { + return String.format("{%s}", value); // compliant: %s is inside brackets + } + + String inParentheses(String value) { + return String.format("(%s)", value); // compliant: %s is inside brackets + } + + String inSquareBrackets(String value) { + return String.format("[%s]", value); // compliant: %s is inside brackets + } + + String inSingleQuotes(String value) { + return String.format("'%s'", value); // compliant: %s is between single quotes + } + + String inDoubleQuotes(String value) { + return String.format("\"%s\"", value); // compliant: contains escape sequences + } + + String inBackticks(String value) { + return String.format("`%s`", value); // compliant: %s is between backticks + } + + String escapedPercentInBrackets(String value) { + return String.format("[%%s] %s", value); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String escapedPercentInQuotes(String value) { + return String.format("'%%s' %s", value); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String apostropheInFormat(String owner, String item) { + return String.format("%s's %s", owner, item); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String itsFormat(String value) { + return String.format("it's %s", value); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String unmatchedClosingBracket(String value) { + return String.format(")%s", value); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String escapedPercentInBackticks(String value) { + return String.format("`%%s` %s", value); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String nestedBrackets(String value) { + return String.format("({%s})", value); // compliant: %s is inside brackets + } + + String backtickNoPlaceholder(String value) { + return String.format("`x` %s", value); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String betweenQuotedSpans(String value) { + return String.format("'x' %s 'y'", value); // Noncompliant {{Use string concatenation instead of String.format().}} + } + + String betweenBacktickSpans(String value) { + return String.format("`x` %s `y`", value); // Noncompliant {{Use string concatenation instead of String.format().}} + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/StringFormatCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/StringFormatCheckSample.textproto.gz new file mode 100644 index 00000000000..9281ea37b5c Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/StringFormatCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/TryWithResourcesCheckSample.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/TryWithResourcesCheckSample.expected.txt.gz new file mode 100644 index 00000000000..01d04e18d85 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/TryWithResourcesCheckSample.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/TryWithResourcesCheckSample.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/TryWithResourcesCheckSample.java new file mode 100644 index 00000000000..fce78eb9e71 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/TryWithResourcesCheckSample.java @@ -0,0 +1,205 @@ +package checks; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; + +class TryWithResourcesCheckSample { + String readerFactoryNonCompliant(String sequence) throws IOException { + char[] buf = new char[1024]; + Reader reader = null; + try { // Noncompliant {{Change this "try" to a try-with-resources.}} +// ^^^ + reader = Reader.of(sequence); +// ^^^^^^^^^^^^^^^^^^^< + reader.read(buf, 0, buf.length); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + if (reader != null) { + reader.close(); + } + } + return String.valueOf(buf); + } + + String readerFactoryCompliant(String sequence) { + char[] buf = new char[1024]; + try (Reader reader = Reader.of(sequence)) { // Compliant + reader.read(buf, 0, buf.length); + } catch (IOException e) { + throw new RuntimeException(e); + } + return String.valueOf(buf); + } + + String foo(String fileName) { + FileReader fr = null; + BufferedReader br = null; + try { // Noncompliant {{Change this "try" to a try-with-resources.}} +// ^^^ + fr = new FileReader(fileName); +// ^^^^^^^^^^^^^^^^^^^^^^^^< + br = new BufferedReader(fr); +// ^^^^^^^^^^^^^^^^^^^^^^< + return br.readLine(); + } catch (Exception e) { + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + } + } + if (fr != null) { + try { + br.close(); + } catch (IOException e) { + } + } + } + try { // compliant, no finally block so let's rely on unclosed resource rule + fr = new FileReader(fileName); + } catch (Exception e) { + + } + try ( + FileReader fr2 = new FileReader(fileName); + BufferedReader br2 = new BufferedReader(fr)) { // compliant + return br.readLine(); + } catch (Exception e) { + } + return null; + } + + void newJustBeforeTryStatement() { + Auto a1 = new Auto(); +// ^^^^^^^^^^> + Auto a2 = new Auto(); +// ^^^^^^^^^^> + try { // Noncompliant {{Change this "try" to a try-with-resources.}} +// ^^^ + a1.doSomething(); + } finally { + a1.close(); + a2.close(); + } + } + + void newJustBeforeAndAfterTryStatement() { + Auto a1 = null; + Auto a2 = new Auto(); +// ^^^^^^^^^^> + try { // Noncompliant {{Change this "try" to a try-with-resources.}} +// ^^^ + a1 = new Auto(); +// ^^^^^^^^^^< + a1.doSomething(); + } finally { + a1.close(); + a2.close(); + } + } + + void methodBetweenNewAndTry() { + Auto a = new Auto(); + a.doSomething(); + try { + a.doSomething(); + } finally { + a.close(); + } + } + + class B { + } + + void unknownNewBetweenNewAndTry() { + Auto a = new Auto(); + B b = new B(); + try { + a.doSomething(); + } finally { + a.close(); + } + } + + Auto passThrough(Auto a) { + return a; + } + + void newInsideMethodInvocation() { + Auto a = passThrough(new Auto()); // Compliant, we do not know what happens in the method + try { + a.doSomething(); + } finally { + a.close(); + } + } + + void newJustBeforeTryWithResource() { + Auto a1 = new Auto(); + try (Auto a2 = new Auto()) { + a1.doSomething(); + } finally { + a1.close(); + } + } + + void enclosedTryWithFinallyStatements() { + Auto a1 = new Auto(); +// ^^^^^^^^^^> + try { // Noncompliant {{Change this "try" to a try-with-resources.}} +// ^^^ + a1.doSomething(); + Auto a2 = new Auto(); +// ^^^^^^^^^^< + try { + a2.doSomething(); + } finally { + a2.close(); + } + } finally { + a1.close(); + } + } + + void enclosedTryStatements() { + Auto a1 = new Auto(); +// ^^^^^^^^^^> + try { // Noncompliant {{Change this "try" to a try-with-resources.}} +// ^^^ + a1.doSomething(); + Auto a2 = new Auto(); +// ^^^^^^^^^^< + try { + a2.doSomething(); + a2.close(); + } catch (Exception e) { + } + } finally { + a1.close(); + } + } + + void method_with_while_continue(boolean a) { + while (a) { + new java.io.BufferedInputStream(null, 4096); + try { // Noncompliant + } finally { + continue; + } + } + } + + static class Auto implements AutoCloseable { + public void doSomething() { + } + + @Override + public void close() { + } + } + +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/TryWithResourcesCheckSample.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/TryWithResourcesCheckSample.textproto.gz new file mode 100644 index 00000000000..8919f5ec786 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/corpus/TryWithResourcesCheckSample.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/ImplicitClass.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/ImplicitClass.expected.txt new file mode 100644 index 00000000000..570503c8260 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/ImplicitClass.expected.txt @@ -0,0 +1,141 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id util unknown : ? +TOKEN @1:13 +TOKEN @1:17 +IDENTIFIER @1:18 id List unknown : ? +TOKEN @1:18 +TOKEN @1:22 +IMPLICIT_CLASS @5:1 class .ImplicitClass [t package] : ImplicitClass super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing ImplicitClass flags [package] members [, counter, greet, main] lookupToString 0 outermost ImplicitClass annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring ImplicitClass +MODIFIERS +TYPE_PARAMETERS +LIST +LIST +VARIABLE @5:1 var ImplicitClass.counter [v package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ImplicitClass flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @5:1 : int +TOKEN @5:1 +IDENTIFIER @5:5 id counter ImplicitClass.counter [v package] : int : int +TOKEN @5:5 +TOKEN @5:13 +INT_LITERAL @5:15 : int = 0 +TOKEN @5:15 +TOKEN @5:16 +METHOD @7:1 method ImplicitClass.main [m package] : ? () returns void throws [] sig ImplicitClass#main()V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ImplicitClass flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @7:1 : void +TOKEN @7:1 +IDENTIFIER @7:6 id main ImplicitClass.main [m package] : ? () returns void throws [] sig ImplicitClass#main()V : void +TOKEN @7:6 +TOKEN @7:10 +TOKEN @7:11 +BLOCK @7:13 +TOKEN @7:13 +FOR_EACH_STATEMENT @8:3 +TOKEN @8:3 +TOKEN @8:7 +VARIABLE @8:8 var main.name [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ImplicitClass flags [package] local true parameter false effectivelyFinal true constant null owner main ImplicitClass#main()V [package] returns void parameters 0 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing ImplicitClass type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @8:8 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @8:8 +IDENTIFIER @8:15 id name main.name [v package] : java.lang.String : java.lang.String +TOKEN @8:15 +TOKEN @8:20 +METHOD_INVOCATION @8:22 call List.of [m static public] : ? (java.lang.String,java.lang.String) returns java.util.List throws [] sig java.util.List#of(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/List; : java.util.List + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing List flags [static, public] overridden [] overridable false generic true default false synchronized false varargs false native false parameters [arg0, arg1] parameterMetadata [] +MEMBER_SELECT @8:22 : ? +IDENTIFIER @8:22 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @8:22 +TOKEN @8:26 +IDENTIFIER @8:27 id of List.of [m static public] : ? (java.lang.String,java.lang.String) returns java.util.List throws [] sig java.util.List#of(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/List; : java.util.List +TOKEN @8:27 +ARGUMENTS @8:29 +TOKEN @8:29 +STRING_LITERAL @8:30 : java.lang.String = world +TOKEN @8:30 +TOKEN @8:37 +STRING_LITERAL @8:39 : java.lang.String = moon +TOKEN @8:39 +TOKEN @8:45 +TOKEN @8:46 +BLOCK @8:48 +TOKEN @8:48 +EXPRESSION_STATEMENT @9:5 +POSTFIX_INCREMENT @9:5 : int +IDENTIFIER @9:5 id counter ImplicitClass.counter [v package] : int : int +TOKEN @9:5 +TOKEN @9:12 +TOKEN @9:14 +EXPRESSION_STATEMENT @10:5 +METHOD_INVOCATION @10:5 call PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void + details declared false usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing PrintStream flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @10:5 : ? +MEMBER_SELECT @10:5 : java.io.PrintStream +IDENTIFIER @10:5 id System java.lang.System [t final public] : java.lang.System : java.lang.System +TOKEN @10:5 +TOKEN @10:11 +IDENTIFIER @10:12 id out System.out [v static final public] : java.io.PrintStream : java.io.PrintStream +TOKEN @10:12 +TOKEN @10:15 +IDENTIFIER @10:16 id println PrintStream.println [m public] : ? (java.lang.String) returns void throws [] sig java.io.PrintStream#println(Ljava/lang/String;)V : void +TOKEN @10:16 +ARGUMENTS @10:23 +TOKEN @10:23 +PLUS @10:24 : java.lang.String +METHOD_INVOCATION @10:24 call ImplicitClass.greet [m package] : ? (java.lang.String) returns java.lang.String throws [] sig ImplicitClass#greet(Ljava/lang/String;)Ljava/lang/String; : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ImplicitClass flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [name] parameterMetadata [] +IDENTIFIER @10:24 id greet ImplicitClass.greet [m package] : ? (java.lang.String) returns java.lang.String throws [] sig ImplicitClass#greet(Ljava/lang/String;)Ljava/lang/String; : java.lang.String +TOKEN @10:24 +ARGUMENTS @10:29 +TOKEN @10:29 +IDENTIFIER @10:30 id name main.name [v package] : java.lang.String : java.lang.String +TOKEN @10:30 +TOKEN @10:34 +TOKEN @10:36 +IDENTIFIER @10:38 id counter ImplicitClass.counter [v package] : int : int +TOKEN @10:38 +TOKEN @10:45 +TOKEN @10:46 +TOKEN @11:3 +TOKEN @12:1 +METHOD @15:1 method ImplicitClass.greet [m package] : ? (java.lang.String) returns java.lang.String throws [] sig ImplicitClass#greet(Ljava/lang/String;)Ljava/lang/String; overrides false + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ImplicitClass flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [name] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +IDENTIFIER @15:1 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @15:1 +IDENTIFIER @15:8 id greet ImplicitClass.greet [m package] : ? (java.lang.String) returns java.lang.String throws [] sig ImplicitClass#greet(Ljava/lang/String;)Ljava/lang/String; : java.lang.String +TOKEN @15:8 +TOKEN @15:13 +VARIABLE @15:14 var greet.name [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing ImplicitClass flags [package] local true parameter true effectivelyFinal true constant null owner greet ImplicitClass#greet(Ljava/lang/String;)Ljava/lang/String; [package] returns java.lang.String parameters 1 thrown 0 overridden 0 declared true usages 1 metadata 0 enclosing ImplicitClass type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @15:14 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @15:14 +IDENTIFIER @15:21 id name greet.name [v package] : java.lang.String : java.lang.String +TOKEN @15:21 +TOKEN @15:25 +BLOCK @15:27 +TOKEN @15:27 +RETURN_STATEMENT @16:3 +TOKEN @16:3 +PLUS @16:10 : java.lang.String +STRING_LITERAL @16:10 : java.lang.String = Hello +TOKEN @16:10 +TOKEN @16:19 +IDENTIFIER @16:21 id name greet.name [v package] : java.lang.String : java.lang.String +TOKEN @16:21 +TOKEN @16:25 +TOKEN @17:1 +TOKEN @18:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/ImplicitClass.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/ImplicitClass.java new file mode 100644 index 00000000000..46d25ecfef1 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/ImplicitClass.java @@ -0,0 +1,17 @@ +import java.util.List; + +/// The number of greetings +/// printed so far. +int counter = 0; + +void main() { + for (String name : List.of("world", "moon")) { + counter++; + System.out.println(greet(name) + counter); + } +} + +/// Greets `name`. +String greet(String name) { + return "Hello " + name; +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/ImplicitClass.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/ImplicitClass.textproto.gz new file mode 100644 index 00000000000..68ab72b22cf Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/ImplicitClass.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/Unnamed.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/Unnamed.expected.txt new file mode 100644 index 00000000000..3b5e72a4b12 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/Unnamed.expected.txt @@ -0,0 +1,475 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id io unknown : ? +TOKEN @1:13 +TOKEN @1:15 +IDENTIFIER @1:16 id IOException unknown : ? +TOKEN @1:16 +TOKEN @1:27 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id io unknown : ? +TOKEN @2:13 +TOKEN @2:15 +IDENTIFIER @2:16 id StringReader unknown : ? +TOKEN @2:16 +TOKEN @2:28 +IMPORT @3:1 +TOKEN @3:1 +MEMBER_SELECT @3:8 : ? +MEMBER_SELECT @3:8 : ? +IDENTIFIER @3:8 id java unknown : ? +TOKEN @3:8 +TOKEN @3:12 +IDENTIFIER @3:13 id util unknown : ? +TOKEN @3:13 +TOKEN @3:17 +IDENTIFIER @3:18 id List unknown : ? +TOKEN @3:18 +TOKEN @3:22 +IMPORT @4:1 +TOKEN @4:1 +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +MEMBER_SELECT @4:8 : ? +IDENTIFIER @4:8 id java unknown : ? +TOKEN @4:8 +TOKEN @4:12 +IDENTIFIER @4:13 id util unknown : ? +TOKEN @4:13 +TOKEN @4:17 +IDENTIFIER @4:18 id function unknown : ? +TOKEN @4:18 +TOKEN @4:26 +IDENTIFIER @4:27 id BiFunction unknown : ? +TOKEN @4:27 +TOKEN @4:37 +CLASS @6:1 class .Unnamed [t package] : Unnamed super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [package] members [, Point, count, first, keepFirst, parse, read, shared] lookupToString 0 outermost Unnamed annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring Unnamed +MODIFIERS +TOKEN @6:1 +IDENTIFIER @6:7 id Unnamed .Unnamed [t package] : Unnamed : Unnamed +TOKEN @6:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @6:15 +RECORD @7:3 class Unnamed.Point [t static final package] : Unnamed$Point super java.lang.Record interfaces [] + details declared true usages 2 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [static, final, package] members [, x, x, y, y] lookupToString 0 outermost Unnamed annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object, java.lang.Record] numerical false wrapper false raw false declaring Point +MODIFIERS +TOKEN @7:3 +IDENTIFIER @7:10 id Point Unnamed.Point [t static final package] : Unnamed$Point : Unnamed$Point +TOKEN @7:10 +TYPE_PARAMETERS +TOKEN @7:15 +VARIABLE @7:16 var Point.x [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Point flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @7:16 : int +TOKEN @7:16 +IDENTIFIER @7:20 id x Point.x [v package] : int : int +TOKEN @7:20 +TOKEN @7:21 +VARIABLE @7:23 var Point.y [v package] : int + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Point flags [package] local false parameter false effectivelyFinal false constant null +MODIFIERS +PRIMITIVE_TYPE @7:23 : int +TOKEN @7:23 +IDENTIFIER @7:27 id y Point.y [v package] : int : int +TOKEN @7:27 +TOKEN @7:28 +LIST +LIST +TOKEN @7:30 +TOKEN @8:3 +VARIABLE @10:3 var Unnamed.shared [v final private] : java.io.StringReader + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [final, private] local false parameter false effectivelyFinal true constant null +MODIFIERS @10:3 +TOKEN @10:3 +TOKEN @10:11 +IDENTIFIER @10:17 id StringReader java.io.StringReader [t public] : java.io.StringReader : java.io.StringReader +TOKEN @10:17 +IDENTIFIER @10:30 id shared Unnamed.shared [v final private] : java.io.StringReader : java.io.StringReader +TOKEN @10:30 +TOKEN @10:37 +NEW_CLASS @10:39 new StringReader. [m public] : ? (java.lang.String) returns void throws [] sig java.io.StringReader#(Ljava/lang/String;)V : java.io.StringReader + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StringReader flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @10:39 +IDENTIFIER @10:43 id StringReader StringReader. [m public] : ? (java.lang.String) returns void throws [] sig java.io.StringReader#(Ljava/lang/String;)V : java.io.StringReader +TOKEN @10:43 +ARGUMENTS @10:55 +TOKEN @10:55 +STRING_LITERAL @10:56 : java.lang.String = shared +TOKEN @10:56 +TOKEN @10:64 +TOKEN @10:65 +METHOD @12:3 method Unnamed.count [m package] : ? (java.util.List) returns int throws [] sig Unnamed#count(Ljava/util/List;)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [items] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @12:3 : int +TOKEN @12:3 +IDENTIFIER @12:7 id count Unnamed.count [m package] : ? (java.util.List) returns int throws [] sig Unnamed#count(Ljava/util/List;)I : int +TOKEN @12:7 +TOKEN @12:12 +VARIABLE @12:13 var count.items [v package] : java.util.List + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[]] enclosing Unnamed flags [package] local true parameter true effectivelyFinal true constant null owner count Unnamed#count(Ljava/util/List;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Unnamed type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PARAMETERIZED_TYPE @12:13 : java.util.List +IDENTIFIER @12:13 id List java.util.List [t public interface] : java.util.List : java.util.List +TOKEN @12:13 +TYPE_ARGUMENTS @12:17 +TOKEN @12:17 +IDENTIFIER @12:18 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @12:18 +TOKEN @12:24 +IDENTIFIER @12:26 id items count.items [v package] : java.util.List : java.util.List +TOKEN @12:26 +TOKEN @12:31 +BLOCK @12:33 +TOKEN @12:33 +VARIABLE @13:5 var count.total [v package] : int + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [package] local true parameter false effectivelyFinal false constant null owner count Unnamed#count(Ljava/util/List;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Unnamed type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @13:5 : int +TOKEN @13:5 +IDENTIFIER @13:9 id total count.total [v package] : int : int +TOKEN @13:9 +TOKEN @13:15 +INT_LITERAL @13:17 : int = 0 +TOKEN @13:17 +TOKEN @13:18 +FOR_EACH_STATEMENT @14:5 +TOKEN @14:5 +TOKEN @14:9 +VARIABLE @14:10 var !unknown!._ [v package] : ? + details declared true usages 0 metadata [] nullability UNKNOWN/VARIABLE nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing null flags [package] local true parameter false effectivelyFinal true constant null +MODIFIERS +VAR_TYPE @14:10 +TOKEN @14:10 +IDENTIFIER @14:14 id _ unknown : ? +TOKEN @14:14 +TOKEN @14:16 +IDENTIFIER @14:18 id items count.items [v package] : java.util.List : java.util.List +TOKEN @14:18 +TOKEN @14:23 +BLOCK @14:25 +TOKEN @14:25 +EXPRESSION_STATEMENT @15:7 +POSTFIX_INCREMENT @15:7 : int +IDENTIFIER @15:7 id total count.total [v package] : int : int +TOKEN @15:7 +TOKEN @15:12 +TOKEN @15:14 +TOKEN @16:5 +RETURN_STATEMENT @17:5 +TOKEN @17:5 +IDENTIFIER @17:12 id total count.total [v package] : int : int +TOKEN @17:12 +TOKEN @17:17 +TOKEN @18:3 +METHOD @20:3 method Unnamed.parse [m package] : ? (java.lang.String) returns int throws [] sig Unnamed#parse(Ljava/lang/String;)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [text] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @20:3 : int +TOKEN @20:3 +IDENTIFIER @20:7 id parse Unnamed.parse [m package] : ? (java.lang.String) returns int throws [] sig Unnamed#parse(Ljava/lang/String;)I : int +TOKEN @20:7 +TOKEN @20:12 +VARIABLE @20:13 var parse.text [v package] : java.lang.String + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [package] local true parameter true effectivelyFinal true constant null owner parse Unnamed#parse(Ljava/lang/String;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Unnamed type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @20:13 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @20:13 +IDENTIFIER @20:20 id text parse.text [v package] : java.lang.String : java.lang.String +TOKEN @20:20 +TOKEN @20:24 +BLOCK @20:26 +TOKEN @20:26 +TRY_STATEMENT @21:5 +TOKEN @21:5 +BLOCK @21:9 +TOKEN @21:9 +RETURN_STATEMENT @22:7 +TOKEN @22:7 +METHOD_INVOCATION @22:14 call Integer.parseInt [m static public] : ? (java.lang.String) returns int throws [java.lang.NumberFormatException] sig java.lang.Integer#parseInt(Ljava/lang/String;)I : int + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Integer flags [static, public] overridden [] overridable false generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +MEMBER_SELECT @22:14 : ? +IDENTIFIER @22:14 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @22:14 +TOKEN @22:21 +IDENTIFIER @22:22 id parseInt Integer.parseInt [m static public] : ? (java.lang.String) returns int throws [java.lang.NumberFormatException] sig java.lang.Integer#parseInt(Ljava/lang/String;)I : int +TOKEN @22:22 +ARGUMENTS @22:30 +TOKEN @22:30 +IDENTIFIER @22:31 id text parse.text [v package] : java.lang.String : java.lang.String +TOKEN @22:31 +TOKEN @22:35 +TOKEN @22:36 +TOKEN @23:5 +CATCH @23:7 +TOKEN @23:7 +TOKEN @23:13 +VARIABLE @23:14 var parse._ [v package] : java.lang.NumberFormatException + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [package] local true parameter false effectivelyFinal true constant null owner parse Unnamed#parse(Ljava/lang/String;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Unnamed type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @23:14 id NumberFormatException java.lang.NumberFormatException [t public] : java.lang.NumberFormatException : java.lang.NumberFormatException +TOKEN @23:14 +IDENTIFIER @23:36 id _ unknown : java.lang.NumberFormatException +TOKEN @23:36 +TOKEN @23:37 +BLOCK @23:39 +TOKEN @23:39 +RETURN_STATEMENT @24:7 +TOKEN @24:7 +UNARY_MINUS @24:14 : int = -1 +TOKEN @24:14 +INT_LITERAL @24:15 : int = 1 +TOKEN @24:15 +TOKEN @24:16 +TOKEN @25:5 +TOKEN @26:3 +METHOD @28:3 method Unnamed.first [m package] : ? (java.lang.Object) returns int throws [] sig Unnamed#first(Ljava/lang/Object;)I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [o] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @28:3 : int +TOKEN @28:3 +IDENTIFIER @28:7 id first Unnamed.first [m package] : ? (java.lang.Object) returns int throws [] sig Unnamed#first(Ljava/lang/Object;)I : int +TOKEN @28:7 +TOKEN @28:12 +VARIABLE @28:13 var first.o [v package] : java.lang.Object + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [package] local true parameter true effectivelyFinal true constant null owner first Unnamed#first(Ljava/lang/Object;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Unnamed type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +IDENTIFIER @28:13 id Object java.lang.Object [t public] : java.lang.Object : java.lang.Object +TOKEN @28:13 +IDENTIFIER @28:20 id o first.o [v package] : java.lang.Object : java.lang.Object +TOKEN @28:20 +TOKEN @28:21 +BLOCK @28:23 +TOKEN @28:23 +IF_STATEMENT @29:5 +TOKEN @29:5 +TOKEN @29:8 +PATTERN_INSTANCE_OF @29:9 : boolean +IDENTIFIER @29:9 id o first.o [v package] : java.lang.Object : java.lang.Object +TOKEN @29:9 +TOKEN @29:11 +RECORD_PATTERN @29:22 : Unnamed$Point +IDENTIFIER @29:22 id Point Unnamed.Point [t static final package] : Unnamed$Point : Unnamed$Point +TOKEN @29:22 +TOKEN @29:27 +TYPE_PATTERN @29:28 : int +VARIABLE @29:28 var first.x [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [package] local true parameter false effectivelyFinal true constant null owner first Unnamed#first(Ljava/lang/Object;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Unnamed type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @29:28 : int +TOKEN @29:28 +IDENTIFIER @29:32 id x first.x [v package] : int : int +TOKEN @29:32 +TYPE_PATTERN @29:35 : int +VARIABLE @29:35 var !unknown!._ [v package] : int + details declared true usages 0 metadata [] nullability UNKNOWN/VARIABLE nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing null flags [package] local true parameter false effectivelyFinal true constant null +MODIFIERS +INFERED_TYPE +IDENTIFIER @29:35 id _ unknown : ? +TOKEN @29:35 +TOKEN @29:36 +TOKEN @29:37 +BLOCK @29:39 +TOKEN @29:39 +RETURN_STATEMENT @30:7 +TOKEN @30:7 +IDENTIFIER @30:14 id x first.x [v package] : int : int +TOKEN @30:14 +TOKEN @30:15 +TOKEN @31:5 +RETURN_STATEMENT @32:5 +TOKEN @32:5 +SWITCH_EXPRESSION @32:12 : int +TOKEN @32:12 +TOKEN @32:19 +IDENTIFIER @32:20 id o first.o [v package] : java.lang.Object : java.lang.Object +TOKEN @32:20 +TOKEN @32:21 +TOKEN @32:23 +CASE_GROUP @33:7 +CASE_LABEL @33:7 +TOKEN @33:7 +RECORD_PATTERN @33:12 : Unnamed$Point +IDENTIFIER @33:12 id Point Unnamed.Point [t static final package] : Unnamed$Point : Unnamed$Point +TOKEN @33:12 +TOKEN @33:17 +TYPE_PATTERN @33:18 : int +VARIABLE @33:18 var !unknown!._ [v package] : int + details declared true usages 0 metadata [] nullability UNKNOWN/VARIABLE nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing null flags [package] local true parameter false effectivelyFinal true constant null +MODIFIERS +INFERED_TYPE +IDENTIFIER @33:18 id _ unknown : ? +TOKEN @33:18 +TYPE_PATTERN @33:21 : int +VARIABLE @33:21 var first.y [v package] : int + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [package] local true parameter false effectivelyFinal true constant null owner first Unnamed#first(Ljava/lang/Object;)I [package] returns int parameters 1 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing Unnamed type true kinds truefalsefalse other falsefalsefalsefalsetruefalse1falsefalse +MODIFIERS +PRIMITIVE_TYPE @33:21 : int +TOKEN @33:21 +IDENTIFIER @33:25 id y first.y [v package] : int : int +TOKEN @33:25 +TOKEN @33:26 +TOKEN @33:28 +YIELD_STATEMENT @33:31 +IDENTIFIER @33:31 id y first.y [v package] : int : int +TOKEN @33:31 +TOKEN @33:32 +CASE_GROUP @34:7 +CASE_LABEL @34:7 +TOKEN @34:7 +TOKEN @34:15 +YIELD_STATEMENT @34:18 +INT_LITERAL @34:18 : int = 0 +TOKEN @34:18 +TOKEN @34:19 +TOKEN @35:5 +TOKEN @35:6 +TOKEN @36:3 +METHOD @38:3 method Unnamed.keepFirst [m package] : ? () returns java.util.function.BiFunction throws [] sig Unnamed#keepFirst()Ljava/util/function/BiFunction; overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [[], [], []] enclosing Unnamed flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [[] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [], [] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [], [] nullability NO_ANNOTATION/VARIABLE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups []] +MODIFIERS +TYPE_PARAMETERS +PARAMETERIZED_TYPE @38:3 : java.util.function.BiFunction +IDENTIFIER @38:3 id BiFunction java.util.function.BiFunction [t public interface] : java.util.function.BiFunction @java.lang.FunctionalInterface : java.util.function.BiFunction +TOKEN @38:3 +TYPE_ARGUMENTS @38:13 +TOKEN @38:13 +IDENTIFIER @38:14 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @38:14 +TOKEN @38:20 +IDENTIFIER @38:22 id Integer java.lang.Integer [t final public] : java.lang.Integer @jdk.internal.ValueBased : java.lang.Integer +TOKEN @38:22 +TOKEN @38:29 +IDENTIFIER @38:31 id String java.lang.String [t final public] : java.lang.String : java.lang.String +TOKEN @38:31 +TOKEN @38:37 +IDENTIFIER @38:39 id keepFirst Unnamed.keepFirst [m package] : ? () returns java.util.function.BiFunction throws [] sig Unnamed#keepFirst()Ljava/util/function/BiFunction; : java.util.function.BiFunction +TOKEN @38:39 +TOKEN @38:48 +TOKEN @38:49 +BLOCK @38:51 +TOKEN @38:51 +RETURN_STATEMENT @39:5 +TOKEN @39:5 +LAMBDA_EXPRESSION @39:12 : java.util.function.BiFunction +TOKEN @39:12 +VARIABLE @39:13 var apply.s [v package] : java.lang.String + details declared true usages 1 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing BiFunction flags [package] local true parameter true effectivelyFinal true constant null owner apply java.util.function.BiFunction#apply(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; [abstract, public] returns java.lang.String parameters 2 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing BiFunction type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @39:13 id s apply.s [v package] : java.lang.String : java.lang.String +TOKEN @39:13 +TOKEN @39:14 +VARIABLE @39:16 var apply._ [v package] : java.lang.Integer + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing BiFunction flags [package] local true parameter true effectivelyFinal true constant null owner apply java.util.function.BiFunction#apply(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; [abstract, public] returns java.lang.String parameters 2 thrown 0 overridden 0 declared false usages 0 metadata 0 enclosing BiFunction type true kinds truefalsefalse other falsefalsefalsefalsetruefalse2falsefalse +MODIFIERS +INFERED_TYPE +IDENTIFIER @39:16 id _ unknown : java.lang.Integer +TOKEN @39:16 +TOKEN @39:17 +TOKEN @39:19 +IDENTIFIER @39:22 id s apply.s [v package] : java.lang.String : java.lang.String +TOKEN @39:22 +TOKEN @39:23 +TOKEN @40:3 +METHOD @42:3 method Unnamed.read [m package] : ? () returns int throws [java.io.IOException] sig Unnamed#read()I overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @42:3 : int +TOKEN @42:3 +IDENTIFIER @42:7 id read Unnamed.read [m package] : ? () returns int throws [java.io.IOException] sig Unnamed#read()I : int +TOKEN @42:7 +TOKEN @42:11 +TOKEN @42:12 +TOKEN @42:14 +LIST @42:21 +IDENTIFIER @42:21 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @42:21 +BLOCK @42:33 +TOKEN @42:33 +VARIABLE @43:5 var read.local [v package] : java.io.StringReader + details declared true usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Unnamed flags [package] local true parameter false effectivelyFinal true constant null owner read Unnamed#read()I [package] returns int parameters 0 thrown 1 overridden 0 declared true usages 0 metadata 0 enclosing Unnamed type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @43:5 id StringReader java.io.StringReader [t public] : java.io.StringReader : java.io.StringReader +TOKEN @43:5 +IDENTIFIER @43:18 id local read.local [v package] : java.io.StringReader : java.io.StringReader +TOKEN @43:18 +TOKEN @43:24 +NEW_CLASS @43:26 new StringReader. [m public] : ? (java.lang.String) returns void throws [] sig java.io.StringReader#(Ljava/lang/String;)V : java.io.StringReader + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StringReader flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [arg0] parameterMetadata [] +TOKEN @43:26 +IDENTIFIER @43:30 id StringReader StringReader. [m public] : ? (java.lang.String) returns void throws [] sig java.io.StringReader#(Ljava/lang/String;)V : java.io.StringReader +TOKEN @43:30 +ARGUMENTS @43:42 +TOKEN @43:42 +STRING_LITERAL @43:43 : java.lang.String = local +TOKEN @43:43 +TOKEN @43:50 +TOKEN @43:51 +TRY_STATEMENT @44:5 +TOKEN @44:5 +TOKEN @44:9 +LIST @44:10 +IDENTIFIER @44:10 id local read.local [v package] : java.io.StringReader : java.io.StringReader +TOKEN @44:10 +TOKEN @44:15 +MEMBER_SELECT @44:17 : java.io.StringReader +IDENTIFIER @44:17 id this Unnamed.this [v final] : Unnamed : Unnamed +TOKEN @44:17 +TOKEN @44:21 +IDENTIFIER @44:22 id shared Unnamed.shared [v final private] : java.io.StringReader : java.io.StringReader +TOKEN @44:22 +TOKEN @44:28 +BLOCK @44:30 +TOKEN @44:30 +RETURN_STATEMENT @45:7 +TOKEN @45:7 +PLUS @45:14 : int +METHOD_INVOCATION @45:14 call StringReader.read [m public] : ? () returns int throws [java.io.IOException] sig java.io.StringReader#read()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StringReader flags [public] overridden [Reader.read[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @45:14 : ? +IDENTIFIER @45:14 id local read.local [v package] : java.io.StringReader : java.io.StringReader +TOKEN @45:14 +TOKEN @45:19 +IDENTIFIER @45:20 id read StringReader.read [m public] : ? () returns int throws [java.io.IOException] sig java.io.StringReader#read()I : int +TOKEN @45:20 +ARGUMENTS @45:24 +TOKEN @45:24 +TOKEN @45:25 +TOKEN @45:27 +METHOD_INVOCATION @45:29 call StringReader.read [m public] : ? () returns int throws [java.io.IOException] sig java.io.StringReader#read()I : int + details declared false usages 2 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing StringReader flags [public] overridden [Reader.read[]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @45:29 : ? +IDENTIFIER @45:29 id shared Unnamed.shared [v final private] : java.io.StringReader : java.io.StringReader +TOKEN @45:29 +TOKEN @45:35 +IDENTIFIER @45:36 id read StringReader.read [m public] : ? () returns int throws [java.io.IOException] sig java.io.StringReader#read()I : int +TOKEN @45:36 +ARGUMENTS @45:40 +TOKEN @45:40 +TOKEN @45:41 +TOKEN @45:42 +TOKEN @46:5 +TOKEN @47:3 +TOKEN @48:1 +TOKEN @49:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/Unnamed.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/Unnamed.java new file mode 100644 index 00000000000..96f441487a2 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/Unnamed.java @@ -0,0 +1,48 @@ +import java.io.IOException; +import java.io.StringReader; +import java.util.List; +import java.util.function.BiFunction; + +class Unnamed { + record Point(int x, int y) { + } + + private final StringReader shared = new StringReader("shared"); + + int count(List items) { + int total = 0; + for (var _ : items) { + total++; + } + return total; + } + + int parse(String text) { + try { + return Integer.parseInt(text); + } catch (NumberFormatException _) { + return -1; + } + } + + int first(Object o) { + if (o instanceof Point(int x, _)) { + return x; + } + return switch (o) { + case Point(_, int y) -> y; + default -> 0; + }; + } + + BiFunction keepFirst() { + return (s, _) -> s; + } + + int read() throws IOException { + StringReader local = new StringReader("local"); + try (local; this.shared) { + return local.read() + shared.read(); + } + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/Unnamed.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/Unnamed.textproto.gz new file mode 100644 index 00000000000..37836ff2d8f Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/Unnamed.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/UnnamedCatch.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/UnnamedCatch.expected.txt new file mode 100644 index 00000000000..d15347a713a --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/UnnamedCatch.expected.txt @@ -0,0 +1,110 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id io unknown : ? +TOKEN @1:13 +TOKEN @1:15 +IDENTIFIER @1:16 id FileNotFoundException unknown : ? +TOKEN @1:16 +TOKEN @1:37 +IMPORT @2:1 +TOKEN @2:1 +MEMBER_SELECT @2:8 : ? +MEMBER_SELECT @2:8 : ? +IDENTIFIER @2:8 id java unknown : ? +TOKEN @2:8 +TOKEN @2:12 +IDENTIFIER @2:13 id io unknown : ? +TOKEN @2:13 +TOKEN @2:15 +IDENTIFIER @2:16 id IOException unknown : ? +TOKEN @2:16 +TOKEN @2:27 +CLASS @4:1 class .UnnamedCatch [t package] : UnnamedCatch super java.lang.Object interfaces [] + details declared true usages 0 metadata [] nullability UNKNOWN/UNKNOWN nonNull false nullable false strongNullable false strict truetruetrue meta false source null tree false lookups [] typeArguments [] enclosing UnnamedCatch flags [package] members [, read] lookupToString 0 outermost UnnamedCatch annotation false subtypeOf [java.lang.Object] superTypes [java.lang.Object] numerical false wrapper false raw false declaring UnnamedCatch +MODIFIERS +TOKEN @4:1 +IDENTIFIER @4:7 id UnnamedCatch .UnnamedCatch [t package] : UnnamedCatch : UnnamedCatch +TOKEN @4:7 +TYPE_PARAMETERS +LIST +LIST +TOKEN @4:20 +METHOD @5:3 method UnnamedCatch.read [m package] : ? () returns void throws [] sig UnnamedCatch#read()V overrides false + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing UnnamedCatch flags [package] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MODIFIERS +TYPE_PARAMETERS +PRIMITIVE_TYPE @5:3 : void +TOKEN @5:3 +IDENTIFIER @5:8 id read UnnamedCatch.read [m package] : ? () returns void throws [] sig UnnamedCatch#read()V : void +TOKEN @5:8 +TOKEN @5:12 +TOKEN @5:13 +BLOCK @5:15 +TOKEN @5:15 +TRY_STATEMENT @6:5 +TOKEN @6:5 +BLOCK @6:9 +TOKEN @6:9 +THROW_STATEMENT @7:7 +TOKEN @7:7 +NEW_CLASS @7:13 new FileNotFoundException. [m public] : ? () returns void throws [] sig java.io.FileNotFoundException#()V : java.io.FileNotFoundException + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing FileNotFoundException flags [public] overridden [IOException.[], Exception.[], Throwable.[], Object.[jdk.internal.vm.annotation.IntrinsicCandidate tree false values 0 annotated true]] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +TOKEN @7:13 +IDENTIFIER @7:17 id FileNotFoundException FileNotFoundException. [m public] : ? () returns void throws [] sig java.io.FileNotFoundException#()V : java.io.FileNotFoundException +TOKEN @7:17 +ARGUMENTS @7:38 +TOKEN @7:38 +TOKEN @7:39 +TOKEN @7:40 +TOKEN @8:5 +CATCH @8:7 +TOKEN @8:7 +TOKEN @8:13 +VARIABLE @8:14 var read.e [v package] : java.io.FileNotFoundException + details declared true usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing UnnamedCatch flags [package] local true parameter false effectivelyFinal true constant null owner read UnnamedCatch#read()V [package] returns void parameters 0 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing UnnamedCatch type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @8:14 id FileNotFoundException java.io.FileNotFoundException [t public] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @8:14 +IDENTIFIER @8:36 id e read.e [v package] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @8:36 +TOKEN @8:37 +BLOCK @8:39 +TOKEN @8:39 +EXPRESSION_STATEMENT @9:7 +METHOD_INVOCATION @9:7 call Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void + details declared false usages 1 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing Throwable flags [public] overridden [] overridable true generic false default false synchronized false varargs false native false parameters [] parameterMetadata [] +MEMBER_SELECT @9:7 : ? +IDENTIFIER @9:7 id e read.e [v package] : java.io.FileNotFoundException : java.io.FileNotFoundException +TOKEN @9:7 +TOKEN @9:8 +IDENTIFIER @9:9 id printStackTrace Throwable.printStackTrace [m public] : ? () returns void throws [] sig java.lang.Throwable#printStackTrace()V : void +TOKEN @9:9 +ARGUMENTS @9:24 +TOKEN @9:24 +TOKEN @9:25 +TOKEN @9:26 +TOKEN @10:5 +CATCH @10:7 +TOKEN @10:7 +TOKEN @10:13 +VARIABLE @10:14 var read._ [v package] : java.io.IOException + details declared true usages 0 metadata [] nullability NO_ANNOTATION/PACKAGE nonNull false nullable false strongNullable false strict falsefalsefalse meta false source null tree false lookups [] typeArguments [] enclosing UnnamedCatch flags [package] local true parameter false effectivelyFinal true constant null owner read UnnamedCatch#read()V [package] returns void parameters 0 thrown 0 overridden 0 declared true usages 0 metadata 0 enclosing UnnamedCatch type true kinds truefalsefalse other falsefalsefalsefalsetruefalse0falsefalse +MODIFIERS +IDENTIFIER @10:14 id IOException java.io.IOException [t public] : java.io.IOException : java.io.IOException +TOKEN @10:14 +IDENTIFIER @10:26 id _ unknown : java.io.IOException +TOKEN @10:26 +TOKEN @10:27 +BLOCK @10:29 +TOKEN @10:29 +TOKEN @11:5 +TOKEN @12:3 +TOKEN @13:1 +TOKEN @14:1 +WARNING MASKED_CATCH IDENTIFIER @10:14 Unreachable catch block for IOException. Only more specific exceptions are thrown and they are handled by previous catch block(s). diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/UnnamedCatch.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/UnnamedCatch.java new file mode 100644 index 00000000000..ad22ced2655 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/UnnamedCatch.java @@ -0,0 +1,13 @@ +import java.io.FileNotFoundException; +import java.io.IOException; + +class UnnamedCatch { + void read() { + try { + throw new FileNotFoundException(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException _) { + } + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/UnnamedCatch.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/UnnamedCatch.textproto.gz new file mode 100644 index 00000000000..4ace57c40c7 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/java25/UnnamedCatch.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/module-info.expected.txt b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/module-info.expected.txt new file mode 100644 index 00000000000..f69263c4e69 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/module-info.expected.txt @@ -0,0 +1,180 @@ +COMPILATION_UNIT @1:1 +IMPORT @1:1 +TOKEN @1:1 +MEMBER_SELECT @1:8 : ? +MEMBER_SELECT @1:8 : ? +IDENTIFIER @1:8 id java unknown : ? +TOKEN @1:8 +TOKEN @1:12 +IDENTIFIER @1:13 id sql unknown : ? +TOKEN @1:13 +TOKEN @1:16 +IDENTIFIER @1:17 id Driver unknown : ? +TOKEN @1:17 +TOKEN @1:23 +MODULE @3:1 +ANNOTATION @3:1 : java.lang.Deprecated +TOKEN @3:1 +IDENTIFIER @3:2 id Deprecated java.lang.Deprecated [t public interface] : java.lang.Deprecated @java.lang.annotation.Documented,java.lang.annotation.Retention,java.lang.annotation.Target : java.lang.Deprecated +TOKEN @3:2 +ARGUMENTS +TOKEN @4:1 +TOKEN @4:6 +LIST @4:13 +IDENTIFIER @4:13 id org unknown : ? +TOKEN @4:13 +IDENTIFIER @4:17 id example unknown : ? +TOKEN @4:17 +IDENTIFIER @4:25 id app unknown : ? +TOKEN @4:25 +TOKEN @4:29 +REQUIRES_DIRECTIVE @5:3 +TOKEN @5:3 +MODIFIERS +LIST @5:12 +IDENTIFIER @5:12 id java unknown : ? +TOKEN @5:12 +IDENTIFIER @5:17 id base unknown : ? +TOKEN @5:17 +TOKEN @5:21 +REQUIRES_DIRECTIVE @6:3 +TOKEN @6:3 +MODIFIERS @6:12 +TOKEN @6:12 +LIST @6:23 +IDENTIFIER @6:23 id java unknown : ? +TOKEN @6:23 +IDENTIFIER @6:28 id logging unknown : ? +TOKEN @6:28 +TOKEN @6:35 +REQUIRES_DIRECTIVE @7:3 +TOKEN @7:3 +MODIFIERS @7:12 +TOKEN @7:12 +LIST @7:19 +IDENTIFIER @7:19 id java unknown : ? +TOKEN @7:19 +IDENTIFIER @7:24 id sql unknown : ? +TOKEN @7:24 +TOKEN @7:27 +EXPORTS_DIRECTIVE @8:3 +TOKEN @8:3 +MEMBER_SELECT @8:11 : ? +MEMBER_SELECT @8:11 : ? +IDENTIFIER @8:11 id org unknown : ? +TOKEN @8:11 +TOKEN @8:14 +IDENTIFIER @8:15 id example unknown : ? +TOKEN @8:15 +TOKEN @8:22 +IDENTIFIER @8:23 id api unknown : ? +TOKEN @8:23 +TOKEN @8:26 +EXPORTS_DIRECTIVE @9:3 +TOKEN @9:3 +MEMBER_SELECT @9:11 : ? +MEMBER_SELECT @9:11 : ? +IDENTIFIER @9:11 id org unknown : ? +TOKEN @9:11 +TOKEN @9:14 +IDENTIFIER @9:15 id example unknown : ? +TOKEN @9:15 +TOKEN @9:22 +IDENTIFIER @9:23 id internal unknown : ? +TOKEN @9:23 +TOKEN @9:32 +LIST @9:35 +LIST @9:35 +IDENTIFIER @9:35 id org unknown : ? +TOKEN @9:35 +IDENTIFIER @9:39 id example unknown : ? +TOKEN @9:39 +IDENTIFIER @9:47 id friend unknown : ? +TOKEN @9:47 +TOKEN @9:53 +LIST @9:55 +IDENTIFIER @9:55 id org unknown : ? +TOKEN @9:55 +IDENTIFIER @9:59 id example unknown : ? +TOKEN @9:59 +IDENTIFIER @9:67 id other unknown : ? +TOKEN @9:67 +TOKEN @9:72 +OPENS_DIRECTIVE @10:3 +TOKEN @10:3 +MEMBER_SELECT @10:9 : ? +MEMBER_SELECT @10:9 : ? +IDENTIFIER @10:9 id org unknown : ? +TOKEN @10:9 +TOKEN @10:12 +IDENTIFIER @10:13 id example unknown : ? +TOKEN @10:13 +TOKEN @10:20 +IDENTIFIER @10:21 id model unknown : ? +TOKEN @10:21 +TOKEN @10:26 +OPENS_DIRECTIVE @11:3 +TOKEN @11:3 +MEMBER_SELECT @11:9 : ? +MEMBER_SELECT @11:9 : ? +IDENTIFIER @11:9 id org unknown : ? +TOKEN @11:9 +TOKEN @11:12 +IDENTIFIER @11:13 id example unknown : ? +TOKEN @11:13 +TOKEN @11:20 +IDENTIFIER @11:21 id data unknown : ? +TOKEN @11:21 +TOKEN @11:26 +LIST @11:29 +LIST @11:29 +IDENTIFIER @11:29 id org unknown : ? +TOKEN @11:29 +IDENTIFIER @11:33 id example unknown : ? +TOKEN @11:33 +IDENTIFIER @11:41 id orm unknown : ? +TOKEN @11:41 +TOKEN @11:44 +USES_DIRECTIVE @12:3 +TOKEN @12:3 +IDENTIFIER @12:8 id Driver unknown : ? +TOKEN @12:8 +TOKEN @12:14 +PROVIDES_DIRECTIVE @13:3 +TOKEN @13:3 +MEMBER_SELECT @13:12 : java.lang.Runnable +MEMBER_SELECT @13:12 : ? +IDENTIFIER @13:12 id java .java [p package] : ? : ? +TOKEN @13:12 +TOKEN @13:16 +IDENTIFIER @13:17 id lang .java.lang [p package] : ? : ? +TOKEN @13:17 +TOKEN @13:21 +IDENTIFIER @13:22 id Runnable java.lang.Runnable [t public interface] : java.lang.Runnable @java.lang.FunctionalInterface : java.lang.Runnable +TOKEN @13:22 +TOKEN @13:31 +LIST @13:36 +MEMBER_SELECT @13:36 : ? +MEMBER_SELECT @13:36 : ? +IDENTIFIER @13:36 id org unknown : ? +TOKEN @13:36 +TOKEN @13:39 +IDENTIFIER @13:40 id example unknown : ? +TOKEN @13:40 +TOKEN @13:47 +IDENTIFIER @13:48 id Task unknown : ? +TOKEN @13:48 +TOKEN @13:52 +MEMBER_SELECT @13:54 : ? +MEMBER_SELECT @13:54 : ? +IDENTIFIER @13:54 id org unknown : ? +TOKEN @13:54 +TOKEN @13:57 +IDENTIFIER @13:58 id example unknown : ? +TOKEN @13:58 +TOKEN @13:65 +IDENTIFIER @13:66 id OtherTask unknown : ? +TOKEN @13:66 +TOKEN @13:75 +TOKEN @14:1 +TOKEN @15:1 diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/module-info.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/module-info.java new file mode 100644 index 00000000000..65456074462 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/module-info.java @@ -0,0 +1,14 @@ +import java.sql.Driver; + +@Deprecated +open module org.example.app { + requires java.base; + requires transitive java.logging; + requires static java.sql; + exports org.example.api; + exports org.example.internal to org.example.friend, org.example.other; + opens org.example.model; + opens org.example.data to org.example.orm; + uses Driver; + provides java.lang.Runnable with org.example.Task, org.example.OtherTask; +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/module-info.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/module-info.textproto.gz new file mode 100644 index 00000000000..1205f19c88d Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/module-info.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/packages.json b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/packages.json new file mode 100644 index 00000000000..afa1c3ec04d --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/packages.json @@ -0,0 +1,5 @@ +{ +"com.example.missing": false, +"java.util": true, +"java.util.concurrent": true +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/cfg/CFG.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/cfg/CFG.expected.txt.gz new file mode 100644 index 00000000000..ea88cdbbfee Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/cfg/CFG.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/cfg/CFG.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/cfg/CFG.java new file mode 100644 index 00000000000..e94f778852f --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/cfg/CFG.java @@ -0,0 +1,1329 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.cfg; + +import java.util.ArrayList; +import java.util.Deque; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonar.java.Preconditions; +import org.sonar.java.model.ExpressionUtils; +import org.sonar.java.model.JavaTree; +import org.sonar.plugins.java.api.cfg.ControlFlowGraph; +import org.sonar.plugins.java.api.location.Position; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.ArrayAccessExpressionTree; +import org.sonar.plugins.java.api.tree.ArrayDimensionTree; +import org.sonar.plugins.java.api.tree.AssertStatementTree; +import org.sonar.plugins.java.api.tree.AssignmentExpressionTree; +import org.sonar.plugins.java.api.tree.BinaryExpressionTree; +import org.sonar.plugins.java.api.tree.BlockTree; +import org.sonar.plugins.java.api.tree.BreakStatementTree; +import org.sonar.plugins.java.api.tree.CaseGroupTree; +import org.sonar.plugins.java.api.tree.CaseLabelTree; +import org.sonar.plugins.java.api.tree.CatchTree; +import org.sonar.plugins.java.api.tree.ConditionalExpressionTree; +import org.sonar.plugins.java.api.tree.ContinueStatementTree; +import org.sonar.plugins.java.api.tree.DoWhileStatementTree; +import org.sonar.plugins.java.api.tree.ExpressionStatementTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.ForEachStatement; +import org.sonar.plugins.java.api.tree.ForStatementTree; +import org.sonar.plugins.java.api.tree.GuardedPatternTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.IfStatementTree; +import org.sonar.plugins.java.api.tree.InstanceOfTree; +import org.sonar.plugins.java.api.tree.LabeledStatementTree; +import org.sonar.plugins.java.api.tree.ListTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.MethodInvocationTree; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.NewArrayTree; +import org.sonar.plugins.java.api.tree.NewClassTree; +import org.sonar.plugins.java.api.tree.NullPatternTree; +import org.sonar.plugins.java.api.tree.ParameterizedTypeTree; +import org.sonar.plugins.java.api.tree.ParenthesizedTree; +import org.sonar.plugins.java.api.tree.PatternInstanceOfTree; +import org.sonar.plugins.java.api.tree.PatternTree; +import org.sonar.plugins.java.api.tree.RecordPatternTree; +import org.sonar.plugins.java.api.tree.ReturnStatementTree; +import org.sonar.plugins.java.api.tree.StatementTree; +import org.sonar.plugins.java.api.tree.SwitchExpressionTree; +import org.sonar.plugins.java.api.tree.SwitchStatementTree; +import org.sonar.plugins.java.api.tree.SwitchTree; +import org.sonar.plugins.java.api.tree.SynchronizedStatementTree; +import org.sonar.plugins.java.api.tree.SyntaxToken; +import org.sonar.plugins.java.api.tree.ThrowStatementTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.TryStatementTree; +import org.sonar.plugins.java.api.tree.TypeCastTree; +import org.sonar.plugins.java.api.tree.TypePatternTree; +import org.sonar.plugins.java.api.tree.TypeTree; +import org.sonar.plugins.java.api.tree.UnaryExpressionTree; +import org.sonar.plugins.java.api.tree.VariableTree; +import org.sonar.plugins.java.api.tree.WhileStatementTree; +import org.sonar.plugins.java.api.tree.WildcardTree; +import org.sonar.plugins.java.api.tree.YieldStatementTree; +import org.sonarsource.analyzer.commons.collections.ListUtils; + +public class CFG implements ControlFlowGraph { + + private static final Logger LOG = LoggerFactory.getLogger(CFG.class); + + @Nullable + private Symbol.MethodSymbol methodSymbol; + private Block currentBlock; + private boolean hasCompleteSemantic = true; + + /** + * List of all blocks in order they were created. + */ + private final List blocks = new ArrayList<>(); + + private final Deque breakTargets = new LinkedList<>(); + private final Deque continueTargets = new LinkedList<>(); + private final Deque exitBlocks = new LinkedList<>(); + private final Deque enclosingTry = new LinkedList<>(); + private final Deque enclosedByCatch = new LinkedList<>(); + private final TryStatement outerTry; + + private static class TryStatement { + Map catches = new LinkedHashMap<>(); + List runtimeCatches = new ArrayList<>(); + + public void addCatch(Type type, Block catchBlock) { + if (type.is("java.lang.Exception") + || type.is("java.lang.Throwable") + || type.isSubtypeOf("java.lang.Error") + || type.isSubtypeOf("java.lang.RuntimeException") + || !type.isSubtypeOf("java.lang.Exception")) { + runtimeCatches.add(catchBlock); + } + catches.put(type, catchBlock); + } + } + + private String pendingLabel = null; + private final Map labelsBreakTarget = new HashMap<>(); + private final Map labelsContinueTarget = new HashMap<>(); + + private CFG(List trees, @Nullable MethodTree tree) { + if (tree != null) { + methodSymbol = tree.symbol(); + checkSymbolSemantic(methodSymbol, "method definition", tree.simpleName().identifierToken()); + } + exitBlocks.add(createBlock()); + currentBlock = createBlock(exitBlock()); + outerTry = new TryStatement(); + enclosingTry.add(outerTry); + enclosedByCatch.push(false); + build(trees); + prune(); + computePredecessors(blocks); + } + + @Override + public boolean hasCompleteSemantic() { + return hasCompleteSemantic; + } + + private void checkIdentifierSemantic(IdentifierTree tree) { + checkSymbolSemantic(tree.symbol(), "unknown identifier", tree.identifierToken()); + } + + private void checkSymbolSemantic(@Nullable Symbol symbol, String reason, @Nullable SyntaxToken location) { + if (symbol != null) { + if (symbol.isUnknown()) { + markSemanticAsIncomplete(reason, location); + } else if (symbol instanceof Symbol.MethodSymbol method) { + if (method.returnType().isUnknown()) { + markSemanticAsIncomplete("unknown return type", location); + } else if (method.parameterTypes().stream().anyMatch(Type::isUnknown)) { + markSemanticAsIncomplete("unknown parameter type", location); + } + } + } + } + + private Type checkTypeSemantic(Type type, String reason, @Nullable SyntaxToken location) { + if (type.isUnknown()) { + markSemanticAsIncomplete(reason, location); + } + return type; + } + + private void markSemanticAsIncomplete(String reason, @Nullable SyntaxToken location) { + if (hasCompleteSemantic) { + hasCompleteSemantic = false; + if (LOG.isDebugEnabled()) { + StringBuilder logMessage = new StringBuilder(); + logMessage.append("Incomplete Semantic, ").append(reason); + if (location != null) { + logMessage.append(" '").append(location.text()).append("'"); + Position position = location.range().start(); + logMessage.append(" line ").append(position.line()).append(" col ").append(position.column()); + } + LOG.debug(logMessage.toString()); + } + } + } + + @Override + public Block exitBlock() { + return exitBlocks.peek(); + } + + @Nullable + public Symbol.MethodSymbol methodSymbol() { + return methodSymbol; + } + + @Override + public Block entryBlock() { + return currentBlock; + } + + @Override + public List blocks() { + return ListUtils.reverse(blocks); + } + + public List reversedBlocks() { + return blocks; + } + + public interface IBlock { + int id(); + List elements(); + + T terminator(); + + Set> successors(); + } + + public static class Block implements IBlock, ControlFlowGraph.Block { + public static final Predicate IS_CATCH_BLOCK = Block::isCatchBlock; + private int id; + private final List elements = new ArrayList<>(); + private final Set successors = new LinkedHashSet<>(); + private final Set predecessors = new LinkedHashSet<>(); + private final Set exceptions = new LinkedHashSet<>(); + private Block trueBlock; + private Block falseBlock; + private Block exitBlock; + private Block successorWithoutJump; + + private Tree terminator; + private CaseGroupTree caseGroup; + + private boolean isFinallyBlock; + private boolean isCatchBlock = false; + private boolean isDefaultBlock = false; + + public Block(int id) { + this.id = id; + } + + @Override + public int id() { + return id; + } + + @Override + public List elements() { + return ListUtils.reverse(elements); + } + + @Override + public Block trueBlock() { + return trueBlock; + } + + @Override + public Block falseBlock() { + return falseBlock; + } + + @Override + public Block exitBlock() { + return exitBlock; + } + + @Override + public boolean isFinallyBlock() { + return isFinallyBlock; + } + + @Override + public boolean isCatchBlock() { + return isCatchBlock; + } + + @Override + public boolean isDefaultBlock() { + return isDefaultBlock; + } + + void addSuccessor(Block successor) { + successors.add(successor); + } + + public void addTrueSuccessor(Block successor) { + if (trueBlock != null) { + throw new IllegalStateException("Attempt to re-assign a true successor"); + } + successors.add(successor); + trueBlock = successor; + } + + public void addFalseSuccessor(Block successor) { + if (falseBlock != null) { + throw new IllegalStateException("Attempt to re-assign a false successor"); + } + successors.add(successor); + falseBlock = successor; + } + + public void addExitSuccessor(Block block) { + successors.add(block); + exitBlock = block; + } + + public Set predecessors() { + return predecessors; + } + + @Override + public Set successors() { + return successors; + } + + @Override + public Set exceptions() { + return exceptions; + } + + @Override + @CheckForNull + public Tree terminator() { + return terminator; + } + + public boolean isInactive() { + return terminator == null && elements.isEmpty() && successors.size() == 1; + } + + private void prune(Block inactiveBlock) { + boolean hasUniqueSuccessor = inactiveBlock.successors.size() == 1; + if (inactiveBlock.equals(trueBlock)) { + Preconditions.checkArgument(hasUniqueSuccessor, "True successor must be replaced by a unique successor!"); + trueBlock = inactiveBlock.successors.iterator().next(); + } + if (inactiveBlock.equals(falseBlock)) { + Preconditions.checkArgument(hasUniqueSuccessor, "False successor must be replaced by a unique successor!"); + falseBlock = inactiveBlock.successors.iterator().next(); + } + if (inactiveBlock.equals(successorWithoutJump)) { + Preconditions.checkArgument(hasUniqueSuccessor, "SuccessorWithoutJump successor must be replaced by a unique successor!"); + successorWithoutJump = inactiveBlock.successors.iterator().next(); + } + if (successors.remove(inactiveBlock)) { + successors.addAll(inactiveBlock.successors); + } + if (exceptions.remove(inactiveBlock)) { + exceptions.addAll(inactiveBlock.exceptions); + exceptions.addAll(inactiveBlock.successors); + } + if (inactiveBlock.equals(exitBlock)) { + exitBlock = inactiveBlock.successors.iterator().next(); + } + } + + public boolean isMethodExitBlock() { + return successors().isEmpty(); + } + + /** + * This method makes the implementation of RSPEC-3626 almost trivial. + * @return the block which would be the successor of this one if this one didn't terminate with a jump + */ + @CheckForNull + public Block successorWithoutJump() { + return successorWithoutJump; + } + + /** + * Label is used to contain additional information about a block which is not directly related to CFG structure. + * Used for simplifying implementation of RSPEC-128. + */ + @CheckForNull + @Override + public CaseGroupTree caseGroup() { + return caseGroup; + } + + public void setCaseGroup(CaseGroupTree caseGroup) { + this.caseGroup = caseGroup; + } + } + + private static void computePredecessors(List blocks) { + for (Block b : blocks) { + for (Block successor : b.successors) { + successor.predecessors.add(b); + } + for (Block successor : b.exceptions) { + successor.predecessors.add(b); + } + } + cleanupUnfeasibleBreakPaths(blocks); + } + + private static void cleanupUnfeasibleBreakPaths(List blocks) { + for (Block block : blocks) { + Set happyPathPredecessor = block.predecessors.stream().filter(p -> !p.exceptions.contains(block)).collect(Collectors.toSet()); + if(block.isFinallyBlock && happyPathPredecessor.size() == 1) { + Block pred = happyPathPredecessor.iterator().next(); + if (pred.terminator != null && pred.terminator.is(Tree.Kind.BREAK_STATEMENT)) { + Set succs = block.successors.stream() + .map(suc -> isLoop(suc) ? getAfterLoopBlock(suc) : suc) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); + block.successors.clear(); + block.successors.addAll(succs); + } + } + } + } + + private static boolean isLoop(Block successor) { + return successor.terminator != null + && successor.terminator.is(Tree.Kind.WHILE_STATEMENT, Tree.Kind.DO_STATEMENT, Tree.Kind.FOR_STATEMENT, Tree.Kind.FOR_EACH_STATEMENT); + } + + @CheckForNull + private static Block getAfterLoopBlock(Block loop) { + if (loop.falseBlock != null) { + return loop.falseBlock; + } + // Because 'for' statements without condition are unconditional jumps block + return loop.successorWithoutJump; + } + + private void prune() { + List inactiveBlocks = new ArrayList<>(); + boolean first = true; + for (Block block : blocks) { + if (!first && isInactive(block)) { + inactiveBlocks.add(block); + } + first = false; + } + if (!inactiveBlocks.isEmpty()) { + removeInactiveBlocks(inactiveBlocks); + if (inactiveBlocks.contains(currentBlock)) { + currentBlock = currentBlock.successors.iterator().next(); + } + int id = 0; + for (Block block : blocks) { + block.id = id; + id += 1; + } + inactiveBlocks.removeAll(blocks); + if (!inactiveBlocks.isEmpty()) { + prune(); + } + } + } + + private boolean isInactive(Block block) { + if (block.equals(currentBlock) && block.successors.size() > 1) { + return false; + } + return block.isInactive(); + } + + private void removeInactiveBlocks(List inactiveBlocks) { + for (Block inactiveBlock : inactiveBlocks) { + for (Block block : blocks) { + block.prune(inactiveBlock); + } + } + blocks.removeAll(inactiveBlocks); + } + + private Block createBlock(Block successor) { + Block result = createBlock(); + result.addSuccessor(successor); + return result; + } + + private Block createBlock() { + Block result = new Block(blocks.size()); + blocks.add(result); + return result; + } + + public static CFG buildCFG(List trees) { + return new CFG(trees, null); + } + + public static CFG build(MethodTree tree) { + BlockTree block = tree.block(); + Preconditions.checkArgument(block != null, "Cannot build CFG for method with no body."); + return build(tree, block.body()); + } + + public static CFG build(MethodTree tree, List elements) { + return new CFG(elements, tree); + } + + private void build(ListTree trees) { + build((List) trees); + } + + private void build(List trees) { + ListUtils.reverse(trees).forEach(this::build); + } + + private void build(Tree tree) { + switch (tree.kind()) { + case BLOCK: + build(((BlockTree) tree).body()); + break; + case RETURN_STATEMENT: + buildReturnStatement((ReturnStatementTree) tree); + break; + case EXPRESSION_STATEMENT: + build(((ExpressionStatementTree) tree).expression()); + break; + case METHOD_INVOCATION: + buildMethodInvocation((MethodInvocationTree) tree); + break; + case IF_STATEMENT: + buildIfStatement((IfStatementTree) tree); + break; + case CONDITIONAL_EXPRESSION: + buildConditionalExpression((ConditionalExpressionTree) tree); + break; + case VARIABLE: + buildVariable((VariableTree) tree); + break; + case MULTIPLY, + DIVIDE, + REMAINDER, + PLUS, + MINUS, + LEFT_SHIFT, + RIGHT_SHIFT, + UNSIGNED_RIGHT_SHIFT, + AND, + XOR, + OR, + GREATER_THAN, + GREATER_THAN_OR_EQUAL_TO, + LESS_THAN, + LESS_THAN_OR_EQUAL_TO, + EQUAL_TO, + NOT_EQUAL_TO: + buildBinaryExpression(tree); + break; + case ASSIGNMENT, + LEFT_SHIFT_ASSIGNMENT, + RIGHT_SHIFT_ASSIGNMENT, + AND_ASSIGNMENT, + REMAINDER_ASSIGNMENT, + UNSIGNED_RIGHT_SHIFT_ASSIGNMENT, + OR_ASSIGNMENT, + XOR_ASSIGNMENT, + DIVIDE_ASSIGNMENT, + MULTIPLY_ASSIGNMENT, + PLUS_ASSIGNMENT, + MINUS_ASSIGNMENT: + buildAssignment((AssignmentExpressionTree) tree); + break; + case MEMBER_SELECT: + buildMemberSelect((MemberSelectExpressionTree) tree); + break; + case CONDITIONAL_AND: + buildConditionalAnd((BinaryExpressionTree) tree); + break; + case CONDITIONAL_OR: + buildConditionalOr((BinaryExpressionTree) tree); + break; + case LABELED_STATEMENT: + buildLabeledStatement((LabeledStatementTree) tree); + break; + case SWITCH_STATEMENT: + buildSwitchStatement((SwitchStatementTree) tree); + break; + case SWITCH_EXPRESSION: + buildSwitchExpression((SwitchExpressionTree) tree); + break; + case BREAK_STATEMENT: + buildBreakStatement((BreakStatementTree) tree); + break; + case YIELD_STATEMENT: + buildYieldStatement((YieldStatementTree) tree); + break; + case CONTINUE_STATEMENT: + buildContinueStatement((ContinueStatementTree) tree); + break; + case WHILE_STATEMENT: + buildWhileStatement((WhileStatementTree) tree); + break; + case DO_STATEMENT: + buildDoWhileStatement((DoWhileStatementTree) tree); + break; + case FOR_EACH_STATEMENT: + buildForEachStatement((ForEachStatement) tree); + break; + case FOR_STATEMENT: + buildForStatement((ForStatementTree) tree); + break; + case TRY_STATEMENT: + buildTryStatement((TryStatementTree) tree); + break; + case THROW_STATEMENT: + buildThrowStatement((ThrowStatementTree) tree); + break; + case SYNCHRONIZED_STATEMENT: + buildSynchronizedStatement((SynchronizedStatementTree) tree); + break; + case POSTFIX_INCREMENT, + POSTFIX_DECREMENT, + PREFIX_INCREMENT, + PREFIX_DECREMENT, + UNARY_MINUS, + UNARY_PLUS, + BITWISE_COMPLEMENT, + LOGICAL_COMPLEMENT: + buildUnaryExpression((UnaryExpressionTree) tree); + break; + case PARENTHESIZED_EXPRESSION: + build(((ParenthesizedTree) tree).expression()); + break; + case ARRAY_ACCESS_EXPRESSION: + buildArrayAccessExpression((ArrayAccessExpressionTree) tree); + break; + case ARRAY_DIMENSION: + buildArrayDimension((ArrayDimensionTree) tree); + break; + case NEW_CLASS: + buildNewClass((NewClassTree) tree); + break; + case TYPE_CAST: + buildTypeCast(tree); + break; + case INSTANCE_OF: + buildInstanceOf((InstanceOfTree) tree); + break; + case PATTERN_INSTANCE_OF: + buildInstanceOf((PatternInstanceOfTree) tree); + break; + case NEW_ARRAY: + buildNewArray((NewArrayTree) tree); + break; + // assert can be ignored by VM so skip them for now. + case ASSERT_STATEMENT: + buildAssertStatement((AssertStatementTree) tree); + break; + // store declarations as complete blocks. + case EMPTY_STATEMENT, + CLASS, + RECORD, + ENUM, + ANNOTATION_TYPE, + INTERFACE, + METHOD_REFERENCE, + LAMBDA_EXPRESSION, + // simple instructions + INT_LITERAL, + LONG_LITERAL, + DOUBLE_LITERAL, + CHAR_LITERAL, + FLOAT_LITERAL, + STRING_LITERAL, + TEXT_BLOCK, + BOOLEAN_LITERAL, + NULL_LITERAL: + currentBlock.elements.add(tree); + break; + case IDENTIFIER: + checkIdentifierSemantic((IdentifierTree) tree); + currentBlock.elements.add(tree); + break; + case NULL_PATTERN, + TYPE_PATTERN, + GUARDED_PATTERN, + RECORD_PATTERN, + DEFAULT_PATTERN: + buildPattern((PatternTree) tree); + break; + case PARAMETERIZED_TYPE: + var typeTree = (ParameterizedTypeTree) tree; + build(typeTree.type()); + build(typeTree.typeArguments()); + break; + case UNBOUNDED_WILDCARD, + EXTENDS_WILDCARD, + SUPER_WILDCARD: + TypeTree bound = ((WildcardTree) tree).bound(); + if (bound != null) { + build(bound); + } + currentBlock.elements.add(tree); + break; + default: + throw new UnsupportedOperationException(tree.kind().name() + " " + ((JavaTree) tree).getLine()); + } + } + + private void buildReturnStatement(ReturnStatementTree returnStatement) { + currentBlock = createUnconditionalJump(returnStatement, exitBlock(), currentBlock); + ExpressionTree expression = returnStatement.expression(); + if (expression != null) { + build(expression); + } + } + + private void buildMethodInvocation(MethodInvocationTree mit) { + SyntaxToken location = mit.methodSelect().lastToken(); + checkSymbolSemantic(mit.methodSymbol(), "method invocation", location); + handleExceptionalPaths(mit.methodSymbol(), location); + currentBlock.elements.add(mit); + build(mit.arguments()); + if (mit.methodSelect().is(Tree.Kind.MEMBER_SELECT)) { + MemberSelectExpressionTree memberSelect = (MemberSelectExpressionTree) mit.methodSelect(); + build(memberSelect.expression()); + } else { + build(mit.methodSelect()); + } + } + + private void buildIfStatement(IfStatementTree ifStatementTree) { + Block next = currentBlock; + // process else-branch + Block elseBlock = next; + StatementTree elseStatement = ifStatementTree.elseStatement(); + if (elseStatement != null) { + // if statement will create the required block. + if (!elseStatement.is(Tree.Kind.IF_STATEMENT)) { + currentBlock = createBlock(next); + } + build(elseStatement); + elseBlock = currentBlock; + } + // process then-branch + currentBlock = createBlock(next); + build(ifStatementTree.thenStatement()); + Block thenBlock = currentBlock; + // process condition + currentBlock = createBranch(ifStatementTree, thenBlock, elseBlock); + buildCondition(ifStatementTree.condition(), thenBlock, elseBlock); + } + + private void buildConditionalExpression(ConditionalExpressionTree cond) { + Block next = currentBlock; + // process else-branch + ExpressionTree elseStatement = cond.falseExpression(); + currentBlock = createBlock(next); + build(elseStatement); + Block elseBlock = currentBlock; + // process then-branch + currentBlock = createBlock(next); + build(cond.trueExpression()); + Block thenBlock = currentBlock; + // process condition + currentBlock = createBranch(cond, thenBlock, elseBlock); + buildCondition(cond.condition(), thenBlock, elseBlock); + } + + private void buildVariable(VariableTree tree) { + checkTypeSemantic(tree.type().symbolType(), "unknown variable type", tree.type().firstToken()); + currentBlock.elements.add(tree); + ExpressionTree initializer = tree.initializer(); + if (initializer != null) { + build(initializer); + } + } + + private void buildBinaryExpression(Tree tree) { + BinaryExpressionTree binaryExpressionTree = (BinaryExpressionTree) tree; + currentBlock.elements.add(tree); + build(binaryExpressionTree.rightOperand()); + build(binaryExpressionTree.leftOperand()); + } + + private void buildAssignment(AssignmentExpressionTree tree) { + currentBlock.elements.add(tree); + build(tree.expression()); + // The variable is not evaluated for simple assignment as it's only used to know where to store the value: JLS8-15.26 + if (!ExpressionUtils.isSimpleAssignment(tree)) { + build(tree.variable()); + } + } + + private void buildMemberSelect(MemberSelectExpressionTree mse) { + currentBlock.elements.add(mse); + // int.class or String[].class are memberSelectExpression which expression part is not an expression. + if (!"class".equals(mse.identifier().name())) { + build(mse.expression()); + } + } + + private void buildConditionalAnd(BinaryExpressionTree tree) { + Block falseBlock = currentBlock; + currentBlock = createBlock(falseBlock); + // process RHS + build(tree.rightOperand()); + // process LHS + buildConditionalBinaryLHS(tree, currentBlock, falseBlock); + } + + private void buildConditionalOr(BinaryExpressionTree tree) { + Block trueBlock = currentBlock; + currentBlock = createBlock(trueBlock); + // process RHS + build(tree.rightOperand()); + // process LHS + buildConditionalBinaryLHS(tree, trueBlock, currentBlock); + } + + private void buildConditionalBinaryLHS(BinaryExpressionTree tree, Block trueBlock, Block falseBlock) { + currentBlock = createBlock(); + Block toComplete = currentBlock; + build(tree.leftOperand()); + toComplete.terminator = tree; + toComplete.addFalseSuccessor(falseBlock); + toComplete.addTrueSuccessor(trueBlock); + } + + private void buildLabeledStatement(LabeledStatementTree labeledStatement) { + String name = labeledStatement.label().name(); + labelsBreakTarget.put(name, currentBlock); + pendingLabel = name; + currentBlock = createBlock(currentBlock); + build(labeledStatement.statement()); + currentBlock = createBlock(currentBlock); + } + + private void buildSwitchStatement(SwitchStatementTree switchStatementTree) { + buildSwitch(switchStatementTree, switchStatementTree); + } + + private void buildSwitchExpression(SwitchExpressionTree switchExpressionTree) { + buildSwitch(switchExpressionTree, switchExpressionTree); + } + + private void buildSwitch(SwitchTree switchTree, Tree terminator) { + Block switchSuccessor = currentBlock; + // process condition + currentBlock = createBlock(); + currentBlock.terminator = terminator; + Block switchBlock = currentBlock; + List switchCasesExpressions = switchTree.cases() + .stream() + .map(CaseGroupTree::labels) + .flatMap(List::stream) + .map(CaseLabelTree::expressions) + .flatMap(List::stream).toList(); + ListUtils.reverse(switchCasesExpressions).forEach(this::build); + + build(switchTree.expression()); + Block conditionBlock = currentBlock; + // process body + currentBlock = createBlock(switchSuccessor); + breakTargets.addLast(switchSuccessor); + boolean hasDefaultCase = false; + if (!switchTree.cases().isEmpty()) { + boolean withoutFallTrough = switchWithoutFallThrough(switchTree); + CaseGroupTree firstCase = switchTree.cases().get(0); + for (CaseGroupTree caseGroupTree : ListUtils.reverse(switchTree.cases())) { + if (withoutFallTrough) { + currentBlock.successors().clear(); + currentBlock.addSuccessor(switchSuccessor); + } + build(caseGroupTree.body()); + currentBlock.elements.add(caseGroupTree); + if (!hasDefaultCase) { + hasDefaultCase = containsDefaultCase(caseGroupTree.labels()); + currentBlock.isDefaultBlock = hasDefaultCase; + } + currentBlock.setCaseGroup(caseGroupTree); + switchBlock.addSuccessor(currentBlock); + if (!caseGroupTree.equals(firstCase)) { + // No block preceding the first case group. + currentBlock = createBlock(currentBlock); + } + } + } + breakTargets.removeLast(); + // process condition + currentBlock = switchBlock; + if (!hasDefaultCase && !terminator.is(Tree.Kind.SWITCH_EXPRESSION)) { + currentBlock.addSuccessor(switchSuccessor); + } + currentBlock = conditionBlock; + } + + /** + * A switch expression can use the traditional cases with 'colon' (with fall-through) or, + * starting with java 12, the 'arrow' cases (without fall-through). Cases can not be mixed. + * + * @param switchTree the switch to evaluate + * @return true if the switch uses fall-through + */ + private static boolean switchWithoutFallThrough(SwitchTree switchTree) { + return switchTree.cases().stream() + .map(CaseGroupTree::labels) + .flatMap(List::stream) + .noneMatch(CaseLabelTree::isFallThrough); + } + + private static boolean containsDefaultCase(List labels) { + return labels.stream().anyMatch(caseLabel -> "default".equals(caseLabel.caseOrDefaultKeyword().text()) + // JDK 17 preview feature + || caseLabel.expressions().stream().anyMatch(expr -> expr.is(Tree.Kind.DEFAULT_PATTERN))); + } + + private void buildBreakStatement(BreakStatementTree tree) { + IdentifierTree label = tree.label(); + boolean isLabel = false; + Block targetBlock = null; + if (label == null) { + if (breakTargets.isEmpty()) { + markSemanticAsIncomplete("'break' statement not in loop or switch statement", tree.firstToken()); + } else { + targetBlock = breakTargets.getLast(); + } + } else { + isLabel = label.symbol() instanceof Symbol.LabelSymbol; + if (isLabel) { + targetBlock = labelsBreakTarget.get(label.name()); + } else { + targetBlock = breakTargets.getLast(); + } + } + currentBlock = createUnconditionalJump(tree, targetBlock, currentBlock); + if(currentBlock.exitBlock != null) { + currentBlock.exitBlock = null; + } + } + + private void buildYieldStatement(YieldStatementTree tree) { + currentBlock = createUnconditionalJump(tree, breakTargets.isEmpty() ? null : breakTargets.getLast(), currentBlock); + build(tree.expression()); + currentBlock.exitBlock = null; + } + + private void buildContinueStatement(ContinueStatementTree tree) { + IdentifierTree label = tree.label(); + Block targetBlock = null; + if (label == null) { + if (continueTargets.isEmpty()) { + markSemanticAsIncomplete("'continue' statement not in loop or switch statement", tree.firstToken()); + } else { + targetBlock = continueTargets.getLast(); + } + } else { + targetBlock = labelsContinueTarget.get(label.name()); + } + currentBlock = createUnconditionalJump(tree, targetBlock, currentBlock); + // cleanup for continue statement to a finally: continue block can't have an exit block. + currentBlock.exitBlock = null; + } + + private void buildWhileStatement(WhileStatementTree whileStatement) { + Block falseBranch = currentBlock; + Block loopback = createBlock(); + // process body + currentBlock = createBlock(loopback); + addContinueTarget(loopback); + breakTargets.addLast(falseBranch); + build(whileStatement.statement()); + breakTargets.removeLast(); + continueTargets.removeLast(); + Block bodyBlock = currentBlock; + // process condition + currentBlock = createBranch(whileStatement, bodyBlock, falseBranch); + buildCondition(whileStatement.condition(), bodyBlock, falseBranch); + loopback.addSuccessor(currentBlock); + currentBlock = createBlock(currentBlock); + } + + private void buildDoWhileStatement(DoWhileStatementTree doWhileStatementTree) { + Block falseBranch = currentBlock; + Block loopback = createBlock(); + // process condition + currentBlock = createBranch(doWhileStatementTree, loopback, falseBranch); + buildCondition(doWhileStatementTree.condition(), loopback, falseBranch); + // process body + addContinueTarget(currentBlock); + currentBlock = createBlock(currentBlock); + breakTargets.addLast(falseBranch); + build(doWhileStatementTree.statement()); + breakTargets.removeLast(); + continueTargets.removeLast(); + loopback.addSuccessor(currentBlock); + currentBlock = createBlock(currentBlock); + } + + private void buildForEachStatement(ForEachStatement tree) { + // TODO(npe) One solution is to create a forstatement node depending on type of expression (iterable or array) and build CFG from it. + Block afterLoop = currentBlock; + Block statementBlock = createBlock(); + Block loopback = createBranch(tree, statementBlock, afterLoop); + currentBlock = createBlock(loopback); + addContinueTarget(loopback); + breakTargets.addLast(afterLoop); + build(tree.statement()); + breakTargets.removeLast(); + continueTargets.removeLast(); + statementBlock.addSuccessor(currentBlock); + currentBlock = loopback; + build(tree.variable()); + currentBlock = createBlock(currentBlock); + build(tree.expression()); + currentBlock = createBlock(currentBlock); + } + + private void addContinueTarget(Block target) { + continueTargets.addLast(target); + if (pendingLabel != null) { + labelsContinueTarget.put(pendingLabel, target); + pendingLabel = null; + } + } + + private void buildForStatement(ForStatementTree tree) { + Block falseBranch = currentBlock; + // process step + currentBlock = createBlock(); + Block updateBlock = currentBlock; + build(tree.update()); + addContinueTarget(currentBlock); + // process body + currentBlock = createBlock(currentBlock); + breakTargets.addLast(falseBranch); + build(tree.statement()); + breakTargets.removeLast(); + continueTargets.removeLast(); + Block body = currentBlock; + // process condition + ExpressionTree condition = tree.condition(); + if (condition != null) { + currentBlock = createBranch(tree, body, falseBranch); + buildCondition(condition, body, falseBranch); + } else { + currentBlock = createUnconditionalJump(tree, body, falseBranch); + } + updateBlock.addSuccessor(currentBlock); + // process init + currentBlock = createBlock(currentBlock); + build(tree.initializer()); + } + + private void buildTryStatement(TryStatementTree tryStatementTree) { + // FIXME only path with no failure constructed for now, (not taking try with resources into consideration). + currentBlock = createBlock(currentBlock); + BlockTree finallyBlockTree = tryStatementTree.finallyBlock(); + if (finallyBlockTree != null) { + currentBlock.isFinallyBlock = true; + Block finallyBlock = currentBlock; + build(finallyBlockTree); + finallyBlock.addExitSuccessor(exitBlock()); + exitBlocks.push(currentBlock); + addContinueTarget(currentBlock); + currentBlock.isFinallyBlock = true; + breakTargets.addLast(currentBlock); + } + Block finallyOrEndBlock = currentBlock; + Block beforeFinally = createBlock(currentBlock); + TryStatement tryStatement = new TryStatement(); + enclosingTry.push(tryStatement); + enclosedByCatch.push(false); + for (CatchTree catchTree : ListUtils.reverse(tryStatementTree.catches())) { + currentBlock = createBlock(finallyOrEndBlock); + enclosedByCatch.push(true); + build(catchTree.block()); + buildVariable(catchTree.parameter()); + currentBlock.isCatchBlock = true; + enclosedByCatch.pop(); + TypeTree type = catchTree.parameter().type(); + tryStatement.addCatch(checkTypeSemantic(type.symbolType(), "catch parameter type", type.firstToken()), currentBlock); + } + currentBlock = beforeFinally; + build(tryStatementTree.block()); + build((List) tryStatementTree.resourceList()); + enclosingTry.pop(); + enclosedByCatch.pop(); + currentBlock = createBlock(currentBlock); + currentBlock.elements.add(tryStatementTree); + if (finallyBlockTree != null) { + exitBlocks.pop(); + continueTargets.removeLast(); + breakTargets.removeLast(); + } + } + + private void buildThrowStatement(ThrowStatementTree throwStatementTree) { + Block jumpTo = exitBlock(); + TryStatement enclosingTryCatch = enclosingTry.peek(); + if(enclosingTryCatch != null){ + jumpTo = enclosingTryCatch.catches.keySet().stream() + .filter(t -> checkTypeSemantic(throwStatementTree.expression().symbolType(), "thrown expression", throwStatementTree.expression().firstToken()).isSubtypeOf(t)) + .findFirst() + .map(t -> enclosingTryCatch.catches.get(t)) + .orElse(exitBlock()); + } + currentBlock = createUnconditionalJump(throwStatementTree, jumpTo, currentBlock); + build(throwStatementTree.expression()); + } + + private void buildSynchronizedStatement(SynchronizedStatementTree sst) { + // First create the block of the statement, + build(sst.block()); + // Then create a single block with the SYNCHRONIZED tree as terminator + currentBlock = createUnconditionalJump(sst, currentBlock, null); + build(sst.expression()); + } + + private void buildUnaryExpression(UnaryExpressionTree tree) { + currentBlock.elements.add(tree); + build(tree.expression()); + } + + private void buildArrayAccessExpression(ArrayAccessExpressionTree tree) { + currentBlock.elements.add(tree); + build(tree.dimension()); + build(tree.expression()); + } + + private void buildArrayDimension(ArrayDimensionTree tree) { + ExpressionTree expression = tree.expression(); + if (expression != null) { + build(expression); + } + } + + private void buildNewClass(NewClassTree tree) { + SyntaxToken location = tree.identifier().lastToken(); + checkSymbolSemantic(tree.methodSymbol(), "new class", location); + handleExceptionalPaths(tree.methodSymbol(), location); + currentBlock.elements.add(tree); + build(tree.arguments()); + ExpressionTree enclosingExpression = tree.enclosingExpression(); + if (enclosingExpression != null) { + build(enclosingExpression); + } + } + + private void handleExceptionalPaths(Symbol.MethodSymbol symbol, @Nullable SyntaxToken location) { + TryStatement pop = enclosingTry.pop(); + TryStatement tryStatement; + Block exceptionPredecessor = currentBlock; + if (Boolean.TRUE.equals(enclosedByCatch.peek())) { + tryStatement = enclosingTry.peek(); + } else { + tryStatement = pop; + } + enclosingTry.push(pop); + if(pop != outerTry) { + currentBlock = createBlock(currentBlock); + currentBlock.exceptions.add(exitBlocks.peek()); + if (!Boolean.TRUE.equals(enclosedByCatch.peek())) { + exceptionPredecessor = currentBlock; + } + } + if (!symbol.isUnknown()) { + List thrownTypes = symbol.thrownTypes(); + thrownTypes.forEach(thrownType -> { + checkTypeSemantic(thrownType, "thrown types", location); + for (Type caughtType : tryStatement.catches.keySet()) { + if (thrownType.isSubtypeOf(caughtType) || + caughtType.isSubtypeOf(thrownType) || + thrownType.isUnknown() || + // note that this condition is not necessary, because unknown type will be added to runtimeCatches due to condition in + // org.sonar.java.cfg.CFG.TryStatement#addCatch ,however, it is here for clarity + caughtType.isUnknown()) { + currentBlock.exceptions.add(tryStatement.catches.get(caughtType)); + } + } + }); + } + exceptionPredecessor.exceptions.addAll(tryStatement.runtimeCatches); + } + + private void buildTypeCast(Tree tree) { + enclosingTry.peek().catches.entrySet().stream() + .filter(e -> e.getKey().isSubtypeOf("java.lang.ClassCastException")) + .findFirst() + .ifPresent(e -> { + currentBlock = createBlock(currentBlock); + currentBlock.successors.add(e.getValue()); + }); + currentBlock.elements.add(tree); + TypeCastTree typeCastTree = (TypeCastTree) tree; + build(typeCastTree.expression()); + } + + private void buildInstanceOf(InstanceOfTree instanceOfTree) { + currentBlock.elements.add(instanceOfTree); + build(instanceOfTree.expression()); + } + + private void buildInstanceOf(PatternInstanceOfTree instanceOfTree) { + currentBlock.elements.add(instanceOfTree); + build(instanceOfTree.pattern()); + build(instanceOfTree.expression()); + } + + private void buildNewArray(NewArrayTree tree) { + currentBlock.elements.add(tree); + build(tree.dimensions()); + build(tree.initializers()); + } + + private void buildAssertStatement(AssertStatementTree assertStatementTree) { + currentBlock.elements.add(assertStatementTree); + // Ignore detail expression as it is only evaluated when assertion is false. + build(assertStatementTree.condition()); + } + + private Block createUnconditionalJump(Tree terminator, @Nullable Block target, @Nullable Block successorWithoutJump) { + Block result = createBlock(); + result.terminator = terminator; + if (target != null) { + if (target == exitBlock()) { + result.addExitSuccessor(target); + } else { + result.addSuccessor(target); + } + } + result.successorWithoutJump = successorWithoutJump; + return result; + } + + private void buildCondition(Tree syntaxNode, Block trueBlock, Block falseBlock) { + switch (syntaxNode.kind()) { + case CONDITIONAL_OR: + buildConditionalOr((BinaryExpressionTree) syntaxNode, trueBlock, falseBlock); + break; + case CONDITIONAL_AND: + // process RHS + buildConditionalAnd((BinaryExpressionTree) syntaxNode, trueBlock, falseBlock); + break; + // Skip syntactic sugar: + case PARENTHESIZED_EXPRESSION: + buildCondition(((ParenthesizedTree) syntaxNode).expression(), trueBlock, falseBlock); + break; + default: + build(syntaxNode); + break; + } + } + + private void buildConditionalOr(BinaryExpressionTree conditionalOr, Block trueBlock, Block falseBlock) { + // process RHS + buildCondition(conditionalOr.rightOperand(), trueBlock, falseBlock); + Block newFalseBlock = currentBlock; + // process LHS + currentBlock = createBranch(conditionalOr, trueBlock, newFalseBlock); + buildCondition(conditionalOr.leftOperand(), trueBlock, newFalseBlock); + } + + private void buildConditionalAnd(BinaryExpressionTree conditionalAnd, Block trueBlock, Block falseBlock) { + buildCondition(conditionalAnd.rightOperand(), trueBlock, falseBlock); + Block newTrueBlock = currentBlock; + // process LHS + currentBlock = createBranch(conditionalAnd, newTrueBlock, falseBlock); + buildCondition(conditionalAnd.leftOperand(), newTrueBlock, falseBlock); + } + + private Block createBranch(Tree terminator, Block trueBranch, Block falseBranch) { + Block result = createBlock(); + result.terminator = terminator; + result.addFalseSuccessor(falseBranch); + result.addTrueSuccessor(trueBranch); + return result; + } + + public void setMethodSymbol(Symbol.MethodSymbol methodSymbol) { + this.methodSymbol = methodSymbol; + } + + private void buildPattern(PatternTree tree) { + switch (tree.kind()) { + case NULL_PATTERN: + buildNullPattern((NullPatternTree) tree); + break; + case TYPE_PATTERN: + buildTypePattern((TypePatternTree) tree); + break; + case GUARDED_PATTERN: + buildGuardedPattern((GuardedPatternTree) tree); + break; + case RECORD_PATTERN: + buildRecordPattern((RecordPatternTree) tree); + break; + case DEFAULT_PATTERN: + // do nothing - handled when building the switch + currentBlock.elements.add(tree); + break; + default: + throw new UnsupportedOperationException(tree.kind().name() + " " + ((JavaTree) tree).getLine()); + } + } + + private void buildNullPattern(NullPatternTree tree) { + currentBlock.elements.add(tree.nullLiteral()); + currentBlock.elements.add(tree); + } + + private void buildTypePattern(TypePatternTree tree) { + buildVariable(tree.patternVariable()); + currentBlock.elements.add(tree); + } + + private void buildGuardedPattern(GuardedPatternTree tree) { + // reverted order + build(tree.expression()); + build(tree.pattern()); + currentBlock.elements.add(tree); + } + + private void buildRecordPattern(RecordPatternTree tree) { + build(tree.patterns()); + build(tree.type()); + currentBlock.elements.add(tree); + } + +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/cfg/CFG.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/cfg/CFG.textproto.gz new file mode 100644 index 00000000000..9a4048344ed Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/cfg/CFG.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/MethodMatchersBuilder.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/MethodMatchersBuilder.expected.txt.gz new file mode 100644 index 00000000000..a5f6f49a427 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/MethodMatchersBuilder.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/MethodMatchersBuilder.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/MethodMatchersBuilder.java new file mode 100644 index 00000000000..9950b15dd44 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/MethodMatchersBuilder.java @@ -0,0 +1,266 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.matcher; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import org.sonarsource.analyzer.commons.collections.SetUtils; +import org.sonar.plugins.java.api.semantic.MethodMatchers; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.MethodInvocationTree; +import org.sonar.plugins.java.api.tree.MethodReferenceTree; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.NewClassTree; +import org.sonar.plugins.java.api.tree.Tree; + +public class MethodMatchersBuilder implements MethodMatchers.TypeBuilder, MethodMatchers.NameBuilder, MethodMatchers.ParametersBuilder, MethodMatchers { + + @Nullable + private final Predicate typePredicate; + + @Nullable + private final Predicate namePredicate; + + @Nullable + private final Predicate> parametersPredicate; + + public MethodMatchersBuilder() { + this.typePredicate = null; + this.namePredicate = null; + this.parametersPredicate = null; + } + + private MethodMatchersBuilder(@Nullable Predicate typePredicate, @Nullable Predicate namePredicate, @Nullable Predicate> parametersPredicate) { + this.typePredicate = typePredicate; + this.namePredicate = namePredicate; + this.parametersPredicate = parametersPredicate; + } + + private static Predicate substituteAny(Predicate predicate, String... elements) { + if (SetUtils.immutableSetOf(elements).contains(ANY)) { + if (elements.length > 1) { + throw new IllegalStateException("Incompatible MethodMatchers.ANY with other predicates."); + } + return e -> true; + } + return predicate; + } + + private static Predicate substituteAnyAndCreateEfficientPredicate( + String[] elements, + Function> singleElementPredicate, + Function, Predicate> multiElementsPredicate) { + if (elements.length == 0) { + throw new IllegalStateException("Method arguments can not be empty, otherwise the predicate would be always false."); + } + if (elements.length == 1) { + String singleElement = elements[0]; + return substituteAny(singleElementPredicate.apply(singleElement), elements); + } else { + List multiElements = Arrays.asList(elements); + return substituteAny(multiElementsPredicate.apply(multiElements), elements); + } + } + + @Override + public NameBuilder ofSubTypes(String... fullyQualifiedTypeNames) { + return ofType(substituteAnyAndCreateEfficientPredicate( + fullyQualifiedTypeNames, + name -> (type -> type.isSubtypeOf(name)), + names -> (type -> names.stream().anyMatch(type::isSubtypeOf)))); + } + + @Override + public NameBuilder ofAnyType() { + return ofTypes(ANY); + } + + @Override + public NameBuilder ofTypes(String... fullyQualifiedTypeNames) { + return ofType(substituteAnyAndCreateEfficientPredicate( + fullyQualifiedTypeNames, + name -> (type -> type.is(name)), + names -> (type -> names.stream().anyMatch(type::is)))); + } + + @Override + public NameBuilder ofType(Predicate typePredicate) { + return new MethodMatchersBuilder(or(this.typePredicate, typePredicate), namePredicate, parametersPredicate); + } + + @Override + public ParametersBuilder names(String... names) { + return name(substituteAnyAndCreateEfficientPredicate( + names, + name -> name::equals, + nameList -> nameList::contains)); + } + + @Override + public ParametersBuilder anyName() { + return names(ANY); + } + + @Override + public ParametersBuilder constructor() { + return names(MethodMatchers.CONSTRUCTOR); + } + + @Override + public ParametersBuilder name(Predicate namePredicate) { + return new MethodMatchersBuilder(typePredicate, or(this.namePredicate, namePredicate), parametersPredicate); + } + + @Override + public ParametersBuilder addParametersMatcher(String... parametersType) { + return addParametersMatcher(Arrays.stream(parametersType) + .>map(parameterType -> substituteAny(type -> type.is(parameterType), parameterType)) + .toList()); + } + + private ParametersBuilder addParametersMatcher(List> parametersType) { + return addParametersMatcher((List actualTypes) -> exactMatchesParameters(parametersType, actualTypes)); + } + + @Override + public ParametersBuilder addWithoutParametersMatcher() { + return addParametersMatcher(Collections.emptyList()); + } + + @Override + public ParametersBuilder withAnyParameters() { + if (parametersPredicate != null) { + throw new IllegalStateException("Incompatible 'any parameters' constraint added to existing parameters constraint."); + } + return addParametersMatcher((List actualParameters) -> true); + } + + @Override + public ParametersBuilder addParametersMatcher(Predicate> parametersPredicate) { + return new MethodMatchersBuilder(typePredicate, namePredicate, or(this.parametersPredicate, parametersPredicate)); + } + + private static boolean exactMatchesParameters(List> expectedTypes, List actualTypes) { + return actualTypes.size() == expectedTypes.size() && matchesParameters(expectedTypes, actualTypes); + } + + private static boolean matchesParameters(List> expectedTypes, List actualTypes) { + for (int i = 0; i < expectedTypes.size(); i++) { + if (!expectedTypes.get(i).test(actualTypes.get(i))) { + return false; + } + } + return true; + } + + @Override + public boolean matches(NewClassTree newClassTree) { + return matches(newClassTree.methodSymbol(), null); + } + + @Override + public boolean matches(MethodInvocationTree mit) { + IdentifierTree id = getIdentifier(mit); + return matches(id.symbol(), getCallSiteType(mit)); + } + + @Override + public boolean matches(MethodTree methodTree) { + Symbol.MethodSymbol symbol = methodTree.symbol(); + Symbol.TypeSymbol enclosingClass = symbol.enclosingClass(); + return enclosingClass != null && matches(symbol, enclosingClass.type()); + } + + @Override + public boolean matches(MethodReferenceTree methodReferenceTree) { + return matches(methodReferenceTree.method().symbol(), getCallSiteType(methodReferenceTree)); + } + + @Override + public boolean matches(Symbol symbol) { + return matches(symbol, null); + } + + @Override + public MethodMatchers build() { + if (typePredicate == null || namePredicate == null || parametersPredicate == null) { + throw new IllegalStateException("MethodMatchers need to be fully initialized."); + } + return this; + } + + private boolean matches(Symbol symbol, @Nullable Type callSiteType) { + return symbol.isMethodSymbol() && isSearchedMethod((Symbol.MethodSymbol) symbol, callSiteType); + } + + @CheckForNull + private static Type getCallSiteType(MethodReferenceTree referenceTree) { + Tree expression = referenceTree.expression(); + if (expression instanceof ExpressionTree expressionTree) { + return expressionTree.symbolType(); + } + return null; + } + + @CheckForNull + private static Type getCallSiteType(MethodInvocationTree mit) { + ExpressionTree methodSelect = mit.methodSelect(); + // methodSelect can only be Tree.Kind.IDENTIFIER or Tree.Kind.MEMBER_SELECT + if (methodSelect.is(Tree.Kind.IDENTIFIER)) { + Symbol.TypeSymbol enclosingClassSymbol = ((IdentifierTree) methodSelect).symbol().enclosingClass(); + return enclosingClassSymbol != null ? enclosingClassSymbol.type() : null; + } else { + return ((MemberSelectExpressionTree) methodSelect).expression().symbolType(); + } + } + + private boolean isSearchedMethod(Symbol.MethodSymbol symbol, @Nullable Type callSiteType) { + Type type = callSiteType; + if (type == null) { + Symbol owner = symbol.owner(); + if (owner != null) { + type = owner.type(); + } + } + return type != null && + namePredicate.test(symbol.name()) && + parametersPredicate.test(symbol.parameterTypes()) && + typePredicate.test(type); + } + + private static IdentifierTree getIdentifier(MethodInvocationTree mit) { + // methodSelect can only be Tree.Kind.IDENTIFIER or Tree.Kind.MEMBER_SELECT + if (mit.methodSelect().is(Tree.Kind.IDENTIFIER)) { + return (IdentifierTree) mit.methodSelect(); + } + return ((MemberSelectExpressionTree) mit.methodSelect()).identifier(); + } + + private static Predicate or(@Nullable Predicate accumulator, Predicate next) { + return accumulator != null ? accumulator.or(next) : next; + } + +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/MethodMatchersBuilder.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/MethodMatchersBuilder.textproto.gz new file mode 100644 index 00000000000..199455ed822 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/MethodMatchersBuilder.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/TreeMatcher.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/TreeMatcher.expected.txt.gz new file mode 100644 index 00000000000..d56e69be5e8 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/TreeMatcher.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/TreeMatcher.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/TreeMatcher.java new file mode 100644 index 00000000000..de896475dc4 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/TreeMatcher.java @@ -0,0 +1,162 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.matcher; + +import org.sonar.plugins.java.api.semantic.MethodMatchers; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.tree.BlockTree; +import org.sonar.plugins.java.api.tree.ExpressionStatementTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.ForEachStatement; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.LambdaExpressionTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.MethodInvocationTree; +import org.sonar.plugins.java.api.tree.StatementTree; +import org.sonar.plugins.java.api.tree.Tree; + +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; + +public class TreeMatcher { + private final Predicate predicate; + + private TreeMatcher(Predicate predicate) { + this.predicate = predicate; + } + + public boolean check(T tree) { + return predicate.test(tree); + } + + public TreeMatcher and(TreeMatcher other) { + return new TreeMatcher<>(predicate.and(other.predicate)); + } + + public TreeMatcher or(TreeMatcher other) { + return new TreeMatcher<>(predicate.or(other.predicate)); + } + + /** Method to allow defining a matcher that refers to itself. */ + public static TreeMatcher recursive(UnaryOperator> treeMatcherMaker) { + AtomicReference> treeMatcherWrapper = new AtomicReference<>(); + TreeMatcher matcherUsingWrapper = new TreeMatcher<>(tree -> treeMatcherWrapper.get().check(tree)); + TreeMatcher matcher = treeMatcherMaker.apply(matcherUsingWrapper); + treeMatcherWrapper.set(matcher); + return treeMatcherWrapper.get(); + } + + public static TreeMatcher matching(Predicate predicate) { + return new TreeMatcher<>(predicate); + } + + public static TreeMatcher any() { + return new TreeMatcher<>(x -> true); + } + + public Predicate asPredicate() { + return predicate; + } + + public static TreeMatcher calls( + MethodMatchers methodMatchers, TreeMatcher methodInvocationMatcher) { + return new TreeMatcher<>( + expressionTree -> (expressionTree instanceof MethodInvocationTree mit + && methodMatchers.matches(mit) && methodInvocationMatcher.check(mit))); + } + + public static TreeMatcher calls(MethodMatchers methodMatchers) { + return calls(methodMatchers, any()); + } + + public static TreeMatcher isCall(TreeMatcher methodInvocationMatcher) { + return new TreeMatcher<>( + expressionTree -> (expressionTree instanceof MethodInvocationTree mit + && methodInvocationMatcher.check(mit))); + } + + public static TreeMatcher isInvocationOf( + MethodMatchers methodMatchers, TreeMatcher methodInvocationMatcher) { + return new TreeMatcher<>( + statementTree -> (statementTree instanceof ExpressionStatementTree exprStatement + && calls(methodMatchers, methodInvocationMatcher).check(exprStatement.expression()))); + } + + public static TreeMatcher isInvocationOf(MethodMatchers methodMatchers) { + return isInvocationOf(methodMatchers, any()); + } + + public static TreeMatcher isInvocation(TreeMatcher methodInvocationMatcher) { + return new TreeMatcher<>( + statementTree -> (statementTree instanceof ExpressionStatementTree exprStatement + && isCall(methodInvocationMatcher).check(exprStatement.expression()))); + } + + public static TreeMatcher isIdentifier(String name) { + return new TreeMatcher<>(expressionTree -> expressionTree instanceof IdentifierTree id && id.name().equals(name)); + } + + public static TreeMatcher isIdentifier(Symbol symbol) { + return new TreeMatcher<>(expressionTree -> expressionTree instanceof IdentifierTree id && id.symbol().equals(symbol)); + } + + public static TreeMatcher isIdentifier(IdentifierTree identifier) { + return isIdentifier(identifier.symbol()); + } + + public static TreeMatcher isLambdaExpression(TreeMatcher lambdaMatcher) { + return new TreeMatcher<>(expressionTree -> expressionTree instanceof LambdaExpressionTree lambda && lambdaMatcher.check(lambda)); + } + + public static TreeMatcher withBody(TreeMatcher bodyMatcher) { + return new TreeMatcher<>(lambda -> bodyMatcher.check(lambda.body())); + } + + public static TreeMatcher isExpression(TreeMatcher expressionMatcher) { + return new TreeMatcher<>(tree -> tree instanceof ExpressionTree expr && expressionMatcher.check(expr)); + } + + public static TreeMatcher hasSize(int size) { + return new TreeMatcher<>(tree -> (tree instanceof BlockTree block && block.body().size() == size) + || (tree instanceof StatementTree && size == 1)); + } + + public static TreeMatcher statementAt(int index, TreeMatcher statementMatcher) { + return new TreeMatcher<>(tree -> + ((tree instanceof BlockTree block && block.body().size() > index && statementMatcher.check(block.body().get(index))) + || (tree instanceof ExpressionStatementTree statement && index == 0 && statementMatcher.check(statement)))); + } + + public static TreeMatcher forEachStatement(TreeMatcher forEachMatcher) { + return new TreeMatcher<>(statement -> statement instanceof ForEachStatement forEachStatement && + forEachMatcher.check(forEachStatement)); + } + + public static TreeMatcher withExpression(TreeMatcher expressionMatcher) { + return new TreeMatcher<>(forEach -> expressionMatcher.check(forEach.expression())); + } + + public static TreeMatcher invokedOn(TreeMatcher expressionMatcher) { + return new TreeMatcher<>(mit -> mit.methodSelect() instanceof MemberSelectExpressionTree mset + && expressionMatcher.check(mset.expression())); + } + + public static TreeMatcher withArgument(int index, TreeMatcher expressionMatcher) { + return new TreeMatcher<>(mit -> mit.arguments().size() > index && expressionMatcher.check(mit.arguments().get(index))); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/TreeMatcher.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/TreeMatcher.textproto.gz new file mode 100644 index 00000000000..ee7897962f1 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/matcher/TreeMatcher.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ExpressionUtils.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ExpressionUtils.expected.txt.gz new file mode 100644 index 00000000000..e5f2cf6ff3d Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ExpressionUtils.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ExpressionUtils.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ExpressionUtils.java new file mode 100644 index 00000000000..a028bd92d99 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ExpressionUtils.java @@ -0,0 +1,451 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.model; + +import java.util.Optional; +import java.util.function.BiFunction; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonar.plugins.java.api.semantic.Symbol; +import org.sonar.plugins.java.api.semantic.Type; +import org.sonar.plugins.java.api.semantic.Type.Primitives; +import org.sonar.plugins.java.api.tree.AssignmentExpressionTree; +import org.sonar.plugins.java.api.tree.BinaryExpressionTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; +import org.sonar.plugins.java.api.tree.LiteralTree; +import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; +import org.sonar.plugins.java.api.tree.MethodInvocationTree; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.ParenthesizedTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.UnaryExpressionTree; +import org.sonar.plugins.java.api.tree.VariableTree; + +public final class ExpressionUtils { + + private static final Logger LOG = LoggerFactory.getLogger(ExpressionUtils.class); + + private ExpressionUtils() { + } + + /** + * In case of simple assignments, only the expression is evaluated, as we only use the reference to the variable to store the result. + * For SE-Based checks, only a single value should be unstacked if its the case. For other cases, two values should be unstacked. + * See JLS8-15.26 + * + * @param tree The assignment tree + * @return true if the tree is a simple assignment + * @see #extractIdentifier(AssignmentExpressionTree) + */ + public static boolean isSimpleAssignment(AssignmentExpressionTree tree) { + if (!tree.is(Tree.Kind.ASSIGNMENT)) { + // This can't possibly be a simple assignment. + return false; + } + + ExpressionTree variable = ExpressionUtils.skipParentheses(tree.variable()); + return variable.is(Tree.Kind.IDENTIFIER) || isSelectOnThisOrSuper(tree); + } + + /** + * Checks of is the given tree is a {@link MemberSelectExpressionTree} which is selecting with this or super + * @param tree The tree to check. + * @return true when the tree is a select on this or super + * @see #isSelectOnThisOrSuper(MemberSelectExpressionTree) + */ + public static boolean isSelectOnThisOrSuper(AssignmentExpressionTree tree) { + ExpressionTree variable = ExpressionUtils.skipParentheses(tree.variable()); + return variable.is(Tree.Kind.MEMBER_SELECT) && isSelectOnThisOrSuper((MemberSelectExpressionTree) variable); + } + + /** + * Checks of is the given tree is selecting with this or super + * @param tree The tree to check. + * @return true when the tree is a select on this or super + * @see #isSelectOnThisOrSuper(AssignmentExpressionTree) + */ + public static boolean isSelectOnThisOrSuper(MemberSelectExpressionTree tree) { + if (!tree.expression().is(Tree.Kind.IDENTIFIER)) { + // This is no longer simple. + return false; + } + + String selectSourceName = ((IdentifierTree) tree.expression()).name(); + return "this".equalsIgnoreCase(selectSourceName) || "super".equalsIgnoreCase(selectSourceName); + } + + public static boolean isThisOrSuper(String name) { + return "this".equals(name) || "super".equals(name); + } + + public static IdentifierTree extractIdentifier(AssignmentExpressionTree tree) { + Optional identifier = extractIdentifier(tree.variable()); + + if (identifier.isPresent()) { + return identifier.get(); + } + + // This should not be possible. + // If it happens anyway, you should make sure the assignment is simple (by calling isSimpleAssignment) before. + throw new IllegalArgumentException("Can not extract identifier."); + } + + private static Optional extractIdentifier(ExpressionTree tree) { + ExpressionTree cleanedExpression = ExpressionUtils.skipParentheses(tree); + if (cleanedExpression.is(Tree.Kind.IDENTIFIER)) { + return Optional.of(((IdentifierTree) cleanedExpression)); + } else if (cleanedExpression.is(Tree.Kind.MEMBER_SELECT)) { + MemberSelectExpressionTree selectTree = (MemberSelectExpressionTree) cleanedExpression; + if (isSelectOnThisOrSuper(selectTree)) { + return Optional.of(selectTree.identifier()); + } + } + return Optional.empty(); + } + + public static Optional extractIdentifierSymbol(ExpressionTree tree) { + return extractIdentifier(tree).map(IdentifierTree::symbol); + } + + /** + * Return whether we are sure that the method invocation is on a given variable. + * + * If unsure (variable is null, or we can not extract an identifier from the method invocation), + * return a default value + */ + public static boolean isInvocationOnVariable(MethodInvocationTree mit, @Nullable Symbol variable, boolean defaultReturn) { + ExpressionTree methodSelect = mit.methodSelect(); + if (variable == null || !methodSelect.is(Tree.Kind.MEMBER_SELECT)) { + return defaultReturn; + } + return extractIdentifierSymbol(((MemberSelectExpressionTree) methodSelect).expression()) + .map(variable::equals) + .orElse(defaultReturn); + } + + public static ExpressionTree skipParentheses(ExpressionTree tree) { + ExpressionTree result = tree; + while (result.is(Tree.Kind.PARENTHESIZED_EXPRESSION)) { + result = ((ParenthesizedTree) result).expression(); + } + return result; + } + + @Nullable + public static Tree skipParenthesesUpwards(@Nullable Tree tree) { + while (tree != null && tree.is(Tree.Kind.PARENTHESIZED_EXPRESSION)) { + tree = tree.parent(); + } + return tree; + } + + public static boolean isNullLiteral(ExpressionTree tree) { + return skipParentheses(tree).is(Tree.Kind.NULL_LITERAL); + } + + public static boolean isSecuringByte(ExpressionTree expression) { + if (expression.is(Tree.Kind.AND)) { + BinaryExpressionTree and = (BinaryExpressionTree) expression; + return LiteralUtils.is0xff(and.rightOperand()) || LiteralUtils.is0xff(and.leftOperand()); + } + return false; + } + + /** + * Retrieve the identifier corresponding to the method name associated to the method invocation + */ + public static IdentifierTree methodName(MethodInvocationTree mit) { + ExpressionTree methodSelect = mit.methodSelect(); + IdentifierTree id; + if (methodSelect.is(Tree.Kind.IDENTIFIER)) { + id = (IdentifierTree) methodSelect; + } else { + id = ((MemberSelectExpressionTree) methodSelect).identifier(); + } + return id; + } + + /** + * Return the first enclosing method or constructor containing the given expression. + */ + @CheckForNull + public static MethodTree getEnclosingMethod(ExpressionTree expr) { + return (MethodTree) getEnclosingTree(expr, Tree.Kind.METHOD, Tree.Kind.CONSTRUCTOR); + } + + @CheckForNull + public static Tree getEnclosingTree(Tree expr, Tree.Kind... kinds) { + Tree result = expr.parent(); + while (result != null && !result.is(kinds)) { + result = result.parent(); + } + return result; + } + + @Nullable + public static Tree getParentOfType(Tree tree, Tree.Kind... kinds) { + Tree result = tree.parent(); + while (result != null && !result.is(kinds)) { + result = result.parent(); + } + return result; + } + + public static Optional getAssignedSymbol(ExpressionTree exp) { + Tree parent = exp.parent(); + if (parent != null) { + if (parent.is(Tree.Kind.ASSIGNMENT)) { + return extractIdentifierSymbol(((AssignmentExpressionTree) parent).variable()); + } else if (parent.is(Tree.Kind.VARIABLE)) { + return Optional.of(((VariableTree) parent).simpleName().symbol()); + } + } + return Optional.empty(); + } + + /** + * Checks if the given expression refers to "this" + * @param expression the expression to check + * @return true if this expression refers to "this" + */ + public static boolean isThis(ExpressionTree expression) { + ExpressionTree newExpression = ExpressionUtils.skipParentheses(expression); + return newExpression.is(Tree.Kind.IDENTIFIER) && "this".equals(((IdentifierTree) newExpression).name()); + } + + @CheckForNull + public static Object resolveAsConstant(ExpressionTree tree) { + ExpressionTree expression = tree; + while (expression.is(Tree.Kind.PARENTHESIZED_EXPRESSION)) { + expression = ((ParenthesizedTree) expression).expression(); + } + if (expression.is(Tree.Kind.MEMBER_SELECT)) { + expression = ((MemberSelectExpressionTree) expression).identifier(); + } + if (expression.is(Tree.Kind.IDENTIFIER)) { + return resolveIdentifier((IdentifierTree) expression); + } + if (expression.is(Tree.Kind.BOOLEAN_LITERAL)) { + return Boolean.parseBoolean(((LiteralTree) expression).value()); + } + if (expression.is(Tree.Kind.STRING_LITERAL, Tree.Kind.TEXT_BLOCK)) { + return LiteralUtils.getAsStringValue((LiteralTree) expression); + } + if (expression instanceof UnaryExpressionTree unaryExpressionTree) { + return resolveUnaryExpression(unaryExpressionTree); + } + if (expression.is(Tree.Kind.INT_LITERAL)) { + return LiteralUtils.intLiteralValue(expression); + } + if (expression.is(Tree.Kind.CHAR_LITERAL)) { + return LiteralUtils.charLiteralValue((LiteralTree) expression); + } + if (expression.is(Tree.Kind.LONG_LITERAL)) { + return LiteralUtils.longLiteralValue(expression); + } + if (expression.is(Tree.Kind.PLUS)) { + return resolvePlus((BinaryExpressionTree) expression); + } + if (expression.is(Tree.Kind.OR)) { + return resolveOr((BinaryExpressionTree) expression); + } + if (expression.is(Tree.Kind.MINUS)) { + return resolveArithmeticOperation((BinaryExpressionTree) expression, (a, b) -> a - b, (a, b) -> a - b); + } + if (expression.is(Tree.Kind.MULTIPLY)) { + return resolveArithmeticOperation((BinaryExpressionTree) expression, (a, b) -> a * b, (a, b) -> a * b); + } + if (expression.is(Tree.Kind.DIVIDE)) { + return resolveArithmeticOperation((BinaryExpressionTree) expression, (a, b) -> a / b, (a, b) -> a / b); + } + if (expression.is(Tree.Kind.REMAINDER)) { + return resolveArithmeticOperation((BinaryExpressionTree) expression, (a, b) -> a % b, (a, b) -> a % b); + } + return null; + } + + public static boolean areVariablesSame(Tree tree1, Tree tree2, boolean defaultValue) { + Symbol symbol1 = getSymbol(tree1); + Symbol symbol2 = getSymbol(tree2); + if (symbol1 == null || symbol1.isUnknown() || symbol2 == null || symbol2.isUnknown()) { + return defaultValue; + } + return symbol1.name().equals(symbol2.name()); + } + + @CheckForNull + private static Symbol getSymbol(Tree tree) { + Symbol symbol = null; + if (tree.is(Tree.Kind.IDENTIFIER)) { + symbol = ((IdentifierTree) tree).symbol(); + } else if (tree.is(Tree.Kind.MEMBER_SELECT)) { + symbol = ((MemberSelectExpressionTree) tree).identifier().symbol(); + } + return symbol; + } + + @CheckForNull + private static Object resolveUnaryExpression(UnaryExpressionTree unaryExpression) { + Object value = resolveAsConstant(unaryExpression.expression()); + if (unaryExpression.is(Tree.Kind.UNARY_PLUS)) { + return value; + } else if (unaryExpression.is(Tree.Kind.UNARY_MINUS)) { + if (value instanceof Long longValue) { + return -longValue; + } else if (value instanceof Integer intValue) { + return -intValue; + } + } else if (unaryExpression.is(Tree.Kind.BITWISE_COMPLEMENT)) { + if (value instanceof Long longValue) { + return ~longValue; + } else if (value instanceof Integer intValue) { + return ~intValue; + } + } else if (unaryExpression.is(Tree.Kind.LOGICAL_COMPLEMENT) && value instanceof Boolean bool) { + return !bool; + } + return null; + } + + @CheckForNull + private static Object resolveIdentifier(IdentifierTree tree) { + Symbol symbol = tree.symbol(); + if (!symbol.isVariableSymbol()) { + return null; + } + Symbol owner = symbol.owner(); + if (owner.isTypeSymbol() && owner.type().is("java.lang.Boolean")) { + if ("TRUE".equals(symbol.name())) { + return Boolean.TRUE; + } else if ("FALSE".equals(symbol.name())) { + return Boolean.FALSE; + } + } + return ((Symbol.VariableSymbol) symbol).constantValue().orElse(null); + } + + @CheckForNull + private static Object resolvePlus(BinaryExpressionTree binaryExpression) { + Object left = resolveAsConstant(binaryExpression.leftOperand()); + Object right = resolveAsConstant(binaryExpression.rightOperand()); + if (left == null || right == null) { + return null; + } else if (left instanceof String leftString) { + return leftString + stringConcatenationValue(right, binaryExpression.rightOperand()); + } else if (right instanceof String rightString) { + return stringConcatenationValue(left, binaryExpression.leftOperand()) + rightString; + } + return resolveArithmeticOperation(left, right, Long::sum, Integer::sum); + } + + private static String stringConcatenationValue(Object value, ExpressionTree expression) { + if (value instanceof Integer intValue && (skipParentheses(expression).is(Tree.Kind.CHAR_LITERAL) || expression.symbolType().isPrimitive(Primitives.CHAR))) { + return Character.toString(intValue); + } + return value.toString(); + } + + @CheckForNull + private static Object resolveArithmeticOperation(BinaryExpressionTree binaryExpression, + BiFunction longOperation, + BiFunction intOperation) { + Object left = resolveAsConstant(binaryExpression.leftOperand()); + Object right = resolveAsConstant(binaryExpression.rightOperand()); + if (left == null || right == null) { + return null; + } + return resolveArithmeticOperation(left, right, longOperation, intOperation); + } + + @CheckForNull + private static Object resolveArithmeticOperation(Object left, Object right, BiFunction longOperation, BiFunction intOperation) { + try { + if (left instanceof Integer leftInt && right instanceof Integer rightInt) { + return intOperation.apply(leftInt, rightInt); + } else if ((left instanceof Long || right instanceof Long) && (left instanceof Integer || right instanceof Integer)) { + return longOperation.apply(((Number) left).longValue(), ((Number) right).longValue()); + } + } catch (ArithmeticException e) { + LOG.debug("Arithmetic exception while resolving arithmetic operation value", e); + } + return null; + } + + @CheckForNull + private static Object resolveOr(BinaryExpressionTree binaryExpression) { + Object left = resolveAsConstant(binaryExpression.leftOperand()); + Object right = resolveAsConstant(binaryExpression.rightOperand()); + if (left == null || right == null) { + return null; + } else if (left instanceof Long leftLong && right instanceof Long rightLong) { + return leftLong | rightLong; + } else if (left instanceof Long leftLong && right instanceof Integer rightInt) { + return leftLong | rightInt; + } else if (left instanceof Integer leftInt && right instanceof Long rightLong) { + return leftInt | rightLong; + } else if (left instanceof Integer leftInt && right instanceof Integer rightInt) { + return leftInt | rightInt; + } + return null; + } + + public static String annotationAttributeName(ExpressionTree expression) { + if (expression.is(Tree.Kind.ASSIGNMENT)) { + AssignmentExpressionTree assignment = (AssignmentExpressionTree) expression; + // assignment.variable() in annotation is always a Tree.Kind.IDENTIFIER + return ((IdentifierTree) assignment.variable()).name(); + } + return "value"; + } + + @Nullable + public static String getNanOwnerTypeName(ExpressionTree expression) { + ExpressionTree expr = skipParentheses(expression); + if (expr.is(Tree.Kind.MEMBER_SELECT)) { + MemberSelectExpressionTree memberSelect = (MemberSelectExpressionTree) expr; + if ("NaN".equals(memberSelect.identifier().name())) { + return resolveNanOwnerType(memberSelect.identifier().symbol()); + } + } else if (expr.is(Tree.Kind.IDENTIFIER)) { + IdentifierTree identifier = (IdentifierTree) expr; + if ("NaN".equals(identifier.name())) { + return resolveNanOwnerType(identifier.symbol()); + } + } + return null; + } + + @Nullable + private static String resolveNanOwnerType(Symbol symbol) { + if (symbol.isUnknown()) { + return null; + } + Symbol owner = symbol.owner(); + if (owner == null || owner.type() == null) { + return null; + } + Type ownerType = owner.type(); + if (ownerType.is("java.lang.Double") || ownerType.is("java.lang.Float")) { + return ownerType.name(); + } + return null; + } + +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ExpressionUtils.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ExpressionUtils.textproto.gz new file mode 100644 index 00000000000..a923d08a2ae Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ExpressionUtils.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/LiteralUtils.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/LiteralUtils.expected.txt.gz new file mode 100644 index 00000000000..dcd7b615050 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/LiteralUtils.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/LiteralUtils.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/LiteralUtils.java new file mode 100644 index 00000000000..5632dcfbad1 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/LiteralUtils.java @@ -0,0 +1,238 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.model; + +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.LiteralTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.Tree.Kind; +import org.sonar.plugins.java.api.tree.UnaryExpressionTree; + +public class LiteralUtils { + + private static final Pattern UNICODE_ESCAPE = Pattern.compile("\\\\u+([0-9a-fA-F]{4})"); + + private LiteralUtils() { + // This class only contains static methods + } + + @CheckForNull + public static Integer intLiteralValue(ExpressionTree expression) { + if (expression.is(Tree.Kind.INT_LITERAL)) { + return intLiteralValue((LiteralTree) expression); + } + if (expression.is(Tree.Kind.UNARY_MINUS, Tree.Kind.UNARY_PLUS)) { + UnaryExpressionTree unaryExp = (UnaryExpressionTree) expression; + Integer subExpressionIntValue = intLiteralValue(unaryExp.expression()); + return expression.is(Tree.Kind.UNARY_MINUS) ? minus(subExpressionIntValue) : subExpressionIntValue; + } + return null; + } + + private static Integer intLiteralValue(LiteralTree literal) { + String literalValue = literal.value().replace("_", ""); + if (literalValue.startsWith("0b") || literalValue.startsWith("0B")) { + // assume it is used as bit mask + return Integer.parseUnsignedInt(literalValue.substring(2), 2); + } + return Long.decode(literalValue).intValue(); + } + + /** + * Decodes a character literal using Java's Unicode translation followed by escape processing, + * returning its promoted integer value. + */ + public static int charLiteralValue(LiteralTree literal) { + String translated = UNICODE_ESCAPE.matcher(literal.value()) + .replaceAll(match -> Matcher.quoteReplacement(String.valueOf((char) Integer.parseInt(match.group(1), 16)))); + return trimQuotes(translated).translateEscapes().charAt(0); + } + + @CheckForNull + public static Long longLiteralValue(ExpressionTree tree) { + ExpressionTree expression = tree; + + int sign = tree.is(Kind.UNARY_MINUS) ? -1 : 1; + if (tree.is(Kind.UNARY_MINUS, Kind.UNARY_PLUS)) { + expression = ((UnaryExpressionTree) tree).expression(); + } + + if (expression.is(Kind.INT_LITERAL, Kind.LONG_LITERAL)) { + String value = trimLongSuffix(((LiteralTree) expression).value()); + // long as hexadecimal can be written using underscore to separate groups + value = value.replace("_", ""); + try { + if (value.startsWith("0b") || value.startsWith("0B")) { + return sign * Long.valueOf(value.substring(2), 2); + } + return sign * Long.decode(value); + } catch (NumberFormatException e) { + // Long.decode() may fail in case of very large long number written in hexadecimal. In such situation, we ignore the number. + // Note that Long.MAX_VALUE = "0x7FFF_FFFF_FFFF_FFFFL", but it is possible to write larger numbers in hexadecimal + // to be used as mask in bitwise operation. For instance: + // 0x8000_0000_0000_0000L (MAX_VALUE + 1), + // 0xFFFF_FFFF_FFFF_FFFFL (only ones), + // 0xFFFF_FFFF_FFFF_FFFEL (only ones except least significant bit), ... + } + } + return null; + } + + @CheckForNull + public static Double doubleLiteralValue(ExpressionTree expression) { + int sign = 1; + if (expression.is(Kind.UNARY_MINUS, Kind.UNARY_PLUS)) { + sign = expression.is(Kind.UNARY_MINUS) ? -1 : 1; + expression = ((UnaryExpressionTree) expression).expression(); + } + + if (expression.is(Kind.FLOAT_LITERAL, Kind.DOUBLE_LITERAL)) { + String value = ((LiteralTree) expression).value().replace("_", ""); + + return sign*Double.parseDouble(value); + } + return null; + } + + @CheckForNull + private static Integer minus(@Nullable Integer nullableInteger) { + return nullableInteger == null ? null : -nullableInteger; + } + + public static boolean isEmptyString(Tree tree) { + return tree.is(Tree.Kind.STRING_LITERAL) && trimQuotes(((LiteralTree) tree).value()).isEmpty(); + } + + public static boolean is0xff(ExpressionTree expression) { + return expression.is(Tree.Kind.INT_LITERAL) && "0xff".equalsIgnoreCase(((LiteralTree) expression).value()); + } + + public static String trimQuotes(String value) { + int delimiterLength = isTextBlock(value) ? 3 : 1; + return value.substring(delimiterLength, value.length() - delimiterLength); + } + + public static boolean isTextBlock(String value) { + return value.startsWith("\"\"\""); + } + + public static String trimLongSuffix(String longString) { + if (StringUtils.isBlank(longString)) { + return longString; + } + int lastCharPosition = longString.length() - 1; + char lastChar = longString.charAt(lastCharPosition); + String value = longString; + if (lastChar == 'L' || lastChar == 'l') { + value = longString.substring(0, lastCharPosition); + } + return value; + } + + public static boolean hasValue(Tree tree, String expectedValue) { + if (!tree.is(Kind.STRING_LITERAL)) { + return false; + } + String actualValue = trimQuotes(((LiteralTree) tree).value()); + return expectedValue.equals(actualValue); + } + + public static boolean isTrue(Tree tree) { + return tree.is(Kind.BOOLEAN_LITERAL) && "true".equals(((LiteralTree) tree).value()); + } + + public static boolean isFalse(Tree tree) { + return tree.is(Kind.BOOLEAN_LITERAL) && "false".equals(((LiteralTree) tree).value()); + } + + /** + * @return true when the expression is an int literal whose value is zero, in any base: + * decimal ({@code 0}), hexadecimal ({@code 0x0}), octal ({@code 00}) or binary ({@code 0b0}). + */ + public static boolean isZero(ExpressionTree tree) { + if (!tree.is(Kind.INT_LITERAL)) { + return false; + } + try { + return intLiteralValue((LiteralTree) tree) == 0; + } catch (NumberFormatException e) { + return false; + } + } + + public static boolean isOne(ExpressionTree tree) { + return tree.is(Kind.INT_LITERAL) && "1".equals(((LiteralTree) tree).value()); + } + + public static boolean isNegOne(ExpressionTree tree) { + return tree.is(Kind.UNARY_MINUS) && isOne(((UnaryExpressionTree) tree).expression()); + } + + public static String getAsStringValue(LiteralTree tree) { + if (!tree.is(Kind.TEXT_BLOCK)) { + return tree.is(Kind.STRING_LITERAL) ? trimQuotes(tree.value()) : tree.value(); + } + String[] lines = tree.value().split("\r?\n"); + int indent = indentationOfTextBlock(lines); + + return Arrays.stream(lines) + .skip(1) + .map(String::stripTrailing) + .map(s -> stripIndent(indent, s)) + .collect(Collectors.joining("\n")) + .replaceAll("\"\"\"$", ""); + } + + private static String stripIndent(int indent, String s) { + return s.isEmpty() ? s : s.substring(indent); + } + + public static int indentationOfTextBlock(String[] lines) { + return Arrays.stream(lines).skip(1) + .filter(LiteralUtils::isNonEmptyLine) + .mapToInt(LiteralUtils::getIndentation) + .min().orElse(0); + } + + private static boolean isNonEmptyLine(String line) { + return line.chars().anyMatch(LiteralUtils::isNotWhiteSpace); + } + + /** + * @return Whether c is not a white space character according to the space-stripping rules of text blocks, i.e. whether + * it's a space, tab or form feed + */ + private static boolean isNotWhiteSpace(int c) { + return c != ' ' && c != '\t' && c != '\f'; + } + + private static int getIndentation(String line) { + for (int i = 0; i < line.length(); ++i) { + if (isNotWhiteSpace(line.charAt(i))) { + return i; + } + } + return line.length(); + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/LiteralUtils.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/LiteralUtils.textproto.gz new file mode 100644 index 00000000000..ef85768b167 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/LiteralUtils.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ModifiersUtils.expected.txt.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ModifiersUtils.expected.txt.gz new file mode 100644 index 00000000000..b7fe9e14105 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ModifiersUtils.expected.txt.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ModifiersUtils.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ModifiersUtils.java new file mode 100644 index 00000000000..0f0eee79939 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ModifiersUtils.java @@ -0,0 +1,94 @@ +/* + * SonarQube Java + * Copyright (C) SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * You can redistribute and/or modify this program under the terms of + * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.java.model; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import javax.annotation.CheckForNull; +import org.sonar.plugins.java.api.tree.AnnotationTree; +import org.sonar.plugins.java.api.tree.ClassTree; +import org.sonar.plugins.java.api.tree.MethodTree; +import org.sonar.plugins.java.api.tree.Modifier; +import org.sonar.plugins.java.api.tree.ModifierKeywordTree; +import org.sonar.plugins.java.api.tree.ModifiersTree; +import org.sonar.plugins.java.api.tree.PackageDeclarationTree; +import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.VariableTree; + +public final class ModifiersUtils { + + private ModifiersUtils() { + // This class only contains static methods + } + + public static boolean hasModifier(ModifiersTree modifiersTree, Modifier expectedModifier) { + for (ModifierKeywordTree modifierKeywordTree : modifiersTree.modifiers()) { + if (modifierKeywordTree.modifier() == expectedModifier) { + return true; + } + } + return false; + } + + public static boolean hasAll(ModifiersTree modifiersTree, Modifier... expectedModifiers) { + for (Modifier expectedModifier : expectedModifiers) { + if (!hasModifier(modifiersTree, expectedModifier)) { + return false; + } + } + return true; + } + + public static boolean hasAnyOf(ModifiersTree modifiersTree, Modifier... expectedModifiers) { + for (Modifier expectedModifier : expectedModifiers) { + if (hasModifier(modifiersTree, expectedModifier)) { + return true; + } + } + return false; + } + + public static boolean hasNoneOf(ModifiersTree modifiersTree, Modifier... unexpectedModifiers) { + return !hasAnyOf(modifiersTree, unexpectedModifiers); + } + + @CheckForNull + public static ModifierKeywordTree getModifier(ModifiersTree modifiers, Modifier expectedModifier) { + return findModifier(modifiers, expectedModifier).orElse(null); + } + + public static Optional findModifier(ModifiersTree modifiersTree, Modifier expectedModifier) { + return modifiersTree.modifiers().stream() + .filter(modifierKeywordTree -> modifierKeywordTree.modifier() == expectedModifier) + .findAny(); + } + + public static List getAnnotations(Tree tree) { + if (tree.kind() == Tree.Kind.VARIABLE) { + return ((VariableTree) tree).modifiers().annotations(); + } else if (tree instanceof MethodTree methodTree) { + return methodTree.modifiers().annotations(); + } else if (tree instanceof ClassTree classTree) { + return classTree.modifiers().annotations(); + } else if (tree.kind() == Tree.Kind.PACKAGE) { + return ((PackageDeclarationTree) tree).annotations(); + } + return Collections.emptyList(); + } + +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ModifiersUtils.textproto.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ModifiersUtils.textproto.gz new file mode 100644 index 00000000000..f1eb4379ea3 Binary files /dev/null and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/project/org/sonar/java/model/ModifiersUtils.textproto.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/types.json.gz b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/types.json.gz index 7e8b6ec4da2..139bd0f7dce 100644 Binary files a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/types.json.gz and b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/replay/types.json.gz differ diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Outer.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Outer.java new file mode 100644 index 00000000000..943afc651f0 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Outer.java @@ -0,0 +1,5 @@ +package e; + +class Outer { + enum Type { FLOAT32, FLOAT64 } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Outer.textproto b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Outer.textproto new file mode 100644 index 00000000000..7106b1dc207 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Outer.textproto @@ -0,0 +1,482 @@ +tree { + kind: "program" + named: true + start_line: 1 + end_line: 6 + end_byte: 64 + children { + kind: "package_declaration" + named: true + start_line: 1 + end_line: 1 + end_col: 10 + end_byte: 10 + children { + kind: "package" + start_line: 1 + end_line: 1 + end_col: 7 + end_byte: 7 + text: "package" + } + children { + kind: "identifier" + named: true + start_line: 1 + start_col: 8 + end_line: 1 + end_col: 9 + start_byte: 8 + end_byte: 9 + text: "e" + } + children { + kind: ";" + start_line: 1 + start_col: 9 + end_line: 1 + end_col: 10 + start_byte: 9 + end_byte: 10 + text: ";" + } + } + children { + kind: "class_declaration" + named: true + start_line: 3 + end_line: 5 + end_col: 1 + start_byte: 12 + end_byte: 63 + children { + kind: "class" + start_line: 3 + end_line: 3 + end_col: 5 + start_byte: 12 + end_byte: 17 + text: "class" + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 3 + start_col: 6 + end_line: 3 + end_col: 11 + start_byte: 18 + end_byte: 23 + text: "Outer" + decls: "e.Outer`1" + } + children { + kind: "type_parameters" + named: true + field: "type_parameters" + start_line: 3 + start_col: 11 + end_line: 3 + end_col: 14 + start_byte: 23 + end_byte: 26 + children { + kind: "<" + start_line: 3 + start_col: 11 + end_line: 3 + end_col: 12 + start_byte: 23 + end_byte: 24 + text: "<" + } + children { + kind: "type_parameter" + named: true + start_line: 3 + start_col: 12 + end_line: 3 + end_col: 13 + start_byte: 24 + end_byte: 25 + children { + kind: "type_identifier" + named: true + start_line: 3 + start_col: 12 + end_line: 3 + end_col: 13 + start_byte: 24 + end_byte: 25 + text: "T" + decls: "e.Outer`1" + } + } + children { + kind: ">" + start_line: 3 + start_col: 13 + end_line: 3 + end_col: 14 + start_byte: 25 + end_byte: 26 + text: ">" + } + } + children { + kind: "class_body" + named: true + field: "body" + start_line: 3 + start_col: 15 + end_line: 5 + end_col: 1 + start_byte: 27 + end_byte: 63 + children { + kind: "{" + start_line: 3 + start_col: 15 + end_line: 3 + end_col: 16 + start_byte: 27 + end_byte: 28 + text: "{" + } + children { + kind: "enum_declaration" + named: true + start_line: 4 + start_col: 2 + end_line: 4 + end_col: 32 + start_byte: 31 + end_byte: 61 + children { + kind: "enum" + start_line: 4 + start_col: 2 + end_line: 4 + end_col: 6 + start_byte: 31 + end_byte: 35 + text: "enum" + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 4 + start_col: 7 + end_line: 4 + end_col: 11 + start_byte: 36 + end_byte: 40 + text: "Type" + decls: "e.Outer`1$Type" + } + children { + kind: "enum_body" + named: true + field: "body" + start_line: 4 + start_col: 12 + end_line: 4 + end_col: 32 + start_byte: 41 + end_byte: 61 + children { + kind: "{" + start_line: 4 + start_col: 12 + end_line: 4 + end_col: 13 + start_byte: 41 + end_byte: 42 + text: "{" + } + children { + kind: "enum_constant" + named: true + start_line: 4 + start_col: 14 + end_line: 4 + end_col: 21 + start_byte: 43 + end_byte: 50 + children { + kind: "identifier" + named: true + field: "name" + start_line: 4 + start_col: 14 + end_line: 4 + end_col: 21 + start_byte: 43 + end_byte: 50 + text: "FLOAT32" + decls: "e.Outer`1$Type#FLOAT32" + } + } + children { + kind: "," + start_line: 4 + start_col: 21 + end_line: 4 + end_col: 22 + start_byte: 50 + end_byte: 51 + text: "," + } + children { + kind: "enum_constant" + named: true + start_line: 4 + start_col: 23 + end_line: 4 + end_col: 30 + start_byte: 52 + end_byte: 59 + children { + kind: "identifier" + named: true + field: "name" + start_line: 4 + start_col: 23 + end_line: 4 + end_col: 30 + start_byte: 52 + end_byte: 59 + text: "FLOAT64" + decls: "e.Outer`1$Type#FLOAT64" + } + } + children { + kind: "}" + start_line: 4 + start_col: 31 + end_line: 4 + end_col: 32 + start_byte: 60 + end_byte: 61 + text: "}" + } + } + } + children { + kind: "}" + start_line: 5 + end_line: 5 + end_col: 1 + start_byte: 62 + end_byte: 63 + text: "}" + } + } + } +} +path: "e/Outer.java" +semantic: true +symbols { + id: "e.Outer`1#()" + kind: "constructor" + name: "Outer" + owner: "e.Outer`1" + facts { + key: "implicit" + value { + flag: true + } + } +} +symbols { + id: "e.Outer`1$Type#()" + kind: "constructor" + name: "Type" + owner: "e.Outer`1$Type" + facts { + key: "implicit" + value { + flag: true + } + } +} +symbols { + id: "e.Outer`1$Type#valueOf(java.lang.String)" + kind: "method" + name: "valueOf" + owner: "e.Outer`1$Type" + facts { + key: "implicit" + value { + flag: true + } + } +} +symbols { + id: "e.Outer`1$Type#values()" + kind: "method" + name: "values" + owner: "e.Outer`1$Type" + facts { + key: "implicit" + value { + flag: true + } + } +} +symbols { + id: "e.Outer`1" + kind: "type" + name: "Outer" + place { + start_byte: 18 + end_byte: 23 + line: 3 + column: 6 + } +} +symbols { + id: "e.Outer`1" + kind: "type" + name: "T" + owner: "e.Outer`1" + place { + start_byte: 24 + end_byte: 25 + line: 3 + column: 12 + } +} +symbols { + id: "e.Outer`1$Type" + kind: "type" + name: "Type" + owner: "e.Outer`1" + place { + start_byte: 36 + end_byte: 40 + line: 4 + column: 7 + } +} +symbols { + id: "e.Outer`1$Type#FLOAT32" + kind: "enum_member" + name: "FLOAT32" + owner: "e.Outer`1$Type" + place { + start_byte: 43 + end_byte: 50 + line: 4 + column: 14 + } +} +symbols { + id: "e.Outer`1$Type#FLOAT64" + kind: "enum_member" + name: "FLOAT64" + owner: "e.Outer`1$Type" + place { + start_byte: 52 + end_byte: 59 + line: 4 + column: 23 + } +} +facts { + key: "e.Outer`1" + value { + kind: "class" + tier: "IN_PROJECT" + parent: "e/Outer.java::" + props { + name: "simple_name" + values: "Outer" + } + props { + name: "type_fqn" + values: "e.Outer`1" + } + params: "e.Outer`1::`0" + } +} +facts { + key: "e.Outer`1$Type" + value { + kind: "enum" + tier: "IN_PROJECT" + parent: "e.Outer`1" + props { + name: "simple_name" + values: "Type" + } + props { + name: "type_fqn" + values: "e.Outer`1$Type" + } + } +} +facts { + key: "e.Outer`1$Type#()" + value { + kind: "method" + tier: "IN_PROJECT" + parent: "e.Outer`1$Type" + props { + name: "member_name" + values: "Type" + } + props { + name: "param_types" + values: "" + } + props { + name: "type_fqn" + values: "e.Outer`1$Type" + } + } +} +facts { + key: "e.Outer`1$Type#FLOAT32" + value { + kind: "field" + tier: "IN_PROJECT" + parent: "e.Outer`1$Type" + props { + name: "member_name" + values: "FLOAT32" + } + props { + name: "simple_name" + values: "FLOAT32" + } + props { + name: "type_fqn" + values: "e.Outer`1$Type" + } + type: "e.Outer`1$Type" + } +} +facts { + key: "e.Outer`1$Type#FLOAT64" + value { + kind: "field" + tier: "IN_PROJECT" + parent: "e.Outer`1$Type" + props { + name: "member_name" + values: "FLOAT64" + } + props { + name: "simple_name" + values: "FLOAT64" + } + props { + name: "type_fqn" + values: "e.Outer`1$Type" + } + type: "e.Outer`1$Type" + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Outer.types.json b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Outer.types.json new file mode 100644 index 00000000000..2c14d30710d --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Outer.types.json @@ -0,0 +1,3733 @@ +{ + "e.Outer": { + "annotations": [], + "id": "e.Outer`1", + "interfaceTypes": [], + "interfaces": [], + "kind": "class", + "members": [ + { + "annotations": [], + "facts": { + "kind": "enum", + "parent": "e.Outer`1", + "props": { + "simple_name": [ + "Type" + ], + "type_fqn": [ + "e.Outer`1$Type" + ] + }, + "tier": "IN_PROJECT" + }, + "id": "e.Outer`1$Type" + }, + { + "annotations": [], + "facts": { + "kind": "typeparameter", + "parent": "e.Outer`1", + "props": { + "name": [ + "T" + ], + "parameter_kind": [ + "type" + ], + "simple_name": [ + "T" + ] + }, + "tier": "IN_PROJECT" + }, + "id": "e.Outer`1::`0" + } + ], + "modifiers": [], + "origin": "project", + "typeParameters": 1, + "typeVars": [ + "T" + ] + }, + "e.Outer$Type": { + "annotations": [], + "id": "e.Outer`1$Type", + "interfaceTypes": [], + "interfaces": [], + "kind": "enum", + "members": [ + { + "annotations": [], + "facts": { + "kind": "method", + "parent": "e.Outer`1$Type", + "props": { + "member_name": [ + "Type" + ], + "param_types": [ + "" + ], + "type_fqn": [ + "e.Outer`1$Type" + ] + }, + "tier": "IN_PROJECT" + }, + "id": "e.Outer`1$Type#\u003cinit\u003e()", + "throws": [], + "varargs": false + }, + { + "annotations": [], + "facts": { + "kind": "field", + "parent": "e.Outer`1$Type", + "props": { + "member_name": [ + "FLOAT32" + ], + "simple_name": [ + "FLOAT32" + ], + "type_fqn": [ + "e.Outer`1$Type" + ] + }, + "tier": "IN_PROJECT", + "type": [ + "e.Outer`1$Type" + ] + }, + "id": "e.Outer`1$Type#FLOAT32" + }, + { + "annotations": [], + "facts": { + "kind": "field", + "parent": "e.Outer`1$Type", + "props": { + "member_name": [ + "FLOAT64" + ], + "simple_name": [ + "FLOAT64" + ], + "type_fqn": [ + "e.Outer`1$Type" + ] + }, + "tier": "IN_PROJECT", + "type": [ + "e.Outer`1$Type" + ] + }, + "id": "e.Outer`1$Type#FLOAT64" + }, + { + "annotations": [], + "facts": { + "kind": "method", + "parent": "e.Outer`1$Type", + "props": { + "member_name": [ + "values" + ], + "modifiers": [ + "public", + "static" + ], + "param_types": [ + "" + ], + "type_fqn": [ + "e.Outer`1$Type" + ] + }, + "returns": [ + "e.Outer`1$Type[]" + ], + "tier": "IN_PROJECT" + }, + "id": "e.Outer`1$Type#values()", + "throws": [], + "varargs": false + }, + { + "annotations": [], + "facts": { + "kind": "method", + "params": [ + "java.lang.String" + ], + "parent": "e.Outer`1$Type", + "props": { + "member_name": [ + "valueOf" + ], + "modifiers": [ + "public", + "static" + ], + "param_types": [ + "java.lang.String" + ], + "type_fqn": [ + "e.Outer`1$Type" + ] + }, + "returns": [ + "e.Outer`1$Type" + ], + "tier": "IN_PROJECT" + }, + "id": "e.Outer`1$Type#valueOf(java.lang.String)", + "throws": [], + "varargs": false + } + ], + "modifiers": [ + "static" + ], + "origin": "project", + "super": "java.lang.Enum", + "superType": { + "args": [ + { + "args": [], + "id": "e.Outer$Type" + } + ], + "id": "java.lang.Enum" + }, + "typeParameters": 0, + "typeVars": [] + }, + "java.io.Serializable": { + "annotations": [], + "interfaces": [], + "kind": "interface", + "members": [], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "typeParameters": 0, + "typeVars": [] + }, + "java.lang.Comparable": { + "annotations": [], + "interfaceTypes": [], + "interfaces": [], + "kind": "interface", + "members": [ + { + "abstract": true, + "annotations": [], + "desc": "(Ljava/lang/Object;)I", + "final": false, + "k": "m", + "name": "compareTo", + "paramTypes": [ + { + "id": "T", + "kind": "typevar" + } + ], + "paramVars": [ + "c0" + ], + "retSelf": false, + "retType": { + "id": "int" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + } + ], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "superType": { + "args": [], + "id": "java.lang.Object" + }, + "typeParameters": 1, + "typeVarBounds": [ + [ + { + "args": [], + "id": "java.lang.Object" + } + ] + ], + "typeVars": [ + "T" + ] + }, + "java.lang.Enum": { + "annotations": [], + "interfaceTypes": [ + { + "args": [], + "id": "java.lang.constant.Constable" + }, + { + "args": [ + { + "id": "E", + "kind": "typevar" + } + ], + "id": "java.lang.Comparable" + }, + { + "args": [], + "id": "java.io.Serializable" + } + ], + "interfaces": [ + "java.lang.constant.Constable", + "java.lang.Comparable", + "java.io.Serializable" + ], + "kind": "class", + "members": [ + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": true, + "k": "m", + "name": "name", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()I", + "final": true, + "k": "m", + "name": "ordinal", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;I)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toString", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/Object;)Z", + "final": true, + "k": "m", + "name": "equals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()I", + "final": true, + "k": "m", + "name": "hashCode", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/Object;", + "final": true, + "k": "m", + "name": "clone", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.CloneNotSupportedException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/Enum;)I", + "final": true, + "k": "m", + "name": "compareTo", + "paramTypes": [ + { + "id": "E", + "kind": "typevar" + } + ], + "paramVars": [ + "c0" + ], + "retSelf": false, + "retType": { + "id": "int" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/Class;", + "final": true, + "k": "m", + "name": "getDeclaringClass", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "id": "E", + "kind": "typevar" + } + ], + "id": "java.lang.Class" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/Optional;", + "final": true, + "k": "m", + "name": "describeConstable", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "args": [ + { + "id": "E", + "kind": "typevar" + } + ], + "id": "java.lang.Enum$EnumDesc" + } + ], + "id": "java.util.Optional" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;", + "final": false, + "k": "m", + "name": "valueOf", + "paramTypes": [ + { + "args": [ + { + "id": "T", + "kind": "typevar" + } + ], + "id": "java.lang.Class" + }, + { + "args": [], + "id": "java.lang.String" + } + ], + "paramVars": [ + "", + "" + ], + "retSelf": false, + "retType": { + "id": "T", + "kind": "typevar" + }, + "static": true, + "synchronized": false, + "throws": [], + "typeVarBounds": [ + [ + { + "args": [ + { + "id": "T", + "kind": "typevar" + } + ], + "id": "java.lang.Enum" + } + ] + ], + "typeVars": [ + "T" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "java.lang.Deprecated", + "values": [ + { + "kind": "string", + "name": "since", + "value": "18" + }, + { + "kind": "boolean", + "name": "forRemoval", + "value": true + } + ] + } + ], + "desc": "()V", + "final": true, + "k": "m", + "name": "finalize", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/io/ObjectInputStream;)V", + "final": false, + "k": "m", + "name": "readObject", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.io.IOException", + "java.lang.ClassNotFoundException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()V", + "final": false, + "k": "m", + "name": "readObjectNoData", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.io.ObjectStreamException" + ], + "varargs": false, + "vis": "public" + }, + { + "annotations": [], + "desc": "Ljava/lang/String;", + "enum": false, + "final": true, + "k": "f", + "name": "name", + "static": false, + "vis": "private" + }, + { + "annotations": [], + "desc": "I", + "enum": false, + "final": true, + "k": "f", + "name": "ordinal", + "static": false, + "vis": "private" + }, + { + "annotations": [ + { + "name": "jdk.internal.vm.annotation.Stable", + "values": [] + } + ], + "desc": "I", + "enum": false, + "final": false, + "k": "f", + "name": "hash", + "static": false, + "vis": "private" + } + ], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "super": "java.lang.Object", + "superType": { + "args": [], + "id": "java.lang.Object" + }, + "typeParameters": 1, + "typeVarBounds": [ + [ + { + "args": [ + { + "id": "E", + "kind": "typevar" + } + ], + "id": "java.lang.Enum" + } + ] + ], + "typeVars": [ + "E" + ] + }, + "java.lang.Object": { + "annotations": [], + "interfaces": [], + "kind": "class", + "members": [ + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "()V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "()Ljava/lang/Class;", + "final": true, + "k": "m", + "name": "getClass", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "kind": "wildcard" + } + ], + "id": "java.lang.Class" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "()I", + "final": false, + "k": "m", + "name": "hashCode", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/Object;)Z", + "final": false, + "k": "m", + "name": "equals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "()Ljava/lang/Object;", + "final": false, + "k": "m", + "name": "clone", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.CloneNotSupportedException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toString", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "()V", + "final": true, + "k": "m", + "name": "notify", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "()V", + "final": true, + "k": "m", + "name": "notifyAll", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()V", + "final": true, + "k": "m", + "name": "wait", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.InterruptedException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(J)V", + "final": true, + "k": "m", + "name": "wait", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.InterruptedException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(J)V", + "final": true, + "k": "m", + "name": "wait0", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.InterruptedException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(JI)V", + "final": true, + "k": "m", + "name": "wait", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.InterruptedException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "java.lang.Deprecated", + "values": [ + { + "kind": "string", + "name": "since", + "value": "9" + }, + { + "kind": "boolean", + "name": "forRemoval", + "value": true + } + ] + } + ], + "desc": "()V", + "final": false, + "k": "m", + "name": "finalize", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.Throwable" + ], + "varargs": false, + "vis": "public" + } + ], + "modifiers": [ + "public" + ], + "origin": "classpath", + "typeParameters": 0, + "typeVars": [] + }, + "java.lang.constant.Constable": { + "annotations": [], + "interfaces": [], + "kind": "interface", + "members": [ + { + "abstract": true, + "annotations": [], + "desc": "()Ljava/util/Optional;", + "final": false, + "k": "m", + "name": "describeConstable", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "extends": { + "args": [], + "id": "java.lang.constant.ConstantDesc" + }, + "kind": "wildcard" + } + ], + "id": "java.util.Optional" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + } + ], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "typeParameters": 0, + "typeVars": [] + }, + "java.lang.CharSequence": { + "annotations": [], + "interfaces": [], + "kind": "interface", + "members": [ + { + "abstract": true, + "annotations": [], + "desc": "()I", + "final": false, + "k": "m", + "name": "length", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": true, + "annotations": [], + "desc": "(I)C", + "final": false, + "k": "m", + "name": "charAt", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Z", + "final": false, + "k": "m", + "name": "isEmpty", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": true, + "annotations": [], + "desc": "(II)Ljava/lang/CharSequence;", + "final": false, + "k": "m", + "name": "subSequence", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": true, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toString", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/stream/IntStream;", + "final": false, + "k": "m", + "name": "chars", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/stream/IntStream;", + "final": false, + "k": "m", + "name": "codePoints", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)I", + "final": false, + "k": "m", + "name": "compare", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + } + ], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "typeParameters": 0, + "typeVars": [] + }, + "java.lang.String": { + "annotations": [], + "interfaceTypes": [ + { + "args": [], + "id": "java.io.Serializable" + }, + { + "args": [ + { + "args": [], + "id": "java.lang.String" + } + ], + "id": "java.lang.Comparable" + }, + { + "args": [], + "id": "java.lang.CharSequence" + }, + { + "args": [], + "id": "java.lang.constant.Constable" + }, + { + "args": [], + "id": "java.lang.constant.ConstantDesc" + } + ], + "interfaces": [ + "java.io.Serializable", + "java.lang.Comparable", + "java.lang.CharSequence", + "java.lang.constant.Constable", + "java.lang.constant.ConstantDesc" + ], + "kind": "class", + "members": [ + { + "abstract": false, + "annotations": [], + "desc": "()V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "(Ljava/lang/String;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([C)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([CII)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([CII)Ljava/lang/Void;", + "final": false, + "k": "m", + "name": "rangeCheck", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([III)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "java.lang.Deprecated", + "values": [ + { + "kind": "string", + "name": "since", + "value": "1.1" + } + ] + } + ], + "desc": "([BIII)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "java.lang.Deprecated", + "values": [ + { + "kind": "string", + "name": "since", + "value": "1.1" + } + ] + } + ], + "desc": "([BI)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIILjava/lang/String;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.io.UnsupportedEncodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIILjava/nio/charset/Charset;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/nio/charset/Charset;[BII)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIIZ)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "newStringUTF8NoRepl", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BLjava/nio/charset/Charset;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "newStringNoRepl", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [ + "java.nio.charset.CharacterCodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BLjava/nio/charset/Charset;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "newStringNoRepl1", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIZ)[B", + "final": false, + "k": "m", + "name": "safeTrim", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(IF)I", + "final": false, + "k": "m", + "name": "scale", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)Ljava/nio/charset/Charset;", + "final": false, + "k": "m", + "name": "lookupCharset", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [ + "java.io.UnsupportedEncodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/nio/charset/Charset;B[B)[B", + "final": false, + "k": "m", + "name": "encode", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/nio/charset/Charset;B[BZ)[B", + "final": false, + "k": "m", + "name": "encodeWithEncoder", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)[B", + "final": false, + "k": "m", + "name": "getBytesUTF8NoRepl", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([B)Z", + "final": false, + "k": "m", + "name": "isASCII", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;Ljava/nio/charset/Charset;)[B", + "final": false, + "k": "m", + "name": "getBytesNoRepl", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [ + "java.nio.charset.CharacterCodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;Ljava/nio/charset/Charset;)[B", + "final": false, + "k": "m", + "name": "getBytesNoRepl1", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(B[B)[B", + "final": false, + "k": "m", + "name": "encodeASCII", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BI)V", + "final": false, + "k": "m", + "name": "replaceNegatives", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(B[B)[B", + "final": false, + "k": "m", + "name": "encode8859_1", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(B[BZ)[B", + "final": false, + "k": "m", + "name": "encode8859_1", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BI[CII)I", + "final": false, + "k": "m", + "name": "decodeASCII", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Z", + "final": false, + "k": "m", + "name": "isNotContinuation", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(III)Z", + "final": false, + "k": "m", + "name": "isMalformed3", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)Z", + "final": false, + "k": "m", + "name": "isMalformed3_2", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(III)Z", + "final": false, + "k": "m", + "name": "isMalformed4", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)Z", + "final": false, + "k": "m", + "name": "isMalformed4_2", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Z", + "final": false, + "k": "m", + "name": "isMalformed4_3", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)C", + "final": false, + "k": "m", + "name": "decode2", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(III)C", + "final": false, + "k": "m", + "name": "decode3", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(IIII)I", + "final": false, + "k": "m", + "name": "decode4", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BII[BIZ)I", + "final": false, + "k": "m", + "name": "decodeUTF8_UTF16", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/nio/charset/CharsetDecoder;[C[BII)I", + "final": false, + "k": "m", + "name": "decodeWithDecoder", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [ + "java.nio.charset.CharacterCodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BI)I", + "final": false, + "k": "m", + "name": "malformed3", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BI)I", + "final": false, + "k": "m", + "name": "malformed4", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)V", + "final": false, + "k": "m", + "name": "throwMalformed", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([B)V", + "final": false, + "k": "m", + "name": "throwMalformed", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)V", + "final": false, + "k": "m", + "name": "throwUnmappable", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([B)V", + "final": false, + "k": "m", + "name": "throwUnmappable", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(B[BZ)[B", + "final": false, + "k": "m", + "name": "encodeUTF8", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BZ)[B", + "final": false, + "k": "m", + "name": "encodeUTF8_UTF16", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BLjava/lang/String;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.io.UnsupportedEncodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BLjava/nio/charset/Charset;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BII)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([B)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/StringBuffer;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/StringBuilder;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()I", + "final": false, + "k": "m", + "name": "length", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Z", + "final": false, + "k": "m", + "name": "isEmpty", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)C", + "final": false, + "k": "m", + "name": "charAt", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)I", + "final": false, + "k": "m", + "name": "codePointAt", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)I", + "final": false, + "k": "m", + "name": "codePointBefore", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)I", + "final": false, + "k": "m", + "name": "codePointCount", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)I", + "final": false, + "k": "m", + "name": "offsetByCodePoints", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II[CI)V", + "final": false, + "k": "m", + "name": "getChars", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "java.lang.Deprecated", + "values": [ + { + "kind": "string", + "name": "since", + "value": "1.1" + } + ] + } + ], + "desc": "(II[BI)V", + "final": false, + "k": "m", + "name": "getBytes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)[B", + "final": false, + "k": "m", + "name": "getBytes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.io.UnsupportedEncodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/nio/charset/Charset;)[B", + "final": false, + "k": "m", + "name": "getBytes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()[B", + "final": false, + "k": "m", + "name": "getBytes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/Object;)Z", + "final": false, + "k": "m", + "name": "equals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/StringBuffer;)Z", + "final": false, + "k": "m", + "name": "contentEquals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/AbstractStringBuilder;)Z", + "final": false, + "k": "m", + "name": "nonSyncContentEquals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/CharSequence;)Z", + "final": false, + "k": "m", + "name": "contentEquals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)Z", + "final": false, + "k": "m", + "name": "equalsIgnoreCase", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)I", + "final": false, + "k": "m", + "name": "compareTo", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)I", + "final": false, + "k": "m", + "name": "compareToIgnoreCase", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(ILjava/lang/String;II)Z", + "final": false, + "k": "m", + "name": "regionMatches", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(ZILjava/lang/String;II)Z", + "final": false, + "k": "m", + "name": "regionMatches", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;I)Z", + "final": false, + "k": "m", + "name": "startsWith", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)Z", + "final": false, + "k": "m", + "name": "startsWith", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)Z", + "final": false, + "k": "m", + "name": "endsWith", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()I", + "final": false, + "k": "m", + "name": "hashCode", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(III)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)I", + "final": false, + "k": "m", + "name": "lastIndexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)I", + "final": false, + "k": "m", + "name": "lastIndexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;I)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;II)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BBILjava/lang/String;I)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)I", + "final": false, + "k": "m", + "name": "lastIndexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;I)I", + "final": false, + "k": "m", + "name": "lastIndexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BBILjava/lang/String;I)I", + "final": false, + "k": "m", + "name": "lastIndexOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "substring", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "substring", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)Ljava/lang/CharSequence;", + "final": false, + "k": "m", + "name": "subSequence", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "concat", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(CC)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "replace", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)Z", + "final": false, + "k": "m", + "name": "matches", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/CharSequence;)Z", + "final": false, + "k": "m", + "name": "contains", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "replaceFirst", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "replaceAll", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "replace", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;I)[Ljava/lang/String;", + "final": false, + "k": "m", + "name": "split", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;I)[Ljava/lang/String;", + "final": false, + "k": "m", + "name": "splitWithDelimiters", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;IZ)[Ljava/lang/String;", + "final": false, + "k": "m", + "name": "split", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(CIZ)[Ljava/lang/String;", + "final": false, + "k": "m", + "name": "split", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)[Ljava/lang/String;", + "final": false, + "k": "m", + "name": "split", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/CharSequence;[Ljava/lang/CharSequence;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "join", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": true, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.ForceInline", + "values": [] + } + ], + "desc": "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;I)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "join", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/CharSequence;Ljava/lang/Iterable;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "join", + "paramTypes": [ + { + "args": [], + "id": "java.lang.CharSequence" + }, + { + "args": [ + { + "extends": { + "args": [], + "id": "java.lang.CharSequence" + }, + "kind": "wildcard" + } + ], + "id": "java.lang.Iterable" + } + ], + "paramVars": [ + "", + "" + ], + "retSelf": false, + "retType": { + "args": [], + "id": "java.lang.String" + }, + "static": true, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/util/Locale;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toLowerCase", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toLowerCase", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/util/Locale;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toUpperCase", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toUpperCase", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "trim", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "strip", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "stripLeading", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "stripTrailing", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Z", + "final": false, + "k": "m", + "name": "isBlank", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/stream/Stream;", + "final": false, + "k": "m", + "name": "lines", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "args": [], + "id": "java.lang.String" + } + ], + "id": "java.util.stream.Stream" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "indent", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()I", + "final": false, + "k": "m", + "name": "indexOfNonWhitespace", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()I", + "final": false, + "k": "m", + "name": "lastIndexOfNonWhitespace", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "stripIndent", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/util/List;)I", + "final": false, + "k": "m", + "name": "outdent", + "paramTypes": [ + { + "args": [ + { + "args": [], + "id": "java.lang.String" + } + ], + "id": "java.util.List" + } + ], + "paramVars": [ + "" + ], + "retSelf": false, + "retType": { + "id": "int" + }, + "static": true, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "translateEscapes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/util/function/Function;)Ljava/lang/Object;", + "final": false, + "k": "m", + "name": "transform", + "paramTypes": [ + { + "args": [ + { + "kind": "wildcard", + "super": { + "args": [], + "id": "java.lang.String" + } + }, + { + "extends": { + "id": "R", + "kind": "typevar" + }, + "kind": "wildcard" + } + ], + "id": "java.util.function.Function" + } + ], + "paramVars": [ + "" + ], + "retSelf": false, + "retType": { + "id": "R", + "kind": "typevar" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [ + [ + { + "args": [], + "id": "java.lang.Object" + } + ] + ], + "typeVars": [ + "R" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toString", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/stream/IntStream;", + "final": false, + "k": "m", + "name": "chars", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/stream/IntStream;", + "final": false, + "k": "m", + "name": "codePoints", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()[C", + "final": false, + "k": "m", + "name": "toCharArray", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "format", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": true, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/util/Locale;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "format", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": true, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([Ljava/lang/Object;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "formatted", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": true, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/Object;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([C)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([CII)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([CII)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "copyValueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([C)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "copyValueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Z)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(C)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(J)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(F)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(D)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "intern", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "repeat", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIII)V", + "final": false, + "k": "m", + "name": "repeatCopyRest", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIB)V", + "final": false, + "k": "m", + "name": "getBytes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIIBI)V", + "final": false, + "k": "m", + "name": "getBytes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([CIILjava/lang/Void;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/AbstractStringBuilder;Ljava/lang/Void;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BB)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()B", + "final": false, + "k": "m", + "name": "coder", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()[B", + "final": false, + "k": "m", + "name": "value", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Z", + "final": false, + "k": "m", + "name": "isLatin1", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)V", + "final": false, + "k": "m", + "name": "checkIndex", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)V", + "final": false, + "k": "m", + "name": "checkOffset", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(III)I", + "final": false, + "k": "m", + "name": "checkBoundsOffCount", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(III)V", + "final": false, + "k": "m", + "name": "checkBoundsBeginEnd", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOfCodePoint", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/Optional;", + "final": false, + "k": "m", + "name": "describeConstable", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "args": [], + "id": "java.lang.String" + } + ], + "id": "java.util.Optional" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/invoke/MethodHandles$Lookup;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "resolveConstantDesc", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "annotations": [ + { + "name": "jdk.internal.vm.annotation.Stable", + "values": [] + } + ], + "desc": "[B", + "enum": false, + "final": true, + "k": "f", + "name": "value", + "static": false, + "vis": "private" + }, + { + "annotations": [], + "desc": "B", + "enum": false, + "final": true, + "k": "f", + "name": "coder", + "static": false, + "vis": "private" + }, + { + "annotations": [], + "desc": "I", + "enum": false, + "final": false, + "k": "f", + "name": "hash", + "static": false, + "vis": "private" + }, + { + "annotations": [], + "desc": "Z", + "enum": false, + "final": false, + "k": "f", + "name": "hashIsZero", + "static": false, + "vis": "private" + }, + { + "annotations": [], + "constant": "-6849794470754667710", + "desc": "J", + "enum": false, + "final": true, + "k": "f", + "name": "serialVersionUID", + "static": true, + "vis": "private" + }, + { + "annotations": [], + "desc": "Z", + "enum": false, + "final": true, + "k": "f", + "name": "COMPACT_STRINGS", + "static": true, + "vis": "package" + }, + { + "annotations": [], + "desc": "[Ljava/io/ObjectStreamField;", + "enum": false, + "final": true, + "k": "f", + "name": "serialPersistentFields", + "static": true, + "vis": "private" + }, + { + "annotations": [], + "constant": "�", + "desc": "C", + "enum": false, + "final": true, + "k": "f", + "name": "REPL", + "static": true, + "vis": "private" + }, + { + "annotations": [], + "desc": "Ljava/util/Comparator;", + "enum": false, + "final": true, + "k": "f", + "name": "CASE_INSENSITIVE_ORDER", + "static": true, + "vis": "public" + }, + { + "annotations": [], + "constant": "0", + "desc": "B", + "enum": false, + "final": true, + "k": "f", + "name": "LATIN1", + "static": true, + "vis": "package" + }, + { + "annotations": [], + "constant": "1", + "desc": "B", + "enum": false, + "final": true, + "k": "f", + "name": "UTF16", + "static": true, + "vis": "package" + } + ], + "modifiers": [ + "public", + "final" + ], + "origin": "classpath", + "super": "java.lang.Object", + "superType": { + "args": [], + "id": "java.lang.Object" + }, + "typeParameters": 0, + "typeVarBounds": [], + "typeVars": [] + }, + "java.lang.constant.ConstantDesc": { + "annotations": [], + "interfaces": [], + "kind": "interface", + "members": [ + { + "abstract": true, + "annotations": [], + "desc": "(Ljava/lang/invoke/MethodHandles$Lookup;)Ljava/lang/Object;", + "final": false, + "k": "m", + "name": "resolveConstantDesc", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.ReflectiveOperationException" + ], + "varargs": false, + "vis": "public" + } + ], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "typeParameters": 0, + "typeVars": [] + } +} \ No newline at end of file diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Routes.java b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Routes.java new file mode 100644 index 00000000000..3fb288f5341 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Routes.java @@ -0,0 +1,28 @@ +package e; + +class Routes { + static final String ADMIN = Missing.PREFIX + "/admin"; + static final String LOCAL = "/local"; + + @interface Path { + String[] value(); + } + + enum Kind { A } + + @interface Tagged { + Kind value(); + } + + @Path(ADMIN) + void unknownConstant() { + } + + @Path(LOCAL) + void knownConstant() { + } + + @Tagged(Kind.A) + void enumConstant() { + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Routes.textproto b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Routes.textproto new file mode 100644 index 00000000000..2fcc913445f --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Routes.textproto @@ -0,0 +1,2021 @@ +tree { + kind: "program" + named: true + start_line: 1 + end_line: 29 + end_byte: 376 + children { + kind: "package_declaration" + named: true + start_line: 1 + end_line: 1 + end_col: 10 + end_byte: 10 + children { + kind: "package" + start_line: 1 + end_line: 1 + end_col: 7 + end_byte: 7 + text: "package" + } + children { + kind: "identifier" + named: true + start_line: 1 + start_col: 8 + end_line: 1 + end_col: 9 + start_byte: 8 + end_byte: 9 + text: "e" + } + children { + kind: ";" + start_line: 1 + start_col: 9 + end_line: 1 + end_col: 10 + start_byte: 9 + end_byte: 10 + text: ";" + } + } + children { + kind: "class_declaration" + named: true + start_line: 3 + end_line: 28 + end_col: 1 + start_byte: 12 + end_byte: 375 + children { + kind: "class" + start_line: 3 + end_line: 3 + end_col: 5 + start_byte: 12 + end_byte: 17 + text: "class" + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 3 + start_col: 6 + end_line: 3 + end_col: 12 + start_byte: 18 + end_byte: 24 + text: "Routes" + decls: "e.Routes" + } + children { + kind: "class_body" + named: true + field: "body" + start_line: 3 + start_col: 13 + end_line: 28 + end_col: 1 + start_byte: 25 + end_byte: 375 + children { + kind: "{" + start_line: 3 + start_col: 13 + end_line: 3 + end_col: 14 + start_byte: 25 + end_byte: 26 + text: "{" + } + children { + kind: "field_declaration" + named: true + start_line: 4 + start_col: 2 + end_line: 4 + end_col: 56 + start_byte: 29 + end_byte: 83 + children { + kind: "modifiers" + named: true + start_line: 4 + start_col: 2 + end_line: 4 + end_col: 14 + start_byte: 29 + end_byte: 41 + children { + kind: "static" + start_line: 4 + start_col: 2 + end_line: 4 + end_col: 8 + start_byte: 29 + end_byte: 35 + text: "static" + } + children { + kind: "final" + start_line: 4 + start_col: 9 + end_line: 4 + end_col: 14 + start_byte: 36 + end_byte: 41 + text: "final" + } + } + children { + kind: "type_identifier" + named: true + field: "type" + start_line: 4 + start_col: 15 + end_line: 4 + end_col: 21 + start_byte: 42 + end_byte: 48 + text: "String" + refs { + access: "ref" + outcome: "bound" + target: "java.lang.String" + } + } + children { + kind: "variable_declarator" + named: true + field: "declarator" + start_line: 4 + start_col: 22 + end_line: 4 + end_col: 55 + start_byte: 49 + end_byte: 82 + children { + kind: "identifier" + named: true + field: "name" + start_line: 4 + start_col: 22 + end_line: 4 + end_col: 27 + start_byte: 49 + end_byte: 54 + text: "ADMIN" + decls: "e.Routes#ADMIN" + } + children { + kind: "=" + start_line: 4 + start_col: 28 + end_line: 4 + end_col: 29 + start_byte: 55 + end_byte: 56 + text: "=" + } + children { + kind: "binary_expression" + named: true + field: "value" + start_line: 4 + start_col: 30 + end_line: 4 + end_col: 55 + start_byte: 57 + end_byte: 82 + children { + kind: "field_access" + named: true + field: "left" + start_line: 4 + start_col: 30 + end_line: 4 + end_col: 44 + start_byte: 57 + end_byte: 71 + children { + kind: "identifier" + named: true + field: "object" + start_line: 4 + start_col: 30 + end_line: 4 + end_col: 37 + start_byte: 57 + end_byte: 64 + text: "Missing" + refs { + access: "r" + outcome: "unresolved" + reason: "not_found" + } + } + children { + kind: "." + start_line: 4 + start_col: 37 + end_line: 4 + end_col: 38 + start_byte: 64 + end_byte: 65 + text: "." + } + children { + kind: "identifier" + named: true + field: "field" + start_line: 4 + start_col: 38 + end_line: 4 + end_col: 44 + start_byte: 65 + end_byte: 71 + text: "PREFIX" + } + } + children { + kind: "+" + field: "operator" + start_line: 4 + start_col: 45 + end_line: 4 + end_col: 46 + start_byte: 72 + end_byte: 73 + text: "+" + } + children { + kind: "string_literal" + named: true + field: "right" + start_line: 4 + start_col: 47 + end_line: 4 + end_col: 55 + start_byte: 74 + end_byte: 82 + text: "\"/admin\"" + children { + kind: "\"" + start_line: 4 + start_col: 47 + end_line: 4 + end_col: 48 + start_byte: 74 + end_byte: 75 + text: "\"" + } + children { + kind: "string_fragment" + named: true + start_line: 4 + start_col: 48 + end_line: 4 + end_col: 54 + start_byte: 75 + end_byte: 81 + text: "/admin" + } + children { + kind: "\"" + start_line: 4 + start_col: 54 + end_line: 4 + end_col: 55 + start_byte: 81 + end_byte: 82 + text: "\"" + } + } + } + } + children { + kind: ";" + start_line: 4 + start_col: 55 + end_line: 4 + end_col: 56 + start_byte: 82 + end_byte: 83 + text: ";" + } + } + children { + kind: "field_declaration" + named: true + start_line: 5 + start_col: 2 + end_line: 5 + end_col: 39 + start_byte: 86 + end_byte: 123 + children { + kind: "modifiers" + named: true + start_line: 5 + start_col: 2 + end_line: 5 + end_col: 14 + start_byte: 86 + end_byte: 98 + children { + kind: "static" + start_line: 5 + start_col: 2 + end_line: 5 + end_col: 8 + start_byte: 86 + end_byte: 92 + text: "static" + } + children { + kind: "final" + start_line: 5 + start_col: 9 + end_line: 5 + end_col: 14 + start_byte: 93 + end_byte: 98 + text: "final" + } + } + children { + kind: "type_identifier" + named: true + field: "type" + start_line: 5 + start_col: 15 + end_line: 5 + end_col: 21 + start_byte: 99 + end_byte: 105 + text: "String" + refs { + access: "ref" + outcome: "bound" + target: "java.lang.String" + } + } + children { + kind: "variable_declarator" + named: true + field: "declarator" + start_line: 5 + start_col: 22 + end_line: 5 + end_col: 38 + start_byte: 106 + end_byte: 122 + children { + kind: "identifier" + named: true + field: "name" + start_line: 5 + start_col: 22 + end_line: 5 + end_col: 27 + start_byte: 106 + end_byte: 111 + text: "LOCAL" + decls: "e.Routes#LOCAL" + } + children { + kind: "=" + start_line: 5 + start_col: 28 + end_line: 5 + end_col: 29 + start_byte: 112 + end_byte: 113 + text: "=" + } + children { + kind: "string_literal" + named: true + field: "value" + start_line: 5 + start_col: 30 + end_line: 5 + end_col: 38 + start_byte: 114 + end_byte: 122 + text: "\"/local\"" + children { + kind: "\"" + start_line: 5 + start_col: 30 + end_line: 5 + end_col: 31 + start_byte: 114 + end_byte: 115 + text: "\"" + } + children { + kind: "string_fragment" + named: true + start_line: 5 + start_col: 31 + end_line: 5 + end_col: 37 + start_byte: 115 + end_byte: 121 + text: "/local" + } + children { + kind: "\"" + start_line: 5 + start_col: 37 + end_line: 5 + end_col: 38 + start_byte: 121 + end_byte: 122 + text: "\"" + } + } + } + children { + kind: ";" + start_line: 5 + start_col: 38 + end_line: 5 + end_col: 39 + start_byte: 122 + end_byte: 123 + text: ";" + } + } + children { + kind: "annotation_type_declaration" + named: true + start_line: 7 + start_col: 2 + end_line: 9 + end_col: 3 + start_byte: 127 + end_byte: 170 + children { + kind: "@interface" + start_line: 7 + start_col: 2 + end_line: 7 + end_col: 12 + start_byte: 127 + end_byte: 137 + text: "@interface" + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 7 + start_col: 13 + end_line: 7 + end_col: 17 + start_byte: 138 + end_byte: 142 + text: "Path" + decls: "e.Routes$Path" + } + children { + kind: "annotation_type_body" + named: true + field: "body" + start_line: 7 + start_col: 18 + end_line: 9 + end_col: 3 + start_byte: 143 + end_byte: 170 + children { + kind: "{" + start_line: 7 + start_col: 18 + end_line: 7 + end_col: 19 + start_byte: 143 + end_byte: 144 + text: "{" + } + children { + kind: "annotation_type_element_declaration" + named: true + start_line: 8 + start_col: 4 + end_line: 8 + end_col: 21 + start_byte: 149 + end_byte: 166 + children { + kind: "array_type" + named: true + field: "type" + start_line: 8 + start_col: 4 + end_line: 8 + end_col: 12 + start_byte: 149 + end_byte: 157 + children { + kind: "type_identifier" + named: true + field: "element" + start_line: 8 + start_col: 4 + end_line: 8 + end_col: 10 + start_byte: 149 + end_byte: 155 + text: "String" + refs { + access: "ref" + outcome: "bound" + target: "java.lang.String" + } + } + children { + kind: "dimensions" + named: true + field: "dimensions" + start_line: 8 + start_col: 10 + end_line: 8 + end_col: 12 + start_byte: 155 + end_byte: 157 + children { + kind: "[" + start_line: 8 + start_col: 10 + end_line: 8 + end_col: 11 + start_byte: 155 + end_byte: 156 + text: "[" + } + children { + kind: "]" + start_line: 8 + start_col: 11 + end_line: 8 + end_col: 12 + start_byte: 156 + end_byte: 157 + text: "]" + } + } + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 8 + start_col: 13 + end_line: 8 + end_col: 18 + start_byte: 158 + end_byte: 163 + text: "value" + decls: "e.Routes$Path#value()" + } + children { + kind: "(" + start_line: 8 + start_col: 18 + end_line: 8 + end_col: 19 + start_byte: 163 + end_byte: 164 + text: "(" + } + children { + kind: ")" + start_line: 8 + start_col: 19 + end_line: 8 + end_col: 20 + start_byte: 164 + end_byte: 165 + text: ")" + } + children { + kind: ";" + start_line: 8 + start_col: 20 + end_line: 8 + end_col: 21 + start_byte: 165 + end_byte: 166 + text: ";" + } + } + children { + kind: "}" + start_line: 9 + start_col: 2 + end_line: 9 + end_col: 3 + start_byte: 169 + end_byte: 170 + text: "}" + } + } + } + children { + kind: "enum_declaration" + named: true + start_line: 11 + start_col: 2 + end_line: 11 + end_col: 17 + start_byte: 174 + end_byte: 189 + children { + kind: "enum" + start_line: 11 + start_col: 2 + end_line: 11 + end_col: 6 + start_byte: 174 + end_byte: 178 + text: "enum" + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 11 + start_col: 7 + end_line: 11 + end_col: 11 + start_byte: 179 + end_byte: 183 + text: "Kind" + decls: "e.Routes$Kind" + } + children { + kind: "enum_body" + named: true + field: "body" + start_line: 11 + start_col: 12 + end_line: 11 + end_col: 17 + start_byte: 184 + end_byte: 189 + children { + kind: "{" + start_line: 11 + start_col: 12 + end_line: 11 + end_col: 13 + start_byte: 184 + end_byte: 185 + text: "{" + } + children { + kind: "enum_constant" + named: true + start_line: 11 + start_col: 14 + end_line: 11 + end_col: 15 + start_byte: 186 + end_byte: 187 + children { + kind: "identifier" + named: true + field: "name" + start_line: 11 + start_col: 14 + end_line: 11 + end_col: 15 + start_byte: 186 + end_byte: 187 + text: "A" + decls: "e.Routes$Kind#A" + } + } + children { + kind: "}" + start_line: 11 + start_col: 16 + end_line: 11 + end_col: 17 + start_byte: 188 + end_byte: 189 + text: "}" + } + } + } + children { + kind: "annotation_type_declaration" + named: true + start_line: 13 + start_col: 2 + end_line: 15 + end_col: 3 + start_byte: 193 + end_byte: 234 + children { + kind: "@interface" + start_line: 13 + start_col: 2 + end_line: 13 + end_col: 12 + start_byte: 193 + end_byte: 203 + text: "@interface" + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 13 + start_col: 13 + end_line: 13 + end_col: 19 + start_byte: 204 + end_byte: 210 + text: "Tagged" + decls: "e.Routes$Tagged" + } + children { + kind: "annotation_type_body" + named: true + field: "body" + start_line: 13 + start_col: 20 + end_line: 15 + end_col: 3 + start_byte: 211 + end_byte: 234 + children { + kind: "{" + start_line: 13 + start_col: 20 + end_line: 13 + end_col: 21 + start_byte: 211 + end_byte: 212 + text: "{" + } + children { + kind: "annotation_type_element_declaration" + named: true + start_line: 14 + start_col: 4 + end_line: 14 + end_col: 17 + start_byte: 217 + end_byte: 230 + children { + kind: "type_identifier" + named: true + field: "type" + start_line: 14 + start_col: 4 + end_line: 14 + end_col: 8 + start_byte: 217 + end_byte: 221 + text: "Kind" + refs { + access: "ref" + outcome: "bound" + target: "e.Routes$Kind" + } + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 14 + start_col: 9 + end_line: 14 + end_col: 14 + start_byte: 222 + end_byte: 227 + text: "value" + decls: "e.Routes$Tagged#value()" + } + children { + kind: "(" + start_line: 14 + start_col: 14 + end_line: 14 + end_col: 15 + start_byte: 227 + end_byte: 228 + text: "(" + } + children { + kind: ")" + start_line: 14 + start_col: 15 + end_line: 14 + end_col: 16 + start_byte: 228 + end_byte: 229 + text: ")" + } + children { + kind: ";" + start_line: 14 + start_col: 16 + end_line: 14 + end_col: 17 + start_byte: 229 + end_byte: 230 + text: ";" + } + } + children { + kind: "}" + start_line: 15 + start_col: 2 + end_line: 15 + end_col: 3 + start_byte: 233 + end_byte: 234 + text: "}" + } + } + } + children { + kind: "method_declaration" + named: true + start_line: 17 + start_col: 2 + end_line: 19 + end_col: 3 + start_byte: 238 + end_byte: 281 + children { + kind: "modifiers" + named: true + start_line: 17 + start_col: 2 + end_line: 17 + end_col: 14 + start_byte: 238 + end_byte: 250 + children { + kind: "annotation" + named: true + start_line: 17 + start_col: 2 + end_line: 17 + end_col: 14 + start_byte: 238 + end_byte: 250 + children { + kind: "@" + start_line: 17 + start_col: 2 + end_line: 17 + end_col: 3 + start_byte: 238 + end_byte: 239 + text: "@" + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 17 + start_col: 3 + end_line: 17 + end_col: 7 + start_byte: 239 + end_byte: 243 + text: "Path" + refs { + access: "ref" + outcome: "bound" + target: "e.Routes$Path" + } + } + children { + kind: "annotation_argument_list" + named: true + field: "arguments" + start_line: 17 + start_col: 7 + end_line: 17 + end_col: 14 + start_byte: 243 + end_byte: 250 + children { + kind: "(" + start_line: 17 + start_col: 7 + end_line: 17 + end_col: 8 + start_byte: 243 + end_byte: 244 + text: "(" + } + children { + kind: "identifier" + named: true + start_line: 17 + start_col: 8 + end_line: 17 + end_col: 13 + start_byte: 244 + end_byte: 249 + text: "ADMIN" + refs { + access: "r" + outcome: "bound" + target: "e.Routes#ADMIN" + } + } + children { + kind: ")" + start_line: 17 + start_col: 13 + end_line: 17 + end_col: 14 + start_byte: 249 + end_byte: 250 + text: ")" + } + } + } + } + children { + kind: "void_type" + named: true + field: "type" + start_line: 18 + start_col: 2 + end_line: 18 + end_col: 6 + start_byte: 253 + end_byte: 257 + text: "void" + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 18 + start_col: 7 + end_line: 18 + end_col: 22 + start_byte: 258 + end_byte: 273 + text: "unknownConstant" + decls: "e.Routes#unknownConstant()" + } + children { + kind: "formal_parameters" + named: true + field: "parameters" + start_line: 18 + start_col: 22 + end_line: 18 + end_col: 24 + start_byte: 273 + end_byte: 275 + children { + kind: "(" + start_line: 18 + start_col: 22 + end_line: 18 + end_col: 23 + start_byte: 273 + end_byte: 274 + text: "(" + } + children { + kind: ")" + start_line: 18 + start_col: 23 + end_line: 18 + end_col: 24 + start_byte: 274 + end_byte: 275 + text: ")" + } + } + children { + kind: "block" + named: true + field: "body" + start_line: 18 + start_col: 25 + end_line: 19 + end_col: 3 + start_byte: 276 + end_byte: 281 + children { + kind: "{" + start_line: 18 + start_col: 25 + end_line: 18 + end_col: 26 + start_byte: 276 + end_byte: 277 + text: "{" + } + children { + kind: "}" + start_line: 19 + start_col: 2 + end_line: 19 + end_col: 3 + start_byte: 280 + end_byte: 281 + text: "}" + } + } + } + children { + kind: "method_declaration" + named: true + start_line: 21 + start_col: 2 + end_line: 23 + end_col: 3 + start_byte: 285 + end_byte: 326 + children { + kind: "modifiers" + named: true + start_line: 21 + start_col: 2 + end_line: 21 + end_col: 14 + start_byte: 285 + end_byte: 297 + children { + kind: "annotation" + named: true + start_line: 21 + start_col: 2 + end_line: 21 + end_col: 14 + start_byte: 285 + end_byte: 297 + children { + kind: "@" + start_line: 21 + start_col: 2 + end_line: 21 + end_col: 3 + start_byte: 285 + end_byte: 286 + text: "@" + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 21 + start_col: 3 + end_line: 21 + end_col: 7 + start_byte: 286 + end_byte: 290 + text: "Path" + refs { + access: "ref" + outcome: "bound" + target: "e.Routes$Path" + } + } + children { + kind: "annotation_argument_list" + named: true + field: "arguments" + start_line: 21 + start_col: 7 + end_line: 21 + end_col: 14 + start_byte: 290 + end_byte: 297 + children { + kind: "(" + start_line: 21 + start_col: 7 + end_line: 21 + end_col: 8 + start_byte: 290 + end_byte: 291 + text: "(" + } + children { + kind: "identifier" + named: true + start_line: 21 + start_col: 8 + end_line: 21 + end_col: 13 + start_byte: 291 + end_byte: 296 + text: "LOCAL" + refs { + access: "r" + outcome: "bound" + target: "e.Routes#LOCAL" + facts { + key: "constant" + value { + text: "/local" + } + } + } + } + children { + kind: ")" + start_line: 21 + start_col: 13 + end_line: 21 + end_col: 14 + start_byte: 296 + end_byte: 297 + text: ")" + } + } + } + } + children { + kind: "void_type" + named: true + field: "type" + start_line: 22 + start_col: 2 + end_line: 22 + end_col: 6 + start_byte: 300 + end_byte: 304 + text: "void" + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 22 + start_col: 7 + end_line: 22 + end_col: 20 + start_byte: 305 + end_byte: 318 + text: "knownConstant" + decls: "e.Routes#knownConstant()" + } + children { + kind: "formal_parameters" + named: true + field: "parameters" + start_line: 22 + start_col: 20 + end_line: 22 + end_col: 22 + start_byte: 318 + end_byte: 320 + children { + kind: "(" + start_line: 22 + start_col: 20 + end_line: 22 + end_col: 21 + start_byte: 318 + end_byte: 319 + text: "(" + } + children { + kind: ")" + start_line: 22 + start_col: 21 + end_line: 22 + end_col: 22 + start_byte: 319 + end_byte: 320 + text: ")" + } + } + children { + kind: "block" + named: true + field: "body" + start_line: 22 + start_col: 23 + end_line: 23 + end_col: 3 + start_byte: 321 + end_byte: 326 + children { + kind: "{" + start_line: 22 + start_col: 23 + end_line: 22 + end_col: 24 + start_byte: 321 + end_byte: 322 + text: "{" + } + children { + kind: "}" + start_line: 23 + start_col: 2 + end_line: 23 + end_col: 3 + start_byte: 325 + end_byte: 326 + text: "}" + } + } + } + children { + kind: "method_declaration" + named: true + start_line: 25 + start_col: 2 + end_line: 27 + end_col: 3 + start_byte: 330 + end_byte: 373 + children { + kind: "modifiers" + named: true + start_line: 25 + start_col: 2 + end_line: 25 + end_col: 17 + start_byte: 330 + end_byte: 345 + children { + kind: "annotation" + named: true + start_line: 25 + start_col: 2 + end_line: 25 + end_col: 17 + start_byte: 330 + end_byte: 345 + children { + kind: "@" + start_line: 25 + start_col: 2 + end_line: 25 + end_col: 3 + start_byte: 330 + end_byte: 331 + text: "@" + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 25 + start_col: 3 + end_line: 25 + end_col: 9 + start_byte: 331 + end_byte: 337 + text: "Tagged" + refs { + access: "ref" + outcome: "bound" + target: "e.Routes$Tagged" + } + } + children { + kind: "annotation_argument_list" + named: true + field: "arguments" + start_line: 25 + start_col: 9 + end_line: 25 + end_col: 17 + start_byte: 337 + end_byte: 345 + children { + kind: "(" + start_line: 25 + start_col: 9 + end_line: 25 + end_col: 10 + start_byte: 337 + end_byte: 338 + text: "(" + } + children { + kind: "field_access" + named: true + start_line: 25 + start_col: 10 + end_line: 25 + end_col: 16 + start_byte: 338 + end_byte: 344 + children { + kind: "identifier" + named: true + field: "object" + start_line: 25 + start_col: 10 + end_line: 25 + end_col: 14 + start_byte: 338 + end_byte: 342 + text: "Kind" + refs { + access: "ref" + outcome: "bound" + target: "e.Routes$Kind" + } + } + children { + kind: "." + start_line: 25 + start_col: 14 + end_line: 25 + end_col: 15 + start_byte: 342 + end_byte: 343 + text: "." + } + children { + kind: "identifier" + named: true + field: "field" + start_line: 25 + start_col: 15 + end_line: 25 + end_col: 16 + start_byte: 343 + end_byte: 344 + text: "A" + refs { + access: "r" + outcome: "bound" + target: "e.Routes$Kind#A" + } + } + } + children { + kind: ")" + start_line: 25 + start_col: 16 + end_line: 25 + end_col: 17 + start_byte: 344 + end_byte: 345 + text: ")" + } + } + } + } + children { + kind: "void_type" + named: true + field: "type" + start_line: 26 + start_col: 2 + end_line: 26 + end_col: 6 + start_byte: 348 + end_byte: 352 + text: "void" + } + children { + kind: "identifier" + named: true + field: "name" + start_line: 26 + start_col: 7 + end_line: 26 + end_col: 19 + start_byte: 353 + end_byte: 365 + text: "enumConstant" + decls: "e.Routes#enumConstant()" + } + children { + kind: "formal_parameters" + named: true + field: "parameters" + start_line: 26 + start_col: 19 + end_line: 26 + end_col: 21 + start_byte: 365 + end_byte: 367 + children { + kind: "(" + start_line: 26 + start_col: 19 + end_line: 26 + end_col: 20 + start_byte: 365 + end_byte: 366 + text: "(" + } + children { + kind: ")" + start_line: 26 + start_col: 20 + end_line: 26 + end_col: 21 + start_byte: 366 + end_byte: 367 + text: ")" + } + } + children { + kind: "block" + named: true + field: "body" + start_line: 26 + start_col: 22 + end_line: 27 + end_col: 3 + start_byte: 368 + end_byte: 373 + children { + kind: "{" + start_line: 26 + start_col: 22 + end_line: 26 + end_col: 23 + start_byte: 368 + end_byte: 369 + text: "{" + } + children { + kind: "}" + start_line: 27 + start_col: 2 + end_line: 27 + end_col: 3 + start_byte: 372 + end_byte: 373 + text: "}" + } + } + } + children { + kind: "}" + start_line: 28 + end_line: 28 + end_col: 1 + start_byte: 374 + end_byte: 375 + text: "}" + } + } + } +} +path: "e/Routes.java" +semantic: true +symbols { + id: "e.Routes#()" + kind: "constructor" + name: "Routes" + owner: "e.Routes" + facts { + key: "implicit" + value { + flag: true + } + } +} +symbols { + id: "e.Routes$Kind#()" + kind: "constructor" + name: "Kind" + owner: "e.Routes$Kind" + facts { + key: "implicit" + value { + flag: true + } + } +} +symbols { + id: "e.Routes$Kind#valueOf(java.lang.String)" + kind: "method" + name: "valueOf" + owner: "e.Routes$Kind" + facts { + key: "implicit" + value { + flag: true + } + } +} +symbols { + id: "e.Routes$Kind#values()" + kind: "method" + name: "values" + owner: "e.Routes$Kind" + facts { + key: "implicit" + value { + flag: true + } + } +} +symbols { + id: "e.Routes" + kind: "type" + name: "Routes" + place { + start_byte: 18 + end_byte: 24 + line: 3 + column: 6 + } +} +symbols { + id: "e.Routes#ADMIN" + kind: "field" + name: "ADMIN" + owner: "e.Routes" + place { + start_byte: 49 + end_byte: 54 + line: 4 + column: 22 + } + facts { + key: "type" + value { + type { + kind: "named" + id: "java.lang.String" + origin: "jdk" + source: "declared" + } + } + } +} +symbols { + id: "e.Routes#LOCAL" + kind: "constant" + name: "LOCAL" + owner: "e.Routes" + place { + start_byte: 106 + end_byte: 111 + line: 5 + column: 22 + } + facts { + key: "constant" + value { + text: "/local" + } + } +} +symbols { + id: "e.Routes$Path" + kind: "type" + name: "Path" + owner: "e.Routes" + place { + start_byte: 138 + end_byte: 142 + line: 7 + column: 13 + } +} +symbols { + id: "e.Routes$Path#value()" + kind: "method" + name: "value" + owner: "e.Routes$Path" + place { + start_byte: 158 + end_byte: 163 + line: 8 + column: 13 + } +} +symbols { + id: "e.Routes$Kind" + kind: "type" + name: "Kind" + owner: "e.Routes" + place { + start_byte: 179 + end_byte: 183 + line: 11 + column: 7 + } +} +symbols { + id: "e.Routes$Kind#A" + kind: "enum_member" + name: "A" + owner: "e.Routes$Kind" + place { + start_byte: 186 + end_byte: 187 + line: 11 + column: 14 + } +} +symbols { + id: "e.Routes$Tagged" + kind: "type" + name: "Tagged" + owner: "e.Routes" + place { + start_byte: 204 + end_byte: 210 + line: 13 + column: 13 + } +} +symbols { + id: "e.Routes$Tagged#value()" + kind: "method" + name: "value" + owner: "e.Routes$Tagged" + place { + start_byte: 222 + end_byte: 227 + line: 14 + column: 9 + } +} +symbols { + id: "e.Routes#unknownConstant()" + kind: "method" + name: "unknownConstant" + owner: "e.Routes" + place { + start_byte: 258 + end_byte: 273 + line: 18 + column: 7 + } + facts { + key: "returns" + value { + type { + kind: "named" + id: "void" + source: "declared" + } + } + } +} +symbols { + id: "e.Routes#knownConstant()" + kind: "method" + name: "knownConstant" + owner: "e.Routes" + place { + start_byte: 305 + end_byte: 318 + line: 22 + column: 7 + } + facts { + key: "returns" + value { + type { + kind: "named" + id: "void" + source: "declared" + } + } + } +} +symbols { + id: "e.Routes#enumConstant()" + kind: "method" + name: "enumConstant" + owner: "e.Routes" + place { + start_byte: 353 + end_byte: 365 + line: 26 + column: 7 + } + facts { + key: "returns" + value { + type { + kind: "named" + id: "void" + source: "declared" + } + } + } +} +facts { + key: "e.Routes" + value { + kind: "class" + tier: "IN_PROJECT" + parent: "e/Routes.java::" + props { + name: "simple_name" + values: "Routes" + } + props { + name: "type_fqn" + values: "e.Routes" + } + } +} +facts { + key: "e.Routes#ADMIN" + value { + kind: "field" + tier: "IN_PROJECT" + parent: "e.Routes" + props { + name: "member_name" + values: "ADMIN" + } + props { + name: "modifiers" + values: "static,final" + } + props { + name: "simple_name" + values: "ADMIN" + } + props { + name: "type_fqn" + values: "e.Routes" + } + type: "java.lang.String" + } +} +facts { + key: "e.Routes#LOCAL" + value { + kind: "field" + tier: "IN_PROJECT" + parent: "e.Routes" + props { + name: "member_name" + values: "LOCAL" + } + props { + name: "modifiers" + values: "static,final" + } + props { + name: "simple_name" + values: "LOCAL" + } + props { + name: "type_fqn" + values: "e.Routes" + } + type: "java.lang.String" + } +} +facts { + key: "e.Routes#enumConstant()" + value { + kind: "method" + tier: "IN_PROJECT" + parent: "e.Routes" + props { + name: "annotation_values" + values: "[{\"elements\":[{\"name\":\"value\",\"value\":{\"constant\":\"A\",\"kind\":\"enum\",\"type\":\"e.Routes$Kind\"}}],\"id\":\"e.Routes$Tagged\"}]" + } + props { + name: "member_name" + values: "enumConstant" + } + props { + name: "param_types" + values: "" + } + props { + name: "simple_name" + values: "enumConstant" + } + props { + name: "type_fqn" + values: "e.Routes" + } + returns: "void" + annotations: "e.Routes$Tagged" + } +} +facts { + key: "e.Routes#knownConstant()" + value { + kind: "method" + tier: "IN_PROJECT" + parent: "e.Routes" + props { + name: "annotation_values" + values: "[{\"elements\":[{\"name\":\"value\",\"value\":{\"kind\":\"string\",\"value\":\"/local\"}}],\"id\":\"e.Routes$Path\"}]" + } + props { + name: "member_name" + values: "knownConstant" + } + props { + name: "param_types" + values: "" + } + props { + name: "simple_name" + values: "knownConstant" + } + props { + name: "type_fqn" + values: "e.Routes" + } + returns: "void" + annotations: "e.Routes$Path" + } +} +facts { + key: "e.Routes#unknownConstant()" + value { + kind: "method" + tier: "IN_PROJECT" + parent: "e.Routes" + props { + name: "annotation_values" + values: "[{\"elements\":[{\"name\":\"value\",\"value\":{\"kind\":\"expression\",\"text\":\"ADMIN\"}}],\"id\":\"e.Routes$Path\"}]" + } + props { + name: "member_name" + values: "unknownConstant" + } + props { + name: "param_types" + values: "" + } + props { + name: "simple_name" + values: "unknownConstant" + } + props { + name: "type_fqn" + values: "e.Routes" + } + returns: "void" + annotations: "e.Routes$Path" + } +} +facts { + key: "e.Routes$Kind" + value { + kind: "enum" + tier: "IN_PROJECT" + parent: "e.Routes" + props { + name: "simple_name" + values: "Kind" + } + props { + name: "type_fqn" + values: "e.Routes$Kind" + } + } +} +facts { + key: "e.Routes$Kind#()" + value { + kind: "method" + tier: "IN_PROJECT" + parent: "e.Routes$Kind" + props { + name: "member_name" + values: "Kind" + } + props { + name: "param_types" + values: "" + } + props { + name: "type_fqn" + values: "e.Routes$Kind" + } + } +} +facts { + key: "e.Routes$Kind#A" + value { + kind: "field" + tier: "IN_PROJECT" + parent: "e.Routes$Kind" + props { + name: "member_name" + values: "A" + } + props { + name: "simple_name" + values: "A" + } + props { + name: "type_fqn" + values: "e.Routes$Kind" + } + type: "e.Routes$Kind" + } +} +facts { + key: "e.Routes$Path" + value { + kind: "annotation" + tier: "IN_PROJECT" + parent: "e.Routes" + props { + name: "simple_name" + values: "Path" + } + props { + name: "type_fqn" + values: "e.Routes$Path" + } + } +} +facts { + key: "e.Routes$Path#value()" + value { + kind: "method" + tier: "IN_PROJECT" + parent: "e.Routes$Path" + props { + name: "member_name" + values: "value" + } + props { + name: "param_types" + values: "" + } + props { + name: "simple_name" + values: "value" + } + props { + name: "type_fqn" + values: "e.Routes$Path" + } + returns: "java.lang.String[]" + } +} +facts { + key: "e.Routes$Tagged" + value { + kind: "annotation" + tier: "IN_PROJECT" + parent: "e.Routes" + props { + name: "simple_name" + values: "Tagged" + } + props { + name: "type_fqn" + values: "e.Routes$Tagged" + } + } +} +facts { + key: "e.Routes$Tagged#value()" + value { + kind: "method" + tier: "IN_PROJECT" + parent: "e.Routes$Tagged" + props { + name: "member_name" + values: "value" + } + props { + name: "param_types" + values: "" + } + props { + name: "simple_name" + values: "value" + } + props { + name: "type_fqn" + values: "e.Routes$Tagged" + } + returns: "e.Routes$Kind" + } +} +facts { + key: "java.lang.String" + value { + kind: "class" + tier: "EXTERNAL_KNOWN" + } +} diff --git a/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Routes.types.json b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Routes.types.json new file mode 100644 index 00000000000..c9c10fa9ff8 --- /dev/null +++ b/java-frontend-semsitter/src/test/resources/org/sonar/java/semsitter/translator/Routes.types.json @@ -0,0 +1,4084 @@ +{ + "e.Routes": { + "annotations": [], + "id": "e.Routes", + "interfaces": [], + "kind": "class", + "members": [ + { + "annotations": [], + "facts": { + "kind": "field", + "parent": "e.Routes", + "props": { + "member_name": [ + "ADMIN" + ], + "modifiers": [ + "static,final" + ], + "simple_name": [ + "ADMIN" + ], + "type_fqn": [ + "e.Routes" + ] + }, + "tier": "IN_PROJECT", + "type": [ + "java.lang.String" + ] + }, + "id": "e.Routes#ADMIN" + }, + { + "annotations": [], + "constant": "/local", + "facts": { + "kind": "field", + "parent": "e.Routes", + "props": { + "member_name": [ + "LOCAL" + ], + "modifiers": [ + "static,final" + ], + "simple_name": [ + "LOCAL" + ], + "type_fqn": [ + "e.Routes" + ] + }, + "tier": "IN_PROJECT", + "type": [ + "java.lang.String" + ] + }, + "id": "e.Routes#LOCAL" + }, + { + "annotations": [ + { + "name": "e.Routes$Tagged", + "values": [ + { + "const": "A", + "kind": "enum", + "name": "value", + "type": "e.Routes$Kind" + } + ] + } + ], + "facts": { + "annotations": [ + "e.Routes$Tagged" + ], + "kind": "method", + "parent": "e.Routes", + "props": { + "annotation_values": [ + "[{\"elements\":[{\"name\":\"value\",\"value\":{\"constant\":\"A\",\"kind\":\"enum\",\"type\":\"e.Routes$Kind\"}}],\"id\":\"e.Routes$Tagged\"}]" + ], + "member_name": [ + "enumConstant" + ], + "param_types": [ + "" + ], + "simple_name": [ + "enumConstant" + ], + "type_fqn": [ + "e.Routes" + ] + }, + "returns": [ + "void" + ], + "tier": "IN_PROJECT" + }, + "id": "e.Routes#enumConstant()", + "throws": [], + "varargs": false + }, + { + "annotations": [ + { + "name": "e.Routes$Path", + "values": [ + { + "kind": "string", + "name": "value", + "value": "/local" + } + ] + } + ], + "facts": { + "annotations": [ + "e.Routes$Path" + ], + "kind": "method", + "parent": "e.Routes", + "props": { + "annotation_values": [ + "[{\"elements\":[{\"name\":\"value\",\"value\":{\"kind\":\"string\",\"value\":\"/local\"}}],\"id\":\"e.Routes$Path\"}]" + ], + "member_name": [ + "knownConstant" + ], + "param_types": [ + "" + ], + "simple_name": [ + "knownConstant" + ], + "type_fqn": [ + "e.Routes" + ] + }, + "returns": [ + "void" + ], + "tier": "IN_PROJECT" + }, + "id": "e.Routes#knownConstant()", + "throws": [], + "varargs": false + }, + { + "annotations": [ + { + "name": "e.Routes$Path", + "values": [ + { + "kind": "expression", + "name": "value", + "text": "ADMIN" + } + ] + } + ], + "facts": { + "annotations": [ + "e.Routes$Path" + ], + "kind": "method", + "parent": "e.Routes", + "props": { + "annotation_values": [ + "[{\"elements\":[{\"name\":\"value\",\"value\":{\"kind\":\"expression\",\"text\":\"ADMIN\"}}],\"id\":\"e.Routes$Path\"}]" + ], + "member_name": [ + "unknownConstant" + ], + "param_types": [ + "" + ], + "simple_name": [ + "unknownConstant" + ], + "type_fqn": [ + "e.Routes" + ] + }, + "returns": [ + "void" + ], + "tier": "IN_PROJECT" + }, + "id": "e.Routes#unknownConstant()", + "throws": [], + "varargs": false + }, + { + "annotations": [], + "facts": { + "kind": "enum", + "parent": "e.Routes", + "props": { + "simple_name": [ + "Kind" + ], + "type_fqn": [ + "e.Routes$Kind" + ] + }, + "tier": "IN_PROJECT" + }, + "id": "e.Routes$Kind" + }, + { + "annotations": [], + "facts": { + "kind": "annotation", + "parent": "e.Routes", + "props": { + "simple_name": [ + "Path" + ], + "type_fqn": [ + "e.Routes$Path" + ] + }, + "tier": "IN_PROJECT" + }, + "id": "e.Routes$Path" + }, + { + "annotations": [], + "facts": { + "kind": "annotation", + "parent": "e.Routes", + "props": { + "simple_name": [ + "Tagged" + ], + "type_fqn": [ + "e.Routes$Tagged" + ] + }, + "tier": "IN_PROJECT" + }, + "id": "e.Routes$Tagged" + } + ], + "modifiers": [], + "origin": "project", + "typeParameters": 0, + "typeVars": [] + }, + "e.Routes$Kind": { + "annotations": [], + "id": "e.Routes$Kind", + "interfaceTypes": [], + "interfaces": [], + "kind": "enum", + "members": [ + { + "annotations": [], + "facts": { + "kind": "method", + "parent": "e.Routes$Kind", + "props": { + "member_name": [ + "Kind" + ], + "param_types": [ + "" + ], + "type_fqn": [ + "e.Routes$Kind" + ] + }, + "tier": "IN_PROJECT" + }, + "id": "e.Routes$Kind#\u003cinit\u003e()", + "throws": [], + "varargs": false + }, + { + "annotations": [], + "facts": { + "kind": "field", + "parent": "e.Routes$Kind", + "props": { + "member_name": [ + "A" + ], + "simple_name": [ + "A" + ], + "type_fqn": [ + "e.Routes$Kind" + ] + }, + "tier": "IN_PROJECT", + "type": [ + "e.Routes$Kind" + ] + }, + "id": "e.Routes$Kind#A" + }, + { + "annotations": [], + "facts": { + "kind": "method", + "parent": "e.Routes$Kind", + "props": { + "member_name": [ + "values" + ], + "modifiers": [ + "public", + "static" + ], + "param_types": [ + "" + ], + "type_fqn": [ + "e.Routes$Kind" + ] + }, + "returns": [ + "e.Routes$Kind[]" + ], + "tier": "IN_PROJECT" + }, + "id": "e.Routes$Kind#values()", + "throws": [], + "varargs": false + }, + { + "annotations": [], + "facts": { + "kind": "method", + "params": [ + "java.lang.String" + ], + "parent": "e.Routes$Kind", + "props": { + "member_name": [ + "valueOf" + ], + "modifiers": [ + "public", + "static" + ], + "param_types": [ + "java.lang.String" + ], + "type_fqn": [ + "e.Routes$Kind" + ] + }, + "returns": [ + "e.Routes$Kind" + ], + "tier": "IN_PROJECT" + }, + "id": "e.Routes$Kind#valueOf(java.lang.String)", + "throws": [], + "varargs": false + } + ], + "modifiers": [ + "static" + ], + "origin": "project", + "super": "java.lang.Enum", + "superType": { + "args": [ + { + "args": [], + "id": "e.Routes$Kind" + } + ], + "id": "java.lang.Enum" + }, + "typeParameters": 0, + "typeVars": [] + }, + "e.Routes$Path": { + "annotations": [], + "id": "e.Routes$Path", + "interfaces": [ + "java.lang.annotation.Annotation" + ], + "kind": "annotation", + "members": [ + { + "annotations": [], + "facts": { + "kind": "method", + "parent": "e.Routes$Path", + "props": { + "member_name": [ + "value" + ], + "param_types": [ + "" + ], + "simple_name": [ + "value" + ], + "type_fqn": [ + "e.Routes$Path" + ] + }, + "returns": [ + "java.lang.String[]" + ], + "tier": "IN_PROJECT" + }, + "id": "e.Routes$Path#value()", + "throws": [], + "varargs": false + } + ], + "modifiers": [ + "static" + ], + "origin": "project", + "typeParameters": 0, + "typeVars": [] + }, + "e.Routes$Tagged": { + "annotations": [], + "id": "e.Routes$Tagged", + "interfaces": [ + "java.lang.annotation.Annotation" + ], + "kind": "annotation", + "members": [ + { + "annotations": [], + "facts": { + "kind": "method", + "parent": "e.Routes$Tagged", + "props": { + "member_name": [ + "value" + ], + "param_types": [ + "" + ], + "simple_name": [ + "value" + ], + "type_fqn": [ + "e.Routes$Tagged" + ] + }, + "returns": [ + "e.Routes$Kind" + ], + "tier": "IN_PROJECT" + }, + "id": "e.Routes$Tagged#value()", + "throws": [], + "varargs": false + } + ], + "modifiers": [ + "static" + ], + "origin": "project", + "typeParameters": 0, + "typeVars": [] + }, + "java.io.Serializable": { + "annotations": [], + "interfaces": [], + "kind": "interface", + "members": [], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "typeParameters": 0, + "typeVars": [] + }, + "java.lang.CharSequence": { + "annotations": [], + "interfaces": [], + "kind": "interface", + "members": [ + { + "abstract": true, + "annotations": [], + "desc": "()I", + "final": false, + "k": "m", + "name": "length", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": true, + "annotations": [], + "desc": "(I)C", + "final": false, + "k": "m", + "name": "charAt", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Z", + "final": false, + "k": "m", + "name": "isEmpty", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": true, + "annotations": [], + "desc": "(II)Ljava/lang/CharSequence;", + "final": false, + "k": "m", + "name": "subSequence", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": true, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toString", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/stream/IntStream;", + "final": false, + "k": "m", + "name": "chars", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/stream/IntStream;", + "final": false, + "k": "m", + "name": "codePoints", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)I", + "final": false, + "k": "m", + "name": "compare", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + } + ], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "typeParameters": 0, + "typeVars": [] + }, + "java.lang.Comparable": { + "annotations": [], + "interfaceTypes": [], + "interfaces": [], + "kind": "interface", + "members": [ + { + "abstract": true, + "annotations": [], + "desc": "(Ljava/lang/Object;)I", + "final": false, + "k": "m", + "name": "compareTo", + "paramTypes": [ + { + "id": "T", + "kind": "typevar" + } + ], + "paramVars": [ + "c0" + ], + "retSelf": false, + "retType": { + "id": "int" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + } + ], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "superType": { + "args": [], + "id": "java.lang.Object" + }, + "typeParameters": 1, + "typeVarBounds": [ + [ + { + "args": [], + "id": "java.lang.Object" + } + ] + ], + "typeVars": [ + "T" + ] + }, + "java.lang.Enum": { + "annotations": [], + "interfaceTypes": [ + { + "args": [], + "id": "java.lang.constant.Constable" + }, + { + "args": [ + { + "id": "E", + "kind": "typevar" + } + ], + "id": "java.lang.Comparable" + }, + { + "args": [], + "id": "java.io.Serializable" + } + ], + "interfaces": [ + "java.lang.constant.Constable", + "java.lang.Comparable", + "java.io.Serializable" + ], + "kind": "class", + "members": [ + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": true, + "k": "m", + "name": "name", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()I", + "final": true, + "k": "m", + "name": "ordinal", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;I)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toString", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/Object;)Z", + "final": true, + "k": "m", + "name": "equals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()I", + "final": true, + "k": "m", + "name": "hashCode", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/Object;", + "final": true, + "k": "m", + "name": "clone", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.CloneNotSupportedException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/Enum;)I", + "final": true, + "k": "m", + "name": "compareTo", + "paramTypes": [ + { + "id": "E", + "kind": "typevar" + } + ], + "paramVars": [ + "c0" + ], + "retSelf": false, + "retType": { + "id": "int" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/Class;", + "final": true, + "k": "m", + "name": "getDeclaringClass", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "id": "E", + "kind": "typevar" + } + ], + "id": "java.lang.Class" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/Optional;", + "final": true, + "k": "m", + "name": "describeConstable", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "args": [ + { + "id": "E", + "kind": "typevar" + } + ], + "id": "java.lang.Enum$EnumDesc" + } + ], + "id": "java.util.Optional" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;", + "final": false, + "k": "m", + "name": "valueOf", + "paramTypes": [ + { + "args": [ + { + "id": "T", + "kind": "typevar" + } + ], + "id": "java.lang.Class" + }, + { + "args": [], + "id": "java.lang.String" + } + ], + "paramVars": [ + "", + "" + ], + "retSelf": false, + "retType": { + "id": "T", + "kind": "typevar" + }, + "static": true, + "synchronized": false, + "throws": [], + "typeVarBounds": [ + [ + { + "args": [ + { + "id": "T", + "kind": "typevar" + } + ], + "id": "java.lang.Enum" + } + ] + ], + "typeVars": [ + "T" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "java.lang.Deprecated", + "values": [ + { + "kind": "string", + "name": "since", + "value": "18" + }, + { + "kind": "boolean", + "name": "forRemoval", + "value": true + } + ] + } + ], + "desc": "()V", + "final": true, + "k": "m", + "name": "finalize", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/io/ObjectInputStream;)V", + "final": false, + "k": "m", + "name": "readObject", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.io.IOException", + "java.lang.ClassNotFoundException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()V", + "final": false, + "k": "m", + "name": "readObjectNoData", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.io.ObjectStreamException" + ], + "varargs": false, + "vis": "public" + }, + { + "annotations": [], + "desc": "Ljava/lang/String;", + "enum": false, + "final": true, + "k": "f", + "name": "name", + "static": false, + "vis": "private" + }, + { + "annotations": [], + "desc": "I", + "enum": false, + "final": true, + "k": "f", + "name": "ordinal", + "static": false, + "vis": "private" + }, + { + "annotations": [ + { + "name": "jdk.internal.vm.annotation.Stable", + "values": [] + } + ], + "desc": "I", + "enum": false, + "final": false, + "k": "f", + "name": "hash", + "static": false, + "vis": "private" + } + ], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "super": "java.lang.Object", + "superType": { + "args": [], + "id": "java.lang.Object" + }, + "typeParameters": 1, + "typeVarBounds": [ + [ + { + "args": [ + { + "id": "E", + "kind": "typevar" + } + ], + "id": "java.lang.Enum" + } + ] + ], + "typeVars": [ + "E" + ] + }, + "java.lang.Object": { + "annotations": [], + "interfaces": [], + "kind": "class", + "members": [ + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "()V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "()Ljava/lang/Class;", + "final": true, + "k": "m", + "name": "getClass", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "kind": "wildcard" + } + ], + "id": "java.lang.Class" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "()I", + "final": false, + "k": "m", + "name": "hashCode", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/Object;)Z", + "final": false, + "k": "m", + "name": "equals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "()Ljava/lang/Object;", + "final": false, + "k": "m", + "name": "clone", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.CloneNotSupportedException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toString", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "()V", + "final": true, + "k": "m", + "name": "notify", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "()V", + "final": true, + "k": "m", + "name": "notifyAll", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()V", + "final": true, + "k": "m", + "name": "wait", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.InterruptedException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(J)V", + "final": true, + "k": "m", + "name": "wait", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.InterruptedException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(J)V", + "final": true, + "k": "m", + "name": "wait0", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.InterruptedException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(JI)V", + "final": true, + "k": "m", + "name": "wait", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.InterruptedException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "java.lang.Deprecated", + "values": [ + { + "kind": "string", + "name": "since", + "value": "9" + }, + { + "kind": "boolean", + "name": "forRemoval", + "value": true + } + ] + } + ], + "desc": "()V", + "final": false, + "k": "m", + "name": "finalize", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.Throwable" + ], + "varargs": false, + "vis": "public" + } + ], + "modifiers": [ + "public" + ], + "origin": "classpath", + "typeParameters": 0, + "typeVars": [] + }, + "java.lang.String": { + "annotations": [], + "interfaceTypes": [ + { + "args": [], + "id": "java.io.Serializable" + }, + { + "args": [ + { + "args": [], + "id": "java.lang.String" + } + ], + "id": "java.lang.Comparable" + }, + { + "args": [], + "id": "java.lang.CharSequence" + }, + { + "args": [], + "id": "java.lang.constant.Constable" + }, + { + "args": [], + "id": "java.lang.constant.ConstantDesc" + } + ], + "interfaces": [ + "java.io.Serializable", + "java.lang.Comparable", + "java.lang.CharSequence", + "java.lang.constant.Constable", + "java.lang.constant.ConstantDesc" + ], + "kind": "class", + "members": [ + { + "abstract": false, + "annotations": [], + "desc": "()V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.IntrinsicCandidate", + "values": [] + } + ], + "desc": "(Ljava/lang/String;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([C)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([CII)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([CII)Ljava/lang/Void;", + "final": false, + "k": "m", + "name": "rangeCheck", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([III)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "java.lang.Deprecated", + "values": [ + { + "kind": "string", + "name": "since", + "value": "1.1" + } + ] + } + ], + "desc": "([BIII)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "java.lang.Deprecated", + "values": [ + { + "kind": "string", + "name": "since", + "value": "1.1" + } + ] + } + ], + "desc": "([BI)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIILjava/lang/String;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.io.UnsupportedEncodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIILjava/nio/charset/Charset;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/nio/charset/Charset;[BII)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIIZ)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "newStringUTF8NoRepl", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BLjava/nio/charset/Charset;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "newStringNoRepl", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [ + "java.nio.charset.CharacterCodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BLjava/nio/charset/Charset;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "newStringNoRepl1", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIZ)[B", + "final": false, + "k": "m", + "name": "safeTrim", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(IF)I", + "final": false, + "k": "m", + "name": "scale", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)Ljava/nio/charset/Charset;", + "final": false, + "k": "m", + "name": "lookupCharset", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [ + "java.io.UnsupportedEncodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/nio/charset/Charset;B[B)[B", + "final": false, + "k": "m", + "name": "encode", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/nio/charset/Charset;B[BZ)[B", + "final": false, + "k": "m", + "name": "encodeWithEncoder", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)[B", + "final": false, + "k": "m", + "name": "getBytesUTF8NoRepl", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([B)Z", + "final": false, + "k": "m", + "name": "isASCII", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;Ljava/nio/charset/Charset;)[B", + "final": false, + "k": "m", + "name": "getBytesNoRepl", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [ + "java.nio.charset.CharacterCodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;Ljava/nio/charset/Charset;)[B", + "final": false, + "k": "m", + "name": "getBytesNoRepl1", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(B[B)[B", + "final": false, + "k": "m", + "name": "encodeASCII", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BI)V", + "final": false, + "k": "m", + "name": "replaceNegatives", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(B[B)[B", + "final": false, + "k": "m", + "name": "encode8859_1", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(B[BZ)[B", + "final": false, + "k": "m", + "name": "encode8859_1", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BI[CII)I", + "final": false, + "k": "m", + "name": "decodeASCII", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Z", + "final": false, + "k": "m", + "name": "isNotContinuation", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(III)Z", + "final": false, + "k": "m", + "name": "isMalformed3", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)Z", + "final": false, + "k": "m", + "name": "isMalformed3_2", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(III)Z", + "final": false, + "k": "m", + "name": "isMalformed4", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)Z", + "final": false, + "k": "m", + "name": "isMalformed4_2", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Z", + "final": false, + "k": "m", + "name": "isMalformed4_3", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)C", + "final": false, + "k": "m", + "name": "decode2", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(III)C", + "final": false, + "k": "m", + "name": "decode3", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(IIII)I", + "final": false, + "k": "m", + "name": "decode4", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BII[BIZ)I", + "final": false, + "k": "m", + "name": "decodeUTF8_UTF16", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/nio/charset/CharsetDecoder;[C[BII)I", + "final": false, + "k": "m", + "name": "decodeWithDecoder", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [ + "java.nio.charset.CharacterCodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BI)I", + "final": false, + "k": "m", + "name": "malformed3", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BI)I", + "final": false, + "k": "m", + "name": "malformed4", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)V", + "final": false, + "k": "m", + "name": "throwMalformed", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([B)V", + "final": false, + "k": "m", + "name": "throwMalformed", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)V", + "final": false, + "k": "m", + "name": "throwUnmappable", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([B)V", + "final": false, + "k": "m", + "name": "throwUnmappable", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(B[BZ)[B", + "final": false, + "k": "m", + "name": "encodeUTF8", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BZ)[B", + "final": false, + "k": "m", + "name": "encodeUTF8_UTF16", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BLjava/lang/String;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.io.UnsupportedEncodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BLjava/nio/charset/Charset;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BII)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([B)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/StringBuffer;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/StringBuilder;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()I", + "final": false, + "k": "m", + "name": "length", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Z", + "final": false, + "k": "m", + "name": "isEmpty", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)C", + "final": false, + "k": "m", + "name": "charAt", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)I", + "final": false, + "k": "m", + "name": "codePointAt", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)I", + "final": false, + "k": "m", + "name": "codePointBefore", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)I", + "final": false, + "k": "m", + "name": "codePointCount", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)I", + "final": false, + "k": "m", + "name": "offsetByCodePoints", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II[CI)V", + "final": false, + "k": "m", + "name": "getChars", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "java.lang.Deprecated", + "values": [ + { + "kind": "string", + "name": "since", + "value": "1.1" + } + ] + } + ], + "desc": "(II[BI)V", + "final": false, + "k": "m", + "name": "getBytes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)[B", + "final": false, + "k": "m", + "name": "getBytes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.io.UnsupportedEncodingException" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/nio/charset/Charset;)[B", + "final": false, + "k": "m", + "name": "getBytes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()[B", + "final": false, + "k": "m", + "name": "getBytes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/Object;)Z", + "final": false, + "k": "m", + "name": "equals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/StringBuffer;)Z", + "final": false, + "k": "m", + "name": "contentEquals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/AbstractStringBuilder;)Z", + "final": false, + "k": "m", + "name": "nonSyncContentEquals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/CharSequence;)Z", + "final": false, + "k": "m", + "name": "contentEquals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)Z", + "final": false, + "k": "m", + "name": "equalsIgnoreCase", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)I", + "final": false, + "k": "m", + "name": "compareTo", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)I", + "final": false, + "k": "m", + "name": "compareToIgnoreCase", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(ILjava/lang/String;II)Z", + "final": false, + "k": "m", + "name": "regionMatches", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(ZILjava/lang/String;II)Z", + "final": false, + "k": "m", + "name": "regionMatches", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;I)Z", + "final": false, + "k": "m", + "name": "startsWith", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)Z", + "final": false, + "k": "m", + "name": "startsWith", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)Z", + "final": false, + "k": "m", + "name": "endsWith", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()I", + "final": false, + "k": "m", + "name": "hashCode", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(III)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)I", + "final": false, + "k": "m", + "name": "lastIndexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)I", + "final": false, + "k": "m", + "name": "lastIndexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;I)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;II)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BBILjava/lang/String;I)I", + "final": false, + "k": "m", + "name": "indexOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)I", + "final": false, + "k": "m", + "name": "lastIndexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;I)I", + "final": false, + "k": "m", + "name": "lastIndexOf", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BBILjava/lang/String;I)I", + "final": false, + "k": "m", + "name": "lastIndexOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "substring", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "substring", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)Ljava/lang/CharSequence;", + "final": false, + "k": "m", + "name": "subSequence", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "concat", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(CC)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "replace", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)Z", + "final": false, + "k": "m", + "name": "matches", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/CharSequence;)Z", + "final": false, + "k": "m", + "name": "contains", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "replaceFirst", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "replaceAll", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "replace", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;I)[Ljava/lang/String;", + "final": false, + "k": "m", + "name": "split", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;I)[Ljava/lang/String;", + "final": false, + "k": "m", + "name": "splitWithDelimiters", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;IZ)[Ljava/lang/String;", + "final": false, + "k": "m", + "name": "split", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(CIZ)[Ljava/lang/String;", + "final": false, + "k": "m", + "name": "split", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;)[Ljava/lang/String;", + "final": false, + "k": "m", + "name": "split", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/CharSequence;[Ljava/lang/CharSequence;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "join", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": true, + "vis": "public" + }, + { + "abstract": false, + "annotations": [ + { + "name": "jdk.internal.vm.annotation.ForceInline", + "values": [] + } + ], + "desc": "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;I)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "join", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/CharSequence;Ljava/lang/Iterable;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "join", + "paramTypes": [ + { + "args": [], + "id": "java.lang.CharSequence" + }, + { + "args": [ + { + "extends": { + "args": [], + "id": "java.lang.CharSequence" + }, + "kind": "wildcard" + } + ], + "id": "java.lang.Iterable" + } + ], + "paramVars": [ + "", + "" + ], + "retSelf": false, + "retType": { + "args": [], + "id": "java.lang.String" + }, + "static": true, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/util/Locale;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toLowerCase", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toLowerCase", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/util/Locale;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toUpperCase", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toUpperCase", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "trim", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "strip", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "stripLeading", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "stripTrailing", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Z", + "final": false, + "k": "m", + "name": "isBlank", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/stream/Stream;", + "final": false, + "k": "m", + "name": "lines", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "args": [], + "id": "java.lang.String" + } + ], + "id": "java.util.stream.Stream" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "indent", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()I", + "final": false, + "k": "m", + "name": "indexOfNonWhitespace", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()I", + "final": false, + "k": "m", + "name": "lastIndexOfNonWhitespace", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "stripIndent", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/util/List;)I", + "final": false, + "k": "m", + "name": "outdent", + "paramTypes": [ + { + "args": [ + { + "args": [], + "id": "java.lang.String" + } + ], + "id": "java.util.List" + } + ], + "paramVars": [ + "" + ], + "retSelf": false, + "retType": { + "id": "int" + }, + "static": true, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "translateEscapes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/util/function/Function;)Ljava/lang/Object;", + "final": false, + "k": "m", + "name": "transform", + "paramTypes": [ + { + "args": [ + { + "kind": "wildcard", + "super": { + "args": [], + "id": "java.lang.String" + } + }, + { + "extends": { + "id": "R", + "kind": "typevar" + }, + "kind": "wildcard" + } + ], + "id": "java.util.function.Function" + } + ], + "paramVars": [ + "" + ], + "retSelf": false, + "retType": { + "id": "R", + "kind": "typevar" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [ + [ + { + "args": [], + "id": "java.lang.Object" + } + ] + ], + "typeVars": [ + "R" + ], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toString", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/stream/IntStream;", + "final": false, + "k": "m", + "name": "chars", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/stream/IntStream;", + "final": false, + "k": "m", + "name": "codePoints", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()[C", + "final": false, + "k": "m", + "name": "toCharArray", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "format", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": true, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/util/Locale;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "format", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": true, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([Ljava/lang/Object;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "formatted", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": true, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/Object;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([C)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([CII)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([CII)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "copyValueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([C)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "copyValueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Z)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(C)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(J)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(F)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(D)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOf", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "intern", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "repeat", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIII)V", + "final": false, + "k": "m", + "name": "repeatCopyRest", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIB)V", + "final": false, + "k": "m", + "name": "getBytes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BIIBI)V", + "final": false, + "k": "m", + "name": "getBytes", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([CIILjava/lang/Void;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/AbstractStringBuilder;Ljava/lang/Void;)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "([BB)V", + "final": false, + "k": "m", + "name": "\u003cinit\u003e", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()B", + "final": false, + "k": "m", + "name": "coder", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()[B", + "final": false, + "k": "m", + "name": "value", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Z", + "final": false, + "k": "m", + "name": "isLatin1", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)V", + "final": false, + "k": "m", + "name": "checkIndex", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(II)V", + "final": false, + "k": "m", + "name": "checkOffset", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(III)I", + "final": false, + "k": "m", + "name": "checkBoundsOffCount", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(III)V", + "final": false, + "k": "m", + "name": "checkBoundsBeginEnd", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(I)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "valueOfCodePoint", + "retSelf": false, + "static": true, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "()Ljava/util/Optional;", + "final": false, + "k": "m", + "name": "describeConstable", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "args": [], + "id": "java.lang.String" + } + ], + "id": "java.util.Optional" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": false, + "annotations": [], + "desc": "(Ljava/lang/invoke/MethodHandles$Lookup;)Ljava/lang/String;", + "final": false, + "k": "m", + "name": "resolveConstantDesc", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "annotations": [ + { + "name": "jdk.internal.vm.annotation.Stable", + "values": [] + } + ], + "desc": "[B", + "enum": false, + "final": true, + "k": "f", + "name": "value", + "static": false, + "vis": "private" + }, + { + "annotations": [], + "desc": "B", + "enum": false, + "final": true, + "k": "f", + "name": "coder", + "static": false, + "vis": "private" + }, + { + "annotations": [], + "desc": "I", + "enum": false, + "final": false, + "k": "f", + "name": "hash", + "static": false, + "vis": "private" + }, + { + "annotations": [], + "desc": "Z", + "enum": false, + "final": false, + "k": "f", + "name": "hashIsZero", + "static": false, + "vis": "private" + }, + { + "annotations": [], + "constant": "-6849794470754667710", + "desc": "J", + "enum": false, + "final": true, + "k": "f", + "name": "serialVersionUID", + "static": true, + "vis": "private" + }, + { + "annotations": [], + "desc": "Z", + "enum": false, + "final": true, + "k": "f", + "name": "COMPACT_STRINGS", + "static": true, + "vis": "package" + }, + { + "annotations": [], + "desc": "[Ljava/io/ObjectStreamField;", + "enum": false, + "final": true, + "k": "f", + "name": "serialPersistentFields", + "static": true, + "vis": "private" + }, + { + "annotations": [], + "constant": "�", + "desc": "C", + "enum": false, + "final": true, + "k": "f", + "name": "REPL", + "static": true, + "vis": "private" + }, + { + "annotations": [], + "desc": "Ljava/util/Comparator;", + "enum": false, + "final": true, + "k": "f", + "name": "CASE_INSENSITIVE_ORDER", + "static": true, + "vis": "public" + }, + { + "annotations": [], + "constant": "0", + "desc": "B", + "enum": false, + "final": true, + "k": "f", + "name": "LATIN1", + "static": true, + "vis": "package" + }, + { + "annotations": [], + "constant": "1", + "desc": "B", + "enum": false, + "final": true, + "k": "f", + "name": "UTF16", + "static": true, + "vis": "package" + } + ], + "modifiers": [ + "public", + "final" + ], + "origin": "classpath", + "super": "java.lang.Object", + "superType": { + "args": [], + "id": "java.lang.Object" + }, + "typeParameters": 0, + "typeVarBounds": [], + "typeVars": [] + }, + "java.lang.annotation.Annotation": { + "annotations": [], + "interfaces": [], + "kind": "interface", + "members": [ + { + "abstract": true, + "annotations": [], + "desc": "(Ljava/lang/Object;)Z", + "final": false, + "k": "m", + "name": "equals", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": true, + "annotations": [], + "desc": "()I", + "final": false, + "k": "m", + "name": "hashCode", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": true, + "annotations": [], + "desc": "()Ljava/lang/String;", + "final": false, + "k": "m", + "name": "toString", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [], + "varargs": false, + "vis": "public" + }, + { + "abstract": true, + "annotations": [], + "desc": "()Ljava/lang/Class;", + "final": false, + "k": "m", + "name": "annotationType", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "extends": { + "args": [], + "id": "java.lang.annotation.Annotation" + }, + "kind": "wildcard" + } + ], + "id": "java.lang.Class" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + } + ], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "typeParameters": 0, + "typeVars": [] + }, + "java.lang.constant.Constable": { + "annotations": [], + "interfaces": [], + "kind": "interface", + "members": [ + { + "abstract": true, + "annotations": [], + "desc": "()Ljava/util/Optional;", + "final": false, + "k": "m", + "name": "describeConstable", + "paramTypes": [], + "paramVars": [], + "retSelf": false, + "retType": { + "args": [ + { + "extends": { + "args": [], + "id": "java.lang.constant.ConstantDesc" + }, + "kind": "wildcard" + } + ], + "id": "java.util.Optional" + }, + "static": false, + "synchronized": false, + "throws": [], + "typeVarBounds": [], + "typeVars": [], + "varargs": false, + "vis": "public" + } + ], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "typeParameters": 0, + "typeVars": [] + }, + "java.lang.constant.ConstantDesc": { + "annotations": [], + "interfaces": [], + "kind": "interface", + "members": [ + { + "abstract": true, + "annotations": [], + "desc": "(Ljava/lang/invoke/MethodHandles$Lookup;)Ljava/lang/Object;", + "final": false, + "k": "m", + "name": "resolveConstantDesc", + "retSelf": false, + "static": false, + "synchronized": false, + "throws": [ + "java.lang.ReflectiveOperationException" + ], + "varargs": false, + "vis": "public" + } + ], + "modifiers": [ + "public", + "abstract" + ], + "origin": "classpath", + "typeParameters": 0, + "typeVars": [] + } +} \ No newline at end of file diff --git a/java-frontend/src/main/java/org/sonar/java/model/JParserProvider.java b/java-frontend/src/main/java/org/sonar/java/model/JParserProvider.java index ae90ba98ef1..0a6ed9e150f 100644 --- a/java-frontend/src/main/java/org/sonar/java/model/JParserProvider.java +++ b/java-frontend/src/main/java/org/sonar/java/model/JParserProvider.java @@ -18,6 +18,7 @@ import java.io.File; import java.util.List; +import org.sonar.api.SonarRuntime; import org.sonar.api.config.Configuration; import org.sonar.plugins.java.api.JavaVersion; @@ -31,6 +32,11 @@ public interface JParserProvider { /** Called once at the start of each analysis, before any parser is created. */ void configure(Configuration configuration); + /** Same as {@link #configure(Configuration)}, for a provider that depends on the product running the analysis. */ + default void configure(Configuration configuration, SonarRuntime runtime) { + configure(configuration); + } + /** Whether the parsers of this provider must be used for the analysis in progress. At most one provider may be enabled at a time. */ boolean isEnabled(); diff --git a/java-frontend/src/main/java/org/sonar/java/model/JParserProviders.java b/java-frontend/src/main/java/org/sonar/java/model/JParserProviders.java index cf4d99140b1..21e857e80bf 100644 --- a/java-frontend/src/main/java/org/sonar/java/model/JParserProviders.java +++ b/java-frontend/src/main/java/org/sonar/java/model/JParserProviders.java @@ -19,7 +19,9 @@ import java.io.File; import java.util.List; import java.util.ServiceLoader; +import java.util.function.Consumer; import java.util.stream.Collectors; +import org.sonar.api.SonarRuntime; import org.sonar.api.config.Configuration; import org.sonar.java.jdt.JDTParser; import org.sonar.plugins.java.api.JavaVersion; @@ -39,14 +41,19 @@ private JParserProviders() { /** Loads and configures fresh providers for the current analysis. Nothing is loaded where no analysis configures them. */ public static void configure(Configuration configuration) { - List discovered = ServiceLoader.load(JParserProvider.class, JParserProviders.class.getClassLoader()) - .stream().map(ServiceLoader.Provider::get).toList(); - configured = configure(discovered, configuration); + configureWith(provider -> provider.configure(configuration)); + } + + /** Same as {@link #configure(Configuration)}, telling the providers which product runs the analysis. */ + public static void configure(Configuration configuration, SonarRuntime runtime) { + configureWith(provider -> provider.configure(configuration, runtime)); } - private static List configure(List providers, Configuration configuration) { - providers.forEach(provider -> provider.configure(configuration)); - return providers; + private static void configureWith(Consumer configuration) { + List discovered = ServiceLoader.load(JParserProvider.class, JParserProviders.class.getClassLoader()) + .stream().map(ServiceLoader.Provider::get).toList(); + discovered.forEach(configuration); + configured = discovered; } static JParser create(JParser.Mode mode, JavaVersion javaVersion, List classpath, boolean shouldIgnoreUnnamedModuleForSplitPackage, diff --git a/java-frontend/src/main/java/org/sonar/java/model/declaration/VariableTreeImpl.java b/java-frontend/src/main/java/org/sonar/java/model/declaration/VariableTreeImpl.java index c697d55faa0..95d2c4b84c8 100644 --- a/java-frontend/src/main/java/org/sonar/java/model/declaration/VariableTreeImpl.java +++ b/java-frontend/src/main/java/org/sonar/java/model/declaration/VariableTreeImpl.java @@ -161,7 +161,7 @@ public SyntaxToken endToken() { return endToken; } - public void setEndToken(InternalSyntaxToken endToken) { + public void setEndToken(@Nullable InternalSyntaxToken endToken) { this.endToken = endToken; } } diff --git a/java-frontend/src/test/java/org/sonar/java/model/JParserProvidersTest.java b/java-frontend/src/test/java/org/sonar/java/model/JParserProvidersTest.java index d6e340617c7..40e55b8e5a7 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/JParserProvidersTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/JParserProvidersTest.java @@ -16,15 +16,20 @@ */ package org.sonar.java.model; +import com.sonarsource.scanner.engine.sensor.test.fixtures.TestSonarRuntime; import java.io.File; import java.util.List; import java.util.Map; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; +import org.sonar.api.SonarEdition; +import org.sonar.api.SonarQubeSide; +import org.sonar.api.SonarRuntime; import org.sonar.api.config.Configuration; import org.sonar.java.jdt.JDTParser; import org.sonar.java.model.RegisteredParserProviders.CreatedParser; import org.sonar.plugins.java.api.JavaVersion; +import org.sonar.api.utils.Version; import org.sonar.scanner.plugin.api.impl.config.MapSettings; import static org.assertj.core.api.Assertions.assertThat; @@ -117,6 +122,21 @@ void a_provider_that_cannot_tell_whether_it_is_enabled_fails_instead_of_falling_ .hasMessage("alpha fails at enabled"); } + @Test + void providers_are_told_the_product_that_runs_the_analysis() { + Configuration configuration = settings(Map.of("alpha.enabledOnCloud", "true")); + + JParserProviders.configure(configuration, runtime(SonarEdition.SONARCLOUD)); + assertThat(JParserProviders.create(JParser.Mode.BATCH, VERSION, List.of(), false, true)).isEqualTo(new CreatedParser("alpha", JParser.Mode.BATCH, VERSION, List.of(), false)); + + JParserProviders.configure(configuration, runtime(SonarEdition.COMMUNITY)); + assertThat(JParserProviders.create(JParser.Mode.BATCH, VERSION, List.of(), false, true)).isInstanceOf(JDTParser.class); + } + + private static SonarRuntime runtime(SonarEdition edition) { + return TestSonarRuntime.forSonarQube(Version.create(10, 0), SonarQubeSide.SCANNER, edition); + } + private static Configuration settings(Map properties) { MapSettings settings = new MapSettings(); properties.forEach(settings::setProperty); diff --git a/java-frontend/src/test/java/org/sonar/java/model/RegisteredParserProviders.java b/java-frontend/src/test/java/org/sonar/java/model/RegisteredParserProviders.java index 8e15aa5883b..08fdaf8ea1b 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/RegisteredParserProviders.java +++ b/java-frontend/src/test/java/org/sonar/java/model/RegisteredParserProviders.java @@ -20,6 +20,8 @@ import java.util.List; import java.util.function.BiConsumer; import java.util.function.BooleanSupplier; +import org.sonar.api.SonarEdition; +import org.sonar.api.SonarRuntime; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.config.Configuration; import org.sonar.java.AnalysisProgress; @@ -28,7 +30,8 @@ /** * Parser providers registered through {@code META-INF/services} for the tests of {@link JParserProviders}. A provider is * driven by the configuration: {@code .enabled} turns it on and {@code .fail} set to {@code configure}, - * {@code enabled} or {@code create} makes that step throw. + * {@code enabled} or {@code create} makes that step throw. {@code .enabledOnCloud} turns it on only when the analysis + * is told that it runs on SonarQube Cloud. */ public final class RegisteredParserProviders { @@ -70,6 +73,12 @@ public void configure(Configuration configuration) { failAt("configure"); } + @Override + public void configure(Configuration configuration, SonarRuntime runtime) { + configure(configuration); + enabled |= configuration.getBoolean(name + ".enabledOnCloud").orElse(false) && runtime.getEdition() == SonarEdition.SONARCLOUD; + } + @Override public boolean isEnabled() { failAt("enabled"); diff --git a/sonar-java-plugin/license-resources/bsd-3-clause.txt b/sonar-java-plugin/license-resources/bsd-3-clause.txt new file mode 100644 index 00000000000..19b305b0006 --- /dev/null +++ b/sonar-java-plugin/license-resources/bsd-3-clause.txt @@ -0,0 +1,32 @@ +Copyright 2008 Google Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Code generated by the Protocol Buffer compiler is owned by the owner +of the input file used when generating it. This code is not +standalone and requires a support library to be linked with it. This +support library is itself covered by the above license. diff --git a/sonar-java-plugin/license-resources/ssal.txt b/sonar-java-plugin/license-resources/ssal.txt new file mode 100644 index 00000000000..28723feb3de --- /dev/null +++ b/sonar-java-plugin/license-resources/ssal.txt @@ -0,0 +1,184 @@ +SONAR Source-Available License v1.0 +Last Updated November 13, 2024 + +1. DEFINITIONS + +"Agreement" means this Sonar Source-Available License v1.0 + +"Competing" means marketing a product or service as a substitute for the +functionality or value of SonarQube. A product or service may compete regardless +of how it is designed or deployed. For example, a product or service may compete +even if it provides its functionality via any kind of interface (including +services, libraries, or plug-ins), even if it is ported to a different platform +or programming language, and even if it is provided free of charge. + +"Contribution" means: + + a) in the case of the initial Contributor, the initial content Distributed under +this Agreement, and + + b) in the case of each subsequent Contributor: + i) changes to the Program, and + ii) additions to the Program; + +where such changes and/or additions to the Program originate from and are +Distributed by that particular Contributor. A Contribution "originates" from a +Contributor if it was added to the Program by such Contributor itself or anyone +acting on such Contributor's behalf. Contributions do not include changes or +additions to the Program that are not Modified Works. + +"Contributor" means any person or entity that Distributes the Program. + +"Derivative Works" shall mean any work, whether in Source Code or other form, +that is based on (or derived from) the Program and for which the editorial +revisions, annotations, elaborations, or other modifications represent, as a +whole, an original work of authorship. + +"Distribute" means the acts of a) distributing or b) making available in any +manner that enables the transfer of a copy. + +"Licensed Patents" mean patent claims licensable by a Contributor that are +necessarily infringed by the use or sale of its Contribution alone or when +combined with the Program. + +"Modified Works" shall mean any work in Source Code or other form that results +from an addition to, deletion from, or modification of the contents of the +Program, including, for purposes of clarity, any new file in Source Code form +that contains any contents of the Program. Modified Works shall not include +works that contain only declarations, interfaces, types, classes, structures, or +files of the Program solely in each case in order to link to, bind by name, or +subclass the Program or Modified Works thereof. + +"Non-competitive Purpose" means any purpose except for (a) providing to others +any product or service that includes or offers the same or substantially similar +functionality as SonarQube, (b) Competing with SonarQube, and/or (c) employing, +using, or engaging artificial intelligence technology that is not part of the +Program to ingest, interpret, analyze, train on, or interact with the data +provided by the Program, or to engage with the Program in any manner. + +"Notices" means any legal statements or attributions included with the Program, +including, without limitation, statements concerning copyright, patent, +trademark, disclaimers of warranty, or limitations of liability + +"Program" means the Contributions Distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, +including Contributors. + +"SonarQube" means an open-source or commercial edition of software offered by +SonarSource that is branded "SonarQube". + +"SonarSource" means SonarSource SA, a Swiss company registered in Switzerland +under UID No. CHE-114.587.664. + +"Source Code" means the form of a Program preferred for making modifications, +including but not limited to software source code, documentation source, and +configuration files. + +2. GRANT OF RIGHTS + + a) Subject to the terms of this Agreement, each Contributor hereby grants +Recipient a non-exclusive, worldwide, royalty-free copyright license, for any +Non-competitive Purpose, to reproduce, prepare Derivative Works of, publicly +display, publicly perform, Distribute and sublicense the Contribution of such +Contributor, if any, and such Derivative Works. + + b) Subject to the terms of this Agreement, each Contributor hereby grants +Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed +Patents, for any Non-competitive Purpose, to make, use, sell, offer to sell, +import, and otherwise transfer the Contribution of such Contributor, if any, in +Source Code or other form. This patent license shall apply to the combination of +the Contribution and the Program if, at the time the Contribution is added by +the Contributor, such addition of the Contribution causes such combination to be +covered by the Licensed Patents. The patent license shall not apply to any other +combinations that include the Contribution. + + c) Recipient understands that although each Contributor grants the licenses to +its Contributions set forth herein, no assurances are provided by any +Contributor that the Program does not infringe the patent or other intellectual +property rights of any other entity. Each Contributor disclaims any liability to +Recipient for claims brought by any other entity based on infringement of +intellectual property rights or otherwise. As a condition to exercising the +rights and licenses granted hereunder, each Recipient hereby assumes sole +responsibility to secure any other intellectual property rights needed, if any. +For example, if a third-party patent license is required to allow Recipient to +Distribute the Program, it is Recipient's responsibility to acquire that license +before distributing the Program. + + d) Each Contributor represents that to its knowledge it has sufficient copyright +rights in its Contribution, if any, to grant the copyright license set forth in +this Agreement. + +3. REQUIREMENTS + +3.1 If a Contributor Distributes the Program in any form, then the Program must +also be made available as Source Code, in accordance with section 3.2, and the +Contributor must accompany the Program with a statement that the Source Code for +the Program is available under this Agreement, and inform Recipients how to +obtain it in a reasonable manner on or through a medium customarily used for +software exchange; and + +3.2 When the Program is Distributed as Source Code: + + a) it must be made available under this Agreement, and + + b) a copy of this Agreement must be included with each copy of the Program. + +3.3 Contributors may not remove or alter any Notices contained within the +Program from any copy of the Program which they Distribute, provided that +Contributors may add their own appropriate Notices. + +4. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT PERMITTED BY +APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES +OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT +LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, +MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and distributing the +Program and assumes all risks associated with its exercise of rights under this +Agreement, including but not limited to the risks and costs of program errors, +compliance with applicable laws, damage to or loss of data, programs or +equipment, and unavailability or interruption of operations. + +5. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT PERMITTED BY +APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF +THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGES. + +6. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable +law, it shall not affect the validity or enforceability of the remainder of the +terms of this Agreement, and without further action by the parties hereto, such +provision shall be reformed to the minimum extent necessary to make such +provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Program itself +(excluding combinations of the Program with other software or hardware) +infringes such Recipient’s patent(s), then such Recipient’s rights granted under +Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient’s rights under this Agreement shall terminate if it fails to +comply with any of the material terms or conditions of this Agreement and does +not cure such failure in a reasonable period of time after becoming aware of +such noncompliance. If all Recipient’s rights under this Agreement terminate, +Recipient agrees to cease use and distribution of the Program as soon as +reasonably practicable. However, Recipient’s obligations under this Agreement +and any licenses granted by Recipient relating to the Program shall continue and +survive. + +Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives +no rights or licenses to the intellectual property of any Contributor under this +Agreement, whether expressly, by implication, estoppel, or otherwise. All rights +in the Program not expressly granted under this Agreement are reserved. Nothing +in this Agreement is intended to be enforceable by any entity that is not a +Contributor or Recipient. No third-party beneficiary rights are created under +this Agreement. diff --git a/sonar-java-plugin/pom.xml b/sonar-java-plugin/pom.xml index a708dca33cf..842a03b9500 100644 --- a/sonar-java-plugin/pom.xml +++ b/sonar-java-plugin/pom.xml @@ -39,6 +39,11 @@ java-frontend ${project.version} + + ${project.groupId} + java-frontend-semsitter + ${project.version} + ${project.groupId} java-checks @@ -184,7 +189,7 @@ - 21500000 + 50000000 19000000 ${project.build.directory}/${project.build.finalName}.jar @@ -233,6 +238,12 @@ ** + + org.sonarsource.java:java-frontend-semsitter + + ** + + xerces:xercesImpl @@ -301,6 +312,14 @@ http://www.opensource.org/licenses/bsd-license.php ${project.baseUri}/license-resources/bsd.txt + + https://opensource.org/licenses/BSD-3-Clause + ${project.baseUri}/license-resources/bsd-3-clause.txt + + + https://sonarsource.com/license/ssal/ + ${project.baseUri}/license-resources/ssal.txt + diff --git a/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaSensor.java b/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaSensor.java index f0cf2e572a1..756d230176f 100644 --- a/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaSensor.java +++ b/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaSensor.java @@ -130,7 +130,7 @@ public void execute(SensorContext context) { telemetry.aggregateAsFlag(JAVA_IS_AUTOSCAN, sonarComponents.isAutoScan()); if (!sonarComponents.isSonarLintContext()) { - JParserProviders.configure(context.config()); + JParserProviders.configure(context.config(), context.runtime()); } JavaFrontend frontend = new JavaFrontend(javaVersion, diff --git a/sonar-java-plugin/src/main/resources/licenses/THIRD_PARTY_LICENSES/com.google.protobuf.protobuf-java-LICENSE.txt b/sonar-java-plugin/src/main/resources/licenses/THIRD_PARTY_LICENSES/com.google.protobuf.protobuf-java-LICENSE.txt new file mode 100644 index 00000000000..19b305b0006 --- /dev/null +++ b/sonar-java-plugin/src/main/resources/licenses/THIRD_PARTY_LICENSES/com.google.protobuf.protobuf-java-LICENSE.txt @@ -0,0 +1,32 @@ +Copyright 2008 Google Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Code generated by the Protocol Buffer compiler is owned by the owner +of the input file used when generating it. This code is not +standalone and requires a support library to be linked with it. This +support library is itself covered by the above license. diff --git a/sonar-java-plugin/src/main/resources/licenses/THIRD_PARTY_LICENSES/org.sonarsource.semsitter.analyzer-wire-LICENSE.txt b/sonar-java-plugin/src/main/resources/licenses/THIRD_PARTY_LICENSES/org.sonarsource.semsitter.analyzer-wire-LICENSE.txt new file mode 100644 index 00000000000..28723feb3de --- /dev/null +++ b/sonar-java-plugin/src/main/resources/licenses/THIRD_PARTY_LICENSES/org.sonarsource.semsitter.analyzer-wire-LICENSE.txt @@ -0,0 +1,184 @@ +SONAR Source-Available License v1.0 +Last Updated November 13, 2024 + +1. DEFINITIONS + +"Agreement" means this Sonar Source-Available License v1.0 + +"Competing" means marketing a product or service as a substitute for the +functionality or value of SonarQube. A product or service may compete regardless +of how it is designed or deployed. For example, a product or service may compete +even if it provides its functionality via any kind of interface (including +services, libraries, or plug-ins), even if it is ported to a different platform +or programming language, and even if it is provided free of charge. + +"Contribution" means: + + a) in the case of the initial Contributor, the initial content Distributed under +this Agreement, and + + b) in the case of each subsequent Contributor: + i) changes to the Program, and + ii) additions to the Program; + +where such changes and/or additions to the Program originate from and are +Distributed by that particular Contributor. A Contribution "originates" from a +Contributor if it was added to the Program by such Contributor itself or anyone +acting on such Contributor's behalf. Contributions do not include changes or +additions to the Program that are not Modified Works. + +"Contributor" means any person or entity that Distributes the Program. + +"Derivative Works" shall mean any work, whether in Source Code or other form, +that is based on (or derived from) the Program and for which the editorial +revisions, annotations, elaborations, or other modifications represent, as a +whole, an original work of authorship. + +"Distribute" means the acts of a) distributing or b) making available in any +manner that enables the transfer of a copy. + +"Licensed Patents" mean patent claims licensable by a Contributor that are +necessarily infringed by the use or sale of its Contribution alone or when +combined with the Program. + +"Modified Works" shall mean any work in Source Code or other form that results +from an addition to, deletion from, or modification of the contents of the +Program, including, for purposes of clarity, any new file in Source Code form +that contains any contents of the Program. Modified Works shall not include +works that contain only declarations, interfaces, types, classes, structures, or +files of the Program solely in each case in order to link to, bind by name, or +subclass the Program or Modified Works thereof. + +"Non-competitive Purpose" means any purpose except for (a) providing to others +any product or service that includes or offers the same or substantially similar +functionality as SonarQube, (b) Competing with SonarQube, and/or (c) employing, +using, or engaging artificial intelligence technology that is not part of the +Program to ingest, interpret, analyze, train on, or interact with the data +provided by the Program, or to engage with the Program in any manner. + +"Notices" means any legal statements or attributions included with the Program, +including, without limitation, statements concerning copyright, patent, +trademark, disclaimers of warranty, or limitations of liability + +"Program" means the Contributions Distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, +including Contributors. + +"SonarQube" means an open-source or commercial edition of software offered by +SonarSource that is branded "SonarQube". + +"SonarSource" means SonarSource SA, a Swiss company registered in Switzerland +under UID No. CHE-114.587.664. + +"Source Code" means the form of a Program preferred for making modifications, +including but not limited to software source code, documentation source, and +configuration files. + +2. GRANT OF RIGHTS + + a) Subject to the terms of this Agreement, each Contributor hereby grants +Recipient a non-exclusive, worldwide, royalty-free copyright license, for any +Non-competitive Purpose, to reproduce, prepare Derivative Works of, publicly +display, publicly perform, Distribute and sublicense the Contribution of such +Contributor, if any, and such Derivative Works. + + b) Subject to the terms of this Agreement, each Contributor hereby grants +Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed +Patents, for any Non-competitive Purpose, to make, use, sell, offer to sell, +import, and otherwise transfer the Contribution of such Contributor, if any, in +Source Code or other form. This patent license shall apply to the combination of +the Contribution and the Program if, at the time the Contribution is added by +the Contributor, such addition of the Contribution causes such combination to be +covered by the Licensed Patents. The patent license shall not apply to any other +combinations that include the Contribution. + + c) Recipient understands that although each Contributor grants the licenses to +its Contributions set forth herein, no assurances are provided by any +Contributor that the Program does not infringe the patent or other intellectual +property rights of any other entity. Each Contributor disclaims any liability to +Recipient for claims brought by any other entity based on infringement of +intellectual property rights or otherwise. As a condition to exercising the +rights and licenses granted hereunder, each Recipient hereby assumes sole +responsibility to secure any other intellectual property rights needed, if any. +For example, if a third-party patent license is required to allow Recipient to +Distribute the Program, it is Recipient's responsibility to acquire that license +before distributing the Program. + + d) Each Contributor represents that to its knowledge it has sufficient copyright +rights in its Contribution, if any, to grant the copyright license set forth in +this Agreement. + +3. REQUIREMENTS + +3.1 If a Contributor Distributes the Program in any form, then the Program must +also be made available as Source Code, in accordance with section 3.2, and the +Contributor must accompany the Program with a statement that the Source Code for +the Program is available under this Agreement, and inform Recipients how to +obtain it in a reasonable manner on or through a medium customarily used for +software exchange; and + +3.2 When the Program is Distributed as Source Code: + + a) it must be made available under this Agreement, and + + b) a copy of this Agreement must be included with each copy of the Program. + +3.3 Contributors may not remove or alter any Notices contained within the +Program from any copy of the Program which they Distribute, provided that +Contributors may add their own appropriate Notices. + +4. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT PERMITTED BY +APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES +OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT +LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, +MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and distributing the +Program and assumes all risks associated with its exercise of rights under this +Agreement, including but not limited to the risks and costs of program errors, +compliance with applicable laws, damage to or loss of data, programs or +equipment, and unavailability or interruption of operations. + +5. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT PERMITTED BY +APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF +THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGES. + +6. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable +law, it shall not affect the validity or enforceability of the remainder of the +terms of this Agreement, and without further action by the parties hereto, such +provision shall be reformed to the minimum extent necessary to make such +provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Program itself +(excluding combinations of the Program with other software or hardware) +infringes such Recipient’s patent(s), then such Recipient’s rights granted under +Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient’s rights under this Agreement shall terminate if it fails to +comply with any of the material terms or conditions of this Agreement and does +not cure such failure in a reasonable period of time after becoming aware of +such noncompliance. If all Recipient’s rights under this Agreement terminate, +Recipient agrees to cease use and distribution of the Program as soon as +reasonably practicable. However, Recipient’s obligations under this Agreement +and any licenses granted by Recipient relating to the Program shall continue and +survive. + +Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives +no rights or licenses to the intellectual property of any Contributor under this +Agreement, whether expressly, by implication, estoppel, or otherwise. All rights +in the Program not expressly granted under this Agreement are reserved. Nothing +in this Agreement is intended to be enforceable by any entity that is not a +Contributor or Recipient. No third-party beneficiary rights are created under +this Agreement. diff --git a/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaSensorTest.java b/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaSensorTest.java index c034ba5b0f7..8641be3a1df 100644 --- a/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaSensorTest.java +++ b/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaSensorTest.java @@ -31,6 +31,7 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Stream; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.io.TempDir; @@ -97,6 +98,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +@Disabled("DO NOT MERGE: the default test runtime makes the sensor use the bundled SemSitter server, which exists for Linux only") class JavaSensorTest { private static final String EXPECTED_TYPE_ERROR_COUNT = "223"; diff --git a/sonar-java-plugin/src/test/java/org/sonar/plugins/java/SpringContextModelSensorTest.java b/sonar-java-plugin/src/test/java/org/sonar/plugins/java/SpringContextModelSensorTest.java index 2c99690a71a..0fd9a294081 100644 --- a/sonar-java-plugin/src/test/java/org/sonar/plugins/java/SpringContextModelSensorTest.java +++ b/sonar-java-plugin/src/test/java/org/sonar/plugins/java/SpringContextModelSensorTest.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.io.TempDir; @@ -63,6 +64,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +@Disabled("DO NOT MERGE: the default test runtime makes the sensor use the bundled SemSitter server, which exists for Linux only") class SpringContextModelSensorTest { private static final String MODULE_KEY = "module";