1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

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
This commit is contained in:
Bogdan Gheorghe 2004-05-28 19:44:48 +00:00
parent a38caa6521
commit 87e2ecff89
11 changed files with 281 additions and 7 deletions

View file

@ -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

View file

@ -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);
}

View file

@ -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();
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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$
}
}
}
}

View file

@ -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;
}
}

View file

@ -105,4 +105,9 @@ public class IndexerModelListener implements IElementChangedListener {
}
public void shutdown(){
if (indexerModelListener != null)
CoreModel.getDefault().removeElementChangedListener(indexerModelListener);
}
}

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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) { }