use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeModel in project dsl-devkit by dsldevkit.
the class ScopeJavaValidator method getAllInheritedScopeDefinitions.
/**
* Returns a set comprising all inherited scope definitions (excluding local scope definitions).
*
* @param context
* scope model to retrieve inherited scope definitions for
* @return all inherited (recursively) scope definitions
*/
private Set<ScopeDefinition> getAllInheritedScopeDefinitions(final ScopeModel context) {
final Set<ScopeDefinition> defs = Sets.newLinkedHashSet();
for (ScopeModel include : context.getIncludedScopes()) {
defs.addAll(include.getScopes());
defs.addAll(getAllInheritedScopeDefinitions(include));
}
return defs;
}
use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeModel in project dsl-devkit by dsldevkit.
the class ScopeLinkingService method getIncludedModel.
/**
* Returns the {@link ScopeModel#getIncludes() included scope model} corresponding to the given node from the node model.
*
* @param context
* context object
* @param node
* parser node corresponding to include reference
* @return referenced {@link ScopeModel} to include
*/
private List<EObject> getIncludedModel(final ScopeModel context, final INode node) {
// based on XtextLinkingService#getUsedGrammar()
try {
String scopeModelName = (String) valueConverterService.toValue("", grammarAccess.getDottedIDRule().getName(), node);
if (scopeModelName != null) {
final ResourceSet resourceSet = context.eResource().getResourceSet();
List<Resource> resources = resourceSet.getResources();
for (int i = 0; i < resources.size(); i++) {
Resource resource = resources.get(i);
EObject rootElement = null;
if (resource instanceof XtextResource && ((XtextResource) resource).getLanguageName().equals(languageName) && !resource.getContents().isEmpty()) {
rootElement = resource.getContents().get(0);
}
if (rootElement instanceof ScopeModel) {
ScopeModel otherModel = (ScopeModel) rootElement;
if (scopeModelName.equals(otherModel.getName())) {
return Collections.<EObject>singletonList(otherModel);
}
}
}
URI classpathURI = URI.createURI(ClasspathUriUtil.CLASSPATH_SCHEME + ":/" + scopeModelName.replace('.', '/') + "." + fileExtensionProvider.getPrimaryFileExtension());
final Resource resource = resourceSet.getResource(classpathURI, true);
if (!resource.getContents().isEmpty()) {
final ScopeModel otherModel = (ScopeModel) resource.getContents().get(0);
if (scopeModelName.equals(otherModel.getName())) {
return Collections.<EObject>singletonList(otherModel);
}
}
}
return Collections.emptyList();
} catch (ClasspathUriResolutionException e) {
LOG.warn("Cannot load included scope.", e);
return Collections.emptyList();
} catch (ValueConverterException e) {
LOG.warn("Cannot convert included scope name.", e);
return Collections.emptyList();
}
}
use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeModel in project dsl-devkit by dsldevkit.
the class ScopeResourceDescriptionStrategy method createEObjectDescriptions.
@Override
public boolean createEObjectDescriptions(final EObject eObject, final IAcceptor<IEObjectDescription> acceptor) {
if (getQualifiedNameProvider() == null || !(eObject instanceof ScopeModel)) {
return false;
}
ScopeModel model = (ScopeModel) eObject;
try {
QualifiedName qualifiedName = getQualifiedNameProvider().getFullyQualifiedName(model);
if (qualifiedName != null) {
Hasher hasher = Hashing.murmur3_32().newHasher(HASHER_CAPACITY);
hasher.putUnencodedChars(getSourceText(model));
for (ScopeModel include : model.getIncludedScopes()) {
hasher.putUnencodedChars(getSourceText(include));
}
acceptor.accept(EObjectDescription.create(qualifiedName, model, Collections.singletonMap("fingerprint", hasher.hash().toString())));
}
// CHECKSTYLE:CHECK-OFF IllegalCatch
} catch (RuntimeException e) {
// CHECKSTYLE:CHECK-ON
LOG.error(e.getMessage(), e);
}
return false;
}
use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeModel in project dsl-devkit by dsldevkit.
the class ScopeJavaValidator method checkNameFunctionExists.
/**
* Verifies that a matching default name function exists for scope expressions without explicit name functions.
*
* @param expr
* scope expression to check
*/
@Check
public void checkNameFunctionExists(final SimpleScopeExpression expr) {
if (expr.getNaming() != null && !expr.getNaming().getNames().isEmpty()) {
return;
}
ScopeDefinition def = EObjectUtil.eContainer(expr, ScopeDefinition.class);
ScopeModel model = EObjectUtil.eContainer(expr, ScopeModel.class);
if (def != null && model != null) {
EClass scopeType = getType(def);
NamingSection namingSection = model.getNaming();
if (namingSection != null) {
for (NamingDefinition naming : namingSection.getNamings()) {
if (naming.getType() != null && isLeftMostSuperType(naming.getType(), scopeType)) {
return;
}
}
}
error(NLS.bind(Messages.missingNameFunction, scopeType.getName()), ScopePackage.Literals.SIMPLE_SCOPE_EXPRESSION__EXPR);
}
}
Aggregations