本文整理匯總了Java中com.intellij.codeInsight.completion.CompletionResultSet.withPrefixMatcher方法的典型用法代碼示例。如果您正苦於以下問題:Java CompletionResultSet.withPrefixMatcher方法的具體用法?Java CompletionResultSet.withPrefixMatcher怎麽用?Java CompletionResultSet.withPrefixMatcher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.codeInsight.completion.CompletionResultSet
的用法示例。
在下文中一共展示了CompletionResultSet.withPrefixMatcher方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolveMacroInfo
import com.intellij.codeInsight.completion.CompletionResultSet; //導入方法依賴的package包/類
private MacroInfo resolveMacroInfo(MacroResolver.Match match, CompletionResultSet completionResultSet, int cursorOffset) {
String reference = match.getReference();
reference = reference.substring(0, Math.min(cursorOffset - match.getStartPos(), reference.length()));
int lastDotIndex = reference.lastIndexOf(".");
String path;
if (reference.isEmpty()) {
// empty reference
completionResultSet = completionResultSet.withPrefixMatcher("");
path = "";
} else if (lastDotIndex != -1) {
// reference with at least one dot
completionResultSet = completionResultSet.withPrefixMatcher(reference.substring(lastDotIndex + 1));
path = reference.substring(0, lastDotIndex);
} else {
// reference without dot
completionResultSet = completionResultSet.withPrefixMatcher(reference);
path = "";
}
return new MacroInfo(path, completionResultSet);
}
示例2: addCompletions
import com.intellij.codeInsight.completion.CompletionResultSet; //導入方法依賴的package包/類
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
Editor editor = parameters.getEditor();
if (!isCompletionEnabled(parameters) || LiveTemplateCompletionContributor.shouldShowAllTemplates() ||
editor.getCaretModel().getCaretCount() != 1) {
/**
* disabled or covered with {@link com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor}
*/
return;
}
PsiFile originalFile = parameters.getOriginalFile();
PostfixLiveTemplate postfixLiveTemplate = getPostfixLiveTemplate(originalFile, editor);
if (postfixLiveTemplate != null) {
postfixLiveTemplate.addCompletions(parameters, result.withPrefixMatcher(new MyPrefixMatcher(result.getPrefixMatcher().getPrefix())));
String possibleKey = postfixLiveTemplate.computeTemplateKeyWithoutContextChecking(new CustomTemplateCallback(editor, originalFile));
if (possibleKey != null) {
result = result.withPrefixMatcher(possibleKey);
result.restartCompletionOnPrefixChange(
StandardPatterns.string().oneOf(postfixLiveTemplate.getAllTemplateKeys(originalFile, parameters.getOffset())));
}
}
}
示例3: adjustPrefix
import com.intellij.codeInsight.completion.CompletionResultSet; //導入方法依賴的package包/類
@NotNull
private CompletionResultSet adjustPrefix(Character chr, @NotNull CompletionResultSet completionResultSet) {
String currentColumn = completionResultSet.getPrefixMatcher().getPrefix();
if (currentColumn.indexOf(chr) != -1) {
currentColumn = currentColumn.substring(currentColumn.lastIndexOf(chr) + 1).trim();
completionResultSet = completionResultSet.withPrefixMatcher(currentColumn);
}
return completionResultSet;
}
示例4: addCompletions
import com.intellij.codeInsight.completion.CompletionResultSet; //導入方法依賴的package包/類
void addCompletions(Project project, String prefix, CompletionResultSet resultSet) {
String matcherPrefix = resultSet.getPrefixMatcher().getPrefix();
int dotIndex = matcherPrefix.lastIndexOf('.');
CompletionResultSet newResultSet = dotIndex < 0
? resultSet
: resultSet.withPrefixMatcher(matcherPrefix.substring(dotIndex + 1));
ElmModuleIndex.getAllModuleNames(project).stream()
.map(s -> getModulePart(s, prefix))
.forEach(optionalString -> optionalString.ifPresent(s -> addStringToResult(s, newResultSet)));
}
示例5: fillCompletionVariants
import com.intellij.codeInsight.completion.CompletionResultSet; //導入方法依賴的package包/類
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiFile file = parameters.getOriginalFile();
if (!(file instanceof PsiPlainTextFile)) return;
TextFieldCompletionProvider field = file.getUserData(TextFieldCompletionProvider.COMPLETING_TEXT_FIELD_KEY);
if (field == null) return;
if (!(field instanceof DumbAware) && DumbService.isDumb(file.getProject())) return;
String text = file.getText();
int offset = Math.min(text.length(), parameters.getOffset());
String prefix = field.getPrefix(text.substring(0, offset));
CompletionResultSet activeResult;
if (!result.getPrefixMatcher().getPrefix().equals(prefix)) {
activeResult = result.withPrefixMatcher(prefix);
}
else {
activeResult = result;
}
if (field.isCaseInsensitivity()) {
activeResult = activeResult.caseInsensitive();
}
field.addCompletionVariants(text, offset, prefix, activeResult);
activeResult.stopHere();
}
示例6: addCompletions
import com.intellij.codeInsight.completion.CompletionResultSet; //導入方法依賴的package包/類
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
final PsiElement psiElement = completionParameters.getPosition();
final MethodReference method = PsiTreeUtil.getParentOfType(psiElement, MethodReference.class);
if (method == null || method.getParameters().length == 0) {
return;
}
if (!ViewsUtil.isValidRenderMethod(method)) {
return;
}
PsiElement parameter = psiElement;
while (parameter != null && !(parameter.getParent() instanceof ParameterList)) {
parameter = parameter.getParent();
}
if (parameter == null || !parameter.equals(method.getParameters()[0])) {
return;
}
String path = getValue(method.getParameters()[0]);
PsiDirectory directory;
if (path.startsWith("/")) {
path = path.substring(1);
directory = ViewsUtil.getRootDirectory(psiElement);
} else {
directory = ViewsUtil.getContextDirectory(psiElement);
}
if (path.contains("/")) {
path = path.substring(0, path.lastIndexOf('/') + 1);
}
while (path.contains("/") && directory != null) {
String subdirectory = path.substring(0, path.indexOf('/'));
path = path.substring(path.indexOf('/') + 1);
directory = subdirectory.equals("..") ? directory.getParent() : directory.findSubdirectory(subdirectory);
}
if (directory != null) {
if (completionResultSet.getPrefixMatcher().getPrefix().contains("/")) {
String prefix = completionResultSet.getPrefixMatcher().getPrefix();
prefix = prefix.substring(prefix.lastIndexOf("/") + 1);
completionResultSet = completionResultSet.withPrefixMatcher(prefix);
}
for (PsiDirectory psiDirectory : directory.getSubdirectories()) {
completionResultSet.addElement(new DirectoryLookupElement(psiDirectory));
}
for (PsiFile psiFile : directory.getFiles()) {
completionResultSet.addElement(new ViewLookupElement(psiFile));
}
}
}