use of ast.Ast.MethodSelector in project L42 by ElvisResearchGroup.
the class InjectionOnSugar method visit.
@Override
public Expression visit(ClassB s) {
Doc doc1 = s.getDoc1();
Header h = (s.isInterface()) ? new Ast.InterfaceHeader() : new Ast.TraitHeader();
List<Type> supertypes = s.getSupertypes();
List<Member> members = new ArrayList<>();
for (ast.ExpCore.ClassB.Member mi : s.getMs()) {
members.add(mi.match(nc -> new Expression.ClassB.NestedClass(nc.getDoc(), nc.getName(), lift(nc.getInner()), nc.getP()), mimpl -> new Expression.ClassB.MethodImplemented(mimpl.getDoc(), mimpl.getS(), lift(mimpl.getInner()), mimpl.getP()), mwt -> {
Doc idoc = mwt.getDoc();
MethodSelector is = mwt.getMs();
MethodType mt = mwt.getMt();
return new Expression.ClassB.MethodWithType(idoc, is, mt, lift(mwt.get_inner()), mwt.getP());
}));
}
return new Expression.ClassB(doc1, h, Collections.emptyList(), supertypes, members, s.getP());
}
use of ast.Ast.MethodSelector in project L42 by ElvisResearchGroup.
the class IsValue method validRightValue.
public boolean validRightValue(ExpCore ec) {
if (!(ec instanceof MCall))
return false;
MCall s = (MCall) ec;
if (!(s.getInner() instanceof EPath)) {
return false;
}
MethodSelector ms = s.getS();
MethodWithType mwt = (MethodWithType) p.extractClassB(((EPath) s.getInner()).getInner())._getMember(ms);
if (mwt.get_inner().isPresent()) {
return false;
}
if (mwt.getMt().getMdf() != ast.Ast.Mdf.Class) {
return false;
}
for (ExpCore ei : s.getEs()) {
if (!isAtom(ei)) {
return false;
}
}
return true;
}
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;
}
use of ast.Ast.MethodSelector 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 ast.Ast.MethodSelector in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method hasPluginUnresponsive.
public static boolean hasPluginUnresponsive(ClassB l) {
//class method T #pluginUnresponsive(Library binaryRepr)
MethodSelector ms = MethodSelector.of("#pluginUnresponsive", Collections.singletonList("binaryRepr"));
MethodWithType mwt = (MethodWithType) l._getMember(ms);
//must be an mwt since normalized
if (mwt == null) {
return false;
}
MethodType mt = mwt.getMt();
if (!mt.getMdf().equals(Mdf.Class)) {
return false;
}
if (!mt.getTs().get(0).equals(Type.immLibrary)) {
return false;
}
if (!mt.getExceptions().isEmpty()) {
return false;
}
if (!mt.getReturnType().getMdf().equals(Mdf.Immutable)) {
return false;
}
//no need to check return type, since is just thrown as error
return true;
}
Aggregations