use of ast.Util.PathMx 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.Util.PathMx in project L42 by ElvisResearchGroup.
the class Abstract method checkPrivacyCoupuled.
static void checkPrivacyCoupuled(ClassB cbFull, ClassB cbClear, List<Ast.C> path) {
//start from a already cleared out of private states
//check if all private nested classes are USED using IsUsed on cbClear
//this also verify that no private nested classes are used as
//type in public methods of public classes.
//collect all PublicPath.privateMethod
//use main->introspection.FindUsage
List<Path> prPath = ExtractInfo.collectPrivatePathsAndSubpaths(cbFull, path);
List<PathMx> prMeth = ExtractInfo.collectPrivateMethodsOfPublicPaths(cbFull, path);
List<Path> coupuledPaths = new ArrayList<>();
for (Path pi : prPath) {
Set<Path> used = ExtractInfo.IsUsed.of(cbClear, pi);
if (used.isEmpty()) {
continue;
}
coupuledPaths.add(pi);
}
List<PathMx> ordered = new ArrayList<>();
try {
//FindUsage.of(Program.empty(),prMeth, cbClear);
Set<PathMx> usedPrMeth = findUsage(prMeth, cbClear);
if (coupuledPaths.isEmpty() && usedPrMeth.isEmpty()) {
return;
}
ordered.addAll(usedPrMeth);
} catch (PathMetaOrNonExistant pne) {
assert !coupuledPaths.isEmpty();
}
Collections.sort(ordered, (px1, px2) -> px1.toString().compareTo(px2.toString()));
throw Errors42.errorPrivacyCoupuled(coupuledPaths, ordered);
}
use of ast.Util.PathMx in project L42 by ElvisResearchGroup.
the class Abstract method findUsage.
private static Set<PathMx> findUsage(List<PathMx> prMeth, ClassB cbClear) {
Set<PathMx> result = new HashSet<>();
for (PathMx pmx : prMeth) {
assert pmx.getPath().outerNumber() == 0;
UserForMethodResult res = Rename.userForMethod(Resources.getP(), /*wasEmpty*/
cbClear, pmx.getPath().getCBar(), pmx.getMs(), false);
result.addAll(res.asClient);
res.asThis.stream().map(e -> new PathMx(Path.outer(0), e)).forEach(result::add);
}
return result;
}
use of ast.Util.PathMx 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;
});
}
}
Aggregations