||method.getName().equals("getFieldValues")) && ! method.getDeclaringClass().getName().equals(Object.class.getName()); allowed &= method.getAnnotation(NoAssist.class) == null; allowed &= (method.getModifiers() & AccessFlag.STATIC) == 0; if ( allowed && (method.getModifiers() & AccessFlag.FINAL) != 0 && ! method.getDeclaringClass().getName().equals("java.lang.Object") ) {
||method.getName().equals("getFieldValues")) && ! method.getDeclaringClass().getName().equals(Object.class.getName()); allowed &= method.getAnnotation(NoAssist.class) == null; allowed &= (method.getModifiers() & AccessFlag.STATIC) == 0; if ( allowed && (method.getModifiers() & AccessFlag.FINAL) != 0 && ! method.getDeclaringClass().getName().equals("java.lang.Object") ) {
@SuppressWarnings("unchecked") private <T extends Annotation> T getMethodAnnotation(CtMethod ctMethod, Class<T> annotation) { try { return (T) ctMethod.getAnnotation(annotation); } catch (ClassNotFoundException e) { // should never happen throw new GwtTestPatchException(e); } }
@SuppressWarnings("unchecked") private <T extends Annotation> T getMethodAnnotation(CtMethod ctMethod, Class<T> annotation) { try { return (T) ctMethod.getAnnotation(annotation); } catch (ClassNotFoundException e) { // should never happen throw new GwtTestPatchException(e); } }
protected void addWorkItem(CtClass clazz, List<MethodInstrumentionWork> work, CtMethod m) throws ClassNotFoundException { Post post = (Post) m.getAnnotation(Post.class); Pre pre = (Pre) m.getAnnotation(Pre.class); if (post != null || pre != null) { MethodInstrumentionWork w = new MethodInstrumentionWork(); MethodInfo methodInfo = m.getMethodInfo2(); w.post = post; w.pre = pre; w.methodName = m.getName(); w.descriptor = methodInfo.getDescriptor(); w.target = clazz; work.add(w); } }
@Override public void transform(String className, CtClass ctclz) throws Exception { final CtMethod[] methods = ctclz.getDeclaredMethods(); for (final CtMethod m : methods) { final Time ann = (Time) m.getAnnotation(Time.class); if (ann != null) { String timerName = ann.identifier(); if (timerName == null || timerName.length() == 0) timerName = String.format("%s#%s", className, m.getLongName()); addTimingInterceptor(ctclz, m, timerName); } } }
@Override public void transform(String className, CtClass ctclz) throws Exception { final CtMethod[] methods = ctclz.getDeclaredMethods(); for (final CtMethod m : methods) { final Time ann = (Time) m.getAnnotation(Time.class); if (ann != null) { String timerName = ann.identifier(); if (timerName == null || timerName.length() == 0) timerName = String.format("%s#%s", className, m.getLongName()); addTimingInterceptor(ctclz, m, timerName); } } }
private boolean shouldCreateChild(final CtClass superClass) throws Exception{ //only classes containing Tests should be processed boolean isTestClass = false; for(CtMethod method : superClass.getMethods()){ if(method.getAnnotation(Test.class) != null){ isTestClass = true; break; } } if(!isTestClass) return false; if (Modifier.isFinal(superClass.getModifiers()) || Modifier.isInterface(superClass.getModifiers())) throw new Exception(superClass.getName() + " should not be final in order to be able to extend it for test."); boolean allConstructorsPrivate = Arrays.stream(superClass.getConstructors()) .map(CtConstructor::getModifiers) .map(Modifier::isPrivate) .reduce((a, b) -> a && b).orElse(true); if (allConstructorsPrivate) throw new Exception(superClass.getName() + " should contain at least one non private constructor"); return true; }
private CtMethod findPatchMethod(CtMethod m) throws Exception { for (CtMethod patchMethod : patchMethods) { PatchMethod annotation = (PatchMethod) patchMethod.getAnnotation(PatchMethod.class); String methodName = (annotation.value().length() > 0) ? annotation.value() : patchMethod.getName(); if (m.getName().equals(methodName) && hasCompatibleSignature(m, patchMethod)) { return patchMethod; } } return null; }
private CtMethod findPatchMethod(CtMethod m) throws Exception { for (CtMethod patchMethod : patchMethods) { PatchMethod annotation = (PatchMethod) patchMethod.getAnnotation(PatchMethod.class); String methodName = (annotation.value().length() > 0) ? annotation.value() : patchMethod.getName(); if (m.getName().equals(methodName) && hasCompatibleSignature(m, patchMethod)) { return patchMethod; } } return null; }
ann = m.getAnnotation(Reference.class); if (ann == null) ann = m.getAnnotation(References.class);
private void profile(CtMethod ctMethod) throws CannotCompileException, ClassNotFoundException { final String START = "com.baidu.hugegraph.perf.PerfUtil.instance().start(\"%s\");"; final String END = "com.baidu.hugegraph.perf.PerfUtil.instance().end(\"%s\");"; Watched annotation = (Watched) ctMethod.getAnnotation(Watched.class); String name = annotation.value(); if (name.isEmpty()) { name = ctMethod.getName(); } if (!annotation.prefix().isEmpty()) { name = annotation.prefix() + "." + name; } ctMethod.insertBefore(String.format(START, name)); // Insert as a finally-statement ctMethod.insertAfter(String.format(END, name), true); LOG.debug("Profiled for: '{}' [{}]", name, ctMethod.getLongName()); }
Secured securedMethodAnnotation = (Secured) method.getAnnotation(Secured.class); Unsecured unsecuredMethodAnnotation = (Unsecured) method.getAnnotation(Unsecured.class);
if (m.hasAnnotation(Caption.class)) { caption = ((Caption) m.getAnnotation(Caption.class)).value(); log.info("caption: " + caption); fileName = ((FileName) m.getAnnotation(FileName.class)).value(); } else { fileName = entryPointName.replace(":", ".") + ".tex"; .getAnnotation(OutputDirectory.class)).value(); label = ((Label) m.getAnnotation(Label.class)).value(); .getAnnotation(SequenceDiagram.class)).value()) { diagramsToRender.add(c);
+ " org.iternine.jeppetto.dao.QueryModel queryModel = new org.iternine.jeppetto.dao.QueryModel();\n\n"); if ((dataAccessMethod = (DataAccessMethod) interfaceMethod.getAnnotation(DataAccessMethod.class)) != null) { operationType = buildQueryModelFromAnnotation(dataAccessMethod, sb);
DelegateCode annotation= (DelegateCode) method.getAnnotation(DelegateCode.class); if (annotation != null && annotation.ignore()) continue;
for (CtClass superCtClass : superContracts) { for (CtMethod superMethod : superCtClass.getDeclaredMethods() ) { Post post = (Post) superMethod.getAnnotation(Post.class); Pre pre = (Pre) superMethod.getAnnotation(Pre.class); if (post != null || pre != null) { String methodName = superMethod.getName();
/** * Responsible for method enhancing, writing service calls to method. * * @param method * Method that has to be edited * @throws javassist.CannotCompileException * if something went wrong * @throws javassist.NotFoundException * if something went wrong * @throws ClassNotFoundException * if something went wrong */ protected void enhanceMethod(CtMethod method) throws CannotCompileException, NotFoundException, ClassNotFoundException { ClassPool cp = method.getDeclaringClass().getClassPool(); method.addLocalVariable("___cbr", cp.get(CallbackResult.class.getName())); CtClass listenerClazz = cp.get(((ObjectCallback) method.getAnnotation(ObjectCallback.class)).value().getName()); String listenerFieldName = "$$$" + listenerClazz.getSimpleName(); CtClass clazz = method.getDeclaringClass(); try { clazz.getField(listenerFieldName); } catch (NotFoundException e) { clazz.addField(CtField.make("Class " + listenerFieldName + " = Class.forName(\"" + listenerClazz.getName() + "\");", clazz)); } int paramLength = method.getParameterTypes().length; method.insertBefore(writeBeforeMethod(method, paramLength, listenerFieldName)); method.insertAfter(writeAfterMethod(method, paramLength, listenerFieldName)); }
/** * Responsible for method enhancing, writing service calls to method. * * @param method * Method that has to be edited * @throws javassist.CannotCompileException * if something went wrong * @throws javassist.NotFoundException * if something went wrong * @throws ClassNotFoundException */ protected void enhanceMethod(CtMethod method) throws CannotCompileException, NotFoundException, ClassNotFoundException { ClassPool cp = method.getDeclaringClass().getClassPool(); method.addLocalVariable("___globalCallbackResult", cp.get(CallbackResult.class.getName())); CtClass listenerClazz = cp.get(((GlobalCallback) method.getAnnotation(GlobalCallback.class)).value().getName()); boolean isStatic = Modifier.isStatic(method.getModifiers()); String listenerFieldName = "$$$" + (isStatic ? "Static" : "") + listenerClazz.getSimpleName(); CtClass clazz = method.getDeclaringClass(); try { clazz.getField(listenerFieldName); } catch (NotFoundException e) { clazz.addField(CtField.make((isStatic ? "static " : "") + "Class " + listenerFieldName + " = Class.forName(\"" + listenerClazz.getName() + "\");", clazz)); } int paramLength = method.getParameterTypes().length; method.insertBefore(writeBeforeMethod(method, paramLength, listenerFieldName)); method.insertAfter(writeAfterMethod(method, paramLength, listenerFieldName)); }
ReflectionAccessor annotation = (ReflectionAccessor)method.getAnnotation(ReflectionAccessor.class); if (annotation == null) { return;