Skip to content

Commit

Permalink
[refactor] replace FSFunction.getName().equals() by shorter method …
Browse files Browse the repository at this point in the history
…"is"
  • Loading branch information
asolntsev committed Oct 12, 2024
1 parent ccc5ce7 commit 8b86962
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected IdentValue getListStyleType(FSFunction function) {
}

protected boolean isCounter(FSFunction function, String counterName) {
if (function.getName().equals("counter")) {
if (function.is("counter")) {
List<PropertyValue> parameters = function.getParameters();
if (parameters.size() == 1 || parameters.size() == 2) {
PropertyValue param = parameters.get(0);
Expand Down Expand Up @@ -175,7 +175,7 @@ public String getLayoutReplacementText() {

@Override
public boolean canHandle(LayoutContext c, FSFunction function) {
if (c.isPrint() && function.getName().equals("target-counter")) {
if (c.isPrint() && function.is("target-counter")) {
List<PropertyValue> parameters = function.getParameters();
if (parameters.size() == 2 || parameters.size() == 3) {
FSFunction f = parameters.get(0).getFunction();
Expand Down Expand Up @@ -279,7 +279,7 @@ public String getLayoutReplacementText() {

@Override
public boolean canHandle(LayoutContext c, FSFunction function) {
if (c.isPrint() && function.getName().equals("leader")) {
if (c.isPrint() && function.is("leader")) {
List<PropertyValue> parameters = function.getParameters();
if (parameters.size() == 1) {
PropertyValue param = parameters.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public FSFunction(String name, List<PropertyValue> parameters) {
_parameters = parameters;
}

public boolean is(String name) {
return _name.equals(name);
}

public String getName() {
return _name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ public List<PropertyDeclaration> buildDeclarations(
}

private boolean isFunctionAllowed(FSFunction function) {
String name = function.getName();
return name.equals("attr") || name.equals("counter") || name.equals("counters") ||
name.equals("element") || name.startsWith("-fs") || name.equals("target-counter") ||
name.equals("leader");
return function.is("attr") || function.is("counter") || function.is("counters") ||
function.is("element") || function.getName().startsWith("-fs") || function.is("target-counter") ||
function.is("leader");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ public List<PropertyDeclaration> buildDeclarations(
checkValidity(cssName, getAllowed(), ident);
} else if (value.getPropertyValueType() == VALUE_TYPE_FUNCTION) {
FSFunction function = value.getFunction();
if (function.getName().equals("running")) {
if (function.is("running")) {
List<PropertyValue> params = function.getParameters();
if (params.size() == 1) {
PropertyValue param = params.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ private static boolean isNestingTableContent(IdentValue display) {
}

private static boolean isAttrFunction(FSFunction function) {
if (function.getName().equals("attr")) {
if (function.is("attr")) {
List<PropertyValue> params = function.getParameters();
if (params.size() == 1) {
PropertyValue value = params.get(0);
Expand All @@ -693,7 +693,7 @@ private static boolean isAttrFunction(FSFunction function) {
}

public static boolean isElementFunction(FSFunction function) {
if (function.getName().equals("element")) {
if (function.is("element")) {
List<PropertyValue> params = function.getParameters();
if (params.isEmpty() || params.size() > 2) {
return false;
Expand All @@ -713,7 +713,7 @@ public static boolean isElementFunction(FSFunction function) {

@Nullable
private static CounterFunction makeCounterFunction(FSFunction function, LayoutContext c, CalculatedStyle style) {
if (function.getName().equals("counter")) {
if (function.is("counter")) {
List<PropertyValue> params = function.getParameters();
if (params.isEmpty() || params.size() > 2) {
return null;
Expand Down Expand Up @@ -748,7 +748,7 @@ private static CounterFunction makeCounterFunction(FSFunction function, LayoutCo
int counterValue = c.getCounterContext(style).getCurrentCounterValue(counter);

return new CounterFunction(counterValue, listStyleType);
} else if (function.getName().equals("counters")) {
} else if (function.is("counters")) {
List<PropertyValue> params = function.getParameters();
if (params.size() < 2 || params.size() > 3) {
return null;
Expand Down

0 comments on commit 8b86962

Please sign in to comment.