Search in sources :

Example 1 with Element

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

the class CeylonDocTool method getSrcUrl.

/**
 * Gets a URL for the source file containing the given thing
 * @param from Where the link is relative to
 * @param modPkgOrDecl e.g. Module, Package or Declaration
 * @return A (relative) URL, or null if no source file exists (e.g. for a
 * package or a module without a descriptor)
 * @throws IOException
 */
protected String getSrcUrl(Object from, Object modPkgOrDecl) throws IOException {
    URI fromUrl = getAbsoluteObjectUrl(from);
    Module module = getModule(from);
    String filename;
    File folder;
    if (modPkgOrDecl instanceof Element) {
        Unit unit = ((Element) modPkgOrDecl).getUnit();
        filename = unit.getFilename();
        folder = getFolder(unit.getPackage());
    } else if (modPkgOrDecl instanceof Package) {
        filename = "package.ceylon";
        folder = getFolder((Package) modPkgOrDecl);
    } else if (modPkgOrDecl instanceof Module) {
        Module moduleDecl = (Module) modPkgOrDecl;
        folder = getApiOutputFolder(moduleDecl);
        filename = Constants.MODULE_DESCRIPTOR;
    } else {
        throw new RuntimeException(CeylondMessages.msg("error.unexpected", modPkgOrDecl));
    }
    File srcFile = new File(folder, filename + ".html").getCanonicalFile();
    String result;
    if (srcFile.exists()) {
        URI url = srcFile.toURI();
        result = relativize(module, fromUrl, url).toString();
    } else {
        result = null;
    }
    return result;
}
Also used : Element(com.redhat.ceylon.model.typechecker.model.Element) Package(com.redhat.ceylon.model.typechecker.model.Package) Module(com.redhat.ceylon.model.typechecker.model.Module) CompilationUnit(com.redhat.ceylon.compiler.typechecker.tree.Tree.CompilationUnit) Unit(com.redhat.ceylon.model.typechecker.model.Unit) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit) URI(java.net.URI) File(java.io.File)

Example 2 with Element

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

the class LinkRenderer method isInCurrentModule.

private boolean isInCurrentModule(Object obj) {
    Module objModule = null;
    if (obj instanceof Module) {
        objModule = (Module) obj;
    } else if (obj instanceof Scope) {
        objModule = getPackage((Scope) obj).getModule();
    } else if (obj instanceof Element) {
        objModule = getPackage(((Element) obj).getScope()).getModule();
    }
    Module currentModule = ceylonDocTool.getCurrentModule();
    if (currentModule != null && objModule != null) {
        return currentModule.equals(objModule);
    }
    return false;
}
Also used : Scope(com.redhat.ceylon.model.typechecker.model.Scope) Element(com.redhat.ceylon.model.typechecker.model.Element) Module(com.redhat.ceylon.model.typechecker.model.Module)

Aggregations

Element (com.redhat.ceylon.model.typechecker.model.Element)2 Module (com.redhat.ceylon.model.typechecker.model.Module)2 PhasedUnit (com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)1 CompilationUnit (com.redhat.ceylon.compiler.typechecker.tree.Tree.CompilationUnit)1 Package (com.redhat.ceylon.model.typechecker.model.Package)1 Scope (com.redhat.ceylon.model.typechecker.model.Scope)1 Unit (com.redhat.ceylon.model.typechecker.model.Unit)1 File (java.io.File)1 URI (java.net.URI)1