Search in sources :

Example 46 with Module

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

the class CeylonDocToolTests method bug2285.

@Test
public void bug2285() throws Exception {
    String pathname = "test/ceylondoc-doesnotexist";
    String moduleName = "com.redhat.ceylon.ceylondoc.test.modules.bug2285";
    Module module = new Module();
    module.setName(Arrays.asList(moduleName));
    module.setVersion("1");
    try {
        CeylonDocTool tool = tool(Arrays.asList(new File(pathname)), Arrays.asList(new File("doc")), Arrays.asList(moduleName), true, false, false);
        tool.run();
        Assert.fail();
    } catch (RuntimeException x) {
        Assert.assertEquals("Can't find module: com.redhat.ceylon.ceylondoc.test.modules.bug2285", x.getMessage());
    }
}
Also used : CeylonDocTool(com.redhat.ceylon.ceylondoc.CeylonDocTool) Module(com.redhat.ceylon.model.typechecker.model.Module) File(java.io.File) Test(org.junit.Test)

Example 47 with Module

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

the class CeylonDocToolTests method bug2101.

@Test
public void bug2101() throws Exception {
    String pathname = "test/ceylondoc";
    String moduleName = "com.redhat.ceylon.ceylondoc.test.modules.bug2101";
    Module module = new Module();
    module.setName(Arrays.asList(moduleName));
    module.setVersion("1");
    CeylonDocTool tool = tool(Arrays.asList(new File(pathname)), Arrays.asList(new File("doc")), Arrays.asList(moduleName), true, false, false);
    tool.run();
    File destDir = getOutputDir(tool, module);
    assertMatchInFile(destDir, "index.html", Pattern.compile("<span class='identifier'>bug2101</span>\\(\\)</code>" + "<div class='description'><div class='doc section'><p>actual doc</p>"));
    assertMatchInFile(destDir, "a/index.html", Pattern.compile("<span class='identifier'>bug2101_wildcard_import</span>\\(\\)</code>" + "<div class='description'><div class='doc section'></div>" + "<div class='annotations section'><span class='title'>Annotations: </span><ul><li>doc\\(<span class='literal'>&quot;fake doc&quot;</span>\\)"));
}
Also used : CeylonDocTool(com.redhat.ceylon.ceylondoc.CeylonDocTool) Module(com.redhat.ceylon.model.typechecker.model.Module) File(java.io.File) Test(org.junit.Test)

Example 48 with Module

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

the class ExpressionTransformer 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
     */
private 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.getProxyClass().getAnnotationTarget();
    } 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) {
                return target == OutputElement.GETTER;
            }
        } 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;
            TypeDeclaration decltype = typeFact().getValueDeclarationType().getDeclaration();
            if (value.isParameter() && !value.isShared() && !(value.isCaptured() && value.isMember())) {
                return target == OutputElement.PARAMETER;
            } else if (annotationCtorDecl instanceof AnnotationProxyMethod) {
                if (value.isLate() || value.isVariable()) {
                    return target == OutputElement.SETTER;
                } else if (!value.isTransient()) {
                    return target == OutputElement.FIELD;
                } else {
                    return target == OutputElement.GETTER;
                }
            } else {
                return 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 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(com.redhat.ceylon.model.loader.model.AnnotationTarget) AnnotationProxyMethod(com.redhat.ceylon.model.loader.model.AnnotationProxyMethod) Constructor(com.redhat.ceylon.model.typechecker.model.Constructor) TypeAlias(com.redhat.ceylon.model.typechecker.model.TypeAlias) Functional(com.redhat.ceylon.model.typechecker.model.Functional) Function(com.redhat.ceylon.model.typechecker.model.Function) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) FieldValue(com.redhat.ceylon.model.loader.model.FieldValue) Value(com.redhat.ceylon.model.typechecker.model.Value) Setter(com.redhat.ceylon.model.typechecker.model.Setter) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) Class(com.redhat.ceylon.model.typechecker.model.Class) JCNewClass(com.sun.tools.javac.tree.JCTree.JCNewClass) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Package(com.redhat.ceylon.model.typechecker.model.Package) Module(com.redhat.ceylon.model.typechecker.model.Module) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface)

Example 49 with Module

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

the class CMRTests method testOverridesCeylonModuleInSourceImport.

@Test
public void testOverridesCeylonModuleInSourceImport() {
    setupBinaryModulesForOverridesCeylonModuleTests();
    ErrorCollector collector = new ErrorCollector();
    CeyloncTaskImpl compilerTask = getCompilerTask(Arrays.asList("-continue", "-src", getPackagePath() + "/modules", "-overrides", getPackagePath() + "modules/overridesCeylonModule/overrides-a-version.xml"), collector, "modules/overridesCeylonModule/module.ceylon");
    ModulesRetriever modulesRetriever = new ModulesRetriever(compilerTask.getContext());
    compilerTask.setTaskListener(modulesRetriever);
    Boolean result = compilerTask.call();
    Assert.assertEquals(Boolean.FALSE, result);
    compareErrors(collector.get(Diagnostic.Kind.ERROR), new CompilerError(2, "The module import should not be overriden, since it is explicitely imported by a project source module"));
    assert (modulesRetriever.modules != null);
    Module a = modulesRetriever.modules.get("a");
    Module b = modulesRetriever.modules.get("b");
    Module c = modulesRetriever.modules.get("c");
    assert (a != null);
    assert (b != null);
    assert (c != null);
    assertEquals("The version override should not be applied to modules imported in source code", "2", a.getVersion());
    assertEquals("The version override should not be applied to modules imported in source code", "2", b.getVersion());
    assertEquals("The version override should not be applied to modules imported in source code", "2", c.getVersion());
}
Also used : ErrorCollector(com.redhat.ceylon.compiler.java.test.ErrorCollector) CompilerError(com.redhat.ceylon.compiler.java.test.CompilerError) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) Module(com.redhat.ceylon.model.typechecker.model.Module) Test(org.junit.Test)

Example 50 with Module

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

the class CMRTests method testOverridesCeylonModuleShareImport.

@Test
public void testOverridesCeylonModuleShareImport() {
    setupBinaryModulesForOverridesCeylonModuleTests();
    ErrorCollector collector = new ErrorCollector();
    CeyloncTaskImpl compilerTask = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules", "-overrides", getPackagePath() + "modules/overridesCeylonModule/overrides-share-c-import.xml"), collector, "modules/overridesCeylonModule/module.ceylon");
    ModulesRetriever modulesRetriever = new ModulesRetriever(compilerTask.getContext());
    compilerTask.setTaskListener(modulesRetriever);
    Boolean result = compilerTask.call();
    Assert.assertEquals(Boolean.TRUE, result);
    Module a = modulesRetriever.modules.get("a");
    assert (a != null);
    ModuleImport cImport = getModuleImport(a, "c");
    assert (cImport != null);
    assertEquals("The 'c' module import should be seen as 'exported' after applying the overrides file", true, cImport.isExport());
}
Also used : ModuleImport(com.redhat.ceylon.model.typechecker.model.ModuleImport) ErrorCollector(com.redhat.ceylon.compiler.java.test.ErrorCollector) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) Module(com.redhat.ceylon.model.typechecker.model.Module) Test(org.junit.Test)

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