Package dev.cel.common
Class CelSource
- java.lang.Object
-
- dev.cel.common.CelSource
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CelSource.Builder
Builder forCelSource
.static class
CelSource.Extension
Tag for an extension that were used while parsing or type checking the source expression.
-
Constructor Summary
Constructors Constructor Description CelSource()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CelCodePointArray
getContent()
Gets the original textual content of this source, represented in an array of code points.java.lang.String
getDescription()
Gets the description of this source that may optionally be set (example: location of the file containing the source).com.google.common.collect.ImmutableSet<CelSource.Extension>
getExtensions()
com.google.common.collect.ImmutableList<java.lang.Integer>
getLineOffsets()
Get the code point offsets (NOT code unit offsets) for new line characters '\n' within the source expression text.java.util.Optional<java.lang.Integer>
getLocationOffset(int line, int column)
Get the code point offset within the source expression text that corresponds with theline
andcolumn
.java.util.Optional<java.lang.Integer>
getLocationOffset(CelSourceLocation location)
com.google.common.collect.ImmutableMap<java.lang.Long,CelExpr>
getMacroCalls()
java.util.Optional<CelSourceLocation>
getOffsetLocation(int offset)
Get the line and column in the source expression text for the given code pointoffset
.com.google.common.collect.ImmutableMap<java.lang.Long,java.lang.Integer>
getPositionsMap()
Gets the map of each parsed node ID (ex: expression ID, policy ID) to their source positions.java.util.Optional<java.lang.String>
getSnippet(int line)
Get the text from the source text that corresponds toline
.static CelSource.Builder
newBuilder()
static CelSource.Builder
newBuilder(CelCodePointArray codePointArray)
static CelSource.Builder
newBuilder(java.lang.String text)
CelSource.Builder
toBuilder()
-
-
-
Method Detail
-
getContent
public CelCodePointArray getContent()
Description copied from interface:Source
Gets the original textual content of this source, represented in an array of code points.- Specified by:
getContent
in interfaceSource
-
getDescription
public java.lang.String getDescription()
Description copied from interface:Source
Gets the description of this source that may optionally be set (example: location of the file containing the source).- Specified by:
getDescription
in interfaceSource
-
getPositionsMap
public com.google.common.collect.ImmutableMap<java.lang.Long,java.lang.Integer> getPositionsMap()
Description copied from interface:Source
Gets the map of each parsed node ID (ex: expression ID, policy ID) to their source positions.- Specified by:
getPositionsMap
in interfaceSource
-
getLineOffsets
public com.google.common.collect.ImmutableList<java.lang.Integer> getLineOffsets()
Get the code point offsets (NOT code unit offsets) for new line characters '\n' within the source expression text.NOTE: The indices point to the index just after the '\n' not the index of '\n' itself.
-
getMacroCalls
public com.google.common.collect.ImmutableMap<java.lang.Long,CelExpr> getMacroCalls()
-
getExtensions
public com.google.common.collect.ImmutableSet<CelSource.Extension> getExtensions()
-
getLocationOffset
public java.util.Optional<java.lang.Integer> getLocationOffset(CelSourceLocation location)
-
getLocationOffset
public java.util.Optional<java.lang.Integer> getLocationOffset(int line, int column)
Get the code point offset within the source expression text that corresponds with theline
andcolumn
.- Parameters:
line
- the line number starting from 1column
- the column number starting from 0
-
getOffsetLocation
public java.util.Optional<CelSourceLocation> getOffsetLocation(int offset)
Get the line and column in the source expression text for the given code pointoffset
.
-
getSnippet
public java.util.Optional<java.lang.String> getSnippet(int line)
Description copied from interface:Source
Get the text from the source text that corresponds toline
. Snippets are split based on the newline ('\n').- Specified by:
getSnippet
in interfaceSource
- Parameters:
line
- the line number starting from 1.
-
toBuilder
public CelSource.Builder toBuilder()
-
newBuilder
public static CelSource.Builder newBuilder()
-
newBuilder
public static CelSource.Builder newBuilder(java.lang.String text)
-
newBuilder
public static CelSource.Builder newBuilder(CelCodePointArray codePointArray)
-
-