2323package com .uber .nullaway ;
2424
2525import static com .google .errorprone .BugPattern .SeverityLevel .WARNING ;
26- import static com .sun .source .tree .Tree .Kind .EXPRESSION_STATEMENT ;
2726import static com .sun .source .tree .Tree .Kind .IDENTIFIER ;
2827import static com .sun .source .tree .Tree .Kind .OTHER ;
29- import static com .sun .source .tree .Tree .Kind .PARENTHESIZED ;
30- import static com .sun .source .tree .Tree .Kind .TYPE_CAST ;
3128import static com .uber .nullaway .ASTHelpersBackports .hasDirectAnnotationWithSimpleName ;
3229import static com .uber .nullaway .ASTHelpersBackports .isStatic ;
3330import static com .uber .nullaway .ErrorBuilder .errMsgForInitializer ;
5956import com .sun .source .tree .AnnotatedTypeTree ;
6057import com .sun .source .tree .AnnotationTree ;
6158import com .sun .source .tree .ArrayAccessTree ;
59+ import com .sun .source .tree .AssertTree ;
6260import com .sun .source .tree .AssignmentTree ;
6361import com .sun .source .tree .BinaryTree ;
6462import com .sun .source .tree .BlockTree ;
@@ -1197,8 +1195,7 @@ private Description checkForReadBeforeInit(ExpressionTree tree, VisitorState sta
11971195 // is this possible?
11981196 return Description .NO_MATCH ;
11991197 }
1200- if (!config .assertsEnabled ()
1201- && enclosingBlockPath .getLeaf ().getKind ().equals (Tree .Kind .ASSERT )) {
1198+ if (!config .assertsEnabled () && enclosingBlockPath .getLeaf () instanceof AssertTree ) {
12021199 return Description .NO_MATCH ;
12031200 }
12041201 if (!relevantInitializerMethodOrBlock (enclosingBlockPath , state )) {
@@ -1375,7 +1372,7 @@ private ImmutableSet<Element> safeInitByCalleeBefore(
13751372 safeInitMethods .add (privMethodElem );
13761373 }
13771374 // Hack: Handling try{...}finally{...} statement, see getSafeInitMethods
1378- if (curStmt . getKind (). equals ( Tree . Kind . TRY ) ) {
1375+ if (curStmt instanceof TryTree ) {
13791376 TryTree tryTree = (TryTree ) curStmt ;
13801377 // ToDo: Should we check initialization inside tryTree.getResources ? What is the scope of
13811378 // that initialization?
@@ -2356,7 +2353,7 @@ private Set<Element> getSafeInitMethods(
23562353 // as "top level" for the purposes of finding initialization methods. Any exception happening
23572354 // there is also an
23582355 // exception of the full method.
2359- if (stmt . getKind (). equals ( Tree . Kind . TRY ) ) {
2356+ if (stmt instanceof TryTree ) {
23602357 TryTree tryTree = (TryTree ) stmt ;
23612358 if (tryTree .getCatches ().size () == 0 ) {
23622359 if (tryTree .getBlock () != null ) {
@@ -2405,7 +2402,7 @@ private Set<Element> getSafeInitMethods(
24052402 }
24062403 return false ;
24072404 };
2408- if (stmt . getKind (). equals ( EXPRESSION_STATEMENT ) ) {
2405+ if (stmt instanceof ExpressionStatementTree ) {
24092406 ExpressionTree expression = ((ExpressionStatementTree ) stmt ).getExpression ();
24102407 if (invokeMatcher .matches (expression , state )) {
24112408 return ASTHelpers .getSymbol (expression );
@@ -2415,7 +2412,7 @@ private Set<Element> getSafeInitMethods(
24152412 }
24162413
24172414 private boolean isThisCall (StatementTree statementTree , VisitorState state ) {
2418- if (statementTree . getKind (). equals ( EXPRESSION_STATEMENT ) ) {
2415+ if (statementTree instanceof ExpressionStatementTree ) {
24192416 ExpressionTree expression = ((ExpressionStatementTree ) statementTree ).getExpression ();
24202417 return Matchers .methodInvocation (THIS_MATCHER ).matches (expression , state );
24212418 }
@@ -2754,7 +2751,7 @@ private Description matchDereference(
27542751 }
27552752
27562753 private static boolean isThisIdentifier (ExpressionTree expressionTree ) {
2757- return expressionTree . getKind (). equals ( IDENTIFIER )
2754+ return expressionTree instanceof IdentifierTree
27582755 && ((IdentifierTree ) expressionTree ).getName ().toString ().equals ("this" );
27592756 }
27602757
@@ -2777,11 +2774,11 @@ private static ExpressionTree stripParensAndCasts(ExpressionTree expr) {
27772774 boolean someChange = true ;
27782775 while (someChange ) {
27792776 someChange = false ;
2780- if (expr . getKind (). equals ( PARENTHESIZED ) ) {
2777+ if (expr instanceof ParenthesizedTree ) {
27812778 expr = ((ParenthesizedTree ) expr ).getExpression ();
27822779 someChange = true ;
27832780 }
2784- if (expr . getKind (). equals ( TYPE_CAST ) ) {
2781+ if (expr instanceof TypeCastTree ) {
27852782 expr = ((TypeCastTree ) expr ).getExpression ();
27862783 someChange = true ;
27872784 }
0 commit comments