当前位置: 首页>>代码示例>>Java>>正文


Java CompletionElement类代码示例

本文整理汇总了Java中com.intellij.codeInsight.completion.scope.CompletionElement的典型用法代码示例。如果您正苦于以下问题:Java CompletionElement类的具体用法?Java CompletionElement怎么用?Java CompletionElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CompletionElement类属于com.intellij.codeInsight.completion.scope包,在下文中一共展示了CompletionElement类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: suggestQualifyingSuperCalls

import com.intellij.codeInsight.completion.scope.CompletionElement; //导入依赖的package包/类
static Set<LookupElement> suggestQualifyingSuperCalls(PsiElement element,
		PsiJavaReference javaReference,
		ElementFilter elementFilter,
		JavaCompletionProcessor.Options options,
		Condition<String> nameCondition)
{
	Set<LookupElement> set = ContainerUtil.newLinkedHashSet();
	for(final String className : getContainingClassNames(element))
	{
		PsiReferenceExpression fakeSuper = JavaCompletionUtil.createReference(className + ".super.rulez", element);
		PsiElement leaf = ObjectUtils.assertNotNull(fakeSuper.getReferenceNameElement());

		JavaCompletionProcessor superProcessor = new JavaCompletionProcessor(leaf, elementFilter, options, nameCondition);
		fakeSuper.processVariants(superProcessor);

		for(CompletionElement completionElement : superProcessor.getResults())
		{
			for(LookupElement item : JavaCompletionUtil.createLookupElements(completionElement, javaReference))
			{
				set.add(withQualifiedSuper(className, item));
			}
		}
	}
	return set;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:26,代码来源:SuperCalls.java

示例2: createLookupElements

import com.intellij.codeInsight.completion.scope.CompletionElement; //导入依赖的package包/类
private static List<? extends LookupElement> createLookupElements(CompletionElement completionElement, PsiJavaReference reference) {
  Object completion = completionElement.getElement();
  assert !(completion instanceof LookupElement);

  if (reference instanceof PsiJavaCodeReferenceElement) {
    if (completion instanceof PsiMethod &&
        ((PsiJavaCodeReferenceElement)reference).getParent() instanceof PsiImportStaticStatement) {
      return Collections.singletonList(JavaLookupElementBuilder.forMethod((PsiMethod)completion, PsiSubstitutor.EMPTY));
    }

    if (completion instanceof PsiClass) {
      return JavaClassNameCompletionContributor.createClassLookupItems((PsiClass)completion,
                                                                       JavaClassNameCompletionContributor.AFTER_NEW.accepts(reference),
                                                                       JavaClassNameInsertHandler.JAVA_CLASS_INSERT_HANDLER,
                                                                       Conditions.<PsiClass>alwaysTrue());
    }
  }
  
  if (reference instanceof PsiMethodReferenceExpression && completion instanceof PsiMethod && ((PsiMethod)completion).isConstructor()) {
    return Collections.singletonList(JavaLookupElementBuilder.forMethod((PsiMethod)completion, "new", PsiSubstitutor.EMPTY, null));
  }

  PsiSubstitutor substitutor = completionElement.getSubstitutor();
  if (substitutor == null) substitutor = PsiSubstitutor.EMPTY;
  if (completion instanceof PsiClass) {
    return Collections.singletonList(JavaClassNameCompletionContributor.createClassLookupItem((PsiClass)completion, true).setSubstitutor(substitutor));
  }
  if (completion instanceof PsiMethod) {
    return Collections.singletonList(new JavaMethodCallElement((PsiMethod)completion).setQualifierSubstitutor(substitutor));
  }
  if (completion instanceof PsiVariable) {
    return Collections.singletonList(new VariableLookupItem((PsiVariable)completion).setSubstitutor(substitutor));
  }

  return Collections.singletonList(LookupItemUtil.objectToLookupItem(completion));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:JavaCompletionUtil.java

示例3: createLookupElements

import com.intellij.codeInsight.completion.scope.CompletionElement; //导入依赖的package包/类
private static List<? extends LookupElement> createLookupElements(CompletionElement completionElement, PsiJavaReference reference) {
  Object completion = completionElement.getElement();
  assert !(completion instanceof LookupElement);

  if (reference instanceof PsiJavaCodeReferenceElement) {
    if (completion instanceof PsiMethod &&
        ((PsiJavaCodeReferenceElement)reference).getParent() instanceof PsiImportStaticStatement) {
      return Arrays.asList(JavaLookupElementBuilder.forMethod((PsiMethod)completion, PsiSubstitutor.EMPTY));
    }

    if (completion instanceof PsiClass) {
      return JavaClassNameCompletionContributor.createClassLookupItems((PsiClass)completion,
                                                                       JavaClassNameCompletionContributor.AFTER_NEW.accepts(reference),
                                                                       JavaClassNameInsertHandler.JAVA_CLASS_INSERT_HANDLER,
                                                                       Condition.TRUE);
    }
  }

  LookupElement _ret = LookupItemUtil.objectToLookupItem(completion);
  if (_ret == null || !(_ret instanceof LookupItem)) return Collections.emptyList();

  final PsiSubstitutor substitutor = completionElement.getSubstitutor();
  if (substitutor != null) {
    ((LookupItem<?>)_ret).setAttribute(LookupItem.SUBSTITUTOR, substitutor);
  }

  return Arrays.asList(_ret);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:29,代码来源:JavaCompletionUtil.java

示例4: processJavaReference

import com.intellij.codeInsight.completion.scope.CompletionElement; //导入依赖的package包/类
public static Set<LookupElement> processJavaReference(PsiElement element, PsiJavaReference javaReference, ElementFilter elementFilter,
                                                      JavaCompletionProcessor.Options options,
                                                      final PrefixMatcher matcher, CompletionParameters parameters) {
  final Set<LookupElement> set = new LinkedHashSet<LookupElement>();
  final Condition<String> nameCondition = new Condition<String>() {
    @Override
    public boolean value(String s) {
      return matcher.prefixMatches(s);
    }
  };

  PsiMethodCallExpression call = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class);
  boolean checkInitialized = parameters.getInvocationCount() <= 1 && call != null && PsiKeyword.SUPER.equals(call.getMethodExpression().getText());

  final JavaCompletionProcessor processor = new JavaCompletionProcessor(element, elementFilter, options.withInitialized(checkInitialized), nameCondition);
  final PsiType plainQualifier = processor.getQualifierType();
  PsiType qualifierType = plainQualifier;

  PsiType runtimeQualifier = getQualifierCastType(javaReference, parameters);
  if (runtimeQualifier != null) {
    PsiType composite = qualifierType == null ? runtimeQualifier : PsiIntersectionType.createIntersection(qualifierType, runtimeQualifier);
    PsiElement ctx = createContextWithXxxVariable(element, composite);
    javaReference = (PsiReferenceExpression) JavaPsiFacade.getElementFactory(element.getProject()).createExpressionFromText("xxx.xxx", ctx);
    qualifierType = runtimeQualifier;
    processor.setQualifierType(qualifierType);
  }

  javaReference.processVariants(processor);

  final PsiTypeLookupItem castItem = runtimeQualifier == null ? null : PsiTypeLookupItem.createLookupItem(runtimeQualifier, (PsiReferenceExpression)javaReference);

  final boolean pkgContext = inSomePackage(element);

  PsiClass qualifierClass = PsiUtil.resolveClassInClassTypeOnly(qualifierType);
  final boolean honorExcludes = qualifierClass == null || !isInExcludedPackage(qualifierClass, false);

  final Set<PsiMember> mentioned = new THashSet<PsiMember>();
  for (CompletionElement completionElement : processor.getResults()) {
    for (LookupElement item : createLookupElements(completionElement, javaReference)) {
      item.putUserData(QUALIFIER_TYPE_ATTR, qualifierType);
      final Object o = item.getObject();
      if (o instanceof PsiClass && !isSourceLevelAccessible(element, (PsiClass)o, pkgContext)) {
        continue;
      }
      if (o instanceof PsiMember) {
        if (honorExcludes && isInExcludedPackage((PsiMember)o, true)) {
          continue;
        }
        mentioned.add(CompletionUtil.getOriginalOrSelf((PsiMember)o));
      }
      set.add(highlightIfNeeded(qualifierType, castQualifier(item, castItem, plainQualifier, processor), o, element));
    }
  }

  if (javaReference instanceof PsiJavaCodeReferenceElement && !((PsiJavaCodeReferenceElement)javaReference).isQualified()) {
    final StaticMemberProcessor memberProcessor = new JavaStaticMemberProcessor(parameters);
    memberProcessor.processMembersOfRegisteredClasses(matcher, new PairConsumer<PsiMember, PsiClass>() {
      @Override
      public void consume(PsiMember member, PsiClass psiClass) {
        if (!mentioned.contains(member) && processor.satisfies(member, ResolveState.initial())) {
          set.add(memberProcessor.createLookupElement(member, psiClass, true));
        }
      }
    });
  }

  return set;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:69,代码来源:JavaCompletionUtil.java

示例5: processJavaReference

import com.intellij.codeInsight.completion.scope.CompletionElement; //导入依赖的package包/类
public static Set<LookupElement> processJavaReference(PsiElement element, PsiJavaReference javaReference, ElementFilter elementFilter,
                                                      JavaCompletionProcessor.Options options,
                                                      final PrefixMatcher matcher, CompletionParameters parameters) {
  final Set<LookupElement> set = new LinkedHashSet<LookupElement>();
  final Condition<String> nameCondition = new Condition<String>() {
    @Override
    public boolean value(String s) {
      return matcher.prefixMatches(s);
    }
  };

  PsiMethodCallExpression call = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class);
  boolean checkInitialized = parameters.getInvocationCount() <= 1 && call != null && PsiKeyword.SUPER.equals(call.getMethodExpression().getText());

  final JavaCompletionProcessor processor = new JavaCompletionProcessor(element, elementFilter, options.withInitialized(checkInitialized), nameCondition);
  final PsiType plainQualifier = processor.getQualifierType();
  PsiType qualifierType = plainQualifier;

  PsiType runtimeQualifier = getQualifierCastType(javaReference, parameters);
  if (runtimeQualifier != null) {
    PsiType composite = qualifierType == null ? runtimeQualifier : PsiIntersectionType.createIntersection(qualifierType, runtimeQualifier);
    PsiElement ctx = createContextWithXxxVariable(element, composite);
    javaReference = (PsiReferenceExpression) JavaPsiFacade.getElementFactory(element.getProject()).createExpressionFromText("xxx.xxx", ctx);
    qualifierType = runtimeQualifier;
    processor.setQualifierType(qualifierType);
  }

  javaReference.processVariants(processor);

  final PsiTypeLookupItem castItem = runtimeQualifier == null ? null : PsiTypeLookupItem.createLookupItem(runtimeQualifier, (PsiReferenceExpression)javaReference);

  final boolean pkgContext = inSomePackage(element);

  final Set<PsiMember> mentioned = new THashSet<PsiMember>();
  for (CompletionElement completionElement : processor.getResults()) {
    for (LookupElement item : createLookupElements(completionElement, javaReference)) {
      item.putUserData(QUALIFIER_TYPE_ATTR, qualifierType);
      final Object o = item.getObject();
      if (o instanceof PsiClass && !isSourceLevelAccessible(element, (PsiClass)o, pkgContext)) {
        continue;
      }
      if (o instanceof PsiMember) {
        if (isInExcludedPackage((PsiMember)o, true)) {
          continue;
        }
        mentioned.add((PsiMember)o);
      }
      set.add(highlightIfNeeded(qualifierType, castQualifier(item, castItem, plainQualifier), o));
    }
  }

  if (javaReference instanceof PsiJavaCodeReferenceElement && !((PsiJavaCodeReferenceElement)javaReference).isQualified()) {
    final StaticMemberProcessor memberProcessor = new JavaStaticMemberProcessor(parameters);
    memberProcessor.processMembersOfRegisteredClasses(matcher, new PairConsumer<PsiMember, PsiClass>() {
      @Override
      public void consume(PsiMember member, PsiClass psiClass) {
        if (!mentioned.contains(member) && processor.satisfies(member, ResolveState.initial())) {
          set.add(memberProcessor.createLookupElement(member, psiClass, true));
        }
      }
    });
  }

  return set;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:66,代码来源:JavaCompletionUtil.java

示例6: processJavaQualifiedReference

import com.intellij.codeInsight.completion.scope.CompletionElement; //导入依赖的package包/类
private static Set<LookupElement> processJavaQualifiedReference(PsiElement element,
		PsiJavaReference javaReference,
		ElementFilter elementFilter,
		JavaCompletionProcessor.Options options,
		final PrefixMatcher matcher,
		CompletionParameters parameters)
{
	final Set<LookupElement> set = new LinkedHashSet<>();
	final Condition<String> nameCondition = matcher::prefixMatches;

	final JavaCompletionProcessor processor = new JavaCompletionProcessor(element, elementFilter, options, nameCondition);
	final PsiType plainQualifier = processor.getQualifierType();
	PsiType qualifierType = plainQualifier;

	PsiType runtimeQualifier = getQualifierCastType(javaReference, parameters);
	if(runtimeQualifier != null)
	{
		PsiType composite = qualifierType == null ? runtimeQualifier : PsiIntersectionType.createIntersection(qualifierType, runtimeQualifier);
		PsiElement ctx = createContextWithXxxVariable(element, composite);
		javaReference = createReference("xxx.xxx", ctx);
		qualifierType = runtimeQualifier;
		processor.setQualifierType(qualifierType);
	}

	javaReference.processVariants(processor);

	final PsiTypeLookupItem castItem = runtimeQualifier == null ? null : PsiTypeLookupItem.createLookupItem(runtimeQualifier, (PsiReferenceExpression) javaReference);

	final boolean pkgContext = inSomePackage(element);

	PsiClass qualifierClass = PsiUtil.resolveClassInClassTypeOnly(qualifierType);
	final boolean honorExcludes = qualifierClass == null || !isInExcludedPackage(qualifierClass, false);

	final Set<PsiMember> mentioned = new THashSet<>();
	for(CompletionElement completionElement : processor.getResults())
	{
		for(LookupElement item : createLookupElements(completionElement, javaReference))
		{
			item.putUserData(QUALIFIER_TYPE_ATTR, qualifierType);
			final Object o = item.getObject();
			if(o instanceof PsiClass && !isSourceLevelAccessible(element, (PsiClass) o, pkgContext))
			{
				continue;
			}
			if(o instanceof PsiMember)
			{
				if(honorExcludes && isInExcludedPackage((PsiMember) o, true))
				{
					continue;
				}
				mentioned.add(CompletionUtil.getOriginalOrSelf((PsiMember) o));
			}
			set.add(highlightIfNeeded(qualifierType, castQualifier(item, castItem, plainQualifier, processor), o, element));
		}
	}

	if(javaReference instanceof PsiJavaCodeReferenceElement)
	{
		PsiElement refQualifier = ((PsiJavaCodeReferenceElement) javaReference).getQualifier();
		if(refQualifier == null)
		{
			final StaticMemberProcessor memberProcessor = new JavaStaticMemberProcessor(parameters);
			memberProcessor.processMembersOfRegisteredClasses(matcher, (member, psiClass) ->
			{
				if(!mentioned.contains(member) && processor.satisfies(member, ResolveState.initial()))
				{
					set.add(memberProcessor.createLookupElement(member, psiClass, true));
				}
			});
		}
		else if(refQualifier instanceof PsiSuperExpression && ((PsiSuperExpression) refQualifier).getQualifier() == null)
		{
			set.addAll(SuperCalls.suggestQualifyingSuperCalls(element, javaReference, elementFilter, options, nameCondition));
		}
	}

	return set;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:79,代码来源:JavaCompletionUtil.java

示例7: createLookupElements

import com.intellij.codeInsight.completion.scope.CompletionElement; //导入依赖的package包/类
static Iterable<? extends LookupElement> createLookupElements(CompletionElement completionElement, PsiJavaReference reference)
{
	Object completion = completionElement.getElement();
	assert !(completion instanceof LookupElement);

	if(reference instanceof PsiJavaCodeReferenceElement)
	{
		if(completion instanceof PsiMethod && ((PsiJavaCodeReferenceElement) reference).getParent() instanceof PsiImportStaticStatement)
		{
			return Collections.singletonList(JavaLookupElementBuilder.forMethod((PsiMethod) completion, PsiSubstitutor.EMPTY));
		}

		if(completion instanceof PsiClass)
		{
			List<JavaPsiClassReferenceElement> classItems = JavaClassNameCompletionContributor.createClassLookupItems((PsiClass) completion, JavaClassNameCompletionContributor.AFTER_NEW.accepts
					(reference), JavaClassNameInsertHandler.JAVA_CLASS_INSERT_HANDLER, Conditions.alwaysTrue());
			return JBIterable.from(classItems).flatMap(i -> JavaConstructorCallElement.wrap(i, reference.getElement()));
		}
	}

	if(reference instanceof PsiMethodReferenceExpression && completion instanceof PsiMethod && ((PsiMethod) completion).isConstructor())
	{
		return Collections.singletonList(JavaLookupElementBuilder.forMethod((PsiMethod) completion, "new", PsiSubstitutor.EMPTY, null));
	}

	PsiSubstitutor substitutor = completionElement.getSubstitutor();
	if(substitutor == null)
	{
		substitutor = PsiSubstitutor.EMPTY;
	}
	if(completion instanceof PsiClass)
	{
		JavaPsiClassReferenceElement classItem = JavaClassNameCompletionContributor.createClassLookupItem((PsiClass) completion, true).setSubstitutor(substitutor);
		return JavaConstructorCallElement.wrap(classItem, reference.getElement());
	}
	if(completion instanceof PsiMethod)
	{
		JavaMethodCallElement item = new JavaMethodCallElement((PsiMethod) completion).setQualifierSubstitutor(substitutor);
		item.setForcedQualifier(completionElement.getQualifierText());
		return Collections.singletonList(item);
	}
	if(completion instanceof PsiVariable)
	{
		return Collections.singletonList(new VariableLookupItem((PsiVariable) completion).setSubstitutor(substitutor));
	}

	return Collections.singletonList(LookupItemUtil.objectToLookupItem(completion));
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:49,代码来源:JavaCompletionUtil.java


注:本文中的com.intellij.codeInsight.completion.scope.CompletionElement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。