Generate everything after import statements.

@param entity The meta entity for which to write the body
@param context The processing context

@return body content
162594
private static StringBuffer generateBody(MetaEntity entity, Context context) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = null;
		try {
			pw = new PrintWriter( sw );

			if ( context.addGeneratedAnnotation() ) {
				pw.println( writeGeneratedAnnotation( entity, context ) );
			}
			if ( context.isAddSuppressWarningsAnnotation() ) {
				pw.println( writeSuppressWarnings() );
			}

			pw.println( writeStaticMetaModelAnnotation( entity ) );

			printClassDeclaration( entity, pw, context );

			pw.println();

			List<MetaAttribute> members = entity.getMembers();
			for ( MetaAttribute metaMember : members ) {
				pw.println( "	" + metaMember.getDeclarationString() );
			}

			pw.println();
			pw.println( "}" );
			return sw.getBuffer();
		}
		finally {
			if ( pw != null ) {
				pw.close();
			}
		}
	}
1254726
private void generateColumnsArray(Finder<SQLProperty> entity) {
		// generate columns array
		Builder sp = FieldSpec.builder(ArrayTypeName.of(String.class), "COLUMNS", Modifier.STATIC, Modifier.PRIVATE,
				Modifier.FINAL);
		String s = "";
		StringBuilder buffer = new StringBuilder();
		for (SQLProperty property : entity.getCollection()) {
			buffer.append(s + "COLUMN_" + columnNameToUpperCaseConverter.convert(property.getName()));
			s = ", ";
		}
		classBuilder.addField(sp.addJavadoc("Columns array\n").initializer("{" + buffer.toString() + "}").build());
		classBuilder.addMethod(MethodSpec.methodBuilder("columns").addModifiers(Modifier.PUBLIC)
				.addJavadoc("Columns array\n").addAnnotation(Override.class).returns(ArrayTypeName.of(String.class))
				.addStatement("return COLUMNS").build());

		classBuilder.addMethod(MethodSpec.methodBuilder("name").addModifiers(Modifier.PUBLIC).addJavadoc("table name\n")
				.addAnnotation(Override.class).returns(TypeName.get(String.class)).addStatement("return TABLE_NAME")
				.build());
	}
927867
private Context getContext(ExecutionContext executionContext) {
        // Get context id.
        HttpServletRequest request = executionContext.getActionBeanContext().getRequest();
        String parameter = request.getParameter(ID_PARAMETER);
        
        // Return context.
        if (parameter != null) {
            int id = Integer.parseInt(parameter, 16);
            return contexts.get(id);
        }
        
        return null;
    }
1364544
function create_content (body) {
      var meta = create_meta_info(body.meta_title, body.meta_description, body.meta_sort);
      return meta + body.content;
    }
939283
public CmsTemplateContextInfo getContextInfoBean(CmsObject cms, HttpServletRequest request) {

        CmsTemplateContextInfo result = new CmsTemplateContextInfo();
        CmsTemplateContext context = (CmsTemplateContext)request.getAttribute(ATTR_TEMPLATE_CONTEXT);
        if (context != null) {
            result.setCurrentContext(context.getKey());

            I_CmsTemplateContextProvider provider = context.getProvider();
            Locale locale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms);
            CmsXmlContentProperty settingDefinition = createTemplateContextsPropertyDefinition(provider, locale);
            result.setSettingDefinition(settingDefinition);
            String cookieName = context.getProvider().getOverrideCookieName();
            if (cookieName != null) {
                String cookieValue = CmsRequestUtil.getCookieValue(request.getCookies(), cookieName);
                result.setSelectedContext(cookieValue);
            }
            result.setCookieName(cookieName);
            Map<String, String> niceNames = new LinkedHashMap<String, String>();
            for (Map.Entry<String, CmsTemplateContext> entry : provider.getAllContexts().entrySet()) {
                CmsTemplateContext otherContext = entry.getValue();
                String niceName = otherContext.getLocalizedName(locale);
                niceNames.put(otherContext.getKey(), niceName);
                for (CmsClientVariant variant : otherContext.getClientVariants().values()) {
                    CmsClientVariantInfo info = new CmsClientVariantInfo(
                        variant.getName(),
                        variant.getNiceName(locale),
                        variant.getScreenWidth(),
                        variant.getScreenHeight(),
                        variant.getParameters());
                    result.setClientVariant(otherContext.getKey(), variant.getName(), info);
                }
            }
            result.setContextLabels(niceNames);
            result.setContextProvider(provider.getClass().getName());
        }
        Map<String, CmsDefaultSet<String>> allowedContextMap = safeGetAllowedContextMap();
        result.setAllowedContexts(allowedContextMap);
        return result;
    }
591296
private static void generateParseOnXmlAttributes(BindTypeContext context, MethodSpec.Builder methodBuilder,
			BindEntity entity) {
		BindTransform bindTransform;

		int count = 0;
		// count property to manage
		{
			// for each elements
			for (BindProperty property : entity.getCollection()) {
				if (property.xmlInfo.xmlType != XmlType.ATTRIBUTE)
					continue;

				count++;
			}
		}

		if (count > 0) {
			// @formatter:off
			methodBuilder.addCode("\n// attributes \n");
			methodBuilder.addStatement("String attributeName = null");
			// methodBuilder.addStatement("String attributeValue = null");

			methodBuilder.addStatement("int attributesCount = xmlParser.getAttributeCount();");
			methodBuilder.beginControlFlow(
					"for (int attributeIndex = 0; attributeIndex < attributesCount; attributeIndex++)");
			methodBuilder.addStatement("attributeName = xmlParser.getAttributeName(attributeIndex)");
			// methodBuilder.addStatement("attributeValue =
			// $T.unescapeXml(xmlParser.getAttributeValue(attributeIndex))",
			// StringEscapeUtils.class);
			methodBuilder.beginControlFlow("switch(attributeName)$>");

			for (BindProperty property : entity.getCollection()) {
				if (property.xmlInfo.xmlType != XmlType.ATTRIBUTE)
					continue;

				methodBuilder.addCode("case $S:\n$>", BindProperty.xmlName(property));

				bindTransform = BindTransformer.lookup(property);
				methodBuilder.addCode("// field $L (mapped by $S)\n", property.getName(),
						BindProperty.xmlName(property));
				bindTransform.generateParseOnXml(context, methodBuilder, "xmlParser",
						property.getPropertyType().getTypeName(), "instance", property);

				methodBuilder.addStatement("$<break");
			}

			methodBuilder.addCode("default:\n$>");
			methodBuilder.addStatement("$<break$<");
			methodBuilder.endControlFlow();

			methodBuilder.endControlFlow();
			// @formatter:on
		} else {
			methodBuilder.addCode("// No attributes found\n");
		}
	}
533406
public ApiResponse createEntity(Entity entity) {
        assertValidApplicationId();
        if (isEmpty(entity.getType())) {
            throw new IllegalArgumentException("Missing entity type");
        }
        ApiResponse response = apiRequest(HttpMethod.POST, null, entity,
                organizationId, applicationId, entity.getType());
        return response;
    }
1270260
private void generateEntity(M2MEntity entity) {
		entity.propertyPrimaryKey = TypeName.LONG;
		entity.propertyKey1 = findPrimaryKeyFieldType(entity.entity1Name.toString());
		entity.propertyKey2 = findPrimaryKeyFieldType(entity.entity2Name.toString());
		if (!entity.needToCreate) {
			return;
		}

		String tableName = entity.tableName;
		String entityClassName = entity.name;

		AnnotationProcessorUtilis.infoOnGeneratedClasses(BindDaoMany2Many.class, entity.getPackageName(),
				entityClassName);

		Converter<String, String> converterFK = CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.UPPER_CAMEL);
		Converter<String, String> converterFieldName = CaseFormat.UPPER_CAMEL.converterTo(CaseFormat.LOWER_CAMEL);
		Converter<String, String> converterField2ColumnName = CaseFormat.LOWER_CAMEL
				.converterTo(CaseFormat.LOWER_UNDERSCORE);
		String fkPrefix = converterFK.convert(entity.idName);

		String fk1Name = converterField2ColumnName.convert(entity.entity1Name.simpleName() + fkPrefix);
		String fk2Name = converterField2ColumnName.convert(entity.entity2Name.simpleName() + fkPrefix);

		String field1Name = converterFieldName.convert(entity.entity1Name.simpleName() + fkPrefix);
		String field2Name = converterFieldName.convert(entity.entity2Name.simpleName() + fkPrefix);

		List<SQLProperty> properties = new ArrayList<SQLProperty>();

		// we define property type later
		{
			SQLProperty property = new SQLProperty(entity.idName, entity.getClassName(), entity.propertyPrimaryKey);
			property.columnType = ColumnType.PRIMARY_KEY;
			property.columnName = entity.idName;
			property.setNullable(false);
			property.setPrimaryKey(true);
			property.foreignParentClassName = null;
			properties.add(property);
		}

		{
			SQLProperty property = new SQLProperty(field1Name, entity.getClassName(), entity.propertyKey1);
			property.columnType = ColumnType.INDEXED;
			property.columnName = fk1Name;
			property.setNullable(false);
			property.setPrimaryKey(false);
			property.onDeleteAction = ForeignKeyAction.CASCADE;
			property.foreignParentClassName = entity.entity1Name.toString();
			properties.add(property);
		}

		{
			SQLProperty property = new SQLProperty(field2Name, entity.getClassName(), entity.propertyKey2);
			property.columnType = ColumnType.INDEXED;
			property.columnName = fk2Name;
			property.setNullable(false);
			property.setPrimaryKey(false);
			property.onDeleteAction = ForeignKeyAction.CASCADE;
			property.foreignParentClassName = entity.entity2Name.toString();
			properties.add(property);
		}

		// @formatter:off
		classBuilder = TypeSpec.classBuilder(entityClassName).addModifiers(Modifier.PUBLIC)
				.addAnnotation(AnnotationSpec.builder(BindSqlType.class).addMember("name", "$S", tableName).build());
		// @formatter:on

		if (entity.immutable) {
			// create constructor
			Builder constructorBuilder = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC);
			for (SQLProperty p : properties) {
				constructorBuilder
						.addParameter(ParameterSpec.builder(p.getPropertyType().getTypeName(), p.getName()).build());
				constructorBuilder.addStatement("this.$L=$L", p.getName(), p.getName());
			}
			classBuilder.addMethod(constructorBuilder.build());
		}

		Modifier fieldModifier = entity.immutable ? Modifier.PRIVATE : Modifier.PUBLIC;

		// javadoc for class
		classBuilder.addJavadoc("<p>");
		classBuilder.addJavadoc("\nGenerated entity implementation for <code>$L</code>\n", entity.name);
		classBuilder.addJavadoc("</p>\n");
		JavadocUtility.generateJavadocGeneratedBy(classBuilder);
		// classBuilder.addJavadoc(" @see $T\n",		

		{
			// @formatter:off
			FieldSpec fieldSpec = FieldSpec.builder(entity.propertyPrimaryKey, entity.idName, fieldModifier)
					.addJavadoc("Primary key\n")
					.addAnnotation(AnnotationSpec.builder(BindSqlColumn.class)
							.addMember("columnType", "$T.$L", ColumnType.class, ColumnType.PRIMARY_KEY).build())
					.build();
			// @formatter:on
			classBuilder.addField(fieldSpec);
		}

		{
			// @formatter:off
			FieldSpec fieldSpec = FieldSpec
					.builder(entity.propertyKey1, field1Name, fieldModifier)
					.addJavadoc("Foreign key to $T model class\n", entity.entity1Name)
					.addAnnotation(AnnotationSpec.builder(BindSqlColumn.class)
							.addMember(AnnotationAttributeType.PARENT_ENTITY.getValue(), "$T.class", entity.entity1Name)
							.addMember(AnnotationAttributeType.ON_DELETE.getValue(), "$T.$L", ForeignKeyAction.class,
									ForeignKeyAction.CASCADE)
							.build())
					.build();
			// @formatter:on
			classBuilder.addField(fieldSpec);
		}

		{
			// @formatter:off
			FieldSpec fieldSpec = FieldSpec
					.builder(entity.propertyKey2, field2Name, fieldModifier)
					.addJavadoc("Foreign key to $T model class\n", entity.entity2Name)
					.addAnnotation(AnnotationSpec.builder(BindSqlColumn.class)
							.addMember(AnnotationAttributeType.PARENT_ENTITY.getValue(), "$T.class", entity.entity2Name)
							.addMember(AnnotationAttributeType.ON_DELETE.getValue(), "$T.$L", ForeignKeyAction.class,
									ForeignKeyAction.CASCADE)
							.build())
					.build();
			// @formatter:on
			classBuilder.addField(fieldSpec);
		}

		if (entity.immutable) {
			// getters
			for (SQLProperty p : properties) {
				Builder methodBuilder = MethodSpec
						.methodBuilder("get" + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, p.getName()))
						.returns(p.getPropertyType().getTypeName()).addStatement("return this.$L", p.getName())
						.addModifiers(Modifier.PUBLIC);

				classBuilder.addMethod(methodBuilder.build());
			}
		}

		TypeSpec typeSpec = classBuilder.build();

		try {
			JavaWriterHelper.writeJava2File(filer, entity.getPackageName(), typeSpec);
		} catch (IOException e) {
			throw new KriptonRuntimeException(e);
		}

		GeneratedTypeElement entityElement = new GeneratedTypeElement(entity.getPackageName(), classBuilder.build(),
				tableName, fk1Name + ", " + fk2Name);

		entityElement.properties = properties;

		entityResult.add(entityElement);
	}
1043749
private static void generateParseOnJackson(BindTypeContext context, BindEntity entity) {
		// @formatter:off
		MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("parseOnJackson").addJavadoc("parse with jackson\n")
				.addAnnotation(Override.class).addModifiers(Modifier.PUBLIC)
				// .addParameter(typeName(AbstractJacksonContext.class),
				// "context")
				.addParameter(typeName(JsonParser.class), "jacksonParser").returns(typeName(entity.getElement()))
				.addException(Exception.class);
		// @formatter:on

		boolean mutableObject = entity.isMutablePojo();

		if (mutableObject) {
			methodBuilder.addStatement("$T instance = new $T()", entity.getElement(), entity.getElement());
		} else {
			ImmutableUtility.generateImmutableVariableInit(entity, methodBuilder);
		}
		methodBuilder.addStatement("String fieldName");

		methodBuilder.beginControlFlow("if (jacksonParser.currentToken() == null)");
		methodBuilder.addStatement("jacksonParser.nextToken()");
		methodBuilder.endControlFlow();

		methodBuilder.beginControlFlow("if (jacksonParser.currentToken() != $T.START_OBJECT)", JsonToken.class);
		methodBuilder.addStatement("jacksonParser.skipChildren()");
		if (!mutableObject) {
			ImmutableUtility.generateImmutableEntityCreation(entity, methodBuilder, "instance", true);
		}
		methodBuilder.addStatement("return instance");
		methodBuilder.endControlFlow();

		methodBuilder.beginControlFlow("while (jacksonParser.nextToken() != $T.END_OBJECT)", JsonToken.class);
		methodBuilder.addStatement("fieldName = jacksonParser.getCurrentName()");
		methodBuilder.addStatement("jacksonParser.nextToken()");

		if (entity.getCollection().size() > 0) {
			methodBuilder.addCode("\n// Parse fields:\n");
			methodBuilder.beginControlFlow("switch (fieldName)$>");

			BindTransform bindTransform;
			for (BindProperty item : entity.getCollection()) {
				bindTransform = BindTransformer.lookup(item);

				methodBuilder.addCode("case $S:\n$>", item.label);
				methodBuilder.addCode("// field $L (mapped with $S)\n", item.getName(), item.label);

				bindTransform.generateParseOnJackson(context, methodBuilder, "jacksonParser",
						item.getPropertyType().getTypeName(), "instance", item);

				methodBuilder.addCode("$<break;\n");
			}

			methodBuilder.addCode("default:$>\n");
			methodBuilder.addStatement("jacksonParser.skipChildren()");
			methodBuilder.addCode("$<break;");

			methodBuilder.addCode("$<");
			methodBuilder.endControlFlow();
		} else {
			methodBuilder.addCode("\n// No field to parse\n");
		}

		methodBuilder.endControlFlow();

		if (!mutableObject) {
			ImmutableUtility.generateImmutableEntityCreation(entity, methodBuilder, "instance", true);
		}
		methodBuilder.addStatement("return instance");

		context.builder.addMethod(methodBuilder.build());

	}
1035835
public void generate(Context context) {
        Appendable target = context.getTarget();

        for (ProcTemplateElement element : elements) {
            try {
                target.append(element.generate(context));
            } catch (IOException e) {
                // Nothing! Because StringBuilder doesn't catch IOException
            }
        }
    }
287311
private void buildSimpleEntity(EntityConfig entityConfig, Entity entity) {
        Table table = entity.getTable();

        // 1st phase: process all column and look for corresponding columnConfig
        for (Column column : table.getColumns()) {
            boolean processed = processColumnUsingColumnConfigIfAny(entityConfig, entity, column);

            // no columnConfig, we just use defaults
            if (!processed) {
                entity.addAttribute(attributeFactory.build(entity, table, column));
            }
        }

        // detect invalid column and jpa secondary case
        processInvalidColumnConfigAndJpaSecondaryTable(entityConfig, entity);
    }
1344456
private void initEntityMetadata(Entity entity) {
    String kind = entity.kind();
    if (kind.trim().length() == 0) {
      kind = entityClass.getSimpleName();
    }
    entityMetadata = new EntityMetadata(entityClass, kind);
  }
1210394
private void generateContextHandlerMeta(final Set<Bean<?>> processBeans) {
        for (final Bean<?> latkeBean : processBeans) {
            final Class<?> clz = latkeBean.getBeanClass();
            final Method[] declaredMethods = clz.getDeclaredMethods();
            for (int i = 0; i < declaredMethods.length; i++) {
                final Method method = declaredMethods[i];
                final RequestProcessing requestProcessingMethodAnn = method.getAnnotation(RequestProcessing.class);
                if (null == requestProcessingMethodAnn) {
                    continue;
                }

                final ContextHandlerMeta contextHandlerMeta = new ContextHandlerMeta();
                contextHandlerMeta.setUriTemplates(requestProcessingMethodAnn.value());
                contextHandlerMeta.setHttpMethods(requestProcessingMethodAnn.method());
                contextHandlerMeta.setInvokeHolder(method);
                contextHandlerMeta.initProcessAdvices();

                addContextHandlerMeta(contextHandlerMeta);
            }
        }
    }
1372583
protected function generateBody(Entity $entity)
    {
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];
        $extLines   = $this->generateExtensionsSerializedSize($entity);

        $body[] = '$calculator = $context->getSizeCalculator();';
        $body[] = '$size       = 0;';
        $body[] = null;

        foreach ($fields as $field) {
            $lines = $this->generateFieldCondition($entity, $field);
            $body  = array_merge($body, $lines, [null]);
        }

        $body   = array_merge($body, $extLines);
        $body[] = null;
        $body[] = 'return $size;';

        return $body;
    }
283327
function do_create_context(context) {
		var context = context || {};
		
		if(!context.replace) {
			context.replace = (function(chunk, context, bodies, params) {
					return chunk.tap(function(data) {
						return (params.from && params.to && (data === params.from) ) ? params.to : data;
					}).render(bodies.block, context).untap();
				});
		}
		
		if(!context.toFixed) {
			context.toFixed = (function(chunk, context, bodies, params) {
					return chunk.tap(function(data) {
						return parseFloat(data).toFixed(params.x || 0);
					}).render(bodies.block, context).untap();
				}); // end of context
		}
		
		return context;
	}
814265
private static void generateSingleReadMethod(PrefsEntity entity) {
		// read method
		PrefsTransform transform;
		Converter<String, String> converter = CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.UPPER_CAMEL);

		for (PrefsProperty item : entity.getCollection()) {
			MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("get" + converter.convert(item.getName())).addModifiers(Modifier.PUBLIC)
					.addJavadoc("reads property <code>$L</code> from shared pref with key <code>$L</code>\n\n", item.getName(), item.getPreferenceKey())
					.addJavadoc("@return property $L value\n", item.getName()).returns(item.getPropertyType().getTypeName());

			if (item.hasTypeAdapter()) {
				transform = PrefsTransformer.lookup(item.typeAdapter.getDataTypeTypename());
			} else {
				transform = PrefsTransformer.lookup(item);
			}

			transform.generateReadProperty(methodBuilder, "prefs", typeName(item.getElement().asType()), "defaultBean", item, false, ReadType.RETURN);

			builder.addMethod(methodBuilder.build());
		}

	}
498394
@SuppressWarnings("unchecked")
	@Override
	public int insert(final Object entity) {
		@SuppressWarnings("rawtypes")
		EntityHandler handler = this.getEntityHandler();
		if (!handler.getEntityType().isInstance(entity)) {
			throw new IllegalArgumentException("Entity type not supported");
		}

		try {
			Class<?> type = entity.getClass();
			TableMetadata metadata = handler.getMetadata(this.transactionManager, type);
			SqlContext context = handler.createInsertContext(this, metadata, type);
			context.setSqlKind(SqlKind.INSERT);

			// IDアノテーションが付与されたカラム情報を取得する
			MappingColumn[] idColumns = MappingUtils.getIdMappingColumns(type);

			setGeneratedKeyColumns(context, idColumns, metadata);

			handler.setInsertParams(context, entity);
			int count = handler.doInsert(this, context, entity);

			if (idColumns != null && idColumns.length > 0) {
				BigDecimal[] ids = context.getGeneratedKeyValues();
				int idx = 0;
				for (MappingColumn col : idColumns) {
					BigDecimal id = ids[idx++];
					setEntityIdValue(entity, id, col);
				}
			}

			return count;
		} catch (SQLException e) {
			throw new EntitySqlRuntimeException(SqlKind.INSERT, e);
		}
	}