use of com.intellij.util.IncorrectOperationException in project smali by JesusFreke.
the class SmaliClass method setName.
@Override
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
SmaliClassStatement classStatement = getClassStatement();
if (classStatement == null) {
throw new IncorrectOperationException();
}
SmaliClassTypeElement classTypeElement = classStatement.getNameElement();
if (classTypeElement == null) {
throw new IncorrectOperationException();
}
String expectedPath = "/" + getName() + ".smali";
VirtualFile virtualFile = this.getContainingFile().getVirtualFile();
if (virtualFile != null) {
String actualPath = virtualFile.getPath();
if (actualPath.endsWith(expectedPath)) {
getContainingFile().setName(name + ".smali");
}
}
String packageName = this.getPackageName();
String newName;
if (packageName.length() > 0) {
newName = packageName + "." + name;
} else {
newName = name;
}
classTypeElement.handleElementRename(newName);
return this;
}
use of com.intellij.util.IncorrectOperationException in project smali by JesusFreke.
the class SmaliClassTypeElement method handleElementRename.
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
SmaliClassDescriptor descriptor = getReferenceNameElement();
if (descriptor == null) {
throw new IncorrectOperationException();
}
SmaliClassDescriptor newDescriptor = new SmaliClassDescriptor(NameUtils.javaToSmaliType(newElementName));
CodeEditUtil.setNodeGenerated(newDescriptor, true);
this.replaceChild(descriptor, newDescriptor);
return this;
}
use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class FieldDescriptorImpl method getDescriptorEvaluation.
@Override
public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(myProject).getElementFactory();
String fieldName;
if (isStatic()) {
String typeName = myField.declaringType().name().replace('$', '.');
typeName = DebuggerTreeNodeExpression.normalize(typeName, PositionUtil.getContextElement(context), myProject);
fieldName = typeName + "." + getName();
} else {
//noinspection HardCodedStringLiteral
fieldName = isOuterLocalVariableValue() ? StringUtil.trimStart(getName(), OUTER_LOCAL_VAR_FIELD_PREFIX) : "this." + getName();
}
try {
return elementFactory.createExpressionFromText(fieldName, null);
} catch (IncorrectOperationException e) {
throw new EvaluateException(DebuggerBundle.message("error.invalid.field.name", getName()), e);
}
}
use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class VirtualFilePointerTest method stressRead.
private static void stressRead(@NotNull final VirtualFilePointer pointer, @NotNull final Collection<Job<Void>> reads) {
for (int i = 0; i < 10; i++) {
final AtomicReference<Job<Void>> reference = new AtomicReference<>();
reference.set(JobLauncher.getInstance().submitToJobThread(() -> ApplicationManager.getApplication().runReadAction(() -> {
VirtualFile file = pointer.getFile();
if (file != null && !file.isValid()) {
throw new IncorrectOperationException("I've caught it. I am that good");
}
}), future -> {
try {
future.get();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
reads.remove(reference.get());
}
}));
reads.add(reference.get());
}
}
use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class FormatterTestCase method checkDocument.
protected void checkDocument(final PsiFile file, final String text, String textAfter) {
final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
final EditorImpl editor;
if (doCheckDocumentUpdate()) {
editor = (EditorImpl) FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), file.getVirtualFile(), 0), false);
editor.putUserData(EditorImpl.DO_DOCUMENT_UPDATE_TEST, Boolean.TRUE);
if (myFile != null) {
FileEditorManager.getInstance(getProject()).closeFile(myFile.getVirtualFile());
}
myEditor = editor;
myFile = file;
} else {
editor = null;
}
WriteCommandAction.runWriteCommandAction(getProject(), () -> {
document.replaceString(0, document.getTextLength(), text);
PsiDocumentManager.getInstance(getProject()).commitDocument(document);
assertEquals(file.getText(), document.getText());
try {
if (doReformatRangeTest) {
CodeStyleManager.getInstance(getProject()).reformatRange(file, file.getTextRange().getStartOffset(), file.getTextRange().getEndOffset());
} else if (myTextRange != null) {
CodeStyleManager.getInstance(getProject()).reformatText(file, myTextRange.getStartOffset(), myTextRange.getEndOffset());
} else {
CodeStyleManager.getInstance(getProject()).reformatText(file, file.getTextRange().getStartOffset(), file.getTextRange().getEndOffset());
}
} catch (IncorrectOperationException e) {
fail();
}
});
assertEquals(textAfter, document.getText());
PsiDocumentManager.getInstance(getProject()).commitDocument(document);
assertEquals(textAfter, file.getText());
}
Aggregations