private String[] getExpectedExceptions(MethodHolder method) { AnnotationHolder annot = method.getAnnotations().get(JUNIT4_TEST); if (annot == null) { return new String[0]; } AnnotationValue expected = annot.getValue("expected"); if (expected == null) { return new String[0]; } ValueType result = expected.getJavaClass(); return new String[] { ((ValueType.Object) result).getClassName() }; }
private void attachDependencyPlugin(MethodDependency methodDep) { if (methodDep.dependencyPluginAttached) { return; } methodDep.dependencyPluginAttached = true; methodDep.dependencyPlugin = dependencyPlugins.get(methodDep.getReference()); if (methodDep.dependencyPlugin != null || isBootstrap()) { return; } AnnotationReader depAnnot = methodDep.getMethod().getAnnotations().get(PluggableDependency.class.getName()); if (depAnnot == null) { return; } ValueType depType = depAnnot.getValue("value").getJavaClass(); String depClassName = ((ValueType.Object) depType).getClassName(); Class<?> depClass; try { depClass = Class.forName(depClassName, true, classLoader); } catch (ClassNotFoundException e) { throw new RuntimeException("Dependency plugin not found: " + depClassName, e); } try { methodDep.dependencyPlugin = (DependencyPlugin) depClass.newInstance(); } catch (IllegalAccessException | InstantiationException e) { throw new RuntimeException("Can't instantiate dependency plugin " + depClassName, e); } }
public static MetadataGenerator createMetadataGenerator(ClassLoader classLoader, MethodReader method, CallLocation callLocation, Diagnostics diagnostics) { AnnotationReader annot = method.getAnnotations().get(MetadataProvider.class.getName()); ValueType generatorType = annot.getValue("value").getJavaClass(); String generatorClassName = ((ValueType.Object) generatorType).getClassName();
break; case AnnotationValue.CLASS: output.writeInt(symbolTable.lookup(value.getJavaClass().toString())); break; case AnnotationValue.DOUBLE:
public NativeMethodNode decompileNative(MethodHolder method) { Generator generator = generators.get(method.getReference()); if (generator == null && !isBootstrap()) { AnnotationHolder annotHolder = method.getAnnotations().get(GeneratedBy.class.getName()); if (annotHolder == null) { throw new DecompilationException("Method " + method.getOwnerName() + "." + method.getDescriptor() + " is native, but no " + GeneratedBy.class.getName() + " annotation found"); } ValueType annotValue = annotHolder.getValues().get("value").getJavaClass(); String generatorClassName = ((ValueType.Object) annotValue).getClassName(); try { Class<?> generatorClass = Class.forName(generatorClassName, true, classLoader); generator = (Generator) generatorClass.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new DecompilationException("Error instantiating generator " + generatorClassName + " for native method " + method.getOwnerName() + "." + method.getDescriptor()); } } NativeMethodNode methodNode = new NativeMethodNode(method.getReference()); methodNode.getModifiers().addAll(method.getModifiers()); methodNode.setGenerator(generator); methodNode.setAsync(asyncMethods.contains(method.getReference())); return methodNode; }
public Injector getInjector(MethodReference ref) { InjectorHolder holder = injectorMap.get(ref); if (holder == null) { holder = new InjectorHolder(null); if (!isBootstrap()) { ClassReader cls = classSource.get(ref.getClassName()); if (cls != null) { MethodReader method = cls.getMethod(ref.getDescriptor()); if (method != null) { AnnotationReader injectedByAnnot = method.getAnnotations().get(InjectedBy.class.getName()); if (injectedByAnnot != null) { ValueType type = injectedByAnnot.getValue("value").getJavaClass(); holder = new InjectorHolder(instantiateInjector(((ValueType.Object) type).getClassName())); } } } } injectorMap.put(ref, holder); } return holder.injector; }
return convertClass(value.getJavaClass()); } else if (hierarchy.isSuperType(ValueType.parse(Enum.class), type, false)) { FieldReference fieldRef = value.getEnumValue();
return pe.getField(value.getEnumValue(), type); case AnnotationValue.CLASS: return pe.constant(value.getJavaClass()); case AnnotationValue.ANNOTATION: return generateAnnotationInstance(agent, pe, value.getAnnotation());
ValueType generatorType = providerAnnot.getValue("value").getJavaClass(); String generatorClassName = ((ValueType.Object) generatorType).getClassName(); Class<?> generatorClass;
private Program generateLaunchProgram(MethodHolder method, ClassHierarchy hierarchy) { ProgramEmitter pe = ProgramEmitter.create(method, hierarchy); pe.getField(TestEntryPoint.class, "testCase", Object.class) .cast(ValueType.object(testMethod.getClassName())) .invokeSpecial(testMethod); MethodReader testMethodReader = hierarchy.getClassSource().resolve(testMethod); AnnotationReader testAnnotation = testMethodReader.getAnnotations().get(JUNIT4_TEST); AnnotationValue throwsValue = testAnnotation != null ? testAnnotation.getValue("expected") : null; if (throwsValue != null) { BasicBlock handler = pe.getProgram().createBasicBlock(); TryCatchBlock tryCatch = new TryCatchBlock(); tryCatch.setExceptionType(((ValueType.Object) throwsValue.getJavaClass()).getClassName()); tryCatch.setHandler(handler); pe.getBlock().getTryCatchBlocks().add(tryCatch); BasicBlock nextBlock = pe.getProgram().createBasicBlock(); pe.jump(nextBlock); pe.enter(nextBlock); pe.construct(AssertionError.class, pe.constant("Expected exception not thrown")).raise(); pe.enter(handler); pe.exit(); } else { pe.exit(); } return pe.getProgram(); } }
@Override public Iterable<String> getExpectedExceptions(MethodReader method) { AnnotationReader annot = method.getAnnotations().get(Test.class.getName()); AnnotationValue expectedAnnot = annot.getValue("expected"); if (expectedAnnot != null) { String className = ((ValueType.Object) expectedAnnot.getJavaClass()).getClassName(); return Collections.singletonList(className); } return Collections.emptyList(); }
private void attachDependencyPlugin(MethodDependency methodDep) { if (methodDep.dependencyPluginAttached) { return; } methodDep.dependencyPluginAttached = true; AnnotationReader depAnnot = methodDep.getMethod().getAnnotations().get(PluggableDependency.class.getName()); if (depAnnot == null) { return; } ValueType depType = depAnnot.getValue("value").getJavaClass(); String depClassName = ((ValueType.Object) depType).getClassName(); Class<?> depClass; try { depClass = Class.forName(depClassName, true, classLoader); } catch (ClassNotFoundException e) { throw new RuntimeException("Dependency plugin not found: " + depClassName, e); } try { methodDep.dependencyPlugin = (DependencyPlugin) depClass.newInstance(); } catch (IllegalAccessException | InstantiationException e) { throw new RuntimeException("Can't instantiate dependency plugin " + depClassName, e); } }
public static MetadataGenerator createMetadataGenerator(ClassLoader classLoader, MethodReader method, CallLocation callLocation, Diagnostics diagnostics) { AnnotationReader annot = method.getAnnotations().get(MetadataProvider.class.getName()); ValueType generatorType = annot.getValue("value").getJavaClass(); String generatorClassName = ((ValueType.Object) generatorType).getClassName();
public Injector getInjector(MethodReference ref) { InjectorHolder holder = injectorMap.get(ref); if (holder == null) { holder = new InjectorHolder(null); ClassReader cls = classSource.get(ref.getClassName()); if (cls != null) { MethodReader method = cls.getMethod(ref.getDescriptor()); if (method != null) { AnnotationReader injectedByAnnot = method.getAnnotations().get(InjectedBy.class.getName()); if (injectedByAnnot != null) { ValueType type = injectedByAnnot.getValue("value").getJavaClass(); holder = new InjectorHolder(instantiateInjector(((ValueType.Object) type).getClassName())); } } } injectorMap.put(ref, holder); } return holder.injector; }
break; case AnnotationValue.CLASS: output.writeInt(symbolTable.lookup(value.getJavaClass().toString())); break; case AnnotationValue.DOUBLE:
public NativeMethodNode decompileNative(MethodHolder method) { Generator generator = generators.get(method.getReference()); if (generator == null) { AnnotationHolder annotHolder = method.getAnnotations().get(GeneratedBy.class.getName()); if (annotHolder == null) { throw new DecompilationException("Method " + method.getOwnerName() + "." + method.getDescriptor() + " is native, but no " + GeneratedBy.class.getName() + " annotation found"); } ValueType annotValue = annotHolder.getValues().get("value").getJavaClass(); String generatorClassName = ((ValueType.Object) annotValue).getClassName(); try { Class<?> generatorClass = Class.forName(generatorClassName, true, classLoader); generator = (Generator) generatorClass.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new DecompilationException("Error instantiating generator " + generatorClassName + " for native method " + method.getOwnerName() + "." + method.getDescriptor()); } } NativeMethodNode methodNode = new NativeMethodNode(new MethodReference(method.getOwnerName(), method.getDescriptor())); methodNode.getModifiers().addAll(method.getModifiers()); methodNode.setGenerator(generator); methodNode.setAsync(asyncMethods.contains(method.getReference())); return methodNode; }
return convertClass(value.getJavaClass()); } else if (classSource.isSuperType(ValueType.parse(Enum.class), type).orElse(false)) { FieldReference fieldRef = value.getEnumValue();
ValueType generatorType = providerAnnot.getValue("value").getJavaClass(); String generatorClassName = ((ValueType.Object) generatorType).getClassName(); Class<?> generatorClass;
BasicBlock handler = pe.getProgram().createBasicBlock(); TryCatchBlock tryCatch = new TryCatchBlock(); tryCatch.setExceptionType(((ValueType.Object) throwsValue.getJavaClass()).getClassName()); tryCatch.setHandler(handler); pe.getBlock().getTryCatchBlocks().add(tryCatch);