org.drools.verifier.alwaysFalse.Patterns.drl Maven / Gradle / Ivy
/*
* Copyright 2010 Red Hat, Inc. and/or its affiliates.
*
* 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.Pattern;
import org.drools.verifier.components.SubPattern;
import org.drools.verifier.components.VerifierRule;
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;
global VerifierReport result;
//
// Finds patterns that are always false.
//
// Dependencies:
// Needs at least one of the following packages or rules to fire:
// package org.drools.verifier.incompatibility;
// rule "Incompatible LiteralRestrictions with ranges in pattern possibility, impossible equality less or equal"
// rule "Incompatible LiteralRestrictions with ranges in pattern possibility, impossible equality greater"
// rule "Incompatible LiteralRestrictions with ranges in pattern possibility, impossible range"
// rule "Incoherent VariableRestrictions in pattern possibility, impossible range"
//
// Example:
// Pattern( a == b && a != b )
//
rule "Pattern that is always false"
when
$p :Pattern()
// Check that there is at least one pattern possibility.
exists SubPattern( patternPath == $p.path )
// All the pattern possibilities for pattern need to be in conflict
forall(
$pp :SubPattern(
patternPath == $p.path
)
Incompatibility(
left memberOf $pp.items,
right memberOf $pp.items
)
)
$r :VerifierRule( path == $p.rulePath )
then
Map impactedRules = new HashMap();
impactedRules.put( $r.getPath(), $r.getName());
// Report an error
result.add( new VerifierMessage(
impactedRules,
Severity.ERROR,
MessageType.ALWAYS_FALSE,
$p,
$p + " in " + $r + " can never be satisfied." ) );
end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy