Search in sources :

Example 1 with ThreatEqualContains

use of com.ge.research.osate.verdict.dsl.verdict.ThreatEqualContains in project VERDICT by ge-high-assurance.

the class VerdictProposalProvider method complete_Var.

@Override
public void complete_Var(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    // Completes with variables that are in scope (introduced by intro clauses, i.e. forall and exists)
    EObject scopeParent = ThreatModelUtil.getContainerForClasses(model, ThreatModelUtil.VAR_FIELD_SCOPE_PARENT_CLASSES);
    if (scopeParent != null && scopeParent.eResource() != null && scopeParent.eResource().getResourceSet() != null) {
        // Get all variables in scope
        List<VerdictVariable> scope = ThreatModelUtil.getScope(scopeParent, indexProvider);
        for (VerdictVariable var : scope) {
            acceptor.accept(createCompletionProposal(var.getId(), context));
        }
    }
    if (model != null) {
        // Get equal/contains parent
        EObject container = model;
        while (container != null && !(container instanceof ThreatEqualContains)) {
            container = container.eContainer();
        }
        if (container instanceof ThreatEqualContains) {
            ThreatEqualContains equalContains = (ThreatEqualContains) container;
            List<String> suggestions = null;
            if (equalContains.isEqual() && equalContains.getLeft() != null && equalContains.getLeft().eResource() != null && equalContains.getLeft().eResource().getResourceSet() != null) {
                // We know the left side, so predict based on that
                ThreatModelUtil.FieldTypeResult res = ThreatModelUtil.getVarType(equalContains.getLeft(), indexProvider);
                if (res.type.isPresent()) {
                    suggestions = res.type.get().getValueSuggestions();
                }
            }
            if (equalContains.isEqual() && equalContains.getRight() != null && equalContains.getRight().eResource() != null && equalContains.getRight().eResource().getResourceSet() != null) {
                // We know the right side, so predict based on that
                ThreatModelUtil.FieldTypeResult res = ThreatModelUtil.getVarType(equalContains.getRight(), indexProvider);
                if (res.type.isPresent()) {
                    suggestions = res.type.get().getValueSuggestions();
                }
            }
            if (suggestions != null) {
                for (String suggestion : suggestions) {
                    // Higher priority (1100) to make them display above the vars
                    acceptor.accept(createCompletionProposal(suggestion, null, null, 1100, context.getPrefix(), context));
                }
            }
        }
    }
}
Also used : ThreatModelUtil(com.ge.research.osate.verdict.dsl.ThreatModelUtil) ThreatEqualContains(com.ge.research.osate.verdict.dsl.verdict.ThreatEqualContains) EObject(org.eclipse.emf.ecore.EObject) VerdictVariable(com.ge.research.osate.verdict.dsl.type.VerdictVariable)

Aggregations

ThreatModelUtil (com.ge.research.osate.verdict.dsl.ThreatModelUtil)1 VerdictVariable (com.ge.research.osate.verdict.dsl.type.VerdictVariable)1 ThreatEqualContains (com.ge.research.osate.verdict.dsl.verdict.ThreatEqualContains)1 EObject (org.eclipse.emf.ecore.EObject)1