Search in sources :

Example 26 with Module

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

Example 27 with Module

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

the class CeylonModelLoader method lookupNewClassMirror.

@Override
public ClassMirror lookupNewClassMirror(Module module, String name) {
    synchronized (getLock()) {
        ClassMirror classMirror = lookupNewClassMirror(name);
        if (classMirror == null)
            return null;
        Module classMirrorModule = findModuleForClassMirror(classMirror);
        if (classMirrorModule == null) {
            logVerbose("Found a class mirror with no module");
            return null;
        }
        // make sure it's imported
        if (isImported(module, classMirrorModule)) {
            return classMirror;
        }
        logVerbose("Found a class mirror that is not imported: " + name);
        return null;
    }
}
Also used : Module(com.redhat.ceylon.model.typechecker.model.Module) ClassMirror(com.redhat.ceylon.model.loader.mirror.ClassMirror)

Example 28 with Module

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

the class AnnotationLoader method setPrimaryFromAnnotationInvocationAnnotation.

private void setPrimaryFromAnnotationInvocationAnnotation(AnnotationMirror annotationInvocationAnnotation, AnnotationInvocation ai) {
    TypeMirror annotationType = (TypeMirror) annotationInvocationAnnotation.getValue(AbstractModelLoader.CEYLON_ANNOTATION_INSTANTIATION_ANNOTATION_MEMBER);
    ClassMirror annotationClassMirror = annotationType.getDeclaredClass();
    Module module = modelLoader.findModuleForClassMirror(annotationClassMirror);
    if (annotationClassMirror.getAnnotation(AbstractModelLoader.CEYLON_METHOD_ANNOTATION) != null) {
        ai.setPrimary((Function) modelLoader.convertToDeclaration(module, annotationClassMirror, DeclarationType.VALUE));
    } else {
        ai.setPrimary((Class) modelLoader.convertToDeclaration(module, annotationClassMirror, DeclarationType.TYPE));
    }
}
Also used : TypeMirror(com.redhat.ceylon.model.loader.mirror.TypeMirror) Module(com.redhat.ceylon.model.typechecker.model.Module) ClassMirror(com.redhat.ceylon.model.loader.mirror.ClassMirror)

Example 29 with Module

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

the class Resolve method loadClass.

/** Load toplevel or member class with given fully qualified name and
     *  verify that it is accessible.
     *  @param env       The current environment.
     *  @param name      The fully qualified name of the class to be loaded.
     */
Symbol loadClass(Env<AttrContext> env, Name name) {
    try {
        ClassSymbol c = reader.loadClass(name);
        if (!isAccessible(env, c))
            return new AccessError(c);
        if (modelLoader != null && !sourceLanguage.isCeylon()) {
            // special cases for java.lang.String and java.lang.Override which are fine
            // See https://github.com/ceylon/ceylon-compiler/issues/2003
            String nameString = name.toString();
            if (!nameString.equals("java.lang.String") && !nameString.equals("java.lang.Override")) {
                // Check if the class is accessible according to Ceylon's access rules
                String scopePackageName = pkgSymbol(env.info.scope.owner).toString();
                Package scopePackage = modelLoader.findPackage(scopePackageName);
                // Don't check if we failed to find it
                if (scopePackage != null) {
                    Module scopeModule = scopePackage.getModule();
                    // Ugly special case where we skip the test when we're compiling the language module itself
                    if (scopeModule != modelLoader.getLanguageModule()) {
                        String importedPackageName = modelLoader.getPackageNameForQualifiedClassName(pkgName(nameString), nameString);
                        Package importedPackage = scopeModule.getPackage(importedPackageName);
                        // Don't check if we failed to find it
                        if (importedPackage == null) {
                            return new ImportError(c, scopeModule);
                        }
                    }
                }
            }
        }
        return c;
    } catch (ClassReader.BadClassFile err) {
        throw err;
    } catch (CompletionFailure ex) {
        return typeNotFound;
    }
}
Also used : CeylonClassReader(com.redhat.ceylon.compiler.java.loader.CeylonClassReader) LocalizedString(com.sun.tools.javac.api.Formattable.LocalizedString) Package(com.redhat.ceylon.model.typechecker.model.Package) Module(com.redhat.ceylon.model.typechecker.model.Module)

Example 30 with Module

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

the class CeylonDocTool method getFolder.

private File getFolder(Package pkg) {
    Module module = pkg.getModule();
    List<String> unprefixedName;
    if (module.isDefault())
        unprefixedName = pkg.getName();
    else {
        // remove the leading module name part
        unprefixedName = pkg.getName().subList(module.getName().size(), pkg.getName().size());
    }
    File dir = new File(getApiOutputFolder(module), join("/", unprefixedName));
    if (shouldInclude(module))
        dir.mkdirs();
    return dir;
}
Also used : Module(com.redhat.ceylon.model.typechecker.model.Module) File(java.io.File)

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