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);
}
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;
}
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()));
}
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;
}
}
});
}
Aggregations