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);
}
}
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();
}
}
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());
}
}
}
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);
}
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);
}
}
}
Aggregations