Search in sources :

Example 1 with SyntaxError

use of org.jboss.forge.roaster.model.SyntaxError 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);
}
Also used : JavaClass(org.jboss.forge.roaster.model.JavaClass) ArrayList(java.util.ArrayList) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) SyntaxError(org.jboss.forge.roaster.model.SyntaxError) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError) Pair(org.uberfire.commons.data.Pair)

Example 2 with SyntaxError

use of org.jboss.forge.roaster.model.SyntaxError 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);
    }
}
Also used : SyntaxError(org.jboss.forge.roaster.model.SyntaxError) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Example 3 with SyntaxError

use of org.jboss.forge.roaster.model.SyntaxError in project kie-wb-common by kiegroup.

the class DataModelerServiceHelper method toDataModelerError.

public List<DataModelerError> toDataModelerError(List<SyntaxError> syntaxErrors, Path file) {
    List<DataModelerError> errors = new ArrayList<DataModelerError>();
    DataModelerError error;
    for (SyntaxError syntaxError : syntaxErrors) {
        error = new DataModelerError(syntaxError.getDescription(), syntaxError.isError() ? Level.ERROR : Level.WARNING, Paths.convert(file));
        error.setColumn(syntaxError.getColumn());
        error.setLine(syntaxError.getLine());
        errors.add(error);
    }
    return errors;
}
Also used : DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) SyntaxError(org.jboss.forge.roaster.model.SyntaxError) ArrayList(java.util.ArrayList)

Aggregations

SyntaxError (org.jboss.forge.roaster.model.SyntaxError)3 ArrayList (java.util.ArrayList)2 DriverError (org.kie.workbench.common.services.datamodeller.driver.model.DriverError)2 JavaClass (org.jboss.forge.roaster.model.JavaClass)1 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)1 DataModelerError (org.kie.workbench.common.screens.datamodeller.model.DataModelerError)1 Pair (org.uberfire.commons.data.Pair)1