JavaScript Development Tools
Release 3.2

org.eclipse.wst.jsdt.core.infer
Class InferEngine

java.lang.Object
  extended by org.eclipse.wst.jsdt.core.ast.ASTVisitor
      extended by 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
 InferredType ArrayType
           
 InferredType BooleanType
           
 InferredType FunctionType
           
 InferredType GlobalType
           
 InferrenceProvider inferenceProvider
           
protected  InferredType inferredGlobal
           
 InferredType NumberType
           
 InferredType ObjectType
           
protected  int passNumber
           
 InferredType StringType
           
 InferredType VoidType
           
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
InferEngine()
           
InferEngine(InferOptions inferOptions)
           
 
Method Summary
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  InferredType createAnonymousType(char[] possibleTypeName, InferredType currentType)
           
 void doInfer()
          Requests to perform type inference on provided compilation unit.
 void endVisit(IAssignment assignment)
           
 void endVisit(IFunctionDeclaration methodDeclaration)
           
 void endVisit(IObjectLiteral literal)
           
 void endVisit(IObjectLiteralField field)
           
 void endVisit(IReturnStatement returnStatement)
           
 InferredType findDefinedType(char[] className)
           
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 Currently, only SNR are supported
protected  InferredType getInferredType2(IExpression fieldReceiver)
           
 IScriptFileDeclaration getScriptFileDeclaration()
          Get the Script file this inferrence is being done on
protected  InferredType getTypeOf(IExpression expression)
           
protected  IAbstractVariableDeclaration getVariable(IExpression expression)
          Finds a Var Declaration on the context from the name represented with the expression Currently, only SNR are supported
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)
           
protected  void handleFunctionDeclarationArguments(IFunctionDeclaration methodDeclaration, IJsDoc jsdoc)
           
protected  boolean handleFunctionExpressionAssignment(IAssignment assignment)
          handle the inferrencing for an assigment whose right hand side is a function expression
protected  void handleJSDocConstructor(InferredType type, IFunctionDeclaration methodDeclaration, int nameStart)
           
protected  boolean handlePotentialType(IAssignment assignment)
           
 void initialize()
          Initializes inference engine.
 void initializeOptions(InferOptions options)
          Overriden by client who wish to update the infer options
protected  boolean isFunction(IFunctionCall messageSend, char[][] names)
           
protected  boolean isFunction(IFunctionCall messageSend, String string)
           
protected  boolean isInNamedMethod()
           
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()
           
 void setCompilationUnit(org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration scriptFileDeclaration)
          Set compilation unit for processing.
 boolean visit(IAllocationExpression allocationExpression)
           
 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, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

passNumber

protected int passNumber

inferenceProvider

public InferrenceProvider inferenceProvider

StringType

public InferredType StringType

NumberType

public InferredType NumberType

BooleanType

public InferredType BooleanType

FunctionType

public InferredType FunctionType

ArrayType

public InferredType ArrayType

VoidType

public InferredType VoidType

ObjectType

public InferredType ObjectType

GlobalType

public InferredType GlobalType

WellKnownTypes

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

inferredGlobal

protected InferredType inferredGlobal
Constructor Detail

InferEngine

public InferEngine(InferOptions inferOptions)

InferEngine

public InferEngine()
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

visit

public boolean visit(ILocalDeclaration localDeclaration)
Overrides:
visit in class ASTVisitor

visit

public boolean visit(IAssignment assignment)
Overrides:
visit in class ASTVisitor

getInferredType2

protected InferredType getInferredType2(IExpression fieldReceiver)

createAnonymousType

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

handleFunctionExpressionAssignment

protected boolean handleFunctionExpressionAssignment(IAssignment assignment)
handle the inferrencing for an assigment whose right hand side is a function expression

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

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

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,
                                             IExpression initializer)

handleFunctionCall

protected boolean handleFunctionCall(IFunctionCall messageSend)

handleFunctionCall

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

endVisit

public void endVisit(IReturnStatement returnStatement)
Overrides:
endVisit in class ASTVisitor

visit

public boolean visit(IReturnStatement returnStatement)
Overrides:
visit 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

handleJSDocConstructor

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

handleFunctionDeclarationArguments

protected void handleFunctionDeclarationArguments(IFunctionDeclaration methodDeclaration,
                                                  IJsDoc jsdoc)

visit

public boolean visit(IAllocationExpression allocationExpression)
Overrides:
visit in class ASTVisitor

endVisit

public void endVisit(IObjectLiteralField field)
Overrides:
endVisit in class ASTVisitor

isMatch

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

isFunction

protected boolean isFunction(IFunctionCall messageSend,
                             String string)

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()

getVariable

protected IAbstractVariableDeclaration getVariable(IExpression expression)
Finds a Var Declaration on the context from the name represented with the expression Currently, only SNR are supported


getFunction

protected IAbstractFunctionDeclaration getFunction(IExpression expression)
Finds a Function Declaration on the context from the name represented with the expression Currently, only SNR are supported


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)
Overriden 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 inferrence is being done on

Returns:

findDefinedType

public InferredType findDefinedType(char[] className)

changePrimitiveToObject

protected char[] changePrimitiveToObject(char[] name)

JavaScript Development Tools
Release 3.2

Copyright (c) IBM Corp. and others 2000, 2010. All Rights Reserved.