Converted more completion code to Kotlin
This commit is contained in:
@@ -138,7 +138,7 @@ public class JetKeywordCompletionContributor : CompletionContributor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class object {
|
class object {
|
||||||
private val KEYWORDS_INSERT_HANDLER = JetKeywordInsertHandler()
|
private val KEYWORDS_INSERT_HANDLER = JetKeywordInsertHandler
|
||||||
private val FUNCTION_KEYWORDS = listOf(JetTokens.GET_KEYWORD.toString(), JetTokens.SET_KEYWORD.toString())
|
private val FUNCTION_KEYWORDS = listOf(JetTokens.GET_KEYWORD.toString(), JetTokens.SET_KEYWORD.toString())
|
||||||
|
|
||||||
private val NOT_IDENTIFIER_FILTER = NotFilter(AndFilter(
|
private val NOT_IDENTIFIER_FILTER = NotFilter(AndFilter(
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ object JetTypesCompletionHelper {
|
|||||||
|
|
||||||
jetCompletionResult.addElement(object : LookupElementDecorator<LookupElement>(lookupElement) {
|
jetCompletionResult.addElement(object : LookupElementDecorator<LookupElement>(lookupElement) {
|
||||||
override fun handleInsert(context: InsertionContext) {
|
override fun handleInsert(context: InsertionContext) {
|
||||||
JetJavaClassInsertHandler.INSTANCE.handleInsert(context, lookupElement)
|
JetJavaClassInsertHandler.handleInsert(context, lookupElement)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2013 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.completion.handlers;
|
|
||||||
|
|
||||||
import com.intellij.codeInsight.completion.InsertHandler;
|
|
||||||
import com.intellij.codeInsight.completion.InsertionContext;
|
|
||||||
import com.intellij.codeInsight.completion.JavaPsiClassReferenceElement;
|
|
||||||
import com.intellij.psi.PsiDocumentManager;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
|
||||||
import org.jetbrains.jet.plugin.quickfix.ImportInsertHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for inserting java class completion.
|
|
||||||
* - Should place import directive if necessary.
|
|
||||||
*/
|
|
||||||
public class JetJavaClassInsertHandler implements InsertHandler<JavaPsiClassReferenceElement> {
|
|
||||||
public static final InsertHandler<JavaPsiClassReferenceElement> INSTANCE = new JetJavaClassInsertHandler();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleInsert(InsertionContext context, JavaPsiClassReferenceElement item) {
|
|
||||||
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
|
|
||||||
|
|
||||||
if (context.getFile() instanceof JetFile) {
|
|
||||||
ImportInsertHelper.addImportDirectiveOrChangeToFqName(new FqName(item.getQualifiedName()),
|
|
||||||
(JetFile) context.getFile(),
|
|
||||||
context.getStartOffset(),
|
|
||||||
item.getObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
// check annotation
|
|
||||||
// check auto insert parentheses
|
|
||||||
// check auto insert type parameters
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.completion.handlers
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.completion.InsertHandler
|
||||||
|
import com.intellij.codeInsight.completion.InsertionContext
|
||||||
|
import com.intellij.codeInsight.completion.JavaPsiClassReferenceElement
|
||||||
|
import com.intellij.psi.PsiDocumentManager
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||||
|
import org.jetbrains.jet.plugin.quickfix.ImportInsertHelper
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for inserting java class completion.
|
||||||
|
* - Should place import directive if necessary.
|
||||||
|
*/
|
||||||
|
public object JetJavaClassInsertHandler : InsertHandler<JavaPsiClassReferenceElement> {
|
||||||
|
override fun handleInsert(context: InsertionContext, item: JavaPsiClassReferenceElement) {
|
||||||
|
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments()
|
||||||
|
|
||||||
|
val file = context.getFile()
|
||||||
|
if (file is JetFile) {
|
||||||
|
ImportInsertHelper.addImportDirectiveOrChangeToFqName(FqName(item.getQualifiedName()!!), file, context.getStartOffset(), item.getObject())
|
||||||
|
}
|
||||||
|
|
||||||
|
// check annotation
|
||||||
|
// check auto insert parentheses
|
||||||
|
// check auto insert type parameters
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2013 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.completion.handlers;
|
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.intellij.codeInsight.TailType;
|
|
||||||
import com.intellij.codeInsight.completion.InsertHandler;
|
|
||||||
import com.intellij.codeInsight.completion.InsertionContext;
|
|
||||||
import com.intellij.codeInsight.lookup.LookupElement;
|
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFunction;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class JetKeywordInsertHandler implements InsertHandler<LookupElement> {
|
|
||||||
|
|
||||||
private final static Set<String> NO_SPACE_AFTER = Sets.newHashSet(
|
|
||||||
JetTokens.THIS_KEYWORD.toString(),
|
|
||||||
JetTokens.SUPER_KEYWORD.toString(),
|
|
||||||
JetTokens.CAPITALIZED_THIS_KEYWORD.toString(),
|
|
||||||
JetTokens.THIS_KEYWORD.toString(),
|
|
||||||
JetTokens.FALSE_KEYWORD.toString(),
|
|
||||||
JetTokens.NULL_KEYWORD.toString(),
|
|
||||||
JetTokens.BREAK_KEYWORD.toString(),
|
|
||||||
JetTokens.CONTINUE_KEYWORD.toString());
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleInsert(InsertionContext context, LookupElement item) {
|
|
||||||
String keyword = item.getLookupString();
|
|
||||||
|
|
||||||
if (NO_SPACE_AFTER.contains(keyword)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyword.equals(JetTokens.RETURN_KEYWORD.toString())) {
|
|
||||||
PsiElement element = context.getFile().findElementAt(context.getStartOffset());
|
|
||||||
if (element != null) {
|
|
||||||
JetFunction jetFunction = PsiTreeUtil.getParentOfType(element, JetFunction.class);
|
|
||||||
if (jetFunction != null) {
|
|
||||||
if (!jetFunction.hasDeclaredReturnType() || JetPsiUtil.isVoidType(jetFunction.getReturnTypeRef())) {
|
|
||||||
// No space for void function
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add space after keyword
|
|
||||||
context.setAddCompletionChar(false);
|
|
||||||
TailType tailType = TailType.SPACE;
|
|
||||||
tailType.processTail(context.getEditor(), context.getTailOffset());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.completion.handlers
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets
|
||||||
|
import com.intellij.codeInsight.TailType
|
||||||
|
import com.intellij.codeInsight.completion.InsertHandler
|
||||||
|
import com.intellij.codeInsight.completion.InsertionContext
|
||||||
|
import com.intellij.codeInsight.lookup.LookupElement
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFunction
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
|
|
||||||
|
public object JetKeywordInsertHandler : InsertHandler<LookupElement> {
|
||||||
|
private val NO_SPACE_AFTER = setOf(JetTokens.THIS_KEYWORD.toString(),
|
||||||
|
JetTokens.SUPER_KEYWORD.toString(),
|
||||||
|
JetTokens.CAPITALIZED_THIS_KEYWORD.toString(),
|
||||||
|
JetTokens.THIS_KEYWORD.toString(),
|
||||||
|
JetTokens.FALSE_KEYWORD.toString(),
|
||||||
|
JetTokens.NULL_KEYWORD.toString(),
|
||||||
|
JetTokens.BREAK_KEYWORD.toString(),
|
||||||
|
JetTokens.CONTINUE_KEYWORD.toString())
|
||||||
|
|
||||||
|
override fun handleInsert(context: InsertionContext, item: LookupElement) {
|
||||||
|
val keyword = item.getLookupString()
|
||||||
|
|
||||||
|
if (keyword in NO_SPACE_AFTER) return
|
||||||
|
|
||||||
|
if (keyword == JetTokens.RETURN_KEYWORD.toString()) {
|
||||||
|
val element = context.getFile().findElementAt(context.getStartOffset())
|
||||||
|
if (element != null) {
|
||||||
|
val jetFunction = PsiTreeUtil.getParentOfType(element, javaClass<JetFunction>())
|
||||||
|
if (jetFunction != null && (!jetFunction.hasDeclaredReturnType() || JetPsiUtil.isVoidType(jetFunction.getReturnTypeRef()))) {
|
||||||
|
// No space for void function
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add space after keyword
|
||||||
|
context.setAddCompletionChar(false)
|
||||||
|
TailType.SPACE.processTail(context.getEditor(), context.getTailOffset())
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user