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

org.drools.verifier.alwaysFalse.Rules.drl Maven / Gradle / Ivy

There is a newer version: 9.44.0.Final
Show newest version
/*
 * Copyright 2010 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//
// created on: 5.6.2008
//
// Rules in this package look for patterns and rules that can never be satisfied.
//
//
package org.drools.verifier.alwaysFalse
//list any import classes here.
import org.drools.verifier.components.VerifierRule;
import org.drools.verifier.components.SubRule;

import org.drools.verifier.report.components.Severity;
import org.drools.verifier.report.components.MessageType;
import org.drools.verifier.report.components.Incompatibility;
import org.drools.verifier.report.components.VerifierMessage;

import org.drools.verifier.data.VerifierReport;

import java.util.Map;
import java.util.HashMap;

import java.util.Map;
import java.util.HashMap;

global VerifierReport result;

//
// Finds rules that are always false.
//
// Dependencies:
//    Needs at least one of the following packages or rules to fire:
//         package org.drools.verifier.incompatibility;
//            rule "Incompatible Patterns"
//
// Example:
//        Pattern( a == b && a != b )
//
rule "Rule that is always false"
    when
        $r :VerifierRule()

        # All the rule possibilities for rule need to be in conflict
        forall(
            $rp :SubRule(
                rulePath == $r.path
            )

            Incompatibility(
                left memberOf $rp.items,
                right memberOf $rp.items
            )
        )
    then
        Map impactedRules = new HashMap();
        impactedRules.put( $r.getPath(), $r.getName());

        # Report an error
        result.add( new VerifierMessage(
                                impactedRules,
                                Severity.ERROR,
                                MessageType.ALWAYS_FALSE,
                                $r,
                                $r + " can never be satisfied." ) );
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy