155. 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.

155.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\parser JavacParser.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\parser JavacParser.java Wed Sep 12 16:50:03 2018 UTC

155.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 3 8450
Changed 2 4
Inserted 0 0
Removed 0 0

155.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

155.4 Active regular expressions

No regular expressions were active.

155.5 Comparison detail

  1   /*
  2    * Copyrig ht (c) 199 9, 2016, 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.pa rser;
  27  
  28   import jav a.util.*;
  29  
  30   import com .sun.sourc e.tree.Mem berReferen ceTree.Ref erenceMode ;
  31  
  32   import com .sun.tools .javac.cod e.*;
  33   import com .sun.tools .javac.par ser.Tokens .*;
  34   import com .sun.tools .javac.par ser.Tokens .Comment.C ommentStyl e;
  35   import com .sun.tools .javac.tre e.*;
  36   import com .sun.tools .javac.tre e.JCTree.* ;
  37   import com .sun.tools .javac.uti l.*;
  38   import com .sun.tools .javac.uti l.JCDiagno stic.Diagn osticFlag;
  39   import com .sun.tools .javac.uti l.JCDiagno stic.Diagn osticPosit ion;
  40   import com .sun.tools .javac.uti l.List;
  41  
  42   import sta tic com.su n.tools.ja vac.parser .Tokens.To kenKind.*;
  43   import sta tic com.su n.tools.ja vac.parser .Tokens.To kenKind.AS SERT;
  44   import sta tic com.su n.tools.ja vac.parser .Tokens.To kenKind.CA SE;
  45   import sta tic com.su n.tools.ja vac.parser .Tokens.To kenKind.CA TCH;
  46   import sta tic com.su n.tools.ja vac.parser .Tokens.To kenKind.EQ ;
  47   import sta tic com.su n.tools.ja vac.parser .Tokens.To kenKind.GT ;
  48   import sta tic com.su n.tools.ja vac.parser .Tokens.To kenKind.IM PORT;
  49   import sta tic com.su n.tools.ja vac.parser .Tokens.To kenKind.LT ;
  50   import sta tic com.su n.tools.ja vac.tree.J CTree.Tag. *;
  51  
  52   /** The pa rser maps  a token se quence int o an abstr act syntax
  53    *  tree.  It operate s by recur sive desce nt, with c ode derive d
  54    *  system atically f rom an LL( 1) grammar . For effi ciency rea sons, an
  55    *  operat or precede nce scheme  is used f or parsing  binary op eration
  56    *  expres sions.
  57    *
  58    *  <p><b> This is NO T part of  any suppor ted API.
  59    *  If you  write cod e that dep ends on th is, you do  so at you r own risk .
  60    *  This c ode and it s internal  interface s are subj ect to cha nge or
  61    *  deleti on without  notice.</ b>
  62    */
  63   public cla ss JavacPa rser imple ments Pars er {
  64  
  65       /** Th e number o f preceden ce levels  of infix o perators.
  66        */
  67       privat e static f inal int i nfixPreced enceLevels  = 10;
  68  
  69       /** Th e scanner  used for l exical ana lysis.
  70        */
  71       protec ted Lexer  S;
  72  
  73       /** Th e factory  to be used  for abstr act syntax  tree cons truction.
  74        */
  75       protec ted TreeMa ker F;
  76  
  77       /** Th e log to b e used for  error dia gnostics.
  78        */
  79       privat e Log log;
  80  
  81       /** Th e Source l anguage se tting. */
  82       privat e Source s ource;
  83  
  84       /** Th e name tab le. */
  85       privat e Names na mes;
  86  
  87       /** En d position  mappings  container  */
  88       privat e final Ab stractEndP osTable en dPosTable;
  89  
  90       // Bec ause of ja vac's limi ted lookah ead, some  contexts a re ambiguo us in
  91       // the  presence  of type an notations  even thoug h they are  not ambig uous
  92       // in  the absenc e of type  annotation s.  Consid er this co de:
  93       //   v oid m(Stri ng [] m) {  }
  94       //   v oid m(Stri ng ... m)  { }
  95       // Aft er parsing  "String",  javac cal ls bracket sOpt which  immediate ly
  96       // ret urns if th e next cha racter is  not '['.   Similarly,  javac can  see
  97       // if  the next t oken is .. . and in t hat case p arse an el lipsis.  B ut in
  98       // the  presence  of type an notations:
  99       //   v oid m(Stri ng @A [] m ) { }
  100       //   v oid m(Stri ng @A ...  m) { }
  101       // no  finite loo kahead is  enough to  determine  whether to  read arra y
  102       // lev els or an  ellipsis.   Furthermo re, if you  call brac ketsOpt, t hen
  103       // bra cketsOpt f irst reads  all the l eading ann otations a nd only th en
  104       // dis covers tha t it needs  to fail.   bracketsO pt needs a  way to pu sh
  105       // bac k the extr a annotati ons that i t read.  ( But, brack etsOpt sho uld
  106       // not  *always*  be allowed  to push b ack extra  annotation s that it  finds
  107       // --  in most co ntexts, an y such ext ra annotat ion is an  error.
  108       //
  109       // The  following  two varia bles permi t type ann otations t hat have
  110       // alr eady been  read to be  stored fo r later us e.  Altern ate
  111       // imp lementatio ns are pos sible but  would caus e much lar ger change s to
  112       // the  parser.
  113  
  114       /** Ty pe annotat ions that  have alrea dy been re ad but hav e not yet  been used.  **/
  115       privat e List<JCA nnotation>  typeAnnot ationsPush edBack = L ist.nil();
  116  
  117       /**
  118        * If  the parser  notices e xtra annot ations, th en it eith er immedia tely
  119        * iss ues an err or (if thi s variable  is false)  or places  the extra
  120        * ann otations i n variable  typeAnnot ationsPush edBack (if  this vari able
  121        * is  true).
  122        */
  123       privat e boolean  permitType Annotation sPushBack  = false;
  124  
  125       interf ace ErrorR ecoveryAct ion {
  126           JC Tree doRec over(Javac Parser par ser);
  127       }
  128  
  129       enum B asicErrorR ecoveryAct ion implem ents Error RecoveryAc tion {
  130           BL OCK_STMT { public JCT ree doReco ver(JavacP arser pars er) { retu rn parser. parseState mentAsBloc k(); }},
  131           CA TCH_CLAUSE  {public J CTree doRe cover(Java cParser pa rser) { re turn parse r.catchCla use(); }}
  132       }
  133  
  134       /** Co nstruct a  parser fro m a given  scanner, t ree factor y and log.
  135        */
  136       protec ted JavacP arser(Pars erFactory  fac,
  137                          Lexer S,
  138                          boolean k eepDocComm ents,
  139                          boolean k eepLineMap ,
  140                          boolean k eepEndPosi tions) {
  141           th is.S = S;
  142           ne xtToken();  // prime  the pump
  143           th is.F = fac .F;
  144           th is.log = f ac.log;
  145           th is.names =  fac.names ;
  146           th is.source  = fac.sour ce;
  147           th is.allowGe nerics = s ource.allo wGenerics( );
  148           th is.allowVa rargs = so urce.allow Varargs();
  149           th is.allowAs serts = so urce.allow Asserts();
  150           th is.allowEn ums = sour ce.allowEn ums();
  151           th is.allowFo reach = so urce.allow Foreach();
  152           th is.allowSt aticImport  = source. allowStati cImport();
  153           th is.allowAn notations  = source.a llowAnnota tions();
  154           th is.allowTW R = source .allowTryW ithResourc es();
  155           th is.allowDi amond = so urce.allow Diamond();
  156           th is.allowMu lticatch =  source.al lowMultica tch();
  157           th is.allowSt ringFoldin g = fac.op tions.getB oolean("al lowStringF olding", t rue);
  158           th is.allowLa mbda = sou rce.allowL ambda();
  159           th is.allowMe thodRefere nces = sou rce.allowM ethodRefer ences();
  160           th is.allowDe faultMetho ds = sourc e.allowDef aultMethod s();
  161           th is.allowSt aticInterf aceMethods  = source. allowStati cInterface Methods();
  162           th is.allowIn tersection TypesInCas t = source .allowInte rsectionTy pesInCast( );
  163           th is.allowTy peAnnotati ons = sour ce.allowTy peAnnotati ons();
  164           th is.allowAn notationsA fterTypePa rams = sou rce.allowA nnotations AfterTypeP arams();
  165           th is.keepDoc Comments =  keepDocCo mments;
  166           do cComments  = newDocCo mmentTable (keepDocCo mments, fa c);
  167           th is.keepLin eMap = kee pLineMap;
  168           th is.errorTr ee = F.Err oneous();
  169           en dPosTable  = newEndPo sTable(kee pEndPositi ons);
  170       }
  171  
  172       protec ted Abstra ctEndPosTa ble newEnd PosTable(b oolean kee pEndPositi ons) {
  173           re turn  keep EndPositio ns
  174                    ? ne w SimpleEn dPosTable( this)
  175                    : ne w EmptyEnd PosTable(t his);
  176       }
  177  
  178       protec ted DocCom mentTable  newDocComm entTable(b oolean kee pDocCommen ts, Parser Factory fa c) {
  179           re turn keepD ocComments  ? new Laz yDocCommen tTable(fac ) : null;
  180       }
  181  
  182       /** Sw itch: Shou ld generic s be recog nized?
  183        */
  184       boolea n allowGen erics;
  185  
  186       /** Sw itch: Shou ld diamond  operator  be recogni zed?
  187        */
  188       boolea n allowDia mond;
  189  
  190       /** Sw itch: Shou ld multica tch clause  be accept ed?
  191        */
  192       boolea n allowMul ticatch;
  193  
  194       /** Sw itch: Shou ld varargs  be recogn ized?
  195        */
  196       boolea n allowVar args;
  197  
  198       /** Sw itch: shou ld we reco gnize asse rt stateme nts, or ju st give a  warning?
  199        */
  200       boolea n allowAss erts;
  201  
  202       /** Sw itch: shou ld we reco gnize enum s, or just  give a wa rning?
  203        */
  204       boolea n allowEnu ms;
  205  
  206       /** Sw itch: shou ld we reco gnize fore ach?
  207        */
  208       boolea n allowFor each;
  209  
  210       /** Sw itch: shou ld we reco gnize fore ach?
  211        */
  212       boolea n allowSta ticImport;
  213  
  214       /** Sw itch: shou ld we reco gnize anno tations?
  215        */
  216       boolea n allowAnn otations;
  217  
  218       /** Sw itch: shou ld we reco gnize try- with-resou rces?
  219        */
  220       boolea n allowTWR ;
  221  
  222       /** Sw itch: shou ld we fold  strings?
  223        */
  224       boolea n allowStr ingFolding ;
  225  
  226       /** Sw itch: shou ld we reco gnize lamb da express ions?
  227        */
  228       boolea n allowLam bda;
  229  
  230       /** Sw itch: shou ld we allo w method/c onstructor  reference s?
  231        */
  232       boolea n allowMet hodReferen ces;
  233  
  234       /** Sw itch: shou ld we allo w default  methods in  interface s?
  235        */
  236       boolea n allowDef aultMethod s;
  237  
  238       /** Sw itch: shou ld we allo w static m ethods in  interfaces ?
  239        */
  240       boolea n allowSta ticInterfa ceMethods;
  241  
  242       /** Sw itch: shou ld we allo w intersec tion types  in cast?
  243        */
  244       boolea n allowInt ersectionT ypesInCast ;
  245  
  246       /** Sw itch: shou ld we keep  docCommen ts?
  247        */
  248       boolea n keepDocC omments;
  249  
  250       /** Sw itch: shou ld we keep  line tabl e?
  251        */
  252       boolea n keepLine Map;
  253  
  254       /** Sw itch: shou ld we reco gnize type  annotatio ns?
  255        */
  256       boolea n allowTyp eAnnotatio ns;
  257  
  258       /** Sw itch: shou ld we allo w annotati ons after  the method  type para meters?
  259        */
  260       boolea n allowAnn otationsAf terTypePar ams;
  261  
  262       /** Sw itch: is " this" allo wed as an  identifier ?
  263        * Thi s is neede d to parse  receiver  types.
  264        */
  265       boolea n allowThi sIdent;
  266  
  267       /** Th e type of  the method  receiver,  as specif ied by a f irst "this " paramete r.
  268        */
  269       JCVari ableDecl r eceiverPar am;
  270  
  271  
  272       /** Wh en terms a re parsed,  the mode  determines  which is  expected:
  273        *      mode = EX PR         : an expre ssion
  274        *      mode = TY PE         : a type
  275        *      mode = NO PARAMS     : no param eters allo wed for ty pe
  276        *      mode = TY PEARG      : type arg ument
  277        */
  278       static  final int  EXPR = 0x 1;
  279       static  final int  TYPE = 0x 2;
  280       static  final int  NOPARAMS  = 0x4;
  281       static  final int  TYPEARG =  0x8;
  282       static  final int  DIAMOND =  0x10;
  283  
  284       /** Th e current  mode.
  285        */
  286       privat e int mode  = 0;
  287  
  288       /** Th e mode of  the term t hat was pa rsed last.
  289        */
  290       privat e int last mode = 0;
  291  
  292       /* --- ------- to ken manage ment ----- ---------  */
  293  
  294       protec ted Token  token;
  295  
  296       public  Token tok en() {
  297           re turn token ;
  298       }
  299  
  300       public  void next Token() {
  301           S. nextToken( );
  302           to ken = S.to ken();
  303       }
  304  
  305       protec ted boolea n peekToke n(Filter<T okenKind>  tk) {
  306           re turn peekT oken(0, tk );
  307       }
  308  
  309       protec ted boolea n peekToke n(int look ahead, Fil ter<TokenK ind> tk) {
  310           re turn tk.ac cepts(S.to ken(lookah ead + 1).k ind);
  311       }
  312  
  313       protec ted boolea n peekToke n(Filter<T okenKind>  tk1, Filte r<TokenKin d> tk2) {
  314           re turn peekT oken(0, tk 1, tk2);
  315       }
  316  
  317       protec ted boolea n peekToke n(int look ahead, Fil ter<TokenK ind> tk1,  Filter<Tok enKind> tk 2) {
  318           re turn tk1.a ccepts(S.t oken(looka head + 1). kind) &&
  319                    tk2. accepts(S. token(look ahead + 2) .kind);
  320       }
  321  
  322       protec ted boolea n peekToke n(Filter<T okenKind>  tk1, Filte r<TokenKin d> tk2, Fi lter<Token Kind> tk3)  {
  323           re turn peekT oken(0, tk 1, tk2, tk 3);
  324       }
  325  
  326       protec ted boolea n peekToke n(int look ahead, Fil ter<TokenK ind> tk1,  Filter<Tok enKind> tk 2, Filter< TokenKind>  tk3) {
  327           re turn tk1.a ccepts(S.t oken(looka head + 1). kind) &&
  328                    tk2. accepts(S. token(look ahead + 2) .kind) &&
  329                    tk3. accepts(S. token(look ahead + 3) .kind);
  330       }
  331  
  332       @Suppr essWarning s("uncheck ed")
  333       protec ted boolea n peekToke n(Filter<T okenKind>. .. kinds)  {
  334           re turn peekT oken(0, ki nds);
  335       }
  336  
  337       @Suppr essWarning s("uncheck ed")
  338       protec ted boolea n peekToke n(int look ahead, Fil ter<TokenK ind>... ki nds) {
  339           fo r (; looka head < kin ds.length  ; lookahea d++) {
  340                if (!kin ds[lookahe ad].accept s(S.token( lookahead  + 1).kind) ) {
  341                    retu rn false;
  342                }
  343           }
  344           re turn true;
  345       }
  346  
  347       /* --- ------- er ror recove ry ------- ------- */
  348  
  349       privat e JCErrone ous errorT ree;
  350  
  351       /** Sk ip forward  until a s uitable st op token i s found.
  352        */
  353       privat e void ski p(boolean  stopAtImpo rt, boolea n stopAtMe mberDecl,  boolean st opAtIdenti fier, bool ean stopAt Statement)  {
  354            w hile (true ) {
  355                 switch  (token.kin d) {
  356                    case  SEMI:
  357                         nextToken( );
  358                         return;
  359                    case  PUBLIC:
  360                    case  FINAL:
  361                    case  ABSTRACT:
  362                    case  MONKEYS_A T:
  363                    case  EOF:
  364                    case  CLASS:
  365                    case  INTERFACE :
  366                    case  ENUM:
  367                         return;
  368                    case  IMPORT:
  369                         if (stopAt Import)
  370                             return ;
  371                         break;
  372                    case  LBRACE:
  373                    case  RBRACE:
  374                    case  PRIVATE:
  375                    case  PROTECTED :
  376                    case  STATIC:
  377                    case  TRANSIENT :
  378                    case  NATIVE:
  379                    case  VOLATILE:
  380                    case  SYNCHRONI ZED:
  381                    case  STRICTFP:
  382                    case  LT:
  383                    case  BYTE:
  384                    case  SHORT:
  385                    case  CHAR:
  386                    case  INT:
  387                    case  LONG:
  388                    case  FLOAT:
  389                    case  DOUBLE:
  390                    case  BOOLEAN:
  391                    case  VOID:
  392                         if (stopAt MemberDecl )
  393                             return ;
  394                         break;
  395                    case  UNDERSCOR E:
  396                    case  IDENTIFIE R:
  397                       i f (stopAtI dentifier)
  398                             return ;
  399                         break;
  400                    case  CASE:
  401                    case  DEFAULT:
  402                    case  IF:
  403                    case  FOR:
  404                    case  WHILE:
  405                    case  DO:
  406                    case  TRY:
  407                    case  SWITCH:
  408                    case  RETURN:
  409                    case  THROW:
  410                    case  BREAK:
  411                    case  CONTINUE:
  412                    case  ELSE:
  413                    case  FINALLY:
  414                    case  CATCH:
  415                         if (stopAt Statement)
  416                             return ;
  417                         break;
  418                }
  419                nextToke n();
  420           }
  421       }
  422  
  423       privat e JCErrone ous syntax Error(int  pos, Strin g key, Tok enKind...  args) {
  424           re turn synta xError(pos , List.<JC Tree>nil() , key, arg s);
  425       }
  426  
  427       privat e JCErrone ous syntax Error(int  pos, List< JCTree> er rs, String  key, Toke nKind... a rgs) {
  428           se tErrorEndP os(pos);
  429           JC Erroneous  err = F.at (pos).Erro neous(errs );
  430           re portSyntax Error(err,  key, (Obj ect[])args );
  431           if  (errs !=  null) {
  432                JCTree l ast = errs .last();
  433                if (last  != null)
  434                    stor eEnd(last,  pos);
  435           }
  436           re turn toP(e rr);
  437       }
  438  
  439       privat e int erro rPos = Pos ition.NOPO S;
  440  
  441       /**
  442        * Rep ort a synt ax using t he given t he positio n paramete r and argu ments,
  443        * unl ess one wa s already  reported a t the same  position.
  444        */
  445       privat e void rep ortSyntaxE rror(int p os, String  key, Obje ct... args ) {
  446           JC Diagnostic .Diagnosti cPosition  diag = new  JCDiagnos tic.Simple Diagnostic Position(p os);
  447           re portSyntax Error(diag , key, arg s);
  448       }
  449  
  450       /**
  451        * Rep ort a synt ax error u sing the g iven Diagn osticPosit ion object  and
  452        * arg uments, un less one w as already  reported  at the sam e position .
  453        */
  454       privat e void rep ortSyntaxE rror(JCDia gnostic.Di agnosticPo sition dia gPos, Stri ng key, Ob ject... ar gs) {
  455           in t pos = di agPos.getP referredPo sition();
  456           if  (pos > S. errPos() | | pos == P osition.NO POS) {
  457                if (toke n.kind ==  EOF) {
  458                    erro r(diagPos,  "prematur e.eof");
  459                } else {
  460                    erro r(diagPos,  key, args );
  461                }
  462           }
  463           S. errPos(pos );
  464           if  (token.po s == error Pos)
  465                nextToke n(); // gu arantee pr ogress
  466           er rorPos = t oken.pos;
  467       }
  468  
  469  
  470       /** Ge nerate a s yntax erro r at curre nt positio n unless o ne was alr eady
  471        *  re ported at  the same p osition.
  472        */
  473       privat e JCErrone ous syntax Error(Stri ng key) {
  474           re turn synta xError(tok en.pos, ke y);
  475       }
  476  
  477       /** Ge nerate a s yntax erro r at curre nt positio n unless o ne was
  478        *  al ready repo rted at th e same pos ition.
  479        */
  480       privat e JCErrone ous syntax Error(Stri ng key, To kenKind ar g) {
  481           re turn synta xError(tok en.pos, ke y, arg);
  482       }
  483  
  484       /** If  next inpu t token ma tches give n token, s kip it, ot herwise re port
  485        *  an  error.
  486        */
  487       public  void acce pt(TokenKi nd tk) {
  488           if  (token.ki nd == tk)  {
  489                nextToke n();
  490           }  else {
  491                setError EndPos(tok en.pos);
  492                reportSy ntaxError( S.prevToke n().endPos , "expecte d", tk);
  493           }
  494       }
  495  
  496       /** Re port an il legal star t of expre ssion/type  error at  given posi tion.
  497        */
  498       JCExpr ession ill egal(int p os) {
  499           se tErrorEndP os(pos);
  500           if  ((mode &  EXPR) != 0 )
  501                return s yntaxError (pos, "ill egal.start .of.expr") ;
  502           el se
  503                return s yntaxError (pos, "ill egal.start .of.type") ;
  504  
  505       }
  506  
  507       /** Re port an il legal star t of expre ssion/type  error at  current po sition.
  508        */
  509       JCExpr ession ill egal() {
  510           re turn illeg al(token.p os);
  511       }
  512  
  513       /** Di agnose a m odifier fl ag from th e set, if  any. */
  514       void c heckNoMods (long mods ) {
  515           if  (mods !=  0) {
  516                long low estMod = m ods & -mod s;
  517                error(to ken.pos, " mod.not.al lowed.here ",
  518                         Flags.asFl agSet(lowe stMod));
  519           }
  520       }
  521  
  522   /* ------- --- doc co mments --- ------ */
  523  
  524       /** A  table to s tore all d ocumentati on comment s
  525        *  in dexed by t he tree no des they r efer to.
  526        *  de fined only  if option  flag keep DocComment  is set.
  527        */
  528       privat e final Do cCommentTa ble docCom ments;
  529  
  530       /** Ma ke an entr y into doc Comments h ashtable,
  531        *  pr ovided fla g keepDocC omments is  set and g iven doc c omment is  non-null.
  532        *  @p aram tree    The tree  to be use d as index  in the ha shtable
  533        *  @p aram dc      The doc  comment to  associate  with the  tree, or n ull.
  534        */
  535       void a ttach(JCTr ee tree, C omment dc)  {
  536           if  (keepDocC omments &&  dc != nul l) {
  537   //           System.o ut.println ("doc comm ent = ");S ystem.out. println(dc );//DEBUG
  538                docComme nts.putCom ment(tree,  dc);
  539           }
  540       }
  541  
  542   /* ------- - source p ositions - ------ */
  543  
  544       privat e void set ErrorEndPo s(int errP os) {
  545           en dPosTable. setErrorEn dPos(errPo s);
  546       }
  547  
  548       privat e void sto reEnd(JCTr ee tree, i nt endpos)  {
  549           en dPosTable. storeEnd(t ree, endpo s);
  550       }
  551  
  552       privat e <T exten ds JCTree>  T to(T t)  {
  553           re turn endPo sTable.to( t);
  554       }
  555  
  556       privat e <T exten ds JCTree>  T toP(T t ) {
  557           re turn endPo sTable.toP (t);
  558       }
  559  
  560       /** Ge t the star t position  for a tre e node.  T he start p osition is
  561        * def ined to be  the posit ion of the  first cha racter of  the first
  562        * tok en of the  node's sou rce text.
  563        * @pa ram tree   The tree n ode
  564        */
  565       public  int getSt artPos(JCT ree tree)  {
  566           re turn TreeI nfo.getSta rtPos(tree );
  567       }
  568  
  569       /**
  570        * Get  the end p osition fo r a tree n ode.  The  end positi on is
  571        * def ined to be  the posit ion of the  last char acter of t he last
  572        * tok en of the  node's sou rce text.   Returns P osition.NO POS if end
  573        * pos itions are  not gener ated or th e position  is otherw ise not
  574        * fou nd.
  575        * @pa ram tree   The tree n ode
  576        */
  577       public  int getEn dPos(JCTre e tree) {
  578           re turn endPo sTable.get EndPos(tre e);
  579       }
  580  
  581  
  582  
  583   /* ------- --- parsin g -------- ------ */
  584  
  585       /**
  586        * Ide nt = IDENT IFIER
  587        */
  588       public  Name iden t() {
  589           if  (token.ki nd == IDEN TIFIER) {
  590                Name nam e = token. name();
  591                nextToke n();
  592                return n ame;
  593           }  else if (t oken.kind  == ASSERT)  {
  594                if (allo wAsserts)  {
  595                    erro r(token.po s, "assert .as.identi fier");
  596                    next Token();
  597                    retu rn names.e rror;
  598                } else {
  599                    warn ing(token. pos, "asse rt.as.iden tifier");
  600                    Name  name = to ken.name() ;
  601                    next Token();
  602                    retu rn name;
  603                }
  604           }  else if (t oken.kind  == ENUM) {
  605                if (allo wEnums) {
  606                    erro r(token.po s, "enum.a s.identifi er");
  607                    next Token();
  608                    retu rn names.e rror;
  609                } else {
  610                    warn ing(token. pos, "enum .as.identi fier");
  611                    Name  name = to ken.name() ;
  612                    next Token();
  613                    retu rn name;
  614                }
  615           }  else if (t oken.kind  == THIS) {
  616                if (allo wThisIdent ) {
  617                    // M ake sure w e're using  a support ed source  version.
  618                    chec kTypeAnnot ations();
  619                    Name  name = to ken.name() ;
  620                    next Token();
  621                    retu rn name;
  622                } else {
  623                    erro r(token.po s, "this.a s.identifi er");
  624                    next Token();
  625                    retu rn names.e rror;
  626                }
  627           }  else if (t oken.kind  == UNDERSC ORE) {
  628                warning( token.pos,  "undersco re.as.iden tifier");
  629                Name nam e = token. name();
  630                nextToke n();
  631                return n ame;
  632           }  else {
  633                accept(I DENTIFIER) ;
  634                return n ames.error ;
  635           }
  636       }
  637  
  638       /**
  639        * Qua lident = I dent { DOT  [Annotati ons] Ident  }
  640        */
  641       public  JCExpress ion qualid ent(boolea n allowAnn os) {
  642           JC Expression  t = toP(F .at(token. pos).Ident (ident())) ;
  643           wh ile (token .kind == D OT) {
  644                int pos  = token.po s;
  645                nextToke n();
  646                List<JCA nnotation>  tyannos =  null;
  647                if (allo wAnnos) {
  648                    tyan nos = type Annotation sOpt();
  649                }
  650                t = toP( F.at(pos). Select(t,  ident()));
  651                if (tyan nos != nul l && tyann os.nonEmpt y()) {
  652                    t =  toP(F.at(t yannos.hea d.pos).Ann otatedType (tyannos,  t));
  653                }
  654           }
  655           re turn t;
  656       }
  657  
  658       JCExpr ession lit eral(Name  prefix) {
  659           re turn liter al(prefix,  token.pos );
  660       }
  661  
  662       /**
  663        * Lit eral =
  664        *      INTLITERA L
  665        *   |  LONGLITER AL
  666        *   |  FLOATLITE RAL
  667        *   |  DOUBLELIT ERAL
  668        *   |  CHARLITER AL
  669        *   |  STRINGLIT ERAL
  670        *   |  TRUE
  671        *   |  FALSE
  672        *   |  NULL
  673        */
  674       JCExpr ession lit eral(Name  prefix, in t pos) {
  675           JC Expression  t = error Tree;
  676           sw itch (toke n.kind) {
  677           ca se INTLITE RAL:
  678                try {
  679                    t =  F.at(pos). Literal(
  680                         TypeTag.IN T,
  681                         Convert.st ring2int(s trval(pref ix), token .radix())) ;
  682                } catch  (NumberFor matExcepti on ex) {
  683                    erro r(token.po s, "int.nu mber.too.l arge", str val(prefix ));
  684                }
  685                break;
  686           ca se LONGLIT ERAL:
  687                try {
  688                    t =  F.at(pos). Literal(
  689                         TypeTag.LO NG,
  690                         new Long(C onvert.str ing2long(s trval(pref ix), token .radix())) );
  691                } catch  (NumberFor matExcepti on ex) {
  692                    erro r(token.po s, "int.nu mber.too.l arge", str val(prefix ));
  693                }
  694                break;
  695           ca se FLOATLI TERAL: {
  696                String p roper = to ken.radix( ) == 16 ?
  697                         ("0x"+ tok en.stringV al()) :
  698                         token.stri ngVal();
  699                Float n;
  700                try {
  701                    n =  Float.valu eOf(proper );
  702                } catch  (NumberFor matExcepti on ex) {
  703                    // e rror alrea dy reporte d in scann er
  704                    n =  Float.NaN;
  705                }
  706                if (n.fl oatValue()  == 0.0f & & !isZero( proper))
  707                    erro r(token.po s, "fp.num ber.too.sm all");
  708                else if  (n.floatVa lue() == F loat.POSIT IVE_INFINI TY)
  709                    erro r(token.po s, "fp.num ber.too.la rge");
  710                else
  711                    t =  F.at(pos). Literal(Ty peTag.FLOA T, n);
  712                break;
  713           }
  714           ca se DOUBLEL ITERAL: {
  715                String p roper = to ken.radix( ) == 16 ?
  716                         ("0x"+ tok en.stringV al()) :
  717                         token.stri ngVal();
  718                Double n ;
  719                try {
  720                    n =  Double.val ueOf(prope r);
  721                } catch  (NumberFor matExcepti on ex) {
  722                    // e rror alrea dy reporte d in scann er
  723                    n =  Double.NaN ;
  724                }
  725                if (n.do ubleValue( ) == 0.0d  && !isZero (proper))
  726                    erro r(token.po s, "fp.num ber.too.sm all");
  727                else if  (n.doubleV alue() ==  Double.POS ITIVE_INFI NITY)
  728                    erro r(token.po s, "fp.num ber.too.la rge");
  729                else
  730                    t =  F.at(pos). Literal(Ty peTag.DOUB LE, n);
  731                break;
  732           }
  733           ca se CHARLIT ERAL:
  734                t = F.at (pos).Lite ral(
  735                    Type Tag.CHAR,
  736                    toke n.stringVa l().charAt (0) + 0);
  737                break;
  738           ca se STRINGL ITERAL:
  739                t = F.at (pos).Lite ral(
  740                    Type Tag.CLASS,
  741                    toke n.stringVa l());
  742                break;
  743           ca se TRUE: c ase FALSE:
  744                t = F.at (pos).Lite ral(
  745                    Type Tag.BOOLEA N,
  746                    (tok en.kind ==  TRUE ? 1  : 0));
  747                break;
  748           ca se NULL:
  749                t = F.at (pos).Lite ral(
  750                    Type Tag.BOT,
  751                    null );
  752                break;
  753           de fault:
  754                Assert.e rror();
  755           }
  756           if  (t == err orTree)
  757                t = F.at (pos).Erro neous();
  758           st oreEnd(t,  token.endP os);
  759           ne xtToken();
  760           re turn t;
  761       }
  762       //wher e
  763           bo olean isZe ro(String  s) {
  764                char[] c s = s.toCh arArray();
  765                int base  = ((cs.le ngth > 1 & & Characte r.toLowerC ase(cs[1])  == 'x') ?  16 : 10);
  766                int i =  ((base==16 ) ? 2 : 0) ;
  767                while (i  < cs.leng th && (cs[ i] == '0'  || cs[i] = = '.')) i+ +;
  768                return ! (i < cs.le ngth && (C haracter.d igit(cs[i] , base) >  0));
  769           }
  770  
  771           St ring strva l(Name pre fix) {
  772                String s  = token.s tringVal() ;
  773                return p refix.isEm pty() ? s  : prefix +  s;
  774           }
  775  
  776       /** te rms can be  either ex pressions  or types.
  777        */
  778       public  JCExpress ion parseE xpression( ) {
  779           re turn term( EXPR);
  780       }
  781  
  782       /**
  783        * par ses (optio nal) type  annotation s followed  by a type . If the
  784        * ann otations a re present  before th e type and  are not c onsumed du ring array
  785        * par sing, this  method re turns a {@ link JCAnn otatedType } consisti ng of
  786        * the se annotat ions and t he underly ing type.  Otherwise,  it return s the
  787        * und erlying ty pe.
  788        *
  789        * <p>
  790        *
  791        * Not e that thi s method s ets {@code  mode} to  {@code TYP E} first,  before
  792        * par sing annot ations.
  793        */
  794       public  JCExpress ion parseT ype() {
  795           Li st<JCAnnot ation> ann otations =  typeAnnot ationsOpt( );
  796           re turn parse Type(annot ations);
  797       }
  798  
  799       public  JCExpress ion parseT ype(List<J CAnnotatio n> annotat ions) {
  800           JC Expression  result =  unannotate dType();
  801  
  802           if  (annotati ons.nonEmp ty()) {
  803                result =  insertAnn otationsTo MostInner( result, an notations,  false);
  804           }
  805  
  806           re turn resul t;
  807       }
  808  
  809       public  JCExpress ion unanno tatedType( ) {
  810           re turn term( TYPE);
  811       }
  812  
  813       JCExpr ession ter m(int newm ode) {
  814           in t prevmode  = mode;
  815           mo de = newmo de;
  816           JC Expression  t = term( );
  817           la stmode = m ode;
  818           mo de = prevm ode;
  819           re turn t;
  820       }
  821  
  822       /**
  823        *  {@ literal
  824        *  Ex pression =  Expressio n1 [Expres sionRest]
  825        *  Ex pressionRe st = [Assi gnmentOper ator Expre ssion1]
  826        *  As signmentOp erator = " =" | "+="  | "-=" | " *=" | "/="  |
  827        *                         " &=" | "|="  | "^=" |
  828        *                         " %=" | "<<= " | ">>="  | ">>>="
  829        *  Ty pe = Type1
  830        *  Ty peNoParams  = TypeNoP arams1
  831        *  St atementExp ression =  Expression
  832        *  Co nstantExpr ession = E xpression
  833        *  }
  834        */
  835       JCExpr ession ter m() {
  836           JC Expression  t = term1 ();
  837           if  ((mode &  EXPR) != 0  &&
  838                token.ki nd == EQ | | PLUSEQ.c ompareTo(t oken.kind)  <= 0 && t oken.kind. compareTo( GTGTGTEQ)  <= 0)
  839                return t ermRest(t) ;
  840           el se
  841                return t ;
  842       }
  843  
  844       JCExpr ession ter mRest(JCEx pression t ) {
  845           sw itch (toke n.kind) {
  846           ca se EQ: {
  847                int pos  = token.po s;
  848                nextToke n();
  849                mode = E XPR;
  850                JCExpres sion t1 =  term();
  851                return t oP(F.at(po s).Assign( t, t1));
  852           }
  853           ca se PLUSEQ:
  854           ca se SUBEQ:
  855           ca se STAREQ:
  856           ca se SLASHEQ :
  857           ca se PERCENT EQ:
  858           ca se AMPEQ:
  859           ca se BAREQ:
  860           ca se CARETEQ :
  861           ca se LTLTEQ:
  862           ca se GTGTEQ:
  863           ca se GTGTGTE Q:
  864                int pos  = token.po s;
  865                TokenKin d tk = tok en.kind;
  866                nextToke n();
  867                mode = E XPR;
  868                JCExpres sion t1 =  term();
  869                return F .at(pos).A ssignop(op tag(tk), t , t1);
  870           de fault:
  871                return t ;
  872           }
  873       }
  874  
  875       /** Ex pression1    = Expres sion2 [Exp ression1Re st]
  876        *  Ty pe1          = Type2
  877        *  Ty peNoParams 1 = TypeNo Params2
  878        */
  879       JCExpr ession ter m1() {
  880           JC Expression  t = term2 ();
  881           if  ((mode &  EXPR) != 0  && token. kind == QU ES) {
  882                mode = E XPR;
  883                return t erm1Rest(t );
  884           }  else {
  885                return t ;
  886           }
  887       }
  888  
  889       /** Ex pression1R est = ["?"  Expressio n ":" Expr ession1]
  890        */
  891       JCExpr ession ter m1Rest(JCE xpression  t) {
  892           if  (token.ki nd == QUES ) {
  893                int pos  = token.po s;
  894                nextToke n();
  895                JCExpres sion t1 =  term();
  896                accept(C OLON);
  897                JCExpres sion t2 =  term1();
  898                return F .at(pos).C onditional (t, t1, t2 );
  899           }  else {
  900                return t ;
  901           }
  902       }
  903  
  904       /** Ex pression2    = Expres sion3 [Exp ression2Re st]
  905        *  Ty pe2          = Type3
  906        *  Ty peNoParams 2 = TypeNo Params3
  907        */
  908       JCExpr ession ter m2() {
  909           JC Expression  t = term3 ();
  910           if  ((mode &  EXPR) != 0  && prec(t oken.kind)  >= TreeIn fo.orPrec)  {
  911                mode = E XPR;
  912                return t erm2Rest(t , TreeInfo .orPrec);
  913           }  else {
  914                return t ;
  915           }
  916       }
  917  
  918       /*  Ex pression2R est = {inf ixop Expre ssion3}
  919        *                    | Expr ession3 in stanceof T ype
  920        *  in fixop          = "||"
  921        *                    | "&&"
  922        *                    | "|"
  923        *                    | "^"
  924        *                    | "&"
  925        *                    | "=="  | "!="
  926        *                    | "<"  | ">" | "< =" | ">="
  927        *                    | "<<"  | ">>" |  ">>>"
  928        *                    | "+"  | "-"
  929        *                    | "*"  | "/" | "% "
  930        */
  931       JCExpr ession ter m2Rest(JCE xpression  t, int min prec) {
  932           JC Expression [] odStack  = newOdSt ack();
  933           To ken[] opSt ack = newO pStack();
  934  
  935           //  optimizat ion, was o dStack = n ew Tree[.. .]; opStac k = new Tr ee[...];
  936           in t top = 0;
  937           od Stack[0] =  t;
  938           in t startPos  = token.p os;
  939           To ken topOp  = Tokens.D UMMY;
  940           wh ile (prec( token.kind ) >= minpr ec) {
  941                opStack[ top] = top Op;
  942                top++;
  943                topOp =  token;
  944                nextToke n();
  945                odStack[ top] = (to pOp.kind = = INSTANCE OF) ? pars eType() :  term3();
  946                while (t op > 0 &&  prec(topOp .kind) >=  prec(token .kind)) {
  947                    odSt ack[top-1]  = makeOp( topOp.pos,  topOp.kin d, odStack [top-1],
  948                                               odStack[to p]);
  949                    top- -;
  950                    topO p = opStac k[top];
  951                }
  952           }
  953           As sert.check (top == 0) ;
  954           t  = odStack[ 0];
  955  
  956           if  (t.hasTag (JCTree.Ta g.PLUS)) {
  957                t = fold Strings(t) ;
  958           }
  959  
  960           od StackSuppl y.add(odSt ack);
  961           op StackSuppl y.add(opSt ack);
  962           re turn t;
  963       }
  964       //wher e
  965           /* * Construc t a binary  or type t est node.
  966            * /
  967           pr ivate JCEx pression m akeOp(int  pos,
  968                                          Toke nKind topO p,
  969                                          JCEx pression o d1,
  970                                          JCEx pression o d2)
  971           {
  972                if (topO p == INSTA NCEOF) {
  973                    retu rn F.at(po s).TypeTes t(od1, od2 );
  974                } else {
  975                    retu rn F.at(po s).Binary( optag(topO p), od1, o d2);
  976                }
  977           }
  978           /* * If tree  is a conca tenation o f string l iterals, r eplace it
  979            *   by a sin gle litera l represen ting the c oncatenate d string.
  980            * /
  981           pr otected JC Expression  foldStrin gs(JCExpre ssion tree ) {
  982                if (!all owStringFo lding)
  983                    retu rn tree;
  984                ListBuff er<JCExpre ssion> opS tack = new  ListBuffe r<>();
  985                ListBuff er<JCLiter al> litBuf  = new Lis tBuffer<>( );
  986                boolean  needsFoldi ng = false ;
  987                JCExpres sion curr  = tree;
  988                while (t rue) {
  989                    if ( curr.hasTa g(JCTree.T ag.PLUS))  {
  990                         JCBinary o p = (JCBin ary)curr;
  991                         needsFoldi ng |= fold IfNeeded(o p.rhs, lit Buf, opSta ck, false) ;
  992                         curr = op. lhs;
  993                    } el se {
  994                         needsFoldi ng |= fold IfNeeded(c urr, litBu f, opStack , true);
  995                         break; //l ast one!
  996                    }
  997                }
  998                if (need sFolding)  {
  999                    List <JCExpress ion> ops =  opStack.t oList();
  1000                    JCEx pression r es = ops.h ead;
  1001                    for  (JCExpress ion op : o ps.tail) {
  1002                         res = F.at (op.getSta rtPosition ()).Binary (optag(Tok enKind.PLU S), res, o p);
  1003                         storeEnd(r es, getEnd Pos(op));
  1004                    }
  1005                    retu rn res;
  1006                } else {
  1007                    retu rn tree;
  1008                }
  1009           }
  1010  
  1011           pr ivate bool ean foldIf Needed(JCE xpression  tree, List Buffer<JCL iteral> li tBuf,
  1012                                                       Li stBuffer<J CExpressio n> opStack , boolean  last) {
  1013                JCLitera l str = st ringLitera l(tree);
  1014                if (str  != null) {
  1015                    litB uf.prepend (str);
  1016                    retu rn last &&  merge(lit Buf, opSta ck);
  1017                } else {
  1018                    bool ean res =  merge(litB uf, opStac k);
  1019                    litB uf.clear() ;
  1020                    opSt ack.prepen d(tree);
  1021                    retu rn res;
  1022                }
  1023           }
  1024  
  1025           bo olean merg e(ListBuff er<JCLiter al> litBuf , ListBuff er<JCExpre ssion> opS tack) {
  1026                if (litB uf.isEmpty ()) {
  1027                    retu rn false;
  1028                } else i f (litBuf. size() ==  1) {
  1029                    opSt ack.prepen d(litBuf.f irst());
  1030                    retu rn false;
  1031                } else {
  1032                    Stri ngBuilder  sb = new S tringBuild er();
  1033                    for  (JCLiteral  lit : lit Buf) {
  1034                         sb.append( lit.getVal ue());
  1035                    }
  1036                    JCEx pression t  = F.at(li tBuf.first ().getStar tPosition( )).Literal (TypeTag.C LASS, sb.t oString()) ;
  1037                    stor eEnd(t, li tBuf.last( ).getEndPo sition(end PosTable)) ;
  1038                    opSt ack.prepen d(t);
  1039                    retu rn true;
  1040                }
  1041           }
  1042  
  1043           pr ivate JCLi teral stri ngLiteral( JCTree tre e) {
  1044                if (tree .hasTag(LI TERAL)) {
  1045                    JCLi teral lit  = (JCLiter al)tree;
  1046                    if ( lit.typeta g == TypeT ag.CLASS)  {
  1047                         return lit ;
  1048                    }
  1049                }
  1050                return n ull;
  1051           }
  1052  
  1053  
  1054           /* * optimiza tion: To s ave alloca ting a new  operand/o perator st ack
  1055            *   for ever y binary o peration,  we use sup plys.
  1056            * /
  1057           Ar rayList<JC Expression []> odStac kSupply =  new ArrayL ist<JCExpr ession[]>( );
  1058           Ar rayList<To ken[]> opS tackSupply  = new Arr ayList<Tok en[]>();
  1059  
  1060           pr ivate JCEx pression[]  newOdStac k() {
  1061                if (odSt ackSupply. isEmpty())
  1062                    retu rn new JCE xpression[ infixPrece denceLevel s + 1];
  1063                return o dStackSupp ly.remove( odStackSup ply.size()  - 1);
  1064           }
  1065  
  1066           pr ivate Toke n[] newOpS tack() {
  1067                if (opSt ackSupply. isEmpty())
  1068                    retu rn new Tok en[infixPr ecedenceLe vels + 1];
  1069                return o pStackSupp ly.remove( opStackSup ply.size()  - 1);
  1070           }
  1071  
  1072       /**
  1073        *  Ex pression3     = Prefi xOp Expres sion3
  1074        *                   | "(" E xpr | Type NoParams " )" Express ion3
  1075        *                   | Prima ry {Select or} {Postf ixOp}
  1076        *
  1077        *  {@ literal
  1078        *  Pr imary         = "(" E xpression  ")"
  1079        *                   | Liter al
  1080        *                   | [Type Arguments]  THIS [Arg uments]
  1081        *                   | [Type Arguments]  SUPER Sup erSuffix
  1082        *                   | NEW [ TypeArgume nts] Creat or
  1083        *                   | "(" A rguments " )" "->" (  Expression  | Block )
  1084        *                   | Ident  "->" ( Ex pression |  Block )
  1085        *                   | [Anno tations] I dent { "."  [Annotati ons] Ident  }
  1086        *                   | Expre ssion3 Mem berReferen ceSuffix
  1087        *                     [ [An notations]  "[" ( "]"  BracketsO pt "." CLA SS | Expre ssion "]"  )
  1088        *                     | Arg uments
  1089        *                     | "."  ( CLASS |  THIS | [T ypeArgumen ts] SUPER  Arguments  | NEW [Typ eArguments ] InnerCre ator )
  1090        *                     ]
  1091        *                   | Basic Type Brack etsOpt "."  CLASS
  1092        *  }
  1093        *
  1094        *  Pr efixOp        = "++"  | "--" | " !" | "~" |  "+" | "-"
  1095        *  Po stfixOp       = "++"  | "--"
  1096        *  Ty pe3           = Ident  { "." Ide nt } [Type Arguments]  {TypeSele ctor} Brac ketsOpt
  1097        *                   | Basic Type
  1098        *  Ty peNoParams 3  = Ident  { "." Ide nt } Brack etsOpt
  1099        *  Se lector        = "." [ TypeArgume nts] Ident  [Argument s]
  1100        *                   | "." T HIS
  1101        *                   | "." [ TypeArgume nts] SUPER  SuperSuff ix
  1102        *                   | "." N EW [TypeAr guments] I nnerCreato r
  1103        *                   | "[" E xpression  "]"
  1104        *  Ty peSelector    = "." I dent [Type Arguments]
  1105        *  Su perSuffix     = Argum ents | "."  Ident [Ar guments]
  1106        */
  1107       protec ted JCExpr ession ter m3() {
  1108           in t pos = to ken.pos;
  1109           JC Expression  t;
  1110           Li st<JCExpre ssion> typ eArgs = ty peArgument sOpt(EXPR) ;
  1111           sw itch (toke n.kind) {
  1112           ca se QUES:
  1113                if ((mod e & TYPE)  != 0 && (m ode & (TYP EARG|NOPAR AMS)) == T YPEARG) {
  1114                    mode  = TYPE;
  1115                    retu rn typeArg ument();
  1116                } else
  1117                    retu rn illegal ();
  1118           ca se PLUSPLU S: case SU BSUB: case  BANG: cas e TILDE: c ase PLUS:  case SUB:
  1119                if (type Args == nu ll && (mod e & EXPR)  != 0) {
  1120                    Toke nKind tk =  token.kin d;
  1121                    next Token();
  1122                    mode  = EXPR;
  1123                    if ( tk == SUB  &&
  1124                         (token.kin d == INTLI TERAL || t oken.kind  == LONGLIT ERAL) &&
  1125                         token.radi x() == 10)  {
  1126                         mode = EXP R;
  1127                         t = litera l(names.hy phen, pos) ;
  1128                    } el se {
  1129                         t = term3( );
  1130                         return F.a t(pos).Una ry(unoptag (tk), t);
  1131                    }
  1132                } else r eturn ille gal();
  1133                break;
  1134           ca se LPAREN:
  1135                if (type Args == nu ll && (mod e & EXPR)  != 0) {
  1136                    Pare nsResult p res = anal yzeParens( );
  1137                    swit ch (pres)  {
  1138                         case CAST:
  1139                            accept( LPAREN);
  1140                            mode =  TYPE;
  1141                            int pos 1 = pos;
  1142                            List<JC Expression > targets  = List.of( t = term3( ));
  1143                            while ( token.kind  == AMP) {
  1144                                che ckIntersec tionTypesI nCast();
  1145                                acc ept(AMP);
  1146                                tar gets = tar gets.prepe nd(term3() );
  1147                            }
  1148                            if (tar gets.lengt h() > 1) {
  1149                                t =  toP(F.at( pos1).Type Intersecti on(targets .reverse() ));
  1150                            }
  1151                            accept( RPAREN);
  1152                            mode =  EXPR;
  1153                            JCExpre ssion t1 =  term3();
  1154                            return  F.at(pos). TypeCast(t , t1);
  1155                         case IMPLI CIT_LAMBDA :
  1156                         case EXPLI CIT_LAMBDA :
  1157                             t = la mbdaExpres sionOrStat ement(true , pres ==  ParensResu lt.EXPLICI T_LAMBDA,  pos);
  1158                             break;
  1159                         default: / /PARENS
  1160                             accept (LPAREN);
  1161                             mode =  EXPR;
  1162                             t = te rmRest(ter m1Rest(ter m2Rest(ter m3(), Tree Info.orPre c)));
  1163                             accept (RPAREN);
  1164                             t = to P(F.at(pos ).Parens(t ));
  1165                             break;
  1166                    }
  1167                } else {
  1168                    retu rn illegal ();
  1169                }
  1170                break;
  1171           ca se THIS:
  1172                if ((mod e & EXPR)  != 0) {
  1173                    mode  = EXPR;
  1174                    t =  to(F.at(po s).Ident(n ames._this ));
  1175                    next Token();
  1176                    if ( typeArgs = = null)
  1177                         t = argume ntsOpt(nul l, t);
  1178                    else
  1179                         t = argume nts(typeAr gs, t);
  1180                    type Args = nul l;
  1181                } else r eturn ille gal();
  1182                break;
  1183           ca se SUPER:
  1184                if ((mod e & EXPR)  != 0) {
  1185                    mode  = EXPR;
  1186                    t =  to(F.at(po s).Ident(n ames._supe r));
  1187                    t =  superSuffi x(typeArgs , t);
  1188                    type Args = nul l;
  1189                } else r eturn ille gal();
  1190                break;
  1191           ca se INTLITE RAL: case  LONGLITERA L: case FL OATLITERAL : case DOU BLELITERAL :
  1192           ca se CHARLIT ERAL: case  STRINGLIT ERAL:
  1193           ca se TRUE: c ase FALSE:  case NULL :
  1194                if (type Args == nu ll && (mod e & EXPR)  != 0) {
  1195                    mode  = EXPR;
  1196                    t =  literal(na mes.empty) ;
  1197                } else r eturn ille gal();
  1198                break;
  1199           ca se NEW:
  1200                if (type Args != nu ll) return  illegal() ;
  1201                if ((mod e & EXPR)  != 0) {
  1202                    mode  = EXPR;
  1203                    next Token();
  1204                    if ( token.kind  == LT) ty peArgs = t ypeArgumen ts(false);
  1205                    t =  creator(po s, typeArg s);
  1206                    type Args = nul l;
  1207                } else r eturn ille gal();
  1208                break;
  1209           ca se MONKEYS _AT:
  1210                // Only  annotated  cast types  and metho d referenc es are val id
  1211                List<JCA nnotation>  typeAnnos  = typeAnn otationsOp t();
  1212                if (type Annos.isEm pty()) {
  1213                    // e lse there  would be n o '@'
  1214                    thro w new Asse rtionError ("Expected  type anno tations, b ut found n one!");
  1215                }
  1216  
  1217                JCExpres sion expr  = term3();
  1218  
  1219                if ((mod e & TYPE)  == 0) {
  1220                    // T ype annota tions on c lass liter als no lon ger legal
  1221                    swit ch (expr.g etTag()) {
  1222                    case  REFERENCE : {
  1223                         JCMemberRe ference mr ef = (JCMe mberRefere nce) expr;
  1224                         mref.expr  = toP(F.at (pos).Anno tatedType( typeAnnos,  mref.expr ));
  1225                         t = mref;
  1226                         break;
  1227                    }
  1228                    case  SELECT: {
  1229                         JCFieldAcc ess sel =  (JCFieldAc cess) expr ;
  1230  
  1231                         if (sel.na me != name s._class)  {
  1232                             return  illegal() ;
  1233                         } else {
  1234                             log.er ror(token. pos, "no.a nnotations .on.dot.cl ass");
  1235                             return  expr;
  1236                         }
  1237                    }
  1238                    defa ult:
  1239                         return ill egal(typeA nnos.head. pos);
  1240                    }
  1241  
  1242                } else {
  1243                    // T ype annota tions targ eting a ca st
  1244                    t =  insertAnno tationsToM ostInner(e xpr, typeA nnos, fals e);
  1245                }
  1246                break;
  1247           ca se UNDERSC ORE: case  IDENTIFIER : case ASS ERT: case  ENUM:
  1248                if (type Args != nu ll) return  illegal() ;
  1249                if ((mod e & EXPR)  != 0 && pe ekToken(AR ROW)) {
  1250                    t =  lambdaExpr essionOrSt atement(fa lse, false , pos);
  1251                } else {
  1252                    t =  toP(F.at(t oken.pos). Ident(iden t()));
  1253                    loop : while (t rue) {
  1254                         pos = toke n.pos;
  1255                         final List <JCAnnotat ion> annos  = typeAnn otationsOp t();
  1256  
  1257                         // need to  report an  error lat er if LBRA CKET is fo r array
  1258                         // index a ccess rath er than ar ray creati on level
  1259                         if (!annos .isEmpty()  && token. kind != LB RACKET &&  token.kind  != ELLIPS IS)
  1260                             return  illegal(a nnos.head. pos);
  1261  
  1262                         switch (to ken.kind)  {
  1263                         case LBRAC KET:
  1264                             nextTo ken();
  1265                             if (to ken.kind = = RBRACKET ) {
  1266                                 ne xtToken();
  1267                                 t  = brackets Opt(t);
  1268                                 t  = toP(F.at (pos).Type Array(t));
  1269                                 if  (annos.no nEmpty())  {
  1270                                      t = toP( F.at(pos). AnnotatedT ype(annos,  t));
  1271                                 }
  1272                                 //  .class is  only allo wed if the re were no  annotatio ns
  1273                                 JC Expression  nt = brac ketsSuffix (t);
  1274                                 if  (nt != t  && (annos. nonEmpty()  || TreeIn fo.contain sTypeAnnot ation(t)))  {
  1275                                      // t and  nt are di fferent if  bracketsS uffix pars ed a .clas s.
  1276                                      // The c heck for n onEmpty co vers the c ase when t he whole a rray is an notated.
  1277                                      // Helpe r method i sAnnotated  looks for  annos dee ply within  t.
  1278                                      syntaxEr ror("no.an notations. on.dot.cla ss");
  1279                                 }
  1280                                 t  = nt;
  1281                             } else  {
  1282                                 if  ((mode &  EXPR) != 0 ) {
  1283                                      mode = E XPR;
  1284                                      JCExpres sion t1 =  term();
  1285                                      if (!ann os.isEmpty ()) t = il legal(anno s.head.pos );
  1286                                      t = to(F .at(pos).I ndexed(t,  t1));
  1287                                 }
  1288                                 ac cept(RBRAC KET);
  1289                             }
  1290                             break  loop;
  1291                         case LPARE N:
  1292                             if ((m ode & EXPR ) != 0) {
  1293                                 mo de = EXPR;
  1294                                 t  = argument s(typeArgs , t);
  1295                                 if  (!annos.i sEmpty())  t = illega l(annos.he ad.pos);
  1296                                 ty peArgs = n ull;
  1297                             }
  1298                             break  loop;
  1299                         case DOT:
  1300                             nextTo ken();
  1301                             int ol dmode = mo de;
  1302                             mode & = ~NOPARAM S;
  1303                             typeAr gs = typeA rgumentsOp t(EXPR);
  1304                             mode =  oldmode;
  1305                             if ((m ode & EXPR ) != 0) {
  1306                                 sw itch (toke n.kind) {
  1307                                 ca se CLASS:
  1308                                      if (type Args != nu ll) return  illegal() ;
  1309                                      mode = E XPR;
  1310                                      t = to(F .at(pos).S elect(t, n ames._clas s));
  1311                                      nextToke n();
  1312                                      break lo op;
  1313                                 ca se THIS:
  1314                                      if (type Args != nu ll) return  illegal() ;
  1315                                      mode = E XPR;
  1316                                      t = to(F .at(pos).S elect(t, n ames._this ));
  1317                                      nextToke n();
  1318                                      break lo op;
  1319                                 ca se SUPER:
  1320                                      mode = E XPR;
  1321                                      t = to(F .at(pos).S elect(t, n ames._supe r));
  1322                                      t = supe rSuffix(ty peArgs, t) ;
  1323                                      typeArgs  = null;
  1324                                      break lo op;
  1325                                 ca se NEW:
  1326                                      if (type Args != nu ll) return  illegal() ;
  1327                                      mode = E XPR;
  1328                                      int pos1  = token.p os;
  1329                                      nextToke n();
  1330                                      if (toke n.kind ==  LT) typeAr gs = typeA rguments(f alse);
  1331                                      t = inne rCreator(p os1, typeA rgs, t);
  1332                                      typeArgs  = null;
  1333                                      break lo op;
  1334                                 }
  1335                             }
  1336  
  1337                             List<J CAnnotatio n> tyannos  = null;
  1338                             if ((m ode & TYPE ) != 0 &&  token.kind  == MONKEY S_AT) {
  1339                                 ty annos = ty peAnnotati onsOpt();
  1340                             }
  1341                             // typ eArgs save d for next  loop iter ation.
  1342                             t = to P(F.at(pos ).Select(t , ident()) );
  1343                             if (ty annos != n ull && tya nnos.nonEm pty()) {
  1344                                 t  = toP(F.at (tyannos.h ead.pos).A nnotatedTy pe(tyannos , t));
  1345                             }
  1346                             break;
  1347                         case ELLIP SIS:
  1348                             if (th is.permitT ypeAnnotat ionsPushBa ck) {
  1349                                 th is.typeAnn otationsPu shedBack =  annos;
  1350                             } else  if (annos .nonEmpty( )) {
  1351                                 //  Don't ret urn here - - error re covery att empt
  1352                                 il legal(anno s.head.pos );
  1353                             }
  1354                             break  loop;
  1355                         case LT:
  1356                             if ((m ode & TYPE ) == 0 &&  isUnboundM emberRef() ) {
  1357                                 // this is an  unbound m ethod refe rence whos e qualifie r
  1358                                 // is a gener ic type i. e. A<S>::m
  1359                                 in t pos1 = t oken.pos;
  1360                                 ac cept(LT);
  1361                                 Li stBuffer<J CExpressio n> args =  new ListBu ffer<JCExp ression>() ;
  1362                                 ar gs.append( typeArgume nt());
  1363                                 wh ile (token .kind == C OMMA) {
  1364                                      nextToke n();
  1365                                      args.app end(typeAr gument());
  1366                                 }
  1367                                 ac cept(GT);
  1368                                 t  = toP(F.at (pos1).Typ eApply(t,  args.toLis t()));
  1369                                 ch eckGeneric s();
  1370                                 wh ile (token .kind == D OT) {
  1371                                      nextToke n();
  1372                                      mode = T YPE;
  1373                                      t = toP( F.at(token .pos).Sele ct(t, iden t()));
  1374                                      t = type ArgumentsO pt(t);
  1375                                 }
  1376                                 t  = brackets Opt(t);
  1377                                 if  (token.ki nd != COLC OL) {
  1378                                      //method  reference  expected  here
  1379                                      t = ille gal();
  1380                                 }
  1381                                 mo de = EXPR;
  1382                                 re turn term3 Rest(t, ty peArgs);
  1383                             }
  1384                             break  loop;
  1385                         default:
  1386                             break  loop;
  1387                         }
  1388                    }
  1389                }
  1390                if (type Args != nu ll) illega l();
  1391                t = type ArgumentsO pt(t);
  1392                break;
  1393           ca se BYTE: c ase SHORT:  case CHAR : case INT : case LON G: case FL OAT:
  1394           ca se DOUBLE:  case BOOL EAN:
  1395                if (type Args != nu ll) illega l();
  1396                t = brac ketsSuffix (bracketsO pt(basicTy pe()));
  1397                break;
  1398           ca se VOID:
  1399                if (type Args != nu ll) illega l();
  1400                if ((mod e & EXPR)  != 0) {
  1401                    next Token();
  1402                    if ( token.kind  == DOT) {
  1403                         JCPrimitiv eTypeTree  ti = toP(F .at(pos).T ypeIdent(T ypeTag.VOI D));
  1404                         t = bracke tsSuffix(t i);
  1405                    } el se {
  1406                         return ill egal(pos);
  1407                    }
  1408                } else {
  1409                    // S upport the  corner ca se of myMe thodHandle .<void>inv oke() by p assing
  1410                    // a  void type  (like oth er primiti ve types)  to the nex t phase.
  1411                    // T he error w ill be rep orted in A ttr.attrib Types or A ttr.visitA pply.
  1412                    JCPr imitiveTyp eTree ti =  to(F.at(p os).TypeId ent(TypeTa g.VOID));
  1413                    next Token();
  1414                    retu rn ti;
  1415                    //re turn illeg al();
  1416                }
  1417                break;
  1418           de fault:
  1419                return i llegal();
  1420           }
  1421           re turn term3 Rest(t, ty peArgs);
  1422       }
  1423  
  1424       JCExpr ession ter m3Rest(JCE xpression  t, List<JC Expression > typeArgs ) {
  1425           if  (typeArgs  != null)  illegal();
  1426           wh ile (true)  {
  1427                int pos1  = token.p os;
  1428                final Li st<JCAnnot ation> ann os = typeA nnotations Opt();
  1429  
  1430                if (toke n.kind ==  LBRACKET)  {
  1431                    next Token();
  1432                    if ( (mode & TY PE) != 0)  {
  1433                         int oldmod e = mode;
  1434                         mode = TYP E;
  1435                         if (token. kind == RB RACKET) {
  1436                             nextTo ken();
  1437                             t = br acketsOpt( t);
  1438                             t = to P(F.at(pos 1).TypeArr ay(t));
  1439                             if (to ken.kind = = COLCOL)  {
  1440                                 mo de = EXPR;
  1441                                 co ntinue;
  1442                             }
  1443                             if (an nos.nonEmp ty()) {
  1444                                 t  = toP(F.at (pos1).Ann otatedType (annos, t) );
  1445                             }
  1446                             return  t;
  1447                         }
  1448                         mode = old mode;
  1449                    }
  1450                    if ( (mode & EX PR) != 0)  {
  1451                         mode = EXP R;
  1452                         JCExpressi on t1 = te rm();
  1453                         t = to(F.a t(pos1).In dexed(t, t 1));
  1454                    }
  1455                    acce pt(RBRACKE T);
  1456                } else i f (token.k ind == DOT ) {
  1457                    next Token();
  1458                    type Args = typ eArguments Opt(EXPR);
  1459                    if ( token.kind  == SUPER  && (mode &  EXPR) !=  0) {
  1460                         mode = EXP R;
  1461                         t = to(F.a t(pos1).Se lect(t, na mes._super ));
  1462                         nextToken( );
  1463                         t = argume nts(typeAr gs, t);
  1464                         typeArgs =  null;
  1465                    } el se if (tok en.kind ==  NEW && (m ode & EXPR ) != 0) {
  1466                         if (typeAr gs != null ) return i llegal();
  1467                         mode = EXP R;
  1468                         int pos2 =  token.pos ;
  1469                         nextToken( );
  1470                         if (token. kind == LT ) typeArgs  = typeArg uments(fal se);
  1471                         t = innerC reator(pos 2, typeArg s, t);
  1472                         typeArgs =  null;
  1473                    } el se {
  1474                         List<JCAnn otation> t yannos = n ull;
  1475                         if ((mode  & TYPE) !=  0 && toke n.kind ==  MONKEYS_AT ) {
  1476                             // is  the mode c heck neede d?
  1477                             tyanno s = typeAn notationsO pt();
  1478                         }
  1479                         t = toP(F. at(pos1).S elect(t, i dent()));
  1480                         if (tyanno s != null  && tyannos .nonEmpty( )) {
  1481                             t = to P(F.at(tya nnos.head. pos).Annot atedType(t yannos, t) );
  1482                         }
  1483                         t = argume ntsOpt(typ eArgs, typ eArguments Opt(t));
  1484                         typeArgs =  null;
  1485                    }
  1486                } else i f ((mode &  EXPR) !=  0 && token .kind == C OLCOL) {
  1487                    mode  = EXPR;
  1488                    if ( typeArgs ! = null) re turn illeg al();
  1489                    acce pt(COLCOL) ;
  1490                    t =  memberRefe renceSuffi x(pos1, t) ;
  1491                } else {
  1492                    if ( !annos.isE mpty()) {
  1493                         if (permit TypeAnnota tionsPushB ack)
  1494                             typeAn notationsP ushedBack  = annos;
  1495                         else
  1496                             return  illegal(a nnos.head. pos);
  1497                    }
  1498                    brea k;
  1499                }
  1500           }
  1501           wh ile ((toke n.kind ==  PLUSPLUS | | token.ki nd == SUBS UB) && (mo de & EXPR)  != 0) {
  1502                mode = E XPR;
  1503                t = to(F .at(token. pos).Unary (
  1504                      to ken.kind = = PLUSPLUS  ? POSTINC  : POSTDEC , t));
  1505                nextToke n();
  1506           }
  1507           re turn toP(t );
  1508       }
  1509  
  1510       /**
  1511        * If  we see an  identifier  followed  by a '&lt; ' it could  be an unb ound
  1512        * met hod refere nce or a b inary expr ession. To  disambigu ate, look  for a
  1513        * mat ching '&gt ;' and see  if the su bsequent t erminal is  either '. ' or '::'.
  1514        */
  1515       @Suppr essWarning s("fallthr ough")
  1516       boolea n isUnboun dMemberRef () {
  1517           in t pos = 0,  depth = 0 ;
  1518           ou ter: for ( Token t =  S.token(po s) ; ; t =  S.token(+ +pos)) {
  1519                switch ( t.kind) {
  1520                    case  IDENTIFIE R: case UN DERSCORE:  case QUES:  case EXTE NDS: case  SUPER:
  1521                    case  DOT: case  RBRACKET:  case LBRA CKET: case  COMMA:
  1522                    case  BYTE: cas e SHORT: c ase INT: c ase LONG:  case FLOAT :
  1523                    case  DOUBLE: c ase BOOLEA N: case CH AR:
  1524                    case  MONKEYS_A T:
  1525                         break;
  1526  
  1527                    case  LPAREN:
  1528                         // skip an notation v alues
  1529                         int nestin g = 0;
  1530                         for (; ; p os++) {
  1531                             TokenK ind tk2 =  S.token(po s).kind;
  1532                             switch  (tk2) {
  1533                                 ca se EOF:
  1534                                      return f alse;
  1535                                 ca se LPAREN:
  1536                                      nesting+ +;
  1537                                      break;
  1538                                 ca se RPAREN:
  1539                                      nesting- -;
  1540                                      if (nest ing == 0)  {
  1541                                          cont inue outer ;
  1542                                      }
  1543                                      break;
  1544                             }
  1545                         }
  1546  
  1547                    case  LT:
  1548                         depth++; b reak;
  1549                    case  GTGTGT:
  1550                         depth--;
  1551                    case  GTGT:
  1552                         depth--;
  1553                    case  GT:
  1554                         depth--;
  1555                         if (depth  == 0) {
  1556                             TokenK ind nextKi nd = S.tok en(pos + 1 ).kind;
  1557                             return
  1558                                 ne xtKind ==  TokenKind. DOT ||
  1559                                 ne xtKind ==  TokenKind. LBRACKET | |
  1560                                 ne xtKind ==  TokenKind. COLCOL;
  1561                         }
  1562                         break;
  1563                    defa ult:
  1564                         return fal se;
  1565                }
  1566           }
  1567       }
  1568  
  1569       /**
  1570        * If  we see an  identifier  followed  by a '&lt; ' it could  be an unb ound
  1571        * met hod refere nce or a b inary expr ession. To  disambigu ate, look  for a
  1572        * mat ching '&gt ;' and see  if the su bsequent t erminal is  either '. ' or '::'.
  1573        */
  1574       @Suppr essWarning s("fallthr ough")
  1575       Parens Result ana lyzeParens () {
  1576           in t depth =  0;
  1577           bo olean type  = false;
  1578           ou ter: for ( int lookah ead = 0 ;  ; lookahea d++) {
  1579                TokenKin d tk = S.t oken(looka head).kind ;
  1580                switch ( tk) {
  1581                    case  COMMA:
  1582                         type = tru e;
  1583                    case  EXTENDS:  case SUPER : case DOT : case AMP :
  1584                         //skip
  1585                         break;
  1586                    case  QUES:
  1587                         if (peekTo ken(lookah ead, EXTEN DS) ||
  1588                                 pe ekToken(lo okahead, S UPER)) {
  1589                             //wild cards
  1590                             type =  true;
  1591                         }
  1592                         break;
  1593                    case  BYTE: cas e SHORT: c ase INT: c ase LONG:  case FLOAT :
  1594                    case  DOUBLE: c ase BOOLEA N: case CH AR:
  1595                         if (peekTo ken(lookah ead, RPARE N)) {
  1596                             //Type , ')' -> c ast
  1597                             return  ParensRes ult.CAST;
  1598                         } else if  (peekToken (lookahead , LAX_IDEN TIFIER)) {
  1599                             //Type , Identifi er/'_'/'as sert'/'enu m' -> expl icit lambd a
  1600                             return  ParensRes ult.EXPLIC IT_LAMBDA;
  1601                         }
  1602                         break;
  1603                    case  LPAREN:
  1604                         if (lookah ead != 0)  {
  1605                             // '('  in a non- starting p osition ->  parens
  1606                             return  ParensRes ult.PARENS ;
  1607                         } else if  (peekToken (lookahead , RPAREN))  {
  1608                             // '(' , ')' -> e xplicit la mbda
  1609                             return  ParensRes ult.EXPLIC IT_LAMBDA;
  1610                         }
  1611                         break;
  1612                    case  RPAREN:
  1613                         // if we h ave seen s omething t hat looks  like a typ e,
  1614                         // then it 's a cast  expression
  1615                         if (type)  return Par ensResult. CAST;
  1616                         // otherwi se, disamb iguate cas t vs. pare nthesized  expression
  1617                         // based o n subseque nt token.
  1618                         switch (S. token(look ahead + 1) .kind) {
  1619                             /*case  PLUSPLUS:  case SUBS UB: */
  1620                             case B ANG: case  TILDE:
  1621                             case L PAREN: cas e THIS: ca se SUPER:
  1622                             case I NTLITERAL:  case LONG LITERAL: c ase FLOATL ITERAL:
  1623                             case D OUBLELITER AL: case C HARLITERAL : case STR INGLITERAL :
  1624                             case T RUE: case  FALSE: cas e NULL:
  1625                             case N EW: case I DENTIFIER:  case ASSE RT: case E NUM: case  UNDERSCORE :
  1626                             case B YTE: case  SHORT: cas e CHAR: ca se INT:
  1627                             case L ONG: case  FLOAT: cas e DOUBLE:  case BOOLE AN: case V OID:
  1628                                 re turn Paren sResult.CA ST;
  1629                             defaul t:
  1630                                 re turn Paren sResult.PA RENS;
  1631                         }
  1632                    case  UNDERSCOR E:
  1633                    case  ASSERT:
  1634                    case  ENUM:
  1635                    case  IDENTIFIE R:
  1636                         if (peekTo ken(lookah ead, LAX_I DENTIFIER) ) {
  1637                             // Ide ntifier, I dentifier/ '_'/'asser t'/'enum'  -> explici t lambda
  1638                             return  ParensRes ult.EXPLIC IT_LAMBDA;
  1639                         } else if  (peekToken (lookahead , RPAREN,  ARROW)) {
  1640                             // Ide ntifier, ' )' '->' ->  implicit  lambda
  1641                             return  ParensRes ult.IMPLIC IT_LAMBDA;
  1642                         }
  1643                         type = fal se;
  1644                         break;
  1645                    case  FINAL:
  1646                    case  ELLIPSIS:
  1647                         //those ca n only app ear in exp licit lamb das
  1648                         return Par ensResult. EXPLICIT_L AMBDA;
  1649                    case  MONKEYS_A T:
  1650                         type = tru e;
  1651                         lookahead  += 1; //sk ip '@'
  1652                         while (pee kToken(loo kahead, DO T)) {
  1653                             lookah ead += 2;
  1654                         }
  1655                         if (peekTo ken(lookah ead, LPARE N)) {
  1656                             lookah ead++;
  1657                             //skip  annotatio n values
  1658                             int ne sting = 0;
  1659                             for (;  ; lookahe ad++) {
  1660                                 To kenKind tk 2 = S.toke n(lookahea d).kind;
  1661                                 sw itch (tk2)  {
  1662                                      case EOF :
  1663                                          retu rn ParensR esult.PARE NS;
  1664                                      case LPA REN:
  1665                                          nest ing++;
  1666                                          brea k;
  1667                                      case RPA REN:
  1668                                          nest ing--;
  1669                                          if ( nesting ==  0) {
  1670                                               continue o uter;
  1671                                          }
  1672                                      break;
  1673                                 }
  1674                             }
  1675                         }
  1676                         break;
  1677                    case  LBRACKET:
  1678                         if (peekTo ken(lookah ead, RBRAC KET, LAX_I DENTIFIER) ) {
  1679                             // '[' , ']', Ide ntifier/'_ '/'assert' /'enum' ->  explicit  lambda
  1680                             return  ParensRes ult.EXPLIC IT_LAMBDA;
  1681                         } else if  (peekToken (lookahead , RBRACKET , RPAREN)  ||
  1682                                 pe ekToken(lo okahead, R BRACKET, A MP)) {
  1683                             // '[' , ']', ')'  -> cast
  1684                             // '[' , ']', '&'  -> cast ( intersecti on type)
  1685                             return  ParensRes ult.CAST;
  1686                         } else if  (peekToken (lookahead , RBRACKET )) {
  1687                             //cons ume the '] ' and skip
  1688                             type =  true;
  1689                             lookah ead++;
  1690                             break;
  1691                         } else {
  1692                             return  ParensRes ult.PARENS ;
  1693                         }
  1694                    case  LT:
  1695                         depth++; b reak;
  1696                    case  GTGTGT:
  1697                         depth--;
  1698                    case  GTGT:
  1699                         depth--;
  1700                    case  GT:
  1701                         depth--;
  1702                         if (depth  == 0) {
  1703                             if (pe ekToken(lo okahead, R PAREN) ||
  1704                                      peekToke n(lookahea d, AMP)) {
  1705                                 //  '>', ')'  -> cast
  1706                                 //  '>', '&'  -> cast
  1707                                 re turn Paren sResult.CA ST;
  1708                             } else  if (peekT oken(looka head, LAX_ IDENTIFIER , COMMA) | |
  1709                                      peekToke n(lookahea d, LAX_IDE NTIFIER, R PAREN, ARR OW) ||
  1710                                      peekToke n(lookahea d, ELLIPSI S)) {
  1711                                 //  '>', Iden tifier/'_' /'assert'/ 'enum', ', ' -> expli cit lambda
  1712                                 //  '>', Iden tifier/'_' /'assert'/ 'enum', ') ', '->' ->  explicit  lambda
  1713                                 //  '>', '... ' -> expli cit lambda
  1714                                 re turn Paren sResult.EX PLICIT_LAM BDA;
  1715                             }
  1716                             //it l ooks a typ e, but cou ld still b e (i) a ca st to gene ric type,
  1717                             //(ii)  an unboun d method r eference o r (iii) an  explicit  lambda
  1718                             type =  true;
  1719                             break;
  1720                         } else if  (depth < 0 ) {
  1721                             //unba lanced '<' , '>' - no t a generi c type
  1722                             return  ParensRes ult.PARENS ;
  1723                         }
  1724                         break;
  1725                    defa ult:
  1726                         //this inc ludes EOF
  1727                         return Par ensResult. PARENS;
  1728                }
  1729           }
  1730       }
  1731  
  1732       /** Ac cepts all  identifier -like toke ns */
  1733       Filter <TokenKind > LAX_IDEN TIFIER = n ew Filter< TokenKind> () {
  1734           pu blic boole an accepts (TokenKind  t) {
  1735                return t  == IDENTI FIER || t  == UNDERSC ORE || t = = ASSERT | | t == ENU M;
  1736           }
  1737       };
  1738  
  1739       enum P arensResul t {
  1740           CA ST,
  1741           EX PLICIT_LAM BDA,
  1742           IM PLICIT_LAM BDA,
  1743           PA RENS;
  1744       }
  1745  
  1746       JCExpr ession lam bdaExpress ionOrState ment(boole an hasPare ns, boolea n explicit Params, in t pos) {
  1747           Li st<JCVaria bleDecl> p arams = ex plicitPara ms ?
  1748                    form alParamete rs(true) :
  1749                    impl icitParame ters(hasPa rens);
  1750  
  1751           re turn lambd aExpressio nOrStateme ntRest(par ams, pos);
  1752       }
  1753  
  1754       JCExpr ession lam bdaExpress ionOrState mentRest(L ist<JCVari ableDecl>  args, int  pos) {
  1755           ch eckLambda( );
  1756           ac cept(ARROW );
  1757  
  1758           re turn token .kind == L BRACE ?
  1759                lambdaSt atement(ar gs, pos, p os) :
  1760                lambdaEx pression(a rgs, pos);
  1761       }
  1762  
  1763       JCExpr ession lam bdaStateme nt(List<JC VariableDe cl> args,  int pos, i nt pos2) {
  1764           JC Block bloc k = block( pos2, 0);
  1765           re turn toP(F .at(pos).L ambda(args , block));
  1766       }
  1767  
  1768       JCExpr ession lam bdaExpress ion(List<J CVariableD ecl> args,  int pos)  {
  1769           JC Tree expr  = parseExp ression();
  1770           re turn toP(F .at(pos).L ambda(args , expr));
  1771       }
  1772  
  1773       /** Su perSuffix  = Argument s | "." [T ypeArgumen ts] Ident  [Arguments ]
  1774        */
  1775       JCExpr ession sup erSuffix(L ist<JCExpr ession> ty peArgs, JC Expression  t) {
  1776           ne xtToken();
  1777           if  (token.ki nd == LPAR EN || type Args != nu ll) {
  1778                t = argu ments(type Args, t);
  1779           }  else if (t oken.kind  == COLCOL)  {
  1780                if (type Args != nu ll) return  illegal() ;
  1781                t = memb erReferenc eSuffix(t) ;
  1782           }  else {
  1783                int pos  = token.po s;
  1784                accept(D OT);
  1785                typeArgs  = (token. kind == LT ) ? typeAr guments(fa lse) : nul l;
  1786                t = toP( F.at(pos). Select(t,  ident()));
  1787                t = argu mentsOpt(t ypeArgs, t );
  1788           }
  1789           re turn t;
  1790       }
  1791  
  1792       /** Ba sicType =  BYTE | SHO RT | CHAR  | INT | LO NG | FLOAT  | DOUBLE  | BOOLEAN
  1793        */
  1794       JCPrim itiveTypeT ree basicT ype() {
  1795           JC PrimitiveT ypeTree t  = to(F.at( token.pos) .TypeIdent (typetag(t oken.kind) ));
  1796           ne xtToken();
  1797           re turn t;
  1798       }
  1799  
  1800       /** Ar gumentsOpt  = [ Argum ents ]
  1801        */
  1802       JCExpr ession arg umentsOpt( List<JCExp ression> t ypeArgs, J CExpressio n t) {
  1803           if  ((mode &  EXPR) != 0  && token. kind == LP AREN || ty peArgs !=  null) {
  1804                mode = E XPR;
  1805                return a rguments(t ypeArgs, t );
  1806           }  else {
  1807                return t ;
  1808           }
  1809       }
  1810  
  1811       /** Ar guments =  "(" [Expre ssion { CO MMA Expres sion }] ") "
  1812        */
  1813       List<J CExpressio n> argumen ts() {
  1814           Li stBuffer<J CExpressio n> args =  new ListBu ffer<>();
  1815           if  (token.ki nd == LPAR EN) {
  1816                nextToke n();
  1817                if (toke n.kind !=  RPAREN) {
  1818                    args .append(pa rseExpress ion());
  1819                    whil e (token.k ind == COM MA) {
  1820                         nextToken( );
  1821                         args.appen d(parseExp ression()) ;
  1822                    }
  1823                }
  1824                accept(R PAREN);
  1825           }  else {
  1826                syntaxEr ror(token. pos, "expe cted", LPA REN);
  1827           }
  1828           re turn args. toList();
  1829       }
  1830  
  1831       JCMeth odInvocati on argumen ts(List<JC Expression > typeArgs , JCExpres sion t) {
  1832           in t pos = to ken.pos;
  1833           Li st<JCExpre ssion> arg s = argume nts();
  1834           re turn toP(F .at(pos).A pply(typeA rgs, t, ar gs));
  1835       }
  1836  
  1837       /**  T ypeArgumen tsOpt = [  TypeArgume nts ]
  1838        */
  1839       JCExpr ession typ eArguments Opt(JCExpr ession t)  {
  1840           if  (token.ki nd == LT & &
  1841                (mode &  TYPE) != 0  &&
  1842                (mode &  NOPARAMS)  == 0) {
  1843                mode = T YPE;
  1844                checkGen erics();
  1845                return t ypeArgumen ts(t, fals e);
  1846           }  else {
  1847                return t ;
  1848           }
  1849       }
  1850       List<J CExpressio n> typeArg umentsOpt( ) {
  1851           re turn typeA rgumentsOp t(TYPE);
  1852       }
  1853  
  1854       List<J CExpressio n> typeArg umentsOpt( int useMod e) {
  1855           if  (token.ki nd == LT)  {
  1856                checkGen erics();
  1857                if ((mod e & useMod e) == 0 ||
  1858                    (mod e & NOPARA MS) != 0)  {
  1859                    ille gal();
  1860                }
  1861                mode = u seMode;
  1862                return t ypeArgumen ts(false);
  1863           }
  1864           re turn null;
  1865       }
  1866  
  1867       /**
  1868        *  {@ literal
  1869        *  Ty peArgument s  = "<" T ypeArgumen t {"," Typ eArgument}  ">"
  1870        *  }
  1871        */
  1872       List<J CExpressio n> typeArg uments(boo lean diamo ndAllowed)  {
  1873           if  (token.ki nd == LT)  {
  1874                nextToke n();
  1875                if (toke n.kind ==  GT && diam ondAllowed ) {
  1876                    chec kDiamond() ;
  1877                    mode  |= DIAMON D;
  1878                    next Token();
  1879                    retu rn List.ni l();
  1880                } else {
  1881                    List Buffer<JCE xpression>  args = ne w ListBuff er<>();
  1882                    args .append((( mode & EXP R) == 0) ?  typeArgum ent() : pa rseType()) ;
  1883                    whil e (token.k ind == COM MA) {
  1884                         nextToken( );
  1885                         args.appen d(((mode &  EXPR) ==  0) ? typeA rgument()  : parseTyp e());
  1886                    }
  1887                    swit ch (token. kind) {
  1888  
  1889                    case  GTGTGTEQ:  case GTGT EQ: case G TEQ:
  1890                    case  GTGTGT: c ase GTGT:
  1891                         token = S. split();
  1892                         break;
  1893                    case  GT:
  1894                         nextToken( );
  1895                         break;
  1896                    defa ult:
  1897                         args.appen d(syntaxEr ror(token. pos, "expe cted", GT) );
  1898                         break;
  1899                    }
  1900                    retu rn args.to List();
  1901                }
  1902           }  else {
  1903                return L ist.<JCExp ression>of (syntaxErr or(token.p os, "expec ted", LT)) ;
  1904           }
  1905       }
  1906  
  1907       /**
  1908        *  {@ literal
  1909        *  Ty peArgument  = Type
  1910        *                 | [Annota tions] "?"
  1911        *                 | [Annota tions] "?"  EXTENDS T ype {"&" T ype}
  1912        *                 | [Annota tions] "?"  SUPER Typ e
  1913        *  }
  1914        */
  1915       JCExpr ession typ eArgument( ) {
  1916           Li st<JCAnnot ation> ann otations =  typeAnnot ationsOpt( );
  1917           if  (token.ki nd != QUES ) return p arseType(a nnotations );
  1918           in t pos = to ken.pos;
  1919           ne xtToken();
  1920           JC Expression  result;
  1921           if  (token.ki nd == EXTE NDS) {
  1922                TypeBoun dKind t =  to(F.at(po s).TypeBou ndKind(Bou ndKind.EXT ENDS));
  1923                nextToke n();
  1924                JCExpres sion bound  = parseTy pe();
  1925                result =  F.at(pos) .Wildcard( t, bound);
  1926           }  else if (t oken.kind  == SUPER)  {
  1927                TypeBoun dKind t =  to(F.at(po s).TypeBou ndKind(Bou ndKind.SUP ER));
  1928                nextToke n();
  1929                JCExpres sion bound  = parseTy pe();
  1930                result =  F.at(pos) .Wildcard( t, bound);
  1931           }  else if (L AX_IDENTIF IER.accept s(token.ki nd)) {
  1932                //error  recovery
  1933                TypeBoun dKind t =  F.at(Posit ion.NOPOS) .TypeBound Kind(Bound Kind.UNBOU ND);
  1934                JCExpres sion wc =  toP(F.at(p os).Wildca rd(t, null ));
  1935                JCIdent  id = toP(F .at(token. pos).Ident (ident())) ;
  1936                JCErrone ous err =  F.at(pos). Erroneous( List.<JCTr ee>of(wc,  id));
  1937                reportSy ntaxError( err, "expe cted3", GT , EXTENDS,  SUPER);
  1938                result =  err;
  1939           }  else {
  1940                TypeBoun dKind t =  toP(F.at(p os).TypeBo undKind(Bo undKind.UN BOUND));
  1941                result =  toP(F.at( pos).Wildc ard(t, nul l));
  1942           }
  1943           if  (!annotat ions.isEmp ty()) {
  1944                result =  toP(F.at( annotation s.head.pos ).Annotate dType(anno tations,re sult));
  1945           }
  1946           re turn resul t;
  1947       }
  1948  
  1949       JCType Apply type Arguments( JCExpressi on t, bool ean diamon dAllowed)  {
  1950           in t pos = to ken.pos;
  1951           Li st<JCExpre ssion> arg s = typeAr guments(di amondAllow ed);
  1952           re turn toP(F .at(pos).T ypeApply(t , args));
  1953       }
  1954  
  1955       /**
  1956        * Bra cketsOpt =  { [Annota tions] "["  "]" }*
  1957        *
  1958        * <p>
  1959        *
  1960        * <co de>annotat ions</code > is the l ist of ann otations t argeting
  1961        * the  expressio n <code>t< /code>.
  1962        */
  1963       privat e JCExpres sion brack etsOpt(JCE xpression  t,
  1964                List<JCA nnotation>  annotatio ns) {
  1965           Li st<JCAnnot ation> nex tLevelAnno tations =  typeAnnota tionsOpt() ;
  1966  
  1967           if  (token.ki nd == LBRA CKET) {
  1968                int pos  = token.po s;
  1969                nextToke n();
  1970                t = brac ketsOptCon t(t, pos,  nextLevelA nnotations );
  1971           }  else if (! nextLevelA nnotations .isEmpty() ) {
  1972                if (perm itTypeAnno tationsPus hBack) {
  1973                    this .typeAnnot ationsPush edBack = n extLevelAn notations;
  1974                } else {
  1975                    retu rn illegal (nextLevel Annotation s.head.pos );
  1976                }
  1977           }
  1978  
  1979           if  (!annotat ions.isEmp ty()) {
  1980                t = toP( F.at(token .pos).Anno tatedType( annotation s, t));
  1981           }
  1982           re turn t;
  1983       }
  1984  
  1985       /** Br acketsOpt  = [ "[" "] " { [Annot ations] "[ " "]"} ]
  1986        */
  1987       privat e JCExpres sion brack etsOpt(JCE xpression  t) {
  1988           re turn brack etsOpt(t,  List.<JCAn notation>n il());
  1989       }
  1990  
  1991       privat e JCExpres sion brack etsOptCont (JCExpress ion t, int  pos,
  1992                List<JCA nnotation>  annotatio ns) {
  1993           ac cept(RBRAC KET);
  1994           t  = brackets Opt(t);
  1995           t  = toP(F.at (pos).Type Array(t));
  1996           if  (annotati ons.nonEmp ty()) {
  1997                t = toP( F.at(pos). AnnotatedT ype(annota tions, t)) ;
  1998           }
  1999           re turn t;
  2000       }
  2001  
  2002       /** Br acketsSuff ixExpr = " ." CLASS
  2003        *  Br acketsSuff ixType =
  2004        */
  2005       JCExpr ession bra cketsSuffi x(JCExpres sion t) {
  2006           if  ((mode &  EXPR) != 0  && token. kind == DO T) {
  2007                mode = E XPR;
  2008                int pos  = token.po s;
  2009                nextToke n();
  2010                accept(C LASS);
  2011                if (toke n.pos == e ndPosTable .errorEndP os) {
  2012                    // e rror recov ery
  2013                    Name  name;
  2014                    if ( LAX_IDENTI FIER.accep ts(token.k ind)) {
  2015                         name = tok en.name();
  2016                         nextToken( );
  2017                    } el se {
  2018                         name = nam es.error;
  2019                    }
  2020                    t =  F.at(pos). Erroneous( List.<JCTr ee>of(toP( F.at(pos). Select(t,  name))));
  2021                } else {
  2022                    t =  toP(F.at(p os).Select (t, names. _class));
  2023                }
  2024           }  else if (( mode & TYP E) != 0) {
  2025                if (toke n.kind !=  COLCOL) {
  2026                    mode  = TYPE;
  2027                }
  2028           }  else if (t oken.kind  != COLCOL)  {
  2029                syntaxEr ror(token. pos, "dot. class.expe cted");
  2030           }
  2031           re turn t;
  2032       }
  2033  
  2034       /**
  2035        * Mem berReferen ceSuffix =  "::" [Typ eArguments ] Ident
  2036        *                         |  "::" [Typ eArguments ] "new"
  2037        */
  2038       JCExpr ession mem berReferen ceSuffix(J CExpressio n t) {
  2039           in t pos1 = t oken.pos;
  2040           ac cept(COLCO L);
  2041           re turn membe rReference Suffix(pos 1, t);
  2042       }
  2043  
  2044       JCExpr ession mem berReferen ceSuffix(i nt pos1, J CExpressio n t) {
  2045           ch eckMethodR eferences( );
  2046           mo de = EXPR;
  2047           Li st<JCExpre ssion> typ eArgs = nu ll;
  2048           if  (token.ki nd == LT)  {
  2049                typeArgs  = typeArg uments(fal se);
  2050           }
  2051           Na me refName ;
  2052           Re ferenceMod e refMode;
  2053           if  (token.ki nd == NEW)  {
  2054                refMode  = Referenc eMode.NEW;
  2055                refName  = names.in it;
  2056                nextToke n();
  2057           }  else {
  2058                refMode  = Referenc eMode.INVO KE;
  2059                refName  = ident();
  2060           }
  2061           re turn toP(F .at(t.getS tartPositi on()).Refe rence(refM ode, refNa me, t, typ eArgs));
  2062       }
  2063  
  2064       /** Cr eator = [A nnotations ] Qualiden t [TypeArg uments] (  ArrayCreat orRest | C lassCreato rRest )
  2065        */
  2066       JCExpr ession cre ator(int n ewpos, Lis t<JCExpres sion> type Args) {
  2067           Li st<JCAnnot ation> new Annotation s = typeAn notationsO pt();
  2068  
  2069           sw itch (toke n.kind) {
  2070           ca se BYTE: c ase SHORT:  case CHAR : case INT : case LON G: case FL OAT:
  2071           ca se DOUBLE:  case BOOL EAN:
  2072                if (type Args == nu ll) {
  2073                    if ( newAnnotat ions.isEmp ty()) {
  2074                         return arr ayCreatorR est(newpos , basicTyp e());
  2075                    } el se {
  2076                         return arr ayCreatorR est(newpos , toP(F.at (newAnnota tions.head .pos).Anno tatedType( newAnnotat ions, basi cType()))) ;
  2077                    }
  2078                }
  2079                break;
  2080           de fault:
  2081           }
  2082           JC Expression  t = quali dent(true) ;
  2083  
  2084           in t oldmode  = mode;
  2085           mo de = TYPE;
  2086           bo olean diam ondFound =  false;
  2087           in t lastType argsPos =  -1;
  2088           if  (token.ki nd == LT)  {
  2089                checkGen erics();
  2090                lastType argsPos =  token.pos;
  2091                t = type Arguments( t, true);
  2092                diamondF ound = (mo de & DIAMO ND) != 0;
  2093           }
  2094           wh ile (token .kind == D OT) {
  2095                if (diam ondFound)  {
  2096                    //ca nnot selec t after a  diamond
  2097                    ille gal();
  2098                }
  2099                int pos  = token.po s;
  2100                nextToke n();
  2101                List<JCA nnotation>  tyannos =  typeAnnot ationsOpt( );
  2102                t = toP( F.at(pos). Select(t,  ident()));
  2103  
  2104                if (tyan nos != nul l && tyann os.nonEmpt y()) {
  2105                    t =  toP(F.at(t yannos.hea d.pos).Ann otatedType (tyannos,  t));
  2106                }
  2107  
  2108                if (toke n.kind ==  LT) {
  2109                    last TypeargsPo s = token. pos;
  2110                    chec kGenerics( );
  2111                    t =  typeArgume nts(t, tru e);
  2112                    diam ondFound =  (mode & D IAMOND) !=  0;
  2113                }
  2114           }
  2115           mo de = oldmo de;
  2116           if  (token.ki nd == LBRA CKET || to ken.kind = = MONKEYS_ AT) {
  2117                // handl e type ann otations f or non pri mitive arr ays
  2118                if (newA nnotations .nonEmpty( )) {
  2119                    t =  insertAnno tationsToM ostInner(t , newAnnot ations, fa lse);
  2120                }
  2121  
  2122                JCExpres sion e = a rrayCreato rRest(newp os, t);
  2123                if (diam ondFound)  {
  2124                    repo rtSyntaxEr ror(lastTy peargsPos,  "cannot.c reate.arra y.with.dia mond");
  2125                    retu rn toP(F.a t(newpos). Erroneous( List.of(e) ));
  2126                }
  2127                else if  (typeArgs  != null) {
  2128                    int  pos = newp os;
  2129                    if ( !typeArgs. isEmpty()  && typeArg s.head.pos  != Positi on.NOPOS)  {
  2130                         // note: t his should  always ha ppen but w e should
  2131                         // not rel y on this  as the par ser is con tinuously
  2132                         // modifie d to impro ve error r ecovery.
  2133                         pos = type Args.head. pos;
  2134                    }
  2135                    setE rrorEndPos (S.prevTok en().endPo s);
  2136                    JCEr roneous er r = F.at(p os).Errone ous(typeAr gs.prepend (e));
  2137                    repo rtSyntaxEr ror(err, " cannot.cre ate.array. with.type. arguments" );
  2138                    retu rn toP(err );
  2139                }
  2140                return e ;
  2141           }  else if (t oken.kind  == LPAREN)  {
  2142                JCNewCla ss newClas s = classC reatorRest (newpos, n ull, typeA rgs, t);
  2143                if (newC lass.def ! = null) {
  2144                    asse rt newClas s.def.mods .annotatio ns.isEmpty ();
  2145                    if ( newAnnotat ions.nonEm pty()) {
  2146                         // Add typ e and decl aration an notations  to the new  class;
  2147                         // com.sun .tools.jav ac.code.Ty peAnnotati ons.TypeAn notationPo sitions.vi sitNewClas s(JCNewCla ss)
  2148                         // will la ter remove  all type  annotation s and only  leave the
  2149                         // declara tion annot ations.
  2150                         newClass.d ef.mods.po s = earlie r(newClass .def.mods. pos, newAn notations. head.pos);
  2151                         newClass.d ef.mods.an notations  = newAnnot ations;
  2152                    }
  2153                } else {
  2154                    // h andle type  annotatio ns for ins tantiation s
  2155                    if ( newAnnotat ions.nonEm pty()) {
  2156                         t = insert Annotation sToMostInn er(t, newA nnotations , false);
  2157                         newClass.c lazz = t;
  2158                    }
  2159                }
  2160                return n ewClass;
  2161           }  else {
  2162                setError EndPos(tok en.pos);
  2163                reportSy ntaxError( token.pos,  "expected 2", LPAREN , LBRACKET );
  2164                t = toP( F.at(newpo s).NewClas s(null, ty peArgs, t,  List.<JCE xpression> nil(), nul l));
  2165                return t oP(F.at(ne wpos).Erro neous(List .<JCTree>o f(t)));
  2166           }
  2167       }
  2168  
  2169       /** In nerCreator  = [Annota tions] Ide nt [TypeAr guments] C lassCreato rRest
  2170        */
  2171       JCExpr ession inn erCreator( int newpos , List<JCE xpression>  typeArgs,  JCExpress ion encl)  {
  2172           Li st<JCAnnot ation> new Annotation s = typeAn notationsO pt();
  2173  
  2174           JC Expression  t = toP(F .at(token. pos).Ident (ident())) ;
  2175  
  2176           if  (newAnnot ations.non Empty()) {
  2177                t = toP( F.at(newAn notations. head.pos). AnnotatedT ype(newAnn otations,  t));
  2178           }
  2179  
  2180           if  (token.ki nd == LT)  {
  2181                int oldm ode = mode ;
  2182                checkGen erics();
  2183                t = type Arguments( t, true);
  2184                mode = o ldmode;
  2185           }
  2186           re turn class CreatorRes t(newpos,  encl, type Args, t);
  2187       }
  2188  
  2189       /** Ar rayCreator Rest = [An notations]  "[" ( "]"  BracketsO pt ArrayIn itializer
  2190        *                            | Express ion "]" {[ Annotation s]  "[" Ex pression " ]"} Bracke tsOpt )
  2191        */
  2192       JCExpr ession arr ayCreatorR est(int ne wpos, JCEx pression e lemtype) {
  2193           Li st<JCAnnot ation> ann os = typeA nnotations Opt();
  2194  
  2195           ac cept(LBRAC KET);
  2196           if  (token.ki nd == RBRA CKET) {
  2197                accept(R BRACKET);
  2198                elemtype  = bracket sOpt(elemt ype, annos );
  2199                if (toke n.kind ==  LBRACE) {
  2200                    JCNe wArray na  = (JCNewAr ray)arrayI nitializer (newpos, e lemtype);
  2201                    if ( annos.nonE mpty()) {
  2202                         // when an  array ini tializer i s present  then
  2203                         // the par sed annota tions shou ld target  the
  2204                         // new arr ay tree
  2205                         // bracket sOpt inser ts the ann otation in
  2206                         // elemtyp e, and it  needs to b e correcte d
  2207                         //
  2208                         JCAnnotate dType anno tated = (J CAnnotated Type)elemt ype;
  2209                         assert ann otated.ann otations = = annos;
  2210                         na.annotat ions = ann otated.ann otations;
  2211                         na.elemtyp e = annota ted.underl yingType;
  2212                    }
  2213                    retu rn na;
  2214                } else {
  2215                    JCEx pression t  = toP(F.a t(newpos). NewArray(e lemtype, L ist.<JCExp ression>ni l(), null) );
  2216                    retu rn syntaxE rror(token .pos, List .<JCTree>o f(t), "arr ay.dimensi on.missing ");
  2217                }
  2218           }  else {
  2219                ListBuff er<JCExpre ssion> dim s = new Li stBuffer<J CExpressio n>();
  2220  
  2221                // maint ain array  dimension  type annot ations
  2222                ListBuff er<List<JC Annotation >> dimAnno tations =  new ListBu ffer<>();
  2223                dimAnnot ations.app end(annos) ;
  2224  
  2225                dims.app end(parseE xpression( ));
  2226                accept(R BRACKET);
  2227                while (t oken.kind  == LBRACKE T
  2228                         || token.k ind == MON KEYS_AT) {
  2229                    List <JCAnnotat ion> maybe DimAnnos =  typeAnnot ationsOpt( );
  2230                    int  pos = toke n.pos;
  2231                    next Token();
  2232                    if ( token.kind  == RBRACK ET) {
  2233                         elemtype =  bracketsO ptCont(ele mtype, pos , maybeDim Annos);
  2234                    } el se {
  2235                         if (token. kind == RB RACKET) {  // no dime nsion
  2236                             elemty pe = brack etsOptCont (elemtype,  pos, mayb eDimAnnos) ;
  2237                         } else {
  2238                             dimAnn otations.a ppend(mayb eDimAnnos) ;
  2239                             dims.a ppend(pars eExpressio n());
  2240                             accept (RBRACKET) ;
  2241                         }
  2242                    }
  2243                }
  2244  
  2245                JCNewArr ay na = to P(F.at(new pos).NewAr ray(elemty pe, dims.t oList(), n ull));
  2246                na.dimAn notations  = dimAnnot ations.toL ist();
  2247                return n a;
  2248           }
  2249       }
  2250  
  2251       /** Cl assCreator Rest = Arg uments [Cl assBody]
  2252        */
  2253       JCNewC lass class CreatorRes t(int newp os,
  2254                                        JCExpr ession enc l,
  2255                                        List<J CExpressio n> typeArg s,
  2256                                        JCExpr ession t)
  2257       {
  2258           Li st<JCExpre ssion> arg s = argume nts();
  2259           JC ClassDecl  body = nul l;
  2260           if  (token.ki nd == LBRA CE) {
  2261                int pos  = token.po s;
  2262                List<JCT ree> defs  = classOrI nterfaceBo dy(names.e mpty, fals e);
  2263                JCModifi ers mods =  F.at(Posi tion.NOPOS ).Modifier s(0);
  2264                body = t oP(F.at(po s).Anonymo usClassDef (mods, def s));
  2265           }
  2266           re turn toP(F .at(newpos ).NewClass (encl, typ eArgs, t,  args, body ));
  2267       }
  2268  
  2269       /** Ar rayInitial izer = "{"  [Variable Initialize r {"," Var iableIniti alizer}] [ ","] "}"
  2270        */
  2271       JCExpr ession arr ayInitiali zer(int ne wpos, JCEx pression t ) {
  2272           ac cept(LBRAC E);
  2273           Li stBuffer<J CExpressio n> elems =  new ListB uffer<JCEx pression>( );
  2274           if  (token.ki nd == COMM A) {
  2275                nextToke n();
  2276           }  else if (t oken.kind  != RBRACE)  {
  2277                elems.ap pend(varia bleInitial izer());
  2278                while (t oken.kind  == COMMA)  {
  2279                    next Token();
  2280                    if ( token.kind  == RBRACE ) break;
  2281                    elem s.append(v ariableIni tializer() );
  2282                }
  2283           }
  2284           ac cept(RBRAC E);
  2285           re turn toP(F .at(newpos ).NewArray (t, List.< JCExpressi on>nil(),  elems.toLi st()));
  2286       }
  2287  
  2288       /** Va riableInit ializer =  ArrayIniti alizer | E xpression
  2289        */
  2290       public  JCExpress ion variab leInitiali zer() {
  2291           re turn token .kind == L BRACE ? ar rayInitial izer(token .pos, null ) : parseE xpression( );
  2292       }
  2293  
  2294       /** Pa rExpressio n = "(" Ex pression " )"
  2295        */
  2296       JCExpr ession par Expression () {
  2297           in t pos = to ken.pos;
  2298           ac cept(LPARE N);
  2299           JC Expression  t = parse Expression ();
  2300           ac cept(RPARE N);
  2301           re turn toP(F .at(pos).P arens(t));
  2302       }
  2303  
  2304       /** Bl ock = "{"  BlockState ments "}"
  2305        */
  2306       JCBloc k block(in t pos, lon g flags) {
  2307           ac cept(LBRAC E);
  2308           Li st<JCState ment> stat s = blockS tatements( );
  2309           JC Block t =  F.at(pos). Block(flag s, stats);
  2310           wh ile (token .kind == C ASE || tok en.kind ==  DEFAULT)  {
  2311                syntaxEr ror("orpha ned", toke n.kind);
  2312                switchBl ockStateme ntGroups() ;
  2313           }
  2314           //  the Block  node has  a field "e ndpos" for  first cha r of last  token, whi ch is
  2315           //  usually b ut not nec essarily t he last ch ar of the  last token .
  2316           t. endpos = t oken.pos;
  2317           ac cept(RBRAC E);
  2318           re turn toP(t );
  2319       }
  2320  
  2321       public  JCBlock b lock() {
  2322           re turn block (token.pos , 0);
  2323       }
  2324  
  2325       /** Bl ockStateme nts = { Bl ockStateme nt }
  2326        *  Bl ockStateme nt  = Loca lVariableD eclaration Statement
  2327        *                    | Clas sOrInterfa ceOrEnumDe claration
  2328        *                    | [Ide nt ":"] St atement
  2329        *  Lo calVariabl eDeclarati onStatemen t
  2330        *                    = { FI NAL | '@'  Annotation  } Type Va riableDecl arators "; "
  2331        */
  2332       @Suppr essWarning s("fallthr ough")
  2333       List<J CStatement > blockSta tements()  {
  2334           // todo: skip  to anchor  on error( ?)
  2335           Li stBuffer<J CStatement > stats =  new ListBu ffer<JCSta tement>();
  2336           wh ile (true)  {
  2337                List<JCS tatement>  stat = blo ckStatemen t();
  2338                if (stat .isEmpty() ) {
  2339                    retu rn stats.t oList();
  2340                } else {
  2341                    if ( token.pos  <= endPosT able.error EndPos) {
  2342                         skip(false , true, tr ue, true);
  2343                    }
  2344                    stat s.addAll(s tat);
  2345                }
  2346           }
  2347       }
  2348  
  2349       /*
  2350        * Thi s method p arses a st atement tr eating it  as a block , relaxing  the
  2351        * JLS  restricti ons, allow s us to pa rse more f aulty code , doing so
  2352        * ena bles us to  provide b etter and  accurate d iagnostics  to the us er.
  2353        */
  2354       JCStat ement pars eStatement AsBlock()  {
  2355           in t pos = to ken.pos;
  2356           Li st<JCState ment> stat s = blockS tatement() ;
  2357           if  (stats.is Empty()) {
  2358                JCErrone ous e = F. at(pos).Er roneous();
  2359                error(e,  "illegal. start.of.s tmt");
  2360                return F .at(pos).E xec(e);
  2361           }  else {
  2362                JCStatem ent first  = stats.he ad;
  2363                String e rror = nul l;
  2364                switch ( first.getT ag()) {
  2365                case CLA SSDEF:
  2366                    erro r = "class .not.allow ed";
  2367                    brea k;
  2368                  case 
D NS    F:
  2369                    erro r = "varia ble.not.al lowed";
  2370                    brea k;
  2371                }
  2372                if (erro r != null)  {
  2373                    erro r(first, e rror);
  2374                    List <JCBlock>  blist = Li st.of(F.at (first.pos ).Block(0,  stats));
  2375                    retu rn toP(F.a t(pos).Exe c(F.at(fir st.pos).Er roneous(bl ist)));
  2376                }
  2377                return f irst;
  2378           }
  2379       }
  2380  
  2381       @Suppr essWarning s("fallthr ough")
  2382       List<J CStatement > blockSta tement() {
  2383           // todo: skip  to anchor  on error( ?)
  2384           in t pos = to ken.pos;
  2385           sw itch (toke n.kind) {
  2386           ca se RBRACE:  case CASE : case DEF AULT: case  EOF:
  2387                return L ist.nil();
  2388           ca se LBRACE:  case IF:  case FOR:  case WHILE : case DO:  case TRY:
  2389           ca se SWITCH:  case SYNC HRONIZED:  case RETUR N: case TH ROW: case  BREAK:
  2390           ca se CONTINU E: case SE MI: case E LSE: case  FINALLY: c ase CATCH:
  2391                return L ist.of(par seStatemen t());
  2392           ca se MONKEYS _AT:
  2393           ca se FINAL:  {
  2394                Comment  dc = token .comment(C ommentStyl e.JAVADOC) ;
  2395                JCModifi ers mods =  modifiers Opt();
  2396                if (toke n.kind ==  INTERFACE  ||
  2397                    toke n.kind ==  CLASS ||
  2398                    allo wEnums &&  token.kind  == ENUM)  {
  2399                    retu rn List.of (classOrIn terfaceOrE numDeclara tion(mods,  dc));
  2400                } else {
  2401                    JCEx pression t  = parseTy pe();
  2402                    List Buffer<JCS tatement>  stats =
  2403                             variab leDeclarat ors(mods,  t, new Lis tBuffer<JC Statement> ());
  2404                    // A  "LocalVar iableDecla rationStat ement" sub sumes the  terminatin g semicolo n
  2405                    stor eEnd(stats .last(), t oken.endPo s);
  2406                    acce pt(SEMI);
  2407                    retu rn stats.t oList();
  2408                }
  2409           }
  2410           ca se ABSTRAC T: case ST RICTFP: {
  2411                Comment  dc = token .comment(C ommentStyl e.JAVADOC) ;
  2412                JCModifi ers mods =  modifiers Opt();
  2413                return L ist.of(cla ssOrInterf aceOrEnumD eclaration (mods, dc) );
  2414           }
  2415           ca se INTERFA CE:
  2416           ca se CLASS:
  2417                Comment  dc = token .comment(C ommentStyl e.JAVADOC) ;
  2418                return L ist.of(cla ssOrInterf aceOrEnumD eclaration (modifiers Opt(), dc) );
  2419           ca se ENUM:
  2420           ca se ASSERT:
  2421                if (allo wEnums &&  token.kind  == ENUM)  {
  2422                    erro r(token.po s, "local. enum");
  2423                    dc =  token.com ment(Comme ntStyle.JA VADOC);
  2424                    retu rn List.of (classOrIn terfaceOrE numDeclara tion(modif iersOpt(),  dc));
  2425                } else i f (allowAs serts && t oken.kind  == ASSERT)  {
  2426                    retu rn List.of (parseStat ement());
  2427                }
  2428                /* fall  through to  default * /
  2429           de fault:
  2430                Token pr evToken =  token;
  2431                JCExpres sion t = t erm(EXPR |  TYPE);
  2432                if (toke n.kind ==  COLON && t .hasTag(ID ENT)) {
  2433                    next Token();
  2434                    JCSt atement st at = parse Statement( );
  2435                    retu rn List.<J CStatement >of(F.at(p os).Labell ed(prevTok en.name(),  stat));
  2436                } else i f ((lastmo de & TYPE)  != 0 && L AX_IDENTIF IER.accept s(token.ki nd)) {
  2437                    pos  = token.po s;
  2438                    JCMo difiers mo ds = F.at( Position.N OPOS).Modi fiers(0);
  2439                    F.at (pos);
  2440                    List Buffer<JCS tatement>  stats =
  2441                             variab leDeclarat ors(mods,  t, new Lis tBuffer<JC Statement> ());
  2442                    // A  "LocalVar iableDecla rationStat ement" sub sumes the  terminatin g semicolo n
  2443                    stor eEnd(stats .last(), t oken.endPo s);
  2444                    acce pt(SEMI);
  2445                    retu rn stats.t oList();
  2446                } else {
  2447                    // T his Exec i s an "Expr essionStat ement"; it  subsumes  the termin ating semi colon
  2448                    JCEx pressionSt atement ex pr = to(F. at(pos).Ex ec(checkEx prStat(t)) );
  2449                    acce pt(SEMI);
  2450                    retu rn List.<J CStatement >of(expr);
  2451                }
  2452           }
  2453       }
  2454  
  2455       /** St atement =
  2456        *        Block
  2457        *      | IF ParE xpression  Statement  [ELSE Stat ement]
  2458        *      | FOR "("  ForInitOp t ";" [Exp ression] " ;" ForUpda teOpt ")"  Statement
  2459        *      | FOR "("  FormalPar ameter : E xpression  ")" Statem ent
  2460        *      | WHILE P arExpressi on Stateme nt
  2461        *      | DO Stat ement WHIL E ParExpre ssion ";"
  2462        *      | TRY Blo ck ( Catch es | [Catc hes] Final lyPart )
  2463        *      | TRY "("  ResourceS pecificati on ";"opt  ")" Block  [Catches]  [FinallyPa rt]
  2464        *      | SWITCH  ParExpress ion "{" Sw itchBlockS tatementGr oups "}"
  2465        *      | SYNCHRO NIZED ParE xpression  Block
  2466        *      | RETURN  [Expressio n] ";"
  2467        *      | THROW E xpression  ";"
  2468        *      | BREAK [ Ident] ";"
  2469        *      | CONTINU E [Ident]  ";"
  2470        *      | ASSERT  Expression  [ ":" Exp ression ]  ";"
  2471        *      | ";"
  2472        *      | Express ionStateme nt
  2473        *      | Ident " :" Stateme nt
  2474        */
  2475       @Suppr essWarning s("fallthr ough")
  2476       public  JCStateme nt parseSt atement()  {
  2477           in t pos = to ken.pos;
  2478           sw itch (toke n.kind) {
  2479           ca se LBRACE:
  2480                return b lock();
  2481           ca se IF: {
  2482                nextToke n();
  2483                JCExpres sion cond  = parExpre ssion();
  2484                JCStatem ent thenpa rt = parse StatementA sBlock();
  2485                JCStatem ent elsepa rt = null;
  2486                if (toke n.kind ==  ELSE) {
  2487                    next Token();
  2488                    else part = par seStatemen tAsBlock() ;
  2489                }
  2490                return F .at(pos).I f(cond, th enpart, el separt);
  2491           }
  2492           ca se FOR: {
  2493                nextToke n();
  2494                accept(L PAREN);
  2495                List<JCS tatement>  inits = to ken.kind = = SEMI ? L ist.<JCSta tement>nil () : forIn it();
  2496                if (init s.length()  == 1 &&
  2497                      inits.head .hasTag(
D NS    F) &&
  2498                    ((JC VariableDe cl) inits. head).init  == null & &
  2499                    toke n.kind ==  COLON) {
  2500                    chec kForeach() ;
  2501                    JCVa riableDecl  var = (JC VariableDe cl)inits.h ead;
  2502                    acce pt(COLON);
  2503                    JCEx pression e xpr = pars eExpressio n();
  2504                    acce pt(RPAREN) ;
  2505                    JCSt atement bo dy = parse StatementA sBlock();
  2506                    retu rn F.at(po s).Foreach Loop(var,  expr, body );
  2507                } else {
  2508                    acce pt(SEMI);
  2509                    JCEx pression c ond = toke n.kind ==  SEMI ? nul l : parseE xpression( );
  2510                    acce pt(SEMI);
  2511                    List <JCExpress ionStateme nt> steps  = token.ki nd == RPAR EN ? List. <JCExpress ionStateme nt>nil() :  forUpdate ();
  2512                    acce pt(RPAREN) ;
  2513                    JCSt atement bo dy = parse StatementA sBlock();
  2514                    retu rn F.at(po s).ForLoop (inits, co nd, steps,  body);
  2515                }
  2516           }
  2517           ca se WHILE:  {
  2518                nextToke n();
  2519                JCExpres sion cond  = parExpre ssion();
  2520                JCStatem ent body =  parseStat ementAsBlo ck();
  2521                return F .at(pos).W hileLoop(c ond, body) ;
  2522           }
  2523           ca se DO: {
  2524                nextToke n();
  2525                JCStatem ent body =  parseStat ementAsBlo ck();
  2526                accept(W HILE);
  2527                JCExpres sion cond  = parExpre ssion();
  2528                JCDoWhil eLoop t =  to(F.at(po s).DoLoop( body, cond ));
  2529                accept(S EMI);
  2530                return t ;
  2531           }
  2532           ca se TRY: {
  2533                nextToke n();
  2534                List<JCT ree> resou rces = Lis t.<JCTree> nil();
  2535                if (toke n.kind ==  LPAREN) {
  2536                    chec kTryWithRe sources();
  2537                    next Token();
  2538                    reso urces = re sources();
  2539                    acce pt(RPAREN) ;
  2540                }
  2541                JCBlock  body = blo ck();
  2542                ListBuff er<JCCatch > catchers  = new Lis tBuffer<JC Catch>();
  2543                JCBlock  finalizer  = null;
  2544                if (toke n.kind ==  CATCH || t oken.kind  == FINALLY ) {
  2545                    whil e (token.k ind == CAT CH) catche rs.append( catchClaus e());
  2546                    if ( token.kind  == FINALL Y) {
  2547                         nextToken( );
  2548                         finalizer  = block();
  2549                    }
  2550                } else {
  2551                    if ( allowTWR)  {
  2552                         if (resour ces.isEmpt y())
  2553                             error( pos, "try. without.ca tch.finall y.or.resou rce.decls" );
  2554                    } el se
  2555                         error(pos,  "try.with out.catch. or.finally ");
  2556                }
  2557                return F .at(pos).T ry(resourc es, body,  catchers.t oList(), f inalizer);
  2558           }
  2559           ca se SWITCH:  {
  2560                nextToke n();
  2561                JCExpres sion selec tor = parE xpression( );
  2562                accept(L BRACE);
  2563                List<JCC ase> cases  = switchB lockStatem entGroups( );
  2564                JCSwitch  t = to(F. at(pos).Sw itch(selec tor, cases ));
  2565                accept(R BRACE);
  2566                return t ;
  2567           }
  2568           ca se SYNCHRO NIZED: {
  2569                nextToke n();
  2570                JCExpres sion lock  = parExpre ssion();
  2571                JCBlock  body = blo ck();
  2572                return F .at(pos).S ynchronize d(lock, bo dy);
  2573           }
  2574           ca se RETURN:  {
  2575                nextToke n();
  2576                JCExpres sion resul t = token. kind == SE MI ? null  : parseExp ression();
  2577                JCReturn  t = to(F. at(pos).Re turn(resul t));
  2578                accept(S EMI);
  2579                return t ;
  2580           }
  2581           ca se THROW:  {
  2582                nextToke n();
  2583                JCExpres sion exc =  parseExpr ession();
  2584                JCThrow  t = to(F.a t(pos).Thr ow(exc));
  2585                accept(S EMI);
  2586                return t ;
  2587           }
  2588           ca se BREAK:  {
  2589                nextToke n();
  2590                Name lab el = LAX_I DENTIFIER. accepts(to ken.kind)  ? ident()  : null;
  2591                JCBreak  t = to(F.a t(pos).Bre ak(label)) ;
  2592                accept(S EMI);
  2593                return t ;
  2594           }
  2595           ca se CONTINU E: {
  2596                nextToke n();
  2597                Name lab el = LAX_I DENTIFIER. accepts(to ken.kind)  ? ident()  : null;
  2598                JCContin ue t =  to (F.at(pos) .Continue( label));
  2599                accept(S EMI);
  2600                return t ;
  2601           }
  2602           ca se SEMI:
  2603                nextToke n();
  2604                return t oP(F.at(po s).Skip()) ;
  2605           ca se ELSE:
  2606                int else Pos = toke n.pos;
  2607                nextToke n();
  2608                return d oRecover(e lsePos, Ba sicErrorRe coveryActi on.BLOCK_S TMT, "else .without.i f");
  2609           ca se FINALLY :
  2610                int fina llyPos = t oken.pos;
  2611                nextToke n();
  2612                return d oRecover(f inallyPos,  BasicErro rRecoveryA ction.BLOC K_STMT, "f inally.wit hout.try") ;
  2613           ca se CATCH:
  2614                return d oRecover(t oken.pos,  BasicError RecoveryAc tion.CATCH _CLAUSE, " catch.with out.try");
  2615           ca se ASSERT:  {
  2616                if (allo wAsserts & & token.ki nd == ASSE RT) {
  2617                    next Token();
  2618                    JCEx pression a ssertion =  parseExpr ession();
  2619                    JCEx pression m essage = n ull;
  2620                    if ( token.kind  == COLON)  {
  2621                         nextToken( );
  2622                         message =  parseExpre ssion();
  2623                    }
  2624                    JCAs sert t = t o(F.at(pos ).Assert(a ssertion,  message));
  2625                    acce pt(SEMI);
  2626                    retu rn t;
  2627                }
  2628                /* else  fall throu gh to defa ult case * /
  2629           }
  2630           ca se ENUM:
  2631           de fault:
  2632                Token pr evToken =  token;
  2633                JCExpres sion expr  = parseExp ression();
  2634                if (toke n.kind ==  COLON && e xpr.hasTag (IDENT)) {
  2635                    next Token();
  2636                    JCSt atement st at = parse Statement( );
  2637                    retu rn F.at(po s).Labelle d(prevToke n.name(),  stat);
  2638                } else {
  2639                    // T his Exec i s an "Expr essionStat ement"; it  subsumes  the termin ating semi colon
  2640                    JCEx pressionSt atement st at = to(F. at(pos).Ex ec(checkEx prStat(exp r)));
  2641                    acce pt(SEMI);
  2642                    retu rn stat;
  2643                }
  2644           }
  2645       }
  2646  
  2647       privat e JCStatem ent doReco ver(int st artPos, Er rorRecover yAction ac tion, Stri ng key) {
  2648           in t errPos =  S.errPos( );
  2649           JC Tree stm =  action.do Recover(th is);
  2650           S. errPos(err Pos);
  2651           re turn toP(F .Exec(synt axError(st artPos, Li st.<JCTree >of(stm),  key)));
  2652       }
  2653  
  2654       /** Ca tchClause      = CATC H "(" Form alParamete r ")" Bloc k
  2655        * TOD O: the "Fo rmalParame ter" is no t correct,  it uses t he special  "catchTyp es" rule b elow.
  2656        */
  2657       protec ted JCCatc h catchCla use() {
  2658           in t pos = to ken.pos;
  2659           ac cept(CATCH );
  2660           ac cept(LPARE N);
  2661           JC Modifiers  mods = opt Final(Flag s.PARAMETE R);
  2662           Li st<JCExpre ssion> cat chTypes =  catchTypes ();
  2663           JC Expression  paramType  = catchTy pes.size()  > 1 ?
  2664                    toP( F.at(catch Types.head .getStartP osition()) .TypeUnion (catchType s)) :
  2665                    catc hTypes.hea d;
  2666           JC VariableDe cl formal  = variable Declarator Id(mods, p aramType);
  2667           ac cept(RPARE N);
  2668           JC Block body  = block() ;
  2669           re turn F.at( pos).Catch (formal, b ody);
  2670       }
  2671  
  2672       List<J CExpressio n> catchTy pes() {
  2673           Li stBuffer<J CExpressio n> catchTy pes = new  ListBuffer <>();
  2674           ca tchTypes.a dd(parseTy pe());
  2675           wh ile (token .kind == B AR) {
  2676                checkMul ticatch();
  2677                nextToke n();
  2678                // Inste ad of qual ident this  is now pa rseType.
  2679                // But w ould that  allow too  much, e.g.  arrays or  generics?
  2680                catchTyp es.add(par seType());
  2681           }
  2682           re turn catch Types.toLi st();
  2683       }
  2684  
  2685       /** Sw itchBlockS tatementGr oups = { S witchBlock StatementG roup }
  2686        *  Sw itchBlockS tatementGr oup = Swit chLabel Bl ockStateme nts
  2687        *  Sw itchLabel  = CASE Con stantExpre ssion ":"  | DEFAULT  ":"
  2688        */
  2689       List<J CCase> swi tchBlockSt atementGro ups() {
  2690           Li stBuffer<J CCase> cas es = new L istBuffer< JCCase>();
  2691           wh ile (true)  {
  2692                int pos  = token.po s;
  2693                switch ( token.kind ) {
  2694                case CAS E:
  2695                case DEF AULT:
  2696                    case s.append(s witchBlock StatementG roup());
  2697                    brea k;
  2698                case RBR ACE: case  EOF:
  2699                    retu rn cases.t oList();
  2700                default:
  2701                    next Token(); / / to ensur e progress
  2702                    synt axError(po s, "expect ed3",
  2703                         CASE, DEFA ULT, RBRAC E);
  2704                }
  2705           }
  2706       }
  2707  
  2708       protec ted JCCase  switchBlo ckStatemen tGroup() {
  2709           in t pos = to ken.pos;
  2710           Li st<JCState ment> stat s;
  2711           JC Case c;
  2712           sw itch (toke n.kind) {
  2713           ca se CASE:
  2714                nextToke n();
  2715                JCExpres sion pat =  parseExpr ession();
  2716                accept(C OLON);
  2717                stats =  blockState ments();
  2718                c = F.at (pos).Case (pat, stat s);
  2719                if (stat s.isEmpty( ))
  2720                    stor eEnd(c, S. prevToken( ).endPos);
  2721                return c ;
  2722           ca se DEFAULT :
  2723                nextToke n();
  2724                accept(C OLON);
  2725                stats =  blockState ments();
  2726                c = F.at (pos).Case (null, sta ts);
  2727                if (stat s.isEmpty( ))
  2728                    stor eEnd(c, S. prevToken( ).endPos);
  2729                return c ;
  2730           }
  2731           th row new As sertionErr or("should  not reach  here");
  2732       }
  2733  
  2734       /** Mo reStatemen tExpressio ns = { COM MA Stateme ntExpressi on }
  2735        */
  2736       <T ext ends ListB uffer<? su per JCExpr essionStat ement>> T  moreStatem entExpress ions(int p os,
  2737                                                                             JC Expression  first,
  2738                                                                             T  stats) {
  2739           //  This Exec  is a "Sta tementExpr ession"; i t subsumes  no termin ating toke n
  2740           st ats.append (toP(F.at( pos).Exec( checkExprS tat(first) )));
  2741           wh ile (token .kind == C OMMA) {
  2742                nextToke n();
  2743                pos = to ken.pos;
  2744                JCExpres sion t = p arseExpres sion();
  2745                // This  Exec is a  "Statement Expression "; it subs umes no te rminating  token
  2746                stats.ap pend(toP(F .at(pos).E xec(checkE xprStat(t) )));
  2747           }
  2748           re turn stats ;
  2749       }
  2750  
  2751       /** Fo rInit = St atementExp ression Mo reStatemen tExpressio ns
  2752        *            |   { FINAL |  '@' Annota tion } Typ e Variable Declarator s
  2753        */
  2754       List<J CStatement > forInit( ) {
  2755           Li stBuffer<J CStatement > stats =  new ListBu ffer<>();
  2756           in t pos = to ken.pos;
  2757           if  (token.ki nd == FINA L || token .kind == M ONKEYS_AT)  {
  2758                return v ariableDec larators(o ptFinal(0) , parseTyp e(), stats ).toList() ;
  2759           }  else {
  2760                JCExpres sion t = t erm(EXPR |  TYPE);
  2761                if ((las tmode & TY PE) != 0 & & LAX_IDEN TIFIER.acc epts(token .kind)) {
  2762                    retu rn variabl eDeclarato rs(mods(po s, 0, List .<JCAnnota tion>nil() ), t, stat s).toList( );
  2763                } else i f ((lastmo de & TYPE)  != 0 && t oken.kind  == COLON)  {
  2764                    erro r(pos, "ba d.initiali zer", "for -loop");
  2765                    retu rn List.of ((JCStatem ent)F.at(p os).VarDef (null, nul l, t, null ));
  2766                } else {
  2767                    retu rn moreSta tementExpr essions(po s, t, stat s).toList( );
  2768                }
  2769           }
  2770       }
  2771  
  2772       /** Fo rUpdate =  StatementE xpression  MoreStatem entExpress ions
  2773        */
  2774       List<J CExpressio nStatement > forUpdat e() {
  2775           re turn moreS tatementEx pressions( token.pos,
  2776                                               parseExpre ssion(),
  2777                                               new ListBu ffer<JCExp ressionSta tement>()) .toList();
  2778       }
  2779  
  2780       /** An notationsO pt = { '@'  Annotatio n }
  2781        *
  2782        * @pa ram kind W hether to  parse an A NNOTATION  or TYPE_AN NOTATION
  2783        */
  2784       List<J CAnnotatio n> annotat ionsOpt(Ta g kind) {
  2785           if  (token.ki nd != MONK EYS_AT) re turn List. nil(); //  optimizati on
  2786           Li stBuffer<J CAnnotatio n> buf = n ew ListBuf fer<JCAnno tation>();
  2787           in t prevmode  = mode;
  2788           wh ile (token .kind == M ONKEYS_AT)  {
  2789                int pos  = token.po s;
  2790                nextToke n();
  2791                buf.appe nd(annotat ion(pos, k ind));
  2792           }
  2793           la stmode = m ode;
  2794           mo de = prevm ode;
  2795           Li st<JCAnnot ation> ann otations =  buf.toLis t();
  2796  
  2797           re turn annot ations;
  2798       }
  2799  
  2800       List<J CAnnotatio n> typeAnn otationsOp t() {
  2801           Li st<JCAnnot ation> ann otations =  annotatio nsOpt(Tag. TYPE_ANNOT ATION);
  2802           re turn annot ations;
  2803       }
  2804  
  2805       /** Mo difiersOpt  = { Modif ier }
  2806        *  Mo difier = P UBLIC | PR OTECTED |  PRIVATE |  STATIC | A BSTRACT |  FINAL
  2807        *            | N ATIVE | SY NCHRONIZED  | TRANSIE NT | VOLAT ILE | "@"
  2808        *            | " @" Annotat ion
  2809        */
  2810       JCModi fiers modi fiersOpt()  {
  2811           re turn modif iersOpt(nu ll);
  2812       }
  2813       protec ted JCModi fiers modi fiersOpt(J CModifiers  partial)  {
  2814           lo ng flags;
  2815           Li stBuffer<J CAnnotatio n> annotat ions = new  ListBuffe r<JCAnnota tion>();
  2816           in t pos;
  2817           if  (partial  == null) {
  2818                flags =  0;
  2819                pos = to ken.pos;
  2820           }  else {
  2821                flags =  partial.fl ags;
  2822                annotati ons.append List(parti al.annotat ions);
  2823                pos = pa rtial.pos;
  2824           }
  2825           if  (token.de precatedFl ag()) {
  2826                flags |=  Flags.DEP RECATED;
  2827           }
  2828           in t lastPos;
  2829       loop:
  2830           wh ile (true)  {
  2831                long fla g;
  2832                switch ( token.kind ) {
  2833                case PRI VATE     :  flag = Fl ags.PRIVAT E; break;
  2834                case PRO TECTED   :  flag = Fl ags.PROTEC TED; break ;
  2835                case PUB LIC      :  flag = Fl ags.PUBLIC ; break;
  2836                case STA TIC      :  flag = Fl ags.STATIC ; break;
  2837                case TRA NSIENT   :  flag = Fl ags.TRANSI ENT; break ;
  2838                case FIN AL       :  flag = Fl ags.FINAL;  break;
  2839                case ABS TRACT    :  flag = Fl ags.ABSTRA CT; break;
  2840                case NAT IVE      :  flag = Fl ags.NATIVE ; break;
  2841                case VOL ATILE    :  flag = Fl ags.VOLATI LE; break;
  2842                case SYN CHRONIZED:  flag = Fl ags.SYNCHR ONIZED; br eak;
  2843                case STR ICTFP    :  flag = Fl ags.STRICT FP; break;
  2844                case MON KEYS_AT  :  flag = Fl ags.ANNOTA TION; brea k;
  2845                case DEF AULT     :  checkDefa ultMethods (); flag =  Flags.DEF AULT; brea k;
  2846                case ERR OR       :  flag = 0;  nextToken (); break;
  2847                default:  break loo p;
  2848                }
  2849                if ((fla gs & flag)  != 0) err or(token.p os, "repea ted.modifi er");
  2850                lastPos  = token.po s;
  2851                nextToke n();
  2852                if (flag  == Flags. ANNOTATION ) {
  2853                    chec kAnnotatio ns();
  2854                    if ( token.kind  != INTERF ACE) {
  2855                         JCAnnotati on ann = a nnotation( lastPos, T ag.ANNOTAT ION);
  2856                         // if firs t modifier  is an ann otation, s et pos to  annotation 's.
  2857                         if (flags  == 0 && an notations. isEmpty())
  2858                             pos =  ann.pos;
  2859                         annotation s.append(a nn);
  2860                         flag = 0;
  2861                    }
  2862                }
  2863                flags |=  flag;
  2864           }
  2865           sw itch (toke n.kind) {
  2866           ca se ENUM: f lags |= Fl ags.ENUM;  break;
  2867           ca se INTERFA CE: flags  |= Flags.I NTERFACE;  break;
  2868           de fault: bre ak;
  2869           }
  2870  
  2871           re turn mods( pos, flags , annotati ons.toList ());
  2872       }
  2873       //wher e
  2874           JC Modifiers  mods(int p os, long f lags, List <JCAnnotat ion> annot ations) {
  2875                /* A mod ifiers tre e with no  modifier t okens or a nnotations
  2876                 * has n o text pos ition. */
  2877                if ((fla gs & (Flag s.Modifier Flags | Fl ags.ANNOTA TION)) ==  0 && annot ations.isE mpty())
  2878                    pos  = Position .NOPOS;
  2879  
  2880                JCModifi ers mods =  F.at(pos) .Modifiers (flags, an notations) ;
  2881                if (pos  != Positio n.NOPOS)
  2882                    stor eEnd(mods,  S.prevTok en().endPo s);
  2883                return m ods;
  2884           }
  2885  
  2886       /** An notation                = "@" Qu alident [  "(" Annota tionFieldV alues ")"  ]
  2887        *
  2888        * @pa ram pos po sition of  "@" token
  2889        * @pa ram kind W hether to  parse an A NNOTATION  or TYPE_AN NOTATION
  2890        */
  2891       JCAnno tation ann otation(in t pos, Tag  kind) {
  2892           //  accept(AT ); // AT c onsumed by  caller
  2893           ch eckAnnotat ions();
  2894           if  (kind ==  Tag.TYPE_A NNOTATION)  {
  2895                checkTyp eAnnotatio ns();
  2896           }
  2897           JC Tree ident  = qualide nt(false);
  2898           Li st<JCExpre ssion> fie ldValues =  annotatio nFieldValu esOpt();
  2899           JC Annotation  ann;
  2900           if  (kind ==  Tag.ANNOTA TION) {
  2901                ann = F. at(pos).An notation(i dent, fiel dValues);
  2902           }  else if (k ind == Tag .TYPE_ANNO TATION) {
  2903                ann = F. at(pos).Ty peAnnotati on(ident,  fieldValue s);
  2904           }  else {
  2905                throw ne w Assertio nError("Un handled an notation k ind: " + k ind);
  2906           }
  2907  
  2908           st oreEnd(ann , S.prevTo ken().endP os);
  2909           re turn ann;
  2910       }
  2911  
  2912       List<J CExpressio n> annotat ionFieldVa luesOpt()  {
  2913           re turn (toke n.kind ==  LPAREN) ?  annotation FieldValue s() : List .<JCExpres sion>nil() ;
  2914       }
  2915  
  2916       /** An notationFi eldValues    = "(" [  Annotation FieldValue  { "," Ann otationFie ldValue }  ] ")" */
  2917       List<J CExpressio n> annotat ionFieldVa lues() {
  2918           ac cept(LPARE N);
  2919           Li stBuffer<J CExpressio n> buf = n ew ListBuf fer<JCExpr ession>();
  2920           if  (token.ki nd != RPAR EN) {
  2921                buf.appe nd(annotat ionFieldVa lue());
  2922                while (t oken.kind  == COMMA)  {
  2923                    next Token();
  2924                    buf. append(ann otationFie ldValue()) ;
  2925                }
  2926           }
  2927           ac cept(RPARE N);
  2928           re turn buf.t oList();
  2929       }
  2930  
  2931       /** An notationFi eldValue     = Annota tionValue
  2932        *                             | Identi fier "=" A nnotationV alue
  2933        */
  2934       JCExpr ession ann otationFie ldValue()  {
  2935           if  (LAX_IDEN TIFIER.acc epts(token .kind)) {
  2936                mode = E XPR;
  2937                JCExpres sion t1 =  term1();
  2938                if (t1.h asTag(IDEN T) && toke n.kind ==  EQ) {
  2939                    int  pos = toke n.pos;
  2940                    acce pt(EQ);
  2941                    JCEx pression v  = annotat ionValue() ;
  2942                    retu rn toP(F.a t(pos).Ass ign(t1, v) );
  2943                } else {
  2944                    retu rn t1;
  2945                }
  2946           }
  2947           re turn annot ationValue ();
  2948       }
  2949  
  2950       /* Ann otationVal ue           = Condit ionalExpre ssion
  2951        *                             | Annota tion
  2952        *                             | "{" [  Annotation Value { ", " Annotati onValue }  ] [","] "} "
  2953        */
  2954       JCExpr ession ann otationVal ue() {
  2955           in t pos;
  2956           sw itch (toke n.kind) {
  2957           ca se MONKEYS _AT:
  2958                pos = to ken.pos;
  2959                nextToke n();
  2960                return a nnotation( pos, Tag.A NNOTATION) ;
  2961           ca se LBRACE:
  2962                pos = to ken.pos;
  2963                accept(L BRACE);
  2964                ListBuff er<JCExpre ssion> buf  = new Lis tBuffer<JC Expression >();
  2965                if (toke n.kind ==  COMMA) {
  2966                    next Token();
  2967                } else i f (token.k ind != RBR ACE) {
  2968                    buf. append(ann otationVal ue());
  2969                    whil e (token.k ind == COM MA) {
  2970                         nextToken( );
  2971                         if (token. kind == RB RACE) brea k;
  2972                         buf.append (annotatio nValue());
  2973                    }
  2974                }
  2975                accept(R BRACE);
  2976                return t oP(F.at(po s).NewArra y(null, Li st.<JCExpr ession>nil (), buf.to List()));
  2977           de fault:
  2978                mode = E XPR;
  2979                return t erm1();
  2980           }
  2981       }
  2982  
  2983       /** Va riableDecl arators =  VariableDe clarator {  "," Varia bleDeclara tor }
  2984        */
  2985       public  <T extend s ListBuff er<? super  JCVariabl eDecl>> T  variableDe clarators( JCModifier s mods,
  2986                                                                                   JCExpre ssion type ,
  2987                                                                                   T vdefs )
  2988       {
  2989           re turn varia bleDeclara torsRest(t oken.pos,  mods, type , ident(),  false, nu ll, vdefs) ;
  2990       }
  2991  
  2992       /** Va riableDecl aratorsRes t = Variab leDeclarat orRest { " ," Variabl eDeclarato r }
  2993        *  Co nstantDecl aratorsRes t = Consta ntDeclarat orRest { " ," Constan tDeclarato r }
  2994        *
  2995        *  @p aram reqIn it  Is an  initialize r always r equired?
  2996        *  @p aram dc        The do cumentatio n comment  for the va riable dec larations,  or null.
  2997        */
  2998       <T ext ends ListB uffer<? su per JCVari ableDecl>>  T variabl eDeclarato rsRest(int  pos,
  2999                                                                              J CModifiers  mods,
  3000                                                                              J CExpressio n type,
  3001                                                                              N ame name,
  3002                                                                              b oolean req Init,
  3003                                                                              C omment dc,
  3004                                                                              T  vdefs)
  3005       {
  3006           vd efs.append (variableD eclaratorR est(pos, m ods, type,  name, req Init, dc)) ;
  3007           wh ile (token .kind == C OMMA) {
  3008                // All b ut last of  multiple  declarator s subsume  a comma
  3009                storeEnd ((JCTree)v defs.last( ), token.e ndPos);
  3010                nextToke n();
  3011                vdefs.ap pend(varia bleDeclara tor(mods,  type, reqI nit, dc));
  3012           }
  3013           re turn vdefs ;
  3014       }
  3015  
  3016       /** Va riableDecl arator = I dent Varia bleDeclara torRest
  3017        *  Co nstantDecl arator = I dent Const antDeclara torRest
  3018        */
  3019       JCVari ableDecl v ariableDec larator(JC Modifiers  mods, JCEx pression t ype, boole an reqInit , Comment  dc) {
  3020           re turn varia bleDeclara torRest(to ken.pos, m ods, type,  ident(),  reqInit, d c);
  3021       }
  3022  
  3023       /** Va riableDecl aratorRest  = Bracket sOpt ["="  VariableIn itializer]
  3024        *  Co nstantDecl aratorRest  = Bracket sOpt "=" V ariableIni tializer
  3025        *
  3026        *  @p aram reqIn it  Is an  initialize r always r equired?
  3027        *  @p aram dc        The do cumentatio n comment  for the va riable dec larations,  or null.
  3028        */
  3029       JCVari ableDecl v ariableDec laratorRes t(int pos,  JCModifie rs mods, J CExpressio n type, Na me name,
  3030                                        boolea n reqInit,  Comment d c) {
  3031           ty pe = brack etsOpt(typ e);
  3032           JC Expression  init = nu ll;
  3033           if  (token.ki nd == EQ)  {
  3034                nextToke n();
  3035                init = v ariableIni tializer() ;
  3036           }
  3037           el se if (req Init) synt axError(to ken.pos, " expected",  EQ);
  3038           JC VariableDe cl result  =
  3039                toP(F.at (pos).VarD ef(mods, n ame, type,  init));
  3040           at tach(resul t, dc);
  3041           re turn resul t;
  3042       }
  3043  
  3044       /** Va riableDecl aratorId =  Ident Bra cketsOpt
  3045        */
  3046       JCVari ableDecl v ariableDec laratorId( JCModifier s mods, JC Expression  type) {
  3047           re turn varia bleDeclara torId(mods , type, fa lse);
  3048       }
  3049       //wher e
  3050       JCVari ableDecl v ariableDec laratorId( JCModifier s mods, JC Expression  type, boo lean lambd aParameter ) {
  3051           in t pos = to ken.pos;
  3052           Na me name;
  3053           if  (lambdaPa rameter &&  token.kin d == UNDER SCORE) {
  3054                log.erro r(pos, "un derscore.a s.identifi er.in.lamb da");
  3055                name = t oken.name( );
  3056                nextToke n();
  3057           }  else {
  3058                if (allo wThisIdent ) {
  3059                    JCEx pression p n = qualid ent(false) ;
  3060                    if ( pn.hasTag( Tag.IDENT)  && ((JCId ent)pn).na me != name s._this) {
  3061                         name = ((J CIdent)pn) .name;
  3062                    } el se {
  3063                         if ((mods. flags & Fl ags.VARARG S) != 0) {
  3064                             log.er ror(token. pos, "vara rgs.and.re ceiver");
  3065                         }
  3066                         if (token. kind == LB RACKET) {
  3067                             log.er ror(token. pos, "arra y.and.rece iver");
  3068                         }
  3069                         return toP (F.at(pos) .ReceiverV arDef(mods , pn, type ));
  3070                    }
  3071                } else {
  3072                    name  = ident() ;
  3073                }
  3074           }
  3075           if  ((mods.fl ags & Flag s.VARARGS)  != 0 &&
  3076                    toke n.kind ==  LBRACKET)  {
  3077                log.erro r(token.po s, "vararg s.and.old. array.synt ax");
  3078           }
  3079           ty pe = brack etsOpt(typ e);
  3080           re turn toP(F .at(pos).V arDef(mods , name, ty pe, null)) ;
  3081       }
  3082  
  3083       /** Re sources =  Resource {  ";" Resou rces }
  3084        */
  3085       List<J CTree> res ources() {
  3086           Li stBuffer<J CTree> def s = new Li stBuffer<J CTree>();
  3087           de fs.append( resource() );
  3088           wh ile (token .kind == S EMI) {
  3089                // All b ut last of  multiple  declarator s must sub sume a sem icolon
  3090                storeEnd (defs.last (), token. endPos);
  3091                int semi ColonPos =  token.pos ;
  3092                nextToke n();
  3093                if (toke n.kind ==  RPAREN) {  // Optiona l trailing  semicolon
  3094                                             / / after la st resourc e
  3095                    brea k;
  3096                }
  3097                defs.app end(resour ce());
  3098           }
  3099           re turn defs. toList();
  3100       }
  3101  
  3102       /** Re source = V ariableMod ifiersOpt  Type Varia bleDeclara torId = Ex pression
  3103        */
  3104       protec ted JCTree  resource( ) {
  3105           JC Modifiers  optFinal =  optFinal( Flags.FINA L);
  3106           JC Expression  type = pa rseType();
  3107           in t pos = to ken.pos;
  3108           Na me ident =  ident();
  3109           re turn varia bleDeclara torRest(po s, optFina l, type, i dent, true , null);
  3110       }
  3111  
  3112       /** Co mpilationU nit = [ {  "@" Annota tion } PAC KAGE Quali dent ";"]  {ImportDec laration}  {TypeDecla ration}
  3113        */
  3114       public  JCTree.JC Compilatio nUnit pars eCompilati onUnit() {
  3115           To ken firstT oken = tok en;
  3116           JC Expression  pid = nul l;
  3117           JC Modifiers  mods = nul l;
  3118           bo olean cons umedToplev elDoc = fa lse;
  3119           bo olean seen Import = f alse;
  3120           bo olean seen Package =  false;
  3121           Li st<JCAnnot ation> pac kageAnnota tions = Li st.nil();
  3122           if  (token.ki nd == MONK EYS_AT)
  3123                mods = m odifiersOp t();
  3124  
  3125           if  (token.ki nd == PACK AGE) {
  3126                seenPack age = true ;
  3127                if (mods  != null)  {
  3128                    chec kNoMods(mo ds.flags);
  3129                    pack ageAnnotat ions = mod s.annotati ons;
  3130                    mods  = null;
  3131                }
  3132                nextToke n();
  3133                pid = qu alident(fa lse);
  3134                accept(S EMI);
  3135           }
  3136           Li stBuffer<J CTree> def s = new Li stBuffer<J CTree>();
  3137           bo olean chec kForImport s = true;
  3138           bo olean firs tTypeDecl  = true;
  3139           wh ile (token .kind != E OF) {
  3140                if (toke n.pos > 0  && token.p os <= endP osTable.er rorEndPos)  {
  3141                    // e rror recov ery
  3142                    skip (checkForI mports, fa lse, false , false);
  3143                    if ( token.kind  == EOF)
  3144                         break;
  3145                }
  3146                if (chec kForImport s && mods  == null &&  token.kin d == IMPOR T) {
  3147                    seen Import = t rue;
  3148                    defs .append(im portDeclar ation());
  3149                } else {
  3150                    Comm ent docCom ment = tok en.comment (CommentSt yle.JAVADO C);
  3151                    if ( firstTypeD ecl && !se enImport & & !seenPac kage) {
  3152                         docComment  = firstTo ken.commen t(CommentS tyle.JAVAD OC);
  3153                         consumedTo plevelDoc  = true;
  3154                    }
  3155                    JCTr ee def = t ypeDeclara tion(mods,  docCommen t);
  3156                    if ( def instan ceof JCExp ressionSta tement)
  3157                         def = ((JC Expression Statement) def).expr;
  3158                    defs .append(de f);
  3159                    if ( def instan ceof JCCla ssDecl)
  3160                         checkForIm ports = fa lse;
  3161                    mods  = null;
  3162                    firs tTypeDecl  = false;
  3163                }
  3164           }
  3165           JC Tree.JCCom pilationUn it topleve l = F.at(f irstToken. pos).TopLe vel(packag eAnnotatio ns, pid, d efs.toList ());
  3166           if  (!consume dToplevelD oc)
  3167                attach(t oplevel, f irstToken. comment(Co mmentStyle .JAVADOC)) ;
  3168           if  (defs.isE mpty())
  3169                storeEnd (toplevel,  S.prevTok en().endPo s);
  3170           if  (keepDocC omments)
  3171                toplevel .docCommen ts = docCo mments;
  3172           if  (keepLine Map)
  3173                toplevel .lineMap =  S.getLine Map();
  3174           th is.endPosT able.setPa rser(null) ; // remov e referenc e to parse r
  3175           to plevel.end Positions  = this.end PosTable;
  3176           re turn tople vel;
  3177       }
  3178  
  3179       /** Im portDeclar ation = IM PORT [ STA TIC ] Iden t { "." Id ent } [ ". " "*" ] "; "
  3180        */
  3181       JCTree  importDec laration()  {
  3182           in t pos = to ken.pos;
  3183           ne xtToken();
  3184           bo olean impo rtStatic =  false;
  3185           if  (token.ki nd == STAT IC) {
  3186                checkSta ticImports ();
  3187                importSt atic = tru e;
  3188                nextToke n();
  3189           }
  3190           JC Expression  pid = toP (F.at(toke n.pos).Ide nt(ident() ));
  3191           do  {
  3192                int pos1  = token.p os;
  3193                accept(D OT);
  3194                if (toke n.kind ==  STAR) {
  3195                    pid  = to(F.at( pos1).Sele ct(pid, na mes.asteri sk));
  3196                    next Token();
  3197                    brea k;
  3198                } else {
  3199                    pid  = toP(F.at (pos1).Sel ect(pid, i dent()));
  3200                }
  3201           }  while (tok en.kind ==  DOT);
  3202           ac cept(SEMI) ;
  3203           re turn toP(F .at(pos).I mport(pid,  importSta tic));
  3204       }
  3205  
  3206       /** Ty peDeclarat ion = Clas sOrInterfa ceOrEnumDe claration
  3207        *                    | ";"
  3208        */
  3209       JCTree  typeDecla ration(JCM odifiers m ods, Comme nt docComm ent) {
  3210           in t pos = to ken.pos;
  3211           if  (mods ==  null && to ken.kind = = SEMI) {
  3212                nextToke n();
  3213                return t oP(F.at(po s).Skip()) ;
  3214           }  else {
  3215                return c lassOrInte rfaceOrEnu mDeclarati on(modifie rsOpt(mods ), docComm ent);
  3216           }
  3217       }
  3218  
  3219       /** Cl assOrInter faceOrEnum Declaratio n = Modifi ersOpt
  3220        *            (Cl assDeclara tion | Int erfaceDecl aration |  EnumDeclar ation)
  3221        *  @p aram mods      Any mo difiers st arting the  class or  interface  declaratio n
  3222        *  @p aram dc        The do cumentatio n comment  for the cl ass, or nu ll.
  3223        */
  3224       JCStat ement clas sOrInterfa ceOrEnumDe claration( JCModifier s mods, Co mment dc)  {
  3225           if  (token.ki nd == CLAS S) {
  3226                return c lassDeclar ation(mods , dc);
  3227           }  else if (t oken.kind  == INTERFA CE) {
  3228                return i nterfaceDe claration( mods, dc);
  3229           }  else if (a llowEnums)  {
  3230                if (toke n.kind ==  ENUM) {
  3231                    retu rn enumDec laration(m ods, dc);
  3232                } else {
  3233                    int  pos = toke n.pos;
  3234                    List <JCTree> e rrs;
  3235                    if ( LAX_IDENTI FIER.accep ts(token.k ind)) {
  3236                         errs = Lis t.<JCTree> of(mods, t oP(F.at(po s).Ident(i dent())));
  3237                         setErrorEn dPos(token .pos);
  3238                    } el se {
  3239                         errs = Lis t.<JCTree> of(mods);
  3240                    }
  3241                    retu rn toP(F.E xec(syntax Error(pos,  errs, "ex pected3",
  3242                                                     CLAS S, INTERFA CE, ENUM)) );
  3243                }
  3244           }  else {
  3245                if (toke n.kind ==  ENUM) {
  3246                    erro r(token.po s, "enums. not.suppor ted.in.sou rce", sour ce.name);
  3247                    allo wEnums = t rue;
  3248                    retu rn enumDec laration(m ods, dc);
  3249                }
  3250                int pos  = token.po s;
  3251                List<JCT ree> errs;
  3252                if (LAX_ IDENTIFIER .accepts(t oken.kind) ) {
  3253                    errs  = List.<J CTree>of(m ods, toP(F .at(pos).I dent(ident ())));
  3254                    setE rrorEndPos (token.pos );
  3255                } else {
  3256                    errs  = List.<J CTree>of(m ods);
  3257                }
  3258                return t oP(F.Exec( syntaxErro r(pos, err s, "expect ed2",
  3259                                                 CLASS, I NTERFACE)) );
  3260           }
  3261       }
  3262  
  3263       /** Cl assDeclara tion = CLA SS Ident T ypeParamet ersOpt [EX TENDS Type ]
  3264        *                       [IM PLEMENTS T ypeList] C lassBody
  3265        *  @p aram mods     The mod ifiers sta rting the  class decl aration
  3266        *  @p aram dc        The do cumentatio n comment  for the cl ass, or nu ll.
  3267        */
  3268       protec ted JCClas sDecl clas sDeclarati on(JCModif iers mods,  Comment d c) {
  3269           in t pos = to ken.pos;
  3270           ac cept(CLASS );
  3271           Na me name =  ident();
  3272  
  3273           Li st<JCTypeP arameter>  typarams =  typeParam etersOpt() ;
  3274  
  3275           JC Expression  extending  = null;
  3276           if  (token.ki nd == EXTE NDS) {
  3277                nextToke n();
  3278                extendin g = parseT ype();
  3279           }
  3280           Li st<JCExpre ssion> imp lementing  = List.nil ();
  3281           if  (token.ki nd == IMPL EMENTS) {
  3282                nextToke n();
  3283                implemen ting = typ eList();
  3284           }
  3285           Li st<JCTree>  defs = cl assOrInter faceBody(n ame, false );
  3286           JC ClassDecl  result = t oP(F.at(po s).ClassDe f(
  3287                mods, na me, typara ms, extend ing, imple menting, d efs));
  3288           at tach(resul t, dc);
  3289           re turn resul t;
  3290       }
  3291  
  3292       /** In terfaceDec laration =  INTERFACE  Ident Typ eParameter sOpt
  3293        *                            [EXTENDS  TypeList]  InterfaceB ody
  3294        *  @p aram mods     The mod ifiers sta rting the  interface  declaratio n
  3295        *  @p aram dc        The do cumentatio n comment  for the in terface, o r null.
  3296        */
  3297       protec ted JCClas sDecl inte rfaceDecla ration(JCM odifiers m ods, Comme nt dc) {
  3298           in t pos = to ken.pos;
  3299           ac cept(INTER FACE);
  3300           Na me name =  ident();
  3301  
  3302           Li st<JCTypeP arameter>  typarams =  typeParam etersOpt() ;
  3303  
  3304           Li st<JCExpre ssion> ext ending = L ist.nil();
  3305           if  (token.ki nd == EXTE NDS) {
  3306                nextToke n();
  3307                extendin g = typeLi st();
  3308           }
  3309           Li st<JCTree>  defs = cl assOrInter faceBody(n ame, true) ;
  3310           JC ClassDecl  result = t oP(F.at(po s).ClassDe f(
  3311                mods, na me, typara ms, null,  extending,  defs));
  3312           at tach(resul t, dc);
  3313           re turn resul t;
  3314       }
  3315  
  3316       /** En umDeclarat ion = ENUM  Ident [IM PLEMENTS T ypeList] E numBody
  3317        *  @p aram mods     The mod ifiers sta rting the  enum decla ration
  3318        *  @p aram dc        The do cumentatio n comment  for the en um, or nul l.
  3319        */
  3320       protec ted JCClas sDecl enum Declaratio n(JCModifi ers mods,  Comment dc ) {
  3321           in t pos = to ken.pos;
  3322           ac cept(ENUM) ;
  3323           Na me name =  ident();
  3324  
  3325           Li st<JCExpre ssion> imp lementing  = List.nil ();
  3326           if  (token.ki nd == IMPL EMENTS) {
  3327                nextToke n();
  3328                implemen ting = typ eList();
  3329           }
  3330  
  3331           Li st<JCTree>  defs = en umBody(nam e);
  3332           mo ds.flags | = Flags.EN UM;
  3333           JC ClassDecl  result = t oP(F.at(po s).
  3334                ClassDef (mods, nam e, List.<J CTypeParam eter>nil() ,
  3335                    null , implemen ting, defs ));
  3336           at tach(resul t, dc);
  3337           re turn resul t;
  3338       }
  3339  
  3340       /** En umBody = " {" { Enume ratorDecla rationList  } [","]
  3341        *                    [ ";"  {ClassBody Declaratio n} ] "}"
  3342        */
  3343       List<J CTree> enu mBody(Name  enumName)  {
  3344           ac cept(LBRAC E);
  3345           Li stBuffer<J CTree> def s = new Li stBuffer<J CTree>();
  3346           if  (token.ki nd == COMM A) {
  3347                nextToke n();
  3348           }  else if (t oken.kind  != RBRACE  && token.k ind != SEM I) {
  3349                defs.app end(enumer atorDeclar ation(enum Name));
  3350                while (t oken.kind  == COMMA)  {
  3351                    next Token();
  3352                    if ( token.kind  == RBRACE  || token. kind == SE MI) break;
  3353                    defs .append(en umeratorDe claration( enumName)) ;
  3354                }
  3355                if (toke n.kind !=  SEMI && to ken.kind ! = RBRACE)  {
  3356                    defs .append(sy ntaxError( token.pos,  "expected 3",
  3357                                      COMMA, R BRACE, SEM I));
  3358                    next Token();
  3359                }
  3360           }
  3361           if  (token.ki nd == SEMI ) {
  3362                nextToke n();
  3363                while (t oken.kind  != RBRACE  && token.k ind != EOF ) {
  3364                    defs .appendLis t(classOrI nterfaceBo dyDeclarat ion(enumNa me,
  3365                                                                         false) );
  3366                    if ( token.pos  <= endPosT able.error EndPos) {
  3367                         // error r ecovery
  3368                       s kip(false,  true, tru e, false);
  3369                    }
  3370                }
  3371           }
  3372           ac cept(RBRAC E);
  3373           re turn defs. toList();
  3374       }
  3375  
  3376       /** En umeratorDe claration  = Annotati onsOpt [Ty peArgument s] IDENTIF IER [ Argu ments ] [  "{" ClassB ody "}" ]
  3377        */
  3378       JCTree  enumerato rDeclarati on(Name en umName) {
  3379           Co mment dc =  token.com ment(Comme ntStyle.JA VADOC);
  3380           in t flags =  Flags.PUBL IC|Flags.S TATIC|Flag s.FINAL|Fl ags.ENUM;
  3381           if  (token.de precatedFl ag()) {
  3382                flags |=  Flags.DEP RECATED;
  3383           }
  3384           in t pos = to ken.pos;
  3385           Li st<JCAnnot ation> ann otations =  annotatio nsOpt(Tag. ANNOTATION );
  3386           JC Modifiers  mods = F.a t(annotati ons.isEmpt y() ? Posi tion.NOPOS  : pos).Mo difiers(fl ags, annot ations);
  3387           Li st<JCExpre ssion> typ eArgs = ty peArgument sOpt();
  3388           in t identPos  = token.p os;
  3389           Na me name =  ident();
  3390           in t createPo s = token. pos;
  3391           Li st<JCExpre ssion> arg s = (token .kind == L PAREN)
  3392                ? argume nts() : Li st.<JCExpr ession>nil ();
  3393           JC ClassDecl  body = nul l;
  3394           if  (token.ki nd == LBRA CE) {
  3395                JCModifi ers mods1  = F.at(Pos ition.NOPO S).Modifie rs(Flags.E NUM | Flag s.STATIC);
  3396                List<JCT ree> defs  = classOrI nterfaceBo dy(names.e mpty, fals e);
  3397                body = t oP(F.at(id entPos).An onymousCla ssDef(mods 1, defs));
  3398           }
  3399           if  (args.isE mpty() &&  body == nu ll)
  3400                createPo s = identP os;
  3401           JC Ident iden t = F.at(i dentPos).I dent(enumN ame);
  3402           JC NewClass c reate = F. at(createP os).NewCla ss(null, t ypeArgs, i dent, args , body);
  3403           if  (createPo s != ident Pos)
  3404                storeEnd (create, S .prevToken ().endPos) ;
  3405           id ent = F.at (identPos) .Ident(enu mName);
  3406           JC Tree resul t = toP(F. at(pos).Va rDef(mods,  name, ide nt, create ));
  3407           at tach(resul t, dc);
  3408           re turn resul t;
  3409       }
  3410  
  3411       /** Ty peList = T ype {"," T ype}
  3412        */
  3413       List<J CExpressio n> typeLis t() {
  3414           Li stBuffer<J CExpressio n> ts = ne w ListBuff er<JCExpre ssion>();
  3415           ts .append(pa rseType()) ;
  3416           wh ile (token .kind == C OMMA) {
  3417                nextToke n();
  3418                ts.appen d(parseTyp e());
  3419           }
  3420           re turn ts.to List();
  3421       }
  3422  
  3423       /** Cl assBody      = "{" {C lassBodyDe claration}  "}"
  3424        *  In terfaceBod y = "{" {I nterfaceBo dyDeclarat ion} "}"
  3425        */
  3426       List<J CTree> cla ssOrInterf aceBody(Na me classNa me, boolea n isInterf ace) {
  3427           ac cept(LBRAC E);
  3428           if  (token.po s <= endPo sTable.err orEndPos)  {
  3429                // error  recovery
  3430                skip(fal se, true,  false, fal se);
  3431                if (toke n.kind ==  LBRACE)
  3432                    next Token();
  3433           }
  3434           Li stBuffer<J CTree> def s = new Li stBuffer<J CTree>();
  3435           wh ile (token .kind != R BRACE && t oken.kind  != EOF) {
  3436                defs.app endList(cl assOrInter faceBodyDe claration( className,  isInterfa ce));
  3437                if (toke n.pos <= e ndPosTable .errorEndP os) {
  3438                   // er ror recove ry
  3439                   skip( false, tru e, true, f alse);
  3440               }
  3441           }
  3442           ac cept(RBRAC E);
  3443           re turn defs. toList();
  3444       }
  3445  
  3446       /** Cl assBodyDec laration =
  3447        *       ";"
  3448        *     | [STATIC]  Block
  3449        *     | Modifier sOpt
  3450        *       ( Type I dent
  3451        *         ( Vari ableDeclar atorsRest  ";" | Meth odDeclarat orRest )
  3452        *       | VOID I dent VoidM ethodDecla ratorRest
  3453        *       | TypePa rameters [ Annotation s]
  3454        *         ( Type  Ident Met hodDeclara torRest
  3455        *         | VOID  Ident Voi dMethodDec laratorRes t
  3456        *         )
  3457        *       | Ident  Constructo rDeclarato rRest
  3458        *       | TypePa rameters I dent Const ructorDecl aratorRest
  3459        *       | ClassO rInterface OrEnumDecl aration
  3460        *       )
  3461        *  In terfaceBod yDeclarati on =
  3462        *       ";"
  3463        *     | Modifier sOpt
  3464        *       ( Type I dent
  3465        *         ( Cons tantDeclar atorsRest  ";" | Meth odDeclarat orRest )
  3466        *       | VOID I dent Metho dDeclarato rRest
  3467        *       | TypePa rameters [ Annotation s]
  3468        *         ( Type  Ident Met hodDeclara torRest
  3469        *         | VOID  Ident Voi dMethodDec laratorRes t
  3470        *         )
  3471        *       | ClassO rInterface OrEnumDecl aration
  3472        *       )
  3473        *
  3474        */
  3475       protec ted List<J CTree> cla ssOrInterf aceBodyDec laration(N ame classN ame, boole an isInter face) {
  3476           if  (token.ki nd == SEMI ) {
  3477                nextToke n();
  3478                return L ist.<JCTre e>nil();
  3479           }  else {
  3480                Comment  dc = token .comment(C ommentStyl e.JAVADOC) ;
  3481                int pos  = token.po s;
  3482                JCModifi ers mods =  modifiers Opt();
  3483                if (toke n.kind ==  CLASS ||
  3484                    toke n.kind ==  INTERFACE  ||
  3485                    allo wEnums &&  token.kind  == ENUM)  {
  3486                    retu rn List.<J CTree>of(c lassOrInte rfaceOrEnu mDeclarati on(mods, d c));
  3487                } else i f (token.k ind == LBR ACE && !is Interface  &&
  3488                            (mods.f lags & Fla gs.Standar dFlags & ~ Flags.STAT IC) == 0 & &
  3489                            mods.an notations. isEmpty())  {
  3490                    retu rn List.<J CTree>of(b lock(pos,  mods.flags ));
  3491                } else {
  3492                    pos  = token.po s;
  3493                    List <JCTypePar ameter> ty params = t ypeParamet ersOpt();
  3494                    // i f there ar e type par ameters bu t no modif iers, save  the start
  3495                    // p osition of  the metho d in the m odifiers.
  3496                    if ( typarams.n onEmpty()  && mods.po s == Posit ion.NOPOS)  {
  3497                         mods.pos =  pos;
  3498                         storeEnd(m ods, pos);
  3499                    }
  3500                    List <JCAnnotat ion> annos AfterParam s = annota tionsOpt(T ag.ANNOTAT ION);
  3501  
  3502                    if ( annosAfter Params.non Empty()) {
  3503                         checkAnnot ationsAfte rTypeParam s(annosAft erParams.h ead.pos);
  3504                         mods.annot ations = m ods.annota tions.appe ndList(ann osAfterPar ams);
  3505                         if (mods.p os == Posi tion.NOPOS )
  3506                             mods.p os = mods. annotation s.head.pos ;
  3507                    }
  3508  
  3509                    Toke n tk = tok en;
  3510                    pos  = token.po s;
  3511                    JCEx pression t ype;
  3512                    bool ean isVoid  = token.k ind == VOI D;
  3513                    if ( isVoid) {
  3514                         type = to( F.at(pos). TypeIdent( TypeTag.VO ID));
  3515                         nextToken( );
  3516                    } el se {
  3517                         // method  returns ty pes are un -annotated  types
  3518                         type = una nnotatedTy pe();
  3519                    }
  3520                    if ( token.kind  == LPAREN  && !isInt erface &&  type.hasTa g(IDENT))  {
  3521                         if (isInte rface || t k.name() ! = classNam e)
  3522                             error( pos, "inva lid.meth.d ecl.ret.ty pe.req");
  3523                         else if (a nnosAfterP arams.nonE mpty())
  3524                             illega l(annosAft erParams.h ead.pos);
  3525                         return Lis t.of(metho dDeclarato rRest(
  3526                             pos, m ods, null,  names.ini t, typaram s,
  3527                             isInte rface, tru e, dc));
  3528                    } el se {
  3529                         pos = toke n.pos;
  3530                         Name name  = ident();
  3531                         if (token. kind == LP AREN) {
  3532                             return  List.of(m ethodDecla ratorRest(
  3533                                 po s, mods, t ype, name,  typarams,
  3534                                 is Interface,  isVoid, d c));
  3535                         } else if  (!isVoid & & typarams .isEmpty() ) {
  3536                             List<J CTree> def s =
  3537                                 va riableDecl aratorsRes t(pos, mod s, type, n ame, isInt erface, dc ,
  3538                                                            new List Buffer<JCT ree>()).to List();
  3539                             storeE nd(defs.la st(), toke n.endPos);
  3540                             accept (SEMI);
  3541                             return  defs;
  3542                         } else {
  3543                             pos =  token.pos;
  3544                             List<J CTree> err  = isVoid
  3545                                 ?  List.<JCTr ee>of(toP( F.at(pos). MethodDef( mods, name , type, ty params,
  3546                                      List.<JC VariableDe cl>nil(),  List.<JCEx pression>n il(), null , null)))
  3547                                 :  null;
  3548                             return  List.<JCT ree>of(syn taxError(t oken.pos,  err, "expe cted", LPA REN));
  3549                         }
  3550                    }
  3551                }
  3552           }
  3553       }
  3554  
  3555       /** Me thodDeclar atorRest =
  3556        *       FormalPa rameters B racketsOpt  [THROWS T ypeList] (  MethodBod y | [DEFAU LT Annotat ionValue]  ";")
  3557        *  Vo idMethodDe claratorRe st =
  3558        *       FormalPa rameters [ THROWS Typ eList] ( M ethodBody  | ";")
  3559        *  Co nstructorD eclaratorR est =
  3560        *       "(" Form alParamete rListOpt " )" [THROWS  TypeList]  MethodBod y
  3561        */
  3562       protec ted JCTree  methodDec laratorRes t(int pos,
  3563                                    JCModifier s mods,
  3564                                    JCExpressi on type,
  3565                                    Name name,
  3566                                    List<JCTyp eParameter > typarams ,
  3567                                    boolean is Interface,  boolean i sVoid,
  3568                                    Comment dc ) {
  3569           if  (isInterf ace && (mo ds.flags &  Flags.STA TIC) != 0)  {
  3570                checkSta ticInterfa ceMethods( );
  3571           }
  3572           JC VariableDe cl prevRec eiverParam  = this.re ceiverPara m;
  3573           tr y {
  3574                this.rec eiverParam  = null;
  3575                // Parsi ng formalP arameters  sets the r eceiverPar am, if pre sent
  3576                List<JCV ariableDec l> params  = formalPa rameters() ;
  3577                if (!isV oid) type  = brackets Opt(type);
  3578                List<JCE xpression>  thrown =  List.nil() ;
  3579                if (toke n.kind ==  THROWS) {
  3580                    next Token();
  3581                    thro wn = quali dentList() ;
  3582                }
  3583                JCBlock  body = nul l;
  3584                JCExpres sion defau ltValue;
  3585                if (toke n.kind ==  LBRACE) {
  3586                    body  = block() ;
  3587                    defa ultValue =  null;
  3588                } else {
  3589                    if ( token.kind  == DEFAUL T) {
  3590                         accept(DEF AULT);
  3591                         defaultVal ue = annot ationValue ();
  3592                    } el se {
  3593                         defaultVal ue = null;
  3594                    }
  3595                    acce pt(SEMI);
  3596                    if ( token.pos  <= endPosT able.error EndPos) {
  3597                         // error r ecovery
  3598                         skip(false , true, fa lse, false );
  3599                         if (token. kind == LB RACE) {
  3600                             body =  block();
  3601                         }
  3602                    }
  3603                }
  3604  
  3605                JCMethod Decl resul t =
  3606                         toP(F.at(p os).Method Def(mods,  name, type , typarams ,
  3607                                                   receiv erParam, p arams, thr own,
  3608                                                   body,  defaultVal ue));
  3609                attach(r esult, dc) ;
  3610                return r esult;
  3611           }  finally {
  3612                this.rec eiverParam  = prevRec eiverParam ;
  3613           }
  3614       }
  3615  
  3616       /** Qu alidentLis t = [Annot ations] Qu alident {" ," [Annota tions] Qua lident}
  3617        */
  3618       List<J CExpressio n> qualide ntList() {
  3619           Li stBuffer<J CExpressio n> ts = ne w ListBuff er<JCExpre ssion>();
  3620  
  3621           Li st<JCAnnot ation> typ eAnnos = t ypeAnnotat ionsOpt();
  3622           JC Expression  qi = qual ident(true );
  3623           if  (!typeAnn os.isEmpty ()) {
  3624                JCExpres sion at =  insertAnno tationsToM ostInner(q i, typeAnn os, false) ;
  3625                ts.appen d(at);
  3626           }  else {
  3627                ts.appen d(qi);
  3628           }
  3629           wh ile (token .kind == C OMMA) {
  3630                nextToke n();
  3631  
  3632                typeAnno s = typeAn notationsO pt();
  3633                qi = qua lident(tru e);
  3634                if (!typ eAnnos.isE mpty()) {
  3635                    JCEx pression a t = insert Annotation sToMostInn er(qi, typ eAnnos, fa lse);
  3636                    ts.a ppend(at);
  3637                } else {
  3638                    ts.a ppend(qi);
  3639                }
  3640           }
  3641           re turn ts.to List();
  3642       }
  3643  
  3644       /**
  3645        *  {@ literal
  3646        *  Ty peParamete rsOpt = [" <" TypePar ameter {", " TypePara meter} ">" ]
  3647        *  }
  3648        */
  3649       List<J CTypeParam eter> type Parameters Opt() {
  3650           if  (token.ki nd == LT)  {
  3651                checkGen erics();
  3652                ListBuff er<JCTypeP arameter>  typarams =  new ListB uffer<JCTy peParamete r>();
  3653                nextToke n();
  3654                typarams .append(ty peParamete r());
  3655                while (t oken.kind  == COMMA)  {
  3656                    next Token();
  3657                    typa rams.appen d(typePara meter());
  3658                }
  3659                accept(G T);
  3660                return t yparams.to List();
  3661           }  else {
  3662                return L ist.nil();
  3663           }
  3664       }
  3665  
  3666       /**
  3667        *  {@ literal
  3668        *  Ty peParamete r = [Annot ations] Ty peVariable  [TypePara meterBound ]
  3669        *  Ty peParamete rBound = E XTENDS Typ e {"&" Typ e}
  3670        *  Ty peVariable  = Ident
  3671        *  }
  3672        */
  3673       JCType Parameter  typeParame ter() {
  3674           in t pos = to ken.pos;
  3675           Li st<JCAnnot ation> ann os = typeA nnotations Opt();
  3676           Na me name =  ident();
  3677           Li stBuffer<J CExpressio n> bounds  = new List Buffer<JCE xpression> ();
  3678           if  (token.ki nd == EXTE NDS) {
  3679                nextToke n();
  3680                bounds.a ppend(pars eType());
  3681                while (t oken.kind  == AMP) {
  3682                    next Token();
  3683                    boun ds.append( parseType( ));
  3684                }
  3685           }
  3686           re turn toP(F .at(pos).T ypeParamet er(name, b ounds.toLi st(), anno s));
  3687       }
  3688  
  3689       /** Fo rmalParame ters = "("  [ FormalP arameterLi st ] ")"
  3690        *  Fo rmalParame terList =  [ FormalPa rameterLis tNovarargs  , ] LastF ormalParam eter
  3691        *  Fo rmalParame terListNov arargs = [  FormalPar ameterList Novarargs  , ] Formal Parameter
  3692        */
  3693       List<J CVariableD ecl> forma lParameter s() {
  3694           re turn forma lParameter s(false);
  3695       }
  3696       List<J CVariableD ecl> forma lParameter s(boolean  lambdaPara meters) {
  3697           Li stBuffer<J CVariableD ecl> param s = new Li stBuffer<J CVariableD ecl>();
  3698           JC VariableDe cl lastPar am;
  3699           ac cept(LPARE N);
  3700           if  (token.ki nd != RPAR EN) {
  3701                this.all owThisIden t = true;
  3702                lastPara m = formal Parameter( lambdaPara meters);
  3703                if (last Param.name expr != nu ll) {
  3704                    this .receiverP aram = las tParam;
  3705                } else {
  3706                    para ms.append( lastParam) ;
  3707                }
  3708                this.all owThisIden t = false;
  3709                while (( lastParam. mods.flags  & Flags.V ARARGS) ==  0 && toke n.kind ==  COMMA) {
  3710                    next Token();
  3711                    para ms.append( lastParam  = formalPa rameter(la mbdaParame ters));
  3712                }
  3713           }
  3714           ac cept(RPARE N);
  3715           re turn param s.toList() ;
  3716       }
  3717  
  3718       List<J CVariableD ecl> impli citParamet ers(boolea n hasParen s) {
  3719           if  (hasParen s) {
  3720                accept(L PAREN);
  3721           }
  3722           Li stBuffer<J CVariableD ecl> param s = new Li stBuffer<J CVariableD ecl>();
  3723           if  (token.ki nd != RPAR EN && toke n.kind !=  ARROW) {
  3724                params.a ppend(impl icitParame ter());
  3725                while (t oken.kind  == COMMA)  {
  3726                    next Token();
  3727                    para ms.append( implicitPa rameter()) ;
  3728                }
  3729           }
  3730           if  (hasParen s) {
  3731                accept(R PAREN);
  3732           }
  3733           re turn param s.toList() ;
  3734       }
  3735  
  3736       JCModi fiers optF inal(long  flags) {
  3737           JC Modifiers  mods = mod ifiersOpt( );
  3738           ch eckNoMods( mods.flags  & ~(Flags .FINAL | F lags.DEPRE CATED));
  3739           mo ds.flags | = flags;
  3740           re turn mods;
  3741       }
  3742  
  3743       /**
  3744        * Ins erts the a nnotations  (and poss ibly a new  array lev el)
  3745        * to  the left-m ost type i n an array  or nested  type.
  3746        *
  3747        * Whe n parsing  a type lik e {@code @ B Outer.In ner @A []} , the
  3748        * {@c ode @A} an notation s hould targ et the arr ay itself,  while
  3749        * {@c ode @B} ta rgets the  nested typ e {@code O uter}.
  3750        *
  3751        * Cur rently the  parser pa rses the a nnotation  first, the n
  3752        * the  array, an d then ins erts the a nnotation  to the lef t-most
  3753        * nes ted type.
  3754        *
  3755        * Whe n {@code c reateNewLe vel} is tr ue, then a  new array
  3756        * lev el is inse rted as th e most inn er type, a nd have th e
  3757        * ann otations t arget it.   This is u seful in t he case of
  3758        * var args, e.g.  {@code St ring @A []  @B ...},  as the par ser
  3759        * fir st parses  the type { @code Stri ng @A []}  then inser ts
  3760        * a n ew array l evel with  {@code @B}  annotatio n.
  3761        */
  3762       privat e JCExpres sion inser tAnnotatio nsToMostIn ner(
  3763                JCExpres sion type,  List<JCAn notation>  annos,
  3764                boolean  createNewL evel) {
  3765           in t origEndP os = getEn dPos(type) ;
  3766           JC Expression  mostInner Type = typ e;
  3767           JC ArrayTypeT ree mostIn nerArrayTy pe = null;
  3768           wh ile (TreeI nfo.typeIn (mostInner Type).hasT ag(TYPEARR AY)) {
  3769                mostInne rArrayType  = (JCArra yTypeTree)  TreeInfo. typeIn(mos tInnerType );
  3770                mostInne rType = mo stInnerArr ayType.ele mtype;
  3771           }
  3772  
  3773           if  (createNe wLevel) {
  3774                mostInne rType = to (F.at(toke n.pos).Typ eArray(mos tInnerType ));
  3775           }
  3776  
  3777           JC Expression  mostInner TypeToRetu rn = mostI nnerType;
  3778           if  (annos.no nEmpty())  {
  3779                JCExpres sion lastT oModify =  mostInnerT ype;
  3780  
  3781                while (T reeInfo.ty peIn(mostI nnerType). hasTag(SEL ECT) ||
  3782                         TreeInfo.t ypeIn(most InnerType) .hasTag(TY PEAPPLY))  {
  3783                    whil e (TreeInf o.typeIn(m ostInnerTy pe).hasTag (SELECT))  {
  3784                         lastToModi fy = mostI nnerType;
  3785                         mostInnerT ype = ((JC FieldAcces s) TreeInf o.typeIn(m ostInnerTy pe)).getEx pression() ;
  3786                    }
  3787                    whil e (TreeInf o.typeIn(m ostInnerTy pe).hasTag (TYPEAPPLY )) {
  3788                         lastToModi fy = mostI nnerType;
  3789                         mostInnerT ype = ((JC TypeApply)  TreeInfo. typeIn(mos tInnerType )).clazz;
  3790                    }
  3791                }
  3792  
  3793                mostInne rType = F. at(annos.h ead.pos).A nnotatedTy pe(annos,  mostInnerT ype);
  3794  
  3795                if (Tree Info.typeI n(lastToMo dify).hasT ag(TYPEAPP LY)) {
  3796                    ((JC TypeApply)  TreeInfo. typeIn(las tToModify) ).clazz =  mostInnerT ype;
  3797                } else i f (TreeInf o.typeIn(l astToModif y).hasTag( SELECT)) {
  3798                    ((JC FieldAcces s) TreeInf o.typeIn(l astToModif y)).select ed = mostI nnerType;
  3799                } else {
  3800                    // W e never sa w a SELECT  or TYPEAP PLY, retur n the anno tated type .
  3801                    most InnerTypeT oReturn =  mostInnerT ype;
  3802                }
  3803           }
  3804  
  3805           if  (mostInne rArrayType  == null)  {
  3806                return m ostInnerTy peToReturn ;
  3807           }  else {
  3808                mostInne rArrayType .elemtype  = mostInne rTypeToRet urn;
  3809                storeEnd (type, ori gEndPos);
  3810                return t ype;
  3811           }
  3812       }
  3813  
  3814       /** Fo rmalParame ter = { FI NAL | '@'  Annotation  } Type Va riableDecl aratorId
  3815        *  La stFormalPa rameter =  { FINAL |  '@' Annota tion } Typ e '...' Id ent | Form alParamete r
  3816        */
  3817       protec ted JCVari ableDecl f ormalParam eter() {
  3818           re turn forma lParameter (false);
  3819       }
  3820       protec ted JCVari ableDecl f ormalParam eter(boole an lambdaP arameter)  {
  3821           JC Modifiers  mods = opt Final(Flag s.PARAMETE R);
  3822           //  need to d istinguish  between v ararg anno s and arra y annos
  3823           //  look at t ypeAnnotat ionsPushed Back comme nt
  3824           th is.permitT ypeAnnotat ionsPushBa ck = true;
  3825           JC Expression  type = pa rseType();
  3826           th is.permitT ypeAnnotat ionsPushBa ck = false ;
  3827  
  3828           if  (token.ki nd == ELLI PSIS) {
  3829                List<JCA nnotation>  varargsAn nos = type Annotation sPushedBac k;
  3830                typeAnno tationsPus hedBack =  List.nil() ;
  3831                checkVar args();
  3832                mods.fla gs |= Flag s.VARARGS;
  3833                // inser t var arg  type annot ations
  3834                type = i nsertAnnot ationsToMo stInner(ty pe, vararg sAnnos, tr ue);
  3835                nextToke n();
  3836           }  else {
  3837                // if no t a var ar g, then ty peAnnotati onsPushedB ack should  be null
  3838                if (type Annotation sPushedBac k.nonEmpty ()) {
  3839                    repo rtSyntaxEr ror(typeAn notationsP ushedBack. head.pos,
  3840                             "illeg al.start.o f.type");
  3841                }
  3842                typeAnno tationsPus hedBack =  List.nil() ;
  3843           }
  3844           re turn varia bleDeclara torId(mods , type, la mbdaParame ter);
  3845       }
  3846  
  3847       protec ted JCVari ableDecl i mplicitPar ameter() {
  3848           JC Modifiers  mods = F.a t(token.po s).Modifie rs(Flags.P ARAMETER);
  3849           re turn varia bleDeclara torId(mods , null, tr ue);
  3850       }
  3851  
  3852   /* ------- --- auxili ary method s -------- ------ */
  3853  
  3854       void e rror(int p os, String  key, Obje ct ... arg s) {
  3855           lo g.error(Di agnosticFl ag.SYNTAX,  pos, key,  args);
  3856       }
  3857  
  3858       void e rror(Diagn osticPosit ion pos, S tring key,  Object .. . args) {
  3859           lo g.error(Di agnosticFl ag.SYNTAX,  pos, key,  args);
  3860       }
  3861  
  3862       void w arning(int  pos, Stri ng key, Ob ject ... a rgs) {
  3863           lo g.warning( pos, key,  args);
  3864       }
  3865  
  3866       /** Ch eck that g iven tree  is a legal  expressio n statemen t.
  3867        */
  3868       protec ted JCExpr ession che ckExprStat (JCExpress ion t) {
  3869           if  (!TreeInf o.isExpres sionStatem ent(t)) {
  3870                JCExpres sion ret =  F.at(t.po s).Erroneo us(List.<J CTree>of(t ));
  3871                error(re t, "not.st mt");
  3872                return r et;
  3873           }  else {
  3874                return t ;
  3875           }
  3876       }
  3877  
  3878       /** Re turn prece dence of o perator re presented  by token,
  3879        *  -1  if token  is not a b inary oper ator. @see  TreeInfo. opPrec
  3880        */
  3881       static  int prec( TokenKind  token) {
  3882           JC Tree.Tag o c = optag( token);
  3883           re turn (oc ! = NO_TAG)  ? TreeInfo .opPrec(oc ) : -1;
  3884       }
  3885  
  3886       /**
  3887        * Ret urn the le sser of tw o position s, making  allowance  for either  one
  3888        * bei ng unset.
  3889        */
  3890       static  int earli er(int pos 1, int pos 2) {
  3891           if  (pos1 ==  Position.N OPOS)
  3892                return p os2;
  3893           if  (pos2 ==  Position.N OPOS)
  3894                return p os1;
  3895           re turn (pos1  < pos2 ?  pos1 : pos 2);
  3896       }
  3897  
  3898       /** Re turn opera tion tag o f binary o perator re presented  by token,
  3899        *  No _TAG if to ken is not  a binary  operator.
  3900        */
  3901       static  JCTree.Ta g optag(To kenKind to ken) {
  3902           sw itch (toke n) {
  3903           ca se BARBAR:
  3904                return O R;
  3905           ca se AMPAMP:
  3906                return A ND;
  3907           ca se BAR:
  3908                return B ITOR;
  3909           ca se BAREQ:
  3910                return B ITOR_ASG;
  3911           ca se CARET:
  3912                return B ITXOR;
  3913           ca se CARETEQ :
  3914                return B ITXOR_ASG;
  3915           ca se AMP:
  3916                return B ITAND;
  3917           ca se AMPEQ:
  3918                return B ITAND_ASG;
  3919           ca se EQEQ:
  3920                return J CTree.Tag. EQ;
  3921           ca se BANGEQ:
  3922                return N E;
  3923           ca se LT:
  3924                return J CTree.Tag. LT;
  3925           ca se GT:
  3926                return J CTree.Tag. GT;
  3927           ca se LTEQ:
  3928                return L E;
  3929           ca se GTEQ:
  3930                return G E;
  3931           ca se LTLT:
  3932                return S L;
  3933           ca se LTLTEQ:
  3934                return S L_ASG;
  3935           ca se GTGT:
  3936                return S R;
  3937           ca se GTGTEQ:
  3938                return S R_ASG;
  3939           ca se GTGTGT:
  3940                return U SR;
  3941           ca se GTGTGTE Q:
  3942                return U SR_ASG;
  3943           ca se PLUS:
  3944                return J CTree.Tag. PLUS;
  3945           ca se PLUSEQ:
  3946                return P LUS_ASG;
  3947           ca se SUB:
  3948                return M INUS;
  3949           ca se SUBEQ:
  3950                return M INUS_ASG;
  3951           ca se STAR:
  3952                return M UL;
  3953           ca se STAREQ:
  3954                return M UL_ASG;
  3955           ca se SLASH:
  3956                return D IV;
  3957           ca se SLASHEQ :
  3958                return D IV_ASG;
  3959           ca se PERCENT :
  3960                return M OD;
  3961           ca se PERCENT EQ:
  3962                return M OD_ASG;
  3963           ca se INSTANC EOF:
  3964                return T YPETEST;
  3965           de fault:
  3966                return N O_TAG;
  3967           }
  3968       }
  3969  
  3970       /** Re turn opera tion tag o f unary op erator rep resented b y token,
  3971        *  No _TAG if to ken is not  a binary  operator.
  3972        */
  3973       static  JCTree.Ta g unoptag( TokenKind  token) {
  3974           sw itch (toke n) {
  3975           ca se PLUS:
  3976                return P OS;
  3977           ca se SUB:
  3978                return N EG;
  3979           ca se BANG:
  3980                return N OT;
  3981           ca se TILDE:
  3982                return C OMPL;
  3983           ca se PLUSPLU S:
  3984                return P REINC;
  3985           ca se SUBSUB:
  3986                return P REDEC;
  3987           de fault:
  3988                return N O_TAG;
  3989           }
  3990       }
  3991  
  3992       /** Re turn type  tag of bas ic type re presented  by token,
  3993        *  NO NE if toke n is not a  basic typ e identifi er.
  3994        */
  3995       static  TypeTag t ypetag(Tok enKind tok en) {
  3996           sw itch (toke n) {
  3997           ca se BYTE:
  3998                return T ypeTag.BYT E;
  3999           ca se CHAR:
  4000                return T ypeTag.CHA R;
  4001           ca se SHORT:
  4002                return T ypeTag.SHO RT;
  4003           ca se INT:
  4004                return T ypeTag.INT ;
  4005           ca se LONG:
  4006                return T ypeTag.LON G;
  4007           ca se FLOAT:
  4008                return T ypeTag.FLO AT;
  4009           ca se DOUBLE:
  4010                return T ypeTag.DOU BLE;
  4011           ca se BOOLEAN :
  4012                return T ypeTag.BOO LEAN;
  4013           de fault:
  4014                return T ypeTag.NON E;
  4015           }
  4016       }
  4017  
  4018       void c heckGeneri cs() {
  4019           if  (!allowGe nerics) {
  4020                error(to ken.pos, " generics.n ot.support ed.in.sour ce", sourc e.name);
  4021                allowGen erics = tr ue;
  4022           }
  4023       }
  4024       void c heckVararg s() {
  4025           if  (!allowVa rargs) {
  4026                error(to ken.pos, " varargs.no t.supporte d.in.sourc e", source .name);
  4027                allowVar args = tru e;
  4028           }
  4029       }
  4030       void c heckForeac h() {
  4031           if  (!allowFo reach) {
  4032                error(to ken.pos, " foreach.no t.supporte d.in.sourc e", source .name);
  4033                allowFor each = tru e;
  4034           }
  4035       }
  4036       void c heckStatic Imports()  {
  4037           if  (!allowSt aticImport ) {
  4038                error(to ken.pos, " static.imp ort.not.su pported.in .source",  source.nam e);
  4039                allowSta ticImport  = true;
  4040           }
  4041       }
  4042       void c heckAnnota tions() {
  4043           if  (!allowAn notations)  {
  4044                error(to ken.pos, " annotation s.not.supp orted.in.s ource", so urce.name) ;
  4045                allowAnn otations =  true;
  4046           }
  4047       }
  4048       void c heckDiamon d() {
  4049           if  (!allowDi amond) {
  4050                error(to ken.pos, " diamond.no t.supporte d.in.sourc e", source .name);
  4051                allowDia mond = tru e;
  4052           }
  4053       }
  4054       void c heckMultic atch() {
  4055           if  (!allowMu lticatch)  {
  4056                error(to ken.pos, " multicatch .not.suppo rted.in.so urce", sou rce.name);
  4057                allowMul ticatch =  true;
  4058           }
  4059       }
  4060       void c heckTryWit hResources () {
  4061           if  (!allowTW R) {
  4062                error(to ken.pos, " try.with.r esources.n ot.support ed.in.sour ce", sourc e.name);
  4063                allowTWR  = true;
  4064           }
  4065       }
  4066       void c heckLambda () {
  4067           if  (!allowLa mbda) {
  4068                log.erro r(token.po s, "lambda .not.suppo rted.in.so urce", sou rce.name);
  4069                allowLam bda = true ;
  4070           }
  4071       }
  4072       void c heckMethod References () {
  4073           if  (!allowMe thodRefere nces) {
  4074                log.erro r(token.po s, "method .reference s.not.supp orted.in.s ource", so urce.name) ;
  4075                allowMet hodReferen ces = true ;
  4076           }
  4077       }
  4078       void c heckDefaul tMethods()  {
  4079           if  (!allowDe faultMetho ds) {
  4080                log.erro r(token.po s, "defaul t.methods. not.suppor ted.in.sou rce", sour ce.name);
  4081                allowDef aultMethod s = true;
  4082           }
  4083       }
  4084       void c heckInters ectionType sInCast()  {
  4085           if  (!allowIn tersection TypesInCas t) {
  4086                log.erro r(token.po s, "inters ection.typ es.in.cast .not.suppo rted.in.so urce", sou rce.name);
  4087                allowInt ersectionT ypesInCast  = true;
  4088           }
  4089       }
  4090       void c heckStatic InterfaceM ethods() {
  4091           if  (!allowSt aticInterf aceMethods ) {
  4092                log.erro r(token.po s, "static .intf.meth ods.not.su pported.in .source",  source.nam e);
  4093                allowSta ticInterfa ceMethods  = true;
  4094           }
  4095       }
  4096       void c heckTypeAn notations( ) {
  4097           if  (!allowTy peAnnotati ons) {
  4098                log.erro r(token.po s, "type.a nnotations .not.suppo rted.in.so urce", sou rce.name);
  4099                allowTyp eAnnotatio ns = true;
  4100           }
  4101       }
  4102       void c heckAnnota tionsAfter TypeParams (int pos)  {
  4103           if  (!allowAn notationsA fterTypePa rams) {
  4104                log.erro r(pos, "an notations. after.type .params.no t.supporte d.in.sourc e", source .name);
  4105                allowAnn otationsAf terTypePar ams = true ;
  4106           }
  4107       }
  4108  
  4109       /*
  4110        * a f unctional  source tre e and end  position m appings
  4111        */
  4112       protec ted static  class Sim pleEndPosT able exten ds Abstrac tEndPosTab le {
  4113  
  4114           pr ivate fina l IntHashT able endPo sMap;
  4115  
  4116           Si mpleEndPos Table(Java cParser pa rser) {
  4117                super(pa rser);
  4118                endPosMa p = new In tHashTable ();
  4119           }
  4120  
  4121           pu blic void  storeEnd(J CTree tree , int endp os) {
  4122                endPosMa p.putAtInd ex(tree, e rrorEndPos  > endpos  ? errorEnd Pos : endp os,
  4123                                       endPosM ap.lookup( tree));
  4124           }
  4125  
  4126           pr otected <T  extends J CTree> T t o(T t) {
  4127                storeEnd (t, parser .token.end Pos);
  4128                return t ;
  4129           }
  4130  
  4131           pr otected <T  extends J CTree> T t oP(T t) {
  4132                storeEnd (t, parser .S.prevTok en().endPo s);
  4133                return t ;
  4134           }
  4135  
  4136           pu blic int g etEndPos(J CTree tree ) {
  4137                int valu e = endPos Map.getFro mIndex(end PosMap.loo kup(tree)) ;
  4138                // As lo ng as Posi tion.NOPOS ==-1, this  just retu rns value.
  4139                return ( value == - 1) ? Posit ion.NOPOS  : value;
  4140           }
  4141  
  4142           pu blic int r eplaceTree (JCTree ol dTree, JCT ree newTre e) {
  4143                int pos  = endPosMa p.remove(o ldTree);
  4144                if (pos  != -1) {
  4145                    stor eEnd(newTr ee, pos);
  4146                    retu rn pos;
  4147                }
  4148                return P osition.NO POS;
  4149           }
  4150       }
  4151  
  4152       /*
  4153        * a d efault ske letal impl ementation  without a ny mapping  overhead.
  4154        */
  4155       protec ted static  class Emp tyEndPosTa ble extend s Abstract EndPosTabl e {
  4156  
  4157           Em ptyEndPosT able(Javac Parser par ser) {
  4158                super(pa rser);
  4159           }
  4160  
  4161           pu blic void  storeEnd(J CTree tree , int endp os) { /* e mpty */ }
  4162  
  4163           pr otected <T  extends J CTree> T t o(T t) {
  4164                return t ;
  4165           }
  4166  
  4167           pr otected <T  extends J CTree> T t oP(T t) {
  4168                return t ;
  4169           }
  4170  
  4171           pu blic int g etEndPos(J CTree tree ) {
  4172                return P osition.NO POS;
  4173           }
  4174  
  4175           pu blic int r eplaceTree (JCTree ol dTree, JCT ree newTre e) {
  4176                return P osition.NO POS;
  4177           }
  4178  
  4179       }
  4180  
  4181       protec ted static  abstract  class Abst ractEndPos Table impl ements End PosTable {
  4182           /* *
  4183            *  The curre nt parser.
  4184            * /
  4185           pr otected Ja vacParser  parser;
  4186  
  4187           /* *
  4188            *  Store the  last erro r position .
  4189            * /
  4190           pr otected in t errorEnd Pos;
  4191  
  4192           pu blic Abstr actEndPosT able(Javac Parser par ser) {
  4193                this.par ser = pars er;
  4194           }
  4195  
  4196           /* *
  4197            *  Store cur rent token 's ending  position f or a tree,  the value  of which
  4198            *  will be t he greater  of last e rror posit ion and th e ending p osition of
  4199            *  the curre nt token.
  4200            *  @param t  The tree.
  4201            * /
  4202           pr otected ab stract <T  extends JC Tree> T to (T t);
  4203  
  4204           /* *
  4205            *  Store cur rent token 's ending  position f or a tree,  the value  of which
  4206            *  will be t he greater  of last e rror posit ion and th e ending p osition of
  4207            *  the previ ous token.
  4208            *  @param t  The tree.
  4209            * /
  4210           pr otected ab stract <T  extends JC Tree> T to P(T t);
  4211  
  4212           /* *
  4213            *  Set the e rror posit ion during  the parsi ng phases,  the value  of which
  4214            *  will be s et only if  it is gre ater than  the last s tored erro r position .
  4215            *  @param er rPos The e rror posit ion
  4216            * /
  4217           pr otected vo id setErro rEndPos(in t errPos)  {
  4218                if (errP os > error EndPos) {
  4219                    erro rEndPos =  errPos;
  4220                }
  4221           }
  4222  
  4223           pr otected vo id setPars er(JavacPa rser parse r) {
  4224                this.par ser = pars er;
  4225           }
  4226       }
  4227   }