Java Code Examples for com.intellij.codeInsight.completion.InsertionContext#getFile()
The following examples show how to use
com.intellij.codeInsight.completion.InsertionContext#getFile() .
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: CSharpParenthesesInsertHandler.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nullable @RequiredUIAccess protected PsiElement findNextToken(final InsertionContext context) { final PsiFile file = context.getFile(); PsiElement element = file.findElementAt(context.getTailOffset()); if(element instanceof PsiWhiteSpace) { boolean allowParametersOnNextLine = false; if(!allowParametersOnNextLine && element.getText().contains("\n")) { return null; } element = file.findElementAt(element.getTextRange().getEndOffset()); } return element; }
Example 2
Source File: VariableInsertHandler.java From intellij-xquery with Apache License 2.0 | 6 votes |
private PsiElement findElementBeforeNameFragment(InsertionContext context) { final PsiFile file = context.getFile(); PsiElement element = file.findElementAt(context.getStartOffset() - 1); element = getElementInFrontOfWhitespace(file, element); if (element instanceof LeafPsiElement && ((LeafPsiElement) element).getElementType() == XQueryTypes.COLON) { PsiElement elementBeforeColon = file.findElementAt(context.getStartOffset() - 2); if (elementBeforeColon != null) { element = elementBeforeColon; PsiElement beforeElementBeforeColon = file.findElementAt(elementBeforeColon.getTextRange().getStartOffset() - 1); if (beforeElementBeforeColon != null) { element = getElementInFrontOfWhitespace(file, beforeElementBeforeColon); } } } return element; }
Example 3
Source File: ProjectViewKeywordCompletionContributor.java From intellij with Apache License 2.0 | 5 votes |
@Nullable private static String findNextTokenText(final InsertionContext context) { final PsiFile file = context.getFile(); PsiElement element = file.findElementAt(context.getTailOffset()); while (element != null && element.getTextLength() == 0) { ASTNode next = element.getNode().getTreeNext(); element = next != null ? next.getPsi() : null; } return element != null ? element.getText() : null; }
Example 4
Source File: BracesInsertHandler.java From consulo-unity3d with Apache License 2.0 | 5 votes |
@Nullable protected PsiElement findNextToken(final InsertionContext context) { final PsiFile file = context.getFile(); PsiElement element = file.findElementAt(context.getTailOffset()); if(element instanceof PsiWhiteSpace) { if(!myAllowParametersOnNextLine && element.getText().contains("\n")) { return null; } element = file.findElementAt(element.getTextRange().getEndOffset()); } return element; }
Example 5
Source File: ExpressionOrStatementInsertHandler.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nullable protected PsiElement findNextToken(final InsertionContext context) { final PsiFile file = context.getFile(); PsiElement element = file.findElementAt(context.getTailOffset()); if(element instanceof PsiWhiteSpace) { if(element.getText().contains("\n")) { return null; } element = file.findElementAt(element.getTextRange().getEndOffset()); } return element; }
Example 6
Source File: LtGtInsertHandler.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nullable protected com.intellij.psi.PsiElement findNextToken(final InsertionContext context) { final PsiFile file = context.getFile(); PsiElement element = file.findElementAt(context.getTailOffset()); if(element instanceof PsiWhiteSpace) { if(!myAllowParametersOnNextLine && element.getText().contains("\n")) { return null; } element = file.findElementAt(element.getTextRange().getEndOffset()); } return element; }
Example 7
Source File: InsertHandlerUtils.java From intellij-xquery with Apache License 2.0 | 5 votes |
private static PsiElement findElementBeforeColon(InsertionContext context) { final PsiFile file = context.getFile(); PsiElement element = file.findElementAt(context.getStartOffset() - 1); if (element instanceof LeafPsiElement && ((LeafPsiElement) element).getElementType() == XQueryTypes.COLON) { return file.findElementAt(context.getStartOffset() - 2); } return null; }
Example 8
Source File: ParenthesesInsertHandler.java From consulo with Apache License 2.0 | 5 votes |
@Nullable protected PsiElement findNextToken(@Nonnull InsertionContext context) { final PsiFile file = context.getFile(); PsiElement element = file.findElementAt(context.getTailOffset()); if (element instanceof PsiWhiteSpace) { if (!myAllowParametersOnNextLine && element.getText().contains("\n")) { return null; } element = file.findElementAt(element.getTextRange().getEndOffset()); } return element; }
Example 9
Source File: JsonInsertFieldHandler.java From intellij-swagger with MIT License | 4 votes |
private boolean shouldAddComma(final @NotNull InsertionContext context) { PsiFile psiFile = context.getFile(); return Optional.ofNullable(psiFile.findElementAt(context.getStartOffset())) .map(el -> !jsonTraversal.isLastChild(el)) .orElse(false); }
Example 10
Source File: CSharpParenthesesWithSemicolonInsertHandler.java From consulo-csharp with Apache License 2.0 | 4 votes |
@Override @RequiredUIAccess 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()); } }*/ }