IDEA-86431 Rename methods LookupElementBuilder.setXXX to withXXX

This commit is contained in:
peter
2012-05-22 17:10:42 +02:00
parent c3b3603256
commit 5d3597e1ff
44 changed files with 211 additions and 109 deletions
@@ -83,7 +83,7 @@ public class RegExpCompletionContributor extends CompletionContributor {
}
private static LookupElement createLookupElement(String name, String type, Icon icon) {
return LookupElementBuilder.create(name).setTypeText(type).setIcon(icon);
return LookupElementBuilder.create(name).withTypeText(type).withIcon(icon);
}
private static class PropertyNameCompletionProvider extends CompletionProvider<CompletionParameters> {
@@ -43,7 +43,7 @@ public class ClassByNameMerger implements Consumer<LookupElement> {
if (lastElement != null) {
if (lastElement.getLookupString().equals(element.getLookupString())) {
number++;
lastElement = LookupElementBuilder.create(element.getLookupString()).setTailText(" (" + number + " variants...)", true);
lastElement = LookupElementBuilder.create(element.getLookupString()).withTailText(" (" + number + " variants...)", true);
return;
}
@@ -36,7 +36,8 @@ public class JavaLookupElementBuilder {
public static LookupElementBuilder forField(@NotNull PsiField field,
final String lookupString,
final @Nullable PsiClass qualifierClass) {
final LookupElementBuilder builder = LookupElementBuilder.create(field, lookupString).setIcon(field.getIcon(Iconable.ICON_FLAG_VISIBILITY));
final LookupElementBuilder builder = LookupElementBuilder.create(field, lookupString).withIcon(
field.getIcon(Iconable.ICON_FLAG_VISIBILITY));
return setBoldIfInClass(field, qualifierClass, builder);
}
@@ -48,14 +49,14 @@ public class JavaLookupElementBuilder {
@NotNull String lookupString, final @NotNull PsiSubstitutor substitutor,
@Nullable PsiClass qualifierClass) {
LookupElementBuilder builder = LookupElementBuilder.create(method, lookupString)
.setIcon(method.getIcon(Iconable.ICON_FLAG_VISIBILITY))
.setPresentableText(method.getName())
.setTailText(PsiFormatUtil.formatMethod(method, substitutor,
PsiFormatUtil.SHOW_PARAMETERS,
PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE));
.withIcon(method.getIcon(Iconable.ICON_FLAG_VISIBILITY))
.withPresentableText(method.getName())
.withTailText(PsiFormatUtil.formatMethod(method, substitutor,
PsiFormatUtil.SHOW_PARAMETERS,
PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE));
final PsiType returnType = method.getReturnType();
if (returnType != null) {
builder = builder.setTypeText(substitutor.substitute(returnType).getPresentableText());
builder = builder.withTypeText(substitutor.substitute(returnType).getPresentableText());
}
builder = setBoldIfInClass(method, qualifierClass, builder);
return builder;
@@ -63,7 +64,7 @@ public class JavaLookupElementBuilder {
private static LookupElementBuilder setBoldIfInClass(@NotNull PsiMember member, @Nullable PsiClass psiClass, @NotNull LookupElementBuilder builder) {
if (psiClass != null && member.getManager().areElementsEquivalent(member.getContainingClass(), psiClass)) {
return builder.setBold();
return builder.bold();
}
return builder;
}
@@ -81,9 +82,9 @@ public class JavaLookupElementBuilder {
final String lookupString,
final boolean withLocation) {
final LookupElementBuilder builder =
LookupElementBuilder.create(psiClass, lookupString).setIcon(psiClass.getIcon(Iconable.ICON_FLAG_VISIBILITY));
LookupElementBuilder.create(psiClass, lookupString).withIcon(psiClass.getIcon(Iconable.ICON_FLAG_VISIBILITY));
if (withLocation) {
return builder.setTailText(" (" + PsiFormatUtil.getPackageDisplayName(psiClass) + ")", true);
return builder.withTailText(" (" + PsiFormatUtil.getPackageDisplayName(psiClass) + ")", true);
}
return builder;
}
@@ -345,9 +345,9 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor {
if (ourClassParent.isAnnotationType() && matcher.prefixMatches(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME)) {
set.add(LookupElementBuilder.create(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME)
.setIcon(PlatformIcons.METHOD_ICON)
.setTailText("()")
.setInsertHandler(ParenthesesInsertHandler.NO_PARAMETERS));
.withIcon(PlatformIcons.METHOD_ICON)
.withTailText("()")
.withInsertHandler(ParenthesesInsertHandler.NO_PARAMETERS));
}
addLookupItems(set, null, matcher, element.getProject(), getUnresolvedReferences(ourClassParent, true));
@@ -86,7 +86,7 @@ class SameSignatureCallParametersProvider extends CompletionProvider<CompletionP
icon.setIcon(PlatformIcons.PARAMETER_ICON, 0, 2*w/5, 0);
icon.setIcon(PlatformIcons.PARAMETER_ICON, 1);
final LookupElement element = LookupElementBuilder.create(lookupString).setIcon(icon);
final LookupElement element = LookupElementBuilder.create(lookupString).withIcon(icon);
element.putUserData(JavaCompletionUtil.SUPER_METHOD_PARAMETERS, Boolean.TRUE);
return TailTypeDecorator.withTail(element, ExpectedTypesProvider.getFinalCallParameterTailType(call, invoked.getReturnType(), invoked));
@@ -139,14 +139,14 @@ public class CreatePropertyFromUsageFix extends CreateFromUsageBaseFix {
@Override
public LookupElement[] calculateLookupItems(ExpressionContext context) {
Set<LookupElement> set = new LinkedHashSet<LookupElement>();
set.add(JavaLookupElementBuilder.forField(myField).setTypeText(myField.getType().getPresentableText()));
set.add(JavaLookupElementBuilder.forField(myField).withTypeText(myField.getType().getPresentableText()));
PsiField[] fields = myClass.getFields();
for (PsiField otherField : fields) {
if (!myDefaultFieldName.equals(otherField.getName())) {
PsiType otherType = otherField.getType();
for (PsiType type : myExpectedTypes) {
if (type.equals(otherType)) {
set.add(JavaLookupElementBuilder.forField(otherField).setTypeText(otherType.getPresentableText()));
set.add(JavaLookupElementBuilder.forField(otherField).withTypeText(otherType.getPresentableText()));
}
}
}
@@ -127,7 +127,7 @@ public class JavaLangClassMemberReference extends PsiReferenceBase<PsiLiteralExp
final List<LookupElementBuilder> elements = new ArrayList<LookupElementBuilder>();
for (PsiMethod method : psiClass.getMethods()) {
if (type == Type.DECLARED_METHOD || isPublic(method)) {
elements.add(JavaLookupElementBuilder.forMethod(method, PsiSubstitutor.EMPTY).setInsertHandler(this));
elements.add(JavaLookupElementBuilder.forMethod(method, PsiSubstitutor.EMPTY).withInsertHandler(this));
}
}
return elements.toArray();
@@ -563,7 +563,7 @@ public class JavaClassReference extends GenericReference implements PsiJavaRefer
return null;
}
}
return JavaLookupElementBuilder.forClass(clazz, name, true).addLookupString(qname).addLookupString(clazz.getName());
return JavaLookupElementBuilder.forClass(clazz, name, true).withLookupString(qname).withLookupString(clazz.getName());
}
@Override
@@ -347,7 +347,7 @@ public class JavaChangeSignatureDialog extends ChangeSignatureDialogBase<Paramet
for (String completionVariant : info.names) {
final LookupElementBuilder element = LookupElementBuilder.create(completionVariant);
result.addElement(element.addLookupString(completionVariant.toLowerCase()));
result.addElement(element.withLookupString(completionVariant.toLowerCase()));
}
}
}
@@ -32,7 +32,7 @@ import java.util.Set;
/**
* @author peter
*/
public class LookupElementBuilder extends LookupElement {
public final class LookupElementBuilder extends LookupElement {
@NotNull private final String myLookupString;
@NotNull private final Object myObject;
private final boolean myCaseSensitive;
@@ -75,12 +75,25 @@ public class LookupElementBuilder extends LookupElement {
return new LookupElementBuilder(lookupString, lookupObject);
}
/**
* @deprecated use {@link #withInsertHandler(com.intellij.codeInsight.completion.InsertHandler)}
*/
public LookupElementBuilder setInsertHandler(@Nullable InsertHandler<LookupElement> insertHandler) {
return withInsertHandler(insertHandler);
}
public LookupElementBuilder withInsertHandler(@Nullable InsertHandler<LookupElement> insertHandler) {
return new LookupElementBuilder(myLookupString, myObject, insertHandler, myRenderer, myHardcodedPresentation,
myAllLookupStrings, myCaseSensitive);
}
/**
* @deprecated use {@link #withRenderer(LookupElementRenderer)}
*/
public LookupElementBuilder setRenderer(@Nullable LookupElementRenderer<LookupElement> renderer) {
return withRenderer(renderer);
}
public LookupElementBuilder withRenderer(@Nullable LookupElementRenderer<LookupElement> renderer) {
return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, renderer, myHardcodedPresentation,
myAllLookupStrings, myCaseSensitive);
}
@@ -91,7 +104,14 @@ public class LookupElementBuilder extends LookupElement {
return myAllLookupStrings;
}
/**
* @deprecated use {@link #withIcon(javax.swing.Icon)}
*/
public LookupElementBuilder setIcon(@Nullable Icon icon) {
return withIcon(icon);
}
public LookupElementBuilder withIcon(@Nullable Icon icon) {
final LookupElementPresentation presentation = copyPresentation();
presentation.setIcon(icon);
return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, null, presentation,
@@ -109,7 +129,13 @@ public class LookupElementBuilder extends LookupElement {
return presentation;
}
/**
* @deprecated use {@link #withLookupString(String)}
*/
public LookupElementBuilder addLookupString(@NotNull String another) {
return withLookupString(another);
}
public LookupElementBuilder withLookupString(@NotNull String another) {
final THashSet<String> set = new THashSet<String>(myAllLookupStrings);
set.add(another);
return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, myRenderer, myHardcodedPresentation,
@@ -120,33 +146,63 @@ public class LookupElementBuilder extends LookupElement {
return myCaseSensitive;
}
/**
* @deprecated use {@link #withCaseSensitivity(boolean)}
*/
public LookupElementBuilder setCaseSensitive(boolean caseSensitive) {
return withCaseSensitivity(caseSensitive);
}
/**
* @param caseSensitive if this lookup item should be completed in the same letter case as prefix
* @return modified builder
* @see com.intellij.codeInsight.completion.CompletionResultSet#caseInsensitive()
*/
public LookupElementBuilder setCaseSensitive(boolean caseSensitive) {
public LookupElementBuilder withCaseSensitivity(boolean caseSensitive) {
return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, myRenderer, myHardcodedPresentation,
myAllLookupStrings, caseSensitive);
}
/**
* @deprecated use {@link #withItemTextForeground(java.awt.Color)}
*/
public LookupElementBuilder setItemTextForeground(@NotNull Color itemTextForeground) {
return withItemTextForeground(itemTextForeground);
}
public LookupElementBuilder withItemTextForeground(@NotNull Color itemTextForeground) {
final LookupElementPresentation presentation = copyPresentation();
presentation.setItemTextForeground(itemTextForeground);
return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, null, presentation, myAllLookupStrings, myCaseSensitive);
}
/**
* @deprecated use {@link #withItemTextUnderlined(boolean)}
*/
public LookupElementBuilder setItemTextUnderlined(boolean underlined) {
return withItemTextUnderlined(underlined);
}
public LookupElementBuilder withItemTextUnderlined(boolean underlined) {
final LookupElementPresentation presentation = copyPresentation();
presentation.setItemTextUnderlined(underlined);
return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, null, presentation, myAllLookupStrings, myCaseSensitive);
}
/**
* @deprecated use {@link #withTypeText(String)}
*/
public LookupElementBuilder setTypeText(@Nullable String typeText) {
return setTypeText(typeText, false);
return withTypeText(typeText);
}
public LookupElementBuilder withTypeText(@Nullable String typeText) {
return withTypeText(typeText, false);
}
/**
* @deprecated use {@link #withTypeText(String, boolean)}
*/
public LookupElementBuilder setTypeText(@Nullable String typeText, boolean grayed) {
return withTypeText(typeText, grayed);
}
public LookupElementBuilder withTypeText(@Nullable String typeText, boolean grayed) {
final LookupElementPresentation presentation = copyPresentation();
presentation.setTypeText(typeText);
presentation.setTypeGrayed(grayed);
@@ -154,40 +210,82 @@ public class LookupElementBuilder extends LookupElement {
myAllLookupStrings, myCaseSensitive);
}
/**
* @deprecated use {@link #withPresentableText(String)}
*/
public LookupElementBuilder setPresentableText(@NotNull String presentableText) {
return withPresentableText(presentableText);
}
public LookupElementBuilder withPresentableText(@NotNull String presentableText) {
final LookupElementPresentation presentation = copyPresentation();
presentation.setItemText(presentableText);
return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, null, presentation,
myAllLookupStrings, myCaseSensitive);
}
/**
* @deprecated use {@link #bold()}
*/
public LookupElementBuilder setBold() {
return setBold(true);
return bold();
}
public LookupElementBuilder bold() {
return withBoldness(true);
}
/**
* @deprecated use {@link #withBoldness(boolean)}
*/
public LookupElementBuilder setBold(boolean bold) {
return withBoldness(bold);
}
public LookupElementBuilder withBoldness(boolean bold) {
final LookupElementPresentation presentation = copyPresentation();
presentation.setItemTextBold(bold);
return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, null, presentation,
myAllLookupStrings, myCaseSensitive);
}
/**
* @deprecated use {@link #strikeout()}
*/
public LookupElementBuilder setStrikeout() {
return setStrikeout(true);
return strikeout();
}
public LookupElementBuilder strikeout() {
return withStrikeoutness(true);
}
/**
* @deprecated use {@link #withStrikeoutness(boolean)}
*/
public LookupElementBuilder setStrikeout(boolean strikeout) {
return withStrikeoutness(strikeout);
}
public LookupElementBuilder withStrikeoutness(boolean strikeout) {
final LookupElementPresentation presentation = copyPresentation();
presentation.setStrikeout(strikeout);
return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, null, presentation,
myAllLookupStrings, myCaseSensitive);
}
/**
* @deprecated use {@link #withTailText(String)}
*/
public LookupElementBuilder setTailText(@Nullable String tailText) {
return setTailText(tailText, false);
return withTailText(tailText);
}
public LookupElementBuilder withTailText(@Nullable String tailText) {
return withTailText(tailText, false);
}
/**
* @deprecated use {@link #withTailText(String, boolean)}
*/
public LookupElementBuilder setTailText(@Nullable String tailText, boolean grayed) {
return withTailText(tailText, grayed);
}
public LookupElementBuilder withTailText(@Nullable String tailText, boolean grayed) {
final LookupElementPresentation presentation = copyPresentation();
presentation.setTailText(tailText, grayed);
return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, null, presentation,
@@ -45,12 +45,13 @@ public class ComboEditorCompletionContributor extends CompletionContributor{
for (int i = 0; i < count; i++) {
final Object o = comboBox.getItemAt(i);
if (o instanceof String) {
resultSet.addElement(PrioritizedLookupElement.withPriority(LookupElementBuilder.create((String)o).setInsertHandler(new InsertHandler<LookupElement>() {
public void handleInsert(final InsertionContext context, final LookupElement item) {
final Document document = context.getEditor().getDocument();
document.deleteString(context.getEditor().getCaretModel().getOffset(), document.getTextLength());
}
}), count-i));
resultSet.addElement(PrioritizedLookupElement.withPriority(LookupElementBuilder.create((String)o).withInsertHandler(
new InsertHandler<LookupElement>() {
public void handleInsert(final InsertionContext context, final LookupElement item) {
final Document document = context.getEditor().getDocument();
document.deleteString(context.getEditor().getCaretModel().getOffset(), document.getTextLength());
}
}), count-i));
}
}
result.stopHere();
@@ -51,7 +51,7 @@ public class CommitCompletionContributor extends CompletionContributor {
VirtualFile virtualFile = change.getVirtualFile();
if (virtualFile != null) {
insensitive.addElement(LookupElementBuilder.create(virtualFile.getName()).
setIcon(VirtualFilePresentation.getIcon(virtualFile)));
withIcon(VirtualFilePresentation.getIcon(virtualFile)));
}
}
}
@@ -87,18 +87,18 @@ public class FileInfoManager implements Disposable {
public static LookupElementBuilder getFileLookupItem(PsiElement psiElement, String encoded, Icon icon) {
if (!(psiElement instanceof PsiFile) || !(psiElement.isPhysical())) {
return LookupElementBuilder.create(psiElement, encoded).setIcon(icon);
return LookupElementBuilder.create(psiElement, encoded).withIcon(icon);
}
return getFileInfoManager()._getLookupItem((PsiFile)psiElement, encoded, icon);
}
public LookupElementBuilder _getLookupItem(@NotNull final PsiFile file, String name, Icon icon) {
LookupElementBuilder builder = LookupElementBuilder.create(file, name).setIcon(icon);
LookupElementBuilder builder = LookupElementBuilder.create(file, name).withIcon(icon);
final String info = _getInfo(file);
if (info != null) {
return builder.setTailText(String.format(" (%s)", info), true);
return builder.withTailText(String.format(" (%s)", info), true);
}
return builder;
@@ -292,7 +292,7 @@ public class FileReference implements FileReferenceOwner, PsiPolyVariantReferenc
if (!encoded.equals(name)) {
final Icon icon = psiElement.getIcon(Iconable.ICON_FLAG_READ_STATUS | Iconable.ICON_FLAG_VISIBILITY);
LookupElementBuilder item = FileInfoManager.getFileLookupItem(candidates[i], encoded, icon);
encodedVariants.add(item.setTailText(" (" + name + ")"));
encodedVariants.add(item.withTailText(" (" + name + ")"));
}
else {
encodedVariants.add(variants[i]);
@@ -74,7 +74,7 @@ public class MyLookupExpression extends Expression {
final Iterator<String> iterator = names.iterator();
for (int i = 0; i < lookupElements.length; i++) {
final String suggestion = iterator.next();
lookupElements[i] = LookupElementBuilder.create(suggestion).setInsertHandler(new InsertHandler<LookupElement>() {
lookupElements[i] = LookupElementBuilder.create(suggestion).withInsertHandler(new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
if (shouldSelectAll) return;
@@ -108,21 +108,21 @@ public abstract class TextFieldWithAutoCompletionListProvider<T> implements Comp
public LookupElementBuilder createLookupBuilder(@NotNull final T item) {
LookupElementBuilder builder = LookupElementBuilder.create(item, getLookupString(item))
.setIcon(getIcon(item));
.withIcon(getIcon(item));
final InsertHandler<LookupElement> handler = createInsertHandler(item);
if (handler != null) {
builder = builder.setInsertHandler(handler);
builder = builder.withInsertHandler(handler);
}
final String tailText = getTailText(item);
if (tailText != null) {
builder = builder.setTailText(tailText, true);
builder = builder.withTailText(tailText, true);
}
final String typeText = getTypeText(item);
if (typeText != null) {
builder = builder.setTypeText(typeText);
builder = builder.withTypeText(typeText);
}
return builder;
}
@@ -58,12 +58,12 @@ final class LanguageReference extends StringLiteralReference {
final FileType ft = l.getAssociatedFileType();
if (ft != null) {
return LookupElementBuilder.create(s).setIcon(ft.getIcon()).setTypeText(ft.getDescription());
return LookupElementBuilder.create(s).withIcon(ft.getIcon()).withTypeText(ft.getDescription());
// } else if (l == StdLanguages.EL) {
// // IDEA-10012
// return new LanguageLookupValue(s, StdFileTypes.JSP.getIcon(), "Expression Language");
}
return LookupElementBuilder.create(s).setIcon(EmptyIcon.ICON_16);
return LookupElementBuilder.create(s).withIcon(EmptyIcon.ICON_16);
}
});
}
@@ -50,7 +50,7 @@ final class RegExpEnumReference extends StringLiteralReference {
}
return ContainerUtil.map2Array(values, new Function<String, Object>() {
public Object fun(String s) {
return LookupElementBuilder.create(s).setIcon(PlatformIcons.ENUM_ICON);
return LookupElementBuilder.create(s).withIcon(PlatformIcons.ENUM_ICON);
}
});
}
@@ -153,11 +153,11 @@ public class OnClickConverter extends Converter<String> implements CustomReferen
private static LookupElement createLookupElement(PsiMethod method) {
final LookupElementBuilder builder = LookupElementBuilder.create(method, method.getName())
.setIcon(method.getIcon(Iconable.ICON_FLAG_VISIBILITY))
.setPresentableText(method.getName());
.withIcon(method.getIcon(Iconable.ICON_FLAG_VISIBILITY))
.withPresentableText(method.getName());
final PsiClass containingClass = method.getContainingClass();
return containingClass != null
? builder.setTailText(" (" + containingClass.getQualifiedName() + ')')
? builder.withTailText(" (" + containingClass.getQualifiedName() + ')')
: builder;
}
}
@@ -62,7 +62,7 @@ public class StyleItemNameConverter extends ResolvingConverter<String> {
return null;
}
final String attributeName = s.substring(prefix.length());
return LookupElementBuilder.create(s).addLookupString(attributeName);
return LookupElementBuilder.create(s).withLookupString(attributeName);
}
@Override
@@ -91,7 +91,7 @@ public class AntDomPropertyReference extends PsiPolyVariantReferenceBase<PsiElem
Object[] result = new Object[variants.size()];
int idx = 0;
for (String variant : variants) {
final LookupElementBuilder builder = LookupElementBuilder.create(variant).setCaseSensitive(false);
final LookupElementBuilder builder = LookupElementBuilder.create(variant).withCaseSensitivity(false);
final LookupElement element = AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE.applyPolicy(builder);
result[idx++] = element;
}
@@ -137,7 +137,7 @@ class AntDomTargetReference extends AntDomReferenceBase implements BindablePsiRe
if (existing.contains(s)){
continue;
}
final LookupElementBuilder builder = LookupElementBuilder.create(s).setCaseSensitive(false);
final LookupElementBuilder builder = LookupElementBuilder.create(s).withCaseSensitivity(false);
final LookupElement element = AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE.applyPolicy(builder);
resVariants.add(element);
}
@@ -170,7 +170,7 @@ public class UsersFilterAction extends BasePopupAction {
if (list != null) {
for (String completionVariant : list) {
final LookupElementBuilder element = LookupElementBuilder.create(completionVariant);
result.addElement(element.addLookupString(completionVariant.toLowerCase()));
result.addElement(element.withLookupString(completionVariant.toLowerCase()));
}
}
}
@@ -281,7 +281,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
protected void addCompletions(@NotNull CompletionParameters parameters,
ProcessingContext context,
@NotNull CompletionResultSet result) {
result.addElement(LookupElementBuilder.create("if").setBold().setInsertHandler(new InsertHandler<LookupElement>() {
result.addElement(LookupElementBuilder.create("if").bold().withInsertHandler(new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
if (context.getCompletionChar() != ' ') {
@@ -290,7 +290,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
if (context.getCompletionChar() == '(') {
context.setAddCompletionChar(false);
}
}
}
}));
}
});
@@ -207,7 +207,7 @@ public class GroovyCompletionData {
}
private static LookupElement keyword(final String keyword, @NotNull TailType tail) {
LookupElementBuilder element = LookupElementBuilder.create(keyword).setBold();
LookupElementBuilder element = LookupElementBuilder.create(keyword).bold();
return tail != TailType.NONE ? TailTypeDecorator.withTail(element, tail) : element;
}
@@ -267,7 +267,7 @@ public class GroovyCompletionUtil {
}
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
LookupElementBuilder builder = LookupElementBuilder.create(resolveResult, importedName).setPresentableText(importedName);
LookupElementBuilder builder = LookupElementBuilder.create(resolveResult, importedName).withPresentableText(importedName);
return setupLookupBuilder(element, substitutor, builder);
}
@@ -275,15 +275,15 @@ public class GroovyCompletionUtil {
if (o instanceof LookupElement) return (LookupElement)o;
if (o instanceof PsiNamedElement) return generateLookupElement((PsiNamedElement)o);
if (o instanceof PsiElement) return setupLookupBuilder((PsiElement)o, PsiSubstitutor.EMPTY, LookupElementBuilder.create(o, ((PsiElement)o).getText()));
return LookupElementBuilder.create(o, o.toString()).setItemTextUnderlined(true);
return LookupElementBuilder.create(o, o.toString()).withItemTextUnderlined(true);
}
private static LookupElementBuilder generateLookupElement(PsiNamedElement element) {
return setupLookupBuilder(element, PsiSubstitutor.EMPTY, LookupElementBuilder.create(element));
}
private static LookupElementBuilder setupLookupBuilder(PsiElement element, PsiSubstitutor substitutor, LookupElementBuilder builder) {
builder = builder.setIcon(element.getIcon(Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS))
.setInsertHandler(GroovyInsertHandler.INSTANCE);
builder = builder.withIcon(element.getIcon(Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS))
.withInsertHandler(GroovyInsertHandler.INSTANCE);
builder = setTailText(element, builder, substitutor);
builder = setTypeText(element, builder, substitutor);
return builder;
@@ -291,8 +291,8 @@ public class GroovyCompletionUtil {
private static LookupElementBuilder setTailText(PsiElement element, LookupElementBuilder builder, PsiSubstitutor substitutor) {
if (element instanceof PsiMethod) {
builder = builder.setTailText(PsiFormatUtil.formatMethod((PsiMethod)element, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS,
PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE));
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);
@@ -304,7 +304,7 @@ public class GroovyCompletionUtil {
}
}, "," + (showSpaceAfterComma(psiClass) ? " " : "")) + ">" + tailText;
}
builder = builder.setTailText(tailText, true);
builder = builder.withTailText(tailText, true);
}
return builder;
}
@@ -331,7 +331,7 @@ public class GroovyCompletionUtil {
else if (element instanceof PsiMethod) {
type = substitutor.substitute(((PsiMethod)element).getReturnType());
}
return type != null ? builder.setTypeText(type.getPresentableText()) : builder;
return type != null ? builder.withTypeText(type.getPresentableText()) : builder;
}
public static boolean hasConstructorParameters(@NotNull PsiClass clazz, @NotNull GroovyPsiElement place) {
@@ -78,7 +78,7 @@ public class GroovyDocCompletionProvider extends CompletionProvider<CompletionPa
for (PsiElement psiElement : elements) {
LookupElement element = GroovyCompletionUtil.getLookupElement(psiElement);
if (psiElement instanceof PsiMethod) {
element = ((LookupElementBuilder)element).setInsertHandler(new GroovyMethodSignatureInsertHandler());
element = ((LookupElementBuilder)element).withInsertHandler(new GroovyMethodSignatureInsertHandler());
}
result.addElement(element);
}
@@ -94,14 +94,14 @@ class MapArgumentCompletionProvider extends CompletionProvider<CompletionParamet
for (Map.Entry<String, NamedArgumentDescriptor> entry : map.entrySet()) {
LookupElementBuilder lookup = LookupElementBuilder.create(entry.getValue(), entry.getKey())
.setInsertHandler(NamedArgumentInsertHandler.INSTANCE)
.setTailText(":");
.withInsertHandler(NamedArgumentInsertHandler.INSTANCE)
.withTailText(":");
if (entry.getValue().getPriority() == Priority.UNLIKELY) {
lookup.setItemTextForeground(DefaultHighlighter.MAP_KEY_COLOR);
lookup.withItemTextForeground(DefaultHighlighter.MAP_KEY_COLOR);
}
else {
lookup = lookup.setIcon(GroovyIcons.DYNAMIC);
lookup = lookup.withIcon(GroovyIcons.DYNAMIC);
}
result.addElement(lookup);
@@ -64,7 +64,7 @@ public class ChooseTypeExpression extends Expression {
}
if (forGroovy) {
result.add(LookupElementBuilder.create(GrModifier.DEF).setBold());
result.add(LookupElementBuilder.create(GrModifier.DEF).bold());
}
return result.toArray(new LookupElement[result.size()]);
@@ -74,7 +74,7 @@ public class ChooseTypeExpression extends Expression {
String text = type.getCanonicalText();
String unboxed = PsiTypesUtil.unboxIfPossible(text);
if (unboxed != null && !unboxed.equals(text)) {
result.add(LookupElementBuilder.create(unboxed).setBold());
result.add(LookupElementBuilder.create(unboxed).bold());
} else {
result.add(PsiTypeLookupItem.createLookupItem(type, null));
}
@@ -149,9 +149,9 @@ public class CompleteReferenceExpression {
@NotNull
public static LookupElementBuilder createPropertyLookupElement(@NotNull String name, @Nullable PsiType type) {
LookupElementBuilder res = LookupElementBuilder.create(name).setIcon(GroovyIcons.PROPERTY);
LookupElementBuilder res = LookupElementBuilder.create(name).withIcon(GroovyIcons.PROPERTY);
if (type != null) {
res = res.setTypeText(type.getPresentableText());
res = res.withTypeText(type.getPresentableText());
}
return res;
}
@@ -190,9 +190,9 @@ public class CompleteReferenceExpression {
LookupElementBuilder builder =
LookupElementBuilder.create(generatePropertyResolveResult(propName, accessor, propType, resolveResult), propName)
.setIcon(GroovyIcons.PROPERTY);
.withIcon(GroovyIcons.PROPERTY);
if (substituted != null) {
builder = builder.setTypeText(substituted.getPresentableText());
builder = builder.withTypeText(substituted.getPresentableText());
}
return builder;
}
@@ -440,7 +440,7 @@ public class CompleteReferenceExpression {
private void processPropertyFromField(GrField field, GroovyResolveResult resolveResult) {
if (field.getGetters().length != 0 || field.getSetter() != null || !myPropertyNames.add(field.getName())) return;
myConsumer.consume(((LookupElementBuilder)GroovyCompletionUtil.createCompletionVariant(resolveResult)).setIcon(GroovyIcons.PROPERTY));
myConsumer.consume(((LookupElementBuilder)GroovyCompletionUtil.createCompletionVariant(resolveResult)).withIcon(GroovyIcons.PROPERTY));
}
private void processProperty(PsiMethod method, GroovyResolveResult resolveResult) {
@@ -474,7 +474,7 @@ public class CompleteReferenceExpression {
if (myPropertyNames.add(name)) {
LookupElementBuilder builder = LookupElementBuilder
.create(generatePropertyResolveResult(name, listenerMethod, null, null), name)
.setIcon(GroovyIcons.PROPERTY);
.withIcon(GroovyIcons.PROPERTY);
myConsumer.consume(builder);
}
}
@@ -55,8 +55,8 @@ public abstract class MavenRepositoryConverter extends ResolvingConverter<String
@Override
public LookupElement createLookupElement(String s) {
return LookupElementBuilder.create(s)
.setIcon(MavenIcons.REPOSITORY_ICON)
.setTailText(" (" + MavenRepositoriesProvider.getInstance().getRepositoryUrl(s) + ")", true);
.withIcon(MavenIcons.REPOSITORY_ICON)
.withTailText(" (" + MavenRepositoriesProvider.getInstance().getRepositoryUrl(s) + ")", true);
}
}
@@ -69,7 +69,7 @@ public class MavenModulePsiReference extends MavenPsiReference implements LocalQ
PsiFile psiFile = eachDomFile.getFile();
String modulePath = calcRelativeModulePath(myVirtualFile, eachVFile);
result.add(LookupElementBuilder.create(psiFile, modulePath).setPresentableText(modulePath));
result.add(LookupElementBuilder.create(psiFile, modulePath).withPresentableText(modulePath));
}
return result.toArray();
@@ -315,7 +315,7 @@ public class MavenPropertyPsiReference extends MavenPsiReference {
if (prefix == null) {
result.add(createLookupElement(baseDir, "project.baseUri", MavenIcons.MAVEN_ICON));
result.add(createLookupElement(baseDir, "pom.baseUri", MavenIcons.MAVEN_ICON));
result.add(LookupElementBuilder.create(TIMESTAMP_PROP).setIcon(MavenIcons.MAVEN_ICON));
result.add(LookupElementBuilder.create(TIMESTAMP_PROP).withIcon(MavenIcons.MAVEN_ICON));
}
processSchema(MavenSchemaProvider.MAVEN_PROJECT_SCHEMA_URL, new SchemaProcessor<Object>() {
@@ -343,12 +343,12 @@ public class MavenPropertyPsiReference extends MavenPsiReference {
MavenRunnerSettings runnerSettings = MavenRunner.getInstance(myProject).getSettings();
for (String prop : runnerSettings.getMavenProperties().keySet()) {
if (!isResultAlreadyContains(result, prop)) {
result.add(LookupElementBuilder.create(prop).setIcon(PlatformIcons.PROPERTY_ICON));
result.add(LookupElementBuilder.create(prop).withIcon(PlatformIcons.PROPERTY_ICON));
}
}
for (String prop : MavenUtil.getPropertiesFromMavenOpts().keySet()) {
if (!isResultAlreadyContains(result, prop)) {
result.add(LookupElementBuilder.create(prop).setIcon(PlatformIcons.PROPERTY_ICON));
result.add(LookupElementBuilder.create(prop).withIcon(PlatformIcons.PROPERTY_ICON));
}
}
}
@@ -404,8 +404,8 @@ public class MavenPropertyPsiReference extends MavenPsiReference {
private static LookupElement createLookupElement(@NotNull Object element, @NotNull String name, @Nullable Icon icon) {
return LookupElementBuilder.create(element, name)
.setIcon(icon)
.setPresentableText(name);
.withIcon(icon)
.withPresentableText(name);
}
@Nullable
@@ -109,7 +109,7 @@ public abstract class MavenRunnerParametersConfigurable implements Configurable,
cachedElements = new ArrayList<LookupElement>(goals.size());
for (String goal : goals) {
cachedElements.add(LookupElementBuilder.create(goal).setIcon(MavenIcons.PHASE_ICON));
cachedElements.add(LookupElementBuilder.create(goal).withIcon(MavenIcons.PHASE_ICON));
}
myCachedElements = cachedElements;
@@ -270,12 +270,12 @@ public abstract class PropertyReferenceBase implements PsiPolyVariantReference,
return ContainerUtil.mapNotNull(variants, new NullableFunction<Object, LookupElement>() {
@Override
public LookupElement fun(Object o) {
if (o instanceof String) return LookupElementBuilder.create((String)o).setIcon(PlatformIcons.PROPERTY_ICON);
if (o instanceof String) return LookupElementBuilder.create((String)o).withIcon(PlatformIcons.PROPERTY_ICON);
IProperty property = (IProperty)o;
String key = property.getKey();
if (key == null) return null;
return LookupElementBuilder.create(property, key).setRenderer(LOOKUP_ELEMENT_RENDERER);
return LookupElementBuilder.create(property, key).withRenderer(LOOKUP_ELEMENT_RENDERER);
}
}).toArray();
}
@@ -323,9 +323,9 @@ public class ActivateTaskDialog extends DialogWrapper {
public LookupElementBuilder createLookupBuilder(@NotNull final Task task) {
LookupElementBuilder builder = super.createLookupBuilder(task);
builder = builder.addLookupString(task.getSummary());
builder = builder.withLookupString(task.getSummary());
if (task.isClosed()) {
builder = builder.setStrikeout();
builder = builder.strikeout();
}
return builder;
@@ -181,9 +181,10 @@ public class XmlCompletionContributor extends CompletionContributor {
final String namespace,
final String tailText, @Nullable String namespacePrefix) {
LookupElementBuilder builder =
LookupElementBuilder.create(Pair.create(name, namespace), name).setInsertHandler(new ExtendedTagInsertHandler(name, namespace, namespacePrefix));
LookupElementBuilder.create(Pair.create(name, namespace), name).withInsertHandler(
new ExtendedTagInsertHandler(name, namespace, namespacePrefix));
if (!StringUtil.isEmpty(namespace)) {
builder = builder.setTypeText(tailText, true);
builder = builder.withTypeText(tailText, true);
}
return builder;
}
@@ -70,13 +70,13 @@ public class XmlSmartCompletionProvider {
insertHandler = new ExtendedTagInsertHandler(name, ((XmlElementDescriptorImpl)descriptor).getNamespace(), null);
}
}
result.addElement(createLookupElement(descriptor).setInsertHandler(insertHandler));
result.addElement(createLookupElement(descriptor).withInsertHandler(insertHandler));
}
public static LookupElementBuilder createLookupElement(@NotNull XmlElementDescriptor descriptor) {
LookupElementBuilder builder = LookupElementBuilder.create(descriptor.getName());
if (descriptor instanceof XmlElementDescriptorImpl) {
builder = builder.setTypeText(((XmlElementDescriptorImpl)descriptor).getNamespace(), true);
builder = builder.withTypeText(((XmlElementDescriptorImpl)descriptor).getNamespace(), true);
}
return builder;
}
@@ -92,7 +92,7 @@ public class XmlEncodingReference implements PsiReference, EmptyResolveMessagePr
Charset[] charsets = CharsetToolkit.getAvailableCharsets();
List<LookupElement> suggestions = new ArrayList<LookupElement>(charsets.length);
for (Charset charset : charsets) {
suggestions.add(LookupElementBuilder.create(charset.name()).setCaseSensitive(false));
suggestions.add(LookupElementBuilder.create(charset.name()).withCaseSensitivity(false));
}
return suggestions.toArray(new LookupElement[suggestions.size()]);
}
@@ -222,13 +222,13 @@ public class TagNameReference implements PsiReference {
LookupElementBuilder lookupElement = LookupElementBuilder.create(qname);
final int separator = qname.indexOf(':');
if (separator > 0) {
lookupElement = lookupElement.addLookupString(qname.substring(separator + 1));
lookupElement = lookupElement.withLookupString(qname.substring(separator + 1));
}
String ns = nsInfo.get(i);
if (StringUtil.isNotEmpty(ns)) {
lookupElement = lookupElement.setTypeText(ns, true);
lookupElement = lookupElement.withTypeText(ns, true);
}
elements.add(lookupElement.setInsertHandler(XmlTagInsertHandler.INSTANCE));
elements.add(lookupElement.withInsertHandler(XmlTagInsertHandler.INSTANCE));
}
return elements.toArray(new LookupElement[elements.size()]);
}
@@ -469,13 +469,13 @@ public class XmlAttributeImpl extends XmlElementImpl implements XmlAttribute {
}
LookupElementBuilder element = LookupElementBuilder.create(name);
if (descriptor instanceof PsiPresentableMetaData) {
element = element.setIcon(((PsiPresentableMetaData)descriptor).getIcon());
element = element.withIcon(((PsiPresentableMetaData)descriptor).getIcon());
}
final int separator = name.indexOf(':');
if (separator > 0) {
element = element.addLookupString(name.substring(separator + 1));
element = element.withLookupString(name.substring(separator + 1));
}
variants.add(element.setCaseSensitive(caseSensitive).setInsertHandler(XmlAttributeInsertHandler.INSTANCE));
variants.add(element.withCaseSensitivity(caseSensitive).withInsertHandler(XmlAttributeInsertHandler.INSTANCE));
}
}
}
@@ -189,7 +189,7 @@ class AnchorReference implements PsiReference, EmptyResolveMessageProvider {
String[] variants = idMap.keySet().toArray(new String[idMap.size()]);
LookupElement[] elements = new LookupElement[variants.length];
for (int i = 0, variantsLength = variants.length; i < variantsLength; i++) {
elements[i] = LookupElementBuilder.create(variants[i]).setCaseSensitive(true);
elements[i] = LookupElementBuilder.create(variants[i]).withCaseSensitivity(true);
}
return elements;
}
@@ -39,12 +39,13 @@ public class UserColorLookup extends LookupElementDecorator<LookupElement> {
private static final String COLOR_STRING = XmlBundle.message("choose.color.in.color.lookup");
public UserColorLookup() {
super(PrioritizedLookupElement.withPriority(LookupElementBuilder.create(COLOR_STRING).setInsertHandler(new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
handleUserSelection(context);
}
}), LookupValueWithPriority.HIGH));
super(PrioritizedLookupElement.withPriority(LookupElementBuilder.create(COLOR_STRING).withInsertHandler(
new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
handleUserSelection(context);
}
}), LookupValueWithPriority.HIGH));
}
private static void handleUserSelection(InsertionContext context) {
@@ -100,7 +100,7 @@ public class RncCompletionData extends CompletionData {
public Object[] get(PsiElement context, CompletionContext completionContext) {
return ContainerUtil.map2Array(doGetKeywords(context), LookupElement.class, new Function<String, LookupElement>() {
public LookupElement fun(String s) {
return TailTypeDecorator.withTail(LookupElementBuilder.create(s).setBold(), TailType.SPACE);
return TailTypeDecorator.withTail(LookupElementBuilder.create(s).bold(), TailType.SPACE);
}
});
}