mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
Fix JavaAutoPopup test
This commit is contained in:
@@ -1,9 +1,26 @@
|
||||
/*
|
||||
* Copyright 2000-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 com.intellij.codeInsight.template.postfix.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionContributor;
|
||||
import com.intellij.codeInsight.completion.CompletionType;
|
||||
import com.intellij.codeInsight.template.CustomLiveTemplate;
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
|
||||
import com.intellij.codeInsight.template.postfix.templates.PostfixLiveTemplate;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -26,9 +43,9 @@ public class PostfixTemplateCompletionContributor extends CompletionContributor
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PostfixLiveTemplate getPostfixLiveTemplate(@NotNull PsiFile file, int offset) {
|
||||
public static PostfixLiveTemplate getPostfixLiveTemplate(@NotNull PsiFile file, @NotNull Editor editor) {
|
||||
PostfixLiveTemplate postfixLiveTemplate = CustomLiveTemplate.EP_NAME.findExtension(PostfixLiveTemplate.class);
|
||||
return postfixLiveTemplate != null && postfixLiveTemplate.isApplicable(file, offset, false) ? postfixLiveTemplate : null;
|
||||
return postfixLiveTemplate != null && TemplateManagerImpl.isApplicable(postfixLiveTemplate, editor, file) ? postfixLiveTemplate : null;
|
||||
}
|
||||
|
||||
private static ElementPattern<? extends PsiElement> identifierAfterDot() {
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2000-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 com.intellij.codeInsight.template.postfix.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.InsertionContext;
|
||||
@@ -47,7 +62,7 @@ class PostfixTemplateLookupElement extends LiveTemplateLookupElement {
|
||||
|
||||
PsiFile file = context.getFile();
|
||||
|
||||
PostfixLiveTemplate postfixLiveTemplate = getPostfixLiveTemplate(file, editor.getCaretModel().getOffset());
|
||||
PostfixLiveTemplate postfixLiveTemplate = getPostfixLiveTemplate(context.getFile(), context.getEditor());
|
||||
if (postfixLiveTemplate != null) {
|
||||
postfixLiveTemplate.expand(templateKey, new CustomTemplateCallback(editor, file, false));
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class PostfixTemplatesCompletionProvider extends CompletionProvider<CompletionPa
|
||||
return;
|
||||
}
|
||||
|
||||
PostfixLiveTemplate postfixLiveTemplate = getPostfixLiveTemplate(parameters.getOriginalFile(), parameters.getOffset());
|
||||
PostfixLiveTemplate postfixLiveTemplate = getPostfixLiveTemplate(parameters.getOriginalFile(), parameters.getEditor());
|
||||
if (postfixLiveTemplate != null) {
|
||||
PsiFile file = parameters.getPosition().getContainingFile();
|
||||
final CustomTemplateCallback callback = new CustomTemplateCallback(parameters.getEditor(), file, false);
|
||||
@@ -50,7 +50,8 @@ class PostfixTemplatesCompletionProvider extends CompletionProvider<CompletionPa
|
||||
}
|
||||
}
|
||||
|
||||
String possibleKey = postfixLiveTemplate.computeTemplateKeyWithoutContextChecking(parameters.getEditor());
|
||||
CharSequence documentContent = parameters.getEditor().getDocument().getCharsSequence();
|
||||
String possibleKey = postfixLiveTemplate.computeTemplateKeyWithoutContextChecking(documentContent, parameters.getOffset());
|
||||
if (StringUtil.isNotEmpty(possibleKey)) {
|
||||
result = result.withPrefixMatcher(possibleKey);
|
||||
result.restartCompletionOnPrefixChange(StandardPatterns.string().startsWith(possibleKey));
|
||||
|
||||
@@ -74,15 +74,13 @@ public class PostfixLiveTemplate extends CustomLiveTemplateBase {
|
||||
@Override
|
||||
public String computeTemplateKey(@NotNull CustomTemplateCallback callback) {
|
||||
Editor editor = callback.getEditor();
|
||||
String key = computeTemplateKeyWithoutContextChecking(editor);
|
||||
String key = computeTemplateKeyWithoutContextChecking(editor.getDocument().getCharsSequence(), editor.getCaretModel().getOffset());
|
||||
if (key == null) return null;
|
||||
return isApplicableTemplate(getTemplateByKey(key), key, callback.getContext().getContainingFile(), editor) ? key : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String computeTemplateKeyWithoutContextChecking(@NotNull Editor editor) {
|
||||
int currentOffset = editor.getCaretModel().getOffset();
|
||||
CharSequence documentContent = editor.getDocument().getCharsSequence();
|
||||
public String computeTemplateKeyWithoutContextChecking(@NotNull CharSequence documentContent, int currentOffset) {
|
||||
int startOffset = currentOffset;
|
||||
while (startOffset > 0) {
|
||||
char currentChar = documentContent.charAt(startOffset - 1);
|
||||
@@ -119,11 +117,11 @@ public class PostfixLiveTemplate extends CustomLiveTemplateBase {
|
||||
@Override
|
||||
public boolean isApplicable(PsiFile file, int offset, boolean wrapping) {
|
||||
PostfixTemplatesSettings settings = PostfixTemplatesSettings.getInstance();
|
||||
return !wrapping
|
||||
&& file != null
|
||||
&& settings != null
|
||||
&& settings.isPostfixTemplatesEnabled()
|
||||
&& PsiUtilCore.getLanguageAtOffset(file, offset) == JavaLanguage.INSTANCE;
|
||||
if (wrapping || file == null || settings == null || !settings.isPostfixTemplatesEnabled() ||
|
||||
PsiUtilCore.getLanguageAtOffset(file, offset) != JavaLanguage.INSTANCE) {
|
||||
return false;
|
||||
}
|
||||
return StringUtil.isNotEmpty(computeTemplateKeyWithoutContextChecking(file.getText(), offset + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user