/** * Returns the deepest {@link Expression} for the given position. * * @param actualQuery The actual query is the text version of the query that may contain extra * whitespace and different formatting than the trim down version generated by the parsed tree * @param position The position in the actual query used to retrieve the {@link Expression} * @return The {@link Expression} located at the given position in the given query */ public Expression getExpression(String actualQuery, int position) { QueryPosition queryPosition = buildPosition(actualQuery, position); return queryPosition.getExpression(); }
/** * Returns the deepest {@link Expression} for the given position. * * @param actualQuery The actual query is the text version of the query that may contain extra * whitespace and different formatting than the trim down version generated by the parsed tree * @param position The position in the actual query used to retrieve the {@link Expression} * @return The {@link Expression} located at the given position in the given query */ public Expression getExpression(String actualQuery, int position) { QueryPosition queryPosition = buildPosition(actualQuery, position); return queryPosition.getExpression(); }
/** * Prepares this visitor by prepopulating it with the necessary data that is required to properly * gather the list of proposals based on the given caret position. * * @param position The position of the cursor within the JPQL query * @param extension This extension can be used to provide additional support to JPQL content assist * that is outside the scope of providing proposals related to JPA metadata. It adds support for * providing suggestions related to class names, enum constants, table names, column names * @return The proposals that are valid choices for the given position */ public ContentAssistProposals buildProposals(int position, ContentAssistExtension extension) { try { JPQLExpression jpqlExpression = queryContext.getJPQLExpression(); String jpqlQuery = queryContext.getJPQLQuery(); // Calculate the position of the cursor within the parsed tree queryPosition = jpqlExpression.buildPosition(jpqlQuery, position); // Retrieve the word from the JPQL query (which is the text before the position of the cursor) wordParser = new WordParser(jpqlQuery); wordParser.setPosition(position); word = wordParser.partialWord(); // Now visit the deepest leaf first and calculate the possible proposals proposals = new DefaultContentAssistProposals(queryContext.getGrammar(), extension); queryPosition.getExpression().accept(this); return proposals; } finally { dispose(); } }