本文整理汇总了Java中com.intellij.codeInsight.completion.InsertionContext.getCompletionChar方法的典型用法代码示例。如果您正苦于以下问题:Java InsertionContext.getCompletionChar方法的具体用法?Java InsertionContext.getCompletionChar怎么用?Java InsertionContext.getCompletionChar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.completion.InsertionContext
的用法示例。
在下文中一共展示了InsertionContext.getCompletionChar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例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());
}
}
示例3: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context) {
LookupElement item = getDelegate();
Project project = context.getProject();
Editor editor = context.getEditor();
PsiDocumentManager.getInstance(project).commitAllDocuments();
TextRange range = myState.getCurrentVariableRange();
final TemplateLookupSelectionHandler handler = item.getUserData(TemplateLookupSelectionHandler.KEY_IN_LOOKUP_ITEM);
if (handler != null && range != null) {
handler.itemSelected(item, context.getFile(), context.getDocument(), range.getStartOffset(), range.getEndOffset());
}
else {
super.handleInsert(context);
}
if (context.getCompletionChar() == '.') {
EditorModificationUtil.insertStringAtCaret(editor, ".");
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
return;
}
if (!myState.isFinished()) {
myState.calcResults(true);
}
myState.nextTab();
}
示例4: 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);
}
}
示例5: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context) {
super.handleInsert(context);
if (getTailType() == TailType.DOT || context.getCompletionChar() == '.') {
AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(context.getEditor());
}
}
示例6: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context) {
LookupElement item = getDelegate();
Project project = context.getProject();
Editor editor = context.getEditor();
PsiDocumentManager.getInstance(project).commitAllDocuments();
TextRange range = myState.getCurrentVariableRange();
final TemplateLookupSelectionHandler handler =
item instanceof LookupItem ? ((LookupItem<?>)item).getAttribute(TemplateLookupSelectionHandler.KEY_IN_LOOKUP_ITEM) : null;
if (handler != null && range != null) {
handler.itemSelected(item, context.getFile(), context.getDocument(), range.getStartOffset(), range.getEndOffset());
}
else {
super.handleInsert(context);
}
if (context.getCompletionChar() == '.') {
EditorModificationUtil.insertStringAtCaret(editor, ".");
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
return;
}
if (!myState.isFinished()) {
myState.calcResults(true);
}
myState.nextTab();
}
示例7: 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());
}
}
示例8: 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);
}
}
示例9: handleCompletionChar
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
private static boolean handleCompletionChar(InsertionContext context) {
if (context.getCompletionChar() == '.') {
EditorModificationUtil.insertStringAtCaret(context.getEditor(), ".");
AutoPopupController.getInstance(context.getProject()).autoPopupMemberLookup(context.getEditor(), null);
return false;
}
return true;
}
示例10: 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());
}
}
示例11: 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());
}
}
示例12: isApplicable
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public boolean isApplicable(@NotNull InsertionContext context) {
return !context.shouldAddCompletionChar() || context.getCompletionChar() != myChar;
}
示例13: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
if (!(item.getObject() instanceof PsiMethod)) {
return;
}
PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument());
final Editor editor = context.getEditor();
final PsiMethod method = (PsiMethod)item.getObject();
final PsiParameter[] parameters = method.getParameterList().getParameters();
final StringBuilder buffer = new StringBuilder();
final CharSequence chars = editor.getDocument().getCharsSequence();
int endOffset = editor.getCaretModel().getOffset();
final Project project = context.getProject();
int afterSharp = CharArrayUtil.shiftBackwardUntil(chars, endOffset - 1, "#") + 1;
int signatureOffset = afterSharp;
PsiElement element = context.getFile().findElementAt(signatureOffset - 1);
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(element.getProject());
PsiDocTag tag = PsiTreeUtil.getParentOfType(element, PsiDocTag.class);
if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
final PsiDocTagValue value = tag.getValueElement();
endOffset = value.getTextRange().getEndOffset();
}
editor.getDocument().deleteString(afterSharp, endOffset);
editor.getCaretModel().moveToOffset(signatureOffset);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getSelectionModel().removeSelection();
buffer.append(method.getName()).append("(");
final int afterParenth = afterSharp + buffer.length();
for (int i = 0; i < parameters.length; i++) {
final PsiType type = TypeConversionUtil.erasure(parameters[i].getType());
buffer.append(type.getCanonicalText());
if (i < parameters.length - 1) {
buffer.append(",");
if (styleSettings.SPACE_AFTER_COMMA) buffer.append(" ");
}
}
buffer.append(")");
if (!(tag instanceof PsiInlineDocTag)) {
buffer.append(" ");
}
else {
final int currentOffset = editor.getCaretModel().getOffset();
if (chars.charAt(currentOffset) == '}') {
afterSharp++;
}
else {
buffer.append("} ");
}
}
String insertString = buffer.toString();
EditorModificationUtil.insertStringAtCaret(editor, insertString);
editor.getCaretModel().moveToOffset(afterSharp + buffer.length());
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
shortenReferences(project, editor, context, afterParenth);
}
示例14: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
if (!(item.getObject() instanceof PsiMethod)) {
return;
}
PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument());
final Editor editor = context.getEditor();
final PsiMethod method = (PsiMethod)item.getObject();
final PsiParameter[] parameters = method.getParameterList().getParameters();
final StringBuilder buffer = new StringBuilder();
final CharSequence chars = editor.getDocument().getCharsSequence();
int endOffset = editor.getCaretModel().getOffset();
final Project project = context.getProject();
int afterSharp = CharArrayUtil.shiftBackwardUntil(chars, endOffset - 1, "#") + 1;
int signatureOffset = afterSharp;
PsiElement element = context.getFile().findElementAt(signatureOffset - 1);
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(element.getProject());
PsiDocTag tag = PsiTreeUtil.getParentOfType(element, PsiDocTag.class);
if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
final PsiDocTagValue value = tag.getValueElement();
endOffset = value.getTextRange().getEndOffset();
}
editor.getDocument().deleteString(afterSharp, endOffset);
editor.getCaretModel().moveToOffset(signatureOffset);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getSelectionModel().removeSelection();
buffer.append(method.getName()).append("(");
final int afterParenth = afterSharp + buffer.length();
for (int i = 0; i < parameters.length; i++) {
final PsiType type = TypeConversionUtil.erasure(parameters[i].getType());
buffer.append(type.getCanonicalText());
if (i < parameters.length - 1) {
buffer.append(",");
if (styleSettings.SPACE_AFTER_COMMA) buffer.append(" ");
}
}
buffer.append(")");
if (!(tag instanceof PsiInlineDocTag)) {
buffer.append(" ");
}
else {
final int currentOffset = editor.getCaretModel().getOffset();
if (chars.charAt(currentOffset) == '}') {
afterSharp++;
}
else {
buffer.append("} ");
}
}
String insertString = buffer.toString();
EditorModificationUtil.insertStringAtCaret(editor, insertString);
editor.getCaretModel().moveToOffset(afterSharp + buffer.length());
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
shortenReferences(project, editor, context, afterParenth);
}
示例15: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
@RequiredDispatchThread
public void handleInsert(InsertionContext context, LookupElement item)
{
boolean isMethodLike = myDeclaration instanceof DotNetLikeMethodDeclaration;
if(isMethodLike)
{
new CSharpParenthesesInsertHandler((DotNetLikeMethodDeclaration) myDeclaration).handleInsert(context, item);
}
if(context.getCompletionChar() != '\n' || context.getFile() instanceof CSharpCodeFragment)
{
return;
}
// for void method we always insert semicolon
if(isMethodLike && !(myDeclaration instanceof CSharpConstructorDeclaration) && DotNetTypeRefUtil.isVmQNameEqual(((DotNetLikeMethodDeclaration) myDeclaration).getReturnTypeRef(),
myDeclaration, DotNetTypes.System.Void))
{
if(TailType.SEMICOLON.isApplicable(context))
{
TailType.SEMICOLON.processTail(context.getEditor(), context.getTailOffset());
}
}
/*else
{
context.commitDocument();
PsiElement elementAt = context.getFile().findElementAt(context.getStartOffset());
PsiElement parent = PsiTreeUtil.getParentOfType(elementAt, CSharpMethodCallExpressionImpl.class);
if(parent != null && parent.getNextSibling() instanceof PsiErrorElement)
{
TailType.SEMICOLON.processTail(context.getEditor(), context.getTailOffset());
}
parent = PsiTreeUtil.getParentOfType(elementAt, CSharpLocalVariable.class);
if(parent != null && parent.getNextSibling() instanceof PsiErrorElement)
{
TailType.SEMICOLON.processTail(context.getEditor(), context.getTailOffset());
}
}*/
}