use of org.eclipse.ceylon.common.Backend in project ceylon by eclipse.
the class Pattern method getModules.
public Set<Module> getModules() {
LinkedHashSet<Module> result = new LinkedHashSet<Module>();
if (match != null) {
Backend be = null;
if (backend != null) {
be = Backend.fromAnnotation(backend);
if (be == null) {
throw new RuntimeException("Unknown backend for pattern: " + backend);
}
}
Collection<String> mods = ModuleWildcardsHelper.expandWildcards(getSrc(), Collections.singletonList(match), be);
for (String mod : mods) {
result.add(new Module(mod));
}
}
return result;
}
use of org.eclipse.ceylon.common.Backend in project ceylon by eclipse.
the class ModuleVisitor method visit.
@Override
public void visit(Tree.ImportModule that) {
super.visit(that);
String version = getVersionString(that.getVersion(), that.getConstantVersion(), that);
if (that.getVersion() == null && version != null) {
that.setVersion(new Tree.QuotedLiteral(new CommonToken(STRING_LITERAL, "\"" + version + "\"")));
}
List<String> name;
Node node;
Tree.ImportPath importPath = that.getImportPath();
Tree.QuotedLiteral quotedLiteral = that.getQuotedLiteral();
if (importPath != null) {
name = getNameAsList(importPath);
node = importPath;
} else if (quotedLiteral != null) {
String nameString = getNameString(quotedLiteral);
name = asList(nameString.split("\\."));
node = quotedLiteral;
} else {
name = Collections.emptyList();
node = null;
}
if (node != null) {
Tree.QuotedLiteral artifact = that.getArtifact();
if (artifact != null) {
name = new ArrayList<String>(name);
String nameString = getNameString(artifact);
name.add("");
name.addAll(asList(nameString.split("\\.")));
}
Tree.QuotedLiteral classifier = that.getClassifier();
if (classifier != null) {
String nameString = getNameString(classifier);
name.add("");
name.addAll(asList(nameString.split("\\.")));
}
}
if (phase == Phase.SRC_MODULE) {
String path = formatPath(name);
that.setName(path);
} else if (phase == Phase.REMAINING) {
// set in previous phase
String path = that.getName();
Tree.Identifier ns = that.getNamespace();
String namespace = ns != null ? ns.getText() : null;
boolean hasMavenName = isMavenModule(path);
boolean forCeylon = (importPath != null && namespace == null) || (importPath == null && namespace == null && !hasMavenName) || DefaultRepository.NAMESPACE.equals(namespace);
if (name.isEmpty()) {
that.addError("missing module name");
} else if (name.get(0).equals(DEFAULT_MODULE_NAME)) {
if (forCeylon) {
node.addError("reserved module name: 'default'");
}
} else if (name.size() == 1 && name.get(0).equals("ceylon")) {
if (forCeylon) {
node.addError("reserved module name: 'ceylon'");
}
} else if (name.size() > 1 && name.get(0).equals("ceylon") && name.get(1).equals("language")) {
if (forCeylon) {
node.addError("the language module is imported implicitly");
}
} else {
if (namespace == null && hasMavenName) {
namespace = MavenRepository.NAMESPACE;
node.addUsageWarning(Warning.missingImportPrefix, "use of old style Maven imports is deprecated, prefix with 'maven:'");
}
Tree.AnnotationList al = that.getAnnotationList();
Unit u = unit.getUnit();
Backends bs = getNativeBackend(al, u);
if (!bs.none()) {
for (Backend b : bs) {
if (!b.isRegistered()) {
node.addError("illegal native backend name: '\"" + b.nativeAnnotation + "\"' (must be either '\"jvm\"' or '\"js\"')");
}
}
if (!moduleBackends.none() && !moduleBackends.supports(bs)) {
node.addError("native backend name on import conflicts with module descriptor: '\"" + bs.names() + "\"' is not in '\"" + moduleBackends.names() + "\"'");
}
}
Module importedModule = moduleManager.getOrCreateModule(name, version);
if (importPath != null) {
importPath.setModel(importedModule);
}
if (!completeOnlyAST && mainModule != null) {
if (importedModule.getVersion() == null) {
importedModule.setVersion(version);
}
ModuleImport moduleImport = moduleManager.findImport(mainModule, importedModule);
if (moduleImport == null) {
boolean optional = hasAnnotation(al, "optional", u);
boolean export = hasAnnotation(al, "shared", u);
moduleImport = new ModuleImport(namespace, importedModule, optional, export, bs);
moduleImport.getAnnotations().clear();
buildAnnotations(al, moduleImport.getAnnotations());
mainModule.addImport(moduleImport);
}
moduleManagerUtil.addModuleDependencyDefinition(moduleImport, that);
}
}
}
}
use of org.eclipse.ceylon.common.Backend in project ceylon by eclipse.
the class DeclarationVisitor method handleNativeHeader.
private void handleNativeHeader(Declaration model, String name) {
// Deal with implementations from the ModelLoader
ArrayList<FunctionOrValue> loadedFunctionsOrValues = null;
ArrayList<ClassOrInterface> loadedClasses = null;
ArrayList<Constructor> loadedConstructors = null;
for (Backend backendToSearch : Backend.getRegisteredBackends()) {
Declaration overloadFromModelLoader = model.getContainer().getDirectMemberForBackend(name, backendToSearch.asSet());
if (overloadFromModelLoader instanceof FunctionOrValue) {
if (loadedFunctionsOrValues == null) {
loadedFunctionsOrValues = new ArrayList<FunctionOrValue>();
}
FunctionOrValue fov = (FunctionOrValue) overloadFromModelLoader;
loadedFunctionsOrValues.add(fov);
} else if (overloadFromModelLoader instanceof ClassOrInterface) {
if (loadedClasses == null) {
loadedClasses = new ArrayList<ClassOrInterface>();
}
ClassOrInterface c = (ClassOrInterface) overloadFromModelLoader;
loadedClasses.add(c);
} else if (overloadFromModelLoader instanceof Constructor) {
if (loadedConstructors == null) {
loadedConstructors = new ArrayList<Constructor>();
}
Constructor c = (Constructor) overloadFromModelLoader;
loadedConstructors.add(c);
}
}
// Initialize the header's overloads
if (model instanceof FunctionOrValue) {
FunctionOrValue m = (FunctionOrValue) model;
if (loadedFunctionsOrValues != null) {
m.initOverloads(loadedFunctionsOrValues.toArray(NO_FUNCTIONS_OR_VALUES));
} else {
m.initOverloads();
}
} else if (model instanceof ClassOrInterface) {
ClassOrInterface c = (ClassOrInterface) model;
if (loadedClasses != null) {
c.initOverloads(loadedClasses.toArray(NO_CLASSES));
} else {
c.initOverloads();
}
} else if (model instanceof Constructor) {
Constructor c = (Constructor) model;
if (loadedConstructors != null) {
c.initOverloads(loadedConstructors.toArray(NO_CONSTRUCTORS));
} else {
c.initOverloads();
}
}
}
use of org.eclipse.ceylon.common.Backend 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.Backend in project ceylon by eclipse.
the class ModuleDoc method writePlatform.
private void writePlatform(Module module) throws IOException {
if (module.isNative()) {
List<String> backendNames = new ArrayList<String>();
for (Backend backend : module.getNativeBackends()) {
backendNames.add(backend.name);
}
open("div class='platform section'");
around("span class='title'", "Platform: ");
around("span class='value'", Util.join(", ", backendNames));
close("div");
}
}
Aggregations