Package javassist.bytecode

Examples of javassist.bytecode.InnerClassesAttribute


            }

            ClassFile classFile = clazz.getClassFile2();
            AttributeInfo attribute = classFile.getAttribute(InnerClassesAttribute.tag);
            if (attribute != null && attribute instanceof InnerClassesAttribute) {
                InnerClassesAttribute ica = (InnerClassesAttribute) attribute;
                String name = classFile.getName();
                int n = ica.tableLength();
                for (int i = 0; i < n; ++i) {
                    if (name.equals(ica.innerClass(i))) {
                        int accessFlags = ica.accessFlags(i);
                        if (Modifier.isFinal(accessFlags)) {
                            ica.setAccessFlags(i, accessFlags ^ Modifier.FINAL);
                        }
                    }
                }
            }
        }
View Full Code Here


/*  394 */     return AccessFlag.toModifier(acc);
/*      */   }
/*      */
/*      */   public CtClass[] getNestedClasses() throws NotFoundException {
/*  398 */     ClassFile cf = getClassFile2();
/*  399 */     InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute("InnerClasses");
/*      */
/*  401 */     if (ica == null) {
/*  402 */       return new CtClass[0];
/*      */     }
/*  404 */     String thisName = cf.getName();
/*  405 */     int n = ica.tableLength();
/*  406 */     ArrayList list = new ArrayList(n);
/*  407 */     for (int i = 0; i < n; i++) {
/*  408 */       String outer = ica.outerClass(i);
/*      */
/*  413 */       if ((outer == null) || (outer.equals(thisName))) {
/*  414 */         String inner = ica.innerClass(i);
/*  415 */         if (inner != null) {
/*  416 */           list.add(this.classPool.get(inner));
/*      */         }
/*      */       }
/*      */     }
View Full Code Here

/*  734 */       getClassFile2().addInterface(anInterface.getName());
/*      */   }
/*      */
/*      */   public CtClass getDeclaringClass() throws NotFoundException {
/*  738 */     ClassFile cf = getClassFile2();
/*  739 */     InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute("InnerClasses");
/*      */
/*  741 */     if (ica == null) {
/*  742 */       return null;
/*      */     }
/*  744 */     String name = getName();
/*  745 */     int n = ica.tableLength();
/*  746 */     for (int i = 0; i < n; i++) {
/*  747 */       if (name.equals(ica.innerClass(i))) {
/*  748 */         String outName = ica.outerClass(i);
/*  749 */         if (outName != null) {
/*  750 */           return this.classPool.get(outName);
/*      */         }
/*      */
/*  753 */         EnclosingMethodAttribute ema = (EnclosingMethodAttribute)cf.getAttribute("EnclosingMethod");
View Full Code Here

/*      */
/*  782 */     checkModify();
/*  783 */     CtClass c = this.classPool.makeNestedClass(getName() + "$" + name);
/*  784 */     ClassFile cf = getClassFile2();
/*  785 */     ClassFile cf2 = c.getClassFile2();
/*  786 */     InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute("InnerClasses");
/*      */
/*  788 */     if (ica == null) {
/*  789 */       ica = new InnerClassesAttribute(cf.getConstPool());
/*  790 */       cf.addAttribute(ica);
/*      */     }
/*      */
/*  793 */     ica.append(c.getName(), getName(), name, cf2.getAccessFlags() & 0xFFFFFFDF | 0x8);
/*      */
/*  795 */     cf2.addAttribute(ica.copy(cf2.getConstPool(), null));
/*  796 */     return c;
/*      */   }
View Full Code Here

/* 37 */     updateInnerEntry(mod, getName(), this, true);
/*    */   }
/*    */
/*    */   private static void updateInnerEntry(int mod, String name, CtClass clazz, boolean outer) {
/* 41 */     ClassFile cf = clazz.getClassFile2();
/* 42 */     InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute("InnerClasses");
/*    */
/* 44 */     if (ica == null) {
/* 45 */       return;
/*    */     }
/* 47 */     int n = ica.tableLength();
/* 48 */     for (int i = 0; i < n; i++)
/* 49 */       if (name.equals(ica.innerClass(i))) {
/* 50 */         int acc = ica.accessFlags(i) & 0x8;
/* 51 */         ica.setAccessFlags(i, mod | acc);
/* 52 */         String outName = ica.outerClass(i);
/* 53 */         if ((outName == null) || (!outer)) break;
/*    */         try {
/* 55 */           CtClass parent = clazz.getClassPool().get(outName);
/* 56 */           updateInnerEntry(mod, name, parent, false);
/*    */         }
View Full Code Here

    }
  }
 
  private void writeInnerClasses( CtClass c, String obfOuterClassName, Collection<String> obfInnerClassNames )
  {
    InnerClassesAttribute attr = new InnerClassesAttribute( c.getClassFile().getConstPool() );
    c.getClassFile().addAttribute( attr );
    for( String obfInnerClassName : obfInnerClassNames )
    {
      // get the new inner class name
      ClassEntry obfClassEntry = new ClassEntry( obfOuterClassName + "$" + obfInnerClassName );
     
      // here's what the JVM spec says about the InnerClasses attribute
      // append( inner, outer of inner if inner is member of outer 0 ow, name after $ if inner not anonymous 0 ow, flags );
     
      // update the attribute with this inner class
      ConstPool constPool = c.getClassFile().getConstPool();
      int innerClassIndex = constPool.addClassInfo( obfClassEntry.getName() );
      int outerClassIndex = 0;
      int innerClassSimpleNameIndex = 0;
      if( !m_jarIndex.isAnonymousClass( obfInnerClassName ) )
      {
        outerClassIndex = constPool.addClassInfo( obfClassEntry.getOuterClassName() );
        innerClassSimpleNameIndex = constPool.addUtf8Info( obfClassEntry.getInnerClassName() );
      }
     
      attr.append(
        innerClassIndex,
        outerClassIndex,
        innerClassSimpleNameIndex,
        c.getClassFile().getAccessFlags() & ~AccessFlag.SUPER
      );
View Full Code Here

   
    c.replaceClassName( nameMap );
   
    // replace simple names in the InnerClasses attribute too
    ConstPool constants = c.getClassFile().getConstPool();
    InnerClassesAttribute attr = (InnerClassesAttribute)c.getClassFile().getAttribute( InnerClassesAttribute.tag );
    if( attr != null )
    {
      for( int i=0; i<attr.tableLength(); i++ )
      {
        ClassEntry classEntry = new ClassEntry( Descriptor.toJvmName( attr.innerClass( i ) ) );
        if( attr.innerNameIndex( i ) != 0 )
        {
          attr.setInnerNameIndex( i, constants.addUtf8Info( classEntry.getInnerClassName() ) );
        }
       
        /* DEBUG
        System.out.println( String.format( "\tDEOBF: %s-> ATTR: %s,%s,%s",
          classEntry,
View Full Code Here

TOP

Related Classes of javassist.bytecode.InnerClassesAttribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.