use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class JsonPackage method setOldAnnotations.
static void setOldAnnotations(List<Annotation> existing, Map<String, List<String>> m) {
for (Map.Entry<String, List<String>> e : m.entrySet()) {
String name = e.getKey();
Annotation ann = new Annotation();
ann.setName(name);
for (String arg : e.getValue()) {
ann.addPositionalArgument(arg);
}
existing.add(ann);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class JsonPackage method setNewAnnotations.
static void setNewAnnotations(List<Annotation> existing, List<Map<String, List<String>>> anns) {
for (Map<String, List<String>> a : anns) {
String name = a.keySet().iterator().next();
Annotation ann = new Annotation();
ann.setName(name);
for (String arg : a.get(name)) {
ann.addPositionalArgument(arg);
}
existing.add(ann);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class MetamodelVisitor method visit.
@Override
public void visit(Tree.SpecifierStatement st) {
TypedDeclaration d = ((Tree.SpecifierStatement) st).getDeclaration();
// Just add shared and actual annotations to this declaration
if (!isNativeHeader(d))
return;
if (d != null) {
Annotation ann = new Annotation();
ann.setName("shared");
d.getAnnotations().add(ann);
ann = new Annotation();
ann.setName("actual");
d.getAnnotations().add(ann);
if (d instanceof Function) {
gen.encodeMethod((Function) d);
} else if (d instanceof Value) {
gen.encodeAttributeOrGetter((Value) d);
} else {
throw new RuntimeException("JS compiler doesn't know how to encode " + d.getClass().getName() + " into model");
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class NpmDescriptorGenerator method generateDescriptor.
public String generateDescriptor() throws IOException {
Map<String, Object> desc = new HashMap<>();
desc.put("name", name(mod));
desc.put("version", mod.getVersion());
for (Annotation ann : mod.getAnnotations()) {
List<String> args = ann.getPositionalArguments();
if ("doc".equals(ann.getName())) {
desc.put("description", args.get(0));
} else if ("license".equals(ann.getName())) {
desc.put("license", args.get(0));
} else if ("by".equals(ann.getName()) && !args.isEmpty()) {
desc.put("author", args.get(0));
desc.put("contributors", args);
}
}
if (!mod.getImports().isEmpty()) {
Map<String, String> deps = new HashMap<>(mod.getImports().size());
Map<String, String> opts = new HashMap<>(mod.getImports().size());
for (ModuleImport imp : mod.getImports()) {
if (imp.isOptional()) {
opts.put(name(imp.getModule()), imp.getModule().getVersion());
} else if (!imp.isNative() || imp.getNativeBackends().supports(Backend.JavaScript)) {
deps.put(name(imp.getModule()), imp.getModule().getVersion());
}
}
if (!deps.isEmpty()) {
desc.put("dependencies", deps);
}
if (!opts.isEmpty()) {
desc.put("optionalDependencies", opts);
}
}
List<String> files = new ArrayList<>((src ? 6 : 4) + (resources ? 1 : 0));
final String modName = mod.getNameAsString() + "-" + mod.getVersion();
files.add(modName + ArtifactContext.JS);
files.add(modName + ArtifactContext.JS + ArtifactContext.SHA1);
files.add(modName + ArtifactContext.JS_MODEL);
files.add(modName + ArtifactContext.JS_MODEL + ArtifactContext.SHA1);
if (src) {
files.add(modName + ArtifactContext.SRC);
files.add(modName + ArtifactContext.SRC + ArtifactContext.SHA1);
}
if (resources) {
files.add(ArtifactContext.RESOURCES);
}
desc.put("files", files);
desc.put("main", files.get(0));
StringWriter sw = new StringWriter();
JSONObject.writeJSON(desc, sw);
return sw.toString();
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class TestBitAnnotations method testEncode.
@Test
public void testEncode() {
final Value v = new Value();
int b = MetamodelGenerator.encodeAnnotations(v.getAnnotations(), v, null);
Assert.assertEquals(0, b);
v.getAnnotations().add(new Annotation("shared"));
b = MetamodelGenerator.encodeAnnotations(v.getAnnotations(), v, null);
Assert.assertEquals(1, b);
v.getAnnotations().add(new Annotation("actual"));
b = MetamodelGenerator.encodeAnnotations(v.getAnnotations(), v, null);
Assert.assertEquals(3, b);
v.getAnnotations().add(new Annotation("default"));
b = MetamodelGenerator.encodeAnnotations(v.getAnnotations(), v, null);
Assert.assertEquals(11, b);
}
Aggregations