Search in sources :

Example 21 with NestedClass

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

the class _Aux method onNestedNavigateToPathAndDo.

static ClassB onNestedNavigateToPathAndDo(ClassB cb, List<Ast.C> cs, Function<NestedClass, Optional<NestedClass>> op) {
    assert !cs.isEmpty();
    assert cb != null;
    List<Member> newMs = new ArrayList<>(cb.getMs());
    Ast.C nName = cs.get(0);
    int index = getIndex(newMs, nName);
    checkIndex(index);
    NestedClass nc = (NestedClass) newMs.get(index);
    if (cs.size() > 1) {
        nc = nc.withInner(onNestedNavigateToPathAndDo(wrapCast(nc.getInner()), cs.subList(1, cs.size()), op));
        newMs.set(index, nc);
        return cb.withMs(newMs);
    }
    assert cs.size() == 1;
    Optional<NestedClass> optNc = op.apply(nc);
    if (optNc.isPresent()) {
        newMs.set(index, optNc.get());
    } else {
        newMs.remove(index);
    }
    return cb.withMs(newMs);
}
Also used : Ast(ast.Ast) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member)

Example 22 with NestedClass

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

the class _Aux method isConsistent.

static boolean isConsistent(ClassB cb) {
    int countWalkBy = 0;
    HashSet<String> keys = new HashSet<String>();
    for (Member m : cb.getMs()) {
        if (m instanceof MethodWithType) {
            MethodWithType mwt = (MethodWithType) m;
            String key = mwt.getMs().toString();
            assert !keys.contains(key);
            keys.add(key);
        //assert mwt.getMt().getTDocs().size() == mwt.getMt().getTs().size();
        }
        if (m instanceof NestedClass) {
            NestedClass nc = (NestedClass) m;
            String key = nc.getName().toString();
            assert !keys.contains(key);
            keys.add(key);
            if (nc.getInner() instanceof ExpCore.WalkBy) {
                countWalkBy += 1;
            }
        }
        if (m instanceof MethodImplemented) {
            MethodImplemented mi = (MethodImplemented) m;
            String key = mi.getS().toString();
            assert !keys.contains(key);
            keys.add(key);
        }
    }
    //     || ((cb.getPhase()!=ast.ExpCore.ClassB.Phase.None && !cb.getUniqueId().isEmpty()) );
    assert countWalkBy <= 1 : cb;
    return true;
}
Also used : MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) NestedClass(ast.ExpCore.ClassB.NestedClass) ToString(lombok.ToString) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member) HashSet(java.util.HashSet)

Example 23 with NestedClass

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

the class _Aux method getNested.

static ExpCore.ClassB.NestedClass getNested(ExpCore.ClassB cb, List<Ast.C> cs) {
    assert !cs.isEmpty();
    Ast.C nName = cs.get(0);
    int index = getIndex(cb.getMs(), nName);
    checkIndex(index);
    NestedClass nc = (NestedClass) cb.getMs().get(index);
    if (cs.size() == 1) {
        return nc;
    }
    return getNested(wrapCast(nc.getInner()), cs.subList(1, cs.size()));
}
Also used : Ast(ast.Ast) NestedClass(ast.ExpCore.ClassB.NestedClass)

Example 24 with NestedClass

use of ast.ExpCore.ClassB.NestedClass 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)

Aggregations

NestedClass (ast.ExpCore.ClassB.NestedClass)24 Member (ast.ExpCore.ClassB.Member)18 ArrayList (java.util.ArrayList)16 ClassB (ast.ExpCore.ClassB)12 Ast (ast.Ast)10 MethodWithType (ast.ExpCore.ClassB.MethodWithType)7 Path (ast.Ast.Path)5 ExpCore (ast.ExpCore)4 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)3 PathPath (ast.Util.PathPath)3 EncodingHelper.ensureExtractClassB (auxiliaryGrammar.EncodingHelper.ensureExtractClassB)3 List (java.util.List)3 C (ast.Ast.C)2 Position (ast.Ast.Position)2 Type (ast.Ast.Type)2 Phase (ast.ExpCore.ClassB.Phase)2 CloneVisitor (coreVisitors.CloneVisitor)2 HashSet (java.util.HashSet)2 Doc (ast.Ast.Doc)1 MethodSelector (ast.Ast.MethodSelector)1