@Test public void generateWithoutValues() throws SingleFileGeneratorException { EnumGenerator generator = new EnumGenerator(); String source = generator.generate(TestEnum.class).getSource(); assertThat(source, containsString("stjs.enumeration")); assertThat(source, containsString("'FIRST'")); assertThat(source, containsString("'SECOND'")); assertThat(source, containsString("'THIRD'")); }
@Test public void generateWithValues() throws SingleFileGeneratorException { EnumGenerator generator = new EnumGenerator(); String source = generator.generate(TestEnumWithValues.class).getSource(); assertThat(source, containsString("return 'Test'")); assertThat(source, containsString("return 'Bla'")); assertThat(source, containsString("return 42")); assertThat(source, containsString("return 17")); assertThat(source, containsString("return true")); assertThat(source, containsString("return false")); }
public void handleNode(MibNode aNode) throws IOException { // Check if the node is a nested group or not. A nested group // has some children but is not a associated. if (aNode.isGroup() || aNode.hasNestedGroups()) { // The node is a nested group ! // handleNestedGroups(aNode); return; } // Check if the node is a table or not. A table has some children // but is not a group. if (aNode.isTable()) { // The node is a table ! // handleTable(aNode); return; } // Name of the symbol // String varName = aNode.getSymbolName(); // Get the object definition associated to the node // ASTObjectTypeDefinition definition = aNode.getObjectType(); if (definition == null) return; // get the syntax ... // ASTNamedType syntax = definition.getSyntax(); String strSyntax = ""; // Get the default MIB variable value // ASTValue defValue = definition.getDefValue(); String init = ""; if (syntax.isEnumeratedType()) { // get the access mode of the node // EnumGenerator enumgen = new EnumGenerator(manager, varName, syntax.getEnumeratedDef(), context); strSyntax = enumgen.getTypeName(); // Now get the SNMP syntax in order to get a valid init value ... // - if a default value is defined, just take it // - otherwise, get a valid init value defined in the syntax mapper // // There is a default value for this variable. // if (defValue != null) { init = defValue.getDefValInitializer(strSyntax, syntax, varName); } // There is no default value for this variable or the default value cannot be resolved. // if ((defValue == null) || (init.equals(""))) { init = " = new " + strSyntax.trim() + "()"; } aNode.setEnumerated(true); aNode.setEnumeratedType(strSyntax); } else { // Get the real syntax to use for the node // strSyntax = syntax.getMbeanSyntax(); // Now get the SNMP syntax in order to get a valid init value ... // - if a default value is defined, just take it // - otherwise, get a valid init value defined in the syntax mapper // // There is a default value for this variable. // if (defValue != null) { init = defValue.getDefValInitializer(strSyntax, syntax, varName); } // There is no default value for this variable or the default value cannot be resolved. // if ((defValue == null) || (init.equals(""))) { init = SyntaxMapper.getInitializer(syntax.getSnmpSyntax()); } } // Add a Java variable for representing the snmp variable ... // long length = syntax.getFixedLength(); aNode.setFixedLength(length); addCacheVar(aNode, strSyntax, length, init, varName); // Generate getter and setter // addAccessors(aNode, strSyntax, varName); }