how do I determine the field type within a field formatter? I have a field formatter that I would like to use on either a string or file field type. I have everything working as two separate field formatters, but with so much shared code, I'd like to make it just one. I've been digging in the API and the core sources, but nothing is jumping out at me. 

/**
 * Plugin implementation of the 'jmol' formatter.
 *
 * @FieldFormatter(
 *   id = "jmol",
 *   label = @Translation("Create a Jmol object"),
 *   field_types = {
 *     "string",
 *     "file"
 *   }
 * )
 */
class SmilesFormatter extends FormatterBase {
public function viewElements(FieldItemListInterface $items, $langcode) {
  foreach ($items as $delta =&gt; $item) {
    // Can't figure this next line out
    $type = ($item-&gt;type);  // I assume it's something easy
    if ($type == 'string') {
      STUFF
    }
    else if ($type == 'file'){
      STUFF
    }
    COMMON STUFF
  }
}
}
Maybe it is better to keep the two formatters separated and just put the shared code into a new formatter. Your two formatters can then extend the new one and just overwride the things specific to them.