Search in sources :

Example 6 with Check

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

the class CheckQuickfixProvider method addIdToCheck.

/**
 * Add explicit ID to a check, autogenerated from its label.
 *
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(IssueCodes.MISSING_ID_ON_CHECK)
public void addIdToCheck(final Issue issue, final IssueResolutionAcceptor acceptor) {
    acceptor.accept(issue, Messages.CheckQuickfixProvider_ADD_ID_LABEL, NLS.bind(Messages.CheckQuickfixProvider_ADD_ID_DESCN, CHECK), NO_IMAGE, (final EObject element, final IModificationContext context) -> {
        final Check check = EcoreUtil2.getContainerOfType(element, Check.class);
        if (check != null) {
            final String label = check.getLabel();
            final String id = CheckUtil.toIdentifier(label);
            check.setId(id);
        }
    });
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) Check(com.avaloq.tools.ddk.check.check.Check) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Example 7 with Check

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

the class CheckCompiler method _toJavaStatement.

/**
 * {@inheritDoc}
 */
// CHECKSTYLE:OFF
protected void _toJavaStatement(final XIssueExpression expr, final ITreeAppendable b, final boolean isReferenced) {
    // NOPMD NPath complexity
    // CHECKSTYLE:ON
    XExpression markerObject = expr.getMarkerObject();
    Check check = generatorExtensions.issuedCheck(expr);
    for (XExpression param : expr.getMessageParameters()) {
        internalToJavaStatement(param, b, true);
        b.newLine();
    }
    if (markerObject != null) {
        internalToJavaStatement(markerObject, b, true);
        b.newLine();
    }
    XExpression markerIndex = expr.getMarkerIndex();
    if (markerIndex != null) {
        internalToJavaStatement(markerIndex, b, true);
        b.newLine();
    }
    JvmType eObjectType = findKnownTopLevelType(EObject.class, expr);
    for (XExpression data : expr.getIssueData()) {
        internalToJavaStatement(data, b, true);
        b.newLine();
    }
    // acceptor
    b.append("// Issue diagnostic").newLine();
    b.append(generatorNaming.catalogInstanceName(expr)).append(".accept(").append("getMessageAcceptor()");
    // context object
    b.append(", //").increaseIndentation().newLine();
    if (markerObject != null) {
        internalToConvertedExpression(markerObject, b, getLightweightType(eObjectType));
    } else {
        b.append(getContextImplicitVariableName(expr));
    }
    b.append(", // context EObject").newLine();
    // feature
    EStructuralFeature markerFeature = expr.getMarkerFeature();
    if (markerFeature != null) {
        b.append(findEPackageInterfaceType(markerFeature, expr));
        b.append(".eINSTANCE.get").append(markerFeature.getEContainingClass().getName()).append("_").append(Strings.toFirstUpper(markerFeature.getName())).append("()");
    } else {
        b.append("null");
    }
    b.append(", // EStructuralFeature").newLine();
    // message
    b.append(generatorNaming.catalogInstanceName(check)).append(".get").append(Strings.toFirstUpper(check.getName())).append("Message(");
    if (!expr.getMessageParameters().isEmpty()) {
        boolean first = true;
        for (XExpression param : expr.getMessageParameters()) {
            if (!first) {
                b.append(", ");
            }
            internalToJavaExpression(param, b);
            first = false;
        }
    }
    b.append(")");
    b.append(", // Message").newLine();
    // severity kind
    b.append(generatorNaming.catalogInstanceName(check)).append(".get").append(Strings.toFirstUpper(generatorExtensions.issuedCheck(expr).getName()));
    b.append("SeverityKind(");
    if (markerObject != null) {
        internalToConvertedExpression(markerObject, b, getLightweightType(eObjectType));
    } else {
        b.append(getContextImplicitVariableName(expr));
    }
    // .append(variable)
    b.append(")");
    b.append(", // Severity ").newLine();
    // marker index
    if (markerIndex != null) {
        internalToJavaExpression(markerIndex, b);
    } else {
        b.append(findKnownTopLevelType(ValidationMessageAcceptor.class, expr)).append(".INSIGNIFICANT_INDEX");
    }
    b.append(", // Marker index").newLine();
    // issue codes
    final String qualifiedIssueCodeName = generatorExtensions.qualifiedIssueCodeName(expr);
    b.append(qualifiedIssueCodeName == null ? "null" : qualifiedIssueCodeName);
    // issue data
    for (XExpression data : expr.getIssueData()) {
        b.append(", ");
        internalToJavaExpression(data, b);
    }
    b.append(" // Issue code & data").decreaseIndentation().newLine();
    b.append(");");
}
Also used : Check(com.avaloq.tools.ddk.check.check.Check) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 8 with Check

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

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

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

the class ConfiguredCheckImpl method setCheck.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setCheck(Check newCheck) {
    Check oldCheck = check;
    check = newCheck;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, CheckcfgPackage.CONFIGURED_CHECK__CHECK, oldCheck, check));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck) Check(com.avaloq.tools.ddk.check.check.Check)

Aggregations

Check (com.avaloq.tools.ddk.check.check.Check)14 ConfiguredCheck (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)4 CheckCatalog (com.avaloq.tools.ddk.check.check.CheckCatalog)3 ConfiguredCatalog (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog)3 IPluginElement (org.eclipse.pde.core.plugin.IPluginElement)3 Category (com.avaloq.tools.ddk.check.check.Category)2 FormalParameter (com.avaloq.tools.ddk.check.check.FormalParameter)2 CheckConfiguration (com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration)2 ConfiguredLanguageValidator (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredLanguageValidator)2 Function (com.google.common.base.Function)2 EObject (org.eclipse.emf.ecore.EObject)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 IPluginObject (org.eclipse.pde.core.plugin.IPluginObject)2 IQualifiedNameProvider (org.eclipse.xtext.naming.IQualifiedNameProvider)2 XExpression (org.eclipse.xtext.xbase.XExpression)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