use of org.kie.workbench.common.services.refactoring.backend.server.indexing.PackageDescrIndexVisitor in project kie-wb-common by kiegroup.
the class AbstractDrlFileIndexer method fillDrlIndexBuilder.
/**
* All Drools-related {@link Indexer} implementations end up extracting the DRL from the related Rule representation
* (see {@link ResourceType}).
* </p>
* The following method then parses the DRL and returns all relevant reference information.
* @param path The {@link Path} of the asset/resource, necessary for extracting reference information.
* @param drl A {@link String} representation of the DRL.
* @return The {@link DefaultIndexBuilder}
* @throws Exception
*/
public DefaultIndexBuilder fillDrlIndexBuilder(final Path path, final String drl) throws Exception {
final DrlParser drlParser = new DrlParser();
final PackageDescr packageDescr = drlParser.parse(true, drl);
if (drlParser.hasErrors()) {
final List<DroolsError> errors = drlParser.getErrors();
logger.warn(ErrorMessageUtilities.makeErrorMessage(path, errors.toArray(new DroolsError[errors.size()])));
return null;
}
if (packageDescr == null) {
logger.warn(ErrorMessageUtilities.makeErrorMessage(path));
return null;
}
final ModuleDataModelOracle dmo = getModuleDataModelOracle(path);
// responsible for basic index info: project name, branch, etc
final DefaultIndexBuilder builder = getIndexBuilder(path);
if (builder == null) {
return null;
}
builder.setPackageName(packageDescr.getName());
// Retrieves info from the parsed syntac tree (PackageDescr)
final PackageDescrIndexVisitor visitor = new PackageDescrIndexVisitor(dmo, builder, packageDescr);
visitor.visit();
addReferencedResourcesToIndexBuilder(builder, visitor);
return builder;
}
use of org.kie.workbench.common.services.refactoring.backend.server.indexing.PackageDescrIndexVisitor in project kie-wb-common by kiegroup.
the class TestPackageNameDrlFileIndexer method toKObject.
@Override
public KObject toKObject(final Path path) {
KObject index = null;
try {
final String drl = ioService.readAllString(path);
final DrlParser drlParser = new DrlParser();
final PackageDescr packageDescr = drlParser.parse(true, drl);
if (drlParser.hasErrors()) {
final List<DroolsError> errors = drlParser.getErrors();
logger.warn(ErrorMessageUtilities.makeErrorMessage(path, errors.toArray(new DroolsError[errors.size()])));
return index;
}
if (packageDescr == null) {
logger.warn(ErrorMessageUtilities.makeErrorMessage(path));
return index;
}
final ModuleDataModelOracle dmo = getModuleDataModelOracle(path);
final Module module = moduleService.resolveModule(Paths.convert(path));
// This is the reason we're overriding toKObject and not using fillDrlIndextBuilder(..)
final Package pkg = mock(Package.class);
when(pkg.getPackageName()).thenReturn(packageDescr.getName());
final DefaultIndexBuilder builder = new DefaultIndexBuilder(Paths.convert(path).getFileName(), module, pkg);
final PackageDescrIndexVisitor visitor = new PackageDescrIndexVisitor(dmo, builder, packageDescr);
visitor.visit();
addReferencedResourcesToIndexBuilder(builder, visitor);
index = KObjectUtil.toKObject(path, IndexTerm.REFACTORING_CLASSIFIER, builder.build());
} catch (Exception e) {
logger.error("Unable to index '" + path.toUri().toString() + "'.", e);
}
return index;
}
Aggregations