Search in sources :

Example 16 with Annotation

use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.

the class TreeUtil method buildAnnotations.

public static void buildAnnotations(Tree.AnnotationList al, List<Annotation> annotations) {
    if (al != null) {
        Tree.AnonymousAnnotation aa = al.getAnonymousAnnotation();
        if (aa != null) {
            Annotation ann = new Annotation();
            ann.setName("doc");
            Tree.StringLiteral lit = aa.getStringLiteral();
            if (lit != null) {
                String text = lit.getText();
                ann.addPositionalArgument(text);
                annotations.add(ann);
            }
        }
        for (Tree.Annotation a : al.getAnnotations()) {
            Annotation ann = new Annotation();
            Tree.BaseMemberExpression bma = (Tree.BaseMemberExpression) a.getPrimary();
            String name = bma.getIdentifier().getText();
            ann.setName(name);
            Tree.NamedArgumentList nal = a.getNamedArgumentList();
            if (nal != null) {
                for (Tree.NamedArgument na : nal.getNamedArguments()) {
                    if (na instanceof Tree.SpecifiedArgument) {
                        Tree.SpecifiedArgument sa = (Tree.SpecifiedArgument) na;
                        Tree.SpecifierExpression sie = sa.getSpecifierExpression();
                        Tree.Expression e = sie.getExpression();
                        if (e != null) {
                            Tree.Term t = e.getTerm();
                            Parameter p = sa.getParameter();
                            if (p != null) {
                                String text = toString(t);
                                if (text != null) {
                                    ann.addNamedArgument(p.getName(), text);
                                }
                            }
                        }
                    }
                }
            }
            Tree.PositionalArgumentList pal = a.getPositionalArgumentList();
            if (pal != null) {
                for (Tree.PositionalArgument pa : pal.getPositionalArguments()) {
                    if (pa instanceof Tree.ListedArgument) {
                        Tree.ListedArgument la = (Tree.ListedArgument) pa;
                        Tree.Term t = la.getExpression().getTerm();
                        String text = toString(t);
                        if (text != null) {
                            ann.addPositionalArgument(text);
                        }
                    }
                }
            }
            annotations.add(ann);
        }
    }
}
Also used : Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter)

Example 17 with Annotation

use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.

the class AbstractModelLoader method readModelAnnotation.

private Annotation readModelAnnotation(AnnotationMirror annotation) {
    Annotation modelAnnotation = new Annotation();
    modelAnnotation.setName((String) annotation.getValue());
    @SuppressWarnings("unchecked") List<String> arguments = (List<String>) annotation.getValue("arguments");
    if (arguments != null) {
        modelAnnotation.getPositionalArguments().addAll(arguments);
    } else {
        @SuppressWarnings("unchecked") List<AnnotationMirror> namedArguments = (List<AnnotationMirror>) annotation.getValue("namedArguments");
        if (namedArguments != null) {
            for (AnnotationMirror namedArgument : namedArguments) {
                String argName = (String) namedArgument.getValue("name");
                String argValue = (String) namedArgument.getValue("value");
                modelAnnotation.getNamedArguments().put(argName, argValue);
            }
        }
    }
    return modelAnnotation;
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 18 with Annotation

use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.

the class AbstractModelLoader method makeInteropAnnotationConstructor.

public AnnotationProxyMethod makeInteropAnnotationConstructor(LazyInterface iface, AnnotationProxyClass klass, OutputElement oe, Scope scope) {
    String ctorName = oe == null ? NamingBase.getJavaBeanName(iface.getName()) : NamingBase.getDisambigAnnoCtorName(iface, oe);
    AnnotationProxyMethod ctor = new AnnotationProxyMethod(this, klass, oe);
    ctor.setAnnotationTarget(oe);
    ctor.setContainer(scope);
    ctor.setScope(scope);
    if (!(scope instanceof Package)) {
        ctor.setStatic(true);
    }
    ctor.setAnnotation(true);
    ctor.setName(ctorName);
    ctor.setShared(iface.isShared());
    Annotation annotationAnnotation2 = new Annotation();
    annotationAnnotation2.setName("annotation");
    ctor.getAnnotations().add(annotationAnnotation2);
    ctor.setType(((TypeDeclaration) iface).getType());
    ctor.setUnit(iface.getUnit());
    return ctor;
}
Also used : AnnotationProxyMethod(org.eclipse.ceylon.model.loader.model.AnnotationProxyMethod) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 19 with Annotation

use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.

the class RefinementVisitor method refineAttribute.

private void refineAttribute(Value assignedAttribute, Tree.BaseMemberExpression bme, Tree.SpecifierStatement that, ClassOrInterface c) {
    if (!assignedAttribute.isFormal() && !assignedAttribute.isDefault() && !assignedAttribute.isShortcutRefinement()) {
        // this condition is here to squash a dupe message
        that.addError("inherited attribute may not be assigned in initializer and may not be refined: " + message(assignedAttribute) + " is declared neither 'formal' nor 'default'", 510);
    // return;
    } else if (assignedAttribute.isVariable()) {
        that.addError("inherited attribute may not be assigned in initializer and may not be refined by non-variable: " + message(assignedAttribute) + " is declared 'variable'");
    // return;
    }
    ClassOrInterface ci = (ClassOrInterface) assignedAttribute.getContainer();
    String name = assignedAttribute.getName();
    Declaration refined = ci.getRefinedMember(name, null, false);
    Value root = refined instanceof Value ? (Value) refined : assignedAttribute;
    Reference rv = getRefinedMemberReference(assignedAttribute, c);
    boolean lazy = that.getSpecifierExpression() instanceof Tree.LazySpecifierExpression;
    Value attribute = new Value();
    attribute.setName(name);
    attribute.setShared(true);
    attribute.setActual(true);
    attribute.getAnnotations().add(new Annotation("shared"));
    attribute.getAnnotations().add(new Annotation("actual"));
    attribute.setRefinedDeclaration(root);
    Unit unit = that.getUnit();
    attribute.setUnit(unit);
    attribute.setContainer(c);
    attribute.setScope(c);
    attribute.setShortcutRefinement(true);
    attribute.setTransient(lazy);
    Declaration rvd = rv.getDeclaration();
    if (rvd instanceof TypedDeclaration) {
        TypedDeclaration rvtd = (TypedDeclaration) rvd;
        attribute.setUncheckedNullType(rvtd.hasUncheckedNullType());
    }
    ModelUtil.setVisibleScope(attribute);
    c.addMember(attribute);
    that.setRefinement(true);
    that.setDeclaration(attribute);
    that.setRefined(assignedAttribute);
    unit.addDeclaration(attribute);
    setRefiningType(c, ci, name, null, false, root, attribute, unit, NO_SUBSTITUTIONS);
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) ExpressionVisitor.getRefinedMemberReference(org.eclipse.ceylon.compiler.typechecker.analyzer.ExpressionVisitor.getRefinedMemberReference) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 20 with Annotation

use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.

the class RefinementVisitor method refineMethod.

private void refineMethod(Function assignedMethod, Tree.BaseMemberExpression bme, Tree.SpecifierStatement that, ClassOrInterface c) {
    if (!assignedMethod.isFormal() && !assignedMethod.isDefault() && !assignedMethod.isShortcutRefinement()) {
        // this condition is here to squash a dupe message
        bme.addError("inherited method may not be refined: " + message(assignedMethod) + " is declared neither 'formal' nor 'default'", 510);
    // return;
    }
    ClassOrInterface ci = (ClassOrInterface) assignedMethod.getContainer();
    String name = assignedMethod.getName();
    List<Type> signature = getSignature(assignedMethod);
    boolean variadic = isVariadic(assignedMethod);
    Declaration refined = ci.getRefinedMember(name, signature, variadic);
    Function root = refined instanceof Function ? (Function) refined : assignedMethod;
    Reference rm = getRefinedMemberReference(assignedMethod, c);
    Function method = new Function();
    method.setName(name);
    List<Tree.ParameterList> paramLists;
    List<TypeParameter> typeParams;
    Tree.Term me = that.getBaseMemberExpression();
    if (me instanceof Tree.ParameterizedExpression) {
        Tree.ParameterizedExpression pe = (Tree.ParameterizedExpression) me;
        paramLists = pe.getParameterLists();
        Tree.TypeParameterList typeParameterList = pe.getTypeParameterList();
        if (typeParameterList != null) {
            typeParams = new ArrayList<TypeParameter>();
            for (Tree.TypeParameterDeclaration tpd : typeParameterList.getTypeParameterDeclarations()) {
                typeParams.add(tpd.getDeclarationModel());
            }
        } else {
            typeParams = null;
        }
    } else {
        paramLists = emptyList();
        typeParams = null;
    }
    Unit unit = that.getUnit();
    final Map<TypeParameter, Type> subs;
    if (typeParams != null) {
        // the type parameters are written
        // down in the shortcut refinement
        method.setTypeParameters(typeParams);
        // TODO: check 'em!!
        // no need to check them because
        // this case is actually disallowed
        // elsewhere (specification statements
        // may not have type parameters)
        subs = NO_SUBSTITUTIONS;
    } else if (assignedMethod.isParameterized()) {
        if (me instanceof Tree.ParameterizedExpression) {
            // we have parameters, but no type parameters
            bme.addError("refined method is generic: '" + assignedMethod.getName(unit) + "' declares type parameters");
            subs = NO_SUBSTITUTIONS;
        } else {
            // we're assigning a method reference
            // so we need to magic up some "fake"
            // type parameters
            subs = copyTypeParametersFromRefined(assignedMethod, method, unit);
        }
    } else {
        subs = NO_SUBSTITUTIONS;
    }
    int i = 0;
    for (ParameterList pl : assignedMethod.getParameterLists()) {
        Tree.ParameterList params = paramLists.size() <= i ? null : paramLists.get(i++);
        createRefiningParameterList(rm, method, params, unit, subs, pl);
    }
    method.setShared(true);
    method.setActual(true);
    method.getAnnotations().add(new Annotation("shared"));
    method.getAnnotations().add(new Annotation("actual"));
    method.setRefinedDeclaration(root);
    method.setUnit(unit);
    method.setContainer(c);
    method.setScope(c);
    method.setShortcutRefinement(true);
    method.setDeclaredVoid(assignedMethod.isDeclaredVoid());
    Declaration rmd = rm.getDeclaration();
    if (rmd instanceof TypedDeclaration) {
        TypedDeclaration rmtd = (TypedDeclaration) rmd;
        method.setUncheckedNullType(rmtd.hasUncheckedNullType());
    }
    ModelUtil.setVisibleScope(method);
    c.addMember(method);
    that.setRefinement(true);
    that.setDeclaration(method);
    that.setRefined(root);
    unit.addDeclaration(method);
    Scope scope = that.getScope();
    if (scope instanceof Specification) {
        Specification spec = (Specification) scope;
        spec.setDeclaration(method);
    }
    setRefiningType(c, ci, name, signature, variadic, root, method, unit, subs);
    inheritDefaultedArguments(method);
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) Function(org.eclipse.ceylon.model.typechecker.model.Function) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) ExpressionVisitor.getRefinedMemberReference(org.eclipse.ceylon.compiler.typechecker.analyzer.ExpressionVisitor.getRefinedMemberReference) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) Specification(org.eclipse.ceylon.model.typechecker.model.Specification) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.erasedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.erasedType) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ModelUtil.getRealScope(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList)

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