Search in sources :

Example 1 with Check

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

the class CheckMarkerHelpExtensionHelper method getElements.

/**
 * Creates a marker help element for every check in the catalog. The new elements are added to the given extension.
 *
 * @param catalog
 *          the catalog
 * @param extension
 *          the extension to add the new element to
 * @return new marker help elements in given extension which don't exist yet, but should; returns an empty list if the extension is up to date
 * @throws CoreException
 *           the core exception
 */
@Override
public Iterable<IPluginElement> getElements(final CheckCatalog catalog, final IPluginExtension extension) throws CoreException {
    List<IPluginElement> result = Lists.newArrayList();
    Multimap<String, String> contextIdToAttributeValues = HashMultimap.<String, String>create();
    for (Check check : catalog.getAllChecks()) {
        final String contextId = getQualifiedContextId(extension, check);
        for (String issueCode : getIssueCodeValues(check)) {
            if (!contextIdToAttributeValues.get(contextId).contains(issueCode)) {
                contextIdToAttributeValues.put(contextId, issueCode);
                IPluginElement markerHelp = createMarkerHelpElement(extension, check, contextId);
                markerHelp.add(createAttributeElement(markerHelp, issueCode));
                result.add(markerHelp);
            }
        }
    }
    return result;
}
Also used : IPluginElement(org.eclipse.pde.core.plugin.IPluginElement) Check(com.avaloq.tools.ddk.check.check.Check)

Example 2 with Check

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

the class CheckMarkerHelpExtensionHelper method doUpdateExtension.

@Override
protected void doUpdateExtension(final CheckCatalog catalog, final IPluginExtension extension, final Iterable<IPluginElement> elements) throws CoreException {
    final IQualifiedNameProvider nameProvider = getFromServiceProvider(IQualifiedNameProvider.class, catalog);
    // Get current marker help element context IDs for this catalog
    List<String> catalogContextIds = Lists.newArrayList();
    for (final Check check : catalog.getAllChecks()) {
        catalogContextIds.add(getQualifiedContextId(extension, check));
    }
    // Remove elements of this catalog
    for (IPluginElement e : elements) {
        if (e.getAttribute(CONTEXT_ID_ATTRIBUTE_TAG) != null) {
            String contextId = e.getAttribute(CONTEXT_ID_ATTRIBUTE_TAG).getValue();
            if (isCatalogContextId(nameProvider.apply(catalog), EcoreUtil.getURI(catalog), extension, contextId)) {
                extension.remove(e);
            }
        }
    }
    // Add new elements
    Iterable<? extends IPluginObject> updatedElements = getElements(catalog, extension);
    for (IPluginObject object : updatedElements) {
        extension.add(object);
    }
}
Also used : IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) IPluginElement(org.eclipse.pde.core.plugin.IPluginElement) Check(com.avaloq.tools.ddk.check.check.Check) IPluginObject(org.eclipse.pde.core.plugin.IPluginObject)

Example 3 with Check

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

the class CheckMarkerHelpExtensionHelper method isExtensionUpdateRequired.

@Override
protected boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IPluginExtension extension, final Iterable<IPluginElement> elements) {
    // TODO should check if this check is too expensive; consider rewriting contents instead
    if (!super.isExtensionUpdateRequired(catalog, extension, elements)) {
        return false;
    }
    final IQualifiedNameProvider nameProvider = getFromServiceProvider(IQualifiedNameProvider.class, catalog);
    // collect all data in the extension model: mapping<context id, pair<execution mode, issue code>>
    HashMultimap<String, Pair<String, String>> contextToValue = HashMultimap.<String, Pair<String, String>>create();
    for (IPluginElement e : elements) {
        if (e.getAttribute(CONTEXT_ID_ATTRIBUTE_TAG) != null) {
            String contextId = e.getAttribute(CONTEXT_ID_ATTRIBUTE_TAG).getValue();
            String mode = e.getAttribute(MARKERTYPE_ATTRIBUTE_TAG).getValue();
            if (isCatalogContextId(nameProvider.apply(catalog), EcoreUtil.getURI(catalog), extension, contextId)) {
                for (IPluginObject o : e.getChildren()) {
                    if (o instanceof IPluginElement && ((IPluginElement) o).getAttribute(ATTRIBUTE_VALUE_TAG) != null) {
                        // NOPMD
                        IPluginAttribute attribute = ((IPluginElement) o).getAttribute(ATTRIBUTE_VALUE_TAG);
                        contextToValue.put(contextId, Tuples.create(mode, attribute.getValue()));
                    }
                }
            }
        }
    }
    // check that the real model and the extension model have the same number of issue codes
    Iterable<String> allExtensionIssueCodes = Iterables.transform(contextToValue.values(), new Function<Pair<String, String>, String>() {

        @Override
        public String apply(final Pair<String, String> input) {
            return input.getSecond();
        }
    });
    if (Iterables.size(allExtensionIssueCodes) != Sets.newHashSet(getAllIssueCodeValues(catalog)).size()) {
        return true;
    }
    // check all relevant data, e.g. detect change of execution mode
    for (final Check check : catalog.getAllChecks()) {
        final Iterable<String> allModelIssueCodes = getIssueCodeValues(check);
        for (final String issueCode : allModelIssueCodes) {
            final String contextId = getQualifiedContextId(extension, check);
            if (contextToValue.containsKey(contextId)) {
                Set<Pair<String, String>> modeToValues = contextToValue.get(contextId);
                try {
                    Iterables.find(modeToValues, new Predicate<Pair<String, String>>() {

                        @Override
                        public boolean apply(final Pair<String, String> input) {
                            return input.getFirst().equals(getCheckType(check)) && input.getSecond().equals(issueCode);
                        }
                    });
                } catch (NoSuchElementException e) {
                    return true;
                }
            } else {
                // context id not present in extension model
                return true;
            }
        }
    }
    return false;
}
Also used : IPluginElement(org.eclipse.pde.core.plugin.IPluginElement) Check(com.avaloq.tools.ddk.check.check.Check) IPluginAttribute(org.eclipse.pde.core.plugin.IPluginAttribute) IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) IPluginObject(org.eclipse.pde.core.plugin.IPluginObject) NoSuchElementException(java.util.NoSuchElementException) Pair(org.eclipse.xtext.util.Pair)

Example 4 with Check

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

the class CheckTocGenerator method addTopicToToc.

/**
 * Adds the topic to toc model.
 *
 * @param model
 *          the model
 * @param label
 *          topic label
 * @param reference
 *          topic reference
 * @param uri
 *          the uri
 * @param buildContext
 *          the context
 * @throws CoreException
 *           CoreException
 */
private void addTopicToToc(final TocModel model, final String label, final String reference, final URI uri, final IBuildContext buildContext) throws CoreException {
    TocTopic topic = model.getFactory().createTocTopic();
    topic.setFieldLabel(label);
    topic.setFieldRef(reference);
    topic.setXMLAttribute(SORT_KEY, "false");
    // Add catalogs and checks as sub-topics
    TocTopic categoryTopic;
    TocTopic checkTopic;
    for (Category category : projectHelper.getCatalog(buildContext, uri).getCategories()) {
        categoryTopic = model.getFactory().createTocTopic();
        categoryTopic.setFieldLabel(category.getLabel());
        categoryTopic.setFieldRef(reference + '#' + generatorNaming.getContextId(category));
        for (Check check : category.getChecks()) {
            checkTopic = model.getFactory().createTocTopic();
            checkTopic.setFieldLabel(check.getLabel());
            checkTopic.setFieldRef(reference + '#' + generatorNaming.getContextId(check));
            categoryTopic.addChild(checkTopic);
        }
        topic.addChild(categoryTopic);
    }
    for (Check check : projectHelper.getCatalog(buildContext, uri).getChecks()) {
        checkTopic = model.getFactory().createTocTopic();
        checkTopic.setFieldLabel(check.getLabel());
        checkTopic.setFieldRef(reference + '#' + generatorNaming.getContextId(check));
        topic.addChild(checkTopic);
    }
    // Add TOC at the right position (to have them sorted alphabetically by label)
    IDocumentElementNode[] children = model.getToc().getChildNodes();
    String childLabel;
    boolean added = false;
    for (IDocumentElementNode child : children) {
        if (child instanceof TocTopic) {
            childLabel = ((TocTopic) child).getFieldLabel();
            if (childLabel.compareTo(label) > 0) {
                // childLabel is alphabetically after the label of the new toc
                model.getToc().addChild(topic, (TocTopic) child, true);
                added = true;
                break;
            }
        }
    }
    if (!added) {
        model.getToc().addChild(topic);
    }
}
Also used : Category(com.avaloq.tools.ddk.check.check.Category) IDocumentElementNode(org.eclipse.pde.internal.core.text.IDocumentElementNode) Check(com.avaloq.tools.ddk.check.check.Check) TocTopic(org.eclipse.pde.internal.ua.core.toc.text.TocTopic)

Example 5 with Check

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

the class CheckOutlineTreeProvider method internalCreateChildren.

@Override
protected void internalCreateChildren(final DocumentRootNode parentNode, final EObject modelElement) {
    CheckCatalog catalog = (CheckCatalog) modelElement;
    if (catalog.getPackageName() != null) {
        getOutlineNodeFactory().createEStructuralFeatureNode(parentNode, catalog, CheckPackage.Literals.CHECK_CATALOG__PACKAGE_NAME, ImageDescriptor.createFromImage(checkImages.forPackage()), catalog.getPackageName(), true);
    }
    if (catalog.getImports() != null && !catalog.getImports().getImportDeclarations().isEmpty()) {
        EStructuralFeatureNode importNode = getOutlineNodeFactory().createEStructuralFeatureNode(parentNode, catalog, CheckPackage.Literals.CHECK_CATALOG__IMPORTS, ImageDescriptor.createFromImage(checkImages.forImportContainer()), "Import declarations", false);
        for (final org.eclipse.xtext.xtype.XImportDeclaration imported : catalog.getImports().getImportDeclarations()) {
            createNode(importNode, imported);
        }
    }
    EObjectNode catalogNode = createNode(parentNode, catalog);
    for (final Category category : catalog.getCategories()) {
        createNode(catalogNode, category);
    }
    for (final Check check : catalog.getChecks()) {
        createNode(catalogNode, check);
    }
}
Also used : Category(com.avaloq.tools.ddk.check.check.Category) EStructuralFeatureNode(org.eclipse.xtext.ui.editor.outline.impl.EStructuralFeatureNode) Check(com.avaloq.tools.ddk.check.check.Check) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) EObjectNode(org.eclipse.xtext.ui.editor.outline.impl.EObjectNode)

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