@Check
public void checkPatterns(PatternModel model) {
resourceDescriptions.setContext(model);
if (model.getPatterns() != null) {
for (Pattern pattern : model.getPatterns()) {
QualifiedName fullyQualifiedName = nameProvider.getFullyQualifiedName(pattern);
final Iterable<IEObjectDescription> shadowingPatternDescriptions = resourceDescriptions.getExportedObjects(PatternLanguagePackage.Literals.PATTERN, fullyQualifiedName, true);
for (IEObjectDescription shadowingPatternDescription : shadowingPatternDescriptions) {
EObject shadowingPattern = shadowingPatternDescription.getEObjectOrProxy();
if (shadowingPattern != pattern) {
URI resourceUri = pattern.eResource().getURI();
URI otherResourceUri = shadowingPatternDescription.getEObjectURI().trimFragment();
IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(resourceUri);
IResourceDescription otherResourceDescription = resourceDescriptions.getResourceDescription(otherResourceUri);
List<IContainer> visible = containerManager.getVisibleContainers(resourceDescription, resourceDescriptions);
List<IContainer> visibleFromOther = containerManager.getVisibleContainers(otherResourceDescription, resourceDescriptions);
if (Iterables.any(visible, contains(otherResourceDescription)) || Iterables.any(visibleFromOther, contains(resourceDescription))) {
String otherResourcePath = Objects.firstNonNull(otherResourceUri.toPlatformString(true), otherResourceUri.toFileString());
error(String.format(DUPLICATE_PATTERN_DEFINITION_MESSAGE, fullyQualifiedName, otherResourcePath), pattern,
PatternLanguagePackage.Literals.PATTERN__NAME, IssueCodes.DUPLICATE_PATTERN_DEFINITION);
}
}
}
}
}
}