code: public static IMarker getMarkerFromEditor(ITextSelection selection, IEditorPart editor) {
          IResource resource = (IResource) editor.getEditorInput().getAdapter(IFile.class);
          IMarker[] allMarkers;
          if (resource != null) {
              allMarkers = getMarkers(resource, IResource.DEPTH_ZERO);
          } else {
              IClassFile classFile = (IClassFile) editor.getEditorInput().getAdapter(IClassFile.class);
              if (classFile == null) {
                  return null;
              }
              Set<IMarker> markers = getMarkers(classFile.getType());
              allMarkers = markers.toArray(new IMarker[markers.size()]);
          }
          // if editor contains only one FB marker, do some cheating and always
          // return it.
          if (allMarkers.length == 1) {
              return allMarkers[0];
          }
          // +1 because it counts real lines, but editor shows lines + 1
          int startLine = selection.getStartLine() + 1;
          for (IMarker marker : allMarkers) {
              int line = getEditorLine(marker);
              if (startLine == line) {
                  return marker;
              }
          }
          return null;
      }
docs: Tries to retrieve right bug marker for given selection. If there are many
  markers for given editor, and text selection doesn't match any of them,
  return null. If there is only one marker for given editor, returns this
  marker in any case.
  
  @param selection
  @param editor
  @return may return null