public void addHoistedCodeToComponentOrCompilationUnitContext(String s) { // look back the stack until we find a Component int lastIndex = bodyStack.size() - 1; for (int i = lastIndex; i > 0; i--) { ICode thisone = bodyStack.get(i); if (thisone instanceof Component) { ((IComponent) thisone).addHoistedCode(s); return; } else if (thisone instanceof CompilationUnit) { ((ICompilationUnit) thisone).addHoistedCode(s); return; } } throw new RuntimeException( "Didn't find Component or Compilation Unit when adding hoisted code"); }