Search in sources :

Example 11 with IGeneratorDescriptor

use of org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor 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)

Example 12 with IGeneratorDescriptor

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

the class SGenNewFileWizard method createDefaultModel.

private Resource createDefaultModel(URI uri) {
    List<EObject> selectedObjects = generatorConfigPage.getSelectedElements();
    IGeneratorDescriptor selectedGenerator = generatorConfigPage.getSelectedGenerator();
    ModelCreator creator = new ModelCreator(selectedGenerator, selectedObjects);
    GeneratorModel model = creator.create();
    Resource resource = resourceSet.createResource(uri);
    resource.getContents().add(model);
    try {
        resource.save(Collections.EMPTY_MAP);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return resource;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) IOException(java.io.IOException)

Example 13 with IGeneratorDescriptor

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

the class SGenProposalProvider method completeGeneratorModel_GeneratorId.

@Override
public void completeGeneratorModel_GeneratorId(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    Iterable<IGeneratorDescriptor> descriptions = GeneratorExtensions.getGeneratorDescriptors();
    for (IGeneratorDescriptor desc : descriptions) {
        ICompletionProposal proposal = createCompletionProposal(desc.getId(), new StyledString((desc.getName() != null) ? desc.getName() : "null"), PathToImageResolver.toImage(desc.getImagePath()), context);
        if (proposal instanceof ConfigurableCompletionProposal) {
            ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
            configurable.setAdditionalProposalInfo(desc.getDescription());
        }
        acceptor.accept(proposal);
    }
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) StyledString(org.eclipse.jface.viewers.StyledString)

Example 14 with IGeneratorDescriptor

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

the class SGenQuickfixProvider method getDefaultFeatureConfiguration.

private FeatureConfiguration getDefaultFeatureConfiguration(final Issue issue, EObject element) {
    GeneratorModel model = (GeneratorModel) EcoreUtil2.getRootContainer(element);
    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) {
            if (featureType.getName().equals(issue.getData()[0])) {
                IDefaultFeatureValueProvider valueProvider = desc.createFeatureValueProvider(SGenActivator.getInstance().getInjector(SGenActivator.ORG_YAKINDU_SCT_GENERATOR_GENMODEL_SGEN));
                if (valueProvider != null) {
                    return valueProvider.createDefaultFeatureConfiguration(featureType, element);
                }
            }
        }
    }
    return null;
}
Also used : FeatureType(org.yakindu.sct.model.sgen.FeatureType) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) FeatureTypeLibrary(org.yakindu.sct.model.sgen.FeatureTypeLibrary) IDefaultFeatureValueProvider(org.yakindu.sct.generator.core.library.IDefaultFeatureValueProvider) 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)

Example 15 with IGeneratorDescriptor

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

the class GeneratorExecutorLookup method createExecutor.

public IGeneratorEntryExecutor createExecutor(GeneratorEntry entry, String generatorId) {
    IGeneratorDescriptor description = GeneratorExtensions.getGeneratorDescriptor(generatorId);
    if (description == null)
        throw new RuntimeException("No generator registered for ID: " + generatorId);
    final IGeneratorEntryExecutor executor = description.createExecutor();
    if (executor == null)
        throw new RuntimeException("Failed to create generator instance for ID:" + generatorId);
    Injector injector = createInjector(entry, description, generatorId);
    injector.injectMembers(executor);
    ITypeSystem typeSystem = injector.getInstance(ITypeSystem.class);
    if (entry.getElementRef() == null || entry.getElementRef().eResource() == null) {
        throw new RuntimeException("Could not resolve reference to model ");
    }
    if (typeSystem instanceof AbstractTypeSystem) {
        ResourceSet set = entry.getElementRef().eResource().getResourceSet();
        set.getResources().add(((AbstractTypeSystem) typeSystem).getResource());
        // XXX: avoid resolving the whole resource set, because there might
        // be models with different domains, we have to ensure that just the
        // models related to the current entry are resolved
        EcoreUtil.resolveAll(entry);
        EcoreUtil.resolveAll(entry.getElementRef());
        EcoreUtil.resolveAll(((AbstractTypeSystem) typeSystem).getResource());
    }
    return executor;
}
Also used : ITypeSystem(org.yakindu.base.types.typesystem.ITypeSystem) Injector(com.google.inject.Injector) AbstractTypeSystem(org.yakindu.base.types.typesystem.AbstractTypeSystem) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Aggregations

IGeneratorDescriptor (org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor)15 GeneratorModel (org.yakindu.sct.model.sgen.GeneratorModel)10 Resource (org.eclipse.emf.ecore.resource.Resource)6 ILibraryDescriptor (org.yakindu.sct.generator.core.extensions.ILibraryDescriptor)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 Check (org.eclipse.xtext.validation.Check)4 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)3 FeatureType (org.yakindu.sct.model.sgen.FeatureType)3 IResource (org.eclipse.core.resources.IResource)2 EClass (org.eclipse.emf.ecore.EClass)2 EObject (org.eclipse.emf.ecore.EObject)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)2 IDefaultFeatureValueProvider (org.yakindu.sct.generator.core.library.IDefaultFeatureValueProvider)2 FeatureResourceDescription (org.yakindu.sct.generator.genmodel.resource.FeatureResourceDescription)2 FeatureTypeLibrary (org.yakindu.sct.model.sgen.FeatureTypeLibrary)2 Injector (com.google.inject.Injector)1 IOException (java.io.IOException)1 IStatus (org.eclipse.core.runtime.IStatus)1