Search in sources :

Example 31 with MethodWithType

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

the class _Sum method matchMt.

private static Void matchMt(List<Ast.C> pathForError, MethodWithType mwta, List<Member> ms, Member mb) {
    if (mb instanceof MethodImplemented) {
        throw Errors42.errorMethodClash(pathForError, mwta, mb, false, Collections.emptyList(), false, false, false);
    }
    MethodWithType mwtb = (MethodWithType) mb;
    Errors42.checkMethodClash(pathForError, mwta, mwtb, false);
    ms.add(_Sum.sumMethod(mwta, mwtb));
    return null;
}
Also used : MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 32 with MethodWithType

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

the class PlgWrapperGenerator method hasFrom.

public static boolean hasFrom(ClassB l) {
    //   class method mut This0 #from(Library binaryRepr)
    MethodSelector ms = MethodSelector.of("#from", Collections.singletonList("binaryRepr"));
    MethodWithType mwt = (MethodWithType) l._getMember(ms);
    //must be an mwt since normalized
    if (mwt == null) {
        return false;
    }
    MethodType mt = mwt.getMt();
    if (!mt.getMdf().equals(Mdf.Class)) {
        return false;
    }
    if (!mt.getTs().get(0).equals(Type.immLibrary)) {
        return false;
    }
    if (!mt.getExceptions().isEmpty()) {
        return false;
    }
    if (!mt.getReturnType().equals(Type.mutThis0)) {
        return false;
    }
    return true;
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 33 with MethodWithType

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

the class PlgWrapperGenerator method addMwt.

private static void addMwt(Program p, PlgInfo plgInfo, Method[] jms, Constructor<?>[] jcs, List<Member> msResult, Path pTop, MethodWithType mwt) throws UnresolvedOverloading, ClassUnfit, MethodUnfit {
    //checks
    try {
        isOkAsReturn(p, pTop, mwt.getMt().getReturnType());
        for (Type ti : mwt.getMt().getExceptions()) {
            isOkAsException(p, pTop, ti.getPath());
        }
        for (Type ti : mwt.getMt().getTs()) {
            isOkAsParameter(p, pTop, ti);
        }
    //TODO: we may want to cache those tests if performance is needed
    } catch (ClassUnfit | MethodUnfit e) {
        e.setMessage("While examining Class " + pTop + " method " + mwt.getMs() + ":\n" + e.getMessage());
        throw e;
    }
    //add to msResult
    //TODO: add behaviour if mwt have special comment to define specific ms for use
    String name = mwt.getMs().nameToS();
    if (name.startsWith("#")) {
        name = name.substring(1);
    }
    UsingInfo ui;
    if (!name.equals("new") && !name.equals("apply"))
        ui = usingMethod(plgInfo, jms, mwt, name);
    else
        ui = usingConstructor(plgInfo, jcs, mwt, name);
    MethodWithType tu = updateTemplateUsing(ui, mwt);
    msResult.add(tu);
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) UsingInfo(platformSpecific.fakeInternet.PluginWithPart.UsingInfo) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit)

Example 34 with MethodWithType

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

the class PlgWrapperGenerator method hasBinaryRepr.

public static boolean hasBinaryRepr(ClassB l) {
    //read method Library #binaryRepr()
    MethodSelector ms = MethodSelector.of("#binaryRepr", Collections.emptyList());
    MethodWithType mwt = (MethodWithType) l._getMember(ms);
    //must be an mwt since normalized
    if (mwt == null) {
        return false;
    }
    MethodType mt = mwt.getMt();
    if (!mt.getMdf().equals(Mdf.Readable)) {
        return false;
    }
    if (!mt.getTs().isEmpty()) {
        return false;
    }
    if (!mt.getExceptions().isEmpty()) {
        return false;
    }
    if (!mt.getReturnType().equals(Type.immLibrary)) {
        return false;
    }
    return true;
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 35 with MethodWithType

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

the class PlgWrapperGenerator method hasExceptionIf.

public static boolean hasExceptionIf(ClassB l) {
    //class method Void #exceptionIf(Library binaryRepr) exception This
    MethodSelector ms = MethodSelector.of("#exceptionIf", Collections.singletonList("binaryRepr"));
    MethodWithType mwt = (MethodWithType) l._getMember(ms);
    //must be an mwt since normalized
    if (mwt == null) {
        return false;
    }
    MethodType mt = mwt.getMt();
    if (!mt.getMdf().equals(Mdf.Class)) {
        return false;
    }
    if (!mt.getTs().get(0).equals(Type.immLibrary)) {
        return false;
    }
    if (mt.getExceptions().size() != 1) {
        return false;
    }
    if (!mt.getExceptions().get(0).equals(Path.outer(0))) {
        return false;
    }
    if (!mt.getReturnType().equals(Type.immVoid)) {
        return false;
    }
    //no need to check return type, since is just thrown as error
    return true;
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Aggregations

MethodWithType (ast.ExpCore.ClassB.MethodWithType)46 Member (ast.ExpCore.ClassB.Member)21 MethodType (ast.Ast.MethodType)18 ArrayList (java.util.ArrayList)16 Type (ast.Ast.Type)13 Path (ast.Ast.Path)10 ClassB (ast.ExpCore.ClassB)10 NestedClass (ast.ExpCore.ClassB.NestedClass)9 ExpCore (ast.ExpCore)8 MethodSelector (ast.Ast.MethodSelector)7 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)7 Ast (ast.Ast)4 Phase (ast.ExpCore.ClassB.Phase)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Program (programReduction.Program)4 Mdf (ast.Ast.Mdf)3 Functions (auxiliaryGrammar.Functions)3 From (coreVisitors.From)3 Collections (java.util.Collections)3