Static factory method ordering
MODIFY
docs/contributing/style-guideline.md
docs/contributing/style-guideline.md
@@ -66,3 +66,21 @@ rough guideline of what are commonly accepted static imports:
* Immutable constants (where clearly named)
* Singleton instances (especially where clearly named an hopefully immutable)
* `tracer()` methods that expose tracer singleton instances
+
+### Ordering of class contents
+
+The following order is preferred:
+
+* Static fields (final before non-final)
+* Instance fields (final before non-final)
+* Static construction methods (includes static factory methods and builder construction methods)
+* Constructors
+* Methods
+* Nested classes
+
+If methods call each other, it's nice if the calling method is ordered (somewhere) above
+the method that it calls. So, for one example, a private method would be ordered (somewhere) below
+the non-private methods that use it.
+
+In static utility classes (where all members are static), the private constructor
+(used to prevent construction) should be ordered after methods instead of before methods.

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/Config.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/Config.java
@@ -25,6 +25,10 @@ public abstract class Config {
// read system properties
@Nullable private static volatile Config instance = null;
+ public static Config create(Map<String, String> allProperties) {
+ return new AutoValue_Config(allProperties);
+ }
+
/**
* Sets the agent configuration singleton. This method is only supposed to be called once, from
* the agent classloader just before the first instrumentation is loaded (and before {@link
@@ -48,10 +52,6 @@ public abstract class Config {
return instance;
}
- public static Config create(Map<String, String> allProperties) {
- return new AutoValue_Config(allProperties);
- }
-
abstract Map<String, String> getAllProperties();
/**

MODIFY
instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraRequest.java
instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraRequest.java
@@ -11,11 +11,11 @@ import com.google.auto.value.AutoValue;
@AutoValue
public abstract class CassandraRequest {
- public abstract Session getSession();
-
- public abstract String getStatement();
-
public static CassandraRequest create(Session session, String statement) {
return new AutoValue_CassandraRequest(session, statement);
}
+
+ public abstract Session getSession();
+
+ public abstract String getStatement();
}

MODIFY
instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraRequest.java
instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraRequest.java
@@ -11,11 +11,11 @@ import com.google.auto.value.AutoValue;
@AutoValue
public abstract class CassandraRequest {
- public abstract Session getSession();
-
- public abstract String getStatement();
-
public static CassandraRequest create(Session session, String statement) {
return new AutoValue_CassandraRequest(session, statement);
}
+
+ public abstract Session getSession();
+
+ public abstract String getStatement();
}

MODIFY
instrumentation/geode-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/geode/GeodeRequest.java
instrumentation/geode-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/geode/GeodeRequest.java
@@ -12,14 +12,14 @@ import org.checkerframework.checker.nullness.qual.Nullable;
@AutoValue
public abstract class GeodeRequest {
+ public static GeodeRequest create(Region<?, ?> region, String operation, @Nullable String query) {
+ return new AutoValue_GeodeRequest(region, operation, query);
+ }
+
public abstract Region<?, ?> getRegion();
public abstract String getOperation();
@Nullable
public abstract String getQuery();
-
- public static GeodeRequest create(Region<?, ?> region, String operation, @Nullable String query) {
- return new AutoValue_GeodeRequest(region, operation, query);
- }
}

MODIFY
instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/DbRequest.java
instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/DbRequest.java
@@ -16,10 +16,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
@AutoValue
public abstract class DbRequest {
- public abstract DbInfo getDbInfo();
-
- @Nullable
- public abstract String getStatement();
@Nullable
public static DbRequest create(PreparedStatement statement) {
@@ -39,4 +35,9 @@ public abstract class DbRequest {
public static DbRequest create(DbInfo dbInfo, String statement) {
return new AutoValue_DbRequest(dbInfo, statement);
}
+
+ public abstract DbInfo getDbInfo();
+
+ @Nullable
+ public abstract String getStatement();
}

MODIFY
instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisRequest.java
instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisRequest.java
@@ -15,12 +15,6 @@ import redis.clients.jedis.Protocol;
@AutoValue
public abstract class JedisRequest {
- public abstract Connection getConnection();
-
- public abstract Protocol.Command getCommand();
-
- public abstract List<byte[]> getArgs();
-
public static JedisRequest create(Connection connection, Protocol.Command command) {
return new AutoValue_JedisRequest(connection, command, emptyList());
}
@@ -29,4 +23,10 @@ public abstract class JedisRequest {
Connection connection, Protocol.Command command, List<byte[]> args) {
return new AutoValue_JedisRequest(connection, command, args);
}
+
+ public abstract Connection getConnection();
+
+ public abstract Protocol.Command getCommand();
+
+ public abstract List<byte[]> getArgs();
}

MODIFY
instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisRequest.java
instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisRequest.java
@@ -16,6 +16,11 @@ import redis.clients.jedis.commands.ProtocolCommand;
@AutoValue
public abstract class JedisRequest {
+ public static JedisRequest create(
+ Connection connection, ProtocolCommand command, List<byte[]> args) {
+ return new AutoValue_JedisRequest(connection, command, args);
+ }
+
public abstract Connection getConnection();
public abstract ProtocolCommand getCommand();
@@ -36,9 +41,4 @@ public abstract class JedisRequest {
public String getStatement() {
return RedisCommandSanitizer.sanitize(getOperation(), getArgs());
}
-
- public static JedisRequest create(
- Connection connection, ProtocolCommand command, List<byte[]> args) {
- return new AutoValue_JedisRequest(connection, command, args);
- }
}

Static factory method ordering (#3206)