Search in sources :

Example 1 with UniquenessJavaValidationHelper

use of com.avaloq.tools.ddk.xtext.validation.UniquenessJavaValidationHelper in project dsl-devkit by dsldevkit.

the class ExportJavaValidator method checkInterfaceFieldUniqueness.

/**
 * Checks that the interface don't have overlapping features, as a feature export is inherited by the export of subtypes.
 *
 * @param context
 *          model to check
 */
@Check
public void checkInterfaceFieldUniqueness(final ExportModel context) {
    UniquenessJavaValidationHelper<InterfaceField> helper1 = new UniquenessJavaValidationHelper<InterfaceField>(new AbstractNameFunction() {

        @Override
        public QualifiedName apply(final EObject from) {
            String name = ((InterfaceField) from).getField().getName();
            return QualifiedName.create(name != null ? name : "");
        }
    }, getMessageAcceptor());
    UniquenessJavaValidationHelper<InterfaceNavigation> helper2 = new UniquenessJavaValidationHelper<InterfaceNavigation>(new AbstractNameFunction() {

        @Override
        public QualifiedName apply(final EObject from) {
            String name = ((InterfaceNavigation) from).getRef().getName();
            return QualifiedName.create(name != null ? name : "");
        }
    }, getMessageAcceptor());
    for (Interface fingertype : context.getInterfaces()) {
        helper1.errorOnDuplicates(Iterables.filter(fingertype.getItems(), InterfaceField.class), ExportPackage.Literals.INTERFACE_FIELD__FIELD);
        helper2.errorOnDuplicates(Iterables.filter(fingertype.getItems(), InterfaceNavigation.class), ExportPackage.Literals.INTERFACE_NAVIGATION__REF);
    }
}
Also used : AbstractNameFunction(com.avaloq.tools.ddk.xtext.scoping.AbstractNameFunction) InterfaceNavigation(com.avaloq.tools.ddk.xtext.export.export.InterfaceNavigation) EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) InterfaceField(com.avaloq.tools.ddk.xtext.export.export.InterfaceField) UniquenessJavaValidationHelper(com.avaloq.tools.ddk.xtext.validation.UniquenessJavaValidationHelper) Interface(com.avaloq.tools.ddk.xtext.export.export.Interface) Check(org.eclipse.xtext.validation.Check)

Example 2 with UniquenessJavaValidationHelper

use of com.avaloq.tools.ddk.xtext.validation.UniquenessJavaValidationHelper in project dsl-devkit by dsldevkit.

the class ExportJavaValidator method checkExportFieldUniqueness.

/**
 * Checks that the exports don't have overlapping features, as a feature export is inherited by the export of subtypes.
 *
 * @param context
 *          model to check
 */
@Check
public void checkExportFieldUniqueness(final ExportModel context) {
    UniquenessJavaValidationHelper<Attribute> helper = new UniquenessJavaValidationHelper<Attribute>(NameFunctions.fromFeature(ExportPackage.Literals.ATTRIBUTE__ATTRIBUTE), getMessageAcceptor()) {

        @Override
        public String getMessage(final Attribute attribute) {
            return "duplicate found: " + attribute.getAttribute().getName();
        }
    };
    UniquenessJavaValidationHelper<UserData> helper2 = new UniquenessJavaValidationHelper<UserData>(NameFunctions.fromFeature(ExportPackage.Literals.USER_DATA__NAME), getMessageAcceptor());
    for (Export export : context.getExports()) {
        helper.errorOnDuplicates(export.getAttributes(), ExportPackage.Literals.ATTRIBUTE__ATTRIBUTE);
        helper2.errorOnDuplicates(export.getUserData(), ExportPackage.Literals.USER_DATA__NAME);
    }
}
Also used : Attribute(com.avaloq.tools.ddk.xtext.export.export.Attribute) UserData(com.avaloq.tools.ddk.xtext.export.export.UserData) Export(com.avaloq.tools.ddk.xtext.export.export.Export) UniquenessJavaValidationHelper(com.avaloq.tools.ddk.xtext.validation.UniquenessJavaValidationHelper) Check(org.eclipse.xtext.validation.Check)

Example 3 with UniquenessJavaValidationHelper

use of com.avaloq.tools.ddk.xtext.validation.UniquenessJavaValidationHelper in project dsl-devkit by dsldevkit.

the class ExportJavaValidator method checkInterfaceAndExportUniqueness.

/**
 * Checks that the interfaces and exports in an export section all are declared for a unique type.
 *
 * @param context
 *          model to check
 */
@Check
public void checkInterfaceAndExportUniqueness(final ExportModel context) {
    UniquenessJavaValidationHelper<DeclarationForType> helper = new UniquenessJavaValidationHelper<DeclarationForType>(new AbstractNameFunction() {

        @Override
        public QualifiedName apply(final EObject from) {
            return QualifiedName.create(((DeclarationForType) from).getType().getEPackage().getName(), ((DeclarationForType) from).getType().getName());
        }
    }, getMessageAcceptor()) {

        @Override
        public String getMessage(final DeclarationForType declaration) {
            return "declaration duplicate found: " + declaration.getType().getEPackage().getName() + "::" + declaration.getType().getName();
        }
    };
    helper.errorOnDuplicates(Iterables.filter(context.getInterfaces(), DeclarationForType.class), ExportPackage.Literals.DECLARATION_FOR_TYPE__TYPE);
    helper.errorOnDuplicates(Iterables.filter(context.getExports(), DeclarationForType.class), ExportPackage.Literals.DECLARATION_FOR_TYPE__TYPE);
}
Also used : AbstractNameFunction(com.avaloq.tools.ddk.xtext.scoping.AbstractNameFunction) DeclarationForType(com.avaloq.tools.ddk.xtext.export.export.DeclarationForType) EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) UniquenessJavaValidationHelper(com.avaloq.tools.ddk.xtext.validation.UniquenessJavaValidationHelper) Check(org.eclipse.xtext.validation.Check)

Aggregations

UniquenessJavaValidationHelper (com.avaloq.tools.ddk.xtext.validation.UniquenessJavaValidationHelper)3 Check (org.eclipse.xtext.validation.Check)3 AbstractNameFunction (com.avaloq.tools.ddk.xtext.scoping.AbstractNameFunction)2 EObject (org.eclipse.emf.ecore.EObject)2 QualifiedName (org.eclipse.xtext.naming.QualifiedName)2 Attribute (com.avaloq.tools.ddk.xtext.export.export.Attribute)1 DeclarationForType (com.avaloq.tools.ddk.xtext.export.export.DeclarationForType)1 Export (com.avaloq.tools.ddk.xtext.export.export.Export)1 Interface (com.avaloq.tools.ddk.xtext.export.export.Interface)1 InterfaceField (com.avaloq.tools.ddk.xtext.export.export.InterfaceField)1 InterfaceNavigation (com.avaloq.tools.ddk.xtext.export.export.InterfaceNavigation)1 UserData (com.avaloq.tools.ddk.xtext.export.export.UserData)1