package edu.kit.iti.formal.pse.worthwhile.validation;

import org.antlr.runtime.EarlyExitException;
import org.eclipse.xtext.nodemodel.SyntaxErrorMessage;
import org.eclipse.xtext.parser.antlr.SyntaxErrorMessageProvider;

/**
 * This class provides the correct syntax error messages.
 * 
 * @author matthias
 * 
 */
public class WorthwhileSyntaxErrorMessageProvider extends SyntaxErrorMessageProvider {

	/**
	 * Error code for "No newline at end of file".
	 */
	public static final String NO_NEWLINE_AT_EOF = "NoNewlineAtEOF";

	/**
	 * Error code for "No return type specified for function".
	 */
	public static final String NO_FUNCTION_RETURN_TYPE = "NoFunctionReturnType";

	/**
	 * Returns a syntax error messages for the context.
	 * 
	 * @param context
	 *                the context from which you want the error message
	 * 
	 * @return the syntax error message
	 */
	@Override
	public final SyntaxErrorMessage getSyntaxErrorMessage(final IParserErrorContext context) {
		if (context.getRecognitionException() instanceof EarlyExitException) {

			if (context.getCurrentNode().getRootNode().getTotalEndLine() == context.getCurrentNode()
			                .getEndLine()) {
				return new SyntaxErrorMessage("Newline is missing", NO_NEWLINE_AT_EOF);
			} else {
				return new SyntaxErrorMessage("Delete this token.", "deleteToken");
			}
		}

		return super.getSyntaxErrorMessage(context);

	}

}

@@ -93,16 +93,63 @@
 eption;%0A
+import org.antlr.runtime.NoViableAltException;%0A
 import o
@@ -262,16 +262,77 @@
 vider;%0A%0A
+import edu.kit.iti.formal.pse.worthwhile.model.ast.Program;%0A%0A
 /**%0A * T
@@ -1447,16 +1447,264 @@
 );%0A%09%09%09%7D%0A
+%09%09%7D else if (context.getRecognitionException() instanceof NoViableAltException%0A%09%09                && context.getCurrentContext() instanceof Program) %7B%0A%09%09%09return new SyntaxErrorMessage(%22Return type of function is missing%22, NO_FUNCTION_RETURN_TYPE);%0A%0A
 %09%09%7D%0A%0A%09%09r

Add no function return type error message.