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

java.lang.Object
  extended by edu.rice.cs.drjava.model.compiler.DefaultCompilerModel
All Implemented Interfaces:
CompilerModel

public class DefaultCompilerModel
extends Object
implements CompilerModel

Default implementation of the CompilerModel interface. This implementation is used for normal DrJava execution (as opposed to testing DrJava). TO DO: convert edu.rice.cs.util.Pair to edu.rice.cs.plt.tuple.Pair; requires making the same conversion in javalanglevels.

Version:
$Id: DefaultCompilerModel.java 4691 2008-12-02 23:33:27Z dlsmith $

Field Summary
 
Fields inherited from interface edu.rice.cs.drjava.model.compiler.CompilerModel
EXTENSIONS
 
Constructor Summary
DefaultCompilerModel(GlobalModel m, Iterable<? extends CompilerInterface> compilers)
          Main constructor.
 
Method Summary
 void addCompiler(CompilerInterface compiler)
          Add a compiler to the active list
 void addListener(CompilerListener listener)
          Adds a CompilerListener to the model.
 void compile(List<OpenDefinitionsDocument> defDocs)
          Compiles all of the given files.
 void compile(OpenDefinitionsDocument doc)
          Compiles the given file.
 void compileAll()
          Compile all open documents.
 void compileProject()
          Compiles all documents in the project source tree.
 CompilerInterface getActiveCompiler()
          Gets the compiler that is the "active" compiler.
 Iterable<CompilerInterface> getAvailableCompilers()
          Returns all registered compilers that are actually available.
 CompilerErrorModel getCompilerErrorModel()
          Gets the CompilerErrorModel representing the last compile.
 Object getCompilerLock()
          Returns the lock used to prevent simultaneous compilation and JUnit testing
 int getNumCompErrors()
          Gets the total number of current compiler errors.
 int getNumErrors()
          Gets the total number of errors in this compiler model.
 int getNumWarnings()
          Gets the total number of current warnings.
 void removeAllListeners()
          Removes all CompilerListeners from this model.
 void removeListener(CompilerListener listener)
          Removes a CompilerListener from the model.
 void resetCompilerErrors()
          Resets the compiler error state to have no errors.
 void setActiveCompiler(CompilerInterface compiler)
          Sets which compiler is the "active" compiler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultCompilerModel

public DefaultCompilerModel(GlobalModel m,
                            Iterable<? extends CompilerInterface> compilers)
Main constructor.

Parameters:
m - the GlobalModel that is the source of documents for this CompilerModel
compilers - The compilers to use. The first will be made active; all are assumed to be available. An empty list is acceptable.
Method Detail

getCompilerLock

public Object getCompilerLock()
Returns the lock used to prevent simultaneous compilation and JUnit testing

Specified by:
getCompilerLock in interface CompilerModel

addListener

public void addListener(CompilerListener listener)
Adds a CompilerListener to the model. This operation is synchronized by the readers/writers protocol in EventNotifier.

Specified by:
addListener in interface CompilerModel
Parameters:
listener - A listener that reacts to compiler events.

removeListener

public void removeListener(CompilerListener listener)
Removes a CompilerListener from the model. If the listener is not installed, this method has no effect.

Specified by:
removeListener in interface CompilerModel
Parameters:
listener - a listener that reacts to compiler events This operation is synchronized by the readers/writers protocol in EventNotifier.

removeAllListeners

public void removeAllListeners()
Removes all CompilerListeners from this model.

Specified by:
removeAllListeners in interface CompilerModel

compileAll

public void compileAll()
                throws IOException
Compile all open documents.

Before compiling, all unsaved and untitled documents are saved, and compilation ends if the user cancels this step. The compilation classpath and sourcepath includes the build directory (if it exists), the source roots, the project "extra classpath" (if it exists), the global "extra classpath", and the current JVM's classpath (which includes drjava.jar, containing JUnit classes).

This method formerly only compiled documents which were out of sync with their class file, as a performance optimization. However, bug #634386 pointed out that unmodified files could depend on modified files, in which case this command would not recompile a file in some situations when it should. Since we value correctness over performance, we now always compile all open documents.

Specified by:
compileAll in interface CompilerModel
Throws:
IOException - if a filesystem-related problem prevents compilation

compileProject

public void compileProject()
                    throws IOException
Compiles all documents in the project source tree. Assumes DrJava currently contains an active project.

Before compiling, all unsaved and untitled documents are saved, and compilation ends if the user cancels this step. The compilation classpath and sourcepath includes the build directory (if it exists), the source roots, the project "extra classpath" (if it exists), the global "extra classpath", and the current JVM's classpath (which includes drjava.jar, containing JUnit classes).

This method formerly only compiled documents which were out of sync with their class file, as a performance optimization. However, bug #634386 pointed out that unmodified files could depend on modified files, in which case this command would not recompile a file in some situations when it should. Since we value correctness over performance, we now always compile all open documents.

Specified by:
compileProject in interface CompilerModel
Throws:
IOException - if a filesystem-related problem prevents compilation

compile

public void compile(List<OpenDefinitionsDocument> defDocs)
             throws IOException
Compiles all of the given files.

Before compiling, all unsaved and untitled documents are saved, and compilation ends if the user cancels this step. The compilation classpath and sourcepath includes the build directory (if it exists), the source roots, the project "extra classpath" (if it exists), the global "extra classpath", and the current JVM's classpath (which includes drjava.jar, containing JUnit classes).

This method formerly only compiled documents which were out of sync with their class file, as a performance optimization. However, bug #634386 pointed out that unmodified files could depend on modified files, in which case this command would not recompile a file in some situations when it should. Since we value correctness over performance, we now always compile all open documents.

@throws IOException if a filesystem-related problem prevents compilation

Specified by:
compile in interface CompilerModel
Parameters:
defDocs - the documents to be compiled
Throws:
IOException - if a filesystem-related problem prevents compilation

compile

public void compile(OpenDefinitionsDocument doc)
             throws IOException
Compiles the given file.

Before compiling, all unsaved and untitled documents are saved, and compilation ends if the user cancels this step. The compilation classpath and sourcepath includes the build directory (if it exists), the source roots, the project "extra classpath" (if it exists), the global "extra classpath", and the current JVM's classpath (which includes drjava.jar, containing JUnit classes).

This method formerly only compiled documents which were out of sync with their class file, as a performance optimization. However, bug #634386 pointed out that unmodified files could depend on modified files, in which case this command would not recompile a file in some situations when it should. Since we value correctness over performance, we now always compile all open documents.

Specified by:
compile in interface CompilerModel
Parameters:
doc - the document to be compiled
Throws:
IOException - if a filesystem-related problem prevents compilation

getCompilerErrorModel

public CompilerErrorModel getCompilerErrorModel()
Gets the CompilerErrorModel representing the last compile.

Specified by:
getCompilerErrorModel in interface CompilerModel

getNumErrors

public int getNumErrors()
Gets the total number of errors in this compiler model.

Specified by:
getNumErrors in interface CompilerModel

getNumCompErrors

public int getNumCompErrors()
Gets the total number of current compiler errors.


getNumWarnings

public int getNumWarnings()
Gets the total number of current warnings.


resetCompilerErrors

public void resetCompilerErrors()
Resets the compiler error state to have no errors.

Specified by:
resetCompilerErrors in interface CompilerModel

getAvailableCompilers

public Iterable<CompilerInterface> getAvailableCompilers()
Returns all registered compilers that are actually available. If there are none, the result is NoCompilerAvailable.ONLY.

Specified by:
getAvailableCompilers in interface CompilerModel

getActiveCompiler

public CompilerInterface getActiveCompiler()
Gets the compiler that is the "active" compiler.

Specified by:
getActiveCompiler in interface CompilerModel
See Also:
setActiveCompiler(edu.rice.cs.drjava.model.compiler.CompilerInterface)

setActiveCompiler

public void setActiveCompiler(CompilerInterface compiler)
Sets which compiler is the "active" compiler.

Specified by:
setActiveCompiler in interface CompilerModel
Parameters:
compiler - Compiler to set active.
Throws:
IllegalArgumentException - If the compiler is not in the list of available compilers
See Also:
getActiveCompiler()

addCompiler

public void addCompiler(CompilerInterface compiler)
Add a compiler to the active list

Specified by:
addCompiler in interface CompilerModel