X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java index 153bf6d..8a88ecf 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java @@ -17,12 +17,15 @@ import net.sourceforge.phpdt.core.JavaCore; import net.sourceforge.phpdt.core.JavaModelException; import net.sourceforge.phpdt.core.dom.CompilationUnit; import net.sourceforge.phpdt.internal.compiler.parser.Scanner; +import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility; import net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction; import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup; import net.sourceforge.phpdt.internal.ui.actions.IndentAction; import net.sourceforge.phpdt.internal.ui.actions.RemoveBlockCommentAction; import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference; import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions; +import net.sourceforge.phpdt.internal.ui.text.JavaHeuristicScanner; +import net.sourceforge.phpdt.internal.ui.text.JavaIndenter; import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher; import net.sourceforge.phpdt.internal.ui.text.SmartBackspaceManager; import net.sourceforge.phpdt.internal.ui.text.SmartSemicolonAutoEditStrategy; @@ -914,10 +917,6 @@ public class PHPUnitEditor extends PHPEditor { //implements private boolean fCloseStringsPHPSQ = true; - private boolean fCloseBracketsHTML = true; - - private boolean fCloseStringsHTML = true; - private int fOffset; private int fLength; @@ -934,14 +933,6 @@ public class PHPUnitEditor extends PHPEditor { //implements fCloseStringsPHPSQ = enabled; } - public void setCloseBracketsHTMLEnabled(boolean enabled) { - fCloseBracketsHTML = enabled; - } - - public void setCloseStringsHTMLEnabled(boolean enabled) { - fCloseStringsHTML = enabled; - } - private boolean hasIdentifierToTheRight(IDocument document, int offset) { try { int end = offset; @@ -969,6 +960,19 @@ public class PHPUnitEditor extends PHPEditor { //implements } } + private boolean hasCharacterToTheLeft(IDocument document, int offset, char character) { + try { + int start = offset; + IRegion startLine = document.getLineInformationOfOffset(start); + int minStart = startLine.getOffset(); + while (start != minStart && Character.isWhitespace(document.getChar(start - 1))) + --start; + return start != minStart && document.getChar(start - 1)== character; + } catch (BadLocationException e) { + return false; + } + } + private boolean hasCharacterToTheRight(IDocument document, int offset, char character) { try { int end = offset; @@ -1010,6 +1014,12 @@ public class PHPUnitEditor extends PHPEditor { //implements if (hasIdentifierToTheRight(document, offset + length)) return; // fall through + case '{': + if (!fCloseBracketsPHP) + return; + if (hasIdentifierToTheRight(document, offset + length)) + return; + // fall through case '"': if (event.character == '"') { if (!fCloseStringsPHPDQ) @@ -1048,7 +1058,6 @@ public class PHPUnitEditor extends PHPEditor { //implements sourceViewer.setSelectedRange(newSelectionDQ.getOffset(), newSelectionDQ.getLength()); event.doit = false; break; - // fall through case '\'': if (event.character == '\'') { if (!fCloseStringsPHPSQ) @@ -1086,57 +1095,38 @@ public class PHPUnitEditor extends PHPEditor { //implements IRegion newSelectionSQ = editorSQ.getSelectedRegion(); sourceViewer.setSelectedRange(newSelectionSQ.getOffset(), newSelectionSQ.getLength()); event.doit = false; + case '\r': { // insert linebreaks and new closing brace after brace and return + if (!fCloseBracketsPHP) { + return; + } + if (hasCharacterToTheLeft(document,offset,'{') && hasCharacterToTheRight(document,offset,'}')) { + String lineDelimiter=StubUtility.getLineDelimiterFor(document); + int caretPos=sourceViewer.getTextWidget().getCaretOffset(); + final StringBuffer buffer = new StringBuffer(lineDelimiter); + // get indentation + IRegion line = document.getLineInformationOfOffset(offset); + String currentLine=document.get(line.getOffset(),line.getLength()); + int index=0; + int max=currentLine.length(); + StringBuffer indent=new StringBuffer(); + while (index