Search in sources :

Example 1 with Locator

use of auxiliaryGrammar.Locator in project L42 by ElvisResearchGroup.

the class RenameAlsoDefinition method visit.

public ClassB.NestedClass visit(ClassB.NestedClass nc) {
    //System.out.println("visitNestedClass "+nc.getName());
    Locator current = this.getLocator().copy();
    current.pushMember(nc);
    for (Locator nl : maps.nesteds) {
        if (!(nl.getAnnotation() instanceof Ast.C)) {
            continue;
        }
        if (!nl.equals(current)) {
            continue;
        }
        assert nl.getAnnotation() instanceof Ast.C : nl.getAnnotation();
        return super.visit(nc.withName((Ast.C) nl.getAnnotation()));
    }
    return super.visit(nc);
}
Also used : Locator(auxiliaryGrammar.Locator)

Example 2 with Locator

use of auxiliaryGrammar.Locator 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 3 with Locator

use of auxiliaryGrammar.Locator in project L42 by ElvisResearchGroup.

the class RenameUsage method mSToReplaceOrNull.

public MethodSelector mSToReplaceOrNull(MethodSelector original, Path src) {
    assert src != null;
    List<Locator> filtered = new ArrayList<>();
    for (Locator pMx : maps.selectors) {
        MethodSelector mii = pMx.getLastMember().match(nc -> {
            throw Assertions.codeNotReachable();
        }, mi -> mi.getS(), mt -> mt.getMs());
        if (original.equals(mii)) {
            filtered.add(pMx);
        }
    }
    if (filtered.isEmpty()) {
        return null;
    }
    Locator pathOriginal = this.getLocator().copy();
    pathOriginal.toFormerNodeLocator();
    //for both ms in methods and in htypes
    boolean isIn = pathOriginal.auxMoveInPath(src);
    if (!isIn) {
        return null;
    }
    for (Locator pMx : filtered) {
        Locator pathDef = pMx.copy();
        pathDef.toFormerNodeLocator();
        if (!pathDef.equals(pathOriginal)) {
            continue;
        }
        return (MethodSelector) pMx.getAnnotation();
    }
    return null;
}
Also used : Locator(auxiliaryGrammar.Locator) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList)

Example 4 with Locator

use of auxiliaryGrammar.Locator in project L42 by ElvisResearchGroup.

the class CollectedLocatorsMap method from.

public static CollectedLocatorsMap from(Path src, Path dest) {
    Locator nl = pathPathToLocator(src, dest);
    CollectedLocatorsMap maps = new CollectedLocatorsMap();
    maps.nesteds.add(nl);
    return maps;
}
Also used : Locator(auxiliaryGrammar.Locator)

Example 5 with Locator

use of auxiliaryGrammar.Locator in project L42 by ElvisResearchGroup.

the class RenameMembers method liftP.

@Override
protected Path liftP(Path s) {
    if (s.isPrimitive()) {
        return s;
    }
    //System.out.print("     "+s);
    assert s.isCore();
    List<Ast.C> cs = s.getCBar();
    //no need to rename outers
    if (cs.isEmpty()) {
        return s;
    }
    Locator current = this.getLocator().copy();
    current.toFormerNodeLocator();
    boolean canCut = current.cutUpTo(s.outerNumber());
    if (!canCut) {
        return s;
    }
    int whereImSize = current.size();
    current.addCs(s.getCBar());
    for (Locator nl : maps.nesteds) {
        if (whereImSize > nl.size()) {
            continue;
        }
        //situation: rename: s1 c1->path   current path locator is:  whereIm c cs
        //check whereImSize<=s1Size and  whereIm c cs =s1 _ 
        boolean compatible = current.prefixOf(nl);
        if (!compatible) {
            continue;
        }
        //the class name in nl.that
        int extraCs = (current.size() - nl.size());
        Path pi = getDestPath(this.getLocator().getClassNamesPath().size(), nl, s, extraCs);
        //TODO:can be made more efficient without creating the listPaths
        return pi;
    }
    return s;
}
Also used : PathPath(ast.Util.PathPath) Path(ast.Ast.Path) Locator(auxiliaryGrammar.Locator)

Aggregations

Locator (auxiliaryGrammar.Locator)9 Path (ast.Ast.Path)3 MethodSelector (ast.Ast.MethodSelector)2 ClassB (ast.ExpCore.ClassB)1 PathPath (ast.Util.PathPath)1 CloneWithPath (coreVisitors.CloneWithPath)1 ArrayList (java.util.ArrayList)1 Program (programReduction.Program)1