src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java
changeset 49436 0fdb76741c56
parent 48932 9e3f2ec326ba
child 51045 215d1a5b097a
equal deleted inserted replaced
49435:5fd26ab491fa 49436:0fdb76741c56
   356 
   356 
   357         RedundantLocalVarTypeAnalyzerBase(JCTree.Tag tag) {
   357         RedundantLocalVarTypeAnalyzerBase(JCTree.Tag tag) {
   358             super(AnalyzerMode.LOCAL, tag);
   358             super(AnalyzerMode.LOCAL, tag);
   359         }
   359         }
   360 
   360 
       
   361         boolean isImplicitlyTyped(JCVariableDecl decl) {
       
   362             return decl.vartype.pos == Position.NOPOS;
       
   363         }
       
   364 
   361         /**
   365         /**
   362          * Map a variable tree into a new declaration using implicit type.
   366          * Map a variable tree into a new declaration using implicit type.
   363          */
   367          */
   364         JCVariableDecl rewriteVarType(JCVariableDecl oldTree) {
   368         JCVariableDecl rewriteVarType(JCVariableDecl oldTree) {
   365             JCVariableDecl newTree = copier.copy(oldTree);
   369             JCVariableDecl newTree = copier.copy(oldTree);
   388             super(VARDEF);
   392             super(VARDEF);
   389         }
   393         }
   390 
   394 
   391         boolean match(JCVariableDecl tree){
   395         boolean match(JCVariableDecl tree){
   392             return tree.sym.owner.kind == Kind.MTH &&
   396             return tree.sym.owner.kind == Kind.MTH &&
   393                     tree.init != null && !tree.isImplicitlyTyped() &&
   397                     tree.init != null && !isImplicitlyTyped(tree) &&
   394                     attr.canInferLocalVarType(tree) == null;
   398                     attr.canInferLocalVarType(tree) == null;
   395         }
   399         }
   396         @Override
   400         @Override
   397         List<JCVariableDecl> rewrite(JCVariableDecl oldTree) {
   401         List<JCVariableDecl> rewrite(JCVariableDecl oldTree) {
   398             return List.of(rewriteVarType(oldTree));
   402             return List.of(rewriteVarType(oldTree));
   412             super(FOREACHLOOP);
   416             super(FOREACHLOOP);
   413         }
   417         }
   414 
   418 
   415         @Override
   419         @Override
   416         boolean match(JCEnhancedForLoop tree){
   420         boolean match(JCEnhancedForLoop tree){
   417             return !tree.var.isImplicitlyTyped();
   421             return !isImplicitlyTyped(tree.var);
   418         }
   422         }
   419         @Override
   423         @Override
   420         List<JCEnhancedForLoop> rewrite(JCEnhancedForLoop oldTree) {
   424         List<JCEnhancedForLoop> rewrite(JCEnhancedForLoop oldTree) {
   421             JCEnhancedForLoop newTree = copier.copy(oldTree);
   425             JCEnhancedForLoop newTree = copier.copy(oldTree);
   422             newTree.var = rewriteVarType(oldTree.var);
   426             newTree.var = rewriteVarType(oldTree.var);