1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 02:15:31 +02:00

Move findAncestorWithType() from CPPVisitor to ASTQueries

Change-Id: Ibcbc0a2685dabd66e7025db5d2924acbbb5a882d
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
Nathan Ridge 2016-01-07 18:25:59 -05:00 committed by Sergey Prigogin
parent 7eeecab020
commit bc953d2348
29 changed files with 82 additions and 76 deletions

View file

@ -128,6 +128,23 @@ public class ASTQueries {
return result; return result;
} }
/**
* Traverses parent chain of the given node and returns the first node of the given type.
* @param node the start node
* @param type the type to look for
* @return the node itself or its closest ancestor that has the given type, or {@code null}
* if no such node is found.
*/
@SuppressWarnings("unchecked")
public static <T extends IASTNode> T findAncestorWithType(IASTNode node, Class<T> type) {
do {
if (type.isInstance(node)) {
return (T) node;
}
} while ((node = node.getParent()) != null);
return null;
}
/** /**
* Searches for the function enclosing the given node. May return <code>null</code>. * Searches for the function enclosing the given node. May return <code>null</code>.
*/ */

View file

@ -269,7 +269,7 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
@Override @Override
public IBinding getOwner() { public IBinding getOwner() {
IASTFunctionDeclarator decl = IASTFunctionDeclarator decl =
CPPVisitor.findAncestorWithType(fDeclarations[0], IASTFunctionDeclarator.class); ASTQueries.findAncestorWithType(fDeclarations[0], IASTFunctionDeclarator.class);
if (decl == null) if (decl == null)
return null; return null;
IASTName name= decl.getName(); IASTName name= decl.getName();

View file

@ -882,7 +882,7 @@ public class CPPTemplates {
IType type = instantiateType(var.getType(), tpMap, -1, within, point); IType type = instantiateType(var.getType(), tpMap, -1, within, point);
IValue value; IValue value;
ICPPASTDeclarator decl = CPPVisitor.findAncestorWithType(point, ICPPASTDeclarator.class); ICPPASTDeclarator decl = ASTQueries.findAncestorWithType(point, ICPPASTDeclarator.class);
if (((IASTName) point).getRoleOfName(false) == IASTNameOwner.r_definition && decl != null && decl.getInitializer() != null) { if (((IASTName) point).getRoleOfName(false) == IASTNameOwner.r_definition && decl != null && decl.getInitializer() != null) {
// Explicit specialization. // Explicit specialization.
value = SemanticUtil.getValueOfInitializer(decl.getInitializer(), type); value = SemanticUtil.getValueOfInitializer(decl.getInitializer(), type);

View file

@ -1329,7 +1329,7 @@ public class CPPVisitor extends ASTQueries {
return new CPPScope.CPPScopeProblem(name, ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION); return new CPPScope.CPPScopeProblem(name, ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
} }
} else if (parent instanceof ICPPASTFieldDesignator) { } else if (parent instanceof ICPPASTFieldDesignator) {
ICPPASTDeclarator declarator = findAncestorWithType(parent, ICPPASTDeclarator.class); ICPPASTDeclarator declarator = ASTQueries.findAncestorWithType(parent, ICPPASTDeclarator.class);
if (declarator != null) { if (declarator != null) {
IType type = createType(declarator); IType type = createType(declarator);
type= getNestedType(type, TDEF | CVTYPE); type= getNestedType(type, TDEF | CVTYPE);
@ -2707,23 +2707,6 @@ public class CPPVisitor extends ASTQueries {
return (ICPPASTDeclarator) ASTQueries.findInnermostDeclarator(dtor); return (ICPPASTDeclarator) ASTQueries.findInnermostDeclarator(dtor);
} }
/**
* Traverses parent chain of the given node and returns the first node of the given type.
* @param node the start node
* @param type the type to look for
* @return the node itself or its closest ancestor that has the given type, or {@code null}
* if no such node is found.
*/
@SuppressWarnings("unchecked")
public static <T extends IASTNode> T findAncestorWithType(IASTNode node, Class<T> type) {
do {
if (type.isInstance(node)) {
return (T) node;
}
} while ((node = node.getParent()) != null);
return null;
}
/** /**
* Traverses a chain of nested homogeneous left-to-right-associative binary expressions and * Traverses a chain of nested homogeneous left-to-right-associative binary expressions and
* returns a list of their operands in left-to-right order. For example, for the expression * returns a list of their operands in left-to-right order. For example, for the expression

View file

@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTypeSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTypeSpecialization;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
@ -300,7 +301,7 @@ public class EvalBinding extends CPPDependentEvaluation {
IASTTranslationUnit ast = point.getTranslationUnit(); IASTTranslationUnit ast = point.getTranslationUnit();
IASTName[] definitions = ast.getDefinitionsInAST(binding); IASTName[] definitions = ast.getDefinitionsInAST(binding);
for (IASTName definition : definitions) { for (IASTName definition : definitions) {
IASTDeclarator declarator = CPPVisitor.findAncestorWithType(definition, IASTDeclarator.class); IASTDeclarator declarator = ASTQueries.findAncestorWithType(definition, IASTDeclarator.class);
if (declarator != null) { if (declarator != null) {
IType localType = CPPVisitor.createType(declarator); IType localType = CPPVisitor.createType(declarator);
if (localType instanceof IArrayType && ((IArrayType) localType).getSize() != null) { if (localType instanceof IArrayType && ((IArrayType) localType).getSize() != null) {

View file

@ -50,6 +50,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTypeSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTypeSpecialization;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.Value;
@ -293,7 +294,7 @@ public class EvalID extends CPPDependentEvaluation {
* Returns {@code true} if the given node is located inside the given enum. * Returns {@code true} if the given node is located inside the given enum.
*/ */
private static boolean isInsideEnum(IASTNode node, ICPPEnumeration enumBinding) { private static boolean isInsideEnum(IASTNode node, ICPPEnumeration enumBinding) {
IASTEnumerator enumeratorNode = CPPVisitor.findAncestorWithType(node, IASTEnumerator.class); IASTEnumerator enumeratorNode = ASTQueries.findAncestorWithType(node, IASTEnumerator.class);
if (enumeratorNode == null) if (enumeratorNode == null)
return false; return false;
IBinding enumerator = enumeratorNode.getName().getBinding(); IBinding enumerator = enumeratorNode.getName().getBinding();

View file

@ -40,7 +40,7 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IncludeFileContentProvider; import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.util.TextUtil; import org.eclipse.cdt.internal.core.util.TextUtil;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -237,11 +237,11 @@ public class CCodeFormatter extends CodeFormatter {
node = nodeSelector.findFirstContainedNode(pos, end - pos); node = nodeSelector.findFirstContainedNode(pos, end - pos);
if (node != null) { if (node != null) {
IASTNode containedNode = node; IASTNode containedNode = node;
node = CPPVisitor.findAncestorWithType(containedNode, IASTStatement.class); node = ASTQueries.findAncestorWithType(containedNode, IASTStatement.class);
if (node == null) if (node == null)
node = CPPVisitor.findAncestorWithType(containedNode, IASTDeclaration.class); node = ASTQueries.findAncestorWithType(containedNode, IASTDeclaration.class);
if (node == null) if (node == null)
node = CPPVisitor.findAncestorWithType(containedNode, IASTPreprocessorMacroExpansion.class); node = ASTQueries.findAncestorWithType(containedNode, IASTPreprocessorMacroExpansion.class);
} }
if (node == null) if (node == null)
break; break;

View file

@ -62,7 +62,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.index.IIndexFragmentName; import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable; import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
import org.eclipse.cdt.internal.core.model.ext.CElementHandleFactory; import org.eclipse.cdt.internal.core.model.ext.CElementHandleFactory;
@ -289,7 +289,7 @@ public class SelectionToDeclarationJob extends Job implements ASTRunnable {
IASTName name = astNames[i]; IASTName name = astNames[i];
if (name.isDefinition()) { if (name.isDefinition()) {
astNames[i] = null; astNames[i] = null;
} else if (CPPVisitor.findAncestorWithType(name, ICPPASTUsingDeclaration.class) != null) { } else if (ASTQueries.findAncestorWithType(name, ICPPASTUsingDeclaration.class) != null) {
if (usingDeclarations == null) if (usingDeclarations == null)
usingDeclarations = new ArrayList<IASTName>(1); usingDeclarations = new ArrayList<IASTName>(1);
usingDeclarations.add(name); usingDeclarations.add(name);

View file

@ -46,8 +46,8 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.rewrite.util.ASTNodes; import org.eclipse.cdt.internal.core.dom.rewrite.util.ASTNodes;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.corext.refactoring.code.flow.FlowContext; import org.eclipse.cdt.internal.corext.refactoring.code.flow.FlowContext;
@ -206,7 +206,7 @@ public class NodeContainer {
IASTNode firstNode = nodes.get(0); IASTNode firstNode = nodes.get(0);
IASTFunctionDefinition enclosingFunction = IASTFunctionDefinition enclosingFunction =
CPPVisitor.findAncestorWithType(firstNode, IASTFunctionDefinition.class); ASTQueries.findAncestorWithType(firstNode, IASTFunctionDefinition.class);
FlowContext flowContext= new FlowContext(enclosingFunction); FlowContext flowContext= new FlowContext(enclosingFunction);
flowContext.setConsiderAccessMode(true); flowContext.setConsiderAccessMode(true);
flowContext.setComputeMode(FlowContext.ARGUMENTS); flowContext.setComputeMode(FlowContext.ARGUMENTS);

View file

@ -58,13 +58,13 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTEqualsInitializer; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTEqualsInitializer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescriptor; import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescriptor;
@ -171,7 +171,7 @@ public class ExtractConstantRefactoring extends CRefactoring {
private ArrayList<String> findAllDeclaredNames() { private ArrayList<String> findAllDeclaredNames() {
ArrayList<String>names = new ArrayList<String>(); ArrayList<String>names = new ArrayList<String>();
IASTFunctionDefinition funcDef = CPPVisitor.findAncestorWithType(target, IASTFunctionDefinition.class); IASTFunctionDefinition funcDef = ASTQueries.findAncestorWithType(target, IASTFunctionDefinition.class);
ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef); ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef);
if (comTypeSpec != null) { if (comTypeSpec != null) {
for(IASTDeclaration dec : comTypeSpec.getMembers()) { for(IASTDeclaration dec : comTypeSpec.getMembers()) {

View file

@ -88,6 +88,7 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTBinaryExpression; import org.eclipse.cdt.internal.core.dom.parser.c.CASTBinaryExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
@ -103,7 +104,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor;
@ -387,7 +387,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
private void createMethodDefinition(final IASTName methodName, MethodContext context, private void createMethodDefinition(final IASTName methodName, MethodContext context,
IASTNode firstExtractedNode, ModificationCollector collector) { IASTNode firstExtractedNode, ModificationCollector collector) {
IASTFunctionDefinition functionToExtractFrom = IASTFunctionDefinition functionToExtractFrom =
CPPVisitor.findAncestorWithType(firstExtractedNode, IASTFunctionDefinition.class); ASTQueries.findAncestorWithType(firstExtractedNode, IASTFunctionDefinition.class);
if (functionToExtractFrom != null) { if (functionToExtractFrom != null) {
String title; String title;
if (context.getType() == MethodContext.ContextType.METHOD) { if (context.getType() == MethodContext.ContextType.METHOD) {
@ -778,7 +778,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
IASTFunctionCallExpression callExpression, IASTName retname) { IASTFunctionCallExpression callExpression, IASTName retname) {
if (info.getReturnVariable().equals(info.getMandatoryReturnVariable())) { if (info.getReturnVariable().equals(info.getMandatoryReturnVariable())) {
IASTSimpleDeclaration orgDecl = IASTSimpleDeclaration orgDecl =
CPPVisitor.findAncestorWithType(info.getReturnVariable().getDeclarationName(), ASTQueries.findAncestorWithType(info.getReturnVariable().getDeclarationName(),
IASTSimpleDeclaration.class); IASTSimpleDeclaration.class);
IASTSimpleDeclaration decl = new CPPASTSimpleDeclaration(); IASTSimpleDeclaration decl = new CPPASTSimpleDeclaration();

View file

@ -60,12 +60,12 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarationStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarationStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTEqualsInitializer; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTEqualsInitializer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescriptor; import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescriptor;
@ -142,7 +142,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
private ArrayList<String> findAllDeclaredNames() { private ArrayList<String> findAllDeclaredNames() {
ArrayList<String> names = new ArrayList<String>(); ArrayList<String> names = new ArrayList<String>();
IASTFunctionDefinition funcDef = CPPVisitor.findAncestorWithType(target, IASTFunctionDefinition.class); IASTFunctionDefinition funcDef = ASTQueries.findAncestorWithType(target, IASTFunctionDefinition.class);
ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef); ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef);
if (comTypeSpec != null) { if (comTypeSpec != null) {
for (IASTDeclaration decl : comTypeSpec.getMembers()) { for (IASTDeclaration decl : comTypeSpec.getMembers()) {
@ -332,7 +332,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
public String[] guessTempNames() { public String[] guessTempNames() {
final List<String> guessedTempNames = new ArrayList<String>(); final List<String> guessedTempNames = new ArrayList<String>();
final List<String> usedNames = new ArrayList<String>(); final List<String> usedNames = new ArrayList<String>();
IASTFunctionDefinition funcDef = CPPVisitor.findAncestorWithType(target, IASTFunctionDefinition.class); IASTFunctionDefinition funcDef = ASTQueries.findAncestorWithType(target, IASTFunctionDefinition.class);
final IScope scope; final IScope scope;
if (funcDef != null && funcDef.getBody() instanceof IASTCompoundStatement) { if (funcDef != null && funcDef.getBody() instanceof IASTCompoundStatement) {
IASTCompoundStatement body = (IASTCompoundStatement) funcDef.getBody(); IASTCompoundStatement body = (IASTCompoundStatement) funcDef.getBody();

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArrayDeclarator;
import org.eclipse.cdt.core.dom.rewrite.TypeHelper; import org.eclipse.cdt.core.dom.rewrite.TypeHelper;
import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTDeclarator; import org.eclipse.cdt.internal.core.dom.parser.c.CASTDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTPointer; import org.eclipse.cdt.internal.core.dom.parser.c.CASTPointer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
@ -74,7 +75,7 @@ public abstract class AccessorFactory {
this.fieldDeclarator = fieldDeclarator; this.fieldDeclarator = fieldDeclarator;
this.accessorName = accessorName; this.accessorName = accessorName;
IASTSimpleDeclaration declaration = IASTSimpleDeclaration declaration =
CPPVisitor.findAncestorWithType(fieldDeclarator, IASTSimpleDeclaration.class); ASTQueries.findAncestorWithType(fieldDeclarator, IASTSimpleDeclaration.class);
this.declSpecifier = declaration.getDeclSpecifier(); this.declSpecifier = declaration.getDeclSpecifier();
IType type = CPPVisitor.createType(declSpecifier); IType type = CPPVisitor.createType(declSpecifier);
passByReference = TypeHelper.shouldBePassedByReference(type, fieldDeclarator.getTranslationUnit()); passByReference = TypeHelper.shouldBePassedByReference(type, fieldDeclarator.getTranslationUnit());

View file

@ -43,8 +43,8 @@ import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ContainerNode; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ContainerNode;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
@ -227,7 +227,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
List<IASTNode> getterAndSetters = new ArrayList<IASTNode>(); List<IASTNode> getterAndSetters = new ArrayList<IASTNode>();
List<IASTFunctionDefinition> definitions = new ArrayList<IASTFunctionDefinition>(); List<IASTFunctionDefinition> definitions = new ArrayList<IASTFunctionDefinition>();
ICPPASTCompositeTypeSpecifier classDefinition = ICPPASTCompositeTypeSpecifier classDefinition =
CPPVisitor.findAncestorWithType(context.existingFields.get(0), ICPPASTCompositeTypeSpecifier.class); ASTQueries.findAncestorWithType(context.existingFields.get(0), ICPPASTCompositeTypeSpecifier.class);
for (AccessorDescriptor accessor : context.selectedAccessors) { for (AccessorDescriptor accessor : context.selectedAccessors) {
IASTName accessorName = new CPPASTName(accessor.toString().toCharArray()); IASTName accessorName = new CPPASTName(accessor.toString().toCharArray());
if (context.isDefinitionSeparate()) { if (context.isDefinitionSeparate()) {
@ -277,7 +277,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
} }
IASTSimpleDeclaration decl = IASTSimpleDeclaration decl =
CPPVisitor.findAncestorWithType(context.existingFields.get(0), IASTSimpleDeclaration.class); ASTQueries.findAncestorWithType(context.existingFields.get(0), IASTSimpleDeclaration.class);
MethodDefinitionInsertLocationFinder locationFinder = new MethodDefinitionInsertLocationFinder(); MethodDefinitionInsertLocationFinder locationFinder = new MethodDefinitionInsertLocationFinder();
InsertLocation location = locationFinder.find(tu, decl.getFileLocation(), decl.getParent(), InsertLocation location = locationFinder.find(tu, decl.getFileLocation(), decl.getParent(),
refactoringContext, pm); refactoringContext, pm);

View file

@ -143,7 +143,7 @@ public class HideMethodRefactoring extends CRefactoring {
} }
IASTCompositeTypeSpecifier classNode = IASTCompositeTypeSpecifier classNode =
CPPVisitor.findAncestorWithType(methodName, IASTCompositeTypeSpecifier.class); ASTQueries.findAncestorWithType(methodName, IASTCompositeTypeSpecifier.class);
if (classNode == null) { if (classNode == null) {
initStatus.addError(Messages.HideMethodRefactoring_EnclosingClassNotFound); initStatus.addError(Messages.HideMethodRefactoring_EnclosingClassNotFound);
} }

View file

@ -57,7 +57,7 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
@ -278,7 +278,7 @@ public class ImplementMethodRefactoring extends CRefactoring {
IASTFunctionDefinition functionDefinition = nodeFactory.newFunctionDefinition(declSpecifier, createdMethodDeclarator, nodeFactory.newCompoundStatement()); IASTFunctionDefinition functionDefinition = nodeFactory.newFunctionDefinition(declSpecifier, createdMethodDeclarator, nodeFactory.newCompoundStatement());
functionDefinition.setParent(unit); functionDefinition.setParent(unit);
ICPPASTTemplateDeclaration templateDeclaration = CPPVisitor.findAncestorWithType(declarationParent, ICPPASTTemplateDeclaration.class); ICPPASTTemplateDeclaration templateDeclaration = ASTQueries.findAncestorWithType(declarationParent, ICPPASTTemplateDeclaration.class);
if (templateDeclaration != null) { if (templateDeclaration != null) {
ICPPASTTemplateDeclaration newTemplateDeclaration = nodeFactory.newTemplateDeclaration(functionDefinition); ICPPASTTemplateDeclaration newTemplateDeclaration = nodeFactory.newTemplateDeclaration(functionDefinition);
newTemplateDeclaration.setParent(unit); newTemplateDeclaration.setParent(unit);

View file

@ -120,6 +120,7 @@ import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClosureType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClosureType;
@ -127,7 +128,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper.MethodKind; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper.MethodKind;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.LookupData; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.LookupData;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
@ -1460,7 +1460,7 @@ public class BindingClassifier {
* Checks if the given name is part of a template argument. * Checks if the given name is part of a template argument.
*/ */
private boolean isTemplateArgumentRequiringCompleteType(IASTName name) { private boolean isTemplateArgumentRequiringCompleteType(IASTName name) {
ICPPASTTypeId typeId = CPPVisitor.findAncestorWithType(name, ICPPASTTypeId.class); ICPPASTTypeId typeId = ASTQueries.findAncestorWithType(name, ICPPASTTypeId.class);
if (typeId == null || typeId.getPropertyInParent() != ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) if (typeId == null || typeId.getPropertyInParent() != ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT)
return false; return false;
ICPPASTTemplateId templateId = (ICPPASTTemplateId) typeId.getParent(); ICPPASTTemplateId templateId = (ICPPASTTemplateId) typeId.getParent();

View file

@ -26,7 +26,7 @@ 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.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
/** /**
* Given a selection and a translation unit, this class finds a * Given a selection and a translation unit, this class finds a
@ -106,6 +106,6 @@ public class DeclaratorFinder {
} }
private boolean isPartOfAStatement(IASTNode node) { private boolean isPartOfAStatement(IASTNode node) {
return CPPVisitor.findAncestorWithType(node, IASTStatement.class) != null; return ASTQueries.findAncestorWithType(node, IASTStatement.class) != null;
} }
} }

View file

@ -25,8 +25,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.ui.refactoring.Container; import org.eclipse.cdt.internal.ui.refactoring.Container;
@ -93,7 +93,7 @@ public class InsertionPointFinder {
public int visit(IASTDeclaration declaration) { public int visit(IASTDeclaration declaration) {
if (declaration instanceof ICPPASTFunctionDefinition) { if (declaration instanceof ICPPASTFunctionDefinition) {
if (declaration.getParent() != null && if (declaration.getParent() != null &&
CPPVisitor.findAncestorWithType(declaration, CPPASTCompositeTypeSpecifier.class) != null) { ASTQueries.findAncestorWithType(declaration, CPPASTCompositeTypeSpecifier.class) != null) {
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
definitions.add((ICPPASTFunctionDefinition) declaration); definitions.add((ICPPASTFunctionDefinition) declaration);

View file

@ -28,7 +28,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
@ -44,7 +44,7 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
private boolean isInClass(IASTNode node) { private boolean isInClass(IASTNode node) {
return node != null && return node != null &&
CPPVisitor.findAncestorWithType(node, ICPPASTCompositeTypeSpecifier.class) != null; ASTQueries.findAncestorWithType(node, ICPPASTCompositeTypeSpecifier.class) != null;
} }
@Override @Override
@ -81,7 +81,7 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
private IASTNode getParentNamespace() { private IASTNode getParentNamespace() {
IASTNode parentNamespace = IASTNode parentNamespace =
CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTNamespaceDefinition.class); ASTQueries.findAncestorWithType(context.getDefinition(), ICPPASTNamespaceDefinition.class);
if (parentNamespace == null) if (parentNamespace == null)
parentNamespace = context.getDefinitionAST(); parentNamespace = context.getDefinitionAST();
return parentNamespace; return parentNamespace;

View file

@ -33,7 +33,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite.CommentPosition; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite.CommentPosition;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTLiteralNode; import org.eclipse.cdt.internal.core.dom.rewrite.ASTLiteralNode;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
@ -118,7 +118,7 @@ public class ToggleFromImplementationToHeaderOrClassStrategy implements IToggleR
} }
private IASTNode getParent() { private IASTNode getParent() {
IASTNode parent = CPPVisitor.findAncestorWithType(context.getDefinition(), IASTNode parent = ASTQueries.findAncestorWithType(context.getDefinition(),
ICPPASTCompositeTypeSpecifier.class); ICPPASTCompositeTypeSpecifier.class);
IASTNode parentnode = null; IASTNode parentnode = null;
if (parent != null) { if (parent != null) {

View file

@ -30,8 +30,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite.CommentPosition; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite.CommentPosition;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
@ -55,7 +55,7 @@ public class ToggleFromInHeaderToClassStrategy implements IToggleRefactoringStra
if (declarator.getName() instanceof ICPPASTQualifiedName) { if (declarator.getName() instanceof ICPPASTQualifiedName) {
declarator = backup; declarator = backup;
} }
return (CPPVisitor.findAncestorWithType(declarator, IASTCompositeTypeSpecifier.class) == null); return (ASTQueries.findAncestorWithType(declarator, IASTCompositeTypeSpecifier.class) == null);
} }
@Override @Override
@ -100,7 +100,7 @@ public class ToggleFromInHeaderToClassStrategy implements IToggleRefactoringStra
} }
} }
IASTNode parent = CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTCompositeTypeSpecifier.class); IASTNode parent = ASTQueries.findAncestorWithType(context.getDefinition(), ICPPASTCompositeTypeSpecifier.class);
if (parent != null) { if (parent != null) {
newDefinition.setParent(parent); newDefinition.setParent(parent);
} else { } else {
@ -111,7 +111,7 @@ public class ToggleFromInHeaderToClassStrategy implements IToggleRefactoringStra
private ASTRewrite replaceDeclarationWithDefinition(ASTRewrite rewriter, private ASTRewrite replaceDeclarationWithDefinition(ASTRewrite rewriter,
IASTFunctionDefinition newDefinition) { IASTFunctionDefinition newDefinition) {
IASTSimpleDeclaration fullDeclaration = CPPVisitor.findAncestorWithType(context.getDeclaration(), CPPASTSimpleDeclaration.class); IASTSimpleDeclaration fullDeclaration = ASTQueries.findAncestorWithType(context.getDeclaration(), CPPASTSimpleDeclaration.class);
ASTRewrite newRewriter = rewriter.replace(fullDeclaration, newDefinition, infoText); ASTRewrite newRewriter = rewriter.replace(fullDeclaration, newDefinition, infoText);
return newRewriter; return newRewriter;
} }

View file

@ -61,7 +61,7 @@ import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite.CommentPosition; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite.CommentPosition;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.cdt.internal.core.dom.rewrite.DeclarationGeneratorImpl; import org.eclipse.cdt.internal.core.dom.rewrite.DeclarationGeneratorImpl;
@ -510,11 +510,11 @@ public class ToggleNodeHelper extends NodeHelper {
*/ */
public static List<ICPPASTNamespaceDefinition> findSurroundingNamespaces(IASTNode node) { public static List<ICPPASTNamespaceDefinition> findSurroundingNamespaces(IASTNode node) {
ArrayList<ICPPASTNamespaceDefinition> namespaces = new ArrayList<>(); ArrayList<ICPPASTNamespaceDefinition> namespaces = new ArrayList<>();
ICPPASTNamespaceDefinition currentNamespace = CPPVisitor.findAncestorWithType(node, ICPPASTNamespaceDefinition currentNamespace = ASTQueries.findAncestorWithType(node,
ICPPASTNamespaceDefinition.class); ICPPASTNamespaceDefinition.class);
while (currentNamespace != null) { while (currentNamespace != null) {
namespaces.add(0, currentNamespace); namespaces.add(0, currentNamespace);
currentNamespace = CPPVisitor.findAncestorWithType(currentNamespace.getParent(), currentNamespace = ASTQueries.findAncestorWithType(currentNamespace.getParent(),
ICPPASTNamespaceDefinition.class); ICPPASTNamespaceDefinition.class);
} }
return namespaces; return namespaces;

View file

@ -32,7 +32,7 @@ import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.corext.util.CModelUtil; import org.eclipse.cdt.internal.corext.util.CModelUtil;
import org.eclipse.cdt.internal.ui.editor.SourceHeaderPartnerFinder; import org.eclipse.cdt.internal.ui.editor.SourceHeaderPartnerFinder;
@ -184,11 +184,11 @@ public class ToggleRefactoringContext {
if (node instanceof IASTSimpleDeclaration) { if (node instanceof IASTSimpleDeclaration) {
return (IASTFunctionDeclarator) ((IASTSimpleDeclaration) node).getDeclarators()[0]; return (IASTFunctionDeclarator) ((IASTSimpleDeclaration) node).getDeclarators()[0];
} }
return CPPVisitor.findAncestorWithType(node, IASTFunctionDeclarator.class); return ASTQueries.findAncestorWithType(node, IASTFunctionDeclarator.class);
} }
private IASTFunctionDefinition findFunctionDefinition(IASTNode node) { private IASTFunctionDefinition findFunctionDefinition(IASTNode node) {
return CPPVisitor.findAncestorWithType(node, IASTFunctionDefinition.class); return ASTQueries.findAncestorWithType(node, IASTFunctionDefinition.class);
} }
public void setDefaultAnswer(boolean defaultAnswer) { public void setDefaultAnswer(boolean defaultAnswer) {

View file

@ -14,7 +14,7 @@ package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
public class ToggleStrategyFactory { public class ToggleStrategyFactory {
private ToggleRefactoringContext context; private ToggleRefactoringContext context;
@ -44,10 +44,10 @@ public class ToggleStrategyFactory {
private boolean isInClassSituation() { private boolean isInClassSituation() {
return (context.getDeclaration() == null) && return (context.getDeclaration() == null) &&
(CPPVisitor.findAncestorWithType(context.getDefinition(), IASTCompositeTypeSpecifier.class) != null); (ASTQueries.findAncestorWithType(context.getDefinition(), IASTCompositeTypeSpecifier.class) != null);
} }
private boolean isTemplateSituation() { private boolean isTemplateSituation() {
return (CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTTemplateDeclaration.class) != null); return (ASTQueries.findAncestorWithType(context.getDefinition(), ICPPASTTemplateDeclaration.class) != null);
} }
} }

View file

@ -37,7 +37,7 @@ import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput; import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext; import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
@ -262,7 +262,7 @@ public class DefinitionFinder {
if (classDefintionName == null) if (classDefintionName == null)
return null; return null;
IASTCompositeTypeSpecifier compositeTypeSpecifier = IASTCompositeTypeSpecifier compositeTypeSpecifier =
CPPVisitor.findAncestorWithType(classDefintionName, IASTCompositeTypeSpecifier.class); ASTQueries.findAncestorWithType(classDefintionName, IASTCompositeTypeSpecifier.class);
IASTTranslationUnit ast = classDefintionName.getTranslationUnit(); IASTTranslationUnit ast = classDefintionName.getTranslationUnit();
IIndex index = context.getIndex(); IIndex index = context.getIndex();
if (index == null) { if (index == null) {
@ -271,7 +271,7 @@ public class DefinitionFinder {
IASTName[] memberDeclarationNames = ast.getDeclarationsInAST(index.adaptBinding(member)); IASTName[] memberDeclarationNames = ast.getDeclarationsInAST(index.adaptBinding(member));
for (IASTName name : memberDeclarationNames) { for (IASTName name : memberDeclarationNames) {
if (name.getPropertyInParent() == IASTDeclarator.DECLARATOR_NAME) { if (name.getPropertyInParent() == IASTDeclarator.DECLARATOR_NAME) {
IASTDeclaration declaration = CPPVisitor.findAncestorWithType(name, IASTDeclaration.class); IASTDeclaration declaration = ASTQueries.findAncestorWithType(name, IASTDeclaration.class);
if (declaration.getParent() == compositeTypeSpecifier) { if (declaration.getParent() == compositeTypeSpecifier) {
return name; return name;
} }

View file

@ -33,6 +33,7 @@ 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.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
@ -141,6 +142,6 @@ public class NodeHelper {
} }
public static boolean isContainedInTemplateDeclaration(IASTNode node) { public static boolean isContainedInTemplateDeclaration(IASTNode node) {
return CPPVisitor.findAncestorWithType(node, ICPPASTTemplateDeclaration.class) != null; return ASTQueries.findAncestorWithType(node, ICPPASTTemplateDeclaration.class) != null;
} }
} }

View file

@ -90,6 +90,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
@ -363,7 +364,7 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
IASTName name = astNames[i]; IASTName name = astNames[i];
if (name.isDefinition()) { if (name.isDefinition()) {
astNames[i]= null; astNames[i]= null;
} else if (CPPVisitor.findAncestorWithType(name, ICPPASTUsingDeclaration.class) != null) { } else if (ASTQueries.findAncestorWithType(name, ICPPASTUsingDeclaration.class) != null) {
if (usingDeclarations == null) if (usingDeclarations == null)
usingDeclarations = new ArrayList<>(1); usingDeclarations = new ArrayList<>(1);
usingDeclarations.add(name); usingDeclarations.add(name);

View file

@ -101,6 +101,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.ui.text.ICPartitions; import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable; import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
import org.eclipse.cdt.internal.corext.util.Strings; import org.eclipse.cdt.internal.corext.util.Strings;
@ -444,10 +445,10 @@ public class CSourceHover extends AbstractCEditorTextHover {
* otherwise {@code null}. * otherwise {@code null}.
*/ */
private String computeHoverForDeclaration(IASTName name) { private String computeHoverForDeclaration(IASTName name) {
ICPPASTDeclarator declarator = CPPVisitor.findAncestorWithType(name, ICPPASTDeclarator.class); ICPPASTDeclarator declarator = ASTQueries.findAncestorWithType(name, ICPPASTDeclarator.class);
if (declarator == null) if (declarator == null)
return null; return null;
IASTDeclaration declaration = CPPVisitor.findAncestorWithType(declarator, IASTDeclaration.class); IASTDeclaration declaration = ASTQueries.findAncestorWithType(declarator, IASTDeclaration.class);
IASTDeclSpecifier declSpec = null; IASTDeclSpecifier declSpec = null;
if (declaration instanceof IASTSimpleDeclaration) { if (declaration instanceof IASTSimpleDeclaration) {
declSpec = ((IASTSimpleDeclaration) declaration).getDeclSpecifier(); declSpec = ((IASTSimpleDeclaration) declaration).getDeclSpecifier();