<commit_before>package de.bmoth.backend.ltl.transformation;

import de.bmoth.parser.ast.nodes.Node;
import de.bmoth.parser.ast.nodes.ltl.LTLNode;
import de.bmoth.parser.ast.nodes.ltl.LTLPrefixOperatorNode;
import de.bmoth.parser.ast.visitors.AbstractASTTransformation;

public class ConvertNotGloballyToFinallyNot extends AbstractASTTransformation{

    @Override
    public boolean canHandleNode(Node node) {
        return node instanceof LTLPrefixOperatorNode;
    }

    @Override
    public Node transformNode(Node oldNode) {
        LTLPrefixOperatorNode notOperator = (LTLPrefixOperatorNode) oldNode;
        if (notOperator.getKind() == LTLPrefixOperatorNode.Kind.NOT) {
            LTLNode argument = notOperator.getArgument();
            if (argument instanceof LTLPrefixOperatorNode) {
                LTLPrefixOperatorNode globallyOperator = (LTLPrefixOperatorNode) argument;
                if (globallyOperator.getKind() == LTLPrefixOperatorNode.Kind.GLOBALLY) {
                    LTLPrefixOperatorNode newNot = new LTLPrefixOperatorNode(LTLPrefixOperatorNode.Kind.NOT,
                            globallyOperator.getArgument());
                    setChanged();
                    return new LTLPrefixOperatorNode(LTLPrefixOperatorNode.Kind.FINALLY, newNot);
                }
            }
        }
        return oldNode;
    }
}<commit_msg>refactored nG -> Fn conversion using LTL AST transformation<commit_after>package de.bmoth.backend.ltl.transformation;

import de.bmoth.parser.ast.nodes.Node;
import de.bmoth.parser.ast.nodes.ltl.LTLNode;
import de.bmoth.parser.ast.nodes.ltl.LTLPrefixOperatorNode;
import de.bmoth.parser.ast.visitors.LTLASTTransformation;

import static de.bmoth.parser.ast.nodes.ltl.LTLPrefixOperatorNode.Kind.*;

public class ConvertNotGloballyToFinallyNot extends LTLASTTransformation {

    @Override
    public boolean canHandleNode(Node node) {
        return isOperator(node, NOT) && contains(node, GLOBALLY);
    }

    @Override
    public Node transformNode(Node node) {
        LTLPrefixOperatorNode not = (LTLPrefixOperatorNode) node;
        LTLPrefixOperatorNode globally = (LTLPrefixOperatorNode) not.getArgument();
        LTLNode inner = globally.getArgument();

        setChanged();
        return new LTLPrefixOperatorNode(FINALLY, new LTLPrefixOperatorNode(NOT, inner));
    }
}
{'fraction_non_alphanumeric': 0.0847890924584576, 'fraction_numerical': 0.0, 'mean_word_length': 3.348148148148148, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6991509', 'n_tokens_mistral': 678, 'n_tokens_neox': 676, 'n_words': 120}