Search in sources :

Example 1 with Path

use of ast.Ast.Path in project L42 by ElvisResearchGroup.

the class FindPathUsage method visit.

public ExpCore visit(ClassB s) {
    Path oldP = searchingFor;
    searchingFor = searchingFor.setNewOuter(searchingFor.outerNumber() + 1);
    try {
        return super.visit(s);
    } finally {
        searchingFor = oldP;
    }
}
Also used : Path(ast.Ast.Path)

Example 2 with Path

use of ast.Ast.Path in project L42 by ElvisResearchGroup.

the class Rename method renameUsage.

//TODO: replace with same mechanism of private normalization when is completed
static ClassB renameUsage(List<PathPath> mapPath, ClassB cb) {
    return (ClassB) cb.accept(new coreVisitors.CloneWithPath() {

        @Override
        protected Path liftP(Path s) {
            if (s.isPrimitive()) {
                return s;
            }
            assert s.isCore();
            List<Ast.C> path = this.getLocator().getClassNamesPath();
            if (s.outerNumber() > path.size()) {
                return s;
            }
            //in usedPath similar thing.
            List<Ast.C> unexploredPath = path.subList(0, path.size() - s.outerNumber());
            //we are in a class literal in a method and we look inside
            if (unexploredPath.contains(null)) {
                return s;
            }
            if (s.outerNumber() > path.size()) {
                return s;
            }
            List<Ast.C> topView = ClassOperations.toTop(path, s);
            for (PathPath pp : mapPath) {
                List<Ast.C> src = pp.getPath1().getCBar();
                if (topView.size() < src.size()) {
                    continue;
                }
                if (topView.equals(src)) {
                    if (pp.getPath2().isPrimitive()) {
                        return pp.getPath2();
                    }
                    if (pp.getPath2().outerNumber() == 0) {
                        return ClassOperations.normalizePath(path, path.size(), pp.getPath2().getCBar());
                    }
                    return pp.getPath2().setNewOuter(pp.getPath2().outerNumber() + path.size());
                }
                List<Ast.C> trimmedTop = topView.subList(0, src.size());
                if (trimmedTop.equals(src)) {
                    List<Ast.C> elongatedDest = new ArrayList<>(pp.getPath2().getCBar());
                    elongatedDest.addAll(topView.subList(src.size(), topView.size()));
                    if (pp.getPath2().outerNumber() == 0) {
                        return ClassOperations.normalizePath(path, path.size(), elongatedDest);
                    } else {
                        return Path.outer(pp.getPath2().outerNumber() + path.size(), elongatedDest);
                    }
                }
            }
            return s;
        }
    });
}
Also used : PathPath(ast.Util.PathPath) Path(ast.Ast.Path) C(ast.Ast.C) PathPath(ast.Util.PathPath) ArrayList(java.util.ArrayList)

Example 3 with Path

use of ast.Ast.Path in project L42 by ElvisResearchGroup.

the class RenameAlsoDefinition method potentiallyRenameMethodImplementedHeader.

private MethodWithType potentiallyRenameMethodImplementedHeader(MethodWithType mi) {
    assert mi.getMt().isRefine();
    ClassB currentCb = this.getLocator().getLastCb();
    Program ep = p;
    for (ClassB cbi : this.getLocator().getCbs()) {
        ep = ep.evilPush(cbi);
    }
    //List<Path> supers = Program.getAllSupertypes(ep, currentCb);
    Path origin = Functions.originDecOf(ep, mi.getMs(), currentCb);
    Locator original = this.getLocator().copy();
    boolean isOut = original.moveInPath(origin);
    if (isOut) {
        return mi;
    }
    for (Locator pMx : maps.selectors) {
        assert pMx.kind() == Kind.Method;
        MethodSelector s = pMx.getLastMember().match(nc -> {
            throw Assertions.codeNotReachable();
        }, mimpl -> mimpl.getS(), mt -> mt.getMs());
        if (!mi.getMs().equals(s)) {
            continue;
        }
        Locator renamed = pMx.copy();
        renamed.toFormerNodeLocator();
        if (!original.equals(renamed)) {
            return mi;
        }
        MethodSelector ms2 = (MethodSelector) pMx.getAnnotation();
        return mi.withMs(ms2);
    }
    return mi;
}
Also used : Path(ast.Ast.Path) Locator(auxiliaryGrammar.Locator) MethodSelector(ast.Ast.MethodSelector) Program(programReduction.Program) ClassB(ast.ExpCore.ClassB)

Example 4 with Path

use of ast.Ast.Path 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 5 with Path

use of ast.Ast.Path 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)

Aggregations

Path (ast.Ast.Path)56 ClassB (ast.ExpCore.ClassB)28 ArrayList (java.util.ArrayList)23 Ast (ast.Ast)14 PathPath (ast.Util.PathPath)13 Type (ast.Ast.Type)12 MethodWithType (ast.ExpCore.ClassB.MethodWithType)12 Doc (ast.Ast.Doc)11 Member (ast.ExpCore.ClassB.Member)11 List (java.util.List)11 ExpCore (ast.ExpCore)10 NestedClass (ast.ExpCore.ClassB.NestedClass)8 PathSPath (ast.Util.PathSPath)8 CloneWithPath (coreVisitors.CloneWithPath)8 Collections (java.util.Collections)8 HashSet (java.util.HashSet)8 Program (programReduction.Program)8 Map (tools.Map)8 MethodSelector (ast.Ast.MethodSelector)7 SPathSPath (ast.Util.SPathSPath)7