src/share/classes/com/sun/tools/javac/util/BaseFileManager.java

changeset 1157
3809292620c9
parent 1136
ae361e7f435a
child 1442
fcf89720ae71
equal deleted inserted replaced
1156:4822dfe0922b 1157:3809292620c9
44 import java.nio.charset.UnsupportedCharsetException; 44 import java.nio.charset.UnsupportedCharsetException;
45 import java.util.Collection; 45 import java.util.Collection;
46 import java.util.HashMap; 46 import java.util.HashMap;
47 import java.util.Iterator; 47 import java.util.Iterator;
48 import java.util.Map; 48 import java.util.Map;
49 import java.util.Set;
49 import javax.tools.JavaFileObject; 50 import javax.tools.JavaFileObject;
50 import javax.tools.JavaFileObject.Kind; 51 import javax.tools.JavaFileObject.Kind;
51 52
52 import com.sun.tools.javac.code.Lint; 53 import com.sun.tools.javac.code.Lint;
53 import com.sun.tools.javac.code.Source; 54 import com.sun.tools.javac.code.Source;
54 import com.sun.tools.javac.file.FSInfo; 55 import com.sun.tools.javac.file.FSInfo;
55 import com.sun.tools.javac.file.Locations; 56 import com.sun.tools.javac.file.Locations;
56 import com.sun.tools.javac.main.JavacOption; 57 import com.sun.tools.javac.main.Option;
57 import com.sun.tools.javac.main.OptionName; 58 import com.sun.tools.javac.main.OptionHelper;
58 import com.sun.tools.javac.main.RecognizedOptions; 59 import com.sun.tools.javac.main.OptionHelper.GrumpyHelper;
59 import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; 60 import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition;
60 61
61 /** 62 /**
62 * Utility methods for building a filemanager. 63 * Utility methods for building a filemanager.
63 * There are no references here to file-system specific objects such as 64 * There are no references here to file-system specific objects such as
99 protected String classLoaderClass; 100 protected String classLoaderClass;
100 101
101 protected Locations locations; 102 protected Locations locations;
102 103
103 protected Source getSource() { 104 protected Source getSource() {
104 String sourceName = options.get(OptionName.SOURCE); 105 String sourceName = options.get(Option.SOURCE);
105 Source source = null; 106 Source source = null;
106 if (sourceName != null) 107 if (sourceName != null)
107 source = Source.lookup(sourceName); 108 source = Source.lookup(sourceName);
108 return (source != null ? source : Source.DEFAULT); 109 return (source != null ? source : Source.DEFAULT);
109 } 110 }
143 return new URLClassLoader(urls, thisClassLoader); 144 return new URLClassLoader(urls, thisClassLoader);
144 } 145 }
145 146
146 // <editor-fold defaultstate="collapsed" desc="Option handling"> 147 // <editor-fold defaultstate="collapsed" desc="Option handling">
147 public boolean handleOption(String current, Iterator<String> remaining) { 148 public boolean handleOption(String current, Iterator<String> remaining) {
148 for (JavacOption o: javacFileManagerOptions) { 149 OptionHelper helper = new GrumpyHelper(log) {
150 @Override
151 public String get(Option option) {
152 return options.get(option.getText());
153 }
154
155 @Override
156 public void put(String name, String value) {
157 options.put(name, value);
158 }
159
160 @Override
161 public void remove(String name) {
162 options.remove(name);
163 }
164 };
165 for (Option o: javacFileManagerOptions) {
149 if (o.matches(current)) { 166 if (o.matches(current)) {
150 if (o.hasArg()) { 167 if (o.hasArg()) {
151 if (remaining.hasNext()) { 168 if (remaining.hasNext()) {
152 if (!o.process(options, current, remaining.next())) 169 if (!o.process(helper, current, remaining.next()))
153 return true; 170 return true;
154 } 171 }
155 } else { 172 } else {
156 if (!o.process(options, current)) 173 if (!o.process(helper, current))
157 return true; 174 return true;
158 } 175 }
159 // operand missing, or process returned false 176 // operand missing, or process returned false
160 throw new IllegalArgumentException(current); 177 throw new IllegalArgumentException(current);
161 } 178 }
162 } 179 }
163 180
164 return false; 181 return false;
165 } 182 }
166 // where 183 // where
167 private static JavacOption[] javacFileManagerOptions = 184 private static Set<Option> javacFileManagerOptions =
168 RecognizedOptions.getJavacFileManagerOptions( 185 Option.getJavacFileManagerOptions();
169 new RecognizedOptions.GrumpyHelper(Log.instance(new Context())));
170 186
171 public int isSupportedOption(String option) { 187 public int isSupportedOption(String option) {
172 for (JavacOption o : javacFileManagerOptions) { 188 for (Option o : javacFileManagerOptions) {
173 if (o.matches(option)) 189 if (o.matches(option))
174 return o.hasArg() ? 1 : 0; 190 return o.hasArg() ? 1 : 0;
175 } 191 }
176 return -1; 192 return -1;
177 } 193 }
189 } 205 }
190 return defaultEncodingName; 206 return defaultEncodingName;
191 } 207 }
192 208
193 public String getEncodingName() { 209 public String getEncodingName() {
194 String encName = options.get(OptionName.ENCODING); 210 String encName = options.get(Option.ENCODING);
195 if (encName == null) 211 if (encName == null)
196 return getDefaultEncodingName(); 212 return getDefaultEncodingName();
197 else 213 else
198 return encName; 214 return encName;
199 } 215 }

mercurial