Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdan Gheorghe2004-05-28 15:44:48 -0400
committerBogdan Gheorghe2004-05-28 15:44:48 -0400
commit87e2ecff897cecc252c7b71e89d2fd6ae5c930a6 (patch)
treeaa9ac68c372068be9ecb71942b699d7e68b512b9
parenta38caa6521bc21f2d55e223991dbd37223b1daae (diff)
downloadorg.eclipse.cdt-87e2ecff897cecc252c7b71e89d2fd6ae5c930a6.tar.gz
org.eclipse.cdt-87e2ecff897cecc252c7b71e89d2fd6ae5c930a6.tar.xz
org.eclipse.cdt-87e2ecff897cecc252c7b71e89d2fd6ae5c930a6.zip
Fix for Bug 60946 - [Indexer] indexer should provide notification whenever index changes
Provide a notification to the listener of index events Fix for Bug 44926 - add extensibility to gracefully handle preprocessor exceptions Added an IndexProblemHandler to handle parser IProblem callbacks
-rw-r--r--core/org.eclipse.cdt.core/index/ChangeLog7
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IIndexChangeListener.java19
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IIndexDelta.java28
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IndexChangeEvent.java33
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexDelta.java45
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java73
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexProblemHandler.java49
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexerModelListener.java5
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java6
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java20
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java3
11 files changed, 281 insertions, 7 deletions
diff --git a/core/org.eclipse.cdt.core/index/ChangeLog b/core/org.eclipse.cdt.core/index/ChangeLog
index 9422bc394f..1ad4803d0e 100644
--- a/core/org.eclipse.cdt.core/index/ChangeLog
+++ b/core/org.eclipse.cdt.core/index/ChangeLog
@@ -1,3 +1,10 @@
+2004-05-28 Bogdan Gheorghe
+ Fix for Bug 60946 - [Indexer] indexer should provide notification whenever index changes
+ Provide a notification to the listener of index events
+
+ Fix for Bug 44926 - add extensibility to gracefully handle preprocessor exceptions
+ Added an IndexProblemHandler to handle parser IProblem callbacks
+
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
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IIndexChangeListener.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IIndexChangeListener.java
new file mode 100644
index 0000000000..a986d92d3e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IIndexChangeListener.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * 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.core.index;
+
+public interface IIndexChangeListener {
+ /**
+ * @param event the change event
+ */
+ public void indexChanged(IndexChangeEvent event);
+}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IIndexDelta.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IIndexDelta.java
new file mode 100644
index 0000000000..d2a50d441c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IIndexDelta.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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.core.index;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IProject;
+
+public interface IIndexDelta {
+ /**
+ * @return Returns the files.
+ */
+ public ArrayList getFiles();
+ /**
+ * @return Returns the project.
+ */
+ public IProject getProject();
+
+}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IndexChangeEvent.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IndexChangeEvent.java
new file mode 100644
index 0000000000..7379199b30
--- /dev/null
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/IndexChangeEvent.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.core.index;
+
+import java.util.EventObject;
+
+public class IndexChangeEvent extends EventObject {
+
+ /**
+ * @param source
+ */
+ public IndexChangeEvent(IIndexDelta delta) {
+ super(delta);
+ }
+
+ /**
+ * Returns the delta describing the change.
+ *
+ */
+ public IIndexDelta getDelta() {
+ return (IIndexDelta) source;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexDelta.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexDelta.java
new file mode 100644
index 0000000000..3aa52ce80d
--- /dev/null
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexDelta.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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.index.impl;
+
+import java.util.ArrayList;
+
+import org.eclipse.cdt.core.index.IIndexDelta;
+import org.eclipse.core.resources.IProject;
+
+public class IndexDelta implements IIndexDelta {
+
+ private ArrayList files = null;
+ private IProject project = null;
+
+ /**
+ * @param filesTrav
+ * @param project
+ *
+ */
+ public IndexDelta(IProject project, ArrayList filesTrav) {
+ this.project = project;
+ this.files = filesTrav;
+ }
+
+ /**
+ * @return Returns the files.
+ */
+ public ArrayList getFiles() {
+ return files;
+ }
+ /**
+ * @return Returns the project.
+ */
+ public IProject getProject() {
+ return project;
+ }
+}
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 5c121119ef..19552a27f2 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
@@ -16,18 +16,24 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.zip.CRC32;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICLogConstants;
+import org.eclipse.cdt.core.index.IIndexChangeListener;
+import org.eclipse.cdt.core.index.IndexChangeEvent;
import org.eclipse.cdt.core.model.ICModelMarker;
+import org.eclipse.cdt.core.model.IElementChangedListener;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.impl.Index;
+import org.eclipse.cdt.internal.core.index.impl.IndexDelta;
import org.eclipse.cdt.internal.core.model.CProject;
import org.eclipse.cdt.internal.core.search.CWorkspaceScope;
import org.eclipse.cdt.internal.core.search.IndexSelector;
@@ -44,7 +50,9 @@ 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.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
@@ -84,6 +92,11 @@ public class IndexManager extends JobManager implements IIndexConstants {
private IndexerModelListener indexModelListener = null;
+ /**
+ * Collection of listeners for indexer deltas
+ */
+ protected List indexChangeListeners = Collections.synchronizedList(new ArrayList());
+
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$
@@ -644,6 +657,8 @@ public class IndexManager extends JobManager implements IIndexConstants {
}
}
+ indexModelListener.shutdown();
+
this.timeoutThread = null;
super.shutdown();
@@ -783,4 +798,62 @@ public class IndexManager extends JobManager implements IIndexConstants {
job.schedule();
}
+ public void addIndexChangeListener(IIndexChangeListener listener) {
+ synchronized(indexChangeListeners) {
+ if (!indexChangeListeners.contains(listener)) {
+ indexChangeListeners.add(listener);
+ }
+ }
+ }
+
+ public void removeIndexChangeListener(IIndexChangeListener listener) {
+ synchronized(indexChangeListeners) {
+ int i = indexChangeListeners.indexOf(listener);
+ if (i != -1) {
+ indexChangeListeners.remove(i);
+ }
+ }
+ }
+ /**
+ * @param indexDelta
+ */
+ public void notifyListeners(IndexDelta indexDelta) {
+ final IndexChangeEvent indexEvent = new IndexChangeEvent(indexDelta);
+ for (int i= 0; i < indexChangeListeners.size(); i++) {
+ IIndexChangeListener tempListener = null;
+ synchronized(indexChangeListeners){
+ tempListener = (IIndexChangeListener) indexChangeListeners.get(i);
+ }
+ final IIndexChangeListener listener = tempListener;
+ long start = -1;
+ if (VERBOSE) {
+ System.out.print("Listener #" + (i+1) + "=" + listener.toString());//$NON-NLS-1$//$NON-NLS-2$
+ start = System.currentTimeMillis();
+ }
+
+ // wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief
+ Job job = new Job("Update Index Listeners"){
+ protected IStatus run(IProgressMonitor monitor) {
+ Platform.run(new ISafeRunnable() {
+ public void handleException(Throwable exception) {
+ CCorePlugin.log(exception);
+ }
+ public void run() throws Exception {
+ listener.indexChanged(indexEvent);
+ }
+ });
+
+ return Status.OK_STATUS;
+ }
+ };
+
+ job.schedule();
+ if (VERBOSE) {
+ System.out.println(" -> " + (System.currentTimeMillis()-start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ }
}
+
+
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexProblemHandler.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexProblemHandler.java
new file mode 100644
index 0000000000..2bbb6e1c50
--- /dev/null
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexProblemHandler.java
@@ -0,0 +1,49 @@
+/*
+ * Created on May 27, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.eclipse.cdt.internal.core.search.indexing;
+
+import org.eclipse.cdt.core.parser.IProblem;
+import org.eclipse.cdt.core.parser.ParserMode;
+
+/**
+ * @author bgheorgh
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class IndexProblemHandler {
+
+
+ public static boolean ruleOnProblem( IProblem p, ParserMode mode )
+ {
+ if( p == null ) return true;
+ if( p.checkCategory( IProblem.SCANNER_RELATED ) || p.checkCategory( IProblem.PREPROCESSOR_RELATED ))
+ {
+ switch( p.getID() )
+ {
+ case IProblem.PREPROCESSOR_POUND_ERROR:
+ case IProblem.PREPROCESSOR_UNBALANCE_CONDITION:
+ case IProblem.PREPROCESSOR_INVALID_MACRO_DEFN:
+ case IProblem.PREPROCESSOR_MACRO_PASTING_ERROR:
+ case IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR:
+ case IProblem.SCANNER_UNEXPECTED_EOF:
+ if( mode == ParserMode.COMPLETE_PARSE )
+ return false;
+
+ case IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN:
+ case IProblem.PREPROCESSOR_INVALID_DIRECTIVE:
+ return true;
+
+ default:
+ return true;
+ }
+ }
+ return true;
+ }
+
+
+}
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
index 21c3a68caa..ac70abe5b6 100644
--- 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
@@ -105,4 +105,9 @@ public class IndexerModelListener implements IElementChangedListener {
}
+ public void shutdown(){
+ if (indexerModelListener != null)
+ CoreModel.getDefault().removeElementChangedListener(indexerModelListener);
+ }
+
}
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 b7acf1234a..dabd9e8d35 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
@@ -19,6 +19,7 @@ import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.util.ArrayList;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants;
@@ -34,6 +35,7 @@ import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.internal.core.index.IDocument;
+import org.eclipse.cdt.internal.core.index.impl.IndexDelta;
import org.eclipse.cdt.utils.TimeOut;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -150,6 +152,10 @@ public class SourceIndexer extends AbstractIndexer {
if( manager.isIndexProblemsEnabled( resourceFile.getProject() ) )
requestor.reportProblems();
+ //Report events
+ ArrayList filesTrav = requestor.getFilesTraversed();
+ IndexDelta indexDelta = new IndexDelta(resourceFile.getProject(),filesTrav);
+ CCorePlugin.getDefault().getCoreModel().getIndexManager().notifyListeners(indexDelta);
//Release all resources
parser=null;
currentProject = null;
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 d200f3ef86..c6a71ccaf0 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
@@ -26,7 +26,6 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICModelMarker;
-import org.eclipse.cdt.core.parser.DefaultProblemHandler;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ParserMode;
@@ -111,11 +110,15 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
private static final String INDEXER_MARKER_PREFIX = Util.bind("indexerMarker.prefix" ) + " "; //$NON-NLS-1$ //$NON-NLS-2$
private static final String INDEXER_MARKER_PROCESSING = Util.bind( "indexerMarker.processing" ); //$NON-NLS-1$
+ private ArrayList filesTraversed = null;
+
public SourceIndexerRequestor(SourceIndexer indexer, IFile resourceFile, TimeOut timeOut) {
super();
this.indexer = indexer;
this.resourceFile = resourceFile;
this.timeoutThread = timeOut;
+ this.filesTraversed = new ArrayList(15);
+ this.filesTraversed.add(resourceFile.getLocation().toOSString());
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem)
@@ -145,7 +148,7 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
}
}
- return DefaultProblemHandler.ruleOnProblem( problem, ParserMode.COMPLETE_PARSE );
+ return IndexProblemHandler.ruleOnProblem( problem, ParserMode.COMPLETE_PARSE );
}
/* (non-Javadoc)
@@ -258,6 +261,8 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
indexer.addInclude(inclusion, parent);
//Push on stack
pushInclude(inclusion);
+ //Add to traversed files
+ this.filesTraversed.add(inclusion.getFullFileName());
}
/* (non-Javadoc)
@@ -749,10 +754,7 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
}
public boolean shouldRecordProblem( IProblem problem ){
- if( problem.checkCategory( IProblem.PREPROCESSOR_RELATED ) ){
- return problem.getID() != IProblem.PREPROCESSOR_CIRCULAR_INCLUSION;
- }
- return false;
+ return problem.checkCategory( IProblem.PREPROCESSOR_RELATED );
}
public void requestRemoveMarkers(IFile resource, IFile originator ){
@@ -831,4 +833,10 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
return null;
}
}
+ /**
+ * @return Returns the filesTraversed.
+ */
+ public ArrayList getFilesTraversed() {
+ return filesTraversed;
+ }
}
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java
index fdbfc15cfd..2e0887eec2 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java
@@ -82,6 +82,7 @@ import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.IMatchLocator;
import org.eclipse.cdt.internal.core.search.AcceptMatchOperation;
+import org.eclipse.cdt.internal.core.search.indexing.IndexProblemHandler;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -115,7 +116,7 @@ public class MatchLocator implements IMatchLocator{
searchScope = scope;
}
- public boolean acceptProblem(IProblem problem) { return DefaultProblemHandler.ruleOnProblem(problem, ParserMode.COMPLETE_PARSE ); }
+ public boolean acceptProblem(IProblem problem) { return IndexProblemHandler.ruleOnProblem(problem, ParserMode.COMPLETE_PARSE ); }
public void acceptUsingDirective(IASTUsingDirective usageDirective) { }
public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) { }
public void acceptASMDefinition(IASTASMDefinition asmDefinition) { }

Back to the top