Java Code Examples for org.jboss.forge.roaster.model.source.JavaClassSource#addImport()

The following examples show how to use org.jboss.forge.roaster.model.source.JavaClassSource#addImport() . 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: EntitasGenerator.java    From Entitas-Java with MIT License 6 votes vote down vote up
private void createContextFields(JavaClassSource codeGen, Set<String> contextNames) {
    codeGen.addImport(Context.class);
    codeGen.addImport("ilargia.entitas.api.*");
    codeGen.addImport("ilargia.entitas.api.entitas.EntityBaseFactory");

    contextNames.forEach((contextName) -> {
        if(contexts.containsKey(contextName)) {
            codeGen.addImport(contexts.get(contextName) + "." + contextName + "Context");
            codeGen.addImport(contexts.get(contextName) + "." + contextName + "ComponentsLookup");
            codeGen.addImport(contexts.get(contextName) + "." + contextName + "Entity");
        }
        codeGen.addMethod()
                .setName(String.format("factory%1$sEntity", contextName))
                .setReturnType(String.format("EntityBaseFactory<%1$sEntity>", contextName))
                .setPublic()
                .setBody(String.format("  return () -> { \n" +
                        "                   return new %1$sEntity();\n" +
                        "        };", contextName));
        codeGen.addField()
                .setName(contextName.toLowerCase())
                .setType(contextName + "Context")
                .setPublic();
    });


}
 
Example 2
Source File: ComponentMatcherGenerator.java    From Entitas-Java with MIT License 6 votes vote down vote up
private void generateMatcher(String contextName, ComponentData data) {
    String pkgDestiny = targetPackageConfig.getTargetPackage();
    CodeGenFile<JavaClassSource> genFile = getCodeGenFile(contextName, data);
    JavaClassSource codeGenerated = genFile.getFileContent();

    if (!pkgDestiny.endsWith(data.getSubDir())) {
        pkgDestiny += "." + data.getSubDir();

    }

    codeGenerated.setPackage(pkgDestiny);
    codeGenerated.addImport(Matcher.class);

    addMatcher(contextName, data, codeGenerated);
    addMatcherMethods(contextName, data, codeGenerated);

}
 
Example 3
Source File: ContextGenerator.java    From Entitas-Java with MIT License 6 votes vote down vote up
private void addContextAddMethods(String contextName, ComponentInfo info, JavaClassSource source) {
    if (!info.isSingletonComponent) {
        source.addMethod()
                .setName(String.format("set%1$s", info.typeName))
                .setReturnType(contextName + "Entity")
                .setPublic()
                .setParameters(info.constructores != null && info.constructores.size() > 0
                        ? memberNamesWithTypeFromConstructor(info.constructores.get(0))
                        : memberNamesWithType(info.memberInfos))
                .setBody(String.format("if(has%1$s()) {\n" +
                                "            throw new EntitasException(\"Could not set %1$s!\" + this + \" already has an entity with %1$s!\", " +
                                "\"You should check if the context already has a %1$sEntity before setting it or use context.Replace%1$s().\");" +
                                "         }\n" +
                                "         %3$sEntity entity = createEntity();\n" +
                                "         entity.add%1$s(%2$s);\n" +
                                "         return entity;"
                        , info.typeName,
                        info.constructores != null && info.constructores.size() > 0
                                ? memberNamesFromConstructor(info.constructores.get(0))
                                : memberNames(info.memberInfos)
                        , contextName));

        source.addImport(info.fullTypeName);

    }
}
 
Example 4
Source File: EntitasGenerator.java    From Entitas-Java with MIT License 6 votes vote down vote up
private void createContextFields(JavaClassSource javaClass, Set<String> contextNames) {
    javaClass.addImport("Context");
    javaClass.addImport("com.ilargia.games.entitas.api.*");
    contextNames.forEach((contextName) -> {

        javaClass.addMethod()
                .setName(String.format("factory%1$sEntity", contextName))
                .setReturnType(String.format("EntityBaseFactory<%1$sEntity>", contextName))
                .setPublic()
                .setBody(String.format("  return () -> { \n" +
                        "                   return new %1$sEntity();\n" +
                        "        };", contextName));
        javaClass.addField()
                .setName(contextName.toLowerCase())
                .setType(contextName + "Context")
                .setPublic();
    });


}
 
Example 5
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("com.ilargia.games.entitas.api.*");


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

        }
        return contextClass;
    }
 
Example 6
Source File: ComponentEntityGenerator.java    From Entitas-Java with MIT License 5 votes vote down vote up
private void addGetMethods(String contextName, ComponentData data, JavaClassSource codeGenerated) {
    codeGenerated.addImport(getFullTypeName(data));

    if (isUnique(data)) {
        codeGenerated.addField()
                .setName(getTypeNameSuffix(data))
                .setType(getTypeName(data))
                .setLiteralInitializer(String.format("new %1$s();", getTypeName(data)))
                .setPublic();

    } else {
        MethodSource<JavaClassSource> methodGET = codeGenerated.addMethod()
                .setName(String.format("get%1$s", getTypeName(data)))
                .setReturnType(getTypeName(data))
                .setPublic();

        String typeName = getTypeName(data);
        List<TypeVariableSource<JavaClassSource>> generics = getGenericsData(data);
        if (generics != null && generics.size() > 0) {
            typeName += "<";
            for (TypeVariableSource<JavaClassSource> generic : generics) {
                String javaType[] = new String[generic.getBounds().size()];
                for (int i = 0; i < generic.getBounds().size(); i++) {
                    javaType[i] = (String) generic.getBounds().get(i).getSimpleName();
                }
                methodGET.addTypeVariable().setName(generic.getName()).setBounds(javaType);
                if (typeName.indexOf("<") != typeName.length() - 1) typeName += ",";
                typeName += generic.getName();
            }
            typeName += ">";

        }
        methodGET.setBody(String.format("return (%1$s)getComponent(%2$s.%3$s);"
                , typeName, (isSharedContext(data) ? "Shared" : contextName) + DEFAULT_COMPONENT_LOOKUP_TAG, getTypeName(data)));
    }
}
 
Example 7
Source File: ComponentEntityGenerator.java    From Entitas-Java with MIT License 5 votes vote down vote up
private void generateEntity(String contextName, ComponentData data) {
    String pkgDestiny = targetPackageConfig.getTargetPackage();
    CodeGenFile<JavaClassSource> genFile = getCodeGenFile(contextName, data);
    JavaClassSource codeGenerated = genFile.getFileContent();

    if (!pkgDestiny.endsWith(data.getSubDir())) {
        pkgDestiny += "." + data.getSubDir();

    }
    if (codeGenerated.getPackage() == null) {
        codeGenerated.setPackage(pkgDestiny);
        codeGenerated.addMethod()
                .setName(contextName + "Entity")
                .setPublic()
                .setConstructor(true)
                .setBody("");
        codeGenerated.addImport("ilargia.entitas.Entity");

    }

    if (shouldGenerateMethods(data)) {
        addImporEnums(data, codeGenerated);
        addEntityMethods(contextName, data, codeGenerated);
    }
    if (isSharedContext(data) && codeGenerated.getImport(targetPackageConfig.getTargetPackage()) == null) {
        codeGenerated.addImport(targetPackageConfig.getTargetPackage() + ".SharedComponentsLookup");
    }

}
 
Example 8
Source File: ComponentContextGenerator.java    From Entitas-Java with MIT License 5 votes vote down vote up
private void generateContext(String contextName, ComponentData data) {
    String pkgDestiny = targetPackageConfig.getTargetPackage();

    if (!contexts.containsKey(contextName)) {
        JavaClassSource sourceGen = Roaster.parse(JavaClassSource.class, String.format("public class %1$sContext extends Context<%1$sEntity> {}", contextName));
        CodeGenFile<JavaClassSource> genFile = new CodeGenFile<JavaClassSource>(contextName + "Context", sourceGen, data.getSubDir());
        contexts.put(contextName, genFile);
        JavaClassSource codeGenerated = genFile.getFileContent();

        if (!pkgDestiny.endsWith(data.getSubDir())) {
            pkgDestiny += "." + data.getSubDir();

        }

        codeGenerated.setPackage(pkgDestiny);
        codeGenerated.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, null);");
        codeGenerated.addImport("ilargia.entitas.Context");
        codeGenerated.addImport("ilargia.entitas.api.*");
        codeGenerated.addImport("ilargia.entitas.api.entitas.EntityBaseFactory");

        if (isUnique(data)) {
            addContextMethods(contextName, data, codeGenerated);
        }
    }
}
 
Example 9
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 10
Source File: ContextGenerator.java    From Entitas-Java with MIT License 5 votes vote down vote up
private void addImports(List<FieldSource<JavaClassSource>> memberInfos, JavaClassSource source) {
    for (FieldSource<JavaClassSource> info : memberInfos) {
        if (info.getOrigin().getImport(info.getType().toString()) != null) {
            if (source.getImport(info.getType().toString()) == null) {
                source.addImport(info.getType());
            }
        }
    }
}
 
Example 11
Source File: ContextGenerator.java    From Entitas-Java with MIT License 5 votes vote down vote up
private void addImports(List<FieldSource<JavaClassSource>> memberInfos, JavaClassSource source) {
    for (FieldSource<JavaClassSource> info : memberInfos) {
        if (info.getOrigin().getImport(info.getType().toString()) != null) {
            if (source.getImport(info.getType().toString()) == null) {
                source.addImport(info.getType());
            }
        }
    }
}
 
Example 12
Source File: CreateTestClassCommand.java    From thorntail-addon with Eclipse Public License 1.0 5 votes vote down vote up
private void addArquillianResourceEnricher(JavaClassSource test) {
    if (asClient.hasValue()) {
        test.addImport("org.jboss.arquillian.test.api.ArquillianResource");
        final FieldSource<JavaClassSource> urlField = test.addField();
        urlField
                .setName("url")
                .setType(URL.class)
                .setPrivate();

        urlField.addAnnotation("ArquillianResource");

    }
}
 
Example 13
Source File: CamelCommandsHelper.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static void createSpringComponentFactoryClass(JavaClassSource javaClass, CamelComponentDetails details, String camelComponentName,
                                                     String componentInstanceName, String configurationCode, Set<String> extraJavaImports) {
    javaClass.addAnnotation("Component");

    javaClass.addImport("org.springframework.beans.factory.config.BeanDefinition");
    javaClass.addImport("org.springframework.beans.factory.annotation.Qualifier");
    javaClass.addImport("org.springframework.context.annotation.Bean");
    javaClass.addImport("org.springframework.context.annotation.Scope");
    javaClass.addImport("org.springframework.stereotype.Component");
    javaClass.addImport(details.getComponentClassQName());
    if (extraJavaImports != null) {
        for (String extra : extraJavaImports) {
            javaClass.addImport(extra);
        }
    }

    String componentClassName = details.getComponentClassName();
    String methodName = "create" + Strings.capitalize(componentInstanceName) + "Component";

    String body = componentClassName + " component = new " + componentClassName + "();" + configurationCode + "\nreturn component;";

    MethodSource<JavaClassSource> method = javaClass.addMethod()
            .setPublic()
            .setReturnType(componentClassName)
            .setName(methodName)
            .setBody(body);

    method.addAnnotation("Qualifier").setStringValue(camelComponentName);
    method.addAnnotation("Bean");
    method.addAnnotation("Scope").setLiteralValue("BeanDefinition.SCOPE_SINGLETON");
}
 
Example 14
Source File: ComponentEntityGenerator.java    From Entitas-Java with MIT License 5 votes vote down vote up
private void addHasMethods(String contextName, ComponentData data, JavaClassSource source) {
    source.addImport(getFullTypeName(data));

    if (isUnique(data)) {
        source.addMethod()
                .setName(String.format("is%1$s", getTypeName(data)))
                .setReturnType("boolean")
                .setPublic()
                .setBody(String.format("return hasComponent(%1$s.%2$s);",
                        WordUtils.capitalize(isSharedContext(data) ? "Shared" : contextName) + DEFAULT_COMPONENT_LOOKUP_TAG,
                        getTypeName(data)));

        source.addMethod()
                .setName(String.format("set%1$s", getTypeName(data)))
                .setReturnType(contextName + "Entity")
                .setPublic()
                .setParameters("boolean value")
                .setBody(String.format(" if(value != hasComponent(%1$s.%2$s)) {\n" +
                                "                    if(value) {\n" +
                                "                        addComponent(%1$s.%2$s, %3$s);\n" +
                                "                    } else {\n" +
                                "                        removeComponent(%1$s.%2$s);\n" +
                                "                    }\n" +
                                "                }\n return this;", WordUtils.capitalize((isSharedContext(data) ? "Shared" : contextName) + DEFAULT_COMPONENT_LOOKUP_TAG),
                        getTypeName(data), getTypeNameSuffix(data)));


    } else {
        source.addMethod()
                .setName(String.format("has%1$s", getTypeName(data)))
                .setReturnType("boolean")
                .setPublic()
                .setBody(String.format("return hasComponent(%1$s.%2$s);",
                        WordUtils.capitalize((isSharedContext(data) ? "Shared" : contextName) + DEFAULT_COMPONENT_LOOKUP_TAG),
                        getTypeName(data)));

    }
}
 
Example 15
Source File: EhDaoGenerator.java    From EhViewer 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 16
Source File: CamelNewRouteBuilderCommand.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    Project project = getSelectedProject(context);
    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);

    // does the project already have camel?
    Dependency core = findCamelCoreDependency(project);
    if (core == null) {
        return Results.fail("The project does not include camel-core");
    }

    // do we already have a class with the name
    String fqn = targetPackage.getValue() != null ? targetPackage.getValue() + "." + name.getValue() : name.getValue();

    JavaResource existing = facet.getJavaResource(fqn);
    if (existing != null && existing.exists()) {
        return Results.fail("A class with name " + fqn + " already exists");
    }

    // need to parse to be able to extends another class
    final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
    javaClass.setName(name.getValue());
    if (targetPackage.getValue() != null) {
        javaClass.setPackage(targetPackage.getValue());
    }
    javaClass.setSuperType("RouteBuilder");
    javaClass.addImport("org.apache.camel.builder.RouteBuilder");

    boolean cdi = CamelCommandsHelper.isCdiProject(getSelectedProject(context));
    boolean spring = CamelCommandsHelper.isSpringProject(getSelectedProject(context));

    if (cdi) {
        javaClass.addAnnotation("javax.inject.Singleton");
    } else if (spring) {
        javaClass.addAnnotation("org.springframework.stereotype.Component");
    }

    javaClass.addMethod()
            .setPublic()
            .setReturnTypeVoid()
            .setName("configure")
            .addThrows(Exception.class).setBody("");

    JavaResource javaResource = facet.saveJavaSource(javaClass);

    // if we are in an GUI editor then open the file
    if (isRunningInGui(context.getUIContext())) {
        context.getUIContext().setSelection(javaResource);
    }

    return Results.success("Created new RouteBuilder class " + name.getValue());
}
 
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: 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 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();
}