Search in sources :

Example 11 with Annotation

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);
    }
}
Also used : List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 12 with Annotation

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);
    }
}
Also used : List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 13 with Annotation

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");
        }
    }
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Function(org.eclipse.ceylon.model.typechecker.model.Function) Value(org.eclipse.ceylon.model.typechecker.model.Value) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 14 with Annotation

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();
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) ArrayList(java.util.ArrayList) JSONObject(net.minidev.json.JSONObject) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 15 with Annotation

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);
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation) Test(org.junit.Test)

Aggregations

Annotation (org.eclipse.ceylon.model.typechecker.model.Annotation)30 ArrayList (java.util.ArrayList)10 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)7 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)6 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)6 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)5 List (java.util.List)4 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)4 Package (org.eclipse.ceylon.model.typechecker.model.Package)4 Value (org.eclipse.ceylon.model.typechecker.model.Value)4 HashMap (java.util.HashMap)3 Class (org.eclipse.ceylon.model.typechecker.model.Class)3 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)3 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)3 Module (org.eclipse.ceylon.model.typechecker.model.Module)3 NothingType (org.eclipse.ceylon.model.typechecker.model.NothingType)3 Map (java.util.Map)2 AnalyzerUtil.getTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration)2 ExpressionVisitor.getRefinedMemberReference (org.eclipse.ceylon.compiler.typechecker.analyzer.ExpressionVisitor.getRefinedMemberReference)2 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)2