private static CodeTree createTryExecuteChild(LocalVariable value, CodeTree executeChild, boolean needDeclaration, boolean hasTry) { CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); boolean hasDeclaration = false; if ((hasTry || !executeChild.isSingleLine()) && needDeclaration) { builder.tree(value.createDeclaration(null)); hasDeclaration = true; } if (hasTry) { builder.startTryBlock(); } else { builder.startGroup(); } if (executeChild.isSingleLine()) { builder.startStatement(); if (hasDeclaration || !needDeclaration) { builder.tree(executeChild); } else { builder.type(value.getTypeMirror()).string(" ").tree(executeChild); } builder.end(); } else { builder.tree(executeChild); } builder.end(); return builder.build(); }
private static CodeTree createTryExecuteChild(LocalVariable value, CodeTree executeChild, boolean needDeclaration, boolean hasTry) { CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); boolean hasDeclaration = false; if ((hasTry || !executeChild.isSingleLine()) && needDeclaration) { builder.tree(value.createDeclaration(null)); hasDeclaration = true; } if (hasTry) { builder.startTryBlock(); } else { builder.startGroup(); } if (executeChild.isSingleLine()) { builder.startStatement(); if (hasDeclaration || !needDeclaration) { builder.tree(executeChild); } else { builder.type(value.getTypeMirror()).string(" ").tree(executeChild); } builder.end(); } else { builder.tree(executeChild); } builder.end(); return builder.build(); }
private CodeExecutableElement createExecuteChildMethod(NodeExecutionData execution, TypeMirror targetType) { if (!usedExecuteChildMethods.contains(execution)) { return null; } LocalContext locals = LocalContext.load(this, createSpecializationNodeSignature(0), Integer.MAX_VALUE); CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED, FINAL), targetType, executeChildMethodName(execution, targetType), Integer.MAX_VALUE, FRAME_VALUE); if (hasChildUnexpectedResult(execution, targetType)) { method.getThrownTypes().add(getType(UnexpectedResultException.class)); } CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, targetType); if (implicitProfile != null) { method.addParameter(implicitProfile); } for (int i = 0; i < execution.getChild().getExecuteWith().size(); i++) { NodeExecutionData executeWith = node.getChildExecutions().get(i); LocalVariable var = locals.createValue(executeWith, genericType); method.addParameter(var.createParameter()); locals.setValue(executeWith, var); } CodeTreeBuilder builder = method.createBuilder(); CodeTree executeChild = createExecuteChild(execution, locals.createValue(execution, targetType), locals, true); if (executeChild.isSingleLine()) { builder.statement(executeChild); } else { builder.tree(executeChild); } return method; }