edu.rice.cs.javalanglevels
Class TypeChecker

java.lang.Object
  extended by edu.rice.cs.javalanglevels.tree.JExpressionIFDepthFirstVisitor<TypeData>
      extended by edu.rice.cs.javalanglevels.TypeChecker
All Implemented Interfaces:
JExpressionIFVisitor<TypeData>
Direct Known Subclasses:
SpecialTypeChecker

public class TypeChecker
extends JExpressionIFDepthFirstVisitor<TypeData>
implements JExpressionIFVisitor<TypeData>

Does Type Checking that is not dependent on the enclosing body. Also does top level type checking. Common to all langauge levels.


Nested Class Summary
static class TypeChecker.TypeCheckerTest
          Test the methods defined in the above class.
 
Field Summary
static ModifiersAndVisibility _abstractMav
           
static ModifiersAndVisibility _finalMav
           
static ModifiersAndVisibility _finalPublicMav
           
protected static Log _log
           
static ModifiersAndVisibility _packageMav
           
static ModifiersAndVisibility _privateMav
           
static ModifiersAndVisibility _protectedMav
           
static ModifiersAndVisibility _publicAbstractMav
           
static ModifiersAndVisibility _publicMav
           
static ModifiersAndVisibility _publicStaticMav
           
static SourceInfo NONE
           
static NullLiteral NULL_LITERAL
           
 
Constructor Summary
TypeChecker(java.io.File file, java.lang.String packageName, java.util.LinkedList<Pair<java.lang.String,JExpressionIF>> errors, Symboltable symbolTable, java.util.LinkedList<java.lang.String> importedFiles, java.util.LinkedList<java.lang.String> importedPackages)
          The normal constructor.
TypeChecker(java.io.File file, java.lang.String packageName, java.util.LinkedList<java.lang.String> importedFiles, java.util.LinkedList<java.lang.String> importedPackages)
          Called by the subclasses.
 
Method Summary
protected static void _addError(java.lang.String message, JExpressionIF that)
          Adds an error pair consisting of the specified String message and JExpression.
protected  void _checkAbstractMethods(SymbolData sd, JExpression classDef)
          The method will add an error for each abstract method in the current SymbolData's inheritance hierarchy that does not have a concrete implementation.
protected  Data _getData()
          The top level type checker does not have a data
protected  Pair<java.util.LinkedList<MethodData>,java.util.LinkedList<MethodData>> _getMatchingMethods(java.lang.String methodName, SymbolData enclosingSD, InstanceData[] arguments, JExpression jexpr, boolean isConstructor, SymbolData thisSD)
          Finds and returns all matching methods.
protected static boolean _isAssignableFrom(SymbolData sdLeft, SymbolData sdRight)
          Return whether the value on the right can be assigned to the value on the left.
protected  boolean _isAssignableFromWithoutAutoboxing(SymbolData sdLeft, SymbolData sdRight)
          Return whether the value on the right can be assigned to the value on the left.
protected  MethodData _lookupMethod(java.lang.String methodName, SymbolData enclosingSD, InstanceData[] arguments, JExpression jexpr, java.lang.String errorMsg, boolean isConstructor, SymbolData thisSD)
          Finds which SymbolData this method is in, beginning at this SymbolData and recursively visiting super classes.
protected  MethodData _lookupMethodHelper(java.lang.String methodName, SymbolData enclosingSD, InstanceData[] arguments, JExpression jexpr, boolean isConstructor, SymbolData thisSD)
          Pass a default value
protected  MethodData _lookupMethodHelper(java.lang.String methodName, SymbolData enclosingSD, InstanceData[] arguments, JExpression jexpr, boolean isConstructor, SymbolData thisSD, java.util.LinkedList<MethodData> matchingMethods)
          Finds which SymbolData this method is in, beginning at this SymbolData and recursively visiting super classes.
 boolean assertFound(TypeData type, JExpressionIF expression)
          If type is a PackageData, then it could not be resolved.
 boolean assertInstanceType(TypeData type, java.lang.String errorMsg, JExpression expression)
          Return true iff type is an instance type.
static boolean checkAccess(JExpression piece, ModifiersAndVisibility mav, java.lang.String name, SymbolData enclosingSD, SymbolData thisSD, java.lang.String dataType)
          Checks that the method is accessible given the SymbolData it's in and the current SymbolData.
static boolean checkAccess(JExpression piece, ModifiersAndVisibility mav, java.lang.String name, SymbolData enclosingSD, SymbolData thisSD, java.lang.String dataType, boolean addError)
          Determines if thisSD can reference specified name defined in enclosingSD.
static boolean checkAccess(ModifiersAndVisibility mav, SymbolData enclosingSD, SymbolData thisSD)
          Call this version when you don't want to add an error--only take in what is necessary to do the check, give default values for anything that will not be used.
protected  boolean checkForCyclicInheritance(SymbolData sd, java.util.LinkedList<SymbolData> hierarchy, TypeDefBase tdb)
          Checks for cyclic inheritance by traversing sd's list of superclasses and interfaces and checking if we've seen them before.
 java.util.LinkedList<VariableData> cloneVariableDataList(java.util.LinkedList<VariableData> vars)
          Create a clone of the linked list of Variable Data.
protected  TypeData defaultCase(JExpressionIF that)
          This method is called by default from cases that do not override forCASEOnly.
protected static SymbolData defineTestCaseClass()
          Adds an appropriate definition of junit.framework.TestCase to symbolTable.
 TypeData forBlockOnly(Block that, TypeData[] statementsRes)
           
 TypeData forBreakStatementOnly(BreakStatement that)
           
 TypeData forCastExpression(CastExpression that)
          Visit the type of the cast expression as well as the value being cast
 TypeData forClassDef(ClassDef that)
          Do what is necessary to handle a class def
 TypeData forClassDefOnly(ClassDef that, TypeData mavRes, TypeData nameRes, TypeData[] typeParametersRes, TypeData superRes, TypeData[] interfacesRes, TypeData bodyRes)
           
 TypeData forClassImportStatement(ClassImportStatement that)
          Retrieve the class being imported from the Symbol table, and make sure it is public.
 TypeData forConcreteMethodDefOnly(ConcreteMethodDef that, TypeData mavRes, TypeData[] typeParamsRes, TypeData resRes, TypeData nameRes, TypeData paramsRes, TypeData[] throwsRes, TypeData bodyRes)
           
 TypeData forContinueStatementOnly(ContinueStatement that)
           
 TypeData forExpressionStatementOnly(ExpressionStatement that, TypeData exprRes)
           
 TypeData forInnerClassDefOnly(InnerClassDef that, TypeData mavRes, TypeData nameRes, TypeData[] typeParamRes, TypeData superClassRes, TypeData[] interfacesRes, TypeData bodyRes)
           
 TypeData forInnerInterfaceDefOnly(InnerInterfaceDef that, TypeData mavRes, TypeData nameRes, TypeData[] typeParamRes, TypeData[] superinterfacesRes, TypeData bodyRes)
           
 TypeData forInstanceInitializerOnly(InstanceInitializer that, TypeData codeRes)
           
 TypeData forInterfaceDef(InterfaceDef that)
          Do everything necessary to handle an interface
 TypeData forInterfaceDefOnly(InterfaceDef that, TypeData mavRes, TypeData nameRes, TypeData[] typeParamRes, TypeData[] superinterfacesRes, TypeData bodyRes)
           
 TypeData forLabeledStatementOnly(LabeledStatement that, TypeData statementRes)
           
 TypeData forMethodDefOnly(MethodDef that, TypeData mavRes, TypeData[] typeParamsRes, TypeData resRes, TypeData nameRes, TypeData paramsRes, TypeData[] throwsRes)
           
 TypeData forPackageStatement(PackageStatement that)
          Make sure that the package being imported does not conflict with another class in the symbol table, since we will not allow a package to be imported if it has the same name as a class.
 TypeData forPrimitiveType(PrimitiveType that)
          Process an instance of PrimitiveType.
 TypeData forReturnStatementOnly(ReturnStatement that)
           
 TypeData forStaticInitializerOnly(StaticInitializer that, TypeData codeRes)
           
 TypeData forSwitchStatementOnly(SwitchStatement that, TypeData testRes, TypeData[] casesRes)
           
 TypeData forTryCatchStatementOnly(TryCatchStatement that, TypeData tryBlockRes, TypeData[] catchBlocksRes)
           
protected  SymbolData getCommonSuperTypeBaseCase(SymbolData sdLeft, SymbolData sdRight)
          Returns the common super type of the two types provided.
static VariableData getFieldOrVariable(java.lang.String text, Data data, SymbolData thisSD, JExpression piece)
          Return the field or variable with the name text inside of data.
static VariableData getFieldOrVariable(java.lang.String text, Data data, SymbolData thisSD, JExpression piece, java.util.LinkedList<VariableData> vars)
           
static VariableData getFieldOrVariable(java.lang.String text, Data data, SymbolData thisSD, JExpression piece, java.util.LinkedList<VariableData> vars, boolean shouldRecur)
           
static VariableData getFieldOrVariable(java.lang.String text, Data data, SymbolData thisSD, JExpression piece, java.util.LinkedList<VariableData> vars, boolean shouldRecur, boolean addError)
          This method checks if the identifier called text is a field or variable visible from the context of the param "data" and is accessible from the context of thisSD.
protected  java.lang.String getQualifiedClassName(java.lang.String className)
          The Qualified Class Name is the package, followed by a dot, followed by the rest of the class name.
 SymbolData getSymbolData(boolean giveAmbigException, java.lang.String className, Data enclosingData, JExpression jexpr, boolean giveException)
          Returns the SymbolData corresponding to the name className.
 SymbolData getSymbolData(java.lang.String className, Data enclosingData, JExpression jexpr)
          Returns the SymbolData corresponding to the name className.
 SymbolData getSymbolData(java.lang.String className, Data enclosingData, JExpression jexpr, boolean giveException)
          Call the next version of GetSymbolData, but pass it giveException as the flag for whether or not to give ambigException.
 SymbolData getSymbolData(java.lang.String className, JExpression jexpr, boolean giveException, boolean runnableNotOkay)
          Returns the SymbolData corresponding to the name className, assuming that className does not refer to an unqualified or partially-qualified inner class.
protected  TypeData[] makeArrayOfRetType(int len)
          Return a TypeData array of the specified size.
protected  boolean notRightPackage(SymbolData sd)
          Return false if the symbolData is in the wrong package.
 
Methods inherited from class edu.rice.cs.javalanglevels.tree.JExpressionIFDepthFirstVisitor
forAbstractMethodDef, forAbstractMethodDefOnly, forAndExpression, forAndExpressionOnly, forAnonymousClassInstantiationOnly, forArrayAccess, forArrayAccessOnly, forArrayInitializer, forArrayInitializerOnly, forArrayInstantiationOnly, forArrayType, forArrayTypeOnly, forAssignmentExpressionOnly, forBinaryExpressionOnly, forBitwiseAndAssignmentExpression, forBitwiseAndAssignmentExpressionOnly, forBitwiseAndExpression, forBitwiseAndExpressionOnly, forBitwiseAssignmentExpressionOnly, forBitwiseBinaryExpressionOnly, forBitwiseNotExpression, forBitwiseNotExpressionOnly, forBitwiseOrAssignmentExpression, forBitwiseOrAssignmentExpressionOnly, forBitwiseOrExpression, forBitwiseOrExpressionOnly, forBitwiseXorAssignmentExpression, forBitwiseXorAssignmentExpressionOnly, forBitwiseXorExpression, forBitwiseXorExpressionOnly, forBlock, forBlockOnly, forBodyOnly, forBooleanExpressionOnly, forBooleanLiteral, forBooleanLiteralOnly, forBracedBody, forBracedBodyOnly, forCastExpressionOnly, forCatchBlock, forCatchBlockOnly, forCharLiteral, forCharLiteralOnly, forClassImportStatementOnly, forClassInstantiationOnly, forClassLiteral, forClassLiteralOnly, forClassOrInterfaceType, forClassOrInterfaceTypeOnly, forComparisonExpressionOnly, forComplexAnonymousClassInstantiation, forComplexAnonymousClassInstantiationOnly, forComplexInitializedArrayInstantiation, forComplexInitializedArrayInstantiationOnly, forComplexMethodInvocation, forComplexMethodInvocationOnly, forComplexNamedClassInstantiation, forComplexNamedClassInstantiationOnly, forComplexNameReference, forComplexNameReferenceOnly, forComplexSuperConstructorInvocation, forComplexSuperConstructorInvocationOnly, forComplexSuperReference, forComplexSuperReferenceOnly, forComplexThisConstructorInvocation, forComplexThisConstructorInvocationOnly, forComplexThisReference, forComplexThisReferenceOnly, forComplexUninitializedArrayInstantiation, forComplexUninitializedArrayInstantiationOnly, forCompoundWord, forCompoundWordOnly, forConcreteMethodDef, forConcreteMethodDefOnly, forConditionalExpression, forConditionalExpressionOnly, forConstructorDef, forConstructorDefOnly, forDefaultCase, forDefaultCaseOnly, forDimensionExpressionList, forDimensionExpressionListOnly, forDivideAssignmentExpression, forDivideAssignmentExpressionOnly, forDivideExpression, forDivideExpressionOnly, forDoStatement, forDoStatementOnly, forDoubleLiteral, forDoubleLiteralOnly, forEmptyExpression, forEmptyExpressionOnly, forEmptyForCondition, forEmptyForConditionOnly, forEmptyStatement, forEmptyStatementOnly, forEqualityExpressionOnly, forEqualsExpression, forEqualsExpressionOnly, forExpressionListOnly, forExpressionOnly, forExpressionStatement, forFloatLiteral, forFloatLiteralOnly, forFormalParameter, forFormalParameterOnly, forForStatement, forForStatementOnly, forFunctionInvocationOnly, forGreaterThanExpression, forGreaterThanExpressionOnly, forGreaterThanOrEqualExpression, forGreaterThanOrEqualExpressionOnly, forIfThenElseStatement, forIfThenElseStatementOnly, forIfThenStatement, forIfThenStatementOnly, forImportStatementOnly, forIncrementExpressionOnly, forInitializedArrayInstantiationOnly, forInitializedVariableDeclarator, forInitializedVariableDeclaratorOnly, forInitializerOnly, forInnerClassDef, forInnerInterfaceDef, forInstanceInitializer, forInstanceofExpression, forInstanceofExpressionOnly, forInstantiationOnly, forIntegerLiteral, forIntegerLiteralOnly, forJExpressionOnly, forLabeledBreakStatement, forLabeledBreakStatementOnly, forLabeledCase, forLabeledCaseOnly, forLabeledContinueStatement, forLabeledContinueStatementOnly, forLabeledStatement, forLabeledStatementOnly, forLeftShiftAssignmentExpression, forLeftShiftAssignmentExpressionOnly, forLeftShiftExpression, forLeftShiftExpressionOnly, forLessThanExpression, forLessThanExpressionOnly, forLessThanOrEqualExpression, forLessThanOrEqualExpressionOnly, forLexicalLiteralOnly, forLongLiteral, forLongLiteralOnly, forMemberType, forMemberTypeOnly, forMethodDefOnly, forMethodInvocationOnly, forMinusAssignmentExpression, forMinusAssignmentExpressionOnly, forMinusExpression, forMinusExpressionOnly, forModAssignmentExpression, forModAssignmentExpressionOnly, forModExpression, forModExpressionOnly, forModifiersAndVisibility, forModifiersAndVisibilityOnly, forMultiplyAssignmentExpression, forMultiplyAssignmentExpressionOnly, forMultiplyExpression, forMultiplyExpressionOnly, forNamedClassInstantiationOnly, forNameReferenceOnly, forNegativeExpression, forNegativeExpressionOnly, forNegativePostfixIncrementExpression, forNegativePostfixIncrementExpressionOnly, forNegativePrefixIncrementExpression, forNegativePrefixIncrementExpressionOnly, forNoOpExpression, forNoOpExpressionOnly, forNormalTryCatchStatement, forNormalTryCatchStatementOnly, forNotEqualExpression, forNotEqualExpressionOnly, forNotExpression, forNotExpressionOnly, forNullLiteral, forNullLiteralOnly, forNumericAssignmentExpressionOnly, forNumericBinaryExpressionOnly, forNumericUnaryExpressionOnly, forOrExpression, forOrExpressionOnly, forPackageImportStatement, forPackageImportStatementOnly, forPackageStatementOnly, forParenthesized, forParenthesizedExpressionList, forParenthesizedExpressionListOnly, forParenthesizedOnly, forPlusAssignmentExpression, forPlusAssignmentExpressionOnly, forPlusExpression, forPlusExpressionOnly, forPositiveExpression, forPositiveExpressionOnly, forPositivePostfixIncrementExpression, forPositivePostfixIncrementExpressionOnly, forPositivePrefixIncrementExpression, forPositivePrefixIncrementExpressionOnly, forPostfixIncrementExpressionOnly, forPrefixIncrementExpressionOnly, forPrimaryOnly, forPrimitiveTypeOnly, forReferenceTypeOnly, forRightSignedShiftAssignmentExpression, forRightSignedShiftAssignmentExpressionOnly, forRightSignedShiftExpression, forRightSignedShiftExpressionOnly, forRightUnsignedShiftAssignmentExpression, forRightUnsignedShiftAssignmentExpressionOnly, forRightUnsignedShiftExpression, forRightUnsignedShiftExpressionOnly, forShiftAssignmentExpressionOnly, forShiftBinaryExpressionOnly, forSimpleAnonymousClassInstantiation, forSimpleAnonymousClassInstantiationOnly, forSimpleAssignmentExpression, forSimpleAssignmentExpressionOnly, forSimpleInitializedArrayInstantiation, forSimpleInitializedArrayInstantiationOnly, forSimpleMethodInvocation, forSimpleMethodInvocationOnly, forSimpleNamedClassInstantiation, forSimpleNamedClassInstantiationOnly, forSimpleNameReference, forSimpleNameReferenceOnly, forSimpleSuperConstructorInvocation, forSimpleSuperConstructorInvocationOnly, forSimpleSuperReference, forSimpleSuperReferenceOnly, forSimpleThisConstructorInvocation, forSimpleThisConstructorInvocationOnly, forSimpleThisReference, forSimpleThisReferenceOnly, forSimpleUninitializedArrayInstantiation, forSimpleUninitializedArrayInstantiationOnly, forSourceFile, forSourceFileOnly, forStatementOnly, forStaticInitializer, forStringLiteral, forStringLiteralOnly, forSuperConstructorInvocationOnly, forSuperReferenceOnly, forSwitchCaseOnly, forSwitchStatement, forSynchronizedStatement, forSynchronizedStatementOnly, forThisConstructorInvocationOnly, forThisReferenceOnly, forThrowStatement, forThrowStatementOnly, forTryCatchFinallyStatement, forTryCatchFinallyStatementOnly, forTypeDefBaseOnly, forTypeOnly, forTypeParameter, forTypeParameterOnly, forTypeVariable, forTypeVariableOnly, forUnaryExpressionOnly, forUnbracedBody, forUnbracedBodyOnly, forUninitializedArrayInstantiationOnly, forUninitializedVariableDeclarator, forUninitializedVariableDeclaratorOnly, forUnlabeledBreakStatement, forUnlabeledBreakStatementOnly, forUnlabeledContinueStatement, forUnlabeledContinueStatementOnly, forUnparenthesizedExpressionList, forUnparenthesizedExpressionListOnly, forValueReturnStatement, forValueReturnStatementOnly, forVariableDeclaration, forVariableDeclarationOnly, forVariableDeclaratorOnly, forVariableReferenceOnly, forVoidReturn, forVoidReturnOnly, forVoidReturnStatement, forVoidReturnStatementOnly, forWhileStatement, forWhileStatementOnly, forWord, forWordOnly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.rice.cs.javalanglevels.tree.JExpressionIFVisitor
forAbstractMethodDef, forAndExpression, forArrayAccess, forArrayInitializer, forArrayType, forBitwiseAndAssignmentExpression, forBitwiseAndExpression, forBitwiseNotExpression, forBitwiseOrAssignmentExpression, forBitwiseOrExpression, forBitwiseXorAssignmentExpression, forBitwiseXorExpression, forBlock, forBooleanLiteral, forBracedBody, forCatchBlock, forCharLiteral, forClassLiteral, forClassOrInterfaceType, forComplexAnonymousClassInstantiation, forComplexInitializedArrayInstantiation, forComplexMethodInvocation, forComplexNamedClassInstantiation, forComplexNameReference, forComplexSuperConstructorInvocation, forComplexSuperReference, forComplexThisConstructorInvocation, forComplexThisReference, forComplexUninitializedArrayInstantiation, forCompoundWord, forConcreteMethodDef, forConditionalExpression, forConstructorDef, forDefaultCase, forDimensionExpressionList, forDivideAssignmentExpression, forDivideExpression, forDoStatement, forDoubleLiteral, forEmptyExpression, forEmptyForCondition, forEmptyStatement, forEqualsExpression, forExpressionStatement, forFloatLiteral, forFormalParameter, forForStatement, forGreaterThanExpression, forGreaterThanOrEqualExpression, forIfThenElseStatement, forIfThenStatement, forInitializedVariableDeclarator, forInnerClassDef, forInnerInterfaceDef, forInstanceInitializer, forInstanceofExpression, forIntegerLiteral, forLabeledBreakStatement, forLabeledCase, forLabeledContinueStatement, forLabeledStatement, forLeftShiftAssignmentExpression, forLeftShiftExpression, forLessThanExpression, forLessThanOrEqualExpression, forLongLiteral, forMemberType, forMinusAssignmentExpression, forMinusExpression, forModAssignmentExpression, forModExpression, forModifiersAndVisibility, forMultiplyAssignmentExpression, forMultiplyExpression, forNegativeExpression, forNegativePostfixIncrementExpression, forNegativePrefixIncrementExpression, forNoOpExpression, forNormalTryCatchStatement, forNotEqualExpression, forNotExpression, forNullLiteral, forOrExpression, forPackageImportStatement, forParenthesized, forParenthesizedExpressionList, forPlusAssignmentExpression, forPlusExpression, forPositiveExpression, forPositivePostfixIncrementExpression, forPositivePrefixIncrementExpression, forRightSignedShiftAssignmentExpression, forRightSignedShiftExpression, forRightUnsignedShiftAssignmentExpression, forRightUnsignedShiftExpression, forSimpleAnonymousClassInstantiation, forSimpleAssignmentExpression, forSimpleInitializedArrayInstantiation, forSimpleMethodInvocation, forSimpleNamedClassInstantiation, forSimpleNameReference, forSimpleSuperConstructorInvocation, forSimpleSuperReference, forSimpleThisConstructorInvocation, forSimpleThisReference, forSimpleUninitializedArrayInstantiation, forSourceFile, forStaticInitializer, forStringLiteral, forSwitchStatement, forSynchronizedStatement, forThrowStatement, forTryCatchFinallyStatement, forTypeParameter, forTypeVariable, forUnbracedBody, forUninitializedVariableDeclarator, forUnlabeledBreakStatement, forUnlabeledContinueStatement, forUnparenthesizedExpressionList, forValueReturnStatement, forVariableDeclaration, forVoidReturn, forVoidReturnStatement, forWhileStatement, forWord
 

Field Detail

NONE

public static final SourceInfo NONE

NULL_LITERAL

public static final NullLiteral NULL_LITERAL

_packageMav

public static final ModifiersAndVisibility _packageMav

_publicMav

public static final ModifiersAndVisibility _publicMav

_protectedMav

public static final ModifiersAndVisibility _protectedMav

_privateMav

public static final ModifiersAndVisibility _privateMav

_abstractMav

public static final ModifiersAndVisibility _abstractMav

_finalMav

public static final ModifiersAndVisibility _finalMav

_finalPublicMav

public static final ModifiersAndVisibility _finalPublicMav

_publicAbstractMav

public static final ModifiersAndVisibility _publicAbstractMav

_publicStaticMav

public static final ModifiersAndVisibility _publicStaticMav

_log

protected static final Log _log
Constructor Detail

TypeChecker

public TypeChecker(java.io.File file,
                   java.lang.String packageName,
                   java.util.LinkedList<Pair<java.lang.String,JExpressionIF>> errors,
                   Symboltable symbolTable,
                   java.util.LinkedList<java.lang.String> importedFiles,
                   java.util.LinkedList<java.lang.String> importedPackages)
The normal constructor. Called to begin type checking

Parameters:
file - The source file being type checked
packageName - The name of the package of the source file
errors - The list of errors that are encountered during type checking
importedFiles - The specific classes imported in the source file
importedPackages - The list of package names that are imported

TypeChecker

public TypeChecker(java.io.File file,
                   java.lang.String packageName,
                   java.util.LinkedList<java.lang.String> importedFiles,
                   java.util.LinkedList<java.lang.String> importedPackages)
Called by the subclasses.

Parameters:
file - The Source File being checked
packageName - The package the source file is in
importedFiles - The specific classes imported in the source file
importedPackages - The list of package names that are imported
Method Detail

_getData

protected Data _getData()
The top level type checker does not have a data


defineTestCaseClass

protected static SymbolData defineTestCaseClass()
Adds an appropriate definition of junit.framework.TestCase to symbolTable.


getSymbolData

public SymbolData getSymbolData(java.lang.String className,
                                Data enclosingData,
                                JExpression jexpr)
Returns the SymbolData corresponding to the name className. Checks 1) unqualified or partially-qualified inner classes visible in this scope, 2) fully-qualified inner classes, 3) primitives, 4) array types, 5) fully qualified top-level classes, 6) imported classes, 7) a top-level class within this package, 8) imported packages, and 9) java.lang classes. Assumes that an error should be generated if the class is not found, and that classes are not allowed to extend java.lang.Runnable. Will always check accessiblity since giveException is assumed to be true.

Parameters:
className - The class name to look up which may or may not be fully qualified.
enclosingData - The enclosing data -- either a MethodData or a ClassData for this reference
jexpr - The AST of the phrase containing the reference.

getSymbolData

public SymbolData getSymbolData(java.lang.String className,
                                Data enclosingData,
                                JExpression jexpr,
                                boolean giveException)
Call the next version of GetSymbolData, but pass it giveException as the flag for whether or not to give ambigException.


getSymbolData

public SymbolData getSymbolData(boolean giveAmbigException,
                                java.lang.String className,
                                Data enclosingData,
                                JExpression jexpr,
                                boolean giveException)
Returns the SymbolData corresponding to the name className. Checks 1) unqualified or partially-qualified inner classes visible in this scope, 2) fully-qualified inner classes, 3) primitives, 4) array types, 5) fully qualified top-level classes, 6) imported classes, 7) a top-level class within this package, 8) imported packages, and 9) java.lang classes. Assumes that classes are not allowed to extend java.lang.Runnable. Will only check accessibility if giveException is true.


getSymbolData

public SymbolData getSymbolData(java.lang.String className,
                                JExpression jexpr,
                                boolean giveException,
                                boolean runnableNotOkay)
Returns the SymbolData corresponding to the name className, assuming that className does not refer to an unqualified or partially-qualified inner class.


notRightPackage

protected boolean notRightPackage(SymbolData sd)
Return false if the symbolData is in the wrong package.

Parameters:
sd - The SymbolData to check.

cloneVariableDataList

public java.util.LinkedList<VariableData> cloneVariableDataList(java.util.LinkedList<VariableData> vars)
Create a clone of the linked list of Variable Data.


getQualifiedClassName

protected java.lang.String getQualifiedClassName(java.lang.String className)
The Qualified Class Name is the package, followed by a dot, followed by the rest of the class name. If the provided className is already qualified, just return it. If the package is not empty, and the className does not start with the package, append the package name onto the className, and return it.

Parameters:
className - The className to qualify.

_lookupMethodHelper

protected MethodData _lookupMethodHelper(java.lang.String methodName,
                                         SymbolData enclosingSD,
                                         InstanceData[] arguments,
                                         JExpression jexpr,
                                         boolean isConstructor,
                                         SymbolData thisSD)
Pass a default value


_getMatchingMethods

protected Pair<java.util.LinkedList<MethodData>,java.util.LinkedList<MethodData>> _getMatchingMethods(java.lang.String methodName,
                                                                                                      SymbolData enclosingSD,
                                                                                                      InstanceData[] arguments,
                                                                                                      JExpression jexpr,
                                                                                                      boolean isConstructor,
                                                                                                      SymbolData thisSD)
Finds and returns all matching methods. Assumes that the correct SymbolData is passed in.

Parameters:
methodName - The name of the method.
enclosingSD - The SymbolData we're currently searching for the method.
arguments - The types of the arguments to the method.
jexpr - The JExpression for the method invocation used in the error message.
isConstructor - True if this method is a constructor. If so, we know it must be in the initial SymbolData.
thisSD - The SymbolData whence the method is invoked.
Returns:
The pair of matching MethodData lists: without autoboxing and with autoboxing. An error is added if it is not found.

_lookupMethodHelper

protected MethodData _lookupMethodHelper(java.lang.String methodName,
                                         SymbolData enclosingSD,
                                         InstanceData[] arguments,
                                         JExpression jexpr,
                                         boolean isConstructor,
                                         SymbolData thisSD,
                                         java.util.LinkedList<MethodData> matchingMethods)
Finds which SymbolData this method is in, beginning at this SymbolData and recursively visiting super classes.

Parameters:
methodName - The name of the method.
enclosingSD - The SymbolData we're currently searching for the method.
arguments - The types of the arguments to the method.
jexpr - The JExpression for the method invocation used in the error message.
isConstructor - Tells us if this method is a constructor. If so, we know it must be in the initial SymbolData. We assume that the correct SymbolData was passed in.
thisSD - The SymbolData whence the method is invoked.
Returns:
The SymbolData where we find the method of null if it was not found. An error is added if it is not found.

_lookupMethod

protected MethodData _lookupMethod(java.lang.String methodName,
                                   SymbolData enclosingSD,
                                   InstanceData[] arguments,
                                   JExpression jexpr,
                                   java.lang.String errorMsg,
                                   boolean isConstructor,
                                   SymbolData thisSD)
Finds which SymbolData this method is in, beginning at this SymbolData and recursively visiting super classes. Adds an error if the method is not found.

Parameters:
methodName - The name of the method.
enclosingSD - The SymbolData we're currently searching for the method.
arguments - The instance types of the arguments to the method.
jexpr - The JExpression for the method invocation used in the error message.
errorMsg - The error to be displayed if the method cannot be found.
isConstructor - True if this method is a constructor. If so, we know it must be in the initial SymbolData. We assume that the correct SymbolData was passed in.
thisSD - The SymbolData of the initial SymbolData.
Returns:
The SymbolData containging the method of null if it was not found. An error is added if it is not found.

checkAccess

public static boolean checkAccess(JExpression piece,
                                  ModifiersAndVisibility mav,
                                  java.lang.String name,
                                  SymbolData enclosingSD,
                                  SymbolData thisSD,
                                  java.lang.String dataType)
Checks that the method is accessible given the SymbolData it's in and the current SymbolData. We have already checked the modifiers for validity. This will also work when checking the accessibility of static inner classes by passing in the static inner class for enclosingSD.

Parameters:
mav - The modifiers and visibility of the thing we're checking
name - The name of the thing we're checking
enclosingSD - The SymbolData which encloses name
thisSD - The SymbolData that is being type checked (from which we're referencing name)
dataType - The String that tells us whether name is a field, method, or class.

checkAccess

public static boolean checkAccess(ModifiersAndVisibility mav,
                                  SymbolData enclosingSD,
                                  SymbolData thisSD)
Call this version when you don't want to add an error--only take in what is necessary to do the check, give default values for anything that will not be used.


checkAccess

public static boolean checkAccess(JExpression piece,
                                  ModifiersAndVisibility mav,
                                  java.lang.String name,
                                  SymbolData enclosingSD,
                                  SymbolData thisSD,
                                  java.lang.String dataType,
                                  boolean addError)
Determines if thisSD can reference specified name defined in enclosingSD. Empty symbol is OK. See preceding method body.

Parameters:
mav - ??

getFieldOrVariable

public static VariableData getFieldOrVariable(java.lang.String text,
                                              Data data,
                                              SymbolData thisSD,
                                              JExpression piece)
Return the field or variable with the name text inside of data. (Referenced from thisSD)


getFieldOrVariable

public static VariableData getFieldOrVariable(java.lang.String text,
                                              Data data,
                                              SymbolData thisSD,
                                              JExpression piece,
                                              java.util.LinkedList<VariableData> vars)

getFieldOrVariable

public static VariableData getFieldOrVariable(java.lang.String text,
                                              Data data,
                                              SymbolData thisSD,
                                              JExpression piece,
                                              java.util.LinkedList<VariableData> vars,
                                              boolean shouldRecur)

getFieldOrVariable

public static VariableData getFieldOrVariable(java.lang.String text,
                                              Data data,
                                              SymbolData thisSD,
                                              JExpression piece,
                                              java.util.LinkedList<VariableData> vars,
                                              boolean shouldRecur,
                                              boolean addError)
This method checks if the identifier called text is a field or variable visible from the context of the param "data" and is accessible from the context of thisSD. This will search through all of "data"'s enclosing classes (outer class, superclass, interfaces) recursively. This could mean a lot of recursion... Returns null if the field or variable is not found.


assertInstanceType

public boolean assertInstanceType(TypeData type,
                                  java.lang.String errorMsg,
                                  JExpression expression)
Return true iff type is an instance type. If not, add an error.


assertFound

public boolean assertFound(TypeData type,
                           JExpressionIF expression)
If type is a PackageData, then it could not be resolved. Give an error


_addError

protected static void _addError(java.lang.String message,
                                JExpressionIF that)
Adds an error pair consisting of the specified String message and JExpression. Sets _errorAdded to true.

Parameters:
message - Error message
that - The JExpression corresponding to where the error is.

makeArrayOfRetType

protected TypeData[] makeArrayOfRetType(int len)
Return a TypeData array of the specified size.

Specified by:
makeArrayOfRetType in class JExpressionIFDepthFirstVisitor<TypeData>

defaultCase

protected TypeData defaultCase(JExpressionIF that)
This method is called by default from cases that do not override forCASEOnly.

Specified by:
defaultCase in class JExpressionIFDepthFirstVisitor<TypeData>

forClassDefOnly

public TypeData forClassDefOnly(ClassDef that,
                                TypeData mavRes,
                                TypeData nameRes,
                                TypeData[] typeParametersRes,
                                TypeData superRes,
                                TypeData[] interfacesRes,
                                TypeData bodyRes)
Overrides:
forClassDefOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forInnerClassDefOnly

public TypeData forInnerClassDefOnly(InnerClassDef that,
                                     TypeData mavRes,
                                     TypeData nameRes,
                                     TypeData[] typeParamRes,
                                     TypeData superClassRes,
                                     TypeData[] interfacesRes,
                                     TypeData bodyRes)
Overrides:
forInnerClassDefOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forInterfaceDefOnly

public TypeData forInterfaceDefOnly(InterfaceDef that,
                                    TypeData mavRes,
                                    TypeData nameRes,
                                    TypeData[] typeParamRes,
                                    TypeData[] superinterfacesRes,
                                    TypeData bodyRes)
Overrides:
forInterfaceDefOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forInnerInterfaceDefOnly

public TypeData forInnerInterfaceDefOnly(InnerInterfaceDef that,
                                         TypeData mavRes,
                                         TypeData nameRes,
                                         TypeData[] typeParamRes,
                                         TypeData[] superinterfacesRes,
                                         TypeData bodyRes)
Overrides:
forInnerInterfaceDefOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forInstanceInitializerOnly

public TypeData forInstanceInitializerOnly(InstanceInitializer that,
                                           TypeData codeRes)
Overrides:
forInstanceInitializerOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forStaticInitializerOnly

public TypeData forStaticInitializerOnly(StaticInitializer that,
                                         TypeData codeRes)
Overrides:
forStaticInitializerOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forLabeledStatementOnly

public TypeData forLabeledStatementOnly(LabeledStatement that,
                                        TypeData statementRes)

forBlockOnly

public TypeData forBlockOnly(Block that,
                             TypeData[] statementsRes)

forExpressionStatementOnly

public TypeData forExpressionStatementOnly(ExpressionStatement that,
                                           TypeData exprRes)
Overrides:
forExpressionStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forSwitchStatementOnly

public TypeData forSwitchStatementOnly(SwitchStatement that,
                                       TypeData testRes,
                                       TypeData[] casesRes)
Overrides:
forSwitchStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forBreakStatementOnly

public TypeData forBreakStatementOnly(BreakStatement that)
Overrides:
forBreakStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forContinueStatementOnly

public TypeData forContinueStatementOnly(ContinueStatement that)
Overrides:
forContinueStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forReturnStatementOnly

public TypeData forReturnStatementOnly(ReturnStatement that)
Overrides:
forReturnStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forTryCatchStatementOnly

public TypeData forTryCatchStatementOnly(TryCatchStatement that,
                                         TypeData tryBlockRes,
                                         TypeData[] catchBlocksRes)
Overrides:
forTryCatchStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forMethodDefOnly

public TypeData forMethodDefOnly(MethodDef that,
                                 TypeData mavRes,
                                 TypeData[] typeParamsRes,
                                 TypeData resRes,
                                 TypeData nameRes,
                                 TypeData paramsRes,
                                 TypeData[] throwsRes)

forConcreteMethodDefOnly

public TypeData forConcreteMethodDefOnly(ConcreteMethodDef that,
                                         TypeData mavRes,
                                         TypeData[] typeParamsRes,
                                         TypeData resRes,
                                         TypeData nameRes,
                                         TypeData paramsRes,
                                         TypeData[] throwsRes,
                                         TypeData bodyRes)

getCommonSuperTypeBaseCase

protected SymbolData getCommonSuperTypeBaseCase(SymbolData sdLeft,
                                                SymbolData sdRight)
Returns the common super type of the two types provided.


_isAssignableFrom

protected static boolean _isAssignableFrom(SymbolData sdLeft,
                                           SymbolData sdRight)
Return whether the value on the right can be assigned to the value on the left. Uses autoboxing if the user has java 1.5.


_isAssignableFromWithoutAutoboxing

protected boolean _isAssignableFromWithoutAutoboxing(SymbolData sdLeft,
                                                     SymbolData sdRight)
Return whether the value on the right can be assigned to the value on the left. Does not use autoboxing.


_checkAbstractMethods

protected void _checkAbstractMethods(SymbolData sd,
                                     JExpression classDef)
The method will add an error for each abstract method in the current SymbolData's inheritance hierarchy that does not have a concrete implementation.

Parameters:
sd - The SymbolData for the current class definition
classDef - The current ClassDef

checkForCyclicInheritance

protected boolean checkForCyclicInheritance(SymbolData sd,
                                            java.util.LinkedList<SymbolData> hierarchy,
                                            TypeDefBase tdb)
Checks for cyclic inheritance by traversing sd's list of superclasses and interfaces and checking if we've seen them before. We accumulate the list of classes and interfaces we've seen before in hierarchy.

Parameters:
sd - The SymbolData we're currently checking
hierarchy - The list of classes and interfaces we've seen before.
Returns:
Whether there is cyclic inheritance

forClassDef

public TypeData forClassDef(ClassDef that)
Do what is necessary to handle a class def

Specified by:
forClassDef in interface JExpressionIFVisitor<TypeData>
Overrides:
forClassDef in class JExpressionIFDepthFirstVisitor<TypeData>

forInterfaceDef

public TypeData forInterfaceDef(InterfaceDef that)
Do everything necessary to handle an interface

Specified by:
forInterfaceDef in interface JExpressionIFVisitor<TypeData>
Overrides:
forInterfaceDef in class JExpressionIFDepthFirstVisitor<TypeData>

forClassImportStatement

public TypeData forClassImportStatement(ClassImportStatement that)
Retrieve the class being imported from the Symbol table, and make sure it is public.

Specified by:
forClassImportStatement in interface JExpressionIFVisitor<TypeData>
Overrides:
forClassImportStatement in class JExpressionIFDepthFirstVisitor<TypeData>

forPackageStatement

public TypeData forPackageStatement(PackageStatement that)
Make sure that the package being imported does not conflict with another class in the symbol table, since we will not allow a package to be imported if it has the same name as a class.

Specified by:
forPackageStatement in interface JExpressionIFVisitor<TypeData>
Overrides:
forPackageStatement in class JExpressionIFDepthFirstVisitor<TypeData>

forPrimitiveType

public TypeData forPrimitiveType(PrimitiveType that)
Description copied from interface: JExpressionIFVisitor
Process an instance of PrimitiveType.

Specified by:
forPrimitiveType in interface JExpressionIFVisitor<TypeData>
Overrides:
forPrimitiveType in class JExpressionIFDepthFirstVisitor<TypeData>
Returns:
the appropriate type for a primitive type.

forCastExpression

public TypeData forCastExpression(CastExpression that)
Visit the type of the cast expression as well as the value being cast

Specified by:
forCastExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forCastExpression in class JExpressionIFDepthFirstVisitor<TypeData>