Search in sources :

Example 16 with Member

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

the class TestHelper method reportError.

public static void reportError(ErrorMessage e) {
    if (Executor.last1 == null || Executor.last2 == null) {
        throw e;
    }
    ClassB c1 = (ClassB) Executor.last1;
    ClassB c2 = (ClassB) Executor.last2;
    ArrayList<Member> ms1 = new ArrayList<>();
    ArrayList<Member> ms2 = new ArrayList<>();
    {
        int i = -1;
        for (Member e1 : c1.getMs()) {
            i += 1;
            Member e2 = c2.getMs().get(i);
            if (e1.equals(e2)) {
                continue;
            }
            ms1.add(e1);
            ms2.add(e2);
        }
    }
    c1 = c1.withMs(ms1);
    c2 = c2.withMs(ms2);
//TestHelper.assertEqualExp(c1, c2);
}
Also used : ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 17 with Member

use of ast.ExpCore.ClassB.Member 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 18 with Member

use of ast.ExpCore.ClassB.Member 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 19 with Member

use of ast.ExpCore.ClassB.Member 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 20 with Member

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

the class TranslateClass method extractConstructors.

private static List<MethodWithType> extractConstructors(ClassB ct) {
    List<MethodWithType> result = new ArrayList<>();
    for (Member m : ct.getMs()) {
        assert m instanceof MethodWithType;
        MethodWithType mt = (MethodWithType) m;
        if (mt.get_inner().isPresent()) {
            continue;
        }
        if (mt.getMt().getMdf() != Ast.Mdf.Class) {
            continue;
        }
        result.add(mt);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Aggregations

Member (ast.ExpCore.ClassB.Member)54 ArrayList (java.util.ArrayList)32 ClassB (ast.ExpCore.ClassB)21 MethodWithType (ast.ExpCore.ClassB.MethodWithType)21 NestedClass (ast.ExpCore.ClassB.NestedClass)20 Ast (ast.Ast)14 ExpCore (ast.ExpCore)11 Path (ast.Ast.Path)10 List (java.util.List)7 Doc (ast.Ast.Doc)5 MethodSelector (ast.Ast.MethodSelector)5 MethodType (ast.Ast.MethodType)5 Collections (java.util.Collections)5 C (ast.Ast.C)4 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)4 Phase (ast.ExpCore.ClassB.Phase)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 Assertions (tools.Assertions)4 Position (ast.Ast.Position)3