Search in sources :

Example 1 with Element

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

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(org.eclipse.ceylon.model.typechecker.model.Element) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) CompilationUnit(org.eclipse.ceylon.compiler.typechecker.tree.Tree.CompilationUnit) URI(java.net.URI) File(java.io.File)

Example 2 with Element

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

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(org.eclipse.ceylon.model.typechecker.model.Scope) Element(org.eclipse.ceylon.model.typechecker.model.Element) Module(org.eclipse.ceylon.model.typechecker.model.Module)

Aggregations

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