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);
}
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);
}
}
}
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);
}
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;
}
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);
}
Aggregations