Search in sources :

Example 6 with GeneratorModel

use of org.yakindu.sct.model.sgen.GeneratorModel 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 7 with GeneratorModel

use of org.yakindu.sct.model.sgen.GeneratorModel in project statecharts by Yakindu.

the class SGenJavaValidator method checkContentType.

@Check
public void checkContentType(GeneratorEntry entry) {
    GeneratorModel generatorModel = EcoreUtil2.getContainerOfType(entry, GeneratorModel.class);
    IGeneratorDescriptor descriptor = GeneratorExtensions.getGeneratorDescriptor(generatorModel.getGeneratorId());
    if (descriptor == null)
        return;
    String contentType = entry.getContentType();
    if (contentType == null || contentType.trim().length() == 0) {
        return;
    }
    if (!contentType.equals(descriptor.getContentType())) {
        error(UNKNOWN_CONTENT_TYPE + contentType + "'", SGenPackage.Literals.GENERATOR_ENTRY__CONTENT_TYPE);
    }
}
Also used : GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) Check(org.eclipse.xtext.validation.Check)

Example 8 with GeneratorModel

use of org.yakindu.sct.model.sgen.GeneratorModel in project statecharts by Yakindu.

the class SGenJavaValidator method checkParameterValue.

@Check
public void checkParameterValue(final FeatureParameterValue value) {
    if (value.getExpression() == null || value.getExpression() == null)
        return;
    GeneratorModel model = (GeneratorModel) EcoreUtil2.getRootContainer(value);
    IGeneratorDescriptor generatorDescriptor = GeneratorExtensions.getGeneratorDescriptor(model.getGeneratorId());
    IDefaultFeatureValueProvider provider = LibraryExtensions.getDefaultFeatureValueProvider(generatorDescriptor.getLibraryIDs(), value.getParameter().getFeatureType().getLibrary());
    injector.injectMembers(provider);
    IStatus status = provider.validateParameterValue(value);
    createMarker(status);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IDefaultFeatureValueProvider(org.yakindu.sct.generator.core.library.IDefaultFeatureValueProvider) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) Check(org.eclipse.xtext.validation.Check)

Example 9 with GeneratorModel

use of org.yakindu.sct.model.sgen.GeneratorModel 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 10 with GeneratorModel

use of org.yakindu.sct.model.sgen.GeneratorModel in project statecharts by Yakindu.

the class EclipseContextGeneratorExecutorLookup method executeGenerator.

public void executeGenerator(IFile file) {
    final GeneratorModel model = GenModelLoader.load(file);
    Job generatorJob = new Job("Execute SCT Genmodel " + file.getName()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                execute(model);
            } catch (Exception ex) {
                return new Status(IStatus.ERROR, BuilderActivator.PLUGIN_ID, ex.getMessage(), ex);
            }
            return Status.OK_STATUS;
        }
    };
    generatorJob.setRule(file.getProject().getWorkspace().getRoot());
    generatorJob.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

GeneratorModel (org.yakindu.sct.model.sgen.GeneratorModel)28 EObject (org.eclipse.emf.ecore.EObject)13 AssertableDiagnostics (org.eclipse.xtext.junit4.validation.AssertableDiagnostics)11 Test (org.junit.Test)11 AbstractSGenTest (org.yakindu.sct.generator.genmodel.test.util.AbstractSGenTest)11 IGeneratorDescriptor (org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor)10 Resource (org.eclipse.emf.ecore.resource.Resource)6 ILibraryDescriptor (org.yakindu.sct.generator.core.extensions.ILibraryDescriptor)5 Check (org.eclipse.xtext.validation.Check)4 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 FeatureType (org.yakindu.sct.model.sgen.FeatureType)3 IResource (org.eclipse.core.resources.IResource)2 IPath (org.eclipse.core.runtime.IPath)2 IStatus (org.eclipse.core.runtime.IStatus)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)2 IDefaultFeatureValueProvider (org.yakindu.sct.generator.core.library.IDefaultFeatureValueProvider)2 FeatureTypeLibrary (org.yakindu.sct.model.sgen.FeatureTypeLibrary)2 PropertyDefinition (org.yakindu.sct.model.sgen.PropertyDefinition)2