Represents the line and file mappings associated with a JSR-045
"stratum".
| Method from org.apache.jasper.compiler.SmapStratum Detail: |
public void addFile(String filename) {
addFile(filename, filename);
}
Adds record of a new file, by filename. |
public void addFile(String filename,
String filePath) {
int pathIndex = filePathList.indexOf(filePath);
if (pathIndex == -1) {
fileNameList.add(filename);
filePathList.add(filePath);
}
}
Adds record of a new file, by filename and path. The path
may be relative to a source compilation path. |
public void addLineData(int inputStartLine,
String inputFileName,
int inputLineCount,
int outputStartLine,
int outputLineIncrement) {
// 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);
}
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.) |
public String getStratumName() {
return stratumName;
}
Returns the name of the stratum. |
public String getString() {
// 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();
}
Returns the given stratum as a String: a StratumSection,
followed by at least one FileSection and at least one LineSection. |
public void optimizeLineSection() {
/* 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++;
}
}
}
Combines consecutive LineInfos wherever possible |
public String toString() {
return getString();
}
|