Skip to content

Commit

Permalink
Another Null Annotation update
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian S committed Dec 12, 2020
1 parent 069c00c commit 9fb6669
Show file tree
Hide file tree
Showing 34 changed files with 190 additions and 108 deletions.
1 change: 0 additions & 1 deletion .project
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
4 changes: 4 additions & 0 deletions annotations/java/lang/String.eea
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class java/lang/String
format
(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
(Ljava/lang/String;[Ljava/lang/Object;)L1java/lang/String;
4 changes: 4 additions & 0 deletions annotations/java/lang/reflect/Field.eea
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class java/lang/reflect/Field
getAnnotation
<T::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TT;>;)TT;
<T::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TT;>;)T0T;
6 changes: 6 additions & 0 deletions annotations/java/math/BigDecimal.eea
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
class java/math/BigDecimal
ZERO
Ljava/math/BigDecimal;
L1java/math/BigDecimal;
add
(Ljava/math/BigDecimal;)Ljava/math/BigDecimal;
(Ljava/math/BigDecimal;)L1java/math/BigDecimal;
setScale
(ILjava/math/RoundingMode;)Ljava/math/BigDecimal;
(ILjava/math/RoundingMode;)L1java/math/BigDecimal;
valueOf
(J)Ljava/math/BigDecimal;
(J)L1java/math/BigDecimal;
10 changes: 10 additions & 0 deletions annotations/java/util/Collections.eea
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class java/util/Collections
emptyMap
<K:Ljava/lang/Object;V:Ljava/lang/Object;>()Ljava/util/Map<TK;TV;>;
<K:Ljava/lang/Object;V:Ljava/lang/Object;>()L1java/util/Map<TK;TV;>;
unmodifiableCollection
<T:Ljava/lang/Object;>(Ljava/util/Collection<+TT;>;)Ljava/util/Collection<TT;>;
<T:Ljava/lang/Object;>(Ljava/util/Collection<+TT;>;)L1java/util/Collection<TT;>;
unmodifiableMap
<K:Ljava/lang/Object;V:Ljava/lang/Object;>(Ljava/util/Map<+TK;+TV;>;)Ljava/util/Map<TK;TV;>;
<K:Ljava/lang/Object;V:Ljava/lang/Object;>(Ljava/util/Map<+TK;+TV;>;)L1java/util/Map<TK;TV;>;
4 changes: 4 additions & 0 deletions annotations/java/util/Objects.eea
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class java/util/Objects
requireNonNull
<T:Ljava/lang/Object;>(TT;)TT;
<1T:Ljava/lang/Object;>(TT;)T1T;
33 changes: 21 additions & 12 deletions src/main/java/de/csdev/ebus/cfg/std/EBusConfigurationReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected void parseTemplateConfiguration(@NonNull EBusCollectionDTO collection)

for (EBusValueDTO value : templateValues) {
if (value != null) {
Collection<EBusCommandValue> pv = parseValueConfiguration(value, null, null, null);
Collection<@NonNull EBusCommandValue> pv = parseValueConfiguration(value, null, null, null);

if (pv != null && !pv.isEmpty()) {
blockList.addAll(pv);
Expand Down Expand Up @@ -250,6 +250,11 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
}
}

if (id == null) {
throw new EBusConfigurationReaderException("Property 'id' is missing for command ! {0}",
commandElement != null ? commandElement.toString() : "<NULL>");
}

EBusCommand cfg = new EBusCommand();
cfg.setId(id);
cfg.setLabel(label);
Expand Down Expand Up @@ -345,13 +350,14 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
* @return
* @throws EBusConfigurationReaderException
*/
protected Collection<EBusCommandValue> parseValueConfiguration(@NonNull EBusValueDTO valueDto,
@Nullable Map<String, EBusCommandValue> templateMap, @Nullable List<EBusCommandValue> templateList,
@Nullable EBusCommandMethod commandMethod) throws EBusConfigurationReaderException {
protected @NonNull Collection<@NonNull EBusCommandValue> parseValueConfiguration(@NonNull EBusValueDTO valueDto,
@Nullable Map<@NonNull String, @NonNull EBusCommandValue> templateMap,
@Nullable List<@NonNull EBusCommandValue> templateList, @Nullable EBusCommandMethod commandMethod)
throws EBusConfigurationReaderException {

Objects.requireNonNull(valueDto, "valueDto");

Collection<EBusCommandValue> result = new ArrayList<EBusCommandValue>();
Collection<@NonNull EBusCommandValue> result = new ArrayList<@NonNull EBusCommandValue>();
String typeStr = valueDto.getType();
String collectionId = null;

Expand All @@ -364,10 +370,11 @@ protected Collection<EBusCommandValue> parseValueConfiguration(@NonNull EBusValu
if (StringUtils.isEmpty(typeStr)) {
throw new EBusConfigurationReaderException("Property 'type' is missing for command ! {0}",
commandMethod != null ? commandMethod.getParent() : "<NULL>");
}

} else if (typeStr != null && typeStr.equals("template-block")) {
if (typeStr != null && typeStr.equals("template-block")) {

Collection<EBusCommandValue> templateCollection = null;
Collection<@NonNull EBusCommandValue> templateCollection = null;

if (StringUtils.isNotEmpty(valueDto.getName())) {
logger.warn("Property 'name' is not allowed for type 'template-block', ignore property !");
Expand Down Expand Up @@ -422,7 +429,7 @@ protected Collection<EBusCommandValue> parseValueConfiguration(@NonNull EBusValu

String id = (String) valueDto.getProperty("id");
String globalId = collectionId + "." + id;
Collection<EBusCommandValue> templateCollection = null;
Collection<@NonNull EBusCommandValue> templateCollection = null;

if (StringUtils.isEmpty(id)) {
throw new EBusConfigurationReaderException("No additional information for type 'template' defined!");
Expand All @@ -436,7 +443,7 @@ protected Collection<EBusCommandValue> parseValueConfiguration(@NonNull EBusValu

} else if (templateMap != null && templateMap.containsKey(id)) {
// return the complete template block from within command block
templateCollection = new ArrayList<EBusCommandValue>();
templateCollection = new ArrayList<@NonNull EBusCommandValue>();
templateCollection.add(templateMap.get(id));

} else {
Expand Down Expand Up @@ -529,7 +536,9 @@ protected Collection<EBusCommandValue> parseValueConfiguration(@NonNull EBusValu
ev.setMapping(valueDto.getMapping());
ev.setFormat(valueDto.getFormat());

ev.setParent(commandMethod);
if (commandMethod != null) {
ev.setParent(commandMethod);
}

result.add(ev);
return result;
Expand Down Expand Up @@ -615,11 +624,11 @@ public void clear() {
templateValueRegistry.clear();
}

public @NonNull Map<String, Collection<EBusCommandValue>> getTemplateValueRegistry() {
public @NonNull Map<@NonNull String, @Nullable Collection<@NonNull EBusCommandValue>> getTemplateValueRegistry() {
return templateValueRegistry;
}

public @NonNull Map<String, Collection<EBusCommandValue>> getTemplateBlockRegistry() {
public @NonNull Map<@NonNull String, @Nullable Collection<@NonNull EBusCommandValue>> getTemplateBlockRegistry() {
return templateBlockRegistry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public List<EBusValueDTO> deserialize(JsonElement jElement, Type typeOfT, JsonDe

ArrayList<String> fields = new ArrayList<String>();
for (Field field : EBusValueDTO.class.getDeclaredFields()) {

SerializedName annotation = field.getAnnotation(SerializedName.class);
if (annotation != null) {
fields.add(annotation.value());
Expand Down
53 changes: 33 additions & 20 deletions src/main/java/de/csdev/ebus/command/EBusCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Objects;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

import de.csdev.ebus.utils.CollectionUtils;
Expand All @@ -24,30 +25,31 @@
* @author Christian Sowada - Initial contribution
*
*/
@NonNullByDefault
public class EBusCommand implements IEBusCommand {

private @NonNull Map<IEBusCommandMethod.@NonNull Method, @Nullable IEBusCommandMethod> channels = new EnumMap<IEBusCommandMethod.@NonNull Method, @Nullable IEBusCommandMethod>(
private Map<IEBusCommandMethod.@NonNull Method, @NonNull IEBusCommandMethod> channels = new EnumMap<IEBusCommandMethod.@NonNull Method, @NonNull IEBusCommandMethod>(
IEBusCommandMethod.Method.class);

private String configurationSource;
private @Nullable String configurationSource;

private String device;
private @Nullable String device;

private String id;
private @Nullable String id;

private String label;
private @Nullable String label;

private IEBusCommandCollection parentCollection;
private @Nullable IEBusCommandCollection parentCollection;

private Map<String, Object> properties;
private @Nullable Map<String, Object> properties;

public void addCommandChannel(@NonNull IEBusCommandMethod channel) {
public void addCommandChannel(IEBusCommandMethod channel) {
Objects.requireNonNull(channel);
channels.put(channel.getMethod(), channel);
}

@Override
public @NonNull Collection<IEBusCommandMethod.Method> getCommandChannelMethods() {
public @NonNull Collection<IEBusCommandMethod.@NonNull Method> getCommandChannelMethods() {
return Objects.requireNonNull(Collections.unmodifiableCollection(channels.keySet()));
}

Expand All @@ -58,7 +60,7 @@ public void addCommandChannel(@NonNull IEBusCommandMethod channel) {
}

@Override
public @NonNull Collection<IEBusCommandMethod> getCommandMethods() {
public @NonNull Collection<@NonNull IEBusCommandMethod> getCommandMethods() {
return Objects.requireNonNull(Collections.unmodifiableCollection(channels.values()));
}

Expand All @@ -68,7 +70,7 @@ public void addCommandChannel(@NonNull IEBusCommandMethod channel) {
* @see de.csdev.ebus.command.IEBusCommand#getConfigurationSource()
*/
@Override
public String getConfigurationSource() {
public @Nullable String getConfigurationSource() {
return configurationSource;
}

Expand All @@ -78,7 +80,7 @@ public String getConfigurationSource() {
* @see de.csdev.ebus.command.IEBusCommand#getDevice()
*/
@Override
public String getDevice() {
public @Nullable String getDevice() {
return device;
}

Expand All @@ -98,49 +100,60 @@ public String getDevice() {
* @see de.csdev.ebus.command.IEBusCommand#getDescription()
*/
@Override
public String getLabel() {
public @Nullable String getLabel() {
return label;
}

@Override
public @NonNull IEBusCommandCollection getParentCollection() {
public IEBusCommandCollection getParentCollection() {
return Objects.requireNonNull(parentCollection);
}

@Override
public @NonNull Map<String, Object> getProperties() {
public Map<@NonNull String, @NonNull Object> getProperties() {
return Objects.requireNonNull(CollectionUtils.unmodifiableNotNullMap(properties));
}

public void setConfigurationSource(String configurationSource) {
public void setConfigurationSource(@Nullable String configurationSource) {
this.configurationSource = configurationSource;
}

public void setDevice(String device) {
public void setDevice(@Nullable String device) {
this.device = device;
}

public EBusCommand setId(String id) {
Objects.requireNonNull(id, "id");
this.id = id;
return this;
}

public void setLabel(String label) {
public void setLabel(@Nullable String label) {
this.label = label;
}

public void setParentCollection(IEBusCommandCollection parentCollection) {
Objects.requireNonNull(parentCollection, "parentCollection");
this.parentCollection = parentCollection;
}

public void setProperties(Map<String, Object> properties) {
Objects.requireNonNull(properties, "properties");
this.properties = new HashMap<String, Object>();
this.properties.putAll(properties);
}

public void setProperty(String key, String value) {
properties = CollectionUtils.newMapIfNull(properties);
properties.put(key, value);

Objects.requireNonNull(key, "key");
Objects.requireNonNull(value, "value");

this.properties = CollectionUtils.newMapIfNull(this.properties);

Map<String, Object> propertiesx = this.properties;
if (propertiesx != null) {
propertiesx.put(key, value);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public void addCommands(List<IEBusCommand> commands) {
*/
@Override
public @NonNull Collection<IEBusCommand> getCommands() {
return Objects.requireNonNull(Collections.unmodifiableCollection((commands.values())));
Collection<IEBusCommand> collection = Collections.unmodifiableCollection((commands.values()));
return Objects.requireNonNull(collection);
}

/*
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/de/csdev/ebus/command/EBusCommandMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public class EBusCommandMethod implements IEBusCommandMethod {

private Byte destinationAddress;

private List<IEBusValue> masterTypes;
private List<@NonNull IEBusValue> masterTypes;

private IEBusCommandMethod.@NonNull Method method;

private @NonNull IEBusCommand parent;

private List<IEBusValue> slaveTypes;
private List<@NonNull IEBusValue> slaveTypes;

private Byte sourceAddress;

Expand All @@ -60,7 +60,7 @@ public EBusCommandMethod(EBusCommand parent, IEBusCommandMethod.Method method) {
*/
public EBusCommandMethod addMasterValue(IEBusValue value) {
if (masterTypes == null) {
masterTypes = new ArrayList<IEBusValue>();
masterTypes = new ArrayList<@NonNull IEBusValue>();
}

if (value != null) {
Expand All @@ -77,7 +77,7 @@ public EBusCommandMethod addMasterValue(IEBusValue value) {
*/
public EBusCommandMethod addSlaveValue(IEBusValue value) {
if (slaveTypes == null) {
slaveTypes = new ArrayList<IEBusValue>();
slaveTypes = new ArrayList<@NonNull IEBusValue>();
}

if (value != null) {
Expand Down Expand Up @@ -129,7 +129,7 @@ public Byte getDestinationAddress() {
* @see de.csdev.ebus.command.IEBusCommand#getMasterTypes()
*/
@Override
public @Nullable List<IEBusValue> getMasterTypes() {
public @Nullable List<@NonNull IEBusValue> getMasterTypes() {
return masterTypes;
}

Expand Down Expand Up @@ -159,7 +159,7 @@ public Byte getDestinationAddress() {
* @see de.csdev.ebus.command.IEBusCommand#getSlaveTypes()
*/
@Override
public @Nullable List<IEBusValue> getSlaveTypes() {
public @Nullable List<@NonNull IEBusValue> getSlaveTypes() {
return slaveTypes;
}

Expand Down Expand Up @@ -196,11 +196,11 @@ public void setDestinationAddress(Byte destinationAddress) {
this.destinationAddress = destinationAddress;
}

public void setMasterTypes(List<IEBusValue> masterTypes) {
public void setMasterTypes(List<@NonNull IEBusValue> masterTypes) {
this.masterTypes = masterTypes;
}

public void setSlaveTypes(List<IEBusValue> slaveTypes) {
public void setSlaveTypes(List<@NonNull IEBusValue> slaveTypes) {
this.slaveTypes = slaveTypes;
}

Expand Down
Loading

0 comments on commit 9fb6669

Please sign in to comment.