updating SQL plugin with latest Quantum code
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPUnitEditor.java
index efd93dd..ac993f6 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
@@ -15,6 +16,7 @@ import net.sourceforge.phpdt.ui.PreferenceConstants;
 import net.sourceforge.phpdt.ui.text.JavaTextTools;
 import net.sourceforge.phpeclipse.PHPCore;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
@@ -86,15 +88,9 @@ public class PHPUnitEditor extends PHPEditor {
       fAdaptedSourceViewer = asv;
     }
 
-    protected Point computeSize(
-      Composite composite,
-      int wHint,
-      int hHint,
-      boolean flushCache) {
+    protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
       Control[] children = composite.getChildren();
-      Point s =
-        children[children.length
-          - 1].computeSize(SWT.DEFAULT, SWT.DEFAULT, flushCache);
+      Point s = children[children.length - 1].computeSize(SWT.DEFAULT, SWT.DEFAULT, flushCache);
       if (fAdaptedSourceViewer.isVerticalRulerVisible())
         s.x += fAdaptedSourceViewer.getVerticalRuler().getWidth() + fGap;
       return s;
@@ -115,23 +111,11 @@ public class PHPUnitEditor extends PHPEditor {
         if (fAdaptedSourceViewer.isOverviewRulerVisible()) {
           OverviewRuler or = fAdaptedSourceViewer.getOverviewRuler();
           orWidth = or.getWidth();
-          or.getControl().setBounds(
-            clArea.width - orWidth,
-            scrollbarHeight,
-            orWidth,
-            clArea.height - 3 * scrollbarHeight);
+          or.getControl().setBounds(clArea.width - orWidth, scrollbarHeight, orWidth, clArea.height - 3 * scrollbarHeight);
         }
 
-        textWidget.setBounds(
-          vrWidth + fGap,
-          0,
-          clArea.width - vrWidth - orWidth - 2 * fGap,
-          clArea.height);
-        vr.getControl().setBounds(
-          0,
-          0,
-          vrWidth,
-          clArea.height - scrollbarHeight);
+        textWidget.setBounds(vrWidth + fGap, 0, clArea.width - vrWidth - orWidth - 2 * fGap, clArea.height);
+        vr.getControl().setBounds(0, 0, vrWidth, clArea.height - scrollbarHeight);
 
       } else {
         StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
@@ -140,8 +124,7 @@ public class PHPUnitEditor extends PHPEditor {
     }
   };
 
-  class AdaptedSourceViewer
-    extends SourceViewer { // extends JavaCorrectionSourceViewer  {
+  class AdaptedSourceViewer extends SourceViewer { // extends JavaCorrectionSourceViewer  {
 
     private List fTextConverters;
 
@@ -155,10 +138,7 @@ public class PHPUnitEditor extends PHPEditor {
     private IVerticalRuler fCachedVerticalRuler;
     private boolean fCachedIsVerticalRulerVisible;
 
-    public AdaptedSourceViewer(
-      Composite parent,
-      IVerticalRuler ruler,
-      int styles) {
+    public AdaptedSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
       super(parent, ruler, styles); //, CompilationUnitEditor.this);
 
       fCachedVerticalRuler = ruler;
@@ -231,9 +211,7 @@ public class PHPUnitEditor extends PHPEditor {
       super.customizeDocumentCommand(command);
       if (!fIgnoreTextConverters && fTextConverters != null) {
         for (Iterator e = fTextConverters.iterator(); e.hasNext();)
-          ((ITextConverter) e.next()).customizeDocumentCommand(
-            getDocument(),
-            command);
+           ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(), command);
       }
       fIgnoreTextConverters = false;
     }
@@ -270,15 +248,9 @@ public class PHPUnitEditor extends PHPEditor {
     }
 
     protected void ensureOverviewHoverManagerInstalled() {
-      if (fOverviewRulerHoveringController == null
-        && fAnnotationHover != null
-        && fHoverControlCreator != null) {
+      if (fOverviewRulerHoveringController == null && fAnnotationHover != null && fHoverControlCreator != null) {
         fOverviewRulerHoveringController =
-          new OverviewRulerHoverManager(
-            fOverviewRuler,
-            this,
-            fAnnotationHover,
-            fHoverControlCreator);
+          new OverviewRulerHoverManager(fOverviewRuler, this, fAnnotationHover, fHoverControlCreator);
         fOverviewRulerHoveringController.install(fOverviewRuler.getControl());
       }
     }
@@ -318,11 +290,7 @@ public class PHPUnitEditor extends PHPEditor {
       IAnnotationModel annotationModel,
       int visibleRegionOffset,
       int visibleRegionLength) {
-      super.setDocument(
-        document,
-        annotationModel,
-        visibleRegionOffset,
-        visibleRegionLength);
+      super.setDocument(document, annotationModel, visibleRegionOffset, visibleRegionLength);
       fOverviewRuler.setModel(annotationModel);
     }
 
@@ -395,9 +363,7 @@ public class PHPUnitEditor extends PHPEditor {
       return remainder;
     }
 
-    public void customizeDocumentCommand(
-      IDocument document,
-      DocumentCommand command) {
+    public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
       String text = command.text;
       if (text == null)
         return;
@@ -420,8 +386,7 @@ public class PHPUnitEditor extends PHPEditor {
 
             int position = 0;
             if (i == 0) {
-              IRegion firstLine =
-                document.getLineInformationOfOffset(command.offset);
+              IRegion firstLine = document.getLineInformationOfOffset(command.offset);
               position = command.offset - firstLine.getOffset();
             }
 
@@ -447,67 +412,77 @@ public class PHPUnitEditor extends PHPEditor {
   };
 
   private static class ExitPolicy implements LinkedPositionUI.ExitPolicy {
-               
+
     final char fExitCharacter;
-               
+
     public ExitPolicy(char exitCharacter) {
-      fExitCharacter= exitCharacter;
+      fExitCharacter = exitCharacter;
     }
 
     /*
      * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitPolicy#doExit(org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionManager, org.eclipse.swt.events.VerifyEvent, int, int)
      */
     public ExitFlags doExit(LinkedPositionManager manager, VerifyEvent event, int offset, int length) {
-                       
+
       if (event.character == fExitCharacter) {
         if (manager.anyPositionIncludes(offset, length))
-          return new ExitFlags(LinkedPositionUI.COMMIT| LinkedPositionUI.UPDATE_CARET, false);
+          return new ExitFlags(LinkedPositionUI.COMMIT | LinkedPositionUI.UPDATE_CARET, false);
         else
           return new ExitFlags(LinkedPositionUI.COMMIT, true);
-      }        
-                       
-      switch (event.character) {                       
-      case '\b':
-        if (manager.getFirstPosition().length == 0)
-          return new ExitFlags(0, false);
-        else
+      }
+
+      switch (event.character) {
+        case '\b' :
+          if (manager.getFirstPosition().length == 0)
+            return new ExitFlags(0, false);
+          else
+            return null;
+
+        case '\n' :
+        case '\r' :
+          return new ExitFlags(LinkedPositionUI.COMMIT, true);
+
+        default :
           return null;
-                               
-      case '\n':
-      case '\r':
-        return new ExitFlags(LinkedPositionUI.COMMIT, true);
-                               
-      default:
-        return null;
-      }                                                
+      }
     }
 
   }
   private class BracketInserter implements VerifyKeyListener, LinkedPositionUI.ExitListener {
-               
-    private boolean fCloseBrackets= true;
-    private boolean fCloseStrings= true;
-               
+
+    private boolean fCloseBracketsPHP = true;
+    private boolean fCloseStringsPHP = true;
+    private boolean fCloseBracketsHTML = true;
+    private boolean fCloseStringsHTML = true;
+
     private int fOffset;
     private int fLength;
 
-    public void setCloseBracketsEnabled(boolean enabled) {
-      fCloseBrackets= enabled;
+    public void setCloseBracketsPHPEnabled(boolean enabled) {
+      fCloseBracketsPHP = enabled;
     }
 
-    public void setCloseStringsEnabled(boolean enabled) {
-      fCloseStrings= enabled;
+    public void setCloseStringsPHPEnabled(boolean enabled) {
+      fCloseStringsPHP = 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;
-        IRegion endLine= document.getLineInformationOfOffset(end);
-        int maxEnd= endLine.getOffset() + endLine.getLength();
+        int end = offset;
+        IRegion endLine = document.getLineInformationOfOffset(end);
+        int maxEnd = endLine.getOffset() + endLine.getLength();
         while (end != maxEnd && Character.isWhitespace(document.getChar(end)))
           ++end;
 
-        return end != maxEnd && Character.isJavaIdentifierPart(document.getChar(end));
+        return end != maxEnd && Scanner.isPHPIdentifierPart(document.getChar(end));
 
       } catch (BadLocationException e) {
         // be conservative
@@ -517,110 +492,168 @@ public class PHPUnitEditor extends PHPEditor {
 
     private boolean hasIdentifierToTheLeft(IDocument document, int offset) {
       try {
-        int start= offset;
-        IRegion startLine= document.getLineInformationOfOffset(start);
-        int minStart= startLine.getOffset();
+        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 && Character.isJavaIdentifierPart(document.getChar(start - 1));
+
+        return start != minStart && Scanner.isPHPIdentifierPart(document.getChar(start - 1));
 
       } catch (BadLocationException e) {
         return true;
-      }                        
+      }
     }
 
     private boolean hasCharacterToTheRight(IDocument document, int offset, char character) {
       try {
-        int end= offset;
-        IRegion endLine= document.getLineInformationOfOffset(end);
-        int maxEnd= endLine.getOffset() + endLine.getLength();
+        int end = offset;
+        IRegion endLine = document.getLineInformationOfOffset(end);
+        int maxEnd = endLine.getOffset() + endLine.getLength();
         while (end != maxEnd && Character.isWhitespace(document.getChar(end)))
           ++end;
-                               
-        return end != maxEnd && document.getChar(end) == character;
 
+        return end != maxEnd && document.getChar(end) == character;
 
       } catch (BadLocationException e) {
         // be conservative
         return true;
-      }                        
+      }
     }
-               
+
     /*
      * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
      */
-    public void verifyKey(VerifyEvent event) {                 
+    public void verifyKey(VerifyEvent event) {
 
       if (!event.doit)
         return;
 
-      final ISourceViewer sourceViewer= getSourceViewer();
-      IDocument document= sourceViewer.getDocument();
+      final ISourceViewer sourceViewer = getSourceViewer();
+      IDocument document = sourceViewer.getDocument();
 
-      final Point selection= sourceViewer.getSelectedRange();
-      final int offset= selection.x;
-      final int length= selection.y;
+      final Point selection = sourceViewer.getSelectedRange();
+      final int offset = selection.x;
+      final int length = selection.y;
 
-      switch (event.character) {
-      case '(':
-        if (hasCharacterToTheRight(document, offset + length, '('))
-          return;
+      try {
+        ITypedRegion partition = document.getPartition(offset);
+        String type = partition.getType();
+        if (type.equals(IPHPPartitionScannerConstants.PHP)) {
+          switch (event.character) {
+            case '(' :
+              if (hasCharacterToTheRight(document, offset + length, '('))
+                return;
+
+              // fall through
+
+            case '[' :
+              if (!fCloseBracketsPHP)
+                return;
+              if (hasIdentifierToTheRight(document, offset + length))
+                return;
+
+              // fall through
+
+            case '"' :
+              if (event.character == '"') {
+                if (!fCloseStringsPHP)
+                  return;
+                // changed for statements like echo ""  print ""
+                //    if (hasIdentifierToTheLeft(document, offset) || hasIdentifierToTheRight(document, offset + length))
+                if (hasIdentifierToTheRight(document, offset + length))
+                  return;
+              }
 
-        // fall through
+              //     ITypedRegion partition= document.getPartition(offset);
+              //       if (! IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) &&  (partition.getOffset() != offset))
+              //         return;
 
-      case '[':
-          if (!fCloseBrackets)
-            return;
-          if (hasIdentifierToTheRight(document, offset + length))
-            return;
-                       
-        // fall through
-                       
-      case '"':
-        if (event.character == '"') {
-          if (!fCloseStrings)
-            return;
-          if (hasIdentifierToTheLeft(document, offset) || hasIdentifierToTheRight(document, offset + length))
-            return;
-        }
-                               
-        try {          
-          ITypedRegion partition= document.getPartition(offset);
-          if (! IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) && partition.getOffset() != offset)
-            return;
+              final char character = event.character;
+              final char closingCharacter = getPeerCharacter(character);
+              final StringBuffer buffer = new StringBuffer();
+              buffer.append(character);
+              buffer.append(closingCharacter);
+
+              document.replace(offset, length, buffer.toString());
+
+              LinkedPositionManager manager = new LinkedPositionManager(document);
+              manager.addPosition(offset + 1, 0);
 
-          final char character= event.character;
-          final char closingCharacter= getPeerCharacter(character);            
-          final StringBuffer buffer= new StringBuffer();
-          buffer.append(character);
-          buffer.append(closingCharacter);
+              fOffset = offset;
+              fLength = 2;
 
-          document.replace(offset, length, buffer.toString());
+              LinkedPositionUI editor = new LinkedPositionUI(sourceViewer, manager);
+              editor.setCancelListener(this);
+              editor.setExitPolicy(new ExitPolicy(closingCharacter));
+              editor.setFinalCaretOffset(offset + 2);
+              editor.enter();
 
-          LinkedPositionManager manager= new LinkedPositionManager(document);
-          manager.addPosition(offset + 1, 0);
+              IRegion newSelection = editor.getSelectedRegion();
+              sourceViewer.setSelectedRange(newSelection.getOffset(), newSelection.getLength());
 
-          fOffset= offset;
-          fLength= 2;
-                       
-          LinkedPositionUI editor= new LinkedPositionUI(sourceViewer, manager);
-          editor.setCancelListener(this);
-          editor.setExitPolicy(new ExitPolicy(closingCharacter));
-          editor.setFinalCaretOffset(offset + 2);
-          editor.enter();
+              event.doit = false;
+          }
+        } else if (type.equals(IPHPPartitionScannerConstants.HTML) || type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {
+          switch (event.character) {
+            case '(' :
+              if (hasCharacterToTheRight(document, offset + length, '('))
+                return;
+
+              // fall through
+
+            case '[' :
+              if (!fCloseBracketsHTML)
+                return;
+              if (hasIdentifierToTheRight(document, offset + length))
+                return;
+
+              // fall through
+
+            case '"' :
+              if (event.character == '"') {
+                if (!fCloseStringsHTML)
+                  return;
+
+                if (hasIdentifierToTheLeft(document, offset) || hasIdentifierToTheRight(document, offset + length))
+                  return;
+              }
 
-          IRegion newSelection= editor.getSelectedRegion();
-          sourceViewer.setSelectedRange(newSelection.getOffset(), newSelection.getLength());
-       
-          event.doit= false;
+              //     ITypedRegion partition= document.getPartition(offset);
+              //       if (! IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) &&  (partition.getOffset() != offset))
+              //         return;
 
-        } catch (BadLocationException e) {
+              final char character = event.character;
+              final char closingCharacter = getPeerCharacter(character);
+              final StringBuffer buffer = new StringBuffer();
+              buffer.append(character);
+              buffer.append(closingCharacter);
+
+              document.replace(offset, length, buffer.toString());
+
+              LinkedPositionManager manager = new LinkedPositionManager(document);
+              manager.addPosition(offset + 1, 0);
+
+              fOffset = offset;
+              fLength = 2;
+
+              LinkedPositionUI editor = new LinkedPositionUI(sourceViewer, manager);
+              editor.setCancelListener(this);
+              editor.setExitPolicy(new ExitPolicy(closingCharacter));
+              editor.setFinalCaretOffset(offset + 2);
+              editor.enter();
+
+              IRegion newSelection = editor.getSelectedRegion();
+              sourceViewer.setSelectedRange(newSelection.getOffset(), newSelection.getLength());
+
+              event.doit = false;
+          }
         }
-        break; 
+      } catch (BadLocationException e) {
       }
+
     }
-               
+
     /*
      * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitListener#exit(boolean)
      */
@@ -630,8 +663,8 @@ public class PHPUnitEditor extends PHPEditor {
 
       // remove brackets
       try {
-        final ISourceViewer sourceViewer= getSourceViewer();
-        IDocument document= sourceViewer.getDocument();
+        final ISourceViewer sourceViewer = getSourceViewer();
+        IDocument document = sourceViewer.getDocument();
         document.replace(fOffset, fLength, null);
       } catch (BadLocationException e) {
       }
@@ -654,17 +687,17 @@ public class PHPUnitEditor extends PHPEditor {
   private TabConverter fTabConverter;
   /** History for structure select action */
   //private SelectionHistory fSelectionHistory;
-  
+
   /** The preference property change listener for php core. */
-  private IPropertyChangeListener fPropertyChangeListener= new PropertyChangeListener();
+  private IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
   /** The remembered selection */
   private ITextSelection fRememberedSelection;
   /** The remembered php element offset */
   private int fRememberedElementOffset;
   /** The bracket inserter. */
-  private BracketInserter fBracketInserter= new BracketInserter();
-  
-  private class PropertyChangeListener implements IPropertyChangeListener {            
+  private BracketInserter fBracketInserter = new BracketInserter();
+
+  private class PropertyChangeListener implements IPropertyChangeListener {
     /*
      * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
      */
@@ -673,84 +706,59 @@ public class PHPUnitEditor extends PHPEditor {
     }
   }
   /* Preference key for code formatter tab size */
-  private final static String CODE_FORMATTER_TAB_SIZE =
-    PHPCore.FORMATTER_TAB_SIZE;
+  private final static String CODE_FORMATTER_TAB_SIZE = PHPCore.FORMATTER_TAB_SIZE;
   /** Preference key for matching brackets */
-  private final static String MATCHING_BRACKETS =
-    PreferenceConstants.EDITOR_MATCHING_BRACKETS;
+  private final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
   /** Preference key for matching brackets color */
-  private final static String MATCHING_BRACKETS_COLOR =
-    PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
+  private final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
   /** Preference key for highlighting current line */
-  private final static String CURRENT_LINE =
-    PreferenceConstants.EDITOR_CURRENT_LINE;
+  private final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
   /** Preference key for highlight color of current line */
-  private final static String CURRENT_LINE_COLOR =
-    PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
+  private final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
   /** Preference key for showing print marging ruler */
-  private final static String PRINT_MARGIN =
-    PreferenceConstants.EDITOR_PRINT_MARGIN;
+  private final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
   /** Preference key for print margin ruler color */
-  private final static String PRINT_MARGIN_COLOR =
-    PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
+  private final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
   /** Preference key for print margin ruler column */
-  private final static String PRINT_MARGIN_COLUMN =
-    PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
+  private final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
   /** Preference key for inserting spaces rather than tabs */
-  private final static String SPACES_FOR_TABS =
-    PreferenceConstants.EDITOR_SPACES_FOR_TABS;
+  private final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
   /** Preference key for error indication */
-  private final static String ERROR_INDICATION =
-    PreferenceConstants.EDITOR_PROBLEM_INDICATION;
+  private final static String ERROR_INDICATION = PreferenceConstants.EDITOR_PROBLEM_INDICATION;
   /** Preference key for error color */
-  private final static String ERROR_INDICATION_COLOR =
-    PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
+  private final static String ERROR_INDICATION_COLOR = PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
   /** Preference key for warning indication */
-  private final static String WARNING_INDICATION =
-    PreferenceConstants.EDITOR_WARNING_INDICATION;
+  private final static String WARNING_INDICATION = PreferenceConstants.EDITOR_WARNING_INDICATION;
   /** Preference key for warning color */
-  private final static String WARNING_INDICATION_COLOR =
-    PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
+  private final static String WARNING_INDICATION_COLOR = PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
   /** Preference key for task indication */
-  private final static String TASK_INDICATION =
-    PreferenceConstants.EDITOR_TASK_INDICATION;
+  private final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
   /** Preference key for task color */
-  private final static String TASK_INDICATION_COLOR =
-    PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
+  private final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
   /** Preference key for bookmark indication */
-  private final static String BOOKMARK_INDICATION =
-    PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
+  private final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
   /** Preference key for bookmark color */
-  private final static String BOOKMARK_INDICATION_COLOR =
-    PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
+  private final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
   /** Preference key for search result indication */
-  private final static String SEARCH_RESULT_INDICATION =
-    PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
+  private final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
   /** Preference key for search result color */
-  private final static String SEARCH_RESULT_INDICATION_COLOR =
-    PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
+  private final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
   /** Preference key for unknown annotation indication */
-  private final static String UNKNOWN_INDICATION =
-    PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
+  private final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
   /** Preference key for unknown annotation color */
-  private final static String UNKNOWN_INDICATION_COLOR =
-    PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
+  private final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
   /** Preference key for linked position color */
-  private final static String LINKED_POSITION_COLOR =
-    PreferenceConstants.EDITOR_LINKED_POSITION_COLOR;
+  private final static String LINKED_POSITION_COLOR = PreferenceConstants.EDITOR_LINKED_POSITION_COLOR;
   /** Preference key for shwoing the overview ruler */
-  private final static String OVERVIEW_RULER =
-    PreferenceConstants.EDITOR_OVERVIEW_RULER;
-    
+  private final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
+
   /** Preference key for error indication in overview ruler */
-  private final static String ERROR_INDICATION_IN_OVERVIEW_RULER =
-    PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
+  private final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
   /** Preference key for warning indication in overview ruler */
   private final static String WARNING_INDICATION_IN_OVERVIEW_RULER =
     PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
   /** Preference key for task indication in overview ruler */
-  private final static String TASK_INDICATION_IN_OVERVIEW_RULER =
-    PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
+  private final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
   /** Preference key for bookmark indication in overview ruler */
   private final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER =
     PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
@@ -761,19 +769,24 @@ public class PHPUnitEditor extends PHPEditor {
   private final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER =
     PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
   /** Preference key for automatically closing strings */
-  private final static String CLOSE_STRINGS= PreferenceConstants.EDITOR_CLOSE_STRINGS;
+  private final static String CLOSE_STRINGS_PHP = PreferenceConstants.EDITOR_CLOSE_STRINGS_PHP;
   /** Preference key for automatically wrapping Java strings */
-  private final static String WRAP_STRINGS= PreferenceConstants.EDITOR_WRAP_STRINGS;
+  private final static String WRAP_STRINGS = PreferenceConstants.EDITOR_WRAP_STRINGS;
   /** Preference key for automatically closing brackets and parenthesis */
-  private final static String CLOSE_BRACKETS= PreferenceConstants.EDITOR_CLOSE_BRACKETS;
+  private final static String CLOSE_BRACKETS_PHP = PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP;
   /** Preference key for automatically closing phpdocs and comments */
-  private final static String CLOSE_JAVADOCS= PreferenceConstants.EDITOR_CLOSE_JAVADOCS;
+  private final static String CLOSE_JAVADOCS = PreferenceConstants.EDITOR_CLOSE_JAVADOCS;
   /** Preference key for automatically adding phpdoc tags */
-  private final static String ADD_JAVADOC_TAGS= PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS;
+  private final static String ADD_JAVADOC_TAGS = PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS;
   /** Preference key for automatically formatting phpdocs */
-  private final static String FORMAT_JAVADOCS= PreferenceConstants.EDITOR_FORMAT_JAVADOCS;
+  private final static String FORMAT_JAVADOCS = PreferenceConstants.EDITOR_FORMAT_JAVADOCS;
+  /** Preference key for automatically closing strings */
+  private final static String CLOSE_STRINGS_HTML = PreferenceConstants.EDITOR_CLOSE_STRINGS_HTML;
+  /** Preference key for automatically closing brackets and parenthesis */
+  private final static String CLOSE_BRACKETS_HTML = PreferenceConstants.EDITOR_CLOSE_BRACKETS_HTML;
+
   /** Preference key for smart paste */
-  private final static String SMART_PASTE= PreferenceConstants.EDITOR_SMART_PASTE;
+  private final static String SMART_PASTE = PreferenceConstants.EDITOR_SMART_PASTE;
   private final static class AnnotationInfo {
     public String fColorPreference;
     public String fOverviewRulerPreference;
@@ -840,9 +853,9 @@ public class PHPUnitEditor extends PHPEditor {
     setDocumentProvider(PHPeclipsePlugin.getDefault().getCompilationUnitDocumentProvider());
     setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
     setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
-    
+
   }
-  
+
   public void createPartControl(Composite parent) {
     super.createPartControl(parent);
 
@@ -851,72 +864,72 @@ public class PHPUnitEditor extends PHPEditor {
     LinePainter linePainter;
     linePainter = new LinePainter(getSourceViewer());
 
-    linePainter.setHighlightColor(
-      new Color(Display.getCurrent(), 225, 235, 224));
+    linePainter.setHighlightColor(new Color(Display.getCurrent(), 225, 235, 224));
 
     fPaintManager.addPainter(linePainter);
 
-               
     if (isBracketHighlightingEnabled())
       startBracketHighlighting();
     if (isLineHighlightingEnabled())
       startLineHighlighting();
     if (isPrintMarginVisible())
       showPrintMargin();
-               
-               
-    Iterator e= ANNOTATION_MAP.keySet().iterator();
+
+    Iterator e = ANNOTATION_MAP.keySet().iterator();
     while (e.hasNext()) {
-      AnnotationType type= (AnnotationType) e.next();
+      AnnotationType type = (AnnotationType) e.next();
       if (isAnnotationIndicationEnabled(type))
         startAnnotationIndication(type);
     }
-                       
+
     if (isTabConversionEnabled())
       startTabConversion();
 
     if (isOverviewRulerVisible())
       showOverviewRuler();
-                       
-                       
-    Preferences preferences= PHPeclipsePlugin.getDefault().getPluginPreferences();
-    preferences.addPropertyChangeListener(fPropertyChangeListener);                    
-               
-    IPreferenceStore preferenceStore= getPreferenceStore();
-    boolean closeBrackets= preferenceStore.getBoolean(CLOSE_BRACKETS);
-    boolean closeStrings= preferenceStore.getBoolean(CLOSE_STRINGS);
-               
-    fBracketInserter.setCloseBracketsEnabled(closeBrackets);
-    fBracketInserter.setCloseStringsEnabled(closeStrings);
-               
-    ISourceViewer sourceViewer= getSourceViewer();
+
+    Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
+    preferences.addPropertyChangeListener(fPropertyChangeListener);
+
+    IPreferenceStore preferenceStore = getPreferenceStore();
+    boolean closeBracketsPHP = preferenceStore.getBoolean(CLOSE_BRACKETS_PHP);
+    boolean closeStringsPHP = preferenceStore.getBoolean(CLOSE_STRINGS_PHP);
+    boolean closeBracketsHTML = preferenceStore.getBoolean(CLOSE_BRACKETS_HTML);
+    boolean closeStringsHTML = preferenceStore.getBoolean(CLOSE_STRINGS_HTML);
+
+    fBracketInserter.setCloseBracketsPHPEnabled(closeBracketsPHP);
+    fBracketInserter.setCloseStringsPHPEnabled(closeStringsPHP);
+    fBracketInserter.setCloseBracketsHTMLEnabled(closeBracketsHTML);
+    fBracketInserter.setCloseStringsHTMLEnabled(closeStringsHTML);
+
+    ISourceViewer sourceViewer = getSourceViewer();
     if (sourceViewer instanceof ITextViewerExtension)
-      ((ITextViewerExtension) sourceViewer).prependVerifyKeyListener(fBracketInserter);
+       ((ITextViewerExtension) sourceViewer).prependVerifyKeyListener(fBracketInserter);
 
   }
 
   private static char getPeerCharacter(char character) {
     switch (character) {
-      case '(':
+      case '(' :
         return ')';
-                               
-      case ')':
+
+      case ')' :
         return '(';
-                               
-      case '[':
+
+      case '[' :
         return ']';
 
-      case ']':
+      case ']' :
         return '[';
-                               
-      case '"':
+
+      case '"' :
         return character;
-                       
-      default:
+
+      default :
         throw new IllegalArgumentException();
-    }                                  
+    }
   }
-       
+
   /*
    * @see AbstractTextEditor#doSetInput(IEditorInput)
    */
@@ -975,8 +988,7 @@ public class PHPUnitEditor extends PHPEditor {
     if (fPrintMarginPainter == null) {
       fPrintMarginPainter = new PrintMarginPainter(getSourceViewer());
       fPrintMarginPainter.setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
-      fPrintMarginPainter.setMarginRulerColumn(
-        getPreferenceStore().getInt(PRINT_MARGIN_COLUMN));
+      fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt(PRINT_MARGIN_COLUMN));
       fPaintManager.addPainter(fPrintMarginPainter);
     }
   }
@@ -1042,9 +1054,7 @@ public class PHPUnitEditor extends PHPEditor {
     return false;
   }
 
-  private void showAnnotationIndicationInOverviewRuler(
-    AnnotationType annotationType,
-    boolean show) {
+  private void showAnnotationIndicationInOverviewRuler(AnnotationType annotationType, boolean show) {
     AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
     OverviewRuler ruler = asv.getOverviewRuler();
     if (ruler != null) {
@@ -1054,9 +1064,7 @@ public class PHPUnitEditor extends PHPEditor {
     }
   }
 
-  private void setColorInOverviewRuler(
-    AnnotationType annotationType,
-    Color color) {
+  private void setColorInOverviewRuler(AnnotationType annotationType, Color color) {
     AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
     OverviewRuler ruler = asv.getOverviewRuler();
     if (ruler != null) {
@@ -1076,8 +1084,7 @@ public class PHPUnitEditor extends PHPEditor {
   }
 
   private int getTabSize() {
-    Preferences preferences =
-      PHPeclipsePlugin.getDefault().getPluginPreferences();
+    Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
     return preferences.getInt(CODE_FORMATTER_TAB_SIZE);
   }
 
@@ -1151,25 +1158,24 @@ public class PHPUnitEditor extends PHPEditor {
   }
 
   public void dispose() {
-    ISourceViewer sourceViewer= getSourceViewer();
+    ISourceViewer sourceViewer = getSourceViewer();
     if (sourceViewer instanceof ITextViewerExtension)
-      ((ITextViewerExtension) sourceViewer).removeVerifyKeyListener(fBracketInserter);
-      
+       ((ITextViewerExtension) sourceViewer).removeVerifyKeyListener(fBracketInserter);
+
     if (fPropertyChangeListener != null) {
-      Preferences preferences= PHPeclipsePlugin.getDefault().getPluginPreferences();
+      Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
       preferences.removePropertyChangeListener(fPropertyChangeListener);
-      fPropertyChangeListener= null;
-    }
-    
-               
-//    if (fJavaEditorErrorTickUpdater != null) {
-//      fJavaEditorErrorTickUpdater.dispose();
-//      fJavaEditorErrorTickUpdater= null;
-//    }
-//             
-//    if (fSelectionHistory != null)
-//      fSelectionHistory.dispose();
-      
+      fPropertyChangeListener = null;
+    }
+
+    //    if (fJavaEditorErrorTickUpdater != null) {
+    //      fJavaEditorErrorTickUpdater.dispose();
+    //      fJavaEditorErrorTickUpdater= null;
+    //    }
+    //         
+    //    if (fSelectionHistory != null)
+    //      fSelectionHistory.dispose();
+
     if (fPaintManager != null) {
       fPaintManager.dispose();
       fPaintManager = null;
@@ -1177,45 +1183,57 @@ public class PHPUnitEditor extends PHPEditor {
 
     if (fActionGroups != null)
       fActionGroups.dispose();
-      
+
     super.dispose();
   }
-  
+
   protected AnnotationType getAnnotationType(String preferenceKey) {
-    Iterator e= ANNOTATION_MAP.keySet().iterator();
+    Iterator e = ANNOTATION_MAP.keySet().iterator();
     while (e.hasNext()) {
-      AnnotationType type= (AnnotationType) e.next();
-      AnnotationInfo info= (AnnotationInfo) ANNOTATION_MAP.get(type);
+      AnnotationType type = (AnnotationType) e.next();
+      AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(type);
       if (info != null) {
-        if (preferenceKey.equals(info.fColorPreference) || preferenceKey.equals(info.fEditorPreference) || preferenceKey.equals(info.fOverviewRulerPreference)) 
+        if (preferenceKey.equals(info.fColorPreference)
+          || preferenceKey.equals(info.fEditorPreference)
+          || preferenceKey.equals(info.fOverviewRulerPreference))
           return type;
       }
     }
     return null;
   }
-  
+
   /*
    * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
    */
   protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
-               
+
     try {
-                       
-      AdaptedSourceViewer asv= (AdaptedSourceViewer) getSourceViewer();
+
+      AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
       if (asv != null) {
-                                       
-        String p= event.getProperty();         
-                               
-        if (CLOSE_BRACKETS.equals(p)) {
-          fBracketInserter.setCloseBracketsEnabled(getPreferenceStore().getBoolean(p));
-          return;      
+
+        String p = event.getProperty();
+
+        if (CLOSE_BRACKETS_PHP.equals(p)) {
+          fBracketInserter.setCloseBracketsPHPEnabled(getPreferenceStore().getBoolean(p));
+          return;
         }
 
-        if (CLOSE_STRINGS.equals(p)) {
-          fBracketInserter.setCloseStringsEnabled(getPreferenceStore().getBoolean(p));
+        if (CLOSE_STRINGS_PHP.equals(p)) {
+          fBracketInserter.setCloseStringsPHPEnabled(getPreferenceStore().getBoolean(p));
           return;
         }
-                                                               
+
+        if (CLOSE_BRACKETS_HTML.equals(p)) {
+          fBracketInserter.setCloseBracketsHTMLEnabled(getPreferenceStore().getBoolean(p));
+          return;
+        }
+
+        if (CLOSE_STRINGS_HTML.equals(p)) {
+          fBracketInserter.setCloseStringsHTMLEnabled(getPreferenceStore().getBoolean(p));
+          return;
+        }
+
         if (SPACES_FOR_TABS.equals(p)) {
           if (isTabConversionEnabled())
             startTabConversion();
@@ -1223,7 +1241,7 @@ public class PHPUnitEditor extends PHPEditor {
             stopTabConversion();
           return;
         }
-                               
+
         if (MATCHING_BRACKETS.equals(p)) {
           if (isBracketHighlightingEnabled())
             startBracketHighlighting();
@@ -1231,13 +1249,13 @@ public class PHPUnitEditor extends PHPEditor {
             stopBracketHighlighting();
           return;
         }
-                               
+
         if (MATCHING_BRACKETS_COLOR.equals(p)) {
           if (fBracketPainter != null)
             fBracketPainter.setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
           return;
         }
-                               
+
         if (CURRENT_LINE.equals(p)) {
           if (isLineHighlightingEnabled())
             startLineHighlighting();
@@ -1245,15 +1263,15 @@ public class PHPUnitEditor extends PHPEditor {
             stopLineHighlighting();
           return;
         }
-                               
+
         if (CURRENT_LINE_COLOR.equals(p)) {
           if (fLinePainter != null) {
             stopLineHighlighting();
             startLineHighlighting();
-          }                                    
+          }
           return;
         }
-                               
+
         if (PRINT_MARGIN.equals(p)) {
           if (isPrintMarginVisible())
             showPrintMargin();
@@ -1261,33 +1279,33 @@ public class PHPUnitEditor extends PHPEditor {
             hidePrintMargin();
           return;
         }
-                               
+
         if (PRINT_MARGIN_COLOR.equals(p)) {
           if (fPrintMarginPainter != null)
             fPrintMarginPainter.setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
           return;
         }
-                               
+
         if (PRINT_MARGIN_COLUMN.equals(p)) {
           if (fPrintMarginPainter != null)
             fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt(PRINT_MARGIN_COLUMN));
           return;
         }
-                               
-        if (OVERVIEW_RULER.equals(p))  {
+
+        if (OVERVIEW_RULER.equals(p)) {
           if (isOverviewRulerVisible())
             showOverviewRuler();
           else
             hideOverviewRuler();
           return;
         }
-                               
-        AnnotationType type= getAnnotationType(p);
+
+        AnnotationType type = getAnnotationType(p);
         if (type != null) {
-                                       
-          AnnotationInfo info= (AnnotationInfo) ANNOTATION_MAP.get(type);
+
+          AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(type);
           if (info.fColorPreference.equals(p)) {
-            Color color= getColor(type);
+            Color color = getColor(type);
             if (fProblemPainter != null) {
               fProblemPainter.setColor(type, color);
               fProblemPainter.paint(IPainter.CONFIGURATION);
@@ -1295,7 +1313,7 @@ public class PHPUnitEditor extends PHPEditor {
             setColorInOverviewRuler(type, color);
             return;
           }
-                                       
+
           if (info.fEditorPreference.equals(p)) {
             if (isAnnotationIndicationEnabled(type))
               startAnnotationIndication(type);
@@ -1303,7 +1321,7 @@ public class PHPUnitEditor extends PHPEditor {
               stopAnnotationIndication(type);
             return;
           }
-                                       
+
           if (info.fOverviewRulerPreference.equals(p)) {
             if (isAnnotationIndicationInOverviewRulerEnabled(type))
               showAnnotationIndicationInOverviewRuler(type, true);
@@ -1313,11 +1331,11 @@ public class PHPUnitEditor extends PHPEditor {
           }
         }
 
-        IContentAssistant c= asv.getContentAssistant();
+        IContentAssistant c = asv.getContentAssistant();
         if (c instanceof ContentAssistant)
           ContentAssistPreference.changeConfiguration((ContentAssistant) c, getPreferenceStore(), event);
       }
-                               
+
     } finally {
       super.handlePreferenceStoreChanged(event);
     }
@@ -1331,9 +1349,9 @@ public class PHPUnitEditor extends PHPEditor {
    * @param event the property change event
    */
   protected void handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
-    AdaptedSourceViewer asv= (AdaptedSourceViewer) getSourceViewer();
+    AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
     if (asv != null) {
-      String p= event.getProperty();                                   
+      String p = event.getProperty();
       if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
         asv.updateIndentationPrefixes();
         if (fTabConverter != null)
@@ -1341,49 +1359,49 @@ public class PHPUnitEditor extends PHPEditor {
       }
     }
   }
-  
+
   /*
    * @see PHPEditor#createJavaSourceViewer(Composite, IVerticalRuler, int)
    */
   protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
     return new AdaptedSourceViewer(parent, ruler, styles);
   }
+
   private boolean isValidSelection(int offset, int length) {
-    IDocumentProvider provider= getDocumentProvider();
+    IDocumentProvider provider = getDocumentProvider();
     if (provider != null) {
-      IDocument document= provider.getDocument(getEditorInput());
+      IDocument document = provider.getDocument(getEditorInput());
       if (document != null) {
-        int end= offset + length;
-        int documentLength= document.getLength();
-        return 0 <= offset  && offset <= documentLength && 0 <= end && end <= documentLength;
+        int end = offset + length;
+        int documentLength = document.getLength();
+        return 0 <= offset && offset <= documentLength && 0 <= end && end <= documentLength;
       }
     }
     return false;
   }
-       
+
   /*
    * @see AbstractTextEditor#canHandleMove(IEditorInput, IEditorInput)
    */
   protected boolean canHandleMove(IEditorInput originalElement, IEditorInput movedElement) {
-               
-    String oldExtension= ""; //$NON-NLS-1$
+
+    String oldExtension = ""; //$NON-NLS-1$
     if (originalElement instanceof IFileEditorInput) {
-      IFile file= ((IFileEditorInput) originalElement).getFile();
+      IFile file = ((IFileEditorInput) originalElement).getFile();
       if (file != null) {
-        String ext= file.getFileExtension();
+        String ext = file.getFileExtension();
         if (ext != null)
-          oldExtension= ext;
+          oldExtension = ext;
       }
     }
-               
-    String newExtension= ""; //$NON-NLS-1$
+
+    String newExtension = ""; //$NON-NLS-1$
     if (movedElement instanceof IFileEditorInput) {
-      IFile file= ((IFileEditorInput) movedElement).getFile();
+      IFile file = ((IFileEditorInput) movedElement).getFile();
       if (file != null)
-        newExtension= file.getFileExtension();
+        newExtension = file.getFileExtension();
     }
-               
+
     return oldExtension.equals(newExtension);
-  } 
+  }
 }