@Override public boolean writeExpression(JavaFileWriter writer) throws IOException { writer.appendExpression(condition) .appendString(" ? ") .appendExpression(ifTrue) .appendString(" : ") .appendExpression(ifFalse); return true; } }
@Override protected void writeGetterBody(JavaFileWriter writer, MethodDeclarationParameters params) throws IOException { writer.writeStringStatement("return super.getRowId()"); }
private void emitTableModelMapper() throws IOException { writer.writeComment("--- mappers"); writer.writeFieldDeclaration(TypeConstants.TABLE_MAPPING_VISITORS, "tableMappingInfo", Expressions.callMethod("generateTableMappingVisitors", PROPERTIES_ARRAY_NAME, ALIASED_PROPERTY_ARRAY_NAME, BASE_PROPERTY_ARRAY_NAME), TypeConstants.PRIVATE_STATIC_FINAL) .writeNewline(); writer.writeAnnotation(CoreTypes.OVERRIDE) .beginMethodDefinition(GET_TABLE_MAPPING_VISITORS) .writeStringStatement("return tableMappingInfo") .finishMethodDefinition(); }
private void emitAliasedPropertyArray() throws IOException { writer.writeComment("--- aliased property references"); Expression aliasedPropertiesInit = Expressions.block(new Expression() { @Override public boolean writeExpression(JavaFileWriter writer) throws IOException { return emitPropertyReferenceArrayBody(true); } }, false, false, false, false); writer.writeFieldDeclaration(TypeConstants.PROPERTY_ARRAY, ALIASED_PROPERTY_ARRAY_NAME, aliasedPropertiesInit, TypeConstants.PUBLIC_STATIC_FINAL) .writeNewline(); writer.beginInitializerBlock(true, true); writer.writeStatement(Expressions.callMethod("validateAliasedProperties", ALIASED_PROPERTY_ARRAY_NAME)); writer.finishInitializerBlock(false, true); writer.writeNewline(); }
@Override public boolean writeExpression(JavaFileWriter writer) throws IOException { writer.appendString("@") .appendString(writer.shortenName(MODEL_GEN_ERRORS, false)) .appendString("({\n"); writer.moveToScope(JavaFileWriter.Scope.METHOD_DEFINITION); boolean needsNewline = false; for (ErrorInfo errorInfo : errors) { if (needsNewline) { writer.appendString(",").writeNewline(); } needsNewline = true; writer.writeExpression(new ModelGenErrorSingle(errorInfo)); } writer.writeNewline(); writer.finishScope(JavaFileWriter.Scope.METHOD_DEFINITION); writer.writeString("})"); return true; } }
@Override protected void writeGetterBody(JavaFileWriter writer, MethodDeclarationParameters params) throws IOException { final String value = "value"; writer.writeFieldDeclaration(CoreTypes.JAVA_STRING, value, Expressions.callMethod("get", propertyName)); Expression condition = Expressions.fromString(value + " == null"); Expression ifTrue = Expressions.fromString("null"); Expression ifFalse = Expressions.staticMethod(enumType, "valueOf", value); TernaryExpression ternary = new TernaryExpression(condition, ifTrue, ifFalse); writer.writeStatement(ternary.returnExpr()); }
private void emitUnaliasedPropertyArray() throws IOException { writer.writeComment("--- unaliased property references"); Expression basePropertiesInit = Expressions.block(new Expression() { @Override public boolean writeExpression(JavaFileWriter writer) throws IOException { return emitPropertyReferenceArrayBody(false); } }, false, false, false, false); writer.writeFieldDeclaration(TypeConstants.PROPERTY_ARRAY, BASE_PROPERTY_ARRAY_NAME, basePropertiesInit, TypeConstants.PRIVATE_STATIC_FINAL) .writeNewline(); }
/** * Subclasses can override this hook to generate a custom method body for the property setter. This version of the * hook is deprecated, users should use {@link #writeGetterBody(JavaFileWriter, MethodDeclarationParameters)} * instead. */ @Deprecated protected void writeSetterBody(JavaFileWriter writer, String argName) throws IOException { writer.writeStatement(Expressions.callMethod("set", propertyName, argName)); writer.writeStringStatement("return this"); }
protected void emitPropertiesArray() throws IOException { writer.writeComment("--- allocate properties array"); writer.writeFieldDeclaration(TypeConstants.PROPERTY_ARRAY, PROPERTIES_ARRAY_NAME, Expressions.arrayAllocation(TypeConstants.PROPERTY, 1, getPropertiesArrayLength()), TypeConstants.PUBLIC_STATIC_FINAL); writer.writeNewline(); }
@Override protected void writeSetterBody(JavaFileWriter writer, MethodDeclarationParameters params) throws IOException { writer.writeStringStatement("super.setRowId(" + params.getArgumentNames().get(0) + ")"); writer.writeStringStatement("return this"); } }
protected void emitPropertyArrayInitialization() throws IOException { writer.beginInitializerBlock(true, true); writePropertiesInitializationBlock(); writer.finishInitializerBlock(false, true); }
@Override protected void emitPropertiesArray() throws IOException { writer.writeFieldDeclaration(TypeConstants.PROPERTY_ARRAY, PROPERTIES_ARRAY_NAME, Expressions.staticReference(modelSpec.getModelSuperclass(), PROPERTIES_ARRAY_NAME), TypeConstants.PUBLIC_STATIC_FINAL); }
private void addAccessorDocumentationForRowids(JavaFileWriter writer, PropertyGenerator propertyGenerator, boolean getter) throws IOException { if (propertyGenerator instanceof RowidPropertyGenerator) { if (DEFAULT_ROWID_PROPERTY_NAME.equals(propertyGenerator.getPropertyName())) { writer.writeAnnotation(CoreTypes.OVERRIDE); } else { writer.writeJavadoc(" This " + (getter ? "getter" : "setter") + " is an alias for " + (getter ? "get" : "set") + "RowId(), as the underlying column is an INTEGER PRIMARY KEY"); } } }
private void emitPropertyDeclarations() throws IOException { writer.writeComment("--- property declarations"); emitAllProperties(); emitPropertyArrayInitialization(); writer.writeNewline(); }
private void emitImports() throws IOException { Set<DeclaredTypeName> imports = new HashSet<>(); modelSpec.addRequiredImports(imports); writer.writeImports(imports); writer.registerOtherKnownNames(TypeConstants.CREATOR, TypeConstants.TABLE_MAPPING_VISITORS, modelSpec.getModelSpecName()); }
@Override public void beforeEmitClassDeclaration(JavaFileWriter writer) throws IOException { String generatedJavadoc = " This class was generated from the model spec at " + "{@link " + modelSpec.getModelSpecName() + "}"; String elementJavadoc = utils.getElements().getDocComment(modelSpec.getModelSpecElement()); if (!AptUtils.isEmpty(elementJavadoc)) { generatedJavadoc = (generatedJavadoc + "\n <br/>\n" + elementJavadoc); } writer.writeJavadoc(generatedJavadoc); writer.writeComment("Generated code -- do not modify!"); }
@Override public final void emitSetter(JavaFileWriter writer) throws IOException { if (isDeprecated) { return; } MethodDeclarationParameters params = setterMethodParams(); modelSpec.getPluginBundle().beforeEmitSetter(writer, this, params); writer.beginMethodDefinition(params); writeSetterBody(writer, params); writer.finishMethodDefinition(); modelSpec.getPluginBundle().afterEmitSetter(writer, this, params); }
public final void writeJava() throws IOException { initFileWriter(); writeJavaFile(); writer.close(); }
private void emitPackage() throws IOException { writer.writePackage(modelSpec.getGeneratedClassName().getPackageName()); }
/** * Helper method that other plugins can use to copy javadocs from an Element */ public static void writeJavadocFromElement(PluginEnvironment pluginEnv, JavaFileWriter writer, Element element) throws IOException { if (!pluginEnv.hasSquidbOption(PluginEnvironment.OPTIONS_DISABLE_JAVADOC_COPYING)) { writer.writeJavadoc(pluginEnv.getUtils().getElements().getDocComment(element)); } } }