# HG changeset patch # User Matthias Bläsing # Date 1337284890 -7200 # Branch mb-patches-5 # Node ID 22fc4eab0a0ada8571064d4b2be0723a04d07a10 # Parent eff5f1ac40a88b0969a85f20cd207bbba5b29695 * Remove duplicated syntax support (SQLSyntax + SQLLexer) * Remove useless pseudo formatter * Add LanguageSupport for editor library 2 (remove dependency on pre65 module) * Rename token categories from SQLLexer to the names used in SQLSyntax to continue using the font settings diff --git a/db.sql.editor/nbproject/project.xml b/db.sql.editor/nbproject/project.xml --- a/db.sql.editor/nbproject/project.xml +++ b/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 diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/Bundle.properties b/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 +++ b/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" diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLEditorKit.java b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLEditorKit.java deleted file mode 100644 --- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLEditorKit.java +++ /dev/null @@ -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; - } - } -} diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLFormatter.java b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLFormatter.java deleted file mode 100644 --- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLFormatter.java +++ /dev/null @@ -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); - } -} diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLIndentEngine.java b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLIndentEngine.java deleted file mode 100644 --- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLIndentEngine.java +++ /dev/null @@ -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); - } -} diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLIndentEngineBeanInfo.java b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLIndentEngineBeanInfo.java deleted file mode 100644 --- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLIndentEngineBeanInfo.java +++ /dev/null @@ -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); - } - } - -} - diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSettingsInitializer.java b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSettingsInitializer.java deleted file mode 100644 --- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSettingsInitializer.java +++ /dev/null @@ -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(); - } -} diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSyntax.java b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSyntax.java deleted file mode 100644 --- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSyntax.java +++ /dev/null @@ -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; - } - } -} diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSyntaxSupport.java b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSyntaxSupport.java deleted file mode 100644 --- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLSyntaxSupport.java +++ /dev/null @@ -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 - }; - } -} diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLTypedTextInterceptor.java b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLTypedTextInterceptor.java new file mode 100644 --- /dev/null +++ b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLTypedTextInterceptor.java @@ -0,0 +1,132 @@ +/* + * 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.SQLTokenId; +import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor; + +/** + * + * @author matthias + */ +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 modifier = new Runnable() { + + public void run() { + int caretOffset = context.getOffset(); + String str = context.getText(); + + if (!str.isEmpty()) { + char insertedChar = str.charAt(str.length() - 1); + if (insertedChar == '\"' || insertedChar == '\'') { //NOI18N + if (canCompleteQuote(doc, caretOffset)) { + try { + // add pair quote + doc.insertString(caretOffset, String.valueOf(insertedChar), null); + context.getComponent().getCaret().setDot(caretOffset + str.length()); + } catch (BadLocationException ex) { + } + } + } + } + } + }; + + if (doc instanceof BaseDocument) { + ((BaseDocument) doc).runAtomic(modifier); + } else { + modifier.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; + } + + @Override + public void cancelled(Context context) { + } +} diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/NetBeans-SQL-preferences.xml b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/NetBeans-SQL-preferences.xml deleted file mode 100644 --- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/NetBeans-SQL-preferences.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/SQLIndentEngine.settings b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/SQLIndentEngine.settings deleted file mode 100644 --- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/SQLIndentEngine.settings +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml b/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 +++ b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml @@ -45,13 +45,6 @@ --> - - - - - - - @@ -80,22 +73,11 @@ - - - - - - - - - - - diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLLanguageConfig.java b/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLLanguageConfig.java new file mode 100644 --- /dev/null +++ b/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 new SQLLanguageHierarchy().language(); + } + + @Override + public String getDisplayName() { + return "SQL"; + } + + @Override + public String getLineCommentPrefix() { + return "-- "; + } + + +} diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLLanguageHierarchy.java b/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLLanguageHierarchy.java new file mode 100644 --- /dev/null +++ b/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLLanguageHierarchy.java @@ -0,0 +1,66 @@ +/* + * 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 java.util.Collection; +import java.util.EnumSet; +import org.netbeans.spi.lexer.LanguageHierarchy; +import org.netbeans.spi.lexer.Lexer; +import org.netbeans.spi.lexer.LexerRestartInfo; + +public class SQLLanguageHierarchy extends LanguageHierarchy { + + @Override + protected String mimeType() { + return "text/x-sql"; // NOI18N + } + + @Override + protected Collection createTokenIds() { + return EnumSet.allOf(SQLTokenId.class); + } + + @Override + protected Lexer createLexer(LexerRestartInfo info) { + return new SQLLexer(info); + } +} diff --git a/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLTokenId.java b/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 +++ b/db.sql.editor/src/org/netbeans/modules/db/sql/lexer/SQLTokenId.java @@ -64,20 +64,20 @@ // 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; @@ -90,35 +90,7 @@ return primaryCategory; } - private static final Language language = new LanguageHierarchy() { - - @Override - protected String mimeType() { - return "text/x-sql"; // NOI18N - } - - @Override - protected Collection createTokenIds() { - return EnumSet.allOf(SQLTokenId.class); - } - - @Override - protected Map> createTokenCategories() { - // XXX what comes here? - return Collections.emptyMap(); - } - - @Override - protected Lexer createLexer(LexerRestartInfo info) { - return new SQLLexer(info); - } - - @Override - protected LanguageEmbedding embedding( - Token token, LanguagePath languagePath, InputAttributes inputAttributes) { - return null; - } - }.language(); + private static final Language language = new SQLLanguageHierarchy().language(); public static Language language() { return language; diff --git a/db.sql.editor/test/unit/src/org/netbeans/modules/db/sql/editor/SQLSyntaxTest.java b/db.sql.editor/test/unit/src/org/netbeans/modules/db/sql/editor/SQLSyntaxTest.java deleted file mode 100644 --- a/db.sql.editor/test/unit/src/org/netbeans/modules/db/sql/editor/SQLSyntaxTest.java +++ /dev/null @@ -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); - } -}