public CodeTreeBuilder end(int times) { for (int i = 0; i < times; i++) { end(); } return this; }
@Override public void afterEnd() { end(); } });
@Override public void afterEnd() { string(" "); end(); } });
public CodeTreeBuilder tree(CodeTree treeToAdd) { if (treeToAdd != null) { if (treeToAdd instanceof BuilderCodeTree) { return push((BuilderCodeTree) treeToAdd, true).end(); } else { BuilderCodeTree tree = new BuilderCodeTree(currentElement, GROUP, null, null); currentElement.add(treeToAdd); return push(tree, true).end(); } } return this; }
static CodeTree createTransferToInterpreterAndInvalidate() { ProcessorContext context = ProcessorContext.getInstance(); CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); builder.startStatement().startStaticCall(context.getType(CompilerDirectives.class), "transferToInterpreterAndInvalidate").end().end(); return builder.build(); }
public CodeTreeBuilder cast(TypeMirror type, CodeTree content) { if (ElementUtils.isVoid(type)) { tree(content); return this; } else if (type.getKind() == TypeKind.DECLARED && ElementUtils.getQualifiedName(type).equals("java.lang.Object")) { tree(content); return this; } else { return startGroup().string("(").type(type).string(")").string(" ").tree(content).end(); } }
public CodeTreeBuilder declaration(String type, String name, CodeTree init) { startStatement(); string(type); string(" "); string(name); if (init != null) { string(" = "); tree(init); } end(); // statement return this; }
public CodeTreeBuilder string(String chunk1, String chunk2, String chunk3, String chunk4, String... chunks) { push(GROUP).string(chunk1).string(chunk2).string(chunk3).string(chunk4); for (int i = 0; i < chunks.length; i++) { string(chunks[i]); } return end(); }
static CodeTree invokeImplicitCast(TypeSystemData typeSystem, ImplicitCastData cast, CodeTree expression) { CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); builder.startStaticCall(createTypeSystemGen(typeSystem), cast.getMethodName()).tree(expression); builder.end(); return builder.build(); }
static CodeTree expect(TypeSystemData typeSystem, TypeMirror type, CodeTree content) { if (ElementUtils.isObject(type) || ElementUtils.isVoid(type)) { return content; } CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); if (typeSystem.hasType(type)) { builder.startStaticCall(createTypeSystemGen(typeSystem), expectTypeMethodName(typeSystem, type)).tree(content).end(); } else { builder.startCall(expectTypeMethodName(typeSystem, type)).tree(content).end(); } return builder.build(); }
public CodeTreeBuilder string(String chunk1, String chunk2, String chunk3, String chunk4, String... chunks) { push(GROUP).string(chunk1).string(chunk2).string(chunk3).string(chunk4); for (int i = 0; i < chunks.length; i++) { string(chunks[i]); } return end(); }
private CodeTree createAssumptionGuard(AssumptionExpression assumption, CodeTree assumptionValue) { CodeTree assumptionGuard = CodeTreeBuilder.createBuilder().startCall("isValid_").tree(assumptionValue).end().build(); isValidSignatures.put(ElementUtils.getQualifiedName(assumption.getExpression().getResolvedType()), assumption.getExpression().getResolvedType()); return assumptionGuard; }
private Element createGetSuppliedChildrenMethod() { ArrayType nodeArray = context.getEnvironment().getTypeUtils().getArrayType(getType(Node.class)); CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), nodeArray, "getSuppliedChildren"); method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = method.createBuilder(); builder.startReturn().tree(createGetSuppliedChildren()).end(); return method; }
private CodeVariableElement createSingleton(CodeTypeElement clazz) { CodeVariableElement field = new CodeVariableElement(modifiers(PUBLIC, STATIC, FINAL), clazz.asType(), singletonName(typeSystem)); field.createInitBuilder().startNew(clazz.asType()).end(); CodeAnnotationMirror annotationMirror = new CodeAnnotationMirror((DeclaredType) context.getType(Deprecated.class)); field.getAnnotationMirrors().add(annotationMirror); return field; }
private CodeVariableElement createSingleton(CodeTypeElement clazz) { CodeVariableElement field = new CodeVariableElement(modifiers(PUBLIC, STATIC, FINAL), clazz.asType(), singletonName(typeSystem)); field.createInitBuilder().startNew(clazz.asType()).end(); CodeAnnotationMirror annotationMirror = new CodeAnnotationMirror((DeclaredType) context.getType(Deprecated.class)); field.getAnnotationMirrors().add(annotationMirror); return field; }
private Element createMethodGetSpecializationNode() { TypeMirror returntype = getType(SpecializationNode.class); CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returntype, "getSpecializationNode"); method.createBuilder().startReturn().string(specializationStartFieldName()).end(); return method; }
private static CodeTree createShortCircuit(LocalVariable targetValue, LocalVariable shortCircuitValue, CodeTree tryExecute) { if (shortCircuitValue == null) { return tryExecute; } CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); builder.tree(shortCircuitValue.createDeclaration(shortCircuitValue.createReference())); builder.tree(targetValue.createDeclaration(builder.create().defaultValue(targetValue.getTypeMirror()).build())); builder.startIf().string(shortCircuitValue.getName()).end().startBlock(); builder.tree(tryExecute); builder.end(); return builder.build(); }
public CodeTree createNotContains(FrameState frameState, Object[] elements) { CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); builder.startParantheses(); builder.tree(createMaskedReference(frameState, elements)); builder.end(); builder.string(" == 0"); builder.string(" /* ", label("is-not"), toString(elements, " && "), " */"); return builder.build(); }
private CodeExecutableElement createAsTypeMethod(TypeMirror type) { if (typeSystem.getCast(type) != null) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), type, TypeSystemCodeGenerator.asTypeMethodName(typeSystem, type)); method.addParameter(new CodeVariableElement(context.getType(Object.class), LOCAL_VALUE)); CodeTreeBuilder body = method.createBuilder(); String assertMessage = typeName(typeSystem) + "." + asTypeMethodName(typeSystem, type) + ": " + ElementUtils.getSimpleName(type) + " expected"; body.startAssert().tree(check(typeSystem, type, LOCAL_VALUE)).string(" : ").doubleQuote(assertMessage).end(); body.startReturn().tree(cast(typeSystem, type, LOCAL_VALUE)).end(); return method; }
private CodeExecutableElement createIsTypeMethod(TypeMirror type) { if (typeSystem.getCheck(type) != null) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), context.getType(boolean.class), TypeSystemCodeGenerator.isTypeMethodName(typeSystem, type)); method.addParameter(new CodeVariableElement(context.getType(Object.class), LOCAL_VALUE)); CodeTreeBuilder body = method.createBuilder(); body.startReturn().tree(check(typeSystem, type, LOCAL_VALUE)).end(); return method; }