本文整理汇总了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;
}
示例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));
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}