Java Code Examples for org.jboss.forge.addon.parser.java.facets.JavaSourceFacet#visitJavaSources()

The following examples show how to use org.jboss.forge.addon.parser.java.facets.JavaSourceFacet#visitJavaSources() . 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: 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 3
Source File: RouteBuilderEndpointsCompleter.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public RouteBuilderEndpointsCompleter(final JavaSourceFacet facet, Function<String, Boolean> filter) {
    // find package names in the source code
    if (facet != null) {
        JavaResourceVisitor visitor = new RouteBuilderCamelEndpointsVisitor(facet, endpoints, filter);
        facet.visitJavaSources(visitor);
    }
}
 
Example 4
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 5
Source File: ScaffoldableEntitySelectionWizard.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void validate(UIValidationContext context)
{
   // Verify if the selected JPA entities have corresponding JAX-RS resources.
   // If yes, then raise warnings if they will be overwritten
   Boolean shouldGenerateRestResources = generateRestResources.getValue();
   List<String> entitiesWithRestResources = new ArrayList<>();
   if (shouldGenerateRestResources.equals(Boolean.TRUE) && targets.getValue() != null)
   {
      for (JavaClassSource klass : targets.getValue())
      {
         Project project = getSelectedProject(context.getUIContext());
         JavaSourceFacet javaSource = project.getFacet(JavaSourceFacet.class);
         RestResourceTypeVisitor restTypeVisitor = new RestResourceTypeVisitor();
         String entityTable = getEntityTable(klass);
         String proposedResourcePath = "/" + inflector.pluralize(entityTable.toLowerCase());
         restTypeVisitor.setProposedPath(proposedResourcePath);
         javaSource.visitJavaSources(restTypeVisitor);
         if (restTypeVisitor.isFound())
         {
            entitiesWithRestResources.add(klass.getQualifiedName());
         }
      }
   }
   if (!entitiesWithRestResources.isEmpty())
   {
      context.addValidationWarning(targets, "Some of the selected entities " + entitiesWithRestResources.toString()
               + " already have associated REST resources that will be overwritten.");
   }
}
 
Example 6
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;
    }