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

- fixed bug in openInEditor method

This commit is contained in:
Alena Laskavaia 2010-07-30 18:34:00 +00:00
parent 2d499636f4
commit e67a019e83

View file

@ -17,7 +17,7 @@
/*
* Created by: Elena Laskavaia
* Created on: 2010-05-05
* Last modified by: $Author$
* Last modified by: $Author: elaskavaia $
*/
package org.eclipse.cdt.codan.ui;
@ -43,9 +43,9 @@ public class CodanEditorUtility {
* @throws PartInitException
* @throws BadLocationException
*/
public static void openFileURL(String fileUrl, IResource markerResource) throws PartInitException, BadLocationException {
public static void openFileURL(String fileUrl, IResource markerResource)
throws PartInitException, BadLocationException {
String file = getFileFromURL(fileUrl);
IEditorPart part = openInEditor(file, markerResource);
int line = getLineFromURL(fileUrl);
revealLine(part, line);
@ -53,6 +53,7 @@ public class CodanEditorUtility {
/**
* Line is the part the follows # in this URL
*
* @return -1 if not line found in URL, and line number if there is
*/
public static int getLineFromURL(String fileUrl) {
@ -72,27 +73,31 @@ public class CodanEditorUtility {
return file;
}
public static void revealLine(IEditorPart part, int line) throws BadLocationException {
public static void revealLine(IEditorPart part, int line)
throws BadLocationException {
if (line > 0) {
if (part instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) part;
IDocument document = textEditor.getDocumentProvider().getDocument(part.getEditorInput());
IDocument document = textEditor.getDocumentProvider()
.getDocument(part.getEditorInput());
textEditor.selectAndReveal(document.getLineOffset(line - 1), 0);
}
}
}
@SuppressWarnings("restriction")
public static IEditorPart openInEditor(String file, IResource markerResource) throws PartInitException {
public static IEditorPart openInEditor(String file, IResource markerResource)
throws PartInitException {
IPath pfile = new Path(file);
ICElement element = null;
if (markerResource != null)
CoreModel.getDefault().create(markerResource);
element = CoreModel.getDefault().create(markerResource);
IEditorPart part = EditorUtility.openInEditor(pfile, element);
return part;
}
public static IEditorPart openInEditor(IMarker marker) throws PartInitException {
public static IEditorPart openInEditor(IMarker marker)
throws PartInitException {
String href = getLocationHRef(marker);
String file = getFileFromURL(href);
return openInEditor(file, marker.getResource());