use of org.immutables.generator.processor.ImmutableTrees.Unit in project immutables by immutables.
the class Processor method generateTemplateType.
private void generateTemplateType(TypeElement templateType) throws IOException, Exception {
SwissArmyKnife knife = new SwissArmyKnife(processingEnv, templateType);
String string = readTemplateResource(templateType, knife);
Unit unit = parseUnit(string);
Unit resolved = transformUnit(knife, unit);
TemplateWriter writingTransformer = new TemplateWriter(knife, templateType, GeneratedTypes.getSimpleName(templateType));
CharSequence template = writingTransformer.toCharSequence(resolved);
JavaFileObject templateFile = knife.environment.getFiler().createSourceFile(GeneratedTypes.getQualifiedName(knife.elements, templateType), templateType);
try (Writer writer = templateFile.openWriter()) {
writer.append(template);
}
}
use of org.immutables.generator.processor.ImmutableTrees.Unit in project immutables by immutables.
the class RunParser method main.
public static void main(String... args) {
Parser templateParser = Parboiled.createParser(Parser.class);
ParsingResult<Object> result = new ReportingParseRunner<>(templateParser.Unit()).run(input2);
ImmutableList<Object> copy = ImmutableList.copyOf(result.valueStack.iterator());
if (!copy.isEmpty()) {
Unit unit = (Unit) copy.get(0);
Unit balance = Balancing.balance(unit);
System.out.println(balance);
}
if (result.hasErrors()) {
System.err.println(ErrorUtils.printParseErrors(result.parseErrors));
}
// System.out.println(ParseTreeUtils.printNodeTree(result));
}
use of org.immutables.generator.processor.ImmutableTrees.Unit in project immutables by immutables.
the class Processor method transformUnit.
private Unit transformUnit(SwissArmyKnife knife, Unit unit) {
Unit trimmed = Spacing.normalize(unit);
Unit balanced = Balancing.balance(trimmed);
Unit optimized = Inliner.optimize(balanced);
Unit resolved = new TypeResolver(knife).resolve(optimized);
return resolved;
}
use of org.immutables.generator.processor.ImmutableTrees.Unit in project immutables by immutables.
the class TemplateWriter method toUnit.
@Override
public Unit toUnit(Unit value) {
context.out("package ", knife.elements.getPackageOf(sourceElement).getQualifiedName(), ";").ln().ln().out("import static ", Intrinsics.class, ".*;").ln().ln();
context.out("@", SuppressWarnings.class, "(", toLiteral("all"), ")").ln().out("public class ", simpleName, " extends ", sourceElement.getQualifiedName()).out(" ").openBrace();
int braces = context.getAndSetPendingBraces(0);
Unit unit = super.toUnit(value);
writeTemplateDispatch(context);
context.getAndSetPendingBraces(braces);
context.ln().closeBraces().ln();
return unit;
}
Aggregations