Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.text/projection/org/eclipse/jface/text')
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocument.java97
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocumentManager.java34
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/Fragment.java41
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/FragmentUpdater.java136
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/IMinimalMapping.java52
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java889
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentEvent.java137
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentManager.java223
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionMapping.java626
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionTextStore.java158
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/Segment.java81
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/SegmentUpdater.java128
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/package.html23
13 files changed, 0 insertions, 2625 deletions
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
deleted file mode 100644
index dfd775d32ae..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocument.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.projection;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Position;
-
-/**
- * Implementation of a child document based on
- * {@link org.eclipse.jface.text.projection.ProjectionDocument}. This class
- * exists for compatibility reasons.
- * <p>
- * 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 offset the offset of the region
- * @param length the length of the region
- */
- public VisibleRegion(int offset, int length) {
- super(offset, length);
- }
-
- /**
- * If offset is the end of the visible region and the length is 0,
- * the offset is considered overlapping with the visible region.
- *
- * @see org.eclipse.jface.text.Position#overlapsWith(int, int)
- */
- public boolean overlapsWith(int offset, int length) {
- boolean appending= (offset == this.offset + this.length) && length == 0;
- return appending || super.overlapsWith(offset, length);
- }
- }
-
- /**
- * Creates a new child document.
- *
- * @param masterDocument @inheritDoc
- */
- public ChildDocument(IDocument masterDocument) {
- super(masterDocument);
- }
-
- /**
- * Returns the parent document of this child document.
- *
- * @return the parent document of this child document
- * @see ProjectionDocument#getMasterDocument()
- */
- public IDocument getParentDocument() {
- return getMasterDocument();
- }
-
- /**
- * 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
- */
- public void setParentDocumentRange(int offset, int length) throws BadLocationException {
- replaceMasterDocumentRanges(offset, length);
- }
-
- /**
- * Returns the parent document range of this child document.
- *
- * @return the parent document range of this child document
- */
- public Position getParentDocumentRange() {
- IRegion coverage= getProjectionMapping().getCoverage();
- return new VisibleRegion(coverage.getOffset(), coverage.getLength());
- }
-}
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
deleted file mode 100644
index 8109b76e250..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocumentManager.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.projection;
-
-
-import org.eclipse.jface.text.IDocument;
-
-
-/**
- * Implementation of a child document manager based on
- * {@link org.eclipse.jface.text.projection.ProjectionDocumentManager}. This
- * class exists for compatibility reasons.
- * <p>
- * 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)
- */
- protected ProjectionDocument createProjectionDocument(IDocument master) {
- return new ChildDocument(master);
- }
-}
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
deleted file mode 100644
index fcdb8c6e8b5..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/Fragment.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.projection;
-
-
-import org.eclipse.jface.text.Position;
-
-
-/**
- * Internal class. Do not use. Only public for testing purposes.
- * <p>
- * 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
- */
- public Fragment(int offset, int length) {
- super(offset, length);
- }
-}
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
deleted file mode 100644
index c357f3638eb..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/FragmentUpdater.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.projection;
-
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Position;
-
-
-/**
- * The position updater used to adapt the fragments of a master document. If an
- * 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)
- */
- public void update(DocumentEvent event) {
-
- try {
-
- Position[] category= event.getDocument().getPositions(getCategory());
-
- fOffset= event.getOffset();
- fLength= event.getLength();
- fReplaceLength= (event.getText() == null ? 0 : event.getText().length());
- 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;
-
- if (notDeleted())
- adaptToReplace();
- }
-
- } catch (BadPositionCategoryException x) {
- // 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;
-
- if (fLength <= 0) {
-
- if (myStart <= fOffset)
- fPosition.length += fReplaceLength;
- else
- fPosition.offset += fReplaceLength;
-
- } else {
-
- if (myStart <= fOffset && fOriginalPosition.offset <= fOffset)
- fPosition.length += fReplaceLength;
- else
- 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 <code>true</code> if there is any affected position,
- * <code>false</code> otherwise
- */
- 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()))
- return true;
- if (fragment.offset + fragment.length == event.getOffset())
- return index == fragments.length;
- }
-
- if (index < fragments.length) {
- Position fragment= fragments[index];
- return fragment.overlapsWith(event.getOffset(), event.getLength());
- }
-
- } catch (BadLocationException x) {
- } catch (BadPositionCategoryException x) {
- }
-
- 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
deleted file mode 100644
index a0a89831945..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/IMinimalMapping.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.projection;
-
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IRegion;
-
-
-/**
- * Internal interface for defining the exact subset of
- * {@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 {
-
- /**
- * @see org.eclipse.jface.text.IDocumentInformationMapping#getCoverage()
- */
- IRegion getCoverage();
-
- /**
- * @see org.eclipse.jface.text.IDocumentInformationMapping#toOriginRegion(IRegion)
- */
- IRegion toOriginRegion(IRegion region) throws BadLocationException;
-
- /**
- * @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()
- */
- int 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
deleted file mode 100644
index 3f1641c36a7..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java
+++ /dev/null
@@ -1,889 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.projection;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jface.text.AbstractDocument;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultLineTracker;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.ILineTracker;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextStore;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-
-
-/**
- * A <code>ProjectionDocument</code> represents a projection of its master
- * document. The contents of a projection document is a sequence of fragments of
- * the master document, i.e. the projection document can be thought as being
- * constructed from the master document by not copying the whole master document
- * but omitting several ranges of the master document.
- * <p>
- * The projection document indirectly utilizes its master document as
- * <code>ITextStore</code> by means of a <code>ProjectionTextStore</code>.
- * <p>
- * The content of a projection document can be changed in two ways. Either by a
- * text replace applied to the master document or the projection document. Or by
- * changing the projection between the master document and the projection
- * document. For the latter the two methods <code>addMasterDocumentRange</code>
- * and <code>removeMasterDocumentRange</code> are provided. For any
- * manipulation, the projection document sends out a
- * {@link org.eclipse.jface.text.projection.ProjectionDocumentEvent} describing
- * the change.
- * <p>
- * Clients are not supposed to directly instantiate this class. In order to
- * obtain a projection document, a
- * {@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
- * document.
- */
- private final static String FRAGMENTS_CATEGORY_PREFIX= "__fragmentsCategory"; //$NON-NLS-1$
-
- /**
- * Name of the position category used to keep track of the project
- * document's segments that correspond to the fragments of the master
- * document.
- */
- private final static String SEGMENTS_CATEGORY= "__segmentsCategory"; //$NON-NLS-1$
-
-
- /** The master document */
- private IDocument fMasterDocument;
- /** The master document as document extension */
- private IDocumentExtension fMasterDocumentExtension;
- /** The fragments' position category */
- private String fFragmentsCategory;
- /** The segment's position category */
- private String fSegmentsCategory;
- /** The document event issued by the master document */
- private DocumentEvent fMasterEvent;
- /** The document event to be issued by the projection document */
- private ProjectionDocumentEvent fSlaveEvent;
- /** 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;
- /** Indicated whether the projection document is in auto expand mode nor not */
- private boolean fIsAutoExpanding= false;
- /** The position updater for the segments */
- private SegmentUpdater fSegmentUpdater;
- /** The position updater for the fragments */
- private FragmentUpdater fFragmentsUpdater;
- /** The projection mapping */
- private ProjectionMapping fMapping;
-
- /**
- * Creates a projection document for the given master document.
- *
- * @param masterDocument the master document
- */
- public ProjectionDocument(IDocument masterDocument) {
- super();
-
- fMasterDocument= masterDocument;
- 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);
-
- 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.
- */
- public void dispose() {
- fMasterDocument.removePositionUpdater(fFragmentsUpdater);
- try {
- fMasterDocument.removePositionCategory(fFragmentsCategory);
- } catch (BadPositionCategoryException x) {
- // 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() {
- try {
- return fMasterDocument.getPositions(fFragmentsCategory);
- } catch (BadPositionCategoryException e) {
- internalError();
- }
- // unreachable
- return null;
- }
-
- /**
- * Returns the segments of this projection document.
- *
- * @return the segments of this projection document
- */
- protected final Position[] getSegments() {
- try {
- return getPositions(fSegmentsCategory);
- } catch (BadPositionCategoryException e) {
- internalError();
- }
- // 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() {
- return fMasterDocument;
- }
-
- /**
- * Initializes the projection document from the master document based on
- * 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++) {
- Fragment fragment= (Fragment) fragments[i];
- Segment segment= new Segment(offset, fragment.getLength());
- segment.fragment= fragment;
- 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
- * @throws BadLocationException in case the fragment is invalid
- * @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
- * projection change or <code>null</code> if none
- * @throws BadLocationException if the given range is invalid in the master
- * 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)
- right= (Fragment) fragments[index];
- }
-
- if (0 < index && index <= fragments.length) {
- Fragment fragment= (Fragment) fragments[index - 1];
- if (fragment.includes(offsetInMaster))
- throw new IllegalArgumentException("overlaps with existing fragment"); //$NON-NLS-1$
- 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);
- fMasterDocument.addPosition(fFragmentsCategory, fragment);
- 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
- */
- private Fragment findFragment(int offsetInMaster, int lengthInMaster) {
- Position[] fragments= getFragments();
- for (int i= 0; i < fragments.length; i++) {
- Fragment f= (Fragment) fragments[i];
- if (f.getOffset() <= offsetInMaster && offsetInMaster + lengthInMaster <= f.getOffset() + f.getLength())
- return f;
- }
- 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
- * this projection document or is not completely comprised by
- * an existing fragment
- */
- 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);
- } else if (fragment.getOffset() + fragment.getLength() == offsetInMaster + lengthInMaster) {
- 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());
- newFragment.segment= segment;
- 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);
- offset= imageRegion.getOffset() + imageRegion.getLength();
- segment= new Segment(offset, fragment.segment.getOffset() + fragment.segment.getLength() - offset);
- newFragment.segment= segment;
- 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 with 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 document
- * @throws BadLocationException in case the given range is invalid in the 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];
- int leftEnd= left.getOffset() + left.getLength();
- 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;
- }
-
- /**
- * 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
- */
- public void addMasterDocumentRange(int offsetInMaster, int lengthInMaster) throws BadLocationException {
- addMasterDocumentRange(offsetInMaster, lengthInMaster, 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
- * @param masterDocumentEvent the master document event which causes this
- * projection change, or <code>null</code> if none
- * @throws BadLocationException in case the master event is not valid
- */
- private void addMasterDocumentRange(int offsetInMaster, int lengthInMaster, DocumentEvent masterDocumentEvent) throws BadLocationException {
-
- IRegion[] gaps= computeUnprojectedMasterRegions(offsetInMaster, lengthInMaster);
- if (gaps == null)
- return;
-
- for (int i= 0; i < gaps.length; i++) {
- IRegion gap= gaps[i];
- 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
- */
- public void removeMasterDocumentRange(int offsetInMaster, int lengthInMaster) throws BadLocationException {
- 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 <code>null</code> 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 <code>null</code>
- * @throws BadLocationException in case the given range is invalid in the master document
- */
- final public IRegion[] computeProjectedMasterRegions(int offsetInMaster, int lengthInMaster) throws BadLocationException {
- IRegion imageRegion= fMapping.toImageRegion(new Region(offsetInMaster, lengthInMaster));
- if (imageRegion != null)
- return fMapping.toExactOriginRegions(imageRegion);
- return null;
- }
-
- /**
- * Returns whether this project is being updated.
- *
- * @return <code>true</code> if the document is updating
- */
- protected boolean isUpdating() {
- return fIsUpdating;
- }
-
- /*
- * @see org.eclipse.jface.text.IDocument#replace(int, int, java.lang.String)
- */
- public void replace(int offset, int length, String text) throws BadLocationException {
- try {
- 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)
- */
- public void set(String text) {
- try {
- 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
- */
- private ProjectionDocumentEvent normalize(DocumentEvent masterEvent) throws BadLocationException {
- if (!isUpdating()) {
- IRegion imageRegion= fMapping.toExactImageRegion(new Region(masterEvent.getOffset(), masterEvent.getLength()));
- if (imageRegion != null)
- return new ProjectionDocumentEvent(this, imageRegion.getOffset(), imageRegion.getLength(), masterEvent.getText(), masterEvent);
- return null;
- } else {
- 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());
- if (imageOffset == -1) {
- Position[] fragments= getFragments();
- int index= fMasterDocument.computeIndexInCategory(fFragmentsCategory, event.getOffset());
- if (index < fragments.length) {
- Fragment fragment= (Fragment) fragments[index];
- left= new Region(event.getOffset(), fragment.getOffset() - event.getOffset());
- 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);
- if (inclusiveImageEndOffset == -1 && !includes(left, inclusiveOriginEndOffset)) {
- int index= fMasterDocument.computeIndexInCategory(fFragmentsCategory, inclusiveOriginEndOffset);
- if (0 < index) {
- Position[] fragments= getFragments();
- 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 <code>true</code> 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;
-
- } 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
- // need to bypass the usual infrastructure as the new segment/fragment would be of length 0 and thus the segmentation be not well formed
- try {
- Fragment fragment= new Fragment(0, 0);
- fMasterDocument.addPosition(fFragmentsCategory, fragment);
- createSegmentFor(fragment, 0);
- } catch (BadPositionCategoryException x) {
- internalError();
- }
- }
- }
-
- 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) {
- if ( !isUpdating() && masterEvent == fMasterEvent) {
- if (fSlaveEvent != null) {
- try {
- getTracker().replace(fSlaveEvent.getOffset(), fSlaveEvent.getLength(), fSlaveEvent.getText());
- fireDocumentChanged(fSlaveEvent);
- } catch (BadLocationException e) {
- internalError();
- }
- } else if (ensureWellFormedSegmentation(masterEvent.getOffset()))
- fMapping.projectionChanged();
- }
- }
-
- /*
- * @see org.eclipse.jface.text.AbstractDocument#fireDocumentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
- */
- protected void fireDocumentAboutToBeChanged(DocumentEvent event) {
- fOriginalEvent= event;
- // 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.
- *
- * @param event the event to be ignored
- */
- protected void fireDocumentChanged(DocumentEvent event) {
- super.fireDocumentChanged(fSlaveEvent);
- }
-
- /*
- * @see org.eclipse.jface.text.AbstractDocument#updateDocumentStructures(org.eclipse.jface.text.DocumentEvent)
- */
- protected void updateDocumentStructures(DocumentEvent event) {
- super.updateDocumentStructures(event);
- ensureWellFormedSegmentation(computeAnchor(event));
- fMapping.projectionChanged();
- }
-
- private int computeAnchor(DocumentEvent event) {
- if (event instanceof ProjectionDocumentEvent) {
- ProjectionDocumentEvent slave= (ProjectionDocumentEvent) event;
- if (ProjectionDocumentEvent.CONTENT_CHANGE == slave.getChangeType()) {
- DocumentEvent master= slave.getMasterEvent();
- if (master != null)
- return master.getOffset();
- }
- }
- return -1;
- }
-
- private boolean ensureWellFormedSegmentation(int anchorOffset) {
- boolean changed= false;
- Position[] segments= getSegments();
- for (int i= 0; i < segments.length; i++) {
- Segment segment= (Segment) segments[i];
- if (segment.isDeleted() || segment.getLength() == 0) {
- try {
- removePosition(fSegmentsCategory, segment);
- fMasterDocument.removePosition(fFragmentsCategory, segment.fragment);
- changed= true;
- } catch (BadPositionCategoryException e) {
- internalError();
- }
- } else if (i < segments.length - 1) {
- Segment next= (Segment) segments[i + 1];
- if (next.isDeleted() || next.getLength() == 0)
- continue;
- Fragment fragment= segment.fragment;
- if (fragment.getOffset() + fragment.getLength() == next.fragment.getOffset()) {
- // join fragments and their corresponding segments
- segment.setLength(segment.getLength() + next.getLength());
- fragment.setLength(fragment.getLength() + next.fragment.getLength());
- next.delete();
- }
- }
- }
-
- if (changed && anchorOffset != -1) {
- Position[] changedSegments= getSegments();
- if (changedSegments == null || changedSegments.length == 0) {
- Fragment fragment= new Fragment(anchorOffset, 0);
- try {
- fMasterDocument.addPosition(fFragmentsCategory, fragment);
- createSegmentFor(fragment, 0);
- } catch (BadLocationException e) {
- internalError();
- } catch (BadPositionCategoryException e) {
- internalError();
- }
- }
- }
-
- return changed;
- }
-
- /*
- * @see IDocumentExtension#registerPostNotificationReplace(IDocumentListener, IDocumentExtension.IReplace)
- */
- public void registerPostNotificationReplace(IDocumentListener owner, IDocumentExtension.IReplace replace) {
- if (!isUpdating())
- throw new UnsupportedOperationException();
- super.registerPostNotificationReplace(owner, replace);
- }
-
- /**
- * Sets the auto expand mode for this document.
- *
- * @param autoExpandMode <code>true</code> 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
deleted file mode 100644
index 79125c9823a..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentEvent.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.projection;
-
-
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.SlaveDocumentEvent;
-
-
-/**
- * This event is sent out by an
- * {@link org.eclipse.jface.text.projection.ProjectionDocument}when it is
- * manipulated. The manipulation is either a content manipulation or a change of
- * the projection between the master and the slave. Clients can determine the
- * type of change by asking the projection document event for its change type
- * (see {@link #getChangeType()}) and comparing it with the predefined types
- * {@link #PROJECTION_CHANGE}and {@link #CONTENT_CHANGE}.
- * <p>
- * 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 <code>-1</code>
- * when calling <code>getMasterOffset</code> or
- * <code>getMasterLength</code>. 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
- * @param text the replacement text
- * @param masterEvent the original master event
- */
- public ProjectionDocumentEvent(IDocument doc, int offset, int length, String text, DocumentEvent masterEvent) {
- 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
- * @param text the replacement text
- * @param masterOffset the offset in the master document
- * @param masterLength the length in the master document
- */
- public ProjectionDocumentEvent(IDocument doc, int offset, int length, String text, int masterOffset, int masterLength) {
- super(doc, offset, length, text, null);
- fChangeType= PROJECTION_CHANGE;
- fMasterOffset= masterOffset;
- fMasterLength= masterLength;
- }
-
- /**
- * Creates a new projection document event for the given properties. The
- * projection change is caused by a manipulation of the master document. In
- * order to accommodate the master document change, the projection document
- * 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
- * @param text the replacement text
- * @param masterOffset the offset in the master document
- * @param masterLength the length in the master document
- * @param masterEvent the master document event
- */
- public ProjectionDocumentEvent(IDocument doc, int offset, int length, String text, int masterOffset, int masterLength, DocumentEvent masterEvent) {
- super(doc, offset, length, text, masterEvent);
- fChangeType= PROJECTION_CHANGE;
- 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 <code>-1</code>.
- *
- * @return the master document offset of the projection change or <code>-1</code>
- */
- 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 <code>-1</code>.
- *
- * @return the master document length of the projection change or <code>-1</code>
- */
- public int getMasterLength() {
- return fMasterLength;
- }
-}
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
deleted file mode 100644
index 4fe4c6a2ca6..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentManager.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.projection;
-
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentInformationMapping;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.ISlaveDocumentManager;
-import org.eclipse.jface.text.ISlaveDocumentManagerExtension;
-
-
-/**
- * A <code>ProjectionDocumentManager</code> is one particular implementation
- * of {@link org.eclipse.jface.text.ISlaveDocumentManager}. This manager
- * creates so called projection documents (see
- * {@link org.eclipse.jface.text.projection.ProjectionDocument}as slave
- * documents for given master documents.
- * <p>
- * A projection document represents a particular projection of the master
- * document and is accordingly adapted to changes of the master document. Vice
- * versa, the master document is accordingly adapted to changes of its slave
- * documents. The manager does not maintain any particular management structure
- * but utilizes mechanisms given by {@link org.eclipse.jface.text.IDocument}
- * such as position categories and position updaters.
- * <p>
- * Clients can instantiate this class. This class is not intended to be
- * subclassed.
- *
- * @since 3.0
- */
-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
- */
- private void add(IDocument master, ProjectionDocument projection) {
- List list= (List) fProjectionRegistry.get(master);
- if (list == null) {
- list= new ArrayList(1);
- fProjectionRegistry.put(master, list);
- }
- list.add(projection);
- }
-
- /**
- * Unregisters the given projection document from its master.
- *
- * @param master the master document
- * @param projection the projection document
- */
- private void remove(IDocument master, ProjectionDocument projection) {
- List list= (List) fProjectionRegistry.get(master);
- if (list != null) {
- list.remove(projection);
- if (list.size() == 0)
- fProjectionRegistry.remove(master);
- }
- }
-
- /**
- * Returns whether the given document is a master document.
- *
- * @param master the document
- * @return <code>true</code> 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
- * <code>null</code> if the document is not a known master document.
- *
- * @param master the document
- * @return an iterator for all registered projection documents or <code>null</code>
- */
- private Iterator getProjectionsIterator(IDocument master) {
- List list= (List) fProjectionRegistry.get(master);
- if (list != null)
- return list.iterator();
- return null;
- }
-
- /**
- * Informs all projection documents of the master document that issued the given document event.
- *
- * @param about indicates whether the change is about to happen or happened already
- * @param masterEvent the document event which will be processed to inform the projection documents
- */
- protected void fireDocumentEvent(boolean about, DocumentEvent masterEvent) {
- IDocument master= masterEvent.getDocument();
- Iterator e= getProjectionsIterator(master);
- if (e == null)
- return;
-
- while (e.hasNext()) {
- ProjectionDocument document= (ProjectionDocument) e.next();
- if (about)
- document.masterDocumentAboutToBeChanged(masterEvent);
- else
- document.masterDocumentChanged(masterEvent);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentChanged(DocumentEvent event) {
- fireDocumentEvent(false, event);
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentAboutToBeChanged(DocumentEvent event) {
- fireDocumentEvent(true, event);
- }
-
- /*
- * @see org.eclipse.jface.text.ISlaveDocumentManager#createMasterSlaveMapping(org.eclipse.jface.text.IDocument)
- */
- public IDocumentInformationMapping createMasterSlaveMapping(IDocument slave) {
- if (slave instanceof ProjectionDocument) {
- ProjectionDocument projectionDocument= (ProjectionDocument) slave;
- return projectionDocument.getProjectionMapping();
- }
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.ISlaveDocumentManager#createSlaveDocument(org.eclipse.jface.text.IDocument)
- */
- public IDocument createSlaveDocument(IDocument master) {
- if (!hasProjection(master))
- master.addDocumentListener(this);
- ProjectionDocument slave= createProjectionDocument(master);
- add(master, slave);
- return slave;
- }
-
- /**
- * Factory method for projection documents.
- *
- * @param master the master document
- * @return the newly created projection document
- */
- protected ProjectionDocument createProjectionDocument(IDocument master) {
- return new ProjectionDocument(master);
- }
-
- /*
- * @see org.eclipse.jface.text.ISlaveDocumentManager#freeSlaveDocument(org.eclipse.jface.text.IDocument)
- */
- public void freeSlaveDocument(IDocument slave) {
- if (slave instanceof ProjectionDocument) {
- ProjectionDocument projectionDocument= (ProjectionDocument) slave;
- IDocument master= projectionDocument.getMasterDocument();
- remove(master, projectionDocument);
- projectionDocument.dispose();
- if (!hasProjection(master))
- master.removeDocumentListener(this);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.ISlaveDocumentManager#getMasterDocument(org.eclipse.jface.text.IDocument)
- */
- public IDocument getMasterDocument(IDocument slave) {
- if (slave instanceof ProjectionDocument)
- return ((ProjectionDocument) slave).getMasterDocument();
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.ISlaveDocumentManager#isSlaveDocument(org.eclipse.jface.text.IDocument)
- */
- public boolean isSlaveDocument(IDocument document) {
- return (document instanceof ProjectionDocument);
- }
-
- /*
- * @see org.eclipse.jface.text.ISlaveDocumentManager#setAutoExpandMode(org.eclipse.jface.text.IDocument, boolean)
- */
- public void setAutoExpandMode(IDocument slave, boolean autoExpanding) {
- if (slave instanceof ProjectionDocument)
- ((ProjectionDocument) slave).setAutoExpandMode(autoExpanding);
- }
-
- /*
- * @see org.eclipse.jface.text.ISlaveDocumentManagerExtension#getSlaveDocuments(org.eclipse.jface.text.IDocument)
- */
- public IDocument[] getSlaveDocuments(IDocument master) {
- List list= (List) fProjectionRegistry.get(master);
- if (list != null) {
- IDocument[] result= new IDocument[list.size()];
- list.toArray(result);
- return result;
- }
- return null;
- }
-}
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
deleted file mode 100644
index ede2945c699..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionMapping.java
+++ /dev/null
@@ -1,626 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.projection;
-
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentInformationMapping;
-import org.eclipse.jface.text.IDocumentInformationMappingExtension;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-
-
-/**
- * Internal class. Do not use. Only public for testing purposes.
- * <p>
- * 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, 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 */
- private String fFragmentsCategory;
- /** The projection document */
- private IDocument fSlaveDocument;
- /** The position category to manage the projection segments inside the slave document. */
- private String fSegmentsCategory;
- /** Cached segments */
- private Position[] fCachedSegments;
- /** Cached fragments */
- private Position[] fCachedFragments;
- /** Thread local indices */
- private static ThreadLocal sfIndices= new ThreadLocal() {
- protected Object initialValue() {
- return new int[2];
- }
- };
-
-
- /**
- * 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
- * @param segmentsCategory the position category of the projection document used to manage the fragments
- */
- public ProjectionMapping(IDocument masterDocument, String fragmentsCategory, IDocument slaveDocument, String segmentsCategory) {
- fMasterDocument= masterDocument;
- fFragmentsCategory= fragmentsCategory;
- fSlaveDocument= slaveDocument;
- fSegmentsCategory= segmentsCategory;
- }
-
- /**
- * Notifies this projection mapping that there was a projection change.
- */
- public void projectionChanged() {
- fCachedSegments= null;
- fCachedFragments= null;
- }
-
- private Position[] getSegments() {
- if (fCachedSegments == null) {
- try {
- fCachedSegments= fSlaveDocument.getPositions(fSegmentsCategory);
- } catch (BadPositionCategoryException e) {
- return new Position[0];
- }
- }
- return fCachedSegments;
- }
-
- private Position[] getFragments() {
- if (fCachedFragments == null) {
- try {
- fCachedFragments= fMasterDocument.getPositions(fFragmentsCategory);
- } catch (BadPositionCategoryException e) {
- return new Position[0];
- }
- }
- return fCachedFragments;
- }
-
- private int findSegmentIndex(int offset) throws BadLocationException {
- Position[] segments= getSegments();
- if (segments.length == 0) {
- if (offset > 0)
- throw new BadLocationException();
- return -1;
- }
-
- try {
- int index= fSlaveDocument.computeIndexInCategory(fSegmentsCategory, offset);
- if (index == segments.length && offset > (segments[index-1].offset + segments[index-1].length))
- 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 {
-
- if (offset < 0 || getImageLength() < offset)
- throw new BadLocationException();
-
- 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];
- }
-
- 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 Math.max(index - 1, 0);
- case RIGHT:
- return Math.min(index, fragments.length - 1);
- }
-
- return -1;
-
- } catch (BadPositionCategoryException e) {
- throw new IllegalStateException();
- }
- }
-
- private Fragment findFragment(int offset) throws BadLocationException {
-
- int length= fMasterDocument.getLength();
- if (offset < 0 || length < offset)
- throw new BadLocationException();
-
- int index= findFragmentIndex(offset, NONE);
- Position[] fragments= getFragments();
- if (index == -1) {
- if (fragments.length > 0) {
- Fragment last= (Fragment) fragments[fragments.length - 1];
- if (last.getOffset() + last.getLength() == offset)
- return last;
- }
- return null;
- }
- return (Fragment) fragments[index];
- }
-
- private void findFragmentIndices(IRegion region, boolean exact, int[] result) throws BadLocationException {
- int offset= region.getOffset();
- if (offset < 0 || fMasterDocument.getLength() < offset)
- throw new BadLocationException();
-
- int inclusiveEndOffset= region.getOffset() + region.getLength() - 1;
- if (inclusiveEndOffset < 0 || fMasterDocument.getLength() < inclusiveEndOffset)
- throw new BadLocationException();
-
- int startIndex= findFragmentIndex(offset, exact ? NONE : LEFT);
- if (startIndex == -1) {
- result[0]= -1;
- return;
- }
-
- int endIndex= findFragmentIndex(inclusiveEndOffset, exact ? NONE : RIGHT);
- if (endIndex == -1) {
- result[0]= -1;
- return;
- }
-
- Position[] fragments= getFragments();
- while (startIndex <= endIndex && !fragments[startIndex].overlapsWith(region.getOffset(), region.getLength()))
- ++startIndex;
-
- while (endIndex >= startIndex && !fragments[endIndex].overlapsWith(region.getOffset(), region.getLength()))
- --endIndex;
-
- if (startIndex > endIndex) {
- result[0]= -1;
- return;
- }
-
- result[0]= startIndex;
- result[1]= endIndex;
- }
-
- private IRegion toImageRegion(IRegion originRegion, boolean exact) throws BadLocationException {
- if (originRegion.getLength() == 0) {
- int imageOffset= toImageOffset(originRegion.getOffset());
- return imageOffset == -1 ? null : new Region(imageOffset, 0);
- }
-
- int[] indices= (int[]) sfIndices.get();
- findFragmentIndices(originRegion, exact, indices);
- if (indices[0] >= 0) {
-
- Position[] fragments= getFragments();
-
- // translate start offset
- Fragment fragment= (Fragment) fragments[indices[0]];
- int originOffset= originRegion.getOffset();
- int relative= originOffset - fragment.getOffset();
- if (relative < 0) {
- Assert.isTrue(!exact);
- relative= 0;
- }
- int imageOffset= fragment.segment.getOffset() + relative;
-
- // translate end offset
- fragment= (Fragment) fragments[indices[1]];
- int exclusiveOriginEndOffset= originRegion.getOffset() + originRegion.getLength();
- relative= exclusiveOriginEndOffset - fragment.getOffset();
- if (relative > fragment.getLength()) {
- Assert.isTrue(!exact);
- int delta= relative - fragment.getLength();
- relative -= delta;
- }
- int exclusiveImageEndOffset= fragment.segment.getOffset() + relative;
-
- return new Region(imageOffset, exclusiveImageEndOffset - imageOffset);
- }
-
- return null;
- }
-
- 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);
- }
-
- private IRegion createOriginStartRegion(Fragment origin, int offsetShift) {
- 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(left.getOffset() + left.getLength(), right.getOffset() + right.getLength());
- if (exclusiveEndOffset < offset)
- return null;
- return new Region(offset, exclusiveEndOffset - offset);
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentInformationMapping#getCoverage()
- */
- public IRegion getCoverage() {
- Position[] fragments= getFragments();
- if (fragments != null && fragments.length > 0) {
- Position first=fragments[0];
- Position last= fragments[fragments.length -1];
- return new Region(first.offset, (last.offset + last.length) - first.offset);
- }
- return new Region(0, 0);
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentInformationMapping#toOriginOffset(int)
- */
- public int toOriginOffset(int imageOffset) throws BadLocationException {
- Segment segment= findSegment(imageOffset);
- int relative= imageOffset - segment.offset;
- return segment.fragment.offset + relative;
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentInformationMapping#toOriginRegion(org.eclipse.jface.text.IRegion)
- */
- public IRegion toOriginRegion(IRegion imageRegion) throws BadLocationException {
- int imageOffset= imageRegion.getOffset();
- int imageLength= imageRegion.getLength();
-
- if (imageLength == 0) {
- if (imageOffset == 0) {
- Position[] fragments= getFragments();
- if (fragments.length == 0 || (fragments.length == 1 && fragments[0].getOffset() == 0 && fragments[0].getLength() == 0))
- return new Region(0, fMasterDocument.getLength());
- }
- 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);
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentInformationMapping#toOriginLines(int)
- */
- 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 inclusiveOriginEndOffset= originRegion.getOffset() + originRegion.getLength() -1;
- int originEndLine= fMasterDocument.getLineOfOffset(inclusiveOriginEndOffset);
- return new Region(originStartLine, (originEndLine + 1) - originStartLine);
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentInformationMapping#toOriginLine(int)
- */
- public int toOriginLine(int imageLine) throws BadLocationException {
- IRegion lines= toOriginLines(imageLine);
- return (lines.getLength() > 1 ? -1 : lines.getOffset());
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentInformationMapping#toImageOffset(int)
- */
- public int toImageOffset(int originOffset) throws BadLocationException {
- Fragment fragment= findFragment(originOffset);
- if (fragment != null) {
- int relative= originOffset - fragment.offset;
- return fragment.segment.offset + relative;
- }
- return -1;
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentInformationMappingExtension#toExactImageRegion(org.eclipse.jface.text.IRegion)
- */
- public IRegion toExactImageRegion(IRegion originRegion) throws BadLocationException {
- return toImageRegion(originRegion, true);
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentInformationMapping#toImageRegion(org.eclipse.jface.text.IRegion)
- */
- public IRegion toImageRegion(IRegion originRegion) throws BadLocationException {
- return toImageRegion(originRegion, false);
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentInformationMapping#toImageLine(int)
- */
- public int toImageLine(int originLine) throws BadLocationException {
- IRegion originRegion= fMasterDocument.getLineInformation(originLine);
- IRegion imageRegion= toImageRegion(originRegion);
- if (imageRegion == null) {
- int imageOffset= toImageOffset(originRegion.getOffset());
- if (imageOffset > -1)
- imageRegion= new Region(imageOffset, 0);
- 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;
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentInformationMapping#toClosestImageLine(int)
- */
- 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() - (left.getOffset() + left.getLength());
- Fragment right= (Fragment) fragments[index];
- int rightDistance= right.getOffset() - (originLineRegion.getOffset() + originLineRegion.getLength());
-
- 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());
- } else if (index == fragments.length) {
- Fragment left= (Fragment) fragments[index - 1];
- originLine= fMasterDocument.getLineOfOffset(left.getOffset() + left.getLength());
- }
-
- 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= imageRegion.getOffset() + imageRegion.getLength();
- 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
- for (int i= 1; i < resultLength - 1; i++)
- result[i]= createOriginRegion((Segment) segments[firstIndex + i]);
- // last
- Segment last= (Segment) segments[lastIndex];
- int segmentEndOffset= last.getOffset() + last.getLength();
- IRegion lastRegion= createOriginEndRegion(last, segmentEndOffset - endOffset);
- if (resultLength > 1) {
- // first != last
- result[resultLength - 1]= lastRegion;
- } else {
- // merge first and last
- IRegion intersection= getIntersectingRegion(result[0], lastRegion);
- if (intersection == null)
- result= new IRegion[0];
- else
- result[0]= intersection;
- }
-
- return result;
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentInformationMappingExtension#getImageLength()
- */
- public int getImageLength() {
- Position[] segments= getSegments();
- int length= 0;
- for (int i= 0; i < segments.length; i++)
- 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 {
-
- if (originRegion.getLength() == 0) {
- int imageOffset= toImageOffset(originRegion.getOffset());
- return imageOffset > -1 ? new IRegion[] { new Region(imageOffset, 0) } : null;
- }
-
- int endOffset= originRegion.getOffset() + originRegion.getLength();
- Position[] fragments= getFragments();
- int firstIndex= findFragmentIndex(originRegion.getOffset(), RIGHT);
- int lastIndex= findFragmentIndex(endOffset - 1, LEFT);
-
- if (firstIndex == -1 || lastIndex == -1 || firstIndex > lastIndex)
- return null;
-
- int resultLength= lastIndex - firstIndex + 1;
- IRegion[] result= new IRegion[resultLength];
-
- // first
- result[0]= createImageStartRegion((Fragment) fragments[firstIndex], originRegion.getOffset() - fragments[firstIndex].getOffset());
- // middles
- for (int i= 1; i < resultLength - 1; i++)
- result[i]= createImageRegion((Fragment) fragments[firstIndex + i]);
- // last
- Fragment last= (Fragment) fragments[lastIndex];
- int fragmentEndOffset= last.getOffset() + last.getLength();
- IRegion lastRegion= createImageEndRegion(last, fragmentEndOffset - endOffset);
- if (resultLength > 1) {
- // first != last
- result[resultLength - 1]= lastRegion;
- } else {
- // merge first and last
- IRegion intersection= getIntersectingRegion(result[0], lastRegion);
- if (intersection == null)
- 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 || lastIndex == -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
- for (int i= 1; i < resultLength - 1; i++)
- result[i]= createOriginRegion((Fragment) fragments[firstIndex + i]);
- // last
- Fragment last= (Fragment) fragments[lastIndex];
- int fragmentEndOffset= last.getOffset() + last.getLength();
- IRegion lastRegion= createOriginEndRegion(last, fragmentEndOffset - endOffset);
- if (resultLength > 1) {
- // first != last
- result[resultLength - 1]= lastRegion;
- } else {
- // merge first and last
- IRegion intersection= getIntersectingRegion(result[0], lastRegion);
- if (intersection == null)
- return null;
- result[0]= intersection;
- }
-
- return result;
- }
-}
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
deleted file mode 100644
index 40219ce4cbd..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionTextStore.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.projection;
-
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextStore;
-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.
- */
- private static class ReusableRegion implements IRegion {
-
- private int fOffset;
- private int fLength;
-
- /*
- * @see org.eclipse.jface.text.IRegion#getLength()
- */
- public int getLength() {
- return fLength;
- }
-
- /*
- * @see org.eclipse.jface.text.IRegion#getOffset()
- */
- public int getOffset() {
- return fOffset;
- }
-
- /**
- * Updates this region.
- *
- * @param offset the new offset
- * @param length the new length
- */
- public void update(int offset, int length) {
- fOffset= offset;
- 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
- */
- public ProjectionTextStore(IDocument masterDocument, IMinimalMapping mapping) {
- fMasterDocument= masterDocument;
- fMapping= mapping;
- }
-
- private void internalError() {
- throw new IllegalStateException();
- }
-
- /*
- * @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) {
- internalError();
- }
- }
-
- /*
- * @see org.eclipse.jface.text.ITextStore#replace(int, int, java.lang.String)
- */
- public void replace(int offset, int length, String text) {
- fReusableRegion.update(offset, length);
- try {
- IRegion masterRegion= fMapping.toOriginRegion(fReusableRegion);
- fMasterDocument.replace(masterRegion.getOffset(), masterRegion.getLength(), text);
- } catch (BadLocationException e) {
- internalError();
- }
- }
-
- /*
- * @see org.eclipse.jface.text.ITextStore#getLength()
- */
- public int getLength() {
- return fMapping.getImageLength();
- }
-
- /*
- * @see org.eclipse.jface.text.ITextStore#get(int)
- */
- public char get(int offset) {
- try {
- int originOffset= fMapping.toOriginOffset(offset);
- return fMasterDocument.getChar(originOffset);
- } catch (BadLocationException e) {
- internalError();
- }
-
- // unreachable
- return (char) 0;
- }
-
- /*
- * @see ITextStore#get(int, int)
- */
- public String get(int offset, int length) {
- try {
- IRegion[] fragments= fMapping.toExactOriginRegions(new Region(offset, length));
- StringBuffer buffer= new StringBuffer();
- for (int i= 0; i < fragments.length; i++) {
- IRegion fragment= fragments[i];
- buffer.append(fMasterDocument.get(fragment.getOffset(), fragment.getLength()));
- }
- return buffer.toString();
- } 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
deleted file mode 100644
index 4915c32f69f..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/Segment.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.projection;
-
-
-import org.eclipse.jface.text.Position;
-
-
-/**
- * Internal class. Do not use. Only public for testing purposes.
- * <p>
- * 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 <code>true</code> if the stretching flag is set, <code>false</code> otherwise.
- * @return <code>true</code> if the stretching flag is set, <code>false</code> otherwise
- */
- public boolean isMarkedForStretch() {
- return isMarkedForStretch;
- }
-
- /**
- * Sets the shifting flag.
- */
- public void markForShift() {
- isMarkedForShift= true;
- }
-
- /**
- * Returns <code>true</code> if the shifting flag is set, <code>false</code> otherwise.
- * @return <code>true</code> if the shifting flag is set, <code>false</code> otherwise
- */
- public boolean isMarkedForShift() {
- return isMarkedForShift;
- }
-
- /**
- * Clears the shifting and the streching flag.
- */
- public void clearMark() {
- isMarkedForStretch= false;
- isMarkedForShift= false;
- }
-}
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
deleted file mode 100644
index f4c415b7ebc..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/SegmentUpdater.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.projection;
-
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.Position;
-
-
-/**
- * The position updater used to adapt the segments of a projection document to
- * changes of the master document. Depending on the flags set on a segment, a
- * 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;
-
- try {
-
- Position[] category= event.getDocument().getPositions(getCategory());
-
- fOffset= event.getOffset();
- fLength= event.getLength();
- fReplaceLength= (event.getText() == null ? 0 : event.getText().length());
- 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);
- myEnd= Math.max(myStart, myEnd);
- int yoursStart= fOffset;
-
- try {
-
- if (myEnd < yoursStart)
- return;
-
- if (segment.isMarkedForStretch) {
- Assert.isTrue(fIsProjectionChange);
- segment.isMarkedForShift= false;
- if (fNextSegment != null) {
- fNextSegment.isMarkedForShift= true;
- 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();
- }
- }
-}
diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/package.html b/org.eclipse.text/projection/org/eclipse/jface/text/projection/package.html
deleted file mode 100644
index 1d60a7a2a6b..00000000000
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/package.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
-<html><head>
- <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
- <meta content="IBM" name="Author">
- <meta content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]" name="GENERATOR"><title>projections</title></head>
-
-<body>
-<p>This package provides an implementation of projection documents. Projection
- is a specific master/slave mapping. Non-overlapping fragments if a master document
- form the segments of a slave document. The slave document is completely built
- out of segments, i.e. there are no gaps between two neighboring segments. The
- segments have exactly the same sequence in which they apprear as fragments in
- the master document.</p>
-<h3>Package Specification</h3>
-<p><tt>ProjectionDocument</tt> is custom
- <tt>IDocument</tt> implementation that
- uses a <tt>ProjectionTextStore. </tt>The
- content of the <tt>ProjectionDocument</tt>
- is defined by the <tt>ProjectionMapping.
- </tt>The<tt> ProjectionDocumentManager</tt>
- manages the life cycle of <tt>ProjectionDocuments</tt>
- and their relation to their master documents.</p>
-</body></html> \ No newline at end of file

Back to the top