Search in sources :

Example 1 with Declaration

use of org.eclipse.xtext.example.homeautomation.ruleEngine.Declaration in project xtext-eclipse by eclipse.

the class RuleEngineValidator method checkUniqueDeclarations.

@Check
public void checkUniqueDeclarations(Model model) {
    Set<String> deviceNames = new HashSet<>();
    Set<String> ruleDescriptions = new HashSet<>();
    for (Declaration decl : model.getDeclarations()) {
        if (decl instanceof Device) {
            String name = ((Device) decl).getName();
            if (!deviceNames.add(name)) {
                error("Device names must be unique.", decl, RuleEnginePackage.Literals.DEVICE__NAME);
            }
        } else {
            String methodName = RuleEngineJvmModelInferrer.getRuleMethodName((Rule) decl);
            if (!ruleDescriptions.add(methodName)) {
                error("Rule descriptions must be unique.", decl, RuleEnginePackage.Literals.RULE__DESCRIPTION);
            }
        }
    }
}
Also used : Device(org.eclipse.xtext.example.homeautomation.ruleEngine.Device) Declaration(org.eclipse.xtext.example.homeautomation.ruleEngine.Declaration) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Example 2 with Declaration

use of org.eclipse.xtext.example.homeautomation.ruleEngine.Declaration in project xtext-eclipse by eclipse.

the class RuleEngineFormatter method _format.

protected void _format(final Model model, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.setNewLines(0, 0, 1);
        it.noSpace();
    };
    document.<Model>prepend(model, _function);
    EList<Declaration> _declarations = model.getDeclarations();
    for (final Declaration declaration : _declarations) {
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.setNewLines(1, 1, 2);
        };
        document.<Declaration>append(document.<Declaration>format(declaration), _function_1);
    }
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Model(org.eclipse.xtext.example.homeautomation.ruleEngine.Model) Declaration(org.eclipse.xtext.example.homeautomation.ruleEngine.Declaration) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Aggregations

Declaration (org.eclipse.xtext.example.homeautomation.ruleEngine.Declaration)2 HashSet (java.util.HashSet)1 Device (org.eclipse.xtext.example.homeautomation.ruleEngine.Device)1 Model (org.eclipse.xtext.example.homeautomation.ruleEngine.Model)1 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)1 Check (org.eclipse.xtext.validation.Check)1 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)1 XImportDeclaration (org.eclipse.xtext.xtype.XImportDeclaration)1