Hi Binoy: thank you for the test. In principle, it should be possible to program just with around methods. Do you have an idea why that did not work? -- Karl >From binoy@ccs.neu.edu Mon Nov 24 11:23:56 1997 >From: Binoy Samuel >To: Karl Lieberherr >CC: mira@ccs.neu.edu, dougo@ccs.neu.edu >Subject: Re: Mira's style > >Karl Lieberherr wrote: >> >> Hi Binoy: >> >> how did the Demeter/Java program work out? Is it working? >> >> -- Karl > >Here is my attempt at using inheritance instead of nesting for the >visitors. > /proj/asl/binoy/regression/suite-latest/j-rondo/ (program*) > >It was not possible to use only around methods to solve this. Neither >was the option of using only before/after. In the end I had to use all >the three. >I didnt very much like my solution; one more level of inheritance, and >this style would not be easy using visitors methods. Maybe there is a >neater solution. Doug? > >---------.cd------------- >// class dictionary >(@ >import java.util.*; >@) > >Container = "(" List(Item) Capacity ")". >Item : Container | Simple. > >Simple = Ident Weight. >Capacity = int. >Weight = int. > >List(S) ~ {S}. > >*noparse* >Main = . > >*visitors* >SummingVisitor : InitialVisitor > *common* > int. >InitialVisitor : CheckingVisitor > *common* > int > Stack. > >CheckingVisitor = int. > >---------.beh----------- >// behavior >Main { >(@ > static public void main(String args[]) throws Exception { > > Container a = Container.parse(System.in); > > int result = a.checkCapacity(); > if(result > 0) { > System.out.println("SUCCESS"); > } > else { > System.out.println("FAILURE"); > } > System.out.println("done "); > } >@) >} > > >Container { > traversal allWeights(SummingVisitor sV , InitialVisitor iV , >CheckingVisitor cV) { > to Weight; > } > > (@ > > int checkCapacity() throws Exception { > > SummingVisitor cV = new CheckingVisitor(0,0,new Stack() , 0); > this.allWeights(cV, (InitialVisitor)cV , (CheckingVisitor)cV); > return (((CheckingVisitor)cV).get_violations()); > } > @) >} > > >SummingVisitor{ > before Simple (@ > System.out.println(host.get_name()); > @) > > around Weight (@ > System.out.println("SummingVisitor :: Weight around"); > total += host.get_i(); > //subtraversal.apply(); > > @) >} > >InitialVisitor{ > before Container(@ > System.out.println("IntialVisitor :: Container before"); > stack.push(new Integer(total)); > @) > > around Container(@ > subtraversal.apply(); > System.out.println("InitialVisitor : Container around"); > initial = ((Integer)stack.pop()).intValue(); > > @) >} > > >CheckingVisitor{ > after Container(@ > // subtraversal.apply(); > System.out.println("CheckingVisitor :: Container after"); > int cap = host.get_capacity().get_i(); > int diff = total - initial ; > if(diff > cap) > { > violations ++ ; > System.out.println(" OVERCAPACITY => Capacity = "+cap+"\tTotal wt = >"+diff); > } > else > System.out.println(" Capacity = "+cap+"\tTotal wt = "+diff); > @) >} > > > >------------------------- > > > >--binoy >