http://www.eclipse.org/legal/cpl-v10.html
Contributors:
- IBM Corporation - Initial implementation
- Klaus Hartlage - www.eclipseproject.de
+ IBM Corporation - Initial implementation
+ www.phpeclipse.de
**********************************************************************/
package net.sourceforge.phpeclipse.phpeditor.php;
import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DefaultAutoIndentStrategy;
+import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
import org.eclipse.jface.text.DocumentCommand;
import org.eclipse.jface.text.IDocument;
/**
* Auto indent strategy sensitive to brackets.
*/
-public class PHPAutoIndentStrategy extends DefaultAutoIndentStrategy {
+public class PHPAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
public PHPAutoIndentStrategy() {
}
-
+
/* (non-Javadoc)
* Method declared on IAutoIndentStrategy
*/
public void customizeDocumentCommand(IDocument d, DocumentCommand c) {
if (c.length == 0 && c.text != null && endsWithDelimiter(d, c.text))
smartIndentAfterNewLine(d, c);
- else if ("}".equals(c.text)) {
+ else if ("}".equals(c.text)) {
smartInsertAfterBracket(d, c);
}
}
-
+
/**
* Returns whether or not the text ends with one of the given search strings.
*/
return false;
}
-
+
/**
* Returns the line number of the next bracket after end.
* @returns the line number of the next matching bracket after end
int start= document.getLineOffset(line);
int brackcount= getBracketCount(document, start, end, false) - closingBracketIncrease;
- // sum up the brackets counts of each line (closing brackets count negative,
+ // sum up the brackets counts of each line (closing brackets count negative,
// opening positive) until we find a line the brings the count to zero
while (brackcount < 0) {
line--;
}
return line;
}
-
+
/**
* Returns the bracket value of a section of text. Closing brackets have a value of -1 and
* open brackets have a value of 1.
// a comment starts, advance to the comment end
begin= getCommentEnd(document, begin + 1, end);
} else if (next == '/') {
- // '//'-comment: nothing to do anymore on this line
+ // '//'-comment: nothing to do anymore on this line
begin= end;
}
}
}
return bracketcount;
}
-
+
/**
* Returns the end position a comment starting at pos.
* @returns the end position a comment starting at pos
}
return end;
}
-
+
/**
* Returns the String at line with the leading whitespace removed.
* @returns the String at line with the leading whitespace removed.
return ""; //$NON-NLS-1$
}
}
-
+
/**
* Returns the position of the character in the document after position.
* @returns the next location of character.
}
return end;
}
-
+
/**
* Set the indent of a new line based on the command provided in the supplied document.
* @param document - the document being parsed
} else {
int start= document.getLineOffset(line);
int whiteend= findEndOfWhiteSpace(document, start, command.offset);
+ int offset = -1;
+// if (command.offset > 0 && command.offset < docLength && document.getChar(command.offset-1) == '{') {
+// offset = command.offset;
+// }
buf.append(document.get(start, whiteend - start));
if (getBracketCount(document, start, command.offset, true) > 0) {
buf.append('\t');
}
+// if (offset >= 0) {
+// buf.append('}');
+// }
}
command.text= buf.toString();
System.out.println(PHPEditorMessages.getString("AutoIndent.error.bad_location_1")); //$NON-NLS-1$
}
}
-
+
/**
* Set the indent of a bracket based on the command provided in the supplied document.
* @param document - the document being parsed