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