@@ -1211,7 +1211,7 @@ public void actionPerformed(ActionEvent event) {
1211
1211
boolean ifound = false ;
1212
1212
1213
1213
for (String potentialName : list ) {
1214
- File subfolder = new File (folder , potentialName );
1214
+ File libFolder = new File (folder , potentialName );
1215
1215
// File libraryFolder = new File(subfolder, "library");
1216
1216
// File libraryJar = new File(libraryFolder, potentialName + ".jar");
1217
1217
// // If a .jar file of the same prefix as the folder exists
@@ -1240,27 +1240,37 @@ public void actionPerformed(ActionEvent event) {
1240
1240
// // need to associate each import with a library folder
1241
1241
// String packages[] =
1242
1242
// Compiler.packageListFromClassPath(libraryClassPath);
1243
- libraries .add (subfolder );
1243
+ libraries .add (libFolder );
1244
+ String libFolderPath = libFolder .getAbsolutePath ();
1244
1245
try {
1245
- String packages [] =
1246
- Compiler .headerListFromIncludePath (subfolder .getAbsolutePath ());
1247
- for (String pkg : packages ) {
1248
- File old = importToLibraryTable .get (pkg );
1246
+ String headers [] = Compiler .headerListFromIncludePath (libFolderPath );
1247
+ for (String header : headers ) {
1248
+ // Extract file name (without extension ".h")
1249
+ String name = header .substring (0 , header .length () - 2 );
1250
+
1251
+ // If the header name equals to the current library folder use it
1252
+ if (libFolderPath .endsWith (name )) {
1253
+ importToLibraryTable .put (header , libFolder );
1254
+ continue ;
1255
+ }
1256
+
1257
+ // If a library was already found with this header, keep it if
1258
+ // the library's directory name matches the header name.
1259
+ File old = importToLibraryTable .get (header );
1249
1260
if (old != null ) {
1250
- // If a library was already found with this header, keep it if
1251
- // the library's directory name matches the header name.
1252
- String name = pkg .substring (0 , pkg .length () - 2 );
1253
- if (old .getPath ().endsWith (name )) continue ;
1261
+ if (old .getPath ().endsWith (name ))
1262
+ continue ;
1254
1263
}
1255
- importToLibraryTable .put (pkg , subfolder );
1264
+ importToLibraryTable .put (header , libFolder );
1256
1265
}
1257
1266
} catch (IOException e ) {
1258
- showWarning (_ ("Error" ), I18n .format ("Unable to list header files in {0}" , subfolder ), e );
1267
+ showWarning (_ ("Error" ), I18n .format (
1268
+ "Unable to list header files in {0}" , libFolder ), e );
1259
1269
}
1260
1270
1261
1271
JMenuItem item = new JMenuItem (libraryName );
1262
1272
item .addActionListener (listener );
1263
- item .setActionCommand (subfolder . getAbsolutePath () );
1273
+ item .setActionCommand (libFolderPath );
1264
1274
menu .add (item );
1265
1275
ifound = true ;
1266
1276
0 commit comments