@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (!FileModificationService.getInstance().prepareFileForWrite(file)) return; perform(getImportPathVariantsToImport(startElement), file, editor); }
@Override public void visitElement(@NotNull PsiElement element) { if (PsiEquivalenceUtil.areElementsEquivalent(element, pattern)) { occurrences.add(element); return; } super.visitElement(element); } };
private void doInsert(InsertionContext context, @NotNull LookupElement item, @Nullable GoSignature signature) { int paramsCount = signature != null ? signature.getParameters().getParameterDeclarationList().size() : 0; InsertHandler<LookupElement> handler = paramsCount == 0 ? ParenthesesInsertHandler.NO_PARAMETERS : ParenthesesInsertHandler.WITH_PARAMETERS; handler.handleInsert(context, item); if (signature != null) { AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), null); } } };
public void handleInsert(InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); char completionChar = context.getCompletionChar(); if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) { return; } Project project = editor.getProject(); if (project != null) { int completionCharOffset = getCompletionCharOffset(editor); if (completionCharOffset == -1) { EditorModificationUtil.insertStringAtCaret(editor, "()", false, 1); PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); } else { editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + completionCharOffset + 1); } if (myTriggerAutoPopup) { AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null); } } }
@Override public void handleInsert(@NotNull InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); int tailOffset = context.getTailOffset(); Document document = editor.getDocument(); context.commitDocument(); boolean staysAtChar = document.getTextLength() > tailOffset && document.getCharsSequence().charAt(tailOffset) == myChar; context.setAddCompletionChar(false); if (!staysAtChar) { document.insertString(tailOffset, String.valueOf(myChar)); } editor.getCaretModel().moveToOffset(tailOffset + 1); AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(editor); } }
ApplicationManager.getApplication().invokeLater(() -> { CommandProcessor.getInstance().runUndoTransparentAction(() -> { PsiElement element = item.getPsiElement(); if (element == null) { return; PsiFile file = context.getFile(); if (!(file instanceof BallerinaFile)) { return; Editor editor = context.getEditor(); Project project = editor.getProject(); if (suggestAlias) { if (suggestAlias) { PsiElement currentPackageName = file.findElementAt(context.getStartOffset()); if (currentPackageName != null) { if (alias == null || alias.isEmpty()) { () -> AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null) );
@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (editor == null) { LOG.error("Cannot run quick fix without editor: " + getClass().getSimpleName(), AttachmentFactory.createAttachment(file.getVirtualFile())); return; } if (!(startElement instanceof GoType)) return; GoType type = (GoType)startElement; PsiElement anchor = PsiTreeUtil.findPrevParent(file, type); String name = "TypeName"; GoTypeDeclaration decl = (GoTypeDeclaration)file.addBefore(GoElementFactory.createTypeDeclaration(project, name, type), anchor); if (decl == null) return; decl = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(decl); if (decl == null) return; GoTypeSpec spec = ContainerUtil.getFirstItem(decl.getTypeSpecList()); if (spec == null) return; TemplateBuilderImpl builder = new TemplateBuilderImpl(file); builder.replaceElement(type, OTHER_NAME, INPUT_NAME, false); builder.replaceElement(spec.getIdentifier(), INPUT_NAME, new ConstantNode(name), true); editor.getCaretModel().moveToOffset(file.getTextRange().getStartOffset()); Template template = builder.buildInlineTemplate(); editor.getCaretModel().moveToOffset(file.getTextRange().getStartOffset()); TemplateManager.getInstance(project).startTemplate(editor, template); }
@Override protected void tearDown() throws Exception { try { updateSettings(defaultGoOnTheFly); CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance(); codeInsightSettings.ADD_MEMBER_IMPORTS_ON_THE_FLY = defaultJavaMemberOnTheFly; codeInsightSettings.ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = defaultJavaOnTheFly; } finally { //noinspection ThrowFromFinallyBlock super.tearDown(); } }
@Override public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { if (!(file instanceof GoFile)) { return; } String testingQualifier = null; if (myType.getParamType() != null) { testingQualifier = importTestingPackageIfNeeded((GoFile)file); PsiDocumentManager.getInstance(file.getProject()).doPostponedOperationsAndUnblockDocument(editor.getDocument()); } String functionText = "func " + myType.getPrefix(); int offset = functionText.length(); functionText += "(" + myType.getSignature(testingQualifier) + ") {\n\t\n}"; EditorModificationUtil.insertStringAtCaret(editor, functionText, false, offset); AutoPopupController.getInstance(project).scheduleAutoPopup(editor); }
@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (!FileModificationService.getInstance().preparePsiElementsForWrite(startElement)) return; Runnable runnable = () -> { AsyncResult<DataContext> dataContextContainer = DataManager.getInstance().getDataContextFromFocus(); dataContextContainer.doWhenDone(new Consumer<DataContext>() { @Override public void consume(DataContext dataContext) { RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(dataContext); if (renameHandler != null) { renameHandler.invoke(project, new PsiElement[]{startElement}, dataContext); } else { RefactoringActionHandler renameRefactoringHandler = RefactoringActionHandlerFactory.getInstance().createRenameHandler(); renameRefactoringHandler.invoke(project, new PsiElement[]{startElement}, dataContext); } } }); }; if (ApplicationManager.getApplication().isUnitTestMode()) { runnable.run(); } else { ApplicationManager.getApplication().invokeLater(runnable, project.getDisposed()); } }
/** * Checks of the {@code psiClass} is annotated with {@link Mapper}. * * @param psiClass the class that needs to be checked * * @return {@code true} if the {@code psiClass} is annotated with {@link Mapper}, {@code false} otherwise */ public static boolean isMapper(PsiClass psiClass) { return isAnnotated( psiClass, MAPPER_ANNOTATION_FQN, false ); }
builder.append(CodeInsightBundle.message("parameter.info.no.parameters"));
public void handleInsert(InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); char completionChar = context.getCompletionChar(); if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) { return; } Project project = editor.getProject(); if (project != null) { int completionCharOffset = getCompletionCharOffset(editor); if (completionCharOffset == -1) { EditorModificationUtil.insertStringAtCaret(editor, "();", false, 1); PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); } else { editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + completionCharOffset + 1); } if (myTriggerAutoPopup) { AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null); } } }
@Override public void handleInsert(@NotNull InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); int tailOffset = context.getTailOffset(); Document document = editor.getDocument(); context.commitDocument(); boolean staysAtChar = (document.getTextLength() > tailOffset) && (document.getCharsSequence().charAt(tailOffset) == myCharacter); context.setAddCompletionChar(false); if (!staysAtChar) { document.insertString(tailOffset, String.valueOf(myCharacter)); } editor.getCaretModel().moveToOffset(tailOffset + 1); AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(editor); } }
@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (!FileModificationService.getInstance().prepareFileForWrite(file)) { return; } if (!(file instanceof BallerinaFile)) { return; } BallerinaFile ballerinaFile = ((BallerinaFile) file); PsiReference reference = startElement.getReference(); if (reference != null && reference.resolve() != null) { return; } List<String> importPathVariantsToImport = getImportPathVariantsToImport(startElement); if (importPathVariantsToImport.size() == 1) { Runnable addImport = () -> BallerinaFile.addImport(ballerinaFile, importPathVariantsToImport.get(0), null); CommandProcessor.getInstance().runUndoTransparentAction( () -> ApplicationManager.getApplication().runWriteAction(addImport) ); } else { performImport(importPathVariantsToImport, ballerinaFile, editor); } }
@Override protected void setUp() throws Exception { super.setUp(); myFixture.enableInspections(GoUnresolvedReferenceInspection.class); ((CodeInsightTestFixtureImpl)myFixture).canChangeDocumentDuringHighlighting(true); CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance(); defaultJavaOnTheFly = codeInsightSettings.ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY; defaultJavaMemberOnTheFly = codeInsightSettings.ADD_MEMBER_IMPORTS_ON_THE_FLY; defaultGoOnTheFly = GoCodeInsightSettings.getInstance().isAddUnambiguousImportsOnTheFly(); codeInsightSettings.ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true; codeInsightSettings.ADD_MEMBER_IMPORTS_ON_THE_FLY = true; }
public void handleInsert(InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); char completionChar = context.getCompletionChar(); if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) { return; } Project project = editor.getProject(); if (project != null) { int completionCharOffset = getCompletionCharOffset(editor); if (completionCharOffset == -1) { EditorModificationUtil.insertStringAtCaret(editor, ";", false, 1); PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); } else { editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + completionCharOffset + 1); } if (myTriggerAutoPopup) { AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null); } } }
public void handleInsert(InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); char completionChar = context.getCompletionChar(); if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) { return; } Project project = editor.getProject(); if (project != null) { int completionCharOffset = getCompletionCharOffset(editor); if (completionCharOffset == -1) { EditorModificationUtil.insertStringAtCaret(editor, " {}", false, 2); PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); } else { editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + completionCharOffset + 1); } if (myTriggerAutoPopup) { AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null); } } }
public void handleInsert(InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); char completionChar = context.getCompletionChar(); if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) { return; } Project project = editor.getProject(); if (project != null) { int completionCharOffset = getCompletionCharOffset(editor); if (completionCharOffset == -1) { EditorModificationUtil.insertStringAtCaret(editor, ":", false, 1); if (myWithSpace) { EditorModificationUtil.insertStringAtCaret(editor, " ", false, 1); } PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); } else { editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + completionCharOffset + 1); } if (myTriggerAutoPopup) { AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null); } } }
public void handleInsert(InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); char completionChar = context.getCompletionChar(); if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) { return; int completionCharOffset = getCompletionCharOffset(editor); if (completionCharOffset == -1) { PsiElement psiElement = item.getPsiElement(); if (psiElement != null) { String hasAReturnValue = psiElement.getUserData(HAS_A_RETURN_VALUE); AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);