Skip to content

Commit

Permalink
#442 annotate all methods in package org.xhtmlrenderer.extend with …
Browse files Browse the repository at this point in the history
…@CheckReturnValue
  • Loading branch information
asolntsev committed Nov 12, 2024
1 parent c29c8ae commit cf54bb3
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
*/
package org.xhtmlrenderer.extend;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.Nullable;
import org.xhtmlrenderer.css.value.FontSpecification;
import org.xhtmlrenderer.layout.SharedContext;
import org.xhtmlrenderer.render.FSFont;

public interface FontResolver {
@Nullable
@CheckReturnValue
FSFont resolveFont(SharedContext renderingContext, FontSpecification spec);
void flushCache();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.extend;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand All @@ -36,70 +35,56 @@
*/
public interface NamespaceHandler {

@CheckReturnValue
String getNamespace();

@CheckReturnValue
Optional<StylesheetInfo> getDefaultStylesheet();

@Nullable
@CheckReturnValue
String getDocumentTitle(Document doc);

/**
* @param doc the document
* @return all links to CSS stylesheets (type="text/css") in this document
*/
@CheckReturnValue
List<StylesheetInfo> getStylesheets(Document doc);

/**
* may return null. Required to return null if attribute does not exist and
* not null if attribute exists.
*/
@CheckReturnValue
String getAttributeValue(Element e, String attrName);

@CheckReturnValue
String getAttributeValue(Element e, @Nullable String namespaceURI, String attrName);

@Nullable
@CheckReturnValue
String getClass(Element e);

@Nullable
@CheckReturnValue
String getID(Element e);

@Nullable
@CheckReturnValue
String getElementStyling(Element e);

/**
* @return The corresponding css properties for styling that is obtained in other ways.
*/
@Nullable
@CheckReturnValue
String getNonCssStyling(Element e);

@CheckReturnValue
String getLang(Element e);

/**
* should return null if element is not a link
*/
@Nullable
@CheckReturnValue
String getLinkUri(Element e);

@Nullable
@CheckReturnValue
String getAnchorName(@Nullable Element e);

/**
* @return Returns true if the Element represents an image.
*/
@CheckReturnValue
boolean isImageElement(Element e);

/**
Expand All @@ -109,7 +94,6 @@ public interface NamespaceHandler {
* @param e The Element to evaluate.
* @return true if the Element is a &lt;form&gt; element, false otherwise.
*/
@CheckReturnValue
boolean isFormElement(Element e);

/**
Expand All @@ -123,7 +107,6 @@ public interface NamespaceHandler {
* @return String containing the URI for the image.
*/
@Nullable
@CheckReturnValue
String getImageSourceURI(Element e);
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.extend;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.Nullable;
import org.xhtmlrenderer.css.parser.FSColor;
import org.xhtmlrenderer.css.style.CalculatedStyle;
Expand Down Expand Up @@ -86,7 +85,6 @@ void paintBackground(
Stroke getStroke();

@Nullable
@CheckReturnValue
Object getRenderingHint(RenderingHints.Key key);

void setRenderingHint(RenderingHints.Key key, Object value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.extend;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;
import org.xhtmlrenderer.layout.LayoutContext;
Expand All @@ -39,7 +38,6 @@ public interface ReplacedElementFactory {
* {@code ReplacedElement} applies
*/
@Nullable
@CheckReturnValue
ReplacedElement createReplacedElement(
LayoutContext c, BlockBox box,
UserAgentCallback uac, int cssWidth, int cssHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
package org.xhtmlrenderer.extend;

import com.google.errorprone.annotations.CheckReturnValue;
import org.xhtmlrenderer.render.FSFont;
import org.xhtmlrenderer.render.FSFontMetrics;
import org.xhtmlrenderer.render.JustificationInfo;
Expand All @@ -41,7 +40,6 @@ void drawString(
float[] getGlyphPositions(OutputDevice outputDevice, FSFont font, FSGlyphVector fsGlyphVector);
Rectangle getGlyphBounds(OutputDevice outputDevice, FSFont font, FSGlyphVector fsGlyphVector, int index, float x, float y);

@CheckReturnValue
FSFontMetrics getFSFontMetrics(
FontContext context, FSFont font, String string);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xhtmlrenderer.extend;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.Nullable;
import org.xhtmlrenderer.resource.CSSResource;
import org.xhtmlrenderer.resource.ImageResource;
Expand Down Expand Up @@ -63,7 +62,6 @@ public interface UserAgentCallback {
* @param uri Location of the image
* @return An ImageResource for the content at the URI.
*/
@CheckReturnValue
ImageResource getImageResource(String uri);

/**
Expand All @@ -72,15 +70,13 @@ public interface UserAgentCallback {
* @param uri Location of the XML
* @return A XMLResource for the content at the URI.
*/
@CheckReturnValue
@Nullable
XMLResource getXMLResource(String uri);

/**
* Retrieves a binary resource located at a given URI and returns its contents
* as a byte array or {@code null} if the resource could not be loaded.
*/
@CheckReturnValue
byte @Nullable [] getBinaryResource(String uri);

/**
Expand All @@ -90,7 +86,6 @@ public interface UserAgentCallback {
* @param uri A URI which may have been visited by this user agent.
* @return The visited value
*/
@CheckReturnValue
boolean isVisited(@Nullable String uri);

/**
Expand All @@ -104,7 +99,6 @@ public interface UserAgentCallback {
/**
* @return the base uri, possibly in the implementations private uri-space
*/
@CheckReturnValue
@Nullable
String getBaseURL();

Expand All @@ -117,7 +111,6 @@ public interface UserAgentCallback {
* @return the full uri in uri-spaces known to the current implementation.
*/
@Nullable
@CheckReturnValue
String resolveURI(@Nullable String uri);
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@NullMarked
@CheckReturnValue
package org.xhtmlrenderer.extend;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.xhtmlrenderer.swing;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.xhtmlrenderer.extend.FSImage;
import org.xhtmlrenderer.util.ImageUtil;
Expand Down Expand Up @@ -70,6 +71,8 @@ public BufferedImage getImage() {
return img;
}

@NonNull
@CheckReturnValue
@Override
public FSImage scale(int width, int height) {
if (width > 0 || height > 0) {
Expand Down Expand Up @@ -107,6 +110,8 @@ public int getHeight() {
return 0;
}

@NonNull
@CheckReturnValue
@Override
public FSImage scale(int width, int height) {
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.xhtmlrenderer.swing;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.Nullable;
import org.xhtmlrenderer.extend.FSImage;
import org.xhtmlrenderer.resource.ImageResource;
Expand Down Expand Up @@ -109,17 +110,17 @@ public synchronized void clear() {
_imageCache.clear();
}

@CheckReturnValue
public ImageResource get(final String uri) {
return get(uri, -1, -1);
}

@CheckReturnValue
public synchronized ImageResource get(final String uri, final int width, final int height) {
if (isEmbeddedBase64Image(uri)) {
ImageResource resource = loadEmbeddedBase64ImageResource(uri);
FSImage scaledImage = resource.getImage();
if (scaledImage != null) {
scaledImage = scaledImage.scale(width, height);
}
FSImage image = resource.getImage();
FSImage scaledImage = image == null ? null : image.scale(width, height);
return new ImageResource(resource.getImageUri(), scaledImage);
} else {
CacheKey key = new CacheKey(uri, width, height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.xhtmlrenderer.swing;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.NonNull;
import org.xhtmlrenderer.extend.FSImage;
import org.xhtmlrenderer.util.ImageUtil;
import org.xhtmlrenderer.util.XRLog;
Expand Down Expand Up @@ -59,6 +61,8 @@ public synchronized int getHeight() {
return img.getHeight(null);
}

@NonNull
@CheckReturnValue
@Override
public synchronized FSImage scale(int width, int height) {
img.getScaledInstance(width, height, Image.SCALE_DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
*/
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;

public class ITextFSImage implements FSImage, Cloneable {
Expand All @@ -39,6 +41,8 @@ public int getHeight() {
return (int)_image.getPlainHeight();
}

@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,6 +19,8 @@
*/
package org.xhtmlrenderer.pdf;

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

import java.net.URI;
Expand Down Expand Up @@ -57,6 +59,8 @@ public int getHeight() {
return (int)_height;
}

@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,8 +19,10 @@
*/
package org.xhtmlrenderer.swt;

import com.google.errorprone.annotations.CheckReturnValue;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.xhtmlrenderer.extend.FSImage;
import org.xhtmlrenderer.extend.UserAgentCallback;
Expand Down Expand Up @@ -110,6 +112,8 @@ public void setWidth(int width) {
_width = width;
}

@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 @@ -27,6 +27,8 @@
import org.eclipse.swt.graphics.Path;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Transform;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.NullUnmarked;
import org.jspecify.annotations.Nullable;
import org.xhtmlrenderer.css.parser.FSColor;
Expand Down Expand Up @@ -340,7 +342,7 @@ public void translate(double tx, double ty) {
@Nullable
@CheckReturnValue
@Override
public Object getRenderingHint(RenderingHints.Key key) {
public Object getRenderingHint(RenderingHints.@NonNull Key key) {
if (RenderingHints.KEY_ANTIALIASING.equals(key)) {
switch (_gc.getAntialias()) {
case SWT.DEFAULT:
Expand All @@ -354,6 +356,7 @@ public Object getRenderingHint(RenderingHints.Key key) {
return null;
}

@NullMarked
@Override
public void setRenderingHint(RenderingHints.Key key, Object value) {
if (RenderingHints.KEY_ANTIALIASING.equals(key)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@NullMarked
@CheckReturnValue
package org.xhtmlrenderer.swt.simple;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.NullMarked;

0 comments on commit cf54bb3

Please sign in to comment.