Search in sources :

Example 1 with Node

use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.

the class BugException method addError.

/**
 * Add an error to the a node. A {@link CodeGenError}
 * is created with the exception's message and the exception as cause,
 * and is added to the assoicated node (if there is one), and otherwise
 * the given node.
 * @param fallbackNode
 */
public void addError(Node fallbackNode) {
    if (!this.attached) {
        Node bestNode = bestNode(fallbackNode);
        bestNode.addError(new CodeGenError(bestNode, getMessage(), Backend.Java, this));
        this.attached = true;
    }
}
Also used : Node(org.eclipse.ceylon.compiler.typechecker.tree.Node)

Example 2 with Node

use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.

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(org.eclipse.ceylon.compiler.typechecker.tree.Node) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 3 with Node

use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.

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(org.eclipse.ceylon.compiler.typechecker.tree.Node) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 4 with Node

use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.

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 = org.eclipse.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(org.eclipse.ceylon.compiler.typechecker.tree.Visitor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(org.eclipse.ceylon.compiler.typechecker.tree.Node) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) List(java.util.List) Util.findBottomMostRefinedDeclaration(org.eclipse.ceylon.ceylondoc.Util.findBottomMostRefinedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) HashSet(java.util.HashSet) Functional(org.eclipse.ceylon.model.typechecker.model.Functional) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with Node

use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.

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(org.eclipse.ceylon.compiler.typechecker.tree.Visitor) Node(org.eclipse.ceylon.compiler.typechecker.tree.Node) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Aggregations

Node (org.eclipse.ceylon.compiler.typechecker.tree.Node)33 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)26 Type (org.eclipse.ceylon.model.typechecker.model.Type)16 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)14 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)12 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)11 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)10 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)10 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)10 ModelUtil.genericFunctionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType)10 ModelUtil.unionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType)10 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)10 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)10 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)9 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)9 AnalyzerUtil.getTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration)7 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)6 AnalyzerUtil.getPackageTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration)6 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)6 AnalyzerUtil.checkCasesDisjoint (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint)5