Skip to content

Commit

Permalink
[ui] Add codemining feature.
Browse files Browse the repository at this point in the history
close #841.

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Jul 17, 2018
1 parent 9a37ea9 commit de16e28
Show file tree
Hide file tree
Showing 17 changed files with 678 additions and 76 deletions.
Expand Up @@ -45,6 +45,7 @@ public class Messages extends NLS {
public static String SREsPreferencePage_8;
public static String SREsPreferencePage_9;
public static String SarlEditorPreferencePage_0;
public static String SarlEditorPreferencePage_1;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

import io.sarl.lang.ui.codemining.SARLCodeminingPreferenceAccess;
import io.sarl.lang.ui.editor.SARLSourceViewerPreferenceAccess;

/** Preference page for the SARL editors.
Expand All @@ -53,10 +54,15 @@ public class SarlEditorPreferencePage extends PreferencePage implements IWorkben
public static final String ID = "io.sarl.eclipse.preferences.SarlEditorPreferencePage"; //$NON-NLS-1$

@Inject
private SARLSourceViewerPreferenceAccess preferences;
private SARLSourceViewerPreferenceAccess sourceViewerPreferences;

@Inject
private SARLCodeminingPreferenceAccess codeminingPreferences;

private Button autoformattingButton;

private Button codeminingButton;

/**
* Constructor.
*/
Expand All @@ -69,17 +75,26 @@ public void init(IWorkbench workbench) {
//
}

/** Replies the preference accessor.
/** Replies the preferences for the source viewer.
*
* @return the preference accessor.
*/
protected SARLSourceViewerPreferenceAccess getSourceViewerPreferenceAccessor() {
return this.sourceViewerPreferences;
}

/** Replies the preferences for the codemining.
*
* @return the preference accessor.
* @since 0.8
*/
protected SARLSourceViewerPreferenceAccess getPreferenceAccessor() {
return this.preferences;
protected SARLCodeminingPreferenceAccess getCodeminingPreferenceAccessor() {
return this.codeminingPreferences;
}

@Override
protected IPreferenceStore doGetPreferenceStore() {
return getPreferenceAccessor().getWritablePreferenceStore();
return getCodeminingPreferenceAccessor().getWritablePreferenceStore(null);
}

@Override
Expand All @@ -99,12 +114,22 @@ protected Control createContents(Composite parent) {
data.horizontalAlignment = GridData.FILL;
pageComponent.setLayoutData(data);

// ensure all the accessors use the same preference store (because only one
// store is saved when closing the dialog box).
getSourceViewerPreferenceAccessor().setWritablePreferenceStore(getPreferenceStore());
getCodeminingPreferenceAccessor().setWritablePreferenceStore(getPreferenceStore());

// create the content
this.autoformattingButton = SWTFactory.createCheckButton(pageComponent,
Messages.SarlEditorPreferencePage_0,
null,
getPreferenceAccessor().isAutoFormattingEnabled(),
1);
getSourceViewerPreferenceAccessor().isAutoFormattingEnabled(),
2);
this.codeminingButton = SWTFactory.createCheckButton(pageComponent,
Messages.SarlEditorPreferencePage_1,
null,
getCodeminingPreferenceAccessor().isCodeminingEnabled(),
2);

SWTFactory.createVerticalSpacer(pageComponent, 1);

Expand All @@ -116,15 +141,14 @@ protected Control createContents(Composite parent) {
@Override
protected void performDefaults() {
this.autoformattingButton.setSelection(SARLSourceViewerPreferenceAccess.AUTOFORMATTING_DEFAULT_VALUE);
this.codeminingButton.setSelection(SARLCodeminingPreferenceAccess.CODEMINING_DEFAULT_VALUE);
super.performDefaults();
}

@Override
public boolean performOk() {
final IPreferenceStore store = getPreferenceStore();
store.setValue(
SARLSourceViewerPreferenceAccess.AUTOFORMATTING_PROPERTY,
this.autoformattingButton.getSelection());
getSourceViewerPreferenceAccessor().setAutoFormattingEnabled(this.autoformattingButton.getSelection());
getCodeminingPreferenceAccessor().setCodeminingEnabled(this.codeminingButton.getSelection());
return super.performOk();
}

Expand Down
Expand Up @@ -10,3 +10,4 @@ SREsPreferencePage_7=Remove
SREsPreferencePage_8=You must specify a default SRE.
SREsPreferencePage_9=Internal Error: {0}
SarlEditorPreferencePage_0=Formatting on paste actions
SarlEditorPreferencePage_1=Show codemining annotations
Expand Up @@ -143,7 +143,7 @@ protected boolean hasProjectSpecificOptions(IProject project) {
* used.
*
* @param project the project.
* @param useSpecificOptions indicates if the specifi options must be used.
* @param useSpecificOptions indicates if the specific options must be used.
* @return <code>true</code> if the property was saved successfully.
*/
@SuppressWarnings("static-method")
Expand Down
Expand Up @@ -22,6 +22,7 @@ module io.sarl.lang.GenerateSARL2
import org.eclipse.emf.mwe.utils.*
import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*
import org.eclipse.xtext.xtext.generator.ui.codemining.*
import org.eclipse.xtext.generator.*
import org.eclipse.xtext.ui.generator.*
import org.eclipse.xtext.generator.parser.antlr.*
Expand Down Expand Up @@ -374,6 +375,11 @@ Workflow {
generateStub = true
}

// Code mining
fragment = CodeMiningFragment auto-inject {
generateStub = true
}

// ***********************************
// Fragments that are specific to SARL
// ***********************************
Expand Down Expand Up @@ -953,6 +959,11 @@ Workflow {
bind = "org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration"
to = "org.eclipse.xtend.ide.editor.XtendSourceViewerConfiguration"
}
ui = {
bind = "org.eclipse.xtext.ui.editor.XtextEditor"
to = "io.sarl.lang.ui.editor.SARLStandardEditor"
override = true
}
ui = {
bind = "org.eclipse.xtext.ui.editor.actions.IActionContributor"
annotatedWithName = "OverrideIndicatorRulerAction"
Expand Down
7 changes: 5 additions & 2 deletions main/coreplugins/io.sarl.lang.ui/META-INF/MANIFEST.MF
Expand Up @@ -31,6 +31,7 @@ Export-Package: io.sarl.lang.ide,
io.sarl.lang.ide.contentassist.antlr.internal,
io.sarl.lang.ui,
io.sarl.lang.ui.codebuilder,
io.sarl.lang.ui.codemining,
io.sarl.lang.ui.compiler,
io.sarl.lang.ui.compiler.extra,
io.sarl.lang.ui.compiler.extra.preferences,
Expand All @@ -52,5 +53,7 @@ Export-Package: io.sarl.lang.ide,
io.sarl.lang.ui.refactoring.rename,
io.sarl.lang.ui.tasks,
io.sarl.lang.ui.validation,
io.sarl.lang.ui.validation.extra
Import-Package: org.apache.log4j
io.sarl.lang.ui.validation.extra,
io.sarl.lang.validation
Import-Package: org.apache.log4j,
org.eclipse.xtext.ui.codemining;resolution:=optional
Expand Up @@ -4,6 +4,7 @@ action.label.0 = Toggle Breakpoint
action.label.1 = Breakpoint Properties
Bundle-Vendor = SARL.io
Bundle-Name = SARL Language compiler IDE tools
codemining.name = SARL Codemining
command.description = Trigger expensive validation
command.description.0 = Copy the qualified name for the selected element
command.description.1 = Copy the qualified name for the selected element
Expand Down
25 changes: 25 additions & 0 deletions main/coreplugins/io.sarl.lang.ui/plugin.xml
Expand Up @@ -412,6 +412,31 @@
<fileTypes extension="sarl" type="text">
</fileTypes>
</extension>
<!-- code mining -->
<extension point="org.eclipse.ui.workbench.texteditor.codeMiningProviders">
<codeMiningProvider
class="io.sarl.lang.ui.SARLExecutableExtensionFactory:org.eclipse.jface.text.codemining.ICodeMiningProvider"
id="io.sarl.lang.SARL.CodeMiningProvider"
label="%codemining.name">
<enabledWhen>
<with variable="editorInput">
<adapt type="org.eclipse.core.resources.IFile">
<test
property="org.eclipse.core.resources.contentTypeId"
value="io.sarl.lang.SARL.contenttype">
</test>
</adapt>
</with>
</enabledWhen>
</codeMiningProvider>
</extension>
<extension
point="org.eclipse.ui.genericeditor.reconcilers">
<reconciler
class="org.eclipse.jface.text.codemining.CodeMiningReconciler"
contentType="io.sarl.lang.SARL.contenttype">
</reconciler>
</extension>



Expand Down
Expand Up @@ -55,8 +55,8 @@
import io.sarl.lang.ui.contentassist.javadoc.SARLJavaDocContentAssistProcessor;
import io.sarl.lang.ui.contentassist.templates.SARLTemplateContextType;
import io.sarl.lang.ui.contentassist.templates.SARLTemplateProposalProvider;
import io.sarl.lang.ui.editor.SARLEditor;
import io.sarl.lang.ui.editor.SARLSourceViewer;
import io.sarl.lang.ui.editor.SARLStandardEditor;
import io.sarl.lang.ui.highlighting.SARLHighlightingCalculator;
import io.sarl.lang.ui.hover.SARLHoverSerializer;
import io.sarl.lang.ui.hover.SARLHoverSignatureProvider;
Expand Down Expand Up @@ -113,6 +113,7 @@
import org.eclipse.xtend.ide.editor.RichStringAwareToggleCommentAction;
import org.eclipse.xtend.ide.editor.SingleLineCommentHelper;
import org.eclipse.xtend.ide.editor.XtendDoubleClickStrategyProvider;
import org.eclipse.xtend.ide.editor.XtendSourceViewerConfiguration;
import org.eclipse.xtend.ide.highlighting.XtendHighlightingConfiguration;
import org.eclipse.xtend.ide.hover.XtendAnnotationHover;
import org.eclipse.xtend.ide.hover.XtendHoverProvider;
Expand Down Expand Up @@ -176,6 +177,7 @@
import org.eclipse.xtext.ui.editor.IXtextEditorCallback;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.XtextSourceViewer;
import org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration;
import org.eclipse.xtext.ui.editor.actions.IActionContributor;
import org.eclipse.xtext.ui.editor.autoedit.AbstractEditStrategyProvider;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
Expand Down Expand Up @@ -456,11 +458,6 @@ public Class<? extends IUnresolvedTypeResolver> bindIUnresolvedTypeResolver() {
return InteractiveUnresolvedTypeResolver.class;
}

// contributed by org.eclipse.xtext.xtext.generator.xbase.XbaseGeneratorFragment2
public Class<? extends XtextEditor> bindXtextEditor() {
return SARLEditor.class;
}

// contributed by org.eclipse.xtext.xtext.generator.ui.templates.CodetemplatesGeneratorFragment2
public Provider<? extends TemplatesLanguageConfiguration> provideTemplatesLanguageConfiguration() {
return AccessibleCodetemplatesActivator.getTemplatesLanguageConfigurationProvider();
Expand Down Expand Up @@ -752,6 +749,11 @@ public Class<? extends MutableFileSystemSupport> bindMutableFileSystemSupport()
return EclipseFileSystemSupportImpl.class;
}

// contributed by io.sarl.lang.mwe2.binding.InjectionFragment2 [Bindings required by extended Xtend API]
public Class<? extends XtextEditor> bindXtextEditor() {
return SARLStandardEditor.class;
}

// contributed by io.sarl.lang.mwe2.binding.InjectionFragment2 [Bindings required by extended Xtend API]
public Class<? extends AbstractFileSystemSupport> bindAbstractFileSystemSupport() {
return EclipseFileSystemSupportImpl.class;
Expand Down Expand Up @@ -838,6 +840,11 @@ public Class<? extends IResourceUIServiceProvider> bindIResourceUIServiceProvide
return RichStringAwareToggleCommentAction.Factory.class;
}

// contributed by io.sarl.lang.mwe2.binding.InjectionFragment2 [Bindings required by extended Xtend API]
public Class<? extends XtextSourceViewerConfiguration> bindXtextSourceViewerConfiguration() {
return XtendSourceViewerConfiguration.class;
}

// contributed by io.sarl.lang.mwe2.binding.InjectionFragment2 [Bindings required by extended Xtend API]
public Class<? extends XtextSourceViewer.Factory> bindXtextSourceViewer$Factory() {
return SARLSourceViewer.Factory.class;
Expand Down

0 comments on commit de16e28

Please sign in to comment.