/* * some utility methods */ aspect ASTUtil { public static boolean ASTNode.isSingletonOf(SimpleSet s, Object o) { return s.size() == 1 && s.iterator().next() == o; } // provide access to the program root public Program ASTNode.programRoot() { ASTNode p; for(p=this; p!=null&&!(p instanceof Program); p=p.getParent()); if(p == null) return null; return (Program)p; } // provide access to the enclosing compilation unit public CompilationUnit ASTNode.compilationUnit() { ASTNode p; for(p=this; p!=null&&!(p instanceof CompilationUnit); p=p.getParent()); if(p == null) return null; return (CompilationUnit)p; } public void TypeDecl.removeBodyDecl(BodyDecl bd) { getBodyDeclList().removeChild(getBodyDeclList().getIndexOfChild(bd)); } public void FieldDeclaration.makePrivate() throws RefactoringException { if(isPrivate()) return; Modifiers m = getModifiers(); for(int i=0;i c) { for(Iterator i=c.iterator();i.hasNext();) add(i.next()); return this; } public int ASTNode.indexIn(ASTNode n) { if(getParent() == n) return getParent().getIndexOfChild(this); if(getParent() == null) return -1; return getParent().indexIn(n); } public boolean ASTNode.inside(ASTNode n) { return indexIn(n) != -1; } public boolean ASTNode.contains(ASTNode n) { while(n!=null && n!=this) n = n.getParent(); return n==this; } public boolean Opt.isEmpty() { return getNumChild() == 0; } public String CompilationUnit.getID() { char pathsep = File.separatorChar; String path = pathName(); int i = path.lastIndexOf(pathsep); String relname_tail = i == -1 ? path : path.substring(i+1); int j = relname_tail.lastIndexOf("."); return relname_tail.substring(0, j); } public static String ASTNode.capitalize(String str) { StringBuffer buf = new StringBuffer(str); if(buf.length() > 0) buf.setCharAt(0, Character.toUpperCase(buf.charAt(0))); return buf.toString(); } }