Skip to content

Commit 1201bc8

Browse files
committed
refactored insertComments() to insertTokens()
1 parent e32fd78 commit 1201bc8

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/fortran/ofp/XMLPrinterBase.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -581,17 +581,21 @@ protected void printParameter(Token param, String name) {
581581
setAttribute(name, param);
582582
}
583583

584-
protected void insertComments(Element context) throws IOException {
584+
/**
585+
* Insert raw tokens from current file into given context.
586+
*/
587+
protected void insertTokens(Element context, int tokenType, String tokenContextName, String tokenTextAttributeName)
588+
throws IOException {
585589
// System.err.println("all tokens: " + new TokensList(new File(filename), false));
586-
TokensList comments = new TokensList(new File(filename), false, FortranLexer.LINE_COMMENT);
587-
// System.err.println("comments: " + comments);
590+
TokensList tokens = new TokensList(new File(filename), false, tokenType);
591+
// System.err.println("found tokens: " + tokens);
588592

589-
for (Token comment : comments) {
590-
int line = comment.getLine();
591-
int col_begin = comment.getCharPositionInLine();
592-
int col_end = col_begin + comment.getText().length();
593+
for (Token token : tokens) {
594+
int line = token.getLine();
595+
int col_begin = token.getCharPositionInLine();
593596
Element target = findContext(context, line, col_begin);
594597
/* debug-only
598+
int col_end = col_begin + comment.getText().length();
595599
Element targetAlt = findContext(context, line, col_end);
596600
*/
597601
if (target == null /*&& targetAlt == null*/) {
@@ -613,16 +617,16 @@ protected void insertComments(Element context) throws IOException {
613617
}
614618
*/
615619

616-
Element commentNode = contextOpen("comment");
617-
setAttribute("text", comment.getText());
618-
updateBounds(comment);
620+
Element tokenNode = contextOpen(tokenContextName);
621+
setAttribute(tokenTextAttributeName, token.getText());
622+
updateBounds(token);
619623
contextClose();
620624

621-
commentNode.getParentNode().removeChild(commentNode);
625+
tokenNode.getParentNode().removeChild(tokenNode);
622626
if (targetIndex < contextNodesCount(target))
623-
target.insertBefore(commentNode, contextNode(target, targetIndex));
627+
target.insertBefore(tokenNode, contextNode(target, targetIndex));
624628
else if (targetIndex == contextNodesCount(target))
625-
target.appendChild(commentNode);
629+
target.appendChild(tokenNode);
626630
else
627631
throw new IllegalArgumentException("location within target is invalid");
628632
}
@@ -668,7 +672,7 @@ public void cleanUp() {
668672
if (verbosity >= 100) {
669673
propagateBounds(context);
670674
try {
671-
insertComments(context);
675+
insertTokens(context, FortranLexer.LINE_COMMENT, "comment", "text");
672676
} catch (IOException error) {
673677
error.printStackTrace();
674678
System.exit(1);

0 commit comments

Comments
 (0)