List of usage examples for org.eclipse.jdt.core.dom EnumDeclaration enumConstants
ASTNode.NodeList enumConstants
To view the source code for org.eclipse.jdt.core.dom EnumDeclaration enumConstants.
Click Source Link
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(EnumDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }/*from ww w . j a v a 2 s . c om*/ printModifiers(node.modifiers()); this.fBuffer.append("enum ");//$NON-NLS-1$ node.getName().accept(this); this.fBuffer.append(" ");//$NON-NLS-1$ if (!node.superInterfaceTypes().isEmpty()) { this.fBuffer.append("implements ");//$NON-NLS-1$ for (Iterator<Type> it = node.superInterfaceTypes().iterator(); it.hasNext();) { Type t = it.next(); t.accept(this); if (it.hasNext()) { this.fBuffer.append(", ");//$NON-NLS-1$ } } this.fBuffer.append(" ");//$NON-NLS-1$ } this.fBuffer.append("{");//$NON-NLS-1$ for (Iterator<EnumConstantDeclaration> it = node.enumConstants().iterator(); it.hasNext();) { EnumConstantDeclaration d = it.next(); d.accept(this); // enum constant declarations do not include punctuation if (it.hasNext()) { // enum constant declarations are separated by commas this.fBuffer.append(", ");//$NON-NLS-1$ } } if (!node.bodyDeclarations().isEmpty()) { this.fBuffer.append("; ");//$NON-NLS-1$ for (Iterator<BodyDeclaration> it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration d = it.next(); d.accept(this); // other body declarations include trailing punctuation } } this.fBuffer.append("}");//$NON-NLS-1$ return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(EnumDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }/*w ww. j av a2 s . com*/ printIndent(); printModifiers(node.modifiers()); this.buffer.append("enum ");//$NON-NLS-1$ node.getName().accept(this); this.buffer.append(" ");//$NON-NLS-1$ if (!node.superInterfaceTypes().isEmpty()) { this.buffer.append("implements ");//$NON-NLS-1$ for (Iterator it = node.superInterfaceTypes().iterator(); it.hasNext();) { Type t = (Type) it.next(); t.accept(this); if (it.hasNext()) { this.buffer.append(", ");//$NON-NLS-1$ } } this.buffer.append(" ");//$NON-NLS-1$ } this.buffer.append("{");//$NON-NLS-1$ for (Iterator it = node.enumConstants().iterator(); it.hasNext();) { EnumConstantDeclaration d = (EnumConstantDeclaration) it.next(); d.accept(this); // enum constant declarations do not include punctuation if (it.hasNext()) { // enum constant declarations are separated by commas this.buffer.append(", ");//$NON-NLS-1$ } } if (!node.bodyDeclarations().isEmpty()) { this.buffer.append("; ");//$NON-NLS-1$ for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration d = (BodyDeclaration) it.next(); d.accept(this); // other body declarations include trailing punctuation } } this.buffer.append("}\n");//$NON-NLS-1$ return false; }
From source file:com.bsiag.eclipse.jdt.java.formatter.LineBreaksPreparator.java
License:Open Source License
@Override public boolean visit(EnumDeclaration node) { handleBracedCode(node, node.getName(), this.options.brace_position_for_enum_declaration, this.options.indent_body_declarations_compare_to_enum_declaration_header, this.options.insert_new_line_in_empty_enum_declaration); handleBodyDeclarations(node.bodyDeclarations()); List<EnumConstantDeclaration> enumConstants = node.enumConstants(); for (int i = 0; i < enumConstants.size(); i++) { EnumConstantDeclaration declaration = enumConstants.get(i); if (declaration.getJavadoc() != null) this.tm.firstTokenIn(declaration, TokenNameCOMMENT_JAVADOC).breakBefore(); if (declaration.getAnonymousClassDeclaration() != null && i < enumConstants.size() - 1) this.tm.firstTokenAfter(declaration, TokenNameCOMMA).breakAfter(); }//w ww. ja v a2 s. co m // put breaks after semicolons int index = enumConstants.isEmpty() ? this.tm.firstIndexAfter(node.getName(), TokenNameLBRACE) + 1 : this.tm.firstIndexAfter(enumConstants.get(enumConstants.size() - 1), -1); for (;; index++) { Token token = this.tm.get(index); if (token.isComment()) continue; if (token.tokenType == TokenNameSEMICOLON) token.breakAfter(); else break; } this.declarationModifierVisited = false; return true; }
From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java
License:Open Source License
@Override public boolean visit(EnumDeclaration node) { List<EnumConstantDeclaration> enumConstants = node.enumConstants(); if (!enumConstants.isEmpty()) { for (EnumConstantDeclaration constant : enumConstants) this.wrapIndexes.add(this.tm.firstIndexIn(constant, -1)); this.wrapParentIndex = this.tm.firstIndexBefore(enumConstants.get(0), TokenNameLBRACE); this.wrapGroupEnd = this.tm.lastIndexIn(enumConstants.get(enumConstants.size() - 1), -1); handleWrap(this.options.alignment_for_enum_constants, node); }//from w w w . j a v a2s.c o m List<Type> superInterfaceTypes = node.superInterfaceTypes(); if (!superInterfaceTypes.isEmpty()) { this.wrapIndexes.add(this.tm.firstIndexBefore(superInterfaceTypes.get(0), TokenNameimplements)); for (Type type : superInterfaceTypes) this.wrapIndexes.add(this.tm.firstIndexIn(type, -1)); this.wrapParentIndex = this.tm.lastIndexIn(node.getName(), -1); this.wrapGroupEnd = this.tm.lastIndexIn(superInterfaceTypes.get(superInterfaceTypes.size() - 1), -1); this.wrapPenalties.add(PREFERRED); handleWrap(this.options.alignment_for_superinterfaces_in_enum_declaration, node); } if (this.options.align_type_members_on_columns) this.fieldAligner.prepareAlign(node.bodyDeclarations()); return true; }
From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java
License:Open Source License
@Override public boolean visit(EnumDeclaration node) { handleToken(node.getName(), TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_enum_declaration, false); handleCommas(node.enumConstants(), this.options.insert_space_before_comma_in_enum_declarations, this.options.insert_space_after_comma_in_enum_declarations); return true;//ww w.ja v a 2 s . co m }
From source file:com.ecfeed.ui.common.EclipseModelImplementer.java
License:Open Source License
@SuppressWarnings("unchecked") private void addEnumItems(CompilationUnit unit, String typeName, List<ChoiceNode> nodes, IType enumType) throws CoreException { EnumDeclaration enumDeclaration = getEnumDeclaration(unit, typeName); if (enumDeclaration == null) { return;//from www. j a v a 2 s .com } List<String> enumItemNames = new ArrayList<String>(); for (ChoiceNode node : nodes) { EnumConstantDeclaration constant = unit.getAST().newEnumConstantDeclaration(); String enumItemName = node.getValueString(); if (enumItemNames.contains(enumItemName)) { continue; } constant.setName(unit.getAST().newSimpleName(enumItemName)); enumDeclaration.enumConstants().add(constant); enumItemNames.add(enumItemName); } saveChanges(unit, enumType.getResource().getLocation()); }
From source file:com.github.parzonka.ccms.engine.SortElementsOperation.java
License:Open Source License
private ASTRewrite sortCompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit ast, final TextEditGroup group) { ast.accept(new ASTVisitor() { @Override//ww w. jav a 2 s.c o m public boolean visit(org.eclipse.jdt.core.dom.CompilationUnit compilationUnit) { final List<AbstractTypeDeclaration> types = compilationUnit.types(); for (final Iterator<AbstractTypeDeclaration> iter = types.iterator(); iter.hasNext();) { final AbstractTypeDeclaration typeDeclaration = iter.next(); typeDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(typeDeclaration.getStartPosition())); compilationUnit.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(typeDeclaration))); } return true; } @Override public boolean visit(AnnotationTypeDeclaration annotationTypeDeclaration) { final List bodyDeclarations = annotationTypeDeclaration.bodyDeclarations(); for (final Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) { final BodyDeclaration bodyDeclaration = (BodyDeclaration) iter.next(); bodyDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(bodyDeclaration.getStartPosition())); annotationTypeDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(bodyDeclaration))); } return true; } @Override public boolean visit(AnonymousClassDeclaration anonymousClassDeclaration) { final List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations(); for (final Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) { final BodyDeclaration bodyDeclaration = (BodyDeclaration) iter.next(); bodyDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(bodyDeclaration.getStartPosition())); anonymousClassDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(bodyDeclaration))); } return true; } @Override public boolean visit(TypeDeclaration typeDeclaration) { final List bodyDeclarations = typeDeclaration.bodyDeclarations(); for (final Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) { final BodyDeclaration bodyDeclaration = (BodyDeclaration) iter.next(); bodyDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(bodyDeclaration.getStartPosition())); typeDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(bodyDeclaration))); } return true; } @Override public boolean visit(EnumDeclaration enumDeclaration) { final List bodyDeclarations = enumDeclaration.bodyDeclarations(); for (final Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) { final BodyDeclaration bodyDeclaration = (BodyDeclaration) iter.next(); bodyDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(bodyDeclaration.getStartPosition())); enumDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(bodyDeclaration))); } final List enumConstants = enumDeclaration.enumConstants(); for (final Iterator iter = enumConstants.iterator(); iter.hasNext();) { final EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) iter.next(); enumConstantDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(enumConstantDeclaration.getStartPosition())); enumDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(enumConstantDeclaration))); } return true; } }); final ASTRewrite rewriter = ASTRewrite.create(ast.getAST()); final boolean[] hasChanges = new boolean[] { false }; ast.accept(new ASTVisitor() { /** * This * * @param elements * @param listRewrite */ private void sortElements(List<BodyDeclaration> elements, ListRewrite listRewrite) { if (elements.size() == 0) return; final List<BodyDeclaration> myCopy = new ArrayList<BodyDeclaration>(); myCopy.addAll(elements); // orderexperiment final List<Signature> methods = new ArrayList<Signature>(); for (final BodyDeclaration bd : myCopy) { if (bd.getNodeType() == ASTNode.METHOD_DECLARATION) { methods.add(new Signature((MethodDeclaration) bd)); } } Collections.sort(methods, ((BodyDeclarationComparator) SortElementsOperation.this.comparator) .getMethodDeclarationComparator()); logger.info("Sorting of methods based on appearance:"); int j = 0; for (final Signature sig : methods) { logger.info("Method [{}] : {}", ++j, sig); } Collections.sort(myCopy, SortElementsOperation.this.comparator); logger.info("Final sorting order just before the AST-Rewrite:"); for (final BodyDeclaration bd : myCopy) { if (bd.getNodeType() == ASTNode.METHOD_DECLARATION) { logger.info("{}", new Signature((MethodDeclaration) bd)); } else { logger.info("{}", bd.toString()); } } for (int i = 0; i < elements.size(); i++) { final BodyDeclaration oldNode = elements.get(i); final BodyDeclaration newNode = myCopy.get(i); if (oldNode != newNode) { if (oldNode.getNodeType() == ASTNode.METHOD_DECLARATION && newNode.getNodeType() == ASTNode.METHOD_DECLARATION) { final Signature oldMethodSignature = new Signature((MethodDeclaration) oldNode); final Signature newMethodSignature = new Signature((MethodDeclaration) newNode); logger.trace("Swapping [{}]for [{}]", oldMethodSignature, newMethodSignature); } else { logger.trace("Swapping [{}]for [{}]", oldNode.getNodeType(), newNode.getNodeType()); } listRewrite.replace(oldNode, rewriter.createMoveTarget(newNode), group); hasChanges[0] = true; } } } @Override public boolean visit(org.eclipse.jdt.core.dom.CompilationUnit compilationUnit) { if (checkMalformedNodes(compilationUnit)) { logger.warn("Malformed nodes. Aborting sorting of current element."); return true; } sortElements(compilationUnit.types(), rewriter.getListRewrite(compilationUnit, org.eclipse.jdt.core.dom.CompilationUnit.TYPES_PROPERTY)); return true; } @Override public boolean visit(AnnotationTypeDeclaration annotationTypeDeclaration) { if (checkMalformedNodes(annotationTypeDeclaration)) { logger.warn("Malformed nodes. Aborting sorting of current element."); return true; } sortElements(annotationTypeDeclaration.bodyDeclarations(), rewriter.getListRewrite( annotationTypeDeclaration, AnnotationTypeDeclaration.BODY_DECLARATIONS_PROPERTY)); return true; } @Override public boolean visit(AnonymousClassDeclaration anonymousClassDeclaration) { if (checkMalformedNodes(anonymousClassDeclaration)) { logger.warn("Malformed nodes. Aborting sorting of current element."); return true; } sortElements(anonymousClassDeclaration.bodyDeclarations(), rewriter.getListRewrite( anonymousClassDeclaration, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY)); return true; } @Override public boolean visit(TypeDeclaration typeDeclaration) { if (checkMalformedNodes(typeDeclaration)) { logger.warn("Malformed nodes. Aborting sorting of current element."); return true; } sortElements(typeDeclaration.bodyDeclarations(), rewriter.getListRewrite(typeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY)); return true; } @Override public boolean visit(EnumDeclaration enumDeclaration) { if (checkMalformedNodes(enumDeclaration)) { return true; // abort sorting of current element } sortElements(enumDeclaration.bodyDeclarations(), rewriter.getListRewrite(enumDeclaration, EnumDeclaration.BODY_DECLARATIONS_PROPERTY)); sortElements(enumDeclaration.enumConstants(), rewriter.getListRewrite(enumDeclaration, EnumDeclaration.ENUM_CONSTANTS_PROPERTY)); return true; } }); if (!hasChanges[0]) return null; return rewriter; }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.EnumConstantDeclaration node) { String fieldName = node.getName().getIdentifier(); IMethodBinding constructorBinding = node.resolveConstructorBinding(); // prepare enum name org.eclipse.jdt.core.dom.EnumDeclaration parentEnum = (org.eclipse.jdt.core.dom.EnumDeclaration) node .getParent();/* www. ja v a 2s .com*/ String enumTypeName = parentEnum.getName().getIdentifier(); // may be create Dart top-level class for Java inner class String innerClassName = null; { AnonymousClassDeclaration anoClassDeclaration = node.getAnonymousClassDeclaration(); if (anoClassDeclaration != null) { innerClassName = enumTypeName + "_" + fieldName; declareInnerClass(constructorBinding, anoClassDeclaration, innerClassName, new String[] { "String", ENUM_NAME_FIELD_NAME, "int", ENUM_ORDINAL_FIELD_NAME }); } } // prepare field type TypeName type = typeName(enumTypeName); // prepare field variables List<VariableDeclaration> variables = Lists.newArrayList(); { List<Expression> argList = translateArguments(null, node.arguments()); { int ordinal = parentEnum.enumConstants().indexOf(node); argList.add(0, integer(ordinal)); argList.add(0, string(fieldName)); } InstanceCreationExpression init; if (innerClassName == null) { init = instanceCreationExpression(Keyword.NEW, typeName(enumTypeName), argList); context.getConstructorDescription(constructorBinding).instanceCreations.add(init); } else { init = instanceCreationExpression(Keyword.NEW, typeName(innerClassName), argList); } variables.add(variableDeclaration(fieldName, init)); } return done(fieldDeclaration(translateJavadoc(node), true, Keyword.FINAL, type, variables)); }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public boolean visit(org.eclipse.jdt.core.dom.EnumDeclaration node) { SimpleIdentifier name = translateSimpleName(node.getName()); // implements ImplementsClause implementsClause;//from w w w. ja v a 2 s .com { List<TypeName> interfaces = Lists.newArrayList(); // add Comparable interfaces.add(typeName("Comparable", typeName(name))); // add declared interfaces if (!node.superInterfaceTypes().isEmpty()) { for (Object javaInterface : node.superInterfaceTypes()) { interfaces.add((TypeName) translate((org.eclipse.jdt.core.dom.ASTNode) javaInterface)); } } // create ImplementsClause implementsClause = new ImplementsClause(null, interfaces); } // members List<ClassMember> members = Lists.newArrayList(); { // constants List<Expression> valuesList = Lists.newArrayList(); for (Object javaConst : node.enumConstants()) { org.eclipse.jdt.core.dom.EnumConstantDeclaration javaEnumConst = (org.eclipse.jdt.core.dom.EnumConstantDeclaration) javaConst; members.add((FieldDeclaration) translate(javaEnumConst)); valuesList.add(identifier(javaEnumConst.getName().getIdentifier())); } // values members.add(fieldDeclaration(true, Keyword.FINAL, listType(typeName(name), 1), variableDeclaration("values", listLiteral(valuesList)))); // body declarations members.add(fieldDeclaration(eolDocComment(ENUM_NAME_FIELD_COMMENT), false, Keyword.FINAL, typeName("String"), variableDeclaration(ENUM_NAME_FIELD_NAME))); members.add(fieldDeclaration(eolDocComment(ENUM_ORDINAL_FIELD_COMMENT), false, Keyword.FINAL, typeName("int"), variableDeclaration(ENUM_ORDINAL_FIELD_NAME))); boolean hasConstructor = false; for (Iterator<?> I = node.bodyDeclarations().iterator(); I.hasNext();) { org.eclipse.jdt.core.dom.BodyDeclaration javaBodyDecl = (org.eclipse.jdt.core.dom.BodyDeclaration) I .next(); constructorImpl = null; ClassMember member = translate(javaBodyDecl); members.add(member); if (constructorImpl != null) { members.add(constructorImpl); } if (javaBodyDecl instanceof org.eclipse.jdt.core.dom.MethodDeclaration) { if (((org.eclipse.jdt.core.dom.MethodDeclaration) javaBodyDecl).isConstructor()) { hasConstructor = true; } } } // add default constructor, use artificial constructor if (!hasConstructor) { org.eclipse.jdt.core.dom.MethodDeclaration ac = node.getAST().newMethodDeclaration(); try { ac.setConstructor(true); ac.setName(node.getAST().newSimpleName(name.getName())); ac.setBody(node.getAST().newBlock()); node.bodyDeclarations().add(ac); ConstructorDeclaration innerConstructor = translate(ac); members.add(innerConstructor); if (constructorImpl != null) { members.add(constructorImpl); } } finally { node.bodyDeclarations().remove(ac); } } // compareTo() members.add(methodDeclaration(typeName("int"), identifier("compareTo"), formalParameterList(simpleFormalParameter(typeName(name), "other")), expressionFunctionBody(binaryExpression(identifier(ENUM_ORDINAL_FIELD_NAME), TokenType.MINUS, propertyAccess(identifier("other"), identifier(ENUM_ORDINAL_FIELD_NAME)))))); // toString() members.add(methodDeclaration(typeName("String"), identifier("toString"), formalParameterList(), expressionFunctionBody(identifier(ENUM_NAME_FIELD_NAME)))); } return done(classDeclaration(translateJavadoc(node), name, null, null, implementsClause, members)); }
From source file:com.google.devtools.j2cpp.gen.CppImplementationGenerator.java
License:Open Source License
@Override protected void generate(EnumDeclaration node) { @SuppressWarnings("unchecked") List<EnumConstantDeclaration> constants = node.enumConstants(); // safe by definition List<MethodDeclaration> methods = Lists.newArrayList(); List<FieldDeclaration> fields = Lists.newArrayList(); MethodDeclaration initializeMethod = null; @SuppressWarnings("unchecked") List<BodyDeclaration> declarations = node.bodyDeclarations(); // safe by definition for (BodyDeclaration decl : declarations) { if (decl instanceof FieldDeclaration) { fields.add((FieldDeclaration) decl); } else if (decl instanceof MethodDeclaration) { MethodDeclaration md = (MethodDeclaration) decl; if (md.getName().getIdentifier().equals("initialize")) { initializeMethod = md;/*w w w . j a v a 2 s . co m*/ } else { methods.add(md); } } } syncLineNumbers(node.getName()); // avoid doc-comment String typeName = NameTable.getFullName(node); for (EnumConstantDeclaration constant : constants) { printf("static %s *%s_%s;\n", typeName, typeName, NameTable.getName(constant.getName())); } printf("IOSObjectArray *%s_values;\n", typeName); newline(); printf("@implementation %s\n\n", typeName); printStaticVars(fields); for (EnumConstantDeclaration constant : constants) { String name = NameTable.getName(constant.getName()); printf("+ (%s *)%s {\n", typeName, name); printf(" return %s_%s;\n", typeName, name); println("}"); } newline(); // Enum constants needs to implement NSCopying. Being singletons, they // can just return self, as long the retain count is incremented. String selfString = Options.useReferenceCounting() ? "[self retain]" : "self"; printf("- (id)copyWithZone:(NSZone *)zone {\n return %s;\n}\n\n", selfString); printProperties(fields.toArray(new FieldDeclaration[0])); printMethods(methods); printf("+ (void)initialize {\n if (self == [%s class]) {\n", typeName); for (int i = 0; i < constants.size(); i++) { EnumConstantDeclaration constant = constants.get(i); @SuppressWarnings("unchecked") List<Expression> args = constant.arguments(); // safe by definition String name = NameTable.getName(constant.getName()); String constantTypeName = NameTable.getFullName(Types.getMethodBinding(constant).getDeclaringClass()); printf(" %s_%s = [[%s alloc] init", typeName, name, constantTypeName); boolean isSimpleEnum = constantTypeName.equals(typeName); // Common-case: no extra fields and no constant anonymous classes. if (args.isEmpty() && isSimpleEnum) { printf("WithNSString:@\"%s_%s\" withInt:%d];\n", typeName.replace("Enum", ""), name, i); } else { String argString = CppStatementGenerator.generateArguments(Types.getMethodBinding(constant), args, fieldHiders, getBuilder().getCurrentLine()); print(argString); if (args.isEmpty()) { print("With"); } else { print(" with"); } printf("NSString:@\"%s_%s\" withInt:%d];\n", typeName.replace("Enum", ""), name, i); } } printf(" %s_values = [[IOSObjectArray alloc] initWithObjects:(id[]){ ", typeName); for (EnumConstantDeclaration constant : constants) { printf("%s_%s, ", typeName, NameTable.getName(constant.getName())); } printf("nil } count:%d type:[IOSClass classWithClass:[%s class]]];\n", constants.size(), typeName); if (initializeMethod != null) { @SuppressWarnings("unchecked") List<Statement> stmts = initializeMethod.getBody().statements(); // safe by definition for (Statement s : stmts) { printf(" %s", CppStatementGenerator.generate(s, fieldHiders, false, getBuilder().getCurrentLine())); } } println(" }\n}\n"); // Print generated values and valueOf methods. println("+ (IOSObjectArray *)values {"); printf(" return [IOSObjectArray arrayWithArray:%s_values];\n", typeName); println("}\n"); printf("+ (%s *)valueOfWithNSString:(NSString *)name {\n", typeName); printf(" for (int i = 0; i < [%s_values count]; i++) {\n", typeName); printf(" %s *e = [%s_values objectAtIndex:i];\n", typeName, typeName); printf(" if ([name isEqual:[e name]]) {\n"); printf(" return e;\n"); printf(" }\n"); printf(" }\n"); printf(" @throw [[JavaLangIllegalArgumentException alloc] initWithNSString:name];\n"); printf(" return nil;\n"); println("}\n"); println("@end"); }