Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete null annotations in API #4

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public final class DefaultRewriteContentHandler implements RewriteContentHandler
*/
@Override
@SuppressWarnings({ "PMD.ReturnEmptyCollectionRatherThanNull", "java:S1168" })
public List<Content> rewriteElement(@NotNull Element element) {
public @Nullable List<Content> rewriteElement(@NotNull Element element) {

// rewrite anchor elements
if (StringUtils.equalsIgnoreCase(element.getName(), "a")) {
Expand Down Expand Up @@ -481,7 +481,7 @@ private String decodeIfEncoded(String value) {

@Override
@SuppressWarnings({ "PMD.ReturnEmptyCollectionRatherThanNull", "java:S1168" })
public List<Content> rewriteText(@NotNull Text text) {
public @Nullable List<Content> rewriteText(@NotNull Text text) {
// nothing to do with text element
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/wcm/handler/richtext/RichText.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ public boolean isValid() {
}

/**
* @return Formatted markup as DOM elements
* @return Formatted markup as DOM elements or empty collection.
*/
public Collection<Content> getContent() {
public @Nullable Collection<Content> getContent() {
return this.content;
}

/**
* @return Formatted markup
*/
public String getMarkup() {
public @Nullable String getMarkup() {
if (!isValid()) {
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/wcm/handler/richtext/RichTextBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ public interface RichTextBuilder {
* @return Rich text builder
*/
@NotNull
RichTextBuilder textMode(TextMode textMode);
RichTextBuilder textMode(@Nullable TextMode textMode);

/**
* Set media arguments to be applied when resolving inline images.
* @param mediaArgs Media arguments
* @return Rich text builder
*/
@NotNull
RichTextBuilder mediaArgs(MediaArgs mediaArgs);
RichTextBuilder mediaArgs(@Nullable MediaArgs mediaArgs);

/**
* Set URL mode to be applied for building URLs for inline links and inline images.
* @param urlMode URL mode
* @return Rich text builder
*/
@NotNull
RichTextBuilder urlMode(UrlMode urlMode);
RichTextBuilder urlMode(@Nullable UrlMode urlMode);

/**
* Build formatted markup and return metadata object containing results.
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/wcm/handler/richtext/RichTextHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.sling.api.resource.Resource;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ProviderType;

/**
Expand All @@ -40,15 +41,15 @@ public interface RichTextHandler {
* @return Rich text builder
*/
@NotNull
RichTextBuilder get(Resource resource);
RichTextBuilder get(@Nullable Resource resource);

/**
* Build formatter text from given raw text string.
* @param text Raw text
* @return Rich text builder
*/
@NotNull
RichTextBuilder get(String text);
RichTextBuilder get(@Nullable String text);

/**
* Check if the given formatted text block is empty. A text block containing only one paragraph element and
Expand All @@ -57,6 +58,6 @@ public interface RichTextHandler {
* @param text XHTML text string (root element not needed)
* @return true if text block is empty
*/
boolean isEmpty(String text);
boolean isEmpty(@Nullable String text);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package io.wcm.handler.richtext;

import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ProviderType;

/**
Expand All @@ -46,11 +45,11 @@ private RichTextNameConstants() {
/**
* Default property for storing rich text.
*/
public static final @NotNull String PN_TEXT = "text";
public static final String PN_TEXT = "text";

/**
* Property that denotes if the text property contains rich text (true) or plain text (false).
*/
public static final @NotNull String PN_TEXT_IS_RICH = "textIsRich";
public static final String PN_TEXT_IS_RICH = "textIsRich";

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
package io.wcm.handler.richtext.impl;

import java.util.Collection;
import java.util.Collections;

import org.apache.sling.api.resource.Resource;
import org.jdom2.Content;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import io.wcm.handler.media.MediaArgs;
import io.wcm.handler.richtext.RichText;
Expand Down Expand Up @@ -64,19 +66,19 @@ final class RichTextBuilderImpl implements RichTextBuilder {
}

@Override
public @NotNull RichTextBuilder urlMode(UrlMode value) {
public @NotNull RichTextBuilder urlMode(@Nullable UrlMode value) {
this.urlMode = value;
return this;
}

@Override
public @NotNull RichTextBuilder textMode(TextMode value) {
public @NotNull RichTextBuilder textMode(@Nullable TextMode value) {
this.textMode = value;
return this;
}

@Override
public @NotNull RichTextBuilder mediaArgs(MediaArgs value) {
public @NotNull RichTextBuilder mediaArgs(@Nullable MediaArgs value) {
this.mediaArgs = value;
return this;
}
Expand All @@ -89,13 +91,17 @@ final class RichTextBuilderImpl implements RichTextBuilder {
}

@Override
public String buildMarkup() {
public @Nullable String buildMarkup() {
return build().getMarkup();
}

@Override
public @NotNull Collection<Content> buildContent() {
return build().getContent();
Collection<Content> result = build().getContent();
if (result == null) {
return Collections.emptyList();
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.jdom2.JDOMException;
import org.jdom2.Text;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -73,12 +74,12 @@ public final class RichTextHandlerImpl implements RichTextHandler {
private List<RewriteContentHandler> rewriteContentHandlers;

@Override
public @NotNull RichTextBuilder get(Resource resource) {
public @NotNull RichTextBuilder get(@Nullable Resource resource) {
return new RichTextBuilderImpl(resource, this);
}

@Override
public @NotNull RichTextBuilder get(String text) {
public @NotNull RichTextBuilder get(@Nullable String text) {
return new RichTextBuilderImpl(text, this);
}

Expand Down Expand Up @@ -165,7 +166,7 @@ private List<Content> processPlainText(String text) {
}

@Override
public boolean isEmpty(String text) {
public boolean isEmpty(@Nullable String text) {
return RichTextUtil.isEmpty(text);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wcm/handler/richtext/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
/**
* RichText Handler API.
*/
@org.osgi.annotation.versioning.Version("1.1.2")
@org.osgi.annotation.versioning.Version("1.1.3")
package io.wcm.handler.richtext;
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.sling.models.annotations.injectorspecific.RequestAttribute;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.jetbrains.annotations.Nullable;

import io.wcm.handler.richtext.RichTextHandler;
import io.wcm.handler.richtext.RichTextNameConstants;
Expand Down Expand Up @@ -76,7 +77,7 @@ public boolean isValid() {
* Returns the formatted text as XHTML markup.
* @return Text markup
*/
public String getMarkup() {
public @Nullable String getMarkup() {
return markup;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.sling.models.annotations.injectorspecific.RequestAttribute;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.jetbrains.annotations.Nullable;

import io.wcm.handler.richtext.RichTextBuilder;
import io.wcm.handler.richtext.RichTextHandler;
Expand Down Expand Up @@ -88,7 +89,7 @@ public boolean isValid() {
* Returns the formatted text as XHTML markup.
* @return Rich text markup
*/
public String getMarkup() {
public @Nullable String getMarkup() {
return markup;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wcm/handler/richtext/ui/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
/**
* Sling model classes for UI views.
*/
@org.osgi.annotation.versioning.Version("1.0.0")
@org.osgi.annotation.versioning.Version("1.0.1")
package io.wcm.handler.richtext.ui;
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static void addParsedText(@NotNull Element parent, @NotNull String text,
* @return Root element with parsed xhtml content
* @throws JDOMException Is thrown if the text could not be parsed as XHTML
*/
public static Element parseText(@NotNull String text) throws JDOMException {
public static @NotNull Element parseText(@NotNull String text) throws JDOMException {
return parseText(text, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.HashMap;
import java.util.Map;

import org.jetbrains.annotations.NotNull;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
Expand All @@ -51,7 +52,7 @@ private XHtmlEntityResolver() {
* XHtmlEntityResolver instance.
* @return XHtmlEntityResolver instance.
*/
public static XHtmlEntityResolver getInstance() {
public static @NotNull XHtmlEntityResolver getInstance() {
return INSTANCE;
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/io/wcm/handler/richtext/util/XHtmlResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package io.wcm.handler.richtext.util;

import org.jetbrains.annotations.NotNull;

/**
* Definition of XHTML resources.
*/
Expand Down Expand Up @@ -68,23 +70,23 @@ enum XHtmlResource {
* Public Id
* @return Public Id
*/
public String getPublicId() {
public @NotNull String getPublicId() {
return this.publicId;
}

/**
* System Id
* @return System Id
*/
public String getSystemId() {
public @NotNull String getSystemId() {
return this.systemId;
}

/**
* Local filename
* @return Local filename
*/
public String getFilename() {
public @NotNull String getFilename() {
return this.filename;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
/**
* Helper classes for RichText handling.
*/
@org.osgi.annotation.versioning.Version("1.0.1")
@org.osgi.annotation.versioning.Version("1.0.2")
package io.wcm.handler.richtext.util;
1 change: 1 addition & 0 deletions src/test/java/io/wcm/handler/richtext/RichTextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void testWithContent() {
assertEquals("<span>wurst</span> <div class=\"abc\"></div>", underTest.getMarkup());
}

@SuppressWarnings("null")
@Test
void testWithoutContent() {
RichText underTest = new RichText(richTextRequest, Collections.emptyList());
Expand Down