From a3be877d4b58d6ead3b761eda2e27698b5f2b743 Mon Sep 17 00:00:00 2001 From: Dani Megert Date: Tue, 19 Apr 2005 12:41:16 +0000 Subject: Removed trailing whitespace. --- .../jface/text/projection/ChildDocument.java | 20 +- .../text/projection/ChildDocumentManager.java | 4 +- .../eclipse/jface/text/projection/Fragment.java | 8 +- .../jface/text/projection/FragmentUpdater.java | 34 +-- .../jface/text/projection/IMinimalMapping.java | 6 +- .../jface/text/projection/ProjectionDocument.java | 296 ++++++++++----------- .../text/projection/ProjectionDocumentEvent.java | 28 +- .../text/projection/ProjectionDocumentManager.java | 38 +-- .../jface/text/projection/ProjectionMapping.java | 196 +++++++------- .../jface/text/projection/ProjectionTextStore.java | 36 +-- .../org/eclipse/jface/text/projection/Segment.java | 18 +- .../jface/text/projection/SegmentUpdater.java | 40 +-- 12 files changed, 362 insertions(+), 362 deletions(-) (limited to 'org.eclipse.text/projection/org/eclipse') diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocument.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocument.java index 53d4ed4015b..84581bb834f 100644 --- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocument.java +++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocument.java @@ -21,31 +21,31 @@ import org.eclipse.jface.text.Position; * exists for compatibility reasons. *

* Internal class. This class is not intended to be used by clients. - * + * * @since 3.0 */ public class ChildDocument extends ProjectionDocument { - + /** * Position reflecting a visible region. The exclusive end offset of the position * is considered being overlapping with the visible region. */ static private class VisibleRegion extends Position { - + /** * Creates a new visible region. - * + * * @param regionOffset the offset of the region * @param regionLength the length of the region */ public VisibleRegion(int regionOffset, int regionLength) { super(regionOffset, regionLength); } - + /** * If regionOffset is the end of the visible region and the regionLength == 0, * the regionOffset is considered overlapping with the visible region. - * + * * @see org.eclipse.jface.text.Position#overlapsWith(int, int) */ public boolean overlapsWith(int regionOffset, int regionLength) { @@ -56,7 +56,7 @@ public class ChildDocument extends ProjectionDocument { /** * Creates a new child document. - * + * * @param masterDocument @inheritDoc */ public ChildDocument(IDocument masterDocument) { @@ -65,7 +65,7 @@ public class ChildDocument extends ProjectionDocument { /** * Returns the parent document of this child document. - * + * * @return the parent document of this child document * @see ProjectionDocument#getMasterDocument() */ @@ -76,7 +76,7 @@ public class ChildDocument extends ProjectionDocument { /** * Sets the parent document range covered by this child document to the * given range. - * + * * @param offset the offset of the range * @param length the length of the range * @throws BadLocationException if the given range is not valid @@ -87,7 +87,7 @@ public class ChildDocument extends ProjectionDocument { /** * Returns the parent document range of this child document. - * + * * @return the parent document range of this child document */ public Position getParentDocumentRange() { diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocumentManager.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocumentManager.java index 72cbca4d676..f42cfbd3d6f 100644 --- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocumentManager.java +++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocumentManager.java @@ -20,11 +20,11 @@ import org.eclipse.jface.text.IDocument; * class exists for compatibility reasons. *

* Internal class. This class is not intended to be used by clients. - * + * * @since 3.0 */ public class ChildDocumentManager extends ProjectionDocumentManager { - + /* * @see org.eclipse.jface.text.projection.ProjectionDocumentManager#createProjectionDocument(org.eclipse.jface.text.IDocument) */ diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/Fragment.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/Fragment.java index 13918778fac..085bbb7b293 100644 --- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/Fragment.java +++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/Fragment.java @@ -19,19 +19,19 @@ import org.eclipse.jface.text.Position; *

* A fragment is a range of the master document that has an image, the so called * segment, in a projection document. - * + * * @since 3.0 */ public class Fragment extends Position { - + /** * The corresponding segment of this fragment. */ public Segment segment; - + /** * Creates a new fragment covering the given range. - * + * * @param offset the offset of the fragment * @param length the length of the fragment */ diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/FragmentUpdater.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/FragmentUpdater.java index 95e07589232..ac995910b71 100644 --- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/FragmentUpdater.java +++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/FragmentUpdater.java @@ -24,23 +24,23 @@ import org.eclipse.jface.text.Position; * insertion happens at a fragment's offset, the fragment is extended rather * than shifted. Also, the last fragment is extended if an insert operation * happens at the end of the fragment. - * + * * @since 3.0 */ class FragmentUpdater extends DefaultPositionUpdater { - + /** Indicates whether the position being updated represents the last fragment. */ private boolean fIsLast= false; - + /** * Creates the fragment updater for the given category. - * + * * @param fragmentCategory the position category used for managing the fragments of a document */ protected FragmentUpdater(String fragmentCategory) { super(fragmentCategory); } - + /* * @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent) */ @@ -56,10 +56,10 @@ class FragmentUpdater extends DefaultPositionUpdater { fDocument= event.getDocument(); for (int i= 0; i < category.length; i++) { - + fPosition= category[i]; fIsLast= (i == category.length -1); - + fOriginalPosition.offset= fPosition.offset; fOriginalPosition.length= fPosition.length; @@ -71,14 +71,14 @@ class FragmentUpdater extends DefaultPositionUpdater { // do nothing } } - + /* * @see org.eclipse.jface.text.DefaultPositionUpdater#adaptToInsert() */ protected void adaptToInsert() { int myStart= fPosition.offset; int myEnd= Math.max(myStart, fPosition.offset + fPosition.length - (fIsLast || isAffectingReplace() ? 0 : 1)); - + if (myEnd < fOffset) return; @@ -97,12 +97,12 @@ class FragmentUpdater extends DefaultPositionUpdater { fPosition.offset += fReplaceLength; } } - + /** * Returns whether this updater considers any position affected by the given * document event. A position is affected if either the offset or the length * of the position is modified but the position is not just shifted. - * + * * @param event the event * @return true if there is any affected position, * false otherwise @@ -110,10 +110,10 @@ class FragmentUpdater extends DefaultPositionUpdater { public boolean affectsPositions(DocumentEvent event) { IDocument document= event.getDocument(); try { - + int index= document.computeIndexInCategory(getCategory(), event.getOffset()); Position[] fragments= document.getPositions(getCategory()); - + if (0 < index) { Position fragment= fragments[index - 1]; if (fragment.overlapsWith(event.getOffset(), event.getLength())) @@ -121,16 +121,16 @@ class FragmentUpdater extends DefaultPositionUpdater { if (index == fragments.length && fragment.offset + fragment.length == event.getOffset()) return true; } - + if (index < fragments.length) { Position fragment= fragments[index]; return fragment.overlapsWith(event.getOffset(), event.getLength()); } - + } catch (BadLocationException x) { } catch (BadPositionCategoryException x) { } - - return false; + + return false; } } diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/IMinimalMapping.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/IMinimalMapping.java index bea921ceb0b..114c934a7e4 100644 --- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/IMinimalMapping.java +++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/IMinimalMapping.java @@ -20,7 +20,7 @@ import org.eclipse.jface.text.IRegion; * {@link org.eclipse.jface.text.projection.ProjectionMapping} that the * {@link org.eclipse.jface.text.projection.ProjectionTextStore} is allowed to * access. - * + * * @since 3.0 */ interface IMinimalMapping { @@ -39,12 +39,12 @@ interface IMinimalMapping { * @see org.eclipse.jface.text.IDocumentInformationMapping#toOriginOffset(int) */ int toOriginOffset(int offset) throws BadLocationException; - + /* * @see org.eclipse.jface.text.IDocumentInformationMappingExtension#toExactOriginRegions(IRegion) */ IRegion[] toExactOriginRegions(IRegion region) throws BadLocationException; - + /* * @see org.eclipse.jface.text.IDocumentInformationMappingExtension#getImageLength() */ diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java index 467523f0325..fb6e7008fae 100644 --- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java +++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java @@ -53,12 +53,12 @@ import org.eclipse.jface.text.Region; * {@link org.eclipse.jface.text.projection.ProjectionDocumentManager}should be * used. This class is not intended to be subclassed outside of its origin * package. - * + * * @since 3.0 */ public class ProjectionDocument extends AbstractDocument { - - + + /** * Prefix of the name of the position category used to keep track of the master * document's fragments that correspond to the segments of the projection @@ -73,7 +73,7 @@ public class ProjectionDocument extends AbstractDocument { */ private final static String SEGMENTS_CATEGORY= "__segmentsCategory"; //$NON-NLS-1$ - + /** The master document */ private IDocument fMasterDocument; /** The master document as document extension */ @@ -89,7 +89,7 @@ public class ProjectionDocument extends AbstractDocument { /** The original document event generated by a direct manipulation of this projection document */ private DocumentEvent fOriginalEvent; /** Indicates whether the projection document initiated a master document update or not */ - private boolean fIsUpdating= false; + private boolean fIsUpdating= false; /** Indicated whether the projection document is in auto expand mode nor not */ private boolean fIsAutoExpanding= false; /** The position updater for the segments */ @@ -98,7 +98,7 @@ public class ProjectionDocument extends AbstractDocument { private FragmentUpdater fFragmentsUpdater; /** The projection mapping */ private ProjectionMapping fMapping; - + /** * Creates a projection document for the given master document. * @@ -106,31 +106,31 @@ public class ProjectionDocument extends AbstractDocument { */ public ProjectionDocument(IDocument masterDocument) { super(); - + fMasterDocument= masterDocument; - if (fMasterDocument instanceof IDocumentExtension) + if (fMasterDocument instanceof IDocumentExtension) fMasterDocumentExtension= (IDocumentExtension) fMasterDocument; - + fSegmentsCategory= SEGMENTS_CATEGORY; fFragmentsCategory= FRAGMENTS_CATEGORY_PREFIX + hashCode(); fMasterDocument.addPositionCategory(fFragmentsCategory); fFragmentsUpdater= new FragmentUpdater(fFragmentsCategory); - fMasterDocument.addPositionUpdater(fFragmentsUpdater); - + fMasterDocument.addPositionUpdater(fFragmentsUpdater); + fMapping= new ProjectionMapping(masterDocument, fFragmentsCategory, this, fSegmentsCategory); - + ITextStore s= new ProjectionTextStore(masterDocument, fMapping); ILineTracker tracker= new DefaultLineTracker(); - + setTextStore(s); setLineTracker(tracker); - + completeInitialization(); - + initializeProjection(); tracker.set(s.get(0, s.getLength())); } - + /** * Disposes this projection document. */ @@ -142,14 +142,14 @@ public class ProjectionDocument extends AbstractDocument { // allow multiple dispose calls } } - + private void internalError() { throw new IllegalStateException(); } - + /** * Returns the fragments of the master documents. - * + * * @return the fragment of the master document */ protected final Position[] getFragments() { @@ -161,10 +161,10 @@ public class ProjectionDocument extends AbstractDocument { // unreachable return null; } - + /** * Returns the segments of this projection document. - * + * * @return the segments of this projection document */ protected final Position[] getSegments() { @@ -176,19 +176,19 @@ public class ProjectionDocument extends AbstractDocument { // unreachable return null; } - + /** * Returns the projection mapping used by this document. - * + * * @return the projection mapping used by this document */ public ProjectionMapping getProjectionMapping(){ return fMapping; } - + /** * Returns the master document of this projection document. - * + * * @return the master document of this projection document */ public IDocument getMasterDocument() { @@ -200,13 +200,13 @@ public class ProjectionDocument extends AbstractDocument { * the master's fragments. */ private void initializeProjection() { - + try { - + addPositionCategory(fSegmentsCategory); fSegmentUpdater= new SegmentUpdater(fSegmentsCategory); addPositionUpdater(fSegmentUpdater); - + int offset= 0; Position[] fragments= getFragments(); for (int i= 0; i < fragments.length; i++) { @@ -216,17 +216,17 @@ public class ProjectionDocument extends AbstractDocument { addPosition(fSegmentsCategory, segment); offset += fragment.length; } - + } catch (BadPositionCategoryException x) { internalError(); } catch (BadLocationException x) { internalError(); } } - + /** * Creates a segment for the given fragment at the given position inside the list of segments. - * + * * @param fragment the corresponding fragment * @param index the index in the list of segments * @return the created segment @@ -234,24 +234,24 @@ public class ProjectionDocument extends AbstractDocument { * @throws BadPositionCategoryException in case the segment category is invalid */ private Segment createSegmentFor(Fragment fragment, int index) throws BadLocationException, BadPositionCategoryException { - + int offset= 0; if (index > 0) { Position[] segments= getSegments(); Segment segment= (Segment) segments[index - 1]; offset= segment.getOffset() + segment.getLength(); } - + Segment segment= new Segment(offset, 0); segment.fragment= fragment; fragment.segment= segment; addPosition(fSegmentsCategory, segment); return segment; } - + /** * Adds the given range of the master document to this projection document. - * + * * @param offsetInMaster offset of the master document range * @param lengthInMaster length of the master document range * @param masterDocumentEvent the master document event that causes this @@ -260,25 +260,25 @@ public class ProjectionDocument extends AbstractDocument { * document */ private void internalAddMasterDocumentRange(int offsetInMaster, int lengthInMaster, DocumentEvent masterDocumentEvent) throws BadLocationException { - + if (lengthInMaster == 0) return; - + try { - + Position[] fragments= getFragments(); int index= fMasterDocument.computeIndexInCategory(fFragmentsCategory, offsetInMaster); - + Fragment left= null; Fragment right= null; - + if (index < fragments.length) { if (offsetInMaster == fragments[index].offset) throw new IllegalArgumentException("overlaps with existing fragment"); //$NON-NLS-1$ - if (offsetInMaster + lengthInMaster == fragments[index].offset) + if (offsetInMaster + lengthInMaster == fragments[index].offset) right= (Fragment) fragments[index]; } - + if (0 < index && index <= fragments.length) { Fragment fragment= (Fragment) fragments[index - 1]; if (fragment.includes(offsetInMaster)) @@ -286,37 +286,37 @@ public class ProjectionDocument extends AbstractDocument { if (fragment.getOffset() + fragment.getLength() == offsetInMaster) left= fragment; } - + int offsetInSlave= 0; if (index > 0) { Fragment fragment= (Fragment) fragments[index - 1]; Segment segment= fragment.segment; offsetInSlave= segment.getOffset() + segment.getLength(); } - + ProjectionDocumentEvent event= new ProjectionDocumentEvent(this, offsetInSlave, 0, fMasterDocument.get(offsetInMaster, lengthInMaster), offsetInMaster, lengthInMaster, masterDocumentEvent); super.fireDocumentAboutToBeChanged(event); // check for neighboring fragment if (left != null && right != null) { - + int endOffset= right.getOffset() + right.getLength(); left.setLength(endOffset - left.getOffset()); left.segment.setLength(left.segment.getLength() + right.segment.getLength()); - + removePosition(fSegmentsCategory, right.segment); fMasterDocument.removePosition(fFragmentsCategory, right); - + } else if (left != null) { int endOffset= offsetInMaster +lengthInMaster; left.setLength(endOffset - left.getOffset()); left.segment.markForStretch(); - + } else if (right != null) { right.setOffset(right.getOffset() - lengthInMaster); right.setLength(right.getLength() + lengthInMaster); right.segment.markForStretch(); - + } else { // create a new segment Fragment fragment= new Fragment(offsetInMaster, lengthInMaster); @@ -324,18 +324,18 @@ public class ProjectionDocument extends AbstractDocument { Segment segment= createSegmentFor(fragment, index); segment.markForStretch(); } - + getTracker().replace(event.getOffset(), event.getLength(), event.getText()); super.fireDocumentChanged(event); - + } catch (BadPositionCategoryException x) { internalError(); } } - + /** * Finds the fragment of the master document that represents the given range. - * + * * @param offsetInMaster the offset of the range in the master document * @param lengthInMaster the length of the range in the master document * @return the fragment representing the given master document range @@ -349,14 +349,14 @@ public class ProjectionDocument extends AbstractDocument { } return null; } - + /** * Removes the given range of the master document from this projection * document. - * + * * @param offsetInMaster the offset of the range in the master document * @param lengthInMaster the length of the range in the master document - * + * * @throws BadLocationException if the given range is not valid in the * master document * @throws IllegalArgumentException if the given range is not projected in @@ -365,18 +365,18 @@ public class ProjectionDocument extends AbstractDocument { */ private void internalRemoveMasterDocumentRange(int offsetInMaster, int lengthInMaster) throws BadLocationException { try { - + IRegion imageRegion= fMapping.toExactImageRegion(new Region(offsetInMaster, lengthInMaster)); if (imageRegion == null) throw new IllegalArgumentException(); - + Fragment fragment= findFragment(offsetInMaster, lengthInMaster); if (fragment == null) throw new IllegalArgumentException(); - + ProjectionDocumentEvent event= new ProjectionDocumentEvent(this, imageRegion.getOffset(), imageRegion.getLength(), null, offsetInMaster, lengthInMaster); super.fireDocumentAboutToBeChanged(event); - + if (fragment.getOffset() == offsetInMaster) { fragment.setOffset(offsetInMaster + lengthInMaster); fragment.setLength(fragment.getLength() - lengthInMaster); @@ -384,7 +384,7 @@ public class ProjectionDocument extends AbstractDocument { fragment.setLength(fragment.getLength() - lengthInMaster); } else { // split fragment into three fragments, let position updater remove it - + // add fragment for the region to be removed Fragment newFragment= new Fragment(offsetInMaster, lengthInMaster); Segment segment= new Segment(imageRegion.getOffset(), imageRegion.getLength()); @@ -392,7 +392,7 @@ public class ProjectionDocument extends AbstractDocument { segment.fragment= newFragment; fMasterDocument.addPosition(fFragmentsCategory, newFragment); addPosition(fSegmentsCategory, segment); - + // add fragment for the remainder right of the deleted range in the original fragment int offset= offsetInMaster + lengthInMaster; newFragment= new Fragment(offset, fragment.getOffset() + fragment.getLength() - offset); @@ -402,25 +402,25 @@ public class ProjectionDocument extends AbstractDocument { segment.fragment= newFragment; fMasterDocument.addPosition(fFragmentsCategory, newFragment); addPosition(fSegmentsCategory, segment); - + // adjust length of initial fragment (the left one) fragment.setLength(offsetInMaster - fragment.getOffset()); fragment.segment.setLength(imageRegion.getOffset() - fragment.segment.getOffset()); } - + getTracker().replace(event.getOffset(), event.getLength(), event.getText()); super.fireDocumentChanged(event); - + } catch (BadPositionCategoryException x) { internalError(); } } - + /** * Returns the sequence of all master document regions which are contained * in the given master document range and which are not yet part of this * projection document. - * + * * @param offsetInMaster the range offset in the master document * @param lengthInMaster the range length in the master document * @return the sequence of regions which are not yet part of the projection @@ -429,21 +429,21 @@ public class ProjectionDocument extends AbstractDocument { * master document */ public final IRegion[] computeUnprojectedMasterRegions(int offsetInMaster, int lengthInMaster) throws BadLocationException { - + IRegion[] fragments= null; IRegion imageRegion= fMapping.toImageRegion(new Region(offsetInMaster, lengthInMaster)); if (imageRegion != null) fragments= fMapping.toExactOriginRegions(imageRegion); - + if (fragments == null || fragments.length == 0) return new IRegion[] { new Region(offsetInMaster, lengthInMaster) }; - + List gaps= new ArrayList(); - + IRegion region= fragments[0]; if (offsetInMaster < region.getOffset()) gaps.add(new Region(offsetInMaster, region.getOffset() - offsetInMaster)); - + for (int i= 0; i < fragments.length - 1; i++) { IRegion left= fragments[i]; IRegion right= fragments[i + 1]; @@ -451,23 +451,23 @@ public class ProjectionDocument extends AbstractDocument { if (leftEnd < right.getOffset()) gaps.add(new Region(leftEnd, right.getOffset() - leftEnd)); } - + region= fragments[fragments.length - 1]; int leftEnd= region.getOffset() + region.getLength(); int rightEnd= offsetInMaster + lengthInMaster; if (leftEnd < rightEnd) gaps.add(new Region(leftEnd, rightEnd - leftEnd)); - + IRegion[] result= new IRegion[gaps.size()]; gaps.toArray(result); return result; } - + /** * Returns the first master document region which is contained in the given * master document range and which is not yet part of this projection * document. - * + * * @param offsetInMaster the range offset in the master document * @param lengthInMaster the range length in the master document * @return the first region that is not yet part of the projection document @@ -475,19 +475,19 @@ public class ProjectionDocument extends AbstractDocument { * master document */ private IRegion computeFirstUnprojectedMasterRegion(int offsetInMaster, int lengthInMaster) throws BadLocationException { - + IRegion[] fragments= null; IRegion imageRegion= fMapping.toImageRegion(new Region(offsetInMaster, lengthInMaster)); if (imageRegion != null) fragments= fMapping.toExactOriginRegions(imageRegion); - + if (fragments == null || fragments.length == 0) return new Region(offsetInMaster, lengthInMaster); - + IRegion region= fragments[0]; if (offsetInMaster < region.getOffset()) return new Region(offsetInMaster, region.getOffset() - offsetInMaster); - + for (int i= 0; i < fragments.length - 1; i++) { IRegion left= fragments[i]; IRegion right= fragments[i + 1]; @@ -495,20 +495,20 @@ public class ProjectionDocument extends AbstractDocument { if (leftEnd < right.getOffset()) return new Region(leftEnd, right.getOffset() - leftEnd); } - + region= fragments[fragments.length - 1]; int leftEnd= region.getOffset() + region.getLength(); int rightEnd= offsetInMaster + lengthInMaster; if (leftEnd < rightEnd) return new Region(leftEnd, rightEnd - leftEnd); - + return null; } - + /** * Ensures that the given range of the master document is part of this * projection document. - * + * * @param offsetInMaster the offset of the master document range * @param lengthInMaster the length of the master document range * @throws BadLocationException in case the master event is not valid @@ -520,7 +520,7 @@ public class ProjectionDocument extends AbstractDocument { /** * Ensures that the given range of the master document is part of this * projection document. - * + * * @param offsetInMaster the offset of the master document range * @param lengthInMaster the length of the master document range * @param masterDocumentEvent the master document event which causes this @@ -533,7 +533,7 @@ public class ProjectionDocument extends AbstractDocument { * to become unfolded, resulting in re-entrant calls to this method. In * order to not add a region twice, we have to compute the next region * to add in every iteration. - * + * * To place an upper bound on the number of iterations, we use the number * of fragments * 2 as the limit. */ @@ -541,19 +541,19 @@ public class ProjectionDocument extends AbstractDocument { while (true) { if (limit-- < 0) throw new IllegalArgumentException("safety loop termination"); //$NON-NLS-1$ - + IRegion gap= computeFirstUnprojectedMasterRegion(offsetInMaster, lengthInMaster); if (gap == null) return; - + internalAddMasterDocumentRange(gap.getOffset(), gap.getLength(), masterDocumentEvent); } } - + /** * Ensures that the given range of the master document is not part of this * projection document. - * + * * @param offsetInMaster the offset of the master document range * @param lengthInMaster the length of the master document range * @throws BadLocationException in case the master event is not valid @@ -562,18 +562,18 @@ public class ProjectionDocument extends AbstractDocument { IRegion[] fragments= computeProjectedMasterRegions(offsetInMaster, lengthInMaster); if (fragments == null || fragments.length == 0) return; - + for (int i= 0; i < fragments.length; i++) { IRegion fragment= fragments[i]; internalRemoveMasterDocumentRange(fragment.getOffset(), fragment.getLength()); } } - + /** * Returns the sequence of all master document regions with are contained in the given master document * range and which are part of this projection document. May return null if no such * regions exist. - * + * * @param offsetInMaster the range offset in the master document * @param lengthInMaster the range length in the master document * @return the sequence of regions which are part of the projection document or null @@ -583,16 +583,16 @@ public class ProjectionDocument extends AbstractDocument { IRegion imageRegion= fMapping.toImageRegion(new Region(offsetInMaster, lengthInMaster)); return imageRegion != null ? fMapping.toExactOriginRegions(imageRegion) : null; } - + /** * Returns whether this project is being updated. - * + * * @return true if the document is updating */ protected boolean isUpdating() { return fIsUpdating; } - + /* * @see org.eclipse.jface.text.IDocument#replace(int, int, java.lang.String) */ @@ -601,16 +601,16 @@ public class ProjectionDocument extends AbstractDocument { fIsUpdating= true; if (fMasterDocumentExtension != null) fMasterDocumentExtension.stopPostNotificationProcessing(); - + super.replace(offset, length, text); - + } finally { fIsUpdating= false; if (fMasterDocumentExtension != null) fMasterDocumentExtension.resumePostNotificationProcessing(); } } - + /* * @see org.eclipse.jface.text.IDocument#set(java.lang.String) */ @@ -619,20 +619,20 @@ public class ProjectionDocument extends AbstractDocument { fIsUpdating= true; if (fMasterDocumentExtension != null) fMasterDocumentExtension.stopPostNotificationProcessing(); - + super.set(text); - + } finally { fIsUpdating= false; if (fMasterDocumentExtension != null) fMasterDocumentExtension.resumePostNotificationProcessing(); } } - + /** * Transforms a document event of the master document into a projection * document based document event. - * + * * @param masterEvent the master document event * @return the slave document event * @throws BadLocationException in case the master event is not valid @@ -644,36 +644,36 @@ public class ProjectionDocument extends AbstractDocument { return new ProjectionDocumentEvent(this, imageRegion.getOffset(), imageRegion.getLength(), masterEvent.getText(), masterEvent); return null; } - + ProjectionDocumentEvent event= new ProjectionDocumentEvent(this, fOriginalEvent.getOffset(), fOriginalEvent.getLength(), fOriginalEvent.getText(), masterEvent); fOriginalEvent= null; return event; } - + private boolean includes(IRegion region, int offset) { if (region == null) return false; return region.getOffset() <= offset && offset <= region.getOffset() + region.getLength(); } - + private boolean includes(IRegion region1, int offset, int length) { if (region1 == null) return false; return region1.getOffset() <= offset && (offset + length <= region1.getOffset() + region1.getLength()); } - + /** * Compute the gaps that must be covered in order to ensure that the range affected * by the given document event is completely projected. - * + * * @param event the master document event * @return the gaps to be covered */ private IRegion[] computeCoverageGap(DocumentEvent event) { - + IRegion left= null; List gaps= new ArrayList(); - + try { // deal with the beginning of the event region int imageOffset= fMapping.toImageOffset(event.getOffset()); @@ -686,11 +686,11 @@ public class ProjectionDocument extends AbstractDocument { gaps.add(left); } } - + // the event itself if (!includes(left, event.getOffset(), event.getLength())) gaps.add(new Region(event.getOffset(), event.getLength())); - + // deal with the end of the event region int inclusiveOriginEndOffset= event.getOffset() + Math.max(0, event.getLength() - 1); int inclusiveImageEndOffset= fMapping.toImageOffset(inclusiveOriginEndOffset); @@ -698,42 +698,42 @@ public class ProjectionDocument extends AbstractDocument { int index= fMasterDocument.computeIndexInCategory(fFragmentsCategory, inclusiveOriginEndOffset); if (0 < index) { Position[] fragments= getFragments(); - Fragment fragment= (Fragment) fragments[index - 1]; + Fragment fragment= (Fragment) fragments[index - 1]; gaps.add(new Region(fragment.getOffset(), inclusiveOriginEndOffset + 1 - fragment.getOffset())); } } - + } catch (BadLocationException e) { internalError(); } catch (BadPositionCategoryException e) { internalError(); } - + IRegion[] result= new IRegion[gaps.size()]; gaps.toArray(result); return result; } - + /** * Ensures that when the master event effects this projection document, that the whole region described by the * event is part of this projection document. - * + * * @param masterEvent the master document event * @return true if masterEvent affects this projection document * @throws BadLocationException in case the master event is not valid */ protected final boolean adaptProjectionToMasterChange(DocumentEvent masterEvent) throws BadLocationException { if (!isUpdating() && fFragmentsUpdater.affectsPositions(masterEvent) || fIsAutoExpanding) { - + IRegion[] gaps= computeCoverageGap(masterEvent); for (int i= 0; i < gaps.length; i++) { IRegion gap= gaps[i]; addMasterDocumentRange(gap.getOffset(), gap.getLength(), masterEvent); } - return true; - + return true; + } else if (fMapping.getImageLength() == 0 && masterEvent.getLength() == 0) { - + Position[] fragments= getFragments(); if (fragments.length == 0) { // there is no segment in this projection document, thus one must be created @@ -747,40 +747,40 @@ public class ProjectionDocument extends AbstractDocument { } } } - + return isUpdating(); } - + /** * When called, this projection document is informed about a forthcoming * change of its master document. This projection document checks whether * the master document change affects it and if so informs all document * listeners. - * + * * @param masterEvent the master document event */ public void masterDocumentAboutToBeChanged(DocumentEvent masterEvent) { try { - + boolean assertNotNull= adaptProjectionToMasterChange(masterEvent); fSlaveEvent= normalize(masterEvent); if (assertNotNull && fSlaveEvent == null) internalError(); - + fMasterEvent= masterEvent; if (fSlaveEvent != null) delayedFireDocumentAboutToBeChanged(); - + } catch (BadLocationException e) { internalError(); } } - + /** * When called, this projection document is informed about a change of its * master document. If this projection document is affected it informs all * of its document listeners. - * + * * @param masterEvent the master document event */ public void masterDocumentChanged(DocumentEvent masterEvent) { @@ -796,7 +796,7 @@ public class ProjectionDocument extends AbstractDocument { fMapping.projectionChanged(); } } - + /* * @see org.eclipse.jface.text.AbstractDocument#fireDocumentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) */ @@ -805,14 +805,14 @@ public class ProjectionDocument extends AbstractDocument { // delay it until there is a notification from the master document // at this point, it is expensive to construct the master document information } - + /** * Fires the slave document event as about-to-be-changed event to all registered listeners. */ private void delayedFireDocumentAboutToBeChanged() { super.fireDocumentAboutToBeChanged(fSlaveEvent); } - + /** * Ignores the given event and sends the semantically equal slave document event instead. * @@ -821,7 +821,7 @@ public class ProjectionDocument extends AbstractDocument { protected void fireDocumentChanged(DocumentEvent event) { super.fireDocumentChanged(fSlaveEvent); } - + /* * @see org.eclipse.jface.text.AbstractDocument#updateDocumentStructures(org.eclipse.jface.text.DocumentEvent) */ @@ -830,7 +830,7 @@ public class ProjectionDocument extends AbstractDocument { ensureWellFormedSegmentation(computeAnchor(event)); fMapping.projectionChanged(); } - + private int computeAnchor(DocumentEvent event) { if (event instanceof ProjectionDocumentEvent) { ProjectionDocumentEvent slave= (ProjectionDocumentEvent) event; @@ -845,7 +845,7 @@ public class ProjectionDocument extends AbstractDocument { } return -1; } - + private boolean ensureWellFormedSegmentation(int anchorOffset) { boolean changed= false; Position[] segments= getSegments(); @@ -853,7 +853,7 @@ public class ProjectionDocument extends AbstractDocument { Segment segment= (Segment) segments[i]; if (segment.isDeleted() || segment.getLength() == 0) { try { - removePosition(fSegmentsCategory, segment); + removePosition(fSegmentsCategory, segment); fMasterDocument.removePosition(fFragmentsCategory, segment.fragment); changed= true; } catch (BadPositionCategoryException e) { @@ -872,7 +872,7 @@ public class ProjectionDocument extends AbstractDocument { } } } - + if (changed && anchorOffset != -1) { Position[] changedSegments= getSegments(); if (changedSegments == null || changedSegments.length == 0) { @@ -887,7 +887,7 @@ public class ProjectionDocument extends AbstractDocument { } } } - + return changed; } @@ -899,46 +899,46 @@ public class ProjectionDocument extends AbstractDocument { throw new UnsupportedOperationException(); super.registerPostNotificationReplace(owner, replace); } - - /** + + /** * Sets the auto expand mode for this document. - * + * * @param autoExpandMode true if auto-expanding */ public void setAutoExpandMode(boolean autoExpandMode) { fIsAutoExpanding= autoExpandMode; } - + /** * Replaces all master document ranges with the given master document range. - * + * * @param offsetInMaster the offset in the master document * @param lengthInMaster the length in the master document * @throws BadLocationException if the given range of the master document is not valid */ public void replaceMasterDocumentRanges(int offsetInMaster, int lengthInMaster) throws BadLocationException { try { - + ProjectionDocumentEvent event= new ProjectionDocumentEvent(this, 0, fMapping.getImageLength(), fMasterDocument.get(offsetInMaster, lengthInMaster), offsetInMaster, lengthInMaster); super.fireDocumentAboutToBeChanged(event); - + Position[] fragments= getFragments(); for (int i= 0; i < fragments.length; i++) { Fragment fragment= (Fragment) fragments[i]; fMasterDocument.removePosition(fFragmentsCategory, fragment); removePosition(fSegmentsCategory, fragment.segment); } - + Fragment fragment= new Fragment(offsetInMaster, lengthInMaster); Segment segment= new Segment(0, 0); segment.fragment= fragment; fragment.segment= segment; fMasterDocument.addPosition(fFragmentsCategory, fragment); addPosition(fSegmentsCategory, segment); - + getTracker().set(fMasterDocument.get(offsetInMaster, lengthInMaster)); super.fireDocumentChanged(event); - + } catch (BadPositionCategoryException x) { internalError(); } diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentEvent.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentEvent.java index 085afab0d28..19160d9c62f 100644 --- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentEvent.java +++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentEvent.java @@ -28,30 +28,30 @@ import org.eclipse.jface.text.SlaveDocumentEvent; * Clients are not supposed to create instances of this class. Instances are * created by {@link org.eclipse.jface.text.projection.ProjectionDocument} * instances. This class is not intended to be subclassed. - * + * * @since 3.0 */ public class ProjectionDocumentEvent extends SlaveDocumentEvent { - + /** The change type indicating a projection change */ public final static Object PROJECTION_CHANGE= new Object(); /** The change type indicating a content change */ public final static Object CONTENT_CHANGE= new Object(); - + /** The change type */ private Object fChangeType; /** The offset of the change in the master document */ private int fMasterOffset= -1; /** The length of the change in the master document */ private int fMasterLength= -1; - + /** * Creates a new content change event caused by the given master document * change. Instances created using this constructor return -1 * when calling getMasterOffset or * getMasterLength. This information can be obtained by * accessing the master event. - * + * * @param doc the changed projection document * @param offset the offset in the projection document * @param length the length in the projection document @@ -62,12 +62,12 @@ public class ProjectionDocumentEvent extends SlaveDocumentEvent { super(doc, offset, length, text, masterEvent); fChangeType= CONTENT_CHANGE; } - + /** * Creates a new projection change event for the given properties. Instances * created with this constructor return the given master document offset and * length but do not have an associated master document event. - * + * * @param doc the projection document * @param offset the offset in the projection document * @param length the length in the projection document @@ -89,7 +89,7 @@ public class ProjectionDocumentEvent extends SlaveDocumentEvent { * had to change the projection. Instances created with this constructor * return the given master document offset and length and also have an * associated master document event. - * + * * @param doc the projection document * @param offset the offset in the projection document * @param length the length in the projection document @@ -104,31 +104,31 @@ public class ProjectionDocumentEvent extends SlaveDocumentEvent { fMasterOffset= masterOffset; fMasterLength= masterLength; } - + /** * Returns the change type of this event. This is either {@link #PROJECTION_CHANGE} or * {@link #CONTENT_CHANGE}. - * + * * @return the change type of this event */ public Object getChangeType() { return fChangeType; } - + /** * Returns the offset of the master document range that has been added or removed in case this * event describes a projection change, otherwise it returns -1. - * + * * @return the master document offset of the projection change or -1 */ public int getMasterOffset() { return fMasterOffset; } - + /** * Returns the length of the master document range that has been added or removed in case this event * describes a projection changed, otherwise -1. - * + * * @return the master document length of the projection change or -1 */ public int getMasterLength() { diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentManager.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentManager.java index 66f298f1753..17b283f115f 100644 --- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentManager.java +++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentManager.java @@ -41,17 +41,17 @@ import org.eclipse.jface.text.ISlaveDocumentManagerExtension; *

* Clients can instantiate this class. This class is not intended to be * subclassed. - * + * * @since 3.0 */ -public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocumentManager, ISlaveDocumentManagerExtension { - +public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocumentManager, ISlaveDocumentManagerExtension { + /** Registry for master documents and their projection documents. */ private Map fProjectionRegistry= new HashMap(); - + /** * Registers the given projection document for the given master document. - * + * * @param master the master document * @param projection the projection document */ @@ -63,10 +63,10 @@ public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocum } list.add(projection); } - + /** * Unregisters the given projection document from its master. - * + * * @param master the master document * @param projection the projection document */ @@ -78,21 +78,21 @@ public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocum fProjectionRegistry.remove(master); } } - + /** * Returns whether the given document is a master document. - * + * * @param master the document * @return true if the given document is a master document known to this manager */ private boolean hasProjection(IDocument master) { return (fProjectionRegistry.get(master) instanceof List); } - + /** * Returns an iterator enumerating all projection documents registered for the given document or * null if the document is not a known master document. - * + * * @param master the document * @return an iterator for all registered projection documents or null */ @@ -102,7 +102,7 @@ public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocum return list.iterator(); return null; } - + /** * Informs all projection documents of the master document that issued the given document event. * @@ -114,7 +114,7 @@ public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocum Iterator e= getProjectionsIterator(master); if (e == null) return; - + while (e.hasNext()) { ProjectionDocument document= (ProjectionDocument) e.next(); if (about) @@ -123,7 +123,7 @@ public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocum document.masterDocumentChanged(masterEvent); } } - + /* * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent) */ @@ -137,7 +137,7 @@ public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocum public void documentAboutToBeChanged(DocumentEvent event) { fireDocumentEvent(true, event); } - + /* * @see org.eclipse.jface.text.ISlaveDocumentManager#createMasterSlaveMapping(org.eclipse.jface.text.IDocument) */ @@ -159,10 +159,10 @@ public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocum add(master, slave); return slave; } - + /** - * Factory method for projection documents. - * + * Factory method for projection documents. + * * @param master the master document * @return the newly created projection document */ @@ -192,7 +192,7 @@ public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocum return ((ProjectionDocument) slave).getMasterDocument(); return null; } - + /* * @see org.eclipse.jface.text.ISlaveDocumentManager#isSlaveDocument(org.eclipse.jface.text.IDocument) */ diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionMapping.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionMapping.java index 80d102d7c6b..572466a4e88 100644 --- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionMapping.java +++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionMapping.java @@ -28,15 +28,15 @@ import org.eclipse.jface.text.Region; *

* Implementation of {@link org.eclipse.jface.text.IDocumentInformationMapping} * for the projection mapping between a master and a slave document. - * + * * @since 3.0 */ public class ProjectionMapping implements IDocumentInformationMapping , IDocumentInformationMappingExtension, IDocumentInformationMappingExtension2, IMinimalMapping { - + private static final int LEFT= -1; private static final int NONE= 0; private static final int RIGHT= +1; - + /** The master document */ private IDocument fMasterDocument; /** The position category used to manage the projection fragments inside the master document */ @@ -52,7 +52,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen /** * Creates a new mapping between the given parent document and the given projection document. - * + * * @param masterDocument the master document * @param fragmentsCategory the position category of the parent document used to manage the projected regions * @param slaveDocument the slave document @@ -64,7 +64,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen fSlaveDocument= slaveDocument; fSegmentsCategory= segmentsCategory; } - + /** * Notifies this projection mapping that there was a projection change. */ @@ -72,7 +72,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen fCachedSegments= null; fCachedFragments= null; } - + private Position[] getSegments() { if (fCachedSegments == null) { try { @@ -83,7 +83,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen } return fCachedSegments; } - + private Position[] getFragments() { if (fCachedFragments == null) { try { @@ -94,7 +94,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen } return fCachedFragments; } - + private int findSegmentIndex(int offset) throws BadLocationException { Position[] segments= getSegments(); if (segments.length == 0) { @@ -102,43 +102,43 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen throw new BadLocationException(); return -1; } - + try { int index= fSlaveDocument.computeIndexInCategory(fSegmentsCategory, offset); if (index == segments.length && offset > exclusiveEnd(segments[index-1])) throw new BadLocationException(); - + if (index < segments.length && offset == segments[index].offset) return index; - + if (index > 0) index--; - + return index; - + } catch (BadPositionCategoryException e) { throw new IllegalStateException(); } } private Segment findSegment(int offset) throws BadLocationException { - + checkImageOffset(offset); int index= findSegmentIndex(offset); if (index == -1) { - + Segment s= new Segment(0, 0); Fragment f= new Fragment(0, 0); s.fragment= f; f.segment= s; return s; } - + Position[] segments= getSegments(); - return (Segment) segments[index]; + return (Segment) segments[index]; } - + /** * Computes the fragment index given an origin offset. Returns the index of * the fragment that contains offset, or -1 @@ -153,7 +153,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen * the last fragment and extensionDirection set to * RIGHT. *

- * + * * @param offset an origin offset * @param extensionDirection the direction in which to extend the search, or * NONE @@ -164,19 +164,19 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen */ private int findFragmentIndex(int offset, int extensionDirection) throws BadLocationException { try { - + Position[] fragments= getFragments(); if (fragments.length == 0) return -1; - + int index= fMasterDocument.computeIndexInCategory(fFragmentsCategory, offset); - + if (index < fragments.length && offset == fragments[index].offset) return index; - + if (0 < index && index <= fragments.length && fragments[index - 1].includes(offset)) return index - 1; - + switch (extensionDirection) { case LEFT: return index - 1; @@ -184,9 +184,9 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen if (index < fragments.length) return index; } - + return -1; - + } catch (BadPositionCategoryException e) { throw new IllegalStateException(); } @@ -194,7 +194,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen private Fragment findFragment(int offset) throws BadLocationException { checkOriginOffset(offset); - + int index= findFragmentIndex(offset, NONE); Position[] fragments= getFragments(); if (index == -1) { @@ -207,10 +207,10 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen } return (Fragment) fragments[index]; } - + /** * Returns the image region for originRegion. - * + * * @param originRegion the region to get the image for * @param exact if true, the begin and end offsets of * originRegion must be projected, otherwise @@ -247,9 +247,9 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen } return null; } - + int imageOffset, exclusiveImageEndOffset; - + // translate start offset int relative= originRegion.getOffset() - fragments[0].getOffset(); if (relative < 0) { @@ -257,7 +257,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen relative= 0; } imageOffset= fragments[0].segment.getOffset() + relative; - + // translate end offset relative= exclusiveEnd(originRegion) - fragments[1].getOffset(); if (relative > fragments[1].getLength()) { @@ -265,14 +265,14 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen relative= fragments[1].getLength(); } exclusiveImageEndOffset= fragments[1].segment.getOffset() + relative; - + return new Region(imageOffset, exclusiveImageEndOffset - imageOffset); } - + /** * Returns the two fragments containing the begin and end offsets of * originRegion. - * + * * @param originRegion the region to get the fragments for * @param exact if true, only the fragments that contain the * begin and end offsets are returned; if false, the @@ -290,42 +290,42 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen Position[] fragments= getFragments(); if (fragments.length == 0) return null; - + checkOriginRegion(originRegion); int startFragmentIdx= findFragmentIndex(originRegion.getOffset(), exact ? NONE : RIGHT); if (startFragmentIdx == -1) return null; - + int endFragmentIdx= findFragmentIndex(inclusiveEnd(originRegion), exact ? NONE : LEFT); if (!takeClosestImage && startFragmentIdx > endFragmentIdx || endFragmentIdx == -1) return null; - + Fragment[] result= {(Fragment) fragments[startFragmentIdx], (Fragment) fragments[endFragmentIdx]}; return result; } - + private IRegion createOriginStartRegion(Segment image, int offsetShift) { return new Region(image.fragment.getOffset() + offsetShift, image.fragment.getLength() - offsetShift); } - + private IRegion createOriginRegion(Segment image) { return new Region(image.fragment.getOffset(), image.fragment.getLength()); } - + private IRegion createOriginEndRegion(Segment image, int lengthReduction) { return new Region(image.fragment.getOffset(), image.fragment.getLength() - lengthReduction); } - + private IRegion createImageStartRegion(Fragment origin, int offsetShift) { int shift= offsetShift > 0 ? offsetShift : 0; return new Region(origin.segment.getOffset() + shift, origin.segment.getLength() - shift); } - + private IRegion createImageRegion(Fragment origin) { return new Region(origin.segment.getOffset(), origin.segment.getLength()); } - + private IRegion createImageEndRegion(Fragment origin, int lengthReduction) { int reduction= lengthReduction > 0 ? lengthReduction : 0; return new Region(origin.segment.getOffset(), origin.segment.getLength() - reduction); @@ -335,16 +335,16 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen int shift= offsetShift > 0 ? offsetShift : 0; return new Region(origin.getOffset() + shift, origin.getLength() - shift); } - + private IRegion createOriginRegion(Fragment origin) { return new Region(origin.getOffset(), origin.getLength()); } - + private IRegion createOriginEndRegion(Fragment origin, int lengthReduction) { int reduction= lengthReduction > 0 ? lengthReduction : 0; return new Region(origin.getOffset(), origin.getLength() - reduction); } - + private IRegion getIntersectingRegion(IRegion left, IRegion right) { int offset= Math.max(left.getOffset(), right.getOffset()); int exclusiveEndOffset= Math.min(exclusiveEnd(left), exclusiveEnd(right)); @@ -352,7 +352,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen return null; return new Region(offset, exclusiveEndOffset - offset); } - + /* * @see org.eclipse.jface.text.IDocumentInformationMapping#getCoverage() */ @@ -372,7 +372,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen public int toOriginOffset(int imageOffset) throws BadLocationException { Segment segment= findSegment(imageOffset); int relative= imageOffset - segment.offset; - return segment.fragment.offset + relative; + return segment.fragment.offset + relative; } /* @@ -381,7 +381,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen public IRegion toOriginRegion(IRegion imageRegion) throws BadLocationException { int imageOffset= imageRegion.getOffset(); int imageLength= imageRegion.getLength(); - + if (imageLength == 0) { if (imageOffset == 0) { Position[] fragments= getFragments(); @@ -390,11 +390,11 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen } return new Region(toOriginOffset(imageOffset), 0); } - + int originOffset= toOriginOffset(imageOffset); int inclusiveImageEndOffset= imageOffset + imageLength -1; int inclusiveOriginEndOffset= toOriginOffset(inclusiveImageEndOffset); - + return new Region(originOffset, (inclusiveOriginEndOffset + 1) - originOffset); } @@ -404,11 +404,11 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen public IRegion toOriginLines(int imageLine) throws BadLocationException { IRegion imageRegion= fSlaveDocument.getLineInformation(imageLine); IRegion originRegion= toOriginRegion(imageRegion); - + int originStartLine= fMasterDocument.getLineOfOffset(originRegion.getOffset()); if (originRegion.getLength() == 0) return new Region(originStartLine, 1); - + int originEndLine= fMasterDocument.getLineOfOffset(inclusiveEnd(originRegion)); return new Region(originStartLine, (originEndLine + 1) - originStartLine); } @@ -428,11 +428,11 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen Fragment fragment= findFragment(originOffset); if (fragment != null) { int relative= originOffset - fragment.offset; - return fragment.segment.offset + relative; + return fragment.segment.offset + relative; } return -1; } - + /* * @see org.eclipse.jface.text.IDocumentInformationMappingExtension#toExactImageRegion(org.eclipse.jface.text.IRegion) */ @@ -446,14 +446,14 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen public IRegion toImageRegion(IRegion originRegion) throws BadLocationException { return toImageRegion(originRegion, false, false); } - + /* * @see org.eclipse.jface.text.IDocumentInformationMappingExtension2#toClosestImageRegion(org.eclipse.jface.text.IRegion) */ public IRegion toClosestImageRegion(IRegion originRegion) throws BadLocationException { return toImageRegion(originRegion, false, true); } - + /* * @see org.eclipse.jface.text.IDocumentInformationMapping#toImageLine(int) */ @@ -467,15 +467,15 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen else return -1; } - + int startLine= fSlaveDocument.getLineOfOffset(imageRegion.getOffset()); if (imageRegion.getLength() == 0) return startLine; - + int endLine= fSlaveDocument.getLineOfOffset(imageRegion.getOffset() + imageRegion.getLength()); if (endLine != startLine) throw new IllegalStateException(); - + return startLine; } @@ -484,29 +484,29 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen */ public int toClosestImageLine(int originLine) throws BadLocationException { try { - + int imageLine= toImageLine(originLine); if (imageLine > -1) return imageLine; - + Position[] fragments= getFragments(); if (fragments.length == 0) return -1; - + IRegion originLineRegion= fMasterDocument.getLineInformation(originLine); int index= fMasterDocument.computeIndexInCategory(fFragmentsCategory, originLineRegion.getOffset()); - + if (0 < index && index < fragments.length) { Fragment left= (Fragment) fragments[index - 1]; int leftDistance= originLineRegion.getOffset() - (exclusiveEnd(left)); Fragment right= (Fragment) fragments[index]; int rightDistance= right.getOffset() - (exclusiveEnd(originLineRegion)); - + if (leftDistance <= rightDistance) originLine= fMasterDocument.getLineOfOffset(left.getOffset() + Math.max(left.getLength() - 1, 0)); else originLine= fMasterDocument.getLineOfOffset(right.getOffset()); - + } else if (index == 0) { Fragment right= (Fragment) fragments[index]; originLine= fMasterDocument.getLineOfOffset(right.getOffset()); @@ -514,31 +514,31 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen Fragment left= (Fragment) fragments[index - 1]; originLine= fMasterDocument.getLineOfOffset(exclusiveEnd(left)); } - + return toImageLine(originLine); - + } catch (BadPositionCategoryException x) { } - + return -1; } - + /* * @see org.eclipse.jface.text.IDocumentInformationMappingExtension#toExactOriginRegions(org.eclipse.jface.text.IRegion) */ public IRegion[] toExactOriginRegions(IRegion imageRegion) throws BadLocationException { - + if (imageRegion.getLength() == 0) return new IRegion[] { new Region(toOriginOffset(imageRegion.getOffset()), 0) }; - + int endOffset= exclusiveEnd(imageRegion); Position[] segments= getSegments(); int firstIndex= findSegmentIndex(imageRegion.getOffset()); int lastIndex= findSegmentIndex(endOffset - 1); - + int resultLength= lastIndex - firstIndex + 1; IRegion[] result= new IRegion[resultLength]; - + // first result[0]= createOriginStartRegion((Segment) segments[firstIndex], imageRegion.getOffset() - segments[firstIndex].getOffset()); // middles @@ -546,7 +546,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen result[i]= createOriginRegion((Segment) segments[firstIndex + i]); // last Segment last= (Segment) segments[lastIndex]; - int segmentEndOffset= exclusiveEnd(last); + int segmentEndOffset= exclusiveEnd(last); IRegion lastRegion= createOriginEndRegion(last, segmentEndOffset - endOffset); if (resultLength > 1) { // first != last @@ -559,7 +559,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen else result[0]= intersection; } - + return result; } @@ -573,29 +573,29 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen length += segments[i].length; return length; } - + /* * @see org.eclipse.jface.text.IDocumentInformationMappingExtension#toExactImageRegions(org.eclipse.jface.text.IRegion) */ public IRegion[] toExactImageRegions(IRegion originRegion) throws BadLocationException { - + int offset= originRegion.getOffset(); if (originRegion.getLength() == 0) { int imageOffset= toImageOffset(offset); return imageOffset > -1 ? new IRegion[] { new Region(imageOffset, 0) } : null; } - + int endOffset= exclusiveEnd(originRegion); Position[] fragments= getFragments(); int firstIndex= findFragmentIndex(offset, RIGHT); int lastIndex= findFragmentIndex(endOffset - 1, LEFT); - + if (firstIndex == -1 || firstIndex > lastIndex) return null; - + int resultLength= lastIndex - firstIndex + 1; IRegion[] result= new IRegion[resultLength]; - + // first result[0]= createImageStartRegion((Fragment) fragments[firstIndex], offset - fragments[firstIndex].getOffset()); // middles @@ -603,7 +603,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen result[i]= createImageRegion((Fragment) fragments[firstIndex + i]); // last Fragment last= (Fragment) fragments[lastIndex]; - int fragmentEndOffset= exclusiveEnd(last); + int fragmentEndOffset= exclusiveEnd(last); IRegion lastRegion= createImageEndRegion(last, fragmentEndOffset - endOffset); if (resultLength > 1) { // first != last @@ -615,34 +615,34 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen return null; result[0]= intersection; } - + return result; } - + /* * @see org.eclipse.jface.text.IDocumentInformationMappingExtension#getExactCoverage(org.eclipse.jface.text.IRegion) */ public IRegion[] getExactCoverage(IRegion originRegion) throws BadLocationException { - + int originOffset= originRegion.getOffset(); int originLength= originRegion.getLength(); - + if (originLength == 0) { int imageOffset= toImageOffset(originOffset); return imageOffset > -1 ? new IRegion[] { new Region(originOffset, 0) } : null; } - + int endOffset= originOffset + originLength; Position[] fragments= getFragments(); int firstIndex= findFragmentIndex(originOffset, RIGHT); int lastIndex= findFragmentIndex(endOffset - 1, LEFT); - + if (firstIndex == -1 || firstIndex > lastIndex) return null; - + int resultLength= lastIndex - firstIndex + 1; IRegion[] result= new IRegion[resultLength]; - + // first result[0]= createOriginStartRegion((Fragment) fragments[firstIndex], originOffset - fragments[firstIndex].getOffset()); // middles @@ -650,7 +650,7 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen result[i]= createOriginRegion((Fragment) fragments[firstIndex + i]); // last Fragment last= (Fragment) fragments[lastIndex]; - int fragmentEndOffset= exclusiveEnd(last); + int fragmentEndOffset= exclusiveEnd(last); IRegion lastRegion= createOriginEndRegion(last, fragmentEndOffset - endOffset); if (resultLength > 1) { // first != last @@ -662,10 +662,10 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen return null; result[0]= intersection; } - + return result; } - + private final void checkOriginRegion(IRegion originRegion) throws BadLocationException { int offset= originRegion.getOffset(); int endOffset= inclusiveEnd(originRegion); @@ -673,17 +673,17 @@ public class ProjectionMapping implements IDocumentInformationMapping , IDocumen if (offset < 0 || offset > max || endOffset < 0 || endOffset > max) throw new BadLocationException(); } - + private final void checkOriginOffset(int originOffset) throws BadLocationException { if (originOffset < 0 || originOffset > fMasterDocument.getLength()) throw new BadLocationException(); } - + private final void checkImageOffset(int imageOffset) throws BadLocationException { if (imageOffset < 0 || imageOffset > getImageLength()) throw new BadLocationException(); } - + private final int exclusiveEnd(Position position) { return position.offset + position.length; } diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionTextStore.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionTextStore.java index c774bb02fd5..a410697d19a 100644 --- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionTextStore.java +++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionTextStore.java @@ -21,17 +21,17 @@ import org.eclipse.jface.text.Region; /** * A text store representing the projection defined by the given document * information mapping. - * + * * @since 3.0 */ class ProjectionTextStore implements ITextStore { - + /** * Implementation of {@link IRegion} that can be reused - * by setting the offset and the length. + * by setting the offset and the length. */ private static class ReusableRegion implements IRegion { - + private int fOffset; private int fLength; @@ -48,10 +48,10 @@ class ProjectionTextStore implements ITextStore { public int getOffset() { return fOffset; } - + /** * Updates this region. - * + * * @param offset the new offset * @param length the new length */ @@ -60,19 +60,19 @@ class ProjectionTextStore implements ITextStore { fLength= length; } } - + /** The master document */ private IDocument fMasterDocument; /** The document information mapping */ private IMinimalMapping fMapping; /** Internal region used for querying the mapping. */ private ReusableRegion fReusableRegion= new ReusableRegion(); - - + + /** * Creates a new projection text store for the given master document and * the given document information mapping. - * + * * @param masterDocument the master document * @param mapping the document information mapping */ @@ -80,7 +80,7 @@ class ProjectionTextStore implements ITextStore { fMasterDocument= masterDocument; fMapping= mapping; } - + private void internalError() { throw new IllegalStateException(); } @@ -89,11 +89,11 @@ class ProjectionTextStore implements ITextStore { * @see org.eclipse.jface.text.ITextStore#set(java.lang.String) */ public void set(String contents) { - + IRegion masterRegion= fMapping.getCoverage(); if (masterRegion == null) internalError(); - + try { fMasterDocument.replace(masterRegion.getOffset(), masterRegion.getLength(), contents); } catch (BadLocationException e) { @@ -112,7 +112,7 @@ class ProjectionTextStore implements ITextStore { } catch (BadLocationException e) { internalError(); } - } + } /* * @see org.eclipse.jface.text.ITextStore#getLength() @@ -120,7 +120,7 @@ class ProjectionTextStore implements ITextStore { public int getLength() { return fMapping.getImageLength(); } - + /* * @see org.eclipse.jface.text.ITextStore#get(int) */ @@ -131,11 +131,11 @@ class ProjectionTextStore implements ITextStore { } catch (BadLocationException e) { internalError(); } - + // unreachable return (char) 0; } - + /* * @see ITextStore#get(int, int) */ @@ -151,7 +151,7 @@ class ProjectionTextStore implements ITextStore { } catch (BadLocationException e) { internalError(); } - + // unreachable return null; } diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/Segment.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/Segment.java index 15a8a4b0044..439047f785c 100644 --- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/Segment.java +++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/Segment.java @@ -19,35 +19,35 @@ import org.eclipse.jface.text.Position; *

* A segment is the image of a master document fragment in a projection * document. - * + * * @since 3.0 */ public class Segment extends Position { - + /** The corresponding fragment for this segment. */ public Fragment fragment; /** A flag indicating that the segment updater should stretch this segment when a change happens at its boundaries. */ public boolean isMarkedForStretch; /** A flag indicating that the segment updater should shift this segment when a change happends at its boundaries. */ public boolean isMarkedForShift; - + /** * Creates a new segment covering the given range. - * + * * @param offset the offset of the segment * @param length the length of the segment */ public Segment(int offset, int length) { super(offset, length); } - + /** * Sets the stretching flag. */ public void markForStretch() { isMarkedForStretch= true; } - + /** * Returns true if the stretching flag is set, false otherwise. * @return true if the stretching flag is set, false otherwise @@ -55,14 +55,14 @@ public class Segment extends Position { public boolean isMarkedForStretch() { return isMarkedForStretch; } - + /** * Sets the shifting flag. */ public void markForShift() { isMarkedForShift= true; } - + /** * Returns true if the shifting flag is set, false otherwise. * @return true if the shifting flag is set, false otherwise @@ -70,7 +70,7 @@ public class Segment extends Position { public boolean isMarkedForShift() { return isMarkedForShift; } - + /** * Clears the shifting and the streching flag. */ diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/SegmentUpdater.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/SegmentUpdater.java index 11a9e55f368..312deffabae 100644 --- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/SegmentUpdater.java +++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/SegmentUpdater.java @@ -24,28 +24,28 @@ import org.eclipse.jface.text.Position; * segment is either extended to shifted if an insertion happens at a segment's * offset. The last segment is extended if an insert operation happens at the * end of the segment. - * + * * @since 3.0 */ class SegmentUpdater extends DefaultPositionUpdater { - + private Segment fNextSegment= null; private boolean fIsProjectionChange= false; - + /** * Creates the segment updater for the given category. - * + * * @param segmentCategory the position category used for managing the segments of a projection document */ protected SegmentUpdater(String segmentCategory) { super(segmentCategory); } - + /* * @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent) */ public void update(DocumentEvent event) { - + Assert.isTrue(event instanceof ProjectionDocumentEvent); fIsProjectionChange= ((ProjectionDocumentEvent) event).getChangeType() == ProjectionDocumentEvent.PROJECTION_CHANGE; @@ -59,33 +59,33 @@ class SegmentUpdater extends DefaultPositionUpdater { fDocument= event.getDocument(); for (int i= 0; i < category.length; i++) { - + fPosition= category[i]; Assert.isTrue(fPosition instanceof Segment); - + if (i < category.length - 1) fNextSegment= (Segment) category[i + 1]; else fNextSegment= null; - + fOriginalPosition.offset= fPosition.offset; fOriginalPosition.length= fPosition.length; if (notDeleted()) adaptToReplace(); - + } - + } catch (BadPositionCategoryException x) { // do nothing } } - + /* * @see org.eclipse.jface.text.DefaultPositionUpdater#adaptToInsert() */ protected void adaptToInsert() { - + Segment segment= (Segment) fPosition; int myStart= segment.offset; int myEnd= segment.offset + segment.length - (segment.isMarkedForStretch || fNextSegment == null || isAffectingReplace() ? 0 : 1); @@ -93,10 +93,10 @@ class SegmentUpdater extends DefaultPositionUpdater { int yoursStart= fOffset; try { - + if (myEnd < yoursStart) return; - + if (segment.isMarkedForStretch) { Assert.isTrue(fIsProjectionChange); segment.isMarkedForShift= false; @@ -105,22 +105,22 @@ class SegmentUpdater extends DefaultPositionUpdater { fNextSegment.isMarkedForStretch= false; } } - + if (fLength <= 0) { - + if (myStart < (yoursStart + (segment.isMarkedForShift ? 0 : 1))) fPosition.length += fReplaceLength; else fPosition.offset += fReplaceLength; - + } else { - + if (myStart <= yoursStart && fOriginalPosition.offset <= yoursStart) fPosition.length += fReplaceLength; else fPosition.offset += fReplaceLength; } - + } finally { segment.clearMark(); } -- cgit v1.2.3