Search in sources :

Example 1 with ClassDescription

use of org.develnext.jphp.genapi.description.ClassDescription in project jphp by jphp-compiler.

the class ApiDocument method generate.

public void generate(File targetDirectory, String language, Map<String, ClassDescription> classMap) {
    for (ClassStmtToken el : classes) {
        ClassDescription cls = classMap.get(el.getFulledName().toLowerCase());
        if (cls == null)
            throw new IllegalStateException("Cannot find class " + el.getFulledName() + " in classMap");
        System.out.println("[" + language + "] gen class: " + cls.getName());
        String result = template.printClass(cls);
        File file = new File(targetDirectory, cls.getName().replace('\\', '/') + ".rst");
        if (!file.getParentFile().exists()) {
            if (!file.getParentFile().mkdirs()) {
                throw new IllegalStateException("Cannot create the '" + file.getParent() + "' directory");
            }
        }
        try {
            FileWriter fileWriter = new FileWriter(file, false);
            try {
                fileWriter.write(result);
            } finally {
                fileWriter.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    template.onEnd(targetDirectory);
}
Also used : FileWriter(java.io.FileWriter) ClassStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken) ClassDescription(org.develnext.jphp.genapi.description.ClassDescription) IOException(java.io.IOException) File(java.io.File)

Example 2 with ClassDescription

use of org.develnext.jphp.genapi.description.ClassDescription in project jphp by jphp-compiler.

the class DocGenerator method generate.

public void generate(File targetDirectory, String language) {
    if (!targetDirectory.exists())
        if (!targetDirectory.mkdirs())
            throw new IllegalStateException("Cannot create target directory");
    SphinxTemplate sphinxTemplate = new SphinxTemplate(language, languages.get(language));
    List<ApiDocument> documents = new ArrayList<ApiDocument>();
    for (File file : files) {
        ApiDocument document = new ApiDocument(parseFile(file), sphinxTemplate);
        documents.add(document);
    }
    Map<String, ClassDescription> classMap = new HashedMap<String, ClassDescription>();
    for (ApiDocument document : documents) {
        classMap.putAll(document.getClasses());
    }
    for (ClassDescription el : classMap.values()) {
        if (el.getExtends() != null) {
            ClassDescription parent = classMap.get(el.getExtends().toLowerCase());
            if (parent != null) {
                parent.addChildClass(el);
            }
        }
    }
    for (ApiDocument document : documents) {
        document.generate(targetDirectory, language, classMap);
    }
}
Also used : ArrayList(java.util.ArrayList) SphinxTemplate(org.develnext.jphp.genapi.template.SphinxTemplate) ClassDescription(org.develnext.jphp.genapi.description.ClassDescription) HashedMap(php.runtime.common.collections.map.HashedMap) File(java.io.File)

Aggregations

File (java.io.File)2 ClassDescription (org.develnext.jphp.genapi.description.ClassDescription)2 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ClassStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken)1 SphinxTemplate (org.develnext.jphp.genapi.template.SphinxTemplate)1 HashedMap (php.runtime.common.collections.map.HashedMap)1