X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategySQ.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategySQ.java index 3cc2044..d58f57b 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategySQ.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategySQ.java @@ -25,26 +25,29 @@ import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.texteditor.ITextEditorExtension3; - /** * Auto indent strategy for java strings */ -public class JavaStringAutoIndentStrategySQ extends DefaultIndentLineAutoEditStrategy { +public class JavaStringAutoIndentStrategySQ extends + DefaultIndentLineAutoEditStrategy { private String fPartitioning; /** * The input string doesn't contain any line delimiter. * - * @param inputString the given input string + * @param inputString + * the given input string * @return the displayable string. */ - private String displayString(String inputString, String indentation, String delimiter) { + 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()){ + 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$ @@ -74,36 +77,36 @@ public class JavaStringAutoIndentStrategySQ extends DefaultIndentLineAutoEditStr } 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' : - tokenBuffer.append("\\r"); //$NON-NLS-1$ - break; - case '\n' : - tokenBuffer.append("\\n"); //$NON-NLS-1$ - break; - case '\b' : - tokenBuffer.append("\\b"); //$NON-NLS-1$ - break; - case '\t' : - // keep tabs verbatim - tokenBuffer.append("\t"); //$NON-NLS-1$ - break; - case '\f' : - tokenBuffer.append("\\f"); //$NON-NLS-1$ - break; - case '\"' : - tokenBuffer.append("\\\""); //$NON-NLS-1$ - break; - case '\'' : - tokenBuffer.append("\\'"); //$NON-NLS-1$ - break; - case '\\' : - tokenBuffer.append("\\\\"); //$NON-NLS-1$ - break; - default : - tokenBuffer.append(c); + case '\r': + tokenBuffer.append("\\r"); //$NON-NLS-1$ + break; + case '\n': + tokenBuffer.append("\\n"); //$NON-NLS-1$ + break; + case '\b': + tokenBuffer.append("\\b"); //$NON-NLS-1$ + break; + case '\t': + // keep tabs verbatim + tokenBuffer.append("\t"); //$NON-NLS-1$ + break; + case '\f': + tokenBuffer.append("\\f"); //$NON-NLS-1$ + break; + case '\"': + tokenBuffer.append("\\\""); //$NON-NLS-1$ + break; + case '\'': + tokenBuffer.append("\\'"); //$NON-NLS-1$ + break; + case '\\': + tokenBuffer.append("\\\\"); //$NON-NLS-1$ + break; + default: + tokenBuffer.append(c); } } buffer.append(tokenBuffer); @@ -112,75 +115,90 @@ public class JavaStringAutoIndentStrategySQ extends DefaultIndentLineAutoEditStr } /** - * Creates a new Java string auto indent strategy for the given document partitioning. + * Creates a new Java string auto indent strategy for the given document + * partitioning. * - * @param partitioning the document partitioning + * @param partitioning + * the document partitioning */ public JavaStringAutoIndentStrategySQ(String partitioning) { super(); - fPartitioning= partitioning; + fPartitioning = partitioning; } private boolean isLineDelimiter(IDocument document, String text) { - String[] delimiters= document.getLegalLineDelimiters(); + String[] delimiters = document.getLegalLineDelimiters(); if (delimiters != null) return TextUtilities.equals(delimiters, text) > -1; return false; } - private String getLineIndentation(IDocument document, int offset) throws BadLocationException { + 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(); + 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); + 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); } - private void javaStringIndentAfterNewLine(IDocument document, DocumentCommand command) throws BadLocationException { + private void javaStringIndentAfterNewLine(IDocument document, + DocumentCommand command) throws BadLocationException { - ITypedRegion partition= TextUtilities.getPartition(document, fPartitioning, command.offset, false); - int offset= partition.getOffset(); - int length= partition.getLength(); + ITypedRegion partition = TextUtilities.getPartition(document, + fPartitioning, command.offset, false); + int offset = partition.getOffset(); + int length = partition.getLength(); if (command.offset == offset) { - // we are really just before the string partition -> feet the event through the java indenter - // new JavaAutoIndentStrategy(fPartitioning).customizeDocumentCommand(document, command); + // we are really just before the string partition -> feet the event + // through the java indenter + // new + // JavaAutoIndentStrategy(fPartitioning).customizeDocumentCommand(document, + // command); return; } - if (command.offset == offset + length && document.getChar(offset + length - 1) == '\'') + if (command.offset == offset + length + && document.getChar(offset + length - 1) == '\'') return; - String indentation= getLineIndentation(document, command.offset); - String delimiter= TextUtilities.getDefaultLineDelimiter(document); + String indentation = getLineIndentation(document, command.offset); + String delimiter = TextUtilities.getDefaultLineDelimiter(document); - IRegion line= document.getLineInformationOfOffset(offset); - String string= document.get(line.getOffset(), offset - line.getOffset()); + IRegion line = document.getLineInformationOfOffset(offset); + 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(); + 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 = "\' ." + 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); } private boolean isSmartMode() { - IWorkbenchPage page= PHPeclipsePlugin.getActivePage(); - if (page != null) { - IEditorPart part= page.getActiveEditor(); + IWorkbenchPage page = PHPeclipsePlugin.getActivePage(); + if (page != null) { + IEditorPart part = page.getActiveEditor(); if (part instanceof ITextEditorExtension3) { - ITextEditorExtension3 extension= (ITextEditorExtension3) part; + ITextEditorExtension3 extension = (ITextEditorExtension3) part; return extension.getInsertMode() == ITextEditorExtension3.SMART_INSERT; } } @@ -188,16 +206,21 @@ public class JavaStringAutoIndentStrategySQ extends DefaultIndentLineAutoEditStr } /* - * @see org.eclipse.jface.text.IAutoIndentStrategy#customizeDocumentCommand(IDocument, DocumentCommand) + * @see org.eclipse.jface.text.IAutoIndentStrategy#customizeDocumentCommand(IDocument, + * DocumentCommand) */ - public void customizeDocumentCommand(IDocument document, DocumentCommand command) { + public void customizeDocumentCommand(IDocument document, + DocumentCommand command) { try { if (command.length != 0 || command.text == null) return; - IPreferenceStore preferenceStore= PHPeclipsePlugin.getDefault().getPreferenceStore(); + IPreferenceStore preferenceStore = PHPeclipsePlugin.getDefault() + .getPreferenceStore(); - if (preferenceStore.getBoolean(PreferenceConstants.EDITOR_WRAP_STRINGS_SQ) && isSmartMode()) + if (preferenceStore + .getBoolean(PreferenceConstants.EDITOR_WRAP_STRINGS_SQ) + && isSmartMode()) javaStringIndentAfterNewLine(document, command); } catch (BadLocationException e) {