From fe0dcb5176bf0905d89cf849aba684bb3e8fdd38 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Thu, 22 Sep 2016 14:10:40 -0700 Subject: [PATCH] Improved Remove Unused Declarations refactoring. Change-Id: Ibc011f9bacb8565463762f013738118eed839757 --- .../RemoveUnusedDeclarationsRefactoring.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/reducer/RemoveUnusedDeclarationsRefactoring.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/reducer/RemoveUnusedDeclarationsRefactoring.java index 61a05a8172e..1167f6f9302 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/reducer/RemoveUnusedDeclarationsRefactoring.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/reducer/RemoveUnusedDeclarationsRefactoring.java @@ -48,6 +48,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -357,15 +358,20 @@ public class RemoveUnusedDeclarationsRefactoring extends CRefactoring { IASTName name = declarator.getName(); if (name instanceof ICPPASTConversionName || name instanceof ICPPASTOperatorName) return null; // Do not remove operators. - names.add(name); + addNameIfNotEmpty(name, names); } IASTDeclSpecifier declSpecifier = ((IASTSimpleDeclaration) declaration).getDeclSpecifier(); if (declSpecifier instanceof IASTCompositeTypeSpecifier) { - names.add(((IASTCompositeTypeSpecifier) declSpecifier).getName()); + addNameIfNotEmpty(((IASTCompositeTypeSpecifier) declSpecifier).getName(), names); } else if (declSpecifier instanceof IASTElaboratedTypeSpecifier) { - names.add(((IASTElaboratedTypeSpecifier) declSpecifier).getName()); + addNameIfNotEmpty(((IASTElaboratedTypeSpecifier) declSpecifier).getName(), names); } else if (declSpecifier instanceof IASTEnumerationSpecifier) { - names.add(((IASTEnumerationSpecifier) declSpecifier).getName()); + IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) declSpecifier; + IASTName name = enumSpecifier.getName(); + addNameIfNotEmpty(name, names); + for (IASTEnumerator enumerator : enumSpecifier.getEnumerators()) { + addNameIfNotEmpty(enumerator.getName(), names); + } } return names; } else if (declaration instanceof IASTFunctionDefinition) { @@ -387,6 +393,11 @@ public class RemoveUnusedDeclarationsRefactoring extends CRefactoring { return null; } + private static void addNameIfNotEmpty(IASTName name, List names) { + if (name.getSimpleID().length != 0) + names.add(name); + } + /** * Returns the topmost non-template declaration declaring the given name, or {@code null} * if the name appears in a non-declaration context.