mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-01 05:15:43 +02:00
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
This commit is contained in:
parent
ae5b03a319
commit
742d1b1514
3 changed files with 117 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
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
|
2004-05-27 Bogdan Gheorghe
|
||||||
Fix for Bug 62015 - Indexer to not rely on file extension for translation Unit
|
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.
|
Changed all indexer file type checking to use the CoreModel file resolution services.
|
||||||
|
|
|
@ -82,6 +82,8 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
||||||
|
|
||||||
private TimeOut timeoutThread = null;
|
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 INDEX_MODEL_ID = CCorePlugin.PLUGIN_ID + ".newindexmodel"; //$NON-NLS-1$
|
||||||
public final static String ACTIVATION = "enable"; //$NON-NLS-1$
|
public final static String ACTIVATION = "enable"; //$NON-NLS-1$
|
||||||
public final static String PROBLEM_ACTIVATION = "problemEnable"; //$NON-NLS-1$
|
public final static String PROBLEM_ACTIVATION = "problemEnable"; //$NON-NLS-1$
|
||||||
|
@ -543,6 +545,8 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
||||||
this.indexNames = new SimpleLookupTable();
|
this.indexNames = new SimpleLookupTable();
|
||||||
this.cCorePluginLocation = null;
|
this.cCorePluginLocation = null;
|
||||||
|
|
||||||
|
indexModelListener = IndexerModelListener.getDefault();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveIndex(IIndex index) throws IOException {
|
public void saveIndex(IIndex index) throws IOException {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue