Skip to content

Commit

Permalink
[eclipse] Add command for adding the SARL API documentation for the s…
Browse files Browse the repository at this point in the history
…elected element.

The command is accessible from the popup menu "Sources>Generate Element
Documentation".

close #1071

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed May 16, 2021
1 parent d1a702e commit eee2883
Show file tree
Hide file tree
Showing 8 changed files with 776 additions and 0 deletions.
Expand Up @@ -99,3 +99,4 @@ key.scheme.name=SARL Keys
context.explorer.name=SARL Explorer
wizard.name.exportSarlApp = Runnable SARL application
wizard.description.exportSarlApp = Export all resources required to run a SARL application into a single JAR file on the local file system.
action.generateElementDocumentation = Generate Element Documentation
31 changes: 31 additions & 0 deletions main/coreplugins/io.sarl.eclipse/plugin.xml
Expand Up @@ -745,4 +745,35 @@
<keywordReference id="org.eclipse.jdt.ui.jarpackager"/>
</wizard>
</extension>

<!-- Generate JavaDoc comment -->
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:xtext.ui.SourceMenu?after=org.eclipse.xtext.ui.ToggleCommentAction">
<command commandId="io.sarl.eclipse.javadoc.generateComment"
label="%action.generateElementDocumentation"
style="push"
mnemonic="t">
<visibleWhen checkEnabled="false">
<reference definitionId="isActiveEditorAnInstanceOfXtextEditor" />
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.commands">
<command id="io.sarl.eclipse.javadoc.generateComment"
categoryId="org.eclipse.xtext.ui.category.XtextEditor"
name="%action.generateElementDocumentation" />
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
class="io.sarl.eclipse.SARLEclipseExecutableExtensionFactory:io.sarl.eclipse.javadoc.GenerateJavadocHandler"
commandId="io.sarl.eclipse.javadoc.generateComment" />
</extension>
<extension point="org.eclipse.ui.bindings">
<key sequence="M2+M3+J"
commandId="io.sarl.eclipse.javadoc.generateComment"
contextId="org.eclipse.xtext.ui.XtextEditorScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
</key>
</extension>
</plugin>
@@ -0,0 +1,72 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2021 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.eclipse.javadoc;

import javax.inject.Inject;
import javax.inject.Provider;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.ui.editor.utils.EditorUtils;
import org.eclipse.xtext.ui.refactoring.ui.SyncUtil;

import io.sarl.lang.ui.contentassist.javadoc.ISarlDocumentationProvider;

/**
* Generate the JavaDoc comment for the selected element.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.12
*/
public class GenerateJavadocHandler extends AbstractHandler {

@Inject
private Provider<SyncUtil> syncUtil;

@Inject
private Provider<ISarlDocumentationProvider> documentProvider;

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
// Save current editor
this.syncUtil.get().totalSync(false);
final XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
if (editor != null) {
final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
final IXtextDocument document = editor.getDocument();
this.documentProvider.get().generateDocumentationIfPossible(document, selection);
}
return null;
} catch (Exception exception) {
throw new ExecutionException(exception.getLocalizedMessage(), exception);
}
}

}

0 comments on commit eee2883

Please sign in to comment.