1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-11 18:25:40 +02:00

Bug 559193 - Rework DoxygenPreferences to encapsulate constants

Part 2 (please refer to the Bug 559193 regarding the reasons to rework):
 - Doxygen option read-only API for clients
 - Doxygen option storage API for configuration UI
 - OSGi component for Doxygen API implementation

Change-Id: Ia97ade397f1040087898aeb3b50872473d3c0631
Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
Alexander Fedorov 2020-01-19 22:49:05 +03:00
parent 053f3d7ea0
commit 5e423d21a9
26 changed files with 635 additions and 258 deletions

View file

@ -9,5 +9,6 @@
<classpathentry kind="src" path="parser"/>
<classpathentry kind="src" path="templateengine"/>
<classpathentry kind="src" path="options"/>
<classpathentry kind="src" path="doxygen"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -25,6 +25,11 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>

View file

@ -0,0 +1,8 @@
classpath=true
dsVersion=V1_3
eclipse.preferences.version=1
enabled=true
generateBundleActivationPolicyLazy=true
path=OSGI-INF
validationErrorLevel=error
validationErrorLevel.missingImplicitUnbindMethod=error

View file

@ -45,6 +45,8 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.core.templateengine,
org.eclipse.cdt.core.templateengine.process,
org.eclipse.cdt.core.templateengine.process.processes,
org.eclipse.cdt.doxygen;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.doxygen.core;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core;
x-friends:="org.eclipse.cdt.codan.core.cxx,
org.eclipse.cdt.debug.core,
@ -82,7 +84,7 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.debug.ui,
org.eclipse.cdt.codan.ui",
org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.options;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.options;x-internal:=true,
org.eclipse.cdt.internal.core.parser;x-internal:=true,
org.eclipse.cdt.internal.core.parser.problem;x-internal:=true,
org.eclipse.cdt.internal.core.parser.scanner;x-friends:="org.eclipse.cdt.ui",
@ -129,6 +131,7 @@ Require-Bundle: org.eclipse.cdt.core.native;bundle-version="[5.10.100,6.0.0)";vi
org.eclipse.core.runtime;bundle-version="[3.16.0,4.0.0)",
org.eclipse.core.variables;bundle-version="[3.4.600,4.0.0)",
org.eclipse.ltk.core.refactoring;bundle-version="[3.10.200,4.0.0)",
org.eclipse.osgi.services;bundle-version="[3.8.0,4.0.0)",
org.eclipse.text;bundle-version="[3.9.0,4.0.0)",
com.ibm.icu;bundle-version="4.4.2",
com.google.gson,
@ -137,4 +140,5 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: javax.xml.bind;version="2.2.0"
Automatic-Module-Name: org.eclipse.cdt.core
Service-Component: OSGI-INF/*.xml

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.cdt.doxygen.internal.core.DoxygenPreferenceAccess">
<service>
<provide interface="org.eclipse.cdt.doxygen.core.DoxygenConfiguration"/>
<provide interface="org.eclipse.cdt.doxygen.core.DoxygenPreferences"/>
</service>
<implementation class="org.eclipse.cdt.doxygen.internal.core.DoxygenPreferenceAccess"/>
</scr:component>

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2003, 2015 IBM Corporation and others.
# Copyright (c) 2003, 2020 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
@ -11,13 +11,15 @@
# Contributors:
# IBM Corporation - initial API and implementation
# Martin Oberhuber (Wind River) - [303083] Split out the Spawner
# Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 559193
###############################################################################
bin.includes = plugin.xml,\
plugin.properties,\
about.html,\
.,\
META-INF/,\
.options
.options,\
OSGI-INF/
src.includes = schema/,\
about.html
javadoc.packages = org.eclipse.cdt.core.*,\
@ -33,4 +35,5 @@ source.. = src/,\
browser/,\
templateengine/,\
options/,\
doxygen/,\
utils/

View file

@ -0,0 +1,78 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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:
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.doxygen;
import java.util.List;
import org.eclipse.cdt.core.options.OptionMetadata;
/**
* The metadata for options to configure doxygen
*
*/
public interface DoxygenMetadata {
/**
* Returns the metadata for the "Use brief tag" option, must not return <code>null</code>.
*
* @return the metadata for the "Use brief tag" option
*
* @see DoxygenOptions#useBriefTags()
*/
OptionMetadata<Boolean> useBriefTagOption();
/**
* Returns the metadata for the "Use structural commands" option, must not return <code>null</code>.
*
* @return the metadata for the "Use structural commands" option
*
* @see DoxygenOptions#useStructuralCommands()
*/
OptionMetadata<Boolean> useStructuralCommandsOption();
/**
* Returns the metadata for the "Use javadoc style for tags" option, must not return <code>null</code>.
*
* @return the metadata for the "Use javadoc style for tags" option
*
* @see DoxygenOptions#useJavadocStyle()
*/
OptionMetadata<Boolean> useJavadocStyleOption();
/**
* Returns the metadata for the "Add new line after brief tag" option, must not return <code>null</code>.
*
* @return the metadata for the "Add new line after brief tag" option
*
* @see DoxygenOptions#newLineAfterBrief()
*/
OptionMetadata<Boolean> newLineAfterBriefOption();
/**
* Returns the metadata for the "Add pre/post tags to functions" option, must not return <code>null</code>.
*
* @return the metadata for the "Add pre/post tags to functions" option
*
* @see DoxygenOptions#usePrePostTag()
*/
OptionMetadata<Boolean> usePrePostTagOption();
/**
* Returns the list of available boolean options to be shown in UI, must not return <code>null</code>.
*
* @return the list of boolean options
*/
List<OptionMetadata<Boolean>> booleanOptions();
}

View file

@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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:
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.doxygen;
/**
* Options to configure doxygen
*
*/
public interface DoxygenOptions {
/**
* Use always brief tag in auto-generation of doxygen comment
*
*/
boolean useBriefTags();
/**
* Use always structured commands in auto-generation of doxygen comment
*
*/
boolean useStructuralCommands();
/**
* Use always javadoc tag style in auto-generation of doxygen comment
*
*/
boolean useJavadocStyle();
/**
* Use always a new line after brief tag in auto-generation of doxygen comment
*
*/
boolean newLineAfterBrief();
/**
* Use always pre/post tags in auto-generation of doxygen comment
*
*/
boolean usePrePostTag();
}

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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:
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.doxygen.core;
import org.eclipse.cdt.doxygen.DoxygenOptions;
import org.eclipse.core.resources.IProject;
/**
* Provides access to the doxygen options according to the required preference scope
*
*/
public interface DoxygenConfiguration {
/**
* Returns the doxygen options for the workspace scope, must not return <code>null</code>
*
* @return doxygen options for the workspace scope
*/
DoxygenOptions workspaceOptions();
/**
* Returns the doxygen options for the given project scope, must not return <code>null</code>
*
* @param project scope for doxygen options, must not be <code>null</code>
* @return doxygen options for the given project scope
*/
DoxygenOptions projectOptions(IProject project);
}

View file

@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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:
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.doxygen.core;
import org.eclipse.cdt.core.options.OptionStorage;
import org.eclipse.cdt.doxygen.DoxygenMetadata;
import org.eclipse.core.resources.IProject;
public interface DoxygenPreferences {
/**
* Returns the workspace storage for doxygen options to be used in UI, must not return <code>null</code>
*
* @return the workspace storage for doxygen options
*/
OptionStorage workspaceStorage();
/**
* Returns the project-specific storage for doxygen options to be used in UI, must not return <code>null</code>
*
* @param project scope for the storage, must not be <code>null</code>
* @return the project-specific storage for doxygen options
*/
OptionStorage projectStorage(IProject project);
/**
* Return the metadata for the options to be used in UI, must not return <code>null</code>
*
* @return the doxygen option metadata
*/
DoxygenMetadata metadata();
}

View file

@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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:
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.doxygen.internal.core;
import org.eclipse.osgi.util.NLS;
public class DoxygenCoreMessages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.doxygen.internal.core.DoxygenCoreMessages"; //$NON-NLS-1$
public static String DoxygenMetadataDefaults_new_line_after_brief_description;
public static String DoxygenMetadataDefaults_new_line_after_brief_name;
public static String DoxygenMetadataDefaults_use_brief_tag_description;
public static String DoxygenMetadataDefaults_use_brief_tag_name;
public static String DoxygenMetadataDefaults_use_javadoc_style_description;
public static String DoxygenMetadataDefaults_use_javadoc_style_name;
public static String DoxygenMetadataDefaults_use_pre_post_tags_description;
public static String DoxygenMetadataDefaults_use_pre_post_tags_name;
public static String DoxygenMetadataDefaults_use_structured_commands_description;
public static String DoxygenMetadataDefaults_use_structured_commands_name;
public static String DoxygenPreferenceAccess_e_null_project;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, DoxygenCoreMessages.class);
}
private DoxygenCoreMessages() {
}
}

View file

@ -0,0 +1,25 @@
###############################################################################
# Copyright (c) 2020 ArSysOp 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:
# Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
###############################################################################
DoxygenMetadataDefaults_new_line_after_brief_description=Use always a new line after brief tag in auto-generation of doxygen comment
DoxygenMetadataDefaults_new_line_after_brief_name=Add new line after brief tag
DoxygenMetadataDefaults_use_brief_tag_description=Use always brief tag in auto-generation of doxygen comment
DoxygenMetadataDefaults_use_brief_tag_name=Use brief tag
DoxygenMetadataDefaults_use_javadoc_style_description=Use always javadoc tag style in auto-generation of doxygen comment
DoxygenMetadataDefaults_use_javadoc_style_name=Use javadoc style for tags
DoxygenMetadataDefaults_use_pre_post_tags_description=Use always pre/post tags in auto-generation of doxygen comment
DoxygenMetadataDefaults_use_pre_post_tags_name=Add pre/post tags to functions
DoxygenMetadataDefaults_use_structured_commands_description=Use always structured commands in auto-generation of doxygen comment
DoxygenMetadataDefaults_use_structured_commands_name=Use structural commands
DoxygenPreferenceAccess_e_null_project=Project must not be null

View file

@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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:
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.doxygen.internal.core;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.options.BaseOption;
import org.eclipse.cdt.core.options.OptionMetadata;
import org.eclipse.cdt.doxygen.DoxygenMetadata;
final class DoxygenMetadataDefaults implements DoxygenMetadata {
private final OptionMetadata<Boolean> useBriefTagOption;
private final OptionMetadata<Boolean> useStructuralCommandsOption;
private final OptionMetadata<Boolean> useJavadocStyleOption;
private final OptionMetadata<Boolean> newLineAfterBriefOption;
private final OptionMetadata<Boolean> usePrePostTagOption;
private final List<OptionMetadata<Boolean>> booleanOptions;
public DoxygenMetadataDefaults() {
this.useBriefTagOption = new BaseOption<>(Boolean.class, "doxygen_use_brief_tag", false, //$NON-NLS-1$
DoxygenCoreMessages.DoxygenMetadataDefaults_use_brief_tag_name,
DoxygenCoreMessages.DoxygenMetadataDefaults_use_brief_tag_description);
this.useStructuralCommandsOption = new BaseOption<>(Boolean.class, "doxygen_use_structural_commands", false, //$NON-NLS-1$
DoxygenCoreMessages.DoxygenMetadataDefaults_use_structured_commands_name,
DoxygenCoreMessages.DoxygenMetadataDefaults_use_structured_commands_description);
this.useJavadocStyleOption = new BaseOption<>(Boolean.class, "doxygen_use_javadoc_tags", true, //$NON-NLS-1$
DoxygenCoreMessages.DoxygenMetadataDefaults_use_javadoc_style_name,
DoxygenCoreMessages.DoxygenMetadataDefaults_use_javadoc_style_description);
this.newLineAfterBriefOption = new BaseOption<>(Boolean.class, "doxygen_new_line_after_brief", true, //$NON-NLS-1$
DoxygenCoreMessages.DoxygenMetadataDefaults_new_line_after_brief_name,
DoxygenCoreMessages.DoxygenMetadataDefaults_new_line_after_brief_description);
this.usePrePostTagOption = new BaseOption<>(Boolean.class, "doxygen_use_pre_tag", false, //$NON-NLS-1$
DoxygenCoreMessages.DoxygenMetadataDefaults_use_pre_post_tags_name,
DoxygenCoreMessages.DoxygenMetadataDefaults_use_pre_post_tags_description);
this.booleanOptions = new ArrayList<>();
booleanOptions.add(useBriefTagOption);
booleanOptions.add(useStructuralCommandsOption);
booleanOptions.add(useJavadocStyleOption);
booleanOptions.add(newLineAfterBriefOption);
booleanOptions.add(usePrePostTagOption);
}
@Override
public OptionMetadata<Boolean> useBriefTagOption() {
return useBriefTagOption;
}
@Override
public OptionMetadata<Boolean> useStructuralCommandsOption() {
return useStructuralCommandsOption;
}
@Override
public OptionMetadata<Boolean> useJavadocStyleOption() {
return useJavadocStyleOption;
}
@Override
public OptionMetadata<Boolean> newLineAfterBriefOption() {
return newLineAfterBriefOption;
}
@Override
public OptionMetadata<Boolean> usePrePostTagOption() {
return usePrePostTagOption;
}
@Override
public List<OptionMetadata<Boolean>> booleanOptions() {
return new ArrayList<>(booleanOptions);
}
}

View file

@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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:
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.doxygen.internal.core;
import org.eclipse.cdt.core.options.OptionStorage;
import org.eclipse.cdt.doxygen.DoxygenMetadata;
import org.eclipse.cdt.doxygen.DoxygenOptions;
final class DoxygenOptionsAccess implements DoxygenOptions {
private final OptionStorage optionStorage;
private final DoxygenMetadata doxygenMetadata;
public DoxygenOptionsAccess(OptionStorage optionStorage, DoxygenMetadata doxygenMetadata) {
this.optionStorage = optionStorage;
this.doxygenMetadata = doxygenMetadata;
}
@Override
public boolean useBriefTags() {
return optionStorage.load(doxygenMetadata.useBriefTagOption());
}
@Override
public boolean useStructuralCommands() {
return optionStorage.load(doxygenMetadata.useStructuralCommandsOption());
}
@Override
public boolean useJavadocStyle() {
return optionStorage.load(doxygenMetadata.useJavadocStyleOption());
}
@Override
public boolean newLineAfterBrief() {
return optionStorage.load(doxygenMetadata.newLineAfterBriefOption());
}
@Override
public boolean usePrePostTag() {
return optionStorage.load(doxygenMetadata.usePrePostTagOption());
}
}

View file

@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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:
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.doxygen.internal.core;
import java.util.Objects;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.options.OptionStorage;
import org.eclipse.cdt.core.options.OsgiPreferenceStorage;
import org.eclipse.cdt.doxygen.DoxygenMetadata;
import org.eclipse.cdt.doxygen.DoxygenOptions;
import org.eclipse.cdt.doxygen.core.DoxygenConfiguration;
import org.eclipse.cdt.doxygen.core.DoxygenPreferences;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.prefs.Preferences;
@Component
public class DoxygenPreferenceAccess implements DoxygenConfiguration, DoxygenPreferences {
private final DoxygenMetadata doxygenMetadata;
public DoxygenPreferenceAccess() {
this.doxygenMetadata = new DoxygenMetadataDefaults();
}
@Override
public OptionStorage workspaceStorage() {
return new OsgiPreferenceStorage(preferences(InstanceScope.INSTANCE));
}
@Override
public OptionStorage projectStorage(IProject project) {
Objects.requireNonNull(DoxygenCoreMessages.DoxygenPreferenceAccess_e_null_project);
return new OsgiPreferenceStorage(preferences(new ProjectScope(project)));
}
@Override
public DoxygenMetadata metadata() {
return doxygenMetadata;
}
@Override
public DoxygenOptions workspaceOptions() {
return new DoxygenOptionsAccess(workspaceStorage(), doxygenMetadata);
}
@Override
public DoxygenOptions projectOptions(IProject project) {
Objects.requireNonNull(DoxygenCoreMessages.DoxygenPreferenceAccess_e_null_project);
return new DoxygenOptionsAccess(projectStorage(project), doxygenMetadata);
}
private Preferences preferences(IScopeContext scope) {
return scope.getNode(nodeQualifier()).node(nodePath());
}
private String nodeQualifier() {
return CCorePlugin.PLUGIN_ID;
}
private String nodePath() {
return "doxygen"; //$NON-NLS-1$
}
}

View file

@ -9,7 +9,7 @@
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial implementation
# Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
###############################################################################
BaseOption_e_null_default_value=Option default value must not be null

View file

@ -39,6 +39,7 @@ Require-Bundle: org.eclipse.jface.text,
org.eclipse.core.filesystem;bundle-version="1.2.0",
org.eclipse.ltk.ui.refactoring,
org.eclipse.osgi,
org.eclipse.e4.core.contexts;bundle-version="[1.8.300,2.0.0)",
org.mockito,
org.hamcrest
Bundle-ActivationPolicy: lazy

View file

@ -13,7 +13,7 @@
* Sergey Prigogin (Google)
* Andrew Ferguson (Symbian)
* Marco Stornelli <marco.stornelli@gmail.com> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134, Bug 559193
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.doctools.doxygen;
@ -23,12 +23,14 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.options.OptionStorage;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.doxygen.DoxygenMetadata;
import org.eclipse.cdt.doxygen.core.DoxygenPreferences;
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;
@ -36,6 +38,7 @@ import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
import org.eclipse.cdt.ui.text.doctools.doxygen.DoxygenMultilineAutoEditStrategy;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
@ -48,6 +51,9 @@ import junit.framework.Test;
public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
private HashMap<String, String> fOptions;
protected ICProject fCProject;
private DoxygenPreferences doxygenPreferences;
private OptionStorage workspaceStorage;
private DoxygenMetadata doxygenMetadata;
/**
* @param name
@ -65,14 +71,12 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
super.setUp();
fOptions = CCorePlugin.getOptions();
fCProject = CProjectHelper.createCCProject("test" + System.currentTimeMillis(), null);
DoxygenPreferences pref = new DoxygenPreferences();
pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, DoxygenPreferences.DEF_DOXYGEN_USE_BRIEF_TAG);
pref.putBoolean(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF,
DoxygenPreferences.DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF);
pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS, DoxygenPreferences.DEF_DOXYGEN_USE_PRE_POST_TAGS);
pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS, DoxygenPreferences.DEF_DOXYGEN_USE_JAVADOC_TAGS);
pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS,
DoxygenPreferences.DEF_DOXYGEN_USE_STRUCTURED_COMMANDS);
DoxygenPreferences doxygenPreferences = EclipseContextFactory
.getServiceContext(CCorePlugin.getDefault().getBundle().getBundleContext())
.get(DoxygenPreferences.class);
doxygenMetadata = doxygenPreferences.metadata();
workspaceStorage = doxygenPreferences.workspaceStorage();
doxygenMetadata.booleanOptions().forEach(o -> workspaceStorage.save(o.defaultValue(), o));
}
/*
@ -733,8 +737,7 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
// */
//void foo() {}
public void testAutoDocCommentBrief() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences();
pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true);
workspaceStorage.save(true, doxygenMetadata.useBriefTagOption());
assertAutoEditBehaviour();
}
@ -746,9 +749,8 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
// */
//void foo() {}
public void testAutoDocCommentBriefNoNewLine() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences();
pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true);
pref.putBoolean(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF, false);
workspaceStorage.save(true, doxygenMetadata.useBriefTagOption());
workspaceStorage.save(false, doxygenMetadata.newLineAfterBriefOption());
assertAutoEditBehaviour();
}
@ -760,8 +762,7 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
// */
//void foo() {}
public void testAutoDocCommentStructured() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences();
pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS, true);
workspaceStorage.save(true, doxygenMetadata.useStructuralCommandsOption());
assertAutoEditBehaviour();
}
@ -774,9 +775,8 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
// */
//void foo() {}
public void testAutoDocCommentNoJavadoc() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences();
pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true);
pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS, false);
workspaceStorage.save(true, doxygenMetadata.useBriefTagOption());
workspaceStorage.save(false, doxygenMetadata.useJavadocStyleOption());
assertAutoEditBehaviour();
}
@ -791,9 +791,8 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
// */
//void foo() {}
public void testAutoDocCommentPrePostTags() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences();
pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true);
pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS, true);
workspaceStorage.save(true, doxygenMetadata.useBriefTagOption());
workspaceStorage.save(true, doxygenMetadata.usePrePostTagOption());
assertAutoEditBehaviour();
}

View file

@ -109,6 +109,7 @@ Require-Bundle: org.eclipse.cdt.core;bundle-version="[6.9.0,7.0.0)",
org.eclipse.core.resources;bundle-version="[3.13.500,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.16.0,4.0.0)",
org.eclipse.core.variables;bundle-version="[3.4.600,4.0.0)",
org.eclipse.e4.core.contexts;bundle-version="[1.8.300,2.0.0)",
org.eclipse.help;bundle-version="[3.8.500,4.0.0)",
org.eclipse.jface.text;bundle-version="[3.15.300,4.0.0)",
org.eclipse.ltk.core.refactoring;bundle-version="[3.10.200,4.0.0)",

View file

@ -15,7 +15,7 @@
* Andrew Ferguson (Symbian)
* Sergey Prigogin (Google)
* Marco Stornelli <marco.stornelli@gmail.com> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134, Bug 559193
*******************************************************************************/
package org.eclipse.cdt.internal.ui.preferences;
@ -26,18 +26,19 @@ import static org.eclipse.cdt.ui.PreferenceConstants.FORMATTING_SCOPE_STATEMENT;
import java.util.ArrayList;
import org.eclipse.cdt.doxygen.core.DoxygenPreferences;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey;
import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl;
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
import org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.dialogs.DocCommentOwnerComposite;
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.ColorSelector;
import org.eclipse.jface.preference.IPreferenceStore;
@ -59,6 +60,7 @@ import org.eclipse.swt.widgets.List;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.Version;
/**
@ -94,7 +96,9 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
super();
Bundle jfaceText = Platform.getBundle("org.eclipse.jface.text"); //$NON-NLS-1$
formattingScopeForEmptySelectionSupported = jfaceText.getVersion().compareTo(new Version(3, 10, 0)) >= 0;
doxygenPreferences = new DoxygenPreferences();
doxygenPreferences = EclipseContextFactory
.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext())
.get(DoxygenPreferences.class);
}
@Override
@ -350,6 +354,7 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
String msg = PreferencesMessages.CEditorPreferencePage_WorkspaceDefaultLabel;
IDocCommentOwner workspaceOwner = DocCommentOwnerManager.getInstance().getWorkspaceCommentOwner();
fDocCommentOwnerComposite = new DocCommentOwnerComposite(contents, workspaceOwner, dsc, msg);
fDocCommentOwnerComposite.setDoxygenMetadata(doxygenPreferences.metadata());
fDocCommentOwnerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
initialize();
@ -368,14 +373,14 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
fAppearanceColorList.select(0);
handleAppearanceColorListSelection();
});
fDocCommentOwnerComposite.initialize(doxygenPreferences);
fDocCommentOwnerComposite.initialize(doxygenPreferences.workspaceStorage());
}
@Override
public boolean performOk() {
DocCommentOwnerManager.getInstance()
.setWorkspaceCommentOwner(fDocCommentOwnerComposite.getSelectedDocCommentOwner());
fDocCommentOwnerComposite.apply(doxygenPreferences);
fDocCommentOwnerComposite.apply(doxygenPreferences.workspaceStorage());
return super.performOk();
}

View file

@ -1,145 +0,0 @@
/*******************************************************************************
* Copyright (c) 2020 Marco Stornelli 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:
* Marco Stornelli - Initial implementation
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.doctools;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.service.prefs.Preferences;
/**
* Encapsulates access to the Doxygen-related preferences according to the current scope
* @since 6.7
*
*/
public final class DoxygenPreferences {
/**
* Use always brief tag in auto-generation of doxygen comment
* @since 6.7
* @noreference This field is not intended to be referenced by clients.
*/
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
* @noreference This field is not intended to be referenced by clients.
*/
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
* @noreference This field is not intended to be referenced by clients.
*/
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
* @noreference This field is not intended to be referenced by clients.
*/
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
* @noreference This field is not intended to be referenced by clients.
*/
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
* @noreference This field is not intended to be referenced by clients.
*/
public static final boolean DEF_DOXYGEN_USE_BRIEF_TAG = false;
/**
* Default use always structured commands in auto-generation of doxygen comment
* @since 6.7
* @noreference This field is not intended to be referenced by clients.
*/
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
* @noreference This field is not intended to be referenced by clients.
*/
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
* @noreference This field is not intended to be referenced by clients.
*/
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
* @noreference This field is not intended to be referenced by clients.
*/
public static final boolean DEF_DOXYGEN_USE_PRE_POST_TAGS = false;
private final Preferences preferences;
public DoxygenPreferences() {
this(InstanceScope.INSTANCE);
}
public DoxygenPreferences(IProject project) {
this(new ProjectScope(project));
}
public DoxygenPreferences(IScopeContext scope) {
this.preferences = scope.getNode(getNodeQualifier()).node(getNodePath());
}
private String getNodeQualifier() {
return CCorePlugin.PLUGIN_ID;
}
private String getNodePath() {
return "doxygen"; //$NON-NLS-1$
}
/**
* Get boolean preference value
* @param key A preference key
* @param defaultValue A default value
* @return The preference value
*
* @since 6.7
*/
public boolean getBoolean(String key, boolean defaultValue) {
return preferences.getBoolean(key, defaultValue);
}
/**
* Put boolean preference value
* @param key A preference key
* @param defaultValue A default value
*
* @since 6.7
*/
public void putBoolean(String key, boolean value) {
preferences.putBoolean(key, value);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2014 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2020 Wind River Systems, Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -14,6 +14,7 @@
* Andrew Ferguson (Symbian)
* Sergey Prigogin (Google)
* Marc-Andre Laperle (Ericsson)
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 559193
*******************************************************************************/
package org.eclipse.cdt.ui.dialogs;
@ -54,11 +55,6 @@ 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

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2007, 2013 Wind River Systems, Inc. and others.
# Copyright (c) 2007, 2020 Wind River Systems, Inc. and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
@ -14,6 +14,7 @@
# Andrew Ferguson (Symbian)
# Sergey Prigogin (Google)
# Marc-Andre Laperle (Ericsson)
# Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 559193
###############################################################################
PreferenceScopeBlock_enableProjectSettings=Enable project specific settings
PreferenceScopeBlock_storeWithProject=Store settings with project
@ -44,11 +45,6 @@ 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

@ -11,17 +11,18 @@
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Marco Stornelli <marco.stornelli@gmail.com> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134, Bug 559193
*******************************************************************************/
package org.eclipse.cdt.ui.dialogs;
import org.eclipse.cdt.doxygen.core.DoxygenPreferences;
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.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@ -32,6 +33,7 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.osgi.framework.FrameworkUtil;
/**
* Project property page for setting documentation comment owner.
@ -49,8 +51,13 @@ public class DocCommentOwnerBlock extends AbstractCOptionPage {
protected Button fCheckbox;
protected Link fLink;
private final DoxygenPreferences doxygenPreferences;
public DocCommentOwnerBlock() {
fManager = DocCommentOwnerManager.getInstance();
doxygenPreferences = EclipseContextFactory
.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext())
.get(DoxygenPreferences.class);
}
void handleCheckBox() {
@ -93,11 +100,11 @@ public class DocCommentOwnerBlock extends AbstractCOptionPage {
IProject project = getProject();
IDocCommentOwner prjOwner = DocCommentOwnerManager.getInstance().getCommentOwner(project);
fDocComboComposite = new DocCommentOwnerComposite(pane, prjOwner, dsc, msg);
fDocComboComposite.setDoxygenMetadata(doxygenPreferences.metadata());
fDocComboComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
fCheckbox.setSelection(fManager.projectDefinesOwnership(project));
DoxygenPreferences preferences = new DoxygenPreferences(project);
fDocComboComposite.initialize(preferences);
fDocComboComposite.initialize(doxygenPreferences.projectStorage(project));
handleCheckBox();
}
@ -110,8 +117,7 @@ public class DocCommentOwnerBlock extends AbstractCOptionPage {
IDocCommentOwner newOwner = fDocComboComposite.getSelectedDocCommentOwner();
fManager.setCommentOwner(project, newOwner, true);
}
DoxygenPreferences preferences = new DoxygenPreferences(project);
fDocComboComposite.apply(preferences);
fDocComboComposite.apply(doxygenPreferences.projectStorage(project));
}
public IProject getProject() {

View file

@ -11,26 +11,17 @@
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Marco Stornelli <marco.stornelli@gmail.com> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134, Bug 559193
*******************************************************************************/
package org.eclipse.cdt.ui.dialogs;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DEF_DOXYGEN_USE_BRIEF_TAG;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DEF_DOXYGEN_USE_JAVADOC_TAGS;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DEF_DOXYGEN_USE_PRE_POST_TAGS;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DEF_DOXYGEN_USE_STRUCTURED_COMMANDS;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS;
import java.util.LinkedHashMap;
import java.util.Map;
import org.eclipse.cdt.core.options.OptionMetadata;
import org.eclipse.cdt.core.options.OptionStorage;
import org.eclipse.cdt.doxygen.DoxygenMetadata;
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.jface.layout.GridDataFactory;
@ -54,13 +45,11 @@ public class DocCommentOwnerComposite extends Composite {
protected Label desc, comboLabel;
protected Group group;
private final Map<String, Button> buttons;
private final Map<String, Boolean> defaults;
private final Map<OptionMetadata<Boolean>, Button> buttons;
public DocCommentOwnerComposite(Composite parent, IDocCommentOwner initialOwner, String description, String label) {
super(parent, SWT.NONE);
buttons = new LinkedHashMap<>();
defaults = new LinkedHashMap<>();
GridLayout gl = new GridLayout();
gl.marginHeight = gl.marginWidth = 0;
setLayout(gl);
@ -83,27 +72,31 @@ public class DocCommentOwnerComposite extends Composite {
gd = GridDataFactory.fillDefaults().grab(true, false).create();
fDocCombo.setLayoutData(gd);
fDocCombo.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> recheckButtons()));
createCheckBox(group, DialogsMessages.DocCommentOwnerComposite_UseBriefTagTitle, DOXYGEN_USE_BRIEF_TAG,
DEF_DOXYGEN_USE_BRIEF_TAG);
createCheckBox(group, DialogsMessages.DocCommentOwnerComposite_UseStructuralCommandsTitle,
DOXYGEN_USE_STRUCTURAL_COMMANDS, DEF_DOXYGEN_USE_STRUCTURED_COMMANDS);
createCheckBox(group, DialogsMessages.DocCommentOwnerComposite_UseTagJavadocStyleTitle,
DOXYGEN_USE_JAVADOC_TAGS, DEF_DOXYGEN_USE_JAVADOC_TAGS);
createCheckBox(group, DialogsMessages.DocCommentOwnerComposite_NewLineAfterBriefTitle,
DOXYGEN_NEW_LINE_AFTER_BRIEF, DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF);
createCheckBox(group, DialogsMessages.DocCommentOwnerComposite_AddPrePostTagsTitle, DOXYGEN_USE_PRE_POST_TAGS,
DEF_DOXYGEN_USE_PRE_POST_TAGS);
}
private Button createCheckBox(Composite parent, String label, String key, boolean value) {
/**
* Creates widgets required to represent doxygen options, extracted from constructor to keep it unchanged.
* Needs to be invoked only once just after the constructor
*
* @param metadata the doxygen metadata to use for checkbox creation
*
* @since 6.7
*
* @noreference This method is not intended to be referenced by clients.
*/
public void setDoxygenMetadata(DoxygenMetadata metadata) {
metadata.booleanOptions().forEach(o -> createCheckBox(group, o));
}
private Button createCheckBox(Composite parent, OptionMetadata<Boolean> option) {
Button checkBox = new Button(parent, SWT.CHECK);
checkBox.setText(label);
checkBox.setText(option.name());
checkBox.setToolTipText(option.description());
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalIndent = 0;
gd.horizontalSpan = 2;
checkBox.setLayoutData(gd);
buttons.put(key, checkBox);
defaults.put(key, value);
buttons.put(option, checkBox);
return checkBox;
}
@ -112,33 +105,29 @@ public class DocCommentOwnerComposite extends Composite {
}
/**
* Initializes widget values from the given preference instance
* Initializes widget values from the given option storage instance
*
* @param preferences the preferences to initialize from
* @param storage the option storage to initialize from
*
* @since 6.7
*
* @noreference This method is not intended to be referenced by clients.
*/
public void initialize(DoxygenPreferences preferences) {
buttons.entrySet().stream().forEach(e -> initialize(e.getValue(), preferences, e.getKey()));
}
void initialize(Button button, DoxygenPreferences pref, String key) {
button.setSelection(pref.getBoolean(key, defaults.get(key)));
public void initialize(OptionStorage storage) {
buttons.entrySet().stream().forEach(e -> e.getValue().setSelection(storage.load(e.getKey())));
}
/**
* Apply widget values to the given preference instance
* Apply widget values to the given option storage instance
*
* @param preferences the preferences to apply to
* @param storage the option storage to apply to
*
* @since 6.7
*
* @noreference This method is not intended to be referenced by clients.
*/
public void apply(DoxygenPreferences preferences) {
buttons.entrySet().stream().forEach(e -> preferences.putBoolean(e.getKey(), e.getValue().getSelection()));
public void apply(OptionStorage storage) {
buttons.entrySet().stream().forEach(e -> storage.save(e.getValue().getSelection(), e.getKey()));
}
@Override

View file

@ -12,7 +12,7 @@
* Andrew Ferguson (Symbian) - Initial implementation
* Anton Leherbauer (Wind River Systems)
* Marco Stornelli <marco.stornelli@gmail.com> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134, Bug 559193
*******************************************************************************/
package org.eclipse.cdt.ui.text.doctools.doxygen;
@ -49,17 +49,20 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.doxygen.DoxygenOptions;
import org.eclipse.cdt.doxygen.core.DoxygenConfiguration;
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.e4.core.contexts.EclipseContextFactory;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.TextUtilities;
import org.osgi.framework.FrameworkUtil;
/**
* {@link IAutoEditStrategy} for adding Doxygen tags for comments.
@ -105,23 +108,23 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
private boolean newLineAfterBrief;
private boolean usePrePostTag;
private final DoxygenConfiguration doxygenConfiguration;
public DoxygenMultilineAutoEditStrategy() {
doxygenConfiguration = EclipseContextFactory
.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext())
.get(DoxygenConfiguration.class);
}
private void refreshPreferences() {
Optional<IProject> project = getProject();
DoxygenPreferences pref = project.isPresent() ? new DoxygenPreferences(project.get())
: new DoxygenPreferences();
newLineAfterBrief = pref.getBoolean(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF,
DoxygenPreferences.DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF);
useBriefTag = pref.getBoolean(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG,
DoxygenPreferences.DEF_DOXYGEN_USE_BRIEF_TAG);
useJavadocStyle = pref.getBoolean(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS,
DoxygenPreferences.DEF_DOXYGEN_USE_JAVADOC_TAGS);
usePrePostTag = pref.getBoolean(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS,
DoxygenPreferences.DEF_DOXYGEN_USE_PRE_POST_TAGS);
useStructuralCommands = pref.getBoolean(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS,
DoxygenPreferences.DEF_DOXYGEN_USE_STRUCTURED_COMMANDS);
DoxygenOptions options = project.isPresent() ? doxygenConfiguration.projectOptions(project.get())
: doxygenConfiguration.workspaceOptions();
newLineAfterBrief = options.newLineAfterBrief();
useBriefTag = options.useBriefTags();
useJavadocStyle = options.useJavadocStyle();
usePrePostTag = options.usePrePostTag();
useStructuralCommands = options.useStructuralCommands();
}
private String getPrefix() {