1/*
2 * Copyright (C) 2008 The Android Open Source Project
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
17package com.android.tools.layoutlib.create;
18
19import com.android.tools.layoutlib.annotations.VisibleForTesting;
20import com.android.tools.layoutlib.annotations.VisibleForTesting.Visibility;
21
22import org.objectweb.asm.AnnotationVisitor;
23import org.objectweb.asm.Attribute;
24import org.objectweb.asm.ClassVisitor;
25import org.objectweb.asm.FieldVisitor;
26import org.objectweb.asm.MethodVisitor;
27import org.objectweb.asm.Opcodes;
28
29/**
30 * Indicates if a class contains any native methods.
31 */
32public class ClassHasNativeVisitor extends ClassVisitor {
33    public ClassHasNativeVisitor() {
34        super(Opcodes.ASM4);
35    }
36
37    private boolean mHasNativeMethods = false;
38
39    public boolean hasNativeMethods() {
40        return mHasNativeMethods;
41    }
42
43    @VisibleForTesting(visibility=Visibility.PRIVATE)
44    protected void setHasNativeMethods(boolean hasNativeMethods, String methodName) {
45        mHasNativeMethods = hasNativeMethods;
46    }
47
48    @Override
49    public void visit(int version, int access, String name, String signature,
50            String superName, String[] interfaces) {
51        // pass
52    }
53
54    @Override
55    public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
56        // pass
57        return null;
58    }
59
60    @Override
61    public void visitAttribute(Attribute attr) {
62        // pass
63    }
64
65    @Override
66    public void visitEnd() {
67        // pass
68    }
69
70    @Override
71    public FieldVisitor visitField(int access, String name, String desc,
72            String signature, Object value) {
73        // pass
74        return null;
75    }
76
77    @Override
78    public void visitInnerClass(String name, String outerName,
79            String innerName, int access) {
80        // pass
81    }
82
83    @Override
84    public MethodVisitor visitMethod(int access, String name, String desc,
85            String signature, String[] exceptions) {
86        if ((access & Opcodes.ACC_NATIVE) != 0) {
87            setHasNativeMethods(true, name);
88        }
89        return null;
90    }
91
92    @Override
93    public void visitOuterClass(String owner, String name, String desc) {
94        // pass
95    }
96
97    @Override
98    public void visitSource(String source, String debug) {
99        // pass
100    }
101
102}
103