Java Code Examples for antlr.collections.AST#toString()

The following examples show how to use antlr.collections.AST#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypedefVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void generateStringAlias(AST typeDeclaratorNode,
                                 AST identifierNode,
                                 XmlSchemaType schemaType,
                                 CorbaType corbaType,
                                 Scope fqName) {

    Scope typedefScope = new Scope(getScope(), identifierNode);

    Alias corbaString = new Alias();
    if (typeDeclaratorNode.getType() == IDLTokenTypes.LITERAL_string) {
        corbaString.setBasetype(CorbaConstants.NT_CORBA_STRING);
    } else if (typeDeclaratorNode.getType() == IDLTokenTypes.LITERAL_wstring) {
        corbaString.setBasetype(CorbaConstants.NT_CORBA_WSTRING);
    } else {
        // should never get here
        throw new RuntimeException("[TypedefVisitor] Attempted to visit an invalid node: "
                                   + typeDeclaratorNode.toString());
    }
    Scope newScope = new Scope(typedefScope.getParent(), identifierNode);
    corbaString.setQName(new QName(typeMap.getTargetNamespace(), newScope.toString()));
    corbaString.setType(Constants.XSD_STRING);
    corbaString.setRepositoryID(newScope.toIDLRepositoryID());

    typeMap.getStructOrExceptionOrUnion().add(corbaString);

}
 
Example 2
Source File: ArrayVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static boolean accept(AST node) {
    boolean result = false;
    AST sizeNode = node.getFirstChild();
    if (sizeNode != null) {
        // check that node has a fixed_array_size child node
        result = true;
        while (sizeNode != null
            && result) {
            // check that all fixed_array_size nodes encode
            // positive integers
            String s = sizeNode.toString();
            for (int j = 0; j < s.length(); j++) {
                if (!Character.isDigit(s.charAt(j))) {
                    result = false;
                }
            }
            sizeNode = sizeNode.getNextSibling();
        }
    }
    return result;
}
 
Example 3
Source File: ExceptionVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XmlSchemaElement createElementType(AST memberNode, XmlSchemaType stype,
                                           Scope fqName) {
    // xmlschema:member
    XmlSchemaElement member = new XmlSchemaElement(schema, false);
    String memberName = memberNode.toString();
    member.setName(memberName);
    if (stype != null) {
        member.setSchemaType(stype);
        member.setSchemaTypeName(stype.getQName());
        if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            member.setNillable(true);
        }
    } else {
        wsdlVisitor.getDeferredActions().
            add(fqName, new ExceptionDeferredAction(member));
    }
    return member;
}
 
Example 4
Source File: StructVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XmlSchemaElement createXmlSchemaElement(AST memberNode,
                                                XmlSchemaType schemaType,
                                                Scope fqName) {
    // xmlschema:member
    XmlSchemaElement member = new XmlSchemaElement(schema, false);
    String memberName = memberNode.toString();
    member.setName(memberName);
    member.setSchemaType(schemaType);
    if (schemaType != null) {
        member.setSchemaTypeName(schemaType.getQName());
        if (schemaType.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            member.setNillable(true);
        }
    } else {
        wsdlVisitor.getDeferredActions().
            add(fqName, new StructDeferredAction(member));
    }
    return member;
}
 
Example 5
Source File: MismatchedTokenException.java    From dacapobench with Apache License 2.0 5 votes vote down vote up
public MismatchedTokenException(String[] tokenNames_, AST node_, int expecting_, boolean matchNot) {
    super("Mismatched Token", "<AST>", -1, -1);
    tokenNames = tokenNames_;
    node = node_;
    if (node_ == null) {
        tokenText = "<empty tree>";
    }
    else {
        tokenText = node_.toString();
    }
    mismatchType = matchNot ? NOT_TOKEN : TOKEN;
    expecting = expecting_;
}
 
Example 6
Source File: UnionVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void removeRecursiveScopedName(AST identifierNode) {
    String structName = identifierNode.toString();
    Scope structScope = new Scope(getScope(), structName);

    ScopeNameCollection scopedNames = wsdlVisitor.getScopedNames();
    scopedNames.remove(structScope);
}
 
Example 7
Source File: UnionVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean addRecursiveScopedName(AST identifierNode) {
    String structName = identifierNode.toString();
    Scope structScope = new Scope(getScope(), structName);

    ScopeNameCollection scopedNames = wsdlVisitor.getScopedNames();
    if (scopedNames.getScope(structScope) == null) {
        scopedNames.add(structScope);
        return true;
    }
    return false;
}
 
Example 8
Source File: UnionVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void visitForwardDeclaredUnion(AST identifierNode) {
    String unionName = identifierNode.toString();
    Scope unionScope = new Scope(getScope(), unionName);

    ScopeNameCollection scopedNames = wsdlVisitor.getScopedNames();
    if (scopedNames.getScope(unionScope) == null) {
        scopedNames.add(unionScope);
    }
}
 
Example 9
Source File: ParamTypeSpecVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void visit(AST node) {
    // <param_type_spec> ::= <base_type_spec>
    //                     | <string_type>
    //                     | <wstring_type>
    //                     | <scoped_name>


    Visitor visitor = null;


    if (PrimitiveTypesVisitor.accept(node)) {
        // base_type_spec
        visitor = new PrimitiveTypesVisitor(getScope(), definition, schema, schemas);
    } else if (StringVisitor.accept(node)) {
        // string_type_spec
        // wstring_type_spec
        visitor = new StringVisitor(getScope(), definition, schema, wsdlVisitor, null);

    } else if (ScopedNameVisitor.accept(getScope(), definition, schema, node, wsdlVisitor)) {
        // scoped_name
        visitor = new ScopedNameVisitor(getScope(), definition, schema, wsdlVisitor);

    } else {
        throw new RuntimeException("[ParamTypeSpecVisitor] Invalid IDL: unknown element "
                                   + node.toString());
    }

    visitor.visit(node);
    setSchemaType(visitor.getSchemaType());
    setCorbaType(visitor.getCorbaType());
    setFullyQualifiedName(visitor.getFullyQualifiedName());
}
 
Example 10
Source File: PortTypeVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void visitForwardDeclaredInterface(AST identifierNode) {
    String interfaceName = identifierNode.toString();
    Scope interfaceScope = new Scope(getScope(), interfaceName);

    ScopeNameCollection scopedNames = wsdlVisitor.getScopedNames();
    if (scopedNames.getScope(interfaceScope) == null) {
        scopedNames.add(interfaceScope);
    }

}
 
Example 11
Source File: AttributeVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void generateSetter(AST typeNode, AST nameNode) {
    // generate wrapped doc element in parameter
    XmlSchemaElement inParameters =
        generateWrappedDocElement(typeNode,
                                  SETTER_PREFIX + nameNode.toString(),
                                  PARAM_NAME);
    // generate wrapped doc element out parameter
    XmlSchemaElement outParameters =
        generateWrappedDocElement(null,
                                  SETTER_PREFIX + nameNode.toString() + RESULT_POSTFIX,
                                  RETURN_PARAM_NAME);

    // generate input message
    Message inMsg = generateMessage(inParameters,
                                    SETTER_PREFIX + nameNode.toString());
    // generate output message
    Message outMsg = generateMessage(outParameters,
                                     SETTER_PREFIX + nameNode.toString() + RESPONSE_POSTFIX);

    // generate operation
    String name = SETTER_PREFIX + nameNode.toString();
    Operation op = generateOperation(name, inMsg, outMsg);


    // generate corba return param
    ParamType corbaParam = generateCorbaParam(typeNode);

    // generate corba operation
    OperationType corbaOp = generateCorbaOperation(op, corbaParam, null);

    // generate binding
    generateCorbaBindingOperation(binding, op, corbaOp);
}
 
Example 12
Source File: AttributeVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void generateGetter(AST typeNode, AST nameNode) {
    // generate wrapped doc element in parameter
    XmlSchemaElement inParameters =
        generateWrappedDocElement(null,
                                  GETTER_PREFIX + nameNode.toString(),
                                  PARAM_NAME);
    // generate wrapped doc element out parameter
    XmlSchemaElement outParameters =
        generateWrappedDocElement(typeNode,
                                  GETTER_PREFIX + nameNode.toString() + RESULT_POSTFIX,
                                  RETURN_PARAM_NAME);

    // generate input message
    Message inMsg = generateMessage(inParameters,
                                    GETTER_PREFIX + nameNode.toString());
    // generate output message
    Message outMsg = generateMessage(outParameters,
                                     GETTER_PREFIX + nameNode.toString() + RESPONSE_POSTFIX);

    // generate operation
    String name = GETTER_PREFIX + nameNode.toString();
    Operation op = generateOperation(name, inMsg, outMsg);


    // generate corba return param
    ArgType corbaReturn = generateCorbaReturnParam(typeNode);

    // generate corba operation
    OperationType corbaOp = generateCorbaOperation(op, null, corbaReturn);

    // generate binding
    generateCorbaBindingOperation(binding, op, corbaOp);
}
 
Example 13
Source File: StructVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void removeRecursiveScopedName(AST identifierNode) {
    String structName = identifierNode.toString();
    Scope structScope = new Scope(getScope(), structName);

    ScopeNameCollection scopedNames = wsdlVisitor.getScopedNames();
    scopedNames.remove(structScope);
}
 
Example 14
Source File: StructVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean addRecursiveScopedName(AST identifierNode) {
    String structName = identifierNode.toString();
    Scope structScope = new Scope(getScope(), structName);

    ScopeNameCollection scopedNames = wsdlVisitor.getScopedNames();
    if (scopedNames.getScope(structScope) == null) {
        scopedNames.add(structScope);
        return true;
    }
    return false;
}
 
Example 15
Source File: StructVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void visitForwardDeclaredStruct(AST identifierNode) {
    String structName = identifierNode.toString();
    Scope structScope = new Scope(getScope(), structName);

    ScopeNameCollection scopedNames = wsdlVisitor.getScopedNames();
    if (scopedNames.getScope(structScope) == null) {
        scopedNames.add(structScope);
    }
}
 
Example 16
Source File: StructVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private MemberType createMemberType(AST memberNode,
                                    CorbaType corbaType,
                                    Scope fqName) {
    // corba:member
    String memberName = memberNode.toString();
    MemberType memberType = new MemberType();
    memberType.setName(memberName);
    if (corbaType != null) {
        memberType.setIdltype(corbaType.getQName());
    } else {
        wsdlVisitor.getDeferredActions().
            add(fqName, new StructDeferredAction(memberType));
    }
    return memberType;
}
 
Example 17
Source File: MismatchedTokenException.java    From dacapobench with Apache License 2.0 5 votes vote down vote up
public MismatchedTokenException(String[] tokenNames_, AST node_, BitSet set_, boolean matchNot) {
    super("Mismatched Token", "<AST>", -1, -1);
    tokenNames = tokenNames_;
    node = node_;
    if (node_ == null) {
        tokenText = "<empty tree>";
    }
    else {
        tokenText = node_.toString();
    }
    mismatchType = matchNot ? NOT_SET : SET;
    set = set_;
}
 
Example 18
Source File: MismatchedTokenException.java    From dacapobench with Apache License 2.0 5 votes vote down vote up
public MismatchedTokenException(String[] tokenNames_, AST node_, int lower, int upper_, boolean matchNot) {
    super("Mismatched Token", "<AST>", -1, -1);
    tokenNames = tokenNames_;
    node = node_;
    if (node_ == null) {
        tokenText = "<empty tree>";
    }
    else {
        tokenText = node_.toString();
    }
    mismatchType = matchNot ? NOT_RANGE : RANGE;
    expecting = lower;
    upper = upper_;
}
 
Example 19
Source File: ScopedNameVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static boolean findSchemaTypeInGlobalScope(Scope scope,
                                                   Definition defn,
                                                   XmlSchema currentSchema,
                                                   AST node,
                                                   WSDLASTVisitor wsdlVisitor,
                                                   VisitorTypeHolder holder) {
    XmlSchemaCollection schemas = wsdlVisitor.getSchemas();
    TypeMappingType typeMap = wsdlVisitor.getTypeMap();
    ModuleToNSMapper mapper = wsdlVisitor.getModuleToNSMapper();
    WSDLSchemaManager manager = wsdlVisitor.getManager();

    Scope scopedName = new Scope(scope, node);
    String name = node.toString();
    if (isFullyScopedName(node)) {
        scopedName = getFullyScopedName(new Scope(), node);
        name = scopedName.toString();
    }
    boolean result = findNonSchemaType(name, wsdlVisitor, holder);
    if (!result) {
        XmlSchema xmlSchema = currentSchema;
        QName qname = null;
        String tns = mapper.map(scopedName.getParent());
        if (tns != null) {
            xmlSchema = manager.getXmlSchema(tns);
            if (xmlSchema != null) {
                qname = new QName(xmlSchema.getTargetNamespace(), scopedName.tail());
            }
        } else {
            qname = new QName(xmlSchema.getTargetNamespace(), name);
        }
        XmlSchemaType stype = null;
        if (qname != null) {
            // Exceptions are treated as a special case as above
            if (exceptionMode) {
                qname = new QName(xmlSchema.getTargetNamespace(), qname.getLocalPart() + "Type");
            }
            stype = xmlSchema.getTypeByName(qname);
            if (stype == null) {
                stype = schemas.getTypeByQName(qname);
            }
        }
        if (stype != null) {
            result = true;
            if (holder != null) {
                holder.setSchemaType(stype);
                holder.setCorbaType(getCorbaSchemaType(xmlSchema, typeMap, stype, scopedName));
                //add a xmlschema import
                if (!currentSchema.getTargetNamespace().equals(xmlSchema.getTargetNamespace())) {
                    String importFile = wsdlVisitor.getOutputDir()
                        + System.getProperty("file.separator")
                        + scopedName.getParent().toString("_");
                    manager.addXmlSchemaImport(currentSchema, xmlSchema, importFile);
                }
            }
        }
    }
    return result;
}
 
Example 20
Source File: ConstVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void visit(AST constNode) {
    // <const_dcl> ::= "const" <const_type> <identifier> "=" <const_exp>
    // <const_type> ::= <integer_type>
    //                | <char_type>
    //                | <wide_char_type>
    //                | <boolean_type>
    //                | <floating_pt_type>
    //                | <string_type>
    //                | <wide_string_type>
    //                | <fixed_pt_const_type>
    //                | <scoped_name>
    //                | <octet_type>


    AST constTypeNode = constNode.getFirstChild();
    AST constNameNode = TypesUtils.getCorbaTypeNameNode(constTypeNode);
    AST constValueNode = constNameNode.getNextSibling();
    // build value string
    StringBuilder constValue = new StringBuilder();
    if (constValueNode.toString() != null) {
        constValue.append(constValueNode.toString());
    }
    constValueNode = constValueNode.getFirstChild();
    if (constValue.length() == 1) {
        // might be a control char
        byte ch = (byte)constValue.charAt(0);
        if (ch >= 0 && ch <= 31) {
            // ascii code between 0 and 31 is invisible control code
            constValue.deleteCharAt(0);
            constValue.append('\\').append(Integer.toOctalString(ch));
        }
    }
    while (constValueNode != null) {
        constValue.append(constValueNode.toString());
        constValueNode = constValueNode.getFirstChild();
    }

    QName constQName = new QName(typeMap.getTargetNamespace(),
                                 new Scope(getScope(), constNameNode).toString());

    Visitor visitor = null;
    if (PrimitiveTypesVisitor.accept(constTypeNode)) {
        visitor = new PrimitiveTypesVisitor(getScope(), definition, schema, schemas);
    } else if (StringVisitor.accept(constTypeNode)) {
        // string_type_spec
        // wstring_type_spec
        visitor = new StringVisitor(getScope(), definition, schema, wsdlVisitor, constTypeNode);
    } else if (FixedPtConstVisitor.accept(constTypeNode)) {
        visitor = new FixedPtConstVisitor(getScope(), definition, schema, schemas);
    } else if (ScopedNameVisitor.accept(getScope(), definition, schema, constTypeNode, wsdlVisitor)) {
        visitor = new ScopedNameVisitor(getScope(), definition, schema, wsdlVisitor);
    }
    if (visitor == null) {
        throw new RuntimeException("can't resolve type for const " + constNameNode.getText());
    }
    visitor.visit(constTypeNode);
    XmlSchemaType constSchemaType = visitor.getSchemaType();
    CorbaTypeImpl constCorbaType = visitor.getCorbaType();

    // corba:const
    Const corbaConst = new Const();
    corbaConst.setQName(constQName);
    corbaConst.setValue(constValue.toString());
    corbaConst.setType(constSchemaType.getQName());
    corbaConst.setIdltype(constCorbaType.getQName());

    typeMap.getStructOrExceptionOrUnion().add(corbaConst);
}