edu.rice.cs.drjava.model.compiler
Class JavacCompiler

java.lang.Object
  extended by edu.rice.cs.drjava.model.compiler.JavacCompiler
All Implemented Interfaces:
CompilerInterface
Direct Known Subclasses:
Javac160FilteringCompiler

public abstract class JavacCompiler
extends java.lang.Object
implements CompilerInterface

An abstract parent for all javac-based compiler interfaces. Manages the auxiliary naming methods. To support loading via reflection, all subclasses are assumed to have a public constructor with a matching signature.

Version:
$Id: JavacCompiler.java 5436 2011-08-02 06:58:19Z mgricken $

Field Summary
protected  java.util.List<? extends java.io.File> _defaultBootClassPath
           
protected  java.lang.String _location
           
protected  JavaVersion.FullVersion _version
           
protected static java.util.Set<java.lang.String> ACM_PROGRAM_CLASSES
          The set of class names that are run as ACM Java Task Force library programs.
static java.util.HashSet<java.lang.String> JAVA_KEYWORDS
          Set of Java/GJ keywords for special coloring.
 
Constructor Summary
protected JavacCompiler(JavaVersion.FullVersion version, java.lang.String location, java.util.List<? extends java.io.File> defaultBootClassPath)
           
 
Method Summary
protected static java.lang.String _deleteSemiColon(java.lang.String s)
          Deletes the last character of a string.
protected static java.lang.String _transformCommand(java.lang.String s, java.lang.String command)
          Assumes a trimmed String.
 java.util.List<java.io.File> additionalBootClassPathForInteractions()
          A compiler can instruct DrJava to include additional elements for the boot class path of the Interactions JVM.
abstract  java.util.List<? extends DJError> compile(java.util.List<? extends java.io.File> files, java.util.List<? extends java.io.File> classPath, java.util.List<? extends java.io.File> sourcePath, java.io.File destination, java.util.List<? extends java.io.File> bootClassPath, java.lang.String sourceVersion, boolean showWarnings)
          Compile the given files.
 java.lang.String getDescription()
          Returns a one-line description of the compiler (such as the name and file location)
 javax.swing.filechooser.FileFilter getFileFilter()
          Return a file filter that can be used to open files this compiler supports.
 java.util.Set<java.lang.String> getKeywordsForFile(java.io.File f)
          Return the set of keywords that should be highlighted in the specified file.
 java.lang.String getName()
          Returns the name of this compiler, appropriate to show to the user.
 java.lang.String getOpenAllFilesInFolderExtension()
          Return the extension of the files that should be opened with the "Open Folder..." command.
 java.util.Set<java.lang.String> getSourceFileExtensions()
          Return the set of source file extensions that this compiler supports.
 java.lang.String getSuggestedFileExtension()
          Return the suggested file extension that will be appended to a file without extension.
abstract  boolean isAvailable()
          Indicates whether this compiler is actually available.
 boolean isSourceFileForThisCompiler(java.io.File f)
          .java --> true .dj --> true .dj0 --> true .dj1 --> true .dj2 --> true otherwise false
static void runCommand(java.lang.String s, java.lang.Class<?> c)
          This method performs the "smart run".
 boolean supportsLanguageLevels()
          Return true if this compiler can be used in conjunction with the language level facility.
 java.lang.String toString()
          String to display in a combo box (generally getName())
static java.lang.String transformAppletCommand(java.lang.String s)
           
 java.lang.String transformCommands(java.lang.String interactionsString)
          Transform the command line to be interpreted into something the Interactions JVM can use.
static java.lang.String transformJavaCommand(java.lang.String s)
           
static java.lang.String transformRunCommand(java.lang.String s)
           
 JavaVersion version()
          The latest version of Java supported by the compiler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_version

protected final JavaVersion.FullVersion _version

_location

protected final java.lang.String _location

_defaultBootClassPath

protected java.util.List<? extends java.io.File> _defaultBootClassPath

ACM_PROGRAM_CLASSES

protected static final java.util.Set<java.lang.String> ACM_PROGRAM_CLASSES
The set of class names that are run as ACM Java Task Force library programs.


JAVA_KEYWORDS

public static final java.util.HashSet<java.lang.String> JAVA_KEYWORDS
Set of Java/GJ keywords for special coloring.

Constructor Detail

JavacCompiler

protected JavacCompiler(JavaVersion.FullVersion version,
                        java.lang.String location,
                        java.util.List<? extends java.io.File> defaultBootClassPath)
Method Detail

isAvailable

public abstract boolean isAvailable()
Description copied from interface: CompilerInterface
Indicates whether this compiler is actually available. As in: Is it installed and located? This method should load the compiler class, which should hopefully prove whether the class can load. If this method returns true, the CompilerInterface.compile(java.util.List, java.util.List, java.util.List, java.io.File, java.util.List, java.lang.String, boolean) method should not fail due to class not being found.

Specified by:
isAvailable in interface CompilerInterface

compile

public abstract java.util.List<? extends DJError> compile(java.util.List<? extends java.io.File> files,
                                                          java.util.List<? extends java.io.File> classPath,
                                                          java.util.List<? extends java.io.File> sourcePath,
                                                          java.io.File destination,
                                                          java.util.List<? extends java.io.File> bootClassPath,
                                                          java.lang.String sourceVersion,
                                                          boolean showWarnings)
Description copied from interface: CompilerInterface
Compile the given files.

Specified by:
compile in interface CompilerInterface
Parameters:
files - Source files to compile.
classPath - Support jars or directories that should be on the classpath. If null, the default is used.
sourcePath - Location of additional sources to be compiled on-demand. If null, the default is used.
destination - Location (directory) for compiled classes. If null, the default in-place location is used.
bootClassPath - The bootclasspath (contains Java API jars or directories); should be consistent with sourceVersion If null, the default is used.
sourceVersion - The language version of the sources. Should be consistent with bootClassPath. If null, the default is used.
showWarnings - Whether compiler warnings should be shown or ignored.
Returns:
Errors that occurred. If no errors, should be zero length (not null).

version

public JavaVersion version()
Description copied from interface: CompilerInterface
The latest version of Java supported by the compiler

Specified by:
version in interface CompilerInterface

getName

public java.lang.String getName()
Description copied from interface: CompilerInterface
Returns the name of this compiler, appropriate to show to the user.

Specified by:
getName in interface CompilerInterface

getDescription

public java.lang.String getDescription()
Description copied from interface: CompilerInterface
Returns a one-line description of the compiler (such as the name and file location)

Specified by:
getDescription in interface CompilerInterface

toString

public java.lang.String toString()
Description copied from interface: CompilerInterface
String to display in a combo box (generally getName())

Specified by:
toString in interface CompilerInterface
Overrides:
toString in class java.lang.Object

additionalBootClassPathForInteractions

public java.util.List<java.io.File> additionalBootClassPathForInteractions()
A compiler can instruct DrJava to include additional elements for the boot class path of the Interactions JVM. This isn't necessary for the Java compilers, though.

Specified by:
additionalBootClassPathForInteractions in interface CompilerInterface

transformCommands

public java.lang.String transformCommands(java.lang.String interactionsString)
Transform the command line to be interpreted into something the Interactions JVM can use. This replaces "java MyClass a b c" with Java code to call MyClass.main(new String[]{"a","b","c"}). "import MyClass" is not handled here. transformCommands should support at least "run", "java" and "applet".

Specified by:
transformCommands in interface CompilerInterface
Parameters:
interactionsString - unprocessed command line
Returns:
command line with commands transformed

transformJavaCommand

public static java.lang.String transformJavaCommand(java.lang.String s)

transformAppletCommand

public static java.lang.String transformAppletCommand(java.lang.String s)

runCommand

public static void runCommand(java.lang.String s,
                              java.lang.Class<?> c)
                       throws java.lang.Throwable
This method performs the "smart run". Unfortunately, we don't get the right static error messages.

Parameters:
s - full command line, i.e. "run MyClass 1 2 3"
c - class to be run, i.e. MyClass.class
Throws:
java.lang.Throwable

transformRunCommand

public static java.lang.String transformRunCommand(java.lang.String s)

_transformCommand

protected static java.lang.String _transformCommand(java.lang.String s,
                                                    java.lang.String command)
Assumes a trimmed String. Returns a string of the call that the interpreter can use. The arguments get formatted as comma-separated list of strings enclosed in quotes. Example: _transformCommand("java MyClass arg1 arg2 arg3", "{0}.main(new String[]'{'{1}'}');") returns "MyClass.main(new String[]{\"arg1\",\"arg2\",\"arg3\"});" NOTE: the command to run is constructed using MessageFormat. That means that certain characters, single quotes and curly braces, for example, are special. To write single quotes, you need to double them. To write curly braces, you need to enclose them in single quotes. Example: MessageFormat.format("Abc {0} ''foo'' '{'something'}'", "def") returns "Abc def 'foo' {something}".

Parameters:
s - the command line, either "java MyApp arg1 arg2 arg3" or "applet MyApplet arg1 arg2 arg3"
command - the command to execute, with {0} marking the place for the class name and {1} the place for the arguments

_deleteSemiColon

protected static java.lang.String _deleteSemiColon(java.lang.String s)
Deletes the last character of a string. Assumes semicolon at the end, but does not check. Helper for _transformCommand(String,String).

Parameters:
s - the String containing the semicolon
Returns:
a substring of s with one less character

isSourceFileForThisCompiler

public boolean isSourceFileForThisCompiler(java.io.File f)
.java --> true .dj --> true .dj0 --> true .dj1 --> true .dj2 --> true otherwise false

Specified by:
isSourceFileForThisCompiler in interface CompilerInterface
Parameters:
f - file to check if it is a source file
Returns:
true if the specified file is a source file for this compiler.

getSourceFileExtensions

public java.util.Set<java.lang.String> getSourceFileExtensions()
Return the set of source file extensions that this compiler supports.

Specified by:
getSourceFileExtensions in interface CompilerInterface
Returns:
the set of source file extensions that this compiler supports.

getSuggestedFileExtension

public java.lang.String getSuggestedFileExtension()
Return the suggested file extension that will be appended to a file without extension.

Specified by:
getSuggestedFileExtension in interface CompilerInterface
Returns:
the suggested file extension

getFileFilter

public javax.swing.filechooser.FileFilter getFileFilter()
Return a file filter that can be used to open files this compiler supports.

Specified by:
getFileFilter in interface CompilerInterface
Returns:
file filter for appropriate source files for this compiler

getOpenAllFilesInFolderExtension

public java.lang.String getOpenAllFilesInFolderExtension()
Return the extension of the files that should be opened with the "Open Folder..." command.

Specified by:
getOpenAllFilesInFolderExtension in interface CompilerInterface
Returns:
file extension for the "Open Folder..." command for this compiler.

supportsLanguageLevels

public boolean supportsLanguageLevels()
Return true if this compiler can be used in conjunction with the language level facility.

Specified by:
supportsLanguageLevels in interface CompilerInterface
Returns:
true if language levels can be used.

getKeywordsForFile

public java.util.Set<java.lang.String> getKeywordsForFile(java.io.File f)
Return the set of keywords that should be highlighted in the specified file.

Specified by:
getKeywordsForFile in interface CompilerInterface
Parameters:
f - file for which to return the keywords
Returns:
the set of keywords that should be highlighted in the specified file.