From 3b2b1c6a42922fe18fc34a30691c5ba496ae6692 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Fri, 26 Sep 2003 17:53:45 +0000 Subject: [PATCH] Patch for Bogdan Gheorghe: This patch integrates the dependency calculator into the indexer. As a result the underlying indexer file storage format has changes. Lots of detail in the change logs of exactly what changed... --- .../ChangeLog | 8 + .../internal/core/MakefileGenerator.java | 42 +- core/org.eclipse.cdt.core.tests/ChangeLog | 12 + .../core/indexer/tests/DependencyTests.java | 713 ++++++++++++++++++ .../core/indexer/tests/IndexManagerTests.java | 101 +-- .../resources/dependency/DepTest3.cpp | 7 + .../resources/dependency/DepTest3.h | 8 + .../core/suite/AutomatedIntegrationSuite.java | 2 + core/org.eclipse.cdt.core/.options | 3 - core/org.eclipse.cdt.core/ChangeLog | 10 + .../org.eclipse.cdt.core/dependency/ChangeLog | 22 + .../AddFileToDependencyTree.java | 116 --- .../sourcedependency/DependencyManager.java | 423 ----------- .../sourcedependency/DependencyQueryJob.java | 188 ++++- .../sourcedependency/DependencyRequest.java | 64 -- .../sourcedependency/DependencyRequestor.java | 60 -- .../sourcedependency/DependencySelector.java | 114 --- .../core/sourcedependency/DependencyTree.java | 195 ----- .../EntireProjectDependencyTree.java | 200 ----- .../sourcedependency/IDependencyTree.java | 85 --- .../sourcedependency/IPreprocessorOutput.java | 20 - .../sourcedependency/ISourceDependency.java | 19 - .../sourcedependency/{impl => }/Node.java | 2 +- .../sourcedependency/PreprocessorOutput.java | 66 -- .../RemoveFromDependencyTree.java | 58 -- .../sourcedependency/impl/InMemoryTree.java | 150 ---- core/org.eclipse.cdt.core/index/ChangeLog | 32 + .../cdt/internal/core/index/IIndex.java | 9 + .../internal/core/index/IIndexerOutput.java | 4 + .../core/index/impl/BlocksIndexInput.java | 83 ++ .../core/index/impl/BlocksIndexOutput.java | 51 +- .../index/impl/GammaCompressedIndexBlock.java | 72 ++ .../core/index/impl/IIndexConstants.java | 2 +- .../core/index/impl/InMemoryIndex.java | 107 +++ .../core/index}/impl/IncludeEntry.java | 72 +- .../index}/impl/IncludeEntryHashedArray.java | 2 +- .../cdt/internal/core/index/impl/Index.java | 76 ++ .../internal/core/index/impl/IndexBlock.java | 7 + .../internal/core/index/impl/IndexInput.java | 41 +- .../core/index/impl/IndexSummary.java | 77 +- .../core/index/impl/IndexerOutput.java | 19 + .../core/index/impl/MergeFactory.java | 41 + .../core/index/impl/SimpleIndexInput.java | 32 + .../cdt/internal/core/index/impl/Util.java | 30 + .../core/search/indexing/AbstractIndexer.java | 34 + .../core/search/indexing/IIndexConstants.java | 3 + .../core/search/indexing/IndexAllProject.java | 16 +- .../core/search/indexing/IndexManager.java | 84 +-- .../core/search/indexing/SourceIndexer.java | 6 + .../indexing/SourceIndexerRequestor.java | 30 +- .../org/eclipse/cdt/core/model/CoreModel.java | 9 - .../internal/core/model/CModelManager.java | 8 +- .../internal/core/model/DeltaProcessor.java | 98 +-- core/org.eclipse.cdt.core/search/ChangeLog | 7 + .../cdt/core/search/ICSearchConstants.java | 5 +- .../core/search/IIndexSearchRequestor.java | 2 + .../internal/core/search/PathCollector.java | 6 + .../core/search/matching/CSearchPattern.java | 18 +- .../core/search/matching/IncludePattern.java | 105 +++ .../src/org/eclipse/cdt/core/CCorePlugin.java | 15 +- core/org.eclipse.cdt.ui/ChangeLog | 7 + .../internal/ui/CPluginResources.properties | 2 +- .../ui/preferences/CProjectOptionBlock.java | 25 - .../ui/preferences/CProjectPropertyPage.java | 120 --- .../eclipse/cdt/ui/dialogs/IndexerBlock.java | 87 --- 65 files changed, 2003 insertions(+), 2129 deletions(-) create mode 100644 core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java create mode 100644 core/org.eclipse.cdt.core.tests/resources/dependency/DepTest3.cpp create mode 100644 core/org.eclipse.cdt.core.tests/resources/dependency/DepTest3.h delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/AddFileToDependencyTree.java delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyManager.java delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyRequest.java delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyRequestor.java delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencySelector.java delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyTree.java delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/EntireProjectDependencyTree.java delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/IDependencyTree.java delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/IPreprocessorOutput.java delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/ISourceDependency.java rename core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/{impl => }/Node.java (94%) delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/PreprocessorOutput.java delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/RemoveFromDependencyTree.java delete mode 100644 core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/InMemoryTree.java rename core/org.eclipse.cdt.core/{dependency/org/eclipse/cdt/internal/core/sourcedependency => index/org/eclipse/cdt/internal/core/index}/impl/IncludeEntry.java (71%) rename core/org.eclipse.cdt.core/{dependency/org/eclipse/cdt/internal/core/sourcedependency => index/org/eclipse/cdt/internal/core/index}/impl/IncludeEntryHashedArray.java (97%) create mode 100644 core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/IncludePattern.java delete mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CProjectOptionBlock.java delete mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CProjectPropertyPage.java delete mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java diff --git a/build/org.eclipse.cdt.managedbuilder.core/ChangeLog b/build/org.eclipse.cdt.managedbuilder.core/ChangeLog index f2ebf0461d7..0bd2a776217 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/ChangeLog +++ b/build/org.eclipse.cdt.managedbuilder.core/ChangeLog @@ -41,6 +41,14 @@ * src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java +2003-09-25 Bogdan Gheorghe + Modified ResourceDeltaVisitor.visit() to use the new mechanism to get the + projects that dependend a file. + + Modified addSourceDependencies() to use the new mechanism to perform a DependencyQueryJob + + * src/org/eclipse/cdt/managedbuilder/internal/core/MakeFileGenerator.java + 2003-09-24 Sean Evoy Changed the implementor of IScannerInfo to answer only absolute paths when asked for includes paths. Users will specify the includes paths in the managed build UI in such a way diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java index 7d81471b348..8e9f9411588 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java @@ -17,14 +17,19 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.search.ICSearchConstants; +import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.core.search.SearchEngine; +import org.eclipse.cdt.internal.core.model.Util; +import org.eclipse.cdt.internal.core.search.PathCollector; +import org.eclipse.cdt.internal.core.search.PatternSearchJob; +import org.eclipse.cdt.internal.core.search.indexing.IndexManager; +import org.eclipse.cdt.internal.core.search.matching.CSearchPattern; +import org.eclipse.cdt.internal.core.sourcedependency.DependencyQueryJob; import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.search.ICSearchConstants; -import org.eclipse.cdt.internal.core.model.Util; -import org.eclipse.cdt.internal.core.sourcedependency.DependencyManager; -import org.eclipse.cdt.internal.core.sourcedependency.DependencyQueryJob; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -160,13 +165,24 @@ public class MakefileGenerator { // Here's the container generator.appendModifiedSubdirectory(resource); // and all the dependents - DependencyManager depMgr = CCorePlugin.getDefault().getCoreModel().getDependencyManager(); - List deps = depMgr.getProjectDependsForFile(resource.getLocation().toOSString()); - if (deps != null) { - ListIterator iter = deps.listIterator(); - while (iter.hasNext()) { + PathCollector pathCollector = new PathCollector(); + ICSearchScope scope = SearchEngine.createWorkspaceScope(); + CSearchPattern pattern = CSearchPattern.createPattern(resource.getLocation().toOSString(),ICSearchConstants.INCLUDE, ICSearchConstants.REFERENCES,ICSearchConstants.EXACT_MATCH,true); + IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); + indexManager.performConcurrentJob( + new PatternSearchJob( + (CSearchPattern) pattern, + scope, + pathCollector, + indexManager + ), + ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null ); + String[] deps = pathCollector.getPaths(); + if (deps.length > 0 ) { + for (int i=0; i failed to calculate dependency for " + this.resource + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$ - e.printStackTrace(); - } - return false; - } finally { - monitor.exitWrite(); // free write lock - } - return true; - } - - protected boolean addDocumentToTree(IDependencyTree dTree) throws IOException { - if (!initializeContents()) return false; - //Need to create document to get string content... - IDocument document = new IFileDocument(resource, this.contents); - if (!shouldAddToTree(document)) return false; - - String docPath = resource.getLocation().toOSString(); - IScannerInfo newInfo = new ScannerInfo((this.buildInfo != null) ? this.buildInfo.getDefinedSymbols() : null,(this.buildInfo != null) ? this.buildInfo.getIncludePaths() : null); - - ParserLanguage language = CoreModel.getDefault().hasCCNature( resource.getProject() ) ? ParserLanguage.CPP : ParserLanguage.C; - dTree.add(document,docPath,newInfo, resource, language); - - return true; - } - - public boolean initializeContents() { - if (this.contents == null) { - try { - IPath location = resource.getLocation(); - if (location != null) - this.contents = org.eclipse.cdt.internal.core.Util.getFileCharContent(location.toFile(), null); - } catch (IOException e) { - } - } - return this.contents != null; - } - - public String toString() { - return "calculating dependency for: " + this.resource.getFullPath(); //$NON-NLS-1$ - } - - public String[] getFileTypes(){ - return FILE_TYPES; - } - - public boolean shouldAddToTree(IDocument document) { - String type = document.getType(); - String[] supportedTypes = this.getFileTypes(); - for (int i = 0; i < supportedTypes.length; ++i) { - if (supportedTypes[i].equals(type)) - return true; - } - return false; - } - -} diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyManager.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyManager.java deleted file mode 100644 index bc754724f42..00000000000 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyManager.java +++ /dev/null @@ -1,423 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.internal.core.sourcedependency; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.zip.CRC32; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.internal.core.CharOperation; -import org.eclipse.cdt.internal.core.search.SimpleLookupTable; -import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor; -import org.eclipse.cdt.internal.core.search.processing.JobManager; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.QualifiedName; - -/** - * @author bgheorgh - */ -public class DependencyManager extends JobManager implements ISourceDependency { - /* number of file contents in memory */ - public static int MAX_FILES_IN_MEMORY = 0; - - public SimpleLookupTable projectNames = new SimpleLookupTable(); - public SimpleLookupTable dependencyTable; - private Map dependencyTrees = new HashMap(5); - - /* read write monitors */ - private Map monitors = new HashMap(5); - - /* need to save ? */ - private boolean needToSave = false; - private static final CRC32 checksumCalculator = new CRC32(); - private IPath ccorePluginLocation = null; - - /* can only replace a current state if its less than the new one */ - private SimpleLookupTable dTreeStates = null; - private File savedDTreesFile = - new File(getCCorePluginWorkingLocation().append("savedDTrees.txt").toOSString()); //$NON-NLS-1$ - public static Integer SAVED_STATE = new Integer(0); - public static Integer UPDATING_STATE = new Integer(1); - public static Integer UNKNOWN_STATE = new Integer(2); - public static Integer REBUILDING_STATE = new Integer(3); - - public static boolean VERBOSE = false; - - public String processName(){ - //TODO: BOG Add name to .properties file - return "Dependency Tree"; //org.eclipse.cdt.internal.core.search.Util.bind("process.name"); //$NON-NLS-1$ - } - - public void reset(){ - super.reset(); - - //Get handles on the info providers - //register yourself for updates - - if (this.dependencyTrees!= null) { - this.dependencyTrees = new HashMap(5); - this.monitors = new HashMap(5); - this.dTreeStates = null; - } - - this.projectNames = new SimpleLookupTable(); - this.dependencyTable = new SimpleLookupTable(); - this.ccorePluginLocation = null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.sourcedependency.ISourceDependency#getProjects(org.eclipse.core.resources.IFile) - */ - public IProject[] getProjects(IFile file) { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.sourcedependency.ISourceDependency#getFileDependencies(org.eclipse.core.resources.IProject, org.eclipse.core.resources.IFile) - */ - public synchronized String[] getFileDependencies(IProject project, IFile file) { - IPath path =project.getFullPath(); - IDependencyTree dTree= this.getDependencyTree(path,true,false); - try{ - if (dTree != null) { - //dTree.printIncludeEntries(); - //dTree.printIndexedFiles(); - String[] files = dTree.getFileDependencies(file.getFullPath()); - return files; - } - } - catch(Exception e){} - return null; - } - - public synchronized IDependencyTree getDependencyTree(IPath path, boolean reuseExistingFile, boolean createIfMissing) { - IDependencyTree dTree = (IDependencyTree) dependencyTrees.get(path); - if (dTree == null){ - String treeName = computeTreeName(path); - Object state = getTreeStates().get(treeName); - Integer currentDTreeState = state == null ? UNKNOWN_STATE : (Integer) state; - if (currentDTreeState == UNKNOWN_STATE) { - // should only be reachable for query jobs - rebuildDTree(treeName, path); - return null; - } - // tree isn't cached, consider reusing an existing tree file - if (reuseExistingFile) { - File treeFile = new File(treeName); - if (treeFile.exists()) { // check before creating tree so as to avoid creating a new empty tree if file is missing - try { - dTree = new DependencyTree(treeName, "Tree for " + path.toOSString(), true /*reuse tree file*/); //$NON-NLS-1$ - dependencyTrees.put(path, dTree); - monitors.put(dTree, new ReadWriteMonitor()); - return dTree; - } catch (IOException e) { - // failed to read the existing file or its no longer compatible - if (currentDTreeState != REBUILDING_STATE) { // rebuild tree if existing file is corrupt, unless the tree is already being rebuilt - if (DependencyManager.VERBOSE) - JobManager.verbose("-> cannot reuse existing tree: "+ treeName +" path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$ - rebuildDTree(treeName, path); - return null; - } else { - dTree = null; // will fall thru to createIfMissing & create a empty tree for the rebuild all job to populate - } - } - } - if (currentDTreeState == SAVED_STATE) { // rebuild tree if existing file is missing - rebuildDTree(treeName, path); - return null; - } - - if (createIfMissing) { - try { - if (VERBOSE) - JobManager.verbose("-> create empty tree: "+treeName+" path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$ - dTree = new DependencyTree(treeName, "Tree for " + path.toOSString(), false /*do not reuse tree file*/); //$NON-NLS-1$ - dependencyTrees.put(path, dTree); - monitors.put(dTree, new ReadWriteMonitor()); - return dTree; - } catch (IOException e) { - if (VERBOSE) - JobManager.verbose("-> unable to create empty tree: "+treeName+" path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$ - // The file could not be created. Possible reason: the project has been deleted. - return null; - } - } - } - } - - return dTree; - } - - String computeTreeName(IPath path) { - String name = (String) projectNames.get(path); - if (name == null) { - String pathString = path.toOSString(); - checksumCalculator.reset(); - checksumCalculator.update(pathString.getBytes()); - String fileName = Long.toString(checksumCalculator.getValue()) + ".depTree"; //$NON-NLS-1$ - if (DependencyManager.VERBOSE) - JobManager.verbose("-> dependency tree name for " + pathString + " is " + fileName); //$NON-NLS-1$ //$NON-NLS-2$ - name = getCCorePluginWorkingLocation().append(fileName).toOSString(); - projectNames.put(path, name); - } - return name; - } - - private IPath getCCorePluginWorkingLocation() { - if (this.ccorePluginLocation != null) return this.ccorePluginLocation; - - return this.ccorePluginLocation = CCorePlugin.getDefault().getStateLocation(); - } - /** - * DTree access is controlled through a read-write monitor so as - * to ensure there is no concurrent read and write operations - * (only concurrent reading is allowed). - */ - public ReadWriteMonitor getMonitorFor(IDependencyTree dTree){ - return (ReadWriteMonitor) monitors.get(dTree); - } - - private SimpleLookupTable getTreeStates() { - if (dTreeStates != null) return dTreeStates; - - this.dTreeStates = new SimpleLookupTable(); - char[] savedDTreeNames = readDTreeState(); - if (savedDTreeNames.length > 0) { - char[][] names = CharOperation.splitOn('\n', savedDTreeNames); - for (int i = 0, l = names.length; i < l; i++) { - char[] name = names[i]; - if (name.length > 0) - this.dTreeStates.put(new String(name), SAVED_STATE); - } - } - return this.dTreeStates; - } - - private char[] readDTreeState() { - try { - return org.eclipse.cdt.internal.core.Util.getFileCharContent(savedDTreesFile, null); - } catch (IOException ignored) { - if (DependencyManager.VERBOSE) - JobManager.verbose("Failed to read saved dTree file names"); //$NON-NLS-1$ - return new char[0]; - } - } - - private void rebuildDTree(String treeName, IPath path) { - Object target = org.eclipse.cdt.internal.core.Util.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, true); - if (target == null) return; - - if (DependencyManager.VERBOSE) - JobManager.verbose("-> request to rebuild dTree: "+treeName+" path: "+path.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$ - - updateTreeState(treeName, REBUILDING_STATE); - DependencyRequest request = null; - if (target instanceof IProject) { - IProject p = (IProject) target; - request = new EntireProjectDependencyTree(p, this); - } - - if (request != null) - request(request); - } - /** - * Trigger addition of the entire content of a project - * Note: the actual operation is performed in background - */ - public void generateEntireDependencyTree(IProject project) { - if (CCorePlugin.getDefault() == null) return; - - /****** - *TODO: BOG Remove these methods once the depTree is - *fully integrated - */ -// if (!isEnabled(project)) return; - - // check if the same request is not already in the queue - DependencyRequest request = new EntireProjectDependencyTree(project, this); - for (int i = this.jobEnd; i > this.jobStart; i--) // NB: don't check job at jobStart, as it may have already started (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32488) - if (request.equals(this.awaitingJobs[i])) return; - this.request(request); - } - - private void updateTreeState(String treeName, Integer treeState) { - getTreeStates(); // ensure the states are initialized - if (treeState != null) { - if (treeState.equals(dTreeStates.get(treeName))) return; // not changed - dTreeStates.put(treeName, treeState); - } else { - if (!dTreeStates.containsKey(treeName)) return; // did not exist anyway - dTreeStates.removeKey(treeName); - } - - BufferedWriter writer = null; - try { - writer = new BufferedWriter(new FileWriter(savedDTreesFile)); - Object[] indexNames = dTreeStates.keyTable; - Object[] states = dTreeStates.valueTable; - for (int i = 0, l = states.length; i < l; i++) { - if (states[i] == SAVED_STATE) { - writer.write((String) indexNames[i]); - writer.write('\n'); - } - } - } catch (IOException ignored) { - if (DependencyManager.VERBOSE) - JobManager.verbose("Failed to write saved dTree file names"); //$NON-NLS-1$ - } finally { - if (writer != null) { - try { - writer.close(); - } catch (IOException e) {} - } - } - if (DependencyManager.VERBOSE) { - String state = "?"; //$NON-NLS-1$ - if (treeState == SAVED_STATE) state = "SAVED"; //$NON-NLS-1$ - else if (treeState == UPDATING_STATE) state = "UPDATING"; //$NON-NLS-1$ - else if (treeState == UNKNOWN_STATE) state = "UNKNOWN"; //$NON-NLS-1$ - else if (treeState == REBUILDING_STATE) state = "REBUILDING"; //$NON-NLS-1$ - JobManager.verbose("-> dTree state updated to: " + state + " for: "+treeName); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - public void jobWasCancelled(IPath path) { - Object o = this.dependencyTrees.get(path); - if (o instanceof IDependencyTree) { - this.monitors.remove(o); - this.dependencyTrees.remove(path); - } - updateTreeState(computeTreeName(path), UNKNOWN_STATE); - } - /** - * Trigger removal of a resource from a tree - * Note: the actual operation is performed in background - */ - public void remove(String resourceName, IPath indexedContainer){ - //request(new RemoveFromIndex(resourceName, indexedContainer, this)); - if (DependencyManager.VERBOSE) - JobManager.verbose("remove file from tree " + resourceName); - } - /** - * Removes the tree for a given path. - * This is a no-op if the tree did not exist. - */ - public synchronized void removeTree(IPath path) { - if (DependencyManager.VERBOSE) - JobManager.verbose("removing dependency tree " + path); //$NON-NLS-1$ - String treeName = computeTreeName(path); - File indexFile = new File(treeName); - if (indexFile.exists()) - indexFile.delete(); - Object o = this.dependencyTrees.get(path); - if (o instanceof IDependencyTree) - this.monitors.remove(o); - this.dependencyTrees.remove(path); - updateTreeState(treeName, null); - } - - public synchronized void addToTable(String fileName, IFile resource){ - ArrayList projectContainer = (ArrayList) dependencyTable.get(fileName); - if (projectContainer == null) { - ArrayList newProjectContainer = new ArrayList(); - newProjectContainer.add(resource.getLocation()); - - dependencyTable.put(fileName, newProjectContainer); - } - else { - if (!projectContainer.contains(resource.getLocation())){ - projectContainer.add(resource.getLocation()); - } - } - } - - public synchronized void removeFromTable(String fileName, IPath refToRemove){ - ArrayList projectContainer = (ArrayList) dependencyTable.get(fileName); - if (projectContainer != null) { - int index = projectContainer.indexOf(refToRemove); - projectContainer.remove(refToRemove); - } - } - - public synchronized ArrayList getProjectDependsForFile(String fileName){ - ArrayList projectContainer = (ArrayList) dependencyTable.get(fileName); - return projectContainer; - } - - /** - * @param file - * @param path - * @param info - */ - public void addSource(IFile file, IPath path, IScannerInfo info) { - if (CCorePlugin.getDefault() == null) return; - AddFileToDependencyTree job = new AddFileToDependencyTree(file, path, this, info); - if (this.awaitingJobsCount() < MAX_FILES_IN_MEMORY) { - // reduces the chance that the file is open later on, preventing it from being deleted - if (!job.initializeContents()) return; - } - request(job); - } - -// /************* -// *TODO: Remove these methods once the depTree is -// *fully integrated -// * START OF TEMP D-TREE ENABLE SECTION -// */ -// final static String DEP_MODEL_ID = CCorePlugin.PLUGIN_ID + ".dependencytree"; -// final static String ACTIVATION = "enable"; -// -// static QualifiedName activationKey = new QualifiedName(DEP_MODEL_ID, ACTIVATION); -// -// public boolean isEnabled(IProject project) { -// String prop = null; -// try { -// if (project != null) { -// prop = project.getPersistentProperty(activationKey); -// } -// } catch (CoreException e) { -// } -// return ((prop != null) && prop.equalsIgnoreCase("true")); -// } -// -// public void setEnabled(IProject project, boolean on) { -// try { -// if (project != null) { -// Boolean newValue = new Boolean(on); -// Boolean oldValue = new Boolean(isEnabled(project)); -// if (!oldValue.equals(newValue)) { -// project.setPersistentProperty(activationKey, newValue.toString()); -// if (on) { -// generateEntireDependencyTree(project); -// } else { -// //remove(project); -// } -// } -// } -// } catch (CoreException e) { -// } -// } -// -// /************ -// * END OF TEMP D-TREE ENABLE SECTION -// */ -} diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyQueryJob.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyQueryJob.java index ed558491f02..be478daf835 100644 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyQueryJob.java +++ b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyQueryJob.java @@ -3,14 +3,27 @@ */ package org.eclipse.cdt.internal.core.sourcedependency; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.core.search.SearchEngine; +import org.eclipse.cdt.internal.core.index.IDocument; +import org.eclipse.cdt.internal.core.index.IIndex; +import org.eclipse.cdt.internal.core.index.impl.BlocksIndexInput; +import org.eclipse.cdt.internal.core.index.impl.IFileDocument; +import org.eclipse.cdt.internal.core.index.impl.IncludeEntry; +import org.eclipse.cdt.internal.core.index.impl.IndexInput; +import org.eclipse.cdt.internal.core.index.impl.IndexedFile; +import org.eclipse.cdt.internal.core.search.IndexSelector; +import org.eclipse.cdt.internal.core.search.indexing.IndexManager; +import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor; import org.eclipse.cdt.internal.core.search.processing.IJob; +import org.eclipse.cdt.internal.core.search.processing.JobManager; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; /** * @author bgheorgh @@ -20,13 +33,14 @@ public class DependencyQueryJob implements IJob { IProject project; IFile file; ArrayList includeFiles; - DependencyManager depManager; - protected DependencySelector depSelector; + IndexManager indexManager; + protected IndexSelector indexSelector; + protected long executionTime = 0; - public DependencyQueryJob(IProject project, IFile file, DependencyManager depMan, List includeFiles) { + public DependencyQueryJob(IProject project, IFile file, IndexManager inMan, List includeFiles) { this.project = project; this.file = file; - this.depManager = depMan; + this.indexManager = inMan; this.includeFiles = (ArrayList) includeFiles; } @@ -46,27 +60,167 @@ public class DependencyQueryJob implements IJob { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.search.processing.IJob#execute(org.eclipse.core.runtime.IProgressMonitor) */ - public boolean execute(IProgressMonitor progress) { - - if ((project == null) ||(file == null)) return false; - - String[] tempFiles = this.depManager.getFileDependencies(project,file); - if (tempFiles != null){ - for (int i=0; i execution time: " + executionTime + "ms - " + this);//$NON-NLS-1$//$NON-NLS-2$ + } + return isComplete; + } finally { + if (progressMonitor != null) { + progressMonitor.done(); + } + } + } + + /** + * @param index + * @param progressMonitor + * @return + */ + public boolean getFileDeps(IIndex index, IProgressMonitor progressMonitor){ + + if (progressMonitor != null && progressMonitor.isCanceled()) + throw new OperationCanceledException(); + +// IIndex inMemIndex = indexManager.peekAtIndex(new Path(((Index)index).toString.substring("Index for ".length()).replace('\\','/'))); +// if (inMemIndex != index) { +// System.out.println("SANITY CHECK: search job using obsolete index: ["+index+ "] instead of: ["+inMemIndex+"]"); +// } + + if (index == null) + return COMPLETE; + ReadWriteMonitor monitor = indexManager.getMonitorFor(index); + if (monitor == null) + return COMPLETE; // index got deleted since acquired + try { + monitor.enterRead(); // ask permission to read + + /* if index has changed, commit these before querying */ + if (index.hasChanged()) { + try { + monitor.exitRead(); // free read lock + monitor.enterWrite(); // ask permission to write + this.indexManager.saveIndex(index); + } catch (IOException e) { + return FAILED; + } finally { + monitor.exitWriteEnterRead(); // finished writing and reacquire read permission + } } - return true; + long start = System.currentTimeMillis(); + // + IndexInput input = new BlocksIndexInput(index.getIndexFile()); + try { + input.open(); + findDep(input); + } finally { + input.close(); + } + // + //String[] tempFiles = this.indexManager.getFileDependencies(project,file); +// if (tempFiles != null){ +// System.out.println("DQJOB File Deps : " + tempFiles.length); +// for (int i=0; i 0 ) ? (IASTInclusion) includeStack.removeFirst() : null; - return oldInclude; - } - - private IASTInclusion peekInclude(){ - return currentInclude; - } -} diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencySelector.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencySelector.java deleted file mode 100644 index 1db318c57d1..00000000000 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencySelector.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Created on Aug 26, 2003 - */ -package org.eclipse.cdt.internal.core.sourcedependency; - -import java.util.ArrayList; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICModel; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.search.ICSearchScope; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; - -/** - * @author bgheorgh - */ -public class DependencySelector { - - /** - * - */ - public DependencySelector( - ICSearchScope searchScope, - ICElement focus, - boolean isPolymorphicSearch, - DependencyManager depManager) { - this.searchScope = searchScope; - this.focus = focus; - this.depManager = depManager; - this.isPolymorphicSearch = isPolymorphicSearch; - } - ICSearchScope searchScope; - ICElement focus; - DependencyManager depManager; - IPath[] treeKeys; // cache of the keys for looking index up - boolean isPolymorphicSearch; - - /** - * Returns whether elements of the given project can see the given focus (an ICProject) - */ - public static boolean canSeeFocus(ICElement focus, boolean isPolymorphicSearch, IPath projectPath) { - //TODO: BOG Temp - Provide Proper Impl - ICModel model = focus.getCModel(); - ICProject project = getCProject(projectPath, model); - return true; - } - /* - * Compute the list of paths which are keying index files. - */ - private void initializeIndexKeys() { - - ArrayList requiredIndexKeys = new ArrayList(); - IPath[] projects = this.searchScope.enclosingProjects(); - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - ICElement projectFocus = this.focus == null ? null : getProject(this.focus); - for (int i = 0; i < projects.length; i++) { - IPath location; - IPath path = projects[i]; - if ((!root.getProject(path.lastSegment()).exists()) // if project does not exist - && path.segmentCount() > 1 - && ((location = root.getFile(path).getLocation()) == null - || !new java.io.File(location.toOSString()).exists()) // and internal jar file does not exist - && !new java.io.File(path.toOSString()).exists()) { // and external jar file does not exist - continue; - } - if (projectFocus == null || canSeeFocus(projectFocus, this.isPolymorphicSearch, path)) { - if (requiredIndexKeys.indexOf(path) == -1) { - requiredIndexKeys.add(path); - } - } - } - this.treeKeys = new IPath[requiredIndexKeys.size()]; - requiredIndexKeys.toArray(this.treeKeys); - } - - public IDependencyTree[] getIndexes() { - if (this.treeKeys == null) { - this.initializeIndexKeys(); - } - // acquire the in-memory indexes on the fly - int length = this.treeKeys.length; - IDependencyTree[] indexes = new IDependencyTree[length]; - int count = 0; - for (int i = 0; i < length; i++){ - // may trigger some index recreation work - IDependencyTree index = depManager.getDependencyTree(treeKeys[i], true /*reuse index file*/, false /*do not create if none*/); - if (index != null) indexes[count++] = index; // only consider indexes which are ready yet - } - if (count != length) { - System.arraycopy(indexes, 0, indexes=new IDependencyTree[count], 0, count); - } - return indexes; - } - /** - * Returns the project that corresponds to the given path. - * Returns null if the path doesn't correspond to a project. - */ - private static ICProject getCProject(IPath path, ICModel model) { - ICProject project = model.getCProject(path.lastSegment()); - if (project.exists()) { - return project; - } else { - return null; - } - } - public static ICElement getProject(ICElement element) { - while (!(element instanceof ICProject)) { - element = element.getParent(); - } - return element; - } -} diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyTree.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyTree.java deleted file mode 100644 index 72498843374..00000000000 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyTree.java +++ /dev/null @@ -1,195 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.internal.core.sourcedependency; - -import java.io.File; -import java.io.IOException; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.core.parser.IPreprocessor; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.internal.core.index.IDocument; -import org.eclipse.cdt.internal.core.index.IQueryResult; -import org.eclipse.cdt.internal.core.index.impl.IndexedFile; -import org.eclipse.cdt.internal.core.sourcedependency.impl.InMemoryTree; -import org.eclipse.cdt.internal.core.sourcedependency.impl.IncludeEntry; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IPath; - - -public class DependencyTree implements IDependencyTree { - /** - * Maximum size of the index in memory. - */ - public static final int MAX_FOOTPRINT= 1000000; - protected InMemoryTree addsTree; - - public DependencyTree(String treeName, String string, boolean b) throws IOException{ - super(); - initialize(); - } - - public DependencyTree() throws IOException { - initialize(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.sourcedependency.IDependencyTree#empty() - */ - public void empty() throws IOException { - // TODO Auto-generated method stub - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.sourcedependency.IDependencyTree#getIndexFile() - */ - public File getIndexFile() { - // TODO Auto-generated method stub - return null; - } - /** - * Returns the number of referencing files in this tree. - */ - public int getNumDocuments() throws IOException { - return addsTree.getNumFiles(); - } - /** - * Returns the number of include entries in this tree. - * @return - * @throws IOException - */ - public int getNumIncludes() throws IOException { - return addsTree.getNumIncludes(); - } - /** - * Returns the path corresponding to a given document number - */ - public String getPath(int documentNumber) throws IOException { - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.sourcedependency.IDependencyTree#hasChanged() - */ - public boolean hasChanged() { - // TODO Auto-generated method stub - return false; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.sourcedependency.IDependencyTree#query(java.lang.String) - */ - public IQueryResult[] query(String word) throws IOException { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.sourcedependency.IDependencyTree#queryInDocumentNames(java.lang.String) - */ - public IQueryResult[] queryInDocumentNames(String word) - throws IOException { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.sourcedependency.IDependencyTree#save() - */ - public void save() throws IOException { - // TODO Auto-generated method stub - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.sourcedependency.IDependencyTree#remove(java.lang.String) - */ - public void remove(String documentName) throws IOException { - //IndexedFile file= addsTree.getIndexedFile(documentName); - //if (file != null) { - //} - - } - /** - * Add the file that will be preprocessed to the tree, create a new - * preprocessor output and preprocess! - */ - public void add(IDocument document, String docPath, IScannerInfo newInfo, IFile file, ParserLanguage language) throws IOException { - IndexedFile indexedFile= addsTree.getIndexedFile(document.getName()); - //if (indexedFile != null) - //remove(indexedFile, 0); - PreprocessorOutput output= new PreprocessorOutput(addsTree, file); - DependencyRequestor depReq = new DependencyRequestor(output,document); - - output.addDocument(document); - - IPreprocessor preprocessor = ParserFactory.createPreprocessor( new StringReader( document.getStringContent() ),docPath , newInfo, ParserMode.COMPLETE_PARSE, language, depReq); - preprocessor.process(); - } - /** - * Initialises the indexGenerator. - */ - public void initialize() throws IOException { - //initialisation of addsTree - addsTree= new InMemoryTree(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.sourcedependency.IDependencyTree#getFileDepencies(int) - */ - public String[] getFileDependencies(IPath filePath) throws IOException { - List tempFileReturn = new ArrayList(); - IndexedFile indexFile = addsTree.getIndexedFile(filePath.toString()); - - if (indexFile == null) - return new String[0]; - - int fileNum = indexFile.getFileNumber(); - IncludeEntry[] tempEntries = addsTree.getIncludeEntries(); - for (int i=0; i= MAX_FOOTPRINT); - } -} diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/EntireProjectDependencyTree.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/EntireProjectDependencyTree.java deleted file mode 100644 index eea64209516..00000000000 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/EntireProjectDependencyTree.java +++ /dev/null @@ -1,200 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.internal.core.sourcedependency; - -import java.util.HashSet; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.IScannerInfoProvider; -import org.eclipse.cdt.internal.core.Util; -import org.eclipse.cdt.internal.core.index.IQueryResult; -import org.eclipse.cdt.internal.core.index.impl.IFileDocument; -import org.eclipse.cdt.internal.core.search.SimpleLookupTable; -import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor; -import org.eclipse.cdt.internal.core.search.processing.JobManager; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceProxy; -import org.eclipse.core.resources.IResourceProxyVisitor; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -/** - * @author bgheorgh - */ -public class EntireProjectDependencyTree extends DependencyRequest { - IProject project; - - public EntireProjectDependencyTree(IProject project, DependencyManager manager) { - super(project.getFullPath(), manager); - this.project = project; - } - - public boolean equals(Object o) { - if (o instanceof EntireProjectDependencyTree) - return this.project.equals(((EntireProjectDependencyTree) o).project); - return false; - } - - public boolean execute(IProgressMonitor progressMonitor) { - - if (progressMonitor != null && progressMonitor.isCanceled()) return true; - if (!project.isAccessible()) return true; // nothing to do - - IDependencyTree dTree = this.manager.getDependencyTree(this.dependencyTreePath, true, /*reuse index file*/ true /*create if none*/); - if (dTree == null) return true; - ReadWriteMonitor monitor = this.manager.getMonitorFor(dTree); - if (monitor == null) return true; // tree got deleted since acquired - - try { - monitor.enterRead(); // ask permission to read - saveIfNecessary(dTree, monitor); - - IQueryResult[] results = dTree.queryInDocumentNames(""); // get all file names already stored in this project //$NON-NLS-1$ - int max = results == null ? 0 : results.length; - final SimpleLookupTable indexedFileNames = new SimpleLookupTable(max == 0 ? 33 : max + 11); - final String OK = "OK"; //$NON-NLS-1$ - final String DELETED = "DELETED"; //$NON-NLS-1$ - for (int i = 0; i < max; i++) - indexedFileNames.put(results[i].getPath(), DELETED); - final long indexLastModified = max == 0 ? 0L : dTree.getIndexFile().lastModified(); - - IPath cProjectPath = project.getFullPath(); - - IWorkspaceRoot root = this.project.getWorkspace().getRoot(); - IResource sourceFolder = root.findMember(cProjectPath); - - if (this.isCancelled) return false; - - if (sourceFolder != null) { - - //collect output locations if source is project (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32041) - final HashSet outputs = new HashSet(); - - final boolean hasOutputs = !outputs.isEmpty(); - - final char[][] patterns = null; - if (max == 0) { - sourceFolder.accept( - new IResourceProxyVisitor() { - public boolean visit(IResourceProxy proxy) { - if (isCancelled) return false; - switch(proxy.getType()) { - case IResource.FILE : -// TODO: BOG Put the file name checking back - //if (Util.isCCFileName(proxy.getName())) { - IResource resource = proxy.requestResource(); - if (resource.getLocation() != null && (patterns == null || !Util.isExcluded(resource, patterns))) { - String name = new IFileDocument((IFile) resource).getName(); - indexedFileNames.put(name, resource); - } - //} - return false; - - case IResource.FOLDER : - if (patterns != null && Util.isExcluded(proxy.requestResource(), patterns)) - return false; - if (hasOutputs && outputs.contains(proxy.requestFullPath())) { - return false; - } - } - return true; - } - }, - IResource.NONE - ); - } else { - sourceFolder.accept( - new IResourceProxyVisitor() { - public boolean visit(IResourceProxy proxy) { - if (isCancelled) return false; - switch(proxy.getType()) { - case IResource.FILE : -// TODO: BOG Put the file name checking back - // if (Util.isCCFileName(proxy.getName())) { - IResource resource = proxy.requestResource(); - IPath path = resource.getLocation(); - if (path != null && (patterns == null || !Util.isExcluded(resource, patterns))) { - String name = new IFileDocument((IFile) resource).getName(); - indexedFileNames.put(name, - indexedFileNames.get(name) == null || indexLastModified < path.toFile().lastModified() - ? (Object) resource - : (Object) OK); - } - //} - return false; - case IResource.FOLDER : - if (patterns != null && Util.isExcluded(proxy.requestResource(), patterns)) - return false; - if (hasOutputs && outputs.contains(proxy.requestFullPath())) { - return false; - } - } - return true; - } - }, - IResource.NONE - ); - } - } - - Object[] names = indexedFileNames.keyTable; - Object[] values = indexedFileNames.valueTable; - boolean shouldSave = false; - for (int i = 0, length = names.length; i < length; i++) { - String name = (String) names[i]; - if (name != null) { - if (this.isCancelled) return false; - - Object value = values[i]; - if (value != OK) { - shouldSave = true; - if (value == DELETED) - this.manager.remove(name, this.dependencyTreePath); - else{ - IScannerInfo scanInfo = null; - IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project); - if (provider != null){ - scanInfo = provider.getScannerInformation(project); - } - this.manager.addSource((IFile) value, this.dependencyTreePath, scanInfo); - } - } - } - } - } catch (/*IO*/Exception e) { - if (DependencyManager.VERBOSE) { - JobManager.verbose("-> failed to generate tree " + this.project + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$ - e.printStackTrace(); - } - this.manager.removeTree(this.dependencyTreePath); - return false; - } finally { - monitor.exitRead(); // free read lock - } - return true; - } - - public int hashCode() { - return this.project.hashCode(); - } - - protected Integer updatedIndexState() { - return DependencyManager.REBUILDING_STATE; - } - - public String toString() { - return "calculating dependency tree for project " + this.project.getFullPath(); //$NON-NLS-1$ - } -} diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/IDependencyTree.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/IDependencyTree.java deleted file mode 100644 index b798594b7bd..00000000000 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/IDependencyTree.java +++ /dev/null @@ -1,85 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.internal.core.sourcedependency; - -import java.io.File; -import java.io.IOException; - -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.internal.core.index.IDocument; -import org.eclipse.cdt.internal.core.index.IQueryResult; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IPath; - -public interface IDependencyTree { - /** - * Adds the given document to the index. - */ - void add(IDocument document, String docPath, IScannerInfo newInfo, IFile file, ParserLanguage language) throws IOException; - - /** - * Empties the index. - */ - void empty() throws IOException; - /** - * Returns the index file on the disk. - */ - File getIndexFile(); - /** - * Returns the number of documents indexed. - */ - int getNumDocuments() throws IOException; - /** - * Returns the number of unique words indexed. - */ - int getNumIncludes() throws IOException; - /** - * Returns the path corresponding to a given document number - */ - String getPath(int documentNumber) throws IOException; - /** - * Ansers true if has some changes to save. - */ - boolean hasChanged(); - /** - * Returns the paths of the documents containing the given word. - */ - IQueryResult[] query(String word) throws IOException; - /** - * Returns the paths of the documents whose names contain the given word. - */ - IQueryResult[] queryInDocumentNames(String word) throws IOException; - - /** - * Removes the corresponding document from the tree. - */ - void remove(String documentName) throws IOException; - /** - * Saves the index on the disk. - */ - void save() throws IOException; - /** - * Gets the files that are included by the passed in file. - */ - String[] getFileDependencies(IPath filePath) throws IOException; - // TODO: BOG Debug Method Take out - /** - * Prints all of the IncludeEntries for this project. - */ - public void printIncludeEntries(); - // TODO: BOG Debug Method Take out - /** - * Prints all of the IndexedFiles for this project. - */ - public void printIndexedFiles(); -} diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/IPreprocessorOutput.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/IPreprocessorOutput.java deleted file mode 100644 index 109545eb7f0..00000000000 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/IPreprocessorOutput.java +++ /dev/null @@ -1,20 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.internal.core.sourcedependency; - -import org.eclipse.cdt.internal.core.index.IDocument; - -public interface IPreprocessorOutput { - public void addDocument(IDocument document); - public void addRef(char[] word); - public void addRef(String word); -} diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/ISourceDependency.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/ISourceDependency.java deleted file mode 100644 index eb6e35293ab..00000000000 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/ISourceDependency.java +++ /dev/null @@ -1,19 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.internal.core.sourcedependency; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; - -public interface ISourceDependency { - IProject[] getProjects(IFile file); - String[] getFileDependencies(IProject project, IFile file); -} diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/Node.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/Node.java similarity index 94% rename from core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/Node.java rename to core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/Node.java index 2d608b7d271..c798ad87726 100644 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/Node.java +++ b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/Node.java @@ -9,7 +9,7 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.internal.core.sourcedependency.impl; +package org.eclipse.cdt.internal.core.sourcedependency; /** * @author bgheorgh diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/PreprocessorOutput.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/PreprocessorOutput.java deleted file mode 100644 index e4bbd08c02d..00000000000 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/PreprocessorOutput.java +++ /dev/null @@ -1,66 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.internal.core.sourcedependency; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.internal.core.index.IDocument; -import org.eclipse.cdt.internal.core.index.impl.IndexedFile; -import org.eclipse.cdt.internal.core.sourcedependency.impl.InMemoryTree; -import org.eclipse.core.resources.IFile; - - -public class PreprocessorOutput implements IPreprocessorOutput { - protected InMemoryTree tree; - protected IndexedFile indexedFile; - protected IDocument document; - protected IFile file; - - public PreprocessorOutput(InMemoryTree tree, IFile file) { - this.tree = tree; - this.file = file; - } - - public void addInclude(IASTInclusion inclusion, IASTInclusion parent){ - addRef(inclusion.getFullFileName()); - addRelatives(inclusion.getFullFileName(),(parent != null ) ? parent.getFullFileName() : null); - - DependencyManager depMan = CCorePlugin.getDefault().getCoreModel().getDependencyManager(); - depMan.addToTable(inclusion.getFullFileName(),this.file); - - } - - public void addRelatives(String inclusion, String parent) { - if (indexedFile == null) { - throw new IllegalStateException(); - } - tree.addRelatives(indexedFile, inclusion, parent); - } - - public void addDocument(IDocument document) { - if (indexedFile == null) { - indexedFile= tree.addDocument(document); - } else { - throw new IllegalStateException(); - } - } - - public void addRef(char[] word) { - if (indexedFile == null) { - throw new IllegalStateException(); - } - tree.addRef(indexedFile, word); - } - - public void addRef(String word) { - addRef(word.toCharArray()); - } -} diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/RemoveFromDependencyTree.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/RemoveFromDependencyTree.java deleted file mode 100644 index b9c1591ba2a..00000000000 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/RemoveFromDependencyTree.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Created on Sep 5, 2003 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.cdt.internal.core.sourcedependency; - -import java.io.IOException; - -import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor; -import org.eclipse.cdt.internal.core.search.processing.JobManager; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * @author bgheorgh - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class RemoveFromDependencyTree extends DependencyRequest { - String resourceName; - - public RemoveFromDependencyTree(String resourceName, IPath dependencyTreePath, DependencyManager manager) { - super(dependencyTreePath, manager); - this.resourceName = resourceName; - } - - public boolean execute(IProgressMonitor progressMonitor) { - - if (progressMonitor != null && progressMonitor.isCanceled()) return true; - - /* ensure no concurrent write access to index */ - IDependencyTree depTree = manager.getDependencyTree(this.dependencyTreePath, true, /*reuse index file*/ false /*create if none*/); - if (depTree == null) return true; - ReadWriteMonitor monitor = manager.getMonitorFor(depTree); - if (monitor == null) return true; // index got deleted since acquired - - try { - monitor.enterWrite(); // ask permission to write - depTree.remove(resourceName); - } catch (IOException e) { - if (DependencyManager.VERBOSE) { - JobManager.verbose("-> failed to remove " + this.resourceName + " from index because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$ - e.printStackTrace(); - } - return false; - } finally { - monitor.exitWrite(); // free write lock - } - return true; - } - - public String toString() { - return "removing " + this.resourceName + " from dep Tree " + this.dependencyTreePath; //$NON-NLS-1$ //$NON-NLS-2$ - } -} diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/InMemoryTree.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/InMemoryTree.java deleted file mode 100644 index dbc39409994..00000000000 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/InMemoryTree.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 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.internal.core.sourcedependency.impl; - -import org.eclipse.cdt.internal.core.index.IDocument; -import org.eclipse.cdt.internal.core.index.impl.IndexedFile; -import org.eclipse.cdt.internal.core.index.impl.IndexedFileHashedArray; - -public class InMemoryTree { - - /** - * hashtable of IncludeEntrys = includeFiles+numbers of the files they appear in. - */ - protected IncludeEntryHashedArray includes; - /** - * List of IndexedFiles = file name + a unique number. - */ - protected IndexedFileHashedArray files; - /** - * Size of the tree. - */ - protected long footprint; - private int lastId; - - public InMemoryTree() { - init(); - } - /** - * Initialises the fields of the tree - */ - public void init() { - includes= new IncludeEntryHashedArray(501); - files= new IndexedFileHashedArray(101); - footprint= 0; - lastId=0; - } - - public IndexedFile addDocument(IDocument document) { - IndexedFile indexedFile= this.files.add(document); - this.footprint += indexedFile.footprint() + 4; - - return indexedFile; - } - /** - * Adds the references of the include to the tree (reference = number of the file the include belongs to). - */ - protected void addRef(char[] include, int[] references) { - int size= references.length; - int i= 0; - while (i < size) { - if (references[i] != 0) - addRef(include, references[i]); - i++; - } - } - /** - * Looks if the include already exists to the tree and adds the fileNum to this include. - * If the include does not exist, it adds it to the tree. - */ - protected void addRef(char[] include, int fileNum) { - IncludeEntry entry= (IncludeEntry) this.includes.get(include); - if (entry == null) { - entry= new IncludeEntry(include, ++lastId); - entry.addRef(fileNum); - this.includes.add(entry); - } else { - this.footprint += entry.addRef(fileNum); - } - } - - public void addRef(IndexedFile indexedFile, char[] include) { - addRef(include, indexedFile.getFileNumber()); - } - - public void addRef(IndexedFile indexedFile, String include) { - addRef(include.toCharArray(), indexedFile.getFileNumber()); - } - /** - * Returns the indexed file with the given path, or null if such file does not exist. - */ - public IndexedFile getIndexedFile(String path) { - return files.get(path); - } - /** - * @see IIndex#getNumDocuments() - */ - public int getNumFiles() { - return files.size(); - } - /** - * @see IIndex#getNumWords() - */ - public int getNumIncludes() { - return includes.elementSize; - } - - /** - * Returns the include entry corresponding to the given include. - */ - protected IncludeEntry getIncludeEntry(char[] include) { - return (IncludeEntry) includes.get(include); - } - - public void addRelatives(IndexedFile indexedFile, String inclusion, String parent) { - addRelatives(indexedFile.getFileNumber(),inclusion.toCharArray(),(parent != null ) ? parent.toCharArray() : null); - } - - protected void addRelatives(int fileNumber, char[] inclusion, char[] parent) { - IncludeEntry childEntry=null; - IncludeEntry parentEntry=null; - - if (inclusion != null) - childEntry= (IncludeEntry) this.includes.get(inclusion); - - if (parent != null) - parentEntry= (IncludeEntry) this.includes.get(parent); - - - childEntry.addParent(fileNumber,(parentEntry!=null) ? parentEntry.getID() : -1); - - if (parent!=null) - parentEntry.addChild(fileNumber,(childEntry!=null) ? childEntry.getID() : -1); - } - /** - * Returns the include entries contained in the hashtable of includes. - */ - public IncludeEntry[] getIncludeEntries() { - return this.includes.asArray(); - } - - public IndexedFile[] getIndexedFiles(){ - return this.files.asArray(); - } - - /** - * Returns the footprint of the index. - */ - public long getFootprint() { - return this.footprint; - } -} diff --git a/core/org.eclipse.cdt.core/index/ChangeLog b/core/org.eclipse.cdt.core/index/ChangeLog index 63fe25cc54a..af4719a1942 100644 --- a/core/org.eclipse.cdt.core/index/ChangeLog +++ b/core/org.eclipse.cdt.core/index/ChangeLog @@ -1,3 +1,35 @@ +2003-09-25 Bogdan Gheorghe + Integrated the dependency service into the indexer. Changes + as follows: + + org.eclipse.cdt.internal.core.index.impl: + * IIndex - added getFileDependencies methods + * IIndexerOutput - modified to allow dep inputs into the index + * BlocksIndexInput - modified to allow the reading of the new index (which includes dep entries) + * BlocksIndexOutput - added facilities to write includes to the index + * GammaCompressedIndexBlock - modified with addIncludeEntry() and nextEntry() + * IncludeEntry - new file + * IncludeEntryHashedArray - new file + * Index - Added getFileDepenendencies to query includeEntries from the index + * IndexBlock - modified to reflect changes in GammaCompressedIndexBlock + * IndexerOutput - added new methods from IIndexerOutput + * IndexInput - modified to allow reading of includes from index files + * IndexSummary - modified to save/read new format which contains include info + * InMemoryIndex - modified InMemoryIndex to keep track of includes + * MergeFactory - modified MergeFactory to accomodate new index file format + * SimpleIndexInput - modified to use the new functions for includes in InMemoryIndex + * Util - Added a quickSort for includeEntry[] + + org.eclipse.cdt.internal.core.search.indexing: + * AbstractIndexer - modified to getResourceFile being indexed, added bestIncludePrefix + to find include table entries, addInclude() which accepts IASTInclusion node and adds it + to the index + * IIndexConstants - added includeRef constant + * IndexManager - got rid of all dependency table references + * SourceIndexer - modified to return resource being indexed + * SourceIndexerRequestor - Added inclusion handling code; stack for includes + + 2003-09-22 Bogdan Gheorghe Took out the old CTags Indexer. Modified IndexAllProject to get diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndex.java index d14f99d7ea0..583c32cd1b8 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndex.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndex.java @@ -13,6 +13,9 @@ package org.eclipse.cdt.internal.core.index; import java.io.File; import java.io.IOException; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IPath; + /** * An IIndex is the interface used to generate an index file, and to make queries on * this index. @@ -71,5 +74,11 @@ public interface IIndex { * Saves the index on the disk. */ void save() throws IOException; + /** + * @param path + * @return + */ + String[] getFileDependencies(IPath path) throws IOException; + String[] getFileDependencies(IFile file) throws IOException; } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexerOutput.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexerOutput.java index be1cee2d18a..19d575bb697 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexerOutput.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexerOutput.java @@ -19,4 +19,8 @@ public interface IIndexerOutput { public void addDocument(IDocument document); public void addRef(char[] word); public void addRef(String word); + //For Dep Tree + public void addIncludeRef(char[] word); + public void addIncludeRef(String word); + public void addRelatives(String inclusion, String parent); } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java index 622253fc82b..7cebcc52297 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java @@ -31,6 +31,7 @@ public class BlocksIndexInput extends IndexInput { protected int currentFileListBlockNum; protected int currentIndexBlockNum; protected IndexBlock currentIndexBlock; + protected IndexBlock currentIncludeIndexBlock; private RandomAccessFile raf; protected File indexFile; protected LRUCache blockCache; @@ -156,6 +157,12 @@ public class BlocksIndexInput extends IndexInput { public int getNumWords() { return summary.getNumWords(); } + /** + * @see IndexInput#getNumIncludes() + */ + public int getNumIncludes() { + return summary.getNumIncludes(); + } /** * @see IndexInput#getSource() */ @@ -169,6 +176,7 @@ public class BlocksIndexInput extends IndexInput { clearCache(); setFirstFile(); setFirstWord(); + setFirstInclude(); } /** * @see IndexInput#moveToNextFile() @@ -388,4 +396,79 @@ public class BlocksIndexInput extends IndexInput { currentIndexBlock.nextEntry(currentWordEntry); } } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.index.impl.IndexInput#moveToNextIncludeEntry() + */ + public void moveToNextIncludeEntry() throws IOException { + includePosition++; + if (!hasMoreIncludes()) { + return; + } + //if end of the current block, we load the next one. + boolean endOfBlock= !currentIncludeIndexBlock.nextEntry(currentIncludeEntry); + if (endOfBlock) { + currentIncludeIndexBlock= getIndexBlock(++currentIndexBlockNum); + currentIncludeIndexBlock.nextEntry(currentWordEntry); + } + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.index.impl.IndexInput#setFirstInclude() + */ + protected void setFirstInclude() throws IOException { + includePosition= 1; + if (getNumIncludes() > 0) { + currentIndexBlockNum= summary.getFirstIncludeBlockNum(); + currentIncludeIndexBlock= getIndexBlock(currentIndexBlockNum); + currentIncludeEntry= new IncludeEntry(0); + currentIncludeIndexBlock.reset(); + currentIncludeIndexBlock.nextEntry(currentIncludeEntry); + } + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.index.impl.IndexInput#queryIncludeEntries() + */ + public IncludeEntry[] queryIncludeEntries() { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.index.impl.IndexInput#queryIncludeEntries(int) + */ + public IncludeEntry[] queryIncludeEntries(int fileNum) throws IOException { + open(); + + if (fileNum < 0) return null; + int[] blockNums = null; + blockNums = summary.getBlockNumsForIncludes(); + + if (blockNums == null || blockNums.length == 0) return null; + + IncludeEntry[] entries = new IncludeEntry[5]; + int count = 0; + for (int i = 0, max = blockNums.length; i < max; i++) { + IndexBlock block = getIndexBlock(blockNums[i]); + block.reset(); + boolean found = false; + IncludeEntry entry = new IncludeEntry(0); + + while (block.nextEntry(entry)) { + if (count == entries.length){ + System.arraycopy(entries, 0, entries = new IncludeEntry[count*2], 0, count); + } + for (int j=0; j this.blockSize - 2) { + return false; + } + byte[] bytes= writeCodeStream.toByteArray(); + field.put(offset, bytes); + offset += bytes.length; + prevWord= entry.getFile(); + return true; + } + /** + * @param entry + * @param prevWord + * @param writeCodeStream + */ + protected void encodeEntry(IncludeEntry entry, char[] prevWord, CodeByteStream codeStream) { + char[] file= entry.getFile(); + int prefixLen= prevWord == null ? 0 : Util.prefixLength(prevWord, file); + codeStream.writeByte(prefixLen); + codeStream.writeUTF(file, prefixLen, file.length); + int n= entry.getNumRefs(); + codeStream.writeGamma(n); + int prevRef= 0; + for (int i= 0; i < n; ++i) { + int ref= entry.getRef(i); + if (ref <= prevRef) + throw new IllegalArgumentException(); + codeStream.writeGamma(ref - prevRef); + prevRef= ref; + } + + } /** * @see IndexBlock#flush */ @@ -106,6 +143,40 @@ public class GammaCompressedIndexBlock extends IndexBlock { return false; } } + /** + * @see IndexBlock#nextEntry + */ + public boolean nextEntry(IncludeEntry entry) { + try { + readCodeStream.reset(field.buffer(), offset); + int prefixLength= readCodeStream.readByte(); + char[] file= readCodeStream.readUTF(); + if (prevWord != null && prefixLength > 0) { + char[] temp= new char[prefixLength + file.length]; + System.arraycopy(prevWord, 0, temp, 0, prefixLength); + System.arraycopy(file, 0, temp, prefixLength, file.length); + file= temp; + } + if (file.length == 0) { + return false; + } + entry.reset(file); + int n= readCodeStream.readGamma(); + int prevRef= 0; + for (int i= 0; i < n; ++i) { + int ref= prevRef + readCodeStream.readGamma(); + if (ref < prevRef) + throw new InternalError(); + entry.addRef(ref); + prevRef= ref; + } + offset= readCodeStream.byteLength(); + prevWord= file; + return true; + } catch (UTFDataFormatException e) { + return false; + } + } /** * @see IndexBlock#reset */ @@ -114,5 +185,6 @@ public class GammaCompressedIndexBlock extends IndexBlock { offset= 0; prevWord= null; } + } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IIndexConstants.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IIndexConstants.java index 8737b4b4ee8..f464514d5d6 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IIndexConstants.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IIndexConstants.java @@ -17,7 +17,7 @@ public interface IIndexConstants { /** * The signature of the index file. */ - public static final String SIGNATURE= "INDEX FILE 0.012"; //$NON-NLS-1$ + public static final String SIGNATURE= "INDEX FILE 0.014"; //$NON-NLS-1$ /** * The separator for files in the index file. */ diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/InMemoryIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/InMemoryIndex.java index 943bf9186f6..70c31e4e008 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/InMemoryIndex.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/InMemoryIndex.java @@ -22,6 +22,10 @@ import org.eclipse.cdt.internal.core.index.IDocument; public class InMemoryIndex { + /** + * hashtable of IncludeEntrys = includeFiles+numbers of the files they appear in. + */ + protected IncludeEntryHashedArray includes; /** * hashtable of WordEntrys = words+numbers of the files they appear in. */ @@ -35,9 +39,14 @@ public class InMemoryIndex { */ protected long footprint; + private IncludeEntry[] sortedIncludeEntries; private WordEntry[] sortedWordEntries; private IndexedFile[] sortedFiles; + + private int lastId; + public InMemoryIndex() { + includes= new IncludeEntryHashedArray(501); init(); } @@ -47,6 +56,46 @@ public class InMemoryIndex { this.sortedFiles = null; return indexedFile; } + + public void addIncludeRef(IndexedFile indexedFile, char[] include) { + addIncludeRef(include, indexedFile.getFileNumber()); + } + + public void addIncludeRef(IndexedFile indexedFile, String include) { + addIncludeRef(include.toCharArray(), indexedFile.getFileNumber()); + } + + /** + * Adds the references of the include to the tree (reference = number of the file the include belongs to). + */ + protected void addIncludeRef(char[] include, int[] references) { + int size= references.length; + int i= 0; + while (i < size) { + if (references[i] != 0) + addIncludeRef(include, references[i]); + i++; + } + } + /** + * Looks if the include already exists to the tree and adds the fileNum to this include. + * If the include does not exist, it adds it to the tree. + */ + protected void addIncludeRef(char[] include, int fileNum) { + IncludeEntry entry= (IncludeEntry) this.includes.get(include); + if (entry == null) { + entry= new IncludeEntry(include, ++lastId); + entry.addRef(fileNum); + this.includes.add(entry); + this.sortedIncludeEntries= null; + //TODO: BOG FIGURE OUT FOOTPRINT + //this.footprint += entry.getClass(); //footprint(); + // + } else { + this.footprint += entry.addRef(fileNum); + } + } + /** * Adds the references of the word to the index (reference = number of the file the word belongs to). */ @@ -83,18 +132,57 @@ public class InMemoryIndex { public void addRef(IndexedFile indexedFile, String word) { addRef(word.toCharArray(), indexedFile.getFileNumber()); } + + public void addRelatives(IndexedFile indexedFile, String inclusion, String parent) { + addRelatives(indexedFile.getFileNumber(),inclusion.toCharArray(),(parent != null ) ? parent.toCharArray() : null); + } + + protected void addRelatives(int fileNumber, char[] inclusion, char[] parent) { + IncludeEntry childEntry=null; + IncludeEntry parentEntry=null; + + if (inclusion != null) + childEntry= (IncludeEntry) this.includes.get(inclusion); + + if (parent != null) + parentEntry= (IncludeEntry) this.includes.get(parent); + + + childEntry.addParent(fileNumber,(parentEntry!=null) ? parentEntry.getID() : -1); + + if (parent!=null) + parentEntry.addChild(fileNumber,(childEntry!=null) ? childEntry.getID() : -1); + } /** * Returns the footprint of the index. */ public long getFootprint() { return this.footprint; } + /** + * Returns the indexed files contained in the hashtable of includes. + */ + public IndexedFile[] getIndexedFiles(){ + return this.files.asArray(); + } /** * Returns the indexed file with the given path, or null if such file does not exist. */ public IndexedFile getIndexedFile(String path) { return files.get(path); } + /** + * Returns the include entries contained in the hashtable of includes. + */ + public IncludeEntry[] getIncludeEntries() { + return this.includes.asArray(); + } + /** + * Returns the include entry corresponding to the given include. + */ + protected IncludeEntry getIncludeEntry(char[] include) { + return (IncludeEntry) includes.get(include); + } /** * @see IIndex#getNumDocuments() */ @@ -107,6 +195,11 @@ public class InMemoryIndex { public int getNumWords() { return words.elementSize; } + + public int getNumIncludes() { + return includes.elementSize; + } + /** * Returns the words contained in the hashtable of words, sorted by alphabetical order. */ @@ -129,6 +222,17 @@ public class InMemoryIndex { } return this.sortedWordEntries; } + /** + * Returns the include entries contained in the hashtable of includeas, sorted by alphabetical order. + */ + protected IncludeEntry[] getSortedIncludeEntries() { + if (this.sortedIncludeEntries == null) { + IncludeEntry[] includes= this.includes.asArray(); + Util.sort(includes); + this.sortedIncludeEntries= includes; + } + return this.sortedIncludeEntries; + } /** * Returns the word entry corresponding to the given word. */ @@ -139,11 +243,14 @@ public class InMemoryIndex { * Initialises the fields of the index */ public void init() { + includes= new IncludeEntryHashedArray(501); words= new WordEntryHashedArray(501); files= new IndexedFileHashedArray(101); footprint= 0; + lastId=0; sortedWordEntries= null; sortedFiles= null; + sortedIncludeEntries=null; } /** * Saves the index in the given file. diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntry.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IncludeEntry.java similarity index 71% rename from core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntry.java rename to core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IncludeEntry.java index 0a0ca38ee87..7495ac6e54a 100644 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntry.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IncludeEntry.java @@ -9,12 +9,13 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.internal.core.sourcedependency.impl; +package org.eclipse.cdt.internal.core.index.impl; import java.util.ArrayList; import java.util.Iterator; import org.eclipse.cdt.internal.core.CharOperation; +import org.eclipse.cdt.internal.core.sourcedependency.Node; /** * @author bgheorgh @@ -30,7 +31,7 @@ public class IncludeEntry { protected ArrayList fChild; protected int fNumParent; protected int fNumChild; - + public IncludeEntry(int id) { this(CharOperation.NO_CHAR,id); } @@ -69,6 +70,51 @@ public class IncludeEntry { fParent.add(newParent); fNumParent++; } + /** + * @param is + */ + public void addRefs(int[] refs) { + int[] newRefs= new int[fNumRefs + refs.length]; + int pos1= 0; + int pos2= 0; + int posNew= 0; + int compare; + int r1= 0; + int r2= 0; + while (pos1 < fNumRefs || pos2 < refs.length) { + if (pos1 >= fNumRefs) { + r2= refs[pos2]; + compare= -1; + } else if (pos2 >= refs.length) { + compare= 1; + r1= fRefs[pos1]; + } else { + r1= fRefs[pos1]; + r2= refs[pos2]; + compare= r2 - r1; + } + if (compare > 0) { + newRefs[posNew]= r1; + posNew++; + pos1++; + } else { + if (r2 != 0) { + newRefs[posNew]= r2; + posNew++; + } + pos2++; + } + } + fRefs= newRefs; + fNumRefs= posNew; + /*for (int i = 0; i < refs.length; i++) + addRef(refs[i]); + int[] newRefs = new int[fNumRefs]; + System.arraycopy(fRefs, 0, newRefs, 0, fNumRefs); + fRefs = newRefs; + Util.sort(fRefs);*/ + + } public void addChild(int fileRef, int parentId){ Node newChild = new Node(fileRef,parentId); @@ -102,7 +148,26 @@ public class IncludeEntry { public char[] getFile() { return fFile; } - + /** + * Changes the references of the wordEntry to match the mapping. For example,
+ * if the current references are [1 3 4]
+ * and mapping is [1 2 3 4 5]
+ * in references 1 becomes mapping[1] = 2, 3->4, and 4->5
+ * => references = [2 4 5].
+ */ + public void mapRefs(int[] mappings) { + int position= 0; + for (int i= 0; i < fNumRefs; i++) { + int map= mappings[fRefs[i]]; + if (map != -1 && map != 0) + fRefs[position++]= map; + } + fNumRefs= position; + + //to be changed! + System.arraycopy(fRefs, 0, (fRefs= new int[fNumRefs]), 0, fNumRefs); + Util.sort(fRefs); + } /** * Clears the includeEntry. */ @@ -155,5 +220,4 @@ public class IncludeEntry { tempBuffer.append("} >"); return tempBuffer.toString(); } - } diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntryHashedArray.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IncludeEntryHashedArray.java similarity index 97% rename from core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntryHashedArray.java rename to core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IncludeEntryHashedArray.java index 584e1726363..3c7bc80c5b6 100644 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntryHashedArray.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IncludeEntryHashedArray.java @@ -9,7 +9,7 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.internal.core.sourcedependency.impl; +package org.eclipse.cdt.internal.core.index.impl; import org.eclipse.cdt.internal.core.CharOperation; diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java index d62f4138049..b2ac5af28f0 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java @@ -12,7 +12,9 @@ package org.eclipse.cdt.internal.core.index.impl; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.eclipse.cdt.internal.core.index.IDocument; @@ -20,6 +22,8 @@ import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.index.IIndexer; import org.eclipse.cdt.internal.core.index.IQueryResult; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IPath; /** * An Index is used to create an index on the disk, and to make queries. It uses a set of @@ -167,6 +171,19 @@ public class Index implements IIndex { input.close(); } } + /** + * @see IIndex#getNumWords + */ + public int getNumIncludes() throws IOException { + //save(); + IndexInput input= new BlocksIndexInput(indexFile); + try { + input.open(); + return input.getNumIncludes(); + } finally { + input.close(); + } + } /** * Returns the path corresponding to a given document number */ @@ -302,6 +319,63 @@ public class Index implements IIndex { input.close(); } } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.sourcedependency.IDependencyTree#getFileDepencies(int) + */ + public String[] getFileDependencies(IPath filePath) throws IOException { +// List tempFileReturn = new ArrayList(); +// +// IndexedFile indexFile = addsIndex.getIndexedFile(filePath.toString()); +// +// if (indexFile == null) +// return new String[0]; +// +// int fileNum = indexFile.getFileNumber(); +// IncludeEntry[] tempEntries = addsIndex.getIncludeEntries(); +// for (int i=0; i 0) { + inc2.mapRefs(mappingAdds); + mergeOutput.addInclude(inc2); + addsInput.moveToNextIncludeEntry(); + } else { + inc1.mapRefs(mappingOld); + inc2.mapRefs(mappingAdds); + inc1.addRefs(inc2.getRefs()); + mergeOutput.addInclude(inc1); + addsInput.moveToNextIncludeEntry(); + oldInput.moveToNextIncludeEntry(); + } + } + mergeOutput.flushIncludes(); + } /** * Records the deletion of one file. */ diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/SimpleIndexInput.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/SimpleIndexInput.java index 0b7cb184a3d..1129839ea45 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/SimpleIndexInput.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/SimpleIndexInput.java @@ -23,6 +23,7 @@ import org.eclipse.cdt.internal.core.index.IQueryResult; public class SimpleIndexInput extends IndexInput { protected WordEntry[] sortedWordEntries; + protected IncludeEntry[] sortedIncludes; protected IndexedFile currentFile; protected IndexedFile[] sortedFiles; protected InMemoryIndex index; @@ -77,6 +78,12 @@ public class SimpleIndexInput extends IndexInput { public int getNumFiles() { return index.getNumFiles(); } + /** + * @see IndexInput#getNumIncludes() + */ + public int getNumIncludes() { + return sortedIncludes.length; + } /** * @see IndexInput#getNumWords() */ @@ -111,16 +118,27 @@ public class SimpleIndexInput extends IndexInput { if (hasMoreWords()) currentWordEntry= sortedWordEntries[wordPosition - 1]; } + /** + * @see IndexInput#moveToNextIncludeEntry() + */ + public void moveToNextIncludeEntry() throws IOException { + includePosition++; + if (hasMoreIncludes()) + currentIncludeEntry= sortedIncludes[includePosition - 1]; + } /** * @see IndexInput#open() */ public void open() throws IOException { sortedWordEntries= index.getSortedWordEntries(); sortedFiles= index.getSortedFiles(); + sortedIncludes = index.getSortedIncludeEntries(); filePosition= 1; wordPosition= 1; + includePosition=1; setFirstFile(); setFirstWord(); + setFirstInclude(); } /** * @see IndexInput#query(String) @@ -173,5 +191,19 @@ public class SimpleIndexInput extends IndexInput { if (sortedWordEntries.length > 0) currentWordEntry= sortedWordEntries[0]; } + /** + * @see IndexInput#setFirstInclude() + */ + protected void setFirstInclude() throws IOException { + includePosition=1; + if (sortedIncludes.length >0) + currentIncludeEntry=sortedIncludes[0]; + } + public IncludeEntry[] queryIncludeEntries() { + return null; + } + public IncludeEntry[] queryIncludeEntries(int fileNum) throws IOException { + return null; + } } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Util.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Util.java index 1f99700a58d..3ff79dcf8bc 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Util.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Util.java @@ -195,6 +195,32 @@ public class Util { quickSort(list, left, original_right); } } + private static void quickSort(IncludeEntry[] list, int left, int right) { + int original_left= left; + int original_right= right; + char[] mid= list[(left + right) / 2].fFile; + do { + while (compare(list[left].fFile, mid) < 0) { + left++; + } + while (compare(mid, list[right].fFile) < 0) { + right--; + } + if (left <= right) { + IncludeEntry tmp= list[left]; + list[left]= list[right]; + list[right]= tmp; + left++; + right--; + } + } while (left <= right); + if (original_left < right) { + quickSort(list, original_left, right); + } + if (left < original_right) { + quickSort(list, left, original_right); + } + } /** * Reads in a string from the specified data input stream. The * string has been encoded using a modified UTF-8 format. @@ -291,6 +317,10 @@ public class Util { if (list.length > 1) quickSort(list, 0, list.length - 1); } + public static void sort(IncludeEntry[] list) { + if (list.length > 1) + quickSort(list, 0, list.length - 1); + } /** * Writes a string to the given output stream using UTF-8 * encoding in a machine-independent manner. diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java index 6b8f9b9cefc..2fbb96494af 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.parser.ast.IASTEnumerator; import org.eclipse.cdt.core.parser.ast.IASTField; import org.eclipse.cdt.core.parser.ast.IASTFunction; +import org.eclipse.cdt.core.parser.ast.IASTInclusion; import org.eclipse.cdt.core.parser.ast.IASTMacro; import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; @@ -33,6 +34,7 @@ import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.index.IDocument; import org.eclipse.cdt.internal.core.index.IIndexer; import org.eclipse.cdt.internal.core.index.IIndexerOutput; +import org.eclipse.core.resources.IFile; public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSearchConstants { @@ -339,6 +341,10 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe * Returns the file types the IIndexer handles. */ public abstract String[] getFileTypes(); + /** + * Returns the file types being indexed. + */ + public abstract IFile getResourceFile(); /** * @see IIndexer#index(IDocument document, IIndexerOutput output) */ @@ -621,5 +627,33 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe return bestPrefix( prefix, (char)0, macroName, null, matchMode, isCaseSenstive ); } + + /** + * @param _limitTo + * @param simpleName + * @param _matchMode + * @param _caseSensitive + * @return + */ + public static final char[] bestIncludePrefix( LimitTo limitTo, char[] incName, int matchMode, boolean isCaseSenstive ){ + //since we only index macro declarations we already know the prefix + char [] prefix = null; + if( limitTo == REFERENCES ){ + prefix = INCLUDE_REF; + } else { + return null; + } + + return bestPrefix( prefix, (char)0, incName, null, matchMode, isCaseSenstive ); + } + + public void addInclude(IASTInclusion inclusion, IASTInclusion parent){ + this.output.addIncludeRef(inclusion.getFullFileName()); + this.output.addRelatives(inclusion.getFullFileName(),(parent != null ) ? parent.getFullFileName() : null); + //Add Dep Table entry + String[] incName = new String[1]; + incName[0] = inclusion.getFullFileName(); + this.output.addRef(encodeEntry(incName, INCLUDE_REF, INCLUDE_REF_LENGTH)); + } } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IIndexConstants.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IIndexConstants.java index fc418777a9b..ee57290fd4c 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IIndexConstants.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IIndexConstants.java @@ -62,6 +62,9 @@ public interface IIndexConstants { char[] MACRO_DECL = "macroDecl/".toCharArray(); int MACRO_DECL_LENGTH = 10; + + char[] INCLUDE_REF = "includeRef/".toCharArray(); + int INCLUDE_REF_LENGTH = 11; //a Var REF will be treated as a typeREF //char[] VAR_REF= "varRef/".toCharArray(); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java index 4ab959818fa..4d12b7cd7ad 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java @@ -14,6 +14,12 @@ package org.eclipse.cdt.internal.core.search.indexing; import java.io.IOException; import java.util.HashSet; +import org.eclipse.cdt.internal.core.Util; +import org.eclipse.cdt.internal.core.index.IIndex; +import org.eclipse.cdt.internal.core.index.IQueryResult; +import org.eclipse.cdt.internal.core.index.impl.IFileDocument; +import org.eclipse.cdt.internal.core.search.SimpleLookupTable; +import org.eclipse.cdt.internal.core.search.processing.JobManager; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -23,16 +29,6 @@ import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.internal.core.Util; -import org.eclipse.cdt.internal.core.index.IIndex; -import org.eclipse.cdt.internal.core.index.IQueryResult; -import org.eclipse.cdt.internal.core.index.impl.IFileDocument; -import org.eclipse.cdt.internal.core.search.processing.JobManager; -import org.eclipse.cdt.internal.core.search.SimpleLookupTable; -import org.eclipse.cdt.internal.core.model.CModel; -import org.eclipse.cdt.internal.core.model.CModelManager; -import org.eclipse.cdt.core.model.ICElement; public class IndexAllProject extends IndexRequest { diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java index c35a4543a88..b7cc31c9035 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java @@ -35,9 +35,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.QualifiedName; public class IndexManager extends JobManager implements IIndexConstants { @@ -106,13 +104,6 @@ public class IndexManager extends JobManager implements IIndexConstants { */ public void addSource(IFile resource, IPath indexedContainer){ - /****** - *TODO: BOG Remove these methods once the new indexer is - *fully integrated - */ -// IProject project= resource.getProject(); -// if (!isEnabled(project)) return; - if (CCorePlugin.getDefault() == null) return; AddCompilationUnitToIndex job = new AddCompilationUnitToIndex(resource, indexedContainer, this); if (this.awaitingJobsCount() < MAX_FILES_IN_MEMORY) { @@ -240,13 +231,7 @@ public class IndexManager extends JobManager implements IIndexConstants { */ public void indexAll(IProject project) { if (CCorePlugin.getDefault() == null) return; - - /****** - *TODO: BOG Remove these methods once the new indexer is - *fully integrated - */ -// if (!isEnabled(project)) return; - + // check if the same request is not already in the queue IndexRequest request = new IndexAllProject(project, this); for (int i = this.jobEnd; i > this.jobStart; i--) // NB: don't check job at jobStart, as it may have already started (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32488) @@ -258,11 +243,6 @@ public class IndexManager extends JobManager implements IIndexConstants { */ public void indexSourceFolder(CProject javaProject, IPath sourceFolder, final char[][] exclusionPattern) { IProject project = javaProject.getProject(); - /****** - *TODO: BOG Remove these methods once the new indexer is - *fully integrated - */ -// if (!isEnabled(project)) return; if (this.jobEnd > this.jobStart) { // check if a job to index the project is not already in the queue @@ -320,14 +300,7 @@ public class IndexManager extends JobManager implements IIndexConstants { IndexRequest request = null; if (target instanceof IProject) { IProject p = (IProject) target; - /****** - *TODO: BOG Remove these methods once the new indexer is - *fully integrated - */ -// if (!isEnabled(p)) return; - - //if (JavaProject.hasJavaNature(p)) - request = new IndexAllProject(p, this); + request = new IndexAllProject(p, this); } if (request != null) @@ -409,12 +382,7 @@ public class IndexManager extends JobManager implements IIndexConstants { */ public void removeSourceFolderFromIndex(CProject javaProject, IPath sourceFolder, char[][] exclusionPatterns) { IProject project = javaProject.getProject(); - /****** - *TODO: BOG Remove these methods once the new indexer is - *fully integrated - */ -// if (!isEnabled(project)) return; - + if (this.jobEnd > this.jobStart) { // check if a job to index the project is not already in the queue IndexRequest request = new IndexAllProject(project, this); @@ -596,49 +564,5 @@ public class IndexManager extends JobManager implements IIndexConstants { else if (indexState == REBUILDING_STATE) state = "REBUILDING"; //$NON-NLS-1$ JobManager.verbose("-> index state updated to: " + state + " for: "+indexName); //$NON-NLS-1$ //$NON-NLS-2$ } - } - - /************* - *TODO: BOG Remove these methods once the new indexer is - *fully integrated - * START OF TEMP INDEXER ENABLE SECTION - */ -// final static String INDEX_MODEL_ID = CCorePlugin.PLUGIN_ID + ".newindexmodel"; -// final static String ACTIVATION = "enable"; -// -// static QualifiedName activationKey = new QualifiedName(INDEX_MODEL_ID, ACTIVATION); -// -// public boolean isEnabled(IProject project) { -// String prop = null; -// try { -// if (project != null) { -// prop = project.getPersistentProperty(activationKey); -// } -// } catch (CoreException e) { -// } -// return ((prop != null) && prop.equalsIgnoreCase("true")); -// } -// -// public void setEnabled(IProject project, boolean on) { -// try { -// if (project != null) { -// Boolean newValue = new Boolean(on); -// Boolean oldValue = new Boolean(isEnabled(project)); -// if (!oldValue.equals(newValue)) { -// project.setPersistentProperty(activationKey, newValue.toString()); -// if (on) { -// indexAll(project); -// } else { -// //remove(project); -// } -// } -// } -// } catch (CoreException e) { -// } -// } - - /************ - * END OF TEMP INDEXER ENABLE SECTION - */ - + } } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java index ccdbb108415..d0a96e06c1d 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java @@ -108,4 +108,10 @@ public class SourceIndexer extends AbstractIndexer { */ public void setFileTypes(String[] fileTypes){} + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer#getResourceFile() + */ + public IFile getResourceFile() { + return resourceFile; + } } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java index a2bb8c633ec..d3ed746f554 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java @@ -15,6 +15,8 @@ package org.eclipse.cdt.internal.core.search.indexing; * @author bgheorgh */ +import java.util.LinkedList; + import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; @@ -69,6 +71,9 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo int depth = 0; int methodDepth = 0; + private IASTInclusion currentInclude = null; + private LinkedList includeStack = new LinkedList(); + public SourceIndexerRequestor(SourceIndexer indexer, IDocument document) { super(); this.indexer = indexer; @@ -180,9 +185,10 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo public void enterInclusion(IASTInclusion inclusion) { // TODO Auto-generated method stub - //System.out.println("NEW INCLUSION \nInclusion short name: " + inclusion.getName()); - //System.out.println("Inclusion Long Name: " + inclusion.getFullFileName()); - //System.out.println("enterInclusion"); + IASTInclusion parent = peekInclude(); + indexer.addInclude(inclusion, parent); + //Push on stack + pushInclude(inclusion); } /* (non-Javadoc) @@ -342,8 +348,7 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo */ public void exitInclusion(IASTInclusion inclusion) { // TODO Auto-generated method stub - //System.out.println("exitInclusion"); - + popInclude(); } /* (non-Javadoc) @@ -455,4 +460,19 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo indexer.addParameterReference( (IASTParameterDeclaration) reference.getReferencedElement() ); } + + private void pushInclude( IASTInclusion inclusion ){ + includeStack.addFirst( currentInclude ); + currentInclude = inclusion; + } + + private IASTInclusion popInclude(){ + IASTInclusion oldInclude = currentInclude; + currentInclude = (includeStack.size() > 0 ) ? (IASTInclusion) includeStack.removeFirst() : null; + return oldInclude; + } + + private IASTInclusion peekInclude(){ + return currentInclude; + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java index b221eca742b..e61eea22e64 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java @@ -9,7 +9,6 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.internal.core.model.BatchOperation; import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.cdt.internal.core.search.indexing.IndexManager; -import org.eclipse.cdt.internal.core.sourcedependency.DependencyManager; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -226,12 +225,4 @@ public class CoreModel { public IndexManager getIndexManager(){ return manager.getIndexManager(); } - - public void startDependencyService() { - manager.getSourceDependencyManager().reset(); - } - - public DependencyManager getDependencyManager(){ - return manager.getSourceDependencyManager(); - } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index 46a154178a8..13e067a8e6a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -28,6 +28,7 @@ import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IElementChangedListener; import org.eclipse.cdt.core.model.IParent; +import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -42,8 +43,6 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.cdt.internal.core.search.indexing.IndexManager; -import org.eclipse.cdt.internal.core.sourcedependency.DependencyManager; public class CModelManager implements IResourceChangeListener { @@ -783,9 +782,4 @@ public class CModelManager implements IResourceChangeListener { // discard all indexing jobs for this project this.getIndexManager().discardJobs(project.getName()); } - - - public DependencyManager getSourceDependencyManager() { - return this.fDeltaProcessor.sourceDependencyManager; - } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java index 133cb8dcfb2..4ba91e1bb3f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java @@ -5,9 +5,6 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ -import java.util.ArrayList; -import java.util.Iterator; - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; @@ -18,18 +15,20 @@ import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IParent; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.search.ICSearchConstants; +import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.core.search.SearchEngine; +import org.eclipse.cdt.internal.core.search.PathCollector; +import org.eclipse.cdt.internal.core.search.PatternSearchJob; import org.eclipse.cdt.internal.core.search.indexing.IndexManager; -import org.eclipse.cdt.internal.core.sourcedependency.DependencyManager; -import org.eclipse.cdt.internal.core.sourcedependency.DependencyQueryJob; +import org.eclipse.cdt.internal.core.search.matching.CSearchPattern; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; /** * This class is used by CModelManager to convert @@ -46,8 +45,6 @@ public class DeltaProcessor { protected IndexManager indexManager = new IndexManager(); - protected DependencyManager sourceDependencyManager = new DependencyManager(); - /* The C element that was last created (see createElement(IResource). * This is used as a stack of C elements (using getParent() to pop it, and * using the various get*(...) to push it. */ @@ -465,37 +462,26 @@ public class DeltaProcessor { } protected void updateIndexAddResource(ICElement element, IResourceDelta delta) { - //CModelManager.getDefault().getIndexManager().addResource(delta.getResource()); if (indexManager == null) return; switch (element.getElementType()) { case ICElement.C_PROJECT : - this.indexManager.indexAll(element.getCProject().getProject()); - this.sourceDependencyManager.generateEntireDependencyTree(element.getCProject().getProject()); - break; + this.indexManager.indexAll(element.getCProject().getProject()); + break; case ICElement.C_UNIT: IFile file = (IFile) delta.getResource(); IProject filesProject = file.getProject(); indexManager.addSource(file, filesProject.getFullPath()); - cleanDependencies(file, filesProject); - IScannerInfo scanInfo = null; - IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(filesProject); - if (provider != null){ - scanInfo = provider.getScannerInformation(filesProject); - } - - this.sourceDependencyManager.addSource(file,filesProject.getFullPath(),scanInfo); break; } } protected void updateIndexRemoveResource(ICElement element, IResourceDelta delta) { - //CModelManager.getDefault().getIndexManager().removeResource(delta.getResource()); - + if (indexManager == null) return; @@ -503,7 +489,6 @@ public class DeltaProcessor { case ICElement.C_PROJECT : this.indexManager.removeIndexFamily(element.getCProject().getProject().getFullPath()); // NB: Discarding index jobs belonging to this project was done during PRE_DELETE - this.sourceDependencyManager.removeTree(element.getCProject().getProject().getFullPath()); break; // NB: Update of index if project is opened, closed, or its c nature is added or removed // is done in updateCurrentDeltaAndIndex @@ -511,7 +496,6 @@ public class DeltaProcessor { case ICElement.C_UNIT: IFile file = (IFile) delta.getResource(); indexManager.remove(file.getFullPath().toString(), file.getProject().getProject().getFullPath()); - sourceDependencyManager.remove(file.getFullPath().toString(),file.getProject().getFullPath()); break; } @@ -519,7 +503,7 @@ public class DeltaProcessor { } private void updateDependencies(ICElement element){ - //Update table + IResource resource = element.getResource(); if (resource == null) return; @@ -529,41 +513,35 @@ public class DeltaProcessor { if ((fileExtension != null) && (fileExtension.equals("h") || fileExtension.equals("hh") || - fileExtension.equals("hpp"))){ - - if (sourceDependencyManager.getProjectDependsForFile(element.getResource().getLocation().toOSString()) == null){ - //retrigger dep trees - sourceDependencyManager.performConcurrentJob(new DependencyQueryJob(null,null,sourceDependencyManager,null),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null); - } - - ArrayList projs =sourceDependencyManager.getProjectDependsForFile(element.getResource().getLocation().toOSString()); - if (projs != null){ - Iterator iter = projs.iterator(); - while (iter.hasNext()){ - IPath pathToReindex = (IPath) iter.next(); - - IWorkspaceRoot workRoot = element.getCProject().getProject().getWorkspace().getRoot(); - IFile fileToReindex = workRoot.getFileForLocation(pathToReindex); - - if (fileToReindex.exists() ) { - if (VERBOSE) - System.out.println("Going to reindex " + fileToReindex.getName()); - this.indexManager.addSource(fileToReindex,fileToReindex.getProject().getProject().getFullPath()); - } + fileExtension.equals("hpp"))) + { + PathCollector pathCollector = new PathCollector(); + //SubProgressMonitor subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 5 ); + ICSearchScope scope = SearchEngine.createWorkspaceScope(); + CSearchPattern pattern = CSearchPattern.createPattern(resource.getLocation().toOSString(),ICSearchConstants.INCLUDE, ICSearchConstants.REFERENCES,ICSearchConstants.EXACT_MATCH,true); + IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); + indexManager.performConcurrentJob( + new PatternSearchJob( + (CSearchPattern) pattern, + scope, + pathCollector, + indexManager + ), + ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null ); + + String[] iPath = pathCollector.getPaths(); + for (int i=0;i