org.eclipse.wst.jsdt.core.infer

## Class InferEngine

- java.lang.Object
- - org.eclipse.wst.jsdt.core.ast.ASTVisitor
  - - org.eclipse.wst.jsdt.core.infer.InferEngine

All Implemented Interfaces:
  IInferEngine

    public class InferEngine
    extends ASTVisitor
    implements IInferEngine

The default inference engine.

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.

### Field Summary

Fields
`InferredType` `ArrayType` Deprecated. use `getArrayType()`
`InferredType` `BooleanType` Deprecated. use `getBooleanType()`
`static boolean` `DEBUG`
`InferredType` `FunctionType` Deprecated. use `getFunctionType()`
`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`

### Fields inherited from interface org.eclipse.wst.jsdt.core.infer.IInferEngine

`ANONYMOUS_CLASS_ID, ANONYMOUS_PREFIX`

### Constructor Summary

Constructors
Constructor and Description
`InferEngine()` Constructor that uses default `InferOptions`.
`InferEngine(InferOptions inferOptions)` Constructor using given `InferOptions`.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
`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)`

### Methods inherited from class org.eclipse.wst.jsdt.core.ast.ASTVisitor

`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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### passNumber

    protected int passNumber

#### DEBUG

    public static boolean DEBUG

#### inferenceProvider

    public InferrenceProvider inferenceProvider

#### StringType

    public InferredType StringType

Deprecated. use `getStringType()`

#### NumberType

    public InferredType NumberType

Deprecated. use `getNumberType()`

#### BooleanType

    public InferredType BooleanType

Deprecated. use `getBooleanType()`

#### FunctionType

    public InferredType FunctionType

Deprecated. use `getFunctionType()`

#### ArrayType

    public InferredType ArrayType

Deprecated. use `getArrayType()`

#### VoidType

    public InferredType VoidType

Deprecated. use `getVoidType()`

#### ObjectType

    public InferredType ObjectType

Deprecated. use `getObjectType()`

#### GlobalType

    public InferredType GlobalType

Deprecated. - no longer used

#### WellKnownTypes

    public static org.eclipse.wst.jsdt.internal.compiler.util.HashtableOfObject WellKnownTypes

#### inferredGlobal

    protected InferredType inferredGlobal

### Constructor Detail

#### InferEngine

    public InferEngine()

Constructor that uses default `InferOptions`.

#### InferEngine

    public InferEngine(InferOptions inferOptions)

Constructor using given `InferOptions`.

Parameters:
  `inferOptions` - to create this infer engine with

### Method Detail

#### initialize

    public void initialize()

Description copied from interface: `IInferEngine`
Initializes inference engine. Always called before `#setCompilationUnit()` to let engine prepare for next compilation unit.

Specified by:
  `initialize` in interface `IInferEngine`

#### setCompilationUnit

    public void setCompilationUnit(org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration scriptFileDeclaration)

Description copied from interface: `IInferEngine`
Set compilation unit for processing.

Specified by:
  `setCompilationUnit` in interface `IInferEngine`

#### visit

    public boolean visit(IFunctionCall functionCall)

Overrides:
  `visit` in class `ASTVisitor`

#### handleFunctionDeclarationArgument

    protected void handleFunctionDeclarationArgument(IArgument declaredArgument,
                                                     IExpression sentArgument)

#### visit

    public boolean visit(ILocalDeclaration localDeclaration)

Overrides:
  `visit` in class `ASTVisitor`

#### endVisit

    public void endVisit(ILocalDeclaration localDeclaration)

Overrides:
  `endVisit` in class `ASTVisitor`
See Also:
  `ASTVisitor.endVisit(org.eclipse.wst.jsdt.core.ast.ILocalDeclaration)`

#### visit

    public boolean visit(IAssignment assignment)

Overrides:
  `visit` in class `ASTVisitor`

#### createAnonymousType

    protected InferredType createAnonymousType(char[] possibleTypeName,
                                               InferredType currentType)

#### createAnonymousType

    protected InferredType createAnonymousType(IASTNode forNode,
                                               InferredType parrentType)

Creates an anonymous type for a given node with an optional parent type.

Parameters:
  `forNode` - the node to create the anonymous type for, the text range of this node will be used to create the anonymous type name
  `parrentType` - optional parent type of the new anonymous type
Returns:
  a new anonymous type

#### createAnonymousGlobalType

    protected InferredType createAnonymousGlobalType(char[] varName)

Creates a global anonymous type.

Parameters:
  `varName` - name of the global variable to create the global anonymous type for
Returns:
  a global anonymous type created from for the given global variable name

#### createAnonymousTypeName

    protected static char[] createAnonymousTypeName(IASTNode node)

Creates an anonymous type name for the given `IASTNode`

Parameters:
  `node` - create the anonymous type name off the location of this node
Returns:
  an anonymous type name based off the given nodes location

#### createAnonymousGlobalTypeName

    public static char[] createAnonymousGlobalTypeName(char[] varName)

Creates an anonymous type name from the given variable name.

Parameters:
  `varName` - to use when creating the anonymous type name
Returns:

#### handleFunctionExpressionAssignment

    protected boolean handleFunctionExpressionAssignment(IAssignment assignment)

handle the inferencing for an assignment whose right hand side is a function expression

Parameters:
  `the` - assignment AST node
Returns:
  true if handled

#### handleLocalDeclarationExpressionType

    protected boolean handleLocalDeclarationExpressionType(ILocalDeclaration localDeclaration)

Parameters:
  `assignment` -
Returns:
  whether a type was not created for this assignment
Since:
  1.3

#### handlePotentialType

    protected boolean handlePotentialType(IAssignment assignment)

Parameters:
  `assignment` -
Returns:
  whether a type was not created for this assignment

#### getDefinedFunction

    protected IFunctionDeclaration getDefinedFunction(IExpression expression)

Get the function referenced by the expression

Parameters:
  `expression` - AST node
Returns:
  the function or null

#### setTypeOf

    protected 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 to
- `IObjectLiteral`
- `IThisReference`

Parameters:
  `expression` - to set the inferred type for
  `type` - inferred type to set on the given expression

#### getTypeOf

    protected InferredType getTypeOf(IExpression expression)

#### populateType

    protected void populateType(InferredType type,
                                IObjectLiteral objLit,
                                boolean isStatic)

#### endVisit

    public void endVisit(IAssignment assignment)

Overrides:
  `endVisit` in class `ASTVisitor`

#### handleAttributeDeclaration

    protected boolean handleAttributeDeclaration(InferredAttribute attribute)

#### handleAttributeDeclaration

    protected boolean handleAttributeDeclaration(InferredAttribute attribute,
                                                 IExpression initializer)

#### handleFunctionCall

    protected boolean handleFunctionCall(IFunctionCall messageSend)

#### handleFunctionCall

    protected boolean handleFunctionCall(IFunctionCall messageSend,
                                         org.eclipse.wst.jsdt.internal.compiler.ast.LocalDeclaration assignmentExpression)

#### visit

    public boolean visit(IReturnStatement returnStatement)

Overrides:
  `visit` in class `ASTVisitor`

#### endVisit

    public void endVisit(IReturnStatement returnStatement)

Overrides:
  `endVisit` in class `ASTVisitor`
See Also:
  `ASTVisitor.endVisit(org.eclipse.wst.jsdt.core.ast.IReturnStatement)`

#### endVisit

    public void endVisit(IFunctionCall functionCall)

Overrides:
  `endVisit` in class `ASTVisitor`

#### endVisit

    public void endVisit(IFunctionDeclaration methodDeclaration)

Overrides:
  `endVisit` in class `ASTVisitor`

#### visit

    public boolean visit(IFunctionDeclaration methodDeclaration)

Overrides:
  `visit` in class `ASTVisitor`

#### handleConstructor

    protected void handleConstructor(InferredType type,
                                     IFunctionDeclaration methodDeclaration,
                                     int start,
                                     int end)

#### handleJSDocConstructor

    protected void handleJSDocConstructor(InferredType type,
                                          IFunctionDeclaration methodDeclaration,
                                          int nameStart)

#### handleFunctionDeclarationArguments

    protected void handleFunctionDeclarationArguments(IFunctionDeclaration methodDeclaration,
                                                      IJsDoc jsdoc)

#### renameType

    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.

Parameters:
  `type` - `InferredType` to rename
  `newTypeName` - new type name for the given `InferredType`

#### convertAnonymousTypeToNamed

    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.

Parameters:
  `type` - anonymous `InferredType` to name
  `newTypeName` - new type name for the given anonymous `InferredType`
See Also:
  `InferredType.isAnonymous`

#### isMatch

    protected boolean isMatch(IExpression expr,
                              char[][] names,
                              int index)

#### isFunction

    protected boolean isFunction(IFunctionCall messageSend,
                                 java.lang.String string)

Deprecated. not used

#### isFunction

    protected boolean isFunction(IFunctionCall messageSend,
                                 char[][] names)

#### doInfer

    public void doInfer()

Description copied from interface: `IInferEngine`
Requests to perform type inference on provided compilation unit. Always called after `IInferEngine.setCompilationUnit(CompilationUnitDeclaration)`

Specified by:
  `doInfer` in interface `IInferEngine`

#### addType

    protected InferredType addType(char[] className)

#### addType

    protected InferredType addType(char[] className,
                                   boolean isDefinition)

Create a new inferred type with the given name

Parameters:
  `className` - the name of the inferred type
  `isDefinition` - true if this unit defines the type
Returns:
  new Inferred type

#### pushContext

    protected final void pushContext()

#### popContext

    protected final void popContext()

#### isInNamedMethod

    protected final boolean isInNamedMethod()

Deprecated. not used internally, will be removed

#### getVariable

    protected IAbstractVariableDeclaration getVariable(IExpression expression)

Finds a Var Declaration on the context from the name represented with the expression

#### getAssignment

    protected IAssignment getAssignment(IExpression expression)

Finds a assignment on the context from the name represented with the expression

#### getFunction

    protected IAbstractFunctionDeclaration getFunction(IExpression expression)

Finds a Function Declaration on the context from the name represented with the expression

Supported:

- `ISingleNameReference`
- `ILocalDeclaration`

#### getInferredType2

    protected InferredType getInferredType2(IExpression fieldReceiver)

Deprecated. - here for compatibility

#### isKnownType

    protected boolean isKnownType(char[] possibleTypeName)

#### constructTypeName

    protected final char[] constructTypeName(IExpression expression)

#### visit

    public boolean visit(IObjectLiteral literal)

Overrides:
  `visit` in class `ASTVisitor`

#### endVisit

    public void endVisit(IObjectLiteral literal)

Overrides:
  `endVisit` in class `ASTVisitor`

#### initializeOptions

    public void initializeOptions(InferOptions options)

Overridden by client who wish to update the infer options

Specified by:
  `initializeOptions` in interface `IInferEngine`
Parameters:
  `options` -

#### isPossibleClassName

    protected boolean isPossibleClassName(char[] name)

#### getScriptFileDeclaration

    public IScriptFileDeclaration getScriptFileDeclaration()

Get the Script file this inference is being done on

Returns:

#### findDefinedType

    public InferredType findDefinedType(char[] className)

#### findDefinedMember

    protected java.lang.Object findDefinedMember(char[] memberName)

#### changePrimitiveToObject

    protected char[] changePrimitiveToObject(char[] name)

#### getStringType

    protected InferredType getStringType()

Returns:
  `InferredType` for the String type

#### getNumberType

    protected InferredType getNumberType()

Returns:
  `InferredType` for the Number type

#### getBooleanType

    protected InferredType getBooleanType()

Returns:
  `InferredType` for the Boolean type

#### getFunctionType

    protected InferredType getFunctionType()

Returns:
  `InferredType` for the Function type

#### getArrayType

    protected InferredType getArrayType()

Returns:
  `InferredType` for the Array type

#### getVoidType

    protected InferredType getVoidType()

Returns:
  `InferredType` for the Void type

#### getObjectType

    protected InferredType getObjectType()

Returns:
  `InferredType` for the Object type

#### getName

    protected char[] getName(IExpression expression)

Gets the name of the given expression.

Supported:

- `ISingleNameReference`
- `IFieldReference`
- `IAssignment`

Parameters:
  `expression` - `IExpression` to get the name for
Returns:
  name of the given `IExpression` or `null` if none can be determined

#### getReceiverType

    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.

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.

Parameters:
  `receiver` - the receiver side of a `FieldReference` to get the type for
  `defineRoot` - 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.
Returns:
  `InferredType` associated with the given receiver side of a `FieldReference`

#### getInferredGlobal

    protected InferredType getInferredGlobal(boolean define)

Parameters:
  `define` - `true` to define the inferred global type if one is not yet defined, `false` otherwise
Returns:
  inferred global type, or `null` if none is yet defined and `define` was given as `false`

#### isGlobal

    protected boolean isGlobal(char[] name)

Determines if the given variable name is global.

Parameters:
  `name` - determine if there is a global variable with this name
Returns:
  `true` if there is a global variable with this name, `false` otherwise

#### createAnonymousTypeForMixin

    protected InferredType createAnonymousTypeForMixin(IExpression mixInto,
                                                       InferredType parentType)

#### getAttributeType

    protected InferredType getAttributeType(char[] attName,
                                            IExpression receiver,
                                            boolean defineRoot)

#### getVisitor

    protected ASTVisitor getVisitor(org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration compilationUnit)

Return a visitor to traverse the given compilation unit's AST. Subclasses may override to provide a more minimal implementations while retaining use of utility methods from the base InferEngine.

Returns:
  a visitor for use with the given compilation unit and current engine states, or `null`