KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > Options


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.base;
26
27 import java.util.*;
28 import java.io.File JavaDoc;
29 import java.lang.reflect.Field JavaDoc;
30 import java.lang.reflect.Modifier JavaDoc;
31
32
33 public class Options {
34     public static final String JavaDoc version = org.aspectj.compiler.Version.text;
35     public static final long build = org.aspectj.compiler.Version.time;
36     private static final File JavaDoc defaultOutputDir = new File JavaDoc(".");
37     public static File JavaDoc getDefaultOutputDir() { return defaultOutputDir; }
38
39     public File JavaDoc outputDir = defaultOutputDir;
40     public File JavaDoc workingDir = new File JavaDoc("ajworkingdir");
41
42     public String JavaDoc classpath = null;
43     //{ addStringOption("classpath", "Specify where to find user class files"); }
44
public String JavaDoc defaultClasspath = null;
45
46     public String JavaDoc bootclasspath = null;
47     public String JavaDoc extdirs = null;
48
49     public String JavaDoc source = "1.3";
50
51     public boolean lenient = false;
52     public boolean strict = false;
53
54     public String JavaDoc encoding = null;
55
56     public boolean porting = false;
57
58     public boolean ignoreErrors = false;
59
60     public boolean runForever = false;
61
62     public boolean mangler = false;
63
64     public boolean force = true;
65     public boolean nocomments = false; // This could be fancier...
66
public boolean verbose = false; // This should be more sophisticated...
67
public boolean preprocess = false;
68     public boolean usejavac = false;
69     public boolean bcgverbose = false;
70     public boolean bcgtrace = false;
71
72     public boolean newWeaving = true;
73
74     public boolean strictTree = false;
75     
76     /**
77      * true when we should generate code in locations like javac does.
78      * This is meaningless (and ignored) in two cases:
79      * <ul> <li> when {@link #usejavac} is true </li>
80      * <li> when {@link #outputDir} is set to not its default value </li>
81      * </ul>
82      * If this is true and meaningful, then class files will be generated in
83      * the same directory as their associated source file. If this is false or
84      * non meaningful, then the location of the generated classfiles is determined
85      * by their enclosing package, rather than defining sourcefile.
86      */

87     public boolean XtargetNearSource = false;
88
89     public boolean O = false;
90     public boolean deprecation = false;
91
92     public boolean noMetaJoinPointOptimization = false;
93     public boolean alwaysMakeAroundClosures = false;
94
95     // lintish stuff
96
public boolean Xlint = false;
97
98     // special hack added for Arno Schmidmeier
99
public boolean XserializableAspects = false;
100
101     // safer names for bean and EJB reflective code
102
public boolean XaddSafePrefix = false;
103     
104     // special hack for David Holmes and OVM PCES work
105
public boolean XOcodeSize = false;
106
107     //XXX need something fancier for g:{...} and g:none
108
public boolean g = false;
109
110     public String JavaDoc target = null;
111
112     // for internal development use
113
public boolean dumpstack = false;
114     public boolean timings = false;
115     public boolean noVersionWarnings = false;
116
117     public boolean prettyPrint = false;
118
119     public boolean nosymbols = false;
120
121     public boolean emacssym = false;
122
123     /**
124      * Makes the compiler likelier ot blow-up
125      * 1. will show stack traces even if there's been an error
126      * 2. does more things
127      */

128     public boolean torture = false;
129     public boolean developer = false;
130
131     // generate code that will cause some jvm's to reveal their bugs
132
public boolean jvmTorture = false;
133
134
135     // number of threads, threads==0 means disable multi-threaded
136
// concurrent compilation
137
public int threads = 0;
138     public int procs = 1;
139
140     // incremental compilation requested
141
public boolean incremental = false;
142
143     public boolean isStringOption(String JavaDoc key) {
144         try {
145             Field JavaDoc field = Options.class.getField(key);
146             if (Modifier.isFinal(field.getModifiers())) return false;
147             if (field.getType() != String JavaDoc.class) return false;
148             return true;
149         } catch (NoSuchFieldException JavaDoc e) {
150             return false;
151         }
152     }
153
154     public boolean isIntegerOption(String JavaDoc key) {
155         try {
156             Field JavaDoc field = Options.class.getField(key);
157             if (Modifier.isFinal(field.getModifiers())) return false;
158             if (field.getType() != Integer.TYPE) return false;
159             return true;
160         } catch (NoSuchFieldException JavaDoc e) {
161             return false;
162         }
163     }
164
165     public boolean set(String JavaDoc key, Object JavaDoc value) {
166         try {
167             Field JavaDoc field = Options.class.getField(key);
168             if (Modifier.isFinal(field.getModifiers())) return false;
169             if (Modifier.isStatic(field.getModifiers())) {
170                 field.set(null,value);
171             } else {
172                 field.set(this,value);
173             }
174             return true;
175         } catch (IllegalArgumentException JavaDoc e) {
176             return false;
177         } catch (NoSuchFieldException JavaDoc e) {
178             return false;
179         } catch (IllegalAccessException JavaDoc e) {
180             throw new RuntimeException JavaDoc("internal error setting option: "+key);
181         }
182     }
183
184     public String JavaDoc setOptions(String JavaDoc[] args, File JavaDoc currentWorkingDir) {
185         for (int i = 0; i < args.length ; i++) {
186             String JavaDoc arg = args[i];
187             //System.out.println("arg: "+arg);
188
String JavaDoc key = arg.substring(1);
189             Object JavaDoc value = Boolean.TRUE;
190
191             if (arg.equals("-d")) {
192                 if ((i+1) >= args.length) return arg;
193                 outputDir = qualifiedFile(args[++i], currentWorkingDir);
194                 continue;
195             } else if (arg.equals("-workingdir")) {
196                 if ((i+1) >= args.length) return arg;
197                 workingDir = qualifiedFile(args[++i], currentWorkingDir);
198                 continue;
199             } else if (isStringOption(key)) {
200                 if ((i+1) >= args.length) return arg;
201                 value = args[++i];
202             }
203             else if (isIntegerOption(key)) {
204                 if ((i+1) >= args.length) return arg;
205                 value = Integer.valueOf(args[++i]);
206             }
207             if (!set(key, value)) {
208                 return arg;
209             }
210         }
211         return null;
212     }
213
214     private File JavaDoc qualifiedFile(String JavaDoc name, File JavaDoc currentWorkingDir) {
215         name = name.replace('/', File.separatorChar);
216         File JavaDoc file = new File JavaDoc(name);
217         if (!file.isAbsolute() && currentWorkingDir != null) {
218             file = new File JavaDoc(currentWorkingDir, name);
219         }
220         return file;
221     }
222
223
224 }
225
Popular Tags