Search in sources :

Example 1 with Export

use of com.avaloq.tools.ddk.xtext.export.export.Export 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 2 with Export

use of com.avaloq.tools.ddk.xtext.export.export.Export in project dsl-devkit by dsldevkit.

the class ExportFragment method getGuiceBindingsRt.

/**
 * {@inheritDoc}
 */
@Override
public Set<Binding> getGuiceBindingsRt(final Grammar grammar) {
    final BindFactory bindFactory = new BindFactory();
    // $NON-NLS-1$
    final String namingPrefix = GrammarUtil.getNamespace(grammar) + ".naming." + GrammarUtil.getName(grammar);
    // $NON-NLS-1$
    final String resourcePrefix = GrammarUtil.getNamespace(grammar) + ".resource." + GrammarUtil.getName(grammar);
    ExportModel m = getModel(grammar);
    if (m != null) {
        // $NON-NLS-1$
        bindFactory.addTypeToType(IQualifiedNameProvider.class.getName(), namingPrefix + "ExportedNamesProvider");
        if (!m.getInterfaces().isEmpty()) {
            // $NON-NLS-1$
            bindFactory.addTypeToType(IFingerprintComputer.class.getName(), resourcePrefix + "FingerprintComputer");
        }
        if (!m.getExports().isEmpty()) {
            // $NON-NLS-1$
            bindFactory.addTypeToType(IDefaultResourceDescriptionStrategy.class.getName(), resourcePrefix + "ResourceDescriptionStrategy");
        }
        if (Iterables.any(m.getExports(), new Predicate<Export>() {

            @Override
            public boolean apply(final Export input) {
                return input.isFingerprint() && input.getFragmentAttribute() != null;
            }
        })) {
            // $NON-NLS-1$
            bindFactory.addTypeToType(IFragmentProvider.class.getName(), resourcePrefix + "FragmentProvider");
        }
    }
    // $NON-NLS-1$
    bindFactory.addTypeToType(IResourceDescription.Manager.class.getName(), resourcePrefix + "ResourceDescriptionManager");
    return bindFactory.getBindings();
}
Also used : IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) IFingerprintComputer(com.avaloq.tools.ddk.xtext.resource.IFingerprintComputer) IDefaultResourceDescriptionStrategy(org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy) ExportModel(com.avaloq.tools.ddk.xtext.export.export.ExportModel) Export(com.avaloq.tools.ddk.xtext.export.export.Export) BindFactory(org.eclipse.xtext.generator.BindFactory) IFragmentProvider(org.eclipse.xtext.resource.IFragmentProvider)

Example 3 with Export

use of com.avaloq.tools.ddk.xtext.export.export.Export in project dsl-devkit by dsldevkit.

the class ExportJavaValidator method checkConsistentFingerprints.

/**
 * Make sure only one type of fingerprinting is used.
 *
 * @param context
 *          export model
 */
@Check
public void checkConsistentFingerprints(final ExportModel context) {
    List<Export> resourceFingerprintExports = Lists.newArrayList();
    List<Export> objectFingerprintExports = Lists.newArrayList();
    for (Export exp : context.getExports()) {
        if (exp.isResourceFingerprint()) {
            resourceFingerprintExports.add(exp);
        } else if (exp.isFingerprint()) {
            objectFingerprintExports.add(exp);
        }
    }
    if (!objectFingerprintExports.isEmpty() && !resourceFingerprintExports.isEmpty()) {
        for (Export exp : Iterables.concat(resourceFingerprintExports, objectFingerprintExports)) {
            error("Resource and object fingerprints cannot be mixed", exp, exp.isFingerprint() ? ExportPackage.Literals.EXPORT__FINGERPRINT : ExportPackage.Literals.EXPORT__RESOURCE_FINGERPRINT, null);
        }
    }
}
Also used : Export(com.avaloq.tools.ddk.xtext.export.export.Export) Check(org.eclipse.xtext.validation.Check)

Aggregations

Export (com.avaloq.tools.ddk.xtext.export.export.Export)3 Check (org.eclipse.xtext.validation.Check)2 Attribute (com.avaloq.tools.ddk.xtext.export.export.Attribute)1 ExportModel (com.avaloq.tools.ddk.xtext.export.export.ExportModel)1 UserData (com.avaloq.tools.ddk.xtext.export.export.UserData)1 IFingerprintComputer (com.avaloq.tools.ddk.xtext.resource.IFingerprintComputer)1 UniquenessJavaValidationHelper (com.avaloq.tools.ddk.xtext.validation.UniquenessJavaValidationHelper)1 BindFactory (org.eclipse.xtext.generator.BindFactory)1 IQualifiedNameProvider (org.eclipse.xtext.naming.IQualifiedNameProvider)1 IDefaultResourceDescriptionStrategy (org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy)1 IFragmentProvider (org.eclipse.xtext.resource.IFragmentProvider)1