1 19 20 package org.netbeans.modules.java.settings; 21 22 import java.beans.*; 23 import java.util.HashMap ; 24 import org.netbeans.jmi.javamodel.PrimitiveType; 25 import org.netbeans.jmi.javamodel.Type; 26 27 import org.openide.options.SystemOption; 28 import org.openide.util.HelpCtx; 29 import org.openide.util.NbBundle; 30 31 35 public class JavaSynchronizationSettings extends SystemOption { 36 37 static final long serialVersionUID = 24341252342342345L; 38 39 public static final String PROP_GENERATE_RETURN = "generateReturn"; 41 public static final int RETURN_GEN_NOTHING = 0; 42 public static final int RETURN_GEN_EXCEPTION = 1; 43 public static final int RETURN_GEN_NULL = 2; 44 45 private static final String [] RETURN_STRINGS = { 46 "\n", "\nthrow new UnsupportedOperationException();\n", "\nreturn null;\n" }; 48 49 private static final HashMap RETURN_STRINGS_PRIMITIVE; 50 51 static { 52 String number = "\nreturn 0;\n"; RETURN_STRINGS_PRIMITIVE = new HashMap (); 54 RETURN_STRINGS_PRIMITIVE.put("void", RETURN_STRINGS[RETURN_GEN_NOTHING]); RETURN_STRINGS_PRIMITIVE.put("boolean", "\nreturn false;\n"); RETURN_STRINGS_PRIMITIVE.put("int", number); RETURN_STRINGS_PRIMITIVE.put("char", "\nreturn ' ';\n"); RETURN_STRINGS_PRIMITIVE.put("byte", number); RETURN_STRINGS_PRIMITIVE.put("short", number); RETURN_STRINGS_PRIMITIVE.put("long", number); RETURN_STRINGS_PRIMITIVE.put("float", number); RETURN_STRINGS_PRIMITIVE.put("double", number); } 64 65 private static int generateReturn = RETURN_GEN_NOTHING; 66 67 68 public String displayName() { 69 return NbBundle.getBundle(JavaSynchronizationSettings.class).getString("CTL_JavaSynchronization_Settings"); 70 } 71 72 public HelpCtx getHelpCtx () { 73 return new HelpCtx (JavaSynchronizationSettings.class); 74 } 75 76 public int getGenerateReturn() { 77 return generateReturn; 78 } 79 80 public void setGenerateReturn(int val) { 81 if (generateReturn != val) { 82 int old = generateReturn; 83 generateReturn = val; 84 firePropertyChange(PROP_GENERATE_RETURN, new Integer (old), new Integer (val)); 85 } 86 } 87 88 public String getGenerateReturnAsString(Type type) { 89 if (generateReturn == RETURN_GEN_NULL) { 90 if (type instanceof PrimitiveType) 91 return (String ) RETURN_STRINGS_PRIMITIVE.get(type.getName()); 92 else 93 return RETURN_STRINGS[RETURN_GEN_NULL]; 94 } 95 else 96 return RETURN_STRINGS[generateReturn]; 97 } 98 } 99 | Popular Tags |