use of ast.Ast.Path 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.Ast.Path in project L42 by ElvisResearchGroup.
the class TranslateClass method getClassOpen.
private static boolean getClassOpen(String s, ClassB ct, StringBuilder res) {
boolean isInterface = ct.isInterface();
res.append("public ");
if (isInterface) {
res.append("interface ");
if (!ct.getDoc1().isEmpty()) {
res.append("/*" + ct.getDoc1().toString() + "*/");
}
} else {
res.append("class ");
}
res.append(s);
System.out.println("creating class " + s);
if (isInterface) {
res.append(" extends ");
} else {
res.append(" implements ");
}
res.append("platformSpecific.javaTranslation.Resources.Revertable");
Set<String> supt = new HashSet<>();
for (Path pi : ct.getSuperPaths()) /*getStage().getInheritedPaths()*/
{
if (pi.equals(Path.Any())) {
continue;
}
assert !pi.isPrimitive();
String resName = Resources.nameOf(pi);
if (resName.equals("Object")) {
continue;
}
boolean notThere = supt.add(resName);
if (notThere) {
res.append(", ");
res.append(resName);
}
}
return isInterface;
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class TranslateExpression method visit.
//not a propagator visitor.
@Override
public Void visit(ExpCore.EPath s) {
Path ss = s.getInner();
if (ss.isPrimitive()) {
if (ss.equals(Path.Any())) {
res.append("platformSpecific.javaTranslation.Resources.Any.type");
}
if (ss.equals(Path.Library())) {
res.append("platformSpecific.javaTranslation.Resources.Library.type");
}
if (ss.equals(Path.Void())) {
res.append("platformSpecific.javaTranslation.Resources.Void.type");
}
return null;
}
ClassB cbs = Resources.getP().extractClassB(ss);
if (cbs.getPhase() == Phase.Coherent && IsCompiled.of(cbs)) {
res.append(Resources.nameOf(ss) + ".type ");
} else {
Position pos = Resources.getP().get(ss.outerNumber()).getP();
int hash = System.identityHashCode(pos);
String cs = s.toString();
int dotPos = cs.indexOf(".");
assert dotPos >= 0;
cs = cs.substring(dotPos);
res.append("platformSpecific.javaTranslation.Resources.fromHash(" + hash + ",\"" + cs + "\")");
}
return null;
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class TestRename method testNormalizePath.
@Test
public void testNormalizePath() {
Path res = ClassOperations.normalizePath(Arrays.asList(), 0, Arrays.asList());
Assert.assertEquals(res, Path.outer(0));
res = ClassOperations.normalizePath(Arrays.asList(C.of("A")), 1, Arrays.asList(C.of("B")));
Assert.assertEquals(res, Path.parse("This1.B"));
res = ClassOperations.normalizePath(Arrays.asList(C.of("B")), 1, Arrays.asList(C.of("B")));
Assert.assertEquals(res, Path.parse("This0"));
}
use of ast.Ast.Path 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);
}
Aggregations