Search in sources :

Example 76 with IncorrectOperationException

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 77 with IncorrectOperationException

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;
}
Also used : IncorrectOperationException(com.intellij.util.IncorrectOperationException) SmaliClassDescriptor(org.jf.smalidea.psi.leaf.SmaliClassDescriptor)

Example 78 with IncorrectOperationException

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);
    }
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) PsiElementFactory(com.intellij.psi.PsiElementFactory) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 79 with IncorrectOperationException

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());
    }
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) IntStream(java.util.stream.IntStream) VirtualFilePointerManager(com.intellij.openapi.vfs.pointers.VirtualFilePointerManager) UIUtil(com.intellij.util.ui.UIUtil) ArrayUtil(com.intellij.util.ArrayUtil) com.intellij.testFramework(com.intellij.testFramework) JobLauncher(com.intellij.concurrency.JobLauncher) NonNls(org.jetbrains.annotations.NonNls) TimeoutException(java.util.concurrent.TimeoutException) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) PathManagerEx(com.intellij.openapi.application.ex.PathManagerEx) Library(com.intellij.openapi.roots.libraries.Library) Job(com.intellij.concurrency.Job) OrderEntryUtil(com.intellij.openapi.roots.impl.OrderEntryUtil) Disposer(com.intellij.openapi.util.Disposer) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) VirtualFilePointerListener(com.intellij.openapi.vfs.pointers.VirtualFilePointerListener) FileUtil(com.intellij.openapi.util.io.FileUtil) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) OrderRootType(com.intellij.openapi.roots.OrderRootType) LibraryUtil(com.intellij.openapi.roots.libraries.LibraryUtil) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Collection(java.util.Collection) ConcurrencyUtil(com.intellij.util.ConcurrencyUtil) IOException(java.io.IOException) MockVirtualFile(com.intellij.mock.MockVirtualFile) Collectors(java.util.stream.Collectors) Disposable(com.intellij.openapi.Disposable) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TempFileSystem(com.intellij.openapi.vfs.ex.temp.TempFileSystem) Nullable(org.jetbrains.annotations.Nullable) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.openapi.vfs(com.intellij.openapi.vfs) NotNull(org.jetbrains.annotations.NotNull) AtomicReference(java.util.concurrent.atomic.AtomicReference) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Job(com.intellij.concurrency.Job) TimeoutException(java.util.concurrent.TimeoutException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 80 with IncorrectOperationException

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());
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Document(com.intellij.openapi.editor.Document)

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