Search in sources :

Example 1 with FileInputGeneratorWrapper

use of com.devonfw.cobigen.eclipse.generator.generic.FileInputGeneratorWrapper in project cobigen by devonfw.

the class GeneratorWrapperFactory method createGenerator.

/**
 * Creates a generator dependent on the input of the selection
 *
 * @param selection current {@link IStructuredSelection} treated as input for generation
 * @param monitor tracking progress
 * @return a specific {@link CobiGenWrapper} instance
 * @throws GeneratorCreationException if any exception occurred during converting the inputs or creating the generator
 * @throws GeneratorProjectNotExistentException if the generator configuration project does not exist
 * @throws InvalidInputException if the selection includes non supported input types or is composed in a non supported
 *         combination of inputs.
 */
public static CobiGenWrapper createGenerator(ISelection selection, IProgressMonitor monitor) throws GeneratorCreationException, GeneratorProjectNotExistentException, InvalidInputException {
    List<Object> extractedInputs = extractValidEclipseInputs(selection);
    if (extractedInputs.size() > 0) {
        monitor.subTask("Initialize CobiGen instance");
        CobiGen cobigen = initializeGenerator();
        monitor.subTask("Reading inputs...");
        monitor.worked(10);
        Object firstElement = extractedInputs.get(0);
        if (firstElement instanceof IJavaElement) {
            LOG.info("Create new CobiGen instance for java inputs...");
            return new JavaInputGeneratorWrapper(cobigen, ((IJavaElement) firstElement).getJavaProject().getProject(), JavaInputConverter.convertInput(extractedInputs, cobigen), monitor);
        } else if (firstElement instanceof IResource) {
            LOG.info("Create new CobiGen instance for file inputs...");
            return new FileInputGeneratorWrapper(cobigen, ((IResource) firstElement).getProject(), FileInputConverter.convertInput(cobigen, extractedInputs), monitor);
        }
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaInputGeneratorWrapper(com.devonfw.cobigen.eclipse.generator.java.JavaInputGeneratorWrapper) CobiGen(com.devonfw.cobigen.api.CobiGen) FileInputGeneratorWrapper(com.devonfw.cobigen.eclipse.generator.generic.FileInputGeneratorWrapper) IResource(org.eclipse.core.resources.IResource)

Aggregations

CobiGen (com.devonfw.cobigen.api.CobiGen)1 FileInputGeneratorWrapper (com.devonfw.cobigen.eclipse.generator.generic.FileInputGeneratorWrapper)1 JavaInputGeneratorWrapper (com.devonfw.cobigen.eclipse.generator.java.JavaInputGeneratorWrapper)1 IResource (org.eclipse.core.resources.IResource)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1