當前位置: 首頁>>代碼示例>>Java>>正文


Java LookupElement.getObject方法代碼示例

本文整理匯總了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);
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:PyClassInsertHandler.java

示例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);
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:19,代碼來源:JavaLangClassMemberReference.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:18,代碼來源:GrAccessorWeigher.java

示例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);
  }
}
 
開發者ID:1tontech,項目名稱:intellij-spring-assistant,代碼行數:39,代碼來源:Suggestion.java

示例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;
}
 
開發者ID:ant-druha,項目名稱:AppleScript-IDEA,代碼行數:12,代碼來源:AppleScriptCompletionWeigher.java

示例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);
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:38,代碼來源:JavaNoVariantsDelegator.java

示例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));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:9,代碼來源:InheritorsHolder.java

示例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);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:8,代碼來源:JavaClassNameInsertHandler.java

示例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);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:32,代碼來源:TestUtils.java

示例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));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:10,代碼來源:GroovyMethodOverrideHandler.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:16,代碼來源:CompletionUtil.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:34,代碼來源:GrMainCompletionProvider.java

示例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();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:34,代碼來源:IpnbPyReference.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:47,代碼來源:GroovyReferenceCharFilter.java


注:本文中的com.intellij.codeInsight.lookup.LookupElement.getObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。