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;
}
use of ast.Ast.MethodSelector in project L42 by ElvisResearchGroup.
the class TestSumMethod method test.
@Test
public void test() {
TestHelper.configureForTest();
ClassB cb = getClassB(_cb);
Path path = Path.parse(_path);
MethodSelector ms1 = MethodSelector.parse(_ms1);
MethodSelector ms2 = MethodSelector.parse(_ms2);
MethodSelector ms3 = MethodSelector.parse(_ms3);
ClassB expected = getClassB(_expected);
if (!isError) {
ClassB res = SumMethods.sumMethods(cb, path.getCBar(), ms1, ms2, ms3, name);
TestHelper.assertEqualExp(expected, res);
} else {
try {
ClassB res = SumMethods.sumMethods(cb, path.getCBar(), ms1, ms2, ms3, name);
fail("error expected");
} catch (Resources.Error err) {
ClassB res = (ClassB) err.unbox;
TestHelper.assertEqualExp(expected, res);
}
}
}
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;
}
Aggregations