2727import java .nio .file .Path ;
2828import java .util .ArrayList ;
2929import java .util .List ;
30- import java .util .stream .Stream ;
3130
3231import org .eclipse .emf .common .util .BasicEList ;
3332import org .eclipse .emf .ecore .resource .Resource ;
@@ -49,30 +48,35 @@ protected static String formatEntry(String elementName, String resourcePath) {
4948 }
5049
5150 public String index (String inputPath ) {
51+ java .util .LinkedHashMap <String , String > map = indexAsMap (inputPath );
52+ List <String > entries = new ArrayList <>();
53+ for (var entry : map .entrySet ()) {
54+ entries .add (formatEntry (entry .getKey (), entry .getValue ()));
55+ }
56+ return String .join ("\n " , entries );
57+ }
58+
59+ public java .util .LinkedHashMap <String , String > indexAsMap (String inputPath ) {
5260 read (inputPath );
5361 File inputFile = new File (inputPath );
62+ String inputDir = inputPath ;
5463 if (!inputFile .isDirectory ()) {
55- inputPath = inputFile .getParent ();
56- if (inputPath == null ) {
57- inputPath = "" ;
58- }
64+ inputDir = inputFile .getParent ();
65+ if (inputDir == null ) inputDir = "" ;
5966 }
60- List <String > entries = new ArrayList <>();
61- for (Resource resource : getInputResources ()) {
62- String resourcePath = resource .getURI ().toFileString ().replace (inputPath + "/" , "" );
63- Namespace rootNamespace = (Namespace )resource .getContents ().get (0 );
67+ java . util . TreeMap <String , String > sorted = new java . util . TreeMap <>();
68+ for (Resource resource : getInputResources ()) {
69+ String resourcePath = resource .getURI ().toFileString ().replace (inputDir + "/" , "" );
70+ Namespace rootNamespace = (Namespace ) resource .getContents ().get (0 );
6471 List <Membership > memberships = rootNamespace .visibleMemberships (new BasicEList <>(), false , false );
65- Stream <String > names = memberships .stream ().map (Membership ::getMemberName );
66- Stream <String > shortNames = memberships .stream ().map (Membership ::getMemberShortName );
67- Stream .concat (names , shortNames )
68- .filter (name ->name != null )
69- .map (name ->formatEntry (name , resourcePath ))
70- .forEach (entries ::add );
72+ for (Membership m : memberships ) {
73+ if (m .getMemberName () != null ) sorted .put (m .getMemberName (), resourcePath );
74+ if (m .getMemberShortName () != null ) sorted .put (m .getMemberShortName (), resourcePath );
75+ }
7176 }
72- entries .sort (null );
73- return String .join ("\n " , entries );
77+ return new java .util .LinkedHashMap <>(sorted );
7478 }
75-
79+
7680 public void writeIndex (String inputPath , String outputPath ) throws IOException {
7781 String index = index (inputPath );
7882 System .out .println ("Writing " + outputPath + "..." );
0 commit comments