Search in sources :

Example 1 with ConfiguredCatalog

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

the class CheckCfgJavaValidator method checkConfiguredCatalogUnique.

/**
 * Checks that within a Check Configuration all Catalog Configurations are unique, meaning that a referenced
 * Check Catalog can only be configured in one place.
 *
 * @param configuration
 *          the configuration
 */
@Check
public void checkConfiguredCatalogUnique(final CheckConfiguration configuration) {
    if (configuration.getLegacyCatalogConfigurations().size() < 2) {
        return;
    }
    Predicate<ConfiguredCatalog> predicate = new Predicate<ConfiguredCatalog>() {

        @Override
        public boolean apply(final ConfiguredCatalog configuredCatalog) {
            final CheckCatalog catalog = configuredCatalog.getCatalog();
            return catalog != null && !catalog.eIsProxy();
        }
    };
    Function<ConfiguredCatalog, String> function = new Function<ConfiguredCatalog, String>() {

        @Override
        public String apply(final ConfiguredCatalog from) {
            return from.getCatalog().getName();
        }
    };
    for (final ConfiguredCatalog c : getDuplicates(predicate, function, configuration.getLegacyCatalogConfigurations())) {
        error(Messages.CheckCfgJavaValidator_DUPLICATE_CATALOG_CONFIGURATION, c, CheckcfgPackage.Literals.CONFIGURED_CATALOG__CATALOG, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, IssueCodes.DUPLICATE_CATALOG_CONFIGURATION);
    }
}
Also used : Function(com.google.common.base.Function) ConfiguredCatalog(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) Predicate(com.google.common.base.Predicate) Check(org.eclipse.xtext.validation.Check) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)

Example 2 with ConfiguredCatalog

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

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

the class CheckConfigurationPropertiesGenerator method generatePropertiesForCatalogsInConfigurableSection.

/**
 * Generate properties for languages or legacy catalogs.
 *
 * @param section
 *          the section
 * @param properties
 *          the properties
 */
private void generatePropertiesForCatalogsInConfigurableSection(final ConfigurableSection section, final Properties properties) {
    String language = null;
    EList<ConfiguredCatalog> configuredCatalogs = ECollections.emptyEList();
    if (section instanceof CheckConfiguration) {
        configuredCatalogs = ((CheckConfiguration) section).getLegacyCatalogConfigurations();
    } else if (section instanceof ConfiguredLanguageValidator) {
        language = ((ConfiguredLanguageValidator) section).getLanguage();
        configuredCatalogs = ((ConfiguredLanguageValidator) section).getCatalogConfigurations();
    }
    for (ConfiguredCatalog catalog : configuredCatalogs) {
        Set<Check> configuredChecks = Sets.newHashSet();
        for (ConfiguredCheck configuredCheck : catalog.getCheckConfigurations()) {
            generatePropertiesForConfiguredCheck(properties, language, configuredCheck);
            configuredChecks.add(configuredCheck.getCheck());
        }
        for (Check unconfiguredCheck : Sets.difference(Sets.newHashSet(catalog.getCatalog().getAllChecks()), configuredChecks)) {
            putInheritedProperties(properties, language, unconfiguredCheck, catalog, ECollections.emptyEList());
        }
    }
}
Also used : CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) ConfiguredCatalog(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog) ConfiguredLanguageValidator(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredLanguageValidator) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck) Check(com.avaloq.tools.ddk.check.check.Check) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)

Example 4 with ConfiguredCatalog

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

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

ConfiguredCatalog (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog)5 ConfiguredCheck (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)5 Check (com.avaloq.tools.ddk.check.check.Check)3 CheckCatalog (com.avaloq.tools.ddk.check.check.CheckCatalog)3 CheckConfiguration (com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration)3 Function (com.google.common.base.Function)3 FormalParameter (com.avaloq.tools.ddk.check.check.FormalParameter)2 ConfiguredLanguageValidator (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredLanguageValidator)2 EList (org.eclipse.emf.common.util.EList)2 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 ConfigurableSection (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfigurableSection)1 ConfiguredParameter (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter)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