use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit 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 is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit 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.");
}
}
use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method isOkAsReturn.
private static void isOkAsReturn(Program p, Path csTop, Type ti) throws ClassUnfit, MethodUnfit {
Path pi = ti.getPath();
if (pi.equals(Path.Void())) {
return;
}
//We will need to generate a simpler returning expression
if (pi.equals(Path.Library())) {
return;
}
Path op = _pathForOutside(csTop.getCBar().size(), pi);
if (op == null) {
checkForInside(p.top(), csTop, pi);
return;
}
ClassB l = p.extractClassB(op);
boolean hasIt = hasFrom(l);
boolean phOk = Functions.isComplete(ti);
if (ti.getMdf() == Mdf.Class && !ti.equals(Type.classAny)) {
throw new RefactorErrors.MethodUnfit().msg("Return type can be 'class' only if is exactly 'class any'");
}
if (!hasIt) {
throw new RefactorErrors.ClassUnfit().msg("Class " + op + " has no method #from(binaryRepr)");
}
if (!phOk) {
//TODO: why this limitation?
throw new RefactorErrors.MethodUnfit().msg("Return type can not be fwd");
}
}
use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method checkForInside.
private static void checkForInside(ClassB lTop, Path csTop, Path originalPath) throws ClassUnfit, MethodUnfit {
if (originalPath.isPrimitive()) {
throw new RefactorErrors.MethodUnfit().msg("Method signature not supported:\n parameters can not be Void/Any/fwd.\n" + "returns can not be Any/fwd\n" + "exceptions can not be Any/Void/Library");
}
Path cs = From.fromP(originalPath, csTop);
assert cs.outerNumber() == 0;
List<Ast.C> cBar = cs.getCBar();
ClassB lPointed = lTop.getClassB(cBar);
Doc d = lPointed.getDoc1();
if (d._getParameterForPlugin() == null || d._getParameterForPluginPart() == null) {
throw new RefactorErrors.ClassUnfit().msg("Class " + cBar + " doesnot have @pluginPart annotation");
}
}
use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit 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);
}
Aggregations