use of org.kie.workbench.common.services.datamodeller.driver.model.DriverError in project kie-wb-common by kiegroup.
the class DataModelerServiceHelperTest method testToDataModelerErrorFromDriverError.
@Test
public void testToDataModelerErrorFromDriverError() {
ArrayList<DriverError> driverErrors = new ArrayList<>();
for (int i = 0; i < 10; i++) {
driverErrors.add(new DriverError(i, "message" + i, mock(Path.class), i, i));
}
List<DataModelerError> result = serviceHelper.toDataModelerError(driverErrors);
assertEquals(driverErrors.size(), result.size());
for (int i = 0; i < driverErrors.size(); i++) {
assertErrorEquals(driverErrors.get(i), result.get(i));
}
}
use of org.kie.workbench.common.services.datamodeller.driver.model.DriverError in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method resolveDefinitionRequest.
@Override
public AnnotationDefinitionResponse resolveDefinitionRequest(AnnotationDefinitionRequest definitionRequest, KieModule kieModule) {
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(kieModule);
ClassTypeResolver classTypeResolver = DriverUtils.createClassTypeResolver(classLoader);
AnnotationDefinitionResponse definitionResponse = new AnnotationDefinitionResponse();
try {
AnnotationDefinition annotationDefinition = modelDriver.buildAnnotationDefinition(definitionRequest.getClassName(), classTypeResolver);
definitionResponse.withAnnotationDefinition(annotationDefinition);
} catch (ModelDriverException e) {
DriverError driverError = new DriverError(e.getMessage());
definitionResponse.addError(driverError);
}
return definitionResponse;
}
use of org.kie.workbench.common.services.datamodeller.driver.model.DriverError in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method validateValuePair.
@Override
public List<ValidationMessage> validateValuePair(String annotationClassName, ElementType target, String valuePairName, String literalValue) {
// Currently we only validate the syntax but additional checks may be added.
List<ValidationMessage> validationMessages = new ArrayList<ValidationMessage>();
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
Pair<AnnotationSource<JavaClassSource>, List<DriverError>> parseResult = modelDriver.parseAnnotationWithValuePair(annotationClassName, target, valuePairName, literalValue);
if (parseResult.getK2() != null && parseResult.getK2().size() > 0) {
ValidationMessage validationMessage;
for (DriverError driverError : parseResult.getK2()) {
validationMessage = new ValidationMessage();
validationMessage.setText(driverError.getMessage());
validationMessage.setColumn(driverError.getColumn());
validationMessage.setLine(driverError.getLine());
validationMessage.setLevel(Level.ERROR);
validationMessages.add(validationMessage);
}
}
return validationMessages;
}
use of org.kie.workbench.common.services.datamodeller.driver.model.DriverError in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriver method addSyntaxErrors.
private void addSyntaxErrors(DriverResult result, Path file, List<SyntaxError> syntaxErrors) {
DriverError error;
for (SyntaxError syntaxError : syntaxErrors) {
error = new DriverError(syntaxError.getDescription(), Paths.convert(file));
error.setLine(syntaxError.getLine());
error.setColumn(syntaxError.getColumn());
result.addError(error);
}
}
use of org.kie.workbench.common.services.datamodeller.driver.model.DriverError in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriver method parseAnnotationWithValuePair.
public Pair<AnnotationSource<JavaClassSource>, List<DriverError>> parseAnnotationWithValuePair(String annotationClassName, ElementType target, String valuePairName, String literalValue) {
List<DriverError> syntaxErrors = new ArrayList<DriverError>();
String annotationStr = "@" + annotationClassName + "(" + valuePairName + "=" + literalValue + " )";
String stub;
AnnotationSource<JavaClassSource> annotation = null;
if (ElementType.TYPE.equals(target)) {
stub = annotationStr + " public class Stub { }";
} else {
stub = "public class Stub { " + annotationStr + " int dummy; }";
}
JavaClassSource temp = (JavaClassSource) Roaster.parse(JavaClass.class, stub);
if (temp.getSyntaxErrors() != null && temp.getSyntaxErrors().size() > 0) {
for (org.jboss.forge.roaster.model.SyntaxError syntaxError : temp.getSyntaxErrors()) {
syntaxErrors.add(new DriverError(syntaxError.getDescription(), syntaxError.getLine(), syntaxError.getColumn()));
}
} else if (ElementType.TYPE.equals(target)) {
annotation = temp.getAnnotation(annotationClassName);
} else {
annotation = temp.getField("dummy").getAnnotation(annotationClassName);
}
if (annotation == null) {
syntaxErrors.add(new DriverError("Annotation value pair could not be parsed."));
}
return new Pair<>(annotation, syntaxErrors);
}
Aggregations