Class StructDeclaration
- All Implemented Interfaces:
AST,Expression
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StructDeclarationA base-case empty StructDeclaration - useful as a better null sentinel. -
Constructor Summary
ConstructorsConstructorDescriptionStructDeclaration(List<StructDeclaration.Member> members, Optional<Pair<Token, Token>> boundary) -
Method Summary
Modifier and TypeMethodDescription<T,R> R accept(ExpressionVisitor<T, R> visitor, T data) static StructDeclaration.MemberanonMember(Expression expression) protected voidappendSource(StringBuilder appendTo) Implementers extend this to append their source to the given string builder.protected static voidappendSource(AST ast, StringBuilder appendTo) Helper method for appending the source of another ast element to a string builder, efficiently if possible.protected voidappendString(StringBuilder appendTo) Append a simplified string representation to the builder.protected booleanbooleangetMember(int index) Shortcut forgetMembers().get(index)inthashCode()booleanisEmpty()booleanTests whether this expression is a literal expression - a literal expression is a constant expression that is unaffected by the scope in which it was realized/evaluated and contains no function-defined behaviour.static StructDeclaration.MemberjsonStyleMember(String ident, Expression expression) Returns a json style (foo: bar) struct memberstatic StructDeclaration.MemberjsonStyleMember(Token ident, Expression expression) Returns a json style (foo: bar) struct memberstatic StructDeclaration.MemberselectAllMember(Token asterisk) Returns a select-all ({*}) struct memberstatic StructDeclaration.MembersqlStyleMember(Token ident, Expression expression, Token as) Returns an sql style (bar as foo) struct memberfinal StringtoSource()final StringtoString()Returns a simplified view of the ast in a source-like fashion, but with a lot of details left out for concisenesswithNewMembers(List<StructDeclaration.Member> newMembers, Optional<Pair<Token, Token>> newBoundary) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface nz.org.riskscape.rl.ast.AST
isA, switchType, toSource
-
Field Details
-
EMPTY
A base-case empty StructDeclaration - useful as a better null sentinel.
-
-
Constructor Details
-
StructDeclaration
-
-
Method Details
-
anonMember
- Returns:
- an anonymous attribute declaration wrapping the given expression.
-
jsonStyleMember
Returns a json style (foo: bar) struct member
-
jsonStyleMember
Returns a json style (foo: bar) struct member
-
sqlStyleMember
Returns an sql style (bar as foo) struct member
-
selectAllMember
Returns a select-all ({*}) struct member
-
appendSource
Implementers extend this to append their source to the given string builder. Done via string builder to encourage a more efficient implementation than is possible with concatenating multiple toString calls that typically contruct a string builder anyway.
-
accept
-
getMember
Shortcut for
getMembers().get(index)- Returns:
- the AttrDeclaration at the given zero-based index
- Throws:
IndexOutOfBoundsException- if the index is < 0 or > size
-
withNewMembers
public StructDeclaration withNewMembers(List<StructDeclaration.Member> newMembers, Optional<Pair<Token, Token>> newBoundary) -
isEmpty
public boolean isEmpty() -
isLiteral
public boolean isLiteral()Description copied from interface:ExpressionTests whether this expression is a literal expression - a literal expression is a constant expression that is unaffected by the scope in which it was realized/evaluated and contains no function-defined behaviour. Therefore a literal expression is one that contains no property access (unless the receiver is a literal) and no function calls.
A literal expression will always realize to being a constant (e.g.
RealizedExpression.isConstant()will return true), however there are constant expressions that are not literal.One edge case to be aware of is a limitation of the AST in determining literal expressions in contrived cases like this one -
{foo: 'bar', baz: qux}.foo. The struct is not literal, but the property being accessed is. But because the AST is relatively 'dumb', the expression itself is not literal. It can, however, be realized as a constant - realization is 'smarter' and can pick out the that the property being accessed is constant. -
equals
-
canEqual
-
hashCode
public int hashCode() -
getMembers
-
getBoundary
- Returns:
- a pair of tokens that represent the start and end of this expression, to be used when giving users information about where errors have occurred. If the expression has been rebuilt then the boundary may be empty or it may be from the original AST. Intended for use in problems to trace errors back to their source.
-
appendSource
Helper method for appending the source of another ast element to a string builder, efficiently if possible.
-
toString
Returns a simplified view of the ast in a source-like fashion, but with a lot of details left out for conciseness
-
appendString
Append a simplified string representation to the builder. Default implementation uses appendSource. Subclasses can override to provide a more concise representation.
-
toSource
-