Search in sources :

Example 1 with IQualifiedNameProvider

use of org.eclipse.xtext.naming.IQualifiedNameProvider 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 2 with IQualifiedNameProvider

use of org.eclipse.xtext.naming.IQualifiedNameProvider 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 3 with IQualifiedNameProvider

use of org.eclipse.xtext.naming.IQualifiedNameProvider in project dsl-devkit by dsldevkit.

the class CatalogFromExtensionPointScope method getAllLocalElements.

@Override
protected Iterable<IEObjectDescription> getAllLocalElements() {
    loadDefinitions();
    if (loadedModel == null) {
        return ImmutableList.of();
    }
    XtextResource resource = (XtextResource) loadedModel.eResource();
    IQualifiedNameProvider nameProvider = resource.getResourceServiceProvider().get(IQualifiedNameProvider.class);
    return Scopes.scopedElementsFor(ImmutableList.of(loadedModel), nameProvider);
}
Also used : IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 4 with IQualifiedNameProvider

use of org.eclipse.xtext.naming.IQualifiedNameProvider in project xtext-core by eclipse.

the class DefaultResourceDescriptionManagerTest method setUp.

@Before
public void setUp() throws Exception {
    EObject copy = EcoreUtil.copy(EcorePackage.eINSTANCE);
    resource = new ResourceImpl();
    resource.getContents().add(copy);
    IQualifiedNameProvider nameProvider = new IQualifiedNameProvider.AbstractImpl() {

        @Override
        public QualifiedName getFullyQualifiedName(EObject obj) {
            if (obj instanceof ENamedElement)
                return QualifiedName.create(((ENamedElement) obj).getName());
            return null;
        }
    };
    DefaultResourceDescriptionStrategy descriptionStrategy = new DefaultResourceDescriptionStrategy();
    descriptionStrategy.setQualifiedNameProvider(nameProvider);
    resourceDescription = new DefaultResourceDescription(resource, descriptionStrategy) {

        @Override
        public Iterable<QualifiedName> getImportedNames() {
            return importedNames;
        }
    };
    manager = new DefaultResourceDescriptionManager();
    importedNames = Collections.emptySet();
}
Also used : ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) DefaultResourceDescription(org.eclipse.xtext.resource.impl.DefaultResourceDescription) EObject(org.eclipse.emf.ecore.EObject) ENamedElement(org.eclipse.emf.ecore.ENamedElement) DefaultResourceDescriptionManager(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager) DefaultResourceDescriptionStrategy(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy) Before(org.junit.Before)

Example 5 with IQualifiedNameProvider

use of org.eclipse.xtext.naming.IQualifiedNameProvider in project xtext-core by eclipse.

the class ResourceSetBasedResourceDescriptionsTest method setUp.

@Before
public void setUp() throws Exception {
    resourceSet = new ResourceSetImpl();
    IQualifiedNameProvider qualifiedNameProvider = new IQualifiedNameProvider.AbstractImpl() {

        @Override
        public QualifiedName getFullyQualifiedName(EObject obj) {
            return QualifiedName.create(((ENamedElement) obj).getName());
        }

        @Override
        public QualifiedName apply(EObject from) {
            return QualifiedName.create(((ENamedElement) from).getName());
        }
    };
    resourceDescriptionManager = new DefaultResourceDescriptionManager();
    resourceDescriptionManager.setCache(IResourceScopeCache.NullImpl.INSTANCE);
    DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy();
    strategy.setQualifiedNameProvider(qualifiedNameProvider);
    resourceDescriptionManager.setStrategy(strategy);
    resDescs = new ResourceSetBasedResourceDescriptions();
    resDescs.setContext(resourceSet);
    resDescs.setRegistry(this);
    container = new ResourceDescriptionsBasedContainer(resDescs);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) EObject(org.eclipse.emf.ecore.EObject) Before(org.junit.Before)

Aggregations

IQualifiedNameProvider (org.eclipse.xtext.naming.IQualifiedNameProvider)7 EObject (org.eclipse.emf.ecore.EObject)4 Check (com.avaloq.tools.ddk.check.check.Check)2 IPluginElement (org.eclipse.pde.core.plugin.IPluginElement)2 IPluginObject (org.eclipse.pde.core.plugin.IPluginObject)2 Before (org.junit.Before)2 NoSuchElementException (java.util.NoSuchElementException)1 ENamedElement (org.eclipse.emf.ecore.ENamedElement)1 ResourceImpl (org.eclipse.emf.ecore.resource.impl.ResourceImpl)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 IPluginAttribute (org.eclipse.pde.core.plugin.IPluginAttribute)1 DefaultDeclarativeQualifiedNameProvider (org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider)1 IQualifiedNameConverter (org.eclipse.xtext.naming.IQualifiedNameConverter)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)1 IParseResult (org.eclipse.xtext.parser.IParseResult)1 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 DefaultResourceDescription (org.eclipse.xtext.resource.impl.DefaultResourceDescription)1