Java Code Examples for antlr.collections.AST#getText()
The following examples show how to use
antlr.collections.AST#getText() .
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: DotNode.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
private void setPropertyNameAndPath(AST parent) { if ( isDotNode( parent ) ) { DotNode dotNode = ( DotNode ) parent; AST lhs = dotNode.getFirstChild(); AST rhs = lhs.getNextSibling(); propertyName = rhs.getText(); propertyPath = propertyPath + "." + propertyName; // Append the new property name onto the unresolved path. dotNode.propertyPath = propertyPath; if ( log.isDebugEnabled() ) { log.debug( "Unresolved property path is now '" + dotNode.propertyPath + "'" ); } } else { if ( log.isDebugEnabled() ) { log.debug( "terminal propertyPath = [" + propertyPath + "]" ); } } }
Example 2
Source File: ASTPrinter.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public String nodeToString(AST ast, boolean showClassName) { if ( ast == null ) { return "{null}"; } StringBuffer buf = new StringBuffer(); buf.append( "[" ).append( getTokenTypeName( ast.getType() ) ).append( "] " ); if ( showClassName ) { buf.append( StringHelper.unqualify( ast.getClass().getName() ) ).append( ": " ); } buf.append( "'" ); String text = ast.getText(); appendEscapedMultibyteChars(text, buf); buf.append( "'" ); if ( ast instanceof DisplayableNode ) { DisplayableNode displayableNode = ( DisplayableNode ) ast; // Add a space before the display text. buf.append( " " ).append( displayableNode.getDisplayText() ); } String s = buf.toString(); return s; }
Example 3
Source File: HqlSqlWalker.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
protected boolean isNonQualifiedPropertyRef(AST ident) { final String identText = ident.getText(); if ( currentFromClause.isFromElementAlias( identText ) ) { return false; } List fromElements = currentFromClause.getExplicitFromElements(); if ( fromElements.size() == 1 ) { final FromElement fromElement = ( FromElement ) fromElements.get( 0 ); try { log.trace( "attempting to resolve property [" + identText + "] as a non-qualified ref" ); return fromElement.getPropertyMapping( identText ).toType( identText ) != null; } catch( QueryException e ) { // Should mean that no such property was found } } return false; }
Example 4
Source File: HqlSqlWalker.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected boolean isNonQualifiedPropertyRef(AST ident) { final String identText = ident.getText(); if ( currentFromClause.isFromElementAlias( identText ) ) { return false; } List fromElements = currentFromClause.getExplicitFromElements(); if ( fromElements.size() == 1 ) { final FromElement fromElement = (FromElement) fromElements.get( 0 ); try { LOG.tracev( "Attempting to resolve property [{0}] as a non-qualified ref", identText ); return fromElement.getPropertyMapping( identText ).toType( identText ) != null; } catch (QueryException e) { // Should mean that no such property was found } } return false; }
Example 5
Source File: ASTPrinter.java From lams with GNU General Public License v2.0 | 6 votes |
public String nodeToString(AST ast) { if ( ast == null ) { return "{node:null}"; } StringBuilder buf = new StringBuilder(); buf.append( "[" ).append( getTokenTypeName( ast.getType() ) ).append( "] " ); buf.append( StringHelper.unqualify( ast.getClass().getName() ) ).append( ": " ); buf.append( "'" ); String text = ast.getText(); if ( text == null ) { text = "{text:null}"; } appendEscapedMultibyteChars( text, buf ); buf.append( "'" ); if ( ast instanceof DisplayableNode ) { DisplayableNode displayableNode = (DisplayableNode) ast; // Add a space before the display text. buf.append( " " ).append( displayableNode.getDisplayText() ); } return buf.toString(); }
Example 6
Source File: HqlSqlWalker.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
protected AST generateNamedParameter(AST delimiterNode, AST nameNode) throws SemanticException { String name = nameNode.getText(); trackNamedParameterPositions( name ); // create the node initially with the param name so that it shows // appropriately in the "original text" attribute ParameterNode parameter = ( ParameterNode ) astFactory.create( NAMED_PARAM, name ); parameter.setText( "?" ); NamedParameterSpecification paramSpec = new NamedParameterSpecification( ( ( Node ) delimiterNode ).getLine(), ( ( Node ) delimiterNode ).getColumn(), name ); parameter.setHqlParameterSpecification( paramSpec ); parameters.add( paramSpec ); return parameter; }
Example 7
Source File: Qualifier.java From testability-explorer with Apache License 2.0 | 5 votes |
public String stringify(AST ast) { if (ast == null) return ""; String text = ""; AST child = ast.getFirstChild(); if (child != null) text += stringify(child); text += ast.getText(); if (child != null) text += stringify(child.getNextSibling()); return text; }
Example 8
Source File: TP01Support.java From proparse with Eclipse Public License 2.0 | 5 votes |
@Override protected void methodBegin(AST blockAST, AST idAST) { scopeAdd(blockAST); JPNode idNode = (JPNode) idAST; BlockNode blockNode = (BlockNode) idNode.parent(); SymbolScope definingScope = currentScope.getParentScope(); Routine r = new Routine(idAST.getText(), definingScope, currentScope); r.setProgressType(TokenTypes.METHOD); r.setDefOrIdNode(blockNode); blockNode.setSymbol(r); definingScope.add(r); currentRoutine = r; }
Example 9
Source File: FromClause.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Adds a new from element to the from node. * * @param path The reference to the class. * @param alias The alias AST. * @return FromElement - The new FROM element. */ public FromElement addFromElement(String path, AST alias) throws SemanticException { // The path may be a reference to an alias defined in the parent query. String classAlias = ( alias == null ) ? null : alias.getText(); checkForDuplicateClassAlias( classAlias ); FromElementFactory factory = new FromElementFactory( this, null, path, classAlias, null, false ); return factory.addFromElement(); }
Example 10
Source File: HqlSqlWalker.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected AST generatePositionalParameter(AST delimiterNode, AST numberNode) throws SemanticException { // todo : we check this multiple times if ( getSessionFactoryHelper().isStrictJPAQLComplianceEnabled() && namedParameters != null ) { throw new SemanticException( "Cannot mix positional and named parameters: " + queryTranslatorImpl.getQueryString() ); } if ( numberNode == null ) { throw new QueryException( String.format( Locale.ROOT, ERROR_LEGACY_ORDINAL_PARAMS_NO_LONGER_SUPPORTED, queryTranslatorImpl.getQueryString() ) ); } final String positionString = numberNode.getText(); final int label = Integer.parseInt( positionString ); trackPositionalParameterPositions( label ); final ParameterNode parameter = (ParameterNode) astFactory.create( PARAM, positionString ); parameter.setText( "?" ); final int queryParamtersPosition = isFilter() ? label : label - 1; final PositionalParameterSpecification paramSpec = new PositionalParameterSpecification( delimiterNode.getLine(), delimiterNode.getColumn(), label, queryParamtersPosition ); parameter.setHqlParameterSpecification( paramSpec ); parameterSpecs.add( paramSpec ); return parameter; }
Example 11
Source File: MethodNode.java From lams with GNU General Public License v2.0 | 5 votes |
private void collectionProperty(AST path, AST name) throws SemanticException { if ( path == null ) { throw new SemanticException( "Collection function " + name.getText() + " has no path!" ); } SqlNode expr = (SqlNode) path; Type type = expr.getDataType(); LOG.debugf( "collectionProperty() : name=%s type=%s", name, type ); resolveCollectionProperty( expr ); }
Example 12
Source File: DotNode.java From lams with GNU General Public License v2.0 | 5 votes |
private void setPropertyNameAndPath(AST parent) { if ( isDotNode( parent ) ) { DotNode dotNode = (DotNode) parent; AST lhs = dotNode.getFirstChild(); AST rhs = lhs.getNextSibling(); propertyName = rhs.getText(); propertyPath = propertyPath + "." + propertyName; // Append the new property name onto the unresolved path. dotNode.propertyPath = propertyPath; LOG.debugf( "Unresolved property path is now '%s'", dotNode.propertyPath ); } else { LOG.debugf( "Terminal getPropertyPath = [%s]", propertyPath ); } }
Example 13
Source File: MethodNode.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private void collectionProperty(AST path, AST name) throws SemanticException { if ( path == null ) { throw new SemanticException( "Collection function " + name.getText() + " has no path!" ); } SqlNode expr = ( SqlNode ) path; Type type = expr.getDataType(); if ( log.isDebugEnabled() ) { log.debug( "collectionProperty() : name=" + name + " type=" + type ); } resolveCollectionProperty( expr ); }
Example 14
Source File: HqlSqlWalker.java From lams with GNU General Public License v2.0 | 4 votes |
@Override protected void createFromJoinElement( AST path, AST alias, int joinType, AST fetchNode, AST propertyFetch, AST with) throws SemanticException { boolean fetch = fetchNode != null; if ( fetch && isSubQuery() ) { throw new QueryException( "fetch not allowed in subquery from-elements" ); } // the incoming "path" can be either: // 1) an implicit join path (join p.address.city) // 2) an entity-join (join com.acme.User) // // so make the proper interpretation here... final EntityPersister entityJoinReferencedPersister = resolveEntityJoinReferencedPersister( path ); if ( entityJoinReferencedPersister != null ) { // `path` referenced an entity final EntityJoinFromElement join = createEntityJoin( entityJoinReferencedPersister, alias, joinType, propertyFetch, with ); ( (FromReferenceNode) path ).setFromElement( join ); } else { if ( path.getType() != SqlTokenTypes.DOT ) { throw new SemanticException( "Path expected for join!" ); } DotNode dot = (DotNode) path; JoinType hibernateJoinType = JoinProcessor.toHibernateJoinType( joinType ); dot.setJoinType( hibernateJoinType ); // Tell the dot node about the join type. dot.setFetch( fetch ); // Generate an explicit join for the root dot node. The implied joins will be collected and passed up // to the root dot node. dot.resolve( true, false, alias == null ? null : alias.getText() ); final FromElement fromElement; if ( dot.getDataType() != null && dot.getDataType().isComponentType() ) { if ( dot.getDataType().isAnyType() ) { throw new SemanticException( "An AnyType attribute cannot be join fetched" ); // ^^ because the discriminator (aka, the "meta columns") must be known to the SQL in // a non-parameterized way. } FromElementFactory factory = new FromElementFactory( getCurrentFromClause(), dot.getLhs().getFromElement(), dot.getPropertyPath(), alias == null ? null : alias.getText(), null, false ); fromElement = factory.createComponentJoin( (CompositeType) dot.getDataType() ); } else { fromElement = dot.getImpliedJoin(); fromElement.setAllPropertyFetch( propertyFetch != null ); if ( with != null ) { if ( fetch ) { throw new SemanticException( "with-clause not allowed on fetched associations; use filters" ); } handleWithFragment( fromElement, with ); } } if ( LOG.isDebugEnabled() ) { LOG.debug( "createFromJoinElement() : " + getASTPrinter().showAsString( fromElement, "-- join tree --" ) ); } } }
Example 15
Source File: ConstVisitor.java From cxf with Apache License 2.0 | 4 votes |
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); }
Example 16
Source File: HqlSqlWalker.java From lams with GNU General Public License v2.0 | 4 votes |
private String buildTraceNodeName(AST tree) { return tree == null ? "???" : tree.getText() + " [" + TokenPrinters.SQL_TOKEN_PRINTER.getTokenTypeName( tree.getType() ) + "]"; }
Example 17
Source File: SqlGenerator.java From lams with GNU General Public License v2.0 | 4 votes |
private String buildTraceNodeName(AST tree) { return tree == null ? "???" : tree.getText() + " [" + TokenPrinters.SQL_TOKEN_PRINTER.getTokenTypeName( tree.getType() ) + "]"; }
Example 18
Source File: DumpASTVisitor.java From dacapobench with Apache License 2.0 | 4 votes |
public void visit(AST node) { // Flatten this level of the tree if it has no children boolean flatten = /*true*/ false; AST node2; for (node2 = node; node2 != null; node2 = node2.getNextSibling()) { if (node2.getFirstChild() != null) { flatten = false; break; } } for (node2 = node; node2 != null; node2 = node2.getNextSibling()) { if (!flatten || node2 == node) { tabs(); } if (node2.getText() == null) { System.out.print("nil"); } else { System.out.print(node2.getText()); } System.out.print(" [" + node2.getType() + "] "); if (flatten) { System.out.print(" "); } else { System.out.println(""); } if (node2.getFirstChild() != null) { level++; visit(node2.getFirstChild()); level--; } } if (flatten) { System.out.println(""); } }
Example 19
Source File: OrderByFragmentRenderer.java From lams with GNU General Public License v2.0 | 4 votes |
private String buildTraceNodeName(AST tree) { return tree == null ? "???" : tree.getText() + " [" + TokenPrinters.ORDERBY_FRAGMENT_PRINTER.getTokenTypeName( tree.getType() ) + "]"; }
Example 20
Source File: FromClause.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Adds a new from element to the from node. * * @param path The reference to the class. * @param alias The alias AST. * * @return FromElement - The new FROM element. */ public FromElement addFromElement(String path, AST alias) throws SemanticException { // The path may be a reference to an alias defined in the parent query. String classAlias = ( alias == null ) ? null : alias.getText(); checkForDuplicateClassAlias( classAlias ); FromElementFactory factory = new FromElementFactory( this, null, path, classAlias, null, false ); return factory.addFromElement(); }