use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class _Sum method matchMt.
private static Void matchMt(List<Ast.C> pathForError, MethodWithType mwta, List<Member> ms, Member mb) {
if (mb instanceof MethodImplemented) {
throw Errors42.errorMethodClash(pathForError, mwta, mb, false, Collections.emptyList(), false, false, false);
}
MethodWithType mwtb = (MethodWithType) mb;
Errors42.checkMethodClash(pathForError, mwta, mwtb, false);
ms.add(_Sum.sumMethod(mwta, mwtb));
return null;
}
use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method hasFrom.
public static boolean hasFrom(ClassB l) {
// class method mut This0 #from(Library binaryRepr)
MethodSelector ms = MethodSelector.of("#from", 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().equals(Type.mutThis0)) {
return false;
}
return true;
}
use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method addMwt.
private static void addMwt(Program p, PlgInfo plgInfo, Method[] jms, Constructor<?>[] jcs, List<Member> msResult, Path pTop, MethodWithType mwt) throws UnresolvedOverloading, ClassUnfit, MethodUnfit {
//checks
try {
isOkAsReturn(p, pTop, mwt.getMt().getReturnType());
for (Type ti : mwt.getMt().getExceptions()) {
isOkAsException(p, pTop, ti.getPath());
}
for (Type ti : mwt.getMt().getTs()) {
isOkAsParameter(p, pTop, ti);
}
//TODO: we may want to cache those tests if performance is needed
} catch (ClassUnfit | MethodUnfit e) {
e.setMessage("While examining Class " + pTop + " method " + mwt.getMs() + ":\n" + e.getMessage());
throw e;
}
//add to msResult
//TODO: add behaviour if mwt have special comment to define specific ms for use
String name = mwt.getMs().nameToS();
if (name.startsWith("#")) {
name = name.substring(1);
}
UsingInfo ui;
if (!name.equals("new") && !name.equals("apply"))
ui = usingMethod(plgInfo, jms, mwt, name);
else
ui = usingConstructor(plgInfo, jcs, mwt, name);
MethodWithType tu = updateTemplateUsing(ui, mwt);
msResult.add(tu);
}
use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method hasBinaryRepr.
public static boolean hasBinaryRepr(ClassB l) {
//read method Library #binaryRepr()
MethodSelector ms = MethodSelector.of("#binaryRepr", Collections.emptyList());
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.Readable)) {
return false;
}
if (!mt.getTs().isEmpty()) {
return false;
}
if (!mt.getExceptions().isEmpty()) {
return false;
}
if (!mt.getReturnType().equals(Type.immLibrary)) {
return false;
}
return true;
}
use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method hasExceptionIf.
public static boolean hasExceptionIf(ClassB l) {
//class method Void #exceptionIf(Library binaryRepr) exception This
MethodSelector ms = MethodSelector.of("#exceptionIf", 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().size() != 1) {
return false;
}
if (!mt.getExceptions().get(0).equals(Path.outer(0))) {
return false;
}
if (!mt.getReturnType().equals(Type.immVoid)) {
return false;
}
//no need to check return type, since is just thrown as error
return true;
}
Aggregations