Class MethodTreeUtils

java.lang.Object
org.sonar.java.checks.helpers.MethodTreeUtils

public final class MethodTreeUtils extends Object
  • Method Details

    • isMainMethod

      public static boolean isMainMethod(MethodTree m, JavaVersion javaVersion)
    • compareMainMethodPriority

      public static int compareMainMethodPriority(MethodTree compared, MethodTree reference)
      Compares the priority of two main methods. In Java 25 and above, a main method with a String[] parameter has higher priority than a main method without parameters. In earlier versions of Java, only a main method with a String[] parameter is considered valid.
      Parameters:
      compared - : first main method to compare
      reference - : second main method to compare
      Returns:
      1 if m1 has higher priority, -1 if m2 has higher priority, 0 if both have the same priority
    • parentMethodInvocationOfArgumentAtPos

      @Nullable public static MethodInvocationTree parentMethodInvocationOfArgumentAtPos(@Nullable ExpressionTree argumentCandidate, int expectedArgumentPosition)
      Returns:
      null when: - argumentCandidate is null - the parent is not a method invocation (ignoring parent parentheses) - argumentCandidate is not at the expected argument position Otherwise, returns the parent method invocation.
    • lamdaArgumentAt

      @Nullable public static VariableTree lamdaArgumentAt(@Nullable LambdaExpressionTree lambdaExpressionTree, int argumentPosition)
    • isEqualsMethod

      public static boolean isEqualsMethod(MethodTree m)
    • isHashCodeMethod

      public static boolean isHashCodeMethod(MethodTree m)
    • isSetterMethod

      public static boolean isSetterMethod(MethodTree m)
    • consecutiveMethodInvocation

      public static Optional<MethodInvocationTree> consecutiveMethodInvocation(Tree tree)
    • subsequentMethodInvocation

      public static Optional<MethodInvocationTree> subsequentMethodInvocation(Tree tree, MethodMatchers methodMatchers)
    • isGetterLike

      public static Optional<String> isGetterLike(Symbol.MethodSymbol methodSymbol)
    • isSetterLike

      public static Optional<String> isSetterLike(Symbol.MethodSymbol methodSymbol)