src/share/classes/com/sun/tools/javac/parser/EndPosParser.java

Wed, 02 Jul 2008 12:56:02 -0700

author
xdono
date
Wed, 02 Jul 2008 12:56:02 -0700
changeset 54
eaf608c64fec
parent 1
9a66ca7c79fa
child 104
5e89c4ca637c
permissions
-rw-r--r--

6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell

duke@1 1 /*
duke@1 2 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javac.parser;
duke@1 27
duke@1 28 import java.util.Map;
duke@1 29 import java.util.HashMap;
duke@1 30 import com.sun.tools.javac.tree.JCTree;
duke@1 31 import com.sun.tools.javac.tree.TreeInfo;
duke@1 32 import com.sun.tools.javac.util.Position;
duke@1 33 import com.sun.tools.javac.util.List;
duke@1 34
duke@1 35 import static com.sun.tools.javac.tree.JCTree.*;
duke@1 36
duke@1 37 /**
duke@1 38 * This class is similar to Parser except that it stores ending
duke@1 39 * positions for the tree nodes.
duke@1 40 *
duke@1 41 * <p><b>This is NOT part of any API supported by Sun Microsystems.
duke@1 42 * If you write code that depends on this, you do so at your own risk.
duke@1 43 * This code and its internal interfaces are subject to change or
duke@1 44 * deletion without notice.</b></p>
duke@1 45 */
duke@1 46 public class EndPosParser extends Parser {
duke@1 47
duke@1 48 public EndPosParser(Factory fac, Lexer S, boolean keepDocComments) {
duke@1 49 super(fac, S, keepDocComments);
duke@1 50 this.S = S;
duke@1 51 endPositions = new HashMap<JCTree,Integer>();
duke@1 52 }
duke@1 53
duke@1 54 private Lexer S;
duke@1 55
duke@1 56 /** A hashtable to store ending positions
duke@1 57 * of source ranges indexed by the tree nodes.
duke@1 58 * Defined only if option flag genEndPos is set.
duke@1 59 */
duke@1 60 Map<JCTree, Integer> endPositions;
duke@1 61
duke@1 62 /** {@inheritDoc} */
duke@1 63 @Override
duke@1 64 protected void storeEnd(JCTree tree, int endpos) {
duke@1 65 int errorEndPos = getErrorEndPos();
duke@1 66 endPositions.put(tree, errorEndPos > endpos ? errorEndPos : endpos);
duke@1 67 }
duke@1 68
duke@1 69 /** {@inheritDoc} */
duke@1 70 @Override
duke@1 71 protected <T extends JCTree> T to(T t) {
duke@1 72 storeEnd(t, S.endPos());
duke@1 73 return t;
duke@1 74 }
duke@1 75
duke@1 76 /** {@inheritDoc} */
duke@1 77 @Override
duke@1 78 protected <T extends JCTree> T toP(T t) {
duke@1 79 storeEnd(t, S.prevEndPos());
duke@1 80 return t;
duke@1 81 }
duke@1 82
duke@1 83 @Override
duke@1 84 public JCCompilationUnit compilationUnit() {
duke@1 85 JCCompilationUnit t = super.compilationUnit();
duke@1 86 t.endPositions = endPositions;
duke@1 87 return t;
duke@1 88 }
duke@1 89
duke@1 90 /** {@inheritDoc} */
duke@1 91 @Override
duke@1 92 JCExpression parExpression() {
duke@1 93 int pos = S.pos();
duke@1 94 JCExpression t = super.parExpression();
duke@1 95 return toP(F.at(pos).Parens(t));
duke@1 96 }
duke@1 97
duke@1 98 /** {@inheritDoc} */
duke@1 99 @Override
duke@1 100 public int getEndPos(JCTree tree) {
duke@1 101 return TreeInfo.getEndPos(tree, endPositions);
duke@1 102 }
duke@1 103
duke@1 104 }

mercurial