Java Code Examples for org.eclipse.emf.ecore.util.EcoreUtil#getExistingAdapter()

The following examples show how to use org.eclipse.emf.ecore.util.EcoreUtil#getExistingAdapter() . 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: SemanticSequencerExtensions.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public Grammar getSuperGrammar(final Grammar grammar) {
  boolean _isEmpty = grammar.getUsedGrammars().isEmpty();
  if (_isEmpty) {
    return null;
  }
  Adapter _existingAdapter = EcoreUtil.getExistingAdapter(grammar, SemanticSequencerExtensions.SuperGrammar.class);
  SemanticSequencerExtensions.SuperGrammar sg = ((SemanticSequencerExtensions.SuperGrammar) _existingAdapter);
  if ((sg != null)) {
    return sg.grammar;
  }
  final URI uri = IterableExtensions.<Grammar>head(grammar.getUsedGrammars()).eResource().getURI();
  final Resource resource = this.cloneResourceSet(grammar.eResource().getResourceSet()).getResource(uri, true);
  EObject _head = IterableExtensions.<EObject>head(resource.getContents());
  final Grammar result = ((Grammar) _head);
  EList<Adapter> _eAdapters = grammar.eAdapters();
  SemanticSequencerExtensions.SuperGrammar _superGrammar = new SemanticSequencerExtensions.SuperGrammar(result);
  _eAdapters.add(_superGrammar);
  return result;
}
 
Example 2
Source File: AbstractSCTResource.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void attachedHelper(EObject eObject) {
	super.attachedHelper(eObject);
	if (eObject instanceof SpecificationElement) {
		Adapter parseAdapter = EcoreUtil.getExistingAdapter(eObject, ParseAdapter.class);
		if (parseAdapter == null) {
			parseSpecificationElement((SpecificationElement) eObject);
			linkSpecificationElement((SpecificationElement) eObject);
			eObject.eAdapters().add(new ParseAdapter());
		}
		Adapter serializeAdapter = EcoreUtil.getExistingAdapter(eObject, SerializeAdapter.class);
		if (serializeAdapter == null) {
			eObject.eAdapters().add(new SerializeAdapter());
		}
	}
}
 
Example 3
Source File: GModelIndex.java    From graphical-lsp with Eclipse Public License 2.0 5 votes vote down vote up
public static void remove(GModelElement element) {
	EObject root = EcoreUtil.getRootContainer(element);
	GModelIndexImpl existingIndex = (GModelIndexImpl) EcoreUtil.getExistingAdapter(root, GModelIndexImpl.class);
	if (existingIndex == null) {
		return;
	}
	existingIndex.unsetTarget(root);
}
 
Example 4
Source File: GModelChangeNotifier.java    From graphical-lsp with Eclipse Public License 2.0 5 votes vote down vote up
public static void remove(GModelElement element) {
	EObject root = EcoreUtil.getRootContainer(element);
	GModelChangeNotifierImpl existingNotifier = (GModelChangeNotifierImpl) EcoreUtil.getExistingAdapter(root,
			GModelChangeNotifierImpl.class);
	if (existingNotifier == null) {
		return;
	}
	existingNotifier.unsetTarget(root);
}
 
Example 5
Source File: JavaConfig.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public static JavaConfig findInEmfObject(Notifier emfObject) {
	JavaConfigAdapter adapter = (JavaConfigAdapter) EcoreUtil.getExistingAdapter(emfObject, JavaConfig.class);
	if (adapter != null) {
		return adapter.get();
	}
	return null;
}
 
Example 6
Source File: ClassFileCache.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public static ClassFileCache findInEmfObject(Notifier emfObject) {
	ClassFileCacheAdapter adapter = ((ClassFileCacheAdapter) EcoreUtil.getExistingAdapter(emfObject, ClassFileCache.class));
	if (adapter != null) {
		return adapter.get();
	}
	return null;
}
 
Example 7
Source File: DirtyStateAwareDiagramDocumentEditor.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private void createDirtyResource(Resource resource) {
	IResourceServiceProvider resourceServiceProvider = IResourceServiceProvider.Registry.INSTANCE
			.getResourceServiceProvider(resource.getURI());
	if (resourceServiceProvider == null) {
		return;
	}
	final DirtyResourceAdapter dirtyResource = new DirtyResourceAdapter(
			resource, resourceServiceProvider);
	dirtyStateManager.manageDirtyState(dirtyResource);
	uri2dirtyResource.put(resource.getURI(), dirtyResource);
	if (EcoreUtil.getExistingAdapter(resource, DirtyResourceUpdater.class) == null)
		resource.eAdapters().add(new DirtyResourceUpdater(dirtyResource));
}
 
Example 8
Source File: AbstractSCTResource.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void detachedHelper(EObject eObject) {
	if (eObject instanceof SpecificationElement) {
		Adapter parseAdapter = EcoreUtil.getExistingAdapter(eObject, ParseAdapter.class);
		if (parseAdapter != null) {
			eObject.eAdapters().remove(parseAdapter);
		}
		Adapter serializeAdapter = EcoreUtil.getExistingAdapter(eObject, SerializeAdapter.class);
		if (serializeAdapter != null) {
			eObject.eAdapters().remove(serializeAdapter);
		}
	}
	super.detachedHelper(eObject);
}
 
Example 9
Source File: GModelIndex.java    From graphical-lsp with Eclipse Public License 2.0 4 votes vote down vote up
public static GModelIndex get(GModelElement element) {
	EObject root = EcoreUtil.getRootContainer(element);
	GModelIndex existingIndex = (GModelIndexImpl) EcoreUtil.getExistingAdapter(root, GModelIndexImpl.class);
	return Optional.ofNullable(existingIndex).orElseGet(() -> (create(element)));
}
 
Example 10
Source File: GModelChangeNotifier.java    From graphical-lsp with Eclipse Public License 2.0 4 votes vote down vote up
public static GModelChangeNotifier get(GModelElement element) {
	EObject root = EcoreUtil.getRootContainer(element);
	GModelChangeNotifier existingNotifier = (GModelChangeNotifierImpl) EcoreUtil.getExistingAdapter(root,
			GModelChangeNotifierImpl.class);
	return Optional.ofNullable(existingNotifier).orElseGet(() -> create(element));
}
 
Example 11
Source File: ResourceStorageFacade.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected ResourceStorageProviderAdapter getResourceStorageProviderAdapter(ResourceSet resourceSet) {
	return (ResourceStorageProviderAdapter) EcoreUtil.getExistingAdapter(
			resourceSet, ResourceStorageProviderAdapter.class);
}
 
Example 12
Source File: STextExtensions.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected ContextElementAdapter getContextElementAdapter(Resource context) {
	return (ContextElementAdapter) EcoreUtil.getExistingAdapter(context, ContextElementAdapter.class);
}