congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ClassWriter
Code IndexAdd Tabnine to your IDE (free)

How to use
ClassWriter
in
cn.wensiqun.asmsupport.org.objectweb.asm

Best Java code snippets using cn.wensiqun.asmsupport.org.objectweb.asm.ClassWriter (Showing top 20 results out of 315)

origin: wensiqun/asmsupport

/**
 * Returns the index of the common super type of the two given types. This
 * method calls {@link #getCommonSuperClass} and caches the result in the
 * {@link #items} hash table to speedup future calls with the same
 * parameters.
 * 
 * @param type1
 *            index of an internal name in {@link #typeTable}.
 * @param type2
 *            index of an internal name in {@link #typeTable}.
 * @return the index of the common super type of the two given types.
 */
int getMergedType(final int type1, final int type2) {
  key2.type = TYPE_MERGED;
  key2.longVal = type1 | (((long) type2) << 32);
  key2.hashCode = 0x7FFFFFFF & (TYPE_MERGED + type1 + type2);
  Item result = get(key2);
  if (result == null) {
    String t = typeTable[type1].strVal1;
    String u = typeTable[type2].strVal1;
    key2.intVal = addType(getCommonSuperClass(t, u));
    result = new Item((short) 0, key2);
    put(result);
  }
  return result.intVal;
}
origin: wensiqun/asmsupport

        | cw.getMergedType(t & BASE_VALUE, u & BASE_VALUE);
  } else {
    v = vdim | OBJECT | cw.addType("java/lang/Object");
      : ELEMENT_OF) + (u & DIM);
  v = Math.min(tdim, udim) | OBJECT
      | cw.addType("java/lang/Object");
} else {
origin: wensiqun/asmsupport

/**
 * Adds a field reference to the constant pool of the class being build.
 * Does nothing if the constant pool already contains a similar item.
 * 
 * @param owner
 *            the internal name of the field's owner class.
 * @param name
 *            the field's name.
 * @param desc
 *            the field's descriptor.
 * @return a new or already existing field reference item.
 */
Item newFieldItem(final String owner, final String name, final String desc) {
  key3.set(FIELD, owner, name, desc);
  Item result = get(key3);
  if (result == null) {
    put122(FIELD, newClass(owner), newNameType(name, desc));
    result = new Item(index++, key3);
    put(result);
  }
  return result;
}
origin: wensiqun/asmsupport

@Override
public final void visitOuterClass(final String owner, final String name,
    final String desc) {
  enclosingMethodOwner = newClass(owner);
  if (name != null && desc != null) {
    enclosingMethod = newNameType(name, desc);
  }
}
origin: wensiqun/asmsupport

@Override
public final void visit(final int version, final int access,
    final String name, final String signature, final String superName,
    final String[] interfaces) {
  this.version = version;
  this.access = access;
  this.name = newClass(name);
  thisName = name;
  if (ClassReader.SIGNATURES && signature != null) {
    this.signature = newUTF8(signature);
  }
  this.superName = superName == null ? 0 : newClass(superName);
  if (interfaces != null && interfaces.length > 0) {
    interfaceCount = interfaces.length;
    this.interfaces = new int[interfaceCount];
    for (int i = 0; i < interfaceCount; ++i) {
      this.interfaces[i] = newClass(interfaces[i]);
    }
  }
}
origin: wensiqun/asmsupport

/**
 * Adds the given "uninitialized" type to {@link #typeTable} and returns its
 * index. This method is used for UNINITIALIZED types, made of an internal
 * name and a bytecode offset.
 * 
 * @param type
 *            the internal name to be added to the type table.
 * @param offset
 *            the bytecode offset of the NEW instruction that created this
 *            UNINITIALIZED type value.
 * @return the index of this internal name in the type table.
 */
int addUninitializedType(final String type, final int offset) {
  key.type = TYPE_UNINIT;
  key.intVal = offset;
  key.strVal1 = type;
  key.hashCode = 0x7FFFFFFF & (TYPE_UNINIT + type.hashCode() + offset);
  Item result = get(key);
  if (result == null) {
    result = addType(key);
  }
  return result.index;
}
origin: wensiqun/asmsupport

if (cst instanceof Integer) {
  int val = ((Integer) cst).intValue();
  return newInteger(val);
} else if (cst instanceof Byte) {
  int val = ((Byte) cst).intValue();
  return newInteger(val);
} else if (cst instanceof Character) {
  int val = ((Character) cst).charValue();
  return newInteger(val);
} else if (cst instanceof Short) {
  int val = ((Short) cst).intValue();
  return newInteger(val);
} else if (cst instanceof Boolean) {
  int val = ((Boolean) cst).booleanValue() ? 1 : 0;
  return newInteger(val);
} else if (cst instanceof Float) {
  float val = ((Float) cst).floatValue();
  return newFloat(val);
} else if (cst instanceof Long) {
  long val = ((Long) cst).longValue();
  return newLong(val);
} else if (cst instanceof Double) {
  double val = ((Double) cst).doubleValue();
  return newDouble(val);
} else if (cst instanceof String) {
  return newString((String) cst);
} else if (cst instanceof Type) {
  Type t = (Type) cst;
  int s = t.getSort();
origin: wensiqun/asmsupport

bootstrapMethods.putShort(newHandle(bsm.tag, bsm.owner, bsm.name,
    bsm.desc));
  Object bsmArg = bsmArgs[i];
  hashCode ^= bsmArg.hashCode();
  bootstrapMethods.putShort(newConst(bsmArg));
  result = new Item(bootstrapMethodIndex);
  result.set(position, hashCode);
  put(result);
result = get(key3);
if (result == null) {
  put122(INDY, bootstrapMethodIndex, newNameType(name, desc));
  result = new Item(index++, key3);
  put(result);
origin: wensiqun/asmsupport

  final String desc) {
key4.set(HANDLE_BASE + tag, owner, name, desc);
Item result = get(key4);
if (result == null) {
  if (tag <= Opcodes.H_PUTSTATIC) {
    put112(HANDLE, tag, newField(owner, name, desc));
  } else {
    put112(HANDLE,
        tag,
        newMethod(owner, name, desc,
            tag == Opcodes.H_INVOKEINTERFACE));
  put(result);
origin: wensiqun/asmsupport

/**
 * Adds a string to the constant pool of the class being build. Does nothing
 * if the constant pool already contains a similar item.
 * 
 * @param value
 *            the String value.
 * @return a new or already existing string item.
 */
private Item newString(final String value) {
  key2.set(STR, value, null, null);
  Item result = get(key2);
  if (result == null) {
    pool.put12(STR, newUTF8(value));
    result = new Item(index++, key2);
    put(result);
  }
  return result;
}
origin: wensiqun/asmsupport

/**
 * Adds a name and type to the constant pool of the class being build. Does
 * nothing if the constant pool already contains a similar item.
 * 
 * @param name
 *            a name.
 * @param desc
 *            a type descriptor.
 * @return a new or already existing name and type item.
 */
Item newNameTypeItem(final String name, final String desc) {
  key2.set(NAME_TYPE, name, desc, null);
  Item result = get(key2);
  if (result == null) {
    put122(NAME_TYPE, newUTF8(name), newUTF8(desc));
    result = new Item(index++, key2);
    put(result);
  }
  return result;
}
origin: wensiqun/asmsupport

/**
 * Adds an integer to the constant pool of the class being build. Does
 * nothing if the constant pool already contains a similar item.
 * 
 * @param value
 *            the int value.
 * @return a new or already existing int item.
 */
Item newInteger(final int value) {
  key.set(value);
  Item result = get(key);
  if (result == null) {
    pool.putByte(INT).putInt(value);
    result = new Item(index++, key);
    put(result);
  }
  return result;
}
origin: wensiqun/asmsupport

@Override
public final void visitInnerClass(final String name,
    final String outerName, final String innerName, final int access) {
  if (innerClasses == null) {
    innerClasses = new ByteVector();
  }
  // Sec. 4.7.6 of the JVMS states "Every CONSTANT_Class_info entry in the
  // constant_pool table which represents a class or interface C that is
  // not a package member must have exactly one corresponding entry in the
  // classes array". To avoid duplicates we keep track in the intVal field
  // of the Item of each CONSTANT_Class_info entry C whether an inner
  // class entry has already been added for C (this field is unused for
  // class entries, and changing its value does not change the hashcode
  // and equality tests). If so we store the index of this inner class
  // entry (plus one) in intVal. This hack allows duplicate detection in
  // O(1) time.
  Item nameItem = newClassItem(name);
  if (nameItem.intVal == 0) {
    ++innerClassesCount;
    innerClasses.putShort(nameItem.index);
    innerClasses.putShort(outerName == null ? 0 : newClass(outerName));
    innerClasses.putShort(innerName == null ? 0 : newUTF8(innerName));
    innerClasses.putShort(access);
    nameItem.intVal = innerClassesCount;
  } else {
    // Compare the inner classes entry nameItem.intVal - 1 with the
    // arguments of this method and throw an exception if there is a
    // difference?
  }
}
origin: wensiqun/asmsupport

newUTF8("BootstrapMethods");
newUTF8("Signature");
newUTF8("SourceFile");
newUTF8("SourceDebugExtension");
newUTF8("EnclosingMethod");
newUTF8("Deprecated");
  ++attributeCount;
  size += 6;
  newUTF8("Synthetic");
++attributeCount;
size += 8 + innerClasses.length;
newUTF8("InnerClasses");
newUTF8("RuntimeVisibleAnnotations");
newUTF8("RuntimeInvisibleAnnotations");
newUTF8("RuntimeVisibleTypeAnnotations");
newUTF8("RuntimeInvisibleTypeAnnotations");
out.putShort(newUTF8("BootstrapMethods"));
origin: wensiqun/asmsupport

if (local[i] instanceof String) {
  frame[frameIndex++] = Frame.OBJECT
      | cw.addType((String) local[i]);
} else if (local[i] instanceof Integer) {
  frame[frameIndex++] = ((Integer) local[i]).intValue();
} else {
  frame[frameIndex++] = Frame.UNINITIALIZED
      | cw.addUninitializedType("",
          ((Label) local[i]).position);
if (stack[i] instanceof String) {
  frame[frameIndex++] = Frame.OBJECT
      | cw.addType((String) stack[i]);
} else if (stack[i] instanceof Integer) {
  frame[frameIndex++] = ((Integer) stack[i]).intValue();
} else {
  frame[frameIndex++] = Frame.UNINITIALIZED
      | cw.addUninitializedType("",
          ((Label) stack[i]).position);
origin: wensiqun/asmsupport

int s;
if (t == UNINITIALIZED_THIS) {
  s = OBJECT | cw.addType(cw.thisName);
} else if ((t & (DIM | BASE_KIND)) == UNINITIALIZED) {
  String type = cw.typeTable[t & BASE_VALUE].strVal1;
  s = OBJECT | cw.addType(type);
} else {
  return t;
origin: wensiqun/asmsupport

@Override
public byte[] toBytes() {
  ClassExecuteContext context = new ClassExecuteContext();
  context.setClassLoader(classLoader);
  initialized(context);
  prepare();
  execute(context);
  return context.getClassVisitor().toByteArray();
}
origin: wensiqun/asmsupport

ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
cw.visit(sc.getVersion(), sc.getModifiers(),
    sc.getName().replace('.', '/'), null,
    Type.getInternalName(sc.getSuperclass().getName()), interfaceStrings);
origin: wensiqun/asmsupport

@Override
public void visitTryCatchBlock(final Label start, final Label end,
    final Label handler, final String type) {
  ++handlerCount;
  Handler h = new Handler();
  h.start = start;
  h.end = end;
  h.handler = handler;
  h.desc = type;
  h.type = type != null ? cw.newClass(type) : 0;
  if (lastHandler == null) {
    firstHandler = h;
  } else {
    lastHandler.next = h;
  }
  lastHandler = h;
}
origin: wensiqun/asmsupport

/**
 * Adds a class reference to the constant pool of the class being build.
 * Does nothing if the constant pool already contains a similar item.
 * <i>This method is intended for {@link Attribute} sub classes, and is
 * normally not needed by class generators or adapters.</i>
 * 
 * @param value
 *            the internal name of the class.
 * @return the index of a new or already existing class reference item.
 */
public int newClass(final String value) {
  return newClassItem(value).index;
}
cn.wensiqun.asmsupport.org.objectweb.asmClassWriter

Javadoc

A ClassVisitor that generates classes in bytecode form. More precisely this visitor generates a byte array conforming to the Java class file format. It can be used alone, to generate a Java class "from scratch", or with one or more ClassReader and adapter class visitor to generate a modified class from one or more existing Java classes.

Most used methods

  • toByteArray
    Returns the bytecode of the class that was build with this class writer.
  • <init>
    Constructs a new ClassWriter object and enables optimizations for "mostly add" bytecode transformati
  • addType
    Adds the given internal name to #typeTable and returns its index. Does nothing if the type table alr
  • addUninitializedType
    Adds the given "uninitialized" type to #typeTable and returns its index. This method is used for UNI
  • get
    Returns the constant pool's hash table item which is equal to the given item.
  • getCommonSuperClass
    Returns the common super type of the two given types. The default implementation of this method load
  • getMergedType
    Returns the index of the common super type of the two given types. This method calls #getCommonSuper
  • newClass
    Adds a class reference to the constant pool of the class being build. Does nothing if the constant p
  • newClassItem
    Adds a class reference to the constant pool of the class being build. Does nothing if the constant p
  • newConst
    Adds a number or string constant to the constant pool of the class being build. Does nothing if the
  • newConstItem
    Adds a number or string constant to the constant pool of the class being build. Does nothing if the
  • newDouble
    Adds a double to the constant pool of the class being build. Does nothing if the constant pool alrea
  • newConstItem,
  • newDouble,
  • newField,
  • newFieldItem,
  • newFloat,
  • newHandle,
  • newHandleItem,
  • newInteger,
  • newInvokeDynamicItem,
  • newLong

Popular in Java

  • Updating database using SQL prepared statement
  • onRequestPermissionsResult (Fragment)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • setRequestProperty (URLConnection)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • JOptionPane (javax.swing)
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now