outputForeignStubs _dflags (ForeignStubs _ _ classExports) modClass =
  map f $ filter (\(cls, _) -> cls /= modClass) $ foreignExportsList classExports
  where f (classSpec, (methodDefs, fieldDefs)) =
          mkClassFile java7 [Public, Super] (jvmify className) (Just superClass)
            interfaces fieldDefs methodDefs''
          where className':specs = T.words classSpec
                className = jvmify className'
                methodDefs' = methodDefs
                methodDefs'' = if hasConstructor
                               then methodDefs'
                               else  mkDefaultConstructor className superClass
                                   : methodDefs'
                hasConstructor = any (\(MethodDef _ (UName n) _ _ _) ->
                                        n == "<init>") methodDefs
                (superClass, interfaces) = parseSpecs specs jobjectC []
        parseSpecs ("extends":superClass:xs) _ is = parseSpecs xs (jvmify superClass) is
        parseSpecs ("implements":interface:xs) sc is = parseSpecs xs sc (jvmify interface:is)
        parseSpecs [] sc is = (sc, reverse is)
        parseSpecs _ _ _ = error $ "Invalid foreign export spec."
        jvmify = T.map (\c -> if c == '.' then '/' else c)
outputForeignStubs _dflags (ForeignStubs _ _ classExports) modClass =
  map f $ filter (\(cls, _) -> cls /= modClass) $ foreignExportsList classExports
  where f (classSpec, (methodDefs, fieldDefs)) =
          mkClassFile java7 [Public, Super] (jvmify className) (Just superClass)
            interfaces fieldDefs methodDefs''
          where className':specs = T.words classSpec
                className = jvmify className'
                methodDefs' = methodDefs
                methodDefs'' = if hasConstructor
                               then methodDefs'
                               else  mkDefaultConstructor className superClass
                                   : methodDefs'
                hasConstructor = any (\(MethodDef _ (UName n) _ _ _) ->
                                        n == "<init>") methodDefs
                (superClass, interfaces) = parseSpecs specs jobjectC []
        parseSpecs ("extends":superClass:xs) _ is = parseSpecs xs (jvmify superClass) is
        parseSpecs ("implements":interface:xs) sc is = parseSpecs xs sc (jvmify interface:is)
        parseSpecs [] sc is = (sc, reverse is)
        parseSpecs _ _ _ = error $ "Invalid foreign export spec."
        jvmify = T.map (\c -> if c == '.' then '/' else c)
outputForeignStubs _dflags (ForeignStubs _ _ classExports) modClass =
  map f $ filter (\(cls, _) -> cls /= modClass) $ foreignExportsList classExports
  where f (classSpec, (methodDefs, fieldDefs)) =
          mkClassFile java7 [Public, Super] (jvmify className) (Just superClass)
            interfaces fieldDefs methodDefs''
          where className':specs = T.words classSpec
                className = jvmify className'
                methodDefs' = methodDefs
                methodDefs'' = if hasConstructor
                               then methodDefs'
                               else  mkDefaultConstructor className superClass
                                   : methodDefs'
                hasConstructor = any (\(MethodDef _ (UName n) _ _ _) ->
                                        n == "<init>") methodDefs
                (superClass, interfaces) = parseSpecs specs jobjectC []
        parseSpecs ("extends":superClass:xs) _ is = parseSpecs xs (jvmify superClass) is
        parseSpecs ("implements":interface:xs) sc is = parseSpecs xs sc (jvmify interface:is)
        parseSpecs [] sc is = (sc, reverse is)
        parseSpecs _ _ _ = error $ "Invalid foreign export spec."
        jvmify = T.map (\c -> if c == '.' then '/' else c)