use of org.eclipse.xtext.resource.IResourceDescriptions in project xtext-xtend by eclipse.
the class XtendImportedNamespaceScopeProvider method getScope.
@Override
public IScope getScope(final EObject context, final EReference reference) {
EClass referenceType = reference.getEReferenceType();
if (TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(referenceType)) {
if (context instanceof XImportDeclaration) {
Resource resource = context.eResource();
IJvmTypeProvider typeProvider = typeScopeProvider.getTypeProvider(resource.getResourceSet());
AbstractTypeScope typeScope = typeScopeProvider.createTypeScope(typeProvider, null);
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(context.eResource().getResourceSet());
IResourceDescription resourceDescription = descriptions.getResourceDescription(resource.getURI());
if (resourceDescription != null) {
typeScope = new LocalResourceFilteringTypeScope(typeScope, resourceDescription);
}
RecordingTypeScope recordingTypeScope = new RecordingTypeScope(typeScope, getImportedNamesSet(resource), getQualifiedNameConverter());
// TODO this scope doesn't support binary syntax for inner types. It should be a KnownTypes scope which doesn't allow simple names
// Unfortunately I cannot use a RecordingTypeScope as a parent as it is not compatible...
IScope scope = SelectableBasedScope.createScope(recordingTypeScope, getAllDescriptions(resource), reference.getEReferenceType(), false);
return scope;
}
final XtendFile xtendFile = getXtendFile(context);
final Resource resource = xtendFile.eResource();
AbstractScope result = resourceScopeCache.get("type.scope", xtendFile.eResource(), new Provider<AbstractScope>() {
@Override
public AbstractScope get() {
IJvmTypeProvider typeProvider = typeScopeProvider.getTypeProvider(resource.getResourceSet());
AbstractTypeScope typeScope = typeScopeProvider.createTypeScope(typeProvider, null);
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(context.eResource().getResourceSet());
IResourceDescription resourceDescription = descriptions.getResourceDescription(resource.getURI());
if (resourceDescription != null) {
typeScope = new LocalResourceFilteringTypeScope(typeScope, resourceDescription);
}
RecordingTypeScope recordingTypeScope = new RecordingTypeScope(typeScope, getImportedNamesSet(resource), getQualifiedNameConverter());
AbstractScope rootTypeScope = getRootTypeScope(xtendFile, recordingTypeScope);
AbstractScope importScope = getImportScope(xtendFile.getImportSection(), rootTypeScope, recordingTypeScope);
AbstractScope localTypes = getResourceTypeScope(xtendFile.eResource(), xtendFile.getPackage(), importScope);
AbstractScope primitiveAware = new PrimitiveAwareScope(localTypes, typeScope);
AbstractScope caching = new CachingTypeScope(primitiveAware);
return caching;
}
});
if (context instanceof AnonymousClass) {
// necessary for the super type of an anonymous class expression
JvmDeclaredType inferredAnonymousType = associations.getInferredType((AnonymousClass) context);
if (inferredAnonymousType != null)
result = new LocalTypeScope(singletonList(inferredAnonymousType), result);
}
XtendMember syntacticContainer = EcoreUtil2.getContainerOfType(context, XtendMember.class);
if (syntacticContainer != null) {
result = getContainerScope(syntacticContainer, result);
}
EObject logicalContainer = logicalContainerProvider.getNearestLogicalContainer(context);
if (logicalContainer != null) {
List<List<JvmTypeParameter>> typeParameters = new ArrayList<List<JvmTypeParameter>>();
while (logicalContainer instanceof JvmTypeParameterDeclarator) {
JvmTypeParameterDeclarator typeParamProvider = (JvmTypeParameterDeclarator) logicalContainer;
if (!typeParamProvider.getTypeParameters().isEmpty()) {
typeParameters.add(typeParamProvider.getTypeParameters());
}
logicalContainer = logicalContainer.eContainer();
}
if (!typeParameters.isEmpty())
result = new TypeParameterScope(typeParameters, result);
}
return result;
} else if (TypesPackage.Literals.JVM_CONSTRUCTOR.isSuperTypeOf(referenceType)) {
IScope typeScope = getScope(context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
// this is not called from the type resolution where we want to allow constructors to link to interfaces
// in order to improve the error message, therefore we use a strict wrapper here
IScope result = new ConstructorTypeScopeWrapper(context, IVisibilityHelper.ALL, typeScope, true);
return result;
} else {
throw new IllegalArgumentException("Unexpected global request for " + reference);
}
}
use of org.eclipse.xtext.resource.IResourceDescriptions in project xtext-core by eclipse.
the class EObjectSnapshotProvider method createEObjectSnapshots.
protected Map<EObject, IEObjectSnapshot> createEObjectSnapshots(Resource resource) {
Map<EObject, IEObjectSnapshot> result = Maps.newLinkedHashMap();
for (IEObjectDescription desc : descriptionProvider.getEObjectDescriptions(resource)) {
EObject obj = EcoreUtil.resolve(desc.getEObjectOrProxy(), resource);
EObjectSnapshot snapshot = getOrCreate(result, obj);
snapshot.descriptions.add(desc);
}
ResourceSet resourceSet = resource.getResourceSet();
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(resourceSet);
URI uri = resource.getURI();
for (IResourceDescription desc : descriptions.getAllResourceDescriptions()) {
for (IReferenceDescription ref : desc.getReferenceDescriptions()) {
URI targetURI = ref.getTargetEObjectUri();
URI sourceEObjectUri = ref.getSourceEObjectUri();
EReference reference = ref.getEReference();
if (targetURI == null || sourceEObjectUri == null || reference == null) {
continue;
}
if (!uri.equals(targetURI.trimFragment())) {
continue;
}
EObject target = resource.getEObject(targetURI.fragment());
if (target == null || target.eIsProxy()) {
continue;
}
EObjectSnapshot snapshot = getOrCreate(result, target);
ReferenceSnapshot rd = new ReferenceSnapshot(sourceEObjectUri, snapshot, reference, ref.getIndexInList(), ref.getContainerEObjectURI());
snapshot.incomingReferences.add(rd);
}
}
return result;
}
use of org.eclipse.xtext.resource.IResourceDescriptions in project xtext-core by eclipse.
the class AbstractLiveContainerTest method testContainerLoadUnload.
@Test
public void testContainerLoadUnload() throws Exception {
ResourceSet resourceSet = new XtextResourceSet();
Resource res = parse("local", resourceSet).eResource();
Resource foo = resourceSet.createResource(computeUnusedUri(resourceSet));
IResourceDescription resourceDescription = descriptionManager.getResourceDescription(res);
IResourceDescriptions resourceDescriptions = descriptionsProvider.getResourceDescriptions(res);
List<IContainer> containers = containerManager.getVisibleContainers(resourceDescription, resourceDescriptions);
assertEquals(1, containers.size());
IContainer container = containers.get(0);
// assertEquals("local", format(container.getExportedObjects()));
foo.load(new StringInputStream("foo"), null);
assertEquals("foo, local", format(container.getExportedObjects()));
// foo.unload();
// assertEquals("local", format(container.getExportedObjects()));
}
use of org.eclipse.xtext.resource.IResourceDescriptions in project xtext-core by eclipse.
the class XtextValidator method checkExternalPackage.
protected void checkExternalPackage(ReferencedMetamodel metamodelReference, String importURI) {
EPackage referencedPackage = metamodelReference.getEPackage();
if (referencedPackage.eIsProxy() || isRuntime(metamodelReference))
return;
if (isRegisteredPackage(referencedPackage)) {
addIssue("The imported package is not on the classpath of this project which may lead to follow-up errors.", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_NOT_ON_CLASSPATH, importURI);
return;
}
if (!importURI.equals(referencedPackage.getNsURI())) {
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(metamodelReference.eResource());
Iterable<IEObjectDescription> packagesInIndex = descriptions.getExportedObjects(EcorePackage.Literals.EPACKAGE, QualifiedName.create(referencedPackage.getNsURI()), false);
if (!Iterables.isEmpty(packagesInIndex)) {
addIssue("Packages should be imported by their namespace URI.", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_EXTERNAL, referencedPackage.getNsURI());
} else if (!ClasspathUriUtil.isClasspathUri(URI.createURI(importURI))) {
addIssue("The imported package is not on the classpath of this project which may lead to follow-up errors.", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_NOT_ON_CLASSPATH, importURI);
return;
} else {
return;
}
}
Map<EObject, Collection<Setting>> allReferences = EcoreUtil.CrossReferencer.find(Collections.singletonList(referencedPackage));
Set<Object> allReferencedInstances = Sets.newHashSet();
for (Setting setting : Iterables.concat(allReferences.values())) {
Object referenced = setting.get(true);
if (allReferencedInstances.add(referenced) && referenced instanceof EObject) {
EPackage transitive = EcoreUtil2.getContainerOfType((EObject) referenced, EPackage.class);
if (isRegisteredPackage(transitive)) {
if (referenced instanceof EDataType)
continue;
if (referenced == EcorePackage.Literals.EOBJECT)
continue;
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(metamodelReference.eResource());
Iterable<IEObjectDescription> packagesInIndex = descriptions.getExportedObjects(EcorePackage.Literals.EPACKAGE, QualifiedName.create(importURI), false);
if (!Iterables.isEmpty(packagesInIndex)) {
if (setting.getEObject().eResource().getURI().isPlatformResource())
addIssue("The imported package refers to elements in the package registry instead of using the instances from the workspace", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_EXTERNAL, referencedPackage.getNsURI());
else
addIssue("The imported package refers to elements in the package registry instead of using the instances from the workspace", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_EXTERNAL);
return;
} else {
addIssue("The imported package refers to elements that are not on the classpath of this project. The package '" + transitive.getNsURI() + "' was loaded from the registry.", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_NOT_ON_CLASSPATH, referencedPackage.getNsURI());
return;
}
}
}
}
}
use of org.eclipse.xtext.resource.IResourceDescriptions in project xtext-core by eclipse.
the class ImportUriGlobalScopeProvider method getResourceDescriptions.
public IResourceDescriptions getResourceDescriptions(Resource resource, Collection<URI> importUris) {
IResourceDescriptions result = getResourceDescriptions(resource);
LoadOnDemandResourceDescriptions demandResourceDescriptions = loadOnDemandDescriptions.get();
demandResourceDescriptions.initialize(result, importUris, resource);
return demandResourceDescriptions;
}
Aggregations