ParserContextBaseNode.java revision 1088:7e62d98d4625
1/* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25package jdk.nashorn.internal.parser; 26 27import java.util.ArrayList; 28import java.util.List; 29import jdk.nashorn.internal.ir.Statement; 30 31/** 32 * Base class for parser context nodes 33 */ 34abstract class ParserContextBaseNode implements ParserContextNode { 35 /** 36 * Flags for this node 37 */ 38 protected int flags; 39 40 private List<Statement> statements; 41 42 /** 43 * Constructor 44 */ 45 public ParserContextBaseNode() { 46 this.statements = new ArrayList<>(); 47 } 48 49 /** 50 * @return The flags for this node 51 */ 52 @Override 53 public int getFlags() { 54 return flags; 55 } 56 57 /** 58 * Returns a single flag 59 * @param flag flag 60 * @return A single flag 61 */ 62 protected int getFlag(final int flag) { 63 return (flags & flag); 64 } 65 66 /** 67 * @param flag flag 68 * @return the new flags 69 */ 70 @Override 71 public int setFlag(final int flag) { 72 flags |= flag; 73 return flags; 74 } 75 76 /** 77 * @return The list of statements that belongs to this node 78 */ 79 @Override 80 public List<Statement> getStatements() { 81 return statements; 82 } 83 84 /** 85 * @param statements statements 86 */ 87 @Override 88 public void setStatements(final List<Statement> statements) { 89 this.statements = statements; 90 } 91 92 /** 93 * Adds a Statement at the end of the Statementlist 94 * @param statement The statement to add 95 */ 96 @Override 97 public void appendStatement(final Statement statement) { 98 this.statements.add(statement); 99 } 100 101 /** 102 * Adds a statement at the begining of the statementlist 103 * @param statement The statement to add 104 */ 105 @Override 106 public void prependStatement(final Statement statement) { 107 this.statements.add(0, statement); 108 } 109} 110