Search in sources :

Example 1 with IEObjectDescription

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;
}
Also used : InternalEObject(org.eclipse.emf.ecore.InternalEObject) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 2 with IEObjectDescription

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;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 3 with IEObjectDescription

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;
}
Also used : URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 4 with IEObjectDescription

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);
        }
    };
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 5 with IEObjectDescription

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;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject) JvmType(org.eclipse.xtext.common.types.JvmType) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)324 Test (org.junit.Test)95 EObject (org.eclipse.emf.ecore.EObject)82 QualifiedName (org.eclipse.xtext.naming.QualifiedName)79 IScope (org.eclipse.xtext.scoping.IScope)56 URI (org.eclipse.emf.common.util.URI)41 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)33 EClass (org.eclipse.emf.ecore.EClass)30 Resource (org.eclipse.emf.ecore.resource.Resource)28 EObjectDescription (org.eclipse.xtext.resource.EObjectDescription)22 AliasedEObjectDescription (org.eclipse.xtext.resource.impl.AliasedEObjectDescription)22 ArrayList (java.util.ArrayList)19 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)14 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)12 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)12 StyledString (org.eclipse.jface.viewers.StyledString)12 XtextResource (org.eclipse.xtext.resource.XtextResource)11 StringInputStream (org.eclipse.xtext.util.StringInputStream)11 EReference (org.eclipse.emf.ecore.EReference)10 List (java.util.List)9