Java Code Examples for org.jboss.forge.roaster.model.source.JavaClassSource#getName()

The following examples show how to use org.jboss.forge.roaster.model.source.JavaClassSource#getName() . 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: CodeGeneratorOld.java    From Entitas-Java with MIT License 6 votes vote down vote up
public static void toFile(JavaClassSource javaClass, File srcFolder) {
    File f = srcFolder;
    String[] parts = javaClass.getPackage().split("\\.");

    try {
        if (!srcFolder.getAbsolutePath().endsWith(parts[parts.length - 1])) {
            f = new File(f, parts[parts.length - 1]);
            createParentDirs(f);
        }
        f = new File(f, javaClass.getName() + ".java");
        write(f, javaClass.toString());

    } catch (IOException e) {
        e.printStackTrace();
    }

}
 
Example 2
Source File: CodeGeneratorOld.java    From Entitas-Java with MIT License 6 votes vote down vote up
public static void toFile(JavaClassSource javaClass, File srcFolder) {
    File f = srcFolder;
    String[] parts = javaClass.getPackage().split("\\.");

    try {
        if (!srcFolder.getAbsolutePath().endsWith(parts[parts.length - 1])) {
            f = new File(f, parts[parts.length - 1]);
            createParentDirs(f);
        }
        f = new File(f, javaClass.getName() + ".java");
        write(f, javaClass.toString());

    } catch (IOException e) {
        e.printStackTrace();
    }

}
 
Example 3
Source File: AngularScaffoldProvider.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
private String parseResourcePath(JavaClassSource klass)
{
   JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
   ResourcePathVisitor visitor = new ResourcePathVisitor(klass.getName());
   java.visitJavaSources(visitor);
   return visitor.getPath();
}
 
Example 4
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;
}