Search in sources :

Example 1 with NotNestableDetectorResult

use of com.synopsys.integration.detector.result.NotNestableDetectorResult in project synopsys-detect by blackducksoftware.

the class DetectorRuleSetEvaluator method evaluateSearchable.

public DetectorResult evaluateSearchable(DetectorRuleSet detectorRuleSet, DetectorRule detectorRule, SearchEnvironment environment) {
    if (!environment.getDetectorFilter().test(detectorRule)) {
        return new ExcludedDetectorResult();
    }
    int maxDepth = detectorRule.getMaxDepth();
    if (environment.getDepth() > maxDepth) {
        return new MaxDepthExceededDetectorResult(environment.getDepth(), maxDepth);
    }
    Set<DetectorRule> yieldTo = environment.getAppliedSoFar().stream().filter(it -> detectorRuleSet.getYieldsTo(detectorRule).contains(it)).collect(Collectors.toSet());
    if (yieldTo.size() > 0) {
        return new YieldedDetectorResult(yieldTo.stream().map(DetectorRule::getName).collect(Collectors.toSet()));
    }
    boolean nestable = detectorRule.isNestable();
    boolean selfNestable = detectorRule.isSelfNestable();
    boolean selfTypeNestable = detectorRule.isSelfTypeNestable();
    DetectorType detectorType = detectorRule.getDetectorType();
    Set<DetectorType> notNestableBeneath = detectorRule.getNotNestableBeneath();
    if (environment.isForceNestedSearch()) {
        return new ForcedNestedPassedDetectorResult();
    } else if (nestable) {
        if (!selfNestable && environment.getAppliedToParent().stream().anyMatch(detectorRule::equals)) {
            return new NotSelfNestableDetectorResult();
        }
        if (!selfTypeNestable && environment.getAppliedToParent().stream().map(DetectorRule::getDetectorType).anyMatch(detectorType::equals)) {
            return new NotSelfTypeNestableDetectorResult(detectorType);
        }
        if (notNestableBeneath.size() > 0) {
            Optional<DetectorType> notNestableBeneathType = environment.getAppliedToParent().stream().map(DetectorRule::getDetectorType).filter(notNestableBeneath::contains).findAny();
            if (notNestableBeneathType.isPresent()) {
                return new NotNestableBeneathDetectorResult(notNestableBeneathType.get());
            }
        }
    } else if (environment.getAppliedToParent().stream().anyMatch(it -> !it.isNestInvisible())) {
        return new NotNestableDetectorResult();
    }
    return new PassedDetectorResult();
}
Also used : MaxDepthExceededDetectorResult(com.synopsys.integration.detector.result.MaxDepthExceededDetectorResult) PassedDetectorResult(com.synopsys.integration.detector.result.PassedDetectorResult) NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) NotSelfNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfNestableDetectorResult) Set(java.util.Set) Collectors(java.util.stream.Collectors) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Optional(java.util.Optional) DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) ForcedNestedPassedDetectorResult(com.synopsys.integration.detector.result.ForcedNestedPassedDetectorResult) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) ExcludedDetectorResult(com.synopsys.integration.detector.result.ExcludedDetectorResult) NotNestableDetectorResult(com.synopsys.integration.detector.result.NotNestableDetectorResult) YieldedDetectorResult(com.synopsys.integration.detector.result.YieldedDetectorResult) Optional(java.util.Optional) YieldedDetectorResult(com.synopsys.integration.detector.result.YieldedDetectorResult) PassedDetectorResult(com.synopsys.integration.detector.result.PassedDetectorResult) ForcedNestedPassedDetectorResult(com.synopsys.integration.detector.result.ForcedNestedPassedDetectorResult) NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) MaxDepthExceededDetectorResult(com.synopsys.integration.detector.result.MaxDepthExceededDetectorResult) DetectorType(com.synopsys.integration.detector.base.DetectorType) NotSelfNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfNestableDetectorResult) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ForcedNestedPassedDetectorResult(com.synopsys.integration.detector.result.ForcedNestedPassedDetectorResult) NotNestableDetectorResult(com.synopsys.integration.detector.result.NotNestableDetectorResult) ExcludedDetectorResult(com.synopsys.integration.detector.result.ExcludedDetectorResult)

Aggregations

DetectorType (com.synopsys.integration.detector.base.DetectorType)1 DetectorResult (com.synopsys.integration.detector.result.DetectorResult)1 ExcludedDetectorResult (com.synopsys.integration.detector.result.ExcludedDetectorResult)1 ForcedNestedPassedDetectorResult (com.synopsys.integration.detector.result.ForcedNestedPassedDetectorResult)1 MaxDepthExceededDetectorResult (com.synopsys.integration.detector.result.MaxDepthExceededDetectorResult)1 NotNestableBeneathDetectorResult (com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult)1 NotNestableDetectorResult (com.synopsys.integration.detector.result.NotNestableDetectorResult)1 NotSelfNestableDetectorResult (com.synopsys.integration.detector.result.NotSelfNestableDetectorResult)1 NotSelfTypeNestableDetectorResult (com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult)1 PassedDetectorResult (com.synopsys.integration.detector.result.PassedDetectorResult)1 YieldedDetectorResult (com.synopsys.integration.detector.result.YieldedDetectorResult)1 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)1 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1