Bug 574748: [Input] Add BasicSourceFragmentEditorInput

Change-Id: Ia5ed183bed3dd7a43146619ee006ee3f55e5b429
diff --git a/ltk/org.eclipse.statet.ltk.ui/META-INF/MANIFEST.MF b/ltk/org.eclipse.statet.ltk.ui/META-INF/MANIFEST.MF
index ff2ff2b..59b38c7 100644
--- a/ltk/org.eclipse.statet.ltk.ui/META-INF/MANIFEST.MF
+++ b/ltk/org.eclipse.statet.ltk.ui/META-INF/MANIFEST.MF
@@ -53,6 +53,7 @@
  org.eclipse.statet.ecommons.workbench.ui.util,
  org.eclipse.statet.ltk.ui,
  org.eclipse.statet.ltk.ui.compare,
+ org.eclipse.statet.ltk.ui.input,
  org.eclipse.statet.ltk.ui.refactoring,
  org.eclipse.statet.ltk.ui.sourceediting,
  org.eclipse.statet.ltk.ui.sourceediting.actions,
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/input/BasicSourceFragmentEditorInput.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/input/BasicSourceFragmentEditorInput.java
new file mode 100644
index 0000000..f4e91b1
--- /dev/null
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/input/BasicSourceFragmentEditorInput.java
@@ -0,0 +1,103 @@
+/*=============================================================================#
+ # Copyright (c) 2021 Stephan Wahlbrink and others.
+ # 
+ # This program and the accompanying materials are made available under the
+ # terms of the Eclipse Public License 2.0 which is available at
+ # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
+ # which is available at https://www.apache.org/licenses/LICENSE-2.0.
+ # 
+ # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
+ # 
+ # Contributors:
+ #     Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
+ #=============================================================================*/
+
+package org.eclipse.statet.ltk.ui.input;
+
+import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IPersistableElement;
+
+import org.eclipse.statet.jcommons.lang.NonNullByDefault;
+import org.eclipse.statet.jcommons.lang.Nullable;
+
+import org.eclipse.statet.ltk.core.input.SourceFragment;
+
+
+@NonNullByDefault
+public class BasicSourceFragmentEditorInput<TFragment extends SourceFragment>
+		implements SourceFragmentEditorInput {
+	
+	
+	protected final TFragment fragment;
+	
+	
+	public BasicSourceFragmentEditorInput(final TFragment fragment) {
+		this.fragment= nonNullAssert(fragment);
+	}
+	
+	
+	@Override
+	public SourceFragment getSourceFragment() {
+		return this.fragment;
+	}
+	
+	
+	@Override
+	public boolean exists() {
+		return false;
+	}
+	
+	@Override
+	public @Nullable ImageDescriptor getImageDescriptor() {
+		return null;
+	}
+	
+	@Override
+	public String getName() {
+		return this.fragment.getName();
+	}
+	
+	@Override
+	public String getToolTipText() {
+		return this.fragment.getFullName();
+	}
+	
+	
+	@Override
+	public @Nullable IPersistableElement getPersistable() {
+		return null;
+	}
+	
+	
+	@Override
+	public <T> @Nullable T getAdapter(final Class<T> adapterType) {
+		return null;
+	}
+	
+	
+	@Override
+	public int hashCode() {
+		return this.fragment.hashCode();
+	}
+	
+	@Override
+	public boolean equals(final @Nullable Object obj) {
+		if (this == obj) {
+			return true;
+		}
+		if (obj instanceof BasicSourceFragmentEditorInput
+				&& getClass() == obj.getClass()) {
+			final BasicSourceFragmentEditorInput<?> other= (BasicSourceFragmentEditorInput<?>)obj;
+			return this.fragment.equals(other.fragment);
+		}
+		return false;
+	}
+	
+	@Override
+	public String toString() {
+		return this.fragment.getFullName();
+	}
+	
+}
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/sourceediting/SourceFragmentEditorInput.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/input/SourceFragmentEditorInput.java
similarity index 94%
rename from ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/sourceediting/SourceFragmentEditorInput.java
rename to ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/input/SourceFragmentEditorInput.java
index cbd0c4c..0d39ade 100644
--- a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/sourceediting/SourceFragmentEditorInput.java
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/input/SourceFragmentEditorInput.java
@@ -12,7 +12,7 @@
  #     Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
  #=============================================================================*/
 
-package org.eclipse.statet.ltk.ui.sourceediting;
+package org.eclipse.statet.ltk.ui.input;
 
 import org.eclipse.ui.IEditorInput;
 
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/sourceediting/FragmentDocumentProvider.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/sourceediting/FragmentDocumentProvider.java
index d78a6a6..2fe285f 100644
--- a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/sourceediting/FragmentDocumentProvider.java
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/sourceediting/FragmentDocumentProvider.java
@@ -37,6 +37,7 @@
 import org.eclipse.statet.ltk.model.core.DocumentModelProvider;
 import org.eclipse.statet.ltk.model.core.LtkModels;
 import org.eclipse.statet.ltk.model.core.element.SourceUnit;
+import org.eclipse.statet.ltk.ui.input.SourceFragmentEditorInput;
 
 
 @NonNullByDefault
@@ -57,11 +58,11 @@
 	
 	private final String modelTypeId;
 	
-	private final IDocumentSetupParticipant documentSetupParticipant;
+	private final @Nullable IDocumentSetupParticipant documentSetupParticipant;
 	
 	
 	public FragmentDocumentProvider(final String modelTypeId,
-			final PartitionerDocumentSetupParticipant documentSetupParticipant) {
+			final @Nullable PartitionerDocumentSetupParticipant documentSetupParticipant) {
 		this.modelTypeId= nonNullAssert(modelTypeId);
 		this.documentSetupParticipant= documentSetupParticipant;
 	}
@@ -107,8 +108,9 @@
 	}
 	
 	protected void setupDocument(final AbstractDocument document) {
-		if (this.documentSetupParticipant != null) {
-			this.documentSetupParticipant.setup(document);
+		final var documentSetupParticipant= this.documentSetupParticipant;
+		if (documentSetupParticipant != null) {
+			documentSetupParticipant.setup(document);
 		}
 	}