Search in sources :

Example 1 with IPluginAttribute

use of org.eclipse.pde.core.plugin.IPluginAttribute 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)

Aggregations

Check (com.avaloq.tools.ddk.check.check.Check)1 NoSuchElementException (java.util.NoSuchElementException)1 IPluginAttribute (org.eclipse.pde.core.plugin.IPluginAttribute)1 IPluginElement (org.eclipse.pde.core.plugin.IPluginElement)1 IPluginObject (org.eclipse.pde.core.plugin.IPluginObject)1 IQualifiedNameProvider (org.eclipse.xtext.naming.IQualifiedNameProvider)1 Pair (org.eclipse.xtext.util.Pair)1