From c0c636bc3cdcf4651d5b9edfd2a23f8d6c5aa26c Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Fri, 9 Dec 2011 14:19:37 +0100 Subject: [PATCH] Bug 366173 - [disassembly] Extract base class from BreakpointsAnnotationModel for custom annotations --- .../model/BreakpointsAnnotationModel.java | 71 ++------------- .../DisassemblyAnnotationModel.java | 90 +++++++++++++++++++ 2 files changed, 98 insertions(+), 63 deletions(-) create mode 100644 dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/provisional/DisassemblyAnnotationModel.java diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/model/BreakpointsAnnotationModel.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/model/BreakpointsAnnotationModel.java index c44b418b7c4..0a33a546846 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/model/BreakpointsAnnotationModel.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/model/BreakpointsAnnotationModel.java @@ -18,8 +18,7 @@ import org.eclipse.cdt.core.IAddress; import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint; import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint; import org.eclipse.cdt.debug.core.model.ICLineBreakpoint; -import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.AddressRangePosition; -import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.LabelPosition; +import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.provisional.DisassemblyAnnotationModel; import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.provisional.IBreakpointLocationProvider; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; @@ -32,13 +31,11 @@ import org.eclipse.debug.core.IBreakpointManager; import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.core.model.ILineBreakpoint; import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.BadPositionCategoryException; import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.AnnotationModel; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.texteditor.MarkerAnnotation; import org.eclipse.ui.texteditor.SimpleMarkerAnnotation; @@ -47,7 +44,7 @@ import org.eclipse.ui.texteditor.SimpleMarkerAnnotation; * Annotation model for breakpoints in the disassembly. * Works only with {@link DisassemblyDocument}. */ -public class BreakpointsAnnotationModel extends AnnotationModel implements IBreakpointListener, IDocumentListener { +public class BreakpointsAnnotationModel extends DisassemblyAnnotationModel implements IBreakpointListener, IDocumentListener { private Runnable fCatchup; @@ -89,6 +86,7 @@ public class BreakpointsAnnotationModel extends AnnotationModel implements IBrea /* * @see org.eclipse.debug.core.IBreakpointListener#breakpointAdded(org.eclipse.debug.core.model.IBreakpoint) */ + @Override public void breakpointAdded(IBreakpoint breakpoint) { addBreakpointAnnotation(breakpoint, true); } @@ -96,6 +94,7 @@ public class BreakpointsAnnotationModel extends AnnotationModel implements IBrea /* * @see org.eclipse.debug.core.IBreakpointListener#breakpointChanged(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta) */ + @Override public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) { Annotation a= findAnnotation(breakpoint.getMarker()); if (a != null) { @@ -114,6 +113,7 @@ public class BreakpointsAnnotationModel extends AnnotationModel implements IBrea /* * @see org.eclipse.debug.core.IBreakpointListener#breakpointRemoved(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta) */ + @Override public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) { Annotation a= findAnnotation(breakpoint.getMarker()); if (a != null) { @@ -220,64 +220,6 @@ public class BreakpointsAnnotationModel extends AnnotationModel implements IBrea return null; } - private Position createPositionFromSourceLine(String fileName, int lineNumber) { - if (fileName != null) { - return getDisassemblyDocument().getSourcePosition(fileName, lineNumber); - } - return null; - } - - private Position createPositionFromSourceLine(IFile file, int lineNumber) { - return getDisassemblyDocument().getSourcePosition(file, lineNumber); - } - - private Position createPositionFromAddress(BigInteger address) { - if (address != null) { - AddressRangePosition p= getDisassemblyDocument().getDisassemblyPosition(address); - if (p != null && p.fValid) { - return new Position(p.offset, p.length); - } - } - return null; - } - - private Position createPositionFromLabel(BigInteger address) { - if (address != null) { - LabelPosition p = getDisassemblyDocument().getLabelPosition(address); - if (p != null && p.fValid) { - return new Position(p.offset, p.length); - } - } - return null; - } - - private Position createPositionFromLabel(String label) { - if (label != null) { - try { - Position[] labelPositions = getDisassemblyDocument().getPositions(DisassemblyDocument.CATEGORY_LABELS); - int labelLen = label.length(); - for (Position position : labelPositions) { - if (position instanceof LabelPosition) { - String candidate = ((LabelPosition) position).fLabel; - if (candidate != null && candidate.startsWith(label)) { - // exact match or followed by () - if (candidate.length() == labelLen || candidate.charAt(labelLen) == '(') { - return position; - } - } - } - } - } catch (BadPositionCategoryException exc) { - return null; - } - } - return null; - } - - private DisassemblyDocument getDisassemblyDocument() { - return (DisassemblyDocument) fDocument; - } - /** * Decode given string representation of a non-negative integer. A * hexadecimal encoded integer is expected to start with 0x. @@ -305,15 +247,18 @@ public class BreakpointsAnnotationModel extends AnnotationModel implements IBrea /* * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) */ + @Override public void documentAboutToBeChanged(DocumentEvent event) { } /* * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent) */ + @Override public void documentChanged(DocumentEvent event) { if (fCatchup == null && event.fText != null && event.fText.length() > 0) { fCatchup= new Runnable() { + @Override public void run() { if (fCatchup == this) { catchupWithBreakpoints(); diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/provisional/DisassemblyAnnotationModel.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/provisional/DisassemblyAnnotationModel.java new file mode 100644 index 00000000000..04d0bf4fb5b --- /dev/null +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/provisional/DisassemblyAnnotationModel.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2011 Wind River Systems, Inc. and others. + * All rights reserved. This program 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.dsf.debug.internal.ui.disassembly.provisional; + +import java.math.BigInteger; + +import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.AddressRangePosition; +import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.LabelPosition; +import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.DisassemblyDocument; +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.text.BadPositionCategoryException; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.source.AnnotationModel; + +public class DisassemblyAnnotationModel extends AnnotationModel { + + public DisassemblyAnnotationModel() { + super(); + } + + private DisassemblyDocument getDisassemblyDocument() { + return (DisassemblyDocument) fDocument; + } + + protected Position createPositionFromSourceLine(String fileName, int lineNumber) { + if (fileName != null) { + return getDisassemblyDocument().getSourcePosition(fileName, lineNumber); + } + return null; + } + + protected Position createPositionFromSourceLine(IFile file, int lineNumber) { + if (file != null) { + return getDisassemblyDocument().getSourcePosition(file, lineNumber); + } + return null; + } + + protected Position createPositionFromAddress(BigInteger address) { + if (address != null) { + AddressRangePosition p= getDisassemblyDocument().getDisassemblyPosition(address); + if (p != null && p.fValid) { + return new Position(p.offset, p.length); + } + } + return null; + } + + protected Position createPositionFromLabel(BigInteger address) { + if (address != null) { + LabelPosition p = getDisassemblyDocument().getLabelPosition(address); + if (p != null && p.fValid) { + return new Position(p.offset, p.length); + } + } + return null; + } + + protected Position createPositionFromLabel(String label) { + if (label != null) { + try { + Position[] labelPositions = getDisassemblyDocument().getPositions(DisassemblyDocument.CATEGORY_LABELS); + int labelLen = label.length(); + for (Position position : labelPositions) { + if (position instanceof LabelPosition) { + String candidate = ((LabelPosition) position).fLabel; + if (candidate != null && candidate.startsWith(label)) { + // exact match or followed by () + if (candidate.length() == labelLen || candidate.charAt(labelLen) == '(') { + return position; + } + } + } + } + } catch (BadPositionCategoryException exc) { + return null; + } + } + return null; + } + +} \ No newline at end of file