001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.model.compiler;
038:
039: import edu.rice.cs.drjava.config.*;
040: import edu.rice.cs.drjava.DrJava;
041:
042: import java.util.HashMap;
043:
044: /** Represents the compiler warnings */
045:
046: public class CompilerOptions implements OptionConstants {
047:
048: private static boolean SHOW_UNCHECKED = DrJava.getConfig()
049: .getSetting(SHOW_UNCHECKED_WARNINGS);
050: private static boolean SHOW_DEPRECATION = DrJava.getConfig()
051: .getSetting(SHOW_DEPRECATION_WARNINGS);
052: private static boolean SHOW_PATH = DrJava.getConfig().getSetting(
053: SHOW_PATH_WARNINGS);
054: private static boolean SHOW_SERIAL = DrJava.getConfig().getSetting(
055: SHOW_SERIAL_WARNINGS);
056: private static boolean SHOW_FINALLY = DrJava.getConfig()
057: .getSetting(SHOW_FINALLY_WARNINGS);
058: private static boolean SHOW_FALLTHROUGH = DrJava.getConfig()
059: .getSetting(SHOW_FALLTHROUGH_WARNINGS);
060:
061: private static WarningOptionListener wol = new WarningOptionListener();
062:
063: /**
064: * The OptionListener for the Warning Options
065: */
066: private static class WarningOptionListener implements
067: OptionListener<Boolean> {
068: public void optionChanged(OptionEvent<Boolean> oce) {
069: updateWarnings();
070: }
071: }
072:
073: public static void updateWarnings() {
074: SHOW_UNCHECKED = DrJava.getConfig().getSetting(
075: SHOW_UNCHECKED_WARNINGS);
076: SHOW_DEPRECATION = DrJava.getConfig().getSetting(
077: SHOW_DEPRECATION_WARNINGS);
078: SHOW_PATH = DrJava.getConfig().getSetting(SHOW_PATH_WARNINGS);
079: SHOW_SERIAL = DrJava.getConfig().getSetting(
080: SHOW_SERIAL_WARNINGS);
081: SHOW_FINALLY = DrJava.getConfig().getSetting(
082: SHOW_FINALLY_WARNINGS);
083: SHOW_FALLTHROUGH = DrJava.getConfig().getSetting(
084: SHOW_FALLTHROUGH_WARNINGS);
085: }
086:
087: static {
088: DrJava.getConfig().addOptionListener(
089: OptionConstants.SHOW_UNCHECKED_WARNINGS, wol);
090: DrJava.getConfig().addOptionListener(
091: OptionConstants.SHOW_DEPRECATION_WARNINGS, wol);
092: DrJava.getConfig().addOptionListener(
093: OptionConstants.SHOW_PATH_WARNINGS, wol);
094: DrJava.getConfig().addOptionListener(
095: OptionConstants.SHOW_SERIAL_WARNINGS, wol);
096: DrJava.getConfig().addOptionListener(
097: OptionConstants.SHOW_FINALLY_WARNINGS, wol);
098: DrJava.getConfig().addOptionListener(
099: OptionConstants.SHOW_FALLTHROUGH_WARNINGS, wol);
100: }
101:
102: public static HashMap<String, String> getOptions(
103: boolean warningsEnabled) {
104: HashMap<String, String> options = new HashMap<String, String>();
105: if (warningsEnabled) {
106: if (SHOW_UNCHECKED) {
107: options.put("-Xlint:unchecked", "");
108: }
109:
110: if (SHOW_DEPRECATION) {
111: options.put("-Xlint:deprecation", "");
112: }
113:
114: if (SHOW_PATH) {
115: options.put("-Xlint:path", "");
116: }
117:
118: if (SHOW_SERIAL) {
119: options.put("-Xlint:serial", "");
120: }
121:
122: if (SHOW_FINALLY) {
123: options.put("-Xlint:finally", "");
124: }
125:
126: if (SHOW_FALLTHROUGH) {
127: options.put("-Xlint:fallthrough", "");
128: options.put("-Xlint:switchcheck", ""); //Some compilers appear to use this option instead. Anyone know anything about this?
129: }
130: }
131:
132: //Add any other options we want to add to the compiler in the future
133: return options;
134: }
135: }
|