Search in sources :

Example 6 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package 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 7 with Package

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

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(org.eclipse.ceylon.model.typechecker.model.Package) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 8 with Package

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

the class IndexApiDoc method collectDeclarations.

private List<Declaration> collectDeclarations() {
    List<Declaration> declarations = new ArrayList<Declaration>();
    for (Package pkg : tool.getPackages(module)) {
        if (tool.shouldInclude(pkg)) {
            List<Declaration> members = pkg.getMembers();
            for (Declaration member : members) {
                if (tool.shouldInclude(member)) {
                    if (member instanceof Value && ((Value) member).getTypeDeclaration().isAnonymous()) {
                        continue;
                    }
                    declarations.add(member);
                }
            }
        }
    }
    Collections.sort(declarations, ReferenceableComparatorByName.INSTANCE);
    return declarations;
}
Also used : ArrayList(java.util.ArrayList) Value(org.eclipse.ceylon.model.typechecker.model.Value) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 9 with Package

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

the class AnnotationUtil method isNaturalTarget.

/**
 * Whether an annotation (with the given {@code annotationCtorDecl}
 * annotation constructor) used on the given declaration ({@code useSite})
 * should be added to the Java annotations of the given generated program
 * elements ({@code target})
 * @param annotationCtorDecl
 * @param useSite
 * @param target
 * @return
 */
public static boolean isNaturalTarget(// use site is either a Declaration, or a Package, or a Module,
Function annotationCtorDecl, // module imports
Object useSite, OutputElement target) {
    EnumSet<AnnotationTarget> interopTargets;
    if (annotationCtorDecl instanceof AnnotationProxyMethod) {
        AnnotationProxyMethod annotationProxyMethod = (AnnotationProxyMethod) annotationCtorDecl;
        if (annotationProxyMethod.getAnnotationTarget() == target) {
            // Foo__WHATEVER, so honour the WHATEVER
            return true;
        }
        interopTargets = annotationProxyMethod.getAnnotationTargets();
    } else {
        interopTargets = null;
    }
    if (useSite instanceof Declaration) {
        if (ModelUtil.isConstructor((Declaration) useSite)) {
            if (useSite instanceof Functional) {
                return target == OutputElement.CONSTRUCTOR;
            } else if (useSite instanceof Value) {
                // If the constructor has a getter we can't annotate, let's
                // put the annotations on the constructor
                Class constructedClass = ModelUtil.getConstructedClass((Declaration) useSite);
                // See CeylonVisitor.transformSingletonConstructor for those tests
                if (constructedClass.isToplevel() || constructedClass.isClassMember())
                    return target == OutputElement.GETTER;
                return target == OutputElement.CONSTRUCTOR;
            }
        } else if (useSite instanceof Class) {
            if (((Class) useSite).getParameterList() != null && interopTargets != null && interopTargets.contains(AnnotationTarget.CONSTRUCTOR) && !interopTargets.contains(AnnotationTarget.TYPE)) {
                return target == OutputElement.CONSTRUCTOR;
            }
            return target == OutputElement.TYPE;
        } else if (useSite instanceof Interface) {
            return target == OutputElement.TYPE;
        } else if (useSite instanceof Value) {
            Value value = (Value) useSite;
            boolean p = value.isParameter() && target == OutputElement.PARAMETER;
            if (annotationCtorDecl instanceof AnnotationProxyMethod) {
                if (!value.isTransient() && (interopTargets == null || interopTargets.contains(AnnotationTarget.FIELD))) {
                    return target == OutputElement.FIELD;
                } else {
                    return target == OutputElement.GETTER;
                }
            } else {
                return p || target == OutputElement.GETTER;
            }
        } else if (useSite instanceof Setter) {
            return target == OutputElement.SETTER;
        } else if (useSite instanceof Function) {
            return target == OutputElement.METHOD;
        } else if (useSite instanceof Constructor) {
            return target == OutputElement.CONSTRUCTOR;
        } else if (useSite instanceof TypeAlias) {
            return target == OutputElement.TYPE;
        }
    } else if (useSite instanceof Package) {
        return (annotationCtorDecl instanceof AnnotationProxyMethod) ? target == OutputElement.PACKAGE : target == OutputElement.TYPE;
    } else if (useSite instanceof Module) {
        return target == OutputElement.TYPE;
    } else if (useSite instanceof Tree.ImportModule) {
        return target == OutputElement.FIELD;
    }
    throw new RuntimeException("" + useSite);
}
Also used : AnnotationTarget(org.eclipse.ceylon.model.loader.model.AnnotationTarget) AnnotationProxyMethod(org.eclipse.ceylon.model.loader.model.AnnotationProxyMethod) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) Functional(org.eclipse.ceylon.model.typechecker.model.Functional) Function(org.eclipse.ceylon.model.typechecker.model.Function) Value(org.eclipse.ceylon.model.typechecker.model.Value) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnnotationProxyClass(org.eclipse.ceylon.model.loader.model.AnnotationProxyClass) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) Interface(org.eclipse.ceylon.model.typechecker.model.Interface)

Example 10 with Package

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

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

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