com.intellij.util.IncorrectOperationException Java Examples
The following examples show how to use
com.intellij.util.IncorrectOperationException.
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: LegacyClassesForIdeQuickFix.java From idea-php-typo3-plugin with MIT License | 6 votes |
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement psiElement = descriptor.getPsiElement(); if (DumbService.isDumb(project)) { showIsInDumpModeMessage(project, psiElement); return; } if (psiElement instanceof ClassReference) { ClassReference classReference = (ClassReference) psiElement; String fqn = classReference.getFQN(); if (fqn != null) { String replacementFQN = LegacyClassesForIDEIndex.findReplacementClass(project, fqn); if (replacementFQN != null) { try { classReference.replace(PhpPsiElementFactory.createClassReference(project, replacementFQN)); } catch (IncorrectOperationException e) { showErrorMessage(project, "Could not replace class reference", psiElement); } } } } }
Example #2
Source File: CsvIntentionHelper.java From intellij-csv-validator with Apache License 2.0 | 6 votes |
public static void unquoteValue(@NotNull Project project, @NotNull final PsiElement element) { try { Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile()); List<Integer> quotePositions = new ArrayList<>(); if (CsvHelper.getElementType(element.getFirstChild()) == CsvTypes.QUOTE) { quotePositions.add(element.getFirstChild().getTextOffset()); } if (CsvHelper.getElementType(element.getLastChild()) == CsvTypes.QUOTE) { quotePositions.add(element.getLastChild().getTextOffset()); } String text = removeQuotes(document.getText(), quotePositions); document.setText(text); } catch (IncorrectOperationException e) { LOG.error(e); } }
Example #3
Source File: CsvValidationInspection.java From intellij-csv-validator with Apache License 2.0 | 6 votes |
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { try { PsiElement element = descriptor.getPsiElement(); Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile()); List<Integer> quotePositions = new ArrayList<>(); int quotePosition = CsvIntentionHelper.getOpeningQuotePosition(element); if (quotePosition != -1) { quotePositions.add(quotePosition); } PsiElement endSeparatorElement = CsvIntentionHelper.findQuotePositionsUntilSeparator(element, quotePositions, true); if (endSeparatorElement == null) { quotePositions.add(document.getTextLength()); } else { quotePositions.add(endSeparatorElement.getTextOffset()); } String text = CsvIntentionHelper.addQuotes(document.getText(), quotePositions); document.setText(text); } catch (IncorrectOperationException e) { LOG.error(e); } }
Example #4
Source File: CsvIntentionHelper.java From intellij-csv-validator with Apache License 2.0 | 6 votes |
public static void quoteValue(@NotNull Project project, @NotNull final PsiElement element) { try { Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile()); List<Integer> quotePositions = new ArrayList<>(); int quotePosition = getOpeningQuotePosition(element.getFirstChild(), element.getLastChild()); if (quotePosition != -1) { quotePositions.add(quotePosition); } PsiElement endSeparatorElement = findQuotePositionsUntilSeparator(element, quotePositions); if (endSeparatorElement == null) { quotePositions.add(document.getTextLength()); } else { quotePositions.add(endSeparatorElement.getTextOffset()); } String text = addQuotes(document.getText(), quotePositions); document.setText(text); } catch (IncorrectOperationException e) { LOG.error(e); } }
Example #5
Source File: SpringReformatter.java From spring-javaformat with Apache License 2.0 | 6 votes |
private void throwNotWritableException(PsiElement element) throws IncorrectOperationException { if (element instanceof PsiDirectory) { String url = ((PsiDirectory) element).getVirtualFile().getPresentableUrl(); throw new IncorrectOperationException(PsiBundle.message("cannot.modify.a.read.only.directory", url)); } PsiFile file = element.getContainingFile(); if (file == null) { throw new IncorrectOperationException(); } VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { throw new IncorrectOperationException(); } throw new IncorrectOperationException( PsiBundle.message("cannot.modify.a.read.only.file", virtualFile.getPresentableUrl())); }
Example #6
Source File: SpecLookupElement.java From litho with Apache License 2.0 | 6 votes |
/** * @param qualifiedName the name of the class to create lookup * @param project to find the lookup annotation class * @param insertHandler adds custom actions to the insert handling * @throws IncorrectOperationException if the qualifiedName does not specify a valid type * @return new {@link LookupElement} or cached instance if it was created previously */ static LookupElement create( String qualifiedName, Project project, InsertHandler<LookupElement> insertHandler) throws IncorrectOperationException { if (CACHE.containsKey(qualifiedName)) { return CACHE.get(qualifiedName); } PsiClass typeCls = PsiSearchUtils.findClass(project, qualifiedName); if (typeCls != null) { SpecLookupElement lookupElement = new SpecLookupElement(typeCls, insertHandler); CACHE.put(qualifiedName, lookupElement); return lookupElement; } // This is a dummy class, we don't want to cache it. typeCls = JavaPsiFacade.getInstance(project) .getElementFactory() .createClass(LithoClassNames.shortName(qualifiedName)); return new SpecLookupElement(typeCls, insertHandler); }
Example #7
Source File: PsiCustomUtil.java From intellij-spring-assistant with MIT License | 6 votes |
@Nullable public static PsiType safeGetValidType(@NotNull Module module, @NotNull String fqn) { try { // Intellij expects inner classes to be referred via `.` instead of `$` PsiType type = JavaPsiFacade.getInstance(module.getProject()).getParserFacade() .createTypeFromText(fqn.replaceAll("\\$", "."), null); boolean typeValid = isValidType(type); if (typeValid) { if (type instanceof PsiClassType) { return PsiClassType.class.cast(type); } else if (type instanceof PsiArrayType) { return PsiArrayType.class.cast(type); } } return null; } catch (IncorrectOperationException e) { debug(() -> log.debug("Unable to find class fqn " + fqn)); return null; } }
Example #8
Source File: PsiUpperSymbolImpl.java From reasonml-idea-plugin with MIT License | 6 votes |
@NotNull @Override public PsiElement setName(@NotNull String newName) throws IncorrectOperationException { PsiElement newNameIdentifier = ORCodeFactory.createModuleName(getProject(), newName); ASTNode newNameNode = newNameIdentifier == null ? null : newNameIdentifier.getFirstChild().getNode(); if (newNameNode != null) { PsiElement nameIdentifier = getFirstChild(); if (nameIdentifier == null) { getNode().addChild(newNameNode); } else { ASTNode oldNameNode = nameIdentifier.getNode(); getNode().replaceChild(oldNameNode, newNameNode); } } return this; }
Example #9
Source File: CsvShiftColumnRightIntentionAction.java From intellij-csv-validator with Apache License 2.0 | 6 votes |
@Override public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) throws IncorrectOperationException { CsvFile csvFile = (CsvFile) psiElement.getContainingFile(); PsiElement element = CsvHelper.getParentFieldElement(psiElement); CsvColumnInfoMap<PsiElement> columnInfoMap = csvFile.getColumnInfoMap(); CsvColumnInfo<PsiElement> leftColumnInfo = columnInfoMap.getColumnInfo(element); // column must be at least index 1 to be shifted left if (leftColumnInfo == null || leftColumnInfo.getColumnIndex() + 1 >= columnInfoMap.getColumnInfos().size()) { return; } CsvColumnInfo<PsiElement> rightColumnInfo = columnInfoMap.getColumnInfo(leftColumnInfo.getColumnIndex() + 1); changeLeftAndRightColumnOrder(project, csvFile, leftColumnInfo, rightColumnInfo); }
Example #10
Source File: PsiLowerSymbolReference.java From reasonml-idea-plugin with MIT License | 6 votes |
@Override public PsiElement handleElementRename(@NotNull String newName) throws IncorrectOperationException { PsiElement newNameIdentifier = ORCodeFactory.createLetName(myElement.getProject(), newName); ASTNode newNameNode = newNameIdentifier == null ? null : newNameIdentifier.getFirstChild().getNode(); if (newNameNode != null) { PsiElement nameIdentifier = myElement.getFirstChild(); if (nameIdentifier == null) { myElement.getNode().addChild(newNameNode); } else { ASTNode oldNameNode = nameIdentifier.getNode(); myElement.getNode().replaceChild(oldNameNode, newNameNode); } } return myElement; }
Example #11
Source File: PsiUpperSymbolReference.java From reasonml-idea-plugin with MIT License | 6 votes |
@Override public PsiElement handleElementRename(@NotNull String newName) throws IncorrectOperationException { PsiElement newNameIdentifier = ORCodeFactory.createModuleName(myElement.getProject(), newName); ASTNode newNameNode = newNameIdentifier == null ? null : newNameIdentifier.getFirstChild().getNode(); if (newNameNode != null) { PsiElement nameIdentifier = myElement.getFirstChild(); if (nameIdentifier == null) { myElement.getNode().addChild(newNameNode); } else { ASTNode oldNameNode = nameIdentifier.getNode(); myElement.getNode().replaceChild(oldNameNode, newNameNode); } } return myElement; }
Example #12
Source File: GenerateSqlXmlIntention.java From NutzCodeInsight with Apache License 2.0 | 5 votes |
@Override public void invoke(@NotNull Project project, Editor editor, PsiFile psiFile) throws IncorrectOperationException { PsiDirectory psiDirectory = psiFile.getContainingDirectory(); WriteCommandAction.runWriteCommandAction(project, () -> { try { Properties properties = new Properties(); properties.setProperty("CLASSNAME", clazz); PsiElement element = TemplateFileUtil.createFromTemplate(SqlTplFileTemplateGroupFactory.NUTZ_SQL_TPL_XML, templateFileName, properties, psiDirectory); NavigationUtil.activateFileWithPsiElement(element, true); } catch (Exception e) { HintManager.getInstance().showErrorHint(editor, "Failed: " + e.getLocalizedMessage()); } }); }
Example #13
Source File: MethodNamePolicy.java From json2java4idea with Apache License 2.0 | 5 votes |
@Nonnull @Override public String convert(@Nonnull String name, @Nonnull TypeName type) { final String variableName = DefaultNamePolicy.format(name, CaseFormat.UPPER_CAMEL); if (Strings.isNullOrEmpty(variableName)) { throw new IllegalArgumentException("Cannot convert '" + name + "' to a method name"); } try { final PsiType psiType = typeConverter.apply(type); return GenerateMembersUtil.suggestGetterName(variableName, psiType, project); } catch (IncorrectOperationException e) { throw new IllegalArgumentException("Cannot convert '" + name + "' to a method name", e); } }
Example #14
Source File: CsvValidationInspection.java From intellij-csv-validator with Apache License 2.0 | 5 votes |
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { try { PsiElement element = descriptor.getPsiElement(); Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile()); document.setText(document.getText() + "\""); } catch (IncorrectOperationException e) { LOG.error(e); } }
Example #15
Source File: ImageUploadIntentionAction.java From markdown-image-kit with MIT License | 5 votes |
@Override public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { MarkdownImage matchImageMark = getMarkdownImage(editor); if (matchImageMark == null) { return; } if (ImageLocationEnum.NETWORK.name().equals(matchImageMark.getLocation().name())) { return; } Map<Document, List<MarkdownImage>> waitingForMoveMap = new HashMap<Document, List<MarkdownImage>>(1) { { put(editor.getDocument(), new ArrayList<MarkdownImage>(1) { { add(matchImageMark); } }); } }; EventData data = new EventData() .setProject(project) .setClientName(getName()) .setClient(getClient()) .setWaitingProcessMap(waitingForMoveMap); // 开启后台任务 new ActionTask(project, MikBundle.message("mik.action.upload.process", getName()), ActionManager.buildUploadChain(data)).queue(); }
Example #16
Source File: GroovyDslParser.java From ok-gradle with Apache License 2.0 | 5 votes |
@Override @Nullable public PsiElement convertToPsiElement(@NotNull Object literal) { ApplicationManager.getApplication().assertReadAccessAllowed(); try { return GroovyDslUtil.createLiteral(myDslFile, literal); } catch (IncorrectOperationException e) { myDslFile.getContext().getNotificationForType(myDslFile, INVALID_EXPRESSION).addError(e); return null; } }
Example #17
Source File: SpaceInsideNonQuotedInspection.java From idea-php-dotenv-plugin with MIT License | 5 votes |
/** * Adds quotes to DotEnvValue element * * @param project The project that contains the file being edited. * @param descriptor A problem found by this inspection. */ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { try { DotEnvValue valueElement = (DotEnvValue) descriptor.getPsiElement(); PsiElement newValueElement = DotEnvFactory.createFromText(project, DotEnvTypes.VALUE, "DUMMY=\"" + valueElement.getText() + "\""); valueElement.getNode().getTreeParent().replaceChild(valueElement.getNode(), newValueElement.getNode()); } catch (IncorrectOperationException e) { LOG.error(e); } }
Example #18
Source File: CsvIntentionHelper.java From intellij-csv-validator with Apache License 2.0 | 5 votes |
public static void quoteAll(@NotNull Project project, @NotNull PsiFile psiFile) { try { Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile); List<Integer> quotePositions = new ArrayList<>(); Collection<PsiElement> fields = getAllFields(psiFile); PsiElement separator; for (PsiElement field : fields) { if (field.getFirstChild() == null || CsvHelper.getElementType(field.getFirstChild()) != CsvTypes.QUOTE) { separator = CsvHelper.getPreviousSeparator(field); if (separator == null) { quotePositions.add(field.getParent().getTextOffset()); } else { quotePositions.add(separator.getTextOffset() + separator.getTextLength()); } } if (field.getLastChild() == null || CsvHelper.getElementType(field.getLastChild()) != CsvTypes.QUOTE) { separator = CsvHelper.getNextSeparator(field); if (separator == null) { quotePositions.add(field.getParent().getTextOffset() + field.getParent().getTextLength()); } else { quotePositions.add(separator.getTextOffset()); } } } String text = addQuotes(document.getText(), quotePositions); document.setText(text); } catch (IncorrectOperationException e) { LOG.error(e); } }
Example #19
Source File: AbstractBaseIntention.java From reasonml-idea-plugin with MIT License | 5 votes |
@Override public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) throws IncorrectOperationException { if (!FileModificationService.getInstance().prepareFileForWrite(file)) { return; } PsiDocumentManager.getInstance(project).commitAllDocuments(); T parentAtCaret = getParentAtCaret(editor, file); if (parentAtCaret != null) { ApplicationManager.getApplication().runWriteAction(() -> runInvoke(project, parentAtCaret)); } }
Example #20
Source File: PX2REMIntention.java From px2rwd-intellij-plugin with MIT License | 5 votes |
@Override public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { Optional.ofNullable(ActionPerformer.getActionPerformer(project, editor)).ifPresent(ap -> Optional.of(FormatTools.getFormatTools(ap.getConstValue())).ifPresent(formatTools -> formatTools.formatLineCode(ap, ShortCutType.REM) ) ); }
Example #21
Source File: RollbackIntention.java From px2rwd-intellij-plugin with MIT License | 5 votes |
@Override public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { Optional.ofNullable(ActionPerformer.getActionPerformer(project, editor)).ifPresent(ap -> Optional.of(FormatTools.getFormatTools(ap.getConstValue())).ifPresent(formatTools -> formatTools.rollbackStyle(ap, ap.getDocument().getLineNumber(ap.getCaretModel().getOffset())) ) ); }
Example #22
Source File: PX2VWIntention.java From px2rwd-intellij-plugin with MIT License | 5 votes |
@Override public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { Optional.ofNullable(ActionPerformer.getActionPerformer(project, editor)).ifPresent(ap -> Optional.of(FormatTools.getFormatTools(ap.getConstValue())).ifPresent(formatTools -> formatTools.formatLineCode(ap, ShortCutType.VW) ) ); }
Example #23
Source File: SoyIdentifierMixin.java From bamboo-soy with Apache License 2.0 | 5 votes |
@Override public PsiElement setName(@NotNull String name) throws IncorrectOperationException { if (getIdentifierWord() == null) { throw new IncorrectOperationException("IdentifierWord missing"); } getIdentifierWord() .replace(SoyPsiElementFactory .createIdentifierFromText(getProject(), name)); return this; }
Example #24
Source File: GroovyDslUtil.java From ok-gradle with Apache License 2.0 | 5 votes |
/** * Creates a literal from a context and value. * * @param context context used to create GrPsiElementFactory * @param unsavedValue the value for the new expression * @return created PsiElement * @throws IncorrectOperationException if creation of the expression fails */ @Nullable static PsiElement createLiteral(@NotNull GradleDslElement context, @NotNull Object unsavedValue) throws IncorrectOperationException { CharSequence unsavedValueText = null; if (unsavedValue instanceof String) { String stringValue = (String)unsavedValue; if (isQuotedString(stringValue)) { // We need to escape the string without the quotes and then add them back. String unquotedString = removeQuotes(stringValue); unsavedValueText = addQuotes(escapeString(unquotedString, true), true); } else { unsavedValueText = addQuotes(escapeString((String)unsavedValue, false), false); } } else if (unsavedValue instanceof Integer || unsavedValue instanceof Boolean || unsavedValue instanceof BigDecimal) { unsavedValueText = unsavedValue.toString(); } else if (unsavedValue instanceof RawText) { unsavedValueText = ((RawText)unsavedValue).getText(); } if (unsavedValueText == null) { return null; } GroovyPsiElementFactory factory = getPsiElementFactory(context); if (factory == null) { return null; } return factory.createExpressionFromText(unsavedValueText); }
Example #25
Source File: SoyIdentifierOwnerMixin.java From bamboo-soy with Apache License 2.0 | 5 votes |
@Override public PsiElement setName(@NotNull String name) throws IncorrectOperationException { if (getNameIdentifier() == null) { throw new IncorrectOperationException("IdentifierWord missing"); } getNameIdentifier().replace(SoyPsiElementFactory.createIdentifierFromText(getProject(), name)); return this; }
Example #26
Source File: OnEventGenerateAction.java From litho with Apache License 2.0 | 5 votes |
/** @return a list of objects to insert into generated code. */ @NotNull @Override protected List<? extends GenerationInfo> generateMemberPrototypes( PsiClass aClass, ClassMember[] members) throws IncorrectOperationException { final List<GenerationInfo> prototypes = new ArrayList<>(); for (ClassMember member : members) { if (member instanceof PsiMethodMember) { PsiMethodMember methodMember = (PsiMethodMember) member; prototypes.add(new PsiGenerationInfo<>(methodMember.getElement())); } } return prototypes; }
Example #27
Source File: OnEventCreateFix.java From litho with Apache License 2.0 | 5 votes |
@Override public void invoke(Project project, Editor editor, PsiFile file) throws IncorrectOperationException { final AtomicReference<PsiMethod> eventMethodRef = new AtomicReference<>(); final Runnable generateOnEvent = () -> OnEventGenerateAction.createHandler( (context, eventProject) -> event, eventMethodRef::set) .invoke(project, editor, file); final Runnable updateArgumentList = () -> Optional.ofNullable(eventMethodRef.get()) .map( eventMethod -> AddArgumentFix.createArgumentList( methodCall, clsName, eventMethod.getName(), JavaPsiFacade.getInstance(project).getElementFactory())) .ifPresent(argumentList -> methodCall.getArgumentList().replace(argumentList)); final Runnable action = () -> { TransactionGuard.getInstance().submitTransactionAndWait(generateOnEvent); WriteCommandAction.runWriteCommandAction(project, updateArgumentList); ComponentGenerateUtils.updateLayoutComponent(layoutCls); LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_FIX_EVENT_HANDLER + ".new"); }; final Application application = ApplicationManager.getApplication(); if (application.isUnitTestMode()) { action.run(); } else { application.invokeLater(action); } }
Example #28
Source File: AddArgumentFix.java From litho with Apache License 2.0 | 5 votes |
@Override public void invoke(Project project, Editor editor, PsiFile file) throws IncorrectOperationException { originalCall.getArgumentList().replace(newArgumentList); int offset = originalCall.getArgumentList().getLastChild().getTextOffset() - 1; // Move cursor before the ')'. editor.getCaretModel().moveToOffset(offset); LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_FIX_EVENT_HANDLER); }
Example #29
Source File: GroovyDslUtil.java From ok-gradle with Apache License 2.0 | 5 votes |
/** * This method is used in order to add elements to the back of a map, * it is derived from {@link ASTDelegatePsiElement#addInternal(ASTNode, ASTNode, ASTNode, Boolean)}. */ private static PsiElement realAddBefore(@NotNull GrListOrMap element, @NotNull PsiElement newElement, @NotNull PsiElement anchor) { CheckUtil.checkWritable(element); TreeElement elementCopy = ChangeUtil.copyToElement(newElement); ASTNode anchorNode = getAnchorNode(element, anchor.getNode(), true); ASTNode newNode = CodeEditUtil.addChildren(element.getNode(), elementCopy, elementCopy, anchorNode); if (newNode == null) { throw new IncorrectOperationException("Element cannot be added"); } if (newNode instanceof TreeElement) { return ChangeUtil.decodeInformation((TreeElement)newNode).getPsi(); } return newNode.getPsi(); }
Example #30
Source File: PsiFakeModule.java From reasonml-idea-plugin with MIT License | 4 votes |
@Override public PsiElement setName(@NotNull String name) throws IncorrectOperationException { throw new RuntimeException("Not implemented, use FileBase"); }