本文整理汇总了Java中com.intellij.codeInsight.lookup.LookupElement.getLookupString方法的典型用法代码示例。如果您正苦于以下问题:Java LookupElement.getLookupString方法的具体用法?Java LookupElement.getLookupString怎么用?Java LookupElement.getLookupString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.lookup.LookupElement
的用法示例。
在下文中一共展示了LookupElement.getLookupString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: weigh
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Override
public Comparable weigh(@NotNull final LookupElement element, @NotNull final CompletionLocation location) {
if (!PsiUtilCore.findLanguageFromElement(location.getCompletionParameters().getPosition()).isKindOf(PythonLanguage.getInstance())) {
return 0;
}
final String name = element.getLookupString();
final LookupElementPresentation presentation = LookupElementPresentation.renderElement(element);
// move dict keys to the top
if ("dict key".equals(presentation.getTypeText())) {
return element.getLookupString().length();
}
if (name.startsWith(DOUBLE_UNDER)) {
if (name.endsWith(DOUBLE_UNDER)) return -10; // __foo__ is lowest
else return -5; // __foo is lower than normal
}
return 0; // default
}
示例2: doTestTagNameIcons
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
private void doTestTagNameIcons(String fileName) throws IOException {
VirtualFile file = copyFileToProject(fileName);
myFixture.configureFromExistingVirtualFile(file);
final LookupElement[] elements = myFixture.complete(CompletionType.BASIC);
final Set<String> elementsToCheck = new HashSet<String>(Arrays.asList(
"view", "include", "requestFocus", "fragment", "Button"));
for (LookupElement element : elements) {
final String s = element.getLookupString();
final Object obj = element.getObject();
if (elementsToCheck.contains(s)) {
LookupElementPresentation presentation = new LookupElementPresentation();
element.renderElement(presentation);
assertNotNull("no icon for element: " + element, presentation.getIcon());
if ("Button".equals(s)) {
assertInstanceOf(obj, PsiClass.class);
}
}
}
}
示例3: renderElement
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
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.suggestion)) {
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(
" (" + Util.getFirstSentenceWithoutDot(suggestion.description) + ")", true);
}
if (suggestion.shortType != null) {
presentation.setTypeText(suggestion.shortType);
}
}
示例4: compare
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Override
public int compare(LookupElement lookupItem1, LookupElement lookupItem2) {
String s1 = lookupItem1.getLookupString();
String s2 = lookupItem2.getLookupString();
int diff1 = 0;
for (int i = 0; i < Math.min(s1.length(), myOldReferenceName.length()); i++) {
if (s1.charAt(i) != myOldReferenceName.charAt(i)) diff1++;
}
int diff2 = 0;
for (int i = 0; i < Math.min(s2.length(), myOldReferenceName.length()); i++) {
if (s2.charAt(i) != myOldReferenceName.charAt(i)) diff2++;
}
return diff1 - diff2;
}
示例5: emulateInsertion
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
public static void emulateInsertion(LookupElement item, int offset, InsertionContext context) {
setOffsets(context, offset, offset);
final Editor editor = context.getEditor();
final Document document = editor.getDocument();
final String lookupString = item.getLookupString();
document.insertString(offset, lookupString);
editor.getCaretModel().moveToOffset(context.getTailOffset());
PsiDocumentManager.getInstance(context.getProject()).commitDocument(document);
item.handleInsert(context);
PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(document);
}
示例6: getLookupElementWeights
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
public static List<String> getLookupElementWeights(LookupImpl lookup) {
final Map<LookupElement,StringBuilder> strings = lookup.getRelevanceStrings();
List<String> sb = new ArrayList<String>();
for (LookupElement item : lookup.getItems()) {
StringBuilder builder = strings.get(item);
String weight = builder == null ? "null" : builder.toString();
final String s = item.getLookupString() + "\t" + weight;
sb.add(s);
}
return sb;
}
示例7: checkCompletionContains
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
public static void checkCompletionContains(JavaCodeInsightTestFixture fixture, String ... expectedVariants) {
LookupElement[] lookupElements = fixture.completeBasic();
Assert.assertNotNull(lookupElements);
Set<String> missedVariants = ContainerUtil.newHashSet(expectedVariants);
for (LookupElement lookupElement : lookupElements) {
String lookupString = lookupElement.getLookupString();
missedVariants.remove(lookupString);
Object object = lookupElement.getObject();
if (object instanceof ResolveResult) {
object = ((ResolveResult)object).getElement();
}
if (object instanceof PsiMethod) {
missedVariants.remove(lookupString + "()");
}
else if (object instanceof PsiVariable) {
missedVariants.remove('@' + lookupString);
}
else if (object instanceof NamedArgumentDescriptor) {
missedVariants.remove(lookupString + ':');
}
}
if (missedVariants.size() > 0) {
Assert.assertTrue("Some completion variants are missed " + missedVariants, false);
}
}
示例8: serialize
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Override
public StatisticsInfo serialize(final LookupElement element, final CompletionLocation location) {
return new StatisticsInfo("completion#" + location.getCompletionParameters().getOriginalFile().getLanguage(), element.getLookupString());
}
示例9: handleInsert
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context, LookupElement item) {
String s = item.getLookupString();
int idx = s.indexOf(':');
String groupId = s.substring(0, idx);
String artifactId = s.substring(idx + 1);
int startOffset = context.getStartOffset();
PsiFile psiFile = context.getFile();
DomFileElement<MavenDomProjectModel> domModel = DomManager.getDomManager(context.getProject()).getFileElement((XmlFile)psiFile, MavenDomProjectModel.class);
if (domModel == null) return;
boolean shouldInvokeCompletion = false;
MavenDomDependency managedDependency = MavenDependencyCompletionUtil.findManagedDependency(domModel.getRootElement(),
context.getProject(), groupId, artifactId);
if (managedDependency == null) {
String value = "<groupId>" + groupId + "</groupId>\n" +
"<artifactId>" + artifactId + "</artifactId>\n" +
"<version></version>";
context.getDocument().replaceString(startOffset, context.getSelectionEndOffset(), value);
context.getEditor().getCaretModel().moveToOffset(startOffset + value.length() - 10);
shouldInvokeCompletion = true;
}
else {
StringBuilder sb = new StringBuilder();
sb.append("<groupId>").append(groupId).append("</groupId>\n")
.append("<artifactId>").append(artifactId).append("</artifactId>\n");
String type = managedDependency.getType().getRawText();
if (type != null && !type.equals("jar")) {
sb.append("<type>").append(type).append("</type>\n");
}
String classifier = managedDependency.getClassifier().getRawText();
if (StringUtil.isNotEmpty(classifier)) {
sb.append("<classifier>").append(classifier).append("</classifier>\n");
}
context.getDocument().replaceString(startOffset, context.getSelectionEndOffset(), sb);
}
context.commitDocument();
PsiElement e = psiFile.findElementAt(startOffset);
while (e != null && (!(e instanceof XmlTag) || !"dependency".equals(((XmlTag)e).getName()))) {
e = e.getParent();
}
if (e != null) {
new ReformatCodeProcessor(psiFile.getProject(), psiFile, e.getTextRange(), false).run();
}
if (shouldInvokeCompletion) {
MavenDependencyCompletionUtil.invokeCompletion(context, CompletionType.BASIC);
}
}
示例10: handleInsert
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context, LookupElement item) {
if (TemplateManager.getInstance(context.getProject()).getActiveTemplate(context.getEditor()) != null) {
return; // Don't brake the template.
}
context.commitDocument();
XmlFile xmlFile = (XmlFile)context.getFile();
PsiElement element = xmlFile.findElementAt(context.getStartOffset());
XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
if (tag == null) return;
XmlTag dependencyTag = tag.getParentTag();
DomElement domElement = DomManager.getDomManager(context.getProject()).getDomElement(dependencyTag);
if (!(domElement instanceof MavenDomDependency)) return;
MavenDomDependency dependency = (MavenDomDependency)domElement;
String artifactId = item.getLookupString();
String groupId = dependency.getGroupId().getStringValue();
if (StringUtil.isEmpty(groupId)) {
String g = getUniqueGroupIdOrNull(context.getProject(), artifactId);
if (g != null) {
dependency.getGroupId().setStringValue(g);
groupId = g;
}
else {
if (groupId == null) {
dependency.getGroupId().setStringValue("");
}
XmlTag groupIdTag = dependency.getGroupId().getXmlTag();
context.getEditor().getCaretModel().moveToOffset(groupIdTag.getValue().getTextRange().getStartOffset());
MavenDependencyCompletionUtil.invokeCompletion(context, CompletionType.SMART);
return;
}
}
MavenDependencyCompletionUtil.addTypeAndClassifierAndVersion(context, dependency, groupId, artifactId);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:47,代码来源:MavenArtifactCoordinatesArtifactIdConverter.java
示例11: doTest
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
protected void doTest(String directory) {
CamelHumpMatcher.forceStartMatching(getTestRootDisposable());
final List<String> stringList = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test");
if (directory.length()!=0) directory += "/";
final String fileName = directory + getTestName(true) + "." + getExtension();
myFixture.addFileToProject(fileName, stringList.get(0));
myFixture.configureByFile(fileName);
boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX;
CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX = false;
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false;
String result = "";
try {
myFixture.completeBasic();
final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myFixture.getEditor());
if (lookup != null) {
List<LookupElement> items = lookup.getItems();
if (!addReferenceVariants()) {
items = ContainerUtil.findAll(items, new Condition<LookupElement>() {
@Override
public boolean value(LookupElement lookupElement) {
final Object o = lookupElement.getObject();
return !(o instanceof PsiMember) && !(o instanceof GrVariable) && !(o instanceof GroovyResolveResult) && !(o instanceof PsiPackage);
}
});
}
Collections.sort(items, new Comparator<LookupElement>() {
@Override
public int compare(LookupElement o1, LookupElement o2) {
return o1.getLookupString().compareTo(o2.getLookupString());
}
});
result = "";
for (LookupElement item : items) {
result = result + "\n" + item.getLookupString();
}
result = result.trim();
LookupManager.getInstance(myFixture.getProject()).hideActiveLookup();
}
}
finally {
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = true;
CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX = old;
}
assertEquals(StringUtil.trimEnd(stringList.get(1), "\n"), result);
}