本文整理汇总了Java中com.intellij.codeInsight.lookup.LookupElementBuilder.withPresentableText方法的典型用法代码示例。如果您正苦于以下问题:Java LookupElementBuilder.withPresentableText方法的具体用法?Java LookupElementBuilder.withPresentableText怎么用?Java LookupElementBuilder.withPresentableText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.lookup.LookupElementBuilder
的用法示例。
在下文中一共展示了LookupElementBuilder.withPresentableText方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addEnumSuggestions
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
private static void addEnumSuggestions(Editor editor, String val, String suffix, List<LookupElement> answer,
String deprecated, String enums, String defaultValue, boolean xmlMode) {
String[] parts = enums.split(",");
for (String part : parts) {
String lookup = val + part;
LookupElementBuilder builder = LookupElementBuilder.create(lookup);
builder = addInsertHandler(editor, suffix, builder, xmlMode);
// only show the option in the UI
builder = builder.withPresentableText(part);
builder = builder.withBoldness(true);
if ("true".equals(deprecated)) {
// mark as deprecated
builder = builder.withStrikeoutness(true);
}
boolean isDefaultValue = defaultValue != null && part.equals(defaultValue);
if (isDefaultValue) {
builder = builder.withTailText(" (default value)");
// add default value first in the list
answer.add(0, builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
} else {
answer.add(builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
}
}
}
示例2: addSmartCompletionSuggestionsContextPath
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
public static List<LookupElement> addSmartCompletionSuggestionsContextPath(String val, ComponentModel component,
Map<String, String> existing, boolean xmlMode, PsiElement psiElement) {
List<LookupElement> answer = new ArrayList<>();
// show the syntax as the only choice for now
LookupElementBuilder builder = LookupElementBuilder.create(val);
builder = builder.withIcon(getCamelPreferenceService().getCamelIcon());
builder = builder.withBoldness(true);
builder = builder.withPresentableText(component.getSyntax());
LookupElement element = builder.withAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
answer.add(element);
val = removeUnknownEnum(val, psiElement);
List<LookupElement> old = addSmartCompletionContextPathEnumSuggestions(val, component, existing);
if (!old.isEmpty()) {
answer.addAll(old);
}
return answer;
}
开发者ID:camel-idea-plugin,项目名称:camel-idea-plugin,代码行数:21,代码来源:CamelSmartCompletionEndpointOptions.java
示例3: addBooleanSuggestions
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
private static void addBooleanSuggestions(Editor editor, String val, String suffix, List<LookupElement> answer,
String deprecated, String defaultValue, boolean xmlMode) {
// for boolean types then give a choice between true|false
String lookup = val + "true";
LookupElementBuilder builder = LookupElementBuilder.create(lookup);
builder = addInsertHandler(editor, suffix, builder, xmlMode);
// only show the option in the UI
builder = builder.withPresentableText("true");
if ("true".equals(deprecated)) {
// mark as deprecated
builder = builder.withStrikeoutness(true);
}
boolean isDefaultValue = defaultValue != null && "true".equals(defaultValue);
if (isDefaultValue) {
builder = builder.withTailText(" (default value)");
// add default value first in the list
answer.add(0, builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
} else {
answer.add(builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
}
lookup = val + "false";
builder = LookupElementBuilder.create(lookup);
builder = addInsertHandler(editor, suffix, builder, xmlMode);
// only show the option in the UI
builder = builder.withPresentableText("false");
if ("true".equals(deprecated)) {
// mark as deprecated
builder = builder.withStrikeoutness(true);
}
isDefaultValue = defaultValue != null && "false".equals(defaultValue);
if (isDefaultValue) {
builder = builder.withTailText(" (default value)");
// add default value first in the list
answer.add(0, builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
} else {
answer.add(builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
}
}
示例4: addDefaultValueSuggestions
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
private static void addDefaultValueSuggestions(Editor editor, String val, String suffix, List<LookupElement> answer,
String deprecated, String defaultValue, boolean xmlMode) {
String lookup = val + defaultValue;
LookupElementBuilder builder = LookupElementBuilder.create(lookup);
builder = addInsertHandler(editor, suffix, builder, xmlMode);
// only show the option in the UI
builder = builder.withPresentableText(defaultValue);
if ("true".equals(deprecated)) {
// mark as deprecated
builder = builder.withStrikeoutness(true);
}
builder = builder.withTailText(" (default value)");
// there is only one value in the list and its the default value, so never auto complete it but show as suggestion
answer.add(0, builder.withAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE));
}
示例5: addSmartCompletionContextPathEnumSuggestions
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
private static List<LookupElement> addSmartCompletionContextPathEnumSuggestions(String val, ComponentModel component,
Map<String, String> existing) {
List<LookupElement> answer = new ArrayList<>();
double priority = 100.0d;
// lets help the suggestion list if we are editing the context-path and only have 1 enum type option
// and the option has not been in use yet, then we can populate the list with the enum values.
long enums = component.getEndpointOptions().stream().filter(o -> "path".equals(o.getKind()) && !o.getEnums().isEmpty()).count();
if (enums == 1) {
for (EndpointOptionModel option : component.getEndpointOptions()) {
// only add support for enum in the context-path smart completion
if ("path".equals(option.getKind()) && !option.getEnums().isEmpty()) {
String name = option.getName();
// only add if not already used
String old = existing != null ? existing.get(name) : "";
if (existing == null || old == null || old.isEmpty()) {
// add all enum as choices
for (String choice : option.getEnums().split(",")) {
String key = choice;
String lookup = val + key;
LookupElementBuilder builder = LookupElementBuilder.create(lookup);
// only show the option in the UI
builder = builder.withPresentableText(choice);
// lets use the option name as the type so its visible
builder = builder.withTypeText(name, true);
builder = builder.withIcon(AllIcons.Nodes.Enum);
if ("true".equals(option.getDeprecated())) {
// mark as deprecated
builder = builder.withStrikeoutness(true);
}
// its an enum so always auto complete the choices
LookupElement element = builder.withAutoCompletionPolicy(AutoCompletionPolicy.ALWAYS_AUTOCOMPLETE);
// they should be in the exact order
element = PrioritizedLookupElement.withPriority(element, priority);
priority -= 1.0d;
answer.add(element);
}
}
}
}
}
return answer;
}
开发者ID:camel-idea-plugin,项目名称:camel-idea-plugin,代码行数:56,代码来源:CamelSmartCompletionEndpointOptions.java
示例6: getVariants
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
@NotNull
public Object[] getVariants() {
Map<String, LookupElement> variants = Maps.newHashMap();
try {
final List<PydevCompletionVariant> completions = myCommunication.getCompletions(getText(), myPrefix);
for (PydevCompletionVariant completion : completions) {
final PsiManager manager = myElement.getManager();
final String name = completion.getName();
final int type = completion.getType();
LookupElementBuilder builder = LookupElementBuilder
.create(new PydevConsoleElement(manager, name, completion.getDescription()))
.withIcon(PyCodeCompletionImages.getImageForType(type));
String args = completion.getArgs();
if (args.equals("(%)")) {
builder.withPresentableText("%" + completion.getName());
builder = builder.withInsertHandler(new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
final Editor editor = context.getEditor();
final Document document = editor.getDocument();
int offset = context.getStartOffset();
if (offset == 0 || !"%".equals(document.getText(TextRange.from(offset - 1, 1)))) {
document.insertString(offset, "%");
}
}
});
args = "";
}
else if (!StringUtil.isEmptyOrSpaces(args)) {
builder = builder.withTailText(args);
}
// Set function insert handler
if (type == IToken.TYPE_FUNCTION || args.endsWith(")")) {
builder = builder.withInsertHandler(ParenthesesInsertHandler.WITH_PARAMETERS);
}
variants.put(name, builder);
}
}
catch (Exception e) {
//LOG.error(e);
}
return variants.values().toArray();
}