public static <T extends Field> ImmutableMap<String, T> getFieldsForType(
      Descriptor descriptor, Set<FieldDescriptor> extensions, Factory<T> factory) {
    ImmutableMap.Builder<String, T> fields = ImmutableMap.builder();
    for (FieldDescriptor fieldDescriptor : descriptor.getFields()) {
      if (ProtoUtils.shouldJsIgnoreField(fieldDescriptor)) {
        continue;
      }
      T field = factory.create(fieldDescriptor);
      fields.put(field.getName(), field);
    }

    SetMultimap<String, T> extensionsBySoyName = MultimapBuilder.hashKeys().hashSetValues().build();
    for (FieldDescriptor extension : extensions) {
      T field = factory.create(extension);
      extensionsBySoyName.put(field.getName(), field);
    }

    for (Map.Entry<String, Set<T>> group : Multimaps.asMap(extensionsBySoyName).entrySet()) {
      Set<T> ambiguousFields = group.getValue();
      String fieldName = group.getKey();
      if (ambiguousFields.size() == 1) {
        fields.put(fieldName, Iterables.getOnlyElement(ambiguousFields));
      } else {
        T value = factory.createAmbiguousFieldSet(ambiguousFields);
        logger.severe(
            "Proto "
                + descriptor.getFullName()
                + " has multiple extensions with the name \""
                + fieldName
                + "\": "
                + fullFieldNames(ambiguousFields)
                + "\nThis field will not be accessible from soy");
        fields.put(fieldName, value);
      }
    }

    return fields.build();
  }
public static < T extends Field > ImmutableMap < String , T > getFieldsForType ( Descriptor descriptor , Set < FieldDescriptor > extensions , Factory < T > factory ) { ImmutableMap . Builder < String , T > fields = ImmutableMap . builder ( ) ; for ( FieldDescriptor fieldDescriptor : descriptor . getFields ( ) ) { if ( ProtoUtils . shouldJsIgnoreField ( fieldDescriptor ) ) { continue ; } T field = factory . create ( fieldDescriptor ) ; fields . put ( field . getName ( ) , field ) ; } SetMultimap < String , T > extensionsBySoyName = MultimapBuilder . hashKeys ( ) . hashSetValues ( ) . build ( ) ; for ( FieldDescriptor extension : extensions ) { T field = factory . create ( extension ) ; extensionsBySoyName . put ( field . getName ( ) , field ) ; } for ( Map . Entry < String , Set < T > > group : Multimaps . asMap ( extensionsBySoyName ) . entrySet ( ) ) { Set < T > ambiguousFields = group . getValue ( ) ; String fieldName = group . getKey ( ) ; if ( ambiguousFields . size ( ) == 1 ) { fields . put ( fieldName , Iterables . getOnlyElement ( ambiguousFields ) ) ; } else { T value = factory . createAmbiguousFieldSet ( ambiguousFields ) ; logger . severe ( "Proto " + descriptor . getFullName ( ) + " has multiple extensions with the name \"" + fieldName + "\": " + fullFieldNames ( ambiguousFields ) + "\nThis field will not be accessible from soy" ) ; fields . put ( fieldName , value ) ; } } return fields . build ( ) ; }
Returns the set of fields indexed by soy accessor name for the given type.