import org.eclipse.jface.preference.IPreferenceStore;
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;
import org.eclipse.jface.text.IRegion;
/**
* Auto indent strategy for java strings
*/
-public class JavaStringAutoIndentStrategySQ extends DefaultAutoIndentStrategy {
-
+public class JavaStringAutoIndentStrategySQ extends DefaultIndentLineAutoEditStrategy {
+
private String fPartitioning;
-
+
/**
* The input string doesn't contain any line delimiter.
*
* @return the displayable string.
*/
private String displayString(String inputString, String indentation, String delimiter) {
-
+
int length = inputString.length();
StringBuffer buffer = new StringBuffer(length);
java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(inputString, "\n\r", true); //$NON-NLS-1$
while (tokenizer.hasMoreTokens()){
-
+
String token = tokenizer.nextToken();
if (token.equals("\r")) { //$NON-NLS-1$
buffer.append("\\r"); //$NON-NLS-1$
buffer.append(indentation);
buffer.append("\'"); //$NON-NLS-1$
continue;
- }
-
+ }
+
StringBuffer tokenBuffer = new StringBuffer();
- for (int i = 0; i < token.length(); i++){
+ for (int i = 0; i < token.length(); i++){
char c = token.charAt(i);
switch (c) {
case '\r' :
super();
fPartitioning= partitioning;
}
-
+
private boolean isLineDelimiter(IDocument document, String text) {
String[] delimiters= document.getLegalLineDelimiters();
if (delimiters != null)
return TextUtilities.equals(delimiters, text) > -1;
return false;
}
-
+
private String getLineIndentation(IDocument document, int offset) throws BadLocationException {
// find start of line
int adjustedOffset= (offset == document.getLength() ? offset - 1 : offset);
IRegion line= document.getLineInformationOfOffset(adjustedOffset);
int start= line.getOffset();
-
+
// find white spaces
int end= findEndOfWhiteSpace(document, start, offset);
-
+
return document.get(start, end - start);
}
- private String getModifiedText(String string, String indentation, String delimiter) throws BadLocationException {
+ private String getModifiedText(String string, String indentation, String delimiter) throws BadLocationException {
return displayString(string, indentation, delimiter);
}
// new JavaAutoIndentStrategy(fPartitioning).customizeDocumentCommand(document, command);
return;
}
-
+
if (command.offset == offset + length && document.getChar(offset + length - 1) == '\'')
return;
String string= document.get(line.getOffset(), offset - line.getOffset());
if (string.trim().length() != 0)
indentation += String.valueOf("\t\t"); //$NON-NLS-1$
-
+
IPreferenceStore preferenceStore= PHPeclipsePlugin.getDefault().getPreferenceStore();
if (isLineDelimiter(document, command.text))
command.text= "\' ." + command.text + indentation + "\'"; //$NON-NLS-1$//$NON-NLS-2$
else if (command.text.length() > 1 && preferenceStore.getBoolean(PreferenceConstants.EDITOR_ESCAPE_STRINGS_SQ))
- command.text= getModifiedText(command.text, indentation, delimiter);
+ command.text= getModifiedText(command.text, indentation, delimiter);
}
-
+
private boolean isSmartMode() {
IWorkbenchPage page= PHPeclipsePlugin.getActivePage();
if (page != null) {
- IEditorPart part= page.getActiveEditor();
+ IEditorPart part= page.getActiveEditor();
if (part instanceof ITextEditorExtension3) {
ITextEditorExtension3 extension= (ITextEditorExtension3) part;
return extension.getInsertMode() == ITextEditorExtension3.SMART_INSERT;
return;
IPreferenceStore preferenceStore= PHPeclipsePlugin.getDefault().getPreferenceStore();
-
+
if (preferenceStore.getBoolean(PreferenceConstants.EDITOR_WRAP_STRINGS_SQ) && isSmartMode())
javaStringIndentAfterNewLine(document, command);
-
+
} catch (BadLocationException e) {
}
}