use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class RenameAlsoDefinition method liftMembers.
public List<Member> liftMembers(List<Member> s) {
List<Member> result1 = super.liftMembers(s);
List<Member> result2 = new ArrayList<>();
for (Member m : result1) {
Optional<Member> optM = Functions.getIfInDom(result2, m);
if (!optM.isPresent()) {
result2.add(m);
continue;
}
Member m2 = optM.get();
result2.remove(m2);
assert m.getClass() == m2.getClass();
_Sum.doubleSimmetricalMatch(null, /*boh, null program, does it breaks?*/
visitStart, visitStart, result2, this.getLocator().getClassNamesPath(), m, m2);
//remove clashes here
}
return result2;
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class RemoveCode method addDep.
private static ClassB addDep(ClassB accumulator, List<Ast.C> path, ClassB originalCb) {
if (path.isEmpty()) {
return mergeNestedHolderWithDep(accumulator, originalCb);
}
Ast.C firstName = path.get(0);
//either fistName does not exist in accumulator, and we call removeAllButPath
//or we have to continue recursivelly.
Optional<Member> optM = Functions.getIfInDom(accumulator.getMs(), firstName);
NestedClass originalNc = (NestedClass) Functions.getIfInDom(originalCb.getMs(), firstName).get();
ClassB newInner;
if (!optM.isPresent()) {
newInner = removeAllButPath(path.subList(1, path.size()), (ClassB) originalNc.getInner());
} else {
NestedClass accumulatorNc = (NestedClass) optM.get();
newInner = addDep((ClassB) accumulatorNc.getInner(), path.subList(1, path.size()), (ClassB) originalNc.getInner());
}
NestedClass nc = originalNc.withInner(newInner);
List<Member> ms = new ArrayList<>(accumulator.getMs());
Functions.replaceIfInDom(ms, nc);
return accumulator.withMs(ms);
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class Rename method userForMethod.
public static UserForMethodResult userForMethod(Program p, ClassB cb, List<Ast.C> path, MethodSelector src, boolean checkMethExists) {
if (checkMethExists) {
Member mem = Errors42.checkExistsPathMethod(cb, path, Optional.of(src));
assert mem instanceof MethodWithType;
}
Member mem = new ExpCore.ClassB.MethodImplemented(Doc.empty(), src, new ExpCore._void(), Position.noInfo);
CollectedLocatorsMap maps = CollectedLocatorsMap.from(Path.outer(0, path), mem, src);
HashSet<PathMx> result1 = new HashSet<>();
HashSet<MethodSelector> result2 = new HashSet<>();
MethodPathCloneVisitor ren = new RenameUsage(cb, maps, p) {
public Ast.Type liftT(Ast.Type t) {
return t;
}
@Override
protected MethodSelector liftMs(MethodSelector ms) {
return ms;
}
@Override
protected MethodSelector liftMsInMetDec(MethodSelector ms) {
return ms;
}
public ExpCore visit(MCall s) {
List<Ast.C> localPath = this.getLocator().getClassNamesPath();
if (!localPath.equals(path)) {
return super.visit(s);
}
if (s.getInner().equals(Path.outer(0)) || s.getInner().equals(new ExpCore.X(Position.noInfo, "this"))) {
result2.add(s.getS());
return s.withInner(s.getInner().accept(this)).withEs(Map.of(e -> e.accept(this), s.getEs()));
}
return super.visit(s);
}
@Override
public MethodSelector visitMS(MethodSelector original, Path src) {
MethodSelector toCollect = this.mSToReplaceOrNull(original, src);
if (toCollect == null) {
return original;
}
Member m = this.getLocator().getLastMember();
assert !(m instanceof NestedClass) : "";
MethodSelector msUser = m.match(nc -> {
throw Assertions.codeNotReachable();
}, mi -> mi.getS(), mt -> mt.getMs());
Path pathUser = Path.outer(0, this.getLocator().getClassNamesPath());
result1.add(new PathMx(pathUser, msUser));
return original;
}
};
ren.visit(cb);
return new UserForMethodResult() {
{
asClient = new ArrayList<>(result1);
asThis = new ArrayList<>(result2);
}
};
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class TranslateClass method getPhNestedNotIntantiable.
private static void getPhNestedNotIntantiable(String s, ClassB cb, StringBuilder res, boolean isInterface) {
if (isInterface) {
res.append("public static final class Ph implements ");
res.append(s + ", platformSpecific.javaTranslation.Resources.PhI<" + s + ">{\n");
} else {
res.append("public static final class Ph extends ");
res.append(s + " implements platformSpecific.javaTranslation.Resources.PhI<" + s + ">{\n");
}
res.append(" private final java.util.ArrayList<java.util.function.Consumer<" + s + ">> actions=new java.util.ArrayList<>();\n");
res.append(" public void commit(" + s + " val){ for(java.util.function.Consumer<" + s + "> r:actions){r.accept(val);} }");
res.append(" public void addAction(java.util.function.Consumer<" + s + "> r){actions.add(r);}");
res.append(" public ast.ExpCore revert()");
res.append("{throw new Error(\"PhInvocation\");}\n");
for (Member m : cb.getMs()) {
MethodWithType mt = (MethodWithType) m;
getMethodHeader(mt, res);
res.append("{throw new Error(\"PhInvocation\");}\n");
}
res.append(" public Ph(){ }\n }\n");
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class TranslateClass method getIType.
private static void getIType(String s, ClassB cb, StringBuilder res) {
res.append("public static final " + s + " type=new " + s + "(){\n");
getITReverter(s, res);
for (Member m : cb.getMs()) {
MethodWithType mt = (MethodWithType) m;
getMethodHeader(mt, res);
res.append("{throw new Error(\"" + "Calling an interface method" + ":" + mt.getMs() + "\");}\n");
}
res.append("};\n");
}
Aggregations