Java Code Examples for org.apache.bcel.Constants#ACC_SUPER

The following examples show how to use org.apache.bcel.Constants#ACC_SUPER . 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: Utility.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
  * Convert bit field of flags into string such as `static final'.
  *
  * Special case: Classes compiled with new compilers and with the
  * `ACC_SUPER' flag would be said to be "synchronized". This is
  * because SUN used the same value for the flags `ACC_SUPER' and
  * `ACC_SYNCHRONIZED'. 
  *
  * @param  access_flags Access flags
  * @param  for_class access flags are for class qualifiers ?
  * @return String representation of flags
  */
 public static final String accessToString(int access_flags, 
				    boolean for_class)
 {
   StringBuffer buf = new StringBuffer();

   int p = 0;
   for(int i=0; p < Constants.MAX_ACC_FLAG; i++) { // Loop through known flags
     p = pow2(i);

     if((access_flags & p) != 0) {
/* Special case: Classes compiled with new compilers and with the
 * `ACC_SUPER' flag would be said to be "synchronized". This is
 * because SUN used the same value for the flags `ACC_SUPER' and
 * `ACC_SYNCHRONIZED'.
 */
if(for_class && ((p == Constants.ACC_SUPER) || (p == Constants.ACC_INTERFACE)))
  continue;	    

buf.append(Constants.ACCESS_NAMES[i] + " ");
     }
   }

   return buf.toString().trim();
 }
 
Example 2
Source File: ClassPathLoaderJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
  ClassGen cg = new ClassGen(name, "java.lang.Object", "<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, null);
  cg.addEmptyConstructor(Constants.ACC_PUBLIC);
  JavaClass jClazz = cg.getJavaClass();
  byte[] bytes = jClazz.getBytes();
  return defineClass(jClazz.getClassName(), bytes, 0, bytes.length);
}
 
Example 3
Source File: ClassPathLoaderJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
  ClassGen cg = new ClassGen(name, "java.lang.Object", "<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, null);
  cg.addEmptyConstructor(Constants.ACC_PUBLIC);
  JavaClass jClazz = cg.getJavaClass();
  byte[] bytes = jClazz.getBytes();
  return defineClass(jClazz.getClassName(), bytes, 0, bytes.length);
}
 
Example 4
Source File: JavaClass.java    From ApkToolPlus with Apache License 2.0 4 votes vote down vote up
public final boolean isSuper() {
  return (access_flags & Constants.ACC_SUPER) != 0;
}
 
Example 5
Source File: JavaBuilder.java    From luaj with MIT License 4 votes vote down vote up
public JavaBuilder(ProtoInfo pi, String classname, String filename) {
	this.pi = pi;
	this.p = pi.prototype;
	this.classname = classname;
	
	// what class to inherit from
	superclassType = p.numparams;
	if ( p.is_vararg != 0 || superclassType >= SUPERTYPE_VARARGS )
		superclassType = SUPERTYPE_VARARGS;
	for ( int i=0, n=p.code.length; i<n; i++ ) {
		int inst = p.code[i];
		int o = Lua.GET_OPCODE(inst);
		if ( (o == Lua.OP_TAILCALL) ||
		     ((o == Lua.OP_RETURN) && (Lua.GETARG_B(inst) < 1 || Lua.GETARG_B(inst) > 2)) ) {
			superclassType = SUPERTYPE_VARARGS;
			break;
		}
	}
	
	// create class generator
	cg = new ClassGen(classname, SUPER_NAME_N[superclassType], filename,
			Constants.ACC_PUBLIC | Constants.ACC_SUPER, null);
	cp = cg.getConstantPool(); // cg creates constant pool

	// main instruction lists
	factory = new InstructionFactory(cg);
	init = new InstructionList();
	main = new InstructionList();

	// create the fields
	for ( int i=0; i<p.upvalues.length; i++ ) {
		boolean isrw = pi.isReadWriteUpvalue( pi.upvals[i] ); 
		Type uptype = isrw? (Type) TYPE_LOCALUPVALUE: (Type) TYPE_LUAVALUE;
		FieldGen fg = new FieldGen(0, uptype, upvalueName(i), cp);
		cg.addField(fg.getField());
	}
	
	// create the method
	mg = new MethodGen( Constants.ACC_PUBLIC | Constants.ACC_FINAL, // access flags
			RETURN_TYPE_N[superclassType], // return type
			ARG_TYPES_N[superclassType], // argument types
			ARG_NAMES_N[superclassType], // arg names
			METH_NAME_N[superclassType], 
			STR_LUAVALUE, // method, defining class
			main, cp);
	
	// initialize the values in the slots
	initializeSlots();	

	// initialize branching
	int nc = p.code.length;
	targets = new int[nc];
	branches = new BranchInstruction[nc];
	branchDestHandles = new InstructionHandle[nc];
	lastInstrHandles = new InstructionHandle[nc];
}