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