1 2 12 package com.versant.core.jdo.query; 13 14 17 public class CastNode extends UnaryNode { 18 19 public int brackets; 20 public String type; 21 public Class cls; 22 23 public CastNode(Node child, int brackets, Object tp) { 24 super(child); 25 this.brackets = brackets; 26 if (tp instanceof Class ) cls = (Class )tp; 27 else type = (String )tp; 28 } 29 30 public String toString() { 31 StringBuffer s = new StringBuffer (); 32 s.append(super.toString()); 33 s.append(" ("); 34 if (cls != null) s.append(cls); 35 else s.append(type); 36 s.append(')'); 37 return s.toString(); 38 } 39 40 public Field visit(MemVisitor visitor, Object obj) { 41 return visitor.visitCastNode(this, obj); 42 } 43 44 47 protected void normalizeImp() { 48 super.normalizeImp(); 49 50 57 63 69 if (next instanceof FieldNode || next instanceof FieldNavNode) { 70 71 FieldNode toReplace = findFieldNode(childList); 73 if (toReplace == null) return; 74 Node toMove = next; 75 Node toKeep = next.next; 76 Node toRaise = childList; 77 78 FieldNavNode castFnn = new FieldNavNode(); 80 castFnn.cast = type; 81 castFnn.lexeme = toReplace.lexeme; 82 83 castFnn.childList = toMove; 85 toMove.parent = castFnn; 86 toMove.next = null; 87 88 toReplace.parent.childList = castFnn; 90 castFnn.parent = toReplace.parent; 91 92 if (toRaise == toReplace) toRaise = castFnn; 94 95 parent.childList = toRaise; 98 toRaise.parent = parent; 99 toRaise.next = toKeep; 100 if (toKeep != null) toKeep.parent = parent; 101 } 102 } 103 104 108 private FieldNode findFieldNode(Node root) { 109 for (; root != null && !(root instanceof FieldNode); root = root.childList); 110 return (FieldNode)root; 111 } 112 113 public Object arrive(NodeVisitor v, Object msg) { 114 return v.arriveCastNode(this, msg); 115 } 116 117 } 118 | Popular Tags |