Search in sources :

Example 1 with Kind

use of ast.ErrorMessage.UserLevelError.Kind in project L42 by ElvisResearchGroup.

the class ErrorFormatter method formatError.

public static ErrorMessage.UserLevelError formatError(Program p, ErrorMessage msg, Class<?> c) throws IllegalAccessException, NoSuchFieldException, SecurityException {
    String errorStart = "\n\n\n------------------------------------\n";
    ArrayList<Ast.Position> ps = new ArrayList<Ast.Position>();
    String errorTxt = "";
    errorTxt += infoFields(msg, c, ps);
    try {
        errorTxt += "Surrounding context:\n";
        errorTxt += envs(msg, c, ps);
        ArrayList<Position> ps2 = ps;
        if (!ps.isEmpty()) {
            ps2 = new ArrayList<>();
        }
        try {
            errorTxt += ctxP(msg, c, ps2);
        } catch (NoSuchFieldException ignored) {
        }
    } catch (NoSuchFieldException ignored) {
    }
    pos(msg, c, ps);
    Position pos = positionsFilter(ps);
    if (c == ErrorMessage.DotDotDotCanNotBeResolved.class) {
    //        ErrorMessage.DotDotDotCanNotBeResolved ddd=(ErrorMessage.DotDotDotCanNotBeResolved)msg;
    }
    errorTxt = "Error kind: " + c.getSimpleName() + "\nPosition:" + ((pos == null) ? "unknown" : pos.toString()) + "\n" + errorTxt;
    //ps+"\n"+errorTxt;
    ErrorMessage.UserLevelError.Kind kind = findKind(msg);
    switch(kind) {
        case TypeError:
            errorTxt = errorStart + "runStatus: " + kind.name() + "\n" + errorTxt;
            break;
        case MetaError:
            errorTxt = errorStart + "runStatus: " + kind.name() + "\n" + "Error in generating the following class: \n" + reportPlaceOfMetaError(p, msg) + /*.replace(".\n","\n")*/
            "\n----------\n" + errorTxt;
        default:
            break;
    }
    Throwable cause = null;
    if (msg.getCause() != null) {
        if (msg.getCause() instanceof ErrorMessage) {
            ErrorMessage.UserLevelError uleCause = formatError(p, (ErrorMessage) msg.getCause());
            cause = uleCause;
            errorTxt += "\n-------- caused by -----\n" + uleCause.getErrorTxt();
        } else {
            cause = msg.getCause();
        }
    }
    ErrorMessage.UserLevelError result = new ErrorMessage.UserLevelError(kind, pos, msg, errorTxt);
    result.initCause(cause);
    return result;
}
Also used : Ast(ast.Ast) Position(ast.Ast.Position) ArrayList(java.util.ArrayList) Kind(ast.ErrorMessage.UserLevelError.Kind) ErrorMessage(ast.ErrorMessage)

Aggregations

Ast (ast.Ast)1 Position (ast.Ast.Position)1 ErrorMessage (ast.ErrorMessage)1 Kind (ast.ErrorMessage.UserLevelError.Kind)1 ArrayList (java.util.ArrayList)1