本文整理汇总了Java中com.intellij.codeInsight.lookup.LookupElementBuilder.withTailText方法的典型用法代码示例。如果您正苦于以下问题:Java LookupElementBuilder.withTailText方法的具体用法?Java LookupElementBuilder.withTailText怎么用?Java LookupElementBuilder.withTailText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.lookup.LookupElementBuilder
的用法示例。
在下文中一共展示了LookupElementBuilder.withTailText方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: createLookupBuilder
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
public LookupElementBuilder createLookupBuilder(@NotNull final T item) {
LookupElementBuilder builder = LookupElementBuilder.create(item, getLookupString(item))
.withIcon(getIcon(item));
final InsertHandler<LookupElement> handler = createInsertHandler(item);
if (handler != null) {
builder = builder.withInsertHandler(handler);
}
final String tailText = getTailText(item);
if (tailText != null) {
builder = builder.withTailText(tailText, true);
}
final String typeText = getTypeText(item);
if (typeText != null) {
builder = builder.withTypeText(typeText);
}
return builder;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:TextFieldWithAutoCompletionListProvider.java
示例3: getResult
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
/**
* @return result lookup elements (to display in {@link PsiReference#getVariants()} for example)
*/
@NotNull
LookupElement[] getResult() {
final List<LookupElement> result = new ArrayList<LookupElement>(myMap.size());
for (final Entry<LookupElementBuilder, Pair<String, Integer>> entry : myMap.entrySet()) {
LookupElementBuilder elementBuilder = entry.getKey();
final Pair<String, Integer> helpAndPriority = entry.getValue();
final String help = helpAndPriority.first;
if (!StringUtil.isEmptyOrSpaces(help)) {
final int padding = myMaxLength - elementBuilder.getLookupString().length();
elementBuilder = elementBuilder.withTailText(String.format("%s : %s", StringUtil.repeat(" ", padding), help));
}
if (myHasPriority) {
// If we have priority and it is not provided for certain element we believe it is 0
final int priority = (helpAndPriority.second == null ? 0 : helpAndPriority.second);
result.add(PrioritizedLookupElement.withPriority(elementBuilder, priority));
}
else {
result.add(elementBuilder);
}
}
return result.toArray(new LookupElement[result.size()]);
}
示例4: createLookupElement
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
@Nullable
@Override
public LookupElement createLookupElement(ActionOrGroup actionOrGroup) {
if (actionOrGroup instanceof Action) {
Action action = (Action)actionOrGroup;
final PsiElement element = getPsiElement(actionOrGroup);
if (element == null) {
throw new IllegalStateException(action.getId().getStringValue() + " in " + DomUtil.getFile(action) + " " + action.isValid() + " ");
}
LookupElementBuilder builder =
LookupElementBuilder.create(ObjectUtils.assertNotNull(element),
ObjectUtils.assertNotNull(getName(action)));
final String text = action.getText().getStringValue();
if (StringUtil.isNotEmpty(text)) {
String withoutMnemonic = StringUtil.replace(text, "_", "");
builder = builder.withTailText(" \"" + withoutMnemonic + "\"", true);
}
return builder;
}
return super.createLookupElement(actionOrGroup);
}
示例5: fillCompletionResultSet
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
protected void fillCompletionResultSet(@NotNull CompletionResultSet completionResultSet, @NotNull Project project) {
for(Map.Entry<String, String> entry : EnvironmentVariablesApi.getAllKeyValues(project).entrySet()) {
LookupElementBuilder lockup = LookupElementBuilder.create(entry.getKey());
if(StringUtils.isNotEmpty(entry.getValue())) {
lockup = lockup.withTailText(" = " + entry.getValue(), true);
}
completionResultSet.addElement(PrioritizedLookupElement.withPriority(lockup, 100));
}
}
示例6: 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));
}
}
示例7: 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));
}
示例8: forClass
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
public static LookupElementBuilder forClass(@NotNull PsiClass psiClass,
final String lookupString,
final boolean withLocation) {
LookupElementBuilder builder =
LookupElementBuilder.create(psiClass, lookupString).withIcon(psiClass.getIcon(Iconable.ICON_FLAG_VISIBILITY));
String name = psiClass.getName();
if (StringUtil.isNotEmpty(name)) {
builder = builder.withLookupString(name);
}
if (withLocation) {
return builder.withTailText(" (" + PsiFormatUtil.getPackageDisplayName(psiClass) + ")", true);
}
return builder;
}
示例9: _getLookupItem
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
public LookupElementBuilder _getLookupItem(@NotNull final PsiFile file, String name, Icon icon) {
LookupElementBuilder builder = LookupElementBuilder.create(file, name).withIcon(icon);
final String info = _getInfo(file);
if (info != null) {
return builder.withTailText(String.format(" (%s)", info), true);
}
return builder;
}
示例10: createLookupElement
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
private static LookupElement createLookupElement(PsiMethod method) {
final LookupElementBuilder builder = LookupElementBuilder.create(method, method.getName())
.withIcon(method.getIcon(Iconable.ICON_FLAG_VISIBILITY))
.withPresentableText(method.getName());
final PsiClass containingClass = method.getContainingClass();
return containingClass != null
? builder.withTailText(" (" + containingClass.getQualifiedName() + ')')
: builder;
}
示例11: setTailText
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
private static LookupElementBuilder setTailText(PsiElement element, LookupElementBuilder builder, PsiSubstitutor substitutor) {
if (element instanceof PsiMethod) {
PsiClass aClass = ((PsiMethod)element).getContainingClass();
if (aClass != null && aClass.isAnnotationType()) {
return builder;
}
builder = builder.withTailText(PsiFormatUtil.formatMethod((PsiMethod)element, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS,
PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE));
}
else if (element instanceof PsiClass) {
String tailText = getPackageText((PsiClass)element);
final PsiClass psiClass = (PsiClass)element;
if ((substitutor == null || substitutor.getSubstitutionMap().isEmpty()) && psiClass.getTypeParameters().length > 0) {
tailText = "<" + StringUtil.join(psiClass.getTypeParameters(), new Function<PsiTypeParameter, String>() {
@Override
public String fun(PsiTypeParameter psiTypeParameter) {
return psiTypeParameter.getName();
}
}, "," + (showSpaceAfterComma(psiClass) ? " " : "")) + ">" + tailText;
}
builder = builder.withTailText(tailText, true);
}
String originInfo = OriginInfoProvider.getOriginInfo(element);
if (originInfo != null) {
builder = builder.appendTailText(" " + originInfo, true);
}
return builder;
}
示例12: buildLookup
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
@NotNull
public static LookupElementBuilder buildLookup(Object field, boolean showSchema, Project project) {
String lookupString = "-";
if (field instanceof DasObject) {
lookupString = ((DasObject) field).getName();
lookupString = RemoveTablePrefix(lookupString, project);
}
if (field instanceof Field) {
lookupString = ((Field) field).getName();
}
LookupElementBuilder builder = LookupElementBuilder.create(field, lookupString);
if (field instanceof Field) {
builder = builder.withTypeText(((Field) field).getType().toString())
.withIcon(((Field) field).getIcon());
}
if (field instanceof PhpDocProperty) {
builder = builder.withTypeText(((PhpDocProperty) field).getType().toString())
.withIcon(((PhpDocProperty) field).getIcon());
}
if (field instanceof DasColumn) {
DasColumn column = (DasColumn) field;
builder = builder.withTypeText(column.getDataType().typeName, true);
if (column.getDbParent() != null && showSchema && column.getDbParent().getDbParent() != null) {
builder = builder.withTailText(" (" + column.getDbParent().getDbParent().getName() + "." + RemoveTablePrefix(column.getDbParent().getName(), project) + ")", true);
}
if (column instanceof DasColumn)
builder = builder.withIcon(TypePresentationService.getService().getIcon(field));
if (column instanceof DbColumnImpl)
builder = builder.withIcon(((DbColumnImpl) column).getIcon());
}
if (field instanceof DasTable) {
DasTable table = (DasTable) field;
DasObject tableSchema = table.getDbParent();
if (tableSchema != null) {
if (tableSchema instanceof DbNamespaceImpl) {
Object dataSource = tableSchema.getDbParent();
// DbDataSourceImpl dataSource = (DbDataSourceImpl) ((DbNamespaceImpl) tableSchema).getDbParent();
if (dataSource != null && dataSource instanceof DbDataSourceImpl ) {
builder = builder.withTypeText(((DbDataSourceImpl)dataSource).getName(), true);
}
if (dataSource != null && dataSource instanceof DbDataSourceImpl ) {
builder = builder.withTypeText(((DbDataSourceImpl)dataSource).getName(), true);
}
}
}
if (showSchema && tableSchema != null) {
builder = builder.withTailText(" (" + table.getDbParent().getName() + ")", true);
}
if (table instanceof DasTable)
builder = builder.withIcon(TypePresentationService.getService().getIcon(table));
if (table instanceof DbElement)
builder = builder.withIcon(((DbElement) table).getIcon());
builder = builder.withInsertHandler((insertionContext, lookupElement) -> {
if (Yii2SupportSettings.getInstance(project).insertWithTablePrefix) {
Document document = insertionContext.getDocument();
int insertPosition = insertionContext.getSelectionEndOffset();
document.insertString(insertPosition - lookupElement.getLookupString().length(), "{{%");
document.insertString(insertPosition + 3, "}}");
insertionContext.getEditor().getCaretModel().getCurrentCaret().moveToOffset(insertPosition + 5);
}
});
}
return builder;
}
示例13: 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();
}
示例14: setupItem
import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
protected LookupElementBuilder setupItem(LookupElementBuilder item) {
final Object object = item.getObject();
if (!myPlainNamesOnly) {
if (!mySuppressParentheses &&
object instanceof PyFunction && ((PyFunction)object).getProperty() == null &&
!PyUtil.hasCustomDecorators((PyFunction)object) &&
!isSingleArgDecoratorCall(myContext, (PyFunction)object)) {
final Project project = ((PyFunction)object).getProject();
item = item.withInsertHandler(PyFunctionInsertHandler.INSTANCE);
final TypeEvalContext context = TypeEvalContext.codeCompletion(project, myContext != null ? myContext.getContainingFile() : null);
final List<PyParameter> parameters = PyUtil.getParameters((PyFunction)object, context);
final String params = StringUtil.join(parameters, new Function<PyParameter, String>() {
@Override
public String fun(PyParameter pyParameter) {
return pyParameter.getName();
}
}, ", ");
item = item.withTailText("(" + params + ")");
}
else if (object instanceof PyClass) {
item = item.withInsertHandler(PyClassInsertHandler.INSTANCE);
}
}
String source = null;
if (object instanceof PsiElement) {
final PsiElement element = (PsiElement)object;
PyClass cls = null;
if (element instanceof PyFunction) {
cls = ((PyFunction)element).getContainingClass();
}
else if (element instanceof PyTargetExpression) {
final PyTargetExpression expr = (PyTargetExpression)element;
if (expr.isQualified() || ScopeUtil.getScopeOwner(expr) instanceof PyClass) {
cls = expr.getContainingClass();
}
}
else if (element instanceof PyClass) {
final ScopeOwner owner = ScopeUtil.getScopeOwner(element);
if (owner instanceof PyClass) {
cls = (PyClass)owner;
}
}
if (cls != null) {
source = cls.getName();
}
else if (myContext == null || !PyUtil.inSameFile(myContext, element)) {
QualifiedName path = QualifiedNameFinder.findCanonicalImportPath(element, null);
if (path != null) {
if (element instanceof PyFile) {
path = path.removeLastComponent();
}
source = path.toString();
}
}
}
if (source != null) {
item = item.withTypeText(source);
}
return item;
}