Search in sources :

Example 51 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class ErrorFormatter method whyIsNotExecutable.

public static String whyIsNotExecutable(Path path, Program p1) {
    ClassB cb = p1.extractClassB(path);
    String whyNot = whyIsNotExecutable(cb);
    if (whyNot != null) {
        return "The requested path is incomplete.\n  " + ToFormattedText.of(path) + whyNot;
    }
    return "The requested path is incomplete since it refers to other incomplete classes in the program";
}
Also used : ClassB(ast.ExpCore.ClassB)

Example 52 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class ErrorFormatter method topFormatErrorMessage.

@SuppressWarnings("unchecked")
public static void topFormatErrorMessage(ErrorMessage msg) {
    //System.out.println(ErrorFormatter.formatError(msg).getErrorTxt());
    L42.printDebug(formatError(Program.emptyLibraryProgram(), msg).getErrorTxt());
    for (Field f : msg.getClass().getDeclaredFields()) {
        f.setAccessible(true);
        if (!f.getName().equals("p")) {
            continue;
        }
        List<ClassB> program;
        try {
            program = (List<ClassB>) f.get(msg);
        } catch (IllegalArgumentException | IllegalAccessException e) {
            throw new Error(e);
        }
        if (program != null) {
            for (ClassB cb : program) {
                L42.printDebug(displayAbstractMethods(cb));
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) ClassB(ast.ExpCore.ClassB)

Example 53 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class ErrorFormatter method printType.

private static void printType(int i, String prefix, ClassB top) {
    System.out.print("This" + i + prefix + " :{\n");
    printMembers(top);
    System.out.print("  }\n");
    for (Member m : top.getMs()) {
        if (!(m instanceof NestedClass)) {
            continue;
        }
        NestedClass nc = (NestedClass) m;
        if (nc.getInner() instanceof ClassB) {
            printType(i, "." + nc.getName(), (ClassB) nc.getInner());
        }
    }
}
Also used : NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 54 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class ErrorFormatter method displayAbstractMethods.

//TODO: what was this for
@SuppressWarnings("unused")
private static void displayAbstractMethods(ClassB cb, StringBuilder result, String nesting) {
    result.append("{\n");
    for (Member m : cb.getMs()) {
        m.match(nc -> {
            if (!(nc.getInner() instanceof ClassB)) {
                return null;
            }
            if (((ClassB) nc.getInner()).isInterface()) {
                return null;
            }
            StringBuilder inner = new StringBuilder();
            displayAbstractMethods((ClassB) nc.getInner(), inner, nesting + "  ");
            String innerStr = inner.toString();
            if (!innerStr.contains("method")) {
                return null;
            }
            result.append(nesting);
            result.append(nc.getName());
            result.append(":");
            result.append(innerStr);
            return null;
        }, mi -> {
            return null;
        }, mt -> {
            if (mt.get_inner().isPresent()) {
                return null;
            }
            if (mt.getMt().getMdf() == Mdf.Class) {
                return null;
            }
            result.append(nesting);
            result.append(ToFormattedText.of(mt).replace("\n", "\n" + nesting));
            result.append("\n");
            return null;
        });
    }
    result.append("}\n");
}
Also used : Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 55 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class L42 method checkFinalError.

public static ErrorMessage.FinalResult checkFinalError(ClassB result) {
    L42.setExecutionStage(ExecutionStage.Closing);
    ClassB.NestedClass last = (ClassB.NestedClass) result.getMs().get(result.getMs().size() - 1);
    if (!(last.getInner() instanceof ClassB)) {
        finalErr(result, "The last class can not be completed");
    }
    ClassB lastC = (ClassB) last.getInner();
    //TODO: booh what is the right kind? if(!(lastC.getH() instanceof Ast.TraitHeader)){finalErr(result,"The last class is not a Trait");}
    if (!lastC.getMs().isEmpty()) {
        finalErr(result, "The last class contains members");
    }
    String errCode = lastC.getDoc1().toString();
    if (!errCode.startsWith("@exitStatus\n")) {
        finalErr(result, "The last class is not an exitStatus class:" + errCode);
    }
    errCode = errCode.substring("@exitStatus\n".length());
    int errCodeInt = 0;
    try {
        errCodeInt = Integer.parseInt(errCode.substring(0, errCode.length() - 1));
    } catch (NumberFormatException e) {
        finalErr(result, "The exitStatus is not a valid number: " + errCode);
    }
    if (errCodeInt > 0 && errCodeInt < 100) {
        finalErr(result, "The exitStatus is reserved: " + errCodeInt);
    }
    return new ErrorMessage.FinalResult(errCodeInt, result);
}
Also used : FinalResult(ast.ErrorMessage.FinalResult) ClassB(ast.ExpCore.ClassB)

Aggregations

ClassB (ast.ExpCore.ClassB)107 ArrayList (java.util.ArrayList)33 Path (ast.Ast.Path)30 ExpCore (ast.ExpCore)25 Member (ast.ExpCore.ClassB.Member)25 EncodingHelper.ensureExtractClassB (auxiliaryGrammar.EncodingHelper.ensureExtractClassB)20 Program (programReduction.Program)20 Ast (ast.Ast)19 MethodWithType (ast.ExpCore.ClassB.MethodWithType)19 MethodSelector (ast.Ast.MethodSelector)18 NestedClass (ast.ExpCore.ClassB.NestedClass)18 List (java.util.List)17 ActionType (platformSpecific.fakeInternet.ActionType)16 Doc (ast.Ast.Doc)12 Type (ast.Ast.Type)12 ErrorMessage (ast.ErrorMessage)12 Optional (java.util.Optional)10 C (ast.Ast.C)9 MethodType (ast.Ast.MethodType)8 Phase (ast.ExpCore.ClassB.Phase)8