Search in sources :

Example 26 with Package

use of com.redhat.ceylon.model.typechecker.model.Package in project ceylon-compiler by ceylon.

the class CeylonDocTool method doc.

private void doc(Module module) throws IOException {
    Writer rootWriter = openWriter(getObjectFile(module));
    try {
        ModuleDoc moduleDoc = new ModuleDoc(this, rootWriter, module);
        moduleDoc.generate();
        for (Package pkg : getPackages(module)) {
            if (pkg.getMembers().isEmpty()) {
                continue;
            }
            // document the package
            if (!isRootPackage(module, pkg)) {
                Writer packageWriter = openWriter(getObjectFile(pkg));
                try {
                    new PackageDoc(this, packageWriter, pkg).generate();
                } finally {
                    packageWriter.close();
                }
            }
            // document its members
            for (Declaration decl : pkg.getMembers()) {
                doc(decl);
            }
            if (pkg.getNameAsString().equals(AbstractModelLoader.CEYLON_LANGUAGE)) {
                docNothingType(pkg);
            }
        }
    } finally {
        rootWriter.close();
    }
}
Also used : Package(com.redhat.ceylon.model.typechecker.model.Package) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 27 with Package

use of com.redhat.ceylon.model.typechecker.model.Package in project ceylon-compiler by ceylon.

the class CeylonDocTool method copySourceFiles.

private void copySourceFiles() throws FileNotFoundException, IOException {
    for (PhasedUnit pu : phasedUnits) {
        Package pkg = pu.getUnit().getPackage();
        if (!shouldInclude(pkg)) {
            continue;
        }
        File file = new File(getFolder(pu.getPackage()), pu.getUnitFile().getName() + ".html");
        File dir = file.getParentFile();
        if (!dir.exists() && !dir.mkdirs()) {
            throw new IOException(CeylondMessages.msg("error.couldNotCreateDirectory", file));
        }
        Writer writer = openWriter(file);
        try {
            Markup markup = new Markup(writer);
            markup.write("<!DOCTYPE html>");
            markup.open("html xmlns='http://www.w3.org/1999/xhtml'");
            markup.open("head");
            markup.tag("meta charset='UTF-8'");
            markup.around("title", pu.getUnit().getFilename());
            markup.tag("link href='" + getResourceUrl(pkg, "favicon.ico") + "' rel='shortcut icon'");
            markup.tag("link href='" + getResourceUrl(pkg, "ceylon.css") + "' rel='stylesheet' type='text/css'");
            markup.tag("link href='" + getResourceUrl(pkg, "ceylondoc.css") + "' rel='stylesheet' type='text/css'");
            markup.tag("link href='http://fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet' type='text/css'");
            markup.open("script type='text/javascript'");
            markup.write("var resourceBaseUrl = '" + getResourceUrl(pkg, "") + "'");
            markup.close("script");
            markup.around("script src='" + getResourceUrl(pkg, "jquery-1.8.2.min.js") + "' type='text/javascript'");
            markup.around("script src='" + getResourceUrl(pkg, "rainbow.min.js") + "' type='text/javascript'");
            markup.around("script src='" + getResourceUrl(pkg, "rainbow.linenumbers.js") + "' type='text/javascript'");
            markup.around("script src='" + getResourceUrl(pkg, "ceylon.js") + "' type='text/javascript'");
            markup.around("script src='" + getResourceUrl(pkg, "ceylondoc.js") + "' type='text/javascript'");
            markup.close("head");
            markup.open("body", "pre data-language='ceylon' style='font-family: Inconsolata, Monaco, Courier, monospace'");
            // XXX source char encoding
            BufferedReader input = new BufferedReader(new InputStreamReader(pu.getUnitFile().getInputStream()));
            try {
                String line = input.readLine();
                while (line != null) {
                    markup.text(line, "\n");
                    line = input.readLine();
                }
            } finally {
                input.close();
            }
            markup.close("pre", "body", "html");
        } finally {
            writer.close();
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Package(com.redhat.ceylon.model.typechecker.model.Package) IOException(java.io.IOException) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)

Example 28 with Package

use of com.redhat.ceylon.model.typechecker.model.Package in project ceylon-compiler by ceylon.

the class PackageDoc method writeSubpackages.

private void writeSubpackages() throws IOException {
    if (!sharingPageWithModule) {
        List<Package> subpackages = new ArrayList<Package>();
        for (Package p : module.getPackages()) {
            if (p.getName().size() == pkg.getName().size() + 1 && p.getNameAsString().startsWith(pkg.getNameAsString()) && tool.shouldInclude(p)) {
                subpackages.add(p);
            }
        }
        Collections.sort(subpackages, ReferenceableComparatorByName.INSTANCE);
        writePackagesTable("Subpackages", subpackages);
    }
}
Also used : ArrayList(java.util.ArrayList) Package(com.redhat.ceylon.model.typechecker.model.Package)

Example 29 with Package

use of com.redhat.ceylon.model.typechecker.model.Package in project ceylon-compiler by ceylon.

the class CeylonDoc method writeBy.

protected final void writeBy(Object obj) throws IOException {
    List<Annotation> annotations;
    if (obj instanceof Declaration) {
        annotations = ((Declaration) obj).getAnnotations();
    } else if (obj instanceof Module) {
        annotations = ((Module) obj).getAnnotations();
    } else if (obj instanceof Package) {
        annotations = ((Package) obj).getAnnotations();
    } else {
        throw new IllegalArgumentException();
    }
    List<String> authors = new ArrayList<>();
    for (Annotation annotation : annotations) {
        if (annotation.getName().equals("by")) {
            for (String author : annotation.getPositionalArguments()) {
                authors.add(author);
            }
        }
    }
    if (!authors.isEmpty()) {
        open("div class='by section'");
        around("span class='title'", "By: ");
        around("span class='value'", Util.join(", ", authors));
        close("div");
    }
}
Also used : ArrayList(java.util.ArrayList) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) Package(com.redhat.ceylon.model.typechecker.model.Package) Module(com.redhat.ceylon.model.typechecker.model.Module) Annotation(com.redhat.ceylon.model.typechecker.model.Annotation)

Example 30 with Package

use of com.redhat.ceylon.model.typechecker.model.Package in project ceylon-compiler by ceylon.

the class CeylonDocTool method getPackages.

List<Package> getPackages(Module module) {
    List<Package> packages = new ArrayList<Package>();
    for (Package pkg : module.getPackages()) {
        if (shouldInclude(pkg)) {
            packages.add(pkg);
        }
    }
    Collections.sort(packages, ReferenceableComparatorByName.INSTANCE);
    return packages;
}
Also used : ArrayList(java.util.ArrayList) Package(com.redhat.ceylon.model.typechecker.model.Package)

Aggregations

Package (com.redhat.ceylon.model.typechecker.model.Package)47 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)18 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)17 Module (com.redhat.ceylon.model.typechecker.model.Module)16 Scope (com.redhat.ceylon.model.typechecker.model.Scope)16 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)14 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)11 ArrayList (java.util.ArrayList)10 Class (com.redhat.ceylon.model.typechecker.model.Class)8 Interface (com.redhat.ceylon.model.typechecker.model.Interface)7 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)6 Value (com.redhat.ceylon.model.typechecker.model.Value)6 PhasedUnit (com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)5 Function (com.redhat.ceylon.model.typechecker.model.Function)5 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)5 Type (com.redhat.ceylon.model.typechecker.model.Type)4 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)4 CeylonCompilationUnit (com.redhat.ceylon.compiler.java.codegen.CeylonCompilationUnit)3 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)3 File (java.io.File)3