From 88ff721dd79afd998bc795b817e3b88bc17bbef6 Mon Sep 17 00:00:00 2001 From: incastrix Date: Tue, 6 Oct 2009 19:47:49 +0000 Subject: [PATCH] Refactory --- .../META-INF/MANIFEST.MF | 3 +- .../actions/PHPStartApacheAction.java | 1 + .../META-INF/MANIFEST.MF | 1 + .../ltk/ui/wizards/RenameIdentifierWizard.java | 3 +- .../ltk/ui/wizards/RenameLocalVariableWizard.java | 3 +- .../phpdt/ui/wizards/NewContainerWizardPage.java | 4 +- .../phpdt/ui/wizards/NewElementWizardPage.java | 4 +- .../phpdt/ui/wizards/NewTypeWizardPage.java | 4 +- .../phpeclipse/phpeditor/DocumentAdapter.java | 515 -------------------- .../phpeclipse/phpeditor/PHPUnitEditor.java | 14 +- .../net/sourceforge/phpeclipse/ui/StatusInfo.java | 185 +++++++ .../src/net/sourceforge/phpeclipse/ui/WebUI.java | 2 +- .../php/model/ValidBreakpointLocationLocator.java | 66 ++-- net.sourceforge.phpeclipse/META-INF/MANIFEST.MF | 8 +- .../sourceforge/phpeclipse/DocumentAdapter.java | 515 ++++++++++++++++++++ 15 files changed, 763 insertions(+), 565 deletions(-) delete mode 100644 net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/phpeditor/DocumentAdapter.java create mode 100644 net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/StatusInfo.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/DocumentAdapter.java diff --git a/net.sourceforge.phpeclipse.externaltools/META-INF/MANIFEST.MF b/net.sourceforge.phpeclipse.externaltools/META-INF/MANIFEST.MF index 24058d5..4586d82 100644 --- a/net.sourceforge.phpeclipse.externaltools/META-INF/MANIFEST.MF +++ b/net.sourceforge.phpeclipse.externaltools/META-INF/MANIFEST.MF @@ -26,7 +26,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.ui.editors, org.eclipse.core.runtime, org.eclipse.debug.ui, - org.eclipse.ui.externaltools + org.eclipse.ui.externaltools, + net.sourceforge.phpeclipse.ui Bundle-RequiredExecutionEnvironment: J2SE-1.4 Bundle-ActivationPolicy: lazy diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartApacheAction.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartApacheAction.java index e28f9f2..742ac88 100644 --- a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartApacheAction.java +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartApacheAction.java @@ -11,6 +11,7 @@ import java.text.MessageFormat; import net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil; import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin; +import net.sourceforge.phpeclipse.ui.WebUI; //import net.sourceforge.phpeclipse.ui.WebUI; import org.eclipse.jface.action.IAction; diff --git a/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF b/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF index 25a9cdf..fc55542 100644 --- a/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF +++ b/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF @@ -16,3 +16,4 @@ Require-Bundle: org.eclipse.core.runtime, net.sourceforge.phpeclipse.ui Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Import-Package: org.eclipse.ui.texteditor diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ltk/ui/wizards/RenameIdentifierWizard.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ltk/ui/wizards/RenameIdentifierWizard.java index ca8bb68..21e80e7 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ltk/ui/wizards/RenameIdentifierWizard.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ltk/ui/wizards/RenameIdentifierWizard.java @@ -34,7 +34,8 @@ public class RenameIdentifierWizard extends RefactoringWizard { // /////////////////////////////////////// protected void addUserInputPages() { - setDefaultPageTitle(getRefactoring().getName()); + //incastrix + //setDefaultPageTitle(getRefactoring().getName()); addPage(new RenameLocalVariablePage(info)); } } diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ltk/ui/wizards/RenameLocalVariableWizard.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ltk/ui/wizards/RenameLocalVariableWizard.java index a4f8941..c2a2910 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ltk/ui/wizards/RenameLocalVariableWizard.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ltk/ui/wizards/RenameLocalVariableWizard.java @@ -31,7 +31,8 @@ public class RenameLocalVariableWizard extends RefactoringWizard { } protected void addUserInputPages() { - setDefaultPageTitle(getRefactoring().getName()); + //incastrix + //setDefaultPageTitle(getRefactoring().getName()); addPage(new RenameLocalVariablePage(info)); } } diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ui/wizards/NewContainerWizardPage.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ui/wizards/NewContainerWizardPage.java index f21bfb6..b2a5da6 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ui/wizards/NewContainerWizardPage.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ui/wizards/NewContainerWizardPage.java @@ -15,7 +15,9 @@ import net.sourceforge.phpdt.core.IJavaProject; import net.sourceforge.phpdt.core.IPackageFragmentRoot; import net.sourceforge.phpdt.core.JavaCore; import net.sourceforge.phpdt.core.JavaModelException; -import net.sourceforge.phpdt.externaltools.internal.ui.StatusInfo; +// incastrix +//import net.sourceforge.phpdt.externaltools.internal.ui.StatusInfo; +import net.sourceforge.phpeclipse.ui.StatusInfo; import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider; import net.sourceforge.phpdt.internal.ui.wizards.NewWizardMessages; import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.DialogField; diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ui/wizards/NewElementWizardPage.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ui/wizards/NewElementWizardPage.java index 653d4a0..90cce1e 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ui/wizards/NewElementWizardPage.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ui/wizards/NewElementWizardPage.java @@ -10,7 +10,9 @@ *******************************************************************************/ package net.sourceforge.phpdt.ui.wizards; -import net.sourceforge.phpdt.externaltools.internal.ui.StatusInfo; +//incastrix +//import net.sourceforge.phpdt.externaltools.internal.ui.StatusInfo; +import net.sourceforge.phpeclipse.ui.StatusInfo; import net.sourceforge.phpdt.internal.ui.dialogs.StatusUtil; import org.eclipse.core.runtime.IStatus; diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ui/wizards/NewTypeWizardPage.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ui/wizards/NewTypeWizardPage.java index a73147a..9819992 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ui/wizards/NewTypeWizardPage.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpdt/ui/wizards/NewTypeWizardPage.java @@ -24,7 +24,9 @@ import net.sourceforge.phpdt.core.ToolFactory; import net.sourceforge.phpdt.core.compiler.IScanner; import net.sourceforge.phpdt.core.compiler.ITerminalSymbols; import net.sourceforge.phpdt.core.compiler.InvalidInputException; -import net.sourceforge.phpdt.externaltools.internal.ui.StatusInfo; +//incastrix +//import net.sourceforge.phpdt.externaltools.internal.ui.StatusInfo; +import net.sourceforge.phpeclipse.ui.StatusInfo; import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility; import net.sourceforge.phpdt.internal.corext.template.php.JavaContext; import net.sourceforge.phpdt.internal.corext.template.php.Templates; diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/phpeditor/DocumentAdapter.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/phpeditor/DocumentAdapter.java deleted file mode 100644 index 124fd7d..0000000 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/phpeditor/DocumentAdapter.java +++ /dev/null @@ -1,515 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package net.sourceforge.phpeclipse.phpeditor; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import net.sourceforge.phpdt.core.BufferChangedEvent; -import net.sourceforge.phpdt.core.IBuffer; -import net.sourceforge.phpdt.core.IBufferChangedListener; -import net.sourceforge.phpdt.core.IOpenable; -import net.sourceforge.phpdt.core.JavaModelException; -import net.sourceforge.phpeclipse.PHPeclipsePlugin; - -import org.eclipse.core.filebuffers.FileBuffers; -import org.eclipse.core.filebuffers.ITextFileBuffer; -import org.eclipse.core.filebuffers.ITextFileBufferManager; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -//incastrix -//import org.eclipse.jface.text.Assert; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DefaultLineTracker; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.swt.widgets.Display; - -/** - * Adapts IDocument to IBuffer. Uses the same - * algorithm as the text widget to determine the buffer's line delimiter. All - * text inserted into the buffer is converted to this line delimiter. This class - * is public for test purposes only. - */ -public class DocumentAdapter implements IBuffer, IDocumentListener { - - /** - * Internal implementation of a NULL instanceof IBuffer. - */ - static private class NullBuffer implements IBuffer { - public void addBufferChangedListener(IBufferChangedListener listener) { - } - - public void append(char[] text) { - } - - public void append(String text) { - } - - public void close() { - } - - public char getChar(int position) { - return 0; - } - - public char[] getCharacters() { - return null; - } - - public String getContents() { - return null; - } - - public int getLength() { - return 0; - } - - public IOpenable getOwner() { - return null; - } - - public String getText(int offset, int length) { - return null; - } - - public IResource getUnderlyingResource() { - return null; - } - - public boolean hasUnsavedChanges() { - return false; - } - - public boolean isClosed() { - return false; - } - - public boolean isReadOnly() { - return true; - } - - public void removeBufferChangedListener(IBufferChangedListener listener) { - } - - public void replace(int position, int length, char[] text) { - } - - public void replace(int position, int length, String text) { - } - - public void save(IProgressMonitor progress, boolean force) - throws JavaModelException { - } - - public void setContents(char[] contents) { - } - - public void setContents(String contents) { - } - } - - /** NULL implementing IBuffer */ - public final static IBuffer NULL = new NullBuffer(); - - /** - * Executes a document set content call in the ui thread. - */ - protected class DocumentSetCommand implements Runnable { - - private String fContents; - - public void run() { - fDocument.set(fContents); - } - - public void set(String contents) { - fContents = contents; - Display.getDefault().syncExec(this); - } - } - - /** - * Executes a document replace call in the ui thread. - */ - protected class DocumentReplaceCommand implements Runnable { - - private int fOffset; - - private int fLength; - - private String fText; - - public void run() { - try { - fDocument.replace(fOffset, fLength, fText); - } catch (BadLocationException x) { - // ignore - } - } - - public void replace(int offset, int length, String text) { - fOffset = offset; - fLength = length; - fText = text; - Display.getDefault().syncExec(this); - } - } - - private static final boolean DEBUG_LINE_DELIMITERS = true; - - private IOpenable fOwner; - - private IFile fFile; - - private ITextFileBuffer fTextFileBuffer; - - private IDocument fDocument; - - private DocumentSetCommand fSetCmd = new DocumentSetCommand(); - - private DocumentReplaceCommand fReplaceCmd = new DocumentReplaceCommand(); - - private Set fLegalLineDelimiters; - - private List fBufferListeners = new ArrayList(3); - - private IStatus fStatus; - - /** - * This method is public for test purposes only. - */ - public DocumentAdapter(IOpenable owner, IFile file) { - - fOwner = owner; - fFile = file; - - initialize(); - } - - private void initialize() { - ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager(); - IPath location = fFile.getFullPath(); - try { - manager.connect(location, new NullProgressMonitor()); - fTextFileBuffer = manager.getTextFileBuffer(location); - fDocument = fTextFileBuffer.getDocument(); - } catch (CoreException x) { - fStatus = x.getStatus(); - fDocument = manager.createEmptyDocument(location); - } - fDocument.addPrenotifiedDocumentListener(this); - } - - /** - * Returns the status of this document adapter. - */ - public IStatus getStatus() { - if (fStatus != null) - return fStatus; - if (fTextFileBuffer != null) - return fTextFileBuffer.getStatus(); - return null; - } - - /** - * Returns the adapted document. - * - * @return the adapted document - */ - public IDocument getDocument() { - return fDocument; - } - - /* - * @see IBuffer#addBufferChangedListener(IBufferChangedListener) - */ - public void addBufferChangedListener(IBufferChangedListener listener) { - Assert.isNotNull(listener); - if (!fBufferListeners.contains(listener)) - fBufferListeners.add(listener); - } - - /* - * @see IBuffer#removeBufferChangedListener(IBufferChangedListener) - */ - public void removeBufferChangedListener(IBufferChangedListener listener) { - Assert.isNotNull(listener); - fBufferListeners.remove(listener); - } - - /* - * @see IBuffer#append(char[]) - */ - public void append(char[] text) { - append(new String(text)); - } - - /* - * @see IBuffer#append(String) - */ - public void append(String text) { - if (DEBUG_LINE_DELIMITERS) { - validateLineDelimiters(text); - } - fReplaceCmd.replace(fDocument.getLength(), 0, text); - } - - /* - * @see IBuffer#close() - */ - public void close() { - - if (isClosed()) - return; - - IDocument d = fDocument; - fDocument = null; - d.removePrenotifiedDocumentListener(this); - - if (fTextFileBuffer != null) { - ITextFileBufferManager manager = FileBuffers - .getTextFileBufferManager(); - try { - manager.disconnect(fTextFileBuffer.getLocation(), - new NullProgressMonitor()); - } catch (CoreException x) { - // ignore - } - fTextFileBuffer = null; - } - - fireBufferChanged(new BufferChangedEvent(this, 0, 0, null)); - fBufferListeners.clear(); - } - - /* - * @see IBuffer#getChar(int) - */ - public char getChar(int position) { - try { - return fDocument.getChar(position); - } catch (BadLocationException x) { - throw new ArrayIndexOutOfBoundsException(); - } - } - - /* - * @see IBuffer#getCharacters() - */ - public char[] getCharacters() { - String content = getContents(); - return content == null ? null : content.toCharArray(); - } - - /* - * @see IBuffer#getContents() - */ - public String getContents() { - return fDocument.get(); - } - - /* - * @see IBuffer#getLength() - */ - public int getLength() { - return fDocument.getLength(); - } - - /* - * @see IBuffer#getOwner() - */ - public IOpenable getOwner() { - return fOwner; - } - - /* - * @see IBuffer#getText(int, int) - */ - public String getText(int offset, int length) { - try { - return fDocument.get(offset, length); - } catch (BadLocationException x) { - throw new ArrayIndexOutOfBoundsException(); - } - } - - /* - * @see IBuffer#getUnderlyingResource() - */ - public IResource getUnderlyingResource() { - return fFile; - } - - /* - * @see IBuffer#hasUnsavedChanges() - */ - public boolean hasUnsavedChanges() { - return fTextFileBuffer != null ? fTextFileBuffer.isDirty() : false; - } - - /* - * @see IBuffer#isClosed() - */ - public boolean isClosed() { - return fDocument == null; - } - - /* - * @see IBuffer#isReadOnly() - */ - public boolean isReadOnly() { - IResource resource = getUnderlyingResource(); - return resource == null ? true : resource.getResourceAttributes() - .isReadOnly(); - } - - /* - * @see IBuffer#replace(int, int, char[]) - */ - public void replace(int position, int length, char[] text) { - replace(position, length, new String(text)); - } - - /* - * @see IBuffer#replace(int, int, String) - */ - public void replace(int position, int length, String text) { - if (DEBUG_LINE_DELIMITERS) { - validateLineDelimiters(text); - } - fReplaceCmd.replace(position, length, text); - } - - /* - * @see IBuffer#save(IProgressMonitor, boolean) - */ - public void save(IProgressMonitor progress, boolean force) - throws JavaModelException { - try { - if (fTextFileBuffer != null) - fTextFileBuffer.commit(progress, force); - } catch (CoreException e) { - throw new JavaModelException(e); - } - } - - /* - * @see IBuffer#setContents(char[]) - */ - public void setContents(char[] contents) { - setContents(new String(contents)); - } - - /* - * @see IBuffer#setContents(String) - */ - public void setContents(String contents) { - int oldLength = fDocument.getLength(); - - if (contents == null) { - - if (oldLength != 0) - fSetCmd.set(""); //$NON-NLS-1$ - - } else { - - // set only if different - if (DEBUG_LINE_DELIMITERS) { - validateLineDelimiters(contents); - } - - if (!contents.equals(fDocument.get())) - fSetCmd.set(contents); - } - } - - private void validateLineDelimiters(String contents) { - - if (fLegalLineDelimiters == null) { - // collect all line delimiters in the document - HashSet existingDelimiters = new HashSet(); - - for (int i = fDocument.getNumberOfLines() - 1; i >= 0; i--) { - try { - String curr = fDocument.getLineDelimiter(i); - if (curr != null) { - existingDelimiters.add(curr); - } - } catch (BadLocationException e) { - PHPeclipsePlugin.log(e); - } - } - if (existingDelimiters.isEmpty()) { - return; // first insertion of a line delimiter: no test - } - fLegalLineDelimiters = existingDelimiters; - - } - - DefaultLineTracker tracker = new DefaultLineTracker(); - tracker.set(contents); - - int lines = tracker.getNumberOfLines(); - if (lines <= 1) - return; - - for (int i = 0; i < lines; i++) { - try { - String curr = tracker.getLineDelimiter(i); - if (curr != null && !fLegalLineDelimiters.contains(curr)) { - StringBuffer buf = new StringBuffer( - "New line delimiter added to new code: "); //$NON-NLS-1$ - for (int k = 0; k < curr.length(); k++) { - buf.append(String.valueOf((int) curr.charAt(k))); - } - PHPeclipsePlugin.log(new Exception(buf.toString())); - } - } catch (BadLocationException e) { - PHPeclipsePlugin.log(e); - } - } - } - - /* - * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent) - */ - public void documentAboutToBeChanged(DocumentEvent event) { - // there is nothing to do here - } - - /* - * @see IDocumentListener#documentChanged(DocumentEvent) - */ - public void documentChanged(DocumentEvent event) { - fireBufferChanged(new BufferChangedEvent(this, event.getOffset(), event - .getLength(), event.getText())); - } - - private void fireBufferChanged(BufferChangedEvent event) { - if (fBufferListeners != null && fBufferListeners.size() > 0) { - Iterator e = new ArrayList(fBufferListeners).iterator(); - while (e.hasNext()) - ((IBufferChangedListener) e.next()).bufferChanged(event); - } - } -} diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java index d330b73..93d23ff 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java @@ -37,7 +37,7 @@ import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI.ExitFlags; import net.sourceforge.phpdt.ui.IWorkingCopyManager; import net.sourceforge.phpdt.ui.PreferenceConstants; import net.sourceforge.phpdt.ui.actions.GenerateActionGroup; -import net.sourceforge.phpdt.ui.text.JavaTextTools; +//import net.sourceforge.phpdt.ui.text.JavaTextTools; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.phpeditor.actions.RTrimAction; import net.sourceforge.phpeclipse.ui.WebUI; @@ -87,7 +87,7 @@ import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.RGB; +//import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -1889,11 +1889,11 @@ public class PHPUnitEditor extends PHPEditor { // implements // return getColor(rgb); // } - private Color getColor(RGB rgb) { - JavaTextTools textTools = WebUI.getDefault() - .getJavaTextTools(); - return textTools.getColorManager().getColor(rgb); - } +// private Color getColor(RGB rgb) { +// JavaTextTools textTools = WebUI.getDefault() +// .getJavaTextTools(); +// return textTools.getColorManager().getColor(rgb); +// } // private Color getColor(AnnotationType annotationType) { // AnnotationInfo info = (AnnotationInfo) diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/StatusInfo.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/StatusInfo.java new file mode 100644 index 0000000..713a7fb --- /dev/null +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/StatusInfo.java @@ -0,0 +1,185 @@ +package net.sourceforge.phpeclipse.ui; + +/********************************************************************** + Copyright (c) 2000, 2002 IBM Corp. All rights reserved. + This file is made available under the terms of the Common Public License v1.0 + which accompanies this distribution, and is available at + http://www.eclipse.org/legal/cpl-v10.html + **********************************************************************/ + +//incastrix +//import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants; + +import org.eclipse.core.runtime.IStatus; +//incastrix +//import org.eclipse.jface.text.Assert; +import org.eclipse.core.runtime.Assert; + +/** + * A settable IStatus. Can be an error, warning, info or ok. For error, info and + * warning states, a message describes the problem. + */ +public class StatusInfo implements IStatus { + + private String fStatusMessage; + + private int fSeverity; + + /** + * Creates a status set to OK (no message) + */ + public StatusInfo() { + this(OK, null); + } + + /** + * Creates a status . + * + * @param severity + * The status severity: ERROR, WARNING, INFO and OK. + * @param message + * The message of the status. Applies only for ERROR, WARNING and + * INFO. + */ + public StatusInfo(int severity, String message) { + fStatusMessage = message; + fSeverity = severity; + } + + /** + * Returns if the status' severity is OK. + */ + public boolean isOK() { + return fSeverity == IStatus.OK; + } + + /** + * Returns if the status' severity is WARNING. + */ + public boolean isWarning() { + return fSeverity == IStatus.WARNING; + } + + /** + * Returns if the status' severity is INFO. + */ + public boolean isInfo() { + return fSeverity == IStatus.INFO; + } + + /** + * Returns if the status' severity is ERROR. + */ + public boolean isError() { + return fSeverity == IStatus.ERROR; + } + + /** + * @see IStatus#getMessage + */ + public String getMessage() { + return fStatusMessage; + } + + /** + * Sets the status to ERROR. + * + * @param The + * error message (can be empty, but not null) + */ + public void setError(String errorMessage) { + Assert.isNotNull(errorMessage); + fStatusMessage = errorMessage; + fSeverity = IStatus.ERROR; + } + + /** + * Sets the status to WARNING. + * + * @param The + * warning message (can be empty, but not null) + */ + public void setWarning(String warningMessage) { + Assert.isNotNull(warningMessage); + fStatusMessage = warningMessage; + fSeverity = IStatus.WARNING; + } + + /** + * Sets the status to INFO. + * + * @param The + * info message (can be empty, but not null) + */ + public void setInfo(String infoMessage) { + Assert.isNotNull(infoMessage); + fStatusMessage = infoMessage; + fSeverity = IStatus.INFO; + } + + /** + * Sets the status to OK. + */ + public void setOK() { + fStatusMessage = null; + fSeverity = IStatus.OK; + } + + /* + * @see IStatus#matches(int) + */ + public boolean matches(int severityMask) { + return (fSeverity & severityMask) != 0; + } + + /** + * Returns always false. + * + * @see IStatus#isMultiStatus() + */ + public boolean isMultiStatus() { + return false; + } + + /* + * @see IStatus#getSeverity() + */ + public int getSeverity() { + return fSeverity; + } + + /* + * @see IStatus#getPlugin() + */ + public String getPlugin() { + return WebUI.PLUGIN_ID/* IExternalToolConstants.PLUGIN_ID*/; + } + + /** + * Returns always null. + * + * @see IStatus#getException() + */ + public Throwable getException() { + return null; + } + + /** + * Returns always the error severity. + * + * @see IStatus#getCode() + */ + public int getCode() { + return fSeverity; + } + + /** + * Returns always null. + * + * @see IStatus#getChildren() + */ + public IStatus[] getChildren() { + return new IStatus[0]; + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java index 7c3cddc..ca6517c 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java @@ -52,7 +52,7 @@ import net.sourceforge.phpeclipse.builder.ExternalEditorInput; import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider; import net.sourceforge.phpeclipse.builder.FileStorage; import net.sourceforge.phpeclipse.builder.IdentifierIndexManager; -import net.sourceforge.phpeclipse.phpeditor.DocumentAdapter; +import net.sourceforge.phpeclipse.DocumentAdapter; import net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider; import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider; //import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr; diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/ValidBreakpointLocationLocator.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/ValidBreakpointLocationLocator.java index d8ced2c..660a92e 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/ValidBreakpointLocationLocator.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/ValidBreakpointLocationLocator.java @@ -26,26 +26,26 @@ import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration; import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; import org.eclipse.jdt.core.dom.ArrayAccess; import org.eclipse.jdt.core.dom.ArrayCreation;*/ -import net.sourceforge.phpdt.internal.compiler.ast.ArrayInitializer; +//import net.sourceforge.phpdt.internal.compiler.ast.ArrayInitializer; /*import org.eclipse.jdt.core.dom.ArrayType;*/ -import net.sourceforge.phpdt.internal.compiler.ast.AssertStatement; -import net.sourceforge.phpdt.internal.compiler.ast.Assignment; -import net.sourceforge.phpdt.internal.compiler.ast.Block; -import net.sourceforge.phpdt.internal.compiler.ast.ThrowStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.AssertStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.Assignment; +//import net.sourceforge.phpdt.internal.compiler.ast.Block; +//import net.sourceforge.phpdt.internal.compiler.ast.ThrowStatement; /*import org.eclipse.jdt.core.dom.BlockComment; import org.eclipse.jdt.core.dom.BodyDeclaration; import org.eclipse.jdt.core.dom.BooleanLiteral;*/ -import net.sourceforge.phpdt.internal.compiler.ast.BreakStatement; -import net.sourceforge.phpdt.internal.compiler.ast.CastExpression; +//import net.sourceforge.phpdt.internal.compiler.ast.BreakStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.CastExpression; /*import org.eclipse.jdt.core.dom.CatchClause; import org.eclipse.jdt.core.dom.CharacterLiteral; import org.eclipse.jdt.core.dom.ClassInstanceCreation; import org.eclipse.jdt.core.dom.CompilationUnit;*/ -import net.sourceforge.phpdt.internal.compiler.ast.ConditionalExpression; +//import net.sourceforge.phpdt.internal.compiler.ast.ConditionalExpression; /*import org.eclipse.jdt.core.dom.ConstructorInvocation;*/ -import net.sourceforge.phpdt.internal.compiler.ast.ContinueStatement; -import net.sourceforge.phpdt.internal.compiler.ast.DoStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.ContinueStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.DoStatement; import net.sourceforge.phpdt.internal.compiler.ast.EmptyStatement; /*import org.eclipse.jdt.core.dom.EnhancedForStatement; import org.eclipse.jdt.core.dom.EnumConstantDeclaration; @@ -53,17 +53,17 @@ import org.eclipse.jdt.core.dom.EnumDeclaration; import org.eclipse.jdt.core.dom.Expression; import org.eclipse.jdt.core.dom.ExpressionStatement; import org.eclipse.jdt.core.dom.FieldAccess;*/ -import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration; -import net.sourceforge.phpdt.internal.compiler.ast.ForStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration; +//import net.sourceforge.phpdt.internal.compiler.ast.ForStatement; /*import org.eclipse.jdt.core.dom.IBinding; import org.eclipse.jdt.core.dom.IVariableBinding;*/ -import net.sourceforge.phpdt.internal.compiler.ast.IfStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.IfStatement; /*import org.eclipse.jdt.core.dom.ImportDeclaration; import org.eclipse.jdt.core.dom.InfixExpression;*/ -import net.sourceforge.phpdt.internal.compiler.ast.Initializer; -import net.sourceforge.phpdt.internal.compiler.ast.InstanceOfExpression; +//import net.sourceforge.phpdt.internal.compiler.ast.Initializer; +//import net.sourceforge.phpdt.internal.compiler.ast.InstanceOfExpression; /*import org.eclipse.jdt.core.dom.Javadoc;*/ -import net.sourceforge.phpdt.internal.compiler.ast.LabeledStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.LabeledStatement; /*import org.eclipse.jdt.core.dom.LineComment; import org.eclipse.jdt.core.dom.MarkerAnnotation; import org.eclipse.jdt.core.dom.MemberRef; @@ -75,41 +75,41 @@ import org.eclipse.jdt.core.dom.MethodRefParameter; import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jdt.core.dom.Name; import org.eclipse.jdt.core.dom.NormalAnnotation;*/ -import net.sourceforge.phpdt.internal.compiler.ast.NullLiteral; -import net.sourceforge.phpdt.internal.compiler.ast.NumberLiteral; +//import net.sourceforge.phpdt.internal.compiler.ast.NullLiteral; +//import net.sourceforge.phpdt.internal.compiler.ast.NumberLiteral; /*import org.eclipse.jdt.core.dom.PackageDeclaration; import org.eclipse.jdt.core.dom.ParameterizedType; import org.eclipse.jdt.core.dom.ParenthesizedExpression;*/ -import net.sourceforge.phpdt.internal.compiler.ast.PostfixExpression; -import net.sourceforge.phpdt.internal.compiler.ast.PrefixExpression; +//import net.sourceforge.phpdt.internal.compiler.ast.PostfixExpression; +//import net.sourceforge.phpdt.internal.compiler.ast.PrefixExpression; /*import org.eclipse.jdt.core.dom.PrimitiveType; import org.eclipse.jdt.core.dom.QualifiedName; import org.eclipse.jdt.core.dom.QualifiedType;*/ -import net.sourceforge.phpdt.internal.compiler.ast.ReturnStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.ReturnStatement; /*import org.eclipse.jdt.core.dom.SimpleName; import org.eclipse.jdt.core.dom.SimpleType; import org.eclipse.jdt.core.dom.SingleMemberAnnotation; import org.eclipse.jdt.core.dom.SingleVariableDeclaration;*/ -import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral; +//import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral; /*import org.eclipse.jdt.core.dom.SuperConstructorInvocation; import org.eclipse.jdt.core.dom.SuperFieldAccess; import org.eclipse.jdt.core.dom.SuperMethodInvocation; import org.eclipse.jdt.core.dom.SwitchCase;*/ -import net.sourceforge.phpdt.internal.compiler.ast.SwitchStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.SwitchStatement; /*import org.eclipse.jdt.core.dom.SynchronizedStatement; import org.eclipse.jdt.core.dom.TagElement; import org.eclipse.jdt.core.dom.TextElement; import org.eclipse.jdt.core.dom.ThisExpression;*/ -import net.sourceforge.phpdt.internal.compiler.ast.ThrowStatement; -import net.sourceforge.phpdt.internal.compiler.ast.TryStatement; -import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration; +//import net.sourceforge.phpdt.internal.compiler.ast.ThrowStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.TryStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration; /*import org.eclipse.jdt.core.dom.TypeDeclarationStatement; import org.eclipse.jdt.core.dom.TypeLiteral; import org.eclipse.jdt.core.dom.TypeParameter; import org.eclipse.jdt.core.dom.VariableDeclarationExpression; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; import org.eclipse.jdt.core.dom.VariableDeclarationStatement;*/ -import net.sourceforge.phpdt.internal.compiler.ast.WhileStatement; +//import net.sourceforge.phpdt.internal.compiler.ast.WhileStatement; /*import org.eclipse.jdt.core.dom.WildcardType; import org.eclipse.jdt.core.dom.PrefixExpression.Operator;*/ @@ -754,12 +754,12 @@ public class ValidBreakpointLocationLocator extends ASTVisitor { super.endVisit(node); }*/ - private String getLabel() { - if (fLabels == null || fLabels.isEmpty()) { - return null; - } - return (String) fLabels.get(fLabels.size() - 1); - } +// private String getLabel() { +// if (fLabels == null || fLabels.isEmpty()) { +// return null; +// } +// return (String) fLabels.get(fLabels.size() - 1); +// } // private void nestLabel(String label) { // if (fLabels == null) { diff --git a/net.sourceforge.phpeclipse/META-INF/MANIFEST.MF b/net.sourceforge.phpeclipse/META-INF/MANIFEST.MF index 9443ab0..f5c610f 100644 --- a/net.sourceforge.phpeclipse/META-INF/MANIFEST.MF +++ b/net.sourceforge.phpeclipse/META-INF/MANIFEST.MF @@ -48,9 +48,11 @@ Export-Package: net.sourceforge.phpdt.core, net.sourceforge.phpeclipse.wizards Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources, - org.eclipse.ltk.core.refactoring + org.eclipse.ltk.core.refactoring, + org.eclipse.text;bundle-version="3.4.0", + org.eclipse.ui.ide, + org.eclipse.swt Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.4 Import-Package: net.sourceforge.phpdt.internal.core.util, - org.eclipse.core.filebuffers, - org.eclipse.ui + org.eclipse.core.filebuffers diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/DocumentAdapter.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/DocumentAdapter.java new file mode 100644 index 0000000..5c81353 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/DocumentAdapter.java @@ -0,0 +1,515 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package net.sourceforge.phpeclipse; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import net.sourceforge.phpdt.core.BufferChangedEvent; +import net.sourceforge.phpdt.core.IBuffer; +import net.sourceforge.phpdt.core.IBufferChangedListener; +import net.sourceforge.phpdt.core.IOpenable; +import net.sourceforge.phpdt.core.JavaModelException; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; + +import org.eclipse.core.filebuffers.FileBuffers; +import org.eclipse.core.filebuffers.ITextFileBuffer; +import org.eclipse.core.filebuffers.ITextFileBufferManager; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +//incastrix +//import org.eclipse.jface.text.Assert; +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DefaultLineTracker; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentListener; +import org.eclipse.swt.widgets.Display; + +/** + * Adapts IDocument to IBuffer. Uses the same + * algorithm as the text widget to determine the buffer's line delimiter. All + * text inserted into the buffer is converted to this line delimiter. This class + * is public for test purposes only. + */ +public class DocumentAdapter implements IBuffer, IDocumentListener { + + /** + * Internal implementation of a NULL instanceof IBuffer. + */ + static private class NullBuffer implements IBuffer { + public void addBufferChangedListener(IBufferChangedListener listener) { + } + + public void append(char[] text) { + } + + public void append(String text) { + } + + public void close() { + } + + public char getChar(int position) { + return 0; + } + + public char[] getCharacters() { + return null; + } + + public String getContents() { + return null; + } + + public int getLength() { + return 0; + } + + public IOpenable getOwner() { + return null; + } + + public String getText(int offset, int length) { + return null; + } + + public IResource getUnderlyingResource() { + return null; + } + + public boolean hasUnsavedChanges() { + return false; + } + + public boolean isClosed() { + return false; + } + + public boolean isReadOnly() { + return true; + } + + public void removeBufferChangedListener(IBufferChangedListener listener) { + } + + public void replace(int position, int length, char[] text) { + } + + public void replace(int position, int length, String text) { + } + + public void save(IProgressMonitor progress, boolean force) + throws JavaModelException { + } + + public void setContents(char[] contents) { + } + + public void setContents(String contents) { + } + } + + /** NULL implementing IBuffer */ + public final static IBuffer NULL = new NullBuffer(); + + /** + * Executes a document set content call in the ui thread. + */ + protected class DocumentSetCommand implements Runnable { + + private String fContents; + + public void run() { + fDocument.set(fContents); + } + + public void set(String contents) { + fContents = contents; + Display.getDefault().syncExec(this); + } + } + + /** + * Executes a document replace call in the ui thread. + */ + protected class DocumentReplaceCommand implements Runnable { + + private int fOffset; + + private int fLength; + + private String fText; + + public void run() { + try { + fDocument.replace(fOffset, fLength, fText); + } catch (BadLocationException x) { + // ignore + } + } + + public void replace(int offset, int length, String text) { + fOffset = offset; + fLength = length; + fText = text; + Display.getDefault().syncExec(this); + } + } + + private static final boolean DEBUG_LINE_DELIMITERS = true; + + private IOpenable fOwner; + + private IFile fFile; + + private ITextFileBuffer fTextFileBuffer; + + private IDocument fDocument; + + private DocumentSetCommand fSetCmd = new DocumentSetCommand(); + + private DocumentReplaceCommand fReplaceCmd = new DocumentReplaceCommand(); + + private Set fLegalLineDelimiters; + + private List fBufferListeners = new ArrayList(3); + + private IStatus fStatus; + + /** + * This method is public for test purposes only. + */ + public DocumentAdapter(IOpenable owner, IFile file) { + + fOwner = owner; + fFile = file; + + initialize(); + } + + private void initialize() { + ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager(); + IPath location = fFile.getFullPath(); + try { + manager.connect(location, new NullProgressMonitor()); + fTextFileBuffer = manager.getTextFileBuffer(location); + fDocument = fTextFileBuffer.getDocument(); + } catch (CoreException x) { + fStatus = x.getStatus(); + fDocument = manager.createEmptyDocument(location); + } + fDocument.addPrenotifiedDocumentListener(this); + } + + /** + * Returns the status of this document adapter. + */ + public IStatus getStatus() { + if (fStatus != null) + return fStatus; + if (fTextFileBuffer != null) + return fTextFileBuffer.getStatus(); + return null; + } + + /** + * Returns the adapted document. + * + * @return the adapted document + */ + public IDocument getDocument() { + return fDocument; + } + + /* + * @see IBuffer#addBufferChangedListener(IBufferChangedListener) + */ + public void addBufferChangedListener(IBufferChangedListener listener) { + Assert.isNotNull(listener); + if (!fBufferListeners.contains(listener)) + fBufferListeners.add(listener); + } + + /* + * @see IBuffer#removeBufferChangedListener(IBufferChangedListener) + */ + public void removeBufferChangedListener(IBufferChangedListener listener) { + Assert.isNotNull(listener); + fBufferListeners.remove(listener); + } + + /* + * @see IBuffer#append(char[]) + */ + public void append(char[] text) { + append(new String(text)); + } + + /* + * @see IBuffer#append(String) + */ + public void append(String text) { + if (DEBUG_LINE_DELIMITERS) { + validateLineDelimiters(text); + } + fReplaceCmd.replace(fDocument.getLength(), 0, text); + } + + /* + * @see IBuffer#close() + */ + public void close() { + + if (isClosed()) + return; + + IDocument d = fDocument; + fDocument = null; + d.removePrenotifiedDocumentListener(this); + + if (fTextFileBuffer != null) { + ITextFileBufferManager manager = FileBuffers + .getTextFileBufferManager(); + try { + manager.disconnect(fTextFileBuffer.getLocation(), + new NullProgressMonitor()); + } catch (CoreException x) { + // ignore + } + fTextFileBuffer = null; + } + + fireBufferChanged(new BufferChangedEvent(this, 0, 0, null)); + fBufferListeners.clear(); + } + + /* + * @see IBuffer#getChar(int) + */ + public char getChar(int position) { + try { + return fDocument.getChar(position); + } catch (BadLocationException x) { + throw new ArrayIndexOutOfBoundsException(); + } + } + + /* + * @see IBuffer#getCharacters() + */ + public char[] getCharacters() { + String content = getContents(); + return content == null ? null : content.toCharArray(); + } + + /* + * @see IBuffer#getContents() + */ + public String getContents() { + return fDocument.get(); + } + + /* + * @see IBuffer#getLength() + */ + public int getLength() { + return fDocument.getLength(); + } + + /* + * @see IBuffer#getOwner() + */ + public IOpenable getOwner() { + return fOwner; + } + + /* + * @see IBuffer#getText(int, int) + */ + public String getText(int offset, int length) { + try { + return fDocument.get(offset, length); + } catch (BadLocationException x) { + throw new ArrayIndexOutOfBoundsException(); + } + } + + /* + * @see IBuffer#getUnderlyingResource() + */ + public IResource getUnderlyingResource() { + return fFile; + } + + /* + * @see IBuffer#hasUnsavedChanges() + */ + public boolean hasUnsavedChanges() { + return fTextFileBuffer != null ? fTextFileBuffer.isDirty() : false; + } + + /* + * @see IBuffer#isClosed() + */ + public boolean isClosed() { + return fDocument == null; + } + + /* + * @see IBuffer#isReadOnly() + */ + public boolean isReadOnly() { + IResource resource = getUnderlyingResource(); + return resource == null ? true : resource.getResourceAttributes() + .isReadOnly(); + } + + /* + * @see IBuffer#replace(int, int, char[]) + */ + public void replace(int position, int length, char[] text) { + replace(position, length, new String(text)); + } + + /* + * @see IBuffer#replace(int, int, String) + */ + public void replace(int position, int length, String text) { + if (DEBUG_LINE_DELIMITERS) { + validateLineDelimiters(text); + } + fReplaceCmd.replace(position, length, text); + } + + /* + * @see IBuffer#save(IProgressMonitor, boolean) + */ + public void save(IProgressMonitor progress, boolean force) + throws JavaModelException { + try { + if (fTextFileBuffer != null) + fTextFileBuffer.commit(progress, force); + } catch (CoreException e) { + throw new JavaModelException(e); + } + } + + /* + * @see IBuffer#setContents(char[]) + */ + public void setContents(char[] contents) { + setContents(new String(contents)); + } + + /* + * @see IBuffer#setContents(String) + */ + public void setContents(String contents) { + int oldLength = fDocument.getLength(); + + if (contents == null) { + + if (oldLength != 0) + fSetCmd.set(""); //$NON-NLS-1$ + + } else { + + // set only if different + if (DEBUG_LINE_DELIMITERS) { + validateLineDelimiters(contents); + } + + if (!contents.equals(fDocument.get())) + fSetCmd.set(contents); + } + } + + private void validateLineDelimiters(String contents) { + + if (fLegalLineDelimiters == null) { + // collect all line delimiters in the document + HashSet existingDelimiters = new HashSet(); + + for (int i = fDocument.getNumberOfLines() - 1; i >= 0; i--) { + try { + String curr = fDocument.getLineDelimiter(i); + if (curr != null) { + existingDelimiters.add(curr); + } + } catch (BadLocationException e) { + PHPeclipsePlugin.log(e); + } + } + if (existingDelimiters.isEmpty()) { + return; // first insertion of a line delimiter: no test + } + fLegalLineDelimiters = existingDelimiters; + + } + + DefaultLineTracker tracker = new DefaultLineTracker(); + tracker.set(contents); + + int lines = tracker.getNumberOfLines(); + if (lines <= 1) + return; + + for (int i = 0; i < lines; i++) { + try { + String curr = tracker.getLineDelimiter(i); + if (curr != null && !fLegalLineDelimiters.contains(curr)) { + StringBuffer buf = new StringBuffer( + "New line delimiter added to new code: "); //$NON-NLS-1$ + for (int k = 0; k < curr.length(); k++) { + buf.append(String.valueOf((int) curr.charAt(k))); + } + PHPeclipsePlugin.log(new Exception(buf.toString())); + } + } catch (BadLocationException e) { + PHPeclipsePlugin.log(e); + } + } + } + + /* + * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent) + */ + public void documentAboutToBeChanged(DocumentEvent event) { + // there is nothing to do here + } + + /* + * @see IDocumentListener#documentChanged(DocumentEvent) + */ + public void documentChanged(DocumentEvent event) { + fireBufferChanged(new BufferChangedEvent(this, event.getOffset(), event + .getLength(), event.getText())); + } + + private void fireBufferChanged(BufferChangedEvent event) { + if (fBufferListeners != null && fBufferListeners.size() > 0) { + Iterator e = new ArrayList(fBufferListeners).iterator(); + while (e.hasNext()) + ((IBufferChangedListener) e.next()).bufferChanged(event); + } + } +} -- 1.7.1