private boolean isNonPublicMethod(final HasAnnotations annotated) { return annotated instanceof MetaMethod && !((MetaMethod) annotated).isPublic(); }
/** * This should only be called for non-public methods. This method forces a * private accessor to be generated for the method. Dispatches to variable * {@code instance}. * * @param method * A method, static or non-static. * @param params * Statements for the values to be passed in as parameters. * @return A statement for accessing invoking the given method. */ public ContextualStatementBuilder exposedMethodStmt(final MetaMethod method, final Statement... params) { if (!method.isPublic()) { addExposedMethod(method); } return DecorableType.METHOD.getAccessStatement(method, factory, params); }
/** * This should only be called for non-public methods. This method forces a * private accessor to be generated for the method. * * @param instance * A statement for the instance on which this method will be called. * @param method * A non-static method. * @param params * Statements for the values to be passed in as parameters. * @return A statement for accessing invoking the given method. */ public ContextualStatementBuilder exposedMethodStmt(final Statement instance, final MetaMethod method, final Statement... params) { if (!method.isPublic()) { addExposedMethod(method); } return DecorableType.METHOD.call(instance, method, factory, params); }
public static Collection<MetaMethod> getAnnotationAttributes(final MetaClass annoClass) { return filterAnnotationMethods(Arrays.stream(annoClass.getDeclaredMethods()), method -> !method.isAnnotationPresent(Nonbinding.class) && method.isPublic() && !method.getName().equals("equals") && !method.getName().equals("hashCode")); }
public static Collection<MetaMethod> getAnnotationAttributes(final MetaClass annoClass) { return filterAnnotationMethods(Arrays.stream(annoClass.getDeclaredMethods()), method -> !method.isAnnotationPresent(Nonbinding.class) && method.isPublic() && !method.getName().equals("equals") && !method.getName().equals("hashCode")); }
public static Collection<MetaMethod> getNonBindingAttributes(final MetaClass annoClass) { return filterAnnotationMethods(Arrays.stream(annoClass.getDeclaredMethods()), method -> method.isAnnotationPresent(Nonbinding.class) && method.isPublic() && !method.getName().equals("equals") && !method.getName().equals("hashCode")); }
public static Collection<MetaMethod> getNonBindingAttributes(final MetaClass annoClass) { return filterAnnotationMethods(Arrays.stream(annoClass.getDeclaredMethods()), method -> method.isAnnotationPresent(Nonbinding.class) && method.isPublic() && !method.getName().equals("equals") && !method.getName().equals("hashCode")); }
public static Statement invokePublicOrPrivateMethod(final FactoryController controller, final MetaMethod method, final Statement... params) { if (method.isPublic()) { return loadVariable("instance").invoke(method, (Object[]) params); } else { return controller.exposedMethodStmt(method, params); } }
@Override protected List<Statement> generateInvokePostConstructsStatements(final ClassStructureBuilder<?> bodyBlockBuilder, final Injectable injectable, final DependencyGraph graph, final InjectionContext injectionContext) { final List<Statement> stmts = new ArrayList<>(); final Queue<MetaMethod> postConstructMethods = gatherPostConstructs(injectable); for (final MetaMethod postConstruct : postConstructMethods) { if (postConstruct.isPublic()) { stmts.add(loadVariable("instance").invoke(postConstruct)); } else { controller.ensureMemberExposed(postConstruct); final String accessorName = getPrivateMethodName(postConstruct); stmts.add(invokePrivateAccessorWithNoParams(accessorName)); } } return stmts; }
private void maybeInvokePreDestroys(final Injectable injectable, final List<Statement> destructionStmts, final ClassStructureBuilder<?> bodyBlockBuilder) { final Queue<MetaMethod> preDestroyMethods = gatherPreDestroys(injectable); for (final MetaMethod preDestroy : preDestroyMethods) { if (preDestroy.isPublic()) { destructionStmts.add(loadVariable("instance").invoke(preDestroy)); } else { controller.ensureMemberExposed(preDestroy); final String accessorName = getPrivateMethodName(preDestroy); destructionStmts.add(invokePrivateAccessorWithNoParams(accessorName)); } } }
private ObjectBuilder createAnonymousImpl(final MetaClass type) { final AnonymousClassStructureBuilder builder = newObject(type).extend(); stream(type.getMethods()) .filter(m -> m.isPublic() && m.isAbstract()) .forEach(m -> { builder .publicOverridesMethod(m.getName(), of(m.getParameters())) .append(Stmt.throw_(RuntimeException.class)) .finish(); }); return builder.finish(); }
@Override public ContextualStatementBuilder call(final Statement instance, final HasAnnotations annotated, final BuildMetaClass factory, final Statement... statement) { final MetaMethod method = (MetaMethod) annotated; if (method.isPublic()) { if (method.isStatic()) { return invokeStatic(method.getDeclaringClass(), method.getName(), (Object[]) statement); } else { return nestedCall(instance).invoke(method, (Object[]) statement); } } else { final Object[] params = getParams(method.isStatic(), instance, statement); return invokeStatic(notNull(factory), getPrivateMethodName(method), params); } }
private ContextualStatementBuilder proxyHelperInvocation(final MetaMethod method, final BuildMetaClass factoryClass) { if (method.isPublic()) { return loadVariable("proxiedInstance").invoke(method.getName(), getParametersForInvocation(method)); } else { controller.addExposedMethod(method); return invokeStatic(factoryClass, getPrivateMethodName(method), getParametersForInvocation(method, loadVariable("proxiedInstance"))); } }
private boolean shouldProxyMethod(final MetaMethod method, final Multimap<String, MetaMethod> proxiedMethodsByName) { return (method.getDeclaringClass() != null && method.getDeclaringClass().isInterface()) || !method.isStatic() && (method.isPublic() || method.isProtected()) && !method.isFinal() && methodIsNotFromObjectUnlessHashCode(method) && typesInSignatureAreVisible(method) && isNotAlreadyProxied(method, proxiedMethodsByName); }
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(); } }
if (!setter.isPublic()) { controller.addExposedMethod(setter); final String privateFieldInjectorName = getPrivateMethodName(setter);
/** * Generates a getter method for the provided property plus the corresponding code for the * implementation of {@link HasProperties#get(String)}. */ private void generateGetter(final ClassStructureBuilder<?> classBuilder, final String property, final CaseBlockBuilder switchBlock) { final MetaMethod getterMethod = bindable.getBeanDescriptor().getReadMethodForProperty(property); if (getterMethod != null && !getterMethod.isFinal() && getterMethod.isPublic()) { BlockBuilder<CaseBlockBuilder> caseBlock = switchBlock.case_(property); caseBlock.append(Stmt.loadVariable("this").invoke(getterMethod.getName()).returnValue()).finish(); classBuilder.publicMethod(getterMethod.getReturnType(), getterMethod.getName()) .append(target().invoke(getterMethod.getName()).returnValue()) .finish(); proxiedAccessorMethods.add(getterMethod); } }
/** * Generates a getter method for the provided property plus the corresponding code for the * implementation of {@link HasProperties#get(String)}. */ private void generateGetter(final ClassStructureBuilder<?> classBuilder, final String property, final CaseBlockBuilder switchBlock) { final MetaMethod getterMethod = bindable.getBeanDescriptor().getReadMethodForProperty(property); if (getterMethod != null && !getterMethod.isFinal() && getterMethod.isPublic()) { BlockBuilder<CaseBlockBuilder> caseBlock = switchBlock.case_(property); caseBlock.append(Stmt.loadVariable("this").invoke(getterMethod.getName()).returnValue()).finish(); classBuilder.publicMethod(getterMethod.getReturnType(), getterMethod.getName()) .append(target().invoke(getterMethod.getName()).returnValue()) .finish(); proxiedAccessorMethods.add(getterMethod); } }
if (!method.isPublic()) { if (!context.isExposed(method, classStructureBuilder.getClassDefinition().getName())) { PrivateAccessUtil.addPrivateAccessStubs(gwtTarget ? "jsni" : "reflection", classStructureBuilder, method);
if (!method.isPublic()) { if (!context.isExposed(method, classStructureBuilder.getClassDefinition().getName())) { PrivateAccessUtil.addPrivateAccessStubs(gwtTarget ? "jsni" : "reflection", classStructureBuilder, method);