Add @Override annotations and clean up code

This commit is contained in:
Mike Cifelli 2017-03-13 09:58:30 -04:00
parent c2d722d5ab
commit f2a481952d
55 changed files with 76 additions and 0 deletions

View File

@ -50,32 +50,41 @@ public class ErrorManager {
} }
public static enum Severity { public static enum Severity {
WARNING { WARNING {
@Override
public String decorate(String warningOutput, RuntimeEnvironment environment) { public String decorate(String warningOutput, RuntimeEnvironment environment) {
return environment.decorateWarningOutput(warningOutput); return environment.decorateWarningOutput(warningOutput);
} }
@Override
public String toDisplayString() { public String toDisplayString() {
return "warning"; return "warning";
} }
}, },
ERROR { ERROR {
@Override
public String decorate(String errorOutput, RuntimeEnvironment environment) { public String decorate(String errorOutput, RuntimeEnvironment environment) {
return environment.decorateErrorOutput(errorOutput); return environment.decorateErrorOutput(errorOutput);
} }
@Override
public String toDisplayString() { public String toDisplayString() {
return "error"; return "error";
} }
}, },
CRITICAL { CRITICAL {
@Override
public String decorate(String criticalOutput, RuntimeEnvironment environment) { public String decorate(String criticalOutput, RuntimeEnvironment environment) {
return environment.decorateCriticalOutput(criticalOutput); return environment.decorateCriticalOutput(criticalOutput);
} }
@Override
public String toDisplayString() { public String toDisplayString() {
return "critical"; return "critical";
} }

View File

@ -81,6 +81,7 @@ public class UserDefinedFunction extends LispFunction {
argumentValidator.setExactNumberOfArguments(this.formalParameters.size()); argumentValidator.setExactNumberOfArguments(this.formalParameters.size());
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -21,6 +21,7 @@ public class APPLY extends LispFunction {
this.argumentValidator.setTrailingArgumentExpectedType(Cons.class); this.argumentValidator.setTrailingArgumentExpectedType(Cons.class);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -58,6 +58,7 @@ public class EVAL extends LispFunction {
this.argumentValidator.setExactNumberOfArguments(1); this.argumentValidator.setExactNumberOfArguments(1);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);
SExpression argument = argumentList.getFirst(); SExpression argument = argumentList.getFirst();

View File

@ -18,6 +18,7 @@ public class EXIT extends LispFunction {
this.environment = RuntimeEnvironment.getInstance(); this.environment = RuntimeEnvironment.getInstance();
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);
environment.terminateSuccessfully(); environment.terminateSuccessfully();

View File

@ -16,6 +16,7 @@ public class FUNCALL extends LispFunction {
this.argumentValidator.setMinimumNumberOfArguments(1); this.argumentValidator.setMinimumNumberOfArguments(1);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);
Cons applyArgs = new Cons(argumentList.getFirst(), makeList(argumentList.getRest())); Cons applyArgs = new Cons(argumentList.getFirst(), makeList(argumentList.getRest()));

View File

@ -29,6 +29,7 @@ public class GENSYM extends LispFunction {
this.argumentValidator.setMaximumNumberOfArguments(0); this.argumentValidator.setMaximumNumberOfArguments(0);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -29,6 +29,7 @@ public class LOAD extends LispFunction {
this.environment = RuntimeEnvironment.getInstance(); this.environment = RuntimeEnvironment.getInstance();
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -16,6 +16,7 @@ public class PRINT extends LispFunction {
this.environment = RuntimeEnvironment.getInstance(); this.environment = RuntimeEnvironment.getInstance();
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);
SExpression argument = argumentList.getFirst(); SExpression argument = argumentList.getFirst();

View File

@ -23,6 +23,7 @@ public class SET extends LispFunction {
this.executionContext = ExecutionContext.getInstance(); this.executionContext = ExecutionContext.getInstance();
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -19,6 +19,7 @@ public class SYMBOL_FUNCTION extends LispFunction {
this.argumentValidator.setEveryArgumentExpectedType(Symbol.class); this.argumentValidator.setEveryArgumentExpectedType(Symbol.class);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -13,6 +13,7 @@ public class CONS extends LispFunction {
this.argumentValidator.setExactNumberOfArguments(2); this.argumentValidator.setExactNumberOfArguments(2);
} }
@Override
public Cons call(Cons argumentList) { public Cons call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -14,6 +14,7 @@ public class FIRST extends LispFunction {
this.argumentValidator.setEveryArgumentExpectedType(Cons.class); this.argumentValidator.setEveryArgumentExpectedType(Cons.class);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);
Cons argument = (Cons) argumentList.getFirst(); Cons argument = (Cons) argumentList.getFirst();

View File

@ -25,6 +25,7 @@ public class LENGTH extends LispFunction {
this.argumentValidator.setEveryArgumentExpectedType(Cons.class); this.argumentValidator.setEveryArgumentExpectedType(Cons.class);
} }
@Override
public LispNumber call(Cons argumentList) { public LispNumber call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -18,6 +18,7 @@ public class LIST extends LispFunction {
this.argumentValidator = new ArgumentValidator(name); this.argumentValidator = new ArgumentValidator(name);
} }
@Override
public Cons call(Cons argumentList) { public Cons call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -14,6 +14,7 @@ public class REST extends LispFunction {
this.argumentValidator.setEveryArgumentExpectedType(Cons.class); this.argumentValidator.setEveryArgumentExpectedType(Cons.class);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);
Cons argument = (Cons) argumentList.getFirst(); Cons argument = (Cons) argumentList.getFirst();

View File

@ -18,6 +18,7 @@ public class DIVIDE extends LispFunction {
this.mathFunction = new MathFunction(this::getReciprocal, this::divide); this.mathFunction = new MathFunction(this::getReciprocal, this::divide);
} }
@Override
public LispNumber call(Cons argumentList) { public LispNumber call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -18,6 +18,7 @@ public class MINUS extends LispFunction {
this.mathFunction = new MathFunction(this::additiveInverse, this::subtract); this.mathFunction = new MathFunction(this::additiveInverse, this::subtract);
} }
@Override
public LispNumber call(Cons argumentList) { public LispNumber call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -17,6 +17,7 @@ public class MULTIPLY extends LispFunction {
this.mathFunction = new MathFunction(number -> number, this::multiply); this.mathFunction = new MathFunction(number -> number, this::multiply);
} }
@Override
public LispNumber call(Cons argumentList) { public LispNumber call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -17,6 +17,7 @@ public class PLUS extends LispFunction {
this.mathFunction = new MathFunction(number -> number, this::add); this.mathFunction = new MathFunction(number -> number, this::add);
} }
@Override
public LispNumber call(Cons argumentList) { public LispNumber call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -16,6 +16,7 @@ public class ATOM extends LispFunction {
this.argumentValidator.setExactNumberOfArguments(1); this.argumentValidator.setExactNumberOfArguments(1);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);
SExpression argument = argumentList.getFirst(); SExpression argument = argumentList.getFirst();

View File

@ -16,6 +16,7 @@ public class EQ extends LispFunction {
this.argumentValidator.setExactNumberOfArguments(2); this.argumentValidator.setExactNumberOfArguments(2);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -20,6 +20,7 @@ public class EQUAL extends LispFunction {
this.argumentValidator.setExactNumberOfArguments(2); this.argumentValidator.setExactNumberOfArguments(2);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -16,6 +16,7 @@ public class LISTP extends LispFunction {
this.argumentValidator.setExactNumberOfArguments(1); this.argumentValidator.setExactNumberOfArguments(1);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -16,6 +16,7 @@ public class NULL extends LispFunction {
this.argumentValidator.setExactNumberOfArguments(1); this.argumentValidator.setExactNumberOfArguments(1);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -17,6 +17,7 @@ public class NUMERIC_EQUAL extends LispFunction {
this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class); this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -17,6 +17,7 @@ public class NUMERIC_GREATER extends LispFunction {
this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class); this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -17,6 +17,7 @@ public class NUMERIC_LESS extends LispFunction {
this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class); this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -15,6 +15,7 @@ public class AND extends LispSpecialFunction {
this.argumentValidator = new ArgumentValidator(name); this.argumentValidator = new ArgumentValidator(name);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -20,6 +20,7 @@ public class CASE extends LispSpecialFunction {
this.argumentValidator.setTrailingArgumentExcludedType(Nil.class); this.argumentValidator.setTrailingArgumentExcludedType(Nil.class);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);
SExpression key = eval(argumentList.getFirst()); SExpression key = eval(argumentList.getFirst());

View File

@ -17,6 +17,7 @@ public class COND extends LispSpecialFunction {
this.argumentValidator.setEveryArgumentExcludedType(Nil.class); this.argumentValidator.setEveryArgumentExcludedType(Nil.class);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -31,6 +31,7 @@ public abstract class Define extends LispSpecialFunction {
this.environment = RuntimeEnvironment.getInstance(); this.environment = RuntimeEnvironment.getInstance();
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -16,6 +16,7 @@ public class IF extends LispSpecialFunction {
this.argumentValidator.setMaximumNumberOfArguments(3); this.argumentValidator.setMaximumNumberOfArguments(3);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -42,6 +42,7 @@ public class LAMBDA extends LispSpecialFunction {
this.lambdaListValidator.setEveryArgumentExpectedType(Symbol.class); this.lambdaListValidator.setEveryArgumentExpectedType(Symbol.class);
} }
@Override
public LambdaExpression call(Cons argumentList) { public LambdaExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -31,6 +31,7 @@ public class LET extends LispSpecialFunction {
this.executionContext = ExecutionContext.getInstance(); this.executionContext = ExecutionContext.getInstance();
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);
Cons variableDefinitions = (Cons) argumentList.getFirst(); Cons variableDefinitions = (Cons) argumentList.getFirst();

View File

@ -11,6 +11,7 @@ public class LET_STAR extends LET {
super(name); super(name);
} }
@Override
protected SymbolTable createLocalScope(Cons variableDefinitions) { protected SymbolTable createLocalScope(Cons variableDefinitions) {
SymbolTable localScope = new SymbolTable(executionContext.getScope()); SymbolTable localScope = new SymbolTable(executionContext.getScope());
executionContext.setScope(localScope); executionContext.setScope(localScope);

View File

@ -14,6 +14,7 @@ public class OR extends LispSpecialFunction {
this.argumentValidator = new ArgumentValidator(name); this.argumentValidator = new ArgumentValidator(name);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -15,6 +15,7 @@ public class PROGN extends LispSpecialFunction {
this.argumentValidator = new ArgumentValidator(name); this.argumentValidator = new ArgumentValidator(name);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -13,6 +13,7 @@ public class QUOTE extends LispSpecialFunction {
this.argumentValidator.setExactNumberOfArguments(1); this.argumentValidator.setExactNumberOfArguments(1);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -18,6 +18,7 @@ public class SETQ extends LispSpecialFunction {
this.argumentValidator.setFirstArgumentExpectedType(Symbol.class); this.argumentValidator.setFirstArgumentExpectedType(Symbol.class);
} }
@Override
public SExpression call(Cons argumentList) { public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList); argumentValidator.validate(argumentList);

View File

@ -12,10 +12,12 @@ public class AtSignExpression extends SExpression {
return expression; return expression;
} }
@Override
public boolean isAtSign() { public boolean isAtSign() {
return true; return true;
} }
@Override
public String toString() { public String toString() {
return "@" + expression; return "@" + expression;
} }

View File

@ -9,10 +9,12 @@ public abstract class Atom extends SExpression {
this.text = text; this.text = text;
} }
@Override
public boolean isAtom() { public boolean isAtom() {
return true; return true;
} }
@Override
public String toString() { public String toString() {
return text; return text;
} }

View File

@ -12,10 +12,12 @@ public class BackquoteExpression extends SExpression {
return expression; return expression;
} }
@Override
public boolean isBackquote() { public boolean isBackquote() {
return true; return true;
} }
@Override
public String toString() { public String toString() {
return "`" + expression; return "`" + expression;
} }

View File

@ -12,10 +12,12 @@ public class CommaExpression extends SExpression {
return expression; return expression;
} }
@Override
public boolean isComma() { public boolean isComma() {
return true; return true;
} }
@Override
public String toString() { public String toString() {
return "," + expression; return "," + expression;
} }

View File

@ -27,10 +27,12 @@ public class Cons extends SExpression {
this.rest = rest; this.rest = rest;
} }
@Override
public boolean isCons() { public boolean isCons() {
return true; return true;
} }
@Override
public String toString() { public String toString() {
return ("(" + toStringAux()); return ("(" + toStringAux());
} }

View File

@ -13,6 +13,7 @@ public class LambdaExpression extends SExpression {
this.function = function; this.function = function;
} }
@Override
public boolean isFunction() { public boolean isFunction() {
return true; return true;
} }
@ -25,6 +26,7 @@ public class LambdaExpression extends SExpression {
return function; return function;
} }
@Override
public String toString() { public String toString() {
return lambdaExpression.toString(); return lambdaExpression.toString();
} }

View File

@ -29,6 +29,7 @@ public class LispNumber extends Atom {
this.value = value; this.value = value;
} }
@Override
public boolean isNumber() { public boolean isNumber() {
return true; return true;
} }

View File

@ -7,6 +7,7 @@ public class LispString extends Atom {
super(text); super(text);
} }
@Override
public boolean isString() { public boolean isString() {
return true; return true;
} }

View File

@ -12,18 +12,22 @@ public class Nil extends Cons {
super.setRest(this); super.setRest(this);
} }
@Override
public boolean isNull() { public boolean isNull() {
return true; return true;
} }
@Override
public boolean isAtom() { public boolean isAtom() {
return true; return true;
} }
@Override
public boolean isCons() { public boolean isCons() {
return false; return false;
} }
@Override
public boolean isSymbol() { public boolean isSymbol() {
return true; return true;
} }
@ -31,13 +35,16 @@ public class Nil extends Cons {
/** /**
* The first of NIL can not be changed. * The first of NIL can not be changed.
*/ */
@Override
public void setFirst(SExpression first) {} public void setFirst(SExpression first) {}
/** /**
* The rest of NIL can not be changed. * The rest of NIL can not be changed.
*/ */
@Override
public void setRest(SExpression rest) {} public void setRest(SExpression rest) {}
@Override
public String toString() { public String toString() {
return "NIL"; return "NIL";
} }

View File

@ -13,6 +13,7 @@ public class Symbol extends Atom {
super(text.toUpperCase()); super(text.toUpperCase());
} }
@Override
public boolean isSymbol() { public boolean isSymbol() {
return true; return true;
} }

View File

@ -25,6 +25,7 @@ public class Eof extends Token {
super(position); super(position);
} }
@Override
public String getMessagePrefix() { public String getMessagePrefix() {
return "end-of-file encountered"; return "end-of-file encountered";
} }

View File

@ -32,6 +32,7 @@ public class RightParenthesis extends Token {
super(position); super(position);
} }
@Override
public String getMessagePrefix() { public String getMessagePrefix() {
return "expression begins with ')'"; return "expression begins with ')'";
} }

View File

@ -7,6 +7,7 @@ import file.FilePosition;
public class TokenFactoryImpl implements TokenFactory { public class TokenFactoryImpl implements TokenFactory {
@Override
public Token createToken(String text, FilePosition position) { public Token createToken(String text, FilePosition position) {
if (text.length() == 0) if (text.length() == 0)
throw new EmptyTokenTextException(position); throw new EmptyTokenTextException(position);
@ -51,6 +52,7 @@ public class TokenFactoryImpl implements TokenFactory {
return (text.length() > 1) && isDigit(text.charAt(1)); return (text.length() > 1) && isDigit(text.charAt(1));
} }
@Override
public Token createEofToken(FilePosition position) { public Token createEofToken(FilePosition position) {
return new Eof("EOF", position); return new Eof("EOF", position);
} }

View File

@ -13,6 +13,7 @@ public class LispInterpreterBuilderTester {
private LispInterpreterBuilder builder = new LispInterpreterBuilderImpl() { private LispInterpreterBuilder builder = new LispInterpreterBuilderImpl() {
@Override
public void reset() { public void reset() {
this.isBuilt = false; this.isBuilt = false;
} }

View File

@ -21,6 +21,7 @@ public final class TestUtilities {
public static InputStream createIOExceptionThrowingInputStream() { public static InputStream createIOExceptionThrowingInputStream() {
return new InputStream() { return new InputStream() {
@Override
public int read() throws IOException { public int read() throws IOException {
throw new IOException("test IOException"); throw new IOException("test IOException");
} }