Skip to content

Commit 402c06e

Browse files
committed
add nullable/notnull annotations
1 parent 0f90474 commit 402c06e

File tree

421 files changed

+2617
-1565
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

421 files changed

+2617
-1565
lines changed

VERSION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Next
179179
compatible with Kotlin array access syntax, also handles nullability of data.
180180
* Fix: deprecate `DataKey.getFrom()`
181181
* Fix: replace all `DataHolder.get()` by `DataKey.get()`
182-
* Fix: add nullability annotations to `Node` and a few other classes
182+
* Fix: add nullability annotations to a boat load of classes.
183183
* Add: `MutableDataHolder.set(@NotNull DataKey<T>, @NotNull T)` and
184184
`MutableDataHolder.set(@NotNull NullableDataKey<T>, @Nullable T)` to respect nullability of
185185
key's data value.

flexmark-docx-converter/src/main/java/com/vladsch/flexmark/docx/converter/DocxRenderer.java

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,13 @@ public Builder() {
332332
super();
333333
}
334334

335-
public Builder(DataHolder options) {
335+
public Builder(@Nullable DataHolder options) {
336336
super(options);
337337
loadExtensions();
338338
}
339339

340340
@Override
341-
protected void removeApiPoint(Object apiPoint) {
341+
protected void removeApiPoint(@NotNull Object apiPoint) {
342342
if (apiPoint instanceof AttributeProviderFactory) this.attributeProviderFactories.remove(apiPoint);
343343
else if (apiPoint instanceof NodeDocxRendererFactory) this.nodeDocxRendererFactories.remove(apiPoint);
344344
else if (apiPoint instanceof LinkResolverFactory) this.linkResolverFactories.remove(apiPoint);
@@ -349,7 +349,7 @@ protected void removeApiPoint(Object apiPoint) {
349349
}
350350

351351
@Override
352-
protected void preloadExtension(Extension extension) {
352+
protected void preloadExtension(@NotNull Extension extension) {
353353
if (extension instanceof DocxRendererExtension) {
354354
DocxRendererExtension docxRendererExtension = (DocxRendererExtension) extension;
355355
docxRendererExtension.rendererOptions(this);
@@ -360,7 +360,7 @@ protected void preloadExtension(Extension extension) {
360360
}
361361

362362
@Override
363-
protected boolean loadExtension(Extension extension) {
363+
protected boolean loadExtension(@NotNull Extension extension) {
364364
if (extension instanceof DocxRendererExtension) {
365365
DocxRendererExtension docxRendererExtension = (DocxRendererExtension) extension;
366366
docxRendererExtension.extend(this);
@@ -408,8 +408,9 @@ public Builder nodeFormatterFactory(NodeDocxRendererFactory nodeDocxRendererFact
408408
* @param linkResolverFactory the factory for creating a node renderer
409409
* @return {@code this}
410410
*/
411+
@NotNull
411412
@Override
412-
public Builder linkResolverFactory(LinkResolverFactory linkResolverFactory) {
413+
public Builder linkResolverFactory(@NotNull LinkResolverFactory linkResolverFactory) {
413414
this.linkResolverFactories.add(linkResolverFactory);
414415
addExtensionApiPoint(linkResolverFactory);
415416
return this;
@@ -421,8 +422,9 @@ public Builder linkResolverFactory(LinkResolverFactory linkResolverFactory) {
421422
* @param attributeProviderFactory the attribute provider factory to add
422423
* @return {@code this}
423424
*/
425+
@NotNull
424426
@Override
425-
public Builder attributeProviderFactory(AttributeProviderFactory attributeProviderFactory) {
427+
public Builder attributeProviderFactory(@NotNull AttributeProviderFactory attributeProviderFactory) {
426428
this.attributeProviderFactories.add(attributeProviderFactory);
427429
addExtensionApiPoint(attributeProviderFactory);
428430
return this;
@@ -434,8 +436,9 @@ public Builder attributeProviderFactory(AttributeProviderFactory attributeProvid
434436
* @param htmlIdGeneratorFactory the factory for generating header tag id attributes
435437
* @return {@code this}
436438
*/
439+
@NotNull
437440
@Override
438-
public Builder htmlIdGeneratorFactory(HeaderIdGeneratorFactory htmlIdGeneratorFactory) {
441+
public Builder htmlIdGeneratorFactory(@NotNull HeaderIdGeneratorFactory htmlIdGeneratorFactory) {
439442
//noinspection VariableNotUsedInsideIf
440443
if (this.htmlIdGeneratorFactory != null) {
441444
throw new IllegalStateException("custom header id factory is already set to " + htmlIdGeneratorFactory.getClass().getName());
@@ -480,7 +483,7 @@ public void remove() {
480483

481484
private class MainDocxRenderer extends DocxContextImpl<Node> implements DocxRendererContext {
482485
private final Document document;
483-
private final Map<Class<?>, NodeDocxRendererHandler> renderers;
486+
private final Map<Class<?>, NodeDocxRendererHandler<?>> renderers;
484487
private final SubClassingBag<Node> collectedNodes;
485488
final HashSet<Class<?>> bookmarkWrapsChildren;
486489

@@ -504,7 +507,7 @@ private class MainDocxRenderer extends DocxContextImpl<Node> implements DocxRend
504507
this.document = document;
505508
this.renderers = new HashMap<>(32);
506509
this.renderingPhases = new HashSet<>(DocxRendererPhase.values().length);
507-
Set<Class> collectNodeTypes = new HashSet<>(100);
510+
Set<Class<?>> collectNodeTypes = new HashSet<>(100);
508511
this.phasedFormatters = new ArrayList<>(nodeFormatterFactories.size());
509512
Boolean defaultLinkResolver = DEFAULT_LINK_RESOLVER.get(options);
510513
this.myLinkResolvers = new LinkResolver[linkResolverFactories.size() + (defaultLinkResolver ? 1 : 0)];
@@ -544,7 +547,7 @@ private class MainDocxRenderer extends DocxContextImpl<Node> implements DocxRend
544547
Set<NodeDocxRendererHandler<?>> formattingHandlers = nodeDocxRenderer.getNodeFormattingHandlers();
545548
if (formattingHandlers == null) continue;
546549

547-
for (NodeDocxRendererHandler nodeType : formattingHandlers) {
550+
for (NodeDocxRendererHandler<?> nodeType : formattingHandlers) {
548551
// Overwrite existing renderer
549552
renderers.put(nodeType.getNodeType(), nodeType);
550553
}
@@ -644,8 +647,9 @@ public Node getNodeFromId(String nodeId) {
644647
return nodeIdMap.getFirst(nodeId);
645648
}
646649

650+
@NotNull
647651
@Override
648-
public String encodeUrl(CharSequence url) {
652+
public String encodeUrl(@NotNull CharSequence url) {
649653
if (rendererOptions.percentEncodeUrls) {
650654
return Escaping.percentEncodeUrl(url);
651655
} else {
@@ -654,7 +658,7 @@ public String encodeUrl(CharSequence url) {
654658
}
655659

656660
@Override
657-
public Attributes extendRenderingNodeAttributes(AttributablePart part, Attributes attributes) {
661+
public Attributes extendRenderingNodeAttributes(@NotNull AttributablePart part, @Nullable Attributes attributes) {
658662
Attributes attr = attributes != null ? attributes : new Attributes();
659663
for (AttributeProvider attributeProvider : myAttributeProviders) {
660664
attributeProvider.setAttributes(this.renderingNode, part, attr);
@@ -663,7 +667,7 @@ public Attributes extendRenderingNodeAttributes(AttributablePart part, Attribute
663667
}
664668

665669
@Override
666-
public Attributes extendRenderingNodeAttributes(Node node, AttributablePart part, Attributes attributes) {
670+
public Attributes extendRenderingNodeAttributes(@NotNull Node node, @NotNull AttributablePart part, @Nullable Attributes attributes) {
667671
Attributes attr = attributes != null ? attributes : new Attributes();
668672
for (AttributeProvider attributeProvider : myAttributeProviders) {
669673
attributeProvider.setAttributes(node, part, attr);
@@ -672,25 +676,26 @@ public Attributes extendRenderingNodeAttributes(Node node, AttributablePart part
672676
}
673677

674678
@Override
675-
public Node getCurrentNode() {
679+
public @NotNull Node getCurrentNode() {
676680
return renderingNode;
677681
}
678682

679683
@Override
680-
public Node getContextFrame() {
684+
public @NotNull Node getContextFrame() {
681685
return renderingNode;
682686
}
683687

684688
@Override
685-
public DataHolder getOptions() {
689+
public @NotNull DataHolder getOptions() {
686690
return options;
687691
}
688692

689693
@Override
690-
public DocxRendererOptions getDocxRendererOptions() {
694+
public @NotNull DocxRendererOptions getDocxRendererOptions() {
691695
return rendererOptions;
692696
}
693697

698+
@NotNull
694699
@Override
695700
public Document getDocument() {
696701
return document;
@@ -721,13 +726,15 @@ public final Iterable<? extends Node> reversedNodesOfType(Collection<Class<?>> c
721726
return collectedNodes == null ? NULL_ITERABLE : collectedNodes.reversedItemsOfType(Node.class, classes);
722727
}
723728

729+
@NotNull
724730
@Override
725-
public ResolvedLink resolveLink(LinkType linkType, CharSequence url, Boolean urlEncode) {
731+
public ResolvedLink resolveLink(@NotNull LinkType linkType, @NotNull CharSequence url, Boolean urlEncode) {
726732
return resolveLink(linkType, url, (Attributes) null, urlEncode);
727733
}
728734

735+
@NotNull
729736
@Override
730-
public ResolvedLink resolveLink(LinkType linkType, CharSequence url, Attributes attributes, Boolean urlEncode) {
737+
public ResolvedLink resolveLink(@NotNull LinkType linkType, @NotNull CharSequence url, Attributes attributes, Boolean urlEncode) {
731738
HashMap<String, ResolvedLink> resolvedLinks = resolvedLinkMap.computeIfAbsent(linkType, k -> new HashMap<>());
732739

733740
String urlSeq = String.valueOf(url);
@@ -756,14 +763,14 @@ public ResolvedLink resolveLink(LinkType linkType, CharSequence url, Attributes
756763
}
757764

758765
@Override
759-
public void render(Node node) {
766+
public void render(@NotNull Node node) {
760767
if (node instanceof Document) {
761768
htmlIdGenerator.generateIds(document);
762769

763770
// now create a map of node to id so we can validate hyperlinks
764771
new AllNodesVisitor() {
765772
@Override
766-
protected void process(Node node) {
773+
protected void process(@NotNull Node node) {
767774
String id = calculateNodeId(node);
768775
if (id != null && !id.isEmpty()) {
769776
nodeIdMap.add(node, id);
@@ -846,7 +853,7 @@ void renderChildrenUnwrapped(Node parent) {
846853
}
847854
}
848855

849-
public void renderChildren(Node parent) {
856+
public void renderChildren(@NotNull Node parent) {
850857
String id = getNodeId(parent);
851858
if (id != null && !id.isEmpty()) {
852859
if (bookmarkWrapsChildren.contains(parent.getClass())) {

flexmark-docx-converter/src/main/java/com/vladsch/flexmark/docx/converter/internal/DocxLinkResolver.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.vladsch.flexmark.util.Utils;
1313
import com.vladsch.flexmark.util.ast.Document;
1414
import com.vladsch.flexmark.util.ast.Node;
15+
import org.jetbrains.annotations.NotNull;
16+
import org.jetbrains.annotations.Nullable;
1517

1618
import java.util.Set;
1719

@@ -40,8 +42,9 @@ public DocxLinkResolver(LinkResolverContext context) {
4042
prefixWwwLinks = DocxRenderer.PREFIX_WWW_LINKS.get(context.getOptions());
4143
}
4244

45+
@NotNull
4346
@Override
44-
public ResolvedLink resolveLink(Node node, LinkResolverContext context, ResolvedLink link) {
47+
public ResolvedLink resolveLink(@NotNull Node node, @NotNull LinkResolverContext context, @NotNull ResolvedLink link) {
4548
Document document = node.getDocument();
4649

4750
if (node instanceof Image || node instanceof Link || node instanceof Reference) {
@@ -131,13 +134,15 @@ public ResolvedLink resolveLink(Node node, LinkResolverContext context, Resolved
131134
}
132135

133136
public static class Factory implements LinkResolverFactory {
137+
@Nullable
134138
@Override
135-
public Set<Class<? extends LinkResolverFactory>> getAfterDependents() {
139+
public Set<Class<?>> getAfterDependents() {
136140
return null;
137141
}
138142

143+
@Nullable
139144
@Override
140-
public Set<Class<? extends LinkResolverFactory>> getBeforeDependents() {
145+
public Set<Class<?>> getBeforeDependents() {
141146
return null;
142147
}
143148

@@ -146,8 +151,9 @@ public boolean affectsGlobalScope() {
146151
return false;
147152
}
148153

154+
@NotNull
149155
@Override
150-
public LinkResolver apply(LinkResolverContext context) {
156+
public LinkResolver apply(@NotNull LinkResolverContext context) {
151157
return new DocxLinkResolver(context);
152158
}
153159
}

flexmark-ext-abbreviation/src/main/java/com/vladsch/flexmark/ext/abbreviation/Abbreviation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ public BasedSequence[] getSegments() {
2727
}
2828

2929
@Override
30-
public void getAstExtra(StringBuilder out) {
30+
public void getAstExtra(@NotNull StringBuilder out) {
3131
astExtraChars(out);
3232
}
3333

34+
@NotNull
3435
@Override
3536
protected String toStringAttributes() {
3637
return "text=" + getChars();
@@ -41,6 +42,7 @@ public boolean isDefined() {
4142
return true;
4243
}
4344

45+
@NotNull
4446
@Override
4547
public BasedSequence getReference() {
4648
return abbreviation;

flexmark-ext-abbreviation/src/main/java/com/vladsch/flexmark/ext/abbreviation/AbbreviationBlock.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.vladsch.flexmark.util.ast.ReferenceNode;
77
import com.vladsch.flexmark.util.sequence.BasedSequence;
88
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
910

1011
/**
1112
* A block node that contains the abbreviation definition
@@ -16,8 +17,9 @@ public class AbbreviationBlock extends Block implements ReferenceNode<Abbreviati
1617
protected BasedSequence closingMarker = BasedSequence.NULL;
1718
protected BasedSequence abbreviation = BasedSequence.NULL;
1819

20+
@Nullable
1921
@Override
20-
public Abbreviation getReferencingNode(Node node) {
22+
public Abbreviation getReferencingNode(@NotNull Node node) {
2123
return node instanceof Abbreviation ? (Abbreviation) node : null;
2224
}
2325

@@ -27,7 +29,7 @@ public int compareTo(AbbreviationBlock o) {
2729
}
2830

2931
@Override
30-
public void getAstExtra(StringBuilder out) {
32+
public void getAstExtra(@NotNull StringBuilder out) {
3133
segmentSpan(out, openingMarker, "open");
3234
segmentSpan(out, text, "text");
3335
segmentSpan(out, closingMarker, "close");

flexmark-ext-abbreviation/src/main/java/com/vladsch/flexmark/ext/abbreviation/AbbreviationExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void extend(Parser.Builder parserBuilder) {
8181
}
8282

8383
@Override
84-
public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) {
84+
public void extend(@NotNull HtmlRenderer.Builder rendererBuilder, @NotNull String rendererType) {
8585
if (rendererBuilder.isRendererType("HTML")) {
8686
rendererBuilder.nodeRendererFactory(new AbbreviationNodeRenderer.Factory());
8787
} else if (rendererBuilder.isRendererType("JIRA")) {

flexmark-ext-abbreviation/src/main/java/com/vladsch/flexmark/ext/abbreviation/internal/AbbreviationBlockParser.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.vladsch.flexmark.util.data.DataKey;
1010
import com.vladsch.flexmark.util.data.DataKeyBase;
1111
import com.vladsch.flexmark.util.sequence.BasedSequence;
12+
import org.jetbrains.annotations.NotNull;
13+
import org.jetbrains.annotations.Nullable;
1214

1315
import java.util.Set;
1416
import java.util.regex.Matcher;
@@ -52,13 +54,15 @@ public boolean isContainer() {
5254
}
5355

5456
public static class Factory implements CustomBlockParserFactory {
57+
@Nullable
5558
@Override
56-
public Set<Class<? extends CustomBlockParserFactory>> getAfterDependents() {
59+
public Set<Class<?>> getAfterDependents() {
5760
return null;
5861
}
5962

63+
@Nullable
6064
@Override
61-
public Set<Class<? extends CustomBlockParserFactory>> getBeforeDependents() {
65+
public Set<Class<?>> getBeforeDependents() {
6266
return null;
6367
}
6468

@@ -67,8 +71,9 @@ public boolean affectsGlobalScope() {
6771
return false;
6872
}
6973

74+
@NotNull
7075
@Override
71-
public BlockParserFactory apply(DataHolder options) {
76+
public BlockParserFactory apply(@NotNull DataHolder options) {
7277
return new BlockFactory(options);
7378
}
7479
}

flexmark-ext-abbreviation/src/main/java/com/vladsch/flexmark/ext/abbreviation/internal/AbbreviationNodeFormatter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.vladsch.flexmark.util.data.DataKey;
1010
import com.vladsch.flexmark.util.format.options.ElementPlacement;
1111
import com.vladsch.flexmark.util.format.options.ElementPlacementSort;
12+
import org.jetbrains.annotations.NotNull;
13+
import org.jetbrains.annotations.Nullable;
1214

1315
import java.util.*;
1416

@@ -69,6 +71,7 @@ public void renderReferenceBlock(AbbreviationBlock node, NodeFormatterContext co
6971
markdown.appendTranslating(node.getAbbreviation()).line();
7072
}
7173

74+
@Nullable
7275
@Override
7376
public Set<NodeFormattingHandler<?>> getNodeFormattingHandlers() {
7477
return new HashSet<>(Arrays.asList(
@@ -77,6 +80,7 @@ public Set<NodeFormattingHandler<?>> getNodeFormattingHandlers() {
7780
));
7881
}
7982

83+
@Nullable
8084
@Override
8185
public Set<Class<?>> getNodeClasses() {
8286
if (options.abbreviationsPlacement != ElementPlacement.AS_IS && options.abbreviationsSort != ElementPlacementSort.SORT_UNUSED_LAST) return null;
@@ -100,8 +104,9 @@ private void render(Abbreviation node, NodeFormatterContext context, MarkdownWri
100104
}
101105

102106
public static class Factory implements NodeFormatterFactory {
107+
@NotNull
103108
@Override
104-
public NodeFormatter create(DataHolder options) {
109+
public NodeFormatter create(@NotNull DataHolder options) {
105110
return new AbbreviationNodeFormatter(options);
106111
}
107112
}

0 commit comments

Comments
 (0)