< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java

Print this page
rev 52490 : imported patch 8212982b2


 366      */
 367     public static int firstStatPos(JCTree tree) {
 368         if (tree.hasTag(BLOCK) && ((JCBlock) tree).stats.nonEmpty())
 369             return ((JCBlock) tree).stats.head.pos;
 370         else
 371             return tree.pos;
 372     }
 373 
 374     /** The end position of given tree, if it is a block with
 375      *  defined endpos.
 376      */
 377     public static int endPos(JCTree tree) {
 378         if (tree.hasTag(BLOCK) && ((JCBlock) tree).endpos != Position.NOPOS)
 379             return ((JCBlock) tree).endpos;
 380         else if (tree.hasTag(SYNCHRONIZED))
 381             return endPos(((JCSynchronized) tree).body);
 382         else if (tree.hasTag(TRY)) {
 383             JCTry t = (JCTry) tree;
 384             return endPos((t.finalizer != null) ? t.finalizer
 385                           : (t.catchers.nonEmpty() ? t.catchers.last().body : t.body));



 386         } else
 387             return tree.pos;
 388     }
 389 
 390 
 391     /** Get the start position for a tree node.  The start position is
 392      * defined to be the position of the first character of the first
 393      * token of the node's source text.
 394      * @param tree  The tree node
 395      */
 396     public static int getStartPos(JCTree tree) {
 397         if (tree == null)
 398             return Position.NOPOS;
 399 
 400         switch(tree.getTag()) {
 401             case MODULEDEF: {
 402                 JCModuleDecl md = (JCModuleDecl)tree;
 403                 return md.mods.annotations.isEmpty() ? md.pos :
 404                        md.mods.annotations.head.pos;
 405             }




 366      */
 367     public static int firstStatPos(JCTree tree) {
 368         if (tree.hasTag(BLOCK) && ((JCBlock) tree).stats.nonEmpty())
 369             return ((JCBlock) tree).stats.head.pos;
 370         else
 371             return tree.pos;
 372     }
 373 
 374     /** The end position of given tree, if it is a block with
 375      *  defined endpos.
 376      */
 377     public static int endPos(JCTree tree) {
 378         if (tree.hasTag(BLOCK) && ((JCBlock) tree).endpos != Position.NOPOS)
 379             return ((JCBlock) tree).endpos;
 380         else if (tree.hasTag(SYNCHRONIZED))
 381             return endPos(((JCSynchronized) tree).body);
 382         else if (tree.hasTag(TRY)) {
 383             JCTry t = (JCTry) tree;
 384             return endPos((t.finalizer != null) ? t.finalizer
 385                           : (t.catchers.nonEmpty() ? t.catchers.last().body : t.body));
 386         } else if (tree.hasTag(SWITCH_EXPRESSION) &&
 387                    ((JCSwitchExpression) tree).endpos != Position.NOPOS) {
 388             return ((JCSwitchExpression) tree).endpos;
 389         } else
 390             return tree.pos;
 391     }
 392 
 393 
 394     /** Get the start position for a tree node.  The start position is
 395      * defined to be the position of the first character of the first
 396      * token of the node's source text.
 397      * @param tree  The tree node
 398      */
 399     public static int getStartPos(JCTree tree) {
 400         if (tree == null)
 401             return Position.NOPOS;
 402 
 403         switch(tree.getTag()) {
 404             case MODULEDEF: {
 405                 JCModuleDecl md = (JCModuleDecl)tree;
 406                 return md.mods.annotations.isEmpty() ? md.pos :
 407                        md.mods.annotations.head.pos;
 408             }


< prev index next >