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


Java InsertionContext.setAddCompletionChar方法代码示例

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


在下文中一共展示了InsertionContext.setAddCompletionChar方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
  final Editor editor = context.getEditor();
  final Document document = editor.getDocument();
  if (context.getCompletionChar() == '(') {
    context.setAddCompletionChar(false);
    final int offset = context.getTailOffset();
    document.insertString(offset, "()");

    PyClass pyClass = (PyClass) item.getObject();
    PyFunction init = pyClass.findInitOrNew(true, null);
    if (init != null && PyFunctionInsertHandler.hasParams(context, init)) {
      editor.getCaretModel().moveToOffset(offset+1);
      AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), init);
    }
    else {
      editor.getCaretModel().moveToOffset(offset+2);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PyClassInsertHandler.java

示例2: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@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());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:PackageLookupItem.java

示例3: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context) {
  final InsertHandler<? extends LookupElement> handler = getInsertHandler();
  if (handler != null) {
    //noinspection unchecked
    ((InsertHandler)handler).handleInsert(context, this);
  }
  if (getTailType() != TailType.UNKNOWN && myInsertHandler == null) {
    context.setAddCompletionChar(false);
    final TailType type = handleCompletionChar(context.getEditor(), this, context.getCompletionChar());
    type.processTail(context.getEditor(), context.getTailOffset());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:LookupItem.java

示例4: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement item)
{
	if(context.getCompletionChar() == myEnterChar)
	{
		context.setAddCompletionChar(false);
		myTailType.processTail(context.getEditor(), context.getTailOffset());
	}
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:10,代码来源:CSharpTailInsertHandlerWithChar.java

示例5: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@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());
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:16,代码来源:PackageLookupItem.java

示例6: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context, final T item) {
  final Editor editor = context.getEditor();
  final Document document = editor.getDocument();
  context.commitDocument();
  PsiElement element = findNextToken(context);

  final char completionChar = context.getCompletionChar();
  final boolean putCaretInside = completionChar == '(' || placeCaretInsideParentheses(context, item);

  if (completionChar == '(') {
    context.setAddCompletionChar(false);
  }

  if (isToken(element, "(")) {
    int lparenthOffset = element.getTextRange().getStartOffset();
    if (mySpaceBeforeParentheses && lparenthOffset == context.getTailOffset()) {
      document.insertString(context.getTailOffset(), " ");
      lparenthOffset++;
    }

    if (completionChar == '(' || completionChar == '\t') {
      editor.getCaretModel().moveToOffset(lparenthOffset + 1);
    } else {
      editor.getCaretModel().moveToOffset(context.getTailOffset());
    }

    context.setTailOffset(lparenthOffset + 1);

    PsiElement list = element.getParent();
    PsiElement last = list.getLastChild();
    if (isToken(last, ")")) {
      int rparenthOffset = last.getTextRange().getStartOffset();
      context.setTailOffset(rparenthOffset + 1);
      if (!putCaretInside) {
        for (int i = lparenthOffset + 1; i < rparenthOffset; i++) {
          if (!Character.isWhitespace(document.getCharsSequence().charAt(i))) {
            return;
          }
        }
        editor.getCaretModel().moveToOffset(context.getTailOffset());
      } else if (mySpaceBetweenParentheses && document.getCharsSequence().charAt(lparenthOffset) == ' ') {
        editor.getCaretModel().moveToOffset(lparenthOffset + 2);
      } else {
        editor.getCaretModel().moveToOffset(lparenthOffset + 1);
      }
      return;
    }
  } else {
    document.insertString(context.getTailOffset(), getSpace(mySpaceBeforeParentheses) + "(" + getSpace(mySpaceBetweenParentheses));
    editor.getCaretModel().moveToOffset(context.getTailOffset());
  }

  if (!myMayInsertRightParenthesis) return;

  if (context.getCompletionChar() == '(') {
    //todo use BraceMatchingUtil.isPairedBracesAllowedBeforeTypeInFileType
    int tail = context.getTailOffset();
    if (tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail))) {
      return;
    }
  }

  document.insertString(context.getTailOffset(), getSpace(mySpaceBetweenParentheses) + ")");
  if (!putCaretInside) {
    editor.getCaretModel().moveToOffset(context.getTailOffset());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:69,代码来源:ParenthesesInsertHandler.java

示例7: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context) {
  context.setAddCompletionChar(false);
  expandTemplate(context.getEditor(), context.getFile());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:CustomLiveTemplateLookupElement.java

示例8: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context) {
  context.getDocument().deleteString(context.getStartOffset(), context.getTailOffset());
  context.setAddCompletionChar(false);
  TemplateManager.getInstance(context.getProject()).startTemplate(context.getEditor(), myTemplate);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:LiveTemplateLookupElementImpl.java

示例9: handleInsertImpl

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
private void handleInsertImpl(InsertionContext context, T item, Editor editor, Document document)
{
	PsiElement element = findNextToken(context);

	final char completionChar = context.getCompletionChar();

	final boolean putCaretInside = completionChar == myOpenChar || placeCaretInsideParentheses(context, item);

	if(completionChar == myOpenChar)
	{
		context.setAddCompletionChar(false);
	}

	boolean canAddSpaceBeforePair = canAddSpaceBeforePair(context, item);

	if(isToken(element, myOpenChar))
	{
		int lparenthOffset = element.getTextRange().getStartOffset();
		if(canAddSpaceBeforePair && lparenthOffset == context.getTailOffset())
		{
			document.insertString(context.getTailOffset(), " ");
			lparenthOffset++;
		}

		if(completionChar == myOpenChar || completionChar == '\t')
		{
			editor.getCaretModel().moveToOffset(lparenthOffset + 1);
		}
		else
		{
			editor.getCaretModel().moveToOffset(context.getTailOffset());
		}

		context.setTailOffset(lparenthOffset + 1);

		PsiElement list = element.getParent();
		PsiElement last = list.getLastChild();
		if(isToken(last, myCloseChar))
		{
			int rparenthOffset = last.getTextRange().getStartOffset();
			context.setTailOffset(rparenthOffset + 1);
			if(!putCaretInside)
			{
				for(int i = lparenthOffset + 1; i < rparenthOffset; i++)
				{
					if(!Character.isWhitespace(document.getCharsSequence().charAt(i)))
					{
						return;
					}
				}
				editor.getCaretModel().moveToOffset(context.getTailOffset());
			}
			else
			{
				editor.getCaretModel().moveToOffset(lparenthOffset + 1);
			}
			return;
		}
	}
	else
	{
		document.insertString(context.getTailOffset(), getSpace(canAddSpaceBeforePair) + myOpenChar);
		editor.getCaretModel().moveToOffset(context.getTailOffset());
	}

	if(context.getCompletionChar() == myOpenChar)
	{
		int tail = context.getTailOffset();
		if(tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail)))
		{
			return;
		}
	}

	document.insertString(context.getTailOffset(), String.valueOf(myCloseChar));
	if(!putCaretInside)
	{
		editor.getCaretModel().moveToOffset(context.getTailOffset());
	}
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:81,代码来源:ExpressionOrStatementInsertHandler.java

示例10: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context, final T item) {
  final Editor editor = context.getEditor();
  final Document document = editor.getDocument();
  context.commitDocument();
  PsiElement lParen = findExistingLeftParenthesis(context);

  final char completionChar = context.getCompletionChar();
  final boolean putCaretInside = completionChar == myLeftParenthesis || placeCaretInsideParentheses(context, item);

  if (completionChar == myLeftParenthesis) {
    context.setAddCompletionChar(false);
  }

  if (lParen != null) {
    int lparenthOffset = lParen.getTextRange().getStartOffset();
    if (mySpaceBeforeParentheses && lparenthOffset == context.getTailOffset()) {
      document.insertString(context.getTailOffset(), " ");
      lparenthOffset++;
    }

    if (completionChar == myLeftParenthesis || completionChar == '\t') {
      editor.getCaretModel().moveToOffset(lparenthOffset + 1);
    }
    else {
      editor.getCaretModel().moveToOffset(context.getTailOffset());
    }

    context.setTailOffset(lparenthOffset + 1);

    PsiElement list = lParen.getParent();
    PsiElement last = list.getLastChild();
    if (isToken(last, String.valueOf(myRightParenthesis))) {
      int rparenthOffset = last.getTextRange().getStartOffset();
      context.setTailOffset(rparenthOffset + 1);
      if (!putCaretInside) {
        for (int i = lparenthOffset + 1; i < rparenthOffset; i++) {
          if (!Character.isWhitespace(document.getCharsSequence().charAt(i))) {
            return;
          }
        }
        editor.getCaretModel().moveToOffset(context.getTailOffset());
      }
      else if (mySpaceBetweenParentheses && document.getCharsSequence().charAt(lparenthOffset) == ' ') {
        editor.getCaretModel().moveToOffset(lparenthOffset + 2);
      }
      else {
        editor.getCaretModel().moveToOffset(lparenthOffset + 1);
      }
      return;
    }
  }
  else {
    document.insertString(context.getTailOffset(), getSpace(mySpaceBeforeParentheses) + myLeftParenthesis + getSpace(mySpaceBetweenParentheses));
    editor.getCaretModel().moveToOffset(context.getTailOffset());
  }

  if (!myMayInsertRightParenthesis) return;

  if (context.getCompletionChar() == myLeftParenthesis) {
    //todo use BraceMatchingUtil.isPairedBracesAllowedBeforeTypeInFileType
    int tail = context.getTailOffset();
    if (tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail))) {
      return;
    }
  }

  document.insertString(context.getTailOffset(), getSpace(mySpaceBetweenParentheses) + myRightParenthesis);
  if (!putCaretInside) {
    editor.getCaretModel().moveToOffset(context.getTailOffset());
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:73,代码来源:ParenthesesInsertHandler.java

示例11: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context)
{
	myImportFixer.handleInsert(context, this);

	PsiElement position = context.getFile().findElementAt(context.getStartOffset());
	if(position != null)
	{
		int genericsStart = context.getTailOffset();
		context.getDocument().insertString(genericsStart, JavaCompletionUtil.escapeXmlIfNeeded(context, calcGenerics(position, context)));
		JavaCompletionUtil.shortenReference(context.getFile(), genericsStart - 1);
	}

	int tail = context.getTailOffset();
	String braces = StringUtil.repeat("[]", getBracketsCount());
	Editor editor = context.getEditor();
	if(!braces.isEmpty())
	{
		if(myAddArrayInitializer)
		{
			context.getDocument().insertString(tail, braces + "{}");
			editor.getCaretModel().moveToOffset(tail + braces.length() + 1);
		}
		else
		{
			context.getDocument().insertString(tail, braces);
			editor.getCaretModel().moveToOffset(tail + 1);
			if(context.getCompletionChar() == '[')
			{
				context.setAddCompletionChar(false);
			}
		}
	}
	else
	{
		editor.getCaretModel().moveToOffset(tail);
	}
	editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);

	InsertHandler handler = getInsertHandler();
	if(handler != null)
	{
		//noinspection unchecked
		handler.handleInsert(context, this);
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:47,代码来源:PsiTypeLookupItem.java


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