1.1 --- a/o.n.antlr.editor/nbproject/project.xml Tue Jan 15 12:37:50 2013 +0100
1.2 +++ b/o.n.antlr.editor/nbproject/project.xml Tue Jan 15 16:03:36 2013 +0100
1.3 @@ -32,6 +32,24 @@
1.4 </run-dependency>
1.5 </dependency>
1.6 <dependency>
1.7 + <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
1.8 + <build-prerequisite/>
1.9 + <compile-dependency/>
1.10 + <run-dependency>
1.11 + <release-version>2</release-version>
1.12 + <specification-version>1.31</specification-version>
1.13 + </run-dependency>
1.14 + </dependency>
1.15 + <dependency>
1.16 + <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
1.17 + <build-prerequisite/>
1.18 + <compile-dependency/>
1.19 + <run-dependency>
1.20 + <release-version>3</release-version>
1.21 + <specification-version>3.33</specification-version>
1.22 + </run-dependency>
1.23 + </dependency>
1.24 + <dependency>
1.25 <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
1.26 <build-prerequisite/>
1.27 <compile-dependency/>
2.1 --- a/o.n.antlr.editor/src/org/netbeans/modules/antlr/editor/AntlrCslLanguage.java Tue Jan 15 12:37:50 2013 +0100
2.2 +++ b/o.n.antlr.editor/src/org/netbeans/modules/antlr/editor/AntlrCslLanguage.java Tue Jan 15 16:03:36 2013 +0100
2.3 @@ -45,6 +45,7 @@
2.4 import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
2.5 import org.netbeans.modules.csl.api.CodeCompletionHandler;
2.6 import org.netbeans.modules.csl.api.DeclarationFinder;
2.7 +import org.netbeans.modules.csl.api.Formatter;
2.8 import org.netbeans.modules.csl.api.OccurrencesFinder;
2.9 import org.netbeans.modules.csl.api.SemanticAnalyzer;
2.10 import org.netbeans.modules.csl.api.StructureScanner;
2.11 @@ -139,6 +140,16 @@
2.12 public CodeCompletionHandler getCompletionHandler() {
2.13 return new AntlrCompletionHandler();
2.14 }
2.15 +
2.16 + @Override
2.17 + public Formatter getFormatter() {
2.18 + return new AntlrFormatter();
2.19 + }
2.20 +
2.21 + @Override
2.22 + public boolean hasFormatter() {
2.23 + return true;
2.24 + }
2.25
2.26
2.27
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/o.n.antlr.editor/src/org/netbeans/modules/antlr/editor/AntlrFormatter.java Tue Jan 15 16:03:36 2013 +0100
3.3 @@ -0,0 +1,100 @@
3.4 +/*
3.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3.6 + *
3.7 + * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
3.8 + *
3.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
3.10 + * Other names may be trademarks of their respective owners.
3.11 + *
3.12 + * The contents of this file are subject to the terms of either the GNU
3.13 + * General Public License Version 2 only ("GPL") or the Common
3.14 + * Development and Distribution License("CDDL") (collectively, the
3.15 + * "License"). You may not use this file except in compliance with the
3.16 + * License. You can obtain a copy of the License at
3.17 + * http://www.netbeans.org/cddl-gplv2.html
3.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
3.19 + * specific language governing permissions and limitations under the
3.20 + * License. When distributing the software, include this License Header
3.21 + * Notice in each file and include the License file at
3.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
3.23 + * particular file as subject to the "Classpath" exception as provided
3.24 + * by Oracle in the GPL Version 2 section of the License file that
3.25 + * accompanied this code. If applicable, add the following below the
3.26 + * License Header, with the fields enclosed by brackets [] replaced by
3.27 + * your own identifying information:
3.28 + * "Portions Copyrighted [year] [name of copyright owner]"
3.29 + *
3.30 + * If you wish your version of this file to be governed by only the CDDL
3.31 + * or only the GPL Version 2, indicate your decision by adding
3.32 + * "[Contributor] elects to include this software in this distribution
3.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
3.34 + * single choice of license, a recipient has the option to distribute
3.35 + * your version of this file under either the CDDL, the GPL Version 2 or
3.36 + * to extend the choice of license to its licensees as provided above.
3.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
3.38 + * Version 2 license, then the option applies only if the new code is
3.39 + * made subject to such option by the copyright holder.
3.40 + *
3.41 + * Contributor(s):
3.42 + *
3.43 + * Portions Copyrighted 2013 Sun Microsystems, Inc.
3.44 + */
3.45 +package org.netbeans.modules.antlr.editor;
3.46 +
3.47 +import javax.swing.text.BadLocationException;
3.48 +import javax.swing.text.Document;
3.49 +import org.netbeans.editor.BaseDocument;
3.50 +import org.netbeans.editor.Utilities;
3.51 +import org.netbeans.modules.csl.api.Formatter;
3.52 +import org.netbeans.modules.csl.spi.ParserResult;
3.53 +import org.netbeans.modules.editor.indent.api.IndentUtils;
3.54 +import org.netbeans.modules.editor.indent.spi.Context;
3.55 +import org.openide.util.Exceptions;
3.56 +
3.57 +/**
3.58 + *
3.59 + * @author marekfukala
3.60 + */
3.61 +public class AntlrFormatter implements Formatter {
3.62 +
3.63 + @Override
3.64 + public void reformat(Context context, ParserResult compilationInfo) {
3.65 + }
3.66 +
3.67 + @Override
3.68 + public void reindent(final Context context) {
3.69 + if (context.startOffset() == context.endOffset()) {
3.70 + //new line indent
3.71 + final BaseDocument document = (BaseDocument) context.document();
3.72 + document.runAtomic(new Runnable() {
3.73 + @Override
3.74 + public void run() {
3.75 + try {
3.76 + int rowIndent = Utilities.getRowIndent(document, context.startOffset() - 1);
3.77 + if(rowIndent != -1) {
3.78 + String indentString = IndentUtils.createIndentString(document, rowIndent);
3.79 + document.insertString(context.caretOffset(), indentString, null);
3.80 + }
3.81 + } catch (BadLocationException ex) {
3.82 + Exceptions.printStackTrace(ex);
3.83 + }
3.84 + }
3.85 + });
3.86 + }
3.87 + }
3.88 +
3.89 + @Override
3.90 + public boolean needsParserResult() {
3.91 + return false;
3.92 + }
3.93 +
3.94 + @Override
3.95 + public int indentSize() {
3.96 + return 4;
3.97 + }
3.98 +
3.99 + @Override
3.100 + public int hangingIndentSize() {
3.101 + return 4;
3.102 + }
3.103 +}