Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

AUnit.java

00001 package edu.ksu.cis.bandera.specification.assertion.node;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1998-2001 SAnToS Laboratories (santos@cis.ksu.edu)  *
00006 
00007  * All rights reserved.                                              *
00008  *                                                                   *
00009  * This work was done as a project in the SAnToS Laboratory,         *
00010  * Department of Computing and Information Sciences, Kansas State    *
00011  * University, USA (http://www.cis.ksu.edu/santos).                  *
00012  * It is understood that any modification not identified as such is  *
00013  * not covered by the preceding statement.                           *
00014  *                                                                   *
00015  * This work is free software; you can redistribute it and/or        *
00016  * modify it under the terms of the GNU Library General Public       *
00017  * License as published by the Free Software Foundation; either      *
00018  * version 2 of the License, or (at your option) any later version.  *
00019  *                                                                   *
00020  * This work is distributed in the hope that it will be useful,      *
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00023  * Library General Public License for more details.                  *
00024  *                                                                   *
00025  * You should have received a copy of the GNU Library General Public *
00026  * License along with this toolkit; if not, write to the             *
00027  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00028  * Boston, MA  02111-1307, USA.                                      *
00029  *                                                                   *
00030  * Java is a trademark of Sun Microsystems, Inc.                     *
00031  *                                                                   *
00032  * To submit a bug report, send a comment, or get the latest news on *
00033  * this project and other SAnToS projects, please visit the web-site *
00034  *                http://www.cis.ksu.edu/santos                      *
00035  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00036 /* This file was generated by SableCC (http://www.sable.mcgill.ca/sablecc/). */
00037 
00038 import java.util.*;
00039 import edu.ksu.cis.bandera.specification.assertion.analysis.*;
00040 
00041 public final class AUnit extends PUnit
00042 {
00043     private PName _name_;
00044     private final LinkedList _comment_ = new TypedLinkedList(new Comment_Cast());
00045     private final LinkedList _assertion_ = new TypedLinkedList(new Assertion_Cast());
00046 
00047     private class Comment_Cast implements Cast
00048     {
00049         public Object cast(Object o)
00050         {
00051             PComment node = (PComment) o;
00052 
00053             if((node.parent() != null) &&
00054                 (node.parent() != AUnit.this))
00055             {
00056                 node.parent().removeChild(node);
00057             }
00058 
00059             if((node.parent() == null) ||
00060                 (node.parent() != AUnit.this))
00061             {
00062                 node.parent(AUnit.this);
00063             }
00064 
00065             return node;
00066         }
00067     }
00068 
00069     private class Assertion_Cast implements Cast
00070     {
00071         public Object cast(Object o)
00072         {
00073             PAssertion node = (PAssertion) o;
00074 
00075             if((node.parent() != null) &&
00076                 (node.parent() != AUnit.this))
00077             {
00078                 node.parent().removeChild(node);
00079             }
00080 
00081             if((node.parent() == null) ||
00082                 (node.parent() != AUnit.this))
00083             {
00084                 node.parent(AUnit.this);
00085             }
00086 
00087             return node;
00088         }
00089     }
00090     public AUnit()
00091     {
00092     }
00093     public AUnit(
00094         PName _name_,
00095         XPComment _comment_,
00096         XPAssertion _assertion_)
00097     {
00098         setName(_name_);
00099 
00100         if(_comment_ != null)
00101         {
00102             while(_comment_ instanceof X1PComment)
00103             {
00104                 this._comment_.addFirst(((X1PComment) _comment_).getPComment());
00105                 _comment_ = ((X1PComment) _comment_).getXPComment();
00106             }
00107             this._comment_.addFirst(((X2PComment) _comment_).getPComment());
00108         }
00109 
00110         if(_assertion_ != null)
00111         {
00112             while(_assertion_ instanceof X1PAssertion)
00113             {
00114                 this._assertion_.addFirst(((X1PAssertion) _assertion_).getPAssertion());
00115                 _assertion_ = ((X1PAssertion) _assertion_).getXPAssertion();
00116             }
00117             this._assertion_.addFirst(((X2PAssertion) _assertion_).getPAssertion());
00118         }
00119 
00120     }
00121     public AUnit(
00122         PName _name_,
00123         List _comment_,
00124         List _assertion_)
00125     {
00126         setName(_name_);
00127 
00128         {
00129             Object temp[] = _comment_.toArray();
00130             for(int i = 0; i < temp.length; i++)
00131             {
00132                 this._comment_.add(temp[i]);
00133             }
00134         }
00135 
00136         {
00137             Object temp[] = _assertion_.toArray();
00138             for(int i = 0; i < temp.length; i++)
00139             {
00140                 this._assertion_.add(temp[i]);
00141             }
00142         }
00143 
00144     }
00145     public void apply(Switch sw)
00146     {
00147         ((Analysis) sw).caseAUnit(this);
00148     }
00149     public Object clone()
00150     {
00151         return new AUnit(
00152             (PName) cloneNode(_name_),
00153             cloneList(_comment_),
00154             cloneList(_assertion_));
00155     }
00156     public LinkedList getAssertion()
00157     {
00158         return _assertion_;
00159     }
00160     public LinkedList getComment()
00161     {
00162         return _comment_;
00163     }
00164     public PName getName()
00165     {
00166         return _name_;
00167     }
00168     void removeChild(Node child)
00169     {
00170         if(_name_ == child)
00171         {
00172             _name_ = null;
00173             return;
00174         }
00175 
00176         if(_comment_.remove(child))
00177         {
00178             return;
00179         }
00180 
00181         if(_assertion_.remove(child))
00182         {
00183             return;
00184         }
00185 
00186     }
00187     void replaceChild(Node oldChild, Node newChild)
00188     {
00189         if(_name_ == oldChild)
00190         {
00191             setName((PName) newChild);
00192             return;
00193         }
00194 
00195         for(ListIterator i = _comment_.listIterator(); i.hasNext();)
00196         {
00197             if(i.next() == oldChild)
00198             {
00199                 if(newChild != null)
00200                 {
00201                     i.set(newChild);
00202                     oldChild.parent(null);
00203                     return;
00204                 }
00205 
00206                 i.remove();
00207                 oldChild.parent(null);
00208                 return;
00209             }
00210         }
00211 
00212         for(ListIterator i = _assertion_.listIterator(); i.hasNext();)
00213         {
00214             if(i.next() == oldChild)
00215             {
00216                 if(newChild != null)
00217                 {
00218                     i.set(newChild);
00219                     oldChild.parent(null);
00220                     return;
00221                 }
00222 
00223                 i.remove();
00224                 oldChild.parent(null);
00225                 return;
00226             }
00227         }
00228 
00229     }
00230     public void setAssertion(List list)
00231     {
00232         Object temp[] = list.toArray();
00233         for(int i = 0; i < temp.length; i++)
00234         {
00235             _assertion_.add(temp[i]);
00236         }
00237     }
00238     public void setComment(List list)
00239     {
00240         Object temp[] = list.toArray();
00241         for(int i = 0; i < temp.length; i++)
00242         {
00243             _comment_.add(temp[i]);
00244         }
00245     }
00246     public void setName(PName node)
00247     {
00248         if(_name_ != null)
00249         {
00250             _name_.parent(null);
00251         }
00252 
00253         if(node != null)
00254         {
00255             if(node.parent() != null)
00256             {
00257                 node.parent().removeChild(node);
00258             }
00259 
00260             node.parent(this);
00261         }
00262 
00263         _name_ = node;
00264     }
00265     public String toString()
00266     {
00267         return ""
00268             + toString(_name_)
00269             + toString(_comment_)
00270             + toString(_assertion_);
00271     }
00272 }

Generated at Thu Feb 7 06:40:20 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001