39a06e62642808cebc19e0d21fdd5a9bb008e439
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.hc2vpp.docs.core;
18
19
20 import java.util.Set;
21 import org.objectweb.asm.ClassVisitor;
22 import org.objectweb.asm.MethodVisitor;
23 import org.objectweb.asm.Opcodes;
24
25 public class MethodDelegatingClassVisitor extends ClassVisitor {
26
27     private final String currentClass;
28     private final String methodName;
29     private final String reference;
30     private final Set<PluginMethodReference> foundReferences;
31     private final Set<String> allreadyProcessedLocalMethods;
32
33     public MethodDelegatingClassVisitor(String currentClass,
34                                         String methodName,
35                                         String reference,
36                                         Set<PluginMethodReference> foundReferences,
37                                         Set<String> allreadyProcessedLocalMethods) {
38         super(Opcodes.ASM5);
39         this.currentClass = currentClass;
40         this.methodName = methodName;
41         this.reference = reference;
42         this.foundReferences = foundReferences;
43         this.allreadyProcessedLocalMethods = allreadyProcessedLocalMethods;
44     }
45
46     @Override
47     public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
48         if (name.equals(methodName)) {
49             return new MethodPluginCoverageVisitor(currentClass, foundReferences, reference,
50                     allreadyProcessedLocalMethods);
51         }
52         return super.visitMethod(access, name, desc, signature, exceptions);
53     }
54 }