@Override public void handleInsert(InsertionContext context) { PsiFile file = context.getFile(); boolean addDot = !(file instanceof PsiJavaCodeReferenceCodeFragment) || ((PsiJavaCodeReferenceCodeFragment)file).isClassesAccepted(); if (addDot) { context.setAddCompletionChar(false); TailType.DOT.processTail(context.getEditor(), context.getTailOffset()); } if (addDot || context.getCompletionChar() == '.') { AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(context.getEditor()); } }
@Override public void handleInsert(InsertionContext context) { PsiFile file = context.getFile(); boolean addDot = !(file instanceof PsiJavaCodeReferenceCodeFragment) || ((PsiJavaCodeReferenceCodeFragment) file).isClassesAccepted(); if(addDot) { context.setAddCompletionChar(false); TailType.DOT.processTail(context.getEditor(), context.getTailOffset()); } if(addDot || context.getCompletionChar() == '.') { AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(context.getEditor()); } }
private static void suggestChainedCalls(CompletionParameters parameters, CompletionResultSet result, PsiElement position) { PsiElement parent = position.getParent(); if(!(parent instanceof PsiJavaCodeReferenceElement) || parent.getParent() instanceof PsiImportStatementBase) { return; } PsiElement qualifier = ((PsiJavaCodeReferenceElement) parent).getQualifier(); if(!(qualifier instanceof PsiJavaCodeReferenceElement) || ((PsiJavaCodeReferenceElement) qualifier).isQualified()) { return; } PsiElement target = ((PsiJavaCodeReferenceElement) qualifier).resolve(); if(target != null && !(target instanceof PsiPackage)) { return; } PsiFile file = position.getContainingFile(); if(file instanceof PsiJavaCodeReferenceCodeFragment) { return; } String fullPrefix = parent.getText().substring(0, parameters.getOffset() - parent.getTextRange().getStartOffset()); CompletionResultSet qualifiedCollector = result.withPrefixMatcher(fullPrefix); ElementFilter filter = JavaCompletionContributor.getReferenceFilter(position); for(LookupElement base : suggestQualifierItems(parameters, (PsiJavaCodeReferenceElement) qualifier, filter)) { PsiType type = JavaCompletionUtil.getLookupElementType(base); if(type != null && !PsiType.VOID.equals(type)) { PsiReferenceExpression ref = ReferenceExpressionCompletionContributor.createMockReference(position, type, base); if(ref != null) { for(final LookupElement item : JavaSmartCompletionContributor.completeReference(position, ref, filter, true, true, parameters, result.getPrefixMatcher())) { qualifiedCollector.addElement(JavaCompletionUtil.highlightIfNeeded(null, new JavaChainLookupElement(base, item), item.getObject(), position)); } } } } }
@NotNull @Override public PsiJavaCodeReferenceCodeFragment createReferenceCodeFragment(@NotNull final String text, @Nullable final PsiElement context, final boolean isPhysical, final boolean isClassesAccepted) { return new PsiJavaCodeReferenceCodeFragmentImpl(myProject, isPhysical, "fragment.java", text, isClassesAccepted, context); }