mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 12:25:35 +02:00
Improved Remove Unused Declarations refactoring.
Change-Id: Ibc011f9bacb8565463762f013738118eed839757
This commit is contained in:
parent
4470a7a5bb
commit
fe0dcb5176
1 changed files with 15 additions and 4 deletions
|
@ -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<IASTName> 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.
|
||||
|
|
Loading…
Add table
Reference in a new issue