Search in sources :

Example 1 with ConfiguredParameter

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

the class CheckCfgJavaValidator method checkConfigurationEqualsDefault.

/**
 * Checks whether a configured check's configuration equals the default. Emits an info if this is the case.
 *
 * @param configuredCheck
 *          the configured check
 */
@Check
public void checkConfigurationEqualsDefault(final ConfiguredCheck configuredCheck) {
    final com.avaloq.tools.ddk.check.check.Check check = configuredCheck.getCheck();
    if (!isParameterConfigured(configuredCheck) || check == null || check.eIsProxy()) {
        // only interesting if check configured and resolvable
        return;
    }
    Iterable<FormalParameter> formalParameters = check.getFormalParameters();
    for (final ConfiguredParameter configParam : configuredCheck.getParameterConfigurations()) {
        try {
            FormalParameter param = Iterables.find(formalParameters, new Predicate<FormalParameter>() {

                @Override
                public boolean apply(final FormalParameter input) {
                    return input == configParam.getParameter();
                }
            });
            if (parameterValuesEqual(configParam.getNewValue(), param.getRight())) {
                info(NLS.bind(Messages.CheckCfgJavaValidator_CONFIGURED_PARAM_EQUALS_DEFAULT, param.getName()), configParam, CheckcfgPackage.Literals.CONFIGURED_PARAMETER__NEW_VALUE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, IssueCodes.CONFIGURED_PARAM_EQUALS_DEFAULT);
            }
        } catch (NoSuchElementException e) {
            LOGGER.debug("Could not find referenced formal parameter");
        }
    }
}
Also used : FormalParameter(com.avaloq.tools.ddk.check.check.FormalParameter) ConfiguredParameter(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter) NoSuchElementException(java.util.NoSuchElementException) Check(org.eclipse.xtext.validation.Check) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)

Example 2 with ConfiguredParameter

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

the class CheckCfgJavaValidator method checkConfiguredParameterUnique.

/**
 * Checks that a Configured Check has unique Configured Parameters.
 *
 * @param configuredCheck
 *          the configured check
 */
@Check
public void checkConfiguredParameterUnique(final ConfiguredCheck configuredCheck) {
    if (configuredCheck.getParameterConfigurations().size() < 2) {
        return;
    }
    Predicate<ConfiguredParameter> predicate = new Predicate<ConfiguredParameter>() {

        @Override
        public boolean apply(final ConfiguredParameter configuredParameter) {
            return configuredParameter.getParameter() != null && !configuredParameter.getParameter().eIsProxy();
        }
    };
    Function<ConfiguredParameter, String> function = new Function<ConfiguredParameter, String>() {

        @Override
        public String apply(final ConfiguredParameter from) {
            return from.getParameter().getName();
        }
    };
    for (final ConfiguredParameter p : getDuplicates(predicate, function, configuredCheck.getParameterConfigurations())) {
        error(Messages.CheckCfgJavaValidator_DUPLICATE_PARAMETER_CONFIGURATION, p, CheckcfgPackage.Literals.CONFIGURED_PARAMETER__PARAMETER, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, IssueCodes.DUPLICATE_PARAMETER_CONFIGURATION);
    }
}
Also used : Function(com.google.common.base.Function) ConfiguredParameter(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter) Predicate(com.google.common.base.Predicate) Check(org.eclipse.xtext.validation.Check) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)

Example 3 with ConfiguredParameter

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

the class CheckConfigurationPropertiesGenerator method putInheritedProperties.

/**
 * Adds the inherited properties.
 *
 * @param properties
 *          the properties
 * @param language
 *          the language
 * @param check
 *          the check to configure
 * @param parentCatalog
 *          the parent catalog configuration
 * @param configuredProperties
 *          the properties already configured for this check
 */
private void putInheritedProperties(final Properties properties, final String language, final Check check, final ConfiguredCatalog parentCatalog, final EList<ConfiguredParameter> configuredProperties) {
    // this check needs to inherit any parameters defined in one of its parent levels (ConfigurableSections).
    // the values of the inferred parameters are taken from the innermost level.
    // @Format-Off
    Set<String> configuredPropertyNames = configuredProperties.stream().map(property -> property.getParameter()).filter(Objects::nonNull).map(formalParameter -> formalParameter.getName()).collect(Collectors.toSet());
    // @Format-On
    EObject parentSection = parentCatalog;
    while (parentSection != null) {
        if (parentSection instanceof ConfigurableSection) {
            EList<ConfiguredParameter> sectionProperties = ((ConfigurableSection) parentSection).getParameterConfigurations();
            for (ConfiguredParameter property : sectionProperties) {
                if (!configuredPropertyNames.contains(property.getParameter().getName())) {
                    configuredPropertyNames.add(property.getParameter().getName());
                    putProperty(properties, language, check, property, evaluateParameterValue(property.getNewValue()));
                }
            }
        }
        parentSection = parentSection.eContainer();
    }
}
Also used : CheckPropertiesGenerator(com.avaloq.tools.ddk.check.generator.CheckPropertiesGenerator) ConfigurableSection(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfigurableSection) Iterables(com.google.common.collect.Iterables) Inject(com.google.inject.Inject) Check(com.avaloq.tools.ddk.check.check.Check) NodeModelUtils(org.eclipse.xtext.nodemodel.util.NodeModelUtils) Logger(org.apache.log4j.Logger) XIssueExpression(com.avaloq.tools.ddk.check.check.XIssueExpression) Locale(java.util.Locale) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) ConfiguredCatalog(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog) FormalParameter(com.avaloq.tools.ddk.check.check.FormalParameter) StreamSupport(java.util.stream.StreamSupport) XExpression(org.eclipse.xtext.xbase.XExpression) Properties(java.util.Properties) Function(com.google.common.base.Function) ConfiguredLanguageValidator(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredLanguageValidator) ConfiguredParameter(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) CheckPreferencesHelper(com.avaloq.tools.ddk.check.runtime.configuration.CheckPreferencesHelper) SeverityKind(com.avaloq.tools.ddk.checkcfg.checkcfg.SeverityKind) Collectors(java.util.stream.Collectors) IExpressionInterpreter(org.eclipse.xtext.xbase.interpreter.IExpressionInterpreter) EList(org.eclipse.emf.common.util.EList) LanguageSpecificCheckConfigurationStore(com.avaloq.tools.ddk.check.runtime.configuration.LanguageSpecificCheckConfigurationStore) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) XListLiteral(org.eclipse.xtext.xbase.XListLiteral) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck) CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) ECollections(org.eclipse.emf.common.util.ECollections) ConfigurableSection(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfigurableSection) ConfiguredParameter(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter) EObject(org.eclipse.emf.ecore.EObject) Objects(java.util.Objects)

Example 4 with ConfiguredParameter

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

the class CheckConfigurationPropertiesGenerator method generatePropertiesForConfiguredCheck.

/**
 * Generate properties for single configured check.
 *
 * @param properties
 *          the properties
 * @param language
 *          the language
 * @param configuredCheck
 *          the configured check
 */
private void generatePropertiesForConfiguredCheck(final Properties properties, final String language, final ConfiguredCheck configuredCheck) {
    if (configuredCheck.getCheck() == null || configuredCheck.getCheck().eIsProxy()) {
        LOG.warn("Did not configure check " + NodeModelUtils.getTokenText(NodeModelUtils.getNode(configuredCheck)));
        return;
    }
    for (ConfiguredParameter parameter : configuredCheck.getParameterConfigurations()) {
        if (parameter.getParameter() == null || parameter.getParameter().eIsProxy()) {
            LOG.warn("Did not configure parameter " + NodeModelUtils.getTokenText(NodeModelUtils.getNode(parameter)));
            continue;
        }
        String propertyValue = evaluateParameterValue(parameter.getNewValue());
        if (propertyValue == null) {
            LOG.error("Could not configure parameter " + NodeModelUtils.getTokenText(NodeModelUtils.getNode(parameter)));
            continue;
        }
        putProperty(properties, language, configuredCheck.getCheck(), parameter, propertyValue);
    }
    putCheckSeverity(properties, language, configuredCheck);
    putInheritedProperties(properties, language, configuredCheck);
}
Also used : ConfiguredParameter(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter)

Example 5 with ConfiguredParameter

use of com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter 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

ConfiguredParameter (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter)5 FormalParameter (com.avaloq.tools.ddk.check.check.FormalParameter)3 ConfiguredCheck (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)3 Function (com.google.common.base.Function)2 Check (org.eclipse.xtext.validation.Check)2 Check (com.avaloq.tools.ddk.check.check.Check)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 ConfiguredCatalog (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog)1 ConfiguredLanguageValidator (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredLanguageValidator)1 SeverityKind (com.avaloq.tools.ddk.checkcfg.checkcfg.SeverityKind)1 Predicate (com.google.common.base.Predicate)1 Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 Inject (com.google.inject.Inject)1