use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.
the class ProtoUtils method getExtensionField.
/**
* Returns the {@link FieldRef} for the generated {@link Extension} field.
*/
private static FieldRef getExtensionField(FieldDescriptor descriptor) {
Preconditions.checkArgument(descriptor.isExtension(), "%s is not an extension", descriptor);
String extensionFieldName = getFieldName(descriptor, false);
if (descriptor.getExtensionScope() != null) {
TypeInfo owner = messageRuntimeType(descriptor.getExtensionScope());
return FieldRef.createPublicStaticField(owner, extensionFieldName, EXTENSION_TYPE);
}
// else we have a 'top level extension'
String containingClass = JavaQualifiedNames.getPackage(descriptor.getFile()) + "." + JavaQualifiedNames.getOuterClassname(descriptor.getFile());
return FieldRef.createPublicStaticField(TypeInfo.create(containingClass), extensionFieldName, EXTENSION_TYPE);
}
use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.
the class ProtoUtils method getPutMethod.
/**
* Returns the {@link MethodRef} for the generated put method for proto map.
*/
private static MethodRef getPutMethod(FieldDescriptor descriptor) {
Preconditions.checkState(descriptor.isMapField());
List<FieldDescriptor> mapFields = descriptor.getMessageType().getFields();
TypeInfo builder = builderRuntimeType(descriptor.getContainingType());
return MethodRef.createInstanceMethod(builder, new Method("put" + getFieldName(descriptor, true), builder.type(), new Type[] { getRuntimeType(mapFields.get(0)), getRuntimeType(mapFields.get(1)) }));
}
use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.
the class InnerClasses method registerInnerClassWithGeneratedName.
/**
* Register the name (or a simpl mangling of it) as an inner class with the given access
* modifiers.
*
* @return A {@link TypeInfo} with the full (possibly mangled) class name
*/
public TypeInfo registerInnerClassWithGeneratedName(String simpleName, int accessModifiers) {
simpleName = classNames.generateName(simpleName);
TypeInfo innerClass = outer.innerClass(simpleName);
innerClassesAccessModifiers.put(innerClass, accessModifiers);
return innerClass;
}
use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.
the class InnerClasses method registerInnerClass.
/**
* Register the given name as an inner class with the given access modifiers.
*
* @return A {@link TypeInfo} with the full class name
*/
public TypeInfo registerInnerClass(String simpleName, int accessModifiers) {
classNames.claimName(simpleName);
TypeInfo innerClass = outer.innerClass(simpleName);
innerClassesAccessModifiers.put(innerClass, accessModifiers);
return innerClass;
}
use of com.google.template.soy.jbcsrc.restricted.TypeInfo in project closure-templates by google.
the class MemoryClassLoaderTest method testDelegation.
@Test
public void testDelegation() throws Exception {
// We want to make sure that for generated types, our classloader doesn't delegate to its parent
// loader
ClassData parentClass = ExpressionTester.createClass(BooleanInvoker.class, FALSE);
ClassData childClass = ExpressionTester.createClass(BooleanInvoker.class, TRUE);
// sanity check, they have the same fully qualified class name
assertThat(parentClass.type()).isEqualTo(childClass.type());
TypeInfo type = childClass.type();
MemoryClassLoader parentLoader = new MemoryClassLoader(ImmutableList.of(parentClass));
MemoryClassLoader childLoader = new MemoryClassLoader(parentLoader, ImmutableList.of(childClass));
BooleanInvoker fromParent = parentLoader.loadClass(type.className()).asSubclass(BooleanInvoker.class).getConstructor().newInstance();
assertThat(fromParent.invoke()).isFalse();
BooleanInvoker fromChild = childLoader.loadClass(type.className()).asSubclass(BooleanInvoker.class).getConstructor().newInstance();
assertThat(fromChild.invoke()).isTrue();
assertThat(fromChild.getClass()).isNotEqualTo(fromParent.getClass());
}
Aggregations