Package sc.lang.java
Class Expression
- java.lang.Object
-
- sc.lang.SemanticNode
-
- sc.lang.java.JavaSemanticNode
-
- sc.lang.java.Definition
-
- sc.lang.java.Statement
-
- sc.lang.java.Expression
-
- All Implemented Interfaces:
ISemanticNode
,ISrcStatement
,IUserDataNode
,IClassBodyStatement
,IDefinition
,ITypedObject
,IValueNode
,ILifecycle
- Direct Known Subclasses:
AbstractLiteral
,ArgumentsExpression
,ArrayInitializer
,BaseLambdaExpression
,BinaryExpression
,ChainedExpression
,ClassValueExpression
,GlueExpression
,JSFunctionDeclaration
,QuestionMarkExpression
,TwoOperatorExpression
public abstract class Expression extends Statement implements IValueNode, ITypedObject, IClassBodyStatement
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class sc.lang.java.Statement
Statement.ErrorRangeInfo, Statement.RuntimeStatus
-
Nested classes/interfaces inherited from class sc.lang.java.JavaSemanticNode
JavaSemanticNode.DepTypeCtx, JavaSemanticNode.DepTypeMode, JavaSemanticNode.MemberCache, JavaSemanticNode.MemberType
-
-
Field Summary
Fields Modifier and Type Field Description BindingDirection
bindingDirection
Statement
bindingStatement
boolean
inactive
Set this to true on an expression to disable it - it won't resolve itself during startboolean
nestedBinding
Statement
replacedByStatement
static java.lang.String
UnknownReferredType
-
Fields inherited from class sc.lang.java.Statement
childNestingDepth, errorArgs, excluded, fromStatement
-
Fields inherited from class sc.lang.java.Definition
modifiers, overrides
-
Fields inherited from class sc.lang.java.JavaSemanticNode
debugDisablePrettyToString, STOP_SEARCHING_SENTINEL
-
Fields inherited from class sc.lang.SemanticNode
debugDiffTrace, initialized, PARENT_NODE_PROPERTY, parentNode, PARSE_NODE_PROPERTY, parseletId, parseNode, parseNodeInvalid, processed, started, transformed, validated
-
Fields inherited from interface sc.lang.ISemanticNode
CopyAll, CopyIndependent, CopyInitLevels, CopyNormal, CopyParseNode, CopyReplace, CopyState, CopyTransformed, SkipParseNode
-
-
Constructor Summary
Constructors Constructor Description Expression()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addChildBodyStatements(java.util.List<java.lang.Object> res)
void
addInitStatements(java.util.List<Statement> res, InitStatementsMode mode)
Expression
applyJSConversion(java.lang.Object paramType)
boolean
canInsertStatementBefore(Expression from)
To differentiate between x++; and foo(bar(), x++);boolean
canMakeBindable()
void
changeExpressionsThis(TypeDeclaration thisType, TypeDeclaration outerType, java.lang.String varName)
void
changeToRHS()
Called when we are moving an expression from the left to the right hand side.void
clearInferredType()
void
convertToSetMethod(Expression arg)
Only needed for expressions that are the left hand side of the equals signExpression
createBindingParameters(boolean includesProps, Expression... bindingParams)
When we are transforming a nested expression, this method takes the set of chained expressions and produces an expression to use as the IBinding[] boundParams argument to create the binding.static Expression
createFromValue(java.lang.Object literalValue, boolean isInitializer)
IdentifierExpression
createImportedIdentExpr(java.lang.String typeName, java.lang.String methName)
Provide full type name and method name - returns an IdentifierExpression to use for a method call but where you need to fill in the arguments later.Expression
deepCopy(int options, java.util.IdentityHashMap<java.lang.Object,java.lang.Object> oldNewMap)
Performs a deep copy of the semantic node tree.java.lang.Object
evalBinding(java.lang.Class expectedType, ExecutionContext ctx)
void
evalBindingArgs(java.util.List<java.lang.Object> bindArgs, boolean isStatic, java.lang.Class expectedType, ExecutionContext ctx)
IBinding[]
evalBindingParameters(java.lang.Class expectedType, ExecutionContext ctx, Expression... bindingParams)
IBinding[]
evalBindingParametersWithThis(java.lang.Object thisObj, java.lang.Class expectedType, ExecutionContext ctx, Expression... bindingParams)
double
evalDouble(java.lang.Class expectedType, ExecutionContext ctx)
long
evalLong(java.lang.Class expectedType, ExecutionContext ctx)
ExecResult
exec(ExecutionContext ctx)
ISrcStatement
findFromStatement(ISrcStatement st)
Returns the statement that was generated from the given src statement.java.lang.CharSequence
formatExprToJS()
java.lang.String
getAbsoluteGenericTypeName(java.lang.Object resultType, boolean includeDims)
java.lang.String
getBindingTypeName()
Subclasses override this to return the class name to use for the binding expressionjava.util.List<Statement>
getBodyStatements()
java.lang.Object
getGenericArgumentType()
java.lang.Object
getGenericType()
java.lang.String
getGenericTypeName(java.lang.Object resultType, boolean includeDims)
boolean
getLHSAssignmentTyped()
java.util.List<JavaType>
getMethodTypeArguments()
java.lang.String
getNodeErrorText()
Override to provide per-node error supportjava.lang.String
getNodeWarningText()
Override for per-node warning supportboolean
getNotFoundError()
Returns true if this is a special "not found" errorjava.lang.Object
getParentReferenceType()
Only implemented for subclasses that can return needsSetMethod=true.Expression
getParentReferenceTypeExpression()
Only implemented for subclasses that can return needsSetMethod=true.java.lang.Object
getPrimitiveValue()
java.lang.String
getReferencePropertyName()
Only implemented for subclasses that can return needsSetMethod=true.java.lang.Class
getRuntimeClass()
Expression
getUnwrappedExpr()
java.lang.String
getUserVisibleName()
boolean
hasInferredType()
java.lang.Object
initBinding(java.lang.Class expectedType, ExecutionContext ctx)
protected boolean
inNamedPropertyMethod(java.lang.String identifier)
protected boolean
inObjectGetMethod(java.lang.Object newType)
Returns true this expression is defined in a method which makes up a getX method for an object of the type being newed.protected boolean
inPropertyMethodForDef(java.lang.Object def)
boolean
isConstant()
boolean
isDeclaredConstant()
This is like isConstant but does not "start" anything so you can use it during initializationboolean
isInferredFinal()
boolean
isInferredSet()
boolean
isLeafStatement()
boolean
isReferenceInitializer()
boolean
isReferenceValueObject()
boolean
isSettableExpr()
boolean
isSimpleReference()
abstract boolean
isStaticTarget()
boolean
isVoidType()
boolean
needsParenWrapper()
Does this expression need a paren wrapper to be combined with an artithmetic operationboolean
needsSetMethod()
boolean
needsTransform()
static Expression
parse(java.lang.String expressionStr)
boolean
producesHtml()
boolean
propagatesInferredType(Expression child)
void
setAssignment(boolean assign)
Only needed for expressions that are the left hand side of the equals signvoid
setBindingInfo(BindingDirection dir, Statement dest, boolean nested)
BindingDirection only set if this is a top-level bindingboolean
setInferredType(java.lang.Object type, boolean finalType)
Called once for each parent-child expression relationship during the start process to propagate the parent's inferredType to the child as we walk up the expression tree so that, for example, we know the initial information in the parameter type so we can find the right method, so the method's parameter types further refine types of the args.void
setValue(java.lang.Object value, ExecutionContext ctx)
java.lang.String
toDefinitionString()
java.lang.String
toGenerateString()
java.lang.String
toLanguageString()
java.lang.String
toSafeLanguageString()
java.lang.String
toString()
boolean
transform(ILanguageModel.RuntimeType runtime)
All definitions share the ability to inherit their definitions.void
transformBinding(ILanguageModel.RuntimeType runtime)
From "a.b.c" to: Bind.bind(<enclosingObject or class>, boundFieldName,void
transformBindingArgs(SemanticNodeList<Expression> bindArgs, sc.lang.java.Expression.BindDescriptor bd)
-
Methods inherited from class sc.lang.java.Statement
addBreakpointNodes, addDependentTypes, addMappingForSrcStatement, addMappingForSrcStatement, addMappingForStatement, addMemberByName, addMembersByName, addNodeCompletions, addReturnStatements, addStatementNodeCompletions, addToFileLineIndex, callsSuper, callsSuperMethod, callsThis, checkFromStatementRef, childIsTopLevelStatement, clearDynFields, clearTransformed, collectConstructorPropInit, collectReferenceInitializers, conflictsWith, displayError, displayFormattedError, displayRangeError, displayTypeError, evalRemoteExprs, execForRuntime, execSys, findStatement, formatToJS, getBuildInitExpression, getChildNestingDepth, getComment, getConstrArgs, getCurrentMethod, getFromStatement, getIndentStr, getNestingDepth, getNodeContainsPart, getNodeErrorRange, getNumStatementLines, getRuntimeStatus, getSrcStatement, getStatementTerminator, getUserData, hasErrors, initDynStatement, initDynStatement, initDynStatements, isIncompleteStatement, isLabeled, isLineStatement, markFixedSuper, matchesStatement, modifyDefinition, needsEnclosingClass, refreshBoundTypes, setAccessTimeForRefs, setComment, setFromStatement, setUserData, stop, transformToJS, updateFromStatementRef
-
Methods inherited from class sc.lang.java.Definition
addInheritedAnnotationProcessor, addModifier, getAccessLevel, getAnnotation, getAnnotations, getAnnotationValueKey, getComputedModifiers, getDefinitionProcessors, getEnclosingTypeName, getExtraModifiers, getInternalAccessLevel, getModifierFlags, getRepeatingAnnotation, getScope, getScopeDefinition, getScopeName, getScopeProcessor, hasAnnotation, hasModifier, init, isDefaultSync, mergeModifiers, modifiersToString, process, processModifiers, removeAnnotation, setAnnotations, setModifierFlags, start, startModifiers, transformDefaultModifier, useDefaultModifier, validate
-
Methods inherited from class sc.lang.java.JavaSemanticNode
addDependentType, applyPartialValue, declaresConstructor, definesConstructor, definesMember, definesMethod, definesType, detectCycles, displayVerboseWarning, displayWarning, findMember, findMemberOwner, findMethod, findType, findType, getDependencyDisabledText, getEnclosingBlockStatement, getEnclosingIMethod, getEnclosingIType, getEnclosingMethod, getEnclosingMethod, getEnclosingStatement, getEnclosingTag, getEnclosingTemplate, getEnclosingType, getExecMode, getImportedTypeName, getJavaLanguage, getJavaModel, getLayeredSystem, getMessageString, getRootTag, getRootType, getStructuralEnclosingType, isCollapsibleNode, isDynamicType, isStatic, needsDataBinding, refreshNode, runtimeError, suggestCompletions, toFileString, transformTemplate, visitTypeReferences
-
Methods inherited from class sc.lang.SemanticNode
changeLanguage, clearInitialized, clearParseNode, clearStarted, computeNearString, containsChild, deepEquals, diffNode, ensureValidated, equals, formatLeftParenDelegateToParent, formatSpaceBeforeAngleBracket, getAnyChildParseNode, getChildAtIndex, getEnclosingSrcStatement, getLanguageModel, getNodeCount, getParentNode, getParseErrorNode, getParseletId, getParseNode, getRootNode, getStartIndex, getStopSemanticProps, getTransformed, hashCode, indexOfChild, isInitialized, isParseNodeValid, isProcessed, isSemanticChildValue, isSemanticProperty, isSemanticProperty, isStarted, isTrailingSrcStatement, isValidated, regenerate, regenerateIfTracking, removeChild, replaceChild, restoreParseNode, restoreParseNode, sameSrcLocation, serialize, setParentNode, setParseErrorNode, setParselet, setParseletId, setParseNode, setParseNodeValid, setProperty, setProperty, spaceAfterParen, styleNode, styleNode, toDeclarationString, toDefinitionString, toDefinitionString, toHeaderString, toLanguageString, toLocationString, toLocationString, toLocationString, toModelString, toModelString, validateParseNode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface sc.lang.java.IDefinition
getEnclosingIType
-
Methods inherited from interface sc.lang.ISemanticNode
changeLanguage, clearInitialized, clearParseNode, clearStarted, containsChild, deepEquals, diffNode, getChildAtIndex, getDependencyDisabledText, getNodeCount, getParentNode, getParseErrorNode, getParseletId, getParseNode, getRootNode, getTransformed, indexOfChild, isInitialized, isParseNodeValid, isSemanticChildValue, isStarted, isTrailingSrcStatement, isValidated, process, refreshNode, regenerate, regenerateIfTracking, removeChild, replaceChild, restoreParseNode, serialize, setParentNode, setParseErrorNode, setParseletId, setParseNode, setParseNodeValid, styleNode, toHeaderString, toLanguageString, toModelString, validateParseNode
-
Methods inherited from interface sc.lang.java.ITypedObject
getTypeDeclaration
-
Methods inherited from interface sc.lang.java.IValueNode
eval
-
-
-
-
Field Detail
-
bindingDirection
public transient BindingDirection bindingDirection
-
bindingStatement
public transient Statement bindingStatement
-
nestedBinding
public transient boolean nestedBinding
-
replacedByStatement
public transient Statement replacedByStatement
-
inactive
public transient boolean inactive
Set this to true on an expression to disable it - it won't resolve itself during start
-
UnknownReferredType
public static final java.lang.String UnknownReferredType
- See Also:
- Constant Field Values
-
-
Method Detail
-
parse
public static Expression parse(java.lang.String expressionStr)
-
createFromValue
public static Expression createFromValue(java.lang.Object literalValue, boolean isInitializer)
-
evalLong
public long evalLong(java.lang.Class expectedType, ExecutionContext ctx)
-
evalDouble
public double evalDouble(java.lang.Class expectedType, ExecutionContext ctx)
-
setAssignment
public void setAssignment(boolean assign)
Only needed for expressions that are the left hand side of the equals sign
-
needsSetMethod
public boolean needsSetMethod()
-
convertToSetMethod
public void convertToSetMethod(Expression arg)
Only needed for expressions that are the left hand side of the equals sign
-
setValue
public void setValue(java.lang.Object value, ExecutionContext ctx)
-
getRuntimeClass
public java.lang.Class getRuntimeClass()
-
setBindingInfo
public void setBindingInfo(BindingDirection dir, Statement dest, boolean nested)
BindingDirection only set if this is a top-level binding
-
needsTransform
public boolean needsTransform()
- Specified by:
needsTransform
in interfaceISemanticNode
- Overrides:
needsTransform
in classDefinition
-
transform
public boolean transform(ILanguageModel.RuntimeType runtime)
Description copied from class:Definition
All definitions share the ability to inherit their definitions. They must set the "overrides" property when they figure out if they are replacing another definition.- Specified by:
transform
in interfaceISemanticNode
- Overrides:
transform
in classDefinition
-
applyJSConversion
public Expression applyJSConversion(java.lang.Object paramType)
-
producesHtml
public boolean producesHtml()
-
evalBinding
public java.lang.Object evalBinding(java.lang.Class expectedType, ExecutionContext ctx)
-
initBinding
public java.lang.Object initBinding(java.lang.Class expectedType, ExecutionContext ctx)
-
evalBindingArgs
public void evalBindingArgs(java.util.List<java.lang.Object> bindArgs, boolean isStatic, java.lang.Class expectedType, ExecutionContext ctx)
-
getBindingTypeName
public java.lang.String getBindingTypeName()
Subclasses override this to return the class name to use for the binding expression
-
transformBinding
public void transformBinding(ILanguageModel.RuntimeType runtime)
From "a.b.c" to: Bind.bind(<enclosingObject or class>, boundFieldName,
-
createBindingParameters
public Expression createBindingParameters(boolean includesProps, Expression... bindingParams)
When we are transforming a nested expression, this method takes the set of chained expressions and produces an expression to use as the IBinding[] boundParams argument to create the binding.
-
evalBindingParameters
public IBinding[] evalBindingParameters(java.lang.Class expectedType, ExecutionContext ctx, Expression... bindingParams)
-
evalBindingParametersWithThis
public IBinding[] evalBindingParametersWithThis(java.lang.Object thisObj, java.lang.Class expectedType, ExecutionContext ctx, Expression... bindingParams)
-
transformBindingArgs
public void transformBindingArgs(SemanticNodeList<Expression> bindArgs, sc.lang.java.Expression.BindDescriptor bd)
-
isConstant
public boolean isConstant()
-
isDeclaredConstant
public boolean isDeclaredConstant()
This is like isConstant but does not "start" anything so you can use it during initialization
-
isReferenceInitializer
public boolean isReferenceInitializer()
-
isSimpleReference
public boolean isSimpleReference()
-
changeExpressionsThis
public void changeExpressionsThis(TypeDeclaration thisType, TypeDeclaration outerType, java.lang.String varName)
-
inNamedPropertyMethod
protected boolean inNamedPropertyMethod(java.lang.String identifier)
-
inPropertyMethodForDef
protected boolean inPropertyMethodForDef(java.lang.Object def)
-
inObjectGetMethod
protected boolean inObjectGetMethod(java.lang.Object newType)
Returns true this expression is defined in a method which makes up a getX method for an object of the type being newed. Because we do not generate classes for simple inner types, the newType passed has to be the runtime class used in the new expression for this objects type.
-
isReferenceValueObject
public boolean isReferenceValueObject()
- Overrides:
isReferenceValueObject
in classJavaSemanticNode
-
getAbsoluteGenericTypeName
public java.lang.String getAbsoluteGenericTypeName(java.lang.Object resultType, boolean includeDims)
- Specified by:
getAbsoluteGenericTypeName
in interfaceITypedObject
-
getGenericTypeName
public java.lang.String getGenericTypeName(java.lang.Object resultType, boolean includeDims)
- Specified by:
getGenericTypeName
in interfaceITypedObject
-
getGenericType
public java.lang.Object getGenericType()
-
getGenericArgumentType
public java.lang.Object getGenericArgumentType()
-
canInsertStatementBefore
public boolean canInsertStatementBefore(Expression from)
To differentiate between x++; and foo(bar(), x++);- Overrides:
canInsertStatementBefore
in classJavaSemanticNode
-
getParentReferenceType
public java.lang.Object getParentReferenceType()
Only implemented for subclasses that can return needsSetMethod=true. For "a.b.c" returns the type of "a.b"
-
getReferencePropertyName
public java.lang.String getReferencePropertyName()
Only implemented for subclasses that can return needsSetMethod=true. For "a.b.c" returns "c"
-
getParentReferenceTypeExpression
public Expression getParentReferenceTypeExpression()
Only implemented for subclasses that can return needsSetMethod=true. For "a.b.c" returns an expr for "a.b"
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toDefinitionString
public java.lang.String toDefinitionString()
- Overrides:
toDefinitionString
in classSemanticNode
-
exec
public ExecResult exec(ExecutionContext ctx)
-
getLHSAssignmentTyped
public boolean getLHSAssignmentTyped()
-
toLanguageString
public java.lang.String toLanguageString()
- Specified by:
toLanguageString
in interfaceISemanticNode
- Overrides:
toLanguageString
in classSemanticNode
-
isStaticTarget
public abstract boolean isStaticTarget()
-
addInitStatements
public void addInitStatements(java.util.List<Statement> res, InitStatementsMode mode)
- Overrides:
addInitStatements
in classStatement
-
getUserVisibleName
public java.lang.String getUserVisibleName()
- Overrides:
getUserVisibleName
in classStatement
-
canMakeBindable
public boolean canMakeBindable()
-
changeToRHS
public void changeToRHS()
Called when we are moving an expression from the left to the right hand side.
-
needsParenWrapper
public boolean needsParenWrapper()
Does this expression need a paren wrapper to be combined with an artithmetic operation
-
addChildBodyStatements
public void addChildBodyStatements(java.util.List<java.lang.Object> res)
- Overrides:
addChildBodyStatements
in classStatement
-
deepCopy
public Expression deepCopy(int options, java.util.IdentityHashMap<java.lang.Object,java.lang.Object> oldNewMap)
Description copied from interface:ISemanticNode
Performs a deep copy of the semantic node tree. Subclasses should do their own copy implementation to decide what else to copy. Uses the copy options flags above. The default, with 0, just copies the semantic node information so you get a new tree like's it parsed but without parse node info. Use that mode only if you want to throw away the original source and regenerate it all from scratch. Otherwise, you can copy the parse tree as well. If you want to copy the semantic node's initial resolved state - including it's init/start, etc. and whatever the subclass adds to that copy, use CopyState or CopyNormal - for both parse nodes and state.- Specified by:
deepCopy
in interfaceISemanticNode
- Overrides:
deepCopy
in classStatement
-
toGenerateString
public java.lang.String toGenerateString()
- Overrides:
toGenerateString
in classJavaSemanticNode
-
toSafeLanguageString
public java.lang.String toSafeLanguageString()
- Overrides:
toSafeLanguageString
in classSemanticNode
-
formatExprToJS
public java.lang.CharSequence formatExprToJS()
-
findFromStatement
public ISrcStatement findFromStatement(ISrcStatement st)
Description copied from class:Statement
Returns the statement that was generated from the given src statement. This will end up being the first one we encounter in the search for the src statement in the chain of fromStatements.- Specified by:
findFromStatement
in interfaceISrcStatement
- Overrides:
findFromStatement
in classStatement
-
isInferredFinal
public boolean isInferredFinal()
-
setInferredType
public boolean setInferredType(java.lang.Object type, boolean finalType)
Called once for each parent-child expression relationship during the start process to propagate the parent's inferredType to the child as we walk up the expression tree so that, for example, we know the initial information in the parameter type so we can find the right method, so the method's parameter types further refine types of the args. The last time we call it, finalType is set to true. When an error occurs and the type becomes "unknown" - we call this with type = UnknownReferredType and finalType =true
-
propagatesInferredType
public boolean propagatesInferredType(Expression child)
-
hasInferredType
public boolean hasInferredType()
-
getMethodTypeArguments
public java.util.List<JavaType> getMethodTypeArguments()
-
clearInferredType
public void clearInferredType()
-
isInferredSet
public boolean isInferredSet()
-
getNodeErrorText
public java.lang.String getNodeErrorText()
Description copied from class:SemanticNode
Override to provide per-node error support- Specified by:
getNodeErrorText
in interfaceISemanticNode
- Overrides:
getNodeErrorText
in classStatement
-
getNodeWarningText
public java.lang.String getNodeWarningText()
Description copied from class:SemanticNode
Override for per-node warning support- Specified by:
getNodeWarningText
in interfaceISemanticNode
- Overrides:
getNodeWarningText
in classSemanticNode
-
isLeafStatement
public boolean isLeafStatement()
- Overrides:
isLeafStatement
in classStatement
-
getBodyStatements
public java.util.List<Statement> getBodyStatements()
- Specified by:
getBodyStatements
in interfaceIClassBodyStatement
-
getPrimitiveValue
public java.lang.Object getPrimitiveValue()
- Specified by:
getPrimitiveValue
in interfaceIValueNode
-
isVoidType
public boolean isVoidType()
-
getNotFoundError
public boolean getNotFoundError()
Description copied from interface:ISemanticNode
Returns true if this is a special "not found" error- Specified by:
getNotFoundError
in interfaceISemanticNode
- Overrides:
getNotFoundError
in classStatement
-
createImportedIdentExpr
public IdentifierExpression createImportedIdentExpr(java.lang.String typeName, java.lang.String methName)
Provide full type name and method name - returns an IdentifierExpression to use for a method call but where you need to fill in the arguments later. If possible, an existing import is used to shorten the generated code.
-
isSettableExpr
public boolean isSettableExpr()
-
getUnwrappedExpr
public Expression getUnwrappedExpr()
-
-