aspect OpenVariables { public AnonymousMethod AnonymousMethod.open() { getBlock().flushCaches(); getBlock().freshenAllDeclarations(); for(int i=getNumParameter()-1;i>=0;--i) getParameter(i).inline(); hostType().flushCaches(); return this; } public void ParameterDeclaration.inline() { AnonymousMethod anon = (AnonymousMethod)getParent().getParent(); int i = anon.getParameterList().getIndexOfChild(this); Expr arg = anon.lookupArg(name()); if(isIn()) { arg = (Expr)arg.lockAllNames(); VariableDeclaration newdecl = asFreshVariableDeclaration(); anon.removeParameter(i); anon.removeArg(i); newdecl.setInit(arg); anon.getBlock().insertStmt(0, newdecl); } else { if(!(arg instanceof VarAccess)) throw new RefactoringException("cannot inline argument"); Variable decl = ((VarAccess)arg).decl(); Collection uses = uses(); anon.removeParameter(i); anon.removeArg(i); for(VarAccess v : uses) { v.flushCaches(); v.lock(decl); } } } }