use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class AttributeChildInvocationHandler method setValue.
@Override
protected void setValue(@Nullable final String value) {
final XmlTag tag = ensureTagExists();
final String attributeName = getXmlElementName();
final String namespace = getXmlApiCompatibleNamespace(getParentHandler());
final String oldValue = StringUtil.unescapeXml(tag.getAttributeValue(attributeName, namespace));
final String newValue = XmlStringUtil.escapeString(value);
if (Comparing.equal(oldValue, newValue, true))
return;
getManager().runChange(() -> {
try {
XmlAttribute attribute = tag.setAttribute(attributeName, namespace, newValue);
setXmlElement(attribute);
getManager().cacheHandler(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute, this);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
});
final DomElement proxy = getProxy();
getManager().fireEvent(oldValue != null ? new DomEvent(proxy, false) : new DomEvent(proxy, true));
}
use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class AttributeChildInvocationHandler method undefineInternal.
@Override
public final void undefineInternal() {
final XmlTag tag = getXmlTag();
if (tag != null) {
getManager().runChange(() -> {
try {
setXmlElement(null);
tag.setAttribute(getXmlElementName(), getXmlApiCompatibleNamespace(getParentHandler()), null);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
});
fireUndefinedEvent();
}
}
use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class XmlUtil method createChildTag.
/**
* @param xmlTag
* @param localName
* @param namespace
* @param bodyText pass null to create collapsed tag, empty string means creating expanded one
* @param enforceNamespacesDeep
* @return
*/
public static XmlTag createChildTag(final XmlTag xmlTag, String localName, String namespace, @Nullable String bodyText, boolean enforceNamespacesDeep) {
String qname;
final String prefix = xmlTag.getPrefixByNamespace(namespace);
if (prefix != null && !prefix.isEmpty()) {
qname = prefix + ":" + localName;
} else {
qname = localName;
}
try {
String tagStart = qname + (!StringUtil.isEmpty(namespace) && xmlTag.getPrefixByNamespace(namespace) == null && !(StringUtil.isEmpty(xmlTag.getNamespacePrefix()) && namespace.equals(xmlTag.getNamespace())) ? " xmlns=\"" + namespace + "\"" : "");
Language language = xmlTag.getLanguage();
if (!(language instanceof HTMLLanguage))
language = XMLLanguage.INSTANCE;
XmlTag retTag;
if (bodyText != null) {
retTag = XmlElementFactory.getInstance(xmlTag.getProject()).createTagFromText("<" + tagStart + ">" + bodyText + "</" + qname + ">", language);
if (enforceNamespacesDeep) {
retTag.acceptChildren(new XmlRecursiveElementVisitor() {
@Override
public void visitXmlTag(XmlTag tag) {
final String namespacePrefix = tag.getNamespacePrefix();
if (namespacePrefix.isEmpty()) {
String qname;
if (prefix != null && !prefix.isEmpty()) {
qname = prefix + ":" + tag.getLocalName();
} else {
qname = tag.getLocalName();
}
try {
tag.setName(qname);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
super.visitXmlTag(tag);
}
});
}
} else {
retTag = XmlElementFactory.getInstance(xmlTag.getProject()).createTagFromText("<" + tagStart + "/>", language);
}
return retTag;
} catch (IncorrectOperationException e) {
LOG.error(e);
}
return null;
}
use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class ConvertToJavaProcessor method performRefactoring.
//private static String
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
final GeneratorClassNameProvider classNameProvider = new GeneratorClassNameProvider();
ExpressionContext context = new ExpressionContext(myProject, myFiles);
final ClassGenerator classGenerator = new ClassGenerator(classNameProvider, new ClassItemGeneratorImpl(context));
for (GroovyFile file : myFiles) {
final PsiClass[] classes = file.getClasses();
StringBuilder builder = new StringBuilder();
boolean first = true;
for (PsiClass aClass : classes) {
classGenerator.writeTypeDefinition(builder, aClass, true, first);
first = false;
builder.append('\n');
}
final Document document = PsiDocumentManager.getInstance(myProject).getDocument(file);
LOG.assertTrue(document != null);
document.setText(builder.toString());
PsiDocumentManager.getInstance(myProject).commitDocument(document);
String fileName = getNewFileName(file);
PsiElement newFile;
try {
newFile = file.setName(fileName);
} catch (final IncorrectOperationException e) {
ApplicationManager.getApplication().invokeLater(() -> Messages.showMessageDialog(myProject, e.getMessage(), RefactoringBundle.message("error.title"), Messages.getErrorIcon()));
return;
}
doPostProcessing(newFile);
}
}
use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class ExpressionGenerator method visitSafeCastExpression.
@Override
public void visitSafeCastExpression(@NotNull GrSafeCastExpression typeCastExpression) {
final GrExpression operand = (GrExpression) PsiUtil.skipParenthesesIfSensibly(typeCastExpression.getOperand(), false);
final GrTypeElement typeElement = typeCastExpression.getCastTypeElement();
if (operand instanceof GrListOrMap && ((GrListOrMap) operand).isMap() && typeElement != null) {
AnonymousFromMapGenerator.writeAnonymousMap((GrListOrMap) operand, typeElement, builder, context);
return;
}
final PsiType type = typeElement.getType();
if (operand instanceof GrListOrMap && !((GrListOrMap) operand).isMap() && type instanceof PsiArrayType) {
builder.append("new ");
final GrExpression[] initializers = ((GrListOrMap) operand).getInitializers();
if (initializers.length == 0) {
TypeWriter.writeTypeForNew(builder, ((PsiArrayType) type).getComponentType(), typeCastExpression);
builder.append("[0]");
} else {
TypeWriter.writeTypeForNew(builder, type, typeCastExpression);
builder.append('{');
for (GrExpression initializer : initializers) {
initializer.accept(this);
builder.append(", ");
}
if (initializers.length > 0) {
builder.delete(builder.length() - 2, builder.length());
//builder.removeFromTheEnd(2);
}
builder.append('}');
}
return;
}
final GroovyResolveResult resolveResult = PsiImplUtil.extractUniqueResult(typeCastExpression.multiResolve(false));
final PsiElement resolved = resolveResult.getElement();
if (resolved instanceof PsiMethod) {
final GrExpression typeParam;
try {
typeParam = factory.createExpressionFromText(typeElement.getText(), typeCastExpression);
} catch (IncorrectOperationException e) {
generateCast(typeElement, operand);
return;
}
invokeMethodOn(((PsiMethod) resolved), operand, new GrExpression[] { typeParam }, GrNamedArgument.EMPTY_ARRAY, GrClosableBlock.EMPTY_ARRAY, resolveResult.getSubstitutor(), typeCastExpression);
} else {
generateCast(typeElement, operand);
}
}
Aggregations