Java Code Examples for org.jboss.forge.roaster.Roaster#parse()

The following examples show how to use org.jboss.forge.roaster.Roaster#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EhDaoGenerator.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
private static void adjustQuickSearch() throws Exception {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, new File(QUICK_SEARCH_PATH));

    // Set all field public
    javaClass.getField("id").setPublic();
    javaClass.getField("name").setPublic();
    javaClass.getField("mode").setPublic();
    javaClass.getField("category").setPublic();
    javaClass.getField("keyword").setPublic();
    javaClass.getField("advanceSearch").setPublic();
    javaClass.getField("minRating").setPublic();
    javaClass.getField("pageFrom").setPublic();
    javaClass.getField("pageTo").setPublic();
    javaClass.getField("time").setPublic();

    javaClass.addMethod("\t@Override\n" +
            "\tpublic String toString() {\n" +
            "\t\treturn name;\n" +
            "\t}");

    FileWriter fileWriter = new FileWriter(QUICK_SEARCH_PATH);
    fileWriter.write(javaClass.toString());
    fileWriter.close();
}
 
Example 2
Source File: MatcherGenerator.java    From Entitas-Java with MIT License 6 votes vote down vote up
private JavaClassSource generateMatchers(String contextName, List<ComponentInfo> componentInfos, String pkgDestiny) {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}",
            CodeGeneratorOld.capitalize(contextName) + "Matcher"));
    if (componentInfos.size() > 0 && !pkgDestiny.endsWith(componentInfos.get(0).subDir)) {
        pkgDestiny += "." + componentInfos.get(0).subDir;

    }

    javaClass.setPackage(pkgDestiny);
    //javaClass.addImport("ilargia.entitas.interfaces.IMatcher");
    javaClass.addImport("Matcher");

    for (ComponentInfo info : componentInfos) {
        addMatcher(contextName, info, javaClass);
        addMatcherMethods(contextName, info, javaClass);
    }
    System.out.println(javaClass);
    return javaClass;
}
 
Example 3
Source File: EhDaoGenerator.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
private static void adjustQuickSearch() throws Exception {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, new File(QUICK_SEARCH_PATH));

    // Set all field public
    javaClass.getField("id").setPublic();
    javaClass.getField("name").setPublic();
    javaClass.getField("mode").setPublic();
    javaClass.getField("category").setPublic();
    javaClass.getField("keyword").setPublic();
    javaClass.getField("advanceSearch").setPublic();
    javaClass.getField("minRating").setPublic();
    javaClass.getField("pageFrom").setPublic();
    javaClass.getField("pageTo").setPublic();
    javaClass.getField("time").setPublic();

    javaClass.addMethod("\t@Override\n" +
            "\tpublic String toString() {\n" +
            "\t\treturn name;\n" +
            "\t}");

    FileWriter fileWriter = new FileWriter(QUICK_SEARCH_PATH);
    fileWriter.write(javaClass.toString());
    fileWriter.close();
}
 
Example 4
Source File: ComponentIndicesGenerator.java    From Entitas-Java with MIT License 6 votes vote down vote up
private JavaClassSource generateIndicesLookup(String poolName, List<ComponentInfo> componentInfos, String pkgDestiny) {
        JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}",
                CodeGeneratorOld.capitalize(poolName) + CodeGeneratorOld.DEFAULT_COMPONENT_LOOKUP_TAG));

//        if(componentInfos.size() > 0 && componentInfos.get(0).directory !=null) {
//            pkgDestiny+= "."+componentInfos.get(0).directory;
//
//        }
        if (componentInfos.size() > 0 && !pkgDestiny.endsWith(componentInfos.get(0).subDir)) {
            pkgDestiny += "." + componentInfos.get(0).subDir;

        }
        javaClass.setPackage(pkgDestiny);

        addIndices(componentInfos, javaClass);
        addComponentNames(componentInfos, javaClass);
        addComponentTypes(componentInfos, javaClass);
        System.out.println(javaClass);
        return javaClass;
    }
 
Example 5
Source File: ComponentIndicesGenerator.java    From Entitas-Java with MIT License 6 votes vote down vote up
public void addComponentFactories(ComponentInfo[] componentInfos, JavaClassSource javaClass) {
    String format = " %1$s.class,\n";
    String code = "return new FactoryComponent[] {";
    for (int i = 0; i < componentInfos.length; i++) {
        ComponentInfo info = componentInfos[i];
        JavaInterfaceSource interfaceSource = Roaster.parse(JavaInterfaceSource.class, String.format("public interface Factory%1$s extends FactoryComponent {}",
                info.typeName));
        interfaceSource.addMethod()
                .setName(String.format("create%1$s", info.typeName))
                .setReturnType(info.typeName)
                .setPublic();

        javaClass.addNestedType(interfaceSource.toString());


    }


}
 
Example 6
Source File: EntitasGenerator.java    From Entitas-Java with MIT License 5 votes vote down vote up
private CodeGenFile<JavaClassSource> generateEntitas(Set<String> contextNames, String pkgDestiny) {
    JavaClassSource sourceGen = Roaster.parse(JavaClassSource.class, "public class Entitas implements IContexts{}");
    CodeGenFile<JavaClassSource> genFile = new CodeGenFile<JavaClassSource>( "Entitas", sourceGen, "");
    sourceGen.setPackage(pkgDestiny);
    createMethodConstructor(sourceGen, contextNames);
    createContextsMethod(sourceGen, contextNames);
    createMethodAllContexts(sourceGen, contextNames);
    createContextFields(sourceGen, contextNames);

    System.out.println(genFile.getFileContent());
    return genFile;

}
 
Example 7
Source File: ContextGenerator.java    From Entitas-Java with MIT License 5 votes vote down vote up
private JavaClassSource generateContext(String contextName, List<ComponentInfo> infos, String pkgDestiny) {
        JavaClassSource contextClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$sContext extends Context<%1$sEntity> {}", contextName));

//        if(infos.size() > 0 && infos.get(0).directory !=null) {
//            pkgDestiny+= "."+infos.get(0).directory;
//
//        }
        if (infos.size() > 0 && !pkgDestiny.endsWith(infos.get(0).subDir)) {
            pkgDestiny += "." + infos.get(0).subDir;

        }
        contextClass.setPackage(pkgDestiny);


        contextClass.addMethod()
                .setName(contextName + "Context")
                .setPublic()
                .setConstructor(true)
                .setParameters(String.format("int totalComponents, int startCreationIndex, ContextInfo contextInfo, EntityBaseFactory<%1$sEntity> factoryMethod", contextName))
                .setBody("super(totalComponents, startCreationIndex, contextInfo, factoryMethod);");
        contextClass.addImport("ilargia.entitas.api.*");


        for (ComponentInfo info : infos) {
            if (info.isSingleEntity) {
                addContextMethods(contextName, info, contextClass);
            }

        }
        return contextClass;
    }
 
Example 8
Source File: EntitasGenerator.java    From Entitas-Java with MIT License 5 votes vote down vote up
public JavaClassSource generateEntitas(Set<String> contextNames, String pkgDestiny) {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, "public class Entitas implements IContexts{}");
    javaClass.setPackage(pkgDestiny);
    createMethodConstructor(javaClass, contextNames);
    createContextsMethod(javaClass, contextNames);
    createMethodAllContexts(javaClass, contextNames);
    createContextFields(javaClass, contextNames);

    return javaClass;

}
 
Example 9
Source File: EntityGenerator.java    From Entitas-Java with MIT License 5 votes vote down vote up
private JavaClassSource generateMatchers(String contextName, List<ComponentInfo> componentInfos, String pkgDestiny) {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}",
            CodeGeneratorOld.capitalize(contextName) + "Matcher"));
    javaClass.setPackage(pkgDestiny);
    //javaClass.addImport("com.ilargia.games.entitas.interfaces.IMatcher");
    javaClass.addImport("Matcher");

    for (ComponentInfo info : componentInfos) {
        addMatcher(contextName, info, javaClass);
        addMatcherMethods(contextName, info, javaClass);
    }
    System.out.println(javaClass);
    return javaClass;
}
 
Example 10
Source File: EntityGenerator.java    From Entitas-Java with MIT License 5 votes vote down vote up
private JavaClassSource generateEntity(String contextName, List<ComponentInfo> infos, String pkgDestiny) {

        JavaClassSource entityClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$sEntity extends Entity {}", contextName));

        if (infos.size() > 0 && !pkgDestiny.endsWith(infos.get(0).subDir)) {
            pkgDestiny += "." + infos.get(0).subDir;

        }
        entityClass.setPackage(pkgDestiny);
        entityClass.addMethod()
                .setName(contextName + "Entity")
                .setPublic()
                .setConstructor(true)
                .setBody("");
        entityClass.addImport("ilargia.entitas.api.*");
        entityClass.addImport("Entity");
        entityClass.addImport("java.util.Stack");

        for (ComponentInfo info : infos) {
            if (info.generateMethods) {
                addImporEnums(info, entityClass);
                addEntityMethods(contextName, info, entityClass);
            }
        }

        System.out.println(Roaster.format(entityClass.toString()));
        return entityClass;
    }
 
Example 11
Source File: EntitasGenerator.java    From Entitas-Java with MIT License 5 votes vote down vote up
public JavaClassSource generateEntitas(Set<String> contextNames, String pkgDestiny) {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, "public class Entitas implements IContexts{}");
    javaClass.setPackage(pkgDestiny);
    createMethodConstructor(javaClass, contextNames);
    createContextsMethod(javaClass, contextNames);
    createMethodAllContexts(javaClass, contextNames);
    createContextFields(javaClass, contextNames);

    return javaClass;

}
 
Example 12
Source File: EhDaoGenerator.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private static void adjustFilter() throws Exception {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, new File(FILTER_PATH));
    // Set field public
    javaClass.getField("mode").setPublic();
    javaClass.getField("text").setPublic();
    javaClass.getField("enable").setPublic();
    // Add hashCode method and equals method
    javaClass.addImport("com.hippo.util.HashCodeUtils");
    javaClass.addMethod("\t@Override\n" +
            "\tpublic int hashCode() {\n" +
            "\t\treturn HashCodeUtils.hashCode(mode, text);\n" +
            "\t}");
    javaClass.addImport("com.hippo.yorozuya.ObjectUtils");
    javaClass.addMethod("\t@Override\n" +
            "\tpublic boolean equals(Object o) {\n" +
            "\t\tif (!(o instanceof Filter)) {\n" +
            "\t\t\treturn false;\n" +
            "\t\t}\n" +
            "\n" +
            "\t\tFilter filter = (Filter) o;\n" +
            "\t\treturn filter.mode == mode && ObjectUtils.equal(filter.text, text);\n" +
            "\t}");

    FileWriter fileWriter = new FileWriter(FILTER_PATH);
    fileWriter.write(javaClass.toString());
    fileWriter.close();
}
 
Example 13
Source File: EndpointDiagnosticService.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
private List<CamelEndpointDetails> retrieveEndpoints(String uri, String camelText) {
	List<CamelEndpointDetails> endpoints = new ArrayList<>();
	if (uri.endsWith(".xml")) {
		try {
			XmlRouteParser.parseXmlRouteEndpoints(new ByteArrayInputStream(camelText.getBytes(StandardCharsets.UTF_8)), "", "/"+uri, endpoints);
		} catch (Exception e) {
			logExceptionValidatingDocument(uri, e);
		}
	} else if(uri.endsWith(".java")) {
		JavaClassSource clazz = (JavaClassSource) Roaster.parse(camelText);
		RouteBuilderParser.parseRouteBuilderEndpoints(clazz, "", "/"+uri, endpoints);
	}
	return endpoints;
}
 
Example 14
Source File: EhDaoGenerator.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
private static void adjustBookmarkInfo() throws Exception {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, new File(BOOKMARK_INFO_PATH));
    // Remove field from GalleryInfo
    javaClass.removeField(javaClass.getField("gid"));
    javaClass.removeField(javaClass.getField("token"));
    javaClass.removeField(javaClass.getField("title"));
    javaClass.removeField(javaClass.getField("titleJpn"));
    javaClass.removeField(javaClass.getField("thumb"));
    javaClass.removeField(javaClass.getField("category"));
    javaClass.removeField(javaClass.getField("posted"));
    javaClass.removeField(javaClass.getField("uploader"));
    javaClass.removeField(javaClass.getField("rating"));
    javaClass.removeField(javaClass.getField("simpleLanguage"));
    // Set all field public
    javaClass.getField("page").setPublic();
    javaClass.getField("time").setPublic();
    // Add Parcelable stuff
    javaClass.addMethod("\t@Override\n" +
            "\tpublic int describeContents() {\n" +
            "\t\treturn 0;\n" +
            "\t}");
    javaClass.addMethod("\t@Override\n" +
            "\tpublic void writeToParcel(Parcel dest, int flags) {\n" +
            "\t\tsuper.writeToParcel(dest, flags);\n" +
            "\t\tdest.writeInt(this.page);\n" +
            "\t\tdest.writeLong(this.time);\n" +
            "\t}");
    javaClass.addMethod("\tprotected BookmarkInfo(Parcel in) {\n" +
            "\t\tsuper(in);\n" +
            "\t\tthis.page = in.readInt();\n" +
            "\t\tthis.time = in.readLong();\n" +
            "\t}").setConstructor(true);
    javaClass.addField("\tpublic static final Creator<BookmarkInfo> CREATOR = new Creator<BookmarkInfo>() {\n" +
            "\t\t@Override\n" +
            "\t\tpublic BookmarkInfo createFromParcel(Parcel source) {\n" +
            "\t\t\treturn new BookmarkInfo(source);\n" +
            "\t\t}\n" +
            "\n" +
            "\t\t@Override\n" +
            "\t\tpublic BookmarkInfo[] newArray(int size) {\n" +
            "\t\t\treturn new BookmarkInfo[size];\n" +
            "\t\t}\n" +
            "\t};");
    javaClass.addImport("android.os.Parcel");
    // Add from GalleryInfo constructor
    javaClass.addMethod("\tpublic BookmarkInfo(GalleryInfo galleryInfo) {\n" +
            "\t\tthis.gid = galleryInfo.gid;\n" +
            "\t\tthis.token = galleryInfo.token;\n" +
            "\t\tthis.title = galleryInfo.title;\n" +
            "\t\tthis.titleJpn = galleryInfo.titleJpn;\n" +
            "\t\tthis.thumb = galleryInfo.thumb;\n" +
            "\t\tthis.category = galleryInfo.category;\n" +
            "\t\tthis.posted = galleryInfo.posted;\n" +
            "\t\tthis.uploader = galleryInfo.uploader;\n" +
            "\t\tthis.rating = galleryInfo.rating;\n" +
            "\t\tthis.simpleTags = galleryInfo.simpleTags;\n" +
            "\t\tthis.simpleLanguage = galleryInfo.simpleLanguage;\n" +
            "\t}").setConstructor(true);
    javaClass.addImport("com.hippo.ehviewer.client.data.GalleryInfo");

    FileWriter fileWriter = new FileWriter(BOOKMARK_INFO_PATH);
    fileWriter.write(javaClass.toString());
    fileWriter.close();
}
 
Example 15
Source File: CreateTestClassCommandTest.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void should_create_asclient_test() throws Exception
{
   assertThat(project.hasFacet(ThorntailFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");
      controller.setValueFor("asClient", true);

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }

   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));

   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   final String testable = defaultDeployment.getLiteralValue("testable");
   assertThat(testable, is("false"));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
Example 16
Source File: EhDaoGenerator.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
private static void adjustDownloadInfo() throws Exception {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, new File(DOWNLOAD_INFO_PATH));
    // Remove field from GalleryInfo
    javaClass.removeField(javaClass.getField("gid"));
    javaClass.removeField(javaClass.getField("token"));
    javaClass.removeField(javaClass.getField("title"));
    javaClass.removeField(javaClass.getField("titleJpn"));
    javaClass.removeField(javaClass.getField("thumb"));
    javaClass.removeField(javaClass.getField("category"));
    javaClass.removeField(javaClass.getField("posted"));
    javaClass.removeField(javaClass.getField("uploader"));
    javaClass.removeField(javaClass.getField("rating"));
    javaClass.removeField(javaClass.getField("simpleLanguage"));
    // Set all field public
    javaClass.getField("state").setPublic();
    javaClass.getField("legacy").setPublic();
    javaClass.getField("time").setPublic();
    javaClass.getField("label").setPublic();
    // Add Parcelable stuff
    javaClass.addMethod("\t@Override\n" +
            "\tpublic int describeContents() {\n" +
            "\t\treturn 0;\n" +
            "\t}");
    javaClass.addMethod("\t@Override\n" +
            "\tpublic void writeToParcel(Parcel dest, int flags) {\n" +
            "\t\tsuper.writeToParcel(dest, flags);\n" +
            "\t\tdest.writeInt(this.state);\n" +
            "\t\tdest.writeInt(this.legacy);\n" +
            "\t\tdest.writeLong(this.time);\n" +
            "\t\tdest.writeString(this.label);\n" +
            "\t}");
    javaClass.addMethod("\tprotected DownloadInfo(Parcel in) {\n" +
            "\t\tsuper(in);\n" +
            "\t\tthis.state = in.readInt();\n" +
            "\t\tthis.legacy = in.readInt();\n" +
            "\t\tthis.time = in.readLong();\n" +
            "\t\tthis.label = in.readString();\n" +
            "\t}").setConstructor(true);
    javaClass.addField("\tpublic static final Creator<DownloadInfo> CREATOR = new Creator<DownloadInfo>() {\n" +
            "\t\t@Override\n" +
            "\t\tpublic DownloadInfo createFromParcel(Parcel source) {\n" +
            "\t\t\treturn new DownloadInfo(source);\n" +
            "\t\t}\n" +
            "\n" +
            "\t\t@Override\n" +
            "\t\tpublic DownloadInfo[] newArray(int size) {\n" +
            "\t\t\treturn new DownloadInfo[size];\n" +
            "\t\t}\n" +
            "\t};");
    javaClass.addImport("android.os.Parcel");
    // Add download info stuff
    javaClass.addField("public static final int STATE_INVALID = -1");
    javaClass.addField("public static final int STATE_NONE = 0");
    javaClass.addField("public static final int STATE_WAIT = 1");
    javaClass.addField("public static final int STATE_DOWNLOAD = 2");
    javaClass.addField("public static final int STATE_FINISH = 3");
    javaClass.addField("public static final int STATE_FAILED = 4");
    javaClass.addField("public long speed");
    javaClass.addField("public long remaining");
    javaClass.addField("public int finished");
    javaClass.addField("public int downloaded");
    javaClass.addField("public int total");
    // Add from GalleryInfo constructor
    javaClass.addMethod("\tpublic DownloadInfo(GalleryInfo galleryInfo) {\n" +
            "\t\tthis.gid = galleryInfo.gid;\n" +
            "\t\tthis.token = galleryInfo.token;\n" +
            "\t\tthis.title = galleryInfo.title;\n" +
            "\t\tthis.titleJpn = galleryInfo.titleJpn;\n" +
            "\t\tthis.thumb = galleryInfo.thumb;\n" +
            "\t\tthis.category = galleryInfo.category;\n" +
            "\t\tthis.posted = galleryInfo.posted;\n" +
            "\t\tthis.uploader = galleryInfo.uploader;\n" +
            "\t\tthis.rating = galleryInfo.rating;\n" +
            "\t\tthis.simpleTags = galleryInfo.simpleTags;\n" +
            "\t\tthis.simpleLanguage = galleryInfo.simpleLanguage;\n" +
            "\t}").setConstructor(true);
    javaClass.addImport("com.hippo.ehviewer.client.data.GalleryInfo");

    FileWriter fileWriter = new FileWriter(DOWNLOAD_INFO_PATH);
    fileWriter.write(javaClass.toString());
    fileWriter.close();
}
 
Example 17
Source File: EhDaoGenerator.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
private static void adjustLocalFavoriteInfo() throws Exception {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, new File(LOCAL_FAVORITE_INFO_PATH));
    // Remove field from GalleryInfo
    javaClass.removeField(javaClass.getField("gid"));
    javaClass.removeField(javaClass.getField("token"));
    javaClass.removeField(javaClass.getField("title"));
    javaClass.removeField(javaClass.getField("titleJpn"));
    javaClass.removeField(javaClass.getField("thumb"));
    javaClass.removeField(javaClass.getField("category"));
    javaClass.removeField(javaClass.getField("posted"));
    javaClass.removeField(javaClass.getField("uploader"));
    javaClass.removeField(javaClass.getField("rating"));
    javaClass.removeField(javaClass.getField("simpleLanguage"));
    // Set all field public
    javaClass.getField("time").setPublic();
    // Add Parcelable stuff
    javaClass.addMethod("\t@Override\n" +
            "\tpublic int describeContents() {\n" +
            "\t\treturn 0;\n" +
            "\t}");
    javaClass.addMethod("\t@Override\n" +
            "\tpublic void writeToParcel(Parcel dest, int flags) {\n" +
            "\t\tsuper.writeToParcel(dest, flags);\n" +
            "\t\tdest.writeLong(this.time);\n" +
            "\t}");
    javaClass.addMethod("\tprotected LocalFavoriteInfo(Parcel in) {\n" +
            "\t\tsuper(in);\n" +
            "\t\tthis.time = in.readLong();\n" +
            "\t}").setConstructor(true);
    javaClass.addField("\tpublic static final Creator<LocalFavoriteInfo> CREATOR = new Creator<LocalFavoriteInfo>() {\n" +
            "\t\t@Override\n" +
            "\t\tpublic LocalFavoriteInfo createFromParcel(Parcel source) {\n" +
            "\t\t\treturn new LocalFavoriteInfo(source);\n" +
            "\t\t}\n" +
            "\n" +
            "\t\t@Override\n" +
            "\t\tpublic LocalFavoriteInfo[] newArray(int size) {\n" +
            "\t\t\treturn new LocalFavoriteInfo[size];\n" +
            "\t\t}\n" +
            "\t};");
    javaClass.addImport("android.os.Parcel");
    // Add from GalleryInfo constructor
    javaClass.addMethod("\tpublic LocalFavoriteInfo(GalleryInfo galleryInfo) {\n" +
            "\t\tthis.gid = galleryInfo.gid;\n" +
            "\t\tthis.token = galleryInfo.token;\n" +
            "\t\tthis.title = galleryInfo.title;\n" +
            "\t\tthis.titleJpn = galleryInfo.titleJpn;\n" +
            "\t\tthis.thumb = galleryInfo.thumb;\n" +
            "\t\tthis.category = galleryInfo.category;\n" +
            "\t\tthis.posted = galleryInfo.posted;\n" +
            "\t\tthis.uploader = galleryInfo.uploader;\n" +
            "\t\tthis.rating = galleryInfo.rating;\n" +
            "\t\tthis.simpleTags = galleryInfo.simpleTags;\n" +
            "\t\tthis.simpleLanguage = galleryInfo.simpleLanguage;\n" +
            "\t}").setConstructor(true);
    javaClass.addImport("com.hippo.ehviewer.client.data.GalleryInfo");

    FileWriter fileWriter = new FileWriter(LOCAL_FAVORITE_INFO_PATH);
    fileWriter.write(javaClass.toString());
    fileWriter.close();
}
 
Example 18
Source File: CreateTestClassCommandTest.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void should_create_incontainer_test() throws Exception
{
   assertThat(project.hasFacet(ThorntailFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }
   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));
   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   assertThat(defaultDeployment.getValues().size(), is(0));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
Example 19
Source File: EhDaoGenerator.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
private static void adjustLocalFavoriteInfo() throws Exception {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, new File(LOCAL_FAVORITE_INFO_PATH));
    // Remove field from GalleryInfo
    javaClass.removeField(javaClass.getField("gid"));
    javaClass.removeField(javaClass.getField("token"));
    javaClass.removeField(javaClass.getField("title"));
    javaClass.removeField(javaClass.getField("titleJpn"));
    javaClass.removeField(javaClass.getField("thumb"));
    javaClass.removeField(javaClass.getField("category"));
    javaClass.removeField(javaClass.getField("posted"));
    javaClass.removeField(javaClass.getField("uploader"));
    javaClass.removeField(javaClass.getField("rating"));
    javaClass.removeField(javaClass.getField("simpleLanguage"));
    // Set all field public
    javaClass.getField("time").setPublic();
    // Add Parcelable stuff
    javaClass.addMethod("\t@Override\n" +
            "\tpublic int describeContents() {\n" +
            "\t\treturn 0;\n" +
            "\t}");
    javaClass.addMethod("\t@Override\n" +
            "\tpublic void writeToParcel(Parcel dest, int flags) {\n" +
            "\t\tsuper.writeToParcel(dest, flags);\n" +
            "\t\tdest.writeLong(this.time);\n" +
            "\t\tdest.writeString(this.id);\n" +
            "\t}");
    javaClass.addMethod("\tprotected LocalFavoriteInfo(Parcel in) {\n" +
            "\t\tsuper(in);\n" +
            "\t\tthis.time = in.readLong();\n" +
            "\t\tthis.id = in.readString();\n" +
            "\t}").setConstructor(true);
    javaClass.addField("\tpublic static final Creator<LocalFavoriteInfo> CREATOR = new Creator<LocalFavoriteInfo>() {\n" +
            "\t\t@Override\n" +
            "\t\tpublic LocalFavoriteInfo createFromParcel(Parcel source) {\n" +
            "\t\t\treturn new LocalFavoriteInfo(source);\n" +
            "\t\t}\n" +
            "\n" +
            "\t\t@Override\n" +
            "\t\tpublic LocalFavoriteInfo[] newArray(int size) {\n" +
            "\t\t\treturn new LocalFavoriteInfo[size];\n" +
            "\t\t}\n" +
            "\t};");
    javaClass.addImport("android.os.Parcel");
    // Add from GalleryInfo constructor
    javaClass.addMethod("\tpublic LocalFavoriteInfo(GalleryInfo galleryInfo) {\n" +
            "\t\tthis.gid = galleryInfo.gid;\n" +
            "\t\tthis.token = galleryInfo.token;\n" +
            "\t\tthis.title = galleryInfo.title;\n" +
            "\t\tthis.titleJpn = galleryInfo.titleJpn;\n" +
            "\t\tthis.thumb = galleryInfo.thumb;\n" +
            "\t\tthis.category = galleryInfo.category;\n" +
            "\t\tthis.posted = galleryInfo.posted;\n" +
            "\t\tthis.uploader = galleryInfo.uploader;\n" +
            "\t\tthis.rating = galleryInfo.rating;\n" +
            "\t\tthis.simpleTags = galleryInfo.simpleTags;\n" +
            "\t\tthis.simpleLanguage = galleryInfo.simpleLanguage;\n" +
            "\t\tthis.id=galleryInfo.getId();\n" +
            "\t\tthis.time = System.currentTimeMillis();\n" +
            "\t}").setConstructor(true);
    javaClass.addImport("com.hippo.ehviewer.client.data.GalleryInfo");

    FileWriter fileWriter = new FileWriter(LOCAL_FAVORITE_INFO_PATH);
    fileWriter.write(javaClass.toString());
    fileWriter.close();
}
 
Example 20
Source File: EhDaoGenerator.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
private static void adjustHistoryInfo() throws Exception {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, new File(HISTORY_INFO_PATH));
    // Remove field from GalleryInfo
    javaClass.removeField(javaClass.getField("gid"));
    javaClass.removeField(javaClass.getField("token"));
    javaClass.removeField(javaClass.getField("title"));
    javaClass.removeField(javaClass.getField("titleJpn"));
    javaClass.removeField(javaClass.getField("thumb"));
    javaClass.removeField(javaClass.getField("category"));
    javaClass.removeField(javaClass.getField("posted"));
    javaClass.removeField(javaClass.getField("uploader"));
    javaClass.removeField(javaClass.getField("rating"));
    javaClass.removeField(javaClass.getField("simpleLanguage"));
    // Set all field public
    javaClass.getField("mode").setPublic();
    javaClass.getField("time").setPublic();
    // Add Parcelable stuff
    javaClass.addMethod("\t@Override\n" +
            "\tpublic int describeContents() {\n" +
            "\t\treturn 0;\n" +
            "\t}");
    javaClass.addMethod("\t@Override\n" +
            "\tpublic void writeToParcel(Parcel dest, int flags) {\n" +
            "\t\tsuper.writeToParcel(dest, flags);\n" +
            "\t\tdest.writeInt(this.mode);\n" +
            "\t\tdest.writeLong(this.time);\n" +
            "\t}");
    javaClass.addMethod("\tprotected HistoryInfo(Parcel in) {\n" +
            "\t\tsuper(in);\n" +
            "\t\tthis.mode = in.readInt();\n" +
            "\t\tthis.time = in.readLong();\n" +
            "\t}").setConstructor(true);
    javaClass.addField("\tpublic static final Creator<HistoryInfo> CREATOR = new Creator<HistoryInfo>() {\n" +
            "\t\t@Override\n" +
            "\t\tpublic HistoryInfo createFromParcel(Parcel source) {\n" +
            "\t\t\treturn new HistoryInfo(source);\n" +
            "\t\t}\n" +
            "\n" +
            "\t\t@Override\n" +
            "\t\tpublic HistoryInfo[] newArray(int size) {\n" +
            "\t\t\treturn new HistoryInfo[size];\n" +
            "\t\t}\n" +
            "\t};");
    javaClass.addImport("com.axlecho.api.MHApiSource");
    javaClass.addImport("android.os.Parcel");
    // Add from GalleryInfo constructor
    javaClass.addMethod("\tpublic HistoryInfo(GalleryInfo galleryInfo) {\n" +
            "\t\tthis.source = galleryInfo.getId().split(\"@\")[1];\n" +
            "\t\tthis.gid = galleryInfo.gid;\n" +
            "\t\tthis.token = galleryInfo.token;\n" +
            "\t\tthis.title = galleryInfo.title;\n" +
            "\t\tthis.titleJpn = galleryInfo.titleJpn;\n" +
            "\t\tthis.thumb = galleryInfo.thumb;\n" +
            "\t\tthis.category = galleryInfo.category;\n" +
            "\t\tthis.posted = galleryInfo.posted;\n" +
            "\t\tthis.uploader = galleryInfo.uploader;\n" +
            "\t\tthis.rating = galleryInfo.rating;\n" +
            "\t\tthis.simpleTags = galleryInfo.simpleTags;\n" +
            "\t\tthis.simpleLanguage = galleryInfo.simpleLanguage;\n" +
            "\t\tthis.id = galleryInfo.getId();\n" +
            "\t}").setConstructor(true);
    javaClass.addImport("com.hippo.ehviewer.client.data.GalleryInfo");

    FileWriter fileWriter = new FileWriter(HISTORY_INFO_PATH);
    fileWriter.write(javaClass.toString());
    fileWriter.close();
}