use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class FindPathUsage method visit.
public ExpCore visit(ClassB s) {
Path oldP = searchingFor;
searchingFor = searchingFor.setNewOuter(searchingFor.outerNumber() + 1);
try {
return super.visit(s);
} finally {
searchingFor = oldP;
}
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class Rename method renameUsage.
//TODO: replace with same mechanism of private normalization when is completed
static ClassB renameUsage(List<PathPath> mapPath, ClassB cb) {
return (ClassB) cb.accept(new coreVisitors.CloneWithPath() {
@Override
protected Path liftP(Path s) {
if (s.isPrimitive()) {
return s;
}
assert s.isCore();
List<Ast.C> path = this.getLocator().getClassNamesPath();
if (s.outerNumber() > path.size()) {
return s;
}
//in usedPath similar thing.
List<Ast.C> unexploredPath = path.subList(0, path.size() - s.outerNumber());
//we are in a class literal in a method and we look inside
if (unexploredPath.contains(null)) {
return s;
}
if (s.outerNumber() > path.size()) {
return s;
}
List<Ast.C> topView = ClassOperations.toTop(path, s);
for (PathPath pp : mapPath) {
List<Ast.C> src = pp.getPath1().getCBar();
if (topView.size() < src.size()) {
continue;
}
if (topView.equals(src)) {
if (pp.getPath2().isPrimitive()) {
return pp.getPath2();
}
if (pp.getPath2().outerNumber() == 0) {
return ClassOperations.normalizePath(path, path.size(), pp.getPath2().getCBar());
}
return pp.getPath2().setNewOuter(pp.getPath2().outerNumber() + path.size());
}
List<Ast.C> trimmedTop = topView.subList(0, src.size());
if (trimmedTop.equals(src)) {
List<Ast.C> elongatedDest = new ArrayList<>(pp.getPath2().getCBar());
elongatedDest.addAll(topView.subList(src.size(), topView.size()));
if (pp.getPath2().outerNumber() == 0) {
return ClassOperations.normalizePath(path, path.size(), elongatedDest);
} else {
return Path.outer(pp.getPath2().outerNumber() + path.size(), elongatedDest);
}
}
}
return s;
}
});
}
use of ast.Ast.Path 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 ast.Ast.Path in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method plgComplete1.
public static ClassB plgComplete1(List<Ast.C> cs, Program p, ClassB l) throws UnresolvedOverloading, ClassUnfit, MethodUnfit {
PluginWithPart pwp = OnLineCode._isPluginWithPart(l.getDoc1());
if (pwp == null) {
return l;
}
PlgInfo plgInfo = new PlgInfo(l.getDoc1());
if (!hasPluginUnresponsive(l)) {
throw new RefactorErrors.ClassUnfit().msg("Class " + Path.outer(0, cs) + " does not contain method #pluginUnresponsive(binaryRepr)");
}
Class<?> c = pwp.pointed;
Method[] jms = c.getMethods();
Constructor<?>[] jcs = c.getDeclaredConstructors();
List<Member> msResult = new ArrayList<>(templateWrapper);
Path pTop = Path.outer(0, cs);
for (Member m : l.getMs()) {
if (!(m instanceof MethodWithType)) {
msResult.add(m);
continue;
}
MethodWithType mwt = (MethodWithType) m;
if (mwt.get_inner().isPresent()) {
msResult.add(mwt);
continue;
}
addMwt(p, plgInfo, jms, jcs, msResult, pTop, mwt);
}
return l.withMs(msResult);
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method isOkAsParameter.
private static void isOkAsParameter(Program p, Path csTop, Type ti) throws ClassUnfit, MethodUnfit {
Path pi = ti.getPath();
//class parameters are ok, and we just omit the .#binaryRepr() call
if (ti.getMdf() == Mdf.Class) {
return;
}
//Libraries are ok and we just omit the .#binaryRepr() call
if (pi.equals(Path.Library())) {
return;
}
Path op = _pathForOutside(csTop.getCBar().size(), pi);
if (op == null) {
checkForInside(p.top(), csTop, pi);
return;
}
//TODO: since p.top is topL, is it ok this extraction?
ClassB l = p.extractClassB(op);
boolean hasIt = hasBinaryRepr(l);
boolean phOk = Functions.isComplete(ti);
if (!hasIt) {
throw new RefactorErrors.ClassUnfit().msg("Class " + op + " has no #binaryRepr() method");
}
if (!phOk) {
throw new RefactorErrors.MethodUnfit().msg("Fwd types not allowed.");
}
}
Aggregations