Package com.redhat.ceylon.compiler.typechecker.tree

Examples of com.redhat.ceylon.compiler.typechecker.tree.Node


    }

    @Test
    public void testCompletions() {
        assist.findNode();
        Node node = assist.getNodeAtLocation();
        //Check that we did find a node
        Assert.assertNotNull("No node found at " + assist.getRow() + ":" + assist.getColumn() + " for file " + file, node);
        //Check that the node we found is the one we were actually looking for
        Assert.assertEquals(nodeText, assist.getTextAtLocation());
        List<String> comps = assist.getCompletions();
View Full Code Here


            } else {
                out.write("error");
            }
            out.write(String.format(" encountered [%s]", err.getMessage()));
            if (err instanceof AnalysisMessage) {
                Node n = ((AnalysisMessage)err).getTreeNode();
                if(n != null)
                    n = com.redhat.ceylon.compiler.typechecker.tree.Util.getIdentifyingNode(n);
                out.write(String.format(" at %s of %s", n.getLocation(), n.getUnit().getFilename()));
            } else if (err instanceof RecognitionError) {
                RecognitionError rer = (RecognitionError)err;
                out.write(String.format(" at %d:%d", rer.getLine(), rer.getCharacterInLine()));
            }
            out.write(System.lineSeparator());
            count++;
           
            if(diagnosticListener != null){
                boolean warning = err instanceof UsageWarning;
                int position = -1;
                File file = null;
                if(err instanceof AnalysisMessage){
                    Node node = ((AnalysisMessage) err).getTreeNode();
                    if(node != null)
                        node = com.redhat.ceylon.compiler.typechecker.tree.Util.getIdentifyingNode(node);
                    if(node != null && node.getToken() != null)
                        position = node.getToken().getCharPositionInLine();
                    if(node.getUnit() != null && node.getUnit().getFullPath() != null)
                        file = new File(node.getUnit().getFullPath()).getAbsoluteFile();
                }else if(err instanceof RecognitionError){
                    // FIXME: file??
                    position = ((RecognitionError) err).getCharacterInLine();
                }
                if(position != -1)
View Full Code Here

        //don't recurse to the Variable, since we don't
        //want to check that the specifier expression is
        //assignable to the declared variable type
        //(nor is it possible to infer the variable type)
        ProducedType t = null;
        Node n = that;
        Tree.Term term = null;
        Tree.Variable v = that.getVariable();
        if (v!=null) {
            //v.getType().visit(this);
            defaultTypeToAnything(v);
View Full Code Here

    }

    @Override public void visit(Tree.Resource that) {
        super.visit(that);
        ProducedType t = null;
        Node typedNode = null;
        Tree.Expression e = that.getExpression();
        Tree.Variable v = that.getVariable();
        if (e!=null) {
            t = e.getTypeModel();
            typedNode = e;
           
        }
        else if (v!=null) {
            t = v.getType().getTypeModel();
            typedNode = v.getType();
            Tree.SpecifierExpression se = v.getSpecifierExpression();
            if (se==null) {
                v.addError("missing resource specifier");
            }
            else {
                e = se.getExpression();
                if (typedNode instanceof Tree.ValueModifier) {
                    typedNode = se.getExpression();
                }
            }
        }
        else {
            that.addError("missing resource expression");
        }
        if (typedNode!=null) {
            if (!isTypeUnknown(t)) {
                if (e != null) {
                    ProducedType ot = unit.getType(unit.getObtainableDeclaration());
                    ProducedType dt = unit.getType(unit.getDestroyableDeclaration());
                    if (isInstantiationExpression(e)) {
                        if (!t.isSubtypeOf(dt) && !t.isSubtypeOf(ot)) {
                            typedNode.addError("resource must be either obtainable or destroyable: '" +
                                    t.getProducedTypeName(unit) + "' is neither 'Obtainable' nor 'Destroyable'");
                        }
                    }
                    else {
                        checkAssignable(t, ot, typedNode, "resource must be obtainable");
View Full Code Here

                        Tree.Parameter parameter =
                                parameterList.getParameters().get(j);
                        Parameter p = parameter.getParameterModel();
                        ProducedType parameterType =
                                p.getModel().getTypedReference().getFullType();
                        Node typeNode = parameter;
                        if (parameter instanceof Tree.ParameterDeclaration) {
                            Tree.Type type =
                                    ((Tree.ParameterDeclaration) parameter)
                                    .getTypedDeclaration().getType();
                            if (type!=null) {
View Full Code Here

            }
        }
        if (type instanceof Tree.LocalModifier) {
            if (isTypeUnknown(type.getTypeModel())) {
                if (se==null || !hasError(se)) {
                    Node node = type.getToken()==null ? that : type;
                    node.addError("argument type could not be inferred");
                }
            }
        }
    }
View Full Code Here

            }
        }
        if (type instanceof Tree.LocalModifier) {
            if (isTypeUnknown(type.getTypeModel())) {
                if (se==null || hasError(type)) {
                    Node node = type.getToken()==null ? that : type;
                    node.addError("argument type could not be inferred");
                }
            }
        }
    }
View Full Code Here

            }
        }
        ProducedType pt = pr.getTypedParameter(p).getFullType();
//      if (p.isSequenced()) pt = unit.getIteratedType(pt);
        if (!isTypeUnknown(argType) && !isTypeUnknown(pt)) {
            Node node;
            if (a instanceof Tree.SpecifiedArgument) {
                node = ((Tree.SpecifiedArgument) a).getSpecifierExpression();
            }
            else {
                node = a;
View Full Code Here

        List<Parameter> params = pl.getParameters();
        for (int i=0; i<params.size(); i++) {
            Parameter p = params.get(i);
            if (i>=args.size()) {
                if (!p.isDefaulted() && (!p.isSequenced() || p.isAtLeastOne())) {
                    Node n = that instanceof Tree.Annotation && args.isEmpty() ? that : pal;
                    n.addError("missing argument to required parameter '" +
                            p.getName() + "' of '" + pr.getDeclaration().getName(unit) + "'");
                }
            }
            else {
                Tree.PositionalArgument a = args.get(i);
View Full Code Here

        }
        ProducedType t;
        TypeDeclaration d;
        Tree.StaticType type = that.getType();
        Tree.BaseMemberExpression oe = that.getObjectExpression();
        Node errorNode;
    if (type != null) {
          t = type.getTypeModel();
          d = t.getDeclaration();
          errorNode = type;
        }
    else if (oe != null ) {
          t = oe.getTypeModel();
          d = t.getDeclaration();
          if (!d.isAnonymous()) {
            oe.addError("must be a reference to an anonymous class");
          }
          errorNode = oe;
        }
    else {
        errorNode = that;
            ClassOrInterface classOrInterface =
                    getContainingClassOrInterface(that.getScope());
        if (that instanceof Tree.ClassLiteral ||
            that instanceof Tree.InterfaceLiteral) {
            d = classOrInterface;
            if (d==null) {
                errorNode.addError("no containing type");
                return; //EARLY EXIT!!
            }
            else {
                t = classOrInterface.getType();
            }
        }
        else {
            errorNode.addError("missing type reference");
            return; //EARLY EXIT!!
        }
    }
        // FIXME: should we disallow type parameters in there?
        if (t!=null) {
            that.setDeclaration(d);
            that.setWantsDeclaration(true);
            if (that instanceof Tree.ClassLiteral) {
                if (!(d instanceof Class)) {
                    if (d != null) {
                        errorNode.addError("referenced declaration is not a class" +
                                getDeclarationReferenceSuggestion(d));
                    }
                }
                that.setTypeModel(unit.getClassDeclarationType());
            }
            else if (that instanceof Tree.InterfaceLiteral) {
                if (!(d instanceof Interface)) {
                    if (d!=null) {
                        errorNode.addError("referenced declaration is not an interface" +
                                getDeclarationReferenceSuggestion(d));
                    }
                }
                that.setTypeModel(unit.getInterfaceDeclarationType());
            }
            else if (that instanceof Tree.AliasLiteral) {
                if (!(d instanceof TypeAlias)) {
                    errorNode.addError("referenced declaration is not a type alias" +
                            getDeclarationReferenceSuggestion(d));
                }
                that.setTypeModel(unit.getAliasDeclarationType());
            }
            else if (that instanceof Tree.TypeParameterLiteral) {
                if (!(d instanceof TypeParameter)) {
                    errorNode.addError("referenced declaration is not a type parameter" +
                            getDeclarationReferenceSuggestion(d));
                }
                that.setTypeModel(unit.getTypeParameterDeclarationType());
            }
            else if (d != null) {
                that.setWantsDeclaration(false);
                t = t.resolveAliases();
                //checkNonlocalType(that.getType(), t.getDeclaration());
                if (d instanceof Class) {
//                    checkNonlocal(that, t.getDeclaration());
                    if (((Class) d).isAbstraction()) {
                        errorNode.addError("class constructor is overloaded");
                    }
                    else {
                        that.setTypeModel(unit.getClassMetatype(t));
                    }
                }
View Full Code Here

TOP

Related Classes of com.redhat.ceylon.compiler.typechecker.tree.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.