1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import java.util.StringTokenizer ; 14 15 import org.eclipse.jface.preference.IPreferenceStore; 16 17 import org.eclipse.jdt.core.IJavaProject; 18 19 import org.eclipse.jdt.ui.PreferenceConstants; 20 21 import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings; 22 import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil; 23 24 public class JavaPreferencesSettings { 25 26 27 public static CodeGenerationSettings getCodeGenerationSettings(IJavaProject project) { 28 CodeGenerationSettings res= new CodeGenerationSettings(); 29 res.createComments= Boolean.valueOf(PreferenceConstants.getPreference(PreferenceConstants.CODEGEN_ADD_COMMENTS, project)).booleanValue(); 30 res.useKeywordThis= Boolean.valueOf(PreferenceConstants.getPreference(PreferenceConstants.CODEGEN_KEYWORD_THIS, project)).booleanValue(); 31 res.overrideAnnotation= Boolean.valueOf(PreferenceConstants.getPreference(PreferenceConstants.CODEGEN_USE_OVERRIDE_ANNOTATION, project)).booleanValue(); 32 res.importOrder= getImportOrderPreference(project); 33 res.importThreshold= getImportNumberThreshold(project); 34 res.staticImportThreshold= getStaticImportNumberThreshold(project); 35 res.importIgnoreLowercase= Boolean.valueOf(PreferenceConstants.getPreference(PreferenceConstants.ORGIMPORTS_IGNORELOWERCASE, project)).booleanValue(); 36 res.tabWidth= CodeFormatterUtil.getTabWidth(project); 37 res.indentWidth= CodeFormatterUtil.getIndentWidth(project); 38 return res; 39 } 40 41 44 public static CodeGenerationSettings getCodeGenerationSettings() { 45 return getCodeGenerationSettings(null); 46 } 47 48 public static int getImportNumberThreshold(IJavaProject project) { 49 String thresholdStr= PreferenceConstants.getPreference(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD, project); 50 try { 51 int threshold= Integer.parseInt(thresholdStr); 52 if (threshold < 0) { 53 threshold= Integer.MAX_VALUE; 54 } 55 return threshold; 56 } catch (NumberFormatException e) { 57 return Integer.MAX_VALUE; 58 } 59 } 60 61 public static int getStaticImportNumberThreshold(IJavaProject project) { 62 String thresholdStr= PreferenceConstants.getPreference(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD, project); 63 try { 64 int threshold= Integer.parseInt(thresholdStr); 65 if (threshold < 0) { 66 threshold= Integer.MAX_VALUE; 67 } 68 return threshold; 69 } catch (NumberFormatException e) { 70 return Integer.MAX_VALUE; 71 } 72 } 73 74 public static String [] getImportOrderPreference(IJavaProject project) { 75 String str= PreferenceConstants.getPreference(PreferenceConstants.ORGIMPORTS_IMPORTORDER, project); 76 if (str != null) { 77 return unpackList(str, ";"); } 79 return new String [0]; 80 } 81 82 85 public static int getImportNumberThreshold(IPreferenceStore prefs) { 86 int threshold= prefs.getInt(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD); 87 if (threshold < 0) { 88 threshold= Integer.MAX_VALUE; 89 } 90 return threshold; 91 } 92 93 96 public static String [] getImportOrderPreference(IPreferenceStore prefs) { 97 String str= prefs.getString(PreferenceConstants.ORGIMPORTS_IMPORTORDER); 98 if (str != null) { 99 return unpackList(str, ";"); } 101 return new String [0]; 102 } 103 104 private static String [] unpackList(String str, String separator) { 105 StringTokenizer tok= new StringTokenizer (str, separator); 106 int nTokens= tok.countTokens(); 107 String [] res= new String [nTokens]; 108 for (int i= 0; i < nTokens; i++) { 109 res[i]= tok.nextToken().trim(); 110 } 111 return res; 112 } 113 114 115 } 116 117 | Popular Tags |