Search in sources :

Example 86 with QualifiedName

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

the class ImportNormalizerTest method testDeresolveIgnoreCase.

@Test
public void testDeresolveIgnoreCase() throws Exception {
    QualifiedName namespace = QualifiedName.create("org", "eclipse", "xtext");
    QualifiedName xtextFQN = namespace.append("Xtext");
    QualifiedName ytextFQN = namespace.skipLast(1).append("ytext");
    QualifiedName xytextFQN = namespace.append("ytext");
    ImportNormalizer importNormalizer = new ImportNormalizer(xtextFQN.toUpperCase(), false, true);
    assertEquals(QualifiedName.create("Xtext"), importNormalizer.deresolve(xtextFQN));
    assertEquals(null, importNormalizer.deresolve(ytextFQN));
    assertEquals(null, importNormalizer.deresolve(xytextFQN));
    importNormalizer = new ImportNormalizer(xytextFQN.toUpperCase(), false, true);
    assertEquals(null, importNormalizer.deresolve(xtextFQN));
    assertEquals(null, importNormalizer.deresolve(ytextFQN));
    assertEquals(QualifiedName.create("ytext"), importNormalizer.deresolve(xytextFQN));
    ImportNormalizer wildCardImportNormalizer = new ImportNormalizer(namespace.toUpperCase(), true, true);
    assertEquals(QualifiedName.create("Xtext"), wildCardImportNormalizer.deresolve(xtextFQN));
    assertEquals(null, wildCardImportNormalizer.deresolve(ytextFQN));
    assertEquals(QualifiedName.create("ytext"), wildCardImportNormalizer.deresolve(xytextFQN));
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) Test(org.junit.Test)

Example 87 with QualifiedName

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

the class SlotEntry method matches.

protected boolean matches(Set<EClass> eclasses, IEObjectDescription desc) {
    boolean valid = eclasses.isEmpty();
    for (Iterator<EClass> iterator = eclasses.iterator(); !valid && iterator.hasNext(); ) {
        EClass eClass = iterator.next();
        valid = valid || EcorePackage.Literals.EOBJECT == eClass || eClass.isSuperTypeOf(desc.getEClass());
    }
    if (name != null) {
        if (Strings.isEmpty(namespaceDelimiter)) {
            return valid && name.equals(desc.getName().toString());
        } else {
            QualifiedName qualifiedName = QualifiedName.create(name.split(Pattern.quote(getNamespaceDelimiter())));
            return valid && (qualifiedName == null || qualifiedName.equals(desc.getName()));
        }
    }
    return valid;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) QualifiedName(org.eclipse.xtext.naming.QualifiedName)

Example 88 with QualifiedName

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

the class DefaultLinkingService method getLinkedObjects.

/**
 * @return the first element returned from the injected {@link IScopeProvider} which matches the text of the passed
 *         {@link INode node}
 */
@Override
public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node) throws IllegalNodeException {
    final EClass requiredType = ref.getEReferenceType();
    if (requiredType == null) {
        return Collections.<EObject>emptyList();
    }
    final String crossRefString = getCrossRefNodeAsString(node);
    if (crossRefString == null || crossRefString.equals("")) {
        return Collections.<EObject>emptyList();
    }
    if (logger.isDebugEnabled()) {
        logger.debug("before getLinkedObjects: node: '" + crossRefString + "'");
    }
    final IScope scope = getScope(context, ref);
    if (scope == null) {
        throw new AssertionError("Scope provider " + scopeProvider.getClass().getName() + " must not return null for context " + context + ", reference " + ref + "! Consider to return IScope.NULLSCOPE instead.");
    }
    final QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString);
    final IEObjectDescription eObjectDescription = scope.getSingleElement(qualifiedLinkName);
    if (logger.isDebugEnabled()) {
        logger.debug("after getLinkedObjects: node: '" + crossRefString + "' result: " + eObjectDescription);
    }
    if (eObjectDescription == null) {
        return Collections.emptyList();
    }
    final EObject result = eObjectDescription.getEObjectOrProxy();
    return Collections.singletonList(result);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 89 with QualifiedName

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

the class DefaultResourceDescription method getImportedNames.

@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();
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) ImportedNamesAdapter(org.eclipse.xtext.linking.impl.ImportedNamesAdapter)

Example 90 with QualifiedName

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

the class PortableURIs method fromFragmentString.

protected PortableURIs.PortableFragmentDescription fromFragmentString(final String fragmentString) {
    final Iterator<String> segments = Splitter.on("#").split(fragmentString).iterator();
    segments.next();
    final URI eClassURI = URI.createURI(URI.decode(segments.next()));
    final EPackage ePackage = this.packageRegistry.getEPackage(eClassURI.trimFragment().toString());
    Resource _eResource = null;
    if (ePackage != null) {
        _eResource = ePackage.eResource();
    }
    EObject _eObject = null;
    if (_eResource != null) {
        _eObject = _eResource.getEObject(eClassURI.fragment());
    }
    final EClass eClass = ((EClass) _eObject);
    final QualifiedName qname = QualifiedName.create(IterableExtensions.<String>toList(Splitter.on(":").split(URI.decode(segments.next()))));
    String _xifexpression = null;
    boolean _hasNext = segments.hasNext();
    if (_hasNext) {
        _xifexpression = URI.decode(segments.next());
    }
    final String fragment = _xifexpression;
    EClass _elvis = null;
    if (eClass != null) {
        _elvis = eClass;
    } else {
        _elvis = EcorePackage.Literals.EOBJECT;
    }
    return new PortableURIs.PortableFragmentDescription(_elvis, qname, fragment);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) URI(org.eclipse.emf.common.util.URI) EPackage(org.eclipse.emf.ecore.EPackage)

Aggregations

QualifiedName (org.eclipse.xtext.naming.QualifiedName)97 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)32 Test (org.junit.Test)31 EObject (org.eclipse.emf.ecore.EObject)27 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)16 EClass (org.eclipse.emf.ecore.EClass)12 Resource (org.eclipse.emf.ecore.resource.Resource)12 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)12 IScope (org.eclipse.xtext.scoping.IScope)10 Set (java.util.Set)9 URI (org.eclipse.emf.common.util.URI)7 XtextResource (org.eclipse.xtext.resource.XtextResource)7 StringInputStream (org.eclipse.xtext.util.StringInputStream)7 JvmType (org.eclipse.xtext.common.types.JvmType)6 Function (com.google.common.base.Function)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 InternalEObject (org.eclipse.emf.ecore.InternalEObject)4 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4