1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 19:35:36 +02:00

Fixed problem marker updating for files that are not indexed due to empty scanner info. Some refactoring of problem marker generation code.

This commit is contained in:
Vladimir Hirsl 2005-05-17 18:41:26 +00:00
parent 0751a71a3a
commit 693f2a4708
8 changed files with 232 additions and 238 deletions

View file

@ -1,3 +1,15 @@
2005-05-17 Vladimir Hirsl
Fixed problem marker updating for files that are not indexed due to
empty scanner info. Some refactoring of problem marker generation code.
* index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexerRunner.java
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/DOMSourceIndexerRunner.java
* index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java
* index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java
* index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java
2005-05-13 Vladimir Hirsl 2005-05-13 Vladimir Hirsl
Files with empty scanner info are not indexed anymore. Files with empty scanner info are not indexed anymore.
Info problem marker is created for each such file. Info problem marker is created for each such file.

View file

@ -32,7 +32,6 @@ import org.eclipse.core.runtime.Path;
* @author Bogdan Gheorghe * @author Bogdan Gheorghe
*/ */
public class CTagsIndexerRunner extends AbstractIndexer { public class CTagsIndexerRunner extends AbstractIndexer {
IFile resourceFile;
private CTagsIndexer indexer; private CTagsIndexer indexer;
/** /**
* @param resource * @param resource
@ -43,13 +42,6 @@ public class CTagsIndexerRunner extends AbstractIndexer {
this.indexer = indexer; this.indexer = indexer;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#getResourceFile()
*/
public IFile getResourceFile() {
return resourceFile;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#indexFile(org.eclipse.cdt.internal.core.index.IDocument) * @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#indexFile(org.eclipse.cdt.internal.core.index.IDocument)
*/ */

View file

@ -78,7 +78,7 @@ public class CGenerateIndexVisitor extends CASTVisitor {
if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)){ if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)){
// Get the location // Get the location
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(problem); IASTFileLocation loc = IndexEncoderUtil.getFileLocation(problem);
indexer.processProblem(problem, loc); indexer.processProblem(problem.getMessage(), loc);
} }
return super.visit(problem); return super.visit(problem);
} }
@ -95,7 +95,7 @@ public class CGenerateIndexVisitor extends CASTVisitor {
if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)){ if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)){
// Get the location // Get the location
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(name); IASTFileLocation loc = IndexEncoderUtil.getFileLocation(name);
indexer.processProblem(name, loc); indexer.processProblem(problem.getMessage(), loc);
} }
return; return;
} }

View file

@ -92,7 +92,7 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)) { if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)) {
// Get the location // Get the location
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(problem); IASTFileLocation loc = IndexEncoderUtil.getFileLocation(problem);
indexer.processProblem(problem, loc); indexer.processProblem(problem.getMessage(), loc);
} }
return super.visit(problem); return super.visit(problem);
} }
@ -109,7 +109,7 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)){ if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)){
// Get the location // Get the location
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(name); IASTFileLocation loc = IndexEncoderUtil.getFileLocation(name);
indexer.processProblem(name, loc); indexer.processProblem(problem.getMessage(), loc);
} }
return; return;
} }

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.index.domsourceindexer; package org.eclipse.cdt.internal.core.index.domsourceindexer;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -24,7 +25,6 @@ import org.eclipse.cdt.core.dom.IASTServiceProvider.UnsupportedDialectException;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -57,7 +57,6 @@ import org.eclipse.core.runtime.Path;
*/ */
public class DOMSourceIndexerRunner extends AbstractIndexer { public class DOMSourceIndexerRunner extends AbstractIndexer {
private IFile resourceFile;
private SourceIndexer indexer; private SourceIndexer indexer;
// timing & errors // timing & errors
static int totalParseTime = 0; static int totalParseTime = 0;
@ -70,10 +69,6 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
this.indexer = indexer; this.indexer = indexer;
} }
public IFile getResourceFile() {
return resourceFile;
}
public void setFileTypes(String[] fileTypes) { public void setFileTypes(String[] fileTypes) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@ -89,6 +84,9 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
if (isScannerInfoEmpty(resourceFile)) { if (isScannerInfoEmpty(resourceFile)) {
// generate info marker - file is not indexed // generate info marker - file is not indexed
addInfoMarker(resourceFile, CCorePlugin.getResourceString("DOMIndexerMarker.EmptyScannerInfo")); //$NON-NLS-1$ addInfoMarker(resourceFile, CCorePlugin.getResourceString("DOMIndexerMarker.EmptyScannerInfo")); //$NON-NLS-1$
if (areProblemMarkersEnabled()) {
reportProblems();
}
return; return;
} }
@ -303,7 +301,7 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
if (areProblemMarkersEnabled() && shouldRecordProblem(problem)) { if (areProblemMarkersEnabled() && shouldRecordProblem(problem)) {
// Get the location // Get the location
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(problem); IASTFileLocation loc = IndexEncoderUtil.getFileLocation(problem);
processProblem(problem, loc); processProblem(problem.getMessage(), loc);
} }
} }
} }
@ -311,81 +309,88 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
/** /**
* @param name * @param name
*/ */
public void processProblem(IASTNode node, IASTFileLocation loc) { public void processProblem(String message, IASTFileLocation loc) {
IFile tempFile = resourceFile; IFile tempFile = resourceFile;
//If we are in an include file, get the include file //If we are in an include file, get the include file
if (loc != null) { if (loc != null) {
String fileName = loc.getFileName(); String fileName = loc.getFileName();
tempFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName)); tempFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName));
if (tempFile != null) { if (tempFile != null) {
generateMarkerProblem(tempFile, resourceFile, node, loc); generateMarkerProblem(tempFile, resourceFile, message, loc);
} }
} }
} }
/* (non-Javadoc) private void generateMarkerProblem(IFile tempFile, IFile originator, String message, IASTFileLocation loc) {
* @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#addMarkers(org.eclipse.core.resources.IFile, org.eclipse.core.resources.IFile, java.lang.Object, java.lang.Object) Problem tempProblem = new AddMarkerProblem(tempFile, originator, message, loc);
*/ if (getProblemsMap().containsKey(tempFile)) {
protected void addMarkers(IFile tempFile, IFile originator, Object problem, Object location) { List list = (List) getProblemsMap().get(tempFile);
String errorMessage = ""; //$NON-NLS-1$ list.add(tempProblem);
} else {
if (problem instanceof IASTProblem) { List list = new ArrayList();
IASTProblem astProblem = (IASTProblem) problem; list.add(new RemoveMarkerProblem(tempFile, resourceFile)); //remove existing markers
errorMessage = astProblem.getMessage(); list.add(tempProblem);
getProblemsMap().put(tempFile, list);
} }
else if (problem instanceof IASTName) { // semantic error specified in IProblemBinding }
IASTName name = (IASTName) problem;
if (name.resolveBinding() instanceof IProblemBinding) { class AddMarkerProblem extends Problem {
IProblemBinding problemBinding = (IProblemBinding) name.resolveBinding(); private String message;
errorMessage = problemBinding.getMessage(); private IASTFileLocation location;
} public AddMarkerProblem(IResource resource, IResource originator, String message, IASTFileLocation location) {
} super(resource, originator);
if (location != null && location instanceof IASTFileLocation) { this.message = message;
IASTFileLocation fileLoc = (IASTFileLocation) location; this.location = location;
try { }
//we only ever add index markers on the file, so DEPTH_ZERO is far enough
IMarker[] markers = tempFile.findMarkers(ICModelMarker.INDEXER_MARKER, true,IResource.DEPTH_ZERO); public void run() {
if (location != null) {
boolean newProblem = true; try {
//we only ever add index markers on the file, so DEPTH_ZERO is far enough
if (markers.length > 0) { IMarker[] markers = resource.findMarkers(ICModelMarker.INDEXER_MARKER, true,IResource.DEPTH_ZERO);
IMarker tempMarker = null;
int nameStart = -1; boolean newProblem = true;
int nameLen = -1;
String tempMsgString = null; if (markers.length > 0) {
IMarker tempMarker = null;
for (int i=0; i<markers.length; i++) { int nameStart = -1;
tempMarker = markers[i]; int nameLen = -1;
nameStart = ((Integer) tempMarker.getAttribute(IMarker.CHAR_START)).intValue(); String tempMsgString = null;
nameLen = ((Integer) tempMarker.getAttribute(IMarker.CHAR_END)).intValue() - nameStart;
tempMsgString = (String) tempMarker.getAttribute(IMarker.MESSAGE); for (int i=0; i<markers.length; i++) {
if (nameStart != -1 && tempMarker = markers[i];
nameStart == fileLoc.getNodeOffset() && nameStart = ((Integer) tempMarker.getAttribute(IMarker.CHAR_START)).intValue();
nameLen == fileLoc.getNodeLength() && nameLen = ((Integer) tempMarker.getAttribute(IMarker.CHAR_END)).intValue() - nameStart;
tempMsgString.equalsIgnoreCase(INDEXER_MARKER_PREFIX + errorMessage)) { tempMsgString = (String) tempMarker.getAttribute(IMarker.MESSAGE);
newProblem = false; if (nameStart != -1 &&
break; nameStart == location.getNodeOffset() &&
} nameLen == location.getNodeLength() &&
} tempMsgString.equalsIgnoreCase(INDEXER_MARKER_PREFIX + message)) {
} newProblem = false;
if (newProblem) { break;
IMarker marker = tempFile.createMarker(ICModelMarker.INDEXER_MARKER); }
int start = fileLoc.getNodeOffset(); }
int end = start + fileLoc.getNodeLength(); }
marker.setAttribute(IMarker.LOCATION, fileLoc.getStartingLineNumber()); if (newProblem) {
marker.setAttribute(IMarker.MESSAGE, INDEXER_MARKER_PREFIX + errorMessage); IMarker marker = resource.createMarker(ICModelMarker.INDEXER_MARKER);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING); int start = location.getNodeOffset();
marker.setAttribute(IMarker.LINE_NUMBER, fileLoc.getStartingLineNumber()); int end = start + location.getNodeLength();
marker.setAttribute(IMarker.CHAR_START, start); marker.setAttribute(IMarker.LOCATION, location.getStartingLineNumber());
marker.setAttribute(IMarker.CHAR_END, end); marker.setAttribute(IMarker.MESSAGE, INDEXER_MARKER_PREFIX + message);
marker.setAttribute(INDEXER_MARKER_ORIGINATOR, originator.getFullPath().toString()); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
} marker.setAttribute(IMarker.LINE_NUMBER, location.getStartingLineNumber());
marker.setAttribute(IMarker.CHAR_START, start);
} catch (CoreException e) { marker.setAttribute(IMarker.CHAR_END, end);
// You need to handle the cases where attribute value is rejected marker.setAttribute(INDEXER_MARKER_ORIGINATOR, originator.getFullPath().toString());
} }
}
} } catch (CoreException e) {
// You need to handle the cases where attribute value is rejected
}
}
}
}
public boolean shouldRecordProblem(IASTProblem problem) { public boolean shouldRecordProblem(IASTProblem problem) {
boolean preprocessor = (getProblemMarkersEnabled() & SourceIndexer.PREPROCESSOR_PROBLEMS_BIT ) != 0; boolean preprocessor = (getProblemMarkersEnabled() & SourceIndexer.PREPROCESSOR_PROBLEMS_BIT ) != 0;
@ -414,38 +419,6 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
return (getProblemMarkersEnabled() & SourceIndexer.SEMANTIC_PROBLEMS_BIT) != 0; return (getProblemMarkersEnabled() & SourceIndexer.SEMANTIC_PROBLEMS_BIT) != 0;
} }
/**
* @param file
* @param message
*/
private void addInfoMarker(IFile file, String message) {
try {
IMarker[] markers = file.findMarkers(ICModelMarker.INDEXER_MARKER, true, IResource.DEPTH_ZERO);
boolean newProblem = true;
if (markers.length > 0) {
IMarker tempMarker = null;
String tempMsgString = null;
for (int i=0; i<markers.length; i++) {
tempMarker = markers[i];
tempMsgString = (String) tempMarker.getAttribute(IMarker.MESSAGE);
if (tempMsgString.equalsIgnoreCase( message )) {
newProblem = false;
break;
}
}
}
if (newProblem){
IMarker marker = file.createMarker(ICModelMarker.INDEXER_MARKER);
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
}
} catch (CoreException e) {}
}
/** /**
* *
*/ */

View file

@ -50,6 +50,7 @@ public abstract class AbstractIndexer implements IIndexer, ICSearchConstants {
protected static final String INDEXER_MARKER_PREFIX = Util.bind("indexerMarker.prefix" ) + " "; //$NON-NLS-1$ //$NON-NLS-2$ protected static final String INDEXER_MARKER_PREFIX = Util.bind("indexerMarker.prefix" ) + " "; //$NON-NLS-1$ //$NON-NLS-2$
protected static final String INDEXER_MARKER_ORIGINATOR = ICModelMarker.INDEXER_MARKER + ".originator"; //$NON-NLS-1$ protected static final String INDEXER_MARKER_ORIGINATOR = ICModelMarker.INDEXER_MARKER + ".originator"; //$NON-NLS-1$
private static final String INDEXER_MARKER_PROCESSING = Util.bind( "indexerMarker.processing" ); //$NON-NLS-1$ private static final String INDEXER_MARKER_PROCESSING = Util.bind( "indexerMarker.processing" ); //$NON-NLS-1$
protected IFile resourceFile;
public AbstractIndexer() { public AbstractIndexer() {
super(); super();
@ -64,10 +65,10 @@ public abstract class AbstractIndexer implements IIndexer, ICSearchConstants {
} }
/** public Map getProblemsMap() {
* Returns the file types being indexed. return problemsMap;
*/ }
public abstract IFile getResourceFile();
/** /**
* @see IIndexer#index(IFile document, IIndexerOutput output) * @see IIndexer#index(IFile document, IIndexerOutput output)
*/ */
@ -77,6 +78,7 @@ public abstract class AbstractIndexer implements IIndexer, ICSearchConstants {
} }
protected abstract void indexFile(IFile file) throws IOException; protected abstract void indexFile(IFile file) throws IOException;
/** /**
* @param fileToBeIndexed * @param fileToBeIndexed
* @see IIndexer#shouldIndex(IFile file) * @see IIndexer#shouldIndex(IFile file)
@ -97,51 +99,107 @@ public abstract class AbstractIndexer implements IIndexer, ICSearchConstants {
return false; return false;
} }
abstract private class Problem { protected abstract class Problem {
public IFile file; public IResource resource;
public IFile originator; public IResource originator;
public Problem( IFile file, IFile orig ){ public Problem (IResource resource, IResource originator) {
this.file = file; this.resource = resource;
this.originator = orig; this.originator = originator;
} }
/**
abstract public boolean isAddProblem(); * Method to actually add/remove problem markers
abstract public Object getProblem(); */
abstract public Object getLocation(); abstract public void run();
} }
private class AddMarkerProblem extends Problem { protected class FileInfoMarker extends Problem {
private Object problem; private String message;
private Object location; public FileInfoMarker(IResource resource, IResource originator, String message) {
public AddMarkerProblem(IFile file, IFile orig, Object problem, Object location) { super(resource, originator);
super( file, orig ); this.message = message;
this.problem = problem; }
this.location = location;
} public void run() {
public boolean isAddProblem(){ try {
return true; IMarker[] markers = resource.findMarkers(ICModelMarker.INDEXER_MARKER, true, IResource.DEPTH_ZERO);
}
public Object getProblem(){ boolean newProblem = true;
return problem;
} if (markers.length > 0) {
public Object getLocation() { IMarker tempMarker = null;
return location; String tempMsgString = null;
for (int i=0; i<markers.length; i++) {
tempMarker = markers[i];
tempMsgString = (String) tempMarker.getAttribute(IMarker.MESSAGE);
if (tempMsgString.equalsIgnoreCase( message )) {
newProblem = false;
break;
}
}
}
if (newProblem){
IMarker marker = resource.createMarker(ICModelMarker.INDEXER_MARKER);
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
}
} catch (CoreException e) {}
}
}
/**
* @param file
* @param message
*/
protected void addInfoMarker(IFile tempFile, String message) {
Problem tempProblem = new FileInfoMarker(tempFile, tempFile, message);
if (getProblemsMap().containsKey(tempFile)) {
List list = (List) getProblemsMap().get(tempFile);
list.add(tempProblem);
} else {
List list = new ArrayList();
list.add(new RemoveMarkerProblem(tempFile, getResourceFile())); //remove existing markers
list.add(tempProblem);
getProblemsMap().put(tempFile, list);
} }
} }
private class RemoveMarkerProblem extends Problem { protected class RemoveMarkerProblem extends Problem {
public RemoveMarkerProblem(IFile file, IFile orig) { public RemoveMarkerProblem(IFile file, IFile orig) {
super(file, orig); super(file, orig);
} }
public boolean isAddProblem() {
return false; public void run() {
} if (originator == null) {
public Object getProblem() { //remove all markers
return null; try {
} resource.deleteMarkers(ICModelMarker.INDEXER_MARKER, true, IResource.DEPTH_INFINITE);
public Object getLocation() { } catch (CoreException e) {
return null; }
} return;
}
// else remove only those markers with matching originator
IMarker[] markers;
try {
markers = resource.findMarkers(ICModelMarker.INDEXER_MARKER, true, IResource.DEPTH_INFINITE);
} catch (CoreException e1) {
return;
}
String origPath = originator.getFullPath().toString();
IMarker mark = null;
String orig = null;
for (int i = 0; i < markers.length; i++) {
mark = markers[ i ];
try {
orig = (String) mark.getAttribute(INDEXER_MARKER_ORIGINATOR);
if( orig != null && orig.equals(origPath )) {
mark.delete();
}
} catch (CoreException e) {
}
}
}
} }
// Problem markers ****************************** // Problem markers ******************************
@ -161,24 +219,7 @@ public abstract class AbstractIndexer implements IIndexer, ICSearchConstants {
this.problemMarkersEnabled = value; this.problemMarkersEnabled = value;
} }
/** // abstract public void generateMarkerProblem(Problem problem);
* @param tempFile - not null
* @param resourceFile
* @param problem
* @param location
*/
public void generateMarkerProblem(IFile tempFile, IFile resourceFile, Object problem, Object location) {
Problem tempProblem = new AddMarkerProblem(tempFile, resourceFile, problem, location);
if (problemsMap.containsKey(tempFile)) {
List list = (List) problemsMap.get(tempFile);
list.add(tempProblem);
} else {
List list = new ArrayList();
list.add(new RemoveMarkerProblem(tempFile, resourceFile)); //remove existing markers
list.add(tempProblem);
problemsMap.put(tempFile, list);
}
}
public void requestRemoveMarkers(IFile resource, IFile originator ){ public void requestRemoveMarkers(IFile resource, IFile originator ){
if (!areProblemMarkersEnabled()) if (!areProblemMarkersEnabled())
@ -264,47 +305,17 @@ public abstract class AbstractIndexer implements IIndexer, ICSearchConstants {
Iterator i = problemsList.iterator(); Iterator i = problemsList.iterator();
while (i.hasNext()) { while (i.hasNext()) {
Problem prob = (Problem) i.next(); Problem prob = (Problem) i.next();
if (prob.isAddProblem()) { prob.run();
addMarkers(prob.file, prob.originator, prob.getProblem(), prob.getLocation());
} else {
removeMarkers(prob.file, prob.originator);
}
} }
} }
public void run() {
// TODO Auto-generated method stub
}
abstract protected void addMarkers(IFile tempFile, IFile originator, Object problem, Object location); public IFile getResourceFile() {
return resourceFile;
public void removeMarkers(IFile resource, IFile originator) { }
if (originator == null) {
//remove all markers
try {
resource.deleteMarkers(ICModelMarker.INDEXER_MARKER, true, IResource.DEPTH_INFINITE);
} catch (CoreException e) {
}
return;
}
// else remove only those markers with matching originator
IMarker[] markers;
try {
markers = resource.findMarkers(ICModelMarker.INDEXER_MARKER, true, IResource.DEPTH_INFINITE);
} catch (CoreException e1) {
return;
}
String origPath = originator.getFullPath().toString();
IMarker mark = null;
String orig = null;
for (int i = 0; i < markers.length; i++) {
mark = markers[ i ];
try {
orig = (String) mark.getAttribute(INDEXER_MARKER_ORIGINATOR);
if( orig != null && orig.equals(origPath )) {
mark.delete();
}
} catch (CoreException e) {
}
}
}
} }

View file

@ -116,7 +116,7 @@ public class SourceIndexerRequestor implements ISourceElementRequestor {
} }
if( tempFile != null ){ if( tempFile != null ){
indexer.generateMarkerProblem(tempFile, resourceFile, problem, null); indexer.generateMarkerProblem(tempFile, resourceFile, problem);
} }
} }

View file

@ -19,6 +19,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants; import org.eclipse.cdt.core.ICLogConstants;
@ -86,7 +87,6 @@ import org.eclipse.core.runtime.Path;
* - Unions * - Unions
*/ */
public class SourceIndexerRunner extends AbstractIndexer { public class SourceIndexerRunner extends AbstractIndexer {
IFile resourceFile;
private SourceIndexer indexer; private SourceIndexer indexer;
/** /**
@ -191,13 +191,6 @@ public class SourceIndexerRunner extends AbstractIndexer {
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer#getResourceFile()
*/
public IFile getResourceFile() {
return resourceFile;
}
/** /**
* @param fullPath * @param fullPath
* @param path * @param path
@ -206,16 +199,17 @@ public class SourceIndexerRunner extends AbstractIndexer {
return indexer.haveEncounteredHeader(fullPath, path); return indexer.haveEncounteredHeader(fullPath, path);
} }
/* (non-Javadoc) protected class AddMarkerProblem extends Problem {
* @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#addMarkers(org.eclipse.core.resources.IFile, org.eclipse.core.resources.IFile, java.lang.Object, java.lang.Object) private IProblem problem;
*/ public AddMarkerProblem(IResource file, IResource orig, IProblem problem) {
protected void addMarkers(IFile tempFile, IFile originator, Object problem, Object location) { super(file, orig);
if (problem instanceof IProblem) { this.problem = problem;
IProblem iProblem = (IProblem) problem; }
public void run() {
try { try {
//we only ever add index markers on the file, so DEPTH_ZERO is far enough //we only ever add index markers on the file, so DEPTH_ZERO is far enough
IMarker[] markers = tempFile.findMarkers(ICModelMarker.INDEXER_MARKER, true,IResource.DEPTH_ZERO); IMarker[] markers = resource.findMarkers(ICModelMarker.INDEXER_MARKER, true,IResource.DEPTH_ZERO);
boolean newProblem = true; boolean newProblem = true;
@ -228,8 +222,8 @@ public class SourceIndexerRunner extends AbstractIndexer {
tempMarker = markers[i]; tempMarker = markers[i];
tempInt = (Integer) tempMarker.getAttribute(IMarker.LINE_NUMBER); tempInt = (Integer) tempMarker.getAttribute(IMarker.LINE_NUMBER);
tempMsgString = (String) tempMarker.getAttribute(IMarker.MESSAGE); tempMsgString = (String) tempMarker.getAttribute(IMarker.MESSAGE);
if (tempInt != null && tempInt.intValue()==iProblem.getSourceLineNumber() && if (tempInt != null && tempInt.intValue() == problem.getSourceLineNumber() &&
tempMsgString.equalsIgnoreCase( INDEXER_MARKER_PREFIX + iProblem.getMessage())) tempMsgString.equalsIgnoreCase( INDEXER_MARKER_PREFIX + problem.getMessage()))
{ {
newProblem = false; newProblem = false;
break; break;
@ -238,24 +232,23 @@ public class SourceIndexerRunner extends AbstractIndexer {
} }
if (newProblem) { if (newProblem) {
IMarker marker = tempFile.createMarker(ICModelMarker.INDEXER_MARKER); IMarker marker = resource.createMarker(ICModelMarker.INDEXER_MARKER);
int start = iProblem.getSourceStart(); int start = problem.getSourceStart();
int end = iProblem.getSourceEnd(); int end = problem.getSourceEnd();
if (end <= start) if (end <= start)
end = start + 1; end = start + 1;
marker.setAttribute(IMarker.LOCATION, iProblem.getSourceLineNumber()); marker.setAttribute(IMarker.LOCATION, problem.getSourceLineNumber());
marker.setAttribute(IMarker.MESSAGE, INDEXER_MARKER_PREFIX + iProblem.getMessage()); marker.setAttribute(IMarker.MESSAGE, INDEXER_MARKER_PREFIX + problem.getMessage());
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
marker.setAttribute(IMarker.LINE_NUMBER, iProblem.getSourceLineNumber()); marker.setAttribute(IMarker.LINE_NUMBER, problem.getSourceLineNumber());
marker.setAttribute(IMarker.CHAR_START, start); marker.setAttribute(IMarker.CHAR_START, start);
marker.setAttribute(IMarker.CHAR_END, end); marker.setAttribute(IMarker.CHAR_END, end);
marker.setAttribute(INDEXER_MARKER_ORIGINATOR, originator.getFullPath().toString() ); marker.setAttribute(INDEXER_MARKER_ORIGINATOR, originator.getFullPath().toString() );
} }
} catch (CoreException e) { } catch (CoreException e) {
// You need to handle the cases where attribute value is rejected // You need to handle the cases where attribute value is rejected
} }
} }
} }
public void addClassSpecifier(IASTClassSpecifier classSpecification, int fileNumber){ public void addClassSpecifier(IASTClassSpecifier classSpecification, int fileNumber){
@ -647,4 +640,17 @@ public class SourceIndexerRunner extends AbstractIndexer {
int BOGUS_ENTRY = 1; int BOGUS_ENTRY = 1;
this.output.addIncludeRef(fileNumber, incName,1,1, IIndex.OFFSET); this.output.addIncludeRef(fileNumber, incName,1,1, IIndex.OFFSET);
} }
public void generateMarkerProblem(IFile tempFile, IFile originator, IProblem problem) {
Problem tempProblem = new AddMarkerProblem(tempFile, originator, problem);
if (getProblemsMap().containsKey(tempFile)) {
List list = (List) getProblemsMap().get(tempFile);
list.add(tempProblem);
} else {
List list = new ArrayList();
list.add(new RemoveMarkerProblem(tempFile, originator)); //remove existing markers
list.add(tempProblem);
getProblemsMap().put(tempFile, list);
}
}
} }