use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class JdtBasedSimpleTypeScope method createScopedElement.
public IEObjectDescription createScopedElement(String fullyQualifiedName) {
InternalEObject proxy = createProxy(fullyQualifiedName);
IEObjectDescription eObjectDescription = EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(fullyQualifiedName), proxy);
return eObjectDescription;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class JdtIndexedJvmTypeAccess method findAccessibleType.
@Override
protected EObject findAccessibleType(String fragment, ResourceSet resourceSet, Iterator<IEObjectDescription> fromIndex) throws UnknownNestedTypeException {
// we know that the iterator is not empty thus we can directly obtain the handles et al without additional guards
IJavaProject javaProject = javaProjectProvider.getJavaProject(resourceSet);
List<String> allVisibleContainerHandles = Lists.newArrayList(javaProjectsState.getVisibleContainerHandles(javaProject.getHandleIdentifier()));
// some models are not in source folders thus we also use the WorkspaceProjectsState (e.g. relevant for Xcore)
allVisibleContainerHandles.addAll(plainProjectsState.getVisibleContainerHandles(javaProject.getElementName()));
List<String> visibleContainerHandles = allVisibleContainerHandles;
IEObjectDescription bestDescription = null;
while (fromIndex.hasNext() && !visibleContainerHandles.isEmpty()) {
// find the description that is the best match, e.g. the one that is in the container closest to the first
IEObjectDescription description = fromIndex.next();
URI trimFragment = description.getEObjectURI().trimFragment();
String handle = javaProjectsState.getContainerHandle(trimFragment);
int idx = visibleContainerHandles.indexOf(handle);
if (idx >= 0) {
bestDescription = description;
// reduce the search scope - only check containers that are better than the current
visibleContainerHandles = allVisibleContainerHandles.subList(0, idx);
}
}
if (bestDescription != null) {
return getAccessibleType(bestDescription, fragment, resourceSet);
}
return null;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class ProjectAwareUniqueClassNameValidator method checkUniqueInIndex.
@Override
protected boolean checkUniqueInIndex(final JvmDeclaredType type, final Iterable<IEObjectDescription> descriptions) {
final URI objectURI = EcoreUtil.getURI(type);
boolean _isPlatformResource = objectURI.isPlatformResource();
if (_isPlatformResource) {
final String project = objectURI.segment(1);
final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
final URI candidate = it.getEObjectURI();
return Boolean.valueOf((candidate.isPlatformResource() && Objects.equal(candidate.segment(1), project)));
};
return super.checkUniqueInIndex(type, IterableExtensions.<IEObjectDescription>filter(descriptions, _function));
}
return true;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class WorkingCopyOwnerProvider method getWorkingCopyOwner.
@Override
public WorkingCopyOwner getWorkingCopyOwner(final IJavaProject javaProject, final ResourceSet resourceSet) {
return new WorkingCopyOwner() {
@Override
public String findSource(String typeName, String packageName) {
if (packageName.startsWith("java"))
return super.findSource(typeName, packageName);
QualifiedName qn = toQualifiedName(packageName, typeName);
final IResourceDescriptions descriptions = descriptionsProvider.getResourceDescriptions(resourceSet);
Iterator<IEObjectDescription> exportedObjects = descriptions.getExportedObjects(TypesPackage.Literals.JVM_DECLARED_TYPE, qn, false).iterator();
while (exportedObjects.hasNext()) {
IEObjectDescription candidate = exportedObjects.next();
URI uri = candidate.getEObjectURI();
if (uri.isPlatformResource() && URI.decode(uri.segment(1)).equals(javaProject.getElementName())) {
IResourceDescription resourceDescription = descriptions.getResourceDescription(uri.trimFragment());
return getSource(typeName, packageName, candidate, resourceSet, resourceDescription);
}
}
return super.findSource(typeName, packageName);
}
/**
* not implemented because we don't have a proper index for Java package names and the very rare cases in which this would
* cause trouble are not worth the general degrade in performance.
*/
@Override
public boolean isPackage(String[] pkg) {
return super.isPackage(pkg);
}
};
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class JvmElementFinder method findJvmElementDeclarationInIndex.
public EObject findJvmElementDeclarationInIndex(EObject jvmElement, IProject project, ResourceSet resourceSet) {
JvmType type = EcoreUtil2.getContainerOfType(jvmElement, JvmType.class);
if (type == null)
return null;
QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(type);
if (qualifiedName != null) {
Iterator<IEObjectDescription> exportedObjects = resourceDescriptions.getExportedObjects(type.eClass(), qualifiedName, false).iterator();
if (exportedObjects.hasNext()) {
URI eObjectURI = exportedObjects.next().getEObjectURI();
EObject eObject = resourceSet.getEObject(eObjectURI, true);
if (type != jvmElement) {
TreeIterator<EObject> contents = eObject.eAllContents();
QualifiedName nameOfActualElement = qualifiedNameProvider.getFullyQualifiedName(jvmElement);
while (contents.hasNext()) {
EObject next = contents.next();
if (jvmElement.eClass().isInstance(next) && nameOfActualElement.equals(qualifiedNameProvider.getFullyQualifiedName(next))) {
return next;
}
}
}
return eObject;
}
}
return null;
}
Aggregations