use of auxiliaryGrammar.Locator in project L42 by ElvisResearchGroup.
the class RenameAlsoDefinition method visit.
public ClassB.NestedClass visit(ClassB.NestedClass nc) {
//System.out.println("visitNestedClass "+nc.getName());
Locator current = this.getLocator().copy();
current.pushMember(nc);
for (Locator nl : maps.nesteds) {
if (!(nl.getAnnotation() instanceof Ast.C)) {
continue;
}
if (!nl.equals(current)) {
continue;
}
assert nl.getAnnotation() instanceof Ast.C : nl.getAnnotation();
return super.visit(nc.withName((Ast.C) nl.getAnnotation()));
}
return super.visit(nc);
}
use of auxiliaryGrammar.Locator in project L42 by ElvisResearchGroup.
the class RenameAlsoDefinition method potentiallyRenameMethodImplementedHeader.
private MethodWithType potentiallyRenameMethodImplementedHeader(MethodWithType mi) {
assert mi.getMt().isRefine();
ClassB currentCb = this.getLocator().getLastCb();
Program ep = p;
for (ClassB cbi : this.getLocator().getCbs()) {
ep = ep.evilPush(cbi);
}
//List<Path> supers = Program.getAllSupertypes(ep, currentCb);
Path origin = Functions.originDecOf(ep, mi.getMs(), currentCb);
Locator original = this.getLocator().copy();
boolean isOut = original.moveInPath(origin);
if (isOut) {
return mi;
}
for (Locator pMx : maps.selectors) {
assert pMx.kind() == Kind.Method;
MethodSelector s = pMx.getLastMember().match(nc -> {
throw Assertions.codeNotReachable();
}, mimpl -> mimpl.getS(), mt -> mt.getMs());
if (!mi.getMs().equals(s)) {
continue;
}
Locator renamed = pMx.copy();
renamed.toFormerNodeLocator();
if (!original.equals(renamed)) {
return mi;
}
MethodSelector ms2 = (MethodSelector) pMx.getAnnotation();
return mi.withMs(ms2);
}
return mi;
}
use of auxiliaryGrammar.Locator in project L42 by ElvisResearchGroup.
the class RenameUsage method mSToReplaceOrNull.
public MethodSelector mSToReplaceOrNull(MethodSelector original, Path src) {
assert src != null;
List<Locator> filtered = new ArrayList<>();
for (Locator pMx : maps.selectors) {
MethodSelector mii = pMx.getLastMember().match(nc -> {
throw Assertions.codeNotReachable();
}, mi -> mi.getS(), mt -> mt.getMs());
if (original.equals(mii)) {
filtered.add(pMx);
}
}
if (filtered.isEmpty()) {
return null;
}
Locator pathOriginal = this.getLocator().copy();
pathOriginal.toFormerNodeLocator();
//for both ms in methods and in htypes
boolean isIn = pathOriginal.auxMoveInPath(src);
if (!isIn) {
return null;
}
for (Locator pMx : filtered) {
Locator pathDef = pMx.copy();
pathDef.toFormerNodeLocator();
if (!pathDef.equals(pathOriginal)) {
continue;
}
return (MethodSelector) pMx.getAnnotation();
}
return null;
}
use of auxiliaryGrammar.Locator in project L42 by ElvisResearchGroup.
the class CollectedLocatorsMap method from.
public static CollectedLocatorsMap from(Path src, Path dest) {
Locator nl = pathPathToLocator(src, dest);
CollectedLocatorsMap maps = new CollectedLocatorsMap();
maps.nesteds.add(nl);
return maps;
}
use of auxiliaryGrammar.Locator 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;
}
Aggregations