List of usage examples for org.objectweb.asm Opcodes ACC_PUBLIC
int ACC_PUBLIC
To view the source code for org.objectweb.asm Opcodes ACC_PUBLIC.
Click Source Link
From source file:com.liferay.alloy.mvc.jsonwebservice.AlloyControllerInvokerManager.java
License:Open Source License
protected byte[] generateAlloyControllerInvokerClassData(Class<?> controllerClass, String alloyControllerInvokerClassName) throws NoClassNecessaryException { boolean jsonWebServiceMethodsPresent = false; ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); String alloyControllerInvokerClassBinaryName = getClassBinaryName(alloyControllerInvokerClassName); String baseAlloyControllerInvokerClassBinaryName = getClassBinaryName( BaseAlloyControllerInvokerImpl.class.getName()); classWriter.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, alloyControllerInvokerClassBinaryName, null, baseAlloyControllerInvokerClassBinaryName, null); MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode();//from w ww . java 2s . c om methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, baseAlloyControllerInvokerClassBinaryName, "<init>", "()V"); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); Method[] methods = controllerClass.getDeclaredMethods(); for (Method method : methods) { if (!Modifier.isPublic(method.getModifiers())) { continue; } JSONWebServiceMethod jsonWebServiceMethod = method.getAnnotation(JSONWebServiceMethod.class); if (jsonWebServiceMethod == null) { continue; } jsonWebServiceMethodsPresent = true; Class<?>[] parameterTypes = jsonWebServiceMethod.parameterTypes(); StringBundler sb = new StringBundler(parameterTypes.length + 3); sb.append(StringPool.OPEN_PARENTHESIS); for (Class<?> parameterType : parameterTypes) { sb.append(Type.getDescriptor(parameterType)); } sb.append(StringPool.CLOSE_PARENTHESIS); sb.append(Type.getDescriptor(JSONSerializable.class)); String methodDescriptor = sb.toString(); methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, method.getName(), methodDescriptor, null, new String[] { getClassBinaryName(Exception.class.getName()) }); methodVisitor.visitCode(); for (int i = 0; i < parameterTypes.length; i++) { String parameterName = jsonWebServiceMethod.parameterNames()[i]; Class<?> parameterType = parameterTypes[i]; methodVisitor.visitLocalVariable(parameterName, Type.getDescriptor(parameterType), null, new Label(), new Label(), i + 1); } methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitLdcInsn(jsonWebServiceMethod.lifecycle()); methodVisitor.visitIntInsn(Opcodes.BIPUSH, parameterTypes.length * 2 + 2); methodVisitor.visitTypeInsn(Opcodes.ANEWARRAY, getClassBinaryName(Object.class.getName())); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitInsn(Opcodes.ICONST_0); methodVisitor.visitLdcInsn("action"); methodVisitor.visitInsn(Opcodes.AASTORE); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitInsn(Opcodes.ICONST_1); methodVisitor.visitLdcInsn(method.getName()); methodVisitor.visitInsn(Opcodes.AASTORE); for (int i = 0; i < parameterTypes.length; i++) { String parameterName = jsonWebServiceMethod.parameterNames()[i]; methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitIntInsn(Opcodes.BIPUSH, (i + 1) * 2); methodVisitor.visitLdcInsn(parameterName); methodVisitor.visitInsn(Opcodes.AASTORE); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitIntInsn(Opcodes.BIPUSH, (i + 1) * 2 + 1); methodVisitor.visitVarInsn(Opcodes.ALOAD, i + 1); methodVisitor.visitInsn(Opcodes.AASTORE); } sb = new StringBundler(5); sb.append(StringPool.OPEN_PARENTHESIS); sb.append(Type.getDescriptor(String.class)); sb.append(Type.getDescriptor(Object[].class)); sb.append(StringPool.CLOSE_PARENTHESIS); sb.append(Type.getDescriptor(JSONSerializable.class)); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, alloyControllerInvokerClassBinaryName, "invokeAlloyController", sb.toString()); methodVisitor.visitInsn(Opcodes.ARETURN); methodVisitor.visitMaxs(-1, -1); methodVisitor.visitEnd(); } classWriter.visitEnd(); if (!jsonWebServiceMethodsPresent) { throw new NoClassNecessaryException(); } return classWriter.toByteArray(); }
From source file:com.liferay.portal.nio.intraband.proxy.IntrabandProxyUtil.java
License:Open Source License
protected static Class<? extends IntrabandProxySkeleton> generateSkeletonClass(ClassLoader classLoader, Class<?> clazz) {// www . j a v a 2s. c o m Type targetType = Type.getType(clazz); String internalName = targetType.getInternalName(); ClassNode classNode = ASMUtil.loadAndRename(TemplateSkeleton.class, internalName.concat(SKELETON_POSTFIX)); classNode.access &= ~Opcodes.ACC_ABSTRACT; classNode.access |= Opcodes.ACC_PUBLIC; FieldNode proxyMethodsMappingFieldNode = ASMUtil.findFieldNode(classNode.fields, "_PROXY_METHODS_MAPPING"); proxyMethodsMappingFieldNode.access |= Opcodes.ACC_FINAL; FieldNode targetLocatorFieldNode = ASMUtil.findFieldNode(classNode.fields, "_targetLocator"); targetLocatorFieldNode.access |= Opcodes.ACC_FINAL; MethodNode doDispatchMethodNode = ASMUtil.findMethodNode(classNode.methods, "doDispatch", Type.VOID_TYPE, _REGISTRATION_REFERENCE_TYPE, _DATAGRAM_TYPE, _DESERIALIZER_TYPE); doDispatchMethodNode.access &= ~Opcodes.ACC_ABSTRACT; MethodNodeGenerator methodNodeGenerator = new MethodNodeGenerator(doDispatchMethodNode); // T target = (T)_targetLocator.getTarget() methodNodeGenerator.loadThis(); methodNodeGenerator.getField(Type.getObjectType(classNode.name), "_targetLocator", _TARGET_LOCATOR_TYPE); methodNodeGenerator.loadArg(2); deserializerRead(methodNodeGenerator, _STRING_TYPE); methodNodeGenerator.invokeInterface(_TARGET_LOCATOR_TYPE.getInternalName(), "getTarget", _OBJECT_TYPE, _STRING_TYPE); methodNodeGenerator.checkCast(targetType); int typedTargetIndex = methodNodeGenerator.newLocal(targetType); methodNodeGenerator.storeLocal(typedTargetIndex); // int index = deserializer.readInt(); methodNodeGenerator.loadArg(2); deserializerRead(methodNodeGenerator, Type.INT_TYPE); methodNodeGenerator.dup(); int indexIndex = methodNodeGenerator.newLocal(Type.INT_TYPE); methodNodeGenerator.storeLocal(indexIndex); // switch (index) MethodsBag methodsBag = extractMethods(clazz); List<Method> proxyMethods = methodsBag.proxyMethods; int[] keys = new int[proxyMethods.size()]; for (int i = 0; i < keys.length; i++) { keys[i] = i; } methodNodeGenerator.tableSwitch(keys, new SkeletonDispatchTableSwitchGenerator(methodNodeGenerator, proxyMethods, classNode.name, typedTargetIndex, indexIndex), true); methodNodeGenerator.returnValue(); methodNodeGenerator.endMethod(); rewriteGetProxyMethodSignaturesMethodNode(classNode, methodsBag.proxyMethodSignatures); return (Class<? extends IntrabandProxySkeleton>) toClass(classNode, classLoader); }
From source file:com.liferay.portal.nio.intraband.proxy.IntrabandProxyUtil.java
License:Open Source License
protected static Class<?> generateStubClass(ClassLoader classLoader, Class<?> clazz, String skeletonId) { String internalName = Type.getInternalName(clazz); ClassNode classNode = ASMUtil.loadAndRename(clazz, internalName.concat(STUB_POSTFIX)); // Class modifiers and hierarchy classNode.access &= ~(Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE); classNode.access |= Opcodes.ACC_PUBLIC; if (clazz.isInterface()) { List<String> interfaces = classNode.interfaces; interfaces.clear();//w w w . j a v a 2 s .co m interfaces.add(internalName); } // Clean up MethodNodes that are going to be generated List<MethodNode> methodNodes = classNode.methods; MethodNode defaultInitMethodNode = ASMUtil.removeMethodNode(methodNodes, "<init>", Type.VOID_TYPE); ASMUtil.removeMethodNodes(methodNodes, "<init>"); ASMUtil.removeMethodNodes(methodNodes, Opcodes.ACC_ABSTRACT); ASMUtil.removeMethodNodes(methodNodes, _annotationDescriptors); // Apply template class ClassNode templateClassNode = ASMUtil.loadAndRename(TemplateStub.class, classNode.name); List<FieldNode> templateFieldNodes = templateClassNode.fields; FieldNode idFieldNode = ASMUtil.findFieldNode(templateFieldNodes, "_id"); idFieldNode.access |= Opcodes.ACC_FINAL; FieldNode intrabandFieldNode = ASMUtil.findFieldNode(templateFieldNodes, "_intraband"); intrabandFieldNode.access |= Opcodes.ACC_FINAL; FieldNode registrationReferenceFieldNode = ASMUtil.findFieldNode(templateFieldNodes, "_registrationReference"); registrationReferenceFieldNode.access |= Opcodes.ACC_FINAL; ASMUtil.addFieldNodes(classNode.fields, templateFieldNodes); List<MethodNode> templateMethodNodes = templateClassNode.methods; MethodNode templateInitMethodNode = ASMUtil.findMethodNode(templateMethodNodes, "<init>", Type.VOID_TYPE, _STRING_TYPE, _REGISTRATION_REFERENCE_TYPE, _EXCEPTION_HANDLER_TYPE); if (defaultInitMethodNode != null) { ASMUtil.mergeMethods(templateInitMethodNode, defaultInitMethodNode, templateInitMethodNode); } MethodNode defaultClinitMethodNode = ASMUtil.removeMethodNode(methodNodes, "<clinit>", Type.VOID_TYPE); if (defaultClinitMethodNode != null) { MethodNode templateClinitMethodNode = ASMUtil.findMethodNode(templateMethodNodes, "<clinit>", Type.VOID_TYPE); ASMUtil.mergeMethods(templateClinitMethodNode, defaultClinitMethodNode, templateClinitMethodNode); } methodNodes.addAll(templateMethodNodes); Type stubType = Type.getType(classNode.name); // Id methods MethodsBag methodsBag = extractMethods(clazz); for (Method idMethod : methodsBag.idMethods) { MethodNodeGenerator methodNodeGenerator = new MethodNodeGenerator(idMethod); methodNodeGenerator.loadThis(); methodNodeGenerator.getField(stubType, "_id", _STRING_TYPE); methodNodeGenerator.returnValue(); methodNodeGenerator.endMethod(); methodNodes.add(methodNodeGenerator.getMethodNode()); } // Proxy methods List<Method> proxyMethods = methodsBag.proxyMethods; for (int i = 0; i < proxyMethods.size(); i++) { methodNodes.add(createProxyMethodNode(proxyMethods.get(i), i, skeletonId, stubType)); } // Empty methods for (Method emptyMethod : methodsBag.emptyMethods) { MethodNodeGenerator methodNodeGenerator = new MethodNodeGenerator(emptyMethod); ASMUtil.addDefaultReturnInsns(methodNodeGenerator, Type.getType(emptyMethod.getReturnType())); methodNodeGenerator.endMethod(); methodNodes.add(methodNodeGenerator.getMethodNode()); } rewriteGetProxyMethodSignaturesMethodNode(classNode, methodsBag.proxyMethodSignatures); return toClass(classNode, classLoader); }
From source file:com.liferay.portal.nio.intraband.proxy.IntrabandProxyUtilTest.java
License:Open Source License
@Test public void testDeserializerRead() { MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, "name", "()V", null, null); MethodNodeGenerator methodNodeGenerator = new MethodNodeGenerator(methodNode); InsnList insnList = methodNode.instructions; for (Type type : _types) { IntrabandProxyUtil.deserializerRead(methodNodeGenerator, type); AbstractInsnNode abstractInsnNode = insnList.getLast(); String methodName = "readObject"; Type returnType = Type.getType(Serializable.class); if (type.getSort() <= Type.DOUBLE) { String name = TextFormatter.format(type.getClassName(), TextFormatter.G); methodName = "read".concat(name); returnType = type;/* www . j a v a 2s. c o m*/ } else if (type.equals(Type.getType(String.class))) { methodName = "readString"; returnType = Type.getType(String.class); _assertMethodInsnNode(abstractInsnNode, Opcodes.INVOKEVIRTUAL, Type.getInternalName(Deserializer.class), "readString", Type.getType(String.class)); } _assertMethodInsnNode(abstractInsnNode, Opcodes.INVOKEVIRTUAL, Type.getInternalName(Deserializer.class), methodName, returnType); } }
From source file:com.liferay.portal.nio.intraband.proxy.IntrabandProxyUtilTest.java
License:Open Source License
@Test public void testSerializerWrite() { MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, "name", "()V", null, null); MethodNodeGenerator methodNodeGenerator = new MethodNodeGenerator(methodNode); InsnList insnList = methodNode.instructions; for (Type type : _types) { IntrabandProxyUtil.serializerWrite(methodNodeGenerator, type); AbstractInsnNode abstractInsnNode = insnList.getLast(); Assert.assertTrue(abstractInsnNode instanceof MethodInsnNode); MethodInsnNode methodInsnNode = (MethodInsnNode) abstractInsnNode; Assert.assertEquals(Opcodes.INVOKEVIRTUAL, abstractInsnNode.getOpcode()); Assert.assertEquals(Type.getInternalName(Serializer.class), methodInsnNode.owner); if (type.getSort() <= Type.DOUBLE) { String name = TextFormatter.format(type.getClassName(), TextFormatter.G); Assert.assertEquals("write".concat(name), methodInsnNode.name); Assert.assertEquals(Type.getMethodDescriptor(Type.VOID_TYPE, type), methodInsnNode.desc); } else if (type.equals(Type.getType(String.class))) { Assert.assertEquals("writeString", methodInsnNode.name); Assert.assertEquals(Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String.class)), methodInsnNode.desc); } else {// w ww .ja v a2s.c o m Assert.assertEquals("writeObject", methodInsnNode.name); Assert.assertEquals(Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Serializable.class)), methodInsnNode.desc); } } }
From source file:com.liferay.portal.nio.intraband.proxy.IntrabandProxyUtilTest.java
License:Open Source License
private void _doTestToClass(boolean proxyClassesDumpEnabled, boolean logEnabled) throws FileNotFoundException { class TestClass { }/*from www . ja v a2 s .c o m*/ ClassNode classNode = _loadClass(TestClass.class); MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, "<clinit>", "()V", null, null); methodNode.visitCode(); methodNode.visitInsn(Opcodes.RETURN); methodNode.visitEnd(); List<MethodNode> methodNodes = classNode.methods; methodNodes.add(methodNode); ClassLoader classLoader = new URLClassLoader(new URL[0], null); Level level = Level.WARNING; if (logEnabled) { level = Level.INFO; } try (CaptureHandler captureHandler = JDKLoggerTestUtil .configureJDKLogger(IntrabandProxyUtil.class.getName(), level)) { List<LogRecord> logRecords = captureHandler.getLogRecords(); IntrabandProxyUtil.toClass(classNode, classLoader); if (proxyClassesDumpEnabled) { StringBundler sb = new StringBundler(6); sb.append(SystemProperties.get(SystemProperties.TMP_DIR)); sb.append(StringPool.SLASH); sb.append(PropsValues.INTRABAND_PROXY_DUMP_CLASSES_DIR); sb.append(StringPool.SLASH); sb.append(classNode.name); sb.append(".class"); String filePath = sb.toString(); File classFile = new File(filePath); Assert.assertTrue(classFile.exists()); ClassNode reloadedClassNode = _loadClass(new FileInputStream(classFile)); MethodNode clinitMethodNode = ASMUtil.findMethodNode(reloadedClassNode.methods, "<clinit>", Type.VOID_TYPE); InsnList insnList = clinitMethodNode.instructions; Assert.assertEquals(1, insnList.size()); _assertInsnNode(insnList.getFirst(), Opcodes.RETURN); if (logEnabled) { Assert.assertEquals(1, logRecords.size()); LogRecord logRecord = logRecords.get(0); Assert.assertEquals(logRecord.getMessage(), "Dumpped class ".concat(filePath)); } } if (!proxyClassesDumpEnabled || !logEnabled) { Assert.assertTrue(logRecords.isEmpty()); } } try { IntrabandProxyUtil.toClass(classNode, classLoader); Assert.fail(); } catch (RuntimeException re) { Throwable throwable = re.getCause(); Assert.assertSame(InvocationTargetException.class, throwable.getClass()); throwable = throwable.getCause(); Assert.assertSame(LinkageError.class, throwable.getClass()); String message = throwable.getMessage(); Assert.assertTrue(message.contains( "duplicate class definition for name: \"" + Type.getInternalName(TestClass.class) + "\"")); } }
From source file:com.lucidtechnics.blackboard.TargetConstructor.java
License:Apache License
private static final byte[] createWrapperObjectByteArray(String _targetName, Class _class) { ClassWriter classWriter = new ClassWriter(true); FieldVisitor fieldVisitor;/* w w w . j ava 2 s . c o m*/ MethodVisitor methodVisitor; String superClassName = _class.getCanonicalName().replaceAll("\\.", "/"); String[] superClassNameParts = superClassName.split("/"); String simpleClassName = superClassNameParts[superClassNameParts.length - 1]; String blackboardSubClassName = "com/lucidtechnics/blackboard/wrapper/" + superClassName + "Wrapper"; classWriter.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, blackboardSubClassName, null, superClassName, new String[] { "com/lucidtechnics/blackboard/Target" }); classWriter.visitSource(simpleClassName, null); { fieldVisitor = classWriter.visitField(Opcodes.ACC_PRIVATE, "blackboardObject", "Ljava/lang/Object;", null, null); fieldVisitor.visitEnd(); } { fieldVisitor = classWriter.visitField(Opcodes.ACC_PRIVATE, "intercepter", "Lcom/lucidtechnics/blackboard/Intercepter;", null, null); fieldVisitor.visitEnd(); } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "getBlackboardObject", "()Ljava/lang/Object;", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitFieldInsn(Opcodes.GETFIELD, blackboardSubClassName, "blackboardObject", "Ljava/lang/Object;"); methodVisitor.visitInsn(Opcodes.ARETURN); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "getIntercepter", "()Lcom/lucidtechnics/blackboard/Intercepter;", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitFieldInsn(Opcodes.GETFIELD, blackboardSubClassName, "intercepter", "Lcom/lucidtechnics/blackboard/Intercepter;"); methodVisitor.visitInsn(Opcodes.ARETURN); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "setBlackboardObject", "(Ljava/lang/Object;)V", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, blackboardSubClassName, "blackboardObject", "Ljava/lang/Object;"); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "setIntercepter", "(Lcom/lucidtechnics/blackboard/Intercepter;)V", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, blackboardSubClassName, "intercepter", "Lcom/lucidtechnics/blackboard/Intercepter;"); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superClassName, "<init>", "()V"); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } List mutatorMethodList = findMutatorMethods(_class); Iterator mutatorMethods = mutatorMethodList.iterator(); while (mutatorMethods.hasNext() == true) { Method method = (Method) mutatorMethods.next(); MethodInfo methodInfo = (MethodInfo) MethodInfoTransformer.getInstance().transform(method); Signature signature = methodInfo.getSignature(); String methodName = signature.getName(); String parameterType = signature.getArgumentTypes()[0].getDescriptor(); String returnType = signature.getReturnType().getDescriptor(); String[] exceptionTypeArray = createExceptionTypeArray(methodInfo.getExceptionTypes()); { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + parameterType + ")" + returnType, null, exceptionTypeArray); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getIntercepter", "()Lcom/lucidtechnics/blackboard/Intercepter;"); Label l1 = new Label(); methodVisitor.visitJumpInsn(Opcodes.IFNULL, l1); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getIntercepter", "()Lcom/lucidtechnics/blackboard/Intercepter;"); methodVisitor.visitLdcInsn(superClassName); methodVisitor.visitLdcInsn(blackboardSubClassName); methodVisitor.visitLdcInsn(methodName); methodVisitor.visitLdcInsn(_targetName); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); int tempOpCode = getLoadOpcode(parameterType); methodVisitor.visitVarInsn(tempOpCode, 1); if (tempOpCode == Opcodes.ALOAD) { //this is an object. methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/lucidtechnics/blackboard/Intercepter", "monitor", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V"); } else { //it is a primitive. methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/lucidtechnics/blackboard/Intercepter", "monitor", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;" + parameterType + ")V"); } methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getBlackboardObject", "()Ljava/lang/Object;"); methodVisitor.visitTypeInsn(Opcodes.CHECKCAST, superClassName); methodVisitor.visitVarInsn(getLoadOpcode(parameterType), 1); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, superClassName, methodName, "(" + parameterType + ")" + returnType); methodVisitor.visitLabel(l1); methodVisitor.visitInsn(getReturnOpcode(returnType)); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } } List otherPublicMethodList = findOtherPublicMethods(_class); Iterator otherPublicMethods = otherPublicMethodList.iterator(); while (otherPublicMethods.hasNext() == true) { Method method = (Method) otherPublicMethods.next(); MethodInfo methodInfo = (MethodInfo) MethodInfoTransformer.getInstance().transform(method); Signature signature = methodInfo.getSignature(); String methodName = signature.getName(); String parameterTypes = constructParameterTypes(signature.getArgumentTypes()); String returnType = signature.getReturnType().getDescriptor(); String[] exceptionTypeArray = createExceptionTypeArray(methodInfo.getExceptionTypes()); if (logger.isDebugEnabled() == true) { logger.debug("Processing method: " + methodName); } if (logger.isDebugEnabled() == true) { logger.debug("Parameter types are: " + parameterTypes); } if ("toString".equalsIgnoreCase(methodName) == false) { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + parameterTypes + ")" + returnType, null, exceptionTypeArray); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getBlackboardObject", "()Ljava/lang/Object;"); methodVisitor.visitTypeInsn(Opcodes.CHECKCAST, superClassName); methodVisitor.visitVarInsn(Opcodes.ASTORE, signature.getArgumentTypes().length + 1); methodVisitor.visitVarInsn(Opcodes.ALOAD, signature.getArgumentTypes().length + 1); loadParameters(methodVisitor, signature.getArgumentTypes()); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, superClassName, methodName, "(" + parameterTypes + ")" + returnType); methodVisitor.visitInsn(getReturnOpcode(returnType)); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } } List protectedMethodList = findProtectedMethods(_class); Iterator protectedMethods = protectedMethodList.iterator(); while (protectedMethods.hasNext() == true) { Method method = (Method) protectedMethods.next(); MethodInfo methodInfo = (MethodInfo) MethodInfoTransformer.getInstance().transform(method); Signature signature = methodInfo.getSignature(); String methodName = signature.getName(); String parameterTypes = constructParameterTypes(signature.getArgumentTypes()); String returnType = signature.getReturnType().getDescriptor(); String[] exceptionTypeArray = createExceptionTypeArray(methodInfo.getExceptionTypes()); if (logger.isDebugEnabled() == true) { logger.debug("Processing method: " + methodName + " and parameter types are: " + parameterTypes); } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PROTECTED, methodName, "(" + parameterTypes + ")" + returnType, null, exceptionTypeArray); methodVisitor.visitCode(); methodVisitor.visitTypeInsn(Opcodes.NEW, "com/lucidtechnics/blackboard/BlackboardException"); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitLdcInsn("Unable to access protected methods on Blackboard object"); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/lucidtechnics/blackboard/BlackboardException", "<init>", "(Ljava/lang/String;)V"); methodVisitor.visitInsn(Opcodes.ATHROW); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getBlackboardObject", "()Ljava/lang/Object;"); methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/lucidtechnics/blackboard/util/Utility", "toString", "(Ljava/lang/Object;)Ljava/lang/String;"); methodVisitor.visitInsn(getReturnOpcode("Ljava/lang/String;")); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } classWriter.visitEnd(); if (logger.isDebugEnabled() == true) { logger.debug("Finished creating new class: " + blackboardSubClassName + " for target class: " + superClassName + "."); } return classWriter.toByteArray(); }
From source file:com.masetta.spann.metadata.reader.asm3_2.ModifierImpl.java
License:Apache License
public Access getAccess() { switch (modifier & ACCESS) { case 0:/*from w ww . ja va2s . c o m*/ return Access.DEFAULT; case Opcodes.ACC_PUBLIC: return Access.PUBLIC; case Opcodes.ACC_PRIVATE: return Access.PRIVATE; case Opcodes.ACC_PROTECTED: return Access.PROTECTED; } throw new IllegalStateException("Unreachanble"); }
From source file:com.mebigfatguy.baremetal4j.Sourcifier.java
License:Apache License
public String accessString(int access) { String separator = ""; StringBuilder sb = new StringBuilder(32); if ((access & Opcodes.ACC_PUBLIC) != 0) { sb.append("public"); separator = " "; } else if ((access & Opcodes.ACC_PROTECTED) != 0) { sb.append("protected"); separator = " "; } else if ((access & Opcodes.ACC_PRIVATE) != 0) { sb.append("private"); separator = " "; }/*from www . j a v a2s .c o m*/ if ((access & Opcodes.ACC_STATIC) != 0) { sb.append(separator).append("static"); separator = " "; } if ((access & Opcodes.ACC_FINAL) != 0) { sb.append(separator).append("final"); separator = " "; } return sb.toString(); }
From source file:com.mebigfatguy.deadmethods.FindDeadMethods.java
License:Apache License
private void removeStandardEnumMethods(ClassRepository repo, Set<String> methods) throws IOException { ClassInfo info = repo.getClassInfo("java/lang/Enum"); {/* w w w . j a va2 s . c om*/ MethodInfo methodInfo = new MethodInfo("valueOf", "(Ljava/lang/String;)?", Opcodes.ACC_PUBLIC); clearDerivedMethods(methods, info, methodInfo.toString()); } { MethodInfo methodInfo = new MethodInfo("values", "()[?", Opcodes.ACC_PUBLIC); clearDerivedMethods(methods, info, methodInfo.toString()); } }