@Override public AnnotationVisitor visitAnnotation(final String name, final String descriptor) { // Case of an element_value with an annotation_value field. // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.16.1. ++numElementValuePairs; if (useNamedValues) { annotation.putShort(symbolTable.addConstantUtf8(name)); } // Write tag and type_index, and reserve 2 bytes for num_element_value_pairs. annotation.put12('@', symbolTable.addConstantUtf8(descriptor)).putShort(0); return new AnnotationWriter(symbolTable, annotation, null); }
/** * Adds a new CONSTANT_Long_info or CONSTANT_Double_info to the constant pool of this symbol * table. * * @param index the constant pool index of the new Symbol. * @param tag one of {@link Symbol#CONSTANT_LONG_TAG} or {@link Symbol#CONSTANT_DOUBLE_TAG}. * @param value a long or double. */ private void addConstantLongOrDouble(final int index, final int tag, final long value) { add(new Entry(index, tag, value, hash(tag, value))); }
@Override public void visitParameter(final String name, final int access) { if (parameters == null) { parameters = new ByteVector(); } ++parametersCount; parameters.putShort((name == null) ? 0 : symbolTable.addConstantUtf8(name)).putShort(access); }
@Override public void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels) { lastBytecodeOffset = code.length; // Add the instruction to the bytecode of the method. code.putByte(Opcodes.LOOKUPSWITCH).putByteArray(null, 0, (4 - code.length % 4) % 4); dflt.put(code, lastBytecodeOffset, true); code.putInt(labels.length); for (int i = 0; i < labels.length; ++i) { code.putInt(keys[i]); labels[i].put(code, lastBytecodeOffset, true); } // If needed, update the maximum stack size and number of locals, and stack map frames. visitSwitchInsn(dflt, labels); }
@Override public void visitEnum(final String name, final String descriptor, final String value) { // Case of an element_value with an enum_const_value field. // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.16.1. ++numElementValuePairs; if (useNamedValues) { annotation.putShort(symbolTable.addConstantUtf8(name)); } annotation .put12('e', symbolTable.addConstantUtf8(descriptor)) .putShort(symbolTable.addConstantUtf8(value)); }
@Override public void visitNestMember(final String nestMember) { if (nestMemberClasses == null) { nestMemberClasses = new ByteVector(); } ++numberOfNestMemberClasses; nestMemberClasses.putShort(symbolTable.addConstantClass(nestMember).index); }
@Override public void visitExport(final String packaze, final int access, final String... modules) { exports.putShort(symbolTable.addConstantPackage(packaze).index).putShort(access); if (modules == null) { exports.putShort(0); } else { exports.putShort(modules.length); for (String module : modules) { exports.putShort(symbolTable.addConstantModule(module).index); } } exportsCount++; }
@Override public final void visitSource(final String file, final String debug) { if (file != null) { sourceFileIndex = symbolTable.addConstantUtf8(file); } if (debug != null) { debugExtension = new ByteVector().encodeUtf8(debug, 0, Integer.MAX_VALUE); } }
@Override public void visitRequire(final String module, final int access, final String version) { requires .putShort(symbolTable.addConstantModule(module).index) .putShort(access) .putShort(version == null ? 0 : symbolTable.addConstantUtf8(version)); requiresCount++; }
@Override public final ModuleVisitor visitModule( final String name, final int access, final String version) { return moduleWriter = new ModuleWriter( symbolTable, symbolTable.addConstantModule(name).index, access, version == null ? 0 : symbolTable.addConstantUtf8(version)); }
@Override public AnnotationVisitor visitAnnotationDefault() { defaultValue = new ByteVector(); return new AnnotationWriter(symbolTable, /* useNamedValues = */ false, defaultValue, null); }
@Override public void visitProvide(final String service, final String... providers) { provides.putShort(symbolTable.addConstantClass(service).index); provides.putShort(providers.length); for (String provider : providers) { provides.putShort(symbolTable.addConstantClass(provider).index); } providesCount++; }
@Override public void visitPackage(final String packaze) { packageIndex.putShort(symbolTable.addConstantPackage(packaze).index); packageCount++; }
@Override public void visitTryCatchBlock( final Label start, final Label end, final Label handler, final String type) { Handler newHandler = new Handler( start, end, handler, type != null ? symbolTable.addConstantClass(type).index : 0, type); if (firstHandler == null) { firstHandler = newHandler; } else { lastHandler.nextHandler = newHandler; } lastHandler = newHandler; }
@Override public void visitTableSwitchInsn( final int min, final int max, final Label dflt, final Label... labels) { lastBytecodeOffset = code.length; // Add the instruction to the bytecode of the method. code.putByte(Opcodes.TABLESWITCH).putByteArray(null, 0, (4 - code.length % 4) % 4); dflt.put(code, lastBytecodeOffset, true); code.putInt(min).putInt(max); for (Label label : labels) { label.put(code, lastBytecodeOffset, true); } // If needed, update the maximum stack size and number of locals, and stack map frames. visitSwitchInsn(dflt, labels); }
/** * Adds a new CONSTANT_String_info to the constant pool of this symbol table. * * @param index the constant pool index of the new Symbol. * @param value a string. */ private void addConstantUtf8(final int index, final String value) { add(new Entry(index, Symbol.CONSTANT_UTF8_TAG, value, hash(Symbol.CONSTANT_UTF8_TAG, value))); }
@Override public void visitOpen(final String packaze, final int access, final String... modules) { opens.putShort(symbolTable.addConstantPackage(packaze).index).putShort(access); if (modules == null) { opens.putShort(0); } else { opens.putShort(modules.length); for (String module : modules) { opens.putShort(symbolTable.addConstantModule(module).index); } } opensCount++; }
@Override public void visitUse(final String service) { usesIndex.putShort(symbolTable.addConstantClass(service).index); usesCount++; }
/** * Adds a new CONSTANT_Integer_info or CONSTANT_Float_info to the constant pool of this symbol * table. * * @param index the constant pool index of the new Symbol. * @param tag one of {@link Symbol#CONSTANT_INTEGER_TAG} or {@link Symbol#CONSTANT_FLOAT_TAG}. * @param value an int or float. */ private void addConstantIntegerOrFloat(final int index, final int tag, final int value) { add(new Entry(index, tag, value, hash(tag, value))); }
/** * Adds a new CONSTANT_NameAndType_info to the constant pool of this symbol table. * * @param index the constant pool index of the new Symbol. * @param name a field or method name. * @param descriptor a field or method descriptor. */ private void addConstantNameAndType(final int index, final String name, final String descriptor) { final int tag = Symbol.CONSTANT_NAME_AND_TYPE_TAG; add(new Entry(index, tag, name, descriptor, hash(tag, name, descriptor))); }