Search in sources :

Example 6 with FormalParameter

use of com.avaloq.tools.ddk.check.check.FormalParameter in project dsl-devkit by dsldevkit.

the class CheckConfigurationImplCustom method getProperties.

/**
 * {@inheritDoc}
 */
@Override
public EList<FormalParameter> getProperties() {
    EList<FormalParameter> properties = new EObjectContainmentEList<FormalParameter>(FormalParameter.class, this, CheckcfgPackage.CHECK_CONFIGURATION__PROPERTIES);
    PropertiesInferenceHelper helper = PropertiesInferenceHelper.getHelper();
    return helper.getProperties(this, properties);
}
Also used : FormalParameter(com.avaloq.tools.ddk.check.check.FormalParameter) PropertiesInferenceHelper(com.avaloq.tools.ddk.checkcfg.util.PropertiesInferenceHelper) EObjectContainmentEList(org.eclipse.emf.ecore.util.EObjectContainmentEList)

Example 7 with FormalParameter

use of com.avaloq.tools.ddk.check.check.FormalParameter 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)

Example 8 with FormalParameter

use of com.avaloq.tools.ddk.check.check.FormalParameter in project dsl-devkit by dsldevkit.

the class CheckCfgProposalProvider method completeConfiguredParameter_NewValue.

@Override
public // CHECKSTYLE:OFF
void completeConfiguredParameter_NewValue(final EObject model, final Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
    // CHECKSTYLE:ON
    // TODO filter depending on type of linked parameter
    FormalParameter parameter = ((ConfiguredParameter) model).getParameter();
    ICheckCfgPropertySpecification propertySpecification = null;
    String[] validValues = null;
    if (parameter != null) {
        propertySpecification = CheckCfgUtil.getPropertySpecification(parameter.getName());
        if (propertySpecification != null) {
            validValues = propertySpecification.getExpectedValues();
        }
    }
    if (validValues != null && validValues.length > 0) {
        String info = propertySpecification.getInfo();
        for (String validValue : validValues) {
            ICompletionProposal proposal = createCompletionProposal(String.format("\"%s\"", validValue), new StyledString(validValue), getImage(model), 0, context.getPrefix(), context);
            if (proposal instanceof ConfigurableCompletionProposal) {
                ((ConfigurableCompletionProposal) proposal).setAdditionalProposalInfo(info);
            }
            acceptor.accept(proposal);
        }
        return;
    }
    super.completeConfiguredParameter_NewValue(model, assignment, context, acceptor);
}
Also used : FormalParameter(com.avaloq.tools.ddk.check.check.FormalParameter) ConfiguredParameter(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter) ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) ICheckCfgPropertySpecification(com.avaloq.tools.ddk.checkcfg.ICheckCfgPropertySpecification)

Aggregations

FormalParameter (com.avaloq.tools.ddk.check.check.FormalParameter)8 ConfiguredCheck (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)3 ConfiguredParameter (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter)3 Check (com.avaloq.tools.ddk.check.check.Check)2 CheckCatalog (com.avaloq.tools.ddk.check.check.CheckCatalog)2 ConfiguredCatalog (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog)2 Function (com.google.common.base.Function)2 EObject (org.eclipse.emf.ecore.EObject)2 Member (com.avaloq.tools.ddk.check.check.Member)1 XIssueExpression (com.avaloq.tools.ddk.check.check.XIssueExpression)1 CheckPropertiesGenerator (com.avaloq.tools.ddk.check.generator.CheckPropertiesGenerator)1 CheckPreferencesHelper (com.avaloq.tools.ddk.check.runtime.configuration.CheckPreferencesHelper)1 LanguageSpecificCheckConfigurationStore (com.avaloq.tools.ddk.check.runtime.configuration.LanguageSpecificCheckConfigurationStore)1 ICheckCfgPropertySpecification (com.avaloq.tools.ddk.checkcfg.ICheckCfgPropertySpecification)1 CheckConfiguration (com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration)1 ConfigurableSection (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfigurableSection)1 ConfiguredLanguageValidator (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredLanguageValidator)1 SeverityKind (com.avaloq.tools.ddk.checkcfg.checkcfg.SeverityKind)1 PropertiesInferenceHelper (com.avaloq.tools.ddk.checkcfg.util.PropertiesInferenceHelper)1 Iterables (com.google.common.collect.Iterables)1