Search in sources :

Example 6 with CheckCatalog

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

the class ConfiguredCatalogImpl method setCatalog.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setCatalog(CheckCatalog newCatalog) {
    CheckCatalog oldCatalog = catalog;
    catalog = newCatalog;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, CheckcfgPackage.CONFIGURED_CATALOG__CATALOG, oldCatalog, catalog));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog)

Example 7 with CheckCatalog

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

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

the class CheckCfgTemplateProposalProvider method addCatalogConfigurations.

/**
 * Adds the populated check configuration.
 *
 * @param templateContext
 *          the template context
 * @param context
 *          the context
 * @param acceptor
 *          the acceptor
 */
@SuppressWarnings("all")
private void addCatalogConfigurations(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) {
    // $NON-NLS-1$
    final String templateName = "Add all registered catalogs";
    // $NON-NLS-1$
    final String templateDescription = "configures all missing catalogs";
    final String contextTypeId = templateContext.getContextType().getId();
    if (context.getRootModel() instanceof CheckConfiguration) {
        final CheckConfiguration conf = (CheckConfiguration) context.getRootModel();
        List<IEObjectDescription> allElements = Lists.newArrayList(scopeProvider.getScope(conf, CheckcfgPackage.Literals.CONFIGURED_CATALOG__CATALOG).getAllElements());
        StringBuilder builder = new StringBuilder();
        for (IEObjectDescription description : allElements) {
            if (description.getEObjectOrProxy() instanceof CheckCatalog) {
                CheckCatalog catalog = (CheckCatalog) description.getEObjectOrProxy();
                if (catalog.eIsProxy()) {
                    catalog = (CheckCatalog) EcoreUtil.resolve(catalog, conf);
                }
                if (isCatalogConfigured(conf, catalog)) {
                    continue;
                } else if (allElements.indexOf(description) > 0) {
                    builder.append(Strings.newLine());
                }
                final String catalogName = qualifiedNameValueConverter.toString(description.getQualifiedName().toString());
                // $NON-NLS-1$ //$NON-NLS-2$
                builder.append("catalog ").append(catalogName).append(" {}").append(Strings.newLine());
            }
        }
        if (builder.length() > 0) {
            // $NON-NLS-1$
            builder.append("${cursor}");
            Template t = new Template(templateName, templateDescription, contextTypeId, builder.toString(), true);
            TemplateProposal tp = createProposal(t, templateContext, context, images.forConfiguredCatalog(), getRelevance(t));
            acceptor.accept(tp);
        }
    }
}
Also used : TemplateProposal(org.eclipse.jface.text.templates.TemplateProposal) CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Template(org.eclipse.jface.text.templates.Template)

Example 9 with CheckCatalog

use of com.avaloq.tools.ddk.check.check.CheckCatalog 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);
    }
}
Also used : Function(com.google.common.base.Function) ConfiguredCatalog(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) Predicate(com.google.common.base.Predicate) Check(org.eclipse.xtext.validation.Check) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)

Example 10 with CheckCatalog

use of com.avaloq.tools.ddk.check.check.CheckCatalog 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);
}
Also used : CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) ConfiguredCatalog(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog) EList(org.eclipse.emf.common.util.EList) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog)

Aggregations

CheckCatalog (com.avaloq.tools.ddk.check.check.CheckCatalog)17 IPluginElement (org.eclipse.pde.core.plugin.IPluginElement)4 IPluginExtension (org.eclipse.pde.core.plugin.IPluginExtension)4 Test (org.junit.Test)4 Check (com.avaloq.tools.ddk.check.check.Check)3 ConfiguredCatalog (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog)3 ConfiguredCheck (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)3 FormalParameter (com.avaloq.tools.ddk.check.check.FormalParameter)2 CheckConfiguration (com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration)2 Function (com.google.common.base.Function)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 Template (org.eclipse.jface.text.templates.Template)2 TemplateProposal (org.eclipse.jface.text.templates.TemplateProposal)2 IPluginObject (org.eclipse.pde.core.plugin.IPluginObject)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 Check (org.eclipse.xtext.validation.Check)2 Category (com.avaloq.tools.ddk.check.check.Category)1