mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 01:45:33 +02:00
Improved code reduction refactorings.
Change-Id: I2bee9e578810dd9ee1b23341a29713fc594d81f4
This commit is contained in:
parent
c19640498d
commit
149e41fd46
3 changed files with 14 additions and 3 deletions
|
@ -4,6 +4,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
||||
class ProblemFinder extends ASTVisitor {
|
||||
boolean foundProblem;
|
||||
|
@ -21,7 +22,8 @@ class ProblemFinder extends ASTVisitor {
|
|||
|
||||
@Override
|
||||
public int visit(IASTName name) {
|
||||
if (name.resolveBinding() instanceof IProblemBinding) {
|
||||
if (!CharArrayUtils.startsWith(name.getSimpleID(), "__builtin_")
|
||||
&& name.resolveBinding() instanceof IProblemBinding) {
|
||||
foundProblem = true;
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor;
|
||||
|
@ -56,6 +58,7 @@ import org.eclipse.cdt.internal.core.dom.rewrite.util.ASTNodes;
|
|||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.changes.CCompositeChange;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
|
||||
|
||||
public class RemoveFunctionBodiesRefactoring extends CRefactoring {
|
||||
private INodeFactory nodeFactory;
|
||||
|
@ -63,6 +66,7 @@ public class RemoveFunctionBodiesRefactoring extends CRefactoring {
|
|||
|
||||
private IIndex index;
|
||||
private IASTTranslationUnit ast;
|
||||
private IRegion region;
|
||||
|
||||
public RemoveFunctionBodiesRefactoring(ICElement element, ISelection selection, ICProject project) {
|
||||
super(element, selection, project);
|
||||
|
@ -83,6 +87,8 @@ public class RemoveFunctionBodiesRefactoring extends CRefactoring {
|
|||
ast = getAST(tu, progress.newChild(1));
|
||||
index = getIndex();
|
||||
nodeFactory = ast.getASTNodeFactory();
|
||||
region = selectedRegion.getLength() == 0 ?
|
||||
new Region(0, ast.getFileLocation().getNodeLength()) : selectedRegion;
|
||||
|
||||
if (isProgressMonitorCanceled(progress, initStatus))
|
||||
return initStatus;
|
||||
|
@ -118,6 +124,8 @@ public class RemoveFunctionBodiesRefactoring extends CRefactoring {
|
|||
CTextFileChange fileChange = new CTextFileChange(tu.getElementName(), tu);
|
||||
fileChange.setEdit(new MultiTextEdit());
|
||||
for (IASTFunctionDefinition definition : finder.functionDefinitions) {
|
||||
if (!SelectionHelper.isNodeInsideRegion(definition, region))
|
||||
continue;
|
||||
IASTStatement body = definition.getBody();
|
||||
IASTName name = definition.getDeclarator().getName();
|
||||
IBinding binding = name.resolveBinding();
|
||||
|
|
|
@ -69,6 +69,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
|
@ -354,8 +355,8 @@ public class RemoveUnusedDeclarationsRefactoring extends CRefactoring {
|
|||
for (IASTDeclarator declarator : declarators) {
|
||||
declarator = findInnermostDeclarator(declarator);
|
||||
IASTName name = declarator.getName();
|
||||
if (name instanceof ICPPASTConversionName)
|
||||
return null; // Do not remove conversion operators.
|
||||
if (name instanceof ICPPASTConversionName || name instanceof ICPPASTOperatorName)
|
||||
return null; // Do not remove operators.
|
||||
names.add(name);
|
||||
}
|
||||
IASTDeclSpecifier declSpecifier = ((IASTSimpleDeclaration) declaration).getDeclSpecifier();
|
||||
|
|
Loading…
Add table
Reference in a new issue