Package sc.lang.java
Class NewExpression
- java.lang.Object
-
- All Implemented Interfaces:
ISemanticNode
,ISrcStatement
,IUserDataNode
,IClassBodyStatement
,IDefinition
,ITypedObject
,IValueNode
,ILifecycle
public class NewExpression extends IdentifierExpression
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class sc.lang.java.IdentifierExpression
IdentifierExpression.IdentifierType
-
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 static java.lang.String
ANON_TYPE_PREFIX
AnonClassDeclaration
anonType
For anonymous types, we may create a real top-level type to represent it in the runtime model.AnonClassDeclaration
anonTypeTransformed
This is a clone of the anonType which gets transformed.SemanticNodeList<Expression>
arrayDimensions
ArrayInitializer
arrayInitializer
java.lang.Object
boundType
java.lang.String
boundTypeName
SemanticNodeList<Statement>
classBody
java.lang.String
classPropertyName
java.lang.Object
constructor
boolean
isStaticContext
boolean
lambdaExpression
True if this new expression is part of a lambda expression.SemanticNodeList<JavaType>
typeArguments
java.lang.String
typeIdentifier
-
Fields inherited from class sc.lang.java.IdentifierExpression
identifiers, innerCreator
-
Fields inherited from class sc.lang.java.ArgumentsExpression
arguments
-
Fields inherited from class sc.lang.java.Expression
bindingDirection, bindingStatement, inactive, nestedBinding, replacedByStatement, 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 NewExpression()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBreakpointNodes(java.util.List<ISrcStatement> res, ISrcStatement srcStatement)
Adds all of the generated statements to the resulting list, for the case where more than one fromStatement points to the same src statement.void
addDependentTypes(java.util.Set<java.lang.Object> types, JavaSemanticNode.DepTypeCtx mode)
java.lang.String
addNodeCompletions(JavaModel origModel, JavaSemanticNode origNode, java.lang.String extMatchPrefix, int offset, java.lang.String dummyIdentifier, java.util.Set<java.lang.String> candidates, boolean nextNameInPath, int max)
This works like suggestCompletions but designed to conform to the requirements of IntelliJ.boolean
applyPartialValue(java.lang.Object value)
When Parser.enablePartialValues is set, and we do not complete parsing the input we'll have a set of errors which represent model fragments.void
changeExpressionsThis(TypeDeclaration td, TypeDeclaration outer, java.lang.String varName)
static NewExpression
create(java.lang.String identifier, SemanticNodeList<Expression> args)
static NewExpression
create(java.lang.String identifier, SemanticNodeList<Expression> arrayDimensions, ArrayInitializer init)
NewExpression
deepCopy(int options, java.util.IdentityHashMap<java.lang.Object,java.lang.Object> oldNewMap)
Performs a deep copy of the semantic node tree.protected java.lang.String
dimsToGenerateString()
java.lang.Object
eval(java.lang.Class expectedType, ExecutionContext ctx)
void
evalBindingArgs(java.util.List<java.lang.Object> bindArgs, boolean isStatic, java.lang.Class expectedType, ExecutionContext ctx)
java.util.List<java.lang.Object>
evalTypeArguments(java.lang.Object type)
ExecResult
exec(ExecutionContext ctx)
java.lang.Object
findMember(java.lang.String name, java.util.EnumSet<JavaSemanticNode.MemberType> mtype, java.lang.Object fromChild, java.lang.Object refType, TypeContext ctx, boolean skipIfaces)
java.lang.Object
findMethod(java.lang.String name, java.util.List<? extends java.lang.Object> params, java.lang.Object fromChild, java.lang.Object refType, boolean staticOnly, java.lang.Object inferredType)
ClassDeclaration
getAnonymousType(boolean xform)
java.lang.String
getBindingTypeName()
Subclasses override this to return the class name to use for the binding expressionjava.util.List<Statement>
getBodyStatements()
int
getChildNestingDepth()
java.lang.Object
getGenericType()
java.lang.Object
getTypeDeclaration()
void
init()
protected boolean
inNewMethod()
boolean
isLineStatement()
boolean
isReferenceInitializer()
boolean
needsTransform()
boolean
refreshBoundTypes(int flags)
void
resolve()
void
setBindingInfo(BindingDirection dir, Statement dest, boolean nested)
BindingDirection only set if this is a top-level bindingboolean
setInferredType(java.lang.Object inferredType, 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
start()
void
stop()
void
styleNode(IStyleAdapter adapter)
Styling for identifier expressions is complicated because the information we need to do the styling is at this level, but the elements we are styling are buried down in the parse-tree of this node.int
suggestCompletions(java.lang.String prefix, java.lang.Object currentType, ExecutionContext ctx, java.lang.String command, int cursor, java.util.Set<java.lang.String> candidates, java.lang.Object continuation, int max)
TODO: very similar to ClassValueExpression.suggestCompletions - try to share this code?java.lang.String
toGenerateString()
boolean
transform(ILanguageModel.RuntimeType runtime)
All definitions share the ability to inherit their definitions.void
transformBindingArgs(SemanticNodeList<Expression> bindArgs, sc.lang.java.Expression.BindDescriptor bd)
From "a.b.c" to: Bind.bind(<enclosingObject or class>, boundFieldName,int
transformTemplate(int ix, boolean statefulContext)
A pass over the semantic node tree to convert template statements into layer cake statements.Statement
transformToJS()
void
validate()
-
Methods inherited from class sc.lang.java.IdentifierExpression
addIdentifier, argsToGenerateString, callsSuper, callsSuperMethod, callsThis, canMakeBindable, changeToRHS, clearStarted, convertPropertyToGetName, convertPropertyToSetName, convertToSetMethod, create, create, createMethodCall, doCastOnConvert, execForRuntime, findClosestMethod, findFromStatement, generateIdentString, getAllIdentifiers, getAssignedProperty, getBoundType, getBoundTypeNoParamType, getConstrArgs, getGenericTypeForIdentifier, getIdentifierPathName, getIdentifierType, getIdentifierTypeFromType, getLHSAssignmentTyped, getNodeContainsPart, getNodeErrorRange, getParentReferenceType, getParentReferenceTypeExpression, getQualifiedClassIdentifier, getReferencePropertyName, getReferenceType, getTypeForIdentifier, isConstant, isDeclaredConstant, isGetSetConversionDisabled, isInferredFinal, isInferredSet, isSettableExpr, isSimpleReference, isStaticTarget, makeBindable, markFixedSuper, needsEnclosingClass, needsGetMethod, needsGetSet, needsSetMethod, offset, producesHtml, propagatesInferredType, removeIdentifier, reresolveTypeReference, setAccessTimeForRefs, setAssignment, setIdentifier, setIdentifiersFromArgs, setParentNode, setValue, visitTypeReferences
-
Methods inherited from class sc.lang.java.Expression
addChildBodyStatements, addInitStatements, applyJSConversion, canInsertStatementBefore, clearInferredType, createBindingParameters, createFromValue, createImportedIdentExpr, evalBinding, evalBindingParameters, evalBindingParametersWithThis, evalDouble, evalLong, formatExprToJS, getAbsoluteGenericTypeName, getGenericArgumentType, getGenericTypeName, getMethodTypeArguments, getNodeErrorText, getNodeWarningText, getNotFoundError, getPrimitiveValue, getRuntimeClass, getUnwrappedExpr, getUserVisibleName, hasInferredType, initBinding, inNamedPropertyMethod, inObjectGetMethod, inPropertyMethodForDef, isLeafStatement, isReferenceValueObject, isVoidType, needsParenWrapper, parse, toDefinitionString, toLanguageString, toSafeLanguageString, toString, transformBinding
-
Methods inherited from class sc.lang.java.Statement
addMappingForSrcStatement, addMappingForSrcStatement, addMappingForStatement, addMemberByName, addMembersByName, addReturnStatements, addStatementNodeCompletions, addToFileLineIndex, checkFromStatementRef, childIsTopLevelStatement, clearDynFields, clearTransformed, collectConstructorPropInit, collectReferenceInitializers, conflictsWith, displayError, displayFormattedError, displayRangeError, displayTypeError, evalRemoteExprs, execSys, findStatement, formatToJS, getBuildInitExpression, getComment, getCurrentMethod, getFromStatement, getIndentStr, getNestingDepth, getNumStatementLines, getRuntimeStatus, getSrcStatement, getStatementTerminator, getUserData, hasErrors, initDynStatement, initDynStatement, initDynStatements, isIncompleteStatement, isLabeled, matchesStatement, modifyDefinition, setComment, setFromStatement, setUserData, 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, isDefaultSync, mergeModifiers, modifiersToString, process, processModifiers, removeAnnotation, setAnnotations, setModifierFlags, startModifiers, transformDefaultModifier, useDefaultModifier
-
Methods inherited from class sc.lang.java.JavaSemanticNode
addDependentType, declaresConstructor, definesConstructor, definesMember, definesMethod, definesType, detectCycles, displayVerboseWarning, displayWarning, findMemberOwner, 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, toFileString
-
Methods inherited from class sc.lang.SemanticNode
changeLanguage, clearInitialized, clearParseNode, 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, setParseErrorNode, setParselet, setParseletId, setParseNode, setParseNodeValid, setProperty, setProperty, spaceAfterParen, 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, 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, setParseErrorNode, setParseletId, setParseNode, setParseNodeValid, toHeaderString, toLanguageString, toModelString, validateParseNode
-
-
-
-
Field Detail
-
ANON_TYPE_PREFIX
public static java.lang.String ANON_TYPE_PREFIX
-
arrayDimensions
public SemanticNodeList<Expression> arrayDimensions
-
arrayInitializer
public ArrayInitializer arrayInitializer
-
typeIdentifier
public java.lang.String typeIdentifier
-
typeArguments
public SemanticNodeList<JavaType> typeArguments
-
classBody
public SemanticNodeList<Statement> classBody
-
boundType
public transient java.lang.Object boundType
-
classPropertyName
public transient java.lang.String classPropertyName
-
boundTypeName
public transient java.lang.String boundTypeName
-
anonType
public transient AnonClassDeclaration anonType
For anonymous types, we may create a real top-level type to represent it in the runtime model.
-
anonTypeTransformed
public transient AnonClassDeclaration anonTypeTransformed
This is a clone of the anonType which gets transformed. It is only available in the transformed model
-
constructor
public transient java.lang.Object constructor
-
isStaticContext
public transient boolean isStaticContext
-
lambdaExpression
public transient boolean lambdaExpression
True if this new expression is part of a lambda expression. If so, it does not create a real type in the type system
-
-
Method Detail
-
create
public static NewExpression create(java.lang.String identifier, SemanticNodeList<Expression> args)
-
create
public static NewExpression create(java.lang.String identifier, SemanticNodeList<Expression> arrayDimensions, ArrayInitializer init)
-
init
public void init()
- Specified by:
init
in interfaceILifecycle
- Overrides:
init
in classDefinition
-
start
public void start()
- Specified by:
start
in interfaceILifecycle
- Overrides:
start
in classIdentifierExpression
-
setInferredType
public boolean setInferredType(java.lang.Object inferredType, boolean finalType)
Description copied from class:Expression
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- Overrides:
setInferredType
in classIdentifierExpression
-
validate
public void validate()
- Specified by:
validate
in interfaceILifecycle
- Overrides:
validate
in classIdentifierExpression
-
findMember
public java.lang.Object findMember(java.lang.String name, java.util.EnumSet<JavaSemanticNode.MemberType> mtype, java.lang.Object fromChild, java.lang.Object refType, TypeContext ctx, boolean skipIfaces)
- Overrides:
findMember
in classJavaSemanticNode
-
findMethod
public java.lang.Object findMethod(java.lang.String name, java.util.List<? extends java.lang.Object> params, java.lang.Object fromChild, java.lang.Object refType, boolean staticOnly, java.lang.Object inferredType)
- Overrides:
findMethod
in classJavaSemanticNode
-
isReferenceInitializer
public boolean isReferenceInitializer()
- Overrides:
isReferenceInitializer
in classIdentifierExpression
-
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 classIdentifierExpression
-
needsTransform
public boolean needsTransform()
- Specified by:
needsTransform
in interfaceISemanticNode
- Overrides:
needsTransform
in classIdentifierExpression
-
getTypeDeclaration
public java.lang.Object getTypeDeclaration()
- Specified by:
getTypeDeclaration
in interfaceITypedObject
- Overrides:
getTypeDeclaration
in classIdentifierExpression
-
evalTypeArguments
public java.util.List<java.lang.Object> evalTypeArguments(java.lang.Object type)
-
getGenericType
public java.lang.Object getGenericType()
- Overrides:
getGenericType
in classIdentifierExpression
-
inNewMethod
protected boolean inNewMethod()
-
exec
public ExecResult exec(ExecutionContext ctx)
- Overrides:
exec
in classIdentifierExpression
-
resolve
public void resolve()
-
eval
public java.lang.Object eval(java.lang.Class expectedType, ExecutionContext ctx)
- Specified by:
eval
in interfaceIValueNode
- Overrides:
eval
in classIdentifierExpression
-
getAnonymousType
public ClassDeclaration getAnonymousType(boolean xform)
-
changeExpressionsThis
public void changeExpressionsThis(TypeDeclaration td, TypeDeclaration outer, java.lang.String varName)
- Overrides:
changeExpressionsThis
in classIdentifierExpression
-
getBindingTypeName
public java.lang.String getBindingTypeName()
Description copied from class:Expression
Subclasses override this to return the class name to use for the binding expression- Overrides:
getBindingTypeName
in classIdentifierExpression
-
transformBindingArgs
public void transformBindingArgs(SemanticNodeList<Expression> bindArgs, sc.lang.java.Expression.BindDescriptor bd)
Description copied from class:IdentifierExpression
From "a.b.c" to: Bind.bind(<enclosingObject or class>, boundFieldName,- Overrides:
transformBindingArgs
in classIdentifierExpression
-
evalBindingArgs
public void evalBindingArgs(java.util.List<java.lang.Object> bindArgs, boolean isStatic, java.lang.Class expectedType, ExecutionContext ctx)
- Overrides:
evalBindingArgs
in classIdentifierExpression
-
styleNode
public void styleNode(IStyleAdapter adapter)
Description copied from class:IdentifierExpression
Styling for identifier expressions is complicated because the information we need to do the styling is at this level, but the elements we are styling are buried down in the parse-tree of this node. So far this is the only problematic case for Java so we are living with it but adding some features at the parselets level would help. One problem is that the parseNode for the IdentifierExpression may be expression, optExpression or exprStatement. We optionally need to 'drill down' to get the parse-node for the IdentifierExpression, then wrap the output with any parse nodes we skipped before or after. To handle this at the parselet level, we could skip those levels automatically. Another problem is that the path name is split into the first name, then "." followed by each subsequent name so there's an extra bump in the hierarchy to deal with the second and subsequent path-names. We could add a method called - childStyleHandler which is called for each child parse node that produces an array value (in this case, the identifiers array). It would return null for parse nodes which are ignored in styling or 'member' or 'staticMember' as necessary for each segment in the identifiers array. That method would be passed the current parent parse node, the child-index, and the current parse-node so it could go back into the identifier expression and find the right style for that segment of the path-name. It could probaby just unmap the value array and deal with the hierarchy skip so maybe we don't need that much context in that method.- Specified by:
styleNode
in interfaceISemanticNode
- Overrides:
styleNode
in classIdentifierExpression
-
refreshBoundTypes
public boolean refreshBoundTypes(int flags)
- Overrides:
refreshBoundTypes
in classIdentifierExpression
-
transformTemplate
public int transformTemplate(int ix, boolean statefulContext)
Description copied from class:JavaSemanticNode
A pass over the semantic node tree to convert template statements into layer cake statements.- Overrides:
transformTemplate
in classIdentifierExpression
-
addDependentTypes
public void addDependentTypes(java.util.Set<java.lang.Object> types, JavaSemanticNode.DepTypeCtx mode)
- Overrides:
addDependentTypes
in classIdentifierExpression
-
transformToJS
public Statement transformToJS()
- Overrides:
transformToJS
in classIdentifierExpression
-
setBindingInfo
public void setBindingInfo(BindingDirection dir, Statement dest, boolean nested)
Description copied from class:Expression
BindingDirection only set if this is a top-level binding- Overrides:
setBindingInfo
in classIdentifierExpression
-
deepCopy
public NewExpression 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 classIdentifierExpression
-
dimsToGenerateString
protected java.lang.String dimsToGenerateString()
-
toGenerateString
public java.lang.String toGenerateString()
- Overrides:
toGenerateString
in classIdentifierExpression
-
suggestCompletions
public int suggestCompletions(java.lang.String prefix, java.lang.Object currentType, ExecutionContext ctx, java.lang.String command, int cursor, java.util.Set<java.lang.String> candidates, java.lang.Object continuation, int max)
TODO: very similar to ClassValueExpression.suggestCompletions - try to share this code?- Overrides:
suggestCompletions
in classIdentifierExpression
-
addBreakpointNodes
public void addBreakpointNodes(java.util.List<ISrcStatement> res, ISrcStatement srcStatement)
Description copied from interface:ISrcStatement
Adds all of the generated statements to the resulting list, for the case where more than one fromStatement points to the same src statement. These are used to determine which statements in the generated code should cause a 'break' when the developer sets a breakpoint on this statement.- Specified by:
addBreakpointNodes
in interfaceISrcStatement
- Overrides:
addBreakpointNodes
in classIdentifierExpression
-
stop
public void stop()
- Specified by:
stop
in interfaceILifecycle
- Overrides:
stop
in classIdentifierExpression
-
applyPartialValue
public boolean applyPartialValue(java.lang.Object value)
Description copied from class:JavaSemanticNode
When Parser.enablePartialValues is set, and we do not complete parsing the input we'll have a set of errors which represent model fragments. In some cases, it would be nice to put the model together as well as possible for code hinting. This method can append fragments onto it... if so return true.- Overrides:
applyPartialValue
in classIdentifierExpression
-
isLineStatement
public boolean isLineStatement()
- Overrides:
isLineStatement
in classStatement
-
getBodyStatements
public java.util.List<Statement> getBodyStatements()
- Specified by:
getBodyStatements
in interfaceIClassBodyStatement
- Overrides:
getBodyStatements
in classArgumentsExpression
-
addNodeCompletions
public java.lang.String addNodeCompletions(JavaModel origModel, JavaSemanticNode origNode, java.lang.String extMatchPrefix, int offset, java.lang.String dummyIdentifier, java.util.Set<java.lang.String> candidates, boolean nextNameInPath, int max)
Description copied from class:JavaSemanticNode
This works like suggestCompletions but designed to conform to the requirements of IntelliJ. We don't support the live programming use case in this version and have access (possibly) to the original model and original node which most closely approximates this node which is being parsed (so we can use more context to do a better job of matching because those values are all resolved).- Overrides:
addNodeCompletions
in classIdentifierExpression
-
getChildNestingDepth
public int getChildNestingDepth()
- Specified by:
getChildNestingDepth
in interfaceISemanticNode
- Overrides:
getChildNestingDepth
in classStatement
-
-