Skip to content

Commit

Permalink
Improve encapsulation within AbstractGnuToolPrefixMacro
Browse files Browse the repository at this point in the history
  • Loading branch information
jld01 committed Apr 19, 2023
1 parent 74d0478 commit b108aeb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,37 @@
*/
public abstract class AbstractGnuToolPrefixMacro implements IBuildMacro {

public static final String MACRO_NAME = IGnuToolFactory.GNU_TOOL_PREFIX_VARIABLE;

@Override
public String getName() {
return IGnuToolFactory.GNU_TOOL_PREFIX_VARIABLE;
public final String getName() {
return MACRO_NAME;
}

@Override
public int getValueType() {
public final int getValueType() {
return IBuildMacro.VALUE_TEXT;
}

@Override
public int getMacroValueType() {
public final int getMacroValueType() {
return getValueType();
}

@Override
public abstract String getStringValue() throws BuildMacroException;

@Override
public String[] getStringListValue() throws BuildMacroException {
public final String[] getStringListValue() throws BuildMacroException {
throw new BuildMacroException(
new CdtVariableException(ICdtVariableStatus.TYPE_MACRO_NOT_STRINGLIST, getName(), null, getName()));
new CdtVariableException(ICdtVariableStatus.TYPE_MACRO_NOT_STRINGLIST, MACRO_NAME, null, MACRO_NAME));
}

protected String getStringValue(IOption option) throws BuildMacroException {
try {
return option.getStringValue();
} catch (BuildException e) {
throw new BuildMacroException(Status.error("Error getting macro value: " + getName(), e)); //$NON-NLS-1$
throw new BuildMacroException(Status.error("Error getting macro value: " + MACRO_NAME, e)); //$NON-NLS-1$
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.eclipse.cdt.managedbuilder.macros.IBuildMacro;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
import org.eclipse.cdt.managedbuilder.macros.IConfigurationBuildMacroSupplier;
import org.eclipse.cdt.utils.IGnuToolFactory;
import org.eclipse.core.runtime.Status;

public class CrossBuildMacroSupplier implements IConfigurationBuildMacroSupplier {
Expand All @@ -47,15 +46,15 @@ public String getStringValue() throws BuildMacroException {

@Override
public IBuildMacro getMacro(String macroName, IConfiguration configuration, IBuildMacroProvider provider) {
if (IGnuToolFactory.GNU_TOOL_PREFIX_VARIABLE.equals(macroName)) {
if (GnuToolPrefixMacro.MACRO_NAME.equals(macroName)) {
return new GnuToolPrefixMacro(configuration);
}
return null;
}

@Override
public IBuildMacro[] getMacros(IConfiguration configuration, IBuildMacroProvider provider) {
final IBuildMacro macro = getMacro(IGnuToolFactory.GNU_TOOL_PREFIX_VARIABLE, configuration, provider);
final IBuildMacro macro = getMacro(GnuToolPrefixMacro.MACRO_NAME, configuration, provider);
return (null == macro) ? new IBuildMacro[0] : new IBuildMacro[] { macro };
}

Expand Down

0 comments on commit b108aeb

Please sign in to comment.