154. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 9/25/2018 2:13:08 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

154.1 Files compared

# Location File Last Modified
1 build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\tools\javac\main JavaCompiler.java Mon Jan 22 14:47:06 2018 UTC
2 build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\tools\javac\main JavaCompiler.java Wed Sep 12 16:49:55 2018 UTC

154.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 3526
Changed 1 2
Inserted 0 0
Removed 0 0

154.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

154.4 Active regular expressions

No regular expressions were active.

154.5 Comparison detail

  1   /*
  2    * Copyrig ht (c) 199 9, 2013, O racle and/ or its aff iliates. A ll rights  reserved.
  3    * DO NOT  ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER.
  4    *
  5    * This co de is free  software;  you can r edistribut e it and/o r modify i t
  6    * under t he terms o f the GNU  General Pu blic Licen se version  2 only, a s
  7    * publish ed by the  Free Softw are Founda tion.  Ora cle design ates this
  8    * particu lar file a s subject  to the "Cl asspath" e xception a s provided
  9    * by Orac le in the  LICENSE fi le that ac companied  this code.
  10    *
  11    * This co de is dist ributed in  the hope  that it wi ll be usef ul, but WI THOUT
  12    * ANY WAR RANTY; wit hout even  the implie d warranty  of MERCHA NTABILITY  or
  13    * FITNESS  FOR A PAR TICULAR PU RPOSE.  Se e the GNU  General Pu blic Licen se
  14    * version  2 for mor e details  (a copy is  included  in the LIC ENSE file  that
  15    * accompa nied this  code).
  16    *
  17    * You sho uld have r eceived a  copy of th e GNU Gene ral Public  License v ersion
  18    * 2 along  with this  work; if  not, write  to the Fr ee Softwar e Foundati on,
  19    * Inc., 5 1 Franklin  St, Fifth  Floor, Bo ston, MA 0 2110-1301  USA.
  20    *
  21    * Please  contact Or acle, 500  Oracle Par kway, Redw ood Shores , CA 94065  USA
  22    * or visi t www.orac le.com if  you need a dditional  informatio n or have  any
  23    * questio ns.
  24    */
  25  
  26   package co m.sun.tool s.javac.ma in;
  27  
  28   import jav a.io.*;
  29   import jav a.util.Has hMap;
  30   import jav a.util.Has hSet;
  31   import jav a.util.Lin kedHashMap ;
  32   import jav a.util.Lin kedHashSet ;
  33   import jav a.util.Map ;
  34   import jav a.util.Mis singResour ceExceptio n;
  35   import jav a.util.Que ue;
  36   import jav a.util.Res ourceBundl e;
  37   import jav a.util.Set ;
  38  
  39   import jav ax.annotat ion.proces sing.Proce ssor;
  40   import jav ax.lang.mo del.Source Version;
  41   import jav ax.tools.D iagnosticL istener;
  42   import jav ax.tools.J avaFileMan ager;
  43   import jav ax.tools.J avaFileObj ect;
  44   import jav ax.tools.S tandardLoc ation;
  45  
  46   import sta tic javax. tools.Stan dardLocati on.CLASS_O UTPUT;
  47  
  48   import com .sun.sourc e.util.Tas kEvent;
  49   import com .sun.tools .javac.api .MultiTask Listener;
  50   import com .sun.tools .javac.cod e.*;
  51   import com .sun.tools .javac.cod e.Lint.Lin tCategory;
  52   import com .sun.tools .javac.cod e.Symbol.* ;
  53   import com .sun.tools .javac.com p.*;
  54   import com .sun.tools .javac.com p.CompileS tates.Comp ileState;
  55   import com .sun.tools .javac.fil e.JavacFil eManager;
  56   import com .sun.tools .javac.jvm .*;
  57   import com .sun.tools .javac.par ser.*;
  58   import com .sun.tools .javac.pro cessing.*;
  59   import com .sun.tools .javac.tre e.*;
  60   import com .sun.tools .javac.tre e.JCTree.* ;
  61   import com .sun.tools .javac.uti l.*;
  62   import com .sun.tools .javac.uti l.Log.Writ erKind;
  63  
  64   import sta tic com.su n.tools.ja vac.code.T ypeTag.CLA SS;
  65   import sta tic com.su n.tools.ja vac.main.O ption.*;
  66   import sta tic com.su n.tools.ja vac.util.J CDiagnosti c.Diagnost icFlag.*;
  67  
  68  
  69   /** This c lass could  be the ma in entry p oint for G JC when GJ C is used  as a
  70    *  compon ent in a l arger soft ware syste m. It prov ides opera tions to
  71    *  constr uct a new  compiler,  and to run  a new com piler on a  set of so urce
  72    *  files.
  73    *
  74    *  <p><b> This is NO T part of  any suppor ted API.
  75    *  If you  write cod e that dep ends on th is, you do  so at you r own risk .
  76    *  This c ode and it s internal  interface s are subj ect to cha nge or
  77    *  deleti on without  notice.</ b>
  78    */
  79   public cla ss JavaCom piler {
  80       /** Th e context  key for th e compiler . */
  81       protec ted static  final Con text.Key<J avaCompile r> compile rKey =
  82           ne w Context. Key<JavaCo mpiler>();
  83  
  84       /** Ge t the Java Compiler i nstance fo r this con text. */
  85       public  static Ja vaCompiler  instance( Context co ntext) {
  86           Ja vaCompiler  instance  = context. get(compil erKey);
  87           if  (instance  == null)
  88                instance  = new Jav aCompiler( context);
  89           re turn insta nce;
  90       }
  91  
  92       /** Th e current  version nu mber as a  string.
  93        */
  94       public  static St ring versi on() {
  95           re turn versi on("releas e");  // m m.nn.oo[-m ilestone]
  96       }
  97  
  98       /** Th e current  full versi on number  as a strin g.
  99        */
  100       public  static St ring fullV ersion() {
  101           re turn versi on("full") ; // mm.mm .oo[-miles tone]-buil d
  102       }
  103  
  104       privat e static f inal Strin g versionR BName = "c om.sun.too ls.javac.r esources.v ersion";
  105       privat e static R esourceBun dle versio nRB;
  106  
  107       privat e static S tring vers ion(String  key) {
  108           if  (versionR B == null)  {
  109                try {
  110                    vers ionRB = Re sourceBund le.getBund le(version RBName);
  111                } catch  (MissingRe sourceExce ption e) {
  112                    retu rn Log.get LocalizedS tring("ver sion.not.a vailable") ;
  113                }
  114           }
  115           tr y {
  116                return v ersionRB.g etString(k ey);
  117           }
  118           ca tch (Missi ngResource Exception  e) {
  119                return L og.getLoca lizedStrin g("version .not.avail able");
  120           }
  121       }
  122  
  123       /**
  124        * Con trol how t he compile r's latter  phases (a ttr, flow,  desugar,  generate)
  125        * are  connected . Each ind ividual fi le is proc essed by e ach phase  in turn,
  126        * but  with diff erent comp ile polici es, you ca n control  the order  in which
  127        * eac h class is  processed  through i ts next ph ase.
  128        *
  129        * <p> Generally  speaking,  the compil er will "f ail fast"  in the fac e of
  130        * err ors, altho ugh not ag gressively  so. flow,  desugar,  etc become  no-ops
  131        * onc e any erro rs have oc curred. No  attempt i s currentl y made to  determine
  132        * if  it might b e safe to  process a  class thro ugh its ne xt phase b ecause
  133        * it  does not d epend on a ny unrelat ed errors  that might  have occu rred.
  134        */
  135       protec ted static  enum Comp ilePolicy  {
  136           /* *
  137            *  Just attr ibute the  parse tree s.
  138            * /
  139           AT TR_ONLY,
  140  
  141           /* *
  142            *  Just attr ibute and  do flow an alysis on  the parse  trees.
  143            *  This shou ld catch m ost user e rrors.
  144            * /
  145           CH ECK_ONLY,
  146  
  147           /* *
  148            *  Attribute  everythin g, then do  flow anal ysis for e verything,
  149            *  then desu gar everyt hing, and  only then  generate o utput.
  150            *  This mean s no outpu t will be  generated  if there a re any
  151            *  errors in  any class es.
  152            * /
  153           SI MPLE,
  154  
  155           /* *
  156            *  Groups th e classes  for each s ource file  together,  then proc ess
  157            *  each grou p in a man ner equiva lent to th e {@code S IMPLE} pol icy.
  158            *  This mean s no outpu t will be  generated  if there a re any
  159            *  errors in  any of th e classes  in a sourc e file.
  160            * /
  161           BY _FILE,
  162  
  163           /* *
  164            *  Completel y process  each entry  on the to do list in  turn.
  165            *  -- this i s the same  for 1.5.
  166            *  Means out put might  be generat ed for som e classes  in a compi lation uni t
  167            *  and not o thers.
  168            * /
  169           BY _TODO;
  170  
  171           st atic Compi lePolicy d ecode(Stri ng option)  {
  172                if (opti on == null )
  173                    retu rn DEFAULT _COMPILE_P OLICY;
  174                else if  (option.eq uals("attr "))
  175                    retu rn ATTR_ON LY;
  176                else if  (option.eq uals("chec k"))
  177                    retu rn CHECK_O NLY;
  178                else if  (option.eq uals("simp le"))
  179                    retu rn SIMPLE;
  180                else if  (option.eq uals("byfi le"))
  181                    retu rn BY_FILE ;
  182                else if  (option.eq uals("byto do"))
  183                    retu rn BY_TODO ;
  184                else
  185                    retu rn DEFAULT _COMPILE_P OLICY;
  186           }
  187       }
  188  
  189       privat e static f inal Compi lePolicy D EFAULT_COM PILE_POLIC Y = Compil ePolicy.BY _TODO;
  190  
  191       protec ted static  enum Impl icitSource Policy {
  192           /* * Don't ge nerate or  process im plicitly r ead source  files. */
  193           NO NE,
  194           /* * Generate  classes f or implici tly read s ource file s. */
  195           CL ASS,
  196           /* * Like CLA SS, but ge nerate war nings if a nnotation  processing  occurs */
  197           UN SET;
  198  
  199           st atic Impli citSourceP olicy deco de(String  option) {
  200                if (opti on == null )
  201                    retu rn UNSET;
  202                else if  (option.eq uals("none "))
  203                    retu rn NONE;
  204                else if  (option.eq uals("clas s"))
  205                    retu rn CLASS;
  206                else
  207                    retu rn UNSET;
  208           }
  209       }
  210  
  211       /** Th e log to b e used for  error rep orting.
  212        */
  213       public  Log log;
  214  
  215       /** Fa ctory for  creating d iagnostic  objects
  216        */
  217       JCDiag nostic.Fac tory diagF actory;
  218  
  219       /** Th e tree fac tory modul e.
  220        */
  221       protec ted TreeMa ker make;
  222  
  223       /** Th e class re ader.
  224        */
  225       protec ted ClassR eader read er;
  226  
  227       /** Th e class wr iter.
  228        */
  229       protec ted ClassW riter writ er;
  230  
  231       /** Th e native h eader writ er.
  232        */
  233       protec ted JNIWri ter jniWri ter;
  234  
  235       /** Th e module f or the sym bol table  entry phas es.
  236        */
  237       protec ted Enter  enter;
  238  
  239       /** Th e symbol t able.
  240        */
  241       protec ted Symtab  syms;
  242  
  243       /** Th e language  version.
  244        */
  245       protec ted Source  source;
  246  
  247       /** Th e module f or code ge neration.
  248        */
  249       protec ted Gen ge n;
  250  
  251       /** Th e name tab le.
  252        */
  253       protec ted Names  names;
  254  
  255       /** Th e attribut or.
  256        */
  257       protec ted Attr a ttr;
  258  
  259       /** Th e attribut or.
  260        */
  261       protec ted Check  chk;
  262  
  263       /** Th e flow ana lyzer.
  264        */
  265       protec ted Flow f low;
  266  
  267       /** Th e type era ser.
  268        */
  269       protec ted TransT ypes trans Types;
  270  
  271       /** Th e syntacti c sugar de sweetener.
  272        */
  273       protec ted Lower  lower;
  274  
  275       /** Th e annotati on annotat or.
  276        */
  277       protec ted Annota te annotat e;
  278  
  279       /** Fo rce a comp letion fai lure on th is name
  280        */
  281       protec ted final  Name compl etionFailu reName;
  282  
  283       /** Ty pe utiliti es.
  284        */
  285       protec ted Types  types;
  286  
  287       /** Ac cess to fi le objects .
  288        */
  289       protec ted JavaFi leManager  fileManage r;
  290  
  291       /** Fa ctory for  parsers.
  292        */
  293       protec ted Parser Factory pa rserFactor y;
  294  
  295       /** Br oadcasting  listener  for progre ss events
  296        */
  297       protec ted MultiT askListene r taskList ener;
  298  
  299       /**
  300        * Ann otation pr ocessing m ay require  and provi de a new i nstance
  301        * of  the compil er to be u sed for th e analyze  and genera te phases.
  302        */
  303       protec ted JavaCo mpiler del egateCompi ler;
  304  
  305       /**
  306        * Sou rceComplet er that de legates to  the compl ete-method  of this c lass.
  307        */
  308       protec ted final  ClassReade r.SourceCo mpleter th isComplete r =
  309                new Clas sReader.So urceComple ter() {
  310                    @Ove rride
  311                    publ ic void co mplete(Cla ssSymbol s ym) throws  Completio nFailure {
  312                         JavaCompil er.this.co mplete(sym );
  313                    }
  314                };
  315  
  316       /**
  317        * Com mand line  options.
  318        */
  319       protec ted Option s options;
  320  
  321       protec ted Contex t context;
  322  
  323       /**
  324        * Fla g set if a ny annotat ion proces sing occur red.
  325        **/
  326       protec ted boolea n annotati onProcessi ngOccurred ;
  327  
  328       /**
  329        * Fla g set if a ny implici t source f iles read.
  330        **/
  331       protec ted boolea n implicit SourceFile sRead;
  332  
  333       protec ted Compil eStates co mpileState s;
  334  
  335       /** Co nstruct a  new compil er using a  shared co ntext.
  336        */
  337       public  JavaCompi ler(Contex t context)  {
  338           th is.context  = context ;
  339           co ntext.put( compilerKe y, this);
  340  
  341           //  if fileMa nager not  already se t, registe r the Java cFileManag er to be u sed
  342           if  (context. get(JavaFi leManager. class) ==  null)
  343                JavacFil eManager.p reRegister (context);
  344  
  345           na mes = Name s.instance (context);
  346           lo g = Log.in stance(con text);
  347           di agFactory  = JCDiagno stic.Facto ry.instanc e(context) ;
  348           re ader = Cla ssReader.i nstance(co ntext);
  349           ma ke = TreeM aker.insta nce(contex t);
  350           wr iter = Cla ssWriter.i nstance(co ntext);
  351           jn iWriter =  JNIWriter. instance(c ontext);
  352           en ter = Ente r.instance (context);
  353           to do = Todo. instance(c ontext);
  354  
  355           fi leManager  = context. get(JavaFi leManager. class);
  356           pa rserFactor y = Parser Factory.in stance(con text);
  357           co mpileState s = Compil eStates.in stance(con text);
  358  
  359           tr y {
  360                // catch  completio n problems  with pred efineds
  361                syms = S ymtab.inst ance(conte xt);
  362           }  catch (Com pletionFai lure ex) {
  363                // inlin ed Check.c ompletionE rror as it  is not in itialized  yet
  364                log.erro r("cant.ac cess", ex. sym, ex.ge tDetailVal ue());
  365                if (ex i nstanceof  ClassReade r.BadClass File)
  366                    thro w new Abor t();
  367           }
  368           so urce = Sou rce.instan ce(context );
  369           Ta rget targe t = Target .instance( context);
  370           at tr = Attr. instance(c ontext);
  371           ch k = Check. instance(c ontext);
  372           ge n = Gen.in stance(con text);
  373           fl ow = Flow. instance(c ontext);
  374           tr ansTypes =  TransType s.instance (context);
  375           lo wer = Lowe r.instance (context);
  376           an notate = A nnotate.in stance(con text);
  377           ty pes = Type s.instance (context);
  378           ta skListener  = MultiTa skListener .instance( context);
  379  
  380           re ader.sourc eCompleter  = thisCom pleter;
  381  
  382           op tions = Op tions.inst ance(conte xt);
  383  
  384           ve rbose        = option s.isSet(VE RBOSE);
  385           so urceOutput   = option s.isSet(PR INTSOURCE) ; // used  to be -s
  386           st ubOutput     = option s.isSet("- stubs");
  387           re lax          = option s.isSet("- relax");
  388           pr intFlat      = option s.isSet("- printflat" );
  389           at trParseOnl y = option s.isSet("- attrparseo nly");
  390           en coding       = option s.get(ENCO DING);
  391           li neDebugInf o = option s.isUnset( G_CUSTOM)  ||
  392                             option s.isSet(G_ CUSTOM, "l ines");
  393           ge nEndPos      = option s.isSet(XJ COV) ||
  394                             contex t.get(Diag nosticList ener.class ) != null;
  395           de vVerbose     = option s.isSet("d ev");
  396           pr ocessPcks    = option s.isSet("p rocess.pac kages");
  397           we rror         = option s.isSet(WE RROR);
  398  
  399           if  (source.c ompareTo(S ource.DEFA ULT) < 0)  {
  400                if (opti ons.isUnse t(XLINT_CU STOM, "-"  + LintCate gory.OPTIO NS.option) ) {
  401                    if ( fileManage r instance of BaseFil eManager)  {
  402                         if (((Base FileManage r) fileMan ager).isDe faultBootC lassPath() )
  403                             log.wa rning(Lint Category.O PTIONS, "s ource.no.b ootclasspa th", sourc e.name);
  404                    }
  405                }
  406           }
  407  
  408           ch eckForObso leteOption s(target);
  409  
  410           ve rboseCompi lePolicy =  options.i sSet("verb oseCompile Policy");
  411  
  412           if  (attrPars eOnly)
  413                compileP olicy = Co mpilePolic y.ATTR_ONL Y;
  414           el se
  415                compileP olicy = Co mpilePolic y.decode(o ptions.get ("compileP olicy"));
  416  
  417           im plicitSour cePolicy =  ImplicitS ourcePolic y.decode(o ptions.get ("-implici t"));
  418  
  419           co mpletionFa ilureName  =
  420                options. isSet("fai lcomplete" )
  421                ? names. fromString (options.g et("failco mplete"))
  422                : null;
  423  
  424           sh ouldStopPo licyIfErro r =
  425                options. isSet("sho uldStopPol icy") // b ackwards c ompatible
  426                ? Compil eState.val ueOf(optio ns.get("sh ouldStopPo licy"))
  427                : option s.isSet("s houldStopP olicyIfErr or")
  428                ? Compil eState.val ueOf(optio ns.get("sh ouldStopPo licyIfErro r"))
  429                : Compil eState.INI T;
  430           sh ouldStopPo licyIfNoEr ror =
  431                options. isSet("sho uldStopPol icyIfNoErr or")
  432                ? Compil eState.val ueOf(optio ns.get("sh ouldStopPo licyIfNoEr ror"))
  433                : Compil eState.GEN ERATE;
  434  
  435           if  (options. isUnset("o ldDiags"))
  436                log.setD iagnosticF ormatter(R ichDiagnos ticFormatt er.instanc e(context) );
  437       }
  438  
  439       privat e void che ckForObsol eteOptions (Target ta rget) {
  440           //  Unless li nt checkin g on optio ns is disa bled, chec k for
  441           //  obsolete  source and  target op tions.
  442           bo olean obso leteOption Found = fa lse;
  443           if  (options. isUnset(XL INT_CUSTOM , "-" + Li ntCategory .OPTIONS.o ption)) {
  444                if (sour ce.compare To(Source. JDK1_5) <=  0) {
  445                    log. warning(Li ntCategory .OPTIONS,  "option.ob solete.sou rce", sour ce.name);
  446                    obso leteOption Found = tr ue;
  447                }
  448  
  449                if (targ et.compare To(Target. JDK1_5) <=  0) {
  450                    log. warning(Li ntCategory .OPTIONS,  "option.ob solete.tar get", targ et.name);
  451                    obso leteOption Found = tr ue;
  452                }
  453  
  454                if (obso leteOption Found)
  455                    log. warning(Li ntCategory .OPTIONS,  "option.ob solete.sup pression") ;
  456           }
  457       }
  458  
  459       /* Swi tches:
  460        */
  461  
  462       /** Ve rbose outp ut.
  463        */
  464       public  boolean v erbose;
  465  
  466       /** Em it plain J ava source  files rat her than c lass files .
  467        */
  468       public  boolean s ourceOutpu t;
  469  
  470       /** Em it stub so urce files  rather th an class f iles.
  471        */
  472       public  boolean s tubOutput;
  473  
  474       /** Ge nerate att ributed pa rse tree o nly.
  475        */
  476       public  boolean a ttrParseOn ly;
  477  
  478       /** Sw itch: rela x some con straints f or produci ng the jsr 14 prototy pe.
  479        */
  480       boolea n relax;
  481  
  482       /** De bug switch : Emit Jav a sources  after inne r class fl attening.
  483        */
  484       public  boolean p rintFlat;
  485  
  486       /** Th e encoding  to be use d for sour ce input.
  487        */
  488       public  String en coding;
  489  
  490       /** Ge nerate cod e with the  LineNumbe rTable att ribute for  debugging
  491        */
  492       public  boolean l ineDebugIn fo;
  493  
  494       /** Sw itch: shou ld we stor e the endi ng positio ns?
  495        */
  496       public  boolean g enEndPos;
  497  
  498       /** Sw itch: shou ld we debu g ignored  exceptions
  499        */
  500       protec ted boolea n devVerbo se;
  501  
  502       /** Sw itch: shou ld we (ann otation) p rocess pac kages as w ell
  503        */
  504       protec ted boolea n processP cks;
  505  
  506       /** Sw itch: trea t warnings  as errors
  507        */
  508       protec ted boolea n werror;
  509  
  510       /** Sw itch: is a nnotation  processing  requested  explicitl y via
  511        * Com pilationTa sk.setProc essors?
  512        */
  513       protec ted boolea n explicit Annotation Processing Requested  = false;
  514  
  515       /**
  516        * The  policy fo r the orde r in which  to perfor m the comp ilation
  517        */
  518       protec ted Compil ePolicy co mpilePolic y;
  519  
  520       /**
  521        * The  policy fo r what to  do with im plicitly r ead source  files
  522        */
  523       protec ted Implic itSourcePo licy impli citSourceP olicy;
  524  
  525       /**
  526        * Rep ort activi ty related  to compil ePolicy
  527        */
  528       public  boolean v erboseComp ilePolicy;
  529  
  530       /**
  531        * Pol icy of how  far to co ntinue com pilation a fter error s have occ urred.
  532        * Set  this to m inimum Com pileState  (INIT) to  stop as so on as poss ible
  533        * aft er errors.
  534        */
  535       public  CompileSt ate should StopPolicy IfError;
  536  
  537       /**
  538        * Pol icy of how  far to co ntinue com pilation w hen no err ors have o ccurred.
  539        * Set  this to m aximum Com pileState  (GENERATE)  to perfor m full com pilation.
  540        * Set  this lowe r to perfo rm partial  compilati on, such a s -proc:on ly.
  541        */
  542       public  CompileSt ate should StopPolicy IfNoError;
  543  
  544       /** A  queue of a ll as yet  unattribut ed classes .
  545        */
  546       public  Todo todo ;
  547  
  548       /** A  list of it ems to be  closed whe n the comp ilation is  complete.
  549        */
  550       public  List<Clos eable> clo seables =  List.nil() ;
  551  
  552       /** Th e set of c urrently c ompiled in putfiles,  needed to  ensure
  553        *  we  don't acc identally  overwrite  an input f ile when - s is set.
  554        *  in itialized  by `compil e'.
  555        */
  556       protec ted Set<Ja vaFileObje ct> inputF iles = new  HashSet<J avaFileObj ect>();
  557  
  558       protec ted boolea n shouldSt op(Compile State cs)  {
  559           Co mpileState  shouldSto pPolicy =  (errorCoun t() > 0 ||  unrecover ableError( ))
  560                ? should StopPolicy IfError
  561                : should StopPolicy IfNoError;
  562           re turn cs.is After(shou ldStopPoli cy);
  563       }
  564  
  565       /** Th e number o f errors r eported so  far.
  566        */
  567       public  int error Count() {
  568           if  (delegate Compiler ! = null &&  delegateCo mpiler !=  this)
  569                return d elegateCom piler.erro rCount();
  570           el se {
  571                if (werr or && log. nerrors ==  0 && log. nwarnings  > 0) {
  572                    log. error("war nings.and. werror");
  573                }
  574           }
  575           re turn log.n errors;
  576       }
  577  
  578       protec ted final  <T> Queue< T> stopIfE rror(Compi leState cs , Queue<T>  queue) {
  579           re turn shoul dStop(cs)  ? new List Buffer<T>( ) : queue;
  580       }
  581  
  582       protec ted final  <T> List<T > stopIfEr ror(Compil eState cs,  List<T> l ist) {
  583           re turn shoul dStop(cs)  ? List.<T> nil() : li st;
  584       }
  585  
  586       /** Th e number o f warnings  reported  so far.
  587        */
  588       public  int warni ngCount()  {
  589           if  (delegate Compiler ! = null &&  delegateCo mpiler !=  this)
  590                return d elegateCom piler.warn ingCount() ;
  591           el se
  592                return l og.nwarnin gs;
  593       }
  594  
  595       /** Tr y to open  input stre am with gi ven name.
  596        *  Re port an er ror if thi s fails.
  597        *  @p aram filen ame   The  file name  of the inp ut stream  to be open ed.
  598        */
  599       public  CharSeque nce readSo urce(JavaF ileObject  filename)  {
  600           tr y {
  601                inputFil es.add(fil ename);
  602                return f ilename.ge tCharConte nt(false);
  603           }  catch (IOE xception e ) {
  604                log.erro r("error.r eading.fil e", filena me, JavacF ileManager .getMessag e(e));
  605                return n ull;
  606           }
  607       }
  608  
  609       /** Pa rse conten ts of inpu t stream.
  610        *  @p aram filen ame     Th e name of  the file f rom which  input stre am comes.
  611        *  @p aram conte nt      Th e characte rs to be p arsed.
  612        */
  613       protec ted JCComp ilationUni t parse(Ja vaFileObje ct filenam e, CharSeq uence cont ent) {
  614           lo ng msec =  now();
  615           JC Compilatio nUnit tree  = make.To pLevel(Lis t.<JCTree. JCAnnotati on>nil(),
  616                                            nu ll, List.< JCTree>nil ());
  617           if  (content  != null) {
  618                if (verb ose) {
  619                    log. printVerbo se("parsin g.started" , filename );
  620                }
  621                if (!tas kListener. isEmpty())  {
  622                    Task Event e =  new TaskEv ent(TaskEv ent.Kind.P ARSE, file name);
  623                    task Listener.s tarted(e);
  624                    keep Comments =  true;
  625                    genE ndPos = tr ue;
  626                }
  627                Parser p arser = pa rserFactor y.newParse r(content,  keepComme nts(), gen EndPos, li neDebugInf o);
  628                tree = p arser.pars eCompilati onUnit();
  629                if (verb ose) {
  630                    log. printVerbo se("parsin g.done", L ong.toStri ng(elapsed (msec)));
  631                }
  632           }
  633  
  634           tr ee.sourcef ile = file name;
  635  
  636           if  (content  != null &&  !taskList ener.isEmp ty()) {
  637                TaskEven t e = new  TaskEvent( TaskEvent. Kind.PARSE , tree);
  638                taskList ener.finis hed(e);
  639           }
  640  
  641           re turn tree;
  642       }
  643       // whe re
  644           pu blic boole an keepCom ments = fa lse;
  645           pr otected bo olean keep Comments()  {
  646                return k eepComment s || sourc eOutput ||  stubOutpu t;
  647           }
  648  
  649  
  650       /** Pa rse conten ts of file .
  651        *  @p aram filen ame     Th e name of  the file t o be parse d.
  652        */
  653       @Depre cated
  654       public  JCTree.JC Compilatio nUnit pars e(String f ilename) {
  655           Ja vacFileMan ager fm =  (JavacFile Manager)fi leManager;
  656           re turn parse (fm.getJav aFileObjec tsFromStri ngs(List.o f(filename )).iterato r().next() );
  657       }
  658  
  659       /** Pa rse conten ts of file .
  660        *  @p aram filen ame     Th e name of  the file t o be parse d.
  661        */
  662       public  JCTree.JC Compilatio nUnit pars e(JavaFile Object fil ename) {
  663           Ja vaFileObje ct prev =  log.useSou rce(filena me);
  664           tr y {
  665                JCTree.J CCompilati onUnit t =  parse(fil ename, rea dSource(fi lename));
  666                if (t.en dPositions  != null)
  667                    log. setEndPosT able(filen ame, t.end Positions) ;
  668                return t ;
  669           }  finally {
  670                log.useS ource(prev );
  671           }
  672       }
  673  
  674       /** Re solve an i dentifier  which may  be the bin ary name o f a class  or
  675        * the  Java name  of a clas s or packa ge.
  676        * @pa ram name       The na me to reso lve
  677        */
  678       public  Symbol re solveBinar yNameOrIde nt(String  name) {
  679           tr y {
  680                Name fla tname = na mes.fromSt ring(name. replace("/ ", "."));
  681                return r eader.load Class(flat name);
  682           }  catch (Com pletionFai lure ignor e) {
  683                return r esolveIden t(name);
  684           }
  685       }
  686  
  687       /** Re solve an i dentifier.
  688        * @pa ram name       The id entifier t o resolve
  689        */
  690       public  Symbol re solveIdent (String na me) {
  691           if  (name.equ als(""))
  692                return s yms.errSym bol;
  693           Ja vaFileObje ct prev =  log.useSou rce(null);
  694           tr y {
  695                JCExpres sion tree  = null;
  696                for (Str ing s : na me.split(" \\.", -1))  {
  697                    if ( !SourceVer sion.isIde ntifier(s) ) // TODO:  check for  keywords
  698                         return sym s.errSymbo l;
  699                    tree  = (tree = = null) ?  make.Ident (names.fro mString(s) )
  700                                            :  make.Selec t(tree, na mes.fromSt ring(s));
  701                }
  702                JCCompil ationUnit  toplevel =
  703                    make .TopLevel( List.<JCTr ee.JCAnnot ation>nil( ), null, L ist.<JCTre e>nil());
  704                toplevel .packge =  syms.unnam edPackage;
  705                return a ttr.attrib Ident(tree , toplevel );
  706           }  finally {
  707                log.useS ource(prev );
  708           }
  709       }
  710  
  711       /** Em it plain J ava source  for a cla ss.
  712        *  @p aram env     The attr ibution en vironment  of the out ermost cla ss
  713        *                  containi ng this cl ass.
  714        *  @p aram cdef    The clas s definiti on to be p rinted.
  715        */
  716       JavaFi leObject p rintSource (Env<AttrC ontext> en v, JCClass Decl cdef)  throws IO Exception  {
  717           Ja vaFileObje ct outFile
  718                = fileMa nager.getJ avaFileFor Output(CLA SS_OUTPUT,
  719                                                      cde f.sym.flat name.toStr ing(),
  720                                                      Jav aFileObjec t.Kind.SOU RCE,
  721                                                      nul l);
  722           if  (inputFil es.contain s(outFile) ) {
  723                log.erro r(cdef.pos (), "sourc e.cant.ove rwrite.inp ut.file",  outFile);
  724                return n ull;
  725           }  else {
  726                Buffered Writer out  = new Buf feredWrite r(outFile. openWriter ());
  727                try {
  728                    new  Pretty(out , true).pr intUnit(en v.toplevel , cdef);
  729                    if ( verbose)
  730                         log.printV erbose("wr ote.file",  outFile);
  731                } finall y {
  732                    out. close();
  733                }
  734                return o utFile;
  735           }
  736       }
  737  
  738       /** Ge nerate cod e and emit  a class f ile for a  given clas s
  739        *  @p aram env     The attr ibution en vironment  of the out ermost cla ss
  740        *                  containi ng this cl ass.
  741        *  @p aram cdef    The clas s definiti on from wh ich code i s generate d.
  742        */
  743       JavaFi leObject g enCode(Env <AttrConte xt> env, J CClassDecl  cdef) thr ows IOExce ption {
  744           tr y {
  745                if (gen. genClass(e nv, cdef)  && (errorC ount() ==  0))
  746                    retu rn writer. writeClass (cdef.sym) ;
  747           }  catch (Cla ssWriter.P oolOverflo w ex) {
  748                log.erro r(cdef.pos (), "limit .pool");
  749           }  catch (Cla ssWriter.S tringOverf low ex) {
  750                log.erro r(cdef.pos (), "limit .string.ov erflow",
  751                           ex.value .substring (0, 20));
  752           }  catch (Com pletionFai lure ex) {
  753                chk.comp letionErro r(cdef.pos (), ex);
  754           }
  755           re turn null;
  756       }
  757  
  758       /** Co mplete com piling a s ource file  that has  been acces sed
  759        *  by  the class  file read er.
  760        *  @p aram c           The  class the  source fil e of which  needs to  be compile d.
  761        */
  762       public  void comp lete(Class Symbol c)  throws Com pletionFai lure {
  763   //      Sy stem.err.p rintln("co mpleting "  + c);//DE BUG
  764           if  (completi onFailureN ame == c.f ullname) {
  765                throw ne w Completi onFailure( c, "user-s elected co mpletion f ailure by  class name ");
  766           }
  767           JC Compilatio nUnit tree ;
  768           Ja vaFileObje ct filenam e = c.clas sfile;
  769           Ja vaFileObje ct prev =  log.useSou rce(filena me);
  770  
  771           tr y {
  772                tree = p arse(filen ame, filen ame.getCha rContent(f alse));
  773           }  catch (IOE xception e ) {
  774                log.erro r("error.r eading.fil e", filena me, JavacF ileManager .getMessag e(e));
  775                tree = m ake.TopLev el(List.<J CTree.JCAn notation>n il(), null , List.<JC Tree>nil() );
  776           }  finally {
  777                log.useS ource(prev );
  778           }
  779  
  780           if  (!taskLis tener.isEm pty()) {
  781                TaskEven t e = new  TaskEvent( TaskEvent. Kind.ENTER , tree);
  782                taskList ener.start ed(e);
  783           }
  784  
  785           en ter.comple te(List.of (tree), c) ;
  786  
  787           if  (!taskLis tener.isEm pty()) {
  788                TaskEven t e = new  TaskEvent( TaskEvent. Kind.ENTER , tree);
  789                taskList ener.finis hed(e);
  790           }
  791  
  792           if  (enter.ge tEnv(c) ==  null) {
  793                boolean  isPkgInfo  =
  794                    tree .sourcefil e.isNameCo mpatible(" package-in fo",
  795                                                        J avaFileObj ect.Kind.S OURCE);
  796                if (isPk gInfo) {
  797                    if ( enter.getE nv(tree.pa ckge) == n ull) {
  798                         JCDiagnost ic diag =
  799                             diagFa ctory.frag ment("file .does.not. contain.pa ckage",
  800                                                        c .location( ));
  801                         throw read er.new Bad ClassFile( c, filenam e, diag);
  802                    }
  803                } else {
  804                    JCDi agnostic d iag =
  805                             diagFa ctory.frag ment("file .doesnt.co ntain.clas s",
  806                                                   c.getQ ualifiedNa me());
  807                    thro w reader.n ew BadClas sFile(c, f ilename, d iag);
  808                }
  809           }
  810  
  811           im plicitSour ceFilesRea d = true;
  812       }
  813  
  814       /** Tr ack when t he JavaCom piler has  been used  to compile  something . */
  815       privat e boolean  hasBeenUse d = false;
  816       privat e long sta rt_msec =  0;
  817       public  long elap sed_msec =  0;
  818  
  819       public  void comp ile(List<J avaFileObj ect> sourc eFileObjec t)
  820           th rows Throw able {
  821           co mpile(sour ceFileObje ct, List.< String>nil (), null);
  822       }
  823  
  824       /**
  825        * Mai n method:  compile a  list of fi les, retur n all comp iled class es
  826        *
  827        * @pa ram source FileObject s file obj ects to be  compiled
  828        * @pa ram classn ames class  names to  process fo r annotati ons
  829        * @pa ram proces sors user  provided a nnotation  processors  to bypass
  830        * dis covery, {@ code null}  means tha t no proce ssors were  provided
  831        */
  832       public  void comp ile(List<J avaFileObj ect> sourc eFileObjec ts,
  833                             List<S tring> cla ssnames,
  834                             Iterab le<? exten ds Process or> proces sors)
  835       {
  836           if  (processo rs != null  && proces sors.itera tor().hasN ext())
  837                explicit Annotation Processing Requested  = true;
  838           //  as a Java Compiler c an only be  used once , throw an  exception  if
  839           //  it has be en used be fore.
  840           if  (hasBeenU sed)
  841                throw ne w Assertio nError("at tempt to r euse JavaC ompiler");
  842           ha sBeenUsed  = true;
  843  
  844           //  forcibly  set the eq uivalent o f -Xlint:- options, s o that no  further
  845           //  warnings  about comm and line o ptions are  generated  from this  point on
  846           op tions.put( XLINT_CUST OM.text +  "-" + Lint Category.O PTIONS.opt ion, "true ");
  847           op tions.remo ve(XLINT_C USTOM.text  + LintCat egory.OPTI ONS.option );
  848  
  849           st art_msec =  now();
  850  
  851           tr y {
  852                initProc essAnnotat ions(proce ssors);
  853  
  854                // These  method ca lls must b e chained  to avoid m emory leak s
  855                delegate Compiler =
  856                    proc essAnnotat ions(
  857                         enterTrees (stopIfErr or(Compile State.PARS E, parseFi les(source FileObject s))),
  858                         classnames );
  859  
  860                delegate Compiler.c ompile2();
  861                delegate Compiler.c lose();
  862                elapsed_ msec = del egateCompi ler.elapse d_msec;
  863           }  catch (Abo rt ex) {
  864                if (devV erbose)
  865                    ex.p rintStackT race(Syste m.err);
  866           }  finally {
  867                if (proc EnvImpl !=  null)
  868                    proc EnvImpl.cl ose();
  869           }
  870       }
  871  
  872       /**
  873        * The  phases fo llowing an notation p rocessing:  attributi on,
  874        * des ugar, and  finally co de generat ion.
  875        */
  876       privat e void com pile2() {
  877           tr y {
  878                switch ( compilePol icy) {
  879                case ATT R_ONLY:
  880                    attr ibute(todo );
  881                    brea k;
  882  
  883                case CHE CK_ONLY:
  884                    flow (attribute (todo));
  885                    brea k;
  886  
  887                case SIM PLE:
  888                    gene rate(desug ar(flow(at tribute(to do))));
  889                    brea k;
  890  
  891                case BY_ FILE: {
  892                         Queue<Queu e<Env<Attr Context>>>  q = todo. groupByFil e();
  893                         while (!q. isEmpty()  && !should Stop(Compi leState.AT TR)) {
  894                             genera te(desugar (flow(attr ibute(q.re move())))) ;
  895                         }
  896                    }
  897                    brea k;
  898  
  899                case BY_ TODO:
  900                    whil e (!todo.i sEmpty())
  901                         generate(d esugar(flo w(attribut e(todo.rem ove()))));
  902                    brea k;
  903  
  904                default:
  905                    Asse rt.error(" unknown co mpile poli cy");
  906                }
  907           }  catch (Abo rt ex) {
  908                if (devV erbose)
  909                    ex.p rintStackT race(Syste m.err);
  910           }
  911  
  912           if  (verbose)  {
  913                elapsed_ msec = ela psed(start _msec);
  914                log.prin tVerbose(" total", Lo ng.toStrin g(elapsed_ msec));
  915           }
  916  
  917           re portDeferr edDiagnost ics();
  918  
  919           if  (!log.has Diagnostic Listener() ) {
  920                printCou nt("error" , errorCou nt());
  921                printCou nt("warn",  warningCo unt());
  922           }
  923       }
  924  
  925       /**
  926        * Set  needRootC lasses to  true, in J avaCompile r subclass  construct or
  927        * tha t want to  collect pu blic apis  of classes  supplied  on the com mand line.
  928        */
  929       protec ted boolea n needRoot Classes =  false;
  930  
  931       /**
  932        * The  list of c lasses exp licitly su pplied on  the comman d line for  compilati on.
  933        * Not  always po pulated.
  934        */
  935       privat e List<JCC lassDecl>  rootClasse s;
  936  
  937       /**
  938        * Par ses a list  of files.
  939        */
  940      public  List<JCCom pilationUn it> parseF iles(Itera ble<JavaFi leObject>  fileObject s) {
  941          if  (shouldSto p(CompileS tate.PARSE ))
  942               return Li st.nil();
  943  
  944           // parse all  files
  945           Li stBuffer<J CCompilati onUnit> tr ees = new  ListBuffer <>();
  946           Se t<JavaFile Object> fi lesSoFar =  new HashS et<JavaFil eObject>() ;
  947           fo r (JavaFil eObject fi leObject :  fileObjec ts) {
  948                if (!fil esSoFar.co ntains(fil eObject))  {
  949                    file sSoFar.add (fileObjec t);
  950                    tree s.append(p arse(fileO bject));
  951                }
  952           }
  953           re turn trees .toList();
  954       }
  955  
  956       /**
  957        * Ent er the sym bols found  in a list  of parse  trees if t he compila tion
  958        * is  expected t o proceed  beyond ann o processi ng into at tr.
  959        * As  a side-eff ect, this  puts eleme nts on the  "todo" li st.
  960        * Als o stores a  list of a ll top lev el classes  in rootCl asses.
  961        */
  962       public  List<JCCo mpilationU nit> enter TreesIfNee ded(List<J CCompilati onUnit> ro ots) {
  963          if  (shouldSto p(CompileS tate.ATTR) )
  964               return Li st.nil();
  965           re turn enter Trees(root s);
  966       }
  967  
  968       /**
  969        * Ent er the sym bols found  in a list  of parse  trees.
  970        * As  a side-eff ect, this  puts eleme nts on the  "todo" li st.
  971        * Als o stores a  list of a ll top lev el classes  in rootCl asses.
  972        */
  973       public  List<JCCo mpilationU nit> enter Trees(List <JCCompila tionUnit>  roots) {
  974           // enter symb ols for al l files
  975           if  (!taskLis tener.isEm pty()) {
  976                for (JCC ompilation Unit unit:  roots) {
  977                    Task Event e =  new TaskEv ent(TaskEv ent.Kind.E NTER, unit );
  978                    task Listener.s tarted(e);
  979                }
  980           }
  981  
  982           en ter.main(r oots);
  983  
  984           if  (!taskLis tener.isEm pty()) {
  985                for (JCC ompilation Unit unit:  roots) {
  986                    Task Event e =  new TaskEv ent(TaskEv ent.Kind.E NTER, unit );
  987                    task Listener.f inished(e) ;
  988                }
  989           }
  990  
  991           //  If genera ting sourc e, or if t racking pu blic apis,
  992           //  then reme mber the c lasses dec lared in
  993           //  the origi nal compil ation unit s listed o n the comm and line.
  994           if  (needRoot Classes ||  sourceOut put || stu bOutput) {
  995                ListBuff er<JCClass Decl> cdef s = new Li stBuffer<> ();
  996                for (JCC ompilation Unit unit  : roots) {
  997                    for  (List<JCTr ee> defs =  unit.defs ;
  998                          defs.nonE mpty();
  999                          defs = de fs.tail) {
  1000                         if (defs.h ead instan ceof JCCla ssDecl)
  1001                             cdefs. append((JC ClassDecl) defs.head) ;
  1002                    }
  1003                }
  1004                rootClas ses = cdef s.toList() ;
  1005           }
  1006  
  1007           //  Ensure th e input fi les have b een record ed. Althou gh this is  normally
  1008           //  done by r eadSource,  it may no t have bee n done if  the trees  were read
  1009           //  in a prio r round of  annotatio n processi ng, and th e trees ha ve been
  1010           //  cleaned a nd are bei ng reused.
  1011           fo r (JCCompi lationUnit  unit : ro ots) {
  1012                inputFil es.add(uni t.sourcefi le);
  1013           }
  1014  
  1015           re turn roots ;
  1016       }
  1017  
  1018       /**
  1019        * Set  to true t o enable s keleton an notation p rocessing  code.
  1020        * Cur rently, we  assume th is variabl e will be  replaced m ore
  1021        * adv anced logi c to figur e out if a nnotation  processing  is
  1022        * nee ded.
  1023        */
  1024       boolea n processA nnotations  = false;
  1025  
  1026       Log.De ferredDiag nosticHand ler deferr edDiagnost icHandler;
  1027  
  1028       /**
  1029        * Obj ect to han dle annota tion proce ssing.
  1030        */
  1031       privat e JavacPro cessingEnv ironment p rocEnvImpl  = null;
  1032  
  1033       /**
  1034        * Che ck if we s hould proc ess annota tions.
  1035        * If  so, and if  no scanne r is yet r egistered,  then set  up the Doc CommentSca nner
  1036        * to  catch doc  comments,  and set ke epComments  so the pa rser recor ds them in
  1037        * the  compilati on unit.
  1038        *
  1039        * @pa ram proces sors user  provided a nnotation  processors  to bypass
  1040        * dis covery, {@ code null}  means tha t no proce ssors were  provided
  1041        */
  1042       public  void init ProcessAnn otations(I terable<?  extends Pr ocessor> p rocessors)  {
  1043           //  Process a nnotations  if proces sing is no t disabled  and there
  1044           //  is at lea st one Pro cessor ava ilable.
  1045           if  (options. isSet(PROC , "none"))  {
  1046                processA nnotations  = false;
  1047           }  else if (p rocEnvImpl  == null)  {
  1048                procEnvI mpl = Java cProcessin gEnvironme nt.instanc e(context) ;
  1049                procEnvI mpl.setPro cessors(pr ocessors);
  1050                processA nnotations  = procEnv Impl.atLea stOneProce ssor();
  1051  
  1052                if (proc essAnnotat ions) {
  1053                    opti ons.put("s ave-parame ter-names" , "save-pa rameter-na mes");
  1054                    read er.savePar ameterName s = true;
  1055                    keep Comments =  true;
  1056                    genE ndPos = tr ue;
  1057                    if ( !taskListe ner.isEmpt y())
  1058                         taskListen er.started (new TaskE vent(TaskE vent.Kind. ANNOTATION _PROCESSIN G));
  1059                    defe rredDiagno sticHandle r = new Lo g.Deferred Diagnostic Handler(lo g);
  1060                } else {  // free r esources
  1061                    proc EnvImpl.cl ose();
  1062                }
  1063           }
  1064       }
  1065  
  1066       // TOD O: called  by JavacTa skImpl
  1067       public  JavaCompi ler proces sAnnotatio ns(List<JC Compilatio nUnit> roo ts) {
  1068           re turn proce ssAnnotati ons(roots,  List.<Str ing>nil()) ;
  1069       }
  1070  
  1071       /**
  1072        * Pro cess any a nnotations  found in  the specif ied compil ation unit s.
  1073        * @pa ram roots  a list of  compilatio n units
  1074        * @re turn an in stance of  the compil er in whic h to compl ete the co mpilation
  1075        */
  1076       // Imp lementatio n note: wh en this me thod is ca lled, log. deferredDi agnostics
  1077       // wil l have bee n set true  by initPr ocessAnnot ations, me aning that  any diagn ostics
  1078       // tha t are repo rted will  go into th e log.defe rredDiagno stics queu e.
  1079       // By  the time t his method  exits, lo g.deferDia gnostics m ust be set  back to f alse,
  1080       // and  all defer redDiagnos tics must  have been  handled: i .e. either  reported
  1081       // or  determined  to be tra nsient, an d therefor e suppress ed.
  1082       public  JavaCompi ler proces sAnnotatio ns(List<JC Compilatio nUnit> roo ts,
  1083                                                  List<St ring> clas snames) {
  1084           if  (shouldSt op(Compile State.PROC ESS)) {
  1085                // Error s were enc ountered.
  1086                // Unles s all the  errors are  resolve e rrors, the  errors we re parse e rrors
  1087                // or ot her errors  during en ter which  cannot be  fixed by r unning
  1088                // any a nnotation  processors .
  1089                if (unre coverableE rror()) {
  1090                    defe rredDiagno sticHandle r.reportDe ferredDiag nostics();
  1091                    log. popDiagnos ticHandler (deferredD iagnosticH andler);
  1092                    retu rn this;
  1093                }
  1094           }
  1095  
  1096           //  ASSERT: p rocessAnno tations an d procEnvI mpl should  have been  set up by
  1097           //  by initPr ocessAnnot ations
  1098  
  1099           //  NOTE: The  !classnam es.isEmpty () checks  should be  refactored  to Main.
  1100  
  1101           if  (!process Annotation s) {
  1102                // If th ere are no  annotatio n processo rs present , and
  1103                // annot ation proc essing is  to occur w ith compil ation,
  1104                // emit  a warning.
  1105                if (opti ons.isSet( PROC, "onl y")) {
  1106                    log. warning("p roc.proc-o nly.reques ted.no.pro cs");
  1107                    todo .clear();
  1108                }
  1109                // If no t processi ng annotat ions, clas snames mus t be empty
  1110                if (!cla ssnames.is Empty()) {
  1111                    log. error("pro c.no.expli cit.annota tion.proce ssing.requ ested",
  1112                               clas snames);
  1113                }
  1114                Assert.c heckNull(d eferredDia gnosticHan dler);
  1115                return t his; // co ntinue reg ular compi lation
  1116           }
  1117  
  1118           As sert.check NonNull(de ferredDiag nosticHand ler);
  1119  
  1120           tr y {
  1121                List<Cla ssSymbol>  classSymbo ls = List. nil();
  1122                List<Pac kageSymbol > pckSymbo ls = List. nil();
  1123                if (!cla ssnames.is Empty()) {
  1124                     //  Check for  explicit r equest for  annotatio n
  1125                     //  processing
  1126                    if ( !explicitA nnotationP rocessingR equested() ) {
  1127                         log.error( "proc.no.e xplicit.an notation.p rocessing. requested" ,
  1128                                    classnames );
  1129                         deferredDi agnosticHa ndler.repo rtDeferred Diagnostic s();
  1130                         log.popDia gnosticHan dler(defer redDiagnos ticHandler );
  1131                         return thi s; // TODO : Will thi s halt com pilation?
  1132                    } el se {
  1133                         boolean er rors = fal se;
  1134                         for (Strin g nameStr  : classnam es) {
  1135                             Symbol  sym = res olveBinary NameOrIden t(nameStr) ;
  1136                             if (sy m == null  ||
  1137                                 (s ym.kind ==  Kinds.PCK  && !proce ssPcks) ||
  1138                                 sy m.kind ==  Kinds.ABSE NT_TYP) {
  1139                                 lo g.error("p roc.cant.f ind.class" , nameStr) ;
  1140                                 er rors = tru e;
  1141                                 co ntinue;
  1142                             }
  1143                             try {
  1144                                 if  (sym.kind  == Kinds. PCK)
  1145                                      sym.comp lete();
  1146                                 if  (sym.exis ts()) {
  1147                                      if (sym. kind == Ki nds.PCK)
  1148                                          pckS ymbols = p ckSymbols. prepend((P ackageSymb ol)sym);
  1149                                      else
  1150                                          clas sSymbols =  classSymb ols.prepen d((ClassSy mbol)sym);
  1151                                      continue ;
  1152                                 }
  1153                                 As sert.check (sym.kind  == Kinds.P CK);
  1154                                 lo g.warning( "proc.pack age.does.n ot.exist",  nameStr);
  1155                                 pc kSymbols =  pckSymbol s.prepend( (PackageSy mbol)sym);
  1156                             } catc h (Complet ionFailure  e) {
  1157                                 lo g.error("p roc.cant.f ind.class" , nameStr) ;
  1158                                 er rors = tru e;
  1159                                 co ntinue;
  1160                             }
  1161                         }
  1162                         if (errors ) {
  1163                             deferr edDiagnost icHandler. reportDefe rredDiagno stics();
  1164                             log.po pDiagnosti cHandler(d eferredDia gnosticHan dler);
  1165                             return  this;
  1166                         }
  1167                    }
  1168                }
  1169                try {
  1170                    Java Compiler c  = procEnv Impl.doPro cessing(co ntext, roo ts, classS ymbols, pc kSymbols,
  1171                             deferr edDiagnost icHandler) ;
  1172                    if ( c != this)
  1173                         annotation Processing Occurred =  c.annotat ionProcess ingOccurre d = true;
  1174                    // d oProcessin g will hav e handled  deferred d iagnostics
  1175                    retu rn c;
  1176                } finall y {
  1177                    proc EnvImpl.cl ose();
  1178                }
  1179           }  catch (Com pletionFai lure ex) {
  1180                log.erro r("cant.ac cess", ex. sym, ex.ge tDetailVal ue());
  1181                deferred Diagnostic Handler.re portDeferr edDiagnost ics();
  1182                log.popD iagnosticH andler(def erredDiagn osticHandl er);
  1183                return t his;
  1184           }
  1185       }
  1186  
  1187       privat e boolean  unrecovera bleError()  {
  1188           if  (deferred Diagnostic Handler !=  null) {
  1189                for (JCD iagnostic  d: deferre dDiagnosti cHandler.g etDiagnost ics()) {
  1190                    if ( d.getKind( ) == JCDia gnostic.Ki nd.ERROR & & !d.isFla gSet(RECOV ERABLE))
  1191                         return tru e;
  1192                }
  1193           }
  1194           re turn false ;
  1195       }
  1196  
  1197       boolea n explicit Annotation Processing Requested( ) {
  1198           re turn
  1199                explicit Annotation Processing Requested  ||
  1200                explicit Annotation Processing Requested( options);
  1201       }
  1202  
  1203       static  boolean e xplicitAnn otationPro cessingReq uested(Opt ions optio ns) {
  1204           re turn
  1205                options. isSet(PROC ESSOR) ||
  1206                options. isSet(PROC ESSORPATH)  ||
  1207                options. isSet(PROC , "only")  ||
  1208                options. isSet(XPRI NT);
  1209       }
  1210  
  1211       /**
  1212        * Att ribute a l ist of par se trees,  such as fo und on the  "todo" li st.
  1213        * Not e that att ributing c lasses may  cause add itional fi les to be
  1214        * par sed and en tered via  the Source Completer.
  1215        * Att ribution o f the entr ies in the  list does  not stop  if any err ors occur.
  1216        * @re turns a li st of envi ronments f or attribu td classes .
  1217        */
  1218       public  Queue<Env <AttrConte xt>> attri bute(Queue <Env<AttrC ontext>> e nvs) {
  1219           Li stBuffer<E nv<AttrCon text>> res ults = new  ListBuffe r<>();
  1220           wh ile (!envs .isEmpty() )
  1221                results. append(att ribute(env s.remove() ));
  1222           re turn stopI fError(Com pileState. ATTR, resu lts);
  1223       }
  1224  
  1225       /**
  1226        * Att ribute a p arse tree.
  1227        * @re turns the  attributed  parse tre e
  1228        */
  1229       public  Env<AttrC ontext> at tribute(En v<AttrCont ext> env)  {
  1230           if  (compileS tates.isDo ne(env, Co mpileState .ATTR))
  1231                return e nv;
  1232  
  1233           if  (verboseC ompilePoli cy)
  1234                printNot e("[attrib ute " + en v.enclClas s.sym + "] ");
  1235           if  (verbose)
  1236                log.prin tVerbose(" checking.a ttribution ", env.enc lClass.sym );
  1237  
  1238           if  (!taskLis tener.isEm pty()) {
  1239                TaskEven t e = new  TaskEvent( TaskEvent. Kind.ANALY ZE, env.to plevel, en v.enclClas s.sym);
  1240                taskList ener.start ed(e);
  1241           }
  1242  
  1243           Ja vaFileObje ct prev =  log.useSou rce(
  1244                                        env.en clClass.sy m.sourcefi le != null  ?
  1245                                        env.en clClass.sy m.sourcefi le :
  1246                                        env.to plevel.sou rcefile);
  1247           tr y {
  1248                attr.att rib(env);
  1249                if (erro rCount() >  0 && !sho uldStop(Co mpileState .ATTR)) {
  1250                    //if  in fail-o ver mode,  ensure tha t AST expr ession nod es
  1251                    //ar e correctl y initiali zed (e.g.  they have  a type/sym bol)
  1252                    attr .postAttr( env.tree);
  1253                }
  1254                compileS tates.put( env, Compi leState.AT TR);
  1255                if (root Classes !=  null && r ootClasses .contains( env.enclCl ass)) {
  1256                    // T his was a  class that  was expli citly supp lied for c ompilation .
  1257                    // I f we want  to capture  the publi c api of t his class,
  1258                    // t hen now is  a good ti me to do i t.
  1259                    repo rtPublicAp i(env.encl Class.sym) ;
  1260                }
  1261           }
  1262           fi nally {
  1263                log.useS ource(prev );
  1264           }
  1265  
  1266           re turn env;
  1267       }
  1268  
  1269       /** Re port the p ublic api  of a class  that was  supplied e xplicitly  for compil ation,
  1270        *  fo r example  on the com mand line  to javac.
  1271        * @pa ram sym Th e symbol o f the clas s.
  1272        */
  1273       public  void repo rtPublicAp i(ClassSym bol sym) {
  1274          //  Override t o collect  the report ed public  api.
  1275       }
  1276  
  1277       /**
  1278        * Per form dataf low checks  on attrib uted parse  trees.
  1279        * The se include  checks fo r definite  assignmen t and unre achable st atements.
  1280        * If  any errors  occur, an  empty lis t will be  returned.
  1281        * @re turns the  list of at tributed p arse trees
  1282        */
  1283       public  Queue<Env <AttrConte xt>> flow( Queue<Env< AttrContex t>> envs)  {
  1284           Li stBuffer<E nv<AttrCon text>> res ults = new  ListBuffe r<>();
  1285           fo r (Env<Att rContext>  env: envs)  {
  1286                flow(env , results) ;
  1287           }
  1288           re turn stopI fError(Com pileState. FLOW, resu lts);
  1289       }
  1290  
  1291       /**
  1292        * Per form dataf low checks  on an att ributed pa rse tree.
  1293        */
  1294       public  Queue<Env <AttrConte xt>> flow( Env<AttrCo ntext> env ) {
  1295           Li stBuffer<E nv<AttrCon text>> res ults = new  ListBuffe r<>();
  1296           fl ow(env, re sults);
  1297           re turn stopI fError(Com pileState. FLOW, resu lts);
  1298       }
  1299  
  1300       /**
  1301        * Per form dataf low checks  on an att ributed pa rse tree.
  1302        */
  1303       protec ted void f low(Env<At trContext>  env, Queu e<Env<Attr Context>>  results) {
  1304           if  (compileS tates.isDo ne(env, Co mpileState .FLOW)) {
  1305                results. add(env);
  1306                return;
  1307           }
  1308  
  1309           tr y {
  1310                if (shou ldStop(Com pileState. FLOW))
  1311                    retu rn;
  1312  
  1313                if (rela x) {
  1314                    resu lts.add(en v);
  1315                    retu rn;
  1316                }
  1317  
  1318                if (verb oseCompile Policy)
  1319                    prin tNote("[fl ow " + env .enclClass .sym + "]" );
  1320                JavaFile Object pre v = log.us eSource(
  1321                                                       en v.enclClas s.sym.sour cefile !=  null ?
  1322                                                       en v.enclClas s.sym.sour cefile :
  1323                                                       en v.toplevel .sourcefil e);
  1324                try {
  1325                    make .at(Positi on.FIRSTPO S);
  1326                    Tree Maker loca lMake = ma ke.forTopl evel(env.t oplevel);
  1327                    flow .analyzeTr ee(env, lo calMake);
  1328                    comp ileStates. put(env, C ompileStat e.FLOW);
  1329  
  1330                    if ( shouldStop (CompileSt ate.FLOW))
  1331                         return;
  1332  
  1333                    resu lts.add(en v);
  1334                }
  1335                finally  {
  1336                    log. useSource( prev);
  1337                }
  1338           }
  1339           fi nally {
  1340                if (!tas kListener. isEmpty())  {
  1341                    Task Event e =  new TaskEv ent(TaskEv ent.Kind.A NALYZE, en v.toplevel , env.encl Class.sym) ;
  1342                    task Listener.f inished(e) ;
  1343                }
  1344           }
  1345       }
  1346  
  1347       /**
  1348        * Pre pare attri buted pars e trees, i n conjunct ion with t heir attri bution con texts,
  1349        * for  source or  code gene ration.
  1350        * If  any errors  occur, an  empty lis t will be  returned.
  1351        * @re turns a li st contain ing the cl asses to b e generate d
  1352        */
  1353       public  Queue<Pai r<Env<Attr Context>,  JCClassDec l>> desuga r(Queue<En v<AttrCont ext>> envs ) {
  1354           Li stBuffer<P air<Env<At trContext> , JCClassD ecl>> resu lts = new  ListBuffer <>();
  1355           fo r (Env<Att rContext>  env: envs)
  1356                desugar( env, resul ts);
  1357           re turn stopI fError(Com pileState. FLOW, resu lts);
  1358       }
  1359  
  1360       HashMa p<Env<Attr Context>,  Queue<Pair <Env<AttrC ontext>, J CClassDecl >>> desuga redEnvs =
  1361                new Hash Map<Env<At trContext> , Queue<Pa ir<Env<Att rContext>,  JCClassDe cl>>>();
  1362  
  1363       /**
  1364        * Pre pare attri buted pars e trees, i n conjunct ion with t heir attri bution con texts,
  1365        * for  source or  code gene ration. If  the file  was not li sted on th e command  line,
  1366        * the  current i mplicitSou rcePolicy  is taken i nto accoun t.
  1367        * The  preparati on stops a s soon as  an error i s found.
  1368        */
  1369       protec ted void d esugar(fin al Env<Att rContext>  env, Queue <Pair<Env< AttrContex t>, JCClas sDecl>> re sults) {
  1370           if  (shouldSt op(Compile State.TRAN STYPES))
  1371                return;
  1372  
  1373           if  (implicit SourcePoli cy == Impl icitSource Policy.NON E
  1374                    && ! inputFiles .contains( env.toplev el.sourcef ile)) {
  1375                return;
  1376           }
  1377  
  1378           if  (compileS tates.isDo ne(env, Co mpileState .LOWER)) {
  1379                results. addAll(des ugaredEnvs .get(env)) ;
  1380                return;
  1381           }
  1382  
  1383           /* *
  1384            *  Ensure th at supercl asses of C  are desug ared befor e C itself . This is
  1385            *  required  for two re asons: (i)  as erasur e (TransTy pes) destr oys
  1386            *  informati on needed  in flow an alysis and  (ii) as s ome checks  carried
  1387            *  out durin g lowering  require t hat all sy nthetic fi elds/metho ds have
  1388            *  already b een added  to C and i ts supercl asses.
  1389            * /
  1390           cl ass ScanNe sted exten ds TreeSca nner {
  1391                Set<Env< AttrContex t>> depend encies = n ew LinkedH ashSet<Env <AttrConte xt>>();
  1392                protecte d boolean  hasLambdas ;
  1393                @Overrid e
  1394                public v oid visitC lassDef(JC ClassDecl  node) {
  1395                    Type  st = type s.supertyp e(node.sym .type);
  1396                    bool ean envFor SuperTypeF ound = fal se;
  1397                    whil e (!envFor SuperTypeF ound && st .hasTag(CL ASS)) {
  1398                         ClassSymbo l c = st.t sym.outerm ostClass() ;
  1399                         Env<AttrCo ntext> stE nv = enter .getEnv(c) ;
  1400                         if (stEnv  != null &&  env != st Env) {
  1401                             if (de pendencies .add(stEnv )) {
  1402                                 bo olean prev HasLambdas  = hasLamb das;
  1403                                 tr y {
  1404                                      scan(stE nv.tree);
  1405                                 }  finally {
  1406                                      /*
  1407                                       * ignor e any upda tes to has Lambdas ma de during
  1408                                       * the n ested scan , this ens ures an in italized
  1409                                       * Lambd aToMethod  is availab le only to  those
  1410                                       * class es that co ntain lamb das
  1411                                       */
  1412                                      hasLambd as = prevH asLambdas;
  1413                                 }
  1414                             }
  1415                             envFor SuperTypeF ound = tru e;
  1416                         }
  1417                         st = types .supertype (st);
  1418                    }
  1419                    supe r.visitCla ssDef(node );
  1420                }
  1421                @Overrid e
  1422                public v oid visitL ambda(JCLa mbda tree)  {
  1423                    hasL ambdas = t rue;
  1424                    supe r.visitLam bda(tree);
  1425                }
  1426                @Overrid e
  1427                public v oid visitR eference(J CMemberRef erence tre e) {
  1428                    hasL ambdas = t rue;
  1429                    supe r.visitRef erence(tre e);
  1430                }
  1431           }
  1432           Sc anNested s canner = n ew ScanNes ted();
  1433           sc anner.scan (env.tree) ;
  1434           fo r (Env<Att rContext>  dep: scann er.depende ncies) {
  1435           if  (!compile States.isD one(dep, C ompileStat e.FLOW))
  1436                desugare dEnvs.put( dep, desug ar(flow(at tribute(de p))));
  1437           }
  1438  
  1439           // We need to  check for  error ano ther time  as more cl asses migh t
  1440           // have been  attributed  and analy zed at thi s stage
  1441           if  (shouldSt op(Compile State.TRAN STYPES))
  1442                return;
  1443  
  1444           if  (verboseC ompilePoli cy)
  1445                printNot e("[desuga r " + env. enclClass. sym + "]") ;
  1446  
  1447           Ja vaFileObje ct prev =  log.useSou rce(env.en clClass.sy m.sourcefi le != null  ?
  1448                                        env.en clClass.sy m.sourcefi le :
  1449                                        env.to plevel.sou rcefile);
  1450           tr y {
  1451                //save t ree prior  to rewriti ng
  1452                JCTree u ntranslate d = env.tr ee;
  1453  
  1454                make.at( Position.F IRSTPOS);
  1455                TreeMake r localMak e = make.f orToplevel (env.tople vel);
  1456  
  1457                if (env. tree insta nceof JCCo mpilationU nit) {
  1458                    if ( !(stubOutp ut || sour ceOutput | | printFla t)) {
  1459                         if (should Stop(Compi leState.LO WER))
  1460                             return ;
  1461                         List<JCTre e> pdef =  lower.tran slateTopLe velClass(e nv, env.tr ee, localM ake);
  1462                         if (pdef.h ead != nul l) {
  1463                             Assert .check(pde f.tail.isE mpty());
  1464                             result s.add(new  Pair<Env<A ttrContext >, JCClass Decl>(env,  (JCClassD ecl)pdef.h ead));
  1465                         }
  1466                    }
  1467                    retu rn;
  1468                }
  1469  
  1470                if (stub Output) {
  1471                    //em it stub Ja va source  file, only  for compi lation
  1472                    //un its enumer ated expli citly on t he command  line
  1473                    JCCl assDecl cd ef = (JCCl assDecl)en v.tree;
  1474                    if ( untranslat ed instanc eof JCClas sDecl &&
  1475                         rootClasse s.contains ((JCClassD ecl)untran slated) &&
  1476                         ((cdef.mod s.flags &  (Flags.PRO TECTED|Fla gs.PUBLIC) ) != 0 ||
  1477                          cdef.sym. packge().g etQualifie dName() ==  names.jav a_lang)) {
  1478                         results.ad d(new Pair <Env<AttrC ontext>, J CClassDecl >(env, rem oveMethodB odies(cdef )));
  1479                    }
  1480                    retu rn;
  1481                }
  1482  
  1483                if (shou ldStop(Com pileState. TRANSTYPES ))
  1484                    retu rn;
  1485  
  1486                env.tree  = transTy pes.transl ateTopLeve lClass(env .tree, loc alMake);
  1487                compileS tates.put( env, Compi leState.TR ANSTYPES);
  1488  
  1489                if (sour ce.allowLa mbda() &&  scanner.ha sLambdas)  {
  1490                    if ( shouldStop (CompileSt ate.UNLAMB DA))
  1491                         return;
  1492  
  1493                    env. tree = Lam bdaToMetho d.instance (context). translateT opLevelCla ss(env, en v.tree, lo calMake);
  1494                    comp ileStates. put(env, C ompileStat e.UNLAMBDA );
  1495                }
  1496  
  1497                if (shou ldStop(Com pileState. LOWER))
  1498                    retu rn;
  1499  
  1500                if (sour ceOutput)  {
  1501                    //em it standar d Java sou rce file,  only for c ompilation
  1502                    //un its enumer ated expli citly on t he command  line
  1503                    JCCl assDecl cd ef = (JCCl assDecl)en v.tree;
  1504                    if ( untranslat ed instanc eof JCClas sDecl &&
  1505                         rootClasse s.contains ((JCClassD ecl)untran slated)) {
  1506                         results.ad d(new Pair <Env<AttrC ontext>, J CClassDecl >(env, cde f));
  1507                    }
  1508                    retu rn;
  1509                }
  1510  
  1511                //transl ate out in ner classe s
  1512                List<JCT ree> cdefs  = lower.t ranslateTo pLevelClas s(env, env .tree, loc alMake);
  1513                compileS tates.put( env, Compi leState.LO WER);
  1514  
  1515                if (shou ldStop(Com pileState. LOWER))
  1516                    retu rn;
  1517  
  1518                //genera te code fo r each cla ss
  1519                for (Lis t<JCTree>  l = cdefs;  l.nonEmpt y(); l = l .tail) {
  1520                    JCCl assDecl cd ef = (JCCl assDecl)l. head;
  1521                    resu lts.add(ne w Pair<Env <AttrConte xt>, JCCla ssDecl>(en v, cdef));
  1522                }
  1523           }
  1524           fi nally {
  1525                log.useS ource(prev );
  1526           }
  1527  
  1528       }
  1529  
  1530       /** Ge nerates th e source o r class fi le for a l ist of cla sses.
  1531        * The  decision  to generat e a source  file or a  class fil e is
  1532        * bas ed upon th e compiler 's options .
  1533        * Gen eration st ops if an  error occu rs while w riting fil es.
  1534        */
  1535       public  void gene rate(Queue <Pair<Env< AttrContex t>, JCClas sDecl>> qu eue) {
  1536           ge nerate(que ue, null);
  1537       }
  1538  
  1539       public  void gene rate(Queue <Pair<Env< AttrContex t>, JCClas sDecl>> qu eue, Queue <JavaFileO bject> res ults) {
  1540           if  (shouldSt op(Compile State.GENE RATE))
  1541                return;
  1542  
  1543           bo olean useP rintSource  = (stubOu tput || so urceOutput  || printF lat);
  1544  
  1545           fo r (Pair<En v<AttrCont ext>, JCCl assDecl> x : queue) {
  1546                Env<Attr Context> e nv = x.fst ;
  1547                JCClassD ecl cdef =  x.snd;
  1548  
  1549                if (verb oseCompile Policy) {
  1550                    prin tNote("[ge nerate "
  1551                                     + (usePri ntSource ?  " source"  : "code")
  1552                                     + " " + c def.sym +  "]");
  1553                }
  1554  
  1555                if (!tas kListener. isEmpty())  {
  1556                    Task Event e =  new TaskEv ent(TaskEv ent.Kind.G ENERATE, e nv.topleve l, cdef.sy m);
  1557                    task Listener.s tarted(e);
  1558                }
  1559  
  1560                JavaFile Object pre v = log.us eSource(en v.enclClas s.sym.sour cefile !=  null ?
  1561                                            en v.enclClas s.sym.sour cefile :
  1562                                            en v.toplevel .sourcefil e);
  1563                try {
  1564                    Java FileObject  file;
  1565                    if ( usePrintSo urce)
  1566                         file = pri ntSource(e nv, cdef);
  1567                    else  {
  1568                         if (fileMa nager.hasL ocation(St andardLoca tion.NATIV E_HEADER_O UTPUT)
  1569                                 &&  jniWriter .needsHead er(cdef.sy m)) {
  1570                             jniWri ter.write( cdef.sym);
  1571                         }
  1572                         file = gen Code(env,  cdef);
  1573                    }
  1574                    if ( results !=  null && f ile != nul l)
  1575                         results.ad d(file);
  1576                } catch  (IOExcepti on ex) {
  1577                    log. error(cdef .pos(), "c lass.cant. write",
  1578                               cdef .sym, ex.g etMessage( ));
  1579                    retu rn;
  1580                } finall y {
  1581                    log. useSource( prev);
  1582                }
  1583  
  1584                if (!tas kListener. isEmpty())  {
  1585                    Task Event e =  new TaskEv ent(TaskEv ent.Kind.G ENERATE, e nv.topleve l, cdef.sy m);
  1586                    task Listener.f inished(e) ;
  1587                }
  1588           }
  1589       }
  1590  
  1591           //  where
  1592           Ma p<JCCompil ationUnit,  Queue<Env <AttrConte xt>>> grou pByFile(Qu eue<Env<At trContext> > envs) {
  1593                // use a  LinkedHas hMap to pr eserve the  order of  the origin al list as  much as p ossible
  1594                Map<JCCo mpilationU nit, Queue <Env<AttrC ontext>>>  map = new  LinkedHash Map<JCComp ilationUni t, Queue<E nv<AttrCon text>>>();
  1595                for (Env <AttrConte xt> env: e nvs) {
  1596                    Queu e<Env<Attr Context>>  sublist =  map.get(en v.toplevel );
  1597                    if ( sublist ==  null) {
  1598                         sublist =  new ListBu ffer<Env<A ttrContext >>();
  1599                         map.put(en v.toplevel , sublist) ;
  1600                    }
  1601                    subl ist.add(en v);
  1602                }
  1603                return m ap;
  1604           }
  1605  
  1606           JC ClassDecl  removeMeth odBodies(J CClassDecl  cdef) {
  1607                final bo olean isIn terface =  (cdef.mods .flags & F lags.INTER FACE) != 0 ;
  1608                class Me thodBodyRe mover exte nds TreeTr anslator {
  1609                    @Ove rride
  1610                    publ ic void vi sitMethodD ef(JCMetho dDecl tree ) {
  1611                         tree.mods. flags &= ~ Flags.SYNC HRONIZED;
  1612                         for (JCVar iableDecl  vd : tree. params)
  1613                             vd.mod s.flags &=  ~Flags.FI NAL;
  1614                         tree.body  = null;
  1615                         super.visi tMethodDef (tree);
  1616                    }
  1617                    @Ove rride
  1618                    publ ic void vi sitVarDef( JCVariable Decl tree)  {
  1619                         if (tree.i nit != nul l && tree. init.type. constValue () == null )
  1620                             tree.i nit = null ;
  1621                         super.visi tVarDef(tr ee);
  1622                    }
  1623                    @Ove rride
  1624                    publ ic void vi sitClassDe f(JCClassD ecl tree)  {
  1625                         ListBuffer <JCTree> n ewdefs = n ew ListBuf fer<>();
  1626                         for (List< JCTree> it  = tree.de fs; it.tai l != null;  it = it.t ail) {
  1627                             JCTree  t = it.he ad;
  1628                             switch  (t.getTag ()) {
  1629                             case C LASSDEF:
  1630                                 if  (isInterf ace ||
  1631                                      (((JCCla ssDecl) t) .mods.flag s & (Flags .PROTECTED |Flags.PUB LIC)) != 0  ||
  1632                                      (((JCCla ssDecl) t) .mods.flag s & (Flags .PRIVATE))  == 0 && ( (JCClassDe cl) t).sym .packge(). getQualifi edName() = = names.ja va_lang)
  1633                                      newdefs. append(t);
  1634                                 br eak;
  1635                             case M ETHODDEF:
  1636                                 if  (isInterf ace ||
  1637                                      (((JCMet hodDecl) t ).mods.fla gs & (Flag s.PROTECTE D|Flags.PU BLIC)) !=  0 ||
  1638                                      ((JCMeth odDecl) t) .sym.name  == names.i nit ||
  1639                                      (((JCMet hodDecl) t ).mods.fla gs & (Flag s.PRIVATE) ) == 0 &&  ((JCMethod Decl) t).s ym.packge( ).getQuali fiedName()  == names. java_lang)
  1640                                      newdefs. append(t);
  1641                                 br eak;
  1642                               case 
D NS    F:
  1643                                 if  (isInterf ace || ((( JCVariable Decl) t).m ods.flags  & (Flags.P ROTECTED|F lags.PUBLI C)) != 0 | |
  1644                                      (((JCVar iableDecl)  t).mods.f lags & (Fl ags.PRIVAT E)) == 0 & & ((JCVari ableDecl)  t).sym.pac kge().getQ ualifiedNa me() == na mes.java_l ang)
  1645                                      newdefs. append(t);
  1646                                 br eak;
  1647                             defaul t:
  1648                                 br eak;
  1649                             }
  1650                         }
  1651                         tree.defs  = newdefs. toList();
  1652                         super.visi tClassDef( tree);
  1653                    }
  1654                }
  1655                MethodBo dyRemover  r = new Me thodBodyRe mover();
  1656                return r .translate (cdef);
  1657           }
  1658  
  1659       public  void repo rtDeferred Diagnostic s() {
  1660           if  (errorCou nt() == 0
  1661                    && a nnotationP rocessingO ccurred
  1662                    && i mplicitSou rceFilesRe ad
  1663                    && i mplicitSou rcePolicy  == Implici tSourcePol icy.UNSET)  {
  1664                if (expl icitAnnota tionProces singReques ted())
  1665                    log. warning("p roc.use.im plicit");
  1666                else
  1667                    log. warning("p roc.use.pr oc.or.impl icit");
  1668           }
  1669           ch k.reportDe ferredDiag nostics();
  1670           if  (log.comp ressedOutp ut) {
  1671                log.mand atoryNote( null, "com pressed.di ags");
  1672           }
  1673       }
  1674  
  1675       /** Cl ose the co mpiler, fl ushing the  logs
  1676        */
  1677       public  void clos e() {
  1678           cl ose(true);
  1679       }
  1680  
  1681       public  void clos e(boolean  disposeNam es) {
  1682           ro otClasses  = null;
  1683           re ader = nul l;
  1684           ma ke = null;
  1685           wr iter = nul l;
  1686           en ter = null ;
  1687           if  (todo !=  null)
  1688                todo.cle ar();
  1689           to do = null;
  1690           pa rserFactor y = null;
  1691           sy ms = null;
  1692           so urce = nul l;
  1693           at tr = null;
  1694           ch k = null;
  1695           ge n = null;
  1696           fl ow = null;
  1697           tr ansTypes =  null;
  1698           lo wer = null ;
  1699           an notate = n ull;
  1700           ty pes = null ;
  1701  
  1702           lo g.flush();
  1703           tr y {
  1704                fileMana ger.flush( );
  1705           }  catch (IOE xception e ) {
  1706                throw ne w Abort(e) ;
  1707           }  finally {
  1708                if (name s != null  && dispose Names)
  1709                    name s.dispose( );
  1710                names =  null;
  1711  
  1712                for (Clo seable c:  closeables ) {
  1713                    try  {
  1714                         c.close();
  1715                    } ca tch (IOExc eption e)  {
  1716                         // When ja vac uses J DK 7 as a  baseline,  this code  would be
  1717                         // better  written to  set any/a ll excepti ons from a ll the
  1718                         // Closeab les as sup pressed ex ceptions o n the Fata lError
  1719                         // that is  thrown.
  1720                         JCDiagnost ic msg = d iagFactory .fragment( "fatal.err .cant.clos e");
  1721                         throw new  FatalError (msg, e);
  1722                    }
  1723                }
  1724                closeabl es = List. nil();
  1725           }
  1726       }
  1727  
  1728       protec ted void p rintNote(S tring line s) {
  1729           lo g.printRaw Lines(Log. WriterKind .NOTICE, l ines);
  1730       }
  1731  
  1732       /** Pr int number s of error s and warn ings.
  1733        */
  1734       public  void prin tCount(Str ing kind,  int count)  {
  1735           if  (count !=  0) {
  1736                String k ey;
  1737                if (coun t == 1)
  1738                    key  = "count."  + kind;
  1739                else
  1740                    key  = "count."  + kind +  ".plural";
  1741                log.prin tLines(Wri terKind.ER ROR, key,  String.val ueOf(count ));
  1742                log.flus h(Log.Writ erKind.ERR OR);
  1743           }
  1744       }
  1745  
  1746       privat e static l ong now()  {
  1747           re turn Syste m.currentT imeMillis( );
  1748       }
  1749  
  1750       privat e static l ong elapse d(long the n) {
  1751           re turn now()  - then;
  1752       }
  1753  
  1754       public  void init Round(Java Compiler p rev) {
  1755           ge nEndPos =  prev.genEn dPos;
  1756           ke epComments  = prev.ke epComments ;
  1757           st art_msec =  prev.star t_msec;
  1758           ha sBeenUsed  = true;
  1759           cl oseables =  prev.clos eables;
  1760           pr ev.closeab les = List .nil();
  1761           sh ouldStopPo licyIfErro r = prev.s houldStopP olicyIfErr or;
  1762           sh ouldStopPo licyIfNoEr ror = prev .shouldSto pPolicyIfN oError;
  1763       }
  1764   }