use of java.util.StringJoiner in project aic-praise by aic-sri-international.
the class PRAiSE method getLegalModelLanguageCodesDescription.
private static String getLegalModelLanguageCodesDescription() {
StringJoiner result = new StringJoiner(", ");
Arrays.stream(ModelLanguage.values()).forEach(ml -> result.add(ml.getCode()));
return result.toString();
}
use of java.util.StringJoiner in project requery by requery.
the class EntityGenerator method generateConstructors.
private void generateConstructors(TypeSpec.Builder builder) {
// copy the existing constructors
for (ExecutableElement constructor : ElementFilter.constructorsIn(typeElement.getEnclosedElements())) {
// constructor params
List<? extends VariableElement> parameters = constructor.getParameters();
if (!parameters.isEmpty()) {
MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder();
constructorBuilder.addModifiers(constructor.getModifiers());
List<String> parameterNames = new ArrayList<>();
for (VariableElement parameter : parameters) {
Modifier[] modifiers = parameter.getModifiers().toArray(new Modifier[parameter.getModifiers().size()]);
String parameterName = parameter.getSimpleName().toString();
parameterNames.add(parameterName);
ParameterSpec.Builder parameterBuilder = ParameterSpec.builder(TypeName.get(parameter.asType()), parameterName, modifiers);
constructorBuilder.addParameter(parameterBuilder.build());
}
// super parameter/arguments
StringJoiner joiner = new StringJoiner(",", "(", ")");
parameterNames.forEach(joiner::add);
constructorBuilder.addStatement("super" + joiner.toString());
builder.addMethod(constructorBuilder.build());
}
}
}
use of java.util.StringJoiner in project requery by requery.
the class EntityMetaGenerator method generateType.
private void generateType(TypeSpec.Builder builder, TypeName targetName) {
CodeBlock.Builder block = CodeBlock.builder().add("new $T<$T>($T.class, $S)\n", TypeBuilder.class, targetName, targetName, entity.tableName());
block.add(".setBaseType($T.class)\n", ClassName.get(typeElement)).add(".setCacheable($L)\n", entity.isCacheable()).add(".setImmutable($L)\n", entity.isImmutable()).add(".setReadOnly($L)\n", entity.isReadOnly()).add(".setStateless($L)\n", entity.isStateless()).add(".setView($L)\n", entity.isView());
String factoryName = entity.classFactoryName();
if (!Names.isEmpty(factoryName)) {
block.add(".setFactory(new $L())\n", ClassName.bestGuess(factoryName));
} else if (entity.isImmutable()) {
// returns this class as the builder
TypeSpec.Builder supplier = TypeSpec.anonymousClassBuilder("").addSuperinterface(parameterizedTypeName(Supplier.class, typeName));
supplier.addMethod(CodeGeneration.overridePublicMethod("get").returns(typeName).addStatement("return new $T()", typeName).build());
block.add(".setBuilderFactory($L)\n", supplier.build());
MethodSpec.Builder applyMethod = CodeGeneration.overridePublicMethod("apply").addParameter(typeName, "value").returns(targetName);
// add embedded builder calls
entity.attributes().values().stream().filter(AttributeDescriptor::isEmbedded).forEach(attribute -> graph.embeddedDescriptorOf(attribute).ifPresent(embedded -> embedded.builderType().ifPresent(type -> {
String fieldName = attribute.fieldName() + "Builder";
String methodName = attribute.setterName();
applyMethod.addStatement("value.builder.$L(value.$L.build())", methodName, fieldName);
})));
applyMethod.addStatement(entity.builderType().isPresent() ? "return value.builder.build()" : "return value.build()");
TypeSpec.Builder buildFunction = TypeSpec.anonymousClassBuilder("").addSuperinterface(parameterizedTypeName(Function.class, typeName, targetName)).addMethod(applyMethod.build());
block.add(".setBuilderFunction($L)\n", buildFunction.build());
} else {
TypeSpec.Builder typeFactory = TypeSpec.anonymousClassBuilder("").addSuperinterface(parameterizedTypeName(Supplier.class, targetName)).addMethod(CodeGeneration.overridePublicMethod("get").addStatement("return new $T()", targetName).returns(targetName).build());
block.add(".setFactory($L)\n", typeFactory.build());
}
ParameterizedTypeName proxyType = parameterizedTypeName(EntityProxy.class, targetName);
TypeSpec.Builder proxyProvider = TypeSpec.anonymousClassBuilder("").addSuperinterface(parameterizedTypeName(Function.class, targetName, proxyType));
MethodSpec.Builder proxyFunction = CodeGeneration.overridePublicMethod("apply").addParameter(targetName, "entity").returns(proxyType);
if (entity.isImmutable() || entity.isUnimplementable()) {
proxyFunction.addStatement("return new $T(entity, $L)", proxyType, TYPE_NAME);
} else {
proxyFunction.addStatement("return entity.$L", PROXY_NAME);
}
proxyProvider.addMethod(proxyFunction.build());
block.add(".setProxyProvider($L)\n", proxyProvider.build());
if (entity.tableAttributes().length > 0) {
StringJoiner joiner = new StringJoiner(",", "new String[] {", "}");
for (String attribute : entity.tableAttributes()) {
joiner.add("\"" + attribute + "\"");
}
block.add(".setTableCreateAttributes($L)\n", joiner.toString());
}
if (entity.tableUniqueIndexes().length > 0) {
StringJoiner joiner = new StringJoiner(",", "new String[] {", "}");
for (String attribute : entity.tableUniqueIndexes()) {
joiner.add("\"" + attribute + "\"");
}
block.add(".setTableUniqueIndexes($L)\n", joiner.toString());
}
attributeNames.forEach(name -> block.add(".addAttribute($L)\n", name));
expressionNames.forEach(name -> block.add(".addExpression($L)\n", name));
block.add(".build()");
ParameterizedTypeName type = parameterizedTypeName(Type.class, targetName);
builder.addField(FieldSpec.builder(type, TYPE_NAME, Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL).initializer("$L", block.build()).build());
}
use of java.util.StringJoiner in project jabref by JabRef.
the class FileAnnotationTab method copyToClipboard.
/**
* Copies the meta and content information of the pdf annotation to the clipboard
*/
private void copyToClipboard() {
StringJoiner sj = new StringJoiner(System.getProperty("line.separator"));
sj.add(Localization.lang("Author") + ": " + authorArea.getText());
sj.add(Localization.lang("Date") + ": " + dateArea.getText());
sj.add(Localization.lang("Page") + ": " + pageArea.getText());
sj.add(Localization.lang("Content") + ": " + contentTxtArea.getText());
sj.add(Localization.lang("Marking") + ": " + markedTxtArea.getText());
new ClipBoardManager().setClipboardContents(sj.toString());
}
use of java.util.StringJoiner in project JMRI by JMRI.
the class WebAppManager method getAngularRoutes.
public String getAngularRoutes(Profile profile, Locale locale) {
// NOI18N
StringJoiner routes = new StringJoiner("\n", "\n", "");
Set<AngularRoute> items = new HashSet<>();
this.getManifests(profile).forEach((WebManifest manifest) -> {
items.addAll(manifest.getAngularRoutes());
});
items.forEach((route) -> {
if (route.getRedirection() != null) {
// NOI18N
routes.add(String.format(" .when('%s', { redirectTo: '%s' })", route.getWhen(), route.getRedirection()));
} else if (route.getTemplate() != null && route.getController() != null) {
// NOI18N
routes.add(String.format(" .when('%s', { templateUrl: '%s', controller: '%s' })", route.getWhen(), route.getTemplate(), route.getController()));
}
});
return routes.toString();
}
Aggregations