public class InferEngine extends ASTVisitor implements IInferEngine
Clients may subclass this class but should expect some breakage by future releases.
Provisional API: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.Modifier and Type | Field and Description |
---|---|
InferredType |
ArrayType
Deprecated.
use
getArrayType() |
InferredType |
BooleanType
Deprecated.
use
getBooleanType() |
static boolean |
DEBUG |
InferredType |
FunctionType
Deprecated.
|
InferredType |
GlobalType
Deprecated.
- no longer used
|
InferrenceProvider |
inferenceProvider |
protected InferredType |
inferredGlobal |
InferredType |
NumberType
Deprecated.
use
getNumberType() |
InferredType |
ObjectType
Deprecated.
use
getObjectType() |
protected int |
passNumber |
InferredType |
StringType
Deprecated.
use
getStringType() |
InferredType |
VoidType
Deprecated.
use
getVoidType() |
static org.eclipse.wst.jsdt.internal.compiler.util.HashtableOfObject |
WellKnownTypes |
ANONYMOUS_CLASS_ID, ANONYMOUS_PREFIX
Constructor and Description |
---|
InferEngine()
Constructor that uses default
InferOptions . |
InferEngine(InferOptions inferOptions)
Constructor using given
InferOptions . |
Modifier and Type | Method and Description |
---|---|
protected InferredType |
addType(char[] className) |
protected InferredType |
addType(char[] className,
boolean isDefinition)
Create a new inferred type with the given name
|
protected char[] |
changePrimitiveToObject(char[] name) |
protected char[] |
constructTypeName(IExpression expression) |
protected void |
convertAnonymousTypeToNamed(InferredType type,
char[] newTypeName)
Converts the given anonymous type to a named global type.
|
protected InferredType |
createAnonymousGlobalType(char[] varName)
Creates a global anonymous type.
|
static char[] |
createAnonymousGlobalTypeName(char[] varName)
Creates an anonymous type name from the given variable name.
|
protected InferredType |
createAnonymousType(char[] possibleTypeName,
InferredType currentType) |
protected InferredType |
createAnonymousType(IASTNode forNode,
InferredType parrentType)
Creates an anonymous type for a given node with an optional parent type.
|
protected InferredType |
createAnonymousTypeForMixin(IExpression mixInto,
InferredType parentType) |
protected static char[] |
createAnonymousTypeName(IASTNode node)
Creates an anonymous type name for the given
IASTNode
|
void |
doInfer()
Requests to perform type inference on provided compilation unit.
|
void |
endVisit(IAssignment assignment) |
void |
endVisit(IFunctionCall functionCall) |
void |
endVisit(IFunctionDeclaration methodDeclaration) |
void |
endVisit(ILocalDeclaration localDeclaration) |
void |
endVisit(IObjectLiteral literal) |
void |
endVisit(IReturnStatement returnStatement) |
protected java.lang.Object |
findDefinedMember(char[] memberName) |
InferredType |
findDefinedType(char[] className) |
protected InferredType |
getArrayType() |
protected IAssignment |
getAssignment(IExpression expression)
Finds a assignment on the context from the name represented with the expression
|
protected InferredType |
getAttributeType(char[] attName,
IExpression receiver,
boolean defineRoot) |
protected InferredType |
getBooleanType() |
protected IFunctionDeclaration |
getDefinedFunction(IExpression expression)
Get the function referenced by the expression
|
protected IAbstractFunctionDeclaration |
getFunction(IExpression expression)
Finds a Function Declaration on the context from the name represented
with the expression
Supported:
ISingleNameReference
ILocalDeclaration
|
protected InferredType |
getFunctionType() |
protected InferredType |
getInferredGlobal(boolean define) |
protected InferredType |
getInferredType2(IExpression fieldReceiver)
Deprecated.
- here for compatibility
|
protected char[] |
getName(IExpression expression)
Gets the name of the given expression.
|
protected InferredType |
getNumberType() |
protected InferredType |
getObjectType() |
protected InferredType |
getReceiverType(IExpression receiver,
boolean defineRoot)
This method is intended to take a chain of field references and
determine the type that the last field should be or is defined on.
|
IScriptFileDeclaration |
getScriptFileDeclaration()
Get the Script file this inference is being done on
|
protected InferredType |
getStringType() |
protected InferredType |
getTypeOf(IExpression expression) |
protected IAbstractVariableDeclaration |
getVariable(IExpression expression)
Finds a Var Declaration on the context from the name represented with the expression
|
protected ASTVisitor |
getVisitor(org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration compilationUnit)
Return a visitor to traverse the given compilation unit's AST.
|
protected InferredType |
getVoidType() |
protected boolean |
handleAttributeDeclaration(InferredAttribute attribute) |
protected boolean |
handleAttributeDeclaration(InferredAttribute attribute,
IExpression initializer) |
protected void |
handleConstructor(InferredType type,
IFunctionDeclaration methodDeclaration,
int start,
int end) |
protected boolean |
handleFunctionCall(IFunctionCall messageSend) |
protected boolean |
handleFunctionCall(IFunctionCall messageSend,
org.eclipse.wst.jsdt.internal.compiler.ast.LocalDeclaration assignmentExpression) |
protected void |
handleFunctionDeclarationArgument(IArgument declaredArgument,
IExpression sentArgument) |
protected void |
handleFunctionDeclarationArguments(IFunctionDeclaration methodDeclaration,
IJsDoc jsdoc) |
protected boolean |
handleFunctionExpressionAssignment(IAssignment assignment)
handle the inferencing for an assignment whose right hand side is a function expression
|
protected void |
handleJSDocConstructor(InferredType type,
IFunctionDeclaration methodDeclaration,
int nameStart) |
protected boolean |
handleLocalDeclarationExpressionType(ILocalDeclaration localDeclaration) |
protected boolean |
handlePotentialType(IAssignment assignment) |
void |
initialize()
Initializes inference engine.
|
void |
initializeOptions(InferOptions options)
Overridden by client who wish to update the infer options
|
protected boolean |
isFunction(IFunctionCall messageSend,
char[][] names) |
protected boolean |
isFunction(IFunctionCall messageSend,
java.lang.String string)
Deprecated.
not used
|
protected boolean |
isGlobal(char[] name)
Determines if the given variable name is global.
|
protected boolean |
isInNamedMethod()
Deprecated.
not used internally, will be removed
|
protected boolean |
isKnownType(char[] possibleTypeName) |
protected boolean |
isMatch(IExpression expr,
char[][] names,
int index) |
protected boolean |
isPossibleClassName(char[] name) |
protected void |
popContext() |
protected void |
populateType(InferredType type,
IObjectLiteral objLit,
boolean isStatic) |
protected void |
pushContext() |
protected void |
renameType(InferredType type,
char[] newTypeName)
Renames the given type to the given name.
|
void |
setCompilationUnit(org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration scriptFileDeclaration)
Set compilation unit for processing.
|
protected void |
setTypeOf(IExpression expression,
InferredType type)
Sets the inferred type of the given expression to the given type.
|
boolean |
visit(IAssignment assignment) |
boolean |
visit(IFunctionCall functionCall) |
boolean |
visit(IFunctionDeclaration methodDeclaration) |
boolean |
visit(ILocalDeclaration localDeclaration) |
boolean |
visit(IObjectLiteral literal) |
boolean |
visit(IReturnStatement returnStatement) |
acceptProblem, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
protected int passNumber
public static boolean DEBUG
public InferrenceProvider inferenceProvider
public InferredType StringType
getStringType()
public InferredType NumberType
getNumberType()
public InferredType BooleanType
getBooleanType()
public InferredType FunctionType
getFunctionType()
public InferredType ArrayType
getArrayType()
public InferredType VoidType
getVoidType()
public InferredType ObjectType
getObjectType()
public InferredType GlobalType
public static org.eclipse.wst.jsdt.internal.compiler.util.HashtableOfObject WellKnownTypes
protected InferredType inferredGlobal
public InferEngine()
Constructor that uses default InferOptions
.
public InferEngine(InferOptions inferOptions)
Constructor using given InferOptions
.
inferOptions
- to create this infer engine withpublic void initialize()
IInferEngine
#setCompilationUnit()
to let engine prepare for next compilation unit.initialize
in interface IInferEngine
public void setCompilationUnit(org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration scriptFileDeclaration)
IInferEngine
setCompilationUnit
in interface IInferEngine
public boolean visit(IFunctionCall functionCall)
visit
in class ASTVisitor
protected void handleFunctionDeclarationArgument(IArgument declaredArgument, IExpression sentArgument)
public boolean visit(ILocalDeclaration localDeclaration)
visit
in class ASTVisitor
public void endVisit(ILocalDeclaration localDeclaration)
endVisit
in class ASTVisitor
ASTVisitor.endVisit(org.eclipse.wst.jsdt.core.ast.ILocalDeclaration)
public boolean visit(IAssignment assignment)
visit
in class ASTVisitor
protected InferredType createAnonymousType(char[] possibleTypeName, InferredType currentType)
protected InferredType createAnonymousType(IASTNode forNode, InferredType parrentType)
Creates an anonymous type for a given node with an optional parent type.
forNode
- the node to create the anonymous type for, the text range of
this node will be used to create the anonymous type nameparrentType
- optional parent type of the new anonymous typeprotected InferredType createAnonymousGlobalType(char[] varName)
Creates a global anonymous type.
varName
- name of the global variable to create the global anonymous type forprotected static char[] createAnonymousTypeName(IASTNode node)
Creates an anonymous type name for the given IASTNode
node
- create the anonymous type name off the location of this nodepublic static char[] createAnonymousGlobalTypeName(char[] varName)
Creates an anonymous type name from the given variable name.
varName
- to use when creating the anonymous type nameprotected boolean handleFunctionExpressionAssignment(IAssignment assignment)
the
- assignment AST nodeprotected boolean handleLocalDeclarationExpressionType(ILocalDeclaration localDeclaration)
assignment
- protected boolean handlePotentialType(IAssignment assignment)
assignment
- protected IFunctionDeclaration getDefinedFunction(IExpression expression)
expression
- AST nodeprotected void setTypeOf(IExpression expression, InferredType type)
Sets the inferred type of the given expression to the given type. Any existing inferred type is overridden. If the given expression is not supported by this method then it is a no op.
Currently supports:
ISingleNameReference
FieldReference
- if it can resolve everything it needs toIObjectLiteral
IThisReference
expression
- to set the inferred type fortype
- inferred type to set on the given expressionprotected InferredType getTypeOf(IExpression expression)
protected void populateType(InferredType type, IObjectLiteral objLit, boolean isStatic)
public void endVisit(IAssignment assignment)
endVisit
in class ASTVisitor
protected boolean handleAttributeDeclaration(InferredAttribute attribute)
protected boolean handleAttributeDeclaration(InferredAttribute attribute, IExpression initializer)
protected boolean handleFunctionCall(IFunctionCall messageSend)
protected boolean handleFunctionCall(IFunctionCall messageSend, org.eclipse.wst.jsdt.internal.compiler.ast.LocalDeclaration assignmentExpression)
public boolean visit(IReturnStatement returnStatement)
visit
in class ASTVisitor
public void endVisit(IReturnStatement returnStatement)
endVisit
in class ASTVisitor
ASTVisitor.endVisit(org.eclipse.wst.jsdt.core.ast.IReturnStatement)
public void endVisit(IFunctionCall functionCall)
endVisit
in class ASTVisitor
public void endVisit(IFunctionDeclaration methodDeclaration)
endVisit
in class ASTVisitor
public boolean visit(IFunctionDeclaration methodDeclaration)
visit
in class ASTVisitor
protected void handleConstructor(InferredType type, IFunctionDeclaration methodDeclaration, int start, int end)
protected void handleJSDocConstructor(InferredType type, IFunctionDeclaration methodDeclaration, int nameStart)
protected void handleFunctionDeclarationArguments(IFunctionDeclaration methodDeclaration, IJsDoc jsdoc)
protected void renameType(InferredType type, char[] newTypeName)
Renames the given type to the given name. If there is a constructor on the type that is also renamed.
type
- InferredType
to renamenewTypeName
- new type name for the given InferredType
protected void convertAnonymousTypeToNamed(InferredType type, char[] newTypeName)
Converts the given anonymous type to a named global type. If the given type is not anonymous then this is a no-op.
type
- anonymous InferredType
to namenewTypeName
- new type name for the given anonymous InferredType
InferredType.isAnonymous
protected boolean isMatch(IExpression expr, char[][] names, int index)
protected boolean isFunction(IFunctionCall messageSend, java.lang.String string)
protected boolean isFunction(IFunctionCall messageSend, char[][] names)
public void doInfer()
IInferEngine
IInferEngine.setCompilationUnit(CompilationUnitDeclaration)
doInfer
in interface IInferEngine
protected InferredType addType(char[] className)
protected InferredType addType(char[] className, boolean isDefinition)
className
- the name of the inferred typeisDefinition
- true if this unit defines the typeprotected final void pushContext()
protected final void popContext()
protected final boolean isInNamedMethod()
protected IAbstractVariableDeclaration getVariable(IExpression expression)
protected IAssignment getAssignment(IExpression expression)
protected IAbstractFunctionDeclaration getFunction(IExpression expression)
Finds a Function Declaration on the context from the name represented with the expression
Supported:
protected InferredType getInferredType2(IExpression fieldReceiver)
protected boolean isKnownType(char[] possibleTypeName)
protected final char[] constructTypeName(IExpression expression)
public boolean visit(IObjectLiteral literal)
visit
in class ASTVisitor
public void endVisit(IObjectLiteral literal)
endVisit
in class ASTVisitor
public void initializeOptions(InferOptions options)
initializeOptions
in interface IInferEngine
options
- protected boolean isPossibleClassName(char[] name)
public IScriptFileDeclaration getScriptFileDeclaration()
public InferredType findDefinedType(char[] className)
protected java.lang.Object findDefinedMember(char[] memberName)
protected char[] changePrimitiveToObject(char[] name)
protected InferredType getStringType()
InferredType
for the String typeprotected InferredType getNumberType()
InferredType
for the Number typeprotected InferredType getBooleanType()
InferredType
for the Boolean typeprotected InferredType getFunctionType()
InferredType
for the Function typeprotected InferredType getArrayType()
InferredType
for the Array typeprotected InferredType getVoidType()
InferredType
for the Void typeprotected InferredType getObjectType()
InferredType
for the Object typeprotected char[] getName(IExpression expression)
expression
- IExpression
to get the name forIExpression
or null
if none
can be determinedprotected InferredType getReceiverType(IExpression receiver, boolean defineRoot)
This method is intended to take a chain of field references and determine the type that the last field should be or is defined on.
EX: foo.bar.awesome.crazy = 42;
If that is the entirety of the file and the receiver of the
foo.bar.awesome.crazy
statement is given to this function,
so the foo.bar.awesome
part, then this function will
create a foo
field on the global inferred type and and
then give it a type that has a bar
field, and then give
the bar
field a type with an awesome
field
and then finally return a new type assigned to the awesome
field such that some other code can deal with assigning the
crazy
field with whatever type is on the right hand side
of the assignment.
receiver
- the receiver side of a FieldReference
to get the
type fordefineRoot
- Has two purposes. If the root of the field reference has no
type and this is true
a type will be created.
If the root of this field reference does not have a type and
this is false
no root type will be created an
thus no type will be returned by this method. When there is
a root type if this argument is true
then the
type on the root will be marked as a definition, else if
false
the root will not be marked as a
definition.InferredType
associated with the given receiver side of
a FieldReference
protected InferredType getInferredGlobal(boolean define)
define
- true
to define the inferred global type if one
is not yet defined, false
otherwisenull
if none is yet
defined and define
was given as false
protected boolean isGlobal(char[] name)
Determines if the given variable name is global.
name
- determine if there is a global variable with this nametrue
if there is a global variable with this name,
false
otherwiseprotected InferredType createAnonymousTypeForMixin(IExpression mixInto, InferredType parentType)
protected InferredType getAttributeType(char[] attName, IExpression receiver, boolean defineRoot)
protected ASTVisitor getVisitor(org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration compilationUnit)
null
Copyright (c) IBM Corp. and others 2000, 2016. All Rights Reserved.