use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition in project dsl-devkit by dsldevkit.
the class ScopeJavaValidator method checkScopeDefinitionUniqueness.
/**
* Checks that all scope definitions are unique. If not a warning is issued.
*
* @param context
* scoping section to check
*/
@Check
public void checkScopeDefinitionUniqueness(final ScopeModel context) {
// NOPMD
final Map<String, ScopeDefinition> profileMap = Maps.newHashMap();
for (ScopeDefinition def : context.getScopes()) {
String profile = null;
if (isDefaultScope(def)) {
profile = def.getTargetType() != null ? def.getTargetType().toString() : def.getReference().toString();
} else {
profile = def.getName();
}
final ScopeDefinition other = profileMap.get(profile);
if (other != null) {
EStructuralFeature feature = isDefaultScope(def) ? (def.getTargetType() != null ? ScopePackage.Literals.SCOPE_DEFINITION__TARGET_TYPE : ScopePackage.Literals.SCOPE_DEFINITION__REFERENCE) : ScopePackage.Literals.SCOPE_DEFINITION__NAME;
errorOnDuplicate(def, other, Messages.duplicatedScopeDefinition, feature);
} else {
profileMap.put(profile, def);
}
if (!isDefaultScope(def)) {
ScopeDefinition base = getOverriddenScope(context, def);
if (base != null && (def.getTargetType() != base.getTargetType() || def.getReference() != base.getReference())) {
errorOnDuplicate(def, base, Messages.wrongScopeDefinitionSignature, ScopePackage.Literals.SCOPE_DEFINITION__NAME);
}
}
}
}
use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition 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.ScopeDefinition 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.ScopeDefinition in project dsl-devkit by dsldevkit.
the class ScopeUtil method getSignature.
/**
* Computes a signature string representation which must be unique for the given rule.
*
* @param rule
* rule to calculate signature for
* @return string signature
*/
public static String getSignature(final ScopeRule rule) {
// NOPMD NPathComplexity
StringBuffer result = new StringBuffer();
final ScopeDefinition def = EObjectUtil.eContainer(rule, ScopeDefinition.class);
result.append(def.getName()).append('_');
final EClass type = def.getReference() != null ? def.getReference().getEReferenceType() : def.getTargetType();
final EReference ref = def.getReference();
if (ref != null) {
result.append(ref.getEContainingClass().getEPackage().getName()).append('_').append(ref.getEContainingClass().getName()).append('_').append(ref.getName()).append("_EReference");
} else {
result.append(type.getEPackage().getName()).append('_').append(type.getName()).append("_EClass");
}
result.append('_');
if (rule.getContext().isGlobal()) {
result.append("org.eclipse.emf.ecore.resource.Resource");
} else {
result.append(rule.getContext().getContextType().getEPackage().getName()).append('_').append(rule.getContext().getContextType().getName());
}
return result.toString();
}
use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition in project dsl-devkit by dsldevkit.
the class ScopeDelegationImpl method setScope.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setScope(ScopeDefinition newScope) {
ScopeDefinition oldScope = scope;
scope = newScope;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ScopePackage.SCOPE_DELEGATION__SCOPE, oldScope, scope));
}
Aggregations