private static Type getBoxedType(final Type type) { switch (type.getSort()) { case Type.BYTE: return Type.getObjectType("java/lang/Byte"); case Type.BOOLEAN: return Type.getObjectType("java/lang/Boolean"); case Type.SHORT: return Type.getObjectType("java/lang/Short"); case Type.CHAR: return Type.getObjectType("java/lang/Character"); case Type.INT: return Type.getObjectType("java/lang/Integer"); case Type.FLOAT: return Type.getObjectType("java/lang/Float"); case Type.LONG: return Type.getObjectType("java/lang/Long"); case Type.DOUBLE: return Type.getObjectType("java/lang/Double"); default: // no boxing required return type; } } }
Type mappedType(Type type) { String internalName = type.getInternalName(); String remappedInternalName = classesToRemap.get(internalName); if (remappedInternalName != null) { return Type.getObjectType(remappedInternalName); } else { return type; } }
@SuppressWarnings("rawtypes") private Type[] args(final Object... args) { Type[] result = new Type[args.length]; for (int i = 0; i < args.length; i++) { Object arg = args[i]; if (arg instanceof Class) { arg = ((Class) arg).getName(); } result[i] = Type.getObjectType(arg.toString().replace(".", "/")); } return result; }
MutableClass(ClassNode classNode, InstrumentationConfiguration config, ClassNodeProvider classNodeProvider) { this.classNode = classNode; this.config = config; this.classNodeProvider = classNodeProvider; this.internalClassName = classNode.name; this.className = classNode.name.replace('/', '.'); this.classType = Type.getObjectType(internalClassName); this.containsStubs = config.containsStubs(className); List<String> foundMethods = new ArrayList<>(classNode.methods.size()); for (MethodNode methodNode : getMethods()) { foundMethods.add(methodNode.name + methodNode.desc); } this.foundMethods = ImmutableSet.copyOf(foundMethods); }
/** * Intercepts the method using the invokedynamic bytecode instruction available in Java 7+. * Should be called through interceptInvokeVirtualMethod, not directly. */ private void interceptInvokeVirtualMethodWithInvokeDynamic( ListIterator<AbstractInsnNode> instructions, MethodInsnNode targetMethod) { instructions.remove(); // remove the method invocation Type type = Type.getObjectType(targetMethod.owner); String description = targetMethod.desc; String owner = type.getClassName(); if (targetMethod.getOpcode() != Opcodes.INVOKESTATIC) { String thisType = type.getDescriptor(); description = "(" + thisType + description.substring(1); } instructions.add(new InvokeDynamicInsnNode(targetMethod.name, description, BOOTSTRAP_INTRINSIC, owner)); } }
private String remapParamType(Type type) { String remappedName; String internalName; switch (type.getSort()) { case ARRAY: internalName = type.getInternalName(); int count = 0; while (internalName.charAt(count) == '[') count++; remappedName = remapParamType(internalName.substring(count)); if (remappedName != null) { return Type.getObjectType(internalName.substring(0, count) + remappedName).getDescriptor(); } break; case OBJECT: type = mappedType(type); break; default: break; } return type.getDescriptor(); } }
/** * Returns the abstract type corresponding to the given public API frame element type. * * @param symbolTable the type table to use to lookup and store type {@link Symbol}. * @param type a frame element type described using the same format as in {@link * MethodVisitor#visitFrame}, i.e. either {@link Opcodes#TOP}, {@link Opcodes#INTEGER}, {@link * Opcodes#FLOAT}, {@link Opcodes#LONG}, {@link Opcodes#DOUBLE}, {@link Opcodes#NULL}, or * {@link Opcodes#UNINITIALIZED_THIS}, or the internal name of a class, or a Label designating * a NEW instruction (for uninitialized types). * @return the abstract type corresponding to the given frame element type. */ static int getAbstractTypeFromApiFormat(final SymbolTable symbolTable, final Object type) { if (type instanceof Integer) { return CONSTANT_KIND | ((Integer) type).intValue(); } else if (type instanceof String) { String descriptor = Type.getObjectType((String) type).getDescriptor(); return getAbstractTypeFromDescriptor(symbolTable, descriptor, 0); } else { return UNINITIALIZED_KIND | symbolTable.addUninitializedType("", ((Label) type).bytecodeOffset); } }
for (TryCatchBlockNode tcb : methodNode.tryCatchBlocks) { target.traps.add(new Trap(getLabel(tcb.start), getLabel(tcb.end), new LabelStmt[]{getLabel(tcb.handler)}, new String[]{tcb.type == null ? null : Type.getObjectType(tcb.type).getDescriptor()})); int handlerIdx = insnList.indexOf(tcb.handler); handlers.set(handlerIdx);
v.visit("value", Type.getObjectType(nullnessAnnotationType.getClassName())); v.visitEnd();
return Double.longBitsToDouble(readLong(cpInfoOffset)); case Symbol.CONSTANT_CLASS_TAG: return Type.getObjectType(readUTF8(cpInfoOffset, charBuffer)); case Symbol.CONSTANT_STRING_TAG: return readUTF8(cpInfoOffset, charBuffer);
return Double.longBitsToDouble(readLong(index)); case CLASS: return Type.getObjectType(readUTF8(index, buf)); case STR: return readUTF8(index, buf);
proxyConstructorGenerator.getField(proxyType, FIELD_PROXY_METHODS, FIELD_TYPE_PROXY_METHODS); proxyConstructorGenerator.push(i); Type methodType = Type.getObjectType(executableMethodWriter.getInternalName()); proxyConstructorGenerator.newInstance(methodType); proxyConstructorGenerator.dup();
/** * Process the type represented by the name, possibly returning a rebased * name. */ private String processInternalName(String sourceType, String internalName) { if (internalName == null) { return null; } return processType(sourceType, Type.getObjectType(internalName)).getInternalName(); }
private @PolyNull Type hack(@PolyNull Type type) { if (type == null) { return null; } String internalName = type.getInternalName(); if (internalName.startsWith(rootPackageName) && !internalName.endsWith(MIXIN_SUFFIX)) { return Type.getObjectType(internalName + "_"); } else { return type; } }
@VisibleForTesting static Type getType(String type) { if (type.equals(Void.TYPE.getName())) { return Type.VOID_TYPE; } else if (type.equals(Boolean.TYPE.getName())) { return Type.BOOLEAN_TYPE; } else if (type.equals(Character.TYPE.getName())) { return Type.CHAR_TYPE; } else if (type.equals(Byte.TYPE.getName())) { return Type.BYTE_TYPE; } else if (type.equals(Short.TYPE.getName())) { return Type.SHORT_TYPE; } else if (type.equals(Integer.TYPE.getName())) { return Type.INT_TYPE; } else if (type.equals(Float.TYPE.getName())) { return Type.FLOAT_TYPE; } else if (type.equals(Long.TYPE.getName())) { return Type.LONG_TYPE; } else if (type.equals(Double.TYPE.getName())) { return Type.DOUBLE_TYPE; } else if (type.endsWith("[]")) { return getArrayType(type); } else { return Type.getObjectType(type.replace('.', '/')); } }
@RequiresNonNull("owner") private ImmutableInstrumentationConfig.Builder startBuilder() { Type type = Type.getObjectType(owner); Type[] argumentTypes = Type.getArgumentTypes(descriptor); ImmutableInstrumentationConfig.Builder builder = ImmutableInstrumentationConfig.builder() .className(type.getClassName()) .methodName(methodName); for (Type argumentType : argumentTypes) { builder.addMethodParameterTypes(argumentType.getClassName()); } return builder; } }
private LazyDefinedClass build(String internalName, byte[] origBytes) throws IOException { processed.add(internalName); PluginClassRemapper remapper = new PluginClassRemapper(); ImmutableLazyDefinedClass.Builder builder = ImmutableLazyDefinedClass.builder() .type(Type.getObjectType(remapper.mapType(internalName))); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); ClassVisitor cv = new ClassRemapper(cw, remapper); ClassReader cr = new ClassReader(origBytes); cr.accept(cv, 0); builder.bytes(cw.toByteArray()); for (String unprocessed : remapper.unprocessed) { builder.addDependencies(build(unprocessed)); } return builder.build(); }
@Override public void visit(int version, int access, String internalName, @Nullable String signature, @Nullable String superInternalName, String /*@Nullable*/ [] interfaceInternalNamesNullable) { type = Type.getObjectType(internalName); String[] interfacesIncludingMixins = getInterfacesIncludingShimsAndMixins( interfaceInternalNamesNullable, shimTypes, mixinTypes); cw.visit(version, access, internalName, signature, superInternalName, interfacesIncludingMixins); }
private void writeInterfaces(String keyword, String[] interfaces) throws SAXException { if (interfaces != null && interfaces.length > 0) { writeKeyword(keyword); String separator = " "; for (String iface : interfaces) { xhtml.characters(separator); writeType(Type.getObjectType(iface)); separator = ", "; } writeSpace(); } }
private ImmutablePointcutClass buildPointcutClass(byte[] bytes, boolean collocateInClassLoader, @Nullable File pluginJar) { ImmutablePointcutClass.Builder builder = ImmutablePointcutClass.builder() .type(Type.getObjectType(checkNotNull(name))); for (PointcutMethodVisitor methodVisitor : pointcutMethodVisitors) { builder.addMethods(methodVisitor.build()); } return builder.pointcut(checkNotNull(pointcutAnnotationVisitor).build()) .bytes(bytes) .collocateInClassLoader(collocateInClassLoader) .pluginJar(pluginJar) .build(); }