A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / actions / RTrimAction.java
index 154b992..d4a1718 100644 (file)
@@ -41,7 +41,7 @@ public class RTrimAction implements IEditorActionDelegate {
        ITextEditor editor = null;
 
        /**
-        *  
+        * 
         */
        public RTrimAction() {
                super();
@@ -58,8 +58,10 @@ public class RTrimAction implements IEditorActionDelegate {
         * this gets called for every action
         */
        public void run(IAction action) {
-               IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
-               ITextSelection sel = (ITextSelection) editor.getSelectionProvider().getSelection();
+               IDocument doc = editor.getDocumentProvider().getDocument(
+                               editor.getEditorInput());
+               ITextSelection sel = (ITextSelection) editor.getSelectionProvider()
+                               .getSelection();
 
                int currentLine = 0;
                int originalCursorOffset = sel.getOffset();
@@ -67,25 +69,28 @@ public class RTrimAction implements IEditorActionDelegate {
                int originalSelectionLength = sel.getLength();
                int selectionLength = originalSelectionLength;
                String oldText;
-               int     lineEnd;
-               
+               int lineEnd;
+
                try {
 
                        while (currentLine < doc.getNumberOfLines()) {
                                int offset = doc.getLineOffset(currentLine);
                                int length = doc.getLineLength(currentLine);
                                oldText = doc.get(offset, length);
-                               
-                               //-- Starts at the end of the line, looking for the first non-first 'white space'
-                               //-- it then breaks out. No point in carrying on, as we have found our true line end
-                               for (lineEnd=oldText.length(); lineEnd > 0; --lineEnd ){
-                                       if ( oldText.charAt(lineEnd-1) != '\t' && oldText.charAt(lineEnd-1) != ' ' ){
+
+                               // -- Starts at the end of the line, looking for the first
+                               // non-first 'white space'
+                               // -- it then breaks out. No point in carrying on, as we have
+                               // found our true line end
+                               for (lineEnd = oldText.length(); lineEnd > 0; --lineEnd) {
+                                       if (oldText.charAt(lineEnd - 1) != '\t'
+                                                       && oldText.charAt(lineEnd - 1) != ' ') {
                                                break;
                                        }
                                }
-                               
-                               //-- Only replace the line if the lengths are different
-                               if ( lineEnd != oldText.length() ) {
+
+                               // -- Only replace the line if the lengths are different
+                               if (lineEnd != oldText.length()) {
                                        String newText = oldText.substring(0, lineEnd);
                                        doc.replace(offset, length, newText);
 
@@ -93,16 +98,27 @@ public class RTrimAction implements IEditorActionDelegate {
                                                if (oldText.length() != newText.length()) {
                                                        cursorOffset -= oldText.length() - newText.length();
                                                }
-                                       } else if (offset <= cursorOffset + selectionLength     && selectionLength > 0) {
+                                       } else if (offset <= cursorOffset + selectionLength
+                                                       && selectionLength > 0) {
                                                selectionLength -= oldText.length() - newText.length();
-                                       }       else if (offset + length == cursorOffset + 2) { // Check if the cursor is at the end of the line.
+                                       } else if (offset + length == cursorOffset + 2) { // Check
+                                                                                                                                               // if
+                                                                                                                                               // the
+                                                                                                                                               // cursor
+                                                                                                                                               // is at
+                                                                                                                                               // the
+                                                                                                                                               // end
+                                                                                                                                               // of
+                                                                                                                                               // the
+                                                                                                                                               // line.
                                                cursorOffset -= 2;
                                        }
                                }
                                currentLine++;
                        }
 
-                       TextSelection selection = new TextSelection(doc, cursorOffset, selectionLength);
+                       TextSelection selection = new TextSelection(doc, cursorOffset,
+                                       selectionLength);
                        editor.getSelectionProvider().setSelection(selection);
                } catch (Exception blx) {
                        blx.printStackTrace();