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());
}
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations