diff options
author | Tom Schindl | 2015-07-17 23:07:03 +0000 |
---|---|---|
committer | Tom Schindl | 2015-07-17 23:08:22 +0000 |
commit | a485362e46ef845177cc926d6139b54438757d05 (patch) | |
tree | 9337f2dff1cc5bab7a97e1e4fa3ad640d53a3e81 | |
parent | 936e730b135f66168c19bace9a5baf05a985b65e (diff) | |
parent | bafc0b8c8d5d818881d6adb4dd21ab2d23576a64 (diff) | |
download | org.eclipse.efxclipse-a485362e46ef845177cc926d6139b54438757d05.tar.gz org.eclipse.efxclipse-a485362e46ef845177cc926d6139b54438757d05.tar.xz org.eclipse.efxclipse-a485362e46ef845177cc926d6139b54438757d05.zip |
Merge branch 'master' of ssh://tschindl@git.eclipse.org:29418/efxclipse/org.eclipse.efxclipse
84 files changed, 0 insertions, 9576 deletions
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/.classpath b/experimental/compensator/org.eclipse.fx.text.ui/.classpath deleted file mode 100644 index eca7bdba8..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/.classpath +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="src" path="src"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/experimental/compensator/org.eclipse.fx.text.ui/.gitignore b/experimental/compensator/org.eclipse.fx.text.ui/.gitignore deleted file mode 100644 index ae3c17260..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/experimental/compensator/org.eclipse.fx.text.ui/.project b/experimental/compensator/org.eclipse.fx.text.ui/.project deleted file mode 100644 index 817056f57..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/.project +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.fx.text.ui</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/experimental/compensator/org.eclipse.fx.text.ui/.settings/org.eclipse.jdt.core.prefs b/experimental/compensator/org.eclipse.fx.text.ui/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 8d88004d6..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,114 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled -org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore -org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull -org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault -org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable -org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.doc.comment.support=enabled -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.autoboxing=warning -org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning -org.eclipse.jdt.core.compiler.problem.deadCode=warning -org.eclipse.jdt.core.compiler.problem.deprecation=warning -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=warning -org.eclipse.jdt.core.compiler.problem.emptyStatement=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning -org.eclipse.jdt.core.compiler.problem.forbiddenReference=error -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning -org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning -org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning -org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=protected -org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning -org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning -org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled -org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning -org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected -org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag -org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning -org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning -org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning -org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error -org.eclipse.jdt.core.compiler.problem.nullReference=error -org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error -org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning -org.eclipse.jdt.core.compiler.problem.parameterAssignment=warning -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning -org.eclipse.jdt.core.compiler.problem.potentialNullReference=error -org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning -org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore -org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore -org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=warning -org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=warning -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning -org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning -org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=warning -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=warning -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled -org.eclipse.jdt.core.compiler.problem.unusedImport=warning -org.eclipse.jdt.core.compiler.problem.unusedLabel=warning -org.eclipse.jdt.core.compiler.problem.unusedLocal=warning -org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning -org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/experimental/compensator/org.eclipse.fx.text.ui/META-INF/MANIFEST.MF b/experimental/compensator/org.eclipse.fx.text.ui/META-INF/MANIFEST.MF deleted file mode 100644 index 02581c0a6..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/META-INF/MANIFEST.MF +++ /dev/null @@ -1,20 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: Ui -Bundle-SymbolicName: org.eclipse.fx.text.ui -Bundle-Version: 1.0.0.qualifier -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Require-Bundle: org.eclipse.fx.ui.controls;bundle-version="1.0.0", - org.eclipse.text;bundle-version="3.5.300", - org.eclipse.fx.text;bundle-version="1.0.0", - org.eclipse.jdt.annotation;bundle-version="2.0.0";resolution:=optional, - org.eclipse.fx.core, - org.eclipse.fx.ui.services -Export-Package: org.eclipse.jface.text, - org.eclipse.jface.text.contentassist, - org.eclipse.jface.text.presentation, - org.eclipse.jface.text.reconciler, - org.eclipse.jface.text.rules, - org.eclipse.jface.text.source, - org.eclipse.jface.viewers -Import-Package: javax.inject;version="1.0.0" diff --git a/experimental/compensator/org.eclipse.fx.text.ui/build.properties b/experimental/compensator/org.eclipse.fx.text.ui/build.properties deleted file mode 100644 index 34d2e4d2d..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/DefaultDocumentAdapter.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/DefaultDocumentAdapter.java deleted file mode 100644 index cd76d6c45..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/DefaultDocumentAdapter.java +++ /dev/null @@ -1,397 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.fx.ui.controls.styledtext.TextChangedEvent; -import org.eclipse.fx.ui.controls.styledtext.TextChangingEvent; - - -/** - * Default implementation of {@link org.eclipse.jface.text.IDocumentAdapter}. - * <p> - * <strong>Note:</strong> This adapter does not work if the widget auto-wraps the text. - * </p> - */ -class DefaultDocumentAdapter implements IDocumentAdapter, IDocumentListener, IDocumentAdapterExtension { - - /** The adapted document. */ - private IDocument fDocument; - /** The document clone for the non-forwarding case. */ - private IDocument fDocumentClone; - /** The original content */ - private String fOriginalContent; - /** The original line delimiters */ - private String[] fOriginalLineDelimiters; - /** The registered text change listeners */ - private List fTextChangeListeners= new ArrayList(1); - /** - * The remembered document event - * @since 2.0 - */ - private DocumentEvent fEvent; - /** The line delimiter */ - private String fLineDelimiter= null; - /** - * Indicates whether this adapter is forwarding document changes - * @since 2.0 - */ - private boolean fIsForwarding= true; - /** - * Length of document at receipt of <code>documentAboutToBeChanged</code> - * @since 2.1 - */ - private int fRememberedLengthOfDocument; - /** - * Length of first document line at receipt of <code>documentAboutToBeChanged</code> - * @since 2.1 - */ - private int fRememberedLengthOfFirstLine; - /** - * The data of the event at receipt of <code>documentAboutToBeChanged</code> - * @since 2.1 - */ - private DocumentEvent fOriginalEvent= new DocumentEvent(); - - - /** - * Creates a new document adapter which is initially not connected to - * any document. - */ - public DefaultDocumentAdapter() { - } - - /** - * Sets the given document as the document to be adapted. - * - * @param document the document to be adapted or <code>null</code> if there is no document - */ - public void setDocument(IDocument document) { - - if (fDocument != null) - fDocument.removePrenotifiedDocumentListener(this); - - fDocument= document; - fLineDelimiter= null; - - if (!fIsForwarding) { - fDocumentClone= null; - if (fDocument != null) { - fOriginalContent= fDocument.get(); - fOriginalLineDelimiters= fDocument.getLegalLineDelimiters(); - } else { - fOriginalContent= null; - fOriginalLineDelimiters= null; - } - } - - if (fDocument != null) - fDocument.addPrenotifiedDocumentListener(this); - } - - /* - * @see StyledTextContent#addTextChangeListener(TextChangeListener) - */ - public void addTextChangeListener(TextChangeListener listener) { - Assert.isNotNull(listener); - if (!fTextChangeListeners.contains(listener)) - fTextChangeListeners.add(listener); - } - - /* - * @see StyledTextContent#removeTextChangeListener(TextChangeListener) - */ - public void removeTextChangeListener(TextChangeListener listener) { - Assert.isNotNull(listener); - fTextChangeListeners.remove(listener); - } - - /** - * Tries to repair the line information. - * - * @param document the document - * @see IRepairableDocument#repairLineInformation() - * @since 3.0 - */ - private void repairLineInformation(IDocument document) { - if (document instanceof IRepairableDocument) { - IRepairableDocument repairable= (IRepairableDocument) document; - repairable.repairLineInformation(); - } - } - - /** - * Returns the line for the given line number. - * - * @param document the document - * @param line the line number - * @return the content of the line of the given number in the given document - * @throws BadLocationException if the line number is invalid for the adapted document - * @since 3.0 - */ - private String doGetLine(IDocument document, int line) throws BadLocationException { - IRegion r= document.getLineInformation(line); - return document.get(r.getOffset(), r.getLength()); - } - - private IDocument getDocumentForRead() { - if (!fIsForwarding) { - if (fDocumentClone == null) { - String content= fOriginalContent == null ? "" : fOriginalContent; //$NON-NLS-1$ - String[] delims= fOriginalLineDelimiters == null ? DefaultLineTracker.DELIMITERS : fOriginalLineDelimiters; - fDocumentClone= new DocumentClone(content, delims); - } - return fDocumentClone; - } - - return fDocument; - } - - @Override - public String getLine(int line) { - - IDocument document= getDocumentForRead(); - try { - return doGetLine(document, line); - } catch (BadLocationException x) { - repairLineInformation(document); - try { - return doGetLine(document, line); - } catch (BadLocationException x2) { - throw new IllegalStateException(x2); - } - } - } - - public int getLineAtOffset(int offset) { - IDocument document= getDocumentForRead(); - try { - return document.getLineOfOffset(offset); - } catch (BadLocationException x) { - repairLineInformation(document); - try { - return document.getLineOfOffset(offset); - } catch (BadLocationException x2) { - } - } - - //TODO Log it - System.err.println("invalid argument"); - return -1; - } - - public int getLineCount() { - return getDocumentForRead().getNumberOfLines(); - } - - public int getOffsetAtLine(int line) { - IDocument document= getDocumentForRead(); - try { - return document.getLineOffset(line); - } catch (BadLocationException x) { - repairLineInformation(document); - try { - return document.getLineOffset(line); - } catch (BadLocationException x2) { - } - } - - //TODO Log it - System.err.println("invalid argument"); - return -1; - } - - public String getTextRange(int offset, int length) { - try { - return getDocumentForRead().get(offset, length); - } catch (BadLocationException x) { - throw new IllegalStateException(x); - } - } - - public void replaceTextRange(int pos, int length, String text) { - try { - fDocument.replace(pos, length, text); - } catch (BadLocationException x) { - //TODO Log it - x.printStackTrace(); - } - } - - public void setText(String text) { - fDocument.set(text); - } - - /* - * @see StyledTextContent#getCharCount() - */ - public int getCharCount() { - return getDocumentForRead().getLength(); - } - - /* - * @see StyledTextContent#getLineDelimiter() - */ - public String getLineDelimiter() { - if (fLineDelimiter == null) - fLineDelimiter= TextUtilities.getDefaultLineDelimiter(fDocument); - return fLineDelimiter; - } - - /* - * @see IDocumentListener#documentChanged(DocumentEvent) - */ - public void documentChanged(DocumentEvent event) { - // check whether the given event is the one which was remembered - if (fEvent == null || event != fEvent) - return; - - if (isPatchedEvent(event) || (event.getOffset() == 0 && event.getLength() == fRememberedLengthOfDocument)) { - fLineDelimiter= null; - fireTextSet(); - } else { - if (event.getOffset() < fRememberedLengthOfFirstLine) - fLineDelimiter= null; - fireTextChanged(); - } - } - - /* - * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent) - */ - public void documentAboutToBeChanged(DocumentEvent event) { - - fRememberedLengthOfDocument= fDocument.getLength(); - try { - fRememberedLengthOfFirstLine= fDocument.getLineLength(0); - } catch (BadLocationException e) { - fRememberedLengthOfFirstLine= -1; - } - - fEvent= event; - rememberEventData(fEvent); - fireTextChanging(); - } - - /** - * Checks whether this event has been changed between <code>documentAboutToBeChanged</code> and - * <code>documentChanged</code>. - * - * @param event the event to be checked - * @return <code>true</code> if the event has been changed, <code>false</code> otherwise - */ - private boolean isPatchedEvent(DocumentEvent event) { - return fOriginalEvent.fOffset != event.fOffset || fOriginalEvent.fLength != event.fLength || fOriginalEvent.fText != event.fText; - } - - /** - * Makes a copy of the given event and remembers it. - * - * @param event the event to be copied - */ - private void rememberEventData(DocumentEvent event) { - fOriginalEvent.fOffset= event.fOffset; - fOriginalEvent.fLength= event.fLength; - fOriginalEvent.fText= event.fText; - } - - /** - * Sends a text changed event to all registered listeners. - */ - private void fireTextChanged() { - - if (!fIsForwarding) - return; - - TextChangedEvent event = TextChangedEvent.textChanged(this); - - if (fTextChangeListeners != null && fTextChangeListeners.size() > 0) { - Iterator e= new ArrayList(fTextChangeListeners).iterator(); - while (e.hasNext()) - ((TextChangeListener) e.next()).textChanged(event); - } - } - - /** - * Sends a text set event to all registered listeners. - */ - private void fireTextSet() { - - if (!fIsForwarding) - return; - - TextChangedEvent event = TextChangedEvent.textSet(this); - - if (fTextChangeListeners != null && fTextChangeListeners.size() > 0) { - Iterator e= new ArrayList(fTextChangeListeners).iterator(); - while (e.hasNext()) - ((TextChangeListener) e.next()).textSet(event); - } - } - - /** - * Sends the text changing event to all registered listeners. - */ - private void fireTextChanging() { - - if (!fIsForwarding) - return; - - try { - IDocument document= fEvent.getDocument(); - if (document == null) - return; - - TextChangingEvent event= TextChangingEvent.textChanging(this, - fEvent.fOffset, - fEvent.fLength, - document.getNumberOfLines(fEvent.fOffset, fEvent.fLength) - 1, - fEvent.fText, - (fEvent.fText == null ? 0 : fEvent.fText.length()), - (fEvent.fText == null ? 0 : document.computeNumberOfLines(fEvent.fText))); - - if (fTextChangeListeners != null && fTextChangeListeners.size() > 0) { - Iterator e= new ArrayList(fTextChangeListeners).iterator(); - while (e.hasNext()) - ((TextChangeListener) e.next()).textChanging(event); - } - - } catch (BadLocationException e) { - } - } - - /* - * @see IDocumentAdapterExtension#resumeForwardingDocumentChanges() - * @since 2.0 - */ - public void resumeForwardingDocumentChanges() { - fIsForwarding= true; - fDocumentClone= null; - fOriginalContent= null; - fOriginalLineDelimiters= null; - fireTextSet(); - } - - /* - * @see IDocumentAdapterExtension#stopForwardingDocumentChanges() - * @since 2.0 - */ - public void stopForwardingDocumentChanges() { - fDocumentClone= null; - fOriginalContent= fDocument.get(); - fOriginalLineDelimiters= fDocument.getLegalLineDelimiters(); - fIsForwarding= false; - } -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/IDocumentAdapter.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/IDocumentAdapter.java deleted file mode 100644 index 55a9b094b..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/IDocumentAdapter.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -import org.eclipse.fx.ui.controls.styledtext.StyledTextContent; - - -/** - * Adapts an {@link org.eclipse.jface.text.IDocument}to the - * {@link org.eclipse.swt.custom.StyledTextContent} interface. The document - * adapter is used by {@link org.eclipse.jface.text.TextViewer} to translate - * document changes into styled text content changes and vice versa. - * <p> - * Clients may implement this interface and override - * <code>TextViewer.createDocumentAdapter</code> if they want to intercept the - * communication between the viewer's text widget and the viewer's document. - * <p> - * In order to provide backward compatibility for clients of - * <code>IDocumentAdapter</code>, extension interfaces are used as a means of - * evolution. The following extension interfaces exist: - * <ul> - * <li>{@link org.eclipse.jface.text.IDocumentAdapterExtension} since version - * 2.0 introducing a way of batching a sequence of document changes into a - * single styled text content notification</li> - * </ul> - * - * @see org.eclipse.jface.text.IDocumentAdapterExtension - * @see org.eclipse.jface.text.IDocument - */ -public interface IDocumentAdapter extends StyledTextContent { - - /** - * Sets the adapters document. - * - * @param document the document to be adapted - */ - void setDocument(IDocument document); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/IDocumentAdapterExtension.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/IDocumentAdapterExtension.java deleted file mode 100644 index 160ee3e40..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/IDocumentAdapterExtension.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text; - -/** - * Extension interface for {@link org.eclipse.jface.text.IDocumentAdapter}. - * <p> - * Introduces the concepts of batching a series of document changes into a - * single styled text content change notification. Batching start when a client - * calls <code>stopForwardingDocumentChanges</code>. After that call this - * document adapter does not send out styled text content change notifications - * until <code>resumeForwardingDocumentChanges</code> is called. On - * <code>resumeForwardingDocumentChanges</code>, it sends out one styled text - * content change notification that covers all changes that have been applied to - * the document since calling <code>stopForwardingDocumentChanges</code>. - * - * @since 2.0 - */ -public interface IDocumentAdapterExtension { - - /** - * Stops forwarding document changes to the styled text. - */ - void stopForwardingDocumentChanges(); - - /** - * Resumes forwarding document changes to the styled text. - * Also forces the styled text to catch up with all the changes - * that have been applied since <code>stopForwardingDocumentChanges</code> - * has been called. - */ - void resumeForwardingDocumentChanges(); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/IRewriteTarget.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/IRewriteTarget.java deleted file mode 100644 index 0f698dc77..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/IRewriteTarget.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - - /** - * A target publishing the required functions to modify a document that is displayed - * in a text viewer. It provides access to the document and control - * over the redraw behavior and the grouping of document changes into undo commands. - * - * @see org.eclipse.jface.text.ITextViewer - * @see org.eclipse.jface.text.IDocument - * @see org.eclipse.jface.text.IUndoManager - * @since 2.0 - */ -public interface IRewriteTarget { - - /** - * Returns the document of this target. - * - * @return the document of this target - */ - IDocument getDocument(); - - /** - * Disables/enables redrawing while modifying the target's document. - * - * @param redraw <code>true</code> if the document's visible presentation - * should be updated, <code>false</code> otherwise - */ - void setRedraw(boolean redraw); - - /** - * If an undo manager is connected to the document's visible presentation, - * this method tells the undo manager to fold all subsequent changes into - * one single undo command until <code>endCompoundChange</code> is called. - */ - void beginCompoundChange(); - - /** - * If an undo manager is connected to the document's visible presentation, - * this method tells the undo manager to stop the folding of changes into a - * single undo command. After this call, all subsequent changes are - * considered to be individually undo-able. - */ - void endCompoundChange(); -} - diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextInputListener.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextInputListener.java deleted file mode 100644 index 44f6d3739..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextInputListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - - -/** - * Text input listeners registered with an - * {@link org.eclipse.jface.text.ITextViewer} are informed if the document - * serving as the text viewer's model is replaced. - * <p> - * Clients may implement this interface.</p> - * - * @see org.eclipse.jface.text.ITextViewer - * @see org.eclipse.jface.text.IDocument - */ -public interface ITextInputListener { - - /** - * Called before the input document is replaced. - * - * @param oldInput the text viewer's previous input document - * @param newInput the text viewer's new input document - */ - void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput); - - /** - * Called after the input document has been replaced. - * - * @param oldInput the text viewer's previous input document - * @param newInput the text viewer's new input document - */ - void inputDocumentChanged(IDocument oldInput, IDocument newInput); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextListener.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextListener.java deleted file mode 100644 index 64d944166..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextListener.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - - -/** - * Text listeners registered with a text viewer are informed about all - * modifications of an {@link org.eclipse.jface.text.ITextViewer} by means of - * text events. A text event describes a change as a replace operation. - * <p> - * The changes described in the event are the changes applied to the text - * viewer's widget (i.e., its visual representation) and not those applied to the - * text viewer's document. The text event can be asked to return the - * corresponding document event. If the text event does not contain a document - * event, the modification of the text viewer is a presentation change. For - * example, changing the visible region of a text viewer, is a presentation - * change. A completely empty text event represents a change of the viewer's - * redraw state.</p> - * <p> - * If a text listener receives a text event, it is guaranteed that both the - * document and the viewer's visual representation are synchronized.</p> - * <p> - * Clients may implement this interface.</p> - * - * @see org.eclipse.jface.text.ITextViewer - * @see org.eclipse.jface.text.TextEvent - * @see org.eclipse.jface.text.DocumentEvent - */ -public interface ITextListener { - - /** - * The visual representation of a text viewer this listener is registered with - * has been changed. - * - * @param event the description of the change - */ - void textChanged(TextEvent event); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextPresentationListener.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextPresentationListener.java deleted file mode 100644 index 839c87477..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextPresentationListener.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * Text presentation listeners registered with an - * {@link org.eclipse.jface.text.ITextViewer} are informed when a - * {@link org.eclipse.jface.text.TextPresentation} is about to be applied to the - * text viewer. The listener can apply changes to the text presentation and thus - * participate in the process of text presentation creation. - * - * @since 3.0 - */ -public interface ITextPresentationListener { - - /** - * This method is called when a text presentation is about to be applied to - * the text viewer. The receiver is allowed to change the text presentation - * during that call. - * - * @param textPresentation the current text presentation - */ - public void applyTextPresentation(TextPresentation textPresentation); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewer.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewer.java deleted file mode 100644 index 9caa5e3be..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewer.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.eclipse.jface.text; - -import org.eclipse.fx.ui.controls.styledtext.StyledTextArea; - -public interface ITextViewer { - public IDocument getDocument(); - public void setDocument(IDocument document); - void setDocument(IDocument document, int modelRangeOffset, int modelRangeLength); - public IRegion getVisibleRegion(); - void addTextListener(ITextListener listener); - public void removeTextListener(ITextListener listener); - void addTextInputListener(ITextInputListener listener); - void removeTextInputListener(ITextInputListener listener); - void changeTextPresentation(TextPresentation presentation, boolean controlRedraw); - StyledTextArea getTextWidget(); - public boolean overlapsWithVisibleRegion(int start, int length); - public void invalidateTextPresentation(); - -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension.java deleted file mode 100644 index ab8ff8b3d..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.eclipse.jface.text; - -public interface ITextViewerExtension { - -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension2.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension2.java deleted file mode 100644 index 78da514dc..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension2.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.eclipse.jface.text; - -public interface ITextViewerExtension2 { - /** - * Invalidates the viewer's text presentation for the given range. - * - * @param offset the offset of the first character to be redrawn - * @param length the length of the range to be redrawn - */ - void invalidateTextPresentation(int offset, int length); - -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension3.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension3.java deleted file mode 100644 index 82adc0d3f..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension3.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * Extension interface for {@link org.eclipse.jface.text.ITextViewer}. <p> - * This interface has been replaced by {@link org.eclipse.jface.text.ITextViewerExtension5}. - * Clients are not supposed to use this interface any longer. - * - * @since 2.1 - * @deprecated replaced by {@link org.eclipse.jface.text.ITextViewerExtension5} - */ -public interface ITextViewerExtension3 { - - - /** - * Returns the minimal region of the viewer's document that completely comprises everything that is - * visible in the viewer's widget or <code>null</code> if there is no such region. - * - * @return the minimal region of the viewer's document comprising the contents of the viewer's widget or <code>null</code> - */ - IRegion getModelCoverage(); - - - /** - * Returns the widget line that corresponds to the given line of the viewer's document or <code>-1</code> if there is no such line. - * - * @param modelLine the line of the viewer's document - * @return the corresponding widget line or <code>-1</code> - */ - int modelLine2WidgetLine(int modelLine); - - /** - * Returns the widget offset that corresponds to the given offset in the viewer's document - * or <code>-1</code> if there is no such offset - * - * @param modelOffset the offset in the viewer's document - * @return the corresponding widget offset or <code>-1</code> - */ - int modelOffset2WidgetOffset(int modelOffset); - - /** - * Returns the minimal region of the viewer's widget that completely comprises the given region of the - * viewer's document or <code>null</code> if there is no such region. - * - * @param modelRange the region of the viewer's document - * @return the minimal region of the widget comprising <code>modelRange</code> or <code>null</code> - */ - IRegion modelRange2WidgetRange(IRegion modelRange); - - - /** - * Returns the offset of the viewer's document that corresponds to the given widget offset - * or <code>-1</code> if there is no such offset - * - * @param widgetOffset the widget offset - * @return the corresponding offset in the viewer's document or <code>-1</code> - */ - int widgetOffset2ModelOffset(int widgetOffset); - - /** - * Returns the minimal region of the viewer's document that completely comprises the given widget region - * or <code>null</code> if there is no such region. - * - * @param widgetRange the widget region - * @return the minimal region of the viewer's document comprising <code>widgetRange</code> or <code>null</code> - */ - IRegion widgetRange2ModelRange(IRegion widgetRange); - - /** - * Returns the line of the viewer's document that corresponds to the given widget line or <code>-1</code> if there is no such line. - * - * @param widgetLine the widget line - * @return the corresponding line of the viewer's document or <code>-1</code> - */ - int widgetlLine2ModelLine(int widgetLine); - - /** - * Returns the widget line of the given widget offset. - * - * @param widgetOffset the widget offset - * @return the widget line of the widget offset - */ - int widgetLineOfWidgetOffset(int widgetOffset); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension4.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension4.java deleted file mode 100644 index 6e7ee0c6b..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension4.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.eclipse.jface.text; - -public interface ITextViewerExtension4 { - /** - * Adds the given text presentation listener to this text viewer. - * This call has no effect if the listener is already registered - * with this text viewer. - * - * @param listener the text presentation listener - */ - void addTextPresentationListener(ITextPresentationListener listener); - - /** - * Removes the given text presentation listener from this text viewer. - * This call has no effect if the listener is not registered with this - * text viewer. - * - * @param listener the text presentation listener - */ - void removeTextPresentationListener(ITextPresentationListener listener); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension5.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension5.java deleted file mode 100644 index 206cfc3ce..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension5.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -/** - * Extension interface for {@link org.eclipse.jface.text.ITextViewer}. Defines - * a conceptual replacement of the original visible region concept. This interface - * replaces {@link org.eclipse.jface.text.ITextViewerExtension3}. - * <p> - * Introduces the explicit concept of model and widget coordinates. For example, - * a selection returned by the text viewer's control is a widget selection. A - * widget selection always maps to a certain range of the viewer's document. - * This range is considered the model selection. - * <p> - * All model ranges that have a corresponding widget ranges are considered - * "exposed model ranges". The viewer can be requested to expose a given model - * range. Thus, a visible region is a particular degeneration of exposed model - * ranges. - * <p> - * This interface allows implementers to follow a sophisticated presentation - * model in which the visible presentation is a complex projection of the - * viewer's input document. - * - * @since 3.0 - */ -public interface ITextViewerExtension5 extends ITextViewerExtension3 { - - /** - * Returns the minimal region of the viewer's input document that completely - * comprises everything that is visible in the viewer's widget or - * <code>null</code> if there is no such region. - * - * @return the minimal region of the viewer's document comprising the - * contents of the viewer's widget or <code>null</code> - */ - IRegion getModelCoverage(); - - /** - * Returns the widget line that corresponds to the given line of the - * viewer's input document or <code>-1</code> if there is no such line. - * - * @param modelLine the line of the viewer's document - * @return the corresponding widget line or <code>-1</code> - */ - int modelLine2WidgetLine(int modelLine); - - /** - * Returns the widget offset that corresponds to the given offset in the - * viewer's input document or <code>-1</code> if there is no such offset - * - * @param modelOffset the offset in the viewer's document - * @return the corresponding widget offset or <code>-1</code> - */ - int modelOffset2WidgetOffset(int modelOffset); - - /** - * Returns the minimal region of the viewer's widget that completely - * comprises the given region of the viewer's input document or - * <code>null</code> if there is no such region. - * - * @param modelRange the region of the viewer's document - * @return the minimal region of the widget comprising - * <code>modelRange</code> or <code>null</code> - */ - IRegion modelRange2WidgetRange(IRegion modelRange); - - /** - * Returns the offset of the viewer's input document that corresponds to the - * given widget offset or <code>-1</code> if there is no such offset - * - * @param widgetOffset the widget offset - * @return the corresponding offset in the viewer's document or - * <code>-1</code> - */ - int widgetOffset2ModelOffset(int widgetOffset); - - /** - * Returns the minimal region of the viewer's input document that completely - * comprises the given widget region or <code>null</code> if there is no - * such region. - * - * @param widgetRange the widget region - * @return the minimal region of the viewer's document comprising - * <code>widgetlRange</code> or <code>null</code> - */ - IRegion widgetRange2ModelRange(IRegion widgetRange); - - /** - * Returns the line of the viewer's input document that corresponds to the - * given widget line or <code>-1</code> if there is no such line. - * - * @param widgetLine the widget line - * @return the corresponding line of the viewer's document or - * <code>-1</code> - */ - int widgetLine2ModelLine(int widgetLine); - - /** - * Returns the widget line of the given widget offset. - * - * @param widgetOffset the widget offset - * @return the widget line of the widget offset - */ - int widgetLineOfWidgetOffset(int widgetOffset); - - - /** - * Returns the maximal subranges of the given model range thus that there is - * no offset inside a subrange for which there is no image offset. - * - * @param modelRange the model range - * @return the list of subranges - */ - IRegion[] getCoveredModelRanges(IRegion modelRange); - - /** - * Exposes the given model range. Returns whether this call caused a change - * of the set of exposed model ranges. - * - * @param modelRange the model range to be exposed - * @return <code>true</code> if the set of exposed model ranges changed, - * <code>false</code> otherwise - */ - boolean exposeModelRange(IRegion modelRange); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension6.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension6.java deleted file mode 100644 index 9024869b6..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension6.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.eclipse.jface.text; - -public interface ITextViewerExtension6 { - -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension7.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension7.java deleted file mode 100644 index 4cf21ff40..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension7.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.eclipse.jface.text; - -public interface ITextViewerExtension7 { - -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension8.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension8.java deleted file mode 100644 index bb4b986f7..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension8.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.eclipse.jface.text; - -public interface ITextViewerExtension8 { - -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextAttribute.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextAttribute.java deleted file mode 100644 index fe6ce417d..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextAttribute.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -import org.eclipse.fx.ui.controls.styledtext.StyleRange; - -import javafx.scene.paint.Color; -import javafx.scene.text.Font; - - -/** - * Description of textual attributes such as color and style. Text attributes - * are considered value objects. - * <p> - * Clients usually instantiate object of the class.</p> - */ -public class TextAttribute { - - /** - * Text attribute for strikethrough style. - * (value <code>1 << 29</code>). - * @since 3.1 - */ - public static final int STRIKETHROUGH= 1 << 29; - - /** - * Text attribute for underline style. - * (value <code>1 << 30</code>) - * @since 3.1 - */ - public static final int UNDERLINE= 1 << 30; - - - /** Foreground color */ - private Color foreground; - - /** Background color */ - private Color background; - - /** The text style */ - private int style; - - /** - * The text font. - * @since 3.3 - */ - private Font font; - - /** - * Cached hash code. - * @since 3.3 - */ - private int fHashCode; - - private String stylename; - - /** - * Creates a text attribute with the given colors and style. - * - * @param foreground the foreground color, <code>null</code> if none - * @param background the background color, <code>null</code> if none - * @param style the style - */ - public TextAttribute(String stylename, Color foreground, Color background, int style) { - this.stylename = stylename; - this.foreground= foreground; - this.background= background; - this.style= style; - } - - /** - * Creates a text attribute with the given colors and style. - * - * @param foreground the foreground color, <code>null</code> if none - * @param background the background color, <code>null</code> if none - * @param style the style - * @param font the font, <code>null</code> if none - * @since 3.3 - */ - public TextAttribute(String stylename, Color foreground, Color background, int style, Font font) { - this.stylename = stylename; - this.foreground= foreground; - this.background= background; - this.style= style; - this.font= font; - } - - /** - * Creates a text attribute for the given foreground color, no background color and - * with the SWT normal style. - * - * @param foreground the foreground color, <code>null</code> if none - */ - public TextAttribute(String stylename, Color foreground) { - this(stylename, foreground, null, StyleRange.NORMAL); - } - - public TextAttribute(String stylename) { - this.stylename = stylename; - } - - public String getStylename() { - return stylename; - } - - /* - * @see Object#equals(Object) - */ - public boolean equals(Object object) { - - if (object == this) - return true; - - if (!(object instanceof TextAttribute)) - return false; - TextAttribute a= (TextAttribute)object; - - return (equals(a.stylename,stylename) && a.style == style && equals(a.foreground, foreground) && equals(a.background, background) && equals(a.font, font)); - } - - /** - * Returns whether the two given objects are equal. - * - * @param o1 the first object, can be <code>null</code> - * @param o2 the second object, can be <code>null</code> - * @return <code>true</code> if the given objects are equals - * @since 2.0 - */ - private boolean equals(Object o1, Object o2) { - if (o1 != null) - return o1.equals(o2); - return (o2 == null); - } - - /* - * @see Object#hashCode() - */ - public int hashCode() { - if (fHashCode == 0) { - int multiplier= 37; // some prime - fHashCode= 13; // some random value - fHashCode= multiplier * fHashCode + (stylename == null ? 0 : stylename.hashCode()); - fHashCode= multiplier * fHashCode + (font == null ? 0 : font.hashCode()); - fHashCode= multiplier * fHashCode + (background == null ? 0 : background.hashCode()); - fHashCode= multiplier * fHashCode + (foreground == null ? 0 : foreground.hashCode()); - fHashCode= multiplier * fHashCode + style; - } - return fHashCode; - } - - /** - * Returns the attribute's foreground color. - * - * @return the attribute's foreground color or <code>null</code> if not set - */ - public Color getForeground() { - return foreground; - } - - /** - * Returns the attribute's background color. - * - * @return the attribute's background color or <code>null</code> if not set - */ - public Color getBackground() { - return background; - } - - /** - * Returns the attribute's style. - * - * @return the attribute's style - */ - public int getStyle() { - return style; - } - - /** - * Returns the attribute's font. - * - * @return the attribute's font or <code>null</code> if not set - * @since 3.3 - */ - public Font getFont() { - return font; - } -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextEvent.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextEvent.java deleted file mode 100644 index 617d0e23e..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextEvent.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * This event is sent to implementers of - * {@link org.eclipse.jface.text.ITextListener}. It represents a change applied - * to text viewer. The change is specified as a replace command using offset, - * length, inserted text, and replaced text. The text viewer issues a text event - * after the viewer has been changed either in response to a change of the - * viewer's document or when the viewer's visual content has been changed. In - * the first case, the text event also carries the original document event. - * Depending on the viewer's presentation mode, the text event coordinates are - * different from the document event's coordinates. - * <p> - * An empty text event usually indicates a change of the viewer's redraw state.</p> - * <p> - * Clients other than text viewer's don't create instances of this class.</p> - * - * @see org.eclipse.jface.text.ITextListener - * @see org.eclipse.jface.text.ITextViewer - * @see org.eclipse.jface.text.DocumentEvent - */ -public class TextEvent { - - /** Start offset of the change */ - private int fOffset; - /** The length of the change */ - private int fLength; - /** Inserted text */ - private String fText; - /** Replaced text */ - private String fReplacedText; - /** The original document event, may by null */ - private DocumentEvent fDocumentEvent; - /** - * The redraw state of the viewer issuing this event - * @since 2.0 - */ - private boolean fViewerRedrawState; - - /** - * Creates a new <code>TextEvent</code> based on the specification. - * - * @param offset the offset - * @param length the length - * @param text the inserted text - * @param replacedText the replaced text - * @param event the associated document event or <code>null</code> if none - * @param viewerRedrawState the redraw state of the viewer - */ - protected TextEvent(int offset, int length, String text, String replacedText, DocumentEvent event, boolean viewerRedrawState) { - fOffset= offset; - fLength= length; - fText= text; - fReplacedText= replacedText; - fDocumentEvent= event; - fViewerRedrawState= viewerRedrawState; - } - - /** - * Returns the offset of the event. - * - * @return the offset of the event - */ - public int getOffset() { - return fOffset; - } - - /** - * Returns the length of the event. - * - * @return the length of the event - */ - public int getLength() { - return fLength; - } - - /** - * Returns the text of the event. - * - * @return the text of the event - */ - public String getText() { - return fText; - } - - /** - * Returns the text replaced by this event. - * - * @return the text replaced by this event - */ - public String getReplacedText() { - return fReplacedText; - } - - /** - * Returns the corresponding document event that caused the viewer change - * - * @return the corresponding document event, <code>null</code> if a visual change only - */ - public DocumentEvent getDocumentEvent() { - return fDocumentEvent; - } - - /** - * Returns the viewer's redraw state. - * - * @return <code>true</code> if the viewer's redraw state is <code>true</code> - * @since 2.0 - */ - public boolean getViewerRedrawState() { - return fViewerRedrawState; - } -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextPresentation.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextPresentation.java deleted file mode 100644 index fc26ba283..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextPresentation.java +++ /dev/null @@ -1,734 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.NoSuchElementException; - -import org.eclipse.fx.ui.controls.styledtext.StyleRange; -import org.eclipse.fx.ui.controls.styledtext.StyledTextArea; - - -/** - * Describes the presentation styles for a section of an indexed text such as a - * document or string. A text presentation defines a default style for the whole - * section and in addition style differences for individual subsections. Text - * presentations can be narrowed down to a particular result window. All methods - * are result window aware, i.e. ranges outside the result window are always - * ignored. - * <p> - * All iterators provided by a text presentation assume that they enumerate non - * overlapping, consecutive ranges inside the default range. Thus, all these - * iterators do not include the default range. The default style range must be - * explicitly asked for using <code>getDefaultStyleRange</code>. - */ -public class TextPresentation { - - /** - * Applies the given presentation to the given text widget. Helper method. - * - * @param presentation the style information - * @param text the widget to which to apply the style information - * @since 2.0 - */ - public static void applyTextPresentation(TextPresentation presentation, StyledTextArea text) { - - StyleRange[] ranges= new StyleRange[presentation.getDenumerableRanges()]; - - int i= 0; - Iterator e= presentation.getAllStyleRangeIterator(); - while (e.hasNext()) - ranges[i++]= (StyleRange) e.next(); - - text.setStyleRanges(ranges); - } - - - - - /** - * Enumerates all the <code>StyleRange</code>s included in the presentation. - */ - class FilterIterator implements Iterator { - - /** The index of the next style range to be enumerated */ - protected int fIndex; - /** The upper bound of the indices of style ranges to be enumerated */ - protected int fLength; - /** Indicates whether ranges similar to the default range should be enumerated */ - protected boolean fSkipDefaults; - /** The result window */ - protected IRegion fWindow; - - /** - * <code>skipDefaults</code> tells the enumeration to skip all those style ranges - * which define the same style as the presentation's default style range. - * - * @param skipDefaults <code>false</code> if ranges similar to the default range should be enumerated - */ - protected FilterIterator(boolean skipDefaults) { - - fSkipDefaults= skipDefaults; - - fWindow= fResultWindow; - fIndex= getFirstIndexInWindow(fWindow); - fLength= getFirstIndexAfterWindow(fWindow); - - if (fSkipDefaults) - computeIndex(); - } - - /* - * @see Iterator#next() - */ - public Object next() { - try { - StyleRange r= (StyleRange) fRanges.get(fIndex++); - return createWindowRelativeRange(fWindow, r); - } catch (ArrayIndexOutOfBoundsException x) { - throw new NoSuchElementException(); - } finally { - if (fSkipDefaults) - computeIndex(); - } - } - - /* - * @see Iterator#hasNext() - */ - public boolean hasNext() { - return fIndex < fLength; - } - - /* - * @see Iterator#remove() - */ - public void remove() { - throw new UnsupportedOperationException(); - } - - /** - * Returns whether the given object should be skipped. - * - * @param o the object to be checked - * @return <code>true</code> if the object should be skipped by the iterator - */ - protected boolean skip(Object o) { - StyleRange r= (StyleRange) o; - return r.similarTo(fDefaultRange); - } - - /** - * Computes the index of the styled range that is the next to be enumerated. - */ - protected void computeIndex() { - while (fIndex < fLength && skip(fRanges.get(fIndex))) - ++ fIndex; - } - } - - /** The style information for the range covered by the whole presentation */ - private StyleRange fDefaultRange; - /** The member ranges of the presentation */ - private ArrayList fRanges; - /** A clipping region against which the presentation can be clipped when asked for results */ - private IRegion fResultWindow; - /** - * The optional extent for this presentation. - * @since 3.0 - */ - private IRegion fExtent; - - - /** - * Creates a new empty text presentation. - */ - public TextPresentation() { - fRanges= new ArrayList(50); - } - - /** - * Creates a new empty text presentation. <code>sizeHint</code> tells the expected size of this - * presentation. - * - * @param sizeHint the expected size of this presentation, must be positive - */ - public TextPresentation(int sizeHint) { - Assert.isTrue(sizeHint > 0); - fRanges= new ArrayList(sizeHint); - } - - /** - * Creates a new empty text presentation with the given extent. <code>sizeHint</code> tells the - * expected size of this presentation. - * - * @param extent the extent of the created <code>TextPresentation</code> - * @param sizeHint the expected size of this presentation, must be positive - * @since 3.0 - */ - public TextPresentation(IRegion extent, int sizeHint) { - this(sizeHint); - Assert.isNotNull(extent); - fExtent= extent; - } - - /** - * Sets the result window for this presentation. When dealing with - * this presentation all ranges which are outside the result window - * are ignored. For example, the size of the presentation is 0 - * when there is no range inside the window even if there are ranges - * outside the window. All methods are aware of the result window. - * - * @param resultWindow the result window - */ - public void setResultWindow(IRegion resultWindow) { - fResultWindow= resultWindow; - } - - /** - * Set the default style range of this presentation. - * The default style range defines the overall area covered - * by this presentation and its style information. - * - * @param range the range describing the default region - */ - public void setDefaultStyleRange(StyleRange range) { - fDefaultRange= range; - } - - /** - * Returns this presentation's default style range. The returned <code>StyleRange</code> - * is relative to the start of the result window. - * - * @return this presentation's default style range - */ - public StyleRange getDefaultStyleRange() { - StyleRange range= createWindowRelativeRange(fResultWindow, fDefaultRange); - if (range == null) - return null; - return (StyleRange)range.clone(); - - } - - /** - * Add the given range to the presentation. The range must be a - * subrange of the presentation's default range. - * - * @param range the range to be added - */ - public void addStyleRange(StyleRange range) { - checkConsistency(range); - fRanges.add(range); - } - - /** - * Replaces the given range in this presentation. The range must be a - * subrange of the presentation's default range. - * - * @param range the range to be added - * @since 3.0 - */ - public void replaceStyleRange(StyleRange range) { - applyStyleRange(range, false); - } - - /** - * Merges the given range into this presentation. The range must be a - * subrange of the presentation's default range. - * - * @param range the range to be added - * @since 3.0 - */ - public void mergeStyleRange(StyleRange range) { - applyStyleRange(range, true); - } - - /** - * Applies the given range to this presentation. The range must be a - * subrange of the presentation's default range. - * - * @param range the range to be added - * @param merge <code>true</code> if the style should be merged instead of replaced - * @since 3.0 - */ - private void applyStyleRange(StyleRange range, boolean merge) { - if (range.length == 0) - return; - - checkConsistency(range); - - int start= range.start; - int length= range.length; - int end= start + length; - - if (fRanges.size() == 0) { - StyleRange defaultRange= getDefaultStyleRange(); - if (defaultRange == null) - defaultRange= range; - - defaultRange.start= start; - defaultRange.length= length; - applyStyle(range, defaultRange, merge); - fRanges.add(defaultRange); - } else { - IRegion rangeRegion= new Region(start, length); - int first= getFirstIndexInWindow(rangeRegion); - - if (first == fRanges.size()) { - StyleRange defaultRange= getDefaultStyleRange(); - if (defaultRange == null) - defaultRange= range; - defaultRange.start= start; - defaultRange.length= length; - applyStyle(range, defaultRange, merge); - fRanges.add(defaultRange); - return; - } - - int last= getFirstIndexAfterWindow(rangeRegion); - for (int i= first; i < last && length > 0; i++) { - - StyleRange current= (StyleRange)fRanges.get(i); - int currentStart= current.start; - int currentEnd= currentStart + current.length; - - if (end <= currentStart) { - fRanges.add(i, range); - return; - } - - if (start >= currentEnd) - continue; - - StyleRange currentCopy= null; - if (end < currentEnd) - currentCopy= (StyleRange)current.clone(); - - if (start < currentStart) { - // Apply style to new default range and add it - StyleRange defaultRange= getDefaultStyleRange(); - if (defaultRange == null) - defaultRange= new StyleRange((String)null); - - defaultRange.start= start; - defaultRange.length= currentStart - start; - applyStyle(range, defaultRange, merge); - fRanges.add(i, defaultRange); - i++; last++; - - - // Apply style to first part of current range - current.length= Math.min(end, currentEnd) - currentStart; - applyStyle(range, current, merge); - } - - if (start >= currentStart) { - // Shorten the current range - current.length= start - currentStart; - - // Apply the style to the rest of the current range and add it - if (current.length > 0) { - current= (StyleRange)current.clone(); - i++; last++; - fRanges.add(i, current); - } - applyStyle(range, current, merge); - current.start= start; - current.length= Math.min(end, currentEnd) - start; - } - - if (end < currentEnd && currentCopy != null) { - // Add rest of current range - currentCopy.start= end; - currentCopy.length= currentEnd - end; - i++; last++; - fRanges.add(i, currentCopy); - } - - // Update range - range.start= currentEnd; - range.length= Math.max(end - currentEnd, 0); - start= range.start; - length= range.length; - } - if (length > 0) { - // Apply style to new default range and add it - StyleRange defaultRange= getDefaultStyleRange(); - if (defaultRange == null) - defaultRange= range; - defaultRange.start= start; - defaultRange.length= end - start; - applyStyle(range, defaultRange, merge); - fRanges.add(last, defaultRange); - } - } - } - - /** - * Replaces the given ranges in this presentation. Each range must be a - * subrange of the presentation's default range. The ranges must be ordered - * by increasing offset and must not overlap (but may be adjacent). - * - * @param ranges the ranges to be added - * @since 3.0 - */ - public void replaceStyleRanges(StyleRange[] ranges) { - applyStyleRanges(ranges, false); - } - - /** - * Merges the given ranges into this presentation. Each range must be a - * subrange of the presentation's default range. The ranges must be ordered - * by increasing offset and must not overlap (but may be adjacent). - * - * @param ranges the ranges to be added - * @since 3.0 - */ - public void mergeStyleRanges(StyleRange[] ranges) { - applyStyleRanges(ranges, true); - } - - /** - * Applies the given ranges to this presentation. Each range must be a - * subrange of the presentation's default range. The ranges must be ordered - * by increasing offset and must not overlap (but may be adjacent). - * - * @param ranges the ranges to be added - * @param merge <code>true</code> if the style should be merged instead of replaced - * @since 3.0 - */ - private void applyStyleRanges(StyleRange[] ranges, boolean merge) { - int j= 0; - ArrayList oldRanges= fRanges; - ArrayList newRanges= new ArrayList(2*ranges.length + oldRanges.size()); - for (int i= 0, n= ranges.length; i < n; i++) { - StyleRange range= ranges[i]; - fRanges= oldRanges; // for getFirstIndexAfterWindow(...) - for (int m= getFirstIndexAfterWindow(new Region(range.start, range.length)); j < m; j++) - newRanges.add(oldRanges.get(j)); - fRanges= newRanges; // for mergeStyleRange(...) - applyStyleRange(range, merge); - } - for (int m= oldRanges.size(); j < m; j++) - newRanges.add(oldRanges.get(j)); - fRanges= newRanges; - } - - /** - * Applies the template's style to the target. - * - * @param template the style range to be used as template - * @param target the style range to which to apply the template - * @param merge <code>true</code> if the style should be merged instead of replaced - * @since 3.0 - */ - private void applyStyle(StyleRange template, StyleRange target, boolean merge) { - if (merge) { - if (template.font != null) - target.font= template.font; - target.fontStyle|= template.fontStyle; - -//TODO No metrics -// if (template.metrics != null) -// target.metrics= template.metrics; - target.stylename = template.stylename; - target.decorationStyleClasses = template.decorationStyleClasses; - - if (template.foreground != null || template.underlineStyle == StyleRange.UNDERLINE_LINK) - target.foreground= template.foreground; - if (template.background != null) - target.background= template.background; - - target.strikeout|= template.strikeout; - if (template.strikeoutColor != null) - target.strikeoutColor= template.strikeoutColor; - - target.underline|= template.underline; - if (template.underlineStyle != StyleRange.NONE && target.underlineStyle != StyleRange.UNDERLINE_LINK) - target.underlineStyle= template.underlineStyle; - - if (template.underlineColor != null) - target.underlineColor= template.underlineColor; - - if (template.borderStyle != StyleRange.NONE) - target.borderStyle= template.borderStyle; - if (template.borderColor != null) - target.borderColor= template.borderColor; - - } else { - target.stylename = template.stylename; - target.font= template.font; - target.fontStyle= template.fontStyle; -// target.metrics= template.metrics; - target.foreground= template.foreground; - target.background= template.background; - target.strikeout= template.strikeout; - target.strikeoutColor= template.strikeoutColor; - target.underline= template.underline; - target.underlineStyle= template.underlineStyle; - target.underlineColor= template.underlineColor; - target.borderStyle= template.borderStyle; - target.borderColor= template.borderColor; - } - } - - /** - * Checks whether the given range is a subrange of the presentation's - * default style range. - * - * @param range the range to be checked - * @exception IllegalArgumentException if range is not a subrange of the presentation's default range - */ - private void checkConsistency(StyleRange range) { - - if (range == null) - throw new IllegalArgumentException(); - - if (fDefaultRange != null) { - - if (range.start < fDefaultRange.start) - range.start= fDefaultRange.start; - - int defaultEnd= fDefaultRange.start + fDefaultRange.length; - int end= range.start + range.length; - if (end > defaultEnd) - range.length -= (end - defaultEnd); - } - } - - /** - * Returns the index of the first range which overlaps with the - * specified window. - * - * @param window the window to be used for searching - * @return the index of the first range overlapping with the window - */ - private int getFirstIndexInWindow(IRegion window) { - if (window != null) { - int start= window.getOffset(); - int i= -1, j= fRanges.size(); - while (j - i > 1) { - int k= (i + j) >> 1; - StyleRange r= (StyleRange) fRanges.get(k); - if (r.start + r.length > start) - j= k; - else - i= k; - } - return j; - } - return 0; - } - - /** - * Returns the index of the first range which comes after the specified window and does - * not overlap with this window. - * - * @param window the window to be used for searching - * @return the index of the first range behind the window and not overlapping with the window - */ - private int getFirstIndexAfterWindow(IRegion window) { - if (window != null) { - int end= window.getOffset() + window.getLength(); - int i= -1, j= fRanges.size(); - while (j - i > 1) { - int k= (i + j) >> 1; - StyleRange r= (StyleRange) fRanges.get(k); - if (r.start < end) - i= k; - else - j= k; - } - return j; - } - return fRanges.size(); - } - - /** - * Returns a style range which is relative to the specified window and - * appropriately clipped if necessary. The original style range is not - * modified. - * - * @param window the reference window - * @param range the absolute range - * @return the window relative range based on the absolute range - */ - private StyleRange createWindowRelativeRange(IRegion window, StyleRange range) { - if (window == null || range == null) - return range; - - int start= range.start - window.getOffset(); - if (start < 0) - start= 0; - - int rangeEnd= range.start + range.length; - int windowEnd= window.getOffset() + window.getLength(); - int end= (rangeEnd > windowEnd ? windowEnd : rangeEnd); - end -= window.getOffset(); - - StyleRange newRange= (StyleRange) range.clone(); - newRange.start= start; - newRange.length= end - start; - return newRange; - } - - /** - * Returns the region which is relative to the specified window and - * appropriately clipped if necessary. - * - * @param coverage the absolute coverage - * @return the window relative region based on the absolute coverage - * @since 3.0 - */ - private IRegion createWindowRelativeRegion(IRegion coverage) { - if (fResultWindow == null || coverage == null) - return coverage; - - int start= coverage.getOffset() - fResultWindow.getOffset(); - if (start < 0) - start= 0; - - int rangeEnd= coverage.getOffset() + coverage.getLength(); - int windowEnd= fResultWindow.getOffset() + fResultWindow.getLength(); - int end= (rangeEnd > windowEnd ? windowEnd : rangeEnd); - end -= fResultWindow.getOffset(); - - return new Region(start, end - start); - } - - /** - * Returns an iterator which enumerates all style ranged which define a style - * different from the presentation's default style range. The default style range - * is not enumerated. - * - * @return a style range iterator - */ - public Iterator getNonDefaultStyleRangeIterator() { - return new FilterIterator(fDefaultRange != null); - } - - /** - * Returns an iterator which enumerates all style ranges of this presentation - * except the default style range. The returned <code>StyleRange</code>s - * are relative to the start of the presentation's result window. - * - * @return a style range iterator - */ - public Iterator getAllStyleRangeIterator() { - return new FilterIterator(false); - } - - /** - * Returns whether this collection contains any style range including - * the default style range. - * - * @return <code>true</code> if there is no style range in this presentation - */ - public boolean isEmpty() { - return (fDefaultRange == null && getDenumerableRanges() == 0); - } - - /** - * Returns the number of style ranges in the presentation not counting the default - * style range. - * - * @return the number of style ranges in the presentation excluding the default style range - */ - public int getDenumerableRanges() { - int size= getFirstIndexAfterWindow(fResultWindow) - getFirstIndexInWindow(fResultWindow); - return (size < 0 ? 0 : size); - } - - /** - * Returns the style range with the smallest offset ignoring the default style range or null - * if the presentation is empty. - * - * @return the style range with the smallest offset different from the default style range - */ - public StyleRange getFirstStyleRange() { - try { - - StyleRange range= (StyleRange) fRanges.get(getFirstIndexInWindow(fResultWindow)); - return createWindowRelativeRange(fResultWindow, range); - - } catch (NoSuchElementException x) { - } catch (IndexOutOfBoundsException x) { - } - - return null; - } - - /** - * Returns the style range with the highest offset ignoring the default style range. - * - * @return the style range with the highest offset different from the default style range - */ - public StyleRange getLastStyleRange() { - try { - - StyleRange range= (StyleRange) fRanges.get(getFirstIndexAfterWindow(fResultWindow) - 1); - return createWindowRelativeRange(fResultWindow, range); - - } catch (NoSuchElementException x) { - return null; - } catch (IndexOutOfBoundsException x) { - return null; - } - } - - /** - * Returns the coverage of this presentation as clipped by the presentation's - * result window. - * - * @return the coverage of this presentation - */ - public IRegion getCoverage() { - - if (fDefaultRange != null) { - StyleRange range= getDefaultStyleRange(); - return new Region(range.start, range.length); - } - - StyleRange first= getFirstStyleRange(); - StyleRange last= getLastStyleRange(); - - if (first == null || last == null) - return null; - - return new Region(first.start, last.start - first. start + last.length); - } - - /** - * Returns the extent of this presentation clipped by the - * presentation's result window. - * - * @return the clipped extent - * @since 3.0 - */ - public IRegion getExtent() { - if (fExtent != null) - return createWindowRelativeRegion(fExtent); - return getCoverage(); - } - - /** - * Clears this presentation by resetting all applied changes. - * @since 2.0 - */ - public void clear() { - fDefaultRange= null; - fResultWindow= null; - fRanges.clear(); - } - - -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextViewer.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextViewer.java deleted file mode 100644 index 513c96eb6..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextViewer.java +++ /dev/null @@ -1,765 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Tom Eicher (Avaloq Evolution AG) - block selection mode - * Markus Schorn <markus.schorn@windriver.com> - shift with trailing empty line - https://bugs.eclipse.org/325438 - *******************************************************************************/ -package org.eclipse.jface.text; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javafx.scene.layout.AnchorPane; - -import org.eclipse.fx.ui.controls.styledtext.StyleRange; -import org.eclipse.fx.ui.controls.styledtext.StyledTextArea; -import org.eclipse.jface.text.projection.ChildDocument; -import org.eclipse.jface.text.projection.ChildDocumentManager; -import org.eclipse.jface.viewers.Viewer; - -public class TextViewer extends Viewer implements - ITextViewer, ITextViewerExtension, ITextViewerExtension2, ITextViewerExtension4, ITextViewerExtension6, ITextViewerExtension7, ITextViewerExtension8 - /*, - IEditingSupportRegistry, ITextOperationTarget, ITextOperationTargetExtension, - IWidgetTokenOwner, IWidgetTokenOwnerExtension, IPostSelectionProvider*/ { - private StyledTextArea fTextWidget; - private IDocument fVisibleDocument; - private VisibleDocumentListener fVisibleDocumentListener= new VisibleDocumentListener(); - private ISlaveDocumentManager fSlaveDocumentManager; - private IDocumentInformationMapping fInformationMapping; - private IDocumentAdapter fDocumentAdapter; - private WidgetCommand fWidgetCommand= new WidgetCommand(); - protected List fTextListeners; - private int fRedrawCounter= 0; - private IRegion fLastSentSelectionChange; - private String fPartitioning; - private IDocument fDocument; - private boolean fReplaceTextPresentation; - private DocumentRewriteSessionListener fDocumentRewriteSessionListener= new DocumentRewriteSessionListener(); - private IRewriteTarget fRewriteTarget; - private ViewerState fViewerState; - private List fTextInputListeners; - protected Position fMarkPosition; - private final String MARK_POSITION_CATEGORY="__mark_category_" + hashCode(); //$NON-NLS-1$ - private final IPositionUpdater fMarkPositionUpdater= new DefaultPositionUpdater(MARK_POSITION_CATEGORY); - private List fTextPresentationListeners; - - public TextViewer() { - createControl(); - } - - protected void createControl() { - fTextWidget = createTextWidget(); - AnchorPane.setLeftAnchor(fTextWidget, 0.0); - AnchorPane.setRightAnchor(fTextWidget, 0.0); - AnchorPane.setTopAnchor(fTextWidget, 0.0); - AnchorPane.setBottomAnchor(fTextWidget, 0.0); - getChildren().add(fTextWidget); - } - - public StyledTextArea getTextWidget() { - return fTextWidget; - } - - protected StyledTextArea createTextWidget() { - StyledTextArea styledText= new StyledTextArea(); - styledText.setLineRulerVisible(true); -// styledText.setLeftMargin(Math.max(styledText.getLeftMargin(), 2)); - return styledText; - } - - public void setInput(Object input) { - - IDocument document= null; - if (input instanceof IDocument) - document= (IDocument) input; - - setDocument(document); - } - - public Object getInput() { - return getDocument(); - } - - public void setDocumentPartitioning(String partitioning) { - fPartitioning= partitioning; - } - - /** - * Sets this viewer's visible document. The visible document represents the - * visible region of the viewer's input document. - * - * @param document the visible document - */ - protected void setVisibleDocument(IDocument document) { - if (fVisibleDocument == document && fVisibleDocument instanceof ChildDocument) { - // optimization for new child documents - return; - } - - if (fVisibleDocument != null) { - if (fVisibleDocumentListener != null) - fVisibleDocument.removeDocumentListener(fVisibleDocumentListener); - if (fVisibleDocument != document) - freeSlaveDocument(fVisibleDocument); - } - - fVisibleDocument= document; - initializeDocumentInformationMapping(fVisibleDocument); - - initializeWidgetContents(); - -//TODO needs porting -// fFindReplaceDocumentAdapter= null; - if (fVisibleDocument != null && fVisibleDocumentListener != null) - fVisibleDocument.addDocumentListener(fVisibleDocumentListener); - } - - public IDocument getDocument() { - return fDocument; - } - - public void setDocument(IDocument document) { - fReplaceTextPresentation= true; - fireInputDocumentAboutToBeChanged(fDocument, document); - - IDocument oldDocument= fDocument; - fDocument= document; - - setVisibleDocument(fDocument); -//TODO needs porting -// resetPlugins(); - inputChanged(fDocument, oldDocument); - - fireInputDocumentChanged(oldDocument, fDocument); - fLastSentSelectionChange= null; - fReplaceTextPresentation= false; - } - - public void setDocument(IDocument document, int modelRangeOffset, int modelRangeLength) { - - fReplaceTextPresentation= true; - fireInputDocumentAboutToBeChanged(fDocument, document); - - IDocument oldDocument= fDocument; - fDocument= document; - - try { - - IDocument slaveDocument= createSlaveDocument(document); - updateSlaveDocument(slaveDocument, modelRangeOffset, modelRangeLength); - setVisibleDocument(slaveDocument); - - } catch (BadLocationException x) { -// throw new IllegalArgumentException(JFaceTextMessages.getString("TextViewer.error.invalid_visible_region_1")); //$NON-NLS-1$ - throw new IllegalArgumentException(); - } - - //TODO needs porting -// resetPlugins(); - inputChanged(fDocument, oldDocument); - - fireInputDocumentChanged(oldDocument, fDocument); - fLastSentSelectionChange= null; - fReplaceTextPresentation= false; - } - - /** - * Creates a slave document for the given document if there is a slave document manager - * associated with this viewer. - * - * @param document the master document - * @return the newly created slave document - * @since 2.1 - */ - protected IDocument createSlaveDocument(IDocument document) { - ISlaveDocumentManager manager= getSlaveDocumentManager(); - if (manager != null) { - if (manager.isSlaveDocument(document)) - return document; - return manager.createSlaveDocument(document); - } - return document; - } - - /** - * Updates the given slave document to show the specified range of its master document. - * - * @param slaveDocument the slave document - * @param modelRangeOffset the offset of the master document range - * @param modelRangeLength the length of the master document range - * @return <code>true</code> if the slave has been adapted successfully - * @throws BadLocationException in case the specified range is not valid in the master document - * @since 3.0 - */ - protected boolean updateSlaveDocument(IDocument slaveDocument, int modelRangeOffset, int modelRangeLength) throws BadLocationException { - return updateVisibleDocument(slaveDocument, modelRangeOffset, modelRangeLength); - } - - /** - * Sets the given slave document to the specified range of its master document. - * - * @param visibleDocument the slave document - * @param visibleRegionOffset the offset of the master document range - * @param visibleRegionLength the length of the master document range - * @return <code>true</code> if the slave has been adapted successfully - * @throws BadLocationException in case the specified range is not valid in the master document - * @since 2.1 - * @deprecated use <code>updateSlaveDocument</code> instead - */ - protected boolean updateVisibleDocument(IDocument visibleDocument, int visibleRegionOffset, int visibleRegionLength) throws BadLocationException { - if (visibleDocument instanceof ChildDocument) { - ChildDocument childDocument= (ChildDocument) visibleDocument; - - IDocument document= childDocument.getParentDocument(); - int line= document.getLineOfOffset(visibleRegionOffset); - int offset= document.getLineOffset(line); - int length= (visibleRegionOffset - offset) + visibleRegionLength; - - Position parentRange= childDocument.getParentDocumentRange(); - if (offset != parentRange.getOffset() || length != parentRange.getLength()) { - childDocument.setParentDocumentRange(offset, length); - return true; - } - } - return false; - } - - public IRegion getVisibleRegion() { - - IDocument document= getVisibleDocument(); - if (document instanceof ChildDocument) { - Position p= ((ChildDocument) document).getParentDocumentRange(); - return new Region(p.getOffset(), p.getLength()); - } - - return new Region(0, document == null ? 0 : document.getLength()); - } - - protected void fireInputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { - List listener= fTextInputListeners; - if (listener != null) { - for (int i= 0; i < listener.size(); i++) { - ITextInputListener l= (ITextInputListener) listener.get(i); - l.inputDocumentAboutToBeChanged(oldInput, newInput); - } - } - } - - protected void fireInputDocumentChanged(IDocument oldInput, IDocument newInput) { - List listener= fTextInputListeners; - if (listener != null) { - for (int i= 0; i < listener.size(); i++) { - ITextInputListener l= (ITextInputListener) listener.get(i); - l.inputDocumentChanged(oldInput, newInput); - } - } - } - - protected IDocument getVisibleDocument() { - return fVisibleDocument; - } - - protected void freeSlaveDocument(IDocument slave) { - ISlaveDocumentManager manager= getSlaveDocumentManager(); - if (manager != null && manager.isSlaveDocument(slave)) - manager.freeSlaveDocument(slave); - } - - protected ISlaveDocumentManager getSlaveDocumentManager() { - if (fSlaveDocumentManager == null) - fSlaveDocumentManager= createSlaveDocumentManager(); - return fSlaveDocumentManager; - } - - protected ISlaveDocumentManager createSlaveDocumentManager() { - return new ChildDocumentManager(); - } - - protected void initializeDocumentInformationMapping(IDocument visibleDocument) { - ISlaveDocumentManager manager= getSlaveDocumentManager(); - fInformationMapping= manager == null ? null : manager.createMasterSlaveMapping(visibleDocument); - } - - protected void inputChanged(Object newInput, Object oldInput) { - - IDocument oldDocument= (IDocument) oldInput; - if (oldDocument != null) { - - if (fMarkPosition != null && !fMarkPosition.isDeleted()) - oldDocument.removePosition(fMarkPosition); - - try { - oldDocument.removePositionUpdater(fMarkPositionUpdater); - oldDocument.removePositionCategory(MARK_POSITION_CATEGORY); - - } catch (BadPositionCategoryException e) { - } - } - - fMarkPosition= null; - - if (oldDocument instanceof IDocumentExtension4) { - IDocumentExtension4 document= (IDocumentExtension4) oldDocument; - document.removeDocumentRewriteSessionListener(fDocumentRewriteSessionListener); - } - -// super.inputChanged(newInput, oldInput); - - if (newInput instanceof IDocumentExtension4) { - IDocumentExtension4 document= (IDocumentExtension4) newInput; - document.addDocumentRewriteSessionListener(fDocumentRewriteSessionListener); - } - - IDocument newDocument= (IDocument) newInput; - if (newDocument != null) { - newDocument.addPositionCategory(MARK_POSITION_CATEGORY); - newDocument.addPositionUpdater(fMarkPositionUpdater); - } - } - - private void initializeWidgetContents() { - - if (fTextWidget != null && fVisibleDocument != null) { - - // set widget content - if (fDocumentAdapter == null) - fDocumentAdapter= createDocumentAdapter(); - - fDocumentAdapter.setDocument(fVisibleDocument); - fTextWidget.setContent(fDocumentAdapter); - System.err.println(fDocumentAdapter); - - // invalidate presentation - invalidateTextPresentation(); - } - } - - protected IDocumentAdapter createDocumentAdapter() { - return new DefaultDocumentAdapter(); - } - - public final void invalidateTextPresentation() { - if (fVisibleDocument != null) { - fWidgetCommand.event= null; - fWidgetCommand.start= 0; - fWidgetCommand.length= fVisibleDocument.getLength(); - fWidgetCommand.text= fVisibleDocument.get(); - updateTextListeners(fWidgetCommand); - } - } - - protected void updateTextListeners(WidgetCommand cmd) { - List textListeners= fTextListeners; - if (textListeners != null) { - textListeners= new ArrayList(textListeners); - DocumentEvent event= cmd.event; - if (event instanceof SlaveDocumentEvent) - event= ((SlaveDocumentEvent) event).getMasterEvent(); - - TextEvent e= new TextEvent(cmd.start, cmd.length, cmd.text, cmd.preservedText, event, redraws()); - for (int i= 0; i < textListeners.size(); i++) { - ITextListener l= (ITextListener) textListeners.get(i); - l.textChanged(e); - } - } - } - - protected final boolean redraws() { - return fRedrawCounter <= 0; - } - - protected void handleVisibleDocumentAboutToBeChanged(DocumentEvent event) { - } - - protected void handleVisibleDocumentChanged(DocumentEvent event) { - } - - public void addTextListener(ITextListener listener) { - - Assert.isNotNull(listener); - - if (fTextListeners == null) - fTextListeners= new ArrayList(); - - if (!fTextListeners.contains(listener)) - fTextListeners.add(listener); - } - - public void removeTextListener(ITextListener listener) { - Assert.isNotNull(listener); - - if (fTextListeners != null) { - fTextListeners.remove(listener); - if (fTextListeners.size() == 0) - fTextListeners= null; - } - } - - public void addTextInputListener(ITextInputListener listener) { - - Assert.isNotNull(listener); - - if (fTextInputListeners == null) - fTextInputListeners= new ArrayList(); - - if (!fTextInputListeners.contains(listener)) - fTextInputListeners.add(listener); - } - - public void removeTextInputListener(ITextInputListener listener) { - - Assert.isNotNull(listener); - - if (fTextInputListeners != null) { - fTextInputListeners.remove(listener); - if (fTextInputListeners.size() == 0) - fTextInputListeners= null; - } - } - - public void changeTextPresentation(TextPresentation presentation, boolean controlRedraw) { - - if (presentation == null || !redraws()) - return; - - if (fTextWidget == null) - return; - - - /* - * Call registered text presentation listeners - * and let them apply their presentation. - */ - if (fTextPresentationListeners != null) { - ArrayList listeners= new ArrayList(fTextPresentationListeners); - for (int i= 0, size= listeners.size(); i < size; i++) { - ITextPresentationListener listener= (ITextPresentationListener)listeners.get(i); - listener.applyTextPresentation(presentation); - } - } - - if (presentation.isEmpty()) - return; - -// if (controlRedraw) -// fTextWidget.setRedraw(false); - - if (fReplaceTextPresentation) - applyTextPresentation(presentation); - else - addPresentation(presentation); - -// if (controlRedraw) -// fTextWidget.setRedraw(true); - } - - private void addPresentation(TextPresentation presentation) { - - StyleRange range= presentation.getDefaultStyleRange(); - if (range != null) { - - range= modelStyleRange2WidgetStyleRange(range); - if (range != null) - fTextWidget.setStyleRange(range); - - ArrayList ranges= new ArrayList(presentation.getDenumerableRanges()); - Iterator e= presentation.getNonDefaultStyleRangeIterator(); - while (e.hasNext()) { - range= (StyleRange) e.next(); - range= modelStyleRange2WidgetStyleRange(range); - if (range != null) - ranges.add(range); - } - - if (!ranges.isEmpty()) - fTextWidget.replaceStyleRanges(0, 0, (StyleRange[])ranges.toArray(new StyleRange[ranges.size()])); - - } else { - IRegion region= modelRange2WidgetRange(presentation.getCoverage()); - if (region == null) - return; - - List list= new ArrayList(presentation.getDenumerableRanges()); - Iterator e= presentation.getAllStyleRangeIterator(); - while (e.hasNext()) { - range= (StyleRange) e.next(); - range= modelStyleRange2WidgetStyleRange(range); - if (range != null) - list.add(range); - } - - if (!list.isEmpty()) { - StyleRange[] ranges= new StyleRange[list.size()]; - list.toArray(ranges); - fTextWidget.replaceStyleRanges(region.getOffset(), region.getLength(), ranges); - } - } - } - - private void applyTextPresentation(TextPresentation presentation) { - List list= new ArrayList(presentation.getDenumerableRanges()); - Iterator e= presentation.getAllStyleRangeIterator(); - while (e.hasNext()) { - StyleRange range= (StyleRange) e.next(); - range= modelStyleRange2WidgetStyleRange(range); - if (range != null) - list.add(range); - } - - if (!list.isEmpty()) { - StyleRange[] ranges= new StyleRange[list.size()]; - list.toArray(ranges); - fTextWidget.setStyleRanges(ranges); - } - } - - protected StyleRange modelStyleRange2WidgetStyleRange(StyleRange range) { - IRegion region= modelRange2WidgetRange(new Region(range.start, range.length)); - if (region != null) { - StyleRange result= (StyleRange) range.clone(); - result.start= region.getOffset(); - result.length= region.getLength(); - return result; - } - return null; - } - - public IRegion modelRange2WidgetRange(IRegion modelRange) { - if (fInformationMapping == null) - return modelRange; - - try { - - if (modelRange.getLength() < 0) { - Region reversed= new Region(modelRange.getOffset() + modelRange.getLength(), -modelRange.getLength()); - IRegion result= fInformationMapping.toImageRegion(reversed); - if (result != null) - return new Region(result.getOffset() + result.getLength(), -result.getLength()); - } - return fInformationMapping.toImageRegion(modelRange); - - } catch (BadLocationException x) { - } - - return null; - } - - public IRewriteTarget getRewriteTarget() { - if (fRewriteTarget == null) - fRewriteTarget= new RewriteTarget(); - return fRewriteTarget; - } - - public final void setRedraw(boolean redraw) { -//TODO needs porting -// setRedraw(redraw, -1); - } - - class VisibleDocumentListener implements IDocumentListener { - - public void documentAboutToBeChanged(DocumentEvent e) { - if (e.getDocument() == getVisibleDocument()) - fWidgetCommand.setEvent(e); - handleVisibleDocumentAboutToBeChanged(e); - } - - public void documentChanged(DocumentEvent e) { - if (fWidgetCommand.event == e) - updateTextListeners(fWidgetCommand); - fLastSentSelectionChange= null; - handleVisibleDocumentChanged(e); - } - } - - /** - * Represents a replace command that brings the text viewer's text widget - * back in synchronization with text viewer's document after the document - * has been changed. - */ - protected class WidgetCommand { - - /** The document event encapsulated by this command. */ - public DocumentEvent event; - /** The start of the event. */ - public int start; - /** The length of the event. */ - public int length; - /** The inserted and replaced text segments of <code>event</code>. */ - public String text; - /** The replaced text segments of <code>event</code>. */ - public String preservedText; - - /** - * Translates a document event into the presentation coordinates of this text viewer. - * - * @param e the event to be translated - */ - public void setEvent(DocumentEvent e) { - - event= e; - - start= e.getOffset(); - length= e.getLength(); - text= e.getText(); - - if (length != 0) { - try { - - if (e instanceof SlaveDocumentEvent) { - SlaveDocumentEvent slave= (SlaveDocumentEvent) e; - DocumentEvent master= slave.getMasterEvent(); - if (master != null) - preservedText= master.getDocument().get(master.getOffset(), master.getLength()); - } else { - preservedText= e.getDocument().get(e.getOffset(), e.getLength()); - } - - } catch (BadLocationException x) { - preservedText= null; -// if (TRACE_ERRORS) -// System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.WidgetCommand.setEvent")); //$NON-NLS-1$ - } - } else - preservedText= null; - } - } - - private class DocumentRewriteSessionListener implements IDocumentRewriteSessionListener { - - /* - * @see org.eclipse.jface.text.IDocumentRewriteSessionListener#documentRewriteSessionChanged(org.eclipse.jface.text.DocumentRewriteSessionEvent) - */ - public void documentRewriteSessionChanged(DocumentRewriteSessionEvent event) { - IRewriteTarget target= TextViewer.this.getRewriteTarget(); - final boolean toggleRedraw; -// if (REDRAW_BUG_158746) -// toggleRedraw= true; -// else - toggleRedraw= event.getSession().getSessionType() != DocumentRewriteSessionType.UNRESTRICTED_SMALL; - final boolean viewportStabilize= !toggleRedraw; - if (DocumentRewriteSessionEvent.SESSION_START == event.getChangeType()) { - if (toggleRedraw) - target.setRedraw(false); - target.beginCompoundChange(); - if (viewportStabilize && fViewerState == null) - fViewerState= new ViewerState(); - } else if (DocumentRewriteSessionEvent.SESSION_STOP == event.getChangeType()) { - if (viewportStabilize && fViewerState != null) { - fViewerState.restore(true); - fViewerState= null; - } - target.endCompoundChange(); - if (toggleRedraw) - target.setRedraw(true); - } - } - } - - public boolean overlapsWithVisibleRegion(int start, int length) { - IDocument document= getVisibleDocument(); - if (document instanceof ChildDocument) { - ChildDocument cdoc= (ChildDocument) document; - return cdoc.getParentDocumentRange().overlapsWith(start, length); - } else if (document != null) { - int size= document.getLength(); - return (start >= 0 && length >= 0 && start + length <= size); - } - return false; - } - - public final void invalidateTextPresentation(int offset, int length) { - if (fVisibleDocument != null) { - - IRegion widgetRange= modelRange2WidgetRange(new Region(offset, length)); - if (widgetRange != null) { - - fWidgetCommand.event= null; - fWidgetCommand.start= widgetRange.getOffset(); - fWidgetCommand.length= widgetRange.getLength(); - - try { - fWidgetCommand.text= fVisibleDocument.get(widgetRange.getOffset(), widgetRange.getLength()); - updateTextListeners(fWidgetCommand); - } catch (BadLocationException x) { - // can not happen because of previous checking - } - } - } - } - - public void addTextPresentationListener(ITextPresentationListener listener) { - - Assert.isNotNull(listener); - - if (fTextPresentationListeners == null) - fTextPresentationListeners= new ArrayList(); - - if (!fTextPresentationListeners.contains(listener)) - fTextPresentationListeners.add(listener); - } - - public void removeTextPresentationListener(ITextPresentationListener listener) { - - Assert.isNotNull(listener); - - if (fTextPresentationListeners != null) { - fTextPresentationListeners.remove(listener); - if (fTextPresentationListeners.size() == 0) - fTextPresentationListeners= null; - } - } - - /** - * The viewer's rewrite target. - * @since 2.0 - */ - class RewriteTarget implements IRewriteTarget { - - /* - * @see org.eclipse.jface.text.IRewriteTarget#beginCompoundChange() - */ - public void beginCompoundChange() { -//TODO needs porting -// if (fUndoManager != null) -// fUndoManager.beginCompoundChange(); - } - - /* - * @see org.eclipse.jface.text.IRewriteTarget#endCompoundChange() - */ - public void endCompoundChange() { -//TODO needs porting -// if (fUndoManager != null) -// fUndoManager.endCompoundChange(); - } - - /* - * @see org.eclipse.jface.text.IRewriteTarget#getDocument() - */ - public IDocument getDocument() { - return TextViewer.this.getDocument(); - } - - /* - * @see org.eclipse.jface.text.IRewriteTarget#setRedraw(boolean) - */ - public void setRedraw(boolean redraw) { - TextViewer.this.setRedraw(redraw); - } - } - - private final class ViewerState { -//TODO needs porting - public void restore(boolean restoreViewport) { - - } - } -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/CompletetionProposal.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/CompletetionProposal.java deleted file mode 100644 index 9e4bffcbc..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/CompletetionProposal.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -import java.util.function.Supplier; - -import javafx.scene.Node; - -import org.eclipse.fx.ui.controls.styledtext.TextSelection; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -public class CompletetionProposal implements ICompletionProposal { - - private final CharSequence label; - - private final String replacementString; - private final int replacementOffset; - private final int replacementLength; - private final int cursorPosition; - private final Supplier<Node> graphicSupplier; - - public CompletetionProposal(String replacementString, int replacementOffset, int replacementLength, CharSequence label, Supplier<Node> graphicSupplier) { - this.replacementString = replacementString; - this.replacementOffset = replacementOffset; - this.replacementLength = replacementLength; - this.cursorPosition = replacementString.length(); - this.label = label; - this.graphicSupplier = graphicSupplier; - } - - @Override - public Node getGraphic() { - return graphicSupplier.get(); - } - - @Override - public CharSequence getLabel() { - return label; - } - - public int getReplacementOffset() { - return replacementOffset; - } - - public int getReplacementLength() { - return replacementLength; - } - - public String getReplacementString() { - return replacementString; - } - - public int getCursorPosition() { - return cursorPosition; - } - - @Override - public void apply(IDocument document) { - try { - document.replace(replacementOffset, replacementLength, replacementString); - } catch (BadLocationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Override - public TextSelection getSelection(IDocument document) { - return new TextSelection(replacementOffset+cursorPosition, 0); - } -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/ContentAssistant.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/ContentAssistant.java deleted file mode 100644 index 2873e453b..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/ContentAssistant.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -import java.util.List; -import java.util.function.Function; - -import javafx.geometry.Point2D; -import javafx.scene.input.KeyCode; - -import org.eclipse.fx.ui.controls.styledtext.VerifyEvent; -import org.eclipse.jface.text.ITextViewer; - -public class ContentAssistant implements IContentAssistant { - private final Function<Integer, List<ICompletionProposal>> proposalComputer; - private ITextViewer viewer; - private ContentProposalPopup popuop; - - public ContentAssistant(Function<Integer, List<ICompletionProposal>> proposalComputer) { - this.proposalComputer = proposalComputer; - } - - @Override - public void install(ITextViewer textViewer) { - if( this.viewer == null ) { - this.viewer = textViewer; - this.popuop = new ContentProposalPopup(textViewer,proposalComputer); - textViewer.getTextWidget().addEventHandler(VerifyEvent.VERIFY, this::handleVerify); - } - } - - private void handleVerify(VerifyEvent event) { - if( !(event.isControlDown() && event.getCode() == KeyCode.SPACE) ) { - return; - } - event.consume(); - - List<ICompletionProposal> proposals = proposalComputer.apply(this.viewer.getTextWidget().getCaretOffset()); - - if( proposals.size() == 1) { - proposals.get(0).apply(this.viewer.getDocument()); - this.viewer.getTextWidget().setSelection(proposals.get(0).getSelection(this.viewer.getDocument())); - } else if( ! proposals.isEmpty() ) { -// System.err.println(this.viewer.getTextWidget().getCaretLocation()); - System.err.println(); - - Point2D p = this.viewer.getTextWidget().getLocationAtOffset(this.viewer.getTextWidget().getCaretOffset()); - System.err.println(p); - this.popuop.displayProposals(proposals, this.viewer.getTextWidget().getCaretOffset(), this.viewer.getTextWidget().localToScreen(p)); - } - } -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/ContentProposalPopup.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/ContentProposalPopup.java deleted file mode 100644 index 802fe02d2..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/ContentProposalPopup.java +++ /dev/null @@ -1,171 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -import static com.sun.javafx.PlatformUtil.isMac; - -import java.util.Collections; -import java.util.List; -import java.util.function.Function; - -import javafx.application.Platform; -import javafx.collections.FXCollections; -import javafx.geometry.Point2D; -import javafx.scene.Node; -import javafx.scene.Scene; -import javafx.scene.control.ListView; -import javafx.scene.input.KeyCode; -import javafx.scene.input.KeyEvent; -import javafx.scene.layout.BorderPane; -import javafx.stage.Stage; -import javafx.stage.StageStyle; - -import org.eclipse.fx.ui.controls.list.SimpleListCell; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextViewer; - -public class ContentProposalPopup { - private ITextViewer viewer; - private Stage stage; - private ListView<ICompletionProposal> proposalList; - private String prefix; - private int offset; - private Function<Integer, List<ICompletionProposal>> proposalComputer; - - public ContentProposalPopup(ITextViewer viewer, Function<Integer, List<ICompletionProposal>> proposalComputer) { - this.viewer = viewer; - this.proposalComputer = proposalComputer; - } - - public void displayProposals(List<ICompletionProposal> proposalList, int offset, Point2D position) { - setup(); - this.prefix = ""; - this.offset = offset; - this.proposalList.setItems(FXCollections.observableArrayList(proposalList)); - this.proposalList.getSelectionModel().select(0); - this.stage.setX(position.getX()); - this.stage.setY(position.getY()); - this.stage.show(); - this.stage.requestFocus(); - } - - private void handleKeyTyped(KeyEvent event) { - if( event.getCharacter().length() == 0 ) { - return; - } - - String character = event.getCharacter(); - if( character.length() == 0 ) { - return; - } - - if (event.isControlDown() || event.isAltDown() || (isMac() && event.isMetaDown())) { - if (!((event.isControlDown() || isMac()) && event.isAltDown())) { - return; - } - } - - if (character.charAt(0) > 0x1F - && character.charAt(0) != 0x7F ) { - try { - this.prefix = prefix+character; - viewer.getDocument().replace(offset, 0, character); - this.offset += event.getCharacter().length(); - viewer.getTextWidget().setCaretOffset(offset); - updateProposals(); - } catch (BadLocationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - private void updateProposals() { - List<ICompletionProposal> list = proposalComputer.apply(offset); - if( ! list.isEmpty() ) { - proposalList.setItems(FXCollections.observableArrayList(list)); - proposalList.scrollTo(0); - proposalList.getSelectionModel().select(0); - } else { - stage.close(); - } - } - - private void handleKeyPressed(KeyEvent event) { - if( event.getCode() == KeyCode.ESCAPE ) { - event.consume(); - stage.close(); - } else if( event.getCode() == KeyCode.BACK_SPACE ) { - event.consume(); - this.offset -= 1; - try { - this.viewer.getDocument().replace(offset, 1, ""); - viewer.getTextWidget().setCaretOffset(offset); - updateProposals(); - } catch (BadLocationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } else if( event.getCode() == KeyCode.ENTER ) { - event.consume(); - applySelection(); - } else if( event.getCode() == KeyCode.LEFT ) { - event.consume(); - this.offset -= 1; - this.offset = Math.max(0, this.offset); - viewer.getTextWidget().setCaretOffset(offset); - updateProposals(); - } else if( event.getCode() == KeyCode.RIGHT ) { - event.consume(); - this.offset += 1; - this.offset = Math.min(viewer.getDocument().getLength()-1, this.offset); - viewer.getTextWidget().setCaretOffset(offset); - updateProposals(); - } - } - - private void applySelection() { - ICompletionProposal selectedItem = proposalList.getSelectionModel().getSelectedItem(); - if( selectedItem != null ) { - IDocument document = viewer.getDocument(); - selectedItem.apply(document); - viewer.getTextWidget().setSelection(selectedItem.getSelection(document)); - stage.close(); - } - } - - private void setup() { - if( stage == null ) { - stage = new Stage(StageStyle.TRANSPARENT); - stage.initOwner(viewer.getTextWidget().getScene().getWindow()); - BorderPane p = new BorderPane(); - Scene s = new Scene(p,300,200); - s.addEventFilter(KeyEvent.KEY_TYPED, this::handleKeyTyped); - s.addEventFilter(KeyEvent.KEY_PRESSED, this::handleKeyPressed); - s.getStylesheets().addAll(viewer.getTextWidget().getScene().getStylesheets()); - proposalList = new ListView<>(); - proposalList.setOnMouseClicked((e) -> { - if(e.getClickCount() == 1) { - applySelection(); - } - }); - - Function<ICompletionProposal, CharSequence> label = (c) -> c.getLabel(); - Function<ICompletionProposal, Node> graphic = (c) -> c.getGraphic(); - Function<ICompletionProposal, List<String>> css = (c) -> Collections.emptyList(); - - - proposalList.setCellFactory((v) -> new SimpleListCell<ICompletionProposal>(label,graphic,css)); - p.setCenter(proposalList); - stage.setScene(s); - stage.focusedProperty().addListener((o) -> { - if( ! stage.isFocused() ) { - Platform.runLater(stage::close); - } - }); - // Fix CSS warnings - stage.setOnHidden((o) -> { - stage = null; - }); - } - } -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/ICompletionProposal.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/ICompletionProposal.java deleted file mode 100644 index a56d16de5..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/ICompletionProposal.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -import javafx.scene.Node; - -import org.eclipse.fx.ui.controls.styledtext.TextSelection; -import org.eclipse.jface.text.IDocument; - -public interface ICompletionProposal { - public CharSequence getLabel(); - public Node getGraphic(); -// public List<String> getStyles(); - - public void apply(IDocument document); - public TextSelection getSelection(IDocument document); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/IContentAssistant.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/IContentAssistant.java deleted file mode 100644 index e8c89ec90..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/contentassist/IContentAssistant.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -import org.eclipse.jface.text.ITextViewer; - -public interface IContentAssistant { - void install(ITextViewer textViewer); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/IPresentationDamager.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/IPresentationDamager.java deleted file mode 100644 index 4039cb96a..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/IPresentationDamager.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.presentation; - - - -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITypedRegion; - - -/** - * A presentation damager is a strategy used by a presentation reconciler to - * determine the region of the document's presentation which must be rebuilt - * because of a document change. A presentation damager is assumed to be - * specific for a particular document content type. A presentation damager is - * expected to return a damage region which is a valid input for a presentation - * repairer. I.e. having access to the damage region only the repairer must be - * able to derive all the information needed to successfully repair this region. - * <p> - * This interface must either be implemented by clients or clients use the - * rule-based default implementation - * {@link org.eclipse.jface.text.rules.DefaultDamagerRepairer}. Implementers - * should be registered with a presentation reconciler in order get involved in - * the reconciling process.</p> - * - * @see IPresentationReconciler - * @see IDocument - * @see DocumentEvent - * @see IPresentationRepairer - */ -public interface IPresentationDamager { - - /** - * Tells the presentation damager on which document it will work. - * - * @param document the damager's working document - */ - void setDocument(IDocument document); - - /** - * Returns the damage in the document's presentation caused by the given document change. - * The damage is restricted to the specified partition for which the presentation damager is - * responsible. The damage may also depend on whether the document change also caused changes - * of the document's partitioning. - * - * @param partition the partition inside which the damage must be determined - * @param event the event describing the change whose damage must be determined - * @param documentPartitioningChanged indicates whether the given change changed the document's partitioning - * @return the computed damage - */ - IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/IPresentationReconciler.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/IPresentationReconciler.java deleted file mode 100644 index edfdc4f2c..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/IPresentationReconciler.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.presentation; - - -import org.eclipse.jface.text.ITextViewer; - - -/** - * An <code>IPresentationReconciler</code> defines and maintains the - * representation of a text viewer's document in the presence of changes applied - * to the document. An <code>IPresentationReconciler</code> is a - * <code>ITextViewer</code> add-on. - * <p> - * The presentation reconciler keeps track of changes applied to the text - * viewer. It sends each change to presentation damagers which are registered - * for the content types of the regions in which the change occurred. The - * presentation reconciler passes the computed damage to presentation repairer - * which construct text presentations. When applied to the presentation - * reconciler's text viewer, those text presentations bring the document's - * presentation in sync with the document's content and thus repair the damage. - * A presentation damager is expected to return damage which is a valid input - * for a presentation repairer registered for the same content type as the - * damager. - * </p> - * <p> - * A presentation reconciler should always be configured with a pair of - * damager/repairer strategies. I.e. for each damager there should be a - * corresponding repairer. - * </p> - * <p> - * The interface may be implemented by clients. Clients may use - * <code>PresentationReconciler</code> as the standard implementation of this - * interface. - * </p> - * <p> - * In order to provided backward compatibility for clients of - * <code>IPresentationReconciler</code>, extension interfaces are used to - * provide a means of evolution. The following extension interface exists: - * <ul> - * <li> - * {@link org.eclipse.jface.text.presentation.IPresentationReconcilerExtension} - * since version 3.0 adding support for documents with multiple partitionings. - * </li> - * </ul> - * </p> - * - * @see org.eclipse.jface.text.presentation.IPresentationReconcilerExtension - * @see org.eclipse.jface.text.ITextViewer - * @see org.eclipse.jface.text.presentation.IPresentationDamager - * @see org.eclipse.jface.text.presentation.IPresentationRepairer - * @see org.eclipse.jface.text.TextPresentation - */ -public interface IPresentationReconciler { - - /** - * Installs this presentation reconciler on the given text viewer. After - * this method has been finished, the reconciler is operational. I.e., it - * works without requesting further client actions until - * <code>uninstall</code> is called. - * <p> - * The <code>install</code> and <code>uninstall</code> methods must be - * called in sequence; i.e. repeatedly calling <code>install</code> - * without calling <code>uninstall</code> may throw an exception. - * </p> - * - * @param viewer the viewer on which this presentation reconciler is - * installed - */ - void install(ITextViewer viewer); - - /** - * Removes the reconciler from the text viewer it has previously been - * installed on. - */ - void uninstall(); - - /** - * Returns the presentation damager registered with this presentation reconciler - * for the specified content type. - * - * @param contentType the content type for which to determine the damager - * @return the presentation damager registered for the given content type, or - * <code>null</code> if there is no damager - */ - IPresentationDamager getDamager(String contentType); - - /** - * Returns the presentation repairer registered with this presentation reconciler - * for the specified content type. - * - * @param contentType the content type for which to determine the repairer - * @return the presentation repairer registered for the given content type, or - * <code>null</code> if there is no repairer - */ - IPresentationRepairer getRepairer(String contentType); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/IPresentationReconcilerExtension.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/IPresentationReconcilerExtension.java deleted file mode 100644 index 1fc459fd2..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/IPresentationReconcilerExtension.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.presentation; - -/** - * Extension interface for {@link IPresentationReconciler}. Adds awareness of - * documents with multiple partitions. - * - * @since 3.0 - */ -public interface IPresentationReconcilerExtension { - - /** - * Returns the document partitioning this presentation reconciler is using. - * - * @return the document partitioning this presentation reconciler is using - */ - String getDocumentPartitioning(); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/IPresentationRepairer.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/IPresentationRepairer.java deleted file mode 100644 index a07f8e681..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/IPresentationRepairer.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.presentation; - - - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.TextPresentation; - - -/** - * A presentation repairer is a strategy used by a presentation reconciler to - * rebuild a damaged region in a document's presentation. A presentation - * repairer is assumed to be specific for a particular document content type. - * The presentation repairer gets the region which it should repair and - * constructs a "repair description". The presentation repairer merges the steps - * contained within this description into the text presentation passed into - * <code>createPresentation</code>. - * <p> - * This interface may be implemented by clients. Alternatively, clients may use - * the rule-based default implementation - * {@link org.eclipse.jface.text.rules.DefaultDamagerRepairer}. Implementers - * should be registered with a presentation reconciler in order get involved in - * the reconciling process. - * </p> - * - * @see IPresentationReconciler - * @see IDocument - * @see org.eclipse.swt.custom.StyleRange - * @see TextPresentation - */ -public interface IPresentationRepairer { - - - /** - * Tells the presentation repairer on which document it will work. - * - * @param document the damager's working document - */ - void setDocument(IDocument document); - - /** - * Fills the given presentation with the style ranges which when applied to the - * presentation reconciler's text viewer repair the presentation damage described by - * the given region. - * - * @param presentation the text presentation to be filled by this repairer - * @param damage the damage to be repaired - */ - void createPresentation(TextPresentation presentation, ITypedRegion damage); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/PresentationReconciler.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/PresentationReconciler.java deleted file mode 100644 index 2ac93be86..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/presentation/PresentationReconciler.java +++ /dev/null @@ -1,595 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text.presentation; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.fx.ui.controls.styledtext.StyleRange; -import org.eclipse.jface.text.Assert; -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.DocumentPartitioningChangedEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentExtension3; -import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.jface.text.IDocumentPartitioningListener; -import org.eclipse.jface.text.IDocumentPartitioningListenerExtension; -import org.eclipse.jface.text.IDocumentPartitioningListenerExtension2; -import org.eclipse.jface.text.IPositionUpdater; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextInputListener; -import org.eclipse.jface.text.ITextListener; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.ITextViewerExtension5; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextEvent; -import org.eclipse.jface.text.TextPresentation; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.text.TypedPosition; - - - -/** - * Standard implementation of <code>IPresentationReconciler</code>. This - * implementation assumes that the tasks performed by its presentation damagers - * and repairers are lightweight and of low cost. This presentation reconciler - * runs in the UI thread and always repairs the complete damage caused by a - * document change rather than just the portion overlapping with the viewer's - * viewport. - * <p> - * Usually, clients instantiate this class and configure it before using it. - * </p> - */ -public class PresentationReconciler implements IPresentationReconciler, IPresentationReconcilerExtension { - - /** Prefix of the name of the position category for tracking damage regions. */ - protected final static String TRACKED_PARTITION= "__reconciler_tracked_partition"; //$NON-NLS-1$ - - - /** - * Internal listener class. - */ - class InternalListener implements - ITextInputListener, IDocumentListener, ITextListener, - IDocumentPartitioningListener, IDocumentPartitioningListenerExtension, IDocumentPartitioningListenerExtension2 { - - /** Set to <code>true</code> if between a document about to be changed and a changed event. */ - private boolean fDocumentChanging= false; - /** - * The cached redraw state of the text viewer. - * @since 3.0 - */ - private boolean fCachedRedrawState= true; - - /* - * @see ITextInputListener#inputDocumentAboutToBeChanged(IDocument, IDocument) - */ - public void inputDocumentAboutToBeChanged(IDocument oldDocument, IDocument newDocument) { - if (oldDocument != null) { - try { - - fViewer.removeTextListener(this); - oldDocument.removeDocumentListener(this); - oldDocument.removeDocumentPartitioningListener(this); - - oldDocument.removePositionUpdater(fPositionUpdater); - oldDocument.removePositionCategory(fPositionCategory); - - } catch (BadPositionCategoryException x) { - // should not happened for former input documents; - } - } - } - - /* - * @see ITextInputListener#inputDocumenChanged(IDocument, IDocument) - */ - public void inputDocumentChanged(IDocument oldDocument, IDocument newDocument) { - - fDocumentChanging= false; - fCachedRedrawState= true; - - if (newDocument != null) { - - newDocument.addPositionCategory(fPositionCategory); - newDocument.addPositionUpdater(fPositionUpdater); - - newDocument.addDocumentPartitioningListener(this); - newDocument.addDocumentListener(this); - fViewer.addTextListener(this); - - setDocumentToDamagers(newDocument); - setDocumentToRepairers(newDocument); - processDamage(new Region(0, newDocument.getLength()), newDocument); - } - } - - /* - * @see IDocumentPartitioningListener#documentPartitioningChanged(IDocument) - */ - public void documentPartitioningChanged(IDocument document) { - if (!fDocumentChanging && fCachedRedrawState) - processDamage(new Region(0, document.getLength()), document); - else - fDocumentPartitioningChanged= true; - } - - /* - * @see IDocumentPartitioningListenerExtension#documentPartitioningChanged(IDocument, IRegion) - * @since 2.0 - */ - public void documentPartitioningChanged(IDocument document, IRegion changedRegion) { - if (!fDocumentChanging && fCachedRedrawState) { - processDamage(new Region(changedRegion.getOffset(), changedRegion.getLength()), document); - } else { - fDocumentPartitioningChanged= true; - fChangedDocumentPartitions= changedRegion; - } - } - - /* - * @see org.eclipse.jface.text.IDocumentPartitioningListenerExtension2#documentPartitioningChanged(org.eclipse.jface.text.DocumentPartitioningChangedEvent) - * @since 3.0 - */ - public void documentPartitioningChanged(DocumentPartitioningChangedEvent event) { - IRegion changedRegion= event.getChangedRegion(getDocumentPartitioning()); - if (changedRegion != null) - documentPartitioningChanged(event.getDocument(), changedRegion); - } - - /* - * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent) - */ - public void documentAboutToBeChanged(DocumentEvent e) { - - fDocumentChanging= true; - if (fCachedRedrawState) { - try { - int offset= e.getOffset() + e.getLength(); - ITypedRegion region= getPartition(e.getDocument(), offset); - fRememberedPosition= new TypedPosition(region); - e.getDocument().addPosition(fPositionCategory, fRememberedPosition); - } catch (BadLocationException x) { - // can not happen - } catch (BadPositionCategoryException x) { - // should not happen on input elements - } - } - } - - /* - * @see IDocumentListener#documentChanged(DocumentEvent) - */ - public void documentChanged(DocumentEvent e) { - if (fCachedRedrawState) { - try { - e.getDocument().removePosition(fPositionCategory, fRememberedPosition); - } catch (BadPositionCategoryException x) { - // can not happen on input documents - } - } - fDocumentChanging= false; - } - - /* - * @see ITextListener#textChanged(TextEvent) - */ - public void textChanged(TextEvent e) { - - fCachedRedrawState= e.getViewerRedrawState(); - if (!fCachedRedrawState) - return; - - IRegion damage= null; - IDocument document= null; - - if (e.getDocumentEvent() == null) { - document= fViewer.getDocument(); - if (document != null) { - if (e.getOffset() == 0 && e.getLength() == 0 && e.getText() == null) { - // redraw state change, damage the whole document - damage= new Region(0, document.getLength()); - } else { - IRegion region= widgetRegion2ModelRegion(e); - if (region != null) { - try { - String text= document.get(region.getOffset(), region.getLength()); - DocumentEvent de= new DocumentEvent(document, region.getOffset(), region.getLength(), text); - damage= getDamage(de, false); - } catch (BadLocationException x) { - } - } - } - } - } else { - DocumentEvent de= e.getDocumentEvent(); - document= de.getDocument(); - damage= getDamage(de, true); - } - - if (damage != null && document != null) - processDamage(damage, document); - - fDocumentPartitioningChanged= false; - fChangedDocumentPartitions= null; - } - - /** - * Translates the given text event into the corresponding range of the viewer's document. - * - * @param e the text event - * @return the widget region corresponding the region of the given event or - * <code>null</code> if none - * @since 2.1 - */ - protected IRegion widgetRegion2ModelRegion(TextEvent e) { - - String text= e.getText(); - int length= text == null ? 0 : text.length(); - - if (fViewer instanceof ITextViewerExtension5) { - ITextViewerExtension5 extension= (ITextViewerExtension5) fViewer; - return extension.widgetRange2ModelRange(new Region(e.getOffset(), length)); - } - - IRegion visible= fViewer.getVisibleRegion(); - IRegion region= new Region(e.getOffset() + visible.getOffset(), length); - return region; - } - } - - /** The map of presentation damagers. */ - private Map fDamagers; - /** The map of presentation repairers. */ - private Map fRepairers; - /** The target viewer. */ - private ITextViewer fViewer; - /** The internal listener. */ - private InternalListener fInternalListener= new InternalListener(); - /** The name of the position category to track damage regions. */ - private String fPositionCategory; - /** The position updated for the damage regions' position category. */ - private IPositionUpdater fPositionUpdater; - /** The positions representing the damage regions. */ - private TypedPosition fRememberedPosition; - /** Flag indicating the receipt of a partitioning changed notification. */ - private boolean fDocumentPartitioningChanged= false; - /** The range covering the changed partitioning. */ - private IRegion fChangedDocumentPartitions= null; - /** - * The partitioning used by this presentation reconciler. - * @since 3.0 - */ - private String fPartitioning; - - /** - * Creates a new presentation reconciler. There are no damagers or repairers - * registered with this reconciler by default. The default partitioning - * <code>IDocumentExtension3.DEFAULT_PARTITIONING</code> is used. - */ - public PresentationReconciler() { - super(); - fPartitioning= IDocumentExtension3.DEFAULT_PARTITIONING; - fPositionCategory= TRACKED_PARTITION + hashCode(); - fPositionUpdater= new DefaultPositionUpdater(fPositionCategory); - } - - /** - * Sets the document partitioning for this presentation reconciler. - * - * @param partitioning the document partitioning for this presentation reconciler. - * @since 3.0 - */ - public void setDocumentPartitioning(String partitioning) { - Assert.isNotNull(partitioning); - fPartitioning= partitioning; - } - - /* - * @see org.eclipse.jface.text.presentation.IPresentationReconcilerExtension#geDocumenttPartitioning() - * @since 3.0 - */ - public String getDocumentPartitioning() { - return fPartitioning; - } - - /** - * Registers the given presentation damager for a particular content type. - * If there is already a damager registered for this type, the old damager - * is removed first. - * - * @param damager the presentation damager to register, or <code>null</code> to remove an existing one - * @param contentType the content type under which to register - */ - public void setDamager(IPresentationDamager damager, String contentType) { - - Assert.isNotNull(contentType); - - if (fDamagers == null) - fDamagers= new HashMap(); - - if (damager == null) - fDamagers.remove(contentType); - else - fDamagers.put(contentType, damager); - } - - /** - * Registers the given presentation repairer for a particular content type. - * If there is already a repairer registered for this type, the old repairer - * is removed first. - * - * @param repairer the presentation repairer to register, or <code>null</code> to remove an existing one - * @param contentType the content type under which to register - */ - public void setRepairer(IPresentationRepairer repairer, String contentType) { - - Assert.isNotNull(contentType); - - if (fRepairers == null) - fRepairers= new HashMap(); - - if (repairer == null) - fRepairers.remove(contentType); - else - fRepairers.put(contentType, repairer); - } - - /* - * @see IPresentationReconciler#install(ITextViewer) - */ - public void install(ITextViewer viewer) { - Assert.isNotNull(viewer); - - fViewer= viewer; - fViewer.addTextInputListener(fInternalListener); - - IDocument document= viewer.getDocument(); - if (document != null) - fInternalListener.inputDocumentChanged(null, document); - } - - /* - * @see IPresentationReconciler#uninstall() - */ - public void uninstall() { - fViewer.removeTextInputListener(fInternalListener); - - // Ensure we uninstall all listeners - fInternalListener.inputDocumentAboutToBeChanged(fViewer.getDocument(), null); - } - - /* - * @see IPresentationReconciler#getDamager(String) - */ - public IPresentationDamager getDamager(String contentType) { - - if (fDamagers == null) - return null; - - return (IPresentationDamager) fDamagers.get(contentType); - } - - /* - * @see IPresentationReconciler#getRepairer(String) - */ - public IPresentationRepairer getRepairer(String contentType) { - - if (fRepairers == null) - return null; - - return (IPresentationRepairer) fRepairers.get(contentType); - } - - /** - * Informs all registered damagers about the document on which they will work. - * - * @param document the document on which to work - */ - protected void setDocumentToDamagers(IDocument document) { - if (fDamagers != null) { - Iterator e= fDamagers.values().iterator(); - while (e.hasNext()) { - IPresentationDamager damager= (IPresentationDamager) e.next(); - damager.setDocument(document); - } - } - } - - /** - * Informs all registered repairers about the document on which they will work. - * - * @param document the document on which to work - */ - protected void setDocumentToRepairers(IDocument document) { - if (fRepairers != null) { - Iterator e= fRepairers.values().iterator(); - while (e.hasNext()) { - IPresentationRepairer repairer= (IPresentationRepairer) e.next(); - repairer.setDocument(document); - } - } - } - - /** - * Constructs a "repair description" for the given damage and returns this - * description as a text presentation. For this, it queries the partitioning - * of the damage region and asks the appropriate presentation repairer for - * each partition to construct the "repair description" for this partition. - * - * @param damage the damage to be repaired - * @param document the document whose presentation must be repaired - * @return the presentation repair description as text presentation or - * <code>null</code> if the partitioning could not be computed - */ - protected TextPresentation createPresentation(IRegion damage, IDocument document) { - try { - if (fRepairers == null || fRepairers.isEmpty()) { - TextPresentation presentation= new TextPresentation(damage, 100); - presentation.setDefaultStyleRange(new StyleRange(null, damage.getOffset(), damage.getLength(), null, null)); - return presentation; - } - - TextPresentation presentation= new TextPresentation(damage, 1000); - - ITypedRegion[] partitioning= TextUtilities.computePartitioning(document, getDocumentPartitioning(), damage.getOffset(), damage.getLength(), false); - for (int i= 0; i < partitioning.length; i++) { - ITypedRegion r= partitioning[i]; - IPresentationRepairer repairer= getRepairer(r.getType()); - if (repairer != null) - repairer.createPresentation(presentation, r); - } - - return presentation; - - } catch (BadLocationException x) { - return null; - } - } - - - /** - * Checks for the first and the last affected partition affected by a - * document event and calls their damagers. Invalidates everything from the - * start of the damage for the first partition until the end of the damage - * for the last partition. - * - * @param e the event describing the document change - * @param optimize <code>true</code> if partition changes should be - * considered for optimization - * @return the damaged caused by the change or <code>null</code> if - * computing the partitioning failed - * @since 3.0 - */ - private IRegion getDamage(DocumentEvent e, boolean optimize) { - int length= e.getText() == null ? 0 : e.getText().length(); - - if (fDamagers == null || fDamagers.isEmpty()) { - length= Math.max(e.getLength(), length); - length= Math.min(e.getDocument().getLength() - e.getOffset(), length); - return new Region(e.getOffset(), length); - } - - boolean isDeletion= length == 0; - IRegion damage= null; - try { - int offset= e.getOffset(); - if (isDeletion) - offset= Math.max(0, offset - 1); - ITypedRegion partition= getPartition(e.getDocument(), offset); - IPresentationDamager damager= getDamager(partition.getType()); - if (damager == null) - return null; - - IRegion r= damager.getDamageRegion(partition, e, fDocumentPartitioningChanged); - - if (!fDocumentPartitioningChanged && optimize && !isDeletion) { - damage= r; - } else { - - int damageStart= r.getOffset(); - int damageEnd= getDamageEndOffset(e); - - if (fChangedDocumentPartitions != null) { - damageStart= Math.min(damageStart, fChangedDocumentPartitions.getOffset()); - damageEnd= Math.max(damageEnd, fChangedDocumentPartitions.getOffset() + fChangedDocumentPartitions.getLength()); - } - - damage= damageEnd == -1 ? r : new Region(damageStart, damageEnd - damageStart); - } - - } catch (BadLocationException x) { - } - - return damage; - } - - /** - * Returns the end offset of the damage. If a partition has been split by - * the given document event also the second half of the original - * partition must be considered. This is achieved by using the remembered - * partition range. - * - * @param e the event describing the change - * @return the damage end offset (excluding) - * @exception BadLocationException if method accesses invalid offset - */ - private int getDamageEndOffset(DocumentEvent e) throws BadLocationException { - - IDocument d= e.getDocument(); - - int length= 0; - if (e.getText() != null) { - length= e.getText().length(); - if (length > 0) - -- length; - } - - ITypedRegion partition= getPartition(d, e.getOffset() + length); - int endOffset= partition.getOffset() + partition.getLength(); - if (endOffset == e.getOffset()) - return -1; - - int end= fRememberedPosition == null ? -1 : fRememberedPosition.getOffset() + fRememberedPosition.getLength(); - if (endOffset < end && end < d.getLength()) - partition= getPartition(d, end); - - IPresentationDamager damager= getDamager(partition.getType()); - if (damager == null) - return -1; - - IRegion r= damager.getDamageRegion(partition, e, fDocumentPartitioningChanged); - - return r.getOffset() + r.getLength(); - } - - /** - * Processes the given damage. - * @param damage the damage to be repaired - * @param document the document whose presentation must be repaired - */ - private void processDamage(IRegion damage, IDocument document) { - if (damage != null && damage.getLength() > 0) { - TextPresentation p= createPresentation(damage, document); - if (p != null) - applyTextRegionCollection(p); - } - } - - /** - * Applies the given text presentation to the text viewer the presentation - * reconciler is installed on. - * - * @param presentation the text presentation to be applied to the text viewer - */ - private void applyTextRegionCollection(TextPresentation presentation) { - fViewer.changeTextPresentation(presentation, false); - } - - /** - * Returns the partition for the given offset in the given document. - * - * @param document the document - * @param offset the offset - * @return the partition - * @throws BadLocationException if offset is invalid in the given document - * @since 3.0 - */ - private ITypedRegion getPartition(IDocument document, int offset) throws BadLocationException { - return TextUtilities.getPartition(document, getDocumentPartitioning(), offset, false); - } -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/reconciler/DirtyRegion.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/reconciler/DirtyRegion.java deleted file mode 100644 index 83b07ac53..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/reconciler/DirtyRegion.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.reconciler; - -import org.eclipse.jface.text.ITypedRegion; - - -/** - * A dirty region describes a document range which has been changed. - */ -public class DirtyRegion implements ITypedRegion { - - /** - * Identifies an insert operation. - */ - final static public String INSERT= "__insert"; //$NON-NLS-1$ - /** - * Identifies a remove operation. - */ - final static public String REMOVE= "__remove"; //$NON-NLS-1$ - - /** The region's offset. */ - private int fOffset; - /** The region's length. */ - private int fLength; - /** Indicates the type of the applied change. */ - private String fType; - /** The text which has been inserted. */ - private String fText; - - /** - * Creates a new dirty region. - * - * @param offset the offset within the document where the change occurred - * @param length the length of the text within the document that changed - * @param type the type of change that this region represents: {@link #INSERT} {@link #REMOVE} - * @param text the substitution text - */ - public DirtyRegion(int offset, int length, String type, String text) { - fOffset= offset; - fLength= length; - fType= normalizeTypeValue(type); - fText= text; - } - - /** - * Computes the normalized type value to ensure that the implementation can use object identity rather - * than equality. - * - * @param type the type value - * @return the normalized type value or <code>null</code> - * @since 3.1 - */ - private String normalizeTypeValue(String type) { - if (INSERT.equals(type)) - return INSERT; - if (REMOVE.equals(type)) - return REMOVE; - return null; - } - - /* - * @see ITypedRegion#getOffset() - */ - public int getOffset() { - return fOffset; - } - - /* - * @see ITypedRegion#getLength() - */ - public int getLength() { - return fLength; - } - - /* - * @see ITypedRegion#getType - */ - public String getType() { - return fType; - } - - /** - * Returns the text that changed as part of the region change. - * - * @return the changed text - */ - public String getText() { - return fText; - } - - /** - * Modify the receiver so that it encompasses the region specified by the dirty region. - * - * @param dr the dirty region with which to merge - */ - void mergeWith(DirtyRegion dr) { - int start= Math.min(fOffset, dr.fOffset); - int end= Math.max(fOffset + fLength, dr.fOffset + dr.fLength); - fOffset= start; - fLength= end - start; - fText= (dr.fText == null ? fText : (fText == null) ? dr.fText : fText + dr.fText); - } -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/reconciler/IReconciler.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/reconciler/IReconciler.java deleted file mode 100644 index 53a10d46a..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/reconciler/IReconciler.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.reconciler; - -import org.eclipse.jface.text.ITextViewer; - - -/** - * An <code>IReconciler</code> defines and maintains a model of the content - * of the text viewer's document in the presence of changes applied to this - * document. An <code>IReconciler</code> is a {@link org.eclipse.jface.text.ITextViewer} add-on. - * <p> - * Reconcilers are assumed to be asynchronous, i.e. they allow a certain - * temporal window of inconsistency between the document and the model of - * the content of this document. - * </p> - * <p> - * Reconcilers have a list of {@link org.eclipse.jface.text.reconciler.IReconcilingStrategy} - * objects each of which is registered for a particular document content type. - * The reconciler uses the strategy objects to react on the changes applied - * to the text viewer's document. - *</p> - * <p> - * In order to provide backward compatibility for clients of <code>IReconciler</code>, extension - * interfaces are used to provide a means of evolution. The following extension interfaces exist: - * <ul> - * <li>{@link org.eclipse.jface.text.reconciler.IReconcilerExtension} since version 3.0 introducing - * the ability to be aware of documents with multiple partitionings.</li> - * </ul> - * </p> - * <p> - * The interface can be implemented by clients. By default, clients use - * {@link org.eclipse.jface.text.reconciler.MonoReconciler} or - * {@link org.eclipse.jface.text.reconciler.Reconciler} as the standard - * implementers of this interface. - * </p> - * - * @see ITextViewer - * @see IReconcilingStrategy - */ -public interface IReconciler { - - /** - * Installs the reconciler on the given text viewer. After this method has been - * finished, the reconciler is operational, i.e., it works without requesting - * further client actions until <code>uninstall</code> is called. - * - * @param textViewer the viewer on which the reconciler is installed - */ - void install(ITextViewer textViewer); - - /** - * Removes the reconciler from the text viewer it has - * previously been installed on. - */ - void uninstall(); - - /** - * Returns the reconciling strategy registered with the reconciler - * for the specified content type. - * - * @param contentType the content type for which to determine the reconciling strategy - * @return the reconciling strategy registered for the given content type, or - * <code>null</code> if there is no such strategy - */ - IReconcilingStrategy getReconcilingStrategy(String contentType); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/reconciler/IReconcilingStrategy.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/reconciler/IReconcilingStrategy.java deleted file mode 100644 index b7f7a582a..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/reconciler/IReconcilingStrategy.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.reconciler; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; - - -/** - * A reconciling strategy is used by an reconciler to reconcile a model - * based on text of a particular content type. It provides methods for - * incremental as well as non-incremental reconciling. - * <p> - * If a reconcile strategy consists of several steps between which - * model transformation is desired the each step should implement - * {@link org.eclipse.jface.text.reconciler.IReconcileStep}. - * </p> - * <p> - * In order to provide backward compatibility for clients of <code>IReconcilingStrategy</code>, extension - * interfaces are used to provide a means of evolution. The following extension interfaces exist: - * <ul> - * <li>{@link org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension} since version 2.0 introducing - * the following functions: - * <ul> - * <li>usage of a progress monitor</li> - * <li>initial reconciling step: if a reconciler runs as periodic activity in the background, this - * methods offers the reconciler a chance for initializing its strategies and achieving a - * reconciled state before the periodic activity starts.</li> - * </ul> - * </li> - * </ul> - * </p> - * <p> - * This interface must be implemented by clients. Implementers should be - * registered with a reconciler in order get involved in the reconciling - * process. - * </p> - */ -public interface IReconcilingStrategy { - - /** - * Tells this reconciling strategy on which document it will - * work. This method will be called before any other method - * and can be called multiple times. The regions passed to the - * other methods always refer to the most recent document - * passed into this method. - * - * @param document the document on which this strategy will work - */ - void setDocument(IDocument document); - - /** - * Activates incremental reconciling of the specified dirty region. - * As a dirty region might span multiple content types, the segment of the - * dirty region which should be investigated is also provided to this - * reconciling strategy. The given regions refer to the document passed into - * the most recent call of {@link #setDocument(IDocument)}. - * - * @param dirtyRegion the document region which has been changed - * @param subRegion the sub region in the dirty region which should be reconciled - */ - void reconcile(DirtyRegion dirtyRegion, IRegion subRegion); - - /** - * Activates non-incremental reconciling. The reconciling strategy is just told - * that there are changes and that it should reconcile the given partition of the - * document most recently passed into {@link #setDocument(IDocument)}. - * - * @param partition the document partition to be reconciled - */ - void reconcile(IRegion partition); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/rules/DefaultDamagerRepairer.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/rules/DefaultDamagerRepairer.java deleted file mode 100644 index 602888b81..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/rules/DefaultDamagerRepairer.java +++ /dev/null @@ -1,231 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.rules; - - -import org.eclipse.fx.ui.controls.styledtext.StyleRange; -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.TextPresentation; -import org.eclipse.jface.text.presentation.IPresentationDamager; -import org.eclipse.jface.text.presentation.IPresentationRepairer; - - -/** - * A standard implementation of a syntax driven presentation damager - * and presentation repairer. It uses a token scanner to scan - * the document and to determine its damage and new text presentation. - * The tokens returned by the scanner are supposed to return text attributes - * as their data. - * - * @see ITokenScanner - * @since 2.0 - */ -public class DefaultDamagerRepairer implements IPresentationDamager, IPresentationRepairer { - - - /** The document this object works on */ - protected IDocument fDocument; - /** The scanner it uses */ - protected ITokenScanner fScanner; - /** The default text attribute if non is returned as data by the current token */ - protected TextAttribute fDefaultTextAttribute; - - /** - * Creates a damager/repairer that uses the given scanner and returns the given default - * text attribute if the current token does not carry a text attribute. - * - * @param scanner the token scanner to be used - * @param defaultTextAttribute the text attribute to be returned if non is specified by the current token, - * may not be <code>null</code> - * - * @deprecated use DefaultDamagerRepairer(ITokenScanner) instead - */ - public DefaultDamagerRepairer(ITokenScanner scanner, TextAttribute defaultTextAttribute) { - - Assert.isNotNull(defaultTextAttribute); - - fScanner= scanner; - fDefaultTextAttribute= defaultTextAttribute; - } - - /** - * Creates a damager/repairer that uses the given scanner. The scanner may not be <code>null</code> - * and is assumed to return only token that carry text attributes. - * - * @param scanner the token scanner to be used, may not be <code>null</code> - */ - public DefaultDamagerRepairer(ITokenScanner scanner) { - - Assert.isNotNull(scanner); - - fScanner= scanner; - fDefaultTextAttribute= new TextAttribute(null,null); - } - - /* - * @see IPresentationDamager#setDocument(IDocument) - * @see IPresentationRepairer#setDocument(IDocument) - */ - public void setDocument(IDocument document) { - fDocument= document; - } - - - //---- IPresentationDamager - - /** - * Returns the end offset of the line that contains the specified offset or - * if the offset is inside a line delimiter, the end offset of the next line. - * - * @param offset the offset whose line end offset must be computed - * @return the line end offset for the given offset - * @exception BadLocationException if offset is invalid in the current document - */ - protected int endOfLineOf(int offset) throws BadLocationException { - - IRegion info= fDocument.getLineInformationOfOffset(offset); - if (offset <= info.getOffset() + info.getLength()) - return info.getOffset() + info.getLength(); - - int line= fDocument.getLineOfOffset(offset); - try { - info= fDocument.getLineInformation(line + 1); - return info.getOffset() + info.getLength(); - } catch (BadLocationException x) { - return fDocument.getLength(); - } - } - - /** - * {@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. - */ - 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; - } - - //---- IPresentationRepairer - - /* - * @see IPresentationRepairer#createPresentation(TextPresentation, ITypedRegion) - */ - public void createPresentation(TextPresentation presentation, ITypedRegion region) { - - if (fScanner == null) { - // will be removed if deprecated constructor will be removed - addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextAttribute); - return; - } - - int lastStart= region.getOffset(); - int length= 0; - boolean firstToken= true; - IToken lastToken= Token.UNDEFINED; - TextAttribute lastAttribute= getTokenTextAttribute(lastToken); - - fScanner.setRange(fDocument, lastStart, region.getLength()); - - while (true) { - IToken token= fScanner.nextToken(); - if (token.isEOF()) - break; - - TextAttribute attribute= getTokenTextAttribute(token); - if (lastAttribute != null && lastAttribute.equals(attribute)) { - length += fScanner.getTokenLength(); - firstToken= false; - } else { - if (!firstToken) - addRange(presentation, lastStart, length, lastAttribute); - firstToken= false; - lastToken= token; - lastAttribute= attribute; - lastStart= fScanner.getTokenOffset(); - length= fScanner.getTokenLength(); - } - } - - addRange(presentation, lastStart, length, lastAttribute); - } - - /** - * Returns a text attribute encoded in the given token. If the token's - * data is not <code>null</code> and a text attribute it is assumed that - * it is the encoded text attribute. It returns the default text attribute - * if there is no encoded text attribute found. - * - * @param token the token whose text attribute is to be determined - * @return the token's text attribute - */ - protected TextAttribute getTokenTextAttribute(IToken token) { - Object data= token.getData(); - if (data instanceof TextAttribute) - return (TextAttribute) data; - return fDefaultTextAttribute; - } - - /** - * Adds style information to the given text presentation. - * - * @param presentation the text presentation to be extended - * @param offset the offset of the range to be styled - * @param length the length of the range to be styled - * @param attr the attribute describing the style of the range to be styled - */ - protected void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr) { - if (attr != null) { - int style= attr.getStyle(); - int fontStyle= style & (StyleRange.ITALIC | StyleRange.BOLD | StyleRange.NORMAL); - StyleRange styleRange= new StyleRange(attr.getStylename(), offset, length, attr.getForeground(), attr.getBackground(), fontStyle); - styleRange.strikeout= (style & TextAttribute.STRIKETHROUGH) != 0; - styleRange.underline= (style & TextAttribute.UNDERLINE) != 0; - styleRange.font= attr.getFont(); - presentation.addStyleRange(styleRange); - } - } -} - - diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPainter.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPainter.java deleted file mode 100644 index 5b062132c..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPainter.java +++ /dev/null @@ -1,638 +0,0 @@ -package org.eclipse.jface.text.source; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.Map.Entry; - -import javafx.application.Platform; -import javafx.scene.paint.Color; - -import org.eclipse.fx.ui.controls.styledtext.StyleRange; -import org.eclipse.fx.ui.controls.styledtext.StyledTextArea; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextInputListener; -import org.eclipse.jface.text.ITextPresentationListener; -import org.eclipse.jface.text.ITextViewerExtension2; -import org.eclipse.jface.text.ITextViewerExtension5; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextPresentation; - -public class AnnotationPainter implements IAnnotationModelListener, IAnnotationModelListenerExtension, ITextPresentationListener { - /** - * Mutex for for decorations map. - * @since 3.0 - */ - private Object fHighlightedDecorationsMapLock= new Object(); - - private Map<Annotation,Decoration> fHighlightedDecorationsMap= new HashMap<>(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=50767 - - /** - * The presentation information (decoration) for an annotation. Each such - * object represents one decoration drawn on the text area, such as squiggly lines - * and underlines. - */ - private static class Decoration { - /** The position of this decoration */ - private Position fPosition; - /** The color of this decoration */ - private String fAnnotationClass; - /** - * The annotation's layer - * @since 3.0 - */ - private int fLayer; - /** - * The painting strategy for this decoration. - * @since 3.0 - */ - private Object fPaintingStrategy; - } - - /** - * A text style painting strategy draws the decoration for an annotation - * onto the text widget by applying a {@link TextStyle} on a given - * {@link StyleRange}. - * - * @since 3.4 - */ - public interface ITextStyleStrategy { - - /** - * Applies a text style on the given <code>StyleRange</code>. - * - * @param styleRange the style range on which to apply the text style - * @param annotationColor the color of the annotation - */ -// void applyTextStyle(StyleRange styleRange, Color annotationColor); - void applyTextStyle(StyleRange styleRange, String annotationStyleClass); - } - - - private ISourceViewer fSourceViewer; - /** The cached widget of the source viewer */ - private StyledTextArea fTextWidget; - /** The annotation model providing the annotations to be drawn */ -// private IAnnotationModel fModel; - /** The annotation access */ - private IAnnotationAccess fAnnotationAccess; - - private Object fDecorationMapLock= new Object(); -// private Map fDecorationsMap= new HashMap(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=50767 - - private Position fTotalHighlightAnnotationRange= null; - - /** - * The range in which the current highlight annotations can be found. - * @since 3.0 - */ - private Position fCurrentHighlightAnnotationRange= null; - private Map fCachedAnnotationType2PaintingStrategy= new HashMap(); - private Map fPaintingStrategyId2PaintingStrategy= new HashMap(); - private Map fAnnotationType2PaintingStrategyId= new HashMap(); - private Map fCachedAnnotationType2Color= new HashMap(); - private Map fAnnotationType2Color= new HashMap(); - - private volatile boolean fIsSettingModel= false; - private boolean fInputDocumentAboutToBeChanged; - private ITextInputListener fTextInputListener; - - /** - * Creates a new annotation painter for the given source viewer and with the - * given annotation access. The painter is not initialized, i.e. no - * annotation types are configured to be painted. - * - * @param sourceViewer the source viewer for this painter - * @param access the annotation access for this painter - */ - public AnnotationPainter(ISourceViewer sourceViewer, IAnnotationAccess access) { - fSourceViewer= sourceViewer; - fAnnotationAccess= access; - fTextWidget= sourceViewer.getTextWidget(); - } - - /** - * Updates the set of decorations based on the current state of - * the painter's annotation model. - * - * @param event the annotation model event - */ - private void catchupWithModel(AnnotationModelEvent event) { - - synchronized (fDecorationMapLock) { -// if (fDecorationsMap == null) -// return; - } - - if (fSourceViewer.getAnnotationModel() == null) { - // annotation model is null -> clear all -// synchronized (fDecorationMapLock) { -// fDecorationsMap.clear(); -// } - synchronized (fHighlightedDecorationsMapLock) { - fHighlightedDecorationsMap.clear(); - } - return; - } - -// IRegion clippingRegion= computeClippingRegion(null, true); - IDocument document= fSourceViewer.getDocument(); - - int highlightAnnotationRangeStart= Integer.MAX_VALUE; - int highlightAnnotationRangeEnd= -1; - - int drawRangeStart= Integer.MAX_VALUE; - int drawRangeEnd= -1; - -// Map decorationsMap; - Map highlightedDecorationsMap; - - // Clone decoration maps -// synchronized (fDecorationMapLock) { -// decorationsMap= new HashMap(fDecorationsMap); -// } - synchronized (fHighlightedDecorationsMapLock) { - highlightedDecorationsMap= new HashMap<>(fHighlightedDecorationsMap); - } - - boolean isWorldChange= false; - - Iterator e; - if (event == null || event.isWorldChange()) { - isWorldChange= true; - -// if (DEBUG && event == null) -// System.out.println("AP: INTERNAL CHANGE"); //$NON-NLS-1$ - -// Iterator iter= decorationsMap.entrySet().iterator(); -// while (iter.hasNext()) { -// Map.Entry entry= (Map.Entry)iter.next(); -// Annotation annotation= (Annotation)entry.getKey(); -// Decoration decoration= (Decoration)entry.getValue(); -//// drawDecoration(decoration, null, annotation, clippingRegion, document); -// } - -// decorationsMap.clear(); - - highlightedDecorationsMap.clear(); - - e= fSourceViewer.getAnnotationModel().getAnnotationIterator(); - - - } else { - - // Remove annotations - Annotation[] removedAnnotations= event.getRemovedAnnotations(); - for (int i= 0, length= removedAnnotations.length; i < length; i++) { - Annotation annotation= removedAnnotations[i]; - Decoration decoration= (Decoration)highlightedDecorationsMap.remove(annotation); - if (decoration != null) { - Position position= decoration.fPosition; - if (position != null) { - highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, position.offset); - highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, position.offset + position.length); - } - } -// decoration= (Decoration)decorationsMap.remove(annotation); -// if (decoration != null) { -//// drawDecoration(decoration, null, annotation, clippingRegion, document); -// Position position= decoration.fPosition; -// if (position != null) { -// drawRangeStart= Math.min(drawRangeStart, position.offset); -// drawRangeEnd= Math.max(drawRangeEnd, position.offset + position.length); -// } -// } - - } - - // Update existing annotations - Annotation[] changedAnnotations= event.getChangedAnnotations(); - for (int i= 0, length= changedAnnotations.length; i < length; i++) { - Annotation annotation= changedAnnotations[i]; - - boolean isHighlighting= false; - - Decoration decoration= (Decoration)highlightedDecorationsMap.get(annotation); - - if (decoration != null) { - isHighlighting= true; - // The call below updates the decoration - no need to create new decoration - decoration= getDecoration(annotation, decoration); - if (decoration == null) { - Decoration removedDecoration= (Decoration)highlightedDecorationsMap.remove(annotation); - if (removedDecoration != null) { - highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, removedDecoration.fPosition.offset); - highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, removedDecoration.fPosition.offset + removedDecoration.fPosition.length); - } - } - - } else { - decoration= getDecoration(annotation, decoration); - if (decoration != null && decoration.fPaintingStrategy instanceof ITextStyleStrategy) { - highlightedDecorationsMap.put(annotation, decoration); - isHighlighting= true; - } - } - - boolean usesDrawingStrategy= !isHighlighting && decoration != null; - - Position position= null; - if (decoration == null) - position= fSourceViewer.getAnnotationModel().getPosition(annotation); - else - position= decoration.fPosition; - - if (position != null && !position.isDeleted()) { - if (isHighlighting) { - highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, position.offset); - highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, position.offset + position.length); - } - if (usesDrawingStrategy) { - drawRangeStart= Math.min(drawRangeStart, position.offset); - drawRangeEnd= Math.max(drawRangeEnd, position.offset + position.length); - } - } else { - Decoration removedDecoration= (Decoration)highlightedDecorationsMap.remove(annotation); - if (removedDecoration != null) { - highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, removedDecoration.fPosition.offset); - highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, removedDecoration.fPosition.offset + removedDecoration.fPosition.length); - } - } - -// if (usesDrawingStrategy) { -// Decoration oldDecoration= (Decoration)decorationsMap.get(annotation); -// if (oldDecoration != null) { -//// drawDecoration(oldDecoration, null, annotation, clippingRegion, document); -// if (decoration != null) -// decorationsMap.put(annotation, decoration); -// else -// decorationsMap.remove(annotation); -// } -// } - } - - e= Arrays.asList(event.getAddedAnnotations()).iterator(); - } - - // Add new annotations - while (e.hasNext()) { - Annotation annotation= (Annotation)e.next(); - Decoration pp= getDecoration(annotation, null); - if (pp != null) { -// if (pp.fPaintingStrategy instanceof IDrawingStrategy) { -// decorationsMap.put(annotation, pp); -// drawRangeStart= Math.min(drawRangeStart, pp.fPosition.offset); -// drawRangeEnd= Math.max(drawRangeEnd, pp.fPosition.offset + pp.fPosition.length); -// } else - if (pp.fPaintingStrategy instanceof ITextStyleStrategy) { - highlightedDecorationsMap.put(annotation, pp); - highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, pp.fPosition.offset); - highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, pp.fPosition.offset + pp.fPosition.length); - } - - } - } - -// synchronized (fDecorationMapLock) { -// fDecorationsMap= decorationsMap; -// updateDrawRanges(drawRangeStart, drawRangeEnd, isWorldChange); -// } - - synchronized (fHighlightedDecorationsMapLock) { - fHighlightedDecorationsMap= highlightedDecorationsMap; - updateHighlightRanges(highlightAnnotationRangeStart, highlightAnnotationRangeEnd, isWorldChange); - } - } - - @Override - public void applyTextPresentation(TextPresentation tp) { - Set<Entry<Annotation,Decoration>> decorations; - - synchronized (fHighlightedDecorationsMapLock) { - if (fHighlightedDecorationsMap == null || fHighlightedDecorationsMap.isEmpty()) - return; - - decorations= new HashSet<>(fHighlightedDecorationsMap.entrySet()); - } - - IRegion region= tp.getExtent(); - -// if (DEBUG) -// System.out.println("AP: applying text presentation offset: " + region.getOffset() + ", length= " + region.getLength()); //$NON-NLS-1$ //$NON-NLS-2$ - - for (int layer= 0, maxLayer= 1; layer < maxLayer; layer++) { - - for (Iterator<?> iter= decorations.iterator(); iter.hasNext();) { - Map.Entry entry= (Map.Entry)iter.next(); - - Annotation a= (Annotation)entry.getKey(); - if (a.isMarkedDeleted()) - continue; - - Decoration pp = (Decoration)entry.getValue(); - - maxLayer= Math.max(maxLayer, pp.fLayer + 1); // dynamically update layer maximum - if (pp.fLayer != layer) // wrong layer: skip annotation - continue; - - Position p= pp.fPosition; - if (fSourceViewer instanceof ITextViewerExtension5) { - ITextViewerExtension5 extension3= (ITextViewerExtension5) fSourceViewer; - if (null == extension3.modelRange2WidgetRange(new Region(p.getOffset(), p.getLength()))) - continue; - } else if (!fSourceViewer.overlapsWithVisibleRegion(p.offset, p.length)) { - continue; - } - - int regionEnd= region.getOffset() + region.getLength(); - int pEnd= p.getOffset() + p.getLength(); - if (pEnd >= region.getOffset() && regionEnd > p.getOffset()) { - int start= Math.max(p.getOffset(), region.getOffset()); - int end= Math.min(regionEnd, pEnd); - int length= Math.max(end - start, 0); - StyleRange styleRange= new StyleRange(null,start, length, null, null); - ((ITextStyleStrategy)pp.fPaintingStrategy).applyTextStyle(styleRange, pp.fAnnotationClass); - tp.mergeStyleRange(styleRange); - } - } - } - } - - private Decoration getDecoration(Annotation annotation, Decoration decoration) { - - if (annotation.isMarkedDeleted()) - return null; - - String type= annotation.getType(); - - Object paintingStrategy= getPaintingStrategy(type); - if (paintingStrategy == null) - return null; - - String color= getColor(type); - if (color == null) - return null; - - Position position= fSourceViewer.getAnnotationModel().getPosition(annotation); - if (position == null || position.isDeleted()) - return null; - - if (decoration == null) - decoration= new Decoration(); - - decoration.fPosition= position; - decoration.fAnnotationClass= color; -// if (fAnnotationAccess instanceof IAnnotationAccessExtension) { -// IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess; -// decoration.fLayer= extension.getLayer(annotation); -// } else { -// decoration.fLayer= IAnnotationAccessExtension.DEFAULT_LAYER; -// } - - decoration.fPaintingStrategy= paintingStrategy; - - return decoration; - } - - private void updateHighlightRanges(int highlightAnnotationRangeStart, int highlightAnnotationRangeEnd, boolean isWorldChange) { - if (highlightAnnotationRangeStart != Integer.MAX_VALUE) { - - int maxRangeStart= highlightAnnotationRangeStart; - int maxRangeEnd= highlightAnnotationRangeEnd; - - if (fTotalHighlightAnnotationRange != null) { - maxRangeStart= Math.min(maxRangeStart, fTotalHighlightAnnotationRange.offset); - maxRangeEnd= Math.max(maxRangeEnd, fTotalHighlightAnnotationRange.offset + fTotalHighlightAnnotationRange.length); - } - - if (fTotalHighlightAnnotationRange == null) - fTotalHighlightAnnotationRange= new Position(0); - if (fCurrentHighlightAnnotationRange == null) - fCurrentHighlightAnnotationRange= new Position(0); - - if (isWorldChange) { - fTotalHighlightAnnotationRange.offset= highlightAnnotationRangeStart; - fTotalHighlightAnnotationRange.length= highlightAnnotationRangeEnd - highlightAnnotationRangeStart; - fCurrentHighlightAnnotationRange.offset= maxRangeStart; - fCurrentHighlightAnnotationRange.length= maxRangeEnd - maxRangeStart; - } else { - fTotalHighlightAnnotationRange.offset= maxRangeStart; - fTotalHighlightAnnotationRange.length= maxRangeEnd - maxRangeStart; - fCurrentHighlightAnnotationRange.offset=highlightAnnotationRangeStart; - fCurrentHighlightAnnotationRange.length= highlightAnnotationRangeEnd - highlightAnnotationRangeStart; - } - } else { - if (isWorldChange) { - fCurrentHighlightAnnotationRange= fTotalHighlightAnnotationRange; - fTotalHighlightAnnotationRange= null; - } else { - fCurrentHighlightAnnotationRange= null; - } - } - - adaptToDocumentLength(fCurrentHighlightAnnotationRange); - adaptToDocumentLength(fTotalHighlightAnnotationRange); - } - - private void adaptToDocumentLength(Position position) { - if (position == null) - return; - - int length= fSourceViewer.getDocument().getLength(); - position.offset= Math.min(position.offset, length); - position.length= Math.min(position.length, length - position.offset); - } - - /** - * Returns the painting strategy for the given annotation. - * - * @param type the annotation type - * @return the annotation painter - * @since 3.0 - */ - private Object getPaintingStrategy(final String type) { - Object strategy= fCachedAnnotationType2PaintingStrategy.get(type); - if (strategy != null) - return strategy; - - strategy= fPaintingStrategyId2PaintingStrategy.get(fAnnotationType2PaintingStrategyId.get(type)); - if (strategy != null) { - fCachedAnnotationType2PaintingStrategy.put(type, strategy); - return strategy; - } - - if (fAnnotationAccess instanceof IAnnotationAccessExtension) { - IAnnotationAccessExtension ext = (IAnnotationAccessExtension) fAnnotationAccess; - Object[] sts = ext.getSupertypes(type); - for (int i= 0; i < sts.length; i++) { - strategy= fPaintingStrategyId2PaintingStrategy.get(fAnnotationType2PaintingStrategyId.get(sts[i])); - if (strategy != null) { - fCachedAnnotationType2PaintingStrategy.put(type, strategy); - return strategy; - } - } - } - - fCachedAnnotationType2PaintingStrategy.put(type, null); - return null; - - } - - private String getColor(final Object annotationType) { - String color= (String)fCachedAnnotationType2Color.get(annotationType); - if (color != null) - return color; - - color= (String)fAnnotationType2Color.get(annotationType); - if (color != null) { - fCachedAnnotationType2Color.put(annotationType, color); - return color; - } - - if (fAnnotationAccess instanceof IAnnotationAccessExtension) { - IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess; - Object[] superTypes= extension.getSupertypes(annotationType); - if (superTypes != null) { - for (int i= 0; i < superTypes.length; i++) { - color= (String)fAnnotationType2Color.get(superTypes[i]); - if (color != null) { - fCachedAnnotationType2Color.put(annotationType, color); - return color; - } - } - } - } - - return null; - } - - private void updatePainting(AnnotationModelEvent event) { -// disablePainting(event == null); - - catchupWithModel(event); - - if (!fInputDocumentAboutToBeChanged) - invalidateTextPresentation(); - -// enablePainting(); - } - - private void invalidateTextPresentation() { - IRegion r= null; - synchronized (fHighlightedDecorationsMapLock) { - if (fCurrentHighlightAnnotationRange != null) - r= new Region(fCurrentHighlightAnnotationRange.getOffset(), fCurrentHighlightAnnotationRange.getLength()); - } - if (r == null) - return; - - if (fSourceViewer instanceof ITextViewerExtension2) { -// if (DEBUG) -// System.out.println("AP: invalidating offset: " + r.getOffset() + ", length= " + r.getLength()); //$NON-NLS-1$ //$NON-NLS-2$ - - ((ITextViewerExtension2)fSourceViewer).invalidateTextPresentation(r.getOffset(), r.getLength()); - - } else { - fSourceViewer.invalidateTextPresentation(); - } - } - - - - @Override - public void modelChanged(AnnotationModelEvent event) { -// Display textWidgetDisplay; -// try { -// StyledText textWidget= fTextWidget; -// if (textWidget == null || textWidget.isDisposed()) -// return; -// textWidgetDisplay= textWidget.getDisplay(); -// } catch (SWTException ex) { -// if (ex.code == SWT.ERROR_WIDGET_DISPOSED) -// return; -// throw ex; -// } - - if (fIsSettingModel) { - // inside the UI thread -> no need for posting - if( Platform.isFxApplicationThread() ) { - updatePainting(event); - } - else { - /* - * we can throw away the changes since - * further update painting will happen - */ - return; - } - } else { -// if (DEBUG && event != null && event.isWorldChange()) { -// System.out.println("AP: WORLD CHANGED, stack trace follows:"); //$NON-NLS-1$ -// new Throwable().printStackTrace(System.out); -// } - - // XXX: posting here is a problem for annotations that are being - // removed and the positions of which are not updated to document - // changes any more. If the document gets modified between - // now and running the posted runnable, the position information - // is not accurate any longer. - Platform.runLater(() -> updatePainting(event)); - - } - } - - @Override - public void modelChanged(IAnnotationModel model) { - modelChanged(new AnnotationModelEvent(model)); - } - - - public void addAnnotationType(Object annotationType, Object strategyID) { - fAnnotationType2PaintingStrategyId.put(annotationType, strategyID); - fCachedAnnotationType2PaintingStrategy.clear(); - - if (fTextInputListener == null) { - fTextInputListener= new ITextInputListener() { - - /* - * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument) - */ - public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { - fInputDocumentAboutToBeChanged= true; - } - - /* - * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument) - */ - public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { - fInputDocumentAboutToBeChanged= false; - } - }; - fSourceViewer.addTextInputListener(fTextInputListener); - } - - } - - public void setAnnotationTypeColor(Object annotationType, String color) { - if (color != null) - fAnnotationType2Color.put(annotationType, color); - else - fAnnotationType2Color.remove(annotationType); - fCachedAnnotationType2Color.clear(); - } - - public void addTextStyleStrategy(Object id, ITextStyleStrategy strategy) { - // don't permit null as null is used to signal that an annotation type is not - // registered with a specific strategy, and that its annotation hierarchy should be searched - if (id == null) - throw new IllegalArgumentException(); - fPaintingStrategyId2PaintingStrategy.put(id, strategy); - fCachedAnnotationType2PaintingStrategy.clear(); - } - -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPresenter.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPresenter.java deleted file mode 100644 index f0bfca63c..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPresenter.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.eclipse.jface.text.source; - -import java.util.List; - -import org.eclipse.fx.ui.services.resources.GraphicsLoader; - -import javafx.scene.Node; - -public interface AnnotationPresenter { - public List<String> getTypes(); - public Node getPresentation(Annotation annotation, GraphicsLoader loader); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccess.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccess.java deleted file mode 100644 index 06c6ab185..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccess.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - -/** - * An annotation access provides access to information that is not available via - * the API of {@link org.eclipse.jface.text.source.Annotation}. With version - * 3.0 all this information is now available from the annotation itself. - * <p> - * - * In order to provide backward compatibility for clients of - * <code>IAnnotationAccess</code>, extension interfaces are used as a means - * of evolution. The following extension interfaces exist: - * <ul> - * <li>{@link org.eclipse.jface.text.source.IAnnotationAccessExtension} since - * version 3.0 replacing all methods in that interface</li> - * <li>{@link IAnnotationAccessExtension2} since - * version 3.2 allowing to set a quick assist assistant to an annotation access.</li> - * </ul></p> - * <p> - * Clients usually implement this interface and its extension interfaces.</p> - * - * @see org.eclipse.jface.text.source.IAnnotationAccessExtension - * @see org.eclipse.jface.text.source.Annotation - * @since 2.1 - */ -public interface IAnnotationAccess { - - /** - * Returns the type of the given annotation. - * - * @param annotation the annotation - * @return the type of the given annotation or <code>null</code> if it has none. - * @deprecated use <code>Annotation.getType()</code> - */ - Object getType(Annotation annotation); - - /** - * Returns whether the given annotation spans multiple lines. - * - * @param annotation the annotation - * @return <code>true</code> if the annotation spans multiple lines, - * <code>false</code> otherwise - * - * @deprecated assumed to always return <code>true</code> - */ - boolean isMultiLine(Annotation annotation); - - /** - * Returns whether the given annotation is temporary rather than persistent. - * - * @param annotation the annotation - * @return <code>true</code> if the annotation is temporary, - * <code>false</code> otherwise - * @deprecated use <code>Annotation.isPersistent()</code> - */ - boolean isTemporary(Annotation annotation); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java deleted file mode 100644 index 7c500fc5c..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - -/** - * Extension interface for {@link org.eclipse.jface.text.source.IAnnotationAccess}.<p> - * This interface replaces the methods of <code>IAnnotationAccess</code>.<p> - * This interface provides - * <ul> - * <li> a label for the annotation type of a given annotation</li> - * <li> the paint layer of a given annotation</li> - * <li> means to paint a given annotation</li> - * <li> information about the type hierarchy of the annotation type of a given annotation</li> - * <ul>. - * - * @see org.eclipse.jface.text.source.IAnnotationAccess - * @since 3.0 - */ -public interface IAnnotationAccessExtension { - - /** - * The default annotation layer. - */ - static final int DEFAULT_LAYER= IAnnotationPresentation.DEFAULT_LAYER; - - /** - * Returns the label for the given annotation's type. - * - * @param annotation the annotation - * @return the label the given annotation's type or <code>null</code> if no such label exists - */ - String getTypeLabel(Annotation annotation); - - /** - * Returns the layer for given annotation. Annotations are considered - * being located at layers and are considered being painted starting with - * layer 0 upwards. Thus an annotation at layer 5 will be drawn on top of - * all co-located annotations at the layers 4 - 0. - * - * @param annotation the annotation - * @return the layer of the given annotation - */ - int getLayer(Annotation annotation); - -// /** -// * Draws a graphical representation of the given annotation within the given bounds. -// * <p> -// * <em>Note that this method is not used when drawing annotations on the editor's -// * text widget. This is handled trough a {@link org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy}.</em> -// * </p> -// * @param annotation the given annotation -// * @param gc the drawing GC -// * @param canvas the canvas to draw on -// * @param bounds the bounds inside the canvas to draw on -// */ -// void paint(Annotation annotation, GC gc, Canvas canvas, Rectangle bounds); - - /** - * Returns <code>true</code> if painting <code>annotation</code> will produce something - * meaningful, <code>false</code> if not. E.g. if no image is available. - * <p> - * <em>Note that this method is not used when drawing annotations on the editor's - * text widget. This is handled trough a {@link org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy}.</em> - * </p> - * @param annotation the annotation to check whether it can be painted - * @return <code>true</code> if painting <code>annotation</code> will succeed - */ - boolean isPaintable(Annotation annotation); - - /** - * Returns <code>true</code> if the given annotation is of the given type - * or <code>false</code> otherwise. - * - * @param annotationType the annotation type - * @param potentialSupertype the potential super annotation type - * @return <code>true</code> if annotation type is a sub-type of the potential annotation super type - */ - boolean isSubtype(Object annotationType, Object potentialSupertype); - - /** - * Returns the list of super types for the given annotation type. This does not include the type - * itself. The index in the array of super types indicates the length of the path in the hierarchy - * graph to the given annotation type. - * - * @param annotationType the annotation type to check - * @return the super types for the given annotation type - */ - Object[] getSupertypes(Object annotationType); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationPresentation.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationPresentation.java deleted file mode 100644 index 0a44ef928..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationPresentation.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - -/** - * Interface for annotations that can take care of their own visible representation. - * - * @since 3.0 - */ -public interface IAnnotationPresentation { - - /** - * The default annotation layer. - */ - static final int DEFAULT_LAYER= 0; - - - /** - * Returns the annotations drawing layer. - * - * @return the annotations drawing layer - */ - int getLayer(); - -// /** -// * Implement this method to draw a graphical representation -// * of this annotation within the given bounds. -// * <p> -// * <em>Note that this method is not used when drawing annotations on the editor's -// * text widget. This is handled trough a {@link org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy}.</em> -// * </p> -// * @param gc the drawing GC -// * @param canvas the canvas to draw on -// * @param bounds the bounds inside the canvas to draw on -// */ -// void paint(GC gc, Canvas canvas, Rectangle bounds); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewer.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewer.java deleted file mode 100644 index b8722e129..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewer.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.eclipse.jface.text.source; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextViewer; - -public interface ISourceViewer extends ITextViewer { - void configure(SourceViewerConfiguration configuration); - void setDocument(IDocument document, IAnnotationModel annotationModel); - public void setDocument(IDocument document, IAnnotationModel annotationModel, int modelRangeOffset, int modelRangeLength); - IAnnotationModel getAnnotationModel(); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewerExtension.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewerExtension.java deleted file mode 100644 index 5fd1cd1ca..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewerExtension.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.eclipse.jface.text.source; - -public interface ISourceViewerExtension { - -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewerExtension2.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewerExtension2.java deleted file mode 100644 index 925eef77e..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewerExtension2.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.eclipse.jface.text.source; - -public interface ISourceViewerExtension2 { - -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewerExtension3.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewerExtension3.java deleted file mode 100644 index 495c4cbbb..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewerExtension3.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.eclipse.jface.text.source; - -public interface ISourceViewerExtension3 { - -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewerExtension4.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewerExtension4.java deleted file mode 100644 index f54fa74a8..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewerExtension4.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.eclipse.jface.text.source; - -public interface ISourceViewerExtension4 { - -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewer.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewer.java deleted file mode 100644 index 9bf91b7a8..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewer.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Tom Eicher (Avaloq Evolution AG) - block selection mode - * Tom Hofmann (Perspectix AG) - bug 297572 - *******************************************************************************/ -package org.eclipse.jface.text.source; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.stream.Collectors; - -import javafx.application.Platform; -import javafx.scene.Node; - -import org.eclipse.fx.ui.controls.styledtext.StyledTextArea.StyledTextLine; -import org.eclipse.fx.ui.services.resources.GraphicsLoader; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ISynchronizable; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.TextViewer; -import org.eclipse.jface.text.contentassist.IContentAssistant; -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.reconciler.IReconciler; - -public class SourceViewer extends TextViewer implements ISourceViewer, ISourceViewerExtension, ISourceViewerExtension2, ISourceViewerExtension3, ISourceViewerExtension4 { - - private IPresentationReconciler fPresentationReconciler; - private IReconciler fReconciler; - private IAnnotationModel fVisualAnnotationModel; - protected final static Object MODEL_ANNOTATION_MODEL= new Object(); - private Map<String, AnnotationPresenter> presenterMap = new HashMap<>(); - private GraphicsLoader graphicsLoader; - - @Override - public void configure(SourceViewerConfiguration configuration) { - if (getTextWidget() == null) - return; - - getTextWidget().getStyleClass().add(configuration.getStyleclassName()); - -// if( configuration.getDefaultStylesheet().getValue() != null ) { -// getTextWidget().getStylesheets().add(configuration.getDefaultStylesheet().getValue().toExternalForm()); -// } -// -// configuration.getDefaultStylesheet().addListener((obs,oldVal,newVal) -> { -// if( oldVal != null ) { -// getTextWidget().getStylesheets().remove(oldVal.toExternalForm()); -// } -// if( newVal != null ) { -// getTextWidget().getStylesheets().add(newVal.toExternalForm()); -// } -// }); - - setDocumentPartitioning(configuration.getConfiguredDocumentPartitioning(this)); - - // install content type independent plug-ins - fPresentationReconciler= configuration.getPresentationReconciler(this); - if (fPresentationReconciler != null) - fPresentationReconciler.install(this); - - fReconciler= configuration.getReconciler(this); - if (fReconciler != null) - fReconciler.install(this); - - IContentAssistant assist = configuration.getContentAssist(); - if( assist != null ) { - assist.install(this); - } - - //TODO This is complete different to JFace-Text - IAnnotationModel annotationModel = configuration.getAnnotationModel(); - if( annotationModel != null ) { - getTextWidget().setLineRulerGraphicNodeFactory(this::annotationFactory); - annotationModel.addAnnotationModelListener(new IAnnotationModelListener() { - - private boolean scheduled = false; - - @Override - public void modelChanged(IAnnotationModel model) { - if( ! scheduled ) { - scheduled = true; - Platform.runLater(() -> { - scheduled = false; - System.err.println("REFRESHING"); - getTextWidget().refreshLineRuler(); - }); - } - } - - }); - } - - if( configuration.getAnnotationPresenters() != null ) { - configuration.getAnnotationPresenters().stream().forEach(p -> p.getTypes().forEach( s -> presenterMap.put(s,p))); - } - -// presenterMap.putAll(configuration.getAnnotationPresenters().stream().collect(Collectors.toMap(p -> p.getType(), p -> p))); - graphicsLoader = configuration.getGraphicsLoader(); - - AnnotationPainter annotationPainter = configuration.getAnnotationPainter(this); - if( annotationModel != null && annotationPainter != null ) { - annotationModel.addAnnotationModelListener(annotationPainter); - addTextPresentationListener(annotationPainter); - } - } - - private Node annotationFactory(StyledTextLine l) { - //TODO Should use IAnnotationExtension2 - @SuppressWarnings("unchecked") - Iterator<Annotation> annotationIterator = fVisualAnnotationModel.getAnnotationIterator(); - while( annotationIterator.hasNext() ) { - Annotation a = annotationIterator.next(); - Position position = fVisualAnnotationModel.getPosition(a); - - if( l.getLineIndex() == getTextWidget().getContent().getLineAtOffset(position.offset) ) { - AnnotationPresenter annotationPresenter = presenterMap.get(a.getType()); - if( annotationPresenter != null ) { - return annotationPresenter.getPresentation(a, graphicsLoader); - } - return null; - } - } - return null; - } - - /** - * Disposes the visual annotation model. - * - * @since 3.1 - */ - protected void disposeVisualAnnotationModel() { - if (fVisualAnnotationModel != null) { - if (getDocument() != null) - fVisualAnnotationModel.disconnect(getDocument()); - - if ( fVisualAnnotationModel instanceof IAnnotationModelExtension) - ((IAnnotationModelExtension)fVisualAnnotationModel).removeAnnotationModel(MODEL_ANNOTATION_MODEL); - - fVisualAnnotationModel= null; - } - } - - /** - * Creates the visual annotation model on top of the given annotation model. - * - * @param annotationModel the wrapped annotation model - * @return the visual annotation model on top of the given annotation model - * @since 3.0 - */ - protected IAnnotationModel createVisualAnnotationModel(IAnnotationModel annotationModel) { - IAnnotationModelExtension model= new AnnotationModel(); - model.addAnnotationModel(MODEL_ANNOTATION_MODEL, annotationModel); - return (IAnnotationModel) model; - } - - public void setDocument(IDocument document, IAnnotationModel annotationModel) { - setDocument(document, annotationModel, -1, -1); - } - - @Override - public void setDocument(IDocument document, IAnnotationModel annotationModel, int modelRangeOffset, int modelRangeLength) { - disposeVisualAnnotationModel(); - - if (annotationModel != null && document != null) { - fVisualAnnotationModel= createVisualAnnotationModel(annotationModel); - - // Make sure the visual model uses the same lock as the underlying model - if (annotationModel instanceof ISynchronizable && fVisualAnnotationModel instanceof ISynchronizable) { - ISynchronizable sync= (ISynchronizable)fVisualAnnotationModel; - sync.setLockObject(((ISynchronizable)annotationModel).getLockObject()); - } - - fVisualAnnotationModel.connect(document); - } - - if (modelRangeOffset == -1 && modelRangeLength == -1) - super.setDocument(document); - else - super.setDocument(document, modelRangeOffset, modelRangeLength); - } - - @Override - public IAnnotationModel getAnnotationModel() { - return fVisualAnnotationModel; - } -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java deleted file mode 100644 index f92067b93..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - -import java.util.Collections; -import java.util.List; - -import javax.inject.Inject; - -import org.eclipse.fx.ui.services.resources.GraphicsLoader; -import org.eclipse.jface.text.IDocumentExtension3; -import org.eclipse.jface.text.contentassist.IContentAssistant; -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.presentation.PresentationReconciler; -import org.eclipse.jface.text.reconciler.IReconciler; - -public abstract class SourceViewerConfiguration { - public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) { - return IDocumentExtension3.DEFAULT_PARTITIONING; - } - - public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { - PresentationReconciler reconciler= new PresentationReconciler(); - reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); - return reconciler; - } - - public abstract String getStyleclassName(); - - public IReconciler getReconciler(ISourceViewer sourceViewer) { - return null; - } - - public IContentAssistant getContentAssist() { - return null; - } - - public IAnnotationModel getAnnotationModel() { - return null; - } - - public List<AnnotationPresenter> getAnnotationPresenters() { - return Collections.emptyList(); - } - - public AnnotationPainter getAnnotationPainter(ISourceViewer sourceViewer) { - return null; - } - - @Inject - GraphicsLoader graphicsLoader; - - public GraphicsLoader getGraphicsLoader() { - return graphicsLoader; - } -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/viewers/IInputSelectionProvider.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/viewers/IInputSelectionProvider.java deleted file mode 100644 index 34de0cd52..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/viewers/IInputSelectionProvider.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.eclipse.jface.viewers; - -public interface IInputSelectionProvider { - public Object getInput(); -} diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/viewers/Viewer.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/viewers/Viewer.java deleted file mode 100644 index 6f8160dd0..000000000 --- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/viewers/Viewer.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.eclipse.jface.viewers; - -import javafx.scene.layout.AnchorPane; - -public abstract class Viewer extends AnchorPane { - protected void inputChanged(Object input, Object oldInput) { - } - - public abstract void setInput(Object input); -} diff --git a/experimental/compensator/org.eclipse.fx.text/.classpath b/experimental/compensator/org.eclipse.fx.text/.classpath deleted file mode 100644 index eca7bdba8..000000000 --- a/experimental/compensator/org.eclipse.fx.text/.classpath +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="src" path="src"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/experimental/compensator/org.eclipse.fx.text/.gitignore b/experimental/compensator/org.eclipse.fx.text/.gitignore deleted file mode 100644 index ae3c17260..000000000 --- a/experimental/compensator/org.eclipse.fx.text/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/experimental/compensator/org.eclipse.fx.text/.project b/experimental/compensator/org.eclipse.fx.text/.project deleted file mode 100644 index bef853f43..000000000 --- a/experimental/compensator/org.eclipse.fx.text/.project +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.fx.text</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/experimental/compensator/org.eclipse.fx.text/.settings/org.eclipse.jdt.core.prefs b/experimental/compensator/org.eclipse.fx.text/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 0c68a61dc..000000000 --- a/experimental/compensator/org.eclipse.fx.text/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/experimental/compensator/org.eclipse.fx.text/META-INF/MANIFEST.MF b/experimental/compensator/org.eclipse.fx.text/META-INF/MANIFEST.MF deleted file mode 100644 index 3d0ae3d6f..000000000 --- a/experimental/compensator/org.eclipse.fx.text/META-INF/MANIFEST.MF +++ /dev/null @@ -1,12 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: Text -Bundle-SymbolicName: org.eclipse.fx.text -Bundle-Version: 1.0.0.qualifier -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Export-Package: org.eclipse.jface.text, - org.eclipse.jface.text.rules, - org.eclipse.jface.text.source -Require-Bundle: org.eclipse.text;bundle-version="3.5.300", - org.eclipse.equinox.common;bundle-version="3.6.200", - org.eclipse.core.runtime;bundle-version="3.10.0" diff --git a/experimental/compensator/org.eclipse.fx.text/build.properties b/experimental/compensator/org.eclipse.fx.text/build.properties deleted file mode 100644 index 34d2e4d2d..000000000 --- a/experimental/compensator/org.eclipse.fx.text/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/DocumentClone.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/DocumentClone.java deleted file mode 100644 index 2998f1e6d..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/DocumentClone.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -import org.eclipse.core.runtime.Assert; - - -/** - * An {@link org.eclipse.jface.text.IDocument} that is a read-only clone of another document. - * - * @since 3.0 - */ -class DocumentClone extends AbstractDocument { - - private static class StringTextStore implements ITextStore { - - private String fContent; - - /** - * Creates a new string text store with the given content. - * - * @param content the content - */ - public StringTextStore(String content) { - Assert.isNotNull(content); - fContent= content; - } - - /* - * @see org.eclipse.jface.text.ITextStore#get(int) - */ - public char get(int offset) { - return fContent.charAt(offset); - } - - /* - * @see org.eclipse.jface.text.ITextStore#get(int, int) - */ - public String get(int offset, int length) { - return fContent.substring(offset, offset + length); - } - - /* - * @see org.eclipse.jface.text.ITextStore#getLength() - */ - public int getLength() { - return fContent.length(); - } - - /* - * @see org.eclipse.jface.text.ITextStore#replace(int, int, java.lang.String) - */ - public void replace(int offset, int length, String text) { - } - - /* - * @see org.eclipse.jface.text.ITextStore#set(java.lang.String) - */ - public void set(String text) { - } - - } - - /** - * Creates a new document clone with the given content. - * - * @param content the content - * @param lineDelimiters the line delimiters - */ - public DocumentClone(String content, String[] lineDelimiters) { - super(); - setTextStore(new StringTextStore(content)); - ConfigurableLineTracker tracker= new ConfigurableLineTracker(lineDelimiters); - setLineTracker(tracker); - getTracker().set(content); - completeInitialization(); - } -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/BufferedDocumentScanner.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/BufferedDocumentScanner.java deleted file mode 100644 index ad7a737db..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/BufferedDocumentScanner.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.rules; - - -import org.eclipse.core.runtime.Assert; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.rules.ICharacterScanner; - - - -/** - * A buffered document scanner. The buffer always contains a section - * of a fixed size of the document to be scanned. - */ - -public final class BufferedDocumentScanner implements ICharacterScanner { - - /** The document being scanned. */ - private IDocument fDocument; - /** The offset of the document range to scan. */ - private int fRangeOffset; - /** The length of the document range to scan. */ - private int fRangeLength; - /** The delimiters of the document. */ - private char[][] fDelimiters; - - /** The buffer. */ - private final char[] fBuffer; - /** The offset of the buffer within the document. */ - private int fBufferOffset; - /** The valid length of the buffer for access. */ - private int fBufferLength; - /** The offset of the scanner within the buffer. */ - private int fOffset; - - - /** - * Creates a new buffered document scanner. - * The buffer size is set to the given number of characters. - * - * @param size the buffer size - */ - public BufferedDocumentScanner(int size) { - Assert.isTrue(size >= 1); - fBuffer= new char[size]; - } - - /** - * Fills the buffer with the contents of the document starting at the given offset. - * - * @param offset the document offset at which the buffer starts - */ - private final void updateBuffer(int offset) { - - fBufferOffset= offset; - - if (fBufferOffset + fBuffer.length > fRangeOffset + fRangeLength) - fBufferLength= fRangeLength - (fBufferOffset - fRangeOffset); - else - fBufferLength= fBuffer.length; - - try { - final String content= fDocument.get(fBufferOffset, fBufferLength); - content.getChars(0, fBufferLength, fBuffer, 0); - } catch (BadLocationException e) { - } - } - - /** - * Configures the scanner by providing access to the document range over which to scan. - * - * @param document the document to scan - * @param offset the offset of the document range to scan - * @param length the length of the document range to scan - */ - public final void setRange(IDocument document, int offset, int length) { - - fDocument= document; - fRangeOffset= offset; - fRangeLength= length; - - String[] delimiters= document.getLegalLineDelimiters(); - fDelimiters= new char[delimiters.length][]; - for (int i= 0; i < delimiters.length; i++) - fDelimiters[i]= delimiters[i].toCharArray(); - - updateBuffer(offset); - fOffset= 0; - } - - /* - * @see ICharacterScanner#read() - */ - public final int read() { - - if (fOffset == fBufferLength) { - int end= fBufferOffset + fBufferLength; - if (end == fDocument.getLength() || end == fRangeOffset + fRangeLength) - return EOF; - else { - updateBuffer(fBufferOffset + fBufferLength); - fOffset= 0; - } - } - - try { - return fBuffer[fOffset++]; - } catch (ArrayIndexOutOfBoundsException ex) { - StringBuffer buf= new StringBuffer(); - buf.append("Detailed state of 'BufferedDocumentScanner:'"); //$NON-NLS-1$ - buf.append("\n\tfOffset= "); //$NON-NLS-1$ - buf.append(fOffset); - buf.append("\n\tfBufferOffset= "); //$NON-NLS-1$ - buf.append(fBufferOffset); - buf.append("\n\tfBufferLength= "); //$NON-NLS-1$ - buf.append(fBufferLength); - buf.append("\n\tfRangeOffset= "); //$NON-NLS-1$ - buf.append(fRangeOffset); - buf.append("\n\tfRangeLength= "); //$NON-NLS-1$ - buf.append(fRangeLength); - System.err.println(buf); - throw ex; - } - } - - /* - * @see ICharacterScanner#unread - */ - public final void unread() { - - if (fOffset == 0) { - if (fBufferOffset == fRangeOffset) { - // error: BOF - } else { - updateBuffer(fBufferOffset - fBuffer.length); - fOffset= fBuffer.length - 1; - } - } else { - --fOffset; - } - } - - /* - * @see ICharacterScanner#getColumn() - */ - public final int getColumn() { - - try { - final int offset= fBufferOffset + fOffset; - final int line= fDocument.getLineOfOffset(offset); - final int start= fDocument.getLineOffset(line); - return offset - start; - } catch (BadLocationException e) { - } - - return -1; - } - - /* - * @see ICharacterScanner#getLegalLineDelimiters() - */ - public final char[][] getLegalLineDelimiters() { - return fDelimiters; - } -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java deleted file mode 100644 index 6f804a832..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text.rules; - -import org.eclipse.core.runtime.Assert; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * A buffered rule based scanner. The buffer always contains a section - * of a fixed size of the document to be scanned. Completely adheres to - * the contract of <code>RuleBasedScanner</code>. - */ -public class BufferedRuleBasedScanner extends RuleBasedScanner { - - /** The default buffer size. Value = 500 */ - private final static int DEFAULT_BUFFER_SIZE= 500; - /** The actual size of the buffer. Initially set to <code>DEFAULT_BUFFER_SIZE</code> */ - private int fBufferSize= DEFAULT_BUFFER_SIZE; - /** The buffer */ - private char[] fBuffer= new char[DEFAULT_BUFFER_SIZE]; - /** The offset of the document at which the buffer starts */ - private int fStart; - /** The offset of the document at which the buffer ends */ - private int fEnd; - /** The cached length of the document */ - private int fDocumentLength; - - - /** - * Creates a new buffered rule based scanner which does - * not have any rule and a default buffer size of 500 characters. - */ - protected BufferedRuleBasedScanner() { - super(); - } - - /** - * Creates a new buffered rule based scanner which does - * not have any rule. The buffer size is set to the given - * number of characters. - * - * @param size the buffer size - */ - public BufferedRuleBasedScanner(int size) { - super(); - setBufferSize(size); - } - - /** - * Sets the buffer to the given number of characters. - * - * @param size the buffer size - */ - protected void setBufferSize(int size) { - Assert.isTrue(size > 0); - fBufferSize= size; - fBuffer= new char[size]; - } - - /** - * Shifts the buffer so that the buffer starts at the - * given document offset. - * - * @param offset the document offset at which the buffer starts - */ - private void shiftBuffer(int offset) { - - fStart= offset; - fEnd= fStart + fBufferSize; - if (fEnd > fDocumentLength) - fEnd= fDocumentLength; - - try { - - String content= fDocument.get(fStart, fEnd - fStart); - content.getChars(0, fEnd - fStart, fBuffer, 0); - - } catch (BadLocationException x) { - } - } - - /* - * @see RuleBasedScanner#setRange(IDocument, int, int) - */ - public void setRange(IDocument document, int offset, int length) { - - super.setRange(document, offset, length); - - fDocumentLength= document.getLength(); - shiftBuffer(offset); - } - - /* - * @see RuleBasedScanner#read() - */ - public int read() { - fColumn= UNDEFINED; - if (fOffset >= fRangeEnd) { - ++ fOffset; - return EOF; - } - - if (fOffset == fEnd) - shiftBuffer(fEnd); - else if (fOffset < fStart || fEnd < fOffset) - shiftBuffer(fOffset); - - return fBuffer[fOffset++ - fStart]; - } - - /* - * @see RuleBasedScanner#unread() - */ - public void unread() { - - if (fOffset == fStart) - shiftBuffer(Math.max(0, fStart - (fBufferSize / 2))); - - --fOffset; - fColumn= UNDEFINED; - } -} - - diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/CombinedWordRule.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/CombinedWordRule.java deleted file mode 100644 index 38d4b1975..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/CombinedWordRule.java +++ /dev/null @@ -1,375 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.rules; - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.Assert; - -import org.eclipse.jface.text.rules.ICharacterScanner; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.IWordDetector; -import org.eclipse.jface.text.rules.Token; - - -/** - * An implementation of <code>IRule</code> capable of detecting words. - * <p> - * Word rules also allow for the association of tokens with specific words. - * That is, not only can the rule be used to provide tokens for exact matches, - * but also for the generalized notion of a word in the context in which it is used. - * A word rules uses a word detector to determine what a word is.</p> - * <p> - * This word rule allows a word detector to be shared among different word matchers. - * Its up to the word matchers to decide if a word matches and, in this a case, which - * token is associated with that word. - * </p> - * - * @see IWordDetector - * @since 3.0 - */ -public class CombinedWordRule implements IRule { - - /** - * Word matcher, that associates matched words with tokens. - */ - public static class WordMatcher { - - /** The table of predefined words and token for this matcher */ - private Map<CharacterBuffer, IToken> fWords= new HashMap<CharacterBuffer, IToken>(); - - /** - * Adds a word and the token to be returned if it is detected. - * - * @param word the word this rule will search for, may not be <code>null</code> - * @param token the token to be returned if the word has been found, may not be <code>null</code> - */ - public void addWord(String word, IToken token) { - Assert.isNotNull(word); - Assert.isNotNull(token); - - fWords.put(new CharacterBuffer(word), token); - } - - /** - * Returns the token associated to the given word and the scanner state. - * - * @param scanner the scanner - * @param word the word - * @return the token or <code>null</code> if none is associated by this matcher - */ - public IToken evaluate(ICharacterScanner scanner, CharacterBuffer word) { - IToken token= fWords.get(word); - if (token != null) - return token; - return Token.UNDEFINED; - } - - /** - * Removes all words. - */ - public void clearWords() { - fWords.clear(); - } - } - - /** - * Character buffer, mutable <b>or</b> suitable for use as key in hash maps. - */ - public static class CharacterBuffer { - - /** Buffer content */ - private char[] fContent; - /** Buffer content size */ - private int fLength= 0; - - /** Is hash code cached? */ - private boolean fIsHashCached= false; - /** The hash code */ - private int fHashCode; - - /** - * Initialize with the given capacity. - * - * @param capacity the initial capacity - */ - public CharacterBuffer(int capacity) { - fContent= new char[capacity]; - } - - /** - * Initialize with the given content. - * - * @param content the initial content - */ - public CharacterBuffer(String content) { - fContent= content.toCharArray(); - fLength= content.length(); - } - - /** - * Empties this buffer. - */ - public void clear() { - fIsHashCached= false; - fLength= 0; - } - - /** - * Appends the given character to the buffer. - * - * @param c the character - */ - public void append(char c) { - fIsHashCached= false; - if (fLength == fContent.length) { - char[] old= fContent; - fContent= new char[old.length << 1]; - System.arraycopy(old, 0, fContent, 0, old.length); - } - fContent[fLength++]= c; - } - - /** - * Returns the length of the content. - * - * @return the length - */ - public int length() { - return fLength; - } - - /** - * Returns the content as string. - * - * @return the content - */ - @Override - public String toString() { - return new String(fContent, 0, fLength); - } - - /** - * Returns the character at the given position. - * - * @param i the position - * @return the character at position <code>i</code> - */ - public char charAt(int i) { - return fContent[i]; - } - - /* - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - if (fIsHashCached) - return fHashCode; - - int hash= 0; - for (int i= 0, n= fLength; i < n; i++) - hash= 29*hash + fContent[i]; - fHashCode= hash; - fIsHashCached= true; - return hash; - } - - - /* - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (obj == this) - return true; - if (!(obj instanceof CharacterBuffer)) - return false; - CharacterBuffer buffer= (CharacterBuffer) obj; - int length= buffer.length(); - if (length != fLength) - return false; - for (int i= 0; i < length; i++) - if (buffer.charAt(i) != fContent[i]) - return false; - return true; - } - - /** - * Is the content equal to the given string? - * - * @param string the string - * @return <code>true</code> iff the content is the same character sequence as in the string - */ - public boolean equals(String string) { - int length= string.length(); - if (length != fLength) - return false; - for (int i= 0; i < length; i++) - if (string.charAt(i) != fContent[i]) - return false; - return true; - } - } - - /** Internal setting for the uninitialized column constraint */ - private static final int UNDEFINED= -1; - - /** The word detector used by this rule */ - private IWordDetector fDetector; - /** The default token to be returned on success and if nothing else has been specified. */ - private IToken fDefaultToken; - /** The column constraint */ - private int fColumn= UNDEFINED; - /** Buffer used for pattern detection */ - private CharacterBuffer fBuffer= new CharacterBuffer(16); - - /** List of word matchers */ - private List<WordMatcher> fMatchers= new ArrayList<WordMatcher>(); - - /** - * Creates a rule which, with the help of an word detector, will return the token - * associated with the detected word. If no token has been associated, the scanner - * will be rolled back and an undefined token will be returned in order to allow - * any subsequent rules to analyze the characters. - * - * @param detector the word detector to be used by this rule, may not be <code>null</code> - * - * @see WordMatcher#addWord(String, IToken) - */ - public CombinedWordRule(IWordDetector detector) { - this(detector, null, Token.UNDEFINED); - } - - /** - * Creates a rule which, with the help of an word detector, will return the token - * associated with the detected word. If no token has been associated, the - * specified default token will be returned. - * - * @param detector the word detector to be used by this rule, may not be <code>null</code> - * @param defaultToken the default token to be returned on success - * if nothing else is specified, may not be <code>null</code> - * - * @see WordMatcher#addWord(String, IToken) - */ - public CombinedWordRule(IWordDetector detector, IToken defaultToken) { - this(detector, null, defaultToken); - } - - /** - * Creates a rule which, with the help of an word detector, will return the token - * associated with the detected word. If no token has been associated, the scanner - * will be rolled back and an undefined token will be returned in order to allow - * any subsequent rules to analyze the characters. - * - * @param detector the word detector to be used by this rule, may not be <code>null</code> - * @param matcher the initial word matcher - * - * @see WordMatcher#addWord(String, IToken) - */ - public CombinedWordRule(IWordDetector detector, WordMatcher matcher) { - this(detector, matcher, Token.UNDEFINED); - } - - /** - * Creates a rule which, with the help of an word detector, will return the token - * associated with the detected word. If no token has been associated, the - * specified default token will be returned. - * - * @param detector the word detector to be used by this rule, may not be <code>null</code> - * @param matcher the initial word matcher - * @param defaultToken the default token to be returned on success - * if nothing else is specified, may not be <code>null</code> - * - * @see WordMatcher#addWord(String, IToken) - */ - public CombinedWordRule(IWordDetector detector, WordMatcher matcher, IToken defaultToken) { - - Assert.isNotNull(detector); - Assert.isNotNull(defaultToken); - - fDetector= detector; - fDefaultToken= defaultToken; - if (matcher != null) - addWordMatcher(matcher); - } - - - /** - * Adds the given matcher. - * - * @param matcher the matcher - */ - public void addWordMatcher(WordMatcher matcher) { - fMatchers.add(matcher); - } - - /** - * Sets a column constraint for this rule. If set, the rule's token - * will only be returned if the pattern is detected starting at the - * specified column. If the column is smaller then 0, the column - * constraint is considered removed. - * - * @param column the column in which the pattern starts - */ - public void setColumnConstraint(int column) { - if (column < 0) - column= UNDEFINED; - fColumn= column; - } - - /* - * @see IRule#evaluate(ICharacterScanner) - */ - public IToken evaluate(ICharacterScanner scanner) { - int c= scanner.read(); - if (fDetector.isWordStart((char) c)) { - if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) { - - fBuffer.clear(); - do { - fBuffer.append((char) c); - c= scanner.read(); - } while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c)); - scanner.unread(); - - for (int i= 0, n= fMatchers.size(); i < n; i++) { - IToken token= fMatchers.get(i).evaluate(scanner, fBuffer); - if (!token.isUndefined()) - return token; - } - - if (fDefaultToken.isUndefined()) - unreadBuffer(scanner); - - return fDefaultToken; - } - } - - scanner.unread(); - return Token.UNDEFINED; - } - - /** - * Returns the characters in the buffer to the scanner. - * - * @param scanner the scanner to be used - */ - private void unreadBuffer(ICharacterScanner scanner) { - for (int i= fBuffer.length() - 1; i >= 0; i--) - scanner.unread(); - } -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/FastPartitioner.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/FastPartitioner.java deleted file mode 100644 index df08dd407..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/FastPartitioner.java +++ /dev/null @@ -1,822 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.rules; - - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.Platform; - -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.DocumentRewriteSession; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentPartitioner; -import org.eclipse.jface.text.IDocumentPartitionerExtension; -import org.eclipse.jface.text.IDocumentPartitionerExtension2; -import org.eclipse.jface.text.IDocumentPartitionerExtension3; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.text.TypedPosition; -import org.eclipse.jface.text.TypedRegion; - - - -/** - * A standard implementation of a document partitioner. It uses an - * {@link IPartitionTokenScanner} to scan the document and to determine the - * document's partitioning. The tokens returned by the scanner must return the - * partition type as their data. The partitioner remembers the document's - * partitions in the document itself rather than maintaining its own data - * structure. - * <p> - * To reduce array creations in {@link IDocument#getPositions(String)}, the - * positions get cached. The cache is cleared after updating the positions in - * {@link #documentChanged2(DocumentEvent)}. Subclasses need to call - * {@link #clearPositionCache()} after modifying the partitioner's positions. - * The cached positions may be accessed through {@link #getPositions()}. - * </p> - * - * @see IPartitionTokenScanner - * @since 3.1 - */ -public class FastPartitioner implements IDocumentPartitioner, IDocumentPartitionerExtension, IDocumentPartitionerExtension2, IDocumentPartitionerExtension3 { - - /** - * The position category this partitioner uses to store the document's partitioning information. - */ - private static final String CONTENT_TYPES_CATEGORY= "__content_types_category"; //$NON-NLS-1$ - /** The partitioner's scanner */ - protected final IPartitionTokenScanner fScanner; - /** The legal content types of this partitioner */ - protected final String[] fLegalContentTypes; - /** The partitioner's document */ - protected IDocument fDocument; - /** The document length before a document change occurred */ - protected int fPreviousDocumentLength; - /** The position updater used to for the default updating of partitions */ - protected final DefaultPositionUpdater fPositionUpdater; - /** The offset at which the first changed partition starts */ - protected int fStartOffset; - /** The offset at which the last changed partition ends */ - protected int fEndOffset; - /**The offset at which a partition has been deleted */ - protected int fDeleteOffset; - /** - * The position category this partitioner uses to store the document's partitioning information. - */ - private final String fPositionCategory; - /** - * The active document rewrite session. - */ - private DocumentRewriteSession fActiveRewriteSession; - /** - * Flag indicating whether this partitioner has been initialized. - */ - private boolean fIsInitialized= false; - /** - * The cached positions from our document, so we don't create a new array every time - * someone requests partition information. - */ - private Position[] fCachedPositions= null; - /** Debug option for cache consistency checking. */ - private static final boolean CHECK_CACHE_CONSISTENCY= "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.jface.text/debug/FastPartitioner/PositionCache")); //$NON-NLS-1$//$NON-NLS-2$; - - /** - * Creates a new partitioner that uses the given scanner and may return - * partitions of the given legal content types. - * - * @param scanner the scanner this partitioner is supposed to use - * @param legalContentTypes the legal content types of this partitioner - */ - public FastPartitioner(IPartitionTokenScanner scanner, String[] legalContentTypes) { - fScanner= scanner; - fLegalContentTypes= TextUtilities.copy(legalContentTypes); - fPositionCategory= CONTENT_TYPES_CATEGORY + hashCode(); - fPositionUpdater= new DefaultPositionUpdater(fPositionCategory); - } - - /* - * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#getManagingPositionCategories() - */ - public String[] getManagingPositionCategories() { - return new String[] { fPositionCategory }; - } - - /* - * @see org.eclipse.jface.text.IDocumentPartitioner#connect(org.eclipse.jface.text.IDocument) - */ - public final void connect(IDocument document) { - connect(document, false); - } - - /** - * {@inheritDoc} - * <p> - * May be extended by subclasses. - * </p> - */ - public void connect(IDocument document, boolean delayInitialization) { - Assert.isNotNull(document); - Assert.isTrue(!document.containsPositionCategory(fPositionCategory)); - - fDocument= document; - fDocument.addPositionCategory(fPositionCategory); - - fIsInitialized= false; - if (!delayInitialization) - checkInitialization(); - } - - /** - * Calls {@link #initialize()} if the receiver is not yet initialized. - */ - protected final void checkInitialization() { - if (!fIsInitialized) - initialize(); - } - - /** - * Performs the initial partitioning of the partitioner's document. - * <p> - * May be extended by subclasses. - * </p> - */ - protected void initialize() { - fIsInitialized= true; - clearPositionCache(); - fScanner.setRange(fDocument, 0, fDocument.getLength()); - - try { - IToken token= fScanner.nextToken(); - while (!token.isEOF()) { - - String contentType= getTokenContentType(token); - - if (isSupportedContentType(contentType)) { - TypedPosition p= new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType); - fDocument.addPosition(fPositionCategory, p); - } - - token= fScanner.nextToken(); - } - } catch (BadLocationException x) { - // cannot happen as offsets come from scanner - } catch (BadPositionCategoryException x) { - // cannot happen if document has been connected before - } - } - - /** - * {@inheritDoc} - * <p> - * May be extended by subclasses. - * </p> - */ - public void disconnect() { - - Assert.isTrue(fDocument.containsPositionCategory(fPositionCategory)); - - try { - fDocument.removePositionCategory(fPositionCategory); - } catch (BadPositionCategoryException x) { - // can not happen because of Assert - } - } - - /** - * {@inheritDoc} - * <p> - * May be extended by subclasses. - * </p> - */ - public void documentAboutToBeChanged(DocumentEvent e) { - if (fIsInitialized) { - - Assert.isTrue(e.getDocument() == fDocument); - - fPreviousDocumentLength= e.getDocument().getLength(); - fStartOffset= -1; - fEndOffset= -1; - fDeleteOffset= -1; - } - } - - /* - * @see IDocumentPartitioner#documentChanged(DocumentEvent) - */ - public final boolean documentChanged(DocumentEvent e) { - if (fIsInitialized) { - IRegion region= documentChanged2(e); - return (region != null); - } - return false; - } - - /** - * Helper method for tracking the minimal region containing all partition changes. - * If <code>offset</code> is smaller than the remembered offset, <code>offset</code> - * will from now on be remembered. If <code>offset + length</code> is greater than - * the remembered end offset, it will be remembered from now on. - * - * @param offset the offset - * @param length the length - */ - private void rememberRegion(int offset, int length) { - // remember start offset - if (fStartOffset == -1) - fStartOffset= offset; - else if (offset < fStartOffset) - fStartOffset= offset; - - // remember end offset - int endOffset= offset + length; - if (fEndOffset == -1) - fEndOffset= endOffset; - else if (endOffset > fEndOffset) - fEndOffset= endOffset; - } - - /** - * Remembers the given offset as the deletion offset. - * - * @param offset the offset - */ - private void rememberDeletedOffset(int offset) { - fDeleteOffset= offset; - } - - /** - * Creates the minimal region containing all partition changes using the - * remembered offset, end offset, and deletion offset. - * - * @return the minimal region containing all the partition changes - */ - private IRegion createRegion() { - if (fDeleteOffset == -1) { - if (fStartOffset == -1 || fEndOffset == -1) - return null; - return new Region(fStartOffset, fEndOffset - fStartOffset); - } else if (fStartOffset == -1 || fEndOffset == -1) { - return new Region(fDeleteOffset, 0); - } else { - int offset= Math.min(fDeleteOffset, fStartOffset); - int endOffset= Math.max(fDeleteOffset, fEndOffset); - return new Region(offset, endOffset - offset); - } - } - - /** - * {@inheritDoc} - * <p> - * May be extended by subclasses. - * </p> - */ - public IRegion documentChanged2(DocumentEvent e) { - - if (!fIsInitialized) - return null; - - try { - Assert.isTrue(e.getDocument() == fDocument); - - Position[] category= getPositions(); - IRegion line= fDocument.getLineInformationOfOffset(e.getOffset()); - int reparseStart= line.getOffset(); - int partitionStart= -1; - String contentType= null; - int newLength= e.getText() == null ? 0 : e.getText().length(); - - int first= fDocument.computeIndexInCategory(fPositionCategory, reparseStart); - if (first > 0) { - TypedPosition partition= (TypedPosition) category[first - 1]; - if (partition.includes(reparseStart)) { - partitionStart= partition.getOffset(); - contentType= partition.getType(); - if (e.getOffset() == partition.getOffset() + partition.getLength()) - reparseStart= partitionStart; - -- first; - } else if (reparseStart == e.getOffset() && reparseStart == partition.getOffset() + partition.getLength()) { - partitionStart= partition.getOffset(); - contentType= partition.getType(); - reparseStart= partitionStart; - -- first; - } else { - partitionStart= partition.getOffset() + partition.getLength(); - contentType= IDocument.DEFAULT_CONTENT_TYPE; - } - } - - fPositionUpdater.update(e); - for (int i= first; i < category.length; i++) { - Position p= category[i]; - if (p.isDeleted) { - rememberDeletedOffset(e.getOffset()); - break; - } - } - clearPositionCache(); - category= getPositions(); - - fScanner.setPartialRange(fDocument, reparseStart, fDocument.getLength() - reparseStart, contentType, partitionStart); - - int behindLastScannedPosition= reparseStart; - IToken token= fScanner.nextToken(); - - while (!token.isEOF()) { - - contentType= getTokenContentType(token); - - if (!isSupportedContentType(contentType)) { - token= fScanner.nextToken(); - continue; - } - - int start= fScanner.getTokenOffset(); - int length= fScanner.getTokenLength(); - - behindLastScannedPosition= start + length; - int lastScannedPosition= behindLastScannedPosition - 1; - - // remove all affected positions - while (first < category.length) { - TypedPosition p= (TypedPosition) category[first]; - if (lastScannedPosition >= p.offset + p.length || - (p.overlapsWith(start, length) && - (!fDocument.containsPosition(fPositionCategory, start, length) || - !contentType.equals(p.getType())))) { - - rememberRegion(p.offset, p.length); - fDocument.removePosition(fPositionCategory, p); - ++ first; - - } else - break; - } - - // if position already exists and we have scanned at least the - // area covered by the event, we are done - if (fDocument.containsPosition(fPositionCategory, start, length)) { - if (lastScannedPosition >= e.getOffset() + newLength) - return createRegion(); - ++ first; - } else { - // insert the new type position - try { - fDocument.addPosition(fPositionCategory, new TypedPosition(start, length, contentType)); - rememberRegion(start, length); - } catch (BadPositionCategoryException x) { - } catch (BadLocationException x) { - } - } - - token= fScanner.nextToken(); - } - - first= fDocument.computeIndexInCategory(fPositionCategory, behindLastScannedPosition); - - clearPositionCache(); - category= getPositions(); - TypedPosition p; - while (first < category.length) { - p= (TypedPosition) category[first++]; - fDocument.removePosition(fPositionCategory, p); - rememberRegion(p.offset, p.length); - } - - } catch (BadPositionCategoryException x) { - // should never happen on connected documents - } catch (BadLocationException x) { - } finally { - clearPositionCache(); - } - - return createRegion(); - } - - /** - * Returns the position in the partitoner's position category which is - * close to the given offset. This is, the position has either an offset which - * is the same as the given offset or an offset which is smaller than the given - * offset. This method profits from the knowledge that a partitioning is - * a ordered set of disjoint position. - * <p> - * May be extended or replaced by subclasses. - * </p> - * @param offset the offset for which to search the closest position - * @return the closest position in the partitioner's category - */ - protected TypedPosition findClosestPosition(int offset) { - - try { - - int index= fDocument.computeIndexInCategory(fPositionCategory, offset); - Position[] category= getPositions(); - - if (category.length == 0) - return null; - - if (index < category.length) { - if (offset == category[index].offset) - return (TypedPosition) category[index]; - } - - if (index > 0) - index--; - - return (TypedPosition) category[index]; - - } catch (BadPositionCategoryException x) { - } catch (BadLocationException x) { - } - - return null; - } - - - /** - * {@inheritDoc} - * <p> - * May be replaced or extended by subclasses. - * </p> - */ - public String getContentType(int offset) { - checkInitialization(); - - TypedPosition p= findClosestPosition(offset); - if (p != null && p.includes(offset)) - return p.getType(); - - return IDocument.DEFAULT_CONTENT_TYPE; - } - - /** - * {@inheritDoc} - * <p> - * May be replaced or extended by subclasses. - * </p> - */ - public ITypedRegion getPartition(int offset) { - checkInitialization(); - - try { - - Position[] category = getPositions(); - - if (category == null || category.length == 0) - return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE); - - int index= fDocument.computeIndexInCategory(fPositionCategory, offset); - - if (index < category.length) { - - TypedPosition next= (TypedPosition) category[index]; - - if (offset == next.offset) - return new TypedRegion(next.getOffset(), next.getLength(), next.getType()); - - if (index == 0) - return new TypedRegion(0, next.offset, IDocument.DEFAULT_CONTENT_TYPE); - - TypedPosition previous= (TypedPosition) category[index - 1]; - if (previous.includes(offset)) - return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); - - int endOffset= previous.getOffset() + previous.getLength(); - return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); - } - - TypedPosition previous= (TypedPosition) category[category.length - 1]; - if (previous.includes(offset)) - return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); - - int endOffset= previous.getOffset() + previous.getLength(); - return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); - - } catch (BadPositionCategoryException x) { - } catch (BadLocationException x) { - } - - return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE); - } - - /* - * @see IDocumentPartitioner#computePartitioning(int, int) - */ - public final ITypedRegion[] computePartitioning(int offset, int length) { - return computePartitioning(offset, length, false); - } - - /** - * {@inheritDoc} - * <p> - * May be replaced or extended by subclasses. - * </p> - */ - public String[] getLegalContentTypes() { - return TextUtilities.copy(fLegalContentTypes); - } - - /** - * Returns whether the given type is one of the legal content types. - * <p> - * May be extended by subclasses. - * </p> - * - * @param contentType the content type to check - * @return <code>true</code> if the content type is a legal content type - */ - protected boolean isSupportedContentType(String contentType) { - if (contentType != null) { - for (int i= 0; i < fLegalContentTypes.length; i++) { - if (fLegalContentTypes[i].equals(contentType)) - return true; - } - } - - return false; - } - - /** - * Returns a content type encoded in the given token. If the token's - * data is not <code>null</code> and a string it is assumed that - * it is the encoded content type. - * <p> - * May be replaced or extended by subclasses. - * </p> - * - * @param token the token whose content type is to be determined - * @return the token's content type - */ - protected String getTokenContentType(IToken token) { - Object data= token.getData(); - if (data instanceof String) - return (String) data; - return null; - } - - /* zero-length partition support */ - - /** - * {@inheritDoc} - * <p> - * May be replaced or extended by subclasses. - * </p> - */ - public String getContentType(int offset, boolean preferOpenPartitions) { - return getPartition(offset, preferOpenPartitions).getType(); - } - - /** - * {@inheritDoc} - * <p> - * May be replaced or extended by subclasses. - * </p> - */ - public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) { - ITypedRegion region= getPartition(offset); - if (preferOpenPartitions) { - if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) { - if (offset > 0) { - region= getPartition(offset - 1); - if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) - return region; - } - return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE); - } - } - return region; - } - - /** - * {@inheritDoc} - * <p> - * May be replaced or extended by subclasses. - * </p> - */ - public ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions) { - checkInitialization(); - List list= new ArrayList(); - - try { - - int endOffset= offset + length; - - Position[] category= getPositions(); - - TypedPosition previous= null, current= null; - int start, end, gapOffset; - Position gap= new Position(0); - - int startIndex= getFirstIndexEndingAfterOffset(category, offset); - int endIndex= getFirstIndexStartingAfterOffset(category, endOffset); - for (int i= startIndex; i < endIndex; i++) { - - current= (TypedPosition) category[i]; - - gapOffset= (previous != null) ? previous.getOffset() + previous.getLength() : 0; - gap.setOffset(gapOffset); - gap.setLength(current.getOffset() - gapOffset); - if ((includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length)) || - (gap.getLength() > 0 && gap.overlapsWith(offset, length))) { - start= Math.max(offset, gapOffset); - end= Math.min(endOffset, gap.getOffset() + gap.getLength()); - list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE)); - } - - if (current.overlapsWith(offset, length)) { - start= Math.max(offset, current.getOffset()); - end= Math.min(endOffset, current.getOffset() + current.getLength()); - list.add(new TypedRegion(start, end - start, current.getType())); - } - - previous= current; - } - - if (previous != null) { - gapOffset= previous.getOffset() + previous.getLength(); - gap.setOffset(gapOffset); - gap.setLength(fDocument.getLength() - gapOffset); - if ((includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length)) || - (gap.getLength() > 0 && gap.overlapsWith(offset, length))) { - start= Math.max(offset, gapOffset); - end= Math.min(endOffset, fDocument.getLength()); - list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE)); - } - } - - if (list.isEmpty()) - list.add(new TypedRegion(offset, length, IDocument.DEFAULT_CONTENT_TYPE)); - - } catch (BadPositionCategoryException ex) { - // Make sure we clear the cache - clearPositionCache(); - } catch (RuntimeException ex) { - // Make sure we clear the cache - clearPositionCache(); - throw ex; - } - - TypedRegion[] result= new TypedRegion[list.size()]; - list.toArray(result); - return result; - } - - /** - * Returns <code>true</code> if the given ranges overlap with or touch each other. - * - * @param gap the first range - * @param offset the offset of the second range - * @param length the length of the second range - * @return <code>true</code> if the given ranges overlap with or touch each other - */ - private boolean overlapsOrTouches(Position gap, int offset, int length) { - return gap.getOffset() <= offset + length && offset <= gap.getOffset() + gap.getLength(); - } - - /** - * Returns the index of the first position which ends after the given offset. - * - * @param positions the positions in linear order - * @param offset the offset - * @return the index of the first position which ends after the offset - */ - private int getFirstIndexEndingAfterOffset(Position[] positions, int offset) { - int i= -1, j= positions.length; - while (j - i > 1) { - int k= (i + j) >> 1; - Position p= positions[k]; - if (p.getOffset() + p.getLength() > offset) - j= k; - else - i= k; - } - return j; - } - - /** - * Returns the index of the first position which starts at or after the given offset. - * - * @param positions the positions in linear order - * @param offset the offset - * @return the index of the first position which starts after the offset - */ - private int getFirstIndexStartingAfterOffset(Position[] positions, int offset) { - int i= -1, j= positions.length; - while (j - i > 1) { - int k= (i + j) >> 1; - Position p= positions[k]; - if (p.getOffset() >= offset) - j= k; - else - i= k; - } - return j; - } - - /* - * @see org.eclipse.jface.text.IDocumentPartitionerExtension3#startRewriteSession(org.eclipse.jface.text.DocumentRewriteSession) - */ - public void startRewriteSession(DocumentRewriteSession session) throws IllegalStateException { - if (fActiveRewriteSession != null) - throw new IllegalStateException(); - fActiveRewriteSession= session; - } - - /** - * {@inheritDoc} - * <p> - * May be extended by subclasses. - * </p> - */ - public void stopRewriteSession(DocumentRewriteSession session) { - if (fActiveRewriteSession == session) - flushRewriteSession(); - } - - /** - * {@inheritDoc} - * <p> - * May be extended by subclasses. - * </p> - */ - public DocumentRewriteSession getActiveRewriteSession() { - return fActiveRewriteSession; - } - - /** - * Flushes the active rewrite session. - */ - protected final void flushRewriteSession() { - fActiveRewriteSession= null; - - // remove all position belonging to the partitioner position category - try { - fDocument.removePositionCategory(fPositionCategory); - } catch (BadPositionCategoryException x) { - } - fDocument.addPositionCategory(fPositionCategory); - - fIsInitialized= false; - } - - /** - * Clears the position cache. Needs to be called whenever the positions have - * been updated. - */ - protected final void clearPositionCache() { - if (fCachedPositions != null) { - fCachedPositions= null; - } - } - - /** - * Returns the partitioners positions. - * - * @return the partitioners positions - * @throws BadPositionCategoryException if getting the positions from the - * document fails - */ - protected final Position[] getPositions() throws BadPositionCategoryException { - if (fCachedPositions == null) { - fCachedPositions= fDocument.getPositions(fPositionCategory); - } else if (CHECK_CACHE_CONSISTENCY) { - Position[] positions= fDocument.getPositions(fPositionCategory); - int len= Math.min(positions.length, fCachedPositions.length); - for (int i= 0; i < len; i++) { - if (!positions[i].equals(fCachedPositions[i])) - System.err.println("FastPartitioner.getPositions(): cached position is not up to date: from document: " + toString(positions[i]) + " in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$ //$NON-NLS-2$ - } - for (int i= len; i < positions.length; i++) - System.err.println("FastPartitioner.getPositions(): new position in document: " + toString(positions[i])); //$NON-NLS-1$ - for (int i= len; i < fCachedPositions.length; i++) - System.err.println("FastPartitioner.getPositions(): stale position in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$ - } - return fCachedPositions; - } - - /** - * Pretty print a <code>Position</code>. - * - * @param position the position to format - * @return a formatted string - */ - private String toString(Position position) { - return "P[" + position.getOffset() + "+" + position.getLength() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/ICharacterScanner.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/ICharacterScanner.java deleted file mode 100644 index 97e8b4c71..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/ICharacterScanner.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.rules; - - -/** - * Defines the interface of a character scanner used by rules. - * Rules may request the next character or ask the character - * scanner to unread the last read character. - */ -public interface ICharacterScanner { - - /** - * The value returned when this scanner has read EOF. - */ - public static final int EOF= -1; - - /** - * Provides rules access to the legal line delimiters. The returned - * object may not be modified by clients. - * - * @return the legal line delimiters - */ - char[][] getLegalLineDelimiters(); - - /** - * Returns the column of the character scanner. - * - * @return the column of the character scanner - */ - int getColumn(); - - /** - * Returns the next character or EOF if end of file has been reached - * - * @return the next character or EOF - */ - int read(); - - /** - * Rewinds the scanner before the last read character. - */ - void unread(); -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IPartitionTokenScanner.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IPartitionTokenScanner.java deleted file mode 100644 index f0d2ebd2f..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IPartitionTokenScanner.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text.rules; - - -import org.eclipse.jface.text.IDocument; - - -/** - * A partition token scanner returns tokens that represent partitions. For that reason, - * a partition token scanner is vulnerable in respect to the document offset it starts - * scanning. In a simple case, a partition token scanner must always start at a partition - * boundary. A partition token scanner can also start in the middle of a partition, - * if it knows the type of the partition. - * - * @since 2.0 - */ -public interface IPartitionTokenScanner extends ITokenScanner { - - /** - * Configures the scanner by providing access to the document range that should be scanned. The - * range may not only contain complete partitions but starts at the beginning of a line in the - * middle of a partition of the given content type. This requires that a partition delimiter can - * not contain a line delimiter. - * - * @param document the document to scan - * @param offset the offset of the document range to scan - * @param length the length of the document range to scan - * @param contentType the content type at the given offset - * @param partitionOffset the offset at which the partition of the given offset starts - */ - void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset); -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IPredicateRule.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IPredicateRule.java deleted file mode 100644 index 5a793437a..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IPredicateRule.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text.rules; - -/** - * Defines the interface for a rule used in the scanning of text for the purpose of - * document partitioning or text styling. A predicate rule can only return one single - * token after having successfully detected content. This token is called success token. - * Also, it also returns a token indicating that this rule has not been successful. - * - * @see ICharacterScanner - * @since 2.0 - */ -public interface IPredicateRule extends IRule { - - /** - * Returns the success token of this predicate rule. - * - * @return the success token of this rule - */ - IToken getSuccessToken(); - - /** - * Evaluates the rule by examining the characters available from - * the provided character scanner. The token returned by this rule - * returns <code>true</code> when calling <code>isUndefined</code>, - * if the text that the rule investigated does not match the rule's requirements. Otherwise, - * this method returns this rule's success token. If this rules relies on a text pattern - * comprising a opening and a closing character sequence this method can also be called - * when the scanner is positioned already between the opening and the closing sequence. - * In this case, <code>resume</code> must be set to <code>true</code>. - * - * @param scanner the character scanner to be used by this rule - * @param resume indicates that the rule starts working between the opening and the closing character sequence - * @return the token computed by the rule - */ - IToken evaluate(ICharacterScanner scanner, boolean resume); -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IRule.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IRule.java deleted file mode 100644 index 667de4689..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IRule.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.rules; - - -/** - * Defines the interface for a rule used in the scanning of text for the purpose of document - * partitioning or text styling. - * - * @see ICharacterScanner - */ -public interface IRule { - - /** - * Evaluates the rule by examining the characters available from the provided character scanner. - * The token returned by this rule returns <code>true</code> when calling - * <code>isUndefined</code>, if the text that the rule investigated does not match the rule's - * requirements - * - * @param scanner the character scanner to be used by this rule - * @return the token computed by the rule - */ - IToken evaluate(ICharacterScanner scanner); -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IToken.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IToken.java deleted file mode 100644 index 4502569c0..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IToken.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.rules; - - -/** - * A token to be returned by a rule. - */ -public interface IToken { - - /** - * Return whether this token is undefined. - * - * @return <code>true</code>if this token is undefined - */ - boolean isUndefined(); - - /** - * Return whether this token represents a whitespace. - * - * @return <code>true</code>if this token represents a whitespace - */ - boolean isWhitespace(); - - /** - * Return whether this token represents End Of File. - * - * @return <code>true</code>if this token represents EOF - */ - boolean isEOF(); - - /** - * Return whether this token is neither undefined, nor whitespace, nor EOF. - * - * @return <code>true</code>if this token is not undefined, not a whitespace, and not EOF - */ - boolean isOther(); - - /** - * Return a data attached to this token. The semantics of this data kept undefined by this interface. - * - * @return the data attached to this token. - */ - Object getData(); -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/ITokenScanner.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/ITokenScanner.java deleted file mode 100644 index dd7ff43b7..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/ITokenScanner.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text.rules; - - -import org.eclipse.jface.text.IDocument; - - -/** - * A token scanner scans a range of a document and reports about the token it finds. - * A scanner has state. When asked, the scanner returns the offset and the length of the - * last found token. - * - * @see org.eclipse.jface.text.rules.IToken - * @since 2.0 - */ -public interface ITokenScanner { - - /** - * Configures the scanner by providing access to the document range that should - * be scanned. - * - * @param document the document to scan - * @param offset the offset of the document range to scan - * @param length the length of the document range to scan - */ - void setRange(IDocument document, int offset, int length); - - /** - * Returns the next token in the document. - * - * @return the next token in the document - */ - IToken nextToken(); - - /** - * Returns the offset of the last token read by this scanner. - * - * @return the offset of the last token read by this scanner - */ - int getTokenOffset(); - - /** - * Returns the length of the last token read by this scanner. - * - * @return the length of the last token read by this scanner - */ - int getTokenLength(); -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IWhitespaceDetector.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IWhitespaceDetector.java deleted file mode 100644 index 5bd84bf38..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IWhitespaceDetector.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.rules; - - -/** - * Defines the interface by which <code>WhitespaceRule</code> - * determines whether a given character is to be considered - * whitespace in the current context. - */ -public interface IWhitespaceDetector { - - /** - * Returns whether the specified character is whitespace. - * - * @param c the character to be checked - * @return <code>true</code> if the specified character is a whitespace char - */ - boolean isWhitespace(char c); -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IWordDetector.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IWordDetector.java deleted file mode 100644 index ae63ee80f..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/IWordDetector.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.rules; - - -/** - * Defines the interface by which <code>WordRule</code> - * determines whether a given character is valid as part - * of a word in the current context. - */ -public interface IWordDetector { - - /** - * Returns whether the specified character is - * valid as the first character in a word. - * - * @param c the character to be checked - * @return <code>true</code> is a valid first character in a word, <code>false</code> otherwise - */ - boolean isWordStart(char c); - - /** - * Returns whether the specified character is - * valid as a subsequent character in a word. - * - * @param c the character to be checked - * @return <code>true</code> if the character is a valid word part, <code>false</code> otherwise - */ - boolean isWordPart(char c); -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/MultiLineRule.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/MultiLineRule.java deleted file mode 100644 index 7887e7842..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/MultiLineRule.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.rules; - - -/** - * A rule for detecting patterns which begin with a given - * sequence and may end with a given sequence thereby spanning - * multiple lines. - */ -public class MultiLineRule extends PatternRule { - - /** - * Creates a rule for the given starting and ending sequence - * which, if detected, will return the specified token. - * - * @param startSequence the pattern's start sequence - * @param endSequence the pattern's end sequence - * @param token the token to be returned on success - */ - public MultiLineRule(String startSequence, String endSequence, IToken token) { - this(startSequence, endSequence, token, (char) 0); - } - - /** - * Creates a rule for the given starting and ending sequence - * which, if detected, will return the specific token. - * Any character which follows the given escape character will be ignored. - * - * @param startSequence the pattern's start sequence - * @param endSequence the pattern's end sequence - * @param token the token to be returned on success - * @param escapeCharacter the escape character - */ - public MultiLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter) { - this(startSequence, endSequence, token, escapeCharacter, false); - } - - /** - * Creates a rule for the given starting and ending sequence - * which, if detected, will return the specific token. Any character that follows the - * given escape character will be ignored. <code>breakOnEOF</code> indicates whether - * EOF is equivalent to detecting the <code>endSequence</code>. - * - * @param startSequence the pattern's start sequence - * @param endSequence the pattern's end sequence - * @param token the token to be returned on success - * @param escapeCharacter the escape character - * @param breaksOnEOF indicates whether the end of the file terminates this rule successfully - * @since 2.1 - */ - public MultiLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOF) { - super(startSequence, endSequence, token, escapeCharacter, false, breaksOnEOF); - } -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/PatternRule.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/PatternRule.java deleted file mode 100644 index d1d92f944..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/PatternRule.java +++ /dev/null @@ -1,324 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Christopher Lenz (cmlenz@gmx.de) - support for line continuation - *******************************************************************************/ -package org.eclipse.jface.text.rules; - -import java.util.Arrays; -import java.util.Comparator; - -import org.eclipse.core.runtime.Assert; - - -/** - * Standard implementation of <code>IPredicateRule</code>. - * Is is capable of detecting a pattern which begins with a given start - * sequence and ends with a given end sequence. If the end sequence is - * not specified, it can be either end of line, end or file, or both. Additionally, - * the pattern can be constrained to begin in a certain column. The rule can also - * be used to check whether the text to scan covers half of the pattern, i.e. contains - * the end sequence required by the rule. - */ -public class PatternRule implements IPredicateRule { - - /** - * Comparator that orders <code>char[]</code> in decreasing array lengths. - * - * @since 3.1 - */ - private static class DecreasingCharArrayLengthComparator implements Comparator { - public int compare(Object o1, Object o2) { - return ((char[]) o2).length - ((char[]) o1).length; - } - } - - /** Internal setting for the un-initialized column constraint */ - protected static final int UNDEFINED= -1; - - /** The token to be returned on success */ - protected IToken fToken; - /** The pattern's start sequence */ - protected char[] fStartSequence; - /** The pattern's end sequence */ - protected char[] fEndSequence; - /** The pattern's column constrain */ - protected int fColumn= UNDEFINED; - /** The pattern's escape character */ - protected char fEscapeCharacter; - /** - * Indicates whether the escape character continues a line - * @since 3.0 - */ - protected boolean fEscapeContinuesLine; - /** Indicates whether end of line terminates the pattern */ - protected boolean fBreaksOnEOL; - /** Indicates whether end of file terminates the pattern */ - protected boolean fBreaksOnEOF; - - /** - * Line delimiter comparator which orders according to decreasing delimiter length. - * @since 3.1 - */ - private Comparator fLineDelimiterComparator= new DecreasingCharArrayLengthComparator(); - /** - * Cached line delimiters. - * @since 3.1 - */ - private char[][] fLineDelimiters; - /** - * Cached sorted {@linkplain #fLineDelimiters}. - * @since 3.1 - */ - private char[][] fSortedLineDelimiters; - - /** - * Creates a rule for the given starting and ending sequence. - * When these sequences are detected the rule will return the specified token. - * Alternatively, the sequence can also be ended by the end of the line. - * Any character which follows the given escapeCharacter will be ignored. - * - * @param startSequence the pattern's start sequence - * @param endSequence the pattern's end sequence, <code>null</code> is a legal value - * @param token the token which will be returned on success - * @param escapeCharacter any character following this one will be ignored - * @param breaksOnEOL indicates whether the end of the line also terminates the pattern - */ - public PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL) { - Assert.isTrue(startSequence != null && startSequence.length() > 0); - Assert.isTrue(endSequence != null || breaksOnEOL); - Assert.isNotNull(token); - - fStartSequence= startSequence.toCharArray(); - fEndSequence= (endSequence == null ? new char[0] : endSequence.toCharArray()); - fToken= token; - fEscapeCharacter= escapeCharacter; - fBreaksOnEOL= breaksOnEOL; - } - - /** - * Creates a rule for the given starting and ending sequence. - * When these sequences are detected the rule will return the specified token. - * Alternatively, the sequence can also be ended by the end of the line or the end of the file. - * Any character which follows the given escapeCharacter will be ignored. - * - * @param startSequence the pattern's start sequence - * @param endSequence the pattern's end sequence, <code>null</code> is a legal value - * @param token the token which will be returned on success - * @param escapeCharacter any character following this one will be ignored - * @param breaksOnEOL indicates whether the end of the line also terminates the pattern - * @param breaksOnEOF indicates whether the end of the file also terminates the pattern - * @since 2.1 - */ - public PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL, boolean breaksOnEOF) { - this(startSequence, endSequence, token, escapeCharacter, breaksOnEOL); - fBreaksOnEOF= breaksOnEOF; - } - - /** - * Creates a rule for the given starting and ending sequence. - * When these sequences are detected the rule will return the specified token. - * Alternatively, the sequence can also be ended by the end of the line or the end of the file. - * Any character which follows the given escapeCharacter will be ignored. An end of line - * immediately after the given <code>lineContinuationCharacter</code> will not cause the - * pattern to terminate even if <code>breakOnEOL</code> is set to true. - * - * @param startSequence the pattern's start sequence - * @param endSequence the pattern's end sequence, <code>null</code> is a legal value - * @param token the token which will be returned on success - * @param escapeCharacter any character following this one will be ignored - * @param breaksOnEOL indicates whether the end of the line also terminates the pattern - * @param breaksOnEOF indicates whether the end of the file also terminates the pattern - * @param escapeContinuesLine indicates whether the specified escape character is used for line - * continuation, so that an end of line immediately after the escape character does not - * terminate the pattern, even if <code>breakOnEOL</code> is set - * @since 3.0 - */ - public PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL, boolean breaksOnEOF, boolean escapeContinuesLine) { - this(startSequence, endSequence, token, escapeCharacter, breaksOnEOL, breaksOnEOF); - fEscapeContinuesLine= escapeContinuesLine; - } - - /** - * Sets a column constraint for this rule. If set, the rule's token - * will only be returned if the pattern is detected starting at the - * specified column. If the column is smaller then 0, the column - * constraint is considered removed. - * - * @param column the column in which the pattern starts - */ - public void setColumnConstraint(int column) { - if (column < 0) - column= UNDEFINED; - fColumn= column; - } - - - /** - * Evaluates this rules without considering any column constraints. - * - * @param scanner the character scanner to be used - * @return the token resulting from this evaluation - */ - protected IToken doEvaluate(ICharacterScanner scanner) { - return doEvaluate(scanner, false); - } - - /** - * Evaluates this rules without considering any column constraints. Resumes - * detection, i.e. look sonly for the end sequence required by this rule if the - * <code>resume</code> flag is set. - * - * @param scanner the character scanner to be used - * @param resume <code>true</code> if detection should be resumed, <code>false</code> otherwise - * @return the token resulting from this evaluation - * @since 2.0 - */ - protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) { - - if (resume) { - - if (endSequenceDetected(scanner)) - return fToken; - - } else { - - int c= scanner.read(); - if (c == fStartSequence[0]) { - if (sequenceDetected(scanner, fStartSequence, false)) { - if (endSequenceDetected(scanner)) - return fToken; - } - } - } - - scanner.unread(); - return Token.UNDEFINED; - } - - /* - * @see IRule#evaluate(ICharacterScanner) - */ - public IToken evaluate(ICharacterScanner scanner) { - return evaluate(scanner, false); - } - - /** - * Returns whether the end sequence was detected. As the pattern can be considered - * ended by a line delimiter, the result of this method is <code>true</code> if the - * rule breaks on the end of the line, or if the EOF character is read. - * - * @param scanner the character scanner to be used - * @return <code>true</code> if the end sequence has been detected - */ - protected boolean endSequenceDetected(ICharacterScanner scanner) { - - char[][] originalDelimiters= scanner.getLegalLineDelimiters(); - int count= originalDelimiters.length; - if (fLineDelimiters == null || fLineDelimiters.length != count) { - fSortedLineDelimiters= new char[count][]; - } else { - while (count > 0 && Arrays.equals(fLineDelimiters[count - 1], originalDelimiters[count - 1])) - count--; - } - if (count != 0) { - fLineDelimiters= originalDelimiters; - System.arraycopy(fLineDelimiters, 0, fSortedLineDelimiters, 0, fLineDelimiters.length); - Arrays.sort(fSortedLineDelimiters, fLineDelimiterComparator); - } - - int readCount= 1; - int c; - while ((c= scanner.read()) != ICharacterScanner.EOF) { - if (c == fEscapeCharacter) { - // Skip escaped character(s) - if (fEscapeContinuesLine) { - c= scanner.read(); - for (int i= 0; i < fSortedLineDelimiters.length; i++) { - if (c == fSortedLineDelimiters[i][0] && sequenceDetected(scanner, fSortedLineDelimiters[i], fBreaksOnEOF)) - break; - } - } else - scanner.read(); - - } else if (fEndSequence.length > 0 && c == fEndSequence[0]) { - // Check if the specified end sequence has been found. - if (sequenceDetected(scanner, fEndSequence, fBreaksOnEOF)) - return true; - } else if (fBreaksOnEOL) { - // Check for end of line since it can be used to terminate the pattern. - for (int i= 0; i < fSortedLineDelimiters.length; i++) { - if (c == fSortedLineDelimiters[i][0] && sequenceDetected(scanner, fSortedLineDelimiters[i], fBreaksOnEOF)) - return true; - } - } - readCount++; - } - - if (fBreaksOnEOF) - return true; - - for (; readCount > 0; readCount--) - scanner.unread(); - - return false; - } - - /** - * Returns whether the next characters to be read by the character scanner - * are an exact match with the given sequence. No escape characters are allowed - * within the sequence. If specified the sequence is considered to be found - * when reading the EOF character. - * - * @param scanner the character scanner to be used - * @param sequence the sequence to be detected - * @param eofAllowed indicated whether EOF terminates the pattern - * @return <code>true</code> if the given sequence has been detected - */ - protected boolean sequenceDetected(ICharacterScanner scanner, char[] sequence, boolean eofAllowed) { - for (int i= 1; i < sequence.length; i++) { - int c= scanner.read(); - if (c == ICharacterScanner.EOF && eofAllowed) { - return true; - } else if (c != sequence[i]) { - // Non-matching character detected, rewind the scanner back to the start. - // Do not unread the first character. - scanner.unread(); - for (int j= i-1; j > 0; j--) - scanner.unread(); - return false; - } - } - - return true; - } - - /* - * @see IPredicateRule#evaluate(ICharacterScanner, boolean) - * @since 2.0 - */ - public IToken evaluate(ICharacterScanner scanner, boolean resume) { - if (fColumn == UNDEFINED) - return doEvaluate(scanner, resume); - - int c= scanner.read(); - scanner.unread(); - if (c == fStartSequence[0]) - return (fColumn == scanner.getColumn() ? doEvaluate(scanner, resume) : Token.UNDEFINED); - return Token.UNDEFINED; - } - - /* - * @see IPredicateRule#getSuccessToken() - * @since 2.0 - */ - public IToken getSuccessToken() { - return fToken; - } -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/RuleBasedPartitionScanner.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/RuleBasedPartitionScanner.java deleted file mode 100644 index 55dde65d5..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/RuleBasedPartitionScanner.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text.rules; - - -import org.eclipse.jface.text.IDocument; - - -/** - * Scanner that exclusively uses predicate rules. - * <p> - * If a partial range is set (see {@link #setPartialRange(IDocument, int, int, String, int)} with - * content type that is not <code>null</code> then this scanner will first try the rules that match - * the given content type. - * </p> - * - * @since 2.0 - */ -public class RuleBasedPartitionScanner extends BufferedRuleBasedScanner implements IPartitionTokenScanner { - - /** The content type of the partition in which to resume scanning. */ - protected String fContentType; - /** The offset of the partition inside which to resume. */ - protected int fPartitionOffset; - - - /** - * Disallow setting the rules since this scanner - * exclusively uses predicate rules. - * - * @param rules the sequence of rules controlling this scanner - */ - public void setRules(IRule[] rules) { - throw new UnsupportedOperationException(); - } - - /* - * @see RuleBasedScanner#setRules(IRule[]) - */ - public void setPredicateRules(IPredicateRule[] rules) { - super.setRules(rules); - } - - /* - * @see ITokenScanner#setRange(IDocument, int, int) - */ - public void setRange(IDocument document, int offset, int length) { - setPartialRange(document, offset, length, null, -1); - } - - /** - * {@inheritDoc} - * <p> - * If the given content type is not <code>null</code> then this scanner will first try the rules - * that match the given content type. - * </p> - */ - public void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset) { - fContentType= contentType; - fPartitionOffset= partitionOffset; - if (partitionOffset > -1) { - int delta= offset - partitionOffset; - if (delta > 0) { - super.setRange(document, partitionOffset, length + delta); - fOffset= offset; - return; - } - } - super.setRange(document, offset, length); - } - - /* - * @see ITokenScanner#nextToken() - */ - public IToken nextToken() { - - - if (fContentType == null || fRules == null) { - //don't try to resume - return super.nextToken(); - } - - // inside a partition - - fColumn= UNDEFINED; - boolean resume= (fPartitionOffset > -1 && fPartitionOffset < fOffset); - fTokenOffset= resume ? fPartitionOffset : fOffset; - - IPredicateRule rule; - IToken token; - - for (int i= 0; i < fRules.length; i++) { - rule= (IPredicateRule) fRules[i]; - token= rule.getSuccessToken(); - if (fContentType.equals(token.getData())) { - token= rule.evaluate(this, resume); - if (!token.isUndefined()) { - fContentType= null; - return token; - } - } - } - - // haven't found any rule for this type of partition - fContentType= null; - if (resume) - fOffset= fPartitionOffset; - return super.nextToken(); - } -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/RuleBasedScanner.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/RuleBasedScanner.java deleted file mode 100644 index dc2777672..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/RuleBasedScanner.java +++ /dev/null @@ -1,216 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text.rules; - - -import org.eclipse.core.runtime.Assert; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - - -/** - * A generic scanner which can be "programmed" with a sequence of rules. - * The scanner is used to get the next token by evaluating its rule in sequence until - * one is successful. If a rule returns a token which is undefined, the scanner will proceed to - * the next rule. Otherwise the token provided by the rule will be returned by - * the scanner. If no rule returned a defined token, this scanner returns a token - * which returns <code>true</code> when calling <code>isOther</code>, unless the end - * of the file is reached. In this case the token returns <code>true</code> when calling - * <code>isEOF</code>. - * - * @see IRule - */ -public class RuleBasedScanner implements ICharacterScanner, ITokenScanner { - - /** The list of rules of this scanner */ - protected IRule[] fRules; - /** The token to be returned by default if no rule fires */ - protected IToken fDefaultReturnToken; - /** The document to be scanned */ - protected IDocument fDocument; - /** The cached legal line delimiters of the document */ - protected char[][] fDelimiters; - /** The offset of the next character to be read */ - protected int fOffset; - /** The end offset of the range to be scanned */ - protected int fRangeEnd; - /** The offset of the last read token */ - protected int fTokenOffset; - /** The cached column of the current scanner position */ - protected int fColumn; - /** Internal setting for the un-initialized column cache. */ - protected static final int UNDEFINED= -1; - - /** - * Creates a new rule based scanner which does not have any rule. - */ - public RuleBasedScanner() { - } - - /** - * Configures the scanner with the given sequence of rules. - * - * @param rules the sequence of rules controlling this scanner - */ - public void setRules(IRule[] rules) { - if (rules != null) { - fRules= new IRule[rules.length]; - System.arraycopy(rules, 0, fRules, 0, rules.length); - } else - fRules= null; - } - - /** - * Configures the scanner's default return token. This is the token - * which is returned when none of the rules fired and EOF has not been - * reached. - * - * @param defaultReturnToken the default return token - * @since 2.0 - */ - public void setDefaultReturnToken(IToken defaultReturnToken) { - Assert.isNotNull(defaultReturnToken.getData()); - fDefaultReturnToken= defaultReturnToken; - } - - /* - * @see ITokenScanner#setRange(IDocument, int, int) - */ - public void setRange(final IDocument document, int offset, int length) { - Assert.isLegal(document != null); - final int documentLength= document.getLength(); - checkRange(offset, length, documentLength); - - fDocument= document; - fOffset= offset; - fColumn= UNDEFINED; - fRangeEnd= offset + length; - - String[] delimiters= fDocument.getLegalLineDelimiters(); - fDelimiters= new char[delimiters.length][]; - for (int i= 0; i < delimiters.length; i++) - fDelimiters[i]= delimiters[i].toCharArray(); - - if (fDefaultReturnToken == null) - fDefaultReturnToken= new Token(null); - } - - /** - * Checks that the given range is valid. - * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=69292 - * - * @param offset the offset of the document range to scan - * @param length the length of the document range to scan - * @param documentLength the document's length - * @since 3.3 - */ - private void checkRange(int offset, int length, int documentLength) { - Assert.isLegal(offset > -1); - Assert.isLegal(length > -1); - Assert.isLegal(offset + length <= documentLength); - } - - /* - * @see ITokenScanner#getTokenOffset() - */ - public int getTokenOffset() { - return fTokenOffset; - } - - /* - * @see ITokenScanner#getTokenLength() - */ - public int getTokenLength() { - if (fOffset < fRangeEnd) - return fOffset - getTokenOffset(); - return fRangeEnd - getTokenOffset(); - } - - - /* - * @see ICharacterScanner#getColumn() - */ - public int getColumn() { - if (fColumn == UNDEFINED) { - try { - int line= fDocument.getLineOfOffset(fOffset); - int start= fDocument.getLineOffset(line); - - fColumn= fOffset - start; - - } catch (BadLocationException ex) { - } - } - return fColumn; - } - - /* - * @see ICharacterScanner#getLegalLineDelimiters() - */ - public char[][] getLegalLineDelimiters() { - return fDelimiters; - } - - /* - * @see ITokenScanner#nextToken() - */ - public IToken nextToken() { - - fTokenOffset= fOffset; - fColumn= UNDEFINED; - - if (fRules != null) { - for (int i= 0; i < fRules.length; i++) { - IToken token= (fRules[i].evaluate(this)); - if (!token.isUndefined()) - return token; - } - } - - if (read() == EOF) - return Token.EOF; - return fDefaultReturnToken; - } - - /* - * @see ICharacterScanner#read() - */ - public int read() { - - try { - - if (fOffset < fRangeEnd) { - try { - return fDocument.getChar(fOffset); - } catch (BadLocationException e) { - } - } - - return EOF; - - } finally { - ++ fOffset; - fColumn= UNDEFINED; - } - } - - /* - * @see ICharacterScanner#unread() - */ - public void unread() { - --fOffset; - fColumn= UNDEFINED; - } -} - - diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/SingleLineRule.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/SingleLineRule.java deleted file mode 100644 index 5b26d852d..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/SingleLineRule.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Christopher Lenz (cmlenz@gmx.de) - support for line continuation - *******************************************************************************/ -package org.eclipse.jface.text.rules; - - -/** - * A specific configuration of pattern rule whereby - * the pattern begins with a specific sequence and may - * end with a specific sequence, but will not span more - * than a single line. - */ -public class SingleLineRule extends PatternRule { - - /** - * Creates a rule for the given starting and ending sequence - * which, if detected, will return the specified token. - * - * @param startSequence the pattern's start sequence - * @param endSequence the pattern's end sequence - * @param token the token to be returned on success - */ - public SingleLineRule(String startSequence, String endSequence, IToken token) { - this(startSequence, endSequence, token, (char) 0); - } - - /** - * Creates a rule for the given starting and ending sequence - * which, if detected, will return the specified token. - * Any character which follows the given escape character - * will be ignored. - * - * @param startSequence the pattern's start sequence - * @param endSequence the pattern's end sequence - * @param token the token to be returned on success - * @param escapeCharacter the escape character - */ - public SingleLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter) { - this(startSequence, endSequence, token, escapeCharacter, false); - } - - /** - * Creates a rule for the given starting and ending sequence - * which, if detected, will return the specified token. Alternatively, the - * line can also be ended with the end of the file. - * Any character which follows the given escape character - * will be ignored. - * - * @param startSequence the pattern's start sequence - * @param endSequence the pattern's end sequence - * @param token the token to be returned on success - * @param escapeCharacter the escape character - * @param breaksOnEOF indicates whether the end of the file successfully terminates this rule - * @since 2.1 - */ - public SingleLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOF) { - super(startSequence, endSequence, token, escapeCharacter, true, breaksOnEOF); - } - - /** - * Creates a rule for the given starting and ending sequence - * which, if detected, will return the specified token. Alternatively, the - * line can also be ended with the end of the file. - * Any character which follows the given escape character - * will be ignored. In addition, an escape character immediately before an - * end of line can be set to continue the line. - * - * @param startSequence the pattern's start sequence - * @param endSequence the pattern's end sequence - * @param token the token to be returned on success - * @param escapeCharacter the escape character - * @param breaksOnEOF indicates whether the end of the file successfully terminates this rule - * @param escapeContinuesLine indicates whether the specified escape character is used for line - * continuation, so that an end of line immediately after the escape character does not - * terminate the line, even if <code>breakOnEOL</code> is true - * @since 3.0 - */ - public SingleLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOF, boolean escapeContinuesLine) { - super(startSequence, endSequence, token, escapeCharacter, true, breaksOnEOF, escapeContinuesLine); - } -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/Token.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/Token.java deleted file mode 100644 index 24f48a458..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/Token.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text.rules; - -import org.eclipse.core.runtime.Assert; - - -/** - * Standard implementation of <code>IToken</code>. - */ -public class Token implements IToken { - - /** Internal token type: Undefined */ - private static final int T_UNDEFINED= 0; - /** Internal token type: EOF */ - private static final int T_EOF= 1; - /** Internal token type: Whitespace */ - private static final int T_WHITESPACE= 2; - /** Internal token type: Others */ - private static final int T_OTHER= 3; - - - /** - * Standard token: Undefined. - */ - public static final IToken UNDEFINED= new Token(T_UNDEFINED); - /** - * Standard token: End Of File. - */ - public static final IToken EOF= new Token(T_EOF); - /** - * Standard token: Whitespace. - */ - public static final IToken WHITESPACE= new Token(T_WHITESPACE); - - /** - * Standard token: Neither {@link #UNDEFINED}, {@link #WHITESPACE}, nor {@link #EOF}. - * @deprecated will be removed - */ - public static final IToken OTHER= new Token(T_OTHER); - - /** The type of this token */ - private int fType; - /** The data associated with this token */ - private Object fData; - - /** - * Creates a new token according to the given specification which does not - * have any data attached to it. - * - * @param type the type of the token - * @since 2.0 - */ - private Token(int type) { - fType= type; - fData= null; - } - - /** - * Creates a new token which represents neither undefined, whitespace, nor EOF. - * The newly created token has the given data attached to it. - * - * @param data the data attached to the newly created token - */ - public Token(Object data) { - fType= T_OTHER; - fData= data; - } - - /** - * Re-initializes the data of this token. The token may not represent - * undefined, whitespace, or EOF. - * - * @param data to be attached to the token - * @since 2.0 - */ - public void setData(Object data) { - Assert.isTrue(isOther()); - fData= data; - } - - /* - * @see IToken#getData() - */ - public Object getData() { - return fData; - } - - /* - * @see IToken#isOther() - */ - public boolean isOther() { - return (fType == T_OTHER); - } - - /* - * @see IToken#isEOF() - */ - public boolean isEOF() { - return (fType == T_EOF); - } - - /* - * @see IToken#isWhitespace() - */ - public boolean isWhitespace() { - return (fType == T_WHITESPACE); - } - - /* - * @see IToken#isUndefined() - */ - public boolean isUndefined() { - return (fType == T_UNDEFINED); - } -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/WhitespaceRule.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/WhitespaceRule.java deleted file mode 100644 index 6bd1af7f2..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/WhitespaceRule.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Anton Leherbauer (Wind River Systems) - [misc] Allow custom token for WhitespaceRule - https://bugs.eclipse.org/bugs/show_bug.cgi?id=251224 - *******************************************************************************/ -package org.eclipse.jface.text.rules; - - -import org.eclipse.core.runtime.Assert; - - -/** - * An implementation of <code>IRule</code> capable of detecting whitespace. - * A whitespace rule uses a whitespace detector in order to find out which - * characters are whitespace characters. - * - * @see IWhitespaceDetector - */ -public class WhitespaceRule implements IRule { - - /** The whitespace detector used by this rule */ - protected IWhitespaceDetector fDetector; - - /** - * The token returned for whitespace. - * @since 3.5 - */ - protected final IToken fWhitespaceToken; - - /** - * Creates a rule which, with the help of an whitespace detector, will return - * {@link Token#WHITESPACE} when a whitespace is detected. - * - * @param detector the rule's whitespace detector - */ - public WhitespaceRule(IWhitespaceDetector detector) { - this(detector, Token.WHITESPACE); - } - - /** - * Creates a rule which, with the help of an whitespace detector, will return the given - * whitespace token when a whitespace is detected. - * - * @param detector the rule's whitespace detector - * @param token the token returned for whitespace - * @since 3.5 - */ - public WhitespaceRule(IWhitespaceDetector detector, IToken token) { - Assert.isNotNull(detector); - Assert.isNotNull(token); - fDetector= detector; - fWhitespaceToken= token; - } - - /** - * {@inheritDoc} - * - * @return {@link #fWhitespaceToken} if whitespace got detected, {@link Token#UNDEFINED} - * otherwise - */ - public IToken evaluate(ICharacterScanner scanner) { - int c= scanner.read(); - if (fDetector.isWhitespace((char) c)) { - do { - c= scanner.read(); - } while (fDetector.isWhitespace((char) c)); - scanner.unread(); - return fWhitespaceToken; - } - - scanner.unread(); - return Token.UNDEFINED; - } -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/WordRule.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/WordRule.java deleted file mode 100644 index b52a7ea38..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/rules/WordRule.java +++ /dev/null @@ -1,174 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Doug Satchwell <doug.satchwell@ymail.com> - [implementation] Performance issue with jface text WordRule - http://bugs.eclipse.org/277299 - *******************************************************************************/ -package org.eclipse.jface.text.rules; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.runtime.Assert; - - -/** - * An implementation of {@link IRule} capable of detecting words. A word rule also allows to - * associate a token to a word. That is, not only can the rule be used to provide tokens for exact - * matches, but also for the generalized notion of a word in the context in which it is used. A word - * rule uses a word detector to determine what a word is. - * - * @see IWordDetector - */ -public class WordRule implements IRule { - - /** Internal setting for the un-initialized column constraint. */ - protected static final int UNDEFINED= -1; - - /** The word detector used by this rule. */ - protected IWordDetector fDetector; - /** The default token to be returned on success and if nothing else has been specified. */ - protected IToken fDefaultToken; - /** The column constraint. */ - protected int fColumn= UNDEFINED; - /** The table of predefined words and token for this rule. */ - protected Map fWords= new HashMap(); - /** Buffer used for pattern detection. */ - private StringBuffer fBuffer= new StringBuffer(); - /** - * Tells whether this rule is case sensitive. - * @since 3.3 - */ - private boolean fIgnoreCase= false; - - - /** - * Creates a rule which, with the help of an word detector, will return the token - * associated with the detected word. If no token has been associated, the scanner - * will be rolled back and an undefined token will be returned in order to allow - * any subsequent rules to analyze the characters. - * - * @param detector the word detector to be used by this rule, may not be <code>null</code> - * @see #addWord(String, IToken) - */ - public WordRule(IWordDetector detector) { - this(detector, Token.UNDEFINED, false); - } - - /** - * Creates a rule which, with the help of a word detector, will return the token - * associated with the detected word. If no token has been associated, the - * specified default token will be returned. - * - * @param detector the word detector to be used by this rule, may not be <code>null</code> - * @param defaultToken the default token to be returned on success - * if nothing else is specified, may not be <code>null</code> - * @see #addWord(String, IToken) - */ - public WordRule(IWordDetector detector, IToken defaultToken) { - this(detector, defaultToken, false); - } - - /** - * Creates a rule which, with the help of a word detector, will return the token - * associated with the detected word. If no token has been associated, the - * specified default token will be returned. - * - * @param detector the word detector to be used by this rule, may not be <code>null</code> - * @param defaultToken the default token to be returned on success - * if nothing else is specified, may not be <code>null</code> - * @param ignoreCase the case sensitivity associated with this rule - * @see #addWord(String, IToken) - * @since 3.3 - */ - public WordRule(IWordDetector detector, IToken defaultToken, boolean ignoreCase) { - Assert.isNotNull(detector); - Assert.isNotNull(defaultToken); - - fDetector= detector; - fDefaultToken= defaultToken; - fIgnoreCase= ignoreCase; - } - - /** - * Adds a word and the token to be returned if it is detected. - * - * @param word the word this rule will search for, may not be <code>null</code> - * @param token the token to be returned if the word has been found, may not be <code>null</code> - */ - public void addWord(String word, IToken token) { - Assert.isNotNull(word); - Assert.isNotNull(token); - - // If case-insensitive, convert to lower case before adding to the map - if (fIgnoreCase) - word= word.toLowerCase(); - fWords.put(word, token); - } - - /** - * Sets a column constraint for this rule. If set, the rule's token - * will only be returned if the pattern is detected starting at the - * specified column. If the column is smaller then 0, the column - * constraint is considered removed. - * - * @param column the column in which the pattern starts - */ - public void setColumnConstraint(int column) { - if (column < 0) - column= UNDEFINED; - fColumn= column; - } - - /* - * @see IRule#evaluate(ICharacterScanner) - */ - public IToken evaluate(ICharacterScanner scanner) { - int c= scanner.read(); - if (c != ICharacterScanner.EOF && fDetector.isWordStart((char) c)) { - if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) { - - fBuffer.setLength(0); - do { - fBuffer.append((char) c); - c= scanner.read(); - } while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c)); - scanner.unread(); - - String buffer= fBuffer.toString(); - // If case-insensitive, convert to lower case before accessing the map - if (fIgnoreCase) - buffer= buffer.toLowerCase(); - - IToken token= (IToken)fWords.get(buffer); - - if (token != null) - return token; - - if (fDefaultToken.isUndefined()) - unreadBuffer(scanner); - - return fDefaultToken; - } - } - - scanner.unread(); - return Token.UNDEFINED; - } - - /** - * Returns the characters in the buffer to the scanner. - * - * @param scanner the scanner to be used - */ - protected void unreadBuffer(ICharacterScanner scanner) { - for (int i= fBuffer.length() - 1; i >= 0; i--) - scanner.unread(); - } - -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/source/CharacterRule.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/source/CharacterRule.java deleted file mode 100644 index cad40655f..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/source/CharacterRule.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.eclipse.jface.text.source; - -import org.eclipse.jface.text.rules.ICharacterScanner; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.Token; - -public final class CharacterRule implements IRule { - - /** Java operators */ - private final char[] fValues; - /** Token to return for this rule */ - private final IToken fToken; - - /** - * Creates a new operator rule. - * - * @param token Token to use for this rule - */ - public CharacterRule(IToken token, char[] values) { - fToken= token; - fValues = values; - } - - /** - * Is this character an operator character? - * - * @param character Character to determine whether it is an operator character - * @return <code>true</code> iff the character is an operator, <code>false</code> otherwise. - */ - public boolean isOperator(char character) { - for (int index= 0; index < fValues.length; index++) { - if (fValues[index] == character) - return true; - } - return false; - } - - public IToken evaluate(ICharacterScanner scanner) { - - int character= scanner.read(); - if (isOperator((char) character)) { - do { - character= scanner.read(); - } while (isOperator((char) character)); - scanner.unread(); - return fToken; - } else { - scanner.unread(); - return Token.UNDEFINED; - } - } - }
\ No newline at end of file diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/source/FastJavaLikePartitionScanner.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/source/FastJavaLikePartitionScanner.java deleted file mode 100644 index e67459d6e..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/source/FastJavaLikePartitionScanner.java +++ /dev/null @@ -1,520 +0,0 @@ -package org.eclipse.jface.text.source; - - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.rules.BufferedDocumentScanner; -import org.eclipse.jface.text.rules.ICharacterScanner; -import org.eclipse.jface.text.rules.IPartitionTokenScanner; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.Token; - - -/** - * This scanner recognizes the JavaDoc comments, Java multi line comments, Java single line comments, - * Java strings and Java characters. - */ -public class FastJavaLikePartitionScanner implements IPartitionTokenScanner { - - // states - private static final int JAVA= 0; - private static final int SINGLE_LINE_COMMENT= 1; - private static final int MULTI_LINE_COMMENT= 2; - private static final int JAVADOC= 3; - private static final int CHARACTER= 4; - private static final int STRING= 5; - - // beginning of prefixes and postfixes - private static final int NONE= 0; - private static final int BACKSLASH= 1; // postfix for STRING and CHARACTER - private static final int SLASH= 2; // prefix for SINGLE_LINE or MULTI_LINE or JAVADOC - private static final int SLASH_STAR= 3; // prefix for MULTI_LINE_COMMENT or JAVADOC - private static final int SLASH_STAR_STAR= 4; // prefix for MULTI_LINE_COMMENT or JAVADOC - private static final int STAR= 5; // postfix for MULTI_LINE_COMMENT or JAVADOC - private static final int CARRIAGE_RETURN=6; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT - - /** The scanner. */ - private final BufferedDocumentScanner fScanner= new BufferedDocumentScanner(1000); // faster implementation - - /** The offset of the last returned token. */ - private int fTokenOffset; - /** The length of the last returned token. */ - private int fTokenLength; - - /** The state of the scanner. */ - private int fState; - /** The last significant characters read. */ - private int fLast; - /** The amount of characters already read on first call to nextToken(). */ - private int fPrefixLength; - - // emulate JavaPartitionScanner - private boolean fEmulate= false; - private int fJavaOffset; - private int fJavaLength; - - private final IToken[] fTokens; - - public FastJavaLikePartitionScanner(String singleLineCommentKey, String multiLineCommentKey, String javaDocKey, String characterKey, String stringKey) { - fTokens= new IToken[] { - new Token(null), - new Token(singleLineCommentKey), - new Token(multiLineCommentKey), - new Token(javaDocKey), - new Token(characterKey), - new Token(stringKey) - }; - } - - /* - * @see org.eclipse.jface.text.rules.ITokenScanner#nextToken() - */ - public IToken nextToken() { - - // emulate JavaPartitionScanner - if (fEmulate) { - if (fJavaOffset != -1 && fTokenOffset + fTokenLength != fJavaOffset + fJavaLength) { - fTokenOffset += fTokenLength; - return fTokens[JAVA]; - } else { - fJavaOffset= -1; - fJavaLength= 0; - } - } - - fTokenOffset += fTokenLength; - fTokenLength= fPrefixLength; - - while (true) { - final int ch= fScanner.read(); - - // characters - switch (ch) { - case ICharacterScanner.EOF: - if (fTokenLength > 0) { - fLast= NONE; // ignore last - return preFix(fState, JAVA, NONE, 0); - - } else { - fLast= NONE; - fPrefixLength= 0; - return Token.EOF; - } - - case '\r': - // emulate JavaPartitionScanner - if (!fEmulate && fLast != CARRIAGE_RETURN) { - fLast= CARRIAGE_RETURN; - fTokenLength++; - continue; - - } else { - - switch (fState) { - case SINGLE_LINE_COMMENT: - case CHARACTER: - case STRING: - if (fTokenLength > 0) { - IToken token= fTokens[fState]; - - // emulate JavaPartitionScanner - if (fEmulate) { - fTokenLength++; - fLast= NONE; - fPrefixLength= 0; - } else { - fLast= CARRIAGE_RETURN; - fPrefixLength= 1; - } - - fState= JAVA; - return token; - - } else { - consume(); - continue; - } - - default: - consume(); - continue; - } - } - - case '\n': - switch (fState) { - case SINGLE_LINE_COMMENT: - case CHARACTER: - case STRING: - // assert(fTokenLength > 0); - return postFix(fState); - - default: - consume(); - continue; - } - - default: - if (!fEmulate && fLast == CARRIAGE_RETURN) { - switch (fState) { - case SINGLE_LINE_COMMENT: - case CHARACTER: - case STRING: - - int last; - int newState; - switch (ch) { - case '/': - last= SLASH; - newState= JAVA; - break; - - case '*': - last= STAR; - newState= JAVA; - break; - - case '\'': - last= NONE; - newState= CHARACTER; - break; - - case '"': - last= NONE; - newState= STRING; - break; - - case '\r': - last= CARRIAGE_RETURN; - newState= JAVA; - break; - - case '\\': - last= BACKSLASH; - newState= JAVA; - break; - - default: - last= NONE; - newState= JAVA; - break; - } - - fLast= NONE; // ignore fLast - return preFix(fState, newState, last, 1); - - default: - break; - } - } - } - - // states - switch (fState) { - case JAVA: - switch (ch) { - case '/': - if (fLast == SLASH) { - if (fTokenLength - getLastLength(fLast) > 0) { - return preFix(JAVA, SINGLE_LINE_COMMENT, NONE, 2); - } else { - preFix(JAVA, SINGLE_LINE_COMMENT, NONE, 2); - fTokenOffset += fTokenLength; - fTokenLength= fPrefixLength; - break; - } - - } else { - fTokenLength++; - fLast= SLASH; - break; - } - - case '*': - if (fLast == SLASH) { - if (fTokenLength - getLastLength(fLast) > 0) - return preFix(JAVA, MULTI_LINE_COMMENT, SLASH_STAR, 2); - else { - preFix(JAVA, MULTI_LINE_COMMENT, SLASH_STAR, 2); - fTokenOffset += fTokenLength; - fTokenLength= fPrefixLength; - break; - } - - } else { - consume(); - break; - } - - case '\'': - fLast= NONE; // ignore fLast - if (fTokenLength > 0) - return preFix(JAVA, CHARACTER, NONE, 1); - else { - preFix(JAVA, CHARACTER, NONE, 1); - fTokenOffset += fTokenLength; - fTokenLength= fPrefixLength; - break; - } - - case '"': - fLast= NONE; // ignore fLast - if (fTokenLength > 0) - return preFix(JAVA, STRING, NONE, 1); - else { - preFix(JAVA, STRING, NONE, 1); - fTokenOffset += fTokenLength; - fTokenLength= fPrefixLength; - break; - } - - default: - consume(); - break; - } - break; - - case SINGLE_LINE_COMMENT: - consume(); - break; - - case JAVADOC: - switch (ch) { - case '/': - switch (fLast) { - case SLASH_STAR_STAR: - return postFix(MULTI_LINE_COMMENT); - - case STAR: - return postFix(JAVADOC); - - default: - consume(); - break; - } - break; - - case '*': - fTokenLength++; - fLast= STAR; - break; - - default: - consume(); - break; - } - break; - - case MULTI_LINE_COMMENT: - switch (ch) { - case '*': - if (fLast == SLASH_STAR) { - fLast= SLASH_STAR_STAR; - fTokenLength++; - fState= JAVADOC; - } else { - fTokenLength++; - fLast= STAR; - } - break; - - case '/': - if (fLast == STAR) { - return postFix(MULTI_LINE_COMMENT); - } else { - consume(); - break; - } - - default: - consume(); - break; - } - break; - - case STRING: - switch (ch) { - case '\\': - fLast= (fLast == BACKSLASH) ? NONE : BACKSLASH; - fTokenLength++; - break; - - case '\"': - if (fLast != BACKSLASH) { - return postFix(STRING); - - } else { - consume(); - break; - } - - default: - consume(); - break; - } - break; - - case CHARACTER: - switch (ch) { - case '\\': - fLast= (fLast == BACKSLASH) ? NONE : BACKSLASH; - fTokenLength++; - break; - - case '\'': - if (fLast != BACKSLASH) { - return postFix(CHARACTER); - - } else { - consume(); - break; - } - - default: - consume(); - break; - } - break; - } - } - } - - private static final int getLastLength(int last) { - switch (last) { - default: - return -1; - - case NONE: - return 0; - - case CARRIAGE_RETURN: - case BACKSLASH: - case SLASH: - case STAR: - return 1; - - case SLASH_STAR: - return 2; - - case SLASH_STAR_STAR: - return 3; - } - } - - private final void consume() { - fTokenLength++; - fLast= NONE; - } - - private final IToken postFix(int state) { - fTokenLength++; - fLast= NONE; - fState= JAVA; - fPrefixLength= 0; - return fTokens[state]; - } - - private final IToken preFix(int state, int newState, int last, int prefixLength) { - // emulate JavaPartitionScanner - if (fEmulate && state == JAVA && (fTokenLength - getLastLength(fLast) > 0)) { - fTokenLength -= getLastLength(fLast); - fJavaOffset= fTokenOffset; - fJavaLength= fTokenLength; - fTokenLength= 1; - fState= newState; - fPrefixLength= prefixLength; - fLast= last; - return fTokens[state]; - - } else { - fTokenLength -= getLastLength(fLast); - fLast= last; - fPrefixLength= prefixLength; - IToken token= fTokens[state]; - fState= newState; - return token; - } - } - - private int getState(String contentType) { - - if (contentType == null) - return JAVA; - - else if (contentType.equals(fTokens[SINGLE_LINE_COMMENT].getData())) - return SINGLE_LINE_COMMENT; - - else if (contentType.equals(fTokens[MULTI_LINE_COMMENT].getData())) - return MULTI_LINE_COMMENT; - - else if (contentType.equals(fTokens[JAVADOC].getData())) - return JAVADOC; - - else if (contentType.equals(fTokens[STRING].getData())) - return STRING; - - else if (contentType.equals(fTokens[CHARACTER].getData())) - return CHARACTER; - - else - return JAVA; - } - - /* - * @see IPartitionTokenScanner#setPartialRange(IDocument, int, int, String, int) - */ - public void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset) { - - fScanner.setRange(document, offset, length); - fTokenOffset= partitionOffset; - fTokenLength= 0; - fPrefixLength= offset - partitionOffset; - fLast= NONE; - - if (offset == partitionOffset) { - // restart at beginning of partition - fState= JAVA; - } else { - fState= getState(contentType); - } - - // emulate JavaPartitionScanner - if (fEmulate) { - fJavaOffset= -1; - fJavaLength= 0; - } - } - - /* - * @see ITokenScanner#setRange(IDocument, int, int) - */ - public void setRange(IDocument document, int offset, int length) { - - fScanner.setRange(document, offset, length); - fTokenOffset= offset; - fTokenLength= 0; - fPrefixLength= 0; - fLast= NONE; - fState= JAVA; - - // emulate JavaPartitionScanner - if (fEmulate) { - fJavaOffset= -1; - fJavaLength= 0; - } - } - - /* - * @see ITokenScanner#getTokenLength() - */ - public int getTokenLength() { - return fTokenLength; - } - - /* - * @see ITokenScanner#getTokenOffset() - */ - public int getTokenOffset() { - return fTokenOffset; - } - -} diff --git a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/source/JavaLikeWordDetector.java b/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/source/JavaLikeWordDetector.java deleted file mode 100644 index 35f4eddd9..000000000 --- a/experimental/compensator/org.eclipse.fx.text/src/org/eclipse/jface/text/source/JavaLikeWordDetector.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - - -import org.eclipse.jface.text.rules.IWordDetector; - -/** - * A Java aware word detector. - */ -public class JavaLikeWordDetector implements IWordDetector { - - /* - * @see IWordDetector#isWordStart - */ - public boolean isWordStart(char c) { - return Character.isJavaIdentifierStart(c); - } - - /* - * @see IWordDetector#isWordPart - */ - public boolean isWordPart(char c) { - return Character.isJavaIdentifierPart(c); - } -} |