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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.preferences;
13 import java.util.StringTokenizer;
15 import net.sourceforge.phpdt.internal.corext.codemanipulation.CodeGenerationSettings;
16 import net.sourceforge.phpdt.internal.corext.util.CodeFormatterUtil;
17 import net.sourceforge.phpdt.ui.PreferenceConstants;
19 import org.eclipse.jface.preference.IPreferenceStore;
21 public class JavaPreferencesSettings {
23 public static CodeGenerationSettings getCodeGenerationSettings() {
24 IPreferenceStore store= PreferenceConstants.getPreferenceStore();
26 CodeGenerationSettings res= new CodeGenerationSettings();
27 res.createComments= store.getBoolean(PreferenceConstants.CODEGEN_ADD_COMMENTS);
28 res.useKeywordThis= store.getBoolean(PreferenceConstants.CODEGEN_KEYWORD_THIS);
29 res.importOrder= getImportOrderPreference(store);
30 res.importThreshold= getImportNumberThreshold(store);
31 res.tabWidth= CodeFormatterUtil.getTabWidth();
35 public static int getImportNumberThreshold(IPreferenceStore prefs) {
36 int threshold= prefs.getInt(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD);
38 threshold= Integer.MAX_VALUE;
44 public static String[] getImportOrderPreference(IPreferenceStore prefs) {
45 String str= prefs.getString(PreferenceConstants.ORGIMPORTS_IMPORTORDER);
47 return unpackList(str, ";"); //$NON-NLS-1$
52 private static String[] unpackList(String str, String separator) {
53 StringTokenizer tok= new StringTokenizer(str, separator); //$NON-NLS-1$
54 int nTokens= tok.countTokens();
55 String[] res= new String[nTokens];
56 for (int i= 0; i < nTokens; i++) {
57 res[i]= tok.nextToken().trim();