From 364c506b2693f38146cfc7c2564b70f6c12f1fee Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Tue, 26 Feb 2008 12:50:49 +0000 Subject: [PATCH] Indexer to parse headers in context of a source, bug 220358. --- .../index/tests/IndexIncludeTest.java | 49 ++++++++++++++++++- .../core/pdom/AbstractIndexerTask.java | 3 +- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java index 939d4ef65db..02e80770e48 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,7 +8,6 @@ * Contributors: * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.index.tests; import java.io.ByteArrayInputStream; @@ -56,6 +55,7 @@ public class IndexIncludeTest extends IndexTestBase { super(name); } + @Override public void setUp() throws Exception { super.setUp(); if (fProject == null) { @@ -68,6 +68,7 @@ public class IndexIncludeTest extends IndexTestBase { fIndex= CCorePlugin.getIndexManager().getIndex(fProject); } + @Override public void tearDown() throws Exception { super.tearDown(); } @@ -296,6 +297,50 @@ public class IndexIncludeTest extends IndexTestBase { } + // #define SOME_MACRO1 ok_1_220358 + // #define SOME_MACRO2 ok_2_220358 + + // int SOME_MACRO1; + + // int SOME_MACRO2; + + // #include "header1.h" + // #include "header2.h" + public void testParsingInContext_bug220358() throws Exception { + StringBuffer[] sources= getContentsForTest(4); + IFile h1= TestSourceReader.createFile(fProject.getProject(), "header1.h", sources[0].toString()); + IFile h2= TestSourceReader.createFile(fProject.getProject(), "header2.h", sources[1].toString()); + IFile s1= TestSourceReader.createFile(fProject.getProject(), "s1.cpp", sources[3].toString()); + // make sure it is parsed in context + waitForIndexer(); + CCorePlugin.getIndexManager().reindex(fProject); + waitForIndexer(); + + fIndex.acquireReadLock(); + try { + IIndexBinding[] binding= fIndex.findBindings("ok_1_220358".toCharArray(), IndexFilter.ALL_DECLARED, NPM); + assertEquals(1, binding.length); + assertTrue(binding[0] instanceof IVariable); + } + finally { + fIndex.releaseReadLock(); + } + + // change header2: + h2= TestSourceReader.createFile(fProject.getProject(), "header2.h", sources[2].toString()); + TestSourceReader.waitUntilFileIsIndexed(fIndex, h2, INDEXER_WAIT_TIME); + fIndex.acquireReadLock(); + try { + IIndexBinding[] binding= fIndex.findBindings("ok_2_220358".toCharArray(), IndexFilter.ALL_DECLARED, NPM); + assertEquals(1, binding.length); + assertTrue(binding[0] instanceof IVariable); + } + finally { + fIndex.releaseReadLock(); + } + } + + // #include "resolved20070426.h" public void testFixedContext() throws Exception { TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java index 34f75f4f778..a38c15f5111 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java @@ -8,7 +8,6 @@ * Contributors: * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.core.pdom; import java.net.URI; @@ -543,7 +542,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } try { Object context= fResolver.getInputFile(ifile.getLocation()); - if (context != null) { + if (context != null && fResolver.isSourceUnit(context)) { contextMap.put(ifile, context); return context; }