Search in sources :

Example 76 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

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(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 77 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

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() && !FileUtil.mkdirs(dir)) {
            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='//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", "code data-language='ceylon' style='font-family: Inconsolata, Monaco, Courier, monospace'");
            String encoding = getEncoding();
            if (encoding == null) {
                encoding = CeylonConfig.get(DefaultToolOptions.DEFAULTS_ENCODING);
            }
            InputStreamReader isr = encoding != null ? new InputStreamReader(pu.getUnitFile().getInputStream(), encoding) : new InputStreamReader(pu.getUnitFile().getInputStream());
            try (BufferedReader input = new BufferedReader(isr)) {
                String line = input.readLine();
                while (line != null) {
                    markup.text(line, "\n");
                    line = input.readLine();
                }
            }
            markup.close("code", "pre", "body", "html");
        } finally {
            writer.close();
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Package(org.eclipse.ceylon.model.typechecker.model.Package) IOException(java.io.IOException) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 78 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

the class CeylonDocTool method collectSubclasses.

private void collectSubclasses() throws IOException {
    for (Module module : modules) {
        for (Package pkg : getPackages(module)) {
            for (Declaration decl : pkg.getMembers()) {
                if (!shouldInclude(decl)) {
                    continue;
                }
                if (decl instanceof ClassOrInterface) {
                    ClassOrInterface c = (ClassOrInterface) decl;
                    // subclasses map
                    if (c instanceof Class) {
                        Type superclass = c.getExtendedType();
                        if (superclass != null) {
                            TypeDeclaration superdec = superclass.getDeclaration();
                            if (subclasses.get(superdec) == null) {
                                subclasses.put(superdec, new ArrayList<Class>());
                            }
                            subclasses.get(superdec).add((Class) c);
                        }
                    }
                    List<Type> satisfiedTypes = new ArrayList<Type>(c.getSatisfiedTypes());
                    if (satisfiedTypes != null && satisfiedTypes.isEmpty() == false) {
                        // satisfying classes or interfaces map
                        for (Type satisfiedType : satisfiedTypes) {
                            TypeDeclaration superdec = satisfiedType.getDeclaration();
                            if (satisfyingClassesOrInterfaces.get(superdec) == null) {
                                satisfyingClassesOrInterfaces.put(superdec, new ArrayList<ClassOrInterface>());
                            }
                            satisfyingClassesOrInterfaces.get(superdec).add(c);
                        }
                    }
                }
            }
        }
    }
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ArrayList(java.util.ArrayList) Class(org.eclipse.ceylon.model.typechecker.model.Class) Package(org.eclipse.ceylon.model.typechecker.model.Package) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Module(org.eclipse.ceylon.model.typechecker.model.Module) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 79 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

the class PhasedUnitsModuleManager method createPackage.

@Override
public Package createPackage(String pkgName, Module module) {
    // never create a lazy package for ceylon.language when we're documenting it
    if ((pkgName.equals(AbstractModelLoader.CEYLON_LANGUAGE) || pkgName.startsWith(AbstractModelLoader.CEYLON_LANGUAGE + ".")) && isModuleLoadedFromSource(AbstractModelLoader.CEYLON_LANGUAGE))
        return super.createPackage(pkgName, module);
    final Package pkg = new LazyPackage(getModelLoader());
    List<String> name = pkgName.isEmpty() ? Collections.<String>emptyList() : splitModuleName(pkgName);
    pkg.setName(name);
    if (module != null) {
        module.getPackages().add(pkg);
        pkg.setModule(module);
    }
    return pkg;
}
Also used : LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 80 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

the class ModuleManager method createPackage.

public Package createPackage(String pkgName, Module module) {
    Package pkg = new Package();
    List<String> name = pkgName.isEmpty() ? asList("") : splitModuleName(pkgName);
    pkg.setName(name);
    if (module != null) {
        module.getPackages().add(pkg);
        pkg.setModule(module);
    }
    return pkg;
}
Also used : Package(org.eclipse.ceylon.model.typechecker.model.Package)

Aggregations

Package (org.eclipse.ceylon.model.typechecker.model.Package)84 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)31 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)31 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)27 Module (org.eclipse.ceylon.model.typechecker.model.Module)26 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)21 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)14 ArrayList (java.util.ArrayList)13 LazyPackage (org.eclipse.ceylon.model.loader.model.LazyPackage)11 Class (org.eclipse.ceylon.model.typechecker.model.Class)11 Function (org.eclipse.ceylon.model.typechecker.model.Function)9 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)9 Value (org.eclipse.ceylon.model.typechecker.model.Value)9 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)8 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)8 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)8 HashSet (java.util.HashSet)7 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)7 ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)7 Type (org.eclipse.ceylon.model.typechecker.model.Type)7