1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Bug 333134 - Add options to configure doxygen behavior

Change-Id: Idf083d6e0fdf80a848412d610cb41da1d379aeaa
Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
This commit is contained in:
Marco Stornelli 2020-01-10 21:03:55 +01:00
parent 692c4c02a3
commit e4d5441385
11 changed files with 432 additions and 30 deletions

View file

@ -16,6 +16,7 @@
package org.eclipse.cdt.ui.tests.text.doctools.doxygen;
import java.util.HashMap;
import java.util.Optional;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
@ -26,6 +27,7 @@ import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.tests.text.AbstractAutoEditTest;
import org.eclipse.cdt.ui.text.ICPartitions;
@ -62,6 +64,16 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
super.setUp();
fOptions = CCorePlugin.getOptions();
fCProject = CProjectHelper.createCCProject("test" + System.currentTimeMillis(), null);
DoxygenPreferences pref = new DoxygenPreferences(Optional.empty());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, DoxygenPreferences.DEF_DOXYGEN_USE_BRIEF_TAG);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF,
DoxygenPreferences.DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS,
DoxygenPreferences.DEF_DOXYGEN_USE_PRE_POST_TAGS);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS,
DoxygenPreferences.DEF_DOXYGEN_USE_JAVADOC_TAGS);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS,
DoxygenPreferences.DEF_DOXYGEN_USE_STRUCTURED_COMMANDS);
}
/*
@ -674,6 +686,79 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
assertAutoEditBehaviour();
}
///**X
//void foo() {}
///**
// * X@brief ${whitespace_eol}
// * ${whitespace_eol}
// */
//void foo() {}
public void testAutoDocCommentBrief() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences(Optional.empty());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true);
assertAutoEditBehaviour();
}
///**X
//void foo() {}
///**
// * X@brief ${whitespace_eol}
// */
//void foo() {}
public void testAutoDocCommentBriefNoNewLine() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences(Optional.empty());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF, false);
assertAutoEditBehaviour();
}
///**X
//void foo() {}
///**
// * X@fn void foo()
// */
//void foo() {}
public void testAutoDocCommentStructured() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences(Optional.empty());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS, true);
assertAutoEditBehaviour();
}
///**X
//void foo() {}
///**
// * X\brief ${whitespace_eol}
// * ${whitespace_eol}
// */
//void foo() {}
public void testAutoDocCommentNoJavadoc() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences(Optional.empty());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS, false);
assertAutoEditBehaviour();
}
///**X
//void foo() {}
///**
// * X@brief ${whitespace_eol}
// * ${whitespace_eol}
// * @pre ${whitespace_eol}
// * @post ${whitespace_eol}
// */
//void foo() {}
public void testAutoDocCommentPrePostTags() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences(Optional.empty());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS, true);
assertAutoEditBehaviour();
}
protected void assertAutoEditBehaviour() throws CoreException {
CTextTools textTools = CUIPlugin.getDefault().getTextTools();
final IDocument doc = new Document();

View file

@ -363,12 +363,14 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
fAppearanceColorList.select(0);
handleAppearanceColorListSelection();
});
fDocCommentOwnerComposite.loadValues();
}
@Override
public boolean performOk() {
DocCommentOwnerManager.getInstance()
.setWorkspaceCommentOwner(fDocCommentOwnerComposite.getSelectedDocCommentOwner());
fDocCommentOwnerComposite.performOk();
return super.performOk();
}

View file

@ -60,6 +60,11 @@ public class DocCommentOwnerManager {
private static final String QUALIFIER = CCorePlugin.PLUGIN_ID;
private static final String WORKSPACE_DOC_TOOL_NODE = "doctool"; //$NON-NLS-1$
private static final String PREFKEY_WORKSPACE_DEFAULT = "workspace.default"; //$NON-NLS-1$
/**
* Default id for built-in CDT doxygen ui comment owner.
* @since 6.7
*/
public static final String DOXYGEN_CDT_DOC_ONWER_ID = "org.eclipse.cdt.ui.doxygen"; //$NON-NLS-1$
private static DocCommentOwnerManager singleton;

View file

@ -0,0 +1,110 @@
/*******************************************************************************
* Copyright (c) 2020 Marco Stornelli
*
* 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:
* Marco Stornelli - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.doctools;
import java.util.Optional;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.service.prefs.Preferences;
public class DoxygenPreferences {
/**
* Use always brief tag in auto-generation of doxygen comment
* @since 6.7
*/
public static final String DOXYGEN_USE_BRIEF_TAG = "doxygen_use_brief_tag"; //$NON-NLS-1$
/**
* Use always structured commands in auto-generation of doxygen comment
* @since 6.7
*/
public static final String DOXYGEN_USE_STRUCTURAL_COMMANDS = "doxygen_use_structural_commands"; //$NON-NLS-1$
/**
* Use always javadoc tag style in auto-generation of doxygen comment
* @since 6.7
*/
public static final String DOXYGEN_USE_JAVADOC_TAGS = "doxygen_use_javadoc_tags"; //$NON-NLS-1$
/**
* Use always a new line after brief tag in auto-generation of doxygen comment
* @since 6.7
*/
public static final String DOXYGEN_NEW_LINE_AFTER_BRIEF = "doxygen_new_line_after_brief"; //$NON-NLS-1$
/**
* Use always a pre tag in auto-generation of doxygen comment
* @since 6.7
*/
public static final String DOXYGEN_USE_PRE_POST_TAGS = "doxygen_use_pre_tag"; //$NON-NLS-1$
/**
* Default use always brief tag in auto-generation of doxygen comment
* @since 6.7
*/
public static final boolean DEF_DOXYGEN_USE_BRIEF_TAG = false;
/**
* Default use always structured commands in auto-generation of doxygen comment
* @since 6.7
*/
public static final boolean DEF_DOXYGEN_USE_STRUCTURED_COMMANDS = false;
/**
* Default use always javadoc tag style in auto-generation of doxygen comment
* @since 6.7
*/
public static final boolean DEF_DOXYGEN_USE_JAVADOC_TAGS = true;
/**
* Default use always a new line after brief tag in auto-generation of doxygen comment
* @since 6.7
*/
public static final boolean DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF = true;
/**
* Default use always a pre tag in auto-generation of doxygen comment
* @since 6.7
*/
public static final boolean DEF_DOXYGEN_USE_PRE_POST_TAGS = false;
private static final String QUALIFIER = CCorePlugin.PLUGIN_ID;
private static final String WORKSPACE_DOXYGEN_NODE = "doxygen"; //$NON-NLS-1$
private Optional<IProject> project;
public DoxygenPreferences(Optional<IProject> project) {
this.project = project;
}
/**
* Get boolean preferences
* @param key A preference key
* @param defaultValue A default value
* @return The preference value
*/
public boolean getBooleanPref(String key, boolean defaultValue) {
Preferences prefs = project.isPresent()
? new ProjectScope(project.get()).getNode(QUALIFIER).node(WORKSPACE_DOXYGEN_NODE)
: InstanceScope.INSTANCE.getNode(QUALIFIER).node(WORKSPACE_DOXYGEN_NODE);
return prefs.getBoolean(key, defaultValue);
}
/**
* Put boolean preferences
* @param key A preference key
* @param defaultValue A default value
*/
public void putBooleanPref(String key, boolean value) {
Preferences prefs = project.isPresent()
? new ProjectScope(project.get()).getNode(QUALIFIER).node(WORKSPACE_DOXYGEN_NODE)
: InstanceScope.INSTANCE.getNode(QUALIFIER).node(WORKSPACE_DOXYGEN_NODE);
prefs.putBoolean(key, value);
}
}

View file

@ -54,6 +54,11 @@ class DialogsMessages extends NLS {
public static String DocCommentOwnerBlock_SelectDocToolDescription;
public static String DocCommentOwnerCombo_None;
public static String DocCommentOwnerComposite_DocumentationToolGroupTitle;
public static String DocCommentOwnerComposite_UseBriefTagTitle;
public static String DocCommentOwnerComposite_UseStructuralCommandsTitle;
public static String DocCommentOwnerComposite_UseTagJavadocStyleTitle;
public static String DocCommentOwnerComposite_NewLineAfterBriefTitle;
public static String DocCommentOwnerComposite_AddPrePostTagsTitle;
public static String RegexErrorParserOptionPage_ConsumeNo;
public static String RegexErrorParserOptionPage_ConsumeYes;
public static String RegexErrorParserOptionPage_DescriptionColumn;

View file

@ -44,6 +44,11 @@ DocCommentOwnerBlock_EnableProjectSpecificSettings=Enable project specific setti
DocCommentOwnerBlock_SelectDocToolDescription=Select the documentation tool to be used to determine editor behaviors in this project
DocCommentOwnerCombo_None=None
DocCommentOwnerComposite_DocumentationToolGroupTitle=Documentation tool comments
DocCommentOwnerComposite_UseBriefTagTitle=Use brief tag
DocCommentOwnerComposite_UseStructuralCommandsTitle=Use structural commands
DocCommentOwnerComposite_UseTagJavadocStyleTitle=Use javadoc style for tags
DocCommentOwnerComposite_NewLineAfterBriefTitle=Add new line after brief tag
DocCommentOwnerComposite_AddPrePostTagsTitle=Add pre/post tags to functions
IndexerBlock_fixedBuildConfig=Use a fixed build configuration
IndexerBlock_indexerOptions=Indexer options
IndexerBlock_buildConfigGroup=Build configuration for the indexer

View file

@ -92,18 +92,20 @@ public class DocCommentOwnerBlock extends AbstractCOptionPage {
fDocComboComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
fCheckbox.setSelection(fManager.projectDefinesOwnership(getProject()));
fDocComboComposite.loadValues(getProject());
handleCheckBox();
}
@Override
public void performApply(IProgressMonitor monitor) throws CoreException {
IProject project = getProject();
if (!fCheckbox.getSelection())
fManager.setCommentOwner(getProject(), null, true);
fManager.setCommentOwner(project, null, true);
else {
IDocCommentOwner newOwner = fDocComboComposite.getSelectedDocCommentOwner();
IProject p = getProject();
fManager.setCommentOwner(p, newOwner, true);
fManager.setCommentOwner(project, newOwner, true);
}
fDocComboComposite.performOk(project);
}
public IProject getProject() {

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
import org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentOwner;
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
@ -85,4 +86,18 @@ public class DocCommentOwnerCombo extends Composite {
public void setEnabled(boolean enabled) {
fCombo.setEnabled(enabled);
}
/**
* @since 6.7
*/
public void addSelectionListener(SelectionListener listener) {
fCombo.addSelectionListener(listener);
}
/**
* @since 6.7
*/
public void removeSelectionListener(SelectionListener listener) {
fCombo.removeSelectionListener(listener);
}
}

View file

@ -13,12 +13,20 @@
*******************************************************************************/
package org.eclipse.cdt.ui.dialogs;
import java.util.Optional;
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
import org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences;
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
@ -29,10 +37,30 @@ import org.eclipse.swt.widgets.Label;
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public class DocCommentOwnerComposite extends Composite {
public class DocCommentOwnerComposite extends Composite implements SelectionListener {
protected DocCommentOwnerCombo fDocCombo;
protected Label desc, comboLabel;
protected Group group;
/**
* @since 6.7
*/
protected Button useBriefTag;
/**
* @since 6.7
*/
protected Button useStructuralCommands;
/**
* @since 6.7
*/
protected Button useJavadocStyle;
/**
* @since 6.7
*/
protected Button newLineAfterBrief;
/**
* @since 6.7
*/
protected Button usePrePostTag;
public DocCommentOwnerComposite(Composite parent, IDocCommentOwner initialOwner, String description, String label) {
super(parent, SWT.NONE);
@ -57,17 +85,120 @@ public class DocCommentOwnerComposite extends Composite {
};
gd = GridDataFactory.fillDefaults().grab(true, false).create();
fDocCombo.setLayoutData(gd);
fDocCombo.addSelectionListener(this);
useBriefTag = addCheckBox(group, DialogsMessages.DocCommentOwnerComposite_UseBriefTagTitle);
useStructuralCommands = addCheckBox(group, DialogsMessages.DocCommentOwnerComposite_UseStructuralCommandsTitle);
useJavadocStyle = addCheckBox(group, DialogsMessages.DocCommentOwnerComposite_UseTagJavadocStyleTitle);
newLineAfterBrief = addCheckBox(group, DialogsMessages.DocCommentOwnerComposite_NewLineAfterBriefTitle);
usePrePostTag = addCheckBox(group, DialogsMessages.DocCommentOwnerComposite_AddPrePostTagsTitle);
}
private Button addCheckBox(Composite parent, String label) {
Button checkBox = new Button(parent, SWT.CHECK);
checkBox.setText(label);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalIndent = 0;
gd.horizontalSpan = 2;
checkBox.setLayoutData(gd);
return checkBox;
}
public IDocCommentOwner getSelectedDocCommentOwner() {
return fDocCombo.getSelectedDocCommentOwner();
}
private void initialize(Button button, DoxygenPreferences pref, String key, boolean defaultValue) {
button.setSelection(pref.getBooleanPref(key, defaultValue));
}
/**
* @since 6.7
*/
public void loadValues(IProject project) {
DoxygenPreferences pref = new DoxygenPreferences(Optional.ofNullable(project));
initialize(newLineAfterBrief, pref, DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF,
DoxygenPreferences.DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF);
initialize(useBriefTag, pref, DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG,
DoxygenPreferences.DEF_DOXYGEN_USE_BRIEF_TAG);
initialize(useJavadocStyle, pref, DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS,
DoxygenPreferences.DEF_DOXYGEN_USE_JAVADOC_TAGS);
initialize(usePrePostTag, pref, DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS,
DoxygenPreferences.DEF_DOXYGEN_USE_PRE_POST_TAGS);
initialize(useStructuralCommands, pref, DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS,
DoxygenPreferences.DEF_DOXYGEN_USE_STRUCTURED_COMMANDS);
}
/**
* @since 6.7
*/
public void loadValues() {
loadValues(null);
}
/**
* @since 6.7
*/
public void performOk(IProject project) {
DoxygenPreferences pref = new DoxygenPreferences(Optional.ofNullable(project));
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF, newLineAfterBrief.getSelection());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, useBriefTag.getSelection());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS, useJavadocStyle.getSelection());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS, usePrePostTag.getSelection());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS, useStructuralCommands.getSelection());
}
/**
* @since 6.7
*/
public void performOk() {
performOk(null);
}
@Override
public void setEnabled(boolean enabled) {
desc.setEnabled(enabled);
comboLabel.setEnabled(enabled);
fDocCombo.setEnabled(enabled);
group.setEnabled(enabled);
if (fDocCombo.isEnabled() && DocCommentOwnerManager.DOXYGEN_CDT_DOC_ONWER_ID
.equals(fDocCombo.getSelectedDocCommentOwner().getID())) {
useBriefTag.setEnabled(true);
useStructuralCommands.setEnabled(true);
useJavadocStyle.setEnabled(true);
newLineAfterBrief.setEnabled(true);
usePrePostTag.setEnabled(true);
} else {
useBriefTag.setEnabled(false);
useStructuralCommands.setEnabled(false);
useJavadocStyle.setEnabled(false);
newLineAfterBrief.setEnabled(false);
usePrePostTag.setEnabled(false);
}
}
@Override
public void widgetSelected(SelectionEvent e) {
if (DocCommentOwnerManager.DOXYGEN_CDT_DOC_ONWER_ID.equals(fDocCombo.getSelectedDocCommentOwner().getID())) {
useBriefTag.setEnabled(true);
useStructuralCommands.setEnabled(true);
useJavadocStyle.setEnabled(true);
newLineAfterBrief.setEnabled(true);
usePrePostTag.setEnabled(true);
} else {
useBriefTag.setEnabled(false);
useStructuralCommands.setEnabled(false);
useJavadocStyle.setEnabled(false);
newLineAfterBrief.setEnabled(false);
usePrePostTag.setEnabled(false);
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
useBriefTag.setEnabled(false);
useStructuralCommands.setEnabled(false);
useJavadocStyle.setEnabled(false);
newLineAfterBrief.setEnabled(false);
usePrePostTag.setEnabled(false);
}
}

View file

@ -17,6 +17,7 @@ package org.eclipse.cdt.ui.text.doctools;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.Optional;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
@ -35,6 +36,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DocumentCommand;
@ -85,6 +87,17 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
fProject = project;
}
/**
* Return the project (if any) associated with this strategy
* @return A project or empty optional if no project is associated
* @since 6.7
*/
protected Optional<IProject> getProject() {
if (fProject != null)
return Optional.of(fProject.getProject());
return Optional.empty();
}
/**
* Check if edit strategy is enabled
* @return True if enabled, false otherwise

View file

@ -15,6 +15,7 @@
package org.eclipse.cdt.ui.text.doctools.doxygen;
import java.util.LinkedHashSet;
import java.util.Optional;
import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
@ -47,7 +48,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
import org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences;
import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
@ -70,6 +73,8 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
private static final String STRUCT = "struct "; //$NON-NLS-1$
private static final String UNION = "union "; //$NON-NLS-1$
private static final String BRIEF = "brief "; //$NON-NLS-1$
private static final String PRE = "pre "; //$NON-NLS-1$
private static final String POST = "post "; //$NON-NLS-1$
private static final String PARAM = "param "; //$NON-NLS-1$
private static final String FUNC = "fn "; //$NON-NLS-1$
private static final String TPARAM = "tparam "; //$NON-NLS-1$
@ -82,17 +87,53 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
protected boolean documentPureVirtuals = true;
protected boolean documentDeclarations = true;
private boolean javadocStyle = true;
private boolean useStructuralCommands = false;
private boolean useBriefTag = false;
private String fLineDelimiter;
private boolean useBriefTag;
private boolean useStructuralCommands;
private boolean useJavadocStyle;
private boolean newLineAfterBrief;
private boolean usePrePostTag;
public DoxygenMultilineAutoEditStrategy() {
}
private void refreshPreferences() {
Optional<IProject> project = getProject();
DoxygenPreferences pref = new DoxygenPreferences(project);
newLineAfterBrief = pref.getBooleanPref(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF,
DoxygenPreferences.DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF);
useBriefTag = pref.getBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG,
DoxygenPreferences.DEF_DOXYGEN_USE_BRIEF_TAG);
useJavadocStyle = pref.getBooleanPref(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS,
DoxygenPreferences.DEF_DOXYGEN_USE_JAVADOC_TAGS);
usePrePostTag = pref.getBooleanPref(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS,
DoxygenPreferences.DEF_DOXYGEN_USE_PRE_POST_TAGS);
useStructuralCommands = pref.getBooleanPref(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS,
DoxygenPreferences.DEF_DOXYGEN_USE_STRUCTURED_COMMANDS);
}
private String getPrefix() {
return javadocStyle ? PREFIX_JAVADOC : PREFIX_NO_JAVADOC;
return useJavadocStyle ? PREFIX_JAVADOC : PREFIX_NO_JAVADOC;
}
private StringBuilder getBriefTag() {
StringBuilder result = new StringBuilder();
if (useBriefTag) {
result.append(getPrefix()).append(BRIEF).append(getLineDelimiter());
if (newLineAfterBrief) {
result.append(getLineDelimiter());
}
}
return result;
}
private StringBuilder getPrePostTag() {
StringBuilder result = new StringBuilder();
if (usePrePostTag) {
result.append(getPrefix()).append(PRE).append(getLineDelimiter()).append(getPrefix()).append(POST)
.append(getLineDelimiter());
}
return result;
}
/**
@ -129,9 +170,7 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
break;
}
}
if (useBriefTag)
result.append(getPrefix()).append(BRIEF).append(getLineDelimiter()).append(getLineDelimiter())
.append(getLineDelimiter()).append(documentTemplateParameters(templateParams));
result.append(getBriefTag()).append(documentTemplateParameters(templateParams));
return result;
}
@ -148,13 +187,11 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
StringBuilder result = new StringBuilder();
if (useStructuralCommands) {
result.append(getPrefix()).append(FUNC).append(ASTStringUtil.getSignatureString(ds, decl))
.append(getLineDelimiter());
}
if (useBriefTag) {
result.append(getPrefix()).append(BRIEF).append(getLineDelimiter()).append(getLineDelimiter())
.append(getLineDelimiter()).append(documentTemplateParameters(templateParams));
result.append(getPrefix()).append(FUNC).append(ASTStringUtil.getSignatureString(ds, null)).append(" ") //$NON-NLS-1$
.append(ASTStringUtil.getSimpleName(decl.getName()))
.append(ASTStringUtil.getSignatureString(null, decl)).append(getLineDelimiter());
}
result.append(getBriefTag()).append(getPrePostTag()).append(documentTemplateParameters(templateParams));
result.append(documentTemplateParameters(templateParams));
result.append(documentFunctionParameters(getParameterDecls(decl)));
@ -283,6 +320,7 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
@Override
public StringBuilder customizeForDeclaration(IDocument doc, IASTNode declToDocument, ITypedRegion partition,
CustomizeOptions options) {
refreshPreferences();
fLineDelimiter = TextUtilities.getDefaultLineDelimiter(doc);
if (declToDocument instanceof ICPPASTLinkageSpecification) {
@ -385,10 +423,7 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
if (useStructuralCommands)
result.append(getPrefix()).append(DEF).append(new String(dec.getName().getSimpleID()))
.append(getLineDelimiter());
if (useBriefTag)
result.append(getPrefix()).append(BRIEF).append(getLineDelimiter()).append(getLineDelimiter())
.append(getLineDelimiter());
return result;
return result.append(getBriefTag());
}
/**
@ -402,10 +437,7 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
if (useStructuralCommands)
result.append(getPrefix()).append(NAMESPACE).append(new String(dec.getName().getSimpleID()))
.append(getLineDelimiter());
if (useBriefTag)
result.append(getPrefix()).append(BRIEF).append(getLineDelimiter()).append(getLineDelimiter())
.append(getLineDelimiter());
return result;
return result.append(getBriefTag());
}
/**
@ -419,10 +451,7 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
if (useStructuralCommands)
result.append(getPrefix()).append(ENUM).append(new String(dec.getName().getSimpleID()))
.append(getLineDelimiter());
if (useBriefTag)
result.append(getPrefix()).append(BRIEF).append(getLineDelimiter()).append(getLineDelimiter())
.append(getLineDelimiter());
return result;
return result.append(getBriefTag());
}
/**