Search in sources :

Example 11 with Check

use of com.avaloq.tools.ddk.check.check.Check 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);
        }
    }
}
Also used : FormalParameter(com.avaloq.tools.ddk.check.check.FormalParameter) TemplateProposal(org.eclipse.jface.text.templates.TemplateProposal) Function(com.google.common.base.Function) ConfiguredCatalog(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck) Check(com.avaloq.tools.ddk.check.check.Check) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) StringJoiner(java.util.StringJoiner) Template(org.eclipse.jface.text.templates.Template)

Example 12 with Check

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

the class XIssueExpressionImpl 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, CheckPackage.XISSUE_EXPRESSION__CHECK, oldCheck, check));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) Check(com.avaloq.tools.ddk.check.check.Check)

Example 13 with Check

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

the class CheckContextsGenerator method updateContextsFile.

/**
 * Update contexts file.
 *
 * @param uri
 *          the uri to the current catalog
 * @param buildContext
 *          the context
 * @throws CoreException
 *           the core exception
 */
public void updateContextsFile(final URI uri, final IBuildContext buildContext) throws CoreException {
    IFile file = projectHelper.getHelpFile(uri, CheckContextsExtensionHelper.CONTEXTS_FILE_NAME);
    CtxHelpModel model = new CtxHelpModel(CoreUtility.getTextDocument(file.getContents()), false);
    model.setUnderlyingResource(file);
    model.load();
    CtxHelpRoot root = model.getCtxHelpRoot();
    CtxHelpDocumentFactory factory = model.getFactory();
    Iterable<CtxHelpContext> contexts = Iterables.filter(model.getCtxHelpRoot().getChildren(), CtxHelpContext.class);
    // all context ids belonging to the catalog
    Set<String> ids = Sets.newHashSet();
    String contextIdPrefix = projectHelper.getCatalog(buildContext, uri).getName().toLowerCase() + "_";
    for (CtxHelpContext context : contexts) {
        if (context.getId().startsWith(contextIdPrefix)) {
            ids.add(context.getId());
        }
    }
    Set<String> checkIds = Sets.newHashSet();
    // Add context for all checks which have been added
    for (Check check : projectHelper.getCatalog(buildContext, uri).getAllChecks()) {
        if (!ids.contains(generatorNaming.getContextId(check))) {
            root.addChild(createContextForCheck(factory, check));
        }
        // all contextIds constructed of the checks of the catalog
        checkIds.add(generatorNaming.getContextId(check));
    }
    // Remove context for checks which have been deleted.
    for (String id : ids) {
        if (!checkIds.contains(id)) {
            for (CtxHelpContext context : contexts) {
                if (context.getId().equals(id)) {
                    root.removeChild(context);
                }
            }
        }
    }
    sortAllContexts(model);
    model.save();
    model.dispose();
}
Also used : CtxHelpModel(org.eclipse.pde.internal.ua.core.ctxhelp.text.CtxHelpModel) IFile(org.eclipse.core.resources.IFile) CtxHelpRoot(org.eclipse.pde.internal.ua.core.ctxhelp.text.CtxHelpRoot) Check(com.avaloq.tools.ddk.check.check.Check) CtxHelpContext(org.eclipse.pde.internal.ua.core.ctxhelp.text.CtxHelpContext) CtxHelpDocumentFactory(org.eclipse.pde.internal.ua.core.ctxhelp.text.CtxHelpDocumentFactory)

Example 14 with Check

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

the class CheckHoverProvider method getHoverInfoAsHtml.

@Override
protected String getHoverInfoAsHtml(final EObject object) {
    if (!hasHover(object) || object.eIsProxy()) {
        // TODO object will be proxy in CA when referencing CheckCatalogs!
        return null;
    }
    if (object instanceof Check) {
        Check check = (Check) object;
        // a dispatcher would be nice
        StringBuffer buffer = new StringBuffer();
        buffer.append(getFirstLine(check));
        appendSection(buffer, "Description", generatorExtension.formatDescription(check.getDescription()));
        appendSection(buffer, "Message", generatorExtension.replacePlaceholder(check.getMessage()));
        return buffer.toString();
    } else if (object instanceof CheckCatalog) {
        CheckCatalog catalog = (CheckCatalog) object;
        StringBuffer buffer = new StringBuffer();
        buffer.append(getFirstLine(catalog));
        appendSection(buffer, "Description", generatorExtension.formatDescription(catalog.getDescription()));
        return buffer.toString();
    }
    return super.getHoverInfoAsHtml(object);
}
Also used : Check(com.avaloq.tools.ddk.check.check.Check) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog)

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