Skip to content

Commit

Permalink
SONARJAVA-4924 Remove deprecated method ExpressionUtils.getEnclosingE…
Browse files Browse the repository at this point in the history
…lement (#4744)
  • Loading branch information
kaufco authored Mar 27, 2024
1 parent cdf94ce commit 7e7fc73
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private static MethodTree usedInOneMethodOnly(Symbol privateFieldSymbol, TypeSym
MethodTree method = null;

for (IdentifierTree usageIdentifier : privateFieldSymbol.usages()) {
MethodTree enclosingMethod = ExpressionUtils.getEnclosingElement(usageIdentifier, Kind.METHOD);
MethodTree enclosingMethod = (MethodTree) ExpressionUtils.getEnclosingTree(usageIdentifier, Kind.METHOD);

if (enclosingMethod == null
|| !enclosingMethod.symbol().owner().equals(classSymbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,7 @@ public static IdentifierTree methodName(MethodInvocationTree mit) {
*/
@CheckForNull
public static MethodTree getEnclosingMethod(ExpressionTree expr) {
return getEnclosingElement(expr, Tree.Kind.METHOD, Tree.Kind.CONSTRUCTOR);
}

/**
* @deprecated
* This method assumes that the enclosing element will be a {@link MethodTree} while allowing any values for `kinds`.
* It will throw a `ClassCastException` for any other `kinds` than `Kind.METHOD` or `Kind.CONSTRUCTOR`.
* Use {@link #getEnclosingTree(Tree, Tree.Kind...)} tree instead and do the required downcast on the callee side.
*/
@Deprecated(since = "7.32", forRemoval = true)
@CheckForNull
public static MethodTree getEnclosingElement(ExpressionTree expr, Tree.Kind... kinds) {
return (MethodTree) getEnclosingTree(expr, kinds);
return (MethodTree) getEnclosingTree(expr, Tree.Kind.METHOD, Tree.Kind.CONSTRUCTOR);
}

@CheckForNull
Expand Down

0 comments on commit 7e7fc73

Please sign in to comment.