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"));
}
}
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()));
}
}
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;
}
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;
}
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;
}
Aggregations