mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Proper handling of class declarations located in cpp files.
This commit is contained in:
parent
496ce4cf38
commit
1f51445b8a
9 changed files with 71 additions and 61 deletions
|
@ -3,7 +3,6 @@
|
|||
//@.config
|
||||
filename=C.h
|
||||
getters=name
|
||||
inHeader=true
|
||||
//@C.cpp
|
||||
#include "C.h"
|
||||
|
||||
|
@ -104,7 +103,6 @@ int gooo = 1;
|
|||
//@.config
|
||||
filename=C.h
|
||||
getters=name
|
||||
inHeader=true
|
||||
//@C.cpp
|
||||
#include "C.h"
|
||||
|
||||
|
@ -215,7 +213,6 @@ int gooo = 1;
|
|||
//@.config
|
||||
filename=C.h
|
||||
setters=name
|
||||
inHeader=true
|
||||
//@C.cpp
|
||||
#include "C.h"
|
||||
|
||||
|
@ -319,7 +316,6 @@ int gooo = 1;
|
|||
filename=C.h
|
||||
setters=name
|
||||
getters=name
|
||||
inHeader=true
|
||||
//@C.cpp
|
||||
#include "C.h"
|
||||
|
||||
|
@ -427,7 +423,6 @@ int gooo = 1;
|
|||
filename=C.h
|
||||
getters=name,systemId
|
||||
setters=name,systemId
|
||||
inHeader=true
|
||||
//@C.cpp
|
||||
#include "C.h"
|
||||
|
||||
|
@ -527,7 +522,6 @@ int gooo = 1;
|
|||
filename=GaS.h
|
||||
getters=i,ok
|
||||
setters=i,ok
|
||||
inHeader=true
|
||||
//@GaS.cpp
|
||||
#include "Getters.h"
|
||||
|
||||
|
@ -593,7 +587,6 @@ private:
|
|||
filename=C.h
|
||||
getters=id
|
||||
setters=id
|
||||
inHeader=true
|
||||
//@C.h
|
||||
#ifndef C_H_
|
||||
#define C_H_
|
||||
|
@ -631,7 +624,6 @@ public:
|
|||
filename=C.h
|
||||
getters=i
|
||||
setters=i
|
||||
inHeader=true
|
||||
//@C.h
|
||||
/*
|
||||
* test.h
|
||||
|
@ -705,19 +697,19 @@ class test {
|
|||
#define TEST_H_
|
||||
|
||||
//comment1
|
||||
class test
|
||||
{
|
||||
class test {
|
||||
void test();
|
||||
//comment3
|
||||
};
|
||||
|
||||
#endif /* TEST_H_ */
|
||||
|
||||
//!Generate Getters and Setters One Getter Selection Implementation in CPP
|
||||
//!Generate Getters and Setters One Getter Selection Separate Definition
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
|
||||
//@.config
|
||||
filename=C.h
|
||||
getters=name
|
||||
definitionSeparate=true
|
||||
//@C.cpp
|
||||
#include "C.h"
|
||||
|
||||
|
@ -815,11 +807,12 @@ public:
|
|||
int gooo = 1;
|
||||
|
||||
#endif /*C_H_*/
|
||||
//!Generate Getters and Setters One Getter Selection with Namespace Implementation in CPP
|
||||
//!Generate Getters and Setters One Getter Selection with Namespace Separate Definition
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
|
||||
//@.config
|
||||
filename=C.h
|
||||
getters=name
|
||||
definitionSeparate=true
|
||||
//@C.cpp
|
||||
#include "C.h"
|
||||
|
||||
|
@ -943,11 +936,12 @@ int gooo = 1;
|
|||
|
||||
#endif /*C_H_*/
|
||||
|
||||
//!Generate Getters and Setters One Setter Selection Implementation in CPP
|
||||
//!Generate Getters and Setters One Setter Selection Separate Definition
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
|
||||
//@.config
|
||||
filename=C.h
|
||||
setters=name
|
||||
definitionSeparate=true
|
||||
//@C.cpp
|
||||
#include "C.h"
|
||||
|
||||
|
@ -1057,12 +1051,13 @@ public:
|
|||
int gooo = 1;
|
||||
|
||||
#endif /*C_H_*/
|
||||
//!Getter and Setter Selection Implementation in CPP
|
||||
//!Getter and Setter Selection Separate Definition
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
|
||||
//@.config
|
||||
filename=C.h
|
||||
setters=name
|
||||
getters=name
|
||||
definitionSeparate=true
|
||||
//@C.cpp
|
||||
#include "C.h"
|
||||
|
||||
|
@ -1177,13 +1172,13 @@ int gooo = 1;
|
|||
|
||||
#endif /*C_H_*/
|
||||
|
||||
//!Generate Getters and Setters no Methods Implementation in CPP
|
||||
//!Generate Getters and Setters no Methods Separate Definition
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
|
||||
//@.config
|
||||
filename=C.h
|
||||
getters=id
|
||||
setters=id
|
||||
infos=1
|
||||
definitionSeparate=true
|
||||
//@C.h
|
||||
#ifndef C_H_
|
||||
#define C_H_
|
||||
|
@ -1208,24 +1203,24 @@ public:
|
|||
void setId(int id);
|
||||
};
|
||||
|
||||
int Person::getId() const {
|
||||
inline int Person::getId() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
void Person::setId(int id) {
|
||||
inline void Person::setId(int id) {
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
|
||||
#endif /*C_H_*/
|
||||
|
||||
//!No Methods Implementation in CPP
|
||||
//!No Methods Separate Definition
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
|
||||
//@.config
|
||||
filename=C.h
|
||||
getters=i
|
||||
setters=i
|
||||
infos=1
|
||||
definitionSeparate=true
|
||||
//@C.h
|
||||
/*
|
||||
* test.h
|
||||
|
@ -1262,11 +1257,11 @@ public:
|
|||
void setI(int i);
|
||||
};
|
||||
|
||||
int test::getI() const {
|
||||
inline int test::getI() const {
|
||||
return i;
|
||||
}
|
||||
|
||||
void test::setI(int i) {
|
||||
inline void test::setI(int i) {
|
||||
this->i = i;
|
||||
}
|
||||
|
||||
|
@ -1279,6 +1274,7 @@ void test::setI(int i) {
|
|||
filename=Test.h
|
||||
getters=testField
|
||||
setters=testField
|
||||
definitionSeparate=true
|
||||
|
||||
//@Test.h
|
||||
#ifndef TEST_H_
|
||||
|
@ -1346,6 +1342,7 @@ void Test::foo() {
|
|||
filename=Test.h
|
||||
getters=testField
|
||||
setters=testField
|
||||
definitionSeparate=true
|
||||
|
||||
//@Test.h
|
||||
#ifndef TEST_H_
|
||||
|
@ -1386,6 +1383,7 @@ void Test::setTestField(int testField) {
|
|||
filename=component_b/public_headers/Test.h
|
||||
getters=testField
|
||||
setters=testField
|
||||
definitionSeparate=true
|
||||
|
||||
//@component_b/public_headers/Test.h
|
||||
#ifndef TEST_H_
|
||||
|
|
|
@ -109,7 +109,7 @@ public abstract class RefactoringTest extends RefactoringBaseTest {
|
|||
|
||||
protected void assertConditionsInfo(RefactoringStatus status, int number) {
|
||||
if (number > 0) {
|
||||
assertTrue("Info in Condition expected", status.hasInfo()); //$NON-NLS-1$
|
||||
assertTrue("Info in condition expected", status.hasInfo()); //$NON-NLS-1$
|
||||
}
|
||||
RefactoringStatusEntry[] entries = status.getEntries();
|
||||
int count = 0;
|
||||
|
@ -123,7 +123,7 @@ public abstract class RefactoringTest extends RefactoringBaseTest {
|
|||
|
||||
protected void assertConditionsError(RefactoringStatus status, int number) {
|
||||
if (number > 0) {
|
||||
assertTrue("Error in Condition expected", status.hasError()); //$NON-NLS-1$
|
||||
assertTrue("Error in condition expected", status.hasError()); //$NON-NLS-1$
|
||||
}
|
||||
RefactoringStatusEntry[] entries = status.getEntries();
|
||||
int count = 0;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Emanuel Graf & Leo Buettiker - initial API and implementation
|
||||
|
@ -41,7 +41,7 @@ public class GenerateGettersAndSettersTest extends RefactoringTest {
|
|||
private List<String> selectedGetters;
|
||||
private List<String> selectedSetters;
|
||||
private GenerateGettersAndSettersRefactoring refactoring;
|
||||
private boolean keepInHeader;
|
||||
private boolean definitionSeparate;
|
||||
private int infos;
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,7 @@ public class GenerateGettersAndSettersTest extends RefactoringTest {
|
|||
|
||||
private void executeRefactoring() throws CoreException, Exception {
|
||||
selectFields();
|
||||
refactoring.getContext().setImplementationInHeader(keepInHeader);
|
||||
refactoring.getContext().setDefinitionSeparate(definitionSeparate);
|
||||
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
|
||||
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
|
||||
if (warnings > 0) {
|
||||
|
@ -109,7 +109,7 @@ public class GenerateGettersAndSettersTest extends RefactoringTest {
|
|||
infos = new Integer(refactoringProperties.getProperty("infos", "0"));
|
||||
String getters = refactoringProperties.getProperty("getters", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
String setters = refactoringProperties.getProperty("setters", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
keepInHeader = Boolean.valueOf(refactoringProperties.getProperty("inHeader", "false"));
|
||||
definitionSeparate = Boolean.valueOf(refactoringProperties.getProperty("definitionSeparate", "false"));
|
||||
|
||||
selectedGetters = new ArrayList<String>();
|
||||
for (String getterName : getters.split(",")) { //$NON-NLS-1$
|
||||
|
|
|
@ -68,18 +68,18 @@ public class GenerateGettersAndSettersInputPage extends UserInputWizardPage impl
|
|||
gd = new GridData();
|
||||
gd.verticalAlignment = SWT.TOP;
|
||||
btComp.setLayoutData(gd);
|
||||
|
||||
final Button placeImplemetation = new Button(comp, SWT.CHECK);
|
||||
placeImplemetation.setText(Messages.GenerateGettersAndSettersInputPage_PlaceImplHeader);
|
||||
|
||||
final Button definitionSeparate = new Button(comp, SWT.CHECK);
|
||||
definitionSeparate.setText(Messages.GenerateGettersAndSettersInputPage_SeparateDefinition);
|
||||
gd = new GridData();
|
||||
gd.horizontalSpan = 2;
|
||||
gd.heightHint = 40;
|
||||
placeImplemetation.setLayoutData(gd);
|
||||
placeImplemetation.setSelection(context.isImplementationInHeader());
|
||||
placeImplemetation.addSelectionListener(new SelectionAdapter() {
|
||||
definitionSeparate.setLayoutData(gd);
|
||||
definitionSeparate.setSelection(context.isDefinitionSeparate());
|
||||
definitionSeparate.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
context.setImplementationInHeader(placeImplemetation.getSelection());
|
||||
context.setDefinitionSeparate(definitionSeparate.getSelection());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -121,9 +121,10 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
|
|||
public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
|
||||
CheckConditionsContext checkContext) throws CoreException, OperationCanceledException {
|
||||
RefactoringStatus result = new RefactoringStatus();
|
||||
if (!context.isImplementationInHeader()) {
|
||||
if (context.isDefinitionSeparate()) {
|
||||
findDefinitionInsertLocation(pm);
|
||||
if (definitionInsertLocation == null || tu.equals(definitionInsertLocation.getTranslationUnit())) {
|
||||
if (definitionInsertLocation == null ||
|
||||
definitionInsertLocation.getTranslationUnit() == null) {
|
||||
result.addInfo(Messages.GenerateGettersAndSettersRefactoring_NoImplFile);
|
||||
}
|
||||
}
|
||||
|
@ -230,14 +231,19 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
|
|||
List<IASTNode> getterAndSetters = new ArrayList<IASTNode>();
|
||||
List<IASTFunctionDefinition> definitions = new ArrayList<IASTFunctionDefinition>();
|
||||
for (GetterSetterInsertEditProvider currentProvider : context.selectedFunctions) {
|
||||
if (context.isImplementationInHeader()) {
|
||||
getterAndSetters.add(currentProvider.getFunctionDefinition(false));
|
||||
} else {
|
||||
if (context.isDefinitionSeparate()) {
|
||||
getterAndSetters.add(currentProvider.getFunctionDeclaration());
|
||||
definitions.add(currentProvider.getFunctionDefinition(true));
|
||||
IASTFunctionDefinition functionDefinition = currentProvider.getFunctionDefinition(true);
|
||||
// Standalone definitions in a header file have to be declared inline.
|
||||
if (definitionInsertLocation.getTranslationUnit().isHeaderUnit()) {
|
||||
functionDefinition.getDeclSpecifier().setInline(true);
|
||||
}
|
||||
definitions.add(functionDefinition);
|
||||
} else {
|
||||
getterAndSetters.add(currentProvider.getFunctionDefinition(false));
|
||||
}
|
||||
}
|
||||
if (!context.isImplementationInHeader()) {
|
||||
if (context.isDefinitionSeparate()) {
|
||||
addDefinition(collector, definitions, pm);
|
||||
}
|
||||
ICPPASTCompositeTypeSpecifier classDefinition =
|
||||
|
@ -271,9 +277,9 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
|
|||
}
|
||||
|
||||
IASTSimpleDeclaration decl = context.existingFields.get(0);
|
||||
MethodDefinitionInsertLocationFinder methodDefinitionInsertLocationFinder = new MethodDefinitionInsertLocationFinder();
|
||||
InsertLocation location = methodDefinitionInsertLocationFinder.find(
|
||||
tu, decl.getFileLocation(), decl.getParent(), astCache, pm);
|
||||
MethodDefinitionInsertLocationFinder locationFinder = new MethodDefinitionInsertLocationFinder();
|
||||
InsertLocation location = locationFinder.find(tu, decl.getFileLocation(), decl.getParent(),
|
||||
astCache, pm);
|
||||
|
||||
if (location.getFile() == null || NodeHelper.isContainedInTemplateDeclaration(decl)) {
|
||||
location.setNodeToInsertAfter(NodeHelper.findTopLevelParent(decl), tu);
|
||||
|
|
|
@ -33,7 +33,7 @@ public class GetterSetterContext implements ITreeContentProvider {
|
|||
public SortedSet<GetterSetterInsertEditProvider> selectedFunctions = new TreeSet<GetterSetterInsertEditProvider>();
|
||||
public IASTName selectedName;
|
||||
private ArrayList<FieldWrapper> wrappedFields;
|
||||
private boolean implementationInHeader = false;
|
||||
private boolean definitionSeparate;
|
||||
|
||||
@Override
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
|
@ -84,9 +84,11 @@ public class GetterSetterContext implements ITreeContentProvider {
|
|||
}
|
||||
|
||||
public void refresh() {
|
||||
// We only recreate the function declarations instead of recreating GetterSetterInsertEditProviders.
|
||||
// That way, selectedFunctions is still valid. Also, the objects inside the TreeViewer are still the same
|
||||
// which is convenient because that way we don't need to save then restore the collapsed/expanded+checked/unchecked state of the TreeViewer.
|
||||
// We only recreate the function declarations instead of recreating
|
||||
// GetterSetterInsertEditProviders. That way, selectedFunctions is still valid.
|
||||
// Also, the objects inside the TreeViewer are still the same, which is convenient because
|
||||
// that way we don't need to save then restore the collapsed/expanded+checked/unchecked
|
||||
// state of the TreeViewer.
|
||||
for (FieldWrapper wrapper : wrappedFields) {
|
||||
for (GetterSetterInsertEditProvider provider : wrapper.childNodes) {
|
||||
provider.createFunctionDeclaration();
|
||||
|
@ -102,12 +104,12 @@ public class GetterSetterContext implements ITreeContentProvider {
|
|||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
}
|
||||
|
||||
public boolean isImplementationInHeader() {
|
||||
return implementationInHeader;
|
||||
public boolean isDefinitionSeparate() {
|
||||
return definitionSeparate;
|
||||
}
|
||||
|
||||
public void setImplementationInHeader(boolean implementationInHeader) {
|
||||
this.implementationInHeader = implementationInHeader;
|
||||
public void setDefinitionSeparate(boolean definitionSeparate) {
|
||||
this.definitionSeparate = definitionSeparate;
|
||||
}
|
||||
|
||||
private ArrayList<FieldWrapper> getWrappedFields() {
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.eclipse.osgi.util.NLS;
|
|||
public final class Messages extends NLS {
|
||||
public static String GenerateGettersAndSettersInputPage_DeselectAll;
|
||||
public static String GenerateGettersAndSettersInputPage_header;
|
||||
public static String GenerateGettersAndSettersInputPage_PlaceImplHeader;
|
||||
public static String GenerateGettersAndSettersInputPage_SeparateDefinition;
|
||||
public static String GenerateGettersAndSettersInputPage_SelectAll;
|
||||
public static String GenerateGettersAndSettersInputPage_SelectGetters;
|
||||
public static String GenerateGettersAndSettersInputPage_SelectSetters;
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
# Contributors:
|
||||
# Institute for Software - initial API and implementation
|
||||
# Institute for Software - initial API and implementation
|
||||
###############################################################################
|
||||
GettersAndSetters_Name=Generate getters and setters
|
||||
GenerateGettersAndSettersInputPage_DeselectAll=Deselect All
|
||||
GenerateGettersAndSettersInputPage_header=Select getters and setters to create:
|
||||
GenerateGettersAndSettersInputPage_PlaceImplHeader=Place implementation in header file
|
||||
GenerateGettersAndSettersInputPage_SeparateDefinition=Definition separate from declaration
|
||||
GenerateGettersAndSettersInputPage_SelectAll=Select All
|
||||
GenerateGettersAndSettersInputPage_SelectGetters=Select Getters
|
||||
GenerateGettersAndSettersInputPage_SelectSetters=Select Setters
|
||||
|
|
|
@ -105,11 +105,15 @@ public class MethodDefinitionInsertLocationFinder {
|
|||
}
|
||||
|
||||
if (insertLocation.getTranslationUnit() == null) {
|
||||
ITranslationUnit partner = SourceHeaderPartnerFinder.getPartnerTranslationUnit(
|
||||
declarationTu, astCache);
|
||||
if (partner != null) {
|
||||
insertLocation.setParentNode(astCache.getAST(partner, null), partner);
|
||||
}
|
||||
if (declarationTu.isHeaderUnit()) {
|
||||
ITranslationUnit partner = SourceHeaderPartnerFinder.getPartnerTranslationUnit(
|
||||
declarationTu, astCache);
|
||||
if (partner != null) {
|
||||
insertLocation.setParentNode(astCache.getAST(partner, null), partner);
|
||||
}
|
||||
} else {
|
||||
insertLocation.setParentNode(parent.getTranslationUnit(), declarationTu);
|
||||
}
|
||||
}
|
||||
|
||||
return insertLocation;
|
||||
|
|
Loading…
Add table
Reference in a new issue