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


Java LookupElement.as方法代碼示例

本文整理匯總了Java中com.intellij.codeInsight.lookup.LookupElement.as方法的典型用法代碼示例。如果您正苦於以下問題:Java LookupElement.as方法的具體用法?Java LookupElement.as怎麽用?Java LookupElement.as使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.codeInsight.lookup.LookupElement的用法示例。


在下文中一共展示了LookupElement.as方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fillActions

import com.intellij.codeInsight.lookup.LookupElement; //導入方法依賴的package包/類
@Override
public void fillActions(final LookupElement element, Lookup lookup, Consumer<LookupElementAction> consumer) {
  final StaticallyImportable item = element.as(StaticallyImportable.CLASS_CONDITION_KEY);
  if (item == null || !item.canBeImported()) {
    return;
  }

  final Icon checkIcon = PlatformIcons.CHECK_ICON;
  final Icon icon = item.willBeImported() ? checkIcon : new EmptyIcon(checkIcon.getIconWidth(), checkIcon.getIconHeight());
  consumer.consume(new LookupElementAction(icon, "Import statically") {
    @Override
    public Result performLookupAction() {
      item.setShouldBeImported(!item.willBeImported());
      return new Result.ChooseItem(element);
    }
  });
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:18,代碼來源:ImportStaticLookupActionProvider.java

示例2: calculateLookupItems

import com.intellij.codeInsight.lookup.LookupElement; //導入方法依賴的package包/類
@Override
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context) {
  if (params.length != 1) return null;
  LookupElement[] lookupItems = params[0].calculateLookupItems(context);
  if (lookupItems == null) return null;

  List<LookupElement> result = ContainerUtil.newArrayList();
  for (LookupElement element : lookupItems) {
    PsiTypeLookupItem lookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
    if (lookupItem != null) {
      PsiType psiType = lookupItem.getType();
      if (psiType instanceof PsiArrayType) {
        result.add(PsiTypeLookupItem.createLookupItem(((PsiArrayType)psiType).getComponentType(), null));
      }
    }
  }

  return lookupItems;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:ComponentTypeOfMacro.java

示例3: weigh

import com.intellij.codeInsight.lookup.LookupElement; //導入方法依賴的package包/類
@Override
public Double weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) {
  final PrioritizedLookupElement prioritized = element.as(PrioritizedLookupElement.CLASS_CONDITION_KEY);
  if (prioritized != null) {
    return prioritized.getPriority();
  }

  final LookupItem item = element.as(LookupItem.CLASS_CONDITION_KEY);
  if (item != null) {
    return item.getPriority();
  }
  return 0.0;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:14,代碼來源:PriorityWeigher.java

示例4: weigh

import com.intellij.codeInsight.lookup.LookupElement; //導入方法依賴的package包/類
@Override
public Integer weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) {
  final PrioritizedLookupElement prioritized = element.as(PrioritizedLookupElement.CLASS_CONDITION_KEY);
  if (prioritized != null) {
    return prioritized.getGrouping();
  }

  return 0;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:10,代碼來源:GroupingWeigher.java

示例5: serialize

import com.intellij.codeInsight.lookup.LookupElement; //導入方法依賴的package包/類
@Override
public StatisticsInfo serialize(final LookupElement element, final CompletionLocation location) {
  Object o = element.getObject();

  if (o instanceof PsiLocalVariable || o instanceof PsiParameter || o instanceof PsiThisExpression || o instanceof PsiKeyword) {
    return StatisticsInfo.EMPTY;
  }

  PsiElement position = location.getCompletionParameters().getPosition();
  if (SUPER_CALL.accepts(position) || ReferenceExpressionCompletionContributor.IN_SWITCH_LABEL.accepts(position)) {
    return StatisticsInfo.EMPTY;
  }

  LookupItem item = element.as(LookupItem.CLASS_CONDITION_KEY);
  if (item == null) return null;

  PsiType qualifierType = JavaCompletionUtil.getQualifierType(item);

  if (o instanceof PsiMember) {
    final ExpectedTypeInfo[] infos = JavaCompletionUtil.EXPECTED_TYPES.getValue(location);
    final ExpectedTypeInfo firstInfo = infos != null && infos.length > 0 ? infos[0] : null;
    String key2 = JavaStatisticsManager.getMemberUseKey2((PsiMember)o);
    if (o instanceof PsiClass) {
      PsiType expectedType = firstInfo != null ? firstInfo.getDefaultType() : null;
      return new StatisticsInfo(JavaStatisticsManager.getAfterNewKey(expectedType), key2);
    }

    PsiClass containingClass = ((PsiMember)o).getContainingClass();
    if (containingClass != null) {
      String expectedName = firstInfo instanceof ExpectedTypeInfoImpl ? ((ExpectedTypeInfoImpl)firstInfo).getExpectedName() : null;
      String contextPrefix = expectedName == null ? "" : "expectedName=" + expectedName + "###";
      String context = contextPrefix + JavaStatisticsManager.getMemberUseKey2(containingClass);

      if (o instanceof PsiMethod) {
        String memberValue = JavaStatisticsManager.getMemberUseKey2(RecursionWeigher.findDeepestSuper((PsiMethod)o));

        List<StatisticsInfo> superMethodInfos = ContainerUtil.newArrayList(new StatisticsInfo(contextPrefix + context, memberValue));
        for (PsiClass superClass : InheritanceUtil.getSuperClasses(containingClass)) {
          superMethodInfos.add(new StatisticsInfo(contextPrefix + JavaStatisticsManager.getMemberUseKey2(superClass), memberValue));
        }
        return StatisticsInfo.createComposite(superMethodInfos);
      }

      return new StatisticsInfo(context, key2);
    }
  }

  if (qualifierType != null) return StatisticsInfo.EMPTY;

  return null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:52,代碼來源:JavaCompletionStatistician.java

示例6: completeFinalReference

import com.intellij.codeInsight.lookup.LookupElement; //導入方法依賴的package包/類
private static Set<LookupElement> completeFinalReference(final PsiElement element, PsiJavaCodeReferenceElement reference, ElementFilter filter,
                                                         final JavaSmartCompletionParameters parameters) {
  final Set<PsiField> used = parameters.getParameters().getInvocationCount() < 2 ? findConstantsUsedInSwitch(element) : Collections.<PsiField>emptySet();

  final Set<LookupElement> elements =
    JavaSmartCompletionContributor.completeReference(element, reference, new AndFilter(filter, new ElementFilter() {
      @Override
      public boolean isAcceptable(Object o, PsiElement context) {
        if (o instanceof CandidateInfo) {
          final CandidateInfo info = (CandidateInfo)o;
          final PsiElement member = info.getElement();

          final PsiType expectedType = parameters.getExpectedType();
          if (expectedType.equals(PsiType.VOID)) {
            return member instanceof PsiMethod;
          }

          //noinspection SuspiciousMethodCalls
          if (member instanceof PsiEnumConstant && used.contains(CompletionUtil.getOriginalOrSelf(member))) {
            return false;
          }

          return AssignableFromFilter.isAcceptable(member, element, expectedType, info.getSubstitutor());
        }
        return false;
      }

      @Override
      public boolean isClassAcceptable(Class hintClass) {
        return true;
      }
    }), false, true, parameters.getParameters(), PrefixMatcher.ALWAYS_TRUE);
  for (LookupElement lookupElement : elements) {
    if (lookupElement.getObject() instanceof PsiMethod) {
      final JavaMethodCallElement item = lookupElement.as(JavaMethodCallElement.CLASS_CONDITION_KEY);
      if (item != null) {
        final PsiMethod method = (PsiMethod)lookupElement.getObject();
        if (SmartCompletionDecorator.hasUnboundTypeParams(method, parameters.getExpectedType())) {
          item.setInferenceSubstitutor(SmartCompletionDecorator.calculateMethodReturnTypeSubstitutor(method, parameters.getExpectedType()), element);
        }
      }
    }
  }

  return elements;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:47,代碼來源:ReferenceExpressionCompletionContributor.java

示例7: withPriority

import com.intellij.codeInsight.lookup.LookupElement; //導入方法依賴的package包/類
public static LookupElement withPriority(LookupElement element, double priority) {
  final PrioritizedLookupElement prioritized = element.as(CLASS_CONDITION_KEY);
  return new PrioritizedLookupElement<LookupElement>(element, priority, prioritized == null ? 0 : prioritized.getGrouping());
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:5,代碼來源:PrioritizedLookupElement.java

示例8: withGrouping

import com.intellij.codeInsight.lookup.LookupElement; //導入方法依賴的package包/類
public static LookupElement withGrouping(LookupElement element, int grouping) {
  final PrioritizedLookupElement prioritized = element.as(CLASS_CONDITION_KEY);
  return new PrioritizedLookupElement<LookupElement>(element, prioritized == null ? 0 : prioritized.getPriority(), grouping);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:5,代碼來源:PrioritizedLookupElement.java

示例9: withExplicitProximity

import com.intellij.codeInsight.lookup.LookupElement; //導入方法依賴的package包/類
public static LookupElement withExplicitProximity(LookupElement element, int explicitProximity) {
  final PrioritizedLookupElement prioritized = element.as(CLASS_CONDITION_KEY);
  double priority = prioritized == null ? 0 : prioritized.getPriority();
  int grouping = prioritized == null ? 0 : prioritized.getGrouping();
  return new PrioritizedLookupElement<LookupElement>(element, priority, grouping, explicitProximity);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:7,代碼來源:PrioritizedLookupElement.java

示例10: weigh

import com.intellij.codeInsight.lookup.LookupElement; //導入方法依賴的package包/類
@Override
public Integer weigh(@NotNull final LookupElement item, @NotNull final CompletionLocation location) {
  PrioritizedLookupElement prioritized = item.as(PrioritizedLookupElement.CLASS_CONDITION_KEY);
  return prioritized != null ? prioritized.getExplicitProximity() : 0;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:6,代碼來源:ExplicitProximityWeigher.java

示例11: weigh

import com.intellij.codeInsight.lookup.LookupElement; //導入方法依賴的package包/類
@Override
public Comparable weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) {
  final PsiElement position = location.getCompletionParameters().getPosition();
  if (!(position.getContainingFile() instanceof GroovyFileBase)) return null;

  Object o = element.getObject();
  if (o instanceof ResolveResult) {
    o = ((ResolveResult)o).getElement();
  }

  final PsiElement parent = position.getParent();
  final PsiElement qualifier = parent instanceof GrReferenceElement ? ((GrReferenceElement)parent).getQualifier() : null;
  if (qualifier == null) {
    if (o instanceof NamedArgumentDescriptor) {
      switch (((NamedArgumentDescriptor)o).getPriority()) {
        case ALWAYS_ON_TOP:
          return NotQualifiedKind.onTop;
        case AS_LOCAL_VARIABLE:
          return NotQualifiedKind.local;
        default:
          return NotQualifiedKind.unknown;
      }
    }
    if (o instanceof PsiVariable && !(o instanceof PsiField)) {
      return NotQualifiedKind.local;
    }

    PsiTypeLookupItem item = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
    if (item != null && item.getBracketsCount() > 0) {
      return NotQualifiedKind.arrayType;
    }

    if (isPriorityKeyword(o)) return NotQualifiedKind.local;
    if (isLightElement(o)) return NotQualifiedKind.unknown;
    if (o instanceof PsiClass) {
      if (((PsiClass)o).isAnnotationType() && GrMainCompletionProvider.AFTER_AT.accepts(position)) {
        final GrAnnotation annotation = PsiTreeUtil.getParentOfType(position, GrAnnotation.class);
        if (annotation != null) {
          PsiElement annoParent = annotation.getParent();
          PsiElement ownerToUse = annoParent instanceof PsiModifierList ? annoParent.getParent() : annoParent;
          PsiAnnotation.TargetType[] elementTypeFields = GrAnnotationImpl.getApplicableElementTypeFields(ownerToUse);
          if (PsiImplUtil.findApplicableTarget((PsiClass)o, elementTypeFields) != null) {
            return NotQualifiedKind.restrictedClass;
          }
        }
      }
      if (GrMainCompletionProvider.IN_CATCH_TYPE.accepts(position) &&
          InheritanceUtil.isInheritor((PsiClass)o, CommonClassNames.JAVA_LANG_THROWABLE)) {
        return NotQualifiedKind.restrictedClass;
      }
    }
    if (o instanceof PsiMember) {
      final PsiClass containingClass = ((PsiMember)o).getContainingClass();
      if (isAccessor((PsiMember)o)) return NotQualifiedKind.accessor;
      if (o instanceof PsiClass && ((PsiClass)o).getContainingClass() == null || o instanceof PsiPackage) return NotQualifiedKind.unknown;
      if (o instanceof PsiClass) return NotQualifiedKind.innerClass;
      if (PsiTreeUtil.isContextAncestor(containingClass, position, false)) return NotQualifiedKind.currentClassMember;
      return NotQualifiedKind.member;
    }
    return NotQualifiedKind.unknown;
  }
  else {
    if (o instanceof PsiEnumConstant) return QualifiedKind.enumConstant;

    if (isLightElement(o)) return QualifiedKind.unknown;
    if (o instanceof PsiMember) {
      if (isTrashMethod((PsiMember)o)) return QualifiedKind.unknown;
      if (isAccessor((PsiMember)o)) return QualifiedKind.accessor;
      if (isQualifierClassMember((PsiMember)o, qualifier)) {
        return QualifiedKind.currentClassMember;
      }
      if (o instanceof PsiClass && ((PsiClass)o).getContainingClass() == null || o instanceof PsiPackage) return QualifiedKind.unknown;
      if (o instanceof PsiClass) return QualifiedKind.innerClass;
      return QualifiedKind.member;
    }
    return QualifiedKind.unknown;
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:79,代碼來源:GrKindWeigher.java


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