Search in sources :

Example 46 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class UriBasedReader method setClasspathURIContext.

public void setClasspathURIContext(Object class1) {
    final XtextResourceSet resourceSet = new XtextResourceSet();
    resourceSet.setClasspathURIContext(class1);
    setResourceSetProvider(new Provider<ResourceSet>() {

        @Override
        public ResourceSet get() {
            return resourceSet;
        }
    });
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 47 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class UriBasedReader method invokeInternal.

@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
    ResourceSet resourceSet = getResourceSet();
    for (URI uri : uris2) {
        Resource resource = resourceSet.getResource(uri, true);
        int numberResources;
        do {
            numberResources = resourceSet.getResources().size();
            EcoreUtil.resolveAll(resource);
        } while (numberResources != resourceSet.getResources().size());
    }
    getValidator().validate(resourceSet, getRegistry(), issues);
    addModelElementsToContext(ctx, resourceSet);
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 48 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class ResourceSetGlobalScopeProvider method getScope.

@Override
protected IScope getScope(Resource resource, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> filter) {
    IScope parent = IScope.NULLSCOPE;
    if (resource == null || resource.getResourceSet() == null)
        return parent;
    final ResourceSet resourceSet = resource.getResourceSet();
    if (resourceSet instanceof ResourceSetReferencingResourceSet) {
        ResourceSetReferencingResourceSet set = (ResourceSetReferencingResourceSet) resourceSet;
        Iterable<ResourceSet> referencedSets = Lists.reverse(set.getReferencedResourceSets());
        for (ResourceSet referencedSet : referencedSets) {
            parent = createScopeWithQualifiedNames(parent, resource, filter, referencedSet, type, ignoreCase);
        }
    }
    return createScopeWithQualifiedNames(parent, resource, filter, resourceSet, type, ignoreCase);
}
Also used : ResourceSetReferencingResourceSet(org.eclipse.xtext.resource.ResourceSetReferencingResourceSet) IScope(org.eclipse.xtext.scoping.IScope) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ResourceSetReferencingResourceSet(org.eclipse.xtext.resource.ResourceSetReferencingResourceSet)

Example 49 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class EcoreUtil2 method isValidUri.

/**
 * checks whether the given URI can be loaded given the context. I.e. there's a resource set with a corresponding
 * resource factory and the physical resource exists.
 */
public static boolean isValidUri(Resource resource, URI uri) {
    if (uri == null || uri.isEmpty()) {
        return false;
    }
    URI newURI = getResolvedImportUri(resource, uri);
    try {
        ResourceSet resourceSet = resource.getResourceSet();
        if (resourceSet.getResource(uri, false) != null)
            return true;
        URIConverter uriConverter = resourceSet.getURIConverter();
        URI normalized = uriConverter.normalize(newURI);
        if (normalized != null)
            // fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=326760
            if ("platform".equals(normalized.scheme()) && !normalized.isPlatform())
                return false;
        return uriConverter.exists(normalized, Collections.emptyMap());
    } catch (RuntimeException e) {
        // thrown by org.eclipse.emf.ecore.resource.ResourceSet#getResource(URI, boolean)
        log.trace("Cannot load resource: " + newURI, e);
    }
    return false;
}
Also used : ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URIConverter(org.eclipse.emf.ecore.resource.URIConverter) URI(org.eclipse.emf.common.util.URI)

Example 50 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class ValidatorFragment2 method generateValidationToDeprecateRules.

protected StringConcatenationClient generateValidationToDeprecateRules() {
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            {
                if (ValidatorFragment2.this.generateDeprecationValidation) {
                    {
                        List<AbstractRule> _deprecatedRulesFromGrammar = ValidatorFragment2.this.getDeprecatedRulesFromGrammar();
                        for (final AbstractRule deprecatedRule : _deprecatedRulesFromGrammar) {
                            EClassifier _classifier = deprecatedRule.getType().getClassifier();
                            ResourceSet _resourceSet = ValidatorFragment2.this.getGrammar().eResource().getResourceSet();
                            final TypeReference elementType = new TypeReference(((EClass) _classifier), _resourceSet);
                            _builder.newLineIfNotEmpty();
                            _builder.newLine();
                            _builder.append("@");
                            _builder.append(Check.class);
                            _builder.newLineIfNotEmpty();
                            _builder.append("public void checkDeprecated");
                            String _simpleName = elementType.getSimpleName();
                            _builder.append(_simpleName);
                            _builder.append("(");
                            _builder.append(elementType);
                            _builder.append(" element) {");
                            _builder.newLineIfNotEmpty();
                            _builder.append("\t");
                            _builder.append("warning(\"This part of the language is marked as deprecated and might get removed in the future!\", element, null);");
                            _builder.newLine();
                            _builder.append("}");
                            _builder.newLine();
                        }
                    }
                }
            }
        }
    };
    return _client;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) EClassifier(org.eclipse.emf.ecore.EClassifier) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) AbstractRule(org.eclipse.xtext.AbstractRule)

Aggregations

ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)123 Resource (org.eclipse.emf.ecore.resource.Resource)71 Test (org.junit.Test)51 EObject (org.eclipse.emf.ecore.EObject)34 URI (org.eclipse.emf.common.util.URI)32 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)32 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)21 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)21 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)20 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)17 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)17 XtextResource (org.eclipse.xtext.resource.XtextResource)16 EPackage (org.eclipse.emf.ecore.EPackage)12 IFile (org.eclipse.core.resources.IFile)10 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)10 ArrayList (java.util.ArrayList)9 EClass (org.eclipse.emf.ecore.EClass)9 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)9 IOException (java.io.IOException)8 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8