use of com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration in project dsl-devkit by dsldevkit.
the class FormatJavaValidator method checkRequiredRulesImplemented.
/**
* Check that identically named parent grammar rules are implemented in the model if the parent configuration implements the rule.
* If both grammars have an identically named rule then the extending FormatConfiguration must declare formatting if the parent FormatConfiguration does.
*
* @param model
* the model
*/
@Check
public void checkRequiredRulesImplemented(final FormatConfiguration model) {
FormatConfiguration extendedModel = model.getExtendedFormatConfiguration();
if (extendedModel == null || extendedModel.eIsProxy() || model.getTargetGrammar() == extendedModel.getTargetGrammar()) {
// NOPMD
return;
}
Iterable<GrammarRule> inheritedRules = Iterables.filter(collectRules(extendedModel), GrammarRule.class);
Set<String> ruleNames = Sets.newHashSet(Iterables.transform(inheritedRules, new Function<GrammarRule, String>() {
@Override
public String apply(final GrammarRule from) {
return from.getTargetRule().getName();
}
}));
for (GrammarRule rule : Iterables.filter(model.getRules(), GrammarRule.class)) {
if (rule.getTargetRule() != null && !rule.getTargetRule().eIsProxy()) {
ruleNames.remove(rule.getTargetRule().getName());
}
}
for (AbstractRule rule : model.getTargetGrammar().getRules()) {
if (ruleNames.contains(rule.getName())) {
error(NLS.bind("Required formatting for rule \"{0}\" missing", rule.getName()), FormatPackage.Literals.FORMAT_CONFIGURATION__TARGET_GRAMMAR, GRAMMAR_RULE_MISSING_CODE, rule.getName());
}
}
}
use of com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration in project dsl-devkit by dsldevkit.
the class FormatJavaValidator method checkExtendedGrammarCompatible.
/**
* Check that extended configuration's grammar is compatible.
*
* @param model
* the model
*/
@Check
public void checkExtendedGrammarCompatible(final FormatConfiguration model) {
FormatConfiguration extendedModel = model.getExtendedFormatConfiguration();
if (extendedModel == null || extendedModel.eIsProxy()) {
return;
}
if (!extendedModel.getTargetGrammar().eIsProxy()) {
List<Grammar> grammars = Lists.newArrayList(model.getTargetGrammar());
grammars.addAll(model.getTargetGrammar().getUsedGrammars());
for (Grammar grammar : grammars) {
if (extendedModel.getTargetGrammar().getName().equals(grammar.getName())) {
return;
}
}
}
error("Extended format configuration has incompatible grammar", FormatPackage.Literals.FORMAT_CONFIGURATION__EXTENDED_FORMAT_CONFIGURATION, EXTENDED_GRAMMAR_INCOMPATIBLE_CODE);
}
use of com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration in project dsl-devkit by dsldevkit.
the class FormatJavaValidator method checkIllegalOverride.
/**
* Checks that no rule declares override when there is no corresponding inherited rule.
*
* @param model
* the model
*/
@Check
public void checkIllegalOverride(final FormatConfiguration model) {
Iterable<Rule> overrideRules = Iterables.filter(model.getRules(), IS_OVERRIDE);
Iterable<Rule> overrideableRules = Lists.newArrayList();
FormatConfiguration extendedModel = model.getExtendedFormatConfiguration();
if (extendedModel != null && !extendedModel.eIsProxy()) {
overrideableRules = collectRules(extendedModel);
}
Map<AbstractRule, GrammarRule> overrideableAbstractRuleMap = Maps.newHashMap();
for (GrammarRule rule : Iterables.filter(overrideableRules, GrammarRule.class)) {
overrideableAbstractRuleMap.put(TARGET_RULE.apply(rule), rule);
}
// Check GrammarRules
for (GrammarRule overrideRule : Iterables.filter(overrideRules, GrammarRule.class)) {
if (!overrideableAbstractRuleMap.containsKey(TARGET_RULE.apply(overrideRule))) {
error(OVERRIDE_ILLEGAL_MESSAGE, overrideRule, FormatPackage.Literals.GRAMMAR_RULE__TARGET_RULE, OVERRIDE_ILLEGAL_CODE);
}
}
// Check WildcardRule
if (!Iterables.isEmpty(Iterables.filter(overrideRules, WildcardRule.class)) && Iterables.isEmpty(Iterables.filter(overrideableRules, WildcardRule.class))) {
error(OVERRIDE_ILLEGAL_MESSAGE, Iterables.filter(overrideRules, WildcardRule.class).iterator().next(), null, OVERRIDE_ILLEGAL_CODE);
}
}
use of com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration in project dsl-devkit by dsldevkit.
the class FormatLinkingService method getConstant.
/**
* Tries to find {@link Constant} that my be defined in the same formatter or in any formatter that is extended by the current formatter.
* An appropriate constant should be matched by comparing its name with the desired one.
*
* @param resourceSet
* to be used for loading
* @param node
* parse subtree for the reference
* @return A singleton list containing the desired constant, or an empty list if not found.
*/
private List<EObject> getConstant(final ResourceSet resourceSet, final INode node) {
String constantFullyQualifiedName = NodeModelUtils.getTokenText(node);
String formatName = URI.createURI(constantFullyQualifiedName).trimFileExtension().toString();
if (formatName != null) {
FormatConfiguration result = loadExtendedFormatConfiguration(formatName, resourceSet);
if (result != null) {
EList<Constant> constants = result.getConstants();
for (Constant constant : constants) {
if (constantFullyQualifiedName.equals(formatName + "." + constant.getName())) {
return Collections.<EObject>singletonList(constant);
}
}
}
}
return Collections.emptyList();
}
use of com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration in project dsl-devkit by dsldevkit.
the class FormatHyperlinkHelper method getExtendedRules.
/**
* Gets all extended rules.
*
* @param rule
* the rule
* @return list with all extended rules
*/
private List<Rule> getExtendedRules(final Rule rule) {
FormatConfiguration model = EObjectUtil.eContainer(rule, FormatConfiguration.class);
List<Rule> result = Lists.newArrayList();
for (FormatConfiguration extendedModel : getExtendedModels(model)) {
for (Rule candidate : extendedModel.getRules()) {
if (//
rule instanceof GrammarRule && candidate instanceof GrammarRule && ((GrammarRule) rule).getTargetRule().equals(((GrammarRule) candidate).getTargetRule())) {
result.add(candidate);
} else if (rule instanceof WildcardRule && candidate instanceof WildcardRule) {
result.add(candidate);
}
}
}
return result;
}
Aggregations