Skip to content

Commit

Permalink
ITextEditorAware API to inject ITextEditor.
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Oct 28, 2022
1 parent 1900585 commit f9f3745
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 16 deletions.
4 changes: 3 additions & 1 deletion org.eclipse.ui.genericeditor/schema/autoEditStrategies.exsd
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.IAutoEditStrategy&lt;/code&gt;
The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.IAutoEditStrategy&lt;/code&gt;.

If you need to access to the ITextEditor in your implementation, you can implement &lt;code&gt;org.eclipse.ui.texteditor.ITextEditorAware&lt;/code&gt; to inject editor instance in your class.
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.text.IAutoEditStrategy"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<annotation>
<documentation>
The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.source.ICharacterPairMatcher&lt;/code&gt;

If you need to access to the ITextEditor in your implementation, you can implement &lt;code&gt;org.eclipse.ui.texteditor.ITextEditorAware&lt;/code&gt; to inject editor instance in your class.
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.text.source.ICharacterPairMatcher"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<annotation>
<documentation>
The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.contentassist.IContentAssistProcessor&lt;/code&gt;

If you need to access to the ITextEditor in your implementation, you can implement &lt;code&gt;org.eclipse.ui.texteditor.ITextEditorAware&lt;/code&gt; to inject editor instance in your class.
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.text.contentassist.IContentAssistProcessor"/>
Expand Down
2 changes: 2 additions & 0 deletions org.eclipse.ui.genericeditor/schema/foldingReconcilers.exsd
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.reconciler.IReconciler&lt;/code&gt;
To manipulate folding, the implementation reconciler needs to use ProjectionAnnotation and viewer.getProjectionModel(). You can find a sample in
org.eclipse.ui.internal.genericeditor.folding.DefaultFoldingReconciler.

If you need to access to the ITextEditor in your implementation, you can implement &lt;code&gt;org.eclipse.ui.texteditor.ITextEditorAware&lt;/code&gt; to inject editor instance in your class.
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.text.reconciler.IReconciler"/>
Expand Down
2 changes: 2 additions & 0 deletions org.eclipse.ui.genericeditor/schema/highlightReconcilers.exsd
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<annotation>
<documentation>
The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.reconciler.IReconciler&lt;/code&gt;

If you need to access to the ITextEditor in your implementation, you can implement &lt;code&gt;org.eclipse.ui.texteditor.ITextEditorAware&lt;/code&gt; to inject editor instance in your class.
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.text.reconciler.IReconciler"/>
Expand Down
2 changes: 2 additions & 0 deletions org.eclipse.ui.genericeditor/schema/hoverProviders.exsd
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<annotation>
<documentation>
The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.ITextHover&lt;/code&gt;

If you need to access to the ITextEditor in your implementation, you can implement &lt;code&gt;org.eclipse.ui.texteditor.ITextEditorAware&lt;/code&gt; to inject editor instance in your class.
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.text.ITextHover"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<annotation>
<documentation>
The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.presentation.IPresentationReconciler&lt;/code&gt;

If you need to access to the ITextEditor in your implementation, you can implement &lt;code&gt;org.eclipse.ui.texteditor.ITextEditorAware&lt;/code&gt; to inject editor instance in your class.
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.text.presentation.IPresentationReconciler"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
<attribute name="class" type="string" use="required">
<annotation>
<documentation>

The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.quickassist.IQuickAssistProcessor&lt;/code&gt;

If you need to access to the ITextEditor in your implementation, you can implement &lt;code&gt;org.eclipse.ui.texteditor.ITextEditorAware&lt;/code&gt; to inject editor instance in your class.
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.text.quickassist.IQuickAssistProcessor"/>
Expand Down Expand Up @@ -88,7 +90,7 @@
<meta.section type="examples"/>
</appinfo>
<documentation>
&lt;extension
&lt;extension
point=&quot;org.eclipse.ui.genericeditor.quickAssistProcessors&quot;&gt;
&lt;quickAssistProcessor
class=&quot;org.eclipse.ui.genericeditor.tests.contributions.QuickAssistProcessor&quot;
Expand Down
2 changes: 2 additions & 0 deletions org.eclipse.ui.genericeditor/schema/reconcilers.exsd
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<annotation>
<documentation>
The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.reconciler.IReconciler&lt;/code&gt;

If you need to access to the ITextEditor in your implementation, you can implement &lt;code&gt;org.eclipse.ui.texteditor.ITextEditorAware&lt;/code&gt; to inject editor instance in your class.
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.text.reconciler.IReconciler"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public List<IAutoEditStrategy> getAutoEditStrategies(ISourceViewer sourceViewer,
.filter(ext -> contentTypes.contains(ext.targetContentType))
.filter(ext -> ext.matches(sourceViewer, editor))
.sorted(new ContentTypeSpecializationComparator<IAutoEditStrategy>())
.map(GenericContentTypeRelatedExtension<IAutoEditStrategy>::createDelegate)
.map(ext -> ext.createDelegate(editor))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<ICharacterPairMatcher> getCharacterPairMatchers(ISourceViewer source
return this.extensions.values().stream().filter(ext -> contentTypes.contains(ext.targetContentType))
.filter(ext -> ext.matches(sourceViewer, editor))
.sorted(new ContentTypeSpecializationComparator<ICharacterPairMatcher>())
.map(GenericContentTypeRelatedExtension<ICharacterPairMatcher>::createDelegate)
.map(ext -> ext.createDelegate(editor))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public List<IContentAssistProcessor> getContentAssistProcessors(ISourceViewer so
.filter(ext -> contentTypes.contains(ext.targetContentType))
.filter(ext -> ext.matches(sourceViewer, editor))
.sorted(new ContentTypeSpecializationComparator<IContentAssistProcessor>())
.map(GenericContentTypeRelatedExtension<IContentAssistProcessor>::createDelegate)
.map(ext -> ext.createDelegate(editor))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorAware;

/**
* This class wraps and proxies an instance of T provided through extensions and
Expand Down Expand Up @@ -54,9 +55,13 @@ public GenericContentTypeRelatedExtension(IConfigurationElement element) throws
}

@SuppressWarnings("unchecked")
public T createDelegate() {
public T createDelegate(ITextEditor editor) {
try {
return (T) extension.createExecutableExtension(CLASS_ATTRIBUTE);
T delegateInstance = (T) extension.createExecutableExtension(CLASS_ATTRIBUTE);
if (delegateInstance instanceof ITextEditorAware) {
((ITextEditorAware) delegateInstance).setEditor(editor);
}
return delegateInstance;
} catch (CoreException e) {
GenericEditorPlugin.getDefault().getLog()
.log(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, e.getMessage(), e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<IPresentationReconciler> getPresentationReconcilers(ISourceViewer so
.filter(ext -> contentTypes.contains(ext.targetContentType))
.filter(ext -> ext.matches(sourceViewer, editor))
.sorted(new ContentTypeSpecializationComparator<IPresentationReconciler>())
.map(GenericContentTypeRelatedExtension<IPresentationReconciler>::createDelegate)
.map(ext -> ext.createDelegate(editor))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public List<IQuickAssistProcessor> getQuickAssistProcessors(ISourceViewer source
.filter(ext -> contentTypes.contains(ext.targetContentType))
.filter(ext -> ext.matches(sourceViewer, editor))
.sorted(new ContentTypeSpecializationComparator<IQuickAssistProcessor>())
.map(GenericContentTypeRelatedExtension<IQuickAssistProcessor>::createDelegate)
.map(ext -> ext.createDelegate(editor))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public List<IReconciler> getReconcilers(ISourceViewer sourceViewer, ITextEditor
.filter(ext -> contentTypes.contains(ext.targetContentType)) //
.filter(ext -> ext.matches(sourceViewer, editor)) //
.sorted(new ContentTypeSpecializationComparator<IReconciler>().reversed()) //
.map(GenericContentTypeRelatedExtension<IReconciler>::createDelegate) //
.map(ext -> ext.createDelegate(editor)) //
.collect(Collectors.toList());
}

Expand All @@ -104,7 +104,7 @@ public List<IReconciler> getHighlightReconcilers(ISourceViewer sourceViewer, ITe
.filter(ext -> contentTypes.contains(ext.targetContentType)) //
.filter(ext -> ext.matches(sourceViewer, editor)) //
.sorted(new ContentTypeSpecializationComparator<IReconciler>().reversed()) //
.map(GenericContentTypeRelatedExtension<IReconciler>::createDelegate) //
.map(ext -> ext.createDelegate(editor)) //
.collect(Collectors.toList());
}

Expand All @@ -128,7 +128,7 @@ public List<IReconciler> getFoldingReconcilers(ISourceViewer sourceViewer, IText
.filter(ext -> contentTypes.contains(ext.targetContentType)) //
.filter(ext -> ext.matches(sourceViewer, editor)) //
.sorted(new ContentTypeSpecializationComparator<IReconciler>().reversed()) //
.map(GenericContentTypeRelatedExtension<IReconciler>::createDelegate) //
.map(ext -> ext.createDelegate(editor)) //
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public List<ITextHover> getAvailableHovers(ISourceViewer sourceViewer, ITextEdit
.filter(ext -> contentTypes.contains(ext.targetContentType))
.filter(ext -> ext.matches(sourceViewer, editor))
// don't sort in the stream as the initial structure is already sorted by isAfter/isBefore
.map(GenericContentTypeRelatedExtension<ITextHover>::createDelegate)
.map(ext -> ext.createDelegate(editor))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* - Angelo ZERR (Red Hat Inc.) - initial implementation
*******************************************************************************/
package org.eclipse.ui.texteditor;

/**
* API to inject {@link ITextEditor} instance.
*
* @since 3.21.0
*
*/
public interface ITextEditorAware {

/**
* Sets the editor
*
* @param editor the editor
*/
void setEditor(ITextEditor editor);

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* actually modifying the editor contents.
* </p>
*/
public abstract class TextEditorAction extends ResourceAction implements IUpdate {
public abstract class TextEditorAction extends ResourceAction implements IUpdate, ITextEditorAware {

/** The action's editor */
private ITextEditor fTextEditor;
Expand Down Expand Up @@ -85,6 +85,7 @@ protected ITextEditor getTextEditor() {
*
* @param editor the new editor, or <code>null</code> if none
*/
@Override
public void setEditor(ITextEditor editor) {
fTextEditor= editor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.jface.text.source.IVerticalRulerColumn;

import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorAware;


/**
Expand All @@ -30,7 +31,7 @@
*
* @since 3.3
*/
public interface IContributedRulerColumn extends IVerticalRulerColumn {
public interface IContributedRulerColumn extends IVerticalRulerColumn, ITextEditorAware {

/**
* Returns the extension point descriptor of this ruler.
Expand All @@ -57,6 +58,7 @@ public interface IContributedRulerColumn extends IVerticalRulerColumn {
*
* @param editor the editor targeted by this ruler instance
*/
@Override
void setEditor(ITextEditor editor);

/**
Expand Down

0 comments on commit f9f3745

Please sign in to comment.