1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.internal.ui.text.phpdoc;
14 import java.text.BreakIterator;
16 import net.sourceforge.phpdt.core.ICompilationUnit;
17 import net.sourceforge.phpdt.core.IJavaElement;
18 import net.sourceforge.phpdt.core.IMethod;
19 import net.sourceforge.phpdt.core.ISourceRange;
20 import net.sourceforge.phpdt.core.IType;
21 import net.sourceforge.phpdt.internal.corext.util.Strings;
22 import net.sourceforge.phpdt.ui.CodeGeneration;
23 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
24 import net.sourceforge.phpdt.ui.PreferenceConstants;
25 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.core.runtime.Preferences;
29 import org.eclipse.jface.preference.IPreferenceStore;
30 import org.eclipse.jface.text.BadLocationException;
31 import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
32 import org.eclipse.jface.text.DocumentCommand;
33 import org.eclipse.jface.text.IDocument;
34 import org.eclipse.jface.text.IRegion;
35 import org.eclipse.jface.text.ITypedRegion;
36 import org.eclipse.jface.text.TextUtilities;
37 import org.eclipse.ui.IEditorPart;
38 import org.eclipse.ui.IWorkbenchPage;
39 import org.eclipse.ui.IWorkbenchWindow;
40 import org.eclipse.ui.PlatformUI;
41 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
42 import org.eclipse.ui.texteditor.ITextEditorExtension3;
45 * Auto indent strategy for java doc comments
47 public class JavaDocAutoIndentStrategy extends
48 DefaultIndentLineAutoEditStrategy {
50 private String fPartitioning;
53 * Creates a new Javadoc auto indent strategy for the given document
57 * the document partitioning
59 public JavaDocAutoIndentStrategy(String partitioning) {
60 fPartitioning = partitioning;
63 private static String getLineDelimiter(IDocument document) {
65 if (document.getNumberOfLines() > 1)
66 return document.getLineDelimiter(0);
67 } catch (BadLocationException e) {
68 PHPeclipsePlugin.log(e);
71 return System.getProperty("line.separator"); //$NON-NLS-1$
75 * Copies the indentation of the previous line and add a star. If the
76 * javadoc just started on this line add standard method tags and close the
80 * the document to work on
82 * the command to deal with
84 private void jdocIndentAfterNewLine(IDocument d, DocumentCommand c) {
86 if (c.offset == -1 || d.getLength() == 0)
91 int p = (c.offset == d.getLength() ? c.offset - 1 : c.offset);
92 IRegion info = d.getLineInformationOfOffset(p);
93 int start = info.getOffset();
96 int end = findEndOfWhiteSpace(d, start, c.offset);
98 StringBuffer buf = new StringBuffer(c.text);
99 if (end >= start) { // 1GEYL1R: ITPJUI:ALL - java doc edit smartness
100 // not work for class comments
102 String indentation = jdocExtractLinePrefix(d, d
103 .getLineOfOffset(c.offset));
104 buf.append(indentation);
105 if (end < c.offset) {
106 if (d.getChar(end) == '/') {
107 // javadoc started on this line
108 buf.append(" * "); //$NON-NLS-1$
112 .getPreferenceStore()
114 PreferenceConstants.EDITOR_CLOSE_JAVADOCS)
115 && isNewComment(d, c.offset, fPartitioning)) {
116 String lineDelimiter = getLineDelimiter(d);
118 String endTag = lineDelimiter + indentation + " */"; //$NON-NLS-1$
119 d.replace(c.offset, 0, endTag); //$NON-NLS-1$
120 // evaluate method signature
121 ICompilationUnit unit = getCompilationUnit();
124 // (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS)
129 // JavaModelUtil.reconcile(unit);
130 // String string= createJavaDocTags(d, c,
131 // indentation, lineDelimiter, unit);
132 // if (string != null) {
133 // d.replace(c.offset, 0, string);
135 // } catch (CoreException e) {
145 c.text = buf.toString();
147 } catch (BadLocationException excp) {
152 private String createJavaDocTags(IDocument document,
153 DocumentCommand command, String indentation, String lineDelimiter,
154 ICompilationUnit unit) throws CoreException, BadLocationException {
155 IJavaElement element = unit.getElementAt(command.offset);
159 switch (element.getElementType()) {
160 case IJavaElement.TYPE:
161 return createTypeTags(document, command, indentation,
162 lineDelimiter, (IType) element);
164 case IJavaElement.METHOD:
165 return createMethodTags(document, command, indentation,
166 lineDelimiter, (IMethod) element);
174 * Removes start and end of a comment and corrects indentation and line
177 private String prepareTemplateComment(String comment, String indentation,
178 String lineDelimiter) {
179 // trim comment start and end if any
180 if (comment.endsWith("*/")) //$NON-NLS-1$
181 comment = comment.substring(0, comment.length() - 2);
182 comment = comment.trim();
183 if (comment.startsWith("/*")) { //$NON-NLS-1$
184 if (comment.length() > 2 && comment.charAt(2) == '*') {
185 comment = comment.substring(3); // remove '/**'
187 comment = comment.substring(2); // remove '/*'
190 // return Strings.changeIndent(comment, 0,
191 // CodeFormatterUtil.getTabWidth(), indentation, lineDelimiter);
192 return Strings.changeIndent(comment, 0, getTabWidth(), indentation,
196 public static int getTabWidth() {
197 Preferences preferences = PHPeclipsePlugin.getDefault()
198 .getPluginPreferences();
200 .getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);
203 private String createTypeTags(IDocument document, DocumentCommand command,
204 String indentation, String lineDelimiter, IType type)
205 throws CoreException {
206 String comment = CodeGeneration.getTypeComment(type
207 .getCompilationUnit(), type.getTypeQualifiedName('.'),
209 if (comment != null) {
210 return prepareTemplateComment(comment.trim(), indentation,
216 private String createMethodTags(IDocument document,
217 DocumentCommand command, String indentation, String lineDelimiter,
218 IMethod method) throws CoreException, BadLocationException {
219 IRegion partition = TextUtilities.getPartition(document, fPartitioning,
220 command.offset, false);
221 ISourceRange sourceRange = method.getSourceRange();
222 if (sourceRange == null
223 || sourceRange.getOffset() != partition.getOffset())
226 // IMethod inheritedMethod= getInheritedMethod(method);
227 // String comment= CodeGeneration.getMethodComment(method,
228 // inheritedMethod, lineDelimiter);
229 // if (comment != null) {
230 // comment= comment.trim();
231 // boolean javadocComment= comment.startsWith("/**"); //$NON-NLS-1$
232 // boolean isJavaDoc= partition.getLength() >= 3 &&
233 // document.get(partition.getOffset(), 3).equals("/**"); //$NON-NLS-1$
234 // if (javadocComment == isJavaDoc) {
235 // return prepareTemplateComment(comment, indentation, lineDelimiter);
242 * Returns the method inherited from, <code>null</code> if method is newly
245 // private static IMethod getInheritedMethod(IMethod method) throws
246 // JavaModelException {
247 // IType declaringType= method.getDeclaringType();
248 // ITypeHierarchy typeHierarchy=
249 // SuperTypeHierarchyCache.getTypeHierarchy(declaringType);
250 // return JavaModelUtil.findMethodDeclarationInHierarchy(typeHierarchy,
252 // method.getElementName(), method.getParameterTypes(),
253 // method.isConstructor());
255 protected void jdocIndentForCommentEnd(IDocument d, DocumentCommand c) {
256 if (c.offset < 2 || d.getLength() == 0) {
260 if ("* ".equals(d.get(c.offset - 2, 2))) { //$NON-NLS-1$
261 // modify document command
265 } catch (BadLocationException excp) {
271 * Guesses if the command operates within a newly created javadoc comment or
272 * not. If in doubt, it will assume that the javadoc is new.
274 private static boolean isNewComment(IDocument document, int commandOffset,
275 String partitioning) {
278 int lineIndex = document.getLineOfOffset(commandOffset) + 1;
279 if (lineIndex >= document.getNumberOfLines())
282 IRegion line = document.getLineInformation(lineIndex);
283 ITypedRegion partition = TextUtilities.getPartition(document,
284 partitioning, commandOffset, false);
285 int partitionEnd = partition.getOffset() + partition.getLength();
286 if (line.getOffset() >= partitionEnd)
289 if (document.getLength() == partitionEnd)
290 return true; // partition goes to end of document - probably
293 String comment = document.get(partition.getOffset(), partition
295 if (comment.indexOf("/*", 2) != -1) //$NON-NLS-1$
296 return true; // enclosed another comment -> probably a new
301 } catch (BadLocationException e) {
306 private boolean isSmartMode() {
307 IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
309 IEditorPart part = page.getActiveEditor();
310 if (part instanceof ITextEditorExtension3) {
311 ITextEditorExtension3 extension = (ITextEditorExtension3) part;
312 return extension.getInsertMode() == ITextEditorExtension3.SMART_INSERT;
319 * @see IAutoIndentStrategy#customizeDocumentCommand
321 public void customizeDocumentCommand(IDocument document,
322 DocumentCommand command) {
329 if (command.text != null && command.length == 0) {
330 String[] lineDelimiters = document.getLegalLineDelimiters();
331 int index = TextUtilities
332 .endsWith(lineDelimiters, command.text);
334 // ends with line delimiter
335 if (lineDelimiters[index].equals(command.text))
336 // just the line delimiter
337 jdocIndentAfterNewLine(document, command);
342 if (command.text != null && command.text.equals("/")) { //$NON-NLS-1$
343 jdocIndentForCommentEnd(document, command);
347 ITypedRegion partition = TextUtilities.getPartition(document,
348 fPartitioning, command.offset, true);
349 int partitionStart = partition.getOffset();
350 int partitionEnd = partition.getLength() + partitionStart;
352 String text = command.text;
353 int offset = command.offset;
354 int length = command.length;
357 final int PREFIX_LENGTH = "/*".length(); //$NON-NLS-1$
358 final int POSTFIX_LENGTH = "*/".length(); //$NON-NLS-1$
359 if ((offset < partitionStart + PREFIX_LENGTH || offset + length > partitionEnd
362 && text.length() >= 2
363 && ((text.indexOf("*/") != -1) || (document.getChar(offset) == '*' && text.startsWith("/")))) //$NON-NLS-1$ //$NON-NLS-2$
366 if (command.text == null || command.text.length() == 0)
367 jdocHandleBackspaceDelete(document, command);
369 else if (command.text != null && command.length == 0
370 && command.text.length() > 0)
371 jdocWrapParagraphOnInsert(document, command);
373 } catch (BadLocationException e) {
374 PHPeclipsePlugin.log(e);
378 private void flushCommand(IDocument document, DocumentCommand command)
379 throws BadLocationException {
384 document.replace(command.offset, command.length, command.text);
386 command.doit = false;
387 if (command.text != null)
388 command.offset += command.text.length();
393 protected void jdocWrapParagraphOnInsert(IDocument document,
394 DocumentCommand command) throws BadLocationException {
396 // Assert.isTrue(command.length == 0);
397 // Assert.isTrue(command.text != null && command.text.length() == 1);
399 if (!getPreferenceStore().getBoolean(
400 PreferenceConstants.EDITOR_FORMAT_JAVADOCS))
403 int line = document.getLineOfOffset(command.offset);
404 IRegion region = document.getLineInformation(line);
405 int lineOffset = region.getOffset();
406 int lineLength = region.getLength();
408 String lineContents = document.get(lineOffset, lineLength);
409 StringBuffer buffer = new StringBuffer(lineContents);
410 int start = command.offset - lineOffset;
411 int end = command.length + start;
412 buffer.replace(start, end, command.text);
415 if (command.text != null && command.text.length() != 0
416 && command.text.trim().length() == 0) {
418 String endOfLine = document.get(command.offset, lineOffset
419 + lineLength - command.offset);
422 if (endOfLine.length() == 0) {
423 // move caret to next line
424 flushCommand(document, command);
426 if (isLineTooShort(document, line)) {
427 int[] caretOffset = { command.offset };
428 jdocWrapParagraphFromLine(document, line, caretOffset,
430 command.offset = caretOffset[0];
434 // move caret to next line if possible
435 if (line < document.getNumberOfLines() - 1
436 && isJavaDocLine(document, line + 1)) {
437 String lineDelimiter = document.getLineDelimiter(line);
438 String nextLinePrefix = jdocExtractLinePrefix(document,
440 command.offset += lineDelimiter.length()
441 + nextLinePrefix.length();
445 // inside whitespace at end of line
446 } else if (endOfLine.trim().length() == 0) {
447 // simply insert space
452 // change in prefix region
453 String prefix = jdocExtractLinePrefix(document, line);
454 boolean wrapAlways = command.offset >= lineOffset
455 && command.offset <= lineOffset + prefix.length();
457 // must insert the text now because it may include whitepace
458 flushCommand(document, command);
461 || calculateDisplayedWidth(buffer.toString()) > getMargin()
462 || isLineTooShort(document, line)) {
463 int[] caretOffset = { command.offset };
464 jdocWrapParagraphFromLine(document, line, caretOffset, wrapAlways);
467 command.offset = caretOffset[0];
472 * Method jdocWrapParagraphFromLine.
478 private void jdocWrapParagraphFromLine(IDocument document, int line,
479 int[] caretOffset, boolean always) throws BadLocationException {
481 String indent = jdocExtractLinePrefix(document, line);
483 if (!indent.trim().startsWith("*")) //$NON-NLS-1$
486 if (indent.trim().startsWith("*/")) //$NON-NLS-1$
489 if (!isLineTooLong(document, line)
490 && !isLineTooShort(document, line))
494 boolean caretRelativeToParagraphOffset = false;
495 int caret = caretOffset[0];
497 int caretLine = document.getLineOfOffset(caret);
498 int lineOffset = document.getLineOffset(line);
499 int paragraphOffset = lineOffset + indent.length();
500 if (paragraphOffset < caret) {
501 caret -= paragraphOffset;
502 caretRelativeToParagraphOffset = true;
507 StringBuffer buffer = new StringBuffer();
508 int currentLine = line;
509 while (line == currentLine || isJavaDocLine(document, currentLine)) {
511 if (buffer.length() != 0
512 && !Character.isWhitespace(buffer
513 .charAt(buffer.length() - 1))) {
515 if (currentLine <= caretLine) {
516 // in this case caretRelativeToParagraphOffset is always
522 String string = getLineContents(document, currentLine);
523 buffer.append(string);
526 String paragraph = buffer.toString();
528 if (paragraph.trim().length() == 0)
531 caretOffset[0] = caretRelativeToParagraphOffset ? caret : 0;
532 String delimiter = document.getLineDelimiter(0);
533 String wrapped = formatParagraph(paragraph, caretOffset, indent,
534 delimiter, getMargin());
536 int beginning = document.getLineOffset(line);
537 int end = document.getLineOffset(currentLine);
538 document.replace(beginning, end - beginning, wrapped.toString());
540 caretOffset[0] = caretRelativeToParagraphOffset ? caretOffset[0]
541 + beginning : caret + beginning;
545 * Line break iterator to handle whitespaces as first class citizens.
547 private static class LineBreakIterator {
549 private final String fString;
551 private final BreakIterator fIterator = BreakIterator.getLineInstance();
557 private int fBufferedEnd;
559 public LineBreakIterator(String string) {
561 fIterator.setText(string);
566 fStart = fIterator.first();
572 if (fBufferedEnd != -1) {
580 fEnd = fIterator.next();
582 if (fEnd == BreakIterator.DONE)
585 final String string = fString.substring(fStart, fEnd);
588 if (string.trim().length() == 0)
591 final String word = string.trim();
592 if (word.length() == string.length())
595 // suspected whitespace
597 return fStart + word.length();
602 * Formats a paragraph, using break iterator.
605 * an offset within the paragraph, which will be updated with
606 * respect to formatting.
608 private static String formatParagraph(String paragraph, int[] offset,
609 String prefix, String lineDelimiter, int margin) {
611 LineBreakIterator iterator = new LineBreakIterator(paragraph);
613 StringBuffer paragraphBuffer = new StringBuffer();
614 StringBuffer lineBuffer = new StringBuffer();
615 StringBuffer whiteSpaceBuffer = new StringBuffer();
617 int index = offset[0];
618 int indexBuffer = -1;
620 // line delimiter could be null
621 if (lineDelimiter == null)
622 lineDelimiter = ""; //$NON-NLS-1$
624 for (int start = iterator.first(), end = iterator.next(); end != BreakIterator.DONE; start = end, end = iterator
627 String word = paragraph.substring(start, end);
629 // word is whitespace
630 if (word.trim().length() == 0) {
631 whiteSpaceBuffer.append(word);
633 // first word of line is always appended
634 } else if (lineBuffer.length() == 0) {
635 lineBuffer.append(prefix);
636 lineBuffer.append(whiteSpaceBuffer.toString());
637 lineBuffer.append(word);
640 String line = lineBuffer.toString()
641 + whiteSpaceBuffer.toString() + word.toString();
644 if (calculateDisplayedWidth(line) > margin) {
645 // flush line buffer and wrap paragraph
646 paragraphBuffer.append(lineBuffer.toString());
647 paragraphBuffer.append(lineDelimiter);
648 lineBuffer.setLength(0);
649 lineBuffer.append(prefix);
650 lineBuffer.append(word);
652 // flush index buffer
653 if (indexBuffer != -1) {
654 offset[0] = indexBuffer;
655 // correct for caret in whitespace at the end of line
656 if (whiteSpaceBuffer.length() != 0 && index < start
657 && index >= start - whiteSpaceBuffer.length())
658 offset[0] -= (index - (start - whiteSpaceBuffer
663 whiteSpaceBuffer.setLength(0);
665 // margin not exceeded
667 lineBuffer.append(whiteSpaceBuffer.toString());
668 lineBuffer.append(word);
669 whiteSpaceBuffer.setLength(0);
673 if (index >= start && index < end) {
674 indexBuffer = paragraphBuffer.length() + lineBuffer.length()
676 if (word.trim().length() != 0)
677 indexBuffer -= word.length();
682 paragraphBuffer.append(lineBuffer.toString());
683 paragraphBuffer.append(lineDelimiter);
685 // flush index buffer
686 if (indexBuffer != -1)
687 offset[0] = indexBuffer;
689 // last position is not returned by break iterator
690 else if (offset[0] == paragraph.length())
691 offset[0] = paragraphBuffer.length() - lineDelimiter.length();
693 return paragraphBuffer.toString();
696 private static IPreferenceStore getPreferenceStore() {
697 return PHPeclipsePlugin.getDefault().getPreferenceStore();
701 * Returns the displayed width of a string, taking in account the displayed
702 * tab width. The result can be compared against the print margin.
704 private static int calculateDisplayedWidth(String string) {
706 int tabWidth = getPreferenceStore()
708 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);
713 for (int i = 0; i < string.length(); i++)
714 if ('\t' == string.charAt(i))
715 column += tabWidth - (column % tabWidth);
722 private String jdocExtractLinePrefix(IDocument d, int line)
723 throws BadLocationException {
725 IRegion region = d.getLineInformation(line);
726 int lineOffset = region.getOffset();
727 int index = findEndOfWhiteSpace(d, lineOffset, lineOffset
728 + d.getLineLength(line));
729 if (d.getChar(index) == '*') {
731 if (index != lineOffset + region.getLength()
732 && d.getChar(index) == ' ')
735 return d.get(lineOffset, index - lineOffset);
738 private String getLineContents(IDocument d, int line)
739 throws BadLocationException {
740 int offset = d.getLineOffset(line);
741 int length = d.getLineLength(line);
742 String lineDelimiter = d.getLineDelimiter(line);
743 if (lineDelimiter != null)
744 length = length - lineDelimiter.length();
745 String lineContents = d.get(offset, length);
746 int trim = jdocExtractLinePrefix(d, line).length();
747 return lineContents.substring(trim);
750 private static String getLine(IDocument document, int line)
751 throws BadLocationException {
752 IRegion region = document.getLineInformation(line);
753 return document.get(region.getOffset(), region.getLength());
757 * Returns <code>true</code> if the javadoc line is too short,
758 * <code>false</code> otherwise.
760 private boolean isLineTooShort(IDocument document, int line)
761 throws BadLocationException {
763 if (!isJavaDocLine(document, line + 1))
766 String nextLine = getLineContents(document, line + 1);
767 if (nextLine.trim().length() == 0)
774 * Returns <code>true</code> if the line is too long, <code>false</code>
777 private boolean isLineTooLong(IDocument document, int line)
778 throws BadLocationException {
779 String lineContents = getLine(document, line);
780 return calculateDisplayedWidth(lineContents) > getMargin();
783 private static int getMargin() {
784 return getPreferenceStore()
786 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN);
789 private static final String[] fgInlineTags = {
790 "<b>", "<i>", "<em>", "<strong>", "<code>" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
793 private boolean isInlineTag(String string) {
794 for (int i = 0; i < fgInlineTags.length; i++)
795 if (string.startsWith(fgInlineTags[i]))
801 * returns true if the specified line is part of a paragraph and should be
802 * merged with the previous line.
804 private boolean isJavaDocLine(IDocument document, int line)
805 throws BadLocationException {
807 if (document.getNumberOfLines() < line)
810 int offset = document.getLineOffset(line);
811 int length = document.getLineLength(line);
812 int firstChar = findEndOfWhiteSpace(document, offset, offset + length);
813 length -= firstChar - offset;
814 String lineContents = document.get(firstChar, length);
816 String prefix = lineContents.trim();
817 if (!prefix.startsWith("*") || prefix.startsWith("*/")) //$NON-NLS-1$ //$NON-NLS-2$
820 lineContents = lineContents.substring(1).trim().toLowerCase();
822 // preserve empty lines
823 if (lineContents.length() == 0)
827 if (lineContents.startsWith("@")) //$NON-NLS-1$
830 // preserve HTML tags which are not inline
831 if (lineContents.startsWith("<") && !isInlineTag(lineContents)) //$NON-NLS-1$
837 protected void jdocHandleBackspaceDelete(IDocument document,
840 if (!getPreferenceStore().getBoolean(
841 PreferenceConstants.EDITOR_FORMAT_JAVADOCS))
845 String text = document.get(c.offset, c.length);
846 int line = document.getLineOfOffset(c.offset);
847 int lineOffset = document.getLineOffset(line);
849 // erase line delimiter
850 String lineDelimiter = document.getLineDelimiter(line);
851 if (lineDelimiter != null && lineDelimiter.equals(text)) {
853 String prefix = jdocExtractLinePrefix(document, line + 1);
855 // strip prefix if any
856 if (prefix.length() > 0) {
857 int length = document.getLineDelimiter(line).length()
859 document.replace(c.offset, length, null);
866 // backspace: beginning of a javadoc line
867 } else if (document.getChar(c.offset - 1) == '*'
868 && jdocExtractLinePrefix(document, line).length() - 1 >= c.offset
871 lineDelimiter = document.getLineDelimiter(line - 1);
872 String prefix = jdocExtractLinePrefix(document, line);
873 int length = (lineDelimiter != null ? lineDelimiter.length()
876 document.replace(c.offset - length + 1, length, null);
879 c.offset -= length - 1;
884 document.replace(c.offset, c.length, null);
889 } catch (BadLocationException e) {
890 PHPeclipsePlugin.log(e);
894 int line = document.getLineOfOffset(c.offset);
895 int lineOffset = document.getLineOffset(line);
896 String prefix = jdocExtractLinePrefix(document, line);
897 boolean always = c.offset > lineOffset
898 && c.offset <= lineOffset + prefix.length();
899 int[] caretOffset = { c.offset };
900 jdocWrapParagraphFromLine(document, document
901 .getLineOfOffset(c.offset), caretOffset, always);
902 c.offset = caretOffset[0];
904 } catch (BadLocationException e) {
905 PHPeclipsePlugin.log(e);
910 * Returns the compilation unit of the CompilationUnitEditor invoking the
911 * AutoIndentStrategy, might return <code>null</code> on error.
913 private static ICompilationUnit getCompilationUnit() {
915 IWorkbenchWindow window = PlatformUI.getWorkbench()
916 .getActiveWorkbenchWindow();
920 IWorkbenchPage page = window.getActivePage();
924 IEditorPart editor = page.getActiveEditor();
928 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
929 .getWorkingCopyManager();
930 ICompilationUnit unit = manager.getWorkingCopy(editor.getEditorInput());