Java Code Examples for java.util.prefs.Preferences#remove()

The following examples show how to use java.util.prefs.Preferences#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNewLineIndentationBeforeEmptyHalfIndentedBlock() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.put("otherBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
    try {
        performNewLineIndentationTest("package t;\npublic class T {\n    public void op() {|{\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\n          {\n    }\n}\n");
    } finally {
        preferences.remove("otherBracePlacement");
    }
}
 
Example 2
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNewLineIndentationBeforeHalfIndentedSwitchEnd() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.put("otherBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
    try {
        performNewLineIndentationTest("package t;\npublic class T {\n    public void op() {\n        switch(get())\n          {\n            case 1:\n                break;|}\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\n        switch(get())\n          {\n            case 1:\n                break;\n          }\n    }\n}\n");
    } finally {
        preferences.remove("otherBracePlacement");
    }
}
 
Example 3
Source File: ImportAnalysisTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testAddImport6() throws IOException {
    JavaSource src = getJavaSource(testFile);
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.putBoolean("importInnerClasses", true);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
            MethodTree node = (MethodTree) clazz.getMembers().get(0);
            BlockTree body = node.getBody();
            List<StatementTree> stats = new ArrayList<StatementTree>();
            for (StatementTree st : body.getStatements()) {
                stats.add(st);
            }
            TypeElement list = workingCopy.getElements().getTypeElement("java.util.Map.Entry");
            Types types = workingCopy.getTypes();
            stats.add(make.Variable(make.Modifiers(Collections.<Modifier>emptySet()), "entry", make.Type(types.erasure(list.asType())), null));
            workingCopy.rewrite(body, make.Block(stats, false));
        }
    };
    src.runModificationTask(task).commit();
    preferences.remove("importInnerClasses");
    assertFiles("testAddImport6.pass");
}
 
Example 4
Source File: OpenProjectListSettings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String putGroupedProperty(String key, String value, boolean notify) {
    Preferences prefs = getPreferences(true);
    String retval = prefs.get(key, null);
    if (value != null) {
        prefs.put(key, value);
    } else {
        prefs.remove(key);
    }
    return retval;
}
 
Example 5
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNewLineIndentationBeforeHalfIndentedDoWhileBlock() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.put("otherBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
    try {
        performNewLineIndentationTest("package t;\npublic class T {\n    public void op() {\n        do| {\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\n        do\n          {\n    }\n}\n");
    } finally {
        preferences.remove("otherBracePlacement");
    }
}
 
Example 6
Source File: CheckUserPrefLater.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class);
    String result = prefs.get("Check", null);
    if ((result == null) || !(result.equals("Success")))
        throw new RuntimeException("User pref not stored!");
    prefs.remove("Check");
    prefs.flush();
}
 
Example 7
Source File: MavenProjectSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void setSettings(Project project, String key, String value, boolean shared) {
    Preferences preferences = getPreferences(project, shared);
    if (value != null) {
        preferences.put(key, value);
    } else {
        preferences.remove(key);
    }
    try {
        preferences.flush();
        preferences.sync();
    } catch (BackingStoreException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 8
Source File: CheckUserPrefLater.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class);
    String result = prefs.get("Check", null);
    if ((result == null) || !(result.equals("Success")))
        throw new RuntimeException("User pref not stored!");
    prefs.remove("Check");
    prefs.flush();
}
 
Example 9
Source File: CheckUserPrefLater.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class);
    String result = prefs.get("Check", null);
    if ((result == null) || !(result.equals("Success")))
        throw new RuntimeException("User pref not stored!");
    prefs.remove("Check");
    prefs.flush();
}
 
Example 10
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testLineIndentationBeforeHalfIndentedTryBlock() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.put("otherBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
    try {
        performLineIndentationTest("package t;\npublic class T {\n    public void op() {\n        try\n|            {\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\n        try\n          {\n    }\n}\n");
    } finally {
        preferences.remove("otherBracePlacement");
    }
}
 
Example 11
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testLineIndentationBeforeHalfIndentedNewArrayInit() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.put("otherBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
    try {
        performLineIndentationTest("package t;\npublic class T {\n    public void op() {\n        int[] arr = new int[]\n|                {\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\n        int[] arr = new int[]\n          {\n    }\n}\n");
    } finally {
        preferences.remove("otherBracePlacement");
    }
}
 
Example 12
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNewLineIndentationAtWrongIndentedMultilineCommentStart() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.putBoolean("enableBlockCommentFormatting", true);
    try {
        performNewLineIndentationTest("package t;\npublic class T {\n   /*|\n    public void op() {\n    }\n}\n",
                "package t;\npublic class T {\n   /*\n    * \n    public void op() {\n    }\n}\n");
    } finally {
        preferences.remove("enableBlockCommentFormatting");
    }
}
 
Example 13
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNewLineIndentationBeforeHalfIndentedElseBlock() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.put("otherBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
    try {
        performNewLineIndentationTest("package t;\npublic class T {\n    public void op() {\n        if (true) {\n        } else| {\n        }\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\n        if (true) {\n        } else\n          {\n        }\n    }\n}\n");
    } finally {
        preferences.remove("otherBracePlacement");
    }
}
 
Example 14
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNewLineIndentationBeforeEmptyHalfIndentedClassEnd() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.put("classDeclBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
    try {
        performNewLineIndentationTest("package t;\npublic class T\n  {|}\n",
                "package t;\npublic class T\n  {\n  }\n");
    } finally {
        preferences.remove("classDeclBracePlacement");
    }
}
 
Example 15
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testLineIndentationInsideAbsolutLabeledStatement() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.putBoolean("absoluteLabelIndent", true);
    try {
        performLineIndentationTest("package t;\npublic class T {\n    public void op() {\nmylabel:\n|\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\nmylabel:\n        \n    }\n}\n");
    } finally {
        preferences.remove("absoluteLabelIndent");
    }
}
 
Example 16
Source File: MetadataProjectHudsonProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public boolean recordAssociation(Project project, Association assoc) {
    Preferences prefs = ProjectUtils.getPreferences(project, MetadataProjectHudsonProvider.class, true);
    if (assoc != null) {
        prefs.put(KEY, assoc.toString());
    } else {
        prefs.remove(KEY);
    }
    return true;
}
 
Example 17
Source File: TinyTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void setValues(Preferences p, Map<String, String> values) {
    for (Entry<String, String> e : values.entrySet()) {
        if (e.getValue() != null) {
            p.put(e.getKey(), e.getValue());
        } else {
            p.remove(e.getKey());
        }
    }
}
 
Example 18
Source File: FmtOptions.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void storeData(JComponent jc, String optionID, Preferences node) {

            if (jc instanceof JTextField) {
                JTextField field = (JTextField) jc;

                String text = field.getText();

                // XXX test for numbers
                if (isInteger(optionID)) {
                    try {
                        Integer.parseInt(text);
                    } catch (NumberFormatException e) {
                        return;
                    }
                }

                // XXX: watch out, tabSize, spacesPerTab, indentSize and expandTabToSpaces
                // fall back on getGlopalXXX() values and not getDefaultAsXXX value,
                // which is why we must not remove them. Proper solution would be to
                // store formatting preferences to MimeLookup and not use NbPreferences.
                // The problem currently is that MimeLookup based Preferences do not support subnodes.
                if (!optionID.equals(TAB_SIZE)
                        && !optionID.equals(SPACES_PER_TAB) && !optionID.equals(INDENT_SIZE)
                        && getDefaultAsString(optionID).equals(text)) {
                    node.remove(optionID);
                } else {
                    node.put(optionID, text);
                }
            } else if (jc instanceof JCheckBox) {
                JCheckBox checkBox = (JCheckBox) jc;
                if (!optionID.equals(EXPAND_TAB_TO_SPACES) && getDefaultAsBoolean(optionID) == checkBox.isSelected()) {
                    node.remove(optionID);
                } else {
                    node.putBoolean(optionID, checkBox.isSelected());
                }
            } else if (jc instanceof JComboBox) {
                JComboBox cb = (JComboBox) jc;
                ComboItem comboItem = ((ComboItem) cb.getSelectedItem());
                String value = comboItem == null ? getDefaultAsString(optionID) : comboItem.value;

                if (getDefaultAsString(optionID).equals(value)) {
                    node.remove(optionID);
                } else {
                    node.put(optionID, value);
                }
            }
        }
 
Example 19
Source File: RecentPathsTest.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    Preferences preferences = Preferences.userNodeForPackage(RecentPathsTest.class).node("test");
    preferences.remove("recents");
    recentPaths = new RecentPaths(Preferences.userNodeForPackage(RecentPathsTest.class).node("test"), "recents", false);
}
 
Example 20
Source File: Utils.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static <T extends Enum<T>> void putPrefsEnum(Preferences prefs, String key, T value, T def) {
	if (value != def)
		prefs.put(key, value.name());
	else
		prefs.remove(key);
}