mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Cosmetics.
This commit is contained in:
parent
c20748bf30
commit
5bd1220fc8
1 changed files with 56 additions and 117 deletions
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Rational Software - Initial API and implementation
|
* IBM Rational Software - Initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.DOMAST;
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
*/
|
*/
|
||||||
public class CPopulateASTViewAction extends ASTVisitor implements IPopulateDOMASTAction {
|
public class CPopulateASTViewAction extends ASTVisitor implements IPopulateDOMASTAction {
|
||||||
private static final int INITIAL_PROBLEM_SIZE = 4;
|
private static final int INITIAL_PROBLEM_SIZE = 4;
|
||||||
|
|
||||||
{
|
{
|
||||||
shouldVisitNames = true;
|
shouldVisitNames = true;
|
||||||
shouldVisitDeclarations = true;
|
shouldVisitDeclarations = true;
|
||||||
|
@ -57,8 +58,8 @@ public class CPopulateASTViewAction extends ASTVisitor implements IPopulateDOMAS
|
||||||
shouldVisitEnumerators = true;
|
shouldVisitEnumerators = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DOMASTNodeParent root = null;
|
DOMASTNodeParent root;
|
||||||
IProgressMonitor monitor = null;
|
IProgressMonitor monitor;
|
||||||
IASTProblem[] astProblems = new IASTProblem[INITIAL_PROBLEM_SIZE];
|
IASTProblem[] astProblems = new IASTProblem[INITIAL_PROBLEM_SIZE];
|
||||||
|
|
||||||
public CPopulateASTViewAction(IASTTranslationUnit tu, IProgressMonitor monitor) {
|
public CPopulateASTViewAction(IASTTranslationUnit tu, IProgressMonitor monitor) {
|
||||||
|
@ -73,24 +74,24 @@ public class CPopulateASTViewAction extends ASTVisitor implements IPopulateDOMAS
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return null if the algorithm should stop (monitor was cancelled)
|
* Returns {@code null} if the algorithm should stop (monitor was cancelled).
|
||||||
* return DOMASTNodeLeafContinue if the algorithm should continue but no valid DOMASTNodeLeaf was added (i.e. node was null
|
* Returns DOMASTNodeLeafContinue if the algorithm should continue but no valid DOMASTNodeLeaf
|
||||||
* return the DOMASTNodeLeaf added to the DOM AST View's model otherwise
|
* was added (i.e. node was {@code null}). Return the DOMASTNodeLeaf added to the DOM AST view's
|
||||||
*
|
* model otherwise
|
||||||
* @param node
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private DOMASTNodeLeaf addRoot(IASTNode node) {
|
private DOMASTNodeLeaf addRoot(IASTNode node) {
|
||||||
if (monitor != null && monitor.isCanceled()) return null;
|
if (monitor != null && monitor.isCanceled())
|
||||||
if (node == null) return new DOMASTNodeLeafContinue(null);
|
return null;
|
||||||
|
if (node == null)
|
||||||
|
return new DOMASTNodeLeafContinue(null);
|
||||||
|
|
||||||
// only do length check for ASTNode (getNodeLocations on PreprocessorStatements is very expensive)
|
// Only do length check for ASTNode (getNodeLocations on PreprocessorStatements is very expensive).
|
||||||
if (node instanceof ASTNode && ((ASTNode)node).getLength() <= 0)
|
if (node instanceof ASTNode && ((ASTNode) node).getLength() <= 0)
|
||||||
return new DOMASTNodeLeafContinue(null);
|
return new DOMASTNodeLeafContinue(null);
|
||||||
|
|
||||||
DOMASTNodeParent parent = null;
|
DOMASTNodeParent parent = null;
|
||||||
|
|
||||||
// if it's a preprocessor statement being merged then do a special search for parent (no search)
|
// If it's a preprocessor statement being merged then do a special search for parent (no search).
|
||||||
if (node instanceof IASTPreprocessorStatement) {
|
if (node instanceof IASTPreprocessorStatement) {
|
||||||
parent = root;
|
parent = root;
|
||||||
} else {
|
} else {
|
||||||
|
@ -116,10 +117,11 @@ public class CPopulateASTViewAction extends ASTVisitor implements IPopulateDOMAS
|
||||||
if (node instanceof IASTProblemHolder || node instanceof IASTProblem) {
|
if (node instanceof IASTProblemHolder || node instanceof IASTProblem) {
|
||||||
tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PROBLEM);
|
tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PROBLEM);
|
||||||
|
|
||||||
if (node instanceof IASTProblemHolder)
|
if (node instanceof IASTProblemHolder) {
|
||||||
astProblems = ArrayUtil.append(IASTProblem.class, astProblems, ((IASTProblemHolder) node).getProblem());
|
astProblems = ArrayUtil.append(astProblems, ((IASTProblemHolder) node).getProblem());
|
||||||
else
|
} else {
|
||||||
astProblems = ArrayUtil.append(IASTProblem.class, astProblems, (IASTProblem) node);
|
astProblems = ArrayUtil.append(astProblems, (IASTProblem) node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (node instanceof IASTPreprocessorStatement)
|
if (node instanceof IASTPreprocessorStatement)
|
||||||
tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PREPROCESSOR);
|
tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PREPROCESSOR);
|
||||||
|
@ -129,181 +131,115 @@ public class CPopulateASTViewAction extends ASTVisitor implements IPopulateDOMAS
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTDeclaration declaration) {
|
public int visit(IASTDeclaration declaration) {
|
||||||
DOMASTNodeLeaf temp = addRoot(declaration);
|
DOMASTNodeLeaf temp = addRoot(declaration);
|
||||||
if (temp == null)
|
if (temp == null)
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
else if (temp instanceof DOMASTNodeLeafContinue)
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
else
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTDeclarator declarator) {
|
public int visit(IASTDeclarator declarator) {
|
||||||
DOMASTNodeLeaf temp = addRoot(declarator);
|
DOMASTNodeLeaf temp = addRoot(declarator);
|
||||||
|
|
||||||
IASTPointerOperator[] ops = declarator.getPointerOperators();
|
IASTPointerOperator[] ops = declarator.getPointerOperators();
|
||||||
for (IASTPointerOperator op : ops)
|
for (IASTPointerOperator op : ops) {
|
||||||
addRoot(op);
|
addRoot(op);
|
||||||
|
}
|
||||||
|
|
||||||
if (declarator instanceof IASTArrayDeclarator) {
|
if (declarator instanceof IASTArrayDeclarator) {
|
||||||
IASTArrayModifier[] mods = ((IASTArrayDeclarator)declarator).getArrayModifiers();
|
IASTArrayModifier[] mods = ((IASTArrayDeclarator)declarator).getArrayModifiers();
|
||||||
for (IASTArrayModifier mod : mods)
|
for (IASTArrayModifier mod : mods) {
|
||||||
addRoot(mod);
|
addRoot(mod);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temp == null)
|
if (temp == null)
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
else if (temp instanceof DOMASTNodeLeafContinue)
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
else
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(ICASTDesignator designator) {
|
public int visit(ICASTDesignator designator) {
|
||||||
DOMASTNodeLeaf temp = addRoot(designator);
|
DOMASTNodeLeaf temp = addRoot(designator);
|
||||||
if (temp == null)
|
if (temp == null)
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
else if (temp instanceof DOMASTNodeLeafContinue)
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
else
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTDeclSpecifier declSpec) {
|
public int visit(IASTDeclSpecifier declSpec) {
|
||||||
DOMASTNodeLeaf temp = addRoot(declSpec);
|
DOMASTNodeLeaf temp = addRoot(declSpec);
|
||||||
if (temp == null)
|
if (temp == null)
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
else if (temp instanceof DOMASTNodeLeafContinue)
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
else
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTEnumerator enumerator) {
|
public int visit(IASTEnumerator enumerator) {
|
||||||
DOMASTNodeLeaf temp = addRoot(enumerator);
|
DOMASTNodeLeaf temp = addRoot(enumerator);
|
||||||
if (temp == null)
|
if (temp == null)
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
else if (temp instanceof DOMASTNodeLeafContinue)
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
else
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTExpression expression) {
|
public int visit(IASTExpression expression) {
|
||||||
DOMASTNodeLeaf temp = addRoot(expression);
|
DOMASTNodeLeaf temp = addRoot(expression);
|
||||||
if (temp == null)
|
if (temp == null)
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
else if (temp instanceof DOMASTNodeLeafContinue)
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
else
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTInitializer initializer) {
|
public int visit(IASTInitializer initializer) {
|
||||||
DOMASTNodeLeaf temp = addRoot(initializer);
|
DOMASTNodeLeaf temp = addRoot(initializer);
|
||||||
if (temp == null)
|
if (temp == null)
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
else if (temp instanceof DOMASTNodeLeafContinue)
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
else
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTName name) {
|
public int visit(IASTName name) {
|
||||||
DOMASTNodeLeaf temp = null;
|
DOMASTNodeLeaf temp = null;
|
||||||
if ( name.toString() != null )
|
if (name.toString() == null)
|
||||||
temp = addRoot(name);
|
|
||||||
else
|
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
|
temp = addRoot(name);
|
||||||
if (temp == null)
|
if (temp == null)
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
else if (temp instanceof DOMASTNodeLeafContinue)
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
else
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(
|
public int visit(IASTParameterDeclaration parameterDeclaration) {
|
||||||
IASTParameterDeclaration parameterDeclaration) {
|
|
||||||
DOMASTNodeLeaf temp = addRoot(parameterDeclaration);
|
DOMASTNodeLeaf temp = addRoot(parameterDeclaration);
|
||||||
if (temp == null)
|
if (temp == null)
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
else if (temp instanceof DOMASTNodeLeafContinue)
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
else
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTStatement statement) {
|
public int visit(IASTStatement statement) {
|
||||||
DOMASTNodeLeaf temp = addRoot(statement);
|
DOMASTNodeLeaf temp = addRoot(statement);
|
||||||
if (temp == null)
|
if (temp == null)
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
else if (temp instanceof DOMASTNodeLeafContinue)
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
else
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTTypeId typeId) {
|
public int visit(IASTTypeId typeId) {
|
||||||
DOMASTNodeLeaf temp = addRoot(typeId);
|
DOMASTNodeLeaf temp = addRoot(typeId);
|
||||||
if (temp == null)
|
if (temp == null)
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
else if (temp instanceof DOMASTNodeLeafContinue)
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
else
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DOMASTNodeLeaf mergeNode(ASTNode node) {
|
private DOMASTNodeLeaf mergeNode(ASTNode node) {
|
||||||
DOMASTNodeLeaf temp = addRoot(node);
|
DOMASTNodeLeaf temp = addRoot(node);
|
||||||
|
|
||||||
if (node instanceof IASTPreprocessorMacroDefinition )
|
if (node instanceof IASTPreprocessorMacroDefinition)
|
||||||
addRoot(((IASTPreprocessorMacroDefinition)node).getName());
|
addRoot(((IASTPreprocessorMacroDefinition) node).getName());
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
@ -311,11 +247,12 @@ public class CPopulateASTViewAction extends ASTVisitor implements IPopulateDOMAS
|
||||||
@Override
|
@Override
|
||||||
public DOMASTNodeLeaf[] mergePreprocessorStatements(IASTPreprocessorStatement[] statements) {
|
public DOMASTNodeLeaf[] mergePreprocessorStatements(IASTPreprocessorStatement[] statements) {
|
||||||
DOMASTNodeLeaf[] leaves = new DOMASTNodeLeaf[statements.length];
|
DOMASTNodeLeaf[] leaves = new DOMASTNodeLeaf[statements.length];
|
||||||
for(int i=0; i<statements.length; i++) {
|
for (int i= 0; i < statements.length; i++) {
|
||||||
if (monitor != null && monitor.isCanceled()) return leaves;
|
if (monitor != null && monitor.isCanceled())
|
||||||
|
return leaves;
|
||||||
|
|
||||||
if (statements[i] instanceof ASTNode)
|
if (statements[i] instanceof ASTNode)
|
||||||
leaves[i] = mergeNode((ASTNode)statements[i]);
|
leaves[i] = mergeNode((ASTNode) statements[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return leaves;
|
return leaves;
|
||||||
|
@ -324,10 +261,11 @@ public class CPopulateASTViewAction extends ASTVisitor implements IPopulateDOMAS
|
||||||
@Override
|
@Override
|
||||||
public void mergePreprocessorProblems(IASTProblem[] problems) {
|
public void mergePreprocessorProblems(IASTProblem[] problems) {
|
||||||
for (IASTProblem problem : problems) {
|
for (IASTProblem problem : problems) {
|
||||||
if (monitor != null && monitor.isCanceled()) return;
|
if (monitor != null && monitor.isCanceled())
|
||||||
|
return;
|
||||||
|
|
||||||
if (problem instanceof ASTNode)
|
if (problem instanceof ASTNode)
|
||||||
mergeNode((ASTNode)problem);
|
mergeNode((ASTNode) problem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,24 +276,25 @@ public class CPopulateASTViewAction extends ASTVisitor implements IPopulateDOMAS
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void groupIncludes(DOMASTNodeLeaf[] treeIncludes) {
|
public void groupIncludes(DOMASTNodeLeaf[] treeIncludes) {
|
||||||
// loop through the includes and make sure that all of the nodes
|
// Loop through the includes and make sure that all of the nodes
|
||||||
// that are children of the TU are in the proper include (based on offset)
|
// that are children of the TU are in the proper include (based on offset)
|
||||||
for (int i=treeIncludes.length - 1; i >= 0; i-- ) {
|
for (int i= treeIncludes.length; --i >= 0;) {
|
||||||
final DOMASTNodeLeaf nodeLeaf = treeIncludes[i];
|
final DOMASTNodeLeaf nodeLeaf = treeIncludes[i];
|
||||||
if (nodeLeaf == null || !(nodeLeaf.getNode() instanceof IASTPreprocessorIncludeStatement)) continue;
|
if (nodeLeaf == null || !(nodeLeaf.getNode() instanceof IASTPreprocessorIncludeStatement))
|
||||||
|
continue;
|
||||||
|
|
||||||
final String path= ((IASTPreprocessorIncludeStatement) nodeLeaf.getNode()).getPath();
|
final String path= ((IASTPreprocessorIncludeStatement) nodeLeaf.getNode()).getPath();
|
||||||
final DOMASTNodeLeaf[] children = root.getChildren(false);
|
final DOMASTNodeLeaf[] children = root.getChildren(false);
|
||||||
for (final DOMASTNodeLeaf child : children) {
|
for (DOMASTNodeLeaf child : children) {
|
||||||
if (child != null && child != nodeLeaf &&
|
if (child != null && child != nodeLeaf &&
|
||||||
child.getNode().getContainingFilename().equals(path)) {
|
child.getNode().getContainingFilename().equals(path)) {
|
||||||
root.removeChild(child);
|
root.removeChild(child);
|
||||||
((DOMASTNodeParent)nodeLeaf).addChild(child);
|
((DOMASTNodeParent) nodeLeaf).addChild(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTProblem[] getASTProblems() {
|
public IASTProblem[] getASTProblems() {
|
||||||
return astProblems;
|
return astProblems;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue