Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdan Gheorghe2004-05-27 17:17:45 -0400
committerBogdan Gheorghe2004-05-27 17:17:45 -0400
commit742d1b1514a09351549de5a64a16f60260bdb33a (patch)
tree6a43c0feb2327d88fa2fc189f8b017a5f3a8e2b3
parentae5b03a319bb450c558363afb5bbbf64dc44abba (diff)
downloadorg.eclipse.cdt-742d1b1514a09351549de5a64a16f60260bdb33a.tar.gz
org.eclipse.cdt-742d1b1514a09351549de5a64a16f60260bdb33a.tar.xz
org.eclipse.cdt-742d1b1514a09351549de5a64a16f60260bdb33a.zip
Fix for Bug 58716 - [Refactoring] Subdirectories confuse refactoring
Added a listener to path change events from the core model; retrigger indexing based on the level of the change event
-rw-r--r--core/org.eclipse.cdt.core/index/ChangeLog5
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java4
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexerModelListener.java108
3 files changed, 117 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core/index/ChangeLog b/core/org.eclipse.cdt.core/index/ChangeLog
index 314fcde913..9422bc394f 100644
--- a/core/org.eclipse.cdt.core/index/ChangeLog
+++ b/core/org.eclipse.cdt.core/index/ChangeLog
@@ -1,4 +1,9 @@
2004-05-27 Bogdan Gheorghe
+ Fix for Bug 58716 - [Refactoring] Subdirectories confuse refactoring
+ Added a listener to path change events from the core model; retrigger
+ indexing based on the granularity of the change event
+
+2004-05-27 Bogdan Gheorghe
Fix for Bug 62015 - Indexer to not rely on file extension for translation Unit
Changed all indexer file type checking to use the CoreModel file resolution services.
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 f0a0ed4196..7109b99c32 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
@@ -82,6 +82,8 @@ public class IndexManager extends JobManager implements IIndexConstants {
private TimeOut timeoutThread = null;
+ private IndexerModelListener indexModelListener = null;
+
public final static String INDEX_MODEL_ID = CCorePlugin.PLUGIN_ID + ".newindexmodel"; //$NON-NLS-1$
public final static String ACTIVATION = "enable"; //$NON-NLS-1$
public final static String PROBLEM_ACTIVATION = "problemEnable"; //$NON-NLS-1$
@@ -542,6 +544,8 @@ public class IndexManager extends JobManager implements IIndexConstants {
this.indexNames = new SimpleLookupTable();
this.cCorePluginLocation = null;
+
+ indexModelListener = IndexerModelListener.getDefault();
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexerModelListener.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexerModelListener.java
new file mode 100644
index 0000000000..21c3a68caa
--- /dev/null
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexerModelListener.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 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.search.indexing;
+
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ElementChangedEvent;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICElementDelta;
+import org.eclipse.cdt.core.model.IElementChangedListener;
+import org.eclipse.cdt.internal.core.model.SourceRoot;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+
+public class IndexerModelListener implements IElementChangedListener {
+
+ private static IndexerModelListener indexerModelListener;
+ private static IndexManager indexManager;
+
+ private IndexerModelListener() {}
+
+ /**
+ * Return the singleton.
+ */
+ public static synchronized IndexerModelListener getDefault() {
+ if (indexerModelListener == null) {
+ indexerModelListener = new IndexerModelListener();
+ CoreModel.getDefault().addElementChangedListener(indexerModelListener);
+ indexManager = CoreModel.getDefault().getIndexManager();
+ }
+ return indexerModelListener;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.model.IElementChangedListener#elementChanged(org.eclipse.cdt.core.model.ElementChangedEvent)
+ */
+ public void elementChanged(ElementChangedEvent event) {
+ try {
+ processDelta(event.getDelta());
+ } catch(CModelException e) {
+ }
+ }
+
+ protected void processDelta(ICElementDelta delta) throws CModelException {
+ int kind= delta.getKind();
+ int flags= delta.getFlags();
+ ICElement element= delta.getElement();
+
+ switch(delta.getKind()){
+ case ICElementDelta.CHANGED:
+ if ((flags & ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE) != 0 ||
+ (flags & ICElementDelta.F_CHANGED_PATHENTRY_MACRO) != 0){
+ IResource tempResource = element.getResource();
+ SourceRoot tempRootElement = null;
+
+ switch(tempResource.getType())
+ {
+ case IResource.FILE:
+ indexManager.addSource((IFile) tempResource,tempResource.getProject().getFullPath());
+ break;
+
+ case IResource.FOLDER:
+ tempRootElement = (SourceRoot) getElementSource(element);
+ if (tempRootElement != null){
+ IProject theProj = tempResource.getProject();
+ indexManager.indexSourceFolder(theProj,tempResource.getFullPath(),tempRootElement.getSourceEntry().fullExclusionPatternChars());
+ }
+ break;
+
+ case IResource.PROJECT:
+ indexManager.indexAll(tempResource.getProject());
+ break;
+ }
+
+ }
+ break;
+ }
+
+ ICElementDelta[] affectedChildren= delta.getAffectedChildren();
+ for (int i= 0; i < affectedChildren.length; i++) {
+ processDelta(affectedChildren[i]);
+ }
+ }
+
+ ICElement getElementSource(ICElement element){
+
+ if (element instanceof SourceRoot){
+ return element;
+ }
+
+ if (element.getParent() != null){
+ return getElementSource(element.getParent());
+ }
+
+ return null;
+
+ }
+
+}

Back to the top