use of ast.Ast.MethodSelector in project L42 by ElvisResearchGroup.
the class Plugin method MrenameMethod£xthat£xpath£xsrc£xdest.
@ActionType({ ActionType.NormType.Library, ActionType.NormType.Library, ActionType.NormType.Library, ActionType.NormType.Library, ActionType.NormType.Library })
public Object MrenameMethod£xthat£xpath£xsrc£xdest(Object _that, Object _path, Object _src, Object _dest) {
ClassB that = ensureExtractClassB(_that);
List<Ast.C> path = PathAux.parseValidCs(ensureExtractStringU(_path));
MethodSelector src = MethodSelector.parse(ensureExtractStringU(_src));
MethodSelector dest = MethodSelector.parse(ensureExtractStringU(_dest));
return Rename.renameMethod(Resources.getP(), that, path, src, dest);
}
use of ast.Ast.MethodSelector in project L42 by ElvisResearchGroup.
the class RefreshUniqueNames method refreshTopLevel.
public static ClassB refreshTopLevel(ClassB e) {
HashMap<Long, Long> map = new HashMap<>();
return (ClassB) e.accept(new coreVisitors.CloneVisitor() {
protected MethodSelector liftMs(MethodSelector ms) {
return ms.withUniqueNum(newN(map, ms.getUniqueNum()));
}
public ClassB.NestedClass visit(ClassB.NestedClass nc) {
long newN = newN(map, nc.getName().getUniqueNum());
return super.visit(nc.withName(nc.getName().withUniqueNum(newN)));
//I need to collect the DECLARED C,ms and those are the only that I need to refresh.
//refresh all can work only at top level
}
@Override
protected Path liftP(Path s) {
if (s.isPrimitive()) {
return s;
}
List<C> cs = s.getCBar();
List<C> newCs = new ArrayList<>();
for (C c : cs) {
newCs.add(c.withUniqueNum(newN(map, c.getUniqueNum())));
}
return Path.outer(s.outerNumber(), newCs);
}
});
}
use of ast.Ast.MethodSelector in project L42 by ElvisResearchGroup.
the class RefreshUniqueNames method refresh.
@SuppressWarnings("unchecked")
public static <T extends ExpCore> T refresh(T e) {
HashMap<Long, Long> map = new HashMap<>();
//load up maps
e.accept(new coreVisitors.PropagatorVisitor() {
public void visit(ClassB.MethodWithType mwt) {
MethodSelector ms = mwt.getMs();
newN(map, ms.getUniqueNum());
super.visit(mwt);
return;
}
public void visit(ClassB.NestedClass nc) {
newN(map, nc.getName().getUniqueNum());
super.visit(nc);
}
});
return (T) e.accept(new coreVisitors.CloneVisitor() {
protected MethodSelector liftMs(MethodSelector ms) {
return ms.withUniqueNum(mappedN(map, ms.getUniqueNum()));
}
public ClassB.NestedClass visit(ClassB.NestedClass nc) {
C name = nc.getName().withUniqueNum(mappedN(map, nc.getName().getUniqueNum()));
return super.visit(nc.withName(name));
}
@Override
protected Path liftP(Path s) {
if (s.isPrimitive()) {
return s;
}
List<C> cs = s.getCBar();
List<C> newCs = new ArrayList<>();
for (C c : cs) {
newCs.add(c.withUniqueNum(mappedN(map, c.getUniqueNum())));
}
return Path.outer(s.outerNumber(), newCs);
}
});
}
use of ast.Ast.MethodSelector in project L42 by ElvisResearchGroup.
the class Desugar method generateGetter.
private static MethodWithType generateGetter(Expression.Position pos, FieldDec f, Doc doc) {
Type fieldNt = (Type) f.getT();
fieldNt = TypeManipulation.noFwd(fieldNt);
Mdf mdf = fieldNt.getMdf();
if (mdf == Mdf.Capsule || mdf == Mdf.Mutable || mdf == Mdf.Lent) {
fieldNt = fieldNt.withMdf(Mdf.Readable);
}
MethodType mti = new MethodType(false, Mdf.Readable, Collections.emptyList(), fieldNt, Collections.emptyList());
String name = f.getName();
//if(name.startsWith("#")){name=name.substring(1);}
MethodSelector msi = MethodSelector.of(name, Collections.emptyList());
MethodWithType mwt = new MethodWithType(doc, msi, mti, Optional.empty(), pos);
return mwt;
}
use of ast.Ast.MethodSelector 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;
}
Aggregations