use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class LazyModuleSourceMapper method shouldAbortOnDuplicateModule.
private boolean shouldAbortOnDuplicateModule(Module module, String moduleName, AbstractModelLoader modelLoader, LinkedList<Module> dependencyTree) {
String standardisedModuleName = ModuleUtil.toCeylonModuleName(moduleName);
// check for an already loaded module with the same name but different version
for (Module loadedModule : getContext().getModules().getListOfModules()) {
String loadedModuleName = loadedModule.getNameAsString();
String standardisedLoadedModuleName = ModuleUtil.toCeylonModuleName(loadedModuleName);
boolean sameModule = loadedModuleName.equals(moduleName);
boolean similarModule = standardisedLoadedModuleName.equals(standardisedModuleName);
if ((sameModule || similarModule) && !loadedModule.getVersion().equals(module.getVersion()) && modelLoader.isModuleInClassPath(loadedModule)) {
if (sameModule) {
String[] versions = VersionComparator.orderVersions(module.getVersion(), loadedModule.getVersion());
String error = "source code imports two different versions of module '" + moduleName + "': " + "version '" + versions[0] + "' and version '" + versions[1] + "'";
addConflictingModuleErrorToModule(moduleName, dependencyTree.getFirst(), error);
} else {
String moduleA;
String moduleB;
if (loadedModuleName.compareTo(moduleName) < 0) {
moduleA = ModuleUtil.makeModuleName(loadedModuleName, loadedModule.getVersion());
moduleB = ModuleUtil.makeModuleName(moduleName, module.getVersion());
} else {
moduleA = ModuleUtil.makeModuleName(moduleName, module.getVersion());
moduleB = ModuleUtil.makeModuleName(loadedModuleName, loadedModule.getVersion());
}
String error = "source code imports two different versions of similar modules '" + moduleA + "' and '" + moduleB + "'";
addConflictingModuleWarningToModule(moduleA, dependencyTree.getFirst(), Warning.similarModule, error);
}
return true;
}
}
return false;
}
use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class LazyModuleSourceMapper method setupJavaModule.
private void setupJavaModule(ModuleImport moduleImport, LazyModule module, AbstractModelLoader modelLoader, ModuleManager moduleManager, ArtifactResult artifact) {
// we didn't find module.class so it must be a java module if it's not the default module
module.setJava(true);
module.setNativeBackends(Backend.Java.asSet());
modelLoader.loadJava9Module(module, artifact.artifact());
List<ArtifactResult> deps = artifact.dependencies();
boolean forceExport = ModuleUtil.isMavenModule(module.getNameAsString()) && modelLoader.isFullyExportMavenDependencies();
for (ArtifactResult dep : deps) {
// forget runtime, test and even provided
if (dep.moduleScope() != ModuleScope.COMPILE)
continue;
// re-export them anyway
if (dep.optional())
continue;
Module dependency = moduleManager.getOrCreateModule(ModuleManager.splitModuleName(dep.name()), dep.version());
ModuleImport depImport = moduleManager.findImport(module, dependency);
if (depImport == null) {
moduleImport = new ModuleImport(dep.namespace(), dependency, dep.optional(), // allow forcing export but not for optional modules
dep.exported() || forceExport && !dep.optional(), Backend.Java);
module.addImport(moduleImport);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class AbstractModelLoader method convertDeclaredTypeToDeclaration.
private Declaration convertDeclaredTypeToDeclaration(Module moduleScope, TypeMirror type, DeclarationType declarationType) {
// SimpleReflType does not do declared class so we make an exception for it
String typeName = type.getQualifiedName();
if (type instanceof SimpleReflType) {
Module module = null;
switch(((SimpleReflType) type).getModule()) {
case CEYLON:
module = getLanguageModule();
break;
case JDK:
module = getJDKBaseModule();
break;
}
return convertToDeclaration(module, typeName, declarationType);
}
ClassMirror classMirror = type.getDeclaredClass();
Module module = findModuleForClassMirror(classMirror);
if (module != null && isImported(moduleScope, module)) {
return convertToDeclaration(module, typeName, declarationType);
} else {
if (module != null && isFlatClasspath() && isMavenModule(moduleScope))
return convertToDeclaration(module, typeName, declarationType);
String error = "Declaration '" + typeName + "' could not be found in module '" + moduleScope.getNameAsString() + "' or its imported modules";
if (module != null && !module.isDefaultModule())
error += " but was found in the non-imported module '" + module.getNameAsString() + "'";
return logModelResolutionException(null, moduleScope, error).getDeclaration();
}
}
use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class AbstractModelLoader method loadCompiledModule.
private boolean loadCompiledModule(Module module, ClassMirror moduleClass, boolean loadModuleImports) {
String moduleClassName = moduleClass.getQualifiedName();
String name = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "name");
String version = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "version");
if (name == null || name.isEmpty()) {
logWarning("Module class " + moduleClassName + " contains no name, ignoring it");
return false;
}
if (!name.equals(module.getNameAsString())) {
logWarning("Module class " + moduleClassName + " declares an invalid name: " + name + ". It should be: " + module.getNameAsString());
return false;
}
if (version == null || version.isEmpty()) {
logWarning("Module class " + moduleClassName + " contains no version, ignoring it");
return false;
}
if (!version.equals(module.getVersion())) {
logWarning("Module class " + moduleClassName + " declares an invalid version: " + version + ". It should be: " + module.getVersion());
return false;
}
// String label = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "label");
// module.setLabel(label);
int major = getAnnotationIntegerValue(moduleClass, CEYLON_CEYLON_ANNOTATION, "major", 0);
int minor = getAnnotationIntegerValue(moduleClass, CEYLON_CEYLON_ANNOTATION, "minor", 0);
module.setJvmMajor(major);
module.setJvmMinor(minor);
// no need to load the "nativeBackends" annotation value, it's loaded from annotations
setAnnotations(module, moduleClass, false);
if (loadModuleImports) {
List<AnnotationMirror> imports = getAnnotationArrayValue(moduleClass, CEYLON_MODULE_ANNOTATION, "dependencies");
if (imports != null) {
boolean supportsNamespaces = ModuleUtil.supportsImportsWithNamespaces(major, minor);
for (AnnotationMirror importAttribute : imports) {
String dependencyName = (String) importAttribute.getValue("name");
if (dependencyName != null) {
String namespace;
if (supportsNamespaces) {
namespace = (String) importAttribute.getValue("namespace");
if (namespace != null && namespace.isEmpty()) {
namespace = null;
}
} else {
if (ModuleUtil.isMavenModule(dependencyName)) {
namespace = "maven";
} else {
namespace = null;
}
}
String dependencyVersion = (String) importAttribute.getValue("version");
Module dependency = moduleManager.getOrCreateModule(ModuleManager.splitModuleName(dependencyName), dependencyVersion);
Boolean optionalVal = (Boolean) importAttribute.getValue("optional");
Boolean exportVal = (Boolean) importAttribute.getValue("export");
List<String> nativeBackends = (List<String>) importAttribute.getValue("nativeBackends");
Backends backends = nativeBackends == null ? Backends.ANY : Backends.fromAnnotations(nativeBackends);
ModuleImport moduleImport = moduleManager.findImport(module, dependency);
if (moduleImport == null) {
boolean optional = optionalVal != null && optionalVal;
boolean export = exportVal != null && exportVal;
moduleImport = new ModuleImport(namespace, dependency, optional, export, backends);
module.addImport(moduleImport);
}
}
}
}
}
module.setAvailable(true);
modules.getListOfModules().add(module);
Module languageModule = modules.getLanguageModule();
module.setLanguageModule(languageModule);
if (loadModuleImports) {
if (!ModelUtil.equalModules(module, languageModule)) {
boolean found = false;
for (ModuleImport mi : module.getImports()) {
if (mi.getModule().isLanguageModule()) {
found = true;
break;
}
}
if (!found) {
// It's not really a LazyModule because we're not loading
// it lazily. It's only here for module version analysis.
// But other stuff expects non-source modules to be lazy.
LazyModule oldLangMod = new LazyModule() {
@Override
protected AbstractModelLoader getModelLoader() {
return AbstractModelLoader.this;
}
};
oldLangMod.setLanguageModule(oldLangMod);
oldLangMod.setName(Arrays.asList("ceylon", "language"));
oldLangMod.setVersion(getJvmLanguageModuleVersion(major, minor));
oldLangMod.setNativeBackends(Backends.JAVA);
oldLangMod.setJvmMajor(major);
oldLangMod.setJvmMinor(minor);
ModuleImport moduleImport = new ModuleImport(null, oldLangMod, false, false);
module.addImport(moduleImport);
}
}
}
return true;
}
use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class AbstractModelLoader method loadPackageDescriptor.
private void loadPackageDescriptor(LazyPackage pkg) {
if (!pkg.getModule().isAvailable())
lazyLoadModule(pkg.getModule());
// Consider the descriptor loaded, we're not going to change our mind
pkg.setDescriptorLoaded(true);
// if we're bootstrapping
if (isBootstrap && pkg.getQualifiedNameString().startsWith(CEYLON_LANGUAGE)) {
return;
}
// let's not load package descriptors for Java modules
if (pkg.getModule() != null && ((LazyModule) pkg.getModule()).isJava()) {
pkg.setShared(((LazyModule) pkg.getModule()).isExportedJavaPackage(pkg.getNameAsString()));
return;
}
String quotedQualifiedName = JVMModuleUtil.quoteJavaKeywords(pkg.getQualifiedNameString());
// FIXME: not sure the toplevel package can have a package declaration
String className = quotedQualifiedName.isEmpty() ? NamingBase.PACKAGE_DESCRIPTOR_CLASS_NAME : quotedQualifiedName + "." + NamingBase.PACKAGE_DESCRIPTOR_CLASS_NAME;
logVerbose("[Trying to look up package from " + className + "]");
Module module = pkg.getModule();
if (module == null)
throw new RuntimeException("Assertion failed: module is null for package " + pkg.getNameAsString());
ClassMirror packageClass = loadClass(module, quotedQualifiedName, className);
if (packageClass == null) {
logVerbose("[Failed to complete " + className + "]");
// missing: leave it private
return;
}
// did we compile it from source or class?
if (packageClass.isLoadedFromSource()) {
// must have come from source, in which case we walked it and
// loaded its values already
logVerbose("[We are compiling the package " + className + "]");
return;
}
loadCompiledPackage(packageClass, pkg);
}
Aggregations