-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introducing serial_port dynamic variable
- Loading branch information
Showing
5 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/UartDynamicVariable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.espressif.idf.core.variable; | ||
|
||
public enum UartDynamicVariable | ||
{ | ||
SERIAL_PORT("serial_port"); //$NON-NLS-1$ | ||
|
||
private String value; | ||
|
||
UartDynamicVariable(String value) | ||
{ | ||
this.value = value; | ||
} | ||
|
||
public String getValue() | ||
{ | ||
return value; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/UartVariableResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.espressif.idf.core.variable; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.variables.IDynamicVariable; | ||
import org.eclipse.core.variables.IDynamicVariableResolver; | ||
import org.eclipse.launchbar.core.ILaunchBarManager; | ||
import org.eclipse.launchbar.core.target.ILaunchTarget; | ||
|
||
import com.espressif.idf.core.IDFCorePlugin; | ||
import com.espressif.idf.core.LaunchBarTargetConstants; | ||
import com.espressif.idf.core.logging.Logger; | ||
import com.espressif.idf.core.util.StringUtil; | ||
|
||
public class UartVariableResolver implements IDynamicVariableResolver | ||
{ | ||
|
||
public String resolveValue(IDynamicVariable variable, String argument) | ||
{ | ||
return getAppropriateEnumVariable(variable).map(this::resolveForDynamicEnum).orElse(variable.getName()); | ||
} | ||
|
||
private Optional<UartDynamicVariable> getAppropriateEnumVariable(IDynamicVariable variable) | ||
{ | ||
return Arrays.stream(UartDynamicVariable.values()).filter(v -> v.getValue().equals(variable.getName())) | ||
.findFirst(); | ||
} | ||
|
||
private String resolveForDynamicEnum(UartDynamicVariable enumVariable) | ||
{ | ||
|
||
return switch (enumVariable) | ||
{ | ||
case SERIAL_PORT -> getSerialPort(); // $NON-NLS-1$ | ||
}; | ||
} | ||
|
||
private String getSerialPort() | ||
{ | ||
return getActiveLaunchTarget().orElseGet(() -> ILaunchTarget.NULL_TARGET) | ||
.getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY); | ||
} | ||
|
||
private Optional<ILaunchTarget> getActiveLaunchTarget() | ||
{ | ||
|
||
try | ||
{ | ||
return Optional.of(IDFCorePlugin.getService(ILaunchBarManager.class).getActiveLaunchTarget()); | ||
} | ||
catch (CoreException e) | ||
{ | ||
Logger.log(e); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters