edu.rice.cs.javalanglevels
Class ConstructorBodyTypeChecker

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.Bob
              extended by edu.rice.cs.javalanglevels.BodyTypeChecker
                  extended by edu.rice.cs.javalanglevels.ConstructorBodyTypeChecker
All Implemented Interfaces:
JExpressionIFVisitor<TypeData>

public class ConstructorBodyTypeChecker
extends BodyTypeChecker

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


Nested Class Summary
static class ConstructorBodyTypeChecker.ConstructorBodyTypeCheckerTest
          Test the methods in the above class.
 
Nested classes/interfaces inherited from class edu.rice.cs.javalanglevels.BodyTypeChecker
BodyTypeChecker.BodyTypeCheckerTest
 
Nested classes/interfaces inherited from class edu.rice.cs.javalanglevels.Bob
Bob.BobTest
 
Nested classes/interfaces inherited from class edu.rice.cs.javalanglevels.TypeChecker
TypeChecker.TypeCheckerTest
 
Field Summary
 
Fields inherited from class edu.rice.cs.javalanglevels.BodyTypeChecker
_bodyData
 
Fields inherited from class edu.rice.cs.javalanglevels.Bob
_data, _thrown, _vars, thingsThatHaveBeenAssigned
 
Fields inherited from class edu.rice.cs.javalanglevels.TypeChecker
_log
 
Constructor Summary
ConstructorBodyTypeChecker(BodyData bodyData, File file, String packageName, LinkedList<String> importedFiles, LinkedList<String> importedPackages, LinkedList<VariableData> vars, LinkedList<Pair<SymbolData,JExpression>> thrown)
           
 
Method Summary
 TypeData complexSuperConstructorInvocationAllowed(ComplexSuperConstructorInvocation that)
          This is used in the case where a complex super constructor invocation is allowed i.e.
 TypeData complexThisConstructorInvocationNotAllowed(ComplexThisConstructorInvocation that)
          ComplexThisConstructorInvocations are not ever allowed--throw an appropriate error.
protected  BodyTypeChecker createANewInstanceOfMe(BodyData bodyData, File file, String pakage, LinkedList<String> importedFiles, LinkedList<String> importedPackages, LinkedList<VariableData> vars, LinkedList<Pair<SymbolData,JExpression>> thrown)
          Create a new instance of this class for visiting inner bodies.
 TypeData forBracedBody(BracedBody that)
          Walk over the statements in the BracedBody, but treat the first line specially.
 TypeData forValueReturnStatementOnly(ValueReturnStatement that, TypeData value_result)
          Throw an error and return null, becuase constructors cannot have value return statements in their bodies.
 TypeData forVoidReturnStatementOnly(VoidReturnStatement that)
          Void return statements are allowed in constructor bodies, since according to java, constructors are void return methods.
 TypeData simpleSuperConstructorInvocationAllowed(SimpleSuperConstructorInvocation that)
          This is used in the case where a simple super constructor invocation is allowed i.e.
 TypeData simpleThisConstructorInvocationAllowed(SimpleThisConstructorInvocation that)
          This is used in the case where a simple this constructor invocation is allowed.
 
Methods inherited from class edu.rice.cs.javalanglevels.BodyTypeChecker
_getData, checkDuplicateExceptions, compareThrownAndCaught, forBlock, forBodyOnly, forBracedBodyOnly, forCatchBlock, forCatchBlockOnly, forDefaultCase, forDoStatement, forDoStatementOnly, forForStatement, forForStatementOnly, forIfThenElseStatement, forIfThenElseStatementOnly, forIfThenStatement, forIfThenStatementOnly, forInstanceInitializer, forLabeledCase, forNormalTryCatchStatement, forNormalTryCatchStatementOnly, forSimpleSuperReferenceOnly, forSimpleThisReferenceOnly, forSwitchCase, forSwitchStatement, forSwitchStatementOnly, forTryCatchFinallyStatement, forTryCatchFinallyStatementOnly, forTypeOnly, forUnbracedBodyOnly, forUninitializedVariableDeclaratorOnly, forValueReturnStatement, forWhileStatement, forWhileStatementOnly, getCommonSuperType, isException, isUncaughtCheckedException, makeSureCaughtStuffWasThrown, tryCatchLeastRestrictiveType
 
Methods inherited from class edu.rice.cs.javalanglevels.Bob
canBeAssigned, findClassReference, forArrayInitializerHelper, forBody, forExpressionStatement, forFormalParameter, forInitializedVariableDeclarator, forInitializedVariableDeclaratorOnly, forInnerClassDef, forInnerInterfaceDef, forLabeledStatement, forStaticInitializer, forSynchronizedStatement, forThrowStatement, forThrowStatementOnly, forUnbracedBody, forUninitializedVariableDeclarator, forVariableDeclaration, getArgTypesForInvocation, handleMethodInvocation, handleUncheckedException, inStaticMethod, isCheckedException
 
Methods inherited from class edu.rice.cs.javalanglevels.TypeChecker
_addError, _checkAbstractMethods, _getMatchingMethods, _isAssignableFrom, _isAssignableFromWithoutAutoboxing, _lookupMethod, _lookupMethodHelper, _lookupMethodHelper, assertFound, assertInstanceType, checkAccessibility, checkAccessibility, checkAccessibility, checkForCyclicInheritance, cloneVariableDataList, defaultCase, 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
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, forBlockOnly, forBooleanExpressionOnly, forBooleanLiteral, forBooleanLiteralOnly, forCastExpressionOnly, 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, forDefaultCaseOnly, forDimensionExpressionList, forDimensionExpressionListOnly, forDivideAssignmentExpression, forDivideAssignmentExpressionOnly, forDivideExpression, forDivideExpressionOnly, forDoubleLiteral, forDoubleLiteralOnly, forEmptyExpression, forEmptyExpressionOnly, forEmptyForCondition, forEmptyForConditionOnly, forEmptyStatement, forEmptyStatementOnly, forEqualityExpressionOnly, forEqualsExpression, forEqualsExpressionOnly, forExpressionListOnly, forExpressionOnly, forFloatLiteral, forFloatLiteralOnly, forFormalParameterOnly, forFunctionInvocationOnly, forGreaterThanExpression, forGreaterThanExpressionOnly, forGreaterThanOrEqualExpression, forGreaterThanOrEqualExpressionOnly, forImportStatementOnly, forIncrementExpressionOnly, forInitializedArrayInstantiationOnly, forInitializerOnly, forInstanceofExpression, forInstanceofExpressionOnly, forInstantiationOnly, forIntegerLiteral, forIntegerLiteralOnly, forJExpressionOnly, forLabeledBreakStatement, forLabeledBreakStatementOnly, 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, 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, forSimpleThisConstructorInvocation, forSimpleThisConstructorInvocationOnly, forSimpleThisReference, forSimpleUninitializedArrayInstantiation, forSimpleUninitializedArrayInstantiationOnly, forSourceFile, forSourceFileOnly, forStatementOnly, forStringLiteral, forStringLiteralOnly, forSuperConstructorInvocationOnly, forSuperReferenceOnly, forSwitchCaseOnly, forSynchronizedStatementOnly, forThisConstructorInvocationOnly, forThisReferenceOnly, forTypeDefBaseOnly, forTypeParameter, forTypeParameterOnly, forTypeVariable, forTypeVariableOnly, forUnaryExpressionOnly, forUninitializedArrayInstantiationOnly, forUnlabeledBreakStatement, forUnlabeledBreakStatementOnly, forUnlabeledContinueStatement, forUnlabeledContinueStatementOnly, forUnparenthesizedExpressionList, forUnparenthesizedExpressionListOnly, forVariableDeclarationOnly, forVariableDeclaratorOnly, forVariableReferenceOnly, forVoidReturn, forVoidReturnOnly, forVoidReturnStatement, 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, forBooleanLiteral, forCharLiteral, forClassLiteral, forClassOrInterfaceType, forComplexAnonymousClassInstantiation, forComplexInitializedArrayInstantiation, forComplexMethodInvocation, forComplexNamedClassInstantiation, forComplexNameReference, forComplexSuperConstructorInvocation, forComplexSuperReference, forComplexThisConstructorInvocation, forComplexThisReference, forComplexUninitializedArrayInstantiation, forCompoundWord, forConcreteMethodDef, forConditionalExpression, forConstructorDef, forDimensionExpressionList, forDivideAssignmentExpression, forDivideExpression, forDoubleLiteral, forEmptyExpression, forEmptyForCondition, forEmptyStatement, forEqualsExpression, forFloatLiteral, forGreaterThanExpression, forGreaterThanOrEqualExpression, forInstanceofExpression, forIntegerLiteral, forLabeledBreakStatement, forLabeledContinueStatement, forLeftShiftAssignmentExpression, forLeftShiftExpression, forLessThanExpression, forLessThanOrEqualExpression, forLongLiteral, forMemberType, forMinusAssignmentExpression, forMinusExpression, forModAssignmentExpression, forModExpression, forModifiersAndVisibility, forMultiplyAssignmentExpression, forMultiplyExpression, forNegativeExpression, forNegativePostfixIncrementExpression, forNegativePrefixIncrementExpression, forNoOpExpression, 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, forTypeParameter, forTypeVariable, forUnlabeledBreakStatement, forUnlabeledContinueStatement, forUnparenthesizedExpressionList, forVoidReturn, forVoidReturnStatement, forWord
 

Constructor Detail

ConstructorBodyTypeChecker

public ConstructorBodyTypeChecker(BodyData bodyData,
                                  File file,
                                  String packageName,
                                  LinkedList<String> importedFiles,
                                  LinkedList<String> importedPackages,
                                  LinkedList<VariableData> vars,
                                  LinkedList<Pair<SymbolData,JExpression>> thrown)
Method Detail

createANewInstanceOfMe

protected BodyTypeChecker createANewInstanceOfMe(BodyData bodyData,
                                                 File file,
                                                 String pakage,
                                                 LinkedList<String> importedFiles,
                                                 LinkedList<String> importedPackages,
                                                 LinkedList<VariableData> vars,
                                                 LinkedList<Pair<SymbolData,JExpression>> thrown)
Create a new instance of this class for visiting inner bodies.

Overrides:
createANewInstanceOfMe in class BodyTypeChecker

simpleThisConstructorInvocationAllowed

public TypeData simpleThisConstructorInvocationAllowed(SimpleThisConstructorInvocation that)
This is used in the case where a simple this constructor invocation is allowed. i.e. when it is the first statement of a constructor body.


complexThisConstructorInvocationNotAllowed

public TypeData complexThisConstructorInvocationNotAllowed(ComplexThisConstructorInvocation that)
ComplexThisConstructorInvocations are not ever allowed--throw an appropriate error.


simpleSuperConstructorInvocationAllowed

public TypeData simpleSuperConstructorInvocationAllowed(SimpleSuperConstructorInvocation that)
This is used in the case where a simple super constructor invocation is allowed i.e. when it is the first statement of a constructor body.


complexSuperConstructorInvocationAllowed

public TypeData complexSuperConstructorInvocationAllowed(ComplexSuperConstructorInvocation that)
This is used in the case where a complex super constructor invocation is allowed i.e. when it is the first statement of a constructor body.


forVoidReturnStatementOnly

public TypeData forVoidReturnStatementOnly(VoidReturnStatement that)
Void return statements are allowed in constructor bodies, since according to java, constructors are void return methods. However, we treat them as if they returned an instance of the class they are a constructor for, so we will return that symbol data here.

Overrides:
forVoidReturnStatementOnly in class BodyTypeChecker
Returns:
the type the method is declared to return.

forValueReturnStatementOnly

public TypeData forValueReturnStatementOnly(ValueReturnStatement that,
                                            TypeData value_result)
Throw an error and return null, becuase constructors cannot have value return statements in their bodies.

Overrides:
forValueReturnStatementOnly in class BodyTypeChecker

forBracedBody

public TypeData forBracedBody(BracedBody that)
Walk over the statements in the BracedBody, but treat the first line specially. A super constructor invocation can only appear on the first line of a constructor, so see if there is one on the first line, and if so, call the appropriate method. If there is no super constructor invocation, then assume there is an implicit one. Then visit the rest of the statements in the body like normal. Make sure errors are thrown for any uncaught exceptions.

Specified by:
forBracedBody in interface JExpressionIFVisitor<TypeData>
Overrides:
forBracedBody in class Bob