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


Java CompletionContributor類代碼示例

本文整理匯總了Java中com.intellij.codeInsight.completion.CompletionContributor的典型用法代碼示例。如果您正苦於以下問題:Java CompletionContributor類的具體用法?Java CompletionContributor怎麽用?Java CompletionContributor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: extend

import com.intellij.codeInsight.completion.CompletionContributor; //導入依賴的package包/類
static void extend(CompletionContributor contributor)
{
	contributor.extend(CompletionType.BASIC, CSharpPatterns.expressionStart(), new CompletionProvider()
	{
		@RequiredReadAction
		@Override
		public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result)
		{
			PsiElement position = parameters.getPosition();
			if(!CSharpModuleUtil.findLanguageVersion(position).isAtLeast(CSharpLanguageVersion._3_0))
			{
				return;
			}
			CSharpReferenceExpressionEx parent = (CSharpReferenceExpressionEx) position.getParent();
			if(parent.getQualifier() != null || parent.kind() != CSharpReferenceExpression.ResolveToKind.ANY_MEMBER)
			{
				return;
			}

			CSharpCompletionUtil.elementToLookup(result, CSharpSoftTokens.FROM_KEYWORD, null, null);
		}
	});
}
 
開發者ID:consulo,項目名稱:consulo-csharp,代碼行數:24,代碼來源:CSharpLinqCompletionContributor.java

示例2: isAutoPopup

import com.intellij.codeInsight.completion.CompletionContributor; //導入依賴的package包/類
private static boolean isAutoPopup(@NotNull Editor editor, @NotNull PsiFile file, char charTyped) {
  final int offset = editor.getCaretModel().getOffset() - 1;
  if (offset >= 0) {
    final PsiElement element = file.findElementAt(offset);
    if (element != null) {
      final List<CompletionContributor> list = CompletionContributor.forLanguage(element.getLanguage());
      for (CompletionContributor contributor : list) {
        if (contributor.invokeAutoPopup(element, charTyped)) return true;
      }
    }
  }
  return false;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:14,代碼來源:TypedHandler.java

示例3: isAutoPopup

import com.intellij.codeInsight.completion.CompletionContributor; //導入依賴的package包/類
private static boolean isAutoPopup(@Nonnull Editor editor, @Nonnull PsiFile file, char charTyped) {
  final int offset = editor.getCaretModel().getOffset() - 1;
  if (offset >= 0) {
    final PsiElement element = file.findElementAt(offset);
    if (element != null) {
      final List<CompletionContributor> list = CompletionContributor.forLanguage(element.getLanguage());
      for (CompletionContributor contributor : list) {
        if (contributor.invokeAutoPopup(element, charTyped)) return true;
      }
    }
  }
  return false;
}
 
開發者ID:consulo,項目名稱:consulo,代碼行數:14,代碼來源:TypedHandler.java

示例4: extend

import com.intellij.codeInsight.completion.CompletionContributor; //導入依賴的package包/類
static void extend(CompletionContributor contributor)
{
	contributor.extend(CompletionType.BASIC, psiElement().andNot(psiElement().inside(DotNetXXXAccessor.class)), new CompletionProvider()
	{
		@RequiredReadAction
		@Override
		public void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet resultSet)
		{
			PsiElement position = completionParameters.getPosition();
			final CSharpXXXAccessorOwner accessorOwner = PsiTreeUtil.getParentOfType(position, CSharpXXXAccessorOwner.class);
			if(accessorOwner == null)
			{
				return;
			}
			PsiElement leftBrace = accessorOwner.getLeftBrace();
			if(leftBrace == null)
			{
				return;
			}

			int textOffset = position.getTextOffset();
			PsiElement rightBrace = accessorOwner.getRightBrace();
			int rightTextRange = rightBrace == null ? -1 : rightBrace.getTextOffset();

			if((rightTextRange == -1 || textOffset < rightTextRange) && textOffset > leftBrace.getTextOffset())
			{
				if(accessorOwner.hasModifier(DotNetModifier.ABSTRACT))
				{
					buildAccessorKeywordsCompletion(resultSet, accessorOwner, null);
				}
				else
				{
					buildAccessorKeywordsCompletion(resultSet, accessorOwner, new InsertHandler<LookupElement>()
					{
						@Override
						@RequiredWriteAction
						public void handleInsert(InsertionContext context, LookupElement item)
						{
							if(context.getCompletionChar() == '{')
							{
								context.setAddCompletionChar(false);

								Editor editor = context.getEditor();

								CaretModel caretModel = editor.getCaretModel();
								int offset = caretModel.getOffset();

								context.getDocument().insertString(offset, "{\n}");
								caretModel.moveToOffset(offset + 1);

								PsiElement elementAt = context.getFile().findElementAt(offset - 1);

								context.commitDocument();

								DotNetXXXAccessor accessor = PsiTreeUtil.getParentOfType(elementAt, DotNetXXXAccessor.class);
								if(accessor != null)
								{
									CodeStyleManager.getInstance(context.getProject()).reformat(accessor);
								}

								EditorWriteActionHandler actionHandler = (EditorWriteActionHandler) EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
								actionHandler.executeWriteAction(editor, DataManager.getInstance().getDataContext(editor.getContentComponent()));
							}
						}
					});
				}
			}
		}
	});
}
 
開發者ID:consulo,項目名稱:consulo-csharp,代碼行數:71,代碼來源:CSharpAccessorCompletionContributor.java

示例5: extend

import com.intellij.codeInsight.completion.CompletionContributor; //導入依賴的package包/類
static void extend(CompletionContributor contributor)
{
	contributor.extend(CompletionType.BASIC, CSharpPatterns.fieldStart(), new CompletionProvider()
	{
		@RequiredReadAction
		@Override
		public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result)
		{
			CSharpFieldDeclaration currentElement = PsiTreeUtil.getParentOfType(parameters.getPosition(), CSharpFieldDeclaration.class);
			assert currentElement != null;

			DotNetModifierList modifierList = currentElement.getModifierList();
			if(modifierList != null)
			{
				int textLength = modifierList.getTextLength();
				if(textLength > 0)
				{
					return;
				}
			}

			PsiElement nextSibling = UsefulPsiTreeUtil.getNextSiblingSkippingWhiteSpacesAndComments(currentElement);
			TextRange textRange = nextSibling == null ? null : new TextRange(currentElement.getTextRange().getEndOffset(), nextSibling.getTextRange().getStartOffset());
			if(textRange != null && !StringUtil.containsLineBreak(textRange.subSequence(currentElement.getContainingFile().getText())))
			{
				return;
			}

			CSharpTypeDeclaration typeDeclaration = PsiTreeUtil.getParentOfType(parameters.getPosition(), CSharpTypeDeclaration.class);

			if(typeDeclaration == null)
			{
				return;
			}

			Consumer<LookupElement> delegate = lookupElement ->
			{
				if(lookupElement != null)
				{
					CSharpCompletionSorting.force(lookupElement, CSharpCompletionSorting.KindSorter.Type.overrideMember);
					result.consume(lookupElement);
				}
			};

			for(CSharpMemberAddByCompletionContributor completionContributor : EP_NAME.getExtensions())
			{
				completionContributor.processCompletion(parameters, context, delegate, typeDeclaration);
			}
		}
	});
}
 
開發者ID:consulo,項目名稱:consulo-csharp,代碼行數:52,代碼來源:CSharpMemberAddByCompletionContributor.java


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