2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.psi
.codeStyle
;
18 import com
.intellij
.openapi
.extensions
.Extensions
;
19 import com
.intellij
.openapi
.fileTypes
.FileType
;
20 import com
.intellij
.openapi
.fileTypes
.FileTypeManager
;
21 import com
.intellij
.openapi
.fileTypes
.FileTypes
;
22 import com
.intellij
.openapi
.util
.*;
23 import com
.intellij
.openapi
.util
.text
.StringUtil
;
24 import com
.intellij
.openapi
.vfs
.VirtualFile
;
25 import com
.intellij
.util
.SystemProperties
;
26 import com
.intellij
.util
.containers
.ClassMap
;
27 import org
.jdom
.Element
;
28 import org
.jetbrains
.annotations
.NonNls
;
29 import org
.jetbrains
.annotations
.NotNull
;
30 import org
.jetbrains
.annotations
.TestOnly
;
33 import java
.lang
.reflect
.Field
;
34 import java
.lang
.reflect
.Modifier
;
37 public class CodeStyleSettings
implements Cloneable
, JDOMExternalizable
{
38 private final ClassMap
<CustomCodeStyleSettings
> myCustomSettings
= new ClassMap
<CustomCodeStyleSettings
>();
39 @NonNls private static final String ADDITIONAL_INDENT_OPTIONS
= "ADDITIONAL_INDENT_OPTIONS";
40 @NonNls private static final String FILETYPE
= "fileType";
42 public CodeStyleSettings() {
46 public CodeStyleSettings(boolean loadExtensions
) {
48 initImportsByDefault();
51 final CodeStyleSettingsProvider
[] codeStyleSettingsProviders
= Extensions
.getExtensions(CodeStyleSettingsProvider
.EXTENSION_POINT_NAME
);
52 for (final CodeStyleSettingsProvider provider
: codeStyleSettingsProviders
) {
53 addCustomSettings(provider
.createCustomSettings(this));
58 private void initImportsByDefault() {
59 PACKAGES_TO_USE_IMPORT_ON_DEMAND
.addEntry(new PackageEntry(false, "java.awt", false));
60 PACKAGES_TO_USE_IMPORT_ON_DEMAND
.addEntry(new PackageEntry(false,"javax.swing", false));
61 IMPORT_LAYOUT_TABLE
.addEntry(PackageEntry
.ALL_OTHER_IMPORTS_ENTRY
);
62 IMPORT_LAYOUT_TABLE
.addEntry(PackageEntry
.BLANK_LINE_ENTRY
);
63 IMPORT_LAYOUT_TABLE
.addEntry(new PackageEntry(false, "javax", true));
64 IMPORT_LAYOUT_TABLE
.addEntry(new PackageEntry(false, "java", true));
65 IMPORT_LAYOUT_TABLE
.addEntry(PackageEntry
.BLANK_LINE_ENTRY
);
66 IMPORT_LAYOUT_TABLE
.addEntry(PackageEntry
.ALL_OTHER_STATIC_IMPORTS_ENTRY
);
69 private void initTypeToName() {
70 initGeneralLocalVariable(PARAMETER_TYPE_TO_NAME
);
71 initGeneralLocalVariable(LOCAL_VARIABLE_TYPE_TO_NAME
);
72 PARAMETER_TYPE_TO_NAME
.addPair("*Exception", "e");
75 private static void initGeneralLocalVariable(@NonNls TypeToNameMap map
) {
76 map
.addPair("int", "i");
77 map
.addPair("byte", "b");
78 map
.addPair("char", "c");
79 map
.addPair("long", "l");
80 map
.addPair("short", "i");
81 map
.addPair("boolean", "b");
82 map
.addPair("double", "v");
83 map
.addPair("float", "v");
84 map
.addPair("java.lang.Object", "o");
85 map
.addPair("java.lang.String", "s");
88 public void setParentSettings(CodeStyleSettings parent
) {
89 myParentSettings
= parent
;
92 public CodeStyleSettings
getParentSettings() {
93 return myParentSettings
;
96 private void addCustomSettings(CustomCodeStyleSettings settings
) {
97 if (settings
!= null) {
98 myCustomSettings
.put(settings
.getClass(), settings
);
102 public <T
extends CustomCodeStyleSettings
> T
getCustomSettings(Class
<T
> aClass
) {
103 return (T
)myCustomSettings
.get(aClass
);
106 public CodeStyleSettings
clone() {
107 CodeStyleSettings clone
= new CodeStyleSettings();
108 clone
.copyFrom(this);
112 private void copyCustomSettingsFrom(CodeStyleSettings from
) {
114 myCustomSettings
.clear();
115 for (final CustomCodeStyleSettings settings
: from
.myCustomSettings
.values()) {
116 addCustomSettings((CustomCodeStyleSettings
) settings
.clone());
119 FIELD_TYPE_TO_NAME
.copyFrom(from
.FIELD_TYPE_TO_NAME
);
120 STATIC_FIELD_TYPE_TO_NAME
.copyFrom(from
.STATIC_FIELD_TYPE_TO_NAME
);
121 PARAMETER_TYPE_TO_NAME
.copyFrom(from
.PARAMETER_TYPE_TO_NAME
);
122 LOCAL_VARIABLE_TYPE_TO_NAME
.copyFrom(from
.LOCAL_VARIABLE_TYPE_TO_NAME
);
124 PACKAGES_TO_USE_IMPORT_ON_DEMAND
.copyFrom(from
.PACKAGES_TO_USE_IMPORT_ON_DEMAND
);
125 IMPORT_LAYOUT_TABLE
.copyFrom(from
.IMPORT_LAYOUT_TABLE
);
127 OTHER_INDENT_OPTIONS
.copyFrom(from
.OTHER_INDENT_OPTIONS
);
129 myAdditionalIndentOptions
.clear();
130 for(Map
.Entry
<FileType
, IndentOptions
> optionEntry
: from
.myAdditionalIndentOptions
.entrySet()) {
131 IndentOptions options
= optionEntry
.getValue();
132 myAdditionalIndentOptions
.put(optionEntry
.getKey(),(IndentOptions
)options
.clone());
136 public void copyFrom(CodeStyleSettings from
) {
137 copyPublicFields(from
, this);
139 copyCustomSettingsFrom(from
);
142 private static void copyPublicFields(Object from
, Object to
) {
144 Field
[] fields
= to
.getClass().getDeclaredFields();
145 for (Field field
: fields
) {
146 if (isPublic(field
) && !isFinal(field
)) {
148 copyFieldValue(from
, to
, field
);
150 catch (Exception e
) {
151 throw new RuntimeException(e
);
157 private static void copyFieldValue(final Object from
, Object to
, final Field field
)
158 throws IllegalAccessException
{
159 Class
<?
> fieldType
= field
.getType();
160 if (fieldType
.isPrimitive()) {
161 field
.set(to
, field
.get(from
));
163 else if (fieldType
.equals(String
.class)) {
164 field
.set(to
, field
.get(from
));
167 System
.out
.println("Field not copied " + field
.getName());
171 private static boolean isPublic(final Field field
) {
172 return (field
.getModifiers() & Modifier
.PUBLIC
) != 0;
175 private static boolean isFinal(final Field field
) {
176 return (field
.getModifiers() & Modifier
.FINAL
) != 0;
179 //----------------- GENERAL --------------------
181 public boolean LINE_COMMENT_AT_FIRST_COLUMN
= true;
182 public boolean BLOCK_COMMENT_AT_FIRST_COLUMN
= true;
184 public boolean KEEP_LINE_BREAKS
= true;
187 * Controls END_OF_LINE_COMMENT's and C_STYLE_COMMENT's
189 public boolean KEEP_FIRST_COLUMN_COMMENT
= true;
190 public boolean INSERT_FIRST_SPACE_IN_LINE
= true;
192 public boolean USE_SAME_INDENTS
= false;
194 public static class IndentOptions
implements JDOMExternalizable
, Cloneable
{
195 public int INDENT_SIZE
= 4;
196 public int CONTINUATION_INDENT_SIZE
= 8;
197 public int TAB_SIZE
= 4;
198 public boolean USE_TAB_CHARACTER
= false;
199 public boolean SMART_TABS
= false;
200 public int LABEL_INDENT_SIZE
= 0;
201 public boolean LABEL_INDENT_ABSOLUTE
= false;
203 public void readExternal(Element element
) throws InvalidDataException
{
204 DefaultJDOMExternalizer
.readExternal(this, element
);
207 public void writeExternal(Element element
) throws WriteExternalException
{
208 DefaultJDOMExternalizer
.writeExternal(this, element
);
211 public Object
clone() {
213 return super.clone();
215 catch (CloneNotSupportedException e
) {
217 throw new RuntimeException(e
);
222 public boolean equals(Object o
) {
223 if (this == o
) return true;
224 if (o
== null || getClass() != o
.getClass()) return false;
226 IndentOptions that
= (IndentOptions
)o
;
228 if (CONTINUATION_INDENT_SIZE
!= that
.CONTINUATION_INDENT_SIZE
) return false;
229 if (INDENT_SIZE
!= that
.INDENT_SIZE
) return false;
230 if (LABEL_INDENT_ABSOLUTE
!= that
.LABEL_INDENT_ABSOLUTE
) return false;
231 if (LABEL_INDENT_SIZE
!= that
.LABEL_INDENT_SIZE
) return false;
232 if (SMART_TABS
!= that
.SMART_TABS
) return false;
233 if (TAB_SIZE
!= that
.TAB_SIZE
) return false;
234 if (USE_TAB_CHARACTER
!= that
.USE_TAB_CHARACTER
) return false;
240 public int hashCode() {
241 int result
= INDENT_SIZE
;
242 result
= 31 * result
+ CONTINUATION_INDENT_SIZE
;
243 result
= 31 * result
+ TAB_SIZE
;
244 result
= 31 * result
+ (USE_TAB_CHARACTER ?
1 : 0);
245 result
= 31 * result
+ (SMART_TABS ?
1 : 0);
246 result
= 31 * result
+ LABEL_INDENT_SIZE
;
247 result
= 31 * result
+ (LABEL_INDENT_ABSOLUTE ?
1 : 0);
251 public void copyFrom(IndentOptions other
) {
252 copyPublicFields(other
, this);
257 public final IndentOptions JAVA_INDENT_OPTIONS
= new IndentOptions();
259 public final IndentOptions JSP_INDENT_OPTIONS
= new IndentOptions();
261 public final IndentOptions XML_INDENT_OPTIONS
= new IndentOptions();
263 public final IndentOptions OTHER_INDENT_OPTIONS
= new IndentOptions();
265 private final Map
<FileType
,IndentOptions
> myAdditionalIndentOptions
= new LinkedHashMap
<FileType
, IndentOptions
>();
267 private static final String ourSystemLineSeparator
= SystemProperties
.getLineSeparator();
270 * Line separator. It can be null if choosen line separator is "System-dependent"!
272 public String LINE_SEPARATOR
;
275 * @return line separator. If choosen line separator is "System-dependent" method returns default separator for this OS.
277 public String
getLineSeparator() {
278 return LINE_SEPARATOR
!= null ? LINE_SEPARATOR
: ourSystemLineSeparator
;
282 * Keep "if (..) ...;" (also while, for)
283 * Does not control "if (..) { .. }"
285 public boolean KEEP_CONTROL_STATEMENT_IN_ONE_LINE
= true;
287 //----------------- BRACES & INDENTS --------------------
311 * if (long-condition-1 &&
316 * if (short-condition) {
322 public static final int END_OF_LINE
= 1;
323 public static final int NEXT_LINE
= 2;
324 public static final int NEXT_LINE_SHIFTED
= 3;
325 public static final int NEXT_LINE_SHIFTED2
= 4;
326 public static final int NEXT_LINE_IF_WRAPPED
= 5;
328 public int BRACE_STYLE
= 1;
329 public int CLASS_BRACE_STYLE
= 1;
330 public int METHOD_BRACE_STYLE
= 1;
332 public boolean DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS
= false;
342 public boolean ELSE_ON_NEW_LINE
= false;
352 public boolean WHILE_ON_NEW_LINE
= false;
362 public boolean CATCH_ON_NEW_LINE
= false;
372 public boolean FINALLY_ON_NEW_LINE
= false;
374 public boolean INDENT_CASE_FROM_SWITCH
= true;
376 public boolean SPECIAL_ELSE_IF_TREATMENT
= true;
378 public boolean ALIGN_MULTILINE_PARAMETERS
= true;
379 public boolean ALIGN_MULTILINE_PARAMETERS_IN_CALLS
= false;
380 public boolean ALIGN_MULTILINE_FOR
= true;
381 public boolean INDENT_WHEN_CASES
= true;
383 public boolean ALIGN_MULTILINE_BINARY_OPERATION
= false;
384 public boolean ALIGN_MULTILINE_ASSIGNMENT
= false;
385 public boolean ALIGN_MULTILINE_TERNARY_OPERATION
= false;
386 public boolean ALIGN_MULTILINE_THROWS_LIST
= false;
387 public boolean ALIGN_MULTILINE_EXTENDS_LIST
= false;
388 public boolean ALIGN_MULTILINE_PARENTHESIZED_EXPRESSION
= false;
390 public boolean ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION
= false;
392 //----------------- Group alignments ---------------
394 public boolean ALIGN_GROUP_FIELD_DECLARATIONS
= false;
396 //----------------- BLANK LINES --------------------
399 * Keep up to this amount of blank lines between declarations
401 public int KEEP_BLANK_LINES_IN_DECLARATIONS
= 2;
404 * Keep up to this amount of blank lines in code
406 public int KEEP_BLANK_LINES_IN_CODE
= 2;
408 public int KEEP_BLANK_LINES_BEFORE_RBRACE
= 2;
410 public int BLANK_LINES_BEFORE_PACKAGE
= 0;
411 public int BLANK_LINES_AFTER_PACKAGE
= 1;
412 public int BLANK_LINES_BEFORE_IMPORTS
= 1;
413 public int BLANK_LINES_AFTER_IMPORTS
= 1;
415 public int BLANK_LINES_AROUND_CLASS
= 1;
416 public int BLANK_LINES_AROUND_FIELD
= 0;
417 public int BLANK_LINES_AROUND_METHOD
= 1;
419 public int BLANK_LINES_AROUND_FIELD_IN_INTERFACE
= 0;
420 public int BLANK_LINES_AROUND_METHOD_IN_INTERFACE
= 1;
423 public int BLANK_LINES_AFTER_CLASS_HEADER
= 0;
424 //public int BLANK_LINES_BETWEEN_CASE_BLOCKS;
426 //----------------- SPACES --------------------
429 * Controls =, +=, -=, etc
431 public boolean SPACE_AROUND_ASSIGNMENT_OPERATORS
= true;
436 public boolean SPACE_AROUND_LOGICAL_OPERATORS
= true;
441 public boolean SPACE_AROUND_EQUALITY_OPERATORS
= true;
444 * Controls <, >, <=, >=
446 public boolean SPACE_AROUND_RELATIONAL_OPERATORS
= true;
451 public boolean SPACE_AROUND_BITWISE_OPERATORS
= true;
456 public boolean SPACE_AROUND_ADDITIVE_OPERATORS
= true;
461 public boolean SPACE_AROUND_MULTIPLICATIVE_OPERATORS
= true;
464 * Controls <<. >>, >>>
466 public boolean SPACE_AROUND_SHIFT_OPERATORS
= true;
468 public boolean SPACE_AFTER_COMMA
= true;
469 public boolean SPACE_BEFORE_COMMA
= false;
470 public boolean SPACE_AFTER_SEMICOLON
= true; // in for-statement
471 public boolean SPACE_BEFORE_SEMICOLON
= false; // in for-statement
478 public boolean SPACE_WITHIN_PARENTHESES
= false;
485 public boolean SPACE_WITHIN_METHOD_CALL_PARENTHESES
= false;
488 * "void f( int param )"
490 * "void f(int param)"
492 public boolean SPACE_WITHIN_METHOD_PARENTHESES
= false;
499 public boolean SPACE_WITHIN_IF_PARENTHESES
= false;
506 public boolean SPACE_WITHIN_WHILE_PARENTHESES
= false;
509 * "for( int i = 0; i < 10; i++ )"
511 * "for(int i = 0; i < 10; i++)"
513 public boolean SPACE_WITHIN_FOR_PARENTHESES
= false;
516 * "catch( Exception e )"
518 * "catch(Exception e)"
520 public boolean SPACE_WITHIN_CATCH_PARENTHESES
= false;
527 public boolean SPACE_WITHIN_SWITCH_PARENTHESES
= false;
530 * "synchronized( expr )"
532 * "synchronized(expr)"
534 public boolean SPACE_WITHIN_SYNCHRONIZED_PARENTHESES
= false;
541 public boolean SPACE_WITHIN_CAST_PARENTHESES
= false;
548 public boolean SPACE_WITHIN_BRACKETS
= false;
551 * "int X[] { 1, 3, 5 }"
553 * "int X[] {1, 3, 5}"
555 public boolean SPACE_WITHIN_ARRAY_INITIALIZER_BRACES
= false;
557 public boolean SPACE_AFTER_TYPE_CAST
= true;
564 public boolean SPACE_BEFORE_METHOD_CALL_PARENTHESES
= false;
567 * "void f (int param)"
569 * "void f(int param)"
571 public boolean SPACE_BEFORE_METHOD_PARENTHESES
= false;
578 public boolean SPACE_BEFORE_IF_PARENTHESES
= true;
585 public boolean SPACE_BEFORE_WHILE_PARENTHESES
= true;
592 public boolean SPACE_BEFORE_FOR_PARENTHESES
= true;
599 public boolean SPACE_BEFORE_CATCH_PARENTHESES
= true;
606 public boolean SPACE_BEFORE_SWITCH_PARENTHESES
= true;
609 * "synchronized (...)"
611 * "synchronized(...)"
613 public boolean SPACE_BEFORE_SYNCHRONIZED_PARENTHESES
= true;
620 public boolean SPACE_BEFORE_CLASS_LBRACE
= true;
627 public boolean SPACE_BEFORE_METHOD_LBRACE
= true;
634 public boolean SPACE_BEFORE_IF_LBRACE
= true;
641 public boolean SPACE_BEFORE_ELSE_LBRACE
= true;
648 public boolean SPACE_BEFORE_WHILE_LBRACE
= true;
655 public boolean SPACE_BEFORE_FOR_LBRACE
= true;
662 public boolean SPACE_BEFORE_DO_LBRACE
= true;
669 public boolean SPACE_BEFORE_SWITCH_LBRACE
= true;
676 public boolean SPACE_BEFORE_TRY_LBRACE
= true;
683 public boolean SPACE_BEFORE_CATCH_LBRACE
= true;
690 public boolean SPACE_BEFORE_FINALLY_LBRACE
= true;
693 * "synchronized (...) {"
695 * "synchronized (...){"
697 public boolean SPACE_BEFORE_SYNCHRONIZED_LBRACE
= true;
704 public boolean SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE
= false;
706 public boolean SPACE_BEFORE_QUEST
= true;
707 public boolean SPACE_AFTER_QUEST
= true;
708 public boolean SPACE_BEFORE_COLON
= true;
709 public boolean SPACE_AFTER_COLON
= true;
710 public boolean SPACE_BEFORE_TYPE_PARAMETER_LIST
= false;
712 //----------------- NAMING CONVENTIONS --------------------
714 public String FIELD_NAME_PREFIX
= "";
715 public String STATIC_FIELD_NAME_PREFIX
= "";
716 public String PARAMETER_NAME_PREFIX
= "";
717 public String LOCAL_VARIABLE_NAME_PREFIX
= "";
719 public String FIELD_NAME_SUFFIX
= "";
720 public String STATIC_FIELD_NAME_SUFFIX
= "";
721 public String PARAMETER_NAME_SUFFIX
= "";
722 public String LOCAL_VARIABLE_NAME_SUFFIX
= "";
724 public boolean PREFER_LONGER_NAMES
= true;
726 public final TypeToNameMap FIELD_TYPE_TO_NAME
= new TypeToNameMap();
727 public final TypeToNameMap STATIC_FIELD_TYPE_TO_NAME
= new TypeToNameMap();
728 @NonNls public final TypeToNameMap PARAMETER_TYPE_TO_NAME
= new TypeToNameMap();
729 public final TypeToNameMap LOCAL_VARIABLE_TYPE_TO_NAME
= new TypeToNameMap();
731 //----------------- 'final' modifier settings -------
732 public boolean GENERATE_FINAL_LOCALS
= false;
733 public boolean GENERATE_FINAL_PARAMETERS
= false;
735 //----------------- annotations ----------------
736 public boolean USE_EXTERNAL_ANNOTATIONS
= false;
737 public boolean INSERT_OVERRIDE_ANNOTATION
= true;
739 //----------------- IMPORTS --------------------
741 public boolean LAYOUT_STATIC_IMPORTS_SEPARATELY
= true;
742 public boolean USE_FQ_CLASS_NAMES
= false;
743 public boolean USE_FQ_CLASS_NAMES_IN_JAVADOC
= true;
744 public boolean USE_SINGLE_CLASS_IMPORTS
= true;
745 public boolean INSERT_INNER_CLASS_IMPORTS
= false;
746 public int CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND
= 5;
747 public int NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND
= 3;
748 public final PackageEntryTable PACKAGES_TO_USE_IMPORT_ON_DEMAND
= new PackageEntryTable();
749 public final PackageEntryTable IMPORT_LAYOUT_TABLE
= new PackageEntryTable();
751 //----------------- ORDER OF MEMBERS ------------------
753 public int FIELDS_ORDER_WEIGHT
= 1;
754 public int CONSTRUCTORS_ORDER_WEIGHT
= 2;
755 public int METHODS_ORDER_WEIGHT
= 3;
756 public int INNER_CLASSES_ORDER_WEIGHT
= 4;
758 //----------------- WRAPPING ---------------------------
759 public int RIGHT_MARGIN
= 120;
761 public static final int DO_NOT_WRAP
= 0x00;
762 public static final int WRAP_AS_NEEDED
= 0x01;
763 public static final int WRAP_ALWAYS
= 0x02;
764 public static final int WRAP_ON_EVERY_ITEM
= 0x04;
766 public int CALL_PARAMETERS_WRAP
= DO_NOT_WRAP
;
767 public boolean PREFER_PARAMETERS_WRAP
= false;
768 public boolean CALL_PARAMETERS_LPAREN_ON_NEXT_LINE
= false;
769 public boolean CALL_PARAMETERS_RPAREN_ON_NEXT_LINE
= false;
771 public int METHOD_PARAMETERS_WRAP
= DO_NOT_WRAP
;
772 public boolean METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
= false;
773 public boolean METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE
= false;
775 public int EXTENDS_LIST_WRAP
= DO_NOT_WRAP
;
776 public int THROWS_LIST_WRAP
= DO_NOT_WRAP
;
778 public int EXTENDS_KEYWORD_WRAP
= DO_NOT_WRAP
;
779 public int THROWS_KEYWORD_WRAP
= DO_NOT_WRAP
;
781 public int METHOD_CALL_CHAIN_WRAP
= DO_NOT_WRAP
;
783 public boolean PARENTHESES_EXPRESSION_LPAREN_WRAP
= false;
784 public boolean PARENTHESES_EXPRESSION_RPAREN_WRAP
= false;
786 public int BINARY_OPERATION_WRAP
= DO_NOT_WRAP
;
787 public boolean BINARY_OPERATION_SIGN_ON_NEXT_LINE
= false;
789 public int TERNARY_OPERATION_WRAP
= DO_NOT_WRAP
;
790 public boolean TERNARY_OPERATION_SIGNS_ON_NEXT_LINE
= false;
792 public boolean MODIFIER_LIST_WRAP
= false;
794 public boolean KEEP_SIMPLE_BLOCKS_IN_ONE_LINE
= false;
795 public boolean KEEP_SIMPLE_METHODS_IN_ONE_LINE
= false;
797 public int FOR_STATEMENT_WRAP
= DO_NOT_WRAP
;
798 public boolean FOR_STATEMENT_LPAREN_ON_NEXT_LINE
= false;
799 public boolean FOR_STATEMENT_RPAREN_ON_NEXT_LINE
= false;
801 public int ARRAY_INITIALIZER_WRAP
= DO_NOT_WRAP
;
802 public boolean ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE
= false;
803 public boolean ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE
= false;
805 public int ASSIGNMENT_WRAP
= DO_NOT_WRAP
;
806 public boolean PLACE_ASSIGNMENT_SIGN_ON_NEXT_LINE
= false;
808 public int LABELED_STATEMENT_WRAP
= WRAP_ALWAYS
;
810 public boolean WRAP_COMMENTS
= false;
812 public int ASSERT_STATEMENT_WRAP
= DO_NOT_WRAP
;
813 public boolean ASSERT_STATEMENT_COLON_ON_NEXT_LINE
= false;
816 public static final int DO_NOT_FORCE
= 0x00;
817 public static final int FORCE_BRACES_IF_MULTILINE
= 0x01;
818 public static final int FORCE_BRACES_ALWAYS
= 0x03;
820 public int IF_BRACE_FORCE
= DO_NOT_FORCE
;
821 public int DOWHILE_BRACE_FORCE
= DO_NOT_FORCE
;
822 public int WHILE_BRACE_FORCE
= DO_NOT_FORCE
;
823 public int FOR_BRACE_FORCE
= DO_NOT_FORCE
;
825 //----------------- EJB NAMING CONVENTIONS -------------
827 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
829 @NonNls public String ENTITY_EB_PREFIX
= ""; //EntityBean EJB Class name prefix
831 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
833 @NonNls public String ENTITY_EB_SUFFIX
= "Bean"; //EntityBean EJB Class name suffix
835 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
837 @NonNls public String ENTITY_HI_PREFIX
= ""; //EntityBean Home interface name prefix
839 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
841 @NonNls public String ENTITY_HI_SUFFIX
= "Home"; //EntityBean Home interface name suffix
843 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
845 @NonNls public String ENTITY_RI_PREFIX
= ""; //EntityBean Remote interface name prefix
847 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
849 @NonNls public String ENTITY_RI_SUFFIX
= ""; //EntityBean Remote interface name prefix
851 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
853 @NonNls public String ENTITY_LHI_PREFIX
= "Local"; //EntityBean local Home interface name prefix
855 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
857 @NonNls public String ENTITY_LHI_SUFFIX
= "Home"; //EntityBean local Home interface name suffix
859 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
861 @NonNls public String ENTITY_LI_PREFIX
= "Local"; //EntityBean local interface name prefix
863 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
865 @NonNls public String ENTITY_LI_SUFFIX
= ""; //EntityBean local interface name suffix
867 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
869 @NonNls public String ENTITY_DD_PREFIX
= ""; //EntityBean deployment descriptor name prefix
871 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
873 @NonNls public String ENTITY_DD_SUFFIX
= "EJB"; //EntityBean deployment descriptor name suffix
875 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
877 @NonNls public String ENTITY_VO_PREFIX
= "";
879 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
881 @NonNls public String ENTITY_VO_SUFFIX
= "VO";
883 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
885 @NonNls public String ENTITY_PK_CLASS
= "java.lang.String";
888 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
890 @NonNls public String SESSION_EB_PREFIX
= ""; //SessionBean EJB Class name prefix
892 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
894 @NonNls public String SESSION_EB_SUFFIX
= "Bean"; //SessionBean EJB Class name suffix
896 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
898 @NonNls public String SESSION_HI_PREFIX
= ""; //SessionBean Home interface name prefix
900 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
902 @NonNls public String SESSION_HI_SUFFIX
= "Home"; //SessionBean Home interface name suffix
904 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
906 @NonNls public String SESSION_RI_PREFIX
= ""; //SessionBean Remote interface name prefix
908 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
910 @NonNls public String SESSION_RI_SUFFIX
= ""; //SessionBean Remote interface name prefix
912 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
914 @NonNls public String SESSION_LHI_PREFIX
= "Local"; //SessionBean local Home interface name prefix
916 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
918 @NonNls public String SESSION_LHI_SUFFIX
= "Home"; //SessionBean local Home interface name suffix
920 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
922 @NonNls public String SESSION_LI_PREFIX
= "Local"; //SessionBean local interface name prefix
924 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
926 @NonNls public String SESSION_LI_SUFFIX
= ""; //SessionBean local interface name suffix
928 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
930 @NonNls public String SESSION_SI_PREFIX
= ""; //SessionBean service endpoint interface name prefix
932 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
934 @NonNls public String SESSION_SI_SUFFIX
= "Service"; //SessionBean service endpoint interface name suffix
936 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
938 @NonNls public String SESSION_DD_PREFIX
= ""; //SessionBean deployment descriptor name prefix
940 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
942 @NonNls public String SESSION_DD_SUFFIX
= "EJB"; //SessionBean deployment descriptor name suffix
945 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
947 @NonNls public String MESSAGE_EB_PREFIX
= ""; //MessageBean EJB Class name prefix
949 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
951 @NonNls public String MESSAGE_EB_SUFFIX
= "Bean"; //MessageBean EJB Class name suffix
953 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
955 @NonNls public String MESSAGE_DD_PREFIX
= ""; //MessageBean deployment descriptor name prefix
957 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
959 @NonNls public String MESSAGE_DD_SUFFIX
= "EJB"; //MessageBean deployment descriptor name suffix
960 //----------------- Servlet NAMING CONVENTIONS -------------
962 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
964 @NonNls public String SERVLET_CLASS_PREFIX
= ""; //SERVLET Class name prefix
966 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
968 @NonNls public String SERVLET_CLASS_SUFFIX
= ""; //SERVLET Class name suffix
970 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
972 @NonNls public String SERVLET_DD_PREFIX
= ""; //SERVLET deployment descriptor name prefix
974 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
976 @NonNls public String SERVLET_DD_SUFFIX
= ""; //SERVLET deployment descriptor name suffix
977 //----------------- Web Filter NAMING CONVENTIONS -------------
979 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
981 @NonNls public String FILTER_CLASS_PREFIX
= ""; //Filter Class name prefix
983 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
985 @NonNls public String FILTER_CLASS_SUFFIX
= ""; //Filter Class name suffix
987 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
989 @NonNls public String FILTER_DD_PREFIX
= ""; //Filter deployment descriptor name prefix
991 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
993 @NonNls public String FILTER_DD_SUFFIX
= ""; //Filter deployment descriptor name suffix
996 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
998 @NonNls public String LISTENER_CLASS_PREFIX
= ""; //Listener Class name prefix
1000 * @deprecated use com.intellij.javaee.JavaeeCodeStyleSettings class
1002 @NonNls public String LISTENER_CLASS_SUFFIX
= ""; //Listener Class name suffix
1004 //------------------------------------------------------------------------
1006 // ---------------------------------- Javadoc formatting options -------------------------
1007 public boolean ENABLE_JAVADOC_FORMATTING
= true;
1010 * Align parameter comments to longest parameter name
1012 public boolean JD_ALIGN_PARAM_COMMENTS
= true;
1013 public int JD_MIN_PARM_NAME_LENGTH
= 0;
1014 public int JD_MAX_PARM_NAME_LENGTH
= 30;
1017 * Align exception comments to longest exception name
1019 public boolean JD_ALIGN_EXCEPTION_COMMENTS
= true;
1020 public int JD_MIN_EXCEPTION_NAME_LENGTH
= 0;
1021 public int JD_MAX_EXCEPTION_NAME_LENGTH
= 30;
1023 public boolean JD_ADD_BLANK_AFTER_PARM_COMMENTS
= false;
1024 public boolean JD_ADD_BLANK_AFTER_RETURN
= false;
1025 public boolean JD_ADD_BLANK_AFTER_DESCRIPTION
= true;
1026 public boolean JD_P_AT_EMPTY_LINES
= true;
1028 public boolean JD_KEEP_INVALID_TAGS
= true;
1029 public boolean JD_KEEP_EMPTY_LINES
= true;
1030 public boolean JD_DO_NOT_WRAP_ONE_LINE_COMMENTS
= false;
1032 public boolean JD_USE_THROWS_NOT_EXCEPTION
= true;
1033 public boolean JD_KEEP_EMPTY_PARAMETER
= true;
1034 public boolean JD_KEEP_EMPTY_EXCEPTION
= true;
1035 public boolean JD_KEEP_EMPTY_RETURN
= true;
1038 public boolean JD_LEADING_ASTERISKS_ARE_ENABLED
= true;
1040 // ---------------------------------------------------------------------------------------
1043 // ---------------------------------- XML formatting options -------------------------
1044 public boolean XML_KEEP_WHITESPACES
= false;
1045 public int XML_ATTRIBUTE_WRAP
= WRAP_AS_NEEDED
;
1046 public int XML_TEXT_WRAP
= WRAP_AS_NEEDED
;
1048 public boolean XML_KEEP_LINE_BREAKS
= true;
1049 public boolean XML_KEEP_LINE_BREAKS_IN_TEXT
= true;
1050 public int XML_KEEP_BLANK_LINES
= 2;
1052 public boolean XML_ALIGN_ATTRIBUTES
= true;
1053 public boolean XML_ALIGN_TEXT
= false;
1055 public boolean XML_SPACE_AROUND_EQUALITY_IN_ATTRIBUTE
= false;
1056 public boolean XML_SPACE_AFTER_TAG_NAME
= false;
1057 public boolean XML_SPACE_INSIDE_EMPTY_TAG
= false;
1059 // ---------------------------------------------------------------------------------------
1061 // ---------------------------------- HTML formatting options -------------------------
1062 public boolean HTML_KEEP_WHITESPACES
= false;
1063 public int HTML_ATTRIBUTE_WRAP
= WRAP_AS_NEEDED
;
1064 public int HTML_TEXT_WRAP
= WRAP_AS_NEEDED
;
1066 public boolean HTML_KEEP_LINE_BREAKS
= true;
1067 public boolean HTML_KEEP_LINE_BREAKS_IN_TEXT
= true;
1068 public int HTML_KEEP_BLANK_LINES
= 2;
1070 public boolean HTML_ALIGN_ATTRIBUTES
= true;
1071 public boolean HTML_ALIGN_TEXT
= false;
1073 public boolean HTML_SPACE_AROUND_EQUALITY_IN_ATTRINUTE
= false;
1074 public boolean HTML_SPACE_AFTER_TAG_NAME
= false;
1075 public boolean HTML_SPACE_INSIDE_EMPTY_TAG
= false;
1077 @NonNls public String HTML_ELEMENTS_TO_INSERT_NEW_LINE_BEFORE
= "body,div,p,form,h1,h2,h3";
1078 @NonNls public String HTML_ELEMENTS_TO_REMOVE_NEW_LINE_BEFORE
= "br";
1079 @NonNls public String HTML_DO_NOT_INDENT_CHILDREN_OF
= "html,body,thead,tbody,tfoot";
1080 public int HTML_DO_NOT_ALIGN_CHILDREN_OF_MIN_LINES
= 200;
1082 @NonNls public String HTML_KEEP_WHITESPACES_INSIDE
= "span,pre";
1083 @NonNls public String HTML_INLINE_ELEMENTS
=
1084 "a,abbr,acronym,b,basefont,bdo,big,br,cite,cite,code,dfn,em,font,i,img,input,kbd,label,q,s,samp,select,span,strike,strong,sub,sup,textarea,tt,u,var";
1085 @NonNls public String HTML_DONT_ADD_BREAKS_IF_INLINE_CONTENT
= "title,h1,h2,h3,h4,h5,h6,p";
1087 // ---------------------------------------------------------------------------------------
1090 // true if <%page import="x.y.z, x.y.t"%>
1091 // false if <%page import="x.y.z"%>
1092 // <%page import="x.y.t"%>
1093 public boolean JSP_PREFER_COMMA_SEPARATED_IMPORT_LIST
= false;
1095 //----------------------------------------------------------------------------------------
1097 //-------------- Annotation formatting settings-------------------------------------------
1099 public int METHOD_ANNOTATION_WRAP
= WRAP_ALWAYS
;
1100 public int CLASS_ANNOTATION_WRAP
= WRAP_ALWAYS
;
1101 public int FIELD_ANNOTATION_WRAP
= WRAP_ALWAYS
;
1102 public int PARAMETER_ANNOTATION_WRAP
= DO_NOT_WRAP
;
1103 public int VARIABLE_ANNOTATION_WRAP
= DO_NOT_WRAP
;
1105 public boolean SPACE_BEFORE_ANOTATION_PARAMETER_LIST
= false;
1106 public boolean SPACE_WITHIN_ANNOTATION_PARENTHESES
= false;
1108 //----------------------------------------------------------------------------------------
1111 //-------------------------Enums----------------------------------------------------------
1112 public int ENUM_CONSTANTS_WRAP
= DO_NOT_WRAP
;
1113 //----------------------------------------------------------------------------------------
1115 private CodeStyleSettings myParentSettings
;
1116 private boolean myLoadedAdditionalIndentOptions
;
1118 public void readExternal(Element element
) throws InvalidDataException
{
1119 DefaultJDOMExternalizer
.readExternal(this, element
);
1120 if (LAYOUT_STATIC_IMPORTS_SEPARATELY
) {
1121 // add <all other static imports> entry if there is none
1122 boolean found
= false;
1123 for (PackageEntry entry
: IMPORT_LAYOUT_TABLE
.getEntries()) {
1124 if (entry
== PackageEntry
.ALL_OTHER_STATIC_IMPORTS_ENTRY
) {
1130 PackageEntry last
= IMPORT_LAYOUT_TABLE
.getEntryCount() == 0 ?
null : IMPORT_LAYOUT_TABLE
.getEntryAt(IMPORT_LAYOUT_TABLE
.getEntryCount() - 1);
1131 if (last
!= PackageEntry
.BLANK_LINE_ENTRY
) {
1132 IMPORT_LAYOUT_TABLE
.addEntry(PackageEntry
.BLANK_LINE_ENTRY
);
1134 IMPORT_LAYOUT_TABLE
.addEntry(PackageEntry
.ALL_OTHER_STATIC_IMPORTS_ENTRY
);
1137 importOldIndentOptions(element
);
1138 for (final CustomCodeStyleSettings settings
: myCustomSettings
.values()) {
1139 settings
.readExternal(element
);
1142 final List list
= element
.getChildren(ADDITIONAL_INDENT_OPTIONS
);
1144 for(Object o
:list
) {
1145 if (o
instanceof Element
) {
1146 final Element additionalIndentElement
= (Element
)o
;
1147 final String fileTypeId
= additionalIndentElement
.getAttributeValue(FILETYPE
);
1149 if (fileTypeId
!= null && fileTypeId
.length() > 0) {
1150 FileType target
= FileTypeManager
.getInstance().getFileTypeByExtension(fileTypeId
);
1151 if (FileTypes
.UNKNOWN
== target
|| FileTypes
.PLAIN_TEXT
== target
|| target
.getDefaultExtension().length() == 0) {
1152 target
= new TempFileType(fileTypeId
);
1155 final IndentOptions options
= new IndentOptions();
1156 options
.readExternal(additionalIndentElement
);
1157 registerAdditionalIndentOptions(target
, options
);
1163 copyOldIndentOptions("java", JAVA_INDENT_OPTIONS
);
1164 copyOldIndentOptions("jsp", JSP_INDENT_OPTIONS
);
1165 copyOldIndentOptions("xml", XML_INDENT_OPTIONS
);
1168 private void copyOldIndentOptions(@NonNls final String extension
, final IndentOptions options
) {
1169 final FileType fileType
= FileTypeManager
.getInstance().getFileTypeByExtension(extension
);
1170 if (fileType
!= FileTypes
.UNKNOWN
&& fileType
!= FileTypes
.PLAIN_TEXT
&& !myAdditionalIndentOptions
.containsKey(fileType
)) {
1171 registerAdditionalIndentOptions(fileType
, options
);
1175 private void importOldIndentOptions(@NonNls Element element
) {
1176 final List options
= element
.getChildren("option");
1177 for (Object option1
: options
) {
1178 @NonNls Element option
= (Element
)option1
;
1179 @NonNls final String name
= option
.getAttributeValue("name");
1180 if ("TAB_SIZE".equals(name
)) {
1181 final int value
= Integer
.valueOf(option
.getAttributeValue("value")).intValue();
1182 JAVA_INDENT_OPTIONS
.TAB_SIZE
= value
;
1183 JSP_INDENT_OPTIONS
.TAB_SIZE
= value
;
1184 XML_INDENT_OPTIONS
.TAB_SIZE
= value
;
1185 OTHER_INDENT_OPTIONS
.TAB_SIZE
= value
;
1187 else if ("INDENT_SIZE".equals(name
)) {
1188 final int value
= Integer
.valueOf(option
.getAttributeValue("value")).intValue();
1189 JAVA_INDENT_OPTIONS
.INDENT_SIZE
= value
;
1190 JSP_INDENT_OPTIONS
.INDENT_SIZE
= value
;
1191 XML_INDENT_OPTIONS
.INDENT_SIZE
= value
;
1192 OTHER_INDENT_OPTIONS
.INDENT_SIZE
= value
;
1194 else if ("CONTINUATION_INDENT_SIZE".equals(name
)) {
1195 final int value
= Integer
.valueOf(option
.getAttributeValue("value")).intValue();
1196 JAVA_INDENT_OPTIONS
.CONTINUATION_INDENT_SIZE
= value
;
1197 JSP_INDENT_OPTIONS
.CONTINUATION_INDENT_SIZE
= value
;
1198 XML_INDENT_OPTIONS
.CONTINUATION_INDENT_SIZE
= value
;
1199 OTHER_INDENT_OPTIONS
.CONTINUATION_INDENT_SIZE
= value
;
1201 else if ("USE_TAB_CHARACTER".equals(name
)) {
1202 final boolean value
= Boolean
.valueOf(option
.getAttributeValue("value")).booleanValue();
1203 JAVA_INDENT_OPTIONS
.USE_TAB_CHARACTER
= value
;
1204 JSP_INDENT_OPTIONS
.USE_TAB_CHARACTER
= value
;
1205 XML_INDENT_OPTIONS
.USE_TAB_CHARACTER
= value
;
1206 OTHER_INDENT_OPTIONS
.USE_TAB_CHARACTER
= value
;
1208 else if ("SMART_TABS".equals(name
)) {
1209 final boolean value
= Boolean
.valueOf(option
.getAttributeValue("value")).booleanValue();
1210 JAVA_INDENT_OPTIONS
.SMART_TABS
= value
;
1211 JSP_INDENT_OPTIONS
.SMART_TABS
= value
;
1212 XML_INDENT_OPTIONS
.SMART_TABS
= value
;
1213 OTHER_INDENT_OPTIONS
.SMART_TABS
= value
;
1218 public void writeExternal(Element element
) throws WriteExternalException
{
1219 final CodeStyleSettings parentSettings
= new CodeStyleSettings();
1220 DefaultJDOMExternalizer
.writeExternal(this, element
, new DifferenceFilter
<CodeStyleSettings
>(this, parentSettings
));
1221 List
<CustomCodeStyleSettings
> customSettings
= new ArrayList
<CustomCodeStyleSettings
>(myCustomSettings
.values());
1223 Collections
.sort(customSettings
, new Comparator
<CustomCodeStyleSettings
>(){
1224 public int compare(final CustomCodeStyleSettings o1
, final CustomCodeStyleSettings o2
) {
1225 return o1
.getTagName().compareTo(o2
.getTagName());
1229 for (final CustomCodeStyleSettings settings
: customSettings
) {
1230 final CustomCodeStyleSettings parentCustomSettings
= parentSettings
.getCustomSettings(settings
.getClass());
1231 assert parentCustomSettings
!= null;
1232 settings
.writeExternal(element
, parentCustomSettings
);
1235 final FileType
[] fileTypes
= myAdditionalIndentOptions
.keySet().toArray(new FileType
[myAdditionalIndentOptions
.keySet().size()]);
1236 Arrays
.sort(fileTypes
, new Comparator
<FileType
>() {
1237 public int compare(final FileType o1
, final FileType o2
) {
1238 return o1
.getDefaultExtension().compareTo(o2
.getDefaultExtension());
1242 for (FileType fileType
: fileTypes
) {
1243 final IndentOptions indentOptions
= myAdditionalIndentOptions
.get(fileType
);
1244 Element additionalIndentOptions
= new Element(ADDITIONAL_INDENT_OPTIONS
);
1245 indentOptions
.writeExternal(additionalIndentOptions
);
1246 additionalIndentOptions
.setAttribute(FILETYPE
,fileType
.getDefaultExtension());
1247 element
.addContent(additionalIndentOptions
);
1251 public IndentOptions
getIndentOptions(FileType fileType
) {
1252 if (USE_SAME_INDENTS
|| fileType
== null) return OTHER_INDENT_OPTIONS
;
1254 if (!myLoadedAdditionalIndentOptions
) {
1255 loadAdditionalIndentOptions();
1257 final IndentOptions indentOptions
= myAdditionalIndentOptions
.get(fileType
);
1258 if (indentOptions
!= null) return indentOptions
;
1260 return OTHER_INDENT_OPTIONS
;
1263 public boolean isSmartTabs(FileType fileType
) {
1264 return getIndentOptions(fileType
).SMART_TABS
;
1267 public int getIndentSize(FileType fileType
) {
1268 return getIndentOptions(fileType
).INDENT_SIZE
;
1271 public int getContinuationIndentSize(FileType fileType
) {
1272 return getIndentOptions(fileType
).CONTINUATION_INDENT_SIZE
;
1275 public int getLabelIndentSize(FileType fileType
) {
1276 return getIndentOptions(fileType
).LABEL_INDENT_SIZE
;
1279 public boolean getLabelIndentAbsolute(FileType fileType
) {
1280 return getIndentOptions(fileType
).LABEL_INDENT_ABSOLUTE
;
1283 public int getTabSize(FileType fileType
) {
1284 return getIndentOptions(fileType
).TAB_SIZE
;
1287 public boolean useTabCharacter(FileType fileType
) {
1288 return getIndentOptions(fileType
).USE_TAB_CHARACTER
;
1291 public static class TypeToNameMap
implements JDOMExternalizable
{
1292 private final List
<String
> myPatterns
= new ArrayList
<String
>();
1293 private final List
<String
> myNames
= new ArrayList
<String
>();
1295 public void addPair(String pattern
, String name
) {
1296 myPatterns
.add(pattern
);
1300 public String
nameByType(String type
) {
1301 for (int i
= 0; i
< myPatterns
.size(); i
++) {
1302 String pattern
= myPatterns
.get(i
);
1303 if (StringUtil
.startsWithChar(pattern
, '*')) {
1304 if (type
.endsWith(pattern
.substring(1))) {
1305 return myNames
.get(i
);
1309 if (type
.equals(pattern
)) {
1310 return myNames
.get(i
);
1317 public void readExternal(@NonNls Element element
) throws InvalidDataException
{
1320 for (final Object o
: element
.getChildren("pair")) {
1321 @NonNls Element e
= (Element
)o
;
1323 String pattern
= e
.getAttributeValue("type");
1324 String name
= e
.getAttributeValue("name");
1325 if (pattern
== null || name
== null) {
1326 throw new InvalidDataException();
1328 myPatterns
.add(pattern
);
1334 public void writeExternal(Element parentNode
) throws WriteExternalException
{
1335 for (int i
= 0; i
< myPatterns
.size(); i
++) {
1336 String pattern
= myPatterns
.get(i
);
1337 String name
= myNames
.get(i
);
1338 @NonNls Element element
= new Element("pair");
1339 parentNode
.addContent(element
);
1340 element
.setAttribute("type", pattern
);
1341 element
.setAttribute("name", name
);
1345 public void copyFrom(TypeToNameMap from
) {
1346 assert from
!= this;
1348 myPatterns
.addAll(from
.myPatterns
);
1350 myNames
.addAll(from
.myNames
);
1353 public boolean equals(Object other
) {
1354 if (other
instanceof TypeToNameMap
) {
1355 TypeToNameMap otherMap
= (TypeToNameMap
)other
;
1356 if (myPatterns
.size() != otherMap
.myPatterns
.size()) {
1359 if (myNames
.size() != otherMap
.myNames
.size()) {
1362 for (int i
= 0; i
< myPatterns
.size(); i
++) {
1363 String s1
= myPatterns
.get(i
);
1364 String s2
= otherMap
.myPatterns
.get(i
);
1365 if (!Comparing
.equal(s1
, s2
)) {
1369 for (int i
= 0; i
< myNames
.size(); i
++) {
1370 String s1
= myNames
.get(i
);
1371 String s2
= otherMap
.myNames
.get(i
);
1372 if (!Comparing
.equal(s1
, s2
)) {
1381 public int hashCode() {
1383 for (String myPattern
: myPatterns
) {
1384 code
+= myPattern
.hashCode();
1386 for (String myName
: myNames
) {
1387 code
+= myName
.hashCode();
1394 private void registerAdditionalIndentOptions(FileType fileType
, IndentOptions options
) {
1395 myAdditionalIndentOptions
.put(fileType
, options
);
1398 public IndentOptions
getAdditionalIndentOptions(FileType fileType
) {
1399 if (!myLoadedAdditionalIndentOptions
) {
1400 loadAdditionalIndentOptions();
1402 return myAdditionalIndentOptions
.get(fileType
);
1405 private void loadAdditionalIndentOptions() {
1406 myLoadedAdditionalIndentOptions
= true;
1407 final FileTypeIndentOptionsProvider
[] providers
= Extensions
.getExtensions(FileTypeIndentOptionsProvider
.EP_NAME
);
1408 for (final FileTypeIndentOptionsProvider provider
: providers
) {
1409 if (!myAdditionalIndentOptions
.containsKey(provider
.getFileType())) {
1410 registerAdditionalIndentOptions(provider
.getFileType(), provider
.createIndentOptions());
1416 public void clearCodeStyleSettings() throws Exception
{
1417 CodeStyleSettings cleanSettings
= new CodeStyleSettings();
1418 copyFrom(cleanSettings
);
1419 myAdditionalIndentOptions
.clear(); //hack
1420 myLoadedAdditionalIndentOptions
= false;
1423 private static class TempFileType
implements FileType
{
1424 private final String myExtension
;
1426 private TempFileType(@NotNull final String extension
) {
1427 myExtension
= extension
;
1431 public String
getName() {
1432 return "TempFileType";
1436 public String
getDescription() {
1437 return "TempFileType";
1441 public String
getDefaultExtension() {
1445 public Icon
getIcon() {
1449 public boolean isBinary() {
1453 public boolean isReadOnly() {
1457 public String
getCharset(@NotNull VirtualFile file
, byte[] content
) {