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


Java InsertionContext.getTailOffset方法代码示例

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

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

示例1: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context) {
  final LookupElement delegate = getDelegate();
  final TailType tailType = computeTailType(context);

  final LookupItem lookupItem = delegate.as(LookupItem.CLASS_CONDITION_KEY);
  if (lookupItem != null && tailType != null) {
    lookupItem.setTailType(TailType.UNKNOWN);
  }
  delegate.handleInsert(context);
  if (tailType != null && tailType.isApplicable(context)) {
    PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting();
    int tailOffset = context.getTailOffset();
    if (tailOffset < 0) {
      throw new AssertionError("tailOffset < 0: delegate=" + getDelegate() + "; this=" + this + "; tail=" + tailType);
    }
    tailType.processTail(context.getEditor(), tailOffset);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:TailTypeDecorator.java


示例2: 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


示例3: addImportForItem

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
public static void addImportForItem(InsertionContext context, PsiClass aClass)
{
	if(aClass.getQualifiedName() == null)
	{
		return;
	}
	PsiFile file = context.getFile();

	int startOffset = context.getStartOffset();
	int tail = context.getTailOffset();
	int newTail = JavaCompletionUtil.insertClassReference(aClass, file, startOffset, tail);
	if(newTail > context.getDocument().getTextLength() || newTail < 0)
	{
		LOG.error(LogMessageEx.createEvent("Invalid offset after insertion ", "offset=" + newTail + "\n" + "start=" + startOffset + "\n" + "tail=" + tail + "\n" + "file.length=" + file
				.getTextLength() + "\n" + "document=" + context.getDocument() + "\n" + DebugUtil.currentStackTrace(), AttachmentFactory.createAttachment(context.getDocument())));
		return;

	}
	context.setTailOffset(newTail);
	JavaCompletionUtil.shortenReference(file, context.getStartOffset());
	PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting();
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:23,代码来源:PsiTypeLookupItem.java


示例4: getStringBeforeAutoCompletedValue

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@NotNull
private String getStringBeforeAutoCompletedValue(final InsertionContext context, final LookupElement item) {
    final int tailOffset = context.getDocument().getText().substring(0, context.getTailOffset()).endsWith("\"")
            ? context.getTailOffset()
            : context.getTailOffset() + 1;

    return context.getDocument().getText().substring(0, tailOffset)
            .replace("\"" + item.getLookupString() + "\"", "");
}
 
开发者ID:zalando,项目名称:intellij-swagger,代码行数:10,代码来源:JsonInsertFieldHandler.java


示例5: isApplicable

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public boolean isApplicable(@NotNull InsertionContext context) {
  CharSequence text = context.getDocument().getCharsSequence();
  int tail = context.getTailOffset();
  if (text.length() > tail + 1 && text.charAt(tail) == ' ' && Character.isLetter(text.charAt(tail + 1))) {
    return false;
  }
  return super.isApplicable(context);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:TailType.java


示例6: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
  if (context.getCompletionChar() != Lookup.REPLACE_SELECT_CHAR) {
    return;
  }
  Document doc = context.getDocument();
  int tailOffset = context.getTailOffset();
  if (tailOffset < doc.getCharsSequence().length() && doc.getCharsSequence().charAt(tailOffset) == '=') {
    doc.deleteString(tailOffset, tailOffset+1);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:OverwriteEqualsInsertHandler.java


示例7: 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();
  int tailOffset = context.getTailOffset();
  document.insertString(tailOffset, IMPORT_KWD);
  editor.getCaretModel().moveToOffset(tailOffset + IMPORT_KWD.length());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:PyImportReference.java


示例8: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context, LookupElement item) {
  final PsiClassType.ClassResolveResult resolveResult = myClassType.resolveGenerics();
  final PsiClass psiClass = resolveResult.getElement();
  if (psiClass == null || !psiClass.isValid()) {
    return;
  }

  GroovyPsiElement place =
    PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), GroovyPsiElement.class, false);
  boolean hasParams = place != null && GroovyCompletionUtil.hasConstructorParameters(psiClass, place);
  if (myTriggerFeature) {
    FeatureUsageTracker.getInstance().triggerFeatureUsed(JavaCompletionFeatures.AFTER_NEW);
  }

  if (hasParams) {
    ParenthesesInsertHandler.WITH_PARAMETERS.handleInsert(context, item);
  }
  else {
    ParenthesesInsertHandler.NO_PARAMETERS.handleInsert(context, item);
  }

  shortenRefsInGenerics(context);
  if (hasParams) {
    AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), null);
  }

  PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getDocument());

  if (psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
    final Editor editor = context.getEditor();
    final int offset = context.getTailOffset();
    editor.getDocument().insertString(offset, " {}");
    editor.getCaretModel().moveToOffset(offset + 2);

    context.setLaterRunnable(generateAnonymousBody(editor, context.getFile()));

  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:AfterNewClassInsertHandler.java


示例9: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
public void handleInsert(final InsertionContext context, LookupItem<PsiClassType> item) {
  final PsiClassType.ClassResolveResult resolveResult = myClassType.resolveGenerics();
  final PsiClass psiClass = resolveResult.getElement();
  if (psiClass == null || !psiClass.isValid()) {
    return;
  }

  GroovyPsiElement place =
    PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), GroovyPsiElement.class, false);
  boolean hasParams = place != null && GroovyCompletionUtil.hasConstructorParameters(psiClass, place);
  if (myTriggerFeature) {
    FeatureUsageTracker.getInstance().triggerFeatureUsed(JavaCompletionFeatures.AFTER_NEW);
  }

  if (hasParams) {
    ParenthesesInsertHandler.WITH_PARAMETERS.handleInsert(context, item);
  }
  else {
    ParenthesesInsertHandler.NO_PARAMETERS.handleInsert(context, item);
  }

  shortenRefsInGenerics(context);
  if (hasParams) {
    AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), null);
  }

  PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getDocument());

  if (psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
    final Editor editor = context.getEditor();
    final int offset = context.getTailOffset();
    editor.getDocument().insertString(offset, " {}");
    editor.getCaretModel().moveToOffset(offset + 2);

    context.setLaterRunnable(generateAnonymousBody(editor, context.getFile()));

  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:39,代码来源:AfterNewClassInsertHandler.java


示例10: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement item)
{
	if(context.getCompletionChar() != ' ')
	{
		int tailOffset = context.getTailOffset();
		TailType.insertChar(context.getEditor(), tailOffset, ' ');
		context.getEditor().getCaretModel().moveToOffset(tailOffset + 1);
	}
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:11,代码来源:SpaceInsertHandler.java


示例11: isApplicable

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public boolean isApplicable(@Nonnull InsertionContext context) {
  CharSequence text = context.getDocument().getCharsSequence();
  int tail = context.getTailOffset();
  if (text.length() > tail + 1 && text.charAt(tail) == ' ' && Character.isLetter(text.charAt(tail + 1))) {
    return false;
  }
  return super.isApplicable(context);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:10,代码来源:TailType.java


示例12: 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


示例13: 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


示例14: 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


示例15: 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.getTailOffset方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。