org.jboss.forge.addon.parser.java.resources.JavaResource Java Examples

The following examples show how to use org.jboss.forge.addon.parser.java.resources.JavaResource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PackageNameCompleter.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public PackageNameCompleter(JavaSourceFacet facet) {
    // find package names in the source code
    facet.visitJavaSources(new JavaResourceVisitor() {
        @Override
        public void visit(VisitContext context, JavaResource javaResource) {
            try {
                // avoid package-info.java files
                if (!javaResource.getName().contains("package-info")) {
                    JavaClass clazz = javaResource.getJavaType();
                    String packageName = clazz.getPackage();
                    if (packageName != null && !packageNames.contains(packageName)) {
                        packageNames.add(packageName);
                    }
                }
            } catch (FileNotFoundException e) {
                // ignore
            }
        }
    });
}
 
Example #2
Source File: TestPackageNameCompleter.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public TestPackageNameCompleter(JavaSourceFacet facet) {
    // find package names in the source code
    facet.visitJavaTestSources(new JavaResourceVisitor() {
        @Override
        public void visit(VisitContext context, JavaResource javaResource) {
            try {
                // avoid package-info.java files
                if (!javaResource.getName().contains("package-info")) {
                    JavaClass clazz = javaResource.getJavaType();
                    String packageName = clazz.getPackage();
                    if (packageName != null && !packageNames.contains(packageName)) {
                        packageNames.add(packageName);
                    }
                }
            } catch (FileNotFoundException e) {
                // ignore
            }
        }
    });
}
 
Example #3
Source File: RouteBuilderCamelEndpointsVisitor.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(VisitContext visitContext, JavaResource resource) {
    try {
        // avoid package-info.java files
        if (!resource.getName().contains("package-info")) {
            JavaClassSource clazz = resource.getJavaType();
            String fqn = resource.getFullyQualifiedName();
            String name = clazz.getQualifiedName();
            String baseDir = facet.getSourceDirectory().getFullyQualifiedName();

            boolean include = true;
            if (filter != null) {
                Boolean out = filter.apply(name);
                LOG.info("Filter " + name + " -> " + out);
                include = out == null || out;
            }

            if (include) {
                RouteBuilderParser.parseRouteBuilderEndpoints(clazz, baseDir, fqn, endpoints);
            }
        }
    } catch (Throwable e) {
        // ignore
    }
}
 
Example #4
Source File: RouteBuilderCompleter.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public RouteBuilderCompleter(JavaSourceFacet facet) {
    // find package names in the source code
    facet.visitJavaSources(new JavaResourceVisitor() {
        @Override
        public void visit(VisitContext context, JavaResource javaResource) {
            try {
                // avoid package-info.java files
                if (!javaResource.getName().contains("package-info")) {
                    JavaClass clazz = javaResource.getJavaType();
                    String superType = clazz.getSuperType();
                    if (superType != null && isRouteBuilder(superType)) {
                        routeBuilders.add(clazz.getQualifiedName());
                        packages.add(clazz.getPackage());
                    }
                }
            } catch (FileNotFoundException e) {
                // ignore
            }
        }
    });
}
 
Example #5
Source File: ResourcePathVisitor.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void visit(VisitContext context, JavaResource javaResource)
{
   if (!found)
   {
      try
      {
         JavaSource<?> javaSource = javaResource.getJavaType();
         if (javaSource instanceof JavaClass)
         {
            JavaClass<?> javaClass = (JavaClass<?>) javaSource;
            if (javaClass.getName().equals(entityName + "Endpoint") && javaClass.hasAnnotation(Path.class))
            {
               this.path = javaClass.getAnnotation(Path.class).getStringValue();
               found = true;
            }
         }
      }
      catch (FileNotFoundException e)
      {
         throw new RuntimeException(e);
      }
   }
}
 
Example #6
Source File: RestResourceTypeVisitor.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void visit(VisitContext context, JavaResource javaResource)
{
   if (!found)
   {
      try
      {
         JavaSource<?> javaType = javaResource.getJavaType();
         if (javaType.getAnnotation("javax.ws.rs.Path") != null)
         {
            String path = javaType.getAnnotation("javax.ws.rs.Path")
                     .getStringValue();
            String absolutePath = path.endsWith("/") ? path.substring(0, path.lastIndexOf('/')) : path;
            if (absolutePath.equals(proposedPath))
            {
               javaSource = javaType;
               found = true;
            }
         }
      }
      catch (FileNotFoundException e)
      {
         throw new RuntimeException(e);
      }
   }
}
 
Example #7
Source File: InspectionResultProcessorTest.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
private void generateManyToManyField(String fieldName, String type, String inverseFieldName, FetchType fetchType,
         Iterable<CascadeType> cascadeTypes) throws Exception
{
   JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
   JavaResource entityClassResource = java.getJavaResource(entityClass);
   projectHelper.createManyToManyField(project, entityClassResource, fieldName, type, inverseFieldName, fetchType,
            cascadeTypes);
   entityClass = getJavaClassFor(entityClass.getName());
}
 
Example #8
Source File: InspectionResultProcessorTest.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
private void generateOneToManyField(String fieldName, String type, String inverseFieldName, FetchType fetchType,
         Iterable<CascadeType> cascadeTypes) throws Exception
{
   JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
   JavaResource entityClassResource = java.getJavaResource(entityClass);
   projectHelper.createOneToManyField(project, entityClassResource, fieldName, type, inverseFieldName, fetchType,
            cascadeTypes);
   entityClass = getJavaClassFor(entityClass.getName());
}
 
Example #9
Source File: InspectionResultProcessorTest.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
private void generateManyToOneField(String fieldName, String type, String inverseFieldName, FetchType fetchType,
         boolean required, Iterable<CascadeType> cascadeTypes) throws Exception
{
   JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
   JavaResource entityClassResource = java.getJavaResource(entityClass);
   projectHelper.createManyToOneField(project, entityClassResource, fieldName, type, inverseFieldName, fetchType,
            required, cascadeTypes);
   entityClass = getJavaClassFor(entityClass.getName());
}
 
Example #10
Source File: InspectionResultProcessorTest.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
private void generateOneToOneField(String fieldName, String type, String inverseFieldName, FetchType fetchType,
         boolean required, Iterable<CascadeType> cascadeTypes) throws Exception
{
   JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
   JavaResource entityClassResource = java.getJavaResource(entityClass);
   projectHelper.createOneToOneField(project, entityClassResource, fieldName, type, inverseFieldName, fetchType,
            required, cascadeTypes);
   entityClass = getJavaClassFor(entityClass.getName());
}
 
Example #11
Source File: ProjectHelper.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
public void createManyToManyField(Project project, JavaResource javaResource, String fieldName,
         String type, String inverseFieldName, FetchType fetchType,
         Iterable<CascadeType> cascadeTypes) throws FileNotFoundException
{
   jpaFieldOperations.newManyToManyRelationship(project, javaResource, fieldName, type, inverseFieldName, fetchType,
            cascadeTypes);
}
 
Example #12
Source File: ProjectHelper.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
public void createOneToManyField(Project project, JavaResource javaResource, String fieldName,
         String type, String inverseFieldName, FetchType fetchType,
         Iterable<CascadeType> cascadeTypes) throws FileNotFoundException
{
   jpaFieldOperations.newOneToManyRelationship(project, javaResource, fieldName, type, inverseFieldName, fetchType,
            cascadeTypes);
}
 
Example #13
Source File: ProjectHelper.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
public void createManyToOneField(Project project, JavaResource javaResource, String fieldName,
         String type, String inverseFieldName, FetchType fetchType, boolean required,
         Iterable<CascadeType> cascadeTypes) throws FileNotFoundException
{
   jpaFieldOperations.newManyToOneRelationship(project, javaResource, fieldName, type, inverseFieldName, fetchType,
            required, cascadeTypes);
}
 
Example #14
Source File: ProjectHelper.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
public void createOneToOneField(Project project, JavaResource javaResource, String fieldName,
         String type, String inverseFieldName, FetchType fetchType, boolean required,
         Iterable<CascadeType> cascadeTypes) throws FileNotFoundException
{
   jpaFieldOperations.newOneToOneRelationship(project, javaResource, fieldName, type, inverseFieldName, fetchType,
            required, cascadeTypes);
}
 
Example #15
Source File: InspectionResultProcessor.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
private JavaClassSource getJavaClass(String qualifiedType)
{
   JavaSourceFacet java = this.project.getFacet(JavaSourceFacet.class);
   try
   {
      JavaResource resource = java.getJavaResource(qualifiedType);
      JavaClassSource javaClass = resource.getJavaType();
      return javaClass;
   }
   catch (FileNotFoundException fileEx)
   {
      throw new RuntimeException(fileEx);
   }
}
 
Example #16
Source File: ConfigureEndpointPropertiesStep.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected Result addEndpointJava(Project project, JavaSourceFacet facet, JavaResource file, String uri,
                                 String endpointInstanceName, String routeBuilder, String cursorPosition) throws Exception {

    JavaClassSource clazz = file.getJavaType();

    // we do not want to change the current code formatting so we need to search
    // replace the unformatted class source code
    StringBuilder sb = new StringBuilder(clazz.toUnformattedString());

    int pos = Integer.valueOf(cursorPosition);

    // move to end if pos is after the content
    pos = Math.min(sb.length(), pos);

    LOG.info("Adding endpoint at pos: " + pos + " in file: " + routeBuilder);

    // check if prev and next is a quote and if not then add it automatic
    int prev = pos - 1;
    int next = pos + 1;
    char ch = sb.charAt(prev);
    char ch2 = next < sb.length() ? sb.charAt(next) : ' ';
    if (ch != '"' && ch2 != '"') {
        uri = "\"" + uri + "\"";
    }

    // insert uri at position
    sb.insert(pos, uri);

    // use this code currently to save content unformatted
    file.setContents(sb.toString());

    return Results.success("Added endpoint " + uri + " in " + routeBuilder);
}
 
Example #17
Source File: ProjectHelper.java    From angularjs-addon with Eclipse Public License 1.0 4 votes vote down vote up
public JavaResource createJPAEntity(Project project, String entityName) throws IOException
{
   String packageName = project.getFacet(JavaSourceFacet.class).getBasePackage() + ".model";
   return persistenceOperations.newEntity(project, entityName, packageName, GenerationType.AUTO);
}
 
Example #18
Source File: AngularScaffoldProvider.java    From angularjs-addon with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public List<Resource<?>> generateFrom(ScaffoldGenerationContext generationContext)
{
   setProject(generationContext.getProject());
   String targetDir = generationContext.getTargetDirectory();
   targetDir = (targetDir == null) ? "" : targetDir;
   List<Resource<?>> result = new ArrayList<>();
   Collection<Resource<?>> resources = generationContext.getResources();
   for (Resource<?> resource : resources)
   {
      JavaSource<?> javaSource = null;
      if (resource instanceof JavaResource)
      {
         JavaResource javaResource = (JavaResource) resource;
         try
         {
            javaSource = javaResource.getJavaType();
         }
         catch (FileNotFoundException fileEx)
         {
            throw new IllegalStateException(fileEx);
         }
      }
      else
      {
         continue;
      }

      JavaClassSource entity = (JavaClassSource) javaSource;
      String resourceRootPath = getRootResourcePath(project);
      // Fetch the REST resource path from the existing JAX-RS resource if found.
      String entityResourcePath = parseResourcePath(entity);
      // If the path is not available, construct a default one from the JPA entity name
      // We'll let the user resolve the incorrect path later,
      // if needed through regeneration of the JAX-RS resources.
      String entityName = entity.getName();
      if (entityResourcePath == null || entityResourcePath.isEmpty())
      {
         entityResourcePath = inflector.pluralize(entityName.toLowerCase());
      }
      entityResourcePath = trimSlashes(entityResourcePath);

      // Inspect the JPA entity and obtain a list of inspection results. Every inspected property is represented as a
      // Map<String,String> and all such inspection results are collated into a list.
      MetawidgetInspectorFacade metawidgetInspectorFacade = new MetawidgetInspectorFacade(project);
      InspectionResultProcessor angularResultEnhancer = new InspectionResultProcessor(project,
               metawidgetInspectorFacade);
      List<Map<String, String>> inspectionResults = metawidgetInspectorFacade.inspect(entity);
      String entityId = angularResultEnhancer.fetchEntityId(entity, inspectionResults);
      inspectionResults = angularResultEnhancer.enhanceResults(entity, inspectionResults);

      MetadataFacet metadata = project.getFacet(MetadataFacet.class);

      // TODO: Provide a 'utility' class for allowing transliteration across language naming schemes
      // We need this to use contextual naming schemes instead of performing toLowerCase etc. in FTLs.

      // Prepare the Freemarker data model
      Map<String, Object> dataModel = new HashMap<>();
      dataModel.put("entityName", entityName);
      dataModel.put("pluralizedEntityName", inflector.pluralize(entityName));
      dataModel.put("entityId", entityId);
      dataModel.put("properties", inspectionResults);
      dataModel.put("projectId", StringUtils.camelCase(metadata.getProjectName()));
      dataModel.put("projectTitle", StringUtils.uncamelCase(metadata.getProjectName()));
      dataModel.put("resourceRootPath", resourceRootPath);
      dataModel.put("resourcePath", entityResourcePath);
      dataModel.put("parentDirectories", getParentDirectories(targetDir));

      // Process the Freemarker templates with the Freemarker data model and retrieve the generated resources from
      // the registry.
      WebResourcesFacet web = project.getFacet(WebResourcesFacet.class);
      ProcessingStrategy strategy = new ProcessTemplateStrategy(web, resourceFactory, project, templateFactory,
               dataModel);
      List<ScaffoldResource> scaffoldResources = getEntityTemplates(targetDir, entityName, strategy);
      scaffoldResources.add(new ScaffoldResource("/views/detail.html.ftl", targetDir + "/views/" + entityName
               + "/detail.html",
               new DetailTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel)));
      scaffoldResources.add(new ScaffoldResource("/views/search.html.ftl", targetDir + "/views/" + entityName
               + "/search.html",
               new SearchTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel)));
      for (ScaffoldResource scaffoldResource : scaffoldResources)
      {
         result.add(scaffoldResource.generate());
      }
   }

   List<Resource<?>> indexResources = generateIndex(targetDir);
   result.addAll(indexResources);
   return result;
}
 
Example #19
Source File: CreateTestClassCommandTest.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void should_set_archivetype_test() throws Exception
{
   assertThat(project.hasFacet(ThorntailFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");
      controller.setValueFor("archiveType", "WAR");

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }

   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));

   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   final String testable = defaultDeployment.getLiteralValue("type");
   assertThat(testable, is("DefaultDeployment.Type.WAR"));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
Example #20
Source File: CreateTestClassCommandTest.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void should_create_asclient_test() throws Exception
{
   assertThat(project.hasFacet(ThorntailFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");
      controller.setValueFor("asClient", true);

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }

   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));

   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   final String testable = defaultDeployment.getLiteralValue("testable");
   assertThat(testable, is("false"));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
Example #21
Source File: InspectionResultProcessorTest.java    From angularjs-addon with Eclipse Public License 1.0 4 votes vote down vote up
private void generateSimpleEntity(String entityName) throws Exception
{
   JavaResource jpaEntity = projectHelper.createJPAEntity(project, entityName);
   entityClass = jpaEntity.getJavaType();
   saveJavaSource();
}
 
Example #22
Source File: CreateTestClassCommandTest.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void should_create_incontainer_test() throws Exception
{
   assertThat(project.hasFacet(ThorntailFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }
   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));
   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   assertThat(defaultDeployment.getValues().size(), is(0));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
Example #23
Source File: ClassScanner.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
protected SortedSet<String> findClassNames(Map<Package, ClassLoader[]> packages, Predicate<String> filter, Integer limit) {
        SortedSet<String> answer = new TreeSet<String>();
        SortedSet<String> classes = new TreeSet<String>();

        Set<Map.Entry<Package, ClassLoader[]>> entries = packages.entrySet();
        for (Map.Entry<Package, ClassLoader[]> entry : entries) {
            Package aPackage = entry.getKey();
            ClassLoader[] classLoaders = entry.getValue();
            CacheValue cacheValue = packageCache.get(aPackage);
            if (cacheValue == null) {
                cacheValue = createPackageCacheValue(aPackage, classLoaders);
                packageCache.put(aPackage, cacheValue);
            }
            classes.addAll(cacheValue.getClassNames());
        }
	      if (this.project != null) {
		      JavaSourceFacet sourceFacet = project.getFacet(JavaSourceFacet.class);
		      sourceFacet.visitJavaSources(new JavaResourceVisitor() {
			      @Override
			      public void visit(VisitContext visitContext, JavaResource javaResource) {
				      classes.add(javaResource.getFullyQualifiedTypeName());
			      }
		      });
	      }
/*
        for (Map.Entry<String, ClassResource> entry : entries) {
            String key = entry.getKey();
            ClassResource classResource = entry.getValue();
            CacheValue cacheValue = cache.get(key);
            if (cacheValue == null) {
                cacheValue = createCacheValue(key, classResource);
                cache.put(key, cacheValue);
            }
            classes.addAll(cacheValue.getClassNames());
            //addClassesForPackage(classResource, search, limit, classes);
        }
*/
        if (withinLimit(limit, answer)) {
            for (String aClass : classes) {
                if (filter.evaluate(aClass)) {
                    answer.add(aClass);
                    if (!withinLimit(limit, answer)) {
                        break;
                    }
                }
            }
        }
        return answer;
    }
 
Example #24
Source File: CamelNewRouteBuilderCommand.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    Project project = getSelectedProject(context);
    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);

    // does the project already have camel?
    Dependency core = findCamelCoreDependency(project);
    if (core == null) {
        return Results.fail("The project does not include camel-core");
    }

    // do we already have a class with the name
    String fqn = targetPackage.getValue() != null ? targetPackage.getValue() + "." + name.getValue() : name.getValue();

    JavaResource existing = facet.getJavaResource(fqn);
    if (existing != null && existing.exists()) {
        return Results.fail("A class with name " + fqn + " already exists");
    }

    // need to parse to be able to extends another class
    final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
    javaClass.setName(name.getValue());
    if (targetPackage.getValue() != null) {
        javaClass.setPackage(targetPackage.getValue());
    }
    javaClass.setSuperType("RouteBuilder");
    javaClass.addImport("org.apache.camel.builder.RouteBuilder");

    boolean cdi = CamelCommandsHelper.isCdiProject(getSelectedProject(context));
    boolean spring = CamelCommandsHelper.isSpringProject(getSelectedProject(context));

    if (cdi) {
        javaClass.addAnnotation("javax.inject.Singleton");
    } else if (spring) {
        javaClass.addAnnotation("org.springframework.stereotype.Component");
    }

    javaClass.addMethod()
            .setPublic()
            .setReturnTypeVoid()
            .setName("configure")
            .addThrows(Exception.class).setBody("");

    JavaResource javaResource = facet.saveJavaSource(javaClass);

    // if we are in an GUI editor then open the file
    if (isRunningInGui(context.getUIContext())) {
        context.getUIContext().setSelection(javaResource);
    }

    return Results.success("Created new RouteBuilder class " + name.getValue());
}