1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Fix for #151005 - Error parser - cannot generate proper marker for file outside of the workspace

This commit is contained in:
Norbert Pltt 2006-11-20 08:14:14 +00:00
parent df6b9c604b
commit c64385f973
18 changed files with 433 additions and 110 deletions

View file

@ -16,6 +16,7 @@ import java.io.InputStreamReader;
import java.io.Reader;
import org.eclipse.cdt.core.IMarkerGenerator;
import org.eclipse.cdt.core.ProblemMarkerInfo;
import org.eclipse.cdt.make.core.makefile.IBadDirective;
import org.eclipse.cdt.make.core.makefile.IDirective;
import org.eclipse.cdt.make.core.makefile.IMakefileValidator;
@ -49,22 +50,38 @@ public class GNUMakefileValidator implements IMakefileValidator {
reporter = new IMarkerGenerator() {
public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) {
ProblemMarkerInfo problemMarkerInfo = new ProblemMarkerInfo(file, lineNumber, errorDesc, severity, errorVar, null);
addMarker(problemMarkerInfo);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IMarkerGenerator#addMarker(org.eclipse.cdt.core.ProblemMarkerInfo)
*/
public void addMarker(ProblemMarkerInfo problemMarkerInfo) {
String name = "Makefile"; //$NON-NLS-1$
if (file != null) {
name = file.getName();
if (problemMarkerInfo.file != null) {
name = problemMarkerInfo.file.getName();
}
StringBuffer sb = new StringBuffer(name);
sb.append(':').append(lineNumber).append(':').append(getSeverity(severity));
if (errorDesc != null) {
sb.append(':').append(errorDesc);
sb.append(':').append(problemMarkerInfo.lineNumber).append(':').append(getSeverity(problemMarkerInfo.severity));
if (problemMarkerInfo.description != null) {
sb.append(':').append(problemMarkerInfo.description);
}
if (errorVar != null ) {
sb.append(':').append(errorVar);
if (problemMarkerInfo.variableName != null ) {
sb.append(':').append(problemMarkerInfo.variableName);
}
if (problemMarkerInfo.externalPath != null ) {
sb.append(':').append(problemMarkerInfo.externalPath);
}
sb.append('\n');
System.out.println(sb.toString());
}
public String getSeverity(int severity) {
if (severity == IMarkerGenerator.SEVERITY_ERROR_BUILD) {
return MakefileMessages.getString("MakefileValidator.errorBuild"); //$NON-NLS-1$

View file

@ -15,6 +15,7 @@ import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IMarkerGenerator;
import org.eclipse.cdt.core.ProblemMarkerInfo;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
@ -39,8 +40,18 @@ public class SCMarkerGenerator implements IMarkerGenerator {
* @see org.eclipse.cdt.core.IMarkerGenerator#addMarker(org.eclipse.core.resources.IResource, int, java.lang.String, int, java.lang.String)
*/
public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) {
ProblemMarkerInfo info = new ProblemMarkerInfo(file, lineNumber, errorDesc, severity, errorVar);
addMarker(info);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IMarkerGenerator#addMarker(org.eclipse.cdt.core.ProblemMarkerInfo)
*/
public void addMarker(ProblemMarkerInfo problemMarkerInfo) {
try {
IMarker[] cur = file.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ONE);
IMarker[] cur = problemMarkerInfo.file.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ONE);
/*
* Try to find matching markers and don't put in duplicates
*/
@ -49,26 +60,30 @@ public class SCMarkerGenerator implements IMarkerGenerator {
int line = ((Integer) cur[i].getAttribute(IMarker.LOCATION)).intValue();
int sev = ((Integer) cur[i].getAttribute(IMarker.SEVERITY)).intValue();
String mesg = (String) cur[i].getAttribute(IMarker.MESSAGE);
if (line == lineNumber && sev == mapMarkerSeverity(severity) && mesg.equals(errorDesc)) {
if (line == problemMarkerInfo.lineNumber && sev == mapMarkerSeverity(problemMarkerInfo.severity) && mesg.equals(problemMarkerInfo.description)) {
return;
}
}
}
IMarker marker = file.createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER);
marker.setAttribute(IMarker.LOCATION, lineNumber);
marker.setAttribute(IMarker.MESSAGE, errorDesc);
marker.setAttribute(IMarker.SEVERITY, mapMarkerSeverity(severity));
marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
IMarker marker = problemMarkerInfo.file.createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER);
marker.setAttribute(IMarker.LOCATION, problemMarkerInfo.lineNumber);
marker.setAttribute(IMarker.MESSAGE, problemMarkerInfo.description);
marker.setAttribute(IMarker.SEVERITY, mapMarkerSeverity(problemMarkerInfo.severity));
marker.setAttribute(IMarker.LINE_NUMBER, problemMarkerInfo.lineNumber);
marker.setAttribute(IMarker.CHAR_START, -1);
marker.setAttribute(IMarker.CHAR_END, -1);
if (errorVar != null) {
marker.setAttribute(ICModelMarker.C_MODEL_MARKER_VARIABLE, errorVar);
if (problemMarkerInfo.variableName != null) {
marker.setAttribute(ICModelMarker.C_MODEL_MARKER_VARIABLE, problemMarkerInfo.variableName);
}
if (problemMarkerInfo.externalPath != null) {
marker.setAttribute(ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION, problemMarkerInfo.externalPath.toOSString());
}
}
catch (CoreException e) {
CCorePlugin.log(e.getStatus());
}
}
public void removeMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) {

View file

@ -22,6 +22,7 @@ import junit.framework.TestCase;
import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.core.IMarkerGenerator;
import org.eclipse.cdt.core.ProblemMarkerInfo;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@ -181,21 +182,31 @@ public class GenericErrorParserTests extends TestCase {
private Comparator fFileNameComparator;
public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) {
int index = Collections.binarySearch(uniqFiles, file, fFileNameComparator);
if (index < 0) {
uniqFiles.add(-1 * (index + 1), file);
ProblemMarkerInfo problemMarkerInfo = new ProblemMarkerInfo(file, lineNumber, errorDesc, severity, errorVar, null);
addMarker(problemMarkerInfo);
}
if (severity == SEVERITY_WARNING) {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IMarkerGenerator#addMarker(org.eclipse.cdt.core.ProblemMarkerInfo)
*/
public void addMarker(ProblemMarkerInfo problemMarkerInfo) {
int index = Collections.binarySearch(uniqFiles, problemMarkerInfo.file, fFileNameComparator);
if (index < 0) {
uniqFiles.add(-1 * (index + 1), problemMarkerInfo.file);
}
if (problemMarkerInfo.severity == SEVERITY_WARNING) {
numWarnings++;
} else if (severity == SEVERITY_ERROR_BUILD || severity == SEVERITY_ERROR_RESOURCE) {
} else if (problemMarkerInfo.severity == SEVERITY_ERROR_BUILD || problemMarkerInfo.severity == SEVERITY_ERROR_RESOURCE) {
numErrors++;
}
lastDescription = errorDesc;
lastDescription = problemMarkerInfo.description;
numMarkers++;
}
public CountingMarkerGenerator() {
numErrors = 0;
numWarnings = 0;

View file

@ -37,6 +37,12 @@ public interface ICModelMarker {
*/
public static final String C_MODEL_MARKER_VARIABLE = "problem.variable"; //$NON-NLS-1$
/**
* C model extension to the marker problem markers which may hold
* the path to the workspace external location of the file containing the problem
*/
public static final String C_MODEL_MARKER_EXTERNAL_LOCATION = "problem.externalLocation"; //$NON-NLS-1$
/**
* C model task marker type (value <code>"org.eclipse.cdt.core.task"</code>).
* This can be used to recognize task markers in the workspace that correspond to tasks

View file

@ -192,6 +192,7 @@
<persistent
value="true">
</persistent>
<attribute name="externalLocation"/>
</extension>
<!-- =================================================================================== -->
<!-- CDT C Nature -->

View file

@ -334,33 +334,24 @@ public class ErrorParserManager extends OutputStream {
return (file != null && file.exists()) ? file : null;
}
protected class Problem {
protected IResource file;
protected int lineNumber;
protected String description;
protected int severity;
protected String variableName;
public Problem(IResource file, int lineNumber, String desciption, int severity, String variableName) {
this.file = file;
this.lineNumber = lineNumber;
this.description = desciption;
this.severity = severity;
this.variableName = variableName;
}
}
/**
* Called by the error parsers.
*/
public void generateMarker(IResource file, int lineNumber, String desc, int severity, String varName) {
Problem problem = new Problem(file, lineNumber, desc, severity, varName);
fErrors.add(problem);
generateExternalMarker(file, lineNumber, desc, severity, varName, null);
}
/**
* Called by the error parsers for external problem markers
*/
public void generateExternalMarker(IResource file, int lineNumber, String desc, int severity, String varName, IPath externalPath) {
ProblemMarkerInfo problemMarkerInfo = new ProblemMarkerInfo(file, lineNumber, desc, severity, varName, externalPath);
fErrors.add(problemMarkerInfo);
if (severity == IMarkerGenerator.SEVERITY_ERROR_RESOURCE)
hasErrors = true;
}
/**
* Called by the error parsers. Return the previous line, save in the working buffer.
*/
@ -456,25 +447,11 @@ public class ErrorParserManager extends OutputStream {
if (nOpens == 0) {
Iterator iter = fErrors.iterator();
while (iter.hasNext()) {
Problem problem = (Problem) iter.next();
if (problem.severity == IMarkerGenerator.SEVERITY_ERROR_BUILD) {
ProblemMarkerInfo problemMarkerInfo = (ProblemMarkerInfo) iter.next();
if (problemMarkerInfo.severity == IMarkerGenerator.SEVERITY_ERROR_BUILD) {
reset = true;
}
if (problem.file == null) {
fMarkerGenerator.addMarker(
fProject,
problem.lineNumber,
problem.description,
problem.severity,
problem.variableName);
} else {
fMarkerGenerator.addMarker(
problem.file,
problem.lineNumber,
problem.description,
problem.severity,
problem.variableName);
}
fMarkerGenerator.addMarker(problemMarkerInfo);
}
fErrors.clear();
}

View file

@ -21,5 +21,10 @@ public interface IMarkerGenerator {
int SEVERITY_ERROR_RESOURCE = 2;
int SEVERITY_ERROR_BUILD = 3;
/**
* callback from Output Parser
* @deprecated Use public void addMarker(org.eclipse.cdt.core.ProblemMarkerInfo problem) instead.
*/
void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar);
void addMarker(ProblemMarkerInfo problemMarkerInfo);
}

View file

@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2006 Siemens AG.
* All rights reserved. This content and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Norbert Ploett - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.core;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
public class ProblemMarkerInfo {
public IResource file;
public int lineNumber;
public String description;
public int severity;
public String variableName;
public IPath externalPath ;
public ProblemMarkerInfo(IResource file, int lineNumber, String desciption, int severity, String variableName) {
this.file = file;
this.lineNumber = lineNumber;
this.description = desciption;
this.severity = severity;
this.variableName = variableName;
this.externalPath = null ;
}
public ProblemMarkerInfo(IResource file, int lineNumber, String description, int severity, String variableName, IPath externalPath) {
super();
this.file = file;
this.lineNumber = lineNumber;
this.description = description;
this.severity = severity;
this.variableName = variableName;
this.externalPath = externalPath;
}
}

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.core.resources;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IMarkerGenerator;
import org.eclipse.cdt.core.ProblemMarkerInfo;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
@ -28,13 +29,21 @@ public abstract class ACBuilder extends IncrementalProjectBuilder implements IMa
super();
}
public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) {
ProblemMarkerInfo problemMarkerInfo = new ProblemMarkerInfo(file, lineNumber, errorDesc, severity, errorVar, null);
addMarker(problemMarkerInfo);
}
/*
* callback from Output Parser
*/
public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) {
public void addMarker(ProblemMarkerInfo problemMarkerInfo) {
try {
IMarker[] cur = file.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ONE);
IResource markerResource = problemMarkerInfo.file ;
if (markerResource==null) {
markerResource = getProject();
}
IMarker[] cur = markerResource.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_ONE);
/*
* Try to find matching markers and don't put in duplicates
*/
@ -43,21 +52,24 @@ public abstract class ACBuilder extends IncrementalProjectBuilder implements IMa
int line = ((Integer) cur[i].getAttribute(IMarker.LOCATION)).intValue();
int sev = ((Integer) cur[i].getAttribute(IMarker.SEVERITY)).intValue();
String mesg = (String) cur[i].getAttribute(IMarker.MESSAGE);
if (line == lineNumber && sev == mapMarkerSeverity(severity) && mesg.equals(errorDesc)) {
if (line == problemMarkerInfo.lineNumber && sev == mapMarkerSeverity(problemMarkerInfo.severity) && mesg.equals(problemMarkerInfo.description)) {
return;
}
}
}
IMarker marker = file.createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER);
marker.setAttribute(IMarker.LOCATION, lineNumber);
marker.setAttribute(IMarker.MESSAGE, errorDesc);
marker.setAttribute(IMarker.SEVERITY, mapMarkerSeverity(severity));
marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
IMarker marker = markerResource.createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER);
marker.setAttribute(IMarker.LOCATION, problemMarkerInfo.lineNumber);
marker.setAttribute(IMarker.MESSAGE, problemMarkerInfo.description);
marker.setAttribute(IMarker.SEVERITY, mapMarkerSeverity(problemMarkerInfo.severity));
marker.setAttribute(IMarker.LINE_NUMBER, problemMarkerInfo.lineNumber);
marker.setAttribute(IMarker.CHAR_START, -1);
marker.setAttribute(IMarker.CHAR_END, -1);
if (errorVar != null) {
marker.setAttribute(ICModelMarker.C_MODEL_MARKER_VARIABLE, errorVar);
if (problemMarkerInfo.variableName != null) {
marker.setAttribute(ICModelMarker.C_MODEL_MARKER_VARIABLE, problemMarkerInfo.variableName);
}
if (problemMarkerInfo.externalPath != null) {
marker.setAttribute(ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION, problemMarkerInfo.externalPath.toOSString());
}
}
catch (CoreException e) {

View file

@ -11,11 +11,18 @@
package org.eclipse.cdt.internal.errorparsers;
import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.utils.CygPath;
import org.eclipse.cdt.utils.DefaultCygwinToolFactory;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
* @author Doug Schaefer
@ -121,8 +128,9 @@ public class ErrorPattern {
int lineNum = getLineNum(matcher);
String desc = getDesc(matcher);
String varName = getVarName(matcher);
IPath externalPath = null ;
IFile file = null;
IResource file = null;
if (fileName != null) {
file = eoParser.findFileName(fileName);
if (file == null || eoParser.isConflictingName(fileName)) {
@ -130,11 +138,40 @@ public class ErrorPattern {
}
if (file == null) {
// If the file is not found in the workspace we attach the problem to the project
// and add the external path to the file.
desc = fileName + " " + desc; //$NON-NLS-1$
file = eoParser.getProject();
externalPath = getLocation(fileName);
}
}
eoParser.generateMarker(file, lineNum, desc, severity, varName);
eoParser.generateExternalMarker(file, lineNum, desc, severity, varName, externalPath);
return true;
}
/**
* If the file designated by filename exists, return the IPath representation of the filename
* If it does not exist, try cygpath translation
*/
protected IPath getLocation(String filename) {
IPath path = new Path(filename);
File file = path.toFile() ;
if (!file.exists()) {
CygPath cygpath = null ;
try {
cygpath = new CygPath("cygpath");
String cygfilename = cygpath.getFileName(filename);
path = new Path(cygfilename);
} catch (IOException e) {
}
finally {
if (null!=cygpath) {
cygpath.dispose();
}
}
}
return path ;
}
}

View file

@ -156,6 +156,7 @@ ShowInvisibleCharactersAction.description=Show invisible (whitespace) characters
# Task Action
DeleteTaskAction.label=Delete C/C++ Markers
DeleteIProblemMarkerAction.label=Delete IProblem Markers
OpenExternalProblemAction.label=Open external location
# Common Editor ruler actions
AddTask.label=Add &Task...

View file

@ -745,6 +745,18 @@
value="org.eclipse.cdt.core.indexermarker"
name="type"/>
</objectContribution>
<objectContribution
id="org.eclipse.cdt.ui.action.openExternalProblem"
objectClass="org.eclipse.core.resources.IMarker">
<action
class="org.eclipse.cdt.internal.ui.util.OpenExternalProblemAction"
id="org.eclipse.cdt.ui.action.openExternalProblemAction"
label="%OpenExternalProblemAction.label"
menubarPath="additions"/>
<filter
name="type"
value="org.eclipse.cdt.core.problem"/>
</objectContribution>
</extension>
<extension
point="org.eclipse.compare.structureCreators">

View file

@ -19,6 +19,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceRuleFactory;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@ -31,6 +32,7 @@ import org.eclipse.jface.text.ILineTracker;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationModel;
import org.eclipse.jface.text.source.AnnotationModelEvent;
import org.eclipse.jface.text.source.IAnnotationAccessExtension;
import org.eclipse.jface.text.source.IAnnotationModel;
@ -854,13 +856,13 @@ public class CDocumentProvider extends TextFileDocumentProvider {
tuInfo.fCopy = copy;
if (tuInfo.fModel == null && element instanceof IStorageEditorInput) {
// IStorage storage= ((IStorageEditorInput)element).getStorage();
// IResource markerResource= original.getCProject().getProject();
// tuInfo.fModel= new ExternalSearchAnnotationModel(markerResource, storage);
// IAnnotationModel fileBufferAnnotationModel= tuInfo.fTextFileBuffer.getAnnotationModel();
// if (fileBufferAnnotationModel != null) {
// ((AnnotationModel)tuInfo.fModel).addAnnotationModel("secondaryModel", fileBufferAnnotationModel); //$NON-NLS-1$
// }
IStorage storage= ((IStorageEditorInput)element).getStorage();
IResource markerResource= original.getCProject().getProject();
tuInfo.fModel= new ExternalSearchAnnotationModel(markerResource, storage);
IAnnotationModel fileBufferAnnotationModel= tuInfo.fTextFileBuffer.getAnnotationModel();
if (fileBufferAnnotationModel != null) {
((AnnotationModel)tuInfo.fModel).addAnnotationModel("secondaryModel", fileBufferAnnotationModel); //$NON-NLS-1$
}
}
if (tuInfo.fModel instanceof TranslationUnitAnnotationModel) {
TranslationUnitAnnotationModel model= (TranslationUnitAnnotationModel) tuInfo.fModel;

View file

@ -15,43 +15,64 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
import org.eclipse.cdt.core.model.ICModelMarker;
public class ExternalSearchAnnotationModel extends
AbstractMarkerAnnotationModel implements IResourceChangeListener {
ResourceMarkerAnnotationModel implements IResourceChangeListener {
protected IWorkspace fWorkspace;
protected IResource fMarkerResource;
protected IStorage fStorage;
protected boolean fChangesApplied;
/**
* @param resource
*/
public ExternalSearchAnnotationModel(IResource resource) {
this.fMarkerResource = resource;
public ExternalSearchAnnotationModel(IResource resource, IStorage storage) {
super(resource);
this.fWorkspace = resource.getWorkspace();
this.fStorage = storage;
}
protected IMarker[] retrieveMarkers() throws CoreException {
if (fMarkerResource != null)
return fMarkerResource.findMarkers(IMarker.MARKER, true, IResource.DEPTH_INFINITE);
return null;
IMarker[] markers = null;
if (getResource() != null) {
markers = getResource().findMarkers(IMarker.MARKER, true,
IResource.DEPTH_ZERO);
}
protected void deleteMarkers(IMarker[] markers) throws CoreException {
}
protected void listenToMarkerChanges(boolean listen) {
return markers;
}
protected boolean isAcceptable(IMarker marker) {
return false;
boolean acceptable = false;
String externalFileName = marker.getAttribute(
ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION, null);
if (externalFileName != null) { // Only accept markers with external
// paths set
IPath externalPath = new Path(externalFileName);
IPath storagePath = fStorage.getFullPath();
acceptable = externalPath.equals(storagePath); // Only accept
// markers for this
// annotation
// model's external
// editor
}
return acceptable;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
*/
public void resourceChanged(IResourceChangeEvent event) {
}
}

View file

@ -16,6 +16,7 @@ import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
@ -54,26 +55,31 @@ public class ExternalSearchDocumentProvider extends FileDocumentProvider {
IStorage storage = externalInput.getStorage();
IProject projectToUseForMarker = null;
IResource resourceToUseForMarker = null;
IFile resourceFile = CUIPlugin.getWorkspace().getRoot().getFileForLocation(storage.getFullPath());
if (resourceFile == null){
IProject[] proj = CUIPlugin.getWorkspace().getRoot().getProjects();
for (int i=0; i<proj.length; i++){
if (proj[i].isOpen()){
projectToUseForMarker = proj[i];
resourceToUseForMarker = externalInput.getMarkerResource();
if (null==resourceToUseForMarker) {
IProject[] proj = CUIPlugin.getWorkspace().getRoot()
.getProjects();
for (int i = 0; i < proj.length; i++) {
if (proj[i].isOpen()) {
resourceToUseForMarker = proj[i];
break;
}
}
}
}
else {
projectToUseForMarker = resourceFile.getProject();
resourceToUseForMarker = resourceFile.getProject();
}
if (projectToUseForMarker != null){
ExternalSearchAnnotationModel model = new ExternalSearchAnnotationModel(projectToUseForMarker);
if (resourceToUseForMarker != null){
ExternalSearchAnnotationModel model = new ExternalSearchAnnotationModel(resourceToUseForMarker, storage);
return model;
}
return null;

View file

@ -240,7 +240,7 @@ public class EditorUtility {
}
if (element instanceof IBinary) {
return new ExternalEditorInput(getStorage((IBinary)element), null);
return new ExternalEditorInput(getStorage((IBinary)element), (IPath)null);
}
element= element.getParent();

View file

@ -15,6 +15,8 @@ import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
@ -31,6 +33,7 @@ import org.eclipse.ui.editors.text.ILocationProvider;
public class ExternalEditorInput implements ITranslationUnitEditorInput {
private IStorage externalFile;
private IResource markerResource;
private ITranslationUnit unit;
private IPath location;
@ -123,7 +126,9 @@ public class ExternalEditorInput implements ITranslationUnitEditorInput {
* @see org.eclipse.ui.editors.text.ILocationProvider#getPath(java.lang.Object)
*/
public IPath getPath(Object element) {
return location;
if (location!=null)
return location ;
return externalFile.getFullPath();
}
public ExternalEditorInput(ITranslationUnit unit, IStorage exFile) {
@ -140,4 +145,22 @@ public class ExternalEditorInput implements ITranslationUnitEditorInput {
this.location = location;
}
/**
* This constructor accepts the storage for the editor
* and a reference to a resource which holds the markers for the external file.
*/
public ExternalEditorInput(IStorage exFile, IResource markerResource) {
this.externalFile = exFile ;
this.markerResource = markerResource ;
}
/**
* Return the resource where markers for this external editor input are stored
*/
public IResource getMarkerResource() {
return markerResource;
}
}

View file

@ -0,0 +1,131 @@
/*******************************************************************************
* Copyright (c) 2006 Siemens AG.
* All rights reserved. This content and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Norbert Ploett - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.util;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.ActionDelegate;
import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.ui.editor.ExternalSearchEditor;
public class OpenExternalProblemAction extends ActionDelegate implements IObjectActionDelegate
{
IStructuredSelection selection ;
public OpenExternalProblemAction() {
}
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}
public void runWithEvent(IAction action, Event event) {
Object object = selection.getFirstElement();
if (object instanceof IMarker) {
try {
IMarker marker = (IMarker) object;
Object attributeObject = marker.getAttribute(ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION);
if (attributeObject instanceof String) {
String externalLocation = (String) attributeObject ;
IPath externalPath = new Path(externalLocation);
IEditorPart editor = null ;
// Try to open a C editor with the project and the path
ICProject cproject = getCProject(marker);
if (null!=cproject) {
ITranslationUnit tu = CoreModel.getDefault()
.createTranslationUnitFrom(cproject,
externalPath);
if (null!=tu) {
editor = EditorUtility.openInEditor(tu);
}
} else {
// Open in plain external editor
IEditorInput input = new ExternalEditorInput(new FileStorage(externalPath), marker.getResource());
editor = CUIPlugin.getActivePage().openEditor(input, ExternalSearchEditor.EDITOR_ID);
}
if (editor instanceof ITextEditor) {
int lineNumber = marker.getAttribute(IMarker.LINE_NUMBER, 0);
int currentOffset = 0 ;
int currentLength = 0;
ITextEditor textEditor = (ITextEditor) editor;
IEditorInput ediinput = textEditor.getEditorInput();
IDocument document = textEditor.getDocumentProvider().getDocument(ediinput);
try {
currentOffset = document.getLineOffset(lineNumber-1);
} catch (BadLocationException e) {
}
textEditor.selectAndReveal(currentOffset, currentLength);
}
}
} catch (CoreException e) {
}
}
}
private ICProject getCProject(IMarker marker) {
ICProject cproject = null ;
if (marker.getResource() instanceof IProject) {
IProject project = (IProject) marker.getResource();
cproject = CModelManager.getDefault().create(project);
}
return cproject ;
}
public void selectionChanged(IAction action, ISelection selection) {
boolean enable = false;
if (selection instanceof IStructuredSelection) {
Object object = ((IStructuredSelection) selection).getFirstElement();
if (object instanceof IMarker) {
try {
IMarker marker = (IMarker) object;
if ((marker.isSubtypeOf(ICModelMarker.C_MODEL_PROBLEM_MARKER))
&&(null!=marker.getAttribute(ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION, null))) {
enable = true;
}
this.selection = (IStructuredSelection)selection;
action.setEnabled(enable);
} catch (CoreException e) {
}
}
}
}
}