diff --git a/src/com/google/java/contract/core/apt/ContractExpressionTransformer.java b/src/com/google/java/contract/core/apt/ContractExpressionTransformer.java index e4218c0..2801de2 100644 --- a/src/com/google/java/contract/core/apt/ContractExpressionTransformer.java +++ b/src/com/google/java/contract/core/apt/ContractExpressionTransformer.java @@ -132,10 +132,6 @@ public ContractExpressionTransformer(DiagnosticManager diagnosticManager, oldId = 0; } - public void setAcceptOld(boolean acceptOld) { - this.acceptOld = acceptOld; - } - @Requires({ "currentBuffer != null", "tokenizer != null", diff --git a/src/com/google/java/contract/core/apt/MethodContractCreator.java b/src/com/google/java/contract/core/apt/MethodContractCreator.java index ff7d249..3377f0f 100644 --- a/src/com/google/java/contract/core/apt/MethodContractCreator.java +++ b/src/com/google/java/contract/core/apt/MethodContractCreator.java @@ -50,7 +50,9 @@ */ @Invariant({ "diagnosticManager != null", - "transformer != null" + "preTransformer != null", + "postTransformer != null", + "postSignalTransformer != null" }) public class MethodContractCreator extends ElementScanner { /** @@ -67,7 +69,6 @@ public PreMethodCreationTrait( @Override public boolean transform(List code, List lineNumbers, Object sourceInfo) { - transformer.setAcceptOld(false); return super.transform(code, lineNumbers, sourceInfo); } @@ -93,7 +94,6 @@ public CommonPostMethodCreationTrait( public boolean transform(List code, List lineNumbers, Object sourceInfo) { int id = transformer.getNextOldId(); - transformer.setAcceptOld(true); boolean success = super.transform(code, lineNumbers, sourceInfo); if (success) { @@ -242,7 +242,9 @@ public List getSourceExpressions() { protected ContractMethodModel postMethod; protected ContractMethodModel postSignalMethod; - protected ContractExpressionTransformer transformer; + protected ContractExpressionTransformer preTransformer; + protected ContractExpressionTransformer postTransformer; + protected ContractExpressionTransformer postSignalTransformer; /** * Constructs a new MethodContractCreator. @@ -254,7 +256,12 @@ public MethodContractCreator(DiagnosticManager diagnosticManager) { preMethod = null; postMethod = null; postSignalMethod = null; - transformer = new ContractExpressionTransformer(diagnosticManager, true); + preTransformer = + new ContractExpressionTransformer(diagnosticManager, false); + postTransformer = + new ContractExpressionTransformer(diagnosticManager, true); + postSignalTransformer = + new ContractExpressionTransformer(diagnosticManager, true); } @Override @@ -271,14 +278,15 @@ public void visitContractAnnotation(ContractAnnotationModel annotation) { List code = annotation.getValues(); if (annotation.getKind().equals(ElementKind.REQUIRES)) { - PreMethodCreationTrait trait = new PreMethodCreationTrait(transformer); + PreMethodCreationTrait trait = new PreMethodCreationTrait(preTransformer); preMethod = createContractMethods(trait, preMethod, annotation); } else if (annotation.getKind().equals(ElementKind.ENSURES)) { - PostMethodCreationTrait trait = new PostMethodCreationTrait(transformer); + PostMethodCreationTrait trait = + new PostMethodCreationTrait(postTransformer); postMethod = createContractMethods(trait, postMethod, annotation); } else if (annotation.getKind().equals(ElementKind.THROW_ENSURES)) { PostSignalMethodCreationTrait trait = - new PostSignalMethodCreationTrait(transformer); + new PostSignalMethodCreationTrait(postSignalTransformer); postSignalMethod = createContractMethods(trait, postSignalMethod, annotation); } else {