11package org .variantsync .diffdetective .variation ;
22
3- import org .variantsync .diffdetective .variation .diff .DiffNode ; // For Javadoc
4- import org .variantsync .diffdetective .variation .tree .VariationNode ; // For Javadoc
3+ import org .variantsync .diffdetective .feature .AnnotationType ;
4+ import org .variantsync .diffdetective .variation .diff .DiffNode ;
5+ import org .variantsync .diffdetective .variation .tree .VariationNode ;
56
67/**
78 * The type of nodes of a {@link DiffNode} and a {@link VariationNode}.
@@ -39,11 +40,11 @@ public boolean isAnnotation() {
3940
4041 /**
4142 * Creates a NodeType from its value names.
42- *
43- * @see Enum#name()
43+ *
4444 * @param name a string that equals the name of one value of this enum (ignoring
4545 * case)
4646 * @return The NodeType that has the given name
47+ * @see Enum#name()
4748 */
4849 public static NodeType fromName (final String name ) {
4950 for (NodeType candidate : values ()) {
@@ -55,10 +56,37 @@ public static NodeType fromName(final String name) {
5556 throw new IllegalArgumentException ("Given string \" " + name + "\" is not the name of a NodeType." );
5657 }
5758
58- // TODO: fromAnnotationType constructor with switch case
59+ /**
60+ * Creates a NodeType from an AnnotationType.
61+ * <p>
62+ * All AnnotationType variants except for 'Endif' are supported.
63+ * There is no valid representation for 'Endif' annotations. Thus, the method throws an IllegalArgumentException
64+ * if it is given an 'Endif'.
65+ * </p>
66+ *
67+ * @param annotationType a variant of AnnotationType
68+ * @return The NodeType that fits the given AnnotationType
69+ */
70+ public static NodeType fromAnnotationType (final AnnotationType annotationType ) {
71+ switch (annotationType ) {
72+ case If -> {
73+ return NodeType .IF ;
74+ }
75+ case Elif -> {
76+ return NodeType .ELIF ;
77+ }
78+ case Else -> {
79+ return NodeType .ELSE ;
80+ }
81+ case None -> {
82+ return NodeType .ARTIFACT ;
83+ }
84+ default -> throw new IllegalArgumentException (annotationType + "has no NodeType counterpart" );
85+ }
86+ }
5987
6088 /**
61- * Returns the number of bits required for storing {@link ordinal} .
89+ * Returns the number of bits required for storing.
6290 */
6391 public static int getRequiredBitCount () {
6492 return 3 ;
0 commit comments