Search in sources :

Example 6 with MethodWithType

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

the class Rename method renameMethod.

public static ClassB renameMethod(Program p, ClassB cb, List<Ast.C> path, MethodSelector src, MethodSelector dest) {
    Member mem = Errors42.checkExistsPathMethod(cb, path, Optional.of(src));
    assert mem instanceof MethodWithType;
    Errors42.checkCompatibleMs(path, (MethodWithType) mem, dest);
    CollectedLocatorsMap maps = CollectedLocatorsMap.from(Path.outer(0, path), (MethodWithType) mem, dest);
    RenameAlsoDefinition ren = new RenameAlsoDefinition(cb, maps, p);
    return (ClassB) ren.visit(cb);
}
Also used : MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 7 with MethodWithType

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

the class SumMethods method sumMethods.

public static ClassB sumMethods(ClassB lib, List<Ast.C> path, MethodSelector m1, MethodSelector m2, MethodSelector mRes, String name) {
    ClassB pathCb = pathCb(lib, path);
    Member mem1 = Errors42.checkExistsPathMethod(lib, path, Optional.of(m1));
    Member mem2 = Errors42.checkExistsPathMethod(lib, path, Optional.of(m2));
    MethodType mt1 = ((MethodWithType) pathCb._getMember(m1)).getMt();
    MethodType mt2 = ((MethodWithType) pathCb._getMember(m2)).getMt();
    int index = m2.getNames().indexOf(name);
    if (index == -1) {
        throw Errors42.errorParameterMismatch(path, mem1, mem2, false, false, false);
    }
    checkParSize(index, path, m1, m2, mRes, mem1, mem2, mt1, mt2);
    MethodType mtU = mtU(index, mt1, mt2);
    if (mtU == null) {
        throw Errors42.errorParameterMismatch(path, mem1, mem2, isReplacedParOk(index, mt1, mt2), false, true);
    }
    ExpCore eU = eU(index, mem2.getP(), mt1, mt2, m1, m2, mRes);
    MethodWithType mwtU = new MethodWithType(Doc.empty(), mRes, mtU, Optional.of(eU), mem2.getP());
    checkConflict(path, mRes, pathCb, mwtU);
    boolean replOk = isReplacedParOk(index, mt1, mt2);
    if (!replOk) {
        throw Errors42.errorParameterMismatch(path, mem1, mem2, false, true, true);
    }
    return finalResult(lib, path, mwtU);
}
Also used : MethodType(ast.Ast.MethodType) ExpCore(ast.ExpCore) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 8 with MethodWithType

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

the class PlgWrapperGenerator method plgComplete1.

public static ClassB plgComplete1(List<Ast.C> cs, Program p, ClassB l) throws UnresolvedOverloading, ClassUnfit, MethodUnfit {
    PluginWithPart pwp = OnLineCode._isPluginWithPart(l.getDoc1());
    if (pwp == null) {
        return l;
    }
    PlgInfo plgInfo = new PlgInfo(l.getDoc1());
    if (!hasPluginUnresponsive(l)) {
        throw new RefactorErrors.ClassUnfit().msg("Class " + Path.outer(0, cs) + " does not contain method #pluginUnresponsive(binaryRepr)");
    }
    Class<?> c = pwp.pointed;
    Method[] jms = c.getMethods();
    Constructor<?>[] jcs = c.getDeclaredConstructors();
    List<Member> msResult = new ArrayList<>(templateWrapper);
    Path pTop = Path.outer(0, cs);
    for (Member m : l.getMs()) {
        if (!(m instanceof MethodWithType)) {
            msResult.add(m);
            continue;
        }
        MethodWithType mwt = (MethodWithType) m;
        if (mwt.get_inner().isPresent()) {
            msResult.add(mwt);
            continue;
        }
        addMwt(p, plgInfo, jms, jcs, msResult, pTop, mwt);
    }
    return l.withMs(msResult);
}
Also used : Path(ast.Ast.Path) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) Method(java.lang.reflect.Method) MethodWithType(ast.ExpCore.ClassB.MethodWithType) PlgInfo(platformSpecific.fakeInternet.PluginWithPart.PlgInfo) PluginWithPart(platformSpecific.fakeInternet.PluginWithPart) Member(ast.ExpCore.ClassB.Member)

Example 9 with MethodWithType

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

the class PlgWrapperGenerator method hasPluginUnresponsive.

public static boolean hasPluginUnresponsive(ClassB l) {
    //class method T #pluginUnresponsive(Library binaryRepr)
    MethodSelector ms = MethodSelector.of("#pluginUnresponsive", 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().getMdf().equals(Mdf.Immutable)) {
        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)

Example 10 with MethodWithType

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

the class Compose method sumMwt.

public static MethodWithType sumMwt(MethodWithType mwt1, MethodWithType mwt2) {
    if (mwt1 == null) {
        return mwt2;
    }
    boolean refine = mwt1.getMt().isRefine() || mwt2.getMt().isRefine();
    if (!mwt1.getMt().withRefine(false).equals(mwt2.getMt().withRefine(false))) {
        assert false;
    }
    Optional<ExpCore> body = mwt1.get_inner();
    if (body.isPresent() && mwt2.get_inner().isPresent()) {
        assert false;
    }
    if (!body.isPresent()) {
        body = mwt2.get_inner();
    }
    MethodWithType mwt = mwt1.withMt(mwt1.getMt().withRefine(refine)).with_inner(body);
    return mwt;
}
Also used : ExpCore(ast.ExpCore) 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