mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Patch for Devin Steffler includes:
- search for IASTNames in the view - progress of view is displayed in progress view and no longer freezes the GUI
This commit is contained in:
parent
04dd7a6d96
commit
beb6ead6ac
10 changed files with 2246 additions and 252 deletions
BIN
core/org.eclipse.cdt.ui.tests/icons/used/search_ref_obj.gif
Normal file
BIN
core/org.eclipse.cdt.ui.tests/icons/used/search_ref_obj.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 151 B |
|
@ -14,6 +14,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
|
||||
public class CTestPlugin extends Plugin {
|
||||
|
@ -53,5 +54,13 @@ public class CTestPlugin extends Plugin {
|
|||
public static String getPluginId() {
|
||||
return PLUGIN_ID;
|
||||
}
|
||||
|
||||
public static Display getStandardDisplay() {
|
||||
Display display= Display.getCurrent();
|
||||
if (display == null) {
|
||||
display= Display.getDefault();
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
}
|
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
|
@ -39,6 +40,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBas
|
|||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.LocationMap.ASTInclusionStatement;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
|
@ -61,13 +63,22 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
|||
}
|
||||
|
||||
TreeParent root = null;
|
||||
IProgressMonitor monitor = null;
|
||||
|
||||
public CPPPopulateASTViewAction(IASTTranslationUnit tu) {
|
||||
public CPPPopulateASTViewAction(IASTTranslationUnit tu, IProgressMonitor monitor) {
|
||||
root = new TreeParent(tu);
|
||||
this.monitor = monitor;
|
||||
}
|
||||
|
||||
private void addRoot(IASTNode node) {
|
||||
if (node == null) return;
|
||||
private int addRoot(IASTNode node) {
|
||||
if (monitor != null && monitor.isCanceled()) return PROCESS_ABORT;
|
||||
if (node == null) return PROCESS_CONTINUE;
|
||||
|
||||
IASTNodeLocation[] nodeLocations = node.getNodeLocations();
|
||||
if (!(nodeLocations.length > 0 &&
|
||||
nodeLocations[0].getNodeOffset() >= 0 &&
|
||||
nodeLocations[0].getNodeLength() > 0))
|
||||
return PROCESS_CONTINUE;
|
||||
|
||||
TreeParent parent = root.findTreeParentForNode(node);
|
||||
|
||||
|
@ -84,21 +95,22 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
|||
tree.setFiltersFlag(TreeObject.FLAG_PREPROCESSOR);
|
||||
if (node instanceof IASTPreprocessorIncludeStatement)
|
||||
tree.setFiltersFlag(TreeObject.FLAG_INCLUDE_STATEMENTS);
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
|
||||
*/
|
||||
public int processDeclaration(IASTDeclaration declaration) {
|
||||
addRoot(declaration);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(declaration);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
|
||||
*/
|
||||
public int processDeclarator(IASTDeclarator declarator) {
|
||||
addRoot(declarator);
|
||||
int ret = addRoot(declarator);
|
||||
|
||||
IASTPointerOperator[] ops = declarator.getPointerOperators();
|
||||
for(int i=0; i<ops.length; i++)
|
||||
|
@ -124,47 +136,42 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
|||
}
|
||||
}
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processBaseSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier)
|
||||
*/
|
||||
public int processBaseSpecifier(ICPPASTBaseSpecifier specifier) {
|
||||
addRoot(specifier);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(specifier);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
|
||||
*/
|
||||
public int processDeclSpecifier(IASTDeclSpecifier declSpec) {
|
||||
addRoot(declSpec);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(declSpec);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
|
||||
*/
|
||||
public int processEnumerator(IASTEnumerator enumerator) {
|
||||
addRoot(enumerator);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(enumerator);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
|
||||
*/
|
||||
public int processExpression(IASTExpression expression) {
|
||||
addRoot(expression);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(expression);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
|
||||
*/
|
||||
public int processInitializer(IASTInitializer initializer) {
|
||||
addRoot(initializer);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(initializer);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -172,7 +179,7 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
|||
*/
|
||||
public int processName(IASTName name) {
|
||||
if (name.toString() != null)
|
||||
addRoot(name);
|
||||
return addRoot(name);
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -180,8 +187,7 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
|||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processNamespace(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition)
|
||||
*/
|
||||
public int processNamespace(ICPPASTNamespaceDefinition namespace) {
|
||||
addRoot(namespace);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(namespace);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -189,24 +195,21 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
|||
*/
|
||||
public int processParameterDeclaration(
|
||||
IASTParameterDeclaration parameterDeclaration) {
|
||||
addRoot(parameterDeclaration);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(parameterDeclaration);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
|
||||
*/
|
||||
public int processStatement(IASTStatement statement) {
|
||||
addRoot(statement);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(statement);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
|
||||
*/
|
||||
public int processTypeId(IASTTypeId typeId) {
|
||||
addRoot(typeId);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(typeId);
|
||||
}
|
||||
|
||||
private void mergeNode(ASTNode node) {
|
||||
|
@ -216,43 +219,34 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
|||
addRoot(((IASTPreprocessorMacroDefinition)node).getName());
|
||||
}
|
||||
|
||||
private void mergePreprocessorStatements(IASTPreprocessorStatement[] statements) {
|
||||
public void mergePreprocessorStatements(IASTPreprocessorStatement[] statements) {
|
||||
for(int i=0; i<statements.length; i++) {
|
||||
if (monitor != null && monitor.isCanceled()) return;
|
||||
|
||||
if (statements[i] instanceof ASTNode)
|
||||
mergeNode((ASTNode)statements[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void mergePreprocessorProblems(IASTProblem[] problems) {
|
||||
public void mergePreprocessorProblems(IASTProblem[] problems) {
|
||||
for(int i=0; i<problems.length; i++) {
|
||||
if (monitor != null && monitor.isCanceled()) return;
|
||||
|
||||
if (problems[i] instanceof ASTNode)
|
||||
mergeNode((ASTNode)problems[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public TreeParent getTree() {
|
||||
if (root.getNode() instanceof IASTTranslationUnit) {
|
||||
IASTTranslationUnit tu = (IASTTranslationUnit)root.getNode();
|
||||
|
||||
IASTPreprocessorStatement[] statements = tu.getAllPreprocessorStatements();
|
||||
// merge preprocessor statements to the tree
|
||||
mergePreprocessorStatements(statements);
|
||||
|
||||
// merge preprocessor problems to the tree
|
||||
mergePreprocessorProblems(tu.getPreprocesorProblems());
|
||||
|
||||
// group #includes
|
||||
groupIncludes(statements);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private void groupIncludes(IASTPreprocessorStatement[] statements) {
|
||||
public void groupIncludes(IASTPreprocessorStatement[] statements) {
|
||||
// get all of the includes from the preprocessor statements (need the object since .equals isn't implemented)
|
||||
IASTPreprocessorIncludeStatement[] includes = new IASTPreprocessorIncludeStatement[INITIAL_INCLUDE_STATEMENT_SIZE];
|
||||
int index = 0;
|
||||
for(int i=0; i<statements.length; i++) {
|
||||
if (monitor != null && monitor.isCanceled()) return;
|
||||
if (index+1 > includes.length) {
|
||||
IASTPreprocessorIncludeStatement[] newIncludes = new IASTPreprocessorIncludeStatement[includes.length * 2];
|
||||
for (int j=0; j<includes.length; j++) {
|
||||
|
@ -268,6 +262,7 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
|||
// get the tree model elements corresponding to the includes
|
||||
TreeParent[] treeIncludes = new TreeParent[includes.length];
|
||||
for (int i=0; i<treeIncludes.length; i++) {
|
||||
if (monitor != null && monitor.isCanceled()) return;
|
||||
treeIncludes[i] = root.findTreeObject(includes[i]);
|
||||
}
|
||||
|
||||
|
@ -278,6 +273,7 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
|||
if (treeIncludes[i] == null) continue;
|
||||
|
||||
for(int j=root.getChildren().length-1; j>=0; j--) {
|
||||
if (monitor != null && monitor.isCanceled()) return;
|
||||
child = root.getChildren()[j];
|
||||
|
||||
if (treeIncludes[i] != child &&
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.LocationMap.ASTInclusionStatement;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
|
@ -55,20 +56,23 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
|||
processEnumerators = true;
|
||||
}
|
||||
|
||||
TreeParent root = null; // TODO what about using a hashtable/hashmap for the tree?
|
||||
TreeParent root = null;
|
||||
IProgressMonitor monitor = null;
|
||||
|
||||
public CPopulateASTViewAction(IASTTranslationUnit tu) {
|
||||
public CPopulateASTViewAction(IASTTranslationUnit tu, IProgressMonitor monitor) {
|
||||
root = new TreeParent(tu);
|
||||
this.monitor = monitor;
|
||||
}
|
||||
|
||||
private void addRoot(IASTNode node) {
|
||||
if (node == null) return;
|
||||
private int addRoot(IASTNode node) {
|
||||
if (monitor != null && monitor.isCanceled()) return PROCESS_ABORT;
|
||||
if (node == null) return PROCESS_CONTINUE;
|
||||
|
||||
IASTNodeLocation[] nodeLocations = node.getNodeLocations();
|
||||
if (!(nodeLocations.length > 0 &&
|
||||
nodeLocations[0].getNodeOffset() >= 0 &&
|
||||
nodeLocations[0].getNodeLength() > 0))
|
||||
return;
|
||||
return PROCESS_CONTINUE;
|
||||
|
||||
TreeParent parent = root.findTreeParentForNode(node);
|
||||
|
||||
|
@ -85,21 +89,22 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
|||
tree.setFiltersFlag(TreeObject.FLAG_PREPROCESSOR);
|
||||
if (node instanceof IASTPreprocessorIncludeStatement)
|
||||
tree.setFiltersFlag(TreeObject.FLAG_INCLUDE_STATEMENTS);
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
|
||||
*/
|
||||
public int processDeclaration(IASTDeclaration declaration) {
|
||||
addRoot(declaration);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(declaration);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
|
||||
*/
|
||||
public int processDeclarator(IASTDeclarator declarator) {
|
||||
addRoot(declarator);
|
||||
int ret = addRoot(declarator);
|
||||
|
||||
IASTPointerOperator[] ops = declarator.getPointerOperators();
|
||||
for(int i=0; i<ops.length; i++)
|
||||
|
@ -111,47 +116,42 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
|||
addRoot(mods[i]);
|
||||
}
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator)
|
||||
*/
|
||||
public int processDesignator(ICASTDesignator designator) {
|
||||
addRoot(designator);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(designator);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
|
||||
*/
|
||||
public int processDeclSpecifier(IASTDeclSpecifier declSpec) {
|
||||
addRoot(declSpec);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(declSpec);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
|
||||
*/
|
||||
public int processEnumerator(IASTEnumerator enumerator) {
|
||||
addRoot(enumerator);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(enumerator);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
|
||||
*/
|
||||
public int processExpression(IASTExpression expression) {
|
||||
addRoot(expression);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(expression);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
|
||||
*/
|
||||
public int processInitializer(IASTInitializer initializer) {
|
||||
addRoot(initializer);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(initializer);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -159,7 +159,7 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
|||
*/
|
||||
public int processName(IASTName name) {
|
||||
if ( name.toString() != null )
|
||||
addRoot(name);
|
||||
return addRoot(name);
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -168,24 +168,21 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
|||
*/
|
||||
public int processParameterDeclaration(
|
||||
IASTParameterDeclaration parameterDeclaration) {
|
||||
addRoot(parameterDeclaration);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(parameterDeclaration);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
|
||||
*/
|
||||
public int processStatement(IASTStatement statement) {
|
||||
addRoot(statement);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(statement);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
|
||||
*/
|
||||
public int processTypeId(IASTTypeId typeId) {
|
||||
addRoot(typeId);
|
||||
return PROCESS_CONTINUE;
|
||||
return addRoot(typeId);
|
||||
}
|
||||
|
||||
private void mergeNode(ASTNode node) {
|
||||
|
@ -195,43 +192,34 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
|||
addRoot(((IASTPreprocessorMacroDefinition)node).getName());
|
||||
}
|
||||
|
||||
private void mergePreprocessorStatements(IASTPreprocessorStatement[] statements) {
|
||||
public void mergePreprocessorStatements(IASTPreprocessorStatement[] statements) {
|
||||
for(int i=0; i<statements.length; i++) {
|
||||
if (monitor != null && monitor.isCanceled()) return;
|
||||
|
||||
if (statements[i] instanceof ASTNode)
|
||||
mergeNode((ASTNode)statements[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void mergePreprocessorProblems(IASTProblem[] problems) {
|
||||
public void mergePreprocessorProblems(IASTProblem[] problems) {
|
||||
for(int i=0; i<problems.length; i++) {
|
||||
if (monitor != null && monitor.isCanceled()) return;
|
||||
|
||||
if (problems[i] instanceof ASTNode)
|
||||
mergeNode((ASTNode)problems[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public TreeParent getTree() {
|
||||
if (root.getNode() instanceof IASTTranslationUnit) {
|
||||
IASTTranslationUnit tu = (IASTTranslationUnit)root.getNode();
|
||||
|
||||
IASTPreprocessorStatement[] statements = tu.getAllPreprocessorStatements();
|
||||
// merge preprocessor statements to the tree
|
||||
mergePreprocessorStatements(statements);
|
||||
|
||||
// merge preprocessor problems to the tree
|
||||
mergePreprocessorProblems(tu.getPreprocesorProblems());
|
||||
|
||||
// group #includes
|
||||
groupIncludes(statements);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private void groupIncludes(IASTPreprocessorStatement[] statements) {
|
||||
public void groupIncludes(IASTPreprocessorStatement[] statements) {
|
||||
// get all of the includes from the preprocessor statements (need the object since .equals isn't implemented)
|
||||
IASTPreprocessorIncludeStatement[] includes = new IASTPreprocessorIncludeStatement[INITIAL_INCLUDE_STATEMENT_SIZE];
|
||||
int index = 0;
|
||||
for(int i=0; i<statements.length; i++) {
|
||||
if (monitor != null && monitor.isCanceled()) return;
|
||||
if (index+1 > includes.length) {
|
||||
IASTPreprocessorIncludeStatement[] newIncludes = new IASTPreprocessorIncludeStatement[includes.length * 2];
|
||||
for (int j=0; j<includes.length; j++) {
|
||||
|
@ -247,6 +235,7 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
|||
// get the tree model elements corresponding to the includes
|
||||
TreeParent[] treeIncludes = new TreeParent[includes.length];
|
||||
for (int i=0; i<treeIncludes.length; i++) {
|
||||
if (monitor != null && monitor.isCanceled()) return;
|
||||
treeIncludes[i] = root.findTreeObject(includes[i]);
|
||||
}
|
||||
|
||||
|
@ -257,6 +246,7 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
|||
if (treeIncludes[i] == null) continue;
|
||||
|
||||
for(int j=root.getChildren().length-1; j>=0; j--) {
|
||||
if (monitor != null && monitor.isCanceled()) return;
|
||||
child = root.getChildren()[j];
|
||||
|
||||
if (treeIncludes[i] != child &&
|
||||
|
|
|
@ -48,12 +48,18 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAct
|
|||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
|
||||
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.ActionContributionItem;
|
||||
import org.eclipse.jface.action.IContributionItem;
|
||||
|
@ -83,11 +89,9 @@ import org.eclipse.swt.widgets.Tree;
|
|||
import org.eclipse.swt.widgets.TreeItem;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IEditorReference;
|
||||
import org.eclipse.ui.ISharedImages;
|
||||
import org.eclipse.ui.IViewPart;
|
||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.part.DrillDownAdapter;
|
||||
|
@ -109,8 +113,10 @@ import org.eclipse.ui.part.ViewPart;
|
|||
*/
|
||||
|
||||
public class DOMAST extends ViewPart {
|
||||
private static final String DOM_AST_HAS_NO_CONTENT = "DOM AST has no content"; //$NON-NLS-1$
|
||||
private static final String SEARCH_FOR_IASTNAME = "Search for IASTName"; //$NON-NLS-1$
|
||||
private static final String CLEAR = "Clear"; //$NON-NLS-1$
|
||||
private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.DOMAST.DOMASTFilterGroup"; //$NON-NLS-1$
|
||||
private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.DOMAST.DOMASTFilterGroup"; //$NON-NLS-1$
|
||||
private static final String EXTENSION_CXX = "CXX"; //$NON-NLS-1$
|
||||
private static final String EXTENSION_CPP = "CPP"; //$NON-NLS-1$
|
||||
private static final String EXTENSION_CC = "CC"; //$NON-NLS-1$
|
||||
|
@ -134,6 +140,7 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
private Action expandAllAction;
|
||||
private Action collapseAllAction;
|
||||
private Action clearAction;
|
||||
private Action searchNamesAction;
|
||||
private IFile file = null;
|
||||
private IEditorPart part = null;
|
||||
private ParserLanguage lang = null;
|
||||
|
@ -149,23 +156,46 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
|
||||
public class ViewContentProvider implements IStructuredContentProvider,
|
||||
ITreeContentProvider {
|
||||
private TreeParent invisibleRoot;
|
||||
private IFile aFile = null;
|
||||
private static final String POPULATING_AST_VIEW = "Populating AST View"; //$NON-NLS-1$
|
||||
private TreeParent invisibleRoot;
|
||||
private TreeParent tuTreeParent = null;
|
||||
private IASTTranslationUnit tu = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ViewContentProvider() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ViewContentProvider(IFile file) {
|
||||
this.aFile = file;
|
||||
this(file, null);
|
||||
}
|
||||
|
||||
public ViewContentProvider(IFile file, Object[] expanded) {
|
||||
StartInitializingASTView job = new StartInitializingASTView(new InitializeView(POPULATING_AST_VIEW, this, viewer, file), expanded);
|
||||
job.schedule();
|
||||
|
||||
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
|
||||
}
|
||||
|
||||
public TreeParent getTUTreeParent() {
|
||||
if (tuTreeParent == null && invisibleRoot != null) {
|
||||
for(int i=0; i<invisibleRoot.getChildren().length; i++) {
|
||||
if (invisibleRoot.getChildren()[i] instanceof TreeParent && invisibleRoot.getChildren()[i].getNode() instanceof IASTTranslationUnit){
|
||||
tuTreeParent = (TreeParent)invisibleRoot.getChildren()[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tuTreeParent;
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTU() {
|
||||
if (tu == null && invisibleRoot != null) {
|
||||
for(int i=0; i<invisibleRoot.getChildren().length; i++) {
|
||||
if (invisibleRoot.getChildren()[i] instanceof TreeParent && invisibleRoot.getChildren()[i].getNode() instanceof IASTTranslationUnit){
|
||||
tu = (IASTTranslationUnit)invisibleRoot.getChildren()[i].getNode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tu;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
@ -200,31 +230,202 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
return false;
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
if (aFile == null || lang == null)
|
||||
return;
|
||||
|
||||
IPopulateDOMASTAction action = null;
|
||||
IASTTranslationUnit tu = null;
|
||||
try {
|
||||
tu = CDOM.getInstance().getASTService().getTranslationUnit(
|
||||
aFile,
|
||||
CDOM.getInstance().getCodeReaderFactory(
|
||||
CDOM.PARSE_SAVED_RESOURCES));
|
||||
} catch (IASTServiceProvider.UnsupportedDialectException e) {
|
||||
return;
|
||||
}
|
||||
if (lang == ParserLanguage.CPP) {
|
||||
action = new CPPPopulateASTViewAction(tu);
|
||||
CPPVisitor.visitTranslationUnit(tu, (CPPBaseVisitorAction) action);
|
||||
} else {
|
||||
action = new CPopulateASTViewAction(tu);
|
||||
CVisitor.visitTranslationUnit(tu, (CBaseVisitorAction) action);
|
||||
}
|
||||
// display roots
|
||||
invisibleRoot = new TreeParent(null); //$NON-NLS-1$
|
||||
invisibleRoot.addChild(action.getTree());
|
||||
private class StartInitializingASTView extends Job {
|
||||
private static final String INITIALIZE_AST_VIEW = "Initialize AST View"; //$NON-NLS-1$
|
||||
InitializeView job = null;
|
||||
Object[] expanded = null;
|
||||
|
||||
public StartInitializingASTView(InitializeView job, Object[] expanded) {
|
||||
super(INITIALIZE_AST_VIEW);
|
||||
this.job = job;
|
||||
this.expanded = expanded;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
job.schedule();
|
||||
|
||||
try {
|
||||
job.join();
|
||||
} catch (InterruptedException ie) {
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
|
||||
CTestPlugin.getStandardDisplay().asyncExec(new InitializeRunnable(viewer)); // update the view from the Display thread
|
||||
// if there are objects to expand then do so now
|
||||
if (expanded != null) {
|
||||
CTestPlugin.getStandardDisplay().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
// set the expansion of the view based on the original snapshot (educated guess)
|
||||
Tree tree = viewer.getTree();
|
||||
expandTreeIfNecessary(tree.getItems(), expanded);
|
||||
|
||||
}
|
||||
|
||||
private void expandTreeIfNecessary(TreeItem[] tree, Object[] expanded) {
|
||||
for( int i=0; i<tree.length; i++) {
|
||||
for( int j=0; j<expanded.length; j++) {
|
||||
if (expanded[j] instanceof TreeObject &&
|
||||
tree[i].getData() instanceof TreeObject &&
|
||||
((TreeObject)expanded[j]).toString().equals(((TreeObject)tree[i].getData()).toString()) &&
|
||||
((TreeObject)expanded[j]).getOffset() == (((TreeObject)tree[i].getData()).getOffset())) {
|
||||
tree[i].setExpanded(true);
|
||||
viewer.refresh();
|
||||
expandTreeIfNecessary(tree[i].getItems(), expanded);
|
||||
}
|
||||
}
|
||||
}
|
||||
}});
|
||||
}
|
||||
|
||||
return job.getResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class InitializeView extends Job {
|
||||
|
||||
private static final String _PREPROCESSOR_PROBLEMS_ = " preprocessor problems."; //$NON-NLS-1$
|
||||
private static final String _PREPROCESSOR_STATEMENTS_ = " preprocessor statements."; //$NON-NLS-1$
|
||||
private static final String MERGING_ = "Merging "; //$NON-NLS-1$
|
||||
private static final String GROUPING_AST = "Grouping AST View according to includes."; //$NON-NLS-1$
|
||||
private static final String GENERATING_INITIAL_TREE = "Generating initial AST Tree for the View"; //$NON-NLS-1$
|
||||
private static final String PARSING_TRANSLATION_UNIT = "Parsing Translation Unit"; //$NON-NLS-1$
|
||||
String name = null;
|
||||
TreeParent root = null;
|
||||
ViewContentProvider provider = null;
|
||||
TreeViewer view = null;
|
||||
IFile file = null;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public InitializeView(String name, ViewContentProvider provider, TreeViewer view, IFile file) {
|
||||
super(name);
|
||||
this.name = name;
|
||||
setUser(true);
|
||||
this.provider = provider;
|
||||
this.view = view;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public TreeParent getInvisibleRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the scheduling rule for this operation
|
||||
*/
|
||||
public ISchedulingRule getScheduleRule() {
|
||||
return ResourcesPlugin.getWorkspace().getRoot();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
if (file == null || lang == null || monitor == null)
|
||||
return Status.CANCEL_STATUS;
|
||||
|
||||
if (monitor.isCanceled()) return Status.CANCEL_STATUS;
|
||||
monitor.beginTask(name, 5);
|
||||
|
||||
IPopulateDOMASTAction action = null;
|
||||
IASTTranslationUnit tu = null;
|
||||
try {
|
||||
monitor.subTask(PARSING_TRANSLATION_UNIT);
|
||||
tu = CDOM.getInstance().getASTService().getTranslationUnit(
|
||||
file,
|
||||
CDOM.getInstance().getCodeReaderFactory(
|
||||
CDOM.PARSE_SAVED_RESOURCES));
|
||||
monitor.worked(1);
|
||||
} catch (IASTServiceProvider.UnsupportedDialectException e) {
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
|
||||
if (monitor.isCanceled()) return Status.CANCEL_STATUS;
|
||||
monitor.subTask(GENERATING_INITIAL_TREE);
|
||||
if (lang == ParserLanguage.CPP) {
|
||||
action = new CPPPopulateASTViewAction(tu, monitor);
|
||||
CPPVisitor.visitTranslationUnit(tu, (CPPBaseVisitorAction) action);
|
||||
} else {
|
||||
action = new CPopulateASTViewAction(tu, monitor);
|
||||
CVisitor.visitTranslationUnit(tu, (CBaseVisitorAction) action);
|
||||
}
|
||||
monitor.worked(2);
|
||||
|
||||
// display roots
|
||||
root = new TreeParent(null); //$NON-NLS-1$
|
||||
|
||||
if (monitor.isCanceled()) return Status.CANCEL_STATUS;
|
||||
IASTPreprocessorStatement[] statements = tu.getAllPreprocessorStatements();
|
||||
monitor.subTask(MERGING_ + statements.length + _PREPROCESSOR_STATEMENTS_);
|
||||
// merge preprocessor statements to the tree
|
||||
action.mergePreprocessorStatements(statements);
|
||||
monitor.worked(3);
|
||||
|
||||
if (monitor.isCanceled()) return Status.CANCEL_STATUS;
|
||||
IASTProblem[] problems = tu.getPreprocesorProblems();
|
||||
monitor.subTask(MERGING_ + problems.length + _PREPROCESSOR_PROBLEMS_);
|
||||
// merge preprocessor problems to the tree
|
||||
action.mergePreprocessorProblems(problems);
|
||||
monitor.worked(4);
|
||||
|
||||
if (monitor.isCanceled()) return Status.CANCEL_STATUS;
|
||||
monitor.subTask(GROUPING_AST);
|
||||
// group #includes
|
||||
action.groupIncludes(statements);
|
||||
monitor.worked(5);
|
||||
|
||||
root.addChild(action.getTree());
|
||||
|
||||
provider.setInvisibleRoot(root);
|
||||
|
||||
monitor.done();
|
||||
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
invisibleRoot = new TreeParent(null); // blank the AST View, when the job above is complete it will update the AST View with the proper tree
|
||||
}
|
||||
|
||||
protected void setInvisibleRoot(TreeParent root) {
|
||||
invisibleRoot = root;
|
||||
}
|
||||
|
||||
public class InitializeRunnable implements Runnable {
|
||||
TreeViewer view = null;
|
||||
|
||||
public InitializeRunnable(TreeViewer view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
public void run() {
|
||||
view.refresh();
|
||||
|
||||
if (view.getTree().getItems().length > 0) {
|
||||
TreeItem[] selection = new TreeItem[1];
|
||||
selection[0] = view.getTree().getItems()[0];
|
||||
|
||||
// select the first item to prevent it from being selected accidentally (and possibly switching editors accidentally)
|
||||
view.getTree().setSelection(selection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
}
|
||||
}
|
||||
|
||||
class ViewLabelProvider extends LabelProvider {
|
||||
|
@ -305,41 +506,20 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
public void createPartControl(Composite parent) {
|
||||
|
||||
if (part == null) {
|
||||
IWorkbenchPage[] pages = PlatformUI.getWorkbench()
|
||||
.getActiveWorkbenchWindow().getPages();
|
||||
|
||||
if (pages.length == 0) {
|
||||
// TODO determine how to hide view if no pages found and part==null
|
||||
}
|
||||
|
||||
outerLoop: for (int i = 0; i < pages.length; i++) {
|
||||
IEditorReference[] editorRefs = pages[i].getEditorReferences();
|
||||
for (int j = 0; j < editorRefs.length; j++) {
|
||||
part = editorRefs[j].getEditor(false);
|
||||
if (part instanceof CEditor) {
|
||||
// TODO set the language properly if implement the above TODO
|
||||
lang = ParserLanguage.CPP;
|
||||
break outerLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage() != null
|
||||
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage().getActiveEditor() != null)
|
||||
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage().getActiveEditor();
|
||||
part = getActiveEditor();
|
||||
|
||||
if (!(part instanceof CEditor)) return;
|
||||
}
|
||||
|
||||
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
drillDownAdapter = new DrillDownAdapter(viewer);
|
||||
|
||||
if (part instanceof CEditor)
|
||||
viewer.setContentProvider(new ViewContentProvider(((CEditor) part)
|
||||
.getInputFile()));
|
||||
else
|
||||
if (part instanceof CEditor) {
|
||||
viewer.setContentProvider(new ViewContentProvider(((CEditor) part).getInputFile()));
|
||||
setFile(((CEditor) part).getInputFile());
|
||||
} else {
|
||||
viewer.setContentProvider(new ViewContentProvider(null)); // don't attempt to create a view based on old file info
|
||||
}
|
||||
|
||||
viewer.setLabelProvider(new ViewLabelProvider());
|
||||
viewer.setInput(getViewSite());
|
||||
|
@ -353,6 +533,7 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
|
||||
public void setContentProvider(ViewContentProvider vcp) {
|
||||
viewer.setContentProvider(vcp);
|
||||
|
||||
}
|
||||
|
||||
private void hookContextMenu() {
|
||||
|
@ -393,9 +574,6 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
}
|
||||
|
||||
private void fillLocalPullDown(IMenuManager manager) {
|
||||
// manager.add(action1); // TODO determine the groups/filters to use
|
||||
// manager.add(new Separator());
|
||||
// manager.add(action2);
|
||||
}
|
||||
|
||||
void fillContextMenu(IMenuManager manager) {
|
||||
|
@ -408,7 +586,7 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
}
|
||||
|
||||
private void fillLocalToolBar(IToolBarManager manager) {
|
||||
manager.add(expandAllAction);
|
||||
manager.add(expandAllAction);
|
||||
manager.add(collapseAllAction);
|
||||
manager.add(new Separator());
|
||||
manager.add(refreshAction);
|
||||
|
@ -416,6 +594,8 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
manager.add(new Separator());
|
||||
manager.add(clearAction);
|
||||
manager.add(new Separator());
|
||||
manager.add(searchNamesAction);
|
||||
manager.add(new Separator());
|
||||
drillDownAdapter.addNavigationActions(manager);
|
||||
}
|
||||
|
||||
|
@ -423,19 +603,7 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
loadActiveEditorAction = new Action() {
|
||||
public void run() {
|
||||
// get the active editor
|
||||
IEditorPart editor = null;
|
||||
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null &&
|
||||
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages() != null) {
|
||||
IWorkbenchPage[] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
|
||||
|
||||
outerLoop: for(int i=0; i<pages.length; i++) {
|
||||
editor = pages[i].getActiveEditor();
|
||||
if (editor instanceof CEditor) {
|
||||
break outerLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEditorPart editor = getActiveEditor();
|
||||
if (editor instanceof CEditor) {
|
||||
IViewPart tempView = null;
|
||||
|
||||
|
@ -456,15 +624,7 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
|
||||
((DOMAST)tempView).setFile(aFile);
|
||||
((DOMAST)tempView).setPart(editor);
|
||||
|
||||
IProject project = aFile.getProject();
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(project, aFile.getFullPath().lastSegment());
|
||||
String lid = type.getLanguage().getId();
|
||||
if ( lid != null && lid.equals(ICFileTypeConstants.LANG_CXX) ) {
|
||||
((DOMAST)tempView).setLang(ParserLanguage.CPP);
|
||||
} else {
|
||||
((DOMAST)tempView).setLang(ParserLanguage.C);
|
||||
}
|
||||
((DOMAST)tempView).setLang(getLanguageFromFile(aFile));
|
||||
((DOMAST)tempView).setContentProvider(((DOMAST)tempView).new ViewContentProvider(((CEditor)editor).getInputFile()));
|
||||
}
|
||||
}
|
||||
|
@ -478,32 +638,12 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
loadActiveEditorAction.setImageDescriptor(DOMASTPluginImages.DESC_DEFAULT);
|
||||
|
||||
refreshAction = new Action() {
|
||||
private void expandTreeIfNecessary(TreeItem[] tree, Object[] expanded) {
|
||||
for( int i=0; i<tree.length; i++) {
|
||||
for( int j=0; j<expanded.length; j++) {
|
||||
if (expanded[j] instanceof TreeObject &&
|
||||
tree[i].getData() instanceof TreeObject &&
|
||||
((TreeObject)expanded[j]).toString().equals(((TreeObject)tree[i].getData()).toString()) &&
|
||||
((TreeObject)expanded[j]).getOffset() == (((TreeObject)tree[i].getData()).getOffset())) {
|
||||
tree[i].setExpanded(true);
|
||||
viewer.refresh();
|
||||
expandTreeIfNecessary(tree[i].getItems(), expanded);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// take a snapshot of the tree expansion
|
||||
Object[] expanded = viewer.getExpandedElements();
|
||||
|
||||
|
||||
// set the new content provider
|
||||
setContentProvider(new ViewContentProvider(file));
|
||||
|
||||
// set the expansion of the view based on the original snapshot (educated guess)
|
||||
Tree tree = viewer.getTree();
|
||||
expandTreeIfNecessary(tree.getItems(), expanded);
|
||||
|
||||
setContentProvider(new ViewContentProvider(file, expanded));
|
||||
}
|
||||
};
|
||||
refreshAction.setText(REFRESH_DOM_AST);
|
||||
|
@ -538,6 +678,24 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
clearAction.setToolTipText(CLEAR);
|
||||
clearAction.setImageDescriptor(DOMASTPluginImages.DESC_CLEAR);
|
||||
|
||||
searchNamesAction = new Action() {
|
||||
private void performSearch() {
|
||||
if (viewer.getTree().getItems().length == 0) {
|
||||
showMessage(DOM_AST_HAS_NO_CONTENT);
|
||||
}
|
||||
|
||||
FindIASTNameDialog dialog = new FindIASTNameDialog(getSite().getShell(), new FindIASTNameTarget(viewer, lang));
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
performSearch();
|
||||
}
|
||||
};
|
||||
searchNamesAction.setText(SEARCH_FOR_IASTNAME);
|
||||
searchNamesAction.setToolTipText(SEARCH_FOR_IASTNAME);
|
||||
searchNamesAction.setImageDescriptor(DOMASTPluginImages.DESC_SEARCH_NAMES);
|
||||
|
||||
openDeclarationsAction = new DisplayDeclarationsAction();
|
||||
openDeclarationsAction.setText(OPEN_DECLARATIONS);
|
||||
openDeclarationsAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
||||
|
@ -551,6 +709,29 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
singleClickAction = new ASTHighlighterAction(part);
|
||||
}
|
||||
|
||||
private IEditorPart getActiveEditor() {
|
||||
IEditorPart editor = null;
|
||||
|
||||
if (getSite().getPage().isEditorAreaVisible()) {
|
||||
editor = getSite().getPage().getActiveEditor();
|
||||
part = editor;
|
||||
lang = lang = getLanguageFromFile(((CEditor)editor).getInputFile());
|
||||
}
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
private ParserLanguage getLanguageFromFile(IFile file) {
|
||||
IProject project = file.getProject();
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(project, file.getFullPath().lastSegment());
|
||||
String lid = type.getLanguage().getId();
|
||||
if ( lid != null && lid.equals(ICFileTypeConstants.LANG_CXX) ) {
|
||||
return ParserLanguage.CPP;
|
||||
}
|
||||
|
||||
return ParserLanguage.C;
|
||||
}
|
||||
|
||||
private class ASTHighlighterAction extends Action {
|
||||
IEditorPart aPart = null;
|
||||
|
||||
|
@ -668,51 +849,6 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
NewSearchUI.runQuery(job);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO need to create a new action with the following for annotations (get
|
||||
// declarations/references)
|
||||
// ISelection selection = viewer.getSelection();
|
||||
// Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||
//
|
||||
// if (aPart instanceof CEditor) {
|
||||
// IAnnotationModel aModel =
|
||||
// ((CEditor)aPart).getDocumentProvider().getAnnotationModel(aPart.getEditorInput());
|
||||
// if ( aModel != null && obj instanceof TreeObject &&
|
||||
// !(((TreeObject)obj).getNode() instanceof IASTTranslationUnit) ) {
|
||||
// Iterator itr = aModel.getAnnotationIterator();
|
||||
// while (itr.hasNext()) {
|
||||
// aModel.removeAnnotation((Annotation)itr.next());
|
||||
// }
|
||||
//
|
||||
// ASTViewAnnotation annotation = new ASTViewAnnotation();
|
||||
// annotation.setType(CMarkerAnnotation.WARNING_ANNOTATION_TYPE);
|
||||
// aModel.addAnnotation(annotation, new
|
||||
// Position(((TreeObject)obj).getOffset(), ((TreeObject)obj).getLength()));
|
||||
// }
|
||||
// }
|
||||
|
||||
// TODO implement annotation for things like open declarations/references
|
||||
// private class ASTViewAnnotation extends Annotation implements
|
||||
// IAnnotationPresentation {
|
||||
//
|
||||
// /* (non-Javadoc)
|
||||
// * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
|
||||
// */
|
||||
// public int getLayer() {
|
||||
// return IAnnotationAccessExtension.DEFAULT_LAYER;
|
||||
// }
|
||||
//
|
||||
// /* (non-Javadoc)
|
||||
// * @see
|
||||
// org.eclipse.jface.text.source.IAnnotationPresentation#paint(org.eclipse.swt.graphics.GC,
|
||||
// org.eclipse.swt.widgets.Canvas, org.eclipse.swt.graphics.Rectangle)
|
||||
// */
|
||||
// public void paint(GC gc, Canvas canvas, Rectangle r) {
|
||||
// // TODO implement this annotation image for
|
||||
// ImageUtilities.drawImage(ASTViewPluginImages.get(ASTViewPluginImages.IMG_TO_DRAW),
|
||||
// gc, canvas, r, SWT.CENTER, SWT.TOP);
|
||||
// }
|
||||
// }
|
||||
|
||||
private void hookSingleClickAction() {
|
||||
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
|
@ -734,11 +870,6 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
viewer.getControl().setFocus();
|
||||
}
|
||||
|
||||
public void setFile(IFile file) {
|
||||
this.file = file;
|
||||
viewer.setContentProvider(new ViewContentProvider(file));
|
||||
}
|
||||
|
||||
public void setPart(IEditorPart part) {
|
||||
this.part = part;
|
||||
|
||||
|
@ -749,5 +880,9 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
public void setLang(ParserLanguage lang) {
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public void setFile(IFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
}
|
|
@ -75,6 +75,7 @@ public class DOMASTPluginImages {
|
|||
public static final String IMG_EXPAND_ALL = NAME_PREFIX + "expandall.gif"; //$NON-NLS-1$
|
||||
public static final String IMG_COLLAPSE_ALL = NAME_PREFIX + "collapseall.gif"; //$NON-NLS-1$
|
||||
public static final String IMG_CLEAR = NAME_PREFIX + "clear.gif"; //$NON-NLS-1$
|
||||
public static final String IMG_SEARCH_NAMES = NAME_PREFIX + "search_ref_obj.gif"; //$NON-NLS-1$
|
||||
|
||||
public static final ImageDescriptor DESC_IASTArrayModifier= createManaged(ICON_PREFIX, IMG_IASTArrayModifier);
|
||||
public static final ImageDescriptor DESC_IASTDeclaration= createManaged(ICON_PREFIX, IMG_IASTDeclaration);
|
||||
|
@ -99,6 +100,7 @@ public class DOMASTPluginImages {
|
|||
public static final ImageDescriptor DESC_EXPAND_ALL= createManaged(ICON_PREFIX, IMG_EXPAND_ALL);
|
||||
public static final ImageDescriptor DESC_COLLAPSE_ALL= createManaged(ICON_PREFIX, IMG_COLLAPSE_ALL);
|
||||
public static final ImageDescriptor DESC_CLEAR= createManaged(ICON_PREFIX, IMG_CLEAR);
|
||||
public static final ImageDescriptor DESC_SEARCH_NAMES= createManaged(ICON_PREFIX, IMG_SEARCH_NAMES);
|
||||
|
||||
private static ImageDescriptor createManaged(String prefix, String name) {
|
||||
return createManaged(imageRegistry, prefix, name);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,444 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
||||
import org.eclipse.jface.text.IFindReplaceTarget;
|
||||
import org.eclipse.jface.text.IFindReplaceTargetExtension3;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.widgets.TreeItem;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
*/
|
||||
public class FindIASTNameTarget implements IFindReplaceTarget, IFindReplaceTargetExtension3 {
|
||||
|
||||
IASTTranslationUnit tu = null;
|
||||
TreeParent tuTreeParent = null;
|
||||
ParserLanguage lang = null;
|
||||
TreeViewer viewer = null;
|
||||
TreeObject startingNode = null;
|
||||
IASTName[] matchingNames = null;
|
||||
boolean wasForward = true;
|
||||
int index = 0;
|
||||
|
||||
static protected class CNameCollector extends CVisitor.CBaseVisitorAction {
|
||||
private static final int REGULAR_NAME_ADD = -1;
|
||||
private static final String BLANK_STRING = ""; //$NON-NLS-1$
|
||||
{
|
||||
processNames = true;
|
||||
}
|
||||
public List nameList = new ArrayList();
|
||||
|
||||
String findString = null;
|
||||
boolean caseSensitive = true;
|
||||
boolean wholeWord = true;
|
||||
boolean regExSearch = false;
|
||||
|
||||
public CNameCollector(String findString, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
|
||||
this.findString = findString;
|
||||
this.caseSensitive = caseSensitive;
|
||||
this.wholeWord = wholeWord;
|
||||
this.regExSearch = regExSearch;
|
||||
}
|
||||
|
||||
public int processName( IASTName name, int offset) {
|
||||
if (name.toString() == null || name.toString() == BLANK_STRING) return PROCESS_CONTINUE;
|
||||
String searchString = null;
|
||||
String match = null;
|
||||
boolean addName = false;
|
||||
|
||||
if (caseSensitive) {
|
||||
searchString = findString;
|
||||
match = name.toString();
|
||||
} else {
|
||||
searchString = findString.toUpperCase();
|
||||
match = name.toString().toUpperCase();
|
||||
}
|
||||
|
||||
if (regExSearch) {
|
||||
if (match.matches(searchString))
|
||||
addName = true;
|
||||
} else if (!wholeWord) {
|
||||
if (match.indexOf(searchString) >= 0)
|
||||
addName = true;
|
||||
} else {
|
||||
if (match.equals(searchString))
|
||||
addName = true;
|
||||
}
|
||||
|
||||
if (addName) {
|
||||
if (offset >= 0)
|
||||
nameList.add(offset, name);
|
||||
else
|
||||
nameList.add( name );
|
||||
}
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public int processName( IASTName name ){
|
||||
return processName(name, REGULAR_NAME_ADD);
|
||||
}
|
||||
public IASTName getName( int idx ){
|
||||
if( idx < 0 || idx >= nameList.size() )
|
||||
return null;
|
||||
return (IASTName) nameList.get( idx );
|
||||
}
|
||||
public int size() { return nameList.size(); }
|
||||
|
||||
private void mergeName(IASTName name) {
|
||||
if (name instanceof ASTNode) {
|
||||
int offset = ((ASTNode)name).getOffset();
|
||||
for( int i=0; i<nameList.size(); i++) {
|
||||
if (nameList.get(i) instanceof ASTNode &&
|
||||
((ASTNode)nameList.get(i)).getOffset() > offset) {
|
||||
processName(name, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if couldn't find the proper place to put the name, then add default
|
||||
processName(name);
|
||||
}
|
||||
}
|
||||
|
||||
public IASTName[] getNameArray(IASTPreprocessorStatement[] statements) {
|
||||
// first merge all of the preprocessor names into the array list
|
||||
for(int i=0; i<statements.length; i++) {
|
||||
if (statements[i] instanceof IASTPreprocessorMacroDefinition) {
|
||||
IASTName name = ((IASTPreprocessorMacroDefinition)statements[i]).getName();
|
||||
if (name != null) {
|
||||
mergeName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// convert the array list into an array of IASTNames
|
||||
IASTName[] namedArray = new IASTName[nameList.size()];
|
||||
|
||||
for(int i=0; i<nameList.size(); i++) {
|
||||
if (nameList.get(i) instanceof IASTName)
|
||||
namedArray[i] = (IASTName)nameList.get(i);
|
||||
}
|
||||
|
||||
return namedArray;
|
||||
}
|
||||
}
|
||||
|
||||
static protected class CPPNameCollector extends CPPVisitor.CPPBaseVisitorAction {
|
||||
private static final int REGULAR_NAME_ADD = -1;
|
||||
private static final String BLANK_STRING = ""; //$NON-NLS-1$
|
||||
{
|
||||
processNames = true;
|
||||
}
|
||||
public List nameList = new ArrayList();
|
||||
|
||||
String findString = null;
|
||||
boolean caseSensitive = true;
|
||||
boolean wholeWord = true;
|
||||
boolean regExSearch = false;
|
||||
Pattern p = null;
|
||||
Matcher m = null;
|
||||
|
||||
public CPPNameCollector(String findString, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
|
||||
this.findString = findString;
|
||||
this.caseSensitive = caseSensitive;
|
||||
this.wholeWord = wholeWord;
|
||||
this.regExSearch = regExSearch;
|
||||
}
|
||||
|
||||
public int processName( IASTName name, int index) {
|
||||
if (name.toString() == null || name.toString() == BLANK_STRING) return PROCESS_CONTINUE;
|
||||
String searchString = null;
|
||||
String match = null;
|
||||
boolean addName = false;
|
||||
|
||||
if (caseSensitive) {
|
||||
searchString = findString;
|
||||
match = name.toString();
|
||||
} else {
|
||||
searchString = findString.toUpperCase();
|
||||
match = name.toString().toUpperCase();
|
||||
}
|
||||
|
||||
if (regExSearch) {
|
||||
if (match.matches(searchString))
|
||||
addName = true;
|
||||
} else if (!wholeWord) {
|
||||
if (match.indexOf(searchString) >= 0)
|
||||
addName = true;
|
||||
} else {
|
||||
if (match.equals(searchString))
|
||||
addName = true;
|
||||
}
|
||||
|
||||
if (addName) {
|
||||
if (index >= 0)
|
||||
nameList.add(index, name);
|
||||
else
|
||||
nameList.add( name );
|
||||
}
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public int processName( IASTName name ){
|
||||
return processName(name, REGULAR_NAME_ADD);
|
||||
}
|
||||
public IASTName getName( int idx ){
|
||||
if( idx < 0 || idx >= nameList.size() )
|
||||
return null;
|
||||
return (IASTName) nameList.get( idx );
|
||||
}
|
||||
public int size() { return nameList.size(); }
|
||||
|
||||
private void mergeName(IASTName name) {
|
||||
if (name instanceof ASTNode) {
|
||||
int offset = ((ASTNode)name).getOffset();
|
||||
for( int i=0; i<nameList.size(); i++) {
|
||||
if (nameList.get(i) instanceof ASTNode &&
|
||||
((ASTNode)nameList.get(i)).getOffset() > offset) {
|
||||
processName(name, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if couldn't find the proper place to put the name, then add default
|
||||
processName(name);
|
||||
}
|
||||
}
|
||||
|
||||
public IASTName[] getNameArray(IASTPreprocessorStatement[] statements) {
|
||||
// first merge all of the preprocessor names into the array list
|
||||
for(int i=0; i<statements.length; i++) {
|
||||
if (statements[i] instanceof IASTPreprocessorMacroDefinition) {
|
||||
IASTName name = ((IASTPreprocessorMacroDefinition)statements[i]).getName();
|
||||
if (name != null) {
|
||||
mergeName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// convert the array list into an array of IASTNames
|
||||
IASTName[] namedArray = new IASTName[nameList.size()];
|
||||
|
||||
for(int i=0; i<nameList.size(); i++) {
|
||||
if (nameList.get(i) instanceof IASTName)
|
||||
namedArray[i] = (IASTName)nameList.get(i);
|
||||
}
|
||||
|
||||
return namedArray;
|
||||
}
|
||||
}
|
||||
|
||||
public FindIASTNameTarget(TreeViewer viewer, ParserLanguage lang) {
|
||||
if (viewer.getContentProvider() instanceof DOMAST.ViewContentProvider) {
|
||||
tu = ((DOMAST.ViewContentProvider)viewer.getContentProvider()).getTU();
|
||||
tuTreeParent = ((DOMAST.ViewContentProvider)viewer.getContentProvider()).getTUTreeParent();
|
||||
}
|
||||
|
||||
this.viewer = viewer;
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.text.IFindReplaceTarget#canPerformFind()
|
||||
*/
|
||||
public boolean canPerformFind() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// recursively search for the next node
|
||||
public IASTName findNextMatchingName(String findString,
|
||||
boolean searchForward, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
|
||||
|
||||
if (matchingNames == null && tu != null) {
|
||||
if (lang == ParserLanguage.CPP) {
|
||||
CPPNameCollector col = new CPPNameCollector(findString, caseSensitive, wholeWord, regExSearch);
|
||||
CPPVisitor.visitTranslationUnit(tu, col);
|
||||
matchingNames = col.getNameArray(tu.getAllPreprocessorStatements());
|
||||
} else {
|
||||
CNameCollector col = new CNameCollector(findString, caseSensitive, wholeWord, regExSearch);
|
||||
CVisitor.visitTranslationUnit(tu, col);
|
||||
matchingNames = col.getNameArray(tu.getAllPreprocessorStatements());
|
||||
}
|
||||
}
|
||||
|
||||
if (searchForward) {
|
||||
if (!wasForward) {
|
||||
wasForward = true;
|
||||
index+=2;
|
||||
}
|
||||
|
||||
if (index >=0 && index < matchingNames.length && matchingNames[index] != null)
|
||||
return matchingNames[index++];
|
||||
} else {
|
||||
if (wasForward) {
|
||||
wasForward = false;
|
||||
index-=2;
|
||||
}
|
||||
|
||||
if (index >= 0 && index < matchingNames.length && matchingNames[index] != null)
|
||||
return matchingNames[index--];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private TreeItem expandTreeToTreeObject(TreeItem[] treeItems, TreeObject treeObj) {
|
||||
for (int i=0; i<treeItems.length; i++) {
|
||||
if (treeItems[i].getData() == treeObj) {
|
||||
return treeItems[i];
|
||||
}
|
||||
|
||||
TreeParent parent = treeObj.getParent();
|
||||
|
||||
if (parent == null) return null;
|
||||
|
||||
while (parent != treeItems[i].getData()) {
|
||||
parent = parent.getParent();
|
||||
if (parent == null) break;
|
||||
}
|
||||
|
||||
if (parent == treeItems[i].getData()) {
|
||||
treeItems[i].setExpanded(true);
|
||||
viewer.refresh();
|
||||
|
||||
return expandTreeToTreeObject(treeItems[i].getItems(), treeObj);
|
||||
}
|
||||
}
|
||||
|
||||
return null; // nothing found
|
||||
}
|
||||
|
||||
private TreeItem expandTreeToTreeObject(TreeObject treeObj) {
|
||||
return expandTreeToTreeObject(viewer.getTree().getItems(), treeObj);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.text.IFindReplaceTarget#findAndSelect(int, java.lang.String, boolean, boolean, boolean)
|
||||
*/
|
||||
public int findAndSelect(int widgetOffset, String findString,
|
||||
boolean searchForward, boolean caseSensitive, boolean wholeWord) {
|
||||
return findAndSelect(widgetOffset, findString, searchForward, caseSensitive, wholeWord, false);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.text.IFindReplaceTarget#getSelection()
|
||||
*/
|
||||
public Point getSelection() {
|
||||
IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
|
||||
|
||||
if (selection.isEmpty()) {
|
||||
if (viewer.getTree().getItems()[0].getData() instanceof TreeObject);
|
||||
startingNode = (TreeObject)viewer.getTree().getItems()[0].getData();
|
||||
|
||||
return new Point(0, 0);
|
||||
}
|
||||
|
||||
startingNode = (TreeObject)selection.getFirstElement();
|
||||
return new Point(((ASTNode)((TreeObject)selection.getFirstElement()).getNode()).getOffset(), 0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.text.IFindReplaceTarget#getSelectionText()
|
||||
*/
|
||||
public String getSelectionText() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.text.IFindReplaceTarget#isEditable()
|
||||
*/
|
||||
public boolean isEditable() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.text.IFindReplaceTarget#replaceSelection(java.lang.String)
|
||||
*/
|
||||
public void replaceSelection(String text) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void clearMatchingNames() {
|
||||
matchingNames = null;
|
||||
index = 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.text.IFindReplaceTargetExtension3#findAndSelect(int, java.lang.String, boolean, boolean, boolean, boolean)
|
||||
*/
|
||||
public int findAndSelect(int offset, String findString, boolean searchForward, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
|
||||
// find the next name in the list of names
|
||||
IASTName foundName = null;
|
||||
foundName = findNextMatchingName( findString, searchForward, caseSensitive, wholeWord, regExSearch );
|
||||
|
||||
// get the TreeObject from the AST View's model corresponding to that name
|
||||
TreeObject treeNode = null;
|
||||
TreeItem treeItem = null;
|
||||
treeNode = tuTreeParent.findTreeObjectForIASTName(foundName);
|
||||
|
||||
if (treeNode != null && treeNode.getParent() != null) {
|
||||
// found a matching TreeObject, so expand the tree to that object
|
||||
treeItem = expandTreeToTreeObject(treeNode); // TODO Devin test this
|
||||
}
|
||||
|
||||
// loop until the next name within the matchingNames list is found in the tree
|
||||
while ((treeNode == null || treeItem == null) && matchingNames.length > 0 &&
|
||||
((searchForward && index < matchingNames.length) ||
|
||||
(!searchForward && index >= 0))) {
|
||||
foundName = findNextMatchingName( findString, searchForward, caseSensitive, wholeWord, regExSearch );
|
||||
treeNode = tuTreeParent.findTreeObjectForIASTName(foundName);
|
||||
|
||||
if (treeNode != null && treeNode.getParent() != null) {
|
||||
// found a matching TreeObject, so expand the tree to that object
|
||||
treeItem = expandTreeToTreeObject(treeNode); // TODO Devin test this
|
||||
}
|
||||
}
|
||||
|
||||
// select the node that was found (and is now displayed)
|
||||
if (treeItem != null) {
|
||||
TreeItem[] items = new TreeItem[1];
|
||||
items[0] = treeItem;
|
||||
treeItem.getParent().setSelection(items);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.text.IFindReplaceTargetExtension3#replaceSelection(java.lang.String, boolean)
|
||||
*/
|
||||
public void replaceSelection(String text, boolean regExReplace) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -10,9 +10,15 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
*/
|
||||
public interface IPopulateDOMASTAction {
|
||||
public TreeParent getTree();
|
||||
public void mergePreprocessorStatements(IASTPreprocessorStatement[] statements);
|
||||
public void mergePreprocessorProblems(IASTProblem[] problems);
|
||||
public void groupIncludes(IASTPreprocessorStatement[] statements);
|
||||
}
|
||||
|
|
|
@ -13,15 +13,15 @@ package org.eclipse.cdt.ui.tests.DOMAST;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
*/
|
||||
public class TreeParent extends TreeObject {
|
||||
private ArrayList children; // TODO might want to use a HashTable/HashMap or wrap one so finding the parent node is faster
|
||||
private ArrayList children;
|
||||
|
||||
public TreeParent(IASTNode node) {
|
||||
super(node);
|
||||
|
@ -168,5 +168,67 @@ public class TreeParent extends TreeObject {
|
|||
|
||||
return null; // nothing found
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the TreeParent that corresponds to the IASTName. This is based on string and offset equality.
|
||||
*
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
public TreeParent findTreeObjectForIASTName(IASTName name) {
|
||||
if (name == null) return null;
|
||||
|
||||
Iterator itr = children.iterator();
|
||||
while (itr.hasNext()) {
|
||||
Object o = itr.next();
|
||||
if (o != null && o instanceof TreeParent) {
|
||||
if (treeParentHasName((TreeParent)o, name)) return (TreeParent)o;
|
||||
|
||||
if ( ((TreeParent)o).hasChildren() ){
|
||||
TreeParent tree = findTreeObjectForIASTName( ((TreeParent)o).getChildren(), name );
|
||||
if (tree != null) return tree;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null; // nothing found
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the TreeParent that corresponds to the IASTName. This is based on string and offset equality.
|
||||
*
|
||||
* @param trees
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
private TreeParent findTreeObjectForIASTName(TreeObject[] trees, IASTName name) {
|
||||
for (int i=0; i<trees.length; i++) {
|
||||
|
||||
if (trees[i] != null && trees[i] instanceof TreeParent) {
|
||||
if (treeParentHasName((TreeParent)trees[i], name)) return (TreeParent)trees[i];
|
||||
|
||||
if ( ((TreeParent)trees[i]).hasChildren() ){
|
||||
TreeParent tree = findTreeObjectForIASTName( ((TreeParent)trees[i]).getChildren(), name );
|
||||
if (tree != null) return tree;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null; // nothing found
|
||||
}
|
||||
|
||||
private boolean treeParentHasName(TreeParent tp, IASTName name) {
|
||||
if ( tp.getNode() instanceof IASTName &&
|
||||
tp.getNode() instanceof ASTNode &&
|
||||
name instanceof ASTNode) {
|
||||
IASTName treeName = (IASTName)tp.getNode();
|
||||
ASTNode treeNode = (ASTNode)tp.getNode();
|
||||
if (treeName.toString().equals(name.toString()) && treeNode.getOffset() == ((ASTNode)name).getOffset() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue