/*
 * Copyright 2000-2007 JetBrains s.r.o.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jetbrains.plugins.scala.lang.editor;

import com.intellij.codeInsight.editorActions.QuoteHandler;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes;

/**
 * @author ilyas
 */
public class ScalaQuoteHandler implements QuoteHandler {
             
  public boolean isClosingQuote(HighlighterIterator iterator, int offset) {
    final IElementType tokenType = iterator.getTokenType();

    if (tokenType == ScalaTokenTypes.tSTRING ||
            tokenType == ScalaTokenTypes.tCHAR) {
      int start = iterator.getStart();
      int end = iterator.getEnd();
      return end - start >= 1 && offset == end - 1;
    }
    return false;
  }

  public boolean isOpeningQuote(HighlighterIterator iterator, int offset) {
    final IElementType tokenType = iterator.getTokenType();

    if (tokenType == ScalaTokenTypes.tWRONG_STRING) {
      int start = iterator.getStart();
      return offset == start;
    }
    return false;
  }

  public boolean hasNonClosedLiteral(Editor editor, HighlighterIterator iterator, int offset) {
    return true;
  }

  public boolean isInsideLiteral(HighlighterIterator iterator) {
    final IElementType tokenType = iterator.getTokenType();
    return tokenType == ScalaTokenTypes.tSTRING ||
            tokenType == ScalaTokenTypes.tCHAR;
  }
}
@@ -702,16 +702,84 @@
 andler;%0A
+import com.intellij.codeInsight.editorActions.JavaLikeQuoteHandler;%0A
 import c
@@ -935,62 +935,319 @@
 ort 
-org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes
+com.intellij.psi.tree.TokenSet;%0Aimport com.intellij.psi.PsiElement;%0Aimport org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes;%0Aimport org.jetbrains.plugins.scala.lang.psi.api.base.ScLiteral;%0Aimport org.jetbrains.plugins.scala.lang.psi.api.expr.ScReferenceExpression;%0Aimport org.jetbrains.annotations.NotNull
 ;%0A%0A/
@@ -1312,16 +1312,24 @@
 lements 
+JavaLike
 QuoteHan
@@ -1339,21 +1339,8 @@
 r %7B%0A
-             
 %0A  p
@@ -1521,36 +1521,32 @@
 RING %7C%7C%0A        
-    
 tokenType == Sca
@@ -2309,28 +2309,24 @@
  %7C%7C%0A        
-    
 tokenType ==
@@ -2352,10 +2352,1086 @@
 HAR;%0A  %7D
+%0A%0A  public TokenSet getConcatenatableStringTokenTypes() %7B%0A    return TokenSet.create(ScalaTokenTypes.tSTRING);%0A  %7D%0A%0A  public String getStringConcatenationOperatorRepresentation() %7B%0A    return %22+%22;%0A  %7D%0A%0A  public TokenSet getStringTokenTypes() %7B%0A    return TokenSet.create(ScalaTokenTypes.tSTRING);%0A  %7D%0A%0A  public boolean isAppropriateElementTypeForLiteral(@NotNull IElementType tokenType) %7B%0A    return tokenType == ScalaTokenTypes.tSEMICOLON%0A        %7C%7C tokenType == ScalaTokenTypes.tCOMMA%0A        %7C%7C tokenType == ScalaTokenTypes.tRPARENTHESIS%0A        %7C%7C tokenType == ScalaTokenTypes.tRSQBRACKET%0A        %7C%7C tokenType == ScalaTokenTypes.tRBRACE%0A        %7C%7C tokenType == ScalaTokenTypes.tSTRING%0A        %7C%7C tokenType == ScalaTokenTypes.tCHAR%0A        %7C%7C ScalaTokenTypes.COMMENTS_TOKEN_SET.contains(tokenType)%0A        %7C%7C ScalaTokenTypes.WHITES_SPACES_TOKEN_SET.contains(tokenType);%0A  %7D%0A%0A  public boolean needParenthesesAroundConcatenation(PsiElement element) %7B%0A    return element.getParent() instanceof ScLiteral && element.getParent().getParent() instanceof ScReferenceExpression;%0A  %7D
 %0A%7D

inside string enter action