Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Getting All DSL Resources in the same Project or dir
Getting All DSL Resources in the same Project or dir [message #1391087] Mon, 30 June 2014 12:29
Thomas Hergenröder is currently offline Thomas HergenröderFriend
Messages: 22
Registered: February 2012
Junior Member
I need all EObjects of one specific Class that are in the same directory or in a subdirectory.

I have a solution that seemded to work,
but it ignores at least one file.
The ignored file is loaded.
It appeard when the same method was called before in the program flow.

edit: The interesting part is that it works fine in the eclipse-Build. But It does not work in the headless build.

Right now I use the following:
public List<IEObjectDescription> getEObjectDescriptions(final Resource resource, final EClass eClass) {
    final List<IEObjectDescription> descriptions = new ArrayList<>();
    final IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions(resource);
    final IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(resource.getURI());
    for (final IContainer c : containerManager.getVisibleContainers(resourceDescription, resourceDescriptions)) {
        for (final IEObjectDescription ob : c.getExportedObjectsByType(eClass)) {
            descriptions.add(ob);
            if (debug) { System.out.println("added ob: " + ob.getName()); }
            if (ob.getName().toString().contains("MandantenBeziehungenBearbeiten")) {
                System.out.println("ob added MandantenBeziehungenBearbeiten");
            }
        }
    }
    return descriptions;
}
and
final Resource resource = module.eResource();
final List<IEObjectDescription> instanceDescriptions = getEObjectDescriptions(resource, eClass);
final ResourceSet resourceSet = resource.getResourceSet();
final String moduleDirPath = resource.getURI();
int i = 0;
for (final IEObjectDescription od : instanceDescriptions) {
    i = i + 1;
    final URI odUri = od.getEObjectURI();
    final String odPath = resource.getURI()(odUri);
    if (odPath.startsWith(moduleDirPath)) {
        final EObject eObject = resourceSet.getEObject(odUri, true);
        if (eObject instanceof StringNamed) {
            stringNameds.add((StringNamed) eObject);
        }
    }
}

[Updated on: Mon, 30 June 2014 12:55]

Report message to a moderator

Previous Topic: fullyQualifiedName is null when loading Resource from URI
Next Topic:Problems when creating ANSI-C like grammar
Goto Forum:
  


Current Time: Sun Dec 08 21:08:40 GMT 2019

Powered by FUDForum. Page generated in 0.02128 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top