use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.
the class LazyClosureCompiler method compileLazyExpression.
Expression compileLazyExpression(String namePrefix, SoyNode declaringNode, String varName, ExprNode exprNode) {
Optional<Expression> asSoyValueProvider = expressionToSoyValueProviderCompiler.compileAvoidingDetaches(exprNode);
if (asSoyValueProvider.isPresent()) {
return asSoyValueProvider.get();
}
TypeInfo type = innerClasses.registerInnerClassWithGeneratedName(getProposedName(namePrefix, varName), LAZY_CLOSURE_ACCESS);
SoyClassWriter writer = SoyClassWriter.builder(type).setAccess(LAZY_CLOSURE_ACCESS).extending(DETACHABLE_VALUE_PROVIDER_TYPE).sourceFileName(declaringNode.getSourceLocation().getFileName()).build();
Expression expr = new CompilationUnit(writer, type, DETACHABLE_VALUE_PROVIDER_TYPE, declaringNode).compileExpression(exprNode);
innerClasses.registerAsInnerClass(writer, type);
writer.visitEnd();
innerClasses.add(writer.toClassData());
return expr;
}
use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.
the class ProtoUtils method getBuilderMethod.
/**
* Returns the {@link MethodRef} for the generated newBuilder method.
*/
private static MethodRef getBuilderMethod(Descriptor descriptor) {
TypeInfo message = messageRuntimeType(descriptor);
TypeInfo builder = builderRuntimeType(descriptor);
return MethodRef.createStaticMethod(message, new Method("newBuilder", builder.type(), NO_METHOD_ARGS)).asNonNullable();
}
use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.
the class ProtoUtils method getSetOrAddMethod.
/**
* Returns the {@link MethodRef} for the generated setter/adder method.
*/
private static MethodRef getSetOrAddMethod(FieldDescriptor descriptor) {
TypeInfo builder = builderRuntimeType(descriptor.getContainingType());
String prefix = descriptor.isRepeated() ? "add" : "set";
boolean isProto3EnumField = isProto3EnumField(descriptor);
String suffix = isProto3EnumField ? "Value" : "";
return MethodRef.createInstanceMethod(builder, new Method(prefix + getFieldName(descriptor, true) + suffix, builder.type(), new Type[] { isProto3EnumField ? Type.INT_TYPE : getRuntimeType(descriptor) })).asNonNullable();
}
use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.
the class CompiledTemplateMetadata method create.
static CompiledTemplateMetadata create(String templateName, TemplateNode node) {
String className = Names.javaClassNameFromSoyTemplateName(templateName);
TypeInfo type = TypeInfo.create(className);
return new AutoValue_CompiledTemplateMetadata(ConstructorRef.create(type, GENERATED_CONSTRUCTOR), MethodRef.createInstanceMethod(type, RENDER_METHOD).asNonNullable(), MethodRef.createInstanceMethod(type, KIND_METHOD).asCheap(), type, node);
}
use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.
the class TemplateFactoryCompiler method compile.
/**
* Compiles the factory.
*/
void compile() {
TypeInfo factoryType = innerClasses.registerInnerClass(FACTORY_CLASS, FACTORY_ACCESS);
SoyClassWriter cw = SoyClassWriter.builder(factoryType).implementing(FACTORY_TYPE).setAccess(FACTORY_ACCESS).sourceFileName(template.node().getSourceLocation().getFileName()).build();
innerClasses.registerAsInnerClass(cw, factoryType);
generateStaticInitializer(cw);
defineDefaultConstructor(cw, factoryType);
generateCreateMethod(cw, factoryType);
cw.visitEnd();
innerClasses.add(cw.toClassData());
}
Aggregations