Refactory: remove unused classes, imports, fields and methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / formatter / impl / FormatterOptions.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.formatter.impl;
12
13 import java.util.Map;
14
15 public class FormatterOptions {
16
17         /**
18          * Option IDs
19          */
20         public static final String OPTION_InsertNewlineBeforeOpeningBrace = "net.sourceforge.phpeclipse.formatter.newline.openingBrace"; //$NON-NLS-1$
21
22         public static final String OPTION_InsertNewlineInControlStatement = "net.sourceforge.phpeclipse.formatter.newline.controlStatement"; //$NON-NLS-1$
23
24         // public static final String OPTION_InsertNewLineBetweenElseAndIf =
25         // "net.sourceforge.phpeclipse.formatter.newline.elseIf"; //$NON-NLS-1$
26         public static final String OPTION_InsertNewLineInEmptyBlock = "net.sourceforge.phpeclipse.formatter.newline.emptyBlock"; //$NON-NLS-1$
27
28         public static final String OPTION_ClearAllBlankLines = "net.sourceforge.phpeclipse.formatter.newline.clearAll"; //$NON-NLS-1$
29
30         public static final String OPTION_SplitLineExceedingLength = "net.sourceforge.phpeclipse.formatter.lineSplit"; //$NON-NLS-1$
31
32         public static final String OPTION_CompactAssignment = "net.sourceforge.phpeclipse.formatter.style.assignment"; //$NON-NLS-1$
33
34         public static final String OPTION_CompactStringConcatenation = "net.sourceforge.phpeclipse.formatter.style.compactStringConcatenation"; //$NON-NLS-1$
35
36         public static final String OPTION_CompactArrays = "net.sourceforge.phpeclipse.formatter.style.compactArrays"; //$NON-NLS-1$
37         
38         public static final String OPTION_TabulationChar = "net.sourceforge.phpeclipse.formatter.tabulation.char"; //$NON-NLS-1$
39
40         public static final String OPTION_TabulationSize = "net.sourceforge.phpeclipse.formatter.tabulation.size"; //$NON-NLS-1$
41
42         public static final String OPTION_CompactDereferencing = "net.sourceforge.phpeclipse.formatter.style.assignment";
43
44         // TODO: add the checkbox in the preferences panel ; load/save
45
46         public static final String INSERT = "insert"; //$NON-NLS-1$
47
48         public static final String DO_NOT_INSERT = "do not insert"; //$NON-NLS-1$
49
50         public static final String PRESERVE_ONE = "preserve one"; //$NON-NLS-1$
51
52         public static final String CLEAR_ALL = "clear all"; //$NON-NLS-1$
53
54         public static final String NORMAL = "normal"; //$NON-NLS-1$
55
56         public static final String COMPACT = "compact"; //$NON-NLS-1$
57
58         public static final String TAB = "tab"; //$NON-NLS-1$
59
60         public static final String SPACE = "space"; //$NON-NLS-1$
61
62         // by default, do not insert blank line before opening brace
63         public boolean newLineBeforeOpeningBraceMode = false;
64
65         // by default, do not insert blank line behind keywords (ELSE, CATCH,
66         // FINALLY,...) in control statements
67         public boolean newlineInControlStatementMode = false;
68
69         // by default, preserve one blank line per sequence of blank lines
70         public boolean clearAllBlankLinesMode = false;
71
72         // line splitting will occur when line exceeds this length
73         public int maxLineLength = 80;
74
75         public boolean compactAssignmentMode = false;
76         
77         public boolean compactStringConcatenation = false;
78
79         public boolean compactArrays = false;
80         
81         // if isTrue, assignments look like x= 12 (not like x = 12);
82         public boolean compactDereferencingMode = true;
83
84         // if isTrue, dereferencing look like $obj->method (not like $obj ->
85         // method);
86
87         // number of consecutive spaces used to replace the tab char
88         public int tabSize = 4; // n spaces for one tab
89
90         public boolean indentWithTab = true;
91
92         // public boolean compactElseIfMode = true;
93         // if true, else and if are kept on the same line.
94         public boolean newLineInEmptyBlockMode = true;
95
96         // if false, no new line in {} if it's empty.
97
98         public char[] lineSeparatorSequence = System
99                         .getProperty("line.separator").toCharArray(); //$NON-NLS-1$
100
101         /**
102          * Initializing the formatter options with default settings
103          */
104         public FormatterOptions() {
105         }
106
107         /**
108          * Initializing the formatter options with external settings
109          */
110         public FormatterOptions(Map settings) {
111                 if (settings == null)
112                         return;
113
114                 // filter options which are related to the assist component
115                 Object[] entries = settings.entrySet().toArray();
116                 for (int i = 0, max = entries.length; i < max; i++) {
117                         Map.Entry entry = (Map.Entry) entries[i];
118                         if (!(entry.getKey() instanceof String))
119                                 continue;
120                         if (!(entry.getValue() instanceof String))
121                                 continue;
122                         String optionID = (String) entry.getKey();
123                         String optionValue = (String) entry.getValue();
124
125                         if (optionID.equals(OPTION_InsertNewlineBeforeOpeningBrace)) {
126                                 if (optionValue.equals(INSERT)) {
127                                         this.newLineBeforeOpeningBraceMode = true;
128                                 } else if (optionValue.equals(DO_NOT_INSERT)) {
129                                         this.newLineBeforeOpeningBraceMode = false;
130                                 }
131                                 continue;
132                         }
133                         if (optionID.equals(OPTION_InsertNewlineInControlStatement)) {
134                                 if (optionValue.equals(INSERT)) {
135                                         this.newlineInControlStatementMode = true;
136                                 } else if (optionValue.equals(DO_NOT_INSERT)) {
137                                         this.newlineInControlStatementMode = false;
138                                 }
139                                 continue;
140                         }
141                         if (optionID.equals(OPTION_ClearAllBlankLines)) {
142                                 if (optionValue.equals(CLEAR_ALL)) {
143                                         this.clearAllBlankLinesMode = true;
144                                 } else if (optionValue.equals(PRESERVE_ONE)) {
145                                         this.clearAllBlankLinesMode = false;
146                                 }
147                                 continue;
148                         }
149                         // if (optionID.equals(OPTION_InsertNewLineBetweenElseAndIf)) {
150                         // if (optionValue.equals(INSERT)) {
151                         // this.compactElseIfMode = false;
152                         // } else if (optionValue.equals(DO_NOT_INSERT)) {
153                         // this.compactElseIfMode = true;
154                         // }
155                         // continue;
156                         // }
157                         if (optionID.equals(OPTION_InsertNewLineInEmptyBlock)) {
158                                 if (optionValue.equals(INSERT)) {
159                                         this.newLineInEmptyBlockMode = true;
160                                 } else if (optionValue.equals(DO_NOT_INSERT)) {
161                                         this.newLineInEmptyBlockMode = false;
162                                 }
163                                 continue;
164                         }
165                         if (optionID.equals(OPTION_SplitLineExceedingLength)) {
166                                 try {
167                                         int val = Integer.parseInt(optionValue);
168                                         if (val >= 0)
169                                                 this.maxLineLength = val;
170                                 } catch (NumberFormatException e) {
171                                 }
172                         }
173                         if (optionID.equals(OPTION_CompactAssignment)) {
174                                 if (optionValue.equals(COMPACT)) {
175                                         this.compactAssignmentMode = true;
176                                 } else if (optionValue.equals(NORMAL)) {
177                                         this.compactAssignmentMode = false;
178                                 }
179                                 continue;
180                         }
181                         if (optionID.equals(OPTION_CompactArrays)) {
182                                 if (optionValue.equals(COMPACT)) {
183                                         this.compactArrays = true;
184                                 } else if (optionValue.equals(NORMAL)) {
185                                         this.compactArrays = false;
186                                 }
187                                 continue;
188                         }
189                         if (optionID.equals(OPTION_CompactStringConcatenation)) {
190                                 if (optionValue.equals(COMPACT)) {
191                                         this.compactStringConcatenation = true;
192                                 } else if (optionValue.equals(NORMAL)) {
193                                         this.compactStringConcatenation = false;
194                                 }
195                                 continue;
196                         }
197                         if (optionID.equals(OPTION_TabulationChar)) {
198                                 if (optionValue.equals(TAB)) {
199                                         this.indentWithTab = true;
200                                 } else if (optionValue.equals(SPACE)) {
201                                         this.indentWithTab = false;
202                                 }
203                                 continue;
204                         }
205                         if (optionID.equals(OPTION_TabulationSize)) {
206                                 try {
207                                         int val = Integer.parseInt(optionValue);
208                                         if (val > 0)
209                                                 this.tabSize = val;
210                                 } catch (NumberFormatException e) {
211                                 }
212                         }
213                 }
214         }
215
216         /**
217          * 
218          * @return int
219          */
220 //      public int getMaxLineLength() {
221 //              return maxLineLength;
222 //      }
223
224 //      public int getTabSize() {
225 //              return tabSize;
226 //      }
227
228 //      public boolean isAddingNewLineBeforeOpeningBrace() {
229 //              return newLineBeforeOpeningBraceMode;
230 //      }
231
232 //      public boolean isAddingNewLineInControlStatement() {
233 //              return newlineInControlStatementMode;
234 //      }
235
236 //      public boolean isAddingNewLineInEmptyBlock() {
237 //              return newLineInEmptyBlockMode;
238 //      }
239
240 //      public boolean isClearingAllBlankLines() {
241 //              return clearAllBlankLinesMode;
242 //      }
243
244 //      public boolean isCompactingAssignment() {
245 //              return compactAssignmentMode;
246 //      }
247
248 //      public boolean isCompactingDereferencing() {
249 //              return compactDereferencingMode;
250 //      }
251
252         // public boolean isCompactingElseIf() {
253         // return compactElseIfMode;
254         // }
255 //      public boolean isUsingTabForIndenting() {
256 //              return indentWithTab;
257 //      }
258
259         public void setLineSeparator(String lineSeparator) {
260                 lineSeparatorSequence = lineSeparator.toCharArray();
261         }
262
263         /**
264          * @deprecated - should use a Map when creating the options.
265          */
266 //      public void setMaxLineLength(int maxLineLength) {
267 //              this.maxLineLength = maxLineLength;
268 //      }
269         /**
270          * @deprecated - should use a Map when creating the options.
271          */
272         // public void setCompactElseIfMode(boolean flag) {
273         // compactElseIfMode = flag;
274         // }
275 }