Package com.google.protobuf
Class DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer
- java.lang.Object
-
- com.google.protobuf.DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer
-
- Enclosing class:
- DescriptorMessageInfoFactory
static class DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer extends java.lang.Object
A helper class to determine whether a message type needs to implementisInitialized()
.If a message type doesn't have any required fields or extensions (directly and transitively), it doesn't need to implement isInitialized() and can always return true there. It's a bit tricky to determine whether a type has transitive required fields because protobuf allows cycle references within the same .proto file (e.g., message Foo has a Bar field, and message Bar has a Foo field). For that we use Tarjan's strongly connected components algorithm to classify messages into strongly connected groups. Messages in the same group are transitively including each other, so they should either all have transitive required fields (or extensions), or none have.
This class is thread-safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer.Node
private static class
DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer.StronglyConnectedComponent
-
Field Summary
Fields Modifier and Type Field Description private int
index
private java.util.Map<Descriptors.Descriptor,DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer.Node>
nodeCache
private java.util.Map<Descriptors.Descriptor,java.lang.Boolean>
resultCache
private java.util.Stack<DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer.Node>
stack
-
Constructor Summary
Constructors Constructor Description IsInitializedCheckAnalyzer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
analyze(DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer.StronglyConnectedComponent component)
private DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer.Node
dfs(Descriptors.Descriptor descriptor)
boolean
needsIsInitializedCheck(Descriptors.Descriptor descriptor)
-
-
-
Field Detail
-
resultCache
private final java.util.Map<Descriptors.Descriptor,java.lang.Boolean> resultCache
-
index
private int index
-
stack
private final java.util.Stack<DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer.Node> stack
-
nodeCache
private final java.util.Map<Descriptors.Descriptor,DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer.Node> nodeCache
-
-
Method Detail
-
needsIsInitializedCheck
public boolean needsIsInitializedCheck(Descriptors.Descriptor descriptor)
-
dfs
private DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer.Node dfs(Descriptors.Descriptor descriptor)
-
analyze
private void analyze(DescriptorMessageInfoFactory.IsInitializedCheckAnalyzer.StronglyConnectedComponent component)
-
-