org.eclipse.xtext.linking.impl.ImportedNamesAdapter Java Examples

The following examples show how to use org.eclipse.xtext.linking.impl.ImportedNamesAdapter. 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: N4JSLinker.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Removes the imported names before linking and cleans other caches attached to the AST.
 */
@Override
protected void beforeModelLinked(EObject model, IDiagnosticConsumer diagnosticsConsumer) {
	ImportedNamesAdapter adapter = ImportedNamesAdapter.find(model.eResource());
	if (adapter != null)
		adapter.clear();

	ComposedMemberScope.clearCachedComposedMembers(model);
}
 
Example #2
Source File: ImportedNamesRecordingScopeAccess.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Obtain a global scope to lookup polyfills. Any request by name on the returned scope will record the name in the
 * list of imported names of the given context resource.
 */
public IScope getRecordingPolyfillScope(Resource context) {
	ImportedNamesAdapter importedNamesAdapter = getImportedNamesAdapter(context);
	IScope scope = globalScopeProvider.getScope(context,
			TypeRefsPackage.Literals.PARAMETERIZED_TYPE_REF__DECLARED_TYPE, null);
	return importedNamesAdapter.wrap(scope);
}
 
Example #3
Source File: ImportedNamesRecordingScopeAccess.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Obtain the previously registered adapter for the imported names or register a new one.
 *
 * @param context
 *            the resource that is supposed to hold the adapter
 */
private ImportedNamesAdapter getImportedNamesAdapter(Resource context) {
	ImportedNamesAdapter adapter = ImportedNamesAdapter.find(context);
	if (adapter != null)
		return adapter;
	ImportedNamesAdapter importedNamesAdapter = importedNamesAdapterProvider.get();
	context.eAdapters().add(importedNamesAdapter);
	return importedNamesAdapter;
}
 
Example #4
Source File: N4JSRuntimeModule.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Provides new instances of the ImportedNamesAdapter, e.g. concrete instances of N4JSImportedNamesAdapter.
 *
 * @see ImportedNamesAdapter
 */
public Provider<ImportedNamesAdapter> provideImportedNamesAdapter() {
	return new Provider<>() {
		@Override
		public ImportedNamesAdapter get() {
			return new N4JSImportedNamesAdapter();
		}
	};
}
 
Example #5
Source File: DefaultResourceDescription.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<QualifiedName> getImportedNames() {
	EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	ImportedNamesAdapter adapter = ImportedNamesAdapter.find(getResource());
	if (adapter != null) {
		ImmutableSet<QualifiedName> result = ImmutableSet.copyOf(adapter.getImportedNames());
		return result;
	}
	return Collections.emptySet();
}
 
Example #6
Source File: ResourceDescription2.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Map<QualifiedName, Set<EClass>> getImportedNamesTypes() {
  ImportedNamesAdapter adapter = ImportedNamesAdapter.find(getResource());
  if (adapter instanceof ImportedNamesTypesAdapter) {
    return ImmutableMap.copyOf(((ImportedNamesTypesAdapter) adapter).getImportedNamesTypes());
  }
  return Collections.emptyMap();
}
 
Example #7
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;
}
 
Example #8
Source File: LinkingService.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected ImportedNamesTypesAdapter getImportedNamesAdapter(final EObject context) {
  ImportedNamesAdapter adapter = ImportedNamesAdapter.find(context.eResource());
  if (adapter instanceof ImportedNamesTypesAdapter) {
    return (ImportedNamesTypesAdapter) adapter;
  }
  ImportedNamesTypesAdapter importedNamesTypeAdapter = importedNamesAdapterProvider.get();
  context.eResource().eAdapters().add(importedNamesTypeAdapter);
  return importedNamesTypeAdapter;
}
 
Example #9
Source File: XtendImportedNamespaceScopeProvider.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected Set<QualifiedName> getImportedNamesSet(Resource resource) {
	ImportedNamesAdapter adapter = getImportedNamesAdapter(resource);
	return adapter.getImportedNames();
}
 
Example #10
Source File: XtendImportedNamespaceScopeProvider.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected ImportedNamesAdapter getImportedNamesAdapter(Resource resource) {
	return ImportedNamesAdapter.findOrInstall(resource);
}