SmapStratumpublic class SmapStratum extends Object Represents the line and file mappings associated with a JSR-045
"stratum". |
Fields Summary |
---|
private String | stratumName | private List | fileNameList | private List | filePathList | private List | lineData | private int | lastFileID |
Constructors Summary |
---|
public SmapStratum(String stratumName)Constructs a new SmapStratum object for the given stratum name
(e.g., JSP).
this.stratumName = stratumName;
fileNameList = new ArrayList();
filePathList = new ArrayList();
lineData = new ArrayList();
lastFileID = 0;
|
Methods Summary |
---|
public void | addFile(java.lang.String filename)Adds record of a new file, by filename.
addFile(filename, filename);
| public void | addFile(java.lang.String filename, java.lang.String filePath)Adds record of a new file, by filename and path. The path
may be relative to a source compilation path.
int pathIndex = filePathList.indexOf(filePath);
if (pathIndex == -1) {
fileNameList.add(filename);
filePathList.add(filePath);
}
| public void | addLineData(int inputStartLine, java.lang.String inputFileName, int inputLineCount, int outputStartLine, int outputLineIncrement)Adds complete information about a simple line mapping. Specify
all the fields in this method; the back-end machinery takes care
of printing only those that are necessary in the final SMAP.
(My view is that fields are optional primarily for spatial efficiency,
not for programmer convenience. Could always add utility methods
later.)
// check the input - what are you doing here??
int fileIndex = filePathList.indexOf(inputFileName);
if (fileIndex == -1) // still
throw new IllegalArgumentException(
"inputFileName: " + inputFileName);
//Jasper incorrectly SMAPs certain Nodes, giving them an
//outputStartLine of 0. This can cause a fatal error in
//optimizeLineSection, making it impossible for Jasper to
//compile the JSP. Until we can fix the underlying
//SMAPping problem, we simply ignore the flawed SMAP entries.
if (outputStartLine == 0)
return;
// build the LineInfo
LineInfo li = new LineInfo();
li.setInputStartLine(inputStartLine);
li.setInputLineCount(inputLineCount);
li.setOutputStartLine(outputStartLine);
li.setOutputLineIncrement(outputLineIncrement);
if (fileIndex != lastFileID)
li.setLineFileID(fileIndex);
lastFileID = fileIndex;
// save it
lineData.add(li);
| public java.lang.String | getStratumName()Returns the name of the stratum.
return stratumName;
| public java.lang.String | getString()Returns the given stratum as a String: a StratumSection,
followed by at least one FileSection and at least one LineSection.
// check state and initialize buffer
if (fileNameList.size() == 0 || lineData.size() == 0)
return null;
StringBuffer out = new StringBuffer();
// print StratumSection
out.append("*S " + stratumName + "\n");
// print FileSection
out.append("*F\n");
int bound = fileNameList.size();
for (int i = 0; i < bound; i++) {
if (filePathList.get(i) != null) {
out.append("+ " + i + " " + fileNameList.get(i) + "\n");
// Source paths must be relative, not absolute, so we
// remove the leading "/", if one exists.
String filePath = (String)filePathList.get(i);
if (filePath.startsWith("/")) {
filePath = filePath.substring(1);
}
out.append(filePath + "\n");
} else {
out.append(i + " " + fileNameList.get(i) + "\n");
}
}
// print LineSection
out.append("*L\n");
bound = lineData.size();
for (int i = 0; i < bound; i++) {
LineInfo li = (LineInfo)lineData.get(i);
out.append(li.getString());
}
return out.toString();
| public void | optimizeLineSection()Combines consecutive LineInfos wherever possible
/* Some debugging code
for (int i = 0; i < lineData.size(); i++) {
LineInfo li = (LineInfo)lineData.get(i);
System.out.print(li.toString());
}
*/
//Incorporate each LineInfo into the previous LineInfo's
//outputLineIncrement, if possible
int i = 0;
while (i < lineData.size() - 1) {
LineInfo li = (LineInfo)lineData.get(i);
LineInfo liNext = (LineInfo)lineData.get(i + 1);
if (!liNext.lineFileIDSet
&& liNext.inputStartLine == li.inputStartLine
&& liNext.inputLineCount == 1
&& li.inputLineCount == 1
&& liNext.outputStartLine
== li.outputStartLine
+ li.inputLineCount * li.outputLineIncrement) {
li.setOutputLineIncrement(
liNext.outputStartLine
- li.outputStartLine
+ liNext.outputLineIncrement);
lineData.remove(i + 1);
} else {
i++;
}
}
//Incorporate each LineInfo into the previous LineInfo's
//inputLineCount, if possible
i = 0;
while (i < lineData.size() - 1) {
LineInfo li = (LineInfo)lineData.get(i);
LineInfo liNext = (LineInfo)lineData.get(i + 1);
if (!liNext.lineFileIDSet
&& liNext.inputStartLine == li.inputStartLine + li.inputLineCount
&& liNext.outputLineIncrement == li.outputLineIncrement
&& liNext.outputStartLine
== li.outputStartLine
+ li.inputLineCount * li.outputLineIncrement) {
li.setInputLineCount(li.inputLineCount + liNext.inputLineCount);
lineData.remove(i + 1);
} else {
i++;
}
}
| public java.lang.String | toString()
return getString();
|
|