private Collection<MetaMethod> getAllDisposesMethods(final MetaClass type, final boolean staticOnly) { final Collection<MetaMethod> disposers = new ArrayList<>(); for (final MetaMethod method : type.getMethods()) { if (staticOnly && !method.isStatic()) { continue; } final List<MetaParameter> disposerParams = method.getParametersAnnotatedWith(Disposes.class); if (disposerParams.size() > 1) { throw new RuntimeException("Found method " + method + " in " + method.getDeclaringClassName() + " with multiple @Disposes parameters."); } else if (disposerParams.size() == 1) { disposers.add(method); } } return disposers; }
@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { MetaMethod metaMethod = decorable.getAsMethod(); PermissionCheck securedResource = metaMethod.getAnnotation(PermissionCheck.class); String permission = securedResource.value(); String onGranted = securedResource.onGranted(); String onDenied = securedResource.onDenied(); String declaringClass = metaMethod.getDeclaringClassName(); // The method must return void if (!metaMethod.getReturnType().getName().equals("void")) { throw new RuntimeException("The @PermissionCheck annotated method \"" + declaringClass + "#" + metaMethod.getName() + "\" must return void"); } // Permission check if (permission == null || permission.trim().length() == 0) { Statement stmt = createPermissionCheck(permission, onGranted, onDenied); controller.addInvokeBefore(metaMethod, stmt); } }
@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { MetaMethod metaMethod = decorable.getAsMethod(); PermissionCheck securedResource = metaMethod.getAnnotation(PermissionCheck.class); String permission = securedResource.value(); String onGranted = securedResource.onGranted(); String onDenied = securedResource.onDenied(); String declaringClass = metaMethod.getDeclaringClassName(); // The method must return void if (!metaMethod.getReturnType().getName().equals("void")) { throw new RuntimeException("The @PermissionCheck annotated method \"" + declaringClass + "#" + metaMethod.getName() + "\" must return void"); } // Permission check if (permission == null || permission.trim().length() == 0) { Statement stmt = createPermissionCheck(permission, onGranted, onDenied); controller.addInvokeBefore(metaMethod, stmt); } }
String onGranted = securedResource.onGranted(); String onDenied = securedResource.onDenied(); String declaringClass = metaMethod.getDeclaringClassName(); int paramCount = metaMethod.getParameters().length;
String onGranted = securedResource.onGranted(); String onDenied = securedResource.onDenied(); String declaringClass = metaMethod.getDeclaringClassName(); int paramCount = metaMethod.getParameters().length;
private BlockBuilder<?> createProxyMethodDeclaration(final ClassStructureBuilder<?> proxyImpl, final MetaMethod method) { final MethodCommentBuilder<?> methodBuilder; if (method.isPublic()) { methodBuilder = proxyImpl.publicMethod(method.getReturnType().getErased(), method.getName(), getParametersForDeclaration(method)); } else if (method.isProtected()) { methodBuilder = proxyImpl.protectedMethod(method.getReturnType().getErased(), method.getName(), getParametersForDeclaration(method)); } else { final String methodType = (method.isProtected()) ? "private" : "package private"; throw new RuntimeException( "Cannot proxy " + methodType + " method from " + method.getDeclaringClassName()); } if (method.isPublic() || method.isProtected()) { return methodBuilder.annotatedWith(new Override() { @Override public Class<? extends Annotation> annotationType() { return Override.class; } }).throws_(method.getCheckedExceptions()).body(); } else { return methodBuilder.throws_(method.getCheckedExceptions()).body(); } }