use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class LazyModuleManager method addImplicitImports.
@Override
public void addImplicitImports() {
Module languageModule = modules.getLanguageModule();
for (Module m : modules.getListOfModules()) {
// Java modules don't depend on ceylon.language
if ((m instanceof LazyModule == false || !((LazyModule) m).isJava()) && !m.equals(languageModule)) {
// add ceylon.language if required
ModuleImport moduleImport = findImport(m, languageModule);
if (moduleImport == null) {
moduleImport = new ModuleImport(null, languageModule, false, true);
m.addImport(moduleImport);
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class AbstractTransformer method makeAtModule.
List<JCAnnotation> makeAtModule(ModuleDescriptor moduleDescriptor) {
Module module = moduleDescriptor.getUnit().getPackage().getModule();
ListBuffer<JCExpression> imports = new ListBuffer<JCTree.JCExpression>();
for (ModuleImport dependency : module.getImports()) {
if (!isForBackend(dependency.getNativeBackends(), Backend.Java)) {
continue;
}
Module dependencyModule = dependency.getModule();
JCExpression dependencyName = make().Assign(naming.makeUnquotedIdent("name"), make().Literal(dependencyModule.getNameAsString()));
JCExpression dependencyVersion = null;
String versionInDescriptor = getImportVersionFromDescriptor(moduleDescriptor, dependency, dependencyModule);
if (versionInDescriptor != null)
dependencyVersion = make().Assign(naming.makeUnquotedIdent("version"), make().Literal(versionInDescriptor));
List<JCExpression> spec;
if (dependencyVersion != null)
spec = List.<JCExpression>of(dependencyName, dependencyVersion);
else
spec = List.<JCExpression>of(dependencyName);
if (dependency.getNamespace() != null && !DefaultRepository.NAMESPACE.equals(dependency.getNamespace())) {
JCExpression dependencyNamespace = make().Assign(naming.makeUnquotedIdent("namespace"), make().Literal(dependency.getNamespace()));
spec = spec.append(dependencyNamespace);
}
if (Util.getAnnotation(dependency, "shared") != null) {
JCExpression exported = make().Assign(naming.makeUnquotedIdent("export"), make().Literal(true));
spec = spec.append(exported);
}
if (Util.getAnnotation(dependency, "optional") != null) {
JCExpression exported = make().Assign(naming.makeUnquotedIdent("optional"), make().Literal(true));
spec = spec.append(exported);
}
JCExpression nativeBackendsAnnotationValue = makeNativeBackendsAnnotationValue(dependency.getNativeBackends());
if (nativeBackendsAnnotationValue != null)
spec = spec.append(nativeBackendsAnnotationValue);
JCAnnotation atImport = make().Annotation(makeIdent(syms().ceylonAtImportType), spec);
imports.add(atImport);
}
ListBuffer<JCExpression> annotationArgs = getLicenseAuthorsDocAnnotationArguments(module.getNameAsString(), module.getAnnotations());
annotationArgs.add(make().Assign(naming.makeUnquotedIdent("version"), make().Literal(module.getVersion())));
// annotationArgs.add(make().Assign(naming.makeUnquotedIdent("label"), make().Literal(module.getLabel())));
annotationArgs.add(make().Assign(naming.makeUnquotedIdent("dependencies"), make().NewArray(null, null, imports.toList())));
JCExpression nativeBackendsAnnotationValue = makeNativeBackendsAnnotationValue(module.getNativeBackends());
if (nativeBackendsAnnotationValue != null)
annotationArgs.add(nativeBackendsAnnotationValue);
if (module.getGroupId() != null)
annotationArgs.add(make().Assign(naming.makeUnquotedIdent("group"), make().Literal(module.getGroupId())));
if (module.getArtifactId() != null)
annotationArgs.add(make().Assign(naming.makeUnquotedIdent("artifact"), make().Literal(module.getArtifactId())));
return makeModelAnnotation(syms().ceylonAtModuleType, annotationArgs.toList());
}
use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class ModuleDoc method writeDependencies.
private void writeDependencies() throws IOException {
List<ModuleImport> moduleImports = new ArrayList<ModuleImport>(module.getImports());
Iterator<ModuleImport> moduleImportIterator = moduleImports.listIterator();
while (moduleImportIterator.hasNext()) {
ModuleImport moduleImport = moduleImportIterator.next();
if (moduleImport.getModule().getNameAsString().equals(AbstractModelLoader.CEYLON_LANGUAGE)) {
moduleImportIterator.remove();
}
}
Collections.sort(moduleImports, ModuleImportComparatorByName.INSTANCE);
if (!moduleImports.isEmpty()) {
openTable("section-dependencies", "Dependencies", 3, false);
for (ModuleImport moduleImport : moduleImports) {
writeDependencyRow(moduleImport);
}
closeTable();
}
}
use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class ModuleManager method overridesModule.
public Module overridesModule(ArtifactResult artifact, Module module, ModuleImport moduleImport) {
String namespace = artifact.namespace();
String realName = artifact.name();
String realVersion = artifact.version();
if (!realName.equals(module.getNameAsString()) || !realVersion.equals(module.getVersion())) {
if (module != module.getLanguageModule()) {
Module realModule = getOrCreateModule(splitModuleName(realName), realVersion);
moduleImport.override(new ModuleImport(namespace, realModule, moduleImport.isOptional(), moduleImport.isExport()));
return realModule;
}
}
return null;
}
use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class ModuleManager method initCoreModules.
public void initCoreModules(Modules initialModules) {
modules = initialModules;
if (modules.getLanguageModule() == null) {
// build empty package
Package emptyPackage = createPackage("", null);
// build default module
// (module in which packages belong to when not explicitly under a module)
List<String> defaultModuleName = singletonList(DEFAULT_MODULE_NAME);
Module defaultModule = createModule(defaultModuleName, "unversioned");
// defaultModule.setDefault(true);
defaultModule.setAvailable(true);
bindPackageToModule(emptyPackage, defaultModule);
modules.getListOfModules().add(defaultModule);
modules.setDefaultModule(defaultModule);
// create language module and add it as a dependency of defaultModule
// since packages outside a module cannot declare dependencies
List<String> languageName = asList("ceylon", "language");
Module languageModule = createModule(languageName, CEYLON_VERSION_NUMBER);
languageModule.setLanguageModule(languageModule);
// not available yet
languageModule.setAvailable(false);
modules.setLanguageModule(languageModule);
modules.getListOfModules().add(languageModule);
defaultModule.addImport(new ModuleImport(null, languageModule, false, false));
defaultModule.setLanguageModule(languageModule);
}
}
Aggregations