11package io .sloeber .ui .MarkerResolutionGenerator ;
22
3+ import static io .sloeber .core .api .Const .*;
4+ import static io .sloeber .ui .Messages .*;
35import java .util .HashSet ;
46import java .util .Map ;
57import java .util .Set ;
1921import io .sloeber .core .api .ConfigurationPreferences ;
2022import io .sloeber .core .api .ISloeberConfiguration ;
2123
24+
2225public class UnresolvedIncludesResolutionGenerator implements IMarkerResolutionGenerator {
2326
24- @ SuppressWarnings ("nls" )
2527 @ Override
2628 public IMarkerResolution [] getResolutions (IMarker marker ) {
2729 IMarkerResolution [] ret = new IMarkerResolution [0 ];
2830 try {
2931 Map <String , Object > attributes = marker .getAttributes ();
30- Object severityObject = attributes .get ("severity" );
32+ Object severityObject = attributes .get ("severity" ); //$NON-NLS-1$
3133 if (!(severityObject instanceof Integer )) {
3234 return ret ;
3335 }
3436 int severity = ((Integer ) severityObject ).intValue ();
3537 if (severity != 2 ) {
3638 return ret ;
3739 }
38- Object messageObject = attributes .get ("message" );
40+ Object messageObject = attributes .get ("message" ); //$NON-NLS-1$
3941 if (!(messageObject instanceof String )) {
4042 return ret ;
4143 }
4244 String message = (String ) messageObject ;
43- if (!message .endsWith (": No such file or directory" )) {
45+ if (!message .endsWith (": No such file or directory" )) { //$NON-NLS-1$
4446 return ret ;
4547 }
46- String libName = message .split (":" )[1 ].trim ();
48+ String libName = message .split (COLON )[1 ].trim ();
4749 if (libName .isBlank ()) {
4850 return ret ;
4951 }
50- if (!libName .endsWith (".h" )) {
52+ if (!libName .endsWith (".h" )) { //$NON-NLS-1$
5153 return ret ;
5254 }
5355
@@ -67,7 +69,7 @@ public IMarkerResolution[] getResolutions(IMarker marker) {
6769
6870 @ Override
6971 public String getLabel () {
70- return "Add the library to the project" ;
72+ return AddLibraryToProject . replace ( LIB_KEY , curlib . getFQN (). toString ()) ;
7173 }
7274
7375 @ Override
@@ -108,21 +110,25 @@ public void run(IMarker marker11) {
108110
109111 Map <String , IArduinoLibraryVersion > toInstallLibs = LibraryManager .getLatestInstallableLibraries (librariesToInstall );
110112
111- if (toInstallLibs .isEmpty ()) {
112- //No installable lib found
113+ if (toInstallLibs .size ()!=1 ) {
114+ //No or more than 1 installable lib found
115+ //skip
113116 return ret ;
114117 }
118+ IArduinoLibraryVersion toInstalllLib =toInstallLibs .get (libName );
115119
116120 ret = new IMarkerResolution [1 ];
117121 ret [0 ] = new IMarkerResolution () {
118122
119123 @ Override
120124 public String getLabel () {
121- return "Install the library in the workspace and add it to the project" ;
125+ return InstallAndAddLibraryToProject .replace (LIB_KEY ,toInstalllLib .getName ())
126+ .replace (VERSION_KEY , toInstalllLib .getVersion ().toString ())
127+ .replace (MAINTAINER , toInstalllLib .getMaintainer ());
122128 }
123129
124130 @ Override
125- public void run (@ SuppressWarnings ( "hiding" ) IMarker marker ) {
131+ public void run ( IMarker marker1 ) {
126132 IArduinoLibraryVersion curlib =null ;
127133
128134 for (Entry <String , IArduinoLibraryVersion > curLibSet : toInstallLibs .entrySet ()) {
0 commit comments