diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java index f500e6c584e..f8a57fa956c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java @@ -246,9 +246,8 @@ public class AST2KnRTests extends AST2BaseTest { // test tu.getDeclarations(IBinding) IASTName[] decls = tu.getDeclarations(x3.resolveBinding()); - assertEquals( decls.length, 2 ); - assertEquals( decls[0], x0 ); - assertEquals( decls[1], x2 ); + assertEquals( decls.length, 1 ); + assertEquals( decls[0], x2 ); assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("c").toCharArray()) ); //$NON-NLS-1$ assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$ @@ -538,9 +537,8 @@ public class AST2KnRTests extends AST2BaseTest { // test tu.getDeclarations(IBinding) IASTName[] decls = tu.getDeclarations(x2.resolveBinding()); - assertEquals( decls.length, 2 ); - assertEquals( decls[0], x0 ); - assertEquals( decls[1], x2 ); + assertEquals( decls.length, 1 ); + assertEquals( decls[0], x2 ); assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_TAG, new String("A_struct").toCharArray()) ); //$NON-NLS-1$ assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("A").toCharArray()) ); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 81646e0ed29..c1f6682d955 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -2099,10 +2099,10 @@ public class AST2Tests extends AST2BaseTest { assertEquals(decls.length, 1); assertEquals(decls[0], def2.getDeclarator().getName()); - decls = tu.getDeclarations(def3.getDeclarator().getName() + decls = tu.getDeclarations(def3.getDeclarator().getNestedDeclarator().getName() .resolveBinding()); assertEquals(decls.length, 1); - assertEquals(decls[0], def3.getDeclarator().getName()); + assertEquals(decls[0], def3.getDeclarator().getNestedDeclarator().getName()); } // any parameter to type function returning T is adjusted to be pointer to diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 2b1b7ad0be9..c15231f4ed6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -301,14 +301,14 @@ public class CVisitor { public int processDeclarator(IASTDeclarator declarator) { //GCC allows declarations in expressions, so we have to continue from the //declarator in case there is something in the initializer expression - if ( declarator == null ) return PROCESS_CONTINUE; + if ( declarator == null || declarator.getName() == null || declarator.getName().toCharArray().length == 0 ) return PROCESS_CONTINUE; //if the binding is something not declared in a declarator, continue if( binding instanceof ICompositeType ) return PROCESS_CONTINUE; if( binding instanceof IEnumeration ) return PROCESS_CONTINUE; IASTNode parent = declarator.getParent(); - while (parent != null && !(parent instanceof IASTDeclaration)) + while (parent != null && !(parent instanceof IASTDeclaration || parent instanceof IASTParameterDeclaration)) parent = parent.getParent(); if ( parent instanceof IASTDeclaration ) { @@ -318,14 +318,14 @@ public class CVisitor { } } else if ( parent instanceof IASTSimpleDeclaration ) { // prototype parameter with no identifier isn't a declaration of the K&R C parameter - if ( binding instanceof CKnRParameter && declarator.getName().toCharArray().length == 0 ) - return PROCESS_CONTINUE; +// if ( binding instanceof CKnRParameter && declarator.getName().toCharArray().length == 0 ) +// return PROCESS_CONTINUE; if ( (declarator.getName() != null && declarator.getName().resolveBinding() == binding) ) { addName(declarator.getName()); } } - } else if ( parent instanceof IASTParameterDeclaration && binding instanceof IParameter ) { + } else if ( parent instanceof IASTParameterDeclaration ) { if ( declarator.getName() != null && declarator.getName().resolveBinding() == binding ) { addName(declarator.getName()); } @@ -1612,6 +1612,8 @@ public class CVisitor { return true; } public static boolean visitExpression( IASTExpression expression, CBaseVisitorAction action ){ + if (expression == null) return true; + if( action.processExpressions ){ switch( action.processExpression( expression ) ){ case CPPBaseVisitorAction.PROCESS_ABORT : return false; diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java index 214b8c7d951..38b6bc8fcc8 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java @@ -63,6 +63,8 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP } private void addRoot(IASTNode node) { + if (node == null) return; + TreeParent parent = root.findParentOfNode(node); if ( parent != null ) { diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java index 769bc0d9677..7961a14a884 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java @@ -59,6 +59,8 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul } private void addRoot(IASTNode node) { + if (node == null) return; + IASTNodeLocation[] nodeLocations = node.getNodeLocations(); if (!(nodeLocations.length > 0 && nodeLocations[0].getNodeOffset() >= 0 && diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMQuery.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMQuery.java index dbbcc4a663a..ac4a3857fa3 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMQuery.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMQuery.java @@ -82,10 +82,13 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery { path = new Path(fileName); file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); - start = names[i].getNodeLocations()[0].getNodeOffset(); - end = names[i].getNodeLocations()[0].getNodeOffset() + names[i].getNodeLocations()[0].getNodeLength(); - - collector.acceptMatch( createMatch(file, start, end, names[i], path ) ); + + if (names[i].getNodeLocations().length > 0) { // fix for 84223 + start = names[i].getNodeLocations()[0].getNodeOffset(); + end = names[i].getNodeLocations()[0].getNodeOffset() + names[i].getNodeLocations()[0].getNodeLength(); + + collector.acceptMatch( createMatch(file, start, end, names[i], path ) ); + } } } catch (CoreException ce) {} }