org.eclipse.jface.text.DocumentEvent#getText ( )源码实例Demo

下面列出了org.eclipse.jface.text.DocumentEvent#getText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: xtext-eclipse   文件: HighlightingPresenter.java
/**
 * Update the given position with the given event. The event overlaps with the start of the position.
 * 
 * @param position
 *            The position
 * @param event
 *            The event
 */
private void updateWithOverStartEvent(AttributedPosition position, DocumentEvent event) {
	int eventOffset = event.getOffset();
	int eventEnd = eventOffset + event.getLength();

	String newText = event.getText();
	if (newText == null)
		newText = ""; //$NON-NLS-1$
	int eventNewLength = newText.length();

	int excludedLength = eventNewLength;
	while (excludedLength > 0 && Character.isJavaIdentifierPart(newText.charAt(excludedLength - 1)))
		excludedLength--;
	int deleted = eventEnd - position.getOffset();
	int inserted = eventNewLength - excludedLength;
	position.update(eventOffset + excludedLength, position.getLength() - deleted + inserted);
}
 
源代码2 项目: LogViewer   文件: DamageRepairer.java
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) {
    if (!documentPartitioningChanged) {
        try {

            IRegion info= document.getLineInformationOfOffset(event.getOffset());
            int start= Math.max(partition.getOffset(), info.getOffset());

            int end= event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length());

            if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
                // optimize the case of the same line
                end= info.getOffset() + info.getLength();
            } else
                end= endOfLineOf(end);

            end= Math.min(partition.getOffset() + partition.getLength(), end);
            return new Region(start, end - start);

        } catch (BadLocationException x) {
            logger.logInfo("unable to find location in document to repair a given region",x); //$NON-NLS-1$
        }
    }
    return partition;
}
 
/**
 * Update the given position with the given event. The event overlaps with the start of the position.
 *
 * @param position The position
 * @param event The event
 */
private void updateWithOverStartEvent(HighlightedPosition position, DocumentEvent event) {
	int eventOffset= event.getOffset();
	int eventEnd= eventOffset + event.getLength();

	String newText= event.getText();
	if (newText == null)
		newText= ""; //$NON-NLS-1$
	int eventNewLength= newText.length();

	int excludedLength= eventNewLength;
	while (excludedLength > 0 && Character.isJavaIdentifierPart(newText.charAt(excludedLength - 1)))
		excludedLength--;
	int deleted= eventEnd - position.getOffset();
	int inserted= eventNewLength - excludedLength;
	position.update(eventOffset + excludedLength, position.getLength() - deleted + inserted);
}
 
源代码4 项目: http4e   文件: NonRuleBasedDamagerRepairer.java
/**
 * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
 */
public IRegion getDamageRegion(
	ITypedRegion partition,
	DocumentEvent event,
	boolean documentPartitioningChanged) {
	if (!documentPartitioningChanged) {
		try {

			IRegion info =
				fDocument.getLineInformationOfOffset(event.getOffset());
			int start = Math.max(partition.getOffset(), info.getOffset());

			int end =
				event.getOffset()
					+ (event.getText() == null
						? event.getLength()
						: event.getText().length());

			if (info.getOffset() <= end
				&& end <= info.getOffset() + info.getLength()) {
				// optimize the case of the same line
				end = info.getOffset() + info.getLength();
			} else
				end = endOfLineOf(end);

			end =
				Math.min(
					partition.getOffset() + partition.getLength(),
					end);
			return new Region(start, end - start);

		} catch (BadLocationException x) {
		}
	}

	return partition;
}
 
源代码5 项目: xtext-eclipse   文件: HighlightingPresenter.java
/**
 * Update the given position with the given event. The event overlaps with the end of the position.
 * 
 * @param position
 *            The position
 * @param event
 *            The event
 */
private void updateWithOverEndEvent(AttributedPosition position, DocumentEvent event) {
	String newText = event.getText();
	if (newText == null)
		newText = ""; //$NON-NLS-1$
	int eventNewLength = newText.length();

	int includedLength = 0;
	while (includedLength < eventNewLength && Character.isJavaIdentifierPart(newText.charAt(includedLength)))
		includedLength++;
	position.setLength(event.getOffset() - position.getOffset() + includedLength);
}
 
源代码6 项目: typescript.java   文件: IDETypeScriptFile.java
@Override
public void documentAboutToBeChanged(DocumentEvent event) {
	if (isDisableChanged()) {
		return;
	}
	setDirty(true);
	if (getProject().getProjectSettings().getSynchStrategy() == SynchStrategy.CHANGE) {
		synchronized (synchLock) {
			try {
				String newText = event.getText();
				int position = event.getOffset();

				Location loc = getLocation(position);
				int line = loc.getLine();
				int offset = loc.getOffset();

				Location endLoc = getLocation(position + event.getLength());
				int endLine = endLoc.getLine();
				int endOffset = endLoc.getOffset();

				getProject().getClient().changeFile(getName(), line, offset, endLine, endOffset, newText);
			} catch (Throwable e) {
				e.printStackTrace();
			} finally {
				setDirty(false);
				synchLock.notifyAll();
			}
		}
	}
}
 
/**
 * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
 */
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged)
{
	if (!documentPartitioningChanged)
	{
		try
		{

			IRegion info = fDocument.getLineInformationOfOffset(event.getOffset());
			int start = Math.max(partition.getOffset(), info.getOffset());

			int end = event.getOffset()
					+ ((event.getText() == null) ? event.getLength() : event.getText().length());

			if (info.getOffset() <= end && end <= info.getOffset() + info.getLength())
			{
				// optimize the case of the same line
				end = info.getOffset() + info.getLength();
			}
			else
			{
				end = endOfLineOf(end);
			}
			end = Math.min(partition.getOffset() + partition.getLength(), end);
			return new Region(start, end - start);

		}
		catch (BadLocationException x)
		{
		}
	}

	return partition;
}
 
/**
 * Update the given position with the given event. The event precedes the position.
 *
 * @param position The position
 * @param event The event
 */
private void updateWithPrecedingEvent(HighlightedPosition position, DocumentEvent event) {
	String newText= event.getText();
	int eventNewLength= newText != null ? newText.length() : 0;
	int deltaLength= eventNewLength - event.getLength();

	position.setOffset(position.getOffset() + deltaLength);
}
 
/**
 * Update the given position with the given event. The event overlaps with the end of the position.
 *
 * @param position The position
 * @param event The event
 */
private void updateWithOverEndEvent(HighlightedPosition position, DocumentEvent event) {
	String newText= event.getText();
	if (newText == null)
		newText= ""; //$NON-NLS-1$
	int eventNewLength= newText.length();

	int includedLength= 0;
	while (includedLength < eventNewLength && Character.isJavaIdentifierPart(newText.charAt(includedLength)))
		includedLength++;
	position.setLength(event.getOffset() - position.getOffset() + includedLength);
}
 
源代码10 项目: uima-uimaj   文件: NonRuleBasedDamagerRepairer.java
/**
 * Gets the damage region.
 *
 * @param partition the partition
 * @param event the event
 * @param documentPartitioningChanged the document partitioning changed
 * @return the damage region
 * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
 */
@Override
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event,
        boolean documentPartitioningChanged) {
  if (!documentPartitioningChanged) {
    try {

      IRegion info = fDocument.getLineInformationOfOffset(event.getOffset());
      int start = Math.max(partition.getOffset(), info.getOffset());

      int end = event.getOffset()
              + (event.getText() == null ? event.getLength() : event.getText().length());

      if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
        // optimize the case of the same line
        end = info.getOffset() + info.getLength();
      } else
        end = endOfLineOf(end);

      end = Math.min(partition.getOffset() + partition.getLength(), end);
      return new Region(start, end - start);

    } catch (BadLocationException x) {
    }
  }

  return partition;
}
 
@Override
public IRegion getDamageRegion(
	ITypedRegion partition,
	DocumentEvent event,
	boolean documentPartitioningChanged) {
	if (!documentPartitioningChanged) {
		try {

			IRegion info = fDocument.getLineInformationOfOffset(event.getOffset());
			int start = Math.max(partition.getOffset(), info.getOffset());

			int end =
				event.getOffset()
					+ (event.getText() == null
						? event.getLength()
						: event.getText().length());

			if (info.getOffset() <= end
				&& end <= info.getOffset() + info.getLength()) {
				// optimize the case of the same line
				end = info.getOffset() + info.getLength();
			} else
				end = endOfLineOf(end);

			end =
				Math.min(
					partition.getOffset() + partition.getLength(),
					end);
			return new Region(start, end - start);

		} catch (BadLocationException x) {
		}
	}

	return partition;
}
 
源代码12 项目: birt   文件: NonRuleBasedDamagerRepairer.java
/**
 * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent,
 *      boolean)
 */
public IRegion getDamageRegion( ITypedRegion partition,
		DocumentEvent event, boolean documentPartitioningChanged )
{
	if ( !documentPartitioningChanged )
	{
		try
		{
			IRegion info = fDocument.getLineInformationOfOffset( event.getOffset( ) );
			int start = Math.max( partition.getOffset( ), info.getOffset( ) );

			int end = event.getOffset( )
					+ ( event.getText( ) == null ? event.getLength( )
							: event.getText( ).length( ) );

			if ( info.getOffset( ) <= end
					&& end <= info.getOffset( ) + info.getLength( ) )
			{
				// optimize the case of the same line
				end = info.getOffset( ) + info.getLength( );
			}
			else
			{
				end = endOfLineOf( end );
			}

			end = Math.min( partition.getOffset( ) + partition.getLength( ),
					end );

			return new Region( start, end - start );
		}
		catch ( BadLocationException x )
		{
		}
	}

	return partition;
}
 
源代码13 项目: birt   文件: NonRuleBasedDamagerRepairer.java
/**
 * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent,
 *      boolean)
 */
public IRegion getDamageRegion( ITypedRegion partition,
		DocumentEvent event, boolean documentPartitioningChanged )
{
	if ( !documentPartitioningChanged )
	{
		try
		{

			IRegion info = fDocument.getLineInformationOfOffset( event.getOffset( ) );
			int start = Math.max( partition.getOffset( ), info.getOffset( ) );

			int end = event.getOffset( )
					+ ( event.getText( ) == null ? event.getLength( )
							: event.getText( ).length( ) );

			if ( info.getOffset( ) <= end
					&& end <= info.getOffset( ) + info.getLength( ) )
			{
				// optimize the case of the same line
				end = info.getOffset( ) + info.getLength( );
			}
			else
				end = endOfLineOf( end );

			end = Math.min( partition.getOffset( ) + partition.getLength( ),
					end );
			return new Region( start, end - start );

		}
		catch ( BadLocationException x )
		{
		}
	}

	return partition;
}
 
源代码14 项目: birt   文件: NonRuleBasedDamagerRepairer.java
/**
 * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent,
 *      boolean)
 */
public IRegion getDamageRegion( ITypedRegion partition,
		DocumentEvent event, boolean documentPartitioningChanged )
{
	if ( !documentPartitioningChanged )
	{
		try
		{
			IRegion info = fDocument.getLineInformationOfOffset( event.getOffset( ) );
			int start = Math.max( partition.getOffset( ), info.getOffset( ) );

			int end = event.getOffset( )
					+ ( event.getText( ) == null ? event.getLength( )
							: event.getText( ).length( ) );

			if ( info.getOffset( ) <= end
					&& end <= info.getOffset( ) + info.getLength( ) )
			{
				// optimize the case of the same line
				end = info.getOffset( ) + info.getLength( );
			}
			else
			{
				end = endOfLineOf( end );
			}

			end = Math.min( partition.getOffset( ) + partition.getLength( ),
					end );

			return new Region( start, end - start );
		}
		catch ( BadLocationException x )
		{
		}
	}

	return partition;
}
 
源代码15 项目: Pydev   文件: PyDefaultDamagerRepairer.java
/**
 * {@inheritDoc}
 * <p>
 * This implementation damages entire lines unless clipped by the given partition.
 * </p>
 *
 * @return the full lines containing the document changes described by the document event,
 *         clipped by the given partition. If there was a partitioning change then the whole
 *         partition is returned.
 */
@Override
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent e, boolean documentPartitioningChanged) {

    if (!documentPartitioningChanged) {
        try {

            IRegion info = fDocument.getLineInformationOfOffset(e.getOffset());
            int start = Math.max(partition.getOffset(), info.getOffset());

            int end = e.getOffset() + (e.getText() == null ? e.getLength() : e.getText().length());

            if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
                // optimize the case of the same line
                end = info.getOffset() + info.getLength();
            } else {
                end = endOfLineOf(end);
            }

            end = Math.min(partition.getOffset() + partition.getLength(), end);
            return new Region(start, end - start);

        } catch (BadLocationException x) {
        }
    }

    return partition;
}
 
源代码16 项目: Pydev   文件: ScriptConsoleDocumentListener.java
/**
 * Whenever the document changes, we stop listening to change the document from
 * within this listener (passing commands to the handler if needed, getting results, etc).
 */
@Override
public void documentChanged(DocumentEvent event) {
    lastChangeMillis = System.currentTimeMillis();
    startDisconnected();
    try {
        int eventOffset = event.getOffset();
        String eventText = event.getText();
        proccessAddition(eventOffset, eventText);
    } finally {
        stopDisconnected();
    }
}
 
源代码17 项目: tm4e   文件: DocumentHelper.java
public static boolean isRemove(DocumentEvent event) {
	return event.getText() == null || event.getText().length() == 0;
}
 
源代码18 项目: tm4e   文件: DocumentHelper.java
public static boolean isInsert(DocumentEvent event) {
	return event.getLength() == 0 && event.getText() != null;
}
 
源代码19 项目: xtext-eclipse   文件: HighlightingPresenter.java
/**
 * Update the given position with the given event. The event precedes the position.
 * 
 * @param position
 *            The position
 * @param event
 *            The event
 */
private void updateWithPrecedingEvent(AttributedPosition position, DocumentEvent event) {
	String newText = event.getText();
	int eventNewLength = newText != null ? newText.length() : 0;
	int deltaLength = eventNewLength - event.getLength();

	position.setOffset(position.getOffset() + deltaLength);
}
 
源代码20 项目: saros   文件: StoppableDocumentListener.java
@Override
public void documentAboutToBeChanged(final DocumentEvent event) {

  if (!enabled) return;

  String text = event.getText() == null ? "" : event.getText();

  editorManager.textAboutToBeChanged(
      event.getOffset(), text, event.getLength(), event.getDocument());
}