提交 a7d096ee 编写于 作者: S Serge Rider

#7494 Text parser base model. SQL dialect registry

上级 b97a5a8f
......@@ -18,7 +18,8 @@ Export-Package: org.jkiss.dbeaver.model.sql,
org.jkiss.dbeaver.model.sql.format.tokenized,
org.jkiss.dbeaver.model.sql.parser,
org.jkiss.dbeaver.model.sql.registry,
org.jkiss.dbeaver.model.text
org.jkiss.dbeaver.model.text,
org.jkiss.dbeaver.model.text.parser
Bundle-ClassPath: .
Require-Bundle: org.eclipse.equinox.security,
org.eclipse.core.runtime,
......
......@@ -4,6 +4,7 @@
<plugin>
<extension-point id="org.jkiss.dbeaver.sqlFormatter" name="%extension-point.org.jkiss.dbeaver.sqlFormatter.name" schema="schema/org.jkiss.dbeaver.sqlFormatter.exsd"/>
<extension-point id="org.jkiss.dbeaver.sqlCommand" name="%extension-point.org.jkiss.dbeaver.sqlCommand.name" schema="schema/org.jkiss.dbeaver.sqlCommand.exsd"/>
<extension-point id="org.jkiss.dbeaver.sqlDialect" name="%extension-point.org.jkiss.dbeaver.sqlCommand.name" schema="schema/org.jkiss.dbeaver.sqlDialect.exsd"/>
<extension point="org.eclipse.core.runtime.preferences">
<initializer class="org.jkiss.dbeaver.model.sql.internal.SQLModelPreferencesInitializer"/>
......@@ -23,4 +24,17 @@
<command id="export" class="org.jkiss.dbeaver.model.sql.commands.SQLCommandExport" label="Export resultset" description="Export results of the next query. Launches data transfer process."/>
</extension>
<extension point="org.jkiss.dbeaver.sqlDialect">
<dialect id="basic" class=" org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect" label="Base SQL Dialect" description="Base SQL dialect for all other dialects.">
<keywords value=""/>
<execKeywords value=""/>
<ddlKeywords value="CREATE,ALTER,DROP"/>
<dmlKeywords value="INSERT,DELETE,UPDATE,UPSERT,MERGE,TRUNCATE"/>
<functions value=""/>
<types value=""/>
<property name="" value=""/>
</dialect>
</extension>
</plugin>
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.jkiss.dbeaver.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.jkiss.dbeaver.core" id="org.jkiss.dbeaver.sqlDialect" name="SQL Formatter"/>
</appInfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence>
<element ref="dialect" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="dialect">
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
</sequence>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="identifier"/>
</appInfo>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.jkiss.dbeaver.model.data.DBDDataFormatter"/>
</appInfo>
</annotation>
</attribute>
<attribute name="configurerClass" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.jkiss.dbeaver.model.data.DBDDataFormatter"/>
</appInfo>
</annotation>
</attribute>
<attribute name="label" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
<attribute name="description" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.sql.registry;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.model.impl.AbstractContextDescriptor;
import org.jkiss.dbeaver.model.sql.SQLDialect;
/**
* SQLDialectDescriptor
*/
public class SQLDialectDescriptor extends AbstractContextDescriptor {
public static final String EXTENSION_ID = "org.jkiss.dbeaver.sqlDialect"; //$NON-NLS-1$
private final String id;
private final String label;
private final String description;
private final ObjectType implClass;
private final DBPImage icon;
SQLDialectDescriptor(IConfigurationElement config) {
super(config);
this.id = config.getAttribute("id");
this.label = config.getAttribute("label");
this.description = config.getAttribute("description");
this.implClass = new ObjectType(config.getAttribute("class"));
this.icon = iconToImage(config.getAttribute("icon"));
}
public String getId() {
return id;
}
public String getLabel() {
return label;
}
public String getDescription() {
return description;
}
public DBPImage getIcon() {
return icon;
}
public SQLDialect createInstance() throws DBException {
return implClass.createInstance(SQLDialect.class);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.sql.registry;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class SQLDialectRegistry
{
static final String TAG_DIALECT = "dialect"; //$NON-NLS-1$
private static SQLDialectRegistry instance = null;
public synchronized static SQLDialectRegistry getInstance()
{
if (instance == null) {
instance = new SQLDialectRegistry();
instance.loadExtensions(Platform.getExtensionRegistry());
}
return instance;
}
private final Map<String, SQLDialectDescriptor> dialects = new LinkedHashMap<>();
private SQLDialectRegistry()
{
}
private void loadExtensions(IExtensionRegistry registry)
{
IConfigurationElement[] extConfigs = registry.getConfigurationElementsFor(SQLCommandHandlerDescriptor.EXTENSION_ID);
for (IConfigurationElement ext : extConfigs) {
// Load functions
if (TAG_DIALECT.equals(ext.getName())) {
SQLDialectDescriptor commandDescriptor = new SQLDialectDescriptor(ext);
this.dialects.put(commandDescriptor.getId(), commandDescriptor);
}
}
}
public void dispose()
{
dialects.clear();
}
public List<SQLDialectDescriptor> getDialects() {
return new ArrayList<>(dialects.values());
}
public SQLDialectDescriptor getDialect(String id) {
return dialects.get(id);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.text.parser;
/**
* Replica of ICharacterScanner but without jface/swt
*/
public interface TPCharacterScanner {
/**
* The value returned when this scanner has read EOF.
*/
int EOF= -1;
/**
* Provides rules access to the legal line delimiters. The returned
* object may not be modified by clients.
*
* @return the legal line delimiters
*/
char[][] getLegalLineDelimiters();
/**
* Returns the column of the character scanner.
*
* @return the column of the character scanner
*/
int getColumn();
/**
* Returns the next character or EOF if end of file has been reached
*
* @return the next character or EOF
*/
int read();
/**
* Rewinds the scanner before the last read character.
*/
void unread();
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.text.parser;
/**
* Replicate of IPredicateRule
*/
public interface TPPredicateRule extends TPRule {
TPToken getSuccessToken();
TPToken evaluate(TPCharacterScanner scanner, boolean resume);
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.text.parser;
/**
* Simple rule
*/
public interface TPRule {
/**
* Evaluates the rule by examining the characters available from the provided character scanner.
* The token returned by this rule returns <code>true</code> when calling
* <code>isUndefined</code>, if the text that the rule investigated does not match the rule's
* requirements
*
* @param scanner the character scanner to be used by this rule
* @return the token computed by the rule
*/
TPToken evaluate(TPCharacterScanner scanner);
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.text.parser;
/**
* A token to be returned by a rule.
*/
public interface TPToken {
/**
* Return whether this token is undefined.
*
* @return <code>true</code>if this token is undefined
*/
boolean isUndefined();
/**
* Return whether this token represents a whitespace.
*
* @return <code>true</code>if this token represents a whitespace
*/
boolean isWhitespace();
/**
* Return whether this token represents End Of File.
*
* @return <code>true</code>if this token represents EOF
*/
boolean isEOF();
/**
* Return whether this token is neither undefined, nor whitespace, nor EOF.
*
* @return <code>true</code>if this token is not undefined, not a whitespace, and not EOF
*/
boolean isOther();
/**
* Return a data attached to this token. The semantics of this data kept undefined by this interface.
*
* @return the data attached to this token.
*/
Object getData();
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.text.parser;
/**
* Standard implementation of <code>TPToken</code>.
*/
public class TPTokenAbstract<DATA> implements TPToken {
private static final int T_UNDEFINED = 0;
private static final int T_EOF = 1;
private static final int T_WHITESPACE = 2;
private static final int T_OTHER = 3;
public static final TPToken UNDEFINED = new TPTokenAbstract(T_UNDEFINED);
public static final TPToken EOF = new TPTokenAbstract(T_EOF);
public static final TPToken WHITESPACE = new TPTokenAbstract(T_WHITESPACE);
/**
* The type of this token
*/
private int type;
private DATA data;
private TPTokenAbstract(int type) {
this.type = type;
}
/**
* Creates a new token according to the given specification which does not
* have any data attached to it.
*/
protected TPTokenAbstract(int type, DATA data) {
this.type = type;
}
@Override
public DATA getData() {
return data;
}
@Override
public boolean isOther() {
return (type == T_OTHER);
}
@Override
public boolean isEOF() {
return (type == T_EOF);
}
@Override
public boolean isWhitespace() {
return (type == T_WHITESPACE);
}
@Override
public boolean isUndefined() {
return (type == T_UNDEFINED);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.text.parser;
/**
* Token for main scanner
*/
public class TPTokenDefault extends TPTokenAbstract<TPTokenType> {
/**
* Token for main parser. Data is token type, depends on parser but usually refers to some colored type.
*/
protected TPTokenDefault(TPTokenType type) {
super(type.getTokenType(), type);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.text.parser;
/**
* Token for partition scanner
*/
public class TPTokenPartition extends TPTokenAbstract<String> {
/**
* Token for partition parser. Data is content type.
*/
protected TPTokenPartition(int type, String contentType) {
super(type, contentType);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.text.parser;
/**
* A token type
*/
public interface TPTokenType {
/**
* See TPTokenAbstract.T_ constants
*/
int getTokenType();
/**
* Usually some color ID associated with this type
*/
String getTypeId();
}
......@@ -235,7 +235,7 @@ public class BasicSQLDialect implements SQLDialect {
@NotNull
@Override
public String getSearchStringEscape() {
return null;
return "";
}
@Override
......
......@@ -25,6 +25,7 @@ import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.sql.SQLConstants;
import org.jkiss.dbeaver.model.sql.SQLDialect;
import org.jkiss.dbeaver.model.sql.parser.SQLParserPartitions;
import org.jkiss.dbeaver.model.text.parser.TPCharacterScanner;
import org.jkiss.dbeaver.runtime.sql.SQLRuleProvider;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.ArrayUtils;
......@@ -40,7 +41,7 @@ import java.util.List;
* changed. The document partitions are based on tokens that represent comments
* and SQL code sections.
*/
public class SQLPartitionScanner extends RuleBasedPartitionScanner {
public class SQLPartitionScanner extends RuleBasedPartitionScanner implements TPCharacterScanner {
private final DBPDataSource dataSource;
// Syntax highlight
......
......@@ -36,6 +36,7 @@ import org.jkiss.dbeaver.model.sql.SQLSyntaxManager;
import org.jkiss.dbeaver.model.sql.parser.SQLWordDetector;
import org.jkiss.dbeaver.model.sql.registry.SQLCommandHandlerDescriptor;
import org.jkiss.dbeaver.model.sql.registry.SQLCommandsRegistry;
import org.jkiss.dbeaver.model.text.parser.TPCharacterScanner;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.runtime.sql.SQLRuleProvider;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase;
......@@ -52,11 +53,11 @@ import java.util.*;
/**
* SQLSyntaxManager.
* <p/>
*
* Contains information about some concrete datasource underlying database syntax.
* Support runtime change of datasource (reloads syntax information)
*/
public class SQLRuleManager extends RuleBasedScanner {
public class SQLRuleManager extends RuleBasedScanner implements TPCharacterScanner {
@NotNull
private final IThemeManager themeManager;
......@@ -69,8 +70,7 @@ public class SQLRuleManager extends RuleBasedScanner {
private boolean evalMode;
public SQLRuleManager(@NotNull SQLSyntaxManager syntaxManager)
{
public SQLRuleManager(@NotNull SQLSyntaxManager syntaxManager) {
this.syntaxManager = syntaxManager;
this.themeManager = PlatformUI.getWorkbench().getThemeManager();
}
......@@ -94,19 +94,16 @@ public class SQLRuleManager extends RuleBasedScanner {
}
}
public void dispose()
{
public void dispose() {
}
@NotNull
public Collection<? extends Position> getPositions(int offset, int length)
{
public Collection<? extends Position> getPositions(int offset, int length) {
return positions.subMap(offset, offset + length).values();
}
@NotNull
public synchronized Set<SQLScriptPosition> getRemovedPositions(boolean clear)
{
public synchronized Set<SQLScriptPosition> getRemovedPositions(boolean clear) {
Set<SQLScriptPosition> posList = removedPositions;
if (clear) {
removedPositions = new HashSet<>();
......@@ -115,8 +112,7 @@ public class SQLRuleManager extends RuleBasedScanner {
}
@NotNull
public synchronized Set<SQLScriptPosition> getAddedPositions(boolean clear)
{
public synchronized Set<SQLScriptPosition> getAddedPositions(boolean clear) {
Set<SQLScriptPosition> posList = addedPositions;
if (clear) {
addedPositions = new HashSet<>();
......@@ -124,8 +120,7 @@ public class SQLRuleManager extends RuleBasedScanner {
return posList;
}
public void refreshRules(@Nullable DBPDataSource dataSource, @Nullable IEditorInput editorInput)
{
public void refreshRules(@Nullable DBPDataSource dataSource, @Nullable IEditorInput editorInput) {
SQLDialect dialect = syntaxManager.getDialect();
SQLRuleProvider ruleProvider = GeneralUtils.adapt(dialect, SQLRuleProvider.class);
DBPDataSourceContainer dataSourceContainer = dataSource == null ? null : dataSource.getContainer();
......@@ -133,39 +128,39 @@ public class SQLRuleManager extends RuleBasedScanner {
boolean minimalRules = SQLEditorBase.isBigScript(editorInput);
boolean boldKeywords = dataSource == null ?
DBWorkbench.getPlatform().getPreferenceStore().getBoolean(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS) :
dataSource.getContainer().getPreferenceStore().getBoolean(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS);
DBWorkbench.getPlatform().getPreferenceStore().getBoolean(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS) :
dataSource.getContainer().getPreferenceStore().getBoolean(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS);
int keywordStyle = boldKeywords ? SWT.BOLD : SWT.NORMAL;
/*final Color backgroundColor = null;unassigned || dataSource != null ?
getColor(SQLConstants.CONFIG_COLOR_BACKGROUND, SWT.COLOR_WHITE) :
getColor(SQLConstants.CONFIG_COLOR_DISABLED, SWT.COLOR_WIDGET_LIGHT_SHADOW);*/
final IToken keywordToken = new Token(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle));
final IToken typeToken = new Token(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_DATATYPE), null, keywordStyle));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_DATATYPE), null, keywordStyle));
final IToken stringToken = new Token(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_STRING), null, SWT.NORMAL));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_STRING), null, SWT.NORMAL));
final IToken quotedToken = new Token(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_DATATYPE), null, SWT.NORMAL));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_DATATYPE), null, SWT.NORMAL));
final IToken numberToken = new Token(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_NUMBER), null, SWT.NORMAL));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_NUMBER), null, SWT.NORMAL));
final IToken commentToken = new SQLCommentToken(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_COMMENT), null, SWT.NORMAL));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_COMMENT), null, SWT.NORMAL));
final SQLDelimiterToken delimiterToken = new SQLDelimiterToken(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_DELIMITER, SWT.COLOR_RED), null, SWT.NORMAL));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_DELIMITER, SWT.COLOR_RED), null, SWT.NORMAL));
final SQLParameterToken parameterToken = new SQLParameterToken(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_PARAMETER, SWT.COLOR_DARK_BLUE), null, keywordStyle));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_PARAMETER, SWT.COLOR_DARK_BLUE), null, keywordStyle));
final SQLVariableToken variableToken = new SQLVariableToken(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_PARAMETER, SWT.COLOR_DARK_BLUE), null, keywordStyle));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_PARAMETER, SWT.COLOR_DARK_BLUE), null, keywordStyle));
final IToken otherToken = new Token(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_TEXT), null, SWT.NORMAL));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_TEXT), null, SWT.NORMAL));
final SQLBlockHeaderToken blockHeaderToken = new SQLBlockHeaderToken(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle));
final SQLBlockBeginToken blockBeginToken = new SQLBlockBeginToken(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle));
final SQLBlockEndToken blockEndToken = new SQLBlockEndToken(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle));
setDefaultReturnToken(otherToken);
List<IRule> rules = new ArrayList<>();
......@@ -255,7 +250,7 @@ public class SQLRuleManager extends RuleBasedScanner {
String delimRedefine = dialect.getScriptDelimiterRedefiner();
if (!CommonUtils.isEmpty(delimRedefine)) {
final SQLSetDelimiterToken setDelimiterToken = new SQLSetDelimiterToken(
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_COMMAND), null, keywordStyle));
new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_COMMAND), null, keywordStyle));
rules.add(new SQLDelimiterSetRule(delimRedefine, setDelimiterToken, delimRule));
}
......@@ -309,13 +304,11 @@ public class SQLRuleManager extends RuleBasedScanner {
setRules(result);
}
public Color getColor(String colorKey)
{
public Color getColor(String colorKey) {
return getColor(colorKey, SWT.COLOR_BLACK);
}
public Color getColor(String colorKey, int colorDefault)
{
public Color getColor(String colorKey, int colorDefault) {
ITheme currentTheme = themeManager.getCurrentTheme();
Color color = currentTheme.getColorRegistry().get(colorKey);
if (color == null) {
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License")),
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.editors.sql.syntax.tokens;
import org.jkiss.dbeaver.model.text.parser.TPTokenType;
/**
* SQL token type
*/
public enum SQLTokenType implements TPTokenType {
T_UNKNOWN(1000),
T_BLOCK_BEGIN(1001),
T_BLOCK_END(1002),
T_BLOCK_TOGGLE(1003),
T_BLOCK_HEADER(1004),
T_COMMENT(1005),
T_CONTROL(1006),
T_DELIMITER(1007),
T_SET_DELIMITER(1008),
T_PARAMETER(1009),
T_VARIABLE(1010);
private final int type;
SQLTokenType(int type) {
this.type = type;
}
@Override
public int getTokenType() {
return type;
}
@Override
public String getTypeId() {
return null;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册