Java Code Examples for org.apache.bcel.Const#ATTR_INNER_CLASSES

The following examples show how to use org.apache.bcel.Const#ATTR_INNER_CLASSES . 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: ClassDumper.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
static ImmutableSet<String> listInnerClassNames(JavaClass javaClass) {
  ImmutableSet.Builder<String> innerClassNames = ImmutableSet.builder();
  String topLevelClassName = javaClass.getClassName();
  ConstantPool constantPool = javaClass.getConstantPool();
  for (Attribute attribute : javaClass.getAttributes()) {
    if (attribute.getTag() == Const.ATTR_INNER_CLASSES) {
      // This innerClasses variable does not include double-nested inner classes
      InnerClasses innerClasses = (InnerClasses) attribute;
      for (InnerClass innerClass : innerClasses.getInnerClasses()) {
        int classIndex = innerClass.getInnerClassIndex();
        String innerClassName = constantPool.getConstantString(classIndex, Const.CONSTANT_Class);
        int outerClassIndex = innerClass.getOuterClassIndex();
        if (outerClassIndex > 0) {
          String outerClassName =
              constantPool.getConstantString(outerClassIndex, Const.CONSTANT_Class);
          String normalOuterClassName = outerClassName.replace('/', '.');
          if (!normalOuterClassName.equals(topLevelClassName)) {
            continue;
          }
        }

        // Class names stored in constant pool have '/' as separator. We want '.' (as binary name)
        String normalInnerClassName = innerClassName.replace('/', '.');
        innerClassNames.add(normalInnerClassName);
      }
    }
  }
  return innerClassNames.build();
}
 
Example 2
Source File: InnerClasses.java    From commons-bcel with Apache License 2.0 2 votes vote down vote up
/**
 * @param name_index Index in constant pool to CONSTANT_Utf8
 * @param length Content length in bytes
 * @param innerClasses array of inner classes attributes
 * @param constant_pool Array of constants
 */
public InnerClasses(final int name_index, final int length, final InnerClass[] innerClasses,
        final ConstantPool constant_pool) {
    super(Const.ATTR_INNER_CLASSES, name_index, length, constant_pool);
    this.innerClasses = innerClasses != null ? innerClasses : new InnerClass[0];
}