KT-1255 Quote handler added.

This commit is contained in:
Alexander.Podkhalyuzin
2012-04-03 18:42:31 +04:00
parent f022b61794
commit 46ede3ca6b
2 changed files with 71 additions and 0 deletions
+1
View File
@@ -76,6 +76,7 @@
<lang.formatter language="jet" implementationClass="org.jetbrains.jet.plugin.formatter.JetFormattingModelBuilder"/>
<lang.findUsagesProvider language="jet" implementationClass="org.jetbrains.jet.plugin.findUsages.JetFindUsagesProvider"/>
<lang.refactoringSupport language="jet" implementationClass="org.jetbrains.jet.plugin.refactoring.JetRefactoringSupportProvider"/>
<quoteHandler fileType="Kotlin" className="org.jetbrains.jet.plugin.editor.KotlinQuoteHandler"/>
<refactoring.moveHandler implementation="org.jetbrains.jet.plugin.refactoring.move.JetMoveFilesOrDirectoriesHandler"/>
<refactoring.copyHandler implementation="org.jetbrains.jet.plugin.refactoring.copy.JetCopyClassHandler"/>
<treeStructureProvider implementation="org.jetbrains.jet.plugin.projectView.JetProjectViewProvider"/>
@@ -0,0 +1,70 @@
/*
* Copyright 2010-2012 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.jet.plugin.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.jet.lexer.JetTokens;
/**
* @author Alefas
* @since 03.04.12
*/
public class KotlinQuoteHandler implements QuoteHandler {
@Override
public boolean isClosingQuote(HighlighterIterator iterator, int offset) {
IElementType tokenType = iterator.getTokenType();
if (tokenType == JetTokens.CHARACTER_LITERAL) {
int start = iterator.getStart();
int end = iterator.getEnd();
return end - start >= 1 && offset == end - 1;
} else if (tokenType == JetTokens.CLOSING_QUOTE) {
return true;
}
return false;
}
@Override
public boolean isOpeningQuote(HighlighterIterator iterator, int offset) {
final IElementType tokenType = iterator.getTokenType();
if (tokenType == JetTokens.OPEN_QUOTE) {
int start = iterator.getStart();
return offset == start;
}
return false;
}
@Override
public boolean hasNonClosedLiteral(Editor editor, HighlighterIterator iterator, int offset) {
return true;
}
@Override
public boolean isInsideLiteral(HighlighterIterator iterator) {
final IElementType tokenType = iterator.getTokenType();
return tokenType == JetTokens.REGULAR_STRING_PART ||
tokenType == JetTokens.OPEN_QUOTE ||
tokenType == JetTokens.CLOSING_QUOTE ||
tokenType == JetTokens.SHORT_TEMPLATE_ENTRY_START ||
tokenType == JetTokens.LONG_TEMPLATE_ENTRY_END ||
tokenType == JetTokens.LONG_TEMPLATE_ENTRY_START;
}
}