// code for generating stubs for the traversals TraversalAspectList { // returns false if there's any error public boolean generateStubs(File dir, String fname) to {VisitorDecl, TraversalDecl} { {{ String aspectName; File aspectFile; StringBuffer aspectBody = new StringBuffer(); boolean returnVal = true; }} before TraversalAspect {{ aspectName = host.get_aspectname().get_aname().toString(); aspectFile = new File(dir, aspectName + ".java"); }} before TraversalDecl {{ String travName = host.get_tv().get_i().toString(); String travStrategy = host.get_ts().get_s(); if (!travStrategy.startsWith("from")) { System.out.println("Strategy does not start with from: " + travStrategy); returnVal = false; } else { String startName = travStrategy.substring(5,travStrategy.indexOf(" ", 5)); if (startName.indexOf("*")> -1) { System.out.println("%Error : You can not have * in the source node of a \n" + "traversal in DAJ. DAJ can not know the " + "classname to which it should create the stub."); returnVal = false; } aspectBody.append(" public void " + startName + "." + travName + "() {}\n"); String visitorNameString = host.getVisitorTypeString(); String visitorReturnTypeString = "void"; if (visitorNameString.compareTo("") != 0) { visitorNameString += " v"; aspectBody.append(" public "+ visitorReturnTypeString + " " + startName + "." + travName + "(" + visitorNameString + ") {}\n"); } } }} after TraversalAspect {{ try { String outString = new String(); outString = outString + "// Stub Generated by AspectDJ\n" + "aspect " + aspectName + " {\n" + aspectBody.toString() + "\n" + "}\n"; if (!aspectName.equals(fname)) { System.out.println("%Error : The name of an aspect and the filename\n" + "have to be the same. " + aspectName + " does not match\n" + fname + ". Please change either the aspect name or\n" + "the file name."); returnVal = false; } else { System.out.println("Generating Stub file: " + aspectFile); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(aspectFile))); pw.print(outString); pw.close(); } } catch (IOException e) { System.out.println(e); returnVal = false; } }} return boolean {{ returnVal }} } } TraversalDecl { public String getVisitorTypeString() to VisitorVar { {{ String returnVal = ""; }} before VisitorVar {{ returnVal = host.get_ident().toString(); }} return String {{ returnVal }} } }