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