2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
41
package org.netbeans.modules.java.source.tasklist;
43
import java.util.HashMap;
45
import java.util.prefs.Preferences;
46
import org.netbeans.api.java.source.JavaSource;
47
import org.openide.util.NbPreferences;
53
public class CompilerSettings {
55
private CompilerSettings() {
58
public static final String ENABLE_LINT = "enable_lint";
59
public static final String ENABLE_LINT_DEPRECATION = "enable_lint_deprecation";
60
public static final String ENABLE_LINT_UNCHECKED = "enable_lint_unchecked";
61
public static final String ENABLE_LINT_FALLTHROUGH = "enable_lint_fallthrough";
62
public static final String ENABLE_LINT_SERIAL = "enable_lint_serial";
63
public static final String ENABLE_LINT_FINALLY = "enable_lint_finally";
64
public static final String ENABLE_LINT_CAST = "enable_lint_cast";
65
public static final String ENABLE_LINT_DIVZERO = "enable_lint_dvizero";
66
public static final String ENABLE_LINT_EMPTY = "enable_lint_empty";
67
public static final String ENABLE_LINT_OVERRIDES = "enable_lint_overrides";
69
private static final Map<String, Boolean> DEFAULTS;
72
DEFAULTS = new HashMap<String, Boolean>();
74
DEFAULTS.put(ENABLE_LINT, false);
75
DEFAULTS.put(ENABLE_LINT_DEPRECATION, false);
76
DEFAULTS.put(ENABLE_LINT_UNCHECKED, false);
77
DEFAULTS.put(ENABLE_LINT_FALLTHROUGH, false);
78
DEFAULTS.put(ENABLE_LINT_SERIAL, false);
79
DEFAULTS.put(ENABLE_LINT_FINALLY, false);
80
DEFAULTS.put(ENABLE_LINT_CAST, false);
81
DEFAULTS.put(ENABLE_LINT_DIVZERO, false);
82
DEFAULTS.put(ENABLE_LINT_EMPTY, false);
83
DEFAULTS.put(ENABLE_LINT_OVERRIDES, false);
86
public static Preferences getNode() {
87
return NbPreferences.forModule(JavaSource.class).node("compiler_settings");
90
public static String getCommandLine() {
91
Preferences p = getNode();
93
StringBuilder sb = new StringBuilder();
95
if (get(p, ENABLE_LINT_DEPRECATION))
96
sb.append("-Xlint:deprecation ");
97
if (get(p, ENABLE_LINT_UNCHECKED))
98
sb.append("-Xlint:unchecked ");
99
if (get(p, ENABLE_LINT_FALLTHROUGH))
100
sb.append("-Xlint:fallthrough ");
101
if (get(p, ENABLE_LINT_SERIAL))
102
sb.append("-Xlint:serial ");
103
if (get(p, ENABLE_LINT_FINALLY))
104
sb.append("-Xlint:finally ");
105
if (get(p, ENABLE_LINT_CAST))
106
sb.append("-Xlint:cast ");
107
if (get(p, ENABLE_LINT_DIVZERO))
108
sb.append("-Xlint:divzero ");
109
if (get(p, ENABLE_LINT_EMPTY))
110
sb.append("-Xlint:empty ");
111
if (get(p, ENABLE_LINT_OVERRIDES))
112
sb.append("-Xlint:overrides ");
114
if (sb.length() > 0 && sb.charAt(sb.length() - 1) == ' ') {
115
sb.deleteCharAt(sb.length() - 1);
118
return sb.toString();
121
public static boolean get(Preferences p, String key) {
122
return p.getBoolean(key, DEFAULTS.get(key));