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

changeset 3497
08a21473de54
parent 3371
7220be8747f0
child 3446
e468915bad3a
equal deleted inserted replaced
3496:08cf09e3f9a3 3497:08a21473de54
1 /* 1 /*
2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
33 import com.sun.tools.javac.comp.AttrContext; 33 import com.sun.tools.javac.comp.AttrContext;
34 import com.sun.tools.javac.comp.Env; 34 import com.sun.tools.javac.comp.Env;
35 import com.sun.tools.javac.tree.JCTree.*; 35 import com.sun.tools.javac.tree.JCTree.*;
36 import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*; 36 import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*;
37 import com.sun.tools.javac.util.*; 37 import com.sun.tools.javac.util.*;
38
38 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 39 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
39 import static com.sun.tools.javac.code.Flags.*; 40 import static com.sun.tools.javac.code.Flags.*;
40 import static com.sun.tools.javac.code.TypeTag.BOT; 41 import static com.sun.tools.javac.code.TypeTag.BOT;
41 import static com.sun.tools.javac.tree.JCTree.Tag.*; 42 import static com.sun.tools.javac.tree.JCTree.Tag.*;
42 import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK; 43 import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK;
609 return TreeInfo.getEndPos(tree, endPosTable); 610 return TreeInfo.getEndPos(tree, endPosTable);
610 } 611 }
611 }; 612 };
612 } 613 }
613 614
615 public enum PosKind {
616 START_POS() { int toPos(JCTree tree) { return TreeInfo.getStartPos(tree); } },
617 FIRST_STAT_POS() { int toPos(JCTree tree) { return firstStatPos(tree); } },
618 END_POS() { int toPos(JCTree tree) { return endPos(tree); } };
619
620 abstract int toPos(JCTree tree);
621 }
622
614 /** The position of the finalizer of given try/synchronized statement. 623 /** The position of the finalizer of given try/synchronized statement.
615 */ 624 */
616 public static int finalizerPos(JCTree tree) { 625 public static int finalizerPos(JCTree tree, PosKind posKind) {
617 if (tree.hasTag(TRY)) { 626 if (tree.hasTag(TRY)) {
618 JCTry t = (JCTry) tree; 627 JCTry t = (JCTry) tree;
619 Assert.checkNonNull(t.finalizer); 628 Assert.checkNonNull(t.finalizer);
620 return firstStatPos(t.finalizer); 629 return posKind.toPos(t.finalizer);
621 } else if (tree.hasTag(SYNCHRONIZED)) { 630 } else if (tree.hasTag(SYNCHRONIZED)) {
622 return endPos(((JCSynchronized) tree).body); 631 return endPos(((JCSynchronized) tree).body);
623 } else { 632 } else {
624 throw new AssertionError(); 633 throw new AssertionError();
625 } 634 }

mercurial