use of org.eclipse.ceylon.common.Backends in project ceylon by eclipse.
the class DeclarationVisitor method handleNativeAnnotation.
private void handleNativeAnnotation(Tree.Declaration that, Declaration model, Tree.AnnotationList al) {
Tree.Annotation na = getAnnotation(al, "native", unit);
Backends backends = Backends.ANY;
if (na != null) {
int cnt = getAnnotationArgumentCount(na);
if (cnt == 0) {
backends = Backends.HEADER;
} else {
for (int i = 0; i < cnt; i++) {
String be = getAnnotationArgument(na, i, unit);
Backend backend = Backend.fromAnnotation(be);
if (backend != null) {
if (!backend.isRegistered()) {
na.addError("illegal native backend name: '\"" + backend.nativeAnnotation + "\"' (must be either '\"jvm\"' or '\"js\"')");
}
backends = backends.merged(backend);
}
}
}
}
model.setNativeBackends(backends);
if (model.isNative() && model.isFormal()) {
that.addError("declaration may not be annotated both 'formal' and 'native'");
}
}
use of org.eclipse.ceylon.common.Backends in project ceylon by eclipse.
the class ModuleSourceMapper method overrideModuleImports.
protected void overrideModuleImports(Module module, ArtifactResult artifact) {
Overrides overrides = getContext().getRepositoryManager().getOverrides();
if (overrides != null) {
Set<ModuleDependencyInfo> existingModuleDependencies = new HashSet<>();
for (ModuleImport i : module.getImports()) {
Module m = i.getModule();
if (m != null) {
existingModuleDependencies.add(new ModuleDependencyInfo(i.getNamespace(), m.getNameAsString(), m.getVersion(), i.isOptional(), i.isExport(), i.getNativeBackends()));
}
}
ModuleInfo sourceModuleInfo = new ModuleInfo(artifact.namespace(), artifact.name(), artifact.version(), artifact.groupId(), artifact.artifactId(), artifact.classifier(), null, existingModuleDependencies);
ModuleInfo newModuleInfo = overrides.applyOverrides(artifact.name(), artifact.version(), sourceModuleInfo);
List<ModuleImport> newModuleImports = new ArrayList<>();
for (ModuleDependencyInfo dep : newModuleInfo.getDependencies()) {
Module dependency = getModuleManager().getOrCreateModule(ModuleManager.splitModuleName(dep.getName()), dep.getVersion());
Backends backends = dependency.getNativeBackends();
ModuleImport newImport = new ModuleImport(dep.getNamespace(), dependency, dep.isOptional(), dep.isExport(), backends);
newModuleImports.add(newImport);
}
module.overrideImports(newModuleImports);
}
}
use of org.eclipse.ceylon.common.Backends in project ceylon by eclipse.
the class TypeVisitor method handleNativeHeader.
private Declaration handleNativeHeader(Declaration hdr, Node that) {
if (hdr.isNativeHeader()) {
Scope scope = that.getScope();
if (scope == hdr) {
scope = scope.getScope();
}
Backends inBackends = scope.getScopedBackends();
Backends backends = inBackends.none() ? unit.getSupportedBackends() : inBackends;
Declaration impl = getNativeDeclaration(hdr, backends);
return inBackends == null || impl == null ? hdr : impl;
}
return hdr;
}
use of org.eclipse.ceylon.common.Backends 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.common.Backends in project ceylon by eclipse.
the class AbstractModelLoader method manageNativeBackend.
private void manageNativeBackend(Annotated annotated, AnnotatedMirror mirror, boolean isNativeHeader) {
if (mirror == null)
return;
// Set "native" annotation
@SuppressWarnings("unchecked") List<String> nativeBackends = (List<String>) getAnnotationValue(mirror, CEYLON_LANGUAGE_NATIVE_ANNOTATION, "backends");
if (nativeBackends != null) {
Backends backends = Backends.fromAnnotations(nativeBackends);
if (isNativeHeader) {
backends = Backends.HEADER;
} else if (backends.header()) {
// Elements in the class file marked `native("")` are actually
// default implementations taken from the header that were
// copied to the output, so here we reset them to `native("jvm")`
backends = Backends.JAVA;
}
if (annotated instanceof Declaration) {
Declaration decl = (Declaration) annotated;
decl.setNativeBackends(backends);
if (isNativeHeader) {
List<Declaration> al = new ArrayList<Declaration>(1);
setOverloads(decl, al);
}
} else if (annotated instanceof Module) {
((Module) annotated).setNativeBackends(backends);
}
} else {
// Mark native Classes and Interfaces as well, but don't deal with overloads and such
if (annotated instanceof LazyClass && !((LazyClass) annotated).isCeylon() || annotated instanceof LazyInterface && !((LazyInterface) annotated).isCeylon()) {
((Declaration) annotated).setNativeBackends(Backend.Java.asSet());
}
}
}
Aggregations