public interface TypeGraphCreationStrategy
Title: Framework Support Library
Description: Defines a strategy used during creation of a type graph (see TypeGraph
).
Copyright: Copyright (c) 2011
Company: StreamScape Technologies
Modifier and Type | Method and Description |
---|---|
TypeGraph |
getGraphNode(TypeGraph node)
Processes the potential
node of the created
TypeGraph and returns it (or creates and returns another node
if necessary) for adding to this TypeGraph . |
boolean |
shouldIncludeParentTypes()
Specifies if the analyzer should include parent types of the analyzed type as separate nodes to the result graph.
|
boolean |
shouldSkipChildren(TypeGraph node)
Returns true if the specified node should be a leaf node in the created type graph and its
children should not be created.
|
TypeGraph getGraphNode(TypeGraph node) throws TypeAnalyzerException
node
of the created
TypeGraph
and returns it (or creates and returns another node
if necessary) for adding to this TypeGraph
.
If the node
should be skipped the function returns null.
For example to skip all the static fields of the type for which the
TypeGraph
is created the strategy should be the following:
class AbstractSkipStaticFieldsStrategy implements TypeGraphCreationStrategy { public TypeGraph getGraphNode(TypeGraph node) { if (Modifier.isStatic(node.getModifiers())) return null; return node; } public boolean shouldSkipChildren(TypeGraph node) { return false; } }Another example is the strategy which renames all the "value" fields of
Map
types to "map-value":
class RenameMapValueStrategy implements TypeGraphCreationStrategy { public TypeGraph getGraphNode(TypeGraph node) { if (! node.getName().equals("value")) return node; TypeGraph parent = node.getParent(); if ((parent == null) || (! (parent.getType() instanceof ParameterizedType))) return node; Class> cls = (Class>)((ParameterizedType)parent.getType()).getRawType(); if (Map.class.isAssignableFrom(cls)) node.setName("map-value"); return node; } public boolean shouldSkipChildren(TypeGraph node) { return false; } }
node
- The potential node to be added to the created
TypeGraph
after processing by this strategy.TypeGraph
or null
if no node should be added.TypeAnalyzerException
- In case of an error occurred during the graph node processingboolean shouldSkipChildren(TypeGraph node) throws TypeAnalyzerException
String, String[], byte[], ..., double[]
types are not parsed deeper and
created as the graph leaves.
class DontParseIntoPrimitivesStrategy implements TypeGraphCreationStrategy { public TypeGraph getGraphNode(TypeGraph node) { return node; } public boolean shouldSkipChildren(TypeGraph node) { Class> cls = TypeAnalyzer.getRawClass(node.getType()); while (cls.isArray()) cls = cls.getComponentType(); return (cls.isPrimitive() || (cls == String.class)); } }
node
- The node which children can be skippedTypeAnalyzerException
- In case of an error occurred during the graph node processingboolean shouldIncludeParentTypes()
true
if the parent types should be included to the result graph, false
otherwise.Copyright © 2015-2024 StreamScape Technologies. All rights reserved.