edu.rice.cs.javalanglevels
Class ClassBodyTypeChecker

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

public class ClassBodyTypeChecker
extends SpecialTypeChecker

Do the TypeChecking appropriate to the context of a class body. Common to all Language Levels.


Nested Class Summary
static class ClassBodyTypeChecker.ClassBodyTypeCheckerTest
          Test the methods that are defined above.
 
Nested classes/interfaces inherited from class edu.rice.cs.javalanglevels.SpecialTypeChecker
SpecialTypeChecker.BobTest
 
Nested classes/interfaces inherited from class edu.rice.cs.javalanglevels.TypeChecker
TypeChecker.TypeCheckerTest
 
Field Summary
protected  boolean hasConstructor
          True if we encounter a ConstructorDef while visiting the body.
 
Fields inherited from class edu.rice.cs.javalanglevels.SpecialTypeChecker
_data, _thrown, _vars, thingsThatHaveBeenAssigned
 
Fields inherited from class edu.rice.cs.javalanglevels.TypeChecker
_abstractMav, _finalMav, _finalPublicMav, _log, _packageMav, _privateMav, _protectedMav, _publicAbstractMav, _publicMav, _publicStaticMav, NONE, NULL_LITERAL
 
Constructor Summary
ClassBodyTypeChecker(SymbolData sd, File file, String packageName, LinkedList<String> importedFiles, LinkedList<String> importedPackages, LinkedList<VariableData> vars, LinkedList<Pair<SymbolData,JExpression>> thrown)
          Constructor for ClassBodyTypeChecker.
 
Method Summary
protected  Data _getData()
          The top level type checker does not have a data
 TypeData forAbstractMethodDef(AbstractMethodDef that)
          Process an instance of AbstractMethodDef.
 TypeData forConcreteMethodDef(ConcreteMethodDef that)
          Visit all of the fields of the ConcreteMethodDef, and resolve everything.
 TypeData forConstructorDef(ConstructorDef that)
          Finds the corresponding MethodData for this constructor first.
 TypeData forConstructorDefOnly(ConstructorDef that, TypeData mavRes, TypeData[] parameters_result, TypeData[] throwsRes, TypeData bodyRes)
           
 TypeData forTypeOnly(Type that)
           
 TypeData forUninitializedVariableDeclaratorOnly(UninitializedVariableDeclarator that, TypeData typeRes, TypeData nameRes)
          We need to do this so that expressions (which should only occur in variable initializers and initializer blocks) can know which fields have already been declared
 
Methods inherited from class edu.rice.cs.javalanglevels.SpecialTypeChecker
canBeAssigned, findClassReference, forArrayInitializerHelper, forBody, forBracedBody, forExpressionStatement, forFormalParameter, forInitializedVariableDeclarator, forInitializedVariableDeclaratorOnly, forInnerClassDef, forInnerInterfaceDef, forInstanceInitializer, forLabeledStatement, forStaticInitializer, forSynchronizedStatement, forThrowStatement, forThrowStatementOnly, forUnbracedBody, forUninitializedVariableDeclarator, forVariableDeclaration, getArgTypesForInvocation, handleMethodInvocation, handleUncheckedException, inStaticMethod, isCheckedException, isUncaughtCheckedException
 
Methods inherited from class edu.rice.cs.javalanglevels.TypeChecker
_addError, _checkAbstractMethods, _getMatchingMethods, _isAssignableFrom, _isAssignableFromWithoutAutoboxing, _lookupMethod, _lookupMethodHelper, _lookupMethodHelper, assertFound, assertInstanceType, checkAccess, checkAccess, checkAccess, checkForCyclicInheritance, cloneVariableDataList, defaultCase, defineTestCaseClass, forBlockOnly, forBreakStatementOnly, forCastExpression, forClassDef, forClassDefOnly, forClassImportStatement, forConcreteMethodDefOnly, forContinueStatementOnly, forExpressionStatementOnly, forInnerClassDefOnly, forInnerInterfaceDefOnly, forInstanceInitializerOnly, forInterfaceDef, forInterfaceDefOnly, forLabeledStatementOnly, forMethodDefOnly, forPackageStatement, forPrimitiveType, forReturnStatementOnly, forStaticInitializerOnly, forSwitchStatementOnly, forTryCatchStatementOnly, getCommonSuperTypeBaseCase, getFieldOrVariable, getFieldOrVariable, getFieldOrVariable, getFieldOrVariable, getQualifiedClassName, getSymbolData, getSymbolData, getSymbolData, getSymbolData, makeArrayOfRetType, notRightPackage
 
Methods inherited from class edu.rice.cs.javalanglevels.tree.JExpressionIFDepthFirstVisitor
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, 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, forConcreteMethodDefOnly, forConditionalExpression, forConditionalExpressionOnly, forConstructorDefOnly, forDefaultCase, forDefaultCaseOnly, forDimensionExpressionList, forDimensionExpressionListOnly, forDivideAssignmentExpression, forDivideAssignmentExpressionOnly, forDivideExpression, forDivideExpressionOnly, forDoStatement, forDoStatementOnly, forDoubleLiteral, forDoubleLiteralOnly, forEmptyExpression, forEmptyExpressionOnly, forEmptyForCondition, forEmptyForConditionOnly, forEmptyStatement, forEmptyStatementOnly, forEqualityExpressionOnly, forEqualsExpression, forEqualsExpressionOnly, forExpressionListOnly, forExpressionOnly, forFloatLiteral, forFloatLiteralOnly, forFormalParameterOnly, forForStatement, forForStatementOnly, forFunctionInvocationOnly, forGreaterThanExpression, forGreaterThanExpressionOnly, forGreaterThanOrEqualExpression, forGreaterThanOrEqualExpressionOnly, forIfThenElseStatement, forIfThenElseStatementOnly, forIfThenStatement, forIfThenStatementOnly, forImportStatementOnly, forIncrementExpressionOnly, forInitializedArrayInstantiationOnly, forInitializerOnly, forInstanceofExpression, forInstanceofExpressionOnly, forInstantiationOnly, forIntegerLiteral, forIntegerLiteralOnly, forJExpressionOnly, forLabeledBreakStatement, forLabeledBreakStatementOnly, forLabeledCase, forLabeledCaseOnly, forLabeledContinueStatement, forLabeledContinueStatementOnly, 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, forStringLiteral, forStringLiteralOnly, forSuperConstructorInvocationOnly, forSuperReferenceOnly, forSwitchCaseOnly, forSwitchStatement, forSynchronizedStatementOnly, forThisConstructorInvocationOnly, forThisReferenceOnly, forTryCatchFinallyStatement, forTryCatchFinallyStatementOnly, forTypeDefBaseOnly, forTypeParameter, forTypeParameterOnly, forTypeVariable, forTypeVariableOnly, forUnaryExpressionOnly, forUnbracedBodyOnly, forUninitializedArrayInstantiationOnly, forUnlabeledBreakStatement, forUnlabeledBreakStatementOnly, forUnlabeledContinueStatement, forUnlabeledContinueStatementOnly, forUnparenthesizedExpressionList, forUnparenthesizedExpressionListOnly, forValueReturnStatement, forValueReturnStatementOnly, 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
forAndExpression, forArrayAccess, forArrayInitializer, forArrayType, forBitwiseAndAssignmentExpression, forBitwiseAndExpression, forBitwiseNotExpression, forBitwiseOrAssignmentExpression, forBitwiseOrExpression, forBitwiseXorAssignmentExpression, forBitwiseXorExpression, forBlock, forBooleanLiteral, forCatchBlock, forCharLiteral, forClassLiteral, forClassOrInterfaceType, forComplexAnonymousClassInstantiation, forComplexInitializedArrayInstantiation, forComplexMethodInvocation, forComplexNamedClassInstantiation, forComplexNameReference, forComplexSuperConstructorInvocation, forComplexSuperReference, forComplexThisConstructorInvocation, forComplexThisReference, forComplexUninitializedArrayInstantiation, forCompoundWord, forConditionalExpression, forDefaultCase, forDimensionExpressionList, forDivideAssignmentExpression, forDivideExpression, forDoStatement, forDoubleLiteral, forEmptyExpression, forEmptyForCondition, forEmptyStatement, forEqualsExpression, forFloatLiteral, forForStatement, forGreaterThanExpression, forGreaterThanOrEqualExpression, forIfThenElseStatement, forIfThenStatement, forInstanceofExpression, forIntegerLiteral, forLabeledBreakStatement, forLabeledCase, forLabeledContinueStatement, 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, forStringLiteral, forSwitchStatement, forTryCatchFinallyStatement, forTypeParameter, forTypeVariable, forUnlabeledBreakStatement, forUnlabeledContinueStatement, forUnparenthesizedExpressionList, forValueReturnStatement, forVoidReturn, forVoidReturnStatement, forWhileStatement, forWord
 

Field Detail

hasConstructor

protected boolean hasConstructor
True if we encounter a ConstructorDef while visiting the body.

Constructor Detail

ClassBodyTypeChecker

public ClassBodyTypeChecker(SymbolData sd,
                            File file,
                            String packageName,
                            LinkedList<String> importedFiles,
                            LinkedList<String> importedPackages,
                            LinkedList<VariableData> vars,
                            LinkedList<Pair<SymbolData,JExpression>> thrown)
Constructor for ClassBodyTypeChecker. Adds all the variables in the symbol data to the list of what can be seen from this context, since class fields can always be seen.

Parameters:
sd - The SymbolData of the class we are type checking.
file - The File corresponding to the source file we are checking.
packageName - The package of the source file.
importedFiles - A list of the names of the classes that are specifically imported in the source file
importedPackages - A list of the names of the packages that are imported in the source file.
vars - A list of the variable datas that can be seen and have been given a value before this context
thrown - The exceptions that are thrown
Method Detail

_getData

protected Data _getData()
Description copied from class: TypeChecker
The top level type checker does not have a data

Overrides:
_getData in class SpecialTypeChecker
Returns:
the symbol data corresponding to the class we are visiting

forUninitializedVariableDeclaratorOnly

public TypeData forUninitializedVariableDeclaratorOnly(UninitializedVariableDeclarator that,
                                                       TypeData typeRes,
                                                       TypeData nameRes)
We need to do this so that expressions (which should only occur in variable initializers and initializer blocks) can know which fields have already been declared

Overrides:
forUninitializedVariableDeclaratorOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forConstructorDef

public TypeData forConstructorDef(ConstructorDef that)
Finds the corresponding MethodData for this constructor first. Then visits the body, making sure that all final fields are assigned a value and that no final fields are reassigned.

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

forConstructorDefOnly

public TypeData forConstructorDefOnly(ConstructorDef that,
                                      TypeData mavRes,
                                      TypeData[] parameters_result,
                                      TypeData[] throwsRes,
                                      TypeData bodyRes)

forConcreteMethodDef

public TypeData forConcreteMethodDef(ConcreteMethodDef that)
Visit all of the fields of the ConcreteMethodDef, and resolve everything. Then, find the corresponding MethodData in the SymbolData's list of methods. It must match both in name and parameter types. Keep track of what has been assigned before we visit the method body, and then visit the method body. Then, make sure the return type of the method is okay, and unassign any variables for which the assignment should not be visible outside the scope of the method.

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

forAbstractMethodDef

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

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

forTypeOnly

public TypeData forTypeOnly(Type that)
Overrides:
forTypeOnly in class JExpressionIFDepthFirstVisitor<TypeData>