Search in sources :

Example 26 with Module

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

the class ExpressionVisitor method handleNativeHeader.

private Declaration handleNativeHeader(Declaration dec, Node that, boolean error) {
    // really nasty workaround to get the "real" scope
    // in which an annotation occurs! (bug #7143)
    Scope scope = (that instanceof Tree.BaseMemberExpression ? ((Tree.BaseMemberExpression) that).getIdentifier() : that).getScope();
    Declaration impl = dec;
    Declaration hdr = null;
    Module ctxModule = unit.getPackage().getModule();
    Module decModule = dec.getUnit().getPackage().getModule();
    Backends decModuleBackends = getModuleBackends(decModule, unit);
    Backends inBackends = scope.getScopedBackends();
    if (dec.isNative()) {
        Backends backends = inBackends.none() ? unit.getSupportedBackends() : inBackends;
        if (dec.isNativeHeader()) {
            hdr = dec;
            impl = getNativeDeclaration(hdr, backends);
        } else {
            Declaration tmp = getNativeHeader(dec);
            if (tmp != dec) {
                hdr = tmp;
                if (hdr != null) {
                    if (backends.none() || !backends.supports(dec.getNativeBackends())) {
                        impl = getNativeDeclaration(hdr, backends);
                    }
                }
            }
        }
    }
    if (error && impl != null && (dec.isToplevel() || dec.isMember()) && declarationScope(scope) != null && (hdr == null || !isImplemented(hdr)) && (ctxModule != decModule && !decModuleBackends.none() || ctxModule == decModule && dec.isNative() && hdr == null) && (inBackends.none() || impl.isNative() && !isForBackend(impl.getNativeBackends(), inBackends) || !decModuleBackends.none() && !isForBackend(decModuleBackends, inBackends))) {
        Declaration d = declarationScope(scope);
        if (!inBackends.none()) {
            that.addError("illegal reference to native declaration '" + dec.getName(unit) + "': native declaration '" + d.getName(unit) + "' has a different backend");
        } else {
            that.addError("illegal reference to native declaration '" + dec.getName(unit) + "': declaration '" + d.getName(unit) + "' is not native (mark it or the module native)", 20010);
        }
    }
    if (dec.isNative()) {
        return inBackends.none() || impl == null ? dec : impl;
    }
    return dec;
}
Also used : NativeUtil.getBackends(org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.getBackends) Backends(org.eclipse.ceylon.common.Backends) NativeUtil.declarationScope(org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) Module(org.eclipse.ceylon.model.typechecker.model.Module) AnalyzerUtil.importedModule(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.importedModule)

Example 27 with Module

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.ModuleLiteral that) {
    super.visit(that);
    Tree.ImportPath path = that.getImportPath();
    if (path == null) {
        path = new Tree.ImportPath(null);
        that.setImportPath(path);
    }
    Module mod = path.getIdentifiers().isEmpty() ? unit.getPackage().getModule() : importedModule(path, that.getRestriction());
    path.setModel(mod);
    that.setTypeModel(unit.getModuleDeclarationType());
}
Also used : CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Module(org.eclipse.ceylon.model.typechecker.model.Module) AnalyzerUtil.importedModule(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.importedModule)

Example 28 with Module

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

the class VisibilityVisitor method exportHint.

private String exportHint() {
    StringBuilder hint = new StringBuilder(" (mark module import");
    if (modules.size() > 1) {
        hint.append("s");
    }
    hint.append(" 'shared' for ");
    boolean first = true;
    for (Module m : modules) {
        if (first) {
            first = false;
        } else {
            hint.append(", ");
        }
        hint.append("'").append(m.getNameAsString()).append("'");
    }
    hint.append(")");
    modules.clear();
    return hint.toString();
}
Also used : Module(org.eclipse.ceylon.model.typechecker.model.Module)

Example 29 with Module

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

the class PhasedUnit method validateTree.

public void validateTree() {
    // System.out.println("Validating tree for " + fileName);
    if (!treeValidated) {
        String fn = unit.getRelativePath();
        for (int i = 0; i < fn.length(); i = fn.offsetByCodePoints(i, 1)) {
            int cp = fn.codePointAt(i);
            if (cp > 127) {
                rootNode.addUsageWarning(Warning.filenameNonAscii, "source file name has non-ASCII characters: " + fn);
            }
        }
        String ufn = unit.getFilename();
        for (Unit u : unit.getPackage().getUnits()) {
            if (!u.equals(unit) && u.getFilename().equalsIgnoreCase(ufn)) {
                if (u.getFilename().equals(ufn)) {
                    String errorMessage = "identical source files: " + unit.getFullPath() + " and " + u.getFullPath();
                    if (u.getFilename().equals(MODULE_FILE) || u.getFilename().equals(PACKAGE_FILE)) {
                        errorMessage += " (a module/package descriptor should be defined only once, even in case of multiple source directories)";
                    }
                    rootNode.addError(errorMessage);
                } else {
                    rootNode.addUsageWarning(Warning.filenameCaselessCollision, "source file names differ only by case: " + unit.getFullPath() + " and " + u.getFullPath());
                }
            }
        }
        rootNode.visit(new Validator().setExceptionHandler(this));
        rootNode.visit(new Visitor() {

            @Override
            public void visit(ModuleDescriptor that) {
                super.visit(that);
                ImportPath importPath = that.getImportPath();
                if (importPath != null) {
                    String moduleName = formatPath(importPath.getIdentifiers());
                    ModuleSourceMapper moduleManagerUtil = moduleSourceMapperRef.get();
                    if (moduleManagerUtil != null) {
                        for (Module otherModule : moduleManagerUtil.getCompiledModules()) {
                            String otherModuleName = otherModule.getNameAsString();
                            if (moduleName.startsWith(otherModuleName + ".") || otherModuleName.startsWith(moduleName + ".")) {
                                StringBuilder error = new StringBuilder().append("Found two modules within the same hierarchy: '").append(otherModule.getNameAsString()).append("' and '").append(moduleName).append("'");
                                that.addError(error.toString());
                            }
                        }
                    }
                }
            }
        }.setExceptionHandler(this));
        treeValidated = true;
    }
}
Also used : ModuleDescriptor(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ModuleDescriptor) DeprecationVisitor(org.eclipse.ceylon.compiler.typechecker.util.DeprecationVisitor) ImportVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.ImportVisitor) TypeHierarchyVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeHierarchyVisitor) LocalDeclarationVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.LocalDeclarationVisitor) StatisticsVisitor(org.eclipse.ceylon.compiler.typechecker.util.StatisticsVisitor) InheritanceVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.InheritanceVisitor) ExpressionVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.ExpressionVisitor) SpecificationVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.SpecificationVisitor) RefinementVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.RefinementVisitor) PrintVisitor(org.eclipse.ceylon.compiler.typechecker.util.PrintVisitor) SelfReferenceVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.SelfReferenceVisitor) TypeArgumentVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeArgumentVisitor) VisibilityVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.VisibilityVisitor) DeclarationVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.DeclarationVisitor) SupertypeVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.SupertypeVisitor) ModuleVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleVisitor) UsageVisitor(org.eclipse.ceylon.compiler.typechecker.util.UsageVisitor) LiteralVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.LiteralVisitor) Visitor(org.eclipse.ceylon.compiler.typechecker.tree.Visitor) ControlFlowVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.ControlFlowVisitor) TypeVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor) AnnotationVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnnotationVisitor) DefaultTypeArgVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.DefaultTypeArgVisitor) AssertionVisitor(org.eclipse.ceylon.compiler.typechecker.util.AssertionVisitor) AliasVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.AliasVisitor) ImportPath(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportPath) ModuleSourceMapper(org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) Module(org.eclipse.ceylon.model.typechecker.model.Module) Validator(org.eclipse.ceylon.compiler.typechecker.tree.Validator)

Example 30 with Module

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

the class CMRTests method testOverridesCeylonModuleVersionProducesJavaModule.

@Test
public void testOverridesCeylonModuleVersionProducesJavaModule() {
    setupBinaryModulesForOverridesCeylonModuleTests();
    ErrorCollector collector = new ErrorCollector();
    CeyloncTaskImpl compilerTask = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules", "-overrides", getPackagePath() + "modules/overridesCeylonModule/overrides-b-version.xml"), collector, "modules/overridesCeylonModule/module.ceylon");
    ModulesRetriever modulesRetriever = new ModulesRetriever(compilerTask.getContext());
    compilerTask.setTaskListener(modulesRetriever);
    Boolean result = compilerTask.call();
    Assert.assertEquals(Boolean.TRUE, result);
    assert (modulesRetriever.modules != null);
    Module b = modulesRetriever.modules.get("b");
    assert (b != null);
    assertEquals("The Ceylon module 'b' is now seen as a Java module when a version override is applied", false, b.isJava());
}
Also used : ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) Module(org.eclipse.ceylon.model.typechecker.model.Module) Test(org.junit.Test)

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