mjc

org.multijava.util.compiler
Class Compiler

java.lang.Object
  extended byorg.multijava.util.Utils
      extended byorg.multijava.util.compiler.Compiler
All Implemented Interfaces:
Cloneable, TroubleReporter
Direct Known Subclasses:
Main

public abstract class Compiler
extends Utils
implements TroubleReporter

This class defines the common behaviour of all KOPI compilers.


Field Summary
private  PrintWriter err
          The output stream for diagnostic messages
private  ModifierUtility modUtil
           
private  PrintWriter out
          The output stream for normal messages
static int PRINT_TO_ERR
          Indicates that the user wants to print to diagnostic output.
static int PRINT_TO_OUT
          Indicates that the user wants to print to normal output.
private  long timestamp
          Each compilation session is identified by a timestamp
 
Fields inherited from class org.multijava.util.Utils
DBG_LEVEL_HIGH, DBG_LEVEL_LOW, DBG_LEVEL_NO
 
Constructor Summary
protected Compiler(ModifierUtility modUtil)
          Creates a new compiler instance.
 
Method Summary
abstract  void catchUp(File filename)
          Compiles the named file (using the options of the current compilation session) up to the same compilation pass as the files named when the compilation session was initiated.
 long getTimestamp()
          Returns the timestamp of the compilation session, identifying it uniquely.
 void inform(String message)
          Write a message to the diagnostic output.
 void inform(String message, int printDestination)
          Write text to the output stream if printDestination is PRINT_TO_OUT and write text to the diagnostic stream if printDestination is PRINT_TO_ERR.
 void inform(Throwable trouble)
          Write a message to the diagnostic output.
 void inform(FormattedException trouble)
          Write a message to the diagnostic output.
 void inform(Message message)
          Write a message to the diagnostic output.
 void inform(MessageDescription description)
          Write a message to the diagnostic output.
 void inform(MessageDescription description, Object parameter)
          Write a message to the diagnostic output.
 void inform(MessageDescription description, Object parameter1, Object parameter2)
          Write a message to the diagnostic output.
 void inform(MessageDescription description, Object[] parameters)
          Write a message to the diagnostic output.
 ModifierUtility modUtil()
           
abstract  boolean parseComments()
          Returns true iff comments should be parsed (false if to be skipped).
private  void readList(ArrayList accum, String name)
          Parses the file referenced by name, extracting the list of files that it contains.
abstract  void reportTrouble(Exception trouble)
          Reports a trouble (error or warning).
 boolean run(PrintWriter err, String[] args)
          Runs a compilation session
abstract  boolean run(String[] args)
          Runs a compilation session
 void setOutputStream(OutputStream os)
          Sets the output stream for inform to err
abstract  boolean verboseMode()
          Returns true iff compilation runs in verbose mode.
 ArrayList verifyFiles(String[] names)
          Takes an array of file names and checks that each exists.
 ArrayList verifyFiles(ArrayList names)
          Takes a list of file names and checks that each exists.
 
Methods inherited from class org.multijava.util.Utils
assertTrue, assertTrue, combineArrays, escapeString, escapeString, fail, fail, getFilePath, hasFlag, hasOtherFlags, parsePathParts, relativePathTo, splitQualifiedName, splitQualifiedName, stripJavaModifiers, stripNonJavaModifiers, stripPrivateModifier, unescapeString, vectorToArray, vectorToIntArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRINT_TO_OUT

public static final int PRINT_TO_OUT
Indicates that the user wants to print to normal output.


PRINT_TO_ERR

public static final int PRINT_TO_ERR
Indicates that the user wants to print to diagnostic output.


timestamp

private final long timestamp
Each compilation session is identified by a timestamp


out

private PrintWriter out
The output stream for normal messages


err

private PrintWriter err
The output stream for diagnostic messages


modUtil

private final ModifierUtility modUtil
Constructor Detail

Compiler

protected Compiler(ModifierUtility modUtil)
Creates a new compiler instance.

Method Detail

getTimestamp

public final long getTimestamp()
Returns the timestamp of the compilation session, identifying it uniquely.


verifyFiles

public ArrayList verifyFiles(ArrayList names)
                      throws UnpositionedError
Takes a list of file names and checks that each exists.

Parameters:
names - a list of names
Returns:
a list (of java.io.File) of files known to exist
Throws:
UnpositionedError - at least one file does not exist

verifyFiles

public ArrayList verifyFiles(String[] names)
                      throws UnpositionedError
Takes an array of file names and checks that each exists.

Parameters:
names - an array of names
Returns:
a list (of java.io.File) of files known to exist
Throws:
UnpositionedError - at least one file does not exist

readList

private void readList(ArrayList accum,
                      String name)
               throws IOException
Parses the file referenced by name, extracting the list of files that it contains. The files are added to accum

Parameters:
accum - a list in which to accumulate the results
name - a string of the form "@file" where "file" is the name of a file containing a list of file names
Throws:
IOException

run

public boolean run(PrintWriter err,
                   String[] args)
Runs a compilation session

Parameters:
err - the diagnostic output stream
args - the arguments to the compiler
Returns:
true iff the compilation succeeded

setOutputStream

public void setOutputStream(OutputStream os)
Sets the output stream for inform to err

Parameters:
os - the output stream to use for error and warning output

 requires os != null;
 

run

public abstract boolean run(String[] args)
Runs a compilation session

Parameters:
args - the arguments to the compiler
Returns:
true iff the compilation succeeded

catchUp

public abstract void catchUp(File filename)
Compiles the named file (using the options of the current compilation session) up to the same compilation pass as the files named when the compilation session was initiated. Then adds the result to the set of compilation units to be processed to completion.

Parameters:
filename - the file descriptor of the file to be compiled

 requires filename != null && filename.canRead();
 

reportTrouble

public abstract void reportTrouble(Exception trouble)
Reports a trouble (error or warning).

Specified by:
reportTrouble in interface TroubleReporter
Parameters:
trouble - a description of the trouble to report.

parseComments

public abstract boolean parseComments()
Returns true iff comments should be parsed (false if to be skipped).


verboseMode

public abstract boolean verboseMode()
Returns true iff compilation runs in verbose mode.


inform

public final void inform(Throwable trouble)
Write a message to the diagnostic output.

Parameters:
trouble - the error caught

inform

public final void inform(FormattedException trouble)
Write a message to the diagnostic output.

Parameters:
trouble - the error caught

inform

public final void inform(Message message)
Write a message to the diagnostic output.

Parameters:
message - the formatted message

inform

public final void inform(MessageDescription description,
                         Object[] parameters)
Write a message to the diagnostic output.

Parameters:
description - the message description
parameters - the array of parameters

inform

public final void inform(MessageDescription description,
                         Object parameter1,
                         Object parameter2)
Write a message to the diagnostic output.

Parameters:
description - the message description
parameter1 - the first parameter
parameter2 - the second parameter

inform

public final void inform(MessageDescription description,
                         Object parameter)
Write a message to the diagnostic output.

Parameters:
description - the message description
parameter - the parameter

inform

public final void inform(MessageDescription description)
Write a message to the diagnostic output.

Parameters:
description - the message description

inform

public void inform(String message)
Write a message to the diagnostic output.

Parameters:
message - the message text

inform

public void inform(String message,
                   int printDestination)
Write text to the output stream if printDestination is PRINT_TO_OUT and write text to the diagnostic stream if printDestination is PRINT_TO_ERR. Subclasses should override setOutputStream() to change the output destination.

Parameters:
message - the message text
printDestination - the output stream that this message goes to
See Also:
setOutputStream(OutputStream)

modUtil

public final ModifierUtility modUtil()

mjc

mjc is Copyright (C) 2000-2004 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. mjc is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.