Java Code Examples for com.intellij.openapi.util.text.StringUtil#isJavaIdentifierPart()
The following examples show how to use
com.intellij.openapi.util.text.StringUtil#isJavaIdentifierPart() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BracesInsertHandler.java From consulo-unity3d with Apache License 2.0 | 4 votes |
@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() == '{') { 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()); } }
Example 2
Source File: ExpressionOrStatementInsertHandler.java From consulo-csharp with Apache License 2.0 | 4 votes |
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()); } }
Example 3
Source File: CSharpParenthesesInsertHandler.java From consulo-csharp with Apache License 2.0 | 4 votes |
@RequiredUIAccess @Override public void handleInsert(final InsertionContext context, final LookupElement 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(); if(completionChar == '(') { context.setAddCompletionChar(false); } if(isToken(element, "(")) { int lparenthOffset = element.getTextRange().getStartOffset(); 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 { AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(editor, CSharpParameterInfoHandler.item(myLikeMethodDeclaration)); editor.getCaretModel().moveToOffset(lparenthOffset + 1); } return; } } else { document.insertString(context.getTailOffset(), "" + "(" + ""); editor.getCaretModel().moveToOffset(context.getTailOffset()); } 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(), ")"); if(!putCaretInside) { editor.getCaretModel().moveToOffset(context.getTailOffset()); } else { AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(editor, CSharpParameterInfoHandler.item(myLikeMethodDeclaration)); } }
Example 4
Source File: LtGtInsertHandler.java From consulo-csharp with Apache License 2.0 | 4 votes |
@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()); } }
Example 5
Source File: ParenthesesInsertHandler.java From consulo with Apache License 2.0 | 4 votes |
@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()); } }