1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.simpligility.maven.plugins.android.asm;
17
18 import org.apache.commons.lang3.StringUtils;
19 import org.objectweb.asm.AnnotationVisitor;
20 import org.objectweb.asm.Attribute;
21 import org.objectweb.asm.ClassVisitor;
22 import org.objectweb.asm.FieldVisitor;
23 import org.objectweb.asm.MethodVisitor;
24 import org.objectweb.asm.Opcodes;
25
26 import java.util.concurrent.atomic.AtomicBoolean;
27
28
29
30
31
32
33
34 class DescendantFinder extends ClassVisitor
35 {
36
37
38
39
40
41
42
43 DescendantFinder( String... parentPackages )
44 {
45 super( Opcodes.ASM4 );
46 this.parentPackages = parentPackages;
47 }
48
49 private final String[] parentPackages;
50 private final AtomicBoolean isDescendantFound = new AtomicBoolean( false );
51
52 @Override
53 public void visit( int version, int access, String name, String signature, String superName, String[] interfaces )
54 {
55 for ( String testPackage : parentPackages )
56 {
57 if ( StringUtils.startsWith( superName, testPackage ) )
58 {
59 flagAsFound();
60
61 }
62 }
63 }
64
65 private void flagAsFound()
66 {
67 isDescendantFound.set( true );
68 }
69
70
71
72
73
74
75 public boolean isDescendantFound()
76 {
77 return isDescendantFound.get();
78 }
79
80 @Override
81 public void visitSource( String source, String debug )
82 {
83 }
84
85 @Override
86 public void visitOuterClass( String owner, String name, String desc )
87 {
88 }
89
90 @Override
91 public AnnotationVisitor visitAnnotation( String desc, boolean visible )
92 {
93 return null;
94 }
95
96 @Override
97 public void visitAttribute( Attribute attr )
98 {
99 }
100
101 @Override
102 public void visitInnerClass( String name, String outerName, String innerName, int access )
103 {
104 }
105
106 @Override
107 public FieldVisitor visitField( int access, String name, String desc, String signature, Object value )
108 {
109 return null;
110 }
111
112 @Override
113 public MethodVisitor visitMethod( int access, String name, String desc, String signature, String[] exceptions )
114 {
115 return null;
116 }
117
118 @Override
119 public void visitEnd()
120 {
121 }
122 }