Skip to content

Commit 0a85493

Browse files
author
mgricken
committed
Null object pattern for JDKDescriptors.
git-svn-id: file:///tmp/test-svn/branches/drjava-compilers@5371 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent d6f67da commit 0a85493

26 files changed

Lines changed: 455 additions & 333 deletions

File tree

drjava/lib/dynamicjava-base.jar

0 Bytes
Binary file not shown.

drjava/lib/javalanglevels-base.jar

-1 Bytes
Binary file not shown.

drjava/lib/platform.jar

91 Bytes
Binary file not shown.

drjava/lib/plt.jar

64 Bytes
Binary file not shown.

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import javax.swing.UIManager.LookAndFeelInfo;
5252

5353
import edu.rice.cs.drjava.platform.PlatformFactory;
54-
54+
import edu.rice.cs.plt.reflect.JavaVersion;
5555
import edu.rice.cs.util.FileOps;
5656

5757
import static java.awt.Event.*;
@@ -312,8 +312,16 @@ public static String getDefaultLookAndFeel() {
312312
return UIManager.getSystemLookAndFeelClassName(); // Mac: Let the system decide.
313313
else if (PlatformFactory.ONLY.isWindowsPlatform())
314314
return UIManager.getCrossPlatformLookAndFeelClassName(); // Windows: Metal, because the Windows LAF is ugly
315-
else
316-
return UIManager.getSystemLookAndFeelClassName(); // Linux: Let the system decide. Probably GTK, which is ok.
315+
else {
316+
if (JavaVersion.CURRENT.supports(JavaVersion.JAVA_6)) {
317+
// Linux with Java 6: Let the system decide. Probably GTK, which is ok.
318+
return UIManager.getSystemLookAndFeelClassName();
319+
}
320+
else {
321+
// Linux with Java older than Java 6: Metal
322+
return UIManager.getCrossPlatformLookAndFeelClassName();
323+
}
324+
}
317325
}
318326

319327
/** Need to ensure that a look-and-feel can be instantiated and is valid.

drjava/src/edu/rice/cs/drjava/model/compiler/descriptors/JDKDescriptor.java renamed to drjava/src/edu/rice/cs/drjava/model/JDKDescriptor.java

Lines changed: 82 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,27 @@
3434
*
3535
* END_COPYRIGHT_BLOCK*/
3636

37-
package edu.rice.cs.drjava.model.compiler.descriptors;
37+
package edu.rice.cs.drjava.model;
3838

3939
import java.io.File;
4040
import java.io.IOException;
4141
import java.io.FileNotFoundException;
4242
import java.util.Set;
4343
import java.util.jar.JarFile;
44+
import java.util.Collections;
45+
46+
import edu.rice.cs.drjava.model.JDKToolsLibrary;
4447
import edu.rice.cs.plt.reflect.JavaVersion;
48+
import edu.rice.cs.plt.reflect.JavaVersion.FullVersion;
4549
import edu.rice.cs.plt.iter.IterUtil;
4650

47-
/** A description of a JDK. */
48-
public interface JDKDescriptor {
51+
/** A description of a JDK.
52+
* Put subclasses of JDKDescriptor in the edu.rice.cs.drjava.model.compiler.descriptors package for DrJava
53+
* to find. */
54+
public abstract class JDKDescriptor {
4955
/** Return the name of this JDK.
5056
* @return name */
51-
public String getName();
57+
public abstract String getName();
5258

5359
/** Packages to shadow when loading a new tools.jar. If we don't shadow these classes, we won't
5460
* be able to load distinct versions for each tools.jar library. These should be verified whenever
@@ -57,35 +63,53 @@ public interface JDKDescriptor {
5763
*
5864
* @return set of packages that need to be shadowed
5965
*/
60-
public Set<String> getToolsPackages();
66+
public abstract Set<String> getToolsPackages();
6167

6268
/** Returns a list of directories that should be searched for tools.jar and classes.jar files.
6369
* @return list of directories to search */
64-
public Iterable<File> getSearchDirectories();
70+
public abstract Iterable<File> getSearchDirectories();
6571

6672
/** Returns a list of files that should be searched if they contain a compiler.
6773
* @return list of files to search */
68-
public Iterable<File> getSearchFiles();
74+
public abstract Iterable<File> getSearchFiles();
6975

7076
/** True if this is a compound JDK and needs a fully featured JDK to operate.
7177
* @return true if compound JDK (e.g. NextGen, Mint, Habanero). */
72-
public boolean isCompound();
78+
public abstract boolean isCompound();
79+
80+
/** True if this is a JDK that can serve as base for a compound JDK.
81+
* @return true if base for a compound JDK (e.g. Sun JDK, OpenJDK, AppleJDK). */
82+
public boolean isBaseForCompound() { return false; }
7383

7484
/** Return the class name of the compiler adapter.
7585
* @return class name of compiler, or null if no compiler */
76-
public String getAdapterForCompiler();
86+
public abstract String getAdapterForCompiler();
87+
88+
/** Return the class name of the compiler adapter.
89+
* @param guessedVersion the guessed version of the compiler
90+
* @return class name of compiler, or null if no compiler */
91+
public String getAdapterForCompiler(JavaVersion.FullVersion guessedVersion) {
92+
return getAdapterForCompiler(); // ignore the version
93+
}
7794

7895
/** Return the class name of the debugger adapter.
7996
* @return class name of debugger, or null if no debugger */
80-
public String getAdapterForDebugger();
97+
public abstract String getAdapterForDebugger();
98+
99+
/** Return the class name of the debugger adapter.
100+
* @param guessedVersion the guessed version of the compiler
101+
* @return class name of debugger, or null if no debugger */
102+
public String getAdapterForDebugger(JavaVersion.FullVersion guessedVersion) {
103+
return getAdapterForDebugger(); // ignore version
104+
}
81105

82106
/** Return true if the file (jar file or directory) contains the compiler.
83107
* @return true if the file contains the compiler */
84-
public boolean containsCompiler(File f);
108+
public abstract boolean containsCompiler(File f);
85109

86110
/** Return the minimum Java version required to use this JDK.
87111
* @return minimum version */
88-
public JavaVersion getMinimumMajorVersion();
112+
public abstract JavaVersion getMinimumMajorVersion();
89113

90114
/** Return the list of additional files required to use the compiler.
91115
* The compiler was found in the specified file. This method may have to search the user's hard drive, e.g.
@@ -105,7 +129,52 @@ public interface JDKDescriptor {
105129
*
106130
* @param compiler location where the compiler was fund
107131
* @return list of additional files that need to be available */
108-
public Iterable<File> getAdditionalCompilerFiles(File compiler) throws FileNotFoundException;
132+
public abstract Iterable<File> getAdditionalCompilerFiles(File compiler) throws FileNotFoundException;
133+
134+
/** Return a description of this JDK.
135+
* @param version the specific version of the compiler
136+
* @return description */
137+
public String getDescription(JavaVersion.FullVersion version) {
138+
return getName() + " library " + version.versionString();
139+
}
140+
141+
/** Singleton representing a JDK that doesn't have a descriptor. */
142+
public static final JDKDescriptor NONE = new None();
143+
144+
/** Class for the singleton representing a JDK that doesn't have a descriptor. */
145+
private static final class None extends JDKDescriptor {
146+
public String getName() { return "none"; }
147+
public String getDescription(JavaVersion.FullVersion version) {
148+
switch(version.vendor()) {
149+
case SUN:
150+
return "Sun JDK library " + version.toString();
151+
case OPENJDK:
152+
return "OpenJDK library " + version.toString();
153+
case APPLE:
154+
return "Apple JDK library " + version.toString();
155+
default:
156+
return "JDK library " + version.toString();
157+
}
158+
}
159+
public Set<String> getToolsPackages() { return Collections.emptySet(); }
160+
public Iterable<File> getSearchDirectories() { return IterUtil.empty(); }
161+
public Iterable<File> getSearchFiles() { return IterUtil.empty(); }
162+
public boolean isCompound() { return false; }
163+
public boolean isBaseForCompound() { return true; }
164+
public String getAdapterForCompiler() { return ""; }
165+
public String getAdapterForCompiler(JavaVersion.FullVersion guessedVersion) {
166+
return JDKToolsLibrary.adapterForCompiler(guessedVersion);
167+
}
168+
public String getAdapterForDebugger() { return ""; }
169+
public String adapterForDebugger(JavaVersion.FullVersion guessedVersion) {
170+
return JDKToolsLibrary.adapterForCompiler(guessedVersion);
171+
}
172+
public boolean containsCompiler(File f) { return true; }
173+
public JavaVersion getMinimumMajorVersion() { return JavaVersion.JAVA_1_1; }
174+
public Iterable<File> getAdditionalCompilerFiles(File compiler) throws FileNotFoundException {
175+
return IterUtil.empty();
176+
}
177+
}
109178

110179
/** Utilities for JDK descriptors. */
111180
public static class Util {

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import edu.rice.cs.drjava.model.javadoc.JavadocModel;
5656
import edu.rice.cs.drjava.model.javadoc.NoJavadocAvailable;
5757
import edu.rice.cs.drjava.model.javadoc.DefaultJavadocModel;
58-
import edu.rice.cs.drjava.model.compiler.descriptors.JDKDescriptor;
58+
import edu.rice.cs.drjava.model.JDKDescriptor;
5959

6060
/**
6161
* Provides dynamic access to the interface of a JDK's tools.jar classes. This level of indirection
@@ -69,11 +69,12 @@ public class JDKToolsLibrary {
6969
private final CompilerInterface _compiler;
7070
private final Debugger _debugger;
7171
private final JavadocModel _javadoc;
72-
private final JDKDescriptor _jdkDescriptor; // may be null
72+
private final JDKDescriptor _jdkDescriptor; // JDKDescriptor.NONE if none
7373

7474
protected JDKToolsLibrary(FullVersion version, JDKDescriptor jdkDescriptor,
7575
CompilerInterface compiler, Debugger debugger,
7676
JavadocModel javadoc) {
77+
assert jdkDescriptor != null;
7778
_version = version;
7879
_compiler = compiler;
7980
_debugger = debugger;
@@ -95,25 +96,9 @@ public boolean isValid() {
9596
return _compiler.isAvailable() || _debugger.isAvailable() || _javadoc.isAvailable();
9697
}
9798

98-
public String toString() {
99-
if (_jdkDescriptor==null) {
100-
switch(_version.vendor()) {
101-
case SUN:
102-
return "Sun JDK library " + _version.versionString();
103-
case OPENJDK:
104-
return "OpenJDK library " + _version.versionString();
105-
case APPLE:
106-
return "Apple JDK library " + _version.versionString();
107-
default:
108-
return "JDK library " + _version.versionString();
109-
}
110-
}
111-
else {
112-
return _jdkDescriptor.getName() + " library " + _version.versionString();
113-
}
114-
}
99+
public String toString() { return _jdkDescriptor.getDescription(_version); }
115100

116-
protected static String adapterForCompiler(JavaVersion.FullVersion version) {
101+
public static String adapterForCompiler(JavaVersion.FullVersion version) {
117102
switch (version.majorVersion()) {
118103
case JAVA_6: {
119104
switch (version.vendor()) {
@@ -127,7 +112,7 @@ protected static String adapterForCompiler(JavaVersion.FullVersion version) {
127112
}
128113
}
129114

130-
protected static String adapterForDebugger(JavaVersion.FullVersion version) {
115+
public static String adapterForDebugger(JavaVersion.FullVersion version) {
131116
switch (version.majorVersion()) {
132117
case JAVA_6: return "edu.rice.cs.drjava.model.debug.jpda.JPDADebugger";
133118
case JAVA_5: return "edu.rice.cs.drjava.model.debug.jpda.JPDADebugger";
@@ -211,7 +196,7 @@ public static Iterable<JDKToolsLibrary> makeFromRuntime(GlobalModel model) {
211196
if (list.size()==0) {
212197
// no compiler found, i.e. compiler == NoCompilerAvailable.ONLY
213198
msg(" no compilers found, adding NoCompilerAvailable library");
214-
list.add(new JDKToolsLibrary(version, null, NoCompilerAvailable.ONLY, debugger, javadoc));
199+
list.add(new JDKToolsLibrary(version, JDKDescriptor.NONE, NoCompilerAvailable.ONLY, debugger, javadoc));
215200
}
216201

217202
return list;

0 commit comments

Comments
 (0)