Search in sources :

Example 6 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)

Example 7 with TypeInfo

use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.

the class InnerClasses method registerAllInnerClasses.

/**
 * Registers all inner classes to the given outer class.
 */
public void registerAllInnerClasses(ClassVisitor visitor) {
    for (Map.Entry<TypeInfo, Integer> entry : innerClassesAccessModifiers.entrySet()) {
        TypeInfo innerClass = entry.getKey();
        doRegister(visitor, innerClass);
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TypeInfo(com.google.template.soy.jbcsrc.restricted.TypeInfo)

Example 8 with TypeInfo

use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.

the class LazyClosureCompiler method compileLazyContent.

Expression compileLazyContent(String namePrefix, RenderUnitNode renderUnit, String varName) {
    Optional<Expression> asRawText = asRawTextOnly(renderUnit);
    if (asRawText.isPresent()) {
        return asRawText.get();
    }
    TypeInfo type = innerClasses.registerInnerClassWithGeneratedName(getProposedName(namePrefix, varName), LAZY_CLOSURE_ACCESS);
    SoyClassWriter writer = SoyClassWriter.builder(type).setAccess(LAZY_CLOSURE_ACCESS).extending(DETACHABLE_CONTENT_PROVIDER_TYPE).sourceFileName(renderUnit.getSourceLocation().getFileName()).build();
    Expression expr = new CompilationUnit(writer, type, DETACHABLE_CONTENT_PROVIDER_TYPE, renderUnit).compileRenderable(renderUnit);
    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 9 with TypeInfo

use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.

the class ProtoUtils method getGetterMethod.

/**
 * Returns the {@link MethodRef} for the generated getter method.
 */
private static MethodRef getGetterMethod(FieldDescriptor descriptor) {
    Preconditions.checkArgument(!descriptor.isExtension(), "extensions do not have getter methods. %s", descriptor);
    TypeInfo message = messageRuntimeType(descriptor.getContainingType());
    boolean isProto3Enum = isProto3EnumField(descriptor);
    return MethodRef.createInstanceMethod(message, new Method("get" + getFieldName(descriptor, true) + // For proto3 enums we access the Value field
    (isProto3Enum ? "Value" : ""), isProto3Enum ? Type.INT_TYPE : getRuntimeType(descriptor), NO_METHOD_ARGS)).asNonNullable().asCheap();
}
Also used : Method(org.objectweb.asm.commons.Method) TypeInfo(com.google.template.soy.jbcsrc.restricted.TypeInfo)

Example 10 with TypeInfo

use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.

the class ProtoUtils method getBuildMethod.

/**
 * Returns the {@link MethodRef} for the generated build method.
 */
private static MethodRef getBuildMethod(Descriptor descriptor) {
    TypeInfo message = messageRuntimeType(descriptor);
    TypeInfo builder = builderRuntimeType(descriptor);
    return MethodRef.createInstanceMethod(builder, new Method("build", message.type(), NO_METHOD_ARGS)).asNonNullable();
}
Also used : Method(org.objectweb.asm.commons.Method) 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