jdk/src/java.base/share/classes/sun/reflect/annotation/TypeAnnotation.java
changeset 34708 4a1e3728135c
parent 25859 3317bb8137f4
equal deleted inserted replaced
34707:5866a10ac337 34708:4a1e3728135c
     1 /*
     1 /*
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   185             System.arraycopy(this.locations, 0, res, 0, depth);
   185             System.arraycopy(this.locations, 0, res, 0, depth);
   186             res[newDepth - 1] = new Location(tag, (short)(index & 0xFF));
   186             res[newDepth - 1] = new Location(tag, (short)(index & 0xFF));
   187             return new LocationInfo(newDepth, res);
   187             return new LocationInfo(newDepth, res);
   188         }
   188         }
   189 
   189 
       
   190         /** Pop a series of locations matching {@code tag}. Stop poping as soon as a non-matching tag is found. */
       
   191         public LocationInfo popAllLocations(byte tag) {
       
   192             LocationInfo l = this;
       
   193             int newDepth = l.depth;
       
   194             while(newDepth > 0 && l.locations[newDepth - 1].tag == tag) {
       
   195                 newDepth--;
       
   196             }
       
   197             if (newDepth != l.depth) {
       
   198                 Location[] res = new Location[newDepth];
       
   199                 System.arraycopy(this.locations, 0, res, 0, newDepth);
       
   200                 return new LocationInfo(newDepth, res);
       
   201             } else
       
   202                 return l;
       
   203         }
       
   204 
   190         public TypeAnnotation[] filter(TypeAnnotation[] ta) {
   205         public TypeAnnotation[] filter(TypeAnnotation[] ta) {
   191             ArrayList<TypeAnnotation> l = new ArrayList<>(ta.length);
   206             ArrayList<TypeAnnotation> l = new ArrayList<>(ta.length);
   192             for (TypeAnnotation t : ta) {
   207             for (TypeAnnotation t : ta) {
   193                 if (isSameLocationInfo(t.getLocationInfo()))
   208                 if (isSameLocationInfo(t.getLocationInfo()))
   194                     l.add(t);
   209                     l.add(t);
   195             }
   210             }
   196             return l.toArray(new TypeAnnotation[0]);
   211             return l.toArray(AnnotatedTypeFactory.EMPTY_TYPE_ANNOTATION_ARRAY);
   197         }
   212         }
   198 
   213 
   199         boolean isSameLocationInfo(LocationInfo other) {
   214         boolean isSameLocationInfo(LocationInfo other) {
   200             if (depth != other.depth)
   215             if (depth != other.depth)
   201                 return false;
   216                 return false;