Skip to content

Commit

Permalink
#442 annotate all methods in package org.xhtmlrenderer.pdf with @Ch…
Browse files Browse the repository at this point in the history
…eckReturnValue
  • Loading branch information
asolntsev committed Nov 12, 2024
1 parent cf54bb3 commit 7ce48f5
Show file tree
Hide file tree
Showing 13 changed files with 9 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.pdf;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand All @@ -30,7 +29,6 @@

public class DOMUtil {
@Nullable
@CheckReturnValue
public static Element getChild(Element parent, String name) {
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Expand All @@ -45,7 +43,6 @@ public static Element getChild(Element parent, String name) {
return null;
}

@CheckReturnValue
public static List<Element> getChildren(Element parent, String name) {
NodeList children = parent.getChildNodes();
List<Element> result = new ArrayList<>(children.getLength());
Expand All @@ -67,7 +64,6 @@ public static List<Element> getChildren(Element parent, String name) {
*
* @return a String with the text content of an element (maybe an empty string but will not be null).
*/
@CheckReturnValue
public static String getText(Element parent) {
StringBuilder sb = new StringBuilder();
getText(parent, sb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.pdf;

import com.google.errorprone.annotations.CheckReturnValue;
import com.lowagie.text.Image;
import org.jspecify.annotations.NonNull;
import org.xhtmlrenderer.extend.FSImage;
Expand All @@ -42,7 +41,6 @@ public int getHeight() {
}

@NonNull
@CheckReturnValue
@Override
public FSImage scale(int width, int height) {
if (width > 0 || height > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.pdf;

import com.google.errorprone.annotations.CheckReturnValue;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.BaseFont;
import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -110,7 +109,6 @@ public static Set<String> getDistinctFontFamilyNames(String path, String encodin
}

@Nullable
@CheckReturnValue
@Override
public FSFont resolveFont(SharedContext renderingContext, FontSpecification spec) {
return resolveFont(spec.families, spec.size, spec.fontWeight, spec.fontStyle);
Expand Down Expand Up @@ -205,7 +203,6 @@ public void addFontDirectory(String dir, String encoding, boolean embedded) thro
}
}

@CheckReturnValue
private File[] filesWithExtensions(File f, String... extensions) {
return requireNonNull(f.listFiles((d, name) -> {
String lower = name.toLowerCase(ROOT);
Expand Down Expand Up @@ -273,7 +270,6 @@ public void addFont(BaseFont font, String path, @Nullable String fontFamilyNameO
}
}

@CheckReturnValue
private static Collection<String> getFontFamilyNames(BaseFont font, @Nullable String fontFamilyNameOverride) {
if (fontFamilyNameOverride != null) {
return singletonList(fontFamilyNameOverride);
Expand Down Expand Up @@ -333,18 +329,15 @@ private void addFontFaceFont(@Nullable String fontFamilyNameOverride, @Nullable
}
}

@CheckReturnValue
private static FontDescription fontDescription(@Nullable IdentValue fontWeightOverride, @Nullable IdentValue fontStyleOverride,
String uri, byte[] ttfAfm, BaseFont font) {
return extractDescription(uri, ttfAfm, font, true, fontWeightOverride, fontStyleOverride);
}

@CheckReturnValue
private byte[] readFile(String path) throws IOException {
return IOUtil.readBytes(Paths.get(path));
}

@CheckReturnValue
private FontFamily getFontFamily(String fontFamilyName) {
FontFamily fontFamily = getFonts().get(fontFamilyName);
if (fontFamily == null) {
Expand All @@ -355,7 +348,6 @@ private FontFamily getFontFamily(String fontFamilyName) {
}

@Nullable
@CheckReturnValue
private FSFont resolveFont(String @Nullable [] families, float size, IdentValue weight, IdentValue style) {
if (!(style == IdentValue.NORMAL || style == IdentValue.OBLIQUE
|| style == IdentValue.ITALIC)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.pdf;

import com.google.errorprone.annotations.CheckReturnValue;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.CMYKColor;
Expand Down Expand Up @@ -254,7 +253,6 @@ private String createRectKey(com.lowagie.text.Rectangle rect) {
return rect.getLeft() + ":" + rect.getBottom() + ":" + rect.getRight() + ":" + rect.getTop();
}

@CheckReturnValue
private Optional<com.lowagie.text.Rectangle> checkLinkArea(RenderingContext c, Box box) {
com.lowagie.text.Rectangle targetArea = calcTotalLinkArea(c, box);
String key = createRectKey(targetArea);
Expand Down Expand Up @@ -363,7 +361,6 @@ public float getDeviceLength(float length) {
}

@Nullable
@CheckReturnValue
private PdfDestination createDestination(RenderingContext c, Box box) {
PdfDestination result = null;

Expand Down Expand Up @@ -472,7 +469,6 @@ public void translate(double tx, double ty) {
}

@Nullable
@CheckReturnValue
@Override
public Object getRenderingHint(RenderingHints.Key key) {
return null;
Expand Down Expand Up @@ -812,7 +808,6 @@ public void clip(Shape s) {
}

@Nullable
@CheckReturnValue
@Override
public Shape getClip() {
try {
Expand Down Expand Up @@ -1106,7 +1101,6 @@ public void addMetadata(String name, String value) {
* null.
*/
@Nullable
@CheckReturnValue
public String getMetadataByName(String name) {
for (Metadata m : _metadata) {
if ((m != null) && m.getName().equalsIgnoreCase(name)) {
Expand Down Expand Up @@ -1292,7 +1286,6 @@ public List<PagePosition> findPagePositionsByID(CssContext c, Pattern pattern) {
}

@Nullable
@CheckReturnValue
private PagePosition calcPDFPagePosition(CssContext c, String id, Box box) {
PageBox page = _root.getLayer().getLastPage(c, box);
if (page == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.pdf;

import com.google.errorprone.annotations.CheckReturnValue;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfWriter;
import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -167,22 +166,18 @@ public ITextRenderer(float dotsPerPoint, int dotsPerPixel, ITextOutputDevice out
}

@Nullable
@CheckReturnValue
public Document getDocument() {
return _doc;
}

@CheckReturnValue
public ITextFontResolver getFontResolver() {
return (ITextFontResolver) _sharedContext.getFontResolver();
}

@CheckReturnValue
private Document loadDocument(final String uri) {
return _sharedContext.getUac().getXMLResource(uri).getDocument();
}

@CheckReturnValue
public static ITextRenderer fromUrl(String uri) {
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(renderer.loadDocument(uri), uri);
Expand Down Expand Up @@ -239,6 +234,7 @@ private void setDocument(Document doc, @Nullable String url, NamespaceHandler ns
getFontResolver().importFontFaces(_sharedContext.getCss().getFontFaceRules(), _sharedContext.getUac());
}

@Nullable
public PDFEncryption getPDFEncryption() {
return _pdfEncryption;
}
Expand Down Expand Up @@ -504,7 +500,6 @@ private void provideMetadataToPage(PdfWriter writer, PageBox page) {
}

@Nullable
@CheckReturnValue
private String stringifyMetadata(Element element) {
Element target = getFirstChildElement(element);
if (target == null) {
Expand All @@ -529,7 +524,6 @@ private String stringifyMetadata(Element element) {
}

@Nullable
@CheckReturnValue
private static Element getFirstChildElement(Element element) {
Node n = element.getFirstChild();
while (n != null) {
Expand All @@ -547,12 +541,10 @@ private String createXPacket(String metadata) {
"\n<?xpacket end='r'?>";
}

@CheckReturnValue
public ITextOutputDevice getOutputDevice() {
return _outputDevice;
}

@CheckReturnValue
public SharedContext getSharedContext() {
return _sharedContext;
}
Expand All @@ -564,17 +556,14 @@ public void exportText(Writer writer) throws IOException {
}

@Nullable
@CheckReturnValue
public BlockBox getRootBox() {
return _root;
}

@CheckReturnValue
public float getDotsPerPoint() {
return _dotsPerPoint;
}

@CheckReturnValue
public List<PagePosition> findPagePositionsByID(Pattern pattern) {
return _outputDevice.findPagePositionsByID(newLayoutContext(), pattern);
}
Expand All @@ -597,7 +586,6 @@ public boolean isFocus(Element e) {
}

@Nullable
@CheckReturnValue
public PDFCreationListener getListener() {
return _listener;
}
Expand All @@ -607,7 +595,6 @@ public void setListener(PDFCreationListener listener) {
}

@Nullable
@CheckReturnValue
public PdfWriter getWriter() {
return _writer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.pdf;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;
import org.xhtmlrenderer.extend.FSImage;
Expand All @@ -46,7 +45,6 @@ public ITextReplacedElementFactory(ITextOutputDevice outputDevice) {
}

@Nullable
@CheckReturnValue
@Override
public ReplacedElement createReplacedElement(LayoutContext c, BlockBox box,
UserAgentCallback uac, int cssWidth, int cssHeight) {
Expand Down Expand Up @@ -145,7 +143,6 @@ public void remove(String fieldName) {
}

@Nullable
@CheckReturnValue
public List<RadioButtonFormField> getRadioButtons(String name) {
return _radioButtonsByName.get(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.pdf;

import com.google.errorprone.annotations.CheckReturnValue;
import com.lowagie.text.pdf.BaseFont;
import org.xhtmlrenderer.extend.FSGlyphVector;
import org.xhtmlrenderer.extend.FontContext;
Expand Down Expand Up @@ -49,7 +48,6 @@ public void drawString(
((ITextOutputDevice)outputDevice).drawString(string, x, y, info);
}

@CheckReturnValue
@Override
public FSFontMetrics getFSFontMetrics(FontContext context, FSFont font, String string) {
FontDescription description = ((ITextFSFont)font).getFontDescription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
package org.xhtmlrenderer.pdf;

import com.google.errorprone.annotations.CheckReturnValue;
import com.lowagie.text.BadElementException;
import com.lowagie.text.Image;
import com.lowagie.text.Rectangle;
Expand Down Expand Up @@ -58,7 +57,6 @@ int getDotsPerPixel() {
return dotsPerPixel;
}

@CheckReturnValue
@Override
public ImageResource getImageResource(String uriStr) {
String unresolvedUri = uriStr;
Expand All @@ -82,7 +80,6 @@ public ImageResource getImageResource(String uriStr) {
}
}

@CheckReturnValue
@Nullable
private ImageResource loadImageResource(String uriStr) {
if (isEmbeddedBase64Image(uriStr)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.pdf;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.NonNull;
import org.xhtmlrenderer.extend.FSImage;

Expand Down Expand Up @@ -60,7 +59,6 @@ public int getHeight() {
}

@NonNull
@CheckReturnValue
@Override
public FSImage scale(int width, int height) {
float targetWidth = width;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.pdf;

import com.google.errorprone.annotations.CheckReturnValue;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfAnnotation;
Expand Down Expand Up @@ -180,7 +179,6 @@ private int getMaxLength(Element elem)
}

@Override
@CheckReturnValue
protected String getValue(Element e) {
return e.getAttribute("value");
}
Expand Down
Loading

0 comments on commit 7ce48f5

Please sign in to comment.