Skip to content

Commit 0a452a0

Browse files
committed
refactor: simplify CSS location getters
1 parent 315d862 commit 0a452a0

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

src/main/java/com/adobe/epubcheck/css/CSSHandler.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import org.idpf.epubcheck.util.css.CssGrammar.CssSelector;
2020
import org.idpf.epubcheck.util.css.CssGrammar.CssURI;
2121
import org.idpf.epubcheck.util.css.CssLocation;
22-
import org.w3c.epubcheck.core.references.URLChecker;
2322
import org.w3c.epubcheck.core.references.Reference;
23+
import org.w3c.epubcheck.core.references.URLChecker;
2424

2525
import com.adobe.epubcheck.api.EPUBLocation;
2626
import com.adobe.epubcheck.api.Report;
@@ -82,6 +82,13 @@ private EPUBLocation getCorrectedEPUBLocation(int lineNumber, int columnNumber,
8282
return EPUBLocation.of(context).at(lineNumber, columnNumber).context(details);
8383
}
8484

85+
private EPUBLocation getCorrectedEPUBLocation(CssConstruct construct)
86+
{
87+
int line = correctedLineNumber(construct.getLocation().getLine());
88+
int col = correctedColumnNumber(line, construct.getLocation().getColumn());
89+
return EPUBLocation.of(context).at(line, col).context(construct.toCssString());
90+
}
91+
8592
private int correctedLineNumber(int lineNumber)
8693
{
8794
return startingLineNumber + lineNumber;
@@ -274,21 +281,15 @@ public void declaration(CssDeclaration declaration)
274281
String value = cns.toCssString();
275282
if (value != null && value.equalsIgnoreCase("fixed"))
276283
{
277-
report.message(MessageId.CSS_006,
278-
getCorrectedEPUBLocation(declaration.getLocation().getLine(),
279-
declaration.getLocation().getColumn(), declaration.toCssString()));
284+
report.message(MessageId.CSS_006, getCorrectedEPUBLocation(declaration));
280285
}
281286
}
282287
}
283288
if (version == EPUBVersion.VERSION_3)
284289
{
285290
if (propertyName.equals("direction") || propertyName.equals("unicode-bidi"))
286291
{
287-
report
288-
.message(MessageId.CSS_001,
289-
getCorrectedEPUBLocation(declaration.getLocation().getLine(),
290-
declaration.getLocation().getColumn(), declaration.toCssString()),
291-
propertyName);
292+
report.message(MessageId.CSS_001, getCorrectedEPUBLocation(declaration), propertyName);
292293
}
293294
}
294295

@@ -340,10 +341,8 @@ else if (version == EPUBVersion.VERSION_3)
340341
}
341342
if (!blessed)
342343
{
343-
report.message(MessageId.CSS_007,
344-
getCorrectedEPUBLocation(declaration.getLocation().getLine(),
345-
declaration.getLocation().getColumn(), declaration.toCssString()),
346-
fontURL, fontMimeType);
344+
report.message(MessageId.CSS_007, getCorrectedEPUBLocation(declaration), fontURL,
345+
fontMimeType);
347346
}
348347
}
349348

0 commit comments

Comments
 (0)