/** * Parses a field type definition * * @param docField * @return */ protected static Field ParseField(FieldDoc docField) { assert (docField != null); Field xmlField = new Field(); xmlField.name = docField.name(); xmlField.comment = docField.commentText(); xmlField.type = ParseType(docField.type()); xmlField.isFinal = docField.isFinal(); if (xmlField.isFinal) { xmlField.finalExpression = docField.constantValueExpression(); } else if (docField.constantValueExpression() != null) { // how would a non-final field have a constant value expression? // my understanding is that this field is only != null when is not final assert (false); } xmlField.isStatic = docField.isStatic(); xmlField.isVolatile = docField.isVolatile(); xmlField.isTransient = docField.isTransient(); xmlField.scope = DetermineScope(docField); // parse annotations from the field xmlField.annotationInstances = ParseAnnotationInstances(docField.annotations(), docField.qualifiedName()); return xmlField; }
/** * 给字段添加数据库备注 * * @param field * @param introspectedTable * @param introspectedColumn */ public void addFieldComment( Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) { field.addJavaDocLine("/**"); StringBuilder sb = new StringBuilder(); sb.append(" * "); sb.append(introspectedColumn.getRemarks()); field.addJavaDocLine(sb.toString()); field.addJavaDocLine(" */"); } // 添加注解 if (field.isTransient()) { // @Column field.addAnnotation("@Transient"); } for (IntrospectedColumn column : introspectedTable.getPrimaryKeyColumns()) { if (introspectedColumn == column) { field.addAnnotation("@Id"); break; } } String column = introspectedColumn.getActualColumnName(); if (StringUtility.stringContainsSpace(column) || introspectedTable.getTableConfiguration().isAllColumnDelimitingEnabled()) { column = introspectedColumn.getContext().getBeginningDelimiter() + column + introspectedColumn.getContext().getEndingDelimiter(); } if (!column.equals(introspectedColumn.getJavaProperty())) { // @Column field.addAnnotation("@Column(name = \"" + column + "\")"); } if (introspectedColumn.isIdentity()) { if (introspectedTable .getTableConfiguration() .getGeneratedKey() .getRuntimeSqlStatement() .equals("JDBC")) { field.addAnnotation("@GeneratedValue(generator = \"JDBC\")"); } else { field.addAnnotation("@GeneratedValue(strategy = GenerationType.IDENTITY)"); } } else if (introspectedColumn.isSequenceColumn()) { field.addAnnotation( "@SequenceGenerator(name=\"\",sequenceName=\"" + introspectedTable.getTableConfiguration().getGeneratedKey().getRuntimeSqlStatement() + "\")"); } }
private void importField(DbJVClass dbClaz, Field field) throws DbException { if (dbClaz == null) { return; } DbJVDataMember member = new DbJVDataMember(dbClaz); member.setName(field.getName()); // set field type Type type = field.getType(); member.setType(toAdt(type)); member.setTypeUse(toTypeUse(type)); // set field modifiers member.setFinal(field.isFinal()); member.setStatic(field.isStatic()); member.setTransient(field.isTransient()); member.setVisibility(toVisibility(field)); member.setVolatile(field.isVolatile()); }