public CodeTypeParameterElement(String name, TypeMirror... bounds) { super(ElementUtils.modifiers()); this.simpleName = CodeNames.of(name); this.bounds = Arrays.asList(bounds); }
public CodeExecutableElement(TypeMirror returnType, String name) { super(ElementUtils.modifiers()); this.returnType = returnType; this.name = CodeNames.of(name); }
public CodeVariableElement(TypeMirror type, String name) { super(ElementUtils.modifiers()); this.type = type; this.name = CodeNames.of(name); }
private CodeVariableElement createInstanceConstant(TypeMirror factoryType) { String varName = instanceVarName(node); CodeVariableElement var = new CodeVariableElement(modifiers(), factoryType, varName); var.getModifiers().add(Modifier.PRIVATE); var.getModifiers().add(Modifier.STATIC); return var; }
private CodeVariableElement createInstanceConstant(TypeMirror factoryType) { String varName = instanceVarName(node); CodeVariableElement var = new CodeVariableElement(modifiers(), factoryType, varName); var.getModifiers().add(Modifier.PRIVATE); var.getModifiers().add(Modifier.STATIC); return var; }
private static CodeTypeElement createContainer(NodeData node) { CodeTypeElement container; Modifier visibility = ElementUtils.getVisibility(node.getTemplateType().getModifiers()); String containerName = NodeFactoryFactory.factoryClassName(node); container = GeneratorUtils.createClass(node, null, modifiers(), containerName, null); if (visibility != null) { container.getModifiers().add(visibility); } container.getModifiers().add(Modifier.FINAL); return container; }
private static CodeVariableElement createNodeChild(ProcessorContext context, TypeMirror type, String name) { CodeVariableElement var = new CodeVariableElement(ElementUtils.modifiers(Modifier.PRIVATE), type, name); var.addAnnotationMirror(new CodeAnnotationMirror((DeclaredType) context.getType(Child.class))); return var; }
private static CodeTypeElement createContainer(NodeData node) { CodeTypeElement container; Modifier visibility = ElementUtils.getVisibility(node.getTemplateType().getModifiers()); String containerName = NodeFactoryFactory.factoryClassName(node); container = GeneratorUtils.createClass(node, null, modifiers(), containerName, null); if (visibility != null) { container.getModifiers().add(visibility); } container.getModifiers().add(Modifier.FINAL); return container; }
private Element createCreatePolymorphic(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) { SpecializationData polymorphic = node.getPolymorphicSpecialization(); CodeTypeElement generatedPolymorphic = generatedSpecializationClasses.get(polymorphic); if (generatedPolymorphic == null) { return null; } TypeMirror returnType = getType(SpecializationNode.class); CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), returnType, "createPolymorphic"); method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); method.createBuilder().startReturn().tree(createCallCreateMethod(polymorphic, null, null)).end(); return method; }
private CodeExecutableElement createInsertAccessor(boolean array) { CodeTypeParameterElement tVar = new CodeTypeParameterElement("T", context.getType(Node.class)); TypeMirror type = tVar.createMirror(null, null); if (array) { type = new ArrayCodeTypeMirror(type); } CodeExecutableElement insertAccessor = new CodeExecutableElement(modifiers(FINAL), type, INSERT_ACCESSOR_NAME); insertAccessor.getParameters().add(new CodeVariableElement(type, "node")); insertAccessor.getTypeParameters().add(tVar); insertAccessor.createBuilder().startReturn().string("super.insert(node)").end(); return insertAccessor; }
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 Element createGetNext(CodeTypeElement type) { if (!nextUsed) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), type.asType(), "getNext"); CodeTreeBuilder builder = method.createBuilder(); builder.startReturn().cast(type.asType(), CodeTreeBuilder.singleString("this.next")).end(); return method; }
private Element createDeepCopyMethod() { if (singleSpecializable) { return null; } CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), getType(Node.class), "deepCopy"); executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = executable.createBuilder(); builder.startReturn().startStaticCall(getType(SpecializationNode.class), "updateRoot").string("super.deepCopy()").end().end(); return executable; }
private Element createGetCostMethod() { TypeMirror returnType = getType(NodeCost.class); CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getCost"); executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = executable.createBuilder(); if (singleSpecializable) { builder.startReturn().staticReference(getType(NodeCost.class), "MONOMORPHIC").end().end(); } else { builder.startReturn().startCall(specializationStartFieldName(), "getNodeCost").end().end(); } return executable; }
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; }
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 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; }