changeset 3191:eff036bd8852

Add a method to deeply copy a TypeAnnotationPosition.
author wmdietl
date Wed, 05 Feb 2014 17:01:54 -0500
parents ca15a58f9d84
children a57a762e616b
files src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Wed Feb 05 14:39:46 2014 -0500
+++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Wed Feb 05 17:01:54 2014 -0500
@@ -25,6 +25,7 @@
 
 package com.sun.tools.javac.code;
 
+import java.util.Arrays;
 import java.util.Iterator;
 
 import com.sun.tools.javac.tree.JCTree.JCLambda;
@@ -358,6 +359,27 @@
     }
 
     /**
+     * Create a new TypeAnnotationPosition with the same values as the input, deeply copied.
+     *
+     * @param tapos The input value.
+     * @return A new copy of the input.
+     */
+    public static TypeAnnotationPosition copy(final TypeAnnotationPosition tapos) {
+        TypeAnnotationPosition res = new TypeAnnotationPosition(tapos.type, tapos.pos, tapos.parameter_index,
+                tapos.onLambda, tapos.type_index, tapos.bound_index, List.from(tapos.location));
+        res.isValidOffset = tapos.isValidOffset;
+        res.exception_index = tapos.exception_index;
+        if (tapos.lvarIndex != null)
+            res.lvarIndex = Arrays.copyOf(tapos.lvarIndex, tapos.lvarIndex.length);
+        if (tapos.lvarLength != null)
+            res.lvarLength = Arrays.copyOf(tapos.lvarLength, tapos.lvarLength.length);
+        if (tapos.lvarOffset != null)
+            res.lvarOffset = Arrays.copyOf(tapos.lvarOffset, tapos.lvarOffset.length);
+        res.offset = tapos.offset;
+        return res;
+    }
+
+    /**
      * Create a {@code TypeAnnotationPosition} for a method return.
      *
      * @param location The type path.