View Javadoc

1   package org.apache.maven.plugins.shade;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.objectweb.asm.AnnotationVisitor;
23  import org.objectweb.asm.ClassVisitor;
24  import org.objectweb.asm.FieldVisitor;
25  import org.objectweb.asm.MethodVisitor;
26  import org.objectweb.asm.commons.Remapper;
27  import org.objectweb.asm.commons.RemappingAnnotationAdapter;
28  import org.objectweb.asm.commons.RemappingClassAdapter;
29  import org.objectweb.asm.commons.RemappingFieldAdapter;
30  import org.objectweb.asm.commons.RemappingMethodAdapter;
31  
32  /**
33   * A temporary class to fix a bug in objectweb asm.
34   * 
35   * @see <a href="http://forge.ow2.org/tracker/index.php?func=detail&aid=314982&group_id=23&atid=100023">bug #314982</a>
36   */
37  class TempRemappingClassAdapter
38      extends RemappingClassAdapter
39  {
40  
41      private static class MethodRemapVisitor
42          extends RemappingMethodAdapter
43      {
44          public MethodRemapVisitor( int access, String desc, MethodVisitor mv, Remapper renamer )
45          {
46              super( access, desc, mv, renamer );
47          }
48  
49          public AnnotationVisitor visitAnnotation( String desc, boolean visible )
50          {
51              // The original source from asm:3.2 does not have the call to remapper.mapDesc()
52              AnnotationVisitor av = mv.visitAnnotation( remapper.mapDesc( desc ), visible );
53              return av == null ? av : new RemappingAnnotationAdapter( av, remapper );
54          }
55      }
56  
57      private static class FieldRemapVisitor
58          extends RemappingFieldAdapter
59      {
60  
61          private final FieldVisitor fv;
62  
63          private final Remapper remapper;
64  
65          public FieldRemapVisitor( FieldVisitor fv, Remapper remapper )
66          {
67              super( fv, remapper );
68              this.fv = fv;
69              this.remapper = remapper;
70          }
71  
72          public AnnotationVisitor visitAnnotation( String desc, boolean visible )
73          {
74              // The original source from asm:3.2 does not have the call to remapper.mapDesc()
75              AnnotationVisitor av = fv.visitAnnotation( remapper.mapDesc( desc ), visible );
76              return av == null ? null : new RemappingAnnotationAdapter( av, remapper );
77          }
78      }
79  
80      public TempRemappingClassAdapter( ClassVisitor cv, Remapper remapper )
81      {
82          super( cv, remapper );
83      }
84  
85      protected MethodVisitor createRemappingMethodAdapter( int access, String newDesc, MethodVisitor mv )
86      {
87          return new MethodRemapVisitor( access, newDesc, mv, remapper );
88      }
89  
90      protected FieldVisitor createRemappingFieldAdapter( FieldVisitor fv )
91      {
92          return new FieldRemapVisitor( fv, remapper );
93      }
94  
95  }