Coverage Report - org.eclipse.swtbot.generator.HamcrestFactoryWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
HamcrestFactoryWriter
0%
0/68
0%
0/2
1.111
 
 1  
 /*******************************************************************************
 2  
  * Copyright (c) 2008 Ketan Padegaonkar and others.
 3  
  * All rights reserved. This program and the accompanying materials
 4  
  * are made available under the terms of the Eclipse Public License v1.0
 5  
  * which accompanies this distribution, and is available at
 6  
  * http://www.eclipse.org/legal/epl-v10.html
 7  
  * 
 8  
  * Contributors:
 9  
  *     Ketan Padegaonkar - initial API and implementation
 10  
  *******************************************************************************/
 11  
 package org.eclipse.swtbot.generator;
 12  
 
 13  
 import java.io.FileWriter;
 14  
 import java.io.PrintWriter;
 15  
 import java.util.Set;
 16  
 import java.util.TreeSet;
 17  
 
 18  
 import org.eclipse.swtbot.swt.finder.utils.FileUtils;
 19  
 
 20  
 /**
 21  
  * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 22  
  * @version $Id$
 23  
  */
 24  
 public class HamcrestFactoryWriter implements HamcrestWriter {
 25  
 
 26  
         private final String                packageName;
 27  
         private final String                shortClassName;
 28  
         private final PrintWriter        output;
 29  
 
 30  0
         private final String                newLine        = "\n"; //$NON-NLS-1$
 31  
         private final String        superClass;
 32  
 
 33  0
         public HamcrestFactoryWriter(String packageName, String shortClassName, String superClass, FileWriter fileWriter) {
 34  0
                 this.packageName = packageName;
 35  0
                 this.shortClassName = shortClassName;
 36  0
                 this.superClass = superClass;
 37  0
                 output = new PrintWriter(fileWriter);
 38  
 
 39  0
         }
 40  
 
 41  
         public void writeHeader(Set<String> imports) {
 42  0
                 output.append("// Generated source. DO NOT MODIFY.").append(newLine); //$NON-NLS-1$
 43  0
                 output.append("// To add new widgets, please see README file in the generator plugin.").append(newLine); //$NON-NLS-1$
 44  0
                 output.append("package ").append(packageName).append(';').append(newLine); //$NON-NLS-1$
 45  0
                 output.append(newLine);
 46  0
                 output.append(newLine);
 47  0
                 writeImports(imports);
 48  0
         }
 49  
 
 50  
         public void beginClassDefinition() {
 51  0
                 output.append(newLine);
 52  0
                 output.append(newLine);
 53  
 
 54  0
                 output.append(FileUtils.read("templates/" + shortClassName + "/javadoc").trim()); //$NON-NLS-1$
 55  0
                 output.append(newLine);
 56  0
                 output.append("public class ").append(shortClassName).append(" extends "+ superClass + " {").append(newLine).append(newLine); //$NON-NLS-1$ //$NON-NLS-2$
 57  0
         }
 58  
 
 59  
 
 60  
 
 61  
         public void writeFooter() {
 62  0
                 output.append(newLine);
 63  0
                 output.append(FileUtils.read("templates/" + shortClassName + "/additionalMethods")); //$NON-NLS-1$
 64  
 
 65  0
                 output.append(newLine);
 66  
                 
 67  0
                 output.append('}').append(newLine);
 68  0
         }
 69  
 
 70  
         public void close() {
 71  0
                 output.close();
 72  0
         }
 73  
 
 74  
         public void flush() {
 75  0
                 output.flush();
 76  0
         }
 77  
 
 78  
         public void writeMethod(String method) {
 79  0
                 output.append(method.toString()).append(newLine);
 80  0
         }
 81  
 
 82  
         private void writeImports(Set<String> imports) {
 83  
 
 84  0
                 imports = new TreeSet<String>(imports);
 85  0
                 imports.addAll(FileUtils.readlines("templates/" + shortClassName + "/imports"));
 86  
 
 87  
 
 88  0
                 for (String importz : imports) {
 89  0
                         output.append(importz).append(";").append(newLine); //$NON-NLS-1$
 90  
                 }
 91  
 
 92  0
         }
 93  
 
 94  
         public void beginConstructors() {
 95  0
                 output.append("        /**\n" +
 96  
                                 "         * Constructs a bot.\n" +
 97  
                                 "         */\n" +
 98  0
                                 "        public " + shortClassName + "() {\n" +
 99  0
                                 "                this(new ControlFinder(), new MenuFinder());\n" +
 100  0
                                 "        }\n" +
 101  0
                                 "\n" +
 102  0
                                 "        /**\n" + 
 103  0
                                 "         * Constructs a bot that will match the contents of the given parentWidget.\n" + 
 104  0
                                 "         * \n" + 
 105  0
                                 "         * @param parent the parent\n" + 
 106  0
                                 "         */\n" + 
 107  0
                                 "        public " + shortClassName + "(Widget parent) {\n" + 
 108  0
                                 "                this(new ChildrenControlFinder(parent), new MenuFinder());\n" + 
 109  0
                                 "        }\n" +
 110  0
                                 "        /**\n" +
 111  0
                                 "         * Constructs an instance of the bot using the given control finder and menu finder.\n" +
 112  0
                                 "         * \n" +
 113  0
                                 "         * @param controlFinder the {@link ControlFinder} used to identify and find controls.\n" +
 114  0
                                 "         * @param menuFinder the {@link MenuFinder} used to find menu items.\n" +
 115  0
                                 "         */\n" +
 116  0
                                 "        public " + shortClassName + "(ControlFinder controlFinder, MenuFinder menuFinder) {\n" +
 117  0
                                 "                this(new Finder(controlFinder, menuFinder));\n" +
 118  0
                                 "        }\n" +
 119  0
                                 "\n" +
 120  0
                                 "        /**\n" +
 121  0
                                 "         * Constructs a bot with the given finder.\n" +
 122  0
                                 "         * \n" +
 123  0
                                 "         * @param finder the finder.\n" +
 124  0
                                 "         */\n" +
 125  0
                                 "        public " + shortClassName + "(Finder finder) {\n" +
 126  0
                                 "                super(finder);\n" +
 127  0
                                 "        }\n\n");
 128  0
         }
 129  
 }