001/* This file was generated by SableCC (http://www.sablecc.org/). */ 002 003package org.anarres.graphviz.parser.node; 004 005import java.util.*; 006import org.anarres.graphviz.parser.analysis.*; 007 008@SuppressWarnings("nls") 009public final class AGraph extends PGraph 010{ 011 private PGraphType _graphType_; 012 private PAtom _name_; 013 private final LinkedList<PStatement> _statement_ = new LinkedList<PStatement>(); 014 015 public AGraph() 016 { 017 // Constructor 018 } 019 020 public AGraph( 021 @SuppressWarnings("hiding") PGraphType _graphType_, 022 @SuppressWarnings("hiding") PAtom _name_, 023 @SuppressWarnings("hiding") List<PStatement> _statement_) 024 { 025 // Constructor 026 setGraphType(_graphType_); 027 028 setName(_name_); 029 030 setStatement(_statement_); 031 032 } 033 034 @Override 035 public Object clone() 036 { 037 return new AGraph( 038 cloneNode(this._graphType_), 039 cloneNode(this._name_), 040 cloneList(this._statement_)); 041 } 042 043 public void apply(Switch sw) 044 { 045 ((Analysis) sw).caseAGraph(this); 046 } 047 048 public PGraphType getGraphType() 049 { 050 return this._graphType_; 051 } 052 053 public void setGraphType(PGraphType node) 054 { 055 if(this._graphType_ != null) 056 { 057 this._graphType_.parent(null); 058 } 059 060 if(node != null) 061 { 062 if(node.parent() != null) 063 { 064 node.parent().removeChild(node); 065 } 066 067 node.parent(this); 068 } 069 070 this._graphType_ = node; 071 } 072 073 public PAtom getName() 074 { 075 return this._name_; 076 } 077 078 public void setName(PAtom node) 079 { 080 if(this._name_ != null) 081 { 082 this._name_.parent(null); 083 } 084 085 if(node != null) 086 { 087 if(node.parent() != null) 088 { 089 node.parent().removeChild(node); 090 } 091 092 node.parent(this); 093 } 094 095 this._name_ = node; 096 } 097 098 public LinkedList<PStatement> getStatement() 099 { 100 return this._statement_; 101 } 102 103 public void setStatement(List<PStatement> list) 104 { 105 this._statement_.clear(); 106 this._statement_.addAll(list); 107 for(PStatement e : list) 108 { 109 if(e.parent() != null) 110 { 111 e.parent().removeChild(e); 112 } 113 114 e.parent(this); 115 } 116 } 117 118 @Override 119 public String toString() 120 { 121 return "" 122 + toString(this._graphType_) 123 + toString(this._name_) 124 + toString(this._statement_); 125 } 126 127 @Override 128 void removeChild(@SuppressWarnings("unused") Node child) 129 { 130 // Remove child 131 if(this._graphType_ == child) 132 { 133 this._graphType_ = null; 134 return; 135 } 136 137 if(this._name_ == child) 138 { 139 this._name_ = null; 140 return; 141 } 142 143 if(this._statement_.remove(child)) 144 { 145 return; 146 } 147 148 throw new RuntimeException("Not a child."); 149 } 150 151 @Override 152 void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) 153 { 154 // Replace child 155 if(this._graphType_ == oldChild) 156 { 157 setGraphType((PGraphType) newChild); 158 return; 159 } 160 161 if(this._name_ == oldChild) 162 { 163 setName((PAtom) newChild); 164 return; 165 } 166 167 for(ListIterator<PStatement> i = this._statement_.listIterator(); i.hasNext();) 168 { 169 if(i.next() == oldChild) 170 { 171 if(newChild != null) 172 { 173 i.set((PStatement) newChild); 174 newChild.parent(this); 175 oldChild.parent(null); 176 return; 177 } 178 179 i.remove(); 180 oldChild.parent(null); 181 return; 182 } 183 } 184 185 throw new RuntimeException("Not a child."); 186 } 187}