public String[] getParserProposals(ParsingResult result) { if (result.getExceptions() == null || result.getExceptions().size() == 0) { return EMPTY; } else { List list = new ArrayList(); //Exceptions may be more than one, so should get all exceptions. for (int i = 0; i < result.getExceptions().size(); i ++) { if (result.getExceptions().get(i) instanceof ParseException) { ParseException pe = (ParseException) result.getExceptions() .get(i); if (pe.expectedTokenSequences == null) { return EMPTY; } String[] proposals = new String[pe.expectedTokenSequences.length]; for (int j = 0; j < pe.expectedTokenSequences.length; j++) { StringBuffer sb = new StringBuffer(); sb.append(pe.tokenImage[pe.expectedTokenSequences[j][0]]); String expected = removeQuotes(sb.toString()); if (!list.contains(expected)) { list.add(expected); } } } } return (String[]) list.toArray(new String[list.size()]); } }
public void setOutlinePage(SQLOutlinePage outlinePage) { _fOutlinePage = outlinePage; if (_fOutlinePage != null && _result != null) { _fOutlinePage.setInput(_result.getRootNode()); } }
/** * Add a new table object into the current table list. * The new table object will not be added when isContentAssist is true for avoiding to be done repeatedly. * @param simpleNode the node's text which is the table name. * @param token the token's image which is the alias name of table. * @param isContentAssist true for content assist. * TODO revisit the necessity of isContentAssist * */ public void addCurrentTables(Node simpleNode, Token token, boolean isContentAssist) { if (!isContentAssist) { return; } if (simpleNode instanceof SimpleNode) { String tableName = ((SimpleNode) simpleNode).getText(); String aliasName = null; if (token != null && token.image != null) { aliasName = token.image; } addCurrentTables(tableName, aliasName, isContentAssist); } }
/** * Returns all the cursor names that can be used at the position indicated by offset. * @param document * @param offset * @param rootNode * @return all the cursor names that can be used at the position indicated by offset */ public ArrayList getCursorNames(IDocument document, int offset) { ArrayList cursors = new ArrayList(); SimpleNode context = (SimpleNode) findContainingDeployable(document, offset, _rootNode); if (context != null) { cursors = findCursorNames(document, offset, context); } return cursors; }
/** * Gets all the parameter definitions indexed by their names in the surrounding stored procedure * * @param document * @param offset * @return key: String; value: IASTSQLParam */ public HashMap getCursors(IDocument document, int offset) { HashMap map = new HashMap(); SimpleNode context = (SimpleNode) findContainingDeployable(document, offset, _rootNode); // only SP can have parameters if (context != null && context instanceof IASTDeployable) { map = findCursors(document, offset, context); } return map; }
/** * Gets all the variable definitions indexed by their names that can be used at the position indicated by offset * * @param document * @param offset * @return key: String; value: IASTSQLParam */ public HashMap getVariables(IDocument document, int offset) { HashMap map = new HashMap(); SimpleNode context = (SimpleNode) findContainingDeployable(document, offset, _rootNode); if (context != null) { map = findVariables(document, offset, context); } return map; }
ParsingResult result = parser.parse(sql, parserParameters); if (result.getExceptions() != null && !result.getExceptions().isEmpty()) IASTStart root = result.getRootNode(); root.setDocument(doc); String group = "";
if (result != null) variables = result.getVariables(document, offset); HashMap sp_params = result.getParameters(document, offset); variables.putAll(sp_params);
/** * Gets all the parameter definitions indexed by their names in the surrounding stored procedure * * @param document * @param offset * @return key: String; value: IASTSQLParam */ public HashMap getParameters(IDocument document, int offset) { HashMap map = new HashMap(); SimpleNode context = (SimpleNode) findContainingDeployable(document, offset, _rootNode); //only SP can have parameters if (context != null && context instanceof IASTDeployable) { map = findParameters(document, offset, (IASTDeployable) context); } return map; }
/** * Finds the node that offset belongs to, or return null if none is found. * * @param document * @param offset * @param rootNode the outmost node to search for * @param inclusive whether to include the trailing spaces * @return */ public static Node findNode(IDocument document, int offset, Node rootNode, boolean inclusive) { if (!contains(document, offset, rootNode, inclusive)) { return null; } //now we are sure the root contains offset SimpleNode root = (SimpleNode) rootNode; for (int i = root.jjtGetNumChildren() - 1; i >= 0; i--) { SimpleNode node = (SimpleNode) root.jjtGetChild(i); if (contains(document, offset, node, inclusive)) { return findNode(document, offset, node, inclusive); } } return root; }
/** * Parse the given sp definition and returns the parameter name/IASTSQLParam pairs. * * @param databaseIdentifier used to determine the db type * @param sp the sp definition * @return */ public static HashMap getSPParams(DatabaseIdentifier databaseIdentifier, String sp) { HashMap map = new HashMap(); SQLParser parser = SQLToolsFacade.getSQLParser(databaseIdentifier.getProfileName(), ""); IDocument doc = new Document(sp); ParsingResult result = parser.parse(sp, new ParserParameters(false)); HashMap params = result.getParameters(doc, doc.getLength() - 1); return params; }
/** * Finds the immediate containing compound statement, or return null * * @param document * @param offset * @return */ public Node findParentCompound(IDocument document, int offset, Node rootNode) { SimpleNode node = (SimpleNode) findNode(document, offset, rootNode, true); if (node == null) { return null; } while (!(node instanceof IASTStart || node instanceof IASTDeployable || (node instanceof IASTSQLStatement && "BEGIN" .equalsIgnoreCase(node.getFirstToken().image)))) { node = (SimpleNode) node.jjtGetParent(); } return node; }
_result = p.parse(content, parserParameters); _result.getRootNode().setEditorInput(_input); IDocument document = _editor.getDocumentProvider().getDocument(_input); _result.getRootNode().setDocument(document); _result.getRootNode().setAnnotationModel(_annotationModel); _editor.setParsingResult(_result); updatePortableAnnotation(presult.getExceptions()); ArrayList exceptions = _result.getExceptions(); updateErrorAnnotation(exceptions); _fOutlinePage.setInput(_result.getRootNode());
if (result != null) variables = result.getVariables(document, offset); HashMap sp_params = result.getParameters(document, offset); variables.putAll(sp_params);
public Node getPreviousNode() { this.getStartOffset(); Node previousNode = ParsingResult.findNode(getDocument(), this.getStartOffset(), getRootNode(), true ); return previousNode; }
/** * Updates the source by giving it a new name * @param newName should be quoted when necessary * @return */ public boolean updateName(String newName) { String body = getBody(); ParsingResult result = _parser.parse(body, _parserParameters); IASTStart root = result.getRootNode(); for (int i = 0; i < root.jjtGetNumChildren(); i++) { Node node = root.jjtGetChild(i); if (node instanceof IASTDeployable) { Node nameNode = ((IASTDeployable) node).getNameNode(); Token nameToken = nameNode.getLastToken(); int[] range = _parser.getRange(nameToken); body = body.substring(0, range[0]) + newName + body.substring(range[1]); setBody(body); return true; } } return false; }
ParsingResult result = _parser.parse(parseText + SQLParser.SPECIAL_TOKEN, pp); result.getRootNode().setDocument(doc);
_parsingResult.getRootNode().setDocument(getSV().getDocument()); _fSQLUpdater.setNeedToParse(false);