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

Visibility ordering within a class declaration.

This commit is contained in:
Sergey Prigogin 2012-01-05 20:23:58 -08:00
parent 76e962ee9b
commit 046c25fadb
7 changed files with 245 additions and 210 deletions

View file

@ -397,7 +397,6 @@ public:
};
#endif /*A_H_*/
//=
#ifndef A_H_
#define A_H_
@ -413,7 +412,6 @@ private:
};
#endif /*A_H_*/
//@A.cpp
#include "A.h"
@ -426,7 +424,6 @@ A::~A() {
int A::foo() {
return /*$*/42/*$$*/;
}
//=
#include "A.h"
@ -439,8 +436,7 @@ A::~A() {
int A::foo() {
return theAnswer;
}
//!Bug 246062 [Refactoring] NPE extracting a constant from an inlined method
//!Bug 246062 - Extracting a constant from an inlined method
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@.config
filename=A.h
@ -450,18 +446,17 @@ class X {
int a = /*$*/42/*$$*/;
}
};
//=
class X {
public:
static const int theAnswer = 42;
private:
void method() {
int a = theAnswer;
}
public:
static const int theAnswer = 42;
};
//!ExtractConstantString
//!Extract constant string
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@.config
visibility=private

View file

@ -1480,7 +1480,6 @@ private:
};
#endif /*A_H_*/
//=
#ifndef A_H_
#define A_H_
@ -1491,15 +1490,14 @@ public:
virtual ~A();
int foo();
private:
int help();
protected:
void exp(int& i);
private:
int help();
};
#endif /*A_H_*/
//@A.cpp
#include "A.h"
@ -1519,7 +1517,6 @@ int A::foo() {
int A::help() {
return 42;
}
//=
#include "A.h"
@ -1543,7 +1540,6 @@ int A::foo() {
int A::help() {
return 42;
}
//@.config
filename=A.cpp
methodname=exp

View file

@ -71,10 +71,6 @@ public:
int GetUniqueId();
char* getName() const {
return name;
}
int getSystemId() {
return systemId;
}
@ -82,6 +78,10 @@ public:
void setSystemId(int systemId) {
this->systemId = systemId;
}
char* getName() const {
return name;
}
};
int gooo = 1;
@ -176,10 +176,6 @@ public:
int GetUniqueId();
char* getName() const {
return name;
}
int getSystemId() {
return systemId;
}
@ -187,6 +183,10 @@ public:
void setSystemId(int systemId) {
this->systemId = systemId;
}
char* getName() const {
return name;
}
};
}
@ -246,7 +246,6 @@ public:
}
};
int gooo = 1;
#endif /* A_H_ */
@ -278,10 +277,6 @@ public:
int GetUniqueId();
void setName(char* name) {
this->name = name;
}
int getSystemId() {
return systemId;
}
@ -289,8 +284,11 @@ public:
void setSystemId(int systemId) {
this->systemId = systemId;
}
};
void setName(char* name) {
this->name = name;
}
};
int gooo = 1;
@ -379,14 +377,6 @@ public:
int GetUniqueId();
char* getName() const {
return name;
}
void setName(char* name) {
this->name = name;
}
int getSystemId() {
return systemId;
}
@ -394,6 +384,14 @@ public:
void setSystemId(int systemId) {
this->systemId = systemId;
}
char* getName() const {
return name;
}
void setName(char* name) {
this->name = name;
}
};
int gooo = 1;
@ -463,6 +461,18 @@ public:
Person myFriend;
Person(int socSecNo); // constructor
~Person(); // destructor
char* Name();
void Print();
int SocSecNo();
int GetUniqueId();
char* getName() const {
return name;
}
@ -478,18 +488,6 @@ public:
void setSystemId(int systemId) {
this->systemId = systemId;
}
Person(int socSecNo); // constructor
~Person(); // destructor
char* Name();
void Print();
int SocSecNo();
int GetUniqueId();
};
int gooo = 1;
@ -567,7 +565,7 @@ GaS::Getters() {
GaS::~Getters() {
}
//!Generate Getters and Setters no Methods
//!Generate Getters and Setters no methods
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config
filename=A.h
@ -588,9 +586,6 @@ private:
#define A_H_
class Person {
private:
int id;
public:
int getId() const {
return id;
@ -599,15 +594,19 @@ public:
void setId(int id) {
this->id = id;
}
private:
int id;
};
#endif /* A_H_ */
//!Generate Getters and Setters no Methods
//!Generate Getters and Setters no methods ascending visibility order
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config
filename=A.h
getters=i
setters=i
ascendingVisibilityOrder=true
//@A.h
/*
* test.h
@ -624,7 +623,6 @@ class test {
};
#endif /* TEST_H_ */
//=
/*
* test.h
@ -650,8 +648,7 @@ public:
};
#endif /* TEST_H_ */
//!Generate Getters and Setters no Fields
//!Generate Getters and Setters no fields
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config
filename=A.h
@ -759,8 +756,6 @@ public:
Person myFriend;
const FullName& getName() const;
void setName(const FullName& name);
Person(int socSecNo); // constructor
~Person(); // destructor
@ -776,6 +771,8 @@ public:
int getSystemId();
void setSystemId(int systemId);
const FullName& getName() const;
void setName(const FullName& name);
};
int gooo = 1;
@ -886,7 +883,6 @@ public:
int SocSecNo();
int GetUniqueId();
char* getName() const;
int getSystemId() {
return systemId;
@ -895,6 +891,8 @@ public:
void setSystemId(int systemId) {
this->systemId = systemId;
}
char* getName() const;
};
}
@ -1005,7 +1003,6 @@ public:
int SocSecNo();
int GetUniqueId();
void setName(char* name);
int getSystemId() {
return systemId;
@ -1014,6 +1011,8 @@ public:
void setSystemId(int systemId) {
this->systemId = systemId;
}
void setName(char* name);
};
int gooo = 1;
@ -1115,8 +1114,6 @@ public:
int SocSecNo();
int GetUniqueId();
char* getName() const;
void setName(char* name);
int getSystemId() {
return systemId;
@ -1125,6 +1122,9 @@ public:
void setSystemId(int systemId) {
this->systemId = systemId;
}
char* getName() const;
void setName(char* name);
};
int gooo = 1;
@ -1178,12 +1178,12 @@ private:
#define A_H_
class Person {
private:
int id;
public:
int getId() const;
void setId(int id);
private:
int id;
};
inline int Person::getId() const {
@ -1228,13 +1228,14 @@ class test {
//comment1
class test {
int i; //comment2
char* b;
//comment3
public:
int getI() const;
void setI(int i);
private:
int i; //comment2
char* b;
//comment3
};
inline int test::getI() const {
@ -1275,12 +1276,13 @@ class Test {
namespace foo {
class Test {
int testField;
void foo();
public:
int getTestField() const;
void setTestField(int testField);
private:
int testField;
void foo();
};
} // namespace foo
@ -1334,11 +1336,12 @@ class Test {
#define TEST_H_
class Test {
int testField;
public:
int getTestField() const;
void setTestField(int testField);
private:
int testField;
};
#endif
@ -1374,11 +1377,12 @@ class Test {
#define TEST_H_
class Test {
int testField;
public:
int getTestField() const;
void setTestField(int testField);
private:
int testField;
};
#endif
@ -1464,13 +1468,13 @@ private:
#define A_H_
class A {
private:
int a[2];
public:
const int* getA() const {
return a;
}
private:
int a[2];
};
#endif /* A_H_ */
//!Bug 352258 - Avoiding reserved names
@ -1493,9 +1497,6 @@ private:
#define A_H_
class getClass {
private:
int mClass;
public:
int getClass1() const {
return mClass;
@ -1504,5 +1505,8 @@ public:
void setClass(int _class) {
mClass = _class;
}
private:
int mClass;
};
#endif /* A_H_ */

View file

@ -18,11 +18,14 @@ import java.util.Properties;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
@ -41,6 +44,7 @@ public class GenerateGettersAndSettersTest extends RefactoringTest {
private String[] selectedSetters;
private GenerateGettersAndSettersRefactoring refactoring;
private boolean definitionSeparate;
private String ascendingVisibilityOrder;
/**
* @param name
@ -52,21 +56,30 @@ public class GenerateGettersAndSettersTest extends RefactoringTest {
@Override
protected void runTest() throws Throwable {
IFile file = project.getFile(fileName);
ICElement element = CoreModel.getDefault().create(file);
refactoring = new GenerateGettersAndSettersRefactoring(element, selection, cproject, astCache);
RefactoringStatus initialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
if (fatalError) {
assertConditionsFatalError(initialConditions);
return;
} else {
assertConditionsOk(initialConditions);
executeRefactoring();
try {
IFile file = project.getFile(fileName);
ICElement element = CoreModel.getDefault().create(file);
refactoring = new GenerateGettersAndSettersRefactoring(element, selection, cproject, astCache);
RefactoringStatus initialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
if (fatalError) {
assertConditionsFatalError(initialConditions);
return;
} else {
assertConditionsOk(initialConditions);
executeRefactoring();
}
} finally {
IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
store.setToDefault(PreferenceConstants.CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER);
}
}
private void executeRefactoring() throws CoreException, Exception {
if (ascendingVisibilityOrder != null) {
IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
store.setValue(PreferenceConstants.CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER, ascendingVisibilityOrder);
}
selectFields();
refactoring.getContext().setDefinitionSeparate(definitionSeparate);
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
@ -102,6 +115,7 @@ public class GenerateGettersAndSettersTest extends RefactoringTest {
String getters = refactoringProperties.getProperty("getters", ""); //$NON-NLS-1$ //$NON-NLS-2$
String setters = refactoringProperties.getProperty("setters", ""); //$NON-NLS-1$ //$NON-NLS-2$
definitionSeparate = Boolean.valueOf(refactoringProperties.getProperty("definitionSeparate", "false"));
ascendingVisibilityOrder = refactoringProperties.getProperty("ascendingVisibilityOrder", null);
selectedGetters = getters.split(",");
selectedSetters = setters.split(",");

View file

@ -8,12 +8,17 @@
*
* Contributors:
* Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.osgi.util.NLS;
import org.eclipse.text.edits.TextEditGroup;
@ -23,9 +28,14 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTVisibilityLabel;
@ -58,7 +68,7 @@ public class AddDeclarationNodeToClassChange {
private AddDeclarationNodeToClassChange(ICPPASTCompositeTypeSpecifier classNode,
VisibilityEnum visibility, List<IASTNode> nodesToAdd, ModificationCollector collector,
boolean isField) {
this.nodesToAdd = nodesToAdd;
this.nodesToAdd = new ArrayList<IASTNode>(nodesToAdd);
this.classNode = classNode;
this.visibility = visibility;
this.collector = collector;
@ -66,83 +76,65 @@ public class AddDeclarationNodeToClassChange {
}
private void createRewrites(boolean isField) {
int lastFunctionDeclaration = -1;
int lastFieldDeclaration = -1;
VisibilityEnum defaultVisibility = classNode.getKey() == IASTCompositeTypeSpecifier.k_struct ?
VisibilityEnum.v_public : VisibilityEnum.v_private;
VisibilityEnum currentVisibility = defaultVisibility;
boolean ascendingVisibilityOrder = isAscendingVisibilityOrder();
int lastFunctionIndex = -1;
int lastFieldIndex = -1;
int lastMatchingVisibilityIndex = -1;
int lastPrecedingVisibilityIndex = -1;
IASTDeclaration[] members = classNode.getMembers();
VisibilityEnum currentVisibility = classNode.getKey() == IASTCompositeTypeSpecifier.k_struct ?
VisibilityEnum.v_public : VisibilityEnum.v_private;
// Find the insert location by iterating over the elements of the class
// and remembering the last element with the matching visibility
// and remembering the last element with the matching visibility and the last element
// with preceding visibility (according to the visibility order preference).
for (int i = 0; i < members.length; i++) {
IASTDeclaration declaration = members[i];
if (declaration instanceof ICPPASTVisibilityLabel) {
currentVisibility = VisibilityEnum.from((ICPPASTVisibilityLabel) declaration);
} else if (declaration instanceof IASTSimpleDeclaration && currentVisibility.equals(visibility)) {
IASTSimpleDeclaration simple = (IASTSimpleDeclaration) declaration;
IASTDeclarator[] declarators = simple.getDeclarators();
if (declarators.length > 0 && declarators[0] != null) {
if (declarators[0] instanceof IASTFunctionDeclarator) {
lastFunctionDeclaration = i;
} else {
lastFieldDeclaration = i;
}
if (currentVisibility == visibility) {
lastMatchingVisibilityIndex = i;
if (declaration instanceof IASTSimpleDeclaration) {
IASTDeclarator[] declarators = ((IASTSimpleDeclaration) declaration).getDeclarators();
if (declarators.length > 0 && declarators[0] != null) {
if (declarators[0] instanceof IASTFunctionDeclarator) {
lastFunctionIndex = i;
} else {
lastFieldIndex = i;
}
}
} else if (declaration instanceof ICPPASTFunctionDefinition) {
lastFunctionIndex = i;
}
} else if (currentVisibility.compareTo(visibility) < 0 == ascendingVisibilityOrder) {
lastPrecedingVisibilityIndex = i;
}
}
IASTDeclaration nextFunctionDeclaration = null;
if (lastFunctionDeclaration < members.length - 1 && lastFunctionDeclaration >= 0)
nextFunctionDeclaration = members[lastFunctionDeclaration + 1];
IASTDeclaration nextFieldDeclaration = null;
if (lastFieldDeclaration < members.length - 1 && lastFieldDeclaration >= 0)
nextFieldDeclaration = members[lastFieldDeclaration + 1];
int index = isField && lastFieldIndex >= 0 || !isField && lastFunctionIndex < 0 ?
lastFieldIndex : lastFunctionIndex;
if (index < 0)
index = lastMatchingVisibilityIndex;
if (index < 0)
index = lastPrecedingVisibilityIndex;
index++;
IASTNode nextNode = index < members.length ? members[index] : null;
createInsert(isField, nextFunctionDeclaration, nextFieldDeclaration, currentVisibility);
}
private void createInsert(boolean isField, IASTDeclaration nextFunctionDeclaration,
IASTDeclaration nextFieldDeclaration, VisibilityEnum currentVisibility) {
if (isField) {
if (nextFieldDeclaration != null) {
insertBefore(nextFieldDeclaration);
} else if (nextFunctionDeclaration != null) {
insertBefore(nextFunctionDeclaration);
} else {
insertAtTheEnd(currentVisibility);
}
} else {
if (nextFunctionDeclaration != null) {
insertBefore(nextFunctionDeclaration);
} else if (nextFieldDeclaration != null) {
insertBefore(nextFieldDeclaration);
} else {
insertAtTheEnd(currentVisibility);
if (lastMatchingVisibilityIndex < 0 &&
!(index == 0 && classNode.getKey() == IASTCompositeTypeSpecifier.k_struct && visibility == defaultVisibility)) {
nodesToAdd.add(0, new CPPASTVisibilityLabel(visibility.getVisibilityLabelValue()));
if (index == 0 && nextNode != null && !(nextNode instanceof ICPPASTVisibilityLabel)) {
nodesToAdd.add(new CPPASTVisibilityLabel(defaultVisibility.getVisibilityLabelValue()));
}
}
}
private void insertBefore(IASTNode nextNode) {
ASTRewrite rewrite = collector.rewriterForTranslationUnit(nextNode.getTranslationUnit());
for (IASTNode node : nodesToAdd) {
rewrite.insertBefore(nextNode.getParent(), nextNode, node, createEditDescription());
}
}
private void insertAtTheEnd(VisibilityEnum currentVisibility) {
ASTRewrite rewrite = collector.rewriterForTranslationUnit(classNode.getTranslationUnit());
if (!currentVisibility.equals(visibility)) {
ICPPASTVisibilityLabel label =
new CPPASTVisibilityLabel(visibility.getICPPASTVisiblityLabelVisibility());
rewrite.insertBefore(classNode, null, label, createEditDescription());
}
for (IASTNode node : nodesToAdd) {
rewrite.insertBefore(classNode, null, node, createEditDescription());
rewrite.insertBefore(classNode, nextNode, node, createEditDescription());
}
}
@ -150,4 +142,14 @@ public class AddDeclarationNodeToClassChange {
return new TextEditGroup(NLS.bind(Messages.AddDeclarationNodeToClassChange_AddDeclaration,
classNode.getName()));
}
private boolean isAscendingVisibilityOrder() {
IPreferencesService preferences = Platform.getPreferencesService();
IASTTranslationUnit ast = classNode.getTranslationUnit();
ITranslationUnit tu = ast.getOriginatingTranslationUnit();
IProject project = tu != null ? tu.getCProject().getProject() : null;
return preferences.getBoolean(CUIPlugin.PLUGIN_ID,
PreferenceConstants.CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER, false,
PreferenceConstants.getPreferenceScopes(project));
}
}

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.utils;
@ -17,22 +17,26 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBas
/**
* Enum that represents C++ visibilities, with methods to convert to
* and from ICPPASTVisiblityLabel.
*
*/
public enum VisibilityEnum {
v_public(Messages.VisibilityEnum_public),
v_protected(Messages.VisibilityEnum_protected),
v_private(Messages.VisibilityEnum_private);
// The values are ordered by increasing visibility.
v_private(Messages.VisibilityEnum_private, ICPPASTVisibilityLabel.v_private, ICPPASTBaseSpecifier.v_private),
v_protected(Messages.VisibilityEnum_protected, ICPPASTVisibilityLabel.v_protected, ICPPASTBaseSpecifier.v_protected),
v_public(Messages.VisibilityEnum_public, ICPPASTVisibilityLabel.v_public, ICPPASTBaseSpecifier.v_public);
private final String stringRepresentation;
private final int visibilityLabelValue;
private final int baseSpecifierValue;
VisibilityEnum(String stringRepresentation) {
private VisibilityEnum(String stringRepresentation, int visibilityLabelValue,
int baseSpecifierValue) {
this.stringRepresentation = stringRepresentation;
this.visibilityLabelValue = visibilityLabelValue;
this.baseSpecifierValue = baseSpecifierValue;
}
public static VisibilityEnum from(ICPPASTVisibilityLabel visibility) {
switch(visibility.getVisibility()){
switch (visibility.getVisibility()) {
case ICPPASTVisibilityLabel.v_private:
return VisibilityEnum.v_private;
case ICPPASTVisibilityLabel.v_protected:
@ -43,36 +47,20 @@ public enum VisibilityEnum {
return null;
}
public int getASTBaseSpecifierVisibility() {
switch (this) {
case v_private:
return ICPPASTBaseSpecifier.v_private;
case v_protected:
return ICPPASTBaseSpecifier.v_protected;
case v_public:
return ICPPASTBaseSpecifier.v_public;
}
return 0;
public int getBaseSpecifierValue() {
return baseSpecifierValue;
}
public int getICPPASTVisiblityLabelVisibility() {
switch (this) {
case v_private:
return ICPPASTVisibilityLabel.v_private;
case v_protected:
return ICPPASTVisibilityLabel.v_protected;
case v_public:
return ICPPASTVisibilityLabel.v_public;
}
return 0;
public int getVisibilityLabelValue() {
return visibilityLabelValue;
}
public static VisibilityEnum getEnumForStringRepresentation(String visibility){
if( VisibilityEnum.v_private.toString().equals( visibility ) ) {
public static VisibilityEnum getEnumForStringRepresentation(String visibility) {
if (VisibilityEnum.v_private.toString().equals(visibility)) {
return VisibilityEnum.v_private;
}else if( VisibilityEnum.v_protected.toString().equals( visibility ) ) {
} else if (VisibilityEnum.v_protected.toString().equals(visibility)) {
return VisibilityEnum.v_protected;
}else if ( VisibilityEnum.v_public.toString().equals( visibility ) ) {
} else if (VisibilityEnum.v_public.toString().equals(visibility)) {
return VisibilityEnum.v_public;
}
return null;

View file

@ -17,9 +17,12 @@ package org.eclipse.cdt.ui;
import java.util.Locale;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceStore;
@ -597,7 +600,8 @@ public class PreferenceConstants {
public final static String EDITOR_TEXT_FONT= "org.eclipse.cdt.ui.editors.textfont"; //$NON-NLS-1$
/**
* A named preference that controls whether the cview's selection is linked to the active editor.
* A named preference that controls whether the cview's selection is linked to the active
* editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
@ -605,7 +609,8 @@ public class PreferenceConstants {
public static final String PREF_LINK_TO_EDITOR= "org.eclipse.cdt.ui.editor.linkToEditor"; //$NON-NLS-1$
/**
* A named preference that speficies whether children of a translation unit are shown in the CView.
* A named preference that specifies whether children of a translation unit are shown in
* the CView.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
@ -613,7 +618,8 @@ public class PreferenceConstants {
public static final String PREF_SHOW_CU_CHILDREN= "org.eclipse.cdt.ui.editor.CUChildren"; //$NON-NLS-1$
/**
* A named preference that speficies whether to use the parser's structural mode to build the CModel.
* A named preference that speficies whether to use the parser's structural mode to build
* the CModel.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
@ -621,7 +627,8 @@ public class PreferenceConstants {
public static final String PREF_USE_STRUCTURAL_PARSE_MODE= "org.eclipse.cdt.ui.editor.UseStructuralMode"; //$NON-NLS-1$
/**
* A named preference that controls if segmented view (show selected element only) is turned on or off.
* A named preference that controls if segmented view (show selected element only) is turned
* on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
@ -818,8 +825,8 @@ public class PreferenceConstants {
public static final String OUTLINE_LINK_TO_EDITOR = "org.eclipse.cdt.ui.outline.linktoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether include directives should be grouped in the
* C/C++ Projects view and the Project Explorer view.
* A named preference that controls whether include directives should be grouped in
* the C/C++ Projects view and the Project Explorer view.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
@ -827,8 +834,8 @@ public class PreferenceConstants {
public static final String CVIEW_GROUP_INCLUDES= "org.eclipse.cdt.ui.cview.groupincludes"; //$NON-NLS-1$
/**
* A named preference that controls whether macro defintions should be grouped in the
* C/C++ Projects view and the Project Explorer view.
* A named preference that controls whether macro definitions should be grouped in
* the C/C++ Projects view and the Project Explorer view.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
@ -837,8 +844,8 @@ public class PreferenceConstants {
public static final String CVIEW_GROUP_MACROS= "org.eclipse.cdt.ui.cview.groupmacros"; //$NON-NLS-1$
/**
* A named preference that controls whether header and source files should be separated in the
* C/C++ Projects view and the Project Explorer view.
* A named preference that controls whether header and source files should be separated in
* the C/C++ Projects view and the Project Explorer view.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
@ -1878,6 +1885,18 @@ public class PreferenceConstants {
*/
public static final int NAME_STYLE_CAPITALIZATION_LOWER_CAMEL_CASE = 4;
/**
* A named preference that controls order of private/protected/public class members in generated
* code.
* <p>
* Value is of type <code>Boolean</code>. The <code>true</code> value means that private members
* are before public ones. The default is to put public members before private ones.
*
* @since 5.4
*/
public static final String CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER = "class_member_ascending_visibility_order"; //$NON-NLS-1$
/**
* Returns the CDT-UI preference store.
*
@ -2089,9 +2108,9 @@ public class PreferenceConstants {
/**
* Returns the node in the preference in the given context.
* @param key The preference key.
* @param project The current context or <code>null</code> if no context is available and the
* workspace setting should be taken. Note that passing <code>null</code> should
* be avoided.
* @param project The current context or <code>null</code> if no context is available and
* the workspace setting should be taken. Note that passing <code>null</code> should
* be avoided.
* @return Returns the node matching the given context.
*/
private static IEclipsePreferences getPreferenceNode(String key, ICProject project) {
@ -2108,15 +2127,20 @@ public class PreferenceConstants {
return node;
}
node = ConfigurationScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID);
if (node.get(key, null) != null) {
return node;
}
return DefaultScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID);
}
/**
* Returns the string value for the given key in the given context.
* @param key The preference key
* @param project The current context or <code>null</code> if no context is available and the
* workspace setting should be taken. Note that passing <code>null</code> should
* be avoided.
* @param project The current context or <code>null</code> if no context is available and
* the workspace setting should be taken. Note that passing <code>null</code> should
* be avoided.
* @return Returns the current value for the string.
* @since 5.0
*/
@ -2127,9 +2151,9 @@ public class PreferenceConstants {
/**
* Returns the integer value for the given key in the given context.
* @param key The preference key
* @param project The current context or <code>null</code> if no context is available and the
* workspace setting should be taken. Note that passing <code>null</code> should
* be avoided.
* @param project The current context or <code>null</code> if no context is available and
* the workspace setting should be taken. Note that passing <code>null</code> should
* be avoided.
* @param defaultValue The default value if not specified in the preferences.
* @return Returns the current value for the string.
* @since 5.1
@ -2141,9 +2165,9 @@ public class PreferenceConstants {
/**
* Returns the boolean value for the given key in the given context.
* @param key The preference key
* @param project The current context or <code>null</code> if no context is available and the
* workspace setting should be taken. Note that passing <code>null</code> should
* be avoided.
* @param project The current context or <code>null</code> if no context is available and
* the workspace setting should be taken. Note that passing <code>null</code> should
* be avoided.
* @param defaultValue The default value if not specified in the preferences.
* @return Returns the current value for the string.
* @since 5.1
@ -2152,4 +2176,16 @@ public class PreferenceConstants {
return getPreferenceNode(key, project).getBoolean(key, defaultValue);
}
/**
* Returns the scopes for preference lookup.
*
* @param project a project or <code>null</code>
* @return the scopes for preference lookup.
* @since 5.4
*/
public static IScopeContext[] getPreferenceScopes(IProject project) {
return project != null ?
new IScopeContext[] { new ProjectScope(project), InstanceScope.INSTANCE, ConfigurationScope.INSTANCE, DefaultScope.INSTANCE } :
new IScopeContext[] { InstanceScope.INSTANCE, ConfigurationScope.INSTANCE, DefaultScope.INSTANCE };
}
}