Search in sources :

Example 51 with IncorrectOperationException

use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.

the class I18nizeQuickFix method performI18nization.

@Override
public void performI18nization(final PsiFile psiFile, final Editor editor, PsiLiteralExpression literalExpression, Collection<PropertiesFile> propertiesFiles, String key, String value, String i18nizedText, PsiExpression[] parameters, final PropertyCreationHandler propertyCreationHandler) throws IncorrectOperationException {
    Project project = psiFile.getProject();
    propertyCreationHandler.createProperty(project, propertiesFiles, key, value, parameters);
    try {
        final PsiElement newExpression = doReplacementInJava(psiFile, editor, literalExpression, i18nizedText);
        reformatAndCorrectReferences(newExpression);
    } catch (IncorrectOperationException e) {
        Messages.showErrorDialog(project, CodeInsightBundle.message("inspection.i18n.expression.is.invalid.error.message"), CodeInsightBundle.message("inspection.error.dialog.title"));
    }
}
Also used : Project(com.intellij.openapi.project.Project) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 52 with IncorrectOperationException

use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.

the class FormSourceCodeGenerator method generate.

public void generate(final VirtualFile formFile) {
    myNeedLoadLabelText = false;
    myNeedLoadButtonText = false;
    final Module module = ModuleUtil.findModuleForFile(formFile, myProject);
    if (module == null) {
        return;
    }
    // ensure that new instances of generators are used for every run
    ourContainerLayoutCodeGenerators.clear();
    ourContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_INTELLIJ, new GridLayoutSourceGenerator());
    ourContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_GRIDBAG, new GridBagLayoutSourceGenerator());
    ourContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_BORDER, new BorderLayoutSourceGenerator());
    ourContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_FLOW, new FlowLayoutSourceGenerator());
    ourContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_CARD, new CardLayoutSourceGenerator());
    ourContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_FORM, new FormLayoutSourceGenerator());
    myErrors.clear();
    final PsiPropertiesProvider propertiesProvider = new PsiPropertiesProvider(module);
    final Document doc = FileDocumentManager.getInstance().getDocument(formFile);
    final LwRootContainer rootContainer;
    try {
        rootContainer = Utils.getRootContainer(doc.getText(), propertiesProvider);
    } catch (AlienFormFileException ignored) {
        // ignoring this file
        return;
    } catch (Exception e) {
        myErrors.add(new FormErrorInfo(null, UIDesignerBundle.message("error.cannot.process.form.file", e)));
        return;
    }
    if (rootContainer.getClassToBind() == null) {
        // form skipped - no class to bind
        return;
    }
    ErrorAnalyzer.analyzeErrors(module, formFile, null, rootContainer, null);
    FormEditingUtil.iterate(rootContainer, new FormEditingUtil.ComponentVisitor<LwComponent>() {

        public boolean visit(final LwComponent iComponent) {
            final ErrorInfo errorInfo = ErrorAnalyzer.getErrorForComponent(iComponent);
            if (errorInfo != null) {
                String message;
                if (iComponent.getBinding() != null) {
                    message = UIDesignerBundle.message("error.for.component", iComponent.getBinding(), errorInfo.myDescription);
                } else {
                    message = errorInfo.myDescription;
                }
                myErrors.add(new FormErrorInfo(iComponent.getId(), message));
            }
            return true;
        }
    });
    if (myErrors.size() != 0) {
        return;
    }
    try {
        _generate(rootContainer, module);
    } catch (ClassToBindNotFoundException e) {
    // ignore
    } catch (CodeGenerationException e) {
        myErrors.add(new FormErrorInfo(e.getComponentId(), e.getMessage()));
    } catch (IncorrectOperationException e) {
        myErrors.add(new FormErrorInfo(null, e.getMessage()));
    }
}
Also used : Document(com.intellij.openapi.editor.Document) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Module(com.intellij.openapi.module.Module)

Example 53 with IncorrectOperationException

use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.

the class DefaultAddAction method performElementAddition.

@Nullable
protected T performElementAddition() {
    final DomElement parent = getParentDomElement();
    final DomManager domManager = parent.getManager();
    final TypeChooser[] oldChoosers = new TypeChooser[] { null };
    final Type[] aClass = new Type[] { null };
    final StableElement<T> result = new WriteCommandAction<StableElement<T>>(domManager.getProject(), DomUtil.getFile(parent)) {

        @Override
        protected void run(@NotNull Result<StableElement<T>> result) throws Throwable {
            final DomElement parentDomElement = getParentDomElement();
            final T t = (T) getDomCollectionChildDescription().addValue(parentDomElement, getElementType());
            tuneNewValue(t);
            aClass[0] = parent.getGenericInfo().getCollectionChildDescription(t.getXmlElementName()).getType();
            oldChoosers[0] = domManager.getTypeChooserManager().getTypeChooser(aClass[0]);
            final SmartPsiElementPointer pointer = SmartPointerManager.getInstance(getProject()).createSmartPsiElementPointer(t.getXmlTag());
            domManager.getTypeChooserManager().registerTypeChooser(aClass[0], new TypeChooser() {

                @Override
                public Type chooseType(final XmlTag tag) {
                    if (tag == pointer.getElement()) {
                        return getElementType();
                    }
                    return oldChoosers[0].chooseType(tag);
                }

                @Override
                public void distinguishTag(final XmlTag tag, final Type aClass) throws IncorrectOperationException {
                    oldChoosers[0].distinguishTag(tag, aClass);
                }

                @Override
                public Type[] getChooserTypes() {
                    return oldChoosers[0].getChooserTypes();
                }
            });
            result.setResult((StableElement<T>) t.createStableCopy());
        }
    }.execute().getResultObject();
    if (result != null) {
        domManager.getTypeChooserManager().registerTypeChooser(aClass[0], oldChoosers[0]);
        return result.getWrappedElement();
    }
    return null;
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) Type(java.lang.reflect.Type) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) IncorrectOperationException(com.intellij.util.IncorrectOperationException) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 54 with IncorrectOperationException

use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.

the class XmlAttributeValueImpl method updateText.

@Override
public PsiLanguageInjectionHost updateText(@NotNull String text) {
    try {
        final String quoteChar = getTextLength() > 0 ? getText().substring(0, 1) : "";
        String contents = StringUtil.containsAnyChar(quoteChar, "'\"") ? StringUtil.trimEnd(StringUtil.trimStart(text, quoteChar), quoteChar) : text;
        XmlAttribute newAttribute = XmlElementFactory.getInstance(getProject()).createAttribute("q", contents, this);
        XmlAttributeValue newValue = newAttribute.getValueElement();
        CheckUtil.checkWritable(this);
        replaceAllChildrenToChildrenOf(newValue.getNode());
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
    return this;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) IncorrectOperationException(com.intellij.util.IncorrectOperationException) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue)

Example 55 with IncorrectOperationException

use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.

the class XmlTextImpl method insertAtOffset.

@Override
public XmlElement insertAtOffset(final XmlElement element, final int displayOffset) throws IncorrectOperationException {
    if (element instanceof XmlText) {
        insertText(((XmlText) element).getValue(), displayOffset);
    } else {
        final PomModel model = PomManager.getModel(getProject());
        final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
        model.runTransaction(new PomTransactionBase(getParent(), aspect) {

            @Override
            public PomModelEvent runInner() throws IncorrectOperationException {
                final XmlTag tag = getParentTag();
                assert tag != null;
                final XmlText rightPart = _splitText(displayOffset);
                PsiElement result;
                if (rightPart != null) {
                    result = tag.addBefore(element, rightPart);
                } else {
                    result = tag.addAfter(element, XmlTextImpl.this);
                }
                return createEvent(new XmlTagChildAddImpl(tag, (XmlTagChild) result));
            }
        });
    }
    return this;
}
Also used : XmlTagChildAddImpl(com.intellij.pom.xml.impl.events.XmlTagChildAddImpl) XmlAspect(com.intellij.pom.xml.XmlAspect) PomModel(com.intellij.pom.PomModel) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PomModelEvent(com.intellij.pom.event.PomModelEvent)

Aggregations

IncorrectOperationException (com.intellij.util.IncorrectOperationException)485 Project (com.intellij.openapi.project.Project)91 NotNull (org.jetbrains.annotations.NotNull)91 Nullable (org.jetbrains.annotations.Nullable)54 PsiElement (com.intellij.psi.PsiElement)50 TextRange (com.intellij.openapi.util.TextRange)43 VirtualFile (com.intellij.openapi.vfs.VirtualFile)38 Document (com.intellij.openapi.editor.Document)37 ASTNode (com.intellij.lang.ASTNode)35 PsiFile (com.intellij.psi.PsiFile)35 Editor (com.intellij.openapi.editor.Editor)33 NonNls (org.jetbrains.annotations.NonNls)32 UsageInfo (com.intellij.usageView.UsageInfo)31 ArrayList (java.util.ArrayList)31 JavaCodeStyleManager (com.intellij.psi.codeStyle.JavaCodeStyleManager)24 IOException (java.io.IOException)24 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)21 XmlTag (com.intellij.psi.xml.XmlTag)20 CodeStyleManager (com.intellij.psi.codeStyle.CodeStyleManager)19 Module (com.intellij.openapi.module.Module)18