mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 09:55:29 +02:00
Move findAncestorWithType() from CPPVisitor to ASTQueries
Change-Id: Ibcbc0a2685dabd66e7025db5d2924acbbb5a882d Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
7eeecab020
commit
bc953d2348
29 changed files with 82 additions and 76 deletions
|
@ -128,6 +128,23 @@ public class ASTQueries {
|
|||
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>.
|
||||
*/
|
||||
|
|
|
@ -269,7 +269,7 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
|
|||
@Override
|
||||
public IBinding getOwner() {
|
||||
IASTFunctionDeclarator decl =
|
||||
CPPVisitor.findAncestorWithType(fDeclarations[0], IASTFunctionDeclarator.class);
|
||||
ASTQueries.findAncestorWithType(fDeclarations[0], IASTFunctionDeclarator.class);
|
||||
if (decl == null)
|
||||
return null;
|
||||
IASTName name= decl.getName();
|
||||
|
|
|
@ -882,7 +882,7 @@ public class CPPTemplates {
|
|||
IType type = instantiateType(var.getType(), tpMap, -1, within, point);
|
||||
|
||||
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) {
|
||||
// Explicit specialization.
|
||||
value = SemanticUtil.getValueOfInitializer(decl.getInitializer(), type);
|
||||
|
|
|
@ -1329,7 +1329,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
return new CPPScope.CPPScopeProblem(name, ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
|
||||
}
|
||||
} else if (parent instanceof ICPPASTFieldDesignator) {
|
||||
ICPPASTDeclarator declarator = findAncestorWithType(parent, ICPPASTDeclarator.class);
|
||||
ICPPASTDeclarator declarator = ASTQueries.findAncestorWithType(parent, ICPPASTDeclarator.class);
|
||||
if (declarator != null) {
|
||||
IType type = createType(declarator);
|
||||
type= getNestedType(type, TDEF | CVTYPE);
|
||||
|
@ -2707,23 +2707,6 @@ public class CPPVisitor extends ASTQueries {
|
|||
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
|
||||
* returns a list of their operands in left-to-right order. For example, for the expression
|
||||
|
|
|
@ -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.ICPPTypeSpecialization;
|
||||
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.ITypeMarshalBuffer;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
|
||||
|
@ -300,7 +301,7 @@ public class EvalBinding extends CPPDependentEvaluation {
|
|||
IASTTranslationUnit ast = point.getTranslationUnit();
|
||||
IASTName[] definitions = ast.getDefinitionsInAST(binding);
|
||||
for (IASTName definition : definitions) {
|
||||
IASTDeclarator declarator = CPPVisitor.findAncestorWithType(definition, IASTDeclarator.class);
|
||||
IASTDeclarator declarator = ASTQueries.findAncestorWithType(definition, IASTDeclarator.class);
|
||||
if (declarator != null) {
|
||||
IType localType = CPPVisitor.createType(declarator);
|
||||
if (localType instanceof IArrayType && ((IArrayType) localType).getSize() != null) {
|
||||
|
|
|
@ -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.ICPPTemplateParameterMap;
|
||||
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.ITypeMarshalBuffer;
|
||||
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.
|
||||
*/
|
||||
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)
|
||||
return false;
|
||||
IBinding enumerator = enumeratorNode.getName().getBinding();
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
|
|||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
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.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -237,11 +237,11 @@ public class CCodeFormatter extends CodeFormatter {
|
|||
node = nodeSelector.findFirstContainedNode(pos, end - pos);
|
||||
if (node != null) {
|
||||
IASTNode containedNode = node;
|
||||
node = CPPVisitor.findAncestorWithType(containedNode, IASTStatement.class);
|
||||
node = ASTQueries.findAncestorWithType(containedNode, IASTStatement.class);
|
||||
if (node == null)
|
||||
node = CPPVisitor.findAncestorWithType(containedNode, IASTDeclaration.class);
|
||||
node = ASTQueries.findAncestorWithType(containedNode, IASTDeclaration.class);
|
||||
if (node == null)
|
||||
node = CPPVisitor.findAncestorWithType(containedNode, IASTPreprocessorMacroExpansion.class);
|
||||
node = ASTQueries.findAncestorWithType(containedNode, IASTPreprocessorMacroExpansion.class);
|
||||
}
|
||||
if (node == null)
|
||||
break;
|
||||
|
|
|
@ -62,7 +62,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
|||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
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.model.ASTCache.ASTRunnable;
|
||||
import org.eclipse.cdt.internal.core.model.ext.CElementHandleFactory;
|
||||
|
@ -289,7 +289,7 @@ public class SelectionToDeclarationJob extends Job implements ASTRunnable {
|
|||
IASTName name = astNames[i];
|
||||
if (name.isDefinition()) {
|
||||
astNames[i] = null;
|
||||
} else if (CPPVisitor.findAncestorWithType(name, ICPPASTUsingDeclaration.class) != null) {
|
||||
} else if (ASTQueries.findAncestorWithType(name, ICPPASTUsingDeclaration.class) != null) {
|
||||
if (usingDeclarations == null)
|
||||
usingDeclarations = new ArrayList<IASTName>(1);
|
||||
usingDeclarations.add(name);
|
||||
|
|
|
@ -46,8 +46,8 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
|||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
|
||||
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.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.util.ASTNodes;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.cdt.internal.corext.refactoring.code.flow.FlowContext;
|
||||
|
@ -206,7 +206,7 @@ public class NodeContainer {
|
|||
|
||||
IASTNode firstNode = nodes.get(0);
|
||||
IASTFunctionDefinition enclosingFunction =
|
||||
CPPVisitor.findAncestorWithType(firstNode, IASTFunctionDefinition.class);
|
||||
ASTQueries.findAncestorWithType(firstNode, IASTFunctionDefinition.class);
|
||||
FlowContext flowContext= new FlowContext(enclosingFunction);
|
||||
flowContext.setConsiderAccessMode(true);
|
||||
flowContext.setComputeMode(FlowContext.ARGUMENTS);
|
||||
|
|
|
@ -58,13 +58,13 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
|
|||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
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.CPPASTIdExpression;
|
||||
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.CPPASTSimpleDeclaration;
|
||||
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.CRefactoringDescriptor;
|
||||
|
@ -171,7 +171,7 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
|
||||
private ArrayList<String> findAllDeclaredNames() {
|
||||
ArrayList<String>names = new ArrayList<String>();
|
||||
IASTFunctionDefinition funcDef = CPPVisitor.findAncestorWithType(target, IASTFunctionDefinition.class);
|
||||
IASTFunctionDefinition funcDef = ASTQueries.findAncestorWithType(target, IASTFunctionDefinition.class);
|
||||
ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef);
|
||||
if (comTypeSpec != null) {
|
||||
for(IASTDeclaration dec : comTypeSpec.getMembers()) {
|
||||
|
|
|
@ -88,6 +88,7 @@ import org.eclipse.cdt.core.model.ICProject;
|
|||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
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.cpp.CPPASTBinaryExpression;
|
||||
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.CPPASTSimpleDeclaration;
|
||||
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.rewrite.astwriter.ASTWriterVisitor;
|
||||
|
||||
|
@ -387,7 +387,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
private void createMethodDefinition(final IASTName methodName, MethodContext context,
|
||||
IASTNode firstExtractedNode, ModificationCollector collector) {
|
||||
IASTFunctionDefinition functionToExtractFrom =
|
||||
CPPVisitor.findAncestorWithType(firstExtractedNode, IASTFunctionDefinition.class);
|
||||
ASTQueries.findAncestorWithType(firstExtractedNode, IASTFunctionDefinition.class);
|
||||
if (functionToExtractFrom != null) {
|
||||
String title;
|
||||
if (context.getType() == MethodContext.ContextType.METHOD) {
|
||||
|
@ -778,7 +778,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
IASTFunctionCallExpression callExpression, IASTName retname) {
|
||||
if (info.getReturnVariable().equals(info.getMandatoryReturnVariable())) {
|
||||
IASTSimpleDeclaration orgDecl =
|
||||
CPPVisitor.findAncestorWithType(info.getReturnVariable().getDeclarationName(),
|
||||
ASTQueries.findAncestorWithType(info.getReturnVariable().getDeclarationName(),
|
||||
IASTSimpleDeclaration.class);
|
||||
IASTSimpleDeclaration decl = new CPPASTSimpleDeclaration();
|
||||
|
||||
|
|
|
@ -60,12 +60,12 @@ import org.eclipse.cdt.core.model.ICProject;
|
|||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
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.CPPASTEqualsInitializer;
|
||||
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.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.CRefactoringDescriptor;
|
||||
|
@ -142,7 +142,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
|
||||
private ArrayList<String> findAllDeclaredNames() {
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
IASTFunctionDefinition funcDef = CPPVisitor.findAncestorWithType(target, IASTFunctionDefinition.class);
|
||||
IASTFunctionDefinition funcDef = ASTQueries.findAncestorWithType(target, IASTFunctionDefinition.class);
|
||||
ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef);
|
||||
if (comTypeSpec != null) {
|
||||
for (IASTDeclaration decl : comTypeSpec.getMembers()) {
|
||||
|
@ -332,7 +332,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
public String[] guessTempNames() {
|
||||
final List<String> guessedTempNames = 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;
|
||||
if (funcDef != null && funcDef.getBody() instanceof IASTCompoundStatement) {
|
||||
IASTCompoundStatement body = (IASTCompoundStatement) funcDef.getBody();
|
||||
|
|
|
@ -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.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.CASTPointer;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
|
||||
|
@ -74,7 +75,7 @@ public abstract class AccessorFactory {
|
|||
this.fieldDeclarator = fieldDeclarator;
|
||||
this.accessorName = accessorName;
|
||||
IASTSimpleDeclaration declaration =
|
||||
CPPVisitor.findAncestorWithType(fieldDeclarator, IASTSimpleDeclaration.class);
|
||||
ASTQueries.findAncestorWithType(fieldDeclarator, IASTSimpleDeclaration.class);
|
||||
this.declSpecifier = declaration.getDeclSpecifier();
|
||||
IType type = CPPVisitor.createType(declSpecifier);
|
||||
passByReference = TypeHelper.shouldBePassedByReference(type, fieldDeclarator.getTranslationUnit());
|
||||
|
|
|
@ -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.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.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ContainerNode;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
||||
|
@ -227,7 +227,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
|||
List<IASTNode> getterAndSetters = new ArrayList<IASTNode>();
|
||||
List<IASTFunctionDefinition> definitions = new ArrayList<IASTFunctionDefinition>();
|
||||
ICPPASTCompositeTypeSpecifier classDefinition =
|
||||
CPPVisitor.findAncestorWithType(context.existingFields.get(0), ICPPASTCompositeTypeSpecifier.class);
|
||||
ASTQueries.findAncestorWithType(context.existingFields.get(0), ICPPASTCompositeTypeSpecifier.class);
|
||||
for (AccessorDescriptor accessor : context.selectedAccessors) {
|
||||
IASTName accessorName = new CPPASTName(accessor.toString().toCharArray());
|
||||
if (context.isDefinitionSeparate()) {
|
||||
|
@ -277,7 +277,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
IASTSimpleDeclaration decl =
|
||||
CPPVisitor.findAncestorWithType(context.existingFields.get(0), IASTSimpleDeclaration.class);
|
||||
ASTQueries.findAncestorWithType(context.existingFields.get(0), IASTSimpleDeclaration.class);
|
||||
MethodDefinitionInsertLocationFinder locationFinder = new MethodDefinitionInsertLocationFinder();
|
||||
InsertLocation location = locationFinder.find(tu, decl.getFileLocation(), decl.getParent(),
|
||||
refactoringContext, pm);
|
||||
|
|
|
@ -143,7 +143,7 @@ public class HideMethodRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
IASTCompositeTypeSpecifier classNode =
|
||||
CPPVisitor.findAncestorWithType(methodName, IASTCompositeTypeSpecifier.class);
|
||||
ASTQueries.findAncestorWithType(methodName, IASTCompositeTypeSpecifier.class);
|
||||
if (classNode == null) {
|
||||
initStatus.addError(Messages.HideMethodRefactoring_EnclosingClassNotFound);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ import org.eclipse.cdt.core.model.ICElement;
|
|||
import org.eclipse.cdt.core.model.ICProject;
|
||||
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.ModificationCollector;
|
||||
|
@ -278,7 +278,7 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
|||
IASTFunctionDefinition functionDefinition = nodeFactory.newFunctionDefinition(declSpecifier, createdMethodDeclarator, nodeFactory.newCompoundStatement());
|
||||
functionDefinition.setParent(unit);
|
||||
|
||||
ICPPASTTemplateDeclaration templateDeclaration = CPPVisitor.findAncestorWithType(declarationParent, ICPPASTTemplateDeclaration.class);
|
||||
ICPPASTTemplateDeclaration templateDeclaration = ASTQueries.findAncestorWithType(declarationParent, ICPPASTTemplateDeclaration.class);
|
||||
if (templateDeclaration != null) {
|
||||
ICPPASTTemplateDeclaration newTemplateDeclaration = nodeFactory.newTemplateDeclaration(functionDefinition);
|
||||
newTemplateDeclaration.setParent(unit);
|
||||
|
|
|
@ -120,6 +120,7 @@ import org.eclipse.cdt.core.index.IndexFilter;
|
|||
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.ASTQueries;
|
||||
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.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.MethodKind;
|
||||
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.LookupData;
|
||||
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.
|
||||
*/
|
||||
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)
|
||||
return false;
|
||||
ICPPASTTemplateId templateId = (ICPPASTTemplateId) typeId.getParent();
|
||||
|
|
|
@ -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.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
|
||||
|
@ -106,6 +106,6 @@ public class DeclaratorFinder {
|
|||
}
|
||||
|
||||
private boolean isPartOfAStatement(IASTNode node) {
|
||||
return CPPVisitor.findAncestorWithType(node, IASTStatement.class) != null;
|
||||
return ASTQueries.findAncestorWithType(node, IASTStatement.class) != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.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.semantics.CPPVisitor;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.Container;
|
||||
|
||||
|
@ -93,7 +93,7 @@ public class InsertionPointFinder {
|
|||
public int visit(IASTDeclaration declaration) {
|
||||
if (declaration instanceof ICPPASTFunctionDefinition) {
|
||||
if (declaration.getParent() != null &&
|
||||
CPPVisitor.findAncestorWithType(declaration, CPPASTCompositeTypeSpecifier.class) != null) {
|
||||
ASTQueries.findAncestorWithType(declaration, CPPASTCompositeTypeSpecifier.class) != null) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
definitions.add((ICPPASTFunctionDefinition) declaration);
|
||||
|
|
|
@ -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.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;
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
|
|||
|
||||
private boolean isInClass(IASTNode node) {
|
||||
return node != null &&
|
||||
CPPVisitor.findAncestorWithType(node, ICPPASTCompositeTypeSpecifier.class) != null;
|
||||
ASTQueries.findAncestorWithType(node, ICPPASTCompositeTypeSpecifier.class) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,7 +81,7 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
|
|||
|
||||
private IASTNode getParentNamespace() {
|
||||
IASTNode parentNamespace =
|
||||
CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTNamespaceDefinition.class);
|
||||
ASTQueries.findAncestorWithType(context.getDefinition(), ICPPASTNamespaceDefinition.class);
|
||||
if (parentNamespace == null)
|
||||
parentNamespace = context.getDefinitionAST();
|
||||
return parentNamespace;
|
||||
|
|
|
@ -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.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.ui.refactoring.ModificationCollector;
|
||||
|
@ -118,7 +118,7 @@ public class ToggleFromImplementationToHeaderOrClassStrategy implements IToggleR
|
|||
}
|
||||
|
||||
private IASTNode getParent() {
|
||||
IASTNode parent = CPPVisitor.findAncestorWithType(context.getDefinition(),
|
||||
IASTNode parent = ASTQueries.findAncestorWithType(context.getDefinition(),
|
||||
ICPPASTCompositeTypeSpecifier.class);
|
||||
IASTNode parentnode = null;
|
||||
if (parent != null) {
|
||||
|
|
|
@ -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.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.semantics.CPPVisitor;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class ToggleFromInHeaderToClassStrategy implements IToggleRefactoringStra
|
|||
if (declarator.getName() instanceof ICPPASTQualifiedName) {
|
||||
declarator = backup;
|
||||
}
|
||||
return (CPPVisitor.findAncestorWithType(declarator, IASTCompositeTypeSpecifier.class) == null);
|
||||
return (ASTQueries.findAncestorWithType(declarator, IASTCompositeTypeSpecifier.class) == null);
|
||||
}
|
||||
|
||||
@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) {
|
||||
newDefinition.setParent(parent);
|
||||
} else {
|
||||
|
@ -111,7 +111,7 @@ public class ToggleFromInHeaderToClassStrategy implements IToggleRefactoringStra
|
|||
|
||||
private ASTRewrite replaceDeclarationWithDefinition(ASTRewrite rewriter,
|
||||
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);
|
||||
return newRewriter;
|
||||
}
|
||||
|
|
|
@ -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.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.rewrite.DeclarationGeneratorImpl;
|
||||
|
||||
|
@ -510,11 +510,11 @@ public class ToggleNodeHelper extends NodeHelper {
|
|||
*/
|
||||
public static List<ICPPASTNamespaceDefinition> findSurroundingNamespaces(IASTNode node) {
|
||||
ArrayList<ICPPASTNamespaceDefinition> namespaces = new ArrayList<>();
|
||||
ICPPASTNamespaceDefinition currentNamespace = CPPVisitor.findAncestorWithType(node,
|
||||
ICPPASTNamespaceDefinition currentNamespace = ASTQueries.findAncestorWithType(node,
|
||||
ICPPASTNamespaceDefinition.class);
|
||||
while (currentNamespace != null) {
|
||||
namespaces.add(0, currentNamespace);
|
||||
currentNamespace = CPPVisitor.findAncestorWithType(currentNamespace.getParent(),
|
||||
currentNamespace = ASTQueries.findAncestorWithType(currentNamespace.getParent(),
|
||||
ICPPASTNamespaceDefinition.class);
|
||||
}
|
||||
return namespaces;
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.eclipse.cdt.core.model.CoreModelUtil;
|
|||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
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.ui.editor.SourceHeaderPartnerFinder;
|
||||
|
@ -184,11 +184,11 @@ public class ToggleRefactoringContext {
|
|||
if (node instanceof IASTSimpleDeclaration) {
|
||||
return (IASTFunctionDeclarator) ((IASTSimpleDeclaration) node).getDeclarators()[0];
|
||||
}
|
||||
return CPPVisitor.findAncestorWithType(node, IASTFunctionDeclarator.class);
|
||||
return ASTQueries.findAncestorWithType(node, IASTFunctionDeclarator.class);
|
||||
}
|
||||
|
||||
private IASTFunctionDefinition findFunctionDefinition(IASTNode node) {
|
||||
return CPPVisitor.findAncestorWithType(node, IASTFunctionDefinition.class);
|
||||
return ASTQueries.findAncestorWithType(node, IASTFunctionDefinition.class);
|
||||
}
|
||||
|
||||
public void setDefaultAnswer(boolean defaultAnswer) {
|
||||
|
|
|
@ -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.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 {
|
||||
private ToggleRefactoringContext context;
|
||||
|
@ -44,10 +44,10 @@ public class ToggleStrategyFactory {
|
|||
|
||||
private boolean isInClassSituation() {
|
||||
return (context.getDeclaration() == null) &&
|
||||
(CPPVisitor.findAncestorWithType(context.getDefinition(), IASTCompositeTypeSpecifier.class) != null);
|
||||
(ASTQueries.findAncestorWithType(context.getDefinition(), IASTCompositeTypeSpecifier.class) != null);
|
||||
}
|
||||
|
||||
private boolean isTemplateSituation() {
|
||||
return (CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTTemplateDeclaration.class) != null);
|
||||
return (ASTQueries.findAncestorWithType(context.getDefinition(), ICPPASTTemplateDeclaration.class) != null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.eclipse.cdt.core.model.CoreModelUtil;
|
|||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
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.refactoring.CRefactoringContext;
|
||||
|
@ -262,7 +262,7 @@ public class DefinitionFinder {
|
|||
if (classDefintionName == null)
|
||||
return null;
|
||||
IASTCompositeTypeSpecifier compositeTypeSpecifier =
|
||||
CPPVisitor.findAncestorWithType(classDefintionName, IASTCompositeTypeSpecifier.class);
|
||||
ASTQueries.findAncestorWithType(classDefintionName, IASTCompositeTypeSpecifier.class);
|
||||
IASTTranslationUnit ast = classDefintionName.getTranslationUnit();
|
||||
IIndex index = context.getIndex();
|
||||
if (index == null) {
|
||||
|
@ -271,7 +271,7 @@ public class DefinitionFinder {
|
|||
IASTName[] memberDeclarationNames = ast.getDeclarationsInAST(index.adaptBinding(member));
|
||||
for (IASTName name : memberDeclarationNames) {
|
||||
if (name.getPropertyInParent() == IASTDeclarator.DECLARATOR_NAME) {
|
||||
IASTDeclaration declaration = CPPVisitor.findAncestorWithType(name, IASTDeclaration.class);
|
||||
IASTDeclaration declaration = ASTQueries.findAncestorWithType(name, IASTDeclaration.class);
|
||||
if (declaration.getParent() == compositeTypeSpecifier) {
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -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.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.CPPASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
@ -141,6 +142,6 @@ public class NodeHelper {
|
|||
}
|
||||
|
||||
public static boolean isContainedInTemplateDeclaration(IASTNode node) {
|
||||
return CPPVisitor.findAncestorWithType(node, ICPPASTTemplateDeclaration.class) != null;
|
||||
return ASTQueries.findAncestorWithType(node, ICPPASTTemplateDeclaration.class) != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
|||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
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.semantics.CPPSemantics;
|
||||
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];
|
||||
if (name.isDefinition()) {
|
||||
astNames[i]= null;
|
||||
} else if (CPPVisitor.findAncestorWithType(name, ICPPASTUsingDeclaration.class) != null) {
|
||||
} else if (ASTQueries.findAncestorWithType(name, ICPPASTUsingDeclaration.class) != null) {
|
||||
if (usingDeclarations == null)
|
||||
usingDeclarations = new ArrayList<>(1);
|
||||
usingDeclarations.add(name);
|
||||
|
|
|
@ -101,6 +101,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
|||
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
||||
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.model.ASTCache.ASTRunnable;
|
||||
import org.eclipse.cdt.internal.corext.util.Strings;
|
||||
|
@ -444,10 +445,10 @@ public class CSourceHover extends AbstractCEditorTextHover {
|
|||
* otherwise {@code null}.
|
||||
*/
|
||||
private String computeHoverForDeclaration(IASTName name) {
|
||||
ICPPASTDeclarator declarator = CPPVisitor.findAncestorWithType(name, ICPPASTDeclarator.class);
|
||||
ICPPASTDeclarator declarator = ASTQueries.findAncestorWithType(name, ICPPASTDeclarator.class);
|
||||
if (declarator == null)
|
||||
return null;
|
||||
IASTDeclaration declaration = CPPVisitor.findAncestorWithType(declarator, IASTDeclaration.class);
|
||||
IASTDeclaration declaration = ASTQueries.findAncestorWithType(declarator, IASTDeclaration.class);
|
||||
IASTDeclSpecifier declSpec = null;
|
||||
if (declaration instanceof IASTSimpleDeclaration) {
|
||||
declSpec = ((IASTSimpleDeclaration) declaration).getDeclSpecifier();
|
||||
|
|
Loading…
Add table
Reference in a new issue