Search in sources :

Example 6 with Module

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

the class LinkRenderer method getExternalUrl.

private String getExternalUrl(Object to) {
    String url = null;
    if (to instanceof Module) {
        url = getExternalModuleUrl((Module) to);
        if (url != null) {
            url += "index.html";
        }
    } else if (to instanceof Package) {
        Package pkg = (Package) to;
        url = getExternalModuleUrl(pkg.getModule());
        if (url != null) {
            url += buildPackageUrlPath(pkg);
            url += "index.html";
        }
    } else if (to instanceof ClassOrInterface) {
        ClassOrInterface klass = (ClassOrInterface) to;
        Package pkg = getPackage(klass);
        url = getExternalModuleUrl(pkg.getModule());
        if (url != null) {
            url += buildPackageUrlPath(pkg);
            url += ceylonDocTool.getFileName(klass);
        }
    }
    return url;
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Package(com.redhat.ceylon.model.typechecker.model.Package) Module(com.redhat.ceylon.model.typechecker.model.Module)

Example 7 with Module

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

the class CeylonDocTool method makeDoc.

private void makeDoc() throws IOException {
    buildNodesMaps();
    if (includeSourceCode) {
        copySourceFiles();
    }
    collectSubclasses();
    collectAnnotationConstructors();
    // document every module
    boolean documentedOne = false;
    for (Module module : modules) {
        if (isEmpty(module)) {
            log.warning(CeylondMessages.msg("warn.moduleHasNoDeclaration", module.getNameAsString()));
        } else {
            documentedOne = true;
        }
        documentModule(module);
        ArtifactContext artifactDocs = new ArtifactContext(module.getNameAsString(), module.getVersion(), ArtifactContext.DOCS);
        // find all doc folders to copy
        File outputDocFolder = getDocOutputFolder(module);
        for (File docFolder : docFolders) {
            File moduleDocFolder = new File(docFolder, join("/", module.getName()));
            if (moduleDocFolder.exists()) {
                FileUtil.copyAll(moduleDocFolder, outputDocFolder);
            }
        }
        repositoryRemoveArtifact(outputRepositoryManager, artifactDocs);
        repositoryPutArtifact(outputRepositoryManager, artifactDocs, getOutputFolder(module, null));
    }
    if (!documentedOne) {
        log.warning(CeylondMessages.msg("warn.couldNotFindAnyDeclaration"));
    }
    if (browse) {
        for (Module module : modules) {
            if (isEmpty(module)) {
                continue;
            }
            ArtifactContext docArtifact = new ArtifactContext(module.getNameAsString(), module.getVersion(), ArtifactContext.DOCS);
            File docFolder = outputRepositoryManager.getArtifact(docArtifact);
            File docIndex = new File(docFolder, "api/index.html");
            if (docIndex.isFile()) {
                try {
                    Desktop.getDesktop().browse(docIndex.toURI());
                } catch (Exception e) {
                    log.error(CeylondMessages.msg("error.unableBrowseModuleDoc", docIndex.toURI()));
                }
            }
        }
    }
}
Also used : ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) Module(com.redhat.ceylon.model.typechecker.model.Module) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 8 with Module

use of com.redhat.ceylon.model.typechecker.model.Module 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 9 with Module

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

the class ForcedCaptureVisitor method isForcedCapture.

private boolean isForcedCapture(Tree.TypedDeclaration that) {
    if (that.getAnnotationList() == null)
        return false;
    for (Annotation anno : that.getAnnotationList().getAnnotations()) {
        Type type = anno.getTypeModel();
        if (type == null || !type.isClassOrInterface())
            continue;
        TypeDeclaration decl = type.getDeclaration();
        if (decl == null)
            continue;
        Module module = Decl.getModule(decl);
        if (module == null)
            continue;
        if (module.getLanguageModule() == module)
            continue;
        // does not come from the language module
        return true;
    }
    return false;
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) Module(com.redhat.ceylon.model.typechecker.model.Module) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Annotation(com.redhat.ceylon.compiler.typechecker.tree.Tree.Annotation)

Example 10 with Module

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

the class LazyModuleSourceMapper method addModuleDependencyDefinition.

@Override
public void addModuleDependencyDefinition(ModuleImport moduleImport, Node definition) {
    super.addModuleDependencyDefinition(moduleImport, definition);
    Module module = moduleImport.getModule();
    if (module == null)
        return;
    String nameAsString = module.getNameAsString();
    String version = module.getVersion();
    if (version != null && AbstractModelLoader.isJDKModule(nameAsString)) {
        // Add a warning if we're using a lower JDK than the one we're running on
        if (JDKUtils.jdk.isLowerVersion(version)) {
            definition.addUsageWarning(Warning.importsOtherJdk, "You import JDK7, which is provided by the JDK8 you are running on, but" + " we cannot check that you are not using any JDK8-specific classes or methods. Upgrade your import to JDK8 if you depend on" + " JDK8 classes or methods.", Backend.Java);
        }
    }
}
Also used : LazyModule(com.redhat.ceylon.model.loader.model.LazyModule) Module(com.redhat.ceylon.model.typechecker.model.Module)

Aggregations

Module (com.redhat.ceylon.model.typechecker.model.Module)50 Package (com.redhat.ceylon.model.typechecker.model.Package)16 File (java.io.File)14 Test (org.junit.Test)12 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)10 CeylonDocTool (com.redhat.ceylon.ceylondoc.CeylonDocTool)9 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)9 ArrayList (java.util.ArrayList)6 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)5 ModuleImport (com.redhat.ceylon.model.typechecker.model.ModuleImport)5 ImportModule (com.redhat.ceylon.compiler.typechecker.tree.Tree.ImportModule)4 Class (com.redhat.ceylon.model.typechecker.model.Class)4 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)4 ErrorCollector (com.redhat.ceylon.compiler.java.test.ErrorCollector)3 CeyloncTaskImpl (com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl)3 PhasedUnit (com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)3 LazyModule (com.redhat.ceylon.model.loader.model.LazyModule)3 Function (com.redhat.ceylon.model.typechecker.model.Function)3 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)3 Type (com.redhat.ceylon.model.typechecker.model.Type)3