Search in sources :

Example 46 with Member

use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.

the class Abstract method auxToAbstract.

private static ClassB auxToAbstract(Program p, ClassB cb, List<Ast.C> pathForError, MethodSelector sel, MethodSelector newSel) {
    List<Member> newMs = new ArrayList<>(cb.getMs());
    Member m = Functions.getIfInDom(newMs, sel).get();
    //make m abstract
    if (m instanceof MethodWithType) {
        MethodWithType mwt = (MethodWithType) m;
        mwt = mwt.with_inner(Optional.empty());
        Functions.replaceIfInDom(newMs, mwt);
    } else {
        //it is method implemented
        Functions.removeIfInDom(newMs, sel);
    }
    //create new class
    if (newSel == null) {
        return cb.withMs(newMs);
    }
    MethodWithType mwt1 = (MethodWithType) cb._getMember(sel);
    assert mwt1 != null;
    if (newSel != null) {
        Errors42.checkCompatibleMs(pathForError, mwt1, newSel);
    }
    Optional<MethodWithType> mwt2 = Optional.ofNullable((MethodWithType) cb._getMember(newSel));
    //never refine, see under
    mwt1 = mwt1.withMs(newSel).withDoc(Doc.empty()).withMt(mwt1.getMt().withRefine(false));
    if (mwt2.isPresent()) {
        //Never there, so will never implement interfaces (on normalized classb)
        throw Errors42.errorMethodClash(pathForError, mwt1, mwt2.get(), false, Collections.emptyList(), false, false, false);
    }
    newMs.add(mwt1);
    return cb.withMs(newMs);
}
Also used : ArrayList(java.util.ArrayList) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 47 with Member

use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.

the class AddDocumentation method auxAddDocOnMethod.

private static ClassB auxAddDocOnMethod(Program p, ClassB cb, MethodSelector sel, Doc doc) {
    List<Member> newMs = new ArrayList<>(cb.getMs());
    Member m = Functions.getIfInDom(newMs, sel).get();
    //add comment
    m.match(nc -> {
        throw Assertions.codeNotReachable();
    }, mi -> {
        throw Assertions.codeNotReachable();
    }, mt -> {
        mt = mt.withDoc(mt.getDoc().sum(doc));
        Functions.replaceIfInDom(newMs, mt);
        return null;
    });
    //create new class
    return cb.withMs(newMs);
}
Also used : ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member)

Example 48 with Member

use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.

the class _Aux method onClassNavigateToPathAndDo.

static ClassB onClassNavigateToPathAndDo(ClassB cb, List<Ast.C> cs, Function<ClassB, ClassB> op) {
    if (cs.isEmpty()) {
        return op.apply(cb);
    }
    List<Member> newMs = new ArrayList<>(cb.getMs());
    Ast.C nName = cs.get(0);
    int index = getIndex(newMs, nName);
    checkIndex(index);
    NestedClass nc = (NestedClass) newMs.get(index);
    if (cs.size() > 1) {
        nc = nc.withInner(onClassNavigateToPathAndDo(wrapCast(nc.getInner()), cs.subList(1, cs.size()), op));
        newMs.set(index, nc);
        return cb.withMs(newMs);
    }
    assert cs.size() == 1;
    ClassB newCb = op.apply(wrapCast(nc.getInner()));
    newMs.set(index, nc.withInner(newCb));
    return cb.withMs(newMs);
}
Also used : Ast(ast.Ast) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 49 with Member

use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.

the class _Aux method onNestedNavigateToPathAndDo.

static ClassB onNestedNavigateToPathAndDo(ClassB cb, List<Ast.C> cs, Function<NestedClass, Optional<NestedClass>> op) {
    assert !cs.isEmpty();
    assert cb != null;
    List<Member> newMs = new ArrayList<>(cb.getMs());
    Ast.C nName = cs.get(0);
    int index = getIndex(newMs, nName);
    checkIndex(index);
    NestedClass nc = (NestedClass) newMs.get(index);
    if (cs.size() > 1) {
        nc = nc.withInner(onNestedNavigateToPathAndDo(wrapCast(nc.getInner()), cs.subList(1, cs.size()), op));
        newMs.set(index, nc);
        return cb.withMs(newMs);
    }
    assert cs.size() == 1;
    Optional<NestedClass> optNc = op.apply(nc);
    if (optNc.isPresent()) {
        newMs.set(index, optNc.get());
    } else {
        newMs.remove(index);
    }
    return cb.withMs(newMs);
}
Also used : Ast(ast.Ast) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member)

Example 50 with Member

use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.

the class _Aux method isConsistent.

static boolean isConsistent(ClassB cb) {
    int countWalkBy = 0;
    HashSet<String> keys = new HashSet<String>();
    for (Member m : cb.getMs()) {
        if (m instanceof MethodWithType) {
            MethodWithType mwt = (MethodWithType) m;
            String key = mwt.getMs().toString();
            assert !keys.contains(key);
            keys.add(key);
        //assert mwt.getMt().getTDocs().size() == mwt.getMt().getTs().size();
        }
        if (m instanceof NestedClass) {
            NestedClass nc = (NestedClass) m;
            String key = nc.getName().toString();
            assert !keys.contains(key);
            keys.add(key);
            if (nc.getInner() instanceof ExpCore.WalkBy) {
                countWalkBy += 1;
            }
        }
        if (m instanceof MethodImplemented) {
            MethodImplemented mi = (MethodImplemented) m;
            String key = mi.getS().toString();
            assert !keys.contains(key);
            keys.add(key);
        }
    }
    //     || ((cb.getPhase()!=ast.ExpCore.ClassB.Phase.None && !cb.getUniqueId().isEmpty()) );
    assert countWalkBy <= 1 : cb;
    return true;
}
Also used : MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) NestedClass(ast.ExpCore.ClassB.NestedClass) ToString(lombok.ToString) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member) HashSet(java.util.HashSet)

Aggregations

Member (ast.ExpCore.ClassB.Member)54 ArrayList (java.util.ArrayList)32 ClassB (ast.ExpCore.ClassB)21 MethodWithType (ast.ExpCore.ClassB.MethodWithType)21 NestedClass (ast.ExpCore.ClassB.NestedClass)20 Ast (ast.Ast)14 ExpCore (ast.ExpCore)11 Path (ast.Ast.Path)10 List (java.util.List)7 Doc (ast.Ast.Doc)5 MethodSelector (ast.Ast.MethodSelector)5 MethodType (ast.Ast.MethodType)5 Collections (java.util.Collections)5 C (ast.Ast.C)4 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)4 Phase (ast.ExpCore.ClassB.Phase)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 Assertions (tools.Assertions)4 Position (ast.Ast.Position)3