Skip to content

Commit

Permalink
Update project to use JSpecify (#1356)
Browse files Browse the repository at this point in the history
Signed-off-by: system24seven <david@system24seven.com>
Co-authored-by: Kevin Herron <kevinherron@gmail.com>
  • Loading branch information
system24seven and kevinherron authored Dec 31, 2024
1 parent a6a92fd commit e75a4c8
Show file tree
Hide file tree
Showing 413 changed files with 891 additions and 957 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/google-java-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4.6.0
with:
distribution: "temurin"
java-version: 17
- uses: axel-op/googlejavaformat-action@v3.6.0
with:
args: "--set-exit-if-changed"
6 changes: 0 additions & 6 deletions milo-examples/client-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>${jetbrains-annotations.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>


Expand Down
6 changes: 0 additions & 6 deletions milo-examples/server-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>${jetbrains-annotations.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.eclipse.milo.opcua.stack.core.encoding.UaEncoder;
import org.eclipse.milo.opcua.stack.core.types.UaEnumeratedType;
import org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public enum CustomEnumType implements UaEnumeratedType {
Field0(0),
Expand Down
5 changes: 0 additions & 5 deletions opc-ua-sdk/codec-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@
<artifactId>milo-encoding-json</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>${jetbrains-annotations.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@
import org.eclipse.milo.opcua.stack.core.types.structured.DataTypeDefinition;
import org.eclipse.milo.opcua.stack.core.types.structured.EnumDefinition;
import org.eclipse.milo.opcua.stack.core.types.structured.StructureDefinition;
import org.jspecify.annotations.NullMarked;

@NullMarked
public class JsonCodecFactory {

public static DataTypeCodec create(DataType dataType, DataTypeTree dataTypeTree) {
DataTypeDefinition definition = dataType.getDataTypeDefinition();

if (definition instanceof EnumDefinition) {
// If we're asked to create a DataTypeCodec and the definition is an EnumDefinition,
// that means it's an OptionSet subclass. True enumerations are encoded/decoded as
// integers, so they don't have a corresponding codec.
/* If we're asked to create a DataTypeCodec and the definition is an EnumDefinition,
* that means it's an OptionSet subclass. True enumerations are encoded/decoded as
* integers, so they don't have a corresponding codec.
*/
return new JsonOptionSetCodec(dataType);
} else if (definition instanceof StructureDefinition) {
return new JsonStructCodec(dataType, dataTypeTree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.ULong;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort;
import org.eclipse.milo.opcua.stack.core.util.ArrayUtil;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
public class JsonConversions {

// region OPC UA to JSON Conversions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureDefinition;
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.Lazy;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
public class JsonStructCodec extends GenericDataTypeCodec<JsonStruct> {

private final Lazy<Map<StructureField, Object>> hints = new Lazy<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public abstract class AbstractTestType extends Structure implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3003");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class ConcreteTestType extends AbstractTestType implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3006");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class ConcreteTestTypeEx extends ConcreteTestType implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3009");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithAbstractArrayFields extends Structure implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3005");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithAbstractMatrixFields extends Structure implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3022");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithBuiltinArrayFields extends Structure implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3019");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.XVType;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithBuiltinArrayFieldsEx extends StructWithBuiltinArrayFields
implements UaStructuredType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithBuiltinMatrixFields extends Structure implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3010");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.XVType;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithBuiltinMatrixFieldsEx extends StructWithBuiltinMatrixFields
implements UaStructuredType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithBuiltinScalarFields extends Structure implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3004");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.XVType;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithBuiltinScalarFieldsEx extends StructWithBuiltinScalarFields
implements UaStructuredType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithOptionalArrayFields extends Structure implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3007");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithOptionalMatrixFields extends Structure implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3035");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithOptionalScalarFields extends Structure implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3016");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithStructureArrayFields extends Structure implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3029");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.StructureField;
import org.eclipse.milo.opcua.stack.core.util.codegen.EqualsBuilder;
import org.eclipse.milo.opcua.stack.core.util.codegen.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public class StructWithStructureMatrixFields extends Structure implements UaStructuredType {
public static final ExpandedNodeId TYPE_ID = ExpandedNodeId.parse("ns=1;i=3032");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
import org.eclipse.milo.opcua.stack.core.types.structured.EnumDefinition;
import org.eclipse.milo.opcua.stack.core.types.structured.EnumField;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public enum TestEnumType implements UaEnumeratedType {
A(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName;
import org.eclipse.milo.opcua.stack.core.types.structured.DataTypeDefinition;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

public abstract class AbstractDataType implements DataType {

Expand Down
12 changes: 5 additions & 7 deletions opc-ua-sdk/dtd-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,17 @@
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>${jetbrains-annotations.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.ULong;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort;
import org.eclipse.milo.opcua.stack.core.util.Namespaces;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;
import org.opcfoundation.opcua.binaryschema.EnumeratedType;
import org.opcfoundation.opcua.binaryschema.FieldType;
import org.opcfoundation.opcua.binaryschema.StructuredType;
Expand Down Expand Up @@ -435,23 +435,17 @@ private boolean fieldIsAbsent(FieldType field, Map<String, MemberT> members) {

private static boolean compareToSwitchValue(
long controlValue, SwitchOperand switchOperand, long switchValue) {
switch (switchOperand) {
case EQUALS:
return controlValue == switchValue;
case NOT_EQUAL:
return controlValue != switchValue;
case GREATER_THAN:
return controlValue > switchValue;
case GREATER_THAN_OR_EQUAL:
return controlValue >= switchValue;
case LESS_THAN:
return controlValue < switchValue;
case LESS_THAN_OR_EQUAL:
return controlValue <= switchValue;
default:
throw new UaSerializationException(
StatusCodes.Bad_InternalError, "unknown SwitchOperand: " + switchOperand);
}
return switch (switchOperand) {
case EQUALS -> controlValue == switchValue;
case NOT_EQUAL -> controlValue != switchValue;
case GREATER_THAN -> controlValue > switchValue;
case GREATER_THAN_OR_EQUAL -> controlValue >= switchValue;
case LESS_THAN -> controlValue < switchValue;
case LESS_THAN_OR_EQUAL -> controlValue <= switchValue;
default ->
throw new UaSerializationException(
StatusCodes.Bad_InternalError, "unknown SwitchOperand: " + switchOperand);
};
}

private static boolean fieldIsScalar(FieldType field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

package org.eclipse.milo.opcua.sdk.core.dtd;

import com.sun.istack.Nullable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.milo.opcua.stack.core.encoding.DataTypeCodec;
import org.eclipse.milo.opcua.stack.core.types.DataTypeDictionary;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.jspecify.annotations.Nullable;
import org.opcfoundation.opcua.binaryschema.TypeDescription;
import org.opcfoundation.opcua.binaryschema.TypeDictionary;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

public class Struct {

private final String name;
private final Map<String, Member> members;

public Struct(@NotNull String name, @NotNull Map<String, Member> members) {
public Struct(@NonNull String name, @NonNull Map<String, Member> members) {
Preconditions.checkNotNull(name);
Preconditions.checkNotNull(members);

this.name = name;
this.members = Map.copyOf(members);
}

@NotNull
@NonNull
public String getName() {
return name;
}

@NotNull
@NonNull
public Map<String, Member> getMembers() {
return members;
}
Expand All @@ -49,7 +49,7 @@ public Member getMember(String name) {
return members.get(name);
}

@NotNull
@NonNull
public Optional<Member> getMemberSafe(String name) {
return Optional.ofNullable(members.get(name));
}
Expand Down
Loading

0 comments on commit e75a4c8

Please sign in to comment.