class JavaFileIndexer extends AbstractFileIndexer {

    @Override
    public IndexBuilder fillIndexBuilder(final Path path) throws Exception {
        if (!ioService.exists(path)) {
            logger.error("Unable to index {} : file does not exist.", path.toUri());
            return null;
        }

        // create indexbuilder
        final KieModule module = getModule(path);

        if (module == null) {
            logger.error("Unable to index " + path.toUri().toString() + ": module could not be resolved.");
            return null;
        }

        final Package pkg = getPackage(path);
        if (pkg == null) {
            logger.error("Unable to index " + path.toUri().toString() + ": package could not be resolved.");
            return null;
        }

        // responsible for basic index info: module name, branch, etc
        final DefaultIndexBuilder builder = new DefaultIndexBuilder(Paths.convert(path).getFileName(),
                                                                    module,
                                                                    pkg);

        // visit/index java source
        final String javaSource = ioService.readAllString(path);
        org.jboss.forge.roaster.model.JavaType<?> javaType = Roaster.parse(javaSource);
        if (javaType.getSyntaxErrors() == null || javaType.getSyntaxErrors().isEmpty()) {

            if (javaFileIndexerExtensions != null) {
                for (JavaFileIndexerExtension javaFileIndexerExtension : javaFileIndexerExtensions) {
                    javaFileIndexerExtension.process(builder,
                                                     javaType);
                }
            }

            String pkgName = pkg.getPackageName();
            pkgName = javaType.getPackage();
            if (pkgName == null) {
                pkgName = "";
            }
            // use Java class package name, not Package name
            builder.setPackageName(pkgName);

            String javaTypeName = javaType.getQualifiedName();
            Resource resParts = new Resource(javaTypeName,
                                             ResourceType.JAVA);

            if (javaType instanceof JavaSource) {
                ClassLoader moduleClassLoader = getModuleClassLoader(module);
                JavaSourceVisitor visitor = new JavaSourceVisitor((JavaSource) javaType,
                                                                  moduleClassLoader,
                                                                  resParts);
                visitor.visit((JavaSource) javaType);
                addReferencedResourcesToIndexBuilder(builder,
                                                     visitor);
            }

            builder.addGenerator(resParts);
        }

        return builder;
    }

}