/** Method invocation. */ public void visitInvokeInstruction(InvokeInstruction i) { Type[] argTypes = i.getArgumentTypes(cp); for (int j = 0; j < argTypes.length; j++) cv.registerCoupling(argTypes[j]); cv.registerCoupling(i.getReturnType(cp)); /* Measuring decision: measure overloaded methods separately */ cv.registerMethodInvocation(i.getClassName(cp), i.getMethodName(cp), argTypes); }
/** * Visits a field of the class. * * @param access the field's access flags (see {@link Opcodes}). This parameter also indicates if * the field is synthetic and/or deprecated. * @param name the field's name. * @param desc the field's descriptor (see {@link Type Type}). * @param signature the field's signature. May be <tt>null</tt> if the field's type does not use * generic types. * @param value the field's initial value. This parameter, which may be <tt>null</tt> if the field * does not have an initial value, must be an {@link Integer}, a {@link Float}, a {@link * Long}, a {@link Double} or a {@link String} (for <tt>int</tt>, <tt>float</tt>, * <tt>long</tt> or <tt>String</tt> fields respectively). <i>This parameter is only used for * static fields</i>. Its value is ignored for non static fields, which must be initialized * through bytecode instructions in constructors or methods. * @return a visitor to visit field annotations and attributes, or <tt>null</tt> if this class * visitor is not interested in visiting these annotations and attributes. */ public FieldVisitor visitField( int access, String name, String desc, String signature, Object value) { if (cv != null) { return cv.visitField(access, name, desc, signature, value); } return null; }
/** * Visits a method of the class. This method <i>must</i> return a new {@link MethodVisitor} * instance (or <tt>null</tt>) each time it is called, i.e., it should not return a previously * returned visitor. * * @param access the method's access flags (see {@link Opcodes}). This parameter also indicates if * the method is synthetic and/or deprecated. * @param name the method's name. * @param desc the method's descriptor (see {@link Type Type}). * @param signature the method's signature. May be <tt>null</tt> if the method parameters, return * type and exceptions do not use generic types. * @param exceptions the internal names of the method's exception classes (see {@link * Type#getInternalName() getInternalName}). May be <tt>null</tt>. * @return an object to visit the byte code of the method, or <tt>null</tt> if this class visitor * is not interested in visiting the code of this method. */ public MethodVisitor visitMethod( int access, String name, String desc, String signature, String[] exceptions) { if (cv != null) { return cv.visitMethod(access, name, desc, signature, exceptions); } return null; }
private void visitClass(String classFileName, ClassVisitor classVisitor) { try { CtClass current = GwtClassPool.getClass( classFileName.substring(0, classFileName.length() - ".class".length())); classVisitor.visit(current); for (CtClass innerClass : current.getNestedClasses()) { classVisitor.visit(innerClass); } } catch (NotFoundException e) { // do nothing } }
public FieldVisitor visitField( final int access, final String name, final String desc, final String signature, final Object value) { return cv.visitField(access, name, desc, signature, value); }
private FieldVisitor declareStaticField(ClassVisitor visitor, String name, Class<?> fieldClass) { return visitor.visitField( ACC_PRIVATE | ACC_FINAL | ACC_STATIC | ACC_SYNTHETIC, name, Type.getDescriptor(fieldClass), null, null); }
/** * Makes the given class visitor visit this method. * * @param cv a class visitor. */ public void accept(final ClassVisitor cv) { String[] exceptions = new String[this.exceptions.size()]; this.exceptions.toArray(exceptions); MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions); if (mv != null) { accept(mv); } }
public MethodVisitor visitMethod( final int access, final String name, final String desc, final String signature, final String[] exceptions) { return cv.visitMethod(access, name, desc, signature, exceptions); }
public void visit( final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) { cv.visit(version, access, name, signature, superName, interfaces); }
/** Visit the method's exception handlers. */ private void updateExceptionHandlers() { CodeExceptionGen[] handlers = mg.getExceptionHandlers(); /* Measuring decision: couple exceptions */ for (int i = 0; i < handlers.length; i++) { Type t = handlers[i].getCatchType(); if (t != null) cv.registerCoupling(t); } }
@Override public void visitEnd() { for (Map.Entry<Handle, Handle> entry : lambdaAccessToImplMethods.entrySet()) { Handle accessMethod = entry.getKey(); Handle implMethod = entry.getValue(); Bytecode.generateDelegateMethod(cv, ACC_STATIC | ACC_SYNTHETIC, accessMethod, implMethod); } super.visitEnd(); }
@Override public void visit( int version, int access, String name, String signature, String superName, String[] interfaces) { super.visit(version, access, name, FOO, superName, interfaces); }
private MethodVisitor declareMethod( ClassVisitor visitor, String methodName, String methodDescriptor, String methodSignature, int access) { MethodVisitor methodVisitor = visitor.visitMethod(access, methodName, methodDescriptor, methodSignature, NO_EXCEPTIONS); methodVisitor.visitCode(); return methodVisitor; }
/** * Visits the header of the class. * * @param version the class version. * @param access the class's access flags (see {@link Opcodes}). This parameter also indicates if * the class is deprecated. * @param name the internal name of the class (see {@link Type#getInternalName() * getInternalName}). * @param signature the signature of this class. May be <tt>null</tt> if the class is not a * generic one, and does not extend or implement generic classes or interfaces. * @param superName the internal of name of the super class (see {@link Type#getInternalName() * getInternalName}). For interfaces, the super class is {@link Object}. May be <tt>null</tt>, * but only for the {@link Object} class. * @param interfaces the internal names of the class's interfaces (see {@link * Type#getInternalName() getInternalName}). May be <tt>null</tt>. */ public void visit( int version, int access, String name, String signature, String superName, String[] interfaces) { if (cv != null) { cv.visit(version, access, name, signature, superName, interfaces); } }
@Override public void visit( int version, int access, String name, String signature, String superName, String[] interfaces) { resetLambdaClassSequenceNumber(); this.classAccess = access; this.className = name; super.visit(version, access, name, signature, superName, interfaces); }
private void declareClass( ClassVisitor visitor, Collection<String> interfaceInternalNames, Type generatedType, Type superclassType) { visitor.visit( V1_6, ACC_PUBLIC, generatedType.getInternalName(), null, superclassType.getInternalName(), Iterables.toArray(interfaceInternalNames, String.class)); }
/** * Makes the given class visitor visit this class. * * @param cv a class visitor. */ public void accept(final ClassVisitor cv) { // visits header String[] interfaces = new String[this.interfaces.size()]; this.interfaces.toArray(interfaces); cv.visit(version, access, name, signature, superName, interfaces); // visits source if (sourceFile != null || sourceDebug != null) { cv.visitSource(sourceFile, sourceDebug); } // visits outer class if (outerClass != null) { cv.visitOuterClass(outerClass, outerMethod, outerMethodDesc); } // visits attributes int i, n; n = visibleAnnotations == null ? 0 : visibleAnnotations.size(); for (i = 0; i < n; ++i) { AnnotationNode an = visibleAnnotations.get(i); an.accept(cv.visitAnnotation(an.desc, true)); } n = invisibleAnnotations == null ? 0 : invisibleAnnotations.size(); for (i = 0; i < n; ++i) { AnnotationNode an = invisibleAnnotations.get(i); an.accept(cv.visitAnnotation(an.desc, false)); } n = attrs == null ? 0 : attrs.size(); for (i = 0; i < n; ++i) { cv.visitAttribute(attrs.get(i)); } // visits inner classes for (i = 0; i < innerClasses.size(); ++i) { innerClasses.get(i).accept(cv); } // visits fields for (i = 0; i < fields.size(); ++i) { fields.get(i).accept(cv); } // visits methods for (i = 0; i < methods.size(); ++i) { methods.get(i).accept(cv); } // visits end cv.visitEnd(); }
private void writeEqualsMethod(ClassVisitor cw, Type generatedType) { MethodVisitor methodVisitor = cw.visitMethod(Opcodes.ACC_PUBLIC, "equals", EQUALS_METHOD_DESCRIPTOR, null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitVarInsn(ALOAD, 1); Label notSameLabel = new Label(); methodVisitor.visitJumpInsn(IF_ACMPNE, notSameLabel); methodVisitor.visitInsn(ICONST_1); methodVisitor.visitInsn(IRETURN); methodVisitor.visitLabel(notSameLabel); methodVisitor.visitVarInsn(ALOAD, 1); methodVisitor.visitTypeInsn(INSTANCEOF, MANAGED_INSTANCE_TYPE); Label notManagedInstanceLabel = new Label(); methodVisitor.visitJumpInsn(IFNE, notManagedInstanceLabel); methodVisitor.visitInsn(ICONST_0); methodVisitor.visitInsn(IRETURN); methodVisitor.visitLabel(notManagedInstanceLabel); methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitMethodInsn( INVOKEVIRTUAL, generatedType.getInternalName(), "getBackingNode", GET_BACKING_NODE_METHOD_DESCRIPTOR, false); methodVisitor.visitVarInsn(ALOAD, 1); methodVisitor.visitTypeInsn(CHECKCAST, MANAGED_INSTANCE_TYPE); methodVisitor.visitMethodInsn( INVOKEINTERFACE, MANAGED_INSTANCE_TYPE, "getBackingNode", GET_BACKING_NODE_METHOD_DESCRIPTOR, true); methodVisitor.visitMethodInsn( INVOKEINTERFACE, MUTABLE_MODEL_NODE_TYPE, "equals", EQUALS_METHOD_DESCRIPTOR, true); finishVisitingMethod(methodVisitor, Opcodes.IRETURN); }
/** * Visits the end of the class. This method, which is the last one to be called, is used to inform * the visitor that all the fields and methods of the class have been visited. */ public void visitEnd() { if (cv != null) { cv.visitEnd(); } }
/** * Visits information about an inner class. This inner class is not necessarily a member of the * class being visited. * * @param name the internal name of an inner class (see {@link Type#getInternalName() * getInternalName}). * @param outerName the internal name of the class to which the inner class belongs (see {@link * Type#getInternalName() getInternalName}). May be <tt>null</tt> for not member classes. * @param innerName the (simple) name of the inner class inside its enclosing class. May be * <tt>null</tt> for anonymous inner classes. * @param access the access flags of the inner class as originally declared in the enclosing * class. */ public void visitInnerClass(String name, String outerName, String innerName, int access) { if (cv != null) { cv.visitInnerClass(name, outerName, innerName, access); } }
/** * Visits a non standard attribute of the class. * * @param attr an attribute. */ public void visitAttribute(Attribute attr) { if (cv != null) { cv.visitAttribute(attr); } }
/** * Visits an annotation of the class. * * @param desc the class descriptor of the annotation class. * @param visible <tt>true</tt> if the annotation is visible at runtime. * @return a visitor to visit the annotation values, or <tt>null</tt> if this visitor is not * interested in visiting this annotation. */ public AnnotationVisitor visitAnnotation(String desc, boolean visible) { if (cv != null) { return cv.visitAnnotation(desc, visible); } return null; }
public void visitInnerClass( final String name, final String outerName, final String innerName, final int access) { cv.visitInnerClass(name, outerName, innerName, access); }
public void accept(ClassVisitor cv) { cv.visitField(access, name, type.getDescriptor(), null /*generics*/, null /*value*/); }
public void accept(ClassVisitor classVisitor) { classVisitor.visitLibraryClass(this); }
public void visitLibraryClass(LibraryClass libraryClass) { if (accepted(libraryClass.getAccessFlags())) { classVisitor.visitLibraryClass(libraryClass); } }
public void visitProgramClass(ProgramClass programClass) { if (accepted(programClass.getAccessFlags())) { classVisitor.visitProgramClass(programClass); } }
public void visitEnd() { cv.visitEnd(); }
/** * Visits the source of the class. * * @param source the name of the source file from which the class was compiled. May be * <tt>null</tt>. * @param debug additional debug information to compute the correspondance between source and * compiled elements of the class. May be <tt>null</tt>. */ public void visitSource(String source, String debug) { if (cv != null) { cv.visitSource(source, debug); } }
/** * Visits the enclosing class of the class. This method must be called only if the class has an * enclosing class. * * @param owner internal name of the enclosing class of the class. * @param name the name of the method that contains the class, or <tt>null</tt> if the class is * not enclosed in a method of its enclosing class. * @param desc the descriptor of the method that contains the class, or <tt>null</tt> if the class * is not enclosed in a method of its enclosing class. */ public void visitOuterClass(String owner, String name, String desc) { if (cv != null) { cv.visitOuterClass(owner, name, desc); } }