Skip to content

Commit

Permalink
add lots of nullability annotations
Browse files Browse the repository at this point in the history
(I must admit that I am not 100% all of them are correct)
  • Loading branch information
asolntsev committed Dec 29, 2023
1 parent ef2be95 commit dca1b47
Show file tree
Hide file tree
Showing 48 changed files with 359 additions and 233 deletions.
5 changes: 2 additions & 3 deletions doc/guide/users-guide-r7.xil
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,9 @@ String address = "http://www.w3.org/";

// render
try {
BufferedImage buff = null;
buff = Graphics2DRenderer.renderToImage(address, "w3c-homepage.png", 1024);
BufferedImage buff = Graphics2DRenderer.renderToImage(address, "w3c-homepage.png", 1024);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}}

Expand Down
5 changes: 2 additions & 3 deletions doc/guide/users-guide-r8.xil
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,9 @@ String address = "http://www.w3.org/";

// render
try {
BufferedImage buff = null;
buff = Graphics2DRenderer.renderToImage(address, "w3c-homepage.png", 1024);
BufferedImage buff = Graphics2DRenderer.renderToImage(address, "w3c-homepage.png", 1024);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.xhtmlrenderer.extend.UserAgentCallback;
import org.xhtmlrenderer.resource.CSSResource;
import org.xhtmlrenderer.util.Configuration;
import org.xhtmlrenderer.util.IOUtil;
import org.xhtmlrenderer.util.XRLog;
import org.xml.sax.InputSource;

Expand All @@ -41,7 +42,7 @@

/**
* A Factory class for Cascading Style Sheets. Sheets are parsed using a single
* parser instance for all sheets. Sheets are cached by URI using a LRU test,
* parser instance for all sheets. Sheets are cached by URI using LRU test,
* but timestamp of file is not checked.
*
* @author Torbjoern Gannholm
Expand Down Expand Up @@ -91,11 +92,7 @@ private Stylesheet parse(StylesheetInfo info) {
// Shouldn't happen
throw new RuntimeException(e.getMessage(), e);
} finally {
try {
is.close();
} catch (IOException e) {
// ignore
}
IOUtil.close(is);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public static void main(String[] args) throws IOException {
tokens.add(s);
}
}
// ignore

StringBuilder buf = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,23 @@
*/
package org.xhtmlrenderer.event;

import javax.annotation.ParametersAreNonnullByDefault;

/**
* Default, do-nothing implementation of a {@link DocumentListener}; implements all methods in {@link DocumentListener}
* but the methods do nothing. Subclass this class and override whichever methods you need to trap.
*/
@ParametersAreNonnullByDefault
public class DefaultDocumentListener implements DocumentListener {
/**
* {@inheritDoc}
*/
public void documentStarted() {
}

/**
* {@inheritDoc}
*/
public void documentLoaded() {
}

/**
* {@inheritDoc}
*/
public void onLayoutException(Throwable t) {
}

/**
* {@inheritDoc}
*/
public void onRenderException(Throwable t) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
*/
package org.xhtmlrenderer.event;

import javax.annotation.ParametersAreNonnullByDefault;

/**
* Implementations of this listener interface receive notifications about
* various document and layout events. Events are called on the Event Dispatch Thread, and will block
* any EDT activity until the methods return; make sure you do as little as possible in each method, or where necessary,
* spin the task off to a separate thread.
*/
@ParametersAreNonnullByDefault
public interface DocumentListener {
/**
* Indicates document has been requested (e.g. a new document is going to be
Expand All @@ -43,24 +46,23 @@ public interface DocumentListener {

/**
* Called when document layout failed with an exception. All
* <code>Throwable</code> objects thrown (except for
* <code>ThreadDeath</code>) during layout and not otherwise handled will
* be provided to this method. If a <code>DocumentListener</code> has been
* {@code Throwable} objects thrown (except for
* {@code ThreadDeath}) during layout and not otherwise handled will
* be provided to this method. If a {@code DocumentListener} has been
* defined an XHTML panel, the listener is entirely responsible for
* handling the exception. No other action will be taken.
*/
void onLayoutException(Throwable t);

/**
* Called when document render failed with an exception. All
* <code>Throwable</code> objects thrown (except for
* <code>ThreadDeath</code>) during render and not otherwise handled will
* be provided to this method. If a <code>DocumentListener</code> has been
* {@code Throwable} objects thrown (except for
* {@code ThreadDeath}) during render and not otherwise handled will
* be provided to this method. If a {@code DocumentListener} has been
* defined an XHTML panel, the listener is entirely responsible for
* handling the exception. No other action will be taken.
*/
void onRenderException(Throwable t);

}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import org.xhtmlrenderer.resource.ImageResource;
import org.xhtmlrenderer.resource.XMLResource;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;


/**
* <p>To be implemented by any user agent using the panel. "User agent" is a
Expand All @@ -47,6 +51,7 @@
*
* @author Torbjoern Gannholm
*/
@ParametersAreNonnullByDefault
public interface UserAgentCallback {
/**
* Retrieves the CSS at the given URI. This is a synchronous call.
Expand Down Expand Up @@ -76,6 +81,8 @@ public interface UserAgentCallback {
* Retrieves a binary resource located at a given URI and returns its contents
* as a byte array or <code>null</code> if the resource could not be loaded.
*/
@Nullable
@CheckReturnValue
byte[] getBinaryResource(String uri);

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

/**
* Does not need to be a correct URL, only an identifier that the
* implementation can resolve.
*
* @param url A URL against which relative references can be resolved.
*/
void setBaseURL(String url);
void setBaseURL(@Nullable String url);

/**
* @return the base uri, possibly in the implementations private uri-space
Expand All @@ -108,6 +116,8 @@ public interface UserAgentCallback {
* @param uri an absolute or relative (to baseURL) uri to be resolved.
* @return the full uri in uri-spaces known to the current implementation.
*/
String resolveURI(String uri);
@Nullable
@CheckReturnValue
String resolveURI(@Nullable String uri);
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.xhtmlrenderer.swing.SwingReplacedElementFactory;
import org.xhtmlrenderer.util.XRLog;

import javax.annotation.Nullable;
import java.awt.*;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -370,7 +371,7 @@ public String getBaseURL() {
*
* @param url The new baseURL value
*/
public void setBaseURL(String url) {
public void setBaseURL(@Nullable String url) {
uac.setBaseURL(url);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,46 @@

import org.xml.sax.InputSource;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
* @author Patrick Wright
*/
@ParametersAreNonnullByDefault
public abstract class AbstractResource implements Resource {
private InputSource inputSource;
private final InputSource inputSource;
private final long createTimeStamp;
private long elapsedLoadTime;

private AbstractResource() {
this.createTimeStamp = System.currentTimeMillis();
}

/**
* Creates a new instance of AbstractResource
*/
public AbstractResource(InputSource source) {
this();
protected AbstractResource(@Nullable InputSource source) {
this.inputSource = source;
this.createTimeStamp = System.currentTimeMillis();
}

public AbstractResource(InputStream is) {
protected AbstractResource(@Nullable InputStream is) {
this(is == null ? null : new InputSource(new BufferedInputStream(is)));
}

@Nullable
@CheckReturnValue
public InputSource getResourceInputSource() {
return this.inputSource;
}

@CheckReturnValue
public long getResourceLoadTimeStamp() {
return this.createTimeStamp;
}

@CheckReturnValue
public long getElapsedLoadTime() {
return elapsedLoadTime;
}

/*package*/
void setElapsedLoadTime(long elapsedLoadTime) {
this.elapsedLoadTime = elapsedLoadTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@
*/
package org.xhtmlrenderer.resource;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.io.InputStream;

/**
* @author Administrator
*/
@ParametersAreNonnullByDefault
public class CSSResource extends AbstractResource {

/**
* Creates a new instance of CSSResource
*/
public CSSResource(InputStream stream) {
public CSSResource(@Nullable InputStream stream) {
super(stream);
}

}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@
import org.xhtmlrenderer.swing.MutableFSImage;
import org.xml.sax.InputSource;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

/**
* @author Administrator
*/
@ParametersAreNonnullByDefault
public class ImageResource extends AbstractResource {
private final String _imageUri;
private final FSImage _img;

//HACK: at least for now, till we know what we want to do here
public ImageResource(final String uri, FSImage img) {
public ImageResource(@Nullable final String uri, @Nullable FSImage img) {
super((InputSource) null);
_imageUri = uri;
_img = img;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@

import org.xml.sax.InputSource;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

/**
*
* @author Patrick Wright
*/
@ParametersAreNonnullByDefault
public interface Resource {
@Nullable
@CheckReturnValue
InputSource getResourceInputSource();
long getResourceLoadTimeStamp();
}

/*
* $Id$
*
* $Log$
* Revision 1.1 2005/02/03 20:39:35 pdoubleya
* Added to CVS.
*
*
*/
@CheckReturnValue
long getResourceLoadTimeStamp();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.xml.sax.helpers.XMLFilterImpl;
import org.xml.sax.helpers.XMLReaderFactory;

import javax.annotation.ParametersAreNonnullByDefault;
import javax.xml.XMLConstants;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
Expand All @@ -57,6 +58,7 @@
/**
* @author Patrick Wright
*/
@ParametersAreNonnullByDefault
public class XMLResource extends AbstractResource {
private Document document;
private static final XMLResourceBuilder XML_RESOURCE_BUILDER;
Expand Down
Loading

0 comments on commit dca1b47

Please sign in to comment.