|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.enough.polish.preprocess.Preprocessor
public class Preprocessor
Preprocesses source code.
Copyright Enough Software 2004 - 2012
| Field Summary | |
|---|---|
static int |
CHANGED
A value indicating that the file has been changed. |
static Pattern |
DIRECTIVE_PATTERN
|
static String |
ENVIRONMENT_KEY
|
static int |
NOT_CHANGED
A value indicating that the file has not been changed. |
static int |
SKIP_FILE
A value indicating that the file should be skipped altogether. |
static int |
SKIP_REST
A value indicating that the rest of the current file should not be preprocessed. |
protected static Pattern |
SYSTEM_PRINT_PATTERN
|
| Constructor Summary | |
|---|---|
Preprocessor(PolishProject project,
Environment environment,
File destinationDir,
boolean backup,
boolean indent,
boolean replacePropertiesWithoutDirective,
String newExt)
Creates a new Preprocessor - usually for a specific device or a device group. |
|
| Method Summary | |
|---|---|
void |
addCustomPreprocessor(CustomPreprocessor preprocessor)
Adds a custom preprocesor to this preprocessor. |
void |
addSymbol(String name)
Deprecated. use environment.addSymbol() instead |
void |
addToPreprocessQueue(String fileName)
Adds the file to the preprocessing queue |
void |
addVariable(String name,
String value)
Deprecated. use environment.addVariable() instead |
void |
addVariables(Map<String,String> additionalVars)
Deprecated. use environment.addVariables() instead |
protected boolean |
checkIfCondition(String argument,
String className,
StringList lines)
Checks whether an if-condition is true. |
void |
clearCustomPreprocessors()
|
static boolean |
containsDirective(String line)
Checks if the given line contains a directive. |
BooleanEvaluator |
getBooleanEvaluator()
Deprecated. use environment.getBooleanEvaluator() instead |
CssAttributesManager |
getCssAttributesManager()
|
Environment |
getEnvironment()
|
protected String |
getErrorStart(String className,
StringList lines)
Creates the start of an error message: |
StyleSheet |
getStyleSheet()
Retrieves the style sheet. |
TextFileManager |
getTextFileManager()
|
String |
getVariable(String name)
Deprecated. use environment.getVariable() instead |
Map<String,String> |
getVariables()
Deprecated. use environment.getVariable() instead |
boolean |
hasSymbol(String symbol)
Deprecated. use environment.hasSymbol() instead |
boolean |
isInPreprocessQueue(String fileName)
Determines whether the given file is in the preprocess queue. |
void |
notifyDevice(Device device,
boolean usesPolishGui)
Notifies this preprocessor about a new device for which code is preprocessed. |
void |
notifyDeviceEnd(Device device,
boolean usesPolishGui)
Notifies this preprocessor about the end of preprocessing for the given device. |
void |
notifyLocale(Locale locale)
Notifies this preprocessor about a new locale for which code is preprocessed. |
void |
notifyPolishPackageStart()
Notifies the processor that from now on source code from the J2ME Polish package is processed. |
boolean |
preprocess(File sourceDir,
String fileName)
Preprocesses the given file and saves it to the destination directory. |
int |
preprocess(String className,
StringList lines)
Preprocesses the given source code. |
String[] |
preprocess(String resourceName,
StringList list,
boolean removePreprocessingComments)
Preprocesses the given string array. |
protected int |
processSingleLine(String className,
StringList lines,
String line,
String trimmedLine)
Checks a single line for a preprocessing directive. |
void |
removeFromPreprocessQueue(String fileName)
Removes the file from the preprocessing queue |
void |
removeSymbol(String name)
Deprecated. use environment.removeSymbol() instead |
void |
removeVariable(String name)
Deprecated. use environment.removeVariable() instead |
boolean |
replacePropertiesWithoutDirective()
Determines whether properties should be replaced without using the //#= directive. |
void |
reset()
Resets this preprocessor. |
void |
setCssAttributesManager(CssAttributesManager manager)
|
void |
setCustomPreprocessors(CustomPreprocessor[] customPreprocessors)
Sets the custom preprocessors which allow a finer grained control of the preprocessing phase. |
void |
setReplacePropertiesWithoutDirective(boolean replacePropertiesWithoutDirective)
Specifies whether properties should be replaced without using the //#= directive. |
void |
setSyleSheet(StyleSheet styleSheet,
Device device)
Sets the style sheet. |
void |
setSymbols(HashMap<String,Boolean> symbols)
Deprecated. use Environment for such settings now |
void |
setTargetDir(String path)
Sets the direcotry to which the preprocessed files should be copied to. |
void |
setTextFileManager(TextFileManager textFileManager)
|
void |
setUsePolishGui(boolean usePolishGui)
Deprecated. use environment add/removeSymbol now |
void |
setVariables(HashMap<String,String> variables)
Deprecated. use Environment for such settings now |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int CHANGED
public static final int NOT_CHANGED
public static final int SKIP_FILE
public static final int SKIP_REST
public static final Pattern DIRECTIVE_PATTERN
protected static final Pattern SYSTEM_PRINT_PATTERN
public static final String ENVIRONMENT_KEY
| Constructor Detail |
|---|
public Preprocessor(PolishProject project,
Environment environment,
File destinationDir,
boolean backup,
boolean indent,
boolean replacePropertiesWithoutDirective,
String newExt)
project - the project settingsenvironment - environment settingsdestinationDir - the destination directory for the preprocessed filesbackup - true when the found source files should be backupedindent - true when comments should be intendedreplacePropertiesWithoutDirective - true when ${name} properties should be replaced without using the //#= directivenewExt - the new extension for preprocessed files| Method Detail |
|---|
public void setCustomPreprocessors(CustomPreprocessor[] customPreprocessors)
customPreprocessors - an array of custom preprocessorspublic void addCustomPreprocessor(CustomPreprocessor preprocessor)
preprocessor - the additional preprocessorpublic void clearCustomPreprocessors()
public void notifyPolishPackageStart()
public void notifyDevice(Device device,
boolean usesPolishGui)
device - the new deviceusesPolishGui - true when the J2ME Polish GUI is used for the new devicepublic void notifyLocale(Locale locale)
locale - the new locale, can be null
public void notifyDeviceEnd(Device device,
boolean usesPolishGui)
device - the new deviceusesPolishGui - true when the J2ME Polish GUI is used for the new devicepublic void setTargetDir(String path)
path - The target path.public void setSymbols(HashMap<String,Boolean> symbols)
symbols - All new symbols, defined in a HashMap.
BuildException - when an invalid symbol is defined (currently only "false" is checked);public void setUsePolishGui(boolean usePolishGui)
usePolishGui - true when the GUI is supported, false otherwisepublic void addSymbol(String name)
name - The name of the symbol.public void removeSymbol(String name)
name - The name of the symbol.public void setVariables(HashMap<String,String> variables)
variables - the variables.
public void addVariable(String name,
String value)
name - The name of the variable.value - The value of the variable.public void removeVariable(String name)
name - the variable namepublic void addVariables(Map<String,String> additionalVars)
additionalVars - A map of additional variables.public BooleanEvaluator getBooleanEvaluator()
Environment.getBooleanEvaluator()
public boolean preprocess(File sourceDir,
String fileName)
throws FileNotFoundException,
IOException,
BuildException
sourceDir - the directory containing the source filefileName - the name (and path)of the source file
FileNotFoundException - when the file was not found
IOException - when the file could not be read or written
BuildException - when the preprocessing failspublic void reset()
public String[] preprocess(String resourceName,
StringList list,
boolean removePreprocessingComments)
resourceName - the name of the resource file.list - a list of strings the text.
BuildException - when the preprocessing fails.
public int preprocess(String className,
StringList lines)
throws BuildException
className - the name of the source file.lines - the source code. Changes are made directly in the code.
BuildException - when the preprocessing fails.
protected int processSingleLine(String className,
StringList lines,
String line,
String trimmedLine)
throws BuildException
className - the name of the source filelines - the source code linesline - the specific linetrimmedLine - the same line but without spaces at the beginning or end
BuildException - when there was a syntax error in the directives
protected boolean checkIfCondition(String argument,
String className,
StringList lines)
throws BuildException
argument - the if-expression e.g. "(symbol1 || symbol2) && symbol3"className - the name of the filelines - the list of source code
BuildException - when there is an syntax error in the expressionpublic static final boolean containsDirective(String line)
line - the line which should be tested
public void setSyleSheet(StyleSheet styleSheet,
Device device)
device - the current devicestyleSheet - the new style sheetpublic StyleSheet getStyleSheet()
public boolean hasSymbol(String symbol)
symbol - the symbol
public String getVariable(String name)
name - the name of the variable
public boolean isInPreprocessQueue(String fileName)
fileName - the name of the file, e.g. "de/enough/polish/ui/Screen.java"
public void addToPreprocessQueue(String fileName)
fileName - the name of the file, e.g. de/enough/polish/ui/Screen.javapublic void removeFromPreprocessQueue(String fileName)
fileName - the name of the filepublic Map<String,String> getVariables()
protected String getErrorStart(String className,
StringList lines)
className - the name of the current classlines - the source code of that class
public void setTextFileManager(TextFileManager textFileManager)
public TextFileManager getTextFileManager()
public void setCssAttributesManager(CssAttributesManager manager)
manager - public CssAttributesManager getCssAttributesManager()
public Environment getEnvironment()
public boolean replacePropertiesWithoutDirective()
public void setReplacePropertiesWithoutDirective(boolean replacePropertiesWithoutDirective)
replacePropertiesWithoutDirective - true when properties should be replaced without using the //#= directive.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||