langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java
changeset 23975 c7c81595aea9
parent 22702 1297fbaf34fa
child 24396 3c36c6afcbca
--- a/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Wed Apr 16 19:21:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Thu Apr 17 12:17:02 2014 -0400
@@ -151,18 +151,14 @@
     public final int parameter_index;
 
     // For class extends, implements, and throws clauses
-
-    // This field is effectively final.  However, it needs to be
-    // modified by Gen for the time being.  Do not introduce new
-    // mutations.
-    public int type_index;
+    public final int type_index;
 
-    // For exception parameters, index into exception table.
-    // In com.sun.tools.javac.jvm.Gen.genCatch we first set the type_index
-    // to the catch type index - that value is only temporary.
-    // Then in com.sun.tools.javac.jvm.Code.fillExceptionParameterPositions
-    // we use that value to determine the exception table index.
-    public int exception_index = Integer.MIN_VALUE;
+    // For exception parameters, index into exception table.  In
+    // com.sun.tools.javac.jvm.Gen.genCatch, we first use this to hold
+    // the catch type index.  Then in
+    // com.sun.tools.javac.jvm.Code.fillExceptionParameterPositions we
+    // use that value to determine the exception table index.
+    private int exception_index = Integer.MIN_VALUE;
 
     // If this type annotation is within a lambda expression,
     // store a pointer to the lambda expression tree in order
@@ -309,6 +305,38 @@
         isValidOffset = true;
     }
 
+    public boolean hasExceptionIndex() {
+        return exception_index >= 0;
+    }
+
+    public int getExceptionIndex() {
+        Assert.check(exception_index >= 0, "exception_index does not contain a bytecode offset");
+        return exception_index;
+    }
+
+    public void setExceptionIndex(final int exception_index) {
+        Assert.check(hasCatchType(), "exception_index already contains a bytecode offset");
+        Assert.check(exception_index >= 0, "Expected a valid bytecode offset");
+        this.exception_index = exception_index;
+    }
+
+    public boolean hasCatchType() {
+        return exception_index < 0 && exception_index != Integer.MIN_VALUE;
+    }
+
+    public int getCatchType() {
+        Assert.check(hasCatchType(),
+                     "exception_index does not contain a valid catch type");
+        return (-this.exception_index) - 1 ;
+    }
+
+    public void setCatchType(final int catchType) {
+        Assert.check(this.exception_index < 0,
+                     "exception_index already contains a bytecode index");
+        Assert.check(catchType >= 0, "Expected a valid catch type");
+        this.exception_index = -(catchType + 1);
+    }
+
     /**
      * Decode the binary representation for a type path and set
      * the {@code location} field.