Skip to content

Commit

Permalink
Use alternative API to find the parent of a node for precedence findi…
Browse files Browse the repository at this point in the history
…ng in

Refaster.

Fixes #3193

PiperOrigin-RevId: 448331636
  • Loading branch information
nick-someone authored and Error Prone Team committed May 12, 2022
1 parent 7cf0654 commit 2f1eece
Showing 1 changed file with 3 additions and 1 deletion.
Expand Up @@ -33,6 +33,7 @@
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.util.TreeScanner;
import com.sun.tools.javac.api.JavacTrees;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.TypeTag;
import com.sun.tools.javac.code.Types;
Expand Down Expand Up @@ -248,7 +249,8 @@ public Fix replace(ExpressionTemplateMatch match) {
*/
private static int getPrecedence(JCTree leaf, Context context) {
JCCompilationUnit comp = context.get(JCCompilationUnit.class);
JCTree parent = TreeInfo.pathFor(leaf, comp).get(1);
JCTree parent =
(JCTree) JavacTrees.instance(context).getPath(comp, leaf).getParentPath().getLeaf();

// In general, this should match the logic in com.sun.tools.javac.tree.Pretty.
//
Expand Down

0 comments on commit 2f1eece

Please sign in to comment.