本文整理汇总了Java中com.intellij.codeInsight.lookup.LookupElement.getObject方法的典型用法代码示例。如果您正苦于以下问题:Java LookupElement.getObject方法的具体用法?Java LookupElement.getObject怎么用?Java LookupElement.getObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.lookup.LookupElement
的用法示例。
在下文中一共展示了LookupElement.getObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleInsert
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
final Editor editor = context.getEditor();
final Document document = editor.getDocument();
if (context.getCompletionChar() == '(') {
context.setAddCompletionChar(false);
final int offset = context.getTailOffset();
document.insertString(offset, "()");
PyClass pyClass = (PyClass) item.getObject();
PyFunction init = pyClass.findInitOrNew(true, null);
if (init != null && PyFunctionInsertHandler.hasParams(context, init)) {
editor.getCaretModel().moveToOffset(offset+1);
AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), init);
}
else {
editor.getCaretModel().moveToOffset(offset+2);
}
}
}
示例2: createMockReference
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Nullable
public static PsiReferenceExpression createMockReference(final PsiElement place, @NotNull PsiType qualifierType, LookupElement qualifierItem) {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getProject());
if (qualifierItem.getObject() instanceof PsiClass) {
final String qname = ((PsiClass)qualifierItem.getObject()).getQualifiedName();
if (qname == null) return null;
final String text = qname + ".xxx";
try {
final PsiExpression expr = factory.createExpressionFromText(text, place);
if (expr instanceof PsiReferenceExpression) {
return (PsiReferenceExpression)expr;
}
return null; // ignore ill-formed qualified names like "org.spark-project.jetty" that can't be used from Java code anyway
}
catch (IncorrectOperationException e) {
LOG.info(e);
return null;
}
}
return (PsiReferenceExpression) factory.createExpressionFromText("xxx.xxx", JavaCompletionUtil
.createContextWithXxxVariable(place, qualifierType));
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ReferenceExpressionCompletionContributor.java
示例3: handleInsert
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
final Object object = item.getObject();
if (object instanceof PsiMethod) {
final PsiElement newElement = PsiUtilCore.getElementAtOffset(context.getFile(), context.getStartOffset());
final int start = newElement.getTextRange().getEndOffset();
final PsiElement params = newElement.getParent().getParent();
final int end = params.getTextRange().getEndOffset() - 1;
final String types = getMethodTypes((PsiMethod)object);
context.getDocument().replaceString(start, end, types);
context.commitDocument();
final PsiElement firstParam = PsiUtilCore.getElementAtOffset(context.getFile(), context.getStartOffset());
final PsiMethodCallExpression methodCall = PsiTreeUtil.getParentOfType(firstParam, PsiMethodCallExpression.class);
if (methodCall != null) {
JavaCodeStyleManager.getInstance(context.getProject()).shortenClassReferences(methodCall);
}
}
}
示例4: weigh
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Override
public Integer weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) {
if (!(location.getCompletionParameters().getPosition().getContainingFile() instanceof GroovyFileBase)) {
return null;
}
Object o = element.getObject();
if (o instanceof ResolveResult) {
o = ((ResolveResult)o).getElement();
}
if (o instanceof PsiMethod &&
(GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)o) || "setProperty".equals(((PsiMethod)o).getName()))) {
return 1;
}
return 0;
}
示例5: 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);
}
}
示例6: weigh
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Override
public Integer weigh(@NotNull final LookupElement element, @NotNull final CompletionLocation location) {
final Object lookupObject = element.getObject();
CommandParameter parameter = null;
boolean opt = false;
if (lookupObject instanceof CommandParameter) {
parameter = (CommandParameter) lookupObject;
opt = parameter.isOptional();
}
return parameter != null && opt ? -10 : 0;
}
示例7: fillCompletionVariants
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Override
public void fillCompletionVariants(@NotNull final CompletionParameters parameters, @NotNull final CompletionResultSet result) {
final InheritorsHolder holder = new InheritorsHolder(result);
ResultTracker tracker = new ResultTracker(result) {
@Override
public void consume(CompletionResult plainResult) {
super.consume(plainResult);
LookupElement element = plainResult.getLookupElement();
Object o = element.getObject();
if (o instanceof PsiClass) {
holder.registerClass((PsiClass)o);
}
if (element instanceof TypeArgumentCompletionProvider.TypeArgsLookupElement) {
((TypeArgumentCompletionProvider.TypeArgsLookupElement)element).registerSingleClass(holder);
}
}
};
result.runRemainingContributors(parameters, tracker);
final boolean empty = tracker.containsOnlyPackages || suggestAllAnnotations(parameters);
if (!empty && parameters.getInvocationCount() == 0) {
result.restartCompletionWhenNothingMatches();
}
if (empty) {
delegate(parameters, JavaCompletionSorting.addJavaSorting(parameters, result), holder);
} else if (Registry.is("ide.completion.show.better.matching.classes")) {
if (parameters.getCompletionType() == CompletionType.BASIC &&
parameters.getInvocationCount() <= 1 &&
JavaCompletionContributor.mayStartClassName(result) &&
JavaCompletionContributor.isClassNamePossible(parameters) &&
!JavaSmartCompletionContributor.AFTER_NEW.accepts(parameters.getPosition())) {
suggestNonImportedClasses(parameters, JavaCompletionSorting.addJavaSorting(parameters, result.withPrefixMatcher(tracker.betterMatcher)), holder);
}
}
}
示例8: consume
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Override
public void consume(LookupElement lookupElement) {
final Object object = lookupElement.getObject();
if (object instanceof PsiClass) {
registerClass((PsiClass)object);
}
myResult.addElement(AutoCompletionPolicy.NEVER_AUTOCOMPLETE.applyPolicy(lookupElement));
}
示例9: insertingAnnotation
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
private static boolean insertingAnnotation(InsertionContext context, LookupElement item) {
final Object obj = item.getObject();
if (!(obj instanceof PsiClass) || !((PsiClass)obj).isAnnotationType()) return false;
PsiElement leaf = context.getFile().findElementAt(context.getStartOffset());
return psiElement(PsiIdentifier.class).withParents(PsiJavaCodeReferenceElement.class, PsiAnnotation.class).accepts(leaf);
}
示例10: 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);
}
}
示例11: handleInsert
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
context.getDocument().deleteString(context.getStartOffset(), context.getTailOffset());
PsiMethod method = (PsiMethod)item.getObject();
List<PsiMethod> prototypes = OverrideImplementUtil.overrideOrImplementMethod(myPsiClass, method, false);
context.commitDocument();
GenerateMembersUtil.insertMembersAtOffset(context.getFile(), context.getStartOffset(),
OverrideImplementUtil.convert2GenerationInfos(prototypes));
}
示例12: getTargetElement
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Nullable
public static PsiElement getTargetElement(LookupElement lookupElement) {
PsiElement psiElement = lookupElement.getPsiElement();
if (psiElement != null) {
return getOriginalElement(psiElement);
}
Object object = lookupElement.getObject();
if (object instanceof LookupValueWithPsiElement) {
final PsiElement element = ((LookupValueWithPsiElement)object).getElement();
if (element != null) return getOriginalElement(element);
}
return null;
}
示例13: assignPriority
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
private static int assignPriority(LookupElement lookupElement, PsiType qualifierType) {
Object object = lookupElement.getObject();
PsiSubstitutor substitutor = null;
GroovyResolveResult resolveResult = null;
if (object instanceof GroovyResolveResult) {
resolveResult = (GroovyResolveResult)object;
substitutor = resolveResult.getSubstitutor();
object = ((GroovyResolveResult)object).getElement();
}
// default groovy methods
if (object instanceof GrGdkMethod &&
GroovyCompletionUtil.skipDefGroovyMethod((GrGdkMethod)object, substitutor, qualifierType)) {
return -1;
}
// operator methods
if (object instanceof PsiMethod &&
PsiUtil.OPERATOR_METHOD_NAMES.contains(((PsiMethod)object).getName()) && !checkForIterator((PsiMethod)object)) {
return -3;
}
// accessors if there is no get, set, is prefix
if (object instanceof PsiMethod && GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)object)) {
return -1;
}
// inaccessible elements
if (resolveResult != null && !resolveResult.isAccessible()) {
return -2;
}
return 0;
}
示例14: getVariants
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@NotNull
@Override
public Object[] getVariants() {
final List<Object> variants = Lists.newArrayList();
Collections.addAll(variants, super.getVariants());
PsiFile file = myElement.getContainingFile();
if (file instanceof IpnbPyFragment) {
final IpnbFilePanel panel = ((IpnbPyFragment)file).getFilePanel();
final List<IpnbEditablePanel> panels = panel.getIpnbPanels();
for (IpnbEditablePanel editablePanel : panels) {
if (!(editablePanel instanceof IpnbCodePanel)) continue;
final Editor editor = ((IpnbCodePanel)editablePanel).getEditor();
final IpnbPyFragment psiFile = (IpnbPyFragment)PsiDocumentManager.getInstance(myElement.getProject()).getPsiFile(editor.getDocument());
if (psiFile == null) continue;
final CompletionVariantsProcessor processor = new CompletionVariantsProcessor(myElement);
PyResolveUtil.scopeCrawlUp(processor, psiFile, null, null);
for (LookupElement e : processor.getResultList()) {
final Object o = e.getObject();
if (o instanceof PsiElement) {
final PsiElement original = CompletionUtil.getOriginalElement((PsiElement)o);
if (original == null) {
continue;
}
}
variants.add(e);
}
}
}
return variants.toArray();
}
示例15: acceptChar
import com.intellij.codeInsight.lookup.LookupElement; //导入方法依赖的package包/类
@Override
@Nullable
public Result acceptChar(char c, int prefixLength, Lookup lookup) {
final PsiFile psiFile = lookup.getPsiFile();
if (psiFile != null && !psiFile.getViewProvider().getLanguages().contains(GroovyLanguage.INSTANCE)) return null;
LookupElement item = lookup.getCurrentItem();
if (item == null) return null;
if (Character.isJavaIdentifierPart(c) || c == '\'') {
return Result.ADD_TO_PREFIX;
}
int caret = lookup.getEditor().getCaretModel().getOffset();
if (c == '.' && prefixLength == 0 && !lookup.isSelectionTouched() && caret > 0 &&
lookup.getEditor().getDocument().getCharsSequence().charAt(caret - 1) == '.') {
return Result.HIDE_LOOKUP;
}
if (c == ':') {
PsiFile file = lookup.getPsiFile();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(lookup.getEditor().getDocument());
PsiElement element = file.findElementAt(Math.max(caret - 1, 0));
if (PsiJavaPatterns.psiElement().withParent(
PsiJavaPatterns.psiElement(GrReferenceExpression.class).withParent(
StandardPatterns.or(PsiJavaPatterns.psiElement(GrCaseLabel.class),
PsiJavaPatterns.psiElement(GrConditionalExpression.class)))).accepts(element)) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
if (item.getObject() instanceof NamedArgumentDescriptor &&
(MapArgumentCompletionProvider.IN_ARGUMENT_LIST_OF_CALL.accepts(element) ||
MapArgumentCompletionProvider.IN_LABEL.accepts(element))) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
return Result.HIDE_LOOKUP;
}
if (c == '[' || c == ']' || c == ')' || c == '>') return CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP;
if (c == '<' && item.getObject() instanceof PsiClass) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
if (c == '(' && PsiKeyword.RETURN.equals(item.getLookupString())) {
return Result.HIDE_LOOKUP;
}
return null;
}