List of usage examples for org.objectweb.asm Opcodes ASM5
int ASM5
To view the source code for org.objectweb.asm Opcodes ASM5.
Click Source Link
From source file:com.intellij.compiler.notNullVerification.NotNullVerifyingInstrumenter.java
License:Apache License
public NotNullVerifyingInstrumenter(final ClassVisitor classVisitor) { super(Opcodes.ASM5, classVisitor); }
From source file:com.intellij.compiler.notNullVerification.NotNullVerifyingInstrumenter.java
License:Apache License
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { final Type[] args = Type.getArgumentTypes(desc); final Type returnType = Type.getReturnType(desc); final MethodVisitor v = cv.visitMethod(access, name, desc, signature, exceptions); return new MethodVisitor(Opcodes.ASM5, v) { private final List<Integer> myNotNullParams = new ArrayList<Integer>(); private int mySyntheticCount = 0; private boolean myIsNotNull = false; private Label myStartGeneratedCodeLabel; @Override//from w w w .java2 s . co m public AnnotationVisitor visitParameterAnnotation(final int parameter, final String anno, final boolean visible) { final AnnotationVisitor av = mv.visitParameterAnnotation(parameter, anno, visible); if (isReferenceType(args[parameter]) && anno.equals(NOT_NULL_TYPE)) { myNotNullParams.add(parameter); } else if (anno.equals(SYNTHETIC_TYPE)) { // see http://forge.ow2.org/tracker/?aid=307392&group_id=23&atid=100023&func=detail mySyntheticCount++; } return av; } @Override public AnnotationVisitor visitAnnotation(String anno, boolean isRuntime) { final AnnotationVisitor av = mv.visitAnnotation(anno, isRuntime); if (isReferenceType(returnType) && anno.equals(NOT_NULL_TYPE)) { myIsNotNull = true; } return av; } @Override public void visitCode() { if (myNotNullParams.size() > 0) { myStartGeneratedCodeLabel = new Label(); mv.visitLabel(myStartGeneratedCodeLabel); } for (Integer param : myNotNullParams) { int var = ((access & ACC_STATIC) == 0) ? 1 : 0; for (int i = 0; i < param; ++i) { var += args[i].getSize(); } mv.visitVarInsn(ALOAD, var); Label end = new Label(); mv.visitJumpInsn(IFNONNULL, end); generateThrow(IAE_CLASS_NAME, String.format(NULL_ARG_MESSAGE, param - mySyntheticCount, myClassName, name), end); } } @Override public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) { final boolean isStatic = (access & ACC_STATIC) != 0; final boolean isParameter = isStatic ? index < args.length : index <= args.length; final Label label = (isParameter && myStartGeneratedCodeLabel != null) ? myStartGeneratedCodeLabel : start; mv.visitLocalVariable(name, desc, signature, label, end, index); } @Override public void visitInsn(int opcode) { if (opcode == ARETURN) { if (myIsNotNull) { mv.visitInsn(DUP); final Label skipLabel = new Label(); mv.visitJumpInsn(IFNONNULL, skipLabel); generateThrow(ISE_CLASS_NAME, String.format(NULL_RESULT_MESSAGE, myClassName, name), skipLabel); } } mv.visitInsn(opcode); } private void generateThrow(final String exceptionClass, final String descr, final Label end) { mv.visitTypeInsn(NEW, exceptionClass); mv.visitInsn(DUP); mv.visitLdcInsn(descr); mv.visitMethodInsn(INVOKESPECIAL, exceptionClass, CONSTRUCTOR_NAME, EXCEPTION_INIT_SIGNATURE); mv.visitInsn(ATHROW); mv.visitLabel(end); myIsModification = true; processPostponedErrors(); } @Override public void visitMaxs(final int maxStack, final int maxLocals) { try { super.visitMaxs(maxStack, maxLocals); } catch (Throwable e) { registerError(name, "visitMaxs", e); } } }; }
From source file:com.jitlogic.zorka.core.spy.SpyClassVisitor.java
License:Open Source License
/** * Creates Spy class visitor./*from w w w. ja v a2 s.c o m*/ * * @param transformer parent class transformer * @param className class name * @param sdefs list of spy definitions to be applied * @param tracer reference to tracer * @param cv output class visitor (typically ClassWriter) */ public SpyClassVisitor(SpyClassTransformer transformer, ClassLoader classLoader, SymbolRegistry symbolRegistry, String className, List<SpyDefinition> sdefs, Tracer tracer, ClassVisitor cv) { super(Opcodes.ASM5, cv); this.transformer = transformer; this.classLoader = classLoader; this.symbolRegistry = symbolRegistry; this.className = className; this.sdefs = sdefs; this.tracer = tracer; for (SpyDefinition sdef : sdefs) { for (SpyMatcher matcher : sdef.getMatcherSet().getMatchers()) { if (matcher.hasFlags(SpyMatcher.RECURSIVE)) { recursive = true; } } } }
From source file:com.liferay.portal.osgi.web.servlet.jsp.compiler.test.JspPrecompileTest.java
License:Open Source License
@Test public void testPrecompiledJsp() throws Exception { String packagePathString = _JSP_PACKAGE_NAME.replace(CharPool.PERIOD, CharPool.SLASH); Path packagePath = _workDirPath.resolve(packagePathString); Files.createDirectories(packagePath); String jspClassName = _PRECOMPILE_JSP_FILE_NAME.replace(CharPool.PERIOD, CharPool.UNDERLINE); Path jspClassPath = packagePath.resolve(jspClassName.concat(".class")); final String className = packagePathString.concat(jspClassName); try (InputStream inputStream = PrecompileTestServlet.class .getResourceAsStream(PrecompileTestServlet.class.getSimpleName() + ".class"); OutputStream outputStream = Files.newOutputStream(jspClassPath)) { ClassReader classReader = new ClassReader(inputStream); ClassWriter classWriter = new ClassWriter(classReader, 0); ClassVisitor classVisitor = new ClassVisitor(Opcodes.ASM5, classWriter) { @Override/* w ww . ja v a 2 s. c o m*/ public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { super.visit(version, access, className, signature, superName, interfaces); } }; classReader.accept(classVisitor, 0); outputStream.write(classWriter.toByteArray()); } try (CaptureAppender captureAppender = Log4JLoggerTestUtil.configureLog4JLogger(_JSP_COMPILER_CLASS_NAME, Level.DEBUG)) { _invokeJSP(_PRECOMPILE_JSP_FILE_NAME, "Precompiled"); Assert.assertFalse("JSP was compiled at runtime", _containsCompilerLog(captureAppender, _PRECOMPILE_JSP_FILE_NAME)); } finally { Files.delete(jspClassPath); } }
From source file:com.liferay.portal.upgrade.test.BaseBuildAutoUpgradeTestCase.java
License:Open Source License
protected void addClass(String path, JarOutputStream jarOutputStream, Object[][] tableColumns, String createSQL) throws IOException { jarOutputStream.putNextEntry(new JarEntry(path)); ClassLoader classLoader = BaseBuildAutoUpgradeTestCase.class.getClassLoader(); try (InputStream inputStream = classLoader.getResourceAsStream(ENTITY_PATH)) { ClassReader classReader = new ClassReader(inputStream); ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_MAXS); ClassVisitor classVisitor = new ClassVisitor(Opcodes.ASM5, classWriter) { @Override/* ww w . jav a 2s . c o m*/ public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { if ((createSQL != null) && name.equals("TABLE_SQL_CREATE")) { value = createSQL; } return super.visitField(access, name, desc, signature, value); } @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor methodVisitor = super.visitMethod(access, name, desc, signature, exceptions); if (name.equals("<clinit>")) { _initTableColumns(methodVisitor, tableColumns); return null; } return methodVisitor; } }; classReader.accept(classVisitor, 0); jarOutputStream.write(classWriter.toByteArray()); } jarOutputStream.closeEntry(); }
From source file:com.mebigfatguy.baremetal4j.BareMetalClassVisitor.java
License:Apache License
public BareMetalClassVisitor(ClassWriter cw, Options options) { super(Opcodes.ASM5, cw); this.options = options; sourcifier = new Sourcifier(); }
From source file:com.mebigfatguy.baremetal4j.BareMetalMethodVisitor.java
License:Apache License
public BareMetalMethodVisitor(MethodVisitor mv, Sourcifier sourcifier) { super(Opcodes.ASM5, mv); this.sourcifier = sourcifier; }
From source file:com.mebigfatguy.exagent.StackTraceClassVisitor.java
License:Apache License
public StackTraceClassVisitor(ClassWriter cw, int parmSizeLimit) { super(Opcodes.ASM5, cw); maxParmSize = parmSizeLimit; }
From source file:com.mebigfatguy.exagent.StackTraceMethodVisitor.java
License:Apache License
public StackTraceMethodVisitor(MethodVisitor mv, String cls, String mName, int access, String desc, int parmSizeLimit) { super(Opcodes.ASM5, mv); clsName = cls;// w w w .ja v a 2s . c o m methodName = mName; maxParmSize = parmSizeLimit; int nextSlot = ((access & Opcodes.ACC_STATIC) != 0) ? 0 : 1; lastParmSlot = nextSlot - 1; List<String> sigs = parseSignature(desc); for (String sig : sigs) { parms.add(new Parm(sig, nextSlot)); lastParmSlot = nextSlot; nextSlot += ("J".equals(sig) || "D".equals(sig)) ? 2 : 1; } exLocalSlot = nextSlot++; depthLocalSlot = nextSlot; }
From source file:com.mebigfatguy.exagent.StackTraceMethodVisitor.java
License:Apache License
@Override public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible) { if (api < Opcodes.ASM5) { throw new RuntimeException(); }/* w ww . ja v a2 s .c o m*/ int[] modifiedIndices = new int[index.length]; System.arraycopy(index, 0, modifiedIndices, 0, index.length); for (int i = 0; i < modifiedIndices.length; i++) { if (index[i] > lastParmSlot) { modifiedIndices[i] += 2; } } return super.visitLocalVariableAnnotation(typeRef, typePath, start, end, modifiedIndices, desc, visible); }