package com.pivotallabs.robolectricgem.expect;

import com.pivotallabs.greatexpectations.BaseMatcher;
import com.pivotallabs.greatexpectations.ExpectGenerator;
import com.pivotallabs.robolectricgem.matchers.ActivityMatcher;
import com.pivotallabs.robolectricgem.matchers.AlertDialogMatcher;
import com.pivotallabs.robolectricgem.matchers.CompoundButtonMatcher;
import com.pivotallabs.robolectricgem.matchers.DialogMatcher;
import com.pivotallabs.robolectricgem.matchers.FakeHttpLayerMatcher;
import com.pivotallabs.robolectricgem.matchers.ImageViewMatcher;
import com.pivotallabs.robolectricgem.matchers.TextViewMatcher;
import com.pivotallabs.robolectricgem.matchers.ViewMatcher;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;

/**
 * See https://github.com/xian/great-expectations
 *
 * Run this class to regenerate Expect.java.
 *
 * This class is designed to be subclassed, in case you want to extend
 * the list of matcher classes with your own matcher classes.
 */
public class RunnableExpectGenerator extends ExpectGenerator {

    @SuppressWarnings({"unchecked"})
    protected static final Class<? extends BaseMatcher>[] CUSTOM_MATCHER_CLASSES = new Class[]{
            ActivityMatcher.class,
            AlertDialogMatcher.class,
            CompoundButtonMatcher.class,
            DialogMatcher.class,
            FakeHttpLayerMatcher.class,
            ImageViewMatcher.class,
            TextViewMatcher.class,
            ViewMatcher.class
    };

    public RunnableExpectGenerator(String packageName) {
        super(packageName);
    }

    public static void main(String args[]) throws java.io.IOException {
        generateCustomExpect();
    }

    public static void generateCustomExpect() throws FileNotFoundException {
        String packageName = getExpectClassPackageName();
        String path = getExpectClassFilePath();
        System.out.println("path = " + path);
        System.out.println("packagename = " + packageName);
        RunnableExpectGenerator expectGenerator = new RunnableExpectGenerator(packageName);
        expectGenerator.setOut(new PrintStream(new File(path)));
        expectGenerator.generate();
    }

    @Override
    @SuppressWarnings({"unchecked"})
    public List<Class<? extends BaseMatcher>> matcherClasses() {
        List<Class<? extends BaseMatcher>> classes = super.matcherClasses();
        classes.addAll(Arrays.asList(CUSTOM_MATCHER_CLASSES));
        return classes;
    }

    protected static String getExpectClassPackageName() {
        return Expect.class.getPackage().getName();
    }

    protected static String getExpectClassFilePath() {
        return "src" + File.separator +
                "robolectricgem" + File.separator +
                getExpectClassPackageName().replace(".", File.separator) + File.separator +
                "Expect.java";
    }
}

@@ -734,16 +734,44 @@
 eption;%0A
+import java.io.IOException;%0A
 import j
@@ -1076,16 +1076,211 @@
 classes.
+ The%0A * subclass can provide its own main() method, which can create an%0A * instance of itself and then call generateCustomExpect().%0A * Override methods to change file path or add matcher classes.
 %0A */%0Apub
@@ -1340,16 +1340,49 @@
 ator %7B%0A%0A
+    private String packageName;%0A%0A
     @Sup
@@ -1883,24 +1883,64 @@
 ckageName);%0A
+        this.packageName = packageName;%0A
     %7D%0A%0A    p
@@ -1984,24 +1984,16 @@
  throws 
-java.io.
 IOExcept
@@ -2010,54 +2010,296 @@
     
-generateCustomExpect();%0A    %7D%0A%0A    public stat
+new RunnableExpectGenerator(getExpectClassPackageName()).generateCustomExpect();%0A    %7D%0A%0A    protected static String getExpectClassPackageName() %7B%0A        return Expect.class.getPackage().getName();%0A    %7D%0A%0A    protected String getPackageName() %7B%0A        return packageName;%0A    %7D%0A%0A    publ
 ic v
@@ -2384,35 +2384,24 @@
 geName = get
-ExpectClass
 PackageName(
@@ -3050,39 +3050,32 @@
 %0A%0A    protected 
-static 
 String getExpect
@@ -3075,35 +3075,34 @@
 tExpectClass
-PackageName
+FilePrefix
 () %7B%0A       
@@ -3113,43 +3113,66 @@
 urn 
-Expect.class.getPackage().getName()
+%22src%22 + File.separator + %22robolectricgem%22 + File.separator
 ;%0A  
@@ -3182,39 +3182,32 @@
 %0A%0A    protected 
-static 
 String getExpect
@@ -3243,82 +3243,34 @@
 urn 
-%22src%22 + File.separator +%0A                %22robolectricgem%22 + File.separator
+getExpectClassFilePrefix()
  +%0A 
@@ -3283,35 +3283,24 @@
          get
-ExpectClass
 PackageName(
@@ -3331,16 +3331,32 @@
 rator) +
+%0A               
  File.se

Make it easier to subclass RunnableExpectGenerator