Search in sources :

Example 41 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project Entitas-Java by Rubentxu.

the class ComponentEntityGenerator method getCodeGenFile.

private CodeGenFile<JavaClassSource> getCodeGenFile(String contextName, ComponentData data) {
    if (entities.containsKey(contextName)) {
        return entities.get(contextName);
    } else {
        JavaClassSource sourceGen = Roaster.parse(JavaClassSource.class, String.format("public class %1$sEntity extends Entity {}", contextName));
        CodeGenFile<JavaClassSource> genFile = new CodeGenFile<JavaClassSource>(contextName + "Entity", sourceGen, data.getSubDir());
        entities.put(contextName, genFile);
        return genFile;
    }
}
Also used : CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 42 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project Entitas-Java by Rubentxu.

the class ComponentMatcherGenerator method getCodeGenFile.

private CodeGenFile<JavaClassSource> getCodeGenFile(String contextName, ComponentData data) {
    if (contexts.containsKey(contextName)) {
        return contexts.get(contextName);
    } else {
        JavaClassSource sourceGen = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}", WordUtils.capitalize(contextName) + "Matcher"));
        CodeGenFile<JavaClassSource> genFile = new CodeGenFile<JavaClassSource>(contextName + "Matcher", sourceGen, data.getSubDir());
        contexts.put(contextName, genFile);
        return genFile;
    }
}
Also used : CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 43 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project Entitas-Java by Rubentxu.

the class EntitasGenerator method generateEntitas.

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;
}
Also used : CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 44 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project EhViewer by seven332.

the class EhDaoGenerator method adjustFilter.

// Since 2
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();
}
Also used : FileWriter(java.io.FileWriter) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) File(java.io.File)

Example 45 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project EhViewer by seven332.

the class EhDaoGenerator method adjustDownloadInfo.

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();
}
Also used : FileWriter(java.io.FileWriter) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) File(java.io.File)

Aggregations

JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)95 File (java.io.File)37 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)26 ParserResult (org.apache.camel.parser.ParserResult)19 List (java.util.List)15 IOException (java.io.IOException)14 MethodSource (org.jboss.forge.roaster.model.source.MethodSource)12 InputStream (java.io.InputStream)10 Collections (java.util.Collections)10 Roaster (org.jboss.forge.roaster.Roaster)10 BufferedReader (java.io.BufferedReader)8 HashMap (java.util.HashMap)8 Matcher (java.util.regex.Matcher)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)8 Arrays (java.util.Arrays)7 Map (java.util.Map)7 Import (org.jboss.forge.roaster.model.source.Import)7 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)7