Java Code Examples for org.eclipse.emf.ecore.resource.Resource#eAdapters()

The following examples show how to use org.eclipse.emf.ecore.resource.Resource#eAdapters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OnChangeEvictingCacheAdapterTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testCacheSurvivesChangesToAdapters() throws Exception {
	EcoreFactory factory = EcoreFactory.eINSTANCE;
	EClass eClass = factory.createEClass();
	Resource resource = new ResourceImpl();
	resource.getContents().add(eClass);
	CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource);
	setValue(ca);
	List<Adapter> adapters = resource.eAdapters();
	assertIsSet(ca);
	AdapterImpl adapter = new AdapterImpl();
	adapters.add(adapter);
	assertIsSet(ca);
	adapters.remove(adapter);
	assertIsSet(ca);
}
 
Example 2
Source File: ActiveAnnotationContexts.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public static ActiveAnnotationContexts installNew(final Resource resource) {
  ActiveAnnotationContexts result = IterableExtensions.<ActiveAnnotationContexts>head(Iterables.<ActiveAnnotationContexts>filter(resource.eAdapters(), ActiveAnnotationContexts.class));
  if ((result != null)) {
    result.contexts.clear();
  } else {
    ActiveAnnotationContexts _activeAnnotationContexts = new ActiveAnnotationContexts();
    result = _activeAnnotationContexts;
    EList<Adapter> _eAdapters = resource.eAdapters();
    _eAdapters.add(result);
  }
  return result;
}
 
Example 3
Source File: ImportedNamesAdapter.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public static ImportedNamesAdapter find(Resource resource) {
	for (Adapter adapter : resource.eAdapters()) {
		if (adapter instanceof ImportedNamesAdapter) {
			return (ImportedNamesAdapter) adapter;
		}
	}
	return null;
}
 
Example 4
Source File: ImplicitReferencesAdapter.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the adapter registered for a resource.
 *
 * @param resource
 *          resource to get adapter for
 * @return the registered adapter or <code>null</code>
 */
public static ImplicitReferencesAdapter find(final Resource resource) {
  for (Adapter adapter : resource.eAdapters()) {
    if (adapter instanceof ImplicitReferencesAdapter) {
      return (ImplicitReferencesAdapter) adapter;
    }
  }
  return null;
}
 
Example 5
Source File: ImportedNamesTypesAdapter.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns registered ImportedNameAdapter for given resource.
 *
 * @param resource
 *          Resource for which adapter should be returned.
 * @return registered importedNamesTypesAdapter.
 */
public static ImportedNamesTypesAdapter find(final Resource resource) {
  for (Adapter adapter : resource.eAdapters()) {
    if (adapter instanceof ImportedNamesAdapter) {
      return (ImportedNamesTypesAdapter) adapter;
    }
  }
  return null;
}