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 ASubgraphNode extends PNode 010{ 011 private PAtom _name_; 012 private final LinkedList<PStatement> _statement_ = new LinkedList<PStatement>(); 013 014 public ASubgraphNode() 015 { 016 // Constructor 017 } 018 019 public ASubgraphNode( 020 @SuppressWarnings("hiding") PAtom _name_, 021 @SuppressWarnings("hiding") List<PStatement> _statement_) 022 { 023 // Constructor 024 setName(_name_); 025 026 setStatement(_statement_); 027 028 } 029 030 @Override 031 public Object clone() 032 { 033 return new ASubgraphNode( 034 cloneNode(this._name_), 035 cloneList(this._statement_)); 036 } 037 038 public void apply(Switch sw) 039 { 040 ((Analysis) sw).caseASubgraphNode(this); 041 } 042 043 public PAtom getName() 044 { 045 return this._name_; 046 } 047 048 public void setName(PAtom node) 049 { 050 if(this._name_ != null) 051 { 052 this._name_.parent(null); 053 } 054 055 if(node != null) 056 { 057 if(node.parent() != null) 058 { 059 node.parent().removeChild(node); 060 } 061 062 node.parent(this); 063 } 064 065 this._name_ = node; 066 } 067 068 public LinkedList<PStatement> getStatement() 069 { 070 return this._statement_; 071 } 072 073 public void setStatement(List<PStatement> list) 074 { 075 this._statement_.clear(); 076 this._statement_.addAll(list); 077 for(PStatement e : list) 078 { 079 if(e.parent() != null) 080 { 081 e.parent().removeChild(e); 082 } 083 084 e.parent(this); 085 } 086 } 087 088 @Override 089 public String toString() 090 { 091 return "" 092 + toString(this._name_) 093 + toString(this._statement_); 094 } 095 096 @Override 097 void removeChild(@SuppressWarnings("unused") Node child) 098 { 099 // Remove child 100 if(this._name_ == child) 101 { 102 this._name_ = null; 103 return; 104 } 105 106 if(this._statement_.remove(child)) 107 { 108 return; 109 } 110 111 throw new RuntimeException("Not a child."); 112 } 113 114 @Override 115 void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) 116 { 117 // Replace child 118 if(this._name_ == oldChild) 119 { 120 setName((PAtom) newChild); 121 return; 122 } 123 124 for(ListIterator<PStatement> i = this._statement_.listIterator(); i.hasNext();) 125 { 126 if(i.next() == oldChild) 127 { 128 if(newChild != null) 129 { 130 i.set((PStatement) newChild); 131 newChild.parent(this); 132 oldChild.parent(null); 133 return; 134 } 135 136 i.remove(); 137 oldChild.parent(null); 138 return; 139 } 140 } 141 142 throw new RuntimeException("Not a child."); 143 } 144}