Search in sources :

Example 1 with FormalParameter

use of com.avaloq.tools.ddk.check.check.FormalParameter in project dsl-devkit by dsldevkit.

the class CheckCompiler method getFormalParameter.

/**
 * Gets the FormalParameter this feature call references, if any.
 *
 * @param element
 *          to check
 * @return The source model element (FormalParameter) for this feature call target, or null.
 */
public FormalParameter getFormalParameter(final JvmIdentifiableElement element) {
    Iterator<EObject> modelElements = associations.getSourceElements(element).iterator();
    FormalParameter parameter = null;
    while (parameter == null && modelElements.hasNext()) {
        EObject obj = modelElements.next();
        if (obj instanceof FormalParameter) {
            parameter = (FormalParameter) obj;
        }
    }
    return parameter;
}
Also used : FormalParameter(com.avaloq.tools.ddk.check.check.FormalParameter) EObject(org.eclipse.emf.ecore.EObject)

Example 2 with FormalParameter

use of com.avaloq.tools.ddk.check.check.FormalParameter in project dsl-devkit by dsldevkit.

the class CheckCompiler method _toJavaExpression.

@Override
protected // CHECKSTYLE:OFF
void _toJavaExpression(final XAbstractFeatureCall expr, final ITreeAppendable b) {
    // CHECKSTYLE:ON
    FormalParameter parameter = getFormalParameter(expr);
    if (parameter != null) {
        // No Java entities are generated for this. Replace by a call to the getter function.
        b.append(generatorNaming.catalogInstanceName(parameter)).append(".").append(generatorNaming.formalParameterGetterName(parameter));
        b.append("(").append(getContextImplicitVariableName(expr)).append(")");
    } else {
        Member member = getMember(expr);
        if (member != null) {
            // Something isn't quite right in the Jvm model yet... or in the xbase compiler. Don't know what it is, but even if in an inner
            // class, it generates "this.foo" instead of either just "foo" or "OuterClass.this.foo". Force it to produce the latter.
            CheckCatalog catalog = EcoreUtil2.getContainerOfType(member, CheckCatalog.class);
            String catalogName = generatorNaming.validatorClassName(catalog);
            b.append(catalogName + ".this.").append(member.getName());
            return;
        }
        super._toJavaExpression(expr, b);
    }
}
Also used : FormalParameter(com.avaloq.tools.ddk.check.check.FormalParameter) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) Member(com.avaloq.tools.ddk.check.check.Member)

Example 3 with FormalParameter

use of com.avaloq.tools.ddk.check.check.FormalParameter 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 4 with FormalParameter

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

use of com.avaloq.tools.ddk.check.check.FormalParameter in project dsl-devkit by dsldevkit.

the class ConfiguredParameterImpl method setParameter.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setParameter(FormalParameter newParameter) {
    FormalParameter oldParameter = parameter;
    parameter = newParameter;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, CheckcfgPackage.CONFIGURED_PARAMETER__PARAMETER, oldParameter, parameter));
}
Also used : FormalParameter(com.avaloq.tools.ddk.check.check.FormalParameter) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

FormalParameter (com.avaloq.tools.ddk.check.check.FormalParameter)8 ConfiguredCheck (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)3 ConfiguredParameter (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter)3 Check (com.avaloq.tools.ddk.check.check.Check)2 CheckCatalog (com.avaloq.tools.ddk.check.check.CheckCatalog)2 ConfiguredCatalog (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog)2 Function (com.google.common.base.Function)2 EObject (org.eclipse.emf.ecore.EObject)2 Member (com.avaloq.tools.ddk.check.check.Member)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 ConfiguredLanguageValidator (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredLanguageValidator)1 SeverityKind (com.avaloq.tools.ddk.checkcfg.checkcfg.SeverityKind)1 PropertiesInferenceHelper (com.avaloq.tools.ddk.checkcfg.util.PropertiesInferenceHelper)1 Iterables (com.google.common.collect.Iterables)1