Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2016-08-22 03:00:08 +0000
committerSergey Prigogin2016-08-22 03:00:08 +0000
commit26fc55708540835e38bf7d118df19047400a3aa7 (patch)
treea8569dcc23bca4565f5e5cfcc06eaf83bdcae534
parent0f887cb8838c7ee5bb2e371d87063bd05464ed1e (diff)
downloadorg.eclipse.cdt-26fc55708540835e38bf7d118df19047400a3aa7.tar.gz
org.eclipse.cdt-26fc55708540835e38bf7d118df19047400a3aa7.tar.xz
org.eclipse.cdt-26fc55708540835e38bf7d118df19047400a3aa7.zip
Improved Remove Unused Declarations refactoring.
-rw-r--r--core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/reducer/RemoveUnusedDeclarationsRefactoring.java30
1 files changed, 21 insertions, 9 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 e3d768e03ec..49df8e669e5 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
@@ -76,6 +76,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPartialSpecialization;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterOptions;
import org.eclipse.cdt.core.index.IIndex;
@@ -275,11 +276,11 @@ public class RemoveUnusedDeclarationsRefactoring extends CRefactoring {
for (IASTName declName : declaredNames) {
char[] declNameChars = declName.getSimpleID();
- if (declNameChars.length != 0 && declNameChars[0] == '~')
- declNameChars = Arrays.copyOfRange(declNameChars, 1, declNameChars.length);
IASTNode startPoint = declName;
int startOffset = ASTNodes.endOffset(declaration);
- if (declaration.getPropertyInParent() == IASTCompositeTypeSpecifier.MEMBER_DECLARATION) {
+ if (declaration.getPropertyInParent() == IASTCompositeTypeSpecifier.MEMBER_DECLARATION
+ && !(declName.resolveBinding() instanceof ICPPConstructor)
+ && (declNameChars.length == 0 || declNameChars[0] != '~')) {
// Member declarations can be referenced by other members declared before them.
startPoint = declaration.getParent();
startOffset = ASTNodes.offset(startPoint);
@@ -287,6 +288,7 @@ public class RemoveUnusedDeclarationsRefactoring extends CRefactoring {
ASTNodeProperty property = declName.getPropertyInParent();
if (property == IASTCompositeTypeSpecifier.TYPE_NAME
|| property == ICPPASTEnumerationSpecifier.ENUMERATION_NAME && ((ICPPASTEnumerationSpecifier) declName.getParent()).isScoped()) {
+ // Start from the first forward declaration of class or scoped enumeration.
while (declName instanceof ICPPASTTemplateId) {
declName = ((ICPPASTTemplateId) declName).getTemplateName();
}
@@ -307,17 +309,24 @@ public class RemoveUnusedDeclarationsRefactoring extends CRefactoring {
}
}
+ if (declNameChars.length != 0 && declNameChars[0] == '~')
+ declNameChars = Arrays.copyOfRange(declNameChars, 1, declNameChars.length);
+
+ int declOffset = ASTNodes.offset(declaration);
+ int declEndOffset = ASTNodes.endOffset(declaration);
+
for (IASTName name : names) {
if (name != declName) {
char[] nameChars = name.getSimpleID();
int offset = nameChars.length != 0 && nameChars[0] == '~' ? 1 : 0;
if (CharArrayUtils.equals(nameChars, offset, nameChars.length - offset, declNameChars)) {
- IASTDeclaration decl = findTopmostNonTemplateDeclaration(name);
- if (decl == null) {
- if (ASTNodes.offset(name) >= startOffset)
+ int nameOffset = ASTNodes.offset(name);
+ if (nameOffset >= declEndOffset || nameOffset >= startOffset && nameOffset < declOffset) {
+ IASTDeclaration decl = findTopmostNonTemplateDeclaration(name);
+ if (decl == null)
return true;
- } else {
+
if (!isDeclaredBy(name, decl))
return true;
}
@@ -389,13 +398,16 @@ public class RemoveUnusedDeclarationsRefactoring extends CRefactoring {
node = node.getParent();
property = node.getPropertyInParent();
}
- if (property == IASTDeclarator.DECLARATOR_NAME || property == IASTCompositeTypeSpecifier.TYPE_NAME) {
+ if (property == IASTDeclarator.DECLARATOR_NAME
+ || property == IASTCompositeTypeSpecifier.TYPE_NAME
+ || property == IASTElaboratedTypeSpecifier.TYPE_NAME) {
node = node.getParent().getParent();
}
for (IASTNode parent; (parent = node.getParent()) != null; node = parent) {
if (!(parent instanceof IASTDeclaration)
|| parent instanceof ICPPASTTemplateDeclaration
- || parent instanceof ICPPASTTemplateSpecialization) {
+ || parent instanceof ICPPASTTemplateSpecialization
+ || parent instanceof ICPPASTNamespaceDefinition) {
if (node instanceof IASTDeclaration) {
return (IASTDeclaration) node;
}

Back to the top