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 {
WARNING {
@Override
public String decorate(String warningOutput, RuntimeEnvironment environment) {
return environment.decorateWarningOutput(warningOutput);
}
@Override
public String toDisplayString() {
return "warning";
}
},
ERROR {
@Override
public String decorate(String errorOutput, RuntimeEnvironment environment) {
return environment.decorateErrorOutput(errorOutput);
}
@Override
public String toDisplayString() {
return "error";
}
},
CRITICAL {
@Override
public String decorate(String criticalOutput, RuntimeEnvironment environment) {
return environment.decorateCriticalOutput(criticalOutput);
}
@Override
public String toDisplayString() {
return "critical";
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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