diff --git a/annotations/src/main/java/annotations/tc/TCWarningAnnotation.java b/annotations/src/main/java/annotations/tc/TCWarningAnnotation.java index 3ce98ebca..2b32621b8 100644 --- a/annotations/src/main/java/annotations/tc/TCWarningAnnotation.java +++ b/annotations/src/main/java/annotations/tc/TCWarningAnnotation.java @@ -24,7 +24,6 @@ package annotations.tc; -import java.io.File; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -41,6 +40,7 @@ import com.fujitsu.vdmj.tc.statements.TCStatement; import com.fujitsu.vdmj.tc.types.TCType; import com.fujitsu.vdmj.typechecker.Environment; +import com.fujitsu.vdmj.typechecker.ModuleEnvironment; import com.fujitsu.vdmj.typechecker.NameScope; import com.fujitsu.vdmj.typechecker.TypeChecker; @@ -48,6 +48,7 @@ public class TCWarningAnnotation extends TCAnnotation { private static final long serialVersionUID = 1L; private int warningCount = 0; + private String moduleName = null; private Set suppressed; public TCWarningAnnotation(TCIdentifierToken name, TCExpressionList args) @@ -56,32 +57,37 @@ public TCWarningAnnotation(TCIdentifierToken name, TCExpressionList args) } @Override - public void tcBefore(TCDefinition def, Environment env, NameScope scope) + public void tcBefore(TCModule module, ModuleEnvironment e) { + moduleName = module.name.getName(); preCheck(); } @Override - public void tcBefore(TCModule module) + public void tcBefore(TCClassDefinition clazz) { + moduleName = clazz.name.getName(); preCheck(); } @Override - public void tcBefore(TCClassDefinition clazz) + public void tcBefore(TCDefinition def, Environment env, NameScope scope) { + warningCount = TypeChecker.getWarningCount(); preCheck(); } @Override public void tcBefore(TCExpression exp, Environment env, NameScope scope) { + warningCount = TypeChecker.getWarningCount(); preCheck(); } @Override public void tcBefore(TCStatement stmt, Environment env, NameScope scope) { + warningCount = TypeChecker.getWarningCount(); preCheck(); } @@ -92,7 +98,6 @@ private void preCheck() name.report(6010, "@Warning must have one or more numeric arguments"); } - warningCount = TypeChecker.getWarningCount(); suppressed = new HashSet(); for (TCExpression arg: args) @@ -121,6 +126,12 @@ public void tcAfter(TCModule module) postCheck(); } + @Override + public void tcAfter(TCModule module, ModuleEnvironment e) + { + postCheck(); + } + @Override public void tcAfter(TCExpression exp, TCType type, Environment env, NameScope scope) { @@ -143,38 +154,25 @@ private void postCheck() { Iterator witer = TypeChecker.getWarnings().iterator(); - for (int i=0; i < warningCount; i++) + if (moduleName == null) { - witer.next(); // skip previous warnings + for (int i=0; i < warningCount; i++) + { + witer.next(); // skip previous warnings + } } while (witer.hasNext()) { VDMWarning w = witer.next(); - if (suppressed.contains((long)w.number)) + if (moduleName != null && !w.location.module.equals(moduleName)) { - witer.remove(); + continue; } - } - } - - @Override - public void doClose() - { - Iterator witer = TypeChecker.getWarnings().iterator(); - int myLine = name.getLocation().startLine; - File myFile = name.getLocation().file; - - while (witer.hasNext()) - { - VDMWarning w = witer.next(); - if (w.location.startLine == myLine + 1 && - w.location.file.equals(myFile) && - suppressed.contains((long)w.number)) + if (suppressed.contains((long)w.number)) { - // Warning is on the line after the one we annotated, so remove it witer.remove(); } } diff --git a/vdmj/src/main/java/com/fujitsu/vdmj/tc/annotations/TCAnnotationList.java b/vdmj/src/main/java/com/fujitsu/vdmj/tc/annotations/TCAnnotationList.java index e776df50a..70452cdb4 100644 --- a/vdmj/src/main/java/com/fujitsu/vdmj/tc/annotations/TCAnnotationList.java +++ b/vdmj/src/main/java/com/fujitsu/vdmj/tc/annotations/TCAnnotationList.java @@ -124,7 +124,7 @@ public void tcAfter(TCModule m, ModuleEnvironment e) { for (TCAnnotation annotation: this) { - annotation.tcAfter(m); + annotation.tcAfter(m, e); } }