use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeRule in project dsl-devkit by dsldevkit.
the class ScopeJavaValidator method checkScopeRuleUniqueness.
/**
* Checks that the all local scope rules (i.e. excluding inherited rules) have a unique context (context type, reference,
* guard).
*
* @param context
* scoping section to check
*/
@Check
public void checkScopeRuleUniqueness(final ScopeModel context) {
final Map<String, ScopeRule> profileMap = Maps.newHashMap();
for (ScopeDefinition def : context.getScopes()) {
for (ScopeRule rule : def.getRules()) {
final Expression guard = rule.getContext().getGuard();
// $NON-NLS-1$ //$NON-NLS-2$
final String profile = ScopeUtil.getSignature(rule) + ":" + (guard != null ? serializer.serialize(guard) : "");
final ScopeRule other = profileMap.get(profile);
if (other != null) {
errorOnDuplicate(rule, other, Messages.duplicatedScopeRule, ScopePackage.Literals.SCOPE_RULE__CONTEXT);
} else {
profileMap.put(profile, rule);
}
}
}
}
use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeRule in project dsl-devkit by dsldevkit.
the class ScopeJavaValidator method checkScopeRuleOverriding.
/**
* Checks that the local scope rules do not override any inherited scope rules (not supported).
*
* @param context
* scoping section to check
*/
@Check
public void checkScopeRuleOverriding(final ScopeModel context) {
final Set<ScopeDefinition> inheritedDefinitions = getAllInheritedScopeDefinitions(context);
if (inheritedDefinitions.isEmpty()) {
return;
}
final Map<String, ScopeRule> profileMap = Maps.newHashMap();
for (ScopeDefinition def : inheritedDefinitions) {
for (ScopeRule rule : def.getRules()) {
final String profile = ScopeUtil.getSignature(rule);
profileMap.put(profile, rule);
}
}
for (ScopeDefinition def : context.getScopes()) {
for (ScopeRule rule : def.getRules()) {
final String profile = ScopeUtil.getSignature(rule);
final ScopeRule other = profileMap.get(profile);
if (other != null) {
errorOnDuplicate(rule, other, Messages.overriddenInheritedScopeRule, ScopePackage.Literals.SCOPE_RULE__CONTEXT);
}
}
}
}
use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeRule in project dsl-devkit by dsldevkit.
the class ScopeJavaValidator method checkGuardDefaultExists.
/**
* Checks that a guarded scope rule is matched by a unguarded default scope rule.
*
* @param context
* scope rule to check
*/
@Check
public void checkGuardDefaultExists(final ScopeRule context) {
if (context.getContext() == null || context.getContext().getGuard() == null) {
return;
}
ScopeDefinition def = EObjectUtil.eContainer(context, ScopeDefinition.class);
ScopeContext ctx = context.getContext();
boolean defaultFound = false;
for (ScopeRule r : def.getRules()) {
ScopeContext c = r.getContext();
if (c != null && c.getGuard() == null && c.getContextType() == ctx.getContextType()) {
defaultFound = true;
break;
}
}
if (!defaultFound) {
warning("No matching default scope rule defined", ScopePackage.Literals.SCOPE_RULE__CONTEXT);
}
}
Aggregations