package mesfavoris.texteditor.internal;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;

import mesfavoris.bookmarktype.AbstractBookmarkMarkerPropertiesProvider;
import mesfavoris.bookmarktype.BookmarkMarkerDescriptor;
import mesfavoris.bookmarktype.IBookmarkLocation;
import mesfavoris.model.Bookmark;

public class WorkspaceFileBookmarkMarkerAttributesProvider extends AbstractBookmarkMarkerPropertiesProvider {

	private final WorkspaceFileBookmarkLocationProvider workspaceFileBookmarkLocationProvider;

	public WorkspaceFileBookmarkMarkerAttributesProvider() {
		this(new WorkspaceFileBookmarkLocationProvider());
	}

	public WorkspaceFileBookmarkMarkerAttributesProvider(
			WorkspaceFileBookmarkLocationProvider textEditorBookmarkLocationProvider) {
		this.workspaceFileBookmarkLocationProvider = textEditorBookmarkLocationProvider;
	}

	@Override
	public BookmarkMarkerDescriptor getMarkerDescriptor(Bookmark bookmark, IProgressMonitor monitor) {
		IBookmarkLocation location = workspaceFileBookmarkLocationProvider.getBookmarkLocation(bookmark, monitor);
		if (!(location instanceof WorkspaceFileBookmarkLocation)) {
			return null;
		}
		WorkspaceFileBookmarkLocation workspaceFileBookmarkLocation = (WorkspaceFileBookmarkLocation) location;
		if (workspaceFileBookmarkLocation.getLineNumber() == null) {
			return null;
		}
		Map attributes = new HashMap();
		attributes.put(IMarker.LINE_NUMBER, new Integer(workspaceFileBookmarkLocation.getLineNumber() + 1));
		if (workspaceFileBookmarkLocation.getLineOffset() != null) {
			attributes.put(IMarker.CHAR_START, Integer.valueOf(workspaceFileBookmarkLocation.getLineOffset()));
			attributes.put(IMarker.CHAR_END, Integer.valueOf(workspaceFileBookmarkLocation.getLineOffset()));
		}
		getMessage(bookmark).ifPresent(message -> attributes.put(IMarker.MESSAGE, message));
		return new BookmarkMarkerDescriptor(workspaceFileBookmarkLocation.getWorkspaceFile(), attributes);
	}

}

@@ -1339,27 +1339,40 @@
 ocation;%0A%09%09i
-f (
+nt lineNumber = 
 workspaceFil
@@ -1409,38 +1409,68 @@
 r() 
-=
+!
 = null
-) %7B%0A%09%09%09return null;%0A%09%09%7D
+ ? workspaceFileBookmarkLocation.getLineNumber() : 0;
 %0A%09%09M
@@ -1542,54 +1542,9 @@
 ER, 
-new Integer(workspaceFileBookmarkLocation.getL
+l
 ineN
@@ -1552,16 +1552,13 @@
 mber
-()
  + 1)
-)
 ;%0A%09%09

Put marker on first line when no line number in bookmark