Search in sources :

Example 71 with Module

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

the class CeylonVersionTool method run.

@Override
public void run() throws IOException, RecognitionException {
    // TODO if version is empty? Prompt? Or should --set have an optional argument?
    TypeCheckerBuilder tcb = new TypeCheckerBuilder();
    for (File path : this.sourceFolders) {
        tcb.addSrcDirectory(applyCwd(path));
    }
    TypeChecker tc = tcb.getTypeChecker();
    PhasedUnits pus = tc.getPhasedUnits();
    pus.visitModules();
    ArrayList<Module> moduleList = new ArrayList<Module>(pus.getModuleSourceMapper().getCompiledModules());
    Collections.sort(moduleList, new Comparator<Module>() {

        @Override
        public int compare(Module m1, Module m2) {
            if (match(m1) && !match(m2)) {
                return -1;
            } else if (!match(m1) && match(m2)) {
                return +1;
            }
            int cmp = m1.getNameAsString().compareToIgnoreCase(m2.getNameAsString());
            if (cmp == 0) {
                cmp = m1.getVersion().compareTo(m2.getVersion());
            }
            return cmp;
        }
    });
    // first update all module versions and remember which version we assigned to which module
    // because the user can update every individual version
    Map<String, String> updatedModuleVersions = new HashMap<String, String>();
    for (Module module : moduleList) {
        boolean isMatch = match(module);
        if (newVersion == null) {
            output(module, isMatch);
        } else if (isMatch) {
            if (!updateModuleVersion(module, updatedModuleVersions)) {
                return;
            }
        }
    }
    if (updateDistribution) {
        updatedModuleVersions.put("ceylon.bootstrap", newVersion);
        updatedModuleVersions.put("ceylon.language", newVersion);
        updatedModuleVersions.put("ceylon.runtime", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.compiler.java", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.compiler.js", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.typechecker", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.common", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.cli", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.model", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.module-loader", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.module-resolver", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.module-resolver-aether", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.module-resolver-webdav", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.module-resolver-javascript", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.langtools.classfile", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.tool.provider", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.tools", newVersion);
    }
    // now do dependencies because we know which modules we did update
    if (newVersion != null && !noUpdateDependencies) {
        for (Module module : moduleList) {
            if (!updateModuleImports(module, updatedModuleVersions)) {
                return;
            }
        }
    }
}
Also used : TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) PhasedUnits(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits) ImportModule(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportModule) Module(org.eclipse.ceylon.model.typechecker.model.Module) File(java.io.File)

Example 72 with Module

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

the class MainForTest method main.

/**
 * Files that are not under a proper module structure are
 * placed under a <nomodule> module.
 */
public static void main(String[] args) throws Exception {
    long start = System.nanoTime();
    RepositoryManager repositoryManager = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").outRepo("test/modules").logger(new LeakingLogger()).buildManager();
    TypeChecker typeChecker = new TypeCheckerBuilder().statistics(true).verbose(false).addSrcDirectory(new File("test/main")).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    int errors = typeChecker.getErrors();
    Tree.CompilationUnit compilationUnit = typeChecker.getPhasedUnitFromRelativePath("ceylon/language/Object.ceylon").getCompilationUnit();
    if (compilationUnit == null) {
        throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for files in .src");
    }
    compilationUnit = typeChecker.getPhasedUnitFromRelativePath("capture/Capture.ceylon").getCompilationUnit();
    if (compilationUnit == null) {
        throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for files in real src dir");
    }
    compilationUnit = typeChecker.getPhasedUnitFromRelativePath("org/eclipse/sample/multisource/Boo.ceylon").getCompilationUnit();
    Module module = compilationUnit.getUnit().getPackage().getModule();
    if (!"org.eclipse.sample.multisource".equals(module.getNameAsString())) {
        throw new RuntimeException("Unable to extract module name");
    }
    if (!"0.2".equals(module.getVersion())) {
        throw new RuntimeException("Unable to extract module version");
    }
    typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(new File("test/main/capture")).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    errors += typeChecker.getErrors();
    compilationUnit = typeChecker.getPhasedUnitFromRelativePath("Capture.ceylon").getCompilationUnit();
    if (compilationUnit == null) {
        throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for top level files (no package) in real src dir");
    }
    typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(new File("test/moduledep1")).addSrcDirectory(new File("test/moduledep2")).addSrcDirectory(new File("test/moduletest")).addSrcDirectory(new File("test/restricted")).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    errors += typeChecker.getErrors();
    ClosableVirtualFile latestZippedLanguageSourceFile = MainHelper.getLatestZippedLanguageSourceFile();
    typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(latestZippedLanguageSourceFile).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    errors += typeChecker.getErrors();
    latestZippedLanguageSourceFile.close();
    System.out.println("Tests took " + ((System.nanoTime() - start) / 1000000) + " ms");
    if (errors > 0) {
        System.exit(1);
    }
}
Also used : ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) LeakingLogger(org.eclipse.ceylon.compiler.typechecker.io.cmr.impl.LeakingLogger) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) Module(org.eclipse.ceylon.model.typechecker.model.Module) ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) File(java.io.File)

Example 73 with Module

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

the class ModelLoaderTests method functionalParameterParameterNames.

@Test
public void functionalParameterParameterNames() {
    compile("FunctionalParameterParameterNames.ceylon");
    try {
        verifyCompilerClassLoading("functionalparameterparameternamestest.ceylon", new RunnableTest() {

            @Override
            public void test(ModelLoader loader) {
                Module mod = loader.getLoadedModule(moduleForJavaModelLoading(), moduleVersionForJavaModelLoading());
                Assert.assertNotNull(mod);
                Package p = mod.getDirectPackage(packageForJavaModelLoading());
                Assert.assertNotNull(p);
                Declaration fpClass = p.getDirectMember("FunctionalParameterParameterNames", Collections.<Type>emptyList(), false);
                Assert.assertNotNull(fpClass);
                {
                    // functionalParameter
                    Function fp = (Function) fpClass.getDirectMember("functionalParameter", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(String))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertTrue(paramF.isDeclaredAnything());
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertTrue(modelF.isDeclaredVoid());
                    Assert.assertEquals("Anything(String)", typeName(modelF));
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramS = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String", typeName(modelS));
                }
                {
                    // callableValueParameter
                    Function fp = (Function) fpClass.getDirectMember("callableValueParameter", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(String))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertFalse(paramF.isDeclaredAnything());
                    Assert.assertTrue(paramF.getModel() instanceof Value);
                    Value modelF = (Value) paramF.getModel();
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals("Anything(String)", typeName(modelF));
                }
                {
                    // functionalParameterNested
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterNested", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(Anything(String)))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.isDeclaredAnything());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertEquals("Anything(Anything(String))", typeName(modelF));
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertTrue(modelF.isDeclaredVoid());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramF2 = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertTrue(paramF2.isDeclaredAnything());
                    Assert.assertEquals("f2", paramF2.getName());
                    Assert.assertTrue(paramF2.getModel() instanceof Function);
                    Function modelF2 = (Function) paramF2.getModel();
                    Assert.assertEquals("Anything(String)", typeName(modelF2));
                    Assert.assertEquals("f2", modelF2.getName());
                    Assert.assertTrue(modelF2.isDeclaredVoid());
                    Assert.assertEquals(1, modelF2.getParameterLists().size());
                    Assert.assertEquals(1, modelF2.getParameterLists().get(0).getParameters().size());
                    Parameter paramS = modelF2.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String", typeName(modelS));
                }
                {
                    // functionalParameterNested2
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterNested2", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(Anything(String, Anything(Boolean, Integer))))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals("Anything(Anything(String, Anything(Boolean, Integer)))", typeName(modelF));
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramF2 = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f2", paramF2.getName());
                    Assert.assertTrue(paramF2.getModel() instanceof Function);
                    Function modelF2 = (Function) paramF2.getModel();
                    Assert.assertEquals("Anything(String, Anything(Boolean, Integer))", typeName(modelF2));
                    Assert.assertEquals("f2", modelF2.getName());
                    Assert.assertEquals(1, modelF2.getParameterLists().size());
                    Assert.assertEquals(2, modelF2.getParameterLists().get(0).getParameters().size());
                    Parameter paramS = modelF2.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("String", typeName(modelS));
                    Assert.assertEquals("s", modelS.getName());
                    Parameter paramF3 = modelF2.getParameterLists().get(0).getParameters().get(1);
                    Assert.assertEquals("f3", paramF3.getName());
                    Assert.assertTrue(paramF3.getModel() instanceof Function);
                    Function modelF3 = (Function) paramF3.getModel();
                    Assert.assertEquals("Anything(Boolean, Integer)", typeName(modelF3));
                    Assert.assertEquals("f3", modelF3.getName());
                    Assert.assertEquals(1, modelF3.getParameterLists().size());
                    Assert.assertEquals(2, modelF3.getParameterLists().get(0).getParameters().size());
                    Parameter paramB1 = modelF3.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("b1", paramB1.getName());
                    Assert.assertTrue(paramB1.getModel() instanceof Value);
                    Value modelB1 = (Value) paramB1.getModel();
                    Assert.assertEquals("Boolean", typeName(modelB1));
                    Assert.assertEquals("b1", modelB1.getName());
                    Parameter paramI2 = modelF3.getParameterLists().get(0).getParameters().get(1);
                    Assert.assertEquals("i2", paramI2.getName());
                    Assert.assertTrue(paramI2.getModel() instanceof Value);
                    Value modelI2 = (Value) paramI2.getModel();
                    Assert.assertEquals("i2", modelI2.getName());
                    Assert.assertEquals("Integer", typeName(modelI2));
                }
                {
                    // functionalParameterMpl
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterMpl", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(Integer)(String))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertTrue(paramF.isDeclaredAnything());
                    Assert.assertEquals("mpl", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertTrue(modelF.isDeclaredVoid());
                    Assert.assertEquals("Anything(Integer)(String)", typeName(modelF));
                    Assert.assertEquals("mpl", modelF.getName());
                    Assert.assertEquals(2, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(1).getParameters().size());
                    Parameter paramS = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String", typeName(modelS));
                    Parameter paramS2 = modelF.getParameterLists().get(1).getParameters().get(0);
                    Assert.assertEquals("i2", paramS2.getName());
                    Assert.assertTrue(paramS2.getModel() instanceof Value);
                    Value modelS2 = (Value) paramS2.getModel();
                    Assert.assertEquals("i2", modelS2.getName());
                    Assert.assertEquals("Integer", typeName(modelS2));
                }
                {
                    // functionalParameterMpl2
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterMpl2", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Parameter paramMpl = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("mpl", paramMpl.getName());
                    Assert.assertTrue(paramMpl.getModel() instanceof Function);
                    Function modelMpl = (Function) paramMpl.getModel();
                    Assert.assertEquals("mpl", modelMpl.getName());
                    Assert.assertEquals(2, modelMpl.getParameterLists().size());
                    Assert.assertEquals(1, modelMpl.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals(1, modelMpl.getParameterLists().get(1).getParameters().size());
                    Parameter paramS = modelMpl.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String", typeName(modelS));
                    Parameter paramF = modelMpl.getParameterLists().get(1).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(2, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramB1 = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("b1", paramB1.getName());
                    Assert.assertTrue(paramB1.getModel() instanceof Value);
                    Value modelB1 = (Value) paramB1.getModel();
                    Assert.assertEquals("b1", modelB1.getName());
                    Assert.assertEquals("Boolean", typeName(modelB1));
                    Parameter paramI2 = modelF.getParameterLists().get(0).getParameters().get(1);
                    Assert.assertEquals("i2", paramI2.getName());
                    Assert.assertTrue(paramI2.getModel() instanceof Value);
                    Value modelI2 = (Value) paramI2.getModel();
                    Assert.assertEquals("i2", modelI2.getName());
                    Assert.assertEquals("Integer", typeName(modelI2));
                }
                {
                    // functionalParameterMpl3
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterMpl3", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Parameter paramMpl = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("mpl", paramMpl.getName());
                    Assert.assertTrue(paramMpl.getModel() instanceof Function);
                    Function modelMpl = (Function) paramMpl.getModel();
                    Assert.assertEquals("mpl", modelMpl.getName());
                    Assert.assertEquals(2, modelMpl.getParameterLists().size());
                    Assert.assertEquals(1, modelMpl.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals(1, modelMpl.getParameterLists().get(1).getParameters().size());
                    Parameter paramF = modelMpl.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(2, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramB1 = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("b1", paramB1.getName());
                    Assert.assertTrue(paramB1.getModel() instanceof Value);
                    Value modelB1 = (Value) paramB1.getModel();
                    Assert.assertEquals("b1", modelB1.getName());
                    Assert.assertEquals("Boolean", typeName(modelB1));
                    Parameter paramI2 = modelF.getParameterLists().get(0).getParameters().get(1);
                    Assert.assertEquals("i2", paramI2.getName());
                    Assert.assertTrue(paramI2.getModel() instanceof Value);
                    Value modelI2 = (Value) paramI2.getModel();
                    Assert.assertEquals("i2", modelI2.getName());
                    Assert.assertEquals("Integer", typeName(modelI2));
                    Parameter paramS = modelMpl.getParameterLists().get(1).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String", typeName(modelS));
                }
                {
                    // functionalParameterReturningCallable
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterReturningCallable", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals("Anything()", modelF.getType().asString());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramS = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String", modelS.getType().asString());
                }
                {
                    // functionalParameterReturningCallable
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterTakingCallable", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals("Anything", modelF.getType().asString());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramF2 = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f2", paramF2.getName());
                    Assert.assertTrue(paramF2.getModel() instanceof Value);
                    Value modelF2 = (Value) paramF2.getModel();
                    Assert.assertEquals("f2", modelF2.getName());
                    Assert.assertEquals("Anything(String)", modelF2.getType().asString());
                }
                {
                    // functionalParameterVariadicStar
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterVariadicStar", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(String*))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertTrue(paramF.isDeclaredAnything());
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertTrue(modelF.isDeclaredVoid());
                    Assert.assertEquals("Anything(String*)", typeName(modelF));
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramS = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.isSequenced());
                    Assert.assertFalse(paramS.isAtLeastOne());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String[]", typeName(modelS));
                }
                {
                    // functionalParameterVariadicPlus
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterVariadicPlus", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(String+))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertTrue(paramF.isDeclaredAnything());
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertTrue(modelF.isDeclaredVoid());
                    Assert.assertEquals("Anything(String+)", typeName(modelF));
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramS = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.isSequenced());
                    Assert.assertTrue(paramS.isAtLeastOne());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("[String+]", typeName(modelS));
                }
            }

            private String typeName(FunctionOrValue fp) {
                if (fp instanceof Function) {
                    return fp.appliedTypedReference(null, Collections.<Type>emptyList()).getFullType().asString();
                } else if (fp instanceof Value) {
                    return fp.getType().asString();
                }
                return null;
            }
        });
    } catch (RuntimeException e) {
        if (e.getCause() instanceof org.junit.ComparisonFailure) {
            throw (org.junit.ComparisonFailure) e.getCause();
        } else if (e.getCause() instanceof java.lang.AssertionError) {
            throw (java.lang.AssertionError) e.getCause();
        }
        throw e;
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) ModelLoader(org.eclipse.ceylon.model.loader.ModelLoader) CeylonModelLoader(org.eclipse.ceylon.compiler.java.loader.CeylonModelLoader) RuntimeModelLoader(org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModelLoader) AbstractModelLoader(org.eclipse.ceylon.model.loader.AbstractModelLoader) DeclarationType(org.eclipse.ceylon.model.loader.ModelLoader.DeclarationType) Type(org.eclipse.ceylon.model.typechecker.model.Type) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Package(org.eclipse.ceylon.model.typechecker.model.Package) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Module(org.eclipse.ceylon.model.typechecker.model.Module) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Test(org.junit.Test)

Example 74 with Module

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

the class ModelLoaderTests method compareNativeRuntimeWithJavaRuntime.

@Test
public void compareNativeRuntimeWithJavaRuntime() {
    // parse the ceylon sources from the language module and
    // build a map of all the native declarations
    final Map<String, Declaration> nativeFromSource = new HashMap<String, Declaration>();
    ClosableVirtualFile latestZippedLanguageSourceFile = getLatestZippedLanguageSourceFile();
    try {
        TypeCheckerBuilder typeCheckerBuilder = new TypeCheckerBuilder().verbose(false).addSrcDirectory(latestZippedLanguageSourceFile);
        TypeChecker typeChecker = typeCheckerBuilder.getTypeChecker();
        typeChecker.process();
        for (PhasedUnit pu : typeChecker.getPhasedUnits().getPhasedUnits()) {
            for (Declaration d : pu.getDeclarations()) {
                if (d.isNativeHeader() && d.isToplevel()) {
                    String qualifiedNameString = d.getQualifiedNameString();
                    String key = d.getDeclarationKind() + ":" + qualifiedNameString;
                    Declaration prev = nativeFromSource.put(key, d);
                    if (prev != null) {
                        Assert.fail("Two declarations with the same key " + key + ": " + d + " and: " + prev);
                    }
                }
            }
        }
    } finally {
        latestZippedLanguageSourceFile.close();
    }
    System.out.println(nativeFromSource);
    // now compile something (it doesn't matter what, we just need
    // to get our hands on from-binary models for the language module)
    RunnableTest tester = new RunnableTest() {

        @Override
        public void test(ModelLoader loader) {
            OtherModelCompare comparer = new OtherModelCompare();
            Module binaryLangMod = loader.getLoadedModule(AbstractModelLoader.CEYLON_LANGUAGE, Versions.CEYLON_VERSION_NUMBER);
            for (Map.Entry<String, Declaration> entry : nativeFromSource.entrySet()) {
                System.out.println(entry.getKey());
                Declaration source = entry.getValue();
                ModelLoader.DeclarationType dt = null;
                switch(source.getDeclarationKind()) {
                    case TYPE:
                    case TYPE_PARAMETER:
                        dt = DeclarationType.TYPE;
                        break;
                    case MEMBER:
                    case SETTER:
                        dt = DeclarationType.VALUE;
                        break;
                }
                // Ensure the package is loaded
                binaryLangMod.getDirectPackage(source.getQualifiedNameString().replaceAll("::.*", ""));
                Declaration binary = loader.getDeclaration(binaryLangMod, source.getQualifiedNameString().replace("::", "."), dt);
                comparer.compareDeclarations(source.getQualifiedNameString(), source, binary);
            }
        }
    };
    verifyCompilerClassLoading("Any.ceylon", tester, defaultOptions);
    verifyRuntimeClassLoading(tester);
}
Also used : ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) HashMap(java.util.HashMap) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) ModelLoader(org.eclipse.ceylon.model.loader.ModelLoader) CeylonModelLoader(org.eclipse.ceylon.compiler.java.loader.CeylonModelLoader) RuntimeModelLoader(org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModelLoader) AbstractModelLoader(org.eclipse.ceylon.model.loader.AbstractModelLoader) DeclarationType(org.eclipse.ceylon.model.loader.ModelLoader.DeclarationType) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Module(org.eclipse.ceylon.model.typechecker.model.Module) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 75 with Module

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

the class JsonModule method getPackage.

@Override
public Package getPackage(String name) {
    if ("default".equals(name)) {
        name = "";
    }
    // search direct packages
    Package p = getDirectPackage(name);
    if (p != null) {
        return p;
    }
    // search imported modules
    HashSet<Module> visited = new HashSet<Module>();
    visited.add(this);
    for (ModuleImport imp : getImports()) {
        p = getPackageFromImport(name, imp.getModule(), visited);
        if (p != null) {
            return p;
        }
    }
    // not found
    return null;
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) HashSet(java.util.HashSet)

Aggregations

Module (org.eclipse.ceylon.model.typechecker.model.Module)113 LazyModule (org.eclipse.ceylon.model.loader.model.LazyModule)37 Package (org.eclipse.ceylon.model.typechecker.model.Package)26 ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)25 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)20 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)19 ArrayList (java.util.ArrayList)18 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)16 File (java.io.File)14 Type (org.eclipse.ceylon.model.typechecker.model.Type)14 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)9 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)9 Test (org.junit.Test)9 Value (org.eclipse.ceylon.model.typechecker.model.Value)8 LinkedList (java.util.LinkedList)7 List (java.util.List)7 Backends (org.eclipse.ceylon.common.Backends)7 ClassMirror (org.eclipse.ceylon.model.loader.mirror.ClassMirror)7