Java Code Examples for org.apache.bcel.classfile.JavaClass#instanceOf()
The following examples show how to use
org.apache.bcel.classfile.JavaClass#instanceOf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedundantInterfaces.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void visitClassContext(ClassContext classContext) { JavaClass obj = classContext.getJavaClass(); String superClassName = obj.getSuperclassName(); if (Values.DOTTED_JAVA_LANG_OBJECT.equals(superClassName)) { return; } String[] interfaceNames = obj.getInterfaceNames(); if ((interfaceNames == null) || (interfaceNames.length == 0)) { return; } try { JavaClass superObj = obj.getSuperClass(); SortedSet<String> redundantInfNames = new TreeSet<>(); for (String interfaceName : interfaceNames) { if (!"java.io.Serializable".equals(interfaceName)) { JavaClass inf = Repository.lookupClass(interfaceName); if (superObj.instanceOf(inf)) { redundantInfNames.add(inf.getClassName()); } } } if (redundantInfNames.size() > 0) { BugInstance bug = new BugInstance(this, "RI_REDUNDANT_INTERFACES", LOW_PRIORITY).addClass(obj); for (String redundantInfName : redundantInfNames) { bug.addClass(redundantInfName).describe("INTERFACE_TYPE"); } bugReporter.reportBug(bug); } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } }
Example 2
Source File: MultithreadedInstanceAccess.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void visitClassContext(ClassContext classContext) { try { JavaClass cls = classContext.getJavaClass(); String superClsName = cls.getSuperclassName(); if (Values.DOTTED_JAVA_LANG_OBJECT.equals(superClsName)) { return; } if (STRUTS_ACTION_NAME.equals(superClsName)) { mtClassName = STRUTS_ACTION_NAME; super.visitClassContext(classContext); } else if (SERVLET_NAME.equals(superClsName)) { mtClassName = SERVLET_NAME; super.visitClassContext(classContext); } else { for (JavaClass mtClass : getMtClasses()) { /* * note: We could just call cls.instanceOf(mtClass) and it * would work for both classes and interfaces, but if * mtClass is an interface it is more efficient to call * cls.implementationOf() and since we're doing this on each * visit that's what we'll do. also note: * implementationOf(mtClass) throws an * IllegalArgumentException when mtClass is not an * interface. See bug#1428253. */ if (mtClass.isClass() ? cls.instanceOf(mtClass) : cls.implementationOf(mtClass)) { mtClassName = mtClass.getClassName(); super.visitClassContext(classContext); return; } } } } catch (Exception e) { // already reported } }
Example 3
Source File: BadAppletConstructor.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void visitClassContext(ClassContext classContext) { if (appletClass == null) { return; } JavaClass cls = classContext.getJavaClass(); try { if (cls.instanceOf(appletClass)) { cls.accept(this); } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } }
Example 4
Source File: Repository.java From ApkToolPlus with Apache License 2.0 | 2 votes |
/** * Equivalent to runtime "instanceof" operator. * @return true, if clazz is an instance of super_class */ public static boolean instanceOf(JavaClass clazz, JavaClass super_class) { return clazz.instanceOf(super_class); }
Example 5
Source File: Repository.java From commons-bcel with Apache License 2.0 | 2 votes |
/** * Equivalent to runtime "instanceof" operator. * @return true, if clazz is an instance of super_class * @throws ClassNotFoundException if any superclasses or superinterfaces * of clazz can't be found */ public static boolean instanceOf( final JavaClass clazz, final JavaClass super_class ) throws ClassNotFoundException { return clazz.instanceOf(super_class); }