Search in sources :

Example 1 with MatchingResult

use of il.org.spartan.Leonidas.plugin.leonidas.MatchingResult in project Main by SpartanRefactoring.

the class Method method generalizes.

@Override
public MatchingResult generalizes(Encapsulator e) {
    if (super.generalizes(e).notMatches() || !iz.method(e.getInner()))
        return new MatchingResult(false);
    PsiMethod m = az.method(e.getInner());
    Wrapper<Integer> dummy = new Wrapper<>(0);
    return matcherReturnType.getMatchingResult(m.getReturnTypeElement(), dummy).combineWith(matcherParameters.getMatchingResult(m.getParameterList(), dummy)).combineWith(matcherCodeBlock.getMatchingResult(m.getBody(), dummy));
}
Also used : MatchingResult(il.org.spartan.Leonidas.plugin.leonidas.MatchingResult) PsiMethod(com.intellij.psi.PsiMethod)

Example 2 with MatchingResult

use of il.org.spartan.Leonidas.plugin.leonidas.MatchingResult in project Main by SpartanRefactoring.

the class Class method matchInnerElements.

private MatchingResult matchInnerElements(PsiElement[] innerElements, List<Matcher> matchers) {
    if (matchers.size() == 0)
        return new MatchingResult(true);
    List<List<MatchingResult>> l = matchers.stream().map(m -> Arrays.stream(innerElements).map(ie -> m.getMatchingResult(ie, new Wrapper<>(0))).filter(mr -> mr.matches()).collect(Collectors.toList())).collect(Collectors.toList());
    MatchingResult[] ass = new MatchingResult[matchers.size()];
    if (!matchInnerElementAux(l, matchers.size() - 1, new LinkedList<>(), ass)) {
        return new MatchingResult(false);
    }
    MatchingResult mr = new MatchingResult(true);
    Arrays.stream(ass).forEach(a -> mr.combineWith(a));
    return mr;
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) PsiMethod(com.intellij.psi.PsiMethod) Pruning(il.org.spartan.Leonidas.plugin.leonidas.Pruning) Collectors(java.util.stream.Collectors) Leonidas.auxilary_layer(il.org.spartan.Leonidas.auxilary_layer) PsiClass(com.intellij.psi.PsiClass) List(java.util.List) Matcher(il.org.spartan.Leonidas.plugin.leonidas.Matcher) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement) PsiField(com.intellij.psi.PsiField) MatchingResult(il.org.spartan.Leonidas.plugin.leonidas.MatchingResult) LinkedList(java.util.LinkedList) MatchingResult(il.org.spartan.Leonidas.plugin.leonidas.MatchingResult) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 3 with MatchingResult

use of il.org.spartan.Leonidas.plugin.leonidas.MatchingResult in project Main by SpartanRefactoring.

the class Class method matchInnerElementAux.

private boolean matchInnerElementAux(List<List<MatchingResult>> l, int i, List<MatchingResult> used, MatchingResult[] ass) {
    if (i < 0)
        return true;
    for (MatchingResult mr : l.get(i)) {
        if (used.contains(mr))
            continue;
        used.add(mr);
        ass[i] = mr;
        if (matchInnerElementAux(l, i - 1, used, ass))
            return true;
        used.remove(mr);
    }
    return false;
}
Also used : MatchingResult(il.org.spartan.Leonidas.plugin.leonidas.MatchingResult)

Example 4 with MatchingResult

use of il.org.spartan.Leonidas.plugin.leonidas.MatchingResult in project Main by SpartanRefactoring.

the class Class method generalizes.

@Override
public MatchingResult generalizes(Encapsulator e) {
    if (!iz.classDeclaration(e.inner))
        return new MatchingResult(false);
    PsiClass c = az.classDeclaration(e.inner);
    MatchingResult mr = new MatchingResult(true);
    if (!super.generalizes(e).matches())
        return new MatchingResult(false);
    mr.combineWith(matchInnerElements(c.getFields(), fieldsMatchers));
    mr.combineWith(matchInnerElements(c.getMethods(), methodsMatchers));
    mr.combineWith(matchInnerElements(c.getInnerClasses(), innerClassesMatchers));
    return mr;
}
Also used : MatchingResult(il.org.spartan.Leonidas.plugin.leonidas.MatchingResult) PsiClass(com.intellij.psi.PsiClass)

Aggregations

MatchingResult (il.org.spartan.Leonidas.plugin.leonidas.MatchingResult)4 PsiClass (com.intellij.psi.PsiClass)2 PsiMethod (com.intellij.psi.PsiMethod)2 PsiElement (com.intellij.psi.PsiElement)1 PsiField (com.intellij.psi.PsiField)1 Leonidas.auxilary_layer (il.org.spartan.Leonidas.auxilary_layer)1 Matcher (il.org.spartan.Leonidas.plugin.leonidas.Matcher)1 Pruning (il.org.spartan.Leonidas.plugin.leonidas.Pruning)1 Arrays (java.util.Arrays)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1