Search in sources :

Example 1 with Node

use of com.redhat.ceylon.compiler.typechecker.tree.Node in project ceylon-compiler by ceylon.

the class ClassOrPackageDoc method getParametersAssertions.

private Map<Parameter, Map<Tree.Assertion, List<Tree.Condition>>> getParametersAssertions(final Declaration decl) {
    final Map<Parameter, Map<Tree.Assertion, List<Tree.Condition>>> parametersAssertions = new LinkedHashMap<Parameter, Map<Tree.Assertion, List<Tree.Condition>>>();
    if (((Functional) decl).getParameterLists().isEmpty()) {
        return parametersAssertions;
    }
    Node node = tool.getNode(decl);
    PhasedUnit pu = tool.getUnit(decl);
    if (node == null || pu == null) {
        return parametersAssertions;
    }
    Tree.Body body = null;
    if (node instanceof Tree.MethodDefinition) {
        body = ((Tree.MethodDefinition) node).getBlock();
    } else if (node instanceof Tree.ClassDefinition) {
        body = ((Tree.ClassDefinition) node).getClassBody();
    }
    if (body == null) {
        return parametersAssertions;
    }
    final Map<String, Parameter> parametersNames = new HashMap<String, Parameter>();
    for (ParameterList parameterList : ((Functional) decl).getParameterLists()) {
        for (Parameter parameter : parameterList.getParameters()) {
            parametersNames.put(parameter.getName(), parameter);
        }
    }
    body.visitChildren(new Visitor() {

        private boolean stop = false;

        private Tree.Assertion assertion = null;

        private Set<Parameter> referencedParameters = new HashSet<Parameter>();

        @Override
        public void visit(Tree.Assertion that) {
            assertion = that;
            super.visit(that);
            assertion = null;
        }

        @Override
        public void visit(Tree.Condition that) {
            referencedParameters.clear();
            super.visit(that);
            if (assertion != null && !referencedParameters.isEmpty()) {
                for (Parameter referencedParameter : referencedParameters) {
                    Map<Tree.Assertion, List<Tree.Condition>> parameterAssertions = parametersAssertions.get(referencedParameter);
                    if (parameterAssertions == null) {
                        parameterAssertions = new LinkedHashMap<Tree.Assertion, List<Tree.Condition>>();
                        parametersAssertions.put(referencedParameter, parameterAssertions);
                    }
                    List<Tree.Condition> parameterConditions = parameterAssertions.get(assertion);
                    if (parameterConditions == null) {
                        parameterConditions = new ArrayList<Tree.Condition>();
                        parameterAssertions.put(assertion, parameterConditions);
                    }
                    parameterConditions.add(that);
                }
            }
        }

        @Override
        public void visit(Tree.BaseMemberExpression that) {
            if (assertion != null) {
                Declaration d = that.getDeclaration();
                Scope realScope = com.redhat.ceylon.model.typechecker.model.ModelUtil.getRealScope(d.getScope());
                if (parametersNames.containsKey(d.getName()) && realScope == decl) {
                    referencedParameters.add(parametersNames.get(d.getName()));
                }
            }
            super.visit(that);
        }

        @Override
        public void visit(Tree.Statement that) {
            if (assertion == null) {
                stop = true;
            }
            super.visit(that);
        }

        @Override
        public void visitAny(Node that) {
            if (!stop) {
                super.visitAny(that);
            }
        }
    });
    return parametersAssertions;
}
Also used : Visitor(com.redhat.ceylon.compiler.typechecker.tree.Visitor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(com.redhat.ceylon.compiler.typechecker.tree.Node) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) ArrayList(java.util.ArrayList) List(java.util.List) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) Util.findBottomMostRefinedDeclaration(com.redhat.ceylon.ceylondoc.Util.findBottomMostRefinedDeclaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) HashSet(java.util.HashSet) Functional(com.redhat.ceylon.model.typechecker.model.Functional) Scope(com.redhat.ceylon.model.typechecker.model.Scope) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with Node

use of com.redhat.ceylon.compiler.typechecker.tree.Node in project ceylon-compiler by ceylon.

the class ClassOrPackageDoc method getParameterDefaultValue.

private String getParameterDefaultValue(Parameter param) throws IOException {
    String defaultValue = null;
    if (param.isDefaulted()) {
        PhasedUnit pu = tool.getParameterUnit(param);
        Node paramNode = tool.getParameterNode(param);
        if (pu != null && paramNode instanceof Tree.Parameter) {
            Tree.SpecifierOrInitializerExpression defArg = getDefaultArgument((Tree.Parameter) paramNode);
            if (defArg != null) {
                defaultValue = getSourceCode(pu, defArg.getExpression());
                if (defaultValue != null) {
                    defaultValue = defaultValue.trim();
                }
            }
        }
    }
    return defaultValue;
}
Also used : Node(com.redhat.ceylon.compiler.typechecker.tree.Node) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)

Example 3 with Node

use of com.redhat.ceylon.compiler.typechecker.tree.Node in project ceylon-compiler by ceylon.

the class CeylonDoc method writeAnnotations.

protected final void writeAnnotations(Referenceable referenceable) throws IOException {
    Tree.AnnotationList annotationList = null;
    Node node = tool.getNode(referenceable);
    if (node instanceof Tree.Declaration) {
        annotationList = ((Tree.Declaration) node).getAnnotationList();
    } else if (node instanceof Tree.ImportModule) {
        annotationList = ((Tree.ImportModule) node).getAnnotationList();
    } else if (node instanceof Tree.ModuleDescriptor) {
        annotationList = ((Tree.ModuleDescriptor) node).getAnnotationList();
    } else if (node instanceof Tree.PackageDescriptor) {
        annotationList = ((Tree.PackageDescriptor) node).getAnnotationList();
    }
    if (annotationList != null) {
        annotationList.visit(new WriteAnnotationsVisitor(referenceable));
    }
}
Also used : Node(com.redhat.ceylon.compiler.typechecker.tree.Node) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration)

Example 4 with Node

use of com.redhat.ceylon.compiler.typechecker.tree.Node in project ceylon-compiler by ceylon.

the class ClassOrPackageDoc method writeConstantValue.

private void writeConstantValue(Value v) throws IOException {
    Node node = tool.getNode(v);
    PhasedUnit pu = tool.getUnit(v);
    if (pu == null || !(node instanceof Tree.AttributeDeclaration)) {
        return;
    }
    Tree.AttributeDeclaration attribute = (Tree.AttributeDeclaration) node;
    Tree.SpecifierOrInitializerExpression specifierExpression = attribute.getSpecifierOrInitializerExpression();
    if (specifierExpression == null) {
        return;
    }
    String value = getSourceCode(pu, specifierExpression);
    int newLineIndex = value.indexOf("\n");
    String valueFirstLine = newLineIndex != -1 ? value.substring(0, newLineIndex) : value;
    around("span class='specifier'", valueFirstLine);
    if (newLineIndex != -1) {
        around("a class='specifier-ellipsis' href='#' title='Click for expand the rest of value.'", "...");
        open("div class='specifier-rest'");
        write(value.substring(newLineIndex + 1));
        close("div");
    }
}
Also used : Node(com.redhat.ceylon.compiler.typechecker.tree.Node) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)

Example 5 with Node

use of com.redhat.ceylon.compiler.typechecker.tree.Node in project ceylon-compiler by ceylon.

the class LinkRenderer method findDocLink.

private Tree.DocLink findDocLink(final String docLinkText, Referenceable referenceable) {
    final Tree.DocLink[] docLinks = new Tree.DocLink[1];
    Node scopeNode = ceylonDocTool.getNode(referenceable);
    if (scopeNode != null) {
        scopeNode.visit(new Visitor() {

            @Override
            public void visit(Tree.DocLink docLink) {
                String s1 = normalizeSpaces(docLinkText);
                String s2 = normalizeSpaces(docLink.getText());
                if (s1.equals(s2)) {
                    docLinks[0] = docLink;
                    return;
                }
            }
        });
    }
    return docLinks[0];
}
Also used : Visitor(com.redhat.ceylon.compiler.typechecker.tree.Visitor) Node(com.redhat.ceylon.compiler.typechecker.tree.Node) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree)

Aggregations

Node (com.redhat.ceylon.compiler.typechecker.tree.Node)9 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)7 PhasedUnit (com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)4 Visitor (com.redhat.ceylon.compiler.typechecker.tree.Visitor)3 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)3 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)3 Scope (com.redhat.ceylon.model.typechecker.model.Scope)2 Type (com.redhat.ceylon.model.typechecker.model.Type)2 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)2 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)2 ArrayList (java.util.ArrayList)2 Util.findBottomMostRefinedDeclaration (com.redhat.ceylon.ceylondoc.Util.findBottomMostRefinedDeclaration)1 SourceDeclarationVisitor (com.redhat.ceylon.compiler.java.loader.SourceDeclarationVisitor)1 Expression (com.redhat.ceylon.compiler.typechecker.tree.Tree.Expression)1 Annotation (com.redhat.ceylon.model.typechecker.model.Annotation)1 Class (com.redhat.ceylon.model.typechecker.model.Class)1 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)1 Constructor (com.redhat.ceylon.model.typechecker.model.Constructor)1 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)1 Functional (com.redhat.ceylon.model.typechecker.model.Functional)1