1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 09:45:39 +02:00

Bug 509749 - Find References doesn't find a reference to a function

Change-Id: Id90a80e234638b590266a8671dd1bf13178e0f94
This commit is contained in:
Sergey Prigogin 2016-12-28 20:56:32 -08:00
parent 63d3ab9cbe
commit 216bc162a4
19 changed files with 202 additions and 121 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true
Bundle-Version: 6.2.0.qualifier
Bundle-Version: 6.3.0.qualifier
Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -41,7 +41,7 @@ public interface ILanguage extends IAdaptable {
public final static int OPTION_SKIP_FUNCTION_BODIES= 0x1;
/**
* @deprecated, has no effect.
* @deprecated, Has no effect.
* @noreference This field is not intended to be referenced by clients.
*/
@Deprecated
@ -55,10 +55,9 @@ public interface ILanguage extends IAdaptable {
public final static int OPTION_NO_IMAGE_LOCATIONS= 0x4;
/**
* Option for {@link #getASTTranslationUnit(FileContent, IScannerInfo, IncludeFileContentProvider, IIndex, int, IParserLogService)}
* Marks the ast as being based on a source-file rather than a header-file. This makes a difference
* when bindings from the AST are used for searching the index, e.g. for static variables.
* @deprecated, Has no effect.
*/
@Deprecated
public final static int OPTION_IS_SOURCE_UNIT= 0x8;
/**
@ -97,22 +96,20 @@ public interface ILanguage extends IAdaptable {
public int getLinkageID();
/**
* @return the human readable name corresponding to this language, suitable for display.
* Returns the human readable name corresponding to this language, suitable for display.
* @since 4.0
*/
public String getName();
/**
* Construct an AST for the source code provided by <code>reader</code>.
* As an option you can supply
* Constructs an AST for the source code provided by <code>reader</code>.
*
* @param content source code to be parsed.
* @param scanInfo provides include paths and defined symbols.
* @param fileCreator factory that provides file content for files included
* @param index (optional) index to use to lookup symbols external to the tu.
* @param options A combination of
* {@link #OPTION_SKIP_FUNCTION_BODIES},
* {@link #OPTION_NO_IMAGE_LOCATIONS}, {@link #OPTION_IS_SOURCE_UNIT},
* or <code>0</code>.
* @param index (optional) index to use to lookup symbols external to the translation unit.
* @param options A combination of {@link #OPTION_SKIP_FUNCTION_BODIES},
* {@link #OPTION_NO_IMAGE_LOCATIONS}, or <code>0</code>.
* @param log logger
* @return an AST for the source code provided by reader.
* @throws CoreException

View file

@ -864,9 +864,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
if ((style & AST_PARSE_INACTIVE_CODE) != 0) {
options |= ILanguage.OPTION_PARSE_INACTIVE_CODE;
}
if (isSourceUnit()) {
options |= ILanguage.OPTION_IS_SOURCE_UNIT;
}
final IParserLogService log;
if (monitor instanceof ICanceler) {
log= new ParserLogService(DebugLogConstants.PARSER, (ICanceler) monitor);

View file

@ -164,9 +164,7 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
try {
// Parse
IASTTranslationUnit ast= parser.parse();
ast.setIsHeaderUnit((options & OPTION_IS_SOURCE_UNIT) == 0);
return ast;
return parser.parse();
} catch (ParseError e) {
// Only the TOO_MANY_TOKENS error can be handled here.
if (e.getErrorKind() != ParseErrorKind.TOO_MANY_TOKENS)

View file

@ -77,6 +77,7 @@ public abstract class FileContent {
/**
* Creates a file content object for a fixed buffer.
*
* @param filePath the path of the file as it will appear in {@link IASTFileLocation#getFileName()}
* @param contents the actual content.
*/
@ -84,23 +85,45 @@ public abstract class FileContent {
return new InternalFileContent(filePath, new CharArray(contents));
}
/**
* Creates a file content object for a fixed buffer.
*
* @param filePath the path of the file as it will appear in {@link IASTFileLocation#getFileName()}
* @param contents the actual content.
* @since 6.3
*/
public static FileContent create(String filePath, boolean isSource, char[] contents) {
InternalFileContent fileContent = new InternalFileContent(filePath, new CharArray(contents));
fileContent.setIsSource(isSource);
return fileContent;
}
/**
* Creates a file content object for a translation-unit, which may be a working copy.
*/
public static FileContent create(ITranslationUnit tu) {
InternalFileContent fileContent;
IPath location= tu.getLocation();
if (location == null)
return create(tu.getElementName(), tu.getContents());
if (tu.isWorkingCopy()) {
return create(location.toOSString(), tu.getContents());
if (location == null) {
fileContent = new InternalFileContent(tu.getElementName(), new CharArray(tu.getContents()));
} else if (tu.isWorkingCopy()) {
fileContent = new InternalFileContent(location.toOSString(), new CharArray(tu.getContents()));
} else {
IResource res= tu.getResource();
if (res instanceof IFile) {
fileContent = InternalParserUtil.createWorkspaceFileContent((IFile) res);
} else {
fileContent = InternalParserUtil.createExternalFileContent(location.toOSString(),
InternalParserUtil.SYSTEM_DEFAULT_ENCODING);
}
}
IResource res= tu.getResource();
if (res instanceof IFile) {
return create((IFile) res);
if (fileContent != null) {
fileContent.setTranslationUnit(tu);
fileContent.setIsSource(tu.isSourceUnit());
}
return createForExternalFileLocation(location.toOSString());
return fileContent;
}
/**
@ -111,22 +134,37 @@ public abstract class FileContent {
}
/**
* Creates a file content for a workspace file
* Creates a file content for a workspace header file.
*/
public static FileContent create(IFile file) {
return InternalParserUtil.createWorkspaceFileContent(file);
}
/**
* Creates a file content object for a header file that is not part of the workspace.
*/
public static FileContent createForExternalFileLocation(String fileLocation) {
return createForExternalFileLocation(fileLocation, InternalParserUtil.SYSTEM_DEFAULT_ENCODING);
}
/**
* Creates a file content object for a file location that is not part of the workspace
* Creates a file content object for a header file that is not part of the workspace.
* @since 5.3
*/
public static FileContent createForExternalFileLocation(String fileLocation, String encoding) {
return InternalParserUtil.createExternalFileContent(fileLocation, encoding);
return createForExternalFileLocation(fileLocation, false, encoding);
}
/**
* Creates a file content object for a header or a source file that is not part of the workspace.
* @since 6.3
*/
public static FileContent createForExternalFileLocation(String fileLocation, boolean isSource,
String encoding) {
InternalFileContent fileContent = InternalParserUtil.createExternalFileContent(fileLocation, encoding);
if (fileContent != null)
fileContent.setIsSource(isSource);
return fileContent;
}
/**

View file

@ -19,7 +19,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
import org.eclipse.cdt.internal.core.parser.scanner.Lexer;
/**
* Interface between the parser and the preprocessor.
* Interface between the parser and the preprocessor.
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
@ -27,7 +27,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.Lexer;
public interface IScanner {
/**
* Returns a map from {@link String} to {@link IMacroBinding} containing
* all the definitions that are defined at the current point in the
* all the definitions that are defined at the current point in the
* process of scanning.
*/
public Map<String, IMacroBinding> getMacroDefinitions();
@ -38,25 +38,27 @@ public interface IScanner {
* @throws OffsetLimitReachedException see {@link Lexer}.
*/
public IToken nextToken() throws EndOfFileException;
/**
* Returns <code>true</code>, whenever we are processing the outermost file of the translation unit.
* Returns {@code true}, whenever we are processing the outermost file of the translation unit.
*/
public boolean isOnTopContext();
/**
* Attempts to cancel the scanner.
*/
public void cancel();
/**
* Returns the location resolver associated with this scanner.
*
* @noreference This method is not intended to be referenced by clients.
*/
public ILocationResolver getLocationResolver();
/**
* Puts the scanner into content assist mode.
*
* @noreference This method is not intended to be referenced by clients.
*/
public void setContentAssistMode(int offset);
@ -64,25 +66,26 @@ public interface IScanner {
/**
* Instructs the scanner to split tokens of kind {@link IToken#tSHIFTR} into two tokens of
* kind {@link IToken#tGT_in_SHIFTR}.
*
* @noreference This method is not intended to be referenced by clients.
*/
public void setSplitShiftROperator(boolean val);
/**
* Turns on/off creation of image locations.
* Turns on/off creation of image locations.
* @see org.eclipse.cdt.core.dom.ast.IASTName#getImageLocation()
*
* @noreference This method is not intended to be referenced by clients.
* @since 5.0
*/
public void setComputeImageLocations(boolean val);
/**
* Turns on/off tracking if exported included files.
* Turns on/off tracking if exported included files.
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement#isIncludedFileExported()
* @see IncludeExportPatterns
*
* @param patterns if not {{@code null}, include export tracking is enabled, otherwise it is
* disabled
* @param patterns if not {@code null}, include export tracking is enabled, otherwise it is disabled
*
* @noreference This method is not intended to be referenced by clients.
* @since 5.5
@ -93,14 +96,16 @@ public interface IScanner {
* Toggles generation of tokens for inactive code branches. When turned on,
* each inactive code branch is preceded by a token of kind {@link IToken#tINACTIVE_CODE_START} and
* succeeded by one of kind {@link IToken#tINACTIVE_CODE_END}.
*
*
* @noreference This method is not intended to be referenced by clients.
*/
public void setProcessInactiveCode(boolean val);
/**
* When in inactive code, skips all tokens up to the end of the inactive code section.
* <p> Note, token after calling this method may be another token of type {@link IToken#tINACTIVE_CODE_START}.
* When in inactive code, skips all tokens up to the end of the inactive code section.
* <p> Note, token after calling this method may be another token of type
* {@link IToken#tINACTIVE_CODE_START}.
*
* @noreference This method is not intended to be referenced by clients.
*/
public void skipInactiveCode() throws OffsetLimitReachedException;
@ -109,21 +114,23 @@ public interface IScanner {
* Returns the current nesting in code branches.
* @see IInactiveCodeToken#getOldNesting()
* @see IInactiveCodeToken#getNewNesting()
*
* @noreference This method is not intended to be referenced by clients.
*/
public int getCodeBranchNesting();
/**
* Returns a list of additional (compiler specific) suffixes which can
* be placed on numbers. e.g. 'u' 'l' -> 1l or 1u.
*
* @noreference This method is not intended to be referenced by clients.
*/
public char[] getAdditionalNumericLiteralSuffixes();
/**
* @deprecated Has no effect.
* @noreference This method is not intended to be referenced by clients.
*/
@Deprecated
public void setScanComments(boolean val);
/**
* Returns a list of additional (compiler specific) suffixes which can
* be placed on numbers. e.g. 'u' 'l' -> 1l or 1u.
* @noreference This method is not intended to be referenced by clients.
*/
public char[] getAdditionalNumericLiteralSuffixes();
public default void setScanComments(boolean val) {}
}

View file

@ -13,6 +13,7 @@
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
@ -506,4 +507,14 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
}
return null;
}
/** For debugging only. */
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append(getName());
IFunctionType t = getType();
result.append(t != null ? ASTTypeUtil.getParameterTypeStringAndQualifiers(t) : "()"); //$NON-NLS-1$
return result.toString();
}
}

View file

@ -447,7 +447,10 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
if (scanner != null) {
tu.setLocationResolver(scanner.getLocationResolver());
if (scanner instanceof CPreprocessor) {
tu.setIsForContentAssist(((CPreprocessor) scanner).isContentAssistMode());
CPreprocessor cPreprocessor = (CPreprocessor) scanner;
tu.setIsForContentAssist(cPreprocessor.isContentAssistMode());
tu.setOriginatingTranslationUnit(cPreprocessor.getTranslationUnit());
tu.setIsHeaderUnit(!cPreprocessor.isSource());
}
}
tu.setASTNodeFactory(this);

View file

@ -770,7 +770,10 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
if (scanner != null) {
tu.setLocationResolver(scanner.getLocationResolver());
if (scanner instanceof CPreprocessor) {
tu.setIsForContentAssist(((CPreprocessor) scanner).isContentAssistMode());
CPreprocessor cPreprocessor = (CPreprocessor) scanner;
tu.setIsForContentAssist(cPreprocessor.isContentAssistMode());
tu.setOriginatingTranslationUnit(cPreprocessor.getTranslationUnit());
tu.setIsHeaderUnit(!cPreprocessor.isSource());
}
}
tu.setASTNodeFactory(this);

View file

@ -166,18 +166,17 @@ public class StandaloneIndexerInputAdapter extends IndexerInputAdapter {
String stu = tu.toString();
String fileEncoding = getFileEncoding(stu);
return FileContent.createForExternalFileLocation(stu, fileEncoding);
return FileContent.createForExternalFileLocation(stu, isSource(stu), fileEncoding);
}
public String getFileEncoding(String stu) {
String fileEncoding = null;
// query file's encoding, if we find it and use it to create CodeReader
// Query file's encoding, if we find it and use it to create CodeReader
FileEncodingRegistry fileEncodingRegistry = fIndexer.getFileEncodingRegistry();
if(fileEncodingRegistry != null){
if (fileEncodingRegistry != null)
fileEncoding = fileEncodingRegistry.getFileEncoding(stu);
}
if (fileEncoding == null)
return InternalParserUtil.SYSTEM_DEFAULT_ENCODING;
fileEncoding = InternalParserUtil.SYSTEM_DEFAULT_ENCODING;
return fileEncoding;
}

View file

@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IFileNomination;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.AbstractParserLogService;
import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
@ -262,7 +263,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
private final ScannerContext fRootContext;
protected ScannerContext fCurrentContext;
private boolean isCancelled= false;
private boolean isCancelled;
private boolean fIsFirstFetchToken= true;
private Token fPrefetchedTokens;
@ -273,8 +274,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
// Detection of include guards used around an include directive
private char[] fExternIncludeGuard;
private Set<String> fTracedGuards;
private Set<String> fTracedGuards;
public CPreprocessor(FileContent fileContent, IScannerInfo info, ParserLanguage language,
IParserLogService log, IScannerExtensionConfiguration configuration,
@ -386,8 +386,12 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
fRootContext.setParseInactiveCode(val);
}
@Override
public void setScanComments(boolean val) {
public ITranslationUnit getTranslationUnit() {
return fRootContent.getTranslationUnit();
}
public boolean isSource() {
return fRootContent.isSource();
}
@Override

View file

@ -16,6 +16,7 @@ import java.util.List;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.FileContent;
import org.eclipse.cdt.core.parser.ISignificantMacros;
@ -56,6 +57,7 @@ public class InternalFileContent extends FileContent {
private final List<FileVersion> fNonPragmaOnceFiles;
private boolean fHeuristic;
private boolean fIsSource;
private ITranslationUnit fTranslationUnit;
private List<IIndexFile> fFiles;
private IncludeSearchPathElement fFoundOnPath;
private final long fTimestamp;
@ -246,6 +248,14 @@ public class InternalFileContent extends FileContent {
fIsSource= isSource;
}
public ITranslationUnit getTranslationUnit() {
return fTranslationUnit;
}
public void setTranslationUnit(ITranslationUnit tu) {
fTranslationUnit = tu;
}
public IncludeSearchPathElement getFoundOnPath() {
return fFoundOnPath;
}

View file

@ -53,7 +53,6 @@ import org.eclipse.cdt.core.index.IPDOMASTProcessor;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.AbstractLanguage;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
import org.eclipse.cdt.core.parser.FileContent;
import org.eclipse.cdt.core.parser.IParserLogService;
@ -63,7 +62,6 @@ import org.eclipse.cdt.core.parser.ISignificantMacros;
import org.eclipse.cdt.core.parser.IncludeExportPatterns;
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
import org.eclipse.cdt.internal.core.index.FileContentKey;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
@ -1088,19 +1086,15 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
progress.subTask(getMessage(MessageKind.parsingFileTask,
path.lastSegment(), path.removeLastSegments(1).toString()));
FileContent codeReader= fResolver.getCodeReader(tu);
final boolean isSource = fResolver.isSourceUnit(tu);
long start= System.currentTimeMillis();
ASTTypeUtil.startTranslationUnit();
IASTTranslationUnit ast=
createAST(lang, codeReader, scanInfo, isSource, fASTOptions, ctx, progress.split(10));
createAST(lang, codeReader, scanInfo, fASTOptions, ctx, progress.split(10));
fStatistics.fParsingTime += System.currentTimeMillis() - start;
if (ast == null) {
++fStatistics.fTooManyTokensCount;
} else {
// Give the new AST a chance to recognize its translation unit before it is written
// to the index.
((ASTTranslationUnit) ast).setOriginatingTranslationUnit((ITranslationUnit) tu);
writeToIndex(lang.getLinkageID(), ast, codeReader, ctx, progress.split(10));
resultCacheCleared = true; // The cache was cleared while writing to the index.
}
@ -1204,14 +1198,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
}
private final IASTTranslationUnit createAST(AbstractLanguage language, FileContent codeReader,
IScannerInfo scanInfo, boolean isSource, int options,
FileContext ctx, IProgressMonitor monitor) throws CoreException {
IScannerInfo scanInfo, int options, FileContext ctx, IProgressMonitor monitor)
throws CoreException {
if (codeReader == null) {
return null;
}
if (isSource) {
options |= ILanguage.OPTION_IS_SOURCE_UNIT;
}
if (fTranslationUnitSizeLimit > 0 && fResolver.getFileSize(codeReader.getFileLocation()) > fTranslationUnitSizeLimit) {
if (fShowActivity) {
trace("Indexer: Skipping large file " + codeReader.getFileLocation()); //$NON-NLS-1$

View file

@ -11,7 +11,7 @@
<relativePath>../../pom.xml</relativePath>
</parent>
<version>6.2.0-SNAPSHOT</version>
<version>6.3.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.core</artifactId>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -7,6 +7,7 @@
*******************************************************************************/
package org.eclipse.cdt.ui.tests.search;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
@ -38,11 +39,11 @@ public class FindReferencesTest extends SearchTestBase {
return suite(FindReferencesTest.class);
}
private CSearchQuery makeProjectQuery(int offset, int length) {
private CSearchQuery makeSearchQuery(IFile file, TextSelection selection) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart part = null;
try {
part = page.openEditor(new FileEditorInput(fHeaderFile), "org.eclipse.cdt.ui.editor.CEditor"); //$NON-NLS-1$
part = page.openEditor(new FileEditorInput(file), "org.eclipse.cdt.ui.editor.CEditor"); //$NON-NLS-1$
} catch (PartInitException e) {
assertFalse(true);
}
@ -50,27 +51,41 @@ public class FindReferencesTest extends SearchTestBase {
CEditor editor = (CEditor) part;
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 5000, 10);
ITranslationUnit tu = editor.getInputCElement();
return new CSearchTextSelectionQuery(new ICElement[] { fCProject }, tu, new TextSelection(offset, length),
CSearchQuery.FIND_REFERENCES);
return new CSearchTextSelectionQuery(new ICElement[] { fCProject }, tu, selection, CSearchQuery.FIND_REFERENCES);
}
private TextSelection selectSection(String section, String context, String code) {
int contextOffset;
if (context == null) {
context = code;
contextOffset = 0;
} else {
contextOffset = code.indexOf(context);
if (contextOffset < 0)
fail("Didn't find \"" + context + "\" in \"" + code + "\"");
}
int offset = context.indexOf(section);
if (offset < 0)
fail("Didn't find \"" + section + "\" in \"" + context + "\"");
return new TextSelection(contextOffset + offset, section.length());
}
// struct A {
// virtual void waldo();
// virtual void waldo();
// };
//
// struct B : public A {
// virtual void waldo() override;
// virtual void waldo() override;
// };
//
// int main() {
// A* a = new B();
// a->waldo();
// A* a = new B();
// a->waldo();
// }
// // empty file
public void testOnlyPolymorphicMatches_bug491343() throws Exception {
int offset = fHeaderContents.indexOf("waldo() override");
CSearchQuery query = makeProjectQuery(offset, 5);
CSearchQuery query = makeSearchQuery(fHeaderFile, selectSection("waldo", "waldo() override", fHeaderContents));
assertOccurrences(query, 1);
}
@ -78,15 +93,14 @@ public class FindReferencesTest extends SearchTestBase {
// #define waldo()
//
// struct S {
// void foo() {
// waldo();
// }
// void foo() {
// waldo();
// }
// };
// // empty file
public void testEnclosingDefinitionOfMacroReference_508216() throws Exception {
int offset = fHeaderContents.indexOf("define waldo") + 7;
CSearchQuery query = makeProjectQuery(offset, 5);
CSearchQuery query = makeSearchQuery(fHeaderFile, selectSection("waldo", "#define waldo", fHeaderContents));
CSearchResult result = getSearchResult(query);
Object[] elements = result.getElements();
assertEquals(1, elements.length);
@ -97,14 +111,30 @@ public class FindReferencesTest extends SearchTestBase {
}
// namespace N {
// void foo();
// void foo();
// }
// using N::foo;
// // empty file
public void testUsingDeclaration_399147() throws Exception {
int offset = fHeaderContents.indexOf("void foo") + 5;
CSearchQuery query = makeProjectQuery(offset, 3);
CSearchQuery query = makeSearchQuery(fHeaderFile, selectSection("foo", "void foo", fHeaderContents));
assertOccurrences(query, 1);
}
// // empty file
// namespace { struct A {}; }
//
// template <typename T>
// class B {};
//
// void findMe(B<A> b) {}
//
// void test(B<A> b) {
// findMe(b);
// }
public void testAnonymousNamespace_509749() throws Exception {
CSearchQuery query = makeSearchQuery(fSourceFile, selectSection("findMe", "findMe(b)", fSourceContents));
assertOccurrences(query, 1);
}
}

View file

@ -26,10 +26,12 @@ import org.eclipse.cdt.internal.ui.search.CSearchResult;
* Base class for tests that test functionality based on CSearchQuery.
*/
public abstract class SearchTestBase extends BaseUITestCase {
ICProject fCProject;
String fHeaderContents;
IFile fHeaderFile;
CharSequence[] testData;
protected ICProject fCProject;
protected String fHeaderContents;
protected IFile fHeaderFile;
protected String fSourceContents;
protected IFile fSourceFile;
protected CharSequence[] testData;
@Override
protected void setUp() throws Exception {
@ -44,7 +46,8 @@ public abstract class SearchTestBase extends BaseUITestCase {
CCorePlugin.getIndexManager().setIndexerId(fCProject, IPDOMManager.ID_FAST_INDEXER);
waitForIndexer(fCProject);
IFile cppfile= TestSourceReader.createFile(fCProject.getProject(), new Path("references.cpp"), testData[1].toString());
fSourceContents = testData[1].toString();
fSourceFile = TestSourceReader.createFile(fCProject.getProject(), new Path("references.cpp"), fSourceContents);
waitForIndexer(fCProject);
}

View file

@ -106,16 +106,15 @@ public class CStructureCreator extends StructureCreator {
// empty scanner info
IScannerInfo scanInfo= new ScannerInfo();
FileContent content = FileContent.create("<text>", document.get().toCharArray()); //$NON-NLS-1$
// determine the language
boolean isSource[]= {false};
ILanguage language= determineLanguage(element, isSource);
FileContent content = FileContent.create("<text>", isSource[0], document.get().toCharArray()); //$NON-NLS-1$
try {
IASTTranslationUnit ast;
int options= isSource[0] ? ILanguage.OPTION_IS_SOURCE_UNIT : 0;
ast= language.getASTTranslationUnit(content, scanInfo, contentProvider, null, options, ParserUtil.getParserLogService());
IASTTranslationUnit ast = language.getASTTranslationUnit(content, scanInfo, contentProvider, null,
0, ParserUtil.getParserLogService());
CStructureCreatorVisitor structureCreator= new CStructureCreatorVisitor(root);
// build structure
ast.accept(structureCreator);

View file

@ -17,10 +17,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lpg.lpgjavaruntime.IToken;
import lpg.lpgjavaruntime.PrsStream;
import lpg.lpgjavaruntime.Token;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTName;
@ -51,6 +47,9 @@ import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory;
import org.eclipse.core.runtime.CoreException;
import lpg.lpgjavaruntime.IToken;
import lpg.lpgjavaruntime.PrsStream;
/**
* Implementation of the ILanguage extension point,
@ -269,9 +268,6 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
log.traceLog("^^^^^^ core parser parses " + reader.getFileLocation() + " in " + (coreFinishTime - lpr_fail_time)/1000 + " seconds");
}
}
if(tu!=null){
tu.setIsHeaderUnit((options & OPTION_IS_SOURCE_UNIT) == 0); // the TU is marked as either a source file or a header file
}
if(DEBUG_PRINT_AST) {
System.out.println("Base Extensible Language AST:");

View file

@ -112,11 +112,6 @@ public class StringScanner implements IScanner {
return 0;
}
@Override
@Deprecated
public void setScanComments(boolean val) {
}
@Override
public char[] getAdditionalNumericLiteralSuffixes() {
return new char[] {};