test/tools/javah/compareTest/FindNativeFiles.java

Mon, 16 Sep 2013 14:13:44 +0200

author
jlahoda
date
Mon, 16 Sep 2013 14:13:44 +0200
changeset 2028
4ce8148ffc4f
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8021112: Spurious unchecked warning reported by javac
6480588: No way to suppress deprecation warnings when implementing deprecated interface
Summary: Fixing DeferredLintHandler configuration, so lint warnings are reported with correct @SuppressWarnings settings
Reviewed-by: jjg, vromero

jjg@416 1 /*
ohair@554 2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
jjg@416 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@416 4 *
jjg@416 5 * This code is free software; you can redistribute it and/or modify it
jjg@416 6 * under the terms of the GNU General Public License version 2 only, as
jjg@416 7 * published by the Free Software Foundation.
jjg@416 8 *
jjg@416 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@416 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@416 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@416 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@416 13 * accompanied this code).
jjg@416 14 *
jjg@416 15 * You should have received a copy of the GNU General Public License version
jjg@416 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@416 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@416 18 *
ohair@554 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 20 * or visit www.oracle.com if you need additional information or have any
ohair@554 21 * questions.
jjg@416 22 */
jjg@416 23
jjg@416 24 import java.io.IOException;
jjg@416 25 import java.io.InputStream;
jjg@416 26 import java.util.Enumeration;
jjg@416 27 import java.util.jar.JarEntry;
jjg@416 28 import java.util.jar.JarFile;
jjg@416 29
jjg@416 30 import com.sun.tools.classfile.AccessFlags;
jjg@416 31 import com.sun.tools.classfile.ClassFile;
jjg@416 32 import com.sun.tools.classfile.ConstantPoolException;
jjg@416 33 import com.sun.tools.classfile.Method;
jjg@416 34 import java.util.Comparator;
jjg@416 35 import java.util.Set;
jjg@416 36 import java.util.TreeSet;
jjg@416 37
jjg@416 38 public class FindNativeFiles {
jjg@416 39 public static void main(String[] args) throws IOException, ConstantPoolException {
jjg@416 40 new FindNativeFiles().run(args);
jjg@416 41 }
jjg@416 42
jjg@416 43 public void run(String[] args) throws IOException, ConstantPoolException {
jjg@416 44 JarFile jar = new JarFile(args[0]);
jjg@416 45 Set<JarEntry> entries = getNativeClasses(jar);
jjg@416 46 for (JarEntry e: entries) {
jjg@416 47 String name = e.getName();
jjg@416 48 String className = name.substring(0, name.length() - 6).replace("/", ".");
jjg@416 49 System.out.println(className);
jjg@416 50 }
jjg@416 51 }
jjg@416 52
jjg@416 53 Set<JarEntry> getNativeClasses(JarFile jar) throws IOException, ConstantPoolException {
jjg@416 54 Set<JarEntry> results = new TreeSet<JarEntry>(new Comparator<JarEntry>() {
jjg@416 55 public int compare(JarEntry o1, JarEntry o2) {
jjg@416 56 return o1.getName().compareTo(o2.getName());
jjg@416 57 }
jjg@416 58 });
jjg@416 59 Enumeration<JarEntry> e = jar.entries();
jjg@416 60 while (e.hasMoreElements()) {
jjg@416 61 JarEntry je = e.nextElement();
jjg@416 62 if (isNativeClass(jar, je))
jjg@416 63 results.add(je);
jjg@416 64 }
jjg@416 65 return results;
jjg@416 66 }
jjg@416 67
jjg@416 68 boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
jjg@416 69 String name = entry.getName();
jjg@416 70 if (name.startsWith("META-INF") || !name.endsWith(".class"))
jjg@416 71 return false;
jjg@416 72 //String className = name.substring(0, name.length() - 6).replace("/", ".");
jjg@416 73 //System.err.println("check " + className);
jjg@416 74 InputStream in = jar.getInputStream(entry);
jjg@416 75 ClassFile cf = ClassFile.read(in);
jjg@416 76 in.close();
jjg@416 77 for (int i = 0; i < cf.methods.length; i++) {
jjg@416 78 Method m = cf.methods[i];
jjg@416 79 if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
jjg@416 80 // System.err.println(className);
jjg@416 81 return true;
jjg@416 82 }
jjg@416 83 }
jjg@416 84 return false;
jjg@416 85 }
jjg@416 86 }

mercurial