/** * @param sql * @param alterTableDef * @return * @throws SqlJetException */ private String getTableAlteredSql(String sql, SqlJetAlterTableDef alterTableDef) throws SqlJetException { final RuleReturnScope parsedSQL = parseTable(sql); final CommonTree ast = (CommonTree) parsedSQL.getTree(); final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(1)).getToken(); final CharStream inputStream = nameToken.getInputStream(); final CommonToken stopToken = (CommonToken) parsedSQL.getStop(); final StringBuilder b = new StringBuilder(); if (alterTableDef.getNewTableName() != null) { b.append(inputStream.substring(0, nameToken.getStartIndex() - 1)); b.append(getAlterTableName(alterTableDef)); b.append(inputStream.substring(nameToken.getStopIndex() + 1, stopToken.getStopIndex())); } else if (alterTableDef.getNewColumnDef() != null) { b.append(inputStream.substring(0, stopToken.getStartIndex() - 1)); b.append(",").append(getAlterTableName(alterTableDef)); b.append(inputStream.substring(stopToken.getStartIndex(), stopToken.getStopIndex())); } else { throw new SqlJetException("Wrong ALTER TABLE statement"); } return b.toString(); }
/** * @param sql * @param alterTableName * @return * @throws SqlJetException */ private String getAlteredIndexSql(String sql, String alterTableName) throws SqlJetException { final RuleReturnScope parsedSQL = parseIndex(sql); final CommonTree ast = (CommonTree) parsedSQL.getTree(); final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(2)).getToken(); final CharStream inputStream = nameToken.getInputStream(); final CommonToken stopToken = (CommonToken) parsedSQL.getStop(); final StringBuilder b = new StringBuilder(); b.append(inputStream.substring(0, nameToken.getStartIndex() - 1)); b.append(alterTableName); b.append(inputStream.substring(nameToken.getStopIndex() + 1, stopToken.getStopIndex())); return b.toString(); }
private String getCoreSQL(RuleReturnScope parsedSQL) { final CommonTree ast = (CommonTree) parsedSQL.getTree(); final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(1)).getToken(); final CharStream inputStream = nameToken.getInputStream(); final CommonToken stopToken = (CommonToken) parsedSQL.getStop(); return inputStream.substring(nameToken.getStartIndex(), stopToken.getStopIndex()); }
/** * @param alterTableDef * @return */ private String getAlterTableName(SqlJetAlterTableDef alterTableDef) { final ParserRuleReturnScope parsedSql = alterTableDef.getParsedSql(); final CommonTree ast = (CommonTree) parsedSql.getTree(); final CommonToken stopToken = (CommonToken) parsedSql.getStop(); final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(ast.getChildCount() - 1)).getToken(); final CharStream inputStream = nameToken.getInputStream(); return inputStream.substring(nameToken.getStartIndex(), stopToken.getStopIndex()); }
private CommonToken getPreviousNonHiddenToken(int offset) { int index = getTokenIndexAtCharacter(tokens, offset); if (index < 0) index = -index; for (; index >= 0; index--) { CommonToken token = getTokens().get(index); if (token.getChannel() != HIDDEN_CHANNEL && token.getStopIndex() < offset) { return token; } } return null; }
private int count(String token, int startIndex, int stopIndex) { int count = 0; List<CommonToken> tokens = getTokens(); for (CommonToken tok : tokens) { if (tok.getStartIndex() >= startIndex && tok.getStopIndex() < stopIndex && tok.getText().equals(token)) { count++; } } return count; }
/** Called 3rd */ @Override public void apply( @NotNull PsiFile file, List<ANTLRv4ExternalAnnotator.Issue> issues, @NotNull AnnotationHolder holder) { for (int i = 0; i < issues.size(); i++) { Issue issue = issues.get(i); for (int j = 0; j < issue.offendingTokens.size(); j++) { Token t = issue.offendingTokens.get(j); if (t instanceof CommonToken) { CommonToken ct = (CommonToken) t; int startIndex = ct.getStartIndex(); int stopIndex = ct.getStopIndex(); TextRange range = new TextRange(startIndex, stopIndex + 1); ErrorSeverity severity = ErrorSeverity.INFO; if (issue.msg.getErrorType() != null) { severity = issue.msg.getErrorType().severity; } switch (severity) { case ERROR: case ERROR_ONE_OFF: case FATAL: holder.createErrorAnnotation(range, issue.annotation); break; case WARNING: holder.createWarningAnnotation(range, issue.annotation); break; case WARNING_ONE_OFF: case INFO: holder.createWeakWarningAnnotation(range, issue.annotation); default: break; } } } } super.apply(file, issues, holder); }
private void adjustStringOrCommentIndentation() throws BadLocationException { CommonToken tok = getTokenStrictlyContainingOffset(getEndOfCurrentLine()); if (tok != null) { int len = command.length; String text = command.text; if (isQuoteOrCommentToken(tok.getType()) && text != null && text.length() < len) { // reduced indent of a quoted or commented token String indent = document.get(command.offset, len); int line = document.getLineOfOffset(tok.getStartIndex()) + 1; int lastLine = document.getLineOfOffset(tok.getStopIndex()); while (line <= lastLine) { int offset = document.getLineOffset(line); if (document.get(offset, len).equals(indent)) { document.replace(offset, len, text); } line++; } } } }
private int end() { final CommonToken t = (CommonToken) input.LT(-1); if (t == null) return -1; return t.getStopIndex() + 1; }