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 implements ClassVisitor { 33 34 private boolean mHasNativeMethods = false; 35 36 public boolean hasNativeMethods() { 37 return mHasNativeMethods; 38 } 39 40 @VisibleForTesting(visibility=Visibility.PRIVATE) 41 protected void setHasNativeMethods(boolean hasNativeMethods, String methodName) { 42 mHasNativeMethods = hasNativeMethods; 43 } 44 45 public void visit(int version, int access, String name, String signature, 46 String superName, String[] interfaces) { 47 // pass 48 } 49 50 public AnnotationVisitor visitAnnotation(String desc, boolean visible) { 51 // pass 52 return null; 53 } 54 55 public void visitAttribute(Attribute attr) { 56 // pass 57 } 58 59 public void visitEnd() { 60 // pass 61 } 62 63 public FieldVisitor visitField(int access, String name, String desc, 64 String signature, Object value) { 65 // pass 66 return null; 67 } 68 69 public void visitInnerClass(String name, String outerName, 70 String innerName, int access) { 71 // pass 72 } 73 74 public MethodVisitor visitMethod(int access, String name, String desc, 75 String signature, String[] exceptions) { 76 if ((access & Opcodes.ACC_NATIVE) != 0) { 77 setHasNativeMethods(true, name); 78 } 79 return null; 80 } 81 82 public void visitOuterClass(String owner, String name, String desc) { 83 // pass 84 } 85 86 public void visitSource(String source, String debug) { 87 // pass 88 } 89 90} 91