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;
}
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());
}
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();
}
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;
}
}
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());
}
Aggregations