Detect <?= as PHP start tag
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / preferences / JavaPreferencesSettings.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.preferences;
12
13 import java.util.StringTokenizer;
14
15 import org.eclipse.jface.preference.IPreferenceStore;
16
17 import net.sourceforge.phpdt.ui.PreferenceConstants;
18
19 import net.sourceforge.phpdt.internal.corext.codemanipulation.CodeGenerationSettings;
20 import net.sourceforge.phpdt.internal.corext.util.CodeFormatterUtil;
21  
22 public class JavaPreferencesSettings  {
23         
24         public static CodeGenerationSettings getCodeGenerationSettings() {
25                 IPreferenceStore store= PreferenceConstants.getPreferenceStore();
26                 
27                 CodeGenerationSettings res= new CodeGenerationSettings();
28                 res.createComments= store.getBoolean(PreferenceConstants.CODEGEN_ADD_COMMENTS);
29                 res.useKeywordThis= store.getBoolean(PreferenceConstants.CODEGEN_KEYWORD_THIS);
30                 res.importOrder= getImportOrderPreference(store);
31                 res.importThreshold= getImportNumberThreshold(store);
32                 res.tabWidth= CodeFormatterUtil.getTabWidth();
33                 return res;
34         }
35
36         public static int getImportNumberThreshold(IPreferenceStore prefs) {
37                 int threshold= prefs.getInt(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD);
38                 if (threshold < 0) {
39                         threshold= Integer.MAX_VALUE;
40                 }
41                 return threshold;
42         }
43
44
45         public static String[] getImportOrderPreference(IPreferenceStore prefs) {
46                 String str= prefs.getString(PreferenceConstants.ORGIMPORTS_IMPORTORDER);
47                 if (str != null) {
48                         return unpackList(str, ";"); //$NON-NLS-1$
49                 }
50                 return new String[0];
51         }
52                 
53         private static String[] unpackList(String str, String separator) {
54                 StringTokenizer tok= new StringTokenizer(str, separator); //$NON-NLS-1$
55                 int nTokens= tok.countTokens();
56                 String[] res= new String[nTokens];
57                 for (int i= 0; i < nTokens; i++) {
58                         res[i]= tok.nextToken().trim();
59                 }
60                 return res;
61         }
62         
63                 
64 }
65