Refine search
private Statement generateInterceptorLogic(ClassStructureBuilder<?> classBuilder, MetaMethod method, Statement requestLogic, List<Statement> parmVars, List<Class<?>> interceptors) { final Statement callContext = ProxyUtil.generateProxyMethodCallContext(context, RemoteCallContext.class, classBuilder.getClassDefinition(), method, requestLogic, interceptors).finish(); return Stmt.try_() .append( Stmt.declareVariable(CallContextStatus.class).asFinal().named("status").initializeWith( Stmt.newObject(CallContextStatus.class).withParameters(interceptors.toArray()))) .append( Stmt.declareVariable(RemoteCallContext.class).asFinal().named("callContext") .initializeWith(callContext)) .append( Stmt.loadVariable("callContext").invoke("setParameters", Stmt.newArray(Object.class).initialize(parmVars.toArray()))) .append( Stmt.loadVariable("callContext").invoke("proceed")) .finish() .catch_(Throwable.class, "throwable") .append( If.cond(Bool.notEquals(Stmt.loadVariable("errorCallback"), Stmt.loadLiteral(null))) .append( If.cond(Stmt.loadVariable("errorCallback").invoke("error", Stmt.load(null), Variable.get("throwable"))) .append(Stmt.loadVariable("this").invoke("invokeDefaultErrorHandlers", Variable.get("throwable"))) .finish() ).finish() .else_() .append(Stmt.loadVariable("this").invoke("invokeDefaultErrorHandlers", Variable.get("throwable"))) .finish()) .finish(); }
/** * Generates code to call {@link Factory#setReference(Object, String, Object)} * for an instance in the * {@link Factory#createInstance(org.jboss.errai.ioc.client.container.ContextManager)} * method. */ public static ContextualStatementBuilder constructSetReference(final String name, final Statement value) { return loadVariable("thisInstance").invoke("setReference", Stmt.loadVariable("instance"), name, value); }
private void implementClearInstance(final ClassStructureBuilder<?> proxyImpl, final Injectable injectable) { proxyImpl.publicMethod(void.class, "clearInstance") .body() .append(loadVariable("proxyHelper").invoke("clearInstance")) .finish(); }
private Statement invokePrivateAccessorWithNoParams(final String accessorName) { return loadVariable("this").invoke(accessorName, loadVariable("instance")); }
@Test public void testEmptyIfBlockUsingNoRhsAndNegation() { String s = StatementBuilder.create() .declareVariable("str", String.class) .loadVariable("str") .invoke("endsWith", "abc") .ifNot() .finish().toJavaString(); assertEquals("Failed to generate empty if block using no rhs", EMPTY_IF_BLOCK_NO_RHS_AND_NEGATION, s); }
private void implementUnwrappedInstance(final ClassStructureBuilder<?> proxyImpl, final Injectable injectable) { proxyImpl.publicMethod(Object.class, "unwrap") .body() .append(loadVariable("proxyHelper").invoke("getInstance", loadVariable("this")).returnValue()) .finish(); }
/** * @return A statement for getting an instance of the type produced by this * factory in * {@link Factory#init(org.jboss.errai.ioc.client.container.Context)}. */ public Statement contextGetInstanceStmt() { return castTo(producedType, loadVariable("context").invoke("getInstance", factoryName)); }
@Test public void testWhileLoopChainedWithExpression() { String s = StatementBuilder.create() .declareVariable("str", String.class) .loadVariable("str") .invoke("length") .while_(BooleanOperator.GreaterThanOrEqual, 2) .finish().toJavaString(); assertEquals("Failed to generate while loop with chained lhs, rhs and no body", WHILE_RHS_EMPTY, s); }
private void implementSetContext(final ClassStructureBuilder<?> proxyImpl, final Injectable injectable) { proxyImpl.publicMethod(void.class, "setProxyContext", finalOf(Context.class, "context")) .body() .append(loadVariable("proxyHelper").invoke("setProxyContext", loadVariable("context"))) .finish(); }
/** * Generates code to call * {@link Factory#getReferenceAs(Object, String, Class)} for an instance in * {@link Factory#createInstance(org.jboss.errai.ioc.client.container.ContextManager)} * and * {@link Factory#destroyInstance(Object, org.jboss.errai.ioc.client.container.ContextManager)} * methods. */ public static ContextualStatementBuilder constructGetReference(final String name, final Class<?> refType) { // This cast is for the benefit of codegen, which is sometimes unable to // identify the value for the type parameter of Factory.getReferenceAs. return castTo(refType, loadVariable("thisInstance").invoke("getReferenceAs", loadVariable("instance"), name, refType)); }
@Test public void testForeachLoopWithLiterals() { String s = StatementBuilder.create() .loadLiteral(new String[] { "s1", "s2" }) .foreach("s") .append(StatementBuilder.create().loadVariable("s").invoke("getBytes")) .finish().toJavaString(); assertEquals("Failed to generate foreach loop using a literal String array", FOREACH_LITERAL_STRING_ARRAY, s); }
private BlockBuilder<ElseBlockBuilder> updateGetMarshallerConditionalBlock(BlockBuilder<ElseBlockBuilder> getMarshallerConditionalBlock, final String helperMethodName) { getMarshallerConditionalBlock = getMarshallerConditionalBlock.finish().elseif_(StringStatement.of(helperMethodName + "(a0)", boolean.class)) .append(Stmt.loadVariable(MARSHALLERS_VAR).invoke("get", Stmt.loadVariable("a0")).returnValue()); return getMarshallerConditionalBlock; }
private void callFinishInitOnContextManager(final String contextManagerFieldName, final BlockBuilder<?> methodBody) { methodBody.append(loadVariable(contextManagerFieldName).invoke("finishInit")); }
@Test public void testForeachLoopWithInvoke() { Builder loop = StatementBuilder.create() .declareVariable("map", Map.class) .loadVariable("map") .invoke("keySet") .foreach("key") .append(Stmt.loadStatic(System.class, "out").invoke("println", Variable.get("key"))) .finish(); assertEquals("Failed to generate foreach loop using invoke()", FOREACH_KEYSET_LOOP, loop.toJavaString()); }
private BlockBuilder<ElseBlockBuilder> updateGetMarshallerConditionalBlock(BlockBuilder<ElseBlockBuilder> getMarshallerConditionalBlock, final String helperMethodName) { getMarshallerConditionalBlock = getMarshallerConditionalBlock.finish().elseif_(StringStatement.of(helperMethodName + "(a0)", boolean.class)) .append(Stmt.loadVariable(MARSHALLERS_VAR).invoke("get", Stmt.loadVariable("a0")).returnValue()); return getMarshallerConditionalBlock; }
/** * @param instanceStmt * The statement for the instance that will be the first parameter to * {@link ContextManager#getInstanceProperty(Object, String, Class)}. * @param name * The name of the property. * @param refType * The type of the property. * @return A statement that looks up a property of an instance from another * factory via * {@link ContextManager#getInstanceProperty(Object, String, Class)}. */ public ContextualStatementBuilder getInstancePropertyStmt(final Statement instanceStmt, final String name, final Class<?> refType) { return Stmt.castTo(refType, loadVariable("contextManager").invoke("getInstanceProperty", instanceStmt, name, refType)); }
@Test public void testIfElseIfBlockUsingNoRhsAndElseifKeyword() { Context c = ContextBuilder.create().addVariable("s", String.class).addVariable("n", Integer.class).getContext(); String s = StatementBuilder.create(c) .loadVariable("s") .invoke("endsWith", "abc") .if_() .append(StatementBuilder.create(c).loadVariable("n").assignValue(0)) .finish() .elseif_(StatementBuilder.create(c).loadVariable("s").invoke("startsWith", "def")) .append(StatementBuilder.create(c).loadVariable("n").assignValue(1)) .finish().toJavaString(); assertEquals("Failed to generate if-elseif block using no rhs", IF_ELSEIF_BLOCK_NO_RHS, s); }
public static Statement buildCheckStatement(ContextualStatementBuilder authzCall, String onGranted, String onDenied) { BooleanExpression boolExpr = BooleanExpressionBuilder.create(authzCall).negate(); BlockBuilder<ElseBlockBuilder> builder = If.cond(boolExpr); if (onDenied != null && onDenied.trim().length() > 0) { builder.append(Stmt.loadVariable("this").invoke(onDenied)); } BlockBuilder<StatementEnd> endBuilder = builder.append(Stmt.returnVoid()).finish().else_(); if (onGranted != null && onGranted.trim().length() > 0) { endBuilder.append(Stmt.loadVariable("this").invoke(onGranted)); } return endBuilder.finish(); }
private void constructInstance(final Injectable injectable, final Collection<Dependency> constructorDependencies, final List<Statement> createInstanceStatements) { if (constructorDependencies.size() > 0) { addConstructorInjectionStatements(injectable, constructorDependencies, createInstanceStatements); } else { assignNewObjectWithZeroArgConstructor(injectable, createInstanceStatements); } createInstanceStatements.add(loadVariable("this").invoke("setIncompleteInstance", loadVariable("instance"))); }