Java Code Examples for com.intellij.codeInsight.lookup.LookupElementPresentation#setTailText()

The following examples show how to use com.intellij.codeInsight.lookup.LookupElementPresentation#setTailText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonParseUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
public static void decorateLookupElement(@NotNull LookupElementPresentation lookupElement, @NotNull JsonRawLookupElement jsonLookup) {

        if(jsonLookup.getTailText() != null) {
            lookupElement.setTailText(jsonLookup.getTailText(), true);
        }

        if(jsonLookup.getTypeText() != null) {
            lookupElement.setTypeText(jsonLookup.getTypeText());
            lookupElement.setTypeGrayed(true);
        }

        String iconString = jsonLookup.getIcon();
        if(iconString != null) {
            Icon icon = getLookupIconOnString(iconString);
            if(icon != null) {
                lookupElement.setIcon(icon);
            }
        }

    }
 
Example 2
Source File: JsonParseUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
public static void decorateLookupElement(@NotNull LookupElementPresentation lookupElement, @NotNull JsonRawLookupElement jsonLookup) {

        if(jsonLookup.getTailText() != null) {
            lookupElement.setTailText(jsonLookup.getTailText(), true);
        }

        if(jsonLookup.getTypeText() != null) {
            lookupElement.setTypeText(jsonLookup.getTypeText());
            lookupElement.setTypeGrayed(true);
        }

        String iconString = jsonLookup.getIcon();
        if(iconString != null) {
            Icon icon = getLookupIconOnString(iconString);
            if(icon != null) {
                lookupElement.setIcon(icon);
            }
        }

    }
 
Example 3
Source File: DoctrineModelFieldLookupElement.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void renderElement(LookupElementPresentation presentation) {
    super.renderElement(presentation);

    presentation.setItemTextBold(withBoldness);
    presentation.setIcon(Symfony2Icons.DOCTRINE);
    presentation.setTypeGrayed(true);

    if(this.doctrineModelField.getTypeName() != null) {
        presentation.setTypeText(this.doctrineModelField.getTypeName());
    }

    if(this.doctrineModelField.getRelationType() != null) {
        presentation.setTailText(String.format("(%s)", this.doctrineModelField.getRelationType()), true);
    }

    if(this.doctrineModelField.getRelation() != null) {
        presentation.setTypeText(this.doctrineModelField.getRelation());
        presentation.setIcon(PhpIcons.CLASS_ICON);
    }

}
 
Example 4
Source File: FormClassConstantsLookupElement.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void renderElement(LookupElementPresentation presentation) {

    // provides parent and string alias name
    List<String> tailsText = new ArrayList<>();

    String getName = PhpElementsUtil.getMethodReturnAsString(phpClass, "getName");
    if(getName != null) {
        tailsText.add(getName);
    }

    // @TODO: getParent should
    String getParent = PhpElementsUtil.getMethodReturnAsString(phpClass, "getParent");
    if(getParent != null && !getParent.equals("form")) {
        tailsText.add(getParent);
    }

    if(tailsText.size() > 0) {
        presentation.setTailText("(" + StringUtils.join(tailsText, ",") + ")", true);
    }

    presentation.setIcon(Symfony2Icons.FORM_TYPE);

    super.renderElement(presentation);
}
 
Example 5
Source File: RouteLookupElement.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * "(GET|POST, var1, var2)"
 */
private void formatTail(@NotNull LookupElementPresentation presentation) {
    List<String> tails = new ArrayList<>();

    Collection<String> methods = route.getMethods();
    if(methods.size() > 0) {
        tails.add(StringUtils.join(ContainerUtil.map(methods, String::toUpperCase), "|"));
    }

    Set<String> variables = this.route.getVariables();
    if(variables.size() > 0) {
        tails.addAll(variables);
    }

    if(tails.size() > 0) {
        presentation.setTailText("(" + StringUtils.join(tails, ", ") + ")", true);
    }
}
 
Example 6
Source File: LiveTemplateLookupElement.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void renderElement(LookupElementPresentation presentation) {
  super.renderElement(presentation);
  char shortcut = getTemplateShortcut();
  presentation.setItemText(getItemText());
  if (sudden) {
    presentation.setItemTextBold(true);
    if (!presentation.isReal() || !((RealLookupElementPresentation)presentation).isLookupSelectionTouched()) {
      if (shortcut == TemplateSettings.DEFAULT_CHAR) {
        shortcut = TemplateSettings.getInstance().getDefaultShortcutChar();
      }
      presentation.setTypeText("  [" + KeyEvent.getKeyText(shortcut) + "] ");
    }
    if (StringUtil.isNotEmpty(myDescription)) {
      presentation.setTailText(" (" + myDescription + ")", true);
    }
  }
  else {
    presentation.setTypeText(myDescription);
  }
}
 
Example 7
Source File: MethodChainLookupElementTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void renderElement() {
  LookupElement testDelegate = new TestLookupElement("");
  Template testTemplate = new TestTemplate("beforeDot.afterDot.afterDot");
  LookupElementPresentation testPresentation = new TestLookupElementPresentation();
  testPresentation.setTailText("oldTail");

  new MethodChainLookupElement(testDelegate, testTemplate).renderElement(testPresentation);
  assertEquals("oldTail.afterDot.afterDot", testPresentation.getTailText());
}
 
Example 8
Source File: Suggestion.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
public void renderElement(LookupElement element, LookupElementPresentation presentation) {
  Suggestion suggestion = (Suggestion) element.getObject();
  if (suggestion.icon != null) {
    presentation.setIcon(suggestion.icon);
  }

  presentation.setStrikeout(suggestion.deprecationLevel != null);
  if (suggestion.deprecationLevel != null) {
    if (suggestion.deprecationLevel == SpringConfigurationMetadataDeprecationLevel.error) {
      presentation.setItemTextForeground(RED);
    } else {
      presentation.setItemTextForeground(YELLOW);
    }
  }

  String lookupString = element.getLookupString();
  presentation.setItemText(lookupString);
  if (!lookupString.equals(suggestion.suggestionToDisplay)) {
    presentation.setItemTextBold(true);
  }

  String shortDescription;
  if (suggestion.defaultValue != null) {
    shortDescription = shortenTextWithEllipsis(suggestion.defaultValue, 60, 0, true);
    TextAttributes attrs =
        EditorColorsManager.getInstance().getGlobalScheme().getAttributes(SCALAR_TEXT);
    presentation.setTailText("=" + shortDescription, attrs.getForegroundColor());
  }

  if (suggestion.description != null) {
    presentation
        .appendTailText(" (" + getFirstSentenceWithoutDot(suggestion.description) + ")",
            true);
  }

  if (suggestion.shortType != null) {
    presentation.setTypeText(suggestion.shortType);
  }
}
 
Example 9
Source File: TranslationLookupElement.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@Override
public void renderElement(LookupElementPresentation presentation) {
    presentation.setItemText(translation.getIndex() + "  ");
    presentation.setTailText(getLookupString(), true);
    presentation.setIcon(TYPO3CMSIcons.TYPO3_ICON);
    presentation.setTypeText("EXT:" + translation.getExtension());
    presentation.setTypeGrayed(true);
}
 
Example 10
Source File: BuildLookupElement.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void renderElement(LookupElementPresentation presentation) {
  presentation.setItemText(getItemText());
  presentation.setTailText(getTailText());
  presentation.setTypeText(getTypeText());
  presentation.setIcon(getIcon());
}
 
Example 11
Source File: HaxeLookupElement.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public void renderElement(LookupElementPresentation presentation) {
  final ItemPresentation myComponentNamePresentation = myComponentName.getPresentation();
  if (myComponentNamePresentation == null) {
    presentation.setItemText(getLookupString());
    return;
  }

  String presentableText = myComponentNamePresentation.getPresentableText();

  // Check for members: methods and fields
  HaxeBaseMemberModel model = HaxeBaseMemberModel.fromPsi(myComponentName);

  if (model != null) {
    // TODO: Specialization support required
    presentableText = model.getPresentableText(context);

    // Check deprecated modifiers
    if (model instanceof HaxeMemberModel && ((HaxeMemberModel)model).getModifiers().hasModifier(HaxePsiModifier.DEPRECATED)) {
      presentation.setStrikeout(true);
    }

    // Check for non-inherited members to highlight them as intellij-java does
    // @TODO: Self members should be displayed first!
    if (leftReference != null) {
      if (model.getDeclaringClass().getPsi() == leftReference.getHaxeClass()) {
        presentation.setItemTextBold(true);
      }
    }
  }

  presentation.setItemText(presentableText);
  presentation.setIcon(myComponentNamePresentation.getIcon(true));
  final String pkg = myComponentNamePresentation.getLocationString();
  if (StringUtil.isNotEmpty(pkg)) {
    presentation.setTailText(" " + pkg, true);
  }
}
 
Example 12
Source File: TwigExtensionLookupElement.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void buildTailText(@NotNull LookupElementPresentation presentation) {
    if(this.twigExtension.getTwigExtensionType() == TwigExtensionParser.TwigExtensionType.SIMPLE_TEST) {
        return;
    }

    String signature = this.twigExtension.getSignature();
    if(signature == null) {
        return;
    }

    Collection<? extends PhpNamedElement> phpNamedElements = PhpIndex.getInstance(this.project).getBySignature(signature);
    if(phpNamedElements.size() == 0) {
        return;
    }

    PhpNamedElement function = phpNamedElements.iterator().next();
    if(function instanceof Function) {
        List<Parameter> parameters = new LinkedList<>(Arrays.asList(((Function) function).getParameters()));

        if(this.twigExtension.getOption("needs_context") != null && parameters.size() > 0) {
            parameters.remove(0);
        }

        if(this.twigExtension.getOption("needs_environment") != null && parameters.size() > 0) {
            parameters.remove(0);
        }

        presentation.setTailText(PhpPresentationUtil.formatParameters(null, parameters.toArray(new Parameter[parameters.size()])).toString(), true);
    }
}
 
Example 13
Source File: NewFileLookupElement.java    From yiistorm with MIT License 5 votes vote down vote up
public void renderElement(LookupElementPresentation presentation) {
    presentation.setItemText(this.lookupString);
    presentation.setIcon(PlatformIcons.ADD_ICON);
    presentation.setTypeText(createTitle);
    presentation.setTailText(".php");
    presentation.setTypeGrayed(false);
}
 
Example 14
Source File: NewArrayValueLookupElement.java    From yiistorm with MIT License 5 votes vote down vote up
public void renderElement(LookupElementPresentation presentation) {
    presentation.setItemText(insertString);
    presentation.setIcon(PlatformIcons.ADD_ICON);
    presentation.setTypeText(createTitle);
    presentation.setTailText(".php");
    presentation.setTypeGrayed(false);
}
 
Example 15
Source File: FilePathCompletionContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void renderElement(LookupElementPresentation presentation) {
  final String relativePath = getRelativePath();

  final StringBuilder sb = new StringBuilder();
  if (myInfo != null) {
    sb.append(" (").append(myInfo);
  }

  if (relativePath != null && !relativePath.equals(myName)) {
    if (myInfo != null) {
      sb.append(", ");
    }
    else {
      sb.append(" (");
    }

    sb.append(relativePath);
  }

  if (sb.length() > 0) {
    sb.append(')');
  }

  presentation.setItemText(myName);

  if (sb.length() > 0) {
    presentation.setTailText(sb.toString(), true);
  }

  presentation.setIcon(myIcon);
}
 
Example 16
Source File: PostfixTemplateLookupElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void renderElement(LookupElementPresentation presentation) {
  super.renderElement(presentation);
  if (sudden) {
    presentation.setTailText(" " + UIUtil.rightArrow() + " " + myTemplate.getExample());
  }
  else {
    presentation.setTypeText(myTemplate.getExample());
    presentation.setTypeGrayed(true);
  }
}