Skip to content

Commit ab9e3c1

Browse files
author
rcartwright
committed
Added support for Java 6.0 by creating a new compiler adapter.
git-svn-id: file:///tmp/test-svn/trunk@3569 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 0ceee5d commit ab9e3c1

20 files changed

+164
-204
lines changed

drjava/src/edu/rice/cs/drjava/config/FontOption.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public class FontOption extends Option<Font> {
4343

4444
public FontOption(String key, Font def) { super(key,def); }
4545

46-
//Changed on 5/19/2004 to reflect a change in the API specifications of decode in the most recent release of
47-
//java 1.5.0 beta. Decode no longer likes "PLAIN", assuming it to be default and returning the wrong font (dialog)
48-
//if the word is present /**/ This may be fixed in future versions of 1.5.0, but the use of the word PLAIN appears to
49-
//have been deprecated since 1.3
46+
/* Changed on 5/19/2004 to reflect a change in the API specifications of decode in the most recent release of
47+
* Java 1.5.0 beta. Decode no longer likes "PLAIN", assuming it to be default and returning the wrong font (dialog)
48+
* if the word is present This may be fixed in future versions of 1.5.0, but the use of the word PLAIN appears to
49+
* have been deprecated since 1.3 */
5050
public Font parse(String s) {
5151
String newS = s;// s.replaceAll("PLAIN-","")
5252
int idx = newS.indexOf("PLAIN-");
@@ -57,10 +57,7 @@ public Font parse(String s) {
5757
return Font.decode(newS); //Font.decode(s);
5858
}
5959

60-
/**
61-
* Create a String representation of the Font object, in the format:
62-
* fontname-fontstyle-fontsize
63-
*/
60+
/** Create a String representation of the Font object, in the format: fontname-fontstyle-fontsize. */
6461
public String format(Font f) {
6562
StringBuffer str = new StringBuffer(f.getName());
6663
str.append("-");

drjava/src/edu/rice/cs/drjava/config/OptionConstants.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public interface OptionConstants {
9595
new ColorOption("interactions.error.color", Color.red.darker());
9696
public static final ColorOption DEBUG_MESSAGE_COLOR = new ColorOption("debug.message.color", Color.blue.darker());
9797

98-
9998
/** Color for background of definitions pane. */
10099
public static final ColorOption DEFINITIONS_BACKGROUND_COLOR =
101100
new ColorOption("definitions.background.color", Color.white);
@@ -829,7 +828,7 @@ public static ArrayList<String> evaluate() {
829828

830829
static final String[] choices = new String[]{JAVADOC_NONE_TEXT, JAVADOC_1_3_TEXT, JAVADOC_1_4_TEXT, JAVADOC_1_5_TEXT};
831830

832-
static final ArrayList<String> linkVersionChoices = new ArrayList(Arrays.asList(choices));
831+
static final ArrayList<String> linkVersionChoices = new ArrayList<String>(Arrays.asList(choices));
833832

834833
/** Constants for the URLs of Sun's system class documentation for different versions of Java. */
835834
public static final StringOption JAVADOC_1_3_LINK =

drjava/src/edu/rice/cs/drjava/model/GlobalModelCompileSuccessTestCase.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,5 @@ protected String _name() {
101101
/**
102102
* Returns whether the currently active compiler supports generics.
103103
*/
104-
protected boolean _isGenericCompiler() {
105-
String name = _model.getCompilerModel().getActiveCompiler().getClass().getName();
106-
for (int i=0; i < CompilerRegistry.GENERIC_JAVA_COMPILERS.length; i++) {
107-
if (name.equals(CompilerRegistry.GENERIC_JAVA_COMPILERS[i])) {
108-
//System.out.println(name + " supports generics");
109-
return true;
110-
}
111-
}
112-
//System.out.println(name + " doesn't support generics");
113-
return false;
114-
}
104+
protected boolean _isGenericCompiler() { return ! CompilerProxy.VERSION.equals("1.4"); }
115105
}

drjava/src/edu/rice/cs/drjava/model/MultiThreadedTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public static void wait(Object o) {
9595
o.wait();
9696
}
9797
catch(InterruptedException e) {
98-
throw new edu.rice.cs.util.UnexpectedException(e, "Thread.join was unexpectedly interrupted.");
98+
e.printStackTrace();
99+
throw new edu.rice.cs.util.UnexpectedException(e, "Thread.wait was unexpectedly interrupted.");
99100
}
100101
}
101102

drjava/src/edu/rice/cs/drjava/model/compiler/CompilerError.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,13 @@ public CompilerError(File file, int lineNumber, int startColumn, String message,
7373
if (lineNumber < 0) _noLocation = true;
7474
}
7575

76-
/**
77-
* Constructor for an CompilerError with an associated file but no location in the source
78-
*/
79-
public CompilerError(File file, String message, boolean isWarning) {
80-
this(file, -1, -1, message, isWarning);
81-
}
76+
/** Constructor for an CompilerError with an associated file but no location in the source */
77+
public CompilerError(File file, String message, boolean isWarning) { this(file, -1, -1, message, isWarning); }
8278

8379
/** Constructor for CompilerErrors without files.
8480
* @param message the error message
8581
*/
86-
public CompilerError(String message, boolean isWarning) {
87-
this(null, message, isWarning);
88-
}
89-
82+
public CompilerError(String message, boolean isWarning) { this(null, message, isWarning); }
9083

9184
/** This function returns true if and only if the given error has no location */
9285
public boolean hasNoLocation() { return _noLocation; }
@@ -168,7 +161,7 @@ public String getLineMessage() {
168161
* files. Warnings are considered greater than errors, all else equal.
169162
*/
170163
public int compareTo(Object o) {
171-
CompilerError other = (CompilerError)o;
164+
CompilerError other = (CompilerError) o;
172165

173166
// Determine if I have a file
174167
if (_file != null) {
@@ -186,16 +179,13 @@ public int compareTo(Object o) {
186179
// My file is null
187180
if (other.file() == null) {
188181
// All else equal.
189-
// I'm a warning. I'm not a warning.
190-
return (this.isWarning()? (other.isWarning()? 0:1):(other.isWarning()? -1:0));
182+
// I'm a warning. I'm not a warning.
183+
return (this.isWarning() ? (other.isWarning() ? 0 : 1) : (other.isWarning()? -1:0));
191184
}
192185
else return -1; // Errors without files are smaller
193186
}
194187

195-
/**
196-
* Compares this error with the given one, based first
197-
* on line number, and then by column.
198-
*/
188+
/** Compares this error with the given one, based first on line number, and then by column. */
199189
private int compareByPosition(CompilerError other) {
200190
// Compare by line unless lines are equal
201191
if (_lineNumber == other._lineNumber) {

drjava/src/edu/rice/cs/drjava/model/compiler/CompilerProxy.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import edu.rice.cs.drjava.DrJava;
3939
import edu.rice.cs.util.classloader.StickyClassLoader;
4040
import edu.rice.cs.util.ClassPathVector;
41+
import edu.rice.cs.util.swing.Utilities;
4142
import edu.rice.cs.drjava.config.OptionConstants;
4243
import edu.rice.cs.drjava.config.FileOption;
4344

@@ -46,6 +47,8 @@
4647
*/
4748
public class CompilerProxy implements CompilerInterface {
4849

50+
public static final String VERSION = System.getProperty("java.specification.version");
51+
4952
/** The actual compiler interface. If it's null, we couldn't load it. */
5053
private CompilerInterface _realCompiler = null;
5154

@@ -82,6 +85,7 @@ private void _recreateCompiler() {
8285

8386
try {
8487
Class<?> c = loader.loadClass(_className);
88+
// Utilities.show("Class " + c + " loaded");
8589
_realCompiler = CompilerRegistry.createCompiler(c);
8690

8791
_realCompiler.setBuildDirectory(_buildDir);
@@ -95,8 +99,10 @@ private void _recreateCompiler() {
9599
_realCompiler.setAllowAssertions(allowAssertions);
96100

97101
String compilerClass = _realCompiler.getClass().getName();
102+
// Utilities.show("Compiler created with name " + compilerClass);
98103
}
99-
catch (Throwable t) { /* don't do anything. realCompiler stays null. */ }
104+
catch (Throwable t) { /* don't do anything. realCompiler stays null. */ }
105+
100106
}
101107

102108

@@ -139,51 +145,42 @@ public CompilerError[] compile(File[] sourceRoots, File[] files) {
139145
* the {@link #compile} method should not fail due to class not being found.
140146
*/
141147
public boolean isAvailable() {
148+
// Utilities.show("CompilerProxy.isAvailable() called for " + getClass() + " real compiler = " + _realCompiler);
142149
if (_realCompiler == null) return false;
143150
else return _realCompiler.isAvailable();
144151
}
145152

146153
/** Returns the name of this compiler, appropriate to show to the user. */
147154
public String getName() {
148-
if (!isAvailable()) return "(unavailable)";
155+
if (! isAvailable()) return "(unavailable)";
149156
return _realCompiler.getName();
150157
}
151158

152159
/** Should return info about compiler, at least including name. */
153160
public String toString() { return getName(); }
154161

155-
/** Allows us to set the extra classpath for the compilers without referencing the
156-
* config object in a loaded class file
157-
*/
158-
public void setExtraClassPath( String extraClassPath) {
159-
_realCompiler.setExtraClassPath(extraClassPath);
160-
}
162+
/** Sets the extra classpath for the compilers without referencing the config object in a loaded class file. */
163+
public void setExtraClassPath( String extraClassPath) { _realCompiler.setExtraClassPath(extraClassPath); }
161164

162165
/** Sets the extra classpath in the form of a ClasspathVector. This should include any classpath entries from the
163166
* project's classpath, if any, and the entries from EXTRA_CLASSPATH.
164167
* @param extraClassPath the classpath to use as the compiler's extra classpath
165168
*/
166-
public void setExtraClassPath(ClassPathVector extraClassPath) {
167-
_extraClassPath = extraClassPath;
168-
}
169+
public void setExtraClassPath(ClassPathVector extraClassPath) { _extraClassPath = extraClassPath; }
169170

170171
/** Sets whether to allow assertions in Java 1.4. */
171-
public void setAllowAssertions(boolean allow) {
172-
_realCompiler.setAllowAssertions(allow);
173-
}
172+
public void setAllowAssertions(boolean allow) { _realCompiler.setAllowAssertions(allow); }
174173

175174
/** Sets whether or not warnings are allowed. */
176175
public void setWarningsEnabled(boolean warningsEnabled) {
177176
_realCompiler.setWarningsEnabled(warningsEnabled);
178177
_warningsEnabled = warningsEnabled;
179178
}
180179

181-
/** This method allows us to set the JSR14 collections path across a class loader.
180+
/** Sets the JSR14 collections path across a class loader.
182181
* (cannot cast a loaded class to a subclass, so all compiler interfaces must have this method)
183182
*/
184-
public void addToBootClassPath( File cp) {
185-
_realCompiler.addToBootClassPath(cp);
186-
}
183+
public void addToBootClassPath( File cp) { _realCompiler.addToBootClassPath(cp); }
187184

188185
/** Sets the build directory for the compilers. */
189186
public void setBuildDirectory(File buildDir) {

drjava/src/edu/rice/cs/drjava/model/compiler/CompilerRegistry.java

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,50 @@
3535

3636
import java.util.LinkedList;
3737
import java.lang.reflect.Field;
38+
import edu.rice.cs.util.swing.Utilities;
39+
import edu.rice.cs.util.UnexpectedException;
3840

3941
/** Registry for all CompilerInterface implementations. Allows registration, by class name, of {@link CompilerInterface}
4042
* implementations. Later, the list of these registered compilers (but only those that successfully loaded) can be
4143
* retrieved.
4244
* @version $Id$
4345
*/
4446
public class CompilerRegistry {
45-
46-
/** A subset of DEFAULT_COMPILERS that support Generic Java. */
47-
public static final String[] GENERIC_JAVA_COMPILERS = {
47+
48+
/* classes that load and adapt various compilers */
49+
50+
public static final String[] JAVA_16_COMPILERS = {
51+
// javac 1.6
52+
"edu.rice.cs.drjava.model.compiler.Javac160FromSetLocation",
53+
"edu.rice.cs.drjava.model.compiler.Javac160FromClasspath",
54+
"edu.rice.cs.drjava.model.compiler.Javac160FromToolsJar"
55+
};
56+
57+
public static final String[] JAVA_15_COMPILERS = {
4858
// javac 1.5
4959
"edu.rice.cs.drjava.model.compiler.Javac150FromSetLocation",
5060
"edu.rice.cs.drjava.model.compiler.Javac150FromClasspath",
5161
"edu.rice.cs.drjava.model.compiler.Javac150FromToolsJar"
5262
};
5363

64+
/** A subset of DEFAULT_COMPILERS that support Raw (non-generic) Java. */
65+
public static final String[] JAVA_14_COMPILERS = {
66+
// javac 1.4
67+
"edu.rice.cs.drjava.model.compiler.Javac141FromSetLocation",
68+
"edu.rice.cs.drjava.model.compiler.Javac141FromClasspath",
69+
"edu.rice.cs.drjava.model.compiler.Javac141FromToolsJar"
70+
};
71+
5472
/** The list of compiler interfaces that are distributed with DrJava. */
5573
static final String[][] DEFAULT_COMPILERS = {
56-
// javac 1.5 and JSR14/GJ
57-
GENERIC_JAVA_COMPILERS,
74+
// javac 1.6
75+
JAVA_16_COMPILERS,
76+
// javac 1.5
77+
JAVA_15_COMPILERS,
5878
// javac 1.4
59-
new String[] {
60-
"edu.rice.cs.drjava.model.compiler.Javac141FromSetLocation",
61-
"edu.rice.cs.drjava.model.compiler.Javac141FromClasspath",
62-
"edu.rice.cs.drjava.model.compiler.Javac141FromToolsJar"
63-
}
79+
JAVA_14_COMPILERS
6480
};
65-
81+
6682
/** Singleton instance. */
6783
public static final CompilerRegistry ONLY = new CompilerRegistry();
6884

@@ -88,22 +104,30 @@ public class CompilerRegistry {
88104
*/
89105
public CompilerInterface[] getAvailableCompilers() {
90106
LinkedList<CompilerInterface> availableCompilers = new LinkedList<CompilerInterface>();
91-
92-
for (String[] row: DEFAULT_COMPILERS) {
107+
108+
String[] candidateCompilers = null;
109+
110+
String version = CompilerProxy.VERSION; // version of executing JVM: 1.4, 1.5, 1.6
111+
112+
if (version.equals("1.4")) candidateCompilers = JAVA_14_COMPILERS;
113+
else if (version.equals("1.5")) candidateCompilers = JAVA_15_COMPILERS;
114+
else if (version.equals("1.6")) candidateCompilers = JAVA_16_COMPILERS;
115+
else throw new
116+
UnexpectedException("Java specification version " + version + "is not supported. Must be 1.4, 1.5, or 1.6");
117+
118+
for (String name : candidateCompilers) {
93119
// DrJava.consoleOut().print("REGISTRY: Checking compiler: " + name + ": ");
94-
for (String name: row) {
95-
try { if (_createCompiler(name, availableCompilers)) break; }
96-
catch (Throwable t) {
120+
try { if (_createCompiler(name, availableCompilers)) break; }
121+
catch (Throwable t) {
97122
// This compiler didn't load. Keep on going.
98123
// DrJava.consoleOut().println("failed to load:");
99124
//t.printStackTrace(DrJava.consoleOut());
100125
//System.err.println();
101-
}
102126
}
103127
}
104128

105129
if (availableCompilers.size() == 0) availableCompilers.add(NoCompilerAvailable.ONLY);
106-
130+
107131
return availableCompilers.toArray(new CompilerInterface[availableCompilers.size()]);
108132
}
109133

@@ -118,7 +142,7 @@ private boolean _createCompiler(String name, LinkedList<CompilerInterface> avail
118142
//System.err.println("\tset to active.");
119143
_activeCompiler = compiler;
120144
}
121-
145+
// Utilities.show("Adding compiler " + compiler);
122146
availableCompilers.add(compiler);
123147
return true;
124148
}
@@ -169,15 +193,14 @@ public CompilerInterface getActiveCompiler() {
169193
*/
170194
private CompilerInterface _instantiateCompiler(String name) throws Throwable {
171195
Class<?> clazz = _baseClassLoader.loadClass(name);
196+
// Utilities.show("Loaded compiler named " + name + " with class name " + clazz);
172197
return createCompiler(clazz);
173198
}
174199

175200
public static CompilerInterface createCompiler(Class clazz) throws Throwable {
176201
try {
177202
Field field = clazz.getField("ONLY");
178-
// null is passed to get since it's a static field
179-
Object val = field.get(null);
180-
203+
Object val = field.get(null); // null is passed to get since it's a static field
181204
return (CompilerInterface) val;
182205
}
183206
catch (Throwable t) {

drjava/src/edu/rice/cs/drjava/model/compiler/Javac141FromClassPath.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,16 @@
3333

3434
package edu.rice.cs.drjava.model.compiler;
3535

36-
/**
37-
* A compiler interface to find Javac (1.4.1+) from the classpath,
38-
* but to do so via a compiler proxy so that the compiler classes can be
39-
* fully unloaded/reloaded every time it is used.
36+
/** A compiler interface to find Javac (1.4.1+) from the classpath, but to do so via a compiler proxy so that the
37+
* compiler classes can be fully unloaded/reloaded every time it is used.
4038
*
41-
* @version $Id$
39+
* @version $Id$
4240
*/
4341
public class Javac141FromClassPath extends CompilerProxy {
4442
public static final CompilerInterface ONLY = new Javac141FromClassPath();
4543

4644
/** Private constructor due to singleton. */
4745
private Javac141FromClassPath() {
48-
super("edu.rice.cs.drjava.model.compiler.Javac141Compiler",
49-
Javac141FromClassPath.class.getClassLoader());
46+
super("edu.rice.cs.drjava.model.compiler.Javac141Compiler", Javac141FromClassPath.class.getClassLoader());
5047
}
5148
}

drjava/src/edu/rice/cs/drjava/model/compiler/Javac141FromSetLocation.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,18 @@ public class Javac141FromSetLocation extends CompilerProxy
5656

5757
/** Private constructor due to singleton. */
5858
public Javac141FromSetLocation() {
59-
super("edu.rice.cs.drjava.model.compiler.Javac141Compiler",
60-
_getClassLoader());
59+
super("edu.rice.cs.drjava.model.compiler.Javac141Compiler", _getClassLoader());
6160
}
6261

6362
private static ClassLoader _getClassLoader() {
6463
File loc = DrJava.getConfig().getSetting(JAVAC_LOCATION);
65-
if (loc == FileOption.NULL_FILE) {
66-
throw new RuntimeException("javac location not set");
67-
}
64+
if (loc == FileOption.NULL_FILE) { throw new RuntimeException("javac location not set"); }
6865

6966
try {
7067
//URL url = new File(loc).toURL();
7168
URL url = loc.toURL();
7269
return new URLClassLoader(new URL[] { url });
7370
}
74-
catch (MalformedURLException e) {
75-
throw new RuntimeException("malformed url exception");
76-
}
71+
catch (MalformedURLException e) { throw new RuntimeException("malformed url exception"); }
7772
}
7873
}

0 commit comments

Comments
 (0)