Search in sources :

Example 6 with ConfiguredCheck

use of com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck in project dsl-devkit by dsldevkit.

the class CheckCfgJavaValidator method checkConfiguredSeverityAllowed.

/**
 * Checks that a configured check's severity is allowed. If referenced check has a {@link SeverityRange severity range} defined, it must be checked that
 * configured value is within defined range.
 *
 * @param configuredCheck
 *          the configured check
 */
@Check
public void checkConfiguredSeverityAllowed(final ConfiguredCheck configuredCheck) {
    // @Format-Off
    if (isSeverityConfigured(configuredCheck) && configuredCheck.getCheck() != null && !configuredCheck.getCheck().eIsProxy() && configuredCheck.getCheck().getSeverityRange() != null) {
        final SeverityRange range = configuredCheck.getCheck().getSeverityRange();
        final com.avaloq.tools.ddk.check.check.SeverityKind configuredSeverity = com.avaloq.tools.ddk.check.check.SeverityKind.getByName(configuredCheck.getSeverity().getName());
        final com.avaloq.tools.ddk.check.check.SeverityKind minSeverity = com.avaloq.tools.ddk.check.check.SeverityKind.get(Math.min(range.getMinSeverity().getValue(), range.getMaxSeverity().getValue()));
        final com.avaloq.tools.ddk.check.check.SeverityKind maxSeverity = com.avaloq.tools.ddk.check.check.SeverityKind.get(Math.max(range.getMinSeverity().getValue(), range.getMaxSeverity().getValue()));
        List<String> issueCodes = Lists.newArrayList();
        if (configuredSeverity.compareTo(minSeverity) < 0 || configuredSeverity.compareTo(maxSeverity) > 0) {
            com.avaloq.tools.ddk.check.check.SeverityKind temp = minSeverity;
            while (temp != null && temp.compareTo(maxSeverity) <= 0) {
                issueCodes.add(temp.getName());
                temp = com.avaloq.tools.ddk.check.check.SeverityKind.get(temp.getValue() + 1);
            }
            String[] codes = issueCodes.toArray(new String[issueCodes.size()]);
            error(Messages.CheckCfgJavaValidator_SEVERITY_NOT_ALLOWED, CheckcfgPackage.Literals.CONFIGURED_CHECK__SEVERITY, IssueCodes.SEVERITY_NOT_ALLOWED, // NOPMD
            issueCodes.isEmpty() ? null : codes);
        }
    // @Format-On
    }
}
Also used : SeverityRange(com.avaloq.tools.ddk.check.check.SeverityRange) Check(org.eclipse.xtext.validation.Check) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)

Example 7 with ConfiguredCheck

use of com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck in project dsl-devkit by dsldevkit.

the class CheckCfgScopeProvider method getScope.

@Override
public IScope getScope(final EObject context, final EReference reference) {
    if (reference == CheckcfgPackage.Literals.CONFIGURED_CHECK__CHECK) {
        // Note that context object can be either a configured check (if 'optional' keyword has been provided
        // so that a new instance is created and the configured catalog does not contain any configured checks
        // yet) or a configured catalog (in all other cases)
        final ConfiguredCatalog configuredCatalog = EcoreUtil2.getContainerOfType(context, ConfiguredCatalog.class);
        if (configuredCatalog == null || configuredCatalog.getCatalog() == null) {
            return IScope.NULLSCOPE;
        }
        CheckCatalog catalog = configuredCatalog.getCatalog();
        return Scopes.scopeFor(catalog.getAllChecks(), checkQualifiedNameProvider, IScope.NULLSCOPE);
    } else if (reference == CheckcfgPackage.Literals.CONFIGURED_PARAMETER__PARAMETER) {
        // a new list of FormalParameters to scope to
        EList<FormalParameter> parameters = ECollections.newBasicEList();
        final ConfiguredCheck configuredCheck = EcoreUtil2.getContainerOfType(context, ConfiguredCheck.class);
        if (configuredCheck != null) {
            // add FormalParameter definitions from linked check
            parameters.addAll(configuredCheck.getCheck().getFormalParameters());
        }
        // add inferred FormalParameters (properties)
        final CheckConfiguration checkConfiguration = EcoreUtil2.getContainerOfType(context, CheckConfiguration.class);
        parameters.addAll(checkConfiguration.getProperties());
        return Scopes.scopeFor(parameters, checkQualifiedNameProvider, IScope.NULLSCOPE);
    }
    return super.getScope(context, reference);
}
Also used : CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) ConfiguredCatalog(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog) EList(org.eclipse.emf.common.util.EList) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog)

Example 8 with ConfiguredCheck

use of com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck in project dsl-devkit by dsldevkit.

the class CheckCfgTemplateProposalProvider method addConfiguredCheckTemplates.

/**
 * Adds template proposals for all checks which may be referenced in current catalog configuration. Only proposals for checks
 * which have not yet been configured are provided.
 *
 * @param templateContext
 *          the template context
 * @param context
 *          the context
 * @param acceptor
 *          the acceptor
 */
private void addConfiguredCheckTemplates(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) {
    // NOPMD
    ConfiguredCatalog configuredCatalog = EcoreUtil2.getContainerOfType(context.getCurrentModel(), ConfiguredCatalog.class);
    Iterable<String> alreadyConfiguredCheckNames = Iterables.filter(Iterables.transform(configuredCatalog.getCheckConfigurations(), new Function<ConfiguredCheck, String>() {

        @Override
        public String apply(final ConfiguredCheck from) {
            if (from.getCheck() != null) {
                return from.getCheck().getName();
            }
            return null;
        }
    }), Predicates.notNull());
    final CheckCatalog catalog = configuredCatalog.getCatalog();
    for (final Check check : catalog.getAllChecks()) {
        // create a template on the fly
        final String checkName = check.getName();
        if (!Iterables.contains(alreadyConfiguredCheckNames, checkName)) {
            // check if referenced check has configurable parameters
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            final StringJoiner paramsJoiner = new StringJoiner(", ", " (", ")");
            // $NON-NLS-1$
            paramsJoiner.setEmptyValue("");
            for (final FormalParameter param : check.getFormalParameters()) {
                final String paramName = param.getName();
                final Object defaultValue = interpreter.evaluate(param.getRight()).getResult();
                final String valuePlaceholder = helper.createLiteralValuePattern(paramName, defaultValue);
                // $NON-NLS-1$
                paramsJoiner.add(paramName + " = " + valuePlaceholder);
            }
            // $NON-NLS-1$ //$NON-NLS-2$
            final String severity = (catalog.isFinal() || check.isFinal()) ? "default " : "${default:Enum('SeverityKind')} ";
            // $NON-NLS-1$ //$NON-NLS-2$
            final String description = "Configures the check \"" + check.getLabel() + "\"";
            // $NON-NLS-1$
            final String contextTypeId = "com.avaloq.tools.ddk.checkcfg.CheckCfg.ConfiguredCheck." + checkName;
            // $NON-NLS-1$
            final String pattern = severity + qualifiedNameValueConverter.toString(checkName) + paramsJoiner + "${cursor}";
            Template t = new Template(checkName, description, contextTypeId, pattern, true);
            TemplateProposal tp = createProposal(t, templateContext, context, images.forConfiguredCheck(check.getDefaultSeverity()), getRelevance(t));
            acceptor.accept(tp);
        }
    }
}
Also used : FormalParameter(com.avaloq.tools.ddk.check.check.FormalParameter) TemplateProposal(org.eclipse.jface.text.templates.TemplateProposal) Function(com.google.common.base.Function) ConfiguredCatalog(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck) Check(com.avaloq.tools.ddk.check.check.Check) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) StringJoiner(java.util.StringJoiner) Template(org.eclipse.jface.text.templates.Template)

Aggregations

ConfiguredCheck (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)8 Check (org.eclipse.xtext.validation.Check)4 ConfiguredCatalog (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog)3 Function (com.google.common.base.Function)3 Check (com.avaloq.tools.ddk.check.check.Check)2 CheckCatalog (com.avaloq.tools.ddk.check.check.CheckCatalog)2 FormalParameter (com.avaloq.tools.ddk.check.check.FormalParameter)2 CheckConfiguration (com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration)2 ConfiguredParameter (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter)2 Predicate (com.google.common.base.Predicate)2 SeverityRange (com.avaloq.tools.ddk.check.check.SeverityRange)1 ConfiguredLanguageValidator (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredLanguageValidator)1 NoSuchElementException (java.util.NoSuchElementException)1 StringJoiner (java.util.StringJoiner)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 Template (org.eclipse.jface.text.templates.Template)1 TemplateProposal (org.eclipse.jface.text.templates.TemplateProposal)1 INode (org.eclipse.xtext.nodemodel.INode)1