--- a/db.sql.editor/nbproject/project.xml
+++ a/db.sql.editor/nbproject/project.xml
@@ -50,6 +50,15 @@
org.netbeans.modules.db.sql.editor
+ org.netbeans.modules.csl.api
+
+
+
+ 2
+ 2.27
+
+
+
org.netbeans.modules.db
@@ -102,15 +111,6 @@
- org.netbeans.modules.editor.deprecated.pre65formatting
-
-
-
- 0-1
- 1.0
-
-
-
org.netbeans.modules.editor.lib
@@ -120,6 +120,24 @@
+ org.netbeans.modules.editor.lib2
+
+
+
+ 1
+ 1.60
+
+
+
+ org.netbeans.modules.editor.mimelookup
+
+
+
+ 1
+ 1.26
+
+
+
org.netbeans.modules.lexer
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/Bundle.properties
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/Bundle.properties
@@ -42,10 +42,6 @@
OPTIONS_sql=SQL Editor
-#SQLIndentEngineBeanInfo
-LBL_SQLIndentEngine=SQL Indentation Engine
-HINT_SQLIndentEngine=Indentation Engine for SQL files
-
#SQLEditorProviderImpl
#{0} = command number
#PARTI18N - only localize "SQL Command" and do not add anything after ".sql"
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLEditorKit.java
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLEditorKit.java
@@ -1,140 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2011 Oracle and/or its affiliates. All rights reserved.
- *
- * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License. When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * Contributor(s):
- *
- * The Original Software is NetBeans. The Initial Developer of the Original
- * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
- * Microsystems, Inc. All Rights Reserved.
- *
- * If you wish your version of this file to be governed by only the CDDL
- * or only the GPL Version 2, indicate your decision by adding
- * "[Contributor] elects to include this software in this distribution
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
- * single choice of license, a recipient has the option to distribute
- * your version of this file under either the CDDL, the GPL Version 2 or
- * to extend the choice of license to its licensees as provided above.
- * However, if you add GPL Version 2 code and therefore, elected the GPL
- * Version 2 license, then the option applies only if the new code is
- * made subject to such option by the copyright holder.
- */
-
-package org.netbeans.modules.db.sql.editor;
-
-import javax.swing.Action;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.Caret;
-import javax.swing.text.Document;
-import javax.swing.text.TextAction;
-import org.netbeans.api.lexer.TokenSequence;
-import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.Syntax;
-import org.netbeans.editor.SyntaxSupport;
-import org.netbeans.modules.db.sql.editor.completion.SQLCompletionEnv;
-import org.netbeans.modules.db.sql.lexer.SQLTokenId;
-import org.netbeans.modules.editor.NbEditorKit;
-
-/**
- * This class implements the editor kit for text/x-sql files
- * in the editor
- *
- * @author Jesse Beaumont
- * @author Andrei Badea
- */
-public class SQLEditorKit extends NbEditorKit {
-
- public static final String MIME_TYPE = "text/x-sql"; // NOI18N
-
- /**
- * Creates a new instance of SQLEditorKit
- */
- public SQLEditorKit() {
- }
-
- /**
- * Create a syntax object suitable for highlighting SQL syntax
- */
- @Override
- public Syntax createSyntax(Document doc) {
- return new SQLSyntax();
- }
-
- /** Create syntax support */
- @Override
- public SyntaxSupport createSyntaxSupport(BaseDocument doc) {
- return new SQLSyntaxSupport(doc);
- }
-
- @Override
- protected Action[] createActions() {
- Action[] superActions = super.createActions();
- Action[] sqlActions = new Action[] {
- new SQLDefaultKeyTypedAction(),
- new ToggleCommentAction("-- ") // NOI18N
- };
- return TextAction.augmentList(superActions, sqlActions);
- }
-
- /**
- * Retrieves the content type for this editor kit
- */
- @Override
- public String getContentType() {
- return MIME_TYPE;
- }
-
- public static class SQLDefaultKeyTypedAction extends ExtDefaultKeyTypedAction {
-
- @Override
- protected void insertString(BaseDocument doc, int caretOffset, Caret caret, String str, boolean overwrite) throws BadLocationException {
- char insertedChar = str.charAt(0);
- if (insertedChar == '\"' || insertedChar == '\'') { //NOI18N
- if (canCompleteQuote(doc, caretOffset)) {
- // add pair quote
- super.insertString(doc, caretOffset, caret, String.valueOf(insertedChar) + insertedChar, overwrite);
- caret.setDot(caretOffset + 1);
- return;
- }
- }
- super.insertString(doc, caretOffset, caret, str, overwrite);
- }
-
- /** Returns true if completion of quote is wanted, i.e. cursor is
- * on token boundary and previous token is dot or whitespace. */
- private static boolean canCompleteQuote(BaseDocument doc, int caretOffset) {
- SQLCompletionEnv env = SQLCompletionEnv.forDocument(doc, caretOffset);
- TokenSequence seq = env.getTokenSequence();
- if (seq.move(caretOffset) == 0 && seq.movePrevious()) {
- switch (seq.token().id()) {
- case WHITESPACE:
- case DOT:
- return true;
- }
- }
- return false;
- }
- }
-}
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLFormatter.java
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLFormatter.java
@@ -1,90 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
- *
- * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License. When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * Contributor(s):
- *
- * The Original Software is NetBeans. The Initial Developer of the Original
- * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
- * Microsystems, Inc. All Rights Reserved.
- *
- * If you wish your version of this file to be governed by only the CDDL
- * or only the GPL Version 2, indicate your decision by adding
- * "[Contributor] elects to include this software in this distribution
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
- * single choice of license, a recipient has the option to distribute
- * your version of this file under either the CDDL, the GPL Version 2 or
- * to extend the choice of license to its licensees as provided above.
- * However, if you add GPL Version 2 code and therefore, elected the GPL
- * Version 2 license, then the option applies only if the new code is
- * made subject to such option by the copyright holder.
- */
-
-package org.netbeans.modules.db.sql.editor;
-
-import java.io.IOException;
-import java.io.Writer;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.JTextComponent;
-import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.Syntax;
-import org.netbeans.editor.ext.ExtFormatter;
-
-/**
- * Formatter for SQL
- *
- * @author Jesse Beaumont
- */
-public class SQLFormatter extends ExtFormatter {
-
- /**
- * Creates a new instance of SQLFormater
- */
- public SQLFormatter(Class kitClass) {
- super(kitClass);
- }
-
- /**
- * Determines whether the specified syntax is supported by this formatter
- */
- protected boolean acceptSyntax(Syntax syntax) {
- return (syntax instanceof SQLSyntax);
- }
-
- /**
- * Reformats a portion of the document
- */
- public Writer reformat(BaseDocument doc, int startOffset, int endOffset, boolean indentOnly)
- throws BadLocationException, IOException {
- return super.reformat(doc, startOffset, endOffset, indentOnly);
- }
-
- /**
- * Reformats a block of text
- */
- public int[] getReformatBlock(JTextComponent target, String typedText) {
- return super.getReformatBlock(target, typedText);
- }
-}
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLIndentEngine.java
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLIndentEngine.java
@@ -1,75 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
- *
- * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License. When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * Contributor(s):
- *
- * The Original Software is NetBeans. The Initial Developer of the Original
- * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
- * Microsystems, Inc. All Rights Reserved.
- *
- * If you wish your version of this file to be governed by only the CDDL
- * or only the GPL Version 2, indicate your decision by adding
- * "[Contributor] elects to include this software in this distribution
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
- * single choice of license, a recipient has the option to distribute
- * your version of this file under either the CDDL, the GPL Version 2 or
- * to extend the choice of license to its licensees as provided above.
- * However, if you add GPL Version 2 code and therefore, elected the GPL
- * Version 2 license, then the option applies only if the new code is
- * made subject to such option by the copyright holder.
- */
-
-package org.netbeans.modules.db.sql.editor;
-
-import org.netbeans.editor.ext.ExtFormatter;
-import org.netbeans.modules.db.sql.editor.SQLFormatter;
-import org.netbeans.modules.editor.FormatterIndentEngine;
-import org.openide.util.NbBundle;
-
-/**
- * Implements an indentation engine for SQL
- *
- * @author Jesse Beaumont
- * @author Andrei Badea
- */
-public class SQLIndentEngine extends FormatterIndentEngine {
-
- static final long serialVersionUID = -2095935054411935707L;
-
- /**
- * Creates a new instance of SQLIndentEngine
- */
- public SQLIndentEngine() {
- setAcceptedMimeTypes(new String[] { SQLEditorKit.MIME_TYPE });
- }
-
- /**
- * Creates a suitable formatter for handling SQL
- */
- protected ExtFormatter createFormatter() {
- return new SQLFormatter(SQLEditorKit.class);
- }
-}
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLIndentEngineBeanInfo.java
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLIndentEngineBeanInfo.java
@@ -1,95 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
- *
- * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License. When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * Contributor(s):
- *
- * The Original Software is NetBeans. The Initial Developer of the Original
- * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
- * Microsystems, Inc. All Rights Reserved.
- *
- * If you wish your version of this file to be governed by only the CDDL
- * or only the GPL Version 2, indicate your decision by adding
- * "[Contributor] elects to include this software in this distribution
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
- * single choice of license, a recipient has the option to distribute
- * your version of this file under either the CDDL, the GPL Version 2 or
- * to extend the choice of license to its licensees as provided above.
- * However, if you add GPL Version 2 code and therefore, elected the GPL
- * Version 2 license, then the option applies only if the new code is
- * made subject to such option by the copyright holder.
- */
-
-package org.netbeans.modules.db.sql.editor;
-
-import java.beans.BeanDescriptor;
-import java.util.MissingResourceException;
-import org.netbeans.modules.editor.FormatterIndentEngineBeanInfo;
-import org.netbeans.modules.editor.NbEditorUtilities;
-import org.openide.util.NbBundle;
-
-/**
- * The BeanInfo descriptor for the SQLIndentEngine
- *
- * @author Jesse Beaumont
- */
-public class SQLIndentEngineBeanInfo extends FormatterIndentEngineBeanInfo {
-
- private BeanDescriptor beanDescriptor;
-
- /**
- * Get the bean descriptor
- */
- public BeanDescriptor getBeanDescriptor () {
- if (beanDescriptor == null) {
- beanDescriptor = new BeanDescriptor(getBeanClass());
- beanDescriptor.setDisplayName(getMessage("LBL_SQLIndentEngine"));
- beanDescriptor.setShortDescription(getMessage("HINT_SQLIndentEngine"));
- beanDescriptor.setValue("global", Boolean.TRUE); // NOI18N
- }
- return beanDescriptor;
- }
-
- /**
- * Get the class of the bean described by this bean info
- */
- protected Class getBeanClass() {
- return SQLIndentEngine.class;
- }
-
- /**
- * Look up a resource bundle message, if it is not found locally defer to
- * the super implementation
- */
- protected String getMessage(String key) {
- try {
- return NbBundle.getMessage(SQLIndentEngineBeanInfo.class, key);
- } catch (MissingResourceException e) {
- return super.getString(key);
- }
- }
-
-}
-
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSettingsInitializer.java
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSettingsInitializer.java
@@ -1,65 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
- *
- * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License. When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * Contributor(s):
- *
- * The Original Software is NetBeans. The Initial Developer of the Original
- * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
- * Microsystems, Inc. All Rights Reserved.
- *
- * If you wish your version of this file to be governed by only the CDDL
- * or only the GPL Version 2, indicate your decision by adding
- * "[Contributor] elects to include this software in this distribution
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
- * single choice of license, a recipient has the option to distribute
- * your version of this file under either the CDDL, the GPL Version 2 or
- * to extend the choice of license to its licensees as provided above.
- * However, if you add GPL Version 2 code and therefore, elected the GPL
- * Version 2 license, then the option applies only if the new code is
- * made subject to such option by the copyright holder.
- */
-
-package org.netbeans.modules.db.sql.editor;
-
-import java.util.Collections;
-import java.util.List;
-import org.openide.text.IndentEngine;
-
-/**
- * Initializes the SQL Settings
- *
- * @author Jesse Beaumont, Andrei Badea
- */
-public class SQLSettingsInitializer {
-
- public static List getTokenContext() {
- return Collections.singletonList(SQLTokenContext.context);
- }
-
- public static IndentEngine getIndentEngine() {
- return new SQLIndentEngine();
- }
-}
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSyntax.java
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSyntax.java
@@ -1,520 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
- *
- * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License. When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * Contributor(s):
- *
- * The Original Software is NetBeans. The Initial Developer of the Original
- * Software is Sun Microsystems, Inc. Portions Copyright 1997-2010 Sun
- * Microsystems, Inc. All Rights Reserved.
- *
- * If you wish your version of this file to be governed by only the CDDL
- * or only the GPL Version 2, indicate your decision by adding
- * "[Contributor] elects to include this software in this distribution
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
- * single choice of license, a recipient has the option to distribute
- * your version of this file under either the CDDL, the GPL Version 2 or
- * to extend the choice of license to its licensees as provided above.
- * However, if you add GPL Version 2 code and therefore, elected the GPL
- * Version 2 license, then the option applies only if the new code is
- * made subject to such option by the copyright holder.
- */
-
-package org.netbeans.modules.db.sql.editor;
-
-import org.netbeans.editor.Syntax;
-import org.netbeans.editor.TokenID;
-import org.netbeans.modules.db.api.sql.SQLKeywords;
-
-/**
- * This class implements SQL syntax recognition
- *
- * @author Jesse Beaumont, Andrei Badea
- */
-public class SQLSyntax extends Syntax {
-
- private static final int ISI_WHITESPACE = 2; // inside white space
- private static final int ISI_LINE_COMMENT = 4; // inside line comment --
- private static final int ISI_BLOCK_COMMENT = 5; // inside block comment /* ... */
- private static final int ISI_STRING = 6; // inside string constant
- private static final int ISI_STRING_A_QUOTE = 7; // inside string constant after '
- private static final int ISI_IDENTIFIER = 10; // inside identifier
- private static final int ISA_SLASH = 11; // slash char
- private static final int ISA_OPERATOR = 12; // after '=', '/', '+'
- private static final int ISA_MINUS = 13;
- private static final int ISA_STAR = 20; // after '*'
- private static final int ISA_STAR_I_BLOCK_COMMENT_END = 21; // after '*' in a block comment
- private static final int ISA_EXCLAMATION = 26; // after '!'
- private static final int ISA_ZERO = 27; // after '0'
- private static final int ISI_INT = 28; // integer number
- private static final int ISI_DOUBLE = 30; // double number
- private static final int ISA_DOT = 33; // after '.'
- private static final int ISA_COMMA = 34; // after ','
- private static final int ISA_SEMICOLON = 35; //after ';'
- private static final int ISA_LPAREN = 36; //after (
- private static final int ISA_RPAREN = 37; //after )
- private static final int ISA_BACK_SLASH_IN_STRING = 38; // after \ in string
- private static final int ISA_HASH = 39; // '#' char
-
- private int startQuoteChar = -1;
-
- /**
- * Creates a new instance of SQLSyntax
- */
- public SQLSyntax() {
- tokenContextPath = SQLTokenContext.contextPath;
- }
-
- /**
- * Parse the next token
- */
- @Override
- protected TokenID parseToken() {
- char actChar; //the current character
-
- //while we still have stuff to parse, do so
- while(offset < stopOffset) {
- actChar = buffer[offset];
-
- //do the appropriate stuff based on what state the parser is in
- switch (state) {
- //the initial state (start of a new token)
- case INIT:
- switch (actChar) {
- case '\'': // NOI18N
- state = ISI_STRING;
- break;
- case '/':
- state = ISA_SLASH;
- break;
- case '#':
- state = ISA_HASH;
- break;
- case '=':
- case '>':
- case '<':
- case '+':
- case ',':
- case ')':
- case '(':
- case ';':
- case '*':
- case '!':
- offset++;
- state = INIT;
- return SQLTokenContext.OPERATOR;
- case '-':
- state = ISA_MINUS;
- break;
- case '0':
- state = ISA_ZERO;
- break;
- case '.':
- state = ISA_DOT;
- break;
- default:
- // Check for whitespace
- if (Character.isWhitespace(actChar)) {
- state = ISI_WHITESPACE;
- break;
- }
-
- // Check for digit
- if (Character.isDigit(actChar)) {
- state = ISI_INT;
- break;
- }
-
- // otherwise it's an identifier
- state = ISI_IDENTIFIER;
- if (isStartQuoteChar(actChar)) {
- startQuoteChar = actChar;
- }
- break;
- }
- break;
- //if we are currently in a whitespace token
- case ISI_WHITESPACE: // white space
- if (!Character.isWhitespace(actChar)) {
- state = INIT;
- return SQLTokenContext.WHITESPACE;
- }
- break;
-
- //if we are currently in a line comment
- case ISI_LINE_COMMENT:
- if (actChar == '\n') {
- state = INIT;
- return SQLTokenContext.LINE_COMMENT;
- }
- break;
-
- //if we are currently in a block comment
- case ISI_BLOCK_COMMENT:
- if(actChar =='*') {
- state = ISA_STAR_I_BLOCK_COMMENT_END;
- }
- break;
-
- //if we are currently in a string literal
- case ISI_STRING:
- switch (actChar) {
- case '\\': // NOI18N
- // escape possible single quote #152325
- state = ISA_BACK_SLASH_IN_STRING;
- break;
- case '\'': // NOI18N
- offset++;
- state = INIT;
- return SQLTokenContext.STRING;
- }
- break;
-
- // If we are after a back slash (\) in string.
- case ISA_BACK_SLASH_IN_STRING:
- state = ISI_STRING;
- break;
-
- //if we are currently in an identifier (e.g. a variable name)
- case ISI_IDENTIFIER:
- if (startQuoteChar != -1) {
- if (!isEndQuoteChar(startQuoteChar, actChar)) {
- break;
- } else {
- offset++;
- }
- } else {
- if (Character.isLetterOrDigit(actChar) || actChar == '_' || actChar == '#') {
- break;
- }
- }
- state = INIT;
- startQuoteChar = -1;
- TokenID tid = matchKeyword(buffer, tokenOffset, offset - tokenOffset);
- if (tid != null) {
- return tid;
- } else {
- return SQLTokenContext.IDENTIFIER;
- }
-
- //if we are after a slash (/)
- case ISA_SLASH:
- switch (actChar) {
- case '*':
- state = ISI_BLOCK_COMMENT;
- break;
- default:
- state = INIT;
- return SQLTokenContext.OPERATOR;
- }
- break;
-
- //if we are after a -
- case ISA_MINUS:
- switch (actChar) {
- case '-':
- state = ISI_LINE_COMMENT;
- break;
- default:
- state = INIT;
- return SQLTokenContext.OPERATOR;
- }
- break;
-
- //if we are after a #
- case ISA_HASH:
- if (Character.isWhitespace(actChar)) {
- // only in MySQL # starts line comment
- state = ISI_LINE_COMMENT;
- if (actChar == '\n') {
- return SQLTokenContext.LINE_COMMENT;
- }
- } else {
- // otherwise it can be identifier (issue 172904)
- if (offset > 1) {
- state = ISI_IDENTIFIER;
- } else {
- state = ISI_LINE_COMMENT;
- }
- }
- break;
-
- //if we are in the middle of a possible block comment end token
- case ISA_STAR_I_BLOCK_COMMENT_END:
- switch (actChar) {
- case '/':
- offset++;
- state = INIT;
- return SQLTokenContext.BLOCK_COMMENT;
- default:
- offset--;
- state = ISI_BLOCK_COMMENT;
- break;
- }
- break;
-
- //if we are after a 0
- case ISA_ZERO:
- switch (actChar) {
- case '.':
- state = ISI_DOUBLE;
- break;
- default:
- if (Character.isDigit(actChar)) {
- state = ISI_INT;
- break;
- } else {
- state = INIT;
- return SQLTokenContext.INT_LITERAL;
- }
- }
- break;
-
- //if we are after an integer
- case ISI_INT:
- switch (actChar) {
- case '.':
- state = ISI_DOUBLE;
- break;
- default:
- if (Character.isDigit(actChar)) {
- state = ISI_INT;
- break;
- } else {
- state = INIT;
- return SQLTokenContext.INT_LITERAL;
- }
- }
- break;
-
- //if we are in the middle of what we believe is a floating point
- //number
- case ISI_DOUBLE:
- if (actChar >= '0' && actChar <= '9') {
- state = ISI_DOUBLE;
- break;
- } else {
- state = INIT;
- return SQLTokenContext.DOUBLE_LITERAL;
- }
-
- //if we are after a period
- case ISA_DOT:
- if (Character.isDigit(actChar)) {
- state = ISI_DOUBLE;
- } else { // only single dot
- state = INIT;
- return SQLTokenContext.DOT;
- }
- break;
-
- } // end of switch(state)
-
- offset++;
- } // end of while(offset...)
-
- /*
- * At this stage there's no more text in the scanned buffer.
- * Scanner first checks whether this is completely the last
- * available buffer.
- */
- if (lastBuffer) {
- switch(state) {
- case ISI_WHITESPACE:
- state = INIT;
- return SQLTokenContext.WHITESPACE;
- case ISI_IDENTIFIER:
- state = INIT;
- startQuoteChar = -1;
- TokenID tid =
- matchKeyword(buffer, tokenOffset, offset - tokenOffset);
- if(tid != null) {
- return tid;
- }
- else {
- return SQLTokenContext.IDENTIFIER;
- }
- case ISI_LINE_COMMENT:
- // stay in line-comment state
- return SQLTokenContext.LINE_COMMENT;
- case ISI_BLOCK_COMMENT:
- case ISA_STAR_I_BLOCK_COMMENT_END:
- // stay in block-comment state
- return SQLTokenContext.BLOCK_COMMENT;
- case ISI_STRING:
- case ISA_BACK_SLASH_IN_STRING:
- return SQLTokenContext.INCOMPLETE_STRING;
- case ISA_ZERO:
- case ISI_INT:
- state = INIT;
- return SQLTokenContext.INT_LITERAL;
- case ISI_DOUBLE:
- state = INIT;
- return SQLTokenContext.DOUBLE_LITERAL;
- case ISA_DOT:
- state = INIT;
- return SQLTokenContext.DOT;
- case ISA_SLASH:
- state = INIT;
- return SQLTokenContext.OPERATOR;
- }
- }
-
- /*
- * At this stage there's no more text in the scanned buffer, but
- * this buffer is not the last so the
- * scan will continue on another buffer.
- * The scanner tries to minimize the amount of characters
- * that will be prescanned in the next buffer by returning the token
- * where possible.
- */
-
- switch (state) {
- case ISI_WHITESPACE:
- return SQLTokenContext.WHITESPACE;
- }
-
- return null; // nothing found
- }
-
- /**
- * Returns the state name for the state id
- */
- @Override
- public String getStateName(int stateNumber) {
- switch(stateNumber) {
- case ISI_WHITESPACE:
- return "ISI_WHITESPACE"; // NOI18N
- case ISI_LINE_COMMENT:
- return "ISI_LINE_COMMENT"; // NOI18N
- case ISI_BLOCK_COMMENT:
- return "ISI_BLOCK_COMMENT"; // NOI18N
- case ISI_STRING:
- return "ISI_STRING"; // NOI18N
- case ISI_STRING_A_QUOTE:
- return "ISI_STRING_A_QUOTE"; // NOI18N
- case ISI_IDENTIFIER:
- return "ISI_IDENTIFIER"; // NOI18N
- case ISA_SLASH:
- return "ISA_SLASH"; // NOI18N
- case ISA_OPERATOR:
- return "ISA_OPERATOR"; // NOI18N
- case ISA_MINUS:
- return "ISA_MINUS"; // NOI18N
- case ISA_STAR:
- return "ISA_STAR"; // NOI18N
- case ISA_STAR_I_BLOCK_COMMENT_END:
- return "ISA_STAR_I_BLOCK_COMMENT_END"; // NOI18N
- case ISA_ZERO:
- return "ISA_ZERO"; // NOI18N
- case ISI_INT:
- return "ISI_INT"; // NOI18N
- case ISI_DOUBLE:
- return "ISI_DOUBLE"; // NOI18N
- case ISA_DOT:
- return "ISA_DOT"; // NOI18N
- case ISA_COMMA:
- return "ISA_COMMA"; // NOI18N
-
- default:
- return super.getStateName(stateNumber);
- }
- }
-
- @Override
- public void loadInitState() {
- startQuoteChar = -1;
- super.loadInitState();
- }
-
- @Override
- public StateInfo createStateInfo() {
- return new SQLStateInfo();
- }
-
- @Override
- public void loadState(StateInfo stateInfo) {
- startQuoteChar = ((SQLStateInfo) stateInfo).getStartQuoteChar();
- super.loadState(stateInfo);
- }
-
- @Override
- public void storeState(StateInfo stateInfo) {
- ((SQLStateInfo)stateInfo).setStartQuoteChar(startQuoteChar);
- super.storeState(stateInfo);
- }
-
- @Override
- public int compareState(StateInfo stateInfo) {
- if (stateInfo != null) {
- if (((SQLStateInfo)stateInfo).getStartQuoteChar() == startQuoteChar) {
- return super.compareState(stateInfo);
- }
- }
- return DIFFERENT_STATE;
- }
-
- private static boolean isStartQuoteChar(int start) {
- return start == '\"' || // SQL-99
- start == '`' || // MySQL
- start == '['; // MS SQL Server
- }
-
-
- private static boolean isEndQuoteChar(int start, int end) {
- return start == '\"' && end == start || // SQL-99
- start == '`' && end == start || // MySQL
- start == '[' && end == ']'; // MS SQL Server
- }
-
- /**
- * Tries to match the specified sequence of characters to a SQL
- * keyword.
- *
- * @return the KEYWORD id or null if no match was found
- */
- public TokenID matchKeyword(char[] buffer, int offset, int len) {
- String keywordCandidate = new String(buffer, offset, len);
-
- if (SQLKeywords.isSQL99Keyword(keywordCandidate.toUpperCase(), true)) {
- return SQLTokenContext.KEYWORD;
- }
-
- return null;
- }
-
- private static final class SQLStateInfo extends BaseStateInfo {
-
- private int startQuoteChar;
-
- public int getStartQuoteChar() {
- return startQuoteChar;
- }
-
- public void setStartQuoteChar(int startQuoteChar) {
- this.startQuoteChar = startQuoteChar;
- }
- }
-}
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSyntaxSupport.java
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSyntaxSupport.java
@@ -1,74 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
- *
- * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License. When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * Contributor(s):
- *
- * The Original Software is NetBeans. The Initial Developer of the Original
- * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
- * Microsystems, Inc. All Rights Reserved.
- *
- * If you wish your version of this file to be governed by only the CDDL
- * or only the GPL Version 2, indicate your decision by adding
- * "[Contributor] elects to include this software in this distribution
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
- * single choice of license, a recipient has the option to distribute
- * your version of this file under either the CDDL, the GPL Version 2 or
- * to extend the choice of license to its licensees as provided above.
- * However, if you add GPL Version 2 code and therefore, elected the GPL
- * Version 2 license, then the option applies only if the new code is
- * made subject to such option by the copyright holder.
- */
-
-package org.netbeans.modules.db.sql.editor;
-
-import javax.swing.text.BadLocationException;
-import javax.swing.text.JTextComponent;
-import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.TokenID;
-import org.netbeans.editor.ext.ExtSyntaxSupport;
-import org.openide.DialogDisplayer;
-import org.openide.NotifyDescriptor;
-
-/**
- *
- * @author Jesse Beaumont
- */
-public class SQLSyntaxSupport extends ExtSyntaxSupport {
-
- public SQLSyntaxSupport(BaseDocument doc) {
- super(doc);
- }
-
- /**
- * Get the array of token IDs that denote the comments.
- */
- public TokenID[] getCommentTokens() {
- return new TokenID[] {
- SQLTokenContext.BLOCK_COMMENT,
- SQLTokenContext.LINE_COMMENT
- };
- }
-}
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLTokenContext.java
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLTokenContext.java
@@ -1,127 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
- *
- * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License. When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * Contributor(s):
- *
- * The Original Software is NetBeans. The Initial Developer of the Original
- * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
- * Microsystems, Inc. All Rights Reserved.
- *
- * If you wish your version of this file to be governed by only the CDDL
- * or only the GPL Version 2, indicate your decision by adding
- * "[Contributor] elects to include this software in this distribution
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
- * single choice of license, a recipient has the option to distribute
- * your version of this file under either the CDDL, the GPL Version 2 or
- * to extend the choice of license to its licensees as provided above.
- * However, if you add GPL Version 2 code and therefore, elected the GPL
- * Version 2 license, then the option applies only if the new code is
- * made subject to such option by the copyright holder.
- */
-
-package org.netbeans.modules.db.sql.editor;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.netbeans.editor.BaseTokenCategory;
-import org.netbeans.editor.BaseTokenID;
-import org.netbeans.editor.TokenContext;
-import org.netbeans.editor.TokenContextPath;
-
-/**
-* SQL token-context defines token-ids and token-categories
-* used in SQL language.
-*
-* @author Jesse Beaumont based on code by Miloslav Metelka
-*/
-
-public class SQLTokenContext extends TokenContext {
-
- // Numeric-ids for token categories
- public static final int ERRORS_ID = 0; // errors
-
- // Numeric-ids for token-ids
- public static final int WHITESPACE_ID = ERRORS_ID + 1; // inside white space
- public static final int LINE_COMMENT_ID = WHITESPACE_ID + 1; // inside line comment --
- public static final int BLOCK_COMMENT_ID = LINE_COMMENT_ID + 1; // inside block comment /* ... */
- public static final int STRING_ID = BLOCK_COMMENT_ID + 1; // inside string constant
- public static final int INCOMPLETE_STRING_ID = STRING_ID + 1; // inside string constant after '
- public static final int IDENTIFIER_ID = INCOMPLETE_STRING_ID + 1; // inside identifier
- public static final int OPERATOR_ID = IDENTIFIER_ID + 1; // slash char
- public static final int INVALID_COMMENT_END_ID = OPERATOR_ID + 1; // after '0'
- public static final int INT_LITERAL_ID = INVALID_COMMENT_END_ID + 1; // integer number
- public static final int DOUBLE_LITERAL_ID = INT_LITERAL_ID + 1; // double number
- public static final int DOT_ID = DOUBLE_LITERAL_ID + 1; // after '.'
- public static final int KEYWORD_ID = DOT_ID + 1;
-
- // Token categories
- public static final BaseTokenCategory ERRORS =
- new BaseTokenCategory("errors", ERRORS_ID); // NOI18N
-
- // Token-ids
- public static final BaseTokenID WHITESPACE =
- new BaseTokenID( "whitespace", WHITESPACE_ID ); // NOI18N
- public static final BaseTokenID LINE_COMMENT =
- new BaseTokenID( "line-comment", LINE_COMMENT_ID ); // NOI18N
- public static final BaseTokenID BLOCK_COMMENT =
- new BaseTokenID( "block-comment", BLOCK_COMMENT_ID ); // NOI18N
- public static final BaseTokenID STRING =
- new BaseTokenID( "string-literal", STRING_ID ); // NOI18N
- public static final BaseTokenID INCOMPLETE_STRING =
- new BaseTokenID( "incomplete-string-literal", INCOMPLETE_STRING_ID, ERRORS ); // NOI18N
- public static final BaseTokenID IDENTIFIER =
- new BaseTokenID( "identifier", IDENTIFIER_ID ); // NOI18N
- public static final BaseTokenID OPERATOR =
- new BaseTokenID( "operator", OPERATOR_ID ); // NOI18N
- public static final BaseTokenID INVALID_COMMENT_END =
- new BaseTokenID( "invalid-comment-end", INVALID_COMMENT_END_ID, ERRORS ); // NOI18N
- public static final BaseTokenID INT_LITERAL =
- new BaseTokenID( "int-literal", INT_LITERAL_ID ); // NOI18N
- public static final BaseTokenID DOUBLE_LITERAL =
- new BaseTokenID( "double-literal", DOUBLE_LITERAL_ID ); // NOI18N
- public static final BaseTokenID DOT =
- new BaseTokenID( "dot", DOT_ID ); // NOI18N
- public static final BaseTokenID KEYWORD =
- new BaseTokenID( "keyword", KEYWORD_ID ); // NOI18N
-
- // Context instance declaration
- public static final SQLTokenContext context = new SQLTokenContext();
- public static final TokenContextPath contextPath = context.getContextPath();
-
- /**
- * Constructs a new SQLTokenContext
- */
- private SQLTokenContext() {
- super("sql-"); // NOI18N
-
- try {
- addDeclaredTokenIDs();
- } catch (Exception e) {
- Logger.getLogger (SQLTokenContext.class.getName ()).log (Level.INFO, e.getLocalizedMessage (), e);
- }
-
- }
-}
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLTypedTextInterceptor.java
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLTypedTextInterceptor.java
@@ -0,0 +1,164 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2012 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.db.sql.editor;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.api.editor.mimelookup.MimeRegistration;
+import org.netbeans.api.editor.mimelookup.MimeRegistrations;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.editor.BaseDocument;
+import org.netbeans.modules.db.sql.editor.completion.SQLCompletionEnv;
+import org.netbeans.modules.db.sql.lexer.SQLLexer;
+import org.netbeans.modules.db.sql.lexer.SQLTokenId;
+import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor;
+
+public class SQLTypedTextInterceptor implements TypedTextInterceptor {
+
+ @MimeRegistrations({
+ @MimeRegistration(mimeType = "text/x-sql", service = TypedTextInterceptor.Factory.class)
+ })
+ public static class Factory implements TypedTextInterceptor.Factory {
+
+ @Override
+ public TypedTextInterceptor createTypedTextInterceptor(org.netbeans.api.editor.mimelookup.MimePath mimePath) {
+ return new SQLTypedTextInterceptor();
+ }
+ }
+
+ @Override
+ public boolean beforeInsert(Context context) throws BadLocationException {
+ return false;
+ }
+
+ @Override
+ public void insert(MutableContext context) throws BadLocationException {
+ }
+
+ @Override
+ public void afterInsert(final Context context) throws BadLocationException {
+ final Document doc = context.getDocument();
+
+ Runnable r = new Runnable() {
+ public void run() {
+ int caretOffset = context.getOffset();
+ String str = context.getText();
+
+ Character nextChar;
+
+ try {
+ nextChar = doc.getText(caretOffset + str.length(),
+ 1).charAt(0);
+ } catch (BadLocationException ex) {
+ nextChar = null;
+ }
+
+ if (!str.isEmpty()) {
+ char insertedChar = str.charAt(str.length() - 1);
+ if ( (SQLLexer.isStartIdentifierQuoteChar(insertedChar)
+ && (nextChar == null || Character.isWhitespace(nextChar) || nextChar.equals('.')))
+ ||
+ (SQLLexer.isStartStringQuoteChar(insertedChar)
+ && (nextChar == null || Character.isWhitespace(nextChar)))
+ ) { //NOI18N
+ if (canCompleteQuote(doc, caretOffset)) {
+ try {
+ // add pair quote
+ doc.insertString(caretOffset + str.length(), String.valueOf((char) SQLLexer.getMatchingQuote(insertedChar)), null);
+ context.getComponent().getCaret().setDot(caretOffset + str.length());
+ } catch (BadLocationException ex) {
+ }
+ }
+ } else if (insertedChar == '(' && (nextChar == null || Character.isWhitespace(nextChar))) {
+ if (canCompleteBrace(doc, caretOffset)) {
+ try {
+ // add pair quote
+ doc.insertString(caretOffset + str.length(), ")", null);
+ context.getComponent().getCaret().setDot(caretOffset + str.length());
+ } catch (BadLocationException ex) {
+ }
+ }
+ }
+ }
+ }
+ };
+
+ if(doc instanceof BaseDocument) {
+ ((BaseDocument) doc).runAtomic(r);
+ } else {
+ r.run();
+ }
+ }
+
+ /**
+ * Returns true if completion of quote is wanted, i.e. cursor is on token
+ * boundary and previous token is dot or whitespace.
+ */
+ private static boolean canCompleteQuote(Document doc, int caretOffset) {
+ SQLCompletionEnv env = SQLCompletionEnv.forDocument(doc, caretOffset);
+ TokenSequence seq = env.getTokenSequence();
+ if (seq.move(caretOffset) == 0 && seq.movePrevious()) {
+ switch (seq.token().id()) {
+ case WHITESPACE:
+ case DOT:
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static boolean canCompleteBrace(Document doc, int caretOffset) {
+ SQLCompletionEnv env = SQLCompletionEnv.forDocument(doc, caretOffset);
+ TokenSequence seq = env.getTokenSequence();
+ if (seq.move(caretOffset) == 0 && seq.movePrevious()) {
+ switch (seq.token().id()) {
+ case WHITESPACE:
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void cancelled(Context context) {
+ }
+}
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/NetBeans-SQL-preferences.xml
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/NetBeans-SQL-preferences.xml
@@ -1,51 +0,0 @@
-
-
-
-
-
-
-
-
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/SQLIndentEngine.settings
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/SQLIndentEngine.settings
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml
@@ -45,13 +45,6 @@
-->
-
-
-
-
-
-
-
@@ -80,22 +73,11 @@
-
-
-
-
-
-
-
-
-
-
-
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLLanguageConfig.java
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLLanguageConfig.java
@@ -0,0 +1,67 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2012 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.db.sql.lexer;
+
+import org.netbeans.api.lexer.Language;
+import org.netbeans.modules.csl.spi.DefaultLanguageConfig;
+import org.netbeans.modules.csl.spi.LanguageRegistration;
+
+@LanguageRegistration(mimeType="text/x-sql")
+public class SQLLanguageConfig extends DefaultLanguageConfig {
+
+ @Override
+ public Language getLexerLanguage() {
+ return SQLTokenId.language();
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "SQL";
+ }
+
+ @Override
+ public String getLineCommentPrefix() {
+ return "-- ";
+ }
+
+
+}
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLLexer.java
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLLexer.java
@@ -128,7 +128,7 @@
}
// Otherwise it's an identifier.
- if (isStartQuoteChar(actChar)) {
+ if (isStartIdentifierQuoteChar(actChar)) {
startQuoteChar = actChar;
}
state = State.ISI_IDENTIFIER;
@@ -182,7 +182,7 @@
// or a keyword.
case ISI_IDENTIFIER:
if (startQuoteChar != -1) {
- if (!isEndQuoteChar(startQuoteChar, actChar)) {
+ if (!isEndIdentifierQuoteChar(startQuoteChar, actChar)) {
break;
}
} else {
@@ -377,16 +377,27 @@
public void release() {
}
- private static boolean isStartQuoteChar(int start) {
+ public static boolean isStartStringQuoteChar(int start) {
+ return start == '\''; // SQL-99 string
+ }
+
+ public static boolean isStartIdentifierQuoteChar(int start) {
return start == '\"' || // SQL-99
start == '`' || // MySQL
start == '['; // MS SQL Server
}
+
+ public static int getMatchingQuote(int start) {
+ switch(start) {
+ case '[':
+ return ']';
+ default:
+ return start;
+ }
+ }
- private static boolean isEndQuoteChar(int start, int end) {
- return start == '\"' && end == start || // SQL-99
- start == '`' && end == start || // MySQL
- start == '[' && end == ']'; // MS SQL Server
+ public static boolean isEndIdentifierQuoteChar(int start, int end) {
+ return end == getMatchingQuote(start);
}
private static SQLTokenId testKeyword(CharSequence value) {
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLTokenId.java
+++ a/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLTokenId.java
@@ -61,23 +61,20 @@
* @author Andrei Badea
*/
public enum SQLTokenId implements TokenId {
-
- // XXX prefix with "sql-" for compat reasons?
-
- WHITESPACE("whitespace"), // NOI18N
- LINE_COMMENT("line-comment"), // NOI18N
- BLOCK_COMMENT("block-comment"), // NOI18N
- STRING("string-literal"), // NOI18N
- INCOMPLETE_STRING("incomplete-string-literal"), // NOI18N
- IDENTIFIER("identifier"), // NOI18N
- OPERATOR("operator"), // NOI18N
- LPAREN("operator"), // NOI18N
- RPAREN("operator"), // NOI18N
- DOT("dot"), // NOI18N
- COMMA("operator"), // // NOI18N XXX or have own category?
- INT_LITERAL("int-literal"), // NOI18N
- DOUBLE_LITERAL("double-literal"), // NOI18N
- KEYWORD("keyword"); // NOI18N
+ WHITESPACE("sql-whitespace"), // NOI18N
+ LINE_COMMENT("sql-line-comment"), // NOI18N
+ BLOCK_COMMENT("sql-block-comment"), // NOI18N
+ STRING("sql-string-literal"), // NOI18N
+ INCOMPLETE_STRING("sql-string-literal"), // NOI18N
+ IDENTIFIER("sql-identifier"), // NOI18N
+ OPERATOR("sql-operator"), // NOI18N
+ LPAREN("sql-operator"), // NOI18N
+ RPAREN("sql-operator"), // NOI18N
+ DOT("sql-dot"), // NOI18N
+ COMMA("sql-operator"), // // NOI18N XXX or have own category?
+ INT_LITERAL("sql-int-literal"), // NOI18N
+ DOUBLE_LITERAL("sql-double-literal"), // NOI18N
+ KEYWORD("sql-keyword"); // NOI18N
private final String primaryCategory;
--- a/db.sql.editor/test/unit/src/org/netbeans/modules/db/sql/editor/SQLSyntaxTest.java
+++ a/db.sql.editor/test/unit/src/org/netbeans/modules/db/sql/editor/SQLSyntaxTest.java
@@ -1,185 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
- *
- * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License. When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * Contributor(s):
- *
- * The Original Software is NetBeans. The Initial Developer of the Original
- * Software is Sun Microsystems, Inc. Portions Copyright 1997-2010 Sun
- * Microsystems, Inc. All Rights Reserved.
- *
- * If you wish your version of this file to be governed by only the CDDL
- * or only the GPL Version 2, indicate your decision by adding
- * "[Contributor] elects to include this software in this distribution
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
- * single choice of license, a recipient has the option to distribute
- * your version of this file under either the CDDL, the GPL Version 2 or
- * to extend the choice of license to its licensees as provided above.
- * However, if you add GPL Version 2 code and therefore, elected the GPL
- * Version 2 license, then the option applies only if the new code is
- * made subject to such option by the copyright holder.
- */
-
-package org.netbeans.modules.db.sql.editor;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import org.netbeans.editor.Syntax;
-import org.netbeans.editor.TokenID;
-import org.netbeans.junit.NbTestCase;
-
-/**
- *
- * @author Andrei Badea, Jiri Skrivanek
- */
-public class SQLSyntaxTest extends NbTestCase {
-
- public SQLSyntaxTest(String testName) {
- super(testName);
- }
-
- public void testNumberLiteralsEndWithFirstNonDigitCharIssue67379() {
- assertTokens("10-20.3-3", new TokenID[] {
- SQLTokenContext.INT_LITERAL,
- SQLTokenContext.OPERATOR,
- SQLTokenContext.DOUBLE_LITERAL,
- SQLTokenContext.OPERATOR,
- SQLTokenContext.INT_LITERAL,
- });
-
- assertTokens("10foo", new TokenID[] {
- SQLTokenContext.INT_LITERAL,
- SQLTokenContext.IDENTIFIER,
- });
- }
-
- public void testLast() {
- SQLSyntax s = new SQLSyntax();
- String sql = "`ident";
- s.load(null, sql.toCharArray(), 0, sql.length(), true, sql.length());
- assertEquals(SQLTokenContext.IDENTIFIER, s.nextToken());
- sql = "select foo bar baz";
- s.load(null, sql.toCharArray(), 0, sql.length(), true, sql.length());
- assertEquals(SQLTokenContext.KEYWORD, s.nextToken());
- }
-
- public void testEscapeSingleQuote() {
- assertTokens("'Frank\\'s Book'", SQLTokenContext.STRING);
- assertTokens("'Frank''s Book'", SQLTokenContext.STRING, SQLTokenContext.STRING);
- assertTokens("'Frank\\s Book'", SQLTokenContext.STRING);
- assertTokens("'Frank\\", SQLTokenContext.INCOMPLETE_STRING);
- assertTokens("'Frank\\'", SQLTokenContext.INCOMPLETE_STRING);
- }
-
- public void testSlash() {
- assertTokens("((EndTime-StartTime)/2)*5", new TokenID[] {
- SQLTokenContext.OPERATOR,
- SQLTokenContext.OPERATOR,
- SQLTokenContext.IDENTIFIER,
- SQLTokenContext.OPERATOR,
- SQLTokenContext.IDENTIFIER,
- SQLTokenContext.OPERATOR,
- SQLTokenContext.OPERATOR,
- SQLTokenContext.INT_LITERAL,
- SQLTokenContext.OPERATOR,
- SQLTokenContext.OPERATOR,
- SQLTokenContext.INT_LITERAL,
- });
- }
-
- public void testComments() {
- assertTokens("select /* block comment */ * from #notLineComment -- line comment",
- SQLTokenContext.KEYWORD,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.BLOCK_COMMENT,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.OPERATOR,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.KEYWORD,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.IDENTIFIER,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.LINE_COMMENT);
- // https://netbeans.org/bugzilla/show_bug.cgi?id=172904
- assertTokens("# MySQL Line Comment", SQLTokenContext.LINE_COMMENT);
- // https://netbeans.org/bugzilla/show_bug.cgi?id=181020
- assertTokens("# my line comment \nselect * from mytable",
- SQLTokenContext.LINE_COMMENT,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.KEYWORD,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.OPERATOR,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.KEYWORD,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.IDENTIFIER
- );
- // https://netbeans.org/bugzilla/show_bug.cgi?id=191188
- assertTokens("select * from mytable where id# = 1",
- SQLTokenContext.KEYWORD,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.OPERATOR,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.KEYWORD,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.IDENTIFIER,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.KEYWORD,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.IDENTIFIER,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.OPERATOR,
- SQLTokenContext.WHITESPACE,
- SQLTokenContext.INT_LITERAL);
- }
-
-
- public void testHashInIdentifier() {
- assertTokens("id# = 1", SQLTokenContext.IDENTIFIER, SQLTokenContext.WHITESPACE, SQLTokenContext.OPERATOR, SQLTokenContext.WHITESPACE, SQLTokenContext.INT_LITERAL);
- }
-
- private void assertTokens(String m, TokenID... tokens) {
- Syntax s = new SQLSyntax();
- s.load(null, m.toCharArray(), 0, m.length(), true, m.length());
-
- TokenID token = null;
- Iterator i = Arrays.asList(tokens).iterator();
- do {
- token = s.nextToken();
- if (token != null) {
- if (!i.hasNext()) {
- fail("More tokens returned than expected.");
- } else {
- assertSame("Tokens differ", i.next(), token);
- }
- } else {
- assertFalse("More tokens expected than returned.", i.hasNext());
- }
- if (token != null) {
- log(token.getName());
- }
- } while (token != null);
- }
-}