From 064f905045cbbcd61723201aa0e93a9d1fb8c85f Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Fri, 16 Dec 2016 14:15:29 -0500 Subject: [PATCH] Performed some minor code cleanup --- src/token/Eof.java | 6 +++--- src/token/RightParenthesis.java | 8 ++++---- src/token/Token.java | 12 ------------ test/error/ErrorManagerTester.java | 2 +- test/scanner/LispScannerLineColumnTester.java | 7 ++++--- test/scanner/LispScannerTextTester.java | 5 ++++- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/token/Eof.java b/src/token/Eof.java index 6f3ff55..2df039b 100644 --- a/src/token/Eof.java +++ b/src/token/Eof.java @@ -14,15 +14,15 @@ public class Eof extends Token { @Override public SExpression parseSExpression(Supplier getNextToken) { - throw new EofEncounteredException(this); + throw new EofEncounteredException(getPosition()); } public static class EofEncounteredException extends LineColumnException { private static final long serialVersionUID = 1L; - public EofEncounteredException(Token token) { - super(token.getPosition()); + public EofEncounteredException(FilePosition position) { + super(position); } public String getMessagePrefix() { diff --git a/src/token/RightParenthesis.java b/src/token/RightParenthesis.java index 7b716b0..f00b622 100644 --- a/src/token/RightParenthesis.java +++ b/src/token/RightParenthesis.java @@ -15,7 +15,7 @@ public class RightParenthesis extends Token { @Override public SExpression parseSExpression(Supplier getNextToken) { - throw new StartsWithRightParenthesisException(this); + throw new StartsWithRightParenthesisException(getPosition()); } @Override @@ -27,12 +27,12 @@ public class RightParenthesis extends Token { private static final long serialVersionUID = 1L; - public StartsWithRightParenthesisException(Token token) { - super(token.getPosition()); + public StartsWithRightParenthesisException(FilePosition position) { + super(position); } public String getMessagePrefix() { - return "Expression begins with ')'"; + return "expression begins with ')'"; } } diff --git a/src/token/Token.java b/src/token/Token.java index 5988585..ad28073 100644 --- a/src/token/Token.java +++ b/src/token/Token.java @@ -27,18 +27,6 @@ public abstract class Token { return position; } - public String getFileName() { - return position.getFileName(); - } - - public int getLine() { - return position.getLineNumber(); - } - - public int getColumn() { - return position.getColumnNumber(); - } - // sExpr ::= NUMBER | IDENTIFIER | STRING | QUOTE_MARK sExpr | LEFT_PAREN sExprTail public abstract SExpression parseSExpression(Supplier getNextToken); diff --git a/test/error/ErrorManagerTester.java b/test/error/ErrorManagerTester.java index 7abb0de..dcdb89d 100644 --- a/test/error/ErrorManagerTester.java +++ b/test/error/ErrorManagerTester.java @@ -53,7 +53,7 @@ public class ErrorManagerTester { } }; } - + @Before public void setUp() { this.indicatorSet = new HashSet<>(); diff --git a/test/scanner/LispScannerLineColumnTester.java b/test/scanner/LispScannerLineColumnTester.java index 3d547a9..be02516 100644 --- a/test/scanner/LispScannerLineColumnTester.java +++ b/test/scanner/LispScannerLineColumnTester.java @@ -7,6 +7,7 @@ import java.io.InputStream; import org.junit.Test; +import file.FilePosition; import token.Token; public class LispScannerLineColumnTester { @@ -24,8 +25,8 @@ public class LispScannerLineColumnTester { return lineColumn; } - public boolean isEqual(Token token) { - return (this.line == token.getLine()) && (this.column == token.getColumn()); + public boolean isEqual(FilePosition position) { + return (this.line == position.getLineNumber()) && (this.column == position.getColumnNumber()); } } @@ -35,7 +36,7 @@ public class LispScannerLineColumnTester { for (LineColumn lineColumn : expectedLineColumnList) { Token nextToken = lispScanner.getNextToken(); - assertTrue(lineColumn.isEqual(nextToken)); + assertTrue(lineColumn.isEqual(nextToken.getPosition())); } } diff --git a/test/scanner/LispScannerTextTester.java b/test/scanner/LispScannerTextTester.java index 3f66da2..5141956 100644 --- a/test/scanner/LispScannerTextTester.java +++ b/test/scanner/LispScannerTextTester.java @@ -7,6 +7,8 @@ import java.io.InputStream; import org.junit.Test; +import file.FilePosition; + public class LispScannerTextTester { private void assertTokenTextMatches(String input, String[] expectedTextList) { @@ -31,8 +33,9 @@ public class LispScannerTextTester { private void assertInputFileNameMatches(String input, String expectedInputFileName) { InputStream stringInputStream = createInputStreamFromString(input); LispScanner lispScanner = new LispScanner(stringInputStream, expectedInputFileName); + FilePosition tokenPosition = lispScanner.getNextToken().getPosition(); - assertEquals(expectedInputFileName, lispScanner.getNextToken().getFileName()); + assertEquals(expectedInputFileName, tokenPosition.getFileName()); } @Test