lingua-franca 0.10.1
Lingua Franca code generator
Loading...
Searching...
No Matches
org.lflang.ast.MalleableString Class Referenceabstract

A MalleableString is an object with multiple valid textual representations. More...

Classes

class  Builder
 Build a MalleableString in a manner analogous to the way we build Strings. More...
class  Joiner
 Join MalleableStrings together using the given separator. More...

Public Member Functions

MalleableString addComments (Stream< String > comments)
 Associate comments with this.
abstract MalleableString constrain (Predicate< String > constraint)
 Apply the given constraint to leaf strings of this.
abstract boolean findBestRepresentation (Supplier< RenderResult > providedRender, ToLongFunction< RenderResult > badness, int width, int indentation, String singleLineCommentPrefix)
 Change the state of this such that the badness of the supplied render result is minimized.
MalleableString indent ()
 Return this, indented by one more level.
abstract boolean isEmpty ()
 Return whether any representation of this contains text.
abstract RenderResult render (int indentation, String singleLineCommentMarker, boolean codeMapTag, EObject enclosingEObject)
 Render this using indentation spaces per indentation level and singleLineCommentMarker to mark the beginnings of single-line comments.
record RenderResult (Stream< String > unplacedComments, String rendering, int levelsOfCommentDisplacement)
 The result of rendering a MalleableString.
MalleableString setSourceEObject (EObject sourceEObject)
 Specify the EObject from which this originated, if applicable.
String toString ()

Static Public Member Functions

static MalleableString anyOf (MalleableString... possibilities)
 Return an object that can be represented as any one of the given alternatives.
static MalleableString anyOf (Object... possibilities)
 Return an object that can be represented as any one of the given alternatives.
static MalleableString anyOf (String... possibilities)
 Return an object that can be represented as any one of the given alternatives.

Protected Attributes

List< String > comments = new ArrayList<>()
EObject sourceEObject = null

Detailed Description

A MalleableString is an object with multiple valid textual representations.

These textual representations are code that may have associated comments.

Member Function Documentation

◆ addComments()

MalleableString org.lflang.ast.MalleableString.addComments ( Stream< String > comments)

Associate comments with this.

◆ anyOf() [1/3]

MalleableString org.lflang.ast.MalleableString.anyOf ( MalleableString... possibilities)
static

Return an object that can be represented as any one of the given alternatives.

◆ anyOf() [2/3]

MalleableString org.lflang.ast.MalleableString.anyOf ( Object... possibilities)
static

Return an object that can be represented as any one of the given alternatives.

◆ anyOf() [3/3]

MalleableString org.lflang.ast.MalleableString.anyOf ( String... possibilities)
static

Return an object that can be represented as any one of the given alternatives.

◆ constrain()

abstract MalleableString org.lflang.ast.MalleableString.constrain ( Predicate< String > constraint)
abstract

Apply the given constraint to leaf strings of this.

This is done on a best-effort basis in the sense that if no options satisfy the constraint, the constraint is not applied.

◆ findBestRepresentation()

abstract boolean org.lflang.ast.MalleableString.findBestRepresentation ( Supplier< RenderResult > providedRender,
ToLongFunction< RenderResult > badness,
int width,
int indentation,
String singleLineCommentPrefix )
abstract

Change the state of this such that the badness of the supplied render result is minimized.

Parameters
providedRenderA supplier of render results that should be optimized.
badnessA badness computer for render results.
widthThe number of columns permitted for this, excluding indentation applied to the whole of this.
indentationThe number of spaces used per level of indentation.
singleLineCommentPrefixThe prefix that marks the start of a single-line comment.
Returns
Whether the best representation changed.

◆ indent()

MalleableString org.lflang.ast.MalleableString.indent ( )

Return this, indented by one more level.

◆ isEmpty()

abstract boolean org.lflang.ast.MalleableString.isEmpty ( )
abstract

Return whether any representation of this contains text.

◆ render()

abstract RenderResult org.lflang.ast.MalleableString.render ( int indentation,
String singleLineCommentMarker,
boolean codeMapTag,
EObject enclosingEObject )
abstract

Render this using indentation spaces per indentation level and singleLineCommentMarker to mark the beginnings of single-line comments.

◆ RenderResult()

record org.lflang.ast.MalleableString.RenderResult ( Stream< String > unplacedComments,
String rendering,
int levelsOfCommentDisplacement )

The result of rendering a MalleableString.

◆ setSourceEObject()

MalleableString org.lflang.ast.MalleableString.setSourceEObject ( EObject sourceEObject)

Specify the EObject from which this originated, if applicable.

◆ toString()

String org.lflang.ast.MalleableString.toString ( )

Member Data Documentation

◆ comments

List<String> org.lflang.ast.MalleableString.comments = new ArrayList<>()
protected

◆ sourceEObject

EObject org.lflang.ast.MalleableString.sourceEObject = null
protected

The documentation for this class was generated from the following file:
  • /Users/runner/work/lingua-franca/lingua-franca/core/src/main/java/org/lflang/ast/MalleableString.java