Search in sources :

Example 1 with UsingInfo

use of platformSpecific.fakeInternet.PluginWithPart.UsingInfo 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 UsingInfo

use of platformSpecific.fakeInternet.PluginWithPart.UsingInfo 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 3 with UsingInfo

use of platformSpecific.fakeInternet.PluginWithPart.UsingInfo 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

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