Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmanuel Graf2008-09-05 05:40:42 -0400
committerEmanuel Graf2008-09-05 05:40:42 -0400
commit54e73948e3071ffc9942fe0fa2f92a71efe4806c (patch)
treec81d6b5c832c10cb52d592a866796dccecc6b67c
parentae91e3e151e98236e5523357c374b317d0352334 (diff)
downloadorg.eclipse.cdt-54e73948e3071ffc9942fe0fa2f92a71efe4806c.tar.gz
org.eclipse.cdt-54e73948e3071ffc9942fe0fa2f92a71efe4806c.tar.xz
org.eclipse.cdt-54e73948e3071ffc9942fe0fa2f92a71efe4806c.zip
NEW - bug 246058: [Refactoring] issues generating getters setters with 2 classes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=246058
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java16
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoring.java63
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java1
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/messages.properties1
4 files changed, 71 insertions, 10 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java
index 4e28ca81d5..cd8bcffead 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java
@@ -52,13 +52,15 @@ public class GenerateGettersAndSettersInputPage extends UserInputWizardPage {
variableSelectionView.setContentProvider(context);
variableSelectionView.setAutoExpandLevel(3);
variableSelectionView.setInput(""); //$NON-NLS-1$
-
- for(Object obj : variableSelectionView.getVisibleExpandedElements()) {
- System.out.println();
- if (obj instanceof FieldWrapper){
- if(obj.toString().contains(context.selectedName.getRawSignature())){
- variableSelectionView.setSubtreeChecked(obj, true);
- }
+ if(context.selectedName != null) {
+ String rawSignature = context.selectedName.getRawSignature();
+ for(Object obj : variableSelectionView.getVisibleExpandedElements()) {
+ if (obj instanceof FieldWrapper){
+
+ if(obj.toString().contains(rawSignature)){
+ variableSelectionView.setSubtreeChecked(obj, true);
+ }
+ }
}
}
ArrayList<GetterSetterInsertEditProvider> checkedFunctions = new ArrayList<GetterSetterInsertEditProvider>();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoring.java
index eaccaa89ca..908de7bee8 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoring.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoring.java
@@ -23,8 +23,12 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
@@ -36,6 +40,7 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
+import org.eclipse.cdt.internal.ui.refactoring.Container;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
@@ -46,6 +51,33 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
*/
public class GenerateGettersAndSettersRefactoring extends CRefactoring {
+ private final class CompositeTypeSpecFinder extends CPPASTVisitor {
+ private final int start;
+ private final Container<IASTCompositeTypeSpecifier> container;
+ {
+ shouldVisitDeclSpecifiers = true;
+ }
+
+ private CompositeTypeSpecFinder(int start, Container<IASTCompositeTypeSpecifier> container) {
+ this.start = start;
+ this.container = container;
+ }
+
+ @Override
+ public int visit(IASTDeclSpecifier declSpec) {
+
+ if (declSpec instanceof IASTCompositeTypeSpecifier) {
+ IASTFileLocation loc = declSpec.getFileLocation();
+ if(start > loc.getNodeOffset() && start < loc.getNodeOffset()+ loc.getNodeLength()) {
+ container.setObject((IASTCompositeTypeSpecifier) declSpec);
+ return ASTVisitor.PROCESS_ABORT;
+ }
+ }
+
+ return super.visit(declSpec);
+ }
+ }
+
private static final String MEMBER_DECLARATION = "MEMBER_DECLARATION"; //$NON-NLS-1$
private final GetterAndSetterContext context = new GetterAndSetterContext();
@@ -72,9 +104,34 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
loadTranslationUnit(initStatus, pm);
context.setUnit(unit);
context.selectedName = getSelectedName();
- findDeclarations();
+ IASTCompositeTypeSpecifier compositeTypeSpecifier = null;
+ if(context.selectedName != null) {
+ compositeTypeSpecifier = getCompositeTypeSpecifier(context.selectedName);
+ }else {
+ compositeTypeSpecifier = findCurrentCompositeTypeSpecifier();
+ }
+ if(compositeTypeSpecifier != null) {
+ findDeclarations(compositeTypeSpecifier);
+ }else {
+ initStatus.addFatalError(Messages.GenerateGettersAndSettersRefactoring_NoCassDefFound);
+ }
}
+ private IASTCompositeTypeSpecifier findCurrentCompositeTypeSpecifier() {
+ final int start = region.getOffset();
+ Container<IASTCompositeTypeSpecifier> container = new Container<IASTCompositeTypeSpecifier>();
+ unit.accept(new CompositeTypeSpecFinder(start, container));
+ return container.getObject();
+ }
+
+ private IASTCompositeTypeSpecifier getCompositeTypeSpecifier(IASTName selectedName) {
+ IASTNode node = selectedName;
+ while(node != null && !(node instanceof IASTCompositeTypeSpecifier)) {
+ node = node.getParent();
+ }
+ return (IASTCompositeTypeSpecifier) node;
+ }
+
private IASTName getSelectedName() {
ArrayList<IASTName> names = findAllMarkedNames();
if (names.size() < 1) {
@@ -83,9 +140,9 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
return names.get(names.size()-1);
}
- protected void findDeclarations() {
+ protected void findDeclarations(IASTCompositeTypeSpecifier compositeTypeSpecifier) {
- unit.accept(new CPPASTVisitor() {
+ compositeTypeSpecifier.accept(new CPPASTVisitor() {
{
shouldVisitDeclarations = true;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java
index 4dec2ab88d..cc5a1bf11b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java
@@ -21,6 +21,7 @@ public final class Messages extends NLS {
// Do not instantiate
}
+ public static String GenerateGettersAndSettersRefactoring_NoCassDefFound;
public static String GenerateGettersAndSettersRefactoring_NoFields;
public static String GettersAndSetters_Name;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/messages.properties
index c1bde5de90..932218380d 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/messages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/messages.properties
@@ -10,4 +10,5 @@
# Institute for Software - initial API and implementation
###############################################################################
GettersAndSetters_Name=Generate Getters and Setters
+GenerateGettersAndSettersRefactoring_NoCassDefFound=No class definition found
GenerateGettersAndSettersRefactoring_NoFields=The class does not contain any fields.

Back to the top