All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lu.uni.serval.ikora.smells.NodeUtils Maven / Gradle / Ivy

There is a newer version: 0.1.19
Show newest version
package lu.uni.serval.ikora.smells;

import lu.uni.serval.ikora.core.model.*;

import java.util.*;

public class NodeUtils {
    private NodeUtils() {}

    public static boolean isCallType(SourceNode sourceNode, Keyword.Type type, boolean allowIndirectCall){
        if(sourceNode instanceof KeywordCall){
            return isType((KeywordCall)sourceNode, type, allowIndirectCall);
        }

        return false;
    }

    public static boolean isSingleAction(UserKeyword keyword, Set types){
        return keyword.getSteps().stream()
                .map(Step::getKeywordCall)
                .filter(Optional::isPresent)
                .map(Optional::get)
                .map(KeywordCall::getKeyword)
                .filter(Optional::isPresent)
                .map(Optional::get)
                .map(Keyword::getType)
                .filter(t -> t != Keyword.Type.LOG)
                .anyMatch(types::contains);
    }

    public static boolean isType(KeywordCall call, Keyword.Type type, boolean allowIndirectCall){
        final Optional keyword = call.getKeyword();

        if(!keyword.isPresent()){
            return false;
        }

        if(keyword.get().getType() == type){
            return true;
        }

        if(allowIndirectCall && UserKeyword.class.isAssignableFrom(keyword.get().getClass())){
            return isSingleAction((UserKeyword)keyword.get(), Collections.singleton(type));
        }

        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy