Skip to content
This repository has been archived by the owner on Jan 11, 2022. It is now read-only.

Commit

Permalink
Add Jetbrains NotNull/Nullable annotations to API.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Aug 14, 2018
1 parent 8bad8db commit 1b38e4c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 14 deletions.
6 changes: 6 additions & 0 deletions ui/granite/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="1.1.6" date="not released">
<action type="update" dev="sseifert">
Add Jetbrains NotNull/Nullable annotations to API.
</action>
</release>

<release version="1.1.4" date="2018-05-26">
<action type="update" dev="sseifert">
Set javax.inject dependency to provided.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void activate(Config config) {
}
}

@SuppressWarnings("null")
@Override
public boolean handles(Resource resource) {
// check if resource is a page, and if the page uses a configured template
Expand Down Expand Up @@ -109,6 +110,7 @@ public List<Emulator> getEmulators(Resource resource) {
return emulators;
}

@SuppressWarnings({ "null", "unused" })
@Override
public List<EmulatorGroup> getEmulatorGroups(Resource resource) {
// convert device groups defined in page props to emulator groups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.sling.api.resource.SyntheticResource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.jetbrains.annotations.NotNull;

import com.day.cq.commons.jcr.JcrConstants;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -111,7 +112,8 @@ private void addChild(Resource child) {
* @param valueMap Properties
* @return Resource
*/
public static Resource create(ResourceResolver resourceResolver, ValueMap valueMap) {
@SuppressWarnings("null")
public static Resource create(@NotNull ResourceResolver resourceResolver, @NotNull ValueMap valueMap) {
return create(resourceResolver, null, JcrConstants.NT_UNSTRUCTURED, valueMap);
}

Expand All @@ -122,7 +124,8 @@ public static Resource create(ResourceResolver resourceResolver, ValueMap valueM
* @param resourceType Resource type
* @return Resource
*/
public static Resource create(ResourceResolver resourceResolver, String path, String resourceType) {
@SuppressWarnings("null")
public static Resource create(@NotNull ResourceResolver resourceResolver, @NotNull String path, @NotNull String resourceType) {
return create(resourceResolver, path, resourceType, ValueMap.EMPTY);
}

Expand All @@ -134,7 +137,8 @@ public static Resource create(ResourceResolver resourceResolver, String path, St
* @param valueMap Properties
* @return Resource
*/
public static Resource create(ResourceResolver resourceResolver, String path, String resourceType, ValueMap valueMap) {
public static Resource create(@NotNull ResourceResolver resourceResolver, @NotNull String path, @NotNull String resourceType,
@NotNull ValueMap valueMap) {
return new GraniteUiSyntheticResource(resourceResolver,
path,
resourceType,
Expand All @@ -147,7 +151,7 @@ public static Resource create(ResourceResolver resourceResolver, String path, St
* @param resource Real resource
* @return Resource
*/
public static Resource wrap(Resource resource) {
public static Resource wrap(@NotNull Resource resource) {
return wrap(resource, resource.getValueMap(), resource.getChildren());
}

Expand All @@ -157,7 +161,7 @@ public static Resource wrap(Resource resource) {
* @param valueMap Properties to use instead of the real properties
* @return Resource
*/
public static Resource wrap(Resource resource, ValueMap valueMap) {
public static Resource wrap(@NotNull Resource resource, @NotNull ValueMap valueMap) {
return wrap(resource, valueMap, resource.getChildren());
}

Expand All @@ -168,7 +172,7 @@ public static Resource wrap(Resource resource, ValueMap valueMap) {
* @param valueMap Properties to be merged with the real properties
* @return Resource
*/
public static Resource wrapMerge(Resource resource, ValueMap valueMap) {
public static Resource wrapMerge(@NotNull Resource resource, @NotNull ValueMap valueMap) {
Map<String, Object> mergedProperties = new HashMap<>();
mergedProperties.putAll(resource.getValueMap());
mergedProperties.putAll(valueMap);
Expand All @@ -190,7 +194,8 @@ private static Resource wrap(Resource resource, ValueMap valueMap, Iterable<Reso
* @param resourceType Resource type
* @return Resource
*/
public static Resource child(Resource parentResource, String name, String resourceType) {
@SuppressWarnings("null")
public static Resource child(@NotNull Resource parentResource, @NotNull String name, @NotNull String resourceType) {
return child(parentResource, name, resourceType, ValueMap.EMPTY);
}

Expand All @@ -202,7 +207,8 @@ public static Resource child(Resource parentResource, String name, String resour
* @param valueMap Properties
* @return Resource
*/
public static Resource child(Resource parentResource, String name, String resourceType, ValueMap valueMap) {
public static Resource child(@NotNull Resource parentResource, @NotNull String name, @NotNull String resourceType,
@NotNull ValueMap valueMap) {
Resource child = new GraniteUiSyntheticResource(parentResource.getResourceResolver(),
parentResource.getPath() + "/" + name,
resourceType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
/**
* Helper for building virtual resource trees for Granite UI components.
*/
@org.osgi.annotation.versioning.Version("1.0.0")
@org.osgi.annotation.versioning.Version("1.0.1")
package io.wcm.wcm.ui.granite.resource;
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.adobe.granite.ui.components.Value;
import com.day.cq.wcm.api.Page;
Expand All @@ -45,7 +47,7 @@ private GraniteUi() {
* @param request Request
* @return Current content resource or null
*/
public static Resource getContentResource(HttpServletRequest request) {
public static @Nullable Resource getContentResource(@NotNull HttpServletRequest request) {

String contentPath = getContentPath(request);

Expand All @@ -62,7 +64,7 @@ public static Resource getContentResource(HttpServletRequest request) {
* @param request Request
* @return Current content resource or the first existing parent/ancestor.
*/
public static Resource getContentResourceOrParent(HttpServletRequest request) {
public static @Nullable Resource getContentResourceOrParent(@NotNull HttpServletRequest request) {
String contentPath = getContentPath(request);
return getContentResourceOrParentFromPath((SlingHttpServletRequest)request, contentPath);
}
Expand All @@ -73,7 +75,7 @@ public static Resource getContentResourceOrParent(HttpServletRequest request) {
* @param request Request
* @return Current content page or null
*/
public static Page getContentPage(HttpServletRequest request) {
public static @Nullable Page getContentPage(@NotNull HttpServletRequest request) {
SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request;
Resource contentResource = getContentResourceOrParent(request);
if (contentResource != null) {
Expand All @@ -91,7 +93,7 @@ public static Page getContentPage(HttpServletRequest request) {
* @param resourceTypes ResourceTypes
* @return Existing resource type
*/
public static String getExistingResourceType(ResourceResolver resourceResolver, String... resourceTypes) {
public static @Nullable String getExistingResourceType(@NotNull ResourceResolver resourceResolver, @NotNull String @NotNull... resourceTypes) {
for (String path : resourceTypes) {
if (resourceResolver.getResource(path) != null) {
return path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
/**
* Helper methods for Granite UI components.
*/
@org.osgi.annotation.versioning.Version("1.1.0")
@org.osgi.annotation.versioning.Version("1.1.1")
package io.wcm.wcm.ui.granite.util;
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

@SuppressWarnings("null")
public class GraniteUiSyntheticResourceTest {

private static final ValueMap SAMPLE_PROPERTES = new ValueMapDecorator(ImmutableMap.<String, Object>builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.day.cq.wcm.api.PageManager;

@RunWith(MockitoJUnitRunner.class)
@SuppressWarnings("null")
public class GraniteUiTest {

private static final String CONTENT_PATH = "/my/path";
Expand Down

0 comments on commit 1b38e4c

Please sign in to comment.