AnchorNode.java revision 953:221a84ef44c0
1/* 2 * Permission is hereby granted, free of charge, to any person obtaining a copy of 3 * this software and associated documentation files (the "Software"), to deal in 4 * the Software without restriction, including without limitation the rights to 5 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 6 * of the Software, and to permit persons to whom the Software is furnished to do 7 * so, subject to the following conditions: 8 * 9 * The above copyright notice and this permission notice shall be included in all 10 * copies or substantial portions of the Software. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 * SOFTWARE. 19 */ 20package jdk.nashorn.internal.runtime.regexp.joni.ast; 21 22import jdk.nashorn.internal.runtime.regexp.joni.constants.AnchorType; 23 24public final class AnchorNode extends Node implements AnchorType { 25 public int type; 26 public Node target; 27 public int charLength; 28 29 public AnchorNode(final int type) { 30 this.type = type; 31 charLength = -1; 32 } 33 34 @Override 35 public int getType() { 36 return ANCHOR; 37 } 38 39 @Override 40 protected void setChild(final Node newChild) { 41 target = newChild; 42 } 43 44 @Override 45 protected Node getChild() { 46 return target; 47 } 48 49 public void setTarget(final Node tgt) { 50 target = tgt; 51 tgt.parent = this; 52 } 53 54 @Override 55 public String getName() { 56 return "Anchor"; 57 } 58 59 @Override 60 public String toString(final int level) { 61 final StringBuilder value = new StringBuilder(); 62 value.append("\n type: " + typeToString()); 63 value.append("\n target: " + pad(target, level + 1)); 64 return value.toString(); 65 } 66 67 public String typeToString() { 68 final StringBuilder type = new StringBuilder(); 69 if (isType(BEGIN_BUF)) type.append("BEGIN_BUF "); 70 if (isType(BEGIN_LINE)) type.append("BEGIN_LINE "); 71 if (isType(BEGIN_POSITION)) type.append("BEGIN_POSITION "); 72 if (isType(END_BUF)) type.append("END_BUF "); 73 if (isType(SEMI_END_BUF)) type.append("SEMI_END_BUF "); 74 if (isType(END_LINE)) type.append("END_LINE "); 75 if (isType(WORD_BOUND)) type.append("WORD_BOUND "); 76 if (isType(NOT_WORD_BOUND)) type.append("NOT_WORD_BOUND "); 77 if (isType(WORD_BEGIN)) type.append("WORD_BEGIN "); 78 if (isType(WORD_END)) type.append("WORD_END "); 79 if (isType(PREC_READ)) type.append("PREC_READ "); 80 if (isType(PREC_READ_NOT)) type.append("PREC_READ_NOT "); 81 if (isType(LOOK_BEHIND)) type.append("LOOK_BEHIND "); 82 if (isType(LOOK_BEHIND_NOT)) type.append("LOOK_BEHIND_NOT "); 83 if (isType(ANYCHAR_STAR)) type.append("ANYCHAR_STAR "); 84 if (isType(ANYCHAR_STAR_ML)) type.append("ANYCHAR_STAR_ML "); 85 return type.toString(); 86 } 87 88 private boolean isType(final int type) { 89 return (this.type & type) != 0; 90 } 91 92} 93