Search in sources :

Example 1 with ILibraryDescriptor

use of org.yakindu.sct.generator.core.extensions.ILibraryDescriptor in project statecharts by Yakindu.

the class SGenTemplateProposalProvider method createFeatureConfigurationTemplates.

private void createFeatureConfigurationTemplates(TemplateContext templateContext, ContentAssistContext context, ITemplateAcceptor acceptor) {
    GeneratorModel model = (GeneratorModel) EcoreUtil2.getRootContainer(context.getCurrentModel());
    IGeneratorDescriptor generatorDescriptor = GeneratorExtensions.getGeneratorDescriptor(model.getGeneratorId());
    Iterable<ILibraryDescriptor> libraryDescriptor = LibraryExtensions.getLibraryDescriptors(generatorDescriptor.getLibraryIDs());
    for (ILibraryDescriptor desc : libraryDescriptor) {
        ResourceSet set = new ResourceSetImpl();
        Resource resource = set.getResource(desc.getURI(), true);
        FeatureTypeLibrary lib = (FeatureTypeLibrary) resource.getContents().get(0);
        EList<FeatureType> types = lib.getTypes();
        for (FeatureType featureType : types) {
            Template template = new Template(featureType.getName() + " feature", "Creates feature " + featureType.getName(), featureType.getName(), creator.createProposal(featureType, desc.createFeatureValueProvider(SGenActivator.getInstance().getInjector(SGenActivator.ORG_YAKINDU_SCT_GENERATOR_GENMODEL_SGEN)), context.getCurrentModel()), false);
            TemplateProposal proposal = createProposal(template, templateContext, context, getImage(template), getRelevance(template));
            acceptor.accept(proposal);
        }
    }
}
Also used : TemplateProposal(org.eclipse.jface.text.templates.TemplateProposal) FeatureType(org.yakindu.sct.model.sgen.FeatureType) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) FeatureTypeLibrary(org.yakindu.sct.model.sgen.FeatureTypeLibrary) Resource(org.eclipse.emf.ecore.resource.Resource) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ILibraryDescriptor(org.yakindu.sct.generator.core.extensions.ILibraryDescriptor) Template(org.eclipse.jface.text.templates.Template)

Example 2 with ILibraryDescriptor

use of org.yakindu.sct.generator.core.extensions.ILibraryDescriptor in project statecharts by Yakindu.

the class SGenScopeProvider method getLibraryScope.

protected SimpleScope getLibraryScope(Resource resource) {
    GeneratorModel generatorModel = (GeneratorModel) EcoreUtil.getObjectByType(resource.getContents(), SGenPackage.Literals.GENERATOR_MODEL);
    Assert.isNotNull(generatorModel);
    String generatorId = generatorModel.getGeneratorId();
    IGeneratorDescriptor generatorDescriptor = GeneratorExtensions.getGeneratorDescriptor(generatorId);
    Iterable<IEObjectDescription> allElements = Lists.newArrayList();
    if (generatorDescriptor != null) {
        Iterable<ILibraryDescriptor> libraryDescriptor = LibraryExtensions.getLibraryDescriptors(generatorDescriptor.getLibraryIDs());
        for (ILibraryDescriptor desc : libraryDescriptor) {
            Resource library = resourceSet.getResource(desc.getURI(), true);
            FeatureResourceDescription description = new FeatureResourceDescription(library);
            injector.injectMembers(description);
            allElements = Iterables.concat(allElements, description.getExportedObjects());
        }
    }
    return new SimpleScope(allElements);
}
Also used : FeatureResourceDescription(org.yakindu.sct.generator.genmodel.resource.FeatureResourceDescription) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) Resource(org.eclipse.emf.ecore.resource.Resource) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ILibraryDescriptor(org.yakindu.sct.generator.core.extensions.ILibraryDescriptor)

Example 3 with ILibraryDescriptor

use of org.yakindu.sct.generator.core.extensions.ILibraryDescriptor in project statecharts by Yakindu.

the class SGenJavaValidator method checkRequiredParameters.

@Check
public void checkRequiredParameters(FeatureConfiguration configuration) {
    GeneratorModel model = (GeneratorModel) EcoreUtil2.getRootContainer(configuration);
    IGeneratorDescriptor generatorDescriptor = GeneratorExtensions.getGeneratorDescriptor(model.getGeneratorId());
    Iterable<ILibraryDescriptor> libraryDescriptors = LibraryExtensions.getLibraryDescriptors(generatorDescriptor.getLibraryIDs());
    Iterable<String> requiredParameters = transform(filter(concat(transform(filter(concat(transform(transform(libraryDescriptors, getFeatureTypeLibrary()), getFeatureTypes())), hasName(configuration.getType().getName())), getParameter())), isRequiredParamter()), getName());
    List<String> configuredParameters = Lists.newArrayList();
    for (FeatureParameterValue featureParameterValue : configuration.getParameterValues()) {
        configuredParameters.add(featureParameterValue.getParameter().getName());
    }
    for (String string : requiredParameters) {
        if (!configuredParameters.contains(string))
            error(String.format(MISSING_REQUIRED_PARAMETER + " %s", string), SGenPackage.Literals.FEATURE_CONFIGURATION__TYPE);
    }
}
Also used : FeatureParameterValue(org.yakindu.sct.model.sgen.FeatureParameterValue) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) ILibraryDescriptor(org.yakindu.sct.generator.core.extensions.ILibraryDescriptor) Check(org.eclipse.xtext.validation.Check)

Example 4 with ILibraryDescriptor

use of org.yakindu.sct.generator.core.extensions.ILibraryDescriptor in project statecharts by Yakindu.

the class HelpIntegrationTest method getAllElements.

private Iterable<IEObjectDescription> getAllElements(String generatorId) {
    IGeneratorDescriptor generatorDescriptor = GeneratorExtensions.getGeneratorDescriptor(generatorId);
    Iterable<ILibraryDescriptor> libraryDescriptor = LibraryExtensions.getLibraryDescriptors(generatorDescriptor.getLibraryIDs());
    Iterable<IEObjectDescription> allElements = Lists.newArrayList();
    for (ILibraryDescriptor desc : libraryDescriptor) {
        Resource library = resourceSet.getResource(desc.getURI(), true);
        FeatureResourceDescription description = new FeatureResourceDescription(library);
        injector.injectMembers(description);
        allElements = Iterables.concat(allElements, description.getExportedObjects());
    }
    return allElements;
}
Also used : FeatureResourceDescription(org.yakindu.sct.generator.genmodel.resource.FeatureResourceDescription) Resource(org.eclipse.emf.ecore.resource.Resource) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) ILibraryDescriptor(org.yakindu.sct.generator.core.extensions.ILibraryDescriptor) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 5 with ILibraryDescriptor

use of org.yakindu.sct.generator.core.extensions.ILibraryDescriptor in project statecharts by Yakindu.

the class SGenJavaValidator method checkRequiredFeatures.

@Check
public void checkRequiredFeatures(GeneratorEntry entry) {
    GeneratorModel model = (GeneratorModel) EcoreUtil2.getRootContainer(entry);
    IGeneratorDescriptor generatorDescriptor = GeneratorExtensions.getGeneratorDescriptor(model.getGeneratorId());
    Iterable<ILibraryDescriptor> libraryDescriptors = LibraryExtensions.getLibraryDescriptors(generatorDescriptor.getLibraryIDs());
    Iterable<FeatureType> requiredFeatures = filter(concat(transform(transform(libraryDescriptors, getFeatureTypeLibrary()), getFeatureTypes())), isRequired());
    List<String> configuredTypes = Lists.newArrayList();
    for (FeatureConfiguration featureConfiguration : entry.getFeatures()) {
        configuredTypes.add(featureConfiguration.getType().getName());
    }
    for (FeatureType featureType : requiredFeatures) {
        if (!configuredTypes.contains(featureType.getName()))
            error(String.format(MISSING_REQUIRED_FEATURE + " %s", featureType.getName()), SGenPackage.Literals.GENERATOR_ENTRY__ELEMENT_REF, CODE_REQUIRED_FEATURE, featureType.getName());
    }
}
Also used : FeatureType(org.yakindu.sct.model.sgen.FeatureType) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) FeatureConfiguration(org.yakindu.sct.model.sgen.FeatureConfiguration) ILibraryDescriptor(org.yakindu.sct.generator.core.extensions.ILibraryDescriptor) Check(org.eclipse.xtext.validation.Check)

Aggregations

ILibraryDescriptor (org.yakindu.sct.generator.core.extensions.ILibraryDescriptor)7 IGeneratorDescriptor (org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor)6 Resource (org.eclipse.emf.ecore.resource.Resource)5 GeneratorModel (org.yakindu.sct.model.sgen.GeneratorModel)5 FeatureType (org.yakindu.sct.model.sgen.FeatureType)4 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 FeatureTypeLibrary (org.yakindu.sct.model.sgen.FeatureTypeLibrary)3 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 Check (org.eclipse.xtext.validation.Check)2 FeatureResourceDescription (org.yakindu.sct.generator.genmodel.resource.FeatureResourceDescription)2 Template (org.eclipse.jface.text.templates.Template)1 TemplateProposal (org.eclipse.jface.text.templates.TemplateProposal)1 SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)1 IDefaultFeatureValueProvider (org.yakindu.sct.generator.core.library.IDefaultFeatureValueProvider)1 FeatureConfiguration (org.yakindu.sct.model.sgen.FeatureConfiguration)1 FeatureParameterValue (org.yakindu.sct.model.sgen.FeatureParameterValue)1