EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.pcm.gmf.resource.editors]

COVERAGE SUMMARY FOR SOURCE FILE [NonRuleBasedDamagerRepairer.java]

nameclass, %method, %block, %line, %
NonRuleBasedDamagerRepairer.java0%   (0/1)0%   (0/6)0%   (0/147)0%   (0/49)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NonRuleBasedDamagerRepairer0%   (0/1)0%   (0/6)0%   (0/147)0%   (0/49)
NonRuleBasedDamagerRepairer (TextAttribute): void 0%   (0/1)0%   (0/8)0%   (0/4)
addRange (TextPresentation, int, int, TextAttribute): void 0%   (0/1)0%   (0/16)0%   (0/9)
createPresentation (TextPresentation, ITypedRegion): void 0%   (0/1)0%   (0/10)0%   (0/6)
endOfLineOf (int): int 0%   (0/1)0%   (0/41)0%   (0/8)
getDamageRegion (ITypedRegion, DocumentEvent, boolean): IRegion 0%   (0/1)0%   (0/68)0%   (0/20)
setDocument (IDocument): void 0%   (0/1)0%   (0/4)0%   (0/2)

1package de.uka.ipd.sdq.pcm.gmf.resource.editors;
2 
3import org.eclipse.core.runtime.Assert;
4import org.eclipse.jface.text.BadLocationException;
5import org.eclipse.jface.text.DocumentEvent;
6import org.eclipse.jface.text.IDocument;
7import org.eclipse.jface.text.IRegion;
8import org.eclipse.jface.text.ITypedRegion;
9import org.eclipse.jface.text.Region;
10import org.eclipse.jface.text.TextAttribute;
11import org.eclipse.jface.text.TextPresentation;
12import org.eclipse.jface.text.presentation.IPresentationDamager;
13import org.eclipse.jface.text.presentation.IPresentationRepairer;
14import org.eclipse.swt.custom.StyleRange;
15 
16public class NonRuleBasedDamagerRepairer
17        implements IPresentationDamager, IPresentationRepairer {
18 
19        /** The document this object works on */
20        protected IDocument fDocument;
21        /** The default text attribute if non is returned as data by the current token */
22        protected TextAttribute fDefaultTextAttribute;
23        
24        /**
25         * Constructor for NonRuleBasedDamagerRepairer.
26         */
27        public NonRuleBasedDamagerRepairer(TextAttribute defaultTextAttribute) {
28                Assert.isNotNull(defaultTextAttribute);
29 
30                fDefaultTextAttribute = defaultTextAttribute;
31        }
32 
33        /**
34         * @see IPresentationRepairer#setDocument(IDocument)
35         */
36        public void setDocument(IDocument document) {
37                fDocument = document;
38        }
39 
40        /**
41         * Returns the end offset of the line that contains the specified offset or
42         * if the offset is inside a line delimiter, the end offset of the next line.
43         *
44         * @param offset the offset whose line end offset must be computed
45         * @return the line end offset for the given offset
46         * @exception BadLocationException if offset is invalid in the current document
47         */
48        protected int endOfLineOf(int offset) throws BadLocationException {
49 
50                IRegion info = fDocument.getLineInformationOfOffset(offset);
51                if (offset <= info.getOffset() + info.getLength())
52                        return info.getOffset() + info.getLength();
53 
54                int line = fDocument.getLineOfOffset(offset);
55                try {
56                        info = fDocument.getLineInformation(line + 1);
57                        return info.getOffset() + info.getLength();
58                } catch (BadLocationException x) {
59                        return fDocument.getLength();
60                }
61        }
62 
63        /**
64         * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
65         */
66        public IRegion getDamageRegion(
67                ITypedRegion partition,
68                DocumentEvent event,
69                boolean documentPartitioningChanged) {
70                if (!documentPartitioningChanged) {
71                        try {
72 
73                                IRegion info =
74                                        fDocument.getLineInformationOfOffset(event.getOffset());
75                                int start = Math.max(partition.getOffset(), info.getOffset());
76 
77                                int end =
78                                        event.getOffset()
79                                                + (event.getText() == null
80                                                        ? event.getLength()
81                                                        : event.getText().length());
82 
83                                if (info.getOffset() <= end
84                                        && end <= info.getOffset() + info.getLength()) {
85                                        // optimize the case of the same line
86                                        end = info.getOffset() + info.getLength();
87                                } else
88                                        end = endOfLineOf(end);
89 
90                                end =
91                                        Math.min(
92                                                partition.getOffset() + partition.getLength(),
93                                                end);
94                                return new Region(start, end - start);
95 
96                        } catch (BadLocationException x) {
97                        }
98                }
99 
100                return partition;
101        }
102 
103        /**
104         * @see IPresentationRepairer#createPresentation(TextPresentation, ITypedRegion)
105         */
106        public void createPresentation(
107                TextPresentation presentation,
108                ITypedRegion region) {
109                addRange(
110                        presentation,
111                        region.getOffset(),
112                        region.getLength(),
113                        fDefaultTextAttribute);
114        }
115 
116        /**
117         * Adds style information to the given text presentation.
118         *
119         * @param presentation the text presentation to be extended
120         * @param offset the offset of the range to be styled
121         * @param length the length of the range to be styled
122         * @param attr the attribute describing the style of the range to be styled
123         */
124        protected void addRange(
125                TextPresentation presentation,
126                int offset,
127                int length,
128                TextAttribute attr) {
129                if (attr != null)
130                        presentation.addStyleRange(
131                                new StyleRange(
132                                        offset,
133                                        length,
134                                        attr.getForeground(),
135                                        attr.getBackground(),
136                                        attr.getStyle()));
137        }
138}

[all classes][de.uka.ipd.sdq.pcm.gmf.resource.editors]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov