Java Code Examples for org.objectweb.asm.Type#getType()
The following examples show how to use
org.objectweb.asm.Type#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IContinuableClassInfoResolver.java From tascalate-javaflow with Apache License 2.0 | 6 votes |
public boolean isContinuableAnnotation(String annotationClassDescriptor) { switch (getAnnotationProcessingState(annotationClassDescriptor)) { case SUPPORTED: return true; case UNSUPPORTED: return false; case UNKNON: markProcessedAnnotation(annotationClassDescriptor); final Type type = Type.getType(annotationClassDescriptor); try { InputStream annotationBytes= resourceLoader.getResourceAsStream(type.getInternalName() + ".class"); try { return resolveContinuableAnnotation(annotationClassDescriptor, new ClassReader(annotationBytes)); } finally { if (null != annotationBytes) { try { annotationBytes.close(); } catch (IOException exIgnore) {} } } } catch (IOException ex) { throw new RuntimeException(ex); } default: throw new RuntimeException("Unknown annotation kind"); } }
Example 2
Source File: UndeclaredThrowableTransformer.java From cglib with Apache License 2.0 | 5 votes |
public UndeclaredThrowableTransformer(Class wrapper) { this.wrapper = Type.getType(wrapper); boolean found = false; Constructor[] cstructs = wrapper.getConstructors(); for (int i = 0; i < cstructs.length; i++) { Class[] types = cstructs[i].getParameterTypes(); if (types.length == 1 && types[0].equals(Throwable.class)) { found = true; break; } } if (!found) throw new IllegalArgumentException(wrapper + " does not have a single-arg constructor that takes a Throwable"); }
Example 3
Source File: CacheonixAnnotationTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test method for {@link CacheonixAnnotation#CacheonixAnnotation(Type, ETransformationState, List)} . */ public void testCacheonixAnnotation() { final List<AnnotationParameter> parameters = new ArrayList<AnnotationParameter>(); final CacheonixAnnotation obj = new CacheonixAnnotation(Type .getType(CacheDataSource.class), ETransformationState.INITIAL_STATE, parameters); assertNotNull(obj); }
Example 4
Source File: PhysicalExprOperatorCompiler.java From yql-plus with Apache License 2.0 | 5 votes |
@Override public void prepare(GambitCreator.ScopeBuilder scope, BytecodeExpression program, BytecodeExpression context, TypeWidget itemType) { super.prepare(scope, program, context, itemType); BytecodeExpression rightExpr = scope.local(evaluateExpression(program, context, right)); IterateAdapter rightIterator = rightExpr.getType().getIterableAdapter(); this.rightRowType = outer ? NullableTypeWidget.create(rightIterator.getValue()) : NotNullableTypeWidget.create(rightIterator.getValue()); this.listOfRightType = new ListTypeWidget(this.rightRowType); GambitCreator.Invocable compiledRightKey = compileFunction(program.getType(), context.getType(), ImmutableList.of(rightRowType), rightKey); TypeWidget rightMapType = new MapTypeWidget(Type.getType(HashMap.class), compiledRightKey.getReturnType(), listOfRightType); this.rightMap = scope.evaluateInto(rightMapType.construct()); if(outer) { this.emptyMatchList = scope.constant(listOfRightType, Arrays.asList(new Object[1])); } else { this.emptyMatchList = scope.constant(listOfRightType, ImmutableList.of()); } // for item in rightExpr: GambitCreator.IterateBuilder loop = scope.iterate(rightExpr); // key = right_key(item) BytecodeExpression key = loop.evaluateInto(loop.cast(AnyTypeWidget.getInstance(), loop.invoke(this.rightKey.getLocation(), compiledRightKey, program, context, loop.getItem()))); GambitCreator.CaseBuilder test = loop.createCase(); // if key in map: // list = map[key] test.when(scope.invokeExact(this.rightKey.getLocation(), "containsKey", Map.class, BaseTypeAdapter.BOOLEAN, rightMap, key), scope.cast(this.listOfRightType, loop.invokeExact(this.rightKey.getLocation(), "get", Map.class, AnyTypeWidget.getInstance(), rightMap, key))); GambitCreator.ScopeBuilder listCreateScope = loop.scope(); BytecodeExpression list = listCreateScope.evaluateInto(this.listOfRightType.construct()); listCreateScope.exec(listCreateScope.invokeExact(this.rightKey.getLocation(), "put", Map.class, AnyTypeWidget.getInstance(), rightMap, key, listCreateScope.cast(AnyTypeWidget.getInstance(), list))); // else: // list = new list // map[key] = list BytecodeExpression targetList = loop.evaluateInto(test.exit(listCreateScope.complete(list))); // list.add(item) loop.exec(loop.invokeExact(Location.NONE, "add", Collection.class, BaseTypeAdapter.BOOLEAN, targetList, loop.cast(Location.NONE, AnyTypeWidget.getInstance(), loop.getItem()))); scope.exec(loop.build()); this.compiledLeftKey = compileFunction(program.getType(), context.getType(), ImmutableList.of(itemType), leftKey); this.compiledJoin = compileFunction(program.getType(), context.getType(), ImmutableList.of(itemType, this.rightRowType), join); this.next.prepare(scope, program, context, compiledJoin.getReturnType()); }
Example 5
Source File: JavaClass.java From deobfuscator with Apache License 2.0 | 5 votes |
public JavaClass(String name, Context context) { if (name.contains("/")) { name = name.replace('/', '.'); } this.name = name; this.context = context; String internalName = this.name.replace('.', '/'); Class<?> primitive = PrimitiveUtils.getPrimitiveByName(internalName); if (primitive == null) { this.type = Type.getObjectType(internalName); Type elementType = this.type; if (elementType.getSort() == Type.ARRAY) { elementType = elementType.getElementType(); } primitive = PrimitiveUtils.getPrimitiveByName(elementType.getClassName()); if (primitive == null) { this.classNode = context.dictionary.get(elementType.getInternalName()); if (this.classNode == null) { System.out.println("Could not find classnode " + this.name); throw new NoClassInPathException(this.name); } this.isPrimitive = false; } else { this.classNode = context.dictionary.get("java/lang/Object"); this.isPrimitive = false; } } else { this.type = Type.getType(primitive); this.classNode = null; this.isPrimitive = true; } }
Example 6
Source File: PhysicalExprOperatorCompiler.java From yql-plus with Apache License 2.0 | 5 votes |
@Override public void prepare(GambitCreator.ScopeBuilder scope, BytecodeExpression program, BytecodeExpression context, TypeWidget itemType) { this.compiledKey = compileFunction(program.getType(), context.getType(), ImmutableList.of(itemType), key); this.listOfItemType = new ListTypeWidget(itemType); this.compiledOutput = compileFunction(program.getType(), context.getType(), ImmutableList.of(compiledKey.getReturnType(), listOfItemType), output); this.accumulateMapType = new MapTypeWidget(Type.getType(LinkedHashMap.class), compiledKey.getReturnType(), listOfItemType); map = scope.evaluateInto(accumulateMapType.construct()); super.prepare(scope, program, context, itemType); }
Example 7
Source File: InputCoverageFactoryTest.java From botsing with Apache License 2.0 | 5 votes |
@Test public void testDetectGoals_map(){ Type type = Type.getType(Map.class); List<InputCoverageTestFitness> goals = new ArrayList<InputCoverageTestFitness>(); inputCoverageFactory.detectGoals("ClassA","method1",new Class[]{Map.class},new Type[]{type},goals); assert (goals.size() == 3); }
Example 8
Source File: ClassScanner.java From forbidden-apis with Apache License 2.0 | 5 votes |
@Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { if (this.isDeprecated && DEPRECATED_DESCRIPTOR.equals(desc)) { // don't report 2 times! return null; } final Type type = Type.getType(desc); classSuppressed |= suppressAnnotations.matcher(type.getClassName()).matches(); reportClassViolation(checkAnnotationDescriptor(type, visible), "annotation on class declaration"); return null; }
Example 9
Source File: IncludingClassVisitor.java From OpenModsLib with MIT License | 5 votes |
@Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { AnnotationVisitor av = super.visitAnnotation(desc, visible); Type t = Type.getType(desc); if (INCLUDE_INTERFACE.equals(t)) return new IncludeAnnotationVisitor(av, this); return av; }
Example 10
Source File: SerianalyzerState.java From serianalyzer with GNU General Public License v3.0 | 5 votes |
private void readObject ( ObjectInputStream ois ) throws ClassNotFoundException, IOException { ois.defaultReadObject(); int cnt = ois.readInt(); Map<MethodReference, Type> retTypes = new HashMap<>(); for ( int i = 0; i < cnt; i++ ) { MethodReference ref = (MethodReference) ois.readObject(); Type t = Type.getType(ois.readUTF()); retTypes.put(ref, t); } this.returnTypes = retTypes; }
Example 11
Source File: VariableTable.java From coroutines with GNU Lesser General Public License v3.0 | 4 votes |
/** * Constructs a {@link VariableTable} object. * @param classNode class that {@code methodeNode} resides in * @param methodNode method this variable table is for */ public VariableTable(ClassNode classNode, MethodNode methodNode) { this((methodNode.access & Opcodes.ACC_STATIC) != 0, Type.getObjectType(classNode.name), Type.getType(methodNode.desc), methodNode.maxLocals); Validate.isTrue(classNode.methods.contains(methodNode)); // sanity check }
Example 12
Source File: CallbackInjector.java From Mixin with MIT License | 4 votes |
Callback(MethodNode handler, Target target, final InjectionNode node, final LocalVariableNode[] locals, boolean captureLocals) { this.handler = handler; this.target = target; this.head = target.insns.getFirst(); this.node = node; this.locals = locals; this.localTypes = locals != null ? new Type[locals.length] : null; this.frameSize = Bytecode.getFirstNonArgLocalIndex(target.arguments, !target.isStatic); List<String> argNames = null; if (locals != null) { int baseArgIndex = CallbackInjector.this.isStatic() ? 0 : 1; argNames = new ArrayList<String>(); for (int l = 0; l <= locals.length; l++) { if (l == this.frameSize) { argNames.add(target.returnType == Type.VOID_TYPE ? "ci" : "cir"); } if (l < locals.length && locals[l] != null) { this.localTypes[l] = Type.getType(locals[l].desc); if (l >= baseArgIndex) { argNames.add(CallbackInjector.meltSnowman(l, locals[l].name)); } } } } // Calc number of args for the handler method, additional 1 is to ignore the CallbackInfo arg Type[] handlerArgs = Type.getArgumentTypes(this.handler.desc); this.extraArgs = Math.max(0, handlerArgs.length - target.arguments.length - 1); this.argNames = argNames != null ? argNames.toArray(new String[argNames.size()]) : null; this.canCaptureLocals = captureLocals && locals != null && locals.length > this.frameSize; this.isAtReturn = this.node.getCurrentTarget() instanceof InsnNode && this.isValueReturnOpcode(this.node.getCurrentTarget().getOpcode()); this.desc = target.getCallbackDescriptor(this.localTypes, target.arguments); this.descl = target.getCallbackDescriptor(true, this.localTypes, target.arguments, this.frameSize, this.extraArgs); // this.typeCasts = new Type[this.frameSize + this.extraArgs]; this.invoke = target.extendStack(); this.ctor = target.extendStack(); this.invoke.add(target.arguments.length); if (this.canCaptureLocals) { this.invoke.add(this.localTypes.length - this.frameSize); } }
Example 13
Source File: Conversions.java From yql-plus with Apache License 2.0 | 4 votes |
BoxCall(Class source, String methodName, Class returnType) { this.owner = Type.getType(returnType); this.methodName = methodName; this.descriptor = Type.getMethodDescriptor(Type.getType(returnType), Type.getType(source)); }
Example 14
Source File: FieldAccess.java From reflectasm with BSD 3-Clause "New" or "Revised" License | 4 votes |
static private void insertGetObject (ClassWriter cw, String classNameInternal, ArrayList<Field> fields) { int maxStack = 6; MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "get", "(Ljava/lang/Object;I)Ljava/lang/Object;", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 2); if (!fields.isEmpty()) { maxStack--; Label[] labels = new Label[fields.size()]; for (int i = 0, n = labels.length; i < n; i++) labels[i] = new Label(); Label defaultLabel = new Label(); mv.visitTableSwitchInsn(0, labels.length - 1, defaultLabel, labels); for (int i = 0, n = labels.length; i < n; i++) { Field field = fields.get(i); mv.visitLabel(labels[i]); mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, classNameInternal); mv.visitFieldInsn(GETFIELD, field.getDeclaringClass().getName().replace('.', '/'), field.getName(), Type.getDescriptor(field.getType())); Type fieldType = Type.getType(field.getType()); switch (fieldType.getSort()) { case Type.BOOLEAN: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;"); break; case Type.BYTE: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;"); break; case Type.CHAR: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;"); break; case Type.SHORT: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;"); break; case Type.INT: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;"); break; case Type.FLOAT: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;"); break; case Type.LONG: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;"); break; case Type.DOUBLE: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;"); break; } mv.visitInsn(ARETURN); } mv.visitLabel(defaultLabel); mv.visitFrame(F_SAME, 0, null, 0, null); } insertThrowExceptionForFieldNotFound(mv); mv.visitMaxs(maxStack, 3); mv.visitEnd(); }
Example 15
Source File: CompletableFutureResultType.java From yql-plus with Apache License 2.0 | 4 votes |
public CompletableFutureResultType(TypeWidget valueType) { super(Type.getType(CompletableFuture.class)); this.valueType = valueType; }
Example 16
Source File: Utils.java From JQF with BSD 2-Clause "Simplified" License | 4 votes |
public static void addValueReadInsn(MethodVisitor mv, String desc, String methodNamePrefix) { Type t; if (desc.startsWith("(")) { t = Type.getReturnType(desc); } else { t = Type.getType(desc); } switch (t.getSort()) { case Type.DOUBLE: mv.visitInsn(DUP2); mv.visitMethodInsn( INVOKESTATIC, Config.instance.analysisClass, methodNamePrefix + "double", "(D)V", false); break; case Type.LONG: mv.visitInsn(DUP2); mv.visitMethodInsn( INVOKESTATIC, Config.instance.analysisClass, methodNamePrefix + "long", "(J)V", false); break; case Type.ARRAY: mv.visitInsn(DUP); mv.visitMethodInsn( INVOKESTATIC, Config.instance.analysisClass, methodNamePrefix + "Object", "(Ljava/lang/Object;)V", false); break; case Type.BOOLEAN: mv.visitInsn(DUP); mv.visitMethodInsn( INVOKESTATIC, Config.instance.analysisClass, methodNamePrefix + "boolean", "(Z)V", false); break; case Type.BYTE: mv.visitInsn(DUP); mv.visitMethodInsn( INVOKESTATIC, Config.instance.analysisClass, methodNamePrefix + "byte", "(B)V", false); break; case Type.CHAR: mv.visitInsn(DUP); mv.visitMethodInsn( INVOKESTATIC, Config.instance.analysisClass, methodNamePrefix + "char", "(C)V", false); break; case Type.FLOAT: mv.visitInsn(DUP); mv.visitMethodInsn( INVOKESTATIC, Config.instance.analysisClass, methodNamePrefix + "float", "(F)V", false); break; case Type.INT: mv.visitInsn(DUP); mv.visitMethodInsn( INVOKESTATIC, Config.instance.analysisClass, methodNamePrefix + "int", "(I)V", false); break; case Type.OBJECT: mv.visitInsn(DUP); mv.visitMethodInsn( INVOKESTATIC, Config.instance.analysisClass, methodNamePrefix + "Object", "(Ljava/lang/Object;)V", false); break; case Type.SHORT: mv.visitInsn(DUP); mv.visitMethodInsn( INVOKESTATIC, Config.instance.analysisClass, methodNamePrefix + "short", "(S)V", false); break; case Type.VOID: mv.visitMethodInsn( INVOKESTATIC, Config.instance.analysisClass, methodNamePrefix + "void", "()V", false); break; default: System.err.println("Unknown field or method descriptor " + desc); System.exit(1); } }
Example 17
Source File: TestThirdEnhance.java From jvm-sandbox with GNU Lesser General Public License v3.0 | 4 votes |
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { final MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); final String signCode = getBehaviorSignCode(name, desc); if (!isMatchedBehavior(signCode)) { return mv; } return new ThirdReWriteMethod(api, mv) { @Override public void visitInsn(final int opcode) { switch (opcode) { case RETURN: case IRETURN: case FRETURN: case ARETURN: case LRETURN: case DRETURN: onExit(); break; default: break; } super.visitInsn(opcode); } private void onExit() { Label startTryBlock = new Label(); Label endTryBlock = new Label(); Label startCatchBlock = new Label(); Label endCatchBlock = new Label(); mv.visitLabel(startTryBlock); //静态调用 Type type = Type.getType(Math.class); String owner = type.getInternalName(); mv.visitMethodInsn(INVOKESTATIC, owner, method.getName(), method.getDescriptor(), false); mv.visitInsn(POP2); mv.visitLabel(endTryBlock); mv.visitJumpInsn(GOTO,endCatchBlock); mv.visitLabel(startCatchBlock); mv.visitInsn(POP); mv.visitLabel(endCatchBlock); mv.visitTryCatchBlock(startTryBlock,endTryBlock,startCatchBlock,ASM_TYPE_THROWABLE.getInternalName()); } }; }
Example 18
Source File: ASMBytecodeEmitter.java From rembulan with Apache License 2.0 | 4 votes |
Type superClassType() { return Type.getType(InvokeKind.nativeClassForKind(kind())); }
Example 19
Source File: AsmDeltaSpikeProxyClassGenerator.java From deltaspike with Apache License 2.0 | 4 votes |
private static void defineMethod(ClassWriter cw, java.lang.reflect.Method method, Type proxyType) { Type methodType = Type.getType(method); ArrayList<Type> exceptionsToCatch = new ArrayList<Type>(); for (Class<?> exception : method.getExceptionTypes()) { if (!RuntimeException.class.isAssignableFrom(exception)) { exceptionsToCatch.add(Type.getType(exception)); } } // push the method definition int modifiers = (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED) & method.getModifiers(); Method asmMethod = Method.getMethod(method); GeneratorAdapter mg = new GeneratorAdapter(modifiers, asmMethod, null, getTypes(method.getExceptionTypes()), cw); // copy annotations for (Annotation annotation : method.getDeclaredAnnotations()) { mg.visitAnnotation(Type.getDescriptor(annotation.annotationType()), true).visitEnd(); } mg.visitCode(); Label tryBlockStart = mg.mark(); mg.loadThis(); mg.getField(proxyType, FIELDNAME_INVOCATION_HANDLER, TYPE_DELTA_SPIKE_PROXY_INVOCATION_HANDLER); mg.loadThis(); loadCurrentMethod(mg, method, methodType); loadArguments(mg, method, methodType); mg.invokeVirtual(TYPE_DELTA_SPIKE_PROXY_INVOCATION_HANDLER, Method.getMethod("Object invoke(Object, java.lang.reflect.Method, Object[])")); // cast the result mg.unbox(methodType.getReturnType()); // build try catch Label tryBlockEnd = mg.mark(); // push return mg.returnValue(); // catch runtime exceptions and rethrow it Label rethrow = mg.mark(); mg.visitVarInsn(Opcodes.ASTORE, 1); mg.visitVarInsn(Opcodes.ALOAD, 1); mg.throwException(); mg.visitTryCatchBlock(tryBlockStart, tryBlockEnd, rethrow, Type.getInternalName(RuntimeException.class)); // catch checked exceptions and rethrow it boolean throwableCatched = false; if (!exceptionsToCatch.isEmpty()) { rethrow = mg.mark(); mg.visitVarInsn(Opcodes.ASTORE, 1); mg.visitVarInsn(Opcodes.ALOAD, 1); mg.throwException(); // catch declared exceptions and rethrow it... for (Type exceptionType : exceptionsToCatch) { if (exceptionType.getClassName().equals(Throwable.class.getName())) { throwableCatched = true; } mg.visitTryCatchBlock(tryBlockStart, tryBlockEnd, rethrow, exceptionType.getInternalName()); } } // if throwable isn't alreached cachted, catch it and wrap it with an UndeclaredThrowableException and throw it if (!throwableCatched) { Type uteType = Type.getType(UndeclaredThrowableException.class); Label wrapAndRethrow = mg.mark(); mg.visitVarInsn(Opcodes.ASTORE, 1); mg.newInstance(uteType); mg.dup(); mg.visitVarInsn(Opcodes.ALOAD, 1); mg.invokeConstructor(uteType, Method.getMethod("void <init>(java.lang.Throwable)")); mg.throwException(); mg.visitTryCatchBlock(tryBlockStart, tryBlockEnd, wrapAndRethrow, Type.getInternalName(Throwable.class)); } // finish the method mg.endMethod(); mg.visitMaxs(12, 12); mg.visitEnd(); }
Example 20
Source File: StackHelper.java From zelixkiller with GNU General Public License v3.0 | 4 votes |
public InsnValue getStatic(FieldInsnNode fin) { return new InsnValue(Type.getType(fin.desc)); }