use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class Rename method redirectDefinition.
private static ClassB redirectDefinition(List<Ast.C> src, List<Ast.C> dest, ClassB lprime) {
assert !src.isEmpty();
assert !dest.isEmpty();
NestedClass nsCb = lprime.getNested(src);
Path toFrom = Path.outer(dest.size() - 1, src.subList(0, src.size() - 1));
ClassB cb = (ClassB) FromInClass.of((ClassB) nsCb.getInner(), toFrom);
List<Member> ms = new ArrayList<>();
ms.add(Functions.encapsulateIn(dest, cb, nsCb.getDoc()));
return ClassB.membersClass(ms, Position.noInfo, lprime.getPhase());
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class RenameMembers method liftP.
@Override
protected Path liftP(Path s) {
if (s.isPrimitive()) {
return s;
}
//System.out.print(" "+s);
assert s.isCore();
List<Ast.C> cs = s.getCBar();
//no need to rename outers
if (cs.isEmpty()) {
return s;
}
Locator current = this.getLocator().copy();
current.toFormerNodeLocator();
boolean canCut = current.cutUpTo(s.outerNumber());
if (!canCut) {
return s;
}
int whereImSize = current.size();
current.addCs(s.getCBar());
for (Locator nl : maps.nesteds) {
if (whereImSize > nl.size()) {
continue;
}
//situation: rename: s1 c1->path current path locator is: whereIm c cs
//check whereImSize<=s1Size and whereIm c cs =s1 _
boolean compatible = current.prefixOf(nl);
if (!compatible) {
continue;
}
//the class name in nl.that
int extraCs = (current.size() - nl.size());
Path pi = getDestPath(this.getLocator().getClassNamesPath().size(), nl, s, extraCs);
//TODO:can be made more efficient without creating the listPaths
return pi;
}
return s;
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class RenameMembers method getDestPath.
private Path getDestPath(int myDept, Locator nl, Path s, int extraCs) {
assert extraCs >= 0 : extraCs;
Path result = null;
if (nl.getAnnotation() instanceof Path) {
result = (Path) nl.getAnnotation();
}
List<Ast.C> cs = s.getCBar();
if (result == null) {
assert nl.getAnnotation() != null;
assert nl.getAnnotation() instanceof String : nl.getAnnotation();
List<Ast.C> newCs = new ArrayList<>(cs);
newCs.set(cs.size() - 1 - extraCs, Ast.C.of((String) nl.getAnnotation()));
return Path.outer(s.outerNumber(), newCs);
}
List<Ast.C> path = cs.subList(cs.size() - extraCs, cs.size());
for (Ast.C si : path) {
result = result.pushC(si);
}
return result.setNewOuter(result.outerNumber() + myDept);
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class Redirect method redirectOkMember.
private static void redirectOkMember(List<PathSPath> ambiguities, List<SPathSPath> exceptions, Member mi, Member miGet, PathSPath current) {
if (mi instanceof NestedClass) {
assert miGet instanceof NestedClass;
assert ((NestedClass) mi).getName().equals(((NestedClass) miGet).getName());
Path src = current.getPath().pushC(((NestedClass) mi).getName());
Path dest = current.getPathsSet().iterator().next().pushC(((NestedClass) mi).getName());
plusEqual(ambiguities, src, Arrays.asList(dest));
return;
}
assert mi.getClass().equals(miGet.getClass());
assert mi instanceof MethodWithType : mi;
MethodWithType mwtSrc = (MethodWithType) mi;
MethodWithType mwtDest = (MethodWithType) miGet;
//this is what happens in p.method
mwtSrc = From.from(mwtSrc, current.getPath());
mwtDest = From.from(mwtDest, current.getPathsSet().iterator().next());
assert mwtSrc.getMs().equals(mwtDest.getMs());
boolean thisMdfOk = mwtSrc.getMt().getMdf().equals(mwtDest.getMt().getMdf());
boolean retOk = redirectOkT(ambiguities, mwtSrc.getMt().getReturnType(), mwtDest.getMt().getReturnType());
List<Integer> parWrong = new ArrayList<Integer>();
{
int i = -1;
for (Type tSrc : mwtSrc.getMt().getTs()) {
i += 1;
Type tDest = mwtDest.getMt().getTs().get(i);
if (!redirectOkT(ambiguities, tSrc, tDest)) {
parWrong.add(i);
}
;
}
}
boolean excOk = plusEqualAndExc(ambiguities, exceptions, current.getPath(), mwtSrc, mwtDest);
if (thisMdfOk && retOk && excOk && parWrong.isEmpty()) {
return;
}
throw Errors42.errorMethodClash(current.getPath().getCBar(), mwtSrc, mwtDest, excOk, parWrong, retOk, thisMdfOk, false);
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class RemoveCode method collectDep.
private static List<List<Ast.C>> collectDep(ClassB depSource, List<Ast.C> origin) {
List<Path> dep = new UsedPaths().of(depSource);
List<List<Ast.C>> result = new ArrayList<>();
for (Path pi : new HashSet<>(dep)) {
if (pi.isPrimitive()) {
continue;
}
Path piF = From.fromP(pi, Path.outer(0, origin));
if (piF.outerNumber() == 0) {
result.add(piF.getCBar());
}
}
return result;
}
Aggregations