Search in sources :

Example 1 with TypeInfo

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;
}
Also used : Statement.returnExpression(com.google.template.soy.jbcsrc.restricted.Statement.returnExpression) SoyExpression(com.google.template.soy.jbcsrc.restricted.SoyExpression) Expression(com.google.template.soy.jbcsrc.restricted.Expression) SoyClassWriter(com.google.template.soy.jbcsrc.internal.SoyClassWriter) TypeInfo(com.google.template.soy.jbcsrc.restricted.TypeInfo)

Example 2 with TypeInfo

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();
}
Also used : Method(org.objectweb.asm.commons.Method) TypeInfo(com.google.template.soy.jbcsrc.restricted.TypeInfo)

Example 3 with TypeInfo

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();
}
Also used : ByteString(com.google.protobuf.ByteString) Method(org.objectweb.asm.commons.Method) TypeInfo(com.google.template.soy.jbcsrc.restricted.TypeInfo)

Example 4 with TypeInfo

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);
}
Also used : TypeInfo(com.google.template.soy.jbcsrc.restricted.TypeInfo)

Example 5 with TypeInfo

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());
}
Also used : SoyClassWriter(com.google.template.soy.jbcsrc.internal.SoyClassWriter) TypeInfo(com.google.template.soy.jbcsrc.restricted.TypeInfo)

Aggregations

TypeInfo (com.google.template.soy.jbcsrc.restricted.TypeInfo)15 Method (org.objectweb.asm.commons.Method)6 SoyClassWriter (com.google.template.soy.jbcsrc.internal.SoyClassWriter)4 ByteString (com.google.protobuf.ByteString)2 Expression (com.google.template.soy.jbcsrc.restricted.Expression)2 SoyExpression (com.google.template.soy.jbcsrc.restricted.SoyExpression)2 Statement.returnExpression (com.google.template.soy.jbcsrc.restricted.Statement.returnExpression)2 JSType (com.google.protobuf.DescriptorProtos.FieldOptions.JSType)1 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)1 JavaType (com.google.protobuf.Descriptors.FieldDescriptor.JavaType)1 ProtoUtils.getJsType (com.google.template.soy.internal.proto.ProtoUtils.getJsType)1 ProtoUtils.hasJsType (com.google.template.soy.internal.proto.ProtoUtils.hasJsType)1 ClassData (com.google.template.soy.jbcsrc.internal.ClassData)1 CodeBuilder (com.google.template.soy.jbcsrc.restricted.CodeBuilder)1 SoyRuntimeType (com.google.template.soy.jbcsrc.restricted.SoyRuntimeType)1 Statement (com.google.template.soy.jbcsrc.restricted.Statement)1 BooleanInvoker (com.google.template.soy.jbcsrc.restricted.testing.ExpressionTester.BooleanInvoker)1 ListType (com.google.template.soy.types.ListType)1 MapType (com.google.template.soy.types.MapType)1 SanitizedType (com.google.template.soy.types.SanitizedType)1