code: public FileDefinition buildFileDefinition( Graphs graphs, File targetFile, boolean addComment ) {
  
  		// Build the global structure
  		FileDefinition result = new FileDefinition( targetFile );
  		result.setFileType( FileDefinition.GRAPH );
  		if( addComment ) {
  			String s = "# File created from an in-memory model,\n# without a binding to existing files.";
  			BlockComment initialComment = new BlockComment( result, s );
  			result.getBlocks().add( initialComment );
  			result.getBlocks().add( new BlockBlank( result, "\n" ));
  		}
  
  		// Process and serialize the components
  		Set<String> alreadySerializedNames = new HashSet<> ();
  		for( Component c : ComponentHelpers.findAllComponents( graphs )) {
  			if( alreadySerializedNames.contains( c.getName()))
  				continue;
  
  			alreadySerializedNames.add( c.getName());
  			result.getBlocks().addAll( buildComponent( result, c, addComment ));
  			for( Facet f : ComponentHelpers.findAllFacets( c )) {
  				if( alreadySerializedNames.contains( f.getName()))
  					continue;
  
  				alreadySerializedNames.add( f.getName());
  				result.getBlocks().addAll( buildFacet( result, f, addComment ));
  			}
  		}
  
  		// There may be orphan facets too
  		for( Facet f : graphs.getFacetNameToFacet().values()) {
  			if( alreadySerializedNames.contains( f.getName()))
  				continue;
  
  			alreadySerializedNames.add( f.getName());
  			result.getBlocks().addAll( buildFacet( result, f, addComment ));
  		}
  
  		return result;
  	}
docs: Builds a file definition from a graph.
  @param graphs the graphs
  @param targetFile the target file (will not be written)
  @param addComment true to insert generated comments
  @return a non-null file definition