Skip to content

Commit 40901ce

Browse files
committed
partial refactoring of bounds code
1 parent d1413f6 commit 40901ce

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/fortran/ofp/XMLPrinterBase.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -433,19 +433,18 @@ public int findPosition(Element context, int line, int col) {
433433
}
434434

435435
protected Integer[] getBounds(Element context) {
436-
Integer line_begin = null;
437-
if (context.hasAttribute(Y_MIN))
438-
line_begin = Integer.valueOf(context.getAttribute(Y_MIN));
439-
Integer col_begin = null;
440-
if (context.hasAttribute(X_MIN))
441-
col_begin = Integer.valueOf(context.getAttribute(X_MIN));
442-
Integer line_end = null;
443-
if (context.hasAttribute(Y_MAX))
444-
line_end = Integer.valueOf(context.getAttribute(Y_MAX));
445-
Integer col_end = null;
446-
if (context.hasAttribute(X_MAX))
447-
col_end = Integer.valueOf(context.getAttribute(X_MAX));
448-
return new Integer[] { line_begin, col_begin, line_end, col_end };
436+
Integer lineBegin = context.hasAttribute(Y_MIN) ? Integer.valueOf(context.getAttribute(Y_MIN)) : null;
437+
Integer colBegin = context.hasAttribute(X_MIN) ? Integer.valueOf(context.getAttribute(X_MIN)) : null;
438+
Integer lineEnd = context.hasAttribute(Y_MAX) ? Integer.valueOf(context.getAttribute(Y_MAX)) : null;
439+
Integer colEnd = context.hasAttribute(X_MAX) ? Integer.valueOf(context.getAttribute(X_MAX)) : null;
440+
return new Integer[] { lineBegin, colBegin, lineEnd, colEnd };
441+
}
442+
443+
protected Integer[] getBounds(Token token) {
444+
Integer line = token.getLine();
445+
Integer colBegin = token.getCharPositionInLine();
446+
Integer colEnd = colBegin + token.getText().length();
447+
return new Integer[] { line, colBegin, line, colEnd };
449448
}
450449

451450
protected void updateBounds(Element context, Integer[] bounds) {
@@ -472,10 +471,7 @@ protected void updateBounds(Element context, Token... newTokens) {
472471
for (Token newToken : newTokens) {
473472
if (newToken == null)
474473
continue;
475-
Integer new_line = newToken.getLine();
476-
Integer new_col_begin = newToken.getCharPositionInLine();
477-
Integer new_col_end = new_col_begin + newToken.getText().length();
478-
updateBounds(context, new_line, new_col_begin, new_line, new_col_end);
474+
updateBounds(context, getBounds(newToken));
479475
}
480476
}
481477

0 commit comments

Comments
 (0)