Search in sources :

Example 1 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName 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 2 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName 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)

Example 3 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-eclipse by eclipse.

the class DeltaConverter method getAdditionallyExportedEObjects.

/**
 * @deprecated This method is not used anymore.
 */
@Deprecated
protected List<IEObjectDescription> getAdditionallyExportedEObjects(IType type, IJavaElementDelta delta) {
    QualifiedName typeName = nameConverter.toQualifiedName(type.getFullyQualifiedName());
    NameBasedEObjectDescriptionBuilder descriptionBuilder = new NameBasedEObjectDescriptionBuilder(typeName);
    traverseDelta(delta, descriptionBuilder);
    return descriptionBuilder.getExported();
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName)

Example 4 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-eclipse by eclipse.

the class NameBasedEObjectDescriptionBuilder method accept.

public void accept(String simpleName) {
    QualifiedName next = baseName.append(simpleName);
    exported.add(new NameBasedEObjectDescription(next));
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName)

Example 5 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-eclipse by eclipse.

the class NameBasedEObjectDescriptionBuilder method nestType.

public NameBasedEObjectDescriptionBuilder nestType(String simpleName) {
    String newLastSegment = baseName.getLastSegment() + "$" + simpleName;
    QualifiedName next = baseName.skipLast(1).append(newLastSegment);
    return new NameBasedEObjectDescriptionBuilder(next, exported);
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName)

Aggregations

QualifiedName (org.eclipse.xtext.naming.QualifiedName)215 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)78 EObject (org.eclipse.emf.ecore.EObject)46 Test (org.junit.Test)46 URI (org.eclipse.emf.common.util.URI)24 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)21 IScope (org.eclipse.xtext.scoping.IScope)21 EClass (org.eclipse.emf.ecore.EClass)18 Resource (org.eclipse.emf.ecore.resource.Resource)16 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)13 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 Set (java.util.Set)10 StyledString (org.eclipse.jface.viewers.StyledString)8 JvmType (org.eclipse.xtext.common.types.JvmType)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Grammar (org.eclipse.xtext.Grammar)6 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)6 HashMap (java.util.HashMap)5 InternalEObject (org.eclipse.emf.ecore.InternalEObject)5