diff --git a/idea/src/org/jetbrains/jet/plugin/completion/JetKeywordCompletionContributor.kt b/idea/src/org/jetbrains/jet/plugin/completion/JetKeywordCompletionContributor.kt index 8a59a6b22df..10bae369bc1 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/JetKeywordCompletionContributor.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/JetKeywordCompletionContributor.kt @@ -138,7 +138,7 @@ public class JetKeywordCompletionContributor : CompletionContributor() { } 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 NOT_IDENTIFIER_FILTER = NotFilter(AndFilter( diff --git a/idea/src/org/jetbrains/jet/plugin/completion/JetTypesCompletionHelper.kt b/idea/src/org/jetbrains/jet/plugin/completion/JetTypesCompletionHelper.kt index 9426a69a518..fab25f11f0a 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/JetTypesCompletionHelper.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/JetTypesCompletionHelper.kt @@ -62,7 +62,7 @@ object JetTypesCompletionHelper { jetCompletionResult.addElement(object : LookupElementDecorator(lookupElement) { override fun handleInsert(context: InsertionContext) { - JetJavaClassInsertHandler.INSTANCE.handleInsert(context, lookupElement) + JetJavaClassInsertHandler.handleInsert(context, lookupElement) } }) } diff --git a/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetJavaClassInsertHandler.java b/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetJavaClassInsertHandler.java deleted file mode 100644 index 42b8d471148..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetJavaClassInsertHandler.java +++ /dev/null @@ -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 { - public static final InsertHandler 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 - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetJavaClassInsertHandler.kt b/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetJavaClassInsertHandler.kt new file mode 100644 index 00000000000..75ac98b67f9 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetJavaClassInsertHandler.kt @@ -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 { + 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 + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetKeywordInsertHandler.java b/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetKeywordInsertHandler.java deleted file mode 100644 index e3586aef34f..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetKeywordInsertHandler.java +++ /dev/null @@ -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 { - - private final static Set 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()); - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetKeywordInsertHandler.kt b/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetKeywordInsertHandler.kt new file mode 100644 index 00000000000..c87d902694d --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetKeywordInsertHandler.kt @@ -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 { + 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()) + 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()) + } +}