For some reasons my JvmModelInferrer
needs to search for all elements of a special type which fulfill a criterion. These elements are necessary to infer the model completely. But all these elements can be spread over all source code files of the project. More precise: There is an element which introduces a class and several elements which modify this class. The grammar for this looks like this (simplified to a minimum depth):
DeltaAction:
AddsUnit | ModifiesUnit | RemovesUnit;
AddsUnit:
{AddsUnit} 'adds' '{' unit=JavaCompilationUnit? '}';
JavaCompilationUnit:
('package' name=QualifiedName EOL)?
importSection=XImportSection?
// ...
typeDeclarations=ClassOrInterface;
ClassOrInterface:
ClassDeclaration /* | ... */;
ClassDeclaration:
'class' name=QualifiedName
// ...
;
ModifiesUnit:
'modifies' unit=[ClassOrInterface|QualifiedName] '{'
// ...
'}';
If I now infer the jvm model for a class pkg.A
, I need to find all ModifiesUnit
units which reference pkg.A
to generate this class.
This is more or less the question: How can I find all elements referencing pkg.A
? I found a soultion, but I think it is very inperformant and maybe there is any API which does i for me much more efficient.
class DeltaJJvmModelInferrer extends AbstractModelInferrer {
@Inject ResourceDescriptionsProvider descsProvider
@Inject ResourceSet set
@Inject IQualifiedNameProvider qnameProvider
def dispatch void infer(DeltaJUnit unit, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
descsProvider.createResourceDescriptions.allResourceDescriptions.forEach [ rd |
val res = set.getResource(rd.URI, true)
res.unload
res.load(null)
EcoreUtil2.resolveAll(res)
]
try {
set.allContents.filter(typeof(ModifiesUnit)).filter [ mu |
qnameProvider.getFullyQualifiedName(mu.unit).equals(qnameProvider.getFullyQualifiedName(cd))
].forEach [ mu |
// Do the stuff I need to do!
]
} catch (Exception e) {
return
}
]
}