Add even more null annotations (#2752)

This PR adds even more missing null annotations which did not fit in #2742 as it grew too big.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2022-02-17 21:30:51 +01:00
committed by GitHub
parent 9bf181bf0a
commit 92917946d4
74 changed files with 439 additions and 295 deletions
@@ -12,6 +12,8 @@
*/
package org.openhab.core.automation.events;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.dto.RuleDTO;
import org.openhab.core.events.AbstractEvent;
@@ -21,6 +23,7 @@ import org.openhab.core.events.AbstractEvent;
* @author Benedikt Niehues - Initial contribution
* @author Markus Rathgeb - Use the DTO for the Rule representation
*/
@NonNullByDefault
public abstract class AbstractRuleRegistryEvent extends AbstractEvent {
private final RuleDTO rule;
@@ -33,7 +36,7 @@ public abstract class AbstractRuleRegistryEvent extends AbstractEvent {
* @param source the source of the event
* @param ruleDTO the ruleDTO for which this event is created
*/
public AbstractRuleRegistryEvent(String topic, String payload, String source, RuleDTO rule) {
public AbstractRuleRegistryEvent(String topic, String payload, @Nullable String source, RuleDTO rule) {
super(topic, payload, source);
this.rule = rule;
}
@@ -12,6 +12,8 @@
*/
package org.openhab.core.automation.events;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.dto.RuleDTO;
/**
@@ -19,6 +21,7 @@ import org.openhab.core.automation.dto.RuleDTO;
*
* @author Benedikt Niehues - Initial contribution
*/
@NonNullByDefault
public class RuleAddedEvent extends AbstractRuleRegistryEvent {
public static final String TYPE = RuleAddedEvent.class.getSimpleName();
@@ -31,7 +34,7 @@ public class RuleAddedEvent extends AbstractRuleRegistryEvent {
* @param source the source of the event
* @param ruleDTO the rule for which this event is created
*/
public RuleAddedEvent(String topic, String payload, String source, RuleDTO rule) {
public RuleAddedEvent(String topic, String payload, @Nullable String source, RuleDTO rule) {
super(topic, payload, source, rule);
}
@@ -12,6 +12,8 @@
*/
package org.openhab.core.automation.events;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.dto.RuleDTO;
/**
@@ -19,6 +21,7 @@ import org.openhab.core.automation.dto.RuleDTO;
*
* @author Benedikt Niehues - Initial contribution
*/
@NonNullByDefault
public class RuleRemovedEvent extends AbstractRuleRegistryEvent {
public static final String TYPE = RuleRemovedEvent.class.getSimpleName();
@@ -31,7 +34,7 @@ public class RuleRemovedEvent extends AbstractRuleRegistryEvent {
* @param source the source of the event
* @param rule the rule for which this event is
*/
public RuleRemovedEvent(String topic, String payload, String source, RuleDTO rule) {
public RuleRemovedEvent(String topic, String payload, @Nullable String source, RuleDTO rule) {
super(topic, payload, source, rule);
}
@@ -12,6 +12,8 @@
*/
package org.openhab.core.automation.events;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.RuleStatusInfo;
import org.openhab.core.events.AbstractEvent;
@@ -21,6 +23,7 @@ import org.openhab.core.events.AbstractEvent;
* @author Benedikt Niehues - Initial contribution
* @author Kai Kreuzer - added toString method
*/
@NonNullByDefault
public class RuleStatusInfoEvent extends AbstractEvent {
public static final String TYPE = RuleStatusInfoEvent.class.getSimpleName();
@@ -37,7 +40,8 @@ public class RuleStatusInfoEvent extends AbstractEvent {
* @param statusInfo the status info for this event
* @param ruleId the rule for which this event is
*/
public RuleStatusInfoEvent(String topic, String payload, String source, RuleStatusInfo statusInfo, String ruleId) {
public RuleStatusInfoEvent(String topic, String payload, @Nullable String source, RuleStatusInfo statusInfo,
String ruleId) {
super(topic, payload, source);
this.statusInfo = statusInfo;
this.ruleId = ruleId;
@@ -12,6 +12,8 @@
*/
package org.openhab.core.automation.events;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.dto.RuleDTO;
/**
@@ -19,6 +21,7 @@ import org.openhab.core.automation.dto.RuleDTO;
*
* @author Benedikt Niehues - Initial contribution
*/
@NonNullByDefault
public class RuleUpdatedEvent extends AbstractRuleRegistryEvent {
public static final String TYPE = RuleUpdatedEvent.class.getSimpleName();
@@ -34,7 +37,7 @@ public class RuleUpdatedEvent extends AbstractRuleRegistryEvent {
* @param rule the rule for which is this event
* @param oldRule the rule that has been updated
*/
public RuleUpdatedEvent(String topic, String payload, String source, RuleDTO rule, RuleDTO oldRule) {
public RuleUpdatedEvent(String topic, String payload, @Nullable String source, RuleDTO rule, RuleDTO oldRule) {
super(topic, payload, source, rule);
this.oldRule = oldRule;
}
@@ -17,6 +17,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.Rule;
import org.openhab.core.automation.RuleStatusInfo;
import org.openhab.core.automation.dto.RuleDTO;
@@ -38,6 +40,7 @@ import org.slf4j.LoggerFactory;
* @author Benedikt Niehues - Initial contribution
* @author Markus Rathgeb - Use the DTO for the Rule representation
*/
@NonNullByDefault
@Component(service = EventFactory.class, immediate = true)
public class RuleEventFactory extends AbstractEventFactory {
@@ -65,7 +68,8 @@ public class RuleEventFactory extends AbstractEventFactory {
}
@Override
protected Event createEventByType(String eventType, String topic, String payload, String source) throws Exception {
protected Event createEventByType(String eventType, String topic, String payload, @Nullable String source)
throws Exception {
logger.trace("creating ruleEvent of type: {}", eventType);
if (RuleAddedEvent.TYPE.equals(eventType)) {
return createRuleAddedEvent(topic, payload, source);
@@ -79,7 +83,7 @@ public class RuleEventFactory extends AbstractEventFactory {
throw new IllegalArgumentException("The event type '" + eventType + "' is not supported by this factory.");
}
private Event createRuleUpdatedEvent(String topic, String payload, String source) {
private Event createRuleUpdatedEvent(String topic, String payload, @Nullable String source) {
RuleDTO[] ruleDTO = deserializePayload(payload, RuleDTO[].class);
if (ruleDTO.length != 2) {
throw new IllegalArgumentException("Creation of RuleUpdatedEvent failed: invalid payload: " + payload);
@@ -87,17 +91,17 @@ public class RuleEventFactory extends AbstractEventFactory {
return new RuleUpdatedEvent(topic, payload, source, ruleDTO[0], ruleDTO[1]);
}
private Event createRuleStatusInfoEvent(String topic, String payload, String source) {
private Event createRuleStatusInfoEvent(String topic, String payload, @Nullable String source) {
RuleStatusInfo statusInfo = deserializePayload(payload, RuleStatusInfo.class);
return new RuleStatusInfoEvent(topic, payload, source, statusInfo, getRuleId(topic));
}
private Event createRuleRemovedEvent(String topic, String payload, String source) {
private Event createRuleRemovedEvent(String topic, String payload, @Nullable String source) {
RuleDTO ruleDTO = deserializePayload(payload, RuleDTO.class);
return new RuleRemovedEvent(topic, payload, source, ruleDTO);
}
private Event createRuleAddedEvent(String topic, String payload, String source) {
private Event createRuleAddedEvent(String topic, String payload, @Nullable String source) {
RuleDTO ruleDTO = deserializePayload(payload, RuleDTO.class);
return new RuleAddedEvent(topic, payload, source, ruleDTO);
}
@@ -12,11 +12,14 @@
*/
package org.openhab.core.automation.internal.module.exception;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* This Exception is used as an indicator for not matching types during comparation
*
* @author Benedikt Niehues - Initial contribution
*/
@NonNullByDefault
public class UncomparableException extends Exception {
private static final long serialVersionUID = 4891205711357448390L;
@@ -12,11 +12,14 @@
*/
package org.openhab.core.automation.module.provider;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* Type to distinguish annotated ActionModules
*
* @author Stefan Triller - Initial contribution
*/
@NonNullByDefault
public enum ActionModuleKind {
SINGLE,
SERVICE,
@@ -12,9 +12,11 @@
*/
package org.openhab.core.automation.parser;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* This class extends the {@link Exception} class functionality with functionality serving to accumulate the all
* exceptions during the parsing process.
@@ -22,12 +24,13 @@ import java.util.List;
* @author Ana Dimova - Initial contribution
*/
@SuppressWarnings("serial")
@NonNullByDefault
public class ParsingException extends Exception {
/**
* Keeps all accumulated exceptions.
*/
List<ParsingNestedException> exceptions;
private List<ParsingNestedException> exceptions;
/**
* Creates the holder for one exception during the parsing process.
@@ -35,8 +38,7 @@ public class ParsingException extends Exception {
* @param e is an exception during the parsing process.
*/
public ParsingException(ParsingNestedException e) {
exceptions = new ArrayList<>();
exceptions.add(e);
exceptions = List.of(e);
}
/**
@@ -49,7 +51,7 @@ public class ParsingException extends Exception {
}
@Override
public String getMessage() {
public @Nullable String getMessage() {
StringBuilder writer = new StringBuilder();
for (ParsingNestedException e : exceptions) {
writer.append(e.getMessage() + "\n");
@@ -12,6 +12,9 @@
*/
package org.openhab.core.automation.parser;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* This class extends the {@link Exception} class functionality with keeping additional information about reasons for
* exception during the parsing process.
@@ -19,6 +22,7 @@ package org.openhab.core.automation.parser;
* @author Ana Dimova - Initial contribution
*/
@SuppressWarnings("serial")
@NonNullByDefault
public class ParsingNestedException extends Exception {
public static final int MODULE_TYPE = 1;
@@ -28,7 +32,7 @@ public class ParsingNestedException extends Exception {
/**
* Keeps information about the UID of the automation object for parsing - module type, template or rule.
*/
private final String id;
private final @Nullable String id;
/**
* Keeps information about the type of the automation object for parsing - module type, template or rule.
@@ -44,7 +48,7 @@ public class ParsingNestedException extends Exception {
* @param msg is the additional message with additional information about the parsing process.
* @param t is the exception thrown during the parsing.
*/
public ParsingNestedException(int type, String id, String msg, Throwable t) {
public ParsingNestedException(int type, @Nullable String id, String msg, Throwable t) {
super(msg, t);
this.id = id;
this.type = type;
@@ -58,14 +62,14 @@ public class ParsingNestedException extends Exception {
* @param id is the UID of the automation object for parsing.
* @param t is the exception thrown during the parsing.
*/
public ParsingNestedException(int type, String id, Throwable t) {
public ParsingNestedException(int type, @Nullable String id, Throwable t) {
super(t);
this.id = id;
this.type = type;
}
@Override
public String getMessage() {
public @Nullable String getMessage() {
StringBuilder sb = new StringBuilder();
switch (type) {
case MODULE_TYPE:
@@ -18,6 +18,7 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -36,6 +37,7 @@ import io.micrometer.core.instrument.Tags;
*
* @author Robert Bach - Initial contribution
*/
@NonNullByDefault
public class BundleStateMetric implements OpenhabCoreMeterBinder, BundleListener {
private final Logger logger = LoggerFactory.getLogger(BundleStateMetric.class);
public static final String METRIC_NAME = "openhab.bundle.state";
@@ -52,7 +54,7 @@ public class BundleStateMetric implements OpenhabCoreMeterBinder, BundleListener
}
@Override
public void bindTo(@io.micrometer.core.lang.NonNull MeterRegistry meterRegistry) {
public void bindTo(@NonNullByDefault({}) MeterRegistry meterRegistry) {
unbind();
logger.debug("BundleStateMetric is being bound...");
this.meterRegistry = meterRegistry;
@@ -63,7 +65,7 @@ public class BundleStateMetric implements OpenhabCoreMeterBinder, BundleListener
}
@Override
public void bundleChanged(BundleEvent bundleEvent) {
public void bundleChanged(@NonNullByDefault({}) BundleEvent bundleEvent) {
if (meterRegistry == null) {
return;
}
@@ -18,6 +18,7 @@ import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.events.Event;
import org.openhab.core.events.EventFilter;
@@ -39,6 +40,7 @@ import io.micrometer.core.instrument.Tag;
*
* @author Robert Bach - Initial contribution
*/
@NonNullByDefault
public class EventCountMetric implements OpenhabCoreMeterBinder, EventSubscriber {
public static final String METRIC_NAME = "event_count";
@@ -47,7 +49,7 @@ public class EventCountMetric implements OpenhabCoreMeterBinder, EventSubscriber
private static final String TOPIC_TAG_NAME = "topic";
private @Nullable MeterRegistry meterRegistry;
private final Set<Tag> tags = new HashSet<>();
private ServiceRegistration<?> eventSubscriberRegistration;
private @Nullable ServiceRegistration<?> eventSubscriberRegistration;
private BundleContext bundleContext;
public EventCountMetric(BundleContext bundleContext, Collection<Tag> tags) {
@@ -57,7 +59,7 @@ public class EventCountMetric implements OpenhabCoreMeterBinder, EventSubscriber
}
@Override
public void bindTo(MeterRegistry meterRegistry) {
public void bindTo(@NonNullByDefault({}) MeterRegistry meterRegistry) {
unbind();
logger.debug("EventCountMetric is being bound...");
this.meterRegistry = meterRegistry;
@@ -16,6 +16,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,6 +35,7 @@ import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
*
* @author Robert Bach - Initial contribution
*/
@NonNullByDefault
public class JVMMetric implements OpenhabCoreMeterBinder {
private final Logger logger = LoggerFactory.getLogger(JVMMetric.class);
@@ -47,7 +49,7 @@ public class JVMMetric implements OpenhabCoreMeterBinder {
}
@Override
public void bindTo(MeterRegistry registry) {
public void bindTo(@NonNullByDefault({}) MeterRegistry registry) {
unbind();
logger.debug("JVMMetric is being bound...");
this.meterRegistry = registry;
@@ -18,6 +18,7 @@ import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.Rule;
import org.openhab.core.automation.RuleRegistry;
@@ -40,6 +41,7 @@ import io.micrometer.core.instrument.Tag;
*
* @author Robert Bach - Initial contribution
*/
@NonNullByDefault
public class RuleMetric implements OpenhabCoreMeterBinder, EventSubscriber {
public static final String METRIC_NAME = "openhab.rule.runs";
@@ -53,7 +55,7 @@ public class RuleMetric implements OpenhabCoreMeterBinder, EventSubscriber {
private static final String RULE_NAME_TAG_NAME = "rulename";
private @Nullable MeterRegistry meterRegistry;
private final Set<Tag> tags = new HashSet<>();
private ServiceRegistration<?> eventSubscriberRegistration;
private @Nullable ServiceRegistration<?> eventSubscriberRegistration;
private BundleContext bundleContext;
private RuleRegistry ruleRegistry;
@@ -65,7 +67,7 @@ public class RuleMetric implements OpenhabCoreMeterBinder, EventSubscriber {
}
@Override
public void bindTo(MeterRegistry meterRegistry) {
public void bindTo(@NonNullByDefault({}) MeterRegistry meterRegistry) {
unbind();
logger.debug("RuleMetric is being bound...");
this.meterRegistry = meterRegistry;
@@ -130,7 +132,7 @@ public class RuleMetric implements OpenhabCoreMeterBinder, EventSubscriber {
meterRegistry.counter(METRIC_NAME, tagsWithRule).increment();
}
private String getRuleName(String ruleId) {
private @Nullable String getRuleName(String ruleId) {
Rule rule = ruleRegistry.get(ruleId);
return rule == null ? null : rule.getName();
}
@@ -20,6 +20,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.events.Event;
import org.openhab.core.events.EventFilter;
@@ -46,6 +47,7 @@ import io.micrometer.core.instrument.Tags;
*
* @author Robert Bach - Initial contribution
*/
@NonNullByDefault
public class ThingStateMetric implements OpenhabCoreMeterBinder, EventSubscriber {
private final Logger logger = LoggerFactory.getLogger(ThingStateMetric.class);
public static final String METRIC_NAME = "openhab.thing.state";
@@ -66,7 +68,7 @@ public class ThingStateMetric implements OpenhabCoreMeterBinder, EventSubscriber
}
@Override
public void bindTo(@io.micrometer.core.lang.NonNull MeterRegistry meterRegistry) {
public void bindTo(@NonNullByDefault({}) MeterRegistry meterRegistry) {
unbind();
logger.debug("ThingStateMetric is being bound...");
this.meterRegistry = meterRegistry;
@@ -17,6 +17,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.common.ThreadPoolManager;
import org.slf4j.Logger;
@@ -32,6 +33,7 @@ import io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics;
*
* @author Robert Bach - Initial contribution
*/
@NonNullByDefault
public class ThreadPoolMetric implements OpenhabCoreMeterBinder {
private final Logger logger = LoggerFactory.getLogger(ThreadPoolMetric.class);
@@ -46,7 +48,7 @@ public class ThreadPoolMetric implements OpenhabCoreMeterBinder {
}
@Override
public void bindTo(MeterRegistry registry) {
public void bindTo(@NonNullByDefault({}) MeterRegistry registry) {
unbind();
logger.debug("ThreadPoolMetric is being bound...");
this.meterRegistry = registry;
@@ -14,12 +14,17 @@ package org.openhab.core.io.rest;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* Utilities for mapping/transforming DTOs.
*
* @author Simon Kaufmann - Initial contribution
*/
@NonNullByDefault
public interface DTOMapper {
<T> Stream<T> limitToFields(Stream<T> itemStream, String fields);
<@NonNull T> Stream<T> limitToFields(Stream<T> itemStream, @Nullable String fields);
}
@@ -12,11 +12,14 @@
*/
package org.openhab.core.io.rest.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* Utility class for constants.
*
* @author Ivan Iliev - Initial contribution
*/
@NonNullByDefault
public class Constants {
public static final String CORS_PROPERTY = "enable";
}
@@ -17,6 +17,9 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.io.rest.DTOMapper;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
@@ -29,12 +32,13 @@ import org.slf4j.LoggerFactory;
* @author Simon Kaufmann - Initial contribution
*/
@Component
@NonNullByDefault
public class DTOMapperImpl implements DTOMapper {
private final Logger logger = LoggerFactory.getLogger(DTOMapperImpl.class);
@Override
public <T> Stream<T> limitToFields(Stream<T> itemStream, String fields) {
public <@NonNull T> Stream<T> limitToFields(Stream<T> itemStream, @Nullable String fields) {
if (fields == null || fields.trim().isEmpty()) {
return itemStream;
}
@@ -23,6 +23,8 @@ import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MultivaluedMap;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.io.rest.RESTConstants;
import org.openhab.core.io.rest.internal.Constants;
import org.osgi.service.component.annotations.Activate;
@@ -49,6 +51,7 @@ import org.slf4j.LoggerFactory;
"service.pid=org.openhab.core.cors" }, configurationPid = "org.openhab.cors", configurationPolicy = ConfigurationPolicy.REQUIRE)
@JaxrsExtension
@JaxrsApplicationSelect("(" + JaxrsWhiteboardConstants.JAX_RS_NAME + "=" + RESTConstants.JAX_RS_NAME + ")")
@NonNullByDefault
public class CorsFilter implements ContainerResponseFilter {
static final String HTTP_HEAD_METHOD = "HEAD";
@@ -87,8 +90,8 @@ public class CorsFilter implements ContainerResponseFilter {
}
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
public void filter(@NonNullByDefault({}) ContainerRequestContext requestContext,
@NonNullByDefault({}) ContainerResponseContext responseContext) throws IOException {
if (isEnabled && !processPreflight(requestContext, responseContext)) {
processRequest(requestContext, responseContext);
}
@@ -150,9 +153,8 @@ public class CorsFilter implements ContainerResponseFilter {
* @param header
* @return The first value from the given header or null if the header is
* not found.
*
*/
private String getValue(MultivaluedMap<String, String> headers, String header) {
private @Nullable String getValue(MultivaluedMap<String, String> headers, String header) {
List<String> values = headers.get(header);
if (values == null || values.isEmpty()) {
return null;
@@ -177,7 +179,7 @@ public class CorsFilter implements ContainerResponseFilter {
}
@Activate
protected void activate(Map<String, Object> properties) {
protected void activate(@Nullable Map<String, Object> properties) {
if (properties != null) {
String corsPropertyValue = (String) properties.get(Constants.CORS_PROPERTY);
this.isEnabled = "true".equalsIgnoreCase(corsPropertyValue);
@@ -24,6 +24,8 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.io.rest.RESTConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants;
@@ -43,6 +45,7 @@ import org.slf4j.LoggerFactory;
@JaxrsExtension
@JaxrsApplicationSelect("(" + JaxrsWhiteboardConstants.JAX_RS_NAME + "=" + RESTConstants.JAX_RS_NAME + ")")
@PreMatching
@NonNullByDefault
public class ProxyFilter implements ContainerRequestFilter {
static final String PROTO_PROXY_HEADER = "x-forwarded-proto";
@@ -52,7 +55,7 @@ public class ProxyFilter implements ContainerRequestFilter {
private final transient Logger logger = LoggerFactory.getLogger(ProxyFilter.class);
@Override
public void filter(ContainerRequestContext ctx) throws IOException {
public void filter(@NonNullByDefault({}) ContainerRequestContext ctx) throws IOException {
String host = getValue(ctx.getHeaders(), HOST_PROXY_HEADER);
String scheme = getValue(ctx.getHeaders(), PROTO_PROXY_HEADER);
@@ -114,7 +117,7 @@ public class ProxyFilter implements ContainerRequestFilter {
ctx.setRequestUri(baseBuilder.build(), requestBuilder.build());
}
private String getValue(MultivaluedMap<String, String> headers, String header) {
private @Nullable String getValue(MultivaluedMap<String, String> headers, String header) {
List<String> values = headers.get(header);
if (values == null || values.isEmpty()) {
return null;
@@ -12,11 +12,14 @@
*/
package org.openhab.core.model.core;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* These are the event types that can occur as model repository changes
*
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
public enum EventType {
ADDED,
REMOVED,
@@ -12,11 +12,14 @@
*/
package org.openhab.core.model.core;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* This class holds all important constants relevant for this bundle.
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
public class ModelCoreConstants {
/** The service pid used for the managed service (without the "org.openhab.core" prefix */
@@ -12,11 +12,14 @@
*/
package org.openhab.core.model.core;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* This interface has to be implemented by services that register an EMF model parser
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
public interface ModelParser {
/**
@@ -14,11 +14,14 @@ package org.openhab.core.model.core;
import java.util.function.Supplier;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* Service interface to execute EMF methods in a single based thread.
*
* @author Markus Rathgeb - Initial contribution
*/
@NonNullByDefault
public interface SafeEMF {
/**
@@ -12,6 +12,8 @@
*/
package org.openhab.core.model.core.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -19,21 +21,22 @@ import org.osgi.framework.BundleContext;
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
public class ModelCoreActivator implements BundleActivator {
private static BundleContext context;
private static @Nullable BundleContext context;
static BundleContext getContext() {
static @Nullable BundleContext getContext() {
return context;
}
@Override
public void start(BundleContext bundleContext) throws Exception {
public void start(@Nullable BundleContext bundleContext) throws Exception {
ModelCoreActivator.context = bundleContext;
}
@Override
public void stop(BundleContext bundleContext) throws Exception {
public void stop(@Nullable BundleContext bundleContext) throws Exception {
ModelCoreActivator.context = null;
}
}
@@ -14,6 +14,7 @@ package org.openhab.core.model.core.internal;
import java.util.function.Supplier;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.model.core.SafeEMF;
import org.osgi.service.component.annotations.Component;
@@ -23,6 +24,7 @@ import org.osgi.service.component.annotations.Component;
* @author Markus Rathgeb - Initial contribution
*/
@Component
@NonNullByDefault
public class SafeEMFImpl implements SafeEMF {
@Override
@@ -34,6 +34,8 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.OpenHAB;
import org.openhab.core.model.core.ModelParser;
import org.openhab.core.model.core.ModelRepository;
@@ -59,6 +61,7 @@ import org.slf4j.LoggerFactory;
* @author Fabio Marini - Refactoring to use WatchService
* @author Ana Dimova - reduce to a single watch thread for all class instances
*/
@NonNullByDefault
@Component(name = "org.openhab.core.folder", immediate = true, configurationPid = "org.openhab.folder", configurationPolicy = ConfigurationPolicy.REQUIRE)
public class FolderObserver extends AbstractWatchService {
private Logger logger = LoggerFactory.getLogger(FolderObserver.class);
@@ -163,7 +166,7 @@ public class FolderObserver extends AbstractWatchService {
}
@Override
protected Kind<?>[] getWatchEventKinds(Path directory) {
protected Kind<?> @Nullable [] getWatchEventKinds(Path directory) {
if (directory != null && isNotEmpty(folderFileExtMap)) {
String folderName = directory.getFileName().toString();
if (folderFileExtMap.containsKey(folderName)) {
@@ -228,7 +231,7 @@ public class FolderObserver extends AbstractWatchService {
}
@Override
public boolean accept(File dir, String name) {
public boolean accept(@NonNullByDefault({}) File dir, @NonNullByDefault({}) String name) {
if (validExtensions != null && validExtensions.length > 0) {
for (String extension : validExtensions) {
if (name.toLowerCase().endsWith("." + extension)) {
@@ -267,7 +270,7 @@ public class FolderObserver extends AbstractWatchService {
}
}
private File getFileByFileExtMap(Map<String, String[]> folderFileExtMap, String filename) {
private @Nullable File getFileByFileExtMap(Map<String, String[]> folderFileExtMap, String filename) {
if (filename != null && !filename.trim().isEmpty() && isNotEmpty(folderFileExtMap)) {
String extension = getExtension(filename);
if (extension != null && !extension.trim().isEmpty()) {
@@ -12,12 +12,15 @@
*/
package org.openhab.core.model.core.internal.util;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* This class provides a few mathematical helper functions that are required by
* code of this bundle.
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
public class MathUtils {
/**
@@ -14,6 +14,8 @@ package org.openhab.core.model.core.valueconverter;
import java.math.BigDecimal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.xtext.conversion.IValueConverter;
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.nodemodel.INode;
@@ -25,10 +27,11 @@ import org.eclipse.xtext.util.Strings;
*
* @author Alex Tugarev - Initial contribution
*/
public class ValueTypeToStringConverter implements IValueConverter<Object> {
@NonNullByDefault
public class ValueTypeToStringConverter implements IValueConverter<@Nullable Object> {
@Override
public Object toValue(String string, INode node) throws ValueConverterException {
public @Nullable Object toValue(@Nullable String string, @Nullable INode node) throws ValueConverterException {
if (string == null) {
return null;
}
@@ -50,7 +53,7 @@ public class ValueTypeToStringConverter implements IValueConverter<Object> {
}
@Override
public String toString(Object value) throws ValueConverterException {
public String toString(@Nullable Object value) throws ValueConverterException {
if (value == null) {
throw new ValueConverterException("Value may not be null.", null, null);
}
@@ -12,12 +12,14 @@
*/
package org.openhab.core.model.item.runtime.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.model.ItemsStandaloneSetup;
import org.openhab.core.model.core.ModelParser;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@NonNullByDefault
@Component(immediate = true)
public class ItemRuntimeActivator implements ModelParser {
@@ -13,12 +13,14 @@
package org.openhab.core.model.lazygen;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.xtext.resource.XtextResourceSet;
/**
*
* @author Holger Schill, Simon Kaufmann - Initial contribution
*/
@NonNullByDefault
public class GlobalResourceSet {
public static ResourceSet getINSTANCE() {
@@ -15,14 +15,18 @@ package org.openhab.core.model.lazygen;
import org.eclipse.emf.mwe.core.WorkflowContext;
import org.eclipse.emf.mwe.core.issues.Issues;
import org.eclipse.emf.mwe.core.monitor.ProgressMonitor;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.xtext.generator.Generator;
/**
*
* @author Holger Schill, Simon Kaufmann - Initial contribution
*/
@NonNullByDefault
public class LazyGenerator extends Generator {
@Nullable
LazyLanguageConfig langConfig = null;
public void addLazyLanguage(LazyLanguageConfig langConfig) {
@@ -31,12 +35,13 @@ public class LazyGenerator extends Generator {
}
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
protected void invokeInternal(@NonNullByDefault({}) WorkflowContext ctx,
@NonNullByDefault({}) ProgressMonitor monitor, @NonNullByDefault({}) Issues issues) {
super.checkConfigurationInternal(issues);
super.invokeInternal(ctx, monitor, issues);
}
@Override
protected void checkConfigurationInternal(Issues issues) {
protected void checkConfigurationInternal(@NonNullByDefault({}) Issues issues) {
}
}
@@ -18,6 +18,8 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.xpand2.XpandExecutionContext;
import org.eclipse.xtext.Grammar;
import org.eclipse.xtext.ecore.EcoreSupportStandaloneSetup;
@@ -32,21 +34,23 @@ import org.slf4j.LoggerFactory;
*
* @author Holger Schill, Simon Kaufmann - Initial contribution
*/
@NonNullByDefault
public class LazyLanguageConfig extends LanguageConfig {
private final Logger logger = LoggerFactory.getLogger(LazyLanguageConfig.class);
@Nullable
String uri = null;
boolean isUI = false;
@Override
public void setUri(String uri) {
public void setUri(@Nullable String uri) {
this.uri = uri;
}
private Grammar grammar;
private @Nullable Grammar grammar;
@Override
public Grammar getGrammar() {
public @Nullable Grammar getGrammar() {
setUriReally(uri);
return grammar;
}
@@ -61,22 +65,23 @@ public class LazyLanguageConfig extends LanguageConfig {
}
@Override
protected void validateGrammar(Grammar grammar) {
protected void validateGrammar(@NonNullByDefault({}) Grammar grammar) {
}
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
public void generate(@NonNullByDefault({}) Grammar grammar, @NonNullByDefault({}) XpandExecutionContext ctx) {
initializeReally();
super.generate(grammar, ctx);
}
@Override
public void generate(LanguageConfig config, XpandExecutionContext ctx) throws CompositeGeneratorException {
public void generate(@NonNullByDefault({}) LanguageConfig config, @NonNullByDefault({}) XpandExecutionContext ctx)
throws CompositeGeneratorException {
initializeReally();
super.generate(config, ctx);
}
public void setUriReally(String uri) {
public void setUriReally(@Nullable String uri) {
ResourceSet rs = GlobalResourceSet.getINSTANCE();
for (String loadedResource : getLoadedResources()) {
URI loadedResourceUri = URI.createURI(loadedResource);
@@ -32,6 +32,7 @@ import org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent2;
import org.eclipse.emf.mwe.core.monitor.ProgressMonitor;
import org.eclipse.emf.mwe.core.resources.ResourceLoaderFactory;
import org.eclipse.emf.mwe.utils.GenModelHelper;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,6 +40,7 @@ import org.slf4j.LoggerFactory;
*
* @author Holger Schill, Simon Kaufmann - Initial contribution
*/
@NonNullByDefault
public class LazyStandaloneSetup extends AbstractWorkflowComponent2 {
private static ResourceSet resourceSet = GlobalResourceSet.getINSTANCE();
@@ -61,7 +63,8 @@ public class LazyStandaloneSetup extends AbstractWorkflowComponent2 {
}
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
protected void invokeInternal(@NonNullByDefault({}) WorkflowContext ctx,
@NonNullByDefault({}) ProgressMonitor monitor, @NonNullByDefault({}) Issues issues) {
for (String generatedEPackage : allgeneratedEPackages) {
addRegisterGeneratedEPackage(generatedEPackage);
}
@@ -19,6 +19,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.xtext.ide.server.UriExtensions;
import org.slf4j.Logger;
@@ -32,6 +33,7 @@ import org.slf4j.LoggerFactory;
*
* @author Simon Kaufmann - Initial contribution
*/
@NonNullByDefault
public class MappingUriExtensions extends UriExtensions {
private final Logger logger = LoggerFactory.getLogger(MappingUriExtensions.class);
@@ -55,7 +57,7 @@ public class MappingUriExtensions extends UriExtensions {
}
@Override
public URI toUri(String pathWithScheme) {
public URI toUri(@NonNullByDefault({}) String pathWithScheme) {
String decodedPathWithScheme = URLDecoder.decode(pathWithScheme, StandardCharsets.UTF_8);
String localClientLocation = clientLocation;
if (localClientLocation != null && decodedPathWithScheme.startsWith(localClientLocation)) {
@@ -76,7 +78,7 @@ public class MappingUriExtensions extends UriExtensions {
}
@Override
public String toUriString(URI uri) {
public String toUriString(@NonNullByDefault({}) URI uri) {
if (clientLocation == null) {
return uri.toString();
}
@@ -84,7 +86,7 @@ public class MappingUriExtensions extends UriExtensions {
}
@Override
public String toUriString(java.net.URI uri) {
public String toUriString(@NonNullByDefault({}) java.net.URI uri) {
return toUriString(URI.createURI(uri.toString()));
}
@@ -158,8 +160,9 @@ public class MappingUriExtensions extends UriExtensions {
return ret;
}
private java.net.URI toURI(String pathWithScheme, String currentPath) {
return java.net.URI.create(pathWithScheme.replace(currentPath, serverLocation));
private java.net.URI toURI(String pathWithScheme, @Nullable String currentPath) {
String path = currentPath == null ? pathWithScheme : pathWithScheme.replace(currentPath, serverLocation);
return java.net.URI.create(path);
}
private String toPathAsInXtext212(java.net.URI uri) {
@@ -18,11 +18,12 @@ import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.xtext.XtextPackage;
import org.eclipse.xtext.resource.FileExtensionProvider;
import org.eclipse.xtext.resource.IResourceFactory;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.resource.IResourceServiceProvider.Registry;
import org.eclipse.xtext.resource.impl.BinaryGrammarResourceFactoryImpl;
import org.eclipse.xtext.resource.impl.ResourceServiceProviderRegistryImpl;
import org.openhab.core.model.ide.ItemsIdeSetup;
@@ -46,9 +47,10 @@ import com.google.inject.Singleton;
* @author Simon Kaufmann - Initial contribution
*/
@Singleton
@NonNullByDefault
public class RegistryProvider implements Provider<IResourceServiceProvider.Registry> {
private IResourceServiceProvider.Registry registry;
private IResourceServiceProvider.@Nullable Registry registry;
private final ScriptServiceUtil scriptServiceUtil;
private final ScriptEngine scriptEngine;
@@ -59,13 +61,12 @@ public class RegistryProvider implements Provider<IResourceServiceProvider.Regis
@Override
public synchronized IResourceServiceProvider.Registry get() {
if (registry == null) {
registry = createRegistry();
}
IResourceServiceProvider.Registry registry = Objects.requireNonNullElse(this.registry, createRegistry());
this.registry = registry;
return registry;
}
private Registry createRegistry() {
private IResourceServiceProvider.Registry createRegistry() {
registerDefaultFactories();
IResourceServiceProvider.Registry registry = new ResourceServiceProviderRegistryImpl();
@@ -14,6 +14,7 @@ package org.openhab.core.model.lsp.internal;
import java.util.concurrent.ExecutorService;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.xtext.ide.ExecutorServiceProvider;
import org.eclipse.xtext.ide.server.DefaultProjectDescriptionFactory;
@@ -37,6 +38,7 @@ import com.google.inject.AbstractModule;
*
* @author Simon Kaufmann - Initial contribution
*/
@NonNullByDefault
public class RuntimeServerModule extends AbstractModule {
private final ScriptServiceUtil scriptServiceUtil;
@@ -12,12 +12,14 @@
*/
package org.openhab.core.model.persistence.runtime.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.model.core.ModelParser;
import org.openhab.core.model.persistence.PersistenceStandaloneSetup;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@NonNullByDefault
@Component(immediate = true)
public class PersistenceRuntimeActivator implements ModelParser {
@@ -12,11 +12,13 @@
*/
package org.openhab.core.model.rule.runtime.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.model.core.ModelParser;
import org.openhab.core.model.rule.RulesStandaloneSetup;
import org.openhab.core.model.script.ScriptServiceUtil;
import org.openhab.core.model.script.engine.ScriptEngine;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
@@ -27,12 +29,20 @@ import org.slf4j.LoggerFactory;
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
@Component(immediate = true, service = { ModelParser.class, RuleRuntimeActivator.class })
public class RuleRuntimeActivator implements ModelParser {
private final Logger logger = LoggerFactory.getLogger(RuleRuntimeActivator.class);
private ScriptServiceUtil scriptServiceUtil;
private ScriptEngine scriptEngine;
private final ScriptServiceUtil scriptServiceUtil;
private final ScriptEngine scriptEngine;
@Activate
public RuleRuntimeActivator(final @Reference ScriptEngine scriptEngine,
final @Reference ScriptServiceUtil scriptServiceUtil) {
this.scriptEngine = scriptEngine;
this.scriptServiceUtil = scriptServiceUtil;
}
public void activate(BundleContext bc) throws Exception {
RulesStandaloneSetup.doSetup(scriptServiceUtil, scriptEngine);
@@ -47,23 +57,4 @@ public class RuleRuntimeActivator implements ModelParser {
public String getExtension() {
return "rules";
}
@Reference
protected void setScriptServiceUtil(ScriptServiceUtil scriptServiceUtil) {
this.scriptServiceUtil = scriptServiceUtil;
}
protected void unsetScriptServiceUtil(ScriptServiceUtil scriptServiceUtil) {
this.scriptServiceUtil = null;
}
@Reference
public void setScriptEngine(ScriptEngine scriptEngine) {
this.scriptEngine = scriptEngine;
}
public void unsetScriptEngine(ScriptEngine scriptEngine) {
this.scriptEngine = null;
}
}
@@ -24,14 +24,6 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.openhab.core.model.core.ModelParser;
import org.openhab.core.model.script.ScriptServiceUtil;
import org.openhab.core.model.script.ScriptStandaloneSetup;
import org.openhab.core.model.script.engine.Script;
import org.openhab.core.model.script.engine.ScriptEngine;
import org.openhab.core.model.script.engine.ScriptExecutionException;
import org.openhab.core.model.script.engine.ScriptParsingException;
import org.openhab.core.model.script.runtime.ScriptRuntime;
import org.eclipse.xtext.diagnostics.Severity;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.resource.XtextResourceSet;
@@ -41,6 +33,14 @@ import org.eclipse.xtext.validation.CheckMode;
import org.eclipse.xtext.validation.IResourceValidator;
import org.eclipse.xtext.validation.Issue;
import org.eclipse.xtext.xbase.XExpression;
import org.openhab.core.model.core.ModelParser;
import org.openhab.core.model.script.ScriptServiceUtil;
import org.openhab.core.model.script.ScriptStandaloneSetup;
import org.openhab.core.model.script.engine.Script;
import org.openhab.core.model.script.engine.ScriptEngine;
import org.openhab.core.model.script.engine.ScriptExecutionException;
import org.openhab.core.model.script.engine.ScriptParsingException;
import org.openhab.core.model.script.runtime.ScriptRuntime;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
@@ -190,7 +190,7 @@ public class ScriptEngineImpl implements ScriptEngine, ModelParser {
private void deleteResource(Resource resource) {
try {
resource.delete(Collections.emptyMap());
} catch(IOException e) {
} catch (IOException e) {
// Do nothing
}
}
@@ -15,6 +15,7 @@ package org.openhab.core.model.script.actions;
import java.io.IOException;
import java.math.BigDecimal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.audio.AudioException;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.model.script.engine.action.ActionDoc;
@@ -30,6 +31,7 @@ import org.slf4j.LoggerFactory;
* @author Kai Kreuzer - Initial contribution
* @author Christoph Weitkamp - Added parameter to adjust the volume
*/
@NonNullByDefault
public class Audio {
private static final Logger logger = LoggerFactory.getLogger(Audio.class);
@@ -12,6 +12,10 @@
*/
package org.openhab.core.model.script.actions;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.model.script.engine.action.ActionDoc;
import org.openhab.core.model.script.engine.action.ParamDoc;
@@ -25,6 +29,7 @@ import org.openhab.core.voice.text.InterpretationException;
* @author Kai Kreuzer - Initial contribution
* @author Christoph Weitkamp - Added parameter to adjust the volume
*/
@NonNullByDefault
public class Voice {
/**
@@ -49,7 +54,7 @@ public class Voice {
*/
@ActionDoc(text = "says a given text with the default voice and the given volume")
public static void say(@ParamDoc(name = "text") Object text,
@ParamDoc(name = "volume", text = "the volume to be used") PercentType volume) {
@ParamDoc(name = "volume", text = "the volume to be used") @Nullable PercentType volume) {
say(text, null, null, volume);
}
@@ -64,7 +69,7 @@ public class Voice {
* voiceId is assumed to be available on the default TTS service.
*/
@ActionDoc(text = "says a given text with a given voice")
public static void say(@ParamDoc(name = "text") Object text, @ParamDoc(name = "voice") String voice) {
public static void say(@ParamDoc(name = "text") Object text, @ParamDoc(name = "voice") @Nullable String voice) {
say(text, voice, null, null);
}
@@ -80,7 +85,7 @@ public class Voice {
* @param volume The volume to be used
*/
@ActionDoc(text = "says a given text with a given voice and the given volume")
public static void say(@ParamDoc(name = "text") Object text, @ParamDoc(name = "voice") String voice,
public static void say(@ParamDoc(name = "text") Object text, @ParamDoc(name = "voice") @Nullable String voice,
@ParamDoc(name = "volume", text = "the volume to be used") PercentType volume) {
say(text, voice, null, volume);
}
@@ -96,8 +101,8 @@ public class Voice {
* be used
*/
@ActionDoc(text = "says a given text with a given voice through the given sink")
public static void say(@ParamDoc(name = "text") Object text, @ParamDoc(name = "voice") String voice,
@ParamDoc(name = "sink") String sink) {
public static void say(@ParamDoc(name = "text") Object text, @ParamDoc(name = "voice") @Nullable String voice,
@ParamDoc(name = "sink") @Nullable String sink) {
say(text, voice, sink, null);
}
@@ -113,9 +118,9 @@ public class Voice {
* @param volume The volume to be used
*/
@ActionDoc(text = "says a given text with a given voice and the given volume through the given sink")
public static void say(@ParamDoc(name = "text") Object text, @ParamDoc(name = "voice") String voice,
@ParamDoc(name = "sink") String sink,
@ParamDoc(name = "volume", text = "the volume to be used") PercentType volume) {
public static void say(@ParamDoc(name = "text") Object text, @ParamDoc(name = "voice") @Nullable String voice,
@ParamDoc(name = "sink") @Nullable String sink,
@ParamDoc(name = "volume", text = "the volume to be used") @Nullable PercentType volume) {
String output = text.toString();
if (!output.isBlank()) {
VoiceActionService.voiceManager.say(output, voice, sink, volume);
@@ -145,13 +150,14 @@ public class Voice {
*/
@ActionDoc(text = "interprets a given text by a given human language interpreter", returns = "human language response")
public static String interpret(@ParamDoc(name = "text") Object text,
@ParamDoc(name = "interpreter") String interpreter) {
@ParamDoc(name = "interpreter") @Nullable String interpreter) {
String response;
try {
response = VoiceActionService.voiceManager.interpret(text.toString(), interpreter);
} catch (InterpretationException e) {
say(e.getMessage());
response = e.getMessage();
String message = Objects.requireNonNullElse(e.getMessage(), "");
say(message);
response = message;
}
return response;
}
@@ -168,15 +174,16 @@ public class Voice {
*/
@ActionDoc(text = "interprets a given text by a given human language interpreter", returns = "human language response")
public static String interpret(@ParamDoc(name = "text") Object text,
@ParamDoc(name = "interpreter") String interpreter, @ParamDoc(name = "sink") String sink) {
@ParamDoc(name = "interpreter") String interpreter, @ParamDoc(name = "sink") @Nullable String sink) {
String response;
try {
response = VoiceActionService.voiceManager.interpret(text.toString(), interpreter);
} catch (InterpretationException e) {
String message = Objects.requireNonNullElse(e.getMessage(), "");
if (sink != null) {
say(e.getMessage(), null, sink);
say(message, null, sink);
}
response = e.getMessage();
response = message;
}
return response;
}
@@ -12,11 +12,14 @@
*/
package org.openhab.core.model.script.engine.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* This interface must be implemented by services that want to contribute script actions.
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
public interface ActionService {
/**
@@ -17,6 +17,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.config.core.ConfigurableService;
import org.openhab.core.events.Event;
import org.openhab.core.events.EventPublisher;
@@ -42,6 +44,7 @@ import org.slf4j.LoggerFactory;
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
@Component(immediate = true, service = HumanLanguageInterpreter.class, configurationPid = "org.openhab.rulehli", //
property = Constants.SERVICE_PID + "=org.openhab.rulehli")
@ConfigurableService(category = "voice", label = "Rule Voice Interpreter", description_uri = RuleHumanLanguageInterpreter.CONFIG_URI)
@@ -83,7 +86,7 @@ public class RuleHumanLanguageInterpreter implements HumanLanguageInterpreter {
}
@Override
public String getLabel(Locale locale) {
public String getLabel(@Nullable Locale locale) {
return "Rule-based Interpreter";
}
@@ -91,18 +94,18 @@ public class RuleHumanLanguageInterpreter implements HumanLanguageInterpreter {
public String interpret(Locale locale, String text) throws InterpretationException {
Event event = ItemEventFactory.createCommandEvent(itemName, new StringType(text));
eventPublisher.post(event);
return null;
return "";
}
@Override
public String getGrammar(Locale locale, String format) {
public @Nullable String getGrammar(Locale locale, String format) {
return null;
}
@Override
public Set<Locale> getSupportedLocales() {
// we do not care about locales, so we return null here to indicate this
return null;
// we do not care about locales, so we return an empty set here to indicate this
return Set.of();
}
@Override
@@ -12,29 +12,28 @@
*/
package org.openhab.core.model.script.internal.engine.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.audio.AudioManager;
import org.openhab.core.model.script.actions.Audio;
import org.openhab.core.model.script.engine.action.ActionService;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@Component
@NonNullByDefault
public class AudioActionService implements ActionService {
public static AudioManager audioManager;
public static @Nullable AudioManager audioManager;
@Activate
public AudioActionService(final @Reference AudioManager audioManager) {
AudioActionService.audioManager = audioManager;
}
@Override
public Class<?> getActionClass() {
return Audio.class;
}
@Reference
protected void setAudioManager(AudioManager audioManager) {
AudioActionService.audioManager = audioManager;
}
protected void unsetAudioManager(AudioManager audioManager) {
AudioActionService.audioManager = null;
}
}
@@ -12,9 +12,12 @@
*/
package org.openhab.core.model.script.internal.engine.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.ephemeris.EphemerisManager;
import org.openhab.core.model.script.actions.Ephemeris;
import org.openhab.core.model.script.engine.action.ActionService;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@@ -24,22 +27,18 @@ import org.osgi.service.component.annotations.Reference;
* @author Gaël L'hopital - Initial contribution
*/
@Component
@NonNullByDefault
public class EphemerisActionService implements ActionService {
public static EphemerisManager ephemerisManager;
public static @Nullable EphemerisManager ephemerisManager;
@Activate
public EphemerisActionService(final @Reference EphemerisManager ephemerisManager) {
EphemerisActionService.ephemerisManager = ephemerisManager;
}
@Override
public Class<?> getActionClass() {
return Ephemeris.class;
}
@Reference
protected void setEphemerisManager(EphemerisManager ephemerisManager) {
EphemerisActionService.ephemerisManager = ephemerisManager;
}
protected void unsetEphemerisManager(EphemerisManager ephemerisManager) {
EphemerisActionService.ephemerisManager = null;
}
}
}
@@ -12,6 +12,7 @@
*/
package org.openhab.core.model.script.internal.engine.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.model.script.engine.action.ActionService;
import org.openhab.core.persistence.extensions.PersistenceExtensions;
import org.osgi.service.component.annotations.Component;
@@ -22,14 +23,11 @@ import org.osgi.service.component.annotations.Component;
* @author Kai Kreuzer - Initial contribution
*/
@Component
@NonNullByDefault
public class PersistenceActionService implements ActionService {
public PersistenceActionService() {
}
@Override
public Class<?> getActionClass() {
return PersistenceExtensions.class;
}
}
@@ -15,6 +15,8 @@ package org.openhab.core.model.script.internal.engine.action;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.model.script.actions.Things;
import org.openhab.core.model.script.engine.action.ActionService;
import org.openhab.core.thing.Thing;
@@ -36,11 +38,12 @@ import org.osgi.service.component.annotations.ReferencePolicy;
* @author Maoliang Huang - Initial contribution
* @author Kai Kreuzer - Extended for general thing access
*/
@NonNullByDefault
@Component(immediate = true)
public class ThingActionService implements ActionService {
private static final Map<String, ThingActions> THING_ACTIONS_MAP = new HashMap<>();
private static ThingRegistry thingRegistry;
private static @Nullable ThingRegistry thingRegistry;
@Activate
public ThingActionService(final @Reference ThingRegistry thingRegistry) {
@@ -52,7 +55,7 @@ public class ThingActionService implements ActionService {
return Things.class;
}
public static ThingStatusInfo getThingStatusInfo(String thingUid) {
public static @Nullable ThingStatusInfo getThingStatusInfo(String thingUid) {
ThingUID uid = new ThingUID(thingUid);
Thing thing = thingRegistry.get(uid);
@@ -71,7 +74,7 @@ public class ThingActionService implements ActionService {
*
* @return actions the actions instance or null, if not available
*/
public static ThingActions getActions(String scope, String thingUid) {
public static @Nullable ThingActions getActions(String scope, String thingUid) {
ThingUID uid = new ThingUID(thingUid);
Thing thing = thingRegistry.get(uid);
if (thing != null) {
@@ -12,8 +12,8 @@
*/
package org.openhab.core.model.script.internal.engine.action;
import org.openhab.core.transform.actions.Transformation;
import org.openhab.core.model.script.engine.action.ActionService;
import org.openhab.core.transform.actions.Transformation;
import org.osgi.service.component.annotations.Component;
/**
@@ -24,12 +24,8 @@ import org.osgi.service.component.annotations.Component;
@Component(immediate = true)
public class TransformationActionService implements ActionService {
public TransformationActionService() {
}
@Override
public Class<?> getActionClass() {
return Transformation.class;
}
}
@@ -12,9 +12,12 @@
*/
package org.openhab.core.model.script.internal.engine.action;
import org.openhab.core.voice.VoiceManager;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.model.script.actions.Voice;
import org.openhab.core.model.script.engine.action.ActionService;
import org.openhab.core.voice.VoiceManager;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@@ -23,23 +26,19 @@ import org.osgi.service.component.annotations.Reference;
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
@Component(immediate = true)
public class VoiceActionService implements ActionService {
public static VoiceManager voiceManager;
public static @Nullable VoiceManager voiceManager;
@Activate
public VoiceActionService(final @Reference VoiceManager voiceManager) {
VoiceActionService.voiceManager = voiceManager;
}
@Override
public Class<?> getActionClass() {
return Voice.class;
}
@Reference
protected void setVoiceManager(VoiceManager voiceManager) {
VoiceActionService.voiceManager = voiceManager;
}
protected void unsetVoiceManager(VoiceManager voiceManager) {
VoiceActionService.voiceManager = null;
}
}
@@ -12,12 +12,14 @@
*/
package org.openhab.core.model.sitemap.runtime.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.model.core.ModelParser;
import org.openhab.core.model.sitemap.SitemapStandaloneSetup;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@NonNullByDefault
@Component(immediate = true)
public class SitemapRuntimeActivator implements ModelParser {
@@ -12,12 +12,14 @@
*/
package org.openhab.core.model.thing.runtime.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.model.core.ModelParser;
import org.openhab.core.model.thing.ThingStandaloneSetup;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@NonNullByDefault
@Component(immediate = true)
public class ThingRuntimeActivator implements ModelParser {
@@ -12,11 +12,15 @@
*/
package org.openhab.core.thing.type;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* Kind of the channel.
*
* @author Moritz Kammerer - Initial contribution
*/
@NonNullByDefault
public enum ChannelKind {
/**
* Channels which have a state.
@@ -34,7 +38,7 @@ public enum ChannelKind {
* @return the parsed ChannelKind.
* @throws IllegalArgumentException if the input couldn't be parsed.
*/
public static ChannelKind parse(String input) {
public static ChannelKind parse(@Nullable String input) {
if (input == null) {
return STATE;
}
@@ -14,6 +14,8 @@ package org.openhab.core.voice.internal.text;
import java.util.Locale;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.events.EventPublisher;
import org.openhab.core.items.ItemRegistry;
import org.openhab.core.library.types.HSBType;
@@ -28,7 +30,9 @@ import org.openhab.core.types.RefreshType;
import org.openhab.core.voice.text.AbstractRuleBasedInterpreter;
import org.openhab.core.voice.text.Expression;
import org.openhab.core.voice.text.HumanLanguageInterpreter;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
/**
@@ -38,9 +42,22 @@ import org.osgi.service.component.annotations.Reference;
* @author Kai Kreuzer - Added further German interpretation rules
* @author Laurent Garnier - Added French interpretation rules
*/
@NonNullByDefault
@Component(service = HumanLanguageInterpreter.class)
public class StandardInterpreter extends AbstractRuleBasedInterpreter {
@Activate
public StandardInterpreter(final @Reference EventPublisher eventPublisher,
final @Reference ItemRegistry itemRegistry) {
super(eventPublisher, itemRegistry);
}
@Override
@Deactivate
protected void deactivate() {
super.deactivate();
}
@Override
public void createRules() {
/****************************** ENGLISH ******************************/
@@ -308,29 +325,7 @@ public class StandardInterpreter extends AbstractRuleBasedInterpreter {
}
@Override
public String getLabel(Locale locale) {
public String getLabel(@Nullable Locale locale) {
return "Built-in Interpreter";
}
@Override
@Reference
public void setItemRegistry(ItemRegistry ItemRegistry) {
super.setItemRegistry(ItemRegistry);
}
@Override
public void unsetItemRegistry(ItemRegistry itemRegistry) {
super.unsetItemRegistry(itemRegistry);
}
@Override
@Reference
public void setEventPublisher(EventPublisher EventPublisher) {
super.setEventPublisher(EventPublisher);
}
@Override
public void unsetEventPublisher(EventPublisher eventPublisher) {
super.unsetEventPublisher(eventPublisher);
}
}
@@ -23,6 +23,8 @@ import java.util.Map.Entry;
import java.util.ResourceBundle;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.common.registry.RegistryChangeListener;
import org.openhab.core.events.EventPublisher;
import org.openhab.core.items.GroupItem;
@@ -42,6 +44,7 @@ import org.slf4j.LoggerFactory;
* @author Tilman Kamp - Initial contribution
* @author Kai Kreuzer - Improved error handling
*/
@NonNullByDefault
public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInterpreter {
private static final String JSGF = "JSGF";
@@ -64,12 +67,12 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
private Logger logger = LoggerFactory.getLogger(AbstractRuleBasedInterpreter.class);
private Map<Locale, List<Rule>> languageRules;
private Map<Locale, Set<String>> allItemTokens = null;
private Map<Locale, Map<Item, List<Set<String>>>> itemTokens = null;
private final Map<Locale, List<Rule>> languageRules = new HashMap<>();
private final Map<Locale, Set<String>> allItemTokens = new HashMap<>();
private final Map<Locale, Map<Item, List<Set<String>>>> itemTokens = new HashMap<>();
private ItemRegistry itemRegistry;
private EventPublisher eventPublisher;
private final ItemRegistry itemRegistry;
private final EventPublisher eventPublisher;
private RegistryChangeListener<Item> registryChangeListener = new RegistryChangeListener<Item>() {
@Override
@@ -88,6 +91,16 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
}
};
public AbstractRuleBasedInterpreter(final EventPublisher eventPublisher, final ItemRegistry itemRegistry) {
this.eventPublisher = eventPublisher;
this.itemRegistry = itemRegistry;
itemRegistry.addRegistryChangeListener(registryChangeListener);
}
protected void deactivate() {
itemRegistry.removeRegistryChangeListener(registryChangeListener);
}
/**
* Called whenever the rules are to be (re)generated and added by {@link addRules}
*/
@@ -97,7 +110,7 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
public String interpret(Locale locale, String text) throws InterpretationException {
ResourceBundle language = ResourceBundle.getBundle(LANGUAGE_SUPPORT, locale);
Rule[] rules = getRules(locale);
if (language == null || rules.length == 0) {
if (rules.length == 0) {
throw new InterpretationException(
locale.getDisplayLanguage(Locale.ENGLISH) + " is not supported at the moment.");
}
@@ -125,9 +138,9 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
}
private void invalidate() {
allItemTokens = null;
itemTokens = null;
languageRules = null;
allItemTokens.clear();
itemTokens.clear();
languageRules.clear();
}
/**
@@ -137,9 +150,6 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
* @return the identifier tokens
*/
Set<String> getAllItemTokens(Locale locale) {
if (allItemTokens == null) {
allItemTokens = new HashMap<>();
}
Set<String> localeTokens = allItemTokens.get(locale);
if (localeTokens == null) {
allItemTokens.put(locale, localeTokens = new HashSet<>());
@@ -160,9 +170,6 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
* @return the list of identifier token sets per item
*/
Map<Item, List<Set<String>>> getItemTokens(Locale locale) {
if (itemTokens == null) {
itemTokens = new HashMap<>();
}
Map<Item, List<Set<String>>> localeTokens = itemTokens.get(locale);
if (localeTokens == null) {
itemTokens.put(locale, localeTokens = new HashMap<>());
@@ -209,13 +216,12 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
* @param stopper Stop expression that, if matching, will stop this expression from consuming further tokens.
* @return Expression that represents a name of an item.
*/
protected Expression name(Expression stopper) {
protected Expression name(@Nullable Expression stopper) {
return tag(NAME, star(new ExpressionIdentifier(this, stopper)));
}
private Map<Locale, List<Rule>> getLanguageRules() {
if (languageRules == null) {
languageRules = new HashMap<>();
if (languageRules.isEmpty()) {
createRules();
}
return languageRules;
@@ -291,7 +297,7 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
* @param tailExpression The tail expression.
* @return The created rule.
*/
protected Rule itemRule(Object headExpression, Object tailExpression) {
protected Rule itemRule(Object headExpression, @Nullable Object tailExpression) {
Expression tail = exp(tailExpression);
Expression expression = tail == null ? seq(headExpression, name()) : seq(headExpression, name(tail), tail);
return new Rule(expression) {
@@ -309,7 +315,7 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
} else {
command = new StringType(cmdNode.getValueAsString());
}
if (name != null && command != null) {
if (name != null) {
try {
return new InterpretationResult(true, executeSingle(language, name, command));
} catch (InterpretationException ex) {
@@ -328,7 +334,7 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
* @param obj the object that's to be converted
* @return resulting expression
*/
protected Expression exp(Object obj) {
protected @Nullable Expression exp(@Nullable Object obj) {
if (obj instanceof Expression) {
return (Expression) obj;
} else {
@@ -385,7 +391,7 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
* @param tag the tag that's to be set
* @return resulting expression
*/
protected Expression tag(String name, Object expression, Object tag) {
protected Expression tag(@Nullable String name, Object expression, @Nullable Object tag) {
return new ExpressionLet(name, exp(expression), null, tag);
}
@@ -407,7 +413,7 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
* @param command the command that should be added
* @return resulting expression
*/
protected Expression cmd(Object expression, Command command) {
protected Expression cmd(Object expression, @Nullable Command command) {
return tag(CMD, expression, command);
}
@@ -499,7 +505,7 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
try {
State newState = (State) command;
State oldState = item.getStateAs(newState.getClass());
if (oldState.equals(newState)) {
if (newState.equals(oldState)) {
String template = language.getString(STATE_ALREADY_SINGULAR);
String cmdName = "state_" + command.toString().toLowerCase();
String stateText = null;
@@ -538,7 +544,8 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
* Provide {null} if there is no need for a certain command to be supported.
* @return All matching items from the item registry.
*/
protected List<Item> getMatchingItems(ResourceBundle language, String[] labelFragments, Class<?> commandType) {
protected List<Item> getMatchingItems(ResourceBundle language, String[] labelFragments,
@Nullable Class<?> commandType) {
List<Item> items = new ArrayList<>();
Map<Item, List<Set<String>>> map = getItemTokens(language.getLocale());
for (Item item : map.keySet()) {
@@ -583,18 +590,17 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
* @param text the text that should be tokenized
* @return resulting tokens
*/
protected List<String> tokenize(Locale locale, String text) {
final Locale localeSafe = locale != null ? locale : Locale.getDefault();
protected List<String> tokenize(Locale locale, @Nullable String text) {
List<String> parts = new ArrayList<>();
if (text == null) {
return parts;
}
String[] split;
if (Locale.FRENCH.getLanguage().equalsIgnoreCase(localeSafe.getLanguage())) {
split = text.toLowerCase(localeSafe).replaceAll("[\\']", " ").replaceAll("[^\\w\\sàâäçéèêëîïôùûü]", " ")
if (Locale.FRENCH.getLanguage().equalsIgnoreCase(locale.getLanguage())) {
split = text.toLowerCase(locale).replaceAll("[\\']", " ").replaceAll("[^\\w\\sàâäçéèêëîïôùûü]", " ")
.split("\\s");
} else {
split = text.toLowerCase(localeSafe).replaceAll("[\\']", "").replaceAll("[^\\w\\s]", " ").split("\\s");
split = text.toLowerCase(locale).replaceAll("[\\']", "").replaceAll("[^\\w\\s]", " ").split("\\s");
}
for (String s : split) {
String part = s.trim();
@@ -672,7 +678,7 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
return exp;
}
private void emit(Object obj) {
private void emit(@Nullable Object obj) {
builder.append(obj);
}
@@ -834,45 +840,16 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
for (Expression e : shared) {
emitDefinition(e);
}
String grammar = builder.toString();
return grammar;
return builder.toString();
}
}
@Override
public String getGrammar(Locale locale, String format) {
public @Nullable String getGrammar(Locale locale, String format) {
if (!JSGF.equals(format)) {
return null;
}
JSGFGenerator generator = new JSGFGenerator(ResourceBundle.getBundle(LANGUAGE_SUPPORT, locale));
return generator.getGrammar();
}
public void setItemRegistry(ItemRegistry itemRegistry) {
if (this.itemRegistry == null) {
this.itemRegistry = itemRegistry;
this.itemRegistry.addRegistryChangeListener(registryChangeListener);
}
}
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void unsetItemRegistry(ItemRegistry itemRegistry) {
if (itemRegistry == this.itemRegistry) {
this.itemRegistry.removeRegistryChangeListener(registryChangeListener);
this.itemRegistry = null;
}
}
public void setEventPublisher(EventPublisher eventPublisher) {
if (this.eventPublisher == null) {
this.eventPublisher = eventPublisher;
}
}
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void unsetEventPublisher(EventPublisher eventPublisher) {
if (eventPublisher == this.eventPublisher) {
this.eventPublisher = null;
}
}
}
@@ -15,11 +15,15 @@ package org.openhab.core.voice.text;
import java.util.Locale;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* This is the interface that a human language text interpreter has to implement.
*
* @author Tilman Kamp - Initial contribution
*/
@NonNullByDefault
public interface HumanLanguageInterpreter {
/**
@@ -35,7 +39,7 @@ public interface HumanLanguageInterpreter {
* @param locale the locale to provide the label for
* @return a localized string to be used in UIs
*/
public String getLabel(Locale locale);
public String getLabel(@Nullable Locale locale);
/**
* Interprets a human language text fragment of a given {@link Locale}
@@ -53,6 +57,7 @@ public interface HumanLanguageInterpreter {
* @param format the grammar format
* @return a grammar of the specified format
*/
@Nullable
String getGrammar(Locale locale, String format);
/**
@@ -12,11 +12,14 @@
*/
package org.openhab.core.voice.text;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* An exception used by {@link HumanLanguageInterpreter}s, if an error occurs.
*
* @author Tilman Kamp - Initial contribution
*/
@NonNullByDefault
public class InterpretationException extends Exception {
private static final long serialVersionUID = 76120119745036525L;
@@ -12,11 +12,15 @@
*/
package org.openhab.core.voice.text;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* Bundles results of an interpretation. Represents final outcome and user feedback. This class is immutable.
*
* @author Tilman Kamp - Initial contribution
*/
@NonNullByDefault
public final class InterpretationResult {
/**
@@ -35,8 +39,8 @@ public final class InterpretationResult {
public static final InterpretationResult SEMANTIC_ERROR = new InterpretationResult(false, "Semantic error.");
private boolean success = false;
private InterpretationException exception;
private String response;
private @Nullable InterpretationException exception;
private String response = "";
/**
* Constructs a successful result.
@@ -82,7 +86,7 @@ public final class InterpretationResult {
/**
* @return the exception
*/
public InterpretationException getException() {
public @Nullable InterpretationException getException() {
return exception;
}
@@ -14,12 +14,15 @@ package org.openhab.core.voice.text;
import java.util.ResourceBundle;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* Represents an expression plus action code that will be executed after successful parsing. This class is immutable and
* deriving classes should conform to this principle.
*
* @author Tilman Kamp - Initial contribution
*/
@NonNullByDefault
public abstract class Rule {
private Expression expression;
@@ -12,11 +12,14 @@
*/
package org.openhab.core.auth.client.oauth2;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* For all exceptions arising during oauth.
*
* @author Gary Tse - Initial contribution
*/
@NonNullByDefault
public class OAuthException extends Exception {
private static final long serialVersionUID = -2548612391437480321L;
@@ -12,6 +12,8 @@
*/
package org.openhab.core.auth.client.oauth2;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* This is an exception class for OAUTH specific errors. i.e. The error responses described in the
* RFC6749. Do NOT confuse this with Java errors.
@@ -29,6 +31,7 @@ package org.openhab.core.auth.client.oauth2;
* @see <a href="https://tools.ietf.org/html/rfc6749#section-4.1.2.1">rfc6749 section-4.1.2.1</a>
* @see <a href="https://tools.ietf.org/html/rfc6749#section-5.2">rfc6749 section-5.2</a>
*/
@NonNullByDefault
public class OAuthResponseException extends Exception {
private static final long serialVersionUID = -3268280125111194474L;
@@ -38,10 +41,10 @@ public class OAuthResponseException extends Exception {
* Must be one of { invalid_request, invalid_client, invalid_grant, unauthorized_client, unsupported_grant_type,
* invalid_scope, access_denied, unsupported_response_type, server_error, temporarily_unavailable }
*/
private String error;
private String errorDescription;
private String errorUri;
private String state;
private String error = "";
private String errorDescription = "";
private String errorUri = "";
private String state = "";
public String getError() {
return error;
@@ -12,11 +12,14 @@
*/
package org.openhab.core.internal.common;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* Denotes that there already is a thread occupied by the same context.
*
* @author Simon Kaufmann - Initial contribution
*/
@NonNullByDefault
class DuplicateExecutionException extends RuntimeException {
private static final long serialVersionUID = 1L;
@@ -12,12 +12,15 @@
*/
package org.openhab.core.items;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* This is an abstract parent exception to be extended by any exceptions
* related to item lookups in the item registry.
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
public abstract class ItemLookupException extends Exception {
public ItemLookupException(String string) {
@@ -12,12 +12,15 @@
*/
package org.openhab.core.items;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* This exception is thrown by the {@link ItemRegistry} if an item could
* not be found.
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
public class ItemNotFoundException extends ItemLookupException {
public ItemNotFoundException(String name) {
@@ -14,12 +14,15 @@ package org.openhab.core.items;
import java.util.Collection;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* This exception can be thrown whenever a search pattern does not uniquely identify
* an item. The list of matching items must be made available through this exception.
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
public class ItemNotUniqueException extends ItemLookupException {
private static final long serialVersionUID = 5154625234283910124L;
@@ -33,7 +36,7 @@ public class ItemNotUniqueException extends ItemLookupException {
/**
* Returns all items that match the search pattern
*
*
* @return collection of items matching the search pattern
*/
public Collection<Item> getMatchingItems() {
@@ -14,6 +14,8 @@ package org.openhab.core.model.thing.testsupport.hue;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
@@ -31,6 +33,7 @@ import org.osgi.service.component.ComponentContext;
*
* @author Simon Kaufmann - Initial contribution
*/
@NonNullByDefault
public class DumbThingHandlerFactory extends BaseThingHandlerFactory implements ThingHandlerFactory {
public static final String BINDING_ID = "dumb";
@@ -51,8 +54,8 @@ public class DumbThingHandlerFactory extends BaseThingHandlerFactory implements
}
@Override
public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID,
ThingUID bridgeUID) {
public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration,
@Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
if (dumb) {
return null;
} else {
@@ -69,7 +72,7 @@ public class DumbThingHandlerFactory extends BaseThingHandlerFactory implements
}
@Override
protected ThingHandler createHandler(Thing thing) {
protected @Nullable ThingHandler createHandler(Thing thing) {
return null;
}
@@ -19,6 +19,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.ThingTypeProvider;
import org.openhab.core.thing.type.ChannelDefinition;
@@ -34,6 +36,7 @@ import org.slf4j.LoggerFactory;
* @author Simon Kaufmann - Initial contribution
*/
@Component
@NonNullByDefault
public class DumbThingTypeProvider implements ThingTypeProvider {
private final Logger logger = LoggerFactory.getLogger(DumbThingTypeProvider.class);
@@ -56,12 +59,12 @@ public class DumbThingTypeProvider implements ThingTypeProvider {
}
@Override
public Collection<ThingType> getThingTypes(Locale locale) {
public Collection<ThingType> getThingTypes(@Nullable Locale locale) {
return THING_TYPES.values();
}
@Override
public ThingType getThingType(ThingTypeUID thingTypeUID, Locale locale) {
public @Nullable ThingType getThingType(ThingTypeUID thingTypeUID, @Nullable Locale locale) {
return THING_TYPES.get(thingTypeUID);
}
}
@@ -17,6 +17,8 @@ import java.util.Collection;
import java.util.List;
import java.util.Locale;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.library.CoreItemFactory;
import org.openhab.core.thing.type.ChannelDefinitionBuilder;
import org.openhab.core.thing.type.ChannelGroupType;
@@ -36,6 +38,7 @@ import org.osgi.service.component.annotations.Component;
* @author Dennis Nobel - Initial contribution
*/
@Component
@NonNullByDefault
public class TestHueChannelTypeProvider implements ChannelTypeProvider, ChannelGroupTypeProvider {
public static final ChannelTypeUID COLORX_TEMP_CHANNEL_TYPE_UID = new ChannelTypeUID("Xhue:Xcolor_temperature");
@@ -45,8 +48,8 @@ public class TestHueChannelTypeProvider implements ChannelTypeProvider, ChannelG
public static final ChannelGroupTypeUID GROUP_CHANNEL_GROUP_TYPE_UID = new ChannelGroupTypeUID("hue", "group");
private List<ChannelType> channelTypes;
private List<ChannelGroupType> channelGroupTypes;
private List<ChannelType> channelTypes = List.of();
private List<ChannelGroupType> channelGroupTypes = List.of();
public TestHueChannelTypeProvider() {
try {
@@ -84,12 +87,12 @@ public class TestHueChannelTypeProvider implements ChannelTypeProvider, ChannelG
}
@Override
public Collection<ChannelType> getChannelTypes(Locale locale) {
public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
return channelTypes;
}
@Override
public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale) {
public @Nullable ChannelType getChannelType(ChannelTypeUID channelTypeUID, @Nullable Locale locale) {
for (ChannelType channelType : channelTypes) {
if (channelType.getUID().equals(channelTypeUID)) {
return channelType;
@@ -99,7 +102,8 @@ public class TestHueChannelTypeProvider implements ChannelTypeProvider, ChannelG
}
@Override
public ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID, Locale locale) {
public @Nullable ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID,
@Nullable Locale locale) {
for (ChannelGroupType channelGroupType : channelGroupTypes) {
if (channelGroupType.getUID().equals(channelGroupTypeUID)) {
return channelGroupType;
@@ -109,7 +113,7 @@ public class TestHueChannelTypeProvider implements ChannelTypeProvider, ChannelG
}
@Override
public Collection<ChannelGroupType> getChannelGroupTypes(Locale locale) {
public Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
return channelGroupTypes;
}
}
@@ -17,6 +17,8 @@ import java.util.Collection;
import java.util.List;
import java.util.Locale;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.config.core.ConfigDescription;
import org.openhab.core.config.core.ConfigDescriptionBuilder;
import org.openhab.core.config.core.ConfigDescriptionParameter;
@@ -31,15 +33,16 @@ import org.osgi.service.component.annotations.Component;
* @author Wouter Born - Migrate tests from Groovy to Java
*/
@Component
@NonNullByDefault
public class TestHueConfigDescriptionProvider implements ConfigDescriptionProvider {
@Override
public Collection<ConfigDescription> getConfigDescriptions(Locale locale) {
public Collection<ConfigDescription> getConfigDescriptions(@Nullable Locale locale) {
return List.of();
}
@Override
public ConfigDescription getConfigDescription(URI uri, Locale locale) {
public @Nullable ConfigDescription getConfigDescription(URI uri, @Nullable Locale locale) {
if (uri.equals(URI.create("hue:LCT001:color"))) {
ConfigDescriptionParameter paramDefault = ConfigDescriptionParameterBuilder
.create("defaultConfig", Type.TEXT).withDefault("defaultValue").build();
@@ -50,11 +50,9 @@ public class TestHueThingHandlerFactory extends BaseThingHandlerFactory {
public static final ThingTypeUID THING_TYPE_LONG_NAME = new ThingTypeUID(BINDING_ID,
"1-thing-id-with-5-dashes_and_3_underscores");
public static final Set<ThingTypeUID> SUPPORTED_BRIDGE_TYPES = Stream.of(THING_TYPE_BRIDGE)
.collect(Collectors.toSet());
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Stream
.of(THING_TYPE_LCT001, THING_TYPE_SENSOR, THING_TYPE_TEST, THING_TYPE_LONG_NAME, THING_TYPE_GROUPED)
.collect(Collectors.toSet());
public static final Set<ThingTypeUID> SUPPORTED_BRIDGE_TYPES = Set.of(THING_TYPE_BRIDGE);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_LCT001, THING_TYPE_SENSOR,
THING_TYPE_TEST, THING_TYPE_LONG_NAME, THING_TYPE_GROUPED);
public static final Set<ThingTypeUID> SUPPORTED_TYPES = Stream
.concat(SUPPORTED_BRIDGE_TYPES.stream(), SUPPORTED_THING_TYPES.stream()).collect(Collectors.toSet());
@@ -16,6 +16,8 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
@@ -28,6 +30,7 @@ import org.osgi.service.component.ComponentContext;
/**
* @author Benedikt Niehues - Initial contribution
*/
@NonNullByDefault
public class TestHueThingHandlerFactoryX extends BaseThingHandlerFactory implements ThingHandlerFactory {
public static final String BINDING_ID = "Xhue";
@@ -36,10 +39,8 @@ public class TestHueThingHandlerFactoryX extends BaseThingHandlerFactory impleme
public static final ThingTypeUID THING_TYPE_LCT001 = new ThingTypeUID(BINDING_ID, "XLCT001");
public static final ThingTypeUID THING_TYPE_TEST = new ThingTypeUID(BINDING_ID, "XTEST");
public static final Set<ThingTypeUID> SUPPORTED_BRIDGE_TYPES = Stream.of(THING_TYPE_BRIDGE)
.collect(Collectors.toSet());
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Stream.of(THING_TYPE_LCT001, THING_TYPE_TEST)
.collect(Collectors.toSet());
public static final Set<ThingTypeUID> SUPPORTED_BRIDGE_TYPES = Set.of(THING_TYPE_BRIDGE);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_LCT001, THING_TYPE_TEST);
public static final Set<ThingTypeUID> SUPPORTED_TYPES = Stream
.concat(SUPPORTED_BRIDGE_TYPES.stream(), SUPPORTED_THING_TYPES.stream()).collect(Collectors.toSet());
@@ -61,8 +62,8 @@ public class TestHueThingHandlerFactoryX extends BaseThingHandlerFactory impleme
}
@Override
public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID,
ThingUID bridgeUID) {
public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration,
@Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
if (SUPPORTED_BRIDGE_TYPES.contains(thingTypeUID)) {
ThingUID hueBridgeUID = getBridgeThingUID(thingTypeUID, thingUID, configuration);
return super.createThing(thingTypeUID, configuration, hueBridgeUID, null);
@@ -79,7 +80,8 @@ public class TestHueThingHandlerFactoryX extends BaseThingHandlerFactory impleme
return SUPPORTED_TYPES.contains(thingTypeUID);
}
private ThingUID getBridgeThingUID(ThingTypeUID thingTypeUID, ThingUID thingUID, Configuration configuration) {
private ThingUID getBridgeThingUID(ThingTypeUID thingTypeUID, @Nullable ThingUID thingUID,
Configuration configuration) {
if (thingUID != null) {
return thingUID;
} else {
@@ -88,8 +90,8 @@ public class TestHueThingHandlerFactoryX extends BaseThingHandlerFactory impleme
}
}
private ThingUID getLightUID(ThingTypeUID thingTypeUID, ThingUID thingUID, Configuration configuration,
ThingUID bridgeUID) {
private ThingUID getLightUID(ThingTypeUID thingTypeUID, @Nullable ThingUID thingUID, Configuration configuration,
@Nullable ThingUID bridgeUID) {
if (thingUID != null) {
return thingUID;
} else {
@@ -99,7 +101,7 @@ public class TestHueThingHandlerFactoryX extends BaseThingHandlerFactory impleme
}
@Override
protected ThingHandler createHandler(Thing thing) {
protected @Nullable ThingHandler createHandler(Thing thing) {
return null;
}
@@ -21,6 +21,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.ThingTypeProvider;
import org.openhab.core.thing.type.ChannelDefinition;
@@ -36,6 +38,7 @@ import org.slf4j.LoggerFactory;
* @author Benedikt Niehues - Initial contribution
*/
@Component
@NonNullByDefault
public class TestHueThingTypeProvider implements ThingTypeProvider {
private final Logger logger = LoggerFactory.getLogger(TestHueThingTypeProvider.class);
@@ -87,12 +90,12 @@ public class TestHueThingTypeProvider implements ThingTypeProvider {
}
@Override
public Collection<ThingType> getThingTypes(Locale locale) {
public Collection<ThingType> getThingTypes(@Nullable Locale locale) {
return THING_TYPES.values();
}
@Override
public ThingType getThingType(ThingTypeUID thingTypeUID, Locale locale) {
public @Nullable ThingType getThingType(ThingTypeUID thingTypeUID, @Nullable Locale locale) {
return THING_TYPES.get(thingTypeUID);
}
}
@@ -15,6 +15,8 @@ package org.openhab.core.voice.internal;
import java.util.Locale;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.voice.text.HumanLanguageInterpreter;
import org.openhab.core.voice.text.InterpretationException;
@@ -27,6 +29,7 @@ import org.openhab.core.voice.text.InterpretationException;
*
* @author Velin Yordanov - migrated from groovy to java
*/
@NonNullByDefault
public class HumanLanguageInterpreterStub implements HumanLanguageInterpreter {
private static final String INTERPRETED_TEXT = "Interpreted text";
@@ -45,7 +48,7 @@ public class HumanLanguageInterpreterStub implements HumanLanguageInterpreter {
}
@Override
public String getLabel(Locale locale) {
public String getLabel(@Nullable Locale locale) {
return HLI_STUB_LABEL;
}
@@ -61,7 +64,7 @@ public class HumanLanguageInterpreterStub implements HumanLanguageInterpreter {
}
@Override
public String getGrammar(Locale locale, String format) {
public @Nullable String getGrammar(Locale locale, String format) {
// This method will not be used in the tests
return null;
}
@@ -69,13 +72,13 @@ public class HumanLanguageInterpreterStub implements HumanLanguageInterpreter {
@Override
public Set<Locale> getSupportedLocales() {
// This method will not be used in the tests
return null;
return Set.of();
}
@Override
public Set<String> getSupportedGrammarFormats() {
// This method will not be used in the tests
return null;
return Set.of();
}
public void setExceptionExpected(boolean exceptionExpected) {