Search in sources :

Example 1 with ScriptPath

use of ratpack.groovy.script.internal.ScriptPath in project ratpack by ratpack.

the class ClosureUtil method getSourceInfo.

public static SourceInfo getSourceInfo(Closure<?> closure) {
    Class<?> closureClass = closure.getClass();
    LineNumber lineNumber = closureClass.getAnnotation(LineNumber.class);
    if (lineNumber == null) {
        return null;
    }
    Class<?> rootClass = getRootClass(closure);
    ScriptPath scriptPath = rootClass.getAnnotation(ScriptPath.class);
    if (scriptPath == null) {
        return null;
    }
    return new SourceInfo(scriptPath.value(), lineNumber.value());
}
Also used : ScriptPath(ratpack.groovy.script.internal.ScriptPath) LineNumber(ratpack.groovy.script.internal.LineNumber)

Example 2 with ScriptPath

use of ratpack.groovy.script.internal.ScriptPath in project ratpack by ratpack.

the class ClosureUtil method findScriptByAnnotation.

private static Path findScriptByAnnotation(Closure<?> closure) {
    Class<?> rootClass = getRootClass(closure);
    ScriptPath annotation = rootClass.getAnnotation(ScriptPath.class);
    if (annotation == null) {
        return null;
    } else {
        String scriptPath = annotation.value();
        URI uri;
        try {
            uri = new URI(scriptPath);
        } catch (URISyntaxException e) {
            return null;
        }
        return Paths.get(uri);
    }
}
Also used : ScriptPath(ratpack.groovy.script.internal.ScriptPath) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

ScriptPath (ratpack.groovy.script.internal.ScriptPath)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 LineNumber (ratpack.groovy.script.internal.LineNumber)1