org.eclipse.text_3.5.101.v20110928-1504

16:48:00.458 INFO  jd.cli.Main - Decompiling org.eclipse.text_3.5.101.v20110928-1504.jar
package org.eclipse.jface.text;

import org.eclipse.core.runtime.ISafeRunnable;

class AbstractDocument$1
  implements ISafeRunnable
{
  private final Exception val$ex;
  
  AbstractDocument$1(Exception paramException)
  {
    val$ex = paramException;
  }
  
  public void run()
    throws Exception
  {
    throw val$ex;
  }
  
  public void handleException(Throwable exception) {}
}

/* Location:
 * Qualified Name:     org.eclipse.jface.text.AbstractDocument.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.text;

class AbstractDocument$RegisteredReplace
{
  IDocumentListener fOwner;
  IDocumentExtension.IReplace fReplace;
  
  AbstractDocument$RegisteredReplace(IDocumentListener owner, IDocumentExtension.IReplace replace)
  {
    fOwner = owner;
    fReplace = replace;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.text.AbstractDocument.RegisteredReplace
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.text;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.PatternSyntaxException;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.SafeRunner;

public abstract class AbstractDocument
  implements IDocument, IDocumentExtension, IDocumentExtension2, IDocumentExtension3, IDocumentExtension4, IRepairableDocument, IRepairableDocumentExtension
{
  private static final boolean DEBUG = false;
  private ITextStore fStore;
  private ILineTracker fTracker;
  private ListenerList fDocumentListeners;
  private ListenerList fPrenotifiedDocumentListeners;
  private ListenerList fDocumentPartitioningListeners;
  private Map fPositions;
  private Map fEndPositions;
  private List fPositionUpdaters;
  private List fPostNotificationChanges;
  
  private static class RegisteredReplace
  {
    IDocumentListener fOwner;
    IDocumentExtension.IReplace fReplace;
    
    RegisteredReplace(IDocumentListener owner, IDocumentExtension.IReplace replace)
    {
      fOwner = owner;
      fReplace = replace;
    }
  }
  
  private int fReentranceCount = 0;
  private int fStoppedCount = 0;
  private boolean fAcceptPostNotificationReplaces = true;
  private int fStoppedListenerNotification = 0;
  private DocumentEvent fDeferredDocumentEvent;
  private Map fDocumentPartitioners;
  private DocumentPartitioningChangedEvent fDocumentPartitioningChangedEvent;
  private FindReplaceDocumentAdapter fFindReplaceDocumentAdapter;
  private DocumentRewriteSession fDocumentRewriteSession;
  private List fDocumentRewriteSessionListeners;
  private long fModificationStamp = -1L;
  private long fNextModificationStamp = -1L;
  private String fInitialLineDelimiter;
  
  protected AbstractDocument()
  {
    fModificationStamp = getNextModificationStamp();
  }
  
  protected ITextStore getStore()
  {
    Assert.isNotNull(fStore);
    return fStore;
  }
  
  protected ILineTracker getTracker()
  {
    Assert.isNotNull(fTracker);
    return fTracker;
  }
  
  protected List getDocumentListeners()
  {
    return Arrays.asList(fDocumentListeners.getListeners());
  }
  
  protected List getDocumentPartitioningListeners()
  {
    return Arrays.asList(fDocumentPartitioningListeners.getListeners());
  }
  
  protected Map getDocumentManagedPositions()
  {
    return fPositions;
  }
  
  public IDocumentPartitioner getDocumentPartitioner()
  {
    return getDocumentPartitioner("__dftl_partitioning");
  }
  
  protected void setTextStore(ITextStore store)
  {
    fStore = store;
  }
  
  protected void setLineTracker(ILineTracker tracker)
  {
    fTracker = tracker;
  }
  
  public void setDocumentPartitioner(IDocumentPartitioner partitioner)
  {
    setDocumentPartitioner("__dftl_partitioning", partitioner);
  }
  
  protected void completeInitialization()
  {
    fPositions = new HashMap();
    fEndPositions = new HashMap();
    fPositionUpdaters = new ArrayList();
    fDocumentListeners = new ListenerList(1);
    fPrenotifiedDocumentListeners = new ListenerList(1);
    fDocumentPartitioningListeners = new ListenerList(1);
    fDocumentRewriteSessionListeners = new ArrayList();
    
    addPositionCategory("__dflt_position_category");
    addPositionUpdater(new DefaultPositionUpdater("__dflt_position_category"));
  }
  
  public void addDocumentListener(IDocumentListener listener)
  {
    Assert.isNotNull(listener);
    fDocumentListeners.add(listener);
  }
  
  public void removeDocumentListener(IDocumentListener listener)
  {
    Assert.isNotNull(listener);
    fDocumentListeners.remove(listener);
  }
  
  public void addPrenotifiedDocumentListener(IDocumentListener listener)
  {
    Assert.isNotNull(listener);
    fPrenotifiedDocumentListeners.add(listener);
  }
  
  public void removePrenotifiedDocumentListener(IDocumentListener listener)
  {
    Assert.isNotNull(listener);
    fPrenotifiedDocumentListeners.remove(listener);
  }
  
  public void addDocumentPartitioningListener(IDocumentPartitioningListener listener)
  {
    Assert.isNotNull(listener);
    fDocumentPartitioningListeners.add(listener);
  }
  
  public void removeDocumentPartitioningListener(IDocumentPartitioningListener listener)
  {
    Assert.isNotNull(listener);
    fDocumentPartitioningListeners.remove(listener);
  }
  
  public void addPosition(String category, Position position)
    throws BadLocationException, BadPositionCategoryException
  {
    if ((offset < 0) || (length < 0) || (offset + length > getLength())) {
      throw new BadLocationException();
    }
    if (category == null) {
      throw new BadPositionCategoryException();
    }
    List list = (List)fPositions.get(category);
    if (list == null) {
      throw new BadPositionCategoryException();
    }
    list.add(computeIndexInPositionList(list, offset), position);
    
    List endPositions = (List)fEndPositions.get(category);
    if (endPositions == null) {
      throw new BadPositionCategoryException();
    }
    endPositions.add(computeIndexInPositionList(endPositions, offset + length - 1, false), position);
  }
  
  public void addPosition(Position position)
    throws BadLocationException
  {
    try
    {
      addPosition("__dflt_position_category", position);
    }
    catch (BadPositionCategoryException localBadPositionCategoryException) {}
  }
  
  public void addPositionCategory(String category)
  {
    if (category == null) {
      return;
    }
    if (!containsPositionCategory(category))
    {
      fPositions.put(category, new ArrayList());
      fEndPositions.put(category, new ArrayList());
    }
  }
  
  public void addPositionUpdater(IPositionUpdater updater)
  {
    insertPositionUpdater(updater, fPositionUpdaters.size());
  }
  
  public boolean containsPosition(String category, int offset, int length)
  {
    if (category == null) {
      return false;
    }
    List list = (List)fPositions.get(category);
    if (list == null) {
      return false;
    }
    int size = list.size();
    if (size == 0) {
      return false;
    }
    int index = computeIndexInPositionList(list, offset);
    if (index < size)
    {
      Position p = (Position)list.get(index);
      while ((p != null) && (offset == offset))
      {
        if (length == length) {
          return true;
        }
        index++;
        p = index < size ? (Position)list.get(index) : null;
      }
    }
    return false;
  }
  
  public boolean containsPositionCategory(String category)
  {
    if (category != null) {
      return fPositions.containsKey(category);
    }
    return false;
  }
  
  /**
   * @deprecated
   */
  protected int computeIndexInPositionList(List positions, int offset)
  {
    return computeIndexInPositionList(positions, offset, true);
  }
  
  protected int computeIndexInPositionList(List positions, int offset, boolean orderedByOffset)
  {
    if (positions.size() == 0) {
      return 0;
    }
    int left = 0;
    int right = positions.size() - 1;
    int mid = 0;
    Position p = null;
    while (left < right)
    {
      mid = (left + right) / 2;
      
      p = (Position)positions.get(mid);
      int pOffset = getOffset(orderedByOffset, p);
      if (offset < pOffset)
      {
        if (left == mid) {
          right = left;
        } else {
          right = mid - 1;
        }
      }
      else if (offset > pOffset)
      {
        if (right == mid) {
          left = right;
        } else {
          left = mid + 1;
        }
      }
      else if (offset == pOffset) {
        left = right = mid;
      }
    }
    int pos = left;
    p = (Position)positions.get(pos);
    int pPosition = getOffset(orderedByOffset, p);
    if (offset > pPosition)
    {
      pos++;
    }
    else
    {
      do
      {
        pos--;
        if (pos < 0) {
          break;
        }
        p = (Position)positions.get(pos);
        pPosition = getOffset(orderedByOffset, p);
      } while (offset == pPosition);
      pos++;
    }
    Assert.isTrue((pos >= 0) && (pos <= positions.size()));
    
    return pos;
  }
  
  private int getOffset(boolean orderedByOffset, Position position)
  {
    if ((orderedByOffset) || (position.getLength() == 0)) {
      return position.getOffset();
    }
    return position.getOffset() + position.getLength() - 1;
  }
  
  public int computeIndexInCategory(String category, int offset)
    throws BadLocationException, BadPositionCategoryException
  {
    if ((offset < 0) || (offset > getLength())) {
      throw new BadLocationException();
    }
    List c = (List)fPositions.get(category);
    if (c == null) {
      throw new BadPositionCategoryException();
    }
    return computeIndexInPositionList(c, offset);
  }
  
  /**
   * @deprecated
   */
  protected void fireDocumentPartitioningChanged()
  {
    if (fDocumentPartitioningListeners == null) {
      return;
    }
    Object[] listeners = fDocumentPartitioningListeners.getListeners();
    for (int i = 0; i < listeners.length; i++) {
      ((IDocumentPartitioningListener)listeners[i]).documentPartitioningChanged(this);
    }
  }
  
  /**
   * @deprecated
   */
  protected void fireDocumentPartitioningChanged(IRegion region)
  {
    if (fDocumentPartitioningListeners == null) {
      return;
    }
    Object[] listeners = fDocumentPartitioningListeners.getListeners();
    for (int i = 0; i < listeners.length; i++)
    {
      IDocumentPartitioningListener l = (IDocumentPartitioningListener)listeners[i];
      try
      {
        if ((l instanceof IDocumentPartitioningListenerExtension)) {
          ((IDocumentPartitioningListenerExtension)l).documentPartitioningChanged(this, region);
        } else {
          l.documentPartitioningChanged(this);
        }
      }
      catch (Exception ex)
      {
        log(ex);
      }
    }
  }
  
  protected void fireDocumentPartitioningChanged(DocumentPartitioningChangedEvent event)
  {
    if (fDocumentPartitioningListeners == null) {
      return;
    }
    Object[] listeners = fDocumentPartitioningListeners.getListeners();
    for (int i = 0; i < listeners.length; i++)
    {
      IDocumentPartitioningListener l = (IDocumentPartitioningListener)listeners[i];
      try
      {
        if ((l instanceof IDocumentPartitioningListenerExtension2))
        {
          IDocumentPartitioningListenerExtension2 extension2 = (IDocumentPartitioningListenerExtension2)l;
          extension2.documentPartitioningChanged(event);
        }
        else if ((l instanceof IDocumentPartitioningListenerExtension))
        {
          IDocumentPartitioningListenerExtension extension = (IDocumentPartitioningListenerExtension)l;
          extension.documentPartitioningChanged(this, event.getCoverage());
        }
        else
        {
          l.documentPartitioningChanged(this);
        }
      }
      catch (Exception ex)
      {
        log(ex);
      }
    }
  }
  
  protected void fireDocumentAboutToBeChanged(DocumentEvent event)
  {
    if (fReentranceCount == 0) {
      flushPostNotificationChanges();
    }
    if (fDocumentPartitioners != null)
    {
      Iterator e = fDocumentPartitioners.values().iterator();
      while (e.hasNext())
      {
        IDocumentPartitioner p = (IDocumentPartitioner)e.next();
        if ((p instanceof IDocumentPartitionerExtension3))
        {
          IDocumentPartitionerExtension3 extension = (IDocumentPartitionerExtension3)p;
          if (extension.getActiveRewriteSession() != null) {}
        }
        else
        {
          try
          {
            p.documentAboutToBeChanged(event);
          }
          catch (Exception ex)
          {
            log(ex);
          }
        }
      }
    }
    Object[] listeners = fPrenotifiedDocumentListeners.getListeners();
    for (int i = 0; i < listeners.length; i++) {
      try
      {
        ((IDocumentListener)listeners[i]).documentAboutToBeChanged(event);
      }
      catch (Exception ex)
      {
        log(ex);
      }
    }
    listeners = fDocumentListeners.getListeners();
    for (int i = 0; i < listeners.length; i++) {
      try
      {
        ((IDocumentListener)listeners[i]).documentAboutToBeChanged(event);
      }
      catch (Exception ex)
      {
        log(ex);
      }
    }
  }
  
  protected void updateDocumentStructures(DocumentEvent event)
  {
    if (fDocumentPartitioners != null)
    {
      fDocumentPartitioningChangedEvent = new DocumentPartitioningChangedEvent(this);
      Iterator e = fDocumentPartitioners.keySet().iterator();
      while (e.hasNext())
      {
        String partitioning = (String)e.next();
        IDocumentPartitioner partitioner = (IDocumentPartitioner)fDocumentPartitioners.get(partitioning);
        if ((partitioner instanceof IDocumentPartitionerExtension3))
        {
          IDocumentPartitionerExtension3 extension = (IDocumentPartitionerExtension3)partitioner;
          if (extension.getActiveRewriteSession() != null) {}
        }
        else if ((partitioner instanceof IDocumentPartitionerExtension))
        {
          IDocumentPartitionerExtension extension = (IDocumentPartitionerExtension)partitioner;
          IRegion r = extension.documentChanged2(event);
          if (r != null) {
            fDocumentPartitioningChangedEvent.setPartitionChange(partitioning, r.getOffset(), r.getLength());
          }
        }
        else if (partitioner.documentChanged(event))
        {
          fDocumentPartitioningChangedEvent.setPartitionChange(partitioning, 0, event.getDocument().getLength());
        }
      }
    }
    if (fPositions.size() > 0) {
      updatePositions(event);
    }
  }
  
  protected void doFireDocumentChanged(DocumentEvent event)
  {
    boolean changed = (fDocumentPartitioningChangedEvent != null) && (!fDocumentPartitioningChangedEvent.isEmpty());
    IRegion change = changed ? fDocumentPartitioningChangedEvent.getCoverage() : null;
    doFireDocumentChanged(event, changed, change);
  }
  
  /**
   * @deprecated
   */
  protected void doFireDocumentChanged(DocumentEvent event, boolean firePartitionChange, IRegion partitionChange)
  {
    doFireDocumentChanged2(event);
  }
  
  protected void doFireDocumentChanged2(DocumentEvent event)
  {
    DocumentPartitioningChangedEvent p = fDocumentPartitioningChangedEvent;
    fDocumentPartitioningChangedEvent = null;
    if ((p != null) && (!p.isEmpty())) {
      fireDocumentPartitioningChanged(p);
    }
    Object[] listeners = fPrenotifiedDocumentListeners.getListeners();
    for (int i = 0; i < listeners.length; i++) {
      try
      {
        ((IDocumentListener)listeners[i]).documentChanged(event);
      }
      catch (Exception ex)
      {
        log(ex);
      }
    }
    listeners = fDocumentListeners.getListeners();
    for (i = 0; i < listeners.length; i++) {
      try
      {
        ((IDocumentListener)listeners[i]).documentChanged(event);
      }
      catch (Exception ex)
      {
        log(ex);
      }
    }
    fReentranceCount += 1;
    try
    {
      if (fReentranceCount == 1) {
        executePostNotificationChanges();
      }
    }
    finally
    {
      fReentranceCount -= 1;
    }
  }
  
  protected void fireDocumentChanged(DocumentEvent event)
  {
    updateDocumentStructures(event);
    if (fStoppedListenerNotification == 0) {
      doFireDocumentChanged(event);
    } else {
      fDeferredDocumentEvent = event;
    }
  }
  
  public char getChar(int pos)
    throws BadLocationException
  {
    if ((pos < 0) || (pos >= getLength())) {
      throw new BadLocationException();
    }
    return getStore().get(pos);
  }
  
  public String getContentType(int offset)
    throws BadLocationException
  {
    String contentType = null;
    try
    {
      contentType = getContentType("__dftl_partitioning", offset, false);
      Assert.isNotNull(contentType);
    }
    catch (BadPartitioningException localBadPartitioningException)
    {
      Assert.isTrue(false);
    }
    return contentType;
  }
  
  public String[] getLegalContentTypes()
  {
    String[] contentTypes = (String[])null;
    try
    {
      contentTypes = getLegalContentTypes("__dftl_partitioning");
      Assert.isNotNull(contentTypes);
    }
    catch (BadPartitioningException localBadPartitioningException)
    {
      Assert.isTrue(false);
    }
    return contentTypes;
  }
  
  public int getLength()
  {
    return getStore().getLength();
  }
  
  public String getLineDelimiter(int line)
    throws BadLocationException
  {
    return getTracker().getLineDelimiter(line);
  }
  
  public String[] getLegalLineDelimiters()
  {
    return getTracker().getLegalLineDelimiters();
  }
  
  public String getDefaultLineDelimiter()
  {
    String lineDelimiter = null;
    try
    {
      lineDelimiter = getLineDelimiter(0);
    }
    catch (BadLocationException localBadLocationException) {}
    if (lineDelimiter != null) {
      return lineDelimiter;
    }
    if (fInitialLineDelimiter != null) {
      return fInitialLineDelimiter;
    }
    String sysLineDelimiter = System.getProperty("line.separator");
    String[] delimiters = getLegalLineDelimiters();
    Assert.isTrue(delimiters.length > 0);
    for (int i = 0; i < delimiters.length; i++) {
      if (delimiters[i].equals(sysLineDelimiter))
      {
        lineDelimiter = sysLineDelimiter;
        break;
      }
    }
    if (lineDelimiter == null) {
      lineDelimiter = delimiters[0];
    }
    return lineDelimiter;
  }
  
  public void setInitialLineDelimiter(String lineDelimiter)
  {
    Assert.isNotNull(lineDelimiter);
    fInitialLineDelimiter = lineDelimiter;
  }
  
  public int getLineLength(int line)
    throws BadLocationException
  {
    return getTracker().getLineLength(line);
  }
  
  public int getLineOfOffset(int pos)
    throws BadLocationException
  {
    return getTracker().getLineNumberOfOffset(pos);
  }
  
  public int getLineOffset(int line)
    throws BadLocationException
  {
    return getTracker().getLineOffset(line);
  }
  
  public IRegion getLineInformation(int line)
    throws BadLocationException
  {
    return getTracker().getLineInformation(line);
  }
  
  public IRegion getLineInformationOfOffset(int offset)
    throws BadLocationException
  {
    return getTracker().getLineInformationOfOffset(offset);
  }
  
  public int getNumberOfLines()
  {
    return getTracker().getNumberOfLines();
  }
  
  public int getNumberOfLines(int offset, int length)
    throws BadLocationException
  {
    return getTracker().getNumberOfLines(offset, length);
  }
  
  public int computeNumberOfLines(String text)
  {
    return getTracker().computeNumberOfLines(text);
  }
  
  public ITypedRegion getPartition(int offset)
    throws BadLocationException
  {
    ITypedRegion partition = null;
    try
    {
      partition = getPartition("__dftl_partitioning", offset, false);
      Assert.isNotNull(partition);
    }
    catch (BadPartitioningException localBadPartitioningException)
    {
      Assert.isTrue(false);
    }
    return partition;
  }
  
  public ITypedRegion[] computePartitioning(int offset, int length)
    throws BadLocationException
  {
    ITypedRegion[] partitioning = (ITypedRegion[])null;
    try
    {
      partitioning = computePartitioning("__dftl_partitioning", offset, length, false);
      Assert.isNotNull(partitioning);
    }
    catch (BadPartitioningException localBadPartitioningException)
    {
      Assert.isTrue(false);
    }
    return partitioning;
  }
  
  public Position[] getPositions(String category)
    throws BadPositionCategoryException
  {
    if (category == null) {
      throw new BadPositionCategoryException();
    }
    List c = (List)fPositions.get(category);
    if (c == null) {
      throw new BadPositionCategoryException();
    }
    Position[] positions = new Position[c.size()];
    c.toArray(positions);
    return positions;
  }
  
  public String[] getPositionCategories()
  {
    String[] categories = new String[fPositions.size()];
    Iterator keys = fPositions.keySet().iterator();
    for (int i = 0; i < categories.length; i++) {
      categories[i] = ((String)keys.next());
    }
    return categories;
  }
  
  public IPositionUpdater[] getPositionUpdaters()
  {
    IPositionUpdater[] updaters = new IPositionUpdater[fPositionUpdaters.size()];
    fPositionUpdaters.toArray(updaters);
    return updaters;
  }
  
  public String get()
  {
    return getStore().get(0, getLength());
  }
  
  public String get(int pos, int length)
    throws BadLocationException
  {
    int myLength = getLength();
    if ((pos < 0) || (length < 0) || (pos + length > myLength)) {
      throw new BadLocationException();
    }
    return getStore().get(pos, length);
  }
  
  public void insertPositionUpdater(IPositionUpdater updater, int index)
  {
    for (int i = fPositionUpdaters.size() - 1; i >= 0; i--) {
      if (fPositionUpdaters.get(i) == updater) {
        return;
      }
    }
    if (index == fPositionUpdaters.size()) {
      fPositionUpdaters.add(updater);
    } else {
      fPositionUpdaters.add(index, updater);
    }
  }
  
  public void removePosition(String category, Position position)
    throws BadPositionCategoryException
  {
    if (position == null) {
      return;
    }
    if (category == null) {
      throw new BadPositionCategoryException();
    }
    List c = (List)fPositions.get(category);
    if (c == null) {
      throw new BadPositionCategoryException();
    }
    removeFromPositionsList(c, position, true);
    
    List endPositions = (List)fEndPositions.get(category);
    if (endPositions == null) {
      throw new BadPositionCategoryException();
    }
    removeFromPositionsList(endPositions, position, false);
  }
  
  private void removeFromPositionsList(List positions, Position position, boolean orderedByOffset)
  {
    int size = positions.size();
    
    int index = computeIndexInPositionList(positions, orderedByOffset ? offset : offset + length - 1, orderedByOffset);
    if ((index < size) && (positions.get(index) == position))
    {
      positions.remove(index);
      return;
    }
    int back = index - 1;
    int forth = index + 1;
    while ((back >= 0) || (forth < size))
    {
      if (back >= 0)
      {
        if (position == positions.get(back))
        {
          positions.remove(back);
          return;
        }
        back--;
      }
      if (forth < size)
      {
        if (position == positions.get(forth))
        {
          positions.remove(forth);
          return;
        }
        forth++;
      }
    }
  }
  
  public void removePosition(Position position)
  {
    try
    {
      removePosition("__dflt_position_category", position);
    }
    catch (BadPositionCategoryException localBadPositionCategoryException) {}
  }
  
  public void removePositionCategory(String category)
    throws BadPositionCategoryException
  {
    if (category == null) {
      return;
    }
    if (!containsPositionCategory(category)) {
      throw new BadPositionCategoryException();
    }
    fPositions.remove(category);
    fEndPositions.remove(category);
  }
  
  public void removePositionUpdater(IPositionUpdater updater)
  {
    for (int i = fPositionUpdaters.size() - 1; i >= 0; i--) {
      if (fPositionUpdaters.get(i) == updater)
      {
        fPositionUpdaters.remove(i);
        return;
      }
    }
  }
  
  private long getNextModificationStamp()
  {
    if ((fNextModificationStamp == Long.MAX_VALUE) || (fNextModificationStamp == -1L)) {
      fNextModificationStamp = 0L;
    } else {
      fNextModificationStamp += 1L;
    }
    return fNextModificationStamp;
  }
  
  public long getModificationStamp()
  {
    return fModificationStamp;
  }
  
  public void replace(int pos, int length, String text, long modificationStamp)
    throws BadLocationException
  {
    if ((pos < 0) || (length < 0) || (pos + length > getLength())) {
      throw new BadLocationException();
    }
    DocumentEvent e = new DocumentEvent(this, pos, length, text);
    fireDocumentAboutToBeChanged(e);
    
    getStore().replace(pos, length, text);
    getTracker().replace(pos, length, text);
    
    fModificationStamp = modificationStamp;
    fNextModificationStamp = Math.max(fModificationStamp, fNextModificationStamp);
    fModificationStamp = fModificationStamp;
    
    fireDocumentChanged(e);
  }
  
  public boolean isLineInformationRepairNeeded(int offset, int length, String text)
    throws BadLocationException
  {
    return false;
  }
  
  public void replace(int pos, int length, String text)
    throws BadLocationException
  {
    if ((length == 0) && ((text == null) || (text.length() == 0))) {
      replace(pos, length, text, getModificationStamp());
    } else {
      replace(pos, length, text, getNextModificationStamp());
    }
  }
  
  public void set(String text)
  {
    set(text, getNextModificationStamp());
  }
  
  public void set(String text, long modificationStamp)
  {
    int length = getStore().getLength();
    
    DocumentEvent e = new DocumentEvent(this, 0, length, text);
    fireDocumentAboutToBeChanged(e);
    
    getStore().set(text);
    getTracker().set(text);
    
    fModificationStamp = modificationStamp;
    fNextModificationStamp = Math.max(fModificationStamp, fNextModificationStamp);
    fModificationStamp = fModificationStamp;
    
    fireDocumentChanged(e);
  }
  
  protected void updatePositions(DocumentEvent event)
  {
    List list = new ArrayList(fPositionUpdaters);
    Iterator e = list.iterator();
    while (e.hasNext())
    {
      IPositionUpdater u = (IPositionUpdater)e.next();
      u.update(event);
    }
  }
  
  /**
   * @deprecated
   */
  public int search(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord)
    throws BadLocationException
  {
    try
    {
      IRegion region = getFindReplaceDocumentAdapter().find(startPosition, findString, forwardSearch, caseSensitive, wholeWord, false);
      return region == null ? -1 : region.getOffset();
    }
    catch (IllegalStateException localIllegalStateException)
    {
      return -1;
    }
    catch (PatternSyntaxException localPatternSyntaxException) {}
    return -1;
  }
  
  private FindReplaceDocumentAdapter getFindReplaceDocumentAdapter()
  {
    if (fFindReplaceDocumentAdapter == null) {
      fFindReplaceDocumentAdapter = new FindReplaceDocumentAdapter(this);
    }
    return fFindReplaceDocumentAdapter;
  }
  
  private void flushPostNotificationChanges()
  {
    if (fPostNotificationChanges != null) {
      fPostNotificationChanges.clear();
    }
  }
  
  private void executePostNotificationChanges()
  {
    if (fStoppedCount > 0) {
      return;
    }
    Iterator e;
    for (; fPostNotificationChanges != null; e.hasNext())
    {
      List changes = fPostNotificationChanges;
      fPostNotificationChanges = null;
      
      e = changes.iterator();
      continue;
      RegisteredReplace replace = (RegisteredReplace)e.next();
      fReplace.perform(this, fOwner);
    }
  }
  
  public void acceptPostNotificationReplaces()
  {
    fAcceptPostNotificationReplaces = true;
  }
  
  public void ignorePostNotificationReplaces()
  {
    fAcceptPostNotificationReplaces = false;
  }
  
  public void registerPostNotificationReplace(IDocumentListener owner, IDocumentExtension.IReplace replace)
  {
    if (fAcceptPostNotificationReplaces)
    {
      if (fPostNotificationChanges == null) {
        fPostNotificationChanges = new ArrayList(1);
      }
      fPostNotificationChanges.add(new RegisteredReplace(owner, replace));
    }
  }
  
  public void stopPostNotificationProcessing()
  {
    fStoppedCount += 1;
  }
  
  public void resumePostNotificationProcessing()
  {
    fStoppedCount -= 1;
    if ((fStoppedCount == 0) && (fReentranceCount == 0)) {
      executePostNotificationChanges();
    }
  }
  
  /**
   * @deprecated
   */
  public void startSequentialRewrite(boolean normalized) {}
  
  /**
   * @deprecated
   */
  public void stopSequentialRewrite() {}
  
  public void resumeListenerNotification()
  {
    fStoppedListenerNotification -= 1;
    if (fStoppedListenerNotification == 0) {
      resumeDocumentListenerNotification();
    }
  }
  
  public void stopListenerNotification()
  {
    fStoppedListenerNotification += 1;
  }
  
  private void resumeDocumentListenerNotification()
  {
    if (fDeferredDocumentEvent != null)
    {
      DocumentEvent event = fDeferredDocumentEvent;
      fDeferredDocumentEvent = null;
      doFireDocumentChanged(event);
    }
  }
  
  public ITypedRegion[] computePartitioning(String partitioning, int offset, int length, boolean includeZeroLengthPartitions)
    throws BadLocationException, BadPartitioningException
  {
    if ((offset < 0) || (length < 0) || (offset + length > getLength())) {
      throw new BadLocationException();
    }
    IDocumentPartitioner partitioner = getDocumentPartitioner(partitioning);
    if ((partitioner instanceof IDocumentPartitionerExtension2))
    {
      checkStateOfPartitioner(partitioner, partitioning);
      return ((IDocumentPartitionerExtension2)partitioner).computePartitioning(offset, length, includeZeroLengthPartitions);
    }
    if (partitioner != null)
    {
      checkStateOfPartitioner(partitioner, partitioning);
      return partitioner.computePartitioning(offset, length);
    }
    if ("__dftl_partitioning".equals(partitioning)) {
      return new TypedRegion[] { new TypedRegion(offset, length, "__dftl_partition_content_type") };
    }
    throw new BadPartitioningException();
  }
  
  public String getContentType(String partitioning, int offset, boolean preferOpenPartitions)
    throws BadLocationException, BadPartitioningException
  {
    if ((offset < 0) || (offset > getLength())) {
      throw new BadLocationException();
    }
    IDocumentPartitioner partitioner = getDocumentPartitioner(partitioning);
    if ((partitioner instanceof IDocumentPartitionerExtension2))
    {
      checkStateOfPartitioner(partitioner, partitioning);
      return ((IDocumentPartitionerExtension2)partitioner).getContentType(offset, preferOpenPartitions);
    }
    if (partitioner != null)
    {
      checkStateOfPartitioner(partitioner, partitioning);
      return partitioner.getContentType(offset);
    }
    if ("__dftl_partitioning".equals(partitioning)) {
      return "__dftl_partition_content_type";
    }
    throw new BadPartitioningException();
  }
  
  public IDocumentPartitioner getDocumentPartitioner(String partitioning)
  {
    return fDocumentPartitioners != null ? (IDocumentPartitioner)fDocumentPartitioners.get(partitioning) : null;
  }
  
  public String[] getLegalContentTypes(String partitioning)
    throws BadPartitioningException
  {
    IDocumentPartitioner partitioner = getDocumentPartitioner(partitioning);
    if (partitioner != null) {
      return partitioner.getLegalContentTypes();
    }
    if ("__dftl_partitioning".equals(partitioning)) {
      return new String[] { "__dftl_partition_content_type" };
    }
    throw new BadPartitioningException();
  }
  
  public ITypedRegion getPartition(String partitioning, int offset, boolean preferOpenPartitions)
    throws BadLocationException, BadPartitioningException
  {
    if ((offset < 0) || (offset > getLength())) {
      throw new BadLocationException();
    }
    IDocumentPartitioner partitioner = getDocumentPartitioner(partitioning);
    if ((partitioner instanceof IDocumentPartitionerExtension2))
    {
      checkStateOfPartitioner(partitioner, partitioning);
      return ((IDocumentPartitionerExtension2)partitioner).getPartition(offset, preferOpenPartitions);
    }
    if (partitioner != null)
    {
      checkStateOfPartitioner(partitioner, partitioning);
      return partitioner.getPartition(offset);
    }
    if ("__dftl_partitioning".equals(partitioning)) {
      return new TypedRegion(0, getLength(), "__dftl_partition_content_type");
    }
    throw new BadPartitioningException();
  }
  
  public String[] getPartitionings()
  {
    if (fDocumentPartitioners == null) {
      return new String[0];
    }
    String[] partitionings = new String[fDocumentPartitioners.size()];
    fDocumentPartitioners.keySet().toArray(partitionings);
    return partitionings;
  }
  
  public void setDocumentPartitioner(String partitioning, IDocumentPartitioner partitioner)
  {
    if (partitioner == null)
    {
      if (fDocumentPartitioners != null)
      {
        fDocumentPartitioners.remove(partitioning);
        if (fDocumentPartitioners.size() == 0) {
          fDocumentPartitioners = null;
        }
      }
    }
    else
    {
      if (fDocumentPartitioners == null) {
        fDocumentPartitioners = new HashMap();
      }
      fDocumentPartitioners.put(partitioning, partitioner);
    }
    DocumentPartitioningChangedEvent event = new DocumentPartitioningChangedEvent(this);
    event.setPartitionChange(partitioning, 0, getLength());
    fireDocumentPartitioningChanged(event);
  }
  
  public void repairLineInformation()
  {
    getTracker().set(get());
  }
  
  protected void fireRewriteSessionChanged(DocumentRewriteSessionEvent event)
  {
    if (fDocumentRewriteSessionListeners.size() > 0)
    {
      List list = new ArrayList(fDocumentRewriteSessionListeners);
      Iterator e = list.iterator();
      while (e.hasNext()) {
        try
        {
          IDocumentRewriteSessionListener l = (IDocumentRewriteSessionListener)e.next();
          l.documentRewriteSessionChanged(event);
        }
        catch (Exception ex)
        {
          log(ex);
        }
      }
    }
  }
  
  public final DocumentRewriteSession getActiveRewriteSession()
  {
    return fDocumentRewriteSession;
  }
  
  public DocumentRewriteSession startRewriteSession(DocumentRewriteSessionType sessionType)
  {
    if (getActiveRewriteSession() != null) {
      throw new IllegalStateException();
    }
    fDocumentRewriteSession = new DocumentRewriteSession(sessionType);
    
    fireRewriteSessionChanged(new DocumentRewriteSessionEvent(this, fDocumentRewriteSession, DocumentRewriteSessionEvent.SESSION_START));
    
    startRewriteSessionOnPartitioners(fDocumentRewriteSession);
    
    ILineTracker tracker = getTracker();
    if ((tracker instanceof ILineTrackerExtension))
    {
      ILineTrackerExtension extension = (ILineTrackerExtension)tracker;
      extension.startRewriteSession(fDocumentRewriteSession);
    }
    if (DocumentRewriteSessionType.SEQUENTIAL == sessionType) {
      startSequentialRewrite(false);
    } else if (DocumentRewriteSessionType.STRICTLY_SEQUENTIAL == sessionType) {
      startSequentialRewrite(true);
    }
    return fDocumentRewriteSession;
  }
  
  protected final void startRewriteSessionOnPartitioners(DocumentRewriteSession session)
  {
    if (fDocumentPartitioners != null)
    {
      Iterator e = fDocumentPartitioners.values().iterator();
      while (e.hasNext())
      {
        Object partitioner = e.next();
        if ((partitioner instanceof IDocumentPartitionerExtension3))
        {
          IDocumentPartitionerExtension3 extension = (IDocumentPartitionerExtension3)partitioner;
          extension.startRewriteSession(session);
        }
      }
    }
  }
  
  public void stopRewriteSession(DocumentRewriteSession session)
  {
    if (fDocumentRewriteSession == session)
    {
      DocumentRewriteSessionType sessionType = session.getSessionType();
      if ((DocumentRewriteSessionType.SEQUENTIAL == sessionType) || (DocumentRewriteSessionType.STRICTLY_SEQUENTIAL == sessionType)) {
        stopSequentialRewrite();
      }
      ILineTracker tracker = getTracker();
      if ((tracker instanceof ILineTrackerExtension))
      {
        ILineTrackerExtension extension = (ILineTrackerExtension)tracker;
        extension.stopRewriteSession(session, get());
      }
      stopRewriteSessionOnPartitioners(fDocumentRewriteSession);
      
      fDocumentRewriteSession = null;
      fireRewriteSessionChanged(new DocumentRewriteSessionEvent(this, session, DocumentRewriteSessionEvent.SESSION_STOP));
    }
  }
  
  protected final void stopRewriteSessionOnPartitioners(DocumentRewriteSession session)
  {
    if (fDocumentPartitioners != null)
    {
      DocumentPartitioningChangedEvent event = new DocumentPartitioningChangedEvent(this);
      Iterator e = fDocumentPartitioners.keySet().iterator();
      while (e.hasNext())
      {
        String partitioning = (String)e.next();
        IDocumentPartitioner partitioner = (IDocumentPartitioner)fDocumentPartitioners.get(partitioning);
        if ((partitioner instanceof IDocumentPartitionerExtension3))
        {
          IDocumentPartitionerExtension3 extension = (IDocumentPartitionerExtension3)partitioner;
          extension.stopRewriteSession(session);
          event.setPartitionChange(partitioning, 0, getLength());
        }
      }
      if (!event.isEmpty()) {
        fireDocumentPartitioningChanged(event);
      }
    }
  }
  
  public void addDocumentRewriteSessionListener(IDocumentRewriteSessionListener listener)
  {
    Assert.isNotNull(listener);
    if (!fDocumentRewriteSessionListeners.contains(listener)) {
      fDocumentRewriteSessionListeners.add(listener);
    }
  }
  
  public void removeDocumentRewriteSessionListener(IDocumentRewriteSessionListener listener)
  {
    Assert.isNotNull(listener);
    fDocumentRewriteSessionListeners.remove(listener);
  }
  
  protected final void checkStateOfPartitioner(IDocumentPartitioner partitioner, String partitioning)
  {
    if (!(partitioner instanceof IDocumentPartitionerExtension3)) {
      return;
    }
    IDocumentPartitionerExtension3 extension = (IDocumentPartitionerExtension3)partitioner;
    DocumentRewriteSession session = extension.getActiveRewriteSession();
    if (session != null)
    {
      extension.stopRewriteSession(session);
      
      DocumentPartitioningChangedEvent event = new DocumentPartitioningChangedEvent(this);
      event.setPartitionChange(partitioning, 0, getLength());
      fireDocumentPartitioningChanged(event);
    }
  }
  
  public Position[] getPositions(String category, int offset, int length, boolean canStartBefore, boolean canEndAfter)
    throws BadPositionCategoryException
  {
    if (((canStartBefore) && (canEndAfter)) || ((!canStartBefore) && (!canEndAfter)))
    {
      List documentPositions;
      List documentPositions;
      if ((canStartBefore) && (canEndAfter))
      {
        List documentPositions;
        if (offset < getLength() / 2) {
          documentPositions = getStartingPositions(category, 0, offset + length);
        } else {
          documentPositions = getEndingPositions(category, offset, getLength() - offset + 1);
        }
      }
      else
      {
        documentPositions = getStartingPositions(category, offset, lengt
1 2 3 4 5 6 7 8 9 10 11 12 13

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd