本文整理汇总了Java中org.jboss.forge.roaster.model.source.JavaClassSource.addImport方法的典型用法代码示例。如果您正苦于以下问题:Java JavaClassSource.addImport方法的具体用法?Java JavaClassSource.addImport怎么用?Java JavaClassSource.addImport使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.forge.roaster.model.source.JavaClassSource
的用法示例。
在下文中一共展示了JavaClassSource.addImport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJavaComponentFactoryClass
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
public static void createJavaComponentFactoryClass(JavaClassSource javaClass, CamelComponentDetails details, String camelComponentName,
String componentInstanceName, String configurationCode, Set<String> extraJavaImports) {
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;";
javaClass.addMethod()
.setPublic()
.setReturnType(componentClassName)
.setName(methodName)
.setBody(body);
}
示例2: createJavaSourceForComponent
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
private void createJavaSourceForComponent(Project project, String schemeName, String packageName, String className) {
JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
String fqn = packageName + "." + className;
JavaResource existing = facet.getJavaResource(fqn);
if (existing != null && existing.exists()) {
// override existing
existing.delete();
}
// need to parse to be able to extends another class
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
javaClass.setName(className);
javaClass.setPackage(packageName);
javaClass.setSuperType("DjangoComponent");
javaClass.addImport("io.fabric8.django.component.connector.DjangoComponent");
// add public no-arg constructor
javaClass.addMethod().setPublic().setConstructor(true).setBody("super(\"" + schemeName + "\", \"" + fqn + "\");");
facet.saveJavaSource(javaClass);
}
示例3: addContextAddMethods
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
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);
}
}
示例4: addAddressAnnotations
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
protected void addAddressAnnotations(JavaClassSource type, ClassPlan plan) {
AddressTemplate address = plan.getAddr();
// resource references
if (1 == plan.getAddresses().size()) {
type.addImport(Address.class);
AnnotationSource<JavaClassSource> addressMeta = type.addAnnotation(Address.class);
addressMeta.setStringValue(plan.getAddresses().get(0).toString());
} else {
type.addImport(Addresses.class);
String[] addresses = new String[plan.getAddresses().size()];
int i = 0;
for (AddressTemplate addressTemplate : plan.getAddresses()) {
addresses[i] = addressTemplate.toString();
i++;
}
AnnotationSource<JavaClassSource> addressesMeta = type.addAnnotation(Addresses.class);
addressesMeta.setStringArrayValue(addresses);
}
}
示例5: createContextFields
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
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();
});
}
示例6: generateMatchers
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
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("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;
}
示例7: probe
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
/**
* Creates an implementation of the network probe. The created class extends
* {@link ExternalProbe}, setting the queuing server's connection data.
*
* @param modified
* The modified service interface
* @return The created source code
*/
public JavaClassSource probe(final JavaInterfaceSource modified) {
File file = new File(this.interfacePath);
String className = new NameProposal("NetworkLatencyProbe.java",
file.getParentFile()).getNewName();
JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
// Set general properties
javaClass.setName(className);
javaClass.setPackage(modified.getPackage());
javaClass.setSuperType(ExternalProbe.class);
// Add imports
javaClass.addImport(ExternalProbe.class);
javaClass.addImport(PascaniRuntime.Context.class);
Context context = Context.PROBE;
String body = NetworkLatencyTemplates.getProbeInitialization(
this.routingKey, context);
javaClass.addMethod().setConstructor(true).setBody(body)
.addThrows(Exception.class);
return javaClass;
}
示例8: addDefaultDeploymentAnnotation
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
private void addDefaultDeploymentAnnotation(JavaClassSource test, Project project) throws ClassNotFoundException, IOException {
test.addImport("org.wildfly.swarm.arquillian.DefaultDeployment");
final AnnotationSource<JavaClassSource> defaultDeploymentAnnotation = test.addAnnotation("DefaultDeployment");
if (asClient.hasValue())
{
defaultDeploymentAnnotation.setLiteralValue("testable", "false");
}
if (mainClass.hasValue())
{
defaultDeploymentAnnotation.setLiteralValue("main", mainClass.getValue() + ".class");
}
if (archiveType.hasValue())
{
defaultDeploymentAnnotation.setLiteralValue("type", String.format("DefaultDeployment.Type.%s", archiveType.getValue()));
}
}
示例9: createContextFields
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
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();
});
}
示例10: addComponentTypes
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
public void addComponentTypes(List<ComponentData> dataList, JavaClassSource codGenerated) {
String format = " %1$s%2$s,\n";
String code = "return new Class[] {";
for (ComponentData data : dataList) {
code += String.format(format, getTypeName(data), ".class");
codGenerated.addImport(getFullTypeName(data));
}
StringBuilder codeFinal = new StringBuilder(code);
if (code.endsWith(",\n")) {
codeFinal.replace(code.lastIndexOf(",\n"), code.lastIndexOf(",") + 1, " }; ");
}
codGenerated.addMethod()
.setName("componentTypes")
.setReturnType("Class[]")
.setPublic()
.setStatic(true)
.setBody(codeFinal.toString());
}
示例11: generateMatcher
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
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);
}
示例12: decorateSource
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Override
public JavaClassSource decorateSource(UIExecutionContext context, Project project, JavaClassSource source)
throws Exception
{
source.addImport("org.wildfly.swarm.Swarm");
MethodSource<JavaClassSource> method = source.addMethod()
.setPublic()
.setStatic(true)
.setReturnTypeVoid()
.setName("main")
.addThrows(Exception.class);
method.addParameter("String[]", "args");
StringBuilder body = new StringBuilder();
body.append("Swarm swarm = new Swarm();").append(System.lineSeparator());
body.append("swarm.start();").append(System.lineSeparator());
body.append("swarm.deploy();");
method.setBody(body.toString());
WildFlySwarmFacet facet = project.getFacet(WildFlySwarmFacet.class);
WildFlySwarmConfigurationBuilder newConfig = WildFlySwarmConfigurationBuilder.create(facet.getConfiguration());
newConfig.mainClass(source.getQualifiedName());
facet.setConfiguration(newConfig);
return source;
}
示例13: generateFrom
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Override
public List<JavaClassSource> generateFrom(RestGenerationContext context) throws Exception
{
JavaClassSource entity = context.getEntity();
Project project = context.getProject();
if (!entity.hasAnnotation(XmlRootElement.class))
{
entity.addAnnotation(XmlRootElement.class);
project.getFacet(JavaSourceFacet.class).saveJavaSource(entity);
}
String idType = JPAEntityUtil.resolveIdType(entity);
String idGetterName = JPAEntityUtil.resolveIdGetterName(entity);
String entityTable = JPAEntityUtil.getEntityTable(entity);
String selectExpression = JPAEntityUtil.getSelectExpression(entity, entityTable);
String idClause = JPAEntityUtil.getIdClause(entity, entityTable);
String orderClause = JPAEntityUtil.getOrderClause(entity,
JPAEntityUtil.getJpqlEntityVariable(entityTable));
String resourcePath = getResourcePath(context);
Map<Object, Object> map = new HashMap<>();
map.put("entity", entity);
map.put("idType", idType);
map.put("getIdStatement", idGetterName);
map.put("contentType", "\"application/json\""); // fixme: hardcoded JSON representation
map.put("entityTable", entityTable);
map.put("selectExpression", selectExpression);
map.put("idClause", idClause);
map.put("orderClause", orderClause);
map.put("resourcePath", resourcePath);
map.put("idIsPrimitive", Types.isPrimitive(idType));
Resource<URL> templateResource = resourceFactory.create(getClass().getResource("Endpoint.jv"));
Template processor = templateFactory.create(templateResource, FreemarkerTemplate.class);
String output = processor.process(map);
JavaClassSource resource = Roaster.parse(JavaClassSource.class, output);
resource.addImport(entity.getQualifiedName());
resource.setPackage(context.getTargetPackageName());
return Arrays.asList(resource);
}
示例14: createCdiComponentProducerClass
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
public static void createCdiComponentProducerClass(JavaClassSource javaClass, CamelComponentDetails details, String camelComponentName,
String componentInstanceName, String configurationCode, Set<String> extraJavaImports) {
javaClass.addImport("javax.enterprise.inject.Produces");
javaClass.addImport("javax.inject.Singleton");
javaClass.addImport("javax.inject.Named");
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("Named").setStringValue(camelComponentName);
method.addAnnotation("Produces");
method.addAnnotation("Singleton");
}
示例15: createSpringComponentFactoryClass
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
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");
}