Class EvaluatorImpl
- java.lang.Object
-
- org.pkl.core.EvaluatorImpl
-
-
Field Summary
Fields Modifier and Type Field Description protected StackFrameTransformerframeTransformerprotected BufferedLoggerloggerprotected ModuleResolvermoduleResolverprotected PackageResolverpackageResolverprotected org.graalvm.polyglot.ContextpolyglotContextprotected SecurityManagersecurityManagerprotected @Nullable java.time.Durationtimeoutprotected @Nullable java.util.concurrent.ScheduledExecutorServicetimeoutExecutor
-
Constructor Summary
Constructors Constructor Description EvaluatorImpl(StackFrameTransformer transformer, SecurityManager manager, Logger logger, java.util.Collection<ModuleKeyFactory> factories, java.util.Collection<ResourceReader> readers, java.util.Map<java.lang.String,java.lang.String> environmentVariables, java.util.Map<java.lang.String,java.lang.String> externalProperties, @Nullable java.time.Duration timeout, @Nullable java.nio.file.Path moduleCacheDir, @Nullable DeclaredDependencies projectDependencies, @Nullable java.lang.String outputFormat)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Releases all resources held by this evaluator.protected <T> TdoEvaluate(ModuleSource moduleSource, java.util.function.Function<VmTyped,T> doEvaluate)PModuleevaluate(ModuleSource moduleSource)Evaluates the module, returning the Java representation of the module object.java.lang.ObjectevaluateExpression(ModuleSource moduleSource, java.lang.String expression)Evaluates the Pkl expression represented asexpression, returning the Java representation of the result.java.lang.StringevaluateExpressionString(ModuleSource moduleSource, java.lang.String expression)Evaluates the Pkl expression, returning the stringified result.java.util.Map<java.lang.String,FileOutput>evaluateOutputFiles(ModuleSource moduleSource)Evaluates a module'soutput.filesproperty.java.lang.StringevaluateOutputText(ModuleSource moduleSource)Evaluates a module'soutput.textproperty.java.lang.ObjectevaluateOutputValue(ModuleSource moduleSource)Evaluates a module'soutput.valueproperty.<T> TevaluateOutputValueAs(ModuleSource moduleSource, PClassInfo<T> classInfo)Evaluates the module'soutput.valueproperty, and validates that its type matches the provided class info.ModuleSchemaevaluateSchema(ModuleSource moduleSource)Evalautes the module's schema, which describes the properties, methods, and classes of a module.TestResultsevaluateTest(ModuleSource moduleSource, boolean overwrite)Runs tests within the module, and returns the test results.
-
-
-
Field Detail
-
frameTransformer
protected final StackFrameTransformer frameTransformer
-
moduleResolver
protected final ModuleResolver moduleResolver
-
polyglotContext
protected final org.graalvm.polyglot.Context polyglotContext
-
timeout
protected final @Nullable java.time.Duration timeout
-
timeoutExecutor
protected final @Nullable java.util.concurrent.ScheduledExecutorService timeoutExecutor
-
securityManager
protected final SecurityManager securityManager
-
logger
protected final BufferedLogger logger
-
packageResolver
protected final PackageResolver packageResolver
-
-
Constructor Detail
-
EvaluatorImpl
public EvaluatorImpl(StackFrameTransformer transformer, SecurityManager manager, Logger logger, java.util.Collection<ModuleKeyFactory> factories, java.util.Collection<ResourceReader> readers, java.util.Map<java.lang.String,java.lang.String> environmentVariables, java.util.Map<java.lang.String,java.lang.String> externalProperties, @Nullable java.time.Duration timeout, @Nullable java.nio.file.Path moduleCacheDir, @Nullable DeclaredDependencies projectDependencies, @Nullable java.lang.String outputFormat)
-
-
Method Detail
-
evaluate
public PModule evaluate(ModuleSource moduleSource)
Description copied from interface:EvaluatorEvaluates the module, returning the Java representation of the module object.
-
evaluateOutputText
public java.lang.String evaluateOutputText(ModuleSource moduleSource)
Description copied from interface:EvaluatorEvaluates a module'soutput.textproperty.- Specified by:
evaluateOutputTextin interfaceEvaluator
-
evaluateOutputValue
public java.lang.Object evaluateOutputValue(ModuleSource moduleSource)
Description copied from interface:EvaluatorEvaluates a module'soutput.valueproperty.- Specified by:
evaluateOutputValuein interfaceEvaluator
-
evaluateOutputFiles
public java.util.Map<java.lang.String,FileOutput> evaluateOutputFiles(ModuleSource moduleSource)
Description copied from interface:EvaluatorEvaluates a module'soutput.filesproperty.- Specified by:
evaluateOutputFilesin interfaceEvaluator
-
evaluateExpression
public java.lang.Object evaluateExpression(ModuleSource moduleSource, java.lang.String expression)
Description copied from interface:EvaluatorEvaluates the Pkl expression represented asexpression, returning the Java representation of the result.The following table describes how Pkl types are represented in Java:
Pkl type Java type Null PNullString StringBoolean BooleanInt LongFloat DoubleTyped, Dynamic PObject(PModuleif the object is a module)Mapping, Map MapListing, List ListSet SetPair PairRegex PatternDataSize DataSizeDuration DurationClass PClassTypeAlias TypeAliasThe following Pkl types have no Java representation, and an error is thrown if an expression computes to a value of these types:
- IntSeq
- Function
- Specified by:
evaluateExpressionin interfaceEvaluator
-
evaluateExpressionString
public java.lang.String evaluateExpressionString(ModuleSource moduleSource, java.lang.String expression)
Description copied from interface:EvaluatorEvaluates the Pkl expression, returning the stringified result.This is equivalent to wrapping the expression with
.toString()- Specified by:
evaluateExpressionStringin interfaceEvaluator
-
evaluateSchema
public ModuleSchema evaluateSchema(ModuleSource moduleSource)
Description copied from interface:EvaluatorEvalautes the module's schema, which describes the properties, methods, and classes of a module.- Specified by:
evaluateSchemain interfaceEvaluator
-
evaluateTest
public TestResults evaluateTest(ModuleSource moduleSource, boolean overwrite)
Description copied from interface:EvaluatorRuns tests within the module, and returns the test results.This requires that the target module be a test module; it must either amend or extend module
"pkl:test". Otherwise, a type mismatch error is thrown.This method will write possibly
pcf-expected.pklandpcf-actual.pcffiles as a sibling of the test module. Theoverwriteparameter causes the evaluator to overwritepcf-expected.pklfiles if they currently exist.- Specified by:
evaluateTestin interfaceEvaluator
-
evaluateOutputValueAs
public <T> T evaluateOutputValueAs(ModuleSource moduleSource, PClassInfo<T> classInfo)
Description copied from interface:EvaluatorEvaluates the module'soutput.valueproperty, and validates that its type matches the provided class info.- Specified by:
evaluateOutputValueAsin interfaceEvaluator
-
close
public void close()
Description copied from interface:EvaluatorReleases all resources held by this evaluator. If anevaluatemethod is currently executing, this method blocks until cancellation of that execution has completed.Once an evaluator has been closed, it can no longer be used, and calling
evaluatemethods will throwIllegalStateException. However, objects previously returned byevaluatemethods remain valid.
-
doEvaluate
protected <T> T doEvaluate(ModuleSource moduleSource, java.util.function.Function<VmTyped,T> doEvaluate)
-
-