use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class Rename method renameMethod.
public static ClassB renameMethod(Program p, ClassB cb, List<Ast.C> path, MethodSelector src, MethodSelector dest) {
Member mem = Errors42.checkExistsPathMethod(cb, path, Optional.of(src));
assert mem instanceof MethodWithType;
Errors42.checkCompatibleMs(path, (MethodWithType) mem, dest);
CollectedLocatorsMap maps = CollectedLocatorsMap.from(Path.outer(0, path), (MethodWithType) mem, dest);
RenameAlsoDefinition ren = new RenameAlsoDefinition(cb, maps, p);
return (ClassB) ren.visit(cb);
}
use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class SumMethods method sumMethods.
public static ClassB sumMethods(ClassB lib, List<Ast.C> path, MethodSelector m1, MethodSelector m2, MethodSelector mRes, String name) {
ClassB pathCb = pathCb(lib, path);
Member mem1 = Errors42.checkExistsPathMethod(lib, path, Optional.of(m1));
Member mem2 = Errors42.checkExistsPathMethod(lib, path, Optional.of(m2));
MethodType mt1 = ((MethodWithType) pathCb._getMember(m1)).getMt();
MethodType mt2 = ((MethodWithType) pathCb._getMember(m2)).getMt();
int index = m2.getNames().indexOf(name);
if (index == -1) {
throw Errors42.errorParameterMismatch(path, mem1, mem2, false, false, false);
}
checkParSize(index, path, m1, m2, mRes, mem1, mem2, mt1, mt2);
MethodType mtU = mtU(index, mt1, mt2);
if (mtU == null) {
throw Errors42.errorParameterMismatch(path, mem1, mem2, isReplacedParOk(index, mt1, mt2), false, true);
}
ExpCore eU = eU(index, mem2.getP(), mt1, mt2, m1, m2, mRes);
MethodWithType mwtU = new MethodWithType(Doc.empty(), mRes, mtU, Optional.of(eU), mem2.getP());
checkConflict(path, mRes, pathCb, mwtU);
boolean replOk = isReplacedParOk(index, mt1, mt2);
if (!replOk) {
throw Errors42.errorParameterMismatch(path, mem1, mem2, false, true, true);
}
return finalResult(lib, path, mwtU);
}
use of ast.ExpCore.ClassB.MethodWithType 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 ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method hasPluginUnresponsive.
public static boolean hasPluginUnresponsive(ClassB l) {
//class method T #pluginUnresponsive(Library binaryRepr)
MethodSelector ms = MethodSelector.of("#pluginUnresponsive", 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().getMdf().equals(Mdf.Immutable)) {
return false;
}
//no need to check return type, since is just thrown as error
return true;
}
use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class Compose method sumMwt.
public static MethodWithType sumMwt(MethodWithType mwt1, MethodWithType mwt2) {
if (mwt1 == null) {
return mwt2;
}
boolean refine = mwt1.getMt().isRefine() || mwt2.getMt().isRefine();
if (!mwt1.getMt().withRefine(false).equals(mwt2.getMt().withRefine(false))) {
assert false;
}
Optional<ExpCore> body = mwt1.get_inner();
if (body.isPresent() && mwt2.get_inner().isPresent()) {
assert false;
}
if (!body.isPresent()) {
body = mwt2.get_inner();
}
MethodWithType mwt = mwt1.withMt(mwt1.getMt().withRefine(refine)).with_inner(body);
return mwt;
}
Aggregations