Search in sources :

Example 96 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project dsl-devkit by dsldevkit.

the class BugAig1314 method testSameScopeUseTwice.

/**
 * Tests that querying the same scope twice doesn't make the resource set grow.
 */
@Test
public void testSameScopeUseTwice() {
    XtextResourceSet rs = new XtextResourceSet();
    URL url = createURL();
    ModelLocation modelLocation = createModelLocation(url);
    CatalogFromExtensionPointScope scope = new TestScope(modelLocation, rs);
    assertResourceSetEmpty(rs);
    Iterable<IEObjectDescription> elements = scope.getAllElements();
    assertIterableNotEmpty(elements);
    int nofResourcesInMap = rs.getURIResourceMap().size();
    int nofResourcesInSet = rs.getResources().size();
    elements = scope.getAllElements();
    assertIterableNotEmpty(elements);
    assertResourceSet(rs, nofResourcesInSet, nofResourcesInMap);
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IModelLocation(com.avaloq.tools.ddk.check.runtime.configuration.IModelLocation) ModelLocation(com.avaloq.tools.ddk.check.runtime.configuration.ModelLocation) URL(java.net.URL) CatalogFromExtensionPointScope(com.avaloq.tools.ddk.check.scoping.CatalogFromExtensionPointScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 97 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription 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 98 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project dsl-devkit by dsldevkit.

the class AbstractScopingTest method assertScopedObjects.

/**
 * Checks if the scope of the given reference for the given context contains only the expected objects.
 * In addition, checks that the reference of the given context references at least one of the expected
 * objects. If the reference has multiplicity > 1, then every reference must reference at least
 * one of the expected objects.
 *
 * @param context
 *          {@link EObject} from which the given objects shall be referenced, must not be {@code null}
 * @param reference
 *          the structural feature of {@code context} for which the scope should be asserted, must not be {@code null} and part of the context element
 * @param expectedObjects
 *          the objects expected in the scope, must not be {@code null}
 */
protected void assertScopedObjects(final EObject context, final EReference reference, final Collection<? extends EObject> expectedObjects) {
    Assert.isNotNull(context, PARAMETER_CONTEXT);
    Assert.isNotNull(reference, PARAMETER_REFERENCE);
    Assert.isNotNull(expectedObjects, PARAMETER_EXPECTED_OBJECTS);
    Assert.isTrue(context.eClass().getEAllReferences().contains(reference), String.format("Contract for argument '%s' failed: Parameter is not within specified range (Expected: %s, Actual: %s).", PARAMETER_CONTEXT, "The context object must contain the given reference.", "Reference not contained by the context object!"));
    Set<URI> expectedUriSet = Sets.newHashSet();
    for (EObject object : expectedObjects) {
        expectedUriSet.add(EcoreUtil.getURI(object));
    }
    IScope scope = getScopeProvider().getScope(context, reference);
    Iterable<IEObjectDescription> allScopedElements = scope.getAllElements();
    Set<URI> scopedUriSet = Sets.newHashSet();
    for (IEObjectDescription description : allScopedElements) {
        URI uri = description.getEObjectURI();
        scopedUriSet.add(uri);
    }
    if (!expectedUriSet.equals(scopedUriSet)) {
        fail("The scope must exactly consist of the expected URIs. Missing " + Sets.difference(expectedUriSet, scopedUriSet) + " extra " + Sets.difference(scopedUriSet, expectedUriSet));
    }
    // test that link resolving worked
    boolean elementResolved;
    if (reference.isMany()) {
        @SuppressWarnings("unchecked") EList<EObject> objects = (EList<EObject>) context.eGet(reference, true);
        // NOPMD
        elementResolved = !objects.isEmpty();
        for (Iterator<EObject> objectIter = objects.iterator(); objectIter.hasNext() && elementResolved; ) {
            EObject eObject = EcoreUtil.resolve(objectIter.next(), context);
            elementResolved = expectedUriSet.contains(EcoreUtil.getURI(eObject));
        }
    } else {
        EObject resolvedObject = (EObject) context.eGet(reference, true);
        elementResolved = expectedUriSet.contains(EcoreUtil.getURI(resolvedObject));
    }
    assertTrue("Linking must have resolved one of the expected objects.", elementResolved);
}
Also used : EObjectResolvingEList(org.eclipse.emf.ecore.util.EObjectResolvingEList) EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 99 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project dsl-devkit by dsldevkit.

the class AbstractCachingResourceDescriptionManager method isReferencedBy.

/**
 * Determines if a given candidate is affected by a given delta.
 *
 * @param delta
 *          delta
 * @param candidate
 *          candidate
 * @param context
 *          context index
 * @return true if the candidate is affected
 */
protected boolean isReferencedBy(final Delta delta, final IResourceDescription candidate, final IResourceDescriptions context) {
    URI candidateURI = candidate.getURI();
    if (delta instanceof ResourceDescriptionDelta && ((ResourceDescriptionDelta) delta).hasObjectFingerprints()) {
        ResourceDescriptionDelta detailedDelta = (ResourceDescriptionDelta) delta;
        final Set<IEObjectDescription> changedOrDeletedObjects = Sets.newHashSet(Iterables.concat(detailedDelta.getChangedObjects(), detailedDelta.getDeletedObjects()));
        for (IResourceDescription desc : ((IResourceDescriptions2) context).findExactReferencingResources(changedOrDeletedObjects, ReferenceMatchPolicy.REFERENCES)) {
            if (desc.getURI().equals(candidateURI)) {
                return true;
            }
        }
        for (IResourceDescription desc : ((IResourceDescriptions2) context).findExactReferencingResources(Sets.newHashSet(detailedDelta.getAddedObjects()), ReferenceMatchPolicy.UNRESOLVED_IMPORTED_NAMES)) {
            if (desc.getURI().equals(candidateURI)) {
                return true;
            }
        }
    } else {
        IResourceDescription resource = delta.getNew() != null ? delta.getNew() : delta.getOld();
        for (IResourceDescription desc : ((IResourceDescriptions2) context).findAllReferencingResources(ImmutableSet.of(resource), ReferenceMatchPolicy.ALL)) {
            if (desc.getURI().equals(candidateURI)) {
                return true;
            }
        }
    }
    return false;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) URI(org.eclipse.emf.common.util.URI) IResourceDescriptions2(com.avaloq.tools.ddk.xtext.resource.extensions.IResourceDescriptions2) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 100 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project ow by vtst.

the class GlobalScopeWithBuiltins method getElements.

@Override
public Iterable<IEObjectDescription> getElements(EObject object) {
    final URI uri = EcoreUtil2.getNormalizedURI(object);
    Iterable<IEObjectDescription> globalElements = globalScope.getElements(object);
    Iterable<IEObjectDescription> builtinElements = getBuiltinElementsByEObject(object, uri);
    return Iterables.concat(globalElements, builtinElements);
}
Also used : URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)324 Test (org.junit.Test)95 EObject (org.eclipse.emf.ecore.EObject)82 QualifiedName (org.eclipse.xtext.naming.QualifiedName)79 IScope (org.eclipse.xtext.scoping.IScope)56 URI (org.eclipse.emf.common.util.URI)41 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)33 EClass (org.eclipse.emf.ecore.EClass)30 Resource (org.eclipse.emf.ecore.resource.Resource)28 EObjectDescription (org.eclipse.xtext.resource.EObjectDescription)22 AliasedEObjectDescription (org.eclipse.xtext.resource.impl.AliasedEObjectDescription)22 ArrayList (java.util.ArrayList)19 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)14 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)12 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)12 StyledString (org.eclipse.jface.viewers.StyledString)12 XtextResource (org.eclipse.xtext.resource.XtextResource)11 StringInputStream (org.eclipse.xtext.util.StringInputStream)11 EReference (org.eclipse.emf.ecore.EReference)10 List (java.util.List)9