use of com.google.common.base.Equivalence.Wrapper in project closure-templates by google.
the class ResolveExpressionTypesVisitor method addTypeSubstitutions.
// Given a map of type subsitutions, add all the entries to the current set of
// active substitutions.
private void addTypeSubstitutions(Map<Wrapper<ExprNode>, SoyType> substitutionsToAdd) {
for (Map.Entry<Wrapper<ExprNode>, SoyType> entry : substitutionsToAdd.entrySet()) {
ExprNode expr = entry.getKey().get();
// Get the existing type
SoyType previousType = expr.getType();
for (TypeSubstitution subst = substitutions; subst != null; subst = subst.parent) {
if (ExprEquivalence.get().equivalent(subst.expression, expr)) {
previousType = subst.type;
break;
}
}
// If the new type is different than the current type, then add a new type substitution.
if (!entry.getValue().equals(previousType)) {
substitutions = new TypeSubstitution(substitutions, expr, entry.getValue());
}
}
}
use of com.google.common.base.Equivalence.Wrapper in project gradle by gradle.
the class ManagedProxyClassGenerator method writeViewMethods.
private void writeViewMethods(ClassVisitor visitor, Type generatedType, Collection<ModelType<?>> viewTypes, StructBindings<?> bindings) {
Type delegateType;
StructSchema<?> delegateSchema = bindings.getDelegateSchema();
if (delegateSchema != null) {
Class<?> delegateClass = delegateSchema.getType().getRawClass();
declareDelegateField(visitor, delegateClass);
delegateType = Type.getType(delegateClass);
} else {
delegateType = null;
}
Multimap<String, ModelProperty<?>> viewPropertiesByNameBuilder = ArrayListMultimap.create();
Set<Wrapper<Method>> viewMethods = Sets.newLinkedHashSet();
for (StructSchema<?> viewSchema : bindings.getImplementedViewSchemas()) {
for (ModelType<?> viewType : viewTypes) {
if (viewType.equals(viewSchema.getType())) {
for (ModelProperty<?> property : viewSchema.getProperties()) {
String propertyName = property.getName();
viewPropertiesByNameBuilder.put(propertyName, property);
}
for (WeaklyTypeReferencingMethod<?, ?> viewMethod : viewSchema.getAllMethods()) {
viewMethods.add(SIGNATURE_EQUIVALENCE.wrap(viewMethod.getMethod()));
}
break;
}
}
}
Class<?> viewClass = bindings.getPublicSchema().getType().getConcreteClass();
for (Collection<ModelProperty<?>> viewProperties : viewPropertiesByNameBuilder.asMap().values()) {
writeViewPropertyDslMethods(visitor, generatedType, viewProperties, viewClass);
}
for (StructMethodBinding methodBinding : bindings.getMethodBindings()) {
WeaklyTypeReferencingMethod<?, ?> weakViewMethod = methodBinding.getViewMethod();
Method viewMethod = weakViewMethod.getMethod();
// Don't generate method if it's not part of the view schema
Wrapper<Method> methodKey = SIGNATURE_EQUIVALENCE.wrap(viewMethod);
if (!viewMethods.contains(methodKey)) {
continue;
}
if (methodBinding instanceof DirectMethodBinding) {
// TODO:LPTR What is with the "metaClass" property here?
boolean isGetterMethod = methodBinding.getAccessorType() == GET_GETTER || methodBinding.getAccessorType() == IS_GETTER;
if (isGetterMethod && !Modifier.isFinal(viewMethod.getModifiers()) && !viewMethod.getName().equals("getMetaClass")) {
writeNonAbstractMethodWrapper(visitor, generatedType, viewClass, viewMethod);
}
} else if (methodBinding instanceof BridgeMethodBinding) {
writeBridgeMethod(visitor, generatedType, viewMethod);
} else if (methodBinding instanceof DelegateMethodBinding) {
writeDelegatingMethod(visitor, generatedType, delegateType, viewMethod);
} else if (methodBinding instanceof ManagedPropertyMethodBinding) {
ManagedPropertyMethodBinding propertyBinding = (ManagedPropertyMethodBinding) methodBinding;
ManagedProperty<?> managedProperty = bindings.getManagedProperty(propertyBinding.getPropertyName());
String propertyName = managedProperty.getName();
Class<?> propertyClass = managedProperty.getType().getRawClass();
WeaklyTypeReferencingMethod<?, ?> propertyAccessor = propertyBinding.getViewMethod();
switch(propertyBinding.getAccessorType()) {
case GET_GETTER:
case IS_GETTER:
writeGetter(visitor, generatedType, propertyName, propertyClass, propertyAccessor);
break;
case SETTER:
writeSetter(visitor, generatedType, propertyName, propertyClass, propertyAccessor);
break;
default:
throw new AssertionError();
}
} else {
throw new AssertionError();
}
}
}
use of com.google.common.base.Equivalence.Wrapper in project gradle by gradle.
the class DefaultStructBindingsStore method collectMethodBindings.
private static <T> Set<StructMethodBinding> collectMethodBindings(StructBindingExtractionContext<T> extractionContext, Map<String, Multimap<PropertyAccessorType, StructMethodBinding>> propertyBindings) {
Collection<WeaklyTypeReferencingMethod<?, ?>> implementedMethods = collectImplementedMethods(extractionContext.getImplementedSchemas());
Map<Wrapper<Method>, WeaklyTypeReferencingMethod<?, ?>> publicViewImplMethods = collectPublicViewImplMethods(extractionContext.getPublicSchema());
Map<Wrapper<Method>, WeaklyTypeReferencingMethod<?, ?>> delegateMethods = collectDelegateMethods(extractionContext.getDelegateSchema());
ImmutableSet.Builder<StructMethodBinding> methodBindingsBuilder = ImmutableSet.builder();
for (WeaklyTypeReferencingMethod<?, ?> weakImplementedMethod : implementedMethods) {
Method implementedMethod = weakImplementedMethod.getMethod();
PropertyAccessorType accessorType = PropertyAccessorType.of(implementedMethod);
Wrapper<Method> methodKey = SIGNATURE_EQUIVALENCE.wrap(implementedMethod);
WeaklyTypeReferencingMethod<?, ?> weakDelegateImplMethod = delegateMethods.get(methodKey);
WeaklyTypeReferencingMethod<?, ?> weakPublicImplMethod = publicViewImplMethods.get(methodKey);
if (weakDelegateImplMethod != null && weakPublicImplMethod != null) {
extractionContext.add(weakImplementedMethod, String.format("it is both implemented by the view '%s' and the delegate type '%s'", extractionContext.getPublicSchema().getType().getDisplayName(), extractionContext.getDelegateSchema().getType().getDisplayName()));
}
String propertyName = accessorType == null ? null : accessorType.propertyNameFor(implementedMethod);
StructMethodBinding binding;
if (!Modifier.isAbstract(implementedMethod.getModifiers())) {
binding = new DirectMethodBinding(weakImplementedMethod, accessorType);
} else if (weakPublicImplMethod != null) {
binding = new BridgeMethodBinding(weakImplementedMethod, weakPublicImplMethod, accessorType);
} else if (weakDelegateImplMethod != null) {
binding = new DelegateMethodBinding(weakImplementedMethod, weakDelegateImplMethod, accessorType);
} else if (propertyName != null) {
binding = new ManagedPropertyMethodBinding(weakImplementedMethod, propertyName, accessorType);
} else {
handleNoMethodImplementation(extractionContext, weakImplementedMethod);
continue;
}
methodBindingsBuilder.add(binding);
if (accessorType != null) {
Multimap<PropertyAccessorType, StructMethodBinding> accessorBindings = propertyBindings.get(propertyName);
if (accessorBindings == null) {
accessorBindings = ArrayListMultimap.create();
propertyBindings.put(propertyName, accessorBindings);
}
accessorBindings.put(accessorType, binding);
}
}
return methodBindingsBuilder.build();
}
use of com.google.common.base.Equivalence.Wrapper in project gradle by gradle.
the class StructSchemaExtractionStrategySupport method selectProperties.
private Iterable<ModelPropertyExtractionContext> selectProperties(final ModelSchemaExtractionContext<?> context, CandidateMethods candidateMethods) {
Map<String, ModelPropertyExtractionContext> propertiesMap = Maps.newTreeMap();
for (Map.Entry<Wrapper<Method>, Collection<Method>> entry : candidateMethods.allMethods().entrySet()) {
Method method = entry.getKey().get();
PropertyAccessorType propertyAccessorType = PropertyAccessorType.of(method);
Collection<Method> methodsWithEqualSignature = entry.getValue();
if (propertyAccessorType != null) {
String propertyName = propertyAccessorType.propertyNameFor(method);
ModelPropertyExtractionContext propertyContext = propertiesMap.get(propertyName);
if (propertyContext == null) {
propertyContext = new ModelPropertyExtractionContext(propertyName);
propertiesMap.put(propertyName, propertyContext);
}
propertyContext.addAccessor(new PropertyAccessorExtractionContext(propertyAccessorType, methodsWithEqualSignature));
}
}
return Collections2.filter(propertiesMap.values(), new Predicate<ModelPropertyExtractionContext>() {
@Override
public boolean apply(ModelPropertyExtractionContext property) {
return property.isReadable();
}
});
}
Aggregations