Search in sources :

Example 51 with Member

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

the class _Aux method withMember.

static ClassB withMember(ClassB cb, Member m) {
    assert cb.isConsistent();
    List<Member> newMs = new java.util.ArrayList<>(cb.getMs());
    int index = _Aux.getIndex(newMs, m);
    if (index == -1) {
        newMs.add(m);
    } else {
        newMs.set(index, m);
    }
    ClassB result = cb.withMs(newMs);
    return result;
}
Also used : ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 52 with Member

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

the class Redirect method remove.

public static ClassB remove(Path path1, ClassB l) {
    if (path1.equals(Path.outer(0))) {
        return ClassB.membersClass(Collections.emptyList(), Position.noInfo, l.getPhase());
    }
    return (ClassB) l.accept(new coreVisitors.CloneVisitor() {

        List<Ast.C> cs = path1.getCBar();

        public List<Member> liftMembers(List<Member> s) {
            List<Member> result = new ArrayList<Member>();
            for (Member m : s) {
                m.match(nc -> manageNC(nc, result), mi -> result.add(liftM(m)), mt -> result.add(liftM(m)));
            }
            return result;
        }

        private boolean manageNC(NestedClass nc, List<Member> result) {
            assert !cs.isEmpty();
            Ast.C top = cs.get(0);
            //out of path
            if (!top.equals(nc.getName())) {
                return result.add(nc);
            }
            if (cs.size() == 1) {
                return true;
            }
            List<Ast.C> csLocal = cs;
            cs = cs.subList(1, cs.size());
            try {
                return result.add(this.visit(nc));
            } finally {
                cs = csLocal;
            }
        }
    });
}
Also used : Ast(ast.Ast) C(ast.Ast.C) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB) C(ast.Ast.C)

Example 53 with Member

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

the class ExtractInfo method auxCollectPrivateMethodsOfPublicPaths.

private static void auxCollectPrivateMethodsOfPublicPaths(ClassB cb, List<PathMx> accumulator, List<Ast.C> prefix) {
    for (Member m : cb.getMs()) {
        m.match(nc -> {
            if (nc.getName().isUnique()) {
                return null;
            }
            List<Ast.C> newPrefix = new ArrayList<>(prefix);
            newPrefix.add(nc.getName());
            auxCollectPrivateMethodsOfPublicPaths((ClassB) nc.getInner(), accumulator, newPrefix);
            return null;
        }, mi -> null, mt -> {
            if (!mt.getMs().isUnique()) {
                return null;
            }
            accumulator.add(new PathMx(Path.outer(0, prefix), mt.getMs()));
            return null;
        });
    }
}
Also used : PathMx(ast.Util.PathMx) ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member)

Example 54 with Member

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

the class MethodPathCloneVisitor method getMt.

private Ast.MethodType getMt(Program p, MethodSelector s, ClassB cb) {
    assert p.top() == cb;
    Optional<Member> mOpt = Functions.getIfInDom(cb.getMs(), s);
    assert mOpt.isPresent();
    if (mOpt.get() instanceof MethodWithType) {
        return ((MethodWithType) mOpt.get()).getMt();
    }
    assert mOpt.get() instanceof MethodImplemented;
    MethodWithType mwt = (MethodWithType) cb._getMember(s);
    return mwt.getMt();
}
Also used : MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) 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