Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
e3077f12
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e3077f12
编写于
6月 19, 2018
作者:
S
serge-rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#3579 SQL indent fix (use preferences in default indenter)
Former-commit-id:
75eb042f
上级
6ab69e67
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
40 addition
and
53 deletion
+40
-53
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/indent/SQLCommentAutoIndentStrategy.java
...r/ui/editors/sql/indent/SQLCommentAutoIndentStrategy.java
+5
-13
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/indent/SQLIndenter.java
.../org/jkiss/dbeaver/ui/editors/sql/indent/SQLIndenter.java
+34
-39
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLSyntaxManager.java
...del/src/org/jkiss/dbeaver/model/sql/SQLSyntaxManager.java
+1
-1
未找到文件。
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/indent/SQLCommentAutoIndentStrategy.java
浏览文件 @
e3077f12
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
org.jkiss.dbeaver.ui.editors.sql.indent
;
package
org.jkiss.dbeaver.ui.editors.sql.indent
;
import
org.eclipse.jface.text.*
;
import
org.eclipse.jface.text.*
;
import
org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants
;
import
org.jkiss.dbeaver.core.DBeaverCore
;
import
org.jkiss.dbeaver.core.DBeaverCore
;
import
org.jkiss.dbeaver.model.preferences.DBPPreferenceStore
;
import
org.jkiss.dbeaver.model.preferences.DBPPreferenceStore
;
import
org.jkiss.dbeaver.ui.editors.sql.SQLPreferenceConstants
;
import
org.jkiss.dbeaver.ui.editors.sql.SQLPreferenceConstants
;
...
@@ -30,9 +31,6 @@ import java.text.BreakIterator;
...
@@ -30,9 +31,6 @@ import java.text.BreakIterator;
*/
*/
public
class
SQLCommentAutoIndentStrategy
extends
DefaultIndentLineAutoEditStrategy
{
public
class
SQLCommentAutoIndentStrategy
extends
DefaultIndentLineAutoEditStrategy
{
private
static
final
int
DEFAULT_MARGIN
=
5
;
private
static
final
int
DEFAULT_TAB_WIDTH
=
4
;
private
String
partitioning
;
private
String
partitioning
;
/**
/**
...
@@ -157,12 +155,7 @@ public class SQLCommentAutoIndentStrategy extends DefaultIndentLineAutoEditStrat
...
@@ -157,12 +155,7 @@ public class SQLCommentAutoIndentStrategy extends DefaultIndentLineAutoEditStrat
}
}
String
comment
=
document
.
get
(
partition
.
getOffset
(),
partition
.
getLength
());
String
comment
=
document
.
get
(
partition
.
getOffset
(),
partition
.
getLength
());
if
(
comment
.
indexOf
(
"/*"
,
2
)
!=
-
1
)
//$NON-NLS-1$
return
comment
.
indexOf
(
"/*"
,
2
)
!=
-
1
;
{
return
true
;
// enclosed another comment -> probably a new comment
}
return
false
;
}
}
catch
(
BadLocationException
e
)
{
catch
(
BadLocationException
e
)
{
...
@@ -550,9 +543,8 @@ public class SQLCommentAutoIndentStrategy extends DefaultIndentLineAutoEditStrat
...
@@ -550,9 +543,8 @@ public class SQLCommentAutoIndentStrategy extends DefaultIndentLineAutoEditStrat
private
static
int
calculateDisplayedWidth
(
String
string
)
private
static
int
calculateDisplayedWidth
(
String
string
)
{
{
final
int
tabWidth
=
DEFAULT_TAB_WIDTH
;
final
int
tabWidth
=
getPreferenceStore
().
getInt
(
/*getPreferenceStore().getInt(
AbstractDecoratedTextEditorPreferenceConstants
.
EDITOR_TAB_WIDTH
);
AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);*/
int
column
=
0
;
int
column
=
0
;
for
(
int
i
=
0
;
i
<
string
.
length
();
i
++)
{
for
(
int
i
=
0
;
i
<
string
.
length
();
i
++)
{
...
@@ -630,7 +622,7 @@ public class SQLCommentAutoIndentStrategy extends DefaultIndentLineAutoEditStrat
...
@@ -630,7 +622,7 @@ public class SQLCommentAutoIndentStrategy extends DefaultIndentLineAutoEditStrat
private
static
int
getMargin
()
private
static
int
getMargin
()
{
{
return
DEFAULT_MARGIN
;
//
getPreferenceStore().getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN);
return
getPreferenceStore
().
getInt
(
AbstractDecoratedTextEditorPreferenceConstants
.
EDITOR_PRINT_MARGIN_COLUMN
);
}
}
/**
/**
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/indent/SQLIndenter.java
浏览文件 @
e3077f12
...
@@ -17,9 +17,12 @@
...
@@ -17,9 +17,12 @@
package
org.jkiss.dbeaver.ui.editors.sql.indent
;
package
org.jkiss.dbeaver.ui.editors.sql.indent
;
import
org.eclipse.jface.preference.IPreferenceStore
;
import
org.eclipse.jface.text.BadLocationException
;
import
org.eclipse.jface.text.BadLocationException
;
import
org.eclipse.jface.text.IDocument
;
import
org.eclipse.jface.text.IDocument
;
import
org.eclipse.jface.text.IRegion
;
import
org.eclipse.jface.text.IRegion
;
import
org.eclipse.ui.internal.editors.text.EditorsPlugin
;
import
org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants
;
public
class
SQLIndenter
{
public
class
SQLIndenter
{
...
@@ -55,10 +58,7 @@ public class SQLIndenter {
...
@@ -55,10 +58,7 @@ public class SQLIndenter {
* @param scanner the {@link SQLHeuristicScanner}to be used for scanning the document. It must be installed on the
* @param scanner the {@link SQLHeuristicScanner}to be used for scanning the document. It must be installed on the
* same <code>IDocument</code>.
* same <code>IDocument</code>.
*/
*/
public
SQLIndenter
(
IDocument
document
,
SQLHeuristicScanner
scanner
)
public
SQLIndenter
(
IDocument
document
,
SQLHeuristicScanner
scanner
)
{
{
assert
(
document
!=
null
);
assert
(
scanner
!=
null
);
this
.
document
=
document
;
this
.
document
=
document
;
this
.
scanner
=
scanner
;
this
.
scanner
=
scanner
;
}
}
...
@@ -68,10 +68,9 @@ public class SQLIndenter {
...
@@ -68,10 +68,9 @@ public class SQLIndenter {
*
*
* @param offset the offset in the document
* @param offset the offset in the document
* @return a String which reflects the indentation at the line in which the reference position to
* @return a String which reflects the indentation at the line in which the reference position to
*
<code>offset</code> resides, or <code>null</code> if it cannot be determined
* <code>offset</code> resides, or <code>null</code> if it cannot be determined
*/
*/
public
String
getReferenceIndentation
(
int
offset
)
public
String
getReferenceIndentation
(
int
offset
)
{
{
int
unit
;
int
unit
;
unit
=
findReferencePosition
(
offset
);
unit
=
findReferencePosition
(
offset
);
// if we were unable to find anything, return null
// if we were unable to find anything, return null
...
@@ -87,10 +86,9 @@ public class SQLIndenter {
...
@@ -87,10 +86,9 @@ public class SQLIndenter {
*
*
* @param offset the offset in the document
* @param offset the offset in the document
* @return a String which reflects the correct indentation for the line in which offset resides, or
* @return a String which reflects the correct indentation for the line in which offset resides, or
*
<code>null</code> if it cannot be determined
* <code>null</code> if it cannot be determined
*/
*/
public
String
computeIndentation
(
int
offset
)
public
String
computeIndentation
(
int
offset
)
{
{
return
computeIndentation
(
offset
,
false
);
return
computeIndentation
(
offset
,
false
);
}
}
...
@@ -101,10 +99,9 @@ public class SQLIndenter {
...
@@ -101,10 +99,9 @@ public class SQLIndenter {
* @param offset the offset in the document
* @param offset the offset in the document
* @param assumeOpening <code>true</code> if an opening statement should be assumed
* @param assumeOpening <code>true</code> if an opening statement should be assumed
* @return a String which reflects the correct indentation for the line in which offset resides, or
* @return a String which reflects the correct indentation for the line in which offset resides, or
*
<code>null</code> if it cannot be determined
* <code>null</code> if it cannot be determined
*/
*/
public
String
computeIndentation
(
int
offset
,
boolean
assumeOpening
)
public
String
computeIndentation
(
int
offset
,
boolean
assumeOpening
)
{
{
indent
=
1
;
indent
=
1
;
...
@@ -132,8 +129,7 @@ public class SQLIndenter {
...
@@ -132,8 +129,7 @@ public class SQLIndenter {
* @param offset the offset in the document
* @param offset the offset in the document
* @return the indentation (leading whitespace) of the line in which <code>offset</code> is located
* @return the indentation (leading whitespace) of the line in which <code>offset</code> is located
*/
*/
private
String
getLeadingWhitespace
(
int
offset
)
private
String
getLeadingWhitespace
(
int
offset
)
{
{
try
{
try
{
IRegion
line
=
document
.
getLineInformationOfOffset
(
offset
);
IRegion
line
=
document
.
getLineInformationOfOffset
(
offset
);
int
lineOffset
=
line
.
getOffset
();
int
lineOffset
=
line
.
getOffset
();
...
@@ -148,8 +144,7 @@ public class SQLIndenter {
...
@@ -148,8 +144,7 @@ public class SQLIndenter {
}
}
return
document
.
get
(
lineOffset
,
nonWS
-
lineOffset
);
return
document
.
get
(
lineOffset
,
nonWS
-
lineOffset
);
}
}
catch
(
BadLocationException
e
)
{
catch
(
BadLocationException
e
)
{
// _log.debug(EditorMessages.error_badLocationException, e);
// _log.debug(EditorMessages.error_badLocationException, e);
return
""
;
return
""
;
}
}
...
@@ -160,8 +155,7 @@ public class SQLIndenter {
...
@@ -160,8 +155,7 @@ public class SQLIndenter {
*
*
* @param indent the indentation to be modified
* @param indent the indentation to be modified
*/
*/
private
void
unindent
(
StringBuilder
indent
)
private
void
unindent
(
StringBuilder
indent
)
{
{
CharSequence
oneIndent
=
createIndent
();
CharSequence
oneIndent
=
createIndent
();
int
i
=
indent
.
lastIndexOf
(
oneIndent
.
toString
());
//$NON-NLS-1$
int
i
=
indent
.
lastIndexOf
(
oneIndent
.
toString
());
//$NON-NLS-1$
if
(
i
!=
-
1
)
{
if
(
i
!=
-
1
)
{
...
@@ -175,8 +169,7 @@ public class SQLIndenter {
...
@@ -175,8 +169,7 @@ public class SQLIndenter {
* @param indent the requested indentation level.
* @param indent the requested indentation level.
* @return the indentation specified by <code>indent</code>
* @return the indentation specified by <code>indent</code>
*/
*/
private
StringBuilder
createIndent
(
int
indent
)
private
StringBuilder
createIndent
(
int
indent
)
{
{
StringBuilder
oneIndent
=
createIndent
();
StringBuilder
oneIndent
=
createIndent
();
StringBuilder
ret
=
new
StringBuilder
();
StringBuilder
ret
=
new
StringBuilder
();
...
@@ -192,11 +185,19 @@ public class SQLIndenter {
...
@@ -192,11 +185,19 @@ public class SQLIndenter {
*
*
* @return one indentation
* @return one indentation
*/
*/
private
StringBuilder
createIndent
()
private
StringBuilder
createIndent
()
{
{
IPreferenceStore
preferenceStore
=
EditorsPlugin
.
getDefault
().
getPreferenceStore
();
// get a sensible default when running without the infrastructure for testing
boolean
useSpaces
=
preferenceStore
.
getBoolean
(
AbstractDecoratedTextEditorPreferenceConstants
.
EDITOR_SPACES_FOR_TABS
);
StringBuilder
oneIndent
=
new
StringBuilder
();
StringBuilder
oneIndent
=
new
StringBuilder
();
oneIndent
.
append
(
'\t'
);
if
(!
useSpaces
)
{
oneIndent
.
append
(
'\t'
);
}
else
{
int
tabWidth
=
preferenceStore
.
getInt
(
AbstractDecoratedTextEditorPreferenceConstants
.
EDITOR_TAB_WIDTH
);
for
(
int
i
=
0
;
i
<
tabWidth
;
i
++)
{
oneIndent
.
append
(
' '
);
}
}
return
oneIndent
;
return
oneIndent
;
}
}
...
@@ -205,10 +206,9 @@ public class SQLIndenter {
...
@@ -205,10 +206,9 @@ public class SQLIndenter {
*
*
* @param offset the offset for which the reference is computed
* @param offset the offset for which the reference is computed
* @return the reference statement relative to which <code>offset</code> should be indented, or
* @return the reference statement relative to which <code>offset</code> should be indented, or
*
{@link SQLHeuristicScanner#NOT_FOUND}
* {@link SQLHeuristicScanner#NOT_FOUND}
*/
*/
public
int
findReferencePosition
(
int
offset
)
public
int
findReferencePosition
(
int
offset
)
{
{
indent
=
0
;
// the indentation modification
indent
=
0
;
// the indentation modification
position
=
offset
;
position
=
offset
;
nextToken
();
nextToken
();
...
@@ -222,10 +222,9 @@ public class SQLIndenter {
...
@@ -222,10 +222,9 @@ public class SQLIndenter {
* or simply increase the indentation by a number of standard indents.
* or simply increase the indentation by a number of standard indents.
*
*
* @return the reference position for a list item: either a previous list item that has its own indentation, or the
* @return the reference position for a list item: either a previous list item that has its own indentation, or the
*
list introduction start.
* list introduction start.
*/
*/
private
int
skipToPreviousListItemOrListStart
()
private
int
skipToPreviousListItemOrListStart
()
{
{
int
startLine
=
line
;
int
startLine
=
line
;
int
startPosition
=
position
;
int
startPosition
=
position
;
while
(
true
)
{
while
(
true
)
{
...
@@ -237,8 +236,7 @@ public class SQLIndenter {
...
@@ -237,8 +236,7 @@ public class SQLIndenter {
int
lineOffset
=
document
.
getLineOffset
(
startLine
);
int
lineOffset
=
document
.
getLineOffset
(
startLine
);
int
bound
=
Math
.
min
(
document
.
getLength
(),
startPosition
+
1
);
int
bound
=
Math
.
min
(
document
.
getLength
(),
startPosition
+
1
);
int
align
=
scanner
.
findNonWhitespaceForwardInAnyPartition
(
lineOffset
,
bound
);
int
align
=
scanner
.
findNonWhitespaceForwardInAnyPartition
(
lineOffset
,
bound
);
}
}
catch
(
BadLocationException
e
)
{
catch
(
BadLocationException
e
)
{
// _log.debug(EditorMessages.error_badLocationException, e);
// _log.debug(EditorMessages.error_badLocationException, e);
// ignore and return just the position
// ignore and return just the position
}
}
...
@@ -257,19 +255,16 @@ public class SQLIndenter {
...
@@ -257,19 +255,16 @@ public class SQLIndenter {
* Reads the next token in backward direction from the heuristic scanner and sets the fields
* Reads the next token in backward direction from the heuristic scanner and sets the fields
* <code>fToken, fPreviousPosition</code> and <code>fPosition</code> accordingly.
* <code>fToken, fPreviousPosition</code> and <code>fPosition</code> accordingly.
*/
*/
private
void
nextToken
()
private
void
nextToken
()
{
{
nextToken
(
position
);
nextToken
(
position
);
}
}
public
void
nextToken
(
int
start
)
public
void
nextToken
(
int
start
)
{
{
token
=
scanner
.
previousToken
(
start
-
1
,
SQLHeuristicScanner
.
UNBOUND
);
token
=
scanner
.
previousToken
(
start
-
1
,
SQLHeuristicScanner
.
UNBOUND
);
position
=
scanner
.
getPosition
()
+
1
;
position
=
scanner
.
getPosition
()
+
1
;
try
{
try
{
line
=
document
.
getLineOfOffset
(
position
);
line
=
document
.
getLineOfOffset
(
position
);
}
}
catch
(
BadLocationException
e
)
{
catch
(
BadLocationException
e
)
{
line
=
-
1
;
line
=
-
1
;
}
}
}
}
...
...
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLSyntaxManager.java
浏览文件 @
e3077f12
...
@@ -138,7 +138,7 @@ public class SQLSyntaxManager {
...
@@ -138,7 +138,7 @@ public class SQLSyntaxManager {
this
.
quoteStrings
=
sqlDialect
.
getIdentifierQuoteStrings
();
this
.
quoteStrings
=
sqlDialect
.
getIdentifierQuoteStrings
();
this
.
structSeparator
=
sqlDialect
.
getStructSeparator
();
this
.
structSeparator
=
sqlDialect
.
getStructSeparator
();
this
.
catalogSeparator
=
sqlDialect
.
getCatalogSeparator
();
this
.
catalogSeparator
=
sqlDialect
.
getCatalogSeparator
();
this
.
escapeChar
=
dialect
.
getStringEscapeCharacter
();
;
this
.
escapeChar
=
dialect
.
getStringEscapeCharacter
();
if
(!
preferenceStore
.
getBoolean
(
ModelPreferences
.
SCRIPT_IGNORE_NATIVE_DELIMITER
))
{
if
(!
preferenceStore
.
getBoolean
(
ModelPreferences
.
SCRIPT_IGNORE_NATIVE_DELIMITER
))
{
this
.
statementDelimiters
=
new
String
[]
{
sqlDialect
.
getScriptDelimiter
().
toLowerCase
()
};
this
.
statementDelimiters
=
new
String
[]
{
sqlDialect
.
getScriptDelimiter
().
toLowerCase
()
};
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录