List of usage examples for org.objectweb.asm Opcodes ACC_STATIC
int ACC_STATIC
To view the source code for org.objectweb.asm Opcodes ACC_STATIC.
Click Source Link
From source file:net.enilink.composition.asm.CompositeClassNode.java
License:Open Source License
@SuppressWarnings("unchecked") public FieldNode addStaticMethodField(Type declaringClass, String name, Type returnType, Type[] paramTypes) { List<?> key = Arrays.asList(declaringClass, name, Arrays.asList(paramTypes)); FieldNode field = methodFields.get(key); if (field == null) { field = new FieldNode(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, "_$method" + ++varCount, Type.getDescriptor(Method.class), null, null); fields.add(field);/*from w w w . ja va 2 s. c om*/ methodFields.put(key, field); MethodNodeGenerator gen = getClassInitGen(); gen.push(declaringClass); gen.push(name); gen.loadArray(paramTypes); gen.invokeVirtual(Type.getType(Class.class), new org.objectweb.asm.commons.Method("getDeclaredMethod", Type.getType(Method.class), new Type[] { Type.getType(String.class), Type.getType(Class[].class) })); gen.putStatic(getType(), field.name, Type.getType(field.desc)); } return field; }
From source file:net.enilink.composition.asm.ExtendedClassNode.java
License:Open Source License
@SuppressWarnings("unchecked") public MethodNodeGenerator getClassInitGen() { if (clinitGen == null) { MethodNode clinit = new MethodNode(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); methods.add(clinit);/*from w w w. j av a 2 s .co m*/ clinitGen = new MethodNodeGenerator(clinit); } return clinitGen; }
From source file:net.sf.clirr.core.internal.asm.AsmField.java
License:Open Source License
public boolean isStatic() { return checkFlag(Opcodes.ACC_STATIC); }
From source file:net.sf.profiler4j.agent.BytecodeTransformer.java
License:Apache License
private static boolean isGetterSetter(int flag, String name, String methodDescriptor) { if ((Opcodes.ACC_PUBLIC | flag) == 0 || ((Opcodes.ACC_STATIC | flag) | (Opcodes.ACC_NATIVE | flag) | (Opcodes.ACC_ABSTRACT | flag) | (Opcodes.ACC_SYNCHRONIZED | flag)) != 0) { return false; }//from w w w .jav a 2 s .c om Type[] pTypes = Type.getArgumentTypes(methodDescriptor); Type rType = Type.getReturnType(methodDescriptor); if (getterRegex.matcher(name).matches() || getterBoolRegex.matcher(name).matches()) { return pTypes.length == 0 && !rType.equals(Type.VOID_TYPE); } if (setterRegex.matcher(name).matches()) { return pTypes.length == 1 && !rType.equals(Type.VOID_TYPE); } return false; }
From source file:net.sourceforge.cobertura.instrument.ClassInstrumenter.java
License:Open Source License
public void visitEnd() { if (instrument) { FieldVisitor visitor = super.visitField(Opcodes.ACC_PRIVATE & Opcodes.ACC_STATIC & Opcodes.ACC_FINAL, HAS_BEEN_INSTRUMENTED_FIELD_NAME, Type.BOOLEAN_TYPE.toString(), null, true); visitor.visitEnd();//from w ww .j av a 2 s . c o m } if (instrument && classData.getNumberOfValidLines() == 0) logger.warning("No line number information found for class " + this.myName + ". Perhaps you need to compile with debug=true?"); }
From source file:net.sourceforge.cobertura.instrument.pass2.BuildClassMapClassVisitor.java
License:GNU General Public License
/** * Analyzes given method and stores information about all found important places into {@link #classMap} *///from www. j a v a 2 s . c om @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (((access & Opcodes.ACC_STATIC) != 0) && CodeProvider.COBERTURA_INIT_METHOD_NAME.equals(name)) { toInstrument = false; // The class has bean already instrumented. } MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); if (ignoredMethods.contains(name + desc)) { return mv; } FindTouchPointsMethodAdapter instrumenter = new FindTouchPointsMethodAdapter( new HistoryMethodAdapter(mv, 4), classMap.getClassName(), name, desc, eventIdGenerator, duplicatedLinesMap, lineIdGenerator); instrumenter.setTouchPointListener(touchPointListener); instrumenter.setIgnoreRegexp(getIgnoreRegexp()); return instrumenter; }
From source file:net.sourceforge.cobertura.instrument.pass3.AbstractCodeProvider.java
License:GNU General Public License
/** * {@inheritDoc}<br/><br/>// w w w. j a v a 2 s .c o m * <p/> * Generates method (named {@link #COBERTURA_CLASSMAP_METHOD_NAME}) with such a signature: * __cobertura_classmap( {@link LightClassmapListener} listener).</br> * <p/> * The method informs the listener about all lines, jumps and switches found, and about all counters tracking * the constructions. */ public void generateCoberturaClassMapMethod(ClassVisitor cv, ClassMap classMap) { LinkedList<TouchPointDescriptor> touchPointDescriptors = new LinkedList<TouchPointDescriptor>( classMap.getTouchPointsInLineOrder()); int parts = 0; for (int j = 0; touchPointDescriptors.size() > 0; j++) { List<TouchPointDescriptor> bufor = new LinkedList<TouchPointDescriptor>(); for (int i = 0; i < 1000 && touchPointDescriptors.size() > 0; i++) { bufor.add(touchPointDescriptors.removeFirst()); } classMapContent(cv, j, bufor); parts++; } MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, COBERTURA_CLASSMAP_METHOD_NAME, "(" + Type.getType(LightClassmapListener.class).toString() + ")V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(classMap.getClassName()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "setClazz", "(Ljava/lang/String;)V"); if (classMap.getSource() != null) { mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(classMap.getSource()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "setSource", "(Ljava/lang/String;)V"); } for (int i = 0; i < parts; i++) { mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, classMap.getClassName(), COBERTURA_CLASSMAP_METHOD_NAME + "_" + i, "(" + Type.getType(LightClassmapListener.class).toString() + ")V"); } mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0);//will be recalculated by writer mv.visitEnd(); }
From source file:net.sourceforge.cobertura.instrument.pass3.AbstractCodeProvider.java
License:GNU General Public License
private void classMapContent(ClassVisitor cv, int nr, List<TouchPointDescriptor> touchPointDescriptors) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, COBERTURA_CLASSMAP_METHOD_NAME + "_" + nr, "(" + Type.getType(LightClassmapListener.class).toString() + ")V", null, null); mv.visitCode();//from ww w . j av a 2 s . co m mv.visitVarInsn(Opcodes.ALOAD, 0); for (TouchPointDescriptor tpd : touchPointDescriptors) { mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(tpd.getLineNumber()); if (tpd instanceof LineTouchPointDescriptor) { mv.visitLdcInsn(((LineTouchPointDescriptor) tpd).getCounterId()); mv.visitLdcInsn(((LineTouchPointDescriptor) tpd).getMethodName()); mv.visitLdcInsn(((LineTouchPointDescriptor) tpd).getMethodSignature()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "putLineTouchPoint", "(IILjava/lang/String;Ljava/lang/String;)V"); } else if (tpd instanceof JumpTouchPointDescriptor) { mv.visitLdcInsn(((JumpTouchPointDescriptor) tpd).getCounterIdForTrue()); mv.visitLdcInsn(((JumpTouchPointDescriptor) tpd).getCounterIdForFalse()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "putJumpTouchPoint", "(III)V"); } else if (tpd instanceof SwitchTouchPointDescriptor) { SwitchTouchPointDescriptor stpd = (SwitchTouchPointDescriptor) tpd; final String enum_sign = ((SwitchTouchPointDescriptor) tpd).getEnumType(); if (enum_sign == null) { mv.visitLdcInsn(Integer.MAX_VALUE); } else { mv.visitMethodInsn(Opcodes.INVOKESTATIC, enum_sign, "values", "()[L" + enum_sign + ";"); mv.visitInsn(Opcodes.ARRAYLENGTH); } Collection<Integer> ci = stpd.getCountersForLabels(); mv.visitLdcInsn(ci.size());//Size of a new table mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT); int i = 0; for (Integer counterId : ci) { mv.visitInsn(Opcodes.DUP); //First for addition of items, second ad putSwitchTouchPoint parameter (or next loop iteration) mv.visitLdcInsn(i); mv.visitLdcInsn(counterId); mv.visitInsn(Opcodes.IASTORE); i++; } mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "putSwitchTouchPoint", "(II[I)V"); } } mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0);//will be recalculated by writer mv.visitEnd(); }
From source file:net.sourceforge.cobertura.instrument.pass3.AbstractCodeProvider.java
License:GNU General Public License
public void generateCoberturaInitMethod(ClassVisitor cv, String className, int countersCnt) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, COBERTURA_INIT_METHOD_NAME, "()V", null, null); mv.visitCode();// www. j a v a 2 s . c o m generateCINITmethod(mv, className, countersCnt); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); //will be recalculated by writer mv.visitEnd(); }
From source file:net.sourceforge.cobertura.instrument.pass3.AtomicArrayCodeProvider.java
License:GNU General Public License
public void generateCountersField(ClassVisitor cv) { FieldVisitor fv = cv.visitField(// w w w. j ava2 s .c o m Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_TRANSIENT, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE, null, null); fv.visitEnd(); }