/** * 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); }
/** * 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); }
/** * 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; }
/** * Provides new instances of the ImportedNamesAdapter, e.g. concrete instances of N4JSImportedNamesAdapter. * * @see ImportedNamesAdapter */ public Provider<ImportedNamesAdapter> provideImportedNamesAdapter() { return new Provider<ImportedNamesAdapter>() { @Override public ImportedNamesAdapter get() { return new N4JSImportedNamesAdapter(); } }; }
@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(); }
/** * {@inheritDoc} */ @Override public Map<QualifiedName, Set<EClass>> getImportedNamesTypes() { ImportedNamesAdapter adapter = ImportedNamesAdapter.find(getResource()); if (adapter instanceof ImportedNamesTypesAdapter) { return ImmutableMap.copyOf(((ImportedNamesTypesAdapter) adapter).getImportedNamesTypes()); } return Maps.newHashMap(); }
/** * 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; }
/** * {@inheritDoc} */ @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; }