--- a/java.editor/src/org/netbeans/modules/java/editor/TalkToEditorImpl.java +++ a/java.editor/src/org/netbeans/modules/java/editor/TalkToEditorImpl.java @@ -0,0 +1,110 @@ +/* + * 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.java.editor; + +import java.beans.PropertyChangeListener; +import java.util.prefs.Preferences; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import javax.swing.text.JTextComponent; +import org.netbeans.api.editor.EditorRegistry; +import org.netbeans.editor.GuardedDocument; +import org.netbeans.modules.editor.indent.api.IndentUtils; +import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; +import org.netbeans.modules.java.preprocessorbridge.api.FmtConstants; +import org.netbeans.modules.java.preprocessorbridge.spi.TalkToEditor; +import org.openide.filesystems.FileObject; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author Jaroslav Tulach + */ +@ServiceProvider(service=TalkToEditor.class) +public final class TalkToEditorImpl extends TalkToEditor { + @Override + protected Preferences implCodePreferences(FileObject file) { + return CodeStylePreferences.get(file, FmtConstants.JAVA_MIME_TYPE).getPreferences(); + } + + @Override + protected Preferences implCodePreferences(Document doc) { + return CodeStylePreferences.get(doc, FmtConstants.JAVA_MIME_TYPE).getPreferences(); + } + + @Override + protected JTextComponent implLastFocusedComponent() { + return EditorRegistry.lastFocusedComponent(); + } + + @Override + protected JTextComponent implFocusedComponent() { + return EditorRegistry.focusedComponent(); + } + + @Override + protected void implAddRemoveListener(PropertyChangeListener pcl, boolean toAdd) { + if (toAdd) { + EditorRegistry.addPropertyChangeListener(pcl); + } else { + EditorRegistry.removePropertyChangeListener(pcl); + } + } + + @Override + protected int implOffsetIndent(Document doc, int offset) throws BadLocationException { + int lineStartOffset = IndentUtils.lineStartOffset(doc, offset); + return IndentUtils.lineIndent(doc, lineStartOffset); + } + + @Override + protected boolean implCheckGuarded(Document doc, int pos, long treePos) { + if (!(doc instanceof GuardedDocument)) { + return true; + } + pos = ((GuardedDocument) doc).getGuardedBlockChain().adjustToBlockEnd(pos); + if (treePos < 0 || pos <= treePos) { + return true; + } + return false; + } +} --- a/java.source/src/org/netbeans/modules/java/ui/Bundle.properties +++ a/java.source/src/org/netbeans/modules/java/ui/Bundle.properties @@ -1,6 +1,6 @@ # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # -# Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. +# 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. @@ -23,12 +23,6 @@ # 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 @@ -39,470 +33,13 @@ # 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. -# Formating options - -LBL_TabsAndIndents=Tabs and Indents -LBL_CodeGeneration=Code Generation -LBL_Alignment=Alignment -LBL_Braces=Braces -LBL_Wrapping=Wrapping -LBL_BlankLines=Blank Lines -LBL_Spaces=Spaces -LBL_Imports=Imports - -LBL_bp_SAME_LINE=Same Line -LBL_bp_NEW_LINE=New Line -LBL_bp_NEW_LINE_HALF_INDENTED=New Line Half Indented -LBL_bp_NEW_LINE_INDENTED= New Line Indented - -LBL_bg_GENERATE=Generate -LBL_bg_LEAVE_ALONE=Leave Alone -LBL_bg_ELIMINATE=Eliminate - -LBL_wrp_WRAP_ALWAYS=Always -LBL_wrp_WRAP_IF_LONG=If Long -LBL_wrp_WRAP_NEVER=Never - -LBL_ip_CARET_LOCATION=Caret Location -LBL_ip_FIRST_IN_CATEGORY=First In Category -LBL_ip_LAST_IN_CATEGORY=Last In Category - -LBL_ExpandTabToSpaces=&Expand Tab to Spaces -LBL_TabSize=&Tab Size: -LBL_IndentSize=&Indentation Size: -LBL_ContinuationIndentSize=&Continuation Indentation Size: -LBL_LabelIndent=&Label Indentation\: -LBL_AbsoluteLabelIndent=&Absolute Label Indentation -LBL_IndentTopLevelClassMemberts=&Indent Top Level Class Members -LBL_AddLeadingStarInComment=A&dd Leading Star In Comment -LBL_RightMargin=&Right Margin: - -LBL_gen_Naming=Naming Conventions\: -LBL_gen_PreferLongerNames=Prefer Longer Names -LBL_gen_UseIsForBooleanGetters=Use Is For Boolean Getters -LBL_gen_Prefix=Prefix -LBL_gen_Suffix=Suffix -LBL_gen_Field=Field\: -LBL_gen_StaticField=Static Field\: -LBL_gen_Parameter=Parameter\: -LBL_gen_LocalVariable=Local Variable\: -LBL_gen_Other=Other\: -LBL_gen_QualifyFieldAccess=Qualify Field Access -LBL_gen_AddOverrideAnnotation=Add Override Annotation -LBL_gen_ParametersFinal=Make Generated Parameters Final -LBL_gen_LocalVariablesFinal=Make Generated Local variables Final -LBL_gen_MembersOreder=Members Sort Order\: -LBL_gen_MembersOrederUp=Move Up -LBL_gen_MembersOrederDown=Move Down -LBL_gen_SortByVisibility=Sort Members By Visibility -LBL_gen_InsertionPoint=Insertion Point\: - -VAL_gen_STATIC=Static -VAL_gen_CLASS=Classes -VAL_gen_CONSTRUCTOR=Constructors -VAL_gen_FIELD=Fields -VAL_gen_INSTANCE_INIT=Instance Initializers -VAL_gen_METHOD=Methods -VAL_gen_STATIC_INIT=Static Initializers - -VAL_gen_PUBLIC=Public -VAL_gen_PRIVATE=Private -VAL_gen_PROTECTED=Protected -VAL_gen_DEFAULT=Default - -LBL_blBeforePackage=Before &Package\: -LBL_blAfterPackage=After Packa&ge\: -LBL_blBeforeImports=Before &Imports\: -LBL_blAfterImports=After Imports\: -LBL_blBeforeClass=Before &Class\: -LBL_blAfterClass=After C&lass\: -LBL_blAfterClassHeader=After Class &Header\: -LBL_blAfterAnonymousClassHeader=After &Anonymous Class Header: -LBL_blBeforeFields=Before &Field\: -LBL_blAfterFields=After Fi&eld\: -LBL_blBeforeMethods=Before &Method\: -LBL_blAfterMethods=After Me&thod\: - -LBL_BeforeKeywords=Before Keywords -LBL_spaceBeforeWhile="while" -LBL_spaceBeforeElse="else" -LBL_spaceBeforeCatch="catch" -LBL_spaceBeforeFinally="finally" - -LBL_BeforeParentheses=Before Parentheses -LBL_spaceBeforeMethodDeclParen=Method Declaration -LBL_spaceBeforeMethodCallParen=Method Call -LBL_spaceBeforeIfParen="if" -LBL_spaceBeforeForParen="for" -LBL_spaceBeforeWhileParen="while" -LBL_spaceBeforeTryParen="try" -LBL_spaceBeforeCatchParen="catch" -LBL_spaceBeforeSwitchParen="switch" -LBL_spaceBeforeSynchronizedParen="synchronized" -LBL_spaceBeforeAnnotationParen=Annotation Parameters - -LBL_AroundOperators=Around Operators -LBL_spaceAroundUnaryOps=Unary Operators -LBL_spaceAroundBinaryOps=Binary Operators -LBL_spaceAroundTernaryOps=Ternary Operators -LBL_spaceAroundAssignOps=Assignment Operators -LBL_spaceAroundAnnotationValueAssignOps=Annotation Value Assignment Operator - -LBL_BeforeLeftBraces=Before Left Braces -LBL_spaceBeforeClassDeclLeftBrace=Class Declaration -LBL_spaceBeforeMethodDeclLeftBrace=Method Declaration -LBL_spaceBeforeIfLeftBrace="if" -LBL_spaceBeforeElseLeftBrace="else" -LBL_spaceBeforeWhileLeftBrace="while" -LBL_spaceBeforeForLeftBrace="for" -LBL_spaceBeforeDoLeftBrace="do" -LBL_spaceBeforeSwitchLeftBrace="switch" -LBL_spaceBeforeTryLeftBrace="try" -LBL_spaceBeforeCatchLeftBrace="catch" -LBL_spaceBeforeFinallyLeftBrace="finally" -LBL_spaceBeforeSynchronizedLeftBrace="synchronized" -LBL_spaceBeforeStaticInitLeftBrace=Static Initializer -LBL_spaceBeforeArrayInitLeftBrace=Array Initializer - -LBL_WithinParentheses=Within Parentheses -LBL_spaceWithinParens=Parentheses -LBL_spaceWithinMethodDeclParens=Method Declaration -LBL_spaceWithinMethodCallParens=Method Call -LBL_spaceWithinIfParens="if" -LBL_spaceWithinForParens="for" -LBL_spaceWithinWhileParens="while" -LBL_spaceWithinSwitchParens="switch" -LBL_spaceWithinTryParens="try" -LBL_spaceWithinCatchParens="catch" -LBL_spaceWithinSynchronizedParens="synchronized" -LBL_spaceWithinTypeCastParens=Type Cast -LBL_spaceWithinAnnotationParens=Annotation -LBL_spaceWithinBraces=Braces -LBL_spaceWithinArrayInitBrackets=Array Initializer Brackets - -LBL_Other=Other -LBL_spaceBeforeComma=Before Comma -LBL_spaceAfterComma=After Comma -LBL_spaceBeforeSemi=Before Semicolon -LBL_spaceAfterSemi=After Semicolon -LBL_spaceBeforeColon=Before Colon -LBL_spaceAfterColon=After Colon -LBL_spaceAfterTypeCast=After Type Cast - -LBL_wrp_extendsImplementsKeyword=&Extends/Implements Keyword\: -LBL_wrp_extendsImplementsList=E&xtends/Implements List\: -LBL_wrp_methodParameters=Method &Parameters\: -LBL_wrp_throwsKeyword=&Throws Keyword\: -LBL_wrp_throwsList=Th&rows List\: -LBL_wrp_methodCallArgs=Method Call Arguments\: -LBL_wrp_annotationArgs=Annotation Arg&uments\: -LBL_wrp_chainedMethodCalls=C&hained Method Calls\: -LBL_wrp_afeterDot=Wrap After Dot In Chained Method Call -LBL_wrp_arrayInit=Array Initiali&zer\: -LBL_wrp_tryResources=Try Re&sources\: -LBL_wrp_multiCatches=Dis&junctive Catch Types\: -LBL_wrp_for=&For\: -LBL_wrp_forStatement=F&or Statement\: -LBL_wrp_ifStatement=&If Statement\: -LBL_wrp_whileStatement=&While Statement\: -LBL_wrp_doWhileStatement=&Do ... While Statement -LBL_wrp_assert=&Assert\: -LBL_wrp_enumConstants=Enum &Constants\: -LBL_wrp_annotations=A&nnotations\: -LBL_wrp_binaryOps=&Binary Operators\: -LBL_wrp_afeterBinaryOps=Wrap After Binary Operators -LBL_wrp_ternaryOps=Ternar&y Operators\: -LBL_wrp_afterTernaryOps=Wrap After Ternary Operators -LBL_wrp_assignOps=Assi&gnment Operators\: - -LBL_br_bracesPlacement=Braces Placement -LBL_br_bracesGeneration=Braces Generation -LBL_al_newLines=New Lines -LBL_al_multilineAlignment=Multiline Alignment -LBL_bp_ClassDecl=&Class Declaration\: -LBL_bp_MethodDecl=&Method Declaration\: -LBL_bp_Other=&Other\: -LBL_bp_SpecialElseIf=&Special "else if" Treatment -LBL_bg_If="&if"\: -LBL_bg_For="&for"\: -LBL_bg_While="&while"\: -LBL_bg_DoWhile="&do ... while"\: -LBL_nl_Else="&else" -LBL_nl_While="w&hile" -LBL_nl_Catch="c&atch" -LBL_nl_Finally="finall&y" -LBL_nl_Modifiers=After modifie&rs -LBL_am_MethodParams=Method &Parameters -LBL_am_CallArgs=Method Call Arg&uments -LBL_am_AnnotationArgs=&Annotation Arguments -LBL_an_Implements=I&mplements List -LBL_am_Throws=&Throws List -LBL_am_Paren=Parenthesize&d -LBL_am_BinaryOp=&Binary Operators -LBL_am_TernaryOp=Ter&nary Operators -LBL_am_Assign=Assi&gnment -LBL_am_For=&For -LBL_am_ArrayInit=Array Initiali&zer -LBL_am_TryResources=Try Re&sources -LBL_am_MultiCatch=Dis&junctive Catch Types - -LBL_IndentCasesFromSwitch=Indent Case Statements In &Switch - -LBL_Comments=Comments -LBL_doc_enableCommentFormat=Enable Comments Formatting -LBL_doc_enableBlockCommentFormat=Format Block Comments -LBL_doc_generalLabel=General -LBL_doc_addLeadingStar=Add Leading Star -LBL_doc_wrapCommentText=Wrap Text At Right Margin -LBL_doc_wrapOneLineCheckBox=Wrap One Line Comments -LBL_doc_preserveNewLinesCheckBox=Preserve New Lines -LBL_doc_javadocLabel=Javadoc -LBL_doc_blankLineAfterDescCheckBox=Add Blank Line After Description -LBL_doc_blankLineAfterParamsCheckBox=Add Blank Line After Parameter Descriptions -LBL_doc_blankLineAfterReturnCheckBox=Add Blank Line After Return Tag -LBL_doc_generatePCheckBox=Generate "

" On Blank Lines -LBL_doc_alignParamsCheckBox=Align Parameter Descriptions -LBL_doc_alignReturnCheckBox=Align Return Value Descriptions -LBL_doc_alignExceptionsCheckBox=Align Exception Descriptions - -LBL_imp_useSingleClass=Use Single Class Imports -LBL_imp_usePackage=Use Package Imports -LBL_imp_useFQN=Use Fully Qualified Names -LBL_imp_importTreshold=Class Count To Use Star Import -LBL_imp_staticImportTreshold=Members Count To Use Static Star Import -LBL_imp_importInnerClasses=Import Inner Classes -LBL_imp_starImportPackages=Packages To Use Star Import: -LBL_imp_importLayout=Import Layout: -LBL_imp_separateStaticImports=Separate Static Imports -LBL_imp_add=Add -LBL_imp_remove=Remove -LBL_imp_moveUp=Move Up -LBL_imp_moveDown=Move Down -LBL_imp_separateGroups=Separate Groups -LBL_imp_allOtherImports= -LBL_imp_Package=Package -LBL_imp_WithSub=* -LBL_imp_Static=Static - -# Following entries (marked) as samples are used as examples in the formating -# options. It is highly discourage to localize them unless absolutely necessary. - -SAMPLE_Default=public class ClassA {\ -public int number = 1;\ -private String text ="A";\ -public ClassA() {\ -}\ -public void meth(String text, int number) {\ -}\ -} - -SAMPLE_TabsIndents=public class ClassA {\ -public int number = 1;\ -private String letters[] = new String[]{ "A", "B" };\ -public int meth(String text, int number) {\ -if ( text == null ) {\ - text = "a";\ -}\ -else if (text.length() == 0) {\ - text = "empty";\ -}\ -else {\ - number++;\ -}\ -label:\ -switch(number) {\ -case 1\:\ - return meth("text", 22);\ -case 2\:\ - return 20;\ -default\:\ - return -1;\ -}\ -} } - -SAMPLE_Align=@Anno(paramA="aValue", paramB="bValue")\ -public class ClassA implements InterfaceA, InterfaceB {\ -private String letters[] = new String[]{"A", "B"};\ -public int meth(String text, int number) throws ExceptionA, ExceptionB {\ -if ( text != null ) {\ -try {\ -meth( "Some text", text.length());\ -} catch ( Throwable t ) {\ -} finally {\ -}\ -} else {\ -text = number == 0 ? "empty" : "nonempty";\ -}\ -do {\ -number =\nnumber + 1;\ -} while (number < 2);\ -for( int i = 1; i < 100; i++ ) {\ -number = (number +\ni) * 2;\ -}\ -}\ -} - -SAMPLE_Braces=public class ClassA {\ -private String letters[] = new String[]{"A", "B"};\ -public int meth(String text, int number) {\ -if ( text != null ) {\ -try {\ -meth( "Some text", text.length());\ -} catch ( Throwable t ) {\ -} finally {\ -}\ -} else {\ -text = number == 0 ? "empty" : "nonempty";\ -}\ -do {\ -number = number + 1;\ -} while (number < 2);\ -for( int i = 1; i < 100; i++ ) {\ -number = number + i;\ -}\ -while(number > 0) {\ -number--;\ -}\ -}\ -} - -SAMPLE_Wrapping=@Anno(paramA="a Value", paramB="bValue")\ -@Deprecated \ -public class ClassA extends Object implements InterfaceA, InterfaceB, InterfaceC {\ -private static final String letters[] = new String[]{ "A", "B", "C", "D" };\ -public int number = 1;\ -public ClassA() {\ -}\ -public int method(String text, int number, Object object) throws ExceptionA, ExceptionB {\ -assert nuber + text.length() < 20 : "message";\ -if (number==13 && object instanceof Runnable )\ -method( "Some text", 12, new Object());\ -for( int i = 1; i < 100; i++ )\ -System.out.print(i);\ -while ( this.number < 2 && number != 3 )\ -this.number++;\ -do \ -method1().method2().method3();\ -while ( this.number < 2 && number != 3 );\ -return number > 100 ? -1 : -2;\ -}\ -public enum Where {\ -NORTH, EAST, SOUTH, WEST;\ -}\ -} - - -SAMPLE_BlankLines=package org.netbeans.samples;\ -import java.util.List;\ -import java.util.Map;\ -\ -public class ClassA {\ -public int i;\ -public int j;\ -\ -public ClassA() {\ -}\ -public void methodA() {\ -new Runnable() {\ -public void run() {\ -}\ -};\ -}\ -public void methodB() {\ -}\ -public class innerClass {\ -}\ -public static interface innerInterface {\ -}\ -} - -SAMPLE_Spaces=@Anno(paramA="aValue", paramB="bValue")\ -public class ClassA {\ -public int number = 1;\ -private String text ="A";\ -static float[] floats = new float[3];\ -protected double[] doubles = new double[]{3.67,40,2e-30};\ -\ -static {\ - floats[0]=12.6f;\ -}\ -\ -public ClassA() {\ -}\ -public int meth(String text, int number) {\ -if (number==13) {\ -return (int)System.currentTimeMillis();\ -}else {\ -}\ -\ -for( int i = 20; i < 100; i++) {\ - synchronized(this) {\ - while(i%13>5)\ - meth( text + " ", number++);\ - }\ -}\ -\ -for(float f : floats)\ - System.out.println(f);\ -\ -switch(number) {\ -case 1\:\ - do { out( (2+3)*this.number--); } while(this.number > 6);\ - return 10;\ -case 2\:\ - try {\ - toString();\ - }\ - catch ( IllegalStateException illegalStateException ) {\ - illegalStateException.printStackTrace();\ - }\ - finally {\ - return 20;\ - }\ -default\:\ - return number > 100 ? -1 : -2;\ -}\ -} } - -SAMPLE_Comments=public class ClassA {\n\ -/**\n\ -This is the first part of a sample method description.\n\ -The second part is placed after a manual newline.\n\ -\n\ -The last part is placed after an empty line.\n\ -@param text the first parameter description\n\ -@param number the second parameter description\n\ -@return this is the return value description\n\ -@throws ExcepA the first exception description\n\ -@throws ExcB the second exception description\n\ -*/\n\ -public String meth(String text, int number) throws ExceptionA, ExcB {\n\ -/*This is one line comment*/\n\ -return number > 0 ? text : null;\n\ -}\n\ -} - -SAMPLE_Imports=package org.netbeans.samples;\ -\ -public class ClassA {\ -\ -public void method() {\ -}\ -} - -SAMPLE_CodeGen=public class ClassA {\ -\ -private String name;\ -} - -nlFinallyCheckBox1.text="finall&y" - -AN_Preview=Preview -AD_Preview=Preview +FmtTabsIndents.continuationIndentSizeField.AccessibleContext.accessibleDescription=Indent size in spaces FmtTabsIndents.absoluteLabelIndentCheckBox.AccessibleContext.accessibleDescription=Indent Labels absolutely -FmtTabsIndents.addLeadingStarInCommentCheckBox.AccessibleContext.accessibleDescription=Comment lines starting with leading star +FmtTabsIndents.labelIndentField.AccessibleContext.accessibleDescription=Label indentation size in spaces FmtTabsIndents.indentCasesFromSwitchCheckBox.AccessibleContext.accessibleDescription=Additional indent for case statements FmtTabsIndents.indentTopLevelClassMembersCheckBox.AccessibleContext.accessibleDescription=Indent for top-level class members -FmtTabsIndents.continuationIndentSizeField.AccessibleContext.accessibleDescription=Indent size in spaces -FmtTabsIndents.labelIndentField.AccessibleContext.accessibleDescription=Label indentation size in spaces --- a/java.editor/src/org/netbeans/modules/java/ui/CategorySupport.java +++ a/java.editor/src/org/netbeans/modules/java/ui/CategorySupport.java @@ -0,0 +1,496 @@ +/* + * 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.java.ui; + +import java.awt.Component; +import java.awt.Container; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.LinkedList; +import java.util.List; +import java.util.prefs.Preferences; +import javax.swing.ComboBoxModel; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JEditorPane; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JSpinner; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.JToggleButton; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.event.ListDataEvent; +import javax.swing.event.ListDataListener; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import org.netbeans.api.editor.settings.SimpleValueNames; +import org.netbeans.api.java.source.CodeStyle; +import org.netbeans.api.java.source.CodeStyle.BracePlacement; +import org.netbeans.api.java.source.CodeStyle.BracesGenerationStyle; +import org.netbeans.api.java.source.CodeStyle.InsertionPoint; +import org.netbeans.api.java.source.CodeStyle.WrapStyle; +import org.netbeans.modules.java.preprocessorbridge.api.FmtConstants; +//XXX: import org.netbeans.modules.java.source.save.Reformatter; +import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; +import org.netbeans.modules.options.editor.spi.PreviewProvider; +import org.openide.text.CloneableEditorSupport; +import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; + +// Support section --------------------------------------------------------- + +public class CategorySupport implements ActionListener, ChangeListener, ListDataListener, TableModelListener, DocumentListener, PreviewProvider, PreferencesCustomizer { + public static final String OPTION_ID = "org.netbeans.modules.java.ui.FormatingOptions.ID"; + private static final int LOAD = 0; + private static final int STORE = 1; + private static final int ADD_LISTENERS = 2; + private static final ComboItem[] bracePlacement = new ComboItem[]{new ComboItem(BracePlacement.SAME_LINE.name(), "LBL_bp_SAME_LINE"), new ComboItem(BracePlacement.NEW_LINE.name(), "LBL_bp_NEW_LINE"), new ComboItem(BracePlacement.NEW_LINE_HALF_INDENTED.name(), "LBL_bp_NEW_LINE_HALF_INDENTED"), new ComboItem(BracePlacement.NEW_LINE_INDENTED.name(), "LBL_bp_NEW_LINE_INDENTED")}; + private static final ComboItem[] bracesGeneration = new ComboItem[]{new ComboItem(BracesGenerationStyle.GENERATE.name(), "LBL_bg_GENERATE"), new ComboItem(BracesGenerationStyle.LEAVE_ALONE.name(), "LBL_bg_LEAVE_ALONE"), new ComboItem(BracesGenerationStyle.ELIMINATE.name(), "LBL_bg_ELIMINATE")}; + private static final ComboItem[] wrap = new ComboItem[]{new ComboItem(WrapStyle.WRAP_ALWAYS.name(), "LBL_wrp_WRAP_ALWAYS"), new ComboItem(WrapStyle.WRAP_IF_LONG.name(), "LBL_wrp_WRAP_IF_LONG"), new ComboItem(WrapStyle.WRAP_NEVER.name(), "LBL_wrp_WRAP_NEVER")}; + private static final ComboItem[] insertionPoint = new ComboItem[]{new ComboItem(InsertionPoint.LAST_IN_CATEGORY.name(), "LBL_ip_LAST_IN_CATEGORY"), new ComboItem(InsertionPoint.FIRST_IN_CATEGORY.name(), "LBL_ip_FIRST_IN_CATEGORY"), new ComboItem(InsertionPoint.CARET_LOCATION.name(), "LBL_ip_CARET_LOCATION")}; + protected final String previewText; + // private String forcedOptions[][]; + // private boolean changed = false; + // private boolean loaded = false; + private final String id; + protected final JPanel panel; + private final List components = new LinkedList(); + private JEditorPane previewPane; + protected final Preferences preferences; + protected final Preferences previewPrefs; + + protected CategorySupport(Preferences preferences, String id, JPanel panel, String previewText, String[]... forcedOptions) { + this.preferences = preferences; + this.id = id; + this.panel = panel; + this.previewText = previewText != null ? previewText : NbBundle.getMessage(CategorySupport.class, "SAMPLE_Default"); //NOI18N + // Scan the panel for its components + scan(panel, components); + // Initialize the preview preferences + Preferences forcedPrefs = new PreviewPreferences(); + for (String[] option : forcedOptions) { + forcedPrefs.put(option[0], option[1]); + } + this.previewPrefs = new ProxyPreferences(forcedPrefs, preferences); + // Load and hook up all the components + loadFrom(preferences); + addListeners(); + } + + protected void addListeners() { + scan(ADD_LISTENERS, null); + } + + protected void loadFrom(Preferences preferences) { + // loaded = true; + scan(LOAD, preferences); + // loaded = false; + } + + // + // public void applyChanges() { + // storeTo(preferences); + // } + // + protected void storeTo(Preferences p) { + scan(STORE, p); + } + + protected void notifyChanged() { + // if (loaded) + // return; + storeTo(preferences); + refreshPreview(); + } + + protected void loadListData(final JList list, final String optionID, final Preferences p) { + } + + protected void storeListData(final JList list, final String optionID, final Preferences node) { + } + + protected void loadTableData(final JTable table, final String optionID, final Preferences p) { + } + + protected void storeTableData(final JTable table, final String optionID, final Preferences node) { + } + + // ActionListener implementation --------------------------------------- + public void actionPerformed(ActionEvent e) { + notifyChanged(); + } + + // ChangeListener implementation --------------------------------------- + @Override + public void stateChanged(ChangeEvent e) { + notifyChanged(); + } + + // ListDataListener implementation ----------------------------------- + @Override + public void contentsChanged(ListDataEvent e) { + } + + @Override + public void intervalAdded(ListDataEvent e) { + notifyChanged(); + } + + @Override + public void intervalRemoved(ListDataEvent e) { + } + + // TableModelListener implementation ----------------------------------- + @Override + public void tableChanged(TableModelEvent e) { + notifyChanged(); + } + + // DocumentListener implementation ------------------------------------- + public void insertUpdate(DocumentEvent e) { + notifyChanged(); + } + + public void removeUpdate(DocumentEvent e) { + notifyChanged(); + } + + public void changedUpdate(DocumentEvent e) { + notifyChanged(); + } + + // PreviewProvider methods ----------------------------------------------------- + public JComponent getPreviewComponent() { + if (previewPane == null) { + previewPane = new JEditorPane(); + previewPane.getAccessibleContext().setAccessibleName(NbBundle.getMessage(CategorySupport.class, "AN_Preview")); //NOI18N + previewPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CategorySupport.class, "AD_Preview")); //NOI18N + previewPane.putClientProperty("HighlightsLayerIncludes", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.SyntaxHighlighting$"); //NOI18N + previewPane.setEditorKit(CloneableEditorSupport.getEditorKit("text/x-java")); + previewPane.setEditable(false); + } + return previewPane; + } + + public void refreshPreview() { + JEditorPane jep = (JEditorPane) getPreviewComponent(); + try { + int rm = previewPrefs.getInt(FmtConstants.rightMargin, FmtConstants.getDefaultAsInt(FmtConstants.rightMargin)); + jep.putClientProperty("TextLimitLine", rm); //NOI18N + jep.getDocument().putProperty(SimpleValueNames.TEXT_LINE_WRAP, ""); //NOI18N + jep.getDocument().putProperty(SimpleValueNames.TAB_SIZE, ""); //NOI18N + jep.getDocument().putProperty(SimpleValueNames.TEXT_LIMIT_WIDTH, ""); //NOI18N + } catch (NumberFormatException e) { + // Ignore it + } + try { + Class.forName(CodeStyle.class.getName(), true, CodeStyle.class.getClassLoader()); + } catch (ClassNotFoundException cnfe) { + // ignore + } + + /** XXX: Another reference to Reformatter: + CodeStyle codeStyle = FmtConstants.codeStyleProducer.create(previewPrefs); + jep.setIgnoreRepaint(true); + jep.setText(Reformatter.reformat(previewText, codeStyle)); + */ + jep.setIgnoreRepaint(false); + jep.scrollRectToVisible(new Rectangle(0, 0, 10, 10)); + jep.repaint(100); + } + + // PreferencesCustomizer implementation -------------------------------- + public JComponent getComponent() { + return panel; + } + + public String getDisplayName() { + return panel.getName(); + } + + public String getId() { + return id; + } + + public HelpCtx getHelpCtx() { + return null; + } + + // PreferencesCustomizer.Factory implementation ------------------------ + public static final class Factory implements PreferencesCustomizer.Factory { + + private final String id; + private final Class panelClass; + private final String previewText; + private final String[][] forcedOptions; + + public Factory(String id, Class panelClass, String previewText, String[]... forcedOptions) { + this.id = id; + this.panelClass = panelClass; + this.previewText = previewText; + this.forcedOptions = forcedOptions; + } + + public PreferencesCustomizer create(Preferences preferences) { + try { + CategorySupport categorySupport = new CategorySupport(preferences, id, panelClass.newInstance(), previewText, forcedOptions); + if (categorySupport.panel instanceof Runnable) { + ((Runnable) categorySupport.panel).run(); + } + return categorySupport; + } catch (Exception e) { + return null; + } + } + } // End of CategorySupport.Factory class + + // Private methods ----------------------------------------------------- + private void performOperation(int operation, JComponent jc, String optionID, Preferences p) { + switch (operation) { + case LOAD: + loadData(jc, optionID, p); + break; + case STORE: + storeData(jc, optionID, p); + break; + case ADD_LISTENERS: + addListener(jc); + break; + } + } + + private void scan(int what, Preferences p) { + for (JComponent jc : components) { + Object o = jc.getClientProperty(OPTION_ID); + if (o instanceof String) { + performOperation(what, jc, (String) o, p); + } else if (o instanceof String[]) { + for (String oid : (String[]) o) { + performOperation(what, jc, oid, p); + } + } + } + } + + private void scan(Container container, List components) { + for (Component c : container.getComponents()) { + if (c instanceof JComponent) { + JComponent jc = (JComponent) c; + Object o = jc.getClientProperty(OPTION_ID); + if (o instanceof String || o instanceof String[]) { + components.add(jc); + } + } + if (c instanceof Container) { + scan((Container) c, components); + } + } + } + + /** Very smart method which tries to set the values in the components correctly + */ + private void loadData(JComponent jc, String optionID, Preferences node) { + if (jc instanceof JTextField) { + JTextField field = (JTextField) jc; + field.setText(node.get(optionID, FmtConstants.getDefaultAsString(optionID))); + } else if (jc instanceof JSpinner) { + JSpinner js = (JSpinner) jc; + js.setValue(node.getInt(optionID, FmtConstants.getDefaultAsInt(optionID))); + } else if (jc instanceof JToggleButton) { + JToggleButton toggle = (JToggleButton) jc; + boolean df = FmtConstants.getDefaultAsBoolean(optionID); + toggle.setSelected(node.getBoolean(optionID, df)); + } else if (jc instanceof JComboBox) { + JComboBox cb = (JComboBox) jc; + String value = node.get(optionID, FmtConstants.getDefaultAsString(optionID)); + ComboBoxModel model = createModel(value); + cb.setModel(model); + ComboItem item = whichItem(value, model); + cb.setSelectedItem(item); + } else if (jc instanceof JList) { + loadListData((JList) jc, optionID, node); + } else if (jc instanceof JTable) { + loadTableData((JTable) jc, optionID, node); + } + } + + private void storeData(JComponent jc, String optionID, Preferences node) { + if (jc instanceof JTextField) { + JTextField field = (JTextField) jc; + String text = field.getText(); + // XXX test for numbers + String val = FmtConstants.getDefaultAsString(optionID); + try { + Integer.parseInt(val); + try { + int i = Integer.parseInt(text); + } catch (NumberFormatException e) { + return; + } + } catch (NumberFormatException ex) { + // OK, default is not number + } + // XXX: watch out, tabSize, spacesPerTab, indentSize and expandTabToSpaces + // fall back on getGlopalXXX() values and not getDefaultAsXXX value, + // which is why we must not remove them. Proper solution would be to + // store formatting preferences to MimeLookup and not use NbPreferences. + // The problem currently is that MimeLookup based Preferences do not support subnodes. + if (!optionID.equals(FmtConstants.tabSize) && !optionID.equals(FmtConstants.spacesPerTab) && !optionID.equals(FmtConstants.indentSize) && FmtConstants.getDefaultAsString(optionID).equals(text)) { + node.remove(optionID); + } else { + node.put(optionID, text); + } + } else if (jc instanceof JSpinner) { + JSpinner js = (JSpinner) jc; + Object value = js.getValue(); + if (FmtConstants.getDefaultAsInt(optionID) == ((Integer) value).intValue()) { + node.remove(optionID); + } else { + node.putInt(optionID, ((Integer) value).intValue()); + } + } else if (jc instanceof JToggleButton) { + JToggleButton toggle = (JToggleButton) jc; + if (!optionID.equals(FmtConstants.expandTabToSpaces) && FmtConstants.getDefaultAsBoolean(optionID) == toggle.isSelected()) { + node.remove(optionID); + } else { + node.putBoolean(optionID, toggle.isSelected()); + } + } else if (jc instanceof JComboBox) { + JComboBox cb = (JComboBox) jc; + // Logger.global.info( cb.getSelectedItem() + " " + optionID); + String value = ((ComboItem) cb.getSelectedItem()).value; + if (FmtConstants.getDefaultAsString(optionID).equals(value)) { + node.remove(optionID); + } else { + node.put(optionID, value); + } + } else if (jc instanceof JList) { + storeListData((JList) jc, optionID, node); + } else if (jc instanceof JTable) { + storeTableData((JTable) jc, optionID, node); + } + } + + private void addListener(JComponent jc) { + if (jc instanceof JTextField) { + JTextField field = (JTextField) jc; + field.addActionListener(this); + field.getDocument().addDocumentListener(this); + } else if (jc instanceof JSpinner) { + JSpinner spinner = (JSpinner) jc; + spinner.addChangeListener(this); + } else if (jc instanceof JToggleButton) { + JToggleButton toggle = (JToggleButton) jc; + toggle.addActionListener(this); + } else if (jc instanceof JComboBox) { + JComboBox cb = (JComboBox) jc; + cb.addActionListener(this); + } else if (jc instanceof JList) { + JList jl = (JList) jc; + jl.getModel().addListDataListener(this); + } else if (jc instanceof JTable) { + JTable jt = (JTable) jc; + jt.getModel().addTableModelListener(this); + } + } + + private ComboBoxModel createModel(String value) { + // is it braces placement? + for (ComboItem comboItem : bracePlacement) { + if (value.equals(comboItem.value)) { + return new DefaultComboBoxModel(bracePlacement); + } + } + // is it braces generation? + for (ComboItem comboItem : bracesGeneration) { + if (value.equals(comboItem.value)) { + return new DefaultComboBoxModel(bracesGeneration); + } + } + // is it wrap? + for (ComboItem comboItem : wrap) { + if (value.equals(comboItem.value)) { + return new DefaultComboBoxModel(wrap); + } + } + // is it insertion point? + for (ComboItem comboItem : insertionPoint) { + if (value.equals(comboItem.value)) { + return new DefaultComboBoxModel(insertionPoint); + } + } + return null; + } + + private static ComboItem whichItem(String value, ComboBoxModel model) { + for (int i = 0; i < model.getSize(); i++) { + ComboItem item = (ComboItem) model.getElementAt(i); + if (value.equals(item.value)) { + return item; + } + } + return null; + } + + private static class ComboItem { + + String value; + String displayName; + + public ComboItem(String value, String key) { + this.value = value; + this.displayName = NbBundle.getMessage(FmtConstants.class, key); + } + + @Override + public String toString() { + return displayName; + } + } + +} --- a/java.source/src/org/netbeans/modules/java/ui/FmtAlignment.form +++ a/java.source/src/org/netbeans/modules/java/ui/FmtAlignment.form @@ -1,4 +1,4 @@ - +

--- a/java.source/src/org/netbeans/modules/java/ui/FmtAlignment.java +++ a/java.source/src/org/netbeans/modules/java/ui/FmtAlignment.java @@ -45,9 +45,8 @@ package org.netbeans.modules.java.ui; import org.netbeans.api.java.source.CodeStyle.WrapStyle; -import static org.netbeans.modules.java.ui.FmtOptions.*; -import static org.netbeans.modules.java.ui.FmtOptions.CategorySupport.OPTION_ID; -import org.netbeans.modules.java.ui.FmtOptions.CategorySupport; +import static org.netbeans.modules.java.preprocessorbridge.api.FmtConstants.*; +import static org.netbeans.modules.java.ui.CategorySupport.OPTION_ID; import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; @@ -83,16 +82,16 @@ public static PreferencesCustomizer.Factory getController() { return new CategorySupport.Factory("alignment", FmtAlignment.class, //NOI18N org.openide.util.NbBundle.getMessage(FmtAlignment.class, "SAMPLE_Align"), // NOI18N - new String[] { FmtOptions.wrapArrayInit, WrapStyle.WRAP_ALWAYS.name() }, - new String[] { FmtOptions.wrapEnumConstants, WrapStyle.WRAP_ALWAYS.name() }, - new String[] { FmtOptions.wrapExtendsImplementsList, WrapStyle.WRAP_ALWAYS.name() }, - new String[] { FmtOptions.wrapFor, WrapStyle.WRAP_ALWAYS.name() }, - new String[] { FmtOptions.wrapMethodCallArgs, WrapStyle.WRAP_ALWAYS.name() }, - new String[] { FmtOptions.wrapAnnotationArgs, WrapStyle.WRAP_ALWAYS.name() }, - new String[] { FmtOptions.wrapMethodParams, WrapStyle.WRAP_ALWAYS.name() }, - new String[] { FmtOptions.wrapTernaryOps, WrapStyle.WRAP_ALWAYS.name() }, - new String[] { FmtOptions.wrapThrowsList, WrapStyle.WRAP_ALWAYS.name() }, - new String[] { FmtOptions.blankLinesBeforeClass, "0" }); + new String[] { wrapArrayInit, WrapStyle.WRAP_ALWAYS.name() }, + new String[] { wrapEnumConstants, WrapStyle.WRAP_ALWAYS.name() }, + new String[] { wrapExtendsImplementsList, WrapStyle.WRAP_ALWAYS.name() }, + new String[] { wrapFor, WrapStyle.WRAP_ALWAYS.name() }, + new String[] { wrapMethodCallArgs, WrapStyle.WRAP_ALWAYS.name() }, + new String[] { wrapAnnotationArgs, WrapStyle.WRAP_ALWAYS.name() }, + new String[] { wrapMethodParams, WrapStyle.WRAP_ALWAYS.name() }, + new String[] { wrapTernaryOps, WrapStyle.WRAP_ALWAYS.name() }, + new String[] { wrapThrowsList, WrapStyle.WRAP_ALWAYS.name() }, + new String[] { blankLinesBeforeClass, "0" }); } /** This method is called from within the constructor to --- a/java.source/src/org/netbeans/modules/java/ui/FmtBlankLines.java +++ a/java.source/src/org/netbeans/modules/java/ui/FmtBlankLines.java @@ -44,9 +44,8 @@ package org.netbeans.modules.java.ui; -import static org.netbeans.modules.java.ui.FmtOptions.*; -import static org.netbeans.modules.java.ui.FmtOptions.CategorySupport.OPTION_ID; -import org.netbeans.modules.java.ui.FmtOptions.CategorySupport; +import static org.netbeans.modules.java.preprocessorbridge.api.FmtConstants.*; +import static org.netbeans.modules.java.ui.CategorySupport.OPTION_ID; import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; /** --- a/java.source/src/org/netbeans/modules/java/ui/FmtBraces.form +++ a/java.source/src/org/netbeans/modules/java/ui/FmtBraces.form @@ -10,6 +10,7 @@ + @@ -24,16 +25,26 @@ + + + + + + + + + + - - - - - - - - + + + + + + + + @@ -43,38 +54,15 @@ + - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - --- a/java.source/src/org/netbeans/modules/java/ui/FmtBraces.java +++ a/java.source/src/org/netbeans/modules/java/ui/FmtBraces.java @@ -44,10 +44,8 @@ package org.netbeans.modules.java.ui; -import org.netbeans.api.java.source.CodeStyle.WrapStyle; -import static org.netbeans.modules.java.ui.FmtOptions.*; -import static org.netbeans.modules.java.ui.FmtOptions.CategorySupport.OPTION_ID; -import org.netbeans.modules.java.ui.FmtOptions.CategorySupport; +import static org.netbeans.modules.java.ui.CategorySupport.OPTION_ID; +import static org.netbeans.modules.java.preprocessorbridge.api.FmtConstants.*; import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; @@ -73,7 +71,7 @@ public static PreferencesCustomizer.Factory getController() { return new CategorySupport.Factory("braces", FmtBraces.class, //NOI18N org.openide.util.NbBundle.getMessage(FmtBraces.class, "SAMPLE_Braces"), // NOI18N - new String[] { FmtOptions.blankLinesBeforeClass, "0" }); + new String[] { blankLinesBeforeClass, "0" }); } /** This method is called from within the constructor to @@ -176,9 +174,9 @@ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(otherCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(classDeclCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent( ifBracesCombo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent( forBracesCombo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent( whileBracesCombo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(ifBracesCombo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(forBracesCombo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(whileBracesCombo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(doWhileBracesCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)) .addComponent(methodDeclCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) @@ -205,7 +203,7 @@ .addContainerGap()) ); - layout.linkSize( javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[]{classDeclCombo, doWhileBracesCombo, forBracesCombo, ifBracesCombo, methodDeclCombo, otherCombo, whileBracesCombo}); + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {classDeclCombo, doWhileBracesCombo, forBracesCombo, ifBracesCombo, methodDeclCombo, otherCombo, whileBracesCombo}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) --- a/java.source/src/org/netbeans/modules/java/ui/FmtCodeGeneration.java +++ a/java.source/src/org/netbeans/modules/java/ui/FmtCodeGeneration.java @@ -73,8 +73,8 @@ import com.sun.source.tree.Tree; import com.sun.source.tree.TypeParameterTree; import com.sun.source.tree.VariableTree; +import org.netbeans.api.java.source.CodeStyle; -import org.netbeans.api.java.source.CodeStyle; import org.netbeans.api.java.source.GeneratorUtilities; import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.api.java.source.ModificationResult; @@ -82,9 +82,8 @@ import org.netbeans.api.java.source.WorkingCopy; import org.netbeans.editor.BaseDocument; import org.netbeans.modules.editor.indent.api.Reformat; -import static org.netbeans.modules.java.ui.FmtOptions.*; -import org.netbeans.modules.java.ui.FmtOptions.CategorySupport; -import static org.netbeans.modules.java.ui.FmtOptions.CategorySupport.OPTION_ID; +import static org.netbeans.modules.java.ui.CategorySupport.OPTION_ID; +import static org.netbeans.modules.java.preprocessorbridge.api.FmtConstants.*; import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; import org.netbeans.modules.parsing.api.ResultIterator; import org.netbeans.modules.parsing.api.Source; @@ -649,7 +648,7 @@ private CodeGenCategorySupport(Preferences preferences, JPanel panel) { super(preferences, "code-generation", panel, NbBundle.getMessage(FmtCodeGeneration.class, "SAMPLE_CodeGen"), //NOI18N - new String[] { FmtOptions.blankLinesBeforeFields, "1" }); //NOI18N + new String[] { blankLinesBeforeFields, "1" }); //NOI18N } @Override @@ -709,7 +708,9 @@ // ignore } - final CodeStyle codeStyle = codeStyleProducer.create(previewPrefs); + // XXX: CodeStyleProducer is not visible + Object codeStyle = null; + //final CodeStyle codeStyle = codeStyleProducer.create(previewPrefs); jep.setIgnoreRepaint(true); try { if (source == null) { --- a/java.source/src/org/netbeans/modules/java/ui/FmtComments.java +++ a/java.source/src/org/netbeans/modules/java/ui/FmtComments.java @@ -42,8 +42,8 @@ package org.netbeans.modules.java.ui; -import static org.netbeans.modules.java.ui.FmtOptions.*; -import static org.netbeans.modules.java.ui.FmtOptions.CategorySupport.OPTION_ID; +import static org.netbeans.modules.java.ui.CategorySupport.OPTION_ID; +import static org.netbeans.modules.java.preprocessorbridge.api.FmtConstants.*; import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; /** @@ -73,8 +73,8 @@ public static PreferencesCustomizer.Factory getController() { return new CategorySupport.Factory("comments", FmtComments.class, //NOI18N org.openide.util.NbBundle.getMessage(FmtComments.class, "SAMPLE_Comments"), // NOI18N - new String[] { FmtOptions.rightMargin, "45" }, //NOI18N - new String[] { FmtOptions.blankLinesBeforeClass, "0" }); //NOI18N + new String[] { rightMargin, "45" }, //NOI18N + new String[] { blankLinesBeforeClass, "0" }); //NOI18N } @Override --- a/java.source/src/org/netbeans/modules/java/ui/FmtImports.java +++ a/java.source/src/org/netbeans/modules/java/ui/FmtImports.java @@ -81,8 +81,8 @@ import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; import org.openide.util.NbBundle; -import static org.netbeans.modules.java.ui.FmtOptions.*; -import static org.netbeans.modules.java.ui.FmtOptions.CategorySupport.OPTION_ID; +import static org.netbeans.modules.java.ui.CategorySupport.OPTION_ID; +import static org.netbeans.modules.java.preprocessorbridge.api.FmtConstants.*; import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; import org.netbeans.modules.parsing.api.Source; import org.netbeans.modules.parsing.api.UserTask; @@ -659,7 +659,9 @@ // ignore } - final CodeStyle codeStyle = codeStyleProducer.create(previewPrefs); + // XXX: CodeStyleProducer is not visible + Object codeStyle = null; + //final CodeStyle codeStyle = codeStyleProducer.create(previewPrefs); jep.setIgnoreRepaint(true); try { if (source == null) { --- a/java.source/src/org/netbeans/modules/java/ui/FmtSpaces.java +++ a/java.source/src/org/netbeans/modules/java/ui/FmtSpaces.java @@ -63,9 +63,9 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreePath; +import static org.netbeans.modules.java.preprocessorbridge.api.FmtConstants.*; import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; import org.openide.util.NbBundle; -import static org.netbeans.modules.java.ui.FmtOptions.*; /** * @@ -357,16 +357,16 @@ } - private static final class SpacesCategorySupport extends FmtOptions.CategorySupport { + private static final class SpacesCategorySupport extends CategorySupport { public SpacesCategorySupport(Preferences preferences, FmtSpaces panel) { super(preferences, "spaces", panel, //NOI18N NbBundle.getMessage( FmtSpaces.class ,"SAMPLE_Spaces"), // NOI18N - new String[] {FmtOptions.placeCatchOnNewLine, Boolean.FALSE.toString()}, - new String[] {FmtOptions.placeElseOnNewLine, Boolean.FALSE.toString()}, - new String[] {FmtOptions.placeWhileOnNewLine, Boolean.FALSE.toString()}, - new String[] {FmtOptions.placeFinallyOnNewLine, Boolean.FALSE.toString()}, - new String[] { FmtOptions.blankLinesBeforeClass, "0" }); + new String[] {placeCatchOnNewLine, Boolean.FALSE.toString()}, + new String[] {placeElseOnNewLine, Boolean.FALSE.toString()}, + new String[] {placeWhileOnNewLine, Boolean.FALSE.toString()}, + new String[] {placeFinallyOnNewLine, Boolean.FALSE.toString()}, + new String[] {blankLinesBeforeClass, "0" }); panel.scs = this; } @@ -378,7 +378,7 @@ @Override protected void loadFrom(Preferences preferences) { for (Item item : getAllItems()) { - boolean df = FmtOptions.getDefaultAsBoolean(item.id); + boolean df = getDefaultAsBoolean(item.id); item.value = preferences.getBoolean(item.id, df); } } @@ -397,7 +397,7 @@ @Override protected void storeTo(Preferences preferences) { for (Item item : getAllItems()) { - boolean df = FmtOptions.getDefaultAsBoolean(item.id); + boolean df = getDefaultAsBoolean(item.id); if (df == item.value) preferences.remove(item.id); else --- a/java.source/src/org/netbeans/modules/java/ui/FmtTabsIndents.form +++ a/java.source/src/org/netbeans/modules/java/ui/FmtTabsIndents.form @@ -1,4 +1,4 @@ - + --- a/java.source/src/org/netbeans/modules/java/ui/FmtTabsIndents.java +++ a/java.source/src/org/netbeans/modules/java/ui/FmtTabsIndents.java @@ -44,9 +44,8 @@ package org.netbeans.modules.java.ui; -import static org.netbeans.modules.java.ui.FmtOptions.*; -import static org.netbeans.modules.java.ui.FmtOptions.CategorySupport.OPTION_ID; -import org.netbeans.modules.java.ui.FmtOptions.CategorySupport; +import static org.netbeans.modules.java.ui.CategorySupport.OPTION_ID; +import static org.netbeans.modules.java.preprocessorbridge.api.FmtConstants.*; import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; /** @@ -73,7 +72,7 @@ public static PreferencesCustomizer.Factory getController() { return new CategorySupport.Factory(PreferencesCustomizer.TABS_AND_INDENTS_ID, FmtTabsIndents.class, //NOI18N org.openide.util.NbBundle.getMessage(FmtTabsIndents.class, "SAMPLE_TabsIndents"), // NOI18N - new String[] { FmtOptions.blankLinesBeforeClass, "0" } + new String[] { blankLinesBeforeClass, "0" } ); } @@ -117,7 +116,7 @@ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(continuationIndentSizeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE) + .addComponent(continuationIndentSizeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 200, Short.MAX_VALUE) .addComponent(labelIndentLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) --- a/java.source/src/org/netbeans/modules/java/ui/FmtWrapping.java +++ a/java.source/src/org/netbeans/modules/java/ui/FmtWrapping.java @@ -47,9 +47,9 @@ import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import org.netbeans.api.java.source.CodeStyle; -import static org.netbeans.modules.java.ui.FmtOptions.*; -import static org.netbeans.modules.java.ui.FmtOptions.CategorySupport.OPTION_ID; -import org.netbeans.modules.java.ui.FmtOptions.CategorySupport; +import static org.netbeans.modules.java.ui.CategorySupport.OPTION_ID; +import org.netbeans.modules.java.preprocessorbridge.api.FmtConstants; +import static org.netbeans.modules.java.preprocessorbridge.api.FmtConstants.*; import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; @@ -120,13 +120,13 @@ public static PreferencesCustomizer.Factory getController() { return new CategorySupport.Factory("wrapping", FmtWrapping.class, //NOI18N org.openide.util.NbBundle.getMessage(FmtWrapping.class, "SAMPLE_Wrapping"), //NOI18N - new String[] { FmtOptions.rightMargin, "35" }, //NOI18N - new String[] { FmtOptions.redundantDoWhileBraces, CodeStyle.BracesGenerationStyle.LEAVE_ALONE.name() }, - new String[] { FmtOptions.redundantForBraces, CodeStyle.BracesGenerationStyle.LEAVE_ALONE.name() }, - new String[] { FmtOptions.redundantIfBraces, CodeStyle.BracesGenerationStyle.LEAVE_ALONE.name() }, - new String[] { FmtOptions.redundantWhileBraces, CodeStyle.BracesGenerationStyle.LEAVE_ALONE.name() }, - new String[] { FmtOptions.blankLinesBeforeClass, "0" }, - new String[] { FmtOptions.blankLinesAfterMethods, "1" } + new String[] { FmtConstants.rightMargin, "35" }, //NOI18N + new String[] { FmtConstants.redundantDoWhileBraces, CodeStyle.BracesGenerationStyle.LEAVE_ALONE.name() }, + new String[] { FmtConstants.redundantForBraces, CodeStyle.BracesGenerationStyle.LEAVE_ALONE.name() }, + new String[] { FmtConstants.redundantIfBraces, CodeStyle.BracesGenerationStyle.LEAVE_ALONE.name() }, + new String[] { FmtConstants.redundantWhileBraces, CodeStyle.BracesGenerationStyle.LEAVE_ALONE.name() }, + new String[] { FmtConstants.blankLinesBeforeClass, "0" }, + new String[] { FmtConstants.blankLinesAfterMethods, "1" } ); // NOI18N } --- a/java.editor/src/org/netbeans/modules/java/ui/PreviewPreferences.java +++ a/java.editor/src/org/netbeans/modules/java/ui/PreviewPreferences.java @@ -0,0 +1,97 @@ +/* + * 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.java.ui; + +import java.util.HashMap; +import java.util.Map; +import java.util.prefs.AbstractPreferences; +import java.util.prefs.BackingStoreException; + +/** + * + * @author Jaroslav Tulach + */ +public class PreviewPreferences extends AbstractPreferences { + private Map map = new HashMap(); + + public PreviewPreferences() { + super(null, ""); // NOI18N + } + + protected void putSpi(String key, String value) { + map.put(key, value); + } + + protected String getSpi(String key) { + return (String) map.get(key); + } + + protected void removeSpi(String key) { + map.remove(key); + } + + protected void removeNodeSpi() throws BackingStoreException { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected String[] keysSpi() throws BackingStoreException { + String[] array = new String[map.keySet().size()]; + return map.keySet().toArray(array); + } + + protected String[] childrenNamesSpi() throws BackingStoreException { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected AbstractPreferences childSpi(String name) { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected void syncSpi() throws BackingStoreException { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected void flushSpi() throws BackingStoreException { + throw new UnsupportedOperationException("Not supported yet."); + } + +} --- a/java.editor/src/org/netbeans/modules/java/ui/ProxyPreferences.java +++ a/java.editor/src/org/netbeans/modules/java/ui/ProxyPreferences.java @@ -0,0 +1,107 @@ +/* + * 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.java.ui; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.prefs.AbstractPreferences; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; + +// read-only, no subnodes + +public final class ProxyPreferences extends AbstractPreferences { + private final Preferences[] delegates; + + public ProxyPreferences(Preferences... delegates) { + super(null, ""); // NOI18N + this.delegates = delegates; + } + + protected void putSpi(String key, String value) { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected String getSpi(String key) { + for (Preferences p : delegates) { + String value = p.get(key, null); + if (value != null) { + return value; + } + } + return null; + } + + protected void removeSpi(String key) { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected void removeNodeSpi() throws BackingStoreException { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected String[] keysSpi() throws BackingStoreException { + Set keys = new HashSet(); + for (Preferences p : delegates) { + keys.addAll(Arrays.asList(p.keys())); + } + return keys.toArray(new String[keys.size()]); + } + + protected String[] childrenNamesSpi() throws BackingStoreException { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected AbstractPreferences childSpi(String name) { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected void syncSpi() throws BackingStoreException { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected void flushSpi() throws BackingStoreException { + throw new UnsupportedOperationException("Not supported yet."); + } + +} // End of ProxyPreferences class --- a/java.editor/test/unit/src/org/netbeans/modules/editor/java/JavaFormatterUnitTest.java +++ a/java.editor/test/unit/src/org/netbeans/modules/editor/java/JavaFormatterUnitTest.java @@ -47,7 +47,7 @@ import java.util.prefs.Preferences; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.java.source.CodeStyle; -import org.netbeans.modules.java.ui.FmtOptions; +import org.netbeans.modules.java.uisupport.FmtOptions; import org.openide.modules.ModuleInfo; import org.openide.util.Lookup; --- a/java.kit/test/qa-functional/src/org/netbeans/test/ide/VerifyJavaSourceDependenciesTest.java +++ a/java.kit/test/qa-functional/src/org/netbeans/test/ide/VerifyJavaSourceDependenciesTest.java @@ -0,0 +1,101 @@ +/* + * 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.test.ide; + +import junit.framework.Test; +import org.netbeans.api.java.source.JavaSource; +import org.netbeans.junit.NbModuleSuite; +import org.netbeans.junit.NbTestCase; +import org.openide.modules.ModuleInfo; +import org.openide.modules.Modules; +import org.openide.util.Lookup; + +/** + * + * @author Jaroslav Tulach + */ +public class VerifyJavaSourceDependenciesTest extends NbTestCase { + public VerifyJavaSourceDependenciesTest(String n) { + super(n); + } + + public static Test suite() { + return NbModuleSuite.emptyConfiguration(). + honorAutoloadEager(true). + enableClasspathModules(false).gui(false). + addTest(VerifyJavaSourceDependenciesTest.class). + clusters("ide|java"). + autoloadModules("ide", ".*"). + autoloadModules("java", ".*"). + enableModules("java", "org.netbeans.modules.java.source").suite(); + } + + public void testJavaSourceEnabled() { + ModuleInfo mi = Modules.getDefault().ownerOf(JavaSource.class); + assertTrue("Module is enabled", mi.isEnabled()); + } + + public void testEditorDisabled() { + StringBuilder sb = new StringBuilder(); + for (ModuleInfo mi : Lookup.getDefault().lookupAll(ModuleInfo.class)) { + if (mi.getCodeNameBase().contains("mimelookup")) { + continue; + } + if (mi.getCodeNameBase().equals("org.netbeans.modules.editor.util")) { + // this one is lightweight + continue; + } + if (mi.getCodeNameBase().equals("org.netbeans.modules.editor.guards")) { + // this one is lightweight and already in JDev anyway + continue; + } + if (mi.getCodeNameBase().contains("editor")) { + if (mi.isEnabled()) { + sb.append(mi.getCodeNameBase()).append('\n'); + } + } + } + if (sb.length() > 0) { + fail("Enabled editor module:\n" + sb); + } + } +} --- a/java.preprocessorbridge/nbproject/project.xml +++ a/java.preprocessorbridge/nbproject/project.xml @@ -23,6 +23,15 @@ + org.netbeans.modules.editor.settings + + + + 1 + 1.43 + + + org.netbeans.modules.parsing.api --- a/java.preprocessorbridge/src/org/netbeans/modules/java/preprocessorbridge/api/FmtConstants.java +++ a/java.preprocessorbridge/src/org/netbeans/modules/java/preprocessorbridge/api/FmtConstants.java @@ -0,0 +1,248 @@ +/* + * 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.java.preprocessorbridge.api; + +import org.netbeans.api.editor.settings.SimpleValueNames; +import org.openide.util.Lookup; + +/** + * + * @author Jaroslav Tulach + */ +public abstract class FmtConstants { + public static final String expandTabToSpaces = SimpleValueNames.EXPAND_TABS; + public static final String tabSize = SimpleValueNames.TAB_SIZE; + public static final String spacesPerTab = SimpleValueNames.SPACES_PER_TAB; + public static final String indentSize = SimpleValueNames.INDENT_SHIFT_WIDTH; + public static final String continuationIndentSize = "continuationIndentSize"; //NOI18N + public static final String labelIndent = "labelIndent"; //NOI18N + public static final String absoluteLabelIndent = "absoluteLabelIndent"; //NOI18N + public static final String indentTopLevelClassMembers = "indentTopLevelClassMembers"; //NOI18N + public static final String indentCasesFromSwitch = "indentCasesFromSwitch"; //NOI18N + public static final String rightMargin = SimpleValueNames.TEXT_LIMIT_WIDTH; + + public static final String addLeadingStarInComment = "addLeadingStarInComment"; //NOI18N + + public static final String preferLongerNames = "preferLongerNames"; //NOI18N + public static final String fieldNamePrefix = "fieldNamePrefix"; //NOI18N + public static final String fieldNameSuffix = "fieldNameSuffix"; //NOI18N + public static final String staticFieldNamePrefix = "staticFieldNamePrefix"; //NOI18N + public static final String staticFieldNameSuffix = "staticFieldNameSuffix"; //NOI18N + public static final String parameterNamePrefix = "parameterNamePrefix"; //NOI18N + public static final String parameterNameSuffix = "parameterNameSuffix"; //NOI18N + public static final String localVarNamePrefix = "localVarNamePrefix"; //NOI18N + public static final String localVarNameSuffix = "localVarNameSuffix"; //NOI18N + public static final String qualifyFieldAccess = "qualifyFieldAccess"; //NOI18N + public static final String useIsForBooleanGetters = "useIsForBooleanGetters"; //NOI18N + public static final String addOverrideAnnotation = "addOverrideAnnotation"; //NOI18N + public static final String makeLocalVarsFinal = "makeLocalVarsFinal"; //NOI18N + public static final String makeParametersFinal = "makeParametersFinal"; //NOI18N + public static final String classMembersOrder = "classMembersOrder"; //NOI18N + public static final String sortMembersByVisibility = "sortMembersByVisibility"; //NOI18N + public static final String visibilityOrder = "visibilityOrder"; //NOI18N + public static final String classMemberInsertionPoint = "classMemberInsertionPoint"; //NOI18N + + public static final String classDeclBracePlacement = "classDeclBracePlacement"; //NOI18N + public static final String methodDeclBracePlacement = "methodDeclBracePlacement"; //NOI18N + public static final String otherBracePlacement = "otherBracePlacement"; //NOI18N + public static final String specialElseIf = "specialElseIf"; //NOI18N + public static final String redundantIfBraces = "redundantIfBraces"; //NOI18N + public static final String redundantForBraces = "redundantForBraces"; //NOI18N + public static final String redundantWhileBraces = "redundantWhileBraces"; //NOI18N + public static final String redundantDoWhileBraces = "redundantDoWhileBraces"; //NOI18N + public static final String alignMultilineMethodParams = "alignMultilineMethodParams"; //NOI18N + public static final String alignMultilineCallArgs = "alignMultilineCallArgs"; //NOI18N + public static final String alignMultilineAnnotationArgs = "alignMultilineAnnotationArgs"; //NOI18N + public static final String alignMultilineImplements = "alignMultilineImplements"; //NOI18N + public static final String alignMultilineThrows = "alignMultilineThrows"; //NOI18N + public static final String alignMultilineParenthesized = "alignMultilineParenthesized"; //NOI18N + public static final String alignMultilineBinaryOp = "alignMultilineBinaryOp"; //NOI18N + public static final String alignMultilineTernaryOp = "alignMultilineTernaryOp"; //NOI18N + public static final String alignMultilineAssignment = "alignMultilineAssignment"; //NOI18N + public static final String alignMultilineTryResources = "alignMultilineTryResources"; //NOI18N + public static final String alignMultilineDisjunctiveCatchTypes = "alignMultilineDisjunctiveCatchTypes"; //NOI18N + public static final String alignMultilineFor = "alignMultilineFor"; //NOI18N + public static final String alignMultilineArrayInit = "alignMultilineArrayInit"; //NOI18N + public static final String placeElseOnNewLine = "placeElseOnNewLine"; //NOI18N + public static final String placeWhileOnNewLine = "placeWhileOnNewLine"; //NOI18N + public static final String placeCatchOnNewLine = "placeCatchOnNewLine"; //NOI18N + public static final String placeFinallyOnNewLine = "placeFinallyOnNewLine"; //NOI18N + public static final String placeNewLineAfterModifiers = "placeNewLineAfterModifiers"; //NOI18N + + public static final String wrapExtendsImplementsKeyword = "wrapExtendsImplementsKeyword"; //NOI18N + public static final String wrapExtendsImplementsList = "wrapExtendsImplementsList"; //NOI18N + public static final String wrapMethodParams = "wrapMethodParams"; //NOI18N + public static final String wrapThrowsKeyword = "wrapThrowsKeyword"; //NOI18N + public static final String wrapThrowsList = "wrapThrowsList"; //NOI18N + public static final String wrapMethodCallArgs = "wrapMethodCallArgs"; //NOI18N + public static final String wrapAnnotationArgs = "wrapAnnotationArgs"; //NOI18N + public static final String wrapChainedMethodCalls = "wrapChainedMethodCalls"; //NOI18N + public static final String wrapAfterDotInChainedMethodCalls = "wrapAfterDotInChainedMethodCalls"; //NOI18N + public static final String wrapArrayInit = "wrapArrayInit"; //NOI18N + public static final String wrapTryResources = "wrapTryResources"; //NOI18N + public static final String wrapDisjunctiveCatchTypes = "wrapDisjunctiveCatchTypes"; //NOI18N + public static final String wrapFor = "wrapFor"; //NOI18N + public static final String wrapForStatement = "wrapForStatement"; //NOI18N + public static final String wrapIfStatement = "wrapIfStatement"; //NOI18N + public static final String wrapWhileStatement = "wrapWhileStatement"; //NOI18N + public static final String wrapDoWhileStatement = "wrapDoWhileStatement"; //NOI18N + public static final String wrapAssert = "wrapAssert"; //NOI18N + public static final String wrapEnumConstants = "wrapEnumConstants"; //NOI18N + public static final String wrapAnnotations = "wrapAnnotations"; //NOI18N + public static final String wrapBinaryOps = "wrapBinaryOps"; //NOI18N + public static final String wrapAfterBinaryOps = "wrapAfterBinaryOps"; //NOI18N + public static final String wrapTernaryOps = "wrapTernaryOps"; //NOI18N + public static final String wrapAfterTernaryOps = "wrapAfterTernaryOps"; //NOI18N + public static final String wrapAssignOps = "wrapAssignOps"; //NOI18N + + public static final String blankLinesBeforePackage = "blankLinesBeforePackage"; //NOI18N + public static final String blankLinesAfterPackage = "blankLinesAfterPackage"; //NOI18N + public static final String blankLinesBeforeImports = "blankLinesBeforeImports"; //NOI18N + public static final String blankLinesAfterImports = "blankLinesAfterImports"; //NOI18N + public static final String blankLinesBeforeClass = "blankLinesBeforeClass"; //NOI18N + public static final String blankLinesAfterClass = "blankLinesAfterClass"; //NOI18N + public static final String blankLinesAfterClassHeader = "blankLinesAfterClassHeader"; //NOI18N + public static final String blankLinesAfterAnonymousClassHeader = "blankLinesAfterAnonymousClassHeader"; //NOI18N + public static final String blankLinesBeforeFields = "blankLinesBeforeFields"; //NOI18N + public static final String blankLinesAfterFields = "blankLinesAfterFields"; //NOI18N + public static final String blankLinesBeforeMethods = "blankLinesBeforeMethods"; //NOI18N + public static final String blankLinesAfterMethods = "blankLinesAfterMethods"; //NOI18N + + public static final String spaceBeforeWhile = "spaceBeforeWhile"; //NOI18N + public static final String spaceBeforeElse = "spaceBeforeElse"; //NOI18N + public static final String spaceBeforeCatch = "spaceBeforeCatch"; //NOI18N + public static final String spaceBeforeFinally = "spaceBeforeFinally"; //NOI18N + public static final String spaceBeforeMethodDeclParen = "spaceBeforeMethodDeclParen"; //NOI18N + public static final String spaceBeforeMethodCallParen = "spaceBeforeMethodCallParen"; //NOI18N + public static final String spaceBeforeIfParen = "spaceBeforeIfParen"; //NOI18N + public static final String spaceBeforeForParen = "spaceBeforeForParen"; //NOI18N + public static final String spaceBeforeWhileParen = "spaceBeforeWhileParen"; //NOI18N + public static final String spaceBeforeTryParen = "spaceBeforeTryParen"; //NOI18N + public static final String spaceBeforeCatchParen = "spaceBeforeCatchParen"; //NOI18N + public static final String spaceBeforeSwitchParen = "spaceBeforeSwitchParen"; //NOI18N + public static final String spaceBeforeSynchronizedParen = "spaceBeforeSynchronizedParen"; //NOI18N + public static final String spaceBeforeAnnotationParen = "spaceBeforeAnnotationParen"; //NOI18N + public static final String spaceAroundUnaryOps = "spaceAroundUnaryOps"; //NOI18N + public static final String spaceAroundBinaryOps = "spaceAroundBinaryOps"; //NOI18N + public static final String spaceAroundTernaryOps = "spaceAroundTernaryOps"; //NOI18N + public static final String spaceAroundAssignOps = "spaceAroundAssignOps"; //NOI18N + public static final String spaceAroundAnnotationValueAssignOps = "spaceAroundAnnotationValueAssignOps"; //NOI18N + public static final String spaceBeforeClassDeclLeftBrace = "spaceBeforeClassDeclLeftBrace"; //NOI18N + public static final String spaceBeforeMethodDeclLeftBrace = "spaceBeforeMethodDeclLeftBrace"; //NOI18N + public static final String spaceBeforeIfLeftBrace = "spaceBeforeIfLeftBrace"; //NOI18N + public static final String spaceBeforeElseLeftBrace = "spaceBeforeElseLeftBrace"; //NOI18N + public static final String spaceBeforeWhileLeftBrace = "spaceBeforeWhileLeftBrace"; //NOI18N + public static final String spaceBeforeForLeftBrace = "spaceBeforeForLeftBrace"; //NOI18N + public static final String spaceBeforeDoLeftBrace = "spaceBeforeDoLeftBrace"; //NOI18N + public static final String spaceBeforeSwitchLeftBrace = "spaceBeforeSwitchLeftBrace"; //NOI18N + public static final String spaceBeforeTryLeftBrace = "spaceBeforeTryLeftBrace"; //NOI18N + public static final String spaceBeforeCatchLeftBrace = "spaceBeforeCatchLeftBrace"; //NOI18N + public static final String spaceBeforeFinallyLeftBrace = "spaceBeforeFinallyLeftBrace"; //NOI18N + public static final String spaceBeforeSynchronizedLeftBrace = "spaceBeforeSynchronizedLeftBrace"; //NOI18N + public static final String spaceBeforeStaticInitLeftBrace = "spaceBeforeStaticInitLeftBrace"; //NOI18N + public static final String spaceBeforeArrayInitLeftBrace = "spaceBeforeArrayInitLeftBrace"; //NOI18N + public static final String spaceWithinParens = "spaceWithinParens"; //NOI18N + public static final String spaceWithinMethodDeclParens = "spaceWithinMethodDeclParens"; //NOI18N + public static final String spaceWithinMethodCallParens = "spaceWithinMethodCallParens"; //NOI18N + public static final String spaceWithinIfParens = "spaceWithinIfParens"; //NOI18N + public static final String spaceWithinForParens = "spaceWithinForParens"; //NOI18N + public static final String spaceWithinWhileParens = "spaceWithinWhileParens"; //NOI18N + public static final String spaceWithinSwitchParens = "spaceWithinSwitchParens"; //NOI18N + public static final String spaceWithinTryParens = "spaceWithinTryParens"; //NOI18N + public static final String spaceWithinCatchParens = "spaceWithinCatchParens"; //NOI18N + public static final String spaceWithinSynchronizedParens = "spaceWithinSynchronizedParens"; //NOI18N + public static final String spaceWithinTypeCastParens = "spaceWithinTypeCastParens"; //NOI18N + public static final String spaceWithinAnnotationParens = "spaceWithinAnnotationParens"; //NOI18N + public static final String spaceWithinBraces = "spaceWithinBraces"; //NOI18N + public static final String spaceWithinArrayInitBrackets = "spaceWithinArrayInitBrackets"; //NOI18N + public static final String spaceBeforeComma = "spaceBeforeComma"; //NOI18N + public static final String spaceAfterComma = "spaceAfterComma"; //NOI18N + public static final String spaceBeforeSemi = "spaceBeforeSemi"; //NOI18N + public static final String spaceAfterSemi = "spaceAfterSemi"; //NOI18N + public static final String spaceBeforeColon = "spaceBeforeColon"; //NOI18N + public static final String spaceAfterColon = "spaceAfterColon"; //NOI18N + public static final String spaceAfterTypeCast = "spaceAfterTypeCast"; //NOI18N + + public static final String useSingleClassImport = "useSingleClassImport"; //NOI18N + public static final String usePackageImport = "usePackageImport"; //NOI18N + public static final String useFQNs = "useFQNs"; //NOI18N + public static final String importInnerClasses = "importInnerClasses"; //NOI18N + public static final String allowConvertToStarImport = "allowConvertToStarImport"; //NOI18N + public static final String countForUsingStarImport = "countForUsingStarImport"; //NOI18N + public static final String allowConvertToStaticStarImport = "allowConvertToStaticStarImport"; //NOI18N + public static final String countForUsingStaticStarImport = "countForUsingStaticStarImport"; //NOI18N + public static final String packagesForStarImport = "packagesForStarImport"; //NOI18N + public static final String separateStaticImports = "separateStaticImports"; //NOI18N + public static final String importGroupsOrder = "importGroupsOrder"; //NOI18N + public static final String separateImportGroups = "separateImportGroups"; //NOI18N + + public static final String enableCommentFormatting = "enableCommentFormatting"; //NOI18N + public static final String enableBlockCommentFormatting = "enableBlockCommentFormatting"; //NOI18N + public static final String wrapCommentText = "wrapCommentText"; //NOI18N + public static final String wrapOneLineComment = "wrapOneLineComment"; //NOI18N + public static final String preserveNewLinesInComments = "preserveNewLinesInComments"; //NOI18N + public static final String blankLineAfterJavadocDescription = "blankLineAfterJavadocDescription"; //NOI18N + public static final String blankLineAfterJavadocParameterDescriptions = "blankLineAfterJavadocParameterDescriptions"; //NOI18N + public static final String blankLineAfterJavadocReturnTag = "blankLineAfterJavadocReturnTag"; //NOI18N + public static final String generateParagraphTagOnBlankLines = "generateParagraphTagOnBlankLines"; //NOI18N + public static final String alignJavadocParameterDescriptions = "alignJavadocParameterDescriptions"; //NOI18N + public static final String alignJavadocReturnDescription = "alignJavadocReturnDescription"; //NOI18N + public static final String alignJavadocExceptionDescriptions = "alignJavadocExceptionDescriptions"; //NOI18N + public static String JAVA_MIME_TYPE = "text/x-java"; // NOI18N + + public static int getDefaultAsInt(String key) { + return Lookup.getDefault().lookup(FmtConstants.class).defaultAsInt(key); + } + + public static boolean getDefaultAsBoolean(String key) { + return Lookup.getDefault().lookup(FmtConstants.class).defaultAsBoolean(key); + } + + public static String getDefaultAsString(String key) { + return Lookup.getDefault().lookup(FmtConstants.class).defaultAsString(key); + } + + protected abstract int defaultAsInt(String key); + protected abstract boolean defaultAsBoolean(String key); + protected abstract String defaultAsString(String key); + +} --- a/java.preprocessorbridge/src/org/netbeans/modules/java/preprocessorbridge/spi/TalkToEditor.java +++ a/java.preprocessorbridge/src/org/netbeans/modules/java/preprocessorbridge/spi/TalkToEditor.java @@ -0,0 +1,99 @@ +/* + * 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.java.preprocessorbridge.spi; + +import java.beans.PropertyChangeListener; +import java.util.prefs.Preferences; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import javax.swing.text.JTextComponent; +import org.openide.filesystems.FileObject; +import org.openide.util.Lookup; + +/** + * + * @author Jaroslav Tulach + */ +public abstract class TalkToEditor { + protected TalkToEditor() { + } + + private static TalkToEditor getDefault() { + return Lookup.getDefault().lookup(TalkToEditor.class); + } + + public static JTextComponent findFocusedComponent() { + return getDefault().implFocusedComponent(); + } + + + public static Preferences findCodePreferences(FileObject file) { + return getDefault().implCodePreferences(file); + } + public static Preferences findCodePreferences(Document doc) { + return getDefault().implCodePreferences(doc); + } + public static JTextComponent findLastFocusedComponent() { + return getDefault().implLastFocusedComponent(); + } + public static void addEditorRegistryListener(PropertyChangeListener propertyChangeListener) { + getDefault().implAddRemoveListener(propertyChangeListener, true); + } + public static void removeEditorRegistryListener(PropertyChangeListener propertyChangeListener) { + getDefault().implAddRemoveListener(propertyChangeListener, false); + } + public static int findOffsetIndent(Document doc, int offset) throws BadLocationException { + return getDefault().implOffsetIndent(doc, offset); + } + public static boolean checkGuarded(Document doc, int pos, long treePos) { + return getDefault().implCheckGuarded(doc, pos, treePos); + } + + + protected abstract Preferences implCodePreferences(FileObject file); + protected abstract Preferences implCodePreferences(Document doc); + protected abstract JTextComponent implLastFocusedComponent(); + protected abstract JTextComponent implFocusedComponent(); + protected abstract void implAddRemoveListener(PropertyChangeListener pcl, boolean toAdd); + protected abstract int implOffsetIndent(Document doc, int offset) throws BadLocationException; + protected abstract boolean implCheckGuarded(Document doc, int pos, long treePos); +} --- a/java.source/nbproject/project.xml +++ a/java.source/nbproject/project.xml @@ -141,43 +141,7 @@ 1 - 1.0 - - - - org.netbeans.modules.editor.indent - - - - 2 - 1.11 - - - - org.netbeans.modules.editor.indent.project - - - - 0-1 - 1.0 - - - - org.netbeans.modules.editor.lib - - - - 3 - 3.1 - - - - org.netbeans.modules.editor.lib2 - - - - 1 - 1.11 + 1.17 @@ -190,21 +154,12 @@ - org.netbeans.modules.editor.settings - - - - 1 - 1.18 - - - org.netbeans.modules.editor.util 1 - 1.22 + 1.49 @@ -252,15 +207,6 @@ - org.netbeans.modules.options.editor - - - - 1 - 1.20 - - - org.netbeans.modules.parsing.api @@ -402,6 +348,15 @@ 6.2 + + org.netbeans.modules.editor.settings + + + + 1 + 1.43 + + --- a/java.source/src/org/netbeans/api/java/source/CodeStyle.java +++ a/java.source/src/org/netbeans/api/java/source/CodeStyle.java @@ -62,10 +62,9 @@ import com.sun.source.tree.VariableTree; import org.netbeans.api.project.Project; -import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; -import org.netbeans.modules.java.source.parsing.JavacParser; -import org.netbeans.modules.java.ui.FmtOptions; -import static org.netbeans.modules.java.ui.FmtOptions.*; +import org.netbeans.modules.java.preprocessorbridge.spi.TalkToEditor; +import org.netbeans.modules.java.uisupport.FmtOptions; +import static org.netbeans.modules.java.uisupport.FmtOptions.*; import org.openide.filesystems.FileObject; /** @@ -117,7 +116,7 @@ * @since 0.39 */ public synchronized static CodeStyle getDefault(FileObject file) { - Preferences prefs = CodeStylePreferences.get(file, JavacParser.MIME_TYPE).getPreferences(); + Preferences prefs = TalkToEditor.findCodePreferences(file); return FmtOptions.codeStyleProducer.create(prefs); } @@ -133,7 +132,7 @@ * @since 0.39 */ public synchronized static CodeStyle getDefault(Document doc) { - Preferences prefs = CodeStylePreferences.get(doc, JavacParser.MIME_TYPE).getPreferences(); + Preferences prefs = TalkToEditor.findCodePreferences(doc); return FmtOptions.codeStyleProducer.create(prefs); } --- a/java.source/src/org/netbeans/api/java/source/GeneratorUtilities.java +++ a/java.source/src/org/netbeans/api/java/source/GeneratorUtilities.java @@ -120,7 +120,7 @@ import org.netbeans.api.java.lexer.JavaTokenId; import org.netbeans.api.lexer.TokenSequence; -import org.netbeans.editor.GuardedDocument; +import org.netbeans.modules.java.preprocessorbridge.spi.TalkToEditor; import org.netbeans.modules.java.source.builder.CommentHandlerService; import org.netbeans.modules.java.source.builder.CommentSetImpl; import org.netbeans.modules.java.source.parsing.FileObjects; @@ -215,12 +215,12 @@ if ((path == null || !utils.isSynthetic(path)) && (codeStyle.getClassMemberInsertionPoint() == CodeStyle.InsertionPoint.FIRST_IN_CATEGORY && comparator.compare(member, tree) <= 0 || comparator.compare(member, tree) < 0)) { - if (doc == null || !(doc instanceof GuardedDocument)) + if (doc == null) { break; + } int pos = (int)(lastMember != null ? sp.getEndPosition(compilationUnit, lastMember) : sp.getStartPosition( compilationUnit,clazz)); - pos = ((GuardedDocument)doc).getGuardedBlockChain().adjustToBlockEnd(pos); long treePos = sp.getStartPosition(compilationUnit, tree); - if (treePos < 0 || pos <= treePos) + if (TalkToEditor.checkGuarded(doc, pos, treePos)) break; } idx++; --- a/java.source/src/org/netbeans/api/java/source/ModificationResult.java +++ a/java.source/src/org/netbeans/api/java/source/ModificationResult.java @@ -62,7 +62,6 @@ import org.netbeans.api.annotations.common.NullUnknown; import org.netbeans.api.java.source.ModificationResult.CreateChange; import org.netbeans.api.queries.FileEncodingQuery; -import org.netbeans.editor.BaseDocument; import org.netbeans.lib.editor.util.swing.DocumentUtilities; import org.netbeans.modules.java.preprocessorbridge.spi.JavaFileFilterImplementation; import org.netbeans.modules.java.source.JavaFileFilterQuery; @@ -349,7 +348,7 @@ // The listener was added while trying to fix #63323 // IMPORTANT: it has to be removed immediatelly after the change to stop marking the events // as ignoring caret changes - if (doc instanceof BaseDocument) { + if (isBaseDocument()) { l = new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { @@ -377,6 +376,20 @@ } } } + + private boolean isBaseDocument() { + if (doc == null) { + return false; + } + Class c = doc.getClass(); + while (c != null) { + if ("org.netbeans.editor.BaseDocument".equals(c.getName())) { // NOI18N + return true; + } + c = c.getSuperclass(); + } + return false; + } }; if (diff.isCommitToGuards()) { NbDocument.runAtomic(doc, task); --- a/java.source/src/org/netbeans/api/java/source/UiUtils.java +++ a/java.source/src/org/netbeans/api/java/source/UiUtils.java @@ -63,7 +63,7 @@ import javax.swing.text.StyledDocument; import org.netbeans.modules.java.source.pretty.VeryPretty; import org.netbeans.modules.java.source.save.DiffContext; -import org.netbeans.modules.java.ui.Icons; +import org.netbeans.modules.java.uisupport.Icons; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.cookies.EditorCookie; --- a/java.source/src/org/netbeans/api/java/source/support/OpenedEditors.java +++ a/java.source/src/org/netbeans/api/java/source/support/OpenedEditors.java @@ -62,8 +62,8 @@ import javax.swing.event.ChangeListener; import javax.swing.text.Document; import javax.swing.text.JTextComponent; -import org.netbeans.api.editor.EditorRegistry; import org.netbeans.api.java.source.JavaSource; +import org.netbeans.modules.java.preprocessorbridge.spi.TalkToEditor; import org.netbeans.modules.java.source.JavaSourceSupportAccessor; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -84,7 +84,7 @@ private static OpenedEditors DEFAULT; private OpenedEditors() { - EditorRegistry.addPropertyChangeListener(new PropertyChangeListener() { + TalkToEditor.addEditorRegistryListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { stateChanged(); } @@ -157,7 +157,7 @@ visibleEditors.clear(); - JTextComponent editor = EditorRegistry.lastFocusedComponent(); + JTextComponent editor = TalkToEditor.findLastFocusedComponent(); DataObject file = editor != null ? getDataObject(editor) : null; --- a/java.source/src/org/netbeans/modules/java/classfile/SideBarFactoryImpl.java +++ a/java.source/src/org/netbeans/modules/java/classfile/SideBarFactoryImpl.java @@ -41,19 +41,19 @@ import javax.swing.JComponent; import javax.swing.text.Document; import javax.swing.text.JTextComponent; -import org.netbeans.editor.SideBarFactory; +//import org.netbeans.editor.SideBarFactory; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileStateInvalidException; import org.openide.loaders.DataObject; import org.openide.util.Exceptions; -/** +/** XXX: probably move to java.editor (?) * * @author lahvac */ -public class SideBarFactoryImpl implements SideBarFactory { +public class SideBarFactoryImpl /* implements SideBarFactory*/ { - @Override + // @Override public JComponent createSideBar(JTextComponent target) { Document doc = target.getDocument(); FileObject originFile; --- a/java.source/src/org/netbeans/modules/java/source/parsing/JavacParser.java +++ a/java.source/src/org/netbeans/modules/java/source/parsing/JavacParser.java @@ -100,7 +100,6 @@ import javax.tools.JavaFileObject; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.annotations.common.NullAllowed; -import org.netbeans.api.editor.EditorRegistry; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.lexer.JavaTokenId; import org.netbeans.api.java.queries.SourceLevelQuery; @@ -137,6 +136,8 @@ import org.netbeans.lib.nbjavac.services.NBJavacTrees; import org.netbeans.lib.nbjavac.services.NBTreeMaker; import org.netbeans.lib.nbjavac.services.PartialReparser; +import org.netbeans.modules.java.preprocessorbridge.api.FmtConstants; +import org.netbeans.modules.java.preprocessorbridge.spi.TalkToEditor; import org.netbeans.modules.java.source.tasklist.CompilerSettings; import org.netbeans.modules.java.source.usages.ClassIndexImpl; import org.netbeans.modules.java.source.usages.ClasspathInfoAccessor; @@ -171,7 +172,7 @@ //Debug logger private static final Logger LOGGER = Logger.getLogger(JavacParser.class.getName()); //Java Mime Type - public static final String MIME_TYPE = "text/x-java"; + public static final String MIME_TYPE = FmtConstants.JAVA_MIME_TYPE; //JavaFileObjectProvider used by the JavacParser - may be overriden by unit test static JavaFileObjectProvider jfoProvider = new DefaultJavaFileObjectProvider (); //No output writer like /dev/null @@ -1116,7 +1117,7 @@ th.addTokenHierarchyListener(lexListener = WeakListeners.create(TokenHierarchyListener.class, this,th)); document = doc; } - EditorRegistry.addPropertyChangeListener(new EditorRegistryWeakListener(this)); + TalkToEditor.addEditorRegistryListener(new EditorRegistryWeakListener(this)); } @Override @@ -1138,9 +1139,9 @@ //reset document this.document = doc; } - } else if (EditorRegistry.FOCUS_GAINED_PROPERTY.equals(evt.getPropertyName())) { + } else if ("focusGained".equals(evt.getPropertyName())) { final Document doc = document; - final JTextComponent focused = EditorRegistry.focusedComponent(); + final JTextComponent focused = TalkToEditor.findFocusedComponent(); final Document focusedDoc = focused == null ? null : focused.getDocument(); if (doc != null && doc == focusedDoc) { positions.clear(); @@ -1216,7 +1217,7 @@ @Override public void propertyChange(PropertyChangeEvent evt) { final PropertyChangeListener delegate = get(); - final JTextComponent lastCandidate = EditorRegistry.focusedComponent(); + final JTextComponent lastCandidate = TalkToEditor.findFocusedComponent(); if (delegate != null && lastCandidate != null && lastCandidate != getLast()) { setLast(lastCandidate); delegate.propertyChange(evt); @@ -1225,7 +1226,7 @@ @Override public void run() { - EditorRegistry.removePropertyChangeListener(this); + TalkToEditor.removeEditorRegistryListener(this); } /** --- a/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java +++ a/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java @@ -76,8 +76,9 @@ import javax.swing.text.BadLocationException; import static org.netbeans.modules.java.source.save.ListMatcher.*; import static com.sun.tools.javac.code.Flags.*; - -import org.netbeans.modules.editor.indent.api.IndentUtils; +import javax.swing.text.Document; + +import org.netbeans.modules.java.preprocessorbridge.spi.TalkToEditor; import static org.netbeans.modules.java.source.save.PositionEstimator.*; public class CasualDiff { @@ -290,11 +291,11 @@ } private static int getOldIndent(DiffContext diffContext, Tree t) { - if (diffContext.doc != null) { + final Document doc = diffContext.doc; + if (doc != null) { try { int offset = (int) diffContext.trees.getSourcePositions().getStartPosition(diffContext.origUnit, t); - int lineStartOffset = IndentUtils.lineStartOffset(diffContext.doc, offset); - return IndentUtils.lineIndent(diffContext.doc, lineStartOffset); + return TalkToEditor.findOffsetIndent(doc, offset); } catch (BadLocationException ex) {} } return -1; --- a/java.source/src/org/netbeans/modules/java/source/save/Reformatter.java +++ a/java.source/src/org/netbeans/modules/java/source/save/Reformatter.java @@ -58,10 +58,12 @@ import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenSequence; +/* XXX: Where to with reformatter? import org.netbeans.editor.GuardedDocument; import org.netbeans.modules.editor.indent.spi.Context; import org.netbeans.modules.editor.indent.spi.ExtraLock; import org.netbeans.modules.editor.indent.spi.ReformatTask; +*/ import org.netbeans.modules.java.source.JavaSourceAccessor; import org.netbeans.modules.java.source.parsing.FileObjects; import org.netbeans.modules.java.source.parsing.JavacParser; @@ -80,7 +82,7 @@ * * @author Dusan Balek */ -public class Reformatter implements ReformatTask { +public class Reformatter { /*implements ReformatTask { private static final Object CT_HANDLER_DOC_PROPERTY = "code-template-insert-handler"; // NOI18N @@ -145,7 +147,7 @@ for (Context.Region region : indentRegions) reformatImpl(region, cs); } - +*/ public static String reformat(String text, CodeStyle style) { return reformat(text, style, style.getRightMargin()); } @@ -175,7 +177,7 @@ } return sb.toString(); } - + /* private void reformatImpl(Context.Region region, CodeStyle cs) throws BadLocationException { boolean templateEdit = doc.getProperty(CT_HANDLER_DOC_PROPERTY) != null; int startOffset = region.getStartOffset(); @@ -367,7 +369,7 @@ return source != null ? new Reformatter(source, context) : null; } } - +*/ private static class Pretty extends TreePathScanner { private static final String OPERATOR = "operator"; //NOI18N --- a/java.source/src/org/netbeans/modules/java/source/save/Reindenter.java +++ a/java.source/src/org/netbeans/modules/java/source/save/Reindenter.java @@ -39,7 +39,6 @@ package org.netbeans.modules.java.source.save; import com.sun.source.tree.AnnotationTree; -import com.sun.source.tree.BinaryTree; import com.sun.source.tree.BlockTree; import com.sun.source.tree.CaseTree; import com.sun.source.tree.ClassTree; @@ -89,10 +88,12 @@ import org.netbeans.api.java.source.CodeStyle; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenSequence; +/* XXX: Where to put the Reindenter? import org.netbeans.modules.editor.indent.spi.Context; import org.netbeans.modules.editor.indent.spi.Context.Region; import org.netbeans.modules.editor.indent.spi.ExtraLock; import org.netbeans.modules.editor.indent.spi.IndentTask; +*/ import org.netbeans.modules.java.source.parsing.FileObjects; import org.netbeans.modules.java.source.parsing.JavacParser; @@ -100,7 +101,7 @@ * * @author Dusan Balek */ -public class Reindenter implements IndentTask { +public class Reindenter { /*implements IndentTask { private final Context context; private CodeStyle cs; @@ -920,4 +921,5 @@ ? new Reindenter(context) : null; } } +*/ } --- a/java.source/src/org/netbeans/modules/java/ui/Bundle.properties +++ a/java.source/src/org/netbeans/modules/java/ui/Bundle.properties @@ -500,9 +500,4 @@ AN_Preview=Preview AD_Preview=Preview -FmtTabsIndents.absoluteLabelIndentCheckBox.AccessibleContext.accessibleDescription=Indent Labels absolutely FmtTabsIndents.addLeadingStarInCommentCheckBox.AccessibleContext.accessibleDescription=Comment lines starting with leading star -FmtTabsIndents.indentCasesFromSwitchCheckBox.AccessibleContext.accessibleDescription=Additional indent for case statements -FmtTabsIndents.indentTopLevelClassMembersCheckBox.AccessibleContext.accessibleDescription=Indent for top-level class members -FmtTabsIndents.continuationIndentSizeField.AccessibleContext.accessibleDescription=Indent size in spaces -FmtTabsIndents.labelIndentField.AccessibleContext.accessibleDescription=Label indentation size in spaces --- a/java.source/src/org/netbeans/modules/java/ui/ElementHeaderFormater.java +++ a/java.source/src/org/netbeans/modules/java/ui/ElementHeaderFormater.java @@ -28,7 +28,7 @@ * * Portions Copyrighted 2007 Sun Microsystems, Inc. */ -package org.netbeans.modules.java.ui; +package org.netbeans.modules.java.uisupport; import com.sun.source.tree.ClassTree; import com.sun.source.tree.MethodTree; --- a/java.source/src/org/netbeans/modules/java/ui/FmtOptions.java +++ a/java.source/src/org/netbeans/modules/java/ui/FmtOptions.java @@ -41,237 +41,25 @@ * 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.java.ui; +package org.netbeans.modules.java.uisupport; -import java.awt.Component; -import java.awt.Container; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Arrays; +import org.netbeans.modules.java.preprocessorbridge.api.FmtConstants; import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.prefs.AbstractPreferences; -import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JEditorPane; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JSpinner; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.JToggleButton; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import org.netbeans.api.editor.settings.SimpleValueNames; import org.netbeans.api.java.source.CodeStyle; -import static org.netbeans.api.java.source.CodeStyle.*; -import org.netbeans.modules.java.source.save.Reformatter; -import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; -import org.netbeans.modules.options.editor.spi.PreviewProvider; - -import org.openide.text.CloneableEditorSupport; -import org.openide.util.HelpCtx; -import org.openide.util.NbBundle; +import org.netbeans.api.java.source.CodeStyle.BracePlacement; +import org.netbeans.api.java.source.CodeStyle.BracesGenerationStyle; +import org.netbeans.api.java.source.CodeStyle.InsertionPoint; +import org.netbeans.api.java.source.CodeStyle.WrapStyle; +import org.openide.util.lookup.ServiceProvider; /** * * @author phrebejk */ -public class FmtOptions { - - public static final String expandTabToSpaces = SimpleValueNames.EXPAND_TABS; - public static final String tabSize = SimpleValueNames.TAB_SIZE; - public static final String spacesPerTab = SimpleValueNames.SPACES_PER_TAB; - public static final String indentSize = SimpleValueNames.INDENT_SHIFT_WIDTH; - public static final String continuationIndentSize = "continuationIndentSize"; //NOI18N - public static final String labelIndent = "labelIndent"; //NOI18N - public static final String absoluteLabelIndent = "absoluteLabelIndent"; //NOI18N - public static final String indentTopLevelClassMembers = "indentTopLevelClassMembers"; //NOI18N - public static final String indentCasesFromSwitch = "indentCasesFromSwitch"; //NOI18N - public static final String rightMargin = SimpleValueNames.TEXT_LIMIT_WIDTH; - - public static final String addLeadingStarInComment = "addLeadingStarInComment"; //NOI18N - - public static final String preferLongerNames = "preferLongerNames"; //NOI18N - public static final String fieldNamePrefix = "fieldNamePrefix"; //NOI18N - public static final String fieldNameSuffix = "fieldNameSuffix"; //NOI18N - public static final String staticFieldNamePrefix = "staticFieldNamePrefix"; //NOI18N - public static final String staticFieldNameSuffix = "staticFieldNameSuffix"; //NOI18N - public static final String parameterNamePrefix = "parameterNamePrefix"; //NOI18N - public static final String parameterNameSuffix = "parameterNameSuffix"; //NOI18N - public static final String localVarNamePrefix = "localVarNamePrefix"; //NOI18N - public static final String localVarNameSuffix = "localVarNameSuffix"; //NOI18N - public static final String qualifyFieldAccess = "qualifyFieldAccess"; //NOI18N - public static final String useIsForBooleanGetters = "useIsForBooleanGetters"; //NOI18N - public static final String addOverrideAnnotation = "addOverrideAnnotation"; //NOI18N - public static final String makeLocalVarsFinal = "makeLocalVarsFinal"; //NOI18N - public static final String makeParametersFinal = "makeParametersFinal"; //NOI18N - public static final String classMembersOrder = "classMembersOrder"; //NOI18N - public static final String sortMembersByVisibility = "sortMembersByVisibility"; //NOI18N - public static final String visibilityOrder = "visibilityOrder"; //NOI18N - public static final String classMemberInsertionPoint = "classMemberInsertionPoint"; //NOI18N - - public static final String classDeclBracePlacement = "classDeclBracePlacement"; //NOI18N - public static final String methodDeclBracePlacement = "methodDeclBracePlacement"; //NOI18N - public static final String otherBracePlacement = "otherBracePlacement"; //NOI18N - public static final String specialElseIf = "specialElseIf"; //NOI18N - public static final String redundantIfBraces = "redundantIfBraces"; //NOI18N - public static final String redundantForBraces = "redundantForBraces"; //NOI18N - public static final String redundantWhileBraces = "redundantWhileBraces"; //NOI18N - public static final String redundantDoWhileBraces = "redundantDoWhileBraces"; //NOI18N - public static final String alignMultilineMethodParams = "alignMultilineMethodParams"; //NOI18N - public static final String alignMultilineCallArgs = "alignMultilineCallArgs"; //NOI18N - public static final String alignMultilineAnnotationArgs = "alignMultilineAnnotationArgs"; //NOI18N - public static final String alignMultilineImplements = "alignMultilineImplements"; //NOI18N - public static final String alignMultilineThrows = "alignMultilineThrows"; //NOI18N - public static final String alignMultilineParenthesized = "alignMultilineParenthesized"; //NOI18N - public static final String alignMultilineBinaryOp = "alignMultilineBinaryOp"; //NOI18N - public static final String alignMultilineTernaryOp = "alignMultilineTernaryOp"; //NOI18N - public static final String alignMultilineAssignment = "alignMultilineAssignment"; //NOI18N - public static final String alignMultilineTryResources = "alignMultilineTryResources"; //NOI18N - public static final String alignMultilineDisjunctiveCatchTypes = "alignMultilineDisjunctiveCatchTypes"; //NOI18N - public static final String alignMultilineFor = "alignMultilineFor"; //NOI18N - public static final String alignMultilineArrayInit = "alignMultilineArrayInit"; //NOI18N - public static final String placeElseOnNewLine = "placeElseOnNewLine"; //NOI18N - public static final String placeWhileOnNewLine = "placeWhileOnNewLine"; //NOI18N - public static final String placeCatchOnNewLine = "placeCatchOnNewLine"; //NOI18N - public static final String placeFinallyOnNewLine = "placeFinallyOnNewLine"; //NOI18N - public static final String placeNewLineAfterModifiers = "placeNewLineAfterModifiers"; //NOI18N - - public static final String wrapExtendsImplementsKeyword = "wrapExtendsImplementsKeyword"; //NOI18N - public static final String wrapExtendsImplementsList = "wrapExtendsImplementsList"; //NOI18N - public static final String wrapMethodParams = "wrapMethodParams"; //NOI18N - public static final String wrapThrowsKeyword = "wrapThrowsKeyword"; //NOI18N - public static final String wrapThrowsList = "wrapThrowsList"; //NOI18N - public static final String wrapMethodCallArgs = "wrapMethodCallArgs"; //NOI18N - public static final String wrapAnnotationArgs = "wrapAnnotationArgs"; //NOI18N - public static final String wrapChainedMethodCalls = "wrapChainedMethodCalls"; //NOI18N - public static final String wrapAfterDotInChainedMethodCalls = "wrapAfterDotInChainedMethodCalls"; //NOI18N - public static final String wrapArrayInit = "wrapArrayInit"; //NOI18N - public static final String wrapTryResources = "wrapTryResources"; //NOI18N - public static final String wrapDisjunctiveCatchTypes = "wrapDisjunctiveCatchTypes"; //NOI18N - public static final String wrapFor = "wrapFor"; //NOI18N - public static final String wrapForStatement = "wrapForStatement"; //NOI18N - public static final String wrapIfStatement = "wrapIfStatement"; //NOI18N - public static final String wrapWhileStatement = "wrapWhileStatement"; //NOI18N - public static final String wrapDoWhileStatement = "wrapDoWhileStatement"; //NOI18N - public static final String wrapAssert = "wrapAssert"; //NOI18N - public static final String wrapEnumConstants = "wrapEnumConstants"; //NOI18N - public static final String wrapAnnotations = "wrapAnnotations"; //NOI18N - public static final String wrapBinaryOps = "wrapBinaryOps"; //NOI18N - public static final String wrapAfterBinaryOps = "wrapAfterBinaryOps"; //NOI18N - public static final String wrapTernaryOps = "wrapTernaryOps"; //NOI18N - public static final String wrapAfterTernaryOps = "wrapAfterTernaryOps"; //NOI18N - public static final String wrapAssignOps = "wrapAssignOps"; //NOI18N - - public static final String blankLinesBeforePackage = "blankLinesBeforePackage"; //NOI18N - public static final String blankLinesAfterPackage = "blankLinesAfterPackage"; //NOI18N - public static final String blankLinesBeforeImports = "blankLinesBeforeImports"; //NOI18N - public static final String blankLinesAfterImports = "blankLinesAfterImports"; //NOI18N - public static final String blankLinesBeforeClass = "blankLinesBeforeClass"; //NOI18N - public static final String blankLinesAfterClass = "blankLinesAfterClass"; //NOI18N - public static final String blankLinesAfterClassHeader = "blankLinesAfterClassHeader"; //NOI18N - public static final String blankLinesAfterAnonymousClassHeader = "blankLinesAfterAnonymousClassHeader"; //NOI18N - public static final String blankLinesBeforeFields = "blankLinesBeforeFields"; //NOI18N - public static final String blankLinesAfterFields = "blankLinesAfterFields"; //NOI18N - public static final String blankLinesBeforeMethods = "blankLinesBeforeMethods"; //NOI18N - public static final String blankLinesAfterMethods = "blankLinesAfterMethods"; //NOI18N - - public static final String spaceBeforeWhile = "spaceBeforeWhile"; //NOI18N - public static final String spaceBeforeElse = "spaceBeforeElse"; //NOI18N - public static final String spaceBeforeCatch = "spaceBeforeCatch"; //NOI18N - public static final String spaceBeforeFinally = "spaceBeforeFinally"; //NOI18N - public static final String spaceBeforeMethodDeclParen = "spaceBeforeMethodDeclParen"; //NOI18N - public static final String spaceBeforeMethodCallParen = "spaceBeforeMethodCallParen"; //NOI18N - public static final String spaceBeforeIfParen = "spaceBeforeIfParen"; //NOI18N - public static final String spaceBeforeForParen = "spaceBeforeForParen"; //NOI18N - public static final String spaceBeforeWhileParen = "spaceBeforeWhileParen"; //NOI18N - public static final String spaceBeforeTryParen = "spaceBeforeTryParen"; //NOI18N - public static final String spaceBeforeCatchParen = "spaceBeforeCatchParen"; //NOI18N - public static final String spaceBeforeSwitchParen = "spaceBeforeSwitchParen"; //NOI18N - public static final String spaceBeforeSynchronizedParen = "spaceBeforeSynchronizedParen"; //NOI18N - public static final String spaceBeforeAnnotationParen = "spaceBeforeAnnotationParen"; //NOI18N - public static final String spaceAroundUnaryOps = "spaceAroundUnaryOps"; //NOI18N - public static final String spaceAroundBinaryOps = "spaceAroundBinaryOps"; //NOI18N - public static final String spaceAroundTernaryOps = "spaceAroundTernaryOps"; //NOI18N - public static final String spaceAroundAssignOps = "spaceAroundAssignOps"; //NOI18N - public static final String spaceAroundAnnotationValueAssignOps = "spaceAroundAnnotationValueAssignOps"; //NOI18N - public static final String spaceBeforeClassDeclLeftBrace = "spaceBeforeClassDeclLeftBrace"; //NOI18N - public static final String spaceBeforeMethodDeclLeftBrace = "spaceBeforeMethodDeclLeftBrace"; //NOI18N - public static final String spaceBeforeIfLeftBrace = "spaceBeforeIfLeftBrace"; //NOI18N - public static final String spaceBeforeElseLeftBrace = "spaceBeforeElseLeftBrace"; //NOI18N - public static final String spaceBeforeWhileLeftBrace = "spaceBeforeWhileLeftBrace"; //NOI18N - public static final String spaceBeforeForLeftBrace = "spaceBeforeForLeftBrace"; //NOI18N - public static final String spaceBeforeDoLeftBrace = "spaceBeforeDoLeftBrace"; //NOI18N - public static final String spaceBeforeSwitchLeftBrace = "spaceBeforeSwitchLeftBrace"; //NOI18N - public static final String spaceBeforeTryLeftBrace = "spaceBeforeTryLeftBrace"; //NOI18N - public static final String spaceBeforeCatchLeftBrace = "spaceBeforeCatchLeftBrace"; //NOI18N - public static final String spaceBeforeFinallyLeftBrace = "spaceBeforeFinallyLeftBrace"; //NOI18N - public static final String spaceBeforeSynchronizedLeftBrace = "spaceBeforeSynchronizedLeftBrace"; //NOI18N - public static final String spaceBeforeStaticInitLeftBrace = "spaceBeforeStaticInitLeftBrace"; //NOI18N - public static final String spaceBeforeArrayInitLeftBrace = "spaceBeforeArrayInitLeftBrace"; //NOI18N - public static final String spaceWithinParens = "spaceWithinParens"; //NOI18N - public static final String spaceWithinMethodDeclParens = "spaceWithinMethodDeclParens"; //NOI18N - public static final String spaceWithinMethodCallParens = "spaceWithinMethodCallParens"; //NOI18N - public static final String spaceWithinIfParens = "spaceWithinIfParens"; //NOI18N - public static final String spaceWithinForParens = "spaceWithinForParens"; //NOI18N - public static final String spaceWithinWhileParens = "spaceWithinWhileParens"; //NOI18N - public static final String spaceWithinSwitchParens = "spaceWithinSwitchParens"; //NOI18N - public static final String spaceWithinTryParens = "spaceWithinTryParens"; //NOI18N - public static final String spaceWithinCatchParens = "spaceWithinCatchParens"; //NOI18N - public static final String spaceWithinSynchronizedParens = "spaceWithinSynchronizedParens"; //NOI18N - public static final String spaceWithinTypeCastParens = "spaceWithinTypeCastParens"; //NOI18N - public static final String spaceWithinAnnotationParens = "spaceWithinAnnotationParens"; //NOI18N - public static final String spaceWithinBraces = "spaceWithinBraces"; //NOI18N - public static final String spaceWithinArrayInitBrackets = "spaceWithinArrayInitBrackets"; //NOI18N - public static final String spaceBeforeComma = "spaceBeforeComma"; //NOI18N - public static final String spaceAfterComma = "spaceAfterComma"; //NOI18N - public static final String spaceBeforeSemi = "spaceBeforeSemi"; //NOI18N - public static final String spaceAfterSemi = "spaceAfterSemi"; //NOI18N - public static final String spaceBeforeColon = "spaceBeforeColon"; //NOI18N - public static final String spaceAfterColon = "spaceAfterColon"; //NOI18N - public static final String spaceAfterTypeCast = "spaceAfterTypeCast"; //NOI18N - - public static final String useSingleClassImport = "useSingleClassImport"; //NOI18N - public static final String usePackageImport = "usePackageImport"; //NOI18N - public static final String useFQNs = "useFQNs"; //NOI18N - public static final String importInnerClasses = "importInnerClasses"; //NOI18N - public static final String allowConvertToStarImport = "allowConvertToStarImport"; //NOI18N - public static final String countForUsingStarImport = "countForUsingStarImport"; //NOI18N - public static final String allowConvertToStaticStarImport = "allowConvertToStaticStarImport"; //NOI18N - public static final String countForUsingStaticStarImport = "countForUsingStaticStarImport"; //NOI18N - public static final String packagesForStarImport = "packagesForStarImport"; //NOI18N - public static final String separateStaticImports = "separateStaticImports"; //NOI18N - public static final String importGroupsOrder = "importGroupsOrder"; //NOI18N - public static final String separateImportGroups = "separateImportGroups"; //NOI18N - - public static final String enableCommentFormatting = "enableCommentFormatting"; //NOI18N - public static final String enableBlockCommentFormatting = "enableBlockCommentFormatting"; //NOI18N - public static final String wrapCommentText = "wrapCommentText"; //NOI18N - public static final String wrapOneLineComment = "wrapOneLineComment"; //NOI18N - public static final String preserveNewLinesInComments = "preserveNewLinesInComments"; //NOI18N - public static final String blankLineAfterJavadocDescription = "blankLineAfterJavadocDescription"; //NOI18N - public static final String blankLineAfterJavadocParameterDescriptions = "blankLineAfterJavadocParameterDescriptions"; //NOI18N - public static final String blankLineAfterJavadocReturnTag = "blankLineAfterJavadocReturnTag"; //NOI18N - public static final String generateParagraphTagOnBlankLines = "generateParagraphTagOnBlankLines"; //NOI18N - public static final String alignJavadocParameterDescriptions = "alignJavadocParameterDescriptions"; //NOI18N - public static final String alignJavadocReturnDescription = "alignJavadocReturnDescription"; //NOI18N - public static final String alignJavadocExceptionDescriptions = "alignJavadocExceptionDescriptions"; //NOI18N +@ServiceProvider(service=FmtConstants.class) +public class FmtOptions extends FmtConstants { public static CodeStyleProducer codeStyleProducer; @@ -283,17 +71,21 @@ private static final String JAVA = "text/x-java"; //NOI18N - private FmtOptions() {} + public FmtOptions() {} - public static int getDefaultAsInt(String key) { + + @Override + protected int defaultAsInt(String key) { return Integer.parseInt(defaults.get(key)); } - - public static boolean getDefaultAsBoolean(String key) { + + @Override + protected boolean defaultAsBoolean(String key) { return Boolean.parseBoolean(defaults.get(key)); } - - public static String getDefaultAsString(String key) { + + @Override + protected String defaultAsString(String key) { return defaults.get(key); } @@ -549,578 +341,6 @@ } } - - - // Support section --------------------------------------------------------- - - public static class CategorySupport implements ActionListener, ChangeListener, ListDataListener, TableModelListener, DocumentListener, PreviewProvider, PreferencesCustomizer { - - public static final String OPTION_ID = "org.netbeans.modules.java.ui.FormatingOptions.ID"; - - private static final int LOAD = 0; - private static final int STORE = 1; - private static final int ADD_LISTENERS = 2; - - private static final ComboItem bracePlacement[] = new ComboItem[] { - new ComboItem( BracePlacement.SAME_LINE.name(), "LBL_bp_SAME_LINE" ), // NOI18N - new ComboItem( BracePlacement.NEW_LINE.name(), "LBL_bp_NEW_LINE" ), // NOI18N - new ComboItem( BracePlacement.NEW_LINE_HALF_INDENTED.name(), "LBL_bp_NEW_LINE_HALF_INDENTED" ), // NOI18N - new ComboItem( BracePlacement.NEW_LINE_INDENTED.name(), "LBL_bp_NEW_LINE_INDENTED" ) // NOI18N - }; - private static final ComboItem bracesGeneration[] = new ComboItem[] { - new ComboItem( BracesGenerationStyle.GENERATE.name(), "LBL_bg_GENERATE" ), // NOI18N - new ComboItem( BracesGenerationStyle.LEAVE_ALONE.name(), "LBL_bg_LEAVE_ALONE" ), // NOI18N - new ComboItem( BracesGenerationStyle.ELIMINATE.name(), "LBL_bg_ELIMINATE" ) // NOI18N - }; - - private static final ComboItem wrap[] = new ComboItem[] { - new ComboItem( WrapStyle.WRAP_ALWAYS.name(), "LBL_wrp_WRAP_ALWAYS" ), // NOI18N - new ComboItem( WrapStyle.WRAP_IF_LONG.name(), "LBL_wrp_WRAP_IF_LONG" ), // NOI18N - new ComboItem( WrapStyle.WRAP_NEVER.name(), "LBL_wrp_WRAP_NEVER" ) // NOI18N - }; - - private static final ComboItem insertionPoint[] = new ComboItem[] { - new ComboItem( InsertionPoint.LAST_IN_CATEGORY.name(), "LBL_ip_LAST_IN_CATEGORY" ), // NOI18N - new ComboItem( InsertionPoint.FIRST_IN_CATEGORY.name(), "LBL_ip_FIRST_IN_CATEGORY" ), // NOI18N - new ComboItem( InsertionPoint.CARET_LOCATION.name(), "LBL_ip_CARET_LOCATION" ) // NOI18N - }; - - protected final String previewText; -// private String forcedOptions[][]; - -// private boolean changed = false; -// private boolean loaded = false; - private final String id; - protected final JPanel panel; - private final List components = new LinkedList(); - private JEditorPane previewPane; - - protected final Preferences preferences; - protected final Preferences previewPrefs; - - protected CategorySupport(Preferences preferences, String id, JPanel panel, String previewText, String[]... forcedOptions) { - this.preferences = preferences; - this.id = id; - this.panel = panel; - this.previewText = previewText != null ? previewText : NbBundle.getMessage(FmtOptions.class, "SAMPLE_Default"); //NOI18N - - // Scan the panel for its components - scan(panel, components); - - // Initialize the preview preferences - Preferences forcedPrefs = new PreviewPreferences(); - for (String[] option : forcedOptions) { - forcedPrefs.put( option[0], option[1]); - } - this.previewPrefs = new ProxyPreferences(forcedPrefs, preferences); - - // Load and hook up all the components - loadFrom(preferences); - addListeners(); - } - - protected void addListeners() { - scan(ADD_LISTENERS, null); - } - - protected void loadFrom(Preferences preferences) { -// loaded = true; - scan(LOAD, preferences); -// loaded = false; - } -// -// public void applyChanges() { -// storeTo(preferences); -// } -// - protected void storeTo(Preferences p) { - scan(STORE, p); - } - - protected void notifyChanged() { -// if (loaded) -// return; - storeTo(preferences); - refreshPreview(); - } - - protected void loadListData(final JList list, final String optionID, final Preferences p) { - } - - protected void storeListData(final JList list, final String optionID, final Preferences node) { - } - - protected void loadTableData(final JTable table, final String optionID, final Preferences p) { - } - - protected void storeTableData(final JTable table, final String optionID, final Preferences node) { - } - - // ActionListener implementation --------------------------------------- - - public void actionPerformed(ActionEvent e) { - notifyChanged(); - } - - // ChangeListener implementation --------------------------------------- - - @Override - public void stateChanged(ChangeEvent e) { - notifyChanged(); - } - - // ListDataListener implementation ----------------------------------- - - @Override - public void contentsChanged(ListDataEvent e) { - } - - @Override - public void intervalAdded(ListDataEvent e) { - notifyChanged(); - } - - @Override - public void intervalRemoved(ListDataEvent e) { - } - - // TableModelListener implementation ----------------------------------- - - @Override - public void tableChanged(TableModelEvent e) { - notifyChanged(); - } - - // DocumentListener implementation ------------------------------------- - - public void insertUpdate(DocumentEvent e) { - notifyChanged(); - } - - public void removeUpdate(DocumentEvent e) { - notifyChanged(); - } - - public void changedUpdate(DocumentEvent e) { - notifyChanged(); - } - - // PreviewProvider methods ----------------------------------------------------- - - public JComponent getPreviewComponent() { - if (previewPane == null) { - previewPane = new JEditorPane(); - previewPane.getAccessibleContext().setAccessibleName(NbBundle.getMessage(FmtOptions.class, "AN_Preview")); //NOI18N - previewPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FmtOptions.class, "AD_Preview")); //NOI18N - previewPane.putClientProperty("HighlightsLayerIncludes", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.SyntaxHighlighting$"); //NOI18N - previewPane.setEditorKit(CloneableEditorSupport.getEditorKit("text/x-java")); - previewPane.setEditable(false); - } - return previewPane; - } - - public void refreshPreview() { - JEditorPane jep = (JEditorPane) getPreviewComponent(); - try { - int rm = previewPrefs.getInt(rightMargin, getDefaultAsInt(rightMargin)); - jep.putClientProperty("TextLimitLine", rm); //NOI18N - jep.getDocument().putProperty(SimpleValueNames.TEXT_LINE_WRAP, ""); //NOI18N - jep.getDocument().putProperty(SimpleValueNames.TAB_SIZE, ""); //NOI18N - jep.getDocument().putProperty(SimpleValueNames.TEXT_LIMIT_WIDTH, ""); //NOI18N - } - catch( NumberFormatException e ) { - // Ignore it - } - try { - Class.forName(CodeStyle.class.getName(), true, CodeStyle.class.getClassLoader()); - } catch (ClassNotFoundException cnfe) { - // ignore - } - - CodeStyle codeStyle = codeStyleProducer.create(previewPrefs); - jep.setIgnoreRepaint(true); - jep.setText(Reformatter.reformat(previewText, codeStyle)); - jep.setIgnoreRepaint(false); - jep.scrollRectToVisible(new Rectangle(0,0,10,10) ); - jep.repaint(100); - } - - // PreferencesCustomizer implementation -------------------------------- - - public JComponent getComponent() { - return panel; - } - - public String getDisplayName() { - return panel.getName(); - } - - public String getId() { - return id; - } - - public HelpCtx getHelpCtx() { - return null; - } - - // PreferencesCustomizer.Factory implementation ------------------------ - - public static final class Factory implements PreferencesCustomizer.Factory { - - private final String id; - private final Class panelClass; - private final String previewText; - private final String[][] forcedOptions; - - public Factory(String id, Class panelClass, String previewText, String[]... forcedOptions) { - this.id = id; - this.panelClass = panelClass; - this.previewText = previewText; - this.forcedOptions = forcedOptions; - } - - public PreferencesCustomizer create(Preferences preferences) { - try { - CategorySupport categorySupport = new CategorySupport(preferences, id, panelClass.newInstance(), previewText, forcedOptions); - if (categorySupport.panel instanceof Runnable) - ((Runnable)categorySupport.panel).run(); - return categorySupport; - } catch (Exception e) { - return null; - } - } - } // End of CategorySupport.Factory class - - // Private methods ----------------------------------------------------- - - private void performOperation(int operation, JComponent jc, String optionID, Preferences p) { - switch(operation) { - case LOAD: - loadData(jc, optionID, p); - break; - case STORE: - storeData(jc, optionID, p); - break; - case ADD_LISTENERS: - addListener(jc); - break; - } - } - - private void scan(int what, Preferences p ) { - for (JComponent jc : components) { - Object o = jc.getClientProperty(OPTION_ID); - if (o instanceof String) { - performOperation(what, jc, (String)o, p); - } else if (o instanceof String[]) { - for(String oid : (String[])o) { - performOperation(what, jc, oid, p); - } - } - } - } - - private void scan(Container container, List components) { - for (Component c : container.getComponents()) { - if (c instanceof JComponent) { - JComponent jc = (JComponent)c; - Object o = jc.getClientProperty(OPTION_ID); - if (o instanceof String || o instanceof String[]) - components.add(jc); - } - if (c instanceof Container) - scan((Container)c, components); - } - } - - /** Very smart method which tries to set the values in the components correctly - */ - private void loadData( JComponent jc, String optionID, Preferences node ) { - - if ( jc instanceof JTextField ) { - JTextField field = (JTextField)jc; - field.setText( node.get(optionID, getDefaultAsString(optionID)) ); - } - else if ( jc instanceof JSpinner ) { - JSpinner js = (JSpinner)jc; - js.setValue(node.getInt(optionID, getDefaultAsInt(optionID))); - } - else if ( jc instanceof JToggleButton ) { - JToggleButton toggle = (JToggleButton)jc; - boolean df = getDefaultAsBoolean(optionID); - toggle.setSelected( node.getBoolean(optionID, df)); - } - else if ( jc instanceof JComboBox ) { - JComboBox cb = (JComboBox)jc; - String value = node.get(optionID, getDefaultAsString(optionID) ); - ComboBoxModel model = createModel(value); - cb.setModel(model); - ComboItem item = whichItem(value, model); - cb.setSelectedItem(item); - } - else if ( jc instanceof JList ) { - loadListData((JList)jc, optionID, node); - } - else if ( jc instanceof JTable ) { - loadTableData((JTable)jc, optionID, node); - } - } - - private void storeData( JComponent jc, String optionID, Preferences node ) { - - if ( jc instanceof JTextField ) { - JTextField field = (JTextField)jc; - - String text = field.getText(); - - // XXX test for numbers - if ( isInteger(optionID) ) { - try { - int i = Integer.parseInt(text); - } catch (NumberFormatException e) { - return; - } - } - - // XXX: watch out, tabSize, spacesPerTab, indentSize and expandTabToSpaces - // fall back on getGlopalXXX() values and not getDefaultAsXXX value, - // which is why we must not remove them. Proper solution would be to - // store formatting preferences to MimeLookup and not use NbPreferences. - // The problem currently is that MimeLookup based Preferences do not support subnodes. - if (!optionID.equals(tabSize) && - !optionID.equals(spacesPerTab) && !optionID.equals(indentSize) && - getDefaultAsString(optionID).equals(text) - ) { - node.remove(optionID); - } else { - node.put(optionID, text); - } - } - else if ( jc instanceof JSpinner ) { - JSpinner js = (JSpinner)jc; - Object value = js.getValue(); - if (getDefaultAsInt(optionID) == ((Integer)value).intValue()) - node.remove(optionID); - else - node.putInt(optionID, ((Integer)value).intValue()); - } - else if ( jc instanceof JToggleButton ) { - JToggleButton toggle = (JToggleButton)jc; - if (!optionID.equals(expandTabToSpaces) && getDefaultAsBoolean(optionID) == toggle.isSelected()) - node.remove(optionID); - else - node.putBoolean(optionID, toggle.isSelected()); - } - else if ( jc instanceof JComboBox ) { - JComboBox cb = (JComboBox)jc; - // Logger.global.info( cb.getSelectedItem() + " " + optionID); - String value = ((ComboItem) cb.getSelectedItem()).value; - if (getDefaultAsString(optionID).equals(value)) - node.remove(optionID); - else - node.put(optionID,value); - } - else if ( jc instanceof JList ) { - storeListData((JList)jc, optionID, node); - } - else if ( jc instanceof JTable ) { - storeTableData((JTable)jc, optionID, node); - } - } - - private void addListener( JComponent jc ) { - if ( jc instanceof JTextField ) { - JTextField field = (JTextField)jc; - field.addActionListener(this); - field.getDocument().addDocumentListener(this); - } - else if ( jc instanceof JSpinner ) { - JSpinner spinner = (JSpinner)jc; - spinner.addChangeListener(this); - } - else if ( jc instanceof JToggleButton ) { - JToggleButton toggle = (JToggleButton)jc; - toggle.addActionListener(this); - } - else if ( jc instanceof JComboBox) { - JComboBox cb = (JComboBox)jc; - cb.addActionListener(this); - } - else if ( jc instanceof JList) { - JList jl = (JList)jc; - jl.getModel().addListDataListener(this); - } - else if ( jc instanceof JTable) { - JTable jt = (JTable)jc; - jt.getModel().addTableModelListener(this); - } - } - - - private ComboBoxModel createModel( String value ) { - - // is it braces placement? - for (ComboItem comboItem : bracePlacement) { - if ( value.equals( comboItem.value) ) { - return new DefaultComboBoxModel( bracePlacement ); - } - } - - // is it braces generation? - for (ComboItem comboItem : bracesGeneration) { - if ( value.equals( comboItem.value) ) { - return new DefaultComboBoxModel( bracesGeneration ); - } - } - - // is it wrap? - for (ComboItem comboItem : wrap) { - if ( value.equals( comboItem.value) ) { - return new DefaultComboBoxModel( wrap ); - } - } - - // is it insertion point? - for (ComboItem comboItem : insertionPoint) { - if ( value.equals( comboItem.value) ) { - return new DefaultComboBoxModel( insertionPoint ); - } - } - - return null; - } - - private static ComboItem whichItem(String value, ComboBoxModel model) { - - for (int i = 0; i < model.getSize(); i++) { - ComboItem item = (ComboItem)model.getElementAt(i); - if ( value.equals(item.value)) { - return item; - } - } - return null; - } - - private static class ComboItem { - - String value; - String displayName; - - public ComboItem(String value, String key) { - this.value = value; - this.displayName = NbBundle.getMessage(FmtOptions.class, key); - } - - @Override - public String toString() { - return displayName; - } - - } - } - - public static class PreviewPreferences extends AbstractPreferences { - - private Map map = new HashMap(); - - public PreviewPreferences() { - super(null, ""); // NOI18N - } - - protected void putSpi(String key, String value) { - map.put(key, value); - } - - protected String getSpi(String key) { - return (String)map.get(key); - } - - protected void removeSpi(String key) { - map.remove(key); - } - - protected void removeNodeSpi() throws BackingStoreException { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected String[] keysSpi() throws BackingStoreException { - String array[] = new String[map.keySet().size()]; - return map.keySet().toArray( array ); - } - - protected String[] childrenNamesSpi() throws BackingStoreException { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected AbstractPreferences childSpi(String name) { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected void syncSpi() throws BackingStoreException { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected void flushSpi() throws BackingStoreException { - throw new UnsupportedOperationException("Not supported yet."); - } - } - - // read-only, no subnodes - public static final class ProxyPreferences extends AbstractPreferences { - - private final Preferences[] delegates; - - public ProxyPreferences(Preferences... delegates) { - super(null, ""); // NOI18N - this.delegates = delegates; - } - - protected void putSpi(String key, String value) { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected String getSpi(String key) { - for(Preferences p : delegates) { - String value = p.get(key, null); - if (value != null) { - return value; - } - } - return null; - } - - protected void removeSpi(String key) { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected void removeNodeSpi() throws BackingStoreException { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected String[] keysSpi() throws BackingStoreException { - Set keys = new HashSet(); - for(Preferences p : delegates) { - keys.addAll(Arrays.asList(p.keys())); - } - return keys.toArray(new String[ keys.size() ]); - } - - protected String[] childrenNamesSpi() throws BackingStoreException { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected AbstractPreferences childSpi(String name) { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected void syncSpi() throws BackingStoreException { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected void flushSpi() throws BackingStoreException { - throw new UnsupportedOperationException("Not supported yet."); - } - } // End of ProxyPreferences class public static interface CodeStyleProducer { --- a/java.source/src/org/netbeans/modules/java/ui/Icons.java +++ a/java.source/src/org/netbeans/modules/java/ui/Icons.java @@ -42,7 +42,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.modules.java.ui; +package org.netbeans.modules.java.uisupport; import java.awt.Image; import java.util.Collection; --- a/java.source/src/org/netbeans/modules/java/ui/LazyListModel.java +++ a/java.source/src/org/netbeans/modules/java/ui/LazyListModel.java @@ -42,7 +42,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.modules.java.ui; +package org.netbeans.modules.java.uisupport; import java.util.BitSet; import javax.swing.*; --- a/java.source/src/org/netbeans/modules/java/ui/Renderers.java +++ a/java.source/src/org/netbeans/modules/java/ui/Renderers.java @@ -42,7 +42,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.modules.java.ui; +package org.netbeans.modules.java.uisupport; import java.awt.Component; import javax.lang.model.element.TypeElement; --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/AnnotationTest.java +++ a/java.source/test/unit/src/org/netbeans/api/java/source/gen/AnnotationTest.java @@ -71,7 +71,7 @@ import org.netbeans.api.java.source.WorkingCopy; import org.netbeans.junit.NbTestSuite; import org.netbeans.modules.java.source.save.Reformatter; -import org.netbeans.modules.java.ui.FmtOptions; +import org.netbeans.modules.java.uisupport.FmtOptions; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/MoveTreeTest.java +++ a/java.source/test/unit/src/org/netbeans/api/java/source/gen/MoveTreeTest.java @@ -70,7 +70,7 @@ import org.netbeans.api.java.source.TreeMaker; import org.netbeans.api.java.source.WorkingCopy; import org.netbeans.junit.NbTestSuite; -import org.netbeans.modules.java.ui.FmtOptions; +import org.netbeans.modules.java.uisupport.FmtOptions; /** * Tests method type parameters changes. --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/OperatorsTest.java +++ a/java.source/test/unit/src/org/netbeans/api/java/source/gen/OperatorsTest.java @@ -54,7 +54,7 @@ import org.netbeans.junit.NbTestSuite; import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; import org.netbeans.modules.java.source.parsing.JavacParser; -import org.netbeans.modules.java.ui.FmtOptions; +import org.netbeans.modules.java.uisupport.FmtOptions; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/RefactoringRegressionsTest.java +++ a/java.source/test/unit/src/org/netbeans/api/java/source/gen/RefactoringRegressionsTest.java @@ -59,7 +59,7 @@ import javax.lang.model.type.TypeKind; import org.netbeans.api.java.source.*; import org.netbeans.junit.NbTestSuite; -import org.netbeans.modules.java.ui.FmtOptions; +import org.netbeans.modules.java.uisupport.FmtOptions; import static org.netbeans.api.java.source.JavaSource.*; /** --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/TryTest.java +++ a/java.source/test/unit/src/org/netbeans/api/java/source/gen/TryTest.java @@ -65,7 +65,7 @@ import org.netbeans.api.java.source.TreeMaker; import org.netbeans.api.java.source.WorkingCopy; import org.netbeans.junit.NbTestSuite; -import org.netbeans.modules.java.ui.FmtOptions; +import org.netbeans.modules.java.uisupport.FmtOptions; import org.openide.filesystems.FileUtil; /** --- a/nbjunit/src/org/netbeans/junit/NbModuleSuite.java +++ a/nbjunit/src/org/netbeans/junit/NbModuleSuite.java @@ -237,6 +237,22 @@ } arr.add(clusterRegExp); arr.add(moduleRegExp); + arr.add("enabled"); // NOI18N + return new Configuration( + this.clusterRegExp, arr, startupArgs, parentClassLoader, + tests, latestTestCaseClass, reuseUserDir, gui, + enableClasspathModules, honorAutoEager, failOnMessage, + failOnException, hideExtraModules); + } + + public Configuration autoloadModules(String clusterRegExp, String moduleRegExp) { + List arr = new ArrayList(); + if (this.moduleRegExp != null) { + arr.addAll(this.moduleRegExp); + } + arr.add(clusterRegExp); + arr.add(moduleRegExp); + arr.add("autoload"); // NOI18N return new Configuration( this.clusterRegExp, arr, startupArgs, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui, @@ -1344,6 +1360,7 @@ } String clusterReg = it.next(); String moduleReg = it.next(); + String state = it.next(); Pattern modPattern = Pattern.compile(moduleReg); for (File c : clusterDirs) { if (!c.getName().matches(clusterReg)) { @@ -1371,7 +1388,12 @@ if (!contains) { continue; } - enableModule(xml, autoloads, contains, new File(config, m.getName())); + if (state.equals("enabled")) { + enableModule(xml, autoloads, contains, new File(config, m.getName())); + } else { + assert state.equals("autoload"); + autoloadModule(xml, autoloads, contains, new File(config, m.getName())); + } } } } @@ -1423,6 +1445,25 @@ } } } + + private static void autoloadModule(String xml, boolean autoloads, boolean enable, File target) throws IOException { + boolean toEnable = false; + Matcher matcherAuto = AUTO.matcher(xml); + if (matcherAuto.find()) { + if ("true".equals(matcherAuto.group(1))) { + return; + } + } + int begin = xml.indexOf("true\n" + " false\n" + " "; + String out = xml.substring(0, begin) + middle + xml.substring(end); + try { + writeModule(target, out); + } catch (IllegalStateException ex) { + throw new IOException("Unparsable:\n" + xml, ex); + } + } private static void writeModule(File file, String xml) throws IOException { String previous;