Search in sources :

Example 1 with Function

use of com.redhat.ceylon.model.typechecker.model.Function in project ceylon-compiler by ceylon.

the class ClassOrPackageDoc method writeParameters.

protected final void writeParameters(Declaration decl) throws IOException {
    if (decl instanceof Functional) {
        Map<Parameter, Map<Tree.Assertion, List<Tree.Condition>>> parametersAssertions = getParametersAssertions(decl);
        boolean first = true;
        List<ParameterList> parameterLists = ((Functional) decl).getParameterLists();
        for (ParameterList parameterList : parameterLists) {
            for (Parameter parameter : parameterList.getParameters()) {
                ParameterDocData parameterDocData = getParameterDocData(parameter, parametersAssertions);
                if (!parameterDocData.isEmpty()) {
                    if (first) {
                        first = false;
                        open("div class='parameters section'");
                        around("span class='title'", "Parameters: ");
                        open("ul");
                    }
                    open("li");
                    open("code");
                    around("span class='parameter' id='" + decl.getName() + "-" + parameter.getName() + "'", parameter.getName());
                    // if parameter is function, we need to produce links to its parameters
                    if (parameter.getModel() instanceof Function) {
                        writeParameterLinksIfRequired((Function) parameter.getModel(), false, decl.getName() + "-");
                    }
                    if (!isEmpty(parameterDocData.defaultValue)) {
                        around("span class='parameter-default-value' title='Parameter default value'", " = " + parameterDocData.defaultValue);
                    }
                    close("code");
                    if (!isEmpty(parameterDocData.doc)) {
                        around("div class='doc section'", parameterDocData.doc);
                    }
                    writeParameterAssertions(decl, parameterDocData.parameterAssertions);
                    close("li");
                }
            }
        }
        if (!first) {
            close("ul");
            close("div");
        }
    }
}
Also used : Functional(com.redhat.ceylon.model.typechecker.model.Functional) Function(com.redhat.ceylon.model.typechecker.model.Function) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with Function

use of com.redhat.ceylon.model.typechecker.model.Function in project ceylon-compiler by ceylon.

the class CeylonDocTool method collectAnnotationConstructors.

private void collectAnnotationConstructors() {
    for (Module module : modules) {
        for (Package pkg : getPackages(module)) {
            for (Declaration decl : pkg.getMembers()) {
                if (decl instanceof Function && decl.isAnnotation() && shouldInclude(decl)) {
                    Function annotationCtor = (Function) decl;
                    TypeDeclaration annotationType = annotationCtor.getTypeDeclaration();
                    List<Function> annotationConstructorList = annotationConstructors.get(annotationType);
                    if (annotationConstructorList == null) {
                        annotationConstructorList = new ArrayList<Function>();
                        annotationConstructors.put(annotationType, annotationConstructorList);
                    }
                    annotationConstructorList.add(annotationCtor);
                }
            }
        }
    }
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) Package(com.redhat.ceylon.model.typechecker.model.Package) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Module(com.redhat.ceylon.model.typechecker.model.Module) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 3 with Function

use of com.redhat.ceylon.model.typechecker.model.Function in project ceylon-compiler by ceylon.

the class ClassDoc method loadMembers.

private void loadMembers() {
    constructors = new TreeMap<String, Declaration>();
    methods = new TreeMap<String, Function>();
    attributes = new TreeMap<String, TypedDeclaration>();
    innerInterfaces = new TreeMap<String, Interface>();
    innerClasses = new TreeMap<String, Class>();
    innerExceptions = new TreeMap<String, Class>();
    innerAliases = new TreeMap<String, TypeAlias>();
    superClasses = getAncestors(klass);
    superInterfaces = getSuperInterfaces(klass);
    for (Declaration m : klass.getMembers()) {
        if (tool.shouldInclude(m)) {
            if (ModelUtil.isConstructor(m)) {
                addTo(constructors, m);
            } else if (m instanceof Value) {
                addTo(attributes, (Value) m);
            } else if (m instanceof Function) {
                addTo(methods, (Function) m);
            } else if (m instanceof Interface) {
                addTo(innerInterfaces, (Interface) m);
            } else if (m instanceof Class) {
                Class c = (Class) m;
                if (Util.isThrowable(c)) {
                    addTo(innerExceptions, c);
                } else {
                    addTo(innerClasses, c);
                }
            } else if (m instanceof TypeAlias) {
                addTo(innerAliases, (TypeAlias) m);
            }
        }
    }
    Collections.sort(superInterfaces, ReferenceableComparatorByName.INSTANCE);
    loadInheritedMembers(attributeSpecification, superClasses, superclassInheritedMembers);
    loadInheritedMembers(methodSpecification, superClasses, superclassInheritedMembers);
    loadInheritedMembers(attributeSpecification, superInterfaces, interfaceInheritedMembers);
    loadInheritedMembers(methodSpecification, superInterfaces, interfaceInheritedMembers);
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) TypeAlias(com.redhat.ceylon.model.typechecker.model.TypeAlias) Function(com.redhat.ceylon.model.typechecker.model.Function) Value(com.redhat.ceylon.model.typechecker.model.Value) Class(com.redhat.ceylon.model.typechecker.model.Class) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface)

Example 4 with Function

use of com.redhat.ceylon.model.typechecker.model.Function in project ceylon-compiler by ceylon.

the class AbstractTransformer method getTypedReference.

TypedReference getTypedReference(TypedDeclaration decl) {
    java.util.List<Type> typeArgs = Collections.<Type>emptyList();
    if (decl instanceof Function) {
        // For methods create type arguments for any type parameters it might have
        Function m = (Function) decl;
        if (!m.getTypeParameters().isEmpty()) {
            typeArgs = new ArrayList<Type>(m.getTypeParameters().size());
            for (TypeParameter p : m.getTypeParameters()) {
                Type pt = p.getType();
                typeArgs.add(pt);
            }
        }
    }
    if (decl.getContainer() instanceof TypeDeclaration) {
        TypeDeclaration containerDecl = (TypeDeclaration) decl.getContainer();
        return containerDecl.getType().getTypedMember(decl, typeArgs);
    }
    return decl.appliedTypedReference(null, typeArgs);
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) Type(com.redhat.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 5 with Function

use of com.redhat.ceylon.model.typechecker.model.Function in project ceylon-compiler by ceylon.

the class AnnotationModelVisitor method visit.

@Override
public void visit(Tree.BaseMemberExpression bme) {
    if (annotationConstructor != null) {
        Declaration declaration = bme.getDeclaration();
        if (checkingInvocationPrimary && isAnnotationConstructor(bme.getDeclaration())) {
            Function ctor = (Function) bme.getDeclaration();
            instantiation.setPrimary(ctor);
            if (ctor.getAnnotationConstructor() != null) {
                instantiation.getConstructorParameters().addAll(((AnnotationInvocation) ctor.getAnnotationConstructor()).getConstructorParameters());
            }
        } else if (checkingArguments || checkingDefaults) {
            if (declaration instanceof Value && ((Value) declaration).isParameter()) {
                Value constructorParameter = (Value) declaration;
                ParameterAnnotationTerm a = new ParameterAnnotationTerm();
                a.setSpread(spread);
                // XXX Is this right?
                a.setSourceParameter(constructorParameter.getInitializerParameter());
                this.term = a;
            } else if (isBooleanTrue(declaration)) {
                LiteralAnnotationTerm argument = new BooleanLiteralAnnotationTerm(true);
                appendLiteralArgument(bme, argument);
            } else if (isBooleanFalse(declaration)) {
                LiteralAnnotationTerm argument = new BooleanLiteralAnnotationTerm(false);
                appendLiteralArgument(bme, argument);
            } else if (bme.getUnit().isEmptyType(bme.getTypeModel()) && bme.getUnit().isIterableType(bme.getTypeModel()) && elements == null) {
                // If we're dealing with an iterable, empty means empty collection, not object
                endCollection(startCollection(bme), bme);
            } else if (Decl.isAnonCaseOfEnumeratedType(bme)) {
                LiteralAnnotationTerm argument = new ObjectLiteralAnnotationTerm(bme.getTypeModel());
                appendLiteralArgument(bme, argument);
            } else {
                bme.addError("compiler bug: unsupported base member expression in annotation constructor", Backend.Java);
            }
        } else {
            bme.addError("compiler bug: unsupported base member expression in annotation constructor", Backend.Java);
        }
    }
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) Value(com.redhat.ceylon.model.typechecker.model.Value) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Aggregations

Function (com.redhat.ceylon.model.typechecker.model.Function)74 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)35 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)35 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)33 Type (com.redhat.ceylon.model.typechecker.model.Type)33 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)26 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)26 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)25 Value (com.redhat.ceylon.model.typechecker.model.Value)25 Class (com.redhat.ceylon.model.typechecker.model.Class)23 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)22 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)20 JCTree (com.sun.tools.javac.tree.JCTree)18 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)17 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)17 ArrayList (java.util.ArrayList)14 ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)13 ModelUtil.appliedType (com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)12 MethodDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)11 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)11