Search in sources :

Example 1 with ClassUnfit

use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit 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);
}
Also used : Path(ast.Ast.Path) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) Method(java.lang.reflect.Method) MethodWithType(ast.ExpCore.ClassB.MethodWithType) PlgInfo(platformSpecific.fakeInternet.PluginWithPart.PlgInfo) PluginWithPart(platformSpecific.fakeInternet.PluginWithPart) Member(ast.ExpCore.ClassB.Member)

Example 2 with ClassUnfit

use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit 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.");
    }
}
Also used : Path(ast.Ast.Path) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) MethodUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit) ClassB(ast.ExpCore.ClassB)

Example 3 with ClassUnfit

use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit 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");
    }
}
Also used : Path(ast.Ast.Path) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) MethodUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit) ClassB(ast.ExpCore.ClassB)

Example 4 with ClassUnfit

use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit 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");
    }
}
Also used : Path(ast.Ast.Path) Doc(ast.Ast.Doc) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) MethodUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit) ClassB(ast.ExpCore.ClassB)

Example 5 with ClassUnfit

use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit 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);
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) UsingInfo(platformSpecific.fakeInternet.PluginWithPart.UsingInfo) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit)

Aggregations

ClassUnfit (is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit)6 Path (ast.Ast.Path)5 ClassB (ast.ExpCore.ClassB)4 MethodUnfit (is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit)4 MethodWithType (ast.ExpCore.ClassB.MethodWithType)2 Doc (ast.Ast.Doc)1 MethodType (ast.Ast.MethodType)1 Type (ast.Ast.Type)1 Member (ast.ExpCore.ClassB.Member)1 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 PluginWithPart (platformSpecific.fakeInternet.PluginWithPart)1 PlgInfo (platformSpecific.fakeInternet.PluginWithPart.PlgInfo)1 UsingInfo (platformSpecific.fakeInternet.PluginWithPart.UsingInfo)1