Search in sources :

Example 1 with UnresolvedOverloading

use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.UnresolvedOverloading in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method usingMethod.

private static UsingInfo usingMethod(PlgInfo plgInfo, Method[] jms, MethodWithType mwt, String name) throws UnresolvedOverloading {
    List<Method> jms0 = new ArrayList<>();
    for (Method mi : jms) {
        if (!mi.getName().equals(name)) {
            continue;
        }
        if (argLessPData(mi) != mwt.getMs().getNames().size()) {
            continue;
        }
        jms0.add(mi);
    }
    if (jms0.size() != 1) {
        throw new RefactorErrors.UnresolvedOverloading().msg("The referred java class " + plgInfo.plgClass.getName() + " does not have exactly one method for " + name + " with right number of arguments.\n" + "List of candidate methods:" + jms0);
    }
    assert jms0.size() == 1 : jms0.size();
    Method jm = jms0.get(0);
    UsingInfo ui = new UsingInfo(plgInfo, jm);
    return ui;
}
Also used : UsingInfo(platformSpecific.fakeInternet.PluginWithPart.UsingInfo) ArrayList(java.util.ArrayList) UnresolvedOverloading(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.UnresolvedOverloading) Method(java.lang.reflect.Method)

Example 2 with UnresolvedOverloading

use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.UnresolvedOverloading 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 3 with UnresolvedOverloading

use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.UnresolvedOverloading in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method usingConstructor.

private static UsingInfo usingConstructor(PlgInfo plgInfo, Constructor<?>[] jcs, MethodWithType mwt, String name) throws UnresolvedOverloading {
    List<Constructor<?>> jcs0 = new ArrayList<>();
    for (Constructor<?> mi : jcs) {
        if (argLessPData(mi) != mwt.getMs().getNames().size()) {
            continue;
        }
        jcs0.add(mi);
    }
    if (jcs0.size() != 1) {
        throw new RefactorErrors.UnresolvedOverloading().msg("The referred java class " + plgInfo.plgClass.getName() + " does not have exactly one constructor with right number of arguments.\n" + "List of candidate constructors:" + jcs0);
    }
    assert jcs0.size() == 1 : jcs0.size();
    Constructor<?> jc = jcs0.get(0);
    UsingInfo ui = new UsingInfo(plgInfo, jc);
    return ui;
}
Also used : UsingInfo(platformSpecific.fakeInternet.PluginWithPart.UsingInfo) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) UnresolvedOverloading(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.UnresolvedOverloading)

Example 4 with UnresolvedOverloading

use of is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.UnresolvedOverloading 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

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