mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Removed use of a deprecated class.
This commit is contained in:
parent
fa9a41f13a
commit
34dd5e451f
2 changed files with 27 additions and 42 deletions
|
@ -41,7 +41,6 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
|
@ -56,12 +55,11 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The baseclass for all other refactorings, provides some common implementations for
|
* The base class for all other refactorings, provides some common implementations for
|
||||||
* condition checking, change generating, selection handling and translation unit loading.
|
* condition checking, change generating, selection handling and translation unit loading.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class CRefactoring extends Refactoring {
|
public abstract class CRefactoring extends Refactoring {
|
||||||
|
|
||||||
private static final int AST_STYLE = ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT | ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
|
private static final int AST_STYLE = ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT | ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
|
||||||
|
|
||||||
protected String name = Messages.Refactoring_name;
|
protected String name = Messages.Refactoring_name;
|
||||||
|
@ -88,8 +86,7 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
} catch (CModelException e) {
|
} catch (CModelException e) {
|
||||||
CUIPlugin.log(e);
|
CUIPlugin.log(e);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.region = SelectionHelper.getRegion(selection);
|
this.region = SelectionHelper.getRegion(selection);
|
||||||
}
|
}
|
||||||
|
@ -100,12 +97,11 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ProblemFinder extends ASTVisitor{
|
private class ProblemFinder extends ASTVisitor {
|
||||||
|
|
||||||
private boolean problemFound = false;
|
private boolean problemFound = false;
|
||||||
private final RefactoringStatus status;
|
private final RefactoringStatus status;
|
||||||
|
|
||||||
public ProblemFinder(RefactoringStatus status){
|
public ProblemFinder(RefactoringStatus status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,12 +156,11 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addWarningToState() {
|
private void addWarningToState() {
|
||||||
if(!problemFound){
|
if (!problemFound) {
|
||||||
status.addWarning(Messages.Refactoring_CompileErrorInTU);
|
status.addWarning(Messages.Refactoring_CompileErrorInTU);
|
||||||
problemFound = true;
|
problemFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -180,19 +175,19 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
throws CoreException, OperationCanceledException {
|
throws CoreException, OperationCanceledException {
|
||||||
SubMonitor sm = SubMonitor.convert(pm, 10);
|
SubMonitor sm = SubMonitor.convert(pm, 10);
|
||||||
sm.subTask(Messages.Refactoring_PM_LoadTU);
|
sm.subTask(Messages.Refactoring_PM_LoadTU);
|
||||||
if(isProgressMonitorCanceld(sm, initStatus)) {
|
if (isProgressMonitorCanceld(sm, initStatus)) {
|
||||||
return initStatus;
|
return initStatus;
|
||||||
}
|
}
|
||||||
if(!loadTranslationUnit(initStatus, sm.newChild(8))){
|
if (!loadTranslationUnit(initStatus, sm.newChild(8))) {
|
||||||
initStatus.addError(Messages.Refactoring_CantLoadTU);
|
initStatus.addError(Messages.Refactoring_CantLoadTU);
|
||||||
return initStatus;
|
return initStatus;
|
||||||
}
|
}
|
||||||
if(isProgressMonitorCanceld(sm, initStatus)) {
|
if (isProgressMonitorCanceld(sm, initStatus)) {
|
||||||
return initStatus;
|
return initStatus;
|
||||||
}
|
}
|
||||||
sm.subTask(Messages.Refactoring_PM_CheckTU);
|
sm.subTask(Messages.Refactoring_PM_CheckTU);
|
||||||
translationUnitHasProblem();
|
translationUnitHasProblem();
|
||||||
if(translationUnitIsAmbiguous()) {
|
if (translationUnitIsAmbiguous()) {
|
||||||
initStatus.addError(Messages.Refactoring_Ambiguity);
|
initStatus.addError(Messages.Refactoring_Ambiguity);
|
||||||
}
|
}
|
||||||
sm.worked(2);
|
sm.worked(2);
|
||||||
|
@ -203,7 +198,7 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
|
|
||||||
protected boolean isProgressMonitorCanceld(IProgressMonitor sm,
|
protected boolean isProgressMonitorCanceld(IProgressMonitor sm,
|
||||||
RefactoringStatus initStatus2) {
|
RefactoringStatus initStatus2) {
|
||||||
if(sm.isCanceled()) {
|
if (sm.isCanceled()) {
|
||||||
initStatus2.addFatalError(Messages.Refactoring_CanceledByUser);
|
initStatus2.addFatalError(Messages.Refactoring_CanceledByUser);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -236,12 +231,12 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
try {
|
try {
|
||||||
subMonitor.subTask(Messages.Refactoring_PM_ParseTU);
|
subMonitor.subTask(Messages.Refactoring_PM_ParseTU);
|
||||||
unit = loadTranslationUnit(file);
|
unit = loadTranslationUnit(file);
|
||||||
if(unit == null) {
|
if (unit == null) {
|
||||||
subMonitor.done();
|
subMonitor.done();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
subMonitor.worked(2);
|
subMonitor.worked(2);
|
||||||
if(isProgressMonitorCanceld(subMonitor, initStatus)) {
|
if (isProgressMonitorCanceld(subMonitor, initStatus)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
subMonitor.subTask(Messages.Refactoring_PM_MergeComments);
|
subMonitor.subTask(Messages.Refactoring_PM_MergeComments);
|
||||||
|
@ -264,7 +259,7 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
|
|
||||||
protected IASTTranslationUnit loadTranslationUnit(IFile file) throws CoreException {
|
protected IASTTranslationUnit loadTranslationUnit(IFile file) throws CoreException {
|
||||||
ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(file);
|
ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(file);
|
||||||
if(tu == null){
|
if (tu == null) {
|
||||||
initStatus.addFatalError(NLS.bind(Messages.CRefactoring_FileNotFound, file.getName()));
|
initStatus.addFatalError(NLS.bind(Messages.CRefactoring_FileNotFound, file.getName()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -301,8 +296,6 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
return fIndex;
|
return fIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public IASTTranslationUnit getUnit() {
|
public IASTTranslationUnit getUnit() {
|
||||||
return unit;
|
return unit;
|
||||||
}
|
}
|
||||||
|
@ -310,8 +303,7 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
protected ArrayList<IASTName> findAllMarkedNames() {
|
protected ArrayList<IASTName> findAllMarkedNames() {
|
||||||
final ArrayList<IASTName> namesVector = new ArrayList<IASTName>();
|
final ArrayList<IASTName> namesVector = new ArrayList<IASTName>();
|
||||||
|
|
||||||
unit.accept(new CPPASTVisitor() {
|
unit.accept(new ASTVisitor() {
|
||||||
|
|
||||||
{
|
{
|
||||||
shouldVisitNames = true;
|
shouldVisitNames = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.eclipse.core.runtime.ILog;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
|
@ -35,7 +36,6 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||||
|
@ -47,15 +47,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter;
|
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter;
|
||||||
|
|
||||||
public class NodeContainer {
|
public class NodeContainer {
|
||||||
|
public final NameInformation NULL_NAME_INFORMATION = new NameInformation(new CPPASTName());
|
||||||
public final NameInformation NULL_NAME_INFORMATION = new NameInformation(
|
|
||||||
new CPPASTName());
|
|
||||||
|
|
||||||
private final ArrayList<IASTNode> vec;
|
private final ArrayList<IASTNode> vec;
|
||||||
private final ArrayList<NameInformation> names;
|
private final ArrayList<NameInformation> names;
|
||||||
|
|
||||||
public class NameInformation {
|
public class NameInformation {
|
||||||
|
|
||||||
private IASTName name;
|
private IASTName name;
|
||||||
private IASTName declaration;
|
private IASTName declaration;
|
||||||
private final ArrayList<IASTName> references;
|
private final ArrayList<IASTName> references;
|
||||||
|
@ -202,7 +199,7 @@ public class NodeContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDeclarationInScope() {
|
public boolean isDeclarationInScope() {
|
||||||
if(declaration != null && declaration.toCharArray().length > 0) {
|
if (declaration != null && declaration.toCharArray().length > 0) {
|
||||||
int declOffset = declaration.getFileLocation().getNodeOffset();
|
int declOffset = declaration.getFileLocation().getNodeOffset();
|
||||||
return declOffset >= getStartOffset()
|
return declOffset >= getStartOffset()
|
||||||
&& declOffset <= getEndOffset();
|
&& declOffset <= getEndOffset();
|
||||||
|
@ -212,8 +209,7 @@ public class NodeContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return Messages.NodeContainer_Name + name + ' '
|
return Messages.NodeContainer_Name + name + ' ' + isDeclarationInScope();
|
||||||
+ isDeclarationInScope();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReference() {
|
public boolean isReference() {
|
||||||
|
@ -290,7 +286,7 @@ public class NodeContainer {
|
||||||
|
|
||||||
public void findAllNames() {
|
public void findAllNames() {
|
||||||
for (IASTNode node : vec) {
|
for (IASTNode node : vec) {
|
||||||
node.accept(new CPPASTVisitor() {
|
node.accept(new ASTVisitor() {
|
||||||
{
|
{
|
||||||
shouldVisitNames = true;
|
shouldVisitNames = true;
|
||||||
}
|
}
|
||||||
|
@ -304,11 +300,9 @@ public class NodeContainer {
|
||||||
ICPPBinding cppBind = (ICPPBinding) bind;
|
ICPPBinding cppBind = (ICPPBinding) bind;
|
||||||
try {
|
try {
|
||||||
if (!cppBind.isGloballyQualified()) {
|
if (!cppBind.isGloballyQualified()) {
|
||||||
NameInformation nameInformation = new NameInformation(
|
NameInformation nameInformation = new NameInformation(name);
|
||||||
name);
|
|
||||||
|
|
||||||
IASTName[] refs = name.getTranslationUnit()
|
IASTName[] refs = name.getTranslationUnit().getReferences(bind);
|
||||||
.getReferences(bind);
|
|
||||||
for (IASTName ref : refs) {
|
for (IASTName ref : refs) {
|
||||||
nameInformation.addReference(ref);
|
nameInformation.addReference(ref);
|
||||||
}
|
}
|
||||||
|
@ -321,12 +315,11 @@ public class NodeContainer {
|
||||||
.getMessage(), e);
|
.getMessage(), e);
|
||||||
logger.log(status);
|
logger.log(status);
|
||||||
}
|
}
|
||||||
}else if(bind instanceof IVariable) {
|
} else if (bind instanceof IVariable) {
|
||||||
NameInformation nameInformation = new NameInformation(
|
NameInformation nameInformation = new NameInformation(
|
||||||
name);
|
name);
|
||||||
|
|
||||||
IASTName[] refs = name.getTranslationUnit()
|
IASTName[] refs = name.getTranslationUnit().getReferences(bind);
|
||||||
.getReferences(bind);
|
|
||||||
for (IASTName ref : refs) {
|
for (IASTName ref : refs) {
|
||||||
nameInformation.addReference(ref);
|
nameInformation.addReference(ref);
|
||||||
}
|
}
|
||||||
|
@ -469,10 +462,10 @@ public class NodeContainer {
|
||||||
if (location instanceof IASTMacroExpansionLocation) {
|
if (location instanceof IASTMacroExpansionLocation) {
|
||||||
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
|
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
|
||||||
nodeOffset = macroLoc.asFileLocation().getNodeOffset();
|
nodeOffset = macroLoc.asFileLocation().getNodeOffset();
|
||||||
}else {
|
} else {
|
||||||
nodeOffset = node.getFileLocation().getNodeOffset();
|
nodeOffset = node.getFileLocation().getNodeOffset();
|
||||||
}
|
}
|
||||||
if(nodeOffset < nodeStart) {
|
if (nodeOffset < nodeStart) {
|
||||||
nodeStart = nodeOffset;
|
nodeStart = nodeOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -509,11 +502,11 @@ public class NodeContainer {
|
||||||
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
|
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
|
||||||
nodeOffset = macroLoc.asFileLocation().getNodeOffset();
|
nodeOffset = macroLoc.asFileLocation().getNodeOffset();
|
||||||
nodeLength = macroLoc.asFileLocation().getNodeLength();
|
nodeLength = macroLoc.asFileLocation().getNodeLength();
|
||||||
}else {
|
} else {
|
||||||
nodeOffset = location.getNodeOffset();
|
nodeOffset = location.getNodeOffset();
|
||||||
nodeLength = location.getNodeLength();
|
nodeLength = location.getNodeLength();
|
||||||
}
|
}
|
||||||
if(fileOffset < nodeOffset) {
|
if (fileOffset < nodeOffset) {
|
||||||
fileOffset = nodeOffset;
|
fileOffset = nodeOffset;
|
||||||
length = nodeLength;
|
length = nodeLength;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue