Search in sources :

Example 91 with URI

use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.

the class AbstractNode method updateMapping.

private int updateMapping(int currentId, Map<EObject, Integer> grammarElementToIdMap, List<String> grammarIdToURIMap, EObject grammarElement) {
    if (!grammarElementToIdMap.containsKey(grammarElement)) {
        URI uri = EcoreUtil.getURI(grammarElement);
        if (uri == null) {
            throw new IllegalStateException("While building the map of grammar elements to an ID, " + "got a grammar element that does not have an URI.  The " + "grammar element has class " + grammarElement.eClass().getName());
        }
        grammarElementToIdMap.put(grammarElement, currentId);
        grammarIdToURIMap.add(uri.toString());
        ++currentId;
    }
    if (currentId != grammarIdToURIMap.size()) {
        throw new IllegalStateException("The next id for a grammar element will be " + currentId + " but the number of elements in " + "the map of grammar elements to IDs contains a different number of elements: " + grammarIdToURIMap.size());
    }
    return currentId;
}
Also used : URI(org.eclipse.emf.common.util.URI)

Example 92 with URI

use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.

the class EclipseProjectPropertiesEncodingProvider method getValue.

protected String getValue(Properties properties, URI resourceUri, String prefix) {
    URI path = resourceUri;
    do {
        String value = properties.getProperty(prefix + path.path());
        if (value != null)
            return value;
        path = path.trimSegments(1);
    } while (path.segmentCount() > 0);
    String value = properties.getProperty(prefix + PROJECT_PROPERTIES);
    if (value != null)
        return value;
    return null;
}
Also used : URI(org.eclipse.emf.common.util.URI)

Example 93 with URI

use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.

the class CrossReferenceSerializer method serializeCrossRef.

@Override
public String serializeCrossRef(EObject context, CrossReference grammarElement, final EObject target, INode node) {
    final EReference ref = GrammarUtil.getReference(grammarElement, context.eClass());
    String text = null;
    if (node != null) {
        List<EObject> objects = linkingService.getLinkedObjects(context, ref, node);
        if (Iterables.any(objects, new Predicate<EObject>() {

            private final URI targetURI = EcoreUtil.getURI(target);

            @Override
            public boolean apply(EObject input) {
                return input == target || EcoreUtil.getURI(input).equals(targetURI);
            }
        }))
            return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL;
    }
    text = getUnconvertedLinkText(target, ref, context);
    if (text != null)
        return getConvertedValue(text, grammarElement);
    if (node != null) {
        return linkingHelper.getCrossRefNodeAsString(node, false);
    }
    return null;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) URI(org.eclipse.emf.common.util.URI) EReference(org.eclipse.emf.ecore.EReference)

Example 94 with URI

use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.

the class ClassloaderClasspathUriResolver method findResourceOnClasspath.

public URI findResourceOnClasspath(ClassLoader classLoader, URI classpathUri) throws URISyntaxException {
    String pathAsString = classpathUri.path();
    if (classpathUri.hasAbsolutePath()) {
        pathAsString = pathAsString.substring(1);
    }
    URL resource = classLoader.getResource(pathAsString);
    if (resource == null)
        throw new FileNotFoundOnClasspathException("Couldn't find resource on classpath. URI was '" + classpathUri + "'");
    URI fileUri = URI.createURI(resource.toString(), true);
    return fileUri.appendFragment(classpathUri.fragment());
}
Also used : URI(org.eclipse.emf.common.util.URI) URL(java.net.URL)

Example 95 with URI

use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.

the class DescriptionUtils method collectOutgoingReferences.

/**
 * Collect the URIs of resources, that are referenced by the given description.
 * @return the list of referenced URIs. Never <code>null</code>.
 */
public Set<URI> collectOutgoingReferences(IResourceDescription description) {
    URI resourceURI = description.getURI();
    Set<URI> result = null;
    for (IReferenceDescription reference : description.getReferenceDescriptions()) {
        URI targetResource = reference.getTargetEObjectUri().trimFragment();
        if (!resourceURI.equals(targetResource)) {
            if (result == null)
                result = Sets.newHashSet(targetResource);
            else
                result.add(targetResource);
        }
    }
    if (result != null)
        return result;
    return Collections.emptySet();
}
Also used : URI(org.eclipse.emf.common.util.URI)

Aggregations

URI (org.eclipse.emf.common.util.URI)305 Resource (org.eclipse.emf.ecore.resource.Resource)85 Test (org.junit.Test)79 EObject (org.eclipse.emf.ecore.EObject)55 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)37 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)33 XtextResource (org.eclipse.xtext.resource.XtextResource)32 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)26 BuildRequest (org.eclipse.xtext.build.BuildRequest)23 File (java.io.File)20 AbstractIncrementalBuilderTest (org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest)20 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)19 IOException (java.io.IOException)18 InternalEObject (org.eclipse.emf.ecore.InternalEObject)18 EPackage (org.eclipse.emf.ecore.EPackage)15 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)15 InputStream (java.io.InputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ArrayList (java.util.ArrayList)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13